Browse Source

Fixed texture viewer, updated imgui again

Thomas Buck 9 years ago
parent
commit
6282248c71
7 changed files with 47 additions and 41 deletions
  1. 1
    2
      .gitignore
  2. 1
    1
      ChangeLog.md
  3. 4
    16
      src/TextureManager.cpp
  4. 5
    6
      src/UI.cpp
  5. 25
    6
      src/deps/imgui/imgui.cpp
  6. 10
    9
      src/deps/imgui/imgui.h
  7. 1
    1
      src/system/FontTTF.cpp

+ 1
- 2
.gitignore View File

1
 .DS_Store
1
 .DS_Store
2
-build
3
-doc
2
+build*

+ 1
- 1
ChangeLog.md View File

4
 
4
 
5
     [ 20140203 ]
5
     [ 20140203 ]
6
     * Updated imgui to newest version, supporting Images
6
     * Updated imgui to newest version, supporting Images
7
-    * Imgui Image texture viewer (still buggy)
7
+    * Texture viewer is back, using imgui Images
8
 
8
 
9
     [ 20140124 ]
9
     [ 20140124 ]
10
     * Started working on Entity system.
10
     * Started working on Entity system.

+ 4
- 16
src/TextureManager.cpp View File

76
         mTextureIdsSystem.pop_back();
76
         mTextureIdsSystem.pop_back();
77
     }
77
     }
78
 
78
 
79
-    clear();
80
-
79
+    gameBuffers.clear();
81
     systemBuffers.clear();
80
     systemBuffers.clear();
81
+
82
+    clear();
82
 }
83
 }
83
 
84
 
84
 void TextureManager::clear() {
85
 void TextureManager::clear() {
98
     gameUnits.clear();
99
     gameUnits.clear();
99
     systemUnits.clear();
100
     systemUnits.clear();
100
     nextFreeTextureUnit = 0;
101
     nextFreeTextureUnit = 0;
101
-
102
-    gameBuffers.clear();
103
 }
102
 }
104
 
103
 
105
 int TextureManager::loadBufferSlot(unsigned char* image,
104
 int TextureManager::loadBufferSlot(unsigned char* image,
167
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
166
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
168
     }
167
     }
169
 
168
 
170
-    Log::get(LOG_DEBUG) << "New Texture: " << slot << " - "
171
-        << ((s == TextureStorage::GAME) ? "Game" : "System") << Log::endl;
172
-
173
     return slot;
169
     return slot;
174
 }
170
 }
175
 
171
 
186
 }
182
 }
187
 
183
 
188
 int TextureManager::bindTexture(unsigned int n, TextureStorage s) {
184
 int TextureManager::bindTexture(unsigned int n, TextureStorage s) {
189
-    if (n >= getIds(s).size()) {
190
-        Log::get(LOG_DEBUG) << "Bound Unknown Texture " << n << " in "
191
-            << ((s == TextureStorage::GAME) ? "Game" : "System") << Log::endl;
192
-    }
193
-
194
     assert(n < getIds(s).size());
185
     assert(n < getIds(s).size());
195
 
186
 
196
     if ((n < getUnits(s).size()) && (getUnits(s).at(n) >= 0)) {
187
     if ((n < getUnits(s).size()) && (getUnits(s).at(n) >= 0)) {
253
 
244
 
254
 BufferManager* TextureManager::getBufferManager(int tex, TextureStorage store) {
245
 BufferManager* TextureManager::getBufferManager(int tex, TextureStorage store) {
255
     auto& v = (store == TextureStorage::GAME) ? gameBuffers : systemBuffers;
246
     auto& v = (store == TextureStorage::GAME) ? gameBuffers : systemBuffers;
256
-    while (v.size() <= tex) {
247
+    while (v.size() <= (tex + 1)) {
257
         v.emplace_back(v.size(), store);
248
         v.emplace_back(v.size(), store);
258
-
259
-        Log::get(LOG_DEBUG) << "New BufferManager: " << v.size() - 1 << " - "
260
-            << ((store == TextureStorage::GAME) ? "Game" : "System") << Log::endl;
261
     }
249
     }
262
     return &(v.at(tex));
250
     return &(v.at(tex));
263
 }
251
 }

+ 5
- 6
src/UI.cpp View File

11
 #include "Camera.h"
11
 #include "Camera.h"
12
 #include "Console.h"
12
 #include "Console.h"
13
 #include "Game.h"
13
 #include "Game.h"
14
-#include "Log.h"
15
 #include "Menu.h"
14
 #include "Menu.h"
16
 #include "Render.h"
15
 #include "Render.h"
17
 #include "RunTime.h"
16
 #include "RunTime.h"
89
     io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
88
     io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
90
     fontTex = TextureManager::loadBufferSlot(pixels, width, height, ColorMode::RGBA, 32,
89
     fontTex = TextureManager::loadBufferSlot(pixels, width, height, ColorMode::RGBA, 32,
91
                                              TextureStorage::SYSTEM, -1, false);
90
                                              TextureStorage::SYSTEM, -1, false);
92
-    io.Fonts->TexID = TextureManager::getBufferManager(fontTex, TextureStorage::SYSTEM);
91
+    auto bm = TextureManager::getBufferManager(fontTex, TextureStorage::SYSTEM);
92
+    io.Fonts->TexID = bm;
93
 
93
 
94
     // Set up OpenRaider style
94
     // Set up OpenRaider style
95
     ImGuiStyle& style = ImGui::GetStyle();
95
     ImGuiStyle& style = ImGui::GetStyle();
311
                 }
311
                 }
312
             }
312
             }
313
 
313
 
314
-            ImGui::Image(TextureManager::getBufferManager(index,
315
-                                                          game ? TextureStorage::GAME
316
-                                                            : TextureStorage::SYSTEM),
317
-                         ImVec2(ImGui::GetColumnWidth() * 2 / 3, ImGui::GetColumnWidth() * 2 / 3));
314
+            auto bm = TextureManager::getBufferManager(index, game ? TextureStorage::GAME
315
+                                                                : TextureStorage::SYSTEM);
316
+            ImGui::Image(bm, ImVec2(ImGui::GetColumnWidth() * 2 / 3, ImGui::GetColumnWidth() * 2 / 3));
318
         }
317
         }
319
 
318
 
320
         SoundManager::display();
319
         SoundManager::display();

+ 25
- 6
src/deps/imgui/imgui.cpp View File

235
  ==================
235
  ==================
236
 
236
 
237
  - misc: merge or clarify ImVec4 / ImGuiAabb, they are essentially duplicate containers
237
  - misc: merge or clarify ImVec4 / ImGuiAabb, they are essentially duplicate containers
238
-!- i/o: avoid requesting mouse capture if button held and initial click was out of reach for imgui
239
  - window: add horizontal scroll
238
  - window: add horizontal scroll
240
  - window: fix resize grip rendering scaling along with Rounding style setting
239
  - window: fix resize grip rendering scaling along with Rounding style setting
241
  - window: autofit feedback loop when user relies on any dynamic layout (window width multiplier, column). maybe just clearly drop manual autofit?
240
  - window: autofit feedback loop when user relies on any dynamic layout (window width multiplier, column). maybe just clearly drop manual autofit?
257
  - input number: use mouse wheel to step up/down
256
  - input number: use mouse wheel to step up/down
258
  - input number: non-decimal input.
257
  - input number: non-decimal input.
259
  - layout: horizontal layout helper (github issue #97)
258
  - layout: horizontal layout helper (github issue #97)
259
+ - layout: more generic alignment state (left/right/centered) for single items?
260
  - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 layout code. item width should include frame padding.
260
  - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 layout code. item width should include frame padding.
261
  - columns: separator function or parameter that works within the column (currently Separator() bypass all columns)
261
  - columns: separator function or parameter that works within the column (currently Separator() bypass all columns)
262
  - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills)
262
  - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills)
300
  - misc: mark printf compiler attributes on relevant functions
300
  - misc: mark printf compiler attributes on relevant functions
301
  - misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL)
301
  - misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL)
302
  - misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon?
302
  - misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon?
303
+ - style editor: have a more global HSV setter (e.g. alter hue on all elements). consider replacing active/hovered by offset in HSV space?
303
  - style editor: color child window height expressed in multiple of line height.
304
  - style editor: color child window height expressed in multiple of line height.
304
  - optimization/render: use indexed rendering to reduce vertex data cost (for remote/networked imgui)
305
  - optimization/render: use indexed rendering to reduce vertex data cost (for remote/networked imgui)
305
  - optimization/render: move clip-rect to vertex data? would allow merging all commands
306
  - optimization/render: move clip-rect to vertex data? would allow merging all commands
1059
 
1060
 
1060
     ImGuiDrawContext        DC;
1061
     ImGuiDrawContext        DC;
1061
     ImVector<ImGuiID>       IDStack;
1062
     ImVector<ImGuiID>       IDStack;
1062
-    ImVector<ImVec4>        ClipRectStack;
1063
+    ImVector<ImVec4>        ClipRectStack;                      // Scissoring / clipping rectangle. x1, y1, x2, y2.
1063
     int                     LastFrameDrawn;
1064
     int                     LastFrameDrawn;
1064
     float                   ItemWidthDefault;
1065
     float                   ItemWidthDefault;
1065
     ImGuiStorage            StateStorage;
1066
     ImGuiStorage            StateStorage;
1697
     else
1698
     else
1698
         g.HoveredRootWindow = FindHoveredWindow(g.IO.MousePos, true);
1699
         g.HoveredRootWindow = FindHoveredWindow(g.IO.MousePos, true);
1699
 
1700
 
1700
-    // Are we using inputs? Tell user so they can capture/discard them.
1701
-    g.IO.WantCaptureMouse = (g.HoveredWindow != NULL) || (g.ActiveId != 0);
1701
+    // Are we using inputs? Tell user so they can capture/discard the inputs away from the rest of their application.
1702
+    // When clicking outside of a window we assume the click is owned by the application and won't request capture.
1703
+    int mouse_earliest_button_down = -1;
1704
+    for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
1705
+    {
1706
+        if (g.IO.MouseClicked[i])
1707
+            g.IO.MouseDownOwned[i] = (g.HoveredWindow != NULL);
1708
+        if (g.IO.MouseDown[i])
1709
+            if (mouse_earliest_button_down == -1 || g.IO.MouseClickedTime[mouse_earliest_button_down] > g.IO.MouseClickedTime[i])
1710
+                mouse_earliest_button_down = i;
1711
+    }
1712
+    bool mouse_owned_by_application = mouse_earliest_button_down != -1 && !g.IO.MouseDownOwned[mouse_earliest_button_down];
1713
+    g.IO.WantCaptureMouse = (!mouse_owned_by_application && g.HoveredWindow != NULL) || (g.ActiveId != 0);
1702
     g.IO.WantCaptureKeyboard = (g.ActiveId != 0);
1714
     g.IO.WantCaptureKeyboard = (g.ActiveId != 0);
1703
 
1715
 
1716
+    // If mouse was first clicked outside of ImGui bounds we also cancel out hovering.
1717
+    if (mouse_owned_by_application)
1718
+        g.HoveredWindow = g.HoveredRootWindow = NULL;
1719
+
1704
     // Scale & Scrolling
1720
     // Scale & Scrolling
1705
     if (g.HoveredWindow && g.IO.MouseWheel != 0.0f)
1721
     if (g.HoveredWindow && g.IO.MouseWheel != 0.0f)
1706
     {
1722
     {
1830
     ImVec4 cr = clip_rect;
1846
     ImVec4 cr = clip_rect;
1831
     if (clipped && !window->ClipRectStack.empty())
1847
     if (clipped && !window->ClipRectStack.empty())
1832
     {
1848
     {
1833
-        // Clip to new clip rect
1849
+        // Clip with existing clip rect
1834
         const ImVec4 cur_cr = window->ClipRectStack.back();
1850
         const ImVec4 cur_cr = window->ClipRectStack.back();
1835
         cr = ImVec4(ImMax(cr.x, cur_cr.x), ImMax(cr.y, cur_cr.y), ImMin(cr.z, cur_cr.z), ImMin(cr.w, cur_cr.w));
1851
         cr = ImVec4(ImMax(cr.x, cur_cr.x), ImMax(cr.y, cur_cr.y), ImMin(cr.z, cur_cr.z), ImMin(cr.w, cur_cr.w));
1836
     }
1852
     }
2815
 
2831
 
2816
             const ImVec2 text_size = CalcTextSize(name, NULL, true);
2832
             const ImVec2 text_size = CalcTextSize(name, NULL, true);
2817
             const ImVec2 text_max = window->Pos + ImVec2(window->Size.x - (p_opened ? (title_bar_aabb.GetHeight()-3) : style.FramePadding.x), style.FramePadding.y + text_size.y);
2833
             const ImVec2 text_max = window->Pos + ImVec2(window->Size.x - (p_opened ? (title_bar_aabb.GetHeight()-3) : style.FramePadding.x), style.FramePadding.y + text_size.y);
2818
-            const bool clip_title = text_size.x > (text_max.x - text_min.x);    // only push a clip rectangle if we need to, because it may turn into a separate draw call
2834
+            const bool clip_title = text_size.x > (text_max.x - text_min.x);    // only push a clip rectangle if we need to, because it may turn into a separate draw call  // FIXME-OPT: CPU side clipping would work well for this kind of case.
2819
             if (clip_title)
2835
             if (clip_title)
2820
                 PushClipRect(ImVec4(text_min.x, text_min.y, text_max.x, text_max.y));
2836
                 PushClipRect(ImVec4(text_min.x, text_min.y, text_max.x, text_max.y));
2821
             RenderText(text_min, name);
2837
             RenderText(text_min, name);
6154
     }
6170
     }
6155
 }
6171
 }
6156
 
6172
 
6173
+// Scissoring. The values in clip_rect are x1, y1, x2, y2.
6157
 void ImDrawList::PushClipRect(const ImVec4& clip_rect)
6174
 void ImDrawList::PushClipRect(const ImVec4& clip_rect)
6158
 {
6175
 {
6159
     clip_rect_stack.push_back(clip_rect);
6176
     clip_rect_stack.push_back(clip_rect);
7712
     ImGui::Text("ImGui says hello.");
7729
     ImGui::Text("ImGui says hello.");
7713
     //ImGui::Text("MousePos (%g, %g)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
7730
     //ImGui::Text("MousePos (%g, %g)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
7714
     //ImGui::Text("MouseWheel %d", ImGui::GetIO().MouseWheel);
7731
     //ImGui::Text("MouseWheel %d", ImGui::GetIO().MouseWheel);
7732
+    //ImGui::Text("WantCaptureMouse: %d", ImGui::GetIO().WantCaptureMouse);
7733
+    //ImGui::Text("WantCaptureKeyboard: %d", ImGui::GetIO().WantCaptureKeyboard);
7715
 
7734
 
7716
     ImGui::Spacing();
7735
     ImGui::Spacing();
7717
     if (ImGui::CollapsingHeader("Help"))
7736
     if (ImGui::CollapsingHeader("Help"))

+ 10
- 9
src/deps/imgui/imgui.h View File

566
     // [Internal] ImGui will maintain those fields for you
566
     // [Internal] ImGui will maintain those fields for you
567
     //------------------------------------------------------------------
567
     //------------------------------------------------------------------
568
 
568
 
569
-    ImVec2      MousePosPrev;
570
-    ImVec2      MouseDelta;
571
-    bool        MouseClicked[5];
572
-    ImVec2      MouseClickedPos[5];
573
-    float       MouseClickedTime[5];
574
-    bool        MouseDoubleClicked[5];
575
-    float       MouseDownTime[5];
576
-    float       KeysDownTime[512];
569
+    ImVec2      MousePosPrev;               //
570
+    ImVec2      MouseDelta;                 // Mouse delta. Note that this is zero if either current or previous position are negative to allow mouse enabling/disabling.
571
+    bool        MouseClicked[5];            // Mouse button went from !Down to Down
572
+    ImVec2      MouseClickedPos[5];         // Position at time of clicking
573
+    float       MouseClickedTime[5];        // Time of last click (used to figure out double-click)
574
+    bool        MouseDoubleClicked[5];      // Has mouse button been double-clicked?
575
+    bool        MouseDownOwned[5];          // Track if button was clicked inside a window. We don't request mouse capture from the application if click started outside ImGui bounds.
576
+    float       MouseDownTime[5];           // Time the mouse button has been down
577
+    float       KeysDownTime[512];          // Time the keyboard key has been down
577
 
578
 
578
     IMGUI_API   ImGuiIO();
579
     IMGUI_API   ImGuiIO();
579
 };
580
 };
782
 
783
 
783
     ImDrawList() { Clear(); }
784
     ImDrawList() { Clear(); }
784
     IMGUI_API void  Clear();
785
     IMGUI_API void  Clear();
785
-    IMGUI_API void  PushClipRect(const ImVec4& clip_rect);
786
+    IMGUI_API void  PushClipRect(const ImVec4& clip_rect);          // Scissoring. The values are x1, y1, x2, y2.
786
     IMGUI_API void  PopClipRect();
787
     IMGUI_API void  PopClipRect();
787
     IMGUI_API void  PushTextureID(const ImTextureID& texture_id);
788
     IMGUI_API void  PushTextureID(const ImTextureID& texture_id);
788
     IMGUI_API void  PopTextureID();
789
     IMGUI_API void  PopTextureID();

+ 1
- 1
src/system/FontTTF.cpp View File

16
 #define MAP_WIDTH 512
16
 #define MAP_WIDTH 512
17
 #define MAP_HEIGHT 512
17
 #define MAP_HEIGHT 512
18
 #define FONT_SIZE 33
18
 #define FONT_SIZE 33
19
-#define MAP_NUM_CHARS 50
19
+#define MAP_NUM_CHARS 100
20
 
20
 
21
 FontMapTTF::FontMapTTF() : begin(-1), texture(-1), charInfo(nullptr) { }
21
 FontMapTTF::FontMapTTF() : begin(-1), texture(-1), charInfo(nullptr) { }
22
 
22
 

Loading…
Cancel
Save