Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
GUIButton.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_GUI_BUTTON_H_
34#define DVD_GUI_BUTTON_H_
35
36#include "GUIElement.h"
37#include "GUIText.h"
38
39namespace CEGUI {
40 class Window;
41 class Font;
42 class EventArgs;
43};
44
45namespace Divide {
46
47class AudioDescriptor;
48
49class GUIButton final : public GUIElementBase<GUIType::GUI_BUTTON> {
52
53 friend class GUIInterface;
54 friend class SceneGUIElements;
55
56 public:
57 enum class Event : U8 {
58 HoverEnter = 0,
61 MouseUp,
66 COUNT
67 };
68
69 public:
70 void setTooltip(const string& tooltipText) override;
71 void setText(const std::string_view& text) const;
72 void setFont(const string& fontName, const string& fontFileName, U32 size) const;
73 void active(bool active) noexcept override;
74 void visible(bool visible) noexcept override;
75
76 void setEventCallback(Event event, const ButtonCallback& callback);
78 void setEventCallback(Event event, const ButtonCallback& callback, Handle<AudioDescriptor> sound);
79
80 // return false if we replace an existing callback
81 static bool soundCallback(const AudioCallback& cbk);
82
83 protected:
84 GUIButton(const string& name,
85 const string& text,
86 const string& guiScheme,
87 const RelativePosition2D& offset,
88 const RelativeScale2D& size,
89 CEGUI::Window* parent);
90
91 ~GUIButton() override;
92
93 bool onEvent(Event event, const CEGUI::EventArgs& /*e*/);
94
95 protected:
98 std::array<Handle<AudioDescriptor>, to_base(Event::COUNT)> _eventSound;
99 std::array<CEGUI::Event::Connection, to_base(Event::COUNT)> _connections;
100
101 CEGUI::Window* _btnWindow;
102
104};
105
106}; // namespace Divide
107
108#endif //DVD_GUI_BUTTON_H_
CEGUI::Window * _btnWindow
Definition: GUIButton.h:101
static AudioCallback s_soundCallback
Definition: GUIButton.h:103
void active(bool active) noexcept override
Definition: GUIButton.cpp:100
std::array< ButtonCallback, to_base(Event::COUNT)> _callbackFunction
A pointer to a function to call if the button is pressed.
Definition: GUIButton.h:97
DELEGATE< void, I64 > ButtonCallback
Definition: GUIButton.h:50
void setEventSound(Event event, Handle< AudioDescriptor > sound)
Definition: GUIButton.cpp:169
std::array< CEGUI::Event::Connection, to_base(Event::COUNT)> _connections
Definition: GUIButton.h:99
~GUIButton() override
Definition: GUIButton.cpp:92
static bool soundCallback(const AudioCallback &cbk)
Definition: GUIButton.cpp:143
DELEGATE< void, Handle< AudioDescriptor > > AudioCallback
Definition: GUIButton.h:51
std::array< Handle< AudioDescriptor >, to_base(Event::COUNT)> _eventSound
Definition: GUIButton.h:98
void visible(bool visible) noexcept override
Definition: GUIButton.cpp:107
void setFont(const string &fontName, const string &fontFileName, U32 size) const
Definition: GUIButton.cpp:126
void setText(const std::string_view &text) const
Definition: GUIButton.cpp:114
void setEventCallback(Event event, const ButtonCallback &callback)
Definition: GUIButton.cpp:165
void setTooltip(const string &tooltipText) override
Definition: GUIButton.cpp:120
bool onEvent(Event event, const CEGUI::EventArgs &)
Definition: GUIButton.cpp:150
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
DELEGATE_STD< Ret, Args... > DELEGATE
uint8_t U8
Project & parent
Definition: DefaultScene.h:41
uint32_t U32
constexpr auto to_base(const Type value) -> Type