Browse Source

Console now made with imgui

Thomas Buck 9 years ago
parent
commit
cb8108aed5

+ 6
- 0
ChangeLog.md View File

@@ -2,12 +2,18 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20140905 ]
6
+    * Recreated working console using imgui
7
+
5 8
     [ 20140904 ]
6 9
     * Fixed imgui colors
7 10
     * World now using smart pointers
8 11
     * Removed atexit handler, now breaking out of main loop on quit
9 12
     * Added calculate and shutdown calls to UI interface, properly shutting down imgui
10 13
     * Created Log class holding logging infos, used by others instead of Console.
14
+    * Removed Console, Debug
15
+    * Removed new fancy UI handling system
16
+    * Properly integrated imgui into UI system
11 17
 
12 18
     [ 20140903 ]
13 19
     * Finishing imgui integration, but now as UI layer and not on top of everything

+ 0
- 3
README.md View File

@@ -108,7 +108,6 @@ OpenRaider tries to load a `MAIN.SFX` from the same folder as the selected level
108 108
 | Key               | Action                |
109 109
 | -----------------:|:--------------------- |
110 110
 | &lt;Esc&gt;       | Toggle menu           |
111
-| &lt;backquote&gt; | Console toggle on/off |
112 111
 | q                 | Toggle debug windows  |
113 112
 | w                 | Move forward          |
114 113
 | s                 | Move back             |
@@ -178,7 +177,5 @@ See the respective files in `cmake` for their licensing.
178 177
 
179 178
 The [clibs/commander](https://github.com/clibs/commander) dependency is Copyright (c) 2012 TJ Holowaychuk (tj@vision-media.ca) and licensed under the [MIT License](http://opensource.org/licenses/MIT).
180 179
 
181
-The included [utf8-cpp](http://utfcpp.sourceforge.net) headers are Copyright (c) 2006 Nemanja Trifunovic. See the files in src/deps/utf8-cpp/ for informations about the license used.
182
-
183 180
 The included GUI lib, [imgui](https://github.com/ocornut/imgui/) is Copyright (c) 2014 Omar Cornut. See src/deps/imgui/LICENSE for more informations about the MIT license used.
184 181
 

+ 0
- 1
data/OpenRaider.ini View File

@@ -21,7 +21,6 @@ set mouse_x    0.75
21 21
 set mouse_y    0.75
22 22
 
23 23
 bind menu     "escape"
24
-bind console  "backquote"
25 24
 bind debug    'q'
26 25
 bind forward  'w'
27 26
 bind backward 's'

+ 0
- 48
include/Console.h View File

@@ -1,48 +0,0 @@
1
-/*!
2
- * \file include/Console.h
3
- * \brief Console 'overlay'
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#ifndef _CONSOLE_H_
9
-#define _CONSOLE_H_
10
-
11
-#include <string>
12
-#include <vector>
13
-
14
-#include "UI.h"
15
-
16
-/*!
17
- * \brief Console 'overlay'
18
- */
19
-class Console : public UI {
20
-public:
21
-
22
-    Console();
23
-    ~Console();
24
-
25
-    virtual void moveToTop();
26
-    virtual void makeInvisible();
27
-    virtual void display();
28
-    virtual void handleKeyboard(KeyboardButton key, bool pressed);
29
-    virtual void handleText(char *text, bool notFinished);
30
-    virtual void handleMouseScroll(int xrel, int yrel);
31
-
32
-private:
33
-
34
-    void moveInHistory(bool up);
35
-
36
-    std::string mInputBuffer;
37
-    std::string mPartialInput;
38
-
39
-    size_t mHistoryPointer;
40
-    std::vector<std::string> mCommandHistory;
41
-    std::string mUnfinishedInput;
42
-
43
-    unsigned int mLineOffset;
44
-};
45
-
46
-Console &getConsole();
47
-
48
-#endif

+ 0
- 41
include/Debug.h View File

@@ -1,41 +0,0 @@
1
-/*!
2
- * \file include/Debug.h
3
- * \brief Debug UI
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#ifndef _DEBUG_H_
9
-#define _DEBUG_H_
10
-
11
-#include "UI.h"
12
-
13
-class Debug : public UI {
14
-public:
15
-    Debug();
16
-    virtual ~Debug();
17
-
18
-    virtual int initialize();
19
-    virtual void eventsFinished();
20
-    virtual void display();
21
-    virtual void calculate();
22
-    virtual void shutdown();
23
-
24
-    virtual void handleKeyboard(KeyboardButton key, bool pressed);
25
-    virtual void handleText(char *text, bool notFinished);
26
-    virtual void handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released);
27
-    virtual void handleMouseMotion(int xrel, int yrel, int xabs, int yabs);
28
-    virtual void handleMouseScroll(int xrel, int yrel);
29
-
30
-private:
31
-    static void renderImGui(ImDrawList** const draw_lists, int count);
32
-
33
-    static unsigned int fontTex;
34
-    std::string iniFilename;
35
-    std::string logFilename;
36
-};
37
-
38
-Debug &getDebug();
39
-
40
-#endif
41
-

+ 5
- 11
include/Game.h View File

@@ -12,19 +12,15 @@
12 12
 #include <vector>
13 13
 
14 14
 #include "Entity.h"
15
-#include "UI.h"
16 15
 #include "TombRaider.h"
17 16
 
18
-/*!
19
- * \brief Game abstraction
20
- */
21
-class Game : public UI {
17
+class Game {
22 18
 public:
23 19
 
24 20
     Game();
25 21
     ~Game();
26 22
 
27
-    virtual int initialize();
23
+    int initialize();
28 24
 
29 25
     bool isLoaded();
30 26
 
@@ -32,11 +28,9 @@ public:
32 28
 
33 29
     void destroy();
34 30
 
35
-    virtual void display();
36
-    virtual void handleAction(ActionEvents action, bool isFinished);
37
-    virtual void handleMouseMotion(int xrel, int yrel, int xabs, int yabs);
38
-    virtual void moveToTop() { }
39
-    virtual void makeInvisible() { }
31
+    void display();
32
+    void handleAction(ActionEvents action, bool isFinished);
33
+    void handleMouseMotion(int xrel, int yrel, int xabs, int yabs);
40 34
 
41 35
     unsigned int getTextureStart();
42 36
     unsigned int getTextureOffset();

+ 16
- 6
include/Menu.h View File

@@ -10,18 +10,26 @@
10 10
 
11 11
 #include <functional>
12 12
 
13
-#include "UI.h"
14
-
15
-/*!
16
- * \brief Menu 'overlay'
17
- */
18
-class Menu : public UI {
13
+class Menu {
19 14
 public:
20 15
 
21 16
     virtual ~Menu() { }
22 17
 
23 18
     virtual int initialize() = 0;
24 19
 
20
+    virtual void display() = 0;
21
+
22
+    virtual void handleKeyboard(KeyboardButton key, bool pressed) = 0;
23
+
24
+    virtual void handleMouseClick(unsigned int x, unsigned int y,
25
+            KeyboardButton button, bool released) = 0;
26
+
27
+    virtual void handleMouseScroll(int xrel, int yrel) = 0;
28
+
29
+    bool isVisible() { return visible; }
30
+
31
+    void setVisible(bool v) { visible = v; }
32
+
25 33
 protected:
26 34
 
27 35
     virtual void showDialog(std::string msg, std::string btn1, std::string btn2,
@@ -43,6 +51,8 @@ protected:
43 51
     std::string dialogButton1;
44 52
     std::string dialogButton2;
45 53
     std::function<int (bool state)> dialogFunction;
54
+
55
+    bool visible;
46 56
 };
47 57
 
48 58
 Menu &getMenu();

+ 2
- 1
include/MenuFolder.h View File

@@ -31,7 +31,8 @@ public:
31 31
 
32 32
     virtual void display();
33 33
     virtual void handleKeyboard(KeyboardButton key, bool pressed);
34
-    virtual void handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released);
34
+    virtual void handleMouseClick(unsigned int x, unsigned int y,
35
+            KeyboardButton button, bool released);
35 36
     virtual void handleMouseScroll(int xrel, int yrel);
36 37
 
37 38
 private:

+ 24
- 42
include/UI.h View File

@@ -9,59 +9,41 @@
9 9
 #define _UI_H_
10 10
 
11 11
 #include <functional>
12
+#include <list>
12 13
 #include <memory>
13
-#include <vector>
14
+#include <tuple>
14 15
 
15 16
 #include "imgui/imgui.h"
16 17
 
17 18
 class UI {
18 19
 public:
19
-    virtual ~UI();
20
+    static int initialize();
21
+    static void eventsFinished();
22
+    static void display();
23
+    static void calculate();
24
+    static void shutdown();
20 25
 
21
-    virtual int initialize();
22
-    virtual void eventsFinished();
23
-    virtual void display();
24
-    virtual void calculate();
25
-    virtual void shutdown();
26
+    static void setVisible(bool v);
27
+    static bool isVisible();
26 28
 
27
-    virtual void handleKeyboard(KeyboardButton key, bool pressed);
28
-    virtual void handleText(char *text, bool notFinished);
29
-    virtual void handleAction(ActionEvents action, bool isFinished);
30
-    virtual void handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released);
31
-    virtual void handleMouseMotion(int xrel, int yrel, int xabs, int yabs);
32
-    virtual void handleMouseScroll(int xrel, int yrel);
33
-
34
-    virtual bool isOnTop();
35
-    virtual void moveToTop();
36
-    virtual void makeInvisible();
37
-
38
-    // ----------------------------------
39
-
40
-    static int passInitialize();
41
-    static void passEvents();
42
-    static void passDisplay();
43
-    static void passCalculate();
44
-    static void passShutdown();
45
-    static void passKeyboard(KeyboardButton key, bool pressed);
46
-    static void passText(char *text, bool notFinished);
47
-    static void passMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released);
48
-    static void passMouseMotion(int xrel, int yrel, int xabs, int yabs);
49
-    static void passMouseScroll(int xrel, int yrel);
50
-
51
-protected:
52
-    static void addWindow(UI* window);
53
-    static void removeWindow(UI *window);
54
-
55
-    long zPos;
29
+    static void handleKeyboard(KeyboardButton key, bool pressed);
30
+    static void handleText(char *text, bool notFinished);
31
+    static void handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released);
32
+    static void handleMouseMotion(int xrel, int yrel, int xabs, int yabs);
33
+    static void handleMouseScroll(int xrel, int yrel);
56 34
 
57 35
 private:
58
-    static void findInList(UI *w, std::function<void (unsigned long i)> func);
59
-    static bool isOnTop(unsigned long windowID);
60
-    static void moveToTop(unsigned long windowID);
61
-    static void makeInvisible(unsigned long windowID);
62
-    static bool compareUIs(UI* a, UI* b);
36
+    static void renderImGui(ImDrawList** const draw_lists, int count);
37
+
38
+    static bool visible;
39
+    static unsigned int fontTex;
40
+    static std::string iniFilename;
41
+    static std::string logFilename;
63 42
 
64
-    static std::vector<UI*> windows;
43
+    static std::list<std::tuple<KeyboardButton, bool>> keyboardEvents;
44
+    static std::list<std::tuple<unsigned int, unsigned int, KeyboardButton, bool>> clickEvents;
45
+    static std::list<std::tuple<int, int, int, int>> motionEvents;
46
+    static std::list<std::tuple<int, int>> scrollEvents;
65 47
 };
66 48
 
67 49
 #endif

+ 0
- 1
include/global.h View File

@@ -42,7 +42,6 @@ const unsigned char CYAN[]   = {   0, 255, 255, 255 };
42 42
 // Actions that can be bound to a key and sent to the game engine
43 43
 typedef enum {
44 44
     menuAction = 0,
45
-    consoleAction,
46 45
     debugAction,
47 46
 
48 47
     forwardAction,

+ 0
- 2
src/CMakeLists.txt View File

@@ -48,8 +48,6 @@ endif (PNG_FOUND)
48 48
 
49 49
 # Set Source files
50 50
 set (SRCS ${SRCS} "Camera.cpp")
51
-set (SRCS ${SRCS} "Console.cpp")
52
-set (SRCS ${SRCS} "Debug.cpp")
53 51
 set (SRCS ${SRCS} "Entity.cpp")
54 52
 set (SRCS ${SRCS} "Exception.cpp")
55 53
 set (SRCS ${SRCS} "Font.cpp")

+ 0
- 216
src/Console.cpp View File

@@ -1,216 +0,0 @@
1
-/*!
2
- * \file src/Console.cpp
3
- * \brief Console 'overlay'
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#include <iostream>
9
-
10
-#include "global.h"
11
-#include "commands/Command.h"
12
-#include "Font.h"
13
-#include "Log.h"
14
-#include "utf8-cpp/utf8.h"
15
-#include "utils/strings.h"
16
-#include "utils/time.h"
17
-#include "Window.h"
18
-#include "Console.h"
19
-
20
-Console::Console() {
21
-    zPos = -1;
22
-    mHistoryPointer = 0;
23
-    mLineOffset = 0;
24
-
25
-    UI::addWindow(this);
26
-}
27
-
28
-Console::~Console() {
29
-    UI::removeWindow(this);
30
-}
31
-
32
-void Console::moveToTop() {
33
-    if (!getWindow().getTextInput())
34
-        getWindow().setTextInput(true);
35
-
36
-    UI::moveToTop();
37
-}
38
-
39
-void Console::makeInvisible() {
40
-    if (getWindow().getTextInput())
41
-        getWindow().setTextInput(false);
42
-
43
-    UI::makeInvisible();
44
-}
45
-
46
-void Console::display() {
47
-    // Calculate line drawing geometry
48
-    // Depends on window height, so recalculate every time
49
-    unsigned int firstLine = 35;
50
-    unsigned int lastLine = (::getWindow().getHeight() / 2) - 55;
51
-    unsigned int inputLine = (::getWindow().getHeight() / 2) - 30;
52
-    unsigned int lineSteps = 20;
53
-    unsigned int lineCount = (lastLine - firstLine + lineSteps) / lineSteps;
54
-    while (((lineCount * lineSteps) + firstLine) < inputLine) {
55
-        lineSteps++;
56
-        lineCount = (lastLine - firstLine + lineSteps) / lineSteps;
57
-    }
58
-
59
-    ::getWindow().glEnter2D();
60
-
61
-    // Draw half-transparent *overlay*
62
-    glColor4f(0.0f, 0.0f, 0.0f, 0.75f);
63
-    glDisable(GL_TEXTURE_2D);
64
-    glRecti(0, 0, ::getWindow().getWidth(), ::getWindow().getHeight() / 2);
65
-    glEnable(GL_TEXTURE_2D);
66
-
67
-    unsigned long scrollIndicator;
68
-    if (getLog().size() > lineCount) {
69
-        scrollIndicator = (getLog().size() - lineCount - mLineOffset) * 100 / (getLog().size() - lineCount);
70
-    } else {
71
-        scrollIndicator = 100;
72
-        mLineOffset = 0;
73
-    }
74
-
75
-    // Draw status line
76
-    std::ostringstream status;
77
-    status << VERSION << " uptime " << (systemTimerGet() / 1000) << "s scroll " << scrollIndicator << "%";
78
-    getFont().drawText(10, 10, 0.70f, BLUE, status.str());
79
-
80
-    // Draw output log
81
-    long end = lineCount;
82
-    long drawOffset = 0;
83
-    long historyOffset = 0;
84
-    if (getLog().size() < lineCount) {
85
-        end = getLog().size();
86
-        drawOffset = lineCount - getLog().size();
87
-    } else if (lineCount < getLog().size()) {
88
-        historyOffset = getLog().size() - lineCount;
89
-    }
90
-
91
-    for (int i = 0; i < end; i++) {
92
-        getFont().drawText(10, (unsigned int)((i + drawOffset) * lineSteps) + firstLine,
93
-                0.75f, BLUE, getLog().get(i + historyOffset - mLineOffset));
94
-    }
95
-
96
-    // Draw current input
97
-    getFont().drawText(10, inputLine, 0.75f, BLUE, "> " + mInputBuffer + mPartialInput);
98
-
99
-    ::getWindow().glExit2D();
100
-}
101
-
102
-void Console::handleKeyboard(KeyboardButton key, bool pressed) {
103
-    if (pressed && (key == enterKey)) {
104
-        // Execute entered command
105
-        if (mInputBuffer.length() > 0) {
106
-            getLog() << "> " << mInputBuffer.c_str() << Log::endl;
107
-            mCommandHistory.push_back(mInputBuffer.c_str());
108
-            int error = Command::command(mInputBuffer);
109
-            if (error != 0) {
110
-                getLog() << "Error Code: " << error << Log::endl;
111
-            }
112
-        } else {
113
-            getLog() << "> " << Log::endl;
114
-        }
115
-
116
-        // Clear partial and input buffer
117
-        mInputBuffer = "";
118
-        mPartialInput = "";
119
-        mHistoryPointer = 0;
120
-    }
121
-
122
-    // Delete last character
123
-    if (pressed && (key == backspaceKey)) {
124
-        if ((mPartialInput.length() == 0)
125
-                && (mInputBuffer.length() > 0)) {
126
-            utf8::iterator<std::string::iterator> it(mInputBuffer.end(), mInputBuffer.begin(), mInputBuffer.end());
127
-            mInputBuffer.erase((--it).base(), mInputBuffer.end());
128
-        }
129
-    }
130
-
131
-    if (pressed && ((key == upKey) || (key == downKey))) {
132
-        moveInHistory(key == upKey);
133
-    }
134
-}
135
-
136
-void Console::moveInHistory(bool up) {
137
-    if (mCommandHistory.size() == 0)
138
-        return;
139
-
140
-    if (up) {
141
-        if (mHistoryPointer < mCommandHistory.size()) {
142
-            mHistoryPointer++;
143
-            if (mHistoryPointer == 1) {
144
-                mUnfinishedInput = mInputBuffer;
145
-            }
146
-        } else {
147
-            return;
148
-        }
149
-    } else {
150
-        if (mHistoryPointer > 0)
151
-            mHistoryPointer--;
152
-        else
153
-            return;
154
-    }
155
-
156
-    if ((mHistoryPointer > 0) && (mHistoryPointer <= mCommandHistory.size())) {
157
-        mInputBuffer = mCommandHistory[mCommandHistory.size() - mHistoryPointer];
158
-    } else {
159
-        if (mUnfinishedInput.length() > 0) {
160
-            mInputBuffer = mUnfinishedInput;
161
-            mUnfinishedInput = "";
162
-        } else {
163
-            mInputBuffer = "";
164
-        }
165
-    }
166
-}
167
-
168
-void Console::handleText(char *text, bool notFinished) {
169
-    // Always scroll to bottom when text input is received
170
-    mLineOffset = 0;
171
-
172
-    if (!notFinished) {
173
-        // Finished entering character
174
-        // delete previous partial character, if present
175
-        mPartialInput = "";
176
-
177
-        //! \fixme Temporary hack filtering the console activation key
178
-        if (text[0] == '`')
179
-            return;
180
-
181
-        // Append new input to buffer
182
-        mInputBuffer += text;
183
-    } else {
184
-        // Partial character received
185
-        mPartialInput = text;
186
-    }
187
-}
188
-
189
-void Console::handleMouseScroll(int xrel, int yrel) {
190
-    assert((xrel != 0) || (yrel != 0));
191
-
192
-    // Calculate line drawing geometry
193
-    // Depends on window height, so recalculate every time
194
-    unsigned int firstLine = 35;
195
-    unsigned int lastLine = (::getWindow().getHeight() / 2) - 55;
196
-    unsigned int inputLine = (::getWindow().getHeight() / 2) - 30;
197
-    unsigned int lineSteps = 20;
198
-    unsigned int lineCount = (lastLine - firstLine + lineSteps) / lineSteps;
199
-    while (((lineCount * lineSteps) + firstLine) < inputLine) {
200
-        lineSteps++;
201
-        lineCount = (lastLine - firstLine + lineSteps) / lineSteps;
202
-    }
203
-
204
-    if (getLog().size() > lineCount) {
205
-        if (yrel > 0) {
206
-            if (mLineOffset < (getLog().size() - lineCount)) {
207
-                mLineOffset++;
208
-            }
209
-        } else if (yrel < 0) {
210
-            if (mLineOffset > 0) {
211
-                mLineOffset--;
212
-            }
213
-        }
214
-    }
215
-}
216
-

+ 0
- 189
src/Debug.cpp View File

@@ -1,189 +0,0 @@
1
-/*!
2
- * \file src/Debug.cpp
3
- * \brief Debug UI
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#include "global.h"
9
-#include "Debug.h"
10
-#include "RunTime.h"
11
-#include "TextureManager.h"
12
-#include "utils/time.h"
13
-#include "Window.h"
14
-
15
-#define STB_IMAGE_IMPLEMENTATION
16
-#include "imgui/stb_image.h"
17
-
18
-unsigned int Debug::fontTex;
19
-
20
-Debug::Debug() {
21
-    zPos = -1;
22
-
23
-    UI::addWindow(this);
24
-}
25
-
26
-Debug::~Debug() {
27
-    UI::removeWindow(this);
28
-}
29
-
30
-int Debug::initialize() {
31
-    iniFilename = getRunTime().getBaseDir() + "/imgui.ini";
32
-    logFilename = getRunTime().getBaseDir() + "/imgui_log.txt";
33
-
34
-    ImGuiIO& io = ImGui::GetIO();
35
-    io.DisplaySize = ImVec2((float)getWindow().getWidth(), (float)getWindow().getHeight());
36
-    io.DeltaTime = 1.0f / 60.0f;
37
-
38
-    io.IniFilename = iniFilename.c_str();
39
-    io.LogFilename = logFilename.c_str();
40
-
41
-    io.KeyMap[ImGuiKey_Tab] = tabKey;
42
-    io.KeyMap[ImGuiKey_LeftArrow] = leftKey;
43
-    io.KeyMap[ImGuiKey_RightArrow] = rightKey;
44
-    io.KeyMap[ImGuiKey_UpArrow] = upKey;
45
-    io.KeyMap[ImGuiKey_DownArrow] = downKey;
46
-    io.KeyMap[ImGuiKey_Home] = homeKey;
47
-    io.KeyMap[ImGuiKey_End] = endKey;
48
-    io.KeyMap[ImGuiKey_Delete] = delKey;
49
-    io.KeyMap[ImGuiKey_Backspace] = backspaceKey;
50
-    io.KeyMap[ImGuiKey_Enter] = enterKey;
51
-    io.KeyMap[ImGuiKey_Escape] = escapeKey;
52
-    io.KeyMap[ImGuiKey_A] = aKey;
53
-    io.KeyMap[ImGuiKey_C] = cKey;
54
-    io.KeyMap[ImGuiKey_V] = vKey;
55
-    io.KeyMap[ImGuiKey_X] = xKey;
56
-    io.KeyMap[ImGuiKey_Y] = yKey;
57
-    io.KeyMap[ImGuiKey_Z] = zKey;
58
-
59
-    io.RenderDrawListsFn = Debug::renderImGui;
60
-
61
-    // Load font texture
62
-    //! \todo Use our own font subsystem instead of this?
63
-    const void* png_data;
64
-    unsigned int png_size;
65
-    ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size);
66
-    int tex_x, tex_y, tex_comp;
67
-    void* tex_data = stbi_load_from_memory((const unsigned char*)png_data,
68
-            (int)png_size, &tex_x, &tex_y, &tex_comp, 0);
69
-
70
-     //! \fixme TODO use proper slot
71
-    fontTex = getTextureManager().loadBufferSlot((unsigned char *)tex_data,
72
-            tex_x, tex_y, RGBA, 32, 0, false);
73
-
74
-    stbi_image_free(tex_data);
75
-
76
-    return 0;
77
-}
78
-
79
-void Debug::eventsFinished() {
80
-    ImGuiIO& io = ImGui::GetIO();
81
-    io.DisplaySize = ImVec2((float)getWindow().getWidth(), (float)getWindow().getHeight());
82
-
83
-    static long lastTime = 0;
84
-    io.DeltaTime = ((float)(systemTimerGet() - lastTime)) / 1000.0f;
85
-    lastTime = systemTimerGet();
86
-
87
-    ImGui::NewFrame();
88
-}
89
-
90
-void Debug::display() {
91
-    ImGui::Render();
92
-}
93
-
94
-void Debug::calculate() {
95
-    //ImGui::ShowTestWindow();
96
-    //ImGui::ShowStyleEditor();
97
-    ImGui::ShowUserGuide();
98
-}
99
-
100
-void Debug::shutdown() {
101
-    ImGui::Shutdown();
102
-}
103
-
104
-void Debug::handleKeyboard(KeyboardButton key, bool pressed) {
105
-    ImGuiIO& io = ImGui::GetIO();
106
-    io.KeysDown[key] = pressed;
107
-    io.KeyCtrl = io.KeysDown[leftctrlKey] | io.KeysDown[rightctrlKey];
108
-    io.KeyShift = io.KeysDown[leftshiftKey] | io.KeysDown[rightshiftKey];
109
-}
110
-
111
-void Debug::handleText(char *text, bool notFinished) {
112
-    ImGuiIO& io = ImGui::GetIO();
113
-    while (*text != '\0') {
114
-        io.AddInputCharacter(*text);
115
-        text++;
116
-    }
117
-}
118
-
119
-void Debug::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
120
-    ImGuiIO& io = ImGui::GetIO();
121
-    io.MousePos = ImVec2((float)x, (float)y);
122
-    if (button == leftmouseKey) {
123
-        io.MouseDown[0] = !released;
124
-    } else if (button == rightmouseKey) {
125
-        io.MouseDown[1] = !released;
126
-    } else if (button == middlemouseKey) {
127
-        io.MouseDown[2] = !released;
128
-    } else if (button == fourthmouseKey) {
129
-        io.MouseDown[3] = !released;
130
-    } else if (button == fifthmouseKey) {
131
-        io.MouseDown[4] = !released;
132
-    }
133
-}
134
-
135
-void Debug::handleMouseMotion(int xrel, int yrel, int xabs, int yabs) {
136
-    ImGuiIO& io = ImGui::GetIO();
137
-    io.MousePos = ImVec2((float)xabs, (float)yabs);
138
-}
139
-
140
-void Debug::handleMouseScroll(int xrel, int yrel) {
141
-    ImGuiIO& io = ImGui::GetIO();
142
-    io.MouseWheel = (yrel != 0) ? yrel > 0 ? 1 : -1 : 0;
143
-}
144
-
145
-void Debug::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
146
-    if (cmd_lists_count == 0)
147
-        return;
148
-
149
-    getWindow().glEnter2D();
150
-
151
-    glDisable(GL_DEPTH_TEST);
152
-    glEnable(GL_SCISSOR_TEST);
153
-
154
-    glEnableClientState(GL_VERTEX_ARRAY);
155
-    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
156
-    glEnableClientState(GL_COLOR_ARRAY);
157
-
158
-    // Setup texture
159
-    getTextureManager().bindTextureId(fontTex);
160
-
161
-    // Render command lists
162
-    for (int n = 0; n < cmd_lists_count; n++) {
163
-        const ImDrawList* cmd_list = cmd_lists[n];
164
-        const unsigned char* vtx_buffer = (const unsigned char*)cmd_list->vtx_buffer.begin();
165
-        glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer));
166
-        glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer+8));
167
-        glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer+16));
168
-
169
-        int vtx_offset = 0;
170
-        const ImDrawCmd* pcmd_end = cmd_list->commands.end();
171
-        for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++) {
172
-            glScissor((int)pcmd->clip_rect.x, (int)(ImGui::GetIO().DisplaySize.y - pcmd->clip_rect.w),
173
-                    (int)(pcmd->clip_rect.z - pcmd->clip_rect.x),
174
-                    (int)(pcmd->clip_rect.w - pcmd->clip_rect.y));
175
-            glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count);
176
-            vtx_offset += pcmd->vtx_count;
177
-        }
178
-    }
179
-
180
-    glEnable(GL_DEPTH_TEST);
181
-    glDisable(GL_SCISSOR_TEST);
182
-
183
-    glDisableClientState(GL_VERTEX_ARRAY);
184
-    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
185
-    glDisableClientState(GL_COLOR_ARRAY);
186
-
187
-    getWindow().glExit2D();
188
-}
189
-

+ 0
- 4
src/Game.cpp View File

@@ -29,17 +29,13 @@ std::map<int, int> gMapTex2Bump;
29 29
 #endif
30 30
 
31 31
 Game::Game() {
32
-    zPos = 0;
33 32
     mLoaded = false;
34 33
     mLara = -1;
35 34
     mTextureStart = 0;
36 35
     mTextureOffset = 0;
37
-
38
-    UI::addWindow(this);
39 36
 }
40 37
 
41 38
 Game::~Game() {
42
-    UI::removeWindow(this);
43 39
 }
44 40
 
45 41
 unsigned int Game::getTextureStart() {

+ 5
- 6
src/MenuFolder.cpp View File

@@ -15,21 +15,17 @@
15 15
 #include "MenuFolder.h"
16 16
 
17 17
 MenuFolder::MenuFolder() {
18
-    zPos = -1;
19 18
     mCursor = 0;
20 19
     mMin = 0;
21 20
     mapFolder = nullptr;
22 21
     hiddenState = false;
23 22
     dialogState = false;
24
-
25
-    UI::addWindow(this);
23
+    visible = false;
26 24
 }
27 25
 
28 26
 MenuFolder::~MenuFolder() {
29 27
     delete mapFolder;
30 28
     mapFolder = nullptr;
31
-
32
-    UI::removeWindow(this);
33 29
 }
34 30
 
35 31
 int MenuFolder::initialize() {
@@ -77,6 +73,9 @@ int MenuFolder::init(Folder *folder, bool filter) {
77 73
 }
78 74
 
79 75
 void MenuFolder::display() {
76
+    if (!visible)
77
+        return;
78
+
80 79
     ::getWindow().glEnter2D();
81 80
 
82 81
     // Draw half-transparent overlay
@@ -123,7 +122,7 @@ void MenuFolder::loadOrOpen() {
123 122
         int error = getGame().loadLevel(mapFolder->getFile((unsigned long)mCursor
124 123
                     - 1 - mapFolder->folderCount()).getPath().c_str());
125 124
         if (error == 0) {
126
-            makeInvisible();
125
+            visible = false;
127 126
         } else {
128 127
             std::ostringstream err;
129 128
             err << "Error loading map: " << error << "!";

+ 1
- 1
src/RunTime.cpp View File

@@ -22,7 +22,7 @@ RunTime::RunTime() {
22 22
 
23 23
     // Default key bindings
24 24
     keyBindings[menuAction] = escapeKey;
25
-    keyBindings[consoleAction] = backquoteKey;
25
+    keyBindings[debugAction] = qKey;
26 26
     keyBindings[forwardAction] = wKey;
27 27
     keyBindings[backwardAction] = sKey;
28 28
     keyBindings[leftAction] = aKey;

+ 247
- 140
src/UI.cpp View File

@@ -8,200 +8,307 @@
8 8
 #include <algorithm>
9 9
 
10 10
 #include "global.h"
11
-#include "Console.h"
12
-#include "Debug.h"
11
+#include "Game.h"
12
+#include "Log.h"
13 13
 #include "Menu.h"
14 14
 #include "RunTime.h"
15 15
 #include "TextureManager.h"
16 16
 #include "Window.h"
17
+#include "commands/Command.h"
18
+#include "utils/time.h"
19
+#include "UI.h"
20
+
21
+#define STB_IMAGE_IMPLEMENTATION
22
+#include "imgui/stb_image.h"
23
+
24
+bool UI::visible = false;
25
+unsigned int UI::fontTex;
26
+std::string UI::iniFilename;
27
+std::string UI::logFilename;
28
+
29
+std::list<std::tuple<KeyboardButton, bool>> UI::keyboardEvents;
30
+std::list<std::tuple<unsigned int, unsigned int, KeyboardButton, bool>> UI::clickEvents;
31
+std::list<std::tuple<int, int, int, int>> UI::motionEvents;
32
+std::list<std::tuple<int, int>> UI::scrollEvents;
33
+
34
+int UI::initialize() {
35
+    iniFilename = getRunTime().getBaseDir() + "/imgui.ini";
36
+    logFilename = getRunTime().getBaseDir() + "/imgui_log.txt";
37
+
38
+    ImGuiIO& io = ImGui::GetIO();
39
+    io.DisplaySize = ImVec2((float)getWindow().getWidth(), (float)getWindow().getHeight());
40
+    io.DeltaTime = 1.0f / 60.0f;
41
+
42
+    io.IniFilename = iniFilename.c_str();
43
+    io.LogFilename = logFilename.c_str();
44
+
45
+    io.KeyMap[ImGuiKey_Tab] = tabKey;
46
+    io.KeyMap[ImGuiKey_LeftArrow] = leftKey;
47
+    io.KeyMap[ImGuiKey_RightArrow] = rightKey;
48
+    io.KeyMap[ImGuiKey_UpArrow] = upKey;
49
+    io.KeyMap[ImGuiKey_DownArrow] = downKey;
50
+    io.KeyMap[ImGuiKey_Home] = homeKey;
51
+    io.KeyMap[ImGuiKey_End] = endKey;
52
+    io.KeyMap[ImGuiKey_Delete] = delKey;
53
+    io.KeyMap[ImGuiKey_Backspace] = backspaceKey;
54
+    io.KeyMap[ImGuiKey_Enter] = enterKey;
55
+    io.KeyMap[ImGuiKey_Escape] = escapeKey;
56
+    io.KeyMap[ImGuiKey_A] = aKey;
57
+    io.KeyMap[ImGuiKey_C] = cKey;
58
+    io.KeyMap[ImGuiKey_V] = vKey;
59
+    io.KeyMap[ImGuiKey_X] = xKey;
60
+    io.KeyMap[ImGuiKey_Y] = yKey;
61
+    io.KeyMap[ImGuiKey_Z] = zKey;
62
+
63
+    io.RenderDrawListsFn = UI::renderImGui;
64
+
65
+    // Load font texture
66
+    //! \todo Use our own font subsystem instead of this?
67
+    const void* png_data;
68
+    unsigned int png_size;
69
+    ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size);
70
+    int tex_x, tex_y, tex_comp;
71
+    void* tex_data = stbi_load_from_memory((const unsigned char*)png_data,
72
+            (int)png_size, &tex_x, &tex_y, &tex_comp, 0);
73
+
74
+     //! \fixme TODO use proper slot
75
+    fontTex = getTextureManager().loadBufferSlot((unsigned char *)tex_data,
76
+            tex_x, tex_y, RGBA, 32, 0, false);
77
+
78
+    stbi_image_free(tex_data);
17 79
 
18
-std::vector<UI*> UI::windows;
19
-
20
-UI::~UI() {
80
+    return 0;
21 81
 }
22 82
 
23
-int UI::initialize() { return 0; }
24
-void UI::eventsFinished() { }
25
-void UI::display() { }
26
-void UI::calculate() { }
27
-void UI::shutdown() { }
28
-void UI::handleKeyboard(KeyboardButton key, bool pressed) { }
29
-void UI::handleText(char *text, bool notFinished) { }
30
-void UI::handleAction(ActionEvents action, bool isFinished) { }
31
-void UI::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) { }
32
-void UI::handleMouseMotion(int xrel, int yrel, int xabs, int yabs) { }
33
-void UI::handleMouseScroll(int xrel, int yrel) { }
34
-
35
-int UI::passInitialize() {
36
-    for (auto &x : windows) {
37
-        int error = x->initialize();
38
-        if (error != 0)
39
-            return error;
40
-    }
83
+void UI::eventsFinished() {
84
+    ImGuiIO& io = ImGui::GetIO();
85
+    io.DisplaySize = ImVec2((float)getWindow().getWidth(), (float)getWindow().getHeight());
41 86
 
42
-    return 0;
43
-}
87
+    static long lastTime = 0;
88
+    io.DeltaTime = ((float)(systemTimerGet() - lastTime)) / 1000.0f;
89
+    lastTime = systemTimerGet();
44 90
 
45
-void UI::passEvents() {
46
-    for (auto &x : windows) {
47
-        x->eventsFinished();
48
-    }
49
-}
91
+    ImGui::NewFrame();
92
+
93
+    bool clicked = !clickEvents.empty();
50 94
 
51
-void UI::passDisplay() {
52
-    std::sort(windows.begin(), windows.end(), compareUIs);
53
-    for (auto &x : windows) {
54
-        if (x->zPos >= 0) {
55
-            x->display();
95
+    if (!visible) {
96
+        while (!clickEvents.empty()) {
97
+            auto i = clickEvents.front();
98
+            if (getMenu().isVisible()) {
99
+                getMenu().handleMouseClick(std::get<0>(i), std::get<1>(i),
100
+                        std::get<2>(i), std::get<3>(i));
101
+            }
102
+            clickEvents.pop_front();
56 103
         }
57
-    }
58
-}
59 104
 
60
-void UI::passCalculate() {
61
-    for (auto &x : windows) {
62
-        x->calculate();
63
-    }
64
-}
105
+        while (!motionEvents.empty()) {
106
+            auto i = motionEvents.front();
107
+            if (!getMenu().isVisible()) {
108
+                getGame().handleMouseMotion(std::get<0>(i), std::get<1>(i),
109
+                        std::get<2>(i), std::get<3>(i));
110
+            }
111
+            motionEvents.pop_front();
112
+        }
65 113
 
66
-void UI::passShutdown() {
67
-    for (auto &x : windows) {
68
-        x->shutdown();
114
+        while (!scrollEvents.empty()) {
115
+            auto i = scrollEvents.front();
116
+            if (getMenu().isVisible()) {
117
+                getMenu().handleMouseScroll(std::get<0>(i), std::get<1>(i));
118
+            }
119
+            scrollEvents.pop_front();
120
+        }
69 121
     }
70
-}
71 122
 
72
-void UI::passKeyboard(KeyboardButton key, bool pressed) {
73
-    if (pressed) {
74
-        if (getRunTime().getKeyBinding(menuAction) == key) {
75
-            if (getMenu().isOnTop()) {
76
-                getMenu().makeInvisible();
77
-            } else {
78
-                getMenu().moveToTop();
79
-            }
80
-        } else if (getRunTime().getKeyBinding(consoleAction) == key) {
81
-            if (getConsole().isOnTop()) {
82
-                getConsole().makeInvisible();
123
+    if ((!io.WantCaptureKeyboard) || (!visible)) {
124
+        while (!keyboardEvents.empty()) {
125
+            auto i = keyboardEvents.front();
126
+
127
+            if (getMenu().isVisible()) {
128
+                getMenu().handleKeyboard(std::get<0>(i), std::get<1>(i));
83 129
             } else {
84
-                getConsole().moveToTop();
130
+                for (int n = forwardAction; n < ActionEventCount; n++) {
131
+                    if (getRunTime().getKeyBinding((ActionEvents)n) == std::get<0>(i))
132
+                        getGame().handleAction((ActionEvents)n, !std::get<1>(i));
133
+                }
85 134
             }
86
-        } else if (getRunTime().getKeyBinding(debugAction) == key) {
87
-            if (!getDebug().isOnTop()) {
88
-                getDebug().moveToTop();
135
+
136
+            if (std::get<1>(i)) {
137
+                if (getRunTime().getKeyBinding(menuAction) == std::get<0>(i)) {
138
+                    getMenu().setVisible(!getMenu().isVisible());
139
+                } else if (getRunTime().getKeyBinding(debugAction) == std::get<0>(i)) {
140
+                    visible = !visible;
141
+                }
89 142
             }
143
+
144
+            keyboardEvents.pop_front();
90 145
         }
91 146
     }
92 147
 
93
-    auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
94
-    (*maxIterator)->handleKeyboard(key, pressed);
95
-
96
-    for (int i = forwardAction; i < ActionEventCount; i++) {
97
-        if (getRunTime().getKeyBinding((ActionEvents)i) == key) {
98
-            (*maxIterator)->handleAction((ActionEvents)i, !pressed);
99
-        }
148
+    if ((!io.WantCaptureKeyboard) && (!io.WantCaptureMouse) && visible && clicked) {
149
+        visible = false;
100 150
     }
101 151
 
102
-    bool mousegrab = (*maxIterator)->zPos == 0;
103
-    if (mousegrab != getWindow().getMousegrab())
104
-        getWindow().setMousegrab(mousegrab);
152
+    keyboardEvents.clear();
153
+    clickEvents.clear();
154
+    motionEvents.clear();
155
+    scrollEvents.clear();
156
+
157
+    if (getWindow().getTextInput() != visible)
158
+        getWindow().setTextInput(visible);
159
+
160
+    bool input = !(visible || getMenu().isVisible());
161
+    if (getWindow().getMousegrab() != input)
162
+        getWindow().setMousegrab(input);
105 163
 }
106 164
 
107
-void UI::passText(char *text, bool notFinished) {
108
-    auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
109
-    (*maxIterator)->handleText(text, notFinished);
165
+void UI::display() {
166
+    if (visible)
167
+        ImGui::Render();
110 168
 }
111 169
 
112
-void UI::passMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
113
-    auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
114
-    (*maxIterator)->handleMouseClick(x, y, button, released);
170
+void UI::calculate() {
171
+    static char buffer[256];
172
+    static bool scrollToBottom = false;
115 173
 
116
-    for (int i = forwardAction; i < ActionEventCount; i++) {
117
-        if (getRunTime().getKeyBinding((ActionEvents)i) == button) {
118
-            (*maxIterator)->handleAction((ActionEvents)i, released);
174
+    ImGui::Begin("Console", NULL, ImVec2(600, 400), -1.0f);
175
+        ImGui::BeginChild("ConsoleText", ImVec2(ImGui::GetWindowWidth(), ImGui::GetWindowSize().y - 70));
176
+            for (int i = 0; i < getLog().size(); i++) {
177
+                ImGui::Text("%s", getLog().get(i).c_str());
178
+            }
179
+            if (scrollToBottom) {
180
+                ImGui::SetScrollPosHere();
181
+                scrollToBottom = false;
182
+            }
183
+        ImGui::EndChild();
184
+
185
+        bool enter = false;
186
+        ImGui::InputText("Command", buffer, 256, ImGuiInputTextFlags_AutoSelectAll, &enter);
187
+        if (enter) {
188
+            getLog() << "> " << buffer << Log::endl;
189
+            int error = Command::command(buffer);
190
+            if (error != 0) {
191
+                getLog() << "Error code: " << error << Log::endl;
192
+            }
193
+            buffer[0] = '\0';
194
+            scrollToBottom = true;
119 195
         }
120
-    }
196
+    ImGui::End();
197
+
198
+    //ImGui::Begin("UI Style");
199
+    //    ImGui::ShowStyleEditor();
200
+    //ImGui::End();
201
+
202
+    //ImGui::Begin("Help");
203
+    //    ImGui::ShowUserGuide();
204
+    //ImGui::End();
205
+
206
+    //ImGui::ShowTestWindow();
121 207
 }
122 208
 
123
-void UI::passMouseMotion(int xrel, int yrel, int xabs, int yabs) {
124
-    auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
125
-    (*maxIterator)->handleMouseMotion(xrel, yrel, xabs, yabs);
209
+void UI::shutdown() {
210
+    ImGui::Shutdown();
126 211
 }
127 212
 
128
-void UI::passMouseScroll(int xrel, int yrel) {
129
-    auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
130
-    (*maxIterator)->handleMouseScroll(xrel, yrel);
213
+void UI::handleKeyboard(KeyboardButton key, bool pressed) {
214
+    ImGuiIO& io = ImGui::GetIO();
215
+    io.KeysDown[key] = pressed;
216
+    io.KeyCtrl = io.KeysDown[leftctrlKey] | io.KeysDown[rightctrlKey];
217
+    io.KeyShift = io.KeysDown[leftshiftKey] | io.KeysDown[rightshiftKey];
218
+
219
+    keyboardEvents.push_back(std::make_tuple(key, pressed));
131 220
 }
132 221
 
133
-void UI::addWindow(UI* window) {
134
-    windows.push_back(window);
222
+void UI::handleText(char *text, bool notFinished) {
223
+    ImGuiIO& io = ImGui::GetIO();
224
+    while (*text != '\0') {
225
+        io.AddInputCharacter(*text);
226
+        text++;
227
+    }
135 228
 }
136 229
 
137
-void UI::removeWindow(UI *window) {
138
-    if (windows.size() == 0) {
139
-        // It seems as if our list was destroyed before the UIs
140
-        return;
230
+void UI::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
231
+    ImGuiIO& io = ImGui::GetIO();
232
+    io.MousePos = ImVec2((float)x, (float)y);
233
+    if (button == leftmouseKey) {
234
+        io.MouseDown[0] = !released;
235
+    } else if (button == rightmouseKey) {
236
+        io.MouseDown[1] = !released;
237
+    } else if (button == middlemouseKey) {
238
+        io.MouseDown[2] = !released;
239
+    } else if (button == fourthmouseKey) {
240
+        io.MouseDown[3] = !released;
241
+    } else if (button == fifthmouseKey) {
242
+        io.MouseDown[4] = !released;
141 243
     }
142 244
 
143
-    findInList(window, [](unsigned long i){
144
-        windows.erase(windows.begin() + i);
145
-    });
245
+    clickEvents.push_back(std::make_tuple(x, y, button, released));
146 246
 }
147 247
 
148
-bool UI::compareUIs(UI* a, UI* b) {
149
-    return a->zPos < b->zPos;
150
-}
248
+void UI::handleMouseMotion(int xrel, int yrel, int xabs, int yabs) {
249
+    ImGuiIO& io = ImGui::GetIO();
250
+    io.MousePos = ImVec2((float)xabs, (float)yabs);
151 251
 
152
-bool UI::isOnTop(unsigned long windowID) {
153
-    assert(windowID < windows.size());
154
-    auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
155
-    unsigned long maxPos = (unsigned long)(maxIterator - windows.begin());
156
-    return (maxPos == windowID);
252
+    motionEvents.push_back(std::make_tuple(xrel, yrel, xabs, yabs));
157 253
 }
158 254
 
159
-void UI::moveToTop(unsigned long windowID) {
160
-    assert(windowID < windows.size());
255
+void UI::handleMouseScroll(int xrel, int yrel) {
256
+    ImGuiIO& io = ImGui::GetIO();
257
+    io.MouseWheel = (yrel != 0) ? yrel > 0 ? 1 : -1 : 0;
161 258
 
162
-    auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
163
-    long max = (*maxIterator)->zPos;
164
-    unsigned long maxPos = (unsigned long)(maxIterator - windows.begin());
259
+    scrollEvents.push_back(std::make_tuple(xrel, yrel));
260
+}
165 261
 
166
-    if (maxPos != windowID) {
167
-        windows.at(windowID)->zPos = max + 1;
168
-    }
262
+void UI::setVisible(bool v) {
263
+    visible = v;
169 264
 }
170 265
 
171
-void UI::makeInvisible(unsigned long windowID) {
172
-    assert(windowID < windows.size());
173
-    windows.at(windowID)->zPos = -1;
266
+bool UI::isVisible() {
267
+    return visible;
174 268
 }
175 269
 
176
-void UI::findInList(UI *w, std::function<void (unsigned long i)> func) {
177
-    for (unsigned long i = 0; i < windows.size(); i++) {
178
-        auto UIptr = &(*windows.at(i));
179
-        if (w == UIptr) {
180
-            func(i);
181
-            return;
270
+void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
271
+    if (cmd_lists_count == 0)
272
+        return;
273
+
274
+    getWindow().glEnter2D();
275
+
276
+    glDisable(GL_DEPTH_TEST);
277
+    glEnable(GL_SCISSOR_TEST);
278
+
279
+    glEnableClientState(GL_VERTEX_ARRAY);
280
+    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
281
+    glEnableClientState(GL_COLOR_ARRAY);
282
+
283
+    // Setup texture
284
+    getTextureManager().bindTextureId(fontTex);
285
+
286
+    // Render command lists
287
+    for (int n = 0; n < cmd_lists_count; n++) {
288
+        const ImDrawList* cmd_list = cmd_lists[n];
289
+        const unsigned char* vtx_buffer = (const unsigned char*)cmd_list->vtx_buffer.begin();
290
+        glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer));
291
+        glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer+8));
292
+        glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer+16));
293
+
294
+        int vtx_offset = 0;
295
+        const ImDrawCmd* pcmd_end = cmd_list->commands.end();
296
+        for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++) {
297
+            glScissor((int)pcmd->clip_rect.x, (int)(ImGui::GetIO().DisplaySize.y - pcmd->clip_rect.w),
298
+                    (int)(pcmd->clip_rect.z - pcmd->clip_rect.x),
299
+                    (int)(pcmd->clip_rect.w - pcmd->clip_rect.y));
300
+            glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count);
301
+            vtx_offset += pcmd->vtx_count;
182 302
         }
183 303
     }
184 304
 
185
-    assert(false); // called UI was not registered
186
-}
305
+    glEnable(GL_DEPTH_TEST);
306
+    glDisable(GL_SCISSOR_TEST);
187 307
 
188
-bool UI::isOnTop() {
189
-    bool top = false;
190
-    findInList(this, [&](unsigned long i) {
191
-        top = UI::isOnTop(i);
192
-    });
193
-    return top;
194
-}
195
-
196
-void UI::moveToTop() {
197
-    findInList(this, [](unsigned long i) {
198
-        UI::moveToTop(i);
199
-    });
200
-}
308
+    glDisableClientState(GL_VERTEX_ARRAY);
309
+    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
310
+    glDisableClientState(GL_COLOR_ARRAY);
201 311
 
202
-void UI::makeInvisible() {
203
-    findInList(this, [](unsigned long i) {
204
-        UI::makeInvisible(i);
205
-    });
312
+    getWindow().glExit2D();
206 313
 }
207 314
 

+ 6
- 6
src/WindowSDL.cpp View File

@@ -128,7 +128,7 @@ void WindowSDL::eventHandling() {
128 128
     while(SDL_PollEvent(&event)) {
129 129
         switch (event.type) {
130 130
             case SDL_MOUSEMOTION:
131
-                UI::passMouseMotion(event.motion.xrel, event.motion.yrel, event.motion.x, event.motion.y);
131
+                UI::handleMouseMotion(event.motion.xrel, event.motion.yrel, event.motion.x, event.motion.y);
132 132
                 break;
133 133
 
134 134
             case SDL_MOUSEBUTTONDOWN:
@@ -146,18 +146,18 @@ void WindowSDL::eventHandling() {
146 146
                     button = fifthmouseKey;
147 147
                 else
148 148
                     button = unknownKey;
149
-                UI::passMouseClick(event.button.x, event.button.y, button, (event.type == SDL_MOUSEBUTTONUP));
149
+                UI::handleMouseClick(event.button.x, event.button.y, button, (event.type == SDL_MOUSEBUTTONUP));
150 150
                 break;
151 151
 
152 152
             case SDL_MOUSEWHEEL:
153 153
                 if ((event.wheel.x != 0) || (event.wheel.y != 0))
154
-                    UI::passMouseScroll(event.wheel.x, event.wheel.y);
154
+                    UI::handleMouseScroll(event.wheel.x, event.wheel.y);
155 155
                 break;
156 156
 
157 157
             case SDL_TEXTINPUT:
158 158
             case SDL_TEXTEDITING:
159 159
                 if (event.text.text != NULL)
160
-                    UI::passText(event.text.text, (event.type == SDL_TEXTEDITING));
160
+                    UI::handleText(event.text.text, (event.type == SDL_TEXTEDITING));
161 161
                 break;
162 162
 
163 163
             case SDL_KEYDOWN:
@@ -428,7 +428,7 @@ void WindowSDL::eventHandling() {
428 428
                         break;
429 429
 
430 430
                 }
431
-                UI::passKeyboard(key, (event.type == SDL_KEYDOWN));
431
+                UI::handleKeyboard(key, (event.type == SDL_KEYDOWN));
432 432
                 break;
433 433
 
434 434
             case SDL_WINDOWEVENT:
@@ -442,7 +442,7 @@ void WindowSDL::eventHandling() {
442 442
         }
443 443
     }
444 444
 
445
-    UI::passEvents();
445
+    UI::eventsFinished();
446 446
 }
447 447
 
448 448
 void WindowSDL::setTextInput(bool on) {

+ 0
- 3
src/commands/CommandBind.cpp View File

@@ -23,7 +23,6 @@ void CommandBind::printHelp() {
23 23
     getLog() << "  bind ACTION KEY" << Log::endl;
24 24
     getLog() << "Available Actions:" << Log::endl;
25 25
     getLog() << "  menu" << Log::endl;
26
-    getLog() << "  console" << Log::endl;
27 26
     getLog() << "  debug" << Log::endl;
28 27
     getLog() << "  forward" << Log::endl;
29 28
     getLog() << "  backward" << Log::endl;
@@ -65,8 +64,6 @@ int CommandBind::execute(std::istream& args) {
65 64
 ActionEvents CommandBind::stringToActionEvent(std::string action) {
66 65
     if (action == "menu") {
67 66
         return menuAction;
68
-    } else if (action == "console") {
69
-        return consoleAction;
70 67
     } else if (action == "debug") {
71 68
         return debugAction;
72 69
     } else if (action == "forward") {

+ 12
- 12
src/commands/CommandEngine.cpp View File

@@ -6,12 +6,12 @@
6 6
  */
7 7
 
8 8
 #include "global.h"
9
-#include "Console.h"
10 9
 #include "Game.h"
11 10
 #include "Log.h"
12 11
 #include "Menu.h"
13 12
 #include "RunTime.h"
14 13
 #include "Render.h"
14
+#include "UI.h"
15 15
 #include "commands/CommandEngine.h"
16 16
 
17 17
 std::string CommandLoad::name() {
@@ -51,7 +51,7 @@ std::string CommandScreenshot::brief() {
51 51
 
52 52
 void CommandScreenshot::printHelp() {
53 53
     getLog() << "sshot-Command Usage:" << Log::endl;
54
-    getLog() << "  sshot [console|menu] [console|menu]" << Log::endl;
54
+    getLog() << "  sshot [debug|menu] [debug|menu]" << Log::endl;
55 55
     getLog() << "Add console/menu to capture them too" << Log::endl;
56 56
 }
57 57
 
@@ -68,25 +68,25 @@ int CommandScreenshot::execute(std::istream& args) {
68 68
     std::string temp, temp2;
69 69
     args >> temp >> temp2;
70 70
 
71
-    getConsole().makeInvisible();
72
-    getMenu().makeInvisible();
71
+    UI::setVisible(false);
72
+    getMenu().setVisible(false);
73 73
 
74
-    if (temp == "console")
75
-        getConsole().moveToTop();
74
+    if (temp == "debug")
75
+        UI::setVisible(true);
76 76
     else if (temp == "menu")
77
-        getMenu().moveToTop();
77
+        getMenu().setVisible(true);
78 78
 
79
-    if (temp2 == "console")
80
-        getConsole().moveToTop();
79
+    if (temp2 == "debug")
80
+        UI::setVisible(true);
81 81
     else if (temp2 == "menu")
82
-        getMenu().moveToTop();
82
+        getMenu().setVisible(true);
83 83
 
84 84
     renderFrame();
85 85
     renderFrame(); // Double buffered
86 86
     getRender().screenShot(filename.c_str());
87 87
 
88
-    getMenu().makeInvisible();
89
-    getConsole().moveToTop();
88
+    getMenu().setVisible(false);
89
+    UI::setVisible(true);
90 90
 
91 91
     getLog() << "Screenshot stored..." << Log::endl;
92 92
     return 0;

+ 88
- 52
src/deps/imgui/imgui.cpp View File

@@ -144,6 +144,7 @@
144 144
  - input number: optional range min/max
145 145
  - input number: holding [-]/[+] buttons should increase the step non-linearly
146 146
  - input number: use mouse wheel to step up/down
147
+ - input text: add multi-line text edit
147 148
  - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 horrible layout code. item width should include frame padding, then we can have a generic horizontal layout helper.
148 149
  - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills)
149 150
  - columns: columns header to act as button (~sort op) and allow resize/reorder
@@ -175,7 +176,7 @@
175 176
  - style editor: add a button to print C code.
176 177
  - optimisation/render: use indexed rendering
177 178
  - optimisation/render: move clip-rect to vertex data? would allow merging all commands
178
- - optimisation/render: merge command-list of all windows into one command-list?
179
+ - optimisation/render: merge command-lists with same clip-rect into one even if they aren't sequential? (as long as in-between clip rectangle don't overlap)?
179 180
  - optimisation/render: font exported by bmfont is not tight fit on vertical axis, incur unneeded pixel-shading cost.
180 181
  - optimisation: turn some the various stack vectors into statically-sized arrays
181 182
  - optimisation: better clipping for multi-component widgets
@@ -1521,6 +1522,7 @@ static const char*  FindTextDisplayEnd(const char* text, const char* text_end =
1521 1522
     return text_display_end;
1522 1523
 }
1523 1524
 
1525
+// Log ImGui display into text output (tty or file or clipboard)
1524 1526
 static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end)
1525 1527
 {
1526 1528
     ImGuiState& g = GImGui;
@@ -1545,7 +1547,7 @@ static void LogText(const ImVec2& ref_pos, const char* text, const char* text_en
1545 1547
         if (line_end >= text_end)
1546 1548
             line_end = NULL;
1547 1549
 
1548
-        bool is_first_line = (text == text_remaining);
1550
+        const bool is_first_line = (text == text_remaining);
1549 1551
         bool is_last_line = false;
1550 1552
         if (line_end == NULL)
1551 1553
         {
@@ -1577,6 +1579,7 @@ static void LogText(const ImVec2& ref_pos, const char* text, const char* text_en
1577 1579
     }
1578 1580
 }
1579 1581
 
1582
+// Internal ImGui function to render text (called from ImGui::Text(), ImGui::TextUnformatted(), etc.)
1580 1583
 static void RenderText(ImVec2 pos, const char* text, const char* text_end, const bool hide_text_after_hash)
1581 1584
 {
1582 1585
     ImGuiState& g = GImGui;
@@ -1608,6 +1611,7 @@ static void RenderText(ImVec2 pos, const char* text, const char* text_end, const
1608 1611
     }
1609 1612
 }
1610 1613
 
1614
+// Render a rectangle shaped with optional rounding and borders
1611 1615
 static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, float rounding)
1612 1616
 {
1613 1617
     ImGuiWindow* window = GetCurrentWindow();
@@ -1622,6 +1626,7 @@ static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border,
1622 1626
     }
1623 1627
 }
1624 1628
 
1629
+// Render a triangle to denote expanded/collapsed state
1625 1630
 static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale, bool shadow)
1626 1631
 {
1627 1632
     ImGuiWindow* window = GetCurrentWindow();
@@ -1650,6 +1655,8 @@ static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale, bool sh
1650 1655
     window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Border));
1651 1656
 }
1652 1657
 
1658
+// Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker.
1659
+// CalcTextSize("") should return ImVec2(0.0f, GImGui.FontSize)
1653 1660
 ImVec2 CalcTextSize(const char* text, const char* text_end, const bool hide_text_after_hash)
1654 1661
 {
1655 1662
     ImGuiWindow* window = GetCurrentWindow();
@@ -1664,6 +1671,7 @@ ImVec2 CalcTextSize(const char* text, const char* text_end, const bool hide_text
1664 1671
     return size;
1665 1672
 }
1666 1673
 
1674
+// Find window given position, search front-to-back
1667 1675
 static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs)
1668 1676
 {
1669 1677
     ImGuiState& g = GImGui;
@@ -1681,8 +1689,9 @@ static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs)
1681 1689
     return NULL;
1682 1690
 }
1683 1691
 
1684
-// - Box is clipped by our current clip setting
1685
-// - Expand to be generous on unprecise inputs systems (touch)
1692
+// Test if mouse cursor is hovering given aabb
1693
+// NB- Box is clipped by our current clip setting
1694
+// NB- Expand the aabb to be generous on unprecise inputs systems (g.Style.TouchExtraPadding)
1686 1695
 static bool IsMouseHoveringBox(const ImGuiAabb& box)
1687 1696
 {
1688 1697
     ImGuiState& g = GImGui;
@@ -1697,7 +1706,7 @@ static bool IsMouseHoveringBox(const ImGuiAabb& box)
1697 1706
     }
1698 1707
 
1699 1708
     // Expand for touch input
1700
-    ImGuiAabb box_for_touch(box_clipped.Min - g.Style.TouchExtraPadding, box_clipped.Max + g.Style.TouchExtraPadding);
1709
+    const ImGuiAabb box_for_touch(box_clipped.Min - g.Style.TouchExtraPadding, box_clipped.Max + g.Style.TouchExtraPadding);
1701 1710
     return box_for_touch.Contains(g.IO.MousePos);
1702 1711
 }
1703 1712
 
@@ -1779,6 +1788,7 @@ ImVec2 GetItemBoxMax()
1779 1788
     return window->DC.LastItemAabb.Max;
1780 1789
 }
1781 1790
 
1791
+// Tooltip is sorted and turned into a BeginTooltip()/EndTooltip() sequence at the end of the frame. Each call override previous value.
1782 1792
 void SetTooltip(const char* fmt, ...)
1783 1793
 {
1784 1794
     ImGuiState& g = GImGui;
@@ -1788,6 +1798,7 @@ void SetTooltip(const char* fmt, ...)
1788 1798
     va_end(args);
1789 1799
 }
1790 1800
 
1801
+// Position new window if they don't have position setting in the .ini file. Rarely useful (used by the sample applications).
1791 1802
 void SetNewWindowDefaultPos(const ImVec2& pos)
1792 1803
 {
1793 1804
     ImGuiState& g = GImGui;
@@ -1867,7 +1878,7 @@ void EndChild()
1867 1878
     }
1868 1879
     else
1869 1880
     {
1870
-        // When using filling child window, we don't provide the width/height to ItemSize so that it doesn't feed back into automatic fitting
1881
+        // When using auto-filling child window, we don't provide the width/height to ItemSize so that it doesn't feed back into automatic size-fitting.
1871 1882
         ImVec2 sz = ImGui::GetWindowSize();
1872 1883
         if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitX)
1873 1884
             sz.x = 0;
@@ -1879,6 +1890,7 @@ void EndChild()
1879 1890
     }
1880 1891
 }
1881 1892
 
1893
+// Push a new ImGui window to add widgets to. This can be called multiple times with the same window to append contents
1882 1894
 bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWindowFlags flags)
1883 1895
 {
1884 1896
     ImGuiState& g = GImGui;
@@ -1890,6 +1902,7 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
1890 1902
         // Create window the first time, and load settings
1891 1903
         if (flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip))
1892 1904
         {
1905
+			// Tooltip and child windows don't store settings
1893 1906
             window = (ImGuiWindow*)IM_MALLOC(sizeof(ImGuiWindow));
1894 1907
             new(window) ImGuiWindow(name, ImVec2(0,0), size);
1895 1908
         }
@@ -1957,11 +1970,11 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
1957 1970
         else
1958 1971
             ImGui::PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y));
1959 1972
 
1960
-        // ID stack
1973
+        // Seed ID stack with our window pointer
1961 1974
         window->IDStack.resize(0);
1962 1975
         ImGui::PushID(window);
1963 1976
 
1964
-        // Move window (at the beginning of the frame)
1977
+        // Move window (at the beginning of the frame to avoid lag)
1965 1978
         const ImGuiID move_id = window->GetID("#MOVE");
1966 1979
         RegisterAliveId(move_id);
1967 1980
         if (g.ActiveId == move_id)
@@ -1993,13 +2006,9 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
1993 2006
             const ImVec2 pad = ImVec2(window->FontSize()*2.0f, window->FontSize()*2.0f);
1994 2007
             window->PosFloat = ImMax(window->PosFloat + window->Size, pad) - window->Size;
1995 2008
             window->PosFloat = ImMin(window->PosFloat, ImVec2(g.IO.DisplaySize.x, g.IO.DisplaySize.y) - pad);
1996
-            window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
1997 2009
             window->SizeFull = ImMax(window->SizeFull, pad);
1998 2010
         }
1999
-        else
2000
-        {
2001
-            window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
2002
-        }
2011
+        window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
2003 2012
 
2004 2013
         // Default item width
2005 2014
         if (window->Size.x > 0.0f && !(window->Flags & ImGuiWindowFlags_Tooltip))
@@ -2007,7 +2016,7 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
2007 2016
         else
2008 2017
             window->ItemWidthDefault = 200.0f;
2009 2018
 
2010
-        // Prepare for focus requests
2019
+        // Prepare for keyboard focus requests
2011 2020
         if (window->FocusIdxRequestNext == IM_INT_MAX || window->FocusIdxCounter == -1)
2012 2021
         {
2013 2022
             window->FocusIdxRequestCurrent = IM_INT_MAX;
@@ -2029,7 +2038,7 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
2029 2038
             window->ScrollY = ImMin(window->ScrollY, ImMax(0.0f, (float)window->SizeContentsFit.y - window->SizeFull.y));
2030 2039
         window->NextScrollY = window->ScrollY;
2031 2040
 
2032
-        // NB- at this point we don't have a clipping rectangle setup yet!
2041
+        // At this point we don't have a clipping rectangle setup yet, so we can test and draw in title bar
2033 2042
         // Collapse window by double-clicking on title bar
2034 2043
         if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
2035 2044
         {
@@ -2047,7 +2056,7 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
2047 2056
 
2048 2057
         if (window->Collapsed)
2049 2058
         {
2050
-            // Title bar only
2059
+            // Draw title bar only
2051 2060
             window->Size = title_bar_aabb.GetSize();
2052 2061
             window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBgCollapsed), g.Style.WindowRounding);
2053 2062
             if (window->Flags & ImGuiWindowFlags_ShowBorders)
@@ -2060,18 +2069,18 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
2060 2069
         {
2061 2070
             window->Size = window->SizeFull;
2062 2071
 
2063
-            // Draw resize grip and resize
2064 2072
             ImU32 resize_col = 0;
2065 2073
             if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
2066 2074
             {
2075
+                // Tooltip always resize
2067 2076
                 if (window->AutoFitFrames > 0)
2068 2077
                 {
2069
-                    // Tooltip always resize
2070 2078
                     window->SizeFull = window->SizeContentsFit + g.Style.WindowPadding - ImVec2(0.0f, g.Style.ItemSpacing.y);
2071 2079
                 }
2072 2080
             }
2073 2081
             else if (!(window->Flags & ImGuiWindowFlags_NoResize))
2074 2082
             {
2083
+				// Draw resize grip
2075 2084
                 const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR());
2076 2085
                 const ImGuiID resize_id = window->GetID("#RESIZE");
2077 2086
                 bool hovered, held;
@@ -2116,6 +2125,7 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
2116 2125
             if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
2117 2126
                 window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBg), g.Style.WindowRounding, 1|2);
2118 2127
 
2128
+			// Borders
2119 2129
             if (window->Flags & ImGuiWindowFlags_ShowBorders)
2120 2130
             {
2121 2131
                 const float rounding = (window->Flags & ImGuiWindowFlags_ComboBox) ? 0.0f : g.Style.WindowRounding;
@@ -2137,7 +2147,7 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
2137 2147
                 const float grab_size_y_norm = ImSaturate(window->Size.y / ImMax(window->SizeContentsFit.y, window->Size.y));
2138 2148
                 const float grab_size_y = scrollbar_bb.GetHeight() * grab_size_y_norm;
2139 2149
 
2140
-                // Handle input right away (none of the code above is relying on scrolling)
2150
+                // Handle input right away (none of the code above is relying on scrolling position)
2141 2151
                 bool held = false;
2142 2152
                 bool hovered = false;
2143 2153
                 if (grab_size_y_norm < 1.0f)
@@ -2246,11 +2256,9 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin
2246 2256
         clip_rect.z -= g.Style.ScrollBarWidth;
2247 2257
     ImGui::PushClipRect(clip_rect);
2248 2258
 
2259
+    // Clear 'accessed' flag last thing
2249 2260
     if (first_begin_of_the_frame)
2250
-    {
2251
-        // Clear 'accessed' flag last thing
2252 2261
         window->Accessed = false;
2253
-    }
2254 2262
 
2255 2263
     // Child window can be out of sight and have "negative" clip windows.
2256 2264
     // Mark them as collapsed so commands are skipped earlier (we can't manually collapse because they have no title bar).
@@ -2282,13 +2290,13 @@ void End()
2282 2290
     ImGui::PopClipRect();   // inner window clip rectangle
2283 2291
     ImGui::PopClipRect();   // outer window clip rectangle
2284 2292
 
2285
-    // Select window for move/focus when we're done with all our widgets
2286
-    ImGuiAabb bb(window->Pos, window->Pos+window->Size);
2293
+    // Select window for move/focus when we're done with all our widgets (we only consider non-childs windows here)
2294
+    const ImGuiAabb bb(window->Pos, window->Pos+window->Size);
2287 2295
     if (g.ActiveId == 0 && g.HoveredId == 0 && g.HoveredWindowExcludingChilds == window && IsMouseHoveringBox(bb) && g.IO.MouseClicked[0])
2288 2296
         g.ActiveId = window->GetID("#MOVE");
2289 2297
 
2290 2298
     // Stop logging
2291
-    if (!(window->Flags & ImGuiWindowFlags_ChildWindow))    // FIXME: more options for scope of logging
2299
+    if (!(window->Flags & ImGuiWindowFlags_ChildWindow))    // FIXME: add more options for scope of logging
2292 2300
     {
2293 2301
         g.LogEnabled = false;
2294 2302
         if (g.LogFile != NULL)
@@ -2314,12 +2322,12 @@ void End()
2314 2322
     g.CurrentWindow = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back();
2315 2323
 }
2316 2324
 
2325
+// Moving window to front
2317 2326
 static void FocusWindow(ImGuiWindow* window)
2318 2327
 {
2319 2328
     ImGuiState& g = GImGui;
2320 2329
     g.FocusedWindow = window;
2321 2330
 
2322
-    // Move to front
2323 2331
     for (size_t i = 0; i < g.Windows.size(); i++)
2324 2332
         if (g.Windows[i] == window)
2325 2333
         {
@@ -2384,7 +2392,7 @@ void PopStyleColor()
2384 2392
 
2385 2393
 const char* GetStyleColorName(ImGuiCol idx)
2386 2394
 {
2387
-    // Create with regexp: ImGuiCol_{.*}, --> case ImGuiCol_\1: return "\1";
2395
+    // Create switch-case from enum with regexp: ImGuiCol_{.*}, --> case ImGuiCol_\1: return "\1";
2388 2396
     switch (idx)
2389 2397
     {
2390 2398
     case ImGuiCol_Text: return "Text";
@@ -2455,7 +2463,7 @@ void SetWindowPos(const ImVec2& pos)
2455 2463
     window->PosFloat = pos;
2456 2464
     window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
2457 2465
 
2458
-    // If we happen to move the window while it is showing (which is a bad idea) let's at least offset the cursor
2466
+    // If we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least offset the cursor
2459 2467
     window->DC.CursorPos += (window->Pos - old_pos);
2460 2468
 }
2461 2469
 
@@ -2609,7 +2617,7 @@ void TextUnformatted(const char* text, const char* text_end)
2609 2617
         {
2610 2618
             ImVec2 pos = start_pos;
2611 2619
 
2612
-            // lines to skip (can't skip when logging text)
2620
+            // Lines to skip (can't skip when logging text)
2613 2621
             if (!g.LogEnabled)
2614 2622
             {
2615 2623
                 int lines_skippable = (int)((clip_rect.y - start_pos.y) / line_height) - 1;
@@ -2626,7 +2634,7 @@ void TextUnformatted(const char* text, const char* text_end)
2626 2634
                 }
2627 2635
             }
2628 2636
 
2629
-            // lines to render?
2637
+            // Lines to render
2630 2638
             if (line < text_end)
2631 2639
             {
2632 2640
                 ImGuiAabb line_box(pos, pos + ImVec2(ImGui::GetWindowWidth(), line_height));
@@ -2647,7 +2655,7 @@ void TextUnformatted(const char* text, const char* text_end)
2647 2655
                     pos.y += line_height;
2648 2656
                 }
2649 2657
 
2650
-                // count remaining lines
2658
+                // Count remaining lines
2651 2659
                 int lines_skipped = 0;
2652 2660
                 while (line < text_end)
2653 2661
                 {
@@ -2676,7 +2684,7 @@ void TextUnformatted(const char* text, const char* text_end)
2676 2684
             return;
2677 2685
 
2678 2686
         // Render
2679
-        // We don't hide text after # in this end-user function.
2687
+        // We don't hide text after ## in this end-user function.
2680 2688
         RenderText(bb.Min, text_begin, text_end, false);
2681 2689
     }
2682 2690
 }
@@ -2693,6 +2701,7 @@ void AlignFirstTextHeightToWidgets()
2693 2701
     ImGui::SameLine(0, 0);
2694 2702
 }
2695 2703
 
2704
+// Add a label+text combo aligned to other label+value widgets
2696 2705
 void LabelText(const char* label, const char* fmt, ...)
2697 2706
 {
2698 2707
     ImGuiState& g = GImGui;
@@ -2805,7 +2814,7 @@ bool Button(const char* label, ImVec2 size, bool repeat_when_held)
2805 2814
     return pressed;
2806 2815
 }
2807 2816
 
2808
-// Fits within text without additional spacing.
2817
+// Small buttons fits within text without additional spacing.
2809 2818
 bool SmallButton(const char* label)
2810 2819
 {
2811 2820
     ImGuiState& g = GImGui;
@@ -2833,6 +2842,7 @@ bool SmallButton(const char* label)
2833 2842
     return pressed;
2834 2843
 }
2835 2844
 
2845
+// Upper-right button to close a window.
2836 2846
 static bool CloseWindowButton(bool* open)
2837 2847
 {
2838 2848
     ImGuiWindow* window = GetCurrentWindow();
@@ -2862,6 +2872,7 @@ static bool CloseWindowButton(bool* open)
2862 2872
     return pressed;
2863 2873
 }
2864 2874
 
2875
+// Start logging ImGui output to TTY
2865 2876
 void LogToTTY(int max_depth)
2866 2877
 {
2867 2878
     ImGuiState& g = GImGui;
@@ -2873,6 +2884,7 @@ void LogToTTY(int max_depth)
2873 2884
         g.LogAutoExpandMaxDepth = max_depth;
2874 2885
 }
2875 2886
 
2887
+// Start logging ImGui output to given file
2876 2888
 void LogToFile(int max_depth, const char* filename)
2877 2889
 {
2878 2890
     ImGuiState& g = GImGui;
@@ -2886,6 +2898,7 @@ void LogToFile(int max_depth, const char* filename)
2886 2898
         g.LogAutoExpandMaxDepth = max_depth;
2887 2899
 }
2888 2900
 
2901
+// Start logging ImGui output to clipboard
2889 2902
 void LogToClipboard(int max_depth)
2890 2903
 {
2891 2904
     ImGuiState& g = GImGui;
@@ -2897,6 +2910,7 @@ void LogToClipboard(int max_depth)
2897 2910
         g.LogAutoExpandMaxDepth = max_depth;
2898 2911
 }
2899 2912
 
2913
+// Helper to display logging buttons
2900 2914
 void LogButtons()
2901 2915
 {
2902 2916
     ImGuiState& g = GImGui;
@@ -2941,6 +2955,7 @@ bool CollapsingHeader(const char* label, const char* str_id, const bool display_
2941 2955
         label = str_id;
2942 2956
     const ImGuiID id = window->GetID(str_id);
2943 2957
 
2958
+	// We only write to the tree storage if the user clicks
2944 2959
     ImGuiStorage* tree = window->DC.StateStorage;
2945 2960
     bool opened;
2946 2961
     if (window->DC.OpenNextNode != -1)
@@ -2954,6 +2969,7 @@ bool CollapsingHeader(const char* label, const char* str_id, const bool display_
2954 2969
         opened = tree->GetInt(id, default_open) != 0;
2955 2970
     }
2956 2971
 
2972
+	// Framed header expand a little outside the default padding
2957 2973
     const ImVec2 window_padding = window->WindowPadding();
2958 2974
     const ImVec2 text_size = CalcTextSize(label);
2959 2975
     const ImVec2 pos_min = window->DC.CursorPos;
@@ -2969,8 +2985,8 @@ bool CollapsingHeader(const char* label, const char* str_id, const bool display_
2969 2985
     const ImGuiAabb text_bb(bb.Min, bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2*2,0) + text_size);
2970 2986
     ItemSize(ImVec2(text_bb.GetSize().x, bb.GetSize().y));  // NB: we don't provide our width so that it doesn't get feed back into AutoFit
2971 2987
 
2972
-    // Logging auto expand tree nodes (but not collapsing headers.. seems like sensible behaviour)
2973
-    // NB- If we are above max depth we still allow manually opened nodes to be logged
2988
+    // When logging is enabled, if automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behaviour).
2989
+    // NB- If we are above max depth we still allow manually opened nodes to be logged.
2974 2990
     if (!display_frame) 
2975 2991
         if (g.LogEnabled && window->DC.TreeDepth < g.LogAutoExpandMaxDepth)
2976 2992
             opened = true;
@@ -2990,12 +3006,14 @@ bool CollapsingHeader(const char* label, const char* str_id, const bool display_
2990 3006
     const ImU32 col = window->Color((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
2991 3007
     if (display_frame)
2992 3008
     {
3009
+		// Framed type
2993 3010
         RenderFrame(bb.Min, bb.Max, col, true);
2994 3011
         RenderCollapseTriangle(bb.Min + style.FramePadding, opened, 1.0f, true);
2995 3012
         RenderText(bb.Min + style.FramePadding + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label);
2996 3013
     }
2997 3014
     else
2998 3015
     {
3016
+		// Unframed typed for tree nodes
2999 3017
         if ((held && hovered) || hovered)
3000 3018
             RenderFrame(bb.Min, bb.Max, col, false);
3001 3019
         RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, window->FontSize()*0.15f), opened, 0.70f, false);
@@ -3005,6 +3023,7 @@ bool CollapsingHeader(const char* label, const char* str_id, const bool display_
3005 3023
     return opened;
3006 3024
 }
3007 3025
 
3026
+// Text with a little bullet aligned to the typical tree node.
3008 3027
 void BulletText(const char* fmt, ...)
3009 3028
 {
3010 3029
     ImGuiState& g = GImGui;
@@ -3033,6 +3052,7 @@ void BulletText(const char* fmt, ...)
3033 3052
     RenderText(bb.Min+ImVec2(window->FontSize()+g.Style.FramePadding.x*2,0), text_begin, text_end);
3034 3053
 }
3035 3054
 
3055
+// If returning 'true' the node is open and the user is responsible for calling TreePop
3036 3056
 bool TreeNode(const char* str_id, const char* fmt, ...)
3037 3057
 {
3038 3058
     static char buf[1024];
@@ -3054,6 +3074,7 @@ bool TreeNode(const char* str_id, const char* fmt, ...)
3054 3074
     return opened;
3055 3075
 }
3056 3076
 
3077
+// If returning 'true' the node is open and the user is responsible for calling TreePop
3057 3078
 bool TreeNode(const void* ptr_id, const char* fmt, ...)
3058 3079
 {
3059 3080
     static char buf[1024];
@@ -3111,6 +3132,7 @@ void PopID()
3111 3132
     window->IDStack.pop_back();
3112 3133
 }
3113 3134
 
3135
+// User can input math operators (e.g. +100) to edit a numerical values.
3114 3136
 // NB: only call right after InputText because we are using its InitialValue storage
3115 3137
 static void ApplyNumericalTextInput(const char* buf, float *v)
3116 3138
 {
@@ -3156,7 +3178,8 @@ static void ApplyNumericalTextInput(const char* buf, float *v)
3156 3178
         *v = op_v;
3157 3179
 }
3158 3180
 
3159
-// use power!=1.0 for logarithmic sliders
3181
+// Use power!=1.0 for logarithmic sliders.
3182
+// Adjust display_format to decorate the value with a prefix or a suffix.
3160 3183
 bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format, float power)
3161 3184
 {
3162 3185
     ImGuiState& g = GImGui;
@@ -3195,14 +3218,14 @@ bool SliderFloat(const char* label, float* v, float v_min, float v_max, const ch
3195 3218
 
3196 3219
     if (IsClipped(slider_bb))
3197 3220
     {
3198
-        // NB- we don't use ClipAdvance() because we don't want to submit ItemSize() because we may change into a text edit later which may submit an ItemSize itself
3221
+        // NB- we don't use ClipAdvance() in the if() statement because we don't want to submit ItemSize() because we may change into a text edit later which may submit an ItemSize itself
3199 3222
         ItemSize(bb);
3200 3223
         return false;
3201 3224
     }
3202 3225
 
3203 3226
     const bool is_unbound = v_min == -FLT_MAX || v_min == FLT_MAX || v_max == -FLT_MAX || v_max == FLT_MAX;
3204 3227
 
3205
-    const float grab_size_in_units = 1.0f;                                                          // In 'v' units. Probably needs to be parametrized, based on a 'v_step' value? decimal precision?
3228
+    const float grab_size_in_units = 1.0f;                                                              // In 'v' units. Probably needs to be parametrized, based on a 'v_step' value? decimal precision?
3206 3229
     float grab_size_in_pixels;
3207 3230
     if (decimal_precision > 0 || is_unbound)
3208 3231
         grab_size_in_pixels = 10.0f;
@@ -3212,7 +3235,7 @@ bool SliderFloat(const char* label, float* v, float v_min, float v_max, const ch
3212 3235
     const float slider_effective_x1 = slider_bb.Min.x + grab_size_in_pixels*0.5f;
3213 3236
     const float slider_effective_x2 = slider_bb.Max.x - grab_size_in_pixels*0.5f;
3214 3237
 
3215
-    // For logarithmic sliders that cross over sign boundary we want the exponential increase to be symetric around 0.0
3238
+    // For logarithmic sliders that cross over sign boundary we want the exponential increase to be symetric around 0.0f
3216 3239
     float linear_zero_pos = 0.0f;   // 0.0->1.0f
3217 3240
     if (!is_unbound)
3218 3241
     {
@@ -3247,7 +3270,7 @@ bool SliderFloat(const char* label, float* v, float v_min, float v_max, const ch
3247 3270
         }
3248 3271
     }
3249 3272
 
3250
-    // Tabbing thru or CTRL-clicking through slider turns into an input box
3273
+    // Tabbing or CTRL-clicking through slider turns into an input box
3251 3274
     bool value_changed = false;
3252 3275
     if (start_text_input || (g.ActiveId == id && id == g.SliderAsInputTextId))
3253 3276
     {
@@ -3256,12 +3279,12 @@ bool SliderFloat(const char* label, float* v, float v_min, float v_max, const ch
3256 3279
 
3257 3280
         g.ActiveId = g.SliderAsInputTextId;
3258 3281
         g.HoveredId = 0;
3259
-        window->FocusItemUnregister();  // Our replacement slider will override the focus ID (that we needed to declare previously to allow for a TAB focus to happen before we got selected)
3282
+        window->FocusItemUnregister();      // Our replacement slider will override the focus ID (that we needed to declare previously to allow for a TAB focus to happen before we got selected)
3260 3283
         value_changed = ImGui::InputText(label, text_buf, IM_ARRAYSIZE(text_buf), ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_AlignCenter);
3261 3284
         if (g.SliderAsInputTextId == 0)
3262 3285
         {
3263 3286
             // First frame
3264
-            IM_ASSERT(g.ActiveId == id);    // InputText ID should match the Slider ID (else we'd need to store them both)
3287
+            IM_ASSERT(g.ActiveId == id);    // InputText ID should match the Slider ID (else we'd need to store them both which is also possible)
3265 3288
             g.SliderAsInputTextId = g.ActiveId;
3266 3289
             g.ActiveId = id;
3267 3290
             g.HoveredId = id;
@@ -3351,12 +3374,12 @@ bool SliderFloat(const char* label, float* v, float v_min, float v_max, const ch
3351 3374
         float v_clamped = ImClamp(*v, v_min, v_max);
3352 3375
         if (v_clamped < 0.0f)
3353 3376
         {
3354
-            float f = 1.0f - (v_clamped - v_min) / (ImMin(0.0f,v_max) - v_min);
3377
+            const float f = 1.0f - (v_clamped - v_min) / (ImMin(0.0f,v_max) - v_min);
3355 3378
             grab_t = (1.0f - powf(f, 1.0f/power)) * linear_zero_pos;
3356 3379
         }
3357 3380
         else
3358 3381
         {
3359
-            float f = (v_clamped - ImMax(0.0f,v_min)) / (v_max - ImMax(0.0f,v_min));
3382
+            const float f = (v_clamped - ImMax(0.0f,v_min)) / (v_max - ImMax(0.0f,v_min));
3360 3383
             grab_t = linear_zero_pos + powf(f, 1.0f/power) * (1.0f - linear_zero_pos);
3361 3384
         }
3362 3385
 
@@ -3366,6 +3389,7 @@ bool SliderFloat(const char* label, float* v, float v_min, float v_max, const ch
3366 3389
         window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, window->Color(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab));
3367 3390
     }
3368 3391
 
3392
+	// Draw value using user-provided display format so user can add prefix/suffix/decorations to the value.
3369 3393
     char value_buf[64];
3370 3394
     ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
3371 3395
     RenderText(ImVec2(slider_bb.GetCenter().x-CalcTextSize(value_buf).x*0.5f, frame_bb.Min.y + style.FramePadding.y), value_buf);
@@ -3536,7 +3560,7 @@ static void Plot(ImGuiPlotType plot_type, const char* label, const float* values
3536 3560
         const float v1 = PlotGetValue(values, stride, (v_idx + values_offset + 1) % values_count);
3537 3561
         const ImVec2 p1 = ImVec2( t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min)) );
3538 3562
 
3539
-        // NB: draw calls are merged into ones
3563
+        // NB- Draw calls are merged together by the DrawList system.
3540 3564
         if (plot_type == ImGuiPlotType_Lines)
3541 3565
             window->DrawList->AddLine(ImLerp(graph_bb.Min, graph_bb.Max, p0), ImLerp(graph_bb.Min, graph_bb.Max, p1), v_hovered == v_idx ? col_hovered : col_base);
3542 3566
         else if (plot_type == ImGuiPlotType_Histogram)
@@ -3546,7 +3570,7 @@ static void Plot(ImGuiPlotType plot_type, const char* label, const float* values
3546 3570
         p0 = p1;
3547 3571
     }
3548 3572
 
3549
-    // Overlay last value
3573
+    // Text overlay
3550 3574
     if (overlay_text)
3551 3575
         RenderText(ImVec2(graph_bb.GetCenter().x-CalcTextSize(overlay_text).x*0.5f, frame_bb.Min.y + style.FramePadding.y), overlay_text);
3552 3576
 
@@ -3663,6 +3687,8 @@ bool RadioButton(const char* label, bool active)
3663 3687
         window->DrawList->AddCircle(center, radius, window->Color(ImGuiCol_Border), 16);
3664 3688
     }
3665 3689
 
3690
+    if (g.LogEnabled)
3691
+        LogText(text_bb.GetTL(), active ? "(x)" : "( )");
3666 3692
     RenderText(text_bb.GetTL(), label);
3667 3693
 
3668 3694
     return pressed;
@@ -3838,6 +3864,7 @@ bool InputFloat(const char* label, float *v, float step, float step_fast, int de
3838 3864
         value_changed = true;
3839 3865
     }
3840 3866
 
3867
+	// Step buttons
3841 3868
     if (step > 0.0f)
3842 3869
     {
3843 3870
         ImGui::PopItemWidth();
@@ -3873,8 +3900,11 @@ bool InputInt(const char* label, int *v, int step, int step_fast)
3873 3900
     return value_changed;
3874 3901
 }
3875 3902
 
3876
-bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags)
3903
+bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, bool *enter)
3877 3904
 {
3905
+    if (enter != NULL)
3906
+        *enter = false;
3907
+
3878 3908
     ImGuiState& g = GImGui;
3879 3909
     ImGuiWindow* window = GetCurrentWindow();
3880 3910
     if (window->SkipItems)
@@ -3894,7 +3924,7 @@ bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlag
3894 3924
     if (ClipAdvance(frame_bb))
3895 3925
         return false;
3896 3926
 
3897
-    // NB: we can only read/write if we are the active widget!
3927
+    // NB: we can only read/write to 'edit_state' if we are the active widget!
3898 3928
     ImGuiTextEditState& edit_state = g.InputTextState;
3899 3929
 
3900 3930
     const bool is_ctrl_down = io.KeyCtrl;
@@ -3937,6 +3967,7 @@ bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlag
3937 3967
     bool cancel_edit = false;
3938 3968
     if (g.ActiveId == id)
3939 3969
     {
3970
+		// Edit in progress
3940 3971
         edit_state.BufSize = buf_size < IM_ARRAYSIZE(edit_state.Text) ? buf_size : IM_ARRAYSIZE(edit_state.Text);
3941 3972
         edit_state.Font = window->Font();
3942 3973
         edit_state.FontSize = window->FontSize();
@@ -3973,7 +4004,7 @@ bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlag
3973 4004
         else if (IsKeyPressedMap(ImGuiKey_End))                 edit_state.OnKeyboardPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTEND | k_mask : STB_TEXTEDIT_K_LINEEND | k_mask);
3974 4005
         else if (IsKeyPressedMap(ImGuiKey_Delete))              edit_state.OnKeyboardPressed(STB_TEXTEDIT_K_DELETE | k_mask);
3975 4006
         else if (IsKeyPressedMap(ImGuiKey_Backspace))           edit_state.OnKeyboardPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask);
3976
-        else if (IsKeyPressedMap(ImGuiKey_Enter))               { g.ActiveId = 0; }
4007
+        else if (IsKeyPressedMap(ImGuiKey_Enter))               { g.ActiveId = 0; if (enter != NULL) *enter = true; }
3977 4008
         else if (IsKeyPressedMap(ImGuiKey_Escape))              { g.ActiveId = 0; cancel_edit = true; }
3978 4009
         else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Z))   edit_state.OnKeyboardPressed(STB_TEXTEDIT_K_UNDO);      // I don't want to use shortcuts but we should probably have an Input-catch stack
3979 4010
         else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Y))   edit_state.OnKeyboardPressed(STB_TEXTEDIT_K_REDO);
@@ -4155,6 +4186,7 @@ static bool Combo_ArrayGetter(void* data, int idx, const char** out_text)
4155 4186
     return true;
4156 4187
 }
4157 4188
 
4189
+// Combo box helper allowing to pass an array of strings.
4158 4190
 bool Combo(const char* label, int* current_item, const char** items, int items_count, int popup_height_items)
4159 4191
 {
4160 4192
     const bool value_changed = Combo(label, current_item, Combo_ArrayGetter, (void*)items, items_count, popup_height_items);
@@ -4181,6 +4213,7 @@ static bool Combo_StringListGetter(void* data, int idx, const char** out_text)
4181 4213
     return true;
4182 4214
 }
4183 4215
 
4216
+// Combo box helper allowing to pass all items in a single string.
4184 4217
 bool Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_height_items)
4185 4218
 {
4186 4219
     int items_count = 0;
@@ -4194,6 +4227,7 @@ bool Combo(const char* label, int* current_item, const char* items_separated_by_
4194 4227
     return value_changed;
4195 4228
 }
4196 4229
 
4230
+// Combo box function.
4197 4231
 bool Combo(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int popup_height_items)
4198 4232
 {
4199 4233
     ImGuiState& g = GImGui;
@@ -4250,7 +4284,7 @@ bool Combo(const char* label, int* current_item, bool (*items_getter)(void*, int
4250 4284
         const ImGuiAabb popup_aabb(ImVec2(frame_bb.Min.x+popup_off_x, frame_bb.Max.y), ImVec2(frame_bb.Max.x+popup_off_x, frame_bb.Max.y + popup_height));
4251 4285
         ImGui::SetCursorPos(popup_aabb.Min - window->Pos);
4252 4286
 
4253
-        ImGuiWindowFlags flags = ImGuiWindowFlags_ComboBox | ((window->Flags & ImGuiWindowFlags_ShowBorders) ? ImGuiWindowFlags_ShowBorders : 0);
4287
+        const ImGuiWindowFlags flags = ImGuiWindowFlags_ComboBox | ((window->Flags & ImGuiWindowFlags_ShowBorders) ? ImGuiWindowFlags_ShowBorders : 0);
4254 4288
         ImGui::BeginChild("#ComboBox", popup_aabb.GetSize(), false, flags);
4255 4289
         ImGuiWindow* child_window = GetCurrentWindow();
4256 4290
         ImGui::Spacing();
@@ -4347,7 +4381,7 @@ bool ColorEdit3(const char* label, float col[3])
4347 4381
     col4[1] = col[1];
4348 4382
     col4[2] = col[2];
4349 4383
     col4[3] = 1.0f;
4350
-    bool value_changed = ImGui::ColorEdit4(label, col4, false);
4384
+    const bool value_changed = ImGui::ColorEdit4(label, col4, false);
4351 4385
     col[0] = col4[0];
4352 4386
     col[1] = col4[1];
4353 4387
     col[2] = col4[2];
@@ -4493,6 +4527,7 @@ void ColorEditMode(ImGuiColorEditMode mode)
4493 4527
     window->DC.ColorEditMode = mode;
4494 4528
 }
4495 4529
 
4530
+// Horizontal separator.
4496 4531
 void Separator()
4497 4532
 {
4498 4533
     ImGuiWindow* window = GetCurrentWindow();
@@ -4518,6 +4553,7 @@ void Separator()
4518 4553
         ImGui::PushColumnClipRect();
4519 4554
 }
4520 4555
 
4556
+// A little vertical spacing.
4521 4557
 void Spacing()
4522 4558
 {
4523 4559
     ImGuiWindow* window = GetCurrentWindow();
@@ -4713,7 +4749,7 @@ void Columns(int columns_count, const char* id, bool border)
4713 4749
             bool hovered, held;
4714 4750
             ButtonBehaviour(column_aabb, column_id, &hovered, &held, true);
4715 4751
 
4716
-            // Draw before resize so our items positioning are in sync with the line
4752
+            // Draw before resize so our items positioning are in sync with the line being drawn
4717 4753
             const ImU32 col = window->Color(held ? ImGuiCol_ColumnActive : hovered ? ImGuiCol_ColumnHovered : ImGuiCol_Column);
4718 4754
             const float xi = (float)(int)x;
4719 4755
             window->DrawList->AddLine(ImVec2(xi, y1), ImVec2(xi, y2), col);

+ 14
- 14
src/deps/imgui/imgui.h View File

@@ -145,16 +145,16 @@ namespace ImGui
145 145
     void        BeginChild(const char* str_id, ImVec2 size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0);
146 146
     void        EndChild();
147 147
     bool        GetWindowIsFocused();
148
-    float       GetWindowWidth();
149
-    ImVec2      GetWindowPos();                                                     // you should rarely need/care about the window position, but it can be useful if you want to use your own drawing
150
-    void        SetWindowPos(const ImVec2& pos);                                    // set current window pos
151 148
     ImVec2      GetWindowSize();
149
+    float       GetWindowWidth();
150
+    ImVec2      GetWindowPos();                                                     // you should rarely need/care about the window position, but it can be useful if you want to use your own drawing.
151
+    void        SetWindowPos(const ImVec2& pos);                                    // set current window pos.
152 152
     ImVec2      GetWindowContentRegionMin();
153 153
     ImVec2      GetWindowContentRegionMax();
154
-    ImDrawList* GetWindowDrawList();
154
+    ImDrawList* GetWindowDrawList();                                                // get rendering command-list if you want to append your own draw primitives.
155 155
     void        SetFontScale(float scale);
156
-    void        SetScrollPosHere();
157
-    void        SetTreeStateStorage(ImGuiStorage* tree);
156
+    void        SetScrollPosHere();                                                 // adjust scrolling position to center into the current cursor position.
157
+    void        SetTreeStateStorage(ImGuiStorage* tree);                            // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it).
158 158
     ImGuiStorage* GetTreeStateStorage();
159 159
     void        PushItemWidth(float item_width);
160 160
     void        PopItemWidth();
@@ -166,7 +166,7 @@ namespace ImGui
166 166
 
167 167
     // Tooltip
168 168
     void        SetTooltip(const char* fmt, ...);                                   // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins.
169
-    void        BeginTooltip();                                                     // use to create full-featured tooltip windows that aren't just text. 
169
+    void        BeginTooltip();                                                     // use to create full-featured tooltip windows that aren't just text.
170 170
     void        EndTooltip();
171 171
 
172 172
     // Layout
@@ -183,7 +183,7 @@ namespace ImGui
183 183
     void        SetCursorPosX(float x);                                             // "
184 184
     void        SetCursorPosY(float y);                                             // "
185 185
     ImVec2      GetCursorScreenPos();												// cursor position in screen space
186
-    void        AlignFirstTextHeightToWidgets();                                    // call once if the first item on the line is a Text() item and you want to vertically lower it to match higher widgets.
186
+    void        AlignFirstTextHeightToWidgets();                                    // call once if the first item on the line is a Text() item and you want to vertically lower it to match subsequent (bigger) widgets.
187 187
     float       GetTextLineSpacing();
188 188
     float       GetTextLineHeight();
189 189
 
@@ -203,7 +203,7 @@ namespace ImGui
203 203
     bool        Button(const char* label, ImVec2 size = ImVec2(0,0), bool repeat_when_held = false);
204 204
     bool        SmallButton(const char* label);
205 205
     bool        CollapsingHeader(const char* label, const char* str_id = NULL, const bool display_frame = true, const bool default_open = false);
206
-    bool        SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
206
+    bool        SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);     // adjust display_format to decorate the value with a prefix or a suffix. Use power!=1.0 for logarithmic sliders.
207 207
     bool        SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
208 208
     bool        SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
209 209
     bool        SliderFloat4(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
@@ -220,7 +220,7 @@ namespace ImGui
220 220
     bool        InputFloat3(const char* label, float v[3], int decimal_precision = -1);
221 221
     bool        InputFloat4(const char* label, float v[4], int decimal_precision = -1);
222 222
     bool        InputInt(const char* label, int* v, int step = 1, int step_fast = 100);
223
-    bool        InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0);
223
+    bool        InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, bool* enter = NULL);
224 224
     bool        Combo(const char* label, int* current_item, const char** items, int items_count, int popup_height_items = 7);
225 225
     bool        Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_height_items = 7);      // Separate items with \0, end item-list with \0\0
226 226
     bool        Combo(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int popup_height_items = 7);
@@ -228,10 +228,10 @@ namespace ImGui
228 228
     bool        ColorEdit3(const char* label, float col[3]);
229 229
     bool        ColorEdit4(const char* label, float col[4], bool show_alpha = true);
230 230
     void        ColorEditMode(ImGuiColorEditMode mode);
231
-    bool        TreeNode(const char* str_label_id);                                 // if returning 'true' the user is responsible for calling TreePop
231
+    bool        TreeNode(const char* str_label_id);                                 // if returning 'true' the node is open and the user is responsible for calling TreePop
232 232
     bool        TreeNode(const char* str_id, const char* fmt, ...);                 // "
233 233
     bool        TreeNode(const void* ptr_id, const char* fmt, ...);                 // "
234
-    void        TreePush(const char* str_id = NULL);                                // already called by TreeNode(), but you can call Push/Pop yourself for layout purpose
234
+    void        TreePush(const char* str_id = NULL);                                // already called by TreeNode(), but you can call Push/Pop yourself for layouting purpose
235 235
     void        TreePush(const void* ptr_id = NULL);                                // "
236 236
     void        TreePop();
237 237
     void        OpenNextNode(bool open);                                            // force open/close the next TreeNode or CollapsingHeader
@@ -290,8 +290,8 @@ enum ImGuiWindowFlags_
290 290
 enum ImGuiInputTextFlags_
291 291
 {
292 292
     // Default: 0
293
-    ImGuiInputTextFlags_CharsDecimal        = 1 << 0,
294
-    ImGuiInputTextFlags_CharsHexadecimal    = 1 << 1,
293
+    ImGuiInputTextFlags_CharsDecimal        = 1 << 0,   // Allow 0123456789.+-*/
294
+    ImGuiInputTextFlags_CharsHexadecimal    = 1 << 1,   // Allow 0123456789ABCDEFabcdef
295 295
     ImGuiInputTextFlags_AutoSelectAll       = 1 << 2,
296 296
     ImGuiInputTextFlags_AlignCenter         = 1 << 3,
297 297
 };

+ 0
- 34
src/deps/utf8-cpp/utf8.h View File

@@ -1,34 +0,0 @@
1
-// Copyright 2006 Nemanja Trifunovic
2
-
3
-/*
4
-Permission is hereby granted, free of charge, to any person or organization
5
-obtaining a copy of the software and accompanying documentation covered by
6
-this license (the "Software") to use, reproduce, display, distribute,
7
-execute, and transmit the Software, and to prepare derivative works of the
8
-Software, and to permit third-parties to whom the Software is furnished to
9
-do so, all subject to the following:
10
-
11
-The copyright notices in the Software and this entire statement, including
12
-the above license grant, this restriction and the following disclaimer,
13
-must be included in all copies of the Software, in whole or in part, and
14
-all derivative works of the Software, unless such copies or derivative
15
-works are solely in the form of machine-executable object code generated by
16
-a source language processor.
17
-
18
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
-FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
21
-SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
22
-FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
23
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
-DEALINGS IN THE SOFTWARE.
25
-*/
26
-
27
-
28
-#ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731
29
-#define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731
30
-
31
-#include "utf8/checked.h"
32
-#include "utf8/unchecked.h"
33
-
34
-#endif // header guard

+ 0
- 323
src/deps/utf8-cpp/utf8/checked.h View File

@@ -1,323 +0,0 @@
1
-// Copyright 2006 Nemanja Trifunovic
2
-
3
-/*
4
-Permission is hereby granted, free of charge, to any person or organization
5
-obtaining a copy of the software and accompanying documentation covered by
6
-this license (the "Software") to use, reproduce, display, distribute,
7
-execute, and transmit the Software, and to prepare derivative works of the
8
-Software, and to permit third-parties to whom the Software is furnished to
9
-do so, all subject to the following:
10
-
11
-The copyright notices in the Software and this entire statement, including
12
-the above license grant, this restriction and the following disclaimer,
13
-must be included in all copies of the Software, in whole or in part, and
14
-all derivative works of the Software, unless such copies or derivative
15
-works are solely in the form of machine-executable object code generated by
16
-a source language processor.
17
-
18
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
-FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
21
-SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
22
-FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
23
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
-DEALINGS IN THE SOFTWARE.
25
-*/
26
-
27
-
28
-#ifndef UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
29
-#define UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
30
-
31
-#include "core.h"
32
-#include <stdexcept>
33
-
34
-namespace utf8
35
-{
36
-    // Exceptions that may be thrown from the library functions.
37
-    class invalid_code_point : public ::std::exception {
38
-        uint32_t cp;
39
-    public:
40
-        invalid_code_point(uint32_t _cp) : cp(_cp) {}
41
-        virtual const char* what() const noexcept { return "Invalid code point"; }
42
-        uint32_t code_point() const {return cp;}
43
-    };
44
-
45
-    class invalid_utf8 : public ::std::exception {
46
-        uint8_t u8;
47
-    public:
48
-        invalid_utf8 (uint8_t u) : u8(u) {}
49
-        virtual const char* what() const noexcept { return "Invalid UTF-8"; }
50
-        uint8_t utf8_octet() const {return u8;}
51
-    };
52
-
53
-    class invalid_utf16 : public ::std::exception {
54
-        uint16_t u16;
55
-    public:
56
-        invalid_utf16 (uint16_t u) : u16(u) {}
57
-        virtual const char* what() const noexcept { return "Invalid UTF-16"; }
58
-        uint16_t utf16_word() const {return u16;}
59
-    };
60
-
61
-    class not_enough_room : public ::std::exception {
62
-    public:
63
-        virtual const char* what() const noexcept { return "Not enough space"; }
64
-    };
65
-
66
-    /// The library API - functions intended to be called by the users
67
-
68
-    template <typename octet_iterator>
69
-    octet_iterator append(uint32_t cp, octet_iterator result)
70
-    {
71
-        if (!utf8::internal::is_code_point_valid(cp))
72
-            throw invalid_code_point(cp);
73
-
74
-        if (cp < 0x80)                        // one octet
75
-            *(result++) = static_cast<uint8_t>(cp);
76
-        else if (cp < 0x800) {                // two octets
77
-            *(result++) = static_cast<uint8_t>((cp >> 6)            | 0xc0);
78
-            *(result++) = static_cast<uint8_t>((cp & 0x3f)          | 0x80);
79
-        }
80
-        else if (cp < 0x10000) {              // three octets
81
-            *(result++) = static_cast<uint8_t>((cp >> 12)           | 0xe0);
82
-            *(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f)   | 0x80);
83
-            *(result++) = static_cast<uint8_t>((cp & 0x3f)          | 0x80);
84
-        }
85
-        else {                                // four octets
86
-            *(result++) = static_cast<uint8_t>((cp >> 18)           | 0xf0);
87
-            *(result++) = static_cast<uint8_t>(((cp >> 12) & 0x3f)  | 0x80);
88
-            *(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f)   | 0x80);
89
-            *(result++) = static_cast<uint8_t>((cp & 0x3f)          | 0x80);
90
-        }
91
-        return result;
92
-    }
93
-
94
-    template <typename octet_iterator, typename output_iterator>
95
-    output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, uint32_t replacement)
96
-    {
97
-        while (start != end) {
98
-            octet_iterator sequence_start = start;
99
-            internal::utf_error err_code = utf8::internal::validate_next(start, end);
100
-            switch (err_code) {
101
-                case internal::UTF8_OK :
102
-                    for (octet_iterator it = sequence_start; it != start; ++it)
103
-                        *out++ = *it;
104
-                    break;
105
-                case internal::NOT_ENOUGH_ROOM:
106
-                    throw not_enough_room();
107
-                case internal::INVALID_LEAD:
108
-                    out = utf8::append (replacement, out);
109
-                    ++start;
110
-                    break;
111
-                case internal::INCOMPLETE_SEQUENCE:
112
-                case internal::OVERLONG_SEQUENCE:
113
-                case internal::INVALID_CODE_POINT:
114
-                    out = utf8::append (replacement, out);
115
-                    ++start;
116
-                    // just one replacement mark for the sequence
117
-                    while (start != end && utf8::internal::is_trail(*start))
118
-                        ++start;
119
-                    break;
120
-            }
121
-        }
122
-        return out;
123
-    }
124
-
125
-    template <typename octet_iterator, typename output_iterator>
126
-    inline output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out)
127
-    {
128
-        static const uint32_t replacement_marker = utf8::internal::mask16(0xfffd);
129
-        return utf8::replace_invalid(start, end, out, replacement_marker);
130
-    }
131
-
132
-    template <typename octet_iterator>
133
-    uint32_t next(octet_iterator& it, octet_iterator end)
134
-    {
135
-        uint32_t cp = 0;
136
-        internal::utf_error err_code = utf8::internal::validate_next(it, end, cp);
137
-        switch (err_code) {
138
-            case internal::UTF8_OK :
139
-                break;
140
-            case internal::NOT_ENOUGH_ROOM :
141
-                throw not_enough_room();
142
-            case internal::INVALID_LEAD :
143
-            case internal::INCOMPLETE_SEQUENCE :
144
-            case internal::OVERLONG_SEQUENCE :
145
-                throw invalid_utf8(*it);
146
-            case internal::INVALID_CODE_POINT :
147
-                throw invalid_code_point(cp);
148
-        }
149
-        return cp;
150
-    }
151
-
152
-    template <typename octet_iterator>
153
-    uint32_t peek_next(octet_iterator it, octet_iterator end)
154
-    {
155
-        return utf8::next(it, end);
156
-    }
157
-
158
-    template <typename octet_iterator>
159
-    uint32_t prior(octet_iterator& it, octet_iterator start)
160
-    {
161
-        // can't do much if it == start
162
-        if (it == start)
163
-            throw not_enough_room();
164
-
165
-        octet_iterator end = it;
166
-        // Go back until we hit either a lead octet or start
167
-        while (utf8::internal::is_trail(*(--it)))
168
-            if (it == start)
169
-                throw invalid_utf8(*it); // error - no lead byte in the sequence
170
-        return utf8::peek_next(it, end);
171
-    }
172
-
173
-    /// Deprecated in versions that include "prior"
174
-    template <typename octet_iterator>
175
-    uint32_t previous(octet_iterator& it, octet_iterator pass_start)
176
-    {
177
-        octet_iterator end = it;
178
-        while (utf8::internal::is_trail(*(--it)))
179
-            if (it == pass_start)
180
-                throw invalid_utf8(*it); // error - no lead byte in the sequence
181
-        octet_iterator temp = it;
182
-        return utf8::next(temp, end);
183
-    }
184
-
185
-    template <typename octet_iterator, typename distance_type>
186
-    void advance (octet_iterator& it, distance_type n, octet_iterator end)
187
-    {
188
-        for (distance_type i = 0; i < n; ++i)
189
-            utf8::next(it, end);
190
-    }
191
-
192
-    template <typename octet_iterator>
193
-    typename std::iterator_traits<octet_iterator>::difference_type
194
-    distance (octet_iterator first, octet_iterator last)
195
-    {
196
-        typename std::iterator_traits<octet_iterator>::difference_type dist;
197
-        for (dist = 0; first < last; ++dist)
198
-            utf8::next(first, last);
199
-        return dist;
200
-    }
201
-
202
-    template <typename u16bit_iterator, typename octet_iterator>
203
-    octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result)
204
-    {
205
-        while (start != end) {
206
-            uint32_t cp = utf8::internal::mask16(*start++);
207
-            // Take care of surrogate pairs first
208
-            if (utf8::internal::is_lead_surrogate(cp)) {
209
-                if (start != end) {
210
-                    uint32_t trail_surrogate = utf8::internal::mask16(*start++);
211
-                    if (utf8::internal::is_trail_surrogate(trail_surrogate))
212
-                        cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET;
213
-                    else
214
-                        throw invalid_utf16(static_cast<uint16_t>(trail_surrogate));
215
-                }
216
-                else
217
-                    throw invalid_utf16(static_cast<uint16_t>(cp));
218
-
219
-            }
220
-            // Lone trail surrogate
221
-            else if (utf8::internal::is_trail_surrogate(cp))
222
-                throw invalid_utf16(static_cast<uint16_t>(cp));
223
-
224
-            result = utf8::append(cp, result);
225
-        }
226
-        return result;
227
-    }
228
-
229
-    template <typename u16bit_iterator, typename octet_iterator>
230
-    u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)
231
-    {
232
-        while (start != end) {
233
-            uint32_t cp = utf8::next(start, end);
234
-            if (cp > 0xffff) { //make a surrogate pair
235
-                *result++ = static_cast<uint16_t>((cp >> 10)   + internal::LEAD_OFFSET);
236
-                *result++ = static_cast<uint16_t>((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN);
237
-            }
238
-            else
239
-                *result++ = static_cast<uint16_t>(cp);
240
-        }
241
-        return result;
242
-    }
243
-
244
-    template <typename octet_iterator, typename u32bit_iterator>
245
-    octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result)
246
-    {
247
-        while (start != end)
248
-            result = utf8::append(*(start++), result);
249
-
250
-        return result;
251
-    }
252
-
253
-    template <typename octet_iterator, typename u32bit_iterator>
254
-    u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)
255
-    {
256
-        while (start != end)
257
-            (*result++) = utf8::next(start, end);
258
-
259
-        return result;
260
-    }
261
-
262
-    // The iterator class
263
-    template <typename octet_iterator>
264
-    class iterator : public std::iterator <std::bidirectional_iterator_tag, uint32_t> {
265
-      octet_iterator it;
266
-      octet_iterator range_start;
267
-      octet_iterator range_end;
268
-      public:
269
-      iterator () {}
270
-      explicit iterator (const octet_iterator& octet_it,
271
-                         const octet_iterator& _range_start,
272
-                         const octet_iterator& _range_end) :
273
-               it(octet_it), range_start(_range_start), range_end(_range_end)
274
-      {
275
-          if (it < range_start || it > range_end)
276
-              throw std::out_of_range("Invalid utf-8 iterator position");
277
-      }
278
-      // the default "big three" are OK
279
-      octet_iterator base () const { return it; }
280
-      uint32_t operator * () const
281
-      {
282
-          octet_iterator temp = it;
283
-          return utf8::next(temp, range_end);
284
-      }
285
-      bool operator == (const iterator& rhs) const
286
-      {
287
-          if (range_start != rhs.range_start || range_end != rhs.range_end)
288
-              throw std::logic_error("Comparing utf-8 iterators defined with different ranges");
289
-          return (it == rhs.it);
290
-      }
291
-      bool operator != (const iterator& rhs) const
292
-      {
293
-          return !(operator == (rhs));
294
-      }
295
-      iterator& operator ++ ()
296
-      {
297
-          utf8::next(it, range_end);
298
-          return *this;
299
-      }
300
-      iterator operator ++ (int)
301
-      {
302
-          iterator temp = *this;
303
-          utf8::next(it, range_end);
304
-          return temp;
305
-      }
306
-      iterator& operator -- ()
307
-      {
308
-          utf8::prior(it, range_start);
309
-          return *this;
310
-      }
311
-      iterator operator -- (int)
312
-      {
313
-          iterator temp = *this;
314
-          utf8::prior(it, range_start);
315
-          return temp;
316
-      }
317
-    }; // class iterator
318
-
319
-} // namespace utf8
320
-
321
-#endif //header guard
322
-
323
-

+ 0
- 329
src/deps/utf8-cpp/utf8/core.h View File

@@ -1,329 +0,0 @@
1
-// Copyright 2006 Nemanja Trifunovic
2
-
3
-/*
4
-Permission is hereby granted, free of charge, to any person or organization
5
-obtaining a copy of the software and accompanying documentation covered by
6
-this license (the "Software") to use, reproduce, display, distribute,
7
-execute, and transmit the Software, and to prepare derivative works of the
8
-Software, and to permit third-parties to whom the Software is furnished to
9
-do so, all subject to the following:
10
-
11
-The copyright notices in the Software and this entire statement, including
12
-the above license grant, this restriction and the following disclaimer,
13
-must be included in all copies of the Software, in whole or in part, and
14
-all derivative works of the Software, unless such copies or derivative
15
-works are solely in the form of machine-executable object code generated by
16
-a source language processor.
17
-
18
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
-FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
21
-SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
22
-FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
23
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
-DEALINGS IN THE SOFTWARE.
25
-*/
26
-
27
-
28
-#ifndef UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
29
-#define UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
30
-
31
-#include <iterator>
32
-
33
-namespace utf8
34
-{
35
-    // The typedefs for 8-bit, 16-bit and 32-bit unsigned integers
36
-    // You may need to change them to match your system.
37
-    // These typedefs have the same names as ones from cstdint, or boost/cstdint
38
-    typedef unsigned char   uint8_t;
39
-    typedef unsigned short  uint16_t;
40
-    typedef unsigned int    uint32_t;
41
-
42
-// Helper code - not intended to be directly called by the library users. May be changed at any time
43
-namespace internal
44
-{
45
-    // Unicode constants
46
-    // Leading (high) surrogates: 0xd800 - 0xdbff
47
-    // Trailing (low) surrogates: 0xdc00 - 0xdfff
48
-    const uint16_t LEAD_SURROGATE_MIN  = 0xd800u;
49
-    const uint16_t LEAD_SURROGATE_MAX  = 0xdbffu;
50
-    const uint16_t TRAIL_SURROGATE_MIN = 0xdc00u;
51
-    const uint16_t TRAIL_SURROGATE_MAX = 0xdfffu;
52
-    const uint16_t LEAD_OFFSET         = LEAD_SURROGATE_MIN - (0x10000 >> 10);
53
-    const uint32_t SURROGATE_OFFSET    = 0x10000u - (LEAD_SURROGATE_MIN << 10) - TRAIL_SURROGATE_MIN;
54
-
55
-    // Maximum valid value for a Unicode code point
56
-    const uint32_t CODE_POINT_MAX      = 0x0010ffffu;
57
-
58
-    template<typename octet_type>
59
-    inline uint8_t mask8(octet_type oc)
60
-    {
61
-        return static_cast<uint8_t>(0xff & oc);
62
-    }
63
-    template<typename u16_type>
64
-    inline uint16_t mask16(u16_type oc)
65
-    {
66
-        return static_cast<uint16_t>(0xffff & oc);
67
-    }
68
-    template<typename octet_type>
69
-    inline bool is_trail(octet_type oc)
70
-    {
71
-        return ((utf8::internal::mask8(oc) >> 6) == 0x2);
72
-    }
73
-
74
-    template <typename u16>
75
-    inline bool is_lead_surrogate(u16 cp)
76
-    {
77
-        return (cp >= LEAD_SURROGATE_MIN && cp <= LEAD_SURROGATE_MAX);
78
-    }
79
-
80
-    template <typename u16>
81
-    inline bool is_trail_surrogate(u16 cp)
82
-    {
83
-        return (cp >= TRAIL_SURROGATE_MIN && cp <= TRAIL_SURROGATE_MAX);
84
-    }
85
-
86
-    template <typename u16>
87
-    inline bool is_surrogate(u16 cp)
88
-    {
89
-        return (cp >= LEAD_SURROGATE_MIN && cp <= TRAIL_SURROGATE_MAX);
90
-    }
91
-
92
-    template <typename u32>
93
-    inline bool is_code_point_valid(u32 cp)
94
-    {
95
-        return (cp <= CODE_POINT_MAX && !utf8::internal::is_surrogate(cp));
96
-    }
97
-
98
-    template <typename octet_iterator>
99
-    inline typename std::iterator_traits<octet_iterator>::difference_type
100
-    sequence_length(octet_iterator lead_it)
101
-    {
102
-        uint8_t lead = utf8::internal::mask8(*lead_it);
103
-        if (lead < 0x80)
104
-            return 1;
105
-        else if ((lead >> 5) == 0x6)
106
-            return 2;
107
-        else if ((lead >> 4) == 0xe)
108
-            return 3;
109
-        else if ((lead >> 3) == 0x1e)
110
-            return 4;
111
-        else
112
-            return 0;
113
-    }
114
-
115
-    template <typename octet_difference_type>
116
-    inline bool is_overlong_sequence(uint32_t cp, octet_difference_type length)
117
-    {
118
-        if (cp < 0x80) {
119
-            if (length != 1) 
120
-                return true;
121
-        }
122
-        else if (cp < 0x800) {
123
-            if (length != 2) 
124
-                return true;
125
-        }
126
-        else if (cp < 0x10000) {
127
-            if (length != 3) 
128
-                return true;
129
-        }
130
-
131
-        return false;
132
-    }
133
-
134
-    enum utf_error {UTF8_OK, NOT_ENOUGH_ROOM, INVALID_LEAD, INCOMPLETE_SEQUENCE, OVERLONG_SEQUENCE, INVALID_CODE_POINT};
135
-
136
-    /// Helper for get_sequence_x
137
-    template <typename octet_iterator>
138
-    utf_error increase_safely(octet_iterator& it, octet_iterator end)
139
-    {
140
-        if (++it == end)
141
-            return NOT_ENOUGH_ROOM;
142
-
143
-        if (!utf8::internal::is_trail(*it))
144
-            return INCOMPLETE_SEQUENCE;
145
-        
146
-        return UTF8_OK;
147
-    }
148
-
149
-    #define UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(IT, END) {utf_error ret = increase_safely(IT, END); if (ret != UTF8_OK) return ret;}    
150
-
151
-    /// get_sequence_x functions decode utf-8 sequences of the length x
152
-    template <typename octet_iterator>
153
-    utf_error get_sequence_1(octet_iterator& it, octet_iterator end, uint32_t& code_point)
154
-    {
155
-        if (it == end)
156
-            return NOT_ENOUGH_ROOM;
157
-
158
-        code_point = utf8::internal::mask8(*it);
159
-
160
-        return UTF8_OK;
161
-    }
162
-
163
-    template <typename octet_iterator>
164
-    utf_error get_sequence_2(octet_iterator& it, octet_iterator end, uint32_t& code_point)
165
-    {
166
-        if (it == end) 
167
-            return NOT_ENOUGH_ROOM;
168
-        
169
-        code_point = utf8::internal::mask8(*it);
170
-
171
-        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
172
-
173
-        code_point = ((code_point << 6) & 0x7ff) + ((*it) & 0x3f);
174
-
175
-        return UTF8_OK;
176
-    }
177
-
178
-    template <typename octet_iterator>
179
-    utf_error get_sequence_3(octet_iterator& it, octet_iterator end, uint32_t& code_point)
180
-    {
181
-        if (it == end)
182
-            return NOT_ENOUGH_ROOM;
183
-            
184
-        code_point = utf8::internal::mask8(*it);
185
-
186
-        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
187
-
188
-        code_point = ((code_point << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff);
189
-
190
-        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
191
-
192
-        code_point += (*it) & 0x3f;
193
-
194
-        return UTF8_OK;
195
-    }
196
-
197
-    template <typename octet_iterator>
198
-    utf_error get_sequence_4(octet_iterator& it, octet_iterator end, uint32_t& code_point)
199
-    {
200
-        if (it == end)
201
-           return NOT_ENOUGH_ROOM;
202
-
203
-        code_point = utf8::internal::mask8(*it);
204
-
205
-        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
206
-
207
-        code_point = ((code_point << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff);
208
-
209
-        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
210
-
211
-        code_point += (utf8::internal::mask8(*it) << 6) & 0xfff;
212
-
213
-        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
214
-
215
-        code_point += (*it) & 0x3f;
216
-
217
-        return UTF8_OK;
218
-    }
219
-
220
-    #undef UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR
221
-
222
-    template <typename octet_iterator>
223
-    utf_error validate_next(octet_iterator& it, octet_iterator end, uint32_t& code_point)
224
-    {
225
-        // Save the original value of it so we can go back in case of failure
226
-        // Of course, it does not make much sense with i.e. stream iterators
227
-        octet_iterator original_it = it;
228
-
229
-        uint32_t cp = 0;
230
-        // Determine the sequence length based on the lead octet
231
-        typedef typename std::iterator_traits<octet_iterator>::difference_type octet_difference_type;
232
-        const octet_difference_type length = utf8::internal::sequence_length(it);
233
-
234
-        // Get trail octets and calculate the code point
235
-        utf_error err = UTF8_OK;
236
-        switch (length) {
237
-            case 0: 
238
-                return INVALID_LEAD;
239
-            case 1:
240
-                err = utf8::internal::get_sequence_1(it, end, cp);
241
-                break;
242
-            case 2:
243
-                err = utf8::internal::get_sequence_2(it, end, cp);
244
-            break;
245
-            case 3:
246
-                err = utf8::internal::get_sequence_3(it, end, cp);
247
-            break;
248
-            case 4:
249
-                err = utf8::internal::get_sequence_4(it, end, cp);
250
-            break;
251
-        }
252
-
253
-        if (err == UTF8_OK) {
254
-            // Decoding succeeded. Now, security checks...
255
-            if (utf8::internal::is_code_point_valid(cp)) {
256
-                if (!utf8::internal::is_overlong_sequence(cp, length)){
257
-                    // Passed! Return here.
258
-                    code_point = cp;
259
-                    ++it;
260
-                    return UTF8_OK;
261
-                }
262
-                else
263
-                    err = OVERLONG_SEQUENCE;
264
-            }
265
-            else 
266
-                err = INVALID_CODE_POINT;
267
-        }
268
-
269
-        // Failure branch - restore the original value of the iterator
270
-        it = original_it;
271
-        return err;
272
-    }
273
-
274
-    template <typename octet_iterator>
275
-    inline utf_error validate_next(octet_iterator& it, octet_iterator end) {
276
-        uint32_t ignored;
277
-        return utf8::internal::validate_next(it, end, ignored);
278
-    }
279
-
280
-} // namespace internal
281
-
282
-    /// The library API - functions intended to be called by the users
283
-
284
-    // Byte order mark
285
-    const uint8_t bom[] = {0xef, 0xbb, 0xbf};
286
-
287
-    template <typename octet_iterator>
288
-    octet_iterator find_invalid(octet_iterator start, octet_iterator end)
289
-    {
290
-        octet_iterator result = start;
291
-        while (result != end) {
292
-            utf8::internal::utf_error err_code = utf8::internal::validate_next(result, end);
293
-            if (err_code != internal::UTF8_OK)
294
-                return result;
295
-        }
296
-        return result;
297
-    }
298
-
299
-    template <typename octet_iterator>
300
-    inline bool is_valid(octet_iterator start, octet_iterator end)
301
-    {
302
-        return (utf8::find_invalid(start, end) == end);
303
-    }
304
-
305
-    template <typename octet_iterator>
306
-    inline bool starts_with_bom (octet_iterator it, octet_iterator end)
307
-    {
308
-        return (
309
-            ((it != end) && (utf8::internal::mask8(*it++)) == bom[0]) &&
310
-            ((it != end) && (utf8::internal::mask8(*it++)) == bom[1]) &&
311
-            ((it != end) && (utf8::internal::mask8(*it))   == bom[2])
312
-           );
313
-    }
314
-	
315
-    //Deprecated in release 2.3 
316
-    template <typename octet_iterator>
317
-    inline bool is_bom (octet_iterator it)
318
-    {
319
-        return (
320
-            (utf8::internal::mask8(*it++)) == bom[0] &&
321
-            (utf8::internal::mask8(*it++)) == bom[1] &&
322
-            (utf8::internal::mask8(*it))   == bom[2]
323
-           );
324
-    }
325
-} // namespace utf8
326
-
327
-#endif // header guard
328
-
329
-

+ 0
- 228
src/deps/utf8-cpp/utf8/unchecked.h View File

@@ -1,228 +0,0 @@
1
-// Copyright 2006 Nemanja Trifunovic
2
-
3
-/*
4
-Permission is hereby granted, free of charge, to any person or organization
5
-obtaining a copy of the software and accompanying documentation covered by
6
-this license (the "Software") to use, reproduce, display, distribute,
7
-execute, and transmit the Software, and to prepare derivative works of the
8
-Software, and to permit third-parties to whom the Software is furnished to
9
-do so, all subject to the following:
10
-
11
-The copyright notices in the Software and this entire statement, including
12
-the above license grant, this restriction and the following disclaimer,
13
-must be included in all copies of the Software, in whole or in part, and
14
-all derivative works of the Software, unless such copies or derivative
15
-works are solely in the form of machine-executable object code generated by
16
-a source language processor.
17
-
18
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
-FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
21
-SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
22
-FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
23
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
-DEALINGS IN THE SOFTWARE.
25
-*/
26
-
27
-
28
-#ifndef UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
29
-#define UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
30
-
31
-#include "core.h"
32
-
33
-namespace utf8
34
-{
35
-    namespace unchecked 
36
-    {
37
-        template <typename octet_iterator>
38
-        octet_iterator append(uint32_t cp, octet_iterator result)
39
-        {
40
-            if (cp < 0x80)                        // one octet
41
-                *(result++) = static_cast<uint8_t>(cp);  
42
-            else if (cp < 0x800) {                // two octets
43
-                *(result++) = static_cast<uint8_t>((cp >> 6)          | 0xc0);
44
-                *(result++) = static_cast<uint8_t>((cp & 0x3f)        | 0x80);
45
-            }
46
-            else if (cp < 0x10000) {              // three octets
47
-                *(result++) = static_cast<uint8_t>((cp >> 12)         | 0xe0);
48
-                *(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f) | 0x80);
49
-                *(result++) = static_cast<uint8_t>((cp & 0x3f)        | 0x80);
50
-            }
51
-            else {                                // four octets
52
-                *(result++) = static_cast<uint8_t>((cp >> 18)         | 0xf0);
53
-                *(result++) = static_cast<uint8_t>(((cp >> 12) & 0x3f)| 0x80);
54
-                *(result++) = static_cast<uint8_t>(((cp >> 6) & 0x3f) | 0x80);
55
-                *(result++) = static_cast<uint8_t>((cp & 0x3f)        | 0x80);
56
-            }
57
-            return result;
58
-        }
59
-
60
-        template <typename octet_iterator>
61
-        uint32_t next(octet_iterator& it)
62
-        {
63
-            uint32_t cp = utf8::internal::mask8(*it);
64
-            typename std::iterator_traits<octet_iterator>::difference_type length = utf8::internal::sequence_length(it);
65
-            switch (length) {
66
-                case 1:
67
-                    break;
68
-                case 2:
69
-                    it++;
70
-                    cp = ((cp << 6) & 0x7ff) + ((*it) & 0x3f);
71
-                    break;
72
-                case 3:
73
-                    ++it; 
74
-                    cp = ((cp << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff);
75
-                    ++it;
76
-                    cp += (*it) & 0x3f;
77
-                    break;
78
-                case 4:
79
-                    ++it;
80
-                    cp = ((cp << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff);                
81
-                    ++it;
82
-                    cp += (utf8::internal::mask8(*it) << 6) & 0xfff;
83
-                    ++it;
84
-                    cp += (*it) & 0x3f; 
85
-                    break;
86
-            }
87
-            ++it;
88
-            return cp;        
89
-        }
90
-
91
-        template <typename octet_iterator>
92
-        uint32_t peek_next(octet_iterator it)
93
-        {
94
-            return utf8::unchecked::next(it);    
95
-        }
96
-
97
-        template <typename octet_iterator>
98
-        uint32_t prior(octet_iterator& it)
99
-        {
100
-            while (utf8::internal::is_trail(*(--it))) ;
101
-            octet_iterator temp = it;
102
-            return utf8::unchecked::next(temp);
103
-        }
104
-
105
-        // Deprecated in versions that include prior, but only for the sake of consistency (see utf8::previous)
106
-        template <typename octet_iterator>
107
-        inline uint32_t previous(octet_iterator& it)
108
-        {
109
-            return utf8::unchecked::prior(it);
110
-        }
111
-
112
-        template <typename octet_iterator, typename distance_type>
113
-        void advance (octet_iterator& it, distance_type n)
114
-        {
115
-            for (distance_type i = 0; i < n; ++i)
116
-                utf8::unchecked::next(it);
117
-        }
118
-
119
-        template <typename octet_iterator>
120
-        typename std::iterator_traits<octet_iterator>::difference_type
121
-        distance (octet_iterator first, octet_iterator last)
122
-        {
123
-            typename std::iterator_traits<octet_iterator>::difference_type dist;
124
-            for (dist = 0; first < last; ++dist) 
125
-                utf8::unchecked::next(first);
126
-            return dist;
127
-        }
128
-
129
-        template <typename u16bit_iterator, typename octet_iterator>
130
-        octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result)
131
-        {       
132
-            while (start != end) {
133
-                uint32_t cp = utf8::internal::mask16(*start++);
134
-            // Take care of surrogate pairs first
135
-                if (utf8::internal::is_lead_surrogate(cp)) {
136
-                    uint32_t trail_surrogate = utf8::internal::mask16(*start++);
137
-                    cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET;
138
-                }
139
-                result = utf8::unchecked::append(cp, result);
140
-            }
141
-            return result;         
142
-        }
143
-
144
-        template <typename u16bit_iterator, typename octet_iterator>
145
-        u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)
146
-        {
147
-            while (start < end) {
148
-                uint32_t cp = utf8::unchecked::next(start);
149
-                if (cp > 0xffff) { //make a surrogate pair
150
-                    *result++ = static_cast<uint16_t>((cp >> 10)   + internal::LEAD_OFFSET);
151
-                    *result++ = static_cast<uint16_t>((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN);
152
-                }
153
-                else
154
-                    *result++ = static_cast<uint16_t>(cp);
155
-            }
156
-            return result;
157
-        }
158
-
159
-        template <typename octet_iterator, typename u32bit_iterator>
160
-        octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result)
161
-        {
162
-            while (start != end)
163
-                result = utf8::unchecked::append(*(start++), result);
164
-
165
-            return result;
166
-        }
167
-
168
-        template <typename octet_iterator, typename u32bit_iterator>
169
-        u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)
170
-        {
171
-            while (start < end)
172
-                (*result++) = utf8::unchecked::next(start);
173
-
174
-            return result;
175
-        }
176
-
177
-        // The iterator class
178
-        template <typename octet_iterator>
179
-          class iterator : public std::iterator <std::bidirectional_iterator_tag, uint32_t> { 
180
-            octet_iterator it;
181
-            public:
182
-            iterator () {}
183
-            explicit iterator (const octet_iterator& octet_it): it(octet_it) {}
184
-            // the default "big three" are OK
185
-            octet_iterator base () const { return it; }
186
-            uint32_t operator * () const
187
-            {
188
-                octet_iterator temp = it;
189
-                return utf8::unchecked::next(temp);
190
-            }
191
-            bool operator == (const iterator& rhs) const 
192
-            { 
193
-                return (it == rhs.it);
194
-            }
195
-            bool operator != (const iterator& rhs) const
196
-            {
197
-                return !(operator == (rhs));
198
-            }
199
-            iterator& operator ++ () 
200
-            {
201
-                ::std::advance(it, utf8::internal::sequence_length(it));
202
-                return *this;
203
-            }
204
-            iterator operator ++ (int)
205
-            {
206
-                iterator temp = *this;
207
-                ::std::advance(it, utf8::internal::sequence_length(it));
208
-                return temp;
209
-            }  
210
-            iterator& operator -- ()
211
-            {
212
-                utf8::unchecked::prior(it);
213
-                return *this;
214
-            }
215
-            iterator operator -- (int)
216
-            {
217
-                iterator temp = *this;
218
-                utf8::unchecked::prior(it);
219
-                return temp;
220
-            }
221
-          }; // class iterator
222
-
223
-    } // namespace utf8::unchecked
224
-} // namespace utf8 
225
-
226
-
227
-#endif // header guard
228
-

+ 23
- 21
src/main.cpp View File

@@ -9,7 +9,6 @@
9 9
 #include <memory>
10 10
 
11 11
 #include "global.h"
12
-#include "Console.h"
13 12
 #include "Exception.h"
14 13
 #include "commander/commander.h"
15 14
 #include "commands/Command.h"
@@ -18,7 +17,6 @@
18 17
 #ifndef UNIT_TEST
19 18
 
20 19
 #include "Camera.h"
21
-#include "Debug.h"
22 20
 #include "FontManager.h"
23 21
 #include "Game.h"
24 22
 #include "Log.h"
@@ -45,8 +43,6 @@
45 43
 static std::string configFileToUse;
46 44
 
47 45
 static std::shared_ptr<Camera> gCamera;
48
-static std::shared_ptr<Console> gConsole;
49
-static std::shared_ptr<Debug> gDebug;
50 46
 static std::shared_ptr<FontManager> gFont;
51 47
 static std::shared_ptr<Game> gGame;
52 48
 static std::shared_ptr<Log> gLog;
@@ -62,14 +58,6 @@ Camera &getCamera() {
62 58
     return *gCamera;
63 59
 }
64 60
 
65
-Console &getConsole() {
66
-    return *gConsole;
67
-}
68
-
69
-Debug& getDebug() {
70
-    return *gDebug;
71
-}
72
-
73 61
 Font &getFont() {
74 62
     return *gFont;
75 63
 }
@@ -121,8 +109,6 @@ int main(int argc, char* argv[]) {
121 109
     command_free(&cmd);
122 110
 
123 111
     gCamera.reset(new Camera());
124
-    gConsole.reset(new Console());
125
-    gDebug.reset(new Debug());
126 112
     gFont.reset(new FontManager());
127 113
     gGame.reset(new Game());
128 114
     gLog.reset(new Log());
@@ -189,25 +175,39 @@ int main(int argc, char* argv[]) {
189 175
         return -5;
190 176
     }
191 177
 
192
-    // Initialize UIs
193
-    error = UI::passInitialize();
178
+    // Initialize Menu
179
+    error = getMenu().initialize();
194 180
     if (error != 0) {
195
-        std::cout << "Could not initialize UIs (" << error << ")!" << std::endl;
181
+        std::cout << "Could not initialize Menu (" << error << ")!" << std::endl;
196 182
         return -6;
197 183
     }
198 184
 
185
+    // Initialize Debug UI
186
+    error = UI::initialize();
187
+    if (error != 0) {
188
+        std::cout << "Could not initialize Debug UI (" << error << ")!" << std::endl;
189
+        return -7;
190
+    }
191
+
192
+    // Initialize Game Engine
193
+    error = getGame().initialize();
194
+    if (error != 0) {
195
+        std::cout << "Could not initialize Game (" << error << ")!" << std::endl;
196
+        return -8;
197
+    }
198
+
199 199
     getLog() << "Starting " << VERSION << Log::endl;
200
-    getMenu().moveToTop();
200
+    getMenu().setVisible(true);
201 201
     systemTimerReset();
202 202
     getRunTime().setRunning(true);
203 203
 
204 204
     while (getRunTime().isRunning()) {
205 205
         getWindow().eventHandling();
206
-        UI::passCalculate();
206
+        UI::calculate();
207 207
         renderFrame();
208 208
     }
209 209
 
210
-    UI::passShutdown();
210
+    UI::shutdown();
211 211
 
212 212
 #ifdef DEBUG
213 213
     std::cout << std::endl;
@@ -222,7 +222,9 @@ int main(int argc, char* argv[]) {
222 222
 }
223 223
 
224 224
 void renderFrame() {
225
-    UI::passDisplay();
225
+    getGame().display();
226
+    getMenu().display();
227
+    UI::display();
226 228
     getWindow().swapBuffersGL();
227 229
 }
228 230
 

Loading…
Cancel
Save