34
34
#define IM_NEWLINE " \n "
35
35
#endif
36
36
37
- // -----------------------------------------------------------------------------
38
- // HELPERS
39
- // (We don't use imgui_internal.h here to make the demo code more trivially portable)
40
- // -----------------------------------------------------------------------------
41
-
42
37
#define IM_ARRAYSIZE (_ARR ) ((int )(sizeof (_ARR)/sizeof (*_ARR)))
43
38
44
- static inline float ImMax (float lhs, float rhs) { return lhs >= rhs ? lhs : rhs; }
45
- static inline float ImClamp (float v, float mn, float mx) { return (v < mn) ? mn : (v > mx) ? mx : v; }
46
- static int ImStricmp (const char * str1, const char * str2) { int d; while ((d = toupper (*str2) - toupper (*str1)) == 0 && *str1) { str1++; str2++; } return d; }
47
- static int ImStrnicmp (const char * str1, const char * str2, int count) { int d = 0 ; while (count > 0 && (d = toupper (*str2) - toupper (*str1)) == 0 && *str1) { str1++; str2++; count--; } return d; }
48
-
49
39
// -----------------------------------------------------------------------------
50
40
// DEMO CODE
51
41
// -----------------------------------------------------------------------------
@@ -449,8 +439,8 @@ void ImGui::ShowTestWindow(bool* opened)
449
439
{
450
440
ImGui::BeginTooltip ();
451
441
float focus_sz = 32 .0f ;
452
- float focus_x = ImClamp ( ImGui::GetMousePos ().x - tex_screen_pos.x - focus_sz * 0 .5f , 0 .0f , tex_w - focus_sz);
453
- float focus_y = ImClamp ( ImGui::GetMousePos ().y - tex_screen_pos.y - focus_sz * 0 .5f , 0 .0f , tex_h - focus_sz);
442
+ float focus_x = ImGui::GetMousePos ().x - tex_screen_pos.x - focus_sz * 0 .5f ; if (focus_x < 0 .0f ) focus_x = 0 . 0f ; else if (focus_x > tex_w - focus_sz) focus_x = tex_w - focus_sz ;
443
+ float focus_y = ImGui::GetMousePos ().y - tex_screen_pos.y - focus_sz * 0 .5f ; if (focus_y < 0 .0f ) focus_y = 0 . 0f ; else if (focus_y > tex_h - focus_sz) focus_y = tex_h - focus_sz ;
454
444
ImGui::Text (" Min: (%.2f, %.2f)" , focus_x, focus_y);
455
445
ImGui::Text (" Max: (%.2f, %.2f)" , focus_x + focus_sz, focus_y + focus_sz);
456
446
ImVec2 uv0 = ImVec2 ((focus_x) / tex_w, (focus_y) / tex_h);
@@ -1640,7 +1630,9 @@ static void ShowExampleAppCustomRendering(bool* opened)
1640
1630
// However you can draw directly and poll mouse/keyboard by yourself. You can manipulate the cursor using GetCursorPos() and SetCursorPos().
1641
1631
// If you only use the ImDrawList API, you can notify the owner window of its extends by using SetCursorPos(max).
1642
1632
ImVec2 canvas_pos = ImGui::GetCursorScreenPos (); // ImDrawList API uses screen coordinates!
1643
- ImVec2 canvas_size = ImVec2 (ImMax (50 .0f ,ImGui::GetWindowContentRegionMax ().x -ImGui::GetCursorPos ().x ), ImMax (50 .0f ,ImGui::GetWindowContentRegionMax ().y -ImGui::GetCursorPos ().y )); // Resize canvas what's available
1633
+ ImVec2 canvas_size = ImVec2 (ImGui::GetContentRegionMax ().x -ImGui::GetCursorPos ().x , ImGui::GetContentRegionMax ().y -ImGui::GetCursorPos ().y ); // Resize canvas what's available
1634
+ if (canvas_size.x < 50 .0f ) canvas_size.x = 50 .0f ;
1635
+ if (canvas_size.y < 50 .0f ) canvas_size.y = 50 .0f ;
1644
1636
draw_list->AddRectFilledMultiColor (canvas_pos, ImVec2 (canvas_pos.x + canvas_size.x , canvas_pos.y + canvas_size.y ), ImColor (0 ,0 ,0 ), ImColor (255 ,0 ,0 ), ImColor (255 ,255 ,0 ), ImColor (0 ,255 ,0 ));
1645
1637
draw_list->AddRect (canvas_pos, ImVec2 (canvas_pos.x + canvas_size.x , canvas_pos.y + canvas_size.y ), ImColor (255 ,255 ,255 ));
1646
1638
bool adding_preview = false ;
@@ -1795,14 +1787,17 @@ struct ExampleAppConsole
1795
1787
ImGui::End ();
1796
1788
}
1797
1789
1790
+ static int Stricmp (const char * str1, const char * str2) { int d; while ((d = toupper (*str2) - toupper (*str1)) == 0 && *str1) { str1++; str2++; } return d; }
1791
+ static int Strnicmp (const char * str1, const char * str2, int count) { int d = 0 ; while (count > 0 && (d = toupper (*str2) - toupper (*str1)) == 0 && *str1) { str1++; str2++; count--; } return d; }
1792
+
1798
1793
void ExecCommand (const char * command_line)
1799
1794
{
1800
1795
AddLog (" # %s\n " , command_line);
1801
1796
1802
1797
// Insert into history. First find match and delete it so it can be pushed to the back. This isn't trying to be smart or optimal.
1803
1798
HistoryPos = -1 ;
1804
1799
for (int i = History.Size -1 ; i >= 0 ; i--)
1805
- if (ImStricmp (History[i], command_line) == 0 )
1800
+ if (Stricmp (History[i], command_line) == 0 )
1806
1801
{
1807
1802
free (History[i]);
1808
1803
History.erase (History.begin () + i);
@@ -1811,17 +1806,17 @@ struct ExampleAppConsole
1811
1806
History.push_back (strdup (command_line));
1812
1807
1813
1808
// Process command
1814
- if (ImStricmp (command_line, " CLEAR" ) == 0 )
1809
+ if (Stricmp (command_line, " CLEAR" ) == 0 )
1815
1810
{
1816
1811
ClearLog ();
1817
1812
}
1818
- else if (ImStricmp (command_line, " HELP" ) == 0 )
1813
+ else if (Stricmp (command_line, " HELP" ) == 0 )
1819
1814
{
1820
1815
AddLog (" Commands:" );
1821
1816
for (int i = 0 ; i < Commands.Size ; i++)
1822
1817
AddLog (" - %s" , Commands[i]);
1823
1818
}
1824
- else if (ImStricmp (command_line, " HISTORY" ) == 0 )
1819
+ else if (Stricmp (command_line, " HISTORY" ) == 0 )
1825
1820
{
1826
1821
for (int i = History.Size >= 10 ? History.Size - 10 : 0 ; i < History.Size ; i++)
1827
1822
AddLog (" %3d: %s\n " , i, History[i]);
@@ -1861,7 +1856,7 @@ struct ExampleAppConsole
1861
1856
// Build a list of candidates
1862
1857
ImVector<const char *> candidates;
1863
1858
for (int i = 0 ; i < Commands.Size ; i++)
1864
- if (ImStrnicmp (Commands[i], word_start, (int )(word_end-word_start)) == 0 )
1859
+ if (Strnicmp (Commands[i], word_start, (int )(word_end-word_start)) == 0 )
1865
1860
candidates.push_back (Commands[i]);
1866
1861
1867
1862
if (candidates.Size == 0 )
0 commit comments