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
#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/ParamHandler.h"
#include "Core/Resources/Headers/ResourceCache.h"

#include "Core/Headers/Application.h"

namespace Divide {

GUIInterface::GUIInterface(GUI& context, const vec2<U16>& resolution)
    : _context(&context),
      _resolutionCache(resolution)
{
}

GUIInterface::~GUIInterface()
{
    for (GUIMap::value_type& it : _guiElements) {
        MemoryManager::DELETE(it.second.first);
    }
}

void GUIInterface::onChangeResolution(U16 w, U16 h) {
    for (const GUIMap::value_type& guiStackIterator : _guiElements) {
        guiStackIterator.second.first->onChangeResolution(w, h);
    }

    _resolutionCache.set(w, h);
}


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

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

GUIElement* GUIInterface::getGUIElementImpl(U64 elementName) const {
    GUIElement* ret = nullptr;
    GUIMap::const_iterator it = _guiElements.find(elementName);
    if (it != std::cend(_guiElements)) {
        ret = it->second.first;
    }


    return ret;
}

GUIElement* GUIInterface::getGUIElementImpl(I64 elementID) const {
    GUIElement* ret = nullptr;
    GUIElement* element = nullptr;
    for (const GUIMap::value_type& guiStackIterator : _guiElements) {
        element = guiStackIterator.second.first;
        if (element->getGUID() == elementID) {
            ret = element;
            break;
        }
    }

    return ret;
}


void GUIInterface::mouseMoved(const GUIEvent& event) {
    for (const GUIMap::value_type& guiStackIterator : _guiElements) {
        guiStackIterator.second.first->mouseMoved(event);
    }
}

void GUIInterface::onMouseUp(const GUIEvent& event) {
    for (const GUIMap::value_type& guiStackIterator : _guiElements) {
        guiStackIterator.second.first->onMouseUp(event);
    }
}

void GUIInterface::onMouseDown(const GUIEvent& event) {
    for (const GUIMap::value_type& guiStackIterator : _guiElements) {
        guiStackIterator.second.first->onMouseDown(event);
    }
}


GUIButton* GUIInterface::addButton(U64 guiID,
                                   const stringImpl& text,
                                   const vec2<I32>& position,
                                   const vec2<U32>& dimensions,
                                   ButtonCallback callback,
                                   const stringImpl& rootSheetID) {
    assert(getGUIElement(guiID) == nullptr);

    const vec2<U16>& resolution = getDisplayResolution();

    vec2<F32> relOffset((position.x * 100.0f) / resolution.width,
                        (position.y * 100.0f) / resolution.height);

    vec2<F32> relDim((dimensions.x * 100.0f) / resolution.width,
                     (dimensions.y * 100.0f) / resolution.height);

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

    if (!parent) {
        parent = _context->rootSheet();
    }

    stringImpl assetPath = ParamHandler::instance().getParam<stringImpl>(_ID("assetsLocation"));
    ResourceDescriptor beepSound("buttonClick");
    beepSound.setResourceLocation(assetPath + "/sounds/beep.wav");
    beepSound.setFlag(false);
    AudioDescriptor_ptr onClickSound = CreateResource<AudioDescriptor>(_context->activeScene()->resourceCache(), beepSound);

    GUIButton* btn = MemoryManager_NEW GUIButton(guiID, text, _context->guiScheme(), relOffset, relDim, parent, callback, onClickSound);

    addElement(guiID, btn);

    return btn;
}

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

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

    return box;
}

GUIText* GUIInterface::addText(U64 guiID,
                               const vec2<I32>& position,
                               const stringImpl& font,
                               const vec4<U8>& colour,
                               const stringImpl& text,
                               U32 fontSize) {
    assert(getGUIElement(guiID) == nullptr);

    GUIText* t = MemoryManager_NEW GUIText(guiID,
                                           text,
                                           vec2<F32>(position.width,
                                                     position.height),
                                           font,
                                           colour,
                                           _context->rootSheet(),
                                           fontSize);
    t->initialHeightCache(to_float(getDisplayResolution().height));
    addElement(guiID, t);

    return t;
}

GUIFlash* GUIInterface::addFlash(U64 guiID,
                                 stringImpl movie,
                                 const vec2<U32>& position,
                                 const vec2<U32>& extent) {
    assert(getGUIElement(guiID) == nullptr);

    GUIFlash* flash = MemoryManager_NEW GUIFlash(guiID, _context->rootSheet());
    addElement(guiID, flash);

    return flash;
}

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

    if (it == std::cend(_guiElements)) {
        return nullptr;
    }

    GUIElement* element = it->second.first;
    assert(element->getType() == GUIType::GUI_TEXT);

    GUIText* textElement = dynamic_cast<GUIText*>(element);
    assert(textElement != nullptr);

    textElement->text(text);

    return textElement;
}

const vec2<U16>& GUIInterface::getDisplayResolution() const {
    return _resolutionCache;
}

}; //namespace Divide

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

Diff revisions: vs.
Revision Author Commited Message
804 Diff Diff IonutCava picture IonutCava Thu 01 Dec, 2016 17:20:59 +0000

[IonutCava]
- Singleton elimination update Part I: get it to compile
— The following classes are no longer Singletons: GFXDevice, GL_API, DX_API, SFXWrapper, FmodWrapper, SDLWrapper, ALWrapper, PXDevice, InputInterface, RenderPassManager, SceneManager and ResourceManager;
— Refactor system to a Context / Component based implementation (Pass relevant context to objects: e.g. GFXDevice object to Textures, GUI to GUIElements, etc)
— Make devices and managers components of the kernel
— Allow multiple Resource caches to co-exist. This may prove useful for later when a more fragmented memory model is need (per frame / per scene / global caches / etc)

  • next steps: part II – cleanup/refactor new code, part III – optimise code, part IV – remove remaining Singletons (e.g. Application, ParamHandler, FrameListenerManager, Recast, PostFX and DebugInterface)
802 Diff Diff IonutCava picture IonutCava Tue 29 Nov, 2016 17:15:38 +0000

[IonutCava]
- GUI class is no longer a Singleton
- Reduced usage of GFXDevice::instance()

795 Diff Diff IonutCava picture IonutCava Wed 23 Nov, 2016 17:14:33 +0000

[IonutCava]
- Remove ULL. Use U64 instead
- Various small bug fixes and typos.

745 Diff Diff IonutCava picture IonutCava Wed 29 Jun, 2016 20:14:50 +0000

[IonutCava]
- Added on click sounds for buttons
- Added music playlist options for scenes (configurable via XML)
- Cache sound chunks and music files in SDLWrapper.cpp

721 Diff Diff IonutCava picture IonutCava Wed 08 Jun, 2016 15:47:49 +0000

[IonutCava]
- Spelling: change all references from our code of “color” to the PROPER British version of “colour” because it sounds 100x better

716 Diff Diff IonutCava picture IonutCava Tue 31 May, 2016 16:08:29 +0000

[IonutCava]
- Multithreaded scene load/unload fixes:
— Added postLoadMainThread call for scenes for thread sensitive loading steps
— GUI element adding is a thread sensitive loading step (a fast one) because CEGUI doesn’t handle threading
- Added REALTIME_WITH_CALLBACK task priority for tasks that need an immediate callback when they complete instead of using the flushCallbackQueue system.
- Some work on shadow mapping for getting it to work again
- ShaderPrograms that fail to load can cause a LockManager infinite wait. Delete the lockManager if the shader didn’t load to avoid waiting on commands that never get called.

715 IonutCava picture IonutCava Fri 27 May, 2016 16:19:22 +0000

[IonutCava]
- Added initial Fade In / Fade Out post effect (used for scene transitions for now)
- Added a GUI Interface that handles a list of GUI elements (used by GUI and SceneGUIElements)
- Fixed some race conditions related to multi-threaded scene loading (a lot remain to be fixed)
- Improved per-thread GPU sync system a bit
- Simplified Singleton define macros (although we should get rid of singletons all together)