소스 검색

Fixed texture viewer, updated imgui again

Thomas Buck 9 년 전
부모
커밋
6282248c71
7개의 변경된 파일47개의 추가작업 그리고 41개의 파일을 삭제
  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 파일 보기

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

+ 1
- 1
ChangeLog.md 파일 보기

@@ -4,7 +4,7 @@
4 4
 
5 5
     [ 20140203 ]
6 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 9
     [ 20140124 ]
10 10
     * Started working on Entity system.

+ 4
- 16
src/TextureManager.cpp 파일 보기

@@ -76,9 +76,10 @@ void TextureManager::shutdown() {
76 76
         mTextureIdsSystem.pop_back();
77 77
     }
78 78
 
79
-    clear();
80
-
79
+    gameBuffers.clear();
81 80
     systemBuffers.clear();
81
+
82
+    clear();
82 83
 }
83 84
 
84 85
 void TextureManager::clear() {
@@ -98,8 +99,6 @@ void TextureManager::clear() {
98 99
     gameUnits.clear();
99 100
     systemUnits.clear();
100 101
     nextFreeTextureUnit = 0;
101
-
102
-    gameBuffers.clear();
103 102
 }
104 103
 
105 104
 int TextureManager::loadBufferSlot(unsigned char* image,
@@ -167,9 +166,6 @@ int TextureManager::loadBufferSlot(unsigned char* image,
167 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 169
     return slot;
174 170
 }
175 171
 
@@ -186,11 +182,6 @@ void TextureManager::bindTextureId(unsigned int n, TextureStorage s, unsigned in
186 182
 }
187 183
 
188 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 185
     assert(n < getIds(s).size());
195 186
 
196 187
     if ((n < getUnits(s).size()) && (getUnits(s).at(n) >= 0)) {
@@ -253,11 +244,8 @@ int TextureManager::getNextTileAnimation(int tile) {
253 244
 
254 245
 BufferManager* TextureManager::getBufferManager(int tex, TextureStorage store) {
255 246
     auto& v = (store == TextureStorage::GAME) ? gameBuffers : systemBuffers;
256
-    while (v.size() <= tex) {
247
+    while (v.size() <= (tex + 1)) {
257 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 250
     return &(v.at(tex));
263 251
 }

+ 5
- 6
src/UI.cpp 파일 보기

@@ -11,7 +11,6 @@
11 11
 #include "Camera.h"
12 12
 #include "Console.h"
13 13
 #include "Game.h"
14
-#include "Log.h"
15 14
 #include "Menu.h"
16 15
 #include "Render.h"
17 16
 #include "RunTime.h"
@@ -89,7 +88,8 @@ int UI::initialize() {
89 88
     io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
90 89
     fontTex = TextureManager::loadBufferSlot(pixels, width, height, ColorMode::RGBA, 32,
91 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 94
     // Set up OpenRaider style
95 95
     ImGuiStyle& style = ImGui::GetStyle();
@@ -311,10 +311,9 @@ void UI::display() {
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 319
         SoundManager::display();

+ 25
- 6
src/deps/imgui/imgui.cpp 파일 보기

@@ -235,7 +235,6 @@
235 235
  ==================
236 236
 
237 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 238
  - window: add horizontal scroll
240 239
  - window: fix resize grip rendering scaling along with Rounding style setting
241 240
  - window: autofit feedback loop when user relies on any dynamic layout (window width multiplier, column). maybe just clearly drop manual autofit?
@@ -257,6 +256,7 @@
257 256
  - input number: use mouse wheel to step up/down
258 257
  - input number: non-decimal input.
259 258
  - layout: horizontal layout helper (github issue #97)
259
+ - layout: more generic alignment state (left/right/centered) for single items?
260 260
  - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 layout code. item width should include frame padding.
261 261
  - columns: separator function or parameter that works within the column (currently Separator() bypass all columns)
262 262
  - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills)
@@ -300,6 +300,7 @@
300 300
  - misc: mark printf compiler attributes on relevant functions
301 301
  - misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL)
302 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 304
  - style editor: color child window height expressed in multiple of line height.
304 305
  - optimization/render: use indexed rendering to reduce vertex data cost (for remote/networked imgui)
305 306
  - optimization/render: move clip-rect to vertex data? would allow merging all commands
@@ -1059,7 +1060,7 @@ struct ImGuiWindow
1059 1060
 
1060 1061
     ImGuiDrawContext        DC;
1061 1062
     ImVector<ImGuiID>       IDStack;
1062
-    ImVector<ImVec4>        ClipRectStack;
1063
+    ImVector<ImVec4>        ClipRectStack;                      // Scissoring / clipping rectangle. x1, y1, x2, y2.
1063 1064
     int                     LastFrameDrawn;
1064 1065
     float                   ItemWidthDefault;
1065 1066
     ImGuiStorage            StateStorage;
@@ -1697,10 +1698,25 @@ void ImGui::NewFrame()
1697 1698
     else
1698 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 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 1720
     // Scale & Scrolling
1705 1721
     if (g.HoveredWindow && g.IO.MouseWheel != 0.0f)
1706 1722
     {
@@ -1830,7 +1846,7 @@ static void PushClipRect(const ImVec4& clip_rect, bool clipped = true)
1830 1846
     ImVec4 cr = clip_rect;
1831 1847
     if (clipped && !window->ClipRectStack.empty())
1832 1848
     {
1833
-        // Clip to new clip rect
1849
+        // Clip with existing clip rect
1834 1850
         const ImVec4 cur_cr = window->ClipRectStack.back();
1835 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,7 +2831,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph
2815 2831
 
2816 2832
             const ImVec2 text_size = CalcTextSize(name, NULL, true);
2817 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 2835
             if (clip_title)
2820 2836
                 PushClipRect(ImVec4(text_min.x, text_min.y, text_max.x, text_max.y));
2821 2837
             RenderText(text_min, name);
@@ -6154,6 +6170,7 @@ void ImDrawList::UpdateClipRect()
6154 6170
     }
6155 6171
 }
6156 6172
 
6173
+// Scissoring. The values in clip_rect are x1, y1, x2, y2.
6157 6174
 void ImDrawList::PushClipRect(const ImVec4& clip_rect)
6158 6175
 {
6159 6176
     clip_rect_stack.push_back(clip_rect);
@@ -7712,6 +7729,8 @@ void ImGui::ShowTestWindow(bool* opened)
7712 7729
     ImGui::Text("ImGui says hello.");
7713 7730
     //ImGui::Text("MousePos (%g, %g)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
7714 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 7735
     ImGui::Spacing();
7717 7736
     if (ImGui::CollapsingHeader("Help"))

+ 10
- 9
src/deps/imgui/imgui.h 파일 보기

@@ -566,14 +566,15 @@ struct ImGuiIO
566 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 579
     IMGUI_API   ImGuiIO();
579 580
 };
@@ -782,7 +783,7 @@ struct ImDrawList
782 783
 
783 784
     ImDrawList() { Clear(); }
784 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 787
     IMGUI_API void  PopClipRect();
787 788
     IMGUI_API void  PushTextureID(const ImTextureID& texture_id);
788 789
     IMGUI_API void  PopTextureID();

+ 1
- 1
src/system/FontTTF.cpp 파일 보기

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

Loading…
취소
저장