trunk/3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.cpp
| r245117 | r245118 | |
| 1 | | // ImGui library v1.35 |
| 1 | // ImGui library v1.32 wip |
| 2 | 2 | // See ImGui::ShowTestWindow() for sample code. |
| 3 | 3 | // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase. |
| 4 | 4 | // Get latest version at https://github.com/ocornut/imgui |
| r245117 | r245118 | |
| 9 | 9 | Index |
| 10 | 10 | - MISSION STATEMENT |
| 11 | 11 | - END-USER GUIDE |
| 12 | | - PROGRAMMER GUIDE (read me!) |
| 13 | | - API BREAKING CHANGES (read me when you update!) |
| 14 | | - FREQUENTLY ASKED QUESTIONS (FAQ) & TROUBLESHOOTING (read me!) |
| 12 | - PROGRAMMER GUIDE |
| 13 | - API BREAKING CHANGES |
| 14 | - TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS |
| 15 | 15 | - ISSUES & TODO-LIST |
| 16 | 16 | - CODE |
| 17 | 17 | - SAMPLE CODE |
| r245117 | r245118 | |
| 27 | 27 | - minimize screen real-estate usage |
| 28 | 28 | - minimize setup and maintenance |
| 29 | 29 | - minimize state storage on user side |
| 30 | | - portable, minimize dependencies, run on target (consoles, phones, etc.) |
| 30 | - portable, minimize dependencies, run on target (consoles, etc.) |
| 31 | 31 | - efficient runtime (NB- we do allocate when "growing" content - creating a window / opening a tree node for the first time, etc. - but a typical frame won't allocate anything) |
| 32 | | - read about immediate-mode gui principles @ http://mollyrocket.com/861, http://mollyrocket.com/forums/index.html |
| 32 | - read about immediate-mode GUI principles @ http://mollyrocket.com/861, http://mollyrocket.com/forums/index.html |
| 33 | 33 | |
| 34 | 34 | Designed for developers and content-creators, not the typical end-user! Some of the weaknesses includes: |
| 35 | 35 | - doesn't look fancy, doesn't animate |
| 36 | 36 | - limited layout features, intricate layouts are typically crafted in code |
| 37 | | - occasionally uses statically sized buffers for string manipulations - won't crash, but some long text may be clipped. functions like ImGui::TextUnformatted() don't have such restriction. |
| 37 | - occasionally use statically sized buffers for string manipulations - won't crash, but some long text may be clipped |
| 38 | 38 | |
| 39 | 39 | |
| 40 | 40 | END-USER GUIDE |
| r245117 | r245118 | |
| 63 | 63 | PROGRAMMER GUIDE |
| 64 | 64 | ================ |
| 65 | 65 | |
| 66 | | - read the FAQ below this section! |
| 67 | | - your code creates the UI, if your code doesn't run the UI is gone! == very dynamic UI, no construction/destructions steps, less data retention on your side, no state duplication, less sync, less bugs. |
| 68 | | - call and read ImGui::ShowTestWindow() for sample code demonstrating most features. |
| 66 | - your code creates the UI, if your code doesn't run the UI is gone! == dynamic UI, no construction step, less data retention on your side, no state duplication, less sync, less errors. |
| 67 | - call and read ImGui::ShowTestWindow() for user-side sample code |
| 69 | 68 | - see examples/ folder for standalone sample applications. |
| 70 | 69 | - customization: use the style editor or PushStyleColor/PushStyleVar to tweak the look of the interface (e.g. if you want a more compact UI or a different color scheme). |
| 71 | 70 | |
| 71 | |
| 72 | 72 | - getting started: |
| 73 | 73 | - initialisation: call ImGui::GetIO() and fill the 'Settings' data. |
| 74 | 74 | - every frame: |
| r245117 | r245118 | |
| 96 | 96 | // TODO: store your texture pointer/identifier in 'io.Fonts->TexID' |
| 97 | 97 | |
| 98 | 98 | // Application main loop |
| 99 | | while (true) |
| 99 | for (;;) |
| 100 | 100 | { |
| 101 | 101 | // 1) get low-level input |
| 102 | 102 | // e.g. on Win32, GetKeyboardState(), or poll your events, etc. |
| r245117 | r245118 | |
| 129 | 129 | Occasionally introducing changes that are breaking the API. The breakage are generally minor and easy to fix. |
| 130 | 130 | Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code. |
| 131 | 131 | |
| 132 | | - 2015/03/08 (1.35) - renamed style.ScrollBarWidth to style.ScrollbarWidth |
| 133 | | - 2015/02/27 (1.34) - renamed OpenNextNode(bool) to SetNextTreeNodeOpened(bool, ImGuiSetCond), kept inline redirection function. |
| 134 | | - 2015/02/27 (1.34) - renamed ImGuiSetCondition_*** to ImGuiSetCond_***, and _FirstUseThisSession becomes _Once. |
| 135 | | - 2015/02/11 (1.32) - changed text input callback ImGuiTextEditCallback return type from void-->int. reserved for future use, return 0 for now. |
| 136 | 132 | - 2015/02/10 (1.32) - renamed GetItemWidth() to CalcItemWidth() to clarify its evolving behavior |
| 137 | 133 | - 2015/02/08 (1.31) - renamed GetTextLineSpacing() to GetTextLineHeightWithSpacing() |
| 138 | 134 | - 2015/02/01 (1.31) - removed IO.MemReallocFn (unused) |
| r245117 | r245118 | |
| 168 | 164 | - 2014/08/28 (1.09) - changed the behavior of IO.PixelCenterOffset following various rendering fixes |
| 169 | 165 | |
| 170 | 166 | |
| 171 | | FREQUENTLY ASKED QUESTIONS (FAQ) & TROUBLESHOOTING |
| 172 | | ================================================== |
| 167 | TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS |
| 168 | ============================================ |
| 173 | 169 | |
| 174 | 170 | If text or lines are blurry when integrating ImGui in your engine: |
| 175 | | |
| 176 | 171 | - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) |
| 177 | 172 | |
| 178 | | A primer on the meaning and use of ID in ImGui: |
| 179 | | |
| 180 | | - widgets require state to be carried over multiple frames (most typically ImGui often needs to remember what is the "active" widget). |
| 181 | | to do so they need an unique ID. unique ID are typically derived from a string label, an integer index or a pointer. |
| 182 | | |
| 183 | | Button("OK"); // Label = "OK", ID = hash of "OK" |
| 184 | | Button("Cancel"); // Label = "Cancel", ID = hash of "Cancel" |
| 185 | | |
| 173 | If you are confused about the meaning or use of ID in ImGui: |
| 174 | - many widgets requires state to be carried over multiple frames (most typically ImGui often wants remember what is the "active" widget). |
| 175 | to do so they need an unique ID. unique ID are typically derived from a string label, an indice or a pointer. |
| 176 | when you call Button("OK") the button shows "OK" and also use "OK" as an ID. |
| 186 | 177 | - ID are uniquely scoped within Windows so no conflict can happen if you have two buttons called "OK" in two different Windows. |
| 178 | within a same Window, use PushID() / PopID() to easily create scopes and avoid ID conflicts. |
| 179 | so if you have a loop creating "multiple" items, you can use PushID() / PopID() with the index of each item, or their pointer, etc. |
| 180 | some functions like TreeNode() implicitly creates a scope for you by calling PushID() |
| 181 | - when dealing with trees, ID are important because you want to preserve the opened/closed state of tree nodes. |
| 182 | depending on your use cases you may want to use strings, indices or pointers as ID. experiment and see what makes more sense! |
| 183 | e.g. When displaying a single object that may change over time, using a static string as ID will preserve your node open/closed state when the targeted object change |
| 184 | e.g. When displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state per object |
| 185 | - when passing a label you can optionally specify extra unique ID information within the same string using "##". This helps solving the simpler collision cases. |
| 186 | e.g. "Label" display "Label" and uses "Label" as ID |
| 187 | e.g. "Label##Foobar" display "Label" and uses "Label##Foobar" as ID |
| 188 | e.g. "##Foobar" display an empty label and uses "##Foobar" as ID |
| 189 | - read articles about immediate-mode ui principles (see web links) to understand the requirement and use of ID. |
| 187 | 190 | |
| 188 | | - when passing a label you can optionally specify extra unique ID information within string itself. This helps solving the simpler collision cases. |
| 189 | | use "##" to pass a complement to the ID that won't be visible to the end-user: |
| 190 | | |
| 191 | | Button("Play##0"); // Label = "Play", ID = hash of "Play##0" |
| 192 | | Button("Play##1"); // Label = "Play", ID = hash of "Play##1" (different from above) |
| 193 | | |
| 194 | | use "###" to pass a label that isn't part of ID. You can use that to change labels while preserving a constant ID. |
| 195 | | |
| 196 | | Button("Hello###ID"; // Label = "Hello", ID = hash of "ID" |
| 197 | | Button("World###ID"; // Label = "World", ID = hash of "ID" (same as above) |
| 198 | | |
| 199 | | - use PushID() / PopID() to create scopes and avoid ID conflicts within the same Window: |
| 200 | | |
| 201 | | Button("Click"); // Label = "Click", ID = hash of "Click" |
| 202 | | PushID("node"); |
| 203 | | Button("Click"); // Label = "Click", ID = hash of "node" and "Click" |
| 204 | | for (int i = 0; i < 100; i++) |
| 205 | | { |
| 206 | | PushID(i); |
| 207 | | Button("Click"); // Label = "Click", ID = hash of "node" and i and "label" |
| 208 | | PopID(); |
| 209 | | } |
| 210 | | PopID(); |
| 211 | | PushID(my_ptr); |
| 212 | | Button("Click"); // Label = "Click", ID = hash of ptr and "Click" |
| 213 | | PopID(); |
| 214 | | |
| 215 | | so if you have a loop creating multiple items, you can use PushID() / PopID() with the index of each item, or their pointer, etc. |
| 216 | | some functions like TreeNode() implicitly creates a scope for you by calling PushID(). |
| 217 | | |
| 218 | | - when working with trees, ID are used to preserve the opened/closed state of tree nodes. |
| 219 | | depending on your use cases you may want to use strings, indices or pointers as ID. |
| 220 | | e.g. when displaying a single object that may change over time (1-1 relationship), using a static string as ID will preserve your node open/closed state when the targeted object change. |
| 221 | | e.g. when displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state differently. experiment and see what makes more sense! |
| 222 | | |
| 223 | 191 | If you want to load a different font than the default (ProggyClean.ttf, size 13) |
| 224 | 192 | |
| 225 | 193 | io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels); |
| r245117 | r245118 | |
| 236 | 204 | |
| 237 | 205 | io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, io.Fonts->GetGlyphRangesJapanese()); // Load Japanese characters |
| 238 | 206 | io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() |
| 239 | | io.ImeWindowHandle = MY_HWND; // To input using Microsoft IME, give ImGui the hwnd of your application |
| 240 | 207 | |
| 208 | If you want to input Japanese/Chinese/Korean in the text input widget: |
| 209 | |
| 210 | - when loading the font, pass a range that contains the characters you need, e.g.: io.Fonts->GetGlyphRangesJapanese() |
| 211 | - to have the Microsoft IME cursor appears at the right location in the screen, setup a handler for the io.ImeSetInputScreenPosFn function: |
| 212 | |
| 213 | #include <Windows.h> |
| 214 | #include <Imm.h> |
| 215 | static void ImImpl_ImeSetInputScreenPosFn(int x, int y) |
| 216 | { |
| 217 | // Notify OS Input Method Editor of text input position |
| 218 | HWND hwnd = glfwGetWin32Window(window); |
| 219 | if (HIMC himc = ImmGetContext(hwnd)) |
| 220 | { |
| 221 | COMPOSITIONFORM cf; |
| 222 | cf.ptCurrentPos.x = x; |
| 223 | cf.ptCurrentPos.y = y; |
| 224 | cf.dwStyle = CFS_FORCE_POSITION; |
| 225 | ImmSetCompositionWindow(himc, &cf); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | // Set pointer to handler in ImGuiIO structure |
| 230 | io.ImeSetInputScreenPosFn = ImImpl_ImeSetInputScreenPosFn; |
| 231 | |
| 241 | 232 | - tip: the construct 'IMGUI_ONCE_UPON_A_FRAME { ... }' will run the block of code only once a frame. You can use it to quickly add custom UI in the middle of a deep nested inner loop in your code. |
| 242 | 233 | - tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug" |
| 243 | 234 | - tip: you can call Begin() multiple times with the same name during the same frame, it will keep appending to the same window. |
| r245117 | r245118 | |
| 263 | 254 | - main: IsItemHovered() returns true even if mouse is active on another widget (e.g. dragging outside of sliders). Maybe not a sensible default? Add parameter or alternate function? |
| 264 | 255 | - main: IsItemHovered() make it 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 |
| 265 | 256 | - main: IsItemHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode? |
| 257 | - scrollbar: use relative mouse movement when first-clicking inside of scroll grab box. |
| 258 | - scrollbar: make the grab visible and a minimum size for long scroll regions |
| 266 | 259 | !- input number: very large int not reliably supported because of int<>float conversions. |
| 267 | 260 | - input number: optional range min/max for Input*() functions |
| 268 | 261 | - input number: holding [-]/[+] buttons could increase the step speed non-linearly (or user-controlled) |
| r245117 | r245118 | |
| 275 | 268 | - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills) |
| 276 | 269 | - columns: columns header to act as button (~sort op) and allow resize/reorder |
| 277 | 270 | - columns: user specify columns size |
| 278 | | - columns: tree node example, removing the last NextColumn() makes a padding difference (it should not) |
| 279 | 271 | - combo: turn child handling code into pop up helper |
| 280 | 272 | - combo: contents should extends to fit label if combo widget is small |
| 281 | 273 | - listbox: multiple selection |
| r245117 | r245118 | |
| 289 | 281 | - plot: add a helper e.g. Plot(char* label, float value, float time_span=2.0f) that stores values and Plot them for you - probably another function name. and/or automatically allow to plot ANY displayed value (more reliance on stable ID) |
| 290 | 282 | - file selection widget -> build the tool in our codebase to improve model-dialog idioms |
| 291 | 283 | - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt() |
| 292 | | - slider: initial absolute click is imprecise. change to relative movement slider? hide mouse cursor, allow more precise input using less screen-space. same as scrollbar. |
| 293 | | - text edit: clean up the mess caused by converting UTF-8 <> wchar. the code is rather inefficient right now. |
| 284 | - slider: initial absolute click is imprecise. change to relative movement slider? hide mouse cursor, allow more precise input using less screen-space. |
| 285 | - text edit: clean up the mess caused by converting UTF-8 <> wchar. the code is rather ineficient right now. |
| 294 | 286 | - text edit: centered text for slider as input text so it matches typical positioning. |
| 295 | 287 | - text edit: flag to disable live update of the user buffer. |
| 296 | 288 | - text edit: field resize behavior - field could stretch when being edited? hover tooltip shows more text? |
| r245117 | r245118 | |
| 301 | 293 | ! style: store rounded corners in texture to use 1 quad per corner (filled and wireframe). so rounding have minor cost. |
| 302 | 294 | - style: checkbox: padding for "active" color should be a multiplier of the |
| 303 | 295 | - style: colorbox not always square? |
| 304 | | - text: simple markup language for color change? |
| 305 | 296 | - log: LogButtons() options for specifying depth and/or hiding depth slider |
| 306 | 297 | - log: have more control over the log scope (e.g. stop logging when leaving current tree node scope) |
| 307 | 298 | - log: be able to right-click and log a window or tree-node into tty/file/clipboard / generalized context menu? |
| r245117 | r245118 | |
| 349 | 340 | #pragma clang diagnostic ignored "-Wformat-nonliteral" // warning : format string is not a string literal // passing non-literal to vsnformat(). yes, user passing incorrect format strings can crash the code. |
| 350 | 341 | #pragma clang diagnostic ignored "-Wexit-time-destructors" // warning : declaration requires an exit-time destructor // exit-time destruction order is undefined. if MemFree() leads to users code that has been disabled before exit it might cause problems. ImGui coding style welcomes static/globals. |
| 351 | 342 | #pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference it. |
| 352 | | #pragma clang diagnostic ignored "-Wsign-conversion" // warning : implicit conversion changes signedness // |
| 343 | #pragma clang diagnostic ignored "-Wsign-conversion" // warning : implicit conversion chanjges signedness // |
| 344 | #elif defined(__GNUC__) |
| 345 | #pragma GCC diagnostic ignored "-Wtype-limits" |
| 346 | #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" |
| 347 | #pragma GCC diagnostic ignored "-Wunused-function" |
| 353 | 348 | #endif |
| 354 | | #ifdef __GNUC__ |
| 355 | | #pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used |
| 356 | | #pragma GCC diagnostic ignored "-Wunused-parameter" // warning: unused parameter ‘xxxx’ |
| 357 | | #pragma GCC diagnostic ignored "-Wtype-limits" // warning: comparison is always true due to limited range of data type |
| 358 | | #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // warning: ‘xxxx’ may be used uninitialized in this function |
| 359 | | #endif |
| 360 | 349 | |
| 361 | 350 | //------------------------------------------------------------------------- |
| 362 | 351 | // STB libraries implementation |
| r245117 | r245118 | |
| 395 | 384 | #endif |
| 396 | 385 | #include "stb_truetype.h" |
| 397 | 386 | |
| 398 | | #define STB_TEXTEDIT_STRING ImGuiTextEditState |
| 399 | | #define STB_TEXTEDIT_CHARTYPE ImWchar |
| 387 | #define STB_TEXTEDIT_STRING ImGuiTextEditState |
| 388 | #define STB_TEXTEDIT_CHARTYPE ImWchar |
| 400 | 389 | #include "stb_textedit.h" |
| 401 | 390 | |
| 402 | 391 | #ifdef __clang__ |
| r245117 | r245118 | |
| 412 | 401 | // Forward Declarations |
| 413 | 402 | //------------------------------------------------------------------------- |
| 414 | 403 | |
| 415 | | struct ImGuiColMod; |
| 416 | | struct ImGuiStyleMod; |
| 417 | 404 | struct ImGuiAabb; |
| 418 | | struct ImGuiDrawContext; |
| 419 | | struct ImGuiTextEditState; |
| 420 | | struct ImGuiIniData; |
| 421 | | struct ImGuiState; |
| 422 | | struct ImGuiWindow; |
| 423 | 405 | |
| 424 | 406 | static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat = false, bool pressed_on_click = false); |
| 425 | 407 | static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL); |
| r245117 | r245118 | |
| 431 | 413 | static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false); |
| 432 | 414 | |
| 433 | 415 | static void SetFont(ImFont* font); |
| 434 | | static bool ItemAdd(const ImGuiAabb& bb, const ImGuiID* id); |
| 416 | static bool ItemAdd(const ImGuiAabb& aabb, const ImGuiID* id); |
| 435 | 417 | static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset = NULL); |
| 436 | | static void ItemSize(const ImGuiAabb& bb, ImVec2* adjust_start_offset = NULL); |
| 418 | static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset = NULL); |
| 437 | 419 | static void PushColumnClipRect(int column_index = -1); |
| 438 | | static bool IsClipped(const ImGuiAabb& bb); |
| 420 | static bool IsClipped(const ImGuiAabb& aabb); |
| 439 | 421 | |
| 440 | | static bool IsMouseHoveringBox(const ImGuiAabb& bb); |
| 422 | static bool IsMouseHoveringBox(const ImGuiAabb& box); |
| 441 | 423 | static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true); |
| 442 | 424 | |
| 443 | | static void Scrollbar(ImGuiWindow* window); |
| 444 | 425 | static bool CloseWindowButton(bool* p_opened = NULL); |
| 445 | 426 | static void FocusWindow(ImGuiWindow* window); |
| 446 | 427 | static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs); |
| r245117 | r245118 | |
| 455 | 436 | static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args); |
| 456 | 437 | |
| 457 | 438 | // Helpers: Misc |
| 458 | | static ImU32 ImHash(const void* data, size_t data_size, ImU32 seed); |
| 439 | static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed); |
| 459 | 440 | static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes = 0); |
| 460 | | static inline int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; } |
| 461 | | static inline bool ImCharIsSpace(int c) { return c == ' ' || c == '\t' || c == 0x3000; } |
| 441 | static int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; } |
| 462 | 442 | |
| 463 | 443 | // Helpers: UTF-8 <> wchar |
| 464 | 444 | static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int in_char); // return output UTF-8 bytes count |
| 465 | 445 | 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 |
| 466 | 446 | static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count |
| 467 | | static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end, const char** in_remaining = NULL); // return input UTF-8 bytes count |
| 447 | 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 |
| 468 | 448 | static int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count) |
| 469 | | static int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string as UTF-8 code-points |
| 449 | static int ImTextCountUtf8BytesFromWchar(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string as UTF-8 code-points |
| 470 | 450 | |
| 471 | 451 | //----------------------------------------------------------------------------- |
| 472 | 452 | // Platform dependent default implementations |
| r245117 | r245118 | |
| 474 | 454 | |
| 475 | 455 | static const char* GetClipboardTextFn_DefaultImpl(); |
| 476 | 456 | static void SetClipboardTextFn_DefaultImpl(const char* text); |
| 477 | | static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y); |
| 478 | 457 | |
| 479 | 458 | //----------------------------------------------------------------------------- |
| 480 | 459 | // Texture Atlas data |
| r245117 | r245118 | |
| 507 | 486 | WindowFillAlphaDefault = 0.70f; // Default alpha of window background, if not specified in ImGui::Begin() |
| 508 | 487 | TreeNodeSpacing = 22.0f; // Horizontal spacing when entering a tree node |
| 509 | 488 | ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns |
| 510 | | ScrollbarWidth = 16.0f; // Width of the vertical scrollbar |
| 511 | | GrabMinSize = 10.0f; // Minimum width/height of a slider or scrollbar grab |
| 489 | ScrollBarWidth = 16.0f; // Width of the vertical scroll bar |
| 512 | 490 | |
| 513 | 491 | Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); |
| 514 | 492 | Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); |
| r245117 | r245118 | |
| 551 | 529 | Colors[ImGuiCol_TooltipBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f); |
| 552 | 530 | } |
| 553 | 531 | |
| 554 | | // Statically allocated font atlas. This is merely a maneuver to keep ImFontAtlas definition at the bottom of the .h file (otherwise it'd be inside ImGuiIO) |
| 555 | | // Also we wouldn't be able to new() one at this point, before users may define IO.MemAllocFn. |
| 532 | // Statically allocated font atlas. This is merely a maneuver to keep its definition at the bottom of the .H file. |
| 533 | // Because we cannot new() at this point (before users may define IO.MemAllocFn) |
| 556 | 534 | static ImFontAtlas GDefaultFontAtlas; |
| 557 | 535 | |
| 558 | 536 | ImGuiIO::ImGuiIO() |
| r245117 | r245118 | |
| 579 | 557 | MemFreeFn = free; |
| 580 | 558 | GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependent default implementations |
| 581 | 559 | SetClipboardTextFn = SetClipboardTextFn_DefaultImpl; |
| 582 | | ImeSetInputScreenPosFn = ImeSetInputScreenPosFn_DefaultImpl; |
| 560 | ImeSetInputScreenPosFn = NULL; |
| 583 | 561 | } |
| 584 | 562 | |
| 585 | 563 | // Pass in translated ASCII characters for text input. |
| 586 | 564 | // - with glfw you can get those from the callback set in glfwSetCharCallback() |
| 587 | | // - on Windows you can get those using ToAscii+keyboard state, or via the WM_CHAR message |
| 565 | // - on Windows you can get those using ToAscii+keyboard state, or via the VM_CHAR message |
| 588 | 566 | void ImGuiIO::AddInputCharacter(ImWchar c) |
| 589 | 567 | { |
| 590 | 568 | const size_t n = ImStrlenW(InputCharacters); |
| r245117 | r245118 | |
| 610 | 588 | #define IM_INT_MAX 2147483647 |
| 611 | 589 | #endif |
| 612 | 590 | |
| 613 | | // Play it nice with Windows users. Notepad in 2015 still doesn't display text data with Unix-style \n. |
| 591 | // Play it nice with Windows users. Notepad in 2014 still doesn't display text data with Unix-style \n. |
| 614 | 592 | #ifdef _MSC_VER |
| 615 | 593 | #define STR_NEWLINE "\r\n" |
| 616 | 594 | #else |
| r245117 | r245118 | |
| 669 | 647 | static size_t ImStrlenW(const ImWchar* str) |
| 670 | 648 | { |
| 671 | 649 | size_t n = 0; |
| 672 | | while (*str++) n++; |
| 650 | while (*str++) |
| 651 | n++; |
| 673 | 652 | return n; |
| 674 | 653 | } |
| 675 | 654 | |
| r245117 | r245118 | |
| 696 | 675 | } |
| 697 | 676 | |
| 698 | 677 | // Pass data_size==0 for zero-terminated string |
| 699 | | // Try to replace with FNV1a hash? |
| 700 | | static ImU32 ImHash(const void* data, size_t data_size, ImU32 seed = 0) |
| 678 | static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed = 0) |
| 701 | 679 | { |
| 702 | 680 | static ImU32 crc32_lut[256] = { 0 }; |
| 703 | 681 | if (!crc32_lut[1]) |
| r245117 | r245118 | |
| 711 | 689 | crc32_lut[i] = crc; |
| 712 | 690 | } |
| 713 | 691 | } |
| 714 | | |
| 715 | | seed = ~seed; |
| 716 | | ImU32 crc = seed; |
| 692 | ImU32 crc = ~seed; |
| 717 | 693 | const unsigned char* current = (const unsigned char*)data; |
| 718 | 694 | |
| 719 | 695 | if (data_size > 0) |
| r245117 | r245118 | |
| 726 | 702 | { |
| 727 | 703 | // Zero-terminated string |
| 728 | 704 | while (unsigned char c = *current++) |
| 729 | | { |
| 730 | | // We support a syntax of "label###id" where only "###id" is included in the hash, and only "label" gets displayed. |
| 731 | | // Because this syntax is rarely used we are optimizing for the common case. |
| 732 | | // - If we reach ### in the string we discard the hash so far and reset to the seed. |
| 733 | | // - We don't do 'current += 2; continue;' after handling ### to keep the code smaller. |
| 734 | | if (c == '#' && current[0] == '#' && current[1] == '#') |
| 735 | | crc = seed; |
| 736 | | |
| 737 | 705 | crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c]; |
| 738 | | } |
| 739 | 706 | } |
| 740 | 707 | return ~crc; |
| 741 | 708 | } |
| r245117 | r245118 | |
| 874 | 841 | ImVec2 PreviousValue; |
| 875 | 842 | }; |
| 876 | 843 | |
| 877 | | struct ImGuiAabb // 2D axis aligned bounding-box |
| 844 | struct ImGuiAabb // 2D axis aligned bounding-box |
| 878 | 845 | { |
| 879 | 846 | ImVec2 Min; |
| 880 | 847 | ImVec2 Max; |
| r245117 | r245118 | |
| 920 | 887 | ImVector<float> TextWrapPos; |
| 921 | 888 | ImGuiColorEditMode ColorEditMode; |
| 922 | 889 | ImGuiStorage* StateStorage; |
| 890 | int OpenNextNode; // FIXME: Reformulate this feature like SetNextWindowCollapsed() API |
| 923 | 891 | |
| 924 | 892 | float ColumnsStartX; // Start position from left of window (increased by TreePush/TreePop, etc.) |
| 925 | 893 | float ColumnsOffsetX; // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API. |
| r245117 | r245118 | |
| 930 | 898 | float ColumnsCellMaxY; |
| 931 | 899 | bool ColumnsShowBorders; |
| 932 | 900 | ImGuiID ColumnsSetID; |
| 933 | | ImVector<float> ColumnsOffsetsT; // Columns offset normalized 0.0 (far left) -> 1.0 (far right) |
| 934 | 901 | |
| 935 | 902 | ImGuiDrawContext() |
| 936 | 903 | { |
| r245117 | r245118 | |
| 942 | 909 | LastItemAabb = ImGuiAabb(0.0f,0.0f,0.0f,0.0f); |
| 943 | 910 | LastItemHovered = false; |
| 944 | 911 | StateStorage = NULL; |
| 912 | OpenNextNode = -1; |
| 945 | 913 | |
| 946 | 914 | ColumnsStartX = 0.0f; |
| 947 | 915 | ColumnsOffsetX = 0.0f; |
| r245117 | r245118 | |
| 957 | 925 | // Internal state of the currently focused/edited text input box |
| 958 | 926 | struct ImGuiTextEditState |
| 959 | 927 | { |
| 960 | | ImGuiID Id; // widget id owning the text state |
| 961 | 928 | ImWchar Text[1024]; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so we copy into own buffer. |
| 962 | | char InitialText[1024*4+1]; // backup of end-user buffer at the time of focus (in UTF-8, unaltered) |
| 963 | | int CurLenA, CurLenW; // we need to maintain our buffer length in both UTF-8 and wchar format. |
| 964 | | size_t BufSizeA; // end-user buffer size, <= 1024 (or increase above) |
| 929 | char InitialText[1024*3+1]; // backup of end-user buffer at the time of focus (in UTF-8, unconverted) |
| 930 | size_t BufSize; // end-user buffer size, <= 1024 (or increase above) |
| 965 | 931 | float Width; // widget width |
| 966 | 932 | float ScrollX; |
| 967 | 933 | STB_TexteditState StbState; |
| 968 | 934 | float CursorAnim; |
| 969 | | ImVec2 InputCursorScreenPos; // Cursor position in screen space to be used by IME callback. |
| 935 | ImVec2 LastCursorPos; // Cursor position in screen space to be used by IME callback. |
| 970 | 936 | bool SelectedAllMouseLock; |
| 971 | 937 | ImFont* Font; |
| 972 | 938 | float FontSize; |
| r245117 | r245118 | |
| 988 | 954 | static void RenderTextScrolledClipped(ImFont* font, float font_size, const char* text, ImVec2 pos_base, float width, float scroll_x); |
| 989 | 955 | }; |
| 990 | 956 | |
| 991 | | // Data saved in imgui.ini file |
| 992 | 957 | struct ImGuiIniData |
| 993 | 958 | { |
| 994 | 959 | char* Name; |
| 995 | | ImGuiID ID; |
| 996 | 960 | ImVec2 Pos; |
| 997 | 961 | ImVec2 Size; |
| 998 | 962 | bool Collapsed; |
| r245117 | r245118 | |
| 1001 | 965 | ~ImGuiIniData() { if (Name) { ImGui::MemFree(Name); Name = NULL; } } |
| 1002 | 966 | }; |
| 1003 | 967 | |
| 1004 | | // Main state for ImGui |
| 1005 | 968 | struct ImGuiState |
| 1006 | 969 | { |
| 1007 | 970 | bool Initialized; |
| r245117 | r245118 | |
| 1024 | 987 | ImGuiID ActiveId; |
| 1025 | 988 | ImGuiID ActiveIdPreviousFrame; |
| 1026 | 989 | bool ActiveIdIsAlive; |
| 1027 | | bool ActiveIdIsFocusedOnly; // Set only by active widget. Denote focus but no active interaction. |
| 1028 | | ImGuiWindow* MovedWindow; // Track the child window we clicked on to move a window. Only valid if ActiveID is the "#MOVE" identifier of a window. |
| 1029 | 990 | float SettingsDirtyTimer; |
| 1030 | 991 | ImVector<ImGuiIniData*> Settings; |
| 1031 | 992 | ImVector<ImGuiColMod> ColorModifiers; |
| 1032 | 993 | ImVector<ImGuiStyleMod> StyleModifiers; |
| 1033 | 994 | ImVector<ImFont*> FontStack; |
| 1034 | | |
| 1035 | 995 | ImVec2 SetNextWindowPosVal; |
| 1036 | | ImGuiSetCond SetNextWindowPosCond; |
| 996 | ImGuiSetCondition SetNextWindowPosCond; |
| 1037 | 997 | ImVec2 SetNextWindowSizeVal; |
| 1038 | | ImGuiSetCond SetNextWindowSizeCond; |
| 998 | ImGuiSetCondition SetNextWindowSizeCond; |
| 1039 | 999 | bool SetNextWindowCollapsedVal; |
| 1040 | | ImGuiSetCond SetNextWindowCollapsedCond; |
| 1041 | | bool SetNextWindowFocus; |
| 1042 | | bool SetNextTreeNodeOpenedVal; |
| 1043 | | ImGuiSetCond SetNextTreeNodeOpenedCond; |
| 1000 | ImGuiSetCondition SetNextWindowCollapsedCond; |
| 1044 | 1001 | |
| 1045 | 1002 | // Render |
| 1046 | 1003 | ImVector<ImDrawList*> RenderDrawLists; |
| r245117 | r245118 | |
| 1051 | 1008 | ImGuiID SliderAsInputTextId; |
| 1052 | 1009 | ImGuiStorage ColorEditModeStorage; // for user selection |
| 1053 | 1010 | ImGuiID ActiveComboID; |
| 1054 | | float ScrollbarClickDeltaToGrabCenter; // distance between mouse and center of grab box, normalized in parent space |
| 1055 | 1011 | char Tooltip[1024]; |
| 1056 | 1012 | char* PrivateClipboard; // if no custom clipboard handler is defined |
| 1057 | 1013 | |
| r245117 | r245118 | |
| 1062 | 1018 | int LogStartDepth; |
| 1063 | 1019 | int LogAutoExpandMaxDepth; |
| 1064 | 1020 | |
| 1065 | | // Misc |
| 1066 | | float FramerateSecPerFrame[120]; // calculate estimate of framerate for user |
| 1067 | | int FramerateSecPerFrameIdx; |
| 1068 | | float FramerateSecPerFrameAccum; |
| 1069 | | |
| 1070 | 1021 | ImGuiState() |
| 1071 | 1022 | { |
| 1072 | 1023 | Initialized = false; |
| 1073 | | Font = NULL; |
| 1074 | | FontSize = 0.0f; |
| 1075 | | FontTexUvWhitePixel = ImVec2(0.0f, 0.0f); |
| 1076 | | |
| 1077 | 1024 | Time = 0.0f; |
| 1078 | 1025 | FrameCount = 0; |
| 1079 | 1026 | FrameCountRendered = -1; |
| r245117 | r245118 | |
| 1081 | 1028 | FocusedWindow = NULL; |
| 1082 | 1029 | HoveredWindow = NULL; |
| 1083 | 1030 | HoveredRootWindow = NULL; |
| 1084 | | HoveredId = 0; |
| 1085 | | ActiveId = 0; |
| 1086 | | ActiveIdPreviousFrame = 0; |
| 1087 | 1031 | ActiveIdIsAlive = false; |
| 1088 | | ActiveIdIsFocusedOnly = false; |
| 1089 | | MovedWindow = NULL; |
| 1090 | 1032 | SettingsDirtyTimer = 0.0f; |
| 1091 | | |
| 1092 | 1033 | SetNextWindowPosVal = ImVec2(0.0f, 0.0f); |
| 1093 | 1034 | SetNextWindowPosCond = 0; |
| 1094 | 1035 | SetNextWindowSizeVal = ImVec2(0.0f, 0.0f); |
| 1095 | 1036 | SetNextWindowSizeCond = 0; |
| 1096 | 1037 | SetNextWindowCollapsedVal = false; |
| 1097 | 1038 | SetNextWindowCollapsedCond = 0; |
| 1098 | | SetNextWindowFocus = false; |
| 1099 | | SetNextTreeNodeOpenedVal = false; |
| 1100 | | SetNextTreeNodeOpenedCond = 0; |
| 1101 | | |
| 1102 | 1039 | SliderAsInputTextId = 0; |
| 1103 | 1040 | ActiveComboID = 0; |
| 1104 | | ScrollbarClickDeltaToGrabCenter = 0.0f; |
| 1105 | 1041 | memset(Tooltip, 0, sizeof(Tooltip)); |
| 1106 | 1042 | PrivateClipboard = NULL; |
| 1107 | | |
| 1108 | 1043 | LogEnabled = false; |
| 1109 | 1044 | LogFile = NULL; |
| 1110 | | LogClipboard = NULL; |
| 1111 | 1045 | LogStartDepth = 0; |
| 1112 | 1046 | LogAutoExpandMaxDepth = 2; |
| 1113 | | |
| 1114 | | memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame)); |
| 1115 | | FramerateSecPerFrameIdx = 0; |
| 1116 | | FramerateSecPerFrameAccum = 0.0f; |
| 1047 | LogClipboard = NULL; |
| 1117 | 1048 | } |
| 1118 | 1049 | }; |
| 1119 | 1050 | |
| r245117 | r245118 | |
| 1129 | 1060 | ImVec2 Pos; // Position rounded-up to nearest pixel |
| 1130 | 1061 | ImVec2 Size; // Current size (==SizeFull or collapsed title bar size) |
| 1131 | 1062 | ImVec2 SizeFull; // Size when non collapsed |
| 1132 | | ImVec2 SizeContents; // Size of contents (== extents reach of the drawing cursor) from previous frame |
| 1133 | | ImVec2 SizeContentsCurrent; // Size of contents, currently extending |
| 1063 | ImVec2 SizeContentsFit; // Size of contents (extents reach by the drawing cursor) - may not fit within Size. |
| 1134 | 1064 | float ScrollY; |
| 1135 | 1065 | float NextScrollY; |
| 1136 | 1066 | bool ScrollbarY; |
| r245117 | r245118 | |
| 1140 | 1070 | bool SkipItems; // == Visible && !Collapsed |
| 1141 | 1071 | int AutoFitFrames; |
| 1142 | 1072 | bool AutoFitOnlyGrows; |
| 1143 | | int SetWindowPosAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowPos() call is allowed with this particular flag. |
| 1144 | | int SetWindowSizeAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowSize() call is allowed with this particular flag. |
| 1145 | | int SetWindowCollapsedAllowFlags; // bit ImGuiSetCond_*** specify if SetWindowCollapsed() call is allowed with this particular flag. |
| 1073 | int SetWindowPosAllowFlags; // bit ImGuiSetCondition_*** specify if SetWindowPos() call is allowed with this particular flag. |
| 1074 | int SetWindowSizeAllowFlags; // bit ImGuiSetCondition_*** specify if SetWindowSize() call is allowed with this particular flag. |
| 1075 | int SetWindowCollapsedAllowFlags; // bit ImGuiSetCondition_*** specify if SetWindowCollapsed() call is allowed with this particular flag. |
| 1146 | 1076 | |
| 1147 | 1077 | ImGuiDrawContext DC; |
| 1148 | 1078 | ImVector<ImGuiID> IDStack; |
| 1149 | 1079 | ImVector<ImVec4> ClipRectStack; // Scissoring / clipping rectangle. x1, y1, x2, y2. |
| 1150 | | ImGuiAabb ClippedAabb; // = ClipRectStack.front() after setup in Begin() |
| 1151 | 1080 | int LastFrameDrawn; |
| 1152 | 1081 | float ItemWidthDefault; |
| 1153 | 1082 | ImGuiStorage StateStorage; |
| r245117 | r245118 | |
| 1180 | 1109 | ImVec2 CursorPos() const { return DC.CursorPos; } |
| 1181 | 1110 | float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : FontSize() + GImGui->Style.FramePadding.y * 2.0f; } |
| 1182 | 1111 | ImGuiAabb TitleBarAabb() const { return ImGuiAabb(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); } |
| 1183 | | ImVec2 WindowPadding() const { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders)) ? ImVec2(0,0) : GImGui->Style.WindowPadding; } |
| 1112 | ImVec2 WindowPadding() const { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders)) ? ImVec2(1,1) : GImGui->Style.WindowPadding; } |
| 1184 | 1113 | ImU32 Color(ImGuiCol idx, float a=1.f) const { ImVec4 c = GImGui->Style.Colors[idx]; c.w *= GImGui->Style.Alpha * a; return ImGui::ColorConvertFloat4ToU32(c); } |
| 1185 | 1114 | ImU32 Color(const ImVec4& col) const { ImVec4 c = col; c.w *= GImGui->Style.Alpha; return ImGui::ColorConvertFloat4ToU32(c); } |
| 1186 | 1115 | }; |
| 1187 | 1116 | |
| 1188 | | static inline ImGuiWindow* GetCurrentWindow() |
| 1117 | static ImGuiWindow* GetCurrentWindow() |
| 1189 | 1118 | { |
| 1190 | 1119 | ImGuiState& g = *GImGui; |
| 1191 | 1120 | IM_ASSERT(g.CurrentWindow != NULL); // ImGui::NewFrame() hasn't been called yet? |
| r245117 | r245118 | |
| 1193 | 1122 | return g.CurrentWindow; |
| 1194 | 1123 | } |
| 1195 | 1124 | |
| 1196 | | static inline ImGuiWindow* GetParentWindow() |
| 1197 | | { |
| 1198 | | ImGuiState& g = *GImGui; |
| 1199 | | IM_ASSERT(g.CurrentWindowStack.size() >= 2); |
| 1200 | | return g.CurrentWindowStack[g.CurrentWindowStack.size() - 2]; |
| 1201 | | } |
| 1202 | | |
| 1203 | 1125 | static void SetActiveId(ImGuiID id) |
| 1204 | 1126 | { |
| 1205 | 1127 | ImGuiState& g = *GImGui; |
| 1206 | 1128 | g.ActiveId = id; |
| 1207 | | g.ActiveIdIsFocusedOnly = false; |
| 1208 | 1129 | } |
| 1209 | 1130 | |
| 1210 | 1131 | static void RegisterAliveId(const ImGuiID& id) |
| r245117 | r245118 | |
| 1330 | 1251 | //----------------------------------------------------------------------------- |
| 1331 | 1252 | |
| 1332 | 1253 | // Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]" |
| 1333 | | ImGuiTextFilter::ImGuiTextFilter(const char* default_filter) |
| 1254 | ImGuiTextFilter::ImGuiTextFilter() |
| 1334 | 1255 | { |
| 1335 | | if (default_filter) |
| 1336 | | { |
| 1337 | | ImFormatString(InputBuf, IM_ARRAYSIZE(InputBuf), "%s", default_filter); |
| 1338 | | Build(); |
| 1339 | | } |
| 1340 | | else |
| 1341 | | { |
| 1342 | | InputBuf[0] = 0; |
| 1343 | | CountGrep = 0; |
| 1344 | | } |
| 1256 | InputBuf[0] = 0; |
| 1257 | CountGrep = 0; |
| 1345 | 1258 | } |
| 1346 | 1259 | |
| 1347 | 1260 | void ImGuiTextFilter::Draw(const char* label, float width) |
| 1348 | 1261 | { |
| 1349 | | if (width > 0.0f) |
| 1350 | | ImGui::PushItemWidth(width); |
| 1262 | ImGuiWindow* window = GetCurrentWindow(); |
| 1263 | if (width < 0.0f) |
| 1264 | { |
| 1265 | ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true); |
| 1266 | width = ImMax(window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x - (label_size.x + GImGui->Style.ItemSpacing.x*4), 10.0f); |
| 1267 | } |
| 1268 | ImGui::PushItemWidth(width); |
| 1351 | 1269 | ImGui::InputText(label, InputBuf, IM_ARRAYSIZE(InputBuf)); |
| 1352 | | if (width > 0.0f) |
| 1353 | | ImGui::PopItemWidth(); |
| 1270 | ImGui::PopItemWidth(); |
| 1354 | 1271 | Build(); |
| 1355 | 1272 | } |
| 1356 | 1273 | |
| r245117 | r245118 | |
| 1466 | 1383 | ImGuiWindow::ImGuiWindow(const char* name) |
| 1467 | 1384 | { |
| 1468 | 1385 | Name = ImStrdup(name); |
| 1469 | | ID = ImHash(name, 0); |
| 1386 | ID = GetID(name); |
| 1470 | 1387 | IDStack.push_back(ID); |
| 1471 | 1388 | |
| 1472 | | Flags = 0; |
| 1473 | 1389 | PosFloat = Pos = ImVec2(0.0f, 0.0f); |
| 1474 | 1390 | Size = SizeFull = ImVec2(0.0f, 0.0f); |
| 1475 | | SizeContents = SizeContentsCurrent = ImVec2(0.0f, 0.0f); |
| 1391 | SizeContentsFit = ImVec2(0.0f, 0.0f); |
| 1476 | 1392 | ScrollY = 0.0f; |
| 1477 | 1393 | NextScrollY = 0.0f; |
| 1478 | 1394 | ScrollbarY = false; |
| r245117 | r245118 | |
| 1482 | 1398 | SkipItems = false; |
| 1483 | 1399 | AutoFitFrames = -1; |
| 1484 | 1400 | AutoFitOnlyGrows = false; |
| 1485 | | SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiSetCond_Always | ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver; |
| 1401 | SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiSetCondition_Always | ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver; |
| 1486 | 1402 | |
| 1487 | 1403 | LastFrameDrawn = -1; |
| 1488 | 1404 | ItemWidthDefault = 0.0f; |
| r245117 | r245118 | |
| 1496 | 1412 | |
| 1497 | 1413 | DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList)); |
| 1498 | 1414 | new(DrawList) ImDrawList(); |
| 1499 | | RootWindow = NULL; |
| 1500 | 1415 | |
| 1501 | 1416 | FocusIdxAllCounter = FocusIdxTabCounter = -1; |
| 1502 | 1417 | FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = IM_INT_MAX; |
| r245117 | r245118 | |
| 1514 | 1429 | |
| 1515 | 1430 | ImGuiID ImGuiWindow::GetID(const char* str) |
| 1516 | 1431 | { |
| 1517 | | ImGuiID seed = IDStack.back(); |
| 1518 | | const ImGuiID id = ImHash(str, 0, seed); |
| 1432 | const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back(); |
| 1433 | const ImGuiID id = ImCrc32(str, 0, seed); |
| 1519 | 1434 | RegisterAliveId(id); |
| 1520 | 1435 | return id; |
| 1521 | 1436 | } |
| 1522 | 1437 | |
| 1523 | 1438 | ImGuiID ImGuiWindow::GetID(const void* ptr) |
| 1524 | 1439 | { |
| 1525 | | ImGuiID seed = IDStack.back(); |
| 1526 | | const ImGuiID id = ImHash(&ptr, sizeof(void*), seed); |
| 1440 | const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back(); |
| 1441 | const ImGuiID id = ImCrc32(&ptr, sizeof(void*), seed); |
| 1527 | 1442 | RegisterAliveId(id); |
| 1528 | 1443 | return id; |
| 1529 | 1444 | } |
| r245117 | r245118 | |
| 1595 | 1510 | static ImGuiIniData* FindWindowSettings(const char* name) |
| 1596 | 1511 | { |
| 1597 | 1512 | ImGuiState& g = *GImGui; |
| 1598 | | ImGuiID id = ImHash(name, 0); |
| 1599 | 1513 | for (size_t i = 0; i != g.Settings.size(); i++) |
| 1600 | 1514 | { |
| 1601 | 1515 | ImGuiIniData* ini = g.Settings[i]; |
| 1602 | | if (ini->ID == id) |
| 1516 | if (ImStricmp(ini->Name, name) == 0) |
| 1603 | 1517 | return ini; |
| 1604 | 1518 | } |
| 1605 | 1519 | return NULL; |
| r245117 | r245118 | |
| 1610 | 1524 | ImGuiIniData* ini = (ImGuiIniData*)ImGui::MemAlloc(sizeof(ImGuiIniData)); |
| 1611 | 1525 | new(ini) ImGuiIniData(); |
| 1612 | 1526 | ini->Name = ImStrdup(name); |
| 1613 | | ini->ID = ImHash(name, 0); |
| 1614 | 1527 | ini->Collapsed = false; |
| 1615 | 1528 | ini->Pos = ImVec2(FLT_MAX,FLT_MAX); |
| 1616 | 1529 | ini->Size = ImVec2(0,0); |
| r245117 | r245118 | |
| 1695 | 1608 | const ImGuiIniData* settings = g.Settings[i]; |
| 1696 | 1609 | if (settings->Pos.x == FLT_MAX) |
| 1697 | 1610 | continue; |
| 1698 | | const char* name = settings->Name; |
| 1699 | | if (const char* p = strstr(name, "###")) // Skip to the "###" marker if any. We don't skip past to match the behavior of GetID() |
| 1700 | | name = p; |
| 1701 | | fprintf(f, "[%s]\n", name); |
| 1611 | fprintf(f, "[%s]\n", settings->Name); |
| 1702 | 1612 | fprintf(f, "Pos=%d,%d\n", (int)settings->Pos.x, (int)settings->Pos.y); |
| 1703 | 1613 | fprintf(f, "Size=%d,%d\n", (int)settings->Size.x, (int)settings->Size.y); |
| 1704 | 1614 | fprintf(f, "Collapsed=%d\n", settings->Collapsed); |
| r245117 | r245118 | |
| 1805 | 1715 | for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++) |
| 1806 | 1716 | g.IO.KeysDownTime[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownTime[i] < 0.0f ? 0.0f : g.IO.KeysDownTime[i] + g.IO.DeltaTime) : -1.0f; |
| 1807 | 1717 | |
| 1808 | | // Calculate frame-rate for the user, as a purely luxurious feature |
| 1809 | | g.FramerateSecPerFrameAccum += g.IO.DeltaTime - g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx]; |
| 1810 | | g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx] = g.IO.DeltaTime; |
| 1811 | | g.FramerateSecPerFrameIdx = (g.FramerateSecPerFrameIdx + 1) % IM_ARRAYSIZE(g.FramerateSecPerFrame); |
| 1812 | | g.IO.Framerate = 1.0f / (g.FramerateSecPerFrameAccum / (float)IM_ARRAYSIZE(g.FramerateSecPerFrame)); |
| 1813 | | |
| 1814 | 1718 | // Clear reference to active widget if the widget isn't alive anymore |
| 1815 | 1719 | g.HoveredId = 0; |
| 1816 | 1720 | if (!g.ActiveIdIsAlive && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0) |
| 1817 | 1721 | SetActiveId(0); |
| 1818 | 1722 | g.ActiveIdPreviousFrame = g.ActiveId; |
| 1819 | 1723 | g.ActiveIdIsAlive = false; |
| 1820 | | if (!g.ActiveId) |
| 1821 | | g.MovedWindow = NULL; |
| 1822 | 1724 | |
| 1823 | 1725 | // Delay saving settings so we don't spam disk too much |
| 1824 | 1726 | if (g.SettingsDirtyTimer > 0.0f) |
| r245117 | r245118 | |
| 1893 | 1795 | } |
| 1894 | 1796 | |
| 1895 | 1797 | // Mark all windows as not visible |
| 1798 | // Clear root windows at this point. |
| 1896 | 1799 | for (size_t i = 0; i != g.Windows.size(); i++) |
| 1897 | 1800 | { |
| 1898 | 1801 | ImGuiWindow* window = g.Windows[i]; |
| 1899 | 1802 | window->Visible = false; |
| 1900 | 1803 | window->Accessed = false; |
| 1804 | window->RootWindow = NULL; |
| 1901 | 1805 | } |
| 1902 | 1806 | |
| 1903 | 1807 | // No window should be open at the beginning of the frame. |
| r245117 | r245118 | |
| 2028 | 1932 | g.CurrentWindow->Visible = false; |
| 2029 | 1933 | ImGui::End(); |
| 2030 | 1934 | |
| 2031 | | // Select window for move/focus when we're done with all our widgets (we use the root window ID here) |
| 1935 | // Select window for move/focus when we're done with all our widgets (we only consider non-child windows here) |
| 2032 | 1936 | if (g.ActiveId == 0 && g.HoveredId == 0 && g.HoveredRootWindow != NULL && g.IO.MouseClicked[0]) |
| 2033 | | { |
| 2034 | | IM_ASSERT(g.MovedWindow == NULL); |
| 2035 | | g.MovedWindow = g.HoveredWindow; |
| 2036 | 1937 | SetActiveId(g.HoveredRootWindow->GetID("#MOVE")); |
| 2037 | | } |
| 2038 | 1938 | |
| 2039 | 1939 | // Sort the window list so that all child windows are after their parent |
| 2040 | 1940 | // We cannot do that on FocusWindow() because childs may not exist yet |
| r245117 | r245118 | |
| 2110 | 2010 | static const char* FindTextDisplayEnd(const char* text, const char* text_end = NULL) |
| 2111 | 2011 | { |
| 2112 | 2012 | const char* text_display_end = text; |
| 2113 | | if (!text_end) |
| 2114 | | text_end = (const char*)-1; |
| 2115 | | while (text_display_end < text_end && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#')) |
| 2013 | while ((!text_end || text_display_end < text_end) && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#')) |
| 2116 | 2014 | text_display_end++; |
| 2117 | 2015 | return text_display_end; |
| 2118 | 2016 | } |
| r245117 | r245118 | |
| 2319 | 2217 | |
| 2320 | 2218 | if (shadow && (window->Flags & ImGuiWindowFlags_ShowBorders) != 0) |
| 2321 | 2219 | window->DrawList->AddTriangleFilled(a+ImVec2(2,2), b+ImVec2(2,2), c+ImVec2(2,2), window->Color(ImGuiCol_BorderShadow)); |
| 2322 | | window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Text)); |
| 2220 | window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Border)); |
| 2323 | 2221 | } |
| 2324 | 2222 | |
| 2325 | 2223 | // Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker. |
| r245117 | r245118 | |
| 2396 | 2294 | continue; |
| 2397 | 2295 | if (excluding_childs && (window->Flags & ImGuiWindowFlags_ChildWindow) != 0) |
| 2398 | 2296 | continue; |
| 2399 | | |
| 2400 | | // Using the clipped AABB so a child window will typically be clipped by its parent. |
| 2401 | | ImGuiAabb bb(window->ClippedAabb.Min - g.Style.TouchExtraPadding, window->ClippedAabb.Max + g.Style.TouchExtraPadding); |
| 2297 | ImGuiAabb bb(window->Pos - g.Style.TouchExtraPadding, window->Pos + window->Size + g.Style.TouchExtraPadding); |
| 2402 | 2298 | if (bb.Contains(pos)) |
| 2403 | 2299 | return window; |
| 2404 | 2300 | } |
| r245117 | r245118 | |
| 2408 | 2304 | // Test if mouse cursor is hovering given aabb |
| 2409 | 2305 | // NB- Box is clipped by our current clip setting |
| 2410 | 2306 | // NB- Expand the aabb to be generous on imprecise inputs systems (g.Style.TouchExtraPadding) |
| 2411 | | static bool IsMouseHoveringBox(const ImGuiAabb& bb) |
| 2307 | static bool IsMouseHoveringBox(const ImGuiAabb& box) |
| 2412 | 2308 | { |
| 2413 | 2309 | ImGuiState& g = *GImGui; |
| 2414 | 2310 | ImGuiWindow* window = GetCurrentWindow(); |
| 2415 | 2311 | |
| 2416 | 2312 | // Clip |
| 2417 | | ImGuiAabb box_clipped = bb; |
| 2313 | ImGuiAabb box_clipped = box; |
| 2418 | 2314 | if (!window->ClipRectStack.empty()) |
| 2419 | 2315 | { |
| 2420 | 2316 | const ImVec4 clip_rect = window->ClipRectStack.back(); |
| r245117 | r245118 | |
| 2521 | 2417 | return false; |
| 2522 | 2418 | } |
| 2523 | 2419 | |
| 2524 | | bool ImGui::IsAnyItemActive() |
| 2525 | | { |
| 2526 | | ImGuiState& g = *GImGui; |
| 2527 | | return g.ActiveId != 0; |
| 2528 | | } |
| 2529 | | |
| 2530 | 2420 | ImVec2 ImGui::GetItemBoxMin() |
| 2531 | 2421 | { |
| 2532 | 2422 | ImGuiWindow* window = GetCurrentWindow(); |
| r245117 | r245118 | |
| 2577 | 2467 | ImGui::End(); |
| 2578 | 2468 | } |
| 2579 | 2469 | |
| 2580 | | bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags) |
| 2470 | void ImGui::BeginChild(ImGuiID id, ImVec2 size, bool border, ImGuiWindowFlags extra_flags) |
| 2581 | 2471 | { |
| 2472 | char str_id[32]; |
| 2473 | ImFormatString(str_id, IM_ARRAYSIZE(str_id), "child_%x", id); |
| 2474 | ImGui::BeginChild(str_id, size, border, extra_flags); |
| 2475 | } |
| 2476 | |
| 2477 | void ImGui::BeginChild(const char* str_id, ImVec2 size, bool border, ImGuiWindowFlags extra_flags) |
| 2478 | { |
| 2582 | 2479 | ImGuiState& g = *GImGui; |
| 2583 | 2480 | ImGuiWindow* window = GetCurrentWindow(); |
| 2584 | 2481 | |
| r245117 | r245118 | |
| 2586 | 2483 | |
| 2587 | 2484 | const ImVec2 content_max = window->Pos + ImGui::GetContentRegionMax(); |
| 2588 | 2485 | const ImVec2 cursor_pos = window->Pos + ImGui::GetCursorPos(); |
| 2589 | | ImVec2 size = size_arg; |
| 2590 | 2486 | if (size.x <= 0.0f) |
| 2591 | 2487 | { |
| 2592 | 2488 | if (size.x == 0.0f) |
| r245117 | r245118 | |
| 2607 | 2503 | ImFormatString(title, IM_ARRAYSIZE(title), "%s.%s", window->Name, str_id); |
| 2608 | 2504 | |
| 2609 | 2505 | const float alpha = 1.0f; |
| 2610 | | bool ret = ImGui::Begin(title, NULL, size, alpha, flags); |
| 2506 | ImGui::Begin(title, NULL, size, alpha, flags); |
| 2611 | 2507 | |
| 2612 | 2508 | if (!(window->Flags & ImGuiWindowFlags_ShowBorders)) |
| 2613 | 2509 | g.CurrentWindow->Flags &= ~ImGuiWindowFlags_ShowBorders; |
| 2614 | | |
| 2615 | | return ret; |
| 2616 | 2510 | } |
| 2617 | 2511 | |
| 2618 | | bool ImGui::BeginChild(ImGuiID id, const ImVec2& size, bool border, ImGuiWindowFlags extra_flags) |
| 2619 | | { |
| 2620 | | char str_id[32]; |
| 2621 | | ImFormatString(str_id, IM_ARRAYSIZE(str_id), "child_%x", id); |
| 2622 | | bool ret = ImGui::BeginChild(str_id, size, border, extra_flags); |
| 2623 | | return ret; |
| 2624 | | } |
| 2625 | | |
| 2626 | 2512 | void ImGui::EndChild() |
| 2627 | 2513 | { |
| 2628 | 2514 | ImGuiWindow* window = GetCurrentWindow(); |
| r245117 | r245118 | |
| 2642 | 2528 | sz.y = 0; |
| 2643 | 2529 | |
| 2644 | 2530 | ImGui::End(); |
| 2645 | | |
| 2646 | | window = GetCurrentWindow(); |
| 2647 | | ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + sz); |
| 2648 | 2531 | ItemSize(sz); |
| 2649 | | ItemAdd(bb, NULL); |
| 2650 | 2532 | } |
| 2651 | 2533 | } |
| 2652 | 2534 | |
| r245117 | r245118 | |
| 2669 | 2551 | |
| 2670 | 2552 | static ImGuiWindow* FindWindowByName(const char* name) |
| 2671 | 2553 | { |
| 2672 | | // FIXME-OPT: Store sorted hashes -> pointers. |
| 2554 | // FIXME-OPT: Consider optimizing this (e.g. sorted hashes to window pointers) |
| 2673 | 2555 | ImGuiState& g = *GImGui; |
| 2674 | | ImGuiID id = ImHash(name, 0); |
| 2675 | | for (size_t i = 0; i < g.Windows.size(); i++) |
| 2676 | | if (g.Windows[i]->ID == id) |
| 2556 | for (size_t i = 0; i != g.Windows.size(); i++) |
| 2557 | if (strcmp(g.Windows[i]->Name, name) == 0) |
| 2677 | 2558 | return g.Windows[i]; |
| 2678 | 2559 | return NULL; |
| 2679 | 2560 | } |
| r245117 | r245118 | |
| 2706 | 2587 | } |
| 2707 | 2588 | else |
| 2708 | 2589 | { |
| 2709 | | window->SetWindowPosAllowFlags &= ~ImGuiSetCond_FirstUseEver; |
| 2710 | | window->SetWindowSizeAllowFlags &= ~ImGuiSetCond_FirstUseEver; |
| 2711 | | window->SetWindowCollapsedAllowFlags &= ~ImGuiSetCond_FirstUseEver; |
| 2590 | window->SetWindowPosAllowFlags &= ~ImGuiSetCondition_FirstUseEver; |
| 2591 | window->SetWindowSizeAllowFlags &= ~ImGuiSetCondition_FirstUseEver; |
| 2592 | window->SetWindowCollapsedAllowFlags &= ~ImGuiSetCondition_FirstUseEver; |
| 2712 | 2593 | } |
| 2713 | 2594 | |
| 2714 | 2595 | if (settings->Pos.x != FLT_MAX) |
| r245117 | r245118 | |
| 2727 | 2608 | } |
| 2728 | 2609 | |
| 2729 | 2610 | // Push a new ImGui window to add widgets to. |
| 2730 | | // - 'size' for a regular window denote the initial size for first-time creation (no saved data) and isn't that useful. Use SetNextWindowSize() prior to calling Begin() for more flexible window manipulation. |
| 2731 | | // - A default window called "Debug" is automatically stacked at the beginning of every frame so you can use widgets without explicitly calling a Begin/End pair. |
| 2732 | | // - Begin/End can be called multiple times during the frame with the same window name to append content. |
| 2733 | | // - The window name is used as a unique identifier to preserve window information across frames (and save rudimentary information to the .ini file). |
| 2734 | | // You can use the "##" or "###" markers to use the same label with different id, or same id with different label. See documentation at the top of this file. |
| 2611 | // - A default window called "Debug" is automatically stacked at the beginning of every frame. |
| 2612 | // - This can be called multiple times during the frame with the same window name to append content to the same window. |
| 2613 | // - The window name is used as a unique identifier to preserve window information across frames (and save rudimentary information to the .ini file). Note that you can use ## to append unique data that isn't displayed, e.g. "My window##1" will use "My window##1" as unique window ID but display "My window" to the user. |
| 2735 | 2614 | // - Return false when window is collapsed, so you can early out in your code. You always need to call ImGui::End() even if false is returned. |
| 2736 | 2615 | // - Passing 'bool* p_opened' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed. |
| 2737 | | // - Passing non-zero 'size' is roughly equivalent to calling SetNextWindowSize(size, ImGuiSetCond_FirstUseEver) prior to calling Begin(). |
| 2738 | | bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg_alpha, ImGuiWindowFlags flags) |
| 2616 | // - Passing non-zero 'size' is roughly equivalent to calling SetNextWindowSize(size, ImGuiSetCondition_FirstUseEver) prior to calling Begin(). |
| 2617 | bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alpha, ImGuiWindowFlags flags) |
| 2739 | 2618 | { |
| 2740 | 2619 | ImGuiState& g = *GImGui; |
| 2741 | 2620 | const ImGuiStyle& style = g.Style; |
| r245117 | r245118 | |
| 2772 | 2651 | ImGui::SetWindowCollapsed(g.SetNextWindowCollapsedVal, g.SetNextWindowCollapsedCond); |
| 2773 | 2652 | g.SetNextWindowCollapsedCond = 0; |
| 2774 | 2653 | } |
| 2775 | | if (g.SetNextWindowFocus) |
| 2776 | | { |
| 2777 | | ImGui::SetWindowFocus(); |
| 2778 | | g.SetNextWindowFocus = false; |
| 2779 | | } |
| 2780 | 2654 | |
| 2781 | 2655 | // Find parent |
| 2782 | 2656 | ImGuiWindow* parent_window = (flags & ImGuiWindowFlags_ChildWindow) != 0 ? g.CurrentWindowStack[g.CurrentWindowStack.size()-2] : NULL; |
| 2783 | 2657 | |
| 2784 | | // Update known root window (if we are a child window, otherwise window == window->RootWindow) |
| 2658 | // Find root (if we are a child window) |
| 2785 | 2659 | size_t root_idx = g.CurrentWindowStack.size() - 1; |
| 2786 | 2660 | while (root_idx > 0) |
| 2787 | 2661 | { |
| r245117 | r245118 | |
| 2792 | 2666 | window->RootWindow = g.CurrentWindowStack[root_idx]; |
| 2793 | 2667 | |
| 2794 | 2668 | // Default alpha |
| 2795 | | if (bg_alpha < 0.0f) |
| 2796 | | bg_alpha = style.WindowFillAlphaDefault; |
| 2669 | if (fill_alpha < 0.0f) |
| 2670 | fill_alpha = style.WindowFillAlphaDefault; |
| 2797 | 2671 | |
| 2798 | 2672 | // When reusing window again multiple times a frame, just append content (don't need to setup again) |
| 2799 | 2673 | const int current_frame = ImGui::GetFrameCount(); |
| r245117 | r245118 | |
| 2810 | 2684 | window->LastFrameDrawn = current_frame; |
| 2811 | 2685 | window->ClipRectStack.resize(0); |
| 2812 | 2686 | |
| 2813 | | // Reset contents size for auto-fitting |
| 2814 | | window->SizeContents = window->SizeContentsCurrent; |
| 2815 | | window->SizeContentsCurrent = ImVec2(0.0f, 0.0f); |
| 2816 | | |
| 2817 | 2687 | if (flags & ImGuiWindowFlags_ChildWindow) |
| 2818 | 2688 | { |
| 2819 | 2689 | parent_window->DC.ChildWindows.push_back(window); |
| r245117 | r245118 | |
| 2836 | 2706 | // Setup and draw window |
| 2837 | 2707 | if (first_begin_of_the_frame) |
| 2838 | 2708 | { |
| 2839 | | // Reset ID stack |
| 2840 | | window->IDStack.resize(1); |
| 2709 | // Seed ID stack with our window pointer |
| 2710 | window->IDStack.resize(0); |
| 2711 | ImGui::PushID(window); |
| 2841 | 2712 | |
| 2842 | | // Move window (at the beginning of the frame to avoid input lag or sheering). Only valid for root windows. |
| 2713 | // Move window (at the beginning of the frame to avoid input lag or sheering) |
| 2843 | 2714 | const ImGuiID move_id = window->GetID("#MOVE"); |
| 2844 | 2715 | RegisterAliveId(move_id); |
| 2845 | 2716 | if (g.ActiveId == move_id) |
| r245117 | r245118 | |
| 2852 | 2723 | if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings)) |
| 2853 | 2724 | MarkSettingsDirty(); |
| 2854 | 2725 | } |
| 2855 | | IM_ASSERT(g.MovedWindow != NULL); |
| 2856 | | FocusWindow(g.MovedWindow); |
| 2726 | FocusWindow(window); |
| 2857 | 2727 | } |
| 2858 | 2728 | else |
| 2859 | 2729 | { |
| 2860 | 2730 | SetActiveId(0); |
| 2861 | | g.MovedWindow = NULL; // Not strictly necessary but doing it for sanity. |
| 2862 | 2731 | } |
| 2863 | 2732 | } |
| 2864 | 2733 | |
| r245117 | r245118 | |
| 2908 | 2777 | window->ScrollY = window->NextScrollY; |
| 2909 | 2778 | window->ScrollY = ImMax(window->ScrollY, 0.0f); |
| 2910 | 2779 | if (!window->Collapsed && !window->SkipItems) |
| 2911 | | window->ScrollY = ImMin(window->ScrollY, ImMax(0.0f, window->SizeContents.y - window->SizeFull.y)); |
| 2780 | window->ScrollY = ImMin(window->ScrollY, ImMax(0.0f, (float)window->SizeContentsFit.y - window->SizeFull.y)); |
| 2912 | 2781 | window->NextScrollY = window->ScrollY; |
| 2913 | 2782 | |
| 2914 | 2783 | // At this point we don't have a clipping rectangle setup yet, so we can test and draw in title bar |
| r245117 | r245118 | |
| 2948 | 2817 | if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0) |
| 2949 | 2818 | { |
| 2950 | 2819 | // Tooltip always resize. We keep the spacing symmetric on both axises for aesthetic purpose. |
| 2951 | | const ImVec2 size_auto_fit = window->SizeContents + style.WindowPadding - ImVec2(0.0f, style.ItemSpacing.y); |
| 2820 | const ImVec2 size_auto_fit = window->SizeContentsFit + style.WindowPadding - ImVec2(0.0f, style.ItemSpacing.y); |
| 2952 | 2821 | window->SizeFull = size_auto_fit; |
| 2953 | 2822 | } |
| 2954 | 2823 | else |
| 2955 | 2824 | { |
| 2956 | | const ImVec2 size_auto_fit = ImClamp(window->SizeContents + style.AutoFitPadding, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding)); |
| 2825 | const ImVec2 size_auto_fit = ImClamp(window->SizeContentsFit + style.AutoFitPadding, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding)); |
| 2957 | 2826 | if ((window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0) |
| 2958 | 2827 | { |
| 2959 | 2828 | // Don't continuously mark settings as dirty, the size of the window doesn't need to be stored. |
| r245117 | r245118 | |
| 2973 | 2842 | { |
| 2974 | 2843 | // Manual resize grip |
| 2975 | 2844 | const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR()); |
| 2976 | | const ImGuiID resize_id = window->GetID("#RESIZE"); |
| 2845 | const ImGuiID resize_id = window->GetID("##RESIZE"); |
| 2977 | 2846 | bool hovered, held; |
| 2978 | 2847 | ButtonBehaviour(resize_aabb, resize_id, &hovered, &held, true); |
| 2979 | 2848 | resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip); |
| r245117 | r245118 | |
| 3001 | 2870 | } |
| 3002 | 2871 | |
| 3003 | 2872 | // Scrollbar |
| 3004 | | window->ScrollbarY = (window->SizeContents.y > window->Size.y) && !(window->Flags & ImGuiWindowFlags_NoScrollbar); |
| 2873 | window->ScrollbarY = (window->SizeContentsFit.y > window->Size.y) && !(window->Flags & ImGuiWindowFlags_NoScrollbar); |
| 3005 | 2874 | |
| 3006 | 2875 | // Window background |
| 3007 | | if (bg_alpha > 0.0f) |
| 2876 | if (fill_alpha > 0.0f) |
| 3008 | 2877 | { |
| 3009 | 2878 | if ((window->Flags & ImGuiWindowFlags_ComboBox) != 0) |
| 3010 | | window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_ComboBg, bg_alpha), window_rounding); |
| 2879 | window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_ComboBg, fill_alpha), window_rounding); |
| 3011 | 2880 | else if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0) |
| 3012 | | window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_TooltipBg, bg_alpha), window_rounding); |
| 2881 | window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_TooltipBg, fill_alpha), window_rounding); |
| 3013 | 2882 | else if ((window->Flags & ImGuiWindowFlags_ChildWindow) != 0) |
| 3014 | | window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size-ImVec2(window->ScrollbarY?style.ScrollbarWidth:0.0f,0.0f), window->Color(ImGuiCol_ChildWindowBg, bg_alpha), window_rounding, window->ScrollbarY ? (1|8) : (0xF)); |
| 2883 | window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size-ImVec2(window->ScrollbarY?style.ScrollBarWidth:0.0f,0.0f), window->Color(ImGuiCol_ChildWindowBg, fill_alpha), window_rounding, window->ScrollbarY ? (1|8) : (0xF)); |
| 3015 | 2884 | else |
| 3016 | | window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, bg_alpha), window_rounding); |
| 2885 | window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, fill_alpha), window_rounding); |
| 3017 | 2886 | } |
| 3018 | 2887 | |
| 3019 | 2888 | // Title bar |
| r245117 | r245118 | |
| 3031 | 2900 | |
| 3032 | 2901 | // Scrollbar |
| 3033 | 2902 | if (window->ScrollbarY) |
| 3034 | | Scrollbar(window); |
| 2903 | { |
| 2904 | ImGuiAabb scrollbar_bb(window->Aabb().Max.x - style.ScrollBarWidth, title_bar_aabb.Max.y+1, window->Aabb().Max.x, window->Aabb().Max.y-1); |
| 2905 | //window->DrawList->AddLine(scrollbar_bb.GetTL(), scrollbar_bb.GetBL(), g.Colors[ImGuiCol_Border]); |
| 2906 | window->DrawList->AddRectFilled(scrollbar_bb.Min, scrollbar_bb.Max, window->Color(ImGuiCol_ScrollbarBg)); |
| 2907 | scrollbar_bb.Expand(ImVec2(-3,-3)); |
| 3035 | 2908 | |
| 2909 | const float grab_size_y_norm = ImSaturate(window->Size.y / ImMax(window->SizeContentsFit.y, window->Size.y)); |
| 2910 | const float grab_size_y = scrollbar_bb.GetHeight() * grab_size_y_norm; |
| 2911 | |
| 2912 | // Handle input right away (none of the code above is relying on scrolling position) |
| 2913 | bool held = false; |
| 2914 | bool hovered = false; |
| 2915 | if (grab_size_y_norm < 1.0f) |
| 2916 | { |
| 2917 | const ImGuiID scrollbar_id = window->GetID("#SCROLLY"); |
| 2918 | ButtonBehaviour(scrollbar_bb, scrollbar_id, &hovered, &held, true); |
| 2919 | if (held) |
| 2920 | { |
| 2921 | g.HoveredId = scrollbar_id; |
| 2922 | const float pos_y_norm = ImSaturate((g.IO.MousePos.y - (scrollbar_bb.Min.y + grab_size_y*0.5f)) / (scrollbar_bb.GetHeight() - grab_size_y)) * (1.0f - grab_size_y_norm); |
| 2923 | window->ScrollY = (float)(int)(pos_y_norm * window->SizeContentsFit.y); |
| 2924 | window->NextScrollY = window->ScrollY; |
| 2925 | } |
| 2926 | } |
| 2927 | |
| 2928 | // Normalized height of the grab |
| 2929 | const float pos_y_norm = ImSaturate(window->ScrollY / ImMax(0.0f, window->SizeContentsFit.y)); |
| 2930 | const ImU32 grab_col = window->Color(held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab); |
| 2931 | window->DrawList->AddRectFilled( |
| 2932 | ImVec2(scrollbar_bb.Min.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y, pos_y_norm)), |
| 2933 | ImVec2(scrollbar_bb.Max.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y, pos_y_norm + grab_size_y_norm)), grab_col); |
| 2934 | } |
| 2935 | |
| 3036 | 2936 | // Render resize grip |
| 3037 | 2937 | // (after the input handling so we don't have a frame of latency) |
| 3038 | 2938 | if (!(window->Flags & ImGuiWindowFlags_NoResize)) |
| r245117 | r245118 | |
| 3075 | 2975 | window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.ColumnsStartPos.y; |
| 3076 | 2976 | window->DC.TreeDepth = 0; |
| 3077 | 2977 | window->DC.StateStorage = &window->StateStorage; |
| 2978 | window->DC.OpenNextNode = -1; |
| 3078 | 2979 | |
| 2980 | // Reset contents size for auto-fitting |
| 2981 | window->SizeContentsFit = ImVec2(0.0f, 0.0f); |
| 3079 | 2982 | if (window->AutoFitFrames > 0) |
| 3080 | 2983 | window->AutoFitFrames--; |
| 3081 | 2984 | |
| r245117 | r245118 | |
| 3096 | 2999 | const ImVec2 text_max = window->Pos + ImVec2(window->Size.x - (p_opened ? (title_bar_aabb.GetHeight()-3) : style.FramePadding.x), style.FramePadding.y*2 + text_size.y); |
| 3097 | 3000 | RenderTextClipped(text_min, name, NULL, &text_size, text_max); |
| 3098 | 3001 | } |
| 3099 | | |
| 3100 | | // Save clipped aabb so we can access it in constant-time in FindHoveredWindow() |
| 3101 | | window->ClippedAabb = window->Aabb(); |
| 3102 | | window->ClippedAabb.Clip(window->ClipRectStack.front()); |
| 3103 | 3002 | } |
| 3104 | 3003 | |
| 3105 | 3004 | // Inner clipping rectangle |
| r245117 | r245118 | |
| 3107 | 3006 | const ImGuiAabb title_bar_aabb = window->TitleBarAabb(); |
| 3108 | 3007 | ImVec4 clip_rect(title_bar_aabb.Min.x+0.5f+window->WindowPadding().x*0.5f, title_bar_aabb.Max.y+0.5f, window->Aabb().Max.x+0.5f-window->WindowPadding().x*0.5f, window->Aabb().Max.y-1.5f); |
| 3109 | 3008 | if (window->ScrollbarY) |
| 3110 | | clip_rect.z -= style.ScrollbarWidth; |
| 3009 | clip_rect.z -= style.ScrollBarWidth; |
| 3111 | 3010 | PushClipRect(clip_rect); |
| 3112 | 3011 | |
| 3113 | 3012 | // Clear 'accessed' flag last thing |
| r245117 | r245118 | |
| 3119 | 3018 | if (flags & ImGuiWindowFlags_ChildWindow) |
| 3120 | 3019 | { |
| 3121 | 3020 | IM_ASSERT((flags & ImGuiWindowFlags_NoTitleBar) != 0); |
| 3122 | | window->Collapsed = parent_window && parent_window->Collapsed; |
| 3123 | | |
| 3124 | 3021 | const ImVec4 clip_rect_t = window->ClipRectStack.back(); |
| 3125 | | window->Collapsed |= (clip_rect_t.x >= clip_rect_t.z || clip_rect_t.y >= clip_rect_t.w); |
| 3022 | window->Collapsed = (clip_rect_t.x >= clip_rect_t.z || clip_rect_t.y >= clip_rect_t.w); |
| 3126 | 3023 | |
| 3127 | 3024 | // We also hide the window from rendering because we've already added its border to the command list. |
| 3128 | 3025 | // (we could perform the check earlier in the function but it is simpler at this point) |
| r245117 | r245118 | |
| 3152 | 3049 | ImGui::LogFinish(); |
| 3153 | 3050 | |
| 3154 | 3051 | // Pop |
| 3155 | | // NB: we don't clear 'window->RootWindow'. The pointer is allowed to live until the next call to Begin(). |
| 3052 | // NB: we don't clear 'window->RootWindow' yet, it will be used then cleared in NewFrame() |
| 3156 | 3053 | g.CurrentWindowStack.pop_back(); |
| 3157 | 3054 | g.CurrentWindow = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back(); |
| 3158 | 3055 | } |
| 3159 | 3056 | |
| 3160 | | // Vertical scrollbar |
| 3161 | | // The entire piece of code below is rather confusing because: |
| 3162 | | // - We handle absolute seeking (when first clicking outside the grab) and relative manipulation (afterward or when clicking inside the grab) |
| 3163 | | // - We store values as ratio and in a form that allows the window content to change while we are holding on a scrollbar |
| 3164 | | static void Scrollbar(ImGuiWindow* window) |
| 3165 | | { |
| 3166 | | ImGuiState& g = *GImGui; |
| 3167 | | const ImGuiStyle& style = g.Style; |
| 3168 | | const ImGuiID id = window->GetID("#SCROLLY"); |
| 3169 | | |
| 3170 | | // Render background |
| 3171 | | ImGuiAabb bb(window->Aabb().Max.x - style.ScrollbarWidth, window->Pos.y + window->TitleBarHeight()+1, window->Aabb().Max.x, window->Aabb().Max.y-1); |
| 3172 | | window->DrawList->AddRectFilled(bb.Min, bb.Max, window->Color(ImGuiCol_ScrollbarBg)); |
| 3173 | | bb.Expand(ImVec2(-3,-3)); |
| 3174 | | const float scrollbar_height = bb.GetHeight(); |
| 3175 | | |
| 3176 | | // The grabable box size generally represent the amount visible (vs the total scrollable amount) |
| 3177 | | // But we maintain a minimum size in pixel to allow for the user to still aim inside. |
| 3178 | | const float grab_h_pixels = ImMax(style.GrabMinSize, scrollbar_height * ImSaturate(window->Size.y / ImMax(window->SizeContents.y, window->Size.y))); |
| 3179 | | const float grab_h_norm = grab_h_pixels / scrollbar_height; |
| 3180 | | |
| 3181 | | // Handle input right away. None of the code of Begin() is relying on scrolling position before calling Scrollbar(). |
| 3182 | | bool held = false; |
| 3183 | | bool hovered = false; |
| 3184 | | const bool previously_held = (g.ActiveId == id); |
| 3185 | | ButtonBehaviour(bb, id, &hovered, &held, true); |
| 3186 | | |
| 3187 | | const float scroll_max = ImMax(1.0f, window->SizeContents.y - window->Size.y); |
| 3188 | | float scroll_ratio = ImSaturate(window->ScrollY / scroll_max); |
| 3189 | | float grab_y_norm = scroll_ratio * (scrollbar_height - grab_h_pixels) / scrollbar_height; |
| 3190 | | if (held) |
| 3191 | | { |
| 3192 | | const float clicked_y_norm = ImSaturate((g.IO.MousePos.y - bb.Min.y) / scrollbar_height); // Click position in scrollbar space (0.0f->1.0f) |
| 3193 | | g.HoveredId = id; |
| 3194 | | |
| 3195 | | bool seek_absolute = false; |
| 3196 | | if (!previously_held) |
| 3197 | | { |
| 3198 | | // On initial click calculate the distance between mouse and the center of the grab |
| 3199 | | if (clicked_y_norm >= grab_y_norm && clicked_y_norm <= grab_y_norm + grab_h_norm) |
| 3200 | | { |
| 3201 | | g.ScrollbarClickDeltaToGrabCenter = clicked_y_norm - grab_y_norm - grab_h_norm*0.5f; |
| 3202 | | } |
| 3203 | | else |
| 3204 | | { |
| 3205 | | seek_absolute = true; |
| 3206 | | g.ScrollbarClickDeltaToGrabCenter = 0; |
| 3207 | | } |
| 3208 | | } |
| 3209 | | |
| 3210 | | // Apply scroll |
| 3211 | | const float scroll_y_norm = ImSaturate((clicked_y_norm - g.ScrollbarClickDeltaToGrabCenter - grab_h_norm*0.5f) / (1.0f - grab_h_norm)); |
| 3212 | | window->ScrollY = (float)(int)(0.5f + scroll_y_norm * (window->SizeContents.y - window->Size.y)); |
| 3213 | | window->NextScrollY = window->ScrollY; |
| 3214 | | |
| 3215 | | // Update values for rendering |
| 3216 | | scroll_ratio = ImSaturate(window->ScrollY / scroll_max); |
| 3217 | | grab_y_norm = scroll_ratio * (scrollbar_height - grab_h_pixels) / scrollbar_height; |
| 3218 | | |
| 3219 | | // Update distance to grab now that we have seeked and saturated |
| 3220 | | if (seek_absolute) |
| 3221 | | g.ScrollbarClickDeltaToGrabCenter = clicked_y_norm - grab_y_norm - grab_h_norm*0.5f; |
| 3222 | | } |
| 3223 | | |
| 3224 | | // Render |
| 3225 | | const ImU32 grab_col = window->Color(held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab); |
| 3226 | | window->DrawList->AddRectFilled(ImVec2(bb.Min.x, ImLerp(bb.Min.y, bb.Max.y, grab_y_norm)), ImVec2(bb.Max.x, ImLerp(bb.Min.y, bb.Max.y, grab_y_norm) + grab_h_pixels), grab_col); |
| 3227 | | } |
| 3228 | | |
| 3229 | 3057 | // Moving window to front of display (which happens to be back of our sorted list) |
| 3230 | 3058 | static void FocusWindow(ImGuiWindow* window) |
| 3231 | 3059 | { |
| 3232 | 3060 | ImGuiState& g = *GImGui; |
| 3233 | | |
| 3234 | | // Always mark the window we passed as focused. This is used for keyboard interactions such as tabbing. |
| 3235 | 3061 | g.FocusedWindow = window; |
| 3236 | 3062 | |
| 3237 | | // And move its root window to the top of the pile |
| 3238 | | if (window->RootWindow) |
| 3239 | | window = window->RootWindow; |
| 3240 | | |
| 3241 | 3063 | if (g.Windows.back() == window) |
| 3242 | 3064 | return; |
| 3243 | 3065 | |
| r245117 | r245118 | |
| 3287 | 3109 | g.Font = font; |
| 3288 | 3110 | g.FontSize = g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale; |
| 3289 | 3111 | g.FontTexUvWhitePixel = g.Font->ContainerAtlas->TexUvWhitePixel; |
| 3112 | g.Font->FallbackGlyph = NULL; |
| 3113 | g.Font->FallbackGlyph = g.Font->FindGlyph(g.Font->FallbackChar); |
| 3290 | 3114 | } |
| 3291 | 3115 | |
| 3292 | 3116 | void ImGui::PushFont(ImFont* font) |
| r245117 | r245118 | |
| 3404 | 3228 | ImGuiState& g = *GImGui; |
| 3405 | 3229 | |
| 3406 | 3230 | ImVec2* pvar = GetStyleVarVec2Addr(idx); |
| 3407 | | IM_ASSERT(pvar != NULL); // Called function with wrong-type? Variable is not a ImVec2. |
| 3231 | IM_ASSERT(pvar != NULL); // Called function with wrong-type? Varialble is not a ImVec2. |
| 3408 | 3232 | ImGuiStyleMod backup; |
| 3409 | 3233 | backup.Var = idx; |
| 3410 | 3234 | backup.PreviousValue = *pvar; |
| r245117 | r245118 | |
| 3496 | 3320 | return window->Pos; |
| 3497 | 3321 | } |
| 3498 | 3322 | |
| 3499 | | static void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiSetCond cond) |
| 3323 | void ImGui::SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond) |
| 3500 | 3324 | { |
| 3325 | ImGuiWindow* window = GetCurrentWindow(); |
| 3326 | |
| 3501 | 3327 | // Test condition (NB: bit 0 is always true) and clear flags for next time |
| 3502 | 3328 | if (cond && (window->SetWindowPosAllowFlags & cond) == 0) |
| 3503 | 3329 | return; |
| 3504 | | window->SetWindowPosAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver); |
| 3330 | window->SetWindowPosAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver); |
| 3505 | 3331 | |
| 3506 | 3332 | // Set |
| 3507 | 3333 | const ImVec2 old_pos = window->Pos; |
| r245117 | r245118 | |
| 3510 | 3336 | window->DC.CursorPos += (window->Pos - old_pos); // As we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least offset the cursor |
| 3511 | 3337 | } |
| 3512 | 3338 | |
| 3513 | | void ImGui::SetWindowPos(const ImVec2& pos, ImGuiSetCond cond) |
| 3514 | | { |
| 3515 | | ImGuiWindow* window = GetCurrentWindow(); |
| 3516 | | SetWindowPos(window, pos, cond); |
| 3517 | | } |
| 3518 | | |
| 3519 | | void ImGui::SetWindowPos(const char* name, const ImVec2& pos, ImGuiSetCond cond) |
| 3520 | | { |
| 3521 | | ImGuiWindow* window = FindWindowByName(name); |
| 3522 | | if (window) |
| 3523 | | SetWindowPos(window, pos, cond); |
| 3524 | | } |
| 3525 | | |
| 3526 | 3339 | ImVec2 ImGui::GetWindowSize() |
| 3527 | 3340 | { |
| 3528 | 3341 | ImGuiWindow* window = GetCurrentWindow(); |
| 3529 | 3342 | return window->Size; |
| 3530 | 3343 | } |
| 3531 | 3344 | |
| 3532 | | static void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiSetCond cond) |
| 3345 | void ImGui::SetWindowSize(const ImVec2& size, ImGuiSetCondition cond) |
| 3533 | 3346 | { |
| 3347 | ImGuiWindow* window = GetCurrentWindow(); |
| 3348 | |
| 3534 | 3349 | // Test condition (NB: bit 0 is always true) and clear flags for next time |
| 3535 | 3350 | if (cond && (window->SetWindowSizeAllowFlags & cond) == 0) |
| 3536 | 3351 | return; |
| 3537 | | window->SetWindowSizeAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver); |
| 3352 | window->SetWindowSizeAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver); |
| 3538 | 3353 | |
| 3539 | 3354 | // Set |
| 3540 | 3355 | if (ImLengthSqr(size) > 0.00001f) |
| r245117 | r245118 | |
| 3550 | 3365 | } |
| 3551 | 3366 | } |
| 3552 | 3367 | |
| 3553 | | void ImGui::SetWindowSize(const ImVec2& size, ImGuiSetCond cond) |
| 3368 | void ImGui::SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond) |
| 3554 | 3369 | { |
| 3555 | 3370 | ImGuiWindow* window = GetCurrentWindow(); |
| 3556 | | SetWindowSize(window, size, cond); |
| 3557 | | } |
| 3558 | 3371 | |
| 3559 | | void ImGui::SetWindowSize(const char* name, const ImVec2& size, ImGuiSetCond cond) |
| 3560 | | { |
| 3561 | | ImGuiWindow* window = FindWindowByName(name); |
| 3562 | | if (window) |
| 3563 | | SetWindowSize(window, size, cond); |
| 3564 | | } |
| 3565 | | |
| 3566 | | static void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiSetCond cond) |
| 3567 | | { |
| 3568 | 3372 | // Test condition (NB: bit 0 is always true) and clear flags for next time |
| 3569 | 3373 | if (cond && (window->SetWindowCollapsedAllowFlags & cond) == 0) |
| 3570 | 3374 | return; |
| 3571 | | window->SetWindowCollapsedAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver); |
| 3375 | window->SetWindowCollapsedAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver); |
| 3572 | 3376 | |
| 3573 | 3377 | // Set |
| 3574 | 3378 | window->Collapsed = collapsed; |
| 3575 | 3379 | } |
| 3576 | 3380 | |
| 3577 | | void ImGui::SetWindowCollapsed(bool collapsed, ImGuiSetCond cond) |
| 3381 | void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiSetCondition cond) |
| 3578 | 3382 | { |
| 3579 | | ImGuiWindow* window = GetCurrentWindow(); |
| 3580 | | SetWindowCollapsed(window, collapsed, cond); |
| 3581 | | } |
| 3582 | | |
| 3583 | | bool ImGui::GetWindowCollapsed() |
| 3584 | | { |
| 3585 | | ImGuiWindow* window = GetCurrentWindow(); |
| 3586 | | return window->Collapsed; |
| 3587 | | } |
| 3588 | | |
| 3589 | | void ImGui::SetWindowCollapsed(const char* name, bool collapsed, ImGuiSetCond cond) |
| 3590 | | { |
| 3591 | | ImGuiWindow* window = FindWindowByName(name); |
| 3592 | | if (window) |
| 3593 | | SetWindowCollapsed(window, collapsed, cond); |
| 3594 | | } |
| 3595 | | |
| 3596 | | void ImGui::SetWindowFocus() |
| 3597 | | { |
| 3598 | | ImGuiWindow* window = GetCurrentWindow(); |
| 3599 | | FocusWindow(window); |
| 3600 | | } |
| 3601 | | |
| 3602 | | void ImGui::SetWindowFocus(const char* name) |
| 3603 | | { |
| 3604 | | ImGuiWindow* window = FindWindowByName(name); |
| 3605 | | if (window) |
| 3606 | | FocusWindow(window); |
| 3607 | | } |
| 3608 | | |
| 3609 | | void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond) |
| 3610 | | { |
| 3611 | 3383 | ImGuiState& g = *GImGui; |
| 3612 | 3384 | g.SetNextWindowPosVal = pos; |
| 3613 | | g.SetNextWindowPosCond = cond ? cond : ImGuiSetCond_Always; |
| 3385 | g.SetNextWindowPosCond = cond ? cond : ImGuiSetCondition_Always; |
| 3614 | 3386 | } |
| 3615 | 3387 | |
| 3616 | | void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiSetCond cond) |
| 3388 | void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiSetCondition cond) |
| 3617 | 3389 | { |
| 3618 | 3390 | ImGuiState& g = *GImGui; |
| 3619 | 3391 | g.SetNextWindowSizeVal = size; |
| 3620 | | g.SetNextWindowSizeCond = cond ? cond : ImGuiSetCond_Always; |
| 3392 | g.SetNextWindowSizeCond = cond ? cond : ImGuiSetCondition_Always; |
| 3621 | 3393 | } |
| 3622 | 3394 | |
| 3623 | | void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiSetCond cond) |
| 3395 | void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiSetCondition cond) |
| 3624 | 3396 | { |
| 3625 | 3397 | ImGuiState& g = *GImGui; |
| 3626 | 3398 | g.SetNextWindowCollapsedVal = collapsed; |
| 3627 | | g.SetNextWindowCollapsedCond = cond ? cond : ImGuiSetCond_Always; |
| 3399 | g.SetNextWindowCollapsedCond = cond ? cond : ImGuiSetCondition_Always; |
| 3628 | 3400 | } |
| 3629 | 3401 | |
| 3630 | | void ImGui::SetNextWindowFocus() |
| 3631 | | { |
| 3632 | | ImGuiState& g = *GImGui; |
| 3633 | | g.SetNextWindowFocus = true; |
| 3634 | | } |
| 3635 | | |
| 3636 | 3402 | ImVec2 ImGui::GetContentRegionMax() |
| 3637 | 3403 | { |
| 3638 | 3404 | ImGuiWindow* window = GetCurrentWindow(); |
| 3639 | | ImVec2 window_padding = window->WindowPadding(); |
| 3640 | | ImVec2 mx = window->Size - window_padding; |
| 3405 | ImVec2 mx = window->Size - window->WindowPadding(); |
| 3641 | 3406 | if (window->DC.ColumnsCount != 1) |
| 3642 | 3407 | { |
| 3643 | 3408 | mx.x = ImGui::GetColumnOffset(window->DC.ColumnsCurrent + 1); |
| 3644 | | mx.x -= window_padding.x; |
| 3409 | mx.x -= GImGui->Style.WindowPadding.x; |
| 3645 | 3410 | } |
| 3646 | 3411 | else |
| 3647 | 3412 | { |
| 3648 | 3413 | if (window->ScrollbarY) |
| 3649 | | mx.x -= GImGui->Style.ScrollbarWidth; |
| 3414 | mx.x -= GImGui->Style.ScrollBarWidth; |
| 3650 | 3415 | } |
| 3651 | 3416 | return mx; |
| 3652 | 3417 | } |
| r245117 | r245118 | |
| 3662 | 3427 | ImGuiWindow* window = GetCurrentWindow(); |
| 3663 | 3428 | ImVec2 m = window->Size - window->WindowPadding(); |
| 3664 | 3429 | if (window->ScrollbarY) |
| 3665 | | m.x -= GImGui->Style.ScrollbarWidth; |
| 3430 | m.x -= GImGui->Style.ScrollBarWidth; |
| 3666 | 3431 | return m; |
| 3667 | 3432 | } |
| 3668 | 3433 | |
| r245117 | r245118 | |
| 3725 | 3490 | { |
| 3726 | 3491 | ImGuiWindow* window = GetCurrentWindow(); |
| 3727 | 3492 | window->DC.CursorPos = window->Pos + pos; |
| 3728 | | window->SizeContentsCurrent = ImMax(window->SizeContentsCurrent, pos + ImVec2(0.0f, window->ScrollY)); |
| 3493 | window->SizeContentsFit = ImMax(window->SizeContentsFit, pos + ImVec2(0.0f, window->ScrollY)); |
| 3729 | 3494 | } |
| 3730 | 3495 | |
| 3731 | 3496 | void ImGui::SetCursorPosX(float x) |
| 3732 | 3497 | { |
| 3733 | 3498 | ImGuiWindow* window = GetCurrentWindow(); |
| 3734 | 3499 | window->DC.CursorPos.x = window->Pos.x + x; |
| 3735 | | window->SizeContentsCurrent.x = ImMax(window->SizeContentsCurrent.x, x); |
| 3500 | window->SizeContentsFit.x = ImMax(window->SizeContentsFit.x, x); |
| 3736 | 3501 | } |
| 3737 | 3502 | |
| 3738 | 3503 | void ImGui::SetCursorPosY(float y) |
| 3739 | 3504 | { |
| 3740 | 3505 | ImGuiWindow* window = GetCurrentWindow(); |
| 3741 | 3506 | window->DC.CursorPos.y = window->Pos.y + y; |
| 3742 | | window->SizeContentsCurrent.y = ImMax(window->SizeContentsCurrent.y, y + window->ScrollY); |
| 3507 | window->SizeContentsFit.y = ImMax(window->SizeContentsFit.y, y + window->ScrollY); |
| 3743 | 3508 | } |
| 3744 | 3509 | |
| 3745 | 3510 | ImVec2 ImGui::GetCursorScreenPos() |
| r245117 | r245118 | |
| 3754 | 3519 | window->DC.CursorPos = screen_pos; |
| 3755 | 3520 | } |
| 3756 | 3521 | |
| 3757 | | float ImGui::GetScrollPosY() |
| 3758 | | { |
| 3759 | | ImGuiWindow* window = GetCurrentWindow(); |
| 3760 | | return window->ScrollY; |
| 3761 | | } |
| 3762 | | |
| 3763 | | float ImGui::GetScrollMaxY() |
| 3764 | | { |
| 3765 | | ImGuiWindow* window = GetCurrentWindow(); |
| 3766 | | return window->SizeContents.y - window->SizeFull.y; |
| 3767 | | } |
| 3768 | | |
| 3769 | 3522 | void ImGui::SetScrollPosHere() |
| 3770 | 3523 | { |
| 3771 | 3524 | ImGuiWindow* window = GetCurrentWindow(); |
| r245117 | r245118 | |
| 3967 | 3720 | const char* value_text_begin = &buf[0]; |
| 3968 | 3721 | const char* value_text_end = value_text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); |
| 3969 | 3722 | |
| 3970 | | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 3971 | | const ImGuiAabb value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, label_size.y)); |
| 3972 | | const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + (label_size.x > 0.0f ? style.ItemInnerSpacing.x : 0.0f), 0.0f) + label_size); |
| 3723 | const ImVec2 text_size = CalcTextSize(label, NULL, true); |
| 3724 | const ImGuiAabb value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, text_size.y)); |
| 3725 | const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + (text_size.x > 0.0f ? style.ItemInnerSpacing.x : 0.0f), 0.0f) + text_size); |
| 3973 | 3726 | ItemSize(bb); |
| 3974 | 3727 | if (!ItemAdd(value_bb, NULL)) |
| 3975 | 3728 | return; |
| r245117 | r245118 | |
| 3993 | 3746 | if (g.HoveredId == 0) |
| 3994 | 3747 | { |
| 3995 | 3748 | ImGuiWindow* window = GetCurrentWindow(); |
| 3996 | | if (g.HoveredRootWindow == window->RootWindow) |
| 3997 | | { |
| 3998 | | bool hovered = (g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdIsFocusedOnly) && IsMouseHoveringBox(bb); |
| 3999 | | return hovered; |
| 4000 | | } |
| 3749 | const bool hovered = (g.HoveredRootWindow == window->RootWindow) && (g.ActiveId == 0 || g.ActiveId == id) && IsMouseHoveringBox(bb); |
| 3750 | return hovered; |
| 4001 | 3751 | } |
| 4002 | 3752 | return false; |
| 4003 | 3753 | } |
| r245117 | r245118 | |
| 4064 | 3814 | |
| 4065 | 3815 | const ImGuiStyle& style = g.Style; |
| 4066 | 3816 | const ImGuiID id = window->GetID(label); |
| 4067 | | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 3817 | const ImVec2 text_size = CalcTextSize(label, NULL, true); |
| 4068 | 3818 | |
| 4069 | | const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : label_size.x, size_arg.y != 0.0f ? size_arg.y : label_size.y); |
| 3819 | const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : text_size.x, size_arg.y != 0.0f ? size_arg.y : text_size.y); |
| 4070 | 3820 | const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size + style.FramePadding*2.0f); |
| 4071 | 3821 | ItemSize(bb); |
| 4072 | 3822 | if (!ItemAdd(bb, &id)) |
| r245117 | r245118 | |
| 4079 | 3829 | const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); |
| 4080 | 3830 | RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding); |
| 4081 | 3831 | |
| 4082 | | const ImVec2 off = ImVec2(ImMax(0.0f, size.x - label_size.x) * 0.5f, ImMax(0.0f, size.y - label_size.y) * 0.5f); // Center (only applies if we explicitly gave a size bigger than the text size, which isn't the common path) |
| 4083 | | RenderTextClipped(bb.Min + style.FramePadding + off, label, NULL, &label_size, bb.Max); // Render clip (only applies if we explicitly gave a size smaller than the text size, which isn't the commmon path) |
| 3832 | const ImVec2 off = ImVec2(ImMax(0.0f, size.x - text_size.x) * 0.5f, ImMax(0.0f, size.y - text_size.y) * 0.5f); // Center (only applies if we explicitly gave a size bigger than the text size, which isn't the common path) |
| 3833 | RenderTextClipped(bb.Min + style.FramePadding + off, label, NULL, &text_size, bb.Max); // Render clip (only applies if we explicitly gave a size smaller than the text size, which isn't the commmon path) |
| 4084 | 3834 | |
| 4085 | 3835 | return pressed; |
| 4086 | 3836 | } |
| r245117 | r245118 | |
| 4095 | 3845 | |
| 4096 | 3846 | const ImGuiStyle& style = g.Style; |
| 4097 | 3847 | const ImGuiID id = window->GetID(label); |
| 4098 | | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 3848 | const ImVec2 text_size = CalcTextSize(label, NULL, true); |
| 4099 | 3849 | |
| 4100 | | const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + label_size + ImVec2(style.FramePadding.x*2,0)); |
| 3850 | const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size + ImVec2(style.FramePadding.x*2,0)); |
| 4101 | 3851 | ItemSize(bb); |
| 4102 | 3852 | if (!ItemAdd(bb, &id)) |
| 4103 | 3853 | return false; |
| r245117 | r245118 | |
| 4138 | 3888 | { |
| 4139 | 3889 | ImGuiWindow* window = GetCurrentWindow(); |
| 4140 | 3890 | |
| 4141 | | const ImGuiID id = window->GetID("#CLOSE"); |
| 3891 | const ImGuiID id = window->GetID("##CLOSE"); |
| 4142 | 3892 | const float size = window->TitleBarHeight() - 4.0f; |
| 4143 | 3893 | const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-3.0f-size,2.0f), window->Aabb().GetTR() + ImVec2(-3.0f,2.0f+size)); |
| 4144 | 3894 | |
| r245117 | r245118 | |
| 4332 | 4082 | LogToClipboard(g.LogAutoExpandMaxDepth); |
| 4333 | 4083 | } |
| 4334 | 4084 | |
| 4335 | | bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display_frame, bool default_open) |
| 4085 | bool ImGui::CollapsingHeader(const char* label, const char* str_id, const bool display_frame, const bool default_open) |
| 4336 | 4086 | { |
| 4337 | 4087 | ImGuiState& g = *GImGui; |
| 4338 | 4088 | ImGuiWindow* window = GetCurrentWindow(); |
| r245117 | r245118 | |
| 4348 | 4098 | label = str_id; |
| 4349 | 4099 | const ImGuiID id = window->GetID(str_id); |
| 4350 | 4100 | |
| 4351 | | // We only write to the tree storage if the user clicks (or explicitely use SetNextTreeNode*** functions) |
| 4101 | // We only write to the tree storage if the user clicks |
| 4352 | 4102 | ImGuiStorage* storage = window->DC.StateStorage; |
| 4353 | 4103 | bool opened; |
| 4354 | | if (g.SetNextTreeNodeOpenedCond != 0) |
| 4104 | if (window->DC.OpenNextNode != -1) |
| 4355 | 4105 | { |
| 4356 | | if (g.SetNextTreeNodeOpenedCond & ImGuiSetCond_Always) |
| 4357 | | { |
| 4358 | | opened = g.SetNextTreeNodeOpenedVal; |
| 4359 | | storage->SetInt(id, opened); |
| 4360 | | } |
| 4361 | | else |
| 4362 | | { |
| 4363 | | // We treat ImGuiSetCondition_Once and ImGuiSetCondition_FirstUseEver the same because tree node state are not saved persistently. |
| 4364 | | const int stored_value = storage->GetInt(id, -1); |
| 4365 | | if (stored_value == -1) |
| 4366 | | { |
| 4367 | | opened = g.SetNextTreeNodeOpenedVal; |
| 4368 | | storage->SetInt(id, opened); |
| 4369 | | } |
| 4370 | | else |
| 4371 | | { |
| 4372 | | opened = stored_value != 0; |
| 4373 | | } |
| 4374 | | } |
| 4375 | | g.SetNextTreeNodeOpenedCond = 0; |
| 4106 | opened = window->DC.OpenNextNode > 0; |
| 4107 | storage->SetInt(id, opened); |
| 4108 | window->DC.OpenNextNode = -1; |
| 4376 | 4109 | } |
| 4377 | 4110 | else |
| 4378 | 4111 | { |
| r245117 | r245118 | |
| 4381 | 4114 | |
| 4382 | 4115 | // Framed header expand a little outside the default padding |
| 4383 | 4116 | const ImVec2 window_padding = window->WindowPadding(); |
| 4384 | | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 4117 | const ImVec2 text_size = CalcTextSize(label, NULL, true); |
| 4385 | 4118 | const ImVec2 pos_min = window->DC.CursorPos; |
| 4386 | 4119 | const ImVec2 pos_max = window->Pos + GetContentRegionMax(); |
| 4387 | | ImGuiAabb bb = ImGuiAabb(pos_min, ImVec2(pos_max.x, pos_min.y + label_size.y)); |
| 4120 | ImGuiAabb bb = ImGuiAabb(pos_min, ImVec2(pos_max.x, pos_min.y + text_size.y)); |
| 4388 | 4121 | if (display_frame) |
| 4389 | 4122 | { |
| 4390 | 4123 | bb.Min.x -= window_padding.x*0.5f - 1; |
| r245117 | r245118 | |
| 4392 | 4125 | bb.Max.y += style.FramePadding.y * 2; |
| 4393 | 4126 | } |
| 4394 | 4127 | |
| 4395 | | const ImGuiAabb text_bb(bb.Min, bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2*2,0) + label_size); |
| 4128 | const ImGuiAabb text_bb(bb.Min, bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2*2,0) + text_size); |
| 4396 | 4129 | ItemSize(ImVec2(text_bb.GetSize().x, bb.GetSize().y)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit |
| 4397 | 4130 | |
| 4398 | 4131 | // When logging is enabled, if automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behaviour). |
| 4399 | 4132 | // NB- If we are above max depth we still allow manually opened nodes to be logged. |
| 4400 | | if (g.LogEnabled && !display_frame && window->DC.TreeDepth < g.LogAutoExpandMaxDepth) |
| 4401 | | opened = true; |
| 4133 | if (!display_frame) |
| 4134 | if (g.LogEnabled && window->DC.TreeDepth < g.LogAutoExpandMaxDepth) |
| 4135 | opened = true; |
| 4402 | 4136 | |
| 4403 | 4137 | if (!ItemAdd(bb, &id)) |
| 4404 | 4138 | return opened; |
| r245117 | r245118 | |
| 4445 | 4179 | return opened; |
| 4446 | 4180 | } |
| 4447 | 4181 | |
| 4448 | | void ImGui::Bullet() |
| 4449 | | { |
| 4450 | | ImGuiState& g = *GImGui; |
| 4451 | | ImGuiWindow* window = GetCurrentWindow(); |
| 4452 | | if (window->SkipItems) |
| 4453 | | return; |
| 4454 | | |
| 4455 | | const ImGuiStyle& style = g.Style; |
| 4456 | | const float line_height = window->FontSize(); |
| 4457 | | const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height, line_height)); |
| 4458 | | ItemSize(bb); |
| 4459 | | if (!ItemAdd(bb, NULL)) |
| 4460 | | return; |
| 4461 | | |
| 4462 | | // Render |
| 4463 | | const float bullet_size = line_height*0.15f; |
| 4464 | | window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text)); |
| 4465 | | |
| 4466 | | // Stay on same line |
| 4467 | | ImGui::SameLine(0, -1); |
| 4468 | | } |
| 4469 | | |
| 4470 | 4182 | // Text with a little bullet aligned to the typical tree node. |
| 4471 | 4183 | void ImGui::BulletTextV(const char* fmt, va_list args) |
| 4472 | 4184 | { |
| r245117 | r245118 | |
| 4475 | 4187 | if (window->SkipItems) |
| 4476 | 4188 | return; |
| 4477 | 4189 | |
| 4190 | const ImGuiStyle& style = g.Style; |
| 4191 | |
| 4478 | 4192 | static char buf[1024]; |
| 4479 | 4193 | const char* text_begin = buf; |
| 4480 | 4194 | const char* text_end = text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); |
| 4481 | 4195 | |
| 4482 | | const ImGuiStyle& style = g.Style; |
| 4483 | 4196 | const float line_height = window->FontSize(); |
| 4484 | | const ImVec2 label_size = CalcTextSize(text_begin, text_end, true); |
| 4485 | | const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (label_size.x > 0.0f ? (style.FramePadding.x*2) : 0.0f),0) + label_size); // Empty text doesn't add padding |
| 4197 | const ImVec2 text_size = CalcTextSize(text_begin, text_end, true); |
| 4198 | const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (text_size.x > 0.0f ? (style.FramePadding.x*2) : 0.0f),0) + text_size); // Empty text doesn't add padding |
| 4486 | 4199 | ItemSize(bb); |
| 4487 | 4200 | if (!ItemAdd(bb, NULL)) |
| 4488 | 4201 | return; |
| r245117 | r245118 | |
| 4562 | 4275 | return TreeNode(str_label_id, "%s", str_label_id); |
| 4563 | 4276 | } |
| 4564 | 4277 | |
| 4565 | | void ImGui::SetNextTreeNodeOpened(bool opened, ImGuiSetCond cond) |
| 4278 | void ImGui::OpenNextNode(bool open) |
| 4566 | 4279 | { |
| 4567 | | ImGuiState& g = *GImGui; |
| 4568 | | g.SetNextTreeNodeOpenedVal = opened; |
| 4569 | | g.SetNextTreeNodeOpenedCond = cond ? cond : ImGuiSetCond_Always; |
| 4280 | ImGuiWindow* window = GetCurrentWindow(); |
| 4281 | window->DC.OpenNextNode = open ? 1 : 0; |
| 4570 | 4282 | } |
| 4571 | 4283 | |
| 4572 | 4284 | void ImGui::PushID(const char* str_id) |
| r245117 | r245118 | |
| 4610 | 4322 | // NB: only call right after InputText because we are using its InitialValue storage |
| 4611 | 4323 | static void ApplyNumericalTextInput(const char* buf, float *v) |
| 4612 | 4324 | { |
| 4613 | | while (ImCharIsSpace(*buf)) |
| 4325 | while (*buf == ' ' || *buf == '\t') |
| 4614 | 4326 | buf++; |
| 4615 | 4327 | |
| 4616 | 4328 | // We don't support '-' op because it would conflict with inputing negative value. |
| r245117 | r245118 | |
| 4619 | 4331 | if (op == '+' || op == '*' || op == '/') |
| 4620 | 4332 | { |
| 4621 | 4333 | buf++; |
| 4622 | | while (ImCharIsSpace(*buf)) |
| 4334 | while (*buf == ' ' || *buf == '\t') |
| 4623 | 4335 | buf++; |
| 4624 | 4336 | } |
| 4625 | 4337 | else |
| r245117 | r245118 | |
| 4683 | 4395 | } |
| 4684 | 4396 | } |
| 4685 | 4397 | |
| 4686 | | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 4687 | | const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f); |
| 4398 | const ImVec2 text_size = CalcTextSize(label, NULL, true); |
| 4399 | const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f); |
| 4688 | 4400 | const ImGuiAabb slider_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding); |
| 4689 | | const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); |
| 4401 | const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(text_size.x > 0.0f ? style.ItemInnerSpacing.x + text_size.x : 0.0f, 0.0f)); |
| 4690 | 4402 | |
| 4691 | 4403 | // NB- we don't call ItemSize() yet becausae we may turn into a text edit box later in the function |
| 4692 | 4404 | if (!ItemAdd(slider_bb, &id)) |
| r245117 | r245118 | |
| 4702 | 4414 | const float grab_size_in_units = 1.0f; // In 'v' units. Probably needs to be parametrized, based on a 'v_step' value? decimal precision? |
| 4703 | 4415 | float grab_size_in_pixels; |
| 4704 | 4416 | if (decimal_precision > 0 || is_unbound) |
| 4705 | | grab_size_in_pixels = style.GrabMinSize; |
| 4417 | grab_size_in_pixels = 10.0f; |
| 4706 | 4418 | else |
| 4707 | | grab_size_in_pixels = ImMax(grab_size_in_units * (w / (v_max-v_min+1.0f)), style.GrabMinSize); // Integer sliders |
| 4419 | grab_size_in_pixels = ImMax(grab_size_in_units * (w / (v_max-v_min+1.0f)), 8.0f); // Integer sliders |
| 4708 | 4420 | const float slider_effective_w = slider_bb.GetWidth() - grab_size_in_pixels; |
| 4709 | 4421 | const float slider_effective_x1 = slider_bb.Min.x + grab_size_in_pixels*0.5f; |
| 4710 | 4422 | const float slider_effective_x2 = slider_bb.Max.x - grab_size_in_pixels*0.5f; |
| r245117 | r245118 | |
| 4759 | 4471 | if (g.SliderAsInputTextId == 0) |
| 4760 | 4472 | { |
| 4761 | 4473 | // First frame |
| 4762 | | IM_ASSERT(g.ActiveId == id); // InputText ID expected to match the Slider ID (else we'd need to store them both, which is also possible) |
| 4474 | IM_ASSERT(g.ActiveId == id); // InputText ID should match the Slider ID (else we'd need to store them both which is also possible) |
| 4763 | 4475 | g.SliderAsInputTextId = g.ActiveId; |
| 4476 | SetActiveId(id); |
| 4764 | 4477 | g.HoveredId = id; |
| 4765 | 4478 | } |
| 4766 | | else if (g.ActiveId != g.SliderAsInputTextId) |
| 4479 | else |
| 4767 | 4480 | { |
| 4768 | | // Release |
| 4769 | | g.SliderAsInputTextId = 0; |
| 4481 | if (g.ActiveId == g.SliderAsInputTextId) |
| 4482 | SetActiveId(id); |
| 4483 | else |
| 4484 | { |
| 4485 | SetActiveId(0); |
| 4486 | g.SliderAsInputTextId = 0; |
| 4487 | } |
| 4770 | 4488 | } |
| 4771 | 4489 | if (value_changed) |
| 4772 | 4490 | { |
| r245117 | r245118 | |
| 4861 | 4579 | |
| 4862 | 4580 | // Draw value using user-provided display format so user can add prefix/suffix/decorations to the value. |
| 4863 | 4581 | char value_buf[64]; |
| 4864 | | char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v); |
| 4865 | | const ImVec2 value_text_size = CalcTextSize(value_buf, value_buf_end, true); |
| 4866 | | RenderTextClipped(ImVec2(ImMax(frame_bb.Min.x + style.FramePadding.x, slider_bb.GetCenter().x - value_text_size.x*0.5f), frame_bb.Min.y + style.FramePadding.y), value_buf, value_buf_end, &value_text_size, frame_bb.Max); |
| 4582 | ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v); |
| 4583 | RenderText(ImVec2(slider_bb.GetCenter().x-CalcTextSize(value_buf, NULL, true).x*0.5f, frame_bb.Min.y + style.FramePadding.y), value_buf); |
| 4867 | 4584 | |
| 4868 | 4585 | RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, slider_bb.Min.y), label); |
| 4869 | 4586 | |
| r245117 | r245118 | |
| 5004 | 4721 | |
| 5005 | 4722 | const ImGuiStyle& style = g.Style; |
| 5006 | 4723 | |
| 5007 | | const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true); |
| 4724 | const ImVec2 text_size = ImGui::CalcTextSize(label, NULL, true); |
| 5008 | 4725 | if (graph_size.x == 0.0f) |
| 5009 | 4726 | graph_size.x = ImGui::CalcItemWidth(); |
| 5010 | 4727 | if (graph_size.y == 0.0f) |
| 5011 | | graph_size.y = label_size.y; |
| 4728 | graph_size.y = text_size.y; |
| 5012 | 4729 | |
| 5013 | 4730 | const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y) + style.FramePadding*2.0f); |
| 5014 | 4731 | const ImGuiAabb graph_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding); |
| 5015 | | const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0)); |
| 4732 | const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(text_size.x > 0.0f ? style.ItemInnerSpacing.x + text_size.x : 0.0f, 0)); |
| 5016 | 4733 | ItemSize(bb); |
| 5017 | 4734 | if (!ItemAdd(bb, NULL)) |
| 5018 | 4735 | return; |
| r245117 | r245118 | |
| 5137 | 4854 | |
| 5138 | 4855 | const ImGuiStyle& style = g.Style; |
| 5139 | 4856 | const ImGuiID id = window->GetID(label); |
| 5140 | | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 4857 | const ImVec2 text_size = CalcTextSize(label, NULL, true); |
| 5141 | 4858 | |
| 5142 | | const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2, label_size.y + style.FramePadding.y*2)); |
| 4859 | const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(text_size.y + style.FramePadding.y*2, text_size.y + style.FramePadding.y*2)); |
| 5143 | 4860 | ItemSize(check_bb); |
| 5144 | 4861 | |
| 5145 | 4862 | ImGuiAabb total_bb = check_bb; |
| 5146 | | if (label_size.x > 0) |
| 4863 | if (text_size.x > 0) |
| 5147 | 4864 | SameLine(0, (int)style.ItemInnerSpacing.x); |
| 5148 | | const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + label_size); |
| 5149 | | if (label_size.x > 0) |
| 4865 | const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + text_size); |
| 4866 | if (text_size.x > 0) |
| 5150 | 4867 | { |
| 5151 | 4868 | ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight())); |
| 5152 | 4869 | total_bb = ImGuiAabb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max)); |
| r245117 | r245118 | |
| 5195 | 4912 | |
| 5196 | 4913 | const ImGuiStyle& style = g.Style; |
| 5197 | 4914 | const ImGuiID id = window->GetID(label); |
| 5198 | | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 5199 | 4915 | |
| 5200 | | const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2-1, label_size.y + style.FramePadding.y*2-1)); |
| 4916 | const ImVec2 text_size = CalcTextSize(label, NULL, true); |
| 4917 | |
| 4918 | const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(text_size.y + style.FramePadding.y*2-1, text_size.y + style.FramePadding.y*2-1)); |
| 5201 | 4919 | ItemSize(check_bb); |
| 5202 | 4920 | |
| 5203 | 4921 | ImGuiAabb total_bb = check_bb; |
| 5204 | | if (label_size.x > 0) |
| 4922 | if (text_size.x > 0) |
| 5205 | 4923 | SameLine(0, (int)style.ItemInnerSpacing.x); |
| 5206 | | const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + label_size); |
| 5207 | | if (label_size.x > 0) |
| 4924 | const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + text_size); |
| 4925 | if (text_size.x > 0) |
| 5208 | 4926 | { |
| 5209 | 4927 | ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight())); |
| 5210 | 4928 | total_bb.Add(text_bb); |
| r245117 | r245118 | |
| 5270 | 4988 | r->num_chars = (int)(text_remaining - (obj->Text + line_start_idx)); |
| 5271 | 4989 | } |
| 5272 | 4990 | |
| 4991 | static bool is_white(unsigned int c) { return c==0 || c==' ' || c=='\t' || c=='\r' || c=='\n'; } |
| 5273 | 4992 | static bool is_separator(unsigned int c) { return c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|'; } |
| 5274 | | #define STB_TEXTEDIT_IS_SPACE(CH) ( ImCharIsSpace((unsigned int)CH) || is_separator((unsigned int)CH) ) |
| 5275 | | static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n) |
| 5276 | | { |
| 5277 | | ImWchar* dst = obj->Text + pos; |
| 5278 | | |
| 5279 | | // We maintain our buffer length in both UTF-8 and wchar formats |
| 5280 | | obj->CurLenA -= ImTextCountUtf8BytesFromStr(dst, dst + n); |
| 5281 | | obj->CurLenW -= n; |
| 5282 | | |
| 5283 | | // Offset remaining text |
| 5284 | | const ImWchar* src = obj->Text + pos + n; |
| 5285 | | while (ImWchar c = *src++) |
| 5286 | | *dst++ = c; |
| 5287 | | *dst = '\0'; |
| 5288 | | } |
| 5289 | | |
| 4993 | #define STB_TEXTEDIT_IS_SPACE(CH) ( is_white((unsigned int)CH) || is_separator((unsigned int)CH) ) |
| 4994 | static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n) { ImWchar* dst = obj->Text+pos; const ImWchar* src = obj->Text+pos+n; while (ImWchar c = *src++) *dst++ = c; *dst = '\0'; } |
| 5290 | 4995 | static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const ImWchar* new_text, int new_text_len) |
| 5291 | 4996 | { |
| 5292 | | const size_t text_len = obj->CurLenW; |
| 5293 | | if ((size_t)new_text_len + text_len + 1 > IM_ARRAYSIZE(obj->Text)) |
| 4997 | const size_t text_len = ImStrlenW(obj->Text); |
| 4998 | if ((size_t)new_text_len + text_len + 1 >= obj->BufSize) |
| 5294 | 4999 | return false; |
| 5295 | 5000 | |
| 5296 | | const int new_text_len_utf8 = ImTextCountUtf8BytesFromStr(new_text, new_text + new_text_len); |
| 5297 | | if ((size_t)new_text_len_utf8 + obj->CurLenA + 1 > obj->BufSizeA) |
| 5298 | | return false; |
| 5299 | | |
| 5300 | 5001 | if (pos != (int)text_len) |
| 5301 | 5002 | memmove(obj->Text + (size_t)pos + new_text_len, obj->Text + (size_t)pos, (text_len - (size_t)pos) * sizeof(ImWchar)); |
| 5302 | 5003 | memcpy(obj->Text + (size_t)pos, new_text, (size_t)new_text_len * sizeof(ImWchar)); |
| 5004 | obj->Text[text_len + (size_t)new_text_len] = '\0'; |
| 5303 | 5005 | |
| 5304 | | obj->CurLenW += new_text_len; |
| 5305 | | obj->CurLenA += new_text_len_utf8; |
| 5306 | | obj->Text[obj->CurLenW] = '\0'; |
| 5307 | | |
| 5308 | 5006 | return true; |
| 5309 | 5007 | } |
| 5310 | 5008 | |
| r245117 | r245118 | |
| 5398 | 5096 | const char* text_start = GetTextPointerClippedA(font, font_size, buf, scroll_x, NULL); |
| 5399 | 5097 | const char* text_end = GetTextPointerClippedA(font, font_size, text_start, width, &text_size); |
| 5400 | 5098 | |
| 5401 | | // We need to test for the possibility of malformed UTF-8 (instead of just text_end[0] != 0) |
| 5402 | | unsigned int text_end_char = 0; |
| 5403 | | ImTextCharFromUtf8(&text_end_char, text_end, NULL); |
| 5404 | | |
| 5405 | 5099 | // Draw a little clip symbol if we've got text on either left or right of the box |
| 5406 | 5100 | const char symbol_c = '~'; |
| 5407 | 5101 | const float symbol_w = font_size*0.40f; // FIXME: compute correct width |
| 5408 | 5102 | const float clip_begin = (text_start > buf && text_start < text_end) ? symbol_w : 0.0f; |
| 5409 | | const float clip_end = (text_end_char != 0 && text_end > text_start) ? symbol_w : 0.0f; |
| 5103 | const float clip_end = (text_end[0] != '\0' && text_end > text_start) ? symbol_w : 0.0f; |
| 5410 | 5104 | |
| 5411 | 5105 | // Draw text |
| 5412 | 5106 | RenderText(pos+ImVec2(clip_begin,0), text_start+(clip_begin>0.0f?1:0), text_end-(clip_end>0.0f?1:0), false); |
| r245117 | r245118 | |
| 5428 | 5122 | |
| 5429 | 5123 | const ImGuiStyle& style = g.Style; |
| 5430 | 5124 | const float w = ImGui::CalcItemWidth(); |
| 5431 | | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 5432 | | const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f); |
| 5125 | const ImVec2 text_size = CalcTextSize(label, NULL, true); |
| 5126 | const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f); |
| 5433 | 5127 | |
| 5434 | 5128 | ImGui::PushID(label); |
| 5435 | 5129 | const float button_sz = window->FontSize(); |
| r245117 | r245118 | |
| 5469 | 5163 | |
| 5470 | 5164 | ImGui::PopID(); |
| 5471 | 5165 | |
| 5472 | | if (label_size.x > 0) |
| 5166 | if (text_size.x > 0) |
| 5473 | 5167 | { |
| 5474 | 5168 | ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); |
| 5475 | | ItemSize(label_size); |
| 5169 | ItemSize(text_size); |
| 5476 | 5170 | RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); |
| 5477 | 5171 | } |
| 5478 | 5172 | |
| r245117 | r245118 | |
| 5528 | 5222 | SelectionStart = SelectionEnd = CursorPos; |
| 5529 | 5223 | } |
| 5530 | 5224 | |
| 5531 | | // Return false to discard a character. |
| 5532 | | static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data) |
| 5225 | static bool InputTextFilterCharacter(ImWchar c, ImGuiInputTextFlags flags) |
| 5533 | 5226 | { |
| 5534 | | unsigned int c = *p_char; |
| 5535 | | |
| 5536 | 5227 | if (c < 128 && c != ' ' && !isprint((int)(c & 0xFF))) |
| 5537 | | return false; |
| 5228 | return true; |
| 5538 | 5229 | |
| 5539 | 5230 | if (c >= 0xE000 && c <= 0xF8FF) // Filter private Unicode range. I don't imagine anybody would want to input them. GLFW on OSX seems to send private characters for special keys like arrow keys. |
| 5540 | | return false; |
| 5231 | return true; |
| 5541 | 5232 | |
| 5542 | | if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank)) |
| 5543 | | { |
| 5544 | | if (flags & ImGuiInputTextFlags_CharsDecimal) |
| 5545 | | if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/')) |
| 5546 | | return false; |
| 5233 | if (flags & ImGuiInputTextFlags_CharsDecimal) |
| 5234 | if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/')) |
| 5235 | return true; |
| 5547 | 5236 | |
| 5548 | | if (flags & ImGuiInputTextFlags_CharsHexadecimal) |
| 5549 | | if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F')) |
| 5550 | | return false; |
| 5237 | if (flags & ImGuiInputTextFlags_CharsHexadecimal) |
| 5238 | if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F')) |
| 5239 | return true; |
| 5551 | 5240 | |
| 5552 | | if (flags & ImGuiInputTextFlags_CharsUppercase) |
| 5553 | | if (c >= 'a' && c <= 'z') |
| 5554 | | *p_char = (c += (unsigned int)('A'-'a')); |
| 5555 | | |
| 5556 | | if (flags & ImGuiInputTextFlags_CharsNoBlank) |
| 5557 | | if (ImCharIsSpace(c)) |
| 5558 | | return false; |
| 5559 | | } |
| 5560 | | |
| 5561 | | if (flags & ImGuiInputTextFlags_CallbackCharFilter) |
| 5562 | | { |
| 5563 | | ImGuiTextEditCallbackData callback_data; |
| 5564 | | memset(&callback_data, 0, sizeof(ImGuiTextEditCallbackData)); |
| 5565 | | callback_data.EventFlag = ImGuiInputTextFlags_CallbackCharFilter; |
| 5566 | | callback_data.EventChar = c; |
| 5567 | | callback_data.Flags = flags; |
| 5568 | | callback_data.UserData = user_data; |
| 5569 | | if (callback(&callback_data) != 0) |
| 5570 | | return false; |
| 5571 | | *p_char = callback_data.EventChar; |
| 5572 | | if (!callback_data.EventChar) |
| 5573 | | return false; |
| 5574 | | } |
| 5575 | | |
| 5576 | | return true; |
| 5241 | return false; |
| 5577 | 5242 | } |
| 5578 | 5243 | |
| 5579 | 5244 | // Edit a string of text |
| 5580 | | bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data) |
| 5245 | bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, void (*callback)(ImGuiTextEditCallbackData*), void* user_data) |
| 5581 | 5246 | { |
| 5582 | 5247 | ImGuiState& g = *GImGui; |
| 5583 | 5248 | ImGuiWindow* window = GetCurrentWindow(); |
| r245117 | r245118 | |
| 5590 | 5255 | const ImGuiID id = window->GetID(label); |
| 5591 | 5256 | const float w = ImGui::CalcItemWidth(); |
| 5592 | 5257 | |
| 5593 | | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 5594 | | const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f); |
| 5595 | | const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? (style.ItemInnerSpacing.x + label_size.x) : 0.0f, 0.0f)); |
| 5258 | const ImVec2 text_size = CalcTextSize(label, NULL, true); |
| 5259 | const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f); |
| 5260 | const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(text_size.x > 0.0f ? (style.ItemInnerSpacing.x + text_size.x) : 0.0f, 0.0f)); |
| 5596 | 5261 | ItemSize(bb); |
| 5597 | 5262 | if (!ItemAdd(frame_bb, &id)) |
| 5598 | 5263 | return false; |
| r245117 | r245118 | |
| 5602 | 5267 | |
| 5603 | 5268 | const bool is_ctrl_down = io.KeyCtrl; |
| 5604 | 5269 | const bool is_shift_down = io.KeyShift; |
| 5605 | | const bool focus_requested = window->FocusItemRegister(g.ActiveId == id, (flags & ImGuiInputTextFlags_CallbackCompletion) == 0); // Using completion callback disable keyboard tabbing |
| 5606 | | const bool focus_requested_by_code = focus_requested && (window->FocusIdxAllCounter == window->FocusIdxAllRequestCurrent); |
| 5607 | | const bool focus_requested_by_tab = focus_requested && !focus_requested_by_code; |
| 5270 | const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id, (flags & ImGuiInputTextFlags_CallbackCompletion) == 0); // Using completion callback disable keyboard tabbing |
| 5271 | //const bool align_center = (bool)(flags & ImGuiInputTextFlags_AlignCenter); // FIXME: Unsupported |
| 5608 | 5272 | |
| 5609 | 5273 | const bool hovered = IsHovered(frame_bb, id); |
| 5610 | 5274 | if (hovered) |
| 5611 | 5275 | g.HoveredId = id; |
| 5612 | | const bool user_clicked = hovered && io.MouseClicked[0]; |
| 5613 | 5276 | |
| 5614 | 5277 | bool select_all = (g.ActiveId != id) && (flags & ImGuiInputTextFlags_AutoSelectAll) != 0; |
| 5615 | | if (focus_requested || user_clicked) |
| 5278 | if (tab_focus_requested || (hovered && io.MouseClicked[0])) |
| 5616 | 5279 | { |
| 5617 | 5280 | if (g.ActiveId != id) |
| 5618 | 5281 | { |
| 5619 | 5282 | // Start edition |
| 5620 | 5283 | // Take a copy of the initial buffer value (both in original UTF-8 format and converted to wchar) |
| 5621 | | // From the moment we focused we are ignoring the content of 'buf' |
| 5622 | 5284 | ImFormatString(edit_state.InitialText, IM_ARRAYSIZE(edit_state.InitialText), "%s", buf); |
| 5623 | | const char* buf_end = NULL; |
| 5624 | | edit_state.CurLenW = (int)ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), buf, NULL, &buf_end); |
| 5625 | | edit_state.CurLenA = (int)(buf_end - buf); // We can't get the result from ImFormatString() above because it is not UTF-8 aware. Here we'll cut off malformed UTF-8. |
| 5285 | ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), buf, NULL); |
| 5286 | edit_state.ScrollX = 0.0f; |
| 5626 | 5287 | edit_state.Width = w; |
| 5627 | | edit_state.InputCursorScreenPos = ImVec2(-1.f,-1.f); |
| 5288 | stb_textedit_initialize_state(&edit_state.StbState, true); |
| 5628 | 5289 | edit_state.CursorAnimReset(); |
| 5290 | edit_state.LastCursorPos = ImVec2(-1.f,-1.f); |
| 5629 | 5291 | |
| 5630 | | if (edit_state.Id != id) |
| 5631 | | { |
| 5632 | | edit_state.Id = id; |
| 5633 | | edit_state.ScrollX = 0.0f; |
| 5634 | | stb_textedit_initialize_state(&edit_state.StbState, true); |
| 5635 | | if (focus_requested_by_code) |
| 5636 | | select_all = true; |
| 5637 | | } |
| 5638 | | else |
| 5639 | | { |
| 5640 | | // Recycle existing cursor/selection/undo stack but clamp position |
| 5641 | | // Note a single mouse click will override the cursor/position immediately by calling stb_textedit_click handler. |
| 5642 | | edit_state.StbState.cursor = ImMin(edit_state.StbState.cursor, edit_state.CurLenW); |
| 5643 | | edit_state.StbState.select_start = ImMin(edit_state.StbState.select_start, edit_state.CurLenW); |
| 5644 | | edit_state.StbState.select_end = ImMin(edit_state.StbState.select_end, edit_state.CurLenW); |
| 5645 | | } |
| 5646 | | if (focus_requested_by_tab || (user_clicked && is_ctrl_down)) |
| 5292 | if (tab_focus_requested || is_ctrl_down) |
| 5647 | 5293 | select_all = true; |
| 5648 | 5294 | } |
| 5649 | 5295 | SetActiveId(id); |
| r245117 | r245118 | |
| 5658 | 5304 | } |
| 5659 | 5305 | } |
| 5660 | 5306 | |
| 5661 | | // Although we are active we don't prevent mouse from hovering other elements unless we are interacting right now with the widget. |
| 5662 | | // Down the line we should have a cleaner concept of focused vs active in the library. |
| 5663 | | if (g.ActiveId == id) |
| 5664 | | g.ActiveIdIsFocusedOnly = !io.MouseDown[0]; |
| 5665 | | |
| 5666 | 5307 | bool value_changed = false; |
| 5667 | 5308 | bool cancel_edit = false; |
| 5668 | 5309 | bool enter_pressed = false; |
| r245117 | r245118 | |
| 5670 | 5311 | if (g.ActiveId == id) |
| 5671 | 5312 | { |
| 5672 | 5313 | // Edit in progress |
| 5673 | | edit_state.BufSizeA = buf_size; |
| 5314 | edit_state.BufSize = buf_size < IM_ARRAYSIZE(edit_state.Text) ? buf_size : IM_ARRAYSIZE(edit_state.Text); |
| 5674 | 5315 | edit_state.Font = window->Font(); |
| 5675 | 5316 | edit_state.FontSize = window->FontSize(); |
| 5676 | 5317 | |
| r245117 | r245118 | |
| 5702 | 5343 | // Process text input (before we check for Return because using some IME will effectively send a Return?) |
| 5703 | 5344 | for (int n = 0; n < IM_ARRAYSIZE(g.IO.InputCharacters) && g.IO.InputCharacters[n]; n++) |
| 5704 | 5345 | { |
| 5705 | | unsigned int c = (unsigned int)g.IO.InputCharacters[n]; |
| 5346 | const ImWchar c = g.IO.InputCharacters[n]; |
| 5706 | 5347 | if (c) |
| 5707 | 5348 | { |
| 5708 | 5349 | // Insert character if they pass filtering |
| 5709 | | if (!InputTextFilterCharacter(&c, flags, callback, user_data)) |
| 5350 | if (InputTextFilterCharacter(c, flags)) |
| 5710 | 5351 | continue; |
| 5711 | | edit_state.OnKeyPressed((int)c); |
| 5352 | edit_state.OnKeyPressed(c); |
| 5712 | 5353 | } |
| 5713 | 5354 | } |
| 5714 | 5355 | |
| r245117 | r245118 | |
| 5738 | 5379 | if (g.IO.SetClipboardTextFn) |
| 5739 | 5380 | { |
| 5740 | 5381 | const int ib = edit_state.HasSelection() ? ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end) : 0; |
| 5741 | | const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : edit_state.CurLenW; |
| 5382 | const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : (int)ImStrlenW(edit_state.Text); |
| 5742 | 5383 | ImTextStrToUtf8(text_tmp_utf8, IM_ARRAYSIZE(text_tmp_utf8), edit_state.Text+ib, edit_state.Text+ie); |
| 5743 | 5384 | g.IO.SetClipboardTextFn(text_tmp_utf8); |
| 5744 | 5385 | } |
| r245117 | r245118 | |
| 5754 | 5395 | if (const char* clipboard = g.IO.GetClipboardTextFn()) |
| 5755 | 5396 | { |
| 5756 | 5397 | // Remove new-line from pasted buffer |
| 5757 | | const size_t clipboard_len = strlen(clipboard); |
| 5398 | size_t clipboard_len = strlen(clipboard); |
| 5758 | 5399 | ImWchar* clipboard_filtered = (ImWchar*)ImGui::MemAlloc((clipboard_len+1) * sizeof(ImWchar)); |
| 5759 | 5400 | int clipboard_filtered_len = 0; |
| 5760 | 5401 | for (const char* s = clipboard; *s; ) |
| 5761 | 5402 | { |
| 5762 | 5403 | unsigned int c; |
| 5763 | | s += ImTextCharFromUtf8(&c, s, NULL); |
| 5764 | | if (c == 0) |
| 5404 | const int bytes_count = ImTextCharFromUtf8(&c, s, NULL); |
| 5405 | if (bytes_count <= 0) |
| 5765 | 5406 | break; |
| 5407 | s += bytes_count; |
| 5766 | 5408 | if (c >= 0x10000) |
| 5767 | 5409 | continue; |
| 5768 | | if (!InputTextFilterCharacter(&c, flags, callback, user_data)) |
| 5410 | if (InputTextFilterCharacter((ImWchar)c, flags)) |
| 5769 | 5411 | continue; |
| 5770 | 5412 | clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c; |
| 5771 | 5413 | } |
| r245117 | r245118 | |
| 5800 | 5442 | IM_ASSERT(callback != NULL); |
| 5801 | 5443 | |
| 5802 | 5444 | // The reason we specify the usage semantic (Completion/History) is that Completion needs to disable keyboard TABBING at the moment. |
| 5803 | | ImGuiInputTextFlags event_flag = 0; |
| 5804 | 5445 | ImGuiKey event_key = ImGuiKey_COUNT; |
| 5805 | 5446 | if ((flags & ImGuiInputTextFlags_CallbackCompletion) != 0 && IsKeyPressedMap(ImGuiKey_Tab)) |
| 5806 | | { |
| 5807 | | event_flag = ImGuiInputTextFlags_CallbackCompletion; |
| 5808 | 5447 | event_key = ImGuiKey_Tab; |
| 5809 | | } |
| 5810 | 5448 | else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_UpArrow)) |
| 5811 | | { |
| 5812 | | event_flag = ImGuiInputTextFlags_CallbackHistory; |
| 5813 | 5449 | event_key = ImGuiKey_UpArrow; |
| 5814 | | } |
| 5815 | 5450 | else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_DownArrow)) |
| 5816 | | { |
| 5817 | | event_flag = ImGuiInputTextFlags_CallbackHistory; |
| 5818 | 5451 | event_key = ImGuiKey_DownArrow; |
| 5819 | | } |
| 5820 | 5452 | |
| 5821 | 5453 | if (event_key != ImGuiKey_COUNT || (flags & ImGuiInputTextFlags_CallbackAlways) != 0) |
| 5822 | 5454 | { |
| 5823 | 5455 | ImGuiTextEditCallbackData callback_data; |
| 5824 | | callback_data.EventFlag = event_flag; |
| 5825 | 5456 | callback_data.EventKey = event_key; |
| 5826 | 5457 | callback_data.Buf = text_tmp_utf8; |
| 5827 | | callback_data.BufSize = edit_state.BufSizeA; |
| 5458 | callback_data.BufSize = edit_state.BufSize; |
| 5828 | 5459 | callback_data.BufDirty = false; |
| 5829 | 5460 | callback_data.Flags = flags; |
| 5830 | 5461 | callback_data.UserData = user_data; |
| 5831 | 5462 | |
| 5832 | 5463 | // We have to convert from position from wchar to UTF-8 positions |
| 5833 | | const int utf8_cursor_pos = callback_data.CursorPos = ImTextCountUtf8BytesFromStr(edit_state.Text, edit_state.Text + edit_state.StbState.cursor); |
| 5834 | | const int utf8_selection_start = callback_data.SelectionStart = ImTextCountUtf8BytesFromStr(edit_state.Text, edit_state.Text + edit_state.StbState.select_start); |
| 5835 | | const int utf8_selection_end = callback_data.SelectionEnd = ImTextCountUtf8BytesFromStr(edit_state.Text, edit_state.Text + edit_state.StbState.select_end); |
| 5464 | const int utf8_cursor_pos = callback_data.CursorPos = ImTextCountUtf8BytesFromWchar(edit_state.Text, edit_state.Text + edit_state.StbState.cursor); |
| 5465 | const int utf8_selection_start = callback_data.SelectionStart = ImTextCountUtf8BytesFromWchar(edit_state.Text, edit_state.Text + edit_state.StbState.select_start); |
| 5466 | const int utf8_selection_end = callback_data.SelectionEnd = ImTextCountUtf8BytesFromWchar(edit_state.Text, edit_state.Text + edit_state.StbState.select_end); |
| 5836 | 5467 | |
| 5837 | 5468 | // Call user code |
| 5838 | 5469 | callback(&callback_data); |
| 5839 | 5470 | |
| 5840 | 5471 | // Read back what user may have modified |
| 5841 | 5472 | IM_ASSERT(callback_data.Buf == text_tmp_utf8); // Invalid to modify those fields |
| 5842 | | IM_ASSERT(callback_data.BufSize == edit_state.BufSizeA); |
| 5473 | IM_ASSERT(callback_data.BufSize == edit_state.BufSize); |
| 5843 | 5474 | IM_ASSERT(callback_data.Flags == flags); |
| 5844 | 5475 | if (callback_data.CursorPos != utf8_cursor_pos) edit_state.StbState.cursor = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.CursorPos); |
| 5845 | 5476 | if (callback_data.SelectionStart != utf8_selection_start) edit_state.StbState.select_start = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionStart); |
| r245117 | r245118 | |
| 5878 | 5509 | } |
| 5879 | 5510 | } |
| 5880 | 5511 | |
| 5512 | // FIXME: 'align_center' unsupported |
| 5881 | 5513 | ImGuiTextEditState::RenderTextScrolledClipped(window->Font(), window->FontSize(), buf, frame_bb.Min + style.FramePadding, w, (g.ActiveId == id) ? edit_state.ScrollX : 0.0f); |
| 5882 | 5514 | |
| 5883 | 5515 | if (g.ActiveId == id) |
| r245117 | r245118 | |
| 5888 | 5520 | if (g.InputTextState.CursorIsVisible()) |
| 5889 | 5521 | window->DrawList->AddRect(cursor_pos - font_off_up + ImVec2(0,2), cursor_pos + font_off_dn - ImVec2(0,3), window->Color(ImGuiCol_Text)); |
| 5890 | 5522 | |
| 5891 | | // Notify OS of text input position for advanced IME |
| 5892 | | if (io.ImeSetInputScreenPosFn && ImLengthSqr(edit_state.InputCursorScreenPos - cursor_pos) > 0.0001f) |
| 5523 | // Notify OS of text input position |
| 5524 | if (io.ImeSetInputScreenPosFn && ImLengthSqr(edit_state.LastCursorPos - cursor_pos) > 0.0001f) |
| 5893 | 5525 | io.ImeSetInputScreenPosFn((int)cursor_pos.x - 1, (int)(cursor_pos.y - window->FontSize())); // -1 x offset so that Windows IME can cover our cursor. Bit of an extra nicety. |
| 5894 | 5526 | |
| 5895 | | edit_state.InputCursorScreenPos = cursor_pos; |
| 5527 | edit_state.LastCursorPos = cursor_pos; |
| 5896 | 5528 | } |
| 5897 | 5529 | |
| 5898 | | if (label_size.x > 0) |
| 5899 | | RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); |
| 5530 | RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); |
| 5900 | 5531 | |
| 5901 | 5532 | if ((flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0) |
| 5902 | 5533 | return enter_pressed; |
| r245117 | r245118 | |
| 6015 | 5646 | const ImGuiID id = window->GetID(label); |
| 6016 | 5647 | const float w = ImGui::CalcItemWidth(); |
| 6017 | 5648 | |
| 6018 | | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 6019 | | const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f); |
| 6020 | | const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + label_size.x,0)); |
| 6021 | | ItemSize(bb); |
| 5649 | const ImVec2 text_size = CalcTextSize(label, NULL, true); |
| 5650 | const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f); |
| 5651 | ItemSize(frame_bb); |
| 6022 | 5652 | if (!ItemAdd(frame_bb, &id)) |
| 6023 | 5653 | return false; |
| 6024 | 5654 | |
| 5655 | const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x,0)); |
| 6025 | 5656 | const float arrow_size = (window->FontSize() + style.FramePadding.x * 2.0f); |
| 6026 | 5657 | const bool hovered = IsHovered(frame_bb, id); |
| 6027 | 5658 | |
| r245117 | r245118 | |
| 6038 | 5669 | RenderTextClipped(frame_bb.Min + style.FramePadding, item_text, NULL, NULL, value_bb.Max); |
| 6039 | 5670 | } |
| 6040 | 5671 | |
| 6041 | | if (label_size.x > 0) |
| 6042 | | RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); |
| 5672 | // Empty text doesn't add padding |
| 5673 | if (text_size.x > 0) |
| 5674 | { |
| 5675 | ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); |
| 5676 | ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); |
| 5677 | } |
| 6043 | 5678 | |
| 6044 | 5679 | ImGui::PushID((int)id); |
| 6045 | 5680 | bool menu_toggled = false; |
| r245117 | r245118 | |
| 6063 | 5698 | |
| 6064 | 5699 | const ImVec2 backup_pos = ImGui::GetCursorPos(); |
| 6065 | 5700 | const float popup_off_x = 0.0f;//style.ItemInnerSpacing.x; |
| 6066 | | const float popup_height = (label_size.y + style.ItemSpacing.y) * ImMin(items_count, height_in_items) + style.WindowPadding.y; |
| 5701 | const float popup_height = (text_size.y + style.ItemSpacing.y) * ImMin(items_count, height_in_items) + style.WindowPadding.y; |
| 6067 | 5702 | const ImGuiAabb popup_aabb(ImVec2(frame_bb.Min.x+popup_off_x, frame_bb.Max.y), ImVec2(frame_bb.Max.x+popup_off_x, frame_bb.Max.y + popup_height)); |
| 6068 | 5703 | ImGui::SetCursorPos(popup_aabb.Min - window->Pos); |
| 6069 | 5704 | |
| r245117 | r245118 | |
| 6117 | 5752 | |
| 6118 | 5753 | const ImGuiStyle& style = g.Style; |
| 6119 | 5754 | const ImGuiID id = window->GetID(label); |
| 6120 | | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 5755 | const ImVec2 text_size = CalcTextSize(label, NULL, true); |
| 6121 | 5756 | |
| 6122 | 5757 | const float w = window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x; |
| 6123 | | const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : w, size_arg.y != 0.0f ? size_arg.y : label_size.y); |
| 5758 | const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : w, size_arg.y != 0.0f ? size_arg.y : text_size.y); |
| 6124 | 5759 | const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size); |
| 6125 | 5760 | ItemSize(bb); |
| 6126 | 5761 | |
| r245117 | r245118 | |
| 6148 | 5783 | } |
| 6149 | 5784 | |
| 6150 | 5785 | //const ImVec2 off = ImVec2(ImMax(0.0f, size.x - text_size.x) * 0.5f, ImMax(0.0f, size.y - text_size.y) * 0.5f); |
| 6151 | | RenderTextClipped(bb.Min, label, NULL, &label_size, bb_with_spacing.Max); |
| 5786 | RenderTextClipped(bb.Min, label, NULL, &text_size, bb_with_spacing.Max); |
| 6152 | 5787 | |
| 6153 | 5788 | return pressed; |
| 6154 | 5789 | } |
| r245117 | r245118 | |
| 6168 | 5803 | bool ImGui::ListBoxHeader(const char* label, const ImVec2& size_arg) |
| 6169 | 5804 | { |
| 6170 | 5805 | ImGuiWindow* window = GetCurrentWindow(); |
| 5806 | if (window->SkipItems) |
| 5807 | return false; |
| 6171 | 5808 | |
| 6172 | 5809 | const ImGuiStyle& style = ImGui::GetStyle(); |
| 6173 | 5810 | const ImGuiID id = ImGui::GetID(label); |
| r245117 | r245118 | |
| 6179 | 5816 | size.y = (size_arg.y != 0.0f) ? size_arg.y : ImGui::GetTextLineHeightWithSpacing() * 7.4f + style.ItemSpacing.y; |
| 6180 | 5817 | const ImVec2 frame_size = ImVec2(size.x, ImMax(size.y, label_size.y)); |
| 6181 | 5818 | const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size); |
| 6182 | | const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); |
| 6183 | | window->DC.LastItemAabb = bb; |
| 6184 | 5819 | |
| 6185 | 5820 | if (label_size.x > 0) |
| 6186 | 5821 | RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); |
| r245117 | r245118 | |
| 6207 | 5842 | |
| 6208 | 5843 | void ImGui::ListBoxFooter() |
| 6209 | 5844 | { |
| 6210 | | ImGuiWindow* parent_window = GetParentWindow(); |
| 6211 | | const ImGuiAabb bb = parent_window->DC.LastItemAabb; |
| 6212 | | |
| 6213 | 5845 | ImGui::EndChildFrame(); |
| 6214 | | |
| 6215 | | parent_window->DC.CursorPos = bb.Min; |
| 6216 | | ItemSize(bb, NULL); |
| 6217 | 5846 | } |
| 6218 | 5847 | |
| 6219 | 5848 | bool ImGui::ListBox(const char* label, int* current_item, const char** items, int items_count, int height_items) |
| r245117 | r245118 | |
| 6224 | 5853 | |
| 6225 | 5854 | bool ImGui::ListBox(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int height_in_items) |
| 6226 | 5855 | { |
| 6227 | | ImGuiWindow* window = GetCurrentWindow(); |
| 6228 | | if (window->SkipItems) |
| 6229 | | return false; |
| 6230 | | |
| 6231 | 5856 | if (!ImGui::ListBoxHeader(label, items_count, height_in_items)) |
| 6232 | 5857 | return false; |
| 6233 | 5858 | |
| r245117 | r245118 | |
| 6261 | 5886 | return false; |
| 6262 | 5887 | |
| 6263 | 5888 | const ImGuiStyle& style = g.Style; |
| 6264 | | const ImGuiID id = window->GetID("#colorbutton"); |
| 5889 | const ImGuiID id = window->GetID("##colorbutton"); |
| 6265 | 5890 | const float square_size = window->FontSize(); |
| 6266 | 5891 | const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(square_size + style.FramePadding.x*2, square_size + (small_height ? 0 : style.FramePadding.y*2))); |
| 6267 | 5892 | ItemSize(bb); |
| r245117 | r245118 | |
| 6381 | 6006 | value_changed |= ImGui::InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal); |
| 6382 | 6007 | ImGui::PopItemWidth(); |
| 6383 | 6008 | char* p = buf; |
| 6384 | | while (*p == '#' || ImCharIsSpace(*p)) |
| 6009 | while (*p == '#' || *p == ' ' || *p == '\t') |
| 6385 | 6010 | p++; |
| 6386 | 6011 | |
| 6387 | 6012 | // Treat at unsigned (%X is unsigned) |
| r245117 | r245118 | |
| 6469 | 6094 | window->DrawList->AddLine(bb.Min, bb.Max, window->Color(ImGuiCol_Border)); |
| 6470 | 6095 | |
| 6471 | 6096 | if (window->DC.ColumnsCount > 1) |
| 6472 | | { |
| 6473 | 6097 | PushColumnClipRect(); |
| 6474 | | window->DC.ColumnsCellMinY = window->DC.CursorPos.y; |
| 6475 | | } |
| 6476 | 6098 | } |
| 6477 | 6099 | |
| 6478 | 6100 | // A little vertical spacing. |
| r245117 | r245118 | |
| 6501 | 6123 | window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y); |
| 6502 | 6124 | window->DC.CursorPos = ImVec2((float)(int)(window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX), (float)(int)(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y)); |
| 6503 | 6125 | |
| 6504 | | window->SizeContentsCurrent = ImMax(window->SizeContentsCurrent, ImVec2(window->DC.CursorPosPrevLine.x - window->Pos.x, window->DC.CursorPos.y + window->ScrollY - window->Pos.y)); |
| 6126 | window->SizeContentsFit = ImMax(window->SizeContentsFit, ImVec2(window->DC.CursorPosPrevLine.x, window->DC.CursorPos.y) - window->Pos + ImVec2(0.0f, window->ScrollY)); |
| 6505 | 6127 | |
| 6506 | 6128 | window->DC.PrevLineHeight = line_height; |
| 6507 | 6129 | window->DC.CurrentLineHeight = 0.0f; |
| 6508 | 6130 | } |
| 6509 | 6131 | |
| 6510 | | static void ItemSize(const ImGuiAabb& bb, ImVec2* adjust_start_offset) |
| 6132 | static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset) |
| 6511 | 6133 | { |
| 6512 | | ItemSize(bb.GetSize(), adjust_start_offset); |
| 6134 | ItemSize(aabb.GetSize(), adjust_start_offset); |
| 6513 | 6135 | } |
| 6514 | 6136 | |
| 6515 | 6137 | static bool IsClipped(const ImGuiAabb& bb) |
| r245117 | r245118 | |
| 6538 | 6160 | window->DC.LastItemHovered = false; |
| 6539 | 6161 | return false; |
| 6540 | 6162 | } |
| 6541 | | |
| 6542 | | // This is a sensible default, but widgets are free to override it after calling ItemAdd() |
| 6543 | | const bool hovered = IsMouseHoveringBox(bb); |
| 6544 | | //const bool hovered = (g.ActiveId == 0 || (id && g.ActiveId == *id) || g.ActiveIdIsFocusedOnly) && IsMouseHoveringBox(bb); // matching the behaviour of IsHovered(), not always what the user wants? |
| 6545 | | window->DC.LastItemHovered = hovered; |
| 6163 | window->DC.LastItemHovered = IsMouseHoveringBox(bb); // this is a sensible default but widgets are free to override it after calling ItemAdd() |
| 6546 | 6164 | return true; |
| 6547 | 6165 | } |
| 6548 | 6166 | |
| r245117 | r245118 | |
| 6607 | 6225 | } |
| 6608 | 6226 | } |
| 6609 | 6227 | |
| 6610 | | int ImGui::GetColumnIndex() |
| 6611 | | { |
| 6612 | | ImGuiWindow* window = GetCurrentWindow(); |
| 6613 | | return window->DC.ColumnsCurrent; |
| 6614 | | } |
| 6615 | | |
| 6616 | | int ImGui::GetColumnsCount() |
| 6617 | | { |
| 6618 | | ImGuiWindow* window = GetCurrentWindow(); |
| 6619 | | return window->DC.ColumnsCount; |
| 6620 | | } |
| 6621 | | |
| 6228 | // FIMXE-OPT: This is called too often. We need to cache offset for active columns set. |
| 6622 | 6229 | float ImGui::GetColumnOffset(int column_index) |
| 6623 | 6230 | { |
| 6624 | 6231 | ImGuiState& g = *GImGui; |
| r245117 | r245118 | |
| 6626 | 6233 | if (column_index < 0) |
| 6627 | 6234 | column_index = window->DC.ColumnsCurrent; |
| 6628 | 6235 | |
| 6629 | | // Read from cache |
| 6630 | | IM_ASSERT(column_index < (int)window->DC.ColumnsOffsetsT.size()); |
| 6631 | | const float t = window->DC.ColumnsOffsetsT[column_index]; |
| 6236 | const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index); |
| 6237 | RegisterAliveId(column_id); |
| 6238 | const float default_t = column_index / (float)window->DC.ColumnsCount; |
| 6239 | const float t = window->StateStorage.GetFloat(column_id, default_t); // Cheaply store our floating point value inside the integer (could store an union into the map?) |
| 6632 | 6240 | |
| 6633 | | const float min_x = window->DC.ColumnsStartX; |
| 6634 | | const float max_x = window->Size.x - (g.Style.ScrollbarWidth);// - window->WindowPadding().x; |
| 6635 | | const float offset = min_x + t * (max_x - min_x); |
| 6241 | const float offset = window->DC.ColumnsStartX + t * (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnsStartX); |
| 6636 | 6242 | return offset; |
| 6637 | 6243 | } |
| 6638 | 6244 | |
| r245117 | r245118 | |
| 6643 | 6249 | if (column_index < 0) |
| 6644 | 6250 | column_index = window->DC.ColumnsCurrent; |
| 6645 | 6251 | |
| 6646 | | IM_ASSERT(column_index < (int)window->DC.ColumnsOffsetsT.size()); |
| 6647 | 6252 | const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index); |
| 6648 | | |
| 6649 | | const float min_x = window->DC.ColumnsStartX; |
| 6650 | | const float max_x = window->Size.x - (g.Style.ScrollbarWidth);// - window->WindowPadding().x; |
| 6651 | | const float t = (offset - min_x) / (max_x - min_x); |
| 6652 | | window->DC.StateStorage->SetFloat(column_id, t); |
| 6653 | | window->DC.ColumnsOffsetsT[column_index] = t; |
| 6253 | const float t = (offset - window->DC.ColumnsStartX) / (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnsStartX); |
| 6254 | window->StateStorage.SetFloat(column_id, t); |
| 6654 | 6255 | } |
| 6655 | 6256 | |
| 6656 | 6257 | float ImGui::GetColumnWidth(int column_index) |
| r245117 | r245118 | |
| 6678 | 6279 | { |
| 6679 | 6280 | ImGuiState& g = *GImGui; |
| 6680 | 6281 | ImGuiWindow* window = GetCurrentWindow(); |
| 6282 | if (window->SkipItems) |
| 6283 | return; |
| 6681 | 6284 | |
| 6682 | 6285 | if (window->DC.ColumnsCount != 1) |
| 6683 | 6286 | { |
| r245117 | r245118 | |
| 6691 | 6294 | } |
| 6692 | 6295 | |
| 6693 | 6296 | // Draw columns borders and handle resize at the time of "closing" a columns set |
| 6694 | | if (window->DC.ColumnsCount != columns_count && window->DC.ColumnsCount != 1 && window->DC.ColumnsShowBorders && !window->SkipItems) |
| 6297 | if (window->DC.ColumnsCount != columns_count && window->DC.ColumnsCount != 1 && window->DC.ColumnsShowBorders) |
| 6695 | 6298 | { |
| 6696 | 6299 | const float y1 = window->DC.ColumnsStartPos.y; |
| 6697 | 6300 | const float y2 = window->DC.CursorPos.y; |
| r245117 | r245118 | |
| 6735 | 6338 | |
| 6736 | 6339 | if (window->DC.ColumnsCount != 1) |
| 6737 | 6340 | { |
| 6738 | | // Cache column offsets |
| 6739 | | window->DC.ColumnsOffsetsT.resize((size_t)columns_count + 1); |
| 6740 | | for (int column_index = 0; column_index < columns_count + 1; column_index++) |
| 6741 | | { |
| 6742 | | const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index); |
| 6743 | | RegisterAliveId(column_id); |
| 6744 | | const float default_t = column_index / (float)window->DC.ColumnsCount; |
| 6745 | | const float t = window->DC.StateStorage->GetFloat(column_id, default_t); // Cheaply store our floating point value inside the integer (could store an union into the map?) |
| 6746 | | window->DC.ColumnsOffsetsT[column_index] = t; |
| 6747 | | } |
| 6748 | | |
| 6749 | 6341 | PushColumnClipRect(); |
| 6750 | 6342 | ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f); |
| 6751 | 6343 | } |
| 6752 | | else |
| 6753 | | { |
| 6754 | | window->DC.ColumnsOffsetsT.resize(2); |
| 6755 | | window->DC.ColumnsOffsetsT[0] = 0.0f; |
| 6756 | | window->DC.ColumnsOffsetsT[1] = 1.0f; |
| 6757 | | } |
| 6758 | 6344 | } |
| 6759 | 6345 | |
| 6760 | 6346 | void ImGui::TreePush(const char* str_id) |
| r245117 | r245118 | |
| 7560 | 7146 | TexUvWhitePixel = ImVec2((TexExtraDataPos.x + 0.5f) / TexWidth, (TexExtraDataPos.y + 0.5f) / TexHeight); |
| 7561 | 7147 | |
| 7562 | 7148 | // Draw a mouse cursor into texture |
| 7563 | | // Because our font uses a single color channel, we have to spread the cursor in 2 layers (black/white) which will be rendered separately. |
| 7149 | // Because our font uses an alpha texture, we have to spread the cursor in 2 parts (black/white) which will be rendered separately. |
| 7564 | 7150 | const char cursor_pixels[] = |
| 7565 | 7151 | { |
| 7566 | 7152 | "X " |
| r245117 | r245118 | |
| 7609 | 7195 | DisplayOffset = ImVec2(-0.5f, 0.5f); |
| 7610 | 7196 | ContainerAtlas = NULL; |
| 7611 | 7197 | Glyphs.clear(); |
| 7612 | | FallbackGlyph = NULL; |
| 7613 | | FallbackXAdvance = 0.0f; |
| 7614 | | IndexXAdvance.clear(); |
| 7615 | 7198 | IndexLookup.clear(); |
| 7199 | FallbackGlyph = NULL; |
| 7616 | 7200 | } |
| 7617 | 7201 | |
| 7618 | 7202 | // Retrieve list of range (2 int per range, values are inclusive) |
| r245117 | r245118 | |
| 7631 | 7215 | static const ImWchar ranges[] = |
| 7632 | 7216 | { |
| 7633 | 7217 | 0x0020, 0x00FF, // Basic Latin + Latin Supplement |
| 7634 | | 0x3000, 0x30FF, // Punctuations, Hiragana, Katakana |
| 7635 | | 0x31F0, 0x31FF, // Katakana Phonetic Extensions |
| 7218 | 0x3040, 0x309F, // Hiragana, Katakana |
| 7636 | 7219 | 0xFF00, 0xFFEF, // Half-width characters |
| 7637 | 7220 | 0x4e00, 0x9FAF, // CJK Ideograms |
| 7638 | 7221 | 0, |
| r245117 | r245118 | |
| 7680 | 7263 | 109,2,18,23,0,0,9,61,3,0,28,41,77,27,19,17,81,5,2,14,5,83,57,252,14,154,263,14,20,8,13,6,57,39,38, |
| 7681 | 7264 | }; |
| 7682 | 7265 | static int ranges_unpacked = false; |
| 7683 | | static ImWchar ranges[8 + IM_ARRAYSIZE(offsets_from_0x4E00)*2 + 1] = |
| 7266 | static ImWchar ranges[6 + 1 + IM_ARRAYSIZE(offsets_from_0x4E00)*2] = |
| 7684 | 7267 | { |
| 7685 | 7268 | 0x0020, 0x00FF, // Basic Latin + Latin Supplement |
| 7686 | | 0x3000, 0x30FF, // Punctuations, Hiragana, Katakana |
| 7687 | | 0x31F0, 0x31FF, // Katakana Phonetic Extensions |
| 7269 | 0x3040, 0x309F, // Hiragana, Katakana |
| 7688 | 7270 | 0xFF00, 0xFFEF, // Half-width characters |
| 7271 | 0, |
| 7689 | 7272 | }; |
| 7690 | 7273 | if (!ranges_unpacked) |
| 7691 | 7274 | { |
| 7692 | 7275 | // Unpack |
| 7693 | 7276 | int codepoint = 0x4e00; |
| 7694 | | ImWchar* dst = &ranges[8]; |
| 7277 | ImWchar* dst = &ranges[6]; |
| 7695 | 7278 | for (int n = 0; n < IM_ARRAYSIZE(offsets_from_0x4E00); n++, dst += 2) |
| 7696 | 7279 | dst[0] = dst[1] = (ImWchar)(codepoint += (offsets_from_0x4E00[n] + 1)); |
| 7697 | 7280 | dst[0] = 0; |
| r245117 | r245118 | |
| 7706 | 7289 | for (size_t i = 0; i != Glyphs.size(); i++) |
| 7707 | 7290 | max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint); |
| 7708 | 7291 | |
| 7709 | | IndexXAdvance.clear(); |
| 7710 | | IndexXAdvance.resize((size_t)max_codepoint + 1); |
| 7711 | 7292 | IndexLookup.clear(); |
| 7712 | 7293 | IndexLookup.resize((size_t)max_codepoint + 1); |
| 7713 | | for (size_t i = 0; i < (size_t)max_codepoint + 1; i++) |
| 7714 | | { |
| 7715 | | IndexXAdvance[i] = -1.0f; |
| 7294 | for (size_t i = 0; i < IndexLookup.size(); i++) |
| 7716 | 7295 | IndexLookup[i] = -1; |
| 7717 | | } |
| 7718 | 7296 | for (size_t i = 0; i < Glyphs.size(); i++) |
| 7719 | | { |
| 7720 | | const size_t codepoint = (int)Glyphs[i].Codepoint; |
| 7721 | | IndexXAdvance[codepoint] = Glyphs[i].XAdvance; |
| 7722 | | IndexLookup[codepoint] = (int)i; |
| 7723 | | } |
| 7297 | IndexLookup[(int)Glyphs[i].Codepoint] = (int)i; |
| 7724 | 7298 | |
| 7725 | 7299 | // Create a glyph to handle TAB |
| 7726 | 7300 | // FIXME: Needs proper TAB handling but it needs to be contextualized (can arbitrary say that each string starts at "column 0" |
| 7727 | | if (FindGlyph((unsigned short)' ')) |
| 7301 | if (const ImFont::Glyph* space_glyph = FindGlyph((unsigned short)' ')) |
| 7728 | 7302 | { |
| 7729 | | if (Glyphs.back().Codepoint != '\t') // So we can call this function multiple times |
| 7730 | | Glyphs.resize(Glyphs.size() + 1); |
| 7303 | Glyphs.resize(Glyphs.size() + 1); |
| 7731 | 7304 | ImFont::Glyph& tab_glyph = Glyphs.back(); |
| 7732 | | tab_glyph = *FindGlyph((unsigned short)' '); |
| 7305 | tab_glyph = *space_glyph; |
| 7733 | 7306 | tab_glyph.Codepoint = '\t'; |
| 7734 | 7307 | tab_glyph.XAdvance *= 4; |
| 7735 | | IndexXAdvance[(size_t)tab_glyph.Codepoint] = (float)tab_glyph.XAdvance; |
| 7736 | | IndexLookup[(size_t)tab_glyph.Codepoint] = (int)(Glyphs.size()-1); |
| 7308 | IndexLookup[(int)tab_glyph.Codepoint] = (int)(Glyphs.size()-1); |
| 7737 | 7309 | } |
| 7738 | | |
| 7739 | | FallbackGlyph = NULL; |
| 7740 | | FallbackGlyph = FindGlyph(FallbackChar); |
| 7741 | | FallbackXAdvance = FallbackGlyph ? FallbackGlyph->XAdvance : 0.0f; |
| 7742 | | for (size_t i = 0; i < (size_t)max_codepoint + 1; i++) |
| 7743 | | if (IndexXAdvance[i] < 0.0f) |
| 7744 | | IndexXAdvance[i] = FallbackXAdvance; |
| 7745 | 7310 | } |
| 7746 | 7311 | |
| 7747 | | void ImFont::SetFallbackChar(ImWchar c) |
| 7748 | | { |
| 7749 | | FallbackChar = c; |
| 7750 | | BuildLookupTable(); |
| 7751 | | } |
| 7752 | | |
| 7753 | 7312 | const ImFont::Glyph* ImFont::FindGlyph(unsigned short c) const |
| 7754 | 7313 | { |
| 7755 | 7314 | if (c < (int)IndexLookup.size()) |
| r245117 | r245118 | |
| 7763 | 7322 | |
| 7764 | 7323 | // Convert UTF-8 to 32-bits character, process single character input. |
| 7765 | 7324 | // Based on stb_from_utf8() from github.com/nothings/stb/ |
| 7766 | | // We handle UTF-8 decoding error by skipping forward. |
| 7767 | 7325 | static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end) |
| 7768 | 7326 | { |
| 7769 | | unsigned int c = (unsigned int)-1; |
| 7770 | | const unsigned char* str = (const unsigned char*)in_text; |
| 7771 | | if (!(*str & 0x80)) |
| 7327 | if (*in_text != 0) |
| 7772 | 7328 | { |
| 7773 | | c = (unsigned int)(*str++); |
| 7774 | | *out_char = c; |
| 7775 | | return 1; |
| 7329 | unsigned int c = (unsigned int)-1; |
| 7330 | const unsigned char* str = (const unsigned char*)in_text; |
| 7331 | if (!(*str & 0x80)) |
| 7332 | { |
| 7333 | c = (unsigned int)(*str++); |
| 7334 | *out_char = c; |
| 7335 | return 1; |
| 7336 | } |
| 7337 | if ((*str & 0xe0) == 0xc0) |
| 7338 | { |
| 7339 | if (in_text_end && in_text_end - (const char*)str < 2) return -1; |
| 7340 | if (*str < 0xc2) return -1; |
| 7341 | c = (unsigned int)((*str++ & 0x1f) << 6); |
| 7342 | if ((*str & 0xc0) != 0x80) return -1; |
| 7343 | c += (*str++ & 0x3f); |
| 7344 | *out_char = c; |
| 7345 | return 2; |
| 7346 | } |
| 7347 | if ((*str & 0xf0) == 0xe0) |
| 7348 | { |
| 7349 | if (in_text_end && in_text_end - (const char*)str < 3) return -1; |
| 7350 | if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return -1; |
| 7351 | if (*str == 0xed && str[1] > 0x9f) return -1; // str[1] < 0x80 is checked below |
| 7352 | c = (unsigned int)((*str++ & 0x0f) << 12); |
| 7353 | if ((*str & 0xc0) != 0x80) return -1; |
| 7354 | c += (unsigned int)((*str++ & 0x3f) << 6); |
| 7355 | if ((*str & 0xc0) != 0x80) return -1; |
| 7356 | c += (*str++ & 0x3f); |
| 7357 | *out_char = c; |
| 7358 | return 3; |
| 7359 | } |
| 7360 | if ((*str & 0xf8) == 0xf0) |
| 7361 | { |
| 7362 | if (in_text_end && in_text_end - (const char*)str < 4) return -1; |
| 7363 | if (*str > 0xf4) return -1; |
| 7364 | if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return -1; |
| 7365 | if (*str == 0xf4 && str[1] > 0x8f) return -1; // str[1] < 0x80 is checked below |
| 7366 | c = (unsigned int)((*str++ & 0x07) << 18); |
| 7367 | if ((*str & 0xc0) != 0x80) return -1; |
| 7368 | c += (unsigned int)((*str++ & 0x3f) << 12); |
| 7369 | if ((*str & 0xc0) != 0x80) return -1; |
| 7370 | c += (unsigned int)((*str++ & 0x3f) << 6); |
| 7371 | if ((*str & 0xc0) != 0x80) return -1; |
| 7372 | c += (*str++ & 0x3f); |
| 7373 | // utf-8 encodings of values used in surrogate pairs are invalid |
| 7374 | if ((c & 0xFFFFF800) == 0xD800) return -1; |
| 7375 | *out_char = c; |
| 7376 | return 4; |
| 7377 | } |
| 7776 | 7378 | } |
| 7777 | | if ((*str & 0xe0) == 0xc0) |
| 7778 | | { |
| 7779 | | *out_char = 0; |
| 7780 | | if (in_text_end && in_text_end - (const char*)str < 2) return 0; |
| 7781 | | if (*str < 0xc2) return 0; |
| 7782 | | c = (unsigned int)((*str++ & 0x1f) << 6); |
| 7783 | | if ((*str & 0xc0) != 0x80) return 0; |
| 7784 | | c += (*str++ & 0x3f); |
| 7785 | | *out_char = c; |
| 7786 | | return 2; |
| 7787 | | } |
| 7788 | | if ((*str & 0xf0) == 0xe0) |
| 7789 | | { |
| 7790 | | *out_char = 0; |
| 7791 | | if (in_text_end && in_text_end - (const char*)str < 3) return 0; |
| 7792 | | if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return 0; |
| 7793 | | if (*str == 0xed && str[1] > 0x9f) return 0; // str[1] < 0x80 is checked below |
| 7794 | | c = (unsigned int)((*str++ & 0x0f) << 12); |
| 7795 | | if ((*str & 0xc0) != 0x80) return 0; |
| 7796 | | c += (unsigned int)((*str++ & 0x3f) << 6); |
| 7797 | | if ((*str & 0xc0) != 0x80) return 0; |
| 7798 | | c += (*str++ & 0x3f); |
| 7799 | | *out_char = c; |
| 7800 | | return 3; |
| 7801 | | } |
| 7802 | | if ((*str & 0xf8) == 0xf0) |
| 7803 | | { |
| 7804 | | *out_char = 0; |
| 7805 | | if (in_text_end && in_text_end - (const char*)str < 4) return 0; |
| 7806 | | if (*str > 0xf4) return 0; |
| 7807 | | if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return 0; |
| 7808 | | if (*str == 0xf4 && str[1] > 0x8f) return 0; // str[1] < 0x80 is checked below |
| 7809 | | c = (unsigned int)((*str++ & 0x07) << 18); |
| 7810 | | if ((*str & 0xc0) != 0x80) return 0; |
| 7811 | | c += (unsigned int)((*str++ & 0x3f) << 12); |
| 7812 | | if ((*str & 0xc0) != 0x80) return 0; |
| 7813 | | c += (unsigned int)((*str++ & 0x3f) << 6); |
| 7814 | | if ((*str & 0xc0) != 0x80) return 0; |
| 7815 | | c += (*str++ & 0x3f); |
| 7816 | | // utf-8 encodings of values used in surrogate pairs are invalid |
| 7817 | | if ((c & 0xFFFFF800) == 0xD800) return 0; |
| 7818 | | *out_char = c; |
| 7819 | | return 4; |
| 7820 | | } |
| 7821 | 7379 | *out_char = 0; |
| 7822 | 7380 | return 0; |
| 7823 | 7381 | } |
| 7824 | 7382 | |
| 7825 | | static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end, const char** in_text_remaining) |
| 7383 | static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end) |
| 7826 | 7384 | { |
| 7827 | 7385 | ImWchar* buf_out = buf; |
| 7828 | 7386 | ImWchar* buf_end = buf + buf_size; |
| r245117 | r245118 | |
| 7830 | 7388 | { |
| 7831 | 7389 | unsigned int c; |
| 7832 | 7390 | in_text += ImTextCharFromUtf8(&c, in_text, in_text_end); |
| 7833 | | if (c == 0) |
| 7834 | | break; |
| 7835 | 7391 | if (c < 0x10000) // FIXME: Losing characters that don't fit in 2 bytes |
| 7836 | 7392 | *buf_out++ = (ImWchar)c; |
| 7837 | 7393 | } |
| 7838 | 7394 | *buf_out = 0; |
| 7839 | | if (in_text_remaining) |
| 7840 | | *in_text_remaining = in_text; |
| 7841 | 7395 | return buf_out - buf; |
| 7842 | 7396 | } |
| 7843 | 7397 | |
| r245117 | r245118 | |
| 7848 | 7402 | { |
| 7849 | 7403 | unsigned int c; |
| 7850 | 7404 | in_text += ImTextCharFromUtf8(&c, in_text, in_text_end); |
| 7851 | | if (c == 0) |
| 7852 | | break; |
| 7853 | 7405 | if (c < 0x10000) |
| 7854 | 7406 | char_count++; |
| 7855 | 7407 | } |
| r245117 | r245118 | |
| 7914 | 7466 | return buf_out - buf; |
| 7915 | 7467 | } |
| 7916 | 7468 | |
| 7917 | | static int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end) |
| 7469 | static int ImTextCountUtf8BytesFromWchar(const ImWchar* in_text, const ImWchar* in_text_end) |
| 7918 | 7470 | { |
| 7919 | 7471 | int bytes_count = 0; |
| 7920 | 7472 | while ((!in_text_end || in_text < in_text_end) && *in_text) |
| r245117 | r245118 | |
| 7954 | 7506 | const char* s = text; |
| 7955 | 7507 | while (s < text_end) |
| 7956 | 7508 | { |
| 7957 | | unsigned int c = (unsigned int)*s; |
| 7958 | | const char* next_s; |
| 7959 | | if (c < 0x80) |
| 7960 | | next_s = s + 1; |
| 7961 | | else |
| 7962 | | next_s = s + ImTextCharFromUtf8(&c, s, text_end); |
| 7963 | | if (c == 0) |
| 7964 | | break; |
| 7509 | unsigned int c; |
| 7510 | const int bytes_count = ImTextCharFromUtf8(&c, s, text_end); |
| 7511 | const char* next_s = s + (bytes_count > 0 ? bytes_count : 1); |
| 7965 | 7512 | |
| 7966 | 7513 | if (c == '\n') |
| 7967 | 7514 | { |
| r245117 | r245118 | |
| 7971 | 7518 | continue; |
| 7972 | 7519 | } |
| 7973 | 7520 | |
| 7974 | | const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance; |
| 7975 | | if (ImCharIsSpace(c)) |
| 7521 | float char_width = 0.0f; |
| 7522 | if (const Glyph* glyph = FindGlyph((unsigned short)c)) |
| 7523 | char_width = glyph->XAdvance * scale; |
| 7524 | |
| 7525 | if (c == ' ' || c == '\t') |
| 7976 | 7526 | { |
| 7977 | 7527 | if (inside_word) |
| 7978 | 7528 | { |
| r245117 | r245118 | |
| 8054 | 7604 | while (s < text_end) |
| 8055 | 7605 | { |
| 8056 | 7606 | const char c = *s; |
| 8057 | | if (ImCharIsSpace(c)) { s++; } else if (c == '\n') { s++; break; } else { break; } |
| 7607 | if (c == ' ' || c == '\t') { s++; } else if (c == '\n') { s++; break; } else { break; } |
| 8058 | 7608 | } |
| 8059 | 7609 | continue; |
| 8060 | 7610 | } |
| 8061 | 7611 | } |
| 8062 | 7612 | |
| 8063 | 7613 | // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte) |
| 8064 | | unsigned int c = (unsigned int)*s; |
| 8065 | | if (c < 0x80) |
| 8066 | | { |
| 8067 | | s += 1; |
| 8068 | | } |
| 8069 | | else |
| 8070 | | { |
| 8071 | | s += ImTextCharFromUtf8(&c, s, text_end); |
| 8072 | | if (c == 0) |
| 8073 | | break; |
| 8074 | | } |
| 7614 | unsigned int c; |
| 7615 | const int bytes_count = ImTextCharFromUtf8(&c, s, text_end); |
| 7616 | s += bytes_count > 0 ? bytes_count : 1; |
| 8075 | 7617 | |
| 8076 | 7618 | if (c == '\n') |
| 8077 | 7619 | { |
| r245117 | r245118 | |
| 8081 | 7623 | continue; |
| 8082 | 7624 | } |
| 8083 | 7625 | |
| 8084 | | const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance; |
| 7626 | float char_width = 0.0f; |
| 7627 | if (const Glyph* glyph = FindGlyph((unsigned short)c)) |
| 7628 | char_width = glyph->XAdvance * scale; |
| 7629 | |
| 8085 | 7630 | if (line_width + char_width >= max_width) |
| 8086 | 7631 | break; |
| 8087 | 7632 | |
| r245117 | r245118 | |
| 8125 | 7670 | continue; |
| 8126 | 7671 | } |
| 8127 | 7672 | |
| 8128 | | const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance; |
| 7673 | float char_width = 0.0f; |
| 7674 | if (const Glyph* glyph = FindGlyph((unsigned short)c)) |
| 7675 | char_width = glyph->XAdvance * scale; |
| 7676 | |
| 8129 | 7677 | if (line_width + char_width >= max_width) |
| 8130 | 7678 | break; |
| 8131 | 7679 | |
| r245117 | r245118 | |
| 8192 | 7740 | while (s < text_end) |
| 8193 | 7741 | { |
| 8194 | 7742 | const char c = *s; |
| 8195 | | if (ImCharIsSpace(c)) { s++; } else if (c == '\n') { s++; break; } else { break; } |
| 7743 | if (c == ' ' || c == '\t') { s++; } else if (c == '\n') { s++; break; } else { break; } |
| 8196 | 7744 | } |
| 8197 | 7745 | continue; |
| 8198 | 7746 | } |
| 8199 | 7747 | } |
| 8200 | 7748 | |
| 8201 | 7749 | // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte) |
| 8202 | | unsigned int c = (unsigned int)*s; |
| 8203 | | if (c < 0x80) |
| 8204 | | { |
| 8205 | | s += 1; |
| 8206 | | } |
| 8207 | | else |
| 8208 | | { |
| 8209 | | s += ImTextCharFromUtf8(&c, s, text_end); |
| 8210 | | if (c == 0) |
| 8211 | | break; |
| 8212 | | } |
| 7750 | unsigned int c; |
| 7751 | const int bytes_count = ImTextCharFromUtf8(&c, s, text_end); |
| 7752 | s += bytes_count > 0 ? bytes_count : 1; |
| 8213 | 7753 | |
| 8214 | 7754 | if (c == '\n') |
| 8215 | 7755 | { |
| r245117 | r245118 | |
| 8291 | 7831 | |
| 8292 | 7832 | #if defined(_MSC_VER) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS) |
| 8293 | 7833 | |
| 8294 | | #ifndef _WINDOWS_ |
| 8295 | 7834 | #define WIN32_LEAN_AND_MEAN |
| 8296 | 7835 | #include <windows.h> |
| 8297 | | #endif |
| 8298 | 7836 | |
| 8299 | 7837 | // Win32 API clipboard implementation |
| 8300 | | static const char* GetClipboardTextFn_DefaultImpl() |
| 7838 | static const char* GetClipboardTextFn_DefaultImpl() |
| 8301 | 7839 | { |
| 8302 | 7840 | static char* buf_local = NULL; |
| 8303 | 7841 | if (buf_local) |
| r245117 | r245118 | |
| 8307 | 7845 | } |
| 8308 | 7846 | if (!OpenClipboard(NULL)) |
| 8309 | 7847 | return NULL; |
| 8310 | | HANDLE wbuf_handle = GetClipboardData(CF_UNICODETEXT); |
| 8311 | | if (wbuf_handle == NULL) |
| 7848 | HANDLE buf_handle = GetClipboardData(CF_TEXT); |
| 7849 | if (buf_handle == NULL) |
| 8312 | 7850 | return NULL; |
| 8313 | | if (ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle)) |
| 8314 | | { |
| 8315 | | int buf_len = ImTextCountUtf8BytesFromStr(wbuf_global, NULL) + 1; |
| 8316 | | buf_local = (char*)ImGui::MemAlloc(buf_len * sizeof(char)); |
| 8317 | | ImTextStrToUtf8(buf_local, buf_len, wbuf_global, NULL); |
| 8318 | | } |
| 8319 | | GlobalUnlock(wbuf_handle); |
| 7851 | if (char* buf_global = (char*)GlobalLock(buf_handle)) |
| 7852 | buf_local = ImStrdup(buf_global); |
| 7853 | GlobalUnlock(buf_handle); |
| 8320 | 7854 | CloseClipboard(); |
| 8321 | 7855 | return buf_local; |
| 8322 | 7856 | } |
| r245117 | r245118 | |
| 8326 | 7860 | { |
| 8327 | 7861 | if (!OpenClipboard(NULL)) |
| 8328 | 7862 | return; |
| 8329 | | |
| 8330 | | const int wbuf_length = ImTextCountCharsFromUtf8(text, NULL) + 1; |
| 8331 | | HGLOBAL wbuf_handle = GlobalAlloc(GMEM_MOVEABLE, (SIZE_T)wbuf_length * sizeof(ImWchar)); |
| 8332 | | if (wbuf_handle == NULL) |
| 7863 | const char* text_end = text + strlen(text); |
| 7864 | const int buf_length = (int)(text_end - text) + 1; |
| 7865 | HGLOBAL buf_handle = GlobalAlloc(GMEM_MOVEABLE, (SIZE_T)buf_length * sizeof(char)); |
| 7866 | if (buf_handle == NULL) |
| 8333 | 7867 | return; |
| 8334 | | ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle); |
| 8335 | | ImTextStrFromUtf8(wbuf_global, wbuf_length, text, NULL); |
| 8336 | | GlobalUnlock(wbuf_handle); |
| 7868 | char* buf_global = (char *)GlobalLock(buf_handle); |
| 7869 | memcpy(buf_global, text, (size_t)(text_end - text)); |
| 7870 | buf_global[text_end - text] = 0; |
| 7871 | GlobalUnlock(buf_handle); |
| 8337 | 7872 | EmptyClipboard(); |
| 8338 | | SetClipboardData(CF_UNICODETEXT, wbuf_handle); |
| 7873 | SetClipboardData(CF_TEXT, buf_handle); |
| 8339 | 7874 | CloseClipboard(); |
| 8340 | 7875 | } |
| 8341 | 7876 | |
| 8342 | 7877 | #else |
| 8343 | 7878 | |
| 8344 | 7879 | // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers |
| 8345 | | static const char* GetClipboardTextFn_DefaultImpl() |
| 7880 | static const char* GetClipboardTextFn_DefaultImpl() |
| 8346 | 7881 | { |
| 8347 | 7882 | return GImGui->PrivateClipboard; |
| 8348 | 7883 | } |
| r245117 | r245118 | |
| 8364 | 7899 | |
| 8365 | 7900 | #endif |
| 8366 | 7901 | |
| 8367 | | #if defined(_MSC_VER) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS) |
| 8368 | | |
| 8369 | | #ifndef _WINDOWS_ |
| 8370 | | #define WIN32_LEAN_AND_MEAN |
| 8371 | | #include <windows.h> |
| 8372 | | #endif |
| 8373 | | #include <Imm.h> |
| 8374 | | #pragma comment(lib, "imm32") |
| 8375 | | |
| 8376 | | static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y) |
| 8377 | | { |
| 8378 | | // Notify OS Input Method Editor of text input position |
| 8379 | | if (HWND hwnd = (HWND)GImGui->IO.ImeWindowHandle) |
| 8380 | | if (HIMC himc = ImmGetContext(hwnd)) |
| 8381 | | { |
| 8382 | | COMPOSITIONFORM cf; |
| 8383 | | cf.ptCurrentPos.x = x; |
| 8384 | | cf.ptCurrentPos.y = y; |
| 8385 | | cf.dwStyle = CFS_FORCE_POSITION; |
| 8386 | | ImmSetCompositionWindow(himc, &cf); |
| 8387 | | } |
| 8388 | | } |
| 8389 | | |
| 8390 | | #else |
| 8391 | | |
| 8392 | | static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y) |
| 8393 | | { |
| 8394 | | } |
| 8395 | | |
| 8396 | | #endif |
| 8397 | | |
| 8398 | 7902 | //----------------------------------------------------------------------------- |
| 8399 | 7903 | // HELP |
| 8400 | 7904 | //----------------------------------------------------------------------------- |
| r245117 | r245118 | |
| 8453 | 7957 | ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f"); |
| 8454 | 7958 | ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 10.0f, "%.0f"); |
| 8455 | 7959 | ImGui::SliderFloat("TreeNodeSpacing", &style.TreeNodeSpacing, 0.0f, 20.0f, "%.0f"); |
| 8456 | | ImGui::SliderFloat("ScrollBarWidth", &style.ScrollbarWidth, 1.0f, 20.0f, "%.0f"); |
| 8457 | | ImGui::SliderFloat("GrabMinSize", &style.GrabMinSize, 1.0f, 20.0f, "%.0f"); |
| 7960 | ImGui::SliderFloat("ScrollBarWidth", &style.ScrollBarWidth, 0.0f, 20.0f, "%.0f"); |
| 8458 | 7961 | ImGui::TreePop(); |
| 8459 | 7962 | } |
| 8460 | 7963 | |
| r245117 | r245118 | |
| 8525 | 8028 | static void ShowExampleAppLongText(bool* opened); |
| 8526 | 8029 | static void ShowExampleAppAutoResize(bool* opened); |
| 8527 | 8030 | static void ShowExampleAppFixedOverlay(bool* opened); |
| 8528 | | static void ShowExampleAppManipulatingWindowTitle(bool* opened); |
| 8529 | 8031 | static void ShowExampleAppCustomRendering(bool* opened); |
| 8530 | 8032 | |
| 8531 | 8033 | // Demonstrate ImGui features (unfortunately this makes this function a little bloated!) |
| 8532 | 8034 | void ImGui::ShowTestWindow(bool* opened) |
| 8533 | 8035 | { |
| 8534 | | // Examples apps |
| 8535 | | static bool show_app_console = false; |
| 8536 | | static bool show_app_long_text = false; |
| 8537 | | static bool show_app_auto_resize = false; |
| 8538 | | static bool show_app_fixed_overlay = false; |
| 8539 | | static bool show_app_custom_rendering = false; |
| 8540 | | static bool show_app_manipulating_window_title = false; |
| 8541 | | if (show_app_console) |
| 8542 | | ShowExampleAppConsole(&show_app_console); |
| 8543 | | if (show_app_long_text) |
| 8544 | | ShowExampleAppLongText(&show_app_long_text); |
| 8545 | | if (show_app_auto_resize) |
| 8546 | | ShowExampleAppAutoResize(&show_app_auto_resize); |
| 8547 | | if (show_app_fixed_overlay) |
| 8548 | | ShowExampleAppFixedOverlay(&show_app_fixed_overlay); |
| 8549 | | if (show_app_manipulating_window_title) |
| 8550 | | ShowExampleAppManipulatingWindowTitle(&show_app_manipulating_window_title); |
| 8551 | | if (show_app_custom_rendering) |
| 8552 | | ShowExampleAppCustomRendering(&show_app_custom_rendering); |
| 8553 | | |
| 8554 | 8036 | static bool no_titlebar = false; |
| 8555 | 8037 | static bool no_border = true; |
| 8556 | 8038 | static bool no_resize = false; |
| 8557 | 8039 | static bool no_move = false; |
| 8558 | 8040 | static bool no_scrollbar = false; |
| 8559 | 8041 | static bool no_collapse = false; |
| 8560 | | static float bg_alpha = 0.65f; |
| 8042 | static float fill_alpha = 0.65f; |
| 8561 | 8043 | |
| 8562 | 8044 | // Demonstrate the various window flags. Typically you would just use the default. |
| 8563 | 8045 | ImGuiWindowFlags window_flags = 0; |
| r245117 | r245118 | |
| 8567 | 8049 | if (no_move) window_flags |= ImGuiWindowFlags_NoMove; |
| 8568 | 8050 | if (no_scrollbar) window_flags |= ImGuiWindowFlags_NoScrollbar; |
| 8569 | 8051 | if (no_collapse) window_flags |= ImGuiWindowFlags_NoCollapse; |
| 8570 | | if (!ImGui::Begin("ImGui Test", opened, ImVec2(550,680), bg_alpha, window_flags)) |
| 8052 | if (!ImGui::Begin("ImGui Test", opened, ImVec2(550,680), fill_alpha, window_flags)) |
| 8571 | 8053 | { |
| 8572 | 8054 | // Early out if the window is collapsed, as an optimization. |
| 8573 | 8055 | ImGui::End(); |
| 8574 | 8056 | return; |
| 8575 | 8057 | } |
| 8058 | ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); |
| 8576 | 8059 | |
| 8577 | | ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); // 2/3 of the space for widget and 1/3 for labels |
| 8578 | | //ImGui::PushItemWidth(-140); // Right align, keep 140 pixels for labels |
| 8579 | | |
| 8580 | 8060 | ImGui::Text("ImGui says hello."); |
| 8581 | 8061 | //ImGui::Text("MousePos (%g, %g)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y); |
| 8582 | 8062 | //ImGui::Text("MouseWheel %d", ImGui::GetIO().MouseWheel); |
| r245117 | r245118 | |
| 8598 | 8078 | ImGui::Checkbox("no move", &no_move); ImGui::SameLine(150); |
| 8599 | 8079 | ImGui::Checkbox("no scrollbar", &no_scrollbar); ImGui::SameLine(300); |
| 8600 | 8080 | ImGui::Checkbox("no collapse", &no_collapse); |
| 8601 | | ImGui::SliderFloat("bg alpha", &bg_alpha, 0.0f, 1.0f); |
| 8081 | ImGui::SliderFloat("fill alpha", &fill_alpha, 0.0f, 1.0f); |
| 8602 | 8082 | |
| 8603 | 8083 | if (ImGui::TreeNode("Style")) |
| 8604 | 8084 | { |
| r245117 | r245118 | |
| 8669 | 8149 | { |
| 8670 | 8150 | ImGui::BulletText("Bullet point 1"); |
| 8671 | 8151 | ImGui::BulletText("Bullet point 2\nOn multiple lines"); |
| 8672 | | ImGui::Bullet(); ImGui::Text("Bullet point 3 (two calls)"); |
| 8673 | | ImGui::Bullet(); ImGui::SmallButton("Button 1"); |
| 8674 | | ImGui::Bullet(); ImGui::SmallButton("Button 2"); |
| 8152 | ImGui::BulletText("Bullet point 3"); |
| 8675 | 8153 | ImGui::TreePop(); |
| 8676 | 8154 | } |
| 8677 | 8155 | |
| r245117 | r245118 | |
| 8813 | 8291 | ImGui::TreePop(); |
| 8814 | 8292 | } |
| 8815 | 8293 | |
| 8816 | | if (ImGui::TreeNode("Filtered Text Input")) |
| 8817 | | { |
| 8818 | | static char buf1[64] = ""; ImGui::InputText("default", buf1, 64); |
| 8819 | | static char buf2[64] = ""; ImGui::InputText("decimal", buf2, 64, ImGuiInputTextFlags_CharsDecimal); |
| 8820 | | static char buf3[64] = ""; ImGui::InputText("hexadecimal", buf3, 64, ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase); |
| 8821 | | static char buf4[64] = ""; ImGui::InputText("uppercase", buf4, 64, ImGuiInputTextFlags_CharsUppercase); |
| 8822 | | static char buf5[64] = ""; ImGui::InputText("no blank", buf5, 64, ImGuiInputTextFlags_CharsNoBlank); |
| 8823 | | struct TextFilters { static int FilterImGuiLetters(ImGuiTextEditCallbackData* data) { if (data->EventChar < 256 && strchr("imgui", (char)data->EventChar)) return 0; return 1; } }; |
| 8824 | | static char buf6[64] = ""; ImGui::InputText("\"imgui\" letters", buf6, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterImGuiLetters); |
| 8825 | | ImGui::TreePop(); |
| 8826 | | } |
| 8827 | | |
| 8828 | 8294 | static bool check = true; |
| 8829 | 8295 | ImGui::Checkbox("checkbox", &check); |
| 8830 | 8296 | |
| r245117 | r245118 | |
| 8926 | 8392 | static int listbox_item_current = 1; |
| 8927 | 8393 | ImGui::ListBox("listbox\n(single select)", &listbox_item_current, listbox_items, IM_ARRAYSIZE(listbox_items), 4); |
| 8928 | 8394 | |
| 8929 | | //static int listbox_item_current2 = 2; |
| 8930 | 8395 | //ImGui::PushItemWidth(-1); |
| 8931 | 8396 | //ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4); |
| 8932 | 8397 | //ImGui::PopItemWidth(); |
| r245117 | r245118 | |
| 8990 | 8455 | ImGui::SameLine(); |
| 8991 | 8456 | ImGui::Checkbox("Rich", &c4); |
| 8992 | 8457 | |
| 8993 | | // Various |
| 8458 | // SliderFloat |
| 8994 | 8459 | static float f0=1.0f, f1=2.0f, f2=3.0f; |
| 8995 | 8460 | ImGui::PushItemWidth(80); |
| 8996 | | const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD" }; |
| 8997 | | static int item = -1; |
| 8998 | | ImGui::Combo("Combo", &item, items, IM_ARRAYSIZE(items)); |
| 8999 | | ImGui::SameLine(); |
| 9000 | 8461 | ImGui::SliderFloat("X", &f0, 0.0f,5.0f); |
| 9001 | 8462 | ImGui::SameLine(); |
| 9002 | 8463 | ImGui::SliderFloat("Y", &f1, 0.0f,5.0f); |
| 9003 | 8464 | ImGui::SameLine(); |
| 9004 | 8465 | ImGui::SliderFloat("Z", &f2, 0.0f,5.0f); |
| 9005 | | ImGui::PopItemWidth(); |
| 9006 | | |
| 9007 | | ImGui::PushItemWidth(80); |
| 9008 | | ImGui::Text("Lists:"); |
| 9009 | | static int selection[4] = { 0, 1, 2, 3 }; |
| 9010 | | for (int i = 0; i < 4; i++) |
| 9011 | | { |
| 9012 | | if (i > 0) ImGui::SameLine(); |
| 9013 | | ImGui::PushID(i); |
| 9014 | | ImGui::ListBox("", &selection[i], items, IM_ARRAYSIZE(items)); |
| 9015 | | ImGui::PopID(); |
| 9016 | | //if (ImGui::IsItemHovered()) ImGui::SetTooltip("ListBox %d hovered", i); |
| 9017 | | } |
| 9018 | | ImGui::PopItemWidth(); |
| 9019 | 8466 | } |
| 9020 | 8467 | |
| 9021 | 8468 | if (ImGui::CollapsingHeader("Child regions")) |
| r245117 | r245118 | |
| 9058 | 8505 | |
| 9059 | 8506 | if (ImGui::CollapsingHeader("Columns")) |
| 9060 | 8507 | { |
| 9061 | | // Basic columns |
| 9062 | | ImGui::Text("Basic:"); |
| 9063 | | ImGui::Columns(4, "mycolumns"); |
| 8508 | ImGui::Columns(4, "data", true); |
| 9064 | 8509 | ImGui::Text("ID"); ImGui::NextColumn(); |
| 9065 | 8510 | ImGui::Text("Name"); ImGui::NextColumn(); |
| 9066 | 8511 | ImGui::Text("Path"); ImGui::NextColumn(); |
| 9067 | 8512 | ImGui::Text("Flags"); ImGui::NextColumn(); |
| 9068 | 8513 | ImGui::Separator(); |
| 9069 | | const char* names[3] = { "Robert", "Stephanie", "C64" }; |
| 9070 | | const char* paths[3] = { "/path/robert", "/path/stephanie", "/path/computer" }; |
| 9071 | | for (int i = 0; i < 3; i++) |
| 9072 | | { |
| 9073 | | ImGui::Text("%04d", i); ImGui::NextColumn(); |
| 9074 | | ImGui::Text(names[i]); ImGui::NextColumn(); |
| 9075 | | ImGui::Text(paths[i]); ImGui::NextColumn(); |
| 9076 | | ImGui::Text("...."); ImGui::NextColumn(); |
| 9077 | | } |
| 9078 | | ImGui::Columns(1); |
| 9079 | 8514 | |
| 9080 | | ImGui::Separator(); |
| 9081 | | ImGui::Spacing(); |
| 8515 | ImGui::Text("0000"); ImGui::NextColumn(); |
| 8516 | ImGui::Text("Robert"); ImGui::NextColumn(); |
| 8517 | ImGui::Text("/path/robert"); ImGui::NextColumn(); |
| 8518 | ImGui::Text("...."); ImGui::NextColumn(); |
| 9082 | 8519 | |
| 9083 | | // Scrolling columns |
| 9084 | | /* |
| 9085 | | ImGui::Text("Scrolling:"); |
| 9086 | | ImGui::BeginChild("##header", ImVec2(0, ImGui::GetTextLineHeightWithSpacing()+ImGui::GetStyle().ItemSpacing.y)); |
| 9087 | | ImGui::Columns(3); |
| 9088 | | ImGui::Text("ID"); ImGui::NextColumn(); |
| 9089 | | ImGui::Text("Name"); ImGui::NextColumn(); |
| 9090 | | ImGui::Text("Path"); ImGui::NextColumn(); |
| 8520 | ImGui::Text("0001"); ImGui::NextColumn(); |
| 8521 | ImGui::Text("Stephanie"); ImGui::NextColumn(); |
| 8522 | ImGui::Text("/path/stephanie"); ImGui::NextColumn(); |
| 8523 | ImGui::Text("line 1"); ImGui::Text("line 2"); ImGui::NextColumn(); // two lines, two items |
| 8524 | |
| 8525 | ImGui::Text("0002"); ImGui::NextColumn(); |
| 8526 | ImGui::Text("C64"); ImGui::NextColumn(); |
| 8527 | ImGui::Text("/path/computer"); ImGui::NextColumn(); |
| 8528 | ImGui::Text("...."); ImGui::NextColumn(); |
| 9091 | 8529 | ImGui::Columns(1); |
| 9092 | | ImGui::Separator(); |
| 9093 | | ImGui::EndChild(); |
| 9094 | | ImGui::BeginChild("##scrollingregion", ImVec2(0, 60)); |
| 9095 | | ImGui::Columns(3); |
| 9096 | | for (int i = 0; i < 10; i++) |
| 9097 | | { |
| 9098 | | ImGui::Text("%04d", i); ImGui::NextColumn(); |
| 9099 | | ImGui::Text("Foobar"); ImGui::NextColumn(); |
| 9100 | | ImGui::Text("/path/foobar/%04d/", i); ImGui::NextColumn(); |
| 9101 | | } |
| 9102 | | ImGui::Columns(1); |
| 9103 | | ImGui::EndChild(); |
| 9104 | 8530 | |
| 9105 | 8531 | ImGui::Separator(); |
| 9106 | | ImGui::Spacing(); |
| 9107 | | */ |
| 9108 | 8532 | |
| 9109 | | // Create multiple items in a same cell before switching to next column |
| 9110 | | ImGui::Text("Mixed items:"); |
| 9111 | 8533 | ImGui::Columns(3, "mixed"); |
| 9112 | | ImGui::Separator(); |
| 9113 | 8534 | |
| 8535 | // Create multiple items in a same cell because switching to next column |
| 9114 | 8536 | static int e = 0; |
| 9115 | 8537 | ImGui::Text("Hello"); |
| 9116 | 8538 | ImGui::Button("Banana"); |
| r245117 | r245118 | |
| 9120 | 8542 | ImGui::Text("ImGui"); |
| 9121 | 8543 | ImGui::Button("Apple"); |
| 9122 | 8544 | ImGui::RadioButton("radio b", &e, 1); |
| 9123 | | static float foo = 1.0f; |
| 9124 | | ImGui::InputFloat("red", &foo, 0.05f, 0, 3); |
| 9125 | 8545 | ImGui::Text("An extra line here."); |
| 9126 | 8546 | ImGui::NextColumn(); |
| 9127 | 8547 | |
| 9128 | 8548 | ImGui::Text("World!"); |
| 9129 | 8549 | ImGui::Button("Corniflower"); |
| 9130 | 8550 | ImGui::RadioButton("radio c", &e, 2); |
| 9131 | | static float bar = 1.0f; |
| 9132 | | ImGui::InputFloat("blue", &bar, 0.05f, 0, 3); |
| 9133 | 8551 | ImGui::NextColumn(); |
| 9134 | 8552 | |
| 9135 | 8553 | if (ImGui::CollapsingHeader("Category A")) ImGui::Text("Blah blah blah"); ImGui::NextColumn(); |
| 9136 | 8554 | if (ImGui::CollapsingHeader("Category B")) ImGui::Text("Blah blah blah"); ImGui::NextColumn(); |
| 9137 | 8555 | if (ImGui::CollapsingHeader("Category C")) ImGui::Text("Blah blah blah"); ImGui::NextColumn(); |
| 8556 | |
| 9138 | 8557 | ImGui::Columns(1); |
| 9139 | 8558 | |
| 9140 | 8559 | ImGui::Separator(); |
| 9141 | | ImGui::Spacing(); |
| 9142 | 8560 | |
| 9143 | | // Tree items |
| 9144 | | ImGui::Text("Tree items:"); |
| 9145 | | ImGui::Columns(2, "tree items"); |
| 9146 | | ImGui::Separator(); |
| 9147 | | if (ImGui::TreeNode("Hello")) { ImGui::BulletText("World"); ImGui::TreePop(); } ImGui::NextColumn(); |
| 9148 | | if (ImGui::TreeNode("Bonjour")) { ImGui::BulletText("Monde"); ImGui::TreePop(); } ImGui::NextColumn(); |
| 8561 | ImGui::Columns(2, "multiple components"); |
| 8562 | static float foo = 1.0f; |
| 8563 | ImGui::InputFloat("red", &foo, 0.05f, 0, 3); ImGui::NextColumn(); |
| 8564 | static float bar = 1.0f; |
| 8565 | ImGui::InputFloat("blue", &bar, 0.05f, 0, 3); ImGui::NextColumn(); |
| 9149 | 8566 | ImGui::Columns(1); |
| 9150 | 8567 | |
| 9151 | 8568 | ImGui::Separator(); |
| 9152 | | ImGui::Spacing(); |
| 9153 | 8569 | |
| 9154 | | // Word-wrapping |
| 9155 | | ImGui::Text("Word-wrapping:"); |
| 9156 | | ImGui::Columns(2, "word-wrapping"); |
| 8570 | ImGui::Columns(2, "tree items"); |
| 8571 | if (ImGui::TreeNode("Hello")) { ImGui::BulletText("World"); ImGui::TreePop(); } ImGui::NextColumn(); |
| 8572 | if (ImGui::TreeNode("Bonjour")) { ImGui::BulletText("Monde"); ImGui::TreePop(); } |
| 8573 | ImGui::Columns(1); |
| 9157 | 8574 | ImGui::Separator(); |
| 8575 | |
| 8576 | ImGui::Columns(2, "word wrapping"); |
| 9158 | 8577 | ImGui::TextWrapped("The quick brown fox jumps over the lazy dog."); |
| 9159 | 8578 | ImGui::Text("Hello Left"); |
| 9160 | 8579 | ImGui::NextColumn(); |
| r245117 | r245118 | |
| 9163 | 8582 | ImGui::Columns(1); |
| 9164 | 8583 | |
| 9165 | 8584 | ImGui::Separator(); |
| 9166 | | ImGui::Spacing(); |
| 9167 | 8585 | |
| 9168 | 8586 | if (ImGui::TreeNode("Inside a tree..")) |
| 9169 | 8587 | { |
| 9170 | 8588 | if (ImGui::TreeNode("node 1 (with borders)")) |
| 9171 | 8589 | { |
| 9172 | 8590 | ImGui::Columns(4); |
| 9173 | | for (int i = 0; i < 8; i++) |
| 9174 | | { |
| 9175 | | ImGui::Text("%c%c%c", 'a'+i, 'a'+i, 'a'+i); |
| 9176 | | ImGui::NextColumn(); |
| 9177 | | } |
| 8591 | ImGui::Text("aaa"); ImGui::NextColumn(); |
| 8592 | ImGui::Text("bbb"); ImGui::NextColumn(); |
| 8593 | ImGui::Text("ccc"); ImGui::NextColumn(); |
| 8594 | ImGui::Text("ddd"); ImGui::NextColumn(); |
| 8595 | ImGui::Text("eee"); ImGui::NextColumn(); |
| 8596 | ImGui::Text("fff"); ImGui::NextColumn(); |
| 8597 | ImGui::Text("ggg"); ImGui::NextColumn(); |
| 8598 | ImGui::Text("hhh"); ImGui::NextColumn(); |
| 9178 | 8599 | ImGui::Columns(1); |
| 9179 | 8600 | ImGui::TreePop(); |
| 9180 | 8601 | } |
| 9181 | 8602 | if (ImGui::TreeNode("node 2 (without borders)")) |
| 9182 | 8603 | { |
| 9183 | 8604 | ImGui::Columns(4, NULL, false); |
| 9184 | | for (int i = 0; i < 8; i++) |
| 9185 | | { |
| 9186 | | ImGui::Text("%c%c%c", 'a'+i, 'a'+i, 'a'+i); |
| 9187 | | ImGui::NextColumn(); |
| 9188 | | } |
| 8605 | ImGui::Text("aaa"); ImGui::NextColumn(); |
| 8606 | ImGui::Text("bbb"); ImGui::NextColumn(); |
| 8607 | ImGui::Text("ccc"); ImGui::NextColumn(); |
| 8608 | ImGui::Text("ddd"); ImGui::NextColumn(); |
| 8609 | ImGui::Text("eee"); ImGui::NextColumn(); |
| 8610 | ImGui::Text("fff"); ImGui::NextColumn(); |
| 8611 | ImGui::Text("ggg"); ImGui::NextColumn(); |
| 8612 | ImGui::Text("hhh"); ImGui::NextColumn(); |
| 9189 | 8613 | ImGui::Columns(1); |
| 9190 | 8614 | ImGui::TreePop(); |
| 9191 | 8615 | } |
| r245117 | r245118 | |
| 9250 | 8674 | ImGui::Text("Item with focus: %d", has_focus); |
| 9251 | 8675 | else |
| 9252 | 8676 | ImGui::Text("Item with focus: <none>"); |
| 9253 | | ImGui::TextWrapped("Cursor & selection are preserved when refocusing last used item in code."); |
| 9254 | 8677 | ImGui::TreePop(); |
| 9255 | 8678 | } |
| 9256 | 8679 | } |
| 9257 | 8680 | |
| 8681 | static bool show_app_console = false; |
| 8682 | static bool show_app_long_text = false; |
| 8683 | static bool show_app_auto_resize = false; |
| 8684 | static bool show_app_fixed_overlay = false; |
| 8685 | static bool show_app_custom_rendering = false; |
| 9258 | 8686 | if (ImGui::CollapsingHeader("App Examples")) |
| 9259 | 8687 | { |
| 9260 | 8688 | ImGui::Checkbox("Console", &show_app_console); |
| 9261 | 8689 | ImGui::Checkbox("Long text display", &show_app_long_text); |
| 9262 | 8690 | ImGui::Checkbox("Auto-resizing window", &show_app_auto_resize); |
| 9263 | 8691 | ImGui::Checkbox("Simple overlay", &show_app_fixed_overlay); |
| 9264 | | ImGui::Checkbox("Manipulating window title", &show_app_manipulating_window_title); |
| 9265 | 8692 | ImGui::Checkbox("Custom rendering", &show_app_custom_rendering); |
| 9266 | 8693 | } |
| 8694 | if (show_app_console) |
| 8695 | ShowExampleAppConsole(&show_app_console); |
| 8696 | if (show_app_long_text) |
| 8697 | ShowExampleAppLongText(&show_app_long_text); |
| 8698 | if (show_app_auto_resize) |
| 8699 | ShowExampleAppAutoResize(&show_app_auto_resize); |
| 8700 | if (show_app_fixed_overlay) |
| 8701 | ShowExampleAppFixedOverlay(&show_app_fixed_overlay); |
| 8702 | if (show_app_custom_rendering) |
| 8703 | ShowExampleAppCustomRendering(&show_app_custom_rendering); |
| 9267 | 8704 | |
| 9268 | 8705 | ImGui::End(); |
| 9269 | 8706 | } |
| r245117 | r245118 | |
| 9301 | 8738 | ImGui::End(); |
| 9302 | 8739 | } |
| 9303 | 8740 | |
| 9304 | | static void ShowExampleAppManipulatingWindowTitle(bool* /*opened*/) |
| 9305 | | { |
| 9306 | | // By default, Windows are uniquely identified by their title. |
| 9307 | | // You can use the "##" and "###" markers to manipulate the display/ID. Read FAQ at the top of this file! |
| 9308 | | |
| 9309 | | // Using "##" to display same title but have unique identifier. |
| 9310 | | ImGui::SetNextWindowPos(ImVec2(100,100), ImGuiSetCond_FirstUseEver); |
| 9311 | | ImGui::Begin("Same title as another window##1"); |
| 9312 | | ImGui::Text("This is window 1.\nMy title is the same as window 2, but my identifier is unique."); |
| 9313 | | ImGui::End(); |
| 9314 | | |
| 9315 | | ImGui::SetNextWindowPos(ImVec2(100,200), ImGuiSetCond_FirstUseEver); |
| 9316 | | ImGui::Begin("Same title as another window##2"); |
| 9317 | | ImGui::Text("This is window 2.\nMy title is the same as window 1, but my identifier is unique."); |
| 9318 | | ImGui::End(); |
| 9319 | | |
| 9320 | | // Using "###" to display a changing title but keep a static identifier "MyWindow" |
| 9321 | | char buf[128]; |
| 9322 | | ImFormatString(buf, IM_ARRAYSIZE(buf), "Animated title %c %d###MyWindow", "|/-\\"[(int)(ImGui::GetTime()/0.25f)&3], rand()); |
| 9323 | | ImGui::SetNextWindowPos(ImVec2(100,300), ImGuiSetCond_FirstUseEver); |
| 9324 | | ImGui::Begin(buf); |
| 9325 | | ImGui::Text("This window has a changing title."); |
| 9326 | | ImGui::End(); |
| 9327 | | } |
| 9328 | | |
| 9329 | 8741 | static void ShowExampleAppCustomRendering(bool* opened) |
| 9330 | 8742 | { |
| 9331 | | ImGui::SetNextWindowSize(ImVec2(300,350), ImGuiSetCond_FirstUseEver); |
| 9332 | 8743 | if (!ImGui::Begin("Example: Custom Rendering", opened)) |
| 9333 | 8744 | { |
| 9334 | 8745 | ImGui::End(); |
| r245117 | r245118 | |
| 9343 | 8754 | static ImVector<ImVec2> points; |
| 9344 | 8755 | static bool adding_line = false; |
| 9345 | 8756 | if (ImGui::Button("Clear")) points.clear(); |
| 9346 | | if (points.size() >= 2) { ImGui::SameLine(); if (ImGui::Button("Undo")) { points.pop_back(); points.pop_back(); } } |
| 8757 | if (points.size() > 2) { ImGui::SameLine(); if (ImGui::Button("Undo")) points.pop_back(); } |
| 9347 | 8758 | ImGui::Text("Left-click and drag to add lines"); |
| 9348 | 8759 | ImGui::Text("Right-click to undo"); |
| 9349 | 8760 | |
| r245117 | r245118 | |
| 9449 | 8860 | if (ImGui::SmallButton("Add Dummy Text")) { AddLog("%d some text", Items.size()); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine(); |
| 9450 | 8861 | if (ImGui::SmallButton("Add Dummy Error")) AddLog("[error] something went wrong"); ImGui::SameLine(); |
| 9451 | 8862 | if (ImGui::SmallButton("Clear")) ClearLog(); |
| 9452 | | //static float t = 0.0f; if (ImGui::GetTime() - t > 0.02f) { t = ImGui::GetTime(); AddLog("Spam %f", t); } |
| 9453 | | |
| 9454 | 8863 | ImGui::Separator(); |
| 9455 | 8864 | |
| 9456 | 8865 | ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0)); |
| r245117 | r245118 | |
| 9536 | 8945 | } |
| 9537 | 8946 | } |
| 9538 | 8947 | |
| 9539 | | static int TextEditCallbackStub(ImGuiTextEditCallbackData* data) |
| 8948 | static void TextEditCallbackStub(ImGuiTextEditCallbackData* data) |
| 9540 | 8949 | { |
| 9541 | 8950 | ExampleAppConsole* console = (ExampleAppConsole*)data->UserData; |
| 9542 | | return console->TextEditCallback(data); |
| 8951 | console->TextEditCallback(data); |
| 9543 | 8952 | } |
| 9544 | 8953 | |
| 9545 | | int TextEditCallback(ImGuiTextEditCallbackData* data) |
| 8954 | void TextEditCallback(ImGuiTextEditCallbackData* data) |
| 9546 | 8955 | { |
| 9547 | 8956 | //AddLog("cursor: %d, selection: %d-%d", data->CursorPos, data->SelectionStart, data->SelectionEnd); |
| 9548 | | switch (data->EventFlag) |
| 8957 | switch (data->EventKey) |
| 9549 | 8958 | { |
| 9550 | | case ImGuiInputTextFlags_CallbackCompletion: |
| 8959 | case ImGuiKey_Tab: |
| 9551 | 8960 | { |
| 9552 | 8961 | // Example of TEXT COMPLETION |
| 9553 | 8962 | |
| r245117 | r245118 | |
| 9557 | 8966 | while (word_start > data->Buf) |
| 9558 | 8967 | { |
| 9559 | 8968 | const char c = word_start[-1]; |
| 9560 | | if (ImCharIsSpace(c) || c == ',' || c == ';') |
| 8969 | if (c == ' ' || c == '\t' || c == ',' || c == ';') |
| 9561 | 8970 | break; |
| 9562 | 8971 | word_start--; |
| 9563 | 8972 | } |
| r245117 | r245118 | |
| 9612 | 9021 | |
| 9613 | 9022 | break; |
| 9614 | 9023 | } |
| 9615 | | case ImGuiInputTextFlags_CallbackHistory: |
| 9024 | case ImGuiKey_UpArrow: |
| 9025 | case ImGuiKey_DownArrow: |
| 9616 | 9026 | { |
| 9617 | 9027 | // Example of HISTORY |
| 9618 | 9028 | const int prev_history_pos = HistoryPos; |
| r245117 | r245118 | |
| 9639 | 9049 | } |
| 9640 | 9050 | } |
| 9641 | 9051 | } |
| 9642 | | return 0; |
| 9643 | 9052 | } |
| 9644 | 9053 | }; |
| 9645 | 9054 | |
trunk/3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.h
| r245117 | r245118 | |
| 1 | | // ImGui library v1.35 |
| 1 | // ImGui library v1.32 wip |
| 2 | 2 | // See .cpp file for documentation. |
| 3 | 3 | // See ImGui::ShowTestWindow() for sample code. |
| 4 | 4 | // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase. |
| r245117 | r245118 | |
| 6 | 6 | |
| 7 | 7 | #pragma once |
| 8 | 8 | |
| 9 | | #include "imconfig.h" // User-editable configuration file |
| 9 | struct ImDrawCmd; |
| 10 | struct ImDrawList; |
| 11 | struct ImFont; |
| 12 | struct ImFontAtlas; |
| 13 | struct ImGuiAabb; |
| 14 | struct ImGuiIO; |
| 15 | struct ImGuiStorage; |
| 16 | struct ImGuiStyle; |
| 17 | struct ImGuiWindow; |
| 18 | |
| 19 | #include "imconfig.h" |
| 10 | 20 | #include <float.h> // FLT_MAX |
| 11 | 21 | #include <stdarg.h> // va_list |
| 12 | 22 | #include <stddef.h> // ptrdiff_t |
| 13 | 23 | #include <stdlib.h> // NULL, malloc |
| 14 | 24 | #include <string.h> // memset, memmove |
| 15 | 25 | |
| 16 | | // Define assertion handler. |
| 17 | 26 | #ifndef IM_ASSERT |
| 18 | 27 | #include <assert.h> |
| 19 | 28 | #define IM_ASSERT(_EXPR) assert(_EXPR) |
| 20 | 29 | #endif |
| 21 | 30 | |
| 22 | | // Define attributes of all API symbols declarations, e.g. for DLL under Windows. |
| 23 | 31 | #ifndef IMGUI_API |
| 24 | 32 | #define IMGUI_API |
| 25 | 33 | #endif |
| 26 | 34 | |
| 27 | | // Forward declarations |
| 28 | | struct ImDrawCmd; |
| 29 | | struct ImDrawList; |
| 30 | | struct ImFont; |
| 31 | | struct ImFontAtlas; |
| 32 | | struct ImGuiIO; |
| 33 | | struct ImGuiStorage; |
| 34 | | struct ImGuiStyle; |
| 35 | | |
| 36 | 35 | typedef unsigned int ImU32; |
| 37 | 36 | typedef unsigned short ImWchar; // character for display |
| 38 | 37 | typedef void* ImTextureID; // user data to refer to a texture (e.g. store your texture handle/id) |
| r245117 | r245118 | |
| 42 | 41 | typedef int ImGuiKey; // enum ImGuiKey_ |
| 43 | 42 | typedef int ImGuiColorEditMode; // enum ImGuiColorEditMode_ |
| 44 | 43 | typedef int ImGuiWindowFlags; // enum ImGuiWindowFlags_ |
| 45 | | typedef int ImGuiSetCond; // enum ImGuiSetCondition_ |
| 44 | typedef int ImGuiSetCondition; // enum ImGuiSetCondition_ |
| 46 | 45 | typedef int ImGuiInputTextFlags; // enum ImGuiInputTextFlags_ |
| 47 | | struct ImGuiTextEditCallbackData; // for advanced uses of InputText() |
| 48 | | typedef int (*ImGuiTextEditCallback)(ImGuiTextEditCallbackData *data); |
| 46 | struct ImGuiTextEditCallbackData; // for advanced uses of InputText() |
| 49 | 47 | |
| 50 | 48 | struct ImVec2 |
| 51 | 49 | { |
| r245117 | r245118 | |
| 76 | 74 | IMGUI_API void MemFree(void* ptr); |
| 77 | 75 | } |
| 78 | 76 | |
| 79 | | // std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug). |
| 77 | // std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug). |
| 80 | 78 | // Use '#define ImVector std::vector' if you want to use the STL type or your own type. |
| 81 | 79 | // Our implementation does NOT call c++ constructors! because the data types we use don't need them (but that could be added as well). Only provide the minimum functionalities we need. |
| 82 | 80 | #ifndef ImVector |
| r245117 | r245118 | |
| 117 | 115 | inline void swap(ImVector<T>& rhs) { const size_t rhs_size = rhs.Size; rhs.Size = Size; Size = rhs_size; const size_t rhs_cap = rhs.Capacity; rhs.Capacity = Capacity; Capacity = rhs_cap; value_type* rhs_data = rhs.Data; rhs.Data = Data; Data = rhs_data; } |
| 118 | 116 | |
| 119 | 117 | inline void resize(size_t new_size) { if (new_size > Capacity) reserve(new_size); Size = new_size; } |
| 120 | | inline void reserve(size_t new_capacity) |
| 121 | | { |
| 118 | inline void reserve(size_t new_capacity) |
| 119 | { |
| 122 | 120 | if (new_capacity <= Capacity) return; |
| 123 | 121 | T* new_data = (value_type*)ImGui::MemAlloc(new_capacity * sizeof(value_type)); |
| 124 | 122 | memcpy(new_data, Data, Size * sizeof(value_type)); |
| 125 | 123 | ImGui::MemFree(Data); |
| 126 | 124 | Data = new_data; |
| 127 | | Capacity = new_capacity; |
| 125 | Capacity = new_capacity; |
| 128 | 126 | } |
| 129 | 127 | |
| 130 | 128 | inline void push_back(const value_type& v) { if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); Data[Size++] = v; } |
| r245117 | r245118 | |
| 143 | 141 | // - struct ImDrawList // Draw command list |
| 144 | 142 | // - struct ImFont // TTF font loader, bake glyphs into bitmap |
| 145 | 143 | |
| 146 | | // ImGui end-user API |
| 144 | // ImGui End-user API |
| 147 | 145 | // In a namespace so that user can add extra functions (e.g. Value() helpers for your vector or common types) |
| 148 | 146 | namespace ImGui |
| 149 | 147 | { |
| r245117 | r245118 | |
| 158 | 156 | IMGUI_API void ShowTestWindow(bool* open = NULL); |
| 159 | 157 | |
| 160 | 158 | // Window |
| 161 | | // See implementation in .cpp for details |
| 162 | | IMGUI_API bool Begin(const char* name = "Debug", bool* p_opened = NULL, const ImVec2& initial_size = ImVec2(0,0), float bg_alpha = -1.0f, ImGuiWindowFlags flags = 0); // return false when window is collapsed, so you can early out in your code. passing 'bool* p_opened' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed. |
| 159 | IMGUI_API bool Begin(const char* name = "Debug", bool* p_opened = NULL, ImVec2 size = ImVec2(0,0), float fill_alpha = -1.0f, ImGuiWindowFlags flags = 0);// return false when window is collapsed, so you can early out in your code. passing 'bool* p_opened' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed. |
| 163 | 160 | IMGUI_API void End(); |
| 164 | | IMGUI_API bool BeginChild(const char* str_id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); // size==0.0f: use remaining window size, size<0.0f: use remaining window size minus abs(size). on each axis. |
| 165 | | IMGUI_API bool BeginChild(ImGuiID id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); // " |
| 161 | IMGUI_API void BeginChild(const char* str_id, ImVec2 size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); // size==0.0f: use remaining window size, size<0.0f: use remaining window size minus abs(size). on each axis. |
| 162 | IMGUI_API void BeginChild(ImGuiID id, ImVec2 size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); // " |
| 166 | 163 | IMGUI_API void EndChild(); |
| 167 | 164 | IMGUI_API bool GetWindowIsFocused(); |
| 168 | 165 | IMGUI_API ImVec2 GetContentRegionMax(); // window or current column boundaries, in windows coordinates |
| r245117 | r245118 | |
| 176 | 173 | IMGUI_API ImVec2 GetWindowSize(); // get current window position. |
| 177 | 174 | IMGUI_API float GetWindowWidth(); |
| 178 | 175 | IMGUI_API bool GetWindowCollapsed(); |
| 176 | IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCondition cond = 0); // set next window position - call before Begin(). |
| 177 | IMGUI_API void SetNextWindowSize(const ImVec2& size, ImGuiSetCondition cond = 0); // set next window size. set to ImVec2(0,0) to force an auto-fit. |
| 178 | IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiSetCondition cond = 0); // set next window collapsed state. |
| 179 | IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond = 0); // set current window position - call within Begin()/End(). may incur tearing. |
| 180 | IMGUI_API void SetWindowSize(const ImVec2& size, ImGuiSetCondition cond = 0); // set current window size. set to ImVec2(0,0) to force an auto-fit. may incur tearing. |
| 181 | IMGUI_API void SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond = 0); // set current window collapsed state. |
| 179 | 182 | |
| 180 | | IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0); // set next window position - call before Begin(). |
| 181 | | IMGUI_API void SetNextWindowSize(const ImVec2& size, ImGuiSetCond cond = 0); // set next window size. set to ImVec2(0,0) to force an auto-fit. |
| 182 | | IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiSetCond cond = 0); // set next window collapsed state. |
| 183 | | IMGUI_API void SetNextWindowFocus(); // set next window to be focused / front-most |
| 184 | | IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0); // set current window position - call within Begin()/End(). may incur tearing. |
| 185 | | IMGUI_API void SetWindowSize(const ImVec2& size, ImGuiSetCond cond = 0); // set current window size. set to ImVec2(0,0) to force an auto-fit. may incur tearing. |
| 186 | | IMGUI_API void SetWindowCollapsed(bool collapsed, ImGuiSetCond cond = 0); // set current window collapsed state. |
| 187 | | IMGUI_API void SetWindowFocus(); // set current window to be focused / front-most |
| 188 | | IMGUI_API void SetWindowPos(const char* name, const ImVec2& pos, ImGuiSetCond cond = 0); // set named window position - call within Begin()/End(). may incur tearing. |
| 189 | | IMGUI_API void SetWindowSize(const char* name, const ImVec2& size, ImGuiSetCond cond = 0); // set named window size. set to ImVec2(0,0) to force an auto-fit. may incur tearing. |
| 190 | | IMGUI_API void SetWindowCollapsed(const char* name, bool collapsed, ImGuiSetCond cond = 0); // set named window collapsed state. |
| 191 | | IMGUI_API void SetWindowFocus(const char* name); // set named window to be focused / front-most |
| 192 | | |
| 193 | | IMGUI_API float GetScrollPosY(); // get scrolling position (0..GetScrollMaxY()) |
| 194 | | IMGUI_API float GetScrollMaxY(); // get maximum scrolling position == ContentSize.Y - WindowSize.Y |
| 195 | 183 | IMGUI_API void SetScrollPosHere(); // adjust scrolling position to center into the current cursor position. |
| 196 | 184 | IMGUI_API void SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget. |
| 197 | 185 | IMGUI_API void SetStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it). |
| r245117 | r245118 | |
| 227 | 215 | IMGUI_API void Spacing(); |
| 228 | 216 | IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border=true); // setup number of columns |
| 229 | 217 | IMGUI_API void NextColumn(); // next column |
| 230 | | IMGUI_API int GetColumnIndex(); // get current column index |
| 231 | | IMGUI_API float GetColumnOffset(int column_index = -1); // get position of column line (in pixels, from the left side of the contents region). pass -1 to use current column, otherwise 0..GetcolumnsCount() inclusive. column 0 is usually 0.0f and not resizable unless you call this. |
| 232 | | IMGUI_API void SetColumnOffset(int column_index, float offset_x); // set position of column line (in pixels, from the left side of the contents region). pass -1 to use current column. |
| 233 | | IMGUI_API float GetColumnWidth(int column_index = -1); // column width (== GetColumnOffset(GetColumnIndex()+1) - GetColumnOffset(GetColumnOffset()) |
| 234 | | IMGUI_API int GetColumnsCount(); // number of columns (what was passed to Columns()) |
| 218 | IMGUI_API float GetColumnOffset(int column_index = -1); |
| 219 | IMGUI_API void SetColumnOffset(int column_index, float offset); |
| 220 | IMGUI_API float GetColumnWidth(int column_index = -1); |
| 235 | 221 | IMGUI_API ImVec2 GetCursorPos(); // cursor position is relative to window position |
| 236 | 222 | IMGUI_API float GetCursorPosX(); // " |
| 237 | 223 | IMGUI_API float GetCursorPosY(); // " |
| r245117 | r245118 | |
| 245 | 231 | IMGUI_API float GetTextLineHeightWithSpacing(); // spacing (in pixels) between 2 consecutive lines of text == GetWindowFontSize() + GetStyle().ItemSpacing.y |
| 246 | 232 | |
| 247 | 233 | // ID scopes |
| 248 | | // If you are creating widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them. |
| 249 | | // You can also use "##extra" within your widget name to distinguish them from each others (see 'Programmer Guide') |
| 234 | // If you are creating repeated widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them. |
| 235 | // You can also use ## within your widget name to distinguish them from each others (see 'Programmer Guide') |
| 250 | 236 | IMGUI_API void PushID(const char* str_id); // push identifier into the ID stack. IDs are hash of the *entire* stack! |
| 251 | 237 | IMGUI_API void PushID(const void* ptr_id); |
| 252 | 238 | IMGUI_API void PushID(const int int_id); |
| r245117 | r245118 | |
| 262 | 248 | IMGUI_API void TextWrapped(const char* fmt, ...); // shortcut for PushTextWrapPos(0.0f); Text(fmt, ...); PopTextWrapPos(); |
| 263 | 249 | IMGUI_API void TextWrappedV(const char* fmt, va_list args); |
| 264 | 250 | IMGUI_API void TextUnformatted(const char* text, const char* text_end = NULL); // doesn't require null terminated string if 'text_end' is specified. no copy done to any bounded stack buffer, recommended for long chunks of text. |
| 265 | | IMGUI_API void LabelText(const char* label, const char* fmt, ...); // display text+label aligned the same way as value+label widgets |
| 251 | IMGUI_API void LabelText(const char* label, const char* fmt, ...); // display text+label aligned the same way as value+label widgets |
| 266 | 252 | IMGUI_API void LabelTextV(const char* label, const char* fmt, va_list args); |
| 267 | | IMGUI_API void Bullet(); |
| 268 | 253 | IMGUI_API void BulletText(const char* fmt, ...); |
| 269 | 254 | IMGUI_API void BulletTextV(const char* fmt, va_list args); |
| 270 | 255 | IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0), bool repeat_when_held = false); |
| r245117 | r245118 | |
| 272 | 257 | IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size); |
| 273 | 258 | 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)); |
| 274 | 259 | 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,1), const ImVec4& tint_col = ImVec4(1,1,1,1)); // <0 frame_padding uses default frame padding settings. 0 for no paddnig. |
| 275 | | IMGUI_API bool CollapsingHeader(const char* label, const char* str_id = NULL, bool display_frame = true, bool default_open = false); |
| 260 | IMGUI_API bool CollapsingHeader(const char* label, const char* str_id = NULL, const bool display_frame = true, const bool default_open = false); |
| 276 | 261 | IMGUI_API bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); // adjust display_format to decorate the value with a prefix or a suffix. Use power!=1.0 for logarithmic sliders. |
| 277 | 262 | IMGUI_API bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); |
| 278 | 263 | IMGUI_API bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); |
| r245117 | r245118 | |
| 290 | 275 | IMGUI_API bool CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value); |
| 291 | 276 | IMGUI_API bool RadioButton(const char* label, bool active); |
| 292 | 277 | IMGUI_API bool RadioButton(const char* label, int* v, int v_button); |
| 293 | | IMGUI_API bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, ImGuiTextEditCallback callback = NULL, void* user_data = NULL); |
| 278 | IMGUI_API bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, void (*callback)(ImGuiTextEditCallbackData*) = NULL, void* user_data = NULL); |
| 294 | 279 | IMGUI_API bool InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, int decimal_precision = -1, ImGuiInputTextFlags extra_flags = 0); |
| 295 | 280 | IMGUI_API bool InputFloat2(const char* label, float v[2], int decimal_precision = -1); |
| 296 | 281 | IMGUI_API bool InputFloat3(const char* label, float v[3], int decimal_precision = -1); |
| r245117 | r245118 | |
| 303 | 288 | IMGUI_API bool ColorEdit3(const char* label, float col[3]); |
| 304 | 289 | IMGUI_API bool ColorEdit4(const char* label, float col[4], bool show_alpha = true); |
| 305 | 290 | IMGUI_API void ColorEditMode(ImGuiColorEditMode mode); |
| 306 | | |
| 307 | | // Trees |
| 308 | 291 | IMGUI_API bool TreeNode(const char* str_label_id); // if returning 'true' the node is open and the user is responsible for calling TreePop |
| 309 | 292 | IMGUI_API bool TreeNode(const char* str_id, const char* fmt, ...); // " |
| 310 | 293 | IMGUI_API bool TreeNode(const void* ptr_id, const char* fmt, ...); // " |
| r245117 | r245118 | |
| 313 | 296 | IMGUI_API void TreePush(const char* str_id = NULL); // already called by TreeNode(), but you can call Push/Pop yourself for layouting purpose |
| 314 | 297 | IMGUI_API void TreePush(const void* ptr_id = NULL); // " |
| 315 | 298 | IMGUI_API void TreePop(); |
| 316 | | IMGUI_API void SetNextTreeNodeOpened(bool opened, ImGuiSetCond cond = 0); // set next tree node to be opened. |
| 299 | IMGUI_API void OpenNextNode(bool open); // force open/close the next TreeNode or CollapsingHeader |
| 317 | 300 | |
| 318 | 301 | // Selectable / Lists |
| 319 | 302 | IMGUI_API bool Selectable(const char* label, bool selected, const ImVec2& size = ImVec2(0,0)); |
| r245117 | r245118 | |
| 343 | 326 | // Utilities |
| 344 | 327 | IMGUI_API bool IsItemHovered(); // was the last item hovered by mouse? |
| 345 | 328 | IMGUI_API bool IsItemActive(); // was the last item active? (e.g. button being held, text field being edited- items that don't interact will always return false) |
| 346 | | IMGUI_API bool IsAnyItemActive(); // |
| 347 | 329 | IMGUI_API ImVec2 GetItemBoxMin(); // get bounding box of last item |
| 348 | 330 | IMGUI_API ImVec2 GetItemBoxMax(); // get bounding box of last item |
| 349 | 331 | IMGUI_API bool IsClipped(const ImVec2& item_size); // to perform coarse clipping on user's side (as an optimization) |
| r245117 | r245118 | |
| 375 | 357 | |
| 376 | 358 | // Obsolete (will be removed) |
| 377 | 359 | IMGUI_API void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size); |
| 378 | | static inline void OpenNextNode(bool open) { ImGui::SetNextTreeNodeOpened(open, 0); } |
| 379 | 360 | |
| 380 | 361 | } // namespace ImGui |
| 381 | 362 | |
| r245117 | r245118 | |
| 386 | 367 | ImGuiWindowFlags_NoTitleBar = 1 << 0, // Disable title-bar |
| 387 | 368 | ImGuiWindowFlags_NoResize = 1 << 1, // Disable user resizing with the lower-right grip |
| 388 | 369 | ImGuiWindowFlags_NoMove = 1 << 2, // Disable user moving the window |
| 389 | | ImGuiWindowFlags_NoScrollbar = 1 << 3, // Disable scrollbar (window can still scroll with mouse or programatically) |
| 370 | ImGuiWindowFlags_NoScrollbar = 1 << 3, // Disable scroll bar (window can still scroll with mouse or programatically) |
| 390 | 371 | ImGuiWindowFlags_NoScrollWithMouse = 1 << 4, // Disable user scrolling with mouse wheel |
| 391 | 372 | ImGuiWindowFlags_NoCollapse = 1 << 5, // Disable user collapsing window by double-clicking on it |
| 392 | 373 | ImGuiWindowFlags_AlwaysAutoResize = 1 << 6, // Resize every window to its content every frame |
| r245117 | r245118 | |
| 406 | 387 | // Default: 0 |
| 407 | 388 | ImGuiInputTextFlags_CharsDecimal = 1 << 0, // Allow 0123456789.+-*/ |
| 408 | 389 | ImGuiInputTextFlags_CharsHexadecimal = 1 << 1, // Allow 0123456789ABCDEFabcdef |
| 409 | | ImGuiInputTextFlags_CharsUppercase = 1 << 2, // Turn a..z into A..Z |
| 410 | | ImGuiInputTextFlags_CharsNoBlank = 1 << 3, // Filter out spaces, tabs |
| 411 | | ImGuiInputTextFlags_AutoSelectAll = 1 << 4, // Select entire text when first taking mouse focus |
| 412 | | ImGuiInputTextFlags_EnterReturnsTrue = 1 << 5, // Return 'true' when Enter is pressed (as opposed to when the value was modified) |
| 413 | | ImGuiInputTextFlags_CallbackCompletion = 1 << 6, // Call user function on pressing TAB (for completion handling) |
| 414 | | ImGuiInputTextFlags_CallbackHistory = 1 << 7, // Call user function on pressing Up/Down arrows (for history handling) |
| 415 | | ImGuiInputTextFlags_CallbackAlways = 1 << 8, // Call user function every time |
| 416 | | ImGuiInputTextFlags_CallbackCharFilter = 1 << 9 // Call user function to filter character. Modify data->EventChar to replace/filter input, or return 1 to discard character. |
| 390 | ImGuiInputTextFlags_AutoSelectAll = 1 << 2, // Select entire text when first taking focus |
| 391 | ImGuiInputTextFlags_EnterReturnsTrue = 1 << 3, // Return 'true' when Enter is pressed (as opposed to when the value was modified) |
| 392 | ImGuiInputTextFlags_CallbackCompletion = 1 << 4, // Call user function on pressing TAB (for completion handling) |
| 393 | ImGuiInputTextFlags_CallbackHistory = 1 << 5, // Call user function on pressing Up/Down arrows (for history handling) |
| 394 | ImGuiInputTextFlags_CallbackAlways = 1 << 6 // Call user function every time |
| 395 | //ImGuiInputTextFlags_AlignCenter = 1 << 6, |
| 417 | 396 | }; |
| 418 | 397 | |
| 419 | 398 | // User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array |
| r245117 | r245118 | |
| 509 | 488 | ImGuiColorEditMode_HEX = 2 |
| 510 | 489 | }; |
| 511 | 490 | |
| 512 | | // Condition flags for ImGui::SetWindow***(), SetNextWindow***(), SetNextTreeNode***() functions |
| 513 | | // All those functions treat 0 as a shortcut to ImGuiSetCond_Always |
| 514 | | enum ImGuiSetCond_ |
| 491 | // Condition flags for ImGui::SetWindow***() and SetNextWindow***() functions |
| 492 | // Those functions treat 0 as a shortcut to ImGuiSetCondition_Always |
| 493 | enum ImGuiSetCondition_ |
| 515 | 494 | { |
| 516 | | ImGuiSetCond_Always = 1 << 0, // Set the variable |
| 517 | | ImGuiSetCond_Once = 1 << 1, // Only set the variable on the first call per runtime session |
| 518 | | ImGuiSetCond_FirstUseEver = 1 << 2 // Only set the variable if the window doesn't exist in the .ini file |
| 495 | ImGuiSetCondition_Always = 1 << 0, // Set the variable |
| 496 | ImGuiSetCondition_FirstUseThisSession = 1 << 1, // Only set the variable on the first call for this window (once per session) |
| 497 | ImGuiSetCondition_FirstUseEver = 1 << 2 // Only set the variable if the window doesn't exist in the .ini file |
| 519 | 498 | }; |
| 520 | 499 | |
| 521 | 500 | struct ImGuiStyle |
| r245117 | r245118 | |
| 534 | 513 | float WindowFillAlphaDefault; // Default alpha of window background, if not specified in ImGui::Begin() |
| 535 | 514 | float TreeNodeSpacing; // Horizontal spacing when entering a tree node |
| 536 | 515 | float ColumnsMinSpacing; // Minimum horizontal spacing between two columns |
| 537 | | float ScrollbarWidth; // Width of the vertical scrollbar |
| 538 | | float GrabMinSize; // Minimum width/height of a slider or scrollbar grab |
| 516 | float ScrollBarWidth; // Width of the vertical scroll bar |
| 539 | 517 | ImVec4 Colors[ImGuiCol_COUNT]; |
| 540 | 518 | |
| 541 | 519 | IMGUI_API ImGuiStyle(); |
| r245117 | r245118 | |
| 551 | 529 | |
| 552 | 530 | ImVec2 DisplaySize; // <unset> // Display size, in pixels. For clamping windows positions. |
| 553 | 531 | float DeltaTime; // = 1.0f/60.0f // Time elapsed since last frame, in seconds. |
| 554 | | float IniSavingRate; // = 5.0f // Maximum time between saving positions/sizes to .ini file, in seconds. |
| 532 | float IniSavingRate; // = 5.0f // Maximum time between saving .ini file, in seconds. |
| 555 | 533 | const char* IniFilename; // = "imgui.ini" // Path to .ini file. NULL to disable .ini saving. |
| 556 | 534 | const char* LogFilename; // = "imgui_log.txt" // Path to .log file (default parameter to ImGui::LogToFile when no file is specified). |
| 557 | 535 | float MouseDoubleClickTime; // = 0.30f // Time for a double-click, in seconds. |
| r245117 | r245118 | |
| 569 | 547 | // User Functions |
| 570 | 548 | //------------------------------------------------------------------ |
| 571 | 549 | |
| 572 | | // REQUIRED: rendering function. |
| 550 | // REQUIRED: rendering function. |
| 573 | 551 | // See example code if you are unsure of how to implement this. |
| 574 | | void (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count); |
| 552 | void (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count); |
| 575 | 553 | |
| 576 | | // Optional: access OS clipboard |
| 577 | | // (default to use native Win32 clipboard on Windows, otherwise uses a private clipboard. Override to access OS clipboard on other architectures) |
| 554 | // Optional: access OS clipboard (default to use native Win32 clipboard on Windows, otherwise use a ImGui private clipboard) |
| 555 | // Override to access OS clipboard on other architectures. |
| 578 | 556 | const char* (*GetClipboardTextFn)(); |
| 579 | 557 | void (*SetClipboardTextFn)(const char* text); |
| 580 | 558 | |
| 581 | | // Optional: override memory allocations. MemFreeFn() may be called with a NULL pointer. |
| 582 | | // (default to posix malloc/free) |
| 559 | // Optional: override memory allocations (default to posix malloc/free). MemFreeFn() may be called with a NULL pointer. |
| 583 | 560 | void* (*MemAllocFn)(size_t sz); |
| 584 | 561 | void (*MemFreeFn)(void* ptr); |
| 585 | 562 | |
| 586 | | // Optional: notify OS Input Method Editor of the screen position of your cursor for text input position (e.g. when using Japanese/Chinese IME in Windows) |
| 587 | | // (default to use native imm32 api on Windows) |
| 563 | // Optional: notify OS Input Method Editor of the screen position of your cursor for text input position (e.g. when using Japanese/Chinese inputs in Windows) |
| 588 | 564 | void (*ImeSetInputScreenPosFn)(int x, int y); |
| 589 | | void* ImeWindowHandle; // (Windows) Set this to your HWND to get automatic IME cursor positioning. |
| 590 | 565 | |
| 591 | 566 | //------------------------------------------------------------------ |
| 592 | 567 | // Input - Fill before calling NewFrame() |
| 593 | 568 | //------------------------------------------------------------------ |
| 594 | 569 | |
| 595 | 570 | ImVec2 MousePos; // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) |
| 596 | | bool MouseDown[5]; // Mouse buttons. ImGui itself only uses button 0 (left button). Others buttons allows to track if mouse is being used by your application + available to user as a convenience via IsMouse** API. |
| 597 | | float MouseWheel; // Mouse wheel: 1 unit scrolls about 5 lines text. |
| 571 | bool MouseDown[5]; // Mouse buttons. ImGui itself only uses button 0 (left button) but you can use others as storage for convenience. |
| 572 | float MouseWheel; // Mouse wheel: 1 unit scrolls about 5 lines text. |
| 598 | 573 | bool MouseDrawCursor; // Request ImGui to draw a mouse cursor for you (if you are on a platform without a mouse cursor). |
| 599 | 574 | bool KeyCtrl; // Keyboard modifier pressed: Control |
| 600 | 575 | bool KeyShift; // Keyboard modifier pressed: Shift |
| 601 | | bool KeysDown[512]; // Keyboard keys that are pressed (in whatever storage order you naturally have access to keyboard data) |
| 576 | bool KeysDown[512]; // Keyboard keys that are pressed (in whatever order user naturally has access to keyboard data) |
| 602 | 577 | ImWchar InputCharacters[16+1]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper. |
| 603 | 578 | |
| 604 | 579 | // Function |
| r245117 | r245118 | |
| 610 | 585 | |
| 611 | 586 | bool WantCaptureMouse; // Mouse is hovering a window or widget is active (= ImGui will use your mouse input) |
| 612 | 587 | bool WantCaptureKeyboard; // Widget is active (= ImGui will use your keyboard input) |
| 613 | | float Framerate; // Framerate estimation, in frame per second. Rolling average estimation based on IO.DeltaTime over 120 frames |
| 614 | 588 | |
| 615 | 589 | //------------------------------------------------------------------ |
| 616 | 590 | // [Internal] ImGui will maintain those fields for you |
| 617 | 591 | //------------------------------------------------------------------ |
| 618 | 592 | |
| 619 | | ImVec2 MousePosPrev; // Previous mouse position |
| 593 | ImVec2 MousePosPrev; // |
| 620 | 594 | ImVec2 MouseDelta; // Mouse delta. Note that this is zero if either current or previous position are negative to allow mouse enabling/disabling. |
| 621 | 595 | bool MouseClicked[5]; // Mouse button went from !Down to Down |
| 622 | 596 | ImVec2 MouseClickedPos[5]; // Position at time of clicking |
| r245117 | r245118 | |
| 672 | 646 | ImVector<TextRange> Filters; |
| 673 | 647 | int CountGrep; |
| 674 | 648 | |
| 675 | | ImGuiTextFilter(const char* default_filter = ""); |
| 649 | ImGuiTextFilter(); |
| 676 | 650 | void Clear() { InputBuf[0] = 0; Build(); } |
| 677 | 651 | void Draw(const char* label = "Filter (inc,-exc)", float width = -1.0f); // Helper calling InputText+Build |
| 678 | 652 | bool PassFilter(const char* val) const; |
| r245117 | r245118 | |
| 706 | 680 | // - You want to store custom debug data easily without adding or editing structures in your code. |
| 707 | 681 | struct ImGuiStorage |
| 708 | 682 | { |
| 709 | | struct Pair |
| 710 | | { |
| 711 | | ImGuiID key; |
| 712 | | union { int val_i; float val_f; void* val_p; }; |
| 713 | | Pair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; } |
| 714 | | Pair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; } |
| 715 | | Pair(ImGuiID _key, void* _val_p) { key = _key; val_p = _val_p; } |
| 683 | struct Pair |
| 684 | { |
| 685 | ImGuiID key; |
| 686 | union { int val_i; float val_f; void* val_p; }; |
| 687 | Pair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; } |
| 688 | Pair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; } |
| 689 | Pair(ImGuiID _key, void* _val_p) { key = _key; val_p = _val_p; } |
| 716 | 690 | }; |
| 717 | 691 | ImVector<Pair> Data; |
| 718 | 692 | |
| r245117 | r245118 | |
| 727 | 701 | IMGUI_API void* GetVoidPtr(ImGuiID key) const; // default_val is NULL |
| 728 | 702 | IMGUI_API void SetVoidPtr(ImGuiID key, void* val); |
| 729 | 703 | |
| 730 | | // - Get***Ref() functions finds pair, insert on demand if missing, return pointer. Useful if you intend to do Get+Set. |
| 704 | // - Get***Ref() functions finds pair, insert on demand if missing, return pointer. Useful if you intend to do Get+Set. |
| 731 | 705 | // - References are only valid until a new value is added to the storage. Calling a Set***() function or a Get***Ref() function invalidates the pointer. |
| 732 | 706 | // - A typical use case where this is convenient: |
| 733 | 707 | // float* pvar = ImGui::GetFloatRef(key); ImGui::SliderFloat("var", pvar, 0, 100.0f); some_var += *pvar; |
| r245117 | r245118 | |
| 742 | 716 | // Shared state of InputText(), passed to callback when a ImGuiInputTextFlags_Callback* flag is used. |
| 743 | 717 | struct ImGuiTextEditCallbackData |
| 744 | 718 | { |
| 745 | | ImGuiInputTextFlags EventFlag; // One of ImGuiInputTextFlags_Callback* // Read-only |
| 746 | | ImGuiInputTextFlags Flags; // What user passed to InputText() // Read-only |
| 747 | | void* UserData; // What user passed to InputText() // Read-only |
| 719 | ImGuiKey EventKey; // Key pressed (Up/Down/TAB) // Read-only |
| 720 | char* Buf; // Current text // Read-write (pointed data only) |
| 721 | size_t BufSize; // // Read-only |
| 722 | bool BufDirty; // Set if you modify Buf directly // Write |
| 723 | ImGuiInputTextFlags Flags; // What user passed to InputText() // Read-only |
| 724 | int CursorPos; // // Read-write |
| 725 | int SelectionStart; // // Read-write (== to SelectionEnd when no selection) |
| 726 | int SelectionEnd; // // Read-write |
| 727 | void* UserData; // What user passed to InputText() |
| 748 | 728 | |
| 749 | | // CharFilter event: |
| 750 | | ImWchar EventChar; // Character input // Read-write (replace character or set to zero) |
| 751 | | |
| 752 | | // Completion,History,Always events: |
| 753 | | ImGuiKey EventKey; // Key pressed (Up/Down/TAB) // Read-only |
| 754 | | char* Buf; // Current text // Read-write (pointed data only) |
| 755 | | size_t BufSize; // // Read-only |
| 756 | | bool BufDirty; // Set if you modify Buf directly // Write |
| 757 | | int CursorPos; // // Read-write |
| 758 | | int SelectionStart; // // Read-write (== to SelectionEnd when no selection) |
| 759 | | int SelectionEnd; // // Read-write |
| 760 | | |
| 761 | 729 | // NB: calling those function loses selection. |
| 762 | 730 | void DeleteChars(int pos, int bytes_count); |
| 763 | 731 | void InsertChars(int pos, const char* text, const char* text_end = NULL); |
| r245117 | r245118 | |
| 772 | 740 | ImColor(int r, int g, int b, int a = 255) { Value.x = (float)r / 255.0f; Value.y = (float)g / 255.0f; Value.z = (float)b / 255.0f; Value.w = (float)a / 255.0f; } |
| 773 | 741 | ImColor(float r, float g, float b, float a = 1.0f) { Value.x = r; Value.y = g; Value.z = b; Value.w = a; } |
| 774 | 742 | ImColor(const ImVec4& col) { Value = col; } |
| 743 | |
| 775 | 744 | operator ImU32() const { return ImGui::ColorConvertFloat4ToU32(Value); } |
| 776 | 745 | operator ImVec4() const { return Value; } |
| 777 | 746 | |
| r245117 | r245118 | |
| 794 | 763 | // It is up to you to decide if your rendering loop or the callback should be responsible for backup/restoring rendering state. |
| 795 | 764 | typedef void (*ImDrawCallback)(const ImDrawList* parent_list, const ImDrawCmd* cmd); |
| 796 | 765 | |
| 797 | | // Typically, 1 command = 1 gpu draw call (unless command is a callback) |
| 766 | // Typically, 1 command = 1 gpu draw call |
| 798 | 767 | struct ImDrawCmd |
| 799 | 768 | { |
| 800 | 769 | unsigned int vtx_count; // Number of vertices (multiple of 3) to be drawn as triangles. The vertices are stored in the callee ImDrawList's vtx_buffer[] array. |
| r245117 | r245118 | |
| 833 | 802 | |
| 834 | 803 | // [Internal to ImGui] |
| 835 | 804 | ImVector<ImVec4> clip_rect_stack; // [Internal] |
| 836 | | ImVector<ImTextureID> texture_id_stack; // [Internal] |
| 805 | ImVector<ImTextureID> texture_id_stack; // [Internal] |
| 837 | 806 | ImDrawVert* vtx_write; // [Internal] point within vtx_buffer after each add command (to avoid using the ImVector<> operators too much) |
| 838 | 807 | |
| 839 | 808 | ImDrawList() { Clear(); } |
| r245117 | r245118 | |
| 843 | 812 | IMGUI_API void PushTextureID(const ImTextureID& texture_id); |
| 844 | 813 | IMGUI_API void PopTextureID(); |
| 845 | 814 | |
| 846 | | // Primitives |
| 815 | // Primitives |
| 847 | 816 | IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col); |
| 848 | 817 | IMGUI_API void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F); |
| 849 | 818 | IMGUI_API void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F); |
| r245117 | r245118 | |
| 928 | 897 | float FontSize; // <user set> // Height of characters, set during loading (don't change after loading) |
| 929 | 898 | float Scale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale() |
| 930 | 899 | ImVec2 DisplayOffset; // = (0.0f,0.0f) // Offset font rendering by xx pixels |
| 931 | | ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar() |
| 900 | ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. |
| 932 | 901 | |
| 933 | 902 | // Members: Runtime data |
| 934 | 903 | struct Glyph |
| r245117 | r245118 | |
| 941 | 910 | }; |
| 942 | 911 | ImFontAtlas* ContainerAtlas; // What we has been loaded into |
| 943 | 912 | ImVector<Glyph> Glyphs; |
| 944 | | const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar) |
| 945 | | float FallbackXAdvance; // |
| 946 | | ImVector<float> IndexXAdvance; // Glyphs->XAdvance directly indexable (for CalcTextSize functions which are often bottleneck in large UI) |
| 947 | 913 | ImVector<int> IndexLookup; // Index glyphs by Unicode code-point |
| 914 | const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar) |
| 948 | 915 | |
| 949 | 916 | // Methods |
| 950 | 917 | IMGUI_API ImFont(); |
| r245117 | r245118 | |
| 952 | 919 | IMGUI_API void Clear(); |
| 953 | 920 | IMGUI_API void BuildLookupTable(); |
| 954 | 921 | IMGUI_API const Glyph* FindGlyph(unsigned short c) const; |
| 955 | | IMGUI_API void SetFallbackChar(ImWchar c); |
| 956 | 922 | IMGUI_API bool IsLoaded() const { return ContainerAtlas != NULL; } |
| 957 | 923 | |
| 958 | 924 | // 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable. |
trunk/3rdparty/bgfx/examples/common/imgui/fs_imgui_latlong.bin.h
| r245117 | r245118 | |
| 1 | | static const uint8_t fs_imgui_latlong_glsl[649] = |
| 1 | static const uint8_t fs_imgui_latlong_glsl[646] = |
| 2 | 2 | { |
| 3 | 3 | 0x46, 0x53, 0x48, 0x03, 0x6f, 0x1e, 0x3e, 0x3c, 0x02, 0x00, 0x11, 0x75, 0x5f, 0x69, 0x6d, 0x61, // FSH.o.><...u_ima |
| 4 | 4 | 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x07, 0x01, 0x00, 0x00, // geLodEnabled.... |
| 5 | 5 | 0x01, 0x00, 0x0a, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x01, 0x00, // ...s_texColor... |
| 6 | | 0x00, 0x01, 0x00, 0x51, 0x02, 0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, // ...Q...varying h |
| 6 | 0x00, 0x01, 0x00, 0x4e, 0x02, 0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, // ...N...varying h |
| 7 | 7 | 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, // ighp vec2 v_texc |
| 8 | 8 | 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x68, // oord0;.uniform h |
| 9 | 9 | 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, // ighp vec4 u_imag |
| r245117 | r245118 | |
| 21 | 21 | 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x20, 0x3d, 0x20, 0x28, 0x76, 0x5f, // tmpvar_3 = (v_ |
| 22 | 22 | 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x2e, 0x79, 0x20, 0x2a, 0x20, 0x33, 0x2e, // texcoord0.y * 3. |
| 23 | 23 | 0x31, 0x34, 0x31, 0x35, 0x39, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, // 14159);. result |
| 24 | | 0x5f, 0x31, 0x2e, 0x78, 0x20, 0x3d, 0x20, 0x28, 0x2d, 0x28, 0x73, 0x69, 0x6e, 0x28, 0x74, 0x6d, // _1.x = (-(sin(tm |
| 25 | | 0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x29, 0x29, 0x20, 0x2a, 0x20, 0x73, 0x69, 0x6e, 0x28, 0x74, // pvar_3)) * sin(t |
| 26 | | 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x73, // mpvar_2));. res |
| 27 | | 0x75, 0x6c, 0x74, 0x5f, 0x31, 0x2e, 0x79, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x73, 0x28, 0x74, 0x6d, // ult_1.y = cos(tm |
| 28 | | 0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, // pvar_3);. resul |
| 29 | | 0x74, 0x5f, 0x31, 0x2e, 0x7a, 0x20, 0x3d, 0x20, 0x28, 0x2d, 0x28, 0x73, 0x69, 0x6e, 0x28, 0x74, // t_1.z = (-(sin(t |
| 30 | | 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x29, 0x29, 0x20, 0x2a, 0x20, 0x63, 0x6f, 0x73, 0x28, // mpvar_3)) * cos( |
| 31 | | 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x6c, 0x6f, // tmpvar_2));. lo |
| 32 | | 0x77, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, // wp vec4 tmpvar_4 |
| 33 | | 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, 0x2e, 0x78, 0x79, 0x7a, // ;. tmpvar_4.xyz |
| 34 | | 0x20, 0x3d, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x43, 0x75, 0x62, 0x65, 0x4c, 0x6f, // = textureCubeLo |
| 35 | | 0x64, 0x20, 0x20, 0x20, 0x20, 0x28, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, // d (s_texColor |
| 36 | | 0x2c, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x5f, 0x31, 0x2c, 0x20, 0x75, 0x5f, 0x69, 0x6d, // , result_1, u_im |
| 37 | | 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x2e, 0x78, 0x29, // ageLodEnabled.x) |
| 38 | | 0x2e, 0x78, 0x79, 0x7a, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, // .xyz;. tmpvar_4 |
| 39 | | 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x28, 0x30, 0x2e, 0x32, 0x20, 0x2b, 0x20, 0x28, 0x30, 0x2e, 0x38, // .w = (0.2 + (0.8 |
| 40 | | 0x20, 0x2a, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, // * u_imageLodEna |
| 41 | | 0x62, 0x6c, 0x65, 0x64, 0x2e, 0x79, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, // bled.y));. gl_F |
| 42 | | 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, // ragColor = tmpva |
| 43 | | 0x72, 0x5f, 0x34, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // r_4;.}... |
| 24 | 0x5f, 0x31, 0x2e, 0x78, 0x20, 0x3d, 0x20, 0x28, 0x73, 0x69, 0x6e, 0x28, 0x74, 0x6d, 0x70, 0x76, // _1.x = (sin(tmpv |
| 25 | 0x61, 0x72, 0x5f, 0x33, 0x29, 0x20, 0x2a, 0x20, 0x63, 0x6f, 0x73, 0x28, 0x74, 0x6d, 0x70, 0x76, // ar_3) * cos(tmpv |
| 26 | 0x61, 0x72, 0x5f, 0x32, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, // ar_2));. result |
| 27 | 0x5f, 0x31, 0x2e, 0x79, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x73, 0x28, 0x74, 0x6d, 0x70, 0x76, 0x61, // _1.y = cos(tmpva |
| 28 | 0x72, 0x5f, 0x33, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x5f, 0x31, // r_3);. result_1 |
| 29 | 0x2e, 0x7a, 0x20, 0x3d, 0x20, 0x28, 0x2d, 0x28, 0x73, 0x69, 0x6e, 0x28, 0x74, 0x6d, 0x70, 0x76, // .z = (-(sin(tmpv |
| 30 | 0x61, 0x72, 0x5f, 0x33, 0x29, 0x29, 0x20, 0x2a, 0x20, 0x73, 0x69, 0x6e, 0x28, 0x74, 0x6d, 0x70, // ar_3)) * sin(tmp |
| 31 | 0x76, 0x61, 0x72, 0x5f, 0x32, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x77, 0x70, 0x20, // var_2));. lowp |
| 32 | 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, 0x3b, 0x0a, 0x20, // vec4 tmpvar_4;. |
| 33 | 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, // tmpvar_4.xyz = |
| 34 | 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x43, 0x75, 0x62, 0x65, 0x4c, 0x6f, 0x64, 0x20, 0x20, // textureCubeLod |
| 35 | 0x20, 0x20, 0x28, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x72, // (s_texColor, r |
| 36 | 0x65, 0x73, 0x75, 0x6c, 0x74, 0x5f, 0x31, 0x2c, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, // esult_1, u_image |
| 37 | 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x2e, 0x78, 0x29, 0x2e, 0x78, 0x79, // LodEnabled.x).xy |
| 38 | 0x7a, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, 0x2e, 0x77, 0x20, // z;. tmpvar_4.w |
| 39 | 0x3d, 0x20, 0x28, 0x30, 0x2e, 0x32, 0x20, 0x2b, 0x20, 0x28, 0x30, 0x2e, 0x38, 0x20, 0x2a, 0x20, // = (0.2 + (0.8 * |
| 40 | 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, // u_imageLodEnable |
| 41 | 0x64, 0x2e, 0x79, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, // d.y));. gl_Frag |
| 42 | 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, // Color = tmpvar_4 |
| 43 | 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // ;.}... |
| 44 | 44 | }; |
| 45 | | static const uint8_t fs_imgui_latlong_dx9[537] = |
| 45 | static const uint8_t fs_imgui_latlong_dx9[553] = |
| 46 | 46 | { |
| 47 | 47 | 0x46, 0x53, 0x48, 0x03, 0x6f, 0x1e, 0x3e, 0x3c, 0x01, 0x00, 0x11, 0x75, 0x5f, 0x69, 0x6d, 0x61, // FSH.o.><...u_ima |
| 48 | 48 | 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x15, 0x01, 0x00, 0x00, // geLodEnabled.... |
| 49 | | 0x01, 0x00, 0xf4, 0x01, 0x00, 0x03, 0xff, 0xff, 0xfe, 0xff, 0x30, 0x00, 0x43, 0x54, 0x41, 0x42, // ..........0.CTAB |
| 49 | 0x01, 0x00, 0x04, 0x02, 0x00, 0x03, 0xff, 0xff, 0xfe, 0xff, 0x30, 0x00, 0x43, 0x54, 0x41, 0x42, // ..........0.CTAB |
| 50 | 50 | 0x1c, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, // ................ |
| 51 | 51 | 0x1c, 0x00, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, // ............D... |
| 52 | 52 | 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........P....... |
| r245117 | r245118 | |
| 71 | 71 | 0x01, 0x00, 0x00, 0xa0, 0x13, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x80, // ................ |
| 72 | 72 | 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x55, 0xa0, // ..............U. |
| 73 | 73 | 0x01, 0x00, 0xaa, 0xa0, 0x25, 0x00, 0x00, 0x02, 0x02, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x80, // ....%........... |
| 74 | | 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x05, 0x80, 0x01, 0x00, 0xc5, 0x80, 0x02, 0x00, 0x55, 0x81, // ..............U. |
| 74 | 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01, 0x80, 0x01, 0x00, 0x00, 0x80, 0x02, 0x00, 0x55, 0x80, // ..............U. |
| 75 | 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x04, 0x80, 0x01, 0x00, 0x55, 0x80, 0x02, 0x00, 0x55, 0x81, // ..........U...U. |
| 75 | 76 | 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x02, 0x80, 0x02, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x02, // ................ |
| 76 | 77 | 0x00, 0x00, 0x08, 0x80, 0x00, 0x00, 0x00, 0xa0, 0x5f, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0x80, // ........_....... |
| 77 | 78 | 0x00, 0x00, 0xe4, 0x80, 0x00, 0x08, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x07, 0x80, // ................ |
| r245117 | r245118 | |
| 83 | 84 | { |
| 84 | 85 | 0x46, 0x53, 0x48, 0x03, 0x6f, 0x1e, 0x3e, 0x3c, 0x01, 0x00, 0x11, 0x75, 0x5f, 0x69, 0x6d, 0x61, // FSH.o.><...u_ima |
| 85 | 86 | 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x15, 0x00, 0x30, 0x0a, // geLodEnabled..0. |
| 86 | | 0x01, 0x00, 0x30, 0x02, 0x44, 0x58, 0x42, 0x43, 0xbb, 0x3e, 0xd7, 0x3a, 0x63, 0xc9, 0x70, 0x0b, // ..0.DXBC.>.:c.p. |
| 87 | | 0xa5, 0x2c, 0x7d, 0xb2, 0x3c, 0x0c, 0x75, 0x44, 0x01, 0x00, 0x00, 0x00, 0x30, 0x02, 0x00, 0x00, // .,}.<.uD....0... |
| 87 | 0x01, 0x00, 0x30, 0x02, 0x44, 0x58, 0x42, 0x43, 0x89, 0x11, 0x25, 0xa6, 0xf5, 0x66, 0x12, 0x3f, // ..0.DXBC..%..f.? |
| 88 | 0xc0, 0x1f, 0x67, 0x9b, 0x6e, 0x4e, 0xac, 0x03, 0x01, 0x00, 0x00, 0x00, 0x30, 0x02, 0x00, 0x00, // ..g.nN......0... |
| 88 | 89 | 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, // ....,........... |
| 89 | 90 | 0x49, 0x53, 0x47, 0x4e, 0x50, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, // ISGNP........... |
| 90 | 91 | 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // 8............... |
| r245117 | r245118 | |
| 100 | 101 | 0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x30, 0x00, 0x04, 0x00, 0x70, 0x10, 0x00, // .`......X0...p.. |
| 101 | 102 | 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x62, 0x10, 0x00, 0x03, 0x32, 0x10, 0x10, 0x00, // ....UU..b...2... |
| 102 | 103 | 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ....e.... ...... |
| 103 | | 0x68, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x0a, 0x32, 0x00, 0x10, 0x00, // h.......8...2... |
| 104 | | 0x00, 0x00, 0x00, 0x00, 0x16, 0x15, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, // .............@.. |
| 105 | | 0xdb, 0x0f, 0x49, 0x40, 0xdb, 0x0f, 0xc9, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ..I@...@........ |
| 106 | | 0x4d, 0x00, 0x00, 0x06, 0x42, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, // M...B........... |
| 107 | | 0x1a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, 0x07, 0x82, 0x00, 0x10, 0x00, // ........M....... |
| 108 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x80, 0x41, 0x00, 0x00, 0x00, // ............A... |
| 104 | 0x68, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x0a, 0x32, 0x00, 0x10, 0x00, // h.......8...2... |
| 105 | 0x00, 0x00, 0x00, 0x00, 0x46, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, // ....F........@.. |
| 106 | 0xdb, 0x0f, 0xc9, 0x40, 0xdb, 0x0f, 0x49, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ...@..I@........ |
| 107 | 0x4d, 0x00, 0x00, 0x07, 0x42, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, // M...B........... |
| 108 | 0x1a, 0x00, 0x10, 0x80, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, 0x06, // ....A.......M... |
| 109 | 0x32, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x16, 0x05, 0x10, 0x00, // 2............... |
| 109 | 110 | 0x00, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, 0x06, 0x00, 0xd0, 0x00, 0x00, 0x62, 0x00, 0x10, 0x00, // ....M.......b... |
| 110 | | 0x01, 0x00, 0x00, 0x00, 0x06, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x07, // ............8... |
| 111 | | 0x12, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ........*....... |
| 112 | | 0x3a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x07, 0x82, 0x00, 0x10, 0x00, // :.......8....... |
| 113 | | 0x01, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x10, 0x00, // ....:.......*... |
| 114 | | 0x01, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x0c, 0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ....H........... |
| 115 | | 0x46, 0x03, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x7e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // F.......F~...... |
| 111 | 0x02, 0x00, 0x00, 0x00, 0x06, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x07, // ............8... |
| 112 | 0x82, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ........*....... |
| 113 | 0x1a, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x07, 0x12, 0x00, 0x10, 0x00, // ........8....... |
| 114 | 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x10, 0x00, // ................ |
| 115 | 0x02, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x0c, 0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ....H........... |
| 116 | 0x86, 0x03, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x7e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ........F~...... |
| 116 | 117 | 0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x80, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, // .`........ ..... |
| 117 | 118 | 0xa3, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, 0x72, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ....6...r ...... |
| 118 | 119 | 0x46, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0a, 0x82, 0x20, 0x10, 0x00, // F.......2.... .. |