Преглед изворни кода

Updated imgui, added consoleAction.

Thomas Buck пре 10 година
родитељ
комит
abb4445957
11 измењених фајлова са 642 додато и 362 уклоњено
  1. 3
    0
      ChangeLog.md
  2. 1
    0
      data/OpenRaider.ini
  3. 5
    2
      include/Console.h
  4. 3
    3
      include/UI.h
  5. 1
    0
      include/global.h
  6. 7
    3
      src/Console.cpp
  7. 1
    0
      src/RunTime.cpp
  8. 25
    28
      src/UI.cpp
  9. 2
    0
      src/commands/CommandBind.cpp
  10. 572
    312
      src/deps/imgui/imgui.cpp
  11. 22
    14
      src/deps/imgui/imgui.h

+ 3
- 0
ChangeLog.md Прегледај датотеку

@@ -5,6 +5,9 @@
5 5
     [ 20140107 ]
6 6
     * Fixed problems with FontTTFs Glyph Baseline
7 7
     * No longer using wrong assert() when glm is included
8
+    * Updated imgui, now Version 1.20
9
+    * Every imgui window is displayed separately and with close button
10
+    * Added consoleAction, defaulting to backquoteKey
8 11
 
9 12
     [ 20150106 ]
10 13
     * Removed SDL2-TTF Font implementation

+ 1
- 0
data/OpenRaider.ini Прегледај датотеку

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

+ 5
- 2
include/Console.h Прегледај датотеку

@@ -17,13 +17,16 @@ class Console {
17 17
   public:
18 18
     static void display();
19 19
 
20
+    static bool isVisible() { return visible; }
21
+    static void setVisible(bool v) { visible = v; }
22
+
20 23
   private:
21 24
     static void callback(ImGuiTextEditCallbackData* data);
22 25
 
23 26
     const static int bufferLength = 256;
27
+
28
+    static bool visible;
24 29
     static char buffer[bufferLength + 1];
25
-    static bool scrollToBottom;
26
-    static bool focusInput;
27 30
     static unsigned long lastLogLength;
28 31
     static std::vector<std::string> lastCommands;
29 32
     static long lastCommandIndex;

+ 3
- 3
include/UI.h Прегледај датотеку

@@ -17,7 +17,7 @@
17 17
 
18 18
 #include "system/Shader.h"
19 19
 
20
-class ImDrawList;
20
+struct ImDrawList;
21 21
 
22 22
 class UI {
23 23
   public:
@@ -27,8 +27,8 @@ class UI {
27 27
     static void shutdown();
28 28
     static void setSize(glm::i32vec2 s);
29 29
 
30
-    static void setVisible(bool v);
31
-    static bool isVisible();
30
+    static void setVisible(bool v) { visible = v; }
31
+    static bool isVisible() { return visible; }
32 32
 
33 33
     static void handleKeyboard(KeyboardButton key, bool pressed);
34 34
     static void handleText(char* text, bool notFinished);

+ 1
- 0
include/global.h Прегледај датотеку

@@ -27,6 +27,7 @@ const unsigned char CYAN[]   = {   0, 255, 255, 255 };
27 27
 typedef enum {
28 28
     menuAction = 0,
29 29
     debugAction,
30
+    consoleAction,
30 31
 
31 32
     forwardAction,
32 33
     backwardAction,

+ 7
- 3
src/Console.cpp Прегледај датотеку

@@ -15,9 +15,8 @@
15 15
 #include "commands/Command.h"
16 16
 #include "Console.h"
17 17
 
18
+bool Console::visible = false;
18 19
 char Console::buffer[bufferLength + 1] = "";
19
-bool Console::scrollToBottom = false;
20
-bool Console::focusInput = false;
21 20
 unsigned long Console::lastLogLength = 0;
22 21
 std::vector<std::string> Console::lastCommands;
23 22
 long Console::lastCommandIndex = -1;
@@ -71,7 +70,11 @@ void Console::callback(ImGuiTextEditCallbackData* data) {
71 70
 }
72 71
 
73 72
 void Console::display() {
74
-    if (ImGui::Begin("Console", nullptr, ImVec2(600, 400))) {
73
+    if (!visible)
74
+        return;
75
+
76
+    static bool scrollToBottom = false;
77
+    if (ImGui::Begin("Console", &visible, ImVec2(600, 400))) {
75 78
         if (lastLogLength != getLog().size()) {
76 79
             lastLogLength = getLog().size();
77 80
             scrollToBottom = true;
@@ -87,6 +90,7 @@ void Console::display() {
87 90
         }
88 91
         ImGui::EndChild();
89 92
 
93
+        bool focusInput = false;
90 94
         if (ImGui::InputText("Command", buffer, bufferLength,
91 95
                              ImGuiInputTextFlags_EnterReturnsTrue
92 96
                              | ImGuiInputTextFlags_CallbackCompletion

+ 1
- 0
src/RunTime.cpp Прегледај датотеку

@@ -48,6 +48,7 @@ void RunTime::initialize() {
48 48
     // Default key bindings
49 49
     keyBindings[menuAction] = escapeKey;
50 50
     keyBindings[debugAction] = qKey;
51
+    keyBindings[consoleAction] = backquoteKey;
51 52
     keyBindings[forwardAction] = wKey;
52 53
     keyBindings[backwardAction] = sKey;
53 54
     keyBindings[leftAction] = aKey;

+ 25
- 28
src/UI.cpp Прегледај датотеку

@@ -113,7 +113,7 @@ void UI::eventsFinished() {
113 113
 
114 114
     ImGui::NewFrame();
115 115
 
116
-    if (!visible) {
116
+    if (!(visible || Console::isVisible())) {
117 117
         while (!clickEvents.empty()) {
118 118
             auto i = clickEvents.front();
119 119
             if (getMenu().isVisible()) {
@@ -144,7 +144,7 @@ void UI::eventsFinished() {
144 144
     while (!keyboardEvents.empty()) {
145 145
         auto i = keyboardEvents.front();
146 146
 
147
-        if (!visible) {
147
+        if (!(visible || Console::isVisible())) {
148 148
             if (getMenu().isVisible()) {
149 149
                 getMenu().handleKeyboard(std::get<0>(i), std::get<1>(i));
150 150
             } else {
@@ -156,16 +156,21 @@ void UI::eventsFinished() {
156 156
         }
157 157
 
158 158
         if (std::get<1>(i)) {
159
-            if (!visible) {
159
+            if (!(visible || Console::isVisible())) {
160 160
                 if (RunTime::getKeyBinding(menuAction) == std::get<0>(i)) {
161 161
                     getMenu().setVisible(!getMenu().isVisible());
162 162
                 }
163 163
             }
164 164
 
165
-            if ((!io.WantCaptureKeyboard) || (!visible)) {
166
-                if (RunTime::getKeyBinding(debugAction) == std::get<0>(i)) {
167
-                    if (!metaKeyIsActive)
165
+            if ((!io.WantCaptureKeyboard) || (!(visible || Console::isVisible()))) {
166
+                if (!metaKeyIsActive) {
167
+                    if (RunTime::getKeyBinding(debugAction) == std::get<0>(i)) {
168 168
                         visible = !visible;
169
+                    }
170
+
171
+                    if (RunTime::getKeyBinding(consoleAction) == std::get<0>(i)) {
172
+                        Console::setVisible(!Console::isVisible());
173
+                    }
169 174
                 }
170 175
             }
171 176
         }
@@ -174,24 +179,22 @@ void UI::eventsFinished() {
174 179
     }
175 180
 
176 181
     bool clicked = !clickEvents.empty();
177
-    // Only already empty when !visible
178
-    if (visible) {
179
-        clickEvents.clear();
180
-        motionEvents.clear();
181
-        scrollEvents.clear();
182
-    }
182
+    clickEvents.clear();
183
+    motionEvents.clear();
184
+    scrollEvents.clear();
183 185
 
184
-    if (visible && (
186
+    if ((visible || Console::isVisible()) && (
185 187
             ((!io.WantCaptureKeyboard) && io.KeysDown[escapeKey])
186 188
             || ((!io.WantCaptureMouse) && clicked)
187 189
         )) {
188 190
         visible = false;
191
+        Console::setVisible(false);
189 192
     }
190 193
 
191
-    if (Window::getTextInput() != visible)
192
-        Window::setTextInput(visible);
194
+    if (Window::getTextInput() != (visible || Console::isVisible()))
195
+        Window::setTextInput(visible || Console::isVisible());
193 196
 
194
-    bool input = !(visible || getMenu().isVisible());
197
+    bool input = !(visible || Console::isVisible() || getMenu().isVisible());
195 198
     if (Window::getMousegrab() != input)
196 199
         Window::setMousegrab(input);
197 200
 
@@ -199,13 +202,15 @@ void UI::eventsFinished() {
199 202
 }
200 203
 
201 204
 void UI::display() {
202
-    if (!visible)
203
-        return;
204
-
205 205
     Console::display();
206 206
 
207
+    if (!visible) {
208
+        ImGui::Render();
209
+        return;
210
+    }
211
+
207 212
     static bool showTestWindow = false;
208
-    if (ImGui::Begin("Engine", nullptr, ImVec2(400, 400))) {
213
+    if (ImGui::Begin("Engine", &visible, ImVec2(400, 400))) {
209 214
         Render::displayUI();
210 215
         RunTime::display();
211 216
         SoundManager::display();
@@ -514,14 +519,6 @@ void UI::handleControllerButton(KeyboardButton button, bool released) {
514 519
     getGame().handleControllerButton(button, released);
515 520
 }
516 521
 
517
-void UI::setVisible(bool v) {
518
-    visible = v;
519
-}
520
-
521
-bool UI::isVisible() {
522
-    return visible;
523
-}
524
-
525 522
 void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
526 523
     if (cmd_lists_count == 0)
527 524
         return;

+ 2
- 0
src/commands/CommandBind.cpp Прегледај датотеку

@@ -66,6 +66,8 @@ ActionEvents CommandBind::stringToActionEvent(std::string action) {
66 66
         return menuAction;
67 67
     } else if (action == "debug") {
68 68
         return debugAction;
69
+    } else if (action == "console") {
70
+        return consoleAction;
69 71
     } else if (action == "forward") {
70 72
         return forwardAction;
71 73
     } else if (action == "backward") {

+ 572
- 312
src/deps/imgui/imgui.cpp
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 22
- 14
src/deps/imgui/imgui.h Прегледај датотеку

@@ -1,4 +1,4 @@
1
-// ImGui library v1.19 wip
1
+// ImGui library v1.20
2 2
 // See .cpp file for commentary.
3 3
 // See ImGui::ShowTestWindow() for sample code.
4 4
 // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
@@ -19,6 +19,7 @@ struct ImGuiWindow;
19 19
 #include <stdarg.h>         // va_list
20 20
 #include <stddef.h>         // ptrdiff_t
21 21
 #include <stdlib.h>         // NULL, malloc
22
+#include <string.h>         // memset, memmove
22 23
 
23 24
 #ifndef IM_ASSERT
24 25
 #include <assert.h>
@@ -170,8 +171,8 @@ namespace ImGui
170 171
 
171 172
     IMGUI_API void          SetScrollPosHere();                                                 // adjust scrolling position to center into the current cursor position.
172 173
     IMGUI_API void          SetKeyboardFocusHere(int offset = 0);                               // focus keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget.
173
-    IMGUI_API void          SetTreeStateStorage(ImGuiStorage* tree);                            // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it).
174
-    IMGUI_API ImGuiStorage* GetTreeStateStorage();
174
+    IMGUI_API void          SetStateStorage(ImGuiStorage* tree);                                // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it).
175
+    IMGUI_API ImGuiStorage* GetStateStorage();
175 176
 
176 177
     IMGUI_API void          PushItemWidth(float item_width);                                    // width of items for the common item+label case. default to ~2/3 of windows width.
177 178
     IMGUI_API void          PopItemWidth();
@@ -212,6 +213,7 @@ namespace ImGui
212 213
 
213 214
     // ID scopes
214 215
     // If you are creating repeated widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them.
216
+    // You can also use ## within your widget name to distinguish them from each others (see 'Programmer Guide')
215 217
     IMGUI_API void          PushID(const char* str_id);                                         // push identifier into the ID stack. IDs are hash of the *entire* stack!
216 218
     IMGUI_API void          PushID(const void* ptr_id);
217 219
     IMGUI_API void          PushID(const int int_id);
@@ -240,6 +242,9 @@ namespace ImGui
240 242
     IMGUI_API bool          SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
241 243
     IMGUI_API bool          SliderAngle(const char* label, float* v, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f);     // *v in radians
242 244
     IMGUI_API bool          SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f");
245
+    IMGUI_API bool          SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* display_format = "%.0f");
246
+    IMGUI_API bool          SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* display_format = "%.0f");
247
+    IMGUI_API bool          SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* display_format = "%.0f");
243 248
     IMGUI_API 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));
244 249
     IMGUI_API void          PlotLines(const char* label, float (*values_getter)(void* data, int idx), void* data, 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));
245 250
     IMGUI_API 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));
@@ -271,7 +276,7 @@ namespace ImGui
271 276
     IMGUI_API void          TreePop();
272 277
     IMGUI_API void          OpenNextNode(bool open);                                            // force open/close the next TreeNode or CollapsingHeader
273 278
 
274
-    // Value helper output "name: value". tip: freely declare your own within the ImGui namespace!
279
+    // Value() Helpers: output single value in "name: value" format. Tip: freely declare your own within the ImGui namespace!
275 280
     IMGUI_API void          Value(const char* prefix, bool b);
276 281
     IMGUI_API void          Value(const char* prefix, int v);
277 282
     IMGUI_API void          Value(const char* prefix, unsigned int v);
@@ -279,11 +284,13 @@ namespace ImGui
279 284
     IMGUI_API void          Color(const char* prefix, const ImVec4& v);
280 285
     IMGUI_API void          Color(const char* prefix, unsigned int v);
281 286
 
282
-    // Logging
283
-    IMGUI_API void          LogButtons();
284
-    IMGUI_API void          LogToTTY(int max_depth = -1);
285
-    IMGUI_API void          LogToFile(int max_depth = -1, const char* filename = NULL);
286
-    IMGUI_API void          LogToClipboard(int max_depth = -1);
287
+    // Logging: All text output from your interface are redirected to tty/file/clipboard. Tree nodes are automatically opened.
288
+    IMGUI_API void          LogToTTY(int max_depth = -1);                                       // start logging to tty
289
+    IMGUI_API void          LogToFile(int max_depth = -1, const char* filename = NULL);         // start logging to file
290
+    IMGUI_API void          LogToClipboard(int max_depth = -1);                                 // start logging to OS clipboard
291
+    IMGUI_API void          LogFinish();                                                        // stop logging (close file, etc.)
292
+    IMGUI_API void          LogButtons();                                                       // helper to display buttons for logging to tty/file/clipboard
293
+    IMGUI_API void          LogText(const char* fmt, ...);                                      // pass text data straight to log (without being displayed)
287 294
 
288 295
     // Utilities
289 296
     IMGUI_API bool          IsItemHovered();                                                    // was the last item active area hovered by mouse?
@@ -301,7 +308,7 @@ namespace ImGui
301 308
     IMGUI_API ImVec2        GetMousePos();                                                      // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls
302 309
     IMGUI_API float         GetTime();
303 310
     IMGUI_API int           GetFrameCount();
304
-    IMGUI_API const char*   GetStyleColorName(ImGuiCol idx);
311
+    IMGUI_API const char*   GetStyleColName(ImGuiCol idx);
305 312
     IMGUI_API void          GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size);
306 313
     IMGUI_API ImVec2        CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f);
307 314
 
@@ -380,6 +387,7 @@ enum ImGuiCol_
380 387
     ImGuiCol_ComboBg,
381 388
     ImGuiCol_CheckHovered,
382 389
     ImGuiCol_CheckActive,
390
+    ImGuiCol_CheckMark,
383 391
     ImGuiCol_SliderGrab,
384 392
     ImGuiCol_SliderGrabActive,
385 393
     ImGuiCol_Button,
@@ -417,7 +425,6 @@ enum ImGuiStyleVar_
417 425
     ImGuiStyleVar_ItemSpacing,       // ImVec2
418 426
     ImGuiStyleVar_ItemInnerSpacing,  // ImVec2
419 427
     ImGuiStyleVar_TreeNodeSpacing,   // float
420
-    ImGuiStyleVar_ColumnsMinSpacing  // float 
421 428
 };
422 429
 
423 430
 // Enumeration for ColorEditMode()
@@ -443,13 +450,13 @@ struct ImGuiStyle
443 450
     float       Alpha;                      // Global alpha applies to everything in ImGui
444 451
     ImVec2      WindowPadding;              // Padding within a window
445 452
     ImVec2      WindowMinSize;              // Minimum window size
453
+    float       WindowRounding;             // Radius of window corners rounding. Set to 0.0f to have rectangular windows
446 454
     ImVec2      FramePadding;               // Padding within a framed rectangle (used by most widgets)
447 455
     ImVec2      ItemSpacing;                // Horizontal and vertical spacing between widgets/lines
448 456
     ImVec2      ItemInnerSpacing;           // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
449 457
     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!
450 458
     ImVec2      AutoFitPadding;             // Extra space after auto-fit (double-clicking on resize grip)
451 459
     float       WindowFillAlphaDefault;     // Default alpha of window background, if not specified in ImGui::Begin()
452
-    float       WindowRounding;             // Radius of window corners rounding. Set to 0.0f to have rectangular windows
453 460
     float       TreeNodeSpacing;            // Horizontal spacing when entering a tree node
454 461
     float       ColumnsMinSpacing;          // Minimum horizontal spacing between two columns
455 462
     float       ScrollBarWidth;             // Width of the vertical scroll bar
@@ -604,6 +611,7 @@ struct ImGuiTextBuffer
604 611
     bool                empty() { return Buf.empty(); }
605 612
     void                clear() { Buf.clear(); Buf.push_back(0); }
606 613
     IMGUI_API void      append(const char* fmt, ...);
614
+    IMGUI_API void      appendv(const char* fmt, va_list args);
607 615
 };
608 616
 
609 617
 // Helper: Key->value storage
@@ -679,7 +687,7 @@ struct ImDrawVert
679 687
     ImU32   col;
680 688
 };
681 689
 #else
682
-// You can change the vertex format layout by defining IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT.
690
+// You can change the vertex format layout by defining IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT in imconfig.h
683 691
 // The code expect ImVec2 pos (8 bytes), ImVec2 uv (8 bytes), ImU32 col (4 bytes), but you can re-order them or add other fields as needed to simplify integration in your engine.
684 692
 // The type has to be described by the #define (you can either declare the struct or use a typedef)
685 693
 IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT;
@@ -737,7 +745,7 @@ struct ImFont
737 745
 
738 746
     // Settings
739 747
     float                       Scale;              // = 1.0f          // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
740
-    ImVec2                      DisplayOffset;      // = (0.0f,0.0f    // Offset font rendering by xx pixels
748
+    ImVec2                      DisplayOffset;      // = (0.0f,0.0f)   // Offset font rendering by xx pixels
741 749
     ImVec2                      TexUvForWhite;      // = (0.0f,0.0f)   // Font texture must have a white pixel at this UV coordinate. Adjust if you are using custom texture.
742 750
     ImWchar                     FallbackChar;       // = '?'           // Replacement glyph is one isn't found.
743 751
 

Loading…
Откажи
Сачувај