Browse Source

Updated imgui, utils/time using more C++11 features

Thomas Buck 10 years ago
parent
commit
05698efead
5 changed files with 32 additions and 27 deletions
  1. 3
    1
      include/utils/time.h
  2. 3
    3
      src/deps/imgui/imconfig.h
  3. 16
    13
      src/deps/imgui/imgui.cpp
  4. 3
    1
      src/deps/imgui/imgui.h
  5. 7
    9
      src/utils/time.cpp

+ 3
- 1
include/utils/time.h View File

@@ -8,11 +8,13 @@
8 8
 #ifndef _UTILS_TIME_H_
9 9
 #define _UTILS_TIME_H_
10 10
 
11
+using or_time_t = unsigned long;
12
+
11 13
 /*!
12 14
  * \brief Read the system timer
13 15
  * \returns number of ticks
14 16
  */
15
-unsigned long systemTimerGet();
17
+or_time_t systemTimerGet();
16 18
 
17 19
 /*!
18 20
  * \brief Reset the system timer

+ 3
- 3
src/deps/imgui/imconfig.h View File

@@ -17,8 +17,8 @@
17 17
 //---- Don't implement default clipboard handlers for Windows (so as not to link with OpenClipboard() and others Win32 functions)
18 18
 //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS
19 19
 
20
-//---- Include imgui_user.cpp at the end of imgui.cpp so you can include code that extends ImGui using its private data/functions.
21
-//#define IMGUI_INCLUDE_IMGUI_USER_CPP
20
+//---- Include imgui_user.inl at the end of imgui.cpp so you can include code that extends ImGui using its private data/functions.
21
+//#define IMGUI_INCLUDE_IMGUI_USER_INL
22 22
 
23 23
 //---- Define implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4.
24 24
 /*
@@ -32,7 +32,7 @@
32 32
 */
33 33
 
34 34
 //---- Freely implement extra functions within the ImGui:: namespace.
35
-//---- Declare helpers or widgets implemented in imgui_user.cpp or elsewhere, so end-user doesn't need to include multiple files.
35
+//---- Declare helpers or widgets implemented in imgui_user.inl or elsewhere, so end-user doesn't need to include multiple files.
36 36
 //---- e.g. you can create variants of the ImGui::Value() helper for your low-level math types.
37 37
 /*
38 38
 namespace ImGui

+ 16
- 13
src/deps/imgui/imgui.cpp View File

@@ -138,6 +138,7 @@
138 138
  API BREAKING CHANGES
139 139
  ====================
140 140
 
141
+  - 2014/10/02 (1.14) renamed IMGUI_INCLUDE_IMGUI_USER_CPP to IMGUI_INCLUDE_IMGUI_USER_INL and imgui_user.cpp to imgui_user.inl (more IDE friendly)
141 142
   - 2014/09/25 (1.13) removed 'text_end' parameter from IO.SetClipboardTextFn (the string is now always zero-terminated for simplicity)
142 143
   - 2014/09/24 (1.12) renamed SetFontScale() to SetWindowFontScale()
143 144
   - 2014/09/24 (1.12) moved IM_MALLOC/IM_REALLOC/IM_FREE preprocessor defines to IO.MemAllocFn/IO.MemReallocFn/IO.MemFreeFn
@@ -148,10 +149,10 @@
148 149
  ISSUES & TODO-LIST
149 150
  ==================
150 151
 
151
- - misc: merge ImVec4 / ImGuiAabb, they are essentially duplicate containers
152
+ - misc: merge or clarify ImVec4 / ImGuiAabb, they are essentially duplicate containers
152 153
  - window: autofit is losing its purpose when user relies on any dynamic layout (window width multiplier, column). maybe just discard autofit?
153
- - window: support horizontal scroll
154
- - window: fix resize grip scaling along with Rounding style setting
154
+ - window: add horizontal scroll
155
+ - window: fix resize grip rendering scaling along with Rounding style setting
155 156
  - widgets: switching from "widget-label" to "label-widget" would make it more convenient to integrate widgets in trees
156 157
  - widgets: clip text? hover clipped text shows it in a tooltip or in-place overlay
157 158
  - main: make IsHovered() more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes
@@ -187,6 +188,7 @@
187 188
  - shortcuts: add a shortcut api, e.g. parse "&Save" and/or "Save (CTRL+S)", pass in to widgets or provide simple ways to use (button=activate, input=focus)
188 189
  ! keyboard: tooltip & combo boxes are messing up / not honoring keyboard tabbing
189 190
  - keyboard: full keyboard navigation and focus.
191
+ - input: reowrk IO to be able to pass actual events to fix temporal aliasing issues.
190 192
  - input: support trackpad style scrolling & slider edit.
191 193
  - tooltip: move to fit within screen (e.g. when mouse cursor is right of the screen).
192 194
  - misc: not thread-safe
@@ -327,6 +329,7 @@ ImGuiIO::ImGuiIO()
327 329
     MousePosPrev = ImVec2(-1,-1);
328 330
     MouseDoubleClickTime = 0.30f;
329 331
     MouseDoubleClickMaxDist = 6.0f;
332
+    UserData = NULL;
330 333
 
331 334
     // User functions
332 335
     RenderDrawListsFn = NULL;
@@ -345,7 +348,7 @@ static size_t ImStrlenW(const ImWchar* str);
345 348
 void ImGuiIO::AddInputCharacter(ImWchar c)
346 349
 {
347 350
     const size_t n = ImStrlenW(InputCharacters);
348
-    if (n < sizeof(InputCharacters) / sizeof(InputCharacters[0]))
351
+    if (n + 1 < sizeof(InputCharacters) / sizeof(InputCharacters[0]))
349 352
     {
350 353
         InputCharacters[n] = c;
351 354
         InputCharacters[n+1] = 0;
@@ -395,9 +398,9 @@ static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, const ImVec2& t)
395 398
 static inline float  ImLength(const ImVec2& lhs)                                { return sqrt(lhs.x*lhs.x + lhs.y*lhs.y); }
396 399
 
397 400
 static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int in_char);                                // return output UTF-8 bytes count
398
-static int ImTextStrToUtf8(char* buf, size_t buf_size, const ImWchar* in_text, const ImWchar* in_text_end);   // return output UTF-8 bytes count
401
+static ptrdiff_t ImTextStrToUtf8(char* buf, size_t buf_size, const ImWchar* in_text, const ImWchar* in_text_end);   // return output UTF-8 bytes count
399 402
 static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end);          // return input UTF-8 bytes count
400
-static int ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end);    // return input UTF-8 bytes count
403
+static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end);    // return input UTF-8 bytes count
401 404
 
402 405
 static int ImStricmp(const char* str1, const char* str2)
403 406
 {
@@ -5513,7 +5516,7 @@ static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const
5513 5516
     return 0;
5514 5517
 }
5515 5518
 
5516
-static int ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end)
5519
+static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end)
5517 5520
 {
5518 5521
     ImWchar* buf_out = buf;
5519 5522
     ImWchar* buf_end = buf + buf_size;
@@ -5533,8 +5536,8 @@ static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int c)
5533 5536
 {
5534 5537
     if (c)
5535 5538
     {
5536
-        int i = 0;
5537
-        int n = (size_t)buf_size;
5539
+        size_t i = 0;
5540
+        size_t n = buf_size;
5538 5541
         if (c < 0x80) 
5539 5542
         {
5540 5543
             if (i+1 > n) return 0;
@@ -5573,7 +5576,7 @@ static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int c)
5573 5576
     return 0;
5574 5577
 }
5575 5578
 
5576
-static int ImTextStrToUtf8(char* buf, size_t buf_size, const ImWchar* in_text, const ImWchar* in_text_end)
5579
+static ptrdiff_t ImTextStrToUtf8(char* buf, size_t buf_size, const ImWchar* in_text, const ImWchar* in_text_end)
5577 5580
 {
5578 5581
     char* buf_out = buf;
5579 5582
     const char* buf_end = buf + buf_size;
@@ -6662,9 +6665,9 @@ void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const voi
6662 6665
 
6663 6666
 //-----------------------------------------------------------------------------
6664 6667
 
6665
-//---- Include imgui_user.cpp at the end of imgui.cpp so you can include code that extends ImGui using its private data/functions.
6666
-#ifdef IMGUI_INCLUDE_IMGUI_USER_CPP
6667
-#include "imgui_user.cpp"
6668
+//---- Include imgui_user.inl at the end of imgui.cpp so you can include code that extends ImGui using its private data/functions.
6669
+#ifdef IMGUI_INCLUDE_IMGUI_USER_INL
6670
+#include "imgui_user.inl"
6668 6671
 #endif
6669 6672
 
6670 6673
 //-----------------------------------------------------------------------------

+ 3
- 1
src/deps/imgui/imgui.h View File

@@ -423,6 +423,8 @@ struct ImGuiIO
423 423
     ImWchar     FontFallbackGlyph;          // = '?'                    // Replacement glyph is one isn't found.
424 424
     float       PixelCenterOffset;          // = 0.0f                   // Try to set to 0.5f or 0.375f if rendering is blurry
425 425
 
426
+    void*       UserData;                   // = NULL                   // Store your own data for retrieval by callbacks.
427
+
426 428
     //------------------------------------------------------------------
427 429
     // User Functions
428 430
     //------------------------------------------------------------------
@@ -454,7 +456,7 @@ struct ImGuiIO
454 456
     bool        KeyCtrl;                    // Keyboard modifier pressed: Control
455 457
     bool        KeyShift;                   // Keyboard modifier pressed: Shift
456 458
     bool        KeysDown[512];              // Keyboard keys that are pressed (in whatever order user naturally has access to keyboard data)
457
-    ImWchar     InputCharacters[16];        // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper.
459
+    ImWchar     InputCharacters[16+1];      // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper.
458 460
 
459 461
     // Function
460 462
     void        AddInputCharacter(ImWchar); // Helper to add a new character into InputCharacters[]

+ 7
- 9
src/utils/time.cpp View File

@@ -10,19 +10,17 @@
10 10
 #include "global.h"
11 11
 #include "utils/time.h"
12 12
 
13
-static unsigned long systemTimerStart = 0;
13
+static auto systemTimerStart = std::chrono::steady_clock::now();
14 14
 
15
-unsigned long systemTimerGet() {
15
+or_time_t systemTimerGet() {
16 16
     auto tp = std::chrono::steady_clock::now();
17
-    auto dtn = tp.time_since_epoch();
18
-    return (dtn.count() * 1000 * std::chrono::steady_clock::period::num
19
-            / std::chrono::steady_clock::period::den) - systemTimerStart;
17
+
18
+    return static_cast<or_time_t>(
19
+            std::chrono::duration_cast<std::chrono::milliseconds>
20
+            (tp - systemTimerStart).count());
20 21
 }
21 22
 
22 23
 void systemTimerReset() {
23
-    auto tp = std::chrono::steady_clock::now();
24
-    auto dtn = tp.time_since_epoch();
25
-    systemTimerStart = dtn.count() * 1000 * std::chrono::steady_clock::period::num
26
-            / std::chrono::steady_clock::period::den;
24
+    systemTimerStart = std::chrono::steady_clock::now();
27 25
 }
28 26
 

Loading…
Cancel
Save