Browse Source

Imgui update, debugging

Thomas Buck 9 years ago
parent
commit
d6eab5d760

+ 5
- 6
CMakeLists.txt View File

37
     set (WARNINGS "${WARNINGS} -Wno-padded -Wno-packed")
37
     set (WARNINGS "${WARNINGS} -Wno-padded -Wno-packed")
38
     set (WARNINGS "${WARNINGS} -Wno-global-constructors -Wno-exit-time-destructors")
38
     set (WARNINGS "${WARNINGS} -Wno-global-constructors -Wno-exit-time-destructors")
39
     set (WARNINGS "${WARNINGS} -Wno-documentation-unknown-command -Wno-c++98-compat-pedantic")
39
     set (WARNINGS "${WARNINGS} -Wno-documentation-unknown-command -Wno-c++98-compat-pedantic")
40
+    set (WARNINGS "${WARNINGS} -Wno-date-time -Wno-unused-variable")
40
     set (WARNINGS "${WARNINGS} -Wno-shorten-64-to-32 -Wno-sign-compare -Wno-sign-conversion")
41
     set (WARNINGS "${WARNINGS} -Wno-shorten-64-to-32 -Wno-sign-compare -Wno-sign-conversion")
41
     set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -std=c++11")
42
     set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -std=c++11")
42
-    set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -g -O0 -ftrapv")
43
-    set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -O2 -fomit-frame-pointer")
44
-    set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -ffast-math -funroll-loops")
43
+    set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -g -O0")
44
+    set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -O2")
45
 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
45
 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
46
     set (WARNINGS "${WARNINGS} -Wall -Wextra -Wpedantic")
46
     set (WARNINGS "${WARNINGS} -Wall -Wextra -Wpedantic")
47
     set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -std=c++11")
47
     set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -std=c++11")
48
-    set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -g -O0 -ftrapv")
49
-    set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -O2 -fomit-frame-pointer")
50
-    set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -ffast-math -funroll-loops")
48
+    set (OpenRaider_CXX_FLAGS_DEBUG "${OpenRaider_CXX_FLAGS_DEBUG} -g -O0")
49
+    set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -O2")
51
 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
50
 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
52
     # TODO Visual C++ compiler flags?
51
     # TODO Visual C++ compiler flags?
53
 endif()
52
 endif()

+ 21
- 7
src/Render.cpp View File

130
         // Check all portals leading from this room to somewhere else
130
         // Check all portals leading from this room to somewhere else
131
         for (int i = 0; i < World::getRoom(room).sizePortals(); i++) {
131
         for (int i = 0; i < World::getRoom(room).sizePortals(); i++) {
132
             auto& portal = World::getRoom(room).getPortal(i);
132
             auto& portal = World::getRoom(room).getPortal(i);
133
-            auto& room = World::getRoom(portal.getAdjoiningRoom());
133
+            auto& r = World::getRoom(portal.getAdjoiningRoom());
134
 
134
 
135
             // Calculate the 2D screen-space bounding box of this portal
135
             // Calculate the 2D screen-space bounding box of this portal
136
             glm::vec3 newMin, newMax;
136
             glm::vec3 newMin, newMax;
137
             for (int c = 0; c < 4; c++) {
137
             for (int c = 0; c < 4; c++) {
138
-                glm::vec3 vert = portal.getVertex(c);
139
-                glm::vec4 result = VP * glm::vec4(vert, 1.0f);
140
-                vert = glm::vec3(result) / result.w;
138
+                glm::vec3 port = portal.getVertex(c);
139
+                glm::vec4 result = VP * glm::vec4(port, 1.0f);
140
+                glm::vec3 vert = glm::vec3(result) / result.w;
141
+
142
+                ImGui::Text("%.2f %.2f %.2f", port.x, port.y, port.z);
143
+                ImGui::Text("%.2f %.2f %.2f %.2f", result.x, result.y, result.z, result.w);
144
+                ImGui::Text("%.2f %.2f %.2f", vert.x, vert.y, vert.z);
145
+                ImGui::Text("----");
141
 
146
 
142
                 if (c == 0) {
147
                 if (c == 0) {
143
                     newMin = vert;
148
                     newMin = vert;
158
                 }
163
                 }
159
             }
164
             }
160
 
165
 
166
+            //ImGui::Text("%.2f %.2f %.2f", newMin.x, newMin.y, newMin.z);
167
+            //ImGui::Text("%.2f %.2f %.2f", newMax.x, newMax.y, newMax.z);
168
+            //ImGui::Text("----");
169
+
161
             //! \fixme Currently also checking behind player, because Z is always 1.0f?!
170
             //! \fixme Currently also checking behind player, because Z is always 1.0f?!
162
             //if ((newMin.z > 0.0f) || (newMin.z < -1.0f) || (newMax.z > 0.0f) || (newMax.z < -1.0f)) {
171
             //if ((newMin.z > 0.0f) || (newMin.z < -1.0f) || (newMax.z > 0.0f) || (newMax.z < -1.0f)) {
163
             //    continue;
172
             //    continue;
164
             //}
173
             //}
165
 
174
 
175
+            //! \fixme Need to check portal normal, only render if it points in our direction
176
+            //if (!normalFacingUs) {
177
+            //    continue;
178
+            //}
179
+
166
             // Check if the portal intersects the portal leading into this room
180
             // Check if the portal intersects the portal leading into this room
167
             if (!((min.x < newMax.x) && (max.x > newMin.x)
181
             if (!((min.x < newMax.x) && (max.x > newMin.x)
168
                 && (min.y < newMax.y) && (max.y > newMin.y))) {
182
                 && (min.y < newMax.y) && (max.y > newMin.y))) {
170
             }
184
             }
171
 
185
 
172
             // Check if the connected room is in our view frustum (could be visible)
186
             // Check if the connected room is in our view frustum (could be visible)
173
-            if (!Camera::boxInFrustum(room.getBoundingBox())) {
174
-                continue;
187
+            if (!Camera::boxInFrustum(r.getBoundingBox())) {
188
+                //continue;
175
             }
189
             }
176
 
190
 
177
             // Check if this room is already in the list...
191
             // Check if this room is already in the list...
178
             bool found = false;
192
             bool found = false;
179
             for (int n = 0; n < roomList.size(); n++) {
193
             for (int n = 0; n < roomList.size(); n++) {
180
-                if (roomList.at(n).room == &room) {
194
+                if (roomList.at(n).room == &r) {
181
                     found = true;
195
                     found = true;
182
                     break;
196
                     break;
183
                 }
197
                 }

+ 6
- 5
src/UI.cpp View File

151
     io.DisplaySize = ImVec2(Window::getSize().x, Window::getSize().y);
151
     io.DisplaySize = ImVec2(Window::getSize().x, Window::getSize().y);
152
 
152
 
153
     static unsigned long lastTime = 0;
153
     static unsigned long lastTime = 0;
154
-    io.DeltaTime = ((float)(systemTimerGet() - lastTime)) / 1000.0f;
154
+    io.DeltaTime = (systemTimerGet() - lastTime) / 1000.0f;
155
     lastTime = systemTimerGet();
155
     lastTime = systemTimerGet();
156
     if (io.DeltaTime <= 0.0f)
156
     if (io.DeltaTime <= 0.0f)
157
         io.DeltaTime = 1.0f / 60.0f;
157
         io.DeltaTime = 1.0f / 60.0f;
172
 
172
 
173
         if (!(visible || Console::isVisible() || Menu::isVisible())) {
173
         if (!(visible || Console::isVisible() || Menu::isVisible())) {
174
             for (int n = forwardAction; n < ActionEventCount; n++) {
174
             for (int n = forwardAction; n < ActionEventCount; n++) {
175
-                if (RunTime::getKeyBinding((ActionEvents)n) == std::get<0>(i))
176
-                    Game::handleAction((ActionEvents)n, !std::get<1>(i));
175
+                auto ae = static_cast<ActionEvents>(n);
176
+                if (RunTime::getKeyBinding(ae) == std::get<0>(i))
177
+                    Game::handleAction(ae, !std::get<1>(i));
177
             }
178
             }
178
         }
179
         }
179
 
180
 
402
 
403
 
403
 void UI::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
404
 void UI::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
404
     ImGuiIO& io = ImGui::GetIO();
405
     ImGuiIO& io = ImGui::GetIO();
405
-    io.MousePos = ImVec2((float)x, (float)y);
406
+    io.MousePos = ImVec2(x, y);
406
     if (button == leftmouseKey) {
407
     if (button == leftmouseKey) {
407
         io.MouseDown[0] = !released;
408
         io.MouseDown[0] = !released;
408
     } else if (button == rightmouseKey) {
409
     } else if (button == rightmouseKey) {
420
 
421
 
421
 void UI::handleMouseMotion(int xrel, int yrel, int xabs, int yabs) {
422
 void UI::handleMouseMotion(int xrel, int yrel, int xabs, int yabs) {
422
     ImGuiIO& io = ImGui::GetIO();
423
     ImGuiIO& io = ImGui::GetIO();
423
-    io.MousePos = ImVec2((float)xabs, (float)yabs);
424
+    io.MousePos = ImVec2(xabs, yabs);
424
 
425
 
425
     motionEvents.push_back(std::make_tuple(xrel, yrel, xabs, yabs));
426
     motionEvents.push_back(std::make_tuple(xrel, yrel, xabs, yabs));
426
 }
427
 }

+ 1
- 1
src/commands/CommandBind.cpp View File

97
         char c = key[1];
97
         char c = key[1];
98
         if (((c >= '0') && (c <= '9'))
98
         if (((c >= '0') && (c <= '9'))
99
             || ((c >= 'a') && (c <= 'z')))
99
             || ((c >= 'a') && (c <= 'z')))
100
-            return (KeyboardButton)c;
100
+            return static_cast<KeyboardButton>(c);
101
     } else if ((key.length() >= 3) && (key[0] == '\"') && (key[key.length() - 1] == '\"')) {
101
     } else if ((key.length() >= 3) && (key[0] == '\"') && (key[key.length() - 1] == '\"')) {
102
         // Special characters like tilde, esc, quote...
102
         // Special characters like tilde, esc, quote...
103
         key.erase(key.length() - 1); // Delete " at end
103
         key.erase(key.length() - 1); // Delete " at end

+ 8
- 5
src/deps/imgui/imconfig.h View File

19
 //#define IMGUI_API __declspec( dllexport )
19
 //#define IMGUI_API __declspec( dllexport )
20
 //#define IMGUI_API __declspec( dllimport )
20
 //#define IMGUI_API __declspec( dllimport )
21
 
21
 
22
+//---- Include imgui_user.inl at the end of imgui.cpp so you can include code that extends ImGui using its private data/functions.
23
+#define IMGUI_INCLUDE_IMGUI_USER_INL
24
+
25
+//---- Include imgui_user.h at the end of imgui.h
26
+#define IMGUI_INCLUDE_IMGUI_USER_H
27
+
22
 //---- Don't implement default handlers for Windows (so as not to link with OpenClipboard() and others Win32 functions)
28
 //---- Don't implement default handlers for Windows (so as not to link with OpenClipboard() and others Win32 functions)
23
 //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS
29
 //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS
24
 //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS
30
 //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS
26
 //---- Don't implement help and test window functionality (ShowUserGuide()/ShowStyleEditor()/ShowTestWindow() methods will be empty)
32
 //---- Don't implement help and test window functionality (ShowUserGuide()/ShowStyleEditor()/ShowTestWindow() methods will be empty)
27
 //#define IMGUI_DISABLE_TEST_WINDOWS
33
 //#define IMGUI_DISABLE_TEST_WINDOWS
28
 
34
 
29
-//---- Include imgui_user.inl at the end of imgui.cpp so you can include code that extends ImGui using its private data/functions.
30
-#define IMGUI_INCLUDE_IMGUI_USER_INL
31
-
32
-//---- Include imgui_user.h at the end of imgui.h
33
-#define IMGUI_INCLUDE_IMGUI_USER_H
35
+//---- Implement STB libraries in a namespace to avoid conflicts
36
+//#define IMGUI_STB_NAMESPACE     ImStb
34
 
37
 
35
 //---- Define constructor and implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4.
38
 //---- Define constructor and implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4.
36
 #define IM_VEC2_CLASS_EXTRA                                                \
39
 #define IM_VEC2_CLASS_EXTRA                                                \

+ 198
- 44
src/deps/imgui/imgui.cpp View File

1
-// ImGui library v1.38 WIP
1
+// ImGui library v1.39 WIP
2
 // See ImGui::ShowTestWindow() for sample code.
2
 // See ImGui::ShowTestWindow() for sample code.
3
 // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase.
3
 // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase.
4
 // Get latest version at https://github.com/ocornut/imgui
4
 // Get latest version at https://github.com/ocornut/imgui
13
  - API BREAKING CHANGES (read me when you update!)
13
  - API BREAKING CHANGES (read me when you update!)
14
  - FREQUENTLY ASKED QUESTIONS (FAQ), TIPS
14
  - FREQUENTLY ASKED QUESTIONS (FAQ), TIPS
15
    - Can I have multiple widgets with the same label? (Yes)
15
    - Can I have multiple widgets with the same label? (Yes)
16
+   - How do I update to a newer version of ImGui?
16
    - Why is my text output blurry?
17
    - Why is my text output blurry?
17
    - How can I load a different font than the default? 
18
    - How can I load a different font than the default? 
18
    - How can I load multiple fonts?
19
    - How can I load multiple fonts?
268
       e.g. when displaying a single object that may change over time (1-1 relationship), using a static string as ID will preserve your node open/closed state when the targeted object change.
269
       e.g. when displaying a single object that may change over time (1-1 relationship), using a static string as ID will preserve your node open/closed state when the targeted object change.
269
       e.g. when displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state differently. experiment and see what makes more sense!
270
       e.g. when displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state differently. experiment and see what makes more sense!
270
 
271
 
272
+ Q: How do I update to a newer version of ImGui?
273
+ A: Overwrite the following files:
274
+     imgui.cpp
275
+     imgui.h
276
+     stb_rect_pack.h
277
+     stb_textedit.h
278
+     stb_truetype.h
279
+    Check the "API BREAKING CHANGES" sections for a list of occasional API breaking changes.
280
+
271
  Q: Why is my text output blurry?
281
  Q: Why is my text output blurry?
272
  A: In your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
282
  A: In your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
273
 
283
 
492
 static void         ItemSize(ImVec2 size, float text_offset_y = 0.0f);
502
 static void         ItemSize(ImVec2 size, float text_offset_y = 0.0f);
493
 static void         ItemSize(const ImRect& bb, float text_offset_y = 0.0f);
503
 static void         ItemSize(const ImRect& bb, float text_offset_y = 0.0f);
494
 static void         PushColumnClipRect(int column_index = -1);
504
 static void         PushColumnClipRect(int column_index = -1);
495
-static bool         IsClippedEx(const ImRect& bb, bool clip_even_when_logged);
505
+static bool         IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when_logged);
496
 
506
 
497
 static bool         IsMouseHoveringRect(const ImRect& bb);
507
 static bool         IsMouseHoveringRect(const ImRect& bb);
498
 static bool         IsKeyPressedMap(ImGuiKey key, bool repeat = true);
508
 static bool         IsKeyPressedMap(ImGuiKey key, bool repeat = true);
1146
     ImGuiID                 ScalarAsInputTextId;                // Temporary text input when CTRL+clicking on a slider, etc.
1156
     ImGuiID                 ScalarAsInputTextId;                // Temporary text input when CTRL+clicking on a slider, etc.
1147
     ImGuiStorage            ColorEditModeStorage;               // for user selection
1157
     ImGuiStorage            ColorEditModeStorage;               // for user selection
1148
     ImGuiID                 ActiveComboID;
1158
     ImGuiID                 ActiveComboID;
1159
+    ImVec2                  ActiveClickDeltaToCenter;
1149
     float                   DragCurrentValue;                   // current dragged value, always float, not rounded by end-user precision settings
1160
     float                   DragCurrentValue;                   // current dragged value, always float, not rounded by end-user precision settings
1150
     ImVec2                  DragLastMouseDelta;
1161
     ImVec2                  DragLastMouseDelta;
1151
     float                   DragSpeedDefaultRatio;              // if speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio
1162
     float                   DragSpeedDefaultRatio;              // if speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio
1204
 
1215
 
1205
         ScalarAsInputTextId = 0;
1216
         ScalarAsInputTextId = 0;
1206
         ActiveComboID = 0;
1217
         ActiveComboID = 0;
1218
+        ActiveClickDeltaToCenter = ImVec2(0.0f, 0.0f);
1207
         DragCurrentValue = 0.0f;
1219
         DragCurrentValue = 0.0f;
1208
         DragLastMouseDelta = ImVec2(0.0f, 0.0f);
1220
         DragLastMouseDelta = ImVec2(0.0f, 0.0f);
1209
         DragSpeedDefaultRatio = 0.01f;
1221
         DragSpeedDefaultRatio = 0.01f;
1403
     return &it->val_f;
1415
     return &it->val_f;
1404
 }
1416
 }
1405
 
1417
 
1418
+void** ImGuiStorage::GetVoidPtrRef(ImGuiID key, void* default_val)
1419
+{
1420
+    ImVector<Pair>::iterator it = LowerBound(Data, key);
1421
+    if (it == Data.end() || it->key != key)
1422
+        it = Data.insert(it, Pair(key, default_val));
1423
+    return &it->val_p;
1424
+}
1425
+
1406
 // FIXME-OPT: Wasting CPU because all SetInt() are preceeded by GetInt() calls so we should have the result from lower_bound already in place.
1426
 // FIXME-OPT: Wasting CPU because all SetInt() are preceeded by GetInt() calls so we should have the result from lower_bound already in place.
1407
 // However we only use SetInt() on explicit user action (so that's maximum once a frame) so the optimisation isn't much needed.
1427
 // However we only use SetInt() on explicit user action (so that's maximum once a frame) so the optimisation isn't much needed.
1408
 void ImGuiStorage::SetInt(ImU32 key, int val)
1428
 void ImGuiStorage::SetInt(ImU32 key, int val)
4255
                 while (line < text_end)
4275
                 while (line < text_end)
4256
                 {
4276
                 {
4257
                     const char* line_end = strchr(line, '\n');
4277
                     const char* line_end = strchr(line, '\n');
4258
-                    if (IsClippedEx(line_rect, false))
4278
+                    if (IsClippedEx(line_rect, NULL, false))
4259
                         break;
4279
                         break;
4260
 
4280
 
4261
                     const ImVec2 line_size = CalcTextSize(line, line_end, false);
4281
                     const ImVec2 line_size = CalcTextSize(line, line_end, false);
5126
     return value;
5146
     return value;
5127
 }
5147
 }
5128
 
5148
 
5129
-static bool SliderBehavior(const ImRect& frame_bb, const ImRect& slider_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, bool horizontal)
5149
+static bool SliderScalarBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, bool horizontal)
5130
 {
5150
 {
5131
     ImGuiState& g = *GImGui;
5151
     ImGuiState& g = *GImGui;
5132
     ImGuiWindow* window = GetCurrentWindow();
5152
     ImGuiWindow* window = GetCurrentWindow();
5137
 
5157
 
5138
     const bool is_non_linear = fabsf(power - 1.0f) > 0.0001f;
5158
     const bool is_non_linear = fabsf(power - 1.0f) > 0.0001f;
5139
 
5159
 
5140
-    const float slider_sz = horizontal ? slider_bb.GetWidth() : slider_bb.GetHeight();
5160
+    const float padding = horizontal ? style.FramePadding.x : style.FramePadding.y;
5161
+    const float slider_sz = horizontal ? (frame_bb.GetWidth() - padding * 2.0f) : (frame_bb.GetHeight() - padding * 2.0f);
5141
     float grab_sz;
5162
     float grab_sz;
5142
     if (decimal_precision > 0)
5163
     if (decimal_precision > 0)
5143
         grab_sz = ImMin(style.GrabMinSize, slider_sz);
5164
         grab_sz = ImMin(style.GrabMinSize, slider_sz);
5144
     else
5165
     else
5145
         grab_sz = ImMin(ImMax(1.0f * (slider_sz / (v_max-v_min+1.0f)), style.GrabMinSize), slider_sz);  // Integer sliders, if possible have the grab size represent 1 unit
5166
         grab_sz = ImMin(ImMax(1.0f * (slider_sz / (v_max-v_min+1.0f)), style.GrabMinSize), slider_sz);  // Integer sliders, if possible have the grab size represent 1 unit
5146
     const float slider_usable_sz = slider_sz - grab_sz;
5167
     const float slider_usable_sz = slider_sz - grab_sz;
5147
-    const float slider_usable_pos_min = (horizontal ? slider_bb.Min.x : slider_bb.Min.y) + grab_sz*0.5f;
5148
-    const float slider_usable_pos_max = (horizontal ? slider_bb.Max.x : slider_bb.Max.y) - grab_sz*0.5f;
5168
+    const float slider_usable_pos_min = (horizontal ? frame_bb.Min.x : frame_bb.Min.y) + padding + grab_sz*0.5f;
5169
+    const float slider_usable_pos_max = (horizontal ? frame_bb.Max.x : frame_bb.Max.y) - padding - grab_sz*0.5f;
5149
 
5170
 
5150
     bool value_changed = false;
5171
     bool value_changed = false;
5151
 
5172
 
5183
                     // Negative: rescale to the negative range before powering
5204
                     // Negative: rescale to the negative range before powering
5184
                     float a = 1.0f - (normalized_pos / linear_zero_pos);
5205
                     float a = 1.0f - (normalized_pos / linear_zero_pos);
5185
                     a = powf(a, power);
5206
                     a = powf(a, power);
5186
-                    new_value = ImLerp(ImMin(v_max,0.f), v_min, a);
5207
+                    new_value = ImLerp(ImMin(v_max,0.0f), v_min, a);
5187
                 }
5208
                 }
5188
                 else
5209
                 else
5189
                 {
5210
                 {
5272
 
5293
 
5273
     const ImVec2 label_size = CalcTextSize(label, NULL, true);
5294
     const ImVec2 label_size = CalcTextSize(label, NULL, true);
5274
     const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
5295
     const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
5275
-    const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
5276
     const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
5296
     const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
5277
 
5297
 
5278
     // NB- we don't call ItemSize() yet because we may turn into a text edit box below
5298
     // NB- we don't call ItemSize() yet because we may turn into a text edit box below
5312
     ItemSize(total_bb, style.FramePadding.y);
5332
     ItemSize(total_bb, style.FramePadding.y);
5313
 
5333
 
5314
     // Actual slider behavior + render grab
5334
     // Actual slider behavior + render grab
5315
-    const bool value_changed = SliderBehavior(frame_bb, inner_bb, id, v, v_min, v_max, power, decimal_precision, true);
5335
+    const bool value_changed = SliderScalarBehavior(frame_bb, id, v, v_min, v_max, power, decimal_precision, true);
5316
 
5336
 
5317
     // Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
5337
     // Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
5318
     char value_buf[64];
5338
     char value_buf[64];
5319
     const char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
5339
     const char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
5320
     const ImVec2 value_text_size = CalcTextSize(value_buf, value_buf_end, true);
5340
     const ImVec2 value_text_size = CalcTextSize(value_buf, value_buf_end, true);
5321
-    RenderTextClipped(ImVec2(ImMax(frame_bb.Min.x + style.FramePadding.x, inner_bb.GetCenter().x - value_text_size.x*0.5f), frame_bb.Min.y + style.FramePadding.y), value_buf, value_buf_end, &value_text_size, frame_bb.Max);
5341
+    RenderTextClipped(ImVec2(ImMax(frame_bb.Min.x + style.FramePadding.x, frame_bb.GetCenter().x - value_text_size.x*0.5f), frame_bb.Min.y + style.FramePadding.y), value_buf, value_buf_end, &value_text_size, frame_bb.Max);
5322
 
5342
 
5323
     if (label_size.x > 0.0f)
5343
     if (label_size.x > 0.0f)
5324
-        RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label);
5344
+        RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
5325
 
5345
 
5326
     return value_changed;
5346
     return value_changed;
5327
 }
5347
 }
5338
 
5358
 
5339
     const ImVec2 label_size = CalcTextSize(label, NULL, true);
5359
     const ImVec2 label_size = CalcTextSize(label, NULL, true);
5340
     const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size);
5360
     const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size);
5341
-    const ImRect slider_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
5342
     const ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
5361
     const ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
5343
 
5362
 
5344
     ItemSize(bb, style.FramePadding.y);
5363
     ItemSize(bb, style.FramePadding.y);
5361
     }
5380
     }
5362
 
5381
 
5363
     // Actual slider behavior + render grab
5382
     // Actual slider behavior + render grab
5364
-    bool value_changed = SliderBehavior(frame_bb, slider_bb, id, v, v_min, v_max, power, decimal_precision, false);
5383
+    bool value_changed = SliderScalarBehavior(frame_bb, id, v, v_min, v_max, power, decimal_precision, false);
5365
 
5384
 
5366
     // Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
5385
     // Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
5367
     // For the vertical slider we allow centered text to overlap the frame padding
5386
     // For the vertical slider we allow centered text to overlap the frame padding
5368
     char value_buf[64];
5387
     char value_buf[64];
5369
     char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
5388
     char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
5370
     const ImVec2 value_text_size = CalcTextSize(value_buf, value_buf_end, true);
5389
     const ImVec2 value_text_size = CalcTextSize(value_buf, value_buf_end, true);
5371
-    RenderTextClipped(ImVec2(ImMax(frame_bb.Min.x, slider_bb.GetCenter().x - value_text_size.x*0.5f), frame_bb.Min.y + style.FramePadding.y), value_buf, value_buf_end, &value_text_size, frame_bb.Max);
5390
+    RenderTextClipped(ImVec2(ImMax(frame_bb.Min.x, frame_bb.GetCenter().x - value_text_size.x*0.5f), frame_bb.Min.y + style.FramePadding.y), value_buf, value_buf_end, &value_text_size, frame_bb.Max);
5372
 
5391
 
5373
     if (label_size.x > 0.0f)
5392
     if (label_size.x > 0.0f)
5374
-        RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, slider_bb.Min.y), label);
5393
+        RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
5375
 
5394
 
5376
     return value_changed;
5395
     return value_changed;
5377
 }
5396
 }
5405
 }
5424
 }
5406
 
5425
 
5407
 // Add multiple sliders on 1 line for compact edition of multiple components
5426
 // Add multiple sliders on 1 line for compact edition of multiple components
5408
-static bool SliderFloatN(const char* label, float v[3], int components, float v_min, float v_max, const char* display_format, float power)
5427
+static bool SliderFloatN(const char* label, float* v, int components, float v_min, float v_max, const char* display_format, float power)
5409
 {
5428
 {
5410
     ImGuiState& g = *GImGui;
5429
     ImGuiState& g = *GImGui;
5411
     ImGuiWindow* window = GetCurrentWindow();
5430
     ImGuiWindow* window = GetCurrentWindow();
5457
     return SliderFloatN(label, v, 4, v_min, v_max, display_format, power);
5476
     return SliderFloatN(label, v, 4, v_min, v_max, display_format, power);
5458
 }
5477
 }
5459
 
5478
 
5460
-static bool SliderIntN(const char* label, int v[3], int components, int v_min, int v_max, const char* display_format)
5479
+static bool SliderIntN(const char* label, int* v, int components, int v_min, int v_max, const char* display_format)
5461
 {
5480
 {
5462
     ImGuiState& g = *GImGui;
5481
     ImGuiState& g = *GImGui;
5463
     ImGuiWindow* window = GetCurrentWindow();
5482
     ImGuiWindow* window = GetCurrentWindow();
5522
 
5541
 
5523
     bool value_changed = false;
5542
     bool value_changed = false;
5524
 
5543
 
5525
-    // Process clicking on the slider
5544
+    // Process clicking on the drag
5526
     if (g.ActiveId == id)
5545
     if (g.ActiveId == id)
5527
     {
5546
     {
5528
         if (g.IO.MouseDown[0])
5547
         if (g.IO.MouseDown[0])
5652
     return value_changed;
5671
     return value_changed;
5653
 }
5672
 }
5654
 
5673
 
5674
+static bool DragFloatN(const char* label, float* v, int components, float v_speed, float v_min, float v_max, const char* display_format, float power)
5675
+{
5676
+    ImGuiState& g = *GImGui;
5677
+    ImGuiWindow* window = GetCurrentWindow();
5678
+    if (window->SkipItems)
5679
+        return false;
5680
+
5681
+    const ImGuiStyle& style = g.Style;
5682
+    const float w_full = ImGui::CalcItemWidth();
5683
+    const float w_item_one  = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)) / (float)components));
5684
+    const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)));
5685
+
5686
+    bool value_changed = false;
5687
+    ImGui::BeginGroup();
5688
+    ImGui::PushID(label);
5689
+    ImGui::PushItemWidth(w_item_one);
5690
+    for (int i = 0; i < components; i++)
5691
+    {
5692
+        ImGui::PushID(i);
5693
+        if (i + 1 == components)
5694
+        {
5695
+            ImGui::PopItemWidth();
5696
+            ImGui::PushItemWidth(w_item_last);
5697
+        }
5698
+        value_changed |= ImGui::DragFloat("##v", &v[i], v_speed, v_min, v_max, display_format, power);
5699
+        ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
5700
+        ImGui::PopID();
5701
+    }
5702
+    ImGui::PopItemWidth();
5703
+    ImGui::PopID();
5704
+
5705
+    ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
5706
+    ImGui::EndGroup();
5707
+
5708
+    return value_changed;
5709
+}
5710
+
5711
+bool ImGui::DragFloat2(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* display_format, float power)
5712
+{
5713
+    return DragFloatN(label, v, 2, v_speed, v_min, v_max, display_format, power);
5714
+}
5715
+
5716
+bool ImGui::DragFloat3(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* display_format, float power)
5717
+{
5718
+    return DragFloatN(label, v, 3, v_speed, v_min, v_max, display_format, power);
5719
+}
5720
+
5721
+bool ImGui::DragFloat4(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* display_format, float power)
5722
+{
5723
+    return DragFloatN(label, v, 4, v_speed, v_min, v_max, display_format, power);
5724
+}
5725
+
5655
 // NB: v_speed is float to allow adjusting the drag speed with more precision
5726
 // NB: v_speed is float to allow adjusting the drag speed with more precision
5656
 bool ImGui::DragInt(const char* label, int* v, float v_speed, int v_min, int v_max, const char* display_format)
5727
 bool ImGui::DragInt(const char* label, int* v, float v_speed, int v_min, int v_max, const char* display_format)
5657
 {
5728
 {
5663
     return value_changed;
5734
     return value_changed;
5664
 }
5735
 }
5665
 
5736
 
5737
+static bool DragIntN(const char* label, int* v, int components, float v_speed, int v_min, int v_max, const char* display_format)
5738
+{
5739
+    ImGuiState& g = *GImGui;
5740
+    ImGuiWindow* window = GetCurrentWindow();
5741
+    if (window->SkipItems)
5742
+        return false;
5743
+
5744
+    const ImGuiStyle& style = g.Style;
5745
+    const float w_full = ImGui::CalcItemWidth();
5746
+    const float w_item_one  = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)) / (float)components));
5747
+    const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)));
5748
+
5749
+    bool value_changed = false;
5750
+    ImGui::BeginGroup();
5751
+    ImGui::PushID(label);
5752
+    ImGui::PushItemWidth(w_item_one);
5753
+    for (int i = 0; i < components; i++)
5754
+    {
5755
+        ImGui::PushID(i);
5756
+        if (i + 1 == components)
5757
+        {
5758
+            ImGui::PopItemWidth();
5759
+            ImGui::PushItemWidth(w_item_last);
5760
+        }
5761
+        value_changed |= ImGui::DragInt("##v", &v[i], v_speed, v_min, v_max, display_format);
5762
+        ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
5763
+        ImGui::PopID();
5764
+    }
5765
+    ImGui::PopItemWidth();
5766
+    ImGui::PopID();
5767
+
5768
+    ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
5769
+    ImGui::EndGroup();
5770
+
5771
+    return value_changed;
5772
+}
5773
+
5774
+bool ImGui::DragInt2(const char* label, int v[2], float v_speed, int v_min, int v_max, const char* display_format)
5775
+{
5776
+    return DragIntN(label, v, 2, v_speed, v_min, v_max, display_format);
5777
+}
5778
+
5779
+bool ImGui::DragInt3(const char* label, int v[3], float v_speed, int v_min, int v_max, const char* display_format)
5780
+{
5781
+    return DragIntN(label, v, 3, v_speed, v_min, v_max, display_format);
5782
+}
5783
+
5784
+bool ImGui::DragInt4(const char* label, int v[4], float v_speed, int v_min, int v_max, const char* display_format)
5785
+{
5786
+    return DragIntN(label, v, 4, v_speed, v_min, v_max, display_format);
5787
+}
5788
+
5666
 enum ImGuiPlotType
5789
 enum ImGuiPlotType
5667
 {
5790
 {
5668
     ImGuiPlotType_Lines,
5791
     ImGuiPlotType_Lines,
6865
     const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : w, size_arg.y != 0.0f ? size_arg.y : label_size.y);
6988
     const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : w, size_arg.y != 0.0f ? size_arg.y : label_size.y);
6866
     ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
6989
     ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
6867
     ItemSize(bb);
6990
     ItemSize(bb);
6868
-    bb.Max.x += style.AutoFitPadding.x;
6991
+    if (size_arg.x == 0.0f)
6992
+        bb.Max.x += style.AutoFitPadding.x;
6869
 
6993
 
6870
     // Selectables are meant to be tightly packed together. So for both rendering and collision we extend to compensate for spacing.
6994
     // Selectables are meant to be tightly packed together. So for both rendering and collision we extend to compensate for spacing.
6871
     ImRect bb_with_spacing = bb;
6995
     ImRect bb_with_spacing = bb;
7256
     ItemSize(bb.GetSize(), text_offset_y); 
7380
     ItemSize(bb.GetSize(), text_offset_y); 
7257
 }
7381
 }
7258
 
7382
 
7259
-static bool IsClippedEx(const ImRect& bb, bool clip_even_when_logged)
7383
+static bool IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when_logged)
7260
 {
7384
 {
7261
     ImGuiState& g = *GImGui;
7385
     ImGuiState& g = *GImGui;
7262
     ImGuiWindow* window = GetCurrentWindow();
7386
     ImGuiWindow* window = GetCurrentWindow();
7263
 
7387
 
7264
     if (!bb.Overlaps(ImRect(window->ClipRectStack.back())))
7388
     if (!bb.Overlaps(ImRect(window->ClipRectStack.back())))
7265
     {
7389
     {
7266
-        if (clip_even_when_logged || !g.LogEnabled)
7267
-            return true;
7390
+        if (!id || *id != GImGui->ActiveId)
7391
+            if (clip_even_when_logged || !g.LogEnabled)
7392
+                return true;
7268
     }
7393
     }
7269
     return false;
7394
     return false;
7270
 }
7395
 }
7272
 bool ImGui::IsRectClipped(const ImVec2& size)
7397
 bool ImGui::IsRectClipped(const ImVec2& size)
7273
 {
7398
 {
7274
     ImGuiWindow* window = GetCurrentWindow();
7399
     ImGuiWindow* window = GetCurrentWindow();
7275
-    return IsClippedEx(ImRect(window->DC.CursorPos, window->DC.CursorPos + size), true);
7400
+    return IsClippedEx(ImRect(window->DC.CursorPos, window->DC.CursorPos + size), NULL, true);
7276
 }
7401
 }
7277
 
7402
 
7278
 static bool ItemAdd(const ImRect& bb, const ImGuiID* id)
7403
 static bool ItemAdd(const ImRect& bb, const ImGuiID* id)
7280
     ImGuiWindow* window = GetCurrentWindow();
7405
     ImGuiWindow* window = GetCurrentWindow();
7281
     window->DC.LastItemID = id ? *id : 0;
7406
     window->DC.LastItemID = id ? *id : 0;
7282
     window->DC.LastItemRect = bb;
7407
     window->DC.LastItemRect = bb;
7283
-    if (IsClippedEx(bb, false))
7408
+    if (IsClippedEx(bb, id, false))
7284
     {
7409
     {
7285
-        if (!id || *id != GImGui->ActiveId)
7286
-        {
7287
-            window->DC.LastItemHoveredAndUsable = window->DC.LastItemHoveredRect = false;
7288
-            return false;
7289
-        }
7410
+        window->DC.LastItemHoveredAndUsable = window->DC.LastItemHoveredRect = false;
7411
+        return false;
7290
     }
7412
     }
7291
 
7413
 
7292
     // This is a sensible default, but widgets are free to override it after calling ItemAdd()
7414
     // This is a sensible default, but widgets are free to override it after calling ItemAdd()
7416
         window->DC.CurrentLineTextBaseOffset = 0.0f;
7538
         window->DC.CurrentLineTextBaseOffset = 0.0f;
7417
 
7539
 
7418
         PushColumnClipRect();
7540
         PushColumnClipRect();
7419
-        ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f);
7541
+        ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f);  // FIXME
7420
     }
7542
     }
7421
 }
7543
 }
7422
 
7544
 
7432
     return window->DC.ColumnsCount;
7554
     return window->DC.ColumnsCount;
7433
 }
7555
 }
7434
 
7556
 
7557
+static float GetDraggedColumnOffset(int column_index)
7558
+{
7559
+    // Active (dragged) column always follow mouse. The reason we need this is that dragging a column to the right edge of an auto-resizing
7560
+    // window creates a feedback loop because we store normalized positions/ So while dragging we enforce absolute positioning
7561
+    ImGuiState& g = *GImGui;
7562
+    ImGuiWindow* window = GetCurrentWindow();
7563
+    IM_ASSERT(g.ActiveId == window->DC.ColumnsSetID + ImGuiID(column_index));
7564
+
7565
+    float x = g.IO.MousePos.x + g.ActiveClickDeltaToCenter.x;
7566
+    x -= window->Pos.x;
7567
+    x = ImClamp(x, ImGui::GetColumnOffset(column_index-1)+g.Style.ColumnsMinSpacing, ImGui::GetColumnOffset(column_index+1)-g.Style.ColumnsMinSpacing);
7568
+
7569
+    return x;
7570
+}
7571
+
7435
 float ImGui::GetColumnOffset(int column_index)
7572
 float ImGui::GetColumnOffset(int column_index)
7436
 {
7573
 {
7437
     ImGuiState& g = *GImGui;
7574
     ImGuiState& g = *GImGui;
7439
     if (column_index < 0)
7576
     if (column_index < 0)
7440
         column_index = window->DC.ColumnsCurrent;
7577
         column_index = window->DC.ColumnsCurrent;
7441
 
7578
 
7579
+    if (g.ActiveId)
7580
+    {
7581
+        const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
7582
+        if (g.ActiveId == column_id)
7583
+            return GetDraggedColumnOffset(column_index);
7584
+    }
7585
+
7442
     // Read from cache
7586
     // Read from cache
7443
     IM_ASSERT(column_index < (int)window->DC.ColumnsOffsetsT.size());
7587
     IM_ASSERT(column_index < (int)window->DC.ColumnsOffsetsT.size());
7444
     const float t = window->DC.ColumnsOffsetsT[column_index];
7588
     const float t = window->DC.ColumnsOffsetsT[column_index];
7515
             const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(i);
7659
             const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(i);
7516
             const ImRect column_rect(ImVec2(x-4,y1),ImVec2(x+4,y2));
7660
             const ImRect column_rect(ImVec2(x-4,y1),ImVec2(x+4,y2));
7517
 
7661
 
7518
-            if (IsClippedEx(column_rect, false))
7662
+            if (IsClippedEx(column_rect, &column_id, false))
7519
                 continue;
7663
                 continue;
7520
 
7664
 
7521
             bool hovered, held;
7665
             bool hovered, held;
7530
 
7674
 
7531
             if (held)
7675
             if (held)
7532
             {
7676
             {
7533
-                x -= window->Pos.x;
7534
-                x = ImClamp(x + g.IO.MouseDelta.x, ImGui::GetColumnOffset(i-1)+g.Style.ColumnsMinSpacing, ImGui::GetColumnOffset(i+1)-g.Style.ColumnsMinSpacing);
7677
+                if (g.ActiveIdIsJustActivated)
7678
+                    g.ActiveClickDeltaToCenter.x = x - g.IO.MousePos.x;
7679
+
7680
+                x = GetDraggedColumnOffset(i);
7535
                 SetColumnOffset(i, x);
7681
                 SetColumnOffset(i, x);
7536
-                x += window->Pos.x;
7537
             }
7682
             }
7538
         }
7683
         }
7539
     }
7684
     }
9868
             ImGui::InputFloat3("input float3", vec4a);
10013
             ImGui::InputFloat3("input float3", vec4a);
9869
         }
10014
         }
9870
 
10015
 
9871
-        /*
9872
         {
10016
         {
9873
             static int i1=50;
10017
             static int i1=50;
9874
             static int i2=42;
10018
             static int i2=42;
9875
             ImGui::DragInt("drag int", &i1, 1);
10019
             ImGui::DragInt("drag int", &i1, 1);
9876
-            ImGui::DragInt("drag int 0..100", &i2, 1, 0, 100);
10020
+            ImGui::SameLine();
10021
+            ImGui::TextColored(ImColor(170,170,170,255), "(?)");
10022
+            if (ImGui::IsItemHovered())
10023
+                ImGui::SetTooltip("Click and drag to edit value.\nHold SHIFT/ALT for faster/slower edit.\nDouble-click or CTRL+click to input text");
10024
+
10025
+            ImGui::DragInt("drag int 0..100", &i2, 1, 0, 100, "%.0f%%");
9877
 
10026
 
9878
             static float f1=1.00f;
10027
             static float f1=1.00f;
9879
             static float f2=0.0067f;
10028
             static float f2=0.0067f;
9880
             ImGui::DragFloat("drag float", &f1, 1.0f);
10029
             ImGui::DragFloat("drag float", &f1, 1.0f);
9881
-            ImGui::DragFloat("drag small float", &f2, 0.0001f, 0.0f, 0.0f, "%.06f");
10030
+            ImGui::DragFloat("drag small float", &f2, 0.0001f, 0.0f, 0.0f, "%.06f ns");
9882
         }
10031
         }
9883
-        */
9884
 
10032
 
9885
         {
10033
         {
9886
             static int i1=0;
10034
             static int i1=0;
9887
-            static int i2=42;
10035
+            //static int i2=42;
9888
             ImGui::SliderInt("slider int 0..3", &i1, 0, 3);
10036
             ImGui::SliderInt("slider int 0..3", &i1, 0, 3);
9889
-            ImGui::SliderInt("slider int -100..100", &i2, -100, 100);
10037
+            //ImGui::SliderInt("slider int -100..100", &i2, -100, 100);
9890
 
10038
 
9891
-            static float f1=1.123f;
9892
-            static float f2=0;
9893
-            ImGui::SliderFloat("slider float", &f1, 0.0f, 2.0f);
10039
+            static float f1=0.123f;
10040
+            static float f2=0.0f;
10041
+            ImGui::SliderFloat("slider float", &f1, 0.0f, 1.0f, "ratio = %.3f");
9894
             ImGui::SliderFloat("slider log float", &f2, -10.0f, 10.0f, "%.4f", 3.0f);
10042
             ImGui::SliderFloat("slider log float", &f2, -10.0f, 10.0f, "%.4f", 3.0f);
9895
             static float angle = 0.0f;
10043
             static float angle = 0.0f;
9896
             ImGui::SliderAngle("slider angle", &angle);
10044
             ImGui::SliderAngle("slider angle", &angle);
9918
             static int vec4i[4] = { 1, 5, 100, 255 };
10066
             static int vec4i[4] = { 1, 5, 100, 255 };
9919
 
10067
 
9920
             ImGui::InputFloat2("input float2", vec4f);
10068
             ImGui::InputFloat2("input float2", vec4f);
10069
+            ImGui::DragFloat2("drag float2", vec4f, 0.01f, 0.0f, 1.0f);
9921
             ImGui::SliderFloat2("slider float2", vec4f, 0.0f, 1.0f);
10070
             ImGui::SliderFloat2("slider float2", vec4f, 0.0f, 1.0f);
10071
+            ImGui::DragInt2("drag int2", vec4i, 1, 0, 255);
9922
             ImGui::InputInt2("input int2", vec4i);
10072
             ImGui::InputInt2("input int2", vec4i);
9923
             ImGui::SliderInt2("slider int2", vec4i, 0, 255);
10073
             ImGui::SliderInt2("slider int2", vec4i, 0, 255);
9924
 
10074
 
9925
             ImGui::InputFloat3("input float3", vec4f);
10075
             ImGui::InputFloat3("input float3", vec4f);
10076
+            ImGui::DragFloat3("drag float3", vec4f, 0.01f, 0.0f, 1.0f);
9926
             ImGui::SliderFloat3("slider float3", vec4f, 0.0f, 1.0f);
10077
             ImGui::SliderFloat3("slider float3", vec4f, 0.0f, 1.0f);
10078
+            ImGui::DragInt3("drag int3", vec4i, 1, 0, 255);
9927
             ImGui::InputInt3("input int3", vec4i);
10079
             ImGui::InputInt3("input int3", vec4i);
9928
             ImGui::SliderInt3("slider int3", vec4i, 0, 255);
10080
             ImGui::SliderInt3("slider int3", vec4i, 0, 255);
9929
 
10081
 
9930
             ImGui::InputFloat4("input float4", vec4f);
10082
             ImGui::InputFloat4("input float4", vec4f);
10083
+            ImGui::DragFloat4("drag float4", vec4f, 0.01f, 0.0f, 1.0f);
9931
             ImGui::SliderFloat4("slider float4", vec4f, 0.0f, 1.0f);
10084
             ImGui::SliderFloat4("slider float4", vec4f, 0.0f, 1.0f);
9932
             ImGui::InputInt4("input int4", vec4i);
10085
             ImGui::InputInt4("input int4", vec4i);
10086
+            ImGui::DragInt4("drag int4", vec4i, 1, 0, 255);
9933
             ImGui::SliderInt4("slider int4", vec4i, 0, 255);
10087
             ImGui::SliderInt4("slider int4", vec4i, 0, 255);
9934
 
10088
 
9935
             ImGui::Indent();
10089
             ImGui::Indent();

+ 11
- 5
src/deps/imgui/imgui.h View File

1
-// ImGui library v1.38 WIP
1
+// ImGui library v1.39 WIP
2
 // See .cpp file for documentation.
2
 // See .cpp file for documentation.
3
 // See ImGui::ShowTestWindow() for sample code.
3
 // See ImGui::ShowTestWindow() for sample code.
4
 // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
4
 // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
13
 #include <stdlib.h>         // NULL, malloc, free, qsort, atoi
13
 #include <stdlib.h>         // NULL, malloc, free, qsort, atoi
14
 #include <string.h>         // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp
14
 #include <string.h>         // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp
15
 
15
 
16
-#define IMGUI_VERSION       "1.38 WIP"
16
+#define IMGUI_VERSION       "1.39 WIP"
17
 
17
 
18
 // Define assertion handler.
18
 // Define assertion handler.
19
 #ifndef IM_ASSERT
19
 #ifndef IM_ASSERT
317
     IMGUI_API bool          VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* display_format = "%.0f");
317
     IMGUI_API bool          VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* display_format = "%.0f");
318
 
318
 
319
     // Widgets: Drags (tip: ctrl+click on a drag box to input text)
319
     // Widgets: Drags (tip: ctrl+click on a drag box to input text)
320
-    // ImGui 1.38+ work-in-progress, may change name or API.
321
-    IMGUI_API bool          DragFloat(const char* label, float* v, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f);  // If v_max >= v_max we have no bound
322
-    IMGUI_API bool          DragInt(const char* label, int* v, float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f");                                    // If v_max >= v_max we have no bound
320
+    IMGUI_API bool          DragFloat(const char* label, float* v, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f);     // If v_max >= v_max we have no bound
321
+    IMGUI_API bool          DragFloat2(const char* label, float v[2], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f);
322
+    IMGUI_API bool          DragFloat3(const char* label, float v[3], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f);
323
+    IMGUI_API bool          DragFloat4(const char* label, float v[4], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f", float power = 1.0f);
324
+    IMGUI_API bool          DragInt(const char* label, int* v, float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f");                                       // If v_max >= v_max we have no bound
325
+    IMGUI_API bool          DragInt2(const char* label, int v[2], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f");
326
+    IMGUI_API bool          DragInt3(const char* label, int v[3], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f");
327
+    IMGUI_API bool          DragInt4(const char* label, int v[4], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* display_format = "%.0f");
323
 
328
 
324
     // Widgets: Input
329
     // Widgets: Input
325
     IMGUI_API bool          InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, ImGuiTextEditCallback callback = NULL, void* user_data = NULL);
330
     IMGUI_API bool          InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, ImGuiTextEditCallback callback = NULL, void* user_data = NULL);
799
     // - You can also use this to quickly create temporary editable values during a session of using Edit&Continue, without restarting your application.
804
     // - You can also use this to quickly create temporary editable values during a session of using Edit&Continue, without restarting your application.
800
     IMGUI_API int*    GetIntRef(ImGuiID key, int default_val = 0);
805
     IMGUI_API int*    GetIntRef(ImGuiID key, int default_val = 0);
801
     IMGUI_API float*  GetFloatRef(ImGuiID key, float default_val = 0);
806
     IMGUI_API float*  GetFloatRef(ImGuiID key, float default_val = 0);
807
+    IMGUI_API void**  GetVoidPtrRef(ImGuiID key, void* default_val = NULL);
802
 
808
 
803
     // Use on your own storage if you know only integer are being stored (open/close all tree nodes)
809
     // Use on your own storage if you know only integer are being stored (open/close all tree nodes)
804
     IMGUI_API void    SetAllInt(int val);
810
     IMGUI_API void    SetAllInt(int val);

+ 5
- 2
src/loader/Loader.cpp View File

51
 
51
 
52
         case TR_3:
52
         case TR_3:
53
             return std::unique_ptr<Loader>(new LoaderTR3());
53
             return std::unique_ptr<Loader>(new LoaderTR3());
54
-    }
55
 
54
 
56
-    return nullptr;
55
+        case TR_UNKNOWN:
56
+        case TR_4:
57
+        case TR_5:
58
+            return nullptr;
59
+    }
57
 }
60
 }
58
 
61
 
59
 Loader::~Loader() { }
62
 Loader::~Loader() { }

+ 3
- 3
src/loader/LoaderTR1.cpp View File

307
             tmp += (i - 1) * 16; // TODO ?
307
             tmp += (i - 1) * 16; // TODO ?
308
             BinaryMemory tree(tmp, (numMeshTrees * 4) - meshTree - ((i - 1) * 16));
308
             BinaryMemory tree(tmp, (numMeshTrees * 4) - meshTree - ((i - 1) * 16));
309
 
309
 
310
-            flag = (char)tree.readU32();
310
+            flag = static_cast<char>(tree.readU32());
311
             offset.x = tree.read32();
311
             offset.x = tree.read32();
312
             offset.y = tree.read32();
312
             offset.y = tree.read32();
313
             offset.z = tree.read32();
313
             offset.z = tree.read32();
317
             rotation[0] = (a & 0x3FF0) >> 4;
317
             rotation[0] = (a & 0x3FF0) >> 4;
318
             rotation[1] = ((a & 0x000F) << 6) | ((b & 0xFC00) >> 10);
318
             rotation[1] = ((a & 0x000F) << 6) | ((b & 0xFC00) >> 10);
319
             rotation[2] = b & 0x03FF;
319
             rotation[2] = b & 0x03FF;
320
-            for (int i = 0; i < 3; i++)
321
-                rotation[i] = rotation[i] * 360.0f / 1024.0f;
320
+            for (int n = 0; n < 3; n++)
321
+                rotation[n] = rotation[n] * 360.0f / 1024.0f;
322
         }
322
         }
323
 
323
 
324
         glm::vec3 rot(rotation[0], rotation[1], rotation[2]);
324
         glm::vec3 rot(rotation[0], rotation[1], rotation[2]);

+ 12
- 12
src/loader/LoaderTR2.cpp View File

189
 // ---- Rooms ----
189
 // ---- Rooms ----
190
 
190
 
191
 void LoaderTR2::loadRoomLights() {
191
 void LoaderTR2::loadRoomLights() {
192
-    int16_t intensity1 = file.read16();
193
-    int16_t intensity2 = file.read16();
192
+    int16_t roomIntensity1 = file.read16();
193
+    int16_t roomIntensity2 = file.read16();
194
     int16_t lightMode = file.read16();
194
     int16_t lightMode = file.read16();
195
 
195
 
196
     uint16_t numLights = file.readU16();
196
     uint16_t numLights = file.readU16();
314
 
314
 
315
             // Fill bounding box
315
             // Fill bounding box
316
             if (v == 0) {
316
             if (v == 0) {
317
-                for (int i = 0; i < 2; i++) {
318
-                    bbox[i].x = vert.x;
319
-                    bbox[i].y = vert.y;
320
-                    bbox[i].z = vert.z;
317
+                for (int n = 0; n < 2; n++) {
318
+                    bbox[n].x = vert.x;
319
+                    bbox[n].y = vert.y;
320
+                    bbox[n].z = vert.z;
321
                 }
321
                 }
322
             } else {
322
             } else {
323
                 if (vert.x < bbox[0].x)
323
                 if (vert.x < bbox[0].x)
413
             // There is a special value of the 'real' index, 2047 or 0x7FF.
413
             // There is a special value of the 'real' index, 2047 or 0x7FF.
414
 
414
 
415
             bool wall = false;
415
             bool wall = false;
416
-            if ((((uint8_t)floor) == 0x81) || (((uint8_t)ceiling) == 0x81)) {
416
+            if (((floor & 0xFF) == 0x81) || ((ceiling & 0xFF) == 0x81)) {
417
                 wall = true;
417
                 wall = true;
418
             }
418
             }
419
 
419
 
728
             char* tmp = reinterpret_cast<char*>(&meshTrees[0]) + meshTree; // TODO (meshTree * 4)?
728
             char* tmp = reinterpret_cast<char*>(&meshTrees[0]) + meshTree; // TODO (meshTree * 4)?
729
             tmp += (i - 1) * 16; // TODO ?
729
             tmp += (i - 1) * 16; // TODO ?
730
             BinaryMemory tree(tmp, (numMeshTrees * 4) - meshTree - ((i - 1) * 16));
730
             BinaryMemory tree(tmp, (numMeshTrees * 4) - meshTree - ((i - 1) * 16));
731
-            flag = (char)tree.readU32();
731
+            flag = static_cast<char>(tree.readU32());
732
             offset.x = tree.read32();
732
             offset.x = tree.read32();
733
             offset.y = tree.read32();
733
             offset.y = tree.read32();
734
             offset.z = tree.read32();
734
             offset.z = tree.read32();
741
                     index = 2;
741
                     index = 2;
742
                 else if (a & 0x4000)
742
                 else if (a & 0x4000)
743
                     index = 1;
743
                     index = 1;
744
-                rotation[index] = ((float)(a & 0x03FF)) * 360.0f / 1024.0f;
744
+                rotation[index] = (static_cast<float>(a & 0x03FF)) * 360.0f / 1024.0f;
745
             } else {
745
             } else {
746
                 // Three angles
746
                 // Three angles
747
                 uint16_t b = frame.readU16();
747
                 uint16_t b = frame.readU16();
748
                 rotation[0] = (a & 0x3FF0) >> 4;
748
                 rotation[0] = (a & 0x3FF0) >> 4;
749
                 rotation[1] = ((a & 0x000F) << 6) | ((b & 0xFC00) >> 10);
749
                 rotation[1] = ((a & 0x000F) << 6) | ((b & 0xFC00) >> 10);
750
                 rotation[2] = b & 0x03FF;
750
                 rotation[2] = b & 0x03FF;
751
-                for (int i = 0; i < 3; i++)
752
-                    rotation[i] = rotation[i] * 360.0f / 1024.0f;
751
+                for (int n = 0; n < 3; n++)
752
+                    rotation[n] = rotation[n] * 360.0f / 1024.0f;
753
             }
753
             }
754
         }
754
         }
755
 
755
 
1122
         // Bits 0-1: channel number?
1122
         // Bits 0-1: channel number?
1123
         uint16_t unknown2 = file.readU16();
1123
         uint16_t unknown2 = file.readU16();
1124
 
1124
 
1125
-        SoundManager::addSoundDetail(sample, ((float)volume) / 32767.0f);
1125
+        SoundManager::addSoundDetail(sample, volume / 32767.0f);
1126
     }
1126
     }
1127
 
1127
 
1128
     if (numSoundDetails > 0)
1128
     if (numSoundDetails > 0)

+ 2
- 2
src/loader/LoaderTR3.cpp View File

53
 }
53
 }
54
 
54
 
55
 void LoaderTR3::loadRoomLights() {
55
 void LoaderTR3::loadRoomLights() {
56
-    int16_t intensity1 = file.read16();
57
-    int16_t intensity2 = file.read16();
56
+    int16_t roomIntensity1 = file.read16();
57
+    int16_t roomIntensity2 = file.read16();
58
 
58
 
59
     uint16_t numLights = file.readU16();
59
     uint16_t numLights = file.readU16();
60
     for (unsigned int l = 0; l < numLights; l++) {
60
     for (unsigned int l = 0; l < numLights; l++) {

+ 2
- 0
src/main.cpp View File

184
 #ifdef DEBUG
184
 #ifdef DEBUG
185
     std::cout << std::endl;
185
     std::cout << std::endl;
186
     std::cout << "Thanks for testing " << VERSION << std::endl;
186
     std::cout << "Thanks for testing " << VERSION << std::endl;
187
+#if defined(__DATE__) && defined(__TIME__)
187
     std::cout << "Build date: " << __DATE__ << " @ " << __TIME__ << std::endl;
188
     std::cout << "Build date: " << __DATE__ << " @ " << __TIME__ << std::endl;
189
+#endif
188
     std::cout << "Build host: " << BUILD_HOST << std::endl;
190
     std::cout << "Build host: " << BUILD_HOST << std::endl;
189
     std::cout << "Web site  : http://github.com/xythobuz/OpenRaider" << std::endl;
191
     std::cout << "Web site  : http://github.com/xythobuz/OpenRaider" << std::endl;
190
     std::cout << "Contact   : xythobuz@xythobuz.de" << std::endl;
192
     std::cout << "Contact   : xythobuz@xythobuz.de" << std::endl;

+ 1
- 2
src/system/WindowSDL.cpp View File

203
 
203
 
204
             case SDL_TEXTINPUT:
204
             case SDL_TEXTINPUT:
205
             case SDL_TEXTEDITING:
205
             case SDL_TEXTEDITING:
206
-                if (event.text.text != nullptr)
207
-                    UI::handleText(event.text.text, (event.type == SDL_TEXTEDITING));
206
+                UI::handleText(event.text.text, (event.type == SDL_TEXTEDITING));
208
                 break;
207
                 break;
209
 
208
 
210
             case SDL_KEYDOWN:
209
             case SDL_KEYDOWN:

+ 1
- 1
src/utils/Folder.cpp View File

112
     createFolderItems();
112
     createFolderItems();
113
     for (unsigned long i = 0; i < fileCount(); i++) {
113
     for (unsigned long i = 0; i < fileCount(); i++) {
114
         if (func(getFile(i))) {
114
         if (func(getFile(i))) {
115
-            files.erase(files.begin() + (long)i--);
115
+            files.erase(files.begin() + i--);
116
         }
116
         }
117
     }
117
     }
118
 }
118
 }

+ 4
- 4
src/utils/pcx.cpp View File

24
     unsigned char* header = new unsigned char[128];
24
     unsigned char* header = new unsigned char[128];
25
 
25
 
26
     // Basic validation
26
     // Basic validation
27
-    if (!file.read((char*)(&header[0]), 128)) {
27
+    if (!file.read(reinterpret_cast<char*>(&header[0]), 128)) {
28
         Log::get(LOG_ERROR) << "File not big enough for valid PCX header!" << Log::endl;
28
         Log::get(LOG_ERROR) << "File not big enough for valid PCX header!" << Log::endl;
29
         delete [] header;
29
         delete [] header;
30
         return -1;
30
         return -1;
83
     unsigned char* header = new unsigned char[128];
83
     unsigned char* header = new unsigned char[128];
84
 
84
 
85
     // Basic validation
85
     // Basic validation
86
-    if (!file.read((char*)(&header[0]), 128)) {
86
+    if (!file.read(reinterpret_cast<char*>(&header[0]), 128)) {
87
         Log::get(LOG_ERROR) << "File not big enough for valid PCX header!" << Log::endl;
87
         Log::get(LOG_ERROR) << "File not big enough for valid PCX header!" << Log::endl;
88
         delete [] header;
88
         delete [] header;
89
         return -1;
89
         return -1;
174
         }
174
         }
175
 
175
 
176
         for (unsigned int j = 0; j < n; j++)
176
         for (unsigned int j = 0; j < n; j++)
177
-            buffer[b++] = (unsigned char)c;
177
+            buffer[b++] = static_cast<unsigned char>(c);
178
 
178
 
179
         i += n;
179
         i += n;
180
     }
180
     }
186
         if ((c == 12) && file) {
186
         if ((c == 12) && file) {
187
             palette = new unsigned char[768];
187
             palette = new unsigned char[768];
188
             for (unsigned int i = 0; i < 768; i++) {
188
             for (unsigned int i = 0; i < 768; i++) {
189
-                palette[i] = (unsigned char)file.get();
189
+                palette[i] = static_cast<unsigned char>(file.get());
190
                 if (!file) {
190
                 if (!file) {
191
                     Log::get(LOG_ERROR) << "Could not read 256 color palette (" << i << ")" << Log::endl;
191
                     Log::get(LOG_ERROR) << "Could not read 256 color palette (" << i << ")" << Log::endl;
192
                     delete [] buffer;
192
                     delete [] buffer;

+ 14
- 14
src/utils/pixel.cpp View File

16
 
16
 
17
     unsigned char* image = new unsigned char[height * width * (bpp / 8)];
17
     unsigned char* image = new unsigned char[height * width * (bpp / 8)];
18
     for (unsigned int i = 0; i < (width * height); i++) {
18
     for (unsigned int i = 0; i < (width * height); i++) {
19
-        image[i * (bpp / 8)] = (unsigned char)(rgba.r * 255);
20
-        image[(i * (bpp / 8)) + 1] = (unsigned char)(rgba.g * 255);
21
-        image[(i * (bpp / 8)) + 2] = (unsigned char)(rgba.b * 255);
19
+        image[i * (bpp / 8)] = static_cast<unsigned char>(rgba.r * 255);
20
+        image[(i * (bpp / 8)) + 1] = static_cast<unsigned char>(rgba.g * 255);
21
+        image[(i * (bpp / 8)) + 2] = static_cast<unsigned char>(rgba.b * 255);
22
         if (bpp == 32) {
22
         if (bpp == 32) {
23
-            image[(i * (bpp / 8)) + 3] = (unsigned char)(rgba.a * 255);
23
+            image[(i * (bpp / 8)) + 3] = static_cast<unsigned char>(rgba.a * 255);
24
         }
24
         }
25
     }
25
     }
26
     return image;
26
     return image;
113
 
113
 
114
     // Copy user data to float format.
114
     // Copy user data to float format.
115
     for (unsigned int i = 0; i < original_height * original_width * components; ++i) {
115
     for (unsigned int i = 0; i < original_height * original_width * components; ++i) {
116
-        tempin[i] = (float)image[i];
116
+        tempin[i] = image[i];
117
     }
117
     }
118
 
118
 
119
     // Determine which filter to use by checking ratios.
119
     // Determine which filter to use by checking ratios.
120
     float sx;
120
     float sx;
121
     if (width > 1) {
121
     if (width > 1) {
122
-        sx = (float)(original_width - 1) / (float)(width - 1);
122
+        sx = (original_width - 1.0f) / (width - 1.0f);
123
     } else {
123
     } else {
124
-        sx = (float)(original_width - 1);
124
+        sx = original_width - 1.0f;
125
     }
125
     }
126
 
126
 
127
     float sy;
127
     float sy;
128
     if (height > 1) {
128
     if (height > 1) {
129
-        sy = (float)(original_height - 1) / (float)(height - 1);
129
+        sy = (original_height - 1.0f) / (height - 1.0f);
130
     } else {
130
     } else {
131
-        sy = (float)(original_height - 1);
131
+        sy = original_height - 1.0f;
132
     }
132
     }
133
 
133
 
134
     if (sx < 1.0 && sy < 1.0) { // Magnify both width and height: use weighted sample of 4 pixels
134
     if (sx < 1.0 && sy < 1.0) { // Magnify both width and height: use weighted sample of 4 pixels
135
         for (unsigned int i = 0; i < height; ++i) {
135
         for (unsigned int i = 0; i < height; ++i) {
136
-            unsigned int i0 = (unsigned int)(i * sy);
136
+            unsigned int i0 = static_cast<unsigned int>(i * sy);
137
             unsigned int i1 = i0 + 1;
137
             unsigned int i1 = i0 + 1;
138
 
138
 
139
             if (i1 >= original_height) {
139
             if (i1 >= original_height) {
143
             float alpha = i * sy - i0;
143
             float alpha = i * sy - i0;
144
 
144
 
145
             for (unsigned int j = 0; j < width; ++j) {
145
             for (unsigned int j = 0; j < width; ++j) {
146
-                unsigned int j0 = (unsigned int)(j * sx);
146
+                unsigned int j0 = static_cast<unsigned int>(j * sx);
147
                 unsigned int j1 = j0 + 1;
147
                 unsigned int j1 = j0 + 1;
148
 
148
 
149
                 if (j1 >= original_width) {
149
                 if (j1 >= original_width) {
169
         }
169
         }
170
     } else { // Shrink width and/or height: use an unweighted box filter
170
     } else { // Shrink width and/or height: use an unweighted box filter
171
         for (unsigned int i = 0; i < height; ++i) {
171
         for (unsigned int i = 0; i < height; ++i) {
172
-            unsigned int i0 = (unsigned int)(i * sy);
172
+            unsigned int i0 = static_cast<unsigned int>(i * sy);
173
             unsigned int i1 = i0 + 1;
173
             unsigned int i1 = i0 + 1;
174
 
174
 
175
             if (i1 >= original_height) {
175
             if (i1 >= original_height) {
177
             }
177
             }
178
 
178
 
179
             for (unsigned int j = 0; j < width; ++j) {
179
             for (unsigned int j = 0; j < width; ++j) {
180
-                unsigned int j0 = (unsigned int)(j * sx);
180
+                unsigned int j0 = static_cast<unsigned int>(j * sx);
181
                 unsigned int j1 = j0 + 1;
181
                 unsigned int j1 = j0 + 1;
182
 
182
 
183
                 if (j1 >= original_width) {
183
                 if (j1 >= original_width) {
206
 
206
 
207
     // Copy to our results.
207
     // Copy to our results.
208
     for (unsigned int i = 0; i < height * width * components; ++i) {
208
     for (unsigned int i = 0; i < height * width * components; ++i) {
209
-        timage[i] = (unsigned char)tempout[i];
209
+        timage[i] = static_cast<unsigned char>(tempout[i]);
210
     }
210
     }
211
 
211
 
212
     // Delete our temp buffers.
212
     // Delete our temp buffers.

Loading…
Cancel
Save