2015-02-22 00:39:21 +08:00
// ImGui library v1.33 wip
2014-08-11 04:58:11 +08:00
// See ImGui::ShowTestWindow() for sample code.
// Read 'Programmer guide' below for notes on how to setup ImGui in your codebase.
// Get latest version at https://github.com/ocornut/imgui
2014-10-25 18:00:24 +08:00
// Developed by Omar Cornut and contributors.
2014-08-11 04:58:11 +08:00
/*
2014-11-10 09:29:01 +08:00
Index
- MISSION STATEMENT
- END - USER GUIDE
- PROGRAMMER GUIDE
- API BREAKING CHANGES
2014-11-27 06:27:48 +08:00
- TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS
2014-11-10 09:29:01 +08:00
- ISSUES & TODO - LIST
- CODE
- SAMPLE CODE
- FONT DATA
2014-08-11 04:58:11 +08:00
MISSION STATEMENT
2014-09-24 21:06:34 +08:00
= = = = = = = = = = = = = = = = =
2014-08-11 04:58:11 +08:00
- easy to use to create code - driven and data - driven tools
2014-10-25 18:00:24 +08:00
- easy to use to create ad hoc short - lived tools and long - lived , more elaborate tools
2014-08-11 04:58:11 +08:00
- easy to hack and improve
- minimize screen real - estate usage
2014-11-10 09:29:01 +08:00
- minimize setup and maintenance
2014-08-11 04:58:11 +08:00
- minimize state storage on user side
- portable , minimize dependencies , run on target ( consoles , etc . )
2014-10-25 18:00:24 +08:00
- 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 )
2014-08-11 04:58:11 +08:00
- read about immediate - mode GUI principles @ http : //mollyrocket.com/861, http://mollyrocket.com/forums/index.html
Designed for developers and content - creators , not the typical end - user ! Some of the weaknesses includes :
- doesn ' t look fancy , doesn ' t animate
- limited layout features , intricate layouts are typically crafted in code
- occasionally use statically sized buffers for string manipulations - won ' t crash , but some long text may be clipped
2014-12-04 19:42:13 +08:00
2014-09-24 21:06:34 +08:00
END - USER GUIDE
= = = = = = = = = = = = = =
2014-08-11 04:58:11 +08:00
- double - click title bar to collapse window
2014-12-22 21:29:39 +08:00
- click upper right corner to close a window , available when ' bool * p_opened ' is passed to ImGui : : Begin ( )
2014-08-11 04:58:11 +08:00
- click and drag on lower right corner to resize window
- click and drag on any empty space to move window
- double - click / double - tap on lower right corner grip to auto - fit to content
- TAB / SHIFT + TAB to cycle through keyboard editable fields
- use mouse wheel to scroll
- use CTRL + mouse wheel to zoom window contents ( if IO . FontAllowScaling is true )
- CTRL + Click on a slider to input value as text
- text editor :
- Hold SHIFT or use mouse to select text .
- CTRL + Left / Right to word jump
- CTRL + Shift + Left / Right to select words
- CTRL + A our Double - Click to select all
- CTRL + X , CTRL + C , CTRL + V to use OS clipboard
- CTRL + Z , CTRL + Y to undo / redo
- ESCAPE to revert text to its original value
- You can apply arithmetic operators + , * , / on numerical values . Use + - to subtract ( because - would set a negative value ! )
2014-12-04 19:42:13 +08:00
2014-08-11 04:58:11 +08:00
PROGRAMMER GUIDE
2014-09-24 21:06:34 +08:00
= = = = = = = = = = = = = = = =
2014-08-11 04:58:11 +08:00
- 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 .
2015-01-18 06:38:10 +08:00
- call and read ImGui : : ShowTestWindow ( ) for user - side sample code
2014-09-24 21:06:34 +08:00
- see examples / folder for standalone sample applications .
2015-02-04 16:01:00 +08:00
- 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 ) .
2014-09-24 21:06:34 +08:00
2014-08-11 04:58:11 +08:00
- getting started :
- initialisation : call ImGui : : GetIO ( ) and fill the ' Settings ' data .
- every frame :
1 / in your mainloop or right after you got your keyboard / mouse info , call ImGui : : GetIO ( ) and fill the ' Input ' data , then call ImGui : : NewFrame ( ) .
2 / use any ImGui function you want between NewFrame ( ) and Render ( )
2014-08-27 01:27:10 +08:00
3 / ImGui : : Render ( ) to render all the accumulated command - lists . it will call your RenderDrawListFn handler that you set in the IO structure .
2014-08-11 04:58:11 +08:00
- all rendering information are stored into command - lists until ImGui : : Render ( ) is called .
- effectively it means you can create widgets at any time in your code , regardless of " update " vs " render " considerations .
2014-08-31 15:23:55 +08:00
- refer to the examples applications in the examples / folder for instruction on how to setup your code .
2014-08-11 04:58:11 +08:00
- a typical application skeleton may be :
2014-08-19 19:09:13 +08:00
// Application init
ImGuiIO & io = ImGui : : GetIO ( ) ;
io . DisplaySize . x = 1920.0f ;
io . DisplaySize . y = 1280.0f ;
io . DeltaTime = 1.0f / 60.0f ;
io . IniFilename = " imgui.ini " ;
2015-01-12 05:24:12 +08:00
// TODO: Fill others settings of the io structure
// Load texture
unsigned char * pixels ;
2015-01-22 18:03:24 +08:00
int width , height , bytes_per_pixels ;
io . Fonts - > GetTexDataAsRGBA32 ( pixels , & width , & height , & bytes_per_pixels ) ;
2015-01-18 06:38:10 +08:00
// TODO: copy texture to graphics memory.
2015-01-18 18:46:49 +08:00
// TODO: store your texture pointer/identifier in 'io.Fonts->TexID'
2014-08-19 19:09:13 +08:00
2014-10-27 05:31:34 +08:00
// Application main loop
2014-08-19 19:09:13 +08:00
while ( true )
{
2015-01-18 06:38:10 +08:00
// 1) get low-level input
2014-08-19 19:09:13 +08:00
// e.g. on Win32, GetKeyboardState(), or poll your events, etc.
2015-01-18 06:38:10 +08:00
// 2) TODO: fill all fields of IO structure and call NewFrame
2014-08-19 19:09:13 +08:00
ImGuiIO & io = ImGui : : GetIO ( ) ;
2015-02-04 16:01:00 +08:00
io . MousePos = mouse_pos ;
io . MouseDown [ 0 ] = mouse_button_0 ;
2014-08-19 19:09:13 +08:00
io . KeysDown [ i ] = . . .
ImGui : : NewFrame ( ) ;
2015-01-18 06:38:10 +08:00
// 3) most of your application code here - you can use any of ImGui::* functions at any point in the frame
ImGui : : Begin ( " My window " ) ;
ImGui : : Text ( " Hello, world. " ) ;
ImGui : : End ( ) ;
2014-08-19 19:09:13 +08:00
GameUpdate ( ) ;
GameRender ( ) ;
2015-01-18 06:38:10 +08:00
// 4) render & swap video buffers
2014-08-19 19:09:13 +08:00
ImGui : : Render ( ) ;
// swap video buffer, etc.
}
2014-08-11 04:58:11 +08:00
2015-02-04 16:01:00 +08:00
- after calling ImGui : : NewFrame ( ) you can read back ' io . WantCaptureMouse ' and ' io . WantCaptureKeyboard ' to tell if ImGui
wants to use your inputs . if it does you can discard / hide the inputs from the rest of your application .
2014-12-04 19:42:13 +08:00
2014-11-27 06:27:48 +08:00
API BREAKING CHANGES
= = = = = = = = = = = = = = = = = = = =
Occasionally introducing changes that are breaking the API . The breakage are generally minor and easy to fix .
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 .
2015-01-29 17:22:32 +08:00
2015-02-12 01:39:13 +08:00
- 2015 / 02 / 11 ( 1.32 ) - changed text input callback ImGuiTextEditCallback return type from void - - > int . reserved for future use , return 0 for now .
2015-02-11 05:07:26 +08:00
- 2015 / 02 / 10 ( 1.32 ) - renamed GetItemWidth ( ) to CalcItemWidth ( ) to clarify its evolving behavior
2015-02-08 21:37:20 +08:00
- 2015 / 02 / 08 ( 1.31 ) - renamed GetTextLineSpacing ( ) to GetTextLineHeightWithSpacing ( )
2015-02-01 22:39:13 +08:00
- 2015 / 02 / 01 ( 1.31 ) - removed IO . MemReallocFn ( unused )
2015-01-29 17:22:32 +08:00
- 2015 / 01 / 19 ( 1.30 ) - renamed ImGuiStorage : : GetIntPtr ( ) / GetFloatPtr ( ) to GetIntRef ( ) / GetIntRef ( ) because Ptr was conflicting with actual pointer storage functions .
2015-01-18 06:38:10 +08:00
- 2015 / 01 / 11 ( 1.30 ) - big font / image API change ! now loads TTF file . allow for multiple fonts . no need for a PNG loader .
2015-01-18 18:46:49 +08:00
( 1.30 ) - removed GetDefaultFontData ( ) . uses io . Fonts - > GetTextureData * ( ) API to retrieve uncompressed pixels .
2015-01-18 06:38:10 +08:00
this sequence :
const void * png_data ;
unsigned int png_size ;
ImGui : : GetDefaultFontData ( NULL , NULL , & png_data , & png_size ) ;
// <Copy to GPU>
became :
unsigned char * pixels ;
int width , height ;
2015-01-18 18:46:49 +08:00
io . Fonts - > GetTexDataAsRGBA32 ( & pixels , & width , & height ) ;
2015-01-18 06:38:10 +08:00
// <Copy to GPU>
2015-01-18 18:46:49 +08:00
io . Fonts - > TexID = ( your_texture_identifier ) ;
2015-01-18 20:22:17 +08:00
you now have much more flexibility to load multiple TTF fonts and manage the texture buffer for internal needs .
it is now recommended your sample the font texture with bilinear interpolation .
2015-01-18 18:46:49 +08:00
( 1.30 ) - added texture identifier in ImDrawCmd passed to your render function ( we can now render images ) . make sure to set io . Fonts - > TexID .
2015-01-18 06:38:10 +08:00
( 1.30 ) - removed IO . PixelCenterOffset ( unnecessary , can be handled in user projection matrix )
2015-01-23 06:54:05 +08:00
( 1.30 ) - removed ImGui : : IsItemFocused ( ) in favor of ImGui : : IsItemActive ( ) which handles all widgets
2015-01-18 06:38:10 +08:00
- 2014 / 12 / 10 ( 1.18 ) - removed SetNewWindowDefaultPos ( ) in favor of new generic API SetNextWindowPos ( pos , ImGuiSetCondition_FirstUseEver )
2015-01-21 05:37:18 +08:00
- 2014 / 11 / 28 ( 1.17 ) - moved IO . Font * * * options to inside the IO . Font - > structure ( FontYOffset , FontTexUvForWhite , FontBaseScale , FontFallbackGlyph )
2015-01-18 06:38:10 +08:00
- 2014 / 11 / 26 ( 1.17 ) - reworked syntax of IMGUI_ONCE_UPON_A_FRAME helper macro to increase compiler compatibility
- 2014 / 11 / 07 ( 1.15 ) - renamed IsHovered ( ) to IsItemHovered ( )
- 2014 / 10 / 02 ( 1.14 ) - renamed IMGUI_INCLUDE_IMGUI_USER_CPP to IMGUI_INCLUDE_IMGUI_USER_INL and imgui_user . cpp to imgui_user . inl ( more IDE friendly )
- 2014 / 09 / 25 ( 1.13 ) - removed ' text_end ' parameter from IO . SetClipboardTextFn ( the string is now always zero - terminated for simplicity )
- 2014 / 09 / 24 ( 1.12 ) - renamed SetFontScale ( ) to SetWindowFontScale ( )
- 2014 / 09 / 24 ( 1.12 ) - moved IM_MALLOC / IM_REALLOC / IM_FREE preprocessor defines to IO . MemAllocFn / IO . MemReallocFn / IO . MemFreeFn
- 2014 / 08 / 30 ( 1.09 ) - removed IO . FontHeight ( now computed automatically )
- 2014 / 08 / 30 ( 1.09 ) - moved IMGUI_FONT_TEX_UV_FOR_WHITE preprocessor define to IO . FontTexUvForWhite
- 2014 / 08 / 28 ( 1.09 ) - changed the behavior of IO . PixelCenterOffset following various rendering fixes
2014-11-27 06:27:48 +08:00
2014-12-04 19:42:13 +08:00
2014-08-31 15:23:55 +08:00
TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS
2014-09-24 21:06:34 +08:00
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
2014-08-31 15:23:55 +08:00
2014-11-30 23:54:58 +08:00
If text or lines are blurry when integrating ImGui in your engine :
2014-08-27 01:27:10 +08:00
- in your Render function , try translating your projection matrix by ( 0.5f , 0.5f ) or ( 0.375f , 0.375f )
2014-11-30 23:54:58 +08:00
If you are confused about the meaning or use of ID in ImGui :
2015-02-04 16:01:00 +08:00
- many widgets requires state to be carried over multiple frames ( most typically ImGui often wants remember what is the " active " widget ) .
2014-08-31 15:23:55 +08:00
to do so they need an unique ID . unique ID are typically derived from a string label , an indice or a pointer .
when you call Button ( " OK " ) the button shows " OK " and also use " OK " as an ID .
- ID are uniquely scoped within Windows so no conflict can happen if you have two buttons called " OK " in two different Windows .
within a same Window , use PushID ( ) / PopID ( ) to easily create scopes and avoid ID conflicts .
2014-09-25 03:39:39 +08:00
so if you have a loop creating " multiple " items , you can use PushID ( ) / PopID ( ) with the index of each item , or their pointer , etc .
some functions like TreeNode ( ) implicitly creates a scope for you by calling PushID ( )
2014-08-31 15:23:55 +08:00
- when dealing with trees , ID are important because you want to preserve the opened / closed state of tree nodes .
2014-08-11 04:58:11 +08:00
depending on your use cases you may want to use strings , indices or pointers as ID . experiment and see what makes more sense !
2015-02-04 16:01:00 +08:00
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
2014-08-11 04:58:11 +08:00
e . g . When displaying a list of objects , using indices or pointers as ID will preserve the node open / closed state per object
- when passing a label you can optionally specify extra unique ID information within the same string using " ## " . This helps solving the simpler collision cases .
e . g . " Label " display " Label " and uses " Label " as ID
e . g . " Label##Foobar " display " Label " and uses " Label##Foobar " as ID
e . g . " ##Foobar " display an empty label and uses " ##Foobar " as ID
2015-02-04 16:01:00 +08:00
- read articles about immediate - mode ui principles ( see web links ) to understand the requirement and use of ID .
2014-08-11 04:58:11 +08:00
2015-01-18 06:38:10 +08:00
If you want to load a different font than the default ( ProggyClean . ttf , size 13 )
2015-01-12 05:24:12 +08:00
2015-01-18 18:46:49 +08:00
io . Fonts - > AddFontFromFileTTF ( " myfontfile.ttf " , size_in_pixels ) ;
2015-01-18 23:12:41 +08:00
io . Fonts - > GetTexDataAsRGBA32 ( ) or GetTexDataAsAlpha8 ( )
2015-01-18 06:38:10 +08:00
2015-01-18 18:46:49 +08:00
If you want to load multiple fonts , use the font atlas to pack them into a single texture !
2015-01-18 06:38:10 +08:00
2015-01-18 18:46:49 +08:00
ImFont * font0 = io . Fonts - > AddFontDefault ( ) ;
ImFont * font1 = io . Fonts - > AddFontFromFileTTF ( " myfontfile.ttf " , size_in_pixels ) ;
2015-02-04 16:01:00 +08:00
ImFont * font2 = io . Fonts - > AddFontFromFileTTF ( " myfontfile2.ttf " , size_in_pixels ) ;
2015-01-18 23:12:41 +08:00
io . Fonts - > GetTexDataAsRGBA32 ( ) or GetTexDataAsAlpha8 ( )
2015-01-18 06:38:10 +08:00
If you want to display Chinese , Japanese , Korean characters , pass custom Unicode ranges when loading a font :
2015-01-18 18:46:49 +08:00
io . Fonts - > AddFontFromFileTTF ( " myfontfile.ttf " , size_in_pixels , io . Fonts - > GetGlyphRangesJapanese ( ) ) ; // Load Japanese characters
2015-01-18 23:12:41 +08:00
io . Fonts - > GetTexDataAsRGBA32 ( ) or GetTexDataAsAlpha8 ( )
2014-11-30 23:54:58 +08:00
If you want to input Japanese / Chinese / Korean in the text input widget :
2015-01-18 06:38:10 +08:00
2015-01-18 18:46:49 +08:00
- when loading the font , pass a range that contains the characters you need , e . g . : io . Fonts - > GetGlyphRangesJapanese ( )
2014-11-30 23:54:58 +08:00
- to have the Microsoft IME cursor appears at the right location in the screen , setup a handler for the io . ImeSetInputScreenPosFn function :
# include <Windows.h>
# include <Imm.h>
static void ImImpl_ImeSetInputScreenPosFn ( int x , int y )
{
// Notify OS Input Method Editor of text input position
HWND hwnd = glfwGetWin32Window ( window ) ;
if ( HIMC himc = ImmGetContext ( hwnd ) )
{
COMPOSITIONFORM cf ;
cf . ptCurrentPos . x = x ;
cf . ptCurrentPos . y = y ;
cf . dwStyle = CFS_FORCE_POSITION ;
ImmSetCompositionWindow ( himc , & cf ) ;
}
}
// Set pointer to handler in ImGuiIO structure
io . ImeSetInputScreenPosFn = ImImpl_ImeSetInputScreenPosFn ;
2015-02-04 16:01:00 +08:00
- 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 .
2014-08-31 15:23:55 +08:00
- tip : you can create widgets without a Begin ( ) / End ( ) block , they will go in an implicit window called " Debug "
2015-02-04 16:01:00 +08:00
- tip : you can call Begin ( ) multiple times with the same name during the same frame , it will keep appending to the same window .
- tip : you can call Render ( ) multiple times ( e . g for VR renders ) .
2015-01-18 06:38:10 +08:00
- tip : call and read the ShowTestWindow ( ) code for more example of how to use ImGui !
2014-08-11 04:58:11 +08:00
2014-12-04 19:42:13 +08:00
2014-09-24 21:06:34 +08:00
ISSUES & TODO - LIST
= = = = = = = = = = = = = = = = = =
2014-08-11 04:58:11 +08:00
2014-10-02 18:56:40 +08:00
- misc : merge or clarify ImVec4 / ImGuiAabb , they are essentially duplicate containers
- window : add horizontal scroll
- window : fix resize grip rendering scaling along with Rounding style setting
2014-12-29 00:09:19 +08:00
- window : autofit feedback loop when user relies on any dynamic layout ( window width multiplier , column ) . maybe just clearly drop manual autofit ?
2014-12-11 18:12:52 +08:00
- window : add a way for very transient windows ( non - saved , temporary overlay over hundreds of objects ) to " clean " up from the global window list .
2015-01-14 21:43:41 +08:00
- window : allow resizing of child windows ( possibly given min / max for each axis ? )
2015-01-23 06:54:05 +08:00
- window : background options for child windows , border option ( disable rounding )
2015-01-15 05:58:30 +08:00
- window : resizing from any sides ? + mouse cursor directives for app .
2015-02-09 01:26:24 +08:00
- widgets : clicking on widget b while widget a should activate widget b ( doesn ' t anymore because of hover capture )
2015-01-20 17:37:30 +08:00
- widgets : display mode : widget - label , label - widget ( aligned on column or using fixed size ) , label - newline - tab - widget etc .
2014-08-11 04:58:11 +08:00
- widgets : clip text ? hover clipped text shows it in a tooltip or in - place overlay
2015-02-04 16:01:00 +08:00
- main : considering adding EndFrame ( ) / Init ( ) . some constructs are awkward in the implementation because of the lack of them .
2015-01-14 21:43:41 +08:00
- 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 ?
- 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
- main : IsItemHovered ( ) info stored in a stack ? so that ' if TreeNode ( ) { Text ; TreePop ; } if IsHovered ' return the hover state of the TreeNode ?
2014-08-11 04:58:11 +08:00
- scrollbar : use relative mouse movement when first - clicking inside of scroll grab box .
2014-08-17 18:28:19 +08:00
- scrollbar : make the grab visible and a minimum size for long scroll regions
2014-12-05 20:34:14 +08:00
! - input number : very large int not reliably supported because of int < > float conversions .
- input number : optional range min / max for Input * ( ) functions
2014-12-29 00:09:19 +08:00
- input number : holding [ - ] / [ + ] buttons could increase the step speed non - linearly ( or user - controlled )
2014-08-19 02:13:18 +08:00
- input number : use mouse wheel to step up / down
2014-12-31 17:49:47 +08:00
- input number : non - decimal input .
2014-12-29 00:09:19 +08:00
- layout : horizontal layout helper ( github issue # 97 )
2015-02-03 03:50:28 +08:00
- layout : more generic alignment state ( left / right / centered ) for single items ?
2015-01-14 21:43:41 +08:00
- layout : clean up the InputFloatN / SliderFloatN / ColorEdit4 layout code . item width should include frame padding .
2014-12-29 00:09:19 +08:00
- columns : separator function or parameter that works within the column ( currently Separator ( ) bypass all columns )
2014-08-11 04:58:11 +08:00
- columns : declare column set ( each column : fixed size , % , fill , distribute default size among fills )
- columns : columns header to act as button ( ~ sort op ) and allow resize / reorder
- columns : user specify columns size
2015-02-11 20:10:45 +08:00
- columns : tree node example actually has a small bug ( opening node in right column extends the column different from opening node in left column )
2014-11-29 05:53:31 +08:00
- combo : turn child handling code into pop up helper
2015-02-08 23:57:06 +08:00
- combo : contents should extends to fit label if combo widget is small
2015-02-11 08:21:27 +08:00
- listbox : multiple selection
- listbox : user may want to initial scroll to focus on the one selected value ?
2015-02-04 16:01:00 +08:00
! menubar , menus
2015-01-23 06:54:05 +08:00
- tabs
2015-01-22 06:45:21 +08:00
- gauge : various forms of gauge / loading bars widgets
2015-01-20 17:37:30 +08:00
- color : better color editor .
2015-02-04 16:01:00 +08:00
- plot : make it easier for user to draw extra stuff into the graph ( e . g : draw basis , highlight certain points , 2 d plots , multiple plots )
- plot : " smooth " automatic scale over time , user give an input 0.0 ( full user scale ) 1.0 ( full derived from value )
2014-08-11 04:58:11 +08:00
- 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 )
2015-02-04 16:01:00 +08:00
- file selection widget - > build the tool in our codebase to improve model - dialog idioms
2014-08-11 04:58:11 +08:00
- slider : allow using the [ - ] / [ + ] buttons used by InputFloat ( ) / InputInt ( )
2014-10-27 05:31:34 +08:00
- slider : initial absolute click is imprecise . change to relative movement slider ? hide mouse cursor , allow more precise input using less screen - space .
2015-02-11 20:10:45 +08:00
- text edit : clean up the mess caused by converting UTF - 8 < > wchar . the code is rather inefficient right now .
2015-02-04 16:01:00 +08:00
- text edit : centered text for slider as input text so it matches typical positioning .
2014-08-11 04:58:11 +08:00
- text edit : flag to disable live update of the user buffer .
2014-10-27 05:31:34 +08:00
- text edit : field resize behavior - field could stretch when being edited ? hover tooltip shows more text ?
2014-11-24 07:35:26 +08:00
- text edit : add multi - line text edit
2015-02-21 21:36:24 +08:00
- tree : reformulate OpenNextNode ( ) into SetNextWindowCollapsed ( ) api
2015-01-23 06:54:05 +08:00
- tree : add treenode / treepush int variants ? because ( void * ) cast from int warns on some platforms / settings
2014-08-11 04:58:11 +08:00
- settings : write more decent code to allow saving / loading new fields
2014-10-27 05:31:34 +08:00
- settings : api for per - tool simple persistent data ( bool , int , float ) in . ini file
2015-02-04 16:01:00 +08:00
! style : store rounded corners in texture to use 1 quad per corner ( filled and wireframe ) . so rounding have minor cost .
2015-01-15 05:58:30 +08:00
- style : checkbox : padding for " active " color should be a multiplier of the
- style : colorbox not always square ?
2015-02-19 01:17:06 +08:00
- text : simple markup language for color change ?
2015-01-20 17:37:30 +08:00
- log : LogButtons ( ) options for specifying depth and / or hiding depth slider
2014-11-30 20:21:50 +08:00
- log : have more control over the log scope ( e . g . stop logging when leaving current tree node scope )
2015-01-04 01:38:10 +08:00
- log : be able to right - click and log a window or tree - node into tty / file / clipboard / generalized context menu ?
2014-08-11 04:58:11 +08:00
- filters : set a current filter that tree node can automatically query to hide themselves
- filters : handle wildcards ( with implicit leading / trailing * ) , regexps
- shortcuts : add a shortcut api , e . g . parse " &Save " and / or " Save (CTRL+S) " , pass in to widgets or provide simple ways to use ( button = activate , input = focus )
2014-09-30 19:22:58 +08:00
! keyboard : tooltip & combo boxes are messing up / not honoring keyboard tabbing
2014-09-30 18:57:37 +08:00
- keyboard : full keyboard navigation and focus .
2014-10-27 05:31:34 +08:00
- input : rework IO to be able to pass actual events to fix temporal aliasing issues .
- input : support track pad style scrolling & slider edit .
2014-09-30 18:57:37 +08:00
- tooltip : move to fit within screen ( e . g . when mouse cursor is right of the screen ) .
2014-11-15 20:00:35 +08:00
- portability : big - endian test / support ( github issue # 81 )
2015-01-23 06:54:05 +08:00
- misc : mark printf compiler attributes on relevant functions
2014-12-29 00:09:19 +08:00
- misc : provide a way to compile out the entire implementation while providing a dummy API ( e . g . # define IMGUI_DUMMY_IMPL )
2014-08-17 01:47:59 +08:00
- misc : double - clicking on title bar to minimize isn ' t consistent , perhaps move to single - click on left - most collapse icon ?
2015-02-03 03:50:28 +08:00
- style editor : have a more global HSV setter ( e . g . alter hue on all elements ) . consider replacing active / hovered by offset in HSV space ?
2015-01-15 05:58:30 +08:00
- style editor : color child window height expressed in multiple of line height .
2014-12-11 18:12:52 +08:00
- optimization / render : use indexed rendering to reduce vertex data cost ( for remote / networked imgui )
2014-10-27 05:31:34 +08:00
- optimization / render : merge command - lists with same clip - rect into one even if they aren ' t sequential ? ( as long as in - between clip rectangle don ' t overlap ) ?
- optimization : turn some the various stack vectors into statically - sized arrays
- optimization : better clipping for multi - component widgets
- optimization : specialize for height based clipping first ( assume widgets never go up + height tests before width tests ? )
2014-08-11 04:58:11 +08:00
*/
2014-11-18 17:55:31 +08:00
# if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
2014-11-12 15:56:42 +08:00
# define _CRT_SECURE_NO_WARNINGS
# endif
2014-08-11 04:58:11 +08:00
# include "imgui.h"
2014-08-19 19:09:13 +08:00
# include <ctype.h> // toupper
2014-11-18 15:51:55 +08:00
# include <math.h> // sqrtf
2014-08-19 19:09:13 +08:00
# include <stdint.h> // intptr_t
# include <stdio.h> // vsnprintf
2014-08-18 16:49:35 +08:00
# include <new> // new (ptr)
2014-08-11 04:58:11 +08:00
2014-11-18 17:55:31 +08:00
# ifdef _MSC_VER
2015-02-02 17:06:51 +08:00
# pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
2014-11-18 17:55:31 +08:00
# pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
# endif
2014-12-29 19:23:03 +08:00
// Clang warnings with -Weverything
2014-11-18 17:55:31 +08:00
# ifdef __clang__
2014-12-29 19:23:03 +08:00
# pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
2014-11-18 17:55:31 +08:00
# pragma clang diagnostic ignored "-Wfloat-equal" // warning : comparing floating point with == or != is unsafe // storing and comparing against same constants ok.
2014-12-29 19:23:03 +08:00
# 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.
2014-11-18 17:55:31 +08:00
# 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.
# pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference it.
2015-01-24 18:18:31 +08:00
# pragma clang diagnostic ignored "-Wsign-conversion" // warning : implicit conversion changes signedness //
2014-11-18 17:55:31 +08:00
# endif
2015-01-24 18:30:40 +08:00
# ifdef __GNUC__
# pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used
# endif
2014-11-18 17:55:31 +08:00
2015-01-09 07:35:01 +08:00
//-------------------------------------------------------------------------
// STB libraries implementation
//-------------------------------------------------------------------------
2015-01-21 18:54:23 +08:00
struct ImGuiTextEditState ;
//#define IMGUI_STB_NAMESPACE ImStb
2015-01-21 18:59:11 +08:00
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
2015-01-21 18:54:23 +08:00
# ifdef IMGUI_STB_NAMESPACE
namespace IMGUI_STB_NAMESPACE
{
# endif
2015-01-18 07:13:54 +08:00
# ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunused-function"
2015-01-18 07:21:06 +08:00
# pragma clang diagnostic ignored "-Wmissing-prototypes"
2015-01-18 07:13:54 +08:00
# endif
2015-01-18 07:21:06 +08:00
2015-01-21 18:54:23 +08:00
# define STBRP_ASSERT(x) IM_ASSERT(x)
2015-01-21 18:59:11 +08:00
# ifndef IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
# define STBRP_STATIC
2015-01-18 07:21:06 +08:00
# define STB_RECT_PACK_IMPLEMENTATION
2015-01-21 18:59:11 +08:00
# endif
2015-01-09 07:35:01 +08:00
# include "stb_rect_pack.h"
# define STBTT_malloc(x,u) ((void)(u), ImGui::MemAlloc(x))
# define STBTT_free(x,u) ((void)(u), ImGui::MemFree(x))
2015-01-21 18:54:23 +08:00
# define STBTT_assert(x) IM_ASSERT(x)
2015-01-21 18:59:11 +08:00
# ifndef IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
2015-01-22 06:45:21 +08:00
# define STBTT_STATIC
2015-01-21 18:59:11 +08:00
# define STB_TRUETYPE_IMPLEMENTATION
# endif
2015-01-09 07:35:01 +08:00
# include "stb_truetype.h"
# define STB_TEXTEDIT_STRING ImGuiTextEditState
# define STB_TEXTEDIT_CHARTYPE ImWchar
# include "stb_textedit.h"
2015-01-18 07:21:06 +08:00
# ifdef __clang__
# pragma clang diagnostic pop
# endif
2015-01-21 18:54:23 +08:00
# ifdef IMGUI_STB_NAMESPACE
} // namespace ImStb
using namespace IMGUI_STB_NAMESPACE ;
# endif
2014-08-11 04:58:11 +08:00
//-------------------------------------------------------------------------
// Forward Declarations
//-------------------------------------------------------------------------
2015-02-08 23:39:40 +08:00
struct ImGuiAabb ;
2015-02-11 01:45:45 +08:00
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 ) ;
2014-08-19 19:09:13 +08:00
static void LogText ( const ImVec2 & ref_pos , const char * text , const char * text_end = NULL ) ;
2014-08-11 04:58:11 +08:00
2015-02-08 23:57:06 +08:00
static void RenderText ( ImVec2 pos , const char * text , const char * text_end = NULL , bool hide_text_after_hash = true ) ;
static void RenderTextWrapped ( ImVec2 pos , const char * text , const char * text_end , float wrap_width ) ;
2015-02-09 00:32:51 +08:00
static void RenderTextClipped ( ImVec2 pos , const char * text , const char * text_end , const ImVec2 * text_size_if_known , const ImVec2 & clip_max ) ;
2014-08-28 05:16:55 +08:00
static void RenderFrame ( ImVec2 p_min , ImVec2 p_max , ImU32 fill_col , bool border = true , float rounding = 0.0f ) ;
2014-12-22 21:29:39 +08:00
static void RenderCollapseTriangle ( ImVec2 p_min , bool opened , float scale = 1.0f , bool shadow = false ) ;
2014-08-11 04:58:11 +08:00
2015-01-17 21:40:56 +08:00
static void SetFont ( ImFont * font ) ;
2015-01-23 06:54:05 +08:00
static bool ItemAdd ( const ImGuiAabb & aabb , const ImGuiID * id ) ;
2014-08-19 19:09:13 +08:00
static void ItemSize ( ImVec2 size , ImVec2 * adjust_start_offset = NULL ) ;
static void ItemSize ( const ImGuiAabb & aabb , ImVec2 * adjust_start_offset = NULL ) ;
static void PushColumnClipRect ( int column_index = - 1 ) ;
static bool IsClipped ( const ImGuiAabb & aabb ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
static bool IsMouseHoveringBox ( const ImGuiAabb & box ) ;
static bool IsKeyPressedMap ( ImGuiKey key , bool repeat = true ) ;
2014-08-11 04:58:11 +08:00
2014-12-22 21:29:39 +08:00
static bool CloseWindowButton ( bool * p_opened = NULL ) ;
2014-08-19 19:09:13 +08:00
static void FocusWindow ( ImGuiWindow * window ) ;
2014-08-11 04:58:11 +08:00
static ImGuiWindow * FindHoveredWindow ( ImVec2 pos , bool excluding_childs ) ;
2014-12-29 19:23:03 +08:00
// Helpers: String
static int ImStricmp ( const char * str1 , const char * str2 ) ;
static int ImStrnicmp ( const char * str1 , const char * str2 , int count ) ;
static char * ImStrdup ( const char * str ) ;
static size_t ImStrlenW ( const ImWchar * str ) ;
static const char * ImStristr ( const char * haystack , const char * needle , const char * needle_end ) ;
static size_t ImFormatString ( char * buf , size_t buf_size , const char * fmt , . . . ) ;
static size_t ImFormatStringV ( char * buf , size_t buf_size , const char * fmt , va_list args ) ;
2015-01-17 21:40:56 +08:00
// Helpers: Misc
2014-12-29 19:23:03 +08:00
static ImU32 ImCrc32 ( const void * data , size_t data_size , ImU32 seed ) ;
2014-12-30 02:05:22 +08:00
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 ) ;
2015-01-17 21:40:56 +08:00
static int ImUpperPowerOfTwo ( int v ) { v - - ; v | = v > > 1 ; v | = v > > 2 ; v | = v > > 4 ; v | = v > > 8 ; v | = v > > 16 ; v + + ; return v ; }
2014-12-29 19:23:03 +08:00
// Helpers: UTF-8 <> wchar
static int ImTextCharToUtf8 ( char * buf , size_t buf_size , unsigned int in_char ) ; // return output UTF-8 bytes count
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
static int ImTextCharFromUtf8 ( unsigned int * out_char , const char * in_text , const char * in_text_end ) ; // return input UTF-8 bytes count
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
static int ImTextCountCharsFromUtf8 ( const char * in_text , const char * in_text_end ) ; // return number of UTF-8 code-points (NOT bytes count)
static int ImTextCountUtf8BytesFromWchar ( const ImWchar * in_text , const ImWchar * in_text_end ) ; // return number of bytes to express string as UTF-8 code-points
2014-08-14 02:53:26 +08:00
//-----------------------------------------------------------------------------
2014-11-10 09:29:01 +08:00
// Platform dependent default implementations
2014-08-14 02:53:26 +08:00
//-----------------------------------------------------------------------------
2014-08-19 19:09:13 +08:00
static const char * GetClipboardTextFn_DefaultImpl ( ) ;
2014-09-25 21:51:06 +08:00
static void SetClipboardTextFn_DefaultImpl ( const char * text ) ;
2014-08-14 02:53:26 +08:00
2015-02-01 02:55:05 +08:00
//-----------------------------------------------------------------------------
// Texture Atlas data
//-----------------------------------------------------------------------------
// Technically we should use the rect pack API for that, but it's just simpler to hard-core the positions for now.
// As we start using more of the texture atlas (for rounded corners) we can change that.
static const ImVec2 TEX_ATLAS_SIZE ( 32 , 32 ) ;
static const ImVec2 TEX_ATLAS_POS_MOUSE_CURSOR_BLACK ( 1 , 3 ) ;
static const ImVec2 TEX_ATLAS_POS_MOUSE_CURSOR_WHITE ( 14 , 3 ) ;
static const ImVec2 TEX_ATLAS_SIZE_MOUSE_CURSOR ( 12 , 19 ) ;
2014-08-11 04:58:11 +08:00
//-----------------------------------------------------------------------------
// User facing structures
//-----------------------------------------------------------------------------
ImGuiStyle : : ImGuiStyle ( )
{
2014-08-19 19:09:13 +08:00
Alpha = 1.0f ; // Global alpha applies to everything in ImGui
WindowPadding = ImVec2 ( 8 , 8 ) ; // Padding within a window
2015-01-15 06:10:48 +08:00
WindowMinSize = ImVec2 ( 32 , 32 ) ; // Minimum window size
2014-12-30 18:00:00 +08:00
WindowRounding = 9.0f ; // Radius of window corners rounding. Set to 0.0f to have rectangular windows
2015-02-10 21:00:22 +08:00
ChildWindowRounding = 0.0f ; // Radius of child window corners rounding. Set to 0.0f to have rectangular windows
2014-12-30 18:00:00 +08:00
FramePadding = ImVec2 ( 4 , 3 ) ; // Padding within a framed rectangle (used by most widgets)
2015-01-15 17:14:44 +08:00
FrameRounding = 0.0f ; // Radius of frame corners rounding. Set to 0.0f to have rectangular frames (used by most widgets).
2014-12-30 18:00:00 +08:00
ItemSpacing = ImVec2 ( 8 , 4 ) ; // Horizontal and vertical spacing between widgets/lines
ItemInnerSpacing = ImVec2 ( 4 , 4 ) ; // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
2014-08-19 19:09:13 +08:00
TouchExtraPadding = ImVec2 ( 0 , 0 ) ; // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much!
AutoFitPadding = ImVec2 ( 8 , 8 ) ; // Extra space after auto-fit (double-clicking on resize grip)
WindowFillAlphaDefault = 0.70f ; // Default alpha of window background, if not specified in ImGui::Begin()
TreeNodeSpacing = 22.0f ; // Horizontal spacing when entering a tree node
ColumnsMinSpacing = 6.0f ; // Minimum horizontal spacing between two columns
ScrollBarWidth = 16.0f ; // Width of the vertical scroll bar
Colors [ ImGuiCol_Text ] = ImVec4 ( 0.90f , 0.90f , 0.90f , 1.00f ) ;
Colors [ ImGuiCol_WindowBg ] = ImVec4 ( 0.00f , 0.00f , 0.00f , 1.00f ) ;
2015-02-10 21:00:22 +08:00
Colors [ ImGuiCol_ChildWindowBg ] = ImVec4 ( 0.00f , 0.00f , 0.00f , 0.00f ) ;
2014-08-19 19:09:13 +08:00
Colors [ ImGuiCol_Border ] = ImVec4 ( 1.00f , 1.00f , 1.00f , 1.00f ) ;
Colors [ ImGuiCol_BorderShadow ] = ImVec4 ( 0.00f , 0.00f , 0.00f , 0.60f ) ;
Colors [ ImGuiCol_FrameBg ] = ImVec4 ( 0.80f , 0.80f , 0.80f , 0.30f ) ; // Background of checkbox, radio button, plot, slider, text input
Colors [ ImGuiCol_TitleBg ] = ImVec4 ( 0.50f , 0.50f , 1.00f , 0.45f ) ;
Colors [ ImGuiCol_TitleBgCollapsed ] = ImVec4 ( 0.40f , 0.40f , 0.80f , 0.20f ) ;
Colors [ ImGuiCol_ScrollbarBg ] = ImVec4 ( 0.40f , 0.40f , 0.80f , 0.15f ) ;
Colors [ ImGuiCol_ScrollbarGrab ] = ImVec4 ( 0.40f , 0.40f , 0.80f , 0.30f ) ;
Colors [ ImGuiCol_ScrollbarGrabHovered ] = ImVec4 ( 0.40f , 0.40f , 0.80f , 0.40f ) ;
Colors [ ImGuiCol_ScrollbarGrabActive ] = ImVec4 ( 0.80f , 0.50f , 0.50f , 0.40f ) ;
Colors [ ImGuiCol_ComboBg ] = ImVec4 ( 0.20f , 0.20f , 0.20f , 0.99f ) ;
2015-01-05 03:37:24 +08:00
Colors [ ImGuiCol_CheckHovered ] = ImVec4 ( 0.60f , 0.40f , 0.40f , 0.45f ) ;
Colors [ ImGuiCol_CheckActive ] = ImVec4 ( 0.65f , 0.50f , 0.50f , 0.55f ) ;
Colors [ ImGuiCol_CheckMark ] = ImVec4 ( 0.90f , 0.90f , 0.90f , 0.50f ) ;
2014-08-19 19:09:13 +08:00
Colors [ ImGuiCol_SliderGrab ] = ImVec4 ( 1.00f , 1.00f , 1.00f , 0.30f ) ;
Colors [ ImGuiCol_SliderGrabActive ] = ImVec4 ( 0.80f , 0.50f , 0.50f , 1.00f ) ;
Colors [ ImGuiCol_Button ] = ImVec4 ( 0.67f , 0.40f , 0.40f , 0.60f ) ;
Colors [ ImGuiCol_ButtonHovered ] = ImVec4 ( 0.67f , 0.40f , 0.40f , 1.00f ) ;
Colors [ ImGuiCol_ButtonActive ] = ImVec4 ( 0.80f , 0.50f , 0.50f , 1.00f ) ;
Colors [ ImGuiCol_Header ] = ImVec4 ( 0.40f , 0.40f , 0.90f , 0.45f ) ;
Colors [ ImGuiCol_HeaderHovered ] = ImVec4 ( 0.45f , 0.45f , 0.90f , 0.80f ) ;
2015-02-11 01:43:58 +08:00
Colors [ ImGuiCol_HeaderActive ] = ImVec4 ( 0.53f , 0.53f , 0.87f , 0.80f ) ;
2014-08-19 19:09:13 +08:00
Colors [ ImGuiCol_Column ] = ImVec4 ( 1.00f , 1.00f , 1.00f , 1.00f ) ;
Colors [ ImGuiCol_ColumnHovered ] = ImVec4 ( 0.60f , 0.40f , 0.40f , 1.00f ) ;
Colors [ ImGuiCol_ColumnActive ] = ImVec4 ( 0.80f , 0.50f , 0.50f , 1.00f ) ;
Colors [ ImGuiCol_ResizeGrip ] = ImVec4 ( 1.00f , 1.00f , 1.00f , 0.30f ) ;
Colors [ ImGuiCol_ResizeGripHovered ] = ImVec4 ( 1.00f , 1.00f , 1.00f , 0.60f ) ;
Colors [ ImGuiCol_ResizeGripActive ] = ImVec4 ( 1.00f , 1.00f , 1.00f , 0.90f ) ;
Colors [ ImGuiCol_CloseButton ] = ImVec4 ( 0.50f , 0.50f , 0.90f , 0.50f ) ;
Colors [ ImGuiCol_CloseButtonHovered ] = ImVec4 ( 0.70f , 0.70f , 0.90f , 0.60f ) ;
Colors [ ImGuiCol_CloseButtonActive ] = ImVec4 ( 0.70f , 0.70f , 0.70f , 1.00f ) ;
Colors [ ImGuiCol_PlotLines ] = ImVec4 ( 1.00f , 1.00f , 1.00f , 1.00f ) ;
Colors [ ImGuiCol_PlotLinesHovered ] = ImVec4 ( 0.90f , 0.70f , 0.00f , 1.00f ) ;
Colors [ ImGuiCol_PlotHistogram ] = ImVec4 ( 0.90f , 0.70f , 0.00f , 1.00f ) ;
Colors [ ImGuiCol_PlotHistogramHovered ] = ImVec4 ( 1.00f , 0.60f , 0.00f , 1.00f ) ;
Colors [ ImGuiCol_TextSelectedBg ] = ImVec4 ( 0.00f , 0.00f , 1.00f , 0.35f ) ;
Colors [ ImGuiCol_TooltipBg ] = ImVec4 ( 0.05f , 0.05f , 0.10f , 0.90f ) ;
2014-08-11 04:58:11 +08:00
}
2015-02-21 21:36:24 +08:00
// 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)
// Also we wouldn't be able to new() one at this point, before users may define IO.MemAllocFn.
2015-01-18 06:15:29 +08:00
static ImFontAtlas GDefaultFontAtlas ;
2015-01-12 02:27:05 +08:00
2014-08-11 04:58:11 +08:00
ImGuiIO : : ImGuiIO ( )
{
2015-02-01 02:55:05 +08:00
// Most fields are initialized with zero
2014-08-19 19:09:13 +08:00
memset ( this , 0 , sizeof ( * this ) ) ;
2015-02-01 02:55:05 +08:00
2014-12-22 09:45:13 +08:00
DisplaySize = ImVec2 ( - 1.0f , - 1.0f ) ;
2014-08-19 19:09:13 +08:00
DeltaTime = 1.0f / 60.0f ;
IniSavingRate = 5.0f ;
IniFilename = " imgui.ini " ;
LogFilename = " imgui_log.txt " ;
2015-01-18 18:46:49 +08:00
Fonts = & GDefaultFontAtlas ;
2014-11-29 08:02:46 +08:00
FontGlobalScale = 1.0f ;
2014-08-19 19:09:13 +08:00
MousePos = ImVec2 ( - 1 , - 1 ) ;
MousePosPrev = ImVec2 ( - 1 , - 1 ) ;
MouseDoubleClickTime = 0.30f ;
MouseDoubleClickMaxDist = 6.0f ;
2014-10-05 16:11:02 +08:00
UserData = NULL ;
2014-08-14 02:53:26 +08:00
2014-09-25 21:51:06 +08:00
// User functions
RenderDrawListsFn = NULL ;
2014-09-25 03:39:39 +08:00
MemAllocFn = malloc ;
MemFreeFn = free ;
2014-12-29 19:23:03 +08:00
GetClipboardTextFn = GetClipboardTextFn_DefaultImpl ; // Platform dependent default implementations
2014-08-19 19:09:13 +08:00
SetClipboardTextFn = SetClipboardTextFn_DefaultImpl ;
2014-09-25 21:51:06 +08:00
ImeSetInputScreenPosFn = NULL ;
2014-08-11 04:58:11 +08:00
}
// Pass in translated ASCII characters for text input.
// - with glfw you can get those from the callback set in glfwSetCharCallback()
2015-02-21 21:36:24 +08:00
// - on Windows you can get those using ToAscii+keyboard state, or via the WM_CHAR message
2014-09-25 21:51:06 +08:00
void ImGuiIO : : AddInputCharacter ( ImWchar c )
2014-08-11 04:58:11 +08:00
{
2014-09-25 21:51:06 +08:00
const size_t n = ImStrlenW ( InputCharacters ) ;
2014-10-07 19:15:59 +08:00
if ( n + 1 < sizeof ( InputCharacters ) / sizeof ( InputCharacters [ 0 ] ) )
2014-08-19 19:09:13 +08:00
{
InputCharacters [ n ] = c ;
InputCharacters [ n + 1 ] = 0 ;
}
2014-08-11 04:58:11 +08:00
}
//-----------------------------------------------------------------------------
// Helpers
//-----------------------------------------------------------------------------
2014-08-19 19:09:13 +08:00
# define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR) / sizeof(*_ARR)))
2014-08-11 04:58:11 +08:00
# undef PI
const float PI = 3.14159265358979323846f ;
2014-08-12 05:31:45 +08:00
# ifdef INT_MAX
# define IM_INT_MAX INT_MAX
# else
# define IM_INT_MAX 2147483647
# endif
2015-02-21 21:36:24 +08:00
// Play it nice with Windows users. Notepad in 2015 still doesn't display text data with Unix-style \n.
2014-12-30 04:41:27 +08:00
# ifdef _MSC_VER
2014-12-30 20:08:33 +08:00
# define STR_NEWLINE "\r\n"
2014-12-30 04:41:27 +08:00
# else
2014-12-30 20:08:33 +08:00
# define STR_NEWLINE "\n"
2014-12-30 04:41:27 +08:00
# endif
2014-08-11 04:58:11 +08:00
// Math bits
// We are keeping those static in the .cpp file so as not to leak them outside, in the case the user has implicit cast operators between ImVec2 and its own types.
2014-08-19 19:09:13 +08:00
static inline ImVec2 operator * ( const ImVec2 & lhs , const float rhs ) { return ImVec2 ( lhs . x * rhs , lhs . y * rhs ) ; }
2014-11-12 15:56:42 +08:00
//static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x/rhs, lhs.y/rhs); }
2014-08-19 19:09:13 +08:00
static inline ImVec2 operator + ( const ImVec2 & lhs , const ImVec2 & rhs ) { return ImVec2 ( lhs . x + rhs . x , lhs . y + rhs . y ) ; }
static inline ImVec2 operator - ( const ImVec2 & lhs , const ImVec2 & rhs ) { return ImVec2 ( lhs . x - rhs . x , lhs . y - rhs . y ) ; }
static inline ImVec2 operator * ( const ImVec2 & lhs , const ImVec2 rhs ) { return ImVec2 ( lhs . x * rhs . x , lhs . y * rhs . y ) ; }
static inline ImVec2 operator / ( const ImVec2 & lhs , const ImVec2 rhs ) { return ImVec2 ( lhs . x / rhs . x , lhs . y / rhs . y ) ; }
static inline ImVec2 & operator + = ( ImVec2 & lhs , const ImVec2 & rhs ) { lhs . x + = rhs . x ; lhs . y + = rhs . y ; return lhs ; }
static inline ImVec2 & operator - = ( ImVec2 & lhs , const ImVec2 & rhs ) { lhs . x - = rhs . x ; lhs . y - = rhs . y ; return lhs ; }
static inline ImVec2 & operator * = ( ImVec2 & lhs , const float rhs ) { lhs . x * = rhs ; lhs . y * = rhs ; return lhs ; }
2014-11-12 15:56:42 +08:00
//static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; }
2014-08-19 19:09:13 +08:00
static inline int ImMin ( int lhs , int rhs ) { return lhs < rhs ? lhs : rhs ; }
static inline int ImMax ( int lhs , int rhs ) { return lhs > = rhs ? lhs : rhs ; }
static inline float ImMin ( float lhs , float rhs ) { return lhs < rhs ? lhs : rhs ; }
static inline float ImMax ( float lhs , float rhs ) { return lhs > = rhs ? lhs : rhs ; }
static inline ImVec2 ImMin ( const ImVec2 & lhs , const ImVec2 & rhs ) { return ImVec2 ( ImMin ( lhs . x , rhs . x ) , ImMin ( lhs . y , rhs . y ) ) ; }
static inline ImVec2 ImMax ( const ImVec2 & lhs , const ImVec2 & rhs ) { return ImVec2 ( ImMax ( lhs . x , rhs . x ) , ImMax ( lhs . y , rhs . y ) ) ; }
2015-02-08 21:44:09 +08:00
static inline int ImClamp ( int v , int mn , int mx ) { return ( v < mn ) ? mn : ( v > mx ) ? mx : v ; }
static inline float ImClamp ( float v , float mn , float mx ) { return ( v < mn ) ? mn : ( v > mx ) ? mx : v ; }
2014-08-19 19:09:13 +08:00
static inline ImVec2 ImClamp ( const ImVec2 & f , const ImVec2 & mn , ImVec2 mx ) { return ImVec2 ( ImClamp ( f . x , mn . x , mx . x ) , ImClamp ( f . y , mn . y , mx . y ) ) ; }
static inline float ImSaturate ( float f ) { return ( f < 0.0f ) ? 0.0f : ( f > 1.0f ) ? 1.0f : f ; }
static inline float ImLerp ( float a , float b , float t ) { return a + ( b - a ) * t ; }
static inline ImVec2 ImLerp ( const ImVec2 & a , const ImVec2 & b , const ImVec2 & t ) { return ImVec2 ( a . x + ( b . x - a . x ) * t . x , a . y + ( b . y - a . y ) * t . y ) ; }
2014-12-29 19:23:03 +08:00
static inline float ImLengthSqr ( const ImVec2 & lhs ) { return lhs . x * lhs . x + lhs . y * lhs . y ; }
2014-09-25 18:29:59 +08:00
2014-08-11 04:58:11 +08:00
static int ImStricmp ( const char * str1 , const char * str2 )
{
2014-08-19 19:09:13 +08:00
int d ;
while ( ( d = toupper ( * str2 ) - toupper ( * str1 ) ) = = 0 & & * str1 ) { str1 + + ; str2 + + ; }
return d ;
2014-08-11 04:58:11 +08:00
}
2014-11-24 07:35:26 +08:00
static int ImStrnicmp ( const char * str1 , const char * str2 , int count )
{
2014-11-30 20:21:50 +08:00
int d = 0 ;
2014-11-24 07:35:26 +08:00
while ( count > 0 & & ( d = toupper ( * str2 ) - toupper ( * str1 ) ) = = 0 & & * str1 ) { str1 + + ; str2 + + ; count - - ; }
2014-11-30 20:31:43 +08:00
return d ;
2014-11-24 07:35:26 +08:00
}
2014-08-31 18:28:21 +08:00
static char * ImStrdup ( const char * str )
{
2014-09-25 01:01:07 +08:00
char * buff = ( char * ) ImGui : : MemAlloc ( strlen ( str ) + 1 ) ;
2014-08-31 18:28:21 +08:00
IM_ASSERT ( buff ) ;
strcpy ( buff , str ) ;
return buff ;
2014-08-11 04:58:11 +08:00
}
2014-09-25 21:51:06 +08:00
static size_t ImStrlenW ( const ImWchar * str )
{
size_t n = 0 ;
2015-02-21 21:36:24 +08:00
while ( * str + + ) n + + ;
2014-09-25 21:51:06 +08:00
return n ;
}
2014-08-11 04:58:11 +08:00
static const char * ImStristr ( const char * haystack , const char * needle , const char * needle_end )
{
2014-08-19 19:09:13 +08:00
if ( ! needle_end )
needle_end = needle + strlen ( needle ) ;
const char un0 = ( char ) toupper ( * needle ) ;
while ( * haystack )
{
if ( toupper ( * haystack ) = = un0 )
{
const char * b = needle + 1 ;
for ( const char * a = haystack + 1 ; b < needle_end ; a + + , b + + )
if ( toupper ( * a ) ! = toupper ( * b ) )
break ;
if ( b = = needle_end )
return haystack ;
}
haystack + + ;
}
return NULL ;
2014-08-11 04:58:11 +08:00
}
2014-12-30 23:18:21 +08:00
// Pass data_size==0 for zero-terminated string
2014-12-29 19:23:03 +08:00
static ImU32 ImCrc32 ( const void * data , size_t data_size , ImU32 seed = 0 )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
static ImU32 crc32_lut [ 256 ] = { 0 } ;
if ( ! crc32_lut [ 1 ] )
{
const ImU32 polynomial = 0xEDB88320 ;
for ( ImU32 i = 0 ; i < 256 ; i + + )
{
ImU32 crc = i ;
for ( ImU32 j = 0 ; j < 8 ; j + + )
2014-08-20 17:40:31 +08:00
crc = ( crc > > 1 ) ^ ( ImU32 ( - int ( crc & 1 ) ) & polynomial ) ;
2014-08-19 19:09:13 +08:00
crc32_lut [ i ] = crc ;
}
}
ImU32 crc = ~ seed ;
2014-12-30 23:18:21 +08:00
const unsigned char * current = ( const unsigned char * ) data ;
2014-12-30 23:38:28 +08:00
if ( data_size > 0 )
{
// Known size
while ( data_size - - )
crc = ( crc > > 8 ) ^ crc32_lut [ ( crc & 0xFF ) ^ * current + + ] ;
}
else
{
// Zero-terminated string
while ( unsigned char c = * current + + )
crc = ( crc > > 8 ) ^ crc32_lut [ ( crc & 0xFF ) ^ c ] ;
}
2014-08-19 19:09:13 +08:00
return ~ crc ;
2014-08-11 04:58:11 +08:00
}
static size_t ImFormatString ( char * buf , size_t buf_size , const char * fmt , . . . )
{
2014-08-19 19:09:13 +08:00
va_list args ;
va_start ( args , fmt ) ;
int w = vsnprintf ( buf , buf_size , fmt , args ) ;
va_end ( args ) ;
buf [ buf_size - 1 ] = 0 ;
2014-08-20 17:40:31 +08:00
return ( w = = - 1 ) ? buf_size : ( size_t ) w ;
2014-08-11 04:58:11 +08:00
}
static size_t ImFormatStringV ( char * buf , size_t buf_size , const char * fmt , va_list args )
{
2014-08-19 19:09:13 +08:00
int w = vsnprintf ( buf , buf_size , fmt , args ) ;
buf [ buf_size - 1 ] = 0 ;
2014-08-20 17:40:31 +08:00
return ( w = = - 1 ) ? buf_size : ( size_t ) w ;
2014-08-11 04:58:11 +08:00
}
2015-02-01 00:36:12 +08:00
ImU32 ImGui : : ColorConvertFloat4ToU32 ( const ImVec4 & in )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImU32 out = ( ( ImU32 ) ( ImSaturate ( in . x ) * 255.f ) ) ;
out | = ( ( ImU32 ) ( ImSaturate ( in . y ) * 255.f ) < < 8 ) ;
out | = ( ( ImU32 ) ( ImSaturate ( in . z ) * 255.f ) < < 16 ) ;
out | = ( ( ImU32 ) ( ImSaturate ( in . w ) * 255.f ) < < 24 ) ;
return out ;
2014-08-11 04:58:11 +08:00
}
// Convert rgb floats ([0-1],[0-1],[0-1]) to hsv floats ([0-1],[0-1],[0-1]), from Foley & van Dam p592
// Optimized http://lolengine.net/blog/2013/01/13/fast-rgb-to-hsv
2015-02-01 00:36:12 +08:00
void ImGui : : ColorConvertRGBtoHSV ( float r , float g , float b , float & out_h , float & out_s , float & out_v )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
float K = 0.f ;
if ( g < b )
{
const float tmp = g ; g = b ; b = tmp ;
K = - 1.f ;
}
if ( r < g )
{
const float tmp = r ; r = g ; g = tmp ;
K = - 2.f / 6.f - K ;
}
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
const float chroma = r - ( g < b ? g : b ) ;
out_h = fabsf ( K + ( g - b ) / ( 6.f * chroma + 1e-20 f ) ) ;
out_s = chroma / ( r + 1e-20 f ) ;
out_v = r ;
2014-08-11 04:58:11 +08:00
}
// Convert hsv floats ([0-1],[0-1],[0-1]) to rgb floats ([0-1],[0-1],[0-1]), from Foley & van Dam p593
// also http://en.wikipedia.org/wiki/HSL_and_HSV
2015-02-01 00:36:12 +08:00
void ImGui : : ColorConvertHSVtoRGB ( float h , float s , float v , float & out_r , float & out_g , float & out_b )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
if ( s = = 0.0f )
{
// gray
out_r = out_g = out_b = v ;
return ;
}
h = fmodf ( h , 1.0f ) / ( 60.0f / 360.0f ) ;
int i = ( int ) h ;
float f = h - ( float ) i ;
float p = v * ( 1.0f - s ) ;
float q = v * ( 1.0f - s * f ) ;
float t = v * ( 1.0f - s * ( 1.0f - f ) ) ;
switch ( i )
{
case 0 : out_r = v ; out_g = t ; out_b = p ; break ;
case 1 : out_r = q ; out_g = v ; out_b = p ; break ;
case 2 : out_r = p ; out_g = v ; out_b = t ; break ;
case 3 : out_r = p ; out_g = q ; out_b = v ; break ;
case 4 : out_r = t ; out_g = p ; out_b = v ; break ;
case 5 : default : out_r = v ; out_g = p ; out_b = q ; break ;
}
2014-08-11 04:58:11 +08:00
}
2014-12-29 19:23:03 +08:00
// Load file content into memory
// Memory allocated with ImGui::MemAlloc(), must be freed by user using ImGui::MemFree()
2014-12-30 02:05:22 +08:00
static bool ImLoadFileToMemory ( const char * filename , const char * file_open_mode , void * * out_file_data , size_t * out_file_size , size_t padding_bytes )
2014-12-29 19:23:03 +08:00
{
IM_ASSERT ( filename & & file_open_mode & & out_file_data & & out_file_size ) ;
2014-12-30 02:13:41 +08:00
IM_ASSERT ( padding_bytes > = 0 ) ;
2014-12-29 19:23:03 +08:00
* out_file_data = NULL ;
* out_file_size = 0 ;
FILE * f ;
if ( ( f = fopen ( filename , file_open_mode ) ) = = NULL )
return false ;
long file_size_signed ;
if ( fseek ( f , 0 , SEEK_END ) | | ( file_size_signed = ftell ( f ) ) = = - 1 | | fseek ( f , 0 , SEEK_SET ) )
{
fclose ( f ) ;
return false ;
}
size_t file_size = ( size_t ) file_size_signed ;
2014-12-30 02:05:22 +08:00
void * file_data = ImGui : : MemAlloc ( file_size + padding_bytes ) ;
2014-12-29 19:23:03 +08:00
if ( file_data = = NULL )
{
fclose ( f ) ;
return false ;
}
if ( fread ( file_data , 1 , file_size , f ) ! = file_size )
{
fclose ( f ) ;
ImGui : : MemFree ( file_data ) ;
return false ;
}
2014-12-30 02:13:41 +08:00
if ( padding_bytes > 0 )
memset ( ( void * ) ( ( ( char * ) file_data ) + file_size ) , 0 , padding_bytes ) ;
2014-12-29 19:23:03 +08:00
fclose ( f ) ;
* out_file_data = file_data ;
* out_file_size = file_size ;
return true ;
}
2014-08-11 04:58:11 +08:00
//-----------------------------------------------------------------------------
2014-11-07 16:22:38 +08:00
struct ImGuiColMod // Color modifier, backup of modified data so we can restore it
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiCol Col ;
ImVec4 PreviousValue ;
2014-08-11 04:58:11 +08:00
} ;
2014-11-07 16:22:38 +08:00
struct ImGuiStyleMod // Style modifier, backup of modified data so we can restore it
{
ImGuiStyleVar Var ;
ImVec2 PreviousValue ;
} ;
2015-02-21 21:36:24 +08:00
struct ImGuiAabb // 2D axis aligned bounding-box
2014-08-19 19:09:13 +08:00
{
ImVec2 Min ;
ImVec2 Max ;
ImGuiAabb ( ) { Min = ImVec2 ( FLT_MAX , FLT_MAX ) ; Max = ImVec2 ( - FLT_MAX , - FLT_MAX ) ; }
ImGuiAabb ( const ImVec2 & min , const ImVec2 & max ) { Min = min ; Max = max ; }
ImGuiAabb ( const ImVec4 & v ) { Min . x = v . x ; Min . y = v . y ; Max . x = v . z ; Max . y = v . w ; }
ImGuiAabb ( float x1 , float y1 , float x2 , float y2 ) { Min . x = x1 ; Min . y = y1 ; Max . x = x2 ; Max . y = y2 ; }
ImVec2 GetCenter ( ) const { return Min + ( Max - Min ) * 0.5f ; }
ImVec2 GetSize ( ) const { return Max - Min ; }
float GetWidth ( ) const { return ( Max - Min ) . x ; }
float GetHeight ( ) const { return ( Max - Min ) . y ; }
ImVec2 GetTL ( ) const { return Min ; }
ImVec2 GetTR ( ) const { return ImVec2 ( Max . x , Min . y ) ; }
ImVec2 GetBL ( ) const { return ImVec2 ( Min . x , Max . y ) ; }
ImVec2 GetBR ( ) const { return Max ; }
2014-12-30 19:41:46 +08:00
bool Contains ( const ImVec2 & p ) const { return p . x > = Min . x & & p . y > = Min . y & & p . x < = Max . x & & p . y < = Max . y ; }
2014-08-19 19:09:13 +08:00
bool Contains ( const ImGuiAabb & r ) const { return r . Min . x > = Min . x & & r . Min . y > = Min . y & & r . Max . x < = Max . x & & r . Max . y < = Max . y ; }
bool Overlaps ( const ImGuiAabb & r ) const { return r . Min . y < = Max . y & & r . Max . y > = Min . y & & r . Min . x < = Max . x & & r . Max . x > = Min . x ; }
2014-12-30 19:41:46 +08:00
void Add ( const ImVec2 & rhs ) { Min . x = ImMin ( Min . x , rhs . x ) ; Min . y = ImMin ( Min . y , rhs . y ) ; Max . x = ImMax ( Max . x , rhs . x ) ; Max . y = ImMax ( Max . x , rhs . x ) ; }
void Add ( const ImGuiAabb & rhs ) { Min . x = ImMin ( Min . x , rhs . Min . x ) ; Min . y = ImMin ( Min . y , rhs . Min . y ) ; Max . x = ImMax ( Max . x , rhs . Max . x ) ; Max . y = ImMax ( Max . y , rhs . Max . y ) ; }
void Expand ( const ImVec2 & sz ) { Min - = sz ; Max + = sz ; }
2014-08-19 19:09:13 +08:00
void Clip ( const ImGuiAabb & clip ) { Min . x = ImMax ( Min . x , clip . Min . x ) ; Min . y = ImMax ( Min . y , clip . Min . y ) ; Max . x = ImMin ( Max . x , clip . Max . x ) ; Max . y = ImMin ( Max . y , clip . Max . y ) ; }
2014-08-11 04:58:11 +08:00
} ;
// Temporary per-window data, reset at the beginning of the frame
struct ImGuiDrawContext
{
2014-08-19 19:09:13 +08:00
ImVec2 CursorPos ;
ImVec2 CursorPosPrevLine ;
ImVec2 CursorStartPos ;
float CurrentLineHeight ;
float PrevLineHeight ;
float LogLineHeight ;
int TreeDepth ;
2015-01-23 06:54:05 +08:00
ImGuiID LastItemID ;
2014-08-19 19:09:13 +08:00
ImGuiAabb LastItemAabb ;
bool LastItemHovered ;
ImVector < ImGuiWindow * > ChildWindows ;
ImVector < bool > AllowKeyboardFocus ;
2015-02-11 05:07:26 +08:00
ImVector < float > ItemWidth ; // 0.0: default, >0.0: width in pixels, <0.0: align xx pixels to the right of window
2014-11-07 13:45:56 +08:00
ImVector < float > TextWrapPos ;
2014-08-19 19:09:13 +08:00
ImGuiColorEditMode ColorEditMode ;
ImGuiStorage * StateStorage ;
2015-02-11 05:07:26 +08:00
int OpenNextNode ; // FIXME: Reformulate this feature like SetNextWindowCollapsed() API
2014-08-19 19:09:13 +08:00
2014-11-20 19:31:55 +08:00
float ColumnsStartX ; // Start position from left of window (increased by TreePush/TreePop, etc.)
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.
int ColumnsCurrent ;
2014-08-19 19:09:13 +08:00
int ColumnsCount ;
2014-11-20 19:31:55 +08:00
ImVec2 ColumnsStartPos ;
float ColumnsCellMinY ;
float ColumnsCellMaxY ;
2014-08-19 19:09:13 +08:00
bool ColumnsShowBorders ;
ImGuiID ColumnsSetID ;
2015-02-11 19:50:24 +08:00
ImVector < float > ColumnsOffsetsT ; // Columns offset normalized 0.0 (far left) -> 1.0 (far right)
2014-08-19 19:09:13 +08:00
ImGuiDrawContext ( )
{
CursorPos = CursorPosPrevLine = CursorStartPos = ImVec2 ( 0.0f , 0.0f ) ;
CurrentLineHeight = PrevLineHeight = 0.0f ;
LogLineHeight = - 1.0f ;
TreeDepth = 0 ;
2015-01-23 06:54:05 +08:00
LastItemID = 0 ;
2014-08-19 19:09:13 +08:00
LastItemAabb = ImGuiAabb ( 0.0f , 0.0f , 0.0f , 0.0f ) ;
LastItemHovered = false ;
StateStorage = NULL ;
OpenNextNode = - 1 ;
2014-11-20 19:31:55 +08:00
ColumnsStartX = 0.0f ;
ColumnsOffsetX = 0.0f ;
ColumnsCurrent = 0 ;
2014-08-19 19:09:13 +08:00
ColumnsCount = 1 ;
2014-11-20 19:31:55 +08:00
ColumnsStartPos = ImVec2 ( 0.0f , 0.0f ) ;
ColumnsCellMinY = ColumnsCellMaxY = 0.0f ;
2014-08-19 19:09:13 +08:00
ColumnsShowBorders = true ;
2014-11-20 19:31:55 +08:00
ColumnsSetID = 0 ;
2014-08-19 19:09:13 +08:00
}
2014-08-11 04:58:11 +08:00
} ;
2014-11-24 07:35:26 +08:00
// Internal state of the currently focused/edited text input box
2014-08-11 04:58:11 +08:00
struct ImGuiTextEditState
{
2015-02-22 00:30:40 +08:00
ImGuiID Id ; // widget id owning the text state
2014-09-25 21:51:06 +08:00
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.
char InitialText [ 1024 * 3 + 1 ] ; // backup of end-user buffer at the time of focus (in UTF-8, unconverted)
2014-08-19 19:09:13 +08:00
size_t BufSize ; // end-user buffer size, <= 1024 (or increase above)
float Width ; // widget width
float ScrollX ;
STB_TexteditState StbState ;
float CursorAnim ;
2015-02-21 21:36:24 +08:00
ImVec2 InputCursorScreenPos ; // Cursor position in screen space to be used by IME callback.
2014-08-19 19:09:13 +08:00
bool SelectedAllMouseLock ;
2014-11-29 06:38:41 +08:00
ImFont * Font ;
2014-08-19 19:09:13 +08:00
float FontSize ;
ImGuiTextEditState ( ) { memset ( this , 0 , sizeof ( * this ) ) ; }
void CursorAnimReset ( ) { CursorAnim = - 0.30f ; } // After a user-input the cursor stays on for a while without blinking
bool CursorIsVisible ( ) const { return CursorAnim < = 0.0f | | fmodf ( CursorAnim , 1.20f ) < = 0.80f ; } // Blinking
bool HasSelection ( ) const { return StbState . select_start ! = StbState . select_end ; }
2014-09-25 21:51:06 +08:00
void SelectAll ( ) { StbState . select_start = 0 ; StbState . select_end = ( int ) ImStrlenW ( Text ) ; StbState . cursor = StbState . select_end ; StbState . has_preferred_x = false ; }
2014-08-19 19:09:13 +08:00
2014-11-24 18:02:39 +08:00
void OnKeyPressed ( int key ) ;
2014-08-19 19:09:13 +08:00
void UpdateScrollOffset ( ) ;
ImVec2 CalcDisplayOffsetFromCharIdx ( int i ) const ;
// Static functions because they are used to render non-focused instances of a text input box
2014-11-29 06:38:41 +08:00
static const char * GetTextPointerClippedA ( ImFont * font , float font_size , const char * text , float width , ImVec2 * out_text_size = NULL ) ;
static const ImWchar * GetTextPointerClippedW ( ImFont * font , float font_size , const ImWchar * text , float width , ImVec2 * out_text_size = NULL ) ;
static void RenderTextScrolledClipped ( ImFont * font , float font_size , const char * text , ImVec2 pos_base , float width , float scroll_x ) ;
2014-08-11 04:58:11 +08:00
} ;
2015-02-12 02:14:39 +08:00
// Data saved in imgui.ini file
2014-08-11 04:58:11 +08:00
struct ImGuiIniData
{
2014-08-19 19:09:13 +08:00
char * Name ;
ImVec2 Pos ;
ImVec2 Size ;
bool Collapsed ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
ImGuiIniData ( ) { memset ( this , 0 , sizeof ( * this ) ) ; }
2014-09-25 01:01:07 +08:00
~ ImGuiIniData ( ) { if ( Name ) { ImGui : : MemFree ( Name ) ; Name = NULL ; } }
2014-08-11 04:58:11 +08:00
} ;
2015-02-12 02:14:39 +08:00
// Main state for ImGui
2014-08-11 04:58:11 +08:00
struct ImGuiState
{
2014-08-19 19:09:13 +08:00
bool Initialized ;
ImGuiIO IO ;
ImGuiStyle Style ;
2015-01-17 21:40:56 +08:00
ImFont * Font ; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back()
2015-01-17 23:44:25 +08:00
float FontSize ; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Size of characters.
2015-01-17 21:40:56 +08:00
ImVec2 FontTexUvWhitePixel ; // (Shortcut) == Font->TexUvForWhite
2014-08-31 01:43:26 +08:00
2014-08-19 19:09:13 +08:00
float Time ;
int FrameCount ;
int FrameCountRendered ;
ImVector < ImGuiWindow * > Windows ;
ImGuiWindow * CurrentWindow ; // Being drawn into
ImVector < ImGuiWindow * > CurrentWindowStack ;
ImGuiWindow * FocusedWindow ; // Will catch keyboard inputs
ImGuiWindow * HoveredWindow ; // Will catch mouse inputs
2014-12-04 00:54:04 +08:00
ImGuiWindow * HoveredRootWindow ; // Will catch mouse inputs (for focus/move only)
2014-08-19 19:09:13 +08:00
ImGuiID HoveredId ;
ImGuiID ActiveId ;
ImGuiID ActiveIdPreviousFrame ;
bool ActiveIdIsAlive ;
2015-02-21 20:49:51 +08:00
bool ActiveIdIsFocusedOnly ; // Set only by active widget. Denote focus but no active interaction.
2014-08-19 19:09:13 +08:00
float SettingsDirtyTimer ;
ImVector < ImGuiIniData * > Settings ;
2014-11-21 21:23:22 +08:00
ImVector < ImGuiColMod > ColorModifiers ;
ImVector < ImGuiStyleMod > StyleModifiers ;
2015-01-17 21:40:56 +08:00
ImVector < ImFont * > FontStack ;
2014-12-11 03:22:30 +08:00
ImVec2 SetNextWindowPosVal ;
ImGuiSetCondition SetNextWindowPosCond ;
ImVec2 SetNextWindowSizeVal ;
ImGuiSetCondition SetNextWindowSizeCond ;
bool SetNextWindowCollapsedVal ;
ImGuiSetCondition SetNextWindowCollapsedCond ;
2014-08-19 19:09:13 +08:00
// Render
ImVector < ImDrawList * > RenderDrawLists ;
2015-02-01 22:42:09 +08:00
ImVector < ImGuiWindow * > RenderSortedWindows ;
2014-08-19 19:09:13 +08:00
// Widget state
ImGuiTextEditState InputTextState ;
ImGuiID SliderAsInputTextId ;
ImGuiStorage ColorEditModeStorage ; // for user selection
ImGuiID ActiveComboID ;
char Tooltip [ 1024 ] ;
char * PrivateClipboard ; // if no custom clipboard handler is defined
// Logging
bool LogEnabled ;
FILE * LogFile ;
2014-09-25 03:39:39 +08:00
ImGuiTextBuffer * LogClipboard ; // pointer so our GImGui static constructor doesn't call heap allocators.
2014-12-30 04:18:52 +08:00
int LogStartDepth ;
2014-08-19 19:09:13 +08:00
int LogAutoExpandMaxDepth ;
2015-02-12 02:28:17 +08:00
// Misc
float FramerateSecPerFrame [ 120 ] ; // calculate estimate of framerate for user
int FramerateSecPerFrameIdx ;
float FramerateSecPerFrameAccum ;
2014-08-19 19:09:13 +08:00
ImGuiState ( )
{
Initialized = false ;
2015-02-21 19:49:12 +08:00
Font = NULL ;
FontSize = 0.0f ;
FontTexUvWhitePixel = ImVec2 ( 0.0f , 0.0f ) ;
2014-08-19 19:09:13 +08:00
Time = 0.0f ;
FrameCount = 0 ;
FrameCountRendered = - 1 ;
CurrentWindow = NULL ;
FocusedWindow = NULL ;
HoveredWindow = NULL ;
2014-12-04 00:54:04 +08:00
HoveredRootWindow = NULL ;
2015-02-21 19:49:12 +08:00
HoveredId = 0 ;
ActiveId = 0 ;
ActiveIdPreviousFrame = 0 ;
2014-08-19 19:09:13 +08:00
ActiveIdIsAlive = false ;
2015-02-21 20:49:51 +08:00
ActiveIdIsFocusedOnly = false ;
2014-08-19 19:09:13 +08:00
SettingsDirtyTimer = 0.0f ;
2014-12-11 03:22:30 +08:00
SetNextWindowPosVal = ImVec2 ( 0.0f , 0.0f ) ;
SetNextWindowPosCond = 0 ;
SetNextWindowSizeVal = ImVec2 ( 0.0f , 0.0f ) ;
SetNextWindowSizeCond = 0 ;
SetNextWindowCollapsedVal = false ;
SetNextWindowCollapsedCond = 0 ;
2015-02-21 19:49:12 +08:00
2014-08-19 19:09:13 +08:00
SliderAsInputTextId = 0 ;
ActiveComboID = 0 ;
memset ( Tooltip , 0 , sizeof ( Tooltip ) ) ;
PrivateClipboard = NULL ;
2015-02-21 19:49:12 +08:00
2014-08-19 19:09:13 +08:00
LogEnabled = false ;
LogFile = NULL ;
2015-02-21 19:49:12 +08:00
LogClipboard = NULL ;
2014-12-30 04:18:52 +08:00
LogStartDepth = 0 ;
2014-08-16 16:28:29 +08:00
LogAutoExpandMaxDepth = 2 ;
2015-02-21 19:49:12 +08:00
memset ( FramerateSecPerFrame , 0 , sizeof ( FramerateSecPerFrame ) ) ;
FramerateSecPerFrameIdx = 0 ;
FramerateSecPerFrameAccum = 0.0f ;
2014-08-19 19:09:13 +08:00
}
2014-08-11 04:58:11 +08:00
} ;
2015-02-04 16:43:11 +08:00
static ImGuiState GImDefaultState ; // Internal state storage
static ImGuiState * GImGui = & GImDefaultState ; // We access everything through this pointer. NB: this pointer is always assumed to be != NULL
2014-08-11 04:58:11 +08:00
struct ImGuiWindow
{
2014-08-19 19:09:13 +08:00
char * Name ;
ImGuiID ID ;
ImGuiWindowFlags Flags ;
ImVec2 PosFloat ;
ImVec2 Pos ; // Position rounded-up to nearest pixel
ImVec2 Size ; // Current size (==SizeFull or collapsed title bar size)
ImVec2 SizeFull ; // Size when non collapsed
ImVec2 SizeContentsFit ; // Size of contents (extents reach by the drawing cursor) - may not fit within Size.
float ScrollY ;
float NextScrollY ;
bool ScrollbarY ;
bool Visible ; // Set to true on Begin()
bool Accessed ; // Set to true when any widget access the current window
bool Collapsed ; // Set when collapsing window to become only title-bar
bool SkipItems ; // == Visible && !Collapsed
int AutoFitFrames ;
2014-11-22 00:29:56 +08:00
bool AutoFitOnlyGrows ;
2014-12-11 03:22:30 +08:00
int SetWindowPosAllowFlags ; // bit ImGuiSetCondition_*** specify if SetWindowPos() call is allowed with this particular flag.
int SetWindowSizeAllowFlags ; // bit ImGuiSetCondition_*** specify if SetWindowSize() call is allowed with this particular flag.
int SetWindowCollapsedAllowFlags ; // bit ImGuiSetCondition_*** specify if SetWindowCollapsed() call is allowed with this particular flag.
2014-08-19 19:09:13 +08:00
ImGuiDrawContext DC ;
ImVector < ImGuiID > IDStack ;
2015-02-03 03:50:28 +08:00
ImVector < ImVec4 > ClipRectStack ; // Scissoring / clipping rectangle. x1, y1, x2, y2.
2015-02-22 20:05:38 +08:00
ImGuiAabb ClippedAabb ; // = ClipRectStack.front() after setup in Begin()
2014-08-19 19:09:13 +08:00
int LastFrameDrawn ;
float ItemWidthDefault ;
ImGuiStorage StateStorage ;
2014-12-04 00:54:04 +08:00
float FontWindowScale ; // Scale multiplier per-window
2014-09-30 19:31:35 +08:00
ImDrawList * DrawList ;
2014-12-04 00:54:04 +08:00
ImGuiWindow * RootWindow ;
2014-08-19 19:09:13 +08:00
2014-09-30 19:31:35 +08:00
// Focus
2014-09-30 19:22:58 +08:00
int FocusIdxAllCounter ; // Start at -1 and increase as assigned via FocusItemRegister()
2014-09-30 19:31:35 +08:00
int FocusIdxTabCounter ; // (same, but only count widgets which you can Tab through)
int FocusIdxAllRequestCurrent ; // Item being requested for focus
int FocusIdxTabRequestCurrent ; // Tab-able item being requested for focus
int FocusIdxAllRequestNext ; // Item being requested for focus, for next update (relies on layout to be stable between the frame pressing TAB and the next frame)
int FocusIdxTabRequestNext ; // "
2014-08-11 04:58:11 +08:00
public :
2014-12-11 03:22:30 +08:00
ImGuiWindow ( const char * name ) ;
2014-08-19 19:09:13 +08:00
~ ImGuiWindow ( ) ;
ImGuiID GetID ( const char * str ) ;
ImGuiID GetID ( const void * ptr ) ;
void AddToRenderList ( ) ;
2014-11-24 07:35:26 +08:00
bool FocusItemRegister ( bool is_active , bool tab_stop = true ) ; // Return true if focus is requested
2014-08-19 19:09:13 +08:00
void FocusItemUnregister ( ) ;
ImGuiAabb Aabb ( ) const { return ImGuiAabb ( Pos , Pos + Size ) ; }
2015-02-01 12:28:24 +08:00
ImFont * Font ( ) const { return GImGui - > Font ; }
float FontSize ( ) const { return GImGui - > FontSize * FontWindowScale ; }
2014-08-19 19:09:13 +08:00
ImVec2 CursorPos ( ) const { return DC . CursorPos ; }
2015-02-01 12:28:24 +08:00
float TitleBarHeight ( ) const { return ( Flags & ImGuiWindowFlags_NoTitleBar ) ? 0 : FontSize ( ) + GImGui - > Style . FramePadding . y * 2.0f ; }
2014-08-19 19:09:13 +08:00
ImGuiAabb TitleBarAabb ( ) const { return ImGuiAabb ( Pos , Pos + ImVec2 ( SizeFull . x , TitleBarHeight ( ) ) ) ; }
2015-02-22 22:34:34 +08:00
ImVec2 WindowPadding ( ) const { return ( ( Flags & ImGuiWindowFlags_ChildWindow ) & & ! ( Flags & ImGuiWindowFlags_ShowBorders ) ) ? ImVec2 ( 0 , 0 ) : GImGui - > Style . WindowPadding ; }
2015-02-01 12:28:24 +08:00
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 ) ; }
ImU32 Color ( const ImVec4 & col ) const { ImVec4 c = col ; c . w * = GImGui - > Style . Alpha ; return ImGui : : ColorConvertFloat4ToU32 ( c ) ; }
2014-08-11 04:58:11 +08:00
} ;
2015-02-21 18:27:13 +08:00
static inline ImGuiWindow * GetCurrentWindow ( )
2014-08-11 04:58:11 +08:00
{
2015-02-04 16:43:11 +08:00
ImGuiState & g = * GImGui ;
IM_ASSERT ( g . CurrentWindow ! = NULL ) ; // ImGui::NewFrame() hasn't been called yet?
g . CurrentWindow - > Accessed = true ;
return g . CurrentWindow ;
2014-08-11 04:58:11 +08:00
}
2015-02-01 06:57:59 +08:00
static void SetActiveId ( ImGuiID id )
{
2015-02-04 16:43:11 +08:00
ImGuiState & g = * GImGui ;
g . ActiveId = id ;
2015-02-21 20:49:51 +08:00
g . ActiveIdIsFocusedOnly = false ;
2015-02-01 06:57:59 +08:00
}
2014-08-11 04:58:11 +08:00
static void RegisterAliveId ( const ImGuiID & id )
{
2015-02-04 16:43:11 +08:00
ImGuiState & g = * GImGui ;
if ( g . ActiveId = = id )
g . ActiveIdIsAlive = true ;
2014-08-11 04:58:11 +08:00
}
//-----------------------------------------------------------------------------
2014-08-26 00:19:04 +08:00
// Helper: Key->value storage
2014-08-11 04:58:11 +08:00
void ImGuiStorage : : Clear ( )
{
2014-08-19 19:09:13 +08:00
Data . clear ( ) ;
2014-08-11 04:58:11 +08:00
}
// std::lower_bound but without the bullshit
static ImVector < ImGuiStorage : : Pair > : : iterator LowerBound ( ImVector < ImGuiStorage : : Pair > & data , ImU32 key )
{
2014-08-19 19:09:13 +08:00
ImVector < ImGuiStorage : : Pair > : : iterator first = data . begin ( ) ;
ImVector < ImGuiStorage : : Pair > : : iterator last = data . end ( ) ;
int count = ( int ) ( last - first ) ;
while ( count > 0 )
{
int count2 = count / 2 ;
ImVector < ImGuiStorage : : Pair > : : iterator mid = first + count2 ;
if ( mid - > key < key )
{
first = + + mid ;
count - = count2 + 1 ;
}
else
{
count = count2 ;
}
}
return first ;
2014-08-11 04:58:11 +08:00
}
2014-12-09 01:14:54 +08:00
int ImGuiStorage : : GetInt ( ImU32 key , int default_val ) const
2014-08-11 04:58:11 +08:00
{
2014-12-09 01:14:54 +08:00
ImVector < Pair > : : iterator it = LowerBound ( const_cast < ImVector < ImGuiStorage : : Pair > & > ( Data ) , key ) ;
if ( it = = Data . end ( ) | | it - > key ! = key )
return default_val ;
return it - > val_i ;
2014-08-11 04:58:11 +08:00
}
2014-12-09 01:14:54 +08:00
float ImGuiStorage : : GetFloat ( ImU32 key , float default_val ) const
2014-08-11 04:58:11 +08:00
{
2014-12-09 01:14:54 +08:00
ImVector < Pair > : : iterator it = LowerBound ( const_cast < ImVector < ImGuiStorage : : Pair > & > ( Data ) , key ) ;
if ( it = = Data . end ( ) | | it - > key ! = key )
2014-08-19 19:09:13 +08:00
return default_val ;
2014-12-09 01:14:54 +08:00
return it - > val_f ;
2014-08-11 04:58:11 +08:00
}
2015-01-29 17:22:32 +08:00
void * ImGuiStorage : : GetVoidPtr ( ImGuiID key ) const
2014-12-09 01:14:54 +08:00
{
2015-01-29 17:22:32 +08:00
ImVector < Pair > : : iterator it = LowerBound ( const_cast < ImVector < ImGuiStorage : : Pair > & > ( Data ) , key ) ;
2014-12-09 01:14:54 +08:00
if ( it = = Data . end ( ) | | it - > key ! = key )
2015-01-29 17:22:32 +08:00
return NULL ;
return it - > val_p ;
2014-12-09 01:14:54 +08:00
}
2015-01-29 17:22:32 +08:00
// 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.
int * ImGuiStorage : : GetIntRef ( ImGuiID key , int default_val )
2014-12-09 01:14:54 +08:00
{
ImVector < Pair > : : iterator it = LowerBound ( Data , key ) ;
if ( it = = Data . end ( ) | | it - > key ! = key )
it = Data . insert ( it , Pair ( key , default_val ) ) ;
2015-01-29 17:22:32 +08:00
return & it - > val_i ;
2014-12-09 01:14:54 +08:00
}
2015-01-29 17:22:32 +08:00
float * ImGuiStorage : : GetFloatRef ( ImGuiID key , float default_val )
2015-01-29 04:31:22 +08:00
{
ImVector < Pair > : : iterator it = LowerBound ( Data , key ) ;
if ( it = = Data . end ( ) | | it - > key ! = key )
2015-01-29 17:22:32 +08:00
it = Data . insert ( it , Pair ( key , default_val ) ) ;
return & it - > val_f ;
2015-01-29 04:31:22 +08:00
}
2014-12-09 01:14:54 +08:00
// FIXME-OPT: Wasting CPU because all SetInt() are preceeded by GetInt() calls so we should have the result from lower_bound already in place.
2014-08-11 04:58:11 +08:00
// However we only use SetInt() on explicit user action (so that's maximum once a frame) so the optimisation isn't much needed.
void ImGuiStorage : : SetInt ( ImU32 key , int val )
{
2014-08-19 19:09:13 +08:00
ImVector < Pair > : : iterator it = LowerBound ( Data , key ) ;
2014-12-09 01:14:54 +08:00
if ( it = = Data . end ( ) | | it - > key ! = key )
2014-08-19 19:09:13 +08:00
{
2014-12-09 01:14:54 +08:00
Data . insert ( it , Pair ( key , val ) ) ;
return ;
2014-08-19 19:09:13 +08:00
}
2014-12-09 01:14:54 +08:00
it - > val_i = val ;
}
void ImGuiStorage : : SetFloat ( ImU32 key , float val )
{
ImVector < Pair > : : iterator it = LowerBound ( Data , key ) ;
if ( it = = Data . end ( ) | | it - > key ! = key )
2014-08-19 19:09:13 +08:00
{
2014-12-09 01:14:54 +08:00
Data . insert ( it , Pair ( key , val ) ) ;
return ;
2014-08-19 19:09:13 +08:00
}
2014-12-09 01:14:54 +08:00
it - > val_f = val ;
2014-08-11 04:58:11 +08:00
}
2015-01-29 04:31:22 +08:00
void ImGuiStorage : : SetVoidPtr ( ImU32 key , void * val )
{
ImVector < Pair > : : iterator it = LowerBound ( Data , key ) ;
if ( it = = Data . end ( ) | | it - > key ! = key )
{
Data . insert ( it , Pair ( key , val ) ) ;
return ;
}
it - > val_p = val ;
}
2014-08-11 04:58:11 +08:00
void ImGuiStorage : : SetAllInt ( int v )
{
2014-08-19 19:09:13 +08:00
for ( size_t i = 0 ; i < Data . size ( ) ; i + + )
2014-12-09 01:14:54 +08:00
Data [ i ] . val_i = v ;
2014-08-11 04:58:11 +08:00
}
//-----------------------------------------------------------------------------
2014-08-26 00:19:04 +08:00
// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
2015-02-15 21:50:04 +08:00
ImGuiTextFilter : : ImGuiTextFilter ( const char * default_filter )
2014-08-11 04:58:11 +08:00
{
2015-02-15 21:50:04 +08:00
if ( default_filter )
{
ImFormatString ( InputBuf , IM_ARRAYSIZE ( InputBuf ) , " %s " , default_filter ) ;
Build ( ) ;
}
else
{
InputBuf [ 0 ] = 0 ;
CountGrep = 0 ;
}
2014-08-11 04:58:11 +08:00
}
void ImGuiTextFilter : : Draw ( const char * label , float width )
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2015-02-13 03:34:14 +08:00
if ( width > 0.0f )
ImGui : : PushItemWidth ( width ) ;
2014-08-19 19:09:13 +08:00
ImGui : : InputText ( label , InputBuf , IM_ARRAYSIZE ( InputBuf ) ) ;
2015-02-13 03:34:14 +08:00
if ( width > 0.0f )
ImGui : : PopItemWidth ( ) ;
2014-08-19 19:09:13 +08:00
Build ( ) ;
2014-08-11 04:58:11 +08:00
}
void ImGuiTextFilter : : TextRange : : split ( char separator , ImVector < TextRange > & out )
{
2014-08-19 19:09:13 +08:00
out . resize ( 0 ) ;
const char * wb = b ;
const char * we = wb ;
while ( we < e )
{
if ( * we = = separator )
{
out . push_back ( TextRange ( wb , we ) ) ;
wb = we + 1 ;
}
we + + ;
}
if ( wb ! = we )
out . push_back ( TextRange ( wb , we ) ) ;
2014-08-11 04:58:11 +08:00
}
void ImGuiTextFilter : : Build ( )
{
2014-08-19 19:09:13 +08:00
Filters . resize ( 0 ) ;
TextRange input_range ( InputBuf , InputBuf + strlen ( InputBuf ) ) ;
input_range . split ( ' , ' , Filters ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
CountGrep = 0 ;
for ( size_t i = 0 ; i ! = Filters . size ( ) ; i + + )
{
Filters [ i ] . trim_blanks ( ) ;
if ( Filters [ i ] . empty ( ) )
continue ;
if ( Filters [ i ] . front ( ) ! = ' - ' )
CountGrep + = 1 ;
}
2014-08-11 04:58:11 +08:00
}
bool ImGuiTextFilter : : PassFilter ( const char * val ) const
{
2014-08-19 19:09:13 +08:00
if ( Filters . empty ( ) )
return true ;
if ( val = = NULL )
val = " " ;
for ( size_t i = 0 ; i ! = Filters . size ( ) ; i + + )
{
const TextRange & f = Filters [ i ] ;
if ( f . empty ( ) )
continue ;
if ( f . front ( ) = = ' - ' )
{
// Subtract
if ( ImStristr ( val , f . begin ( ) + 1 , f . end ( ) ) ! = NULL )
return false ;
}
else
{
// Grep
if ( ImStristr ( val , f . begin ( ) , f . end ( ) ) ! = NULL )
return true ;
}
}
// Implicit * grep
if ( CountGrep = = 0 )
return true ;
return false ;
2014-08-11 04:58:11 +08:00
}
//-----------------------------------------------------------------------------
2015-01-14 21:01:53 +08:00
// On some platform vsnprintf() takes va_list by reference and modifies it.
// va_copy is the 'correct' way to copy a va_list but Visual Studio prior to 2013 doesn't have it.
# ifndef va_copy
# define va_copy(dest, src) (dest = src)
# endif
2014-08-26 00:19:04 +08:00
// Helper: Text buffer for logging/accumulating text
2014-12-30 04:18:52 +08:00
void ImGuiTextBuffer : : appendv ( const char * fmt , va_list args )
2014-08-11 04:58:11 +08:00
{
2015-01-14 21:01:53 +08:00
va_list args_copy ;
va_copy ( args_copy , args ) ;
2014-12-30 04:18:52 +08:00
int len = vsnprintf ( NULL , 0 , fmt , args ) ; // FIXME-OPT: could do a first pass write attempt, likely successful on first pass.
2014-08-19 19:09:13 +08:00
if ( len < = 0 )
return ;
2015-01-14 21:04:33 +08:00
2014-08-19 19:09:13 +08:00
const size_t write_off = Buf . size ( ) ;
2015-01-14 21:04:33 +08:00
const size_t needed_sz = write_off + ( size_t ) len ;
2014-08-20 17:40:31 +08:00
if ( write_off + ( size_t ) len > = Buf . capacity ( ) )
2015-01-14 21:04:33 +08:00
{
const size_t double_capacity = Buf . capacity ( ) * 2 ;
Buf . reserve ( needed_sz > double_capacity ? needed_sz : double_capacity ) ;
}
2014-08-11 04:58:11 +08:00
2015-01-14 21:04:33 +08:00
Buf . resize ( needed_sz ) ;
2015-01-14 21:01:53 +08:00
ImFormatStringV ( & Buf [ write_off ] - 1 , ( size_t ) len + 1 , fmt , args_copy ) ;
2014-12-30 04:18:52 +08:00
}
2014-08-11 04:58:11 +08:00
2014-12-30 04:18:52 +08:00
void ImGuiTextBuffer : : append ( const char * fmt , . . . )
{
va_list args ;
2014-08-19 19:09:13 +08:00
va_start ( args , fmt ) ;
2014-12-30 04:18:52 +08:00
appendv ( fmt , args ) ;
2014-08-19 19:09:13 +08:00
va_end ( args ) ;
2014-08-11 04:58:11 +08:00
}
//-----------------------------------------------------------------------------
2014-12-11 03:22:30 +08:00
ImGuiWindow : : ImGuiWindow ( const char * name )
2014-08-11 04:58:11 +08:00
{
2014-08-31 18:28:21 +08:00
Name = ImStrdup ( name ) ;
2014-08-19 19:09:13 +08:00
ID = GetID ( name ) ;
2015-02-22 20:05:38 +08:00
Flags = 0 ;
2014-12-11 03:22:30 +08:00
PosFloat = Pos = ImVec2 ( 0.0f , 0.0f ) ;
Size = SizeFull = ImVec2 ( 0.0f , 0.0f ) ;
2014-08-19 19:09:13 +08:00
SizeContentsFit = ImVec2 ( 0.0f , 0.0f ) ;
ScrollY = 0.0f ;
NextScrollY = 0.0f ;
ScrollbarY = false ;
Visible = false ;
Accessed = false ;
Collapsed = false ;
SkipItems = false ;
AutoFitFrames = - 1 ;
2014-11-22 00:29:56 +08:00
AutoFitOnlyGrows = false ;
2014-12-11 03:22:30 +08:00
SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiSetCondition_Always | ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver ;
2015-02-22 20:05:38 +08:00
IDStack . push_back ( ID ) ;
2014-08-19 19:09:13 +08:00
LastFrameDrawn = - 1 ;
ItemWidthDefault = 0.0f ;
2014-09-24 21:03:42 +08:00
FontWindowScale = 1.0f ;
2014-08-11 04:58:11 +08:00
2014-12-29 19:23:03 +08:00
if ( ImLengthSqr ( Size ) < 0.00001f )
2014-11-22 00:29:56 +08:00
{
2014-10-27 04:07:15 +08:00
AutoFitFrames = 2 ;
2014-11-22 00:29:56 +08:00
AutoFitOnlyGrows = true ;
}
2014-08-11 04:58:11 +08:00
2014-09-30 19:31:35 +08:00
DrawList = ( ImDrawList * ) ImGui : : MemAlloc ( sizeof ( ImDrawList ) ) ;
new ( DrawList ) ImDrawList ( ) ;
2015-02-22 20:05:38 +08:00
RootWindow = NULL ;
2014-09-30 19:31:35 +08:00
2014-09-30 19:22:58 +08:00
FocusIdxAllCounter = FocusIdxTabCounter = - 1 ;
FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = IM_INT_MAX ;
FocusIdxAllRequestNext = FocusIdxTabRequestNext = IM_INT_MAX ;
2014-08-11 04:58:11 +08:00
}
ImGuiWindow : : ~ ImGuiWindow ( )
{
2014-08-16 16:28:29 +08:00
DrawList - > ~ ImDrawList ( ) ;
2014-09-25 01:01:07 +08:00
ImGui : : MemFree ( DrawList ) ;
2014-08-19 19:09:13 +08:00
DrawList = NULL ;
2014-09-25 01:01:07 +08:00
ImGui : : MemFree ( Name ) ;
2014-08-19 19:09:13 +08:00
Name = NULL ;
2014-08-11 04:58:11 +08:00
}
ImGuiID ImGuiWindow : : GetID ( const char * str )
{
2014-08-19 19:09:13 +08:00
const ImGuiID seed = IDStack . empty ( ) ? 0 : IDStack . back ( ) ;
2014-12-30 23:18:21 +08:00
const ImGuiID id = ImCrc32 ( str , 0 , seed ) ;
2014-08-19 19:09:13 +08:00
RegisterAliveId ( id ) ;
return id ;
2014-08-11 04:58:11 +08:00
}
ImGuiID ImGuiWindow : : GetID ( const void * ptr )
{
2014-08-19 19:09:13 +08:00
const ImGuiID seed = IDStack . empty ( ) ? 0 : IDStack . back ( ) ;
2014-12-29 19:23:03 +08:00
const ImGuiID id = ImCrc32 ( & ptr , sizeof ( void * ) , seed ) ;
2014-08-19 19:09:13 +08:00
RegisterAliveId ( id ) ;
return id ;
2014-08-11 04:58:11 +08:00
}
2014-11-24 07:35:26 +08:00
bool ImGuiWindow : : FocusItemRegister ( bool is_active , bool tab_stop )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-09-30 18:57:37 +08:00
const bool allow_keyboard_focus = window - > DC . AllowKeyboardFocus . back ( ) ;
2014-09-30 19:31:35 +08:00
FocusIdxAllCounter + + ;
2014-09-30 18:57:37 +08:00
if ( allow_keyboard_focus )
2014-09-30 19:22:58 +08:00
FocusIdxTabCounter + + ;
2014-08-11 04:58:11 +08:00
2014-09-30 19:22:58 +08:00
// Process keyboard input at this point: TAB, Shift-TAB switch focus
2014-09-30 18:57:37 +08:00
// We can always TAB out of a widget that doesn't allow tabbing in.
2014-11-24 07:35:26 +08:00
if ( tab_stop & & FocusIdxAllRequestNext = = IM_INT_MAX & & FocusIdxTabRequestNext = = IM_INT_MAX & & is_active & & IsKeyPressedMap ( ImGuiKey_Tab ) )
2014-08-19 19:09:13 +08:00
{
// Modulo on index will be applied at the end of frame once we've got the total counter of items.
2014-09-30 19:22:58 +08:00
FocusIdxTabRequestNext = FocusIdxTabCounter + ( g . IO . KeyShift ? ( allow_keyboard_focus ? - 1 : 0 ) : + 1 ) ;
2014-08-19 19:09:13 +08:00
}
2014-08-11 04:58:11 +08:00
2014-09-30 19:31:35 +08:00
if ( FocusIdxAllCounter = = FocusIdxAllRequestCurrent )
return true ;
2014-09-30 19:22:58 +08:00
if ( allow_keyboard_focus )
2014-09-30 19:31:35 +08:00
if ( FocusIdxTabCounter = = FocusIdxTabRequestCurrent )
return true ;
2014-09-30 18:57:37 +08:00
2014-09-30 19:22:58 +08:00
return false ;
2014-08-11 04:58:11 +08:00
}
void ImGuiWindow : : FocusItemUnregister ( )
{
2014-09-30 19:31:35 +08:00
FocusIdxAllCounter - - ;
2014-09-30 19:22:58 +08:00
FocusIdxTabCounter - - ;
2014-08-11 04:58:11 +08:00
}
void ImGuiWindow : : AddToRenderList ( )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( ! DrawList - > commands . empty ( ) & & ! DrawList - > vtx_buffer . empty ( ) )
{
if ( DrawList - > commands . back ( ) . vtx_count = = 0 )
DrawList - > commands . pop_back ( ) ;
g . RenderDrawLists . push_back ( DrawList ) ;
}
for ( size_t i = 0 ; i < DC . ChildWindows . size ( ) ; i + + )
{
ImGuiWindow * child = DC . ChildWindows [ i ] ;
2015-02-09 01:21:51 +08:00
if ( child - > Visible ) // clipped children may have been marked not Visible
2014-08-19 19:09:13 +08:00
child - > AddToRenderList ( ) ;
}
2014-08-11 04:58:11 +08:00
}
//-----------------------------------------------------------------------------
2014-11-10 09:29:01 +08:00
void * ImGui : : MemAlloc ( size_t sz )
2014-09-25 01:01:07 +08:00
{
2015-02-01 12:28:24 +08:00
return GImGui - > IO . MemAllocFn ( sz ) ;
2014-09-25 01:01:07 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : MemFree ( void * ptr )
2014-09-25 01:01:07 +08:00
{
2015-02-01 12:28:24 +08:00
return GImGui - > IO . MemFreeFn ( ptr ) ;
2014-09-25 01:01:07 +08:00
}
2014-09-25 03:39:39 +08:00
2014-08-11 04:58:11 +08:00
static ImGuiIniData * FindWindowSettings ( const char * name )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
for ( size_t i = 0 ; i ! = g . Settings . size ( ) ; i + + )
{
ImGuiIniData * ini = g . Settings [ i ] ;
if ( ImStricmp ( ini - > Name , name ) = = 0 )
return ini ;
}
2014-12-11 03:22:30 +08:00
return NULL ;
}
static ImGuiIniData * AddWindowSettings ( const char * name )
{
2014-09-25 01:01:07 +08:00
ImGuiIniData * ini = ( ImGuiIniData * ) ImGui : : MemAlloc ( sizeof ( ImGuiIniData ) ) ;
2014-08-31 18:28:21 +08:00
new ( ini ) ImGuiIniData ( ) ;
ini - > Name = ImStrdup ( name ) ;
2014-08-16 16:28:29 +08:00
ini - > Collapsed = false ;
2014-08-19 19:09:13 +08:00
ini - > Pos = ImVec2 ( FLT_MAX , FLT_MAX ) ;
ini - > Size = ImVec2 ( 0 , 0 ) ;
2015-02-01 12:28:24 +08:00
GImGui - > Settings . push_back ( ini ) ;
2014-08-19 19:09:13 +08:00
return ini ;
2014-08-11 04:58:11 +08:00
}
// Zero-tolerance, poor-man .ini parsing
// FIXME: Write something less rubbish
static void LoadSettings ( )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
const char * filename = g . IO . IniFilename ;
if ( ! filename )
return ;
2014-12-29 19:23:03 +08:00
char * file_data ;
size_t file_size ;
2014-12-30 02:05:22 +08:00
if ( ! ImLoadFileToMemory ( filename , " rb " , ( void * * ) & file_data , & file_size , 1 ) )
2014-08-19 19:09:13 +08:00
return ;
ImGuiIniData * settings = NULL ;
2014-12-29 19:23:03 +08:00
const char * buf_end = file_data + file_size ;
for ( const char * line_start = file_data ; line_start < buf_end ; )
2014-08-19 19:09:13 +08:00
{
const char * line_end = line_start ;
while ( line_end < buf_end & & * line_end ! = ' \n ' & & * line_end ! = ' \r ' )
line_end + + ;
if ( line_start [ 0 ] = = ' [ ' & & line_end > line_start & & line_end [ - 1 ] = = ' ] ' )
{
char name [ 64 ] ;
ImFormatString ( name , IM_ARRAYSIZE ( name ) , " %.*s " , line_end - line_start - 2 , line_start + 1 ) ;
settings = FindWindowSettings ( name ) ;
2014-12-11 03:22:30 +08:00
if ( ! settings )
settings = AddWindowSettings ( name ) ;
2014-08-19 19:09:13 +08:00
}
else if ( settings )
{
float x , y ;
int i ;
if ( sscanf ( line_start , " Pos=%f,%f " , & x , & y ) = = 2 )
settings - > Pos = ImVec2 ( x , y ) ;
else if ( sscanf ( line_start , " Size=%f,%f " , & x , & y ) = = 2 )
settings - > Size = ImMax ( ImVec2 ( x , y ) , g . Style . WindowMinSize ) ;
else if ( sscanf ( line_start , " Collapsed=%d " , & i ) = = 1 )
settings - > Collapsed = ( i ! = 0 ) ;
}
line_start = line_end + 1 ;
}
2014-08-11 04:58:11 +08:00
2014-12-29 19:23:03 +08:00
ImGui : : MemFree ( file_data ) ;
2014-08-11 04:58:11 +08:00
}
static void SaveSettings ( )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
const char * filename = g . IO . IniFilename ;
if ( ! filename )
return ;
// Gather data from windows that were active during this session
for ( size_t i = 0 ; i ! = g . Windows . size ( ) ; i + + )
{
ImGuiWindow * window = g . Windows [ i ] ;
2014-12-11 01:13:45 +08:00
if ( window - > Flags & ImGuiWindowFlags_NoSavedSettings )
2014-08-19 19:09:13 +08:00
continue ;
ImGuiIniData * settings = FindWindowSettings ( window - > Name ) ;
settings - > Pos = window - > Pos ;
settings - > Size = window - > SizeFull ;
settings - > Collapsed = window - > Collapsed ;
}
// Write .ini file
// If a window wasn't opened in this session we preserve its settings
FILE * f = fopen ( filename , " wt " ) ;
if ( ! f )
return ;
for ( size_t i = 0 ; i ! = g . Settings . size ( ) ; i + + )
{
const ImGuiIniData * settings = g . Settings [ i ] ;
if ( settings - > Pos . x = = FLT_MAX )
continue ;
fprintf ( f , " [%s] \n " , settings - > Name ) ;
fprintf ( f , " Pos=%d,%d \n " , ( int ) settings - > Pos . x , ( int ) settings - > Pos . y ) ;
fprintf ( f , " Size=%d,%d \n " , ( int ) settings - > Size . x , ( int ) settings - > Size . y ) ;
fprintf ( f , " Collapsed=%d \n " , settings - > Collapsed ) ;
fprintf ( f , " \n " ) ;
}
fclose ( f ) ;
2014-08-11 04:58:11 +08:00
}
static void MarkSettingsDirty ( )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( g . SettingsDirtyTimer < = 0.0f )
g . SettingsDirtyTimer = g . IO . IniSavingRate ;
2014-08-11 04:58:11 +08:00
}
2015-02-04 16:43:11 +08:00
// Internal state access - if you want to share ImGui state between modules (e.g. DLL) or allocate it yourself
// Note that we still point to some static data and members (such as GFontAtlas), so the state instance you end up using will point to the static data within its module
2015-02-01 12:28:24 +08:00
void * ImGui : : GetInternalState ( )
{
2015-02-04 16:30:03 +08:00
return GImGui ;
2015-02-01 12:28:24 +08:00
}
2015-02-04 16:43:11 +08:00
size_t ImGui : : GetInternalStateSize ( )
2015-02-01 12:28:24 +08:00
{
2015-02-04 16:30:03 +08:00
return sizeof ( ImGuiState ) ;
2015-02-01 13:55:19 +08:00
}
void ImGui : : SetInternalState ( void * state , bool construct )
{
2015-02-04 16:43:11 +08:00
if ( construct )
new ( state ) ImGuiState ( ) ;
2015-02-04 16:30:03 +08:00
GImGui = ( ImGuiState * ) state ;
2015-02-01 12:28:24 +08:00
}
2014-11-10 09:29:01 +08:00
ImGuiIO & ImGui : : GetIO ( )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
return GImGui - > IO ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
ImGuiStyle & ImGui : : GetStyle ( )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
return GImGui - > Style ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : NewFrame ( )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-11 04:58:11 +08:00
2015-01-09 07:35:01 +08:00
// Check user data
2014-08-19 19:09:13 +08:00
IM_ASSERT ( g . IO . DeltaTime > 0.0f ) ;
2014-12-22 09:45:13 +08:00
IM_ASSERT ( g . IO . DisplaySize . x > = 0.0f & & g . IO . DisplaySize . y > = 0.0f ) ;
2015-01-18 06:15:29 +08:00
IM_ASSERT ( g . IO . RenderDrawListsFn ! = NULL ) ; // Must be implemented
2015-01-18 18:46:49 +08:00
IM_ASSERT ( g . IO . Fonts - > Fonts . size ( ) > 0 ) ; // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
IM_ASSERT ( g . IO . Fonts - > Fonts [ 0 ] - > IsLoaded ( ) ) ; // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( ! g . Initialized )
{
2014-08-16 16:28:29 +08:00
// Initialize on first frame
2014-09-25 01:01:07 +08:00
g . LogClipboard = ( ImGuiTextBuffer * ) ImGui : : MemAlloc ( sizeof ( ImGuiTextBuffer ) ) ;
2014-08-31 18:28:21 +08:00
new ( g . LogClipboard ) ImGuiTextBuffer ( ) ;
2014-08-19 19:09:13 +08:00
IM_ASSERT ( g . Settings . empty ( ) ) ;
LoadSettings ( ) ;
g . Initialized = true ;
}
2014-11-29 08:02:46 +08:00
2015-01-18 18:46:49 +08:00
SetFont ( g . IO . Fonts - > Fonts [ 0 ] ) ;
2014-08-19 19:09:13 +08:00
g . Time + = g . IO . DeltaTime ;
g . FrameCount + = 1 ;
g . Tooltip [ 0 ] = ' \0 ' ;
// Update inputs state
if ( g . IO . MousePos . x < 0 & & g . IO . MousePos . y < 0 )
g . IO . MousePos = ImVec2 ( - 9999.0f , - 9999.0f ) ;
if ( ( g . IO . MousePos . x < 0 & & g . IO . MousePos . y < 0 ) | | ( g . IO . MousePosPrev . x < 0 & & g . IO . MousePosPrev . y < 0 ) ) // if mouse just appeared or disappeared (negative coordinate) we cancel out movement in MouseDelta
g . IO . MouseDelta = ImVec2 ( 0.0f , 0.0f ) ;
else
g . IO . MouseDelta = g . IO . MousePos - g . IO . MousePosPrev ;
g . IO . MousePosPrev = g . IO . MousePos ;
for ( size_t i = 0 ; i < IM_ARRAYSIZE ( g . IO . MouseDown ) ; i + + )
{
g . IO . MouseDownTime [ i ] = g . IO . MouseDown [ i ] ? ( g . IO . MouseDownTime [ i ] < 0.0f ? 0.0f : g . IO . MouseDownTime [ i ] + g . IO . DeltaTime ) : - 1.0f ;
g . IO . MouseClicked [ i ] = ( g . IO . MouseDownTime [ i ] = = 0.0f ) ;
g . IO . MouseDoubleClicked [ i ] = false ;
if ( g . IO . MouseClicked [ i ] )
{
if ( g . Time - g . IO . MouseClickedTime [ i ] < g . IO . MouseDoubleClickTime )
{
2014-12-29 19:23:03 +08:00
if ( ImLengthSqr ( g . IO . MousePos - g . IO . MouseClickedPos [ i ] ) < g . IO . MouseDoubleClickMaxDist * g . IO . MouseDoubleClickMaxDist )
2014-08-19 19:09:13 +08:00
g . IO . MouseDoubleClicked [ i ] = true ;
g . IO . MouseClickedTime [ i ] = - FLT_MAX ; // so the third click isn't turned into a double-click
}
else
{
g . IO . MouseClickedTime [ i ] = g . Time ;
g . IO . MouseClickedPos [ i ] = g . IO . MousePos ;
}
}
}
for ( size_t i = 0 ; i < IM_ARRAYSIZE ( g . IO . KeysDown ) ; i + + )
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 ;
2015-02-12 02:28:17 +08:00
// Calculate frame-rate for the user, as a purely luxurious feature
g . FramerateSecPerFrameAccum + = g . IO . DeltaTime - g . FramerateSecPerFrame [ g . FramerateSecPerFrameIdx ] ;
g . FramerateSecPerFrame [ g . FramerateSecPerFrameIdx ] = g . IO . DeltaTime ;
g . FramerateSecPerFrameIdx = ( g . FramerateSecPerFrameIdx + 1 ) % IM_ARRAYSIZE ( g . FramerateSecPerFrame ) ;
g . IO . Framerate = 1.0f / ( g . FramerateSecPerFrameAccum / ( float ) IM_ARRAYSIZE ( g . FramerateSecPerFrame ) ) ;
2014-08-19 19:09:13 +08:00
// Clear reference to active widget if the widget isn't alive anymore
g . HoveredId = 0 ;
if ( ! g . ActiveIdIsAlive & & g . ActiveIdPreviousFrame = = g . ActiveId & & g . ActiveId ! = 0 )
2015-02-01 06:57:59 +08:00
SetActiveId ( 0 ) ;
2014-08-19 19:09:13 +08:00
g . ActiveIdPreviousFrame = g . ActiveId ;
g . ActiveIdIsAlive = false ;
// Delay saving settings so we don't spam disk too much
if ( g . SettingsDirtyTimer > 0.0f )
{
g . SettingsDirtyTimer - = g . IO . DeltaTime ;
if ( g . SettingsDirtyTimer < = 0.0f )
SaveSettings ( ) ;
}
2015-01-05 06:07:37 +08:00
// Find the window we are hovering. Child windows can extend beyond the limit of their parent so we need to derive HoveredRootWindow from HoveredWindow
2014-11-10 09:29:01 +08:00
g . HoveredWindow = FindHoveredWindow ( g . IO . MousePos , false ) ;
2015-01-05 06:07:37 +08:00
if ( g . HoveredWindow & & ( g . HoveredWindow - > Flags & ImGuiWindowFlags_ChildWindow ) )
g . HoveredRootWindow = g . HoveredWindow - > RootWindow ;
else
g . HoveredRootWindow = FindHoveredWindow ( g . IO . MousePos , true ) ;
2014-08-19 19:09:13 +08:00
2015-02-03 17:56:19 +08:00
// Are we using inputs? Tell user so they can capture/discard the inputs away from the rest of their application.
// When clicking outside of a window we assume the click is owned by the application and won't request capture.
int mouse_earliest_button_down = - 1 ;
for ( size_t i = 0 ; i < IM_ARRAYSIZE ( g . IO . MouseDown ) ; i + + )
{
if ( g . IO . MouseClicked [ i ] )
g . IO . MouseDownOwned [ i ] = ( g . HoveredWindow ! = NULL ) ;
if ( g . IO . MouseDown [ i ] )
if ( mouse_earliest_button_down = = - 1 | | g . IO . MouseClickedTime [ mouse_earliest_button_down ] > g . IO . MouseClickedTime [ i ] )
mouse_earliest_button_down = i ;
}
bool mouse_owned_by_application = mouse_earliest_button_down ! = - 1 & & ! g . IO . MouseDownOwned [ mouse_earliest_button_down ] ;
g . IO . WantCaptureMouse = ( ! mouse_owned_by_application & & g . HoveredWindow ! = NULL ) | | ( g . ActiveId ! = 0 ) ;
2014-08-19 19:09:13 +08:00
g . IO . WantCaptureKeyboard = ( g . ActiveId ! = 0 ) ;
2015-02-03 18:35:43 +08:00
// If mouse was first clicked outside of ImGui bounds we also cancel out hovering.
if ( mouse_owned_by_application )
g . HoveredWindow = g . HoveredRootWindow = NULL ;
2014-08-19 19:09:13 +08:00
// Scale & Scrolling
2014-11-30 18:20:25 +08:00
if ( g . HoveredWindow & & g . IO . MouseWheel ! = 0.0f )
2014-08-19 19:09:13 +08:00
{
ImGuiWindow * window = g . HoveredWindow ;
if ( g . IO . KeyCtrl )
{
2014-09-24 21:03:42 +08:00
if ( g . IO . FontAllowUserScaling )
2014-08-19 19:09:13 +08:00
{
// Zoom / Scale window
2014-11-30 18:20:25 +08:00
float new_font_scale = ImClamp ( window - > FontWindowScale + g . IO . MouseWheel * 0.10f , 0.50f , 2.50f ) ;
2014-09-24 21:03:42 +08:00
float scale = new_font_scale / window - > FontWindowScale ;
window - > FontWindowScale = new_font_scale ;
2014-08-19 19:09:13 +08:00
const ImVec2 offset = window - > Size * ( 1.0f - scale ) * ( g . IO . MousePos - window - > Pos ) / window - > Size ;
window - > Pos + = offset ;
window - > PosFloat + = offset ;
window - > Size * = scale ;
window - > SizeFull * = scale ;
}
}
else
{
// Scroll
2014-12-04 00:54:04 +08:00
if ( ! ( window - > Flags & ImGuiWindowFlags_NoScrollWithMouse ) )
{
const int scroll_lines = ( window - > Flags & ImGuiWindowFlags_ComboBox ) ? 3 : 5 ;
window - > NextScrollY - = g . IO . MouseWheel * window - > FontSize ( ) * scroll_lines ;
}
2014-08-19 19:09:13 +08:00
}
}
// Pressing TAB activate widget focus
// NB: Don't discard FocusedWindow if it isn't active, so that a window that go on/off programatically won't lose its keyboard focus.
if ( g . ActiveId = = 0 & & g . FocusedWindow ! = NULL & & g . FocusedWindow - > Visible & & IsKeyPressedMap ( ImGuiKey_Tab , false ) )
{
2014-09-30 19:22:58 +08:00
g . FocusedWindow - > FocusIdxTabRequestNext = 0 ;
2014-08-19 19:09:13 +08:00
}
// Mark all windows as not visible
2015-01-05 06:07:37 +08:00
// Clear root windows at this point.
2014-08-19 19:09:13 +08:00
for ( size_t i = 0 ; i ! = g . Windows . size ( ) ; i + + )
{
ImGuiWindow * window = g . Windows [ i ] ;
window - > Visible = false ;
window - > Accessed = false ;
2015-01-05 06:07:37 +08:00
window - > RootWindow = NULL ;
2014-08-19 19:09:13 +08:00
}
// No window should be open at the beginning of the frame.
// But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear.
2015-02-01 22:39:13 +08:00
g . CurrentWindowStack . resize ( 0 ) ;
2014-08-19 19:09:13 +08:00
// Create implicit window - we will only render it if the user has added something to it.
ImGui : : Begin ( " Debug " , NULL , ImVec2 ( 400 , 400 ) ) ;
2014-08-11 04:58:11 +08:00
}
// NB: behaviour of ImGui after Shutdown() is not tested/guaranteed at the moment. This function is merely here to free heap allocations.
2014-11-10 09:29:01 +08:00
void ImGui : : Shutdown ( )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
if ( ! g . Initialized )
return ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
SaveSettings ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
for ( size_t i = 0 ; i < g . Windows . size ( ) ; i + + )
2014-08-31 18:28:21 +08:00
{
2014-08-16 16:28:29 +08:00
g . Windows [ i ] - > ~ ImGuiWindow ( ) ;
2014-09-25 01:01:07 +08:00
ImGui : : MemFree ( g . Windows [ i ] ) ;
2014-08-16 16:28:29 +08:00
}
2014-08-19 19:09:13 +08:00
g . Windows . clear ( ) ;
g . CurrentWindowStack . clear ( ) ;
2014-08-31 18:28:21 +08:00
g . RenderDrawLists . clear ( ) ;
2014-08-19 19:09:13 +08:00
g . FocusedWindow = NULL ;
g . HoveredWindow = NULL ;
2014-12-04 00:54:04 +08:00
g . HoveredRootWindow = NULL ;
2014-08-19 19:09:13 +08:00
for ( size_t i = 0 ; i < g . Settings . size ( ) ; i + + )
2014-08-31 18:28:21 +08:00
{
2014-08-16 17:04:45 +08:00
g . Settings [ i ] - > ~ ImGuiIniData ( ) ;
2014-09-25 01:01:07 +08:00
ImGui : : MemFree ( g . Settings [ i ] ) ;
2014-08-16 17:04:45 +08:00
}
2014-08-19 19:09:13 +08:00
g . Settings . clear ( ) ;
2015-01-07 22:55:35 +08:00
g . ColorModifiers . clear ( ) ;
g . StyleModifiers . clear ( ) ;
2015-01-17 22:13:08 +08:00
g . FontStack . clear ( ) ;
2014-08-19 19:09:13 +08:00
g . ColorEditModeStorage . Clear ( ) ;
if ( g . LogFile & & g . LogFile ! = stdout )
{
fclose ( g . LogFile ) ;
g . LogFile = NULL ;
}
2015-01-18 18:46:49 +08:00
g . IO . Fonts - > Clear ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( g . PrivateClipboard )
{
2014-09-25 01:01:07 +08:00
ImGui : : MemFree ( g . PrivateClipboard ) ;
2014-08-19 19:09:13 +08:00
g . PrivateClipboard = NULL ;
}
2014-08-14 22:03:10 +08:00
2014-08-18 19:38:03 +08:00
if ( g . LogClipboard )
{
g . LogClipboard - > ~ ImGuiTextBuffer ( ) ;
2014-09-25 01:01:07 +08:00
ImGui : : MemFree ( g . LogClipboard ) ;
2014-08-18 19:38:03 +08:00
}
2014-08-16 16:28:29 +08:00
2014-08-19 19:09:13 +08:00
g . Initialized = false ;
2014-08-11 04:58:11 +08:00
}
2015-02-09 01:21:51 +08:00
// FIXME: Add a more explicit sort order in the window structure.
static int ChildWindowComparer ( const void * lhs , const void * rhs )
{
const ImGuiWindow * a = * ( const ImGuiWindow * * ) lhs ;
const ImGuiWindow * b = * ( const ImGuiWindow * * ) rhs ;
if ( int d = ( a - > Flags & ImGuiWindowFlags_Tooltip ) - ( b - > Flags & ImGuiWindowFlags_Tooltip ) )
return d ;
if ( int d = ( a - > Flags & ImGuiWindowFlags_ComboBox ) - ( b - > Flags & ImGuiWindowFlags_ComboBox ) )
return d ;
return 0 ;
}
2014-08-11 04:58:11 +08:00
static void AddWindowToSortedBuffer ( ImGuiWindow * window , ImVector < ImGuiWindow * > & sorted_windows )
{
2014-08-19 19:09:13 +08:00
sorted_windows . push_back ( window ) ;
if ( window - > Visible )
{
2015-02-09 01:21:51 +08:00
const size_t count = window - > DC . ChildWindows . size ( ) ;
if ( count > 1 )
qsort ( window - > DC . ChildWindows . begin ( ) , count , sizeof ( ImGuiWindow * ) , ChildWindowComparer ) ;
for ( size_t i = 0 ; i < count ; i + + )
2014-08-19 19:09:13 +08:00
{
ImGuiWindow * child = window - > DC . ChildWindows [ i ] ;
if ( child - > Visible )
AddWindowToSortedBuffer ( child , sorted_windows ) ;
}
}
2014-08-11 04:58:11 +08:00
}
static void PushClipRect ( const ImVec4 & clip_rect , bool clipped = true )
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
ImVec4 cr = clip_rect ;
if ( clipped & & ! window - > ClipRectStack . empty ( ) )
{
2015-02-03 03:50:28 +08:00
// Clip with existing clip rect
2014-08-19 19:09:13 +08:00
const ImVec4 cur_cr = window - > ClipRectStack . back ( ) ;
cr = ImVec4 ( ImMax ( cr . x , cur_cr . x ) , ImMax ( cr . y , cur_cr . y ) , ImMin ( cr . z , cur_cr . z ) , ImMin ( cr . w , cur_cr . w ) ) ;
}
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
window - > ClipRectStack . push_back ( cr ) ;
window - > DrawList - > PushClipRect ( cr ) ;
2014-08-11 04:58:11 +08:00
}
static void PopClipRect ( )
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > ClipRectStack . pop_back ( ) ;
window - > DrawList - > PopClipRect ( ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : Render ( )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
IM_ASSERT ( g . Initialized ) ; // Forgot to call ImGui::NewFrame()
const bool first_render_of_the_frame = ( g . FrameCountRendered ! = g . FrameCount ) ;
g . FrameCountRendered = g . FrameCount ;
if ( first_render_of_the_frame )
{
// Hide implicit window if it hasn't been used
IM_ASSERT ( g . CurrentWindowStack . size ( ) = = 1 ) ; // Mismatched Begin/End
if ( g . CurrentWindow & & ! g . CurrentWindow - > Accessed )
g . CurrentWindow - > Visible = false ;
ImGui : : End ( ) ;
2015-02-09 01:21:51 +08:00
// Select window for move/focus when we're done with all our widgets (we only consider non-child windows here)
2015-01-16 18:55:49 +08:00
if ( g . ActiveId = = 0 & & g . HoveredId = = 0 & & g . HoveredRootWindow ! = NULL & & g . IO . MouseClicked [ 0 ] )
2015-02-01 06:57:59 +08:00
SetActiveId ( g . HoveredRootWindow - > GetID ( " #MOVE " ) ) ;
2015-01-16 18:55:49 +08:00
2014-08-19 19:09:13 +08:00
// Sort the window list so that all child windows are after their parent
// We cannot do that on FocusWindow() because childs may not exist yet
2015-02-01 22:42:09 +08:00
g . RenderSortedWindows . resize ( 0 ) ;
g . RenderSortedWindows . reserve ( g . Windows . size ( ) ) ;
2014-08-19 19:09:13 +08:00
for ( size_t i = 0 ; i ! = g . Windows . size ( ) ; i + + )
{
ImGuiWindow * window = g . Windows [ i ] ;
2015-02-09 01:21:51 +08:00
if ( window - > Flags & ImGuiWindowFlags_ChildWindow ) // if a child is visible its parent will add it
2014-08-19 19:09:13 +08:00
if ( window - > Visible )
continue ;
2015-02-01 22:42:09 +08:00
AddWindowToSortedBuffer ( window , g . RenderSortedWindows ) ;
2014-08-19 19:09:13 +08:00
}
2015-02-09 01:21:51 +08:00
IM_ASSERT ( g . Windows . size ( ) = = g . RenderSortedWindows . size ( ) ) ; // we done something wrong
2015-02-01 22:42:09 +08:00
g . Windows . swap ( g . RenderSortedWindows ) ;
2014-08-19 19:09:13 +08:00
// Clear data for next frame
2014-11-30 18:20:25 +08:00
g . IO . MouseWheel = 0.0f ;
2014-08-19 19:09:13 +08:00
memset ( g . IO . InputCharacters , 0 , sizeof ( g . IO . InputCharacters ) ) ;
}
// Skip render altogether if alpha is 0.0
// Note that vertex buffers have been created, so it is best practice that you don't call Begin/End in the first place.
if ( g . Style . Alpha > 0.0f )
{
// Render tooltip
if ( g . Tooltip [ 0 ] )
{
// Use a dummy window to render the tooltip
ImGui : : BeginTooltip ( ) ;
ImGui : : TextUnformatted ( g . Tooltip ) ;
ImGui : : EndTooltip ( ) ;
}
// Gather windows to render
g . RenderDrawLists . resize ( 0 ) ;
for ( size_t i = 0 ; i ! = g . Windows . size ( ) ; i + + )
{
ImGuiWindow * window = g . Windows [ i ] ;
if ( window - > Visible & & ( window - > Flags & ( ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip ) ) = = 0 )
window - > AddToRenderList ( ) ;
}
for ( size_t i = 0 ; i ! = g . Windows . size ( ) ; i + + )
{
ImGuiWindow * window = g . Windows [ i ] ;
if ( window - > Visible & & ( window - > Flags & ImGuiWindowFlags_Tooltip ) )
window - > AddToRenderList ( ) ;
}
2015-02-01 02:55:05 +08:00
if ( g . IO . MouseDrawCursor )
{
const ImVec2 pos = g . IO . MousePos ;
const ImVec2 size = TEX_ATLAS_SIZE_MOUSE_CURSOR ;
const ImTextureID tex_id = g . IO . Fonts - > TexID ;
const ImVec2 tex_uv_scale ( 1.0f / g . IO . Fonts - > TexWidth , 1.0f / g . IO . Fonts - > TexHeight ) ;
static ImDrawList draw_list ;
draw_list . Clear ( ) ;
draw_list . AddImage ( tex_id , pos + ImVec2 ( 1 , 0 ) , pos + ImVec2 ( 1 , 0 ) + size , TEX_ATLAS_POS_MOUSE_CURSOR_BLACK * tex_uv_scale , ( TEX_ATLAS_POS_MOUSE_CURSOR_BLACK + size ) * tex_uv_scale , 0x30000000 ) ; // Shadow
draw_list . AddImage ( tex_id , pos + ImVec2 ( 2 , 0 ) , pos + ImVec2 ( 2 , 0 ) + size , TEX_ATLAS_POS_MOUSE_CURSOR_BLACK * tex_uv_scale , ( TEX_ATLAS_POS_MOUSE_CURSOR_BLACK + size ) * tex_uv_scale , 0x30000000 ) ; // Shadow
draw_list . AddImage ( tex_id , pos , pos + size , TEX_ATLAS_POS_MOUSE_CURSOR_BLACK * tex_uv_scale , ( TEX_ATLAS_POS_MOUSE_CURSOR_BLACK + size ) * tex_uv_scale , 0xFF000000 ) ; // Black border
draw_list . AddImage ( tex_id , pos , pos + size , TEX_ATLAS_POS_MOUSE_CURSOR_WHITE * tex_uv_scale , ( TEX_ATLAS_POS_MOUSE_CURSOR_WHITE + size ) * tex_uv_scale , 0xFFFFFFFF ) ; // White fill
g . RenderDrawLists . push_back ( & draw_list ) ;
}
2014-08-19 19:09:13 +08:00
// Render
if ( ! g . RenderDrawLists . empty ( ) )
g . IO . RenderDrawListsFn ( & g . RenderDrawLists [ 0 ] , ( int ) g . RenderDrawLists . size ( ) ) ;
g . RenderDrawLists . resize ( 0 ) ;
}
2014-08-11 04:58:11 +08:00
}
// Find the optional ## from which we stop displaying text.
2014-08-19 19:09:13 +08:00
static const char * FindTextDisplayEnd ( const char * text , const char * text_end = NULL )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
const char * text_display_end = text ;
while ( ( ! text_end | | text_display_end < text_end ) & & * text_display_end ! = ' \0 ' & & ( text_display_end [ 0 ] ! = ' # ' | | text_display_end [ 1 ] ! = ' # ' ) )
text_display_end + + ;
return text_display_end ;
2014-08-11 04:58:11 +08:00
}
2014-12-30 04:18:52 +08:00
// Pass text data straight to log (without being displayed)
void ImGui : : LogText ( const char * fmt , . . . )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-12-30 04:18:52 +08:00
if ( ! g . LogEnabled )
return ;
va_list args ;
va_start ( args , fmt ) ;
if ( g . LogFile )
{
vfprintf ( g . LogFile , fmt , args ) ;
}
else
{
g . LogClipboard - > appendv ( fmt , args ) ;
}
va_end ( args ) ;
}
// Internal version that takes a position to decide on newline placement and pad items according to their depth.
2015-02-08 23:57:06 +08:00
// We split text into individual lines to add current tree level padding
2014-08-11 04:58:11 +08:00
static void LogText ( const ImVec2 & ref_pos , const char * text , const char * text_end )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( ! text_end )
text_end = FindTextDisplayEnd ( text , text_end ) ;
const bool log_new_line = ref_pos . y > window - > DC . LogLineHeight + 1 ;
window - > DC . LogLineHeight = ref_pos . y ;
const char * text_remaining = text ;
2014-12-30 04:18:52 +08:00
if ( g . LogStartDepth > window - > DC . TreeDepth ) // Re-adjust padding if we have popped out of our starting depth
g . LogStartDepth = window - > DC . TreeDepth ;
const int tree_depth = ( window - > DC . TreeDepth - g . LogStartDepth ) ;
2015-02-02 17:06:51 +08:00
for ( ; ; )
2014-08-19 19:09:13 +08:00
{
2015-01-14 21:04:33 +08:00
// Split the string. Each new line (after a '\n') is followed by spacing corresponding to the current depth of our log entry.
2014-08-19 19:09:13 +08:00
const char * line_end = text_remaining ;
while ( line_end < text_end )
if ( * line_end = = ' \n ' )
break ;
else
line_end + + ;
if ( line_end > = text_end )
line_end = NULL ;
2014-09-02 21:35:06 +08:00
const bool is_first_line = ( text = = text_remaining ) ;
2014-08-19 19:09:13 +08:00
bool is_last_line = false ;
if ( line_end = = NULL )
{
is_last_line = true ;
line_end = text_end ;
}
if ( line_end ! = NULL & & ! ( is_last_line & & ( line_end - text_remaining ) = = 0 ) )
{
const int char_count = ( int ) ( line_end - text_remaining ) ;
2014-12-30 04:18:52 +08:00
if ( log_new_line | | ! is_first_line )
2014-12-30 20:08:33 +08:00
ImGui : : LogText ( STR_NEWLINE " %*s%.*s " , tree_depth * 4 , " " , char_count , text_remaining ) ;
2014-08-19 19:09:13 +08:00
else
2014-12-30 04:18:52 +08:00
ImGui : : LogText ( " %.*s " , char_count , text_remaining ) ;
2014-08-19 19:09:13 +08:00
}
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( is_last_line )
break ;
text_remaining = line_end + 1 ;
}
2014-08-11 04:58:11 +08:00
}
2014-11-07 13:45:56 +08:00
static float CalcWrapWidthForPos ( const ImVec2 & pos , float wrap_pos_x )
{
if ( wrap_pos_x < 0.0f )
return 0.0f ;
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-11-07 16:22:38 +08:00
if ( wrap_pos_x = = 0.0f )
2014-11-10 09:29:01 +08:00
wrap_pos_x = ImGui : : GetContentRegionMax ( ) . x ;
2014-11-07 13:45:56 +08:00
if ( wrap_pos_x > 0.0f )
wrap_pos_x + = window - > Pos . x ; // wrap_pos_x is provided is window local space
const float wrap_width = wrap_pos_x > 0.0f ? ImMax ( wrap_pos_x - pos . x , 0.00001f ) : 0.0f ;
return wrap_width ;
}
2015-02-08 23:57:06 +08:00
// Internal ImGui functions to render text
// RenderText***() functions calls ImDrawList::AddText() calls ImBitmapFont::RenderText()
static void RenderText ( ImVec2 pos , const char * text , const char * text_end , bool hide_text_after_hash )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
// Hide anything after a '##' string
const char * text_display_end ;
if ( hide_text_after_hash )
{
text_display_end = FindTextDisplayEnd ( text , text_end ) ;
}
else
{
if ( ! text_end )
2014-11-17 01:27:26 +08:00
text_end = text + strlen ( text ) ; // FIXME-OPT
2014-08-19 19:09:13 +08:00
text_display_end = text_end ;
}
const int text_len = ( int ) ( text_display_end - text ) ;
if ( text_len > 0 )
{
// Render
2015-02-08 23:57:06 +08:00
window - > DrawList - > AddText ( window - > Font ( ) , window - > FontSize ( ) , pos , window - > Color ( ImGuiCol_Text ) , text , text_display_end ) ;
2015-02-08 23:39:40 +08:00
2015-02-08 23:57:06 +08:00
// Log as text
2015-02-08 23:39:40 +08:00
if ( g . LogEnabled )
LogText ( pos , text , text_display_end ) ;
}
}
2015-02-08 23:57:06 +08:00
static void RenderTextWrapped ( ImVec2 pos , const char * text , const char * text_end , float wrap_width )
{
ImGuiState & g = * GImGui ;
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( ! text_end )
text_end = text + strlen ( text ) ; // FIXME-OPT
const int text_len = ( int ) ( text_end - text ) ;
if ( text_len > 0 )
{
// Render
window - > DrawList - > AddText ( window - > Font ( ) , window - > FontSize ( ) , pos , window - > Color ( ImGuiCol_Text ) , text , text_end , wrap_width ) ;
// Log as text
if ( g . LogEnabled )
LogText ( pos , text , text_end ) ;
}
}
2015-02-09 00:32:51 +08:00
static void RenderTextClipped ( ImVec2 pos , const char * text , const char * text_end , const ImVec2 * text_size_if_known , const ImVec2 & clip_max )
2015-02-08 23:39:40 +08:00
{
ImGuiState & g = * GImGui ;
ImGuiWindow * window = GetCurrentWindow ( ) ;
// Hide anything after a '##' string
const char * text_display_end = FindTextDisplayEnd ( text , text_end ) ;
const int text_len = ( int ) ( text_display_end - text ) ;
if ( text_len > 0 )
{
2015-02-08 23:57:06 +08:00
const ImVec2 text_size = text_size_if_known ? * text_size_if_known : ImGui : : CalcTextSize ( text , text_display_end , false , 0.0f ) ;
2015-02-08 23:39:40 +08:00
2015-02-09 00:32:51 +08:00
// Perform CPU side clipping for single clipped element to avoid using scissor state
const bool need_clipping = ( pos . x + text_size . x > = clip_max . x ) | | ( pos . y + text_size . y > = clip_max . y ) ;
2015-02-08 23:39:40 +08:00
// Render
2015-02-09 00:32:51 +08:00
window - > DrawList - > AddText ( window - > Font ( ) , window - > FontSize ( ) , pos , window - > Color ( ImGuiCol_Text ) , text , text_display_end , 0.0f , need_clipping ? & clip_max : NULL ) ;
2014-08-19 19:09:13 +08:00
2015-02-08 23:57:06 +08:00
// Log as text
2014-08-19 19:09:13 +08:00
if ( g . LogEnabled )
LogText ( pos , text , text_display_end ) ;
}
2014-08-11 04:58:11 +08:00
}
2014-09-02 21:35:06 +08:00
// Render a rectangle shaped with optional rounding and borders
2014-08-11 04:58:11 +08:00
static void RenderFrame ( ImVec2 p_min , ImVec2 p_max , ImU32 fill_col , bool border , float rounding )
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
window - > DrawList - > AddRectFilled ( p_min , p_max , fill_col , rounding ) ;
if ( border & & ( window - > Flags & ImGuiWindowFlags_ShowBorders ) )
{
2015-01-18 01:17:18 +08:00
// FIXME: This is the best I've found that works on multiple renderer/back ends. Bit dodgy.
window - > DrawList - > AddRect ( p_min + ImVec2 ( 1.5f , 1.5f ) , p_max + ImVec2 ( 1 , 1 ) , window - > Color ( ImGuiCol_BorderShadow ) , rounding ) ;
window - > DrawList - > AddRect ( p_min + ImVec2 ( 0.5f , 0.5f ) , p_max + ImVec2 ( 0 , 0 ) , window - > Color ( ImGuiCol_Border ) , rounding ) ;
2014-08-19 19:09:13 +08:00
}
2014-08-11 04:58:11 +08:00
}
2014-09-02 21:35:06 +08:00
// Render a triangle to denote expanded/collapsed state
2014-12-22 21:29:39 +08:00
static void RenderCollapseTriangle ( ImVec2 p_min , bool opened , float scale , bool shadow )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
const float h = window - > FontSize ( ) * 1.00f ;
const float r = h * 0.40f * scale ;
ImVec2 center = p_min + ImVec2 ( h * 0.50f , h * 0.50f * scale ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
ImVec2 a , b , c ;
2014-12-22 21:29:39 +08:00
if ( opened )
2014-08-19 19:09:13 +08:00
{
center . y - = r * 0.25f ;
a = center + ImVec2 ( 0 , 1 ) * r ;
b = center + ImVec2 ( - 0.866f , - 0.5f ) * r ;
c = center + ImVec2 ( 0.866f , - 0.5f ) * r ;
}
else
{
a = center + ImVec2 ( 1 , 0 ) * r ;
b = center + ImVec2 ( - 0.500f , 0.866f ) * r ;
c = center + ImVec2 ( - 0.500f , - 0.866f ) * r ;
}
2014-08-28 00:54:11 +08:00
if ( shadow & & ( window - > Flags & ImGuiWindowFlags_ShowBorders ) ! = 0 )
2014-08-19 19:09:13 +08:00
window - > DrawList - > AddTriangleFilled ( a + ImVec2 ( 2 , 2 ) , b + ImVec2 ( 2 , 2 ) , c + ImVec2 ( 2 , 2 ) , window - > Color ( ImGuiCol_BorderShadow ) ) ;
window - > DrawList - > AddTriangleFilled ( a , b , c , window - > Color ( ImGuiCol_Border ) ) ;
2014-08-11 04:58:11 +08:00
}
2014-09-02 21:35:06 +08:00
// Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker.
2015-02-01 12:28:24 +08:00
// CalcTextSize("") should return ImVec2(0.0f, GImGui->FontSize)
2014-11-30 20:21:50 +08:00
ImVec2 ImGui : : CalcTextSize ( const char * text , const char * text_end , bool hide_text_after_double_hash , float wrap_width )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
const char * text_display_end ;
2014-11-30 20:21:50 +08:00
if ( hide_text_after_double_hash )
2014-08-19 19:09:13 +08:00
text_display_end = FindTextDisplayEnd ( text , text_end ) ; // Hide anything after a '##' string
else
text_display_end = text_end ;
2014-08-11 04:58:11 +08:00
2015-01-23 07:02:44 +08:00
ImFont * font = window - > Font ( ) ;
const float font_size = window - > FontSize ( ) ;
ImVec2 text_size = font - > CalcTextSizeA ( font_size , FLT_MAX , wrap_width , text , text_display_end , NULL ) ;
// Cancel out character spacing for the last character of a line (it is baked into glyph->XAdvance field)
const float font_scale = font_size / font - > FontSize ;
const float character_spacing_x = 1.0f * font_scale ;
if ( text_size . x > 0.0f )
text_size . x - = character_spacing_x ;
2014-11-07 13:45:56 +08:00
return text_size ;
2014-08-11 04:58:11 +08:00
}
2015-02-09 00:39:34 +08:00
// Helper to calculate coarse clipping of large list of evenly sized items.
2015-02-08 21:44:09 +08:00
// If you are displaying thousands of items and you have a random access to the list, you can perform clipping yourself to save on CPU.
// {
// float item_height = ImGui::GetTextLineHeightWithSpacing();
// int display_start, display_end;
// ImGui::CalcListClipping(count, item_height, &display_start, &display_end); // calculate how many to clip/display
// ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (display_start) * item_height); // advance cursor
// for (int i = display_start; i < display_end; i++) // display only visible items
// // TODO: display visible item
// ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (count - display_end) * item_height); // advance cursor
// }
void ImGui : : CalcListClipping ( int items_count , float items_height , int * out_items_display_start , int * out_items_display_end )
{
ImGuiState & g = * GImGui ;
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( g . LogEnabled )
{
// If logging is active, do not perform any clipping
* out_items_display_start = 0 ;
* out_items_display_end = items_count ;
return ;
}
const ImVec2 pos = window - > DC . CursorPos ;
const ImVec4 clip_rect = window - > ClipRectStack . back ( ) ;
const float clip_y1 = clip_rect . y ;
const float clip_y2 = clip_rect . w ;
int start = ( int ) ( ( clip_y1 - pos . y ) / items_height ) ;
int end = ( int ) ( ( clip_y2 - pos . y ) / items_height ) ;
start = ImClamp ( start , 0 , items_count ) ;
end = ImClamp ( end + 1 , start , items_count ) ;
* out_items_display_start = start ;
* out_items_display_end = end ;
}
2014-09-02 21:35:06 +08:00
// Find window given position, search front-to-back
2014-08-11 04:58:11 +08:00
static ImGuiWindow * FindHoveredWindow ( ImVec2 pos , bool excluding_childs )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
for ( int i = ( int ) g . Windows . size ( ) - 1 ; i > = 0 ; i - - )
{
ImGuiWindow * window = g . Windows [ ( size_t ) i ] ;
if ( ! window - > Visible )
continue ;
if ( excluding_childs & & ( window - > Flags & ImGuiWindowFlags_ChildWindow ) ! = 0 )
continue ;
2015-02-22 20:05:38 +08:00
// Using the clipped AABB so a child window will typically be clipped by its parent.
ImGuiAabb bb ( window - > ClippedAabb . Min - g . Style . TouchExtraPadding , window - > ClippedAabb . Max + g . Style . TouchExtraPadding ) ;
2014-08-19 19:09:13 +08:00
if ( bb . Contains ( pos ) )
return window ;
}
return NULL ;
2014-08-11 04:58:11 +08:00
}
2014-09-02 21:35:06 +08:00
// Test if mouse cursor is hovering given aabb
// NB- Box is clipped by our current clip setting
2014-11-10 09:29:01 +08:00
// NB- Expand the aabb to be generous on imprecise inputs systems (g.Style.TouchExtraPadding)
2014-08-11 04:58:11 +08:00
static bool IsMouseHoveringBox ( const ImGuiAabb & box )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
// Clip
ImGuiAabb box_clipped = box ;
if ( ! window - > ClipRectStack . empty ( ) )
{
const ImVec4 clip_rect = window - > ClipRectStack . back ( ) ;
box_clipped . Clip ( ImGuiAabb ( ImVec2 ( clip_rect . x , clip_rect . y ) , ImVec2 ( clip_rect . z , clip_rect . w ) ) ) ;
}
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
// Expand for touch input
2014-09-02 21:35:06 +08:00
const ImGuiAabb box_for_touch ( box_clipped . Min - g . Style . TouchExtraPadding , box_clipped . Max + g . Style . TouchExtraPadding ) ;
2014-08-19 19:09:13 +08:00
return box_for_touch . Contains ( g . IO . MousePos ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : IsMouseHoveringBox ( const ImVec2 & box_min , const ImVec2 & box_max )
2014-08-13 02:57:46 +08:00
{
2014-08-19 19:09:13 +08:00
return IsMouseHoveringBox ( ImGuiAabb ( box_min , box_max ) ) ;
2014-08-13 02:57:46 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : IsMouseHoveringWindow ( )
2014-09-24 22:38:29 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-09-24 22:38:29 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-09-25 03:39:39 +08:00
return g . HoveredWindow = = window ;
2014-09-24 22:38:29 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : IsMouseHoveringAnyWindow ( )
2014-09-24 22:38:29 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-09-25 03:39:39 +08:00
return g . HoveredWindow ! = NULL ;
2014-09-24 22:38:29 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : IsPosHoveringAnyWindow ( const ImVec2 & pos )
2014-09-24 22:49:15 +08:00
{
2014-11-10 09:29:01 +08:00
return FindHoveredWindow ( pos , false ) ! = NULL ;
2014-09-24 22:49:15 +08:00
}
2014-08-11 04:58:11 +08:00
static bool IsKeyPressedMap ( ImGuiKey key , bool repeat )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
const int key_index = g . IO . KeyMap [ key ] ;
2014-11-10 09:29:01 +08:00
return ImGui : : IsKeyPressed ( key_index , repeat ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : IsKeyPressed ( int key_index , bool repeat )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
IM_ASSERT ( key_index > = 0 & & key_index < IM_ARRAYSIZE ( g . IO . KeysDown ) ) ;
const float t = g . IO . KeysDownTime [ key_index ] ;
if ( t = = 0.0f )
return true ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
// FIXME: Repeat rate should be provided elsewhere?
const float KEY_REPEAT_DELAY = 0.250f ;
const float KEY_REPEAT_RATE = 0.020f ;
if ( repeat & & t > KEY_REPEAT_DELAY )
if ( ( fmodf ( t - KEY_REPEAT_DELAY , KEY_REPEAT_RATE ) > KEY_REPEAT_RATE * 0.5f ) ! = ( fmodf ( t - KEY_REPEAT_DELAY - g . IO . DeltaTime , KEY_REPEAT_RATE ) > KEY_REPEAT_RATE * 0.5f ) )
return true ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
return false ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : IsMouseClicked ( int button , bool repeat )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
IM_ASSERT ( button > = 0 & & button < IM_ARRAYSIZE ( g . IO . MouseDown ) ) ;
const float t = g . IO . MouseDownTime [ button ] ;
if ( t = = 0.0f )
return true ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
// FIXME: Repeat rate should be provided elsewhere?
const float MOUSE_REPEAT_DELAY = 0.250f ;
const float MOUSE_REPEAT_RATE = 0.020f ;
if ( repeat & & t > MOUSE_REPEAT_DELAY )
if ( ( fmodf ( t - MOUSE_REPEAT_DELAY , MOUSE_REPEAT_RATE ) > MOUSE_REPEAT_RATE * 0.5f ) ! = ( fmodf ( t - MOUSE_REPEAT_DELAY - g . IO . DeltaTime , MOUSE_REPEAT_RATE ) > MOUSE_REPEAT_RATE * 0.5f ) )
return true ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
return false ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : IsMouseDoubleClicked ( int button )
2014-08-13 02:57:46 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
IM_ASSERT ( button > = 0 & & button < IM_ARRAYSIZE ( g . IO . MouseDown ) ) ;
return g . IO . MouseDoubleClicked [ button ] ;
2014-08-13 02:57:46 +08:00
}
2014-11-10 09:29:01 +08:00
ImVec2 ImGui : : GetMousePos ( )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
return GImGui - > IO . MousePos ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : IsItemHovered ( )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return window - > DC . LastItemHovered ;
2014-08-11 04:58:11 +08:00
}
2015-01-23 06:54:05 +08:00
bool ImGui : : IsItemActive ( )
2014-11-07 13:45:56 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2015-01-23 06:54:05 +08:00
if ( g . ActiveId )
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
return g . ActiveId = = window - > DC . LastItemID ;
}
return false ;
2014-11-07 13:45:56 +08:00
}
2015-02-19 01:17:06 +08:00
bool ImGui : : IsAnyItemActive ( )
{
ImGuiState & g = * GImGui ;
return g . ActiveId ! = 0 ;
}
2014-11-10 09:29:01 +08:00
ImVec2 ImGui : : GetItemBoxMin ( )
2014-08-14 19:43:30 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return window - > DC . LastItemAabb . Min ;
2014-08-14 19:43:30 +08:00
}
2014-11-10 09:29:01 +08:00
ImVec2 ImGui : : GetItemBoxMax ( )
2014-08-14 19:43:30 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return window - > DC . LastItemAabb . Max ;
2014-08-14 19:43:30 +08:00
}
2014-09-25 02:27:29 +08:00
// Tooltip is stored and turned into a BeginTooltip()/EndTooltip() sequence at the end of the frame. Each call override previous value.
2014-11-10 09:29:01 +08:00
void ImGui : : SetTooltipV ( const char * fmt , va_list args )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-09-25 02:27:29 +08:00
ImFormatStringV ( g . Tooltip , IM_ARRAYSIZE ( g . Tooltip ) , fmt , args ) ;
}
2014-11-10 09:29:01 +08:00
void ImGui : : SetTooltip ( const char * fmt , . . . )
2014-09-25 02:27:29 +08:00
{
2014-08-19 19:09:13 +08:00
va_list args ;
va_start ( args , fmt ) ;
2014-09-25 02:27:29 +08:00
SetTooltipV ( fmt , args ) ;
2014-08-19 19:09:13 +08:00
va_end ( args ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
float ImGui : : GetTime ( )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
return GImGui - > Time ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
int ImGui : : GetFrameCount ( )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
return GImGui - > FrameCount ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : BeginTooltip ( )
2014-08-15 23:18:00 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2015-01-16 02:00:10 +08:00
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_Tooltip ;
ImGui : : Begin ( " ##Tooltip " , NULL , ImVec2 ( 0 , 0 ) , g . Style . Colors [ ImGuiCol_TooltipBg ] . w , window_flags ) ;
2014-08-15 23:18:00 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : EndTooltip ( )
2014-08-15 23:18:00 +08:00
{
2014-08-19 19:09:13 +08:00
IM_ASSERT ( GetCurrentWindow ( ) - > Flags & ImGuiWindowFlags_Tooltip ) ;
ImGui : : End ( ) ;
2014-08-15 23:18:00 +08:00
}
2015-02-22 20:38:46 +08:00
bool ImGui : : BeginChild ( const char * str_id , const ImVec2 & size_arg , bool border , ImGuiWindowFlags extra_flags )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-08-11 04:58:11 +08:00
2014-12-11 01:13:45 +08:00
ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_ChildWindow ;
2014-08-11 04:58:11 +08:00
2014-11-07 16:22:38 +08:00
const ImVec2 content_max = window - > Pos + ImGui : : GetContentRegionMax ( ) ;
2014-08-19 19:09:13 +08:00
const ImVec2 cursor_pos = window - > Pos + ImGui : : GetCursorPos ( ) ;
2015-02-22 20:38:46 +08:00
ImVec2 size = size_arg ;
2014-08-19 19:09:13 +08:00
if ( size . x < = 0.0f )
{
2014-11-07 16:22:38 +08:00
if ( size . x = = 0.0f )
flags | = ImGuiWindowFlags_ChildWindowAutoFitX ;
size . x = ImMax ( content_max . x - cursor_pos . x , g . Style . WindowMinSize . x ) - fabsf ( size . x ) ;
2014-08-19 19:09:13 +08:00
}
if ( size . y < = 0.0f )
{
2014-11-07 16:22:38 +08:00
if ( size . y = = 0.0f )
flags | = ImGuiWindowFlags_ChildWindowAutoFitY ;
size . y = ImMax ( content_max . y - cursor_pos . y , g . Style . WindowMinSize . y ) - fabsf ( size . y ) ;
2014-08-19 19:09:13 +08:00
}
if ( border )
flags | = ImGuiWindowFlags_ShowBorders ;
flags | = extra_flags ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
char title [ 256 ] ;
ImFormatString ( title , IM_ARRAYSIZE ( title ) , " %s.%s " , window - > Name , str_id ) ;
2014-08-11 04:58:11 +08:00
2015-02-10 21:00:22 +08:00
const float alpha = 1.0f ;
2015-02-21 18:30:05 +08:00
bool ret = ImGui : : Begin ( title , NULL , size , alpha , flags ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( ! ( window - > Flags & ImGuiWindowFlags_ShowBorders ) )
g . CurrentWindow - > Flags & = ~ ImGuiWindowFlags_ShowBorders ;
2015-02-21 18:30:05 +08:00
return ret ;
2014-08-11 04:58:11 +08:00
}
2015-02-22 20:38:46 +08:00
bool ImGui : : BeginChild ( ImGuiID id , const ImVec2 & size , bool border , ImGuiWindowFlags extra_flags )
2015-02-21 18:10:21 +08:00
{
char str_id [ 32 ] ;
ImFormatString ( str_id , IM_ARRAYSIZE ( str_id ) , " child_%x " , id ) ;
2015-02-21 18:30:05 +08:00
bool ret = ImGui : : BeginChild ( str_id , size , border , extra_flags ) ;
return ret ;
2015-02-21 18:10:21 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : EndChild ( )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-12-11 01:13:45 +08:00
IM_ASSERT ( window - > Flags & ImGuiWindowFlags_ChildWindow ) ;
2014-08-19 19:09:13 +08:00
if ( window - > Flags & ImGuiWindowFlags_ComboBox )
{
ImGui : : End ( ) ;
}
else
{
2014-09-02 21:35:06 +08:00
// When using auto-filling child window, we don't provide the width/height to ItemSize so that it doesn't feed back into automatic size-fitting.
2014-08-19 19:09:13 +08:00
ImVec2 sz = ImGui : : GetWindowSize ( ) ;
if ( window - > Flags & ImGuiWindowFlags_ChildWindowAutoFitX )
sz . x = 0 ;
if ( window - > Flags & ImGuiWindowFlags_ChildWindowAutoFitY )
sz . y = 0 ;
ImGui : : End ( ) ;
2014-11-10 09:29:01 +08:00
ItemSize ( sz ) ;
2014-08-19 19:09:13 +08:00
}
2014-08-11 04:58:11 +08:00
}
2015-02-11 05:21:23 +08:00
// Helper to create a child window / scrolling region that looks like a normal widget frame.
void ImGui : : BeginChildFrame ( ImGuiID id , const ImVec2 & size )
{
ImGuiState & g = * GImGui ;
const ImGuiStyle & style = g . Style ;
ImGui : : PushStyleColor ( ImGuiCol_ChildWindowBg , style . Colors [ ImGuiCol_FrameBg ] ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_ChildWindowRounding , style . FrameRounding ) ;
ImGui : : BeginChild ( id , size ) ;
}
void ImGui : : EndChildFrame ( )
{
ImGui : : EndChild ( ) ;
ImGui : : PopStyleVar ( ) ;
ImGui : : PopStyleColor ( ) ;
}
2014-12-29 01:54:02 +08:00
static ImGuiWindow * FindWindowByName ( const char * name )
{
// FIXME-OPT: Consider optimizing this (e.g. sorted hashes to window pointers)
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-12-29 01:54:02 +08:00
for ( size_t i = 0 ; i ! = g . Windows . size ( ) ; i + + )
if ( strcmp ( g . Windows [ i ] - > Name , name ) = = 0 )
return g . Windows [ i ] ;
return NULL ;
}
static ImGuiWindow * CreateNewWindow ( const char * name , ImVec2 size , ImGuiWindowFlags flags )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-12-29 01:54:02 +08:00
// Create window the first time
ImGuiWindow * window = ( ImGuiWindow * ) ImGui : : MemAlloc ( sizeof ( ImGuiWindow ) ) ;
new ( window ) ImGuiWindow ( name ) ;
window - > Flags = flags ;
if ( flags & ImGuiWindowFlags_NoSavedSettings )
{
2014-12-29 19:23:03 +08:00
// User can disable loading and saving of settings. Tooltip and child windows also don't store settings.
2014-12-29 01:54:02 +08:00
window - > Size = window - > SizeFull = size ;
}
else
{
// Retrieve settings from .ini file
2014-12-29 19:23:03 +08:00
// Use SetWindowPos() or SetNextWindowPos() with the appropriate condition flag to change the initial position of a window.
2014-12-29 01:54:02 +08:00
window - > PosFloat = ImVec2 ( 60 , 60 ) ;
window - > Pos = ImVec2 ( ( float ) ( int ) window - > PosFloat . x , ( float ) ( int ) window - > PosFloat . y ) ;
ImGuiIniData * settings = FindWindowSettings ( name ) ;
if ( ! settings )
{
settings = AddWindowSettings ( name ) ;
}
else
{
window - > SetWindowPosAllowFlags & = ~ ImGuiSetCondition_FirstUseEver ;
window - > SetWindowSizeAllowFlags & = ~ ImGuiSetCondition_FirstUseEver ;
window - > SetWindowCollapsedAllowFlags & = ~ ImGuiSetCondition_FirstUseEver ;
}
if ( settings - > Pos . x ! = FLT_MAX )
{
window - > PosFloat = settings - > Pos ;
window - > Pos = ImVec2 ( ( float ) ( int ) window - > PosFloat . x , ( float ) ( int ) window - > PosFloat . y ) ;
window - > Collapsed = settings - > Collapsed ;
}
2014-12-29 19:23:03 +08:00
if ( ImLengthSqr ( settings - > Size ) > 0.00001f & & ! ( flags & ImGuiWindowFlags_NoResize ) )
2014-12-29 01:54:02 +08:00
size = settings - > Size ;
window - > Size = window - > SizeFull = size ;
}
g . Windows . push_back ( window ) ;
return window ;
}
2014-12-11 03:22:30 +08:00
// Push a new ImGui window to add widgets to.
2015-02-22 20:38:46 +08:00
// - '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.
// - 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.
// - Begin/End can be called multiple times during the frame with the same window name to append content.
2014-12-22 21:29:39 +08:00
// - 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.
// - 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.
// - 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.
// - Passing non-zero 'size' is roughly equivalent to calling SetNextWindowSize(size, ImGuiSetCondition_FirstUseEver) prior to calling Begin().
2015-02-22 20:38:46 +08:00
bool ImGui : : Begin ( const char * name , bool * p_opened , const ImVec2 & size , float bg_alpha , ImGuiWindowFlags flags )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
const ImGuiStyle & style = g . Style ;
2014-11-14 10:17:59 +08:00
IM_ASSERT ( g . Initialized ) ; // Forgot to call ImGui::NewFrame()
2014-12-22 21:29:39 +08:00
IM_ASSERT ( name ! = NULL ) ; // Must pass a name
2014-08-19 19:09:13 +08:00
2014-12-29 01:54:02 +08:00
// Find or create
ImGuiWindow * window = FindWindowByName ( name ) ;
2014-08-19 19:09:13 +08:00
if ( ! window )
2014-12-29 01:54:02 +08:00
window = CreateNewWindow ( name , size , flags ) ;
2014-08-19 19:09:13 +08:00
window - > Flags = ( ImGuiWindowFlags ) flags ;
2014-12-29 01:54:02 +08:00
// Add to stack
2014-08-19 19:09:13 +08:00
g . CurrentWindowStack . push_back ( window ) ;
g . CurrentWindow = window ;
2014-12-11 03:22:30 +08:00
// Process SetNextWindow***() calls
2015-01-16 01:47:53 +08:00
bool window_pos_set_by_api = false ;
2014-12-11 03:22:30 +08:00
if ( g . SetNextWindowPosCond )
{
const ImVec2 backup_cursor_pos = window - > DC . CursorPos ;
ImGui : : SetWindowPos ( g . SetNextWindowPosVal , g . SetNextWindowPosCond ) ;
window - > DC . CursorPos = backup_cursor_pos ;
2015-01-16 01:47:53 +08:00
window_pos_set_by_api = true ;
2014-12-11 03:22:30 +08:00
g . SetNextWindowPosCond = 0 ;
}
if ( g . SetNextWindowSizeCond )
{
ImGui : : SetWindowSize ( g . SetNextWindowSizeVal , g . SetNextWindowSizeCond ) ;
g . SetNextWindowSizeCond = 0 ;
}
if ( g . SetNextWindowCollapsedCond )
{
ImGui : : SetWindowCollapsed ( g . SetNextWindowCollapsedVal , g . SetNextWindowCollapsedCond ) ;
g . SetNextWindowCollapsedCond = 0 ;
}
2015-01-29 21:07:20 +08:00
// Find parent
ImGuiWindow * parent_window = ( flags & ImGuiWindowFlags_ChildWindow ) ! = 0 ? g . CurrentWindowStack [ g . CurrentWindowStack . size ( ) - 2 ] : NULL ;
2014-12-29 01:54:02 +08:00
// Find root (if we are a child window)
2014-12-04 00:54:04 +08:00
size_t root_idx = g . CurrentWindowStack . size ( ) - 1 ;
while ( root_idx > 0 )
{
if ( ( g . CurrentWindowStack [ root_idx ] - > Flags & ImGuiWindowFlags_ChildWindow ) = = 0 )
break ;
root_idx - - ;
}
window - > RootWindow = g . CurrentWindowStack [ root_idx ] ;
2014-08-19 19:09:13 +08:00
// Default alpha
2015-02-22 20:38:46 +08:00
if ( bg_alpha < 0.0f )
bg_alpha = style . WindowFillAlphaDefault ;
2014-08-19 19:09:13 +08:00
// When reusing window again multiple times a frame, just append content (don't need to setup again)
const int current_frame = ImGui : : GetFrameCount ( ) ;
const bool first_begin_of_the_frame = ( window - > LastFrameDrawn ! = current_frame ) ;
if ( first_begin_of_the_frame )
{
window - > DrawList - > Clear ( ) ;
window - > Visible = true ;
// New windows appears in front
if ( window - > LastFrameDrawn < current_frame - 1 )
2014-11-10 09:29:01 +08:00
FocusWindow ( window ) ;
2014-08-19 19:09:13 +08:00
window - > LastFrameDrawn = current_frame ;
window - > ClipRectStack . resize ( 0 ) ;
if ( flags & ImGuiWindowFlags_ChildWindow )
{
parent_window - > DC . ChildWindows . push_back ( window ) ;
window - > Pos = window - > PosFloat = parent_window - > DC . CursorPos ;
window - > SizeFull = size ;
}
2015-01-29 21:20:25 +08:00
}
2014-08-19 19:09:13 +08:00
2015-01-29 21:20:25 +08:00
// Setup texture
window - > DrawList - > PushTextureID ( g . Font - > ContainerAtlas - > TexID ) ;
// Setup outer clipping rectangle
if ( ( flags & ImGuiWindowFlags_ChildWindow ) & & ! ( flags & ImGuiWindowFlags_ComboBox ) )
PushClipRect ( parent_window - > ClipRectStack . back ( ) ) ;
else if ( g . IO . DisplayVisibleMin . x ! = g . IO . DisplayVisibleMax . x & & g . IO . DisplayVisibleMin . y ! = g . IO . DisplayVisibleMax . y )
PushClipRect ( ImVec4 ( g . IO . DisplayVisibleMin . x , g . IO . DisplayVisibleMin . y , g . IO . DisplayVisibleMax . x , g . IO . DisplayVisibleMax . y ) ) ;
else
PushClipRect ( ImVec4 ( 0.0f , 0.0f , g . IO . DisplaySize . x , g . IO . DisplaySize . y ) ) ;
2014-08-19 19:09:13 +08:00
2015-01-29 21:20:25 +08:00
// Setup and draw window
if ( first_begin_of_the_frame )
{
2014-09-02 21:35:06 +08:00
// Seed ID stack with our window pointer
2014-08-19 19:09:13 +08:00
window - > IDStack . resize ( 0 ) ;
ImGui : : PushID ( window ) ;
2015-01-05 02:23:30 +08:00
// Move window (at the beginning of the frame to avoid input lag or sheering)
2014-08-19 19:09:13 +08:00
const ImGuiID move_id = window - > GetID ( " #MOVE " ) ;
RegisterAliveId ( move_id ) ;
if ( g . ActiveId = = move_id )
{
if ( g . IO . MouseDown [ 0 ] )
{
if ( ! ( window - > Flags & ImGuiWindowFlags_NoMove ) )
{
window - > PosFloat + = g . IO . MouseDelta ;
2015-01-05 02:23:30 +08:00
if ( ! ( window - > Flags & ImGuiWindowFlags_NoSavedSettings ) )
MarkSettingsDirty ( ) ;
2014-08-19 19:09:13 +08:00
}
2014-11-10 09:29:01 +08:00
FocusWindow ( window ) ;
2014-08-19 19:09:13 +08:00
}
else
{
2015-02-01 06:57:59 +08:00
SetActiveId ( 0 ) ;
2014-08-19 19:09:13 +08:00
}
}
2015-01-16 01:47:53 +08:00
// Tooltips always follows mouse
if ( ! window_pos_set_by_api & & ( window - > Flags & ImGuiWindowFlags_Tooltip ) ! = 0 )
2014-08-19 19:09:13 +08:00
{
2014-12-30 23:38:28 +08:00
window - > PosFloat = g . IO . MousePos + ImVec2 ( 32 , 16 ) - style . FramePadding * 2 ;
2014-08-19 19:09:13 +08:00
}
// Clamp into view
2015-01-15 06:10:48 +08:00
if ( ! ( window - > Flags & ImGuiWindowFlags_ChildWindow ) & & ! ( window - > Flags & ImGuiWindowFlags_Tooltip ) )
2014-08-19 19:09:13 +08:00
{
2015-01-29 21:20:25 +08:00
// FIXME: Parameterize padding.
2015-01-14 07:05:20 +08:00
const ImVec2 pad = ImVec2 ( window - > FontSize ( ) * 2.0f , window - > FontSize ( ) * 2.0f ) ; // FIXME: Parametrize of clarify this behavior.
2014-12-22 10:14:25 +08:00
if ( g . IO . DisplaySize . x > 0.0f & & g . IO . DisplaySize . y > 0.0f ) // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing.
{
2015-01-29 21:20:25 +08:00
ImVec2 clip_min = pad ;
ImVec2 clip_max = g . IO . DisplaySize - pad ;
window - > PosFloat = ImMax ( window - > PosFloat + window - > Size , clip_min ) - window - > Size ;
window - > PosFloat = ImMin ( window - > PosFloat , clip_max ) ;
2014-12-22 10:14:25 +08:00
}
2015-01-14 07:05:20 +08:00
window - > SizeFull = ImMax ( window - > SizeFull , style . WindowMinSize ) ;
2014-08-19 19:09:13 +08:00
}
2014-09-02 21:35:06 +08:00
window - > Pos = ImVec2 ( ( float ) ( int ) window - > PosFloat . x , ( float ) ( int ) window - > PosFloat . y ) ;
2014-08-19 19:09:13 +08:00
2015-01-16 01:47:53 +08:00
// Default item width. Make it proportional to window size if window manually resizes
2014-11-22 00:29:56 +08:00
if ( window - > Size . x > 0.0f & & ! ( window - > Flags & ImGuiWindowFlags_Tooltip ) & & ! ( window - > Flags & ImGuiWindowFlags_AlwaysAutoResize ) )
2014-08-19 19:09:13 +08:00
window - > ItemWidthDefault = ( float ) ( int ) ( window - > Size . x * 0.65f ) ;
else
window - > ItemWidthDefault = 200.0f ;
2014-09-30 19:31:35 +08:00
// Prepare for focus requests
if ( window - > FocusIdxAllRequestNext = = IM_INT_MAX | | window - > FocusIdxAllCounter = = - 1 )
window - > FocusIdxAllRequestCurrent = IM_INT_MAX ;
else
window - > FocusIdxAllRequestCurrent = ( window - > FocusIdxAllRequestNext + ( window - > FocusIdxAllCounter + 1 ) ) % ( window - > FocusIdxAllCounter + 1 ) ;
2014-09-30 19:22:58 +08:00
if ( window - > FocusIdxTabRequestNext = = IM_INT_MAX | | window - > FocusIdxTabCounter = = - 1 )
window - > FocusIdxTabRequestCurrent = IM_INT_MAX ;
2014-08-19 19:09:13 +08:00
else
2014-09-30 19:31:35 +08:00
window - > FocusIdxTabRequestCurrent = ( window - > FocusIdxTabRequestNext + ( window - > FocusIdxTabCounter + 1 ) ) % ( window - > FocusIdxTabCounter + 1 ) ;
window - > FocusIdxAllCounter = window - > FocusIdxTabCounter = - 1 ;
2014-09-30 19:22:58 +08:00
window - > FocusIdxAllRequestNext = window - > FocusIdxTabRequestNext = IM_INT_MAX ;
2014-08-19 19:09:13 +08:00
ImGuiAabb title_bar_aabb = window - > TitleBarAabb ( ) ;
// Apply and ImClamp scrolling
window - > ScrollY = window - > NextScrollY ;
window - > ScrollY = ImMax ( window - > ScrollY , 0.0f ) ;
if ( ! window - > Collapsed & & ! window - > SkipItems )
window - > ScrollY = ImMin ( window - > ScrollY , ImMax ( 0.0f , ( float ) window - > SizeContentsFit . y - window - > SizeFull . y ) ) ;
window - > NextScrollY = window - > ScrollY ;
2014-09-02 21:35:06 +08:00
// At this point we don't have a clipping rectangle setup yet, so we can test and draw in title bar
2014-08-19 19:09:13 +08:00
// Collapse window by double-clicking on title bar
if ( ! ( window - > Flags & ImGuiWindowFlags_NoTitleBar ) )
{
2015-02-02 17:49:12 +08:00
if ( ! ( window - > Flags & ImGuiWindowFlags_NoCollapse ) & & g . HoveredWindow = = window & & IsMouseHoveringBox ( title_bar_aabb ) & & g . IO . MouseDoubleClicked [ 0 ] )
2014-08-19 19:09:13 +08:00
{
window - > Collapsed = ! window - > Collapsed ;
2015-01-05 02:23:30 +08:00
if ( ! ( window - > Flags & ImGuiWindowFlags_NoSavedSettings ) )
MarkSettingsDirty ( ) ;
2014-11-10 09:29:01 +08:00
FocusWindow ( window ) ;
2014-08-19 19:09:13 +08:00
}
}
else
{
window - > Collapsed = false ;
}
2015-02-10 21:00:22 +08:00
const float window_rounding = ( window - > Flags & ImGuiWindowFlags_ChildWindow ) ? style . ChildWindowRounding : style . WindowRounding ;
2014-08-19 19:09:13 +08:00
if ( window - > Collapsed )
{
2014-09-02 21:35:06 +08:00
// Draw title bar only
2014-08-19 19:09:13 +08:00
window - > Size = title_bar_aabb . GetSize ( ) ;
2015-02-10 21:00:22 +08:00
window - > DrawList - > AddRectFilled ( title_bar_aabb . GetTL ( ) , title_bar_aabb . GetBR ( ) , window - > Color ( ImGuiCol_TitleBgCollapsed ) , window_rounding ) ;
2014-08-19 19:09:13 +08:00
if ( window - > Flags & ImGuiWindowFlags_ShowBorders )
{
2015-02-10 21:00:22 +08:00
window - > DrawList - > AddRect ( title_bar_aabb . GetTL ( ) + ImVec2 ( 1 , 1 ) , title_bar_aabb . GetBR ( ) + ImVec2 ( 1 , 1 ) , window - > Color ( ImGuiCol_BorderShadow ) , window_rounding ) ;
window - > DrawList - > AddRect ( title_bar_aabb . GetTL ( ) , title_bar_aabb . GetBR ( ) , window - > Color ( ImGuiCol_Border ) , window_rounding ) ;
2014-08-19 19:09:13 +08:00
}
}
else
{
window - > Size = window - > SizeFull ;
ImU32 resize_col = 0 ;
if ( ( window - > Flags & ImGuiWindowFlags_Tooltip ) ! = 0 )
{
2015-01-16 02:00:10 +08:00
// Tooltip always resize. We keep the spacing symmetric on both axises for aesthetic purpose.
const ImVec2 size_auto_fit = window - > SizeContentsFit + style . WindowPadding - ImVec2 ( 0.0f , style . ItemSpacing . y ) ;
window - > SizeFull = size_auto_fit ;
2014-08-19 19:09:13 +08:00
}
2014-10-27 04:07:15 +08:00
else
2014-08-19 19:09:13 +08:00
{
2014-12-22 10:14:25 +08:00
const ImVec2 size_auto_fit = ImClamp ( window - > SizeContentsFit + style . AutoFitPadding , style . WindowMinSize , ImMax ( style . WindowMinSize , g . IO . DisplaySize - style . AutoFitPadding ) ) ;
2014-11-22 00:29:56 +08:00
if ( ( window - > Flags & ImGuiWindowFlags_AlwaysAutoResize ) ! = 0 )
{
2014-12-04 00:54:04 +08:00
// Don't continuously mark settings as dirty, the size of the window doesn't need to be stored.
2014-11-22 00:29:56 +08:00
window - > SizeFull = size_auto_fit ;
}
else if ( window - > AutoFitFrames > 0 )
2014-08-19 19:09:13 +08:00
{
// Auto-fit only grows during the first few frames
2014-11-22 00:29:56 +08:00
if ( window - > AutoFitOnlyGrows )
window - > SizeFull = ImMax ( window - > SizeFull , size_auto_fit ) ;
else
window - > SizeFull = size_auto_fit ;
2015-01-05 02:23:30 +08:00
if ( ! ( window - > Flags & ImGuiWindowFlags_NoSavedSettings ) )
MarkSettingsDirty ( ) ;
2014-08-19 19:09:13 +08:00
}
2014-10-27 04:07:15 +08:00
else if ( ! ( window - > Flags & ImGuiWindowFlags_NoResize ) )
2014-08-19 19:09:13 +08:00
{
2015-01-16 01:47:53 +08:00
// Manual resize grip
2014-10-27 04:07:15 +08:00
const ImGuiAabb resize_aabb ( window - > Aabb ( ) . GetBR ( ) - ImVec2 ( 18 , 18 ) , window - > Aabb ( ) . GetBR ( ) ) ;
2014-12-04 00:54:04 +08:00
const ImGuiID resize_id = window - > GetID ( " ##RESIZE " ) ;
2014-10-27 04:07:15 +08:00
bool hovered , held ;
ButtonBehaviour ( resize_aabb , resize_id , & hovered , & held , true ) ;
resize_col = window - > Color ( held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip ) ;
if ( g . HoveredWindow = = window & & held & & g . IO . MouseDoubleClicked [ 0 ] )
{
2015-01-16 01:47:53 +08:00
// Manual auto-fit when double-clicking
2014-10-27 04:07:15 +08:00
window - > SizeFull = size_auto_fit ;
window - > Size = window - > SizeFull ;
2015-01-05 02:23:30 +08:00
if ( ! ( window - > Flags & ImGuiWindowFlags_NoSavedSettings ) )
MarkSettingsDirty ( ) ;
2014-10-27 04:07:15 +08:00
}
else if ( held )
{
// Resize
window - > SizeFull = ImMax ( window - > SizeFull + g . IO . MouseDelta , style . WindowMinSize ) ;
window - > Size = window - > SizeFull ;
2015-01-05 02:23:30 +08:00
if ( ! ( window - > Flags & ImGuiWindowFlags_NoSavedSettings ) )
MarkSettingsDirty ( ) ;
2014-10-27 04:07:15 +08:00
}
2014-08-19 19:09:13 +08:00
}
2015-01-16 01:47:53 +08:00
// Update aabb immediately so that rendering right below us isn't one frame late
2014-08-19 19:09:13 +08:00
title_bar_aabb = window - > TitleBarAabb ( ) ;
}
2015-02-10 21:00:22 +08:00
// Scrollbar
window - > ScrollbarY = ( window - > SizeContentsFit . y > window - > Size . y ) & & ! ( window - > Flags & ImGuiWindowFlags_NoScrollbar ) ;
// Window background
2015-02-22 20:38:46 +08:00
if ( bg_alpha > 0.0f )
2014-08-19 19:09:13 +08:00
{
if ( ( window - > Flags & ImGuiWindowFlags_ComboBox ) ! = 0 )
2015-02-22 20:38:46 +08:00
window - > DrawList - > AddRectFilled ( window - > Pos , window - > Pos + window - > Size , window - > Color ( ImGuiCol_ComboBg , bg_alpha ) , window_rounding ) ;
2015-01-15 06:10:48 +08:00
else if ( ( window - > Flags & ImGuiWindowFlags_Tooltip ) ! = 0 )
2015-02-22 20:38:46 +08:00
window - > DrawList - > AddRectFilled ( window - > Pos , window - > Pos + window - > Size , window - > Color ( ImGuiCol_TooltipBg , bg_alpha ) , window_rounding ) ;
2015-02-10 21:00:22 +08:00
else if ( ( window - > Flags & ImGuiWindowFlags_ChildWindow ) ! = 0 )
2015-02-22 20:38:46 +08:00
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 ) ) ;
2014-08-19 19:09:13 +08:00
else
2015-02-22 20:38:46 +08:00
window - > DrawList - > AddRectFilled ( window - > Pos , window - > Pos + window - > Size , window - > Color ( ImGuiCol_WindowBg , bg_alpha ) , window_rounding ) ;
2014-08-19 19:09:13 +08:00
}
2015-02-10 21:00:22 +08:00
// Title bar
2014-08-19 19:09:13 +08:00
if ( ! ( window - > Flags & ImGuiWindowFlags_NoTitleBar ) )
2015-02-10 21:00:22 +08:00
window - > DrawList - > AddRectFilled ( title_bar_aabb . GetTL ( ) , title_bar_aabb . GetBR ( ) , window - > Color ( ImGuiCol_TitleBg ) , window_rounding , 1 | 2 ) ;
2014-08-19 19:09:13 +08:00
2014-09-25 03:39:39 +08:00
// Borders
2014-08-19 19:09:13 +08:00
if ( window - > Flags & ImGuiWindowFlags_ShowBorders )
{
2015-02-10 21:00:22 +08:00
window - > DrawList - > AddRect ( window - > Pos + ImVec2 ( 1 , 1 ) , window - > Pos + window - > Size + ImVec2 ( 1 , 1 ) , window - > Color ( ImGuiCol_BorderShadow ) , window_rounding ) ;
window - > DrawList - > AddRect ( window - > Pos , window - > Pos + window - > Size , window - > Color ( ImGuiCol_Border ) , window_rounding ) ;
2014-08-19 19:09:13 +08:00
if ( ! ( window - > Flags & ImGuiWindowFlags_NoTitleBar ) )
window - > DrawList - > AddLine ( title_bar_aabb . GetBL ( ) , title_bar_aabb . GetBR ( ) , window - > Color ( ImGuiCol_Border ) ) ;
}
// Scrollbar
if ( window - > ScrollbarY )
{
ImGuiAabb scrollbar_bb ( window - > Aabb ( ) . Max . x - style . ScrollBarWidth , title_bar_aabb . Max . y + 1 , window - > Aabb ( ) . Max . x , window - > Aabb ( ) . Max . y - 1 ) ;
//window->DrawList->AddLine(scrollbar_bb.GetTL(), scrollbar_bb.GetBL(), g.Colors[ImGuiCol_Border]);
window - > DrawList - > AddRectFilled ( scrollbar_bb . Min , scrollbar_bb . Max , window - > Color ( ImGuiCol_ScrollbarBg ) ) ;
2014-08-28 05:16:55 +08:00
scrollbar_bb . Expand ( ImVec2 ( - 3 , - 3 ) ) ;
2014-08-19 19:09:13 +08:00
const float grab_size_y_norm = ImSaturate ( window - > Size . y / ImMax ( window - > SizeContentsFit . y , window - > Size . y ) ) ;
const float grab_size_y = scrollbar_bb . GetHeight ( ) * grab_size_y_norm ;
2014-09-02 21:35:06 +08:00
// Handle input right away (none of the code above is relying on scrolling position)
2014-08-19 19:09:13 +08:00
bool held = false ;
bool hovered = false ;
if ( grab_size_y_norm < 1.0f )
{
const ImGuiID scrollbar_id = window - > GetID ( " #SCROLLY " ) ;
ButtonBehaviour ( scrollbar_bb , scrollbar_id , & hovered , & held , true ) ;
if ( held )
{
g . HoveredId = scrollbar_id ;
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 ) ;
2015-02-08 21:29:55 +08:00
window - > ScrollY = ( float ) ( int ) ( pos_y_norm * window - > SizeContentsFit . y ) ;
2014-08-19 19:09:13 +08:00
window - > NextScrollY = window - > ScrollY ;
}
}
// Normalized height of the grab
const float pos_y_norm = ImSaturate ( window - > ScrollY / ImMax ( 0.0f , window - > SizeContentsFit . y ) ) ;
const ImU32 grab_col = window - > Color ( held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab ) ;
window - > DrawList - > AddRectFilled (
ImVec2 ( scrollbar_bb . Min . x , ImLerp ( scrollbar_bb . Min . y , scrollbar_bb . Max . y , pos_y_norm ) ) ,
ImVec2 ( scrollbar_bb . Max . x , ImLerp ( scrollbar_bb . Min . y , scrollbar_bb . Max . y , pos_y_norm + grab_size_y_norm ) ) , grab_col ) ;
}
// Render resize grip
// (after the input handling so we don't have a frame of latency)
if ( ! ( window - > Flags & ImGuiWindowFlags_NoResize ) )
{
2015-02-10 21:00:22 +08:00
const float r = window_rounding ;
2014-08-19 19:09:13 +08:00
const ImVec2 br = window - > Aabb ( ) . GetBR ( ) ;
if ( r = = 0.0f )
{
window - > DrawList - > AddTriangleFilled ( br , br - ImVec2 ( 0 , 14 ) , br - ImVec2 ( 14 , 0 ) , resize_col ) ;
}
else
{
2015-01-18 01:03:22 +08:00
// FIXME: We should draw 4 triangles and decide on a size that's not dependent on the rounding size (previously used 18)
2014-08-19 19:09:13 +08:00
window - > DrawList - > AddArc ( br - ImVec2 ( r , r ) , r , resize_col , 6 , 9 , true ) ;
2015-01-18 01:17:18 +08:00
window - > DrawList - > AddTriangleFilled ( br + ImVec2 ( 0 , - 2 * r ) , br + ImVec2 ( 0 , - r ) , br + ImVec2 ( - r , - r ) , resize_col ) ;
window - > DrawList - > AddTriangleFilled ( br + ImVec2 ( - r , - r ) , br + ImVec2 ( - r , 0 ) , br + ImVec2 ( - 2 * r , 0 ) , resize_col ) ;
2014-08-19 19:09:13 +08:00
}
}
}
// Setup drawing context
2014-11-20 19:31:55 +08:00
window - > DC . ColumnsStartX = window - > WindowPadding ( ) . x ;
window - > DC . ColumnsOffsetX = 0.0f ;
window - > DC . CursorStartPos = window - > Pos + ImVec2 ( window - > DC . ColumnsStartX + window - > DC . ColumnsOffsetX , window - > TitleBarHeight ( ) + window - > WindowPadding ( ) . y ) - ImVec2 ( 0.0f , window - > ScrollY ) ;
2014-08-19 19:09:13 +08:00
window - > DC . CursorPos = window - > DC . CursorStartPos ;
window - > DC . CursorPosPrevLine = window - > DC . CursorPos ;
window - > DC . CurrentLineHeight = window - > DC . PrevLineHeight = 0.0f ;
window - > DC . LogLineHeight = window - > DC . CursorPos . y - 9999.0f ;
window - > DC . ChildWindows . resize ( 0 ) ;
window - > DC . ItemWidth . resize ( 0 ) ;
window - > DC . ItemWidth . push_back ( window - > ItemWidthDefault ) ;
window - > DC . AllowKeyboardFocus . resize ( 0 ) ;
window - > DC . AllowKeyboardFocus . push_back ( true ) ;
2014-11-07 13:45:56 +08:00
window - > DC . TextWrapPos . resize ( 0 ) ;
window - > DC . TextWrapPos . push_back ( - 1.0f ) ; // disabled
2014-08-19 19:09:13 +08:00
window - > DC . ColorEditMode = ImGuiColorEditMode_UserSelect ;
2014-11-20 19:31:55 +08:00
window - > DC . ColumnsCurrent = 0 ;
2014-08-19 19:09:13 +08:00
window - > DC . ColumnsCount = 1 ;
2014-11-20 19:31:55 +08:00
window - > DC . ColumnsStartPos = window - > DC . CursorPos ;
window - > DC . ColumnsCellMinY = window - > DC . ColumnsCellMaxY = window - > DC . ColumnsStartPos . y ;
2014-08-19 19:09:13 +08:00
window - > DC . TreeDepth = 0 ;
window - > DC . StateStorage = & window - > StateStorage ;
window - > DC . OpenNextNode = - 1 ;
// Reset contents size for auto-fitting
window - > SizeContentsFit = ImVec2 ( 0.0f , 0.0f ) ;
if ( window - > AutoFitFrames > 0 )
window - > AutoFitFrames - - ;
// Title bar
if ( ! ( window - > Flags & ImGuiWindowFlags_NoTitleBar ) )
{
2014-12-22 21:29:39 +08:00
if ( p_opened ! = NULL )
CloseWindowButton ( p_opened ) ;
2014-08-19 19:09:13 +08:00
2015-02-02 17:49:12 +08:00
ImVec2 text_min = window - > Pos + style . FramePadding ;
if ( ! ( window - > Flags & ImGuiWindowFlags_NoCollapse ) )
{
RenderCollapseTriangle ( window - > Pos + style . FramePadding , ! window - > Collapsed , 1.0f , true ) ;
text_min . x + = window - > FontSize ( ) + style . ItemInnerSpacing . x ;
}
2014-12-29 00:17:08 +08:00
const ImVec2 text_size = CalcTextSize ( name , NULL , true ) ;
2015-02-10 04:31:59 +08:00
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 ) ;
2015-02-09 00:39:34 +08:00
RenderTextClipped ( text_min , name , NULL , & text_size , text_max ) ;
2014-08-19 19:09:13 +08:00
}
2015-02-22 20:05:38 +08:00
// Save clipped aabb so we can access it in constant-time in FindHoveredWindow()
window - > ClippedAabb = window - > Aabb ( ) ;
window - > ClippedAabb . Clip ( window - > ClipRectStack . front ( ) ) ;
2014-08-19 19:09:13 +08:00
}
// Inner clipping rectangle
// We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame
const ImGuiAabb title_bar_aabb = window - > TitleBarAabb ( ) ;
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 ) ;
if ( window - > ScrollbarY )
2014-12-30 23:38:28 +08:00
clip_rect . z - = style . ScrollBarWidth ;
2014-11-10 09:29:01 +08:00
PushClipRect ( clip_rect ) ;
2014-08-19 19:09:13 +08:00
2014-09-02 21:35:06 +08:00
// Clear 'accessed' flag last thing
2014-08-19 19:09:13 +08:00
if ( first_begin_of_the_frame )
window - > Accessed = false ;
// Child window can be out of sight and have "negative" clip windows.
// Mark them as collapsed so commands are skipped earlier (we can't manually collapse because they have no title bar).
if ( flags & ImGuiWindowFlags_ChildWindow )
{
IM_ASSERT ( ( flags & ImGuiWindowFlags_NoTitleBar ) ! = 0 ) ;
2015-02-21 18:02:32 +08:00
window - > Collapsed = parent_window & & parent_window - > Collapsed ;
2014-11-18 03:35:58 +08:00
const ImVec4 clip_rect_t = window - > ClipRectStack . back ( ) ;
2015-02-21 18:02:32 +08:00
window - > Collapsed | = ( clip_rect_t . x > = clip_rect_t . z | | clip_rect_t . y > = clip_rect_t . w ) ;
2014-08-19 19:09:13 +08:00
// We also hide the window from rendering because we've already added its border to the command list.
2014-11-18 15:51:55 +08:00
// (we could perform the check earlier in the function but it is simpler at this point)
2014-08-19 19:09:13 +08:00
if ( window - > Collapsed )
window - > Visible = false ;
}
2014-12-30 23:38:28 +08:00
if ( style . Alpha < = 0.0f )
2014-08-19 19:09:13 +08:00
window - > Visible = false ;
2014-12-30 23:38:28 +08:00
// Return false if we don't intend to display anything to allow user to perform an early out optimization
2014-08-19 19:09:13 +08:00
window - > SkipItems = window - > Collapsed | | ( ! window - > Visible & & window - > AutoFitFrames = = 0 ) ;
return ! window - > SkipItems ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : End ( )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = g . CurrentWindow ;
ImGui : : Columns ( 1 , " #CloseColumns " ) ;
2014-11-10 09:29:01 +08:00
PopClipRect ( ) ; // inner window clip rectangle
PopClipRect ( ) ; // outer window clip rectangle
2015-01-12 00:30:39 +08:00
window - > DrawList - > PopTextureID ( ) ;
2014-08-19 19:09:13 +08:00
// Stop logging
2014-09-02 21:35:06 +08:00
if ( ! ( window - > Flags & ImGuiWindowFlags_ChildWindow ) ) // FIXME: add more options for scope of logging
2014-12-30 02:13:41 +08:00
ImGui : : LogFinish ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
// Pop
2015-01-05 06:07:37 +08:00
// NB: we don't clear 'window->RootWindow' yet, it will be used then cleared in NewFrame()
2014-08-19 19:09:13 +08:00
g . CurrentWindowStack . pop_back ( ) ;
g . CurrentWindow = g . CurrentWindowStack . empty ( ) ? NULL : g . CurrentWindowStack . back ( ) ;
2014-08-11 04:58:11 +08:00
}
2015-01-05 02:23:30 +08:00
// Moving window to front of display (which happens to be back of our sorted list)
2014-08-11 04:58:11 +08:00
static void FocusWindow ( ImGuiWindow * window )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
g . FocusedWindow = window ;
2014-08-11 04:58:11 +08:00
2015-01-05 02:23:30 +08:00
if ( g . Windows . back ( ) = = window )
return ;
2014-08-19 19:09:13 +08:00
for ( size_t i = 0 ; i < g . Windows . size ( ) ; i + + )
if ( g . Windows [ i ] = = window )
{
g . Windows . erase ( g . Windows . begin ( ) + i ) ;
break ;
}
g . Windows . push_back ( window ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : PushItemWidth ( float item_width )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2015-02-11 05:07:26 +08:00
window - > DC . ItemWidth . push_back ( item_width = = 0.0f ? window - > ItemWidthDefault : item_width ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : PopItemWidth ( )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > DC . ItemWidth . pop_back ( ) ;
2014-08-11 04:58:11 +08:00
}
2015-02-11 05:07:26 +08:00
float ImGui : : CalcItemWidth ( )
2014-08-12 07:04:13 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2015-02-11 05:07:26 +08:00
float w = window - > DC . ItemWidth . back ( ) ;
if ( w < 0.0f )
{
2015-02-11 05:42:21 +08:00
// Align to a right-side limit. We include 1 frame padding in the calculation because this is how the width is always used (we add 2 frame padding to it), but we could move that responsibility to the widget as well.
ImGuiState & g = * GImGui ;
2015-02-11 05:07:26 +08:00
w = - w ;
float width_to_right_edge = window - > Pos . x + ImGui : : GetContentRegionMax ( ) . x - window - > DC . CursorPos . x ;
2015-02-11 05:42:21 +08:00
w = ImMax ( 1.0f , width_to_right_edge - w - g . Style . FramePadding . x * 2.0f ) ;
2015-02-11 05:07:26 +08:00
}
2015-02-11 05:42:21 +08:00
w = ( float ) ( int ) w ;
2015-02-11 05:07:26 +08:00
return w ;
2014-08-12 07:04:13 +08:00
}
2015-01-17 21:40:56 +08:00
static void SetFont ( ImFont * font )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2015-01-17 21:40:56 +08:00
2015-01-18 06:15:29 +08:00
IM_ASSERT ( font & & font - > IsLoaded ( ) ) ;
2015-01-17 21:40:56 +08:00
IM_ASSERT ( font - > Scale > 0.0f ) ;
g . Font = font ;
g . FontSize = g . IO . FontGlobalScale * g . Font - > FontSize * g . Font - > Scale ;
2015-01-18 06:15:29 +08:00
g . FontTexUvWhitePixel = g . Font - > ContainerAtlas - > TexUvWhitePixel ;
2015-01-17 21:40:56 +08:00
g . Font - > FallbackGlyph = NULL ;
g . Font - > FallbackGlyph = g . Font - > FindGlyph ( g . Font - > FallbackChar ) ;
}
void ImGui : : PushFont ( ImFont * font )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2015-01-17 21:40:56 +08:00
2015-01-18 06:15:29 +08:00
if ( ! font )
2015-01-18 18:46:49 +08:00
font = g . IO . Fonts - > Fonts [ 0 ] ;
2015-01-18 06:15:29 +08:00
2015-01-17 22:13:08 +08:00
SetFont ( font ) ;
g . FontStack . push_back ( font ) ;
2015-01-18 06:15:29 +08:00
g . CurrentWindow - > DrawList - > PushTextureID ( font - > ContainerAtlas - > TexID ) ;
2015-01-17 21:40:56 +08:00
}
void ImGui : : PopFont ( )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2015-01-17 21:40:56 +08:00
2015-01-17 22:13:08 +08:00
g . CurrentWindow - > DrawList - > PopTextureID ( ) ;
2015-01-17 21:40:56 +08:00
g . FontStack . pop_back ( ) ;
2015-01-18 18:46:49 +08:00
SetFont ( g . FontStack . empty ( ) ? g . IO . Fonts - > Fonts [ 0 ] : g . FontStack . back ( ) ) ;
2015-01-17 21:40:56 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : PushAllowKeyboardFocus ( bool allow_keyboard_focus )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > DC . AllowKeyboardFocus . push_back ( allow_keyboard_focus ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : PopAllowKeyboardFocus ( )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > DC . AllowKeyboardFocus . pop_back ( ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : PushTextWrapPos ( float wrap_x )
2014-11-07 13:45:56 +08:00
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > DC . TextWrapPos . push_back ( wrap_x ) ;
}
2014-11-10 09:29:01 +08:00
void ImGui : : PopTextWrapPos ( )
2014-11-07 13:45:56 +08:00
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > DC . TextWrapPos . pop_back ( ) ;
}
2014-11-10 09:29:01 +08:00
void ImGui : : PushStyleColor ( ImGuiCol idx , const ImVec4 & col )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
ImGuiColMod backup ;
backup . Col = idx ;
backup . PreviousValue = g . Style . Colors [ idx ] ;
2014-11-21 21:23:22 +08:00
g . ColorModifiers . push_back ( backup ) ;
2014-08-19 19:09:13 +08:00
g . Style . Colors [ idx ] = col ;
2014-08-11 04:58:11 +08:00
}
2014-11-21 21:23:22 +08:00
void ImGui : : PopStyleColor ( int count )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-11 04:58:11 +08:00
2014-11-21 21:23:22 +08:00
while ( count > 0 )
{
ImGuiColMod & backup = g . ColorModifiers . back ( ) ;
g . Style . Colors [ backup . Col ] = backup . PreviousValue ;
g . ColorModifiers . pop_back ( ) ;
count - - ;
}
2014-08-11 04:58:11 +08:00
}
2014-11-07 16:22:38 +08:00
static float * GetStyleVarFloatAddr ( ImGuiStyleVar idx )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-11-07 16:22:38 +08:00
switch ( idx )
{
case ImGuiStyleVar_Alpha : return & g . Style . Alpha ;
2014-12-19 20:56:00 +08:00
case ImGuiStyleVar_WindowRounding : return & g . Style . WindowRounding ;
2015-02-10 21:00:22 +08:00
case ImGuiStyleVar_ChildWindowRounding : return & g . Style . ChildWindowRounding ;
2015-01-15 17:14:44 +08:00
case ImGuiStyleVar_FrameRounding : return & g . Style . FrameRounding ;
2014-11-07 16:22:38 +08:00
case ImGuiStyleVar_TreeNodeSpacing : return & g . Style . TreeNodeSpacing ;
}
return NULL ;
}
static ImVec2 * GetStyleVarVec2Addr ( ImGuiStyleVar idx )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-11-07 16:22:38 +08:00
switch ( idx )
{
case ImGuiStyleVar_WindowPadding : return & g . Style . WindowPadding ;
case ImGuiStyleVar_FramePadding : return & g . Style . FramePadding ;
case ImGuiStyleVar_ItemSpacing : return & g . Style . ItemSpacing ;
case ImGuiStyleVar_ItemInnerSpacing : return & g . Style . ItemInnerSpacing ;
}
return NULL ;
}
2014-11-10 09:29:01 +08:00
void ImGui : : PushStyleVar ( ImGuiStyleVar idx , float val )
2014-11-07 16:22:38 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-11-07 16:22:38 +08:00
float * pvar = GetStyleVarFloatAddr ( idx ) ;
2015-01-17 20:27:27 +08:00
IM_ASSERT ( pvar ! = NULL ) ; // Called function with wrong-type? Variable is not a float.
2014-11-07 16:22:38 +08:00
ImGuiStyleMod backup ;
backup . Var = idx ;
backup . PreviousValue = ImVec2 ( * pvar , 0.0f ) ;
2014-11-21 21:23:22 +08:00
g . StyleModifiers . push_back ( backup ) ;
2014-11-07 16:22:38 +08:00
* pvar = val ;
}
2014-11-10 09:29:01 +08:00
void ImGui : : PushStyleVar ( ImGuiStyleVar idx , const ImVec2 & val )
2014-11-07 16:22:38 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-11-07 16:22:38 +08:00
ImVec2 * pvar = GetStyleVarVec2Addr ( idx ) ;
2015-01-17 20:27:27 +08:00
IM_ASSERT ( pvar ! = NULL ) ; // Called function with wrong-type? Varialble is not a ImVec2.
2014-11-07 16:22:38 +08:00
ImGuiStyleMod backup ;
backup . Var = idx ;
backup . PreviousValue = * pvar ;
2014-11-21 21:23:22 +08:00
g . StyleModifiers . push_back ( backup ) ;
2014-11-07 16:22:38 +08:00
* pvar = val ;
}
2014-11-21 21:23:22 +08:00
void ImGui : : PopStyleVar ( int count )
2014-11-07 16:22:38 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-11-07 16:22:38 +08:00
2014-11-21 21:23:22 +08:00
while ( count > 0 )
{
ImGuiStyleMod & backup = g . StyleModifiers . back ( ) ;
if ( float * pvar_f = GetStyleVarFloatAddr ( backup . Var ) )
* pvar_f = backup . PreviousValue . x ;
else if ( ImVec2 * pvar_v = GetStyleVarVec2Addr ( backup . Var ) )
* pvar_v = backup . PreviousValue ;
g . StyleModifiers . pop_back ( ) ;
2014-11-22 00:29:56 +08:00
count - - ;
2014-11-21 21:23:22 +08:00
}
2014-11-07 16:22:38 +08:00
}
2014-12-30 03:56:01 +08:00
const char * ImGui : : GetStyleColName ( ImGuiCol idx )
2014-08-11 04:58:11 +08:00
{
2014-09-02 21:35:06 +08:00
// Create switch-case from enum with regexp: ImGuiCol_{.*}, --> case ImGuiCol_\1: return "\1";
2014-08-19 19:09:13 +08:00
switch ( idx )
{
case ImGuiCol_Text : return " Text " ;
case ImGuiCol_WindowBg : return " WindowBg " ;
2015-02-10 21:00:22 +08:00
case ImGuiCol_ChildWindowBg : return " ChildWindowBg " ;
2014-08-19 19:09:13 +08:00
case ImGuiCol_Border : return " Border " ;
case ImGuiCol_BorderShadow : return " BorderShadow " ;
case ImGuiCol_FrameBg : return " FrameBg " ;
case ImGuiCol_TitleBg : return " TitleBg " ;
case ImGuiCol_TitleBgCollapsed : return " TitleBgCollapsed " ;
case ImGuiCol_ScrollbarBg : return " ScrollbarBg " ;
case ImGuiCol_ScrollbarGrab : return " ScrollbarGrab " ;
case ImGuiCol_ScrollbarGrabHovered : return " ScrollbarGrabHovered " ;
case ImGuiCol_ScrollbarGrabActive : return " ScrollbarGrabActive " ;
case ImGuiCol_ComboBg : return " ComboBg " ;
2015-01-10 01:19:24 +08:00
case ImGuiCol_CheckHovered : return " CheckHovered " ;
case ImGuiCol_CheckActive : return " CheckActive " ;
case ImGuiCol_CheckMark : return " CheckMark " ;
2014-08-19 19:09:13 +08:00
case ImGuiCol_SliderGrab : return " SliderGrab " ;
case ImGuiCol_SliderGrabActive : return " SliderGrabActive " ;
case ImGuiCol_Button : return " Button " ;
case ImGuiCol_ButtonHovered : return " ButtonHovered " ;
case ImGuiCol_ButtonActive : return " ButtonActive " ;
case ImGuiCol_Header : return " Header " ;
case ImGuiCol_HeaderHovered : return " HeaderHovered " ;
case ImGuiCol_HeaderActive : return " HeaderActive " ;
case ImGuiCol_Column : return " Column " ;
case ImGuiCol_ColumnHovered : return " ColumnHovered " ;
case ImGuiCol_ColumnActive : return " ColumnActive " ;
case ImGuiCol_ResizeGrip : return " ResizeGrip " ;
case ImGuiCol_ResizeGripHovered : return " ResizeGripHovered " ;
case ImGuiCol_ResizeGripActive : return " ResizeGripActive " ;
case ImGuiCol_CloseButton : return " CloseButton " ;
case ImGuiCol_CloseButtonHovered : return " CloseButtonHovered " ;
case ImGuiCol_CloseButtonActive : return " CloseButtonActive " ;
case ImGuiCol_PlotLines : return " PlotLines " ;
case ImGuiCol_PlotLinesHovered : return " PlotLinesHovered " ;
case ImGuiCol_PlotHistogram : return " PlotHistogram " ;
2014-08-21 00:42:53 +08:00
case ImGuiCol_PlotHistogramHovered : return " PlotHistogramHovered " ;
2014-08-19 19:09:13 +08:00
case ImGuiCol_TextSelectedBg : return " TextSelectedBg " ;
case ImGuiCol_TooltipBg : return " TooltipBg " ;
}
IM_ASSERT ( 0 ) ;
return " Unknown " ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : GetWindowIsFocused ( )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return g . FocusedWindow = = window ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
float ImGui : : GetWindowWidth ( )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return window - > Size . x ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
ImVec2 ImGui : : GetWindowPos ( )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return window - > Pos ;
2014-08-11 04:58:11 +08:00
}
2014-12-11 03:22:30 +08:00
void ImGui : : SetWindowPos ( const ImVec2 & pos , ImGuiSetCondition cond )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-12-11 03:22:30 +08:00
// Test condition (NB: bit 0 is always true) and clear flags for next time
if ( cond & & ( window - > SetWindowPosAllowFlags & cond ) = = 0 )
return ;
window - > SetWindowPosAllowFlags & = ~ ( ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver ) ;
// Set
2014-08-19 19:09:13 +08:00
const ImVec2 old_pos = window - > Pos ;
window - > PosFloat = pos ;
window - > Pos = ImVec2 ( ( float ) ( int ) window - > PosFloat . x , ( float ) ( int ) window - > PosFloat . y ) ;
2014-12-11 03:22:30 +08:00
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
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
ImVec2 ImGui : : GetWindowSize ( )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return window - > Size ;
2014-08-11 04:58:11 +08:00
}
2014-12-11 03:22:30 +08:00
void ImGui : : SetWindowSize ( const ImVec2 & size , ImGuiSetCondition cond )
2014-10-27 04:07:15 +08:00
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-12-11 03:22:30 +08:00
// Test condition (NB: bit 0 is always true) and clear flags for next time
if ( cond & & ( window - > SetWindowSizeAllowFlags & cond ) = = 0 )
return ;
window - > SetWindowSizeAllowFlags & = ~ ( ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver ) ;
// Set
2014-12-29 19:23:03 +08:00
if ( ImLengthSqr ( size ) > 0.00001f )
2014-11-22 00:29:56 +08:00
{
2014-12-29 19:23:03 +08:00
window - > SizeFull = size ;
window - > AutoFitFrames = 0 ;
2014-11-22 00:29:56 +08:00
}
else
{
2014-12-29 19:23:03 +08:00
// Autofit
window - > AutoFitFrames = 2 ;
window - > AutoFitOnlyGrows = false ;
2014-11-22 00:29:56 +08:00
}
2014-10-27 04:07:15 +08:00
}
2014-12-11 03:22:30 +08:00
void ImGui : : SetWindowCollapsed ( bool collapsed , ImGuiSetCondition cond )
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
// Test condition (NB: bit 0 is always true) and clear flags for next time
if ( cond & & ( window - > SetWindowCollapsedAllowFlags & cond ) = = 0 )
return ;
window - > SetWindowCollapsedAllowFlags & = ~ ( ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver ) ;
// Set
window - > Collapsed = collapsed ;
}
void ImGui : : SetNextWindowPos ( const ImVec2 & pos , ImGuiSetCondition cond )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-12-11 03:22:30 +08:00
g . SetNextWindowPosVal = pos ;
g . SetNextWindowPosCond = cond ? cond : ImGuiSetCondition_Always ;
}
void ImGui : : SetNextWindowSize ( const ImVec2 & size , ImGuiSetCondition cond )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-12-11 03:22:30 +08:00
g . SetNextWindowSizeVal = size ;
g . SetNextWindowSizeCond = cond ? cond : ImGuiSetCondition_Always ;
}
void ImGui : : SetNextWindowCollapsed ( bool collapsed , ImGuiSetCondition cond )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-12-11 03:22:30 +08:00
g . SetNextWindowCollapsedVal = collapsed ;
g . SetNextWindowCollapsedCond = cond ? cond : ImGuiSetCondition_Always ;
}
2014-11-10 09:29:01 +08:00
ImVec2 ImGui : : GetContentRegionMax ( )
2014-11-07 14:17:04 +08:00
{
2014-11-07 16:22:38 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2015-02-11 05:07:26 +08:00
ImVec2 mx = window - > Size - window - > WindowPadding ( ) ;
2014-11-07 16:22:38 +08:00
if ( window - > DC . ColumnsCount ! = 1 )
{
2015-02-11 05:07:26 +08:00
mx . x = ImGui : : GetColumnOffset ( window - > DC . ColumnsCurrent + 1 ) ;
mx . x - = GImGui - > Style . WindowPadding . x ;
2014-11-07 16:22:38 +08:00
}
else
{
if ( window - > ScrollbarY )
2015-02-11 05:07:26 +08:00
mx . x - = GImGui - > Style . ScrollBarWidth ;
2014-11-07 16:22:38 +08:00
}
2015-02-11 05:07:26 +08:00
return mx ;
2014-11-07 14:17:04 +08:00
}
2014-11-10 09:29:01 +08:00
ImVec2 ImGui : : GetWindowContentRegionMin ( )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return ImVec2 ( 0 , window - > TitleBarHeight ( ) ) + window - > WindowPadding ( ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
ImVec2 ImGui : : GetWindowContentRegionMax ( )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
ImVec2 m = window - > Size - window - > WindowPadding ( ) ;
if ( window - > ScrollbarY )
2015-02-01 12:28:24 +08:00
m . x - = GImGui - > Style . ScrollBarWidth ;
2014-08-19 19:09:13 +08:00
return m ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
float ImGui : : GetTextLineHeight ( )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return window - > FontSize ( ) ;
2014-08-11 04:58:11 +08:00
}
2015-02-08 21:37:20 +08:00
float ImGui : : GetTextLineHeightWithSpacing ( )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return window - > FontSize ( ) + g . Style . ItemSpacing . y ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
ImDrawList * ImGui : : GetWindowDrawList ( )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return window - > DrawList ;
2014-08-11 04:58:11 +08:00
}
2014-11-29 06:38:41 +08:00
ImFont * ImGui : : GetWindowFont ( )
2014-10-25 18:00:24 +08:00
{
2014-10-27 04:07:15 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return window - > Font ( ) ;
2014-10-25 18:00:24 +08:00
}
2014-11-10 09:29:01 +08:00
float ImGui : : GetWindowFontSize ( )
2014-10-25 18:00:24 +08:00
{
2014-10-27 04:07:15 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return window - > FontSize ( ) ;
2014-10-25 18:00:24 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : SetWindowFontScale ( float scale )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-09-24 21:03:42 +08:00
window - > FontWindowScale = scale ;
2014-08-11 04:58:11 +08:00
}
2015-01-15 22:41:22 +08:00
// NB: internally we store CursorPos in absolute screen coordinates because it is more convenient.
// Conversion happens as we pass the value to user, but it makes our naming convention dodgy. May want to rename 'DC.CursorPos'.
2014-11-10 09:29:01 +08:00
ImVec2 ImGui : : GetCursorPos ( )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return window - > DC . CursorPos - window - > Pos ;
2014-08-11 04:58:11 +08:00
}
2015-02-08 21:37:20 +08:00
float ImGui : : GetCursorPosX ( )
{
return ImGui : : GetCursorPos ( ) . x ;
}
float ImGui : : GetCursorPosY ( )
{
return ImGui : : GetCursorPos ( ) . y ;
}
2014-11-10 09:29:01 +08:00
void ImGui : : SetCursorPos ( const ImVec2 & pos )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > DC . CursorPos = window - > Pos + pos ;
2015-02-08 22:19:59 +08:00
window - > SizeContentsFit = ImMax ( window - > SizeContentsFit , pos + ImVec2 ( 0.0f , window - > ScrollY ) ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : SetCursorPosX ( float x )
2014-08-29 20:36:31 +08:00
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > DC . CursorPos . x = window - > Pos . x + x ;
2015-02-08 22:19:59 +08:00
window - > SizeContentsFit . x = ImMax ( window - > SizeContentsFit . x , x ) ;
2014-08-29 20:36:31 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : SetCursorPosY ( float y )
2014-08-29 20:36:31 +08:00
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > DC . CursorPos . y = window - > Pos . y + y ;
2015-02-08 22:19:59 +08:00
window - > SizeContentsFit . y = ImMax ( window - > SizeContentsFit . y , y + window - > ScrollY ) ;
2014-08-29 20:36:31 +08:00
}
2014-11-10 09:29:01 +08:00
ImVec2 ImGui : : GetCursorScreenPos ( )
2014-08-19 19:39:30 +08:00
{
2014-08-19 19:45:34 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return window - > DC . CursorPos ;
2014-08-11 04:58:11 +08:00
}
2015-01-15 22:41:22 +08:00
void ImGui : : SetCursorScreenPos ( const ImVec2 & screen_pos )
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > DC . CursorPos = screen_pos ;
}
2014-11-10 09:29:01 +08:00
void ImGui : : SetScrollPosHere ( )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > NextScrollY = ( window - > DC . CursorPos . y + window - > ScrollY ) - ( window - > Pos . y + window - > SizeFull . y * 0.5f ) - ( window - > TitleBarHeight ( ) + window - > WindowPadding ( ) . y ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : SetKeyboardFocusHere ( int offset )
2014-09-30 18:57:37 +08:00
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-09-30 19:31:35 +08:00
window - > FocusIdxAllRequestNext = window - > FocusIdxAllCounter + 1 + offset ;
window - > FocusIdxTabRequestNext = IM_INT_MAX ;
2014-09-30 18:57:37 +08:00
}
2014-12-30 02:17:54 +08:00
void ImGui : : SetStateStorage ( ImGuiStorage * tree )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > DC . StateStorage = tree ? tree : & window - > StateStorage ;
2014-08-11 04:58:11 +08:00
}
2014-12-30 02:17:54 +08:00
ImGuiStorage * ImGui : : GetStateStorage ( )
2014-08-13 02:57:46 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return window - > DC . StateStorage ;
2014-08-13 02:57:46 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : TextV ( const char * fmt , va_list args )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
static char buf [ 1024 ] ;
const char * text_end = buf + ImFormatStringV ( buf , IM_ARRAYSIZE ( buf ) , fmt , args ) ;
TextUnformatted ( buf , text_end ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : Text ( const char * fmt , . . . )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
va_list args ;
va_start ( args , fmt ) ;
TextV ( fmt , args ) ;
va_end ( args ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : TextColoredV ( const ImVec4 & col , const char * fmt , va_list args )
2014-08-15 19:32:53 +08:00
{
2014-08-19 19:09:13 +08:00
ImGui : : PushStyleColor ( ImGuiCol_Text , col ) ;
2014-09-25 02:27:29 +08:00
TextV ( fmt , args ) ;
ImGui : : PopStyleColor ( ) ;
}
2014-11-10 09:29:01 +08:00
void ImGui : : TextColored ( const ImVec4 & col , const char * fmt , . . . )
2014-09-25 02:27:29 +08:00
{
2014-08-19 19:09:13 +08:00
va_list args ;
va_start ( args , fmt ) ;
2014-09-25 02:27:29 +08:00
TextColoredV ( col , fmt , args ) ;
2014-08-19 19:09:13 +08:00
va_end ( args ) ;
2014-08-15 19:32:53 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : TextWrappedV ( const char * fmt , va_list args )
2014-11-07 13:45:56 +08:00
{
ImGui : : PushTextWrapPos ( 0.0f ) ;
TextV ( fmt , args ) ;
ImGui : : PopTextWrapPos ( ) ;
}
2014-11-10 09:29:01 +08:00
void ImGui : : TextWrapped ( const char * fmt , . . . )
2014-11-07 13:45:56 +08:00
{
va_list args ;
va_start ( args , fmt ) ;
TextWrappedV ( fmt , args ) ;
va_end ( args ) ;
}
2014-11-10 09:29:01 +08:00
void ImGui : : TextUnformatted ( const char * text , const char * text_end )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return ;
2014-09-25 03:39:39 +08:00
IM_ASSERT ( text ! = NULL ) ;
2014-08-19 19:09:13 +08:00
const char * text_begin = text ;
if ( text_end = = NULL )
2014-11-17 01:27:26 +08:00
text_end = text + strlen ( text ) ; // FIXME-OPT
2014-08-19 19:09:13 +08:00
2014-11-07 13:45:56 +08:00
const float wrap_pos_x = window - > DC . TextWrapPos . back ( ) ;
const bool wrap_enabled = wrap_pos_x > = 0.0f ;
if ( text_end - text > 2000 & & ! wrap_enabled )
2014-08-19 19:09:13 +08:00
{
// Long text!
// Perform manual coarse clipping to optimize for long multi-line text
2015-02-11 06:48:46 +08:00
// From this point we will only compute the width of lines that are visible. Optimization only available when word-wrapping is disabled.
// We also don't vertically center the text within the line full height, which is unlikely to matter because we are likely the biggest and only item on the line.
2014-08-19 19:09:13 +08:00
const char * line = text ;
const float line_height = ImGui : : GetTextLineHeight ( ) ;
const ImVec2 start_pos = window - > DC . CursorPos ;
const ImVec4 clip_rect = window - > ClipRectStack . back ( ) ;
ImVec2 text_size ( 0 , 0 ) ;
if ( start_pos . y < = clip_rect . w )
{
ImVec2 pos = start_pos ;
2014-09-02 21:35:06 +08:00
// Lines to skip (can't skip when logging text)
2014-08-19 19:09:13 +08:00
if ( ! g . LogEnabled )
{
int lines_skippable = ( int ) ( ( clip_rect . y - start_pos . y ) / line_height ) - 1 ;
if ( lines_skippable > 0 )
{
int lines_skipped = 0 ;
while ( line < text_end & & lines_skipped < = lines_skippable )
{
const char * line_end = strchr ( line , ' \n ' ) ;
line = line_end + 1 ;
lines_skipped + + ;
}
pos . y + = lines_skipped * line_height ;
}
}
2014-09-02 21:35:06 +08:00
// Lines to render
2014-08-19 19:09:13 +08:00
if ( line < text_end )
{
ImGuiAabb line_box ( pos , pos + ImVec2 ( ImGui : : GetWindowWidth ( ) , line_height ) ) ;
while ( line < text_end )
{
const char * line_end = strchr ( line , ' \n ' ) ;
2014-11-10 09:29:01 +08:00
if ( IsClipped ( line_box ) )
2014-08-19 19:09:13 +08:00
break ;
const ImVec2 line_size = CalcTextSize ( line , line_end , false ) ;
text_size . x = ImMax ( text_size . x , line_size . x ) ;
RenderText ( pos , line , line_end , false ) ;
if ( ! line_end )
line_end = text_end ;
line = line_end + 1 ;
line_box . Min . y + = line_height ;
line_box . Max . y + = line_height ;
pos . y + = line_height ;
}
2014-09-02 21:35:06 +08:00
// Count remaining lines
2014-08-19 19:09:13 +08:00
int lines_skipped = 0 ;
while ( line < text_end )
{
const char * line_end = strchr ( line , ' \n ' ) ;
if ( ! line_end )
line_end = text_end ;
line = line_end + 1 ;
lines_skipped + + ;
}
pos . y + = lines_skipped * line_height ;
}
text_size . y + = ( pos - start_pos ) . y ;
}
const ImGuiAabb bb ( window - > DC . CursorPos , window - > DC . CursorPos + text_size ) ;
ItemSize ( bb ) ;
2015-01-23 06:54:05 +08:00
ItemAdd ( bb , NULL ) ;
2014-08-19 19:09:13 +08:00
}
else
{
2014-11-07 13:45:56 +08:00
const float wrap_width = wrap_enabled ? CalcWrapWidthForPos ( window - > DC . CursorPos , wrap_pos_x ) : 0.0f ;
const ImVec2 text_size = CalcTextSize ( text_begin , text_end , false , wrap_width ) ;
2014-08-19 19:09:13 +08:00
ImGuiAabb bb ( window - > DC . CursorPos , window - > DC . CursorPos + text_size ) ;
ItemSize ( bb . GetSize ( ) , & bb . Min ) ;
2015-01-23 06:54:05 +08:00
if ( ! ItemAdd ( bb , NULL ) )
2014-08-19 19:09:13 +08:00
return ;
2015-02-08 23:57:06 +08:00
// Render (we don't hide text after ## in this end-user function)
RenderTextWrapped ( bb . Min , text_begin , text_end , wrap_width ) ;
2014-08-19 19:09:13 +08:00
}
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : AlignFirstTextHeightToWidgets ( )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
// Declare a dummy item size to that upcoming items that are smaller will center-align on the newly expanded line height.
2014-11-10 09:29:01 +08:00
ItemSize ( ImVec2 ( 0 , window - > FontSize ( ) + g . Style . FramePadding . y * 2 ) ) ;
2014-08-19 19:09:13 +08:00
ImGui : : SameLine ( 0 , 0 ) ;
2014-08-11 04:58:11 +08:00
}
2014-09-02 21:35:06 +08:00
// Add a label+text combo aligned to other label+value widgets
2014-11-10 09:29:01 +08:00
void ImGui : : LabelTextV ( const char * label , const char * fmt , va_list args )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return ;
const ImGuiStyle & style = g . Style ;
2015-02-11 05:07:26 +08:00
const float w = ImGui : : CalcItemWidth ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
static char buf [ 1024 ] ;
2015-02-08 23:46:23 +08:00
const char * value_text_begin = & buf [ 0 ] ;
const char * value_text_end = value_text_begin + ImFormatStringV ( buf , IM_ARRAYSIZE ( buf ) , fmt , args ) ;
2014-08-11 04:58:11 +08:00
2014-12-29 00:17:08 +08:00
const ImVec2 text_size = CalcTextSize ( label , NULL , true ) ;
2014-08-19 19:09:13 +08:00
const ImGuiAabb value_bb ( window - > DC . CursorPos , window - > DC . CursorPos + ImVec2 ( w + style . FramePadding . x * 2 , text_size . y ) ) ;
2014-12-30 19:41:46 +08:00
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 ) ;
2014-08-19 19:09:13 +08:00
ItemSize ( bb ) ;
2015-01-23 06:54:05 +08:00
if ( ! ItemAdd ( value_bb , NULL ) )
2014-08-19 19:09:13 +08:00
return ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
// Render
2015-02-09 00:32:51 +08:00
RenderTextClipped ( value_bb . Min , value_text_begin , value_text_end , NULL , value_bb . Max ) ;
2014-08-19 19:09:13 +08:00
RenderText ( ImVec2 ( value_bb . Max . x + style . ItemInnerSpacing . x , value_bb . Min . y ) , label ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : LabelText ( const char * label , const char * fmt , . . . )
2014-09-25 02:27:29 +08:00
{
va_list args ;
va_start ( args , fmt ) ;
LabelTextV ( label , fmt , args ) ;
va_end ( args ) ;
}
2015-01-05 02:12:30 +08:00
static bool IsHovered ( const ImGuiAabb & bb , const ImGuiID & id )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2015-01-05 02:12:30 +08:00
if ( g . HoveredId = = 0 )
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
2015-02-21 20:49:51 +08:00
if ( g . HoveredRootWindow = = window - > RootWindow )
{
bool hovered = ( g . ActiveId = = 0 | | g . ActiveId = = id | | g . ActiveIdIsFocusedOnly ) & & IsMouseHoveringBox ( bb ) ;
return hovered ;
}
2015-01-05 02:12:30 +08:00
}
return false ;
}
2015-02-11 01:45:45 +08:00
static bool ButtonBehaviour ( const ImGuiAabb & bb , const ImGuiID & id , bool * out_hovered , bool * out_held , bool allow_key_modifiers , bool repeat , bool pressed_on_click )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2015-01-05 02:12:30 +08:00
const bool hovered = IsHovered ( bb , id ) ;
2014-08-19 19:09:13 +08:00
bool pressed = false ;
if ( hovered )
{
g . HoveredId = id ;
if ( allow_key_modifiers | | ( ! g . IO . KeyCtrl & & ! g . IO . KeyShift ) )
{
if ( g . IO . MouseClicked [ 0 ] )
{
2015-02-11 01:45:45 +08:00
if ( pressed_on_click )
{
pressed = true ;
SetActiveId ( 0 ) ;
}
else
{
SetActiveId ( id ) ;
}
2015-01-05 02:36:33 +08:00
FocusWindow ( window ) ;
2014-08-19 19:09:13 +08:00
}
else if ( repeat & & g . ActiveId & & ImGui : : IsMouseClicked ( 0 , true ) )
{
pressed = true ;
}
}
}
bool held = false ;
if ( g . ActiveId = = id )
{
if ( g . IO . MouseDown [ 0 ] )
{
held = true ;
}
else
{
if ( hovered )
pressed = true ;
2015-02-01 06:57:59 +08:00
SetActiveId ( 0 ) ;
2014-08-19 19:09:13 +08:00
}
}
if ( out_hovered ) * out_hovered = hovered ;
if ( out_held ) * out_held = held ;
return pressed ;
2014-08-11 04:58:11 +08:00
}
2015-01-12 00:30:39 +08:00
bool ImGui : : Button ( const char * label , const ImVec2 & size_arg , bool repeat_when_held )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
const ImGuiStyle & style = g . Style ;
const ImGuiID id = window - > GetID ( label ) ;
2014-12-29 00:17:08 +08:00
const ImVec2 text_size = CalcTextSize ( label , NULL , true ) ;
2014-12-30 23:38:28 +08:00
2015-01-12 00:30:39 +08:00
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 ) ;
2014-12-30 19:41:46 +08:00
const ImGuiAabb bb ( window - > DC . CursorPos , window - > DC . CursorPos + size + style . FramePadding * 2.0f ) ;
2014-08-19 19:09:13 +08:00
ItemSize ( bb ) ;
2015-01-23 06:54:05 +08:00
if ( ! ItemAdd ( bb , & id ) )
2014-08-19 19:09:13 +08:00
return false ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
bool hovered , held ;
bool pressed = ButtonBehaviour ( bb , id , & hovered , & held , true , repeat_when_held ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
// Render
const ImU32 col = window - > Color ( ( hovered & & held ) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button ) ;
2015-01-15 17:14:44 +08:00
RenderFrame ( bb . Min , bb . Max , col , true , style . FrameRounding ) ;
2014-08-11 04:58:11 +08:00
2015-02-08 23:39:40 +08:00
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)
2015-02-09 00:32:51 +08:00
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)
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
return pressed ;
2014-08-11 04:58:11 +08:00
}
2014-09-02 21:35:06 +08:00
// Small buttons fits within text without additional spacing.
2014-11-10 09:29:01 +08:00
bool ImGui : : SmallButton ( const char * label )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
const ImGuiStyle & style = g . Style ;
const ImGuiID id = window - > GetID ( label ) ;
2014-12-29 01:54:02 +08:00
const ImVec2 text_size = CalcTextSize ( label , NULL , true ) ;
2014-12-30 23:38:28 +08:00
2014-12-29 00:17:08 +08:00
const ImGuiAabb bb ( window - > DC . CursorPos , window - > DC . CursorPos + text_size + ImVec2 ( style . FramePadding . x * 2 , 0 ) ) ;
2014-08-19 19:09:13 +08:00
ItemSize ( bb ) ;
2015-01-23 06:54:05 +08:00
if ( ! ItemAdd ( bb , & id ) )
2014-08-19 19:09:13 +08:00
return false ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
bool hovered , held ;
bool pressed = ButtonBehaviour ( bb , id , & hovered , & held , true ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
// Render
const ImU32 col = window - > Color ( ( hovered & & held ) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button ) ;
RenderFrame ( bb . Min , bb . Max , col ) ;
RenderText ( bb . Min + ImVec2 ( style . FramePadding . x , 0 ) , label ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
return pressed ;
2014-08-11 04:58:11 +08:00
}
2015-01-22 06:03:25 +08:00
// Tip: use ImGui::PushID()/PopID() to push indices or pointers in the ID stack.
// Then you can keep 'str_id' empty or the same for all your buttons (instead of creating a string based on a non-string id)
bool ImGui : : InvisibleButton ( const char * str_id , const ImVec2 & size )
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
2015-01-23 06:54:05 +08:00
const ImGuiID id = window - > GetID ( str_id ) ;
2015-01-22 06:03:25 +08:00
const ImGuiAabb bb ( window - > DC . CursorPos , window - > DC . CursorPos + size ) ;
ItemSize ( bb ) ;
2015-01-23 06:54:05 +08:00
if ( ! ItemAdd ( bb , & id ) )
2015-01-22 06:03:25 +08:00
return false ;
2015-01-29 21:20:25 +08:00
bool hovered , held ;
2015-01-22 06:03:25 +08:00
bool pressed = ButtonBehaviour ( bb , id , & hovered , & held , true ) ;
return pressed ;
}
2014-09-02 21:35:06 +08:00
// Upper-right button to close a window.
2014-12-22 21:29:39 +08:00
static bool CloseWindowButton ( bool * p_opened )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
const ImGuiID id = window - > GetID ( " ##CLOSE " ) ;
2014-08-28 05:16:55 +08:00
const float size = window - > TitleBarHeight ( ) - 4.0f ;
2014-08-28 21:52:10 +08:00
const ImGuiAabb bb ( window - > Aabb ( ) . GetTR ( ) + ImVec2 ( - 3.0f - size , 2.0f ) , window - > Aabb ( ) . GetTR ( ) + ImVec2 ( - 3.0f , 2.0f + size ) ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
bool hovered , held ;
bool pressed = ButtonBehaviour ( bb , id , & hovered , & held , true ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
// Render
const ImU32 col = window - > Color ( ( held & & hovered ) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton ) ;
2014-08-28 21:52:10 +08:00
const ImVec2 center = bb . GetCenter ( ) ;
window - > DrawList - > AddCircleFilled ( center , ImMax ( 2.0f , size * 0.5f ) , col , 16 ) ;
2014-08-11 04:58:11 +08:00
2014-08-28 21:52:10 +08:00
const float cross_extent = ( size * 0.5f * 0.7071f ) - 1.0f ;
if ( hovered )
2014-08-19 19:09:13 +08:00
{
2014-08-28 21:52:10 +08:00
window - > DrawList - > AddLine ( center + ImVec2 ( + cross_extent , + cross_extent ) , center + ImVec2 ( - cross_extent , - cross_extent ) , window - > Color ( ImGuiCol_Text ) ) ;
window - > DrawList - > AddLine ( center + ImVec2 ( + cross_extent , - cross_extent ) , center + ImVec2 ( - cross_extent , + cross_extent ) , window - > Color ( ImGuiCol_Text ) ) ;
2014-08-19 19:09:13 +08:00
}
2014-08-11 04:58:11 +08:00
2014-12-22 21:29:39 +08:00
if ( p_opened ! = NULL & & pressed )
* p_opened = ! * p_opened ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
return pressed ;
2014-08-11 04:58:11 +08:00
}
2015-02-01 00:44:55 +08:00
void ImGui : : Image ( ImTextureID user_texture_id , const ImVec2 & size , const ImVec2 & uv0 , const ImVec2 & uv1 , const ImVec4 & tint_col , const ImVec4 & border_col )
2015-01-12 00:30:39 +08:00
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return ;
ImGuiAabb bb ( window - > DC . CursorPos , window - > DC . CursorPos + size ) ;
2015-02-01 00:44:55 +08:00
if ( border_col . w > 0.0f )
2015-01-12 00:30:39 +08:00
bb . Max + = ImVec2 ( 2 , 2 ) ;
2015-02-01 00:21:12 +08:00
ItemSize ( bb ) ;
2015-01-23 06:54:05 +08:00
if ( ! ItemAdd ( bb , NULL ) )
2015-01-12 00:30:39 +08:00
return ;
2015-02-01 00:44:55 +08:00
if ( border_col . w > 0.0f )
2015-01-12 00:30:39 +08:00
{
2015-02-01 00:44:55 +08:00
window - > DrawList - > AddRect ( bb . Min , bb . Max , window - > Color ( border_col ) , 0.0f ) ;
window - > DrawList - > AddImage ( user_texture_id , bb . Min + ImVec2 ( 1 , 1 ) , bb . Max - ImVec2 ( 1 , 1 ) , uv0 , uv1 , window - > Color ( tint_col ) ) ;
2015-01-12 00:30:39 +08:00
}
else
{
2015-02-01 00:44:55 +08:00
window - > DrawList - > AddImage ( user_texture_id , bb . Min , bb . Max , uv0 , uv1 , window - > Color ( tint_col ) ) ;
2015-01-12 00:30:39 +08:00
}
}
2015-02-01 00:21:12 +08:00
// frame_padding < 0: uses FramePadding from style (default)
// frame_padding = 0: no framing
// frame_padding > 0: set framing size
// The color used are the button colors.
2015-02-05 02:19:43 +08:00
bool ImGui : : ImageButton ( ImTextureID user_texture_id , const ImVec2 & size , const ImVec2 & uv0 , const ImVec2 & uv1 , int frame_padding , const ImVec4 & bg_col , const ImVec4 & tint_col )
2015-02-01 00:21:12 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2015-02-01 00:21:12 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
const ImGuiStyle & style = g . Style ;
// Default to using texture ID as ID. User can still push string/integer prefixes.
// We could hash the size/uv to create a unique ID but that would prevent the user from animating buttons.
ImGui : : PushID ( ( void * ) user_texture_id ) ;
const ImGuiID id = window - > GetID ( " #image " ) ;
ImGui : : PopID ( ) ;
const ImVec2 padding = ( frame_padding > = 0 ) ? ImVec2 ( ( float ) frame_padding , ( float ) frame_padding ) : style . FramePadding ;
const ImGuiAabb bb ( window - > DC . CursorPos , window - > DC . CursorPos + size + padding * 2 ) ;
const ImGuiAabb image_bb ( window - > DC . CursorPos + padding , window - > DC . CursorPos + padding + size ) ;
ItemSize ( bb ) ;
if ( ! ItemAdd ( bb , & id ) )
return false ;
bool hovered , held ;
bool pressed = ButtonBehaviour ( bb , id , & hovered , & held , true ) ;
// Render
const ImU32 col = window - > Color ( ( hovered & & held ) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button ) ;
if ( padding . x > 0.0f | | padding . y > 0.0f )
RenderFrame ( bb . Min , bb . Max , col ) ;
2015-02-01 00:44:55 +08:00
if ( bg_col . w > 0.0f )
window - > DrawList - > AddRectFilled ( image_bb . Min , image_bb . Max , window - > Color ( bg_col ) ) ;
2015-02-05 02:19:43 +08:00
window - > DrawList - > AddImage ( user_texture_id , image_bb . Min , image_bb . Max , uv0 , uv1 , window - > Color ( tint_col ) ) ;
2015-02-01 00:21:12 +08:00
return pressed ;
}
2014-09-02 21:35:06 +08:00
// Start logging ImGui output to TTY
2014-11-10 09:29:01 +08:00
void ImGui : : LogToTTY ( int max_depth )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-12-30 04:18:52 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-08-19 19:09:13 +08:00
if ( g . LogEnabled )
return ;
2014-12-30 04:18:52 +08:00
2014-08-19 19:09:13 +08:00
g . LogEnabled = true ;
g . LogFile = stdout ;
2014-12-30 04:18:52 +08:00
g . LogStartDepth = window - > DC . TreeDepth ;
2014-08-19 19:09:13 +08:00
if ( max_depth > = 0 )
g . LogAutoExpandMaxDepth = max_depth ;
2014-08-11 04:58:11 +08:00
}
2014-09-02 21:35:06 +08:00
// Start logging ImGui output to given file
2014-11-10 09:29:01 +08:00
void ImGui : : LogToFile ( int max_depth , const char * filename )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-12-30 04:18:52 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-08-19 19:09:13 +08:00
if ( g . LogEnabled )
return ;
if ( ! filename )
filename = g . IO . LogFilename ;
2014-12-30 04:18:52 +08:00
2014-12-30 04:41:27 +08:00
g . LogFile = fopen ( filename , " ab " ) ;
2015-01-05 05:37:49 +08:00
if ( ! g . LogFile )
{
IM_ASSERT ( g . LogFile ! = NULL ) ; // Consider this an error
return ;
}
g . LogEnabled = true ;
2014-12-30 04:18:52 +08:00
g . LogStartDepth = window - > DC . TreeDepth ;
2014-08-19 19:09:13 +08:00
if ( max_depth > = 0 )
g . LogAutoExpandMaxDepth = max_depth ;
2014-08-11 04:58:11 +08:00
}
2014-09-02 21:35:06 +08:00
// Start logging ImGui output to clipboard
2014-11-10 09:29:01 +08:00
void ImGui : : LogToClipboard ( int max_depth )
2014-08-11 04:58:11 +08:00
{
2014-12-30 04:18:52 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
if ( g . LogEnabled )
return ;
2014-12-30 04:18:52 +08:00
2014-08-19 19:09:13 +08:00
g . LogEnabled = true ;
g . LogFile = NULL ;
2014-12-30 04:18:52 +08:00
g . LogStartDepth = window - > DC . TreeDepth ;
2014-08-19 19:09:13 +08:00
if ( max_depth > = 0 )
g . LogAutoExpandMaxDepth = max_depth ;
2014-08-11 04:58:11 +08:00
}
2014-12-30 02:13:41 +08:00
void ImGui : : LogFinish ( )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-12-30 02:13:41 +08:00
if ( ! g . LogEnabled )
return ;
2014-12-30 04:18:52 +08:00
2014-12-30 20:08:33 +08:00
ImGui : : LogText ( STR_NEWLINE ) ;
2014-12-30 02:13:41 +08:00
g . LogEnabled = false ;
if ( g . LogFile ! = NULL )
{
if ( g . LogFile = = stdout )
fflush ( g . LogFile ) ;
else
fclose ( g . LogFile ) ;
g . LogFile = NULL ;
}
if ( g . LogClipboard - > size ( ) > 1 )
{
if ( g . IO . SetClipboardTextFn )
g . IO . SetClipboardTextFn ( g . LogClipboard - > begin ( ) ) ;
g . LogClipboard - > clear ( ) ;
}
}
2014-09-02 21:35:06 +08:00
// Helper to display logging buttons
2014-11-10 09:29:01 +08:00
void ImGui : : LogButtons ( )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
ImGui : : PushID ( " LogButtons " ) ;
const bool log_to_tty = ImGui : : Button ( " Log To TTY " ) ;
ImGui : : SameLine ( ) ;
const bool log_to_file = ImGui : : Button ( " Log To File " ) ;
ImGui : : SameLine ( ) ;
const bool log_to_clipboard = ImGui : : Button ( " Log To Clipboard " ) ;
ImGui : : SameLine ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
ImGui : : PushItemWidth ( 80.0f ) ;
ImGui : : PushAllowKeyboardFocus ( false ) ;
ImGui : : SliderInt ( " Depth " , & g . LogAutoExpandMaxDepth , 0 , 9 , NULL ) ;
ImGui : : PopAllowKeyboardFocus ( ) ;
ImGui : : PopItemWidth ( ) ;
ImGui : : PopID ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
// Start logging at the end of the function so that the buttons don't appear in the log
if ( log_to_tty )
LogToTTY ( g . LogAutoExpandMaxDepth ) ;
if ( log_to_file )
LogToFile ( g . LogAutoExpandMaxDepth , g . IO . LogFilename ) ;
if ( log_to_clipboard )
LogToClipboard ( g . LogAutoExpandMaxDepth ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : CollapsingHeader ( const char * label , const char * str_id , const bool display_frame , const bool default_open )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
const ImGuiStyle & style = g . Style ;
IM_ASSERT ( str_id ! = NULL | | label ! = NULL ) ;
if ( str_id = = NULL )
str_id = label ;
if ( label = = NULL )
label = str_id ;
const ImGuiID id = window - > GetID ( str_id ) ;
2014-09-25 03:39:39 +08:00
// We only write to the tree storage if the user clicks
2014-12-30 02:17:54 +08:00
ImGuiStorage * storage = window - > DC . StateStorage ;
2014-08-19 19:09:13 +08:00
bool opened ;
if ( window - > DC . OpenNextNode ! = - 1 )
{
opened = window - > DC . OpenNextNode > 0 ;
2014-12-30 02:17:54 +08:00
storage - > SetInt ( id , opened ) ;
2014-08-19 19:09:13 +08:00
window - > DC . OpenNextNode = - 1 ;
}
else
{
2014-12-30 02:17:54 +08:00
opened = storage - > GetInt ( id , default_open ) ! = 0 ;
2014-08-19 19:09:13 +08:00
}
2014-09-25 03:39:39 +08:00
// Framed header expand a little outside the default padding
2014-08-19 19:09:13 +08:00
const ImVec2 window_padding = window - > WindowPadding ( ) ;
2014-12-29 00:17:08 +08:00
const ImVec2 text_size = CalcTextSize ( label , NULL , true ) ;
2014-08-19 19:09:13 +08:00
const ImVec2 pos_min = window - > DC . CursorPos ;
2014-11-07 14:17:04 +08:00
const ImVec2 pos_max = window - > Pos + GetContentRegionMax ( ) ;
2014-08-19 19:09:13 +08:00
ImGuiAabb bb = ImGuiAabb ( pos_min , ImVec2 ( pos_max . x , pos_min . y + text_size . y ) ) ;
if ( display_frame )
{
2014-08-27 18:38:26 +08:00
bb . Min . x - = window_padding . x * 0.5f - 1 ;
bb . Max . x + = window_padding . x * 0.5f - 1 ;
2014-08-19 19:09:13 +08:00
bb . Max . y + = style . FramePadding . y * 2 ;
}
const ImGuiAabb text_bb ( bb . Min , bb . Min + ImVec2 ( window - > FontSize ( ) + style . FramePadding . x * 2 * 2 , 0 ) + text_size ) ;
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
2014-09-02 21:35:06 +08:00
// When logging is enabled, if automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behaviour).
// NB- If we are above max depth we still allow manually opened nodes to be logged.
2014-08-19 19:09:13 +08:00
if ( ! display_frame )
if ( g . LogEnabled & & window - > DC . TreeDepth < g . LogAutoExpandMaxDepth )
opened = true ;
2015-01-23 06:54:05 +08:00
if ( ! ItemAdd ( bb , & id ) )
2014-08-19 19:09:13 +08:00
return opened ;
bool hovered , held ;
bool pressed = ButtonBehaviour ( display_frame ? bb : text_bb , id , & hovered , & held , false ) ;
if ( pressed )
{
opened = ! opened ;
2014-12-30 02:17:54 +08:00
storage - > SetInt ( id , opened ) ;
2014-08-19 19:09:13 +08:00
}
// Render
const ImU32 col = window - > Color ( ( held & & hovered ) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header ) ;
if ( display_frame )
{
2014-09-25 03:39:39 +08:00
// Framed type
2015-01-15 18:29:51 +08:00
RenderFrame ( bb . Min , bb . Max , col , true , style . FrameRounding ) ;
2014-08-19 19:09:13 +08:00
RenderCollapseTriangle ( bb . Min + style . FramePadding , opened , 1.0f , true ) ;
2014-12-30 04:18:52 +08:00
if ( g . LogEnabled )
{
// NB: '##' is normally used to hide text (as a library-wide feature), so we need to specify the text range to make sure the ## aren't stripped out here.
const char log_prefix [ ] = " \n ## " ;
LogText ( bb . Min + style . FramePadding , log_prefix , log_prefix + 3 ) ;
}
2014-08-19 19:09:13 +08:00
RenderText ( bb . Min + style . FramePadding + ImVec2 ( window - > FontSize ( ) + style . FramePadding . x * 2 , 0 ) , label ) ;
2014-12-30 04:18:52 +08:00
if ( g . LogEnabled )
{
const char log_suffix [ ] = " ## " ;
LogText ( bb . Min + style . FramePadding , log_suffix , log_suffix + 2 ) ;
}
2014-08-19 19:09:13 +08:00
}
else
{
2014-09-25 03:39:39 +08:00
// Unframed typed for tree nodes
2014-08-19 19:09:13 +08:00
if ( ( held & & hovered ) | | hovered )
RenderFrame ( bb . Min , bb . Max , col , false ) ;
2014-08-28 00:54:11 +08:00
RenderCollapseTriangle ( bb . Min + ImVec2 ( style . FramePadding . x , window - > FontSize ( ) * 0.15f ) , opened , 0.70f , false ) ;
2014-12-30 04:18:52 +08:00
if ( g . LogEnabled )
LogText ( bb . Min , " > " ) ;
2014-08-19 19:09:13 +08:00
RenderText ( bb . Min + ImVec2 ( window - > FontSize ( ) + style . FramePadding . x * 2 , 0 ) , label ) ;
}
return opened ;
2014-08-11 04:58:11 +08:00
}
2014-09-02 21:35:06 +08:00
// Text with a little bullet aligned to the typical tree node.
2014-11-10 09:29:01 +08:00
void ImGui : : BulletTextV ( const char * fmt , va_list args )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return ;
2014-12-30 23:38:28 +08:00
const ImGuiStyle & style = g . Style ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
static char buf [ 1024 ] ;
const char * text_begin = buf ;
const char * text_end = text_begin + ImFormatStringV ( buf , IM_ARRAYSIZE ( buf ) , fmt , args ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
const float line_height = window - > FontSize ( ) ;
2014-12-29 00:17:08 +08:00
const ImVec2 text_size = CalcTextSize ( text_begin , text_end , true ) ;
2014-12-30 23:38:28 +08:00
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
2014-08-19 19:09:13 +08:00
ItemSize ( bb ) ;
2015-01-23 06:54:05 +08:00
if ( ! ItemAdd ( bb , NULL ) )
2014-08-19 19:09:13 +08:00
return ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
// Render
const float bullet_size = line_height * 0.15f ;
2014-12-30 23:38:28 +08:00
window - > DrawList - > AddCircleFilled ( bb . Min + ImVec2 ( style . FramePadding . x + line_height * 0.5f , line_height * 0.5f ) , bullet_size , window - > Color ( ImGuiCol_Text ) ) ;
RenderText ( bb . Min + ImVec2 ( window - > FontSize ( ) + style . FramePadding . x * 2 , 0 ) , text_begin , text_end ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : BulletText ( const char * fmt , . . . )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
va_list args ;
va_start ( args , fmt ) ;
2014-09-25 02:27:29 +08:00
BulletTextV ( fmt , args ) ;
2014-08-19 19:09:13 +08:00
va_end ( args ) ;
2014-09-25 02:27:29 +08:00
}
// If returning 'true' the node is open and the user is responsible for calling TreePop
2014-11-10 09:29:01 +08:00
bool ImGui : : TreeNodeV ( const char * str_id , const char * fmt , va_list args )
2014-09-25 02:27:29 +08:00
{
static char buf [ 1024 ] ;
ImFormatStringV ( buf , IM_ARRAYSIZE ( buf ) , fmt , args ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( ! str_id | | ! str_id [ 0 ] )
str_id = fmt ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
ImGui : : PushID ( str_id ) ;
const bool opened = ImGui : : CollapsingHeader ( buf , " " , false ) ; // do not add to the ID so that TreeNodeSetOpen can access
ImGui : : PopID ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( opened )
ImGui : : TreePush ( str_id ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
return opened ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : TreeNode ( const char * str_id , const char * fmt , . . . )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
va_list args ;
va_start ( args , fmt ) ;
2014-09-25 02:27:29 +08:00
bool s = TreeNodeV ( str_id , fmt , args ) ;
2014-08-19 19:09:13 +08:00
va_end ( args ) ;
2014-09-25 02:27:29 +08:00
return s ;
}
// If returning 'true' the node is open and the user is responsible for calling TreePop
2014-11-10 09:29:01 +08:00
bool ImGui : : TreeNodeV ( const void * ptr_id , const char * fmt , va_list args )
2014-09-25 02:27:29 +08:00
{
static char buf [ 1024 ] ;
ImFormatStringV ( buf , IM_ARRAYSIZE ( buf ) , fmt , args ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( ! ptr_id )
ptr_id = fmt ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
ImGui : : PushID ( ptr_id ) ;
const bool opened = ImGui : : CollapsingHeader ( buf , " " , false ) ;
ImGui : : PopID ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( opened )
ImGui : : TreePush ( ptr_id ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
return opened ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : TreeNode ( const void * ptr_id , const char * fmt , . . . )
2014-09-25 02:27:29 +08:00
{
va_list args ;
va_start ( args , fmt ) ;
bool s = TreeNodeV ( ptr_id , fmt , args ) ;
va_end ( args ) ;
return s ;
}
2014-11-10 09:29:01 +08:00
bool ImGui : : TreeNode ( const char * str_label_id )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
return TreeNode ( str_label_id , " %s " , str_label_id ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : OpenNextNode ( bool open )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > DC . OpenNextNode = open ? 1 : 0 ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : PushID ( const char * str_id )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > IDStack . push_back ( window - > GetID ( str_id ) ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : PushID ( const void * ptr_id )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > IDStack . push_back ( window - > GetID ( ptr_id ) ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : PushID ( const int int_id )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
const void * ptr_id = ( void * ) ( intptr_t ) int_id ;
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > IDStack . push_back ( window - > GetID ( ptr_id ) ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : PopID ( )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > IDStack . pop_back ( ) ;
2014-08-11 04:58:11 +08:00
}
2014-12-09 01:14:54 +08:00
ImGuiID ImGui : : GetID ( const char * str_id )
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
return window - > GetID ( str_id ) ;
}
ImGuiID ImGui : : GetID ( const void * ptr_id )
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
return window - > GetID ( ptr_id ) ;
}
2014-09-02 21:35:06 +08:00
// User can input math operators (e.g. +100) to edit a numerical values.
2014-08-11 04:58:11 +08:00
// NB: only call right after InputText because we are using its InitialValue storage
static void ApplyNumericalTextInput ( const char * buf , float * v )
{
2014-08-19 19:09:13 +08:00
while ( * buf = = ' ' | | * buf = = ' \t ' )
buf + + ;
// We don't support '-' op because it would conflict with inputing negative value.
// Instead you can use +-100 to subtract from an existing value
char op = buf [ 0 ] ;
if ( op = = ' + ' | | op = = ' * ' | | op = = ' / ' )
{
buf + + ;
while ( * buf = = ' ' | | * buf = = ' \t ' )
buf + + ;
}
else
{
op = 0 ;
}
if ( ! buf [ 0 ] )
return ;
float ref_v = * v ;
if ( op )
2015-02-01 12:28:24 +08:00
if ( sscanf ( GImGui - > InputTextState . InitialText , " %f " , & ref_v ) < 1 )
2014-08-19 19:09:13 +08:00
return ;
float op_v = 0.0f ;
if ( sscanf ( buf , " %f " , & op_v ) < 1 )
return ;
if ( op = = ' + ' )
* v = ref_v + op_v ;
else if ( op = = ' * ' )
* v = ref_v * op_v ;
else if ( op = = ' / ' )
{
if ( op_v = = 0.0f )
return ;
* v = ref_v / op_v ;
}
else
* v = op_v ;
2014-08-11 04:58:11 +08:00
}
2014-09-02 21:35:06 +08:00
// Use power!=1.0 for logarithmic sliders.
// Adjust display_format to decorate the value with a prefix or a suffix.
2014-11-10 09:29:01 +08:00
bool ImGui : : SliderFloat ( const char * label , float * v , float v_min , float v_max , const char * display_format , float power )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
const ImGuiStyle & style = g . Style ;
const ImGuiID id = window - > GetID ( label ) ;
2015-02-11 05:07:26 +08:00
const float w = ImGui : : CalcItemWidth ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( ! display_format )
display_format = " %.3f " ;
2014-08-11 04:58:11 +08:00
2014-11-24 18:02:39 +08:00
// Parse display precision back from the display format string
2014-08-19 19:09:13 +08:00
int decimal_precision = 3 ;
if ( const char * p = strchr ( display_format , ' % ' ) )
{
p + + ;
while ( * p > = ' 0 ' & & * p < = ' 9 ' )
p + + ;
if ( * p = = ' . ' )
{
decimal_precision = atoi ( p + 1 ) ;
if ( decimal_precision < 0 | | decimal_precision > 10 )
decimal_precision = 3 ;
}
}
2014-08-14 01:38:24 +08:00
2014-12-29 00:17:08 +08:00
const ImVec2 text_size = CalcTextSize ( label , NULL , true ) ;
2014-08-19 19:09:13 +08:00
const ImGuiAabb frame_bb ( window - > DC . CursorPos , window - > DC . CursorPos + ImVec2 ( w , text_size . y ) + style . FramePadding * 2.0f ) ;
2014-12-30 23:38:28 +08:00
const ImGuiAabb slider_bb ( frame_bb . Min + style . FramePadding , frame_bb . Max - style . FramePadding ) ;
2014-12-30 19:41:46 +08:00
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 ) ) ;
2014-08-11 04:58:11 +08:00
2015-01-23 06:54:05 +08:00
// NB- we don't call ItemSize() yet becausae we may turn into a text edit box later in the function
if ( ! ItemAdd ( slider_bb , & id ) )
2014-08-19 19:09:13 +08:00
{
ItemSize ( bb ) ;
return false ;
}
2014-11-07 13:45:56 +08:00
const bool tab_focus_requested = window - > FocusItemRegister ( g . ActiveId = = id ) ;
2014-08-19 19:09:13 +08:00
const bool is_unbound = v_min = = - FLT_MAX | | v_min = = FLT_MAX | | v_max = = - FLT_MAX | | v_max = = FLT_MAX ;
2014-09-02 21:35:06 +08:00
const float grab_size_in_units = 1.0f ; // In 'v' units. Probably needs to be parametrized, based on a 'v_step' value? decimal precision?
2014-08-19 19:09:13 +08:00
float grab_size_in_pixels ;
if ( decimal_precision > 0 | | is_unbound )
grab_size_in_pixels = 10.0f ;
else
grab_size_in_pixels = ImMax ( grab_size_in_units * ( w / ( v_max - v_min + 1.0f ) ) , 8.0f ) ; // Integer sliders
const float slider_effective_w = slider_bb . GetWidth ( ) - grab_size_in_pixels ;
const float slider_effective_x1 = slider_bb . Min . x + grab_size_in_pixels * 0.5f ;
const float slider_effective_x2 = slider_bb . Max . x - grab_size_in_pixels * 0.5f ;
2014-11-24 18:02:39 +08:00
// For logarithmic sliders that cross over sign boundary we want the exponential increase to be symmetric around 0.0f
2014-08-19 19:09:13 +08:00
float linear_zero_pos = 0.0f ; // 0.0->1.0f
if ( ! is_unbound )
{
if ( v_min * v_max < 0.0f )
{
// Different sign
const float linear_dist_min_to_0 = powf ( fabsf ( 0.0f - v_min ) , 1.0f / power ) ;
const float linear_dist_max_to_0 = powf ( fabsf ( v_max - 0.0f ) , 1.0f / power ) ;
linear_zero_pos = linear_dist_min_to_0 / ( linear_dist_min_to_0 + linear_dist_max_to_0 ) ;
}
else
{
// Same sign
linear_zero_pos = v_min < 0.0f ? 1.0f : 0.0f ;
}
}
2015-01-05 02:12:30 +08:00
const bool hovered = IsHovered ( slider_bb , id ) ;
2014-08-19 19:09:13 +08:00
if ( hovered )
g . HoveredId = id ;
bool start_text_input = false ;
if ( tab_focus_requested | | ( hovered & & g . IO . MouseClicked [ 0 ] ) )
{
2015-02-01 06:57:59 +08:00
SetActiveId ( id ) ;
2015-01-05 02:36:33 +08:00
FocusWindow ( window ) ;
2014-08-19 19:09:13 +08:00
const bool is_ctrl_down = g . IO . KeyCtrl ;
if ( tab_focus_requested | | is_ctrl_down | | is_unbound )
{
start_text_input = true ;
g . SliderAsInputTextId = 0 ;
}
}
2014-09-02 21:35:06 +08:00
// Tabbing or CTRL-clicking through slider turns into an input box
2014-08-19 19:09:13 +08:00
bool value_changed = false ;
if ( start_text_input | | ( g . ActiveId = = id & & id = = g . SliderAsInputTextId ) )
{
char text_buf [ 64 ] ;
ImFormatString ( text_buf , IM_ARRAYSIZE ( text_buf ) , " %.*f " , decimal_precision , * v ) ;
2015-02-01 06:57:59 +08:00
SetActiveId ( g . SliderAsInputTextId ) ;
2014-08-19 19:09:13 +08:00
g . HoveredId = 0 ;
2014-11-24 18:02:39 +08:00
window - > FocusItemUnregister ( ) ; // Our replacement slider will override the focus ID (registered previously to allow for a TAB focus to happen)
2014-09-08 23:50:09 +08:00
value_changed = ImGui : : InputText ( label , text_buf , IM_ARRAYSIZE ( text_buf ) , ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll ) ;
2014-08-19 19:09:13 +08:00
if ( g . SliderAsInputTextId = = 0 )
{
// First frame
2015-02-21 20:49:51 +08:00
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)
2014-08-19 19:09:13 +08:00
g . SliderAsInputTextId = g . ActiveId ;
g . HoveredId = id ;
}
2015-02-21 20:49:51 +08:00
else if ( g . ActiveId ! = g . SliderAsInputTextId )
2014-08-19 19:09:13 +08:00
{
2015-02-21 20:49:51 +08:00
// Release
g . SliderAsInputTextId = 0 ;
2014-08-19 19:09:13 +08:00
}
if ( value_changed )
{
ApplyNumericalTextInput ( text_buf , v ) ;
}
return value_changed ;
}
ItemSize ( bb ) ;
2015-01-15 17:14:44 +08:00
RenderFrame ( frame_bb . Min , frame_bb . Max , window - > Color ( ImGuiCol_FrameBg ) , true , style . FrameRounding ) ;
2014-08-19 19:09:13 +08:00
2014-11-27 06:16:38 +08:00
// Process clicking on the slider
2014-08-19 19:09:13 +08:00
if ( g . ActiveId = = id )
{
if ( g . IO . MouseDown [ 0 ] )
{
if ( ! is_unbound )
{
const float normalized_pos = ImClamp ( ( g . IO . MousePos . x - slider_effective_x1 ) / slider_effective_w , 0.0f , 1.0f ) ;
// Linear slider
//float new_value = ImLerp(v_min, v_max, normalized_pos);
// Account for logarithmic scale on both sides of the zero
float new_value ;
if ( normalized_pos < linear_zero_pos )
{
// Negative: rescale to the negative range before powering
float a = 1.0f - ( normalized_pos / linear_zero_pos ) ;
a = powf ( a , power ) ;
new_value = ImLerp ( ImMin ( v_max , 0.f ) , v_min , a ) ;
}
else
{
// Positive: rescale to the positive range before powering
float a ;
if ( fabsf ( linear_zero_pos - 1.0f ) > 1.e-6 )
a = ( normalized_pos - linear_zero_pos ) / ( 1.0f - linear_zero_pos ) ;
else
a = normalized_pos ;
a = powf ( a , power ) ;
new_value = ImLerp ( ImMax ( v_min , 0.0f ) , v_max , a ) ;
}
// Round past decimal precision
2014-11-24 18:02:39 +08:00
// 0->1, 1->0.1, 2->0.01, etc.
2014-08-19 19:09:13 +08:00
// So when our value is 1.99999 with a precision of 0.001 we'll end up rounding to 2.0
const float min_step = 1.0f / powf ( 10.0f , ( float ) decimal_precision ) ;
const float remainder = fmodf ( new_value , min_step ) ;
if ( remainder < = min_step * 0.5f )
new_value - = remainder ;
else
new_value + = ( min_step - remainder ) ;
if ( * v ! = new_value )
{
* v = new_value ;
value_changed = true ;
}
}
}
else
{
2015-02-01 06:57:59 +08:00
SetActiveId ( 0 ) ;
2014-08-19 19:09:13 +08:00
}
}
if ( ! is_unbound )
{
// Linear slider
// const float grab_t = (ImClamp(*v, v_min, v_max) - v_min) / (v_max - v_min);
// Calculate slider grab positioning
float grab_t ;
float v_clamped = ImClamp ( * v , v_min , v_max ) ;
if ( v_clamped < 0.0f )
{
2014-09-02 21:35:06 +08:00
const float f = 1.0f - ( v_clamped - v_min ) / ( ImMin ( 0.0f , v_max ) - v_min ) ;
2014-08-19 19:09:13 +08:00
grab_t = ( 1.0f - powf ( f , 1.0f / power ) ) * linear_zero_pos ;
}
else
{
2014-09-02 21:35:06 +08:00
const float f = ( v_clamped - ImMax ( 0.0f , v_min ) ) / ( v_max - ImMax ( 0.0f , v_min ) ) ;
2014-08-19 19:09:13 +08:00
grab_t = linear_zero_pos + powf ( f , 1.0f / power ) * ( 1.0f - linear_zero_pos ) ;
}
// Draw
const float grab_x = ImLerp ( slider_effective_x1 , slider_effective_x2 , grab_t ) ;
2014-08-26 23:56:20 +08:00
const ImGuiAabb grab_bb ( ImVec2 ( grab_x - grab_size_in_pixels * 0.5f , frame_bb . Min . y + 2.0f ) , ImVec2 ( grab_x + grab_size_in_pixels * 0.5f , frame_bb . Max . y - 2.0f ) ) ;
2014-08-19 19:09:13 +08:00
window - > DrawList - > AddRectFilled ( grab_bb . Min , grab_bb . Max , window - > Color ( g . ActiveId = = id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab ) ) ;
}
2014-09-25 03:39:39 +08:00
// Draw value using user-provided display format so user can add prefix/suffix/decorations to the value.
2014-08-19 19:09:13 +08:00
char value_buf [ 64 ] ;
2015-02-13 18:37:03 +08:00
char * value_buf_end = value_buf + ImFormatString ( value_buf , IM_ARRAYSIZE ( value_buf ) , display_format , * v ) ;
const ImVec2 value_text_size = CalcTextSize ( value_buf , value_buf_end , true ) ;
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 ) ;
2014-08-19 19:09:13 +08:00
RenderText ( ImVec2 ( frame_bb . Max . x + style . ItemInnerSpacing . x , slider_bb . Min . y ) , label ) ;
return value_changed ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : SliderAngle ( const char * label , float * v , float v_degrees_min , float v_degrees_max )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
float v_deg = * v * 360.0f / ( 2 * PI ) ;
2014-11-24 18:02:39 +08:00
bool value_changed = ImGui : : SliderFloat ( label , & v_deg , v_degrees_min , v_degrees_max , " %.0f deg " , 1.0f ) ;
2014-08-19 19:09:13 +08:00
* v = v_deg * ( 2 * PI ) / 360.0f ;
2014-11-24 18:02:39 +08:00
return value_changed ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : SliderInt ( const char * label , int * v , int v_min , int v_max , const char * display_format )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
if ( ! display_format )
display_format = " %.0f " ;
float v_f = ( float ) * v ;
2014-11-24 18:02:39 +08:00
bool value_changed = ImGui : : SliderFloat ( label , & v_f , ( float ) v_min , ( float ) v_max , display_format , 1.0f ) ;
2014-08-19 19:09:13 +08:00
* v = ( int ) v_f ;
2014-11-24 18:02:39 +08:00
return value_changed ;
2014-08-11 04:58:11 +08:00
}
2014-11-24 18:02:39 +08:00
// Add multiple sliders on 1 line for compact edition of multiple components
2014-08-17 21:16:10 +08:00
static bool SliderFloatN ( const char * label , float v [ 3 ] , int components , float v_min , float v_max , const char * display_format , float power )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
const ImGuiStyle & style = g . Style ;
2015-02-11 05:07:26 +08:00
const float w_full = ImGui : : CalcItemWidth ( ) ;
2014-12-30 19:41:46 +08:00
const float w_item_one = ImMax ( 1.0f , ( float ) ( int ) ( ( w_full - ( style . FramePadding . x * 2.0f + style . ItemInnerSpacing . x ) * ( components - 1 ) ) / ( float ) components ) ) ;
const float w_item_last = ImMax ( 1.0f , ( float ) ( int ) ( w_full - ( w_item_one + style . FramePadding . x * 2.0f + style . ItemInnerSpacing . x ) * ( components - 1 ) ) ) ;
2014-08-19 19:09:13 +08:00
bool value_changed = false ;
ImGui : : PushID ( label ) ;
ImGui : : PushItemWidth ( w_item_one ) ;
for ( int i = 0 ; i < components ; i + + )
{
ImGui : : PushID ( i ) ;
if ( i + 1 = = components )
{
ImGui : : PopItemWidth ( ) ;
ImGui : : PushItemWidth ( w_item_last ) ;
}
value_changed | = ImGui : : SliderFloat ( " ##v " , & v [ i ] , v_min , v_max , display_format , power ) ;
2014-12-30 19:41:46 +08:00
ImGui : : SameLine ( 0 , ( int ) style . ItemInnerSpacing . x ) ;
2014-08-19 19:09:13 +08:00
ImGui : : PopID ( ) ;
}
ImGui : : PopItemWidth ( ) ;
ImGui : : PopID ( ) ;
ImGui : : TextUnformatted ( label , FindTextDisplayEnd ( label ) ) ;
return value_changed ;
2014-08-14 01:38:24 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : SliderFloat2 ( const char * label , float v [ 2 ] , float v_min , float v_max , const char * display_format , float power )
2014-08-14 01:38:24 +08:00
{
2014-08-19 19:09:13 +08:00
return SliderFloatN ( label , v , 2 , v_min , v_max , display_format , power ) ;
2014-08-17 21:16:10 +08:00
}
2014-08-11 04:58:11 +08:00
2014-11-10 09:29:01 +08:00
bool ImGui : : SliderFloat3 ( const char * label , float v [ 3 ] , float v_min , float v_max , const char * display_format , float power )
2014-08-17 21:16:10 +08:00
{
2014-08-19 19:09:13 +08:00
return SliderFloatN ( label , v , 3 , v_min , v_max , display_format , power ) ;
2014-08-17 21:16:10 +08:00
}
2014-08-11 04:58:11 +08:00
2014-11-10 09:29:01 +08:00
bool ImGui : : SliderFloat4 ( const char * label , float v [ 4 ] , float v_min , float v_max , const char * display_format , float power )
2014-08-17 21:16:10 +08:00
{
2014-08-19 19:09:13 +08:00
return SliderFloatN ( label , v , 4 , v_min , v_max , display_format , power ) ;
2014-08-11 04:58:11 +08:00
}
2014-12-30 19:54:04 +08:00
static bool SliderIntN ( const char * label , int v [ 3 ] , int components , int v_min , int v_max , const char * display_format )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-12-30 19:54:04 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
const ImGuiStyle & style = g . Style ;
2015-02-11 05:07:26 +08:00
const float w_full = ImGui : : CalcItemWidth ( ) ;
2014-12-30 19:54:04 +08:00
const float w_item_one = ImMax ( 1.0f , ( float ) ( int ) ( ( w_full - ( style . FramePadding . x * 2.0f + style . ItemInnerSpacing . x ) * ( components - 1 ) ) / ( float ) components ) ) ;
const float w_item_last = ImMax ( 1.0f , ( float ) ( int ) ( w_full - ( w_item_one + style . FramePadding . x * 2.0f + style . ItemInnerSpacing . x ) * ( components - 1 ) ) ) ;
bool value_changed = false ;
ImGui : : PushID ( label ) ;
ImGui : : PushItemWidth ( w_item_one ) ;
for ( int i = 0 ; i < components ; i + + )
{
ImGui : : PushID ( i ) ;
if ( i + 1 = = components )
{
ImGui : : PopItemWidth ( ) ;
ImGui : : PushItemWidth ( w_item_last ) ;
}
value_changed | = ImGui : : SliderInt ( " ##v " , & v [ i ] , v_min , v_max , display_format ) ;
ImGui : : SameLine ( 0 , ( int ) style . ItemInnerSpacing . x ) ;
ImGui : : PopID ( ) ;
}
ImGui : : PopItemWidth ( ) ;
ImGui : : PopID ( ) ;
ImGui : : TextUnformatted ( label , FindTextDisplayEnd ( label ) ) ;
return value_changed ;
}
bool ImGui : : SliderInt2 ( const char * label , int v [ 2 ] , int v_min , int v_max , const char * display_format )
{
return SliderIntN ( label , v , 2 , v_min , v_max , display_format ) ;
}
bool ImGui : : SliderInt3 ( const char * label , int v [ 3 ] , int v_min , int v_max , const char * display_format )
{
return SliderIntN ( label , v , 3 , v_min , v_max , display_format ) ;
}
bool ImGui : : SliderInt4 ( const char * label , int v [ 4 ] , int v_min , int v_max , const char * display_format )
{
return SliderIntN ( label , v , 4 , v_min , v_max , display_format ) ;
}
2014-08-11 04:58:11 +08:00
enum ImGuiPlotType
{
2014-08-19 19:09:13 +08:00
ImGuiPlotType_Lines ,
2014-11-18 17:55:31 +08:00
ImGuiPlotType_Histogram
2014-08-11 04:58:11 +08:00
} ;
2014-10-27 03:25:00 +08:00
static void Plot ( ImGuiPlotType plot_type , const char * label , float ( * values_getter ) ( void * data , int idx ) , void * data , int values_count , int values_offset , const char * overlay_text , float scale_min , float scale_max , ImVec2 graph_size )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return ;
const ImGuiStyle & style = g . Style ;
2014-12-29 00:17:08 +08:00
const ImVec2 text_size = ImGui : : CalcTextSize ( label , NULL , true ) ;
2014-11-18 17:55:31 +08:00
if ( graph_size . x = = 0.0f )
2015-02-11 05:07:26 +08:00
graph_size . x = ImGui : : CalcItemWidth ( ) ;
2014-11-18 17:55:31 +08:00
if ( graph_size . y = = 0.0f )
2014-08-19 19:09:13 +08:00
graph_size . y = text_size . y ;
const ImGuiAabb frame_bb ( window - > DC . CursorPos , window - > DC . CursorPos + ImVec2 ( graph_size . x , graph_size . y ) + style . FramePadding * 2.0f ) ;
const ImGuiAabb graph_bb ( frame_bb . Min + style . FramePadding , frame_bb . Max - style . FramePadding ) ;
2014-12-30 19:41:46 +08:00
const ImGuiAabb bb ( frame_bb . Min , frame_bb . Max + ImVec2 ( text_size . x > 0.0f ? style . ItemInnerSpacing . x + text_size . x : 0.0f , 0 ) ) ;
2014-08-19 19:09:13 +08:00
ItemSize ( bb ) ;
2015-01-23 06:54:05 +08:00
if ( ! ItemAdd ( bb , NULL ) )
2014-08-19 19:09:13 +08:00
return ;
2014-11-24 18:02:39 +08:00
// Determine scale from values if not specified
2014-08-19 19:09:13 +08:00
if ( scale_min = = FLT_MAX | | scale_max = = FLT_MAX )
{
float v_min = FLT_MAX ;
float v_max = - FLT_MAX ;
for ( int i = 0 ; i < values_count ; i + + )
{
2014-10-27 03:25:00 +08:00
const float v = values_getter ( data , i ) ;
2014-08-19 19:09:13 +08:00
v_min = ImMin ( v_min , v ) ;
v_max = ImMax ( v_max , v ) ;
}
if ( scale_min = = FLT_MAX )
scale_min = v_min ;
if ( scale_max = = FLT_MAX )
scale_max = v_max ;
}
2015-01-15 17:14:44 +08:00
RenderFrame ( frame_bb . Min , frame_bb . Max , window - > Color ( ImGuiCol_FrameBg ) , true , style . FrameRounding ) ;
2014-08-19 19:09:13 +08:00
int res_w = ImMin ( ( int ) graph_size . x , values_count ) ;
if ( plot_type = = ImGuiPlotType_Lines )
res_w - = 1 ;
// Tooltip on hover
int v_hovered = - 1 ;
if ( IsMouseHoveringBox ( graph_bb ) )
{
const float t = ImClamp ( ( g . IO . MousePos . x - graph_bb . Min . x ) / ( graph_bb . Max . x - graph_bb . Min . x ) , 0.0f , 0.9999f ) ;
const int v_idx = ( int ) ( t * ( values_count + ( ( plot_type = = ImGuiPlotType_Lines ) ? - 1 : 0 ) ) ) ;
IM_ASSERT ( v_idx > = 0 & & v_idx < values_count ) ;
2014-10-27 03:25:00 +08:00
const float v0 = values_getter ( data , ( v_idx + values_offset ) % values_count ) ;
const float v1 = values_getter ( data , ( v_idx + 1 + values_offset ) % values_count ) ;
2014-08-19 19:09:13 +08:00
if ( plot_type = = ImGuiPlotType_Lines )
ImGui : : SetTooltip ( " %d: %8.4g \n %d: %8.4g " , v_idx , v0 , v_idx + 1 , v1 ) ;
else if ( plot_type = = ImGuiPlotType_Histogram )
ImGui : : SetTooltip ( " %d: %8.4g " , v_idx , v0 ) ;
v_hovered = v_idx ;
}
const float t_step = 1.0f / ( float ) res_w ;
2014-10-27 03:25:00 +08:00
float v0 = values_getter ( data , ( 0 + values_offset ) % values_count ) ;
2014-08-19 19:09:13 +08:00
float t0 = 0.0f ;
ImVec2 p0 = ImVec2 ( t0 , 1.0f - ImSaturate ( ( v0 - scale_min ) / ( scale_max - scale_min ) ) ) ;
const ImU32 col_base = window - > Color ( ( plot_type = = ImGuiPlotType_Lines ) ? ImGuiCol_PlotLines : ImGuiCol_PlotHistogram ) ;
const ImU32 col_hovered = window - > Color ( ( plot_type = = ImGuiPlotType_Lines ) ? ImGuiCol_PlotLinesHovered : ImGuiCol_PlotHistogramHovered ) ;
for ( int n = 0 ; n < res_w ; n + + )
{
const float t1 = t0 + t_step ;
const int v_idx = ( int ) ( t0 * values_count ) ;
IM_ASSERT ( v_idx > = 0 & & v_idx < values_count ) ;
2014-10-27 03:25:00 +08:00
const float v1 = values_getter ( data , ( v_idx + values_offset + 1 ) % values_count ) ;
2014-08-19 19:09:13 +08:00
const ImVec2 p1 = ImVec2 ( t1 , 1.0f - ImSaturate ( ( v1 - scale_min ) / ( scale_max - scale_min ) ) ) ;
2014-09-02 21:35:06 +08:00
// NB- Draw calls are merged together by the DrawList system.
2014-08-19 19:09:13 +08:00
if ( plot_type = = ImGuiPlotType_Lines )
window - > DrawList - > AddLine ( ImLerp ( graph_bb . Min , graph_bb . Max , p0 ) , ImLerp ( graph_bb . Min , graph_bb . Max , p1 ) , v_hovered = = v_idx ? col_hovered : col_base ) ;
else if ( plot_type = = ImGuiPlotType_Histogram )
window - > DrawList - > AddRectFilled ( ImLerp ( graph_bb . Min , graph_bb . Max , p0 ) , ImLerp ( graph_bb . Min , graph_bb . Max , ImVec2 ( p1 . x , 1.0f ) ) + ImVec2 ( - 1 , 0 ) , v_hovered = = v_idx ? col_hovered : col_base ) ;
t0 = t1 ;
p0 = p1 ;
}
2014-09-02 21:35:06 +08:00
// Text overlay
2014-08-19 19:09:13 +08:00
if ( overlay_text )
2014-12-29 00:17:08 +08:00
RenderText ( ImVec2 ( graph_bb . GetCenter ( ) . x - ImGui : : CalcTextSize ( overlay_text , NULL , true ) . x * 0.5f , frame_bb . Min . y + style . FramePadding . y ) , overlay_text ) ;
2014-08-19 19:09:13 +08:00
RenderText ( ImVec2 ( frame_bb . Max . x + style . ItemInnerSpacing . x , graph_bb . Min . y ) , label ) ;
2014-08-11 04:58:11 +08:00
}
2014-10-27 03:56:57 +08:00
struct ImGuiPlotArrayGetterData
2014-10-27 03:25:00 +08:00
{
const float * Values ;
size_t Stride ;
2014-10-27 03:56:57 +08:00
ImGuiPlotArrayGetterData ( const float * values , size_t stride ) { Values = values ; Stride = stride ; }
2014-10-27 03:25:00 +08:00
} ;
2014-10-27 03:56:57 +08:00
static float Plot_ArrayGetter ( void * data , int idx )
2014-10-27 03:25:00 +08:00
{
2014-10-27 03:56:57 +08:00
ImGuiPlotArrayGetterData * plot_data = ( ImGuiPlotArrayGetterData * ) data ;
2014-11-18 17:55:31 +08:00
const float v = * ( float * ) ( void * ) ( ( unsigned char * ) plot_data - > Values + ( size_t ) idx * plot_data - > Stride ) ;
2014-10-27 03:25:00 +08:00
return v ;
}
2014-11-10 09:29:01 +08:00
void ImGui : : PlotLines ( const char * label , const float * values , int values_count , int values_offset , const char * overlay_text , float scale_min , float scale_max , ImVec2 graph_size , size_t stride )
2014-08-11 04:58:11 +08:00
{
2014-10-27 03:56:57 +08:00
ImGuiPlotArrayGetterData data ( values , stride ) ;
2014-11-10 09:29:01 +08:00
Plot ( ImGuiPlotType_Lines , label , & Plot_ArrayGetter , ( void * ) & data , values_count , values_offset , overlay_text , scale_min , scale_max , graph_size ) ;
2014-10-27 03:25:00 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : PlotLines ( const char * label , float ( * values_getter ) ( void * data , int idx ) , void * data , int values_count , int values_offset , const char * overlay_text , float scale_min , float scale_max , ImVec2 graph_size )
2014-10-27 03:25:00 +08:00
{
2014-11-10 09:29:01 +08:00
Plot ( ImGuiPlotType_Lines , label , values_getter , data , values_count , values_offset , overlay_text , scale_min , scale_max , graph_size ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : PlotHistogram ( const char * label , const float * values , int values_count , int values_offset , const char * overlay_text , float scale_min , float scale_max , ImVec2 graph_size , size_t stride )
2014-08-11 04:58:11 +08:00
{
2014-10-27 03:56:57 +08:00
ImGuiPlotArrayGetterData data ( values , stride ) ;
2014-11-10 09:29:01 +08:00
Plot ( ImGuiPlotType_Histogram , label , & Plot_ArrayGetter , ( void * ) & data , values_count , values_offset , overlay_text , scale_min , scale_max , graph_size ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : PlotHistogram ( const char * label , float ( * values_getter ) ( void * data , int idx ) , void * data , int values_count , int values_offset , const char * overlay_text , float scale_min , float scale_max , ImVec2 graph_size )
2014-10-27 03:25:00 +08:00
{
2014-11-10 09:29:01 +08:00
Plot ( ImGuiPlotType_Histogram , label , values_getter , data , values_count , values_offset , overlay_text , scale_min , scale_max , graph_size ) ;
2014-10-27 03:25:00 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : Checkbox ( const char * label , bool * v )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
2014-08-29 00:32:03 +08:00
return false ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
const ImGuiStyle & style = g . Style ;
const ImGuiID id = window - > GetID ( label ) ;
2014-12-29 00:17:08 +08:00
const ImVec2 text_size = CalcTextSize ( label , NULL , true ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
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 ) ) ;
ItemSize ( check_bb ) ;
2014-08-11 04:58:11 +08:00
2014-12-30 19:41:46 +08:00
ImGuiAabb total_bb = check_bb ;
if ( text_size . x > 0 )
2014-12-30 23:38:28 +08:00
SameLine ( 0 , ( int ) style . ItemInnerSpacing . x ) ;
2014-08-19 19:09:13 +08:00
const ImGuiAabb text_bb ( window - > DC . CursorPos + ImVec2 ( 0 , style . FramePadding . y ) , window - > DC . CursorPos + ImVec2 ( 0 , style . FramePadding . y ) + text_size ) ;
2014-12-30 19:41:46 +08:00
if ( text_size . x > 0 )
{
ItemSize ( ImVec2 ( text_bb . GetWidth ( ) , check_bb . GetHeight ( ) ) ) ;
total_bb = ImGuiAabb ( ImMin ( check_bb . Min , text_bb . Min ) , ImMax ( check_bb . Max , text_bb . Max ) ) ;
}
2014-08-11 04:58:11 +08:00
2015-01-23 06:54:05 +08:00
if ( ! ItemAdd ( total_bb , & id ) )
2014-08-29 00:32:03 +08:00
return false ;
2014-08-11 04:58:11 +08:00
2015-01-05 03:23:36 +08:00
bool hovered , held ;
bool pressed = ButtonBehaviour ( total_bb , id , & hovered , & held , true ) ;
2014-08-19 19:09:13 +08:00
if ( pressed )
* v = ! ( * v ) ;
2014-08-11 04:58:11 +08:00
2015-01-15 17:14:44 +08:00
RenderFrame ( check_bb . Min , check_bb . Max , window - > Color ( ( held & & hovered ) ? ImGuiCol_CheckActive : hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg ) , true , style . FrameRounding ) ;
2014-08-19 19:09:13 +08:00
if ( * v )
{
2014-11-29 06:38:41 +08:00
const float check_sz = ImMin ( check_bb . GetWidth ( ) , check_bb . GetHeight ( ) ) ;
const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f ;
2015-01-15 17:14:44 +08:00
window - > DrawList - > AddRectFilled ( check_bb . Min + ImVec2 ( pad , pad ) , check_bb . Max - ImVec2 ( pad , pad ) , window - > Color ( ImGuiCol_CheckMark ) , style . FrameRounding ) ;
2014-08-19 19:09:13 +08:00
}
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( g . LogEnabled )
LogText ( text_bb . GetTL ( ) , * v ? " [x] " : " [ ] " ) ;
RenderText ( text_bb . GetTL ( ) , label ) ;
2014-08-11 04:58:11 +08:00
2014-08-29 00:32:03 +08:00
return pressed ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : CheckboxFlags ( const char * label , unsigned int * flags , unsigned int flags_value )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
bool v = ( * flags & flags_value ) ? true : false ;
2014-08-29 00:32:03 +08:00
bool pressed = ImGui : : Checkbox ( label , & v ) ;
2014-08-19 19:09:13 +08:00
if ( v )
* flags | = flags_value ;
else
* flags & = ~ flags_value ;
2014-08-29 00:32:03 +08:00
return pressed ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : RadioButton ( const char * label , bool active )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
const ImGuiStyle & style = g . Style ;
const ImGuiID id = window - > GetID ( label ) ;
2014-08-11 04:58:11 +08:00
2014-12-29 00:17:08 +08:00
const ImVec2 text_size = CalcTextSize ( label , NULL , true ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
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 ) ) ;
ItemSize ( check_bb ) ;
2014-08-11 04:58:11 +08:00
2014-12-30 19:41:46 +08:00
ImGuiAabb total_bb = check_bb ;
if ( text_size . x > 0 )
SameLine ( 0 , ( int ) style . ItemInnerSpacing . x ) ;
2014-08-19 19:09:13 +08:00
const ImGuiAabb text_bb ( window - > DC . CursorPos + ImVec2 ( 0 , style . FramePadding . y ) , window - > DC . CursorPos + ImVec2 ( 0 , style . FramePadding . y ) + text_size ) ;
2014-12-30 19:41:46 +08:00
if ( text_size . x > 0 )
{
ItemSize ( ImVec2 ( text_bb . GetWidth ( ) , check_bb . GetHeight ( ) ) ) ;
total_bb . Add ( text_bb ) ;
}
2014-08-11 04:58:11 +08:00
2015-01-23 06:54:05 +08:00
if ( ! ItemAdd ( total_bb , & id ) )
2014-08-19 19:09:13 +08:00
return false ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
ImVec2 center = check_bb . GetCenter ( ) ;
center . x = ( float ) ( int ) center . x + 0.5f ;
center . y = ( float ) ( int ) center . y + 0.5f ;
const float radius = check_bb . GetHeight ( ) * 0.5f ;
2014-08-11 04:58:11 +08:00
2015-01-05 03:23:36 +08:00
bool hovered , held ;
bool pressed = ButtonBehaviour ( total_bb , id , & hovered , & held , true ) ;
2014-08-11 04:58:11 +08:00
2015-01-05 03:37:24 +08:00
window - > DrawList - > AddCircleFilled ( center , radius , window - > Color ( ( held & & hovered ) ? ImGuiCol_CheckActive : hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg ) , 16 ) ;
2014-08-19 19:09:13 +08:00
if ( active )
2014-11-29 06:38:41 +08:00
{
const float check_sz = ImMin ( check_bb . GetWidth ( ) , check_bb . GetHeight ( ) ) ;
const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f ;
2015-01-05 03:37:24 +08:00
window - > DrawList - > AddCircleFilled ( center , radius - pad , window - > Color ( ImGuiCol_CheckMark ) , 16 ) ;
2014-11-29 06:38:41 +08:00
}
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( window - > Flags & ImGuiWindowFlags_ShowBorders )
{
window - > DrawList - > AddCircle ( center + ImVec2 ( 1 , 1 ) , radius , window - > Color ( ImGuiCol_BorderShadow ) , 16 ) ;
window - > DrawList - > AddCircle ( center , radius , window - > Color ( ImGuiCol_Border ) , 16 ) ;
}
2014-08-11 04:58:11 +08:00
2014-09-02 21:36:03 +08:00
if ( g . LogEnabled )
LogText ( text_bb . GetTL ( ) , active ? " (x) " : " ( ) " ) ;
2014-08-19 19:09:13 +08:00
RenderText ( text_bb . GetTL ( ) , label ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
return pressed ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : RadioButton ( const char * label , int * v , int v_button )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
const bool pressed = ImGui : : RadioButton ( label , * v = = v_button ) ;
if ( pressed )
{
* v = v_button ;
}
return pressed ;
2014-08-11 04:58:11 +08:00
}
2014-11-24 07:35:26 +08:00
// Wrapper for stb_textedit.h to edit text (our wrapper is for: statically sized buffer, single-line, wchar characters. InputText converts between UTF-8 and wchar)
2014-11-18 15:51:55 +08:00
static int STB_TEXTEDIT_STRINGLEN ( const STB_TEXTEDIT_STRING * obj ) { return ( int ) ImStrlenW ( obj - > Text ) ; }
static ImWchar STB_TEXTEDIT_GETCHAR ( const STB_TEXTEDIT_STRING * obj , int idx ) { return obj - > Text [ idx ] ; }
static float STB_TEXTEDIT_GETWIDTH ( STB_TEXTEDIT_STRING * obj , int line_start_idx , int char_idx ) { ( void ) line_start_idx ; return obj - > Font - > CalcTextSizeW ( obj - > FontSize , FLT_MAX , & obj - > Text [ char_idx ] , & obj - > Text [ char_idx ] + 1 , NULL ) . x ; }
static int STB_TEXTEDIT_KEYTOTEXT ( int key ) { return key > = 0x10000 ? 0 : key ; }
2014-11-18 03:35:58 +08:00
static ImWchar STB_TEXTEDIT_NEWLINE = ' \n ' ;
2014-11-18 15:51:55 +08:00
static void STB_TEXTEDIT_LAYOUTROW ( StbTexteditRow * r , STB_TEXTEDIT_STRING * obj , int line_start_idx )
2014-08-11 04:58:11 +08:00
{
2014-09-25 21:51:06 +08:00
const ImWchar * text_remaining = NULL ;
const ImVec2 size = obj - > Font - > CalcTextSizeW ( obj - > FontSize , FLT_MAX , obj - > Text + line_start_idx , NULL , & text_remaining ) ;
2014-08-19 19:09:13 +08:00
r - > x0 = 0.0f ;
r - > x1 = size . x ;
r - > baseline_y_delta = size . y ;
r - > ymin = 0.0f ;
r - > ymax = size . y ;
r - > num_chars = ( int ) ( text_remaining - ( obj - > Text + line_start_idx ) ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-24 07:35:26 +08:00
static bool is_white ( unsigned int c ) { return c = = 0 | | c = = ' ' | | c = = ' \t ' | | c = = ' \r ' | | c = = ' \n ' ; }
static bool is_separator ( unsigned int c ) { return c = = ' , ' | | c = = ' ; ' | | c = = ' ( ' | | c = = ' ) ' | | c = = ' { ' | | c = = ' } ' | | c = = ' [ ' | | c = = ' ] ' | | c = = ' | ' ; }
2014-12-01 00:56:35 +08:00
# define STB_TEXTEDIT_IS_SPACE(CH) ( is_white((unsigned int)CH) || is_separator((unsigned int)CH) )
2014-11-24 07:35:26 +08:00
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 ' ; }
static bool STB_TEXTEDIT_INSERTCHARS ( STB_TEXTEDIT_STRING * obj , int pos , const ImWchar * new_text , int new_text_len )
2014-08-11 04:58:11 +08:00
{
2014-09-25 21:51:06 +08:00
const size_t text_len = ImStrlenW ( obj - > Text ) ;
2015-02-13 17:39:50 +08:00
if ( ( size_t ) new_text_len + text_len + 1 > obj - > BufSize )
2014-08-19 19:09:13 +08:00
return false ;
2014-08-11 04:58:11 +08:00
2014-11-30 20:21:50 +08:00
if ( pos ! = ( int ) text_len )
2014-11-24 07:35:26 +08:00
memmove ( obj - > Text + ( size_t ) pos + new_text_len , obj - > Text + ( size_t ) pos , ( text_len - ( size_t ) pos ) * sizeof ( ImWchar ) ) ;
memcpy ( obj - > Text + ( size_t ) pos , new_text , ( size_t ) new_text_len * sizeof ( ImWchar ) ) ;
obj - > Text [ text_len + ( size_t ) new_text_len ] = ' \0 ' ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
return true ;
2014-08-11 04:58:11 +08:00
}
enum
{
2014-08-19 19:09:13 +08:00
STB_TEXTEDIT_K_LEFT = 1 < < 16 , // keyboard input to move cursor left
STB_TEXTEDIT_K_RIGHT , // keyboard input to move cursor right
STB_TEXTEDIT_K_UP , // keyboard input to move cursor up
STB_TEXTEDIT_K_DOWN , // keyboard input to move cursor down
STB_TEXTEDIT_K_LINESTART , // keyboard input to move cursor to start of line
STB_TEXTEDIT_K_LINEEND , // keyboard input to move cursor to end of line
STB_TEXTEDIT_K_TEXTSTART , // keyboard input to move cursor to start of text
STB_TEXTEDIT_K_TEXTEND , // keyboard input to move cursor to end of text
STB_TEXTEDIT_K_DELETE , // keyboard input to delete selection or character under cursor
STB_TEXTEDIT_K_BACKSPACE , // keyboard input to delete selection or character left of cursor
STB_TEXTEDIT_K_UNDO , // keyboard input to perform undo
STB_TEXTEDIT_K_REDO , // keyboard input to perform redo
STB_TEXTEDIT_K_WORDLEFT , // keyboard input to move cursor left one word
STB_TEXTEDIT_K_WORDRIGHT , // keyboard input to move cursor right one word
2014-11-18 17:55:31 +08:00
STB_TEXTEDIT_K_SHIFT = 1 < < 17
2014-08-11 04:58:11 +08:00
} ;
2015-01-21 18:59:11 +08:00
# ifdef IMGUI_STB_NAMESPACE
namespace IMGUI_STB_NAMESPACE
{
# endif
2014-08-11 04:58:11 +08:00
# define STB_TEXTEDIT_IMPLEMENTATION
# include "stb_textedit.h"
2015-01-21 18:59:11 +08:00
# ifdef IMGUI_STB_NAMESPACE
}
# endif
2014-08-11 04:58:11 +08:00
2014-11-24 18:02:39 +08:00
void ImGuiTextEditState : : OnKeyPressed ( int key )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
stb_textedit_key ( this , & StbState , key ) ;
CursorAnimReset ( ) ;
2014-08-11 04:58:11 +08:00
}
void ImGuiTextEditState : : UpdateScrollOffset ( )
{
2014-08-19 19:09:13 +08:00
// Scroll in chunks of quarter width
const float scroll_x_increment = Width * 0.25f ;
2014-11-07 13:45:56 +08:00
const float cursor_offset_x = Font - > CalcTextSizeW ( FontSize , FLT_MAX , Text , Text + StbState . cursor , NULL ) . x ;
2014-08-19 19:09:13 +08:00
if ( ScrollX > cursor_offset_x )
ScrollX = ImMax ( 0.0f , cursor_offset_x - scroll_x_increment ) ;
else if ( ScrollX < cursor_offset_x - Width )
ScrollX = cursor_offset_x - Width + scroll_x_increment ;
2014-08-11 04:58:11 +08:00
}
ImVec2 ImGuiTextEditState : : CalcDisplayOffsetFromCharIdx ( int i ) const
{
2014-09-25 21:51:06 +08:00
const ImWchar * text_start = GetTextPointerClippedW ( Font , FontSize , Text , ScrollX , NULL ) ;
const ImWchar * text_end = ( Text + i > = text_start ) ? Text + i : text_start ; // Clip if requested character is outside of display
2014-08-19 19:09:13 +08:00
IM_ASSERT ( text_end > = text_start ) ;
2014-08-11 04:58:11 +08:00
2014-09-25 21:51:06 +08:00
const ImVec2 offset = Font - > CalcTextSizeW ( FontSize , Width , text_start , text_end , NULL ) ;
2014-08-19 19:09:13 +08:00
return offset ;
2014-08-11 04:58:11 +08:00
}
// [Static]
2014-11-29 06:38:41 +08:00
const char * ImGuiTextEditState : : GetTextPointerClippedA ( ImFont * font , float font_size , const char * text , float width , ImVec2 * out_text_size )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
if ( width < = 0.0f )
return text ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
const char * text_clipped_end = NULL ;
2014-11-07 13:45:56 +08:00
const ImVec2 text_size = font - > CalcTextSizeA ( font_size , width , 0.0f , text , NULL , & text_clipped_end ) ;
2014-09-25 21:51:06 +08:00
if ( out_text_size )
* out_text_size = text_size ;
return text_clipped_end ;
}
// [Static]
2014-11-29 06:38:41 +08:00
const ImWchar * ImGuiTextEditState : : GetTextPointerClippedW ( ImFont * font , float font_size , const ImWchar * text , float width , ImVec2 * out_text_size )
2014-09-25 21:51:06 +08:00
{
if ( width < = 0.0f )
return text ;
const ImWchar * text_clipped_end = NULL ;
const ImVec2 text_size = font - > CalcTextSizeW ( font_size , width , text , NULL , & text_clipped_end ) ;
2014-08-19 19:09:13 +08:00
if ( out_text_size )
* out_text_size = text_size ;
return text_clipped_end ;
2014-08-11 04:58:11 +08:00
}
// [Static]
2014-11-29 06:38:41 +08:00
void ImGuiTextEditState : : RenderTextScrolledClipped ( ImFont * font , float font_size , const char * buf , ImVec2 pos , float width , float scroll_x )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
// NB- We start drawing at character boundary
ImVec2 text_size ;
2014-09-25 21:51:06 +08:00
const char * text_start = GetTextPointerClippedA ( font , font_size , buf , scroll_x , NULL ) ;
const char * text_end = GetTextPointerClippedA ( font , font_size , text_start , width , & text_size ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
// Draw a little clip symbol if we've got text on either left or right of the box
const char symbol_c = ' ~ ' ;
const float symbol_w = font_size * 0.40f ; // FIXME: compute correct width
const float clip_begin = ( text_start > buf & & text_start < text_end ) ? symbol_w : 0.0f ;
const float clip_end = ( text_end [ 0 ] ! = ' \0 ' & & text_end > text_start ) ? symbol_w : 0.0f ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
// Draw text
2015-02-08 23:39:40 +08:00
RenderText ( pos + ImVec2 ( clip_begin , 0 ) , text_start + ( clip_begin > 0.0f ? 1 : 0 ) , text_end - ( clip_end > 0.0f ? 1 : 0 ) , false ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
// Draw the clip symbol
const char s [ 2 ] = { symbol_c , ' \0 ' } ;
if ( clip_begin > 0.0f )
2014-11-10 09:29:01 +08:00
RenderText ( pos , s ) ;
2014-08-19 19:09:13 +08:00
if ( clip_end > 0.0f )
2014-11-10 09:29:01 +08:00
RenderText ( pos + ImVec2 ( width - clip_end , 0.0f ) , s ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : InputFloat ( const char * label , float * v , float step , float step_fast , int decimal_precision , ImGuiInputTextFlags extra_flags )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
const ImGuiStyle & style = g . Style ;
2015-02-11 05:07:26 +08:00
const float w = ImGui : : CalcItemWidth ( ) ;
2014-12-29 00:17:08 +08:00
const ImVec2 text_size = CalcTextSize ( label , NULL , true ) ;
2014-08-19 19:09:13 +08:00
const ImGuiAabb frame_bb ( window - > DC . CursorPos , window - > DC . CursorPos + ImVec2 ( w , text_size . y ) + style . FramePadding * 2.0f ) ;
ImGui : : PushID ( label ) ;
const float button_sz = window - > FontSize ( ) ;
if ( step > 0.0f )
2014-12-30 23:38:28 +08:00
ImGui : : PushItemWidth ( ImMax ( 1.0f , w - ( button_sz + style . FramePadding . x * 2.0f + style . ItemInnerSpacing . x ) * 2 ) ) ;
2014-08-19 19:09:13 +08:00
char buf [ 64 ] ;
if ( decimal_precision < 0 )
ImFormatString ( buf , IM_ARRAYSIZE ( buf ) , " %f " , * v ) ; // Ideally we'd have a minimum decimal precision of 1 to visually denote that it is a float, while hiding non-significant digits?
else
ImFormatString ( buf , IM_ARRAYSIZE ( buf ) , " %.*f " , decimal_precision , * v ) ;
bool value_changed = false ;
2014-09-25 03:39:39 +08:00
const ImGuiInputTextFlags flags = extra_flags | ( ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll ) ;
2014-09-08 23:50:09 +08:00
if ( ImGui : : InputText ( " " , buf , IM_ARRAYSIZE ( buf ) , flags ) )
2014-08-19 19:09:13 +08:00
{
ApplyNumericalTextInput ( buf , v ) ;
value_changed = true ;
}
2014-09-25 03:39:39 +08:00
// Step buttons
2014-08-19 19:09:13 +08:00
if ( step > 0.0f )
{
ImGui : : PopItemWidth ( ) ;
2014-12-30 19:41:46 +08:00
ImGui : : SameLine ( 0 , ( int ) style . ItemInnerSpacing . x ) ;
2014-08-19 19:09:13 +08:00
if ( ImGui : : Button ( " - " , ImVec2 ( button_sz , button_sz ) , true ) )
{
* v - = g . IO . KeyCtrl & & step_fast > 0.0f ? step_fast : step ;
value_changed = true ;
}
2014-12-30 19:41:46 +08:00
ImGui : : SameLine ( 0 , ( int ) style . ItemInnerSpacing . x ) ;
2014-08-19 19:09:13 +08:00
if ( ImGui : : Button ( " + " , ImVec2 ( button_sz , button_sz ) , true ) )
{
* v + = g . IO . KeyCtrl & & step_fast > 0.0f ? step_fast : step ;
value_changed = true ;
}
}
ImGui : : PopID ( ) ;
2014-12-30 23:38:28 +08:00
if ( text_size . x > 0 )
{
ImGui : : SameLine ( 0 , ( int ) style . ItemInnerSpacing . x ) ;
ItemSize ( text_size ) ;
RenderText ( ImVec2 ( frame_bb . Max . x + style . ItemInnerSpacing . x , frame_bb . Min . y + style . FramePadding . y ) , label ) ;
}
2014-08-19 19:09:13 +08:00
return value_changed ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : InputInt ( const char * label , int * v , int step , int step_fast , ImGuiInputTextFlags extra_flags )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
float f = ( float ) * v ;
2014-09-08 23:50:09 +08:00
const bool value_changed = ImGui : : InputFloat ( label , & f , ( float ) step , ( float ) step_fast , 0 , extra_flags ) ;
2014-12-05 20:34:14 +08:00
if ( value_changed )
* v = ( int ) f ;
2014-08-19 19:09:13 +08:00
return value_changed ;
2014-08-11 04:58:11 +08:00
}
2014-11-24 18:02:39 +08:00
// Public API to manipulate UTF-8 text
// We expose UTF-8 to the user (unlike the STB_TEXTEDIT_* functions which are manipulating wchar)
2014-11-30 20:21:50 +08:00
void ImGuiTextEditCallbackData : : DeleteChars ( int pos , int bytes_count )
2014-11-24 07:35:26 +08:00
{
char * dst = Buf + pos ;
const char * src = Buf + pos + bytes_count ;
while ( char c = * src + + )
* dst + + = c ;
* dst = ' \0 ' ;
BufDirty = true ;
2014-11-30 20:21:50 +08:00
if ( CursorPos + bytes_count > = pos )
2014-11-24 07:35:26 +08:00
CursorPos - = bytes_count ;
2014-11-30 20:21:50 +08:00
else if ( CursorPos > = pos )
2014-11-24 07:35:26 +08:00
CursorPos = pos ;
SelectionStart = SelectionEnd = CursorPos ;
}
2014-11-30 20:21:50 +08:00
void ImGuiTextEditCallbackData : : InsertChars ( int pos , const char * new_text , const char * new_text_end )
2014-11-24 07:35:26 +08:00
{
const size_t text_len = strlen ( Buf ) ;
if ( ! new_text_end )
new_text_end = new_text + strlen ( new_text ) ;
2014-11-30 20:21:50 +08:00
const size_t new_text_len = ( size_t ) ( new_text_end - new_text ) ;
2014-11-24 07:35:26 +08:00
if ( new_text_len + text_len + 1 > = BufSize )
return ;
2014-11-30 23:53:47 +08:00
size_t upos = ( size_t ) pos ;
2014-11-30 20:21:50 +08:00
if ( text_len ! = upos )
memmove ( Buf + upos + new_text_len , Buf + upos , text_len - upos ) ;
memcpy ( Buf + upos , new_text , new_text_len * sizeof ( char ) ) ;
2014-11-24 07:35:26 +08:00
Buf [ text_len + new_text_len ] = ' \0 ' ;
BufDirty = true ;
2014-11-30 20:21:50 +08:00
if ( CursorPos > = pos )
CursorPos + = ( int ) new_text_len ;
2014-11-24 07:35:26 +08:00
SelectionStart = SelectionEnd = CursorPos ;
}
2015-02-12 01:39:13 +08:00
// Return false to discard a character.
static bool InputTextFilterCharacter ( unsigned int * p_char , ImGuiInputTextFlags flags , ImGuiTextEditCallback callback , void * user_data )
2015-01-05 02:47:08 +08:00
{
2015-02-12 01:39:13 +08:00
unsigned int c = * p_char ;
2015-01-05 03:23:36 +08:00
if ( c < 128 & & c ! = ' ' & & ! isprint ( ( int ) ( c & 0xFF ) ) )
2015-02-12 01:39:13 +08:00
return false ;
2015-01-05 02:47:08 +08:00
2015-02-01 22:08:37 +08:00
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.
2015-02-12 01:39:13 +08:00
return false ;
2015-02-01 22:08:37 +08:00
2015-02-12 02:01:32 +08:00
if ( flags & ( ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank ) )
{
if ( flags & ImGuiInputTextFlags_CharsDecimal )
if ( ! ( c > = ' 0 ' & & c < = ' 9 ' ) & & ( c ! = ' . ' ) & & ( c ! = ' - ' ) & & ( c ! = ' + ' ) & & ( c ! = ' * ' ) & & ( c ! = ' / ' ) )
return false ;
2015-01-05 02:47:08 +08:00
2015-02-12 02:01:32 +08:00
if ( flags & ImGuiInputTextFlags_CharsHexadecimal )
if ( ! ( c > = ' 0 ' & & c < = ' 9 ' ) & & ! ( c > = ' a ' & & c < = ' f ' ) & & ! ( c > = ' A ' & & c < = ' F ' ) )
return false ;
if ( flags & ImGuiInputTextFlags_CharsUppercase )
if ( c > = ' a ' & & c < = ' z ' )
* p_char = ( c + = ' A ' - ' a ' ) ;
2015-01-05 02:47:08 +08:00
2015-02-12 02:01:32 +08:00
if ( flags & ImGuiInputTextFlags_CharsNoBlank )
if ( c = = ' ' | | c = = ' \t ' )
return false ;
}
2015-02-12 01:46:16 +08:00
2015-02-12 01:39:13 +08:00
if ( flags & ImGuiInputTextFlags_CallbackCharFilter )
{
ImGuiTextEditCallbackData callback_data ;
memset ( & callback_data , 0 , sizeof ( ImGuiTextEditCallbackData ) ) ;
callback_data . EventFlag = ImGuiInputTextFlags_CallbackCharFilter ;
callback_data . EventChar = c ;
callback_data . Flags = flags ;
callback_data . UserData = user_data ;
2015-02-12 01:55:26 +08:00
if ( callback ( & callback_data ) ! = 0 )
return false ;
2015-02-12 01:39:13 +08:00
* p_char = callback_data . EventChar ;
if ( ! callback_data . EventChar )
return false ;
}
return true ;
2015-01-05 02:47:08 +08:00
}
2014-11-24 18:02:39 +08:00
// Edit a string of text
2015-02-12 01:39:13 +08:00
bool ImGui : : InputText ( const char * label , char * buf , size_t buf_size , ImGuiInputTextFlags flags , ImGuiTextEditCallback callback , void * user_data )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
const ImGuiIO & io = g . IO ;
const ImGuiStyle & style = g . Style ;
const ImGuiID id = window - > GetID ( label ) ;
2015-02-11 05:07:26 +08:00
const float w = ImGui : : CalcItemWidth ( ) ;
2014-08-19 19:09:13 +08:00
2014-12-29 00:17:08 +08:00
const ImVec2 text_size = CalcTextSize ( label , NULL , true ) ;
2014-08-19 19:09:13 +08:00
const ImGuiAabb frame_bb ( window - > DC . CursorPos , window - > DC . CursorPos + ImVec2 ( w , text_size . y ) + style . FramePadding * 2.0f ) ;
2014-12-30 19:41:46 +08:00
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 ) ) ;
2014-08-19 19:09:13 +08:00
ItemSize ( bb ) ;
2015-01-23 06:54:05 +08:00
if ( ! ItemAdd ( frame_bb , & id ) )
2014-08-19 19:09:13 +08:00
return false ;
2014-12-30 23:38:28 +08:00
// NB: we are only allowed to access 'edit_state' if we are the active widget.
2014-08-19 19:09:13 +08:00
ImGuiTextEditState & edit_state = g . InputTextState ;
const bool is_ctrl_down = io . KeyCtrl ;
const bool is_shift_down = io . KeyShift ;
2015-02-22 00:05:59 +08:00
const bool focus_requested = window - > FocusItemRegister ( g . ActiveId = = id , ( flags & ImGuiInputTextFlags_CallbackCompletion ) = = 0 ) ; // Using completion callback disable keyboard tabbing
2015-02-22 00:30:40 +08:00
const bool focus_requested_by_code = focus_requested & & ( window - > FocusIdxAllCounter = = window - > FocusIdxAllRequestCurrent ) ;
const bool focus_requested_by_tab = focus_requested & & ! focus_requested_by_code ;
2014-08-19 19:09:13 +08:00
2015-01-05 02:12:30 +08:00
const bool hovered = IsHovered ( frame_bb , id ) ;
2014-08-19 19:09:13 +08:00
if ( hovered )
g . HoveredId = id ;
2015-02-22 00:05:59 +08:00
const bool user_clicked = hovered & & io . MouseClicked [ 0 ] ;
2014-08-19 19:09:13 +08:00
bool select_all = ( g . ActiveId ! = id ) & & ( flags & ImGuiInputTextFlags_AutoSelectAll ) ! = 0 ;
2015-02-22 00:05:59 +08:00
if ( focus_requested | | user_clicked )
2014-08-19 19:09:13 +08:00
{
if ( g . ActiveId ! = id )
{
// Start edition
2014-09-25 21:51:06 +08:00
// Take a copy of the initial buffer value (both in original UTF-8 format and converted to wchar)
ImFormatString ( edit_state . InitialText , IM_ARRAYSIZE ( edit_state . InitialText ) , " %s " , buf ) ;
2015-02-22 00:30:40 +08:00
size_t buf_len = ImTextStrFromUtf8 ( edit_state . Text , IM_ARRAYSIZE ( edit_state . Text ) , buf , NULL ) ;
2014-08-19 19:09:13 +08:00
edit_state . Width = w ;
2015-02-21 21:36:24 +08:00
edit_state . InputCursorScreenPos = ImVec2 ( - 1.f , - 1.f ) ;
2015-02-22 00:30:40 +08:00
edit_state . CursorAnimReset ( ) ;
2014-08-19 19:09:13 +08:00
2015-02-22 00:30:40 +08:00
if ( edit_state . Id ! = id )
{
edit_state . Id = id ;
edit_state . ScrollX = 0.0f ;
stb_textedit_initialize_state ( & edit_state . StbState , true ) ;
if ( focus_requested_by_code )
select_all = true ;
}
else
{
// Recycle existing cursor/selection/undo stack but clamp position
// Note a single mouse click will override the cursor/position immediately by calling stb_textedit_click handler.
edit_state . StbState . cursor = ImMin ( edit_state . StbState . cursor , buf_len ) ;
edit_state . StbState . select_start = ImMin ( edit_state . StbState . select_start , buf_len ) ;
edit_state . StbState . select_end = ImMin ( edit_state . StbState . select_end , buf_len ) ;
}
if ( focus_requested_by_tab | | ( user_clicked & & is_ctrl_down ) )
2014-08-19 19:09:13 +08:00
select_all = true ;
}
2015-02-01 06:57:59 +08:00
SetActiveId ( id ) ;
2015-01-05 02:36:33 +08:00
FocusWindow ( window ) ;
2014-08-19 19:09:13 +08:00
}
else if ( io . MouseClicked [ 0 ] )
{
// Release focus when we click outside
if ( g . ActiveId = = id )
{
2015-02-01 06:57:59 +08:00
SetActiveId ( 0 ) ;
2014-08-19 19:09:13 +08:00
}
}
2015-02-21 20:49:51 +08:00
// Although we are active we don't prevent mouse from hovering other elements unless we are interacting right now with the widget.
// Down the line we should have a cleaner concept of focused vs active in the library.
if ( g . ActiveId = = id )
g . ActiveIdIsFocusedOnly = ! io . MouseDown [ 0 ] ;
2014-08-19 19:09:13 +08:00
bool value_changed = false ;
bool cancel_edit = false ;
2014-09-08 21:48:39 +08:00
bool enter_pressed = false ;
2014-09-25 21:51:06 +08:00
static char text_tmp_utf8 [ IM_ARRAYSIZE ( edit_state . InitialText ) ] ;
2014-09-26 08:06:27 +08:00
if ( g . ActiveId = = id )
2014-08-19 19:09:13 +08:00
{
2014-09-25 03:39:39 +08:00
// Edit in progress
2014-08-19 19:09:13 +08:00
edit_state . BufSize = buf_size < IM_ARRAYSIZE ( edit_state . Text ) ? buf_size : IM_ARRAYSIZE ( edit_state . Text ) ;
edit_state . Font = window - > Font ( ) ;
edit_state . FontSize = window - > FontSize ( ) ;
const float mx = g . IO . MousePos . x - frame_bb . Min . x - style . FramePadding . x ;
2014-11-24 18:02:39 +08:00
const float my = window - > FontSize ( ) * 0.5f ; // Flatten mouse because we are doing a single-line edit
2014-08-19 19:09:13 +08:00
edit_state . UpdateScrollOffset ( ) ;
if ( select_all | | ( hovered & & io . MouseDoubleClicked [ 0 ] ) )
{
edit_state . SelectAll ( ) ;
edit_state . SelectedAllMouseLock = true ;
}
else if ( io . MouseClicked [ 0 ] & & ! edit_state . SelectedAllMouseLock )
{
stb_textedit_click ( & edit_state , & edit_state . StbState , mx + edit_state . ScrollX , my ) ;
edit_state . CursorAnimReset ( ) ;
}
else if ( io . MouseDown [ 0 ] & & ! edit_state . SelectedAllMouseLock )
{
stb_textedit_drag ( & edit_state , & edit_state . StbState , mx + edit_state . ScrollX , my ) ;
edit_state . CursorAnimReset ( ) ;
}
if ( edit_state . SelectedAllMouseLock & & ! io . MouseDown [ 0 ] )
edit_state . SelectedAllMouseLock = false ;
2015-02-01 07:51:00 +08:00
if ( g . IO . InputCharacters [ 0 ] )
{
// Process text input (before we check for Return because using some IME will effectively send a Return?)
for ( int n = 0 ; n < IM_ARRAYSIZE ( g . IO . InputCharacters ) & & g . IO . InputCharacters [ n ] ; n + + )
{
2015-02-12 01:39:13 +08:00
unsigned int c = ( unsigned int ) g . IO . InputCharacters [ n ] ;
2015-02-01 07:51:00 +08:00
if ( c )
{
// Insert character if they pass filtering
2015-02-12 01:39:13 +08:00
if ( ! InputTextFilterCharacter ( & c , flags , callback , user_data ) )
2015-02-01 07:51:00 +08:00
continue ;
2015-02-12 01:39:13 +08:00
edit_state . OnKeyPressed ( ( int ) c ) ;
2015-02-01 07:51:00 +08:00
}
}
// Consume characters
memset ( g . IO . InputCharacters , 0 , sizeof ( g . IO . InputCharacters ) ) ;
}
2014-08-19 19:09:13 +08:00
const int k_mask = ( is_shift_down ? STB_TEXTEDIT_K_SHIFT : 0 ) ;
2014-11-27 06:16:38 +08:00
if ( IsKeyPressedMap ( ImGuiKey_LeftArrow ) ) { edit_state . OnKeyPressed ( is_ctrl_down ? STB_TEXTEDIT_K_WORDLEFT | k_mask : STB_TEXTEDIT_K_LEFT | k_mask ) ; }
else if ( IsKeyPressedMap ( ImGuiKey_RightArrow ) ) { edit_state . OnKeyPressed ( is_ctrl_down ? STB_TEXTEDIT_K_WORDRIGHT | k_mask : STB_TEXTEDIT_K_RIGHT | k_mask ) ; }
else if ( IsKeyPressedMap ( ImGuiKey_Home ) ) { edit_state . OnKeyPressed ( is_ctrl_down ? STB_TEXTEDIT_K_TEXTSTART | k_mask : STB_TEXTEDIT_K_LINESTART | k_mask ) ; }
else if ( IsKeyPressedMap ( ImGuiKey_End ) ) { edit_state . OnKeyPressed ( is_ctrl_down ? STB_TEXTEDIT_K_TEXTEND | k_mask : STB_TEXTEDIT_K_LINEEND | k_mask ) ; }
else if ( IsKeyPressedMap ( ImGuiKey_Delete ) ) { edit_state . OnKeyPressed ( STB_TEXTEDIT_K_DELETE | k_mask ) ; }
else if ( IsKeyPressedMap ( ImGuiKey_Backspace ) ) { edit_state . OnKeyPressed ( STB_TEXTEDIT_K_BACKSPACE | k_mask ) ; }
2015-02-01 06:57:59 +08:00
else if ( IsKeyPressedMap ( ImGuiKey_Enter ) ) { SetActiveId ( 0 ) ; enter_pressed = true ; }
else if ( IsKeyPressedMap ( ImGuiKey_Escape ) ) { SetActiveId ( 0 ) ; cancel_edit = true ; }
2014-11-27 06:16:38 +08:00
else if ( is_ctrl_down & & IsKeyPressedMap ( ImGuiKey_Z ) ) { edit_state . OnKeyPressed ( STB_TEXTEDIT_K_UNDO ) ; }
else if ( is_ctrl_down & & IsKeyPressedMap ( ImGuiKey_Y ) ) { edit_state . OnKeyPressed ( STB_TEXTEDIT_K_REDO ) ; }
else if ( is_ctrl_down & & IsKeyPressedMap ( ImGuiKey_A ) ) { edit_state . SelectAll ( ) ; }
2014-09-25 21:51:06 +08:00
else if ( is_ctrl_down & & ( IsKeyPressedMap ( ImGuiKey_X ) | | IsKeyPressedMap ( ImGuiKey_C ) ) )
2014-08-19 19:09:13 +08:00
{
2014-09-25 21:51:06 +08:00
// Cut, Copy
const bool cut = IsKeyPressedMap ( ImGuiKey_X ) ;
if ( cut & & ! edit_state . HasSelection ( ) )
2014-08-19 19:09:13 +08:00
edit_state . SelectAll ( ) ;
if ( g . IO . SetClipboardTextFn )
2014-09-25 21:51:06 +08:00
{
const int ib = edit_state . HasSelection ( ) ? ImMin ( edit_state . StbState . select_start , edit_state . StbState . select_end ) : 0 ;
const int ie = edit_state . HasSelection ( ) ? ImMax ( edit_state . StbState . select_start , edit_state . StbState . select_end ) : ( int ) ImStrlenW ( edit_state . Text ) ;
2014-09-26 08:06:27 +08:00
ImTextStrToUtf8 ( text_tmp_utf8 , IM_ARRAYSIZE ( text_tmp_utf8 ) , edit_state . Text + ib , edit_state . Text + ie ) ;
2014-09-25 21:51:06 +08:00
g . IO . SetClipboardTextFn ( text_tmp_utf8 ) ;
}
if ( cut )
stb_textedit_cut ( & edit_state , & edit_state . StbState ) ;
2014-08-19 19:09:13 +08:00
}
else if ( is_ctrl_down & & IsKeyPressedMap ( ImGuiKey_V ) )
{
2014-09-25 21:51:06 +08:00
// Paste
2014-08-19 19:09:13 +08:00
if ( g . IO . GetClipboardTextFn )
2014-09-25 18:35:23 +08:00
{
2014-08-19 19:09:13 +08:00
if ( const char * clipboard = g . IO . GetClipboardTextFn ( ) )
{
// Remove new-line from pasted buffer
size_t clipboard_len = strlen ( clipboard ) ;
2014-09-25 21:51:06 +08:00
ImWchar * clipboard_filtered = ( ImWchar * ) ImGui : : MemAlloc ( ( clipboard_len + 1 ) * sizeof ( ImWchar ) ) ;
2014-08-19 19:09:13 +08:00
int clipboard_filtered_len = 0 ;
2014-09-25 21:51:06 +08:00
for ( const char * s = clipboard ; * s ; )
2014-08-19 19:09:13 +08:00
{
2014-09-25 21:51:06 +08:00
unsigned int c ;
2015-02-11 20:23:38 +08:00
s + = ImTextCharFromUtf8 ( & c , s , NULL ) ;
if ( c = = 0 )
2014-09-25 21:51:06 +08:00
break ;
2014-11-20 19:31:55 +08:00
if ( c > = 0x10000 )
continue ;
2015-02-12 01:39:13 +08:00
if ( ! InputTextFilterCharacter ( & c , flags , callback , user_data ) )
2015-01-05 03:23:36 +08:00
continue ;
clipboard_filtered [ clipboard_filtered_len + + ] = ( ImWchar ) c ;
2014-08-19 19:09:13 +08:00
}
clipboard_filtered [ clipboard_filtered_len ] = 0 ;
2015-01-05 02:47:08 +08:00
if ( clipboard_filtered_len > 0 ) // If everything was filtered, ignore the pasting operation
2015-01-05 03:23:36 +08:00
stb_textedit_paste ( & edit_state , & edit_state . StbState , clipboard_filtered , clipboard_filtered_len ) ;
2014-09-25 01:01:07 +08:00
ImGui : : MemFree ( clipboard_filtered ) ;
2014-08-19 19:09:13 +08:00
}
2014-09-25 18:35:23 +08:00
}
2014-08-19 19:09:13 +08:00
}
edit_state . CursorAnim + = g . IO . DeltaTime ;
edit_state . UpdateScrollOffset ( ) ;
if ( cancel_edit )
{
// Restore initial value
ImFormatString ( buf , buf_size , " %s " , edit_state . InitialText ) ;
value_changed = true ;
}
else
{
// Apply new value immediately - copy modified buffer back
2014-09-25 21:51:06 +08:00
// Note that as soon as we can focus into the input box, the in-widget value gets priority over any underlying modification of the input buffer
// FIXME: We actually always render 'buf' in RenderTextScrolledClipped
2014-11-24 07:35:26 +08:00
// FIXME-OPT: CPU waste to do this every time the widget is active, should mark dirty state from the stb_textedit callbacks
2014-09-25 21:51:06 +08:00
ImTextStrToUtf8 ( text_tmp_utf8 , IM_ARRAYSIZE ( text_tmp_utf8 ) , edit_state . Text , NULL ) ;
2014-11-24 07:35:26 +08:00
// User callback
if ( ( flags & ( ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackAlways ) ) ! = 0 )
{
IM_ASSERT ( callback ! = NULL ) ;
// The reason we specify the usage semantic (Completion/History) is that Completion needs to disable keyboard TABBING at the moment.
2015-02-12 01:39:13 +08:00
ImGuiInputTextFlags event_flag = 0 ;
2014-11-24 07:35:26 +08:00
ImGuiKey event_key = ImGuiKey_COUNT ;
if ( ( flags & ImGuiInputTextFlags_CallbackCompletion ) ! = 0 & & IsKeyPressedMap ( ImGuiKey_Tab ) )
2015-02-12 01:39:13 +08:00
{
event_flag = ImGuiInputTextFlags_CallbackCompletion ;
2014-11-24 07:35:26 +08:00
event_key = ImGuiKey_Tab ;
2015-02-12 01:39:13 +08:00
}
2014-11-24 07:35:26 +08:00
else if ( ( flags & ImGuiInputTextFlags_CallbackHistory ) ! = 0 & & IsKeyPressedMap ( ImGuiKey_UpArrow ) )
2015-02-12 01:39:13 +08:00
{
event_flag = ImGuiInputTextFlags_CallbackHistory ;
2014-11-24 07:35:26 +08:00
event_key = ImGuiKey_UpArrow ;
2015-02-12 01:39:13 +08:00
}
2014-11-24 07:35:26 +08:00
else if ( ( flags & ImGuiInputTextFlags_CallbackHistory ) ! = 0 & & IsKeyPressedMap ( ImGuiKey_DownArrow ) )
2015-02-12 01:39:13 +08:00
{
event_flag = ImGuiInputTextFlags_CallbackHistory ;
2014-11-24 07:35:26 +08:00
event_key = ImGuiKey_DownArrow ;
2015-02-12 01:39:13 +08:00
}
2014-11-24 07:35:26 +08:00
if ( event_key ! = ImGuiKey_COUNT | | ( flags & ImGuiInputTextFlags_CallbackAlways ) ! = 0 )
{
ImGuiTextEditCallbackData callback_data ;
2015-02-12 01:39:13 +08:00
callback_data . EventFlag = event_flag ;
2014-11-24 07:35:26 +08:00
callback_data . EventKey = event_key ;
callback_data . Buf = text_tmp_utf8 ;
callback_data . BufSize = edit_state . BufSize ;
callback_data . BufDirty = false ;
callback_data . Flags = flags ;
2014-11-27 06:16:38 +08:00
callback_data . UserData = user_data ;
2014-11-24 07:35:26 +08:00
// We have to convert from position from wchar to UTF-8 positions
const int utf8_cursor_pos = callback_data . CursorPos = ImTextCountUtf8BytesFromWchar ( edit_state . Text , edit_state . Text + edit_state . StbState . cursor ) ;
const int utf8_selection_start = callback_data . SelectionStart = ImTextCountUtf8BytesFromWchar ( edit_state . Text , edit_state . Text + edit_state . StbState . select_start ) ;
const int utf8_selection_end = callback_data . SelectionEnd = ImTextCountUtf8BytesFromWchar ( edit_state . Text , edit_state . Text + edit_state . StbState . select_end ) ;
2014-11-27 06:16:38 +08:00
// Call user code
callback ( & callback_data ) ;
2014-11-24 07:35:26 +08:00
// Read back what user may have modified
IM_ASSERT ( callback_data . Buf = = text_tmp_utf8 ) ; // Invalid to modify those fields
IM_ASSERT ( callback_data . BufSize = = edit_state . BufSize ) ;
IM_ASSERT ( callback_data . Flags = = flags ) ;
if ( callback_data . CursorPos ! = utf8_cursor_pos ) edit_state . StbState . cursor = ImTextCountCharsFromUtf8 ( callback_data . Buf , callback_data . Buf + callback_data . CursorPos ) ;
if ( callback_data . SelectionStart ! = utf8_selection_start ) edit_state . StbState . select_start = ImTextCountCharsFromUtf8 ( callback_data . Buf , callback_data . Buf + callback_data . SelectionStart ) ;
if ( callback_data . SelectionEnd ! = utf8_selection_end ) edit_state . StbState . select_end = ImTextCountCharsFromUtf8 ( callback_data . Buf , callback_data . Buf + callback_data . SelectionEnd ) ;
if ( callback_data . BufDirty )
{
ImTextStrFromUtf8 ( edit_state . Text , IM_ARRAYSIZE ( edit_state . Text ) , text_tmp_utf8 , NULL ) ;
edit_state . CursorAnimReset ( ) ;
}
}
}
2014-09-25 21:51:06 +08:00
if ( strcmp ( text_tmp_utf8 , buf ) ! = 0 )
2014-08-19 19:09:13 +08:00
{
2014-09-25 21:51:06 +08:00
ImFormatString ( buf , buf_size , " %s " , text_tmp_utf8 ) ;
2014-08-19 19:09:13 +08:00
value_changed = true ;
}
}
}
2015-01-15 17:14:44 +08:00
RenderFrame ( frame_bb . Min , frame_bb . Max , window - > Color ( ImGuiCol_FrameBg ) , true , style . FrameRounding ) ;
2014-08-19 19:09:13 +08:00
2014-11-24 07:35:26 +08:00
const ImVec2 font_off_up = ImVec2 ( 0.0f , window - > FontSize ( ) + 1.0f ) ; // FIXME: those offsets are part of the style or font API
2014-08-19 19:09:13 +08:00
const ImVec2 font_off_dn = ImVec2 ( 0.0f , 2.0f ) ;
if ( g . ActiveId = = id )
{
// Draw selection
const int select_begin_idx = edit_state . StbState . select_start ;
const int select_end_idx = edit_state . StbState . select_end ;
if ( select_begin_idx ! = select_end_idx )
{
const ImVec2 select_begin_pos = frame_bb . Min + style . FramePadding + edit_state . CalcDisplayOffsetFromCharIdx ( ImMin ( select_begin_idx , select_end_idx ) ) ;
const ImVec2 select_end_pos = frame_bb . Min + style . FramePadding + edit_state . CalcDisplayOffsetFromCharIdx ( ImMax ( select_begin_idx , select_end_idx ) ) ;
window - > DrawList - > AddRectFilled ( select_begin_pos - font_off_up , select_end_pos + font_off_dn , window - > Color ( ImGuiCol_TextSelectedBg ) ) ;
}
}
ImGuiTextEditState : : RenderTextScrolledClipped ( window - > Font ( ) , window - > FontSize ( ) , buf , frame_bb . Min + style . FramePadding , w , ( g . ActiveId = = id ) ? edit_state . ScrollX : 0.0f ) ;
if ( g . ActiveId = = id )
{
2014-09-25 21:51:06 +08:00
const ImVec2 cursor_pos = frame_bb . Min + style . FramePadding + edit_state . CalcDisplayOffsetFromCharIdx ( edit_state . StbState . cursor ) ;
2014-08-19 19:09:13 +08:00
// Draw blinking cursor
if ( g . InputTextState . CursorIsVisible ( ) )
window - > DrawList - > AddRect ( cursor_pos - font_off_up + ImVec2 ( 0 , 2 ) , cursor_pos + font_off_dn - ImVec2 ( 0 , 3 ) , window - > Color ( ImGuiCol_Text ) ) ;
2014-09-25 21:51:06 +08:00
2015-02-21 21:36:24 +08:00
// Notify OS of text input position for advanced IME
if ( io . ImeSetInputScreenPosFn & & ImLengthSqr ( edit_state . InputCursorScreenPos - cursor_pos ) > 0.0001f )
2014-09-25 21:51:06 +08:00
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.
2015-02-21 21:36:24 +08:00
edit_state . InputCursorScreenPos = cursor_pos ;
2014-08-19 19:09:13 +08:00
}
RenderText ( ImVec2 ( frame_bb . Max . x + style . ItemInnerSpacing . x , frame_bb . Min . y + style . FramePadding . y ) , label ) ;
2014-09-08 21:48:39 +08:00
if ( ( flags & ImGuiInputTextFlags_EnterReturnsTrue ) ! = 0 )
return enter_pressed ;
else
return value_changed ;
2014-08-11 04:58:11 +08:00
}
2014-08-17 21:16:10 +08:00
static bool InputFloatN ( const char * label , float * v , int components , int decimal_precision )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
const ImGuiStyle & style = g . Style ;
2015-02-11 05:07:26 +08:00
const float w_full = ImGui : : CalcItemWidth ( ) ;
2014-12-30 19:41:46 +08:00
const float w_item_one = ImMax ( 1.0f , ( float ) ( int ) ( ( w_full - ( style . FramePadding . x * 2.0f + style . ItemInnerSpacing . x ) * ( components - 1 ) ) / ( float ) components ) ) ;
const float w_item_last = ImMax ( 1.0f , ( float ) ( int ) ( w_full - ( w_item_one + style . FramePadding . x * 2.0f + style . ItemInnerSpacing . x ) * ( components - 1 ) ) ) ;
2014-08-19 19:09:13 +08:00
bool value_changed = false ;
ImGui : : PushID ( label ) ;
ImGui : : PushItemWidth ( w_item_one ) ;
for ( int i = 0 ; i < components ; i + + )
{
ImGui : : PushID ( i ) ;
if ( i + 1 = = components )
{
ImGui : : PopItemWidth ( ) ;
ImGui : : PushItemWidth ( w_item_last ) ;
}
value_changed | = ImGui : : InputFloat ( " ##v " , & v [ i ] , 0 , 0 , decimal_precision ) ;
2014-12-30 19:41:46 +08:00
ImGui : : SameLine ( 0 , ( int ) style . ItemInnerSpacing . x ) ;
2014-08-19 19:09:13 +08:00
ImGui : : PopID ( ) ;
}
ImGui : : PopItemWidth ( ) ;
ImGui : : PopID ( ) ;
ImGui : : TextUnformatted ( label , FindTextDisplayEnd ( label ) ) ;
return value_changed ;
2014-08-14 01:38:24 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : InputFloat2 ( const char * label , float v [ 2 ] , int decimal_precision )
2014-08-14 01:38:24 +08:00
{
2014-08-19 19:09:13 +08:00
return InputFloatN ( label , v , 2 , decimal_precision ) ;
2014-08-17 21:16:10 +08:00
}
2014-08-11 04:58:11 +08:00
2014-11-10 09:29:01 +08:00
bool ImGui : : InputFloat3 ( const char * label , float v [ 3 ] , int decimal_precision )
2014-08-17 21:16:10 +08:00
{
2014-08-19 19:09:13 +08:00
return InputFloatN ( label , v , 3 , decimal_precision ) ;
2014-08-17 21:16:10 +08:00
}
2014-08-11 04:58:11 +08:00
2014-11-10 09:29:01 +08:00
bool ImGui : : InputFloat4 ( const char * label , float v [ 4 ] , int decimal_precision )
2014-08-17 21:16:10 +08:00
{
2014-08-19 19:09:13 +08:00
return InputFloatN ( label , v , 4 , decimal_precision ) ;
2014-08-11 04:58:11 +08:00
}
2015-02-11 01:45:45 +08:00
static bool Items_ArrayGetter ( void * data , int idx , const char * * out_text )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
const char * * items = ( const char * * ) data ;
if ( out_text )
* out_text = items [ idx ] ;
return true ;
2014-08-11 04:58:11 +08:00
}
2015-02-11 01:45:45 +08:00
static bool Items_SingleStringGetter ( void * data , int idx , const char * * out_text )
2014-08-11 04:58:11 +08:00
{
2015-02-11 01:45:45 +08:00
// FIXME-OPT: we could pre-compute the indices to fasten this. But only 1 active combo means the waste is limited.
2014-08-19 19:09:13 +08:00
const char * items_separated_by_zeros = ( const char * ) data ;
int items_count = 0 ;
const char * p = items_separated_by_zeros ;
while ( * p )
{
if ( idx = = items_count )
break ;
p + = strlen ( p ) + 1 ;
items_count + + ;
}
if ( ! * p )
return false ;
if ( out_text )
* out_text = p ;
return true ;
2014-08-11 04:58:11 +08:00
}
2015-02-11 01:45:45 +08:00
// Combo box helper allowing to pass an array of strings.
2015-02-11 06:48:46 +08:00
bool ImGui : : Combo ( const char * label , int * current_item , const char * * items , int items_count , int height_in_items )
2015-02-11 01:45:45 +08:00
{
2015-02-11 06:48:46 +08:00
const bool value_changed = Combo ( label , current_item , Items_ArrayGetter , ( void * ) items , items_count , height_in_items ) ;
2015-02-11 01:45:45 +08:00
return value_changed ;
}
2014-09-02 21:35:06 +08:00
// Combo box helper allowing to pass all items in a single string.
2015-02-11 06:48:46 +08:00
bool ImGui : : Combo ( const char * label , int * current_item , const char * items_separated_by_zeros , int height_in_items )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
int items_count = 0 ;
2015-02-11 01:45:45 +08:00
const char * p = items_separated_by_zeros ; // FIXME-OPT: Avoid computing this
2014-08-19 19:09:13 +08:00
while ( * p )
{
p + = strlen ( p ) + 1 ;
items_count + + ;
}
2015-02-11 06:48:46 +08:00
bool value_changed = Combo ( label , current_item , Items_SingleStringGetter , ( void * ) items_separated_by_zeros , items_count , height_in_items ) ;
2014-08-19 19:09:13 +08:00
return value_changed ;
2014-08-11 04:58:11 +08:00
}
2014-09-02 21:35:06 +08:00
// Combo box function.
2015-02-11 06:48:46 +08:00
bool ImGui : : Combo ( const char * label , int * current_item , bool ( * items_getter ) ( void * , int , const char * * ) , void * data , int items_count , int height_in_items )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
const ImGuiStyle & style = g . Style ;
const ImGuiID id = window - > GetID ( label ) ;
2015-02-11 05:07:26 +08:00
const float w = ImGui : : CalcItemWidth ( ) ;
2014-08-19 19:09:13 +08:00
2014-12-29 00:17:08 +08:00
const ImVec2 text_size = CalcTextSize ( label , NULL , true ) ;
2014-12-30 19:41:46 +08:00
const ImGuiAabb frame_bb ( window - > DC . CursorPos , window - > DC . CursorPos + ImVec2 ( w , text_size . y ) + style . FramePadding * 2.0f ) ;
2014-12-26 20:38:13 +08:00
ItemSize ( frame_bb ) ;
2015-01-23 06:54:05 +08:00
if ( ! ItemAdd ( frame_bb , & id ) )
2014-08-19 19:09:13 +08:00
return false ;
2014-12-26 20:38:13 +08:00
const ImGuiAabb bb ( frame_bb . Min , frame_bb . Max + ImVec2 ( style . ItemInnerSpacing . x + text_size . x , 0 ) ) ;
2014-12-29 01:54:02 +08:00
const float arrow_size = ( window - > FontSize ( ) + style . FramePadding . x * 2.0f ) ;
2015-01-05 02:32:15 +08:00
const bool hovered = IsHovered ( frame_bb , id ) ;
2014-08-19 19:09:13 +08:00
bool value_changed = false ;
2015-02-08 23:39:40 +08:00
const ImGuiAabb value_bb ( frame_bb . Min , frame_bb . Max - ImVec2 ( arrow_size , 0.0f ) ) ;
2015-01-15 17:14:44 +08:00
RenderFrame ( frame_bb . Min , frame_bb . Max , window - > Color ( ImGuiCol_FrameBg ) , true , style . FrameRounding ) ;
RenderFrame ( ImVec2 ( frame_bb . Max . x - arrow_size , frame_bb . Min . y ) , frame_bb . Max , window - > Color ( hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button ) , true , style . FrameRounding ) ; // FIXME-ROUNDING
2014-08-19 19:09:13 +08:00
RenderCollapseTriangle ( ImVec2 ( frame_bb . Max . x - arrow_size , frame_bb . Min . y ) + style . FramePadding , true ) ;
if ( * current_item > = 0 & & * current_item < items_count )
{
const char * item_text ;
if ( items_getter ( data , * current_item , & item_text ) )
2015-02-09 00:32:51 +08:00
RenderTextClipped ( frame_bb . Min + style . FramePadding , item_text , NULL , NULL , value_bb . Max ) ;
2014-08-19 19:09:13 +08:00
}
2014-12-30 19:41:46 +08:00
// Empty text doesn't add padding
if ( text_size . x > 0 )
{
2014-12-30 23:38:28 +08:00
ImGui : : SameLine ( 0 , ( int ) style . ItemInnerSpacing . x ) ;
2014-12-30 19:41:46 +08:00
ImGui : : TextUnformatted ( label , FindTextDisplayEnd ( label ) ) ;
}
2014-08-19 19:09:13 +08:00
2014-08-20 17:40:31 +08:00
ImGui : : PushID ( ( int ) id ) ;
2014-08-19 19:09:13 +08:00
bool menu_toggled = false ;
if ( hovered )
{
g . HoveredId = id ;
if ( g . IO . MouseClicked [ 0 ] )
{
menu_toggled = true ;
g . ActiveComboID = ( g . ActiveComboID = = id ) ? 0 : id ;
2015-01-05 02:36:33 +08:00
if ( g . ActiveComboID )
FocusWindow ( window ) ;
2014-08-19 19:09:13 +08:00
}
}
if ( g . ActiveComboID = = id )
{
2015-02-11 06:48:46 +08:00
// Size default to hold ~7 items
if ( height_in_items < 0 )
height_in_items = 7 ;
2014-08-19 19:09:13 +08:00
const ImVec2 backup_pos = ImGui : : GetCursorPos ( ) ;
2014-12-30 23:38:28 +08:00
const float popup_off_x = 0.0f ; //style.ItemInnerSpacing.x;
2015-02-11 06:48:46 +08:00
const float popup_height = ( text_size . y + style . ItemSpacing . y ) * ImMin ( items_count , height_in_items ) + style . WindowPadding . y ;
2014-08-19 19:09:13 +08:00
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 ) ) ;
ImGui : : SetCursorPos ( popup_aabb . Min - window - > Pos ) ;
2014-09-02 21:35:06 +08:00
const ImGuiWindowFlags flags = ImGuiWindowFlags_ComboBox | ( ( window - > Flags & ImGuiWindowFlags_ShowBorders ) ? ImGuiWindowFlags_ShowBorders : 0 ) ;
2014-08-19 19:09:13 +08:00
ImGui : : BeginChild ( " #ComboBox " , popup_aabb . GetSize ( ) , false , flags ) ;
ImGui : : Spacing ( ) ;
bool combo_item_active = false ;
2015-02-11 03:51:52 +08:00
combo_item_active | = ( g . ActiveId = = GetCurrentWindow ( ) - > GetID ( " #SCROLLY " ) ) ;
2014-08-19 19:09:13 +08:00
2014-11-24 18:02:39 +08:00
// Display items
2015-02-11 05:07:26 +08:00
for ( int i = 0 ; i < items_count ; i + + )
2014-08-19 19:09:13 +08:00
{
2015-02-11 05:07:26 +08:00
ImGui : : PushID ( ( void * ) ( intptr_t ) i ) ;
const bool item_selected = ( i = = * current_item ) ;
2014-08-19 19:09:13 +08:00
const char * item_text ;
2015-02-11 05:07:26 +08:00
if ( ! items_getter ( data , i , & item_text ) )
2014-08-19 19:09:13 +08:00
item_text = " *Unknown item* " ;
2015-02-11 03:51:52 +08:00
if ( ImGui : : Selectable ( item_text , item_selected ) )
2014-08-19 19:09:13 +08:00
{
2015-02-01 06:57:59 +08:00
SetActiveId ( 0 ) ;
2014-08-19 19:09:13 +08:00
g . ActiveComboID = 0 ;
value_changed = true ;
2015-02-11 05:07:26 +08:00
* current_item = i ;
2014-08-19 19:09:13 +08:00
}
2015-02-11 06:48:46 +08:00
if ( item_selected & & menu_toggled )
ImGui : : SetScrollPosHere ( ) ;
2015-02-11 03:51:52 +08:00
combo_item_active | = ImGui : : IsItemActive ( ) ;
ImGui : : PopID ( ) ;
2014-08-19 19:09:13 +08:00
}
ImGui : : EndChild ( ) ;
ImGui : : SetCursorPos ( backup_pos ) ;
if ( ! combo_item_active & & g . ActiveId ! = 0 )
g . ActiveComboID = 0 ;
}
ImGui : : PopID ( ) ;
return value_changed ;
2014-08-11 04:58:11 +08:00
}
2015-02-11 03:09:37 +08:00
// Tip: pass an empty label (e.g. "##dummy") then you can use the space to draw other text or image.
// But you need to make sure the ID is unique, e.g. enclose calls in PushID/PopID.
bool ImGui : : Selectable ( const char * label , bool selected , const ImVec2 & size_arg )
{
ImGuiState & g = * GImGui ;
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
const ImGuiStyle & style = g . Style ;
const ImGuiID id = window - > GetID ( label ) ;
const ImVec2 text_size = CalcTextSize ( label , NULL , true ) ;
const float w = window - > Pos . x + ImGui : : GetContentRegionMax ( ) . x - window - > DC . CursorPos . x ;
const ImVec2 size ( size_arg . x ! = 0.0f ? size_arg . x : w , size_arg . y ! = 0.0f ? size_arg . y : text_size . y ) ;
const ImGuiAabb bb ( window - > DC . CursorPos , window - > DC . CursorPos + size ) ;
ItemSize ( bb ) ;
2015-02-11 06:48:46 +08:00
// Selectables are meant to be tightly packed together. So for both rendering and collision we extend to compensate for spacing.
2015-02-11 03:09:37 +08:00
ImGuiAabb bb_with_spacing = bb ;
const float spacing_L = ( float ) ( int ) ( style . ItemSpacing . x * 0.5f ) ;
2015-02-11 06:48:46 +08:00
const float spacing_U = ( float ) ( int ) ( style . ItemSpacing . y * 0.5f ) ;
2015-02-11 03:09:37 +08:00
const float spacing_R = style . ItemSpacing . x - spacing_L ;
2015-02-11 06:48:46 +08:00
const float spacing_D = style . ItemSpacing . y - spacing_U ;
2015-02-11 03:09:37 +08:00
bb_with_spacing . Min . x - = spacing_L ;
2015-02-11 06:48:46 +08:00
bb_with_spacing . Min . y - = spacing_U ;
2015-02-11 03:09:37 +08:00
bb_with_spacing . Max . x + = spacing_R ;
2015-02-11 06:48:46 +08:00
bb_with_spacing . Max . y + = spacing_D ;
2015-02-11 03:09:37 +08:00
if ( ! ItemAdd ( bb_with_spacing , & id ) )
return false ;
bool hovered , held ;
bool pressed = ButtonBehaviour ( bb_with_spacing , id , & hovered , & held , true , false , false ) ;
// Render
if ( hovered | | selected )
{
const ImU32 col = window - > Color ( ( held & & hovered ) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header ) ;
RenderFrame ( bb_with_spacing . Min , bb_with_spacing . Max , col , false , style . FrameRounding ) ;
}
//const ImVec2 off = ImVec2(ImMax(0.0f, size.x - text_size.x) * 0.5f, ImMax(0.0f, size.y - text_size.y) * 0.5f);
2015-02-11 06:56:28 +08:00
RenderTextClipped ( bb . Min , label , NULL , & text_size , bb_with_spacing . Max ) ;
2015-02-11 03:09:37 +08:00
return pressed ;
}
bool ImGui : : Selectable ( const char * label , bool * p_selected , const ImVec2 & size_arg )
{
if ( ImGui : : Selectable ( label , * p_selected , size_arg ) )
{
* p_selected = ! * p_selected ;
return true ;
}
2015-02-11 03:47:35 +08:00
return false ;
2015-02-11 03:09:37 +08:00
}
2015-02-11 08:21:27 +08:00
// Helper to calculate the size of a listbox and display a label on the right.
// Tip: To have a list filling the entire window width, PushItemWidth(-1) and pass an empty label "##empty"
bool ImGui : : ListBoxHeader ( const char * label , const ImVec2 & size_arg )
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
const ImGuiStyle & style = ImGui : : GetStyle ( ) ;
const ImGuiID id = ImGui : : GetID ( label ) ;
const ImVec2 label_size = ImGui : : CalcTextSize ( label , NULL , true ) ;
// Size default to hold ~7 items. Fractional number of items helps seeing that we can scroll down/up without looking at scrollbar.
ImVec2 size ;
size . x = ( size_arg . x ! = 0.0f ) ? size_arg . x : ImGui : : CalcItemWidth ( ) + style . FramePadding . x * 2.0f ;
size . y = ( size_arg . y ! = 0.0f ) ? size_arg . y : ImGui : : GetTextLineHeightWithSpacing ( ) * 7.4f + style . ItemSpacing . y ;
const ImVec2 frame_size = ImVec2 ( size . x , ImMax ( size . y , label_size . y ) ) ;
const ImGuiAabb frame_bb ( window - > DC . CursorPos , window - > DC . CursorPos + frame_size ) ;
if ( label_size . x > 0 )
RenderText ( ImVec2 ( frame_bb . Max . x + style . ItemInnerSpacing . x , frame_bb . Min . y + style . FramePadding . y ) , label ) ;
ImGui : : BeginChildFrame ( id , frame_bb . GetSize ( ) ) ;
return true ;
}
bool ImGui : : ListBoxHeader ( const char * label , int items_count , int height_in_items )
{
// Size default to hold ~7 items. Fractional number of items helps seeing that we can scroll down/up without looking at scrollbar.
// However we don't add +0.40f if items_count <= height_in_items. It is slightly dodgy, because it means a dynamic list of items will make the widget resize occasionally when it crosses that size.
// I am expecting that someone will come and complain about this behavior in a remote future, then we can advise on a better solution.
if ( height_in_items < 0 )
height_in_items = ImMin ( items_count , 7 ) ;
float height_in_items_f = height_in_items < items_count ? ( height_in_items + 0.40f ) : ( height_in_items + 0.00f ) ;
// We include ItemSpacing.y so that a list sized for the exact number of items doesn't make a scrollbar appears. We could also enforce that by passing a flag to BeginChild().
ImVec2 size ;
size . x = 0.0f ;
size . y = ImGui : : GetTextLineHeightWithSpacing ( ) * height_in_items_f + ImGui : : GetStyle ( ) . ItemSpacing . y ;
return ImGui : : ListBoxHeader ( label , size ) ;
}
void ImGui : : ListBoxFooter ( )
{
ImGui : : EndChildFrame ( ) ;
}
bool ImGui : : ListBox ( const char * label , int * current_item , const char * * items , int items_count , int height_items )
{
const bool value_changed = ListBox ( label , current_item , Items_ArrayGetter , ( void * ) items , items_count , height_items ) ;
return value_changed ;
}
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 )
{
if ( ! ImGui : : ListBoxHeader ( label , items_count , height_in_items ) )
return false ;
bool value_changed = false ;
for ( int i = 0 ; i < items_count ; i + + )
{
const bool item_selected = ( i = = * current_item ) ;
const char * item_text ;
if ( ! items_getter ( data , i , & item_text ) )
item_text = " *Unknown item* " ;
ImGui : : PushID ( i ) ;
if ( ImGui : : Selectable ( item_text , item_selected ) )
{
* current_item = i ;
value_changed = true ;
}
ImGui : : PopID ( ) ;
}
ImGui : : ListBoxFooter ( ) ;
return value_changed ;
}
2014-08-11 04:58:11 +08:00
// A little colored square. Return true when clicked.
2014-11-10 09:29:01 +08:00
bool ImGui : : ColorButton ( const ImVec4 & col , bool small_height , bool outline_border )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
const ImGuiStyle & style = g . Style ;
2015-01-15 17:49:12 +08:00
const ImGuiID id = window - > GetID ( " ##colorbutton " ) ;
2014-08-19 19:09:13 +08:00
const float square_size = window - > FontSize ( ) ;
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 ) ) ) ;
ItemSize ( bb ) ;
2015-01-23 06:54:05 +08:00
if ( ! ItemAdd ( bb , & id ) )
2014-08-19 19:09:13 +08:00
return false ;
2014-08-11 04:58:11 +08:00
2015-01-15 17:49:12 +08:00
bool hovered , held ;
bool pressed = ButtonBehaviour ( bb , id , & hovered , & held , true ) ;
2015-01-15 17:14:44 +08:00
RenderFrame ( bb . Min , bb . Max , window - > Color ( col ) , outline_border , style . FrameRounding ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( hovered )
{
int ix = ( int ) ( col . x * 255.0f + 0.5f ) ;
int iy = ( int ) ( col . y * 255.0f + 0.5f ) ;
int iz = ( int ) ( col . z * 255.0f + 0.5f ) ;
int iw = ( int ) ( col . w * 255.0f + 0.5f ) ;
ImGui : : SetTooltip ( " Color: \n (%.2f,%.2f,%.2f,%.2f) \n #%02X%02X%02X%02X " , col . x , col . y , col . z , col . w , ix , iy , iz , iw ) ;
}
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
return pressed ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : ColorEdit3 ( const char * label , float col [ 3 ] )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
float col4 [ 4 ] ;
col4 [ 0 ] = col [ 0 ] ;
col4 [ 1 ] = col [ 1 ] ;
col4 [ 2 ] = col [ 2 ] ;
col4 [ 3 ] = 1.0f ;
2014-09-02 21:35:06 +08:00
const bool value_changed = ImGui : : ColorEdit4 ( label , col4 , false ) ;
2014-08-19 19:09:13 +08:00
col [ 0 ] = col4 [ 0 ] ;
col [ 1 ] = col4 [ 1 ] ;
col [ 2 ] = col4 [ 2 ] ;
return value_changed ;
2014-08-11 04:58:11 +08:00
}
2014-11-24 18:02:39 +08:00
// Edit colors components (each component in 0.0f..1.0f range
2014-08-11 04:58:11 +08:00
// Use CTRL-Click to input value and TAB to go to next item.
2014-11-10 09:29:01 +08:00
bool ImGui : : ColorEdit4 ( const char * label , float col [ 4 ] , bool alpha )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
const ImGuiStyle & style = g . Style ;
const ImGuiID id = window - > GetID ( label ) ;
2015-02-11 05:07:26 +08:00
const float w_full = ImGui : : CalcItemWidth ( ) ;
2014-08-19 19:09:13 +08:00
const float square_sz = ( window - > FontSize ( ) + style . FramePadding . x * 2.0f ) ;
ImGuiColorEditMode edit_mode = window - > DC . ColorEditMode ;
2015-01-15 17:49:12 +08:00
if ( edit_mode = = ImGuiColorEditMode_UserSelect | | edit_mode = = ImGuiColorEditMode_UserSelectShowButton )
2014-08-19 19:09:13 +08:00
edit_mode = g . ColorEditModeStorage . GetInt ( id , 0 ) % 3 ;
float fx = col [ 0 ] ;
float fy = col [ 1 ] ;
float fz = col [ 2 ] ;
float fw = col [ 3 ] ;
const ImVec4 col_display ( fx , fy , fz , 1.0f ) ;
if ( edit_mode = = ImGuiColorEditMode_HSV )
2015-02-01 00:36:12 +08:00
ImGui : : ColorConvertRGBtoHSV ( fx , fy , fz , fx , fy , fz ) ;
2014-08-19 19:09:13 +08:00
int ix = ( int ) ( fx * 255.0f + 0.5f ) ;
int iy = ( int ) ( fy * 255.0f + 0.5f ) ;
int iz = ( int ) ( fz * 255.0f + 0.5f ) ;
int iw = ( int ) ( fw * 255.0f + 0.5f ) ;
int components = alpha ? 4 : 3 ;
bool value_changed = false ;
ImGui : : PushID ( label ) ;
bool hsv = ( edit_mode = = 1 ) ;
switch ( edit_mode )
{
case ImGuiColorEditMode_RGB :
case ImGuiColorEditMode_HSV :
{
2014-12-30 19:54:04 +08:00
// 0: RGB 0..255 Sliders
// 1: HSV 0..255 Sliders
2014-08-19 19:09:13 +08:00
const float w_items_all = w_full - ( square_sz + style . ItemInnerSpacing . x ) ;
2014-12-30 19:41:46 +08:00
const float w_item_one = ImMax ( 1.0f , ( float ) ( int ) ( ( w_items_all - ( style . FramePadding . x * 2.0f + style . ItemInnerSpacing . x ) * ( components - 1 ) ) / ( float ) components ) ) ;
const float w_item_last = ImMax ( 1.0f , ( float ) ( int ) ( w_items_all - ( w_item_one + style . FramePadding . x * 2.0f + style . ItemInnerSpacing . x ) * ( components - 1 ) ) ) ;
2014-08-19 19:09:13 +08:00
ImGui : : PushItemWidth ( w_item_one ) ;
value_changed | = ImGui : : SliderInt ( " ##X " , & ix , 0 , 255 , hsv ? " H:%3.0f " : " R:%3.0f " ) ;
2014-12-30 19:41:46 +08:00
ImGui : : SameLine ( 0 , ( int ) style . ItemInnerSpacing . x ) ;
2014-08-19 19:09:13 +08:00
value_changed | = ImGui : : SliderInt ( " ##Y " , & iy , 0 , 255 , hsv ? " S:%3.0f " : " G:%3.0f " ) ;
2014-12-30 19:41:46 +08:00
ImGui : : SameLine ( 0 , ( int ) style . ItemInnerSpacing . x ) ;
2014-08-19 19:09:13 +08:00
if ( alpha )
{
value_changed | = ImGui : : SliderInt ( " ##Z " , & iz , 0 , 255 , hsv ? " V:%3.0f " : " B:%3.0f " ) ;
2014-12-30 19:41:46 +08:00
ImGui : : SameLine ( 0 , ( int ) style . ItemInnerSpacing . x ) ;
2014-08-19 19:09:13 +08:00
ImGui : : PushItemWidth ( w_item_last ) ;
value_changed | = ImGui : : SliderInt ( " ##W " , & iw , 0 , 255 , " A:%3.0f " ) ;
}
else
{
ImGui : : PushItemWidth ( w_item_last ) ;
value_changed | = ImGui : : SliderInt ( " ##Z " , & iz , 0 , 255 , hsv ? " V:%3.0f " : " B:%3.0f " ) ;
}
ImGui : : PopItemWidth ( ) ;
ImGui : : PopItemWidth ( ) ;
}
break ;
case ImGuiColorEditMode_HEX :
{
// 2: RGB Hexadecimal
const float w_slider_all = w_full - square_sz ;
char buf [ 64 ] ;
if ( alpha )
sprintf ( buf , " #%02X%02X%02X%02X " , ix , iy , iz , iw ) ;
else
sprintf ( buf , " #%02X%02X%02X " , ix , iy , iz ) ;
2014-12-30 23:38:28 +08:00
ImGui : : PushItemWidth ( w_slider_all - style . ItemInnerSpacing . x ) ;
2014-08-19 19:09:13 +08:00
value_changed | = ImGui : : InputText ( " ##Text " , buf , IM_ARRAYSIZE ( buf ) , ImGuiInputTextFlags_CharsHexadecimal ) ;
ImGui : : PopItemWidth ( ) ;
char * p = buf ;
while ( * p = = ' # ' | | * p = = ' ' | | * p = = ' \t ' )
p + + ;
2014-10-27 02:57:19 +08:00
2014-10-27 04:07:15 +08:00
// Treat at unsigned (%X is unsigned)
2014-08-19 19:09:13 +08:00
ix = iy = iz = iw = 0 ;
if ( alpha )
2014-10-27 02:57:19 +08:00
sscanf ( p , " %02X%02X%02X%02X " , ( unsigned int * ) & ix , ( unsigned int * ) & iy , ( unsigned int * ) & iz , ( unsigned int * ) & iw ) ;
2014-08-19 19:09:13 +08:00
else
2014-10-27 02:57:19 +08:00
sscanf ( p , " %02X%02X%02X " , ( unsigned int * ) & ix , ( unsigned int * ) & iy , ( unsigned int * ) & iz ) ;
2014-08-19 19:09:13 +08:00
}
break ;
}
2014-12-30 19:41:46 +08:00
ImGui : : SameLine ( 0 , ( int ) style . ItemInnerSpacing . x ) ;
2015-01-15 17:49:12 +08:00
if ( ImGui : : ColorButton ( col_display ) )
{
// Don't set local copy of 'edit_mode' right away!
g . ColorEditModeStorage . SetInt ( id , ( edit_mode + 1 ) % 3 ) ;
}
2014-08-19 19:09:13 +08:00
2015-01-15 17:49:12 +08:00
if ( window - > DC . ColorEditMode = = ImGuiColorEditMode_UserSelectShowButton )
2014-08-19 19:09:13 +08:00
{
ImGui : : SameLine ( 0 , ( int ) style . ItemInnerSpacing . x ) ;
const char * button_titles [ 3 ] = { " RGB " , " HSV " , " HEX " } ;
if ( ImGui : : Button ( button_titles [ edit_mode ] ) )
{
2014-11-24 18:02:39 +08:00
// Don't set local copy of 'edit_mode' right away!
2014-08-19 19:09:13 +08:00
g . ColorEditModeStorage . SetInt ( id , ( edit_mode + 1 ) % 3 ) ;
}
2015-01-18 01:19:07 +08:00
ImGui : : SameLine ( ) ;
}
else
{
ImGui : : SameLine ( 0 , ( int ) style . ItemInnerSpacing . x ) ;
2014-08-19 19:09:13 +08:00
}
ImGui : : TextUnformatted ( label , FindTextDisplayEnd ( label ) ) ;
// Convert back
fx = ix / 255.0f ;
fy = iy / 255.0f ;
fz = iz / 255.0f ;
fw = iw / 255.0f ;
if ( edit_mode = = 1 )
2015-02-01 00:36:12 +08:00
ImGui : : ColorConvertHSVtoRGB ( fx , fy , fz , fx , fy , fz ) ;
2014-08-19 19:09:13 +08:00
if ( value_changed )
{
col [ 0 ] = fx ;
col [ 1 ] = fy ;
col [ 2 ] = fz ;
if ( alpha )
col [ 3 ] = fw ;
}
ImGui : : PopID ( ) ;
return value_changed ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : ColorEditMode ( ImGuiColorEditMode mode )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > DC . ColorEditMode = mode ;
2014-08-11 04:58:11 +08:00
}
2014-11-24 18:02:39 +08:00
// Horizontal separating line.
2014-11-10 09:29:01 +08:00
void ImGui : : Separator ( )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( window - > DC . ColumnsCount > 1 )
2014-11-10 09:29:01 +08:00
PopClipRect ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
const ImGuiAabb bb ( ImVec2 ( window - > Pos . x , window - > DC . CursorPos . y ) , ImVec2 ( window - > Pos . x + window - > Size . x , window - > DC . CursorPos . y ) ) ;
ItemSize ( ImVec2 ( 0.0f , bb . GetSize ( ) . y ) ) ; // NB: we don't provide our width so that it doesn't get feed back into AutoFit
2015-01-23 06:54:05 +08:00
if ( ! ItemAdd ( bb , NULL ) )
2014-08-19 19:09:13 +08:00
{
if ( window - > DC . ColumnsCount > 1 )
2014-11-10 09:29:01 +08:00
PushColumnClipRect ( ) ;
2014-08-19 19:09:13 +08:00
return ;
}
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
window - > DrawList - > AddLine ( bb . Min , bb . Max , window - > Color ( ImGuiCol_Border ) ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( window - > DC . ColumnsCount > 1 )
2014-11-10 09:29:01 +08:00
PushColumnClipRect ( ) ;
2014-08-11 04:58:11 +08:00
}
2014-09-02 21:35:06 +08:00
// A little vertical spacing.
2014-11-10 09:29:01 +08:00
void ImGui : : Spacing ( )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
ItemSize ( ImVec2 ( 0 , 0 ) ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-24 18:02:39 +08:00
// Advance cursor given item size.
2015-02-01 00:21:12 +08:00
static void ItemSize ( ImVec2 size , ImVec2 * adjust_vertical_offset )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
const float line_height = ImMax ( window - > DC . CurrentLineHeight , size . y ) ;
2015-02-01 00:21:12 +08:00
if ( adjust_vertical_offset )
adjust_vertical_offset - > y = adjust_vertical_offset - > y + ( line_height - size . y ) * 0.5f ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
// Always align ourselves on pixel boundaries
window - > DC . CursorPosPrevLine = ImVec2 ( window - > DC . CursorPos . x + size . x , window - > DC . CursorPos . y ) ;
2014-11-20 19:31:55 +08:00
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 ) ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
window - > SizeContentsFit = ImMax ( window - > SizeContentsFit , ImVec2 ( window - > DC . CursorPosPrevLine . x , window - > DC . CursorPos . y ) - window - > Pos + ImVec2 ( 0.0f , window - > ScrollY ) ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
window - > DC . PrevLineHeight = line_height ;
window - > DC . CurrentLineHeight = 0.0f ;
2014-08-11 04:58:11 +08:00
}
static void ItemSize ( const ImGuiAabb & aabb , ImVec2 * adjust_start_offset )
{
2014-08-19 19:09:13 +08:00
ItemSize ( aabb . GetSize ( ) , adjust_start_offset ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
static bool IsClipped ( const ImGuiAabb & bb )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( ! bb . Overlaps ( ImGuiAabb ( window - > ClipRectStack . back ( ) ) ) & & ! g . LogEnabled )
return true ;
return false ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
bool ImGui : : IsClipped ( const ImVec2 & item_size )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return IsClipped ( ImGuiAabb ( window - > DC . CursorPos , window - > DC . CursorPos + item_size ) ) ;
2014-08-11 04:58:11 +08:00
}
2015-01-23 06:54:05 +08:00
static bool ItemAdd ( const ImGuiAabb & bb , const ImGuiID * id )
2014-08-11 04:58:11 +08:00
{
2015-02-22 00:50:34 +08:00
//ImGuiState& g = *GImGui;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2015-01-23 06:54:05 +08:00
window - > DC . LastItemID = id ? * id : 0 ;
2014-08-19 19:09:13 +08:00
window - > DC . LastItemAabb = bb ;
2014-11-10 09:29:01 +08:00
if ( IsClipped ( bb ) )
2014-08-19 19:09:13 +08:00
{
window - > DC . LastItemHovered = false ;
2015-01-23 06:54:05 +08:00
return false ;
2014-08-19 19:09:13 +08:00
}
2015-02-22 00:50:34 +08:00
// This is a sensible default, but widgets are free to override it after calling ItemAdd()
const bool hovered = IsMouseHoveringBox ( bb ) ;
//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?
window - > DC . LastItemHovered = hovered ;
2015-01-23 06:54:05 +08:00
return true ;
2014-08-11 04:58:11 +08:00
}
// Gets back to previous line and continue with horizontal layout
2014-08-19 19:09:13 +08:00
// column_x == 0 : follow on previous item
// columm_x != 0 : align to specified column
// spacing_w < 0 : use default spacing if column_x==0, no spacing if column_x!=0
// spacing_w >= 0 : enforce spacing
2014-11-10 09:29:01 +08:00
void ImGui : : SameLine ( int column_x , int spacing_w )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return ;
float x , y ;
if ( column_x ! = 0 )
{
if ( spacing_w < 0 ) spacing_w = 0 ;
x = window - > Pos . x + ( float ) column_x + ( float ) spacing_w ;
y = window - > DC . CursorPosPrevLine . y ;
}
else
{
if ( spacing_w < 0 ) spacing_w = ( int ) g . Style . ItemSpacing . x ;
x = window - > DC . CursorPosPrevLine . x + ( float ) spacing_w ;
y = window - > DC . CursorPosPrevLine . y ;
}
window - > DC . CurrentLineHeight = window - > DC . PrevLineHeight ;
window - > DC . CursorPos = ImVec2 ( x , y ) ;
2014-08-11 04:58:11 +08:00
}
2015-01-23 06:54:05 +08:00
void ImGui : : NextColumn ( )
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2015-01-23 06:54:05 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return ;
if ( window - > DC . ColumnsCount > 1 )
{
ImGui : : PopItemWidth ( ) ;
PopClipRect ( ) ;
window - > DC . ColumnsCellMaxY = ImMax ( window - > DC . ColumnsCellMaxY , window - > DC . CursorPos . y ) ;
if ( + + window - > DC . ColumnsCurrent < window - > DC . ColumnsCount )
{
window - > DC . ColumnsOffsetX = ImGui : : GetColumnOffset ( window - > DC . ColumnsCurrent ) - window - > DC . ColumnsStartX + g . Style . ItemSpacing . x ;
}
else
{
window - > DC . ColumnsCurrent = 0 ;
window - > DC . ColumnsOffsetX = 0.0f ;
window - > DC . ColumnsCellMinY = window - > DC . ColumnsCellMaxY ;
}
window - > DC . CursorPos . x = ( float ) ( int ) ( window - > Pos . x + window - > DC . ColumnsStartX + window - > DC . ColumnsOffsetX ) ;
window - > DC . CursorPos . y = window - > DC . ColumnsCellMinY ;
window - > DC . CurrentLineHeight = 0.0f ;
PushColumnClipRect ( ) ;
ImGui : : PushItemWidth ( ImGui : : GetColumnWidth ( ) * 0.65f ) ;
}
}
2014-11-10 09:29:01 +08:00
float ImGui : : GetColumnOffset ( int column_index )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( column_index < 0 )
2014-11-20 19:31:55 +08:00
column_index = window - > DC . ColumnsCurrent ;
2014-08-11 04:58:11 +08:00
2015-02-11 19:50:24 +08:00
// Read from cache
IM_ASSERT ( column_index < ( int ) window - > DC . ColumnsOffsetsT . size ( ) ) ;
const float t = window - > DC . ColumnsOffsetsT [ column_index ] ;
2014-11-20 19:31:55 +08:00
const float offset = window - > DC . ColumnsStartX + t * ( window - > Size . x - g . Style . ScrollBarWidth - window - > DC . ColumnsStartX ) ;
2014-08-19 19:09:13 +08:00
return offset ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : SetColumnOffset ( int column_index , float offset )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( column_index < 0 )
2014-11-20 19:31:55 +08:00
column_index = window - > DC . ColumnsCurrent ;
2014-08-11 04:58:11 +08:00
2015-02-11 19:50:24 +08:00
IM_ASSERT ( column_index < ( int ) window - > DC . ColumnsOffsetsT . size ( ) ) ;
2014-08-20 17:40:31 +08:00
const ImGuiID column_id = window - > DC . ColumnsSetID + ImGuiID ( column_index ) ;
2014-11-20 19:31:55 +08:00
const float t = ( offset - window - > DC . ColumnsStartX ) / ( window - > Size . x - g . Style . ScrollBarWidth - window - > DC . ColumnsStartX ) ;
2014-12-30 02:17:54 +08:00
window - > StateStorage . SetFloat ( column_id , t ) ;
2015-02-11 19:50:24 +08:00
window - > DC . ColumnsOffsetsT [ column_index ] = t ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
float ImGui : : GetColumnWidth ( int column_index )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( column_index < 0 )
2014-11-20 19:31:55 +08:00
column_index = window - > DC . ColumnsCurrent ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
const float w = GetColumnOffset ( column_index + 1 ) - GetColumnOffset ( column_index ) ;
return w ;
2014-08-11 04:58:11 +08:00
}
static void PushColumnClipRect ( int column_index )
{
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( column_index < 0 )
2014-11-20 19:31:55 +08:00
column_index = window - > DC . ColumnsCurrent ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
const float x1 = window - > Pos . x + ImGui : : GetColumnOffset ( column_index ) - 1 ;
const float x2 = window - > Pos . x + ImGui : : GetColumnOffset ( column_index + 1 ) - 1 ;
2014-11-10 09:29:01 +08:00
PushClipRect ( ImVec4 ( x1 , - FLT_MAX , x2 , + FLT_MAX ) ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : Columns ( int columns_count , const char * id , bool border )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > DC . ColumnsCount ! = 1 )
{
2014-11-20 19:31:55 +08:00
if ( window - > DC . ColumnsCurrent ! = 0 )
2014-11-10 09:29:01 +08:00
ItemSize ( ImVec2 ( 0 , 0 ) ) ; // Advance to column 0
2014-08-19 19:09:13 +08:00
ImGui : : PopItemWidth ( ) ;
2014-11-10 09:29:01 +08:00
PopClipRect ( ) ;
2014-11-20 19:31:55 +08:00
window - > DC . ColumnsCellMaxY = ImMax ( window - > DC . ColumnsCellMaxY , window - > DC . CursorPos . y ) ;
window - > DC . CursorPos . y = window - > DC . ColumnsCellMaxY ;
2014-08-19 19:09:13 +08:00
}
2014-11-20 19:31:55 +08:00
// Draw columns borders and handle resize at the time of "closing" a columns set
2015-02-21 18:27:13 +08:00
if ( window - > DC . ColumnsCount ! = columns_count & & window - > DC . ColumnsCount ! = 1 & & window - > DC . ColumnsShowBorders & & ! window - > SkipItems )
2014-08-19 19:09:13 +08:00
{
2014-11-20 19:31:55 +08:00
const float y1 = window - > DC . ColumnsStartPos . y ;
2014-08-19 19:09:13 +08:00
const float y2 = window - > DC . CursorPos . y ;
for ( int i = 1 ; i < window - > DC . ColumnsCount ; i + + )
{
float x = window - > Pos . x + GetColumnOffset ( i ) ;
2014-08-20 17:40:31 +08:00
const ImGuiID column_id = window - > DC . ColumnsSetID + ImGuiID ( i ) ;
2014-08-19 19:09:13 +08:00
const ImGuiAabb column_aabb ( ImVec2 ( x - 4 , y1 ) , ImVec2 ( x + 4 , y2 ) ) ;
if ( IsClipped ( column_aabb ) )
continue ;
bool hovered , held ;
ButtonBehaviour ( column_aabb , column_id , & hovered , & held , true ) ;
2014-09-02 21:35:06 +08:00
// Draw before resize so our items positioning are in sync with the line being drawn
2014-08-19 19:09:13 +08:00
const ImU32 col = window - > Color ( held ? ImGuiCol_ColumnActive : hovered ? ImGuiCol_ColumnHovered : ImGuiCol_Column ) ;
const float xi = ( float ) ( int ) x ;
window - > DrawList - > AddLine ( ImVec2 ( xi , y1 ) , ImVec2 ( xi , y2 ) , col ) ;
if ( held )
{
x - = window - > Pos . x ;
x = ImClamp ( x + g . IO . MouseDelta . x , ImGui : : GetColumnOffset ( i - 1 ) + g . Style . ColumnsMinSpacing , ImGui : : GetColumnOffset ( i + 1 ) - g . Style . ColumnsMinSpacing ) ;
SetColumnOffset ( i , x ) ;
x + = window - > Pos . x ;
}
}
}
2014-11-20 19:31:55 +08:00
// Set state for first column
2014-08-19 19:09:13 +08:00
window - > DC . ColumnsSetID = window - > GetID ( id ? id : " " ) ;
2014-11-20 19:31:55 +08:00
window - > DC . ColumnsCurrent = 0 ;
2014-08-19 19:09:13 +08:00
window - > DC . ColumnsCount = columns_count ;
window - > DC . ColumnsShowBorders = border ;
2014-11-20 19:31:55 +08:00
window - > DC . ColumnsStartPos = window - > DC . CursorPos ;
window - > DC . ColumnsCellMinY = window - > DC . ColumnsCellMaxY = window - > DC . CursorPos . y ;
window - > DC . ColumnsOffsetX = 0.0f ;
window - > DC . CursorPos . x = ( float ) ( int ) ( window - > Pos . x + window - > DC . ColumnsStartX + window - > DC . ColumnsOffsetX ) ;
2014-08-19 19:09:13 +08:00
if ( window - > DC . ColumnsCount ! = 1 )
{
2015-02-11 19:50:24 +08:00
// Cache column offsets
window - > DC . ColumnsOffsetsT . resize ( ( size_t ) columns_count + 1 ) ;
for ( int column_index = 0 ; column_index < columns_count + 1 ; column_index + + )
{
const ImGuiID column_id = window - > DC . ColumnsSetID + ImGuiID ( column_index ) ;
RegisterAliveId ( column_id ) ;
const float default_t = column_index / ( float ) window - > DC . ColumnsCount ;
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?)
window - > DC . ColumnsOffsetsT [ column_index ] = t ;
}
2014-11-10 09:29:01 +08:00
PushColumnClipRect ( ) ;
2014-08-19 19:09:13 +08:00
ImGui : : PushItemWidth ( ImGui : : GetColumnWidth ( ) * 0.65f ) ;
}
2015-02-11 19:50:24 +08:00
else
{
window - > DC . ColumnsOffsetsT . resize ( 2 ) ;
window - > DC . ColumnsOffsetsT [ 0 ] = 0.0f ;
window - > DC . ColumnsOffsetsT [ 1 ] = 1.0f ;
}
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : TreePush ( const char * str_id )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-11-20 19:31:55 +08:00
window - > DC . ColumnsStartX + = g . Style . TreeNodeSpacing ;
window - > DC . CursorPos . x = window - > Pos . x + window - > DC . ColumnsStartX + window - > DC . ColumnsOffsetX ;
2014-08-19 19:09:13 +08:00
window - > DC . TreeDepth + + ;
PushID ( str_id ? str_id : " #TreePush " ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : TreePush ( const void * ptr_id )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-11-20 19:31:55 +08:00
window - > DC . ColumnsStartX + = g . Style . TreeNodeSpacing ;
window - > DC . CursorPos . x = window - > Pos . x + window - > DC . ColumnsStartX + window - > DC . ColumnsOffsetX ;
2014-08-19 19:09:13 +08:00
window - > DC . TreeDepth + + ;
PushID ( ptr_id ? ptr_id : ( const void * ) " #TreePush " ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : TreePop ( )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-11-20 19:31:55 +08:00
window - > DC . ColumnsStartX - = g . Style . TreeNodeSpacing ;
window - > DC . CursorPos . x = window - > Pos . x + window - > DC . ColumnsStartX + window - > DC . ColumnsOffsetX ;
2014-08-19 19:09:13 +08:00
window - > DC . TreeDepth - - ;
PopID ( ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-12 07:36:34 +08:00
void ImGui : : Value ( const char * prefix , bool b )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGui : : Text ( " %s: %s " , prefix , ( b ? " true " : " false " ) ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-12 07:36:34 +08:00
void ImGui : : Value ( const char * prefix , int v )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGui : : Text ( " %s: %d " , prefix , v ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-12 07:36:34 +08:00
void ImGui : : Value ( const char * prefix , unsigned int v )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGui : : Text ( " %s: %d " , prefix , v ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-12 07:36:34 +08:00
void ImGui : : Value ( const char * prefix , float v , const char * float_format )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
if ( float_format )
{
char fmt [ 64 ] ;
sprintf ( fmt , " %%s: %s " , float_format ) ;
ImGui : : Text ( fmt , prefix , v ) ;
}
else
{
ImGui : : Text ( " %s: %.3f " , prefix , v ) ;
}
2014-08-11 04:58:11 +08:00
}
2014-11-12 07:36:34 +08:00
void ImGui : : Color ( const char * prefix , const ImVec4 & v )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGui : : Text ( " %s: (%.2f,%.2f,%.2f,%.2f) " , prefix , v . x , v . y , v . z , v . w ) ;
ImGui : : SameLine ( ) ;
ImGui : : ColorButton ( v , true ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-12 07:36:34 +08:00
void ImGui : : Color ( const char * prefix , unsigned int v )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
ImGui : : Text ( " %s: %08X " , prefix , v ) ;
ImGui : : SameLine ( ) ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
ImVec4 col ;
col . x = ( float ) ( ( v > > 0 ) & 0xFF ) / 255.0f ;
col . y = ( float ) ( ( v > > 8 ) & 0xFF ) / 255.0f ;
col . z = ( float ) ( ( v > > 16 ) & 0xFF ) / 255.0f ;
col . w = ( float ) ( ( v > > 24 ) & 0xFF ) / 255.0f ;
ImGui : : ColorButton ( col , true ) ;
2014-08-11 04:58:11 +08:00
}
//-----------------------------------------------------------------------------
// ImDrawList
//-----------------------------------------------------------------------------
2015-01-12 00:30:39 +08:00
static ImVec4 GNullClipRect ( - 9999.0f , - 9999.0f , + 9999.0f , + 9999.0f ) ;
2014-08-11 04:58:11 +08:00
void ImDrawList : : Clear ( )
{
2014-08-19 19:09:13 +08:00
commands . resize ( 0 ) ;
vtx_buffer . resize ( 0 ) ;
vtx_write = NULL ;
clip_rect_stack . resize ( 0 ) ;
2015-01-12 00:30:39 +08:00
texture_id_stack . resize ( 0 ) ;
2014-08-11 04:58:11 +08:00
}
2015-01-31 23:24:55 +08:00
void ImDrawList : : AddDrawCmd ( )
2015-01-31 17:51:25 +08:00
{
ImDrawCmd draw_cmd ;
draw_cmd . vtx_count = 0 ;
2015-01-31 23:24:55 +08:00
draw_cmd . clip_rect = clip_rect_stack . empty ( ) ? GNullClipRect : clip_rect_stack . back ( ) ;
draw_cmd . texture_id = texture_id_stack . empty ( ) ? NULL : texture_id_stack . back ( ) ;
draw_cmd . user_callback = NULL ;
draw_cmd . user_callback_data = NULL ;
2015-01-31 17:51:25 +08:00
commands . push_back ( draw_cmd ) ;
}
2015-01-31 23:24:55 +08:00
void ImDrawList : : AddCallback ( ImDrawCallback callback , void * callback_data )
2014-08-11 04:58:11 +08:00
{
2015-01-17 22:13:08 +08:00
ImDrawCmd * current_cmd = commands . empty ( ) ? NULL : & commands . back ( ) ;
2015-01-31 23:24:55 +08:00
if ( ! current_cmd | | current_cmd - > vtx_count ! = 0 | | current_cmd - > user_callback ! = NULL )
2014-08-19 19:09:13 +08:00
{
2015-01-31 23:24:55 +08:00
AddDrawCmd ( ) ;
current_cmd = & commands . back ( ) ;
}
current_cmd - > user_callback = callback ;
current_cmd - > user_callback_data = callback_data ;
// Force a new command after us
// We function this way so that the most common calls (AddLine, AddRect..) always have a command to add to without doing any check.
AddDrawCmd ( ) ;
}
void ImDrawList : : UpdateClipRect ( )
{
ImDrawCmd * current_cmd = commands . empty ( ) ? NULL : & commands . back ( ) ;
if ( ! current_cmd | | ( current_cmd - > vtx_count ! = 0 ) | | current_cmd - > user_callback ! = NULL )
{
AddDrawCmd ( ) ;
2014-08-19 19:09:13 +08:00
}
else
{
2015-01-31 23:24:55 +08:00
current_cmd - > clip_rect = clip_rect_stack . empty ( ) ? GNullClipRect : clip_rect_stack . back ( ) ;
2014-08-19 19:09:13 +08:00
}
2015-01-12 00:30:39 +08:00
}
2015-02-03 03:50:28 +08:00
// Scissoring. The values in clip_rect are x1, y1, x2, y2.
2015-01-12 00:30:39 +08:00
void ImDrawList : : PushClipRect ( const ImVec4 & clip_rect )
{
2014-08-19 19:09:13 +08:00
clip_rect_stack . push_back ( clip_rect ) ;
2015-01-31 23:24:55 +08:00
UpdateClipRect ( ) ;
2014-08-11 04:58:11 +08:00
}
void ImDrawList : : PopClipRect ( )
{
2015-01-29 21:07:20 +08:00
IM_ASSERT ( clip_rect_stack . size ( ) > 0 ) ;
2014-08-19 19:09:13 +08:00
clip_rect_stack . pop_back ( ) ;
2015-01-31 23:24:55 +08:00
UpdateClipRect ( ) ;
2015-01-12 00:30:39 +08:00
}
2015-01-31 23:24:55 +08:00
void ImDrawList : : UpdateTextureID ( )
2015-01-12 00:30:39 +08:00
{
2015-01-17 22:13:08 +08:00
ImDrawCmd * current_cmd = commands . empty ( ) ? NULL : & commands . back ( ) ;
2015-01-31 23:24:55 +08:00
const ImTextureID texture_id = texture_id_stack . empty ( ) ? NULL : texture_id_stack . back ( ) ;
if ( ! current_cmd | | ( current_cmd - > vtx_count ! = 0 & & current_cmd - > texture_id ! = texture_id ) | | current_cmd - > user_callback ! = NULL )
2014-08-19 19:09:13 +08:00
{
2015-01-31 23:24:55 +08:00
AddDrawCmd ( ) ;
2014-08-19 19:09:13 +08:00
}
else
{
2015-01-31 23:24:55 +08:00
current_cmd - > texture_id = texture_id ;
2014-08-19 19:09:13 +08:00
}
2014-08-11 04:58:11 +08:00
}
2015-01-12 00:30:39 +08:00
void ImDrawList : : PushTextureID ( const ImTextureID & texture_id )
{
texture_id_stack . push_back ( texture_id ) ;
2015-01-31 23:24:55 +08:00
UpdateTextureID ( ) ;
2015-01-12 00:30:39 +08:00
}
void ImDrawList : : PopTextureID ( )
{
2015-01-29 21:07:20 +08:00
IM_ASSERT ( texture_id_stack . size ( ) > 0 ) ;
2015-01-12 00:30:39 +08:00
texture_id_stack . pop_back ( ) ;
2015-01-31 23:24:55 +08:00
UpdateTextureID ( ) ;
2015-01-12 00:30:39 +08:00
}
2014-08-13 18:34:08 +08:00
void ImDrawList : : ReserveVertices ( unsigned int vtx_count )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
if ( vtx_count > 0 )
{
ImDrawCmd & draw_cmd = commands . back ( ) ;
draw_cmd . vtx_count + = vtx_count ;
vtx_buffer . resize ( vtx_buffer . size ( ) + vtx_count ) ;
vtx_write = & vtx_buffer [ vtx_buffer . size ( ) - vtx_count ] ;
}
2014-08-11 04:58:11 +08:00
}
void ImDrawList : : AddVtx ( const ImVec2 & pos , ImU32 col )
{
2014-08-19 19:09:13 +08:00
vtx_write - > pos = pos ;
vtx_write - > col = col ;
2015-02-01 12:28:24 +08:00
vtx_write - > uv = GImGui - > FontTexUvWhitePixel ;
2014-08-19 19:09:13 +08:00
vtx_write + + ;
2014-08-11 04:58:11 +08:00
}
2015-01-12 00:30:39 +08:00
void ImDrawList : : AddVtxUV ( const ImVec2 & pos , ImU32 col , const ImVec2 & uv )
{
vtx_write - > pos = pos ;
vtx_write - > col = col ;
vtx_write - > uv = uv ;
vtx_write + + ;
}
2015-01-31 23:24:55 +08:00
// NB: memory should be reserved for 6 vertices by the caller.
2014-08-11 04:58:11 +08:00
void ImDrawList : : AddVtxLine ( const ImVec2 & a , const ImVec2 & b , ImU32 col )
{
2014-12-29 19:23:03 +08:00
const float length = sqrtf ( ImLengthSqr ( b - a ) ) ;
2015-01-18 01:17:18 +08:00
const ImVec2 hn = ( b - a ) * ( 0.50f / length ) ; // half normal
const ImVec2 hp0 = ImVec2 ( + hn . y , - hn . x ) ; // half perpendiculars + user offset
const ImVec2 hp1 = ImVec2 ( - hn . y , + hn . x ) ;
2014-08-11 04:58:11 +08:00
2014-11-24 18:02:39 +08:00
// Two triangles makes up one line. Using triangles allows us to reduce amount of draw calls.
2014-08-28 21:52:10 +08:00
AddVtx ( a + hp0 , col ) ;
AddVtx ( b + hp0 , col ) ;
AddVtx ( a + hp1 , col ) ;
AddVtx ( b + hp0 , col ) ;
AddVtx ( b + hp1 , col ) ;
AddVtx ( a + hp1 , col ) ;
2014-08-11 04:58:11 +08:00
}
void ImDrawList : : AddLine ( const ImVec2 & a , const ImVec2 & b , ImU32 col )
{
2014-08-19 19:09:13 +08:00
if ( ( col > > 24 ) = = 0 )
return ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
ReserveVertices ( 6 ) ;
AddVtxLine ( a , b , col ) ;
2014-08-11 04:58:11 +08:00
}
void ImDrawList : : AddArc ( const ImVec2 & center , float rad , ImU32 col , int a_min , int a_max , bool tris , const ImVec2 & third_point_offset )
{
2014-08-19 19:09:13 +08:00
if ( ( col > > 24 ) = = 0 )
return ;
static ImVec2 circle_vtx [ 12 ] ;
static bool circle_vtx_builds = false ;
if ( ! circle_vtx_builds )
{
for ( int i = 0 ; i < IM_ARRAYSIZE ( circle_vtx ) ; i + + )
{
const float a = ( ( float ) i / ( float ) IM_ARRAYSIZE ( circle_vtx ) ) * 2 * PI ;
2014-11-18 15:51:55 +08:00
circle_vtx [ i ] . x = cosf ( a + PI ) ;
circle_vtx [ i ] . y = sinf ( a + PI ) ;
2014-08-19 19:09:13 +08:00
}
circle_vtx_builds = true ;
}
if ( tris )
{
2014-08-20 17:40:31 +08:00
ReserveVertices ( ( unsigned int ) ( a_max - a_min ) * 3 ) ;
2014-08-19 19:09:13 +08:00
for ( int a = a_min ; a < a_max ; a + + )
{
AddVtx ( center + circle_vtx [ a % IM_ARRAYSIZE ( circle_vtx ) ] * rad , col ) ;
AddVtx ( center + circle_vtx [ ( a + 1 ) % IM_ARRAYSIZE ( circle_vtx ) ] * rad , col ) ;
AddVtx ( center + third_point_offset , col ) ;
}
}
else
{
2014-08-20 17:40:31 +08:00
ReserveVertices ( ( unsigned int ) ( a_max - a_min ) * 6 ) ;
2014-08-19 19:09:13 +08:00
for ( int a = a_min ; a < a_max ; a + + )
AddVtxLine ( center + circle_vtx [ a % IM_ARRAYSIZE ( circle_vtx ) ] * rad , center + circle_vtx [ ( a + 1 ) % IM_ARRAYSIZE ( circle_vtx ) ] * rad , col ) ;
}
2014-08-11 04:58:11 +08:00
}
void ImDrawList : : AddRect ( const ImVec2 & a , const ImVec2 & b , ImU32 col , float rounding , int rounding_corners )
{
2014-08-19 19:09:13 +08:00
if ( ( col > > 24 ) = = 0 )
return ;
float r = rounding ;
r = ImMin ( r , fabsf ( b . x - a . x ) * ( ( ( rounding_corners & ( 1 | 2 ) ) = = ( 1 | 2 ) ) | | ( ( rounding_corners & ( 4 | 8 ) ) = = ( 4 | 8 ) ) ? 0.5f : 1.0f ) ) ;
r = ImMin ( r , fabsf ( b . y - a . y ) * ( ( ( rounding_corners & ( 1 | 8 ) ) = = ( 1 | 8 ) ) | | ( ( rounding_corners & ( 2 | 4 ) ) = = ( 2 | 4 ) ) ? 0.5f : 1.0f ) ) ;
if ( r = = 0.0f | | rounding_corners = = 0 )
{
ReserveVertices ( 4 * 6 ) ;
AddVtxLine ( ImVec2 ( a . x , a . y ) , ImVec2 ( b . x , a . y ) , col ) ;
AddVtxLine ( ImVec2 ( b . x , a . y ) , ImVec2 ( b . x , b . y ) , col ) ;
AddVtxLine ( ImVec2 ( b . x , b . y ) , ImVec2 ( a . x , b . y ) , col ) ;
AddVtxLine ( ImVec2 ( a . x , b . y ) , ImVec2 ( a . x , a . y ) , col ) ;
}
else
{
ReserveVertices ( 4 * 6 ) ;
AddVtxLine ( ImVec2 ( a . x + ( ( rounding_corners & 1 ) ? r : 0 ) , a . y ) , ImVec2 ( b . x - ( ( rounding_corners & 2 ) ? r : 0 ) , a . y ) , col ) ;
AddVtxLine ( ImVec2 ( b . x , a . y + ( ( rounding_corners & 2 ) ? r : 0 ) ) , ImVec2 ( b . x , b . y - ( ( rounding_corners & 4 ) ? r : 0 ) ) , col ) ;
AddVtxLine ( ImVec2 ( b . x - ( ( rounding_corners & 4 ) ? r : 0 ) , b . y ) , ImVec2 ( a . x + ( ( rounding_corners & 8 ) ? r : 0 ) , b . y ) , col ) ;
AddVtxLine ( ImVec2 ( a . x , b . y - ( ( rounding_corners & 8 ) ? r : 0 ) ) , ImVec2 ( a . x , a . y + ( ( rounding_corners & 1 ) ? r : 0 ) ) , col ) ;
if ( rounding_corners & 1 ) AddArc ( ImVec2 ( a . x + r , a . y + r ) , r , col , 0 , 3 ) ;
if ( rounding_corners & 2 ) AddArc ( ImVec2 ( b . x - r , a . y + r ) , r , col , 3 , 6 ) ;
if ( rounding_corners & 4 ) AddArc ( ImVec2 ( b . x - r , b . y - r ) , r , col , 6 , 9 ) ;
if ( rounding_corners & 8 ) AddArc ( ImVec2 ( a . x + r , b . y - r ) , r , col , 9 , 12 ) ;
}
2014-08-11 04:58:11 +08:00
}
void ImDrawList : : AddRectFilled ( const ImVec2 & a , const ImVec2 & b , ImU32 col , float rounding , int rounding_corners )
{
2014-08-19 19:09:13 +08:00
if ( ( col > > 24 ) = = 0 )
return ;
float r = rounding ;
r = ImMin ( r , fabsf ( b . x - a . x ) * ( ( ( rounding_corners & ( 1 | 2 ) ) = = ( 1 | 2 ) ) | | ( ( rounding_corners & ( 4 | 8 ) ) = = ( 4 | 8 ) ) ? 0.5f : 1.0f ) ) ;
r = ImMin ( r , fabsf ( b . y - a . y ) * ( ( ( rounding_corners & ( 1 | 8 ) ) = = ( 1 | 8 ) ) | | ( ( rounding_corners & ( 2 | 4 ) ) = = ( 2 | 4 ) ) ? 0.5f : 1.0f ) ) ;
if ( r = = 0.0f | | rounding_corners = = 0 )
{
// Use triangle so we can merge more draw calls together (at the cost of extra vertices)
ReserveVertices ( 6 ) ;
AddVtx ( ImVec2 ( a . x , a . y ) , col ) ;
AddVtx ( ImVec2 ( b . x , a . y ) , col ) ;
AddVtx ( ImVec2 ( b . x , b . y ) , col ) ;
AddVtx ( ImVec2 ( a . x , a . y ) , col ) ;
AddVtx ( ImVec2 ( b . x , b . y ) , col ) ;
AddVtx ( ImVec2 ( a . x , b . y ) , col ) ;
}
else
{
ReserveVertices ( 6 + 6 * 2 ) ;
AddVtx ( ImVec2 ( a . x + r , a . y ) , col ) ;
AddVtx ( ImVec2 ( b . x - r , a . y ) , col ) ;
AddVtx ( ImVec2 ( b . x - r , b . y ) , col ) ;
AddVtx ( ImVec2 ( a . x + r , a . y ) , col ) ;
AddVtx ( ImVec2 ( b . x - r , b . y ) , col ) ;
AddVtx ( ImVec2 ( a . x + r , b . y ) , col ) ;
float top_y = ( rounding_corners & 1 ) ? a . y + r : a . y ;
float bot_y = ( rounding_corners & 8 ) ? b . y - r : b . y ;
AddVtx ( ImVec2 ( a . x , top_y ) , col ) ;
AddVtx ( ImVec2 ( a . x + r , top_y ) , col ) ;
AddVtx ( ImVec2 ( a . x + r , bot_y ) , col ) ;
AddVtx ( ImVec2 ( a . x , top_y ) , col ) ;
AddVtx ( ImVec2 ( a . x + r , bot_y ) , col ) ;
AddVtx ( ImVec2 ( a . x , bot_y ) , col ) ;
top_y = ( rounding_corners & 2 ) ? a . y + r : a . y ;
bot_y = ( rounding_corners & 4 ) ? b . y - r : b . y ;
AddVtx ( ImVec2 ( b . x - r , top_y ) , col ) ;
AddVtx ( ImVec2 ( b . x , top_y ) , col ) ;
AddVtx ( ImVec2 ( b . x , bot_y ) , col ) ;
AddVtx ( ImVec2 ( b . x - r , top_y ) , col ) ;
AddVtx ( ImVec2 ( b . x , bot_y ) , col ) ;
AddVtx ( ImVec2 ( b . x - r , bot_y ) , col ) ;
if ( rounding_corners & 1 ) AddArc ( ImVec2 ( a . x + r , a . y + r ) , r , col , 0 , 3 , true ) ;
if ( rounding_corners & 2 ) AddArc ( ImVec2 ( b . x - r , a . y + r ) , r , col , 3 , 6 , true ) ;
if ( rounding_corners & 4 ) AddArc ( ImVec2 ( b . x - r , b . y - r ) , r , col , 6 , 9 , true ) ;
if ( rounding_corners & 8 ) AddArc ( ImVec2 ( a . x + r , b . y - r ) , r , col , 9 , 12 , true ) ;
}
2014-08-11 04:58:11 +08:00
}
void ImDrawList : : AddTriangleFilled ( const ImVec2 & a , const ImVec2 & b , const ImVec2 & c , ImU32 col )
{
2014-08-19 19:09:13 +08:00
if ( ( col > > 24 ) = = 0 )
return ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
ReserveVertices ( 3 ) ;
2015-01-18 01:17:18 +08:00
AddVtx ( a , col ) ;
AddVtx ( b , col ) ;
AddVtx ( c , col ) ;
2014-08-11 04:58:11 +08:00
}
void ImDrawList : : AddCircle ( const ImVec2 & centre , float radius , ImU32 col , int num_segments )
{
2014-08-19 19:09:13 +08:00
if ( ( col > > 24 ) = = 0 )
return ;
2014-08-11 04:58:11 +08:00
2014-08-20 17:40:31 +08:00
ReserveVertices ( ( unsigned int ) num_segments * 6 ) ;
2014-08-19 19:09:13 +08:00
const float a_step = 2 * PI / ( float ) num_segments ;
float a0 = 0.0f ;
for ( int i = 0 ; i < num_segments ; i + + )
{
const float a1 = ( i + 1 ) = = num_segments ? 0.0f : a0 + a_step ;
2015-01-18 01:17:18 +08:00
AddVtxLine ( centre + ImVec2 ( cosf ( a0 ) , sinf ( a0 ) ) * radius , centre + ImVec2 ( cosf ( a1 ) , sinf ( a1 ) ) * radius , col ) ;
2014-08-19 19:09:13 +08:00
a0 = a1 ;
}
2014-08-11 04:58:11 +08:00
}
void ImDrawList : : AddCircleFilled ( const ImVec2 & centre , float radius , ImU32 col , int num_segments )
{
2014-08-19 19:09:13 +08:00
if ( ( col > > 24 ) = = 0 )
return ;
2014-08-11 04:58:11 +08:00
2014-08-20 17:40:31 +08:00
ReserveVertices ( ( unsigned int ) num_segments * 3 ) ;
2014-08-19 19:09:13 +08:00
const float a_step = 2 * PI / ( float ) num_segments ;
float a0 = 0.0f ;
for ( int i = 0 ; i < num_segments ; i + + )
{
const float a1 = ( i + 1 ) = = num_segments ? 0.0f : a0 + a_step ;
2015-01-18 01:17:18 +08:00
AddVtx ( centre + ImVec2 ( cosf ( a0 ) , sinf ( a0 ) ) * radius , col ) ;
AddVtx ( centre + ImVec2 ( cosf ( a1 ) , sinf ( a1 ) ) * radius , col ) ;
AddVtx ( centre , col ) ;
2014-08-19 19:09:13 +08:00
a0 = a1 ;
}
2014-08-11 04:58:11 +08:00
}
2015-02-09 00:32:51 +08:00
void ImDrawList : : AddText ( ImFont * font , float font_size , const ImVec2 & pos , ImU32 col , const char * text_begin , const char * text_end , float wrap_width , const ImVec2 * cpu_clip_max )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
if ( ( col > > 24 ) = = 0 )
return ;
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
if ( text_end = = NULL )
2015-01-12 00:46:39 +08:00
text_end = text_begin + strlen ( text_begin ) ;
2015-01-18 06:15:29 +08:00
IM_ASSERT ( font - > ContainerAtlas - > TexID = = texture_id_stack . back ( ) ) ; // Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font.
2014-08-11 04:58:11 +08:00
2014-08-19 19:09:13 +08:00
// reserve vertices for worse case
2014-08-20 17:40:31 +08:00
const unsigned int char_count = ( unsigned int ) ( text_end - text_begin ) ;
const unsigned int vtx_count_max = char_count * 6 ;
2014-08-19 19:09:13 +08:00
const size_t vtx_begin = vtx_buffer . size ( ) ;
ReserveVertices ( vtx_count_max ) ;
2014-08-11 04:58:11 +08:00
2015-02-09 00:32:51 +08:00
font - > RenderText ( font_size , pos , col , clip_rect_stack . back ( ) , text_begin , text_end , vtx_write , wrap_width , cpu_clip_max ) ;
2014-08-11 04:58:11 +08:00
2014-08-20 17:40:31 +08:00
// give back unused vertices
vtx_buffer . resize ( ( size_t ) ( vtx_write - & vtx_buffer . front ( ) ) ) ;
const size_t vtx_count = vtx_buffer . size ( ) - vtx_begin ;
commands . back ( ) . vtx_count - = ( unsigned int ) ( vtx_count_max - vtx_count ) ;
2014-08-19 19:09:13 +08:00
vtx_write - = ( vtx_count_max - vtx_count ) ;
2014-08-11 04:58:11 +08:00
}
2015-01-12 00:30:39 +08:00
void ImDrawList : : AddImage ( ImTextureID user_texture_id , const ImVec2 & a , const ImVec2 & b , const ImVec2 & uv0 , const ImVec2 & uv1 , ImU32 col )
{
if ( ( col > > 24 ) = = 0 )
return ;
2015-02-01 02:55:05 +08:00
const bool push_texture_id = texture_id_stack . empty ( ) | | user_texture_id ! = texture_id_stack . back ( ) ;
2015-01-12 00:30:39 +08:00
if ( push_texture_id )
PushTextureID ( user_texture_id ) ;
ReserveVertices ( 6 ) ;
AddVtxUV ( ImVec2 ( a . x , a . y ) , col , uv0 ) ;
AddVtxUV ( ImVec2 ( b . x , a . y ) , col , ImVec2 ( uv1 . x , uv0 . y ) ) ;
AddVtxUV ( ImVec2 ( b . x , b . y ) , col , uv1 ) ;
AddVtxUV ( ImVec2 ( a . x , a . y ) , col , ImVec2 ( uv0 . x , uv0 . y ) ) ;
AddVtxUV ( ImVec2 ( b . x , b . y ) , col , uv1 ) ;
AddVtxUV ( ImVec2 ( a . x , b . y ) , col , ImVec2 ( uv0 . x , uv1 . y ) ) ;
if ( push_texture_id )
PopTextureID ( ) ;
}
2014-08-11 04:58:11 +08:00
//-----------------------------------------------------------------------------
2015-01-18 06:15:29 +08:00
// ImFontAtlias
2014-08-11 04:58:11 +08:00
//-----------------------------------------------------------------------------
2015-01-18 06:15:29 +08:00
struct ImFontAtlas : : ImFontAtlasData
2014-08-11 04:58:11 +08:00
{
2015-01-18 06:15:29 +08:00
// Input
2015-01-18 20:12:16 +08:00
ImFont * OutFont ; // Load into this font
void * TTFData ; // TTF data, we own the memory
size_t TTFDataSize ; // TTF data size, in bytes
float SizePixels ; // Desired output size, in pixels
const ImWchar * GlyphRanges ; // List of Unicode range (2 value per range, values are inclusive, zero-terminated list)
int FontNo ; // Index of font within .TTF file (0)
2015-01-18 06:15:29 +08:00
// Temporary Build Data
2015-01-18 20:12:16 +08:00
stbtt_fontinfo FontInfo ;
stbrp_rect * Rects ;
stbtt_pack_range * Ranges ;
int RangesCount ;
2015-01-18 06:15:29 +08:00
} ;
2014-11-29 08:02:46 +08:00
2015-01-18 06:15:29 +08:00
ImFontAtlas : : ImFontAtlas ( )
{
TexID = NULL ;
2015-01-12 05:06:57 +08:00
TexPixelsAlpha8 = NULL ;
TexPixelsRGBA32 = NULL ;
2015-01-18 06:15:29 +08:00
TexWidth = TexHeight = 0 ;
TexExtraDataPos = TexUvWhitePixel = ImVec2 ( 0 , 0 ) ;
2015-01-09 07:35:01 +08:00
}
2015-01-18 06:15:29 +08:00
ImFontAtlas : : ~ ImFontAtlas ( )
2015-01-09 07:35:01 +08:00
{
2015-01-18 18:46:49 +08:00
Clear ( ) ;
2015-01-18 06:15:29 +08:00
}
void ImFontAtlas : : ClearInputData ( )
{
for ( size_t i = 0 ; i < InputData . size ( ) ; i + + )
{
if ( InputData [ i ] - > TTFData )
ImGui : : MemFree ( InputData [ i ] - > TTFData ) ;
ImGui : : MemFree ( InputData [ i ] ) ;
}
InputData . clear ( ) ;
}
void ImFontAtlas : : ClearTexData ( )
{
if ( TexPixelsAlpha8 )
ImGui : : MemFree ( TexPixelsAlpha8 ) ;
if ( TexPixelsRGBA32 )
ImGui : : MemFree ( TexPixelsRGBA32 ) ;
TexPixelsAlpha8 = NULL ;
TexPixelsRGBA32 = NULL ;
2014-08-11 04:58:11 +08:00
}
2015-01-18 18:46:49 +08:00
void ImFontAtlas : : Clear ( )
2015-01-12 05:06:57 +08:00
{
2015-01-18 18:46:49 +08:00
ClearInputData ( ) ;
ClearTexData ( ) ;
2015-01-18 06:15:29 +08:00
for ( size_t i = 0 ; i < Fonts . size ( ) ; i + + )
{
Fonts [ i ] - > ~ ImFont ( ) ;
ImGui : : MemFree ( Fonts [ i ] ) ;
}
Fonts . clear ( ) ;
}
2015-01-18 23:12:41 +08:00
void ImGui : : GetDefaultFontData ( const void * * fnt_data , unsigned int * fnt_size , const void * * png_data , unsigned int * png_size )
{
printf ( " GetDefaultFontData() is obsoleted in ImGui 1.30. \n " ) ;
printf ( " Please use ImGui::GetIO().Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() functions to retrieve uncompressed texture data. \n " ) ;
if ( fnt_data ) * fnt_data = NULL ;
if ( fnt_size ) * fnt_size = 0 ;
if ( png_data ) * png_data = NULL ;
if ( png_size ) * png_size = 0 ;
IM_ASSERT ( false ) ;
}
2015-01-18 06:15:29 +08:00
void ImFontAtlas : : GetTexDataAsAlpha8 ( unsigned char * * out_pixels , int * out_width , int * out_height , int * out_bytes_per_pixel )
{
// Lazily build
if ( TexPixelsAlpha8 = = NULL )
{
if ( InputData . empty ( ) )
AddFontDefault ( ) ;
Build ( ) ;
}
2015-01-12 05:06:57 +08:00
* out_pixels = TexPixelsAlpha8 ;
if ( out_width ) * out_width = TexWidth ;
if ( out_height ) * out_height = TexHeight ;
if ( out_bytes_per_pixel ) * out_bytes_per_pixel = 1 ;
}
2015-01-18 06:15:29 +08:00
void ImFontAtlas : : GetTexDataAsRGBA32 ( unsigned char * * out_pixels , int * out_width , int * out_height , int * out_bytes_per_pixel )
2015-01-12 05:06:57 +08:00
{
// Lazily convert to RGBA32 format
// Although it is likely to be the most commonly used format, our font rendering is 8 bpp
if ( ! TexPixelsRGBA32 )
{
unsigned char * pixels ;
2015-01-18 06:15:29 +08:00
GetTexDataAsAlpha8 ( & pixels , NULL , NULL ) ;
2015-01-18 07:21:06 +08:00
TexPixelsRGBA32 = ( unsigned int * ) ImGui : : MemAlloc ( ( size_t ) ( TexWidth * TexHeight * 4 ) ) ;
2015-01-12 05:06:57 +08:00
const unsigned char * src = pixels ;
unsigned int * dst = TexPixelsRGBA32 ;
for ( int n = TexWidth * TexHeight ; n > 0 ; n - - )
2015-01-18 07:21:06 +08:00
* dst + + = ( ( unsigned int ) ( * src + + ) < < 24 ) | 0x00FFFFFF ;
2015-01-12 05:06:57 +08:00
}
* out_pixels = ( unsigned char * ) TexPixelsRGBA32 ;
if ( out_width ) * out_width = TexWidth ;
if ( out_height ) * out_height = TexHeight ;
if ( out_bytes_per_pixel ) * out_bytes_per_pixel = 4 ;
}
2015-01-18 06:15:29 +08:00
static void GetDefaultCompressedFontDataTTF ( const void * * ttf_compressed_data , unsigned int * ttf_compressed_size ) ;
static unsigned int stb_decompress_length ( unsigned char * input ) ;
static unsigned int stb_decompress ( unsigned char * output , unsigned char * i , unsigned int length ) ;
// Load embedded ProggyClean.ttf at size 13
ImFont * ImFontAtlas : : AddFontDefault ( )
2014-08-11 04:58:11 +08:00
{
2015-01-18 06:15:29 +08:00
// Get compressed data
unsigned int ttf_compressed_size ;
const void * ttf_compressed ;
GetDefaultCompressedFontDataTTF ( & ttf_compressed , & ttf_compressed_size ) ;
// Decompress
const size_t buf_decompressed_size = stb_decompress_length ( ( unsigned char * ) ttf_compressed ) ;
unsigned char * buf_decompressed = ( unsigned char * ) ImGui : : MemAlloc ( buf_decompressed_size ) ;
stb_decompress ( buf_decompressed , ( unsigned char * ) ttf_compressed , ttf_compressed_size ) ;
// Add
2015-01-18 18:46:49 +08:00
ImFont * font = AddFontFromMemoryTTF ( buf_decompressed , buf_decompressed_size , 13.0f , GetGlyphRangesDefault ( ) , 0 ) ;
2015-01-18 06:15:29 +08:00
font - > DisplayOffset . y + = 1 ;
return font ;
2015-01-12 05:06:57 +08:00
}
2015-01-09 07:35:01 +08:00
2015-01-18 06:15:29 +08:00
ImFont * ImFontAtlas : : AddFontFromFileTTF ( const char * filename , float size_pixels , const ImWchar * glyph_ranges , int font_no )
2015-01-12 05:06:57 +08:00
{
2015-01-18 06:15:29 +08:00
void * data = NULL ;
size_t data_size = 0 ;
if ( ! ImLoadFileToMemory ( filename , " rb " , ( void * * ) & data , & data_size ) )
2015-01-18 19:36:23 +08:00
{
IM_ASSERT ( 0 ) ; // Could not load file.
2015-01-18 06:15:29 +08:00
return NULL ;
2015-01-18 19:36:23 +08:00
}
2015-01-18 06:15:29 +08:00
// Add
ImFont * font = AddFontFromMemoryTTF ( data , data_size , size_pixels , glyph_ranges , font_no ) ;
return font ;
}
// NB: ownership of 'data' is given to ImFontAtlas which will clear it.
ImFont * ImFontAtlas : : AddFontFromMemoryTTF ( void * in_ttf_data , size_t in_ttf_data_size , float size_pixels , const ImWchar * glyph_ranges , int font_no )
{
// Create new font
ImFont * font = ( ImFont * ) ImGui : : MemAlloc ( sizeof ( ImFont ) ) ;
new ( font ) ImFont ( ) ;
Fonts . push_back ( font ) ;
// Add to build list
ImFontAtlasData * data = ( ImFontAtlasData * ) ImGui : : MemAlloc ( sizeof ( ImFontAtlasData ) ) ;
memset ( data , 0 , sizeof ( ImFontAtlasData ) ) ;
data - > OutFont = font ;
data - > TTFData = in_ttf_data ;
data - > TTFDataSize = in_ttf_data_size ;
data - > SizePixels = size_pixels ;
data - > GlyphRanges = glyph_ranges ;
2015-01-18 07:21:06 +08:00
data - > FontNo = font_no ;
2015-01-18 06:15:29 +08:00
InputData . push_back ( data ) ;
// Invalidate texture
ClearTexData ( ) ;
return font ;
}
bool ImFontAtlas : : Build ( )
{
IM_ASSERT ( InputData . size ( ) > 0 ) ;
2015-01-12 00:30:39 +08:00
TexID = NULL ;
TexWidth = TexHeight = 0 ;
TexExtraDataPos = TexUvWhitePixel = ImVec2 ( 0 , 0 ) ;
2015-01-18 06:15:29 +08:00
ClearTexData ( ) ;
// Initialize font information early (so we can error without any cleanup) + count glyphs
int total_glyph_count = 0 ;
2015-01-18 20:12:16 +08:00
int total_glyph_range_count = 0 ;
2015-01-18 06:15:29 +08:00
for ( size_t input_i = 0 ; input_i < InputData . size ( ) ; input_i + + )
{
ImFontAtlasData & data = * InputData [ input_i ] ;
2015-01-18 18:46:49 +08:00
IM_ASSERT ( data . OutFont & & ! data . OutFont - > IsLoaded ( ) ) ;
2015-01-18 06:15:29 +08:00
const int font_offset = stbtt_GetFontOffsetForIndex ( ( unsigned char * ) data . TTFData , data . FontNo ) ;
IM_ASSERT ( font_offset > = 0 ) ;
if ( ! stbtt_InitFont ( & data . FontInfo , ( unsigned char * ) data . TTFData , font_offset ) )
return false ;
2015-01-18 19:36:23 +08:00
if ( ! data . GlyphRanges )
data . GlyphRanges = GetGlyphRangesDefault ( ) ;
for ( const ImWchar * in_range = data . GlyphRanges ; in_range [ 0 ] & & in_range [ 1 ] ; in_range + = 2 )
2015-01-18 20:12:16 +08:00
{
2015-01-18 06:15:29 +08:00
total_glyph_count + = ( in_range [ 1 ] - in_range [ 0 ] ) + 1 ;
2015-01-18 20:12:16 +08:00
total_glyph_range_count + + ;
}
2015-01-18 06:15:29 +08:00
}
// Start packing
2015-01-18 19:55:58 +08:00
TexWidth = ( total_glyph_count > 1000 ) ? 1024 : 512 ; // Width doesn't actually matters.
2015-01-18 06:15:29 +08:00
TexHeight = 0 ;
const int max_tex_height = 1024 * 32 ;
stbtt_pack_context spc ;
int ret = stbtt_PackBegin ( & spc , NULL , TexWidth , max_tex_height , 0 , 1 , NULL ) ;
IM_ASSERT ( ret ) ;
stbtt_PackSetOversampling ( & spc , 1 , 1 ) ;
// Pack our extra data rectangle first, so it will be on the upper-left corner of our texture (UV will have small values).
stbrp_rect extra_rect ;
2015-02-02 16:51:45 +08:00
extra_rect . w = ( stbrp_coord ) TEX_ATLAS_SIZE . x ;
extra_rect . h = ( stbrp_coord ) TEX_ATLAS_SIZE . y ;
2015-01-18 06:15:29 +08:00
stbrp_pack_rects ( ( stbrp_context * ) spc . pack_info , & extra_rect , 1 ) ;
TexExtraDataPos = ImVec2 ( extra_rect . x , extra_rect . y ) ;
2015-01-18 20:12:16 +08:00
// Allocate packing character data and flag packed characters buffer as non-packed (x0=y0=x1=y1=0)
int buf_packedchars_n = 0 , buf_rects_n = 0 , buf_ranges_n = 0 ;
stbtt_packedchar * buf_packedchars = ( stbtt_packedchar * ) ImGui : : MemAlloc ( total_glyph_count * sizeof ( stbtt_packedchar ) ) ;
stbrp_rect * buf_rects = ( stbrp_rect * ) ImGui : : MemAlloc ( total_glyph_count * sizeof ( stbrp_rect ) ) ;
stbtt_pack_range * buf_ranges = ( stbtt_pack_range * ) ImGui : : MemAlloc ( total_glyph_range_count * sizeof ( stbtt_pack_range ) ) ;
memset ( buf_packedchars , 0 , total_glyph_count * sizeof ( stbtt_packedchar ) ) ;
2015-01-30 00:44:46 +08:00
memset ( buf_rects , 0 , total_glyph_count * sizeof ( stbrp_rect ) ) ; // Unnessary but let's clear this for the sake of sanity.
2015-01-18 20:12:16 +08:00
memset ( buf_ranges , 0 , total_glyph_range_count * sizeof ( stbtt_pack_range ) ) ;
2015-01-18 19:55:58 +08:00
2015-01-18 06:15:29 +08:00
// First pass: pack all glyphs (no rendering at this point, we are working with glyph sizes only)
int tex_height = extra_rect . y + extra_rect . h ;
for ( size_t input_i = 0 ; input_i < InputData . size ( ) ; input_i + + )
{
ImFontAtlasData & data = * InputData [ input_i ] ;
// Setup ranges
int glyph_count = 0 ;
2015-01-20 08:01:25 +08:00
int glyph_ranges_count = 0 ;
2015-01-18 06:15:29 +08:00
for ( const ImWchar * in_range = data . GlyphRanges ; in_range [ 0 ] & & in_range [ 1 ] ; in_range + = 2 )
{
glyph_count + = ( in_range [ 1 ] - in_range [ 0 ] ) + 1 ;
glyph_ranges_count + + ;
}
2015-01-18 20:12:16 +08:00
data . Ranges = buf_ranges + buf_ranges_n ;
data . RangesCount = glyph_ranges_count ;
buf_ranges_n + = glyph_ranges_count ;
2015-01-20 08:01:25 +08:00
for ( int i = 0 ; i < glyph_ranges_count ; i + + )
2015-01-18 06:15:29 +08:00
{
2015-01-18 20:12:16 +08:00
const ImWchar * in_range = & data . GlyphRanges [ i * 2 ] ;
2015-01-18 06:15:29 +08:00
stbtt_pack_range & range = data . Ranges [ i ] ;
range . font_size = data . SizePixels ;
range . first_unicode_char_in_range = in_range [ 0 ] ;
range . num_chars_in_range = ( in_range [ 1 ] - in_range [ 0 ] ) + 1 ;
2015-01-18 20:12:16 +08:00
range . chardata_for_range = buf_packedchars + buf_packedchars_n ;
buf_packedchars_n + = range . num_chars_in_range ;
2015-01-18 06:15:29 +08:00
}
// Pack
2015-01-18 20:12:16 +08:00
data . Rects = buf_rects + buf_rects_n ;
buf_rects_n + = glyph_count ;
const int n = stbtt_PackFontRangesGatherRects ( & spc , & data . FontInfo , data . Ranges , data . RangesCount , data . Rects ) ;
2015-01-18 06:15:29 +08:00
stbrp_pack_rects ( ( stbrp_context * ) spc . pack_info , data . Rects , n ) ;
// Extend texture height
for ( int i = 0 ; i < n ; i + + )
if ( data . Rects [ i ] . was_packed )
tex_height = ImMax ( tex_height , data . Rects [ i ] . y + data . Rects [ i ] . h ) ;
}
2015-01-18 20:12:16 +08:00
IM_ASSERT ( buf_rects_n = = total_glyph_count ) ;
IM_ASSERT ( buf_packedchars_n = = total_glyph_count ) ;
IM_ASSERT ( buf_ranges_n = = total_glyph_range_count ) ;
2015-01-18 06:15:29 +08:00
// Create texture
TexHeight = ImUpperPowerOfTwo ( tex_height ) ;
2015-01-18 20:12:16 +08:00
TexPixelsAlpha8 = ( unsigned char * ) ImGui : : MemAlloc ( TexWidth * TexHeight ) ;
2015-01-18 06:15:29 +08:00
memset ( TexPixelsAlpha8 , 0 , TexWidth * TexHeight ) ;
spc . pixels = TexPixelsAlpha8 ;
spc . height = TexHeight ;
// Second pass: render characters
for ( size_t input_i = 0 ; input_i < InputData . size ( ) ; input_i + + )
{
ImFontAtlasData & data = * InputData [ input_i ] ;
2015-01-18 20:12:16 +08:00
ret = stbtt_PackFontRangesRenderIntoRects ( & spc , & data . FontInfo , data . Ranges , data . RangesCount , data . Rects ) ;
2015-01-18 06:15:29 +08:00
data . Rects = NULL ;
}
// End packing
stbtt_PackEnd ( & spc ) ;
2015-01-18 20:12:16 +08:00
ImGui : : MemFree ( buf_rects ) ;
buf_rects = NULL ;
2015-01-18 06:15:29 +08:00
// Third pass: setup ImFont and glyphs for runtime
for ( size_t input_i = 0 ; input_i < InputData . size ( ) ; input_i + + )
{
ImFontAtlasData & data = * InputData [ input_i ] ;
data . OutFont - > ContainerAtlas = this ;
data . OutFont - > FontSize = data . SizePixels ;
const float font_scale = stbtt_ScaleForPixelHeight ( & data . FontInfo , data . SizePixels ) ;
int font_ascent , font_descent , font_line_gap ;
stbtt_GetFontVMetrics ( & data . FontInfo , & font_ascent , & font_descent , & font_line_gap ) ;
2015-01-12 00:30:39 +08:00
2015-01-18 06:15:29 +08:00
const float uv_scale_x = 1.0f / TexWidth ;
const float uv_scale_y = 1.0f / TexHeight ;
const int character_spacing_x = 1 ;
2015-01-18 20:12:16 +08:00
for ( int i = 0 ; i < data . RangesCount ; i + + )
2015-01-18 06:15:29 +08:00
{
stbtt_pack_range & range = data . Ranges [ i ] ;
for ( int char_idx = 0 ; char_idx < range . num_chars_in_range ; char_idx + = 1 )
{
const int codepoint = range . first_unicode_char_in_range + char_idx ;
const stbtt_packedchar & pc = range . chardata_for_range [ char_idx ] ;
if ( ! pc . x0 & & ! pc . x1 & & ! pc . y0 & & ! pc . y1 )
continue ;
data . OutFont - > Glyphs . resize ( data . OutFont - > Glyphs . size ( ) + 1 ) ;
ImFont : : Glyph & glyph = data . OutFont - > Glyphs . back ( ) ;
glyph . Codepoint = ( ImWchar ) codepoint ;
2015-01-18 07:21:06 +08:00
glyph . Width = ( signed short ) pc . x1 - pc . x0 + 1 ;
glyph . Height = ( signed short ) pc . y1 - pc . y0 + 1 ;
2015-01-18 06:15:29 +08:00
glyph . XOffset = ( signed short ) ( pc . xoff ) ;
2015-01-18 07:21:06 +08:00
glyph . YOffset = ( signed short ) ( pc . yoff + ( int ) ( font_ascent * font_scale ) ) ;
2015-01-18 06:15:29 +08:00
glyph . XAdvance = ( signed short ) ( pc . xadvance + character_spacing_x ) ; // Bake spacing into XAdvance
glyph . U0 = ( ( float ) pc . x0 - 0.5f ) * uv_scale_x ;
glyph . V0 = ( ( float ) pc . y0 - 0.5f ) * uv_scale_y ;
glyph . U1 = ( ( float ) pc . x0 - 0.5f + glyph . Width ) * uv_scale_x ;
glyph . V1 = ( ( float ) pc . y0 - 0.5f + glyph . Height ) * uv_scale_y ;
}
}
data . OutFont - > BuildLookupTable ( ) ;
}
2015-01-18 19:55:58 +08:00
// Cleanup temporaries
2015-01-18 20:12:16 +08:00
ImGui : : MemFree ( buf_packedchars ) ;
ImGui : : MemFree ( buf_ranges ) ;
buf_packedchars = NULL ;
buf_ranges = NULL ;
2015-01-18 19:55:58 +08:00
ClearInputData ( ) ;
2015-02-01 02:55:05 +08:00
// Render into our custom data block
RenderCustomTexData ( ) ;
return true ;
}
void ImFontAtlas : : RenderCustomTexData ( )
{
IM_ASSERT ( TexExtraDataPos . x = = 0.0f & & TexExtraDataPos . y = = 0.0f ) ;
2015-01-18 06:15:29 +08:00
// Draw white pixel into texture and make UV points to it
TexPixelsAlpha8 [ 0 ] = TexPixelsAlpha8 [ 1 ] = TexPixelsAlpha8 [ TexWidth + 0 ] = TexPixelsAlpha8 [ TexWidth + 1 ] = 0xFF ;
TexUvWhitePixel = ImVec2 ( ( TexExtraDataPos . x + 0.5f ) / TexWidth , ( TexExtraDataPos . y + 0.5f ) / TexHeight ) ;
2015-02-01 02:55:05 +08:00
// Draw a mouse cursor into texture
// Because our font uses an alpha texture, we have to spread the cursor in 2 parts (black/white) which will be rendered separately.
const char cursor_pixels [ ] =
{
" X "
" XX "
" X.X "
" X..X "
" X...X "
" X....X "
" X.....X "
" X......X "
" X.......X "
" X........X "
" X.........X "
" X..........X "
" X......XXXXX "
" X...X..X "
" X..X X..X "
" X.X X..X "
" XX X..X "
" X..X "
" XX "
} ;
IM_ASSERT ( sizeof ( cursor_pixels ) - 1 = = ( int ) TEX_ATLAS_SIZE_MOUSE_CURSOR . x * ( int ) TEX_ATLAS_SIZE_MOUSE_CURSOR . y ) ;
for ( int y = 0 , n = 0 ; y < 19 ; y + + )
for ( int x = 0 ; x < 12 ; x + + , n + + )
{
TexPixelsAlpha8 [ ( ( int ) TEX_ATLAS_POS_MOUSE_CURSOR_BLACK . x + x ) + ( ( int ) TEX_ATLAS_POS_MOUSE_CURSOR_BLACK . y + y ) * TexWidth ] = ( cursor_pixels [ n ] = = ' X ' ) ? 0xFF : 0x00 ;
TexPixelsAlpha8 [ ( ( int ) TEX_ATLAS_POS_MOUSE_CURSOR_WHITE . x + x ) + ( ( int ) TEX_ATLAS_POS_MOUSE_CURSOR_WHITE . y + y ) * TexWidth ] = ( cursor_pixels [ n ] = = ' . ' ) ? 0xFF : 0x00 ;
}
2015-01-18 06:15:29 +08:00
}
//-----------------------------------------------------------------------------
// ImFont
//-----------------------------------------------------------------------------
ImFont : : ImFont ( )
{
Scale = 1.0f ;
FallbackChar = ( ImWchar ) ' ? ' ;
Clear ( ) ;
}
void ImFont : : Clear ( )
{
FontSize = 0.0f ;
DisplayOffset = ImVec2 ( - 0.5f , 0.5f ) ;
ContainerAtlas = NULL ;
2015-01-09 07:35:01 +08:00
Glyphs . clear ( ) ;
2015-02-11 20:10:45 +08:00
IndexXAdvance . clear ( ) ;
2014-08-19 19:09:13 +08:00
IndexLookup . clear ( ) ;
2015-01-07 22:55:35 +08:00
FallbackGlyph = NULL ;
2015-01-09 07:35:01 +08:00
}
// Retrieve list of range (2 int per range, values are inclusive)
2015-01-18 06:15:29 +08:00
const ImWchar * ImFontAtlas : : GetGlyphRangesDefault ( )
2015-01-09 07:35:01 +08:00
{
static const ImWchar ranges [ ] =
{
0x0020 , 0x00FF , // Basic Latin + Latin Supplement
0 ,
} ;
return & ranges [ 0 ] ;
}
2015-01-18 06:15:29 +08:00
const ImWchar * ImFontAtlas : : GetGlyphRangesChinese ( )
2015-01-09 07:35:01 +08:00
{
static const ImWchar ranges [ ] =
{
0x0020 , 0x00FF , // Basic Latin + Latin Supplement
0x3040 , 0x309F , // Hiragana, Katakana
0xFF00 , 0xFFEF , // Half-width characters
0x4e00 , 0x9FAF , // CJK Ideograms
0 ,
} ;
return & ranges [ 0 ] ;
}
2015-01-18 06:15:29 +08:00
const ImWchar * ImFontAtlas : : GetGlyphRangesJapanese ( )
2015-01-09 07:35:01 +08:00
{
// Store the 1946 ideograms code points as successive offsets from the initial unicode codepoint 0x4E00. Each offset has an implicit +1.
// This encoding helps us reduce the source code size.
static const short offsets_from_0x4E00 [ ] =
{
- 1 , 0 , 1 , 3 , 0 , 0 , 0 , 0 , 1 , 0 , 5 , 1 , 1 , 0 , 7 , 4 , 6 , 10 , 0 , 1 , 9 , 9 , 7 , 1 , 3 , 19 , 1 , 10 , 7 , 1 , 0 , 1 , 0 , 5 , 1 , 0 , 6 , 4 , 2 , 6 , 0 , 0 , 12 , 6 , 8 , 0 , 3 , 5 , 0 , 1 , 0 , 9 , 0 , 0 , 8 , 1 , 1 , 3 , 4 , 5 , 13 , 0 , 0 , 8 , 2 , 17 ,
4 , 3 , 1 , 1 , 9 , 6 , 0 , 0 , 0 , 2 , 1 , 3 , 2 , 22 , 1 , 9 , 11 , 1 , 13 , 1 , 3 , 12 , 0 , 5 , 9 , 2 , 0 , 6 , 12 , 5 , 3 , 12 , 4 , 1 , 2 , 16 , 1 , 1 , 4 , 6 , 5 , 3 , 0 , 6 , 13 , 15 , 5 , 12 , 8 , 14 , 0 , 0 , 6 , 15 , 3 , 6 , 0 , 18 , 8 , 1 , 6 , 14 , 1 ,
5 , 4 , 12 , 24 , 3 , 13 , 12 , 10 , 24 , 0 , 0 , 0 , 1 , 0 , 1 , 1 , 2 , 9 , 10 , 2 , 2 , 0 , 0 , 3 , 3 , 1 , 0 , 3 , 8 , 0 , 3 , 2 , 4 , 4 , 1 , 6 , 11 , 10 , 14 , 6 , 15 , 3 , 4 , 15 , 1 , 0 , 0 , 5 , 2 , 2 , 0 , 0 , 1 , 6 , 5 , 5 , 6 , 0 , 3 , 6 , 5 , 0 , 0 , 1 , 0 ,
11 , 2 , 2 , 8 , 4 , 7 , 0 , 10 , 0 , 1 , 2 , 17 , 19 , 3 , 0 , 2 , 5 , 0 , 6 , 2 , 4 , 4 , 6 , 1 , 1 , 11 , 2 , 0 , 3 , 1 , 2 , 1 , 2 , 10 , 7 , 6 , 3 , 16 , 0 , 8 , 24 , 0 , 0 , 3 , 1 , 1 , 3 , 0 , 1 , 6 , 0 , 0 , 0 , 2 , 0 , 1 , 5 , 15 , 0 , 1 , 0 , 0 , 2 , 11 , 19 ,
1 , 4 , 19 , 7 , 6 , 5 , 1 , 0 , 0 , 0 , 0 , 5 , 1 , 0 , 1 , 9 , 0 , 0 , 5 , 0 , 2 , 0 , 1 , 0 , 3 , 0 , 11 , 3 , 0 , 2 , 0 , 0 , 0 , 0 , 0 , 9 , 3 , 6 , 4 , 12 , 0 , 14 , 0 , 0 , 29 , 10 , 8 , 0 , 14 , 37 , 13 , 0 , 31 , 16 , 19 , 0 , 8 , 30 , 1 , 20 , 8 , 3 , 48 ,
21 , 1 , 0 , 12 , 0 , 10 , 44 , 34 , 42 , 54 , 11 , 18 , 82 , 0 , 2 , 1 , 2 , 12 , 1 , 0 , 6 , 2 , 17 , 2 , 12 , 7 , 0 , 7 , 17 , 4 , 2 , 6 , 24 , 23 , 8 , 23 , 39 , 2 , 16 , 23 , 1 , 0 , 5 , 1 , 2 , 15 , 14 , 5 , 6 , 2 , 11 , 0 , 8 , 6 , 2 , 2 , 2 , 14 ,
20 , 4 , 15 , 3 , 4 , 11 , 10 , 10 , 2 , 5 , 2 , 1 , 30 , 2 , 1 , 0 , 0 , 22 , 5 , 5 , 0 , 3 , 1 , 5 , 4 , 1 , 0 , 0 , 2 , 2 , 21 , 1 , 5 , 1 , 2 , 16 , 2 , 1 , 3 , 4 , 0 , 8 , 4 , 0 , 0 , 5 , 14 , 11 , 2 , 16 , 1 , 13 , 1 , 7 , 0 , 22 , 15 , 3 , 1 , 22 , 7 , 14 ,
22 , 19 , 11 , 24 , 18 , 46 , 10 , 20 , 64 , 45 , 3 , 2 , 0 , 4 , 5 , 0 , 1 , 4 , 25 , 1 , 0 , 0 , 2 , 10 , 0 , 0 , 0 , 1 , 0 , 1 , 2 , 0 , 0 , 9 , 1 , 2 , 0 , 0 , 0 , 2 , 5 , 2 , 1 , 1 , 5 , 5 , 8 , 1 , 1 , 1 , 5 , 1 , 4 , 9 , 1 , 3 , 0 , 1 , 0 , 1 , 1 , 2 , 0 , 0 ,
2 , 0 , 1 , 8 , 22 , 8 , 1 , 0 , 0 , 0 , 0 , 4 , 2 , 1 , 0 , 9 , 8 , 5 , 0 , 9 , 1 , 30 , 24 , 2 , 6 , 4 , 39 , 0 , 14 , 5 , 16 , 6 , 26 , 179 , 0 , 2 , 1 , 1 , 0 , 0 , 0 , 5 , 2 , 9 , 6 , 0 , 2 , 5 , 16 , 7 , 5 , 1 , 1 , 0 , 2 , 4 , 4 , 7 , 15 , 13 , 14 , 0 , 0 ,
3 , 0 , 1 , 0 , 0 , 0 , 2 , 1 , 6 , 4 , 5 , 1 , 4 , 9 , 0 , 3 , 1 , 8 , 0 , 0 , 10 , 5 , 0 , 43 , 0 , 2 , 6 , 8 , 4 , 0 , 2 , 0 , 0 , 9 , 6 , 0 , 9 , 3 , 1 , 6 , 20 , 14 , 6 , 1 , 4 , 0 , 7 , 2 , 3 , 0 , 2 , 0 , 5 , 0 , 3 , 1 , 0 , 3 , 9 , 7 , 0 , 3 , 4 , 0 , 4 , 9 , 1 , 6 , 0 ,
9 , 0 , 0 , 2 , 3 , 10 , 9 , 28 , 3 , 6 , 2 , 4 , 1 , 2 , 32 , 4 , 1 , 18 , 2 , 0 , 3 , 1 , 5 , 30 , 10 , 0 , 2 , 2 , 2 , 0 , 7 , 9 , 8 , 11 , 10 , 11 , 7 , 2 , 13 , 7 , 5 , 10 , 0 , 3 , 40 , 2 , 0 , 1 , 6 , 12 , 0 , 4 , 5 , 1 , 5 , 11 , 11 , 21 , 4 , 8 , 3 , 7 ,
8 , 8 , 33 , 5 , 23 , 0 , 0 , 19 , 8 , 8 , 2 , 3 , 0 , 6 , 1 , 1 , 1 , 5 , 1 , 27 , 4 , 2 , 5 , 0 , 3 , 5 , 6 , 3 , 1 , 0 , 3 , 1 , 12 , 5 , 3 , 3 , 2 , 0 , 7 , 7 , 2 , 1 , 0 , 4 , 0 , 1 , 1 , 2 , 0 , 10 , 10 , 6 , 2 , 5 , 9 , 7 , 5 , 15 , 15 , 21 , 6 , 11 , 5 , 20 ,
4 , 3 , 5 , 5 , 2 , 5 , 0 , 2 , 1 , 0 , 1 , 7 , 28 , 0 , 9 , 0 , 5 , 12 , 5 , 5 , 18 , 30 , 0 , 12 , 3 , 3 , 21 , 16 , 25 , 32 , 9 , 3 , 14 , 11 , 24 , 5 , 66 , 9 , 1 , 2 , 0 , 5 , 9 , 1 , 5 , 1 , 8 , 0 , 8 , 3 , 3 , 0 , 1 , 15 , 1 , 4 , 8 , 1 , 2 , 7 , 0 , 7 , 2 ,
8 , 3 , 7 , 5 , 3 , 7 , 10 , 2 , 1 , 0 , 0 , 2 , 25 , 0 , 6 , 4 , 0 , 10 , 0 , 4 , 2 , 4 , 1 , 12 , 5 , 38 , 4 , 0 , 4 , 1 , 10 , 5 , 9 , 4 , 0 , 14 , 4 , 2 , 5 , 18 , 20 , 21 , 1 , 3 , 0 , 5 , 0 , 7 , 0 , 3 , 7 , 1 , 3 , 1 , 1 , 8 , 1 , 0 , 0 , 0 , 3 , 2 , 5 , 2 , 11 ,
6 , 0 , 13 , 1 , 3 , 9 , 1 , 12 , 0 , 16 , 6 , 2 , 1 , 0 , 2 , 1 , 12 , 6 , 13 , 11 , 2 , 0 , 28 , 1 , 7 , 8 , 14 , 13 , 8 , 13 , 0 , 2 , 0 , 5 , 4 , 8 , 10 , 2 , 37 , 42 , 19 , 6 , 6 , 7 , 4 , 14 , 11 , 18 , 14 , 80 , 7 , 6 , 0 , 4 , 72 , 12 , 36 , 27 ,
7 , 7 , 0 , 14 , 17 , 19 , 164 , 27 , 0 , 5 , 10 , 7 , 3 , 13 , 6 , 14 , 0 , 2 , 2 , 5 , 3 , 0 , 6 , 13 , 0 , 0 , 10 , 29 , 0 , 4 , 0 , 3 , 13 , 0 , 3 , 1 , 6 , 51 , 1 , 5 , 28 , 2 , 0 , 8 , 0 , 20 , 2 , 4 , 0 , 25 , 2 , 10 , 13 , 10 , 0 , 16 , 4 , 0 , 1 , 0 ,
2 , 1 , 7 , 0 , 1 , 8 , 11 , 0 , 0 , 1 , 2 , 7 , 2 , 23 , 11 , 6 , 6 , 4 , 16 , 2 , 2 , 2 , 0 , 22 , 9 , 3 , 3 , 5 , 2 , 0 , 15 , 16 , 21 , 2 , 9 , 20 , 15 , 15 , 5 , 3 , 9 , 1 , 0 , 0 , 1 , 7 , 7 , 5 , 4 , 2 , 2 , 2 , 38 , 24 , 14 , 0 , 0 , 15 , 5 , 6 , 24 , 14 ,
5 , 5 , 11 , 0 , 21 , 12 , 0 , 3 , 8 , 4 , 11 , 1 , 8 , 0 , 11 , 27 , 7 , 2 , 4 , 9 , 21 , 59 , 0 , 1 , 39 , 3 , 60 , 62 , 3 , 0 , 12 , 11 , 0 , 3 , 30 , 11 , 0 , 13 , 88 , 4 , 15 , 5 , 28 , 13 , 1 , 4 , 48 , 17 , 17 , 4 , 28 , 32 , 46 , 0 , 16 , 0 ,
18 , 11 , 1 , 8 , 6 , 38 , 11 , 2 , 6 , 11 , 38 , 2 , 0 , 45 , 3 , 11 , 2 , 7 , 8 , 4 , 30 , 14 , 17 , 2 , 1 , 1 , 65 , 18 , 12 , 16 , 4 , 2 , 45 , 123 , 12 , 56 , 33 , 1 , 4 , 3 , 4 , 7 , 0 , 0 , 0 , 3 , 2 , 0 , 16 , 4 , 2 , 4 , 2 , 0 , 7 , 4 , 5 , 2 , 26 ,
2 , 25 , 6 , 11 , 6 , 1 , 16 , 2 , 6 , 17 , 77 , 15 , 3 , 35 , 0 , 1 , 0 , 5 , 1 , 0 , 38 , 16 , 6 , 3 , 12 , 3 , 3 , 3 , 0 , 9 , 3 , 1 , 3 , 5 , 2 , 9 , 0 , 18 , 0 , 25 , 1 , 3 , 32 , 1 , 72 , 46 , 6 , 2 , 7 , 1 , 3 , 14 , 17 , 0 , 28 , 1 , 40 , 13 , 0 , 20 ,
15 , 40 , 6 , 38 , 24 , 12 , 43 , 1 , 1 , 9 , 0 , 12 , 6 , 0 , 6 , 2 , 4 , 19 , 3 , 7 , 1 , 48 , 0 , 9 , 5 , 0 , 5 , 6 , 9 , 6 , 10 , 15 , 2 , 11 , 19 , 3 , 9 , 2 , 0 , 1 , 10 , 1 , 27 , 8 , 1 , 3 , 6 , 1 , 14 , 0 , 26 , 0 , 27 , 16 , 3 , 4 , 9 , 6 , 2 , 23 ,
9 , 10 , 5 , 25 , 2 , 1 , 6 , 1 , 1 , 48 , 15 , 9 , 15 , 14 , 3 , 4 , 26 , 60 , 29 , 13 , 37 , 21 , 1 , 6 , 4 , 0 , 2 , 11 , 22 , 23 , 16 , 16 , 2 , 2 , 1 , 3 , 0 , 5 , 1 , 6 , 4 , 0 , 0 , 4 , 0 , 0 , 8 , 3 , 0 , 2 , 5 , 0 , 7 , 1 , 7 , 3 , 13 , 2 , 4 , 10 ,
3 , 0 , 2 , 31 , 0 , 18 , 3 , 0 , 12 , 10 , 4 , 1 , 0 , 7 , 5 , 7 , 0 , 5 , 4 , 12 , 2 , 22 , 10 , 4 , 2 , 15 , 2 , 8 , 9 , 0 , 23 , 2 , 197 , 51 , 3 , 1 , 1 , 4 , 13 , 4 , 3 , 21 , 4 , 19 , 3 , 10 , 5 , 40 , 0 , 4 , 1 , 1 , 10 , 4 , 1 , 27 , 34 , 7 , 21 ,
2 , 17 , 2 , 9 , 6 , 4 , 2 , 3 , 0 , 4 , 2 , 7 , 8 , 2 , 5 , 1 , 15 , 21 , 3 , 4 , 4 , 2 , 2 , 17 , 22 , 1 , 5 , 22 , 4 , 26 , 7 , 0 , 32 , 1 , 11 , 42 , 15 , 4 , 1 , 2 , 5 , 0 , 19 , 3 , 1 , 8 , 6 , 0 , 10 , 1 , 9 , 2 , 13 , 30 , 8 , 2 , 24 , 17 , 19 , 1 , 4 ,
4 , 25 , 13 , 0 , 10 , 16 , 11 , 39 , 18 , 8 , 5 , 30 , 82 , 1 , 6 , 8 , 18 , 77 , 11 , 13 , 20 , 75 , 11 , 112 , 78 , 33 , 3 , 0 , 0 , 60 , 17 , 84 , 9 , 1 , 1 , 12 , 30 , 10 , 49 , 5 , 32 , 158 , 178 , 5 , 5 , 6 , 3 , 3 , 1 , 3 , 1 , 4 , 7 , 6 ,
19 , 31 , 21 , 0 , 2 , 9 , 5 , 6 , 27 , 4 , 9 , 8 , 1 , 76 , 18 , 12 , 1 , 4 , 0 , 3 , 3 , 6 , 3 , 12 , 2 , 8 , 30 , 16 , 2 , 25 , 1 , 5 , 5 , 4 , 3 , 0 , 6 , 10 , 2 , 3 , 1 , 0 , 5 , 1 , 19 , 3 , 0 , 8 , 1 , 5 , 2 , 6 , 0 , 0 , 0 , 19 , 1 , 2 , 0 , 5 , 1 , 2 , 5 ,
1 , 3 , 7 , 0 , 4 , 12 , 7 , 3 , 10 , 22 , 0 , 9 , 5 , 1 , 0 , 2 , 20 , 1 , 1 , 3 , 23 , 30 , 3 , 9 , 9 , 1 , 4 , 191 , 14 , 3 , 15 , 6 , 8 , 50 , 0 , 1 , 0 , 0 , 4 , 0 , 0 , 1 , 0 , 2 , 4 , 2 , 0 , 2 , 3 , 0 , 2 , 0 , 2 , 2 , 8 , 7 , 0 , 1 , 1 , 1 , 3 , 3 , 17 , 11 ,
91 , 1 , 9 , 3 , 2 , 13 , 4 , 24 , 15 , 41 , 3 , 13 , 3 , 1 , 20 , 4 , 125 , 29 , 30 , 1 , 0 , 4 , 12 , 2 , 21 , 4 , 5 , 5 , 19 , 11 , 0 , 13 , 11 , 86 , 2 , 18 , 0 , 7 , 1 , 8 , 8 , 2 , 2 , 22 , 1 , 2 , 6 , 5 , 2 , 0 , 1 , 2 , 8 , 0 , 2 , 0 , 5 , 2 , 1 , 0 ,
2 , 10 , 2 , 0 , 5 , 9 , 2 , 1 , 2 , 0 , 1 , 0 , 4 , 0 , 0 , 10 , 2 , 5 , 3 , 0 , 6 , 1 , 0 , 1 , 4 , 4 , 33 , 3 , 13 , 17 , 3 , 18 , 6 , 4 , 7 , 1 , 5 , 78 , 0 , 4 , 1 , 13 , 7 , 1 , 8 , 1 , 0 , 35 , 27 , 15 , 3 , 0 , 0 , 0 , 1 , 11 , 5 , 41 , 38 , 15 , 22 , 6 ,
14 , 14 , 2 , 1 , 11 , 6 , 20 , 63 , 5 , 8 , 27 , 7 , 11 , 2 , 2 , 40 , 58 , 23 , 50 , 54 , 56 , 293 , 8 , 8 , 1 , 5 , 1 , 14 , 0 , 1 , 12 , 37 , 89 , 8 , 8 , 8 , 2 , 10 , 6 , 0 , 0 , 0 , 4 , 5 , 2 , 1 , 0 , 1 , 1 , 2 , 7 , 0 , 3 , 3 , 0 , 4 , 6 , 0 , 3 , 2 ,
19 , 3 , 8 , 0 , 0 , 0 , 4 , 4 , 16 , 0 , 4 , 1 , 5 , 1 , 3 , 0 , 3 , 4 , 6 , 2 , 17 , 10 , 10 , 31 , 6 , 4 , 3 , 6 , 10 , 126 , 7 , 3 , 2 , 2 , 0 , 9 , 0 , 0 , 5 , 20 , 13 , 0 , 15 , 0 , 6 , 0 , 2 , 5 , 8 , 64 , 50 , 3 , 2 , 12 , 2 , 9 , 0 , 0 , 11 , 8 , 20 ,
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 ,
} ;
static int ranges_unpacked = false ;
static ImWchar ranges [ 6 + 1 + IM_ARRAYSIZE ( offsets_from_0x4E00 ) * 2 ] =
{
0x0020 , 0x00FF , // Basic Latin + Latin Supplement
0x3040 , 0x309F , // Hiragana, Katakana
0xFF00 , 0xFFEF , // Half-width characters
0 ,
} ;
if ( ! ranges_unpacked )
{
// Unpack
int codepoint = 0x4e00 ;
ImWchar * dst = & ranges [ 6 ] ;
for ( int n = 0 ; n < IM_ARRAYSIZE ( offsets_from_0x4E00 ) ; n + + , dst + = 2 )
dst [ 0 ] = dst [ 1 ] = ( ImWchar ) ( codepoint + = ( offsets_from_0x4E00 [ n ] + 1 ) ) ;
dst [ 0 ] = 0 ;
ranges_unpacked = true ;
}
return & ranges [ 0 ] ;
}
2014-11-29 06:38:41 +08:00
void ImFont : : BuildLookupTable ( )
2014-08-11 04:58:11 +08:00
{
2015-01-09 07:35:01 +08:00
int max_codepoint = 0 ;
for ( size_t i = 0 ; i ! = Glyphs . size ( ) ; i + + )
max_codepoint = ImMax ( max_codepoint , ( int ) Glyphs [ i ] . Codepoint ) ;
2014-08-11 04:58:11 +08:00
2015-02-11 20:10:45 +08:00
IndexXAdvance . clear ( ) ;
IndexXAdvance . resize ( ( size_t ) max_codepoint + 1 ) ;
2014-08-19 19:09:13 +08:00
IndexLookup . clear ( ) ;
2015-01-09 07:35:01 +08:00
IndexLookup . resize ( ( size_t ) max_codepoint + 1 ) ;
2015-02-11 20:10:45 +08:00
for ( size_t i = 0 ; i < ( size_t ) max_codepoint + 1 ; i + + )
{
IndexXAdvance [ i ] = 0.0f ;
2014-08-19 19:09:13 +08:00
IndexLookup [ i ] = - 1 ;
2015-02-11 20:10:45 +08:00
}
2015-01-09 07:35:01 +08:00
for ( size_t i = 0 ; i < Glyphs . size ( ) ; i + + )
2015-02-11 20:10:45 +08:00
{
const size_t codepoint = ( int ) Glyphs [ i ] . Codepoint ;
IndexXAdvance [ codepoint ] = Glyphs [ i ] . XAdvance ;
IndexLookup [ codepoint ] = ( int ) i ;
}
2015-01-18 06:53:54 +08:00
// Create a glyph to handle TAB
// FIXME: Needs proper TAB handling but it needs to be contextualized (can arbitrary say that each string starts at "column 0"
if ( const ImFont : : Glyph * space_glyph = FindGlyph ( ( unsigned short ) ' ' ) )
{
Glyphs . resize ( Glyphs . size ( ) + 1 ) ;
ImFont : : Glyph & tab_glyph = Glyphs . back ( ) ;
2015-02-13 16:56:06 +08:00
tab_glyph = * FindGlyph ( ( unsigned short ) ' ' ) ;
2015-01-18 06:53:54 +08:00
tab_glyph . Codepoint = ' \t ' ;
tab_glyph . XAdvance * = 4 ;
2015-02-11 20:10:45 +08:00
IndexXAdvance [ ( size_t ) tab_glyph . Codepoint ] = ( float ) tab_glyph . XAdvance ;
IndexLookup [ ( size_t ) tab_glyph . Codepoint ] = ( int ) ( Glyphs . size ( ) - 1 ) ;
2015-01-18 06:53:54 +08:00
}
2014-08-11 04:58:11 +08:00
}
2015-01-09 07:35:01 +08:00
const ImFont : : Glyph * ImFont : : FindGlyph ( unsigned short c ) const
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
if ( c < ( int ) IndexLookup . size ( ) )
{
const int i = IndexLookup [ c ] ;
2015-01-15 05:59:39 +08:00
if ( i ! = - 1 )
return & Glyphs [ i ] ;
2014-08-19 19:09:13 +08:00
}
2014-11-29 08:04:05 +08:00
return FallbackGlyph ;
2014-08-11 04:58:11 +08:00
}
2014-09-25 18:29:59 +08:00
// Convert UTF-8 to 32-bits character, process single character input.
// Based on stb_from_utf8() from github.com/nothings/stb/
static int ImTextCharFromUtf8 ( unsigned int * out_char , const char * in_text , const char * in_text_end )
{
2015-02-11 20:23:38 +08:00
unsigned int c = ( unsigned int ) - 1 ;
const unsigned char * str = ( const unsigned char * ) in_text ;
if ( ! ( * str & 0x80 ) )
{
c = ( unsigned int ) ( * str + + ) ;
* out_char = c ;
return 1 ;
}
if ( ( * str & 0xe0 ) = = 0xc0 )
{
if ( in_text_end & & in_text_end - ( const char * ) str < 2 ) return - 1 ;
if ( * str < 0xc2 ) return - 1 ;
c = ( unsigned int ) ( ( * str + + & 0x1f ) < < 6 ) ;
if ( ( * str & 0xc0 ) ! = 0x80 ) return - 1 ;
c + = ( * str + + & 0x3f ) ;
* out_char = c ;
return 2 ;
}
if ( ( * str & 0xf0 ) = = 0xe0 )
{
if ( in_text_end & & in_text_end - ( const char * ) str < 3 ) return - 1 ;
if ( * str = = 0xe0 & & ( str [ 1 ] < 0xa0 | | str [ 1 ] > 0xbf ) ) return - 1 ;
if ( * str = = 0xed & & str [ 1 ] > 0x9f ) return - 1 ; // str[1] < 0x80 is checked below
c = ( unsigned int ) ( ( * str + + & 0x0f ) < < 12 ) ;
if ( ( * str & 0xc0 ) ! = 0x80 ) return - 1 ;
c + = ( unsigned int ) ( ( * str + + & 0x3f ) < < 6 ) ;
if ( ( * str & 0xc0 ) ! = 0x80 ) return - 1 ;
c + = ( * str + + & 0x3f ) ;
* out_char = c ;
return 3 ;
}
if ( ( * str & 0xf8 ) = = 0xf0 )
{
if ( in_text_end & & in_text_end - ( const char * ) str < 4 ) return - 1 ;
if ( * str > 0xf4 ) return - 1 ;
if ( * str = = 0xf0 & & ( str [ 1 ] < 0x90 | | str [ 1 ] > 0xbf ) ) return - 1 ;
if ( * str = = 0xf4 & & str [ 1 ] > 0x8f ) return - 1 ; // str[1] < 0x80 is checked below
c = ( unsigned int ) ( ( * str + + & 0x07 ) < < 18 ) ;
if ( ( * str & 0xc0 ) ! = 0x80 ) return - 1 ;
c + = ( unsigned int ) ( ( * str + + & 0x3f ) < < 12 ) ;
if ( ( * str & 0xc0 ) ! = 0x80 ) return - 1 ;
c + = ( unsigned int ) ( ( * str + + & 0x3f ) < < 6 ) ;
if ( ( * str & 0xc0 ) ! = 0x80 ) return - 1 ;
c + = ( * str + + & 0x3f ) ;
// utf-8 encodings of values used in surrogate pairs are invalid
if ( ( c & 0xFFFFF800 ) = = 0xD800 ) return - 1 ;
* out_char = c ;
return 4 ;
2014-09-25 18:35:23 +08:00
}
* out_char = 0 ;
return 0 ;
2014-09-25 18:29:59 +08:00
}
2014-10-04 11:24:04 +08:00
static ptrdiff_t ImTextStrFromUtf8 ( ImWchar * buf , size_t buf_size , const char * in_text , const char * in_text_end )
2014-09-25 21:51:06 +08:00
{
ImWchar * buf_out = buf ;
ImWchar * buf_end = buf + buf_size ;
while ( buf_out < buf_end - 1 & & ( ! in_text_end | | in_text < in_text_end ) & & * in_text )
{
unsigned int c ;
in_text + = ImTextCharFromUtf8 ( & c , in_text , in_text_end ) ;
if ( c < 0x10000 ) // FIXME: Losing characters that don't fit in 2 bytes
* buf_out + + = ( ImWchar ) c ;
}
* buf_out = 0 ;
return buf_out - buf ;
}
2014-11-24 07:35:26 +08:00
static int ImTextCountCharsFromUtf8 ( const char * in_text , const char * in_text_end )
{
int char_count = 0 ;
while ( ( ! in_text_end | | in_text < in_text_end ) & & * in_text )
{
unsigned int c ;
in_text + = ImTextCharFromUtf8 ( & c , in_text , in_text_end ) ;
if ( c < 0x10000 )
char_count + + ;
}
return char_count ;
}
2014-09-25 21:51:06 +08:00
// Based on stb_to_utf8() from github.com/nothings/stb/
static int ImTextCharToUtf8 ( char * buf , size_t buf_size , unsigned int c )
{
if ( c )
{
2014-10-04 11:24:04 +08:00
size_t i = 0 ;
size_t n = buf_size ;
2014-09-25 21:51:06 +08:00
if ( c < 0x80 )
{
if ( i + 1 > n ) return 0 ;
buf [ i + + ] = ( char ) c ;
return 1 ;
}
else if ( c < 0x800 )
{
if ( i + 2 > n ) return 0 ;
2014-11-18 03:35:58 +08:00
buf [ i + + ] = ( char ) ( 0xc0 + ( c > > 6 ) ) ;
buf [ i + + ] = ( char ) ( 0x80 + ( c & 0x3f ) ) ;
2014-09-25 21:51:06 +08:00
return 2 ;
}
else if ( c > = 0xdc00 & & c < 0xe000 )
{
return 0 ;
}
else if ( c > = 0xd800 & & c < 0xdc00 )
{
2014-09-26 03:55:48 +08:00
if ( i + 4 > n ) return 0 ;
2014-11-18 03:35:58 +08:00
buf [ i + + ] = ( char ) ( 0xf0 + ( c > > 18 ) ) ;
buf [ i + + ] = ( char ) ( 0x80 + ( ( c > > 12 ) & 0x3f ) ) ;
buf [ i + + ] = ( char ) ( 0x80 + ( ( c > > 6 ) & 0x3f ) ) ;
buf [ i + + ] = ( char ) ( 0x80 + ( ( c ) & 0x3f ) ) ;
2014-09-25 21:51:06 +08:00
return 4 ;
}
//else if (c < 0x10000)
{
if ( i + 3 > n ) return 0 ;
2014-11-18 03:35:58 +08:00
buf [ i + + ] = ( char ) ( 0xe0 + ( c > > 12 ) ) ;
buf [ i + + ] = ( char ) ( 0x80 + ( ( c > > 6 ) & 0x3f ) ) ;
buf [ i + + ] = ( char ) ( 0x80 + ( ( c ) & 0x3f ) ) ;
2014-09-25 21:51:06 +08:00
return 3 ;
}
}
return 0 ;
}
2014-10-04 11:24:04 +08:00
static ptrdiff_t ImTextStrToUtf8 ( char * buf , size_t buf_size , const ImWchar * in_text , const ImWchar * in_text_end )
2014-09-25 21:51:06 +08:00
{
char * buf_out = buf ;
const char * buf_end = buf + buf_size ;
while ( buf_out < buf_end - 1 & & ( ! in_text_end | | in_text < in_text_end ) & & * in_text )
{
2014-11-18 03:35:58 +08:00
buf_out + = ImTextCharToUtf8 ( buf_out , ( uintptr_t ) ( buf_end - buf_out - 1 ) , ( unsigned int ) * in_text ) ;
2014-09-25 21:51:06 +08:00
in_text + + ;
}
* buf_out = 0 ;
return buf_out - buf ;
}
2014-11-24 07:35:26 +08:00
static int ImTextCountUtf8BytesFromWchar ( const ImWchar * in_text , const ImWchar * in_text_end )
{
int bytes_count = 0 ;
while ( ( ! in_text_end | | in_text < in_text_end ) & & * in_text )
{
char dummy [ 5 ] ; // FIXME-OPT
bytes_count + = ImTextCharToUtf8 ( dummy , 5 , ( unsigned int ) * in_text ) ;
in_text + + ;
}
return bytes_count ;
}
2014-11-29 08:02:46 +08:00
const char * ImFont : : CalcWordWrapPositionA ( float scale , const char * text , const char * text_end , float wrap_width ) const
2014-11-07 13:45:56 +08:00
{
// Simple word-wrapping for English, not full-featured. Please submit failing cases!
// FIXME: Much possible improvements (don't cut things like "word !", "word!!!" but cut within "word,,,,", more sensible support for punctuations, support for Unicode punctuations, etc.)
// For references, possible wrap point marked with ^
// "aaa bbb, ccc,ddd. eee fff. ggg!"
// ^ ^ ^ ^ ^__ ^ ^
// List of hardcoded separators: .,;!?'"
// Skip extra blanks after a line returns (that includes not counting them in width computation)
2015-01-09 07:35:01 +08:00
// e.g. "Hello world" --> "Hello" "World"
2014-11-07 13:45:56 +08:00
// Cut words that cannot possibly fit within one line.
2015-01-09 07:35:01 +08:00
// e.g.: "The tropical fish" with ~5 characters worth of width --> "The tr" "opical" "fish"
2014-11-07 13:45:56 +08:00
float line_width = 0.0f ;
float word_width = 0.0f ;
float blank_width = 0.0f ;
const char * word_end = text ;
const char * prev_word_end = NULL ;
bool inside_word = true ;
const char * s = text ;
while ( s < text_end )
{
2015-02-11 20:31:04 +08:00
unsigned int c = ( unsigned int ) * s ;
const char * next_s ;
if ( c < 0x80 )
next_s = s + 1 ;
else
next_s = s + ImTextCharFromUtf8 ( & c , s , text_end ) ;
2014-11-07 13:45:56 +08:00
if ( c = = ' \n ' )
{
line_width = word_width = blank_width = 0.0f ;
inside_word = true ;
s = next_s ;
continue ;
}
2015-02-11 20:10:45 +08:00
const float char_width = ( ( size_t ) c < IndexXAdvance . size ( ) ) ? IndexXAdvance [ ( size_t ) c ] * scale : 0.0f ;
2014-11-07 13:45:56 +08:00
if ( c = = ' ' | | c = = ' \t ' )
{
if ( inside_word )
{
line_width + = blank_width ;
blank_width = 0.0f ;
}
blank_width + = char_width ;
inside_word = false ;
}
else
{
word_width + = char_width ;
if ( inside_word )
{
word_end = next_s ;
}
else
{
prev_word_end = word_end ;
line_width + = word_width + blank_width ;
word_width = blank_width = 0.0f ;
}
// Allow wrapping after punctuation.
2014-11-22 00:35:35 +08:00
inside_word = ! ( c = = ' . ' | | c = = ' , ' | | c = = ' ; ' | | c = = ' ! ' | | c = = ' ? ' | | c = = ' \" ' ) ;
2014-11-07 13:45:56 +08:00
}
// We ignore blank width at the end of the line (they can be skipped)
if ( line_width + word_width > = wrap_width )
{
// Words that cannot possibly fit within an entire line will be cut anywhere.
if ( word_width < wrap_width )
s = prev_word_end ? prev_word_end : word_end ;
break ;
}
s = next_s ;
}
return s ;
}
2014-11-29 06:38:41 +08:00
ImVec2 ImFont : : CalcTextSizeA ( float size , float max_width , float wrap_width , const char * text_begin , const char * text_end , const char * * remaining ) const
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
if ( ! text_end )
2015-01-17 21:40:56 +08:00
text_end = text_begin + strlen ( text_begin ) ; // FIXME-OPT: Need to avoid this.
2014-08-19 19:09:13 +08:00
2015-01-09 07:35:01 +08:00
const float scale = size / FontSize ;
const float line_height = FontSize * scale ;
2014-08-19 19:09:13 +08:00
ImVec2 text_size = ImVec2 ( 0 , 0 ) ;
float line_width = 0.0f ;
2014-11-07 13:45:56 +08:00
const bool word_wrap_enabled = ( wrap_width > 0.0f ) ;
const char * word_wrap_eol = NULL ;
2014-08-19 19:09:13 +08:00
const char * s = text_begin ;
while ( s < text_end )
{
2014-11-07 13:45:56 +08:00
if ( word_wrap_enabled )
{
// Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature.
if ( ! word_wrap_eol )
{
2014-11-29 08:02:46 +08:00
word_wrap_eol = CalcWordWrapPositionA ( scale , s , text_end , wrap_width - line_width ) ;
2014-11-07 13:45:56 +08:00
if ( word_wrap_eol = = s ) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
word_wrap_eol + + ; // +1 may not be a character start point in UTF-8 but it's ok because we use s >= word_wrap_eol below
}
if ( s > = word_wrap_eol )
{
if ( text_size . x < line_width )
text_size . x = line_width ;
text_size . y + = line_height ;
line_width = 0.0f ;
word_wrap_eol = NULL ;
// Wrapping skips upcoming blanks
while ( s < text_end )
{
const char c = * s ;
if ( c = = ' ' | | c = = ' \t ' ) { s + + ; } else if ( c = = ' \n ' ) { s + + ; break ; } else { break ; }
}
continue ;
}
}
// Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
2015-02-11 20:31:04 +08:00
unsigned int c = ( unsigned int ) * s ;
if ( c < 0x80 )
s + = 1 ;
else
s + = ImTextCharFromUtf8 ( & c , s , text_end ) ;
2014-11-07 13:45:56 +08:00
2014-08-19 19:09:13 +08:00
if ( c = = ' \n ' )
{
2015-01-17 21:40:56 +08:00
text_size . x = ImMax ( text_size . x , line_width ) ;
2014-08-19 19:09:13 +08:00
text_size . y + = line_height ;
2014-11-07 13:45:56 +08:00
line_width = 0.0f ;
continue ;
2014-08-19 19:09:13 +08:00
}
2014-11-07 13:45:56 +08:00
2015-02-11 20:10:45 +08:00
const float char_width = ( ( size_t ) c < IndexXAdvance . size ( ) ) ? IndexXAdvance [ ( size_t ) c ] * scale : 0.0f ;
2014-11-07 13:45:56 +08:00
if ( line_width + char_width > = max_width )
break ;
line_width + = char_width ;
2014-09-25 21:51:06 +08:00
}
if ( line_width > 0 | | text_size . y = = 0.0f )
{
if ( text_size . x < line_width )
text_size . x = line_width ;
text_size . y + = line_height ;
}
if ( remaining )
* remaining = s ;
return text_size ;
}
2014-11-29 06:38:41 +08:00
ImVec2 ImFont : : CalcTextSizeW ( float size , float max_width , const ImWchar * text_begin , const ImWchar * text_end , const ImWchar * * remaining ) const
2014-09-25 21:51:06 +08:00
{
if ( ! text_end )
text_end = text_begin + ImStrlenW ( text_begin ) ;
2015-01-09 07:35:01 +08:00
const float scale = size / FontSize ;
const float line_height = FontSize * scale ;
2014-09-25 21:51:06 +08:00
ImVec2 text_size = ImVec2 ( 0 , 0 ) ;
float line_width = 0.0f ;
const ImWchar * s = text_begin ;
while ( s < text_end )
{
const unsigned int c = ( unsigned int ) ( * s + + ) ;
if ( c = = ' \n ' )
{
2015-01-17 21:40:56 +08:00
text_size . x = ImMax ( text_size . x , line_width ) ;
2014-09-25 21:51:06 +08:00
text_size . y + = line_height ;
2014-11-07 13:45:56 +08:00
line_width = 0.0f ;
continue ;
2014-09-25 21:51:06 +08:00
}
2014-11-07 13:45:56 +08:00
2015-02-11 20:10:45 +08:00
const float char_width = ( ( size_t ) c < IndexXAdvance . size ( ) ) ? IndexXAdvance [ ( size_t ) c ] * scale : 0.0f ;
2014-11-07 13:45:56 +08:00
if ( line_width + char_width > = max_width )
break ;
line_width + = char_width ;
2014-08-19 19:09:13 +08:00
}
if ( line_width > 0 | | text_size . y = = 0.0f )
{
if ( text_size . x < line_width )
text_size . x = line_width ;
text_size . y + = line_height ;
}
if ( remaining )
* remaining = s ;
return text_size ;
2014-08-11 04:58:11 +08:00
}
2015-02-09 00:32:51 +08:00
void ImFont : : RenderText ( float size , ImVec2 pos , ImU32 col , const ImVec4 & clip_rect_ref , const char * text_begin , const char * text_end , ImDrawVert * & out_vertices , float wrap_width , const ImVec2 * cpu_clip_max ) const
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
if ( ! text_end )
text_end = text_begin + strlen ( text_begin ) ;
2015-01-09 07:35:01 +08:00
const float scale = size / FontSize ;
const float line_height = FontSize * scale ;
2014-08-19 19:09:13 +08:00
// Align to be pixel perfect
2014-11-29 08:02:46 +08:00
pos . x = ( float ) ( int ) pos . x + DisplayOffset . x ;
pos . y = ( float ) ( int ) pos . y + DisplayOffset . y ;
2014-08-19 19:09:13 +08:00
2014-11-07 13:45:56 +08:00
const bool word_wrap_enabled = ( wrap_width > 0.0f ) ;
const char * word_wrap_eol = NULL ;
2014-08-19 19:09:13 +08:00
2015-02-09 00:32:51 +08:00
ImVec4 clip_rect = clip_rect_ref ;
if ( cpu_clip_max )
{
clip_rect . z = ImMin ( clip_rect . z , cpu_clip_max - > x ) ;
clip_rect . w = ImMin ( clip_rect . w , cpu_clip_max - > y ) ;
}
2014-08-19 19:09:13 +08:00
float x = pos . x ;
float y = pos . y ;
2014-11-07 13:45:56 +08:00
const char * s = text_begin ;
while ( s < text_end )
2014-08-19 19:09:13 +08:00
{
2014-11-07 13:45:56 +08:00
if ( word_wrap_enabled )
{
// Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature.
if ( ! word_wrap_eol )
{
2014-11-29 08:02:46 +08:00
word_wrap_eol = CalcWordWrapPositionA ( scale , s , text_end , wrap_width - ( x - pos . x ) ) ;
2014-11-07 13:45:56 +08:00
if ( word_wrap_eol = = s ) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
word_wrap_eol + + ; // +1 may not be a character start point in UTF-8 but it's ok because we use s >= word_wrap_eol below
}
if ( s > = word_wrap_eol )
{
x = pos . x ;
2015-01-05 06:29:53 +08:00
y + = line_height ;
2014-11-07 13:45:56 +08:00
word_wrap_eol = NULL ;
// Wrapping skips upcoming blanks
while ( s < text_end )
{
const char c = * s ;
if ( c = = ' ' | | c = = ' \t ' ) { s + + ; } else if ( c = = ' \n ' ) { s + + ; break ; } else { break ; }
}
continue ;
}
}
// Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
2015-02-11 20:31:04 +08:00
unsigned int c = ( unsigned int ) * s ;
if ( c < 0x80 )
s + = 1 ;
else
s + = ImTextCharFromUtf8 ( & c , s , text_end ) ;
2014-09-25 18:29:59 +08:00
2014-09-25 18:35:23 +08:00
if ( c = = ' \n ' )
2014-08-19 19:09:13 +08:00
{
x = pos . x ;
2015-01-05 06:29:53 +08:00
y + = line_height ;
2014-08-19 19:09:13 +08:00
continue ;
}
2014-11-07 13:45:56 +08:00
float char_width = 0.0f ;
2015-01-18 06:53:54 +08:00
if ( const Glyph * glyph = FindGlyph ( ( unsigned short ) c ) )
2014-11-07 13:45:56 +08:00
{
2015-01-09 07:35:01 +08:00
char_width = glyph - > XAdvance * scale ;
2015-01-18 06:53:54 +08:00
if ( c ! = ' ' & & c ! = ' \t ' )
2014-08-19 19:09:13 +08:00
{
2014-11-07 13:45:56 +08:00
// Clipping on Y is more likely
2015-02-09 00:32:51 +08:00
float y1 = ( float ) ( y + glyph - > YOffset * scale ) ;
float y2 = ( float ) ( y1 + glyph - > Height * scale ) ;
2014-11-07 13:45:56 +08:00
if ( y1 < = clip_rect . w & & y2 > = clip_rect . y )
2014-08-19 19:09:13 +08:00
{
2015-02-09 00:32:51 +08:00
float x1 = ( float ) ( x + glyph - > XOffset * scale ) ;
float x2 = ( float ) ( x1 + glyph - > Width * scale ) ;
2014-11-07 13:45:56 +08:00
if ( x1 < = clip_rect . z & & x2 > = clip_rect . x )
{
// Render a character
2015-02-09 00:32:51 +08:00
float u1 = glyph - > U0 ;
float v1 = glyph - > V0 ;
float u2 = glyph - > U1 ;
float v2 = glyph - > V1 ;
// CPU side clipping used to fit text in their frame when the frame is too small. Only does clipping for axis aligned quad and in the "max" direction (bottom-right)
if ( cpu_clip_max )
{
if ( x2 > cpu_clip_max - > x )
{
const float clip_tx = ( cpu_clip_max - > x - x1 ) / ( x2 - x1 ) ;
x2 = cpu_clip_max - > x ;
u2 = u1 + clip_tx * ( u2 - u1 ) ;
}
if ( y2 > cpu_clip_max - > y )
{
const float clip_ty = ( cpu_clip_max - > y - y1 ) / ( y2 - y1 ) ;
y2 = cpu_clip_max - > y ;
v2 = v1 + clip_ty * ( v2 - v1 ) ;
}
}
2014-08-19 19:09:13 +08:00
2014-11-07 13:45:56 +08:00
out_vertices [ 0 ] . pos = ImVec2 ( x1 , y1 ) ;
2015-02-09 00:32:51 +08:00
out_vertices [ 0 ] . uv = ImVec2 ( u1 , v1 ) ;
2014-11-07 13:45:56 +08:00
out_vertices [ 0 ] . col = col ;
2014-08-19 19:09:13 +08:00
2014-11-07 13:45:56 +08:00
out_vertices [ 1 ] . pos = ImVec2 ( x2 , y1 ) ;
2015-02-09 00:32:51 +08:00
out_vertices [ 1 ] . uv = ImVec2 ( u2 , v1 ) ;
2014-11-07 13:45:56 +08:00
out_vertices [ 1 ] . col = col ;
2014-08-19 19:09:13 +08:00
2014-11-07 13:45:56 +08:00
out_vertices [ 2 ] . pos = ImVec2 ( x2 , y2 ) ;
2015-02-09 00:32:51 +08:00
out_vertices [ 2 ] . uv = ImVec2 ( u2 , v2 ) ;
2014-11-07 13:45:56 +08:00
out_vertices [ 2 ] . col = col ;
2014-08-19 19:09:13 +08:00
2014-11-07 13:45:56 +08:00
out_vertices [ 3 ] = out_vertices [ 0 ] ;
out_vertices [ 4 ] = out_vertices [ 2 ] ;
2014-08-19 19:09:13 +08:00
2014-11-07 13:45:56 +08:00
out_vertices [ 5 ] . pos = ImVec2 ( x1 , y2 ) ;
2015-02-09 00:32:51 +08:00
out_vertices [ 5 ] . uv = ImVec2 ( u1 , v2 ) ;
2014-11-07 13:45:56 +08:00
out_vertices [ 5 ] . col = col ;
2014-08-19 19:09:13 +08:00
2014-11-07 13:45:56 +08:00
out_vertices + = 6 ;
}
}
2014-08-19 19:09:13 +08:00
}
}
2014-11-07 13:45:56 +08:00
x + = char_width ;
2014-08-19 19:09:13 +08:00
}
2014-08-11 04:58:11 +08:00
}
2014-08-14 02:53:26 +08:00
//-----------------------------------------------------------------------------
// PLATFORM DEPENDANT HELPERS
//-----------------------------------------------------------------------------
2014-08-14 22:03:10 +08:00
# if defined(_MSC_VER) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS)
2014-08-14 02:53:26 +08:00
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
2014-08-14 22:03:10 +08:00
// Win32 API clipboard implementation
2014-08-19 19:09:13 +08:00
static const char * GetClipboardTextFn_DefaultImpl ( )
2014-08-14 02:53:26 +08:00
{
2014-08-19 19:09:13 +08:00
static char * buf_local = NULL ;
if ( buf_local )
{
2014-09-25 01:01:07 +08:00
ImGui : : MemFree ( buf_local ) ;
2014-08-19 19:09:13 +08:00
buf_local = NULL ;
}
if ( ! OpenClipboard ( NULL ) )
return NULL ;
HANDLE buf_handle = GetClipboardData ( CF_TEXT ) ;
if ( buf_handle = = NULL )
return NULL ;
if ( char * buf_global = ( char * ) GlobalLock ( buf_handle ) )
2014-08-31 18:28:21 +08:00
buf_local = ImStrdup ( buf_global ) ;
2014-08-19 19:09:13 +08:00
GlobalUnlock ( buf_handle ) ;
CloseClipboard ( ) ;
return buf_local ;
2014-08-14 02:53:26 +08:00
}
2014-08-14 22:03:10 +08:00
// Win32 API clipboard implementation
2014-09-25 21:51:06 +08:00
static void SetClipboardTextFn_DefaultImpl ( const char * text )
2014-08-14 02:53:26 +08:00
{
2014-08-19 19:09:13 +08:00
if ( ! OpenClipboard ( NULL ) )
return ;
2014-09-25 21:51:06 +08:00
const char * text_end = text + strlen ( text ) ;
2014-08-19 19:09:13 +08:00
const int buf_length = ( int ) ( text_end - text ) + 1 ;
2014-11-18 17:55:31 +08:00
HGLOBAL buf_handle = GlobalAlloc ( GMEM_MOVEABLE , ( SIZE_T ) buf_length * sizeof ( char ) ) ;
2014-08-19 19:09:13 +08:00
if ( buf_handle = = NULL )
return ;
char * buf_global = ( char * ) GlobalLock ( buf_handle ) ;
2014-11-18 17:55:31 +08:00
memcpy ( buf_global , text , ( size_t ) ( text_end - text ) ) ;
2014-08-19 19:09:13 +08:00
buf_global [ text_end - text ] = 0 ;
GlobalUnlock ( buf_handle ) ;
EmptyClipboard ( ) ;
SetClipboardData ( CF_TEXT , buf_handle ) ;
CloseClipboard ( ) ;
2014-08-14 02:53:26 +08:00
}
2014-08-14 22:03:10 +08:00
# else
// Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
2014-08-19 19:09:13 +08:00
static const char * GetClipboardTextFn_DefaultImpl ( )
2014-08-14 22:03:10 +08:00
{
2015-02-01 12:28:24 +08:00
return GImGui - > PrivateClipboard ;
2014-08-14 22:03:10 +08:00
}
// Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
2014-09-25 21:51:06 +08:00
static void SetClipboardTextFn_DefaultImpl ( const char * text )
2014-08-14 22:03:10 +08:00
{
2015-02-04 16:43:11 +08:00
ImGuiState & g = * GImGui ;
if ( g . PrivateClipboard )
2014-08-19 19:09:13 +08:00
{
2015-02-04 16:43:11 +08:00
ImGui : : MemFree ( g . PrivateClipboard ) ;
g . PrivateClipboard = NULL ;
2014-08-19 19:09:13 +08:00
}
2014-09-25 21:51:06 +08:00
const char * text_end = text + strlen ( text ) ;
2015-02-04 16:43:11 +08:00
g . PrivateClipboard = ( char * ) ImGui : : MemAlloc ( ( size_t ) ( text_end - text ) + 1 ) ;
memcpy ( g . PrivateClipboard , text , ( size_t ) ( text_end - text ) ) ;
g . PrivateClipboard [ ( size_t ) ( text_end - text ) ] = 0 ;
2014-08-14 22:03:10 +08:00
}
# endif
2014-08-14 02:53:26 +08:00
2014-08-11 04:58:11 +08:00
//-----------------------------------------------------------------------------
// HELP
//-----------------------------------------------------------------------------
2014-11-10 09:29:01 +08:00
void ImGui : : ShowUserGuide ( )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGui : : BulletText ( " Double-click on title bar to collapse window. " ) ;
ImGui : : BulletText ( " Click and drag on lower right corner to resize window. " ) ;
ImGui : : BulletText ( " Click and drag on any empty space to move window. " ) ;
ImGui : : BulletText ( " Mouse Wheel to scroll. " ) ;
2014-09-24 21:03:42 +08:00
if ( g . IO . FontAllowUserScaling )
2014-08-19 19:09:13 +08:00
ImGui : : BulletText ( " CTRL+Mouse Wheel to zoom window contents. " ) ;
2014-11-07 13:45:56 +08:00
ImGui : : BulletText ( " TAB/SHIFT+TAB to cycle through keyboard editable fields. " ) ;
2014-08-19 19:09:13 +08:00
ImGui : : BulletText ( " CTRL+Click on a slider to input text. " ) ;
ImGui : : BulletText (
" While editing text: \n "
" - Hold SHIFT or use mouse to select text \n "
" - CTRL+Left/Right to word jump \n "
" - CTRL+A select all \n "
" - CTRL+X,CTRL+C,CTRL+V clipboard \n "
" - CTRL+Z,CTRL+Y undo/redo \n "
" - ESCAPE to revert \n "
" - You can apply arithmetic operators +,*,/ on numerical values. \n "
" Use +- to subtract. \n " ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-10 09:29:01 +08:00
void ImGui : : ShowStyleEditor ( ImGuiStyle * ref )
2014-08-11 04:58:11 +08:00
{
2015-02-01 12:28:24 +08:00
ImGuiState & g = * GImGui ;
2014-08-19 19:09:13 +08:00
ImGuiStyle & style = g . Style ;
2014-12-30 20:08:33 +08:00
const ImGuiStyle def ; // Default style
2014-08-19 19:09:13 +08:00
if ( ImGui : : Button ( " Revert Style " ) )
g . Style = ref ? * ref : def ;
if ( ref )
{
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Save Style " ) )
* ref = g . Style ;
}
2014-12-11 03:22:30 +08:00
ImGui : : PushItemWidth ( ImGui : : GetWindowWidth ( ) * 0.55f ) ;
2014-08-19 19:09:13 +08:00
2014-08-21 00:42:53 +08:00
if ( ImGui : : TreeNode ( " Sizes " ) )
{
ImGui : : SliderFloat ( " Alpha " , & style . Alpha , 0.20f , 1.0f , " %.2f " ) ; // Not exposing zero here so user doesn't "lose" the UI. But application code could have a toggle to switch between zero and non-zero.
ImGui : : SliderFloat2 ( " WindowPadding " , ( float * ) & style . WindowPadding , 0.0f , 20.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " WindowRounding " , & style . WindowRounding , 0.0f , 16.0f , " %.0f " ) ;
2015-02-10 21:00:22 +08:00
ImGui : : SliderFloat ( " ChildWindowRounding " , & style . ChildWindowRounding , 0.0f , 16.0f , " %.0f " ) ;
2014-08-21 00:42:53 +08:00
ImGui : : SliderFloat2 ( " FramePadding " , ( float * ) & style . FramePadding , 0.0f , 20.0f , " %.0f " ) ;
2015-01-15 17:14:44 +08:00
ImGui : : SliderFloat ( " FrameRounding " , & style . FrameRounding , 0.0f , 16.0f , " %.0f " ) ;
2014-08-21 00:42:53 +08:00
ImGui : : SliderFloat2 ( " ItemSpacing " , ( float * ) & style . ItemSpacing , 0.0f , 20.0f , " %.0f " ) ;
ImGui : : SliderFloat2 ( " ItemInnerSpacing " , ( float * ) & style . ItemInnerSpacing , 0.0f , 20.0f , " %.0f " ) ;
2014-12-30 18:00:00 +08:00
ImGui : : SliderFloat2 ( " TouchExtraPadding " , ( float * ) & style . TouchExtraPadding , 0.0f , 10.0f , " %.0f " ) ;
2014-08-21 00:42:53 +08:00
ImGui : : SliderFloat ( " TreeNodeSpacing " , & style . TreeNodeSpacing , 0.0f , 20.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " ScrollBarWidth " , & style . ScrollBarWidth , 0.0f , 20.0f , " %.0f " ) ;
ImGui : : TreePop ( ) ;
}
2014-08-19 19:09:13 +08:00
2014-08-21 00:42:53 +08:00
if ( ImGui : : TreeNode ( " Colors " ) )
2014-08-19 19:09:13 +08:00
{
2014-12-30 20:08:33 +08:00
static int output_dest = 0 ;
static bool output_only_modified = false ;
if ( ImGui : : Button ( " Output Colors " ) )
{
if ( output_dest = = 0 )
ImGui : : LogToClipboard ( ) ;
else
ImGui : : LogToTTY ( ) ;
ImGui : : LogText ( " ImGuiStyle& style = ImGui::GetStyle(); " STR_NEWLINE ) ;
for ( int i = 0 ; i < ImGuiCol_COUNT ; i + + )
{
const ImVec4 & col = style . Colors [ i ] ;
const char * name = ImGui : : GetStyleColName ( i ) ;
if ( ! output_only_modified | | memcmp ( & col , ( ref ? & ref - > Colors [ i ] : & def . Colors [ i ] ) , sizeof ( ImVec4 ) ) ! = 0 )
ImGui : : LogText ( " style.Colors[ImGuiCol_%s]%*s= ImVec4(%.2ff, %.2ff, %.2ff, %.2ff); " STR_NEWLINE , name , 22 - strlen ( name ) , " " , col . x , col . y , col . z , col . w ) ;
}
ImGui : : LogFinish ( ) ;
}
ImGui : : SameLine ( ) ; ImGui : : PushItemWidth ( 150 ) ; ImGui : : Combo ( " ##output_type " , & output_dest , " To Clipboard \0 To TTY " ) ; ImGui : : PopItemWidth ( ) ;
ImGui : : SameLine ( ) ; ImGui : : Checkbox ( " Only Modified Fields " , & output_only_modified ) ;
2014-08-21 00:42:53 +08:00
static ImGuiColorEditMode edit_mode = ImGuiColorEditMode_RGB ;
ImGui : : RadioButton ( " RGB " , & edit_mode , ImGuiColorEditMode_RGB ) ;
ImGui : : SameLine ( ) ;
ImGui : : RadioButton ( " HSV " , & edit_mode , ImGuiColorEditMode_HSV ) ;
ImGui : : SameLine ( ) ;
ImGui : : RadioButton ( " HEX " , & edit_mode , ImGuiColorEditMode_HEX ) ;
2015-01-15 17:49:12 +08:00
//ImGui::Text("Tip: Click on colored square to change edit mode.");
2014-08-21 00:42:53 +08:00
static ImGuiTextFilter filter ;
filter . Draw ( " Filter colors " , 200 ) ;
2014-11-20 19:54:13 +08:00
ImGui : : BeginChild ( " #colors " , ImVec2 ( 0 , 300 ) , true ) ;
2014-11-20 19:33:40 +08:00
2014-08-21 00:42:53 +08:00
ImGui : : ColorEditMode ( edit_mode ) ;
for ( int i = 0 ; i < ImGuiCol_COUNT ; i + + )
2014-08-19 19:09:13 +08:00
{
2014-12-30 03:56:01 +08:00
const char * name = ImGui : : GetStyleColName ( i ) ;
2014-08-21 00:42:53 +08:00
if ( ! filter . PassFilter ( name ) )
continue ;
ImGui : : PushID ( i ) ;
ImGui : : ColorEdit4 ( name , ( float * ) & style . Colors [ i ] , true ) ;
if ( memcmp ( & style . Colors [ i ] , ( ref ? & ref - > Colors [ i ] : & def . Colors [ i ] ) , sizeof ( ImVec4 ) ) ! = 0 )
{
ImGui : : SameLine ( ) ; if ( ImGui : : Button ( " Revert " ) ) style . Colors [ i ] = ref ? ref - > Colors [ i ] : def . Colors [ i ] ;
if ( ref ) { ImGui : : SameLine ( ) ; if ( ImGui : : Button ( " Save " ) ) ref - > Colors [ i ] = style . Colors [ i ] ; }
}
ImGui : : PopID ( ) ;
2014-08-19 19:09:13 +08:00
}
2014-11-20 19:54:13 +08:00
ImGui : : EndChild ( ) ;
2014-11-20 19:33:40 +08:00
2014-08-21 00:42:53 +08:00
ImGui : : TreePop ( ) ;
2014-08-19 19:09:13 +08:00
}
2014-08-21 00:42:53 +08:00
ImGui : : PopItemWidth ( ) ;
2014-08-11 04:58:11 +08:00
}
//-----------------------------------------------------------------------------
// SAMPLE CODE
//-----------------------------------------------------------------------------
2014-12-22 21:29:39 +08:00
static void ShowExampleAppConsole ( bool * opened ) ;
static void ShowExampleAppLongText ( bool * opened ) ;
static void ShowExampleAppAutoResize ( bool * opened ) ;
static void ShowExampleAppFixedOverlay ( bool * opened ) ;
2015-01-23 08:38:04 +08:00
static void ShowExampleAppCustomRendering ( bool * opened ) ;
2014-11-07 16:22:38 +08:00
2014-08-11 04:58:11 +08:00
// Demonstrate ImGui features (unfortunately this makes this function a little bloated!)
2014-12-22 21:29:39 +08:00
void ImGui : : ShowTestWindow ( bool * opened )
2014-08-11 04:58:11 +08:00
{
2014-08-19 19:09:13 +08:00
static bool no_titlebar = false ;
static bool no_border = true ;
static bool no_resize = false ;
static bool no_move = false ;
static bool no_scrollbar = false ;
2015-02-02 17:49:12 +08:00
static bool no_collapse = false ;
2015-02-22 20:38:46 +08:00
static float bg_alpha = 0.65f ;
2014-08-19 19:09:13 +08:00
2015-02-02 17:49:12 +08:00
// Demonstrate the various window flags. Typically you would just use the default.
ImGuiWindowFlags window_flags = 0 ;
if ( no_titlebar ) window_flags | = ImGuiWindowFlags_NoTitleBar ;
if ( ! no_border ) window_flags | = ImGuiWindowFlags_ShowBorders ;
if ( no_resize ) window_flags | = ImGuiWindowFlags_NoResize ;
if ( no_move ) window_flags | = ImGuiWindowFlags_NoMove ;
if ( no_scrollbar ) window_flags | = ImGuiWindowFlags_NoScrollbar ;
if ( no_collapse ) window_flags | = ImGuiWindowFlags_NoCollapse ;
2015-02-22 20:38:46 +08:00
if ( ! ImGui : : Begin ( " ImGui Test " , opened , ImVec2 ( 550 , 680 ) , bg_alpha , window_flags ) )
2015-01-31 18:20:37 +08:00
{
// Early out if the window is collapsed, as an optimization.
ImGui : : End ( ) ;
return ;
}
2015-02-12 02:34:55 +08:00
ImGui : : PushItemWidth ( ImGui : : GetWindowWidth ( ) * 0.65f ) ; // 2/3 of the space for widget and 1/3 for labels
//ImGui::PushItemWidth(-140); // Right align, keep 140 pixels for labels
2014-08-19 19:09:13 +08:00
ImGui : : Text ( " ImGui says hello. " ) ;
2014-11-30 23:00:07 +08:00
//ImGui::Text("MousePos (%g, %g)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
//ImGui::Text("MouseWheel %d", ImGui::GetIO().MouseWheel);
2015-02-03 17:56:19 +08:00
//ImGui::Text("WantCaptureMouse: %d", ImGui::GetIO().WantCaptureMouse);
//ImGui::Text("WantCaptureKeyboard: %d", ImGui::GetIO().WantCaptureKeyboard);
2014-08-19 19:09:13 +08:00
ImGui : : Spacing ( ) ;
if ( ImGui : : CollapsingHeader ( " Help " ) )
{
2014-11-10 09:29:01 +08:00
ImGui : : TextWrapped ( " This window is being created by the ShowTestWindow() function. Please refer to the code for programming reference. \n \n User Guide: " ) ;
2014-08-19 19:09:13 +08:00
ImGui : : ShowUserGuide ( ) ;
}
if ( ImGui : : CollapsingHeader ( " Window options " ) )
{
2014-08-27 18:38:26 +08:00
ImGui : : Checkbox ( " no titlebar " , & no_titlebar ) ; ImGui : : SameLine ( 150 ) ;
ImGui : : Checkbox ( " no border " , & no_border ) ; ImGui : : SameLine ( 300 ) ;
2014-08-19 19:09:13 +08:00
ImGui : : Checkbox ( " no resize " , & no_resize ) ;
2014-08-27 18:38:26 +08:00
ImGui : : Checkbox ( " no move " , & no_move ) ; ImGui : : SameLine ( 150 ) ;
2015-02-02 17:49:12 +08:00
ImGui : : Checkbox ( " no scrollbar " , & no_scrollbar ) ; ImGui : : SameLine ( 300 ) ;
ImGui : : Checkbox ( " no collapse " , & no_collapse ) ;
2015-02-22 20:38:46 +08:00
ImGui : : SliderFloat ( " bg alpha " , & bg_alpha , 0.0f , 1.0f ) ;
2014-11-29 08:02:46 +08:00
2015-01-18 06:15:29 +08:00
if ( ImGui : : TreeNode ( " Style " ) )
2014-08-19 19:09:13 +08:00
{
ImGui : : ShowStyleEditor ( ) ;
ImGui : : TreePop ( ) ;
}
2015-01-18 06:15:29 +08:00
if ( ImGui : : TreeNode ( " Fonts " ) )
{
2015-01-18 18:46:49 +08:00
ImGui : : TextWrapped ( " Tip: Load fonts with GetIO().Fonts->AddFontFromFileTTF(). " ) ;
for ( size_t i = 0 ; i < ImGui : : GetIO ( ) . Fonts - > Fonts . size ( ) ; i + + )
2015-01-18 06:15:29 +08:00
{
2015-01-18 18:46:49 +08:00
ImFont * font = ImGui : : GetIO ( ) . Fonts - > Fonts [ i ] ;
2015-01-18 06:15:29 +08:00
ImGui : : BulletText ( " Font %d: %.2f pixels, %d glyphs " , i , font - > FontSize , font - > Glyphs . size ( ) ) ;
ImGui : : TreePush ( ( void * ) i ) ;
ImGui : : PushFont ( font ) ;
ImGui : : Text ( " The quick brown fox jumps over the lazy dog " ) ;
ImGui : : PopFont ( ) ;
if ( i > 0 & & ImGui : : Button ( " Set as default " ) )
{
2015-01-18 18:46:49 +08:00
ImGui : : GetIO ( ) . Fonts - > Fonts [ i ] = ImGui : : GetIO ( ) . Fonts - > Fonts [ 0 ] ;
ImGui : : GetIO ( ) . Fonts - > Fonts [ 0 ] = font ;
2015-01-18 06:15:29 +08:00
}
ImGui : : SliderFloat ( " font scale " , & font - > Scale , 0.3f , 2.0f , " %.1f " ) ; // scale only this font
ImGui : : TreePop ( ) ;
}
static float window_scale = 1.0f ;
ImGui : : SliderFloat ( " this window scale " , & window_scale , 0.3f , 2.0f , " %.1f " ) ; // scale only this window
ImGui : : SliderFloat ( " global scale " , & ImGui : : GetIO ( ) . FontGlobalScale , 0.3f , 2.0f , " %.1f " ) ; // scale everything
ImGui : : SetWindowFontScale ( window_scale ) ;
ImGui : : TreePop ( ) ;
}
2014-08-19 19:09:13 +08:00
if ( ImGui : : TreeNode ( " Logging " ) )
{
ImGui : : LogButtons ( ) ;
ImGui : : TreePop ( ) ;
}
}
if ( ImGui : : CollapsingHeader ( " Widgets " ) )
{
static bool a = false ;
if ( ImGui : : Button ( " Button " ) ) { printf ( " Clicked \n " ) ; a ^ = 1 ; }
if ( a )
{
ImGui : : SameLine ( ) ;
ImGui : : Text ( " Thanks for clicking me! " ) ;
}
if ( ImGui : : TreeNode ( " Tree " ) )
{
for ( size_t i = 0 ; i < 5 ; i + + )
{
if ( ImGui : : TreeNode ( ( void * ) i , " Child %d " , i ) )
{
ImGui : : Text ( " blah blah " ) ;
ImGui : : SameLine ( ) ;
if ( ImGui : : SmallButton ( " print " ) )
printf ( " Child %d pressed " , ( int ) i ) ;
ImGui : : TreePop ( ) ;
}
}
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Bullets " ) )
{
ImGui : : BulletText ( " Bullet point 1 " ) ;
ImGui : : BulletText ( " Bullet point 2 \n On multiple lines " ) ;
ImGui : : BulletText ( " Bullet point 3 " ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Colored Text " ) )
{
2014-11-07 13:45:56 +08:00
// Using shortcut. You can use PushStyleColor()/PopStyleColor() for more flexibility.
2014-08-19 19:09:13 +08:00
ImGui : : TextColored ( ImVec4 ( 1.0f , 0.0f , 1.0f , 1.0f ) , " Pink " ) ;
ImGui : : TextColored ( ImVec4 ( 1.0f , 1.0f , 0.0f , 1.0f ) , " Yellow " ) ;
ImGui : : TreePop ( ) ;
}
2014-11-07 13:45:56 +08:00
if ( ImGui : : TreeNode ( " Word Wrapping " ) )
{
// Using shortcut. You can use PushTextWrapPos()/PopTextWrapPos() for more flexibility.
2015-01-12 06:22:46 +08:00
ImGui : : TextWrapped ( " This text should automatically wrap on the edge of the window. The current implementation for text wrapping follows simple rules that works for English and possibly other languages. " ) ;
2014-11-07 13:45:56 +08:00
ImGui : : Spacing ( ) ;
static float wrap_width = 200.0f ;
ImGui : : SliderFloat ( " Wrap width " , & wrap_width , - 20 , 600 , " %.0f " ) ;
ImGui : : Text ( " Test paragraph 1: " ) ;
ImGui : : GetWindowDrawList ( ) - > AddRectFilled ( ImGui : : GetCursorScreenPos ( ) + ImVec2 ( wrap_width , 0.0f ) , ImGui : : GetCursorScreenPos ( ) + ImVec2 ( wrap_width + 10 , ImGui : : GetTextLineHeight ( ) ) , 0xFFFF00FF ) ;
ImGui : : PushTextWrapPos ( ImGui : : GetCursorPos ( ) . x + wrap_width ) ;
ImGui : : Text ( " lazy dog. This paragraph is made to fit within %.0f pixels. The quick brown fox jumps over the lazy dog. " , wrap_width ) ;
ImGui : : GetWindowDrawList ( ) - > AddRect ( ImGui : : GetItemBoxMin ( ) , ImGui : : GetItemBoxMax ( ) , 0xFF00FFFF ) ;
ImGui : : PopTextWrapPos ( ) ;
ImGui : : Text ( " Test paragraph 2: " ) ;
ImGui : : GetWindowDrawList ( ) - > AddRectFilled ( ImGui : : GetCursorScreenPos ( ) + ImVec2 ( wrap_width , 0.0f ) , ImGui : : GetCursorScreenPos ( ) + ImVec2 ( wrap_width + 10 , ImGui : : GetTextLineHeight ( ) ) , 0xFFFF00FF ) ;
ImGui : : PushTextWrapPos ( ImGui : : GetCursorPos ( ) . x + wrap_width ) ;
ImGui : : Text ( " aaaaaaaa bbbbbbbb, cccccccc,dddddddd. eeeeeeee ffffffff. gggggggg!hhhhhhhh " ) ;
ImGui : : GetWindowDrawList ( ) - > AddRect ( ImGui : : GetItemBoxMin ( ) , ImGui : : GetItemBoxMax ( ) , 0xFF00FFFF ) ;
ImGui : : PopTextWrapPos ( ) ;
ImGui : : TreePop ( ) ;
}
2014-09-26 08:06:27 +08:00
if ( ImGui : : TreeNode ( " UTF-8 Text " ) )
{
2015-01-12 06:22:46 +08:00
// UTF-8 test with Japanese characters
2015-01-17 21:40:56 +08:00
// (needs a suitable font, try Arial Unicode or M+ fonts http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html)
2014-09-26 08:06:27 +08:00
// Most compiler appears to support UTF-8 in source code (with Visual Studio you need to save your file as 'UTF-8 without signature')
2014-11-07 13:45:56 +08:00
// However for the sake for maximum portability here we are *not* including raw UTF-8 character in this source file, instead we encode the string with hexadecimal constants.
2015-01-12 06:22:46 +08:00
// In your own application be reasonable and use UTF-8 in source or retrieve the data from file system!
2015-02-01 07:55:47 +08:00
// Note that characters values are preserved even if the font cannot be displayed, so you can safely copy & paste garbled characters into another application.
ImGui : : TextWrapped ( " CJK text will only appears if the font was loaded with the appropriate CJK character ranges. Call io.Font->LoadFromFileTTF() manually to load extra character ranges. " ) ;
2014-09-26 08:06:27 +08:00
ImGui : : Text ( " Hiragana: \xe3 \x81 \x8b \xe3 \x81 \x8d \xe3 \x81 \x8f \xe3 \x81 \x91 \xe3 \x81 \x93 (kakikukeko) " ) ;
ImGui : : Text ( " Kanjis: \xe6 \x97 \xa5 \xe6 \x9c \xac \xe8 \xaa \x9e (nihongo) " ) ;
static char buf [ 32 ] = " \xe6 \x97 \xa5 \xe6 \x9c \xac \xe8 \xaa \x9e " ;
ImGui : : InputText ( " UTF-8 input " , buf , IM_ARRAYSIZE ( buf ) ) ;
ImGui : : TreePop ( ) ;
}
2015-02-09 00:32:51 +08:00
if ( ImGui : : TreeNode ( " Clipping " ) )
{
static ImVec2 size ( 80 , 20 ) ;
ImGui : : TextWrapped ( " On a per-widget basis we are occasionally clipping text if it won't fit in its frame. " ) ;
ImGui : : SliderFloat2 ( " size " , ( float * ) & size , 5.0f , 200.0f ) ;
ImGui : : Button ( " Line 1 hello \n Line 2 clip me! " , size ) ;
ImGui : : TextWrapped ( " Otherwise we are doing coarser clipping + passing a scissor rectangle to the renderer. The system is designed to try minimizing both execution and rendering cost. " ) ;
ImGui : : TreePop ( ) ;
}
2015-01-12 00:30:39 +08:00
if ( ImGui : : TreeNode ( " Images " ) )
{
2015-01-12 01:56:43 +08:00
ImGui : : TextWrapped ( " Below we are displaying the font texture (which is the only texture we have access to in this demo). Use the 'ImTextureID' type as storage to pass pointers or identifier to your own texture data. Hover the texture for a zoomed view! " ) ;
2015-01-12 00:30:39 +08:00
ImVec2 tex_screen_pos = ImGui : : GetCursorScreenPos ( ) ;
2015-01-18 18:46:49 +08:00
float tex_w = ( float ) ImGui : : GetIO ( ) . Fonts - > TexWidth ;
float tex_h = ( float ) ImGui : : GetIO ( ) . Fonts - > TexHeight ;
ImTextureID tex_id = ImGui : : GetIO ( ) . Fonts - > TexID ;
2015-02-01 00:44:55 +08:00
ImGui : : Image ( tex_id , ImVec2 ( tex_w , tex_h ) , ImVec2 ( 0 , 0 ) , ImVec2 ( 1 , 1 ) , ImColor ( 255 , 255 , 255 , 255 ) , ImColor ( 255 , 255 , 255 , 128 ) ) ;
2015-01-12 00:30:39 +08:00
if ( ImGui : : IsItemHovered ( ) )
{
ImGui : : BeginTooltip ( ) ;
float focus_sz = 32.0f ;
float focus_x = ImClamp ( ImGui : : GetMousePos ( ) . x - tex_screen_pos . x - focus_sz * 0.5f , 0.0f , tex_w - focus_sz ) ;
float focus_y = ImClamp ( ImGui : : GetMousePos ( ) . y - tex_screen_pos . y - focus_sz * 0.5f , 0.0f , tex_h - focus_sz ) ;
ImGui : : Text ( " Min: (%.2f, %.2f) " , focus_x , focus_y ) ;
ImGui : : Text ( " Max: (%.2f, %.2f) " , focus_x + focus_sz , focus_y + focus_sz ) ;
ImVec2 uv0 = ImVec2 ( ( focus_x ) / tex_w , ( focus_y ) / tex_h ) ;
ImVec2 uv1 = ImVec2 ( ( focus_x + focus_sz ) / tex_w , ( focus_y + focus_sz ) / tex_h ) ;
2015-02-01 00:44:55 +08:00
ImGui : : Image ( tex_id , ImVec2 ( 128 , 128 ) , uv0 , uv1 , ImColor ( 255 , 255 , 255 , 255 ) , ImColor ( 255 , 255 , 255 , 128 ) ) ;
2015-01-12 00:30:39 +08:00
ImGui : : EndTooltip ( ) ;
}
2015-02-01 00:21:12 +08:00
ImGui : : TextWrapped ( " And now some textured buttons.. " ) ;
static int pressed_count = 0 ;
for ( int i = 0 ; i < 8 ; i + + )
{
if ( i > 0 )
ImGui : : SameLine ( ) ;
ImGui : : PushID ( i ) ;
int frame_padding = - 1 + i ; // -1 padding uses default padding
if ( ImGui : : ImageButton ( tex_id , ImVec2 ( 32 , 32 ) , ImVec2 ( 0 , 0 ) , ImVec2 ( 32.0f / tex_w , 32 / tex_h ) , frame_padding ) )
pressed_count + = 1 ;
ImGui : : PopID ( ) ;
}
ImGui : : Text ( " Pressed %d times. " , pressed_count ) ;
2015-01-12 00:30:39 +08:00
ImGui : : TreePop ( ) ;
}
2015-02-11 03:09:37 +08:00
if ( ImGui : : TreeNode ( " Selectables " ) )
{
if ( ImGui : : TreeNode ( " Basic " ) )
{
static bool selected [ 3 ] = { false , true , false } ;
ImGui : : Selectable ( " 1. I am selectable " , & selected [ 0 ] ) ;
ImGui : : Selectable ( " 2. I am selectable " , & selected [ 1 ] ) ;
ImGui : : Text ( " 3. I am normal text " ) ;
ImGui : : Selectable ( " 4. I am selectable " , & selected [ 2 ] ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Rendering more text into the same block " ) )
{
static bool selected [ 3 ] = { false , false , false } ;
ImGui : : Selectable ( " main.c " , & selected [ 0 ] ) ; ImGui : : SameLine ( 300 ) ; ImGui : : Text ( " 2,345 bytes " ) ;
ImGui : : Selectable ( " Hello.cpp " , & selected [ 1 ] ) ; ImGui : : SameLine ( 300 ) ; ImGui : : Text ( " 12,345 bytes " ) ;
ImGui : : Selectable ( " Hello.h " , & selected [ 2 ] ) ; ImGui : : SameLine ( 300 ) ; ImGui : : Text ( " 2,345 bytes " ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Grid " ) )
{
static bool selected [ 16 ] = { true , false , false , false , false , true , false , false , false , false , true , false , false , false , false , true } ;
for ( int i = 0 ; i < 16 ; i + + )
{
ImGui : : PushID ( i ) ;
if ( ImGui : : Selectable ( " Me " , & selected [ i ] , ImVec2 ( 50 , 50 ) ) )
{
int x = i % 4 , y = i / 4 ;
if ( x > 0 ) selected [ i - 1 ] ^ = 1 ;
if ( x < 3 ) selected [ i + 1 ] ^ = 1 ;
if ( y > 0 ) selected [ i - 4 ] ^ = 1 ;
if ( y < 3 ) selected [ i + 4 ] ^ = 1 ;
}
if ( ( i % 4 ) < 3 ) ImGui : : SameLine ( ) ;
ImGui : : PopID ( ) ;
}
ImGui : : TreePop ( ) ;
}
ImGui : : TreePop ( ) ;
}
2015-02-12 01:39:13 +08:00
if ( ImGui : : TreeNode ( " Filtered Text Input " ) )
{
static char buf1 [ 64 ] = " " ; ImGui : : InputText ( " default " , buf1 , 64 ) ;
static char buf2 [ 64 ] = " " ; ImGui : : InputText ( " decimal " , buf2 , 64 , ImGuiInputTextFlags_CharsDecimal ) ;
2015-02-12 01:46:16 +08:00
static char buf3 [ 64 ] = " " ; ImGui : : InputText ( " hexadecimal " , buf3 , 64 , ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase ) ;
static char buf4 [ 64 ] = " " ; ImGui : : InputText ( " uppercase " , buf4 , 64 , ImGuiInputTextFlags_CharsUppercase ) ;
2015-02-12 02:01:32 +08:00
static char buf5 [ 64 ] = " " ; ImGui : : InputText ( " no blank " , buf5 , 64 , ImGuiInputTextFlags_CharsNoBlank ) ;
struct TextFilters { static int FilterImGuiLetters ( ImGuiTextEditCallbackData * data ) { if ( data - > EventChar < 256 & & strchr ( " imgui " , ( char ) data - > EventChar ) ) return 0 ; return 1 ; } } ;
static char buf6 [ 64 ] = " " ; ImGui : : InputText ( " \" imgui \" letters " , buf6 , 64 , ImGuiInputTextFlags_CallbackCharFilter , TextFilters : : FilterImGuiLetters ) ;
2015-02-12 01:39:13 +08:00
ImGui : : TreePop ( ) ;
}
2014-09-30 18:57:37 +08:00
static bool check = true ;
ImGui : : Checkbox ( " checkbox " , & check ) ;
2014-09-26 08:06:27 +08:00
2014-08-19 19:09:13 +08:00
static int e = 0 ;
ImGui : : RadioButton ( " radio a " , & e , 0 ) ; ImGui : : SameLine ( ) ;
ImGui : : RadioButton ( " radio b " , & e , 1 ) ; ImGui : : SameLine ( ) ;
ImGui : : RadioButton ( " radio c " , & e , 2 ) ;
2015-02-01 01:15:07 +08:00
// Color buttons, demonstrate using PushID() to add unique identifier in the ID stack, and changing style.
for ( int i = 0 ; i < 7 ; i + + )
{
if ( i > 0 ) ImGui : : SameLine ( ) ;
ImGui : : PushID ( i ) ;
ImGui : : PushStyleColor ( ImGuiCol_Button , ImColor : : HSV ( i / 7.0f , 0.6f , 0.6f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonHovered , ImColor : : HSV ( i / 7.0f , 0.7f , 0.7f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonActive , ImColor : : HSV ( i / 7.0f , 0.8f , 0.8f ) ) ;
ImGui : : Button ( " Click " ) ;
ImGui : : PopStyleColor ( 3 ) ;
ImGui : : PopID ( ) ;
}
2015-02-01 05:27:26 +08:00
ImGui : : Text ( " Hover over me " ) ;
2014-11-07 14:49:14 +08:00
if ( ImGui : : IsItemHovered ( ) )
2014-08-19 19:09:13 +08:00
ImGui : : SetTooltip ( " I am a tooltip " ) ;
ImGui : : SameLine ( ) ;
ImGui : : Text ( " - or me " ) ;
2014-11-07 14:49:14 +08:00
if ( ImGui : : IsItemHovered ( ) )
2014-08-19 19:09:13 +08:00
{
ImGui : : BeginTooltip ( ) ;
ImGui : : Text ( " I am a fancy tooltip " ) ;
static float arr [ ] = { 0.6f , 0.1f , 1.0f , 0.5f , 0.92f , 0.1f , 0.2f } ;
ImGui : : PlotLines ( " Curve " , arr , IM_ARRAYSIZE ( arr ) ) ;
ImGui : : EndTooltip ( ) ;
}
2014-11-29 07:08:45 +08:00
// Testing IMGUI_ONCE_UPON_A_FRAME macro
//for (int i = 0; i < 5; i++)
//{
2014-12-01 00:56:35 +08:00
// IMGUI_ONCE_UPON_A_FRAME
// {
// ImGui::Text("This will be displayed only once.");
// }
2014-11-29 07:08:45 +08:00
//}
2014-11-27 06:16:38 +08:00
2014-08-27 18:38:26 +08:00
ImGui : : Separator ( ) ;
2014-08-19 19:09:13 +08:00
static int item = 1 ;
ImGui : : Combo ( " combo " , & item , " aaaa \0 bbbb \0 cccc \0 dddd \0 eeee \0 \0 " ) ;
const char * items [ ] = { " AAAA " , " BBBB " , " CCCC " , " DDDD " , " EEEE " , " FFFF " , " GGGG " , " HHHH " , " IIII " , " JJJJ " , " KKKK " } ;
static int item2 = - 1 ;
ImGui : : Combo ( " combo scroll " , & item2 , items , IM_ARRAYSIZE ( items ) ) ;
static char str0 [ 128 ] = " Hello, world! " ;
static int i0 = 123 ;
static float f0 = 0.001f ;
ImGui : : InputText ( " string " , str0 , IM_ARRAYSIZE ( str0 ) ) ;
ImGui : : InputInt ( " input int " , & i0 ) ;
ImGui : : InputFloat ( " input float " , & f0 , 0.01f , 1.0f ) ;
2014-12-30 23:38:28 +08:00
static float vec4a [ 4 ] = { 0.10f , 0.20f , 0.30f , 0.44f } ;
2014-12-30 23:18:21 +08:00
//ImGui::InputFloat2("input float2", vec4a);
ImGui : : InputFloat3 ( " input float3 " , vec4a ) ;
2014-08-19 19:09:13 +08:00
//ImGui::InputFloat4("input float4", vec4a);
static int i1 = 0 ;
static int i2 = 42 ;
ImGui : : SliderInt ( " int 0..3 " , & i1 , 0 , 3 ) ;
ImGui : : SliderInt ( " int -100..100 " , & i2 , - 100 , 100 ) ;
static float f1 = 1.123f ;
static float f2 = 0 ;
static float f3 = 0 ;
static float f4 = 123456789.0f ;
ImGui : : SliderFloat ( " float " , & f1 , 0.0f , 2.0f ) ;
ImGui : : SliderFloat ( " log float " , & f2 , 0.0f , 10.0f , " %.4f " , 2.0f ) ;
ImGui : : SliderFloat ( " signed log float " , & f3 , - 10.0f , 10.0f , " %.4f " , 3.0f ) ;
ImGui : : SliderFloat ( " unbound float " , & f4 , - FLT_MAX , FLT_MAX , " %.4f " ) ;
static float angle = 0.0f ;
ImGui : : SliderAngle ( " angle " , & angle ) ;
2014-12-30 19:54:04 +08:00
static float vec4b [ 4 ] = { 0.10f , 0.20f , 0.30f , 0.40f } ;
//ImGui::SliderFloat2("slider float2", vec4b, 0.0f, 1.0f);
ImGui : : SliderFloat3 ( " slider float3 " , vec4b , 0.0f , 1.0f ) ;
2014-08-19 19:09:13 +08:00
//ImGui::SliderFloat4("slider float4", vec4b, 0.0f, 1.0f);
2014-12-30 19:54:04 +08:00
//static int vec4i[4] = { 1, 5, 100, 255 };
//ImGui::SliderInt2("slider int2", vec4i, 0, 255);
//ImGui::SliderInt3("slider int3", vec4i, 0, 255);
//ImGui::SliderInt4("slider int4", vec4i, 0, 255);
2014-08-19 19:09:13 +08:00
static float col1 [ 3 ] = { 1.0f , 0.0f , 0.2f } ;
static float col2 [ 4 ] = { 0.4f , 0.7f , 0.0f , 0.5f } ;
ImGui : : ColorEdit3 ( " color 1 " , col1 ) ;
ImGui : : ColorEdit4 ( " color 2 " , col2 ) ;
2015-02-11 08:21:27 +08:00
const char * listbox_items [ ] = { " Apple " , " Banana " , " Cherry " , " Kiwi " , " Mango " , " Orange " , " Pineapple " , " Strawberry " , " Watermelon " } ;
static int listbox_item_current = 1 , listbox_item_current2 = 2 ;
ImGui : : ListBox ( " listbox \n (single select) " , & listbox_item_current , listbox_items , IM_ARRAYSIZE ( listbox_items ) , 4 ) ;
//ImGui::PushItemWidth(-1);
//ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
//ImGui::PopItemWidth();
2014-08-19 19:09:13 +08:00
}
if ( ImGui : : CollapsingHeader ( " Graphs widgets " ) )
{
static float arr [ ] = { 0.6f , 0.1f , 1.0f , 0.5f , 0.92f , 0.1f , 0.2f } ;
ImGui : : PlotLines ( " Frame Times " , arr , IM_ARRAYSIZE ( arr ) ) ;
static bool pause ;
static ImVector < float > values ; if ( values . empty ( ) ) { values . resize ( 100 ) ; memset ( & values . front ( ) , 0 , values . size ( ) * sizeof ( float ) ) ; }
2014-08-20 17:40:31 +08:00
static size_t values_offset = 0 ;
2014-08-19 19:09:13 +08:00
if ( ! pause )
{
2014-11-24 18:02:39 +08:00
// create dummy data at fixed 60 hz rate
2014-08-19 19:09:13 +08:00
static float refresh_time = - 1.0f ;
if ( ImGui : : GetTime ( ) > refresh_time + 1.0f / 60.0f )
{
refresh_time = ImGui : : GetTime ( ) ;
static float phase = 0.0f ;
2014-11-18 15:51:55 +08:00
values [ values_offset ] = cosf ( phase ) ;
2014-08-19 19:09:13 +08:00
values_offset = ( values_offset + 1 ) % values . size ( ) ;
phase + = 0.10f * values_offset ;
}
}
2014-08-20 17:40:31 +08:00
ImGui : : PlotLines ( " Frame Times " , & values . front ( ) , ( int ) values . size ( ) , ( int ) values_offset , " avg 0.0 " , - 1.0f , 1.0f , ImVec2 ( 0 , 70 ) ) ;
2014-08-19 19:09:13 +08:00
ImGui : : SameLine ( ) ; ImGui : : Checkbox ( " pause " , & pause ) ;
ImGui : : PlotHistogram ( " Histogram " , arr , IM_ARRAYSIZE ( arr ) , 0 , NULL , 0.0f , 1.0f , ImVec2 ( 0 , 70 ) ) ;
}
2015-01-05 02:12:30 +08:00
if ( ImGui : : CollapsingHeader ( " Horizontal Layout " ) )
2014-08-19 19:09:13 +08:00
{
// Text
ImGui : : Text ( " Hello " ) ;
ImGui : : SameLine ( ) ;
ImGui : : Text ( " World " ) ;
// Button
if ( ImGui : : Button ( " Banana " ) ) printf ( " Pressed! \n " ) ;
ImGui : : SameLine ( ) ;
ImGui : : Button ( " Apple " ) ;
ImGui : : SameLine ( ) ;
ImGui : : Button ( " Corniflower " ) ;
// Button
2015-01-05 02:12:30 +08:00
ImGui : : Text ( " Small buttons " ) ;
2014-08-19 19:09:13 +08:00
ImGui : : SameLine ( ) ;
2015-01-05 02:12:30 +08:00
ImGui : : SmallButton ( " Like this one " ) ;
2014-08-19 19:09:13 +08:00
ImGui : : SameLine ( ) ;
2015-01-05 02:12:30 +08:00
ImGui : : Text ( " can fit within a text block. " ) ;
2014-08-19 19:09:13 +08:00
// Checkbox
static bool c1 = false , c2 = false , c3 = false , c4 = false ;
ImGui : : Checkbox ( " My " , & c1 ) ;
ImGui : : SameLine ( ) ;
ImGui : : Checkbox ( " Tailor " , & c2 ) ;
ImGui : : SameLine ( ) ;
ImGui : : Checkbox ( " Is " , & c3 ) ;
ImGui : : SameLine ( ) ;
ImGui : : Checkbox ( " Rich " , & c4 ) ;
// SliderFloat
static float f0 = 1.0f , f1 = 2.0f , f2 = 3.0f ;
ImGui : : PushItemWidth ( 80 ) ;
2015-01-05 02:12:30 +08:00
ImGui : : SliderFloat ( " X " , & f0 , 0.0f , 5.0f ) ;
2014-08-19 19:09:13 +08:00
ImGui : : SameLine ( ) ;
2015-01-05 02:12:30 +08:00
ImGui : : SliderFloat ( " Y " , & f1 , 0.0f , 5.0f ) ;
2014-08-19 19:09:13 +08:00
ImGui : : SameLine ( ) ;
2015-01-05 02:12:30 +08:00
ImGui : : SliderFloat ( " Z " , & f2 , 0.0f , 5.0f ) ;
2014-08-19 19:09:13 +08:00
}
if ( ImGui : : CollapsingHeader ( " Child regions " ) )
{
ImGui : : Text ( " Without border " ) ;
static int line = 50 ;
bool goto_line = ImGui : : Button ( " Goto " ) ;
ImGui : : SameLine ( ) ;
ImGui : : PushItemWidth ( 100 ) ;
2014-09-08 23:50:09 +08:00
goto_line | = ImGui : : InputInt ( " ##Line " , & line , 0 , 0 , ImGuiInputTextFlags_EnterReturnsTrue ) ;
2014-08-19 19:09:13 +08:00
ImGui : : PopItemWidth ( ) ;
2014-12-11 03:22:30 +08:00
ImGui : : BeginChild ( " Sub1 " , ImVec2 ( ImGui : : GetWindowWidth ( ) * 0.5f , 300 ) ) ;
2014-08-19 19:09:13 +08:00
for ( int i = 0 ; i < 100 ; i + + )
{
ImGui : : Text ( " %04d: scrollable region " , i ) ;
if ( goto_line & & line = = i )
ImGui : : SetScrollPosHere ( ) ;
}
if ( goto_line & & line > = 100 )
ImGui : : SetScrollPosHere ( ) ;
ImGui : : EndChild ( ) ;
ImGui : : SameLine ( ) ;
2015-02-10 21:00:22 +08:00
ImGui : : PushStyleVar ( ImGuiStyleVar_ChildWindowRounding , 5.0f ) ;
2014-08-19 19:09:13 +08:00
ImGui : : BeginChild ( " Sub2 " , ImVec2 ( 0 , 300 ) , true ) ;
ImGui : : Text ( " With border " ) ;
ImGui : : Columns ( 2 ) ;
for ( int i = 0 ; i < 100 ; i + + )
{
2015-01-31 18:20:37 +08:00
if ( i = = 50 )
ImGui : : NextColumn ( ) ;
2014-08-19 19:09:13 +08:00
char buf [ 32 ] ;
ImFormatString ( buf , IM_ARRAYSIZE ( buf ) , " %08x " , i * 5731 ) ;
ImGui : : Button ( buf ) ;
}
ImGui : : EndChild ( ) ;
2015-02-10 21:00:22 +08:00
ImGui : : PopStyleVar ( ) ;
2014-08-19 19:09:13 +08:00
}
if ( ImGui : : CollapsingHeader ( " Columns " ) )
{
ImGui : : Columns ( 4 , " data " , true ) ;
ImGui : : Text ( " ID " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Name " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Path " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Flags " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Separator ( ) ;
ImGui : : Text ( " 0000 " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Robert " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " /path/robert " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " .... " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " 0001 " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Stephanie " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " /path/stephanie " ) ; ImGui : : NextColumn ( ) ;
2014-11-20 19:31:55 +08:00
ImGui : : Text ( " line 1 " ) ; ImGui : : Text ( " line 2 " ) ; ImGui : : NextColumn ( ) ; // two lines, two items
2014-08-19 19:09:13 +08:00
ImGui : : Text ( " 0002 " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " C64 " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " /path/computer " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " .... " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Columns ( 1 ) ;
ImGui : : Separator ( ) ;
ImGui : : Columns ( 3 , " mixed " ) ;
2014-11-07 14:17:04 +08:00
2014-11-24 18:02:39 +08:00
// Create multiple items in a same cell because switching to next column
2014-08-19 19:09:13 +08:00
static int e = 0 ;
2014-11-20 19:31:55 +08:00
ImGui : : Text ( " Hello " ) ;
ImGui : : Button ( " Banana " ) ;
ImGui : : RadioButton ( " radio a " , & e , 0 ) ;
ImGui : : NextColumn ( ) ;
ImGui : : Text ( " ImGui " ) ;
ImGui : : Button ( " Apple " ) ;
ImGui : : RadioButton ( " radio b " , & e , 1 ) ;
ImGui : : Text ( " An extra line here. " ) ;
ImGui : : NextColumn ( ) ;
ImGui : : Text ( " World! " ) ;
ImGui : : Button ( " Corniflower " ) ;
ImGui : : RadioButton ( " radio c " , & e , 2 ) ;
ImGui : : NextColumn ( ) ;
2014-11-07 14:17:04 +08:00
2014-11-20 19:31:55 +08:00
if ( ImGui : : CollapsingHeader ( " Category A " ) ) ImGui : : Text ( " Blah blah blah " ) ; ImGui : : NextColumn ( ) ;
if ( ImGui : : CollapsingHeader ( " Category B " ) ) ImGui : : Text ( " Blah blah blah " ) ; ImGui : : NextColumn ( ) ;
if ( ImGui : : CollapsingHeader ( " Category C " ) ) ImGui : : Text ( " Blah blah blah " ) ; ImGui : : NextColumn ( ) ;
2014-11-07 14:17:04 +08:00
2014-11-07 16:22:38 +08:00
ImGui : : Columns ( 1 ) ;
2014-08-19 19:09:13 +08:00
ImGui : : Separator ( ) ;
ImGui : : Columns ( 2 , " multiple components " ) ;
static float foo = 1.0f ;
ImGui : : InputFloat ( " red " , & foo , 0.05f , 0 , 3 ) ; ImGui : : NextColumn ( ) ;
static float bar = 1.0f ;
ImGui : : InputFloat ( " blue " , & bar , 0.05f , 0 , 3 ) ; ImGui : : NextColumn ( ) ;
ImGui : : Columns ( 1 ) ;
2014-11-07 16:22:38 +08:00
ImGui : : Separator ( ) ;
2015-02-10 20:37:52 +08:00
ImGui : : Columns ( 2 , " tree items " ) ;
if ( ImGui : : TreeNode ( " Hello " ) ) { ImGui : : BulletText ( " World " ) ; ImGui : : TreePop ( ) ; } ImGui : : NextColumn ( ) ;
if ( ImGui : : TreeNode ( " Bonjour " ) ) { ImGui : : BulletText ( " Monde " ) ; ImGui : : TreePop ( ) ; }
ImGui : : Columns ( 1 ) ;
ImGui : : Separator ( ) ;
2014-11-07 16:22:38 +08:00
ImGui : : Columns ( 2 , " word wrapping " ) ;
ImGui : : TextWrapped ( " The quick brown fox jumps over the lazy dog. " ) ;
2014-11-20 19:31:55 +08:00
ImGui : : Text ( " Hello Left " ) ;
2014-11-07 16:22:38 +08:00
ImGui : : NextColumn ( ) ;
ImGui : : TextWrapped ( " The quick brown fox jumps over the lazy dog. " ) ;
2014-11-20 19:31:55 +08:00
ImGui : : Text ( " Hello Right " ) ;
2014-11-07 16:22:38 +08:00
ImGui : : Columns ( 1 ) ;
2014-11-07 14:17:04 +08:00
2014-08-19 19:09:13 +08:00
ImGui : : Separator ( ) ;
if ( ImGui : : TreeNode ( " Inside a tree.. " ) )
{
if ( ImGui : : TreeNode ( " node 1 (with borders) " ) )
{
ImGui : : Columns ( 4 ) ;
ImGui : : Text ( " aaa " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " bbb " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " ccc " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " ddd " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " eee " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " fff " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " ggg " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " hhh " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Columns ( 1 ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " node 2 (without borders) " ) )
{
ImGui : : Columns ( 4 , NULL , false ) ;
ImGui : : Text ( " aaa " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " bbb " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " ccc " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " ddd " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " eee " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " fff " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " ggg " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " hhh " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Columns ( 1 ) ;
ImGui : : TreePop ( ) ;
}
ImGui : : TreePop ( ) ;
}
}
if ( ImGui : : CollapsingHeader ( " Filtering " ) )
{
static ImGuiTextFilter filter ;
2014-09-25 03:39:39 +08:00
ImGui : : Text ( " Filter usage: \n "
" \" \" display all lines \n "
" \" xxx \" display lines containing \" xxx \" \n "
" \" xxx,yyy \" display lines containing \" xxx \" or \" yyy \" \n "
" \" -xxx \" hide lines containing \" xxx \" " ) ;
filter . Draw ( ) ;
2014-08-19 19:09:13 +08:00
const char * lines [ ] = { " aaa1.c " , " bbb1.c " , " ccc1.c " , " aaa2.cpp " , " bbb2.cpp " , " ccc2.cpp " , " abc.h " , " hello, world " } ;
for ( size_t i = 0 ; i < IM_ARRAYSIZE ( lines ) ; i + + )
if ( filter . PassFilter ( lines [ i ] ) )
ImGui : : BulletText ( " %s " , lines [ i ] ) ;
}
2014-09-30 18:57:37 +08:00
if ( ImGui : : CollapsingHeader ( " Keyboard & Focus " ) )
{
if ( ImGui : : TreeNode ( " Tabbing " ) )
{
ImGui : : Text ( " Use TAB/SHIFT+TAB to cycle thru keyboard editable fields. " ) ;
static char buf [ 32 ] = " dummy " ;
ImGui : : InputText ( " 1 " , buf , IM_ARRAYSIZE ( buf ) ) ;
ImGui : : InputText ( " 2 " , buf , IM_ARRAYSIZE ( buf ) ) ;
ImGui : : InputText ( " 3 " , buf , IM_ARRAYSIZE ( buf ) ) ;
ImGui : : PushAllowKeyboardFocus ( false ) ;
ImGui : : InputText ( " 4 (tab skip) " , buf , IM_ARRAYSIZE ( buf ) ) ;
//ImGui::SameLine(); ImGui::Text("(?)"); if (ImGui::IsHovered()) ImGui::SetTooltip("Use ImGui::PushAllowKeyboardFocus(bool)\nto disable tabbing through certain widgets.");
ImGui : : PopAllowKeyboardFocus ( ) ;
ImGui : : InputText ( " 5 " , buf , IM_ARRAYSIZE ( buf ) ) ;
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNode ( " Focus from code " ) )
{
bool focus_1 = ImGui : : Button ( " Focus on 1 " ) ; ImGui : : SameLine ( ) ;
bool focus_2 = ImGui : : Button ( " Focus on 2 " ) ; ImGui : : SameLine ( ) ;
bool focus_3 = ImGui : : Button ( " Focus on 3 " ) ;
2014-11-07 13:45:56 +08:00
int has_focus = 0 ;
2014-09-30 18:57:37 +08:00
static char buf [ 128 ] = " click on a button to set focus " ;
2014-11-07 13:45:56 +08:00
2014-09-30 18:57:37 +08:00
if ( focus_1 ) ImGui : : SetKeyboardFocusHere ( ) ;
2014-09-30 19:22:58 +08:00
ImGui : : InputText ( " 1 " , buf , IM_ARRAYSIZE ( buf ) ) ;
2015-01-23 06:54:05 +08:00
if ( ImGui : : IsItemActive ( ) ) has_focus = 1 ;
2014-11-07 13:45:56 +08:00
2014-09-30 18:57:37 +08:00
if ( focus_2 ) ImGui : : SetKeyboardFocusHere ( ) ;
2014-09-30 19:22:58 +08:00
ImGui : : InputText ( " 2 " , buf , IM_ARRAYSIZE ( buf ) ) ;
2015-01-23 06:54:05 +08:00
if ( ImGui : : IsItemActive ( ) ) has_focus = 2 ;
2014-11-07 13:45:56 +08:00
2014-09-30 19:22:58 +08:00
ImGui : : PushAllowKeyboardFocus ( false ) ;
2014-09-30 18:57:37 +08:00
if ( focus_3 ) ImGui : : SetKeyboardFocusHere ( ) ;
2014-09-30 19:22:58 +08:00
ImGui : : InputText ( " 3 (tab skip) " , buf , IM_ARRAYSIZE ( buf ) ) ;
2015-01-23 06:54:05 +08:00
if ( ImGui : : IsItemActive ( ) ) has_focus = 3 ;
2014-09-30 19:22:58 +08:00
ImGui : : PopAllowKeyboardFocus ( ) ;
2014-11-07 13:45:56 +08:00
if ( has_focus )
ImGui : : Text ( " Item with focus: %d " , has_focus ) ;
else
ImGui : : Text ( " Item with focus: <none> " ) ;
2015-02-22 00:30:40 +08:00
ImGui : : TextWrapped ( " Cursor & selection are preserved when refocusing last used item in code. " ) ;
2014-09-30 18:57:37 +08:00
ImGui : : TreePop ( ) ;
}
}
2014-11-20 19:54:13 +08:00
static bool show_app_console = false ;
static bool show_app_long_text = false ;
2014-11-22 00:29:56 +08:00
static bool show_app_auto_resize = false ;
2014-12-11 01:13:45 +08:00
static bool show_app_fixed_overlay = false ;
2015-01-23 08:38:04 +08:00
static bool show_app_custom_rendering = false ;
2014-11-07 16:22:38 +08:00
if ( ImGui : : CollapsingHeader ( " App Examples " ) )
{
2014-11-10 09:29:01 +08:00
ImGui : : Checkbox ( " Console " , & show_app_console ) ;
ImGui : : Checkbox ( " Long text display " , & show_app_long_text ) ;
2014-11-22 00:29:56 +08:00
ImGui : : Checkbox ( " Auto-resizing window " , & show_app_auto_resize ) ;
2014-12-11 01:13:45 +08:00
ImGui : : Checkbox ( " Simple overlay " , & show_app_fixed_overlay ) ;
2015-01-23 08:38:04 +08:00
ImGui : : Checkbox ( " Custom rendering " , & show_app_custom_rendering ) ;
2014-08-19 19:09:13 +08:00
}
2014-11-20 19:54:13 +08:00
if ( show_app_console )
ShowExampleAppConsole ( & show_app_console ) ;
if ( show_app_long_text )
ShowExampleAppLongText ( & show_app_long_text ) ;
2014-11-22 00:29:56 +08:00
if ( show_app_auto_resize )
ShowExampleAppAutoResize ( & show_app_auto_resize ) ;
2014-12-11 01:13:45 +08:00
if ( show_app_fixed_overlay )
ShowExampleAppFixedOverlay ( & show_app_fixed_overlay ) ;
2015-01-23 08:38:04 +08:00
if ( show_app_custom_rendering )
ShowExampleAppCustomRendering ( & show_app_custom_rendering ) ;
2014-11-22 00:29:56 +08:00
ImGui : : End ( ) ;
}
2014-12-22 21:29:39 +08:00
static void ShowExampleAppAutoResize ( bool * opened )
2014-11-22 00:29:56 +08:00
{
2014-12-22 21:29:39 +08:00
if ( ! ImGui : : Begin ( " Example: Auto-Resizing Window " , opened , ImVec2 ( 0 , 0 ) , - 1.0f , ImGuiWindowFlags_AlwaysAutoResize ) )
2014-11-22 00:29:56 +08:00
{
ImGui : : End ( ) ;
return ;
}
static int lines = 10 ;
ImGui : : TextWrapped ( " Window will resize every-frame to the size of its content. Note that you don't want to query the window size to output your content because that would create a feedback loop. " ) ;
ImGui : : SliderInt ( " Number of lines " , & lines , 1 , 20 ) ;
for ( int i = 0 ; i < lines ; i + + )
ImGui : : Text ( " %*sThis is line %d " , i * 4 , " " , i ) ; // Pad with space to extend size horizontally
2014-08-19 19:09:13 +08:00
ImGui : : End ( ) ;
2014-08-11 04:58:11 +08:00
}
2014-11-07 16:22:38 +08:00
2014-12-22 21:29:39 +08:00
static void ShowExampleAppFixedOverlay ( bool * opened )
2014-12-11 01:13:45 +08:00
{
2014-12-22 21:29:39 +08:00
if ( ! ImGui : : Begin ( " Example: Fixed Overlay " , opened , ImVec2 ( 0 , 0 ) , 0.3f , ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings ) )
2014-12-11 01:13:45 +08:00
{
ImGui : : End ( ) ;
return ;
}
ImGui : : SetWindowPos ( ImVec2 ( 10 , 10 ) ) ;
ImGui : : Text ( " Simple overlay \n on the top-left side of the screen. " ) ;
ImGui : : Separator ( ) ;
ImGui : : Text ( " Mouse Position: (%.1f,%.1f) " , ImGui : : GetIO ( ) . MousePos . x , ImGui : : GetIO ( ) . MousePos . y ) ;
ImGui : : End ( ) ;
}
2015-01-23 08:38:04 +08:00
static void ShowExampleAppCustomRendering ( bool * opened )
{
if ( ! ImGui : : Begin ( " Example: Custom Rendering " , opened ) )
{
ImGui : : End ( ) ;
return ;
}
// Tip: If you do a lot of custom rendering, you probably want to use your own geometrical types and benefit of overloaded operators, etc.
// Define IM_VEC2_CLASS_EXTRA in imconfig.h to create implicit conversions between your types and ImVec2/ImVec4.
// ImGui defines overloaded operators but they are internal to imgui.cpp and not exposed outside (to avoid messing with your types)
// In this example we aren't using the operators.
static ImVector < ImVec2 > points ;
static bool adding_line = false ;
if ( ImGui : : Button ( " Clear " ) ) points . clear ( ) ;
if ( points . size ( ) > 2 ) { ImGui : : SameLine ( ) ; if ( ImGui : : Button ( " Undo " ) ) points . pop_back ( ) ; }
ImGui : : Text ( " Left-click and drag to add lines " ) ;
ImGui : : Text ( " Right-click to undo " ) ;
ImDrawList * draw_list = ImGui : : GetWindowDrawList ( ) ;
// Here we are using InvisibleButton() as a convenience to 1) advance the cursor and 2) allows us to use IsItemHovered()
// However you can draw directly and poll mouse/keyboard by yourself. You can manipulate the cursor using GetCursorPos() and SetCursorPos().
2015-02-08 22:19:59 +08:00
// If you only use the ImDrawList API, you can notify the owner window of its extends by using SetCursorPos(max).
2015-01-23 08:38:04 +08:00
ImVec2 canvas_pos = ImGui : : GetCursorScreenPos ( ) ; // ImDrawList API uses screen coordinates!
2015-01-29 22:04:49 +08:00
ImVec2 canvas_size = ImVec2 ( ImMax ( 50.0f , ImGui : : GetWindowContentRegionMax ( ) . x - ImGui : : GetCursorPos ( ) . x ) , ImMax ( 50.0f , ImGui : : GetWindowContentRegionMax ( ) . y - ImGui : : GetCursorPos ( ) . y ) ) ; // Resize canvas what's available
2015-01-23 08:38:04 +08:00
draw_list - > AddRect ( canvas_pos , ImVec2 ( canvas_pos . x + canvas_size . x , canvas_pos . y + canvas_size . y ) , 0xFFFFFFFF ) ;
bool adding_preview = false ;
ImGui : : InvisibleButton ( " canvas " , canvas_size ) ;
if ( ImGui : : IsItemHovered ( ) )
{
ImVec2 mouse_pos_in_canvas = ImVec2 ( ImGui : : GetIO ( ) . MousePos . x - canvas_pos . x , ImGui : : GetIO ( ) . MousePos . y - canvas_pos . y ) ;
if ( ! adding_line & & ImGui : : GetIO ( ) . MouseClicked [ 0 ] )
{
points . push_back ( mouse_pos_in_canvas ) ;
adding_line = true ;
}
if ( adding_line )
{
adding_preview = true ;
points . push_back ( mouse_pos_in_canvas ) ;
if ( ! ImGui : : GetIO ( ) . MouseDown [ 0 ] )
adding_line = adding_preview = false ;
}
if ( ImGui : : GetIO ( ) . MouseClicked [ 1 ] & & ! points . empty ( ) )
{
adding_line = false ;
points . pop_back ( ) ;
points . pop_back ( ) ;
}
}
draw_list - > PushClipRect ( ImVec4 ( canvas_pos . x , canvas_pos . y , canvas_pos . x + canvas_size . x , canvas_pos . y + canvas_size . y ) ) ; // clip lines within the canvas (if we resize it, etc.)
for ( int i = 0 ; i < ( int ) points . size ( ) - 1 ; i + = 2 )
draw_list - > AddLine ( ImVec2 ( canvas_pos . x + points [ i ] . x , canvas_pos . y + points [ i ] . y ) , ImVec2 ( canvas_pos . x + points [ i + 1 ] . x , canvas_pos . y + points [ i + 1 ] . y ) , 0xFF00FFFF ) ;
draw_list - > PopClipRect ( ) ;
if ( adding_preview )
points . pop_back ( ) ;
ImGui : : End ( ) ;
}
2014-11-24 07:35:26 +08:00
struct ExampleAppConsole
{
2014-12-31 00:49:39 +08:00
char InputBuf [ 256 ] ;
ImVector < char * > Items ;
bool ScrollToBottom ;
ImVector < char * > History ;
int HistoryPos ; // -1: new line, 0..History.size()-1 browsing history.
ImVector < const char * > Commands ;
2014-11-24 07:35:26 +08:00
2014-12-31 00:49:39 +08:00
ExampleAppConsole ( )
{
ClearLog ( ) ;
HistoryPos = - 1 ;
Commands . push_back ( " HELP " ) ;
Commands . push_back ( " HISTORY " ) ;
Commands . push_back ( " CLEAR " ) ;
Commands . push_back ( " CLASSIFY " ) ; // "classify" is here to provide an example of "C"+[tab] completing to "CL" and displaying matches.
}
~ ExampleAppConsole ( )
{
ClearLog ( ) ;
for ( size_t i = 0 ; i < Items . size ( ) ; i + + )
ImGui : : MemFree ( History [ i ] ) ;
}
void ClearLog ( )
2014-11-24 07:35:26 +08:00
{
for ( size_t i = 0 ; i < Items . size ( ) ; i + + )
ImGui : : MemFree ( Items [ i ] ) ;
Items . clear ( ) ;
2014-12-31 00:49:39 +08:00
ScrollToBottom = true ;
2014-11-24 07:35:26 +08:00
}
2014-12-01 00:56:35 +08:00
void AddLog ( const char * fmt , . . . )
2014-11-24 07:35:26 +08:00
{
2014-12-31 00:49:39 +08:00
char buf [ 1024 ] ;
2014-11-24 07:35:26 +08:00
va_list args ;
va_start ( args , fmt ) ;
ImFormatStringV ( buf , IM_ARRAYSIZE ( buf ) , fmt , args ) ;
va_end ( args ) ;
Items . push_back ( ImStrdup ( buf ) ) ;
2014-12-31 00:49:39 +08:00
ScrollToBottom = true ;
}
void Run ( const char * title , bool * opened )
{
if ( ! ImGui : : Begin ( title , opened , ImVec2 ( 520 , 600 ) ) )
{
ImGui : : End ( ) ;
return ;
}
2015-01-12 06:22:46 +08:00
ImGui : : TextWrapped ( " This example implements a console with basic coloring, completion and history. A more elaborate implementation may want to store entries along with extra data such as timestamp, emitter, etc. " ) ;
2014-12-31 00:49:39 +08:00
ImGui : : TextWrapped ( " Enter 'HELP' for help, press TAB to use text completion. " ) ;
// TODO: display from bottom
// TODO: clip manually
2015-02-08 22:19:59 +08:00
if ( ImGui : : SmallButton ( " Add Dummy Text " ) ) { AddLog ( " %d some text " , Items . size ( ) ) ; AddLog ( " some more text " ) ; AddLog ( " display very important message here! " ) ; } ImGui : : SameLine ( ) ;
2014-12-31 00:49:39 +08:00
if ( ImGui : : SmallButton ( " Add Dummy Error " ) ) AddLog ( " [error] something went wrong " ) ; ImGui : : SameLine ( ) ;
if ( ImGui : : SmallButton ( " Clear " ) ) ClearLog ( ) ;
ImGui : : Separator ( ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_FramePadding , ImVec2 ( 0 , 0 ) ) ;
static ImGuiTextFilter filter ;
filter . Draw ( " Filter ( \" incl,-excl \" ) ( \" error \" ) " , 180 ) ;
if ( ImGui : : IsItemHovered ( ) ) ImGui : : SetKeyboardFocusHere ( - 1 ) ; // Auto focus on hover
ImGui : : PopStyleVar ( ) ;
ImGui : : Separator ( ) ;
// Display every line as a separate entry so we can change their color or add custom widgets. If you only want raw text you can use ImGui::TextUnformatted(log.begin(), log.end());
2015-02-08 22:19:59 +08:00
// NB- if you have thousands of entries this approach may be too inefficient. You can seek and display only the lines that are visible - CalcListClipping() is a helper to compute this information.
// If your items are of variable size you may want to implement code similar to what CalcListClipping() does. Or split your data into fixed height items to allow random-seeking into your list.
2015-02-08 21:37:20 +08:00
ImGui : : BeginChild ( " ScrollingRegion " , ImVec2 ( 0 , - ImGui : : GetTextLineHeightWithSpacing ( ) * 2 ) ) ;
2014-12-31 00:49:39 +08:00
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( 4 , 1 ) ) ; // Tighten spacing
for ( size_t i = 0 ; i < Items . size ( ) ; i + + )
{
const char * item = Items [ i ] ;
if ( ! filter . PassFilter ( item ) )
continue ;
ImVec4 col ( 1 , 1 , 1 , 1 ) ; // A better implement may store a type per-item. For the sample let's just parse the text.
if ( strstr ( item , " [error] " ) ) col = ImVec4 ( 1.0f , 0.4f , 0.4f , 1.0f ) ;
else if ( strncmp ( item , " # " , 2 ) = = 0 ) col = ImVec4 ( 1.0f , 0.8f , 0.6f , 1.0f ) ;
ImGui : : PushStyleColor ( ImGuiCol_Text , col ) ;
ImGui : : TextUnformatted ( item ) ;
ImGui : : PopStyleColor ( ) ;
}
if ( ScrollToBottom )
ImGui : : SetScrollPosHere ( ) ;
ScrollToBottom = false ;
ImGui : : PopStyleVar ( ) ;
ImGui : : EndChild ( ) ;
ImGui : : Separator ( ) ;
// Command-line
if ( ImGui : : InputText ( " Input " , InputBuf , IM_ARRAYSIZE ( InputBuf ) , ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory , & TextEditCallbackStub , ( void * ) this ) )
{
char * input_end = InputBuf + strlen ( InputBuf ) ;
while ( input_end > InputBuf & & input_end [ - 1 ] = = ' ' ) input_end - - ; * input_end = 0 ;
if ( InputBuf [ 0 ] )
ExecCommand ( InputBuf ) ;
strcpy ( InputBuf , " " ) ;
}
if ( ImGui : : IsItemHovered ( ) ) ImGui : : SetKeyboardFocusHere ( - 1 ) ; // Auto focus on hover
ImGui : : End ( ) ;
}
void ExecCommand ( const char * command_line )
{
AddLog ( " # %s \n " , command_line ) ;
// Insert into history. First find match and delete it so it can be pushed to the back. This isn't trying to be smart or optimal.
HistoryPos = - 1 ;
for ( int i = ( int ) History . size ( ) - 1 ; i > = 0 ; i - - )
if ( ImStricmp ( History [ i ] , command_line ) = = 0 )
{
ImGui : : MemFree ( History [ i ] ) ;
History . erase ( History . begin ( ) + i ) ;
break ;
}
History . push_back ( ImStrdup ( command_line ) ) ;
// Process command
if ( ImStricmp ( command_line , " CLEAR " ) = = 0 )
{
ClearLog ( ) ;
}
else if ( ImStricmp ( command_line , " HELP " ) = = 0 )
{
AddLog ( " Commands: " ) ;
for ( size_t i = 0 ; i < Commands . size ( ) ; i + + )
AddLog ( " - %s " , Commands [ i ] ) ;
}
else if ( ImStricmp ( command_line , " HISTORY " ) = = 0 )
{
for ( size_t i = History . size ( ) > = 10 ? History . size ( ) - 10 : 0 ; i < History . size ( ) ; i + + )
AddLog ( " %3d: %s \n " , i , History [ i ] ) ;
}
else
{
AddLog ( " Unknown command: '%s' \n " , command_line ) ;
}
}
2015-02-12 01:39:13 +08:00
static int TextEditCallbackStub ( ImGuiTextEditCallbackData * data )
2014-12-31 00:49:39 +08:00
{
ExampleAppConsole * console = ( ExampleAppConsole * ) data - > UserData ;
2015-02-12 01:39:13 +08:00
return console - > TextEditCallback ( data ) ;
2014-11-24 07:35:26 +08:00
}
2015-02-12 01:39:13 +08:00
int TextEditCallback ( ImGuiTextEditCallbackData * data )
2014-11-24 07:35:26 +08:00
{
2014-11-27 06:16:38 +08:00
//AddLog("cursor: %d, selection: %d-%d", data->CursorPos, data->SelectionStart, data->SelectionEnd);
2015-02-12 01:39:13 +08:00
switch ( data - > EventFlag )
2014-11-24 07:35:26 +08:00
{
2015-02-12 01:39:13 +08:00
case ImGuiInputTextFlags_CallbackCompletion :
2014-11-24 07:35:26 +08:00
{
// Example of TEXT COMPLETION
// Locate beginning of current word
const char * word_end = data - > Buf + data - > CursorPos ;
const char * word_start = word_end ;
while ( word_start > data - > Buf )
{
const char c = word_start [ - 1 ] ;
if ( c = = ' ' | | c = = ' \t ' | | c = = ' , ' | | c = = ' ; ' )
break ;
word_start - - ;
}
// Build a list of candidates
ImVector < const char * > candidates ;
2014-12-31 00:49:39 +08:00
for ( size_t i = 0 ; i < Commands . size ( ) ; i + + )
if ( ImStrnicmp ( Commands [ i ] , word_start , ( int ) ( word_end - word_start ) ) = = 0 )
candidates . push_back ( Commands [ i ] ) ;
2014-11-24 07:35:26 +08:00
if ( candidates . size ( ) = = 0 )
{
// No match
AddLog ( " No match for \" %.*s \" ! \n " , word_end - word_start , word_start ) ;
}
else if ( candidates . size ( ) = = 1 )
{
// Single match. Delete the beginning of the word and replace it entirely so we've got nice casing
2014-12-06 20:49:46 +08:00
data - > DeleteChars ( ( int ) ( word_start - data - > Buf ) , ( int ) ( word_end - word_start ) ) ;
2014-11-24 07:35:26 +08:00
data - > InsertChars ( data - > CursorPos , candidates [ 0 ] ) ;
data - > InsertChars ( data - > CursorPos , " " ) ;
}
else
{
// Multiple matches. Complete as much as we can, so inputing "C" will complete to "CL" and display "CLEAR" and "CLASSIFY"
2014-12-06 20:49:46 +08:00
int match_len = ( int ) ( word_end - word_start ) ;
2015-02-02 17:06:51 +08:00
for ( ; ; )
2014-11-24 07:35:26 +08:00
{
2014-11-30 20:21:50 +08:00
int c = 0 ;
2014-11-24 07:35:26 +08:00
bool all_candidates_matches = true ;
for ( size_t i = 0 ; i < candidates . size ( ) & & all_candidates_matches ; i + + )
if ( i = = 0 )
c = toupper ( candidates [ i ] [ match_len ] ) ;
else if ( c ! = toupper ( candidates [ i ] [ match_len ] ) )
all_candidates_matches = false ;
if ( ! all_candidates_matches )
break ;
match_len + + ;
}
2014-11-27 06:16:38 +08:00
if ( match_len > 0 )
{
2014-12-06 20:49:46 +08:00
data - > DeleteChars ( ( int ) ( word_start - data - > Buf ) , ( int ) ( word_end - word_start ) ) ;
2014-11-27 06:16:38 +08:00
data - > InsertChars ( data - > CursorPos , candidates [ 0 ] , candidates [ 0 ] + match_len ) ;
}
2014-11-24 07:35:26 +08:00
// List matches
AddLog ( " Possible matches: \n " ) ;
for ( size_t i = 0 ; i < candidates . size ( ) ; i + + )
AddLog ( " - %s \n " , candidates [ i ] ) ;
}
break ;
}
2015-02-12 01:39:13 +08:00
case ImGuiInputTextFlags_CallbackHistory :
2014-12-31 00:49:39 +08:00
{
// Example of HISTORY
const int prev_history_pos = HistoryPos ;
if ( data - > EventKey = = ImGuiKey_UpArrow )
{
if ( HistoryPos = = - 1 )
2015-01-14 07:19:11 +08:00
HistoryPos = ( int ) ( History . size ( ) - 1 ) ;
2014-12-31 00:49:39 +08:00
else if ( HistoryPos > 0 )
HistoryPos - - ;
}
else if ( data - > EventKey = = ImGuiKey_DownArrow )
{
if ( HistoryPos ! = - 1 )
if ( + + HistoryPos > = ( int ) History . size ( ) )
HistoryPos = - 1 ;
}
// A better implementation would preserve the data on the current input line along with cursor position.
if ( prev_history_pos ! = HistoryPos )
{
ImFormatString ( data - > Buf , data - > BufSize , " %s " , ( HistoryPos > = 0 ) ? History [ HistoryPos ] : " " ) ;
data - > BufDirty = true ;
2015-01-14 07:19:11 +08:00
data - > CursorPos = data - > SelectionStart = data - > SelectionEnd = ( int ) strlen ( data - > Buf ) ;
2014-12-31 00:49:39 +08:00
}
}
2014-11-24 07:35:26 +08:00
}
2015-02-12 01:39:13 +08:00
return 0 ;
2014-11-24 07:35:26 +08:00
}
} ;
2014-12-22 21:29:39 +08:00
static void ShowExampleAppConsole ( bool * opened )
2014-11-07 16:22:38 +08:00
{
2014-11-24 07:35:26 +08:00
static ExampleAppConsole console ;
2014-12-31 00:49:39 +08:00
console . Run ( " Example: Console " , opened ) ;
2014-11-07 16:22:38 +08:00
}
2014-12-22 21:29:39 +08:00
static void ShowExampleAppLongText ( bool * opened )
2014-11-10 09:29:01 +08:00
{
2014-12-22 21:29:39 +08:00
if ( ! ImGui : : Begin ( " Example: Long text display " , opened , ImVec2 ( 520 , 600 ) ) )
2014-11-10 09:29:01 +08:00
{
ImGui : : End ( ) ;
return ;
}
2014-08-11 04:58:11 +08:00
2015-02-08 22:32:58 +08:00
static int test_type = 0 ;
2014-11-10 09:29:01 +08:00
static ImGuiTextBuffer log ;
static int lines = 0 ;
ImGui : : Text ( " Printing unusually long amount of text. " ) ;
2015-02-09 00:39:34 +08:00
ImGui : : Combo ( " Test type " , & test_type , " Single call to TextUnformatted() \0 Multiple calls to Text(), clipped manually \0 Multiple calls to Text(), not clipped " ) ;
2014-11-10 09:29:01 +08:00
ImGui : : Text ( " Buffer contents: %d lines, %d bytes " , lines , log . size ( ) ) ;
if ( ImGui : : Button ( " Clear " ) ) { log . clear ( ) ; lines = 0 ; }
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Add 1000 lines " ) )
{
for ( int i = 0 ; i < 1000 ; i + + )
log . append ( " %i The quick brown fox jumps over the lazy dog \n " , lines + i ) ;
lines + = 1000 ;
}
ImGui : : BeginChild ( " Log " ) ;
2015-02-08 22:32:58 +08:00
switch ( test_type )
{
case 0 :
// Single call to TextUnformatted() with a big buffer
ImGui : : TextUnformatted ( log . begin ( ) , log . end ( ) ) ;
break ;
case 1 :
2015-02-09 00:39:34 +08:00
// Multiple calls to Text(), manually coarsely clipped - demonstrate how to use the CalcListClipping() helper.
2015-02-08 22:32:58 +08:00
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( 0 , 0 ) ) ;
int display_start , display_end ;
ImGui : : CalcListClipping ( lines , ImGui : : GetTextLineHeight ( ) , & display_start , & display_end ) ;
ImGui : : SetCursorPosY ( ImGui : : GetCursorPosY ( ) + ( display_start ) * ImGui : : GetTextLineHeight ( ) ) ;
for ( int i = display_start ; i < display_end ; i + + )
ImGui : : Text ( " %i The quick brown fox jumps over the lazy dog \n " , i ) ;
ImGui : : SetCursorPosY ( ImGui : : GetCursorPosY ( ) + ( lines - display_end ) * ImGui : : GetTextLineHeight ( ) ) ;
ImGui : : PopStyleVar ( ) ;
break ;
case 2 :
2015-02-09 00:39:34 +08:00
// Multiple calls to Text(), not clipped
2015-02-08 22:32:58 +08:00
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( 0 , 0 ) ) ;
for ( int i = 0 ; i < lines ; i + + )
ImGui : : Text ( " %i The quick brown fox jumps over the lazy dog \n " , i ) ;
ImGui : : PopStyleVar ( ) ;
break ;
}
2014-11-10 09:29:01 +08:00
ImGui : : EndChild ( ) ;
ImGui : : End ( ) ;
}
// End of Sample code
2014-08-11 04:58:11 +08:00
//-----------------------------------------------------------------------------
2015-01-18 19:19:11 +08:00
// FONT DATA
2014-08-11 04:58:11 +08:00
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
2015-01-18 19:19:11 +08:00
// ProggyClean.ttf
// Copyright (c) 2004, 2005 Tristan Grimmer
// MIT license (see License.txt in http://www.upperbounds.net/download/ProggyClean.ttf.zip)
// Download and more information at http://upperbounds.net
2014-08-11 04:58:11 +08:00
//-----------------------------------------------------------------------------
2015-01-18 19:19:11 +08:00
// Compressed with stb_compress() then converted to a C array.
2015-01-09 07:35:01 +08:00
// Decompressor from stb.h (public domain) by Sean Barrett
// https://github.com/nothings/stb/blob/master/stb.h
2015-01-18 19:19:11 +08:00
//-----------------------------------------------------------------------------
2014-08-11 04:58:11 +08:00
2015-01-09 07:35:01 +08:00
static unsigned int stb_decompress_length ( unsigned char * input )
{
return ( input [ 8 ] < < 24 ) + ( input [ 9 ] < < 16 ) + ( input [ 10 ] < < 8 ) + input [ 11 ] ;
}
2015-01-18 19:19:11 +08:00
static unsigned char * stb__barrier , * stb__barrier2 , * stb__barrier3 , * stb__barrier4 ;
2015-01-09 07:35:01 +08:00
static unsigned char * stb__dout ;
static void stb__match ( unsigned char * data , unsigned int length )
{
// INVERSE of memmove... write each byte before copying the next...
assert ( stb__dout + length < = stb__barrier ) ;
if ( stb__dout + length > stb__barrier ) { stb__dout + = length ; return ; }
if ( data < stb__barrier4 ) { stb__dout = stb__barrier + 1 ; return ; }
while ( length - - ) * stb__dout + + = * data + + ;
}
static void stb__lit ( unsigned char * data , unsigned int length )
{
assert ( stb__dout + length < = stb__barrier ) ;
if ( stb__dout + length > stb__barrier ) { stb__dout + = length ; return ; }
if ( data < stb__barrier2 ) { stb__dout = stb__barrier + 1 ; return ; }
memcpy ( stb__dout , data , length ) ;
stb__dout + = length ;
}
# define stb__in2(x) ((i[x] << 8) + i[(x)+1])
# define stb__in3(x) ((i[x] << 16) + stb__in2((x)+1))
# define stb__in4(x) ((i[x] << 24) + stb__in3((x)+1))
static unsigned char * stb_decompress_token ( unsigned char * i )
{
if ( * i > = 0x20 ) { // use fewer if's for cases that expand small
if ( * i > = 0x80 ) stb__match ( stb__dout - i [ 1 ] - 1 , i [ 0 ] - 0x80 + 1 ) , i + = 2 ;
else if ( * i > = 0x40 ) stb__match ( stb__dout - ( stb__in2 ( 0 ) - 0x4000 + 1 ) , i [ 2 ] + 1 ) , i + = 3 ;
else /* *i >= 0x20 */ stb__lit ( i + 1 , i [ 0 ] - 0x20 + 1 ) , i + = 1 + ( i [ 0 ] - 0x20 + 1 ) ;
} else { // more ifs for cases that expand large, since overhead is amortized
if ( * i > = 0x18 ) stb__match ( stb__dout - ( stb__in3 ( 0 ) - 0x180000 + 1 ) , i [ 3 ] + 1 ) , i + = 4 ;
else if ( * i > = 0x10 ) stb__match ( stb__dout - ( stb__in3 ( 0 ) - 0x100000 + 1 ) , stb__in2 ( 3 ) + 1 ) , i + = 5 ;
else if ( * i > = 0x08 ) stb__lit ( i + 2 , stb__in2 ( 0 ) - 0x0800 + 1 ) , i + = 2 + ( stb__in2 ( 0 ) - 0x0800 + 1 ) ;
else if ( * i = = 0x07 ) stb__lit ( i + 3 , stb__in2 ( 1 ) + 1 ) , i + = 3 + ( stb__in2 ( 1 ) + 1 ) ;
else if ( * i = = 0x06 ) stb__match ( stb__dout - ( stb__in3 ( 1 ) + 1 ) , i [ 4 ] + 1 ) , i + = 5 ;
else if ( * i = = 0x04 ) stb__match ( stb__dout - ( stb__in3 ( 1 ) + 1 ) , stb__in2 ( 4 ) + 1 ) , i + = 6 ;
}
return i ;
}
2014-08-11 04:58:11 +08:00
2015-01-09 07:35:01 +08:00
static unsigned int stb_adler32 ( unsigned int adler32 , unsigned char * buffer , unsigned int buflen )
2014-08-11 04:58:11 +08:00
{
2015-01-09 07:35:01 +08:00
const unsigned long ADLER_MOD = 65521 ;
unsigned long s1 = adler32 & 0xffff , s2 = adler32 > > 16 ;
unsigned long blocklen , i ;
blocklen = buflen % 5552 ;
while ( buflen ) {
for ( i = 0 ; i + 7 < blocklen ; i + = 8 ) {
s1 + = buffer [ 0 ] , s2 + = s1 ;
s1 + = buffer [ 1 ] , s2 + = s1 ;
s1 + = buffer [ 2 ] , s2 + = s1 ;
s1 + = buffer [ 3 ] , s2 + = s1 ;
s1 + = buffer [ 4 ] , s2 + = s1 ;
s1 + = buffer [ 5 ] , s2 + = s1 ;
s1 + = buffer [ 6 ] , s2 + = s1 ;
s1 + = buffer [ 7 ] , s2 + = s1 ;
buffer + = 8 ;
}
for ( ; i < blocklen ; + + i )
s1 + = * buffer + + , s2 + = s1 ;
s1 % = ADLER_MOD , s2 % = ADLER_MOD ;
buflen - = blocklen ;
blocklen = 5552 ;
}
2015-02-02 16:51:45 +08:00
return ( unsigned int ) ( s2 < < 16 ) + ( unsigned int ) s1 ;
2014-08-11 04:58:11 +08:00
}
2015-01-09 07:35:01 +08:00
static unsigned int stb_decompress ( unsigned char * output , unsigned char * i , unsigned int length )
{
unsigned int olen ;
if ( stb__in4 ( 0 ) ! = 0x57bC0000 ) return 0 ;
if ( stb__in4 ( 4 ) ! = 0 ) return 0 ; // error! stream is > 4GB
olen = stb_decompress_length ( i ) ;
stb__barrier2 = i ;
stb__barrier3 = i + length ;
stb__barrier = output + olen ;
stb__barrier4 = output ;
i + = 16 ;
stb__dout = output ;
2015-02-02 17:06:51 +08:00
for ( ; ; ) {
2015-01-09 07:35:01 +08:00
unsigned char * old_i = i ;
i = stb_decompress_token ( i ) ;
if ( i = = old_i ) {
if ( * i = = 0x05 & & i [ 1 ] = = 0xfa ) {
assert ( stb__dout = = output + olen ) ;
if ( stb__dout ! = output + olen ) return 0 ;
if ( stb_adler32 ( 1 , output , olen ) ! = ( unsigned int ) stb__in4 ( 2 ) )
return 0 ;
return olen ;
} else {
assert ( 0 ) ; /* NOTREACHED */
return 0 ;
}
}
assert ( stb__dout < = output + olen ) ;
if ( stb__dout > output + olen )
return 0 ;
}
}
static const unsigned int proggy_clean_ttf_compressed_size = 9583 ;
static const unsigned int proggy_clean_ttf_compressed_data [ 9584 / 4 ] =
{
0x0000bc57 , 0x00000000 , 0xf8a00000 , 0x00000400 , 0x00010037 , 0x000c0000 , 0x00030080 , 0x2f534f40 , 0x74eb8832 , 0x01000090 , 0x2c158248 , 0x616d634e ,
0x23120270 , 0x03000075 , 0x241382a0 , 0x74766352 , 0x82178220 , 0xfc042102 , 0x02380482 , 0x66796c67 , 0x5689af12 , 0x04070000 , 0x80920000 , 0x64616568 ,
0xd36691d7 , 0xcc201b82 , 0x36210382 , 0x27108268 , 0xc3014208 , 0x04010000 , 0x243b0f82 , 0x78746d68 , 0x807e008a , 0x98010000 , 0x06020000 , 0x61636f6c ,
0xd8b0738c , 0x82050000 , 0x0402291e , 0x7078616d , 0xda00ae01 , 0x28201f82 , 0x202c1082 , 0x656d616e , 0x96bb5925 , 0x84990000 , 0x9e2c1382 , 0x74736f70 ,
0xef83aca6 , 0x249b0000 , 0xd22c3382 , 0x70657270 , 0x12010269 , 0xf4040000 , 0x08202f82 , 0x012ecb84 , 0x553c0000 , 0x0f5fd5e9 , 0x0300f53c , 0x00830008 ,
0x7767b722 , 0x002b3f82 , 0xa692bd00 , 0xfe0000d7 , 0x83800380 , 0x21f1826f , 0x00850002 , 0x41820120 , 0x40fec026 , 0x80030000 , 0x05821083 , 0x07830120 ,
0x0221038a , 0x24118200 , 0x90000101 , 0x82798200 , 0x00022617 , 0x00400008 , 0x2009820a , 0x82098276 , 0x82002006 , 0x9001213b , 0x0223c883 , 0x828a02bc ,
0x858f2010 , 0xc5012507 , 0x00023200 , 0x04210083 , 0x91058309 , 0x6c412b03 , 0x40007374 , 0xac200000 , 0x00830008 , 0x01000523 , 0x834d8380 , 0x80032103 ,
0x012101bf , 0x23b88280 , 0x00800000 , 0x0b830382 , 0x07820120 , 0x83800021 , 0x88012001 , 0x84002009 , 0x2005870f , 0x870d8301 , 0x2023901b , 0x83199501 ,
0x82002015 , 0x84802000 , 0x84238267 , 0x88002027 , 0x8561882d , 0x21058211 , 0x13880000 , 0x01800022 , 0x05850d85 , 0x0f828020 , 0x03208384 , 0x03200582 ,
0x47901b84 , 0x1b850020 , 0x1f821d82 , 0x3f831d88 , 0x3f410383 , 0x84058405 , 0x210982cd , 0x09830000 , 0x03207789 , 0xf38a1384 , 0x01203782 , 0x13872384 ,
0x0b88c983 , 0x0d898f84 , 0x00202982 , 0x23900383 , 0x87008021 , 0x83df8301 , 0x86118d03 , 0x863f880d , 0x8f35880f , 0x2160820f , 0x04830300 , 0x1c220382 ,
0x05820100 , 0x4c000022 , 0x09831182 , 0x04001c24 , 0x11823000 , 0x0800082e , 0x00000200 , 0xff007f00 , 0xffffac20 , 0x00220982 , 0x09848100 , 0xdf216682 ,
0x843586d5 , 0x06012116 , 0x04400684 , 0xa58120d7 , 0x00b127d8 , 0x01b88d01 , 0x2d8685ff , 0xc100c621 , 0xf4be0801 , 0x9e011c01 , 0x88021402 , 0x1403fc02 ,
0x9c035803 , 0x1404de03 , 0x50043204 , 0xa2046204 , 0x66051605 , 0x1206bc05 , 0xd6067406 , 0x7e073807 , 0x4e08ec07 , 0x96086c08 , 0x1009d008 , 0x88094a09 ,
0x800a160a , 0x560b040b , 0x2e0cc80b , 0xea0c820c , 0xa40d5e0d , 0x500eea0d , 0x280f960e , 0x1210b00f , 0xe0107410 , 0xb6115211 , 0x6e120412 , 0x4c13c412 ,
0xf613ac13 , 0xae145814 , 0x4015ea14 , 0xa6158015 , 0x1216b815 , 0xc6167e16 , 0x8e173417 , 0x5618e017 , 0xee18ba18 , 0x96193619 , 0x481ad419 , 0xf01a9c1a ,
0xc81b5c1b , 0x4c1c041c , 0xea1c961c , 0x921d2a1d , 0x401ed21d , 0xe01e8e1e , 0x761f241f , 0xa61fa61f , 0x01821020 , 0x8a202e34 , 0xc820b220 , 0x74211421 ,
0xee219821 , 0x86226222 , 0x01820c23 , 0x83238021 , 0x23983c01 , 0x24d823b0 , 0x244a2400 , 0x24902468 , 0x250625ae , 0x25822560 , 0x26f825f8 , 0x82aa2658 ,
0xd8be0801 , 0x9a274027 , 0x68280a28 , 0x0e29a828 , 0xb8292029 , 0x362af829 , 0x602a602a , 0x2a2b022b , 0xac2b5e2b , 0x202ce62b , 0x9a2c342c , 0x5c2d282d ,
0xaa2d782d , 0x262ee82d , 0x262fa62e , 0xf42fb62f , 0xc8305e30 , 0xb4313e31 , 0x9e321e32 , 0x82331e33 , 0x5c34ee33 , 0x3a35ce34 , 0xd4358635 , 0x72362636 ,
0x7637e636 , 0x3a38d837 , 0x1239a638 , 0xae397439 , 0x9a3a2e3a , 0x7c3b063b , 0x3a3ce83b , 0x223d963c , 0xec3d863d , 0xc63e563e , 0x9a3f2a3f , 0x6a401240 ,
0x3641d040 , 0x0842a241 , 0x7a424042 , 0xf042b842 , 0xcc436243 , 0x8a442a44 , 0x5845ee44 , 0xe245b645 , 0xb4465446 , 0x7a471447 , 0x5448da47 , 0x4049c648 ,
0x15462400 , 0x034d0808 , 0x0b000700 , 0x13000f00 , 0x1b001700 , 0x23001f00 , 0x2b002700 , 0x33002f00 , 0x3b003700 , 0x43003f00 , 0x4b004700 , 0x53004f00 ,
0x5b005700 , 0x63005f00 , 0x6b006700 , 0x73006f00 , 0x7b007700 , 0x83007f00 , 0x8b008700 , 0x00008f00 , 0x15333511 , 0x20039631 , 0x20178205 , 0xd3038221 ,
0x20739707 , 0x25008580 , 0x028080fc , 0x05be8080 , 0x04204a85 , 0x05ce0685 , 0x0107002a , 0x02000080 , 0x00000400 , 0x250d8b41 , 0x33350100 , 0x03920715 ,
0x13820320 , 0x858d0120 , 0x0e8d0320 , 0xff260d83 , 0x00808000 , 0x54820106 , 0x04800223 , 0x845b8c80 , 0x41332059 , 0x078b068f , 0x82000121 , 0x82fe2039 ,
0x84802003 , 0x83042004 , 0x23598a0e , 0x00180000 , 0x03210082 , 0x42ab9080 , 0x73942137 , 0x2013bb41 , 0x8f978205 , 0x2027a39b , 0x20b68801 , 0x84b286fd ,
0x91c88407 , 0x41032011 , 0x11a51130 , 0x15000027 , 0x80ff8000 , 0x11af4103 , 0x841b0341 , 0x8bd983fd , 0x9be99bc9 , 0x8343831b , 0x21f1821f , 0xb58300ff ,
0x0f84e889 , 0xf78a0484 , 0x8000ff22 , 0x0020eeb3 , 0x14200082 , 0x2130ef41 , 0xeb431300 , 0x4133200a , 0xd7410ecb , 0x9a07200b , 0x2027871b , 0x21238221 ,
0xe7828080 , 0xe784fd20 , 0xe8848020 , 0xfe808022 , 0x08880d85 , 0xba41fd20 , 0x82248205 , 0x85eab02a , 0x008022e7 , 0x2cd74200 , 0x44010021 , 0xd34406eb ,
0x44312013 , 0xcf8b0eef , 0x0d422f8b , 0x82332007 , 0x0001212f , 0x8023cf82 , 0x83000180 , 0x820583de , 0x830682d4 , 0x820020d4 , 0x82dc850a , 0x20e282e9 ,
0xb2ff85fe , 0x010327e9 , 0x02000380 , 0x0f440400 , 0x0c634407 , 0x68825982 , 0x85048021 , 0x260a825d , 0x010b0000 , 0x4400ff00 , 0x2746103f , 0x08d74209 ,
0x4d440720 , 0x0eaf4406 , 0xc3441d20 , 0x23078406 , 0xff800002 , 0x04845b83 , 0x8d05b241 , 0x1781436f , 0x6b8c87a5 , 0x1521878e , 0x06474505 , 0x01210783 ,
0x84688c00 , 0x8904828e , 0x441e8cf7 , 0x0b270cff , 0x80008000 , 0x45030003 , 0xfb430fab , 0x080f4107 , 0x410bf942 , 0xd34307e5 , 0x070d4207 , 0x80800123 ,
0x205d85fe , 0x849183fe , 0x20128404 , 0x82809702 , 0x00002217 , 0x41839a09 , 0x6b4408cf , 0x0733440f , 0x3b460720 , 0x82798707 , 0x97802052 , 0x0000296f ,
0xff800004 , 0x01800100 , 0x0021ef89 , 0x0a914625 , 0x410a4d41 , 0x00250ed4 , 0x00050000 , 0x056d4280 , 0x210a7b46 , 0x21481300 , 0x46ed8512 , 0x00210bd1 ,
0x89718202 , 0x21738877 , 0x2b850001 , 0x00220582 , 0x87450a00 , 0x0ddb4606 , 0x41079b42 , 0x9d420c09 , 0x0b09420b , 0x8d820720 , 0x9742fc84 , 0x42098909 ,
0x00241e0f , 0x00800014 , 0x0b47da82 , 0x0833442a , 0x49078d41 , 0x2f450f13 , 0x42278f17 , 0x01200751 , 0x22063742 , 0x44808001 , 0x20450519 , 0x88068906 ,
0x83fe2019 , 0x4203202a , 0x1a941a58 , 0x00820020 , 0xe7a40e20 , 0x420ce146 , 0x854307e9 , 0x0fcb4713 , 0xff20a182 , 0xfe209b82 , 0x0c867f8b , 0x0021aea4 ,
0x219fa40f , 0x7d41003b , 0x07194214 , 0xbf440520 , 0x071d4206 , 0x6941a590 , 0x80802309 , 0x028900ff , 0xa9a4b685 , 0xc5808021 , 0x449b82ab , 0x152007eb ,
0x42134d46 , 0x61440a15 , 0x051e4208 , 0x222b0442 , 0x47001100 , 0xfd412913 , 0x17194714 , 0x410f5b41 , 0x02220773 , 0x09428080 , 0x21a98208 , 0xd4420001 ,
0x481c840d , 0x00232bc9 , 0x42120000 , 0xe74c261b , 0x149d4405 , 0x07209d87 , 0x410db944 , 0x14421c81 , 0x42fd2005 , 0x80410bd2 , 0x203d8531 , 0x06874100 ,
0x48256f4a , 0xcb420c95 , 0x13934113 , 0x44075d44 , 0x044c0855 , 0x00ff2105 , 0xfe228185 , 0x45448000 , 0x22c5b508 , 0x410c0000 , 0x7b412087 , 0x1bb74514 ,
0x32429c85 , 0x0a574805 , 0x21208943 , 0x8ba01300 , 0x440dfb4e , 0x77431437 , 0x245b4113 , 0x200fb145 , 0x41108ffe , 0x80203562 , 0x00200082 , 0x46362b42 ,
0x1742178d , 0x4527830f , 0x0f830b2f , 0x4a138146 , 0x802409a1 , 0xfe8000ff , 0x94419982 , 0x09294320 , 0x04000022 , 0x49050f4f , 0xcb470a63 , 0x48032008 ,
0x2b48067b , 0x85022008 , 0x82638338 , 0x00002209 , 0x05af4806 , 0x900e9f49 , 0x84c5873f , 0x214285bd , 0x064900ff , 0x0c894607 , 0x00000023 , 0x4903820a ,
0x714319f3 , 0x0749410c , 0x8a07a145 , 0x02152507 , 0xfe808000 , 0x74490386 , 0x8080211b , 0x0c276f82 , 0x00018000 , 0x48028003 , 0x2b2315db , 0x43002f00 ,
0x6f82142f , 0x44011521 , 0x93510da7 , 0x20e68508 , 0x06494d80 , 0x8e838020 , 0x06821286 , 0x124bff20 , 0x25f3830c , 0x03800080 , 0xe74a0380 , 0x207b8715 ,
0x876b861d , 0x4a152007 , 0x07870775 , 0xf6876086 , 0x8417674a , 0x0a0021f2 , 0x431c9743 , 0x8d421485 , 0x200b830b , 0x06474d03 , 0x71828020 , 0x04510120 ,
0x42da8606 , 0x1f831882 , 0x001a0022 , 0xff4d0082 , 0x0b0f532c , 0x0d449b94 , 0x4e312007 , 0x074f12e7 , 0x0bf3490b , 0xbb412120 , 0x413f820a , 0xef490857 ,
0x80002313 , 0xe2830001 , 0x6441fc20 , 0x8b802006 , 0x00012108 , 0xfd201582 , 0x492c9b48 , 0x802014ff , 0x51084347 , 0x0f4327f3 , 0x17bf4a14 , 0x201b7944 ,
0x06964201 , 0x134ffe20 , 0x20d6830b , 0x25d78280 , 0xfd800002 , 0x05888000 , 0x9318dc41 , 0x21d282d4 , 0xdb481800 , 0x0dff542a , 0x45107743 , 0xe14813f5 ,
0x0f034113 , 0x83135d45 , 0x47b28437 , 0xe4510e73 , 0x21f58e06 , 0x2b8400fd , 0x1041fcac , 0x08db4b0b , 0x421fdb41 , 0xdf4b18df , 0x011d210a , 0x420af350 ,
0x6e8308af , 0xac85cb86 , 0x1e461082 , 0x82b7a407 , 0x411420a3 , 0xa34130ab , 0x178f4124 , 0x41139741 , 0x86410d93 , 0x82118511 , 0x057243d8 , 0x8941d9a4 ,
0x3093480c , 0x4a13474f , 0xfb5016a9 , 0x07ad4108 , 0x4a0f9d42 , 0xfe200fad , 0x4708aa41 , 0x83482dba , 0x288f4d06 , 0xb398c3bb , 0x44267b41 , 0xb34439d7 ,
0x0755410f , 0x200ebb45 , 0x0f5f4215 , 0x20191343 , 0x06df5301 , 0xf04c0220 , 0x2ba64d07 , 0x82050841 , 0x430020ce , 0xa78f3627 , 0x5213ff42 , 0x2f970bc1 ,
0x4305ab55 , 0xa084111b , 0x450bac45 , 0x5f4238b8 , 0x010c2106 , 0x0220ed82 , 0x441bb344 , 0x875010af , 0x0737480f , 0x490c5747 , 0x0c840c03 , 0x4c204b42 ,
0x8ba905d7 , 0x8b948793 , 0x510c0c51 , 0xfb4b24b9 , 0x1b174107 , 0x5709d74c , 0xd1410ca5 , 0x079d480f , 0x201ff541 , 0x06804780 , 0x7d520120 , 0x80002205 ,
0x20a983fe , 0x47bb83fe , 0x1b8409b4 , 0x81580220 , 0x4e00202c , 0x4f41282f , 0x0eab4f17 , 0x57471520 , 0x0e0f4808 , 0x8221e041 , 0x3e1b4a8b , 0x4407175d ,
0x1b4b071f , 0x4a0f8b07 , 0x174a0703 , 0x0ba5411b , 0x430fb141 , 0x0120057b , 0xfc20dd82 , 0x4a056047 , 0xf4850c0c , 0x01221982 , 0x02828000 , 0x1a5d088b ,
0x20094108 , 0x8c0e3941 , 0x4900200e , 0x7744434f , 0x200b870b , 0x0e4b5a33 , 0x2b41f78b , 0x8b138307 , 0x0b9f450b , 0x2406f741 , 0xfd808001 , 0x09475a00 ,
0x84000121 , 0x5980200e , 0x85450e5d , 0x832c8206 , 0x4106831e , 0x00213814 , 0x28b34810 , 0x410c2f4b , 0x5f4a13d7 , 0x0b2b4113 , 0x6e43a883 , 0x11174b05 ,
0x4b066a45 , 0xcc470541 , 0x5000202b , 0xcb472f4b , 0x44b59f0f , 0xc5430b5b , 0x0d654907 , 0x21065544 , 0xd6828080 , 0xfe201982 , 0x8230ec4a , 0x120025c2 ,
0x80ff8000 , 0x4128d74d , 0x3320408b , 0x410a9f50 , 0xdb822793 , 0x822bd454 , 0x61134b2e , 0x410b214a , 0xad4117c9 , 0x0001211f , 0x4206854f , 0x4b430596 ,
0x06bb5530 , 0x2025cf46 , 0x0ddd5747 , 0x500ea349 , 0x0f840fa7 , 0x5213c153 , 0x634e08d1 , 0x0bbe4809 , 0x59316e4d , 0x5b50053f , 0x203f6323 , 0x5117eb46 ,
0x94450a63 , 0x246e410a , 0x63410020 , 0x0bdb5f2f , 0x4233ab44 , 0x39480757 , 0x112d4a07 , 0x7241118f , 0x000e2132 , 0x9f286f41 , 0x0f8762c3 , 0x33350723 ,
0x094e6415 , 0x2010925f , 0x067252fe , 0xd0438020 , 0x63a68225 , 0x11203a4f , 0x480e6360 , 0x5748131f , 0x079b521f , 0x200e2f43 , 0x864b8315 , 0x113348e7 ,
0x85084e48 , 0x06855008 , 0x5880fd21 , 0x7c420925 , 0x0c414824 , 0x37470c86 , 0x1b8b422b , 0x5b0a8755 , 0x23410c21 , 0x0b83420b , 0x5a082047 , 0xf482067f ,
0xa80b4c47 , 0x0c0021cf , 0x20207b42 , 0x0fb74100 , 0x420b8744 , 0xeb43076f , 0x0f6f420b , 0x4261fe20 , 0x439aa00c , 0x215034e3 , 0x0ff9570f , 0x4b1f2d5d ,
0x2d5d0c6f , 0x09634d0b , 0x1f51b8a0 , 0x620f200c , 0xaf681e87 , 0x24f94d07 , 0x4e0f4945 , 0xfe200c05 , 0x22139742 , 0x57048080 , 0x23950c20 , 0x97601585 ,
0x4813201f , 0xad620523 , 0x200f8f0f , 0x9e638f15 , 0x00002181 , 0x41342341 , 0x0f930f0b , 0x210b4b62 , 0x978f0001 , 0xfe200f84 , 0x8425c863 , 0x2704822b ,
0x80000a00 , 0x00038001 , 0x610e9768 , 0x834514bb , 0x0bc3430f , 0x2107e357 , 0x80848080 , 0x4400fe21 , 0x2e410983 , 0x00002a1a , 0x00000700 , 0x800380ff ,
0x0fdf5800 , 0x59150021 , 0xd142163d , 0x0c02410c , 0x01020025 , 0x65800300 , 0x00240853 , 0x1d333501 , 0x15220382 , 0x35420001 , 0x44002008 , 0x376406d7 ,
0x096f6b19 , 0x480bc142 , 0x8f4908a7 , 0x211f8b1f , 0x9e830001 , 0x0584fe20 , 0x4180fd21 , 0x11850910 , 0x8d198259 , 0x000021d4 , 0x5a08275d , 0x275d1983 ,
0x06d9420e , 0x9f08b36a , 0x0f7d47b5 , 0x8d8a2f8b , 0x4c0e0b57 , 0xe7410e17 , 0x42d18c1a , 0xb351087a , 0x1ac36505 , 0x4b4a2f20 , 0x0b9f450d , 0x430beb53 ,
0xa7881015 , 0xa5826a83 , 0x80200f82 , 0x86185a65 , 0x4100208e , 0x176c3367 , 0x0fe7650b , 0x4a17ad4b , 0x0f4217ed , 0x112e4206 , 0x41113a42 , 0xf7423169 ,
0x0cb34737 , 0x560f8b46 , 0xa75407e5 , 0x5f01200f , 0x31590c48 , 0x80802106 , 0x42268841 , 0x0020091e , 0x4207ef64 , 0x69461df7 , 0x138d4114 , 0x820f5145 ,
0x53802090 , 0xff200529 , 0xb944b183 , 0x417e8505 , 0x00202561 , 0x15210082 , 0x42378200 , 0x9b431cc3 , 0x004f220d , 0x0dd54253 , 0x4213f149 , 0x7d41133b ,
0x42c9870b , 0x802010f9 , 0x420b2c42 , 0x8f441138 , 0x267c4408 , 0x600cb743 , 0x8f4109d3 , 0x05ab701d , 0x83440020 , 0x3521223f , 0x0b794733 , 0xfb62fe20 ,
0x4afd2010 , 0xaf410ae7 , 0x25ce8525 , 0x01080000 , 0x7b6b0000 , 0x0973710b , 0x82010021 , 0x49038375 , 0x33420767 , 0x052c4212 , 0x58464b85 , 0x41fe2005 ,
0x50440c27 , 0x000c2209 , 0x1cb36b80 , 0x9b06df44 , 0x0f93566f , 0x52830220 , 0xfe216e8d , 0x200f8200 , 0x0fb86704 , 0xb057238d , 0x050b5305 , 0x7217eb47 ,
0xbd410b6b , 0x0f214610 , 0x871f9956 , 0x1e91567e , 0x2029b741 , 0x20008200 , 0x18b7410a , 0x27002322 , 0x41095543 , 0x0f8f0fb3 , 0x41000121 , 0x889d111c ,
0x14207b82 , 0x00200382 , 0x73188761 , 0x475013a7 , 0x6e33200c , 0x234e0ea3 , 0x9b138313 , 0x08e54d17 , 0x9711094e , 0x2ee74311 , 0x4908875e , 0xd75d1f1f ,
0x19ab5238 , 0xa2084d48 , 0x63a7a9b3 , 0x55450b83 , 0x0fd74213 , 0x440d814c , 0x4f481673 , 0x05714323 , 0x13000022 , 0x412e1f46 , 0xdf493459 , 0x21c7550f ,
0x8408215f , 0x201d49cb , 0xb1103043 , 0x0f0d65d7 , 0x452b8d41 , 0x594b0f8d , 0x0b004605 , 0xb215eb46 , 0x000a24d7 , 0x47000080 , 0x002118cf , 0x06436413 ,
0x420bd750 , 0x2b500743 , 0x076a470c , 0x4105c050 , 0xd942053f , 0x0d00211a , 0x5f44779c , 0x0ce94805 , 0x51558186 , 0x14a54c0b , 0x49082b41 , 0x0a4b0888 ,
0x8080261f , 0x0d000000 , 0x20048201 , 0x1deb6a03 , 0x420cb372 , 0x07201783 , 0x4306854d , 0x8b830c59 , 0x59093c74 , 0x0020250f , 0x67070f4a , 0x2341160b ,
0x00372105 , 0x431c515d , 0x554e17ef , 0x0e5d6b05 , 0x41115442 , 0xb74a1ac1 , 0x2243420a , 0x5b4f878f , 0x7507200f , 0x384b086f , 0x09d45409 , 0x0020869a ,
0x12200082 , 0xab460382 , 0x10075329 , 0x54138346 , 0xaf540fbf , 0x1ea75413 , 0x9a0c9e54 , 0x0f6b44c1 , 0x41000021 , 0x47412a4f , 0x07374907 , 0x5310bf76 ,
0xff2009b4 , 0x9a09a64c , 0x8200208d , 0x34c34500 , 0x970fe141 , 0x1fd74b0f , 0x440a3850 , 0x206411f0 , 0x27934609 , 0x470c5d41 , 0x555c2947 , 0x1787540f ,
0x6e0f234e , 0x7d540a1b , 0x1d736b08 , 0x0026a088 , 0x80000e00 , 0x9b5200ff , 0x08ef4318 , 0x450bff77 , 0x1d4d0b83 , 0x081f7006 , 0xcb691b86 , 0x4b022008 ,
0xc34b0b33 , 0x1d0d4a0c , 0x8025a188 , 0x0b000000 , 0x52a38201 , 0xbf7d0873 , 0x0c234511 , 0x8f0f894a , 0x4101200f , 0x0c880c9d , 0x2b418ea1 , 0x06c74128 ,
0x66181341 , 0x7b4c0bb9 , 0x0c06630b , 0xfe200c87 , 0x9ba10882 , 0x27091765 , 0x01000008 , 0x02800380 , 0x48113f4e , 0x29430cf5 , 0x09a75a0b , 0x31618020 ,
0x6d802009 , 0x61840e33 , 0x8208bf51 , 0x0c637d61 , 0x7f092379 , 0x4f470f4b , 0x1797510c , 0x46076157 , 0xf5500fdf , 0x0f616910 , 0x1171fe20 , 0x82802006 ,
0x08696908 , 0x41127a4c , 0x3f4a15f3 , 0x01042607 , 0x0200ff00 , 0x1cf77700 , 0xff204185 , 0x00235b8d , 0x43100000 , 0x3b22243f , 0x3b4d3f00 , 0x0b937709 ,
0xad42f18f , 0x0b1f420f , 0x51084b43 , 0x8020104a , 0xb557ff83 , 0x052b7f2a , 0x0280ff22 , 0x250beb78 , 0x00170013 , 0xbf6d2500 , 0x07db760e , 0x410e2b7f ,
0x00230e4f , 0x49030000 , 0x0582055b , 0x07000326 , 0x00000b00 , 0x580bcd46 , 0x00200cdd , 0x57078749 , 0x8749160f , 0x0f994f0a , 0x41134761 , 0x01200b31 ,
0xeb796883 , 0x0b41500b , 0x0e90b38e , 0x202e7b51 , 0x05d95801 , 0x41080570 , 0x1d530fc9 , 0x0b937a0f , 0xaf8eb387 , 0xf743b98f , 0x07c74227 , 0x80000523 ,
0x0fcb4503 , 0x430ca37b , 0x7782077f , 0x8d0a9947 , 0x08af4666 , 0xeb798020 , 0x6459881e , 0xc3740bbf , 0x0feb6f0b , 0x20072748 , 0x052b6102 , 0x435e0584 ,
0x7d088308 , 0x03200afd , 0x92109e41 , 0x28aa8210 , 0x80001500 , 0x80030000 , 0x0fdb5805 , 0x209f4018 , 0xa7418d87 , 0x0aa3440f , 0x20314961 , 0x073a52ff ,
0x6108505d , 0x43181051 , 0x00223457 , 0xe7820500 , 0x50028021 , 0x81410d33 , 0x063d7108 , 0xdb41af84 , 0x4d888205 , 0x00201198 , 0x463d835f , 0x152106d7 ,
0x0a355a33 , 0x6917614e , 0x75411f4d , 0x184b8b07 , 0x1809c344 , 0x21091640 , 0x0b828000 , 0x42808021 , 0x26790519 , 0x86058605 , 0x2428422d , 0x22123b42 ,
0x42000080 , 0xf587513b , 0x7813677b , 0xaf4d139f , 0x00ff210c , 0x5e0a1d57 , 0x3b421546 , 0x01032736 , 0x02000380 , 0x41180480 , 0x2f420f07 , 0x0c624807 ,
0x00000025 , 0x18000103 , 0x83153741 , 0x430120c3 , 0x042106b2 , 0x088d4d00 , 0x2f830620 , 0x1810434a , 0x18140345 , 0x8507fb41 , 0x5ee582ea , 0x0023116c ,
0x8d000600 , 0x053b56af , 0xa6554fa2 , 0x0d704608 , 0x40180d20 , 0x47181a43 , 0xd37b07ff , 0x0b79500c , 0x420fd745 , 0x47450bd9 , 0x8471830a , 0x095a777e ,
0x84137542 , 0x82002013 , 0x2f401800 , 0x0007213b , 0x4405e349 , 0x0d550ff3 , 0x16254c0c , 0x820ffe4a , 0x0400218a , 0x89066f41 , 0x106b414f , 0xc84d0120 ,
0x80802206 , 0x0c9a4b03 , 0x00100025 , 0x68000200 , 0x9d8c2473 , 0x44134344 , 0xf36a0f33 , 0x4678860f , 0x1b440a25 , 0x41988c0a , 0x80201879 , 0x43079b5e ,
0x4a18080b , 0x0341190b , 0x1259530c , 0x43251552 , 0x908205c8 , 0x0cac4018 , 0x86000421 , 0x0e504aa2 , 0x0020b891 , 0xfb450082 , 0x51132014 , 0x8f5205f3 ,
0x35052108 , 0x8505cb59 , 0x0f6d4f70 , 0x82150021 , 0x29af5047 , 0x4f004b24 , 0x75795300 , 0x1b595709 , 0x460b6742 , 0xbf4b0f0d , 0x5743870b , 0xcb6d1461 ,
0x08f64505 , 0x4e05ab6c , 0x334126c3 , 0x0bcb6b0d , 0x1811034d , 0x4111ef4b , 0x814f1ce5 , 0x20af8227 , 0x07fd7b80 , 0x41188e84 , 0xef410f33 , 0x80802429 ,
0x410d0000 , 0xa34205ab , 0x76b7881c , 0xff500b89 , 0x0741430f , 0x20086f4a , 0x209d8200 , 0x234c18fd , 0x05d4670a , 0x4509af51 , 0x9642078d , 0x189e831d ,
0x7c1cc74b , 0xcd4c07b9 , 0x0e7c440f , 0x8b7b0320 , 0x21108210 , 0xc76c8080 , 0x03002106 , 0x6b23bf41 , 0xc549060b , 0x7946180b , 0x0ff7530f , 0x17ad4618 ,
0x200ecd45 , 0x208c83fd , 0x5e0488fe , 0x032009c6 , 0x420d044e , 0x0d8f0d7f , 0x00820020 , 0x18001021 , 0x6d273b45 , 0xfd4c0c93 , 0xcf451813 , 0x0fe5450f ,
0x5a47c382 , 0x820a8b0a , 0x282b4998 , 0x410a8b5b , 0x4b232583 , 0x54004f00 , 0x978f0ce3 , 0x500f1944 , 0xa95f1709 , 0x0280220b , 0x05ba7080 , 0xa1530682 ,
0x06324c13 , 0x91412582 , 0x05536e2c , 0x63431020 , 0x0f434706 , 0x8c11374c , 0x176143d7 , 0x4d0f454c , 0xd3680bed , 0x0bee4d17 , 0x212b9a41 , 0x0f530a00 ,
0x140d531c , 0x43139143 , 0x95610e8d , 0x0f094415 , 0x4205fb56 , 0x1b4205cf , 0x17015225 , 0x5e0c477f , 0xaf6e0aeb , 0x0ff36218 , 0x04849a84 , 0x0a454218 ,
0x9c430420 , 0x23c6822b , 0x04000102 , 0x45091b4b , 0xf05f0955 , 0x82802007 , 0x421c2023 , 0x5218282b , 0x7b53173f , 0x0fe7480c , 0x74173b7f , 0x47751317 ,
0x634d1807 , 0x0f6f430f , 0x24086547 , 0xfc808002 , 0x0b3c7f80 , 0x10840120 , 0x188d1282 , 0x20096b43 , 0x0fc24403 , 0x00260faf , 0x0180000b , 0x3f500280 ,
0x18002019 , 0x450b4941 , 0xf3530fb9 , 0x18002010 , 0x8208a551 , 0x06234d56 , 0xcb58a39b , 0xc3421805 , 0x1313461e , 0x0f855018 , 0xd34b0120 , 0x6cfe2008 ,
0x574f0885 , 0x09204114 , 0x07000029 , 0x00008000 , 0x44028002 , 0x01420f57 , 0x10c95c10 , 0x11184c18 , 0x80221185 , 0x7f421e00 , 0x00732240 , 0x09cd4977 ,
0x6d0b2b42 , 0x4f180f8f , 0x8f5a0bcb , 0x9b0f830f , 0x0fb9411f , 0x230b5756 , 0x00fd8080 , 0x82060745 , 0x000121d5 , 0x8e0fb277 , 0x4a8d4211 , 0x24061c53 ,
0x04000007 , 0x12275280 , 0x430c954c , 0x80201545 , 0x200f764f , 0x20008200 , 0x20ce8308 , 0x09534f02 , 0x660edf64 , 0x73731771 , 0xe7411807 , 0x20a2820c ,
0x13b64404 , 0x8f5d6682 , 0x1d6b4508 , 0x0cff4d18 , 0x3348c58f , 0x0fc34c07 , 0x31558b84 , 0x8398820f , 0x17514712 , 0x240b0e46 , 0x80000a00 , 0x093b4502 ,
0x420f9759 , 0xa54c0bf1 , 0x0f2b470c , 0x410d314b , 0x2584170c , 0x73b30020 , 0xb55fe782 , 0x204d8410 , 0x08e043fe , 0x4f147e41 , 0x022008ab , 0x4b055159 ,
0x2950068f , 0x00022208 , 0x48511880 , 0x82002009 , 0x00112300 , 0x634dff00 , 0x24415f27 , 0x180f6d43 , 0x4d0b5d45 , 0x4d5f05ef , 0x01802317 , 0x56188000 ,
0xa7840807 , 0xc6450220 , 0x21ca8229 , 0x4b781a00 , 0x3359182c , 0x0cf3470f , 0x180bef46 , 0x420b0354 , 0xff470b07 , 0x4515200a , 0x9758239b , 0x4a80200c ,
0xd2410a26 , 0x05fb4a08 , 0x4b05e241 , 0x03200dc9 , 0x92290941 , 0x00002829 , 0x00010900 , 0x5b020001 , 0x23201363 , 0x460d776a , 0xef530fdb , 0x209a890c ,
0x13fc4302 , 0x00008024 , 0xc4820104 , 0x08820220 , 0x20086b5b , 0x18518700 , 0x8408d349 , 0x0da449a1 , 0x00080024 , 0x7b690280 , 0x4c438b1a , 0x01220f63 ,
0x4c878000 , 0x5c149c53 , 0xfb430868 , 0x2f56181e , 0x0ccf7b1b , 0x0f075618 , 0x2008e347 , 0x14144104 , 0x00207f83 , 0x00207b82 , 0x201adf47 , 0x16c35a13 ,
0x540fdf47 , 0x802006c8 , 0x5418f185 , 0x29430995 , 0x00002419 , 0x58001600 , 0x5720316f , 0x4d051542 , 0x4b7b1b03 , 0x138f4707 , 0xb747b787 , 0x4aab8213 ,
0x058305fc , 0x20115759 , 0x82128401 , 0x0a0b44e8 , 0x46800121 , 0xe64210d0 , 0x82129312 , 0x4bffdffe , 0x3b41171b , 0x9b27870f , 0x808022ff , 0x085c68fe ,
0x41800021 , 0x01410b20 , 0x001a213a , 0x47480082 , 0x11374e12 , 0x56130b4c , 0xdf4b0c65 , 0x0b0f590b , 0x0f574c18 , 0x830feb4b , 0x075f480f , 0x480b4755 ,
0x40490b73 , 0x80012206 , 0x09d74280 , 0x80fe8022 , 0x80210e86 , 0x056643ff , 0x10820020 , 0x420b2646 , 0x0b58391a , 0xd74c1808 , 0x078b4e22 , 0x2007f55f ,
0x4b491807 , 0x83802017 , 0x65aa82a7 , 0x3152099e , 0x068b7616 , 0x9b431220 , 0x09bb742c , 0x500e376c , 0x8342179b , 0x0a4d5d0f , 0x8020a883 , 0x180cd349 ,
0x2016bb4b , 0x14476004 , 0x84136c43 , 0x08cf7813 , 0x4f4c0520 , 0x156f420f , 0x20085f42 , 0x6fd3be03 , 0xd4d30803 , 0xa7411420 , 0x004b222c , 0x0d3b614f ,
0x3f702120 , 0x1393410a , 0x8f132745 , 0x47421827 , 0x41e08209 , 0xb05e2bb9 , 0x18b7410c , 0x18082647 , 0x4107a748 , 0xeb8826bf , 0x0ca76018 , 0x733ecb41 ,
0xd0410d83 , 0x43ebaf2a , 0x0420067f , 0x721dab4c , 0x472005bb , 0x4105d341 , 0x334844cb , 0x20dba408 , 0x47d6ac00 , 0x034e3aef , 0x0f8f421b , 0x930f134d ,
0x3521231f , 0xb7421533 , 0x42f5ad0a , 0x1e961eaa , 0x17000022 , 0x4c367b50 , 0x7d491001 , 0x0bf5520f , 0x4c18fda7 , 0xb8460c55 , 0x83fe2005 , 0x00fe25b9 ,
0x80000180 , 0x9e751085 , 0x261b5c12 , 0x82110341 , 0x001123fb , 0x4518fe80 , 0xf38c2753 , 0x6d134979 , 0x295107a7 , 0xaf5f180f , 0x0fe3660c , 0x180b6079 ,
0x2007bd5f , 0x9aab9103 , 0x2f4d1811 , 0x05002109 , 0x44254746 , 0x1d200787 , 0x450bab75 , 0x4f180f57 , 0x4f181361 , 0x3b831795 , 0xeb4b0120 , 0x0b734805 ,
0x84078f48 , 0x2e1b47bc , 0x00203383 , 0xaf065f45 , 0x831520d7 , 0x130f51a7 , 0x1797bf97 , 0x2b47d783 , 0x18fe2005 , 0x4a18a44f , 0xa64d086d , 0x1ab0410d ,
0x6205a258 , 0xdbab069f , 0x4f06f778 , 0xa963081d , 0x133b670a , 0x8323d141 , 0x13195b23 , 0x530f5e70 , 0xe5ad0824 , 0x58001421 , 0x1f472b4b , 0x47bf410c ,
0x82000121 , 0x83fe20cb , 0x07424404 , 0x68068243 , 0xd7ad0d3d , 0x00010d26 , 0x80020000 , 0x4a1c6f43 , 0x23681081 , 0x10a14f13 , 0x8a070e57 , 0x430a848f ,
0x7372243e , 0x4397a205 , 0xb56c1021 , 0x43978f0f , 0x64180505 , 0x99aa0ff2 , 0x0e000022 , 0x20223341 , 0x094b4f37 , 0x074a3320 , 0x2639410a , 0xfe208e84 ,
0x8b0e0048 , 0x508020a3 , 0x9e4308fe , 0x073f4115 , 0xe3480420 , 0x0c9b5f1b , 0x7c137743 , 0x9a95185b , 0x6122b148 , 0x979b08df , 0x0fe36c18 , 0x48109358 ,
0x23441375 , 0x0ffd5c0b , 0x180fc746 , 0x2011d157 , 0x07e95702 , 0x58180120 , 0x18770ac3 , 0x51032008 , 0x7d4118e3 , 0x80802315 , 0x3b4c1900 , 0xbb5a1830 ,
0x0ceb6109 , 0x5b0b3d42 , 0x4f181369 , 0x4f180b8d , 0x4f180f75 , 0x355a1b81 , 0x200d820d , 0x18e483fd , 0x4528854f , 0x89420846 , 0x1321411f , 0x44086b60 ,
0x07421d77 , 0x107d4405 , 0x4113fd41 , 0x5a181bf1 , 0x4f180db3 , 0x8021128f , 0x20f68280 , 0x44a882fe , 0x334d249a , 0x052f6109 , 0x1520c3a7 , 0xef4eb783 ,
0x4ec39b1b , 0xc4c90ee7 , 0x20060b4d , 0x256f4905 , 0x4d0cf761 , 0xcf9b1f13 , 0xa213d74e , 0x0e1145d4 , 0x50135b42 , 0xcb4e398f , 0x20d79f27 , 0x08865d80 ,
0x186d5018 , 0xa90f7142 , 0x067342d7 , 0x3f450420 , 0x65002021 , 0xe3560771 , 0x24d38f23 , 0x15333531 , 0x0eb94d01 , 0x451c9f41 , 0x384322fb , 0x00092108 ,
0x19af6b18 , 0x6e0c6f5a , 0xbd770bfb , 0x22bb7718 , 0x20090f57 , 0x25e74204 , 0x4207275a , 0xdb5408ef , 0x1769450f , 0x1b1b5518 , 0x210b1f57 , 0x5e4c8001 ,
0x55012006 , 0x802107f1 , 0x0a306a80 , 0x45808021 , 0x0d850b88 , 0x31744f18 , 0x1808ec54 , 0x2009575b , 0x45ffa505 , 0x1b420c73 , 0x180f9f0f , 0x4a0cf748 ,
0x501805b2 , 0x00210f40 , 0x4d118f80 , 0xd6823359 , 0x072b5118 , 0x314ad7aa , 0x8fc79f08 , 0x45d78b1f , 0xfe20058f , 0x23325118 , 0x7b54d9b5 , 0x9fc38f46 ,
0x10bb410f , 0x41077b42 , 0xc1410faf , 0x27cf441d , 0x46051b4f , 0x04200683 , 0x2121d344 , 0x8f530043 , 0x8fcf9f0e , 0x21df8c1f , 0x50188000 , 0x5d180e52 ,
0xfd201710 , 0x4405c341 , 0xd68528e3 , 0x20071f6b , 0x1b734305 , 0x6b080957 , 0x7d422b1f , 0x67002006 , 0x7f8317b1 , 0x2024cb48 , 0x08676e00 , 0x8749a39b ,
0x18132006 , 0x410a6370 , 0x8f490b47 , 0x7e1f8f13 , 0x551805c3 , 0x4c180915 , 0xfe200e2f , 0x244d5d18 , 0x270bcf44 , 0xff000019 , 0x04800380 , 0x5f253342 ,
0xff520df7 , 0x13274c18 , 0x5542dd93 , 0x0776181b , 0xf94a1808 , 0x084a4c0c , 0x4308ea5b , 0xde831150 , 0x7900fd21 , 0x00492c1e , 0x060f4510 , 0x17410020 ,
0x0ce74526 , 0x6206b341 , 0x1f561083 , 0x9d6c181b , 0x08a0500e , 0x112e4118 , 0x60000421 , 0xbf901202 , 0x4408e241 , 0xc7ab0513 , 0xb40f0950 , 0x055943c7 ,
0x4f18ff20 , 0xc9ae1cad , 0x32b34f18 , 0x7a180120 , 0x3d520a05 , 0x53d1b40a , 0x80200813 , 0x1b815018 , 0x832bf86f , 0x67731847 , 0x297f4308 , 0x6418d54e ,
0x734213f7 , 0x056b4b27 , 0xdba5fe20 , 0x1828aa4e , 0x2031a370 , 0x06cb6101 , 0x2040ad41 , 0x07365300 , 0x2558d985 , 0x83fe200c , 0x0380211c , 0x542c4743 ,
0x052006b7 , 0x6021df45 , 0x897b0707 , 0x18d3c010 , 0x20090e70 , 0x1d5843ff , 0x540a0e44 , 0x002126c5 , 0x322f7416 , 0x636a5720 , 0x0f317409 , 0x610fe159 ,
0x294617e7 , 0x08555213 , 0x2006a75d , 0x6cec84fd , 0xfb5907be , 0x3a317405 , 0x83808021 , 0x180f20ea , 0x4626434a , 0x531818e3 , 0xdb59172d , 0x0cbb460c ,
0x2013d859 , 0x18b94502 , 0x8f46188d , 0x77521842 , 0x0a184e38 , 0x9585fd20 , 0x6a180684 , 0xc64507e9 , 0x51cbb230 , 0xd3440cf3 , 0x17ff6a0f , 0x450f5b42 ,
0x276407c1 , 0x4853180a , 0x21ccb010 , 0xcf580013 , 0x0c15442d , 0x410a1144 , 0x1144359d , 0x5cfe2006 , 0xa1410a43 , 0x2bb64519 , 0x2f5b7618 , 0xb512b745 ,
0x0cfd6fd1 , 0x42089f59 , 0xb8450c70 , 0x0000232d , 0x50180900 , 0xb9491ae3 , 0x0fc37610 , 0x01210f83 , 0x0f3b4100 , 0xa01b2742 , 0x0ccd426f , 0x6e8f6f94 ,
0x9c808021 , 0xc7511870 , 0x17c74b08 , 0x9b147542 , 0x44fe2079 , 0xd5480c7e , 0x95ef861d , 0x101b597b , 0xf5417594 , 0x9f471808 , 0x86868d0e , 0x3733491c ,
0x690f4d6d , 0x43440b83 , 0x1ba94c0b , 0x660cd16b , 0x802008ae , 0x74126448 , 0xcb4f38a3 , 0x2cb74b0b , 0x47137755 , 0xe3971777 , 0x1b5d0120 , 0x057a4108 ,
0x6e08664d , 0x17421478 , 0x11af4208 , 0x850c3f42 , 0x08234f0c , 0x4321eb4a , 0xf3451095 , 0x0f394e0f , 0x4310eb45 , 0xc09707b1 , 0x54431782 , 0xaec08d1d ,
0x0f434dbb , 0x9f0c0b45 , 0x0a3b4dbb , 0x4618bdc7 , 0x536032eb , 0x17354213 , 0x4d134169 , 0xc7a30c2f , 0x4e254342 , 0x174332cf , 0x43cdae17 , 0x6b4706e4 ,
0x0e16430d , 0x530b5542 , 0x2f7c26bb , 0x13075f31 , 0x43175342 , 0x60181317 , 0x6550114e , 0x28624710 , 0x58070021 , 0x59181683 , 0x2d540cf5 , 0x05d5660c ,
0x20090c7b , 0x0e157e02 , 0x8000ff2b , 0x14000080 , 0x80ff8000 , 0x27137e03 , 0x336a4b20 , 0x0f817107 , 0x13876e18 , 0x730f2f7e , 0x2f450b75 , 0x6d02200b ,
0x6d66094c , 0x4b802009 , 0x15820a02 , 0x2f45fe20 , 0x5e032006 , 0x00202fd9 , 0x450af741 , 0xeb412e0f , 0x0ff3411f , 0x420a8b65 , 0xf7410eae , 0x1c664810 ,
0x540e1145 , 0xbfa509f3 , 0x42302f58 , 0x80200c35 , 0xcb066c47 , 0x4b1120c1 , 0x41492abb , 0x34854110 , 0xa7097b72 , 0x251545c7 , 0x4b2c7f56 , 0xc5b40bab ,
0x940cd54e , 0x2e6151c8 , 0x09f35f18 , 0x4b420420 , 0x09677121 , 0x8f24f357 , 0x1b5418e1 , 0x08915a1f , 0x3143d894 , 0x22541805 , 0x1b9b4b0e , 0x8c0d3443 ,
0x1400240d , 0x18ff8000 , 0x582e6387 , 0xf99b2b3b , 0x8807a550 , 0x17a14790 , 0x2184fd20 , 0x5758fe20 , 0x2354882c , 0x15000080 , 0x5e056751 , 0x334c2c2f ,
0x97c58f0c , 0x1fd7410f , 0x0d4d4018 , 0x4114dc41 , 0x04470ed6 , 0x0dd54128 , 0x00820020 , 0x02011523 , 0x22008700 , 0x86480024 , 0x0001240a , 0x8682001a ,
0x0002240b , 0x866c000e , 0x8a03200b , 0x8a042017 , 0x0005220b , 0x22218614 , 0x84060000 , 0x86012017 , 0x8212200f , 0x250b8519 , 0x000d0001 , 0x0b850031 ,
0x07000224 , 0x0b862600 , 0x11000324 , 0x0b862d00 , 0x238a0420 , 0x0a000524 , 0x17863e00 , 0x17840620 , 0x01000324 , 0x57820904 , 0x0b85a783 , 0x0b85a785 ,
0x0b85a785 , 0x22000325 , 0x85007a00 , 0x85a7850b , 0x85a7850b , 0x22a7850b , 0x82300032 , 0x00342201 , 0x0805862f , 0x35003131 , 0x54207962 , 0x74736972 ,
0x47206e61 , 0x6d6d6972 , 0x65527265 , 0x616c7567 , 0x58545472 , 0x6f725020 , 0x43796767 , 0x6e61656c , 0x30325454 , 0x822f3430 , 0x35313502 , 0x79006200 ,
0x54002000 , 0x69007200 , 0x74007300 , 0x6e006100 , 0x47200f82 , 0x6d240f84 , 0x65006d00 , 0x52200982 , 0x67240582 , 0x6c007500 , 0x72201d82 , 0x54222b82 ,
0x23825800 , 0x19825020 , 0x67006f22 , 0x79220182 , 0x1b824300 , 0x3b846520 , 0x1f825420 , 0x41000021 , 0x1422099b , 0x0b410000 , 0x87088206 , 0x01012102 ,
0x78080982 , 0x01020101 , 0x01040103 , 0x01060105 , 0x01080107 , 0x010a0109 , 0x010c010b , 0x010e010d , 0x0110010f , 0x01120111 , 0x01140113 , 0x01160115 ,
0x01180117 , 0x011a0119 , 0x011c011b , 0x011e011d , 0x0020011f , 0x00040003 , 0x00060005 , 0x00080007 , 0x000a0009 , 0x000c000b , 0x000e000d , 0x0010000f ,
0x00120011 , 0x00140013 , 0x00160015 , 0x00180017 , 0x001a0019 , 0x001c001b , 0x001e001d , 0x08bb821f , 0x22002142 , 0x24002300 , 0x26002500 , 0x28002700 ,
0x2a002900 , 0x2c002b00 , 0x2e002d00 , 0x30002f00 , 0x32003100 , 0x34003300 , 0x36003500 , 0x38003700 , 0x3a003900 , 0x3c003b00 , 0x3e003d00 , 0x40003f00 ,
0x42004100 , 0x4b09f382 , 0x00450044 , 0x00470046 , 0x00490048 , 0x004b004a , 0x004d004c , 0x004f004e , 0x00510050 , 0x00530052 , 0x00550054 , 0x00570056 ,
0x00590058 , 0x005b005a , 0x005d005c , 0x005f005e , 0x01610060 , 0x01220121 , 0x01240123 , 0x01260125 , 0x01280127 , 0x012a0129 , 0x012c012b , 0x012e012d ,
0x0130012f , 0x01320131 , 0x01340133 , 0x01360135 , 0x01380137 , 0x013a0139 , 0x013c013b , 0x013e013d , 0x0140013f , 0x00ac0041 , 0x008400a3 , 0x00bd0085 ,
0x00e80096 , 0x008e0086 , 0x009d008b , 0x00a400a9 , 0x008a00ef , 0x008300da , 0x00f20093 , 0x008d00f3 , 0x00880097 , 0x00de00c3 , 0x009e00f1 , 0x00f500aa ,
0x00f600f4 , 0x00ad00a2 , 0x00c700c9 , 0x006200ae , 0x00900063 , 0x00cb0064 , 0x00c80065 , 0x00cf00ca , 0x00cd00cc , 0x00e900ce , 0x00d30066 , 0x00d100d0 ,
0x006700af , 0x009100f0 , 0x00d400d6 , 0x006800d5 , 0x00ed00eb , 0x006a0089 , 0x006b0069 , 0x006c006d , 0x00a0006e , 0x0071006f , 0x00720070 , 0x00750073 ,
0x00760074 , 0x00ea0077 , 0x007a0078 , 0x007b0079 , 0x007c007d , 0x00a100b8 , 0x007e007f , 0x00810080 , 0x00ee00ec , 0x6e750eba , 0x646f6369 , 0x78302365 ,
0x31303030 , 0x32200e8d , 0x33200e8d , 0x34200e8d , 0x35200e8d , 0x36200e8d , 0x37200e8d , 0x38200e8d , 0x39200e8d , 0x61200e8d , 0x62200e8d , 0x63200e8d ,
0x64200e8d , 0x65200e8d , 0x66200e8d , 0x31210e8c , 0x8d0e8d30 , 0x8d3120ef , 0x8d3120ef , 0x8d3120ef , 0x8d3120ef , 0x8d3120ef , 0x8d3120ef , 0x8d3120ef ,
0x8d3120ef , 0x8d3120ef , 0x8d3120ef , 0x8d3120ef , 0x8d3120ef , 0x8d3120ef , 0x66312def , 0x6c656406 , 0x04657465 , 0x6f727545 , 0x3820ec8c , 0x3820ec8d ,
0x3820ec8d , 0x3820ec8d , 0x3820ec8d , 0x3820ec8d , 0x3820ec8d , 0x3820ec8d , 0x3820ec8d , 0x3820ec8d , 0x3820ec8d , 0x3820ec8d , 0x3820ec8d , 0x3820ec8d ,
0x3820ec8d , 0x200ddc41 , 0x0ddc4139 , 0xef8d3920 , 0xef8d3920 , 0xef8d3920 , 0xef8d3920 , 0xef8d3920 , 0xef8d3920 , 0xef8d3920 , 0xef8d3920 , 0xef8d3920 ,
0xef8d3920 , 0xef8d3920 , 0xef8d3920 , 0xef8d3920 , 0xef8d3920 , 0x00663923 , 0x48fa0500 , 0x00f762f9 ,
} ;
2015-01-09 17:00:53 +08:00
static void GetDefaultCompressedFontDataTTF ( const void * * ttf_compressed_data , unsigned int * ttf_compressed_size )
{
* ttf_compressed_data = proggy_clean_ttf_compressed_data ;
* ttf_compressed_size = proggy_clean_ttf_compressed_size ;
}
2014-08-11 04:58:11 +08:00
//-----------------------------------------------------------------------------
2014-09-10 18:22:01 +08:00
2014-12-06 07:09:43 +08:00
//---- Include imgui_user.inl at the end of imgui.cpp
//---- So you can include code that extends ImGui using its private data/functions.
2014-10-02 18:56:40 +08:00
# ifdef IMGUI_INCLUDE_IMGUI_USER_INL
# include "imgui_user.inl"
2014-09-10 18:22:01 +08:00
# endif
//-----------------------------------------------------------------------------