Browse Source

Started integrating imgui

Thomas Buck 9 years ago
parent
commit
ae407b1b59

+ 1
- 0
ChangeLog.md View File

@@ -7,6 +7,7 @@
7 7
       can be stacked arbitrarily. The top most gets keyboard/mouse/action events.
8 8
     * Removed old C-String handling utility methods, now using std::string
9 9
     * Moved getX() methods from main into their respective cpp file
10
+    * Started work on integrating imgui
10 11
 
11 12
     [ 20140831 ]
12 13
     * Moved command specific code from OpenRaider to static Command methods

+ 2
- 0
README.md View File

@@ -179,3 +179,5 @@ The [clibs/commander](https://github.com/clibs/commander) dependency is Copyrigh
179 179
 
180 180
 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.
181 181
 
182
+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.
183
+

+ 20
- 2
include/UI.h View File

@@ -9,9 +9,13 @@
9 9
 #define _UI_H_
10 10
 
11 11
 #include <functional>
12
+#include <list>
12 13
 #include <memory>
14
+#include <tuple>
13 15
 #include <vector>
14 16
 
17
+#include "imgui/imgui.h"
18
+
15 19
 class UI {
16 20
 public:
17 21
     virtual ~UI();
@@ -28,8 +32,8 @@ public:
28 32
     virtual void moveToTop();
29 33
     virtual void makeInvisible();
30 34
 
31
-    static void addWindow(UI* window);
32
-    static void removeWindow(UI *window);
35
+    static int initialize();
36
+    static void eventsFinished();
33 37
     static void displayInOrder();
34 38
     static void passKeyboard(KeyboardButton key, bool pressed);
35 39
     static void passText(char *text, bool notFinished);
@@ -38,9 +42,18 @@ public:
38 42
     static void passMouseScroll(int xrel, int yrel);
39 43
 
40 44
 protected:
45
+    static void addWindow(UI* window);
46
+    static void removeWindow(UI *window);
47
+
41 48
     long zPos;
42 49
 
43 50
 private:
51
+    static void sendKeyboard(KeyboardButton key, bool pressed);
52
+    static void sendText(char *text, bool notFinished);
53
+    static void sendMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released);
54
+    static void sendMouseMotion(int xrel, int yrel);
55
+    static void sendMouseScroll(int xrel, int yrel);
56
+    static void renderImGui(ImDrawList** const draw_lists, int count);
44 57
     static void findInList(UI *w, std::function<void (unsigned long i)> func);
45 58
     static bool isOnTop(unsigned long windowID);
46 59
     static void moveToTop(unsigned long windowID);
@@ -48,6 +61,11 @@ private:
48 61
     static bool compareUIs(UI* a, UI* b);
49 62
 
50 63
     static std::vector<UI*> windows;
64
+    static std::list<std::tuple<KeyboardButton, bool>> keyboardEvents;
65
+    static std::list<std::tuple<char *, bool>> textEvents;
66
+    static std::list<std::tuple<unsigned int, unsigned int, KeyboardButton, bool>> clickEvents;
67
+    static std::list<std::tuple<int, int>> motionEvents;
68
+    static std::list<std::tuple<int, int>> scrollEvents;
51 69
 };
52 70
 
53 71
 #endif

+ 1
- 1
src/MenuFolder.cpp View File

@@ -185,7 +185,7 @@ void MenuFolder::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton
185 185
 }
186 186
 
187 187
 void MenuFolder::handleMouseScroll(int xrel, int yrel) {
188
-    if (handleMouseScrollDialog(xrel, yrel));
188
+    if (handleMouseScrollDialog(xrel, yrel))
189 189
         return;
190 190
 
191 191
     assert((xrel != 0) || (yrel != 0));

+ 6
- 0
src/OpenRaider.cpp View File

@@ -144,6 +144,12 @@ int OpenRaider::initialize() {
144 144
         return -7;
145 145
     }
146 146
 
147
+    error = UI::initialize();
148
+    if (error != 0) {
149
+        printf("Could not Initialize UI (%d)!\n", error);
150
+        return -8;
151
+    }
152
+
147 153
 #ifdef DEBUG
148 154
     mFPS = true;
149 155
 #endif

+ 201
- 15
src/UI.cpp View File

@@ -11,10 +11,20 @@
11 11
 #include "Console.h"
12 12
 #include "Menu.h"
13 13
 #include "OpenRaider.h"
14
+#include "TextureManager.h"
14 15
 #include "Window.h"
15
-#include "UI.h"
16
+
17
+#define STB_IMAGE_IMPLEMENTATION
18
+#include "imgui/stb_image.h"
16 19
 
17 20
 std::vector<UI*> UI::windows;
21
+std::list<std::tuple<KeyboardButton, bool>> UI::keyboardEvents;
22
+std::list<std::tuple<char *, bool>> UI::textEvents;
23
+std::list<std::tuple<unsigned int, unsigned int, KeyboardButton, bool>> UI::clickEvents;
24
+std::list<std::tuple<int, int>> UI::motionEvents;
25
+std::list<std::tuple<int, int>> UI::scrollEvents;
26
+
27
+static GLuint fontTex;
18 28
 
19 29
 UI::~UI() {
20 30
 }
@@ -27,6 +37,180 @@ void UI::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button,
27 37
 void UI::handleMouseMotion(int xrel, int yrel) { }
28 38
 void UI::handleMouseScroll(int xrel, int yrel) { }
29 39
 
40
+int UI::initialize() {
41
+    ImGuiIO& io = ImGui::GetIO();
42
+    io.DisplaySize = ImVec2((float)getWindow().getWidth(), (float)getWindow().getHeight());
43
+    io.DeltaTime = 1.0f/60.0f;
44
+    io.PixelCenterOffset = 0.0f;
45
+
46
+    io.KeyMap[ImGuiKey_Tab] = tabKey;
47
+    io.KeyMap[ImGuiKey_LeftArrow] = leftKey;
48
+    io.KeyMap[ImGuiKey_RightArrow] = rightKey;
49
+    io.KeyMap[ImGuiKey_UpArrow] = upKey;
50
+    io.KeyMap[ImGuiKey_DownArrow] = downKey;
51
+    io.KeyMap[ImGuiKey_Home] = homeKey;
52
+    io.KeyMap[ImGuiKey_End] = endKey;
53
+    io.KeyMap[ImGuiKey_Delete] = delKey;
54
+    io.KeyMap[ImGuiKey_Backspace] = backspaceKey;
55
+    io.KeyMap[ImGuiKey_Enter] = enterKey;
56
+    io.KeyMap[ImGuiKey_Escape] = escapeKey;
57
+    io.KeyMap[ImGuiKey_A] = aKey;
58
+    io.KeyMap[ImGuiKey_C] = cKey;
59
+    io.KeyMap[ImGuiKey_V] = vKey;
60
+    io.KeyMap[ImGuiKey_X] = xKey;
61
+    io.KeyMap[ImGuiKey_Y] = yKey;
62
+    io.KeyMap[ImGuiKey_Z] = zKey;
63
+
64
+    io.RenderDrawListsFn = UI::renderImGui;
65
+
66
+    // Load font texture
67
+    //glGenTextures(1, &fontTex);
68
+    //glBindTexture(GL_TEXTURE_2D, fontTex);
69
+    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
70
+    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
71
+    const void* png_data;
72
+    unsigned int png_size;
73
+    ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size);
74
+    int tex_x, tex_y, tex_comp;
75
+    void* tex_data = stbi_load_from_memory((const unsigned char*)png_data, (int)png_size, &tex_x, &tex_y, &tex_comp, 0);
76
+    //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_x, tex_y, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_data);
77
+    fontTex = getTextureManager().loadBufferSlot((unsigned char *)tex_data, tex_x, tex_y, RGBA, 32, 0);
78
+    stbi_image_free(tex_data);
79
+
80
+    return 0;
81
+}
82
+
83
+void UI::eventsFinished() {
84
+    ImGui::NewFrame();
85
+    ImGuiIO& io = ImGui::GetIO();
86
+
87
+    if (!io.WantCaptureKeyboard) {
88
+        while (keyboardEvents.size() > 0) {
89
+            sendKeyboard(std::get<0>(keyboardEvents.front()), std::get<1>(keyboardEvents.front()));
90
+            keyboardEvents.pop_front();
91
+        }
92
+
93
+        while (textEvents.size() > 0) {
94
+            sendText(std::get<0>(textEvents.front()), std::get<1>(textEvents.front()));
95
+            textEvents.pop_front();
96
+        }
97
+    }
98
+
99
+    if (!io.WantCaptureMouse) {
100
+        while (clickEvents.size() > 0) {
101
+            sendMouseClick(std::get<0>(clickEvents.front()), std::get<1>(clickEvents.front()),
102
+                    std::get<2>(clickEvents.front()), std::get<3>(clickEvents.front()));
103
+            clickEvents.pop_front();
104
+        }
105
+
106
+        while (motionEvents.size() > 0) {
107
+            sendMouseMotion(std::get<0>(motionEvents.front()), std::get<1>(motionEvents.front()));
108
+            motionEvents.pop_front();
109
+        }
110
+
111
+        while (scrollEvents.size() > 0) {
112
+            sendMouseScroll(std::get<0>(scrollEvents.front()), std::get<1>(scrollEvents.front()));
113
+            scrollEvents.pop_front();
114
+        }
115
+    }
116
+
117
+    keyboardEvents.clear();
118
+    textEvents.clear();
119
+    clickEvents.clear();
120
+    motionEvents.clear();
121
+    scrollEvents.clear();
122
+
123
+    ImGui::SetNewWindowDefaultPos(ImVec2(50, 50));
124
+    bool show_test_window = true;
125
+    ImGui::ShowTestWindow(&show_test_window);
126
+}
127
+
128
+void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
129
+    if (cmd_lists_count == 0)
130
+        return;
131
+
132
+    glDisable(GL_CULL_FACE);
133
+    glDisable(GL_DEPTH_TEST);
134
+    glEnable(GL_SCISSOR_TEST);
135
+    //glEnableClientState(GL_VERTEX_ARRAY);
136
+    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
137
+    glEnableClientState(GL_COLOR_ARRAY);
138
+
139
+    // Setup texture
140
+    //glBindTexture(GL_TEXTURE_2D, fontTex);
141
+    //glEnable(GL_TEXTURE_2D);
142
+    getTextureManager().bindTextureId(fontTex);
143
+
144
+    const float width = ImGui::GetIO().DisplaySize.x;
145
+    const float height = ImGui::GetIO().DisplaySize.y;
146
+
147
+    /*
148
+    // Setup orthographic projection matrix
149
+    glMatrixMode(GL_PROJECTION);
150
+    glLoadIdentity();
151
+    glOrtho(0.0f, width, height, 0.0f, -1.0f, +1.0f);
152
+    glMatrixMode(GL_MODELVIEW);
153
+    glLoadIdentity();
154
+    */
155
+
156
+    // Render command lists
157
+    for (int n = 0; n < cmd_lists_count; n++) {
158
+        const ImDrawList* cmd_list = cmd_lists[n];
159
+        const unsigned char* vtx_buffer = (const unsigned char*)cmd_list->vtx_buffer.begin();
160
+        glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer));
161
+        glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer+8));
162
+        glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer+16));
163
+
164
+        int vtx_offset = 0;
165
+        const ImDrawCmd* pcmd_end = cmd_list->commands.end();
166
+        for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++) {
167
+            glScissor((int)pcmd->clip_rect.x, (int)(height - pcmd->clip_rect.w),
168
+                    (int)(pcmd->clip_rect.z - pcmd->clip_rect.x),
169
+                    (int)(pcmd->clip_rect.w - pcmd->clip_rect.y));
170
+            glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count);
171
+            vtx_offset += pcmd->vtx_count;
172
+        }
173
+    }
174
+
175
+    glEnable(GL_CULL_FACE);
176
+    glEnable(GL_DEPTH_TEST);
177
+    glDisable(GL_SCISSOR_TEST);
178
+    glDisableClientState(GL_COLOR_ARRAY);
179
+    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
180
+    //glDisableClientState(GL_VERTEX_ARRAY);
181
+}
182
+
183
+void UI::passKeyboard(KeyboardButton key, bool pressed) {
184
+    keyboardEvents.push_back(std::make_tuple(key, pressed));
185
+
186
+    ImGuiIO& io = ImGui::GetIO();
187
+    io.KeysDown[key] = pressed;
188
+    io.KeyCtrl = io.KeysDown[leftctrlKey] | io.KeysDown[rightctrlKey];
189
+    io.KeyShift = io.KeysDown[leftshiftKey] | io.KeysDown[rightshiftKey];
190
+}
191
+
192
+void UI::passText(char *text, bool notFinished) {
193
+    textEvents.push_back(std::make_tuple(text, notFinished));
194
+    // TODO
195
+}
196
+
197
+void UI::passMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
198
+    clickEvents.push_back(std::make_tuple(x, y, button, released));
199
+    // TODO
200
+}
201
+
202
+void UI::passMouseMotion(int xrel, int yrel) {
203
+    motionEvents.push_back(std::make_tuple(xrel, yrel));
204
+    // TODO
205
+}
206
+
207
+void UI::passMouseScroll(int xrel, int yrel) {
208
+    scrollEvents.push_back(std::make_tuple(xrel, yrel));
209
+
210
+    ImGuiIO& io = ImGui::GetIO();
211
+    io.MouseWheel = (yrel != 0) ? yrel > 0 ? 1 : -1 : 0;
212
+}
213
+
30 214
 void UI::addWindow(UI* window) {
31 215
     windows.push_back(window);
32 216
 }
@@ -97,7 +281,18 @@ void UI::makeInvisible() {
97 281
     });
98 282
 }
99 283
 
100
-void UI::passKeyboard(KeyboardButton key, bool pressed) {
284
+void UI::displayInOrder() {
285
+    std::sort(windows.begin(), windows.end(), compareUIs);
286
+    for (auto &x : windows) {
287
+        if (x->zPos >= 0) {
288
+            x->display();
289
+        }
290
+    }
291
+
292
+    ImGui::Render();
293
+}
294
+
295
+void UI::sendKeyboard(KeyboardButton key, bool pressed) {
101 296
     if (pressed) {
102 297
         if (getOpenRaider().keyBindings[menuAction] == key) {
103 298
             if (getMenu().isOnTop()) {
@@ -128,12 +323,12 @@ void UI::passKeyboard(KeyboardButton key, bool pressed) {
128 323
         getWindow().setMousegrab(mousegrab);
129 324
 }
130 325
 
131
-void UI::passText(char *text, bool notFinished) {
326
+void UI::sendText(char *text, bool notFinished) {
132 327
     auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
133 328
     (*maxIterator)->handleText(text, notFinished);
134 329
 }
135 330
 
136
-void UI::passMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
331
+void UI::sendMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
137 332
     auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
138 333
     (*maxIterator)->handleMouseClick(x, y, button, released);
139 334
 
@@ -144,22 +339,13 @@ void UI::passMouseClick(unsigned int x, unsigned int y, KeyboardButton button, b
144 339
     }
145 340
 }
146 341
 
147
-void UI::passMouseMotion(int xrel, int yrel) {
342
+void UI::sendMouseMotion(int xrel, int yrel) {
148 343
     auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
149 344
     (*maxIterator)->handleMouseMotion(xrel, yrel);
150 345
 }
151 346
 
152
-void UI::passMouseScroll(int xrel, int yrel) {
347
+void UI::sendMouseScroll(int xrel, int yrel) {
153 348
     auto maxIterator = std::max_element(windows.begin(), windows.end(), compareUIs);
154 349
     (*maxIterator)->handleMouseScroll(xrel, yrel);
155 350
 }
156 351
 
157
-void UI::displayInOrder() {
158
-    std::sort(windows.begin(), windows.end(), compareUIs);
159
-    for (auto &x : windows) {
160
-        if (x->zPos >= 0) {
161
-            x->display();
162
-        }
163
-    }
164
-}
165
-

+ 2
- 0
src/WindowSDL.cpp View File

@@ -439,6 +439,8 @@ void WindowSDL::eventHandling() {
439 439
                 exit(0);
440 440
         }
441 441
     }
442
+
443
+    UI::eventsFinished();
442 444
 }
443 445
 
444 446
 void WindowSDL::setTextInput(bool on) {

+ 1
- 0
src/deps/CMakeLists.txt View File

@@ -1,5 +1,6 @@
1 1
 # Source files
2 2
 set (DEPS_SRCS ${DEPS_SRCS} "commander/commander.c")
3
+set (DEPS_SRCS ${DEPS_SRCS} "imgui/imgui.cpp")
3 4
 
4 5
 # Add library
5 6
 add_library (OpenRaider_deps OBJECT ${DEPS_SRCS})

+ 21
- 0
src/deps/imgui/LICENSE View File

@@ -0,0 +1,21 @@
1
+The MIT License (MIT)
2
+
3
+Copyright (c) 2014 Omar Cornut
4
+
5
+Permission is hereby granted, free of charge, to any person obtaining a copy
6
+of this software and associated documentation files (the "Software"), to deal
7
+in the Software without restriction, including without limitation the rights
8
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+copies of the Software, and to permit persons to whom the Software is
10
+furnished to do so, subject to the following conditions:
11
+
12
+The above copyright notice and this permission notice shall be included in all
13
+copies or substantial portions of the Software.
14
+
15
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+SOFTWARE.

+ 67
- 0
src/deps/imgui/README.md View File

@@ -0,0 +1,67 @@
1
+ImGui
2
+=====
3
+
4
+ImGui is a bloat-free graphical user interface library for C++. It outputs vertex buffers that you can render in your 3D-pipeline enabled application. It is portable, renderer agnostic and carries minimal amount of dependencies (only 3 files are needed). It is based on an "immediate" graphical user interface paradigm which allows you to build simple user interfaces with ease.
5
+
6
+ImGui is designed to enable fast iteration and allow programmers to create "content creation" or "debug" tools (as opposed to tools for the average end-user). It favors simplicity and thus lacks certain features normally found in more high-level libraries, such as string localisation.
7
+
8
+ImGui is particularly suited to integration in 3D applications, fullscreen applications, embedded applications, games, or any applications on consoles platforms where operating system features are non-standard. 
9
+
10
+After ImGui is setup in your engine, you can use it like in this example:
11
+
12
+![screenshot of sample code alongside its output with ImGui](/web/code_sample_01.png?raw=true)
13
+
14
+ImGui outputs vertex buffers and simple command-lists that you can render in your application. Because it doesn't know or touch graphics state directly, you can call ImGui commands anywhere in your code (e.g. in the middle of a running algorithm, or in the middle of your own rendering process). Refer to the sample applications in the examples/ folder for instructions on how to integrate ImGui with your existing codebase. 
15
+
16
+Gallery
17
+-------
18
+
19
+![screenshot 1](/web/test_window_01.png?raw=true)
20
+![screenshot 2](/web/test_window_02.png?raw=true)
21
+![screenshot 3](/web/test_window_03.png?raw=true)
22
+![screenshot 4](/web/test_window_04.png?raw=true)
23
+
24
+References
25
+----------
26
+
27
+The Immediate Mode GUI paradigm may at first appear unusual to some users. This is mainly because "Retained Mode" GUIs have been so widespread and predominant. The following links can give you a better understanding about how Immediate Mode GUIs works. 
28
+- [Johannes 'johno' Norneby's article](http://www.johno.se/book/imgui.html).
29
+- [A presentation by Rickard Gustafsson and Johannes Algelind](http://www.cse.chalmers.se/edu/year/2011/course/TDA361/Advanced%20Computer%20Graphics/IMGUI.pdf).
30
+- [Jari Komppa's tutorial on building an ImGui library](http://iki.fi/sol/imgui/).
31
+- [Casey Muratori's original video that popularized the concept](https://mollyrocket.com/861).
32
+
33
+Frequently Asked Question
34
+-------------------------
35
+<b>How do you use ImGui on a platform that may not have a mouse and keyboard?</b>
36
+
37
+I recommend using [Synergy](http://synergy-project.org) and the uSynergy.c micro client to share your mouse and keyboard. This way you can seemingly use your PC input devices on a video game console or a tablet. ImGui was also designed to function with touch inputs if you increase the padding of widgets to compensate for the lack of precision of touch devices, but it is recommended you use a mouse to allow optimising for screen real-estate.
38
+
39
+<b>I integrated ImGui in my engine and the text or lines are blurry..</b>
40
+
41
+- Try adjusting ImGui::GetIO().PixelCenterOffset to 0.0f or 0.5f.
42
+- In your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f).
43
+
44
+<b>Can you create elaborate/serious tools with ImGui?</b>
45
+
46
+Yes. I have written data browsers, debuggers, profilers and all sort of non-trivial tools with the library. There's no reason you cannot, and in my experience the simplicity of the API is very empowering. However note that ImGui is programmer centric and the immediate-mode GUI paradigm might requires a bit of adaptation before you can realize its full potential. 
47
+
48
+<b>Can you reskin the look of ImGui?</b>
49
+
50
+Yes, you can alter the look of the interface to some degree: changing colors, sizes and padding, font. However, as ImGui is designed and optimised to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface. The example below uses modified settings to create a more compact UI with different colors:
51
+
52
+![skinning screenshot 1](/web/skinning_sample_01.png?raw=true)
53
+
54
+
55
+Credits
56
+-------
57
+
58
+Developed by [Omar Cornut](http://www.miracleworld.net). The library was developed with the support of [Media Molecule](http://www.mediamolecule.com) and first used internally on the game [Tearaway](http://tearaway.mediamolecule.com). 
59
+
60
+Embeds [proggy_clean](http://upperbounds.net) font by Tristan Grimmer (also MIT license).
61
+
62
+Inspiration, feedback, and testing: Casey Muratori, Atman Binstock, Mikko Mononen, Emmanuel Briney, Stefan Kamoda, Anton Mikhailov, Matt Willis. Thanks!
63
+
64
+License
65
+-------
66
+
67
+ImGui is licensed under the MIT License, see LICENSE for more information.

+ 43
- 0
src/deps/imgui/imconfig.h View File

@@ -0,0 +1,43 @@
1
+//-----------------------------------------------------------------------------
2
+// USER IMPLEMENTATION
3
+//-----------------------------------------------------------------------------
4
+
5
+#pragma once
6
+
7
+//---- Define your own malloc/free/realloc functions if you want to override internal memory allocations for ImGui
8
+//#define IM_MALLOC(_SIZE)			MyMalloc(_SIZE)			// void* MyMalloc(size_t size);
9
+//#define IM_FREE(_PTR)				MyFree(_PTR)			// void MyFree(void *ptr);
10
+//#define IM_REALLOC(_PTR, _SIZE)	MyRealloc(_PTR, _SIZE)	// void* MyRealloc(void *ptr, size_t size);
11
+
12
+//---- Define your own ImVector<> type if you don't want to use the provided implementation defined in imgui.h
13
+//#include <vector>
14
+//#define ImVector  std::vector
15
+//#define ImVector  MyVector
16
+
17
+//---- Define assertion handler. Defaults to calling assert().
18
+//#define IM_ASSERT(_EXPR)  MyAssert(_EXPR)
19
+
20
+//---- Don't implement default clipboard handlers for Windows (so as not to link with OpenClipboard(), etc.)
21
+//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS
22
+
23
+//---- Define implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4.
24
+/*
25
+#define IM_VEC2_CLASS_EXTRA                                                 \
26
+        ImVec2(const MyVec2& f) { x = f.x; y = f.y; }                       \
27
+        operator MyVec2() const { return MyVec2(x,y); }
28
+
29
+#define IM_VEC4_CLASS_EXTRA                                                 \
30
+        ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; }     \
31
+        operator MyVec4() const { return MyVec4(x,y,z,w); }
32
+*/
33
+
34
+//---- Freely implement extra functions within the ImGui:: namespace.
35
+//---- e.g. you can create variants of the ImGui::Value() helper for your low-level math types.
36
+/*
37
+namespace ImGui
38
+{
39
+    void    Value(const char* prefix, const MyVec2& v, const char* float_format = NULL);
40
+    void    Value(const char* prefix, const MyVec4& v, const char* float_format = NULL);
41
+};
42
+*/
43
+

+ 6202
- 0
src/deps/imgui/imgui.cpp
File diff suppressed because it is too large
View File


+ 661
- 0
src/deps/imgui/imgui.h View File

@@ -0,0 +1,661 @@
1
+// ImGui library
2
+// See .cpp file for commentary.
3
+// See ImGui::ShowTestWindow() for sample code.
4
+// Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
5
+// Get latest version at https://github.com/ocornut/imgui
6
+
7
+#pragma once
8
+
9
+struct ImDrawList;
10
+struct ImBitmapFont;
11
+struct ImGuiAabb;
12
+struct ImGuiIO;
13
+struct ImGuiStorage;
14
+struct ImGuiStyle;
15
+struct ImGuiWindow;
16
+
17
+#include "imconfig.h"
18
+#include <float.h>          // FLT_MAX
19
+#include <stdarg.h>         // va_list
20
+#include <stdlib.h>         // NULL, malloc
21
+
22
+#ifndef IM_MALLOC
23
+#define IM_MALLOC(_SIZE) malloc((_SIZE))
24
+#endif
25
+
26
+#ifndef IM_FREE
27
+#define IM_FREE(_PTR) free((_PTR))
28
+#endif
29
+
30
+#ifndef IM_REALLOC
31
+#define IM_REALLOC(_PTR, _SIZE) realloc((_PTR), (_SIZE))
32
+#endif
33
+
34
+#ifndef IM_ASSERT
35
+#include <assert.h>
36
+#define IM_ASSERT(_EXPR)    assert(_EXPR)
37
+#endif
38
+
39
+typedef unsigned int ImU32;
40
+typedef ImU32 ImGuiID;
41
+typedef int ImGuiCol;               // enum ImGuiCol_
42
+typedef int ImGuiKey;               // enum ImGuiKey_
43
+typedef int ImGuiColorEditMode;     // enum ImGuiColorEditMode_
44
+typedef int ImGuiWindowFlags;       // enum ImGuiWindowFlags_
45
+typedef int ImGuiInputTextFlags;    // enum ImGuiInputTextFlags_
46
+typedef ImBitmapFont* ImFont;
47
+
48
+struct ImVec2
49
+{
50
+    float x, y;
51
+    ImVec2() {}
52
+    ImVec2(float _x, float _y) { x = _x; y = _y; }
53
+
54
+#ifdef IM_VEC2_CLASS_EXTRA
55
+    IM_VEC2_CLASS_EXTRA
56
+#endif
57
+};
58
+
59
+struct ImVec4
60
+{
61
+    float x, y, z, w;
62
+    ImVec4() {}
63
+    ImVec4(float _x, float _y, float _z, float _w) { x = _x; y = _y; z = _z; w = _w; }
64
+
65
+#ifdef IM_VEC4_CLASS_EXTRA
66
+    IM_VEC4_CLASS_EXTRA
67
+#endif
68
+};
69
+
70
+// std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug). 
71
+// this implementation does NOT call c++ constructors! we don't need them! also only provide the minimum functionalities we need.
72
+#ifndef ImVector
73
+template<typename T>
74
+class ImVector
75
+{
76
+private:
77
+    size_t                      Size;
78
+    size_t                      Capacity;
79
+    T*                          Data;
80
+
81
+public:
82
+    typedef T                   value_type;
83
+    typedef value_type*         iterator;
84
+    typedef const value_type*   const_iterator;
85
+
86
+    ImVector()                  { Size = Capacity = 0; Data = NULL; }
87
+    ~ImVector()                 { if (Data) IM_FREE(Data); }
88
+
89
+    inline bool                 empty() const                   { return Size == 0; }
90
+    inline size_t               size() const                    { return Size; }
91
+    inline size_t               capacity() const                { return Capacity; }
92
+
93
+    inline value_type&          at(size_t i)                    { IM_ASSERT(i < Size); return Data[i]; }
94
+    inline const value_type&    at(size_t i) const              { IM_ASSERT(i < Size); return Data[i]; }
95
+    inline value_type&          operator[](size_t i)            { IM_ASSERT(i < Size); return Data[i]; }
96
+    inline const value_type&    operator[](size_t i) const      { IM_ASSERT(i < Size); return Data[i]; }
97
+
98
+    inline void                 clear()                         { if (Data) { Size = Capacity = 0; IM_FREE(Data); Data = NULL; } }
99
+    inline iterator             begin()                         { return Data; }
100
+    inline const_iterator       begin() const                   { return Data; }
101
+    inline iterator             end()                           { return Data + Size; }
102
+    inline const_iterator       end() const                     { return Data + Size; }
103
+    inline value_type&          front()                         { return at(0); }
104
+    inline const value_type&    front() const                   { return at(0); }
105
+    inline value_type&          back()                          { IM_ASSERT(Size > 0); return at(Size-1); }
106
+    inline const value_type&    back() const                    { IM_ASSERT(Size > 0); return at(Size-1); }
107
+    inline void                 swap(ImVector<T>& rhs)          { const size_t rhs_size = rhs.Size; rhs.Size = Size; Size = rhs_size; const size_t rhs_cap = rhs.Capacity; rhs.Capacity = Capacity; Capacity = rhs_cap; value_type* rhs_data = rhs.Data; rhs.Data = Data; Data = rhs_data; }
108
+
109
+    inline void                 reserve(size_t new_capacity)    { Data = (value_type*)IM_REALLOC(Data, new_capacity * sizeof(value_type)); Capacity = new_capacity; }
110
+    inline void                 resize(size_t new_size)         { if (new_size > Capacity) reserve(new_size); Size = new_size; }
111
+
112
+    inline void                 push_back(const value_type& v)  { if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); Data[Size++] = v; }
113
+    inline void                 pop_back()                      { IM_ASSERT(Size > 0); Size--; }
114
+
115
+    inline iterator             erase(const_iterator it)        { IM_ASSERT(it >= begin() && it < end()); const int off = it - begin(); memmove(Data + off, Data + off + 1, (Size - off - 1) * sizeof(value_type)); Size--; return Data + off; }
116
+    inline void                 insert(const_iterator it, const value_type& v)  { IM_ASSERT(it >= begin() && it <= end()); const int off = it - begin(); if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); if (off < (int)Size) memmove(Data + off + 1, Data + off, (Size - off) * sizeof(value_type)); Data[off] = v; Size++; }
117
+};
118
+#endif // #ifndef ImVector
119
+
120
+// Helpers at bottom of the file:
121
+// - if (IMGUI_ONCE_UPON_A_FRAME)       // Execute a block of code once per frame only
122
+// - struct ImGuiTextFilter             // Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
123
+// - struct ImGuiTextBuffer             // Text buffer for logging/accumulating text
124
+// - struct ImGuiStorage                // Custom key value storage (if you need to alter open/close states manually)
125
+// - struct ImDrawList                  // Draw command list
126
+// - struct ImBitmapFont                // Bitmap font loader
127
+
128
+// ImGui End-user API
129
+// In a namespace so that user can add extra functions (e.g. Value() helpers for your vector or common types)
130
+namespace ImGui
131
+{
132
+    // Main
133
+    ImGuiIO&    GetIO();
134
+    ImGuiStyle& GetStyle();
135
+    void        NewFrame();
136
+    void        Render();
137
+    void        Shutdown();
138
+    void        ShowUserGuide();
139
+    void        ShowStyleEditor(ImGuiStyle* ref = NULL);
140
+    void        ShowTestWindow(bool* open = NULL);
141
+
142
+    // Window
143
+    bool        Begin(const char* name = "Debug", bool* open = NULL, ImVec2 size = ImVec2(0,0), float fill_alpha = -1.0f, ImGuiWindowFlags flags = 0);
144
+    void        End();
145
+    void        BeginChild(const char* str_id, ImVec2 size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0);
146
+    void        EndChild();
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
+    ImVec2      GetWindowSize();
152
+    ImVec2      GetWindowContentRegionMin();
153
+    ImVec2      GetWindowContentRegionMax();
154
+    ImDrawList* GetWindowDrawList();
155
+    void        SetFontScale(float scale);
156
+    void        SetScrollPosHere();
157
+    void        SetTreeStateStorage(ImGuiStorage* tree);
158
+    ImGuiStorage* GetTreeStateStorage();
159
+    void        PushItemWidth(float item_width);
160
+    void        PopItemWidth();
161
+    float       GetItemWidth();
162
+    void        PushAllowKeyboardFocus(bool v);
163
+    void        PopAllowKeyboardFocus();
164
+    void        PushStyleColor(ImGuiCol idx, const ImVec4& col);
165
+    void        PopStyleColor();
166
+
167
+    // Tooltip
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. 
170
+    void        EndTooltip();
171
+
172
+    // Layout
173
+    void        Separator();                                                        // horizontal line
174
+    void        SameLine(int column_x = 0, int spacing_w = -1);                     // call between widgets to layout them horizontally
175
+    void        Spacing();
176
+    void        Columns(int count = 1, const char* id = NULL, bool border=true);    // setup number of columns
177
+    void        NextColumn();                                                       // next column
178
+    float       GetColumnOffset(int column_index = -1);
179
+    void        SetColumnOffset(int column_index, float offset);
180
+    float       GetColumnWidth(int column_index = -1);
181
+    ImVec2      GetCursorPos();                                                     // cursor position relative to window position
182
+    void        SetCursorPos(const ImVec2& pos);                                    // "
183
+    void        SetCursorPosX(float x);                                             // "
184
+    void        SetCursorPosY(float y);                                             // "
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.
187
+    float       GetTextLineSpacing();
188
+    float       GetTextLineHeight();
189
+
190
+    // ID scopes
191
+    void        PushID(const char* str_id);
192
+    void        PushID(const void* ptr_id);
193
+    void        PushID(const int int_id);
194
+    void        PopID();
195
+
196
+    // Widgets
197
+    void        Text(const char* fmt, ...);
198
+    void        TextV(const char* fmt, va_list args);
199
+    void        TextColored(const ImVec4& col, const char* fmt, ...);               // shortcut to doing PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor();
200
+    void        TextUnformatted(const char* text, const char* text_end = NULL);     // doesn't require null terminated string if 'text_end' is specified. no copy done to any bounded stack buffer, better for long chunks of text.
201
+    void        LabelText(const char* label, const char* fmt, ...);
202
+    void        BulletText(const char* fmt, ...);
203
+    bool        Button(const char* label, ImVec2 size = ImVec2(0,0), bool repeat_when_held = false);
204
+    bool        SmallButton(const char* label);
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);
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
+    bool        SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
209
+    bool        SliderFloat4(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
210
+    bool        SliderAngle(const char* label, float* v, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f);     // *v in radians
211
+    bool        SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f");
212
+    void        PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float));
213
+    void        PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float));
214
+    bool        Checkbox(const char* label, bool* v);
215
+    bool        CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value);
216
+    bool        RadioButton(const char* label, bool active);
217
+    bool        RadioButton(const char* label, int* v, int v_button);
218
+    bool        InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, int decimal_precision = -1);
219
+    bool        InputFloat2(const char* label, float v[2], int decimal_precision = -1);
220
+    bool        InputFloat3(const char* label, float v[3], int decimal_precision = -1);
221
+    bool        InputFloat4(const char* label, float v[4], int decimal_precision = -1);
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);
224
+    bool        Combo(const char* label, int* current_item, const char** items, int items_count, int popup_height_items = 7);
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
+    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);
227
+    bool        ColorButton(const ImVec4& col, bool small_height = false, bool outline_border = true);
228
+    bool        ColorEdit3(const char* label, float col[3]);
229
+    bool        ColorEdit4(const char* label, float col[4], bool show_alpha = true);
230
+    void        ColorEditMode(ImGuiColorEditMode mode);
231
+    bool        TreeNode(const char* str_label_id);                                 // if returning 'true' the user is responsible for calling TreePop
232
+    bool        TreeNode(const char* str_id, const char* fmt, ...);                 // "
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
235
+    void        TreePush(const void* ptr_id = NULL);                                // "
236
+    void        TreePop();
237
+    void        OpenNextNode(bool open);                                            // force open/close the next TreeNode or CollapsingHeader
238
+
239
+    // Value helper output "name: value"
240
+    // Freely declare your own in the ImGui namespace.
241
+    void        Value(const char* prefix, bool b);
242
+    void        Value(const char* prefix, int v);
243
+    void        Value(const char* prefix, unsigned int v);
244
+    void        Value(const char* prefix, float v, const char* float_format = NULL);
245
+    void        Color(const char* prefix, const ImVec4& v);
246
+    void        Color(const char* prefix, unsigned int v);
247
+
248
+    // Logging
249
+    void        LogButtons();
250
+    void        LogToTTY(int max_depth = -1);
251
+    void        LogToFile(int max_depth = -1, const char* filename = NULL);
252
+    void        LogToClipboard(int max_depth = -1);
253
+
254
+    // Utilities
255
+    void        SetNewWindowDefaultPos(const ImVec2& pos);                          // set position of window that do
256
+    bool        IsHovered();                                                        // was the last item active area hovered by mouse?
257
+    ImVec2      GetItemBoxMin();                                                    // get bounding box of last item
258
+    ImVec2      GetItemBoxMax();                                                    // get bounding box of last item
259
+    bool        IsClipped(const ImVec2& item_size);                                 // to perform coarse clipping on user's side (as an optimisation)
260
+    bool        IsKeyPressed(int key_index, bool repeat = true);                    // key_index into the keys_down[512] array, imgui doesn't know the semantic of each entry
261
+    bool        IsMouseClicked(int button, bool repeat = false);
262
+    bool        IsMouseDoubleClicked(int button);
263
+    bool        IsMouseHoveringBox(const ImVec2& box_min, const ImVec2& box_max);
264
+    ImVec2      GetMousePos();
265
+    float       GetTime();
266
+    int         GetFrameCount();
267
+    const char* GetStyleColorName(ImGuiCol idx);
268
+    void        GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size);
269
+    ImVec2      CalcTextSize(const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true);
270
+
271
+}; // namespace ImGui
272
+
273
+// Flags for ImGui::Begin()
274
+enum ImGuiWindowFlags_
275
+{
276
+    // Default: 0
277
+    ImGuiWindowFlags_ShowBorders            = 1 << 0,
278
+    ImGuiWindowFlags_NoTitleBar             = 1 << 1,
279
+    ImGuiWindowFlags_NoResize               = 1 << 2,
280
+    ImGuiWindowFlags_NoMove                 = 1 << 3,
281
+    ImGuiWindowFlags_NoScrollbar            = 1 << 4,
282
+    ImGuiWindowFlags_ChildWindow            = 1 << 5,   // For internal use by BeginChild()
283
+    ImGuiWindowFlags_ChildWindowAutoFitX    = 1 << 6,   // For internal use by BeginChild()
284
+    ImGuiWindowFlags_ChildWindowAutoFitY    = 1 << 7,   // For internal use by BeginChild()
285
+    ImGuiWindowFlags_ComboBox               = 1 << 8,   // For internal use by ComboBox()
286
+    ImGuiWindowFlags_Tooltip                = 1 << 9,   // For internal use by Render() when using Tooltip
287
+};
288
+
289
+// Flags for ImGui::InputText()
290
+enum ImGuiInputTextFlags_
291
+{
292
+    // Default: 0
293
+    ImGuiInputTextFlags_CharsDecimal        = 1 << 0,
294
+    ImGuiInputTextFlags_CharsHexadecimal    = 1 << 1,
295
+    ImGuiInputTextFlags_AutoSelectAll       = 1 << 2,
296
+    ImGuiInputTextFlags_AlignCenter         = 1 << 3,
297
+};
298
+
299
+// User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array
300
+enum ImGuiKey_
301
+{
302
+    ImGuiKey_Tab,
303
+    ImGuiKey_LeftArrow,
304
+    ImGuiKey_RightArrow,
305
+    ImGuiKey_UpArrow,
306
+    ImGuiKey_DownArrow,
307
+    ImGuiKey_Home,
308
+    ImGuiKey_End,
309
+    ImGuiKey_Delete,
310
+    ImGuiKey_Backspace,
311
+    ImGuiKey_Enter,
312
+    ImGuiKey_Escape,
313
+    ImGuiKey_A,         // for CTRL+A: select all
314
+    ImGuiKey_C,         // for CTRL+C: copy
315
+    ImGuiKey_V,         // for CTRL+V: paste
316
+    ImGuiKey_X,         // for CTRL+X: cut
317
+    ImGuiKey_Y,         // for CTRL+Y: redo
318
+    ImGuiKey_Z,         // for CTRL+Z: undo
319
+    ImGuiKey_COUNT,
320
+};
321
+
322
+enum ImGuiCol_
323
+{
324
+    ImGuiCol_Text,
325
+    ImGuiCol_WindowBg,
326
+    ImGuiCol_Border,
327
+    ImGuiCol_BorderShadow,
328
+    ImGuiCol_FrameBg,               // Background of checkbox, radio button, plot, slider, text input
329
+    ImGuiCol_TitleBg,
330
+    ImGuiCol_TitleBgCollapsed,
331
+    ImGuiCol_ScrollbarBg,
332
+    ImGuiCol_ScrollbarGrab,
333
+    ImGuiCol_ScrollbarGrabHovered,
334
+    ImGuiCol_ScrollbarGrabActive,
335
+    ImGuiCol_ComboBg,
336
+    ImGuiCol_CheckHovered,
337
+    ImGuiCol_CheckActive,
338
+    ImGuiCol_SliderGrab,
339
+    ImGuiCol_SliderGrabActive,
340
+    ImGuiCol_Button,
341
+    ImGuiCol_ButtonHovered,
342
+    ImGuiCol_ButtonActive,
343
+    ImGuiCol_Header,
344
+    ImGuiCol_HeaderHovered,
345
+    ImGuiCol_HeaderActive,
346
+    ImGuiCol_Column,
347
+    ImGuiCol_ColumnHovered,
348
+    ImGuiCol_ColumnActive,
349
+    ImGuiCol_ResizeGrip,
350
+    ImGuiCol_ResizeGripHovered,
351
+    ImGuiCol_ResizeGripActive,
352
+    ImGuiCol_CloseButton,
353
+    ImGuiCol_CloseButtonHovered,
354
+    ImGuiCol_CloseButtonActive,
355
+    ImGuiCol_PlotLines,
356
+    ImGuiCol_PlotLinesHovered,
357
+    ImGuiCol_PlotHistogram,
358
+    ImGuiCol_PlotHistogramHovered,
359
+    ImGuiCol_TextSelectedBg,
360
+    ImGuiCol_TooltipBg,
361
+    ImGuiCol_COUNT,
362
+};
363
+
364
+enum ImGuiColorEditMode_
365
+{
366
+    ImGuiColorEditMode_UserSelect = -1,
367
+    ImGuiColorEditMode_RGB = 0,
368
+    ImGuiColorEditMode_HSV = 1,
369
+    ImGuiColorEditMode_HEX = 2,
370
+};
371
+
372
+struct ImGuiStyle
373
+{
374
+    float       Alpha;                      // Global alpha applies to everything in ImGui
375
+    ImVec2      WindowPadding;              // Padding within a window
376
+    ImVec2      WindowMinSize;              // Minimum window size
377
+    ImVec2      FramePadding;               // Padding within a framed rectangle (used by most widgets)
378
+    ImVec2      ItemSpacing;                // Horizontal and vertical spacing between widgets/lines
379
+    ImVec2      ItemInnerSpacing;           // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
380
+    ImVec2      TouchExtraPadding;          // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much!
381
+    ImVec2      AutoFitPadding;             // Extra space after auto-fit (double-clicking on resize grip)
382
+    float       WindowFillAlphaDefault;     // Default alpha of window background, if not specified in ImGui::Begin()
383
+    float       WindowRounding;             // Radius of window corners rounding. Set to 0.0f to have rectangular windows
384
+    float       TreeNodeSpacing;            // Horizontal spacing when entering a tree node
385
+    float       ColumnsMinSpacing;          // Minimum horizontal spacing between two columns
386
+    float       ScrollBarWidth;             // Width of the vertical scroll bar
387
+    ImVec4      Colors[ImGuiCol_COUNT];
388
+
389
+    ImGuiStyle();
390
+};
391
+
392
+// This is where your app communicate with ImGui. Call ImGui::GetIO() to access.
393
+// Read 'Programmer guide' section in .cpp file for general usage.
394
+struct ImGuiIO
395
+{
396
+    // Settings (fill once)                 // Default value:
397
+    ImVec2      DisplaySize;                // <unset>                  // Display size, in pixels. For clamping windows positions.
398
+    float       DeltaTime;                  // = 1.0f/60.0f             // Time elapsed since last frame, in seconds.
399
+    float       IniSavingRate;              // = 5.0f                   // Maximum time between saving .ini file, in seconds. Set to a negative value to disable .ini saving.
400
+    const char* IniFilename;                // = "imgui.ini"            // Absolute path to .ini file.
401
+    const char* LogFilename;                // = "imgui_log.txt"        // Absolute path to .log file.
402
+    float       MouseDoubleClickTime;       // = 0.30f                  // Time for a double-click, in seconds.
403
+    float       MouseDoubleClickMaxDist;    // = 6.0f                   // Distance threshold to stay in to validate a double-click, in pixels.
404
+    int         KeyMap[ImGuiKey_COUNT];     // <unset>                  // Map of indices into the KeysDown[512] entries array
405
+    ImFont      Font;                       // <auto>                   // Gets passed to text functions. Typedef ImFont to the type you want (ImBitmapFont* or your own font).
406
+	float		FontYOffset;				// = 0.0f					// Offset font rendering by xx pixels in Y axis.
407
+    ImVec2      FontTexUvForWhite;          // = (0.0f,0.0f)            // Font texture must have a white pixel at this UV coordinate. Adjust if you are using custom texture.
408
+    bool        FontAllowScaling;           // = false                  // Set to allow scaling text with CTRL+Wheel.
409
+    float       PixelCenterOffset;          // = 0.0f                   // Try to set to 0.5f or 0.375f if rendering is blurry
410
+
411
+    // Settings - Rendering function (REQUIRED)
412
+    // See example code if you are unsure of how to implement this.
413
+    void        (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count);
414
+
415
+    // Settings - Clipboard Support
416
+    // Override to provide your clipboard handlers.
417
+    // On Windows architecture, defaults to use the native Win32 clipboard, otherwise default to use a ImGui private clipboard. 
418
+    // NB- for SetClipboardTextFn, the string is *NOT* zero-terminated at 'text_end'
419
+    const char* (*GetClipboardTextFn)();                                        
420
+    void        (*SetClipboardTextFn)(const char* text, const char* text_end);
421
+
422
+    // Input - Fill before calling NewFrame()
423
+    ImVec2      MousePos;                   // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
424
+    bool        MouseDown[5];               // Mouse buttons. ImGui itself only uses button 0 (left button) but you can use others as storage for convenience.
425
+    int         MouseWheel;                 // Mouse wheel: -1,0,+1
426
+    bool        KeyCtrl;                    // Keyboard modifier pressed: Control
427
+    bool        KeyShift;                   // Keyboard modifier pressed: Shift
428
+    bool        KeysDown[512];              // Keyboard keys that are pressed (in whatever order user naturally has access to keyboard data)
429
+    char        InputCharacters[16];        // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper.
430
+
431
+    // Output - Retrieve after calling NewFrame(), you can use them to discard inputs or hide them from the rest of your application
432
+    bool        WantCaptureMouse;           // ImGui is using your mouse input (= window is being hovered or widget is active).
433
+    bool        WantCaptureKeyboard;        // imGui is using your keyboard input (= widget is active).
434
+
435
+    // Function
436
+    void        AddInputCharacter(char c);  // Helper to add a new character into InputCharacters[]
437
+
438
+    // [Internal] ImGui will maintain those fields for you
439
+    ImVec2      MousePosPrev;
440
+    ImVec2      MouseDelta;
441
+    bool        MouseClicked[5];
442
+    ImVec2      MouseClickedPos[5];
443
+    float       MouseClickedTime[5];
444
+    bool        MouseDoubleClicked[5];
445
+    float       MouseDownTime[5];
446
+    float       KeysDownTime[512];
447
+
448
+    ImGuiIO();
449
+};
450
+
451
+//-----------------------------------------------------------------------------
452
+// Helpers
453
+//-----------------------------------------------------------------------------
454
+
455
+// Helper: execute a block of code once a frame only
456
+// Usage: if (IMGUI_ONCE_UPON_A_FRAME) {/*do something once a frame*/)
457
+#define IMGUI_ONCE_UPON_A_FRAME         static ImGuiOncePerFrame im = ImGuiOncePerFrame()
458
+struct ImGuiOncePerFrame
459
+{
460
+    ImGuiOncePerFrame() : LastFrame(-1) {}
461
+    operator bool() const { return TryIsNewFrame(); }
462
+private:
463
+    mutable int LastFrame;
464
+    bool        TryIsNewFrame() const   { const int current_frame = ImGui::GetFrameCount(); if (LastFrame == current_frame) return false; LastFrame = current_frame; return true; }
465
+};
466
+
467
+// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
468
+struct ImGuiTextFilter
469
+{
470
+    struct TextRange 
471
+    { 
472
+        const char* b; 
473
+        const char* e;
474
+
475
+        TextRange() { b = e = NULL; }
476
+        TextRange(const char* _b, const char* _e) { b = _b; e = _e; }
477
+        const char* begin() const { return b; }
478
+        const char* end() const { return e; }
479
+        bool empty() const { return b == e; }
480
+        char front() const { return *b; }
481
+        static bool isblank(char c) { return c == ' ' || c == '\t'; } 
482
+        void trim_blanks() { while (b < e && isblank(*b)) b++; while (e > b && isblank(*(e-1))) e--; }
483
+        void split(char separator, ImVector<TextRange>& out);
484
+    };
485
+
486
+    char                InputBuf[256];
487
+    ImVector<TextRange> Filters;
488
+    int                 CountGrep;
489
+
490
+    ImGuiTextFilter();
491
+    void Clear() { InputBuf[0] = 0; Build(); }
492
+    void Draw(const char* label = "Filter (inc,-exc)", float width = -1.0f);    // Helper calling InputText+Build
493
+    bool PassFilter(const char* val) const;
494
+    bool IsActive() const { return !Filters.empty(); }
495
+    void Build();
496
+};
497
+
498
+// Helper: Text buffer for logging/accumulating text
499
+struct ImGuiTextBuffer
500
+{
501
+    ImVector<char>      Buf;
502
+
503
+    ImGuiTextBuffer()   { Buf.push_back(0); }
504
+    const char*         begin() const { return Buf.begin(); }
505
+    const char*         end() const { return Buf.end()-1; }
506
+    size_t              size() const { return Buf.size()-1; }
507
+    bool                empty() { return Buf.empty(); }
508
+    void                clear() { Buf.clear(); Buf.push_back(0); }
509
+    void                append(const char* fmt, ...);
510
+};
511
+
512
+// Helper: Key->value storage
513
+// - Store collapse state for a tree
514
+// - Store color edit options, etc.
515
+// Typically you don't have to worry about this since a storage is held within each Window.
516
+// Declare your own storage if you want to manipulate the open/close state of a particular sub-tree in your interface.
517
+struct ImGuiStorage
518
+{
519
+    struct Pair { ImU32 key; int val; };
520
+    ImVector<Pair>  Data;
521
+
522
+    void    Clear();
523
+    int     GetInt(ImU32 key, int default_val = 0);
524
+    void    SetInt(ImU32 key, int val);
525
+    void    SetAllInt(int val);
526
+
527
+    int*    Find(ImU32 key);
528
+    void    Insert(ImU32 key, int val);
529
+};
530
+
531
+//-----------------------------------------------------------------------------
532
+// Draw List
533
+// Hold a series of drawing commands. The user provide a renderer for ImDrawList
534
+//-----------------------------------------------------------------------------
535
+
536
+struct ImDrawCmd
537
+{
538
+    unsigned int    vtx_count;
539
+    ImVec4          clip_rect;
540
+};
541
+
542
+// sizeof() == 20
543
+struct ImDrawVert
544
+{
545
+    ImVec2  pos;
546
+    ImVec2  uv;
547
+    ImU32   col;
548
+};
549
+
550
+// Draw command list
551
+// User is responsible for providing a renderer for this in ImGuiIO::RenderDrawListFn
552
+struct ImDrawList
553
+{
554
+    // This is what you have to render
555
+    ImVector<ImDrawCmd>     commands;           // commands
556
+    ImVector<ImDrawVert>    vtx_buffer;         // each command consume ImDrawCmd::vtx_count of those
557
+
558
+    // [Internal to ImGui]
559
+    ImVector<ImVec4>        clip_rect_stack;    // [internal] clip rect stack while building the command-list (so text command can perform clipping early on)
560
+    ImDrawVert*             vtx_write;          // [internal] point within vtx_buffer after each add command (to avoid using the ImVector<> operators too much)
561
+
562
+    ImDrawList() { Clear(); }
563
+
564
+    void Clear();
565
+    void PushClipRect(const ImVec4& clip_rect);
566
+    void PopClipRect();
567
+    void ReserveVertices(unsigned int vtx_count);
568
+    void AddVtx(const ImVec2& pos, ImU32 col);
569
+    void AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col);
570
+
571
+    // Primitives
572
+    void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col);
573
+    void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F);
574
+    void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F);
575
+    void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col);
576
+    void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12);
577
+    void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12);
578
+    void AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris=false, const ImVec2& third_point_offset = ImVec2(0,0));
579
+    void AddText(ImFont font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end);
580
+};
581
+
582
+// Optional bitmap font data loader & renderer into vertices
583
+//  #define ImFont to ImBitmapFont to use
584
+// Using the .fnt format exported by BMFont
585
+//  - tool: http://www.angelcode.com/products/bmfont
586
+//  - file-format: http://www.angelcode.com/products/bmfont/doc/file_format.html
587
+// Assume valid file data (won't handle invalid/malicious data)
588
+// Handle a subset of parameters.
589
+//  - kerning pair are not supported (because ImGui code does per-character CalcTextSize calls, need to turn it into something more stateful to allow kerning)
590
+struct ImBitmapFont
591
+{
592
+#pragma pack(push, 1)
593
+    struct FntInfo
594
+    {
595
+        signed short    FontSize;
596
+        unsigned char   BitField;       // bit 0: smooth, bit 1: unicode, bit 2: italic, bit 3: bold, bit 4: fixedHeight, bits 5-7: reserved
597
+        unsigned char   CharSet;
598
+        unsigned short  StretchH;
599
+        unsigned char   AA;
600
+        unsigned char   PaddingUp, PaddingRight, PaddingDown, PaddingLeft;
601
+        unsigned char   SpacingHoriz, SpacingVert;
602
+        unsigned char   Outline;
603
+        //char          FontName[];
604
+    };
605
+
606
+    struct FntCommon
607
+    {
608
+        unsigned short  LineHeight;
609
+        unsigned short  Base;
610
+        unsigned short  ScaleW, ScaleH;
611
+        unsigned short  Pages;
612
+        unsigned char   BitField;
613
+        unsigned char   Channels[4];
614
+    };
615
+
616
+    struct FntGlyph
617
+    {
618
+        unsigned int    Id;
619
+        unsigned short  X, Y;
620
+        unsigned short  Width, Height;
621
+        signed short    XOffset, YOffset;
622
+        signed short    XAdvance;
623
+        unsigned char   Page;
624
+        unsigned char   Channel;
625
+    };
626
+
627
+    struct FntKerning
628
+    {
629
+        unsigned int    IdFirst;
630
+        unsigned int    IdSecond;
631
+        signed short    Amount;
632
+    };
633
+#pragma pack(pop)
634
+
635
+    unsigned char*          Data;               // Raw data, content of .fnt file
636
+    size_t                  DataSize;           //
637
+    bool                    DataOwned;          // 
638
+    const FntInfo*          Info;               // (point into raw data)
639
+    const FntCommon*        Common;             // (point into raw data)
640
+    const FntGlyph*         Glyphs;             // (point into raw data)
641
+    size_t                  GlyphsCount;        //
642
+    const FntKerning*       Kerning;            // (point into raw data)
643
+    size_t                  KerningCount;       //
644
+    int                     TabCount;           // FIXME: mishandled (add fixed amount instead of aligning to column)
645
+    ImVector<const char*>   Filenames;          // (point into raw data)
646
+    ImVector<int>           IndexLookup;        // (built)
647
+
648
+    ImBitmapFont();
649
+    ~ImBitmapFont() { Clear(); }
650
+
651
+    bool                    LoadFromMemory(const void* data, size_t data_size);
652
+    bool                    LoadFromFile(const char* filename);
653
+    void                    Clear();
654
+    void                    BuildLookupTable();
655
+    const FntGlyph *        FindGlyph(unsigned short c) const;
656
+    float                   GetFontSize() const { return (float)Info->FontSize; }
657
+	bool					IsLoaded() const { return Info != NULL && Common != NULL && Glyphs != NULL; }
658
+
659
+    ImVec2                  CalcTextSize(float size, float max_width, const char* text_begin, const char* text_end, const char** remaining = NULL) const;
660
+    void                    RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices) const;
661
+};

+ 4671
- 0
src/deps/imgui/stb_image.h
File diff suppressed because it is too large
View File


+ 1254
- 0
src/deps/imgui/stb_textedit.h
File diff suppressed because it is too large
View File


Loading…
Cancel
Save