mirror of https://github.com/bkaradzic/bgfx
Updated ImGui.
This commit is contained in:
parent
7f039cad3c
commit
bd2bbc84ed
|
@ -3,7 +3,7 @@
|
|||
|
||||
// See imgui.cpp file for documentation.
|
||||
// Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code.
|
||||
// Newcomers, read 'Programmer guide' below for notes on how to setup Dear ImGui in your codebase.
|
||||
// Newcomers, read 'Programmer guide' in imgui.cpp for notes on how to setup Dear ImGui in your codebase.
|
||||
// Get latest version at https://github.com/ocornut/imgui
|
||||
|
||||
/*
|
||||
|
@ -26,7 +26,7 @@ Index of this file:
|
|||
|
||||
#pragma once
|
||||
|
||||
// Configuration file (edit imconfig.h or define IMGUI_USER_CONFIG to your own filename)
|
||||
// Configuration file with compile-time options (edit imconfig.h or define IMGUI_USER_CONFIG to your own filename)
|
||||
#ifdef IMGUI_USER_CONFIG
|
||||
#include IMGUI_USER_CONFIG
|
||||
#endif
|
||||
|
@ -44,7 +44,7 @@ Index of this file:
|
|||
#include <string.h> // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp
|
||||
|
||||
// Version
|
||||
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY00 then bounced up to XYY01 when release tagging happens)
|
||||
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens)
|
||||
#define IMGUI_VERSION "1.69 WIP"
|
||||
#define IMGUI_VERSION_NUM 16899
|
||||
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert))
|
||||
|
@ -151,6 +151,10 @@ typedef int (*ImGuiInputTextCallback)(ImGuiInputTextCallbackData *data);
|
|||
typedef void (*ImGuiSizeCallback)(ImGuiSizeCallbackData* data);
|
||||
|
||||
// Scalar data types
|
||||
typedef char ImS8; // 8-bit signed integer == char
|
||||
typedef unsigned char ImU8; // 8-bit unsigned integer
|
||||
typedef short ImS16; // 16-bit signed integer
|
||||
typedef unsigned short ImU16; // 16-bit unsigned integer
|
||||
typedef signed int ImS32; // 32-bit signed integer == int
|
||||
typedef unsigned int ImU32; // 32-bit unsigned integer (often used to store packed colors)
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
|
@ -216,12 +220,12 @@ namespace ImGui
|
|||
// Demo, Debug, Information
|
||||
IMGUI_API void ShowDemoWindow(bool* p_open = NULL); // create demo/test window (previously called ShowTestWindow). demonstrate most ImGui features. call this to learn about the library! try to make it always available in your application!
|
||||
IMGUI_API void ShowAboutWindow(bool* p_open = NULL); // create about window. display Dear ImGui version, credits and build/system information.
|
||||
IMGUI_API void ShowMetricsWindow(bool* p_open = NULL); // create metrics window. display Dear ImGui internals: draw commands (with individual draw calls and vertices), window list, basic internal state, etc.
|
||||
IMGUI_API void ShowMetricsWindow(bool* p_open = NULL); // create metrics/debug window. display Dear ImGui internals: draw commands (with individual draw calls and vertices), window list, basic internal state, etc.
|
||||
IMGUI_API void ShowStyleEditor(ImGuiStyle* ref = NULL); // add style editor block (not a window). you can pass in a reference ImGuiStyle structure to compare to, revert to and save to (else it uses the default style)
|
||||
IMGUI_API bool ShowStyleSelector(const char* label); // add style selector block (not a window), essentially a combo listing the default styles.
|
||||
IMGUI_API void ShowFontSelector(const char* label); // add font selector block (not a window), essentially a combo listing the loaded fonts.
|
||||
IMGUI_API void ShowUserGuide(); // add basic help/info block (not a window): how to manipulate ImGui as a end-user (mouse/keyboard controls).
|
||||
IMGUI_API const char* GetVersion(); // get the compiled version string e.g. "1.23"
|
||||
IMGUI_API const char* GetVersion(); // get the compiled version string e.g. "1.23" (essentially the compiled value for IMGUI_VERSION)
|
||||
|
||||
// Styles
|
||||
IMGUI_API void StyleColorsDark(ImGuiStyle* dst = NULL); // new, recommended style (default)
|
||||
|
@ -386,7 +390,7 @@ namespace ImGui
|
|||
// - Most widgets return true when the value has been changed or when pressed/selected
|
||||
IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0)); // button
|
||||
IMGUI_API bool SmallButton(const char* label); // button with FramePadding=(0,0) to easily embed within text
|
||||
IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size); // button behavior without the visuals, useful to build custom behaviors using the public api (along with IsItemActive, IsItemHovered, etc.)
|
||||
IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size); // button behavior without the visuals, frequently useful to build custom behaviors using the public api (along with IsItemActive, IsItemHovered, etc.)
|
||||
IMGUI_API bool ArrowButton(const char* str_id, ImGuiDir dir); // square button with an arrow shape
|
||||
IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0));
|
||||
IMGUI_API bool ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,0), const ImVec4& tint_col = ImVec4(1,1,1,1)); // <0 frame_padding uses default frame padding settings. 0 for no padding
|
||||
|
@ -583,7 +587,7 @@ namespace ImGui
|
|||
// Drag and Drop
|
||||
// [BETA API] API may evolve!
|
||||
IMGUI_API bool BeginDragDropSource(ImGuiDragDropFlags flags = 0); // call when the current item is active. If this return true, you can call SetDragDropPayload() + EndDragDropSource()
|
||||
IMGUI_API bool SetDragDropPayload(const char* type, const void* data, size_t size, ImGuiCond cond = 0);// type is a user defined string of maximum 32 characters. Strings starting with '_' are reserved for dear imgui internal types. Data is copied and held by imgui.
|
||||
IMGUI_API bool SetDragDropPayload(const char* type, const void* data, size_t sz, ImGuiCond cond = 0); // type is a user defined string of maximum 32 characters. Strings starting with '_' are reserved for dear imgui internal types. Data is copied and held by imgui.
|
||||
IMGUI_API void EndDragDropSource(); // only call EndDragDropSource() if BeginDragDropSource() returns true!
|
||||
IMGUI_API bool BeginDragDropTarget(); // call after submitting an item that may receive a payload. If this returns true, you can call AcceptDragDropPayload() + EndDragDropTarget()
|
||||
IMGUI_API const ImGuiPayload* AcceptDragDropPayload(const char* type, ImGuiDragDropFlags flags = 0); // accept contents of a given type. If ImGuiDragDropFlags_AcceptBeforeDelivery is set you can peek into the payload before the mouse button is released.
|
||||
|
@ -611,9 +615,9 @@ namespace ImGui
|
|||
IMGUI_API bool IsItemActivated(); // was the last item just made active (item was previously inactive).
|
||||
IMGUI_API bool IsItemDeactivated(); // was the last item just made inactive (item was previously active). Useful for Undo/Redo patterns with widgets that requires continuous editing.
|
||||
IMGUI_API bool IsItemDeactivatedAfterEdit(); // was the last item just made inactive and made a value change when it was active? (e.g. Slider/Drag moved). Useful for Undo/Redo patterns with widgets that requires continuous editing. Note that you may get false positives (some widgets such as Combo()/ListBox()/Selectable() will return true even when clicking an already selected item).
|
||||
IMGUI_API bool IsAnyItemHovered();
|
||||
IMGUI_API bool IsAnyItemActive();
|
||||
IMGUI_API bool IsAnyItemFocused();
|
||||
IMGUI_API bool IsAnyItemHovered(); // is any item hovered?
|
||||
IMGUI_API bool IsAnyItemActive(); // is any item active?
|
||||
IMGUI_API bool IsAnyItemFocused(); // is any item focused?
|
||||
IMGUI_API ImVec2 GetItemRectMin(); // get upper-left bounding rectangle of the last item (screen space)
|
||||
IMGUI_API ImVec2 GetItemRectMax(); // get lower-right bounding rectangle of the last item (screen space)
|
||||
IMGUI_API ImVec2 GetItemRectSize(); // get size of last item
|
||||
|
@ -625,8 +629,8 @@ namespace ImGui
|
|||
IMGUI_API double GetTime(); // get global imgui time. incremented by io.DeltaTime every frame.
|
||||
IMGUI_API int GetFrameCount(); // get global imgui frame count. incremented by 1 every frame.
|
||||
IMGUI_API ImDrawList* GetOverlayDrawList(); // this draw list will be the last rendered one, useful to quickly draw overlays shapes/text
|
||||
IMGUI_API ImDrawListSharedData* GetDrawListSharedData(); // you may use this when creating your own ImDrawList instances
|
||||
IMGUI_API const char* GetStyleColorName(ImGuiCol idx);
|
||||
IMGUI_API ImDrawListSharedData* GetDrawListSharedData(); // you may use this when creating your own ImDrawList instances.
|
||||
IMGUI_API const char* GetStyleColorName(ImGuiCol idx); // get a string corresponding to the enum value (for display, saving, etc.).
|
||||
IMGUI_API void SetStateStorage(ImGuiStorage* storage); // replace current window storage with our own (if you want to manipulate it yourself, typically clear subsection of it)
|
||||
IMGUI_API ImGuiStorage* GetStateStorage();
|
||||
IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f);
|
||||
|
@ -653,7 +657,7 @@ namespace ImGui
|
|||
IMGUI_API bool IsMouseReleased(int button); // did mouse button released (went from Down to !Down)
|
||||
IMGUI_API bool IsMouseDragging(int button = 0, float lock_threshold = -1.0f); // is mouse dragging. if lock_threshold < -1.0f uses io.MouseDraggingThreshold
|
||||
IMGUI_API bool IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip = true); // is mouse hovering given bounding rect (in screen space). clipped by current clipping settings, but disregarding of other consideration of focus/window ordering/popup-block.
|
||||
IMGUI_API bool IsMousePosValid(const ImVec2* mouse_pos = NULL); //
|
||||
IMGUI_API bool IsMousePosValid(const ImVec2* mouse_pos = NULL); // by convention we use (-FLT_MAX,-FLT_MAX) to denote that there is no mouse
|
||||
IMGUI_API ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls
|
||||
IMGUI_API ImVec2 GetMousePosOnOpeningCurrentPopup(); // retrieve backup of mouse position at the time of opening popup we have BeginPopup() into
|
||||
IMGUI_API ImVec2 GetMouseDragDelta(int button = 0, float lock_threshold = -1.0f); // return the delta from the initial clicking position. This is locked and return 0.0f until the mouse moves past a distance threshold at least once. If lock_threshold < -1.0f uses io.MouseDraggingThreshold
|
||||
|
@ -672,12 +676,12 @@ namespace ImGui
|
|||
// - Set io.IniFilename to NULL to load/save manually. Read io.WantSaveIniSettings description about handling .ini saving manually.
|
||||
IMGUI_API void LoadIniSettingsFromDisk(const char* ini_filename); // call after CreateContext() and before the first call to NewFrame(). NewFrame() automatically calls LoadIniSettingsFromDisk(io.IniFilename).
|
||||
IMGUI_API void LoadIniSettingsFromMemory(const char* ini_data, size_t ini_size=0); // call after CreateContext() and before the first call to NewFrame() to provide .ini data from your own data source.
|
||||
IMGUI_API void SaveIniSettingsToDisk(const char* ini_filename);
|
||||
IMGUI_API void SaveIniSettingsToDisk(const char* ini_filename); // this is automatically called (if io.IniFilename is not empty) a few seconds after any modification that should be reflected in the .ini file (and also by DestroyContext).
|
||||
IMGUI_API const char* SaveIniSettingsToMemory(size_t* out_ini_size = NULL); // return a zero-terminated string with the .ini data which you can save by your own mean. call when io.WantSaveIniSettings is set, then save data by your own mean and clear io.WantSaveIniSettings.
|
||||
|
||||
// Memory Utilities
|
||||
// Memory Allocators
|
||||
// - All those functions are not reliant on the current context.
|
||||
// - If you reload the contents of imgui.cpp at runtime, you may need to call SetCurrentContext() + SetAllocatorFunctions() again.
|
||||
// - If you reload the contents of imgui.cpp at runtime, you may need to call SetCurrentContext() + SetAllocatorFunctions() again because we use global storage for those.
|
||||
IMGUI_API void SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* user_data), void (*free_func)(void* ptr, void* user_data), void* user_data = NULL);
|
||||
IMGUI_API void* MemAlloc(size_t size);
|
||||
IMGUI_API void MemFree(void* ptr);
|
||||
|
@ -738,7 +742,7 @@ enum ImGuiInputTextFlags_
|
|||
ImGuiInputTextFlags_CharsUppercase = 1 << 2, // Turn a..z into A..Z
|
||||
ImGuiInputTextFlags_CharsNoBlank = 1 << 3, // Filter out spaces, tabs
|
||||
ImGuiInputTextFlags_AutoSelectAll = 1 << 4, // Select entire text when first taking mouse focus
|
||||
ImGuiInputTextFlags_EnterReturnsTrue = 1 << 5, // Return 'true' when Enter is pressed (as opposed to when the value was modified)
|
||||
ImGuiInputTextFlags_EnterReturnsTrue = 1 << 5, // Return 'true' when Enter is pressed (as opposed to every time the value was modified). Consider looking at the IsItemDeactivatedAfterEdit() function.
|
||||
ImGuiInputTextFlags_CallbackCompletion = 1 << 6, // Callback on pressing TAB (for completion handling)
|
||||
ImGuiInputTextFlags_CallbackHistory = 1 << 7, // Callback on pressing Up/Down arrows (for history handling)
|
||||
ImGuiInputTextFlags_CallbackAlways = 1 << 8, // Callback on each iteration. User code may query cursor position, modify text buffer.
|
||||
|
@ -885,10 +889,14 @@ enum ImGuiDragDropFlags_
|
|||
// A primary data type
|
||||
enum ImGuiDataType_
|
||||
{
|
||||
ImGuiDataType_S8, // char
|
||||
ImGuiDataType_U8, // unsigned char
|
||||
ImGuiDataType_S16, // short
|
||||
ImGuiDataType_U16, // unsigned short
|
||||
ImGuiDataType_S32, // int
|
||||
ImGuiDataType_U32, // unsigned int
|
||||
ImGuiDataType_S64, // long long, __int64
|
||||
ImGuiDataType_U64, // unsigned long long, unsigned __int64
|
||||
ImGuiDataType_S64, // long long / __int64
|
||||
ImGuiDataType_U64, // unsigned long long / unsigned __int64
|
||||
ImGuiDataType_Float, // float
|
||||
ImGuiDataType_Double, // double
|
||||
ImGuiDataType_COUNT
|
||||
|
@ -1060,7 +1068,7 @@ enum ImGuiCol_
|
|||
// NB: if changing this enum, you need to update the associated internal table GStyleVarInfo[] accordingly. This is where we link enum values to members offset/type.
|
||||
enum ImGuiStyleVar_
|
||||
{
|
||||
// Enum name ......................// Member in ImGuiStyle structure (see ImGuiStyle for descriptions)
|
||||
// Enum name --------------------- // Member in ImGuiStyle structure (see ImGuiStyle for descriptions)
|
||||
ImGuiStyleVar_Alpha, // float Alpha
|
||||
ImGuiStyleVar_WindowPadding, // ImVec2 WindowPadding
|
||||
ImGuiStyleVar_WindowRounding, // float WindowRounding
|
||||
|
|
|
@ -1198,6 +1198,10 @@ static void ShowDemoWindowWidgets()
|
|||
ImS64 LLONG_MAX = 9223372036854775807LL;
|
||||
ImU64 ULLONG_MAX = (2ULL * 9223372036854775807LL + 1);
|
||||
#endif
|
||||
const char s8_zero = 0, s8_one = 1, s8_fifty = 50, s8_min = -128, s8_max = 127;
|
||||
const ImU8 u8_zero = 0, u8_one = 1, u8_fifty = 50, u8_min = 0, u8_max = 255;
|
||||
const short s16_zero = 0, s16_one = 1, s16_fifty = 50, s16_min = -32768, s16_max = 32767;
|
||||
const ImU16 u16_zero = 0, u16_one = 1, u16_fifty = 50, u16_min = 0, u16_max = 65535;
|
||||
const ImS32 s32_zero = 0, s32_one = 1, s32_fifty = 50, s32_min = INT_MIN/2, s32_max = INT_MAX/2, s32_hi_a = INT_MAX/2 - 100, s32_hi_b = INT_MAX/2;
|
||||
const ImU32 u32_zero = 0, u32_one = 1, u32_fifty = 50, u32_min = 0, u32_max = UINT_MAX/2, u32_hi_a = UINT_MAX/2 - 100, u32_hi_b = UINT_MAX/2;
|
||||
const ImS64 s64_zero = 0, s64_one = 1, s64_fifty = 50, s64_min = LLONG_MIN/2, s64_max = LLONG_MAX/2, s64_hi_a = LLONG_MAX/2 - 100, s64_hi_b = LLONG_MAX/2;
|
||||
|
@ -1206,6 +1210,10 @@ static void ShowDemoWindowWidgets()
|
|||
const double f64_zero = 0., f64_one = 1., f64_lo_a = -1000000000000000.0, f64_hi_a = +1000000000000000.0;
|
||||
|
||||
// State
|
||||
static char s8_v = 127;
|
||||
static ImU8 u8_v = 255;
|
||||
static short s16_v = 32767;
|
||||
static ImU16 u16_v = 65535;
|
||||
static ImS32 s32_v = -1;
|
||||
static ImU32 u32_v = (ImU32)-1;
|
||||
static ImS64 s64_v = -1;
|
||||
|
@ -1217,6 +1225,10 @@ static void ShowDemoWindowWidgets()
|
|||
static bool drag_clamp = false;
|
||||
ImGui::Text("Drags:");
|
||||
ImGui::Checkbox("Clamp integers to 0..50", &drag_clamp); ImGui::SameLine(); ShowHelpMarker("As with every widgets in dear imgui, we never modify values unless there is a user interaction.\nYou can override the clamping limits by using CTRL+Click to input a value.");
|
||||
ImGui::DragScalar("drag s8", ImGuiDataType_S8, &s8_v, drag_speed, drag_clamp ? &s8_zero : NULL, drag_clamp ? &s8_fifty : NULL);
|
||||
ImGui::DragScalar("drag u8", ImGuiDataType_U8, &u8_v, drag_speed, drag_clamp ? &u8_zero : NULL, drag_clamp ? &u8_fifty : NULL, "%u ms");
|
||||
ImGui::DragScalar("drag s16", ImGuiDataType_S16, &s16_v, drag_speed, drag_clamp ? &s16_zero : NULL, drag_clamp ? &s16_fifty : NULL);
|
||||
ImGui::DragScalar("drag u16", ImGuiDataType_U16, &u16_v, drag_speed, drag_clamp ? &u16_zero : NULL, drag_clamp ? &u16_fifty : NULL, "%u ms");
|
||||
ImGui::DragScalar("drag s32", ImGuiDataType_S32, &s32_v, drag_speed, drag_clamp ? &s32_zero : NULL, drag_clamp ? &s32_fifty : NULL);
|
||||
ImGui::DragScalar("drag u32", ImGuiDataType_U32, &u32_v, drag_speed, drag_clamp ? &u32_zero : NULL, drag_clamp ? &u32_fifty : NULL, "%u ms");
|
||||
ImGui::DragScalar("drag s64", ImGuiDataType_S64, &s64_v, drag_speed, drag_clamp ? &s64_zero : NULL, drag_clamp ? &s64_fifty : NULL);
|
||||
|
@ -1227,6 +1239,10 @@ static void ShowDemoWindowWidgets()
|
|||
ImGui::DragScalar("drag double ^2", ImGuiDataType_Double, &f64_v, 0.0005f, &f64_zero, &f64_one, "0 < %.10f < 1", 2.0f);
|
||||
|
||||
ImGui::Text("Sliders");
|
||||
ImGui::SliderScalar("slider s8 full", ImGuiDataType_S8, &s8_v, &s8_min, &s8_max, "%d");
|
||||
ImGui::SliderScalar("slider u8 full", ImGuiDataType_U8, &u8_v, &u8_min, &u8_max, "%u");
|
||||
ImGui::SliderScalar("slider s16 full", ImGuiDataType_S16, &s16_v, &s16_min, &s16_max, "%d");
|
||||
ImGui::SliderScalar("slider u16 full", ImGuiDataType_U16, &u16_v, &u16_min, &u16_max, "%u");
|
||||
ImGui::SliderScalar("slider s32 low", ImGuiDataType_S32, &s32_v, &s32_zero, &s32_fifty,"%d");
|
||||
ImGui::SliderScalar("slider s32 high", ImGuiDataType_S32, &s32_v, &s32_hi_a, &s32_hi_b, "%d");
|
||||
ImGui::SliderScalar("slider s32 full", ImGuiDataType_S32, &s32_v, &s32_min, &s32_max, "%d");
|
||||
|
@ -1249,6 +1265,10 @@ static void ShowDemoWindowWidgets()
|
|||
static bool inputs_step = true;
|
||||
ImGui::Text("Inputs");
|
||||
ImGui::Checkbox("Show step buttons", &inputs_step);
|
||||
ImGui::InputScalar("input s8", ImGuiDataType_S8, &s8_v, inputs_step ? &s8_one : NULL, NULL, "%d");
|
||||
ImGui::InputScalar("input u8", ImGuiDataType_U8, &u8_v, inputs_step ? &u8_one : NULL, NULL, "%u");
|
||||
ImGui::InputScalar("input s16", ImGuiDataType_S16, &s16_v, inputs_step ? &s16_one : NULL, NULL, "%d");
|
||||
ImGui::InputScalar("input u16", ImGuiDataType_U16, &u16_v, inputs_step ? &u16_one : NULL, NULL, "%u");
|
||||
ImGui::InputScalar("input s32", ImGuiDataType_S32, &s32_v, inputs_step ? &s32_one : NULL, NULL, "%d");
|
||||
ImGui::InputScalar("input s32 hex", ImGuiDataType_S32, &s32_v, inputs_step ? &s32_one : NULL, NULL, "%08X", ImGuiInputTextFlags_CharsHexadecimal);
|
||||
ImGui::InputScalar("input u32", ImGuiDataType_U32, &u32_v, inputs_step ? &u32_one : NULL, NULL, "%u");
|
||||
|
|
|
@ -225,12 +225,15 @@ static inline double ImAtof(const char* s)
|
|||
static inline float ImFloorStd(float x) { return floorf(x); } // we already uses our own ImFloor() { return (float)(int)v } internally so the standard one wrapper is named differently (it's used by stb_truetype)
|
||||
static inline float ImCeil(float x) { return ceilf(x); }
|
||||
#endif
|
||||
// - ImMin/ImMax/ImClamp/ImLerp/ImSwap are used by widgets which support for variety of types: signed/unsigned int/long long float/double, using templates here but we could also redefine them 6 times
|
||||
// - ImMin/ImMax/ImClamp/ImLerp/ImSwap are used by widgets which support for variety of types: signed/unsigned int/long long float/double
|
||||
// (Exceptionally using templates here but we could also redefine them for variety of types)
|
||||
template<typename T> static inline T ImMin(T lhs, T rhs) { return lhs < rhs ? lhs : rhs; }
|
||||
template<typename T> static inline T ImMax(T lhs, T rhs) { return lhs >= rhs ? lhs : rhs; }
|
||||
template<typename T> static inline T ImClamp(T v, T mn, T mx) { return (v < mn) ? mn : (v > mx) ? mx : v; }
|
||||
template<typename T> static inline T ImLerp(T a, T b, float t) { return (T)(a + (b - a) * t); }
|
||||
template<typename T> static inline void ImSwap(T& a, T& b) { T tmp = a; a = b; b = tmp; }
|
||||
template<typename T> static inline T ImAddClampOverflow(T a, T b, T mn, T mx) { if (b < 0 && (a < mn - b)) return mn; if (b > 0 && (a > mx - b)) return mx; return a + b; }
|
||||
template<typename T> static inline T ImSubClampOverflow(T a, T b, T mn, T mx) { if (b > 0 && (a < mn + b)) return mn; if (b < 0 && (a > mx + b)) return mx; return a - b; }
|
||||
// - Misc maths helpers
|
||||
static inline ImVec2 ImMin(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x < rhs.x ? lhs.x : rhs.x, lhs.y < rhs.y ? lhs.y : rhs.y); }
|
||||
static inline ImVec2 ImMax(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x >= rhs.x ? lhs.x : rhs.x, lhs.y >= rhs.y ? lhs.y : rhs.y); }
|
||||
|
|
|
@ -74,22 +74,30 @@ Index of this file:
|
|||
//-------------------------------------------------------------------------
|
||||
|
||||
// Those MIN/MAX values are not define because we need to point to them
|
||||
static const ImS32 IM_S32_MIN = INT_MIN; // (-2147483647 - 1), (0x80000000);
|
||||
static const ImS32 IM_S32_MAX = INT_MAX; // (2147483647), (0x7FFFFFFF)
|
||||
static const ImU32 IM_U32_MIN = 0;
|
||||
static const ImU32 IM_U32_MAX = UINT_MAX; // (0xFFFFFFFF)
|
||||
static const char IM_S8_MIN = -128;
|
||||
static const char IM_S8_MAX = 127;
|
||||
static const unsigned char IM_U8_MIN = 0;
|
||||
static const unsigned char IM_U8_MAX = 0xFF;
|
||||
static const short IM_S16_MIN = -32768;
|
||||
static const short IM_S16_MAX = 32767;
|
||||
static const unsigned short IM_U16_MIN = 0;
|
||||
static const unsigned short IM_U16_MAX = 0xFFFF;
|
||||
static const ImS32 IM_S32_MIN = INT_MIN; // (-2147483647 - 1), (0x80000000);
|
||||
static const ImS32 IM_S32_MAX = INT_MAX; // (2147483647), (0x7FFFFFFF)
|
||||
static const ImU32 IM_U32_MIN = 0;
|
||||
static const ImU32 IM_U32_MAX = UINT_MAX; // (0xFFFFFFFF)
|
||||
#ifdef LLONG_MIN
|
||||
static const ImS64 IM_S64_MIN = LLONG_MIN; // (-9223372036854775807ll - 1ll);
|
||||
static const ImS64 IM_S64_MAX = LLONG_MAX; // (9223372036854775807ll);
|
||||
static const ImS64 IM_S64_MIN = LLONG_MIN; // (-9223372036854775807ll - 1ll);
|
||||
static const ImS64 IM_S64_MAX = LLONG_MAX; // (9223372036854775807ll);
|
||||
#else
|
||||
static const ImS64 IM_S64_MIN = -9223372036854775807LL - 1;
|
||||
static const ImS64 IM_S64_MAX = 9223372036854775807LL;
|
||||
static const ImS64 IM_S64_MIN = -9223372036854775807LL - 1;
|
||||
static const ImS64 IM_S64_MAX = 9223372036854775807LL;
|
||||
#endif
|
||||
static const ImU64 IM_U64_MIN = 0;
|
||||
static const ImU64 IM_U64_MIN = 0;
|
||||
#ifdef ULLONG_MAX
|
||||
static const ImU64 IM_U64_MAX = ULLONG_MAX; // (0xFFFFFFFFFFFFFFFFull);
|
||||
static const ImU64 IM_U64_MAX = ULLONG_MAX; // (0xFFFFFFFFFFFFFFFFull);
|
||||
#else
|
||||
static const ImU64 IM_U64_MAX = (2ULL * 9223372036854775807LL + 1);
|
||||
static const ImU64 IM_U64_MAX = (2ULL * 9223372036854775807LL + 1);
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -1495,17 +1503,21 @@ struct ImGuiDataTypeInfo
|
|||
|
||||
static const ImGuiDataTypeInfo GDataTypeInfo[] =
|
||||
{
|
||||
{ sizeof(int), "%d", "%d" },
|
||||
{ sizeof(unsigned int), "%u", "%u" },
|
||||
{ sizeof(char), "%d", "%d" }, // ImGuiDataType_S8
|
||||
{ sizeof(unsigned char), "%u", "%u" },
|
||||
{ sizeof(short), "%d", "%d" }, // ImGuiDataType_S16
|
||||
{ sizeof(unsigned short), "%u", "%u" },
|
||||
{ sizeof(int), "%d", "%d" }, // ImGuiDataType_S32
|
||||
{ sizeof(unsigned int), "%u", "%u" },
|
||||
#ifdef _MSC_VER
|
||||
{ sizeof(ImS64), "%I64d","%I64d" },
|
||||
{ sizeof(ImU64), "%I64u","%I64u" },
|
||||
{ sizeof(ImS64), "%I64d","%I64d" }, // ImGuiDataType_S64
|
||||
{ sizeof(ImU64), "%I64u","%I64u" },
|
||||
#else
|
||||
{ sizeof(ImS64), "%lld", "%lld" },
|
||||
{ sizeof(ImU64), "%llu", "%llu" },
|
||||
{ sizeof(ImS64), "%lld", "%lld" }, // ImGuiDataType_S64
|
||||
{ sizeof(ImU64), "%llu", "%llu" },
|
||||
#endif
|
||||
{ sizeof(float), "%f", "%f" }, // float are promoted to double in va_arg
|
||||
{ sizeof(double), "%f", "%lf" },
|
||||
{ sizeof(float), "%f", "%f" }, // ImGuiDataType_Float (float are promoted to double in va_arg)
|
||||
{ sizeof(double), "%f", "%lf" }, // ImGuiDataType_Double
|
||||
};
|
||||
IM_STATIC_ASSERT(IM_ARRAYSIZE(GDataTypeInfo) == ImGuiDataType_COUNT);
|
||||
|
||||
|
@ -1535,47 +1547,71 @@ static const char* PatchFormatStringFloatToInt(const char* fmt)
|
|||
|
||||
static inline int DataTypeFormatString(char* buf, int buf_size, ImGuiDataType data_type, const void* data_ptr, const char* format)
|
||||
{
|
||||
if (data_type == ImGuiDataType_S32 || data_type == ImGuiDataType_U32) // Signedness doesn't matter when pushing the argument
|
||||
// Signedness doesn't matter when pushing integer arguments
|
||||
if (data_type == ImGuiDataType_S32 || data_type == ImGuiDataType_U32)
|
||||
return ImFormatString(buf, buf_size, format, *(const ImU32*)data_ptr);
|
||||
if (data_type == ImGuiDataType_S64 || data_type == ImGuiDataType_U64) // Signedness doesn't matter when pushing the argument
|
||||
if (data_type == ImGuiDataType_S64 || data_type == ImGuiDataType_U64)
|
||||
return ImFormatString(buf, buf_size, format, *(const ImU64*)data_ptr);
|
||||
if (data_type == ImGuiDataType_Float)
|
||||
return ImFormatString(buf, buf_size, format, *(const float*)data_ptr);
|
||||
if (data_type == ImGuiDataType_Double)
|
||||
return ImFormatString(buf, buf_size, format, *(const double*)data_ptr);
|
||||
if (data_type == ImGuiDataType_S8)
|
||||
return ImFormatString(buf, buf_size, format, *(const ImS8*)data_ptr);
|
||||
if (data_type == ImGuiDataType_U8)
|
||||
return ImFormatString(buf, buf_size, format, *(const ImU8*)data_ptr);
|
||||
if (data_type == ImGuiDataType_S16)
|
||||
return ImFormatString(buf, buf_size, format, *(const ImS16*)data_ptr);
|
||||
if (data_type == ImGuiDataType_U16)
|
||||
return ImFormatString(buf, buf_size, format, *(const ImU16*)data_ptr);
|
||||
IM_ASSERT(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// FIXME: Adding support for clamping on boundaries of the data type would be nice.
|
||||
static void DataTypeApplyOp(ImGuiDataType data_type, int op, void* output, void* arg1, const void* arg2)
|
||||
{
|
||||
IM_ASSERT(op == '+' || op == '-');
|
||||
switch (data_type)
|
||||
{
|
||||
case ImGuiDataType_S8:
|
||||
if (op == '+') { *(ImS8*)output = ImAddClampOverflow(*(const ImS8*)arg1, *(const ImS8*)arg2, IM_S8_MIN, IM_S8_MAX); }
|
||||
if (op == '-') { *(ImS8*)output = ImSubClampOverflow(*(const ImS8*)arg1, *(const ImS8*)arg2, IM_S8_MIN, IM_S8_MAX); }
|
||||
return;
|
||||
case ImGuiDataType_U8:
|
||||
if (op == '+') { *(ImU8*)output = ImAddClampOverflow(*(const ImU8*)arg1, *(const ImU8*)arg2, IM_U8_MIN, IM_U8_MAX); }
|
||||
if (op == '-') { *(ImU8*)output = ImSubClampOverflow(*(const ImU8*)arg1, *(const ImU8*)arg2, IM_U8_MIN, IM_U8_MAX); }
|
||||
return;
|
||||
case ImGuiDataType_S16:
|
||||
if (op == '+') { *(ImS16*)output = ImAddClampOverflow(*(const ImS16*)arg1, *(const ImS16*)arg2, IM_S16_MIN, IM_S16_MAX); }
|
||||
if (op == '-') { *(ImS16*)output = ImSubClampOverflow(*(const ImS16*)arg1, *(const ImS16*)arg2, IM_S16_MIN, IM_S16_MAX); }
|
||||
return;
|
||||
case ImGuiDataType_U16:
|
||||
if (op == '+') { *(ImU16*)output = ImAddClampOverflow(*(const ImU16*)arg1, *(const ImU16*)arg2, IM_U16_MIN, IM_U16_MAX); }
|
||||
if (op == '-') { *(ImU16*)output = ImSubClampOverflow(*(const ImU16*)arg1, *(const ImU16*)arg2, IM_U16_MIN, IM_U16_MAX); }
|
||||
return;
|
||||
case ImGuiDataType_S32:
|
||||
if (op == '+') *(int*)output = *(const int*)arg1 + *(const int*)arg2;
|
||||
else if (op == '-') *(int*)output = *(const int*)arg1 - *(const int*)arg2;
|
||||
if (op == '+') { *(ImS32*)output = ImAddClampOverflow(*(const ImS32*)arg1, *(const ImS32*)arg2, IM_S32_MIN, IM_S32_MAX); }
|
||||
if (op == '-') { *(ImS32*)output = ImSubClampOverflow(*(const ImS32*)arg1, *(const ImS32*)arg2, IM_S32_MIN, IM_S32_MAX); }
|
||||
return;
|
||||
case ImGuiDataType_U32:
|
||||
if (op == '+') *(unsigned int*)output = *(const unsigned int*)arg1 + *(const ImU32*)arg2;
|
||||
else if (op == '-') *(unsigned int*)output = *(const unsigned int*)arg1 - *(const ImU32*)arg2;
|
||||
if (op == '+') { *(ImU32*)output = ImAddClampOverflow(*(const ImU32*)arg1, *(const ImU32*)arg2, IM_U32_MIN, IM_U32_MAX); }
|
||||
if (op == '-') { *(ImU32*)output = ImSubClampOverflow(*(const ImU32*)arg1, *(const ImU32*)arg2, IM_U32_MIN, IM_U32_MAX); }
|
||||
return;
|
||||
case ImGuiDataType_S64:
|
||||
if (op == '+') *(ImS64*)output = *(const ImS64*)arg1 + *(const ImS64*)arg2;
|
||||
else if (op == '-') *(ImS64*)output = *(const ImS64*)arg1 - *(const ImS64*)arg2;
|
||||
if (op == '+') { *(ImS64*)output = ImAddClampOverflow(*(const ImS64*)arg1, *(const ImS64*)arg2, IM_S64_MIN, IM_S64_MAX); }
|
||||
if (op == '-') { *(ImS64*)output = ImSubClampOverflow(*(const ImS64*)arg1, *(const ImS64*)arg2, IM_S64_MIN, IM_S64_MAX); }
|
||||
return;
|
||||
case ImGuiDataType_U64:
|
||||
if (op == '+') *(ImU64*)output = *(const ImU64*)arg1 + *(const ImU64*)arg2;
|
||||
else if (op == '-') *(ImU64*)output = *(const ImU64*)arg1 - *(const ImU64*)arg2;
|
||||
if (op == '+') { *(ImU64*)output = ImAddClampOverflow(*(const ImU64*)arg1, *(const ImU64*)arg2, IM_U64_MIN, IM_U64_MAX); }
|
||||
if (op == '-') { *(ImU64*)output = ImSubClampOverflow(*(const ImU64*)arg1, *(const ImU64*)arg2, IM_U64_MIN, IM_U64_MAX); }
|
||||
return;
|
||||
case ImGuiDataType_Float:
|
||||
if (op == '+') *(float*)output = *(const float*)arg1 + *(const float*)arg2;
|
||||
else if (op == '-') *(float*)output = *(const float*)arg1 - *(const float*)arg2;
|
||||
if (op == '+') { *(float*)output = *(const float*)arg1 + *(const float*)arg2; }
|
||||
if (op == '-') { *(float*)output = *(const float*)arg1 - *(const float*)arg2; }
|
||||
return;
|
||||
case ImGuiDataType_Double:
|
||||
if (op == '+') *(double*)output = *(const double*)arg1 + *(const double*)arg2;
|
||||
else if (op == '-') *(double*)output = *(const double*)arg1 - *(const double*)arg2;
|
||||
if (op == '+') { *(double*)output = *(const double*)arg1 + *(const double*)arg2; }
|
||||
if (op == '-') { *(double*)output = *(const double*)arg1 - *(const double*)arg2; }
|
||||
return;
|
||||
case ImGuiDataType_COUNT: break;
|
||||
}
|
||||
|
@ -1614,6 +1650,7 @@ static bool DataTypeApplyOpFromText(const char* buf, const char* initial_value_b
|
|||
if (format == NULL)
|
||||
format = GDataTypeInfo[data_type].ScanFmt;
|
||||
|
||||
// FIXME-LEGACY: The aim is to remove those operators and write a proper expression evaluator at some point..
|
||||
int arg1i = 0;
|
||||
if (data_type == ImGuiDataType_S32)
|
||||
{
|
||||
|
@ -1628,12 +1665,6 @@ static bool DataTypeApplyOpFromText(const char* buf, const char* initial_value_b
|
|||
else if (op == '/') { if (sscanf(buf, "%f", &arg1f) && arg1f != 0.0f) *v = (int)(arg0i / arg1f); } // Divide
|
||||
else { if (sscanf(buf, format, &arg1i) == 1) *v = arg1i; } // Assign constant
|
||||
}
|
||||
else if (data_type == ImGuiDataType_U32 || data_type == ImGuiDataType_S64 || data_type == ImGuiDataType_U64)
|
||||
{
|
||||
// Assign constant
|
||||
// FIXME: We don't bother handling support for legacy operators since they are a little too crappy. Instead we may implement a proper expression evaluator in the future.
|
||||
sscanf(buf, format, data_ptr);
|
||||
}
|
||||
else if (data_type == ImGuiDataType_Float)
|
||||
{
|
||||
// For floats we have to ignore format with precision (e.g. "%.2f") because sscanf doesn't take them in
|
||||
|
@ -1663,6 +1694,29 @@ static bool DataTypeApplyOpFromText(const char* buf, const char* initial_value_b
|
|||
else if (op == '/') { if (arg1f != 0.0f) *v = arg0f / arg1f; } // Divide
|
||||
else { *v = arg1f; } // Assign constant
|
||||
}
|
||||
else if (data_type == ImGuiDataType_U32 || data_type == ImGuiDataType_S64 || data_type == ImGuiDataType_U64)
|
||||
{
|
||||
// All other types assign constant
|
||||
// We don't bother handling support for legacy operators since they are a little too crappy. Instead we will later implement a proper expression evaluator in the future.
|
||||
sscanf(buf, format, data_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Small types need a 32-bit buffer to receive the result from scanf()
|
||||
int v32;
|
||||
sscanf(buf, format, &v32);
|
||||
if (data_type == ImGuiDataType_S8)
|
||||
*(ImS8*)data_ptr = (ImS8)ImClamp(v32, (int)IM_S8_MIN, (int)IM_S8_MAX);
|
||||
else if (data_type == ImGuiDataType_U8)
|
||||
*(ImU8*)data_ptr = (ImU8)ImClamp(v32, (int)IM_U8_MIN, (int)IM_U8_MAX);
|
||||
else if (data_type == ImGuiDataType_S16)
|
||||
*(ImS16*)data_ptr = (ImS16)ImClamp(v32, (int)IM_S16_MIN, (int)IM_S16_MAX);
|
||||
else if (data_type == ImGuiDataType_U16)
|
||||
*(ImU16*)data_ptr = (ImU16)ImClamp(v32, (int)IM_U16_MIN, (int)IM_U16_MAX);
|
||||
else
|
||||
IM_ASSERT(0);
|
||||
}
|
||||
|
||||
return memcmp(data_backup, data_ptr, GDataTypeInfo[data_type].Size) != 0;
|
||||
}
|
||||
|
||||
|
@ -1845,6 +1899,10 @@ bool ImGui::DragBehavior(ImGuiID id, ImGuiDataType data_type, void* v, float v_s
|
|||
|
||||
switch (data_type)
|
||||
{
|
||||
case ImGuiDataType_S8: { ImS32 v32 = (ImS32)*(ImS8*)v; bool r = DragBehaviorT<ImS32, ImS32, float >(ImGuiDataType_S32, &v32, v_speed, v_min ? *(const ImS8*) v_min : IM_S8_MIN, v_max ? *(const ImS8*)v_max : IM_S8_MAX, format, power, flags); if (r) *(ImS8*)v = (ImS8)v32; return r; }
|
||||
case ImGuiDataType_U8: { ImU32 v32 = (ImU32)*(ImU8*)v; bool r = DragBehaviorT<ImU32, ImS32, float >(ImGuiDataType_U32, &v32, v_speed, v_min ? *(const ImU8*) v_min : IM_U8_MIN, v_max ? *(const ImU8*)v_max : IM_U8_MAX, format, power, flags); if (r) *(ImU8*)v = (ImU8)v32; return r; }
|
||||
case ImGuiDataType_S16: { ImS32 v32 = (ImS32)*(ImS16*)v; bool r = DragBehaviorT<ImS32, ImS32, float >(ImGuiDataType_S32, &v32, v_speed, v_min ? *(const ImS16*)v_min : IM_S16_MIN, v_max ? *(const ImS16*)v_max : IM_S16_MAX, format, power, flags); if (r) *(ImS16*)v = (ImS16)v32; return r; }
|
||||
case ImGuiDataType_U16: { ImU32 v32 = (ImU32)*(ImU16*)v; bool r = DragBehaviorT<ImU32, ImS32, float >(ImGuiDataType_U32, &v32, v_speed, v_min ? *(const ImU16*)v_min : IM_U16_MIN, v_max ? *(const ImU16*)v_max : IM_U16_MAX, format, power, flags); if (r) *(ImU16*)v = (ImU16)v32; return r; }
|
||||
case ImGuiDataType_S32: return DragBehaviorT<ImS32, ImS32, float >(data_type, (ImS32*)v, v_speed, v_min ? *(const ImS32* )v_min : IM_S32_MIN, v_max ? *(const ImS32* )v_max : IM_S32_MAX, format, power, flags);
|
||||
case ImGuiDataType_U32: return DragBehaviorT<ImU32, ImS32, float >(data_type, (ImU32*)v, v_speed, v_min ? *(const ImU32* )v_min : IM_U32_MIN, v_max ? *(const ImU32* )v_max : IM_U32_MAX, format, power, flags);
|
||||
case ImGuiDataType_S64: return DragBehaviorT<ImS64, ImS64, double>(data_type, (ImS64*)v, v_speed, v_min ? *(const ImS64* )v_min : IM_S64_MIN, v_max ? *(const ImS64* )v_max : IM_S64_MAX, format, power, flags);
|
||||
|
@ -2284,6 +2342,10 @@ bool ImGui::SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type
|
|||
{
|
||||
switch (data_type)
|
||||
{
|
||||
case ImGuiDataType_S8: { ImS32 v32 = (ImS32)*(ImS8*)v; bool r = SliderBehaviorT<ImS32, ImS32, float >(bb, id, ImGuiDataType_S32, &v32, *(const ImS8*)v_min, *(const ImS8*)v_max, format, power, flags, out_grab_bb); if (r) *(ImS8*)v = (ImS8)v32; return r; }
|
||||
case ImGuiDataType_U8: { ImU32 v32 = (ImU32)*(ImU8*)v; bool r = SliderBehaviorT<ImU32, ImS32, float >(bb, id, ImGuiDataType_U32, &v32, *(const ImU8*)v_min, *(const ImU8*)v_max, format, power, flags, out_grab_bb); if (r) *(ImU8*)v = (ImU8)v32; return r; }
|
||||
case ImGuiDataType_S16: { ImS32 v32 = (ImS32)*(ImS16*)v; bool r = SliderBehaviorT<ImS32, ImS32, float >(bb, id, ImGuiDataType_S32, &v32, *(const ImS16*)v_min, *(const ImS16*)v_max, format, power, flags, out_grab_bb); if (r) *(ImS16*)v = (ImS16)v32; return r; }
|
||||
case ImGuiDataType_U16: { ImU32 v32 = (ImU32)*(ImU16*)v; bool r = SliderBehaviorT<ImU32, ImS32, float >(bb, id, ImGuiDataType_U32, &v32, *(const ImU16*)v_min, *(const ImU16*)v_max, format, power, flags, out_grab_bb); if (r) *(ImU16*)v = (ImU16)v32; return r; }
|
||||
case ImGuiDataType_S32:
|
||||
IM_ASSERT(*(const ImS32*)v_min >= IM_S32_MIN/2 && *(const ImS32*)v_max <= IM_S32_MAX/2);
|
||||
return SliderBehaviorT<ImS32, ImS32, float >(bb, id, data_type, (ImS32*)v, *(const ImS32*)v_min, *(const ImS32*)v_max, format, power, flags, out_grab_bb);
|
||||
|
|
Loading…
Reference in New Issue