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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
#include "stdafx.h"

#include "Headers/GUI.h"
#include "Headers/SceneGUIElements.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/XMLEntryData.h"
#include "Core/Headers/Configuration.h"
#include "Core/Headers/PlatformContext.h"
#include "Core/Resources/Headers/ResourceCache.h"
#include "Core/Debugging/Headers/DebugInterface.h"

#include "Platform/Video/Headers/GFXDevice.h"
#include "Platform/Input/Headers/InputInterface.h"
#include "Platform/Video/Shaders/Headers/ShaderProgram.h"

#if !defined(CEGUI_STATIC)
#define CEGUI_STATIC
#endif
#include <CEGUI/CEGUI.h>

#include <stdarg.h>

namespace Divide {
namespace {
    GUIMessageBox* g_assertMsgBox = nullptr;
};

void DIVIDE_ASSERT_MSG_BOX(const char* failMessage) {
    if (g_assertMsgBox) {
        g_assertMsgBox->setTitle("Assertion Failed!");
        g_assertMsgBox->setMessage(stringImpl("Assert: ") + failMessage);
        g_assertMsgBox->setMessageType(GUIMessageBox::MessageType::MESSAGE_ERROR);
        g_assertMsgBox->show();
    }
}

GUI::GUI(Kernel& parent)
  : GUIInterface(*this),
    KernelComponent(parent),
    _ceguiInput(*this),
    _init(false),
    _rootSheet(nullptr),
    _defaultMsgBox(nullptr),
    _debugVarCacheCount(0),
    _activeScene(nullptr),
    _console(nullptr),
    _ceguiContext(nullptr),
    _ceguiRenderer(nullptr),
    _ceguiRenderTextureTarget(nullptr),
    _textRenderInterval(Time::MillisecondsToMicroseconds(10))
{
    // 500ms
    _ceguiInput.setInitialDelay(0.500f);
}

GUI::~GUI()
{
    destroy();
}

void GUI::onChangeScene(Scene* newScene) {
    assert(newScene != nullptr);
    ReadLock r_lock(_guiStackLock);
    if (_activeScene != nullptr && _activeScene->getGUID() != newScene->getGUID()) {
        GUIMapPerScene::const_iterator it = _guiStack.find(_activeScene->getGUID());
        if (it != std::cend(_guiStack)) {
            it->second->onDisable();
        }
    }

    GUIMapPerScene::const_iterator it = _guiStack.find(newScene->getGUID());
    if (it != std::cend(_guiStack)) {
        it->second->onEnable();
    } else {
        SceneGUIElements* elements = Attorney::SceneGUI::guiElements(*newScene);
        hashAlg::insert(_guiStack, newScene->getGUID(), elements);
        elements->onEnable();
    }

    _activeScene = newScene;
}

void GUI::onUnloadScene(Scene* scene) {
    assert(scene != nullptr);
    WriteLock w_lock(_guiStackLock);
    GUIMapPerScene::const_iterator it = _guiStack.find(scene->getGUID());
    if (it != std::cend(_guiStack)) {
        _guiStack.erase(it);
    }
}

void GUI::draw(GFXDevice& context, GFX::CommandBuffer& bufferInOut) {
    if (!_init || !_activeScene) {
        return;
    }

    TextElementBatch textBatch;
    for (const GUIMap::value_type& guiStackIterator : _guiElements[to_base(GUIType::GUI_TEXT)]) {
        GUIText& textLabel = static_cast<GUIText&>(*guiStackIterator.second.first);
        if (textLabel.isVisible() && !textLabel.text().empty()) {
            textBatch._data.push_back(textLabel);
        }
    }

    if (!textBatch().empty()) {
        Attorney::GFXDeviceGUI::drawText(context, textBatch, bufferInOut);
    }

    ReadLock r_lock(_guiStackLock);
    // scene specific
    GUIMapPerScene::const_iterator it = _guiStack.find(_activeScene->getGUID());
    if (it != std::cend(_guiStack)) {
        it->second->draw(context, bufferInOut);
    }

    if (parent().platformContext().config().gui.cegui.enabled) {
        if (!parent().platformContext().config().gui.cegui.skipRendering) {
            _ceguiRenderer->beginRendering();

            _ceguiRenderTextureTarget->clear();
            getCEGUIContext().draw();

            _ceguiRenderer->endRendering();

            context.drawFullscreenTexture(getCEGUIRenderTextureData(), bufferInOut);
        }
    }
}

void GUI::update(const U64 deltaTimeUS) {
    if (!_init) {
        return;
    }

    if (parent().platformContext().config().gui.cegui.enabled) {
        _ceguiInput.update(deltaTimeUS);
        CEGUI::System::getSingleton().injectTimePulse(Time::MicrosecondsToSeconds<F32>(deltaTimeUS));
        CEGUI::System::getSingleton().getDefaultGUIContext().injectTimePulse(Time::MicrosecondsToSeconds<F32>(deltaTimeUS));
    }

    if (_console) {
        _console->update(deltaTimeUS);
    }
}

bool GUI::init(PlatformContext& context, ResourceCache& cache, const vec2<U16>& renderResolution) {
    if (_init) {
        Console::d_errorfn(Locale::get(_ID("ERROR_GUI_DOUBLE_INIT")));
        return false;
    }
    _defaultGUIScheme = context.config().gui.cegui.defaultGUIScheme;

    _console = MemoryManager_NEW GUIConsole(*this, context, cache);

    if (Config::Build::IS_DEBUG_BUILD) {
        CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative);
    }

    CEGUI::DefaultResourceProvider* rp
        = static_cast<CEGUI::DefaultResourceProvider*>(CEGUI::System::getSingleton().getResourceProvider());

    CEGUI::String CEGUIInstallSharePath(Paths::g_assetsLocation + Paths::g_GUILocation);
    rp->setResourceGroupDirectory("schemes", CEGUIInstallSharePath + "schemes/");
    rp->setResourceGroupDirectory("imagesets", CEGUIInstallSharePath + "imagesets/");
    rp->setResourceGroupDirectory("fonts", CEGUIInstallSharePath + Paths::g_fontsPath);
    rp->setResourceGroupDirectory("layouts", CEGUIInstallSharePath + "layouts/");
    rp->setResourceGroupDirectory("looknfeels", CEGUIInstallSharePath + "looknfeel/");
    rp->setResourceGroupDirectory("lua_scripts", CEGUIInstallSharePath + "lua_scripts/");
    rp->setResourceGroupDirectory("schemas", CEGUIInstallSharePath + "xml_schemas/");
    rp->setResourceGroupDirectory("animations", CEGUIInstallSharePath + "animations/");

    // set the default resource groups to be used
    CEGUI::ImageManager::setImagesetDefaultResourceGroup("imagesets");
    CEGUI::Font::setDefaultResourceGroup("fonts");
    CEGUI::Scheme::setDefaultResourceGroup("schemes");
    CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeels");
    CEGUI::WindowManager::setDefaultResourceGroup("layouts");
    CEGUI::ScriptModule::setDefaultResourceGroup("lua_scripts");
    // setup default group for validation schemas
    CEGUI::XMLParser* parser = CEGUI::System::getSingleton().getXMLParser();
    if (parser->isPropertyPresent("SchemaDefaultResourceGroup")) {
        parser->setProperty("SchemaDefaultResourceGroup", "schemas");
    }
    CEGUI::FontManager::getSingleton().createFromFile("DejaVuSans-10.font");
    CEGUI::FontManager::getSingleton().createFromFile("DejaVuSans-12.font");
    CEGUI::FontManager::getSingleton().createFromFile("DejaVuSans-10-NoScale.font");
    CEGUI::FontManager::getSingleton().createFromFile("DejaVuSans-12-NoScale.font");
    CEGUI::SchemeManager::getSingleton().createFromFile((_defaultGUIScheme + ".scheme").c_str());

    _rootSheet = CEGUI::WindowManager::getSingleton().createWindow("DefaultWindow", "root_window");
    _rootSheet->setMousePassThroughEnabled(true);
    _rootSheet->setUsingAutoRenderingSurface(false);
    _rootSheet->setPixelAligned(false);

    CEGUI::Sizef size(static_cast<float>(renderResolution.width), static_cast<float>(renderResolution.height));
    // We create a CEGUI texture target and create a GUIContext that will use it.
    _ceguiRenderTextureTarget = CEGUI::System::getSingleton().getRenderer()->createTextureTarget();
    _ceguiRenderTextureTarget->declareRenderSize(size);
    _ceguiContext = &CEGUI::System::getSingleton().createGUIContext(static_cast<CEGUI::RenderTarget&>(*_ceguiRenderTextureTarget));

    getCEGUIContext().setRootWindow(_rootSheet);
    getCEGUIContext().setDefaultTooltipType((_defaultGUIScheme + "/Tooltip").c_str());
    _ceguiRenderer = CEGUI::System::getSingleton().getRenderer();
    assert(_console);
    
    _console->createCEGUIWindow();

    _defaultMsgBox = addMsgBox(_ID("AssertMsgBox"),
                               "Assertion failure",
                               "Assertion failed with message: ");

    g_assertMsgBox = _defaultMsgBox;

    GUIButton::soundCallback([&context](const AudioDescriptor_ptr& sound) { context.sfx().playSound(sound); });

    if (parent().platformContext().config().gui.cegui.enabled) {
        CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Sizef(renderResolution.width, renderResolution.height));
    }

    _init = true;
    return true;
}

void GUI::destroy() {
    if (_init) {
        Console::printfn(Locale::get(_ID("STOP_GUI")));
        MemoryManager::DELETE(_console);

        {
            WriteLock w_lock(_guiStackLock);
            assert(_guiStack.empty());
            for (U8 i = 0; i < to_base(GUIType::COUNT); ++i) {
                for (GUIMap::value_type& it : _guiElements[i]) {
                    MemoryManager::DELETE(it.second.first);
                }
                _guiElements[i].clear();
            }
        }

        _defaultMsgBox = nullptr;
        g_assertMsgBox = nullptr;
        // Close CEGUI
        try {
            CEGUI::System::destroy();
        }
        catch (...) {
            Console::d_errorfn(Locale::get(_ID("ERROR_CEGUI_DESTROY")));
        }
        _init = false;
    }
}

void GUI::onSizeChange(const SizeChangeParams& params) {
    if ((!params.window || params.isFullScreen) && parent().platformContext().config().gui.cegui.enabled) {
        CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Sizef(params.width, params.height));
    }

    ReadLock r_lock(_guiStackLock);
    if (!_guiStack.empty()) {
        // scene specific
        GUIMapPerScene::const_iterator it = _guiStack.find(_activeScene->getGUID());
        if (it != std::cend(_guiStack)) {
            it->second->onSizeChange(params);
        }
    }

    GUIInterface::onSizeChange(params);
}

void GUI::selectionChangeCallback(Scene* const activeScene, PlayerIndex idx) {
    ACKNOWLEDGE_UNUSED(activeScene);
    ACKNOWLEDGE_UNUSED(idx);
}

void GUI::setCursorPosition(I32 x, I32 y) {
    if (parent().platformContext().config().gui.cegui.enabled) {
        getCEGUIContext().injectMousePosition(to_F32(x), to_F32(y));
    }
}

// Return true if input was consumed
bool GUI::onKeyDown(const Input::KeyEvent& key) {
    if (!_init) {
        return false;
    }

    if (parent().platformContext().config().gui.cegui.enabled) {
        return _ceguiInput.onKeyDown(key);
    }

    return false;
}

// Return true if input was consumed
bool GUI::onKeyUp(const Input::KeyEvent& key) {
    if (!_init) {
        return false;
    }

    if (parent().platformContext().config().gui.cegui.enabled) {
        return _ceguiInput.onKeyUp(key);
    }

    return false;
}

// Return true if input was consumed
bool GUI::mouseMoved(const Input::MouseEvent& arg) {
    if (!_init) {
        return false;
    }

    GUIEvent event;
    event.mousePoint.set(arg.X().abs, arg.Y().abs);

    if (GUIInterface::mouseMoved(event)) {
        return true;
    }

    // scene specific
    ReadLock r_lock(_guiStackLock);
    GUIMapPerScene::const_iterator it = _guiStack.find(_activeScene->getGUID());
    if (it != std::cend(_guiStack)) {
        if (it->second->mouseMoved(event)) {
            return true;
        }
    }

    if (parent().platformContext().config().gui.cegui.enabled) {
        return _ceguiInput.mouseMoved(arg);
    }

    return false;
}

// Return true if input was consumed
bool GUI::mouseButtonPressed(const Input::MouseEvent& arg,
                             Input::MouseButton button) {
    if (!_init) {
        return false;
    }

    bool consumed = false;
    if (parent().platformContext().config().gui.cegui.enabled) {
        consumed = _ceguiInput.mouseButtonPressed(arg, button);
    }

    if (!consumed) {
        if (button == Input::MouseButton::MB_Left) {
            GUIEvent event;
            event.mouseClickCount = 0;

            if (GUIInterface::onMouseDown(event)) {
                return true;
            }

            // scene specific
            ReadLock r_lock(_guiStackLock);
            GUIMapPerScene::const_iterator it = _guiStack.find(_activeScene->getGUID());
            if (it != std::cend(_guiStack)) {
                if (it->second->onMouseDown(event)) {
                    return true;
                }
            }
        }
    }

    return consumed;
}

// Return true if input was consumed
bool GUI::mouseButtonReleased(const Input::MouseEvent& arg,
                              Input::MouseButton button) {
    if (!_init) {
        return false;
    }

    bool consumed = false;
    if (parent().platformContext().config().gui.cegui.enabled) {
        consumed = _ceguiInput.mouseButtonReleased(arg, button);
    }

    if (!consumed) {
        if (button == Input::MouseButton::MB_Left) {
            GUIEvent event;
            event.mouseClickCount = 1;

            if (GUIInterface::onMouseUp(event)) {
                return true;
            }

            // scene specific
            ReadLock r_lock(_guiStackLock);
            GUIMapPerScene::const_iterator it = _guiStack.find(_activeScene->getGUID());
            if (it != std::cend(_guiStack)) {
                if (it->second->onMouseUp(event)) {
                    return true;
                }
            }
        }
    }

    return consumed;
}

// Return true if input was consumed
bool GUI::joystickAxisMoved(const Input::JoystickEvent& arg, I8 axis) {
    if (parent().platformContext().config().gui.cegui.enabled) {
        return _ceguiInput.joystickAxisMoved(arg, axis);
    }

    return false;
}

// Return true if input was consumed
bool GUI::joystickPovMoved(const Input::JoystickEvent& arg, I8 pov) {
    if (parent().platformContext().config().gui.cegui.enabled) {
        return _ceguiInput.joystickPovMoved(arg, pov);
    }

    return false;
}

// Return true if input was consumed
bool GUI::joystickButtonPressed(const Input::JoystickEvent& arg,
                                Input::JoystickButton button) {
    if (parent().platformContext().config().gui.cegui.enabled) {
        return _ceguiInput.joystickButtonPressed(arg, button);
    }

    return false;
}

// Return true if input was consumed
bool GUI::joystickButtonReleased(const Input::JoystickEvent& arg,
                                 Input::JoystickButton button) {
    if (parent().platformContext().config().gui.cegui.enabled) {
        return _ceguiInput.joystickButtonReleased(arg, button);
    }

    return false;
}

// Return true if input was consumed
bool GUI::joystickSliderMoved(const Input::JoystickEvent& arg, I8 index) {
    if (parent().platformContext().config().gui.cegui.enabled) {
        return _ceguiInput.joystickSliderMoved(arg, index);
    }

    return false;
}

// Return true if input was consumed
bool GUI::joystickvector3Moved(const Input::JoystickEvent& arg, I8 index) {
    if (parent().platformContext().config().gui.cegui.enabled) {
        return _ceguiInput.joystickvector3Moved(arg, index);
    }

    return false;
}

GUIElement* GUI::getGUIElementImpl(I64 sceneID, U64 elementName, GUIType type) const {
    if (sceneID != 0) {
        ReadLock r_lock(_guiStackLock);
        GUIMapPerScene::const_iterator it = _guiStack.find(sceneID);
        if (it != std::cend(_guiStack)) {
            return it->second->getGUIElement(elementName);
        }
    } else {
        return GUIInterface::getGUIElementImpl(elementName, type);
    }

    return nullptr;
}

GUIElement* GUI::getGUIElementImpl(I64 sceneID, I64 elementID, GUIType type) const {
    if (sceneID != 0) {
        ReadLock r_lock(_guiStackLock);
        GUIMapPerScene::const_iterator it = _guiStack.find(sceneID);
        if (it != std::cend(_guiStack)) {
            return it->second->getGUIElement(elementID);
        }
    } else {
        return GUIInterface::getGUIElementImpl(elementID, type);
    }

    return nullptr;
}
CEGUI::GUIContext& GUI::getCEGUIContext() {
    assert(_ceguiContext != nullptr);
    return *_ceguiContext;
}

const CEGUI::GUIContext& GUI::getCEGUIContext() const {
    assert(_ceguiContext != nullptr);
    return *_ceguiContext;
}

TextureData GUI::getCEGUIRenderTextureData() const {
    TextureData ret;

    if (_ceguiRenderTextureTarget != nullptr) {
        const GFXDevice& gfx = _context->parent().platformContext().gfx();
        ret.setHandle(gfx.getHandleFromCEGUITexture(_ceguiRenderTextureTarget->getTexture()));
    }

    return ret;
}
};

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

Diff revisions: vs.
Revision Author Commited Message
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.

1002 Diff Diff IonutCava picture IonutCava Mon 18 Dec, 2017 17:31:54 +0000

[Ionut]
- Cleanup GUI a bit
- Disable some nVidia GL warnings

987 Diff Diff IonutCava picture IonutCava Thu 30 Nov, 2017 17:19:21 +0000

[Ionut]
- glBlendFuncSeparate changes the blend mode for ALL buffers, so adjust code to handle this. This also fixes CEGUI rendering
- Fix CEGUI crashing on shutdown

986 Diff Diff IonutCava picture IonutCava Wed 29 Nov, 2017 23:24:51 +0000

[Ionut]
- Fix an issue with imgui_addons saving and loading layouts

984 Diff Diff IonutCava picture IonutCava Mon 27 Nov, 2017 17:42:23 +0000

[Ionut]
- Fix viewport adjustment on window resize

983 Diff Diff IonutCava picture IonutCava Sun 26 Nov, 2017 23:34:26 +0000

[Ionut]
- Finishing up CEGUI RTT rendering. Still have alpha issues

982 Diff Diff IonutCava picture IonutCava Thu 23 Nov, 2017 18:27:19 +0000

[Ionut]
- Oups

981 Diff Diff IonutCava picture IonutCava Thu 23 Nov, 2017 18:24:51 +0000

[Ionut]
- More work on porting CEGUI to RTT

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

[Ionut]
- Started porting CEGUI to RTT

979 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