Updated ImGui.

This commit is contained in:
Branimir Karadžić 2018-02-12 19:14:59 -08:00
parent 654160d3ee
commit bee9ebc414
2 changed files with 134 additions and 86 deletions

View File

@ -655,6 +655,7 @@
#define IMGUI_DEBUG_NAV_SCORING 0 #define IMGUI_DEBUG_NAV_SCORING 0
#define IMGUI_DEBUG_NAV_RECTS 0 #define IMGUI_DEBUG_NAV_RECTS 0
// Visual Studio warnings
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning (disable: 4127) // condition expression is constant #pragma warning (disable: 4127) // condition expression is constant
#pragma warning (disable: 4201) // nonstandard extension used: nameless struct/union #pragma warning (disable: 4201) // nonstandard extension used: nameless struct/union
@ -685,6 +686,13 @@
#pragma GCC diagnostic ignored "-Wformat-nonliteral" // warning: format not a string literal, format string not checked #pragma GCC diagnostic ignored "-Wformat-nonliteral" // warning: format not a string literal, format string not checked
#endif #endif
// Enforce cdecl calling convention for functions called by the standard library, in case compilation settings changed the default to e.g. __vectorcall
#ifdef _MSC_VER
#define IMGUI_CDECL __cdecl
#else
#define IMGUI_CDECL
#endif
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Forward Declarations // Forward Declarations
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@ -735,6 +743,7 @@ static void NavUpdate();
static void NavUpdateWindowing(); static void NavUpdateWindowing();
static void NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, const ImGuiID id); static void NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, const ImGuiID id);
static void UpdateMovingWindow();
static void UpdateManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4]); static void UpdateManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4]);
static void FocusFrontMostActiveWindow(ImGuiWindow* ignore_window); static void FocusFrontMostActiveWindow(ImGuiWindow* ignore_window);
} }
@ -1507,7 +1516,7 @@ void ImGuiStorage::BuildSortByKey()
{ {
struct StaticFunc struct StaticFunc
{ {
static int PairCompareByID(const void* lhs, const void* rhs) static int IMGUI_CDECL PairCompareByID(const void* lhs, const void* rhs)
{ {
// We can't just do a subtraction because qsort uses signed integers and subtracting our ID doesn't play well with that. // We can't just do a subtraction because qsort uses signed integers and subtracting our ID doesn't play well with that.
if (((const Pair*)lhs)->key > ((const Pair*)rhs)->key) return +1; if (((const Pair*)lhs)->key > ((const Pair*)rhs)->key) return +1;
@ -3222,6 +3231,45 @@ static void ImGui::NavUpdate()
#endif #endif
} }
static void ImGui::UpdateMovingWindow()
{
ImGuiContext& g = *GImGui;
if (g.MovingWindow && g.MovingWindow->MoveId == g.ActiveId && g.ActiveIdSource == ImGuiInputSource_Mouse)
{
// We actually want to move the root window. g.MovingWindow == window we clicked on (could be a child window).
// We track it to preserve Focus and so that ActiveIdWindow == MovingWindow and ActiveId == MovingWindow->MoveId for consistency.
KeepAliveID(g.ActiveId);
IM_ASSERT(g.MovingWindow && g.MovingWindow->RootWindow);
ImGuiWindow* moving_window = g.MovingWindow->RootWindow;
if (g.IO.MouseDown[0])
{
ImVec2 pos = g.IO.MousePos - g.ActiveIdClickOffset;
if (moving_window->PosFloat.x != pos.x || moving_window->PosFloat.y != pos.y)
{
MarkIniSettingsDirty(moving_window);
moving_window->PosFloat = pos;
}
FocusWindow(g.MovingWindow);
}
else
{
ClearActiveID();
g.MovingWindow = NULL;
}
}
else
{
// When clicking/dragging from a window that has the _NoMove flag, we still set the ActiveId in order to prevent hovering others.
if (g.ActiveIdWindow && g.ActiveIdWindow->MoveId == g.ActiveId)
{
KeepAliveID(g.ActiveId);
if (!g.IO.MouseDown[0])
ClearActiveID();
}
g.MovingWindow = NULL;
}
}
void ImGui::NewFrame() void ImGui::NewFrame()
{ {
IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() or ImGui::SetCurrentContext()?"); IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() or ImGui::SetCurrentContext()?");
@ -3350,40 +3398,8 @@ void ImGui::NewFrame()
g.FramerateSecPerFrameIdx = (g.FramerateSecPerFrameIdx + 1) % IM_ARRAYSIZE(g.FramerateSecPerFrame); g.FramerateSecPerFrameIdx = (g.FramerateSecPerFrameIdx + 1) % IM_ARRAYSIZE(g.FramerateSecPerFrame);
g.IO.Framerate = 1.0f / (g.FramerateSecPerFrameAccum / (float)IM_ARRAYSIZE(g.FramerateSecPerFrame)); g.IO.Framerate = 1.0f / (g.FramerateSecPerFrameAccum / (float)IM_ARRAYSIZE(g.FramerateSecPerFrame));
// Handle user moving window with mouse (at the beginning of the frame to avoid input lag or sheering). // Handle user moving window with mouse (at the beginning of the frame to avoid input lag or sheering)
if (g.MovingWindow && g.MovingWindow->MoveId == g.ActiveId && g.ActiveIdSource == ImGuiInputSource_Mouse) UpdateMovingWindow();
{
KeepAliveID(g.ActiveId);
IM_ASSERT(g.MovingWindow && g.MovingWindow->RootWindow);
if (g.IO.MouseDown[0])
{
// MovingWindow = window we clicked on, could be a child window. We track it to preserve Focus and so that ActiveIdWindow == MovingWindow and ActiveId == MovingWindow->MoveId for consistency.
ImGuiWindow* actually_moving_window = g.MovingWindow->RootWindow;
ImVec2 pos = g.IO.MousePos - g.ActiveIdClickOffset;
if (actually_moving_window->PosFloat.x != pos.x || actually_moving_window->PosFloat.y != pos.y)
{
MarkIniSettingsDirty(actually_moving_window);
actually_moving_window->PosFloat = pos;
}
FocusWindow(g.MovingWindow);
}
else
{
ClearActiveID();
g.MovingWindow = NULL;
}
}
else
{
// When clicking/dragging from a window that has the _NoMove flag, we still set the ActiveId in order to prevent hovering others.
if (g.ActiveIdWindow && g.ActiveIdWindow->MoveId == g.ActiveId)
{
KeepAliveID(g.ActiveId);
if (!g.IO.MouseDown[0])
ClearActiveID();
}
g.MovingWindow = NULL;
}
// Delay saving settings so we don't spam disk too much // Delay saving settings so we don't spam disk too much
if (g.SettingsDirtyTimer > 0.0f) if (g.SettingsDirtyTimer > 0.0f)
@ -3796,7 +3812,7 @@ static void MarkIniSettingsDirty(ImGuiWindow* window)
} }
// FIXME: Add a more explicit sort order in the window structure. // FIXME: Add a more explicit sort order in the window structure.
static int ChildWindowComparer(const void* lhs, const void* rhs) static int IMGUI_CDECL ChildWindowComparer(const void* lhs, const void* rhs)
{ {
const ImGuiWindow* a = *(const ImGuiWindow**)lhs; const ImGuiWindow* a = *(const ImGuiWindow**)lhs;
const ImGuiWindow* b = *(const ImGuiWindow**)rhs; const ImGuiWindow* b = *(const ImGuiWindow**)rhs;

View File

@ -1,23 +1,4 @@
#if defined(__GNUC__) || defined(__clang__) // stb_rect_pack.h - v0.11 - public domain - rectangle packing
# if defined(__has_warning)
# define STB_HAS_WARNING __has_warning
# else
# define STB_HAS_WARNING(w) 1
# endif
# if defined(__clang__)
# pragma clang diagnostic ignored "-Wunknown-pragmas"
# endif // defined(__clang__)
# pragma GCC diagnostic ignored "-Wtype-limits"
# pragma GCC diagnostic ignored "-Wunused-function"
# pragma GCC diagnostic ignored "-Wunused-parameter"
# if STB_HAS_WARNING("-Wunused-but-set-variable")
# pragma GCC diagnostic ignored "-Wunused-but-set-variable"
# endif
#else
# pragma warning(disable:4100) // C4100: 'c': unreferenced formal parameter
#endif
// stb_rect_pack.h - v0.08 - public domain - rectangle packing
// Sean Barrett 2014 // Sean Barrett 2014
// //
// Useful for e.g. packing rectangular textures into an atlas. // Useful for e.g. packing rectangular textures into an atlas.
@ -46,11 +27,16 @@
// Sean Barrett // Sean Barrett
// Minor features // Minor features
// Martins Mozeiko // Martins Mozeiko
// github:IntellectualKitty
//
// Bugfixes / warning fixes // Bugfixes / warning fixes
// Jeremy Jaussaud // Jeremy Jaussaud
// //
// Version history: // Version history:
// //
// 0.11 (2017-03-03) return packing success/fail result
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
// 0.09 (2016-08-27) fix compiler warnings
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0) // 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0) // 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort // 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
@ -60,9 +46,7 @@
// //
// LICENSE // LICENSE
// //
// This software is dual-licensed to the public domain and under the following // See end of file for license information.
// license: you are granted a perpetual, irrevocable license to copy, modify,
// publish, and distribute this file as you see fit.
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
@ -94,7 +78,7 @@ typedef int stbrp_coord;
typedef unsigned short stbrp_coord; typedef unsigned short stbrp_coord;
#endif #endif
STBRP_DEF void stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects); STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
// Assign packed locations to rectangles. The rectangles are of type // Assign packed locations to rectangles. The rectangles are of type
// 'stbrp_rect' defined below, stored in the array 'rects', and there // 'stbrp_rect' defined below, stored in the array 'rects', and there
// are 'num_rects' many of them. // are 'num_rects' many of them.
@ -115,6 +99,9 @@ STBRP_DEF void stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int
// arrays will probably produce worse packing results than calling it // arrays will probably produce worse packing results than calling it
// a single time with the full rectangle array, but the option is // a single time with the full rectangle array, but the option is
// available. // available.
//
// The function returns 1 if all of the rectangles were successfully
// packed and 0 otherwise.
struct stbrp_rect struct stbrp_rect
{ {
@ -167,7 +154,7 @@ enum
{ {
STBRP_HEURISTIC_Skyline_default=0, STBRP_HEURISTIC_Skyline_default=0,
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default, STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
STBRP_HEURISTIC_Skyline_BF_sortHeight, STBRP_HEURISTIC_Skyline_BF_sortHeight
}; };
@ -217,9 +204,17 @@ struct stbrp_context
#define STBRP_ASSERT assert #define STBRP_ASSERT assert
#endif #endif
#ifdef _MSC_VER
#define STBRP__NOTUSED(v) (void)(v)
#define STBRP__CDECL __cdecl
#else
#define STBRP__NOTUSED(v) (void)sizeof(v)
#define STBRP__CDECL
#endif
enum enum
{ {
STBRP__INIT_skyline = 1, STBRP__INIT_skyline = 1
}; };
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic) STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
@ -292,6 +287,9 @@ static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0
stbrp_node *node = first; stbrp_node *node = first;
int x1 = x0 + width; int x1 = x0 + width;
int min_y, visited_width, waste_area; int min_y, visited_width, waste_area;
STBRP__NOTUSED(c);
STBRP_ASSERT(first->x <= x0); STBRP_ASSERT(first->x <= x0);
#if 0 #if 0
@ -496,17 +494,14 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i
STBRP_ASSERT(cur->next == NULL); STBRP_ASSERT(cur->next == NULL);
{ {
stbrp_node *L1 = NULL, *L2 = NULL;
int count=0; int count=0;
cur = context->active_head; cur = context->active_head;
while (cur) { while (cur) {
L1 = cur;
cur = cur->next; cur = cur->next;
++count; ++count;
} }
cur = context->free_head; cur = context->free_head;
while (cur) { while (cur) {
L2 = cur;
cur = cur->next; cur = cur->next;
++count; ++count;
} }
@ -517,10 +512,10 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i
return res; return res;
} }
static int rect_height_compare(const void *a, const void *b) static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
{ {
stbrp_rect *p = (stbrp_rect *) a; const stbrp_rect *p = (const stbrp_rect *) a;
stbrp_rect *q = (stbrp_rect *) b; const stbrp_rect *q = (const stbrp_rect *) b;
if (p->h > q->h) if (p->h > q->h)
return -1; return -1;
if (p->h < q->h) if (p->h < q->h)
@ -528,21 +523,10 @@ static int rect_height_compare(const void *a, const void *b)
return (p->w > q->w) ? -1 : (p->w < q->w); return (p->w > q->w) ? -1 : (p->w < q->w);
} }
static int rect_width_compare(const void *a, const void *b) static int STBRP__CDECL rect_original_order(const void *a, const void *b)
{ {
stbrp_rect *p = (stbrp_rect *) a; const stbrp_rect *p = (const stbrp_rect *) a;
stbrp_rect *q = (stbrp_rect *) b; const stbrp_rect *q = (const stbrp_rect *) b;
if (p->w > q->w)
return -1;
if (p->w < q->w)
return 1;
return (p->h > q->h) ? -1 : (p->h < q->h);
}
static int rect_original_order(const void *a, const void *b)
{
stbrp_rect *p = (stbrp_rect *) a;
stbrp_rect *q = (stbrp_rect *) b;
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed); return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
} }
@ -552,9 +536,9 @@ static int rect_original_order(const void *a, const void *b)
#define STBRP__MAXVAL 0xffff #define STBRP__MAXVAL 0xffff
#endif #endif
STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects) STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
{ {
int i; int i, all_rects_packed = 1;
// we use the 'was_packed' field internally to allow sorting/unsorting // we use the 'was_packed' field internally to allow sorting/unsorting
for (i=0; i < num_rects; ++i) { for (i=0; i < num_rects; ++i) {
@ -584,8 +568,56 @@ STBRP_DEF void stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int n
// unsort // unsort
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order); STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
// set was_packed flags // set was_packed flags and all_rects_packed status
for (i=0; i < num_rects; ++i) for (i=0; i < num_rects; ++i) {
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL); rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
if (!rects[i].was_packed)
all_rects_packed = 0;
}
// return the all_rects_packed status
return all_rects_packed;
} }
#endif #endif
/*
------------------------------------------------------------------------------
This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2017 Sean Barrett
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
------------------------------------------------------------------------------
ALTERNATIVE B - Public Domain (www.unlicense.org)
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------
*/