Subversion Repository Public Repository

Divide-Framework

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#include "stdafx.h"

#include "Headers/GUIInterface.h"

#include "Headers/GUI.h"
#include "Headers/GUIFlash.h"
#include "Headers/GUIText.h"
#include "Headers/GUIButton.h"
#include "Headers/GUIConsole.h"
#include "Headers/GUIMessageBox.h"

#include "Scenes/Headers/Scene.h"
#include "Core/Headers/PlatformContext.h"
#include "Core/Resources/Headers/ResourceCache.h"
#include "Platform/Headers/PlatformRuntime.h"

namespace Divide {

GUIInterface::GUIInterface(GUI& context)
    : _context(&context)
{
    Locale::addChangeLanguageCallback([this](const char* newLanguage) { 
        onLanguageChange(newLanguage);
    });
}

GUIInterface::~GUIInterface()
{
    for (U8 i = 0; i < to_base(GUIType::COUNT); ++i) {
        for (GUIMap::value_type& it : _guiElements[i]) {
            MemoryManager::DELETE(it.second.first);
        }
    }
}

void GUIInterface::onSizeChange(const SizeChangeParams& params) {
    for (U8 i = 0; i < to_base(GUIType::COUNT); ++i) {
        for (const GUIMap::value_type& guiStackIterator : _guiElements[i]) {
            guiStackIterator.second.first->onSizeChange(params);
        }
    }
}

void GUIInterface::onLanguageChange(const char* newLanguage) {
    ACKNOWLEDGE_UNUSED(newLanguage);
}

void GUIInterface::addElement(U64 id, GUIElement* element) {
    assert(Runtime::isMainThread());

    U8 typeIndex = to_U8(element->getType());
    GUIMap& targetMap = _guiElements[typeIndex];

    GUIMap::iterator it = targetMap.find(id);
    if (it != std::end(targetMap)) {
        MemoryManager::SAFE_UPDATE(it->second.first, element);
        it->second.second = element ? element->isVisible() : false;
    } else {
        hashAlg::insert(targetMap, std::make_pair(id, std::make_pair(element, element ? element->isVisible() : false)));
    }
}

GUIElement* GUIInterface::getGUIElementImpl(U64 elementName, GUIType type) const {
    GUIElement* ret = nullptr;
    if (type == GUIType::COUNT) {
        for (U8 i = 0; i < to_base(GUIType::COUNT); ++i) {
            GUIMap::const_iterator it = _guiElements[i].find(elementName);
            if (it != std::cend(_guiElements[i])) {
                ret = it->second.first;
                break;
            }
        }
    } else {
        GUIMap::const_iterator it = _guiElements[to_U32(type)].find(elementName);
        if (it != std::cend(_guiElements[to_U32(type)])) {
            ret = it->second.first;
        }
    }
    return ret;
}

GUIElement* GUIInterface::getGUIElementImpl(I64 elementID, GUIType type) const {
    GUIElement* ret = nullptr;
    GUIElement* element = nullptr;
    if (type == GUIType::COUNT) {
        for (U8 i = 0; i < to_base(GUIType::COUNT); ++i) {
            for (const GUIMap::value_type& guiStackIterator : _guiElements[i]) {
                element = guiStackIterator.second.first;
                if (element->getGUID() == elementID) {
                    ret = element;
                    break;
                }
            }
            if (ret != nullptr) {
                break;
            }
        }
    } else {
        for (const GUIMap::value_type& guiStackIterator : _guiElements[to_U32(type)]) {
            element = guiStackIterator.second.first;
            if (element->getGUID() == elementID) {
                ret = element;
                break;
            }
        }
    }

    return ret;
}

// Return true if input was consumed
bool GUIInterface::mouseMoved(const GUIEvent& event) {
    for (U8 i = 0; i < to_base(GUIType::COUNT); ++i) {
        for (const GUIMap::value_type& guiStackIterator : _guiElements[i]) {
            if (guiStackIterator.second.first->mouseMoved(event)) {
                return true;
            }
        }
    }

    return false;
}

// Return true if input was consumed
bool GUIInterface::onMouseUp(const GUIEvent& event) {
    for (U8 i = 0; i < to_base(GUIType::COUNT); ++i) {
        for (const GUIMap::value_type& guiStackIterator : _guiElements[i]) {
            if (guiStackIterator.second.first->onMouseUp(event)) {
                return true;
            }
        }
    }

    return false;
}

// Return true if input was consumed
bool GUIInterface::onMouseDown(const GUIEvent& event) {
    for (U8 i = 0; i < to_base(GUIType::COUNT); ++i) {
        for (const GUIMap::value_type& guiStackIterator : _guiElements[i]) {
            if (guiStackIterator.second.first->onMouseDown(event)) {
                return true;
            }
        }
    }

    return false;
}


GUIButton* GUIInterface::addButton(U64 guiID,
                                   const stringImpl& name,
                                   const stringImpl& text,
                                   const RelativePosition2D& position,
                                   const RelativeScale2D& size,
                                   const stringImpl& rootSheetID) {
    assert(getGUIElement(guiID) == nullptr);

    CEGUI::Window* parent = _context->getCEGUIContext().getRootWindow();
    if (!rootSheetID.empty()) {
        parent = parent->getChild(rootSheetID.c_str());
    }

    ResourceDescriptor beepSound("buttonClick");
    beepSound.setResourceName("beep.wav");
    beepSound.setResourceLocation(Paths::g_assetsLocation + Paths::g_soundsLocation);
    beepSound.setFlag(false);
    AudioDescriptor_ptr onClickSound = CreateResource<AudioDescriptor>(_context->parent().resourceCache(), beepSound);

    GUIButton* btn = MemoryManager_NEW GUIButton(guiID,
                                                 name,
                                                 text,
                                                 _context->guiScheme(),
                                                 position,
                                                 size,
                                                 parent);

    btn->setEventSound(GUIButton::Event::MouseClick, onClickSound);

    addElement(guiID, btn);

    return btn;
}

GUIMessageBox* GUIInterface::addMsgBox(U64 guiID,
                                       const stringImpl& name,
                                       const stringImpl& title,
                                       const stringImpl& message,
                                       const vec2<I32>& offsetFromCentre) {
    assert(getGUIElement(guiID) == nullptr);

    GUIMessageBox* box = MemoryManager_NEW GUIMessageBox(guiID,
                                                         name,
                                                         title,
                                                         message,
                                                         offsetFromCentre,
                                                         _context->rootSheet());
    addElement(guiID, box);

    return box;
}

GUIText* GUIInterface::addText(U64 guiID,
                               const stringImpl& name,
                               const RelativePosition2D& position,
                               const stringImpl& font,
                               const UColour& colour,
                               const stringImpl& text,
                               U8 fontSize) {
    assert(getGUIElement(guiID) == nullptr);

    GUIText* t = MemoryManager_NEW GUIText(guiID,
                                           name,
                                           text,
                                           position,
                                           font,
                                           colour,
                                           _context->rootSheet(),
                                           fontSize);
    addElement(guiID, t);

    return t;
}

GUIFlash* GUIInterface::addFlash(U64 guiID,
                                 const stringImpl& name,
                                 stringImpl movie,
                                 const RelativePosition2D& position,
                                 const RelativeScale2D& size) {
    ACKNOWLEDGE_UNUSED(position);
    ACKNOWLEDGE_UNUSED(size);

    assert(getGUIElement(guiID) == nullptr);
    
    GUIFlash* flash = MemoryManager_NEW GUIFlash(guiID, name, _context->rootSheet());
    addElement(guiID, flash);

    return flash;
}

GUIText* GUIInterface::modifyText(U64 guiID, const stringImpl& text) {
    GUIMap::iterator it = _guiElements[to_base(GUIType::GUI_TEXT)].find(guiID);

    if (it == std::cend(_guiElements[to_base(GUIType::GUI_TEXT)])) {
        return nullptr;
    }

    GUIText* textElement = static_cast<GUIText*>(it->second.first);
    assert(textElement != nullptr);

    textElement->text(text);

    return textElement;
}

CEGUI::Window* GUIInterface::createWindow(const CEGUI::String& type, const CEGUI::String& name) {
    CEGUI::Window* window = CEGUI::WindowManager::getSingleton().createWindow(type, name);
    if (window != nullptr) {
        _context->rootSheet()->addChild(window);
    }

    return window;
}

CEGUI::Window* GUIInterface::loadWindowFromLayoutFile(const char* layoutFileName) {
    CEGUI::Window* window = CEGUI::WindowManager::getSingleton().loadLayoutFromFile(layoutFileName);
    if (window != nullptr) {
        _context->rootSheet()->addChild(window);
    }

    return window;
}

bool GUIInterface::unloadWindow(CEGUI::Window*& window) {
    if (_context->rootSheet()->isChild(window)) {
        _context->rootSheet()->destroyChild(window);
        window = nullptr;
        return true;
    }

    return false;
}
}; //namespace Divide

Commits for Divide-Framework/trunk/Source Code/GUI/GUIInterface.cpp

Diff revisions: vs.
Revision Author Commited Message
1019 Diff Diff IonutCava picture IonutCava Wed 17 Jan, 2018 17:17:12 +0000

[Ionut]
- Attempt to add a generic “create cegui window” system

1004 Diff Diff IonutCava picture IonutCava Wed 20 Dec, 2017 17:16:32 +0000

[Ionut]
- More GUI cleanup (added multiple GUIButton events)
- Typedef vec4<U8> and vec4<F32> to UColour and FColour respectively for easier to read code.

1003 Diff Diff IonutCava picture IonutCava Tue 19 Dec, 2017 17:08:06 +0000

[Ionut]
- GUI cleanup

980 Diff Diff IonutCava picture IonutCava Wed 22 Nov, 2017 17:18:46 +0000

[Ionut]
- Started porting CEGUI to RTT

979 Diff Diff IonutCava picture IonutCava Tue 21 Nov, 2017 23:24:57 +0000

[Ionut]
- W.I.P. Rework GUI element positioning and scaling
- Update ImGUI and IMGUI_ADDONS

978 Diff Diff IonutCava picture IonutCava Mon 20 Nov, 2017 23:42:23 +0000

[Ionut]
- More decoupling between window size and render resolution.
- Attempt to preserve render target aspect on window resize events

  • Resolution change is currently broken *
955 Diff Diff IonutCava picture IonutCava Sun 29 Oct, 2017 20:45:04 +0000

[Ionut]
- Modify the CEGUI opengl renderer to interact with the state in GLWrapper better
- Performance optimizations

909 Diff Diff IonutCava picture IonutCava Thu 29 Jun, 2017 23:57:18 +0000

[Ionut]
- Rework RenderTarget class
— RTAttachment now deal with textures directly
— RT size needs to be specified upfront
- Application class is no longer a Singleton but passed around in the PlatformContext

902 Diff Diff IonutCava picture IonutCava Sun 25 Jun, 2017 16:56:57 +0000

[Ionut]
- Rework input system a bit for easier maintenance and readability
- Toggle AntTweakBar display using CTRL+F11

895 IonutCava picture IonutCava Wed 21 Jun, 2017 21:10:26 +0000

[IonutCava]
- Reorder and cleanup OpenGL backend a bit.
- Small code cleanup
- Some small profile-guided optimizations