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
#include "stdafx.h"

#include "Headers/GUI.h"
#include "Headers/GUIConsole.h"
#include "Headers/GUIConsoleCommandParser.h"
#include "CEGUIAddons/Headers/CEGUIFormattedListBox.h"

#include "Core/Headers/Console.h"
#include "Core/Headers/Configuration.h"
#include "Core/Headers/PlatformContext.h"
#include "Utility/Headers/Localization.h"

#include "Platform/Headers/PlatformRuntime.h"

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

namespace Divide {

namespace {
    /// Maximum number of lines to display in the console Window
    constexpr U32 _CEGUI_MAX_CONSOLE_ENTRIES = Config::Build::IS_DEBUG_BUILD ? 128 : 512;
};

GUIConsole::GUIConsole(GUI& parent, PlatformContext& context, ResourceCache& cache)
    : PlatformContextComponent(context),
      _parent(parent),
      _init(false),
      _closing(false),
      _editBox(nullptr),
      _lastMsgType(Console::EntryType::Info),
      _inputHistoryIndex(0),
      _consoleCallbackIndex(0),
      _outputWindow(nullptr),
      _consoleWindow(nullptr),
      _outputBuffer(_CEGUI_MAX_CONSOLE_ENTRIES)
{
    // we need a default command parser, so just create it here
    _cmdParser = MemoryManager_NEW GUIConsoleCommandParser(_context, cache);

    _consoleCallbackIndex = Console::bindConsoleOutput([this](const Console::OutputEntry& entry) {
        printText(entry);
    });
}

GUIConsole::~GUIConsole()
{
    Console::unbindConsoleOutput(_consoleCallbackIndex);
    _closing = true;

    if (_consoleWindow) {
        setVisible(false);
        _init = false;
        _parent.getCEGUIContext().getRootWindow()->removeChild(_consoleWindow);
        CEGUI::WindowManager::getSingletonPtr()->destroyWindow(_consoleWindow);
    }

    MemoryManager::DELETE(_cmdParser);

    _outputBuffer.clear();
}

void GUIConsole::createCEGUIWindow() {
    if (_init) {
        Console::errorfn(Locale::get(_ID("ERROR_CONSOLE_DOUBLE_INIT")));
    }
    // load the console Window from the layout file
    stringImpl layoutFile(_context.config().gui.consoleLayoutFile);
    _consoleWindow = CEGUI::WindowManager::getSingletonPtr()->loadLayoutFromFile(layoutFile.c_str());

    if (_consoleWindow) {
        // Add the Window to the GUI Root Sheet
        _parent.getCEGUIContext().getRootWindow()->addChild(_consoleWindow);
        _outputWindow = static_cast<CEGUI::Listbox*>(_consoleWindow->getChild("ChatBox"));
        _editBox = static_cast<CEGUI::Editbox*>(_consoleWindow->getChild("EditBox"));
        // Now register the handlers for the events (Clicking, typing, etc)
        RegisterHandlers();
    } else {
        // Loading layout from file, failed, so output an error Message.
        CEGUI::Logger::getSingleton().logEvent(
            "Error: Unable to load the ConsoleWindow from .layout");
        Console::errorfn(Locale::get(_ID("ERROR_CONSOLE_LAYOUT_FILE")),
                         layoutFile.c_str());
    }

    _consoleWindow->setVisible(false);
    _init = true;
    Console::printfn(Locale::get(_ID("GUI_CONSOLE_CREATED")));
}

void GUIConsole::RegisterHandlers() {
    assert(_editBox != nullptr);
    // We need to monitor text/command submission from the editBox
    _editBox->subscribeEvent(
        CEGUI::Editbox::EventTextAccepted,
        CEGUI::Event::Subscriber(&GUIConsole::Handle_TextSubmitted, this));
    // we also monitor any key presses to make sure we do not accidentally hide
    // the console in the middle of a sentence
    _editBox->subscribeEvent(
        CEGUI::Editbox::EventKeyUp,
        CEGUI::Event::Subscriber(&GUIConsole::Handle_TextInput, this));
}

bool GUIConsole::Handle_TextInput(const CEGUI::EventArgs& e) {
    assert(_editBox != nullptr);
    const CEGUI::KeyEventArgs* keyEvent =
        static_cast<const CEGUI::KeyEventArgs*>(&e);
    // Just get the current text string from the editbox at each keypress.
    // Performance isn't a issue for console commands
    if (!_inputHistory.empty()) {
        if (keyEvent->scancode == CEGUI::Key::ArrowUp) {
            _inputHistoryIndex--;
            if (_inputHistoryIndex < 0)
                _inputHistoryIndex = (I16)_inputHistory.size() - 1;
            _editBox->setText(_inputHistory[_inputHistoryIndex]);
        }
        if (keyEvent->scancode == CEGUI::Key::ArrowDown) {
            _inputHistoryIndex++;
            if (_inputHistoryIndex >= (I32)_inputHistory.size())
                _inputHistoryIndex = 0;
            _editBox->setText(_inputHistory[_inputHistoryIndex]);
        }
    }

    _inputBuffer = _editBox->getText();
    return true;
}

bool GUIConsole::Handle_TextSubmitted(const CEGUI::EventArgs& e) {
    assert(_editBox != nullptr);
    // Since we have that string, lets send it to the TextParser which will
    // handle it from here
    _cmdParser->processCommand(_inputBuffer.c_str());
    // Now that we've finished with the text, we need to ensure that we clear
    // out the EditBox.
    // This is what we would expect to happen after we press enter
    _editBox->setText("");
    _inputHistory.push_back(_inputBuffer);
    // Keep command history low
    if (_inputHistory.size() > _CEGUI_MAX_CONSOLE_ENTRIES) {
        _inputHistory.pop_front();
    }
    _inputHistoryIndex = (I16)_inputHistory.size() - 1;
    // reset the inputbuffer so we can handle console closing properly
    _inputBuffer.clear();
    return true;
}

void GUIConsole::setVisible(bool visible) {
    if (_init) {
        // if it's not the first key (e.g., if the toggle key is "~", then
        // "lorem~ipsum" should not close the Window)
        if (!_inputBuffer.empty()) {
            return;
        }
        assert(_editBox != nullptr);
        _consoleWindow->setVisible(visible);

        if (visible) {
            _editBox->activate();
        } else {
            _editBox->deactivate();
            _editBox->setText("");
        }

        printText(Console::OutputEntry(visible ? "Toggling console display: ON"
                                               : "Toggling console display: OFF",
                                       Console::EntryType::Info));
        size_t count = _outputWindow->getItemCount();
        if (count > 0 && visible) {
            _outputWindow->ensureItemIsVisible(count - 1);
        }
    }
}

bool GUIConsole::isVisible() {
    if (!_init) {
        return false;
    }
    return _consoleWindow->isVisible();
}

void GUIConsole::printText(const Console::OutputEntry& entry) {
    WriteLock w_lock(_outputLock);
    _outputBuffer.push_back(entry);
}

void GUIConsole::OutputText(const Console::OutputEntry& text) {
    if (_outputWindow->getItemCount() == _CEGUI_MAX_CONSOLE_ENTRIES - 1) {
        _outputWindow->removeItem(_outputWindow->getListboxItemFromIndex(0));
    }

    CEGUI::FormattedListboxTextItem* crtItem =
        new CEGUI::FormattedListboxTextItem(
            CEGUI::String(text._text),
            (text._type == Console::EntryType::Error 
                         ? CEGUI::Colour(1.0f, 0.0f, 0.0f)
                         : text._type == Console::EntryType::Warning 
                                      ? CEGUI::Colour(1.0f, 1.0f, 0.0f)
                                      : CEGUI::Colour(0.4f, 0.4f, 0.3f)),
            CEGUI::HTF_WORDWRAP_LEFT_ALIGNED);

    crtItem->setTextParsingEnabled(false);
    _outputWindow->addItem(crtItem);
    _outputWindow->ensureItemIsVisible(crtItem);
}

void GUIConsole::update(const U64 deltaTimeUS) {
    if (!_init || !Runtime::isMainThread() || _closing) {
        return;
    }
    if (!isVisible()) {
        return;
    }

    {
        UpgradableReadLock ur_lock(_outputLock);
        size_t entryCount = _outputBuffer.size();
        if (entryCount > 0) {
            for(size_t i = 0; i < entryCount; ++i) {
                const Console::OutputEntry& message = _outputBuffer[i];

                Console::EntryType type = message._type;
                if (_lastMsgType != type) {
                    _lastMsgType = type;
                    OutputText(message);
                    _lastMsg.clear();
                }
         
                _lastMsg.append(message._text.c_str());
                _lastMsg.append("\n");
            }
            UpgradeToWriteLock uw_lock(ur_lock);
            _outputBuffer.clear();
        }
    }

    if (!_lastMsg.empty()) {
        OutputText(Console::OutputEntry(_lastMsg.c_str(), _lastMsgType));
        _lastMsg.clear();
    }
}
};

Commits for Divide-Framework/trunk/Source Code/GUI/GUIConsole.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.

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

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

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

977 Diff Diff IonutCava picture IonutCava Mon 20 Nov, 2017 17:13:16 +0000

[Ionut]
- Add an “ApplicationOutput” class that the Editor uses to show console entries and parse commands
- Add “Warning” messages to console outputs

969 Diff Diff IonutCava picture IonutCava Mon 13 Nov, 2017 00:15:57 +0000

[Ionut]
- Further improve DisplayWindow <-> Input relationship
- Add Flip-Y 2D camera (D3D style projection)
- Fix IMGUI rendering
- Add IMGUI sample and IMWINDOW sample rendering at the same time
- Improve IMWINDOW multi-window support
— Bug: nothing rendering in child platform windows
- Add draw command to move render context from one window to another

968 Diff Diff IonutCava picture IonutCava Tue 07 Nov, 2017 17:32:31 +0000

[Ionut]
- Consistent naming between timing variables

952 Diff Diff IonutCava picture IonutCava Wed 25 Oct, 2017 00:35:37 +0000

[Ionut]
- Added the CEGUI rendering project to our solution for easier modification, debugging and integration
- Updated to OIS 1.4
- Some updates to the WindowHandle struct

  • Only compiled in Debug*
941 Diff Diff IonutCava picture IonutCava Mon 04 Sep, 2017 20:55:02 +0000

[Ionut]
- Update CEGUI from static to dynamic config (some dlls might still be missing)
- Attempt to work around a weird string issue with the newest VS2017 update

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

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