VPS
Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 1003 vs 1004 for /trunk/Source Code/GUI/GUIButton.cpp

Diff revisions: vs.
  @@ -8,7 +8,8 @@
8 8
9 9 namespace Divide {
10 10
11 - GUIButton::AudioCallback GUIButton::_soundCallback;
11 +
12 + GUIButton::AudioCallback GUIButton::s_soundCallback;
12 13
13 14 GUIButton::GUIButton(U64 guiID,
14 15 const stringImpl& name,
  @@ -16,16 +17,14 @@
16 17 const stringImpl& guiScheme,
17 18 const RelativePosition2D& offset,
18 19 const RelativeScale2D& size,
19 - CEGUI::Window* parent,
20 - ButtonCallback callback,
21 - AudioDescriptor_ptr onClickSound)
20 + CEGUI::Window* parent)
22 21 : GUIElement(guiID, name, parent, GUIType::GUI_BUTTON),
23 - _callbackFunction(callback),
24 - _btnWindow(nullptr),
25 - _onClickSound(onClickSound)
22 + _btnWindow(nullptr)
26 23 {
27 24
28 - _btnWindow = CEGUI::WindowManager::getSingleton().createWindow((guiScheme + "/Button").c_str(), text.c_str());
25 + static stringImpl buttonInfo = guiScheme + "/Button";
26 +
27 + _btnWindow = CEGUI::WindowManager::getSingleton().createWindow(buttonInfo.c_str(), name.c_str());
29 28
30 29 _btnWindow->setPosition(offset);
31 30
  @@ -33,10 +32,24 @@
33 32
34 33 _btnWindow->setText(text.c_str());
35 34
36 - _btnWindow->subscribeEvent(CEGUI::PushButton::EventClicked,
37 - CEGUI::Event::Subscriber(&GUIButton::joystickButtonPressed, this));
38 -
35 + _btnWindow->subscribeEvent(CEGUI::PushButton::EventMouseMove,
36 + CEGUI::Event::Subscriber(&GUIButton::onMove, this));
37 + _btnWindow->subscribeEvent(CEGUI::PushButton::EventMouseEntersArea,
38 + CEGUI::Event::Subscriber(&GUIButton::onHoverEnter, this));
39 + _btnWindow->subscribeEvent(CEGUI::PushButton::EventMouseLeavesArea,
40 + CEGUI::Event::Subscriber(&GUIButton::onHoverLeave, this));
41 + _btnWindow->subscribeEvent(CEGUI::PushButton::EventMouseButtonDown,
42 + CEGUI::Event::Subscriber(&GUIButton::onButtonDown, this));
43 + _btnWindow->subscribeEvent(CEGUI::PushButton::EventMouseButtonUp,
44 + CEGUI::Event::Subscriber(&GUIButton::onButtonUp, this));
45 + _btnWindow->subscribeEvent(CEGUI::PushButton::EventMouseClick,
46 + CEGUI::Event::Subscriber(&GUIButton::onClick, this));
47 + _btnWindow->subscribeEvent(CEGUI::PushButton::EventMouseDoubleClick,
48 + CEGUI::Event::Subscriber(&GUIButton::onDoubleClick, this));
49 + _btnWindow->subscribeEvent(CEGUI::PushButton::EventMouseDoubleClick,
50 + CEGUI::Event::Subscriber(&GUIButton::onTripleClick, this));
39 51 _parent->addChild(_btnWindow);
52 +
40 53 setActive(true);
41 54 }
42 55
  @@ -71,7 +84,7 @@
71 84 const stringImpl& fontFileName, U32 size) {
72 85 if (!fontName.empty()) {
73 86 if (!CEGUI::FontManager::getSingleton().isDefined(fontName.c_str())) {
74 - CEGUI::FontManager::getSingleton().createFreeTypeFont(
87 + CEGUI::FontManager::getSingleton().createFreeTypeFont(
75 88 fontName.c_str(), to_F32(size), true, fontFileName.c_str());
76 89 }
77 90
  @@ -81,27 +94,67 @@
81 94 }
82 95 }
83 96
84 - bool GUIButton::joystickButtonPressed(const CEGUI::EventArgs& /*e*/) {
85 - if (_callbackFunction) {
86 - _callbackFunction(getGUID());
87 - if (_onClickSound && _soundCallback) {
88 - _soundCallback(_onClickSound);
97 + bool GUIButton::soundCallback(const AudioCallback& cbk) {
98 + bool hasCbk = s_soundCallback ? true : false;
99 + s_soundCallback = cbk;
100 +
101 + return hasCbk;
102 + }
103 +
104 + bool GUIButton::onEvent(Event event, const CEGUI::EventArgs& /*e*/) {
105 + if (_callbackFunction[to_base(event)]) {
106 + _callbackFunction[to_base(event)](getGUID());
107 + if (_eventSound[to_base(event)] && s_soundCallback) {
108 + s_soundCallback(_eventSound[to_base(event)]);
89 109 }
90 110 return true;
91 111 }
92 112 return false;
93 113 }
94 114
95 - void GUIButton::setOnClickSound(const AudioDescriptor_ptr& onClickSound) {
96 - _onClickSound = onClickSound;
115 + bool GUIButton::onMove(const CEGUI::EventArgs& e) {
116 + return onEvent(Event::MouseMove, e);
97 117 }
98 118
119 + bool GUIButton::onHoverEnter(const CEGUI::EventArgs& e) {
120 + return onEvent(Event::HoverEnter, e);
121 + }
99 122
100 - bool GUIButton::soundCallback(const AudioCallback& cbk) {
101 - bool hasCbk = _soundCallback ? true : false;
102 - _soundCallback = cbk;
123 + bool GUIButton::onHoverLeave(const CEGUI::EventArgs& e) {
124 + return onEvent(Event::HoverLeave, e);
125 + }
103 126
104 - return hasCbk;
127 + bool GUIButton::onButtonDown(const CEGUI::EventArgs& e) {
128 + return onEvent(Event::MouseDown, e);
129 + }
130 +
131 + bool GUIButton::onButtonUp(const CEGUI::EventArgs& e) {
132 + return onEvent(Event::MouseUp, e);
133 + }
134 +
135 + bool GUIButton::onClick(const CEGUI::EventArgs& e) {
136 + return onEvent(Event::MouseClick, e);
137 + }
138 +
139 + bool GUIButton::onDoubleClick(const CEGUI::EventArgs& e) {
140 + return onEvent(Event::MouseDoubleClick, e);
141 + }
142 +
143 + bool GUIButton::onTripleClick(const CEGUI::EventArgs& e) {
144 + return onEvent(Event::MouseTripleClick, e);
145 + }
146 +
147 + void GUIButton::setEventCallback(Event event, ButtonCallback callback) {
148 + _callbackFunction[to_base(event)] = callback;
149 + }
150 +
151 + void GUIButton::setEventSound(Event event, AudioDescriptor_ptr sound) {
152 + _eventSound[to_base(event)] = sound;
153 + }
154 +
155 + void GUIButton::setEventCallback(Event event, ButtonCallback callback, AudioDescriptor_ptr sound) {
156 + setEventCallback(event, callback);
157 + setEventSound(event, sound);
105 158 }
106 159
107 160 };