Skip to content

Commit 3658314

Browse files
committed
imgui_demo.cpp doesn't redefine functions from imgui_internal.h so all files can be unity-built (#219)
1 parent 815d1d9 commit 3658314

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

imgui_demo.cpp

+13-18
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,8 @@
3434
#define IM_NEWLINE "\n"
3535
#endif
3636

37-
//-----------------------------------------------------------------------------
38-
// HELPERS
39-
// (We don't use imgui_internal.h here to make the demo code more trivially portable)
40-
//-----------------------------------------------------------------------------
41-
4237
#define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR)))
4338

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-
4939
//-----------------------------------------------------------------------------
5040
// DEMO CODE
5141
//-----------------------------------------------------------------------------
@@ -449,8 +439,8 @@ void ImGui::ShowTestWindow(bool* opened)
449439
{
450440
ImGui::BeginTooltip();
451441
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;
454444
ImGui::Text("Min: (%.2f, %.2f)", focus_x, focus_y);
455445
ImGui::Text("Max: (%.2f, %.2f)", focus_x + focus_sz, focus_y + focus_sz);
456446
ImVec2 uv0 = ImVec2((focus_x) / tex_w, (focus_y) / tex_h);
@@ -1640,7 +1630,9 @@ static void ShowExampleAppCustomRendering(bool* opened)
16401630
// However you can draw directly and poll mouse/keyboard by yourself. You can manipulate the cursor using GetCursorPos() and SetCursorPos().
16411631
// If you only use the ImDrawList API, you can notify the owner window of its extends by using SetCursorPos(max).
16421632
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;
16441636
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));
16451637
draw_list->AddRect(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), ImColor(255,255,255));
16461638
bool adding_preview = false;
@@ -1795,14 +1787,17 @@ struct ExampleAppConsole
17951787
ImGui::End();
17961788
}
17971789

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+
17981793
void ExecCommand(const char* command_line)
17991794
{
18001795
AddLog("# %s\n", command_line);
18011796

18021797
// 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.
18031798
HistoryPos = -1;
18041799
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)
18061801
{
18071802
free(History[i]);
18081803
History.erase(History.begin() + i);
@@ -1811,17 +1806,17 @@ struct ExampleAppConsole
18111806
History.push_back(strdup(command_line));
18121807

18131808
// Process command
1814-
if (ImStricmp(command_line, "CLEAR") == 0)
1809+
if (Stricmp(command_line, "CLEAR") == 0)
18151810
{
18161811
ClearLog();
18171812
}
1818-
else if (ImStricmp(command_line, "HELP") == 0)
1813+
else if (Stricmp(command_line, "HELP") == 0)
18191814
{
18201815
AddLog("Commands:");
18211816
for (int i = 0; i < Commands.Size; i++)
18221817
AddLog("- %s", Commands[i]);
18231818
}
1824-
else if (ImStricmp(command_line, "HISTORY") == 0)
1819+
else if (Stricmp(command_line, "HISTORY") == 0)
18251820
{
18261821
for (int i = History.Size >= 10 ? History.Size - 10 : 0; i < History.Size; i++)
18271822
AddLog("%3d: %s\n", i, History[i]);
@@ -1861,7 +1856,7 @@ struct ExampleAppConsole
18611856
// Build a list of candidates
18621857
ImVector<const char*> candidates;
18631858
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)
18651860
candidates.push_back(Commands[i]);
18661861

18671862
if (candidates.Size == 0)

0 commit comments

Comments
 (0)