Previous 199869 Revisions Next

r36606 Tuesday 24th March, 2015 at 15:36:59 UTC by fulivi
Added MESS driver for Intel MDS series-II
[/trunk]makefile
[3rdparty/bgfx]README.md
[3rdparty/bgfx/3rdparty/ib-compress]writebitstream.h
[3rdparty/bgfx/3rdparty/ocornut-imgui]imconfig.h imgui.cpp imgui.h
[3rdparty/bgfx/examples/08-update]fs_update_3d.sc update.cpp
[3rdparty/bgfx/examples/23-vectordisplay]vectordisplay.cpp
[3rdparty/bgfx/examples/25-c99]helloworld.c
[3rdparty/bgfx/examples/common/entry]entry.cpp entry.h entry_android.cpp entry_asmjs.cpp entry_ios.mm entry_nacl.cpp entry_osx.mm entry_p.h entry_qnx.cpp entry_sdl.cpp entry_windows.cpp entry_winrt.cpp entry_x11.cpp
[3rdparty/bgfx/examples/common/imgui]fs_imgui_latlong.bin.h fs_imgui_latlong.sc imgui.cpp imgui.h ocornut_imgui.cpp
[3rdparty/bgfx/examples/common/nanovg]nanovg.cpp nanovg.h nanovg_bgfx.cpp
[3rdparty/bgfx/examples/runtime/shaders/dx11]fs_update_3d.bin
[3rdparty/bgfx/examples/runtime/shaders/dx9]fs_update_3d.bin
[3rdparty/bgfx/examples/runtime/shaders/gles]fs_update_3d.bin
[3rdparty/bgfx/examples/runtime/shaders/glsl]fs_update_3d.bin
[3rdparty/bgfx/include]bgfx.c99.h bgfx.h bgfxdefines.h
[3rdparty/bgfx/scripts]bgfx.lua example-common.lua genie.lua geometryc.lua makedisttex.lua shaderc.lua texturec.lua
[3rdparty/bgfx/src]bgfx.cpp bgfx_compute.sh bgfx_p.h bgfx_shader.sh config.h glimports.h image.cpp image.h renderer_d3d.h renderer_d3d11.cpp renderer_d3d9.cpp renderer_d3d9.h renderer_gl.cpp renderer_gl.h renderer_vk.cpp vertexdecl.cpp
[3rdparty/bgfx/tools/shaderc]shaderc.cpp
[3rdparty/bx/3rdparty/CL]cl_platform.h
[3rdparty/bx/include/bx]handlealloc.h platform.h uint32_t.h
[3rdparty/bx/scripts]genie.lua toolchain.lua
[3rdparty/bx/tools/bin/darwin]genie
[3rdparty/bx/tools/bin/linux]genie
[3rdparty/bx/tools/bin/windows]genie.exe
[3rdparty/genie].editorconfig README.md makefile scripting-reference.md*
[3rdparty/genie/build/gmake.darwin]genie.make
[3rdparty/genie/build/gmake.linux]genie.make
[3rdparty/genie/build/gmake.windows]genie.make
[3rdparty/genie/docs]scripting-reference.md
[3rdparty/genie/scripts]genie.lua
[3rdparty/genie/src/actions/make]make_cpp.lua
[3rdparty/genie/src/actions/vstudio]_vstudio.lua vs2010_vcxproj.lua
[3rdparty/genie/src/base]api.lua bake.lua path.lua
[3rdparty/genie/src/host]premake.c scripts.c
[3rdparty/lua/src]luaconf.h
[3rdparty/mongoose]mongoose.c mongoose.h
[3rdparty/mongoose/docs]API.md Embed.md LuaSqlite.md* ReleaseNotes.md
[3rdparty/mongoose/examples].gitignore Makefile
[3rdparty/mongoose/examples/multi_threaded_server]Makefile
[3rdparty/mongoose/examples/proxy_server]Makefile
[3rdparty/mongoose/examples/web_server]Makefile web_server.c
[3rdparty/mongoose/examples/web_server/certs]cert.pem
[3rdparty/mongoose/examples/websocket_ssl_proxy]Makefile
[3rdparty/mongoose/test]unit_test.c
[3rdparty/portmidi/pm_mac]osxsupport.m
[docs]luaengine.md
[hash]gamegear.xml gameking.xml gba.xml gbcolor.xml megadriv.xml nes.xml pasogo.xml pc8801_flop.xml pc98.xml pet_rom.xml pico.xml sms.xml snes.xml snes_strom.xml
[src/build]file2str.py flags_clang.mak makedep.c makelist.py makemak.c png2bdc.py verinfo.py
[src/emu]emucore.h emuopts.c emuopts.h info.c luaengine.c mame.c render.c render.h schedule.c validity.c validity.h video.c video.h
[src/emu/bus]bus.mak
[src/emu/bus/a2bus]ezcgi.c ezcgi.h
[src/emu/bus/nes]nes_pcb.inc
[src/emu/bus/scsi]omti5100.c omti5100.h
[src/emu/cpu]cpu.mak
[src/emu/cpu/arcompact]arcompact_make.py
[src/emu/cpu/h8]h8.c h8make.py
[src/emu/cpu/hmcs40]hmcs40.c hmcs40.h hmcs40d.c hmcs40op.inc
[src/emu/cpu/i386]i386.h i386ops.h pentops.inc x87ops.inc
[src/emu/cpu/i960]i960.c
[src/emu/cpu/m6502]m6502make.py
[src/emu/cpu/m6809]m6809make.py
[src/emu/cpu/mcs96]mcs96make.py
[src/emu/cpu/nec]nec.c nec.h necinstr.inc v53.c v53.h
[src/emu/cpu/pic16c5x]pic16c5x.c pic16c5x.h
[src/emu/cpu/sharc]sharc.c
[src/emu/cpu/tms0980]tms0980.c tms0980.h
[src/emu/cpu/tms57002]tmsmake.py
[src/emu/cpu/ucom4]ucom4.h
[src/emu/cpu/z80]kl5c80a12.c kl5c80a12.h
[src/emu/debug]dvbpoints.c dvdisasm.c dvwpoints.c
[src/emu/drivers]xtal.h
[src/emu/machine]am9517a.c am9517a.h i8251.c i8251.h i8257.c machine.mak mcf5206e.c mcf5206e.h omti5100.c* omti5100.h* pic8259.c tmp68301.c tms6100.c upd71071.c upd71071.h vrc4373.c vrc4373.h wd_fdc.c
[src/emu/netlist]plists.h
[src/emu/sound]es1373.c es1373.h flt_rc.c okim9810.c okim9810.h sound.mak wavwrite.c
[src/emu/ui]filemngr.c filemngr.h ui.c
[src/emu/video]scn2674.c scn2674.h tms34061.c video.mak voodoo_pci.c voodoo_pci.h
[src/lib]lib.mak
[src/lib/formats]a26_cas.c a5105_dsk.c abc800_dsk.c ace_tap.c adam_cas.c adam_dsk.c ami_dsk.c ap_dsk35.c apf_apt.c apollo_dsk.c applix_dsk.c apridisk.c asst128_dsk.c atari_dsk.c atarist_dsk.c atom_tap.c bw12_dsk.c bw2_dsk.c cassimg.c cbm_crt.c cbm_crt.h cbm_tap.c ccvf_dsk.c cgen_cas.c coco_cas.c coco_dsk.c comx35_dsk.c concept_dsk.c coupedsk.c cpis_dsk.c cqm_dsk.c csw_cas.c d64_dsk.c d64_dsk.h d67_dsk.c d71_dsk.c d80_dsk.c d81_dsk.c d82_dsk.c d88_dsk.c dcp_dsk.c dfi_dsk.c dim_dsk.c dip_dsk.c dmk_dsk.c dmv_dsk.c dsk_dsk.c ep64_dsk.c esq16_dsk.c esq8_dsk.c excali64_dsk.c fc100_cas.c fdd_dsk.c fdi_dsk.c flex_dsk.c flopimg.c fm7_cas.c fmsx_cas.c fmtowns_dsk.c g64_dsk.c gtp_cas.c hect_dsk.c hect_tap.c hxcmfm_dsk.c imd_dsk.c ioprocs.c ipf_dsk.c iq151_dsk.c itt3030_dsk.c kaypro_dsk.c kc85_dsk.c kc_cas.c kim1_cas.c lviv_lvt.c m20_dsk.c m5_dsk.c mbee_cas.c mfi_dsk.c mm_dsk.c msx_dsk.c mz_cas.c nanos_dsk.c naslite_dsk.c nes_dsk.c nfd_dsk.c orao_cas.c oric_dsk.c oric_tap.c p6001_cas.c pasti_dsk.c pc98_dsk.c pc98fdi_dsk.c pc_dsk.c phc25_cas.c pmd_cas.c primoptp.c pyldin_dsk.c ql_dsk.c rk_cas.c rx50_dsk.c sc3000_bit.c sf7000_dsk.c smx_dsk.c sol_cas.c sorc_cas.c sorc_dsk.c sord_cas.c spc1000_cas.c st_dsk.c svi_cas.c svi_dsk.c tandy2k_dsk.c td0_dsk.c thom_cas.c thom_dsk.c ti99_dsk.c tiki100_dsk.c trd_dsk.c trs_cas.c trs_dsk.c tvc_cas.c tvc_dsk.c tzx_cas.c uef_cas.c upd765_dsk.c vg5k_cas.c victor9k_dsk.c victor9k_dsk.h vt_cas.c vt_dsk.c vtech1_dsk.c wd177x_dsk.c x07_cas.c x1_tap.c xdf_dsk.c z80ne_dsk.c zx81_p.c
[src/lib/util]avhuff.c aviio.c bitmap.c bitmap.h cdrom.c chd.c chdcd.c chdcodec.c corefile.c corestr.h coretmpl.h cstrpool.c delegate.c delegate.h flac.c harddisk.c huffman.c opresolv.c options.c palette.c png.c tagmap.c xmlfile.c zippath.c
[src/mame]mame.lst mame.mak
[src/mame/audio]hng64.c mw8080bw.c subs.c
[src/mame/drivers]argus.c armedf.c astinvad.c astrcorp.c atlantis.c bbusters.c bingor.c blackt96.c cabal.c capbowl.c cocoloco.c combatsc.c cps1.c cubo.c ddragon3.c deadang.c drgnmst.c dynax.c fgoal.c flyball.c funkball.c galaxian.c galaxold.c gbusters.c* goldstar.c hng64.c hotblock.c ironhors.c iteagle.c jankenmn.c jchan.c jongkyo.c junofrst.c karnov.c kickgoal.c m72.c madalien.c megaphx.c megaplay.c megasys1.c mgolf.c midzeus.c mitchell.c mosaic.c mpu4hw.c neogeo.c neogeo_noslot.c nova2001.c opwolf.c paradise.c peplus.c pinball2k.c playmark.c pooyan.c psikyo.c psychic5.c pturn.c queen.c raiden2.c re900.c realbrk.c rltennis.c rohga.c sam.c sandscrp.c scobra.c segas32.c seta.c seta2.c shougi.c shuuz.c sidearms.c simple_st0016.c sothello.c speedbal.c speedspn.c speglsht.c srmp2.c srmp5.c srmp6.c srumbler.c ssozumo.c ssrj.c sstrangr.c ssv.c sub.c subs.c suna16.c suna8.c supdrapo.c supertnk.c superwng.c suprgolf.c suprloco.c suprridr.c suprslam.c tagteam.c taito_l.c tankbatt.c tankbust.c taotaido.c tbowl.c tecmo.c tgtpanic.c thedeep.c thunderx.c timelimt.c toaplan2.c tryout.c tsamurai.c ttchamp.c tugboat.c twins.c usgames.c vamphalf.c vigilant.c vulgus.c wc90.c wc90b.c xain.c xtheball.c
[src/mame/includes]argus.h armedf.h bbusters.h cabal.h capbowl.h deadang.h drgnmst.h dynax.h fgoal.h gbusters.h* goldstar.h hng64.h ironhors.h m72.h megasys1.h midzeus.h mosaic.h mpu4.h nova2001.h paradise.h playmark.h pooyan.h psychic5.h realbrk.h rltennis.h seta.h seta2.h shuuz.h sidearms.h simple_st0016.h speedbal.h speedspn.h srmp2.h srumbler.h ssozumo.h ssrj.h ssv.h subs.h suna16.h suna8.h suprloco.h suprridr.h tagteam.h tankbatt.h tankbust.h taotaido.h tbowl.h thedeep.h thunderx.h timelimt.h tryout.h tsamurai.h usgames.h vigilant.h vulgus.h wc90.h wc90b.h xain.h
[src/mame/layout]bingowng.lay cherryb3.lay chrygld.lay cmaster.lay cmasterb.lay cmasterc.lay cmpacman.lay cmv4.lay crazybon.lay goldstar.lay lucky8.lay nfb96.lay nfb96tx.lay pokonl97.lay roypok96.lay skill98.lay tonypok.lay unkch.lay
[src/mame/machine]hng64_net.c iteagle_fpga.c iteagle_fpga.h subs.c
[src/mame/video]argus.c bbusters.c cabal.c capbowl.c cps1.c deadang.c decmxc06.c decmxc06.h dynax.c fgoal.c gbusters.c* goldstar.c hng64.c hng64_3d.c hng64_sprite.c ironhors.c jalblend.c jalblend.h megasys1.c mosaic.c paradise.c pc080sn.c pooyan.c psychic5.c realbrk.c rltennis.c seta.c seta001.c seta001.h seta2.c shuuz.c sidearms.c speedbal.c speedspn.c srmp2.c srumbler.c ssozumo.c ssrj.c ssv.c st0020.c subs.c suna16.c suprloco.c suprridr.c tagteam.c tankbatt.c tankbust.c taotaido.c tbowl.c thedeep.c thunderx.c timelimt.c tryout.c tsamurai.c vulgus.c wc90b.c xain.c
[src/mess]mess.lst mess.mak messcore.mak
[src/mess/audio]gamate.c upd1771.c
[src/mess/drivers]a7800.c alnchase.c* amaztron.c* apple2.c apple2e.c cnsector.c* comp4.c* edracula.c* elecbowl.c elecdet.c* fanucspmg.c fidelz80.c gamate.c hh_hmcs40.c hh_pic16.c hh_tms1k.c hh_ucom4.c imds2.c* ip22.c m24.c mathmagi.c* mbdtower.c mbee.c merlin.c* pasogo.c pc.c pcd.c simon.c* sms.c snes.c splitsec.c* starwbc.c* stopthie.c* tandy12.c* tc4.c* ti99_4x.c ticalc1x.c tispeak.c tmtennis.c* unk3403.c* vt100.c wildfire.c
[src/mess/includes]gamate.h hh_tms1k.h imds2.h* mbee.h
[src/mess/layout]alnchase.lay* amaztron.lay cnsector.lay ebball.lay ebball2.lay ebball3.lay edracula.lay* elecbowl.lay hh_hmcs40_test.lay hh_ucom4_test.lay maniac.lay mbdtower.lay ssimon.lay tmtennis.lay* wildfire.lay
[src/mess/machine]m24_kbd.c m24_kbd.h mbee.c pcd_kbd.c pcd_kbd.h
[src/mess/tools/floptool]main.c
[src/mess/tools/imgtool]iflopimg.c imgterrs.c library.c library.h modules.c
[src/mess/video]mbee.c
[src/osd]osdcore.c osdcore.h
[src/osd/modules]osdwindow.h
[src/osd/modules/debugger]debugwin.c
[src/osd/modules/font]font_windows.c
[src/osd/modules/lib]osdobj_common.c osdobj_common.h
[src/osd/modules/opengl]SDL1211_opengl.h gl_shader_mgr.c gl_shader_mgr.h gl_shader_tool.c gl_shader_tool.h osd_opengl.h
[src/osd/modules/opengl/shader]genc.sh glsl_bilinear.vsh glsl_bilinear_idx16_lut.fsh glsl_bilinear_idx16_lut.fsh.c glsl_bilinear_rgb32_dir.fsh glsl_bilinear_rgb32_dir.fsh.c glsl_bilinear_rgb32_lut.fsh glsl_bilinear_rgb32_lut.fsh.c glsl_general.vsh glsl_general.vsh.c glsl_plain.vsh glsl_plain_idx16_lut.fsh glsl_plain_idx16_lut.fsh.c glsl_plain_rgb32_dir.fsh glsl_plain_rgb32_dir.fsh.c glsl_plain_rgb32_lut.fsh glsl_plain_rgb32_lut.fsh.c
[src/osd/modules/render]blit13.h draw13.c drawbgfx.c drawd3d.c drawd3d.h drawdd.c drawgdi.c drawnone.c drawogl.c drawsdl.c
[src/osd/modules/render/d3d]d3d9intf.c d3dcomm.h d3dhlsl.c d3dhlsl.h d3dintf.h
[src/osd/modules/sync]osdsync.h
[src/osd/sdl]SDL1211_opengl.h* blit13.h* draw13.c* drawbgfx.c* drawogl.c* drawsdl.c* gl_shader_mgr.c* gl_shader_mgr.h* gl_shader_tool.c* gl_shader_tool.h* osd_opengl.h* osdsdl.h sdl.mak sdlmain.c video.c video.h window.c window.h
[src/osd/sdl/man]castool.1 chdman.1 floptool.1 imgtool.1 jedutil.1 ldresample.1 ldverify.1 mame.6 mess.6 romcmp.1 testkeys.1
[src/osd/sdl/shader]genc.sh* glsl_bilinear.vsh* glsl_bilinear_idx16_lut.fsh* glsl_bilinear_idx16_lut.fsh.c* glsl_bilinear_rgb32_dir.fsh* glsl_bilinear_rgb32_dir.fsh.c* glsl_bilinear_rgb32_lut.fsh* glsl_bilinear_rgb32_lut.fsh.c* glsl_general.vsh* glsl_general.vsh.c* glsl_plain.vsh* glsl_plain_idx16_lut.fsh* glsl_plain_idx16_lut.fsh.c* glsl_plain_rgb32_dir.fsh* glsl_plain_rgb32_dir.fsh.c* glsl_plain_rgb32_lut.fsh* glsl_plain_rgb32_lut.fsh.c*
[src/osd/windows]d3d9intf.c* d3dcomm.h* d3dhlsl.c* d3dhlsl.h* d3dintf.h* drawbgfx.c* drawd3d.c* drawd3d.h* drawdd.c* drawgdi.c* drawnone.c* video.c video.h window.c window.h windows.mak winmain.c winmain.h winprefix.h
[src/regtests/chdman]chdtest.py
[src/regtests/chdman/input/createhd_4]in.params
[src/regtests/chdman/input/createhd_5]in.params
[src/regtests/chdman/output/createhd_4]out.chd
[src/regtests/chdman/output/createhd_5]out.chd
[src/regtests/jedutil]jedtest.py
[src/tools]chdman.c ldresample.c ldverify.c nltool.c pngcmp.c regrep.c split.c src2html.c tools.mak unidasm.c

trunk/3rdparty/bgfx/3rdparty/ib-compress/writebitstream.h
r245117r245118
3434#define WBS_INLINE __forceinline
3535#else
3636#define WBS_INLINE inline
37#endif
37#endif
3838
39// Very simple bitstream for writing that will grow to accomodate written bits.
39// Very simple bitstream for writing that will grow to accomodate written bits.
4040class WriteBitstream
4141{
4242public:
4343
44    // Construct the bit stream with an initial buffer capacity - should be a multiple of 8 and > 0
44    // Construct the bit stream with an initial buffer capacity - should be a multiple of 8 and > 0
4545    WriteBitstream( size_t initialBufferCapacity = 16 )
4646    {
4747        m_bufferCursor =
r245117r245118
6666    // Write a V int to the stream.
6767    void WriteVInt( uint32_t value );
6868
69    // Get the size in bytes
69    // Get the size in bytes
7070    size_t ByteSize() const { return ( m_size + 7 ) >> 3; }
7171
7272    // Finish writing by flushing the buffer.
r245117r245118
8080    // If we need to grow the buffer.
8181    void GrowBuffer();
8282
83    // Not copyable
83    // Not copyable
8484    WriteBitstream( const WriteBitstream& );
8585
8686    // Not assignable
r245117r245118
9696
9797WBS_INLINE void WriteBitstream::Write( uint32_t value, uint32_t bitCount )
9898{
99    m_bitBuffer |= ( static_cast<uint64_t>( value ) << ( 64 - m_bitsLeft ) ) & ( m_bitsLeft == 0 ? 0 : UINT64_C(0xFFFFFFFFFFFFFFFF) );
99    m_bitBuffer |= ( static_cast<uint64_t>( value ) << ( 64 - m_bitsLeft ) ) & ( m_bitsLeft == 0 ? 0 : 0xFFFFFFFFFFFFFFFF );
100100
101101    if ( bitCount > m_bitsLeft )
102102    {
r245117r245118
175175    m_bufferEnd    = m_buffer + newBufferSize;
176176}
177177
178#endif // -- WRITE_BIT_STREAM_H__
178#endif // -- WRITE_BIT_STREAM_H__
No newline at end of file
trunk/3rdparty/bgfx/3rdparty/ocornut-imgui/imconfig.h
r245117r245118
1414//---- Define assertion handler. Defaults to calling assert().
1515//#define IM_ASSERT(_EXPR)  MyAssert(_EXPR)
1616
17//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows.
18//#define IMGUI_API __declspec( dllexport )
19//#define IMGUI_API __declspec( dllimport )
20
21//---- Don't implement default handlers for Windows (so as not to link with OpenClipboard() and others Win32 functions)
17//---- Don't implement default clipboard handlers for Windows (so as not to link with OpenClipboard() and others Win32 functions)
2218//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS
23//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS
2419
2520//---- Include imgui_user.inl at the end of imgui.cpp so you can include code that extends ImGui using its private data/functions.
2621//#define IMGUI_INCLUDE_IMGUI_USER_INL
r245117r245118
4136
4237//---- Freely implement extra functions within the ImGui:: namespace.
4338//---- Declare helpers or widgets implemented in imgui_user.inl or elsewhere, so end-user doesn't need to include multiple files.
44//---- e.g. you can create variants of the ImGui::Value() helper for your low-level math types, or your own widgets/helpers.
39//---- e.g. you can create variants of the ImGui::Value() helper for your low-level math types.
4540/*
4641namespace ImGui
4742{
trunk/3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.cpp
r245117r245118
1// ImGui library v1.35
1// ImGui library v1.32 wip
22// See ImGui::ShowTestWindow() for sample code.
33// Read 'Programmer guide' below for notes on how to setup ImGui in your codebase.
44// Get latest version at https://github.com/ocornut/imgui
r245117r245118
99 Index
1010 - MISSION STATEMENT
1111 - END-USER GUIDE
12 - PROGRAMMER GUIDE (read me!)
13 - API BREAKING CHANGES (read me when you update!)
14 - FREQUENTLY ASKED QUESTIONS (FAQ) & TROUBLESHOOTING (read me!)
12 - PROGRAMMER GUIDE
13 - API BREAKING CHANGES
14 - TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS
1515 - ISSUES & TODO-LIST
1616 - CODE
1717 - SAMPLE CODE
r245117r245118
2727 - minimize screen real-estate usage
2828 - minimize setup and maintenance
2929 - minimize state storage on user side
30 - portable, minimize dependencies, run on target (consoles, phones, etc.)
30 - portable, minimize dependencies, run on target (consoles, etc.)
3131 - efficient runtime (NB- we do allocate when "growing" content - creating a window / opening a tree node for the first time, etc. - but a typical frame won't allocate anything)
32 - read about immediate-mode gui principles @ http://mollyrocket.com/861, http://mollyrocket.com/forums/index.html
32 - read about immediate-mode GUI principles @ http://mollyrocket.com/861, http://mollyrocket.com/forums/index.html
3333
3434 Designed for developers and content-creators, not the typical end-user! Some of the weaknesses includes:
3535 - doesn't look fancy, doesn't animate
3636 - limited layout features, intricate layouts are typically crafted in code
37 - occasionally uses statically sized buffers for string manipulations - won't crash, but some long text may be clipped. functions like ImGui::TextUnformatted() don't have such restriction.
37 - occasionally use statically sized buffers for string manipulations - won't crash, but some long text may be clipped
3838
3939
4040 END-USER GUIDE
r245117r245118
6363 PROGRAMMER GUIDE
6464 ================
6565
66 - read the FAQ below this section!
67 - your code creates the UI, if your code doesn't run the UI is gone! == very dynamic UI, no construction/destructions steps, less data retention on your side, no state duplication, less sync, less bugs.
68 - call and read ImGui::ShowTestWindow() for sample code demonstrating most features.
66 - your code creates the UI, if your code doesn't run the UI is gone! == dynamic UI, no construction step, less data retention on your side, no state duplication, less sync, less errors.
67 - call and read ImGui::ShowTestWindow() for user-side sample code
6968 - see examples/ folder for standalone sample applications.
7069 - 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).
7170
71
7272 - getting started:
7373   - initialisation: call ImGui::GetIO() and fill the 'Settings' data.
7474   - every frame:
r245117r245118
9696        // TODO: store your texture pointer/identifier in 'io.Fonts->TexID'
9797
9898        // Application main loop
99        while (true)
99        for (;;)
100100        {
101101            // 1) get low-level input
102102            // e.g. on Win32, GetKeyboardState(), or poll your events, etc.
r245117r245118
129129 Occasionally introducing changes that are breaking the API. The breakage are generally minor and easy to fix.
130130 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.
131131
132 - 2015/03/08 (1.35) - renamed style.ScrollBarWidth to style.ScrollbarWidth
133 - 2015/02/27 (1.34) - renamed OpenNextNode(bool) to SetNextTreeNodeOpened(bool, ImGuiSetCond), kept inline redirection function.
134 - 2015/02/27 (1.34) - renamed ImGuiSetCondition_*** to ImGuiSetCond_***, and _FirstUseThisSession becomes _Once.
135 - 2015/02/11 (1.32) - changed text input callback ImGuiTextEditCallback return type from void-->int. reserved for future use, return 0 for now.
136132 - 2015/02/10 (1.32) - renamed GetItemWidth() to CalcItemWidth() to clarify its evolving behavior
137133 - 2015/02/08 (1.31) - renamed GetTextLineSpacing() to GetTextLineHeightWithSpacing()
138134 - 2015/02/01 (1.31) - removed IO.MemReallocFn (unused)
r245117r245118
168164 - 2014/08/28 (1.09) - changed the behavior of IO.PixelCenterOffset following various rendering fixes
169165
170166
171 FREQUENTLY ASKED QUESTIONS (FAQ) & TROUBLESHOOTING
172 ==================================================
167 TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS
168 ============================================
173169
174170 If text or lines are blurry when integrating ImGui in your engine:
175
176171   - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
177172
178 A primer on the meaning and use of ID in ImGui:
179
180   - widgets require state to be carried over multiple frames (most typically ImGui often needs to remember what is the "active" widget).
181     to do so they need an unique ID. unique ID are typically derived from a string label, an integer index or a pointer.
182
183       Button("OK");        // Label = "OK",     ID = hash of "OK"
184       Button("Cancel");    // Label = "Cancel", ID = hash of "Cancel"
185
173 If you are confused about the meaning or use of ID in ImGui:
174   - many widgets requires state to be carried over multiple frames (most typically ImGui often wants remember what is the "active" widget).
175     to do so they need an unique ID. unique ID are typically derived from a string label, an indice or a pointer.
176     when you call Button("OK") the button shows "OK" and also use "OK" as an ID.
186177   - ID are uniquely scoped within Windows so no conflict can happen if you have two buttons called "OK" in two different Windows.
178     within a same Window, use PushID() / PopID() to easily create scopes and avoid ID conflicts.
179     so if you have a loop creating "multiple" items, you can use PushID() / PopID() with the index of each item, or their pointer, etc.
180     some functions like TreeNode() implicitly creates a scope for you by calling PushID()
181   - when dealing with trees, ID are important because you want to preserve the opened/closed state of tree nodes.
182     depending on your use cases you may want to use strings, indices or pointers as ID. experiment and see what makes more sense!
183      e.g. When displaying a single object that may change over time, using a static string as ID will preserve your node open/closed state when the targeted object change
184      e.g. When displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state per object
185   - when passing a label you can optionally specify extra unique ID information within the same string using "##". This helps solving the simpler collision cases.
186      e.g. "Label" display "Label" and uses "Label" as ID
187      e.g. "Label##Foobar" display "Label" and uses "Label##Foobar" as ID
188      e.g. "##Foobar" display an empty label and uses "##Foobar" as ID
189   - read articles about immediate-mode ui principles (see web links) to understand the requirement and use of ID.
187190
188   - when passing a label you can optionally specify extra unique ID information within string itself. This helps solving the simpler collision cases.
189     use "##" to pass a complement to the ID that won't be visible to the end-user:
190
191       Button("Play##0");   // Label = "Play",   ID = hash of "Play##0"
192       Button("Play##1");   // Label = "Play",   ID = hash of "Play##1" (different from above)
193
194     use "###" to pass a label that isn't part of ID. You can use that to change labels while preserving a constant ID.
195
196       Button("Hello###ID"; // Label = "Hello",  ID = hash of "ID"
197       Button("World###ID"; // Label = "World",  ID = hash of "ID" (same as above)
198
199   - use PushID() / PopID() to create scopes and avoid ID conflicts within the same Window:
200
201       Button("Click");     // Label = "Click",  ID = hash of "Click"
202       PushID("node");
203       Button("Click");     // Label = "Click",  ID = hash of "node" and "Click"
204       for (int i = 0; i < 100; i++)
205       {
206          PushID(i);
207          Button("Click");  // Label = "Click",  ID = hash of "node" and i and "label"
208          PopID();
209       }
210       PopID();
211       PushID(my_ptr);
212       Button("Click");     // Label = "Click",  ID = hash of ptr and "Click"
213       PopID();
214
215     so if you have a loop creating multiple items, you can use PushID() / PopID() with the index of each item, or their pointer, etc.
216     some functions like TreeNode() implicitly creates a scope for you by calling PushID().
217
218   - when working with trees, ID are used to preserve the opened/closed state of tree nodes.
219     depending on your use cases you may want to use strings, indices or pointers as ID.
220      e.g. when displaying a single object that may change over time (1-1 relationship), using a static string as ID will preserve your node open/closed state when the targeted object change.
221      e.g. when displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state differently. experiment and see what makes more sense!
222
223191 If you want to load a different font than the default (ProggyClean.ttf, size 13)
224192
225193     io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);
r245117r245118
236204
237205     io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, io.Fonts->GetGlyphRangesJapanese());  // Load Japanese characters
238206     io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
239     io.ImeWindowHandle = MY_HWND;      // To input using Microsoft IME, give ImGui the hwnd of your application
240207
208 If you want to input Japanese/Chinese/Korean in the text input widget:
209
210    - when loading the font, pass a range that contains the characters you need, e.g.: io.Fonts->GetGlyphRangesJapanese()
211    - to have the Microsoft IME cursor appears at the right location in the screen, setup a handler for the io.ImeSetInputScreenPosFn function:
212
213        #include <Windows.h>
214        #include <Imm.h>
215        static void ImImpl_ImeSetInputScreenPosFn(int x, int y)
216        {
217          // Notify OS Input Method Editor of text input position
218          HWND hwnd = glfwGetWin32Window(window);
219          if (HIMC himc = ImmGetContext(hwnd))
220          {
221            COMPOSITIONFORM cf;
222            cf.ptCurrentPos.x = x;
223            cf.ptCurrentPos.y = y;
224            cf.dwStyle = CFS_FORCE_POSITION;
225            ImmSetCompositionWindow(himc, &cf);
226          }
227        }
228
229        // Set pointer to handler in ImGuiIO structure
230        io.ImeSetInputScreenPosFn = ImImpl_ImeSetInputScreenPosFn;
231
241232 - 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.
242233 - tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug"
243234 - tip: you can call Begin() multiple times with the same name during the same frame, it will keep appending to the same window.
r245117r245118
263254 - 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?
264255 - 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
265256 - main: IsItemHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode?
257 - scrollbar: use relative mouse movement when first-clicking inside of scroll grab box.
258 - scrollbar: make the grab visible and a minimum size for long scroll regions
266259!- input number: very large int not reliably supported because of int<>float conversions.
267260 - input number: optional range min/max for Input*() functions
268261 - input number: holding [-]/[+] buttons could increase the step speed non-linearly (or user-controlled)
r245117r245118
275268 - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills)
276269 - columns: columns header to act as button (~sort op) and allow resize/reorder
277270 - columns: user specify columns size
278 - columns: tree node example, removing the last NextColumn() makes a padding difference (it should not)
279271 - combo: turn child handling code into pop up helper
280272 - combo: contents should extends to fit label if combo widget is small
281273 - listbox: multiple selection
r245117r245118
289281 - 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)
290282 - file selection widget -> build the tool in our codebase to improve model-dialog idioms
291283 - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt()
292 - slider: initial absolute click is imprecise. change to relative movement slider? hide mouse cursor, allow more precise input using less screen-space. same as scrollbar.
293 - text edit: clean up the mess caused by converting UTF-8 <> wchar. the code is rather inefficient right now.
284 - slider: initial absolute click is imprecise. change to relative movement slider? hide mouse cursor, allow more precise input using less screen-space.
285 - text edit: clean up the mess caused by converting UTF-8 <> wchar. the code is rather ineficient right now.
294286 - text edit: centered text for slider as input text so it matches typical positioning.
295287 - text edit: flag to disable live update of the user buffer.
296288 - text edit: field resize behavior - field could stretch when being edited? hover tooltip shows more text?
r245117r245118
301293 ! style: store rounded corners in texture to use 1 quad per corner (filled and wireframe). so rounding have minor cost.
302294 - style: checkbox: padding for "active" color should be a multiplier of the
303295 - style: colorbox not always square?
304 - text: simple markup language for color change?
305296 - log: LogButtons() options for specifying depth and/or hiding depth slider
306297 - log: have more control over the log scope (e.g. stop logging when leaving current tree node scope)
307298 - log: be able to right-click and log a window or tree-node into tty/file/clipboard / generalized context menu?
r245117r245118
349340#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.
350341#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.
351342#pragma clang diagnostic ignored "-Wglobal-constructors"    // warning : declaration requires a global destructor           // similar to above, not sure what the exact difference it.
352#pragma clang diagnostic ignored "-Wsign-conversion"        // warning : implicit conversion changes signedness             //
343#pragma clang diagnostic ignored "-Wsign-conversion"        // warning : implicit conversion chanjges signedness            //
344#elif defined(__GNUC__)
345#pragma GCC diagnostic ignored "-Wtype-limits"
346#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
347#pragma GCC diagnostic ignored "-Wunused-function"
353348#endif
354#ifdef __GNUC__
355#pragma GCC diagnostic ignored "-Wunused-function"          // warning: 'xxxx' defined but not used
356#pragma GCC diagnostic ignored "-Wunused-parameter"         // warning: unused parameter ‘xxxx’
357#pragma GCC diagnostic ignored "-Wtype-limits"              // warning: comparison is always true due to limited range of data type
358#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"      // warning: ‘xxxx’ may be used uninitialized in this function
359#endif
360349
361350//-------------------------------------------------------------------------
362351// STB libraries implementation
r245117r245118
395384#endif
396385#include "stb_truetype.h"
397386
398#define STB_TEXTEDIT_STRING    ImGuiTextEditState
399#define STB_TEXTEDIT_CHARTYPE  ImWchar
387#define STB_TEXTEDIT_STRING ImGuiTextEditState
388#define STB_TEXTEDIT_CHARTYPE ImWchar
400389#include "stb_textedit.h"
401390
402391#ifdef __clang__
r245117r245118
412401// Forward Declarations
413402//-------------------------------------------------------------------------
414403
415struct ImGuiColMod;
416struct ImGuiStyleMod;
417404struct ImGuiAabb;
418struct ImGuiDrawContext;
419struct ImGuiTextEditState;
420struct ImGuiIniData;
421struct ImGuiState;
422struct ImGuiWindow;
423405
424406static 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);
425407static void         LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL);
r245117r245118
431413static void         RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false);
432414
433415static void         SetFont(ImFont* font);
434static bool         ItemAdd(const ImGuiAabb& bb, const ImGuiID* id);
416static bool         ItemAdd(const ImGuiAabb& aabb, const ImGuiID* id);
435417static void         ItemSize(ImVec2 size, ImVec2* adjust_start_offset = NULL);
436static void         ItemSize(const ImGuiAabb& bb, ImVec2* adjust_start_offset = NULL);
418static void         ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset = NULL);
437419static void         PushColumnClipRect(int column_index = -1);
438static bool         IsClipped(const ImGuiAabb& bb);
420static bool         IsClipped(const ImGuiAabb& aabb);
439421
440static bool         IsMouseHoveringBox(const ImGuiAabb& bb);
422static bool         IsMouseHoveringBox(const ImGuiAabb& box);
441423static bool         IsKeyPressedMap(ImGuiKey key, bool repeat = true);
442424
443static void         Scrollbar(ImGuiWindow* window);
444425static bool         CloseWindowButton(bool* p_opened = NULL);
445426static void         FocusWindow(ImGuiWindow* window);
446427static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs);
r245117r245118
455436static size_t       ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args);
456437
457438// Helpers: Misc
458static ImU32        ImHash(const void* data, size_t data_size, ImU32 seed);
439static ImU32        ImCrc32(const void* data, size_t data_size, ImU32 seed);
459440static bool         ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes = 0);
460static inline int   ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; }
461static inline bool  ImCharIsSpace(int c) { return c == ' ' || c == '\t' || c == 0x3000; }
441static int          ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; }
462442
463443// Helpers: UTF-8 <> wchar
464444static int          ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int in_char);                                // return output UTF-8 bytes count
465445static ptrdiff_t    ImTextStrToUtf8(char* buf, size_t buf_size, const ImWchar* in_text, const ImWchar* in_text_end);   // return output UTF-8 bytes count
466446static int          ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end);          // return input UTF-8 bytes count
467static ptrdiff_t    ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end, const char** in_remaining = NULL);   // return input UTF-8 bytes count
447static ptrdiff_t    ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end);    // return input UTF-8 bytes count
468448static int          ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end);                            // return number of UTF-8 code-points (NOT bytes count)
469static int          ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end);                   // return number of bytes to express string as UTF-8 code-points
449static int          ImTextCountUtf8BytesFromWchar(const ImWchar* in_text, const ImWchar* in_text_end);                 // return number of bytes to express string as UTF-8 code-points
470450
471451//-----------------------------------------------------------------------------
472452// Platform dependent default implementations
r245117r245118
474454
475455static const char*  GetClipboardTextFn_DefaultImpl();
476456static void         SetClipboardTextFn_DefaultImpl(const char* text);
477static void         ImeSetInputScreenPosFn_DefaultImpl(int x, int y);
478457
479458//-----------------------------------------------------------------------------
480459// Texture Atlas data
r245117r245118
507486    WindowFillAlphaDefault  = 0.70f;            // Default alpha of window background, if not specified in ImGui::Begin()
508487    TreeNodeSpacing         = 22.0f;            // Horizontal spacing when entering a tree node
509488    ColumnsMinSpacing       = 6.0f;             // Minimum horizontal spacing between two columns
510    ScrollbarWidth          = 16.0f;            // Width of the vertical scrollbar
511    GrabMinSize             = 10.0f;            // Minimum width/height of a slider or scrollbar grab
489    ScrollBarWidth          = 16.0f;            // Width of the vertical scroll bar
512490
513491    Colors[ImGuiCol_Text]                   = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
514492    Colors[ImGuiCol_WindowBg]               = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
r245117r245118
551529    Colors[ImGuiCol_TooltipBg]              = ImVec4(0.05f, 0.05f, 0.10f, 0.90f);
552530}
553531
554// Statically allocated font atlas. This is merely a maneuver to keep ImFontAtlas definition at the bottom of the .h file (otherwise it'd be inside ImGuiIO)
555// Also we wouldn't be able to new() one at this point, before users may define IO.MemAllocFn.
532// Statically allocated font atlas. This is merely a maneuver to keep its definition at the bottom of the .H file.
533// Because we cannot new() at this point (before users may define IO.MemAllocFn)
556534static ImFontAtlas GDefaultFontAtlas;
557535
558536ImGuiIO::ImGuiIO()
r245117r245118
579557    MemFreeFn = free;
580558    GetClipboardTextFn = GetClipboardTextFn_DefaultImpl;   // Platform dependent default implementations
581559    SetClipboardTextFn = SetClipboardTextFn_DefaultImpl;
582    ImeSetInputScreenPosFn = ImeSetInputScreenPosFn_DefaultImpl;
560    ImeSetInputScreenPosFn = NULL;
583561}
584562
585563// Pass in translated ASCII characters for text input.
586564// - with glfw you can get those from the callback set in glfwSetCharCallback()
587// - on Windows you can get those using ToAscii+keyboard state, or via the WM_CHAR message
565// - on Windows you can get those using ToAscii+keyboard state, or via the VM_CHAR message
588566void ImGuiIO::AddInputCharacter(ImWchar c)
589567{
590568    const size_t n = ImStrlenW(InputCharacters);
r245117r245118
610588#define IM_INT_MAX 2147483647
611589#endif
612590
613// Play it nice with Windows users. Notepad in 2015 still doesn't display text data with Unix-style \n.
591// Play it nice with Windows users. Notepad in 2014 still doesn't display text data with Unix-style \n.
614592#ifdef _MSC_VER
615593#define STR_NEWLINE "\r\n"
616594#else
r245117r245118
669647static size_t ImStrlenW(const ImWchar* str)
670648{
671649    size_t n = 0;
672    while (*str++) n++;
650    while (*str++)
651        n++;
673652    return n;
674653}
675654
r245117r245118
696675}
697676
698677// Pass data_size==0 for zero-terminated string
699// Try to replace with FNV1a hash?
700static ImU32 ImHash(const void* data, size_t data_size, ImU32 seed = 0)
678static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed = 0)
701679{
702680    static ImU32 crc32_lut[256] = { 0 };
703681    if (!crc32_lut[1])
r245117r245118
711689            crc32_lut[i] = crc;
712690        }
713691    }
714
715    seed = ~seed;
716    ImU32 crc = seed;
692    ImU32 crc = ~seed;
717693    const unsigned char* current = (const unsigned char*)data;
718694
719695    if (data_size > 0)
r245117r245118
726702    {
727703        // Zero-terminated string
728704        while (unsigned char c = *current++)
729        {
730            // We support a syntax of "label###id" where only "###id" is included in the hash, and only "label" gets displayed.
731            // Because this syntax is rarely used we are optimizing for the common case.
732            // - If we reach ### in the string we discard the hash so far and reset to the seed.
733            // - We don't do 'current += 2; continue;' after handling ### to keep the code smaller.
734            if (c == '#' && current[0] == '#' && current[1] == '#')
735                crc = seed;
736
737705            crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
738        }
739706    }
740707    return ~crc;
741708}
r245117r245118
874841    ImVec2      PreviousValue;
875842};
876843
877struct ImGuiAabb        // 2D axis aligned bounding-box
844struct ImGuiAabb    // 2D axis aligned bounding-box
878845{
879846    ImVec2      Min;
880847    ImVec2      Max;
r245117r245118
920887    ImVector<float>         TextWrapPos;
921888    ImGuiColorEditMode      ColorEditMode;
922889    ImGuiStorage*           StateStorage;
890    int                     OpenNextNode;        // FIXME: Reformulate this feature like SetNextWindowCollapsed() API
923891
924892    float                   ColumnsStartX;       // Start position from left of window (increased by TreePush/TreePop, etc.)
925893    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.
r245117r245118
930898    float                   ColumnsCellMaxY;
931899    bool                    ColumnsShowBorders;
932900    ImGuiID                 ColumnsSetID;
933    ImVector<float>         ColumnsOffsetsT;     // Columns offset normalized 0.0 (far left) -> 1.0 (far right)
934901
935902    ImGuiDrawContext()
936903    {
r245117r245118
942909        LastItemAabb = ImGuiAabb(0.0f,0.0f,0.0f,0.0f);
943910        LastItemHovered = false;
944911        StateStorage = NULL;
912        OpenNextNode = -1;
945913
946914        ColumnsStartX = 0.0f;
947915        ColumnsOffsetX = 0.0f;
r245117r245118
957925// Internal state of the currently focused/edited text input box
958926struct ImGuiTextEditState
959927{
960    ImGuiID             Id;                             // widget id owning the text state
961928    ImWchar             Text[1024];                     // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so we copy into own buffer.
962    char                InitialText[1024*4+1];          // backup of end-user buffer at the time of focus (in UTF-8, unaltered)
963    int                 CurLenA, CurLenW;               // we need to maintain our buffer length in both UTF-8 and wchar format.
964    size_t              BufSizeA;                       // end-user buffer size, <= 1024 (or increase above)
929    char                InitialText[1024*3+1];          // backup of end-user buffer at the time of focus (in UTF-8, unconverted)
930    size_t              BufSize;                        // end-user buffer size, <= 1024 (or increase above)
965931    float               Width;                          // widget width
966932    float               ScrollX;
967933    STB_TexteditState   StbState;
968934    float               CursorAnim;
969    ImVec2              InputCursorScreenPos;           // Cursor position in screen space to be used by IME callback.
935    ImVec2              LastCursorPos;                  // Cursor position in screen space to be used by IME callback.
970936    bool                SelectedAllMouseLock;
971937    ImFont*             Font;
972938    float               FontSize;
r245117r245118
988954    static void             RenderTextScrolledClipped(ImFont* font, float font_size, const char* text, ImVec2 pos_base, float width, float scroll_x);
989955};
990956
991// Data saved in imgui.ini file
992957struct ImGuiIniData
993958{
994959    char*   Name;
995    ImGuiID ID;
996960    ImVec2  Pos;
997961    ImVec2  Size;
998962    bool    Collapsed;
r245117r245118
1001965    ~ImGuiIniData() { if (Name) { ImGui::MemFree(Name); Name = NULL; } }
1002966};
1003967
1004// Main state for ImGui
1005968struct ImGuiState
1006969{
1007970    bool                    Initialized;
r245117r245118
1024987    ImGuiID                 ActiveId;
1025988    ImGuiID                 ActiveIdPreviousFrame;
1026989    bool                    ActiveIdIsAlive;
1027    bool                    ActiveIdIsFocusedOnly;              // Set only by active widget. Denote focus but no active interaction.
1028    ImGuiWindow*            MovedWindow;                        // Track the child window we clicked on to move a window. Only valid if ActiveID is the "#MOVE" identifier of a window.
1029990    float                   SettingsDirtyTimer;
1030991    ImVector<ImGuiIniData*> Settings;
1031992    ImVector<ImGuiColMod>   ColorModifiers;
1032993    ImVector<ImGuiStyleMod> StyleModifiers;
1033994    ImVector<ImFont*>       FontStack;
1034
1035995    ImVec2                  SetNextWindowPosVal;
1036    ImGuiSetCond            SetNextWindowPosCond;
996    ImGuiSetCondition       SetNextWindowPosCond;
1037997    ImVec2                  SetNextWindowSizeVal;
1038    ImGuiSetCond            SetNextWindowSizeCond;
998    ImGuiSetCondition       SetNextWindowSizeCond;
1039999    bool                    SetNextWindowCollapsedVal;
1040    ImGuiSetCond            SetNextWindowCollapsedCond;
1041    bool                    SetNextWindowFocus;
1042    bool                    SetNextTreeNodeOpenedVal;
1043    ImGuiSetCond            SetNextTreeNodeOpenedCond;
1000    ImGuiSetCondition       SetNextWindowCollapsedCond;
10441001
10451002    // Render
10461003    ImVector<ImDrawList*>   RenderDrawLists;
r245117r245118
10511008    ImGuiID                 SliderAsInputTextId;
10521009    ImGuiStorage            ColorEditModeStorage;               // for user selection
10531010    ImGuiID                 ActiveComboID;
1054    float                   ScrollbarClickDeltaToGrabCenter;    // distance between mouse and center of grab box, normalized in parent space
10551011    char                    Tooltip[1024];
10561012    char*                   PrivateClipboard;                   // if no custom clipboard handler is defined
10571013
r245117r245118
10621018    int                     LogStartDepth;
10631019    int                     LogAutoExpandMaxDepth;
10641020
1065    // Misc
1066    float                   FramerateSecPerFrame[120];          // calculate estimate of framerate for user
1067    int                     FramerateSecPerFrameIdx;
1068    float                   FramerateSecPerFrameAccum;
1069
10701021    ImGuiState()
10711022    {
10721023        Initialized = false;
1073        Font = NULL;
1074        FontSize = 0.0f;
1075        FontTexUvWhitePixel = ImVec2(0.0f, 0.0f);
1076
10771024        Time = 0.0f;
10781025        FrameCount = 0;
10791026        FrameCountRendered = -1;
r245117r245118
10811028        FocusedWindow = NULL;
10821029        HoveredWindow = NULL;
10831030        HoveredRootWindow = NULL;
1084        HoveredId = 0;
1085        ActiveId = 0;
1086        ActiveIdPreviousFrame = 0;
10871031        ActiveIdIsAlive = false;
1088        ActiveIdIsFocusedOnly = false;
1089        MovedWindow = NULL;
10901032        SettingsDirtyTimer = 0.0f;
1091
10921033        SetNextWindowPosVal = ImVec2(0.0f, 0.0f);
10931034        SetNextWindowPosCond = 0;
10941035        SetNextWindowSizeVal = ImVec2(0.0f, 0.0f);
10951036        SetNextWindowSizeCond = 0;
10961037        SetNextWindowCollapsedVal = false;
10971038        SetNextWindowCollapsedCond = 0;
1098        SetNextWindowFocus = false;
1099        SetNextTreeNodeOpenedVal = false;
1100        SetNextTreeNodeOpenedCond = 0;
1101
11021039        SliderAsInputTextId = 0;
11031040        ActiveComboID = 0;
1104        ScrollbarClickDeltaToGrabCenter = 0.0f;
11051041        memset(Tooltip, 0, sizeof(Tooltip));
11061042        PrivateClipboard = NULL;
1107
11081043        LogEnabled = false;
11091044        LogFile = NULL;
1110        LogClipboard = NULL;
11111045        LogStartDepth = 0;
11121046        LogAutoExpandMaxDepth = 2;
1113
1114        memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame));
1115        FramerateSecPerFrameIdx = 0;
1116        FramerateSecPerFrameAccum = 0.0f;
1047        LogClipboard = NULL;
11171048    }
11181049};
11191050
r245117r245118
11291060    ImVec2                  Pos;                                // Position rounded-up to nearest pixel
11301061    ImVec2                  Size;                               // Current size (==SizeFull or collapsed title bar size)
11311062    ImVec2                  SizeFull;                           // Size when non collapsed
1132    ImVec2                  SizeContents;                       // Size of contents (== extents reach of the drawing cursor) from previous frame
1133    ImVec2                  SizeContentsCurrent;                // Size of contents, currently extending
1063    ImVec2                  SizeContentsFit;                    // Size of contents (extents reach by the drawing cursor) - may not fit within Size.
11341064    float                   ScrollY;
11351065    float                   NextScrollY;
11361066    bool                    ScrollbarY;
r245117r245118
11401070    bool                    SkipItems;                          // == Visible && !Collapsed
11411071    int                     AutoFitFrames;
11421072    bool                    AutoFitOnlyGrows;
1143    int                     SetWindowPosAllowFlags;             // bit ImGuiSetCond_*** specify if SetWindowPos() call is allowed with this particular flag.
1144    int                     SetWindowSizeAllowFlags;            // bit ImGuiSetCond_*** specify if SetWindowSize() call is allowed with this particular flag.
1145    int                     SetWindowCollapsedAllowFlags;       // bit ImGuiSetCond_*** specify if SetWindowCollapsed() call is allowed with this particular flag.
1073    int                     SetWindowPosAllowFlags;             // bit ImGuiSetCondition_*** specify if SetWindowPos() call is allowed with this particular flag.
1074    int                     SetWindowSizeAllowFlags;            // bit ImGuiSetCondition_*** specify if SetWindowSize() call is allowed with this particular flag.
1075    int                     SetWindowCollapsedAllowFlags;       // bit ImGuiSetCondition_*** specify if SetWindowCollapsed() call is allowed with this particular flag.
11461076
11471077    ImGuiDrawContext        DC;
11481078    ImVector<ImGuiID>       IDStack;
11491079    ImVector<ImVec4>        ClipRectStack;                      // Scissoring / clipping rectangle. x1, y1, x2, y2.
1150    ImGuiAabb               ClippedAabb;                        // = ClipRectStack.front() after setup in Begin()
11511080    int                     LastFrameDrawn;
11521081    float                   ItemWidthDefault;
11531082    ImGuiStorage            StateStorage;
r245117r245118
11801109    ImVec2      CursorPos() const                       { return DC.CursorPos; }
11811110    float       TitleBarHeight() const                  { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : FontSize() + GImGui->Style.FramePadding.y * 2.0f; }
11821111    ImGuiAabb   TitleBarAabb() const                    { return ImGuiAabb(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); }
1183    ImVec2      WindowPadding() const                   { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders)) ? ImVec2(0,0) : GImGui->Style.WindowPadding; }
1112    ImVec2      WindowPadding() const                   { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders)) ? ImVec2(1,1) : GImGui->Style.WindowPadding; }
11841113    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); }
11851114    ImU32       Color(const ImVec4& col) const          { ImVec4 c = col; c.w *= GImGui->Style.Alpha; return ImGui::ColorConvertFloat4ToU32(c); }
11861115};
11871116
1188static inline ImGuiWindow* GetCurrentWindow()
1117static ImGuiWindow* GetCurrentWindow()
11891118{
11901119    ImGuiState& g = *GImGui;
11911120    IM_ASSERT(g.CurrentWindow != NULL);    // ImGui::NewFrame() hasn't been called yet?
r245117r245118
11931122    return g.CurrentWindow;
11941123}
11951124
1196static inline ImGuiWindow* GetParentWindow()
1197{
1198    ImGuiState& g = *GImGui;
1199    IM_ASSERT(g.CurrentWindowStack.size() >= 2);
1200    return g.CurrentWindowStack[g.CurrentWindowStack.size() - 2];
1201}
1202
12031125static void SetActiveId(ImGuiID id)
12041126{
12051127    ImGuiState& g = *GImGui;
12061128    g.ActiveId = id;
1207    g.ActiveIdIsFocusedOnly = false;
12081129}
12091130
12101131static void RegisterAliveId(const ImGuiID& id)
r245117r245118
13301251//-----------------------------------------------------------------------------
13311252
13321253// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
1333ImGuiTextFilter::ImGuiTextFilter(const char* default_filter)
1254ImGuiTextFilter::ImGuiTextFilter()
13341255{
1335    if (default_filter)
1336    {
1337        ImFormatString(InputBuf, IM_ARRAYSIZE(InputBuf), "%s", default_filter);
1338        Build();
1339    }
1340    else
1341    {
1342        InputBuf[0] = 0;
1343        CountGrep = 0;
1344    }
1256    InputBuf[0] = 0;
1257    CountGrep = 0;
13451258}
13461259
13471260void ImGuiTextFilter::Draw(const char* label, float width)
13481261{
1349    if (width > 0.0f)
1350        ImGui::PushItemWidth(width);
1262    ImGuiWindow* window = GetCurrentWindow();
1263    if (width < 0.0f)
1264    {
1265        ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
1266        width = ImMax(window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x - (label_size.x + GImGui->Style.ItemSpacing.x*4), 10.0f);
1267    }
1268    ImGui::PushItemWidth(width);
13511269    ImGui::InputText(label, InputBuf, IM_ARRAYSIZE(InputBuf));
1352    if (width > 0.0f)
1353        ImGui::PopItemWidth();
1270    ImGui::PopItemWidth();
13541271    Build();
13551272}
13561273
r245117r245118
14661383ImGuiWindow::ImGuiWindow(const char* name)
14671384{
14681385    Name = ImStrdup(name);
1469    ID = ImHash(name, 0);
1386    ID = GetID(name);
14701387    IDStack.push_back(ID);
14711388
1472    Flags = 0;
14731389    PosFloat = Pos = ImVec2(0.0f, 0.0f);
14741390    Size = SizeFull = ImVec2(0.0f, 0.0f);
1475    SizeContents = SizeContentsCurrent = ImVec2(0.0f, 0.0f);
1391    SizeContentsFit = ImVec2(0.0f, 0.0f);
14761392    ScrollY = 0.0f;
14771393    NextScrollY = 0.0f;
14781394    ScrollbarY = false;
r245117r245118
14821398    SkipItems = false;
14831399    AutoFitFrames = -1;
14841400    AutoFitOnlyGrows = false;
1485    SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiSetCond_Always | ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver;
1401    SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiSetCondition_Always | ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver;
14861402
14871403    LastFrameDrawn = -1;
14881404    ItemWidthDefault = 0.0f;
r245117r245118
14961412
14971413    DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList));
14981414    new(DrawList) ImDrawList();
1499    RootWindow = NULL;
15001415
15011416    FocusIdxAllCounter = FocusIdxTabCounter = -1;
15021417    FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = IM_INT_MAX;
r245117r245118
15141429
15151430ImGuiID ImGuiWindow::GetID(const char* str)
15161431{
1517    ImGuiID seed = IDStack.back();
1518    const ImGuiID id = ImHash(str, 0, seed);
1432    const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back();
1433    const ImGuiID id = ImCrc32(str, 0, seed);
15191434    RegisterAliveId(id);
15201435    return id;
15211436}
15221437
15231438ImGuiID ImGuiWindow::GetID(const void* ptr)
15241439{
1525    ImGuiID seed = IDStack.back();
1526    const ImGuiID id = ImHash(&ptr, sizeof(void*), seed);
1440    const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back();
1441    const ImGuiID id = ImCrc32(&ptr, sizeof(void*), seed);
15271442    RegisterAliveId(id);
15281443    return id;
15291444}
r245117r245118
15951510static ImGuiIniData* FindWindowSettings(const char* name)
15961511{
15971512    ImGuiState& g = *GImGui;
1598    ImGuiID id = ImHash(name, 0);
15991513    for (size_t i = 0; i != g.Settings.size(); i++)
16001514    {
16011515        ImGuiIniData* ini = g.Settings[i];
1602        if (ini->ID == id)
1516        if (ImStricmp(ini->Name, name) == 0)
16031517            return ini;
16041518    }
16051519    return NULL;
r245117r245118
16101524    ImGuiIniData* ini = (ImGuiIniData*)ImGui::MemAlloc(sizeof(ImGuiIniData));
16111525    new(ini) ImGuiIniData();
16121526    ini->Name = ImStrdup(name);
1613    ini->ID = ImHash(name, 0);
16141527    ini->Collapsed = false;
16151528    ini->Pos = ImVec2(FLT_MAX,FLT_MAX);
16161529    ini->Size = ImVec2(0,0);
r245117r245118
16951608        const ImGuiIniData* settings = g.Settings[i];
16961609        if (settings->Pos.x == FLT_MAX)
16971610            continue;
1698        const char* name = settings->Name;
1699        if (const char* p = strstr(name, "###"))  // Skip to the "###" marker if any. We don't skip past to match the behavior of GetID()
1700            name = p;
1701        fprintf(f, "[%s]\n", name);
1611        fprintf(f, "[%s]\n", settings->Name);
17021612        fprintf(f, "Pos=%d,%d\n", (int)settings->Pos.x, (int)settings->Pos.y);
17031613        fprintf(f, "Size=%d,%d\n", (int)settings->Size.x, (int)settings->Size.y);
17041614        fprintf(f, "Collapsed=%d\n", settings->Collapsed);
r245117r245118
18051715    for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++)
18061716        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;
18071717
1808    // Calculate frame-rate for the user, as a purely luxurious feature
1809    g.FramerateSecPerFrameAccum += g.IO.DeltaTime - g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx];
1810    g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx] = g.IO.DeltaTime;
1811    g.FramerateSecPerFrameIdx = (g.FramerateSecPerFrameIdx + 1) % IM_ARRAYSIZE(g.FramerateSecPerFrame);
1812    g.IO.Framerate = 1.0f / (g.FramerateSecPerFrameAccum / (float)IM_ARRAYSIZE(g.FramerateSecPerFrame));
1813
18141718    // Clear reference to active widget if the widget isn't alive anymore
18151719    g.HoveredId = 0;
18161720    if (!g.ActiveIdIsAlive && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0)
18171721        SetActiveId(0);
18181722    g.ActiveIdPreviousFrame = g.ActiveId;
18191723    g.ActiveIdIsAlive = false;
1820    if (!g.ActiveId)
1821        g.MovedWindow = NULL;
18221724
18231725    // Delay saving settings so we don't spam disk too much
18241726    if (g.SettingsDirtyTimer > 0.0f)
r245117r245118
18931795    }
18941796
18951797    // Mark all windows as not visible
1798    // Clear root windows at this point.
18961799    for (size_t i = 0; i != g.Windows.size(); i++)
18971800    {
18981801        ImGuiWindow* window = g.Windows[i];
18991802        window->Visible = false;
19001803        window->Accessed = false;
1804        window->RootWindow = NULL;
19011805    }
19021806
19031807    // No window should be open at the beginning of the frame.
r245117r245118
20281932            g.CurrentWindow->Visible = false;
20291933        ImGui::End();
20301934
2031        // Select window for move/focus when we're done with all our widgets (we use the root window ID here)
1935        // Select window for move/focus when we're done with all our widgets (we only consider non-child windows here)
20321936        if (g.ActiveId == 0 && g.HoveredId == 0 && g.HoveredRootWindow != NULL && g.IO.MouseClicked[0])
2033        {
2034            IM_ASSERT(g.MovedWindow == NULL);
2035            g.MovedWindow = g.HoveredWindow;
20361937            SetActiveId(g.HoveredRootWindow->GetID("#MOVE"));
2037        }
20381938
20391939        // Sort the window list so that all child windows are after their parent
20401940        // We cannot do that on FocusWindow() because childs may not exist yet
r245117r245118
21102010static const char*  FindTextDisplayEnd(const char* text, const char* text_end = NULL)
21112011{
21122012    const char* text_display_end = text;
2113    if (!text_end)
2114        text_end = (const char*)-1;
2115    while (text_display_end < text_end && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#'))
2013    while ((!text_end || text_display_end < text_end) && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#'))
21162014        text_display_end++;
21172015    return text_display_end;
21182016}
r245117r245118
23192217
23202218    if (shadow && (window->Flags & ImGuiWindowFlags_ShowBorders) != 0)
23212219        window->DrawList->AddTriangleFilled(a+ImVec2(2,2), b+ImVec2(2,2), c+ImVec2(2,2), window->Color(ImGuiCol_BorderShadow));
2322    window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Text));
2220    window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Border));
23232221}
23242222
23252223// Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker.
r245117r245118
23962294            continue;
23972295        if (excluding_childs && (window->Flags & ImGuiWindowFlags_ChildWindow) != 0)
23982296            continue;
2399
2400        // Using the clipped AABB so a child window will typically be clipped by its parent.
2401        ImGuiAabb bb(window->ClippedAabb.Min - g.Style.TouchExtraPadding, window->ClippedAabb.Max + g.Style.TouchExtraPadding);
2297        ImGuiAabb bb(window->Pos - g.Style.TouchExtraPadding, window->Pos + window->Size + g.Style.TouchExtraPadding);
24022298        if (bb.Contains(pos))
24032299            return window;
24042300    }
r245117r245118
24082304// Test if mouse cursor is hovering given aabb
24092305// NB- Box is clipped by our current clip setting
24102306// NB- Expand the aabb to be generous on imprecise inputs systems (g.Style.TouchExtraPadding)
2411static bool IsMouseHoveringBox(const ImGuiAabb& bb)
2307static bool IsMouseHoveringBox(const ImGuiAabb& box)
24122308{
24132309    ImGuiState& g = *GImGui;
24142310    ImGuiWindow* window = GetCurrentWindow();
24152311
24162312    // Clip
2417    ImGuiAabb box_clipped = bb;
2313    ImGuiAabb box_clipped = box;
24182314    if (!window->ClipRectStack.empty())
24192315    {
24202316        const ImVec4 clip_rect = window->ClipRectStack.back();
r245117r245118
25212417    return false;
25222418}
25232419
2524bool ImGui::IsAnyItemActive()
2525{
2526    ImGuiState& g = *GImGui;
2527    return g.ActiveId != 0;
2528}
2529
25302420ImVec2 ImGui::GetItemBoxMin()
25312421{
25322422    ImGuiWindow* window = GetCurrentWindow();
r245117r245118
25772467    ImGui::End();
25782468}
25792469
2580bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags)
2470void ImGui::BeginChild(ImGuiID id, ImVec2 size, bool border, ImGuiWindowFlags extra_flags)
25812471{
2472    char str_id[32];
2473    ImFormatString(str_id, IM_ARRAYSIZE(str_id), "child_%x", id);
2474    ImGui::BeginChild(str_id, size, border, extra_flags);
2475}
2476
2477void ImGui::BeginChild(const char* str_id, ImVec2 size, bool border, ImGuiWindowFlags extra_flags)
2478{
25822479    ImGuiState& g = *GImGui;
25832480    ImGuiWindow* window = GetCurrentWindow();
25842481
r245117r245118
25862483
25872484    const ImVec2 content_max = window->Pos + ImGui::GetContentRegionMax();
25882485    const ImVec2 cursor_pos = window->Pos + ImGui::GetCursorPos();
2589    ImVec2 size = size_arg;
25902486    if (size.x <= 0.0f)
25912487    {
25922488        if (size.x == 0.0f)
r245117r245118
26072503    ImFormatString(title, IM_ARRAYSIZE(title), "%s.%s", window->Name, str_id);
26082504
26092505    const float alpha = 1.0f;
2610    bool ret = ImGui::Begin(title, NULL, size, alpha, flags);
2506    ImGui::Begin(title, NULL, size, alpha, flags);
26112507
26122508    if (!(window->Flags & ImGuiWindowFlags_ShowBorders))
26132509        g.CurrentWindow->Flags &= ~ImGuiWindowFlags_ShowBorders;
2614
2615    return ret;
26162510}
26172511
2618bool ImGui::BeginChild(ImGuiID id, const ImVec2& size, bool border, ImGuiWindowFlags extra_flags)
2619{
2620    char str_id[32];
2621    ImFormatString(str_id, IM_ARRAYSIZE(str_id), "child_%x", id);
2622    bool ret = ImGui::BeginChild(str_id, size, border, extra_flags);
2623    return ret;
2624}
2625
26262512void ImGui::EndChild()
26272513{
26282514    ImGuiWindow* window = GetCurrentWindow();
r245117r245118
26422528            sz.y = 0;
26432529
26442530        ImGui::End();
2645
2646        window = GetCurrentWindow();
2647        ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + sz);
26482531        ItemSize(sz);
2649        ItemAdd(bb, NULL);
26502532    }
26512533}
26522534
r245117r245118
26692551
26702552static ImGuiWindow* FindWindowByName(const char* name)
26712553{
2672    // FIXME-OPT: Store sorted hashes -> pointers.
2554    // FIXME-OPT: Consider optimizing this (e.g. sorted hashes to window pointers)
26732555    ImGuiState& g = *GImGui;
2674    ImGuiID id = ImHash(name, 0);
2675    for (size_t i = 0; i < g.Windows.size(); i++)
2676        if (g.Windows[i]->ID == id)
2556    for (size_t i = 0; i != g.Windows.size(); i++)
2557        if (strcmp(g.Windows[i]->Name, name) == 0)
26772558            return g.Windows[i];
26782559    return NULL;
26792560}
r245117r245118
27062587        }
27072588        else
27082589        {
2709            window->SetWindowPosAllowFlags &= ~ImGuiSetCond_FirstUseEver;
2710            window->SetWindowSizeAllowFlags &= ~ImGuiSetCond_FirstUseEver;
2711            window->SetWindowCollapsedAllowFlags &= ~ImGuiSetCond_FirstUseEver;
2590            window->SetWindowPosAllowFlags &= ~ImGuiSetCondition_FirstUseEver;
2591            window->SetWindowSizeAllowFlags &= ~ImGuiSetCondition_FirstUseEver;
2592            window->SetWindowCollapsedAllowFlags &= ~ImGuiSetCondition_FirstUseEver;
27122593        }
27132594
27142595        if (settings->Pos.x != FLT_MAX)
r245117r245118
27272608}
27282609
27292610// Push a new ImGui window to add widgets to.
2730// - 'size' for a regular window denote the initial size for first-time creation (no saved data) and isn't that useful. Use SetNextWindowSize() prior to calling Begin() for more flexible window manipulation.
2731// - A default window called "Debug" is automatically stacked at the beginning of every frame so you can use widgets without explicitly calling a Begin/End pair.
2732// - Begin/End can be called multiple times during the frame with the same window name to append content.
2733// - The window name is used as a unique identifier to preserve window information across frames (and save rudimentary information to the .ini file).
2734//   You can use the "##" or "###" markers to use the same label with different id, or same id with different label. See documentation at the top of this file.
2611// - A default window called "Debug" is automatically stacked at the beginning of every frame.
2612// - This can be called multiple times during the frame with the same window name to append content to the same window.
2613// - The window name is used as a unique identifier to preserve window information across frames (and save rudimentary information to the .ini file). Note that you can use ## to append unique data that isn't displayed, e.g. "My window##1" will use "My window##1" as unique window ID but display "My window" to the user.
27352614// - 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.
27362615// - Passing 'bool* p_opened' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed.
2737// - Passing non-zero 'size' is roughly equivalent to calling SetNextWindowSize(size, ImGuiSetCond_FirstUseEver) prior to calling Begin().
2738bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size, float bg_alpha, ImGuiWindowFlags flags)
2616// - Passing non-zero 'size' is roughly equivalent to calling SetNextWindowSize(size, ImGuiSetCondition_FirstUseEver) prior to calling Begin().
2617bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alpha, ImGuiWindowFlags flags)
27392618{
27402619    ImGuiState& g = *GImGui;
27412620    const ImGuiStyle& style = g.Style;
r245117r245118
27722651        ImGui::SetWindowCollapsed(g.SetNextWindowCollapsedVal, g.SetNextWindowCollapsedCond);
27732652        g.SetNextWindowCollapsedCond = 0;
27742653    }
2775    if (g.SetNextWindowFocus)
2776    {
2777        ImGui::SetWindowFocus();
2778        g.SetNextWindowFocus = false;
2779    }
27802654
27812655    // Find parent
27822656    ImGuiWindow* parent_window = (flags & ImGuiWindowFlags_ChildWindow) != 0 ? g.CurrentWindowStack[g.CurrentWindowStack.size()-2] : NULL;
27832657
2784    // Update known root window (if we are a child window, otherwise window == window->RootWindow)
2658    // Find root (if we are a child window)
27852659    size_t root_idx = g.CurrentWindowStack.size() - 1;
27862660    while (root_idx > 0)
27872661    {
r245117r245118
27922666    window->RootWindow = g.CurrentWindowStack[root_idx];
27932667
27942668    // Default alpha
2795    if (bg_alpha < 0.0f)
2796        bg_alpha = style.WindowFillAlphaDefault;
2669    if (fill_alpha < 0.0f)
2670        fill_alpha = style.WindowFillAlphaDefault;
27972671
27982672    // When reusing window again multiple times a frame, just append content (don't need to setup again)
27992673    const int current_frame = ImGui::GetFrameCount();
r245117r245118
28102684        window->LastFrameDrawn = current_frame;
28112685        window->ClipRectStack.resize(0);
28122686
2813        // Reset contents size for auto-fitting
2814        window->SizeContents = window->SizeContentsCurrent;
2815        window->SizeContentsCurrent = ImVec2(0.0f, 0.0f);
2816
28172687        if (flags & ImGuiWindowFlags_ChildWindow)
28182688        {
28192689            parent_window->DC.ChildWindows.push_back(window);
r245117r245118
28362706    // Setup and draw window
28372707    if (first_begin_of_the_frame)
28382708    {
2839        // Reset ID stack
2840        window->IDStack.resize(1);
2709        // Seed ID stack with our window pointer
2710        window->IDStack.resize(0);
2711        ImGui::PushID(window);
28412712
2842        // Move window (at the beginning of the frame to avoid input lag or sheering). Only valid for root windows.
2713        // Move window (at the beginning of the frame to avoid input lag or sheering)
28432714        const ImGuiID move_id = window->GetID("#MOVE");
28442715        RegisterAliveId(move_id);
28452716        if (g.ActiveId == move_id)
r245117r245118
28522723                    if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
28532724                        MarkSettingsDirty();
28542725                }
2855                IM_ASSERT(g.MovedWindow != NULL);
2856                FocusWindow(g.MovedWindow);
2726                FocusWindow(window);
28572727            }
28582728            else
28592729            {
28602730                SetActiveId(0);
2861                g.MovedWindow = NULL;   // Not strictly necessary but doing it for sanity.
28622731            }
28632732        }
28642733
r245117r245118
29082777        window->ScrollY = window->NextScrollY;
29092778        window->ScrollY = ImMax(window->ScrollY, 0.0f);
29102779        if (!window->Collapsed && !window->SkipItems)
2911            window->ScrollY = ImMin(window->ScrollY, ImMax(0.0f, window->SizeContents.y - window->SizeFull.y));
2780            window->ScrollY = ImMin(window->ScrollY, ImMax(0.0f, (float)window->SizeContentsFit.y - window->SizeFull.y));
29122781        window->NextScrollY = window->ScrollY;
29132782
29142783        // At this point we don't have a clipping rectangle setup yet, so we can test and draw in title bar
r245117r245118
29482817            if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
29492818            {
29502819                // Tooltip always resize. We keep the spacing symmetric on both axises for aesthetic purpose.
2951                const ImVec2 size_auto_fit = window->SizeContents + style.WindowPadding - ImVec2(0.0f, style.ItemSpacing.y);
2820                const ImVec2 size_auto_fit = window->SizeContentsFit + style.WindowPadding - ImVec2(0.0f, style.ItemSpacing.y);
29522821                window->SizeFull = size_auto_fit;
29532822            }
29542823            else
29552824            {
2956                const ImVec2 size_auto_fit = ImClamp(window->SizeContents + style.AutoFitPadding, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding));
2825                const ImVec2 size_auto_fit = ImClamp(window->SizeContentsFit + style.AutoFitPadding, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding));
29572826                if ((window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0)
29582827                {
29592828                    // Don't continuously mark settings as dirty, the size of the window doesn't need to be stored.
r245117r245118
29732842                {
29742843                    // Manual resize grip
29752844                    const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR());
2976                    const ImGuiID resize_id = window->GetID("#RESIZE");
2845                    const ImGuiID resize_id = window->GetID("##RESIZE");
29772846                    bool hovered, held;
29782847                    ButtonBehaviour(resize_aabb, resize_id, &hovered, &held, true);
29792848                    resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip);
r245117r245118
30012870            }
30022871
30032872            // Scrollbar
3004            window->ScrollbarY = (window->SizeContents.y > window->Size.y) && !(window->Flags & ImGuiWindowFlags_NoScrollbar);
2873            window->ScrollbarY = (window->SizeContentsFit.y > window->Size.y) && !(window->Flags & ImGuiWindowFlags_NoScrollbar);
30052874
30062875            // Window background
3007            if (bg_alpha > 0.0f)
2876            if (fill_alpha > 0.0f)
30082877            {
30092878                if ((window->Flags & ImGuiWindowFlags_ComboBox) != 0)
3010                    window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_ComboBg, bg_alpha), window_rounding);
2879                    window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_ComboBg, fill_alpha), window_rounding);
30112880                else if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
3012                    window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_TooltipBg, bg_alpha), window_rounding);
2881                    window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_TooltipBg, fill_alpha), window_rounding);
30132882                else if ((window->Flags & ImGuiWindowFlags_ChildWindow) != 0)
3014                    window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size-ImVec2(window->ScrollbarY?style.ScrollbarWidth:0.0f,0.0f), window->Color(ImGuiCol_ChildWindowBg, bg_alpha), window_rounding, window->ScrollbarY ? (1|8) : (0xF));
2883                    window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size-ImVec2(window->ScrollbarY?style.ScrollBarWidth:0.0f,0.0f), window->Color(ImGuiCol_ChildWindowBg, fill_alpha), window_rounding, window->ScrollbarY ? (1|8) : (0xF));
30152884                else
3016                    window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, bg_alpha), window_rounding);
2885                    window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, fill_alpha), window_rounding);
30172886            }
30182887
30192888            // Title bar
r245117r245118
30312900
30322901            // Scrollbar
30332902            if (window->ScrollbarY)
3034                Scrollbar(window);
2903            {
2904                ImGuiAabb scrollbar_bb(window->Aabb().Max.x - style.ScrollBarWidth, title_bar_aabb.Max.y+1, window->Aabb().Max.x, window->Aabb().Max.y-1);
2905                //window->DrawList->AddLine(scrollbar_bb.GetTL(), scrollbar_bb.GetBL(), g.Colors[ImGuiCol_Border]);
2906                window->DrawList->AddRectFilled(scrollbar_bb.Min, scrollbar_bb.Max, window->Color(ImGuiCol_ScrollbarBg));
2907                scrollbar_bb.Expand(ImVec2(-3,-3));
30352908
2909                const float grab_size_y_norm = ImSaturate(window->Size.y / ImMax(window->SizeContentsFit.y, window->Size.y));
2910                const float grab_size_y = scrollbar_bb.GetHeight() * grab_size_y_norm;
2911
2912                // Handle input right away (none of the code above is relying on scrolling position)
2913                bool held = false;
2914                bool hovered = false;
2915                if (grab_size_y_norm < 1.0f)
2916                {
2917                    const ImGuiID scrollbar_id = window->GetID("#SCROLLY");
2918                    ButtonBehaviour(scrollbar_bb, scrollbar_id, &hovered, &held, true);
2919                    if (held)
2920                    {
2921                        g.HoveredId = scrollbar_id;
2922                        const float pos_y_norm = ImSaturate((g.IO.MousePos.y - (scrollbar_bb.Min.y + grab_size_y*0.5f)) / (scrollbar_bb.GetHeight() - grab_size_y)) * (1.0f - grab_size_y_norm);
2923                        window->ScrollY = (float)(int)(pos_y_norm * window->SizeContentsFit.y);
2924                        window->NextScrollY = window->ScrollY;
2925                    }
2926                }
2927
2928                // Normalized height of the grab
2929                const float pos_y_norm = ImSaturate(window->ScrollY / ImMax(0.0f, window->SizeContentsFit.y));
2930                const ImU32 grab_col = window->Color(held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab);
2931                window->DrawList->AddRectFilled(
2932                    ImVec2(scrollbar_bb.Min.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y, pos_y_norm)),
2933                    ImVec2(scrollbar_bb.Max.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y, pos_y_norm + grab_size_y_norm)), grab_col);
2934            }
2935
30362936            // Render resize grip
30372937            // (after the input handling so we don't have a frame of latency)
30382938            if (!(window->Flags & ImGuiWindowFlags_NoResize))
r245117r245118
30752975        window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.ColumnsStartPos.y;
30762976        window->DC.TreeDepth = 0;
30772977        window->DC.StateStorage = &window->StateStorage;
2978        window->DC.OpenNextNode = -1;
30782979
2980        // Reset contents size for auto-fitting
2981        window->SizeContentsFit = ImVec2(0.0f, 0.0f);
30792982        if (window->AutoFitFrames > 0)
30802983            window->AutoFitFrames--;
30812984
r245117r245118
30962999            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);
30973000            RenderTextClipped(text_min, name, NULL, &text_size, text_max);
30983001        }
3099
3100        // Save clipped aabb so we can access it in constant-time in FindHoveredWindow()
3101        window->ClippedAabb = window->Aabb();
3102        window->ClippedAabb.Clip(window->ClipRectStack.front());
31033002    }
31043003
31053004    // Inner clipping rectangle
r245117r245118
31073006    const ImGuiAabb title_bar_aabb = window->TitleBarAabb();
31083007    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);
31093008    if (window->ScrollbarY)
3110        clip_rect.z -= style.ScrollbarWidth;
3009        clip_rect.z -= style.ScrollBarWidth;
31113010    PushClipRect(clip_rect);
31123011
31133012    // Clear 'accessed' flag last thing
r245117r245118
31193018    if (flags & ImGuiWindowFlags_ChildWindow)
31203019    {
31213020        IM_ASSERT((flags & ImGuiWindowFlags_NoTitleBar) != 0);
3122        window->Collapsed = parent_window && parent_window->Collapsed;
3123
31243021        const ImVec4 clip_rect_t = window->ClipRectStack.back();
3125        window->Collapsed |= (clip_rect_t.x >= clip_rect_t.z || clip_rect_t.y >= clip_rect_t.w);
3022        window->Collapsed = (clip_rect_t.x >= clip_rect_t.z || clip_rect_t.y >= clip_rect_t.w);
31263023
31273024        // We also hide the window from rendering because we've already added its border to the command list.
31283025        // (we could perform the check earlier in the function but it is simpler at this point)
r245117r245118
31523049        ImGui::LogFinish();
31533050
31543051    // Pop
3155    // NB: we don't clear 'window->RootWindow'. The pointer is allowed to live until the next call to Begin().
3052    // NB: we don't clear 'window->RootWindow' yet, it will be used then cleared in NewFrame()
31563053    g.CurrentWindowStack.pop_back();
31573054    g.CurrentWindow = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back();
31583055}
31593056
3160// Vertical scrollbar
3161// The entire piece of code below is rather confusing because:
3162// - We handle absolute seeking (when first clicking outside the grab) and relative manipulation (afterward or when clicking inside the grab)
3163// - We store values as ratio and in a form that allows the window content to change while we are holding on a scrollbar
3164static void Scrollbar(ImGuiWindow* window)
3165{
3166    ImGuiState& g = *GImGui;
3167    const ImGuiStyle& style = g.Style;
3168    const ImGuiID id = window->GetID("#SCROLLY");
3169
3170    // Render background
3171    ImGuiAabb bb(window->Aabb().Max.x - style.ScrollbarWidth, window->Pos.y + window->TitleBarHeight()+1, window->Aabb().Max.x, window->Aabb().Max.y-1);
3172    window->DrawList->AddRectFilled(bb.Min, bb.Max, window->Color(ImGuiCol_ScrollbarBg));
3173    bb.Expand(ImVec2(-3,-3));
3174    const float scrollbar_height = bb.GetHeight();
3175
3176    // The grabable box size generally represent the amount visible (vs the total scrollable amount)
3177    // But we maintain a minimum size in pixel to allow for the user to still aim inside.
3178    const float grab_h_pixels = ImMax(style.GrabMinSize, scrollbar_height * ImSaturate(window->Size.y / ImMax(window->SizeContents.y, window->Size.y)));
3179    const float grab_h_norm = grab_h_pixels / scrollbar_height;
3180
3181    // Handle input right away. None of the code of Begin() is relying on scrolling position before calling Scrollbar().
3182    bool held = false;
3183    bool hovered = false;
3184    const bool previously_held = (g.ActiveId == id);
3185    ButtonBehaviour(bb, id, &hovered, &held, true);
3186
3187    const float scroll_max = ImMax(1.0f, window->SizeContents.y - window->Size.y);
3188    float scroll_ratio = ImSaturate(window->ScrollY / scroll_max);
3189    float grab_y_norm = scroll_ratio * (scrollbar_height - grab_h_pixels) / scrollbar_height;
3190    if (held)
3191    {
3192        const float clicked_y_norm = ImSaturate((g.IO.MousePos.y - bb.Min.y) / scrollbar_height);     // Click position in scrollbar space (0.0f->1.0f)
3193        g.HoveredId = id;
3194
3195        bool seek_absolute = false;
3196        if (!previously_held)
3197        {
3198            // On initial click calculate the distance between mouse and the center of the grab
3199            if (clicked_y_norm >= grab_y_norm && clicked_y_norm <= grab_y_norm + grab_h_norm)
3200            {
3201                g.ScrollbarClickDeltaToGrabCenter = clicked_y_norm - grab_y_norm - grab_h_norm*0.5f;
3202            }
3203            else
3204            {
3205                seek_absolute = true;
3206                g.ScrollbarClickDeltaToGrabCenter = 0;
3207            }
3208        }
3209
3210        // Apply scroll
3211        const float scroll_y_norm = ImSaturate((clicked_y_norm - g.ScrollbarClickDeltaToGrabCenter - grab_h_norm*0.5f) / (1.0f - grab_h_norm));
3212        window->ScrollY = (float)(int)(0.5f + scroll_y_norm * (window->SizeContents.y - window->Size.y));
3213        window->NextScrollY = window->ScrollY;
3214
3215        // Update values for rendering
3216        scroll_ratio = ImSaturate(window->ScrollY / scroll_max);
3217        grab_y_norm = scroll_ratio * (scrollbar_height - grab_h_pixels) / scrollbar_height;
3218
3219        // Update distance to grab now that we have seeked and saturated
3220        if (seek_absolute)
3221            g.ScrollbarClickDeltaToGrabCenter = clicked_y_norm - grab_y_norm - grab_h_norm*0.5f;
3222    }
3223
3224    // Render
3225    const ImU32 grab_col = window->Color(held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab);
3226    window->DrawList->AddRectFilled(ImVec2(bb.Min.x, ImLerp(bb.Min.y, bb.Max.y, grab_y_norm)), ImVec2(bb.Max.x, ImLerp(bb.Min.y, bb.Max.y, grab_y_norm) + grab_h_pixels), grab_col);
3227}
3228
32293057// Moving window to front of display (which happens to be back of our sorted list)
32303058static void FocusWindow(ImGuiWindow* window)
32313059{
32323060    ImGuiState& g = *GImGui;
3233
3234    // Always mark the window we passed as focused. This is used for keyboard interactions such as tabbing.
32353061    g.FocusedWindow = window;
32363062
3237    // And move its root window to the top of the pile
3238    if (window->RootWindow)
3239        window = window->RootWindow;
3240
32413063    if (g.Windows.back() == window)
32423064        return;
32433065
r245117r245118
32873109    g.Font = font;
32883110    g.FontSize = g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale;
32893111    g.FontTexUvWhitePixel = g.Font->ContainerAtlas->TexUvWhitePixel;
3112    g.Font->FallbackGlyph = NULL;
3113    g.Font->FallbackGlyph = g.Font->FindGlyph(g.Font->FallbackChar);
32903114}
32913115
32923116void ImGui::PushFont(ImFont* font)
r245117r245118
34043228    ImGuiState& g = *GImGui;
34053229
34063230    ImVec2* pvar = GetStyleVarVec2Addr(idx);
3407    IM_ASSERT(pvar != NULL); // Called function with wrong-type? Variable is not a ImVec2.
3231    IM_ASSERT(pvar != NULL); // Called function with wrong-type? Varialble is not a ImVec2.
34083232    ImGuiStyleMod backup;
34093233    backup.Var = idx;
34103234    backup.PreviousValue = *pvar;
r245117r245118
34963320    return window->Pos;
34973321}
34983322
3499static void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiSetCond cond)
3323void ImGui::SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond)
35003324{
3325    ImGuiWindow* window = GetCurrentWindow();
3326
35013327    // Test condition (NB: bit 0 is always true) and clear flags for next time
35023328    if (cond && (window->SetWindowPosAllowFlags & cond) == 0)
35033329        return;
3504    window->SetWindowPosAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver);
3330    window->SetWindowPosAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver);
35053331
35063332    // Set
35073333    const ImVec2 old_pos = window->Pos;
r245117r245118
35103336    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
35113337}
35123338
3513void ImGui::SetWindowPos(const ImVec2& pos, ImGuiSetCond cond)
3514{
3515    ImGuiWindow* window = GetCurrentWindow();
3516    SetWindowPos(window, pos, cond);
3517}
3518
3519void ImGui::SetWindowPos(const char* name, const ImVec2& pos, ImGuiSetCond cond)
3520{
3521    ImGuiWindow* window = FindWindowByName(name);
3522    if (window)
3523        SetWindowPos(window, pos, cond);
3524}
3525
35263339ImVec2 ImGui::GetWindowSize()
35273340{
35283341    ImGuiWindow* window = GetCurrentWindow();
35293342    return window->Size;
35303343}
35313344
3532static void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiSetCond cond)
3345void ImGui::SetWindowSize(const ImVec2& size, ImGuiSetCondition cond)
35333346{
3347    ImGuiWindow* window = GetCurrentWindow();
3348
35343349    // Test condition (NB: bit 0 is always true) and clear flags for next time
35353350    if (cond && (window->SetWindowSizeAllowFlags & cond) == 0)
35363351        return;
3537    window->SetWindowSizeAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver);
3352    window->SetWindowSizeAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver);
35383353
35393354    // Set
35403355    if (ImLengthSqr(size) > 0.00001f)
r245117r245118
35503365    }
35513366}
35523367
3553void ImGui::SetWindowSize(const ImVec2& size, ImGuiSetCond cond)
3368void ImGui::SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond)
35543369{
35553370    ImGuiWindow* window = GetCurrentWindow();
3556    SetWindowSize(window, size, cond);
3557}
35583371
3559void ImGui::SetWindowSize(const char* name, const ImVec2& size, ImGuiSetCond cond)
3560{
3561    ImGuiWindow* window = FindWindowByName(name);
3562    if (window)
3563        SetWindowSize(window, size, cond);
3564}
3565
3566static void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiSetCond cond)
3567{
35683372    // Test condition (NB: bit 0 is always true) and clear flags for next time
35693373    if (cond && (window->SetWindowCollapsedAllowFlags & cond) == 0)
35703374        return;
3571    window->SetWindowCollapsedAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver);
3375    window->SetWindowCollapsedAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver);
35723376
35733377    // Set
35743378    window->Collapsed = collapsed;
35753379}
35763380
3577void ImGui::SetWindowCollapsed(bool collapsed, ImGuiSetCond cond)
3381void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiSetCondition cond)
35783382{
3579    ImGuiWindow* window = GetCurrentWindow();
3580    SetWindowCollapsed(window, collapsed, cond);
3581}
3582
3583bool ImGui::GetWindowCollapsed()
3584{
3585    ImGuiWindow* window = GetCurrentWindow();
3586    return window->Collapsed;
3587}
3588
3589void ImGui::SetWindowCollapsed(const char* name, bool collapsed, ImGuiSetCond cond)
3590{
3591    ImGuiWindow* window = FindWindowByName(name);
3592    if (window)
3593        SetWindowCollapsed(window, collapsed, cond);
3594}
3595
3596void ImGui::SetWindowFocus()
3597{
3598    ImGuiWindow* window = GetCurrentWindow();
3599    FocusWindow(window);
3600}
3601
3602void ImGui::SetWindowFocus(const char* name)
3603{
3604    ImGuiWindow* window = FindWindowByName(name);
3605    if (window)
3606        FocusWindow(window);
3607}
3608
3609void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond)
3610{
36113383    ImGuiState& g = *GImGui;
36123384    g.SetNextWindowPosVal = pos;
3613    g.SetNextWindowPosCond = cond ? cond : ImGuiSetCond_Always;
3385    g.SetNextWindowPosCond = cond ? cond : ImGuiSetCondition_Always;
36143386}
36153387
3616void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiSetCond cond)
3388void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiSetCondition cond)
36173389{
36183390    ImGuiState& g = *GImGui;
36193391    g.SetNextWindowSizeVal = size;
3620    g.SetNextWindowSizeCond = cond ? cond : ImGuiSetCond_Always;
3392    g.SetNextWindowSizeCond = cond ? cond : ImGuiSetCondition_Always;
36213393}
36223394
3623void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiSetCond cond)
3395void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiSetCondition cond)
36243396{
36253397    ImGuiState& g = *GImGui;
36263398    g.SetNextWindowCollapsedVal = collapsed;
3627    g.SetNextWindowCollapsedCond = cond ? cond : ImGuiSetCond_Always;
3399    g.SetNextWindowCollapsedCond = cond ? cond : ImGuiSetCondition_Always;
36283400}
36293401
3630void ImGui::SetNextWindowFocus()
3631{
3632    ImGuiState& g = *GImGui;
3633    g.SetNextWindowFocus = true;
3634}
3635
36363402ImVec2 ImGui::GetContentRegionMax()
36373403{
36383404    ImGuiWindow* window = GetCurrentWindow();
3639    ImVec2 window_padding = window->WindowPadding();
3640    ImVec2 mx = window->Size - window_padding;
3405    ImVec2 mx = window->Size - window->WindowPadding();
36413406    if (window->DC.ColumnsCount != 1)
36423407    {
36433408        mx.x = ImGui::GetColumnOffset(window->DC.ColumnsCurrent + 1);
3644        mx.x -= window_padding.x;
3409        mx.x -= GImGui->Style.WindowPadding.x;
36453410    }
36463411    else
36473412    {
36483413        if (window->ScrollbarY)
3649            mx.x -= GImGui->Style.ScrollbarWidth;
3414            mx.x -= GImGui->Style.ScrollBarWidth;
36503415    }
36513416    return mx;
36523417}
r245117r245118
36623427    ImGuiWindow* window = GetCurrentWindow();
36633428    ImVec2 m = window->Size - window->WindowPadding();
36643429    if (window->ScrollbarY)
3665        m.x -= GImGui->Style.ScrollbarWidth;
3430        m.x -= GImGui->Style.ScrollBarWidth;
36663431    return m;
36673432}
36683433
r245117r245118
37253490{
37263491    ImGuiWindow* window = GetCurrentWindow();
37273492    window->DC.CursorPos = window->Pos + pos;
3728    window->SizeContentsCurrent = ImMax(window->SizeContentsCurrent, pos + ImVec2(0.0f, window->ScrollY));
3493    window->SizeContentsFit = ImMax(window->SizeContentsFit, pos + ImVec2(0.0f, window->ScrollY));
37293494}
37303495
37313496void ImGui::SetCursorPosX(float x)
37323497{
37333498    ImGuiWindow* window = GetCurrentWindow();
37343499    window->DC.CursorPos.x = window->Pos.x + x;
3735    window->SizeContentsCurrent.x = ImMax(window->SizeContentsCurrent.x, x);
3500    window->SizeContentsFit.x = ImMax(window->SizeContentsFit.x, x);
37363501}
37373502
37383503void ImGui::SetCursorPosY(float y)
37393504{
37403505    ImGuiWindow* window = GetCurrentWindow();
37413506    window->DC.CursorPos.y = window->Pos.y + y;
3742    window->SizeContentsCurrent.y = ImMax(window->SizeContentsCurrent.y, y + window->ScrollY);
3507    window->SizeContentsFit.y = ImMax(window->SizeContentsFit.y, y + window->ScrollY);
37433508}
37443509
37453510ImVec2 ImGui::GetCursorScreenPos()
r245117r245118
37543519    window->DC.CursorPos = screen_pos;
37553520}
37563521
3757float ImGui::GetScrollPosY()
3758{
3759    ImGuiWindow* window = GetCurrentWindow();
3760    return window->ScrollY;
3761}
3762
3763float ImGui::GetScrollMaxY()
3764{
3765    ImGuiWindow* window = GetCurrentWindow();
3766    return window->SizeContents.y - window->SizeFull.y;
3767}
3768
37693522void ImGui::SetScrollPosHere()
37703523{
37713524    ImGuiWindow* window = GetCurrentWindow();
r245117r245118
39673720    const char* value_text_begin = &buf[0];
39683721    const char* value_text_end = value_text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
39693722
3970    const ImVec2 label_size = CalcTextSize(label, NULL, true);
3971    const ImGuiAabb value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, label_size.y));
3972    const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + (label_size.x > 0.0f ? style.ItemInnerSpacing.x : 0.0f), 0.0f) + label_size);
3723    const ImVec2 text_size = CalcTextSize(label, NULL, true);
3724    const ImGuiAabb value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, text_size.y));
3725    const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + (text_size.x > 0.0f ? style.ItemInnerSpacing.x : 0.0f), 0.0f) + text_size);
39733726    ItemSize(bb);
39743727    if (!ItemAdd(value_bb, NULL))
39753728        return;
r245117r245118
39933746    if (g.HoveredId == 0)
39943747    {
39953748        ImGuiWindow* window = GetCurrentWindow();
3996        if (g.HoveredRootWindow == window->RootWindow)
3997        {
3998            bool hovered = (g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdIsFocusedOnly) && IsMouseHoveringBox(bb);
3999            return hovered;
4000        }
3749        const bool hovered = (g.HoveredRootWindow == window->RootWindow) && (g.ActiveId == 0 || g.ActiveId == id) && IsMouseHoveringBox(bb);
3750        return hovered;
40013751    }
40023752    return false;
40033753}
r245117r245118
40643814
40653815    const ImGuiStyle& style = g.Style;
40663816    const ImGuiID id = window->GetID(label);
4067    const ImVec2 label_size = CalcTextSize(label, NULL, true);
3817    const ImVec2 text_size = CalcTextSize(label, NULL, true);
40683818
4069    const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : label_size.x, size_arg.y != 0.0f ? size_arg.y : label_size.y);
3819    const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : text_size.x, size_arg.y != 0.0f ? size_arg.y : text_size.y);
40703820    const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size + style.FramePadding*2.0f);
40713821    ItemSize(bb);
40723822    if (!ItemAdd(bb, &id))
r245117r245118
40793829    const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
40803830    RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
40813831
4082    const ImVec2 off = ImVec2(ImMax(0.0f, size.x - label_size.x) * 0.5f, ImMax(0.0f, size.y - label_size.y) * 0.5f); // Center (only applies if we explicitly gave a size bigger than the text size, which isn't the common path)
4083    RenderTextClipped(bb.Min + style.FramePadding + off, label, NULL, &label_size, bb.Max);                          // Render clip (only applies if we explicitly gave a size smaller than the text size, which isn't the commmon path)
3832    const ImVec2 off = ImVec2(ImMax(0.0f, size.x - text_size.x) * 0.5f, ImMax(0.0f, size.y - text_size.y) * 0.5f);  // Center (only applies if we explicitly gave a size bigger than the text size, which isn't the common path)
3833    RenderTextClipped(bb.Min + style.FramePadding + off, label, NULL, &text_size, bb.Max);                          // Render clip (only applies if we explicitly gave a size smaller than the text size, which isn't the commmon path)
40843834
40853835    return pressed;
40863836}
r245117r245118
40953845
40963846    const ImGuiStyle& style = g.Style;
40973847    const ImGuiID id = window->GetID(label);
4098    const ImVec2 label_size = CalcTextSize(label, NULL, true);
3848    const ImVec2 text_size = CalcTextSize(label, NULL, true);
40993849
4100    const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + label_size + ImVec2(style.FramePadding.x*2,0));
3850    const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size + ImVec2(style.FramePadding.x*2,0));
41013851    ItemSize(bb);
41023852    if (!ItemAdd(bb, &id))
41033853        return false;
r245117r245118
41383888{
41393889    ImGuiWindow* window = GetCurrentWindow();
41403890
4141    const ImGuiID id = window->GetID("#CLOSE");
3891    const ImGuiID id = window->GetID("##CLOSE");
41423892    const float size = window->TitleBarHeight() - 4.0f;
41433893    const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-3.0f-size,2.0f), window->Aabb().GetTR() + ImVec2(-3.0f,2.0f+size));
41443894
r245117r245118
43324082        LogToClipboard(g.LogAutoExpandMaxDepth);
43334083}
43344084
4335bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display_frame, bool default_open)
4085bool ImGui::CollapsingHeader(const char* label, const char* str_id, const bool display_frame, const bool default_open)
43364086{
43374087    ImGuiState& g = *GImGui;
43384088    ImGuiWindow* window = GetCurrentWindow();
r245117r245118
43484098        label = str_id;
43494099    const ImGuiID id = window->GetID(str_id);
43504100
4351    // We only write to the tree storage if the user clicks (or explicitely use SetNextTreeNode*** functions)
4101    // We only write to the tree storage if the user clicks
43524102    ImGuiStorage* storage = window->DC.StateStorage;
43534103    bool opened;
4354    if (g.SetNextTreeNodeOpenedCond != 0)
4104    if (window->DC.OpenNextNode != -1)
43554105    {
4356        if (g.SetNextTreeNodeOpenedCond & ImGuiSetCond_Always)
4357        {
4358            opened = g.SetNextTreeNodeOpenedVal;
4359            storage->SetInt(id, opened);
4360        }
4361        else
4362        {
4363            // We treat ImGuiSetCondition_Once and ImGuiSetCondition_FirstUseEver the same because tree node state are not saved persistently.
4364            const int stored_value = storage->GetInt(id, -1);
4365            if (stored_value == -1)
4366            {
4367                opened = g.SetNextTreeNodeOpenedVal;
4368                storage->SetInt(id, opened);
4369            }
4370            else
4371            {
4372                opened = stored_value != 0;
4373            }
4374        }
4375        g.SetNextTreeNodeOpenedCond = 0;
4106        opened = window->DC.OpenNextNode > 0;
4107        storage->SetInt(id, opened);
4108        window->DC.OpenNextNode = -1;
43764109    }
43774110    else
43784111    {
r245117r245118
43814114
43824115    // Framed header expand a little outside the default padding
43834116    const ImVec2 window_padding = window->WindowPadding();
4384    const ImVec2 label_size = CalcTextSize(label, NULL, true);
4117    const ImVec2 text_size = CalcTextSize(label, NULL, true);
43854118    const ImVec2 pos_min = window->DC.CursorPos;
43864119    const ImVec2 pos_max = window->Pos + GetContentRegionMax();
4387    ImGuiAabb bb = ImGuiAabb(pos_min, ImVec2(pos_max.x, pos_min.y + label_size.y));
4120    ImGuiAabb bb = ImGuiAabb(pos_min, ImVec2(pos_max.x, pos_min.y + text_size.y));
43884121    if (display_frame)
43894122    {
43904123        bb.Min.x -= window_padding.x*0.5f - 1;
r245117r245118
43924125        bb.Max.y += style.FramePadding.y * 2;
43934126    }
43944127
4395    const ImGuiAabb text_bb(bb.Min, bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2*2,0) + label_size);
4128    const ImGuiAabb text_bb(bb.Min, bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2*2,0) + text_size);
43964129    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
43974130
43984131    // When logging is enabled, if automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behaviour).
43994132    // NB- If we are above max depth we still allow manually opened nodes to be logged.
4400    if (g.LogEnabled && !display_frame && window->DC.TreeDepth < g.LogAutoExpandMaxDepth)
4401        opened = true;
4133    if (!display_frame)
4134        if (g.LogEnabled && window->DC.TreeDepth < g.LogAutoExpandMaxDepth)
4135            opened = true;
44024136
44034137    if (!ItemAdd(bb, &id))
44044138        return opened;
r245117r245118
44454179    return opened;
44464180}
44474181
4448void ImGui::Bullet()
4449{
4450    ImGuiState& g = *GImGui;
4451    ImGuiWindow* window = GetCurrentWindow();
4452    if (window->SkipItems)
4453        return;
4454
4455    const ImGuiStyle& style = g.Style;
4456    const float line_height = window->FontSize();
4457    const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height, line_height));
4458    ItemSize(bb);
4459    if (!ItemAdd(bb, NULL))
4460        return;
4461
4462    // Render
4463    const float bullet_size = line_height*0.15f;
4464    window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text));
4465
4466    // Stay on same line
4467    ImGui::SameLine(0, -1);
4468}
4469
44704182// Text with a little bullet aligned to the typical tree node.
44714183void ImGui::BulletTextV(const char* fmt, va_list args)
44724184{
r245117r245118
44754187    if (window->SkipItems)
44764188        return;
44774189
4190    const ImGuiStyle& style = g.Style;
4191
44784192    static char buf[1024];
44794193    const char* text_begin = buf;
44804194    const char* text_end = text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
44814195
4482    const ImGuiStyle& style = g.Style;
44834196    const float line_height = window->FontSize();
4484    const ImVec2 label_size = CalcTextSize(text_begin, text_end, true);
4485    const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (label_size.x > 0.0f ? (style.FramePadding.x*2) : 0.0f),0) + label_size);  // Empty text doesn't add padding
4197    const ImVec2 text_size = CalcTextSize(text_begin, text_end, true);
4198    const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (text_size.x > 0.0f ? (style.FramePadding.x*2) : 0.0f),0) + text_size);  // Empty text doesn't add padding
44864199    ItemSize(bb);
44874200    if (!ItemAdd(bb, NULL))
44884201        return;
r245117r245118
45624275    return TreeNode(str_label_id, "%s", str_label_id);
45634276}
45644277
4565void ImGui::SetNextTreeNodeOpened(bool opened, ImGuiSetCond cond)
4278void ImGui::OpenNextNode(bool open)
45664279{
4567    ImGuiState& g = *GImGui;
4568    g.SetNextTreeNodeOpenedVal = opened;
4569    g.SetNextTreeNodeOpenedCond = cond ? cond : ImGuiSetCond_Always;
4280    ImGuiWindow* window = GetCurrentWindow();
4281    window->DC.OpenNextNode = open ? 1 : 0;
45704282}
45714283
45724284void ImGui::PushID(const char* str_id)
r245117r245118
46104322// NB: only call right after InputText because we are using its InitialValue storage
46114323static void ApplyNumericalTextInput(const char* buf, float *v)
46124324{
4613    while (ImCharIsSpace(*buf))
4325    while (*buf == ' ' || *buf == '\t')
46144326        buf++;
46154327
46164328    // We don't support '-' op because it would conflict with inputing negative value.
r245117r245118
46194331    if (op == '+' || op == '*' || op == '/')
46204332    {
46214333        buf++;
4622        while (ImCharIsSpace(*buf))
4334        while (*buf == ' ' || *buf == '\t')
46234335            buf++;
46244336    }
46254337    else
r245117r245118
46834395        }
46844396    }
46854397
4686    const ImVec2 label_size = CalcTextSize(label, NULL, true);
4687    const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
4398    const ImVec2 text_size = CalcTextSize(label, NULL, true);
4399    const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f);
46884400    const ImGuiAabb slider_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
4689    const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
4401    const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(text_size.x > 0.0f ? style.ItemInnerSpacing.x + text_size.x : 0.0f, 0.0f));
46904402
46914403    // NB- we don't call ItemSize() yet becausae we may turn into a text edit box later in the function
46924404    if (!ItemAdd(slider_bb, &id))
r245117r245118
47024414    const float grab_size_in_units = 1.0f;                                                              // In 'v' units. Probably needs to be parametrized, based on a 'v_step' value? decimal precision?
47034415    float grab_size_in_pixels;
47044416    if (decimal_precision > 0 || is_unbound)
4705        grab_size_in_pixels = style.GrabMinSize;
4417        grab_size_in_pixels = 10.0f;
47064418    else
4707        grab_size_in_pixels = ImMax(grab_size_in_units * (w / (v_max-v_min+1.0f)), style.GrabMinSize);  // Integer sliders
4419        grab_size_in_pixels = ImMax(grab_size_in_units * (w / (v_max-v_min+1.0f)), 8.0f);               // Integer sliders
47084420    const float slider_effective_w = slider_bb.GetWidth() - grab_size_in_pixels;
47094421    const float slider_effective_x1 = slider_bb.Min.x + grab_size_in_pixels*0.5f;
47104422    const float slider_effective_x2 = slider_bb.Max.x - grab_size_in_pixels*0.5f;
r245117r245118
47594471        if (g.SliderAsInputTextId == 0)
47604472        {
47614473            // First frame
4762            IM_ASSERT(g.ActiveId == id);    // InputText ID expected to match the Slider ID (else we'd need to store them both, which is also possible)
4474            IM_ASSERT(g.ActiveId == id);    // InputText ID should match the Slider ID (else we'd need to store them both which is also possible)
47634475            g.SliderAsInputTextId = g.ActiveId;
4476            SetActiveId(id);
47644477            g.HoveredId = id;
47654478        }
4766        else if (g.ActiveId != g.SliderAsInputTextId)
4479        else
47674480        {
4768            // Release
4769            g.SliderAsInputTextId = 0;
4481            if (g.ActiveId == g.SliderAsInputTextId)
4482                SetActiveId(id);
4483            else
4484            {
4485                SetActiveId(0);
4486                g.SliderAsInputTextId = 0;
4487            }
47704488        }
47714489        if (value_changed)
47724490        {
r245117r245118
48614579
48624580    // Draw value using user-provided display format so user can add prefix/suffix/decorations to the value.
48634581    char value_buf[64];
4864    char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
4865    const ImVec2 value_text_size = CalcTextSize(value_buf, value_buf_end, true);
4866    RenderTextClipped(ImVec2(ImMax(frame_bb.Min.x + style.FramePadding.x, slider_bb.GetCenter().x - value_text_size.x*0.5f), frame_bb.Min.y + style.FramePadding.y), value_buf, value_buf_end, &value_text_size, frame_bb.Max);
4582    ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
4583    RenderText(ImVec2(slider_bb.GetCenter().x-CalcTextSize(value_buf, NULL, true).x*0.5f, frame_bb.Min.y + style.FramePadding.y), value_buf);
48674584
48684585    RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, slider_bb.Min.y), label);
48694586
r245117r245118
50044721
50054722    const ImGuiStyle& style = g.Style;
50064723
5007    const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
4724    const ImVec2 text_size = ImGui::CalcTextSize(label, NULL, true);
50084725    if (graph_size.x == 0.0f)
50094726        graph_size.x = ImGui::CalcItemWidth();
50104727    if (graph_size.y == 0.0f)
5011        graph_size.y = label_size.y;
4728        graph_size.y = text_size.y;
50124729
50134730    const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y) + style.FramePadding*2.0f);
50144731    const ImGuiAabb graph_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
5015    const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0));
4732    const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(text_size.x > 0.0f ? style.ItemInnerSpacing.x + text_size.x : 0.0f, 0));
50164733    ItemSize(bb);
50174734    if (!ItemAdd(bb, NULL))
50184735        return;
r245117r245118
51374854
51384855    const ImGuiStyle& style = g.Style;
51394856    const ImGuiID id = window->GetID(label);
5140    const ImVec2 label_size = CalcTextSize(label, NULL, true);
4857    const ImVec2 text_size = CalcTextSize(label, NULL, true);
51414858
5142    const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2, label_size.y + style.FramePadding.y*2));
4859    const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(text_size.y + style.FramePadding.y*2, text_size.y + style.FramePadding.y*2));
51434860    ItemSize(check_bb);
51444861
51454862    ImGuiAabb total_bb = check_bb;
5146    if (label_size.x > 0)
4863    if (text_size.x > 0)
51474864        SameLine(0, (int)style.ItemInnerSpacing.x);
5148    const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + label_size);
5149    if (label_size.x > 0)
4865    const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + text_size);
4866    if (text_size.x > 0)
51504867    {
51514868        ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()));
51524869        total_bb = ImGuiAabb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
r245117r245118
51954912
51964913    const ImGuiStyle& style = g.Style;
51974914    const ImGuiID id = window->GetID(label);
5198    const ImVec2 label_size = CalcTextSize(label, NULL, true);
51994915
5200    const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(label_size.y + style.FramePadding.y*2-1, label_size.y + style.FramePadding.y*2-1));
4916    const ImVec2 text_size = CalcTextSize(label, NULL, true);
4917
4918    const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(text_size.y + style.FramePadding.y*2-1, text_size.y + style.FramePadding.y*2-1));
52014919    ItemSize(check_bb);
52024920
52034921    ImGuiAabb total_bb = check_bb;
5204    if (label_size.x > 0)
4922    if (text_size.x > 0)
52054923        SameLine(0, (int)style.ItemInnerSpacing.x);
5206    const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + label_size);
5207    if (label_size.x > 0)
4924    const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + text_size);
4925    if (text_size.x > 0)
52084926    {
52094927        ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()));
52104928        total_bb.Add(text_bb);
r245117r245118
52704988    r->num_chars = (int)(text_remaining - (obj->Text + line_start_idx));
52714989}
52724990
4991static bool is_white(unsigned int c)                                                              { return c==0 || c==' ' || c=='\t' || c=='\r' || c=='\n'; }
52734992static bool is_separator(unsigned int c)                                                          { return c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|'; }
5274#define STB_TEXTEDIT_IS_SPACE(CH)                                                                 ( ImCharIsSpace((unsigned int)CH) || is_separator((unsigned int)CH) )
5275static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n)
5276{
5277    ImWchar* dst = obj->Text + pos;
5278
5279    // We maintain our buffer length in both UTF-8 and wchar formats
5280    obj->CurLenA -= ImTextCountUtf8BytesFromStr(dst, dst + n);
5281    obj->CurLenW -= n;
5282
5283    // Offset remaining text
5284    const ImWchar* src = obj->Text + pos + n;
5285    while (ImWchar c = *src++)
5286        *dst++ = c;
5287    *dst = '\0';
5288}
5289
4993#define STB_TEXTEDIT_IS_SPACE(CH)                                                                 ( is_white((unsigned int)CH) || is_separator((unsigned int)CH) )
4994static 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'; }
52904995static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const ImWchar* new_text, int new_text_len)
52914996{
5292    const size_t text_len = obj->CurLenW;
5293    if ((size_t)new_text_len + text_len + 1 > IM_ARRAYSIZE(obj->Text))
4997    const size_t text_len = ImStrlenW(obj->Text);
4998    if ((size_t)new_text_len + text_len + 1 >= obj->BufSize)
52944999        return false;
52955000
5296    const int new_text_len_utf8 = ImTextCountUtf8BytesFromStr(new_text, new_text + new_text_len);
5297    if ((size_t)new_text_len_utf8 + obj->CurLenA + 1 > obj->BufSizeA)
5298        return false;
5299
53005001    if (pos != (int)text_len)
53015002        memmove(obj->Text + (size_t)pos + new_text_len, obj->Text + (size_t)pos, (text_len - (size_t)pos) * sizeof(ImWchar));
53025003    memcpy(obj->Text + (size_t)pos, new_text, (size_t)new_text_len * sizeof(ImWchar));
5004    obj->Text[text_len + (size_t)new_text_len] = '\0';
53035005
5304    obj->CurLenW += new_text_len;
5305    obj->CurLenA += new_text_len_utf8;
5306    obj->Text[obj->CurLenW] = '\0';
5307
53085006    return true;
53095007}
53105008
r245117r245118
53985096    const char* text_start = GetTextPointerClippedA(font, font_size, buf, scroll_x, NULL);
53995097    const char* text_end = GetTextPointerClippedA(font, font_size, text_start, width, &text_size);
54005098
5401    // We need to test for the possibility of malformed UTF-8 (instead of just text_end[0] != 0)
5402    unsigned int text_end_char = 0;
5403    ImTextCharFromUtf8(&text_end_char, text_end, NULL);
5404
54055099    // Draw a little clip symbol if we've got text on either left or right of the box
54065100    const char symbol_c = '~';
54075101    const float symbol_w = font_size*0.40f;     // FIXME: compute correct width
54085102    const float clip_begin = (text_start > buf && text_start < text_end) ? symbol_w : 0.0f;
5409    const float clip_end = (text_end_char != 0 && text_end > text_start) ? symbol_w : 0.0f;
5103    const float clip_end = (text_end[0] != '\0' && text_end > text_start) ? symbol_w : 0.0f;
54105104
54115105    // Draw text
54125106    RenderText(pos+ImVec2(clip_begin,0), text_start+(clip_begin>0.0f?1:0), text_end-(clip_end>0.0f?1:0), false);
r245117r245118
54285122
54295123    const ImGuiStyle& style = g.Style;
54305124    const float w = ImGui::CalcItemWidth();
5431    const ImVec2 label_size = CalcTextSize(label, NULL, true);
5432    const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
5125    const ImVec2 text_size = CalcTextSize(label, NULL, true);
5126    const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f);
54335127
54345128    ImGui::PushID(label);
54355129    const float button_sz = window->FontSize();
r245117r245118
54695163
54705164    ImGui::PopID();
54715165
5472    if (label_size.x > 0)
5166    if (text_size.x > 0)
54735167    {
54745168        ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
5475        ItemSize(label_size);
5169        ItemSize(text_size);
54765170        RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
54775171    }
54785172
r245117r245118
55285222    SelectionStart = SelectionEnd = CursorPos;
55295223}
55305224
5531// Return false to discard a character.
5532static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data)
5225static bool InputTextFilterCharacter(ImWchar c, ImGuiInputTextFlags flags)
55335226{
5534    unsigned int c = *p_char;
5535
55365227    if (c < 128 && c != ' ' && !isprint((int)(c & 0xFF)))
5537        return false;
5228        return true;
55385229
55395230    if (c >= 0xE000 && c <= 0xF8FF) // Filter private Unicode range. I don't imagine anybody would want to input them. GLFW on OSX seems to send private characters for special keys like arrow keys.
5540        return false;
5231        return true;
55415232
5542    if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank))
5543    {
5544        if (flags & ImGuiInputTextFlags_CharsDecimal)
5545            if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/'))
5546                return false;
5233    if (flags & ImGuiInputTextFlags_CharsDecimal)
5234        if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/'))
5235            return true;
55475236
5548        if (flags & ImGuiInputTextFlags_CharsHexadecimal)
5549            if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F'))
5550                return false;
5237    if (flags & ImGuiInputTextFlags_CharsHexadecimal)
5238        if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F'))
5239            return true;
55515240
5552        if (flags & ImGuiInputTextFlags_CharsUppercase)
5553            if (c >= 'a' && c <= 'z')
5554                *p_char = (c += (unsigned int)('A'-'a'));
5555
5556        if (flags & ImGuiInputTextFlags_CharsNoBlank)
5557            if (ImCharIsSpace(c))
5558                return false;
5559    }
5560
5561    if (flags & ImGuiInputTextFlags_CallbackCharFilter)
5562    {
5563        ImGuiTextEditCallbackData callback_data;
5564        memset(&callback_data, 0, sizeof(ImGuiTextEditCallbackData));
5565        callback_data.EventFlag = ImGuiInputTextFlags_CallbackCharFilter;
5566        callback_data.EventChar = c;
5567        callback_data.Flags = flags;
5568        callback_data.UserData = user_data;
5569        if (callback(&callback_data) != 0)
5570            return false;
5571        *p_char = callback_data.EventChar;
5572        if (!callback_data.EventChar)
5573            return false;
5574    }
5575
5576    return true;
5241    return false;
55775242}
55785243
55795244// Edit a string of text
5580bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data)
5245bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, void (*callback)(ImGuiTextEditCallbackData*), void* user_data)
55815246{
55825247    ImGuiState& g = *GImGui;
55835248    ImGuiWindow* window = GetCurrentWindow();
r245117r245118
55905255    const ImGuiID id = window->GetID(label);
55915256    const float w = ImGui::CalcItemWidth();
55925257
5593    const ImVec2 label_size = CalcTextSize(label, NULL, true);
5594    const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
5595    const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? (style.ItemInnerSpacing.x + label_size.x) : 0.0f, 0.0f));
5258    const ImVec2 text_size = CalcTextSize(label, NULL, true);
5259    const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f);
5260    const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(text_size.x > 0.0f ? (style.ItemInnerSpacing.x + text_size.x) : 0.0f, 0.0f));
55965261    ItemSize(bb);
55975262    if (!ItemAdd(frame_bb, &id))
55985263        return false;
r245117r245118
56025267
56035268    const bool is_ctrl_down = io.KeyCtrl;
56045269    const bool is_shift_down = io.KeyShift;
5605    const bool focus_requested = window->FocusItemRegister(g.ActiveId == id, (flags & ImGuiInputTextFlags_CallbackCompletion) == 0);    // Using completion callback disable keyboard tabbing
5606    const bool focus_requested_by_code = focus_requested && (window->FocusIdxAllCounter == window->FocusIdxAllRequestCurrent);
5607    const bool focus_requested_by_tab = focus_requested && !focus_requested_by_code;
5270    const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id, (flags & ImGuiInputTextFlags_CallbackCompletion) == 0);    // Using completion callback disable keyboard tabbing
5271    //const bool align_center = (bool)(flags & ImGuiInputTextFlags_AlignCenter);    // FIXME: Unsupported
56085272
56095273    const bool hovered = IsHovered(frame_bb, id);
56105274    if (hovered)
56115275        g.HoveredId = id;
5612    const bool user_clicked = hovered && io.MouseClicked[0];
56135276
56145277    bool select_all = (g.ActiveId != id) && (flags & ImGuiInputTextFlags_AutoSelectAll) != 0;
5615    if (focus_requested || user_clicked)
5278    if (tab_focus_requested || (hovered && io.MouseClicked[0]))
56165279    {
56175280        if (g.ActiveId != id)
56185281        {
56195282            // Start edition
56205283            // Take a copy of the initial buffer value (both in original UTF-8 format and converted to wchar)
5621            // From the moment we focused we are ignoring the content of 'buf'
56225284            ImFormatString(edit_state.InitialText, IM_ARRAYSIZE(edit_state.InitialText), "%s", buf);
5623            const char* buf_end = NULL;
5624            edit_state.CurLenW = (int)ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), buf, NULL, &buf_end);
5625            edit_state.CurLenA = (int)(buf_end - buf); // We can't get the result from ImFormatString() above because it is not UTF-8 aware. Here we'll cut off malformed UTF-8.
5285            ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), buf, NULL);
5286            edit_state.ScrollX = 0.0f;
56265287            edit_state.Width = w;
5627            edit_state.InputCursorScreenPos = ImVec2(-1.f,-1.f);
5288            stb_textedit_initialize_state(&edit_state.StbState, true);
56285289            edit_state.CursorAnimReset();
5290            edit_state.LastCursorPos = ImVec2(-1.f,-1.f);
56295291
5630            if (edit_state.Id != id)
5631            {
5632                edit_state.Id = id;
5633                edit_state.ScrollX = 0.0f;
5634                stb_textedit_initialize_state(&edit_state.StbState, true);
5635                if (focus_requested_by_code)
5636                    select_all = true;
5637            }
5638            else
5639            {
5640                // Recycle existing cursor/selection/undo stack but clamp position
5641                // Note a single mouse click will override the cursor/position immediately by calling stb_textedit_click handler.
5642                edit_state.StbState.cursor = ImMin(edit_state.StbState.cursor, edit_state.CurLenW);
5643                edit_state.StbState.select_start = ImMin(edit_state.StbState.select_start, edit_state.CurLenW);
5644                edit_state.StbState.select_end = ImMin(edit_state.StbState.select_end, edit_state.CurLenW);
5645            }
5646            if (focus_requested_by_tab || (user_clicked && is_ctrl_down))
5292            if (tab_focus_requested || is_ctrl_down)
56475293                select_all = true;
56485294        }
56495295        SetActiveId(id);
r245117r245118
56585304        }
56595305    }
56605306
5661    // Although we are active we don't prevent mouse from hovering other elements unless we are interacting right now with the widget.
5662    // Down the line we should have a cleaner concept of focused vs active in the library.
5663    if (g.ActiveId == id)
5664        g.ActiveIdIsFocusedOnly = !io.MouseDown[0];
5665
56665307    bool value_changed = false;
56675308    bool cancel_edit = false;
56685309    bool enter_pressed = false;
r245117r245118
56705311    if (g.ActiveId == id)
56715312    {
56725313        // Edit in progress
5673        edit_state.BufSizeA = buf_size;
5314        edit_state.BufSize = buf_size < IM_ARRAYSIZE(edit_state.Text) ? buf_size : IM_ARRAYSIZE(edit_state.Text);
56745315        edit_state.Font = window->Font();
56755316        edit_state.FontSize = window->FontSize();
56765317
r245117r245118
57025343            // Process text input (before we check for Return because using some IME will effectively send a Return?)
57035344            for (int n = 0; n < IM_ARRAYSIZE(g.IO.InputCharacters) && g.IO.InputCharacters[n]; n++)
57045345            {
5705                unsigned int c = (unsigned int)g.IO.InputCharacters[n];
5346                const ImWchar c = g.IO.InputCharacters[n];
57065347                if (c)
57075348                {
57085349                    // Insert character if they pass filtering
5709                    if (!InputTextFilterCharacter(&c, flags, callback, user_data))
5350                    if (InputTextFilterCharacter(c, flags))
57105351                        continue;
5711                    edit_state.OnKeyPressed((int)c);
5352                    edit_state.OnKeyPressed(c);
57125353                }
57135354            }
57145355
r245117r245118
57385379            if (g.IO.SetClipboardTextFn)
57395380            {
57405381                const int ib = edit_state.HasSelection() ? ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end) : 0;
5741                const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : edit_state.CurLenW;
5382                const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : (int)ImStrlenW(edit_state.Text);
57425383                ImTextStrToUtf8(text_tmp_utf8, IM_ARRAYSIZE(text_tmp_utf8), edit_state.Text+ib, edit_state.Text+ie);
57435384                g.IO.SetClipboardTextFn(text_tmp_utf8);
57445385            }
r245117r245118
57545395                if (const char* clipboard = g.IO.GetClipboardTextFn())
57555396                {
57565397                    // Remove new-line from pasted buffer
5757                    const size_t clipboard_len = strlen(clipboard);
5398                    size_t clipboard_len = strlen(clipboard);
57585399                    ImWchar* clipboard_filtered = (ImWchar*)ImGui::MemAlloc((clipboard_len+1) * sizeof(ImWchar));
57595400                    int clipboard_filtered_len = 0;
57605401                    for (const char* s = clipboard; *s; )
57615402                    {
57625403                        unsigned int c;
5763                        s += ImTextCharFromUtf8(&c, s, NULL);
5764                        if (c == 0)
5404                        const int bytes_count = ImTextCharFromUtf8(&c, s, NULL);
5405                        if (bytes_count <= 0)
57655406                            break;
5407                        s += bytes_count;
57665408                        if (c >= 0x10000)
57675409                            continue;
5768                        if (!InputTextFilterCharacter(&c, flags, callback, user_data))
5410                        if (InputTextFilterCharacter((ImWchar)c, flags))
57695411                            continue;
57705412                        clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c;
57715413                    }
r245117r245118
58005442                IM_ASSERT(callback != NULL);
58015443
58025444                // The reason we specify the usage semantic (Completion/History) is that Completion needs to disable keyboard TABBING at the moment.
5803                ImGuiInputTextFlags event_flag = 0;
58045445                ImGuiKey event_key = ImGuiKey_COUNT;
58055446                if ((flags & ImGuiInputTextFlags_CallbackCompletion) != 0 && IsKeyPressedMap(ImGuiKey_Tab))
5806                {
5807                    event_flag = ImGuiInputTextFlags_CallbackCompletion;
58085447                    event_key = ImGuiKey_Tab;
5809                }
58105448                else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_UpArrow))
5811                {
5812                    event_flag = ImGuiInputTextFlags_CallbackHistory;
58135449                    event_key = ImGuiKey_UpArrow;
5814                }
58155450                else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_DownArrow))
5816                {
5817                    event_flag = ImGuiInputTextFlags_CallbackHistory;
58185451                    event_key = ImGuiKey_DownArrow;
5819                }
58205452
58215453                if (event_key != ImGuiKey_COUNT || (flags & ImGuiInputTextFlags_CallbackAlways) != 0)
58225454                {
58235455                    ImGuiTextEditCallbackData callback_data;
5824                    callback_data.EventFlag = event_flag;
58255456                    callback_data.EventKey = event_key;
58265457                    callback_data.Buf = text_tmp_utf8;
5827                    callback_data.BufSize = edit_state.BufSizeA;
5458                    callback_data.BufSize = edit_state.BufSize;
58285459                    callback_data.BufDirty = false;
58295460                    callback_data.Flags = flags;
58305461                    callback_data.UserData = user_data;
58315462
58325463                    // We have to convert from position from wchar to UTF-8 positions
5833                    const int utf8_cursor_pos = callback_data.CursorPos = ImTextCountUtf8BytesFromStr(edit_state.Text, edit_state.Text + edit_state.StbState.cursor);
5834                    const int utf8_selection_start = callback_data.SelectionStart = ImTextCountUtf8BytesFromStr(edit_state.Text, edit_state.Text + edit_state.StbState.select_start);
5835                    const int utf8_selection_end = callback_data.SelectionEnd = ImTextCountUtf8BytesFromStr(edit_state.Text, edit_state.Text + edit_state.StbState.select_end);
5464                    const int utf8_cursor_pos = callback_data.CursorPos = ImTextCountUtf8BytesFromWchar(edit_state.Text, edit_state.Text + edit_state.StbState.cursor);
5465                    const int utf8_selection_start = callback_data.SelectionStart = ImTextCountUtf8BytesFromWchar(edit_state.Text, edit_state.Text + edit_state.StbState.select_start);
5466                    const int utf8_selection_end = callback_data.SelectionEnd = ImTextCountUtf8BytesFromWchar(edit_state.Text, edit_state.Text + edit_state.StbState.select_end);
58365467
58375468                    // Call user code
58385469                    callback(&callback_data);
58395470
58405471                    // Read back what user may have modified
58415472                    IM_ASSERT(callback_data.Buf == text_tmp_utf8);             // Invalid to modify those fields
5842                    IM_ASSERT(callback_data.BufSize == edit_state.BufSizeA);
5473                    IM_ASSERT(callback_data.BufSize == edit_state.BufSize);
58435474                    IM_ASSERT(callback_data.Flags == flags);
58445475                    if (callback_data.CursorPos != utf8_cursor_pos)            edit_state.StbState.cursor = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.CursorPos);
58455476                    if (callback_data.SelectionStart != utf8_selection_start)  edit_state.StbState.select_start = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionStart);
r245117r245118
58785509        }
58795510    }
58805511
5512    // FIXME: 'align_center' unsupported
58815513    ImGuiTextEditState::RenderTextScrolledClipped(window->Font(), window->FontSize(), buf, frame_bb.Min + style.FramePadding, w, (g.ActiveId == id) ? edit_state.ScrollX : 0.0f);
58825514
58835515    if (g.ActiveId == id)
r245117r245118
58885520        if (g.InputTextState.CursorIsVisible())
58895521            window->DrawList->AddRect(cursor_pos - font_off_up + ImVec2(0,2), cursor_pos + font_off_dn - ImVec2(0,3), window->Color(ImGuiCol_Text));
58905522
5891        // Notify OS of text input position for advanced IME
5892        if (io.ImeSetInputScreenPosFn && ImLengthSqr(edit_state.InputCursorScreenPos - cursor_pos) > 0.0001f)
5523        // Notify OS of text input position
5524        if (io.ImeSetInputScreenPosFn && ImLengthSqr(edit_state.LastCursorPos - cursor_pos) > 0.0001f)
58935525            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.
58945526
5895        edit_state.InputCursorScreenPos = cursor_pos;
5527        edit_state.LastCursorPos = cursor_pos;
58965528    }
58975529
5898    if (label_size.x > 0)
5899        RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
5530    RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
59005531
59015532    if ((flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0)
59025533        return enter_pressed;
r245117r245118
60155646    const ImGuiID id = window->GetID(label);
60165647    const float w = ImGui::CalcItemWidth();
60175648
6018    const ImVec2 label_size = CalcTextSize(label, NULL, true);
6019    const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
6020    const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + label_size.x,0));
6021    ItemSize(bb);
5649    const ImVec2 text_size = CalcTextSize(label, NULL, true);
5650    const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f);
5651    ItemSize(frame_bb);
60225652    if (!ItemAdd(frame_bb, &id))
60235653        return false;
60245654
5655    const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x,0));
60255656    const float arrow_size = (window->FontSize() + style.FramePadding.x * 2.0f);
60265657    const bool hovered = IsHovered(frame_bb, id);
60275658
r245117r245118
60385669            RenderTextClipped(frame_bb.Min + style.FramePadding, item_text, NULL, NULL, value_bb.Max);
60395670    }
60405671
6041    if (label_size.x > 0)
6042        RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
5672    // Empty text doesn't add padding
5673    if (text_size.x > 0)
5674    {
5675        ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
5676        ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
5677    }
60435678
60445679    ImGui::PushID((int)id);
60455680    bool menu_toggled = false;
r245117r245118
60635698
60645699        const ImVec2 backup_pos = ImGui::GetCursorPos();
60655700        const float popup_off_x = 0.0f;//style.ItemInnerSpacing.x;
6066        const float popup_height = (label_size.y + style.ItemSpacing.y) * ImMin(items_count, height_in_items) + style.WindowPadding.y;
5701        const float popup_height = (text_size.y + style.ItemSpacing.y) * ImMin(items_count, height_in_items) + style.WindowPadding.y;
60675702        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));
60685703        ImGui::SetCursorPos(popup_aabb.Min - window->Pos);
60695704
r245117r245118
61175752
61185753    const ImGuiStyle& style = g.Style;
61195754    const ImGuiID id = window->GetID(label);
6120    const ImVec2 label_size = CalcTextSize(label, NULL, true);
5755    const ImVec2 text_size = CalcTextSize(label, NULL, true);
61215756
61225757    const float w = window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x;
6123    const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : w, size_arg.y != 0.0f ? size_arg.y : label_size.y);
5758    const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : w, size_arg.y != 0.0f ? size_arg.y : text_size.y);
61245759    const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size);
61255760    ItemSize(bb);
61265761
r245117r245118
61485783    }
61495784
61505785    //const ImVec2 off = ImVec2(ImMax(0.0f, size.x - text_size.x) * 0.5f, ImMax(0.0f, size.y - text_size.y) * 0.5f);
6151    RenderTextClipped(bb.Min, label, NULL, &label_size, bb_with_spacing.Max);
5786    RenderTextClipped(bb.Min, label, NULL, &text_size, bb_with_spacing.Max);
61525787
61535788    return pressed;
61545789}
r245117r245118
61685803bool ImGui::ListBoxHeader(const char* label, const ImVec2& size_arg)
61695804{
61705805    ImGuiWindow* window = GetCurrentWindow();
5806    if (window->SkipItems)
5807        return false;
61715808
61725809    const ImGuiStyle& style = ImGui::GetStyle();
61735810    const ImGuiID id = ImGui::GetID(label);
r245117r245118
61795816    size.y = (size_arg.y != 0.0f) ? size_arg.y : ImGui::GetTextLineHeightWithSpacing() * 7.4f + style.ItemSpacing.y;
61805817    const ImVec2 frame_size = ImVec2(size.x, ImMax(size.y, label_size.y));
61815818    const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size);
6182    const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
6183    window->DC.LastItemAabb = bb;
61845819
61855820    if (label_size.x > 0)
61865821        RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
r245117r245118
62075842
62085843void ImGui::ListBoxFooter()
62095844{
6210    ImGuiWindow* parent_window = GetParentWindow();
6211    const ImGuiAabb bb = parent_window->DC.LastItemAabb;
6212
62135845    ImGui::EndChildFrame();
6214
6215    parent_window->DC.CursorPos = bb.Min;
6216    ItemSize(bb, NULL);
62175846}
62185847
62195848bool ImGui::ListBox(const char* label, int* current_item, const char** items, int items_count, int height_items)
r245117r245118
62245853
62255854bool ImGui::ListBox(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int height_in_items)
62265855{
6227    ImGuiWindow* window = GetCurrentWindow();
6228    if (window->SkipItems)
6229        return false;
6230
62315856    if (!ImGui::ListBoxHeader(label, items_count, height_in_items))
62325857        return false;
62335858
r245117r245118
62615886        return false;
62625887
62635888    const ImGuiStyle& style = g.Style;
6264    const ImGuiID id = window->GetID("#colorbutton");
5889    const ImGuiID id = window->GetID("##colorbutton");
62655890    const float square_size = window->FontSize();
62665891    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)));
62675892    ItemSize(bb);
r245117r245118
63816006            value_changed |= ImGui::InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal);
63826007            ImGui::PopItemWidth();
63836008            char* p = buf;
6384            while (*p == '#' || ImCharIsSpace(*p))
6009            while (*p == '#' || *p == ' ' || *p == '\t')
63856010                p++;
63866011
63876012            // Treat at unsigned (%X is unsigned)
r245117r245118
64696094    window->DrawList->AddLine(bb.Min, bb.Max, window->Color(ImGuiCol_Border));
64706095
64716096    if (window->DC.ColumnsCount > 1)
6472    {
64736097        PushColumnClipRect();
6474        window->DC.ColumnsCellMinY = window->DC.CursorPos.y;
6475    }
64766098}
64776099
64786100// A little vertical spacing.
r245117r245118
65016123    window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y);
65026124    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));
65036125
6504    window->SizeContentsCurrent = ImMax(window->SizeContentsCurrent, ImVec2(window->DC.CursorPosPrevLine.x - window->Pos.x, window->DC.CursorPos.y + window->ScrollY - window->Pos.y));
6126    window->SizeContentsFit = ImMax(window->SizeContentsFit, ImVec2(window->DC.CursorPosPrevLine.x, window->DC.CursorPos.y) - window->Pos + ImVec2(0.0f, window->ScrollY));
65056127
65066128    window->DC.PrevLineHeight = line_height;
65076129    window->DC.CurrentLineHeight = 0.0f;
65086130}
65096131
6510static void ItemSize(const ImGuiAabb& bb, ImVec2* adjust_start_offset)
6132static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset)
65116133{
6512    ItemSize(bb.GetSize(), adjust_start_offset);
6134    ItemSize(aabb.GetSize(), adjust_start_offset);
65136135}
65146136
65156137static bool IsClipped(const ImGuiAabb& bb)
r245117r245118
65386160        window->DC.LastItemHovered = false;
65396161        return false;
65406162    }
6541
6542    // This is a sensible default, but widgets are free to override it after calling ItemAdd()
6543    const bool hovered = IsMouseHoveringBox(bb);
6544    //const bool hovered = (g.ActiveId == 0 || (id && g.ActiveId == *id) || g.ActiveIdIsFocusedOnly) && IsMouseHoveringBox(bb);  // matching the behaviour of IsHovered(), not always what the user wants?
6545    window->DC.LastItemHovered = hovered;
6163    window->DC.LastItemHovered = IsMouseHoveringBox(bb);     // this is a sensible default but widgets are free to override it after calling ItemAdd()
65466164    return true;
65476165}
65486166
r245117r245118
66076225    }
66086226}
66096227
6610int ImGui::GetColumnIndex()
6611{
6612    ImGuiWindow* window = GetCurrentWindow();
6613    return window->DC.ColumnsCurrent;
6614}
6615
6616int ImGui::GetColumnsCount()
6617{
6618    ImGuiWindow* window = GetCurrentWindow();
6619    return window->DC.ColumnsCount;
6620}
6621
6228// FIMXE-OPT: This is called too often. We need to cache offset for active columns set.
66226229float ImGui::GetColumnOffset(int column_index)
66236230{
66246231    ImGuiState& g = *GImGui;
r245117r245118
66266233    if (column_index < 0)
66276234        column_index = window->DC.ColumnsCurrent;
66286235
6629    // Read from cache
6630    IM_ASSERT(column_index < (int)window->DC.ColumnsOffsetsT.size());
6631    const float t = window->DC.ColumnsOffsetsT[column_index];
6236    const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
6237    RegisterAliveId(column_id);
6238    const float default_t = column_index / (float)window->DC.ColumnsCount;
6239    const float t = window->StateStorage.GetFloat(column_id, default_t);      // Cheaply store our floating point value inside the integer (could store an union into the map?)
66326240
6633    const float min_x = window->DC.ColumnsStartX;
6634    const float max_x = window->Size.x - (g.Style.ScrollbarWidth);// - window->WindowPadding().x;
6635    const float offset = min_x + t * (max_x - min_x);
6241    const float offset = window->DC.ColumnsStartX + t * (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnsStartX);
66366242    return offset;
66376243}
66386244
r245117r245118
66436249    if (column_index < 0)
66446250        column_index = window->DC.ColumnsCurrent;
66456251
6646    IM_ASSERT(column_index < (int)window->DC.ColumnsOffsetsT.size());
66476252    const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
6648
6649    const float min_x = window->DC.ColumnsStartX;
6650    const float max_x = window->Size.x - (g.Style.ScrollbarWidth);// - window->WindowPadding().x;
6651    const float t = (offset - min_x) / (max_x - min_x);
6652    window->DC.StateStorage->SetFloat(column_id, t);
6653    window->DC.ColumnsOffsetsT[column_index] = t;
6253    const float t = (offset - window->DC.ColumnsStartX) / (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnsStartX);
6254    window->StateStorage.SetFloat(column_id, t);
66546255}
66556256
66566257float ImGui::GetColumnWidth(int column_index)
r245117r245118
66786279{
66796280    ImGuiState& g = *GImGui;
66806281    ImGuiWindow* window = GetCurrentWindow();
6282    if (window->SkipItems)
6283        return;
66816284
66826285    if (window->DC.ColumnsCount != 1)
66836286    {
r245117r245118
66916294    }
66926295
66936296    // Draw columns borders and handle resize at the time of "closing" a columns set
6694    if (window->DC.ColumnsCount != columns_count && window->DC.ColumnsCount != 1 && window->DC.ColumnsShowBorders && !window->SkipItems)
6297    if (window->DC.ColumnsCount != columns_count && window->DC.ColumnsCount != 1 && window->DC.ColumnsShowBorders)
66956298    {
66966299        const float y1 = window->DC.ColumnsStartPos.y;
66976300        const float y2 = window->DC.CursorPos.y;
r245117r245118
67356338
67366339    if (window->DC.ColumnsCount != 1)
67376340    {
6738        // Cache column offsets
6739        window->DC.ColumnsOffsetsT.resize((size_t)columns_count + 1);
6740        for (int column_index = 0; column_index < columns_count + 1; column_index++)
6741        {
6742            const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
6743            RegisterAliveId(column_id);
6744            const float default_t = column_index / (float)window->DC.ColumnsCount;
6745            const float t = window->DC.StateStorage->GetFloat(column_id, default_t);      // Cheaply store our floating point value inside the integer (could store an union into the map?)
6746            window->DC.ColumnsOffsetsT[column_index] = t;
6747        }
6748
67496341        PushColumnClipRect();
67506342        ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f);
67516343    }
6752    else
6753    {
6754        window->DC.ColumnsOffsetsT.resize(2);
6755        window->DC.ColumnsOffsetsT[0] = 0.0f;
6756        window->DC.ColumnsOffsetsT[1] = 1.0f;
6757    }
67586344}
67596345
67606346void ImGui::TreePush(const char* str_id)
r245117r245118
75607146    TexUvWhitePixel = ImVec2((TexExtraDataPos.x + 0.5f) / TexWidth, (TexExtraDataPos.y + 0.5f) / TexHeight);
75617147
75627148    // Draw a mouse cursor into texture
7563    // Because our font uses a single color channel, we have to spread the cursor in 2 layers (black/white) which will be rendered separately.
7149    // Because our font uses an alpha texture, we have to spread the cursor in 2 parts (black/white) which will be rendered separately.
75647150    const char cursor_pixels[] =
75657151    {
75667152        "X           "
r245117r245118
76097195    DisplayOffset = ImVec2(-0.5f, 0.5f);
76107196    ContainerAtlas = NULL;
76117197    Glyphs.clear();
7612    FallbackGlyph = NULL;
7613    FallbackXAdvance = 0.0f;
7614    IndexXAdvance.clear();
76157198    IndexLookup.clear();
7199    FallbackGlyph = NULL;
76167200}
76177201
76187202// Retrieve list of range (2 int per range, values are inclusive)
r245117r245118
76317215    static const ImWchar ranges[] =
76327216    {
76337217        0x0020, 0x00FF, // Basic Latin + Latin Supplement
7634        0x3000, 0x30FF, // Punctuations, Hiragana, Katakana
7635        0x31F0, 0x31FF, // Katakana Phonetic Extensions
7218        0x3040, 0x309F, // Hiragana, Katakana
76367219        0xFF00, 0xFFEF, // Half-width characters
76377220        0x4e00, 0x9FAF, // CJK Ideograms
76387221        0,
r245117r245118
76807263        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,
76817264    };
76827265    static int ranges_unpacked = false;
7683    static ImWchar ranges[8 + IM_ARRAYSIZE(offsets_from_0x4E00)*2 + 1] =
7266    static ImWchar ranges[6 + 1 + IM_ARRAYSIZE(offsets_from_0x4E00)*2] =
76847267    {
76857268        0x0020, 0x00FF, // Basic Latin + Latin Supplement
7686        0x3000, 0x30FF, // Punctuations, Hiragana, Katakana
7687        0x31F0, 0x31FF, // Katakana Phonetic Extensions
7269        0x3040, 0x309F, // Hiragana, Katakana
76887270        0xFF00, 0xFFEF, // Half-width characters
7271        0,
76897272    };
76907273    if (!ranges_unpacked)
76917274    {
76927275        // Unpack
76937276        int codepoint = 0x4e00;
7694        ImWchar* dst = &ranges[8];
7277        ImWchar* dst = &ranges[6];
76957278        for (int n = 0; n < IM_ARRAYSIZE(offsets_from_0x4E00); n++, dst += 2)
76967279            dst[0] = dst[1] = (ImWchar)(codepoint += (offsets_from_0x4E00[n] + 1));
76977280        dst[0] = 0;
r245117r245118
77067289    for (size_t i = 0; i != Glyphs.size(); i++)
77077290        max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint);
77087291
7709    IndexXAdvance.clear();
7710    IndexXAdvance.resize((size_t)max_codepoint + 1);
77117292    IndexLookup.clear();
77127293    IndexLookup.resize((size_t)max_codepoint + 1);
7713    for (size_t i = 0; i < (size_t)max_codepoint + 1; i++)
7714    {
7715        IndexXAdvance[i] = -1.0f;
7294    for (size_t i = 0; i < IndexLookup.size(); i++)
77167295        IndexLookup[i] = -1;
7717    }
77187296    for (size_t i = 0; i < Glyphs.size(); i++)
7719    {
7720        const size_t codepoint = (int)Glyphs[i].Codepoint;
7721        IndexXAdvance[codepoint] = Glyphs[i].XAdvance;
7722        IndexLookup[codepoint] = (int)i;
7723    }
7297        IndexLookup[(int)Glyphs[i].Codepoint] = (int)i;
77247298
77257299    // Create a glyph to handle TAB
77267300    // FIXME: Needs proper TAB handling but it needs to be contextualized (can arbitrary say that each string starts at "column 0"
7727    if (FindGlyph((unsigned short)' '))
7301    if (const ImFont::Glyph* space_glyph = FindGlyph((unsigned short)' '))
77287302    {
7729        if (Glyphs.back().Codepoint != '\t')   // So we can call this function multiple times
7730            Glyphs.resize(Glyphs.size() + 1);
7303        Glyphs.resize(Glyphs.size() + 1);
77317304        ImFont::Glyph& tab_glyph = Glyphs.back();
7732        tab_glyph = *FindGlyph((unsigned short)' ');
7305        tab_glyph = *space_glyph;
77337306        tab_glyph.Codepoint = '\t';
77347307        tab_glyph.XAdvance *= 4;
7735        IndexXAdvance[(size_t)tab_glyph.Codepoint] = (float)tab_glyph.XAdvance;
7736        IndexLookup[(size_t)tab_glyph.Codepoint] = (int)(Glyphs.size()-1);
7308        IndexLookup[(int)tab_glyph.Codepoint] = (int)(Glyphs.size()-1);
77377309    }
7738
7739    FallbackGlyph = NULL;
7740    FallbackGlyph = FindGlyph(FallbackChar);
7741    FallbackXAdvance = FallbackGlyph ? FallbackGlyph->XAdvance : 0.0f;
7742    for (size_t i = 0; i < (size_t)max_codepoint + 1; i++)
7743        if (IndexXAdvance[i] < 0.0f)
7744            IndexXAdvance[i] = FallbackXAdvance;
77457310}
77467311
7747void ImFont::SetFallbackChar(ImWchar c)
7748{
7749    FallbackChar = c;
7750    BuildLookupTable();
7751}
7752
77537312const ImFont::Glyph* ImFont::FindGlyph(unsigned short c) const
77547313{
77557314    if (c < (int)IndexLookup.size())
r245117r245118
77637322
77647323// Convert UTF-8 to 32-bits character, process single character input.
77657324// Based on stb_from_utf8() from github.com/nothings/stb/
7766// We handle UTF-8 decoding error by skipping forward.
77677325static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end)
77687326{
7769    unsigned int c = (unsigned int)-1;
7770    const unsigned char* str = (const unsigned char*)in_text;
7771    if (!(*str & 0x80))
7327    if (*in_text != 0)
77727328    {
7773        c = (unsigned int)(*str++);
7774        *out_char = c;
7775        return 1;
7329        unsigned int c = (unsigned int)-1;
7330        const unsigned char* str = (const unsigned char*)in_text;
7331        if (!(*str & 0x80))
7332        {
7333            c = (unsigned int)(*str++);
7334            *out_char = c;
7335            return 1;
7336        }
7337        if ((*str & 0xe0) == 0xc0)
7338        {
7339            if (in_text_end && in_text_end - (const char*)str < 2) return -1;
7340            if (*str < 0xc2) return -1;
7341            c = (unsigned int)((*str++ & 0x1f) << 6);
7342            if ((*str & 0xc0) != 0x80) return -1;
7343            c += (*str++ & 0x3f);
7344            *out_char = c;
7345            return 2;
7346        }
7347        if ((*str & 0xf0) == 0xe0)
7348        {
7349            if (in_text_end && in_text_end - (const char*)str < 3) return -1;
7350            if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return -1;
7351            if (*str == 0xed && str[1] > 0x9f) return -1; // str[1] < 0x80 is checked below
7352            c = (unsigned int)((*str++ & 0x0f) << 12);
7353            if ((*str & 0xc0) != 0x80) return -1;
7354            c += (unsigned int)((*str++ & 0x3f) << 6);
7355            if ((*str & 0xc0) != 0x80) return -1;
7356            c += (*str++ & 0x3f);
7357            *out_char = c;
7358            return 3;
7359        }
7360        if ((*str & 0xf8) == 0xf0)
7361        {
7362            if (in_text_end && in_text_end - (const char*)str < 4) return -1;
7363            if (*str > 0xf4) return -1;
7364            if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return -1;
7365            if (*str == 0xf4 && str[1] > 0x8f) return -1; // str[1] < 0x80 is checked below
7366            c = (unsigned int)((*str++ & 0x07) << 18);
7367            if ((*str & 0xc0) != 0x80) return -1;
7368            c += (unsigned int)((*str++ & 0x3f) << 12);
7369            if ((*str & 0xc0) != 0x80) return -1;
7370            c += (unsigned int)((*str++ & 0x3f) << 6);
7371            if ((*str & 0xc0) != 0x80) return -1;
7372            c += (*str++ & 0x3f);
7373            // utf-8 encodings of values used in surrogate pairs are invalid
7374            if ((c & 0xFFFFF800) == 0xD800) return -1;
7375            *out_char = c;
7376            return 4;
7377        }
77767378    }
7777    if ((*str & 0xe0) == 0xc0)
7778    {
7779        *out_char = 0;
7780        if (in_text_end && in_text_end - (const char*)str < 2) return 0;
7781        if (*str < 0xc2) return 0;
7782        c = (unsigned int)((*str++ & 0x1f) << 6);
7783        if ((*str & 0xc0) != 0x80) return 0;
7784        c += (*str++ & 0x3f);
7785        *out_char = c;
7786        return 2;
7787    }
7788    if ((*str & 0xf0) == 0xe0)
7789    {
7790        *out_char = 0;
7791        if (in_text_end && in_text_end - (const char*)str < 3) return 0;
7792        if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return 0;
7793        if (*str == 0xed && str[1] > 0x9f) return 0; // str[1] < 0x80 is checked below
7794        c = (unsigned int)((*str++ & 0x0f) << 12);
7795        if ((*str & 0xc0) != 0x80) return 0;
7796        c += (unsigned int)((*str++ & 0x3f) << 6);
7797        if ((*str & 0xc0) != 0x80) return 0;
7798        c += (*str++ & 0x3f);
7799        *out_char = c;
7800        return 3;
7801    }
7802    if ((*str & 0xf8) == 0xf0)
7803    {
7804        *out_char = 0;
7805        if (in_text_end && in_text_end - (const char*)str < 4) return 0;
7806        if (*str > 0xf4) return 0;
7807        if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return 0;
7808        if (*str == 0xf4 && str[1] > 0x8f) return 0; // str[1] < 0x80 is checked below
7809        c = (unsigned int)((*str++ & 0x07) << 18);
7810        if ((*str & 0xc0) != 0x80) return 0;
7811        c += (unsigned int)((*str++ & 0x3f) << 12);
7812        if ((*str & 0xc0) != 0x80) return 0;
7813        c += (unsigned int)((*str++ & 0x3f) << 6);
7814        if ((*str & 0xc0) != 0x80) return 0;
7815        c += (*str++ & 0x3f);
7816        // utf-8 encodings of values used in surrogate pairs are invalid
7817        if ((c & 0xFFFFF800) == 0xD800) return 0;
7818        *out_char = c;
7819        return 4;
7820    }
78217379    *out_char = 0;
78227380    return 0;
78237381}
78247382
7825static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end, const char** in_text_remaining)
7383static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end)
78267384{
78277385    ImWchar* buf_out = buf;
78287386    ImWchar* buf_end = buf + buf_size;
r245117r245118
78307388    {
78317389        unsigned int c;
78327390        in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
7833        if (c == 0)
7834            break;
78357391        if (c < 0x10000)    // FIXME: Losing characters that don't fit in 2 bytes
78367392            *buf_out++ = (ImWchar)c;
78377393    }
78387394    *buf_out = 0;
7839    if (in_text_remaining)
7840        *in_text_remaining = in_text;
78417395    return buf_out - buf;
78427396}
78437397
r245117r245118
78487402    {
78497403        unsigned int c;
78507404        in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
7851        if (c == 0)
7852            break;
78537405        if (c < 0x10000)
78547406            char_count++;
78557407    }
r245117r245118
79147466    return buf_out - buf;
79157467}
79167468
7917static int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end)
7469static int ImTextCountUtf8BytesFromWchar(const ImWchar* in_text, const ImWchar* in_text_end)
79187470{
79197471    int bytes_count = 0;
79207472    while ((!in_text_end || in_text < in_text_end) && *in_text)
r245117r245118
79547506    const char* s = text;
79557507    while (s < text_end)
79567508    {
7957        unsigned int c = (unsigned int)*s;
7958        const char* next_s;
7959        if (c < 0x80)
7960            next_s = s + 1;
7961        else
7962            next_s = s + ImTextCharFromUtf8(&c, s, text_end);
7963        if (c == 0)
7964            break;
7509        unsigned int c;
7510        const int bytes_count = ImTextCharFromUtf8(&c, s, text_end);
7511        const char* next_s = s + (bytes_count > 0 ? bytes_count : 1);
79657512
79667513        if (c == '\n')
79677514        {
r245117r245118
79717518            continue;
79727519        }
79737520
7974        const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance;
7975        if (ImCharIsSpace(c))
7521        float char_width = 0.0f;
7522        if (const Glyph* glyph = FindGlyph((unsigned short)c))
7523            char_width = glyph->XAdvance * scale;
7524
7525        if (c == ' ' || c == '\t')
79767526        {
79777527            if (inside_word)
79787528            {
r245117r245118
80547604                while (s < text_end)
80557605                {
80567606                    const char c = *s;
8057                    if (ImCharIsSpace(c)) { s++; } else if (c == '\n') { s++; break; } else { break; }
7607                    if (c == ' ' || c == '\t') { s++; } else if (c == '\n') { s++; break; } else { break; }
80587608                }
80597609                continue;
80607610            }
80617611        }
80627612
80637613        // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
8064        unsigned int c = (unsigned int)*s;
8065        if (c < 0x80)
8066        {
8067            s += 1;
8068        }
8069        else
8070        {
8071            s += ImTextCharFromUtf8(&c, s, text_end);
8072            if (c == 0)
8073                break;
8074        }
7614        unsigned int c;
7615        const int bytes_count = ImTextCharFromUtf8(&c, s, text_end);
7616        s += bytes_count > 0 ? bytes_count : 1;
80757617
80767618        if (c == '\n')
80777619        {
r245117r245118
80817623            continue;
80827624        }
80837625
8084        const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance;
7626        float char_width = 0.0f;
7627        if (const Glyph* glyph = FindGlyph((unsigned short)c))
7628            char_width = glyph->XAdvance * scale;
7629
80857630        if (line_width + char_width >= max_width)
80867631            break;
80877632
r245117r245118
81257670            continue;
81267671        }
81277672
8128        const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance;
7673        float char_width = 0.0f;
7674        if (const Glyph* glyph = FindGlyph((unsigned short)c))
7675            char_width = glyph->XAdvance * scale;
7676
81297677        if (line_width + char_width >= max_width)
81307678            break;
81317679
r245117r245118
81927740                while (s < text_end)
81937741                {
81947742                    const char c = *s;
8195                    if (ImCharIsSpace(c)) { s++; } else if (c == '\n') { s++; break; } else { break; }
7743                    if (c == ' ' || c == '\t') { s++; } else if (c == '\n') { s++; break; } else { break; }
81967744                }
81977745                continue;
81987746            }
81997747        }
82007748
82017749        // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
8202        unsigned int c = (unsigned int)*s;
8203        if (c < 0x80)
8204        {
8205            s += 1;
8206        }
8207        else
8208        {
8209            s += ImTextCharFromUtf8(&c, s, text_end);
8210            if (c == 0)
8211                break;
8212        }
7750        unsigned int c;
7751        const int bytes_count = ImTextCharFromUtf8(&c, s, text_end);
7752        s += bytes_count > 0 ? bytes_count : 1;
82137753
82147754        if (c == '\n')
82157755        {
r245117r245118
82917831
82927832#if defined(_MSC_VER) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS)
82937833
8294#ifndef _WINDOWS_
82957834#define WIN32_LEAN_AND_MEAN
82967835#include <windows.h>
8297#endif
82987836
82997837// Win32 API clipboard implementation
8300static const char* GetClipboardTextFn_DefaultImpl()
7838static const char* GetClipboardTextFn_DefaultImpl()
83017839{
83027840    static char* buf_local = NULL;
83037841    if (buf_local)
r245117r245118
83077845    }
83087846    if (!OpenClipboard(NULL))
83097847        return NULL;
8310    HANDLE wbuf_handle = GetClipboardData(CF_UNICODETEXT);
8311    if (wbuf_handle == NULL)
7848    HANDLE buf_handle = GetClipboardData(CF_TEXT);
7849    if (buf_handle == NULL)
83127850        return NULL;
8313    if (ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle))
8314    {
8315        int buf_len = ImTextCountUtf8BytesFromStr(wbuf_global, NULL) + 1;
8316        buf_local = (char*)ImGui::MemAlloc(buf_len * sizeof(char));
8317        ImTextStrToUtf8(buf_local, buf_len, wbuf_global, NULL);
8318    }
8319    GlobalUnlock(wbuf_handle);
7851    if (char* buf_global = (char*)GlobalLock(buf_handle))
7852        buf_local = ImStrdup(buf_global);
7853    GlobalUnlock(buf_handle);
83207854    CloseClipboard();
83217855    return buf_local;
83227856}
r245117r245118
83267860{
83277861    if (!OpenClipboard(NULL))
83287862        return;
8329
8330    const int wbuf_length = ImTextCountCharsFromUtf8(text, NULL) + 1;
8331    HGLOBAL wbuf_handle = GlobalAlloc(GMEM_MOVEABLE, (SIZE_T)wbuf_length * sizeof(ImWchar));
8332    if (wbuf_handle == NULL)
7863    const char* text_end = text + strlen(text);
7864    const int buf_length = (int)(text_end - text) + 1;
7865    HGLOBAL buf_handle = GlobalAlloc(GMEM_MOVEABLE, (SIZE_T)buf_length * sizeof(char));
7866    if (buf_handle == NULL)
83337867        return;
8334    ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle);
8335    ImTextStrFromUtf8(wbuf_global, wbuf_length, text, NULL);
8336    GlobalUnlock(wbuf_handle);
7868    char* buf_global = (char *)GlobalLock(buf_handle);
7869    memcpy(buf_global, text, (size_t)(text_end - text));
7870    buf_global[text_end - text] = 0;
7871    GlobalUnlock(buf_handle);
83377872    EmptyClipboard();
8338    SetClipboardData(CF_UNICODETEXT, wbuf_handle);
7873    SetClipboardData(CF_TEXT, buf_handle);
83397874    CloseClipboard();
83407875}
83417876
83427877#else
83437878
83447879// Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
8345static const char* GetClipboardTextFn_DefaultImpl()
7880static const char* GetClipboardTextFn_DefaultImpl()
83467881{
83477882    return GImGui->PrivateClipboard;
83487883}
r245117r245118
83647899
83657900#endif
83667901
8367#if defined(_MSC_VER) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS)
8368
8369#ifndef _WINDOWS_
8370#define WIN32_LEAN_AND_MEAN
8371#include <windows.h>
8372#endif
8373#include <Imm.h>
8374#pragma comment(lib, "imm32")
8375
8376static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y)
8377{
8378    // Notify OS Input Method Editor of text input position
8379    if (HWND hwnd = (HWND)GImGui->IO.ImeWindowHandle)
8380        if (HIMC himc = ImmGetContext(hwnd))
8381        {
8382            COMPOSITIONFORM cf;
8383            cf.ptCurrentPos.x = x;
8384            cf.ptCurrentPos.y = y;
8385            cf.dwStyle = CFS_FORCE_POSITION;
8386            ImmSetCompositionWindow(himc, &cf);
8387        }
8388}
8389
8390#else
8391
8392static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y)
8393{
8394}
8395
8396#endif
8397
83987902//-----------------------------------------------------------------------------
83997903// HELP
84007904//-----------------------------------------------------------------------------
r245117r245118
84537957        ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f");
84547958        ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 10.0f, "%.0f");
84557959        ImGui::SliderFloat("TreeNodeSpacing", &style.TreeNodeSpacing, 0.0f, 20.0f, "%.0f");
8456        ImGui::SliderFloat("ScrollBarWidth", &style.ScrollbarWidth, 1.0f, 20.0f, "%.0f");
8457        ImGui::SliderFloat("GrabMinSize", &style.GrabMinSize, 1.0f, 20.0f, "%.0f");
7960        ImGui::SliderFloat("ScrollBarWidth", &style.ScrollBarWidth, 0.0f, 20.0f, "%.0f");
84587961        ImGui::TreePop();
84597962    }
84607963
r245117r245118
85258028static void ShowExampleAppLongText(bool* opened);
85268029static void ShowExampleAppAutoResize(bool* opened);
85278030static void ShowExampleAppFixedOverlay(bool* opened);
8528static void ShowExampleAppManipulatingWindowTitle(bool* opened);
85298031static void ShowExampleAppCustomRendering(bool* opened);
85308032
85318033// Demonstrate ImGui features (unfortunately this makes this function a little bloated!)
85328034void ImGui::ShowTestWindow(bool* opened)
85338035{
8534    // Examples apps
8535    static bool show_app_console = false;
8536    static bool show_app_long_text = false;
8537    static bool show_app_auto_resize = false;
8538    static bool show_app_fixed_overlay = false;
8539    static bool show_app_custom_rendering = false;
8540    static bool show_app_manipulating_window_title = false;
8541    if (show_app_console)
8542        ShowExampleAppConsole(&show_app_console);
8543    if (show_app_long_text)
8544        ShowExampleAppLongText(&show_app_long_text);
8545    if (show_app_auto_resize)
8546        ShowExampleAppAutoResize(&show_app_auto_resize);
8547    if (show_app_fixed_overlay)
8548        ShowExampleAppFixedOverlay(&show_app_fixed_overlay);
8549    if (show_app_manipulating_window_title)
8550        ShowExampleAppManipulatingWindowTitle(&show_app_manipulating_window_title);
8551    if (show_app_custom_rendering)
8552        ShowExampleAppCustomRendering(&show_app_custom_rendering);
8553
85548036    static bool no_titlebar = false;
85558037    static bool no_border = true;
85568038    static bool no_resize = false;
85578039    static bool no_move = false;
85588040    static bool no_scrollbar = false;
85598041    static bool no_collapse = false;
8560    static float bg_alpha = 0.65f;
8042    static float fill_alpha = 0.65f;
85618043
85628044    // Demonstrate the various window flags. Typically you would just use the default.
85638045    ImGuiWindowFlags window_flags = 0;
r245117r245118
85678049    if (no_move)      window_flags |= ImGuiWindowFlags_NoMove;
85688050    if (no_scrollbar) window_flags |= ImGuiWindowFlags_NoScrollbar;
85698051    if (no_collapse)  window_flags |= ImGuiWindowFlags_NoCollapse;
8570    if (!ImGui::Begin("ImGui Test", opened, ImVec2(550,680), bg_alpha, window_flags))
8052    if (!ImGui::Begin("ImGui Test", opened, ImVec2(550,680), fill_alpha, window_flags))
85718053    {
85728054        // Early out if the window is collapsed, as an optimization.
85738055        ImGui::End();
85748056        return;
85758057    }
8058    ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f);
85768059
8577    ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f);    // 2/3 of the space for widget and 1/3 for labels
8578    //ImGui::PushItemWidth(-140);                             // Right align, keep 140 pixels for labels
8579
85808060    ImGui::Text("ImGui says hello.");
85818061    //ImGui::Text("MousePos (%g, %g)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
85828062    //ImGui::Text("MouseWheel %d", ImGui::GetIO().MouseWheel);
r245117r245118
85988078        ImGui::Checkbox("no move", &no_move); ImGui::SameLine(150);
85998079        ImGui::Checkbox("no scrollbar", &no_scrollbar); ImGui::SameLine(300);
86008080        ImGui::Checkbox("no collapse", &no_collapse);
8601        ImGui::SliderFloat("bg alpha", &bg_alpha, 0.0f, 1.0f);
8081        ImGui::SliderFloat("fill alpha", &fill_alpha, 0.0f, 1.0f);
86028082
86038083        if (ImGui::TreeNode("Style"))
86048084        {
r245117r245118
86698149        {
86708150            ImGui::BulletText("Bullet point 1");
86718151            ImGui::BulletText("Bullet point 2\nOn multiple lines");
8672            ImGui::Bullet(); ImGui::Text("Bullet point 3 (two calls)");
8673            ImGui::Bullet(); ImGui::SmallButton("Button 1");
8674            ImGui::Bullet(); ImGui::SmallButton("Button 2");
8152            ImGui::BulletText("Bullet point 3");
86758153            ImGui::TreePop();
86768154        }
86778155
r245117r245118
88138291            ImGui::TreePop();
88148292        }
88158293
8816        if (ImGui::TreeNode("Filtered Text Input"))
8817        {
8818            static char buf1[64] = ""; ImGui::InputText("default", buf1, 64);
8819            static char buf2[64] = ""; ImGui::InputText("decimal", buf2, 64, ImGuiInputTextFlags_CharsDecimal);
8820            static char buf3[64] = ""; ImGui::InputText("hexadecimal", buf3, 64, ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase);
8821            static char buf4[64] = ""; ImGui::InputText("uppercase", buf4, 64, ImGuiInputTextFlags_CharsUppercase);
8822            static char buf5[64] = ""; ImGui::InputText("no blank", buf5, 64, ImGuiInputTextFlags_CharsNoBlank);
8823            struct TextFilters { static int FilterImGuiLetters(ImGuiTextEditCallbackData* data) { if (data->EventChar < 256 && strchr("imgui", (char)data->EventChar)) return 0; return 1; } };
8824            static char buf6[64] = ""; ImGui::InputText("\"imgui\" letters", buf6, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterImGuiLetters);
8825            ImGui::TreePop();
8826        }
8827
88288294        static bool check = true;
88298295        ImGui::Checkbox("checkbox", &check);
88308296
r245117r245118
89268392        static int listbox_item_current = 1;
89278393        ImGui::ListBox("listbox\n(single select)", &listbox_item_current, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
89288394
8929        //static int listbox_item_current2 = 2;
89308395        //ImGui::PushItemWidth(-1);
89318396        //ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
89328397        //ImGui::PopItemWidth();
r245117r245118
89908455        ImGui::SameLine();
89918456        ImGui::Checkbox("Rich", &c4);
89928457
8993        // Various
8458        // SliderFloat
89948459        static float f0=1.0f, f1=2.0f, f2=3.0f;
89958460        ImGui::PushItemWidth(80);
8996        const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD" };
8997        static int item = -1;
8998        ImGui::Combo("Combo", &item, items, IM_ARRAYSIZE(items));
8999        ImGui::SameLine();
90008461        ImGui::SliderFloat("X", &f0, 0.0f,5.0f);
90018462        ImGui::SameLine();
90028463        ImGui::SliderFloat("Y", &f1, 0.0f,5.0f);
90038464        ImGui::SameLine();
90048465        ImGui::SliderFloat("Z", &f2, 0.0f,5.0f);
9005        ImGui::PopItemWidth();
9006
9007        ImGui::PushItemWidth(80);
9008        ImGui::Text("Lists:");
9009        static int selection[4] = { 0, 1, 2, 3 };
9010        for (int i = 0; i < 4; i++)
9011        {
9012            if (i > 0) ImGui::SameLine();
9013            ImGui::PushID(i);
9014            ImGui::ListBox("", &selection[i], items, IM_ARRAYSIZE(items));
9015            ImGui::PopID();
9016            //if (ImGui::IsItemHovered()) ImGui::SetTooltip("ListBox %d hovered", i);
9017        }
9018        ImGui::PopItemWidth();
90198466    }
90208467
90218468    if (ImGui::CollapsingHeader("Child regions"))
r245117r245118
90588505
90598506    if (ImGui::CollapsingHeader("Columns"))
90608507    {
9061        // Basic columns
9062        ImGui::Text("Basic:");
9063        ImGui::Columns(4, "mycolumns");
8508        ImGui::Columns(4, "data", true);
90648509        ImGui::Text("ID"); ImGui::NextColumn();
90658510        ImGui::Text("Name"); ImGui::NextColumn();
90668511        ImGui::Text("Path"); ImGui::NextColumn();
90678512        ImGui::Text("Flags"); ImGui::NextColumn();
90688513        ImGui::Separator();
9069        const char* names[3] = { "Robert", "Stephanie", "C64" };
9070        const char* paths[3] = { "/path/robert", "/path/stephanie", "/path/computer" };
9071        for (int i = 0; i < 3; i++)
9072        {
9073            ImGui::Text("%04d", i); ImGui::NextColumn();
9074            ImGui::Text(names[i]); ImGui::NextColumn();
9075            ImGui::Text(paths[i]); ImGui::NextColumn();
9076            ImGui::Text("...."); ImGui::NextColumn();
9077        }
9078        ImGui::Columns(1);
90798514
9080        ImGui::Separator();
9081        ImGui::Spacing();
8515        ImGui::Text("0000"); ImGui::NextColumn();
8516        ImGui::Text("Robert"); ImGui::NextColumn();
8517        ImGui::Text("/path/robert"); ImGui::NextColumn();
8518        ImGui::Text("...."); ImGui::NextColumn();
90828519
9083        // Scrolling columns
9084      /*
9085        ImGui::Text("Scrolling:");
9086        ImGui::BeginChild("##header", ImVec2(0, ImGui::GetTextLineHeightWithSpacing()+ImGui::GetStyle().ItemSpacing.y));
9087        ImGui::Columns(3);
9088        ImGui::Text("ID"); ImGui::NextColumn();
9089        ImGui::Text("Name"); ImGui::NextColumn();
9090        ImGui::Text("Path"); ImGui::NextColumn();
8520        ImGui::Text("0001"); ImGui::NextColumn();
8521        ImGui::Text("Stephanie"); ImGui::NextColumn();
8522        ImGui::Text("/path/stephanie"); ImGui::NextColumn();
8523        ImGui::Text("line 1"); ImGui::Text("line 2"); ImGui::NextColumn(); // two lines, two items
8524
8525        ImGui::Text("0002"); ImGui::NextColumn();
8526        ImGui::Text("C64"); ImGui::NextColumn();
8527        ImGui::Text("/path/computer"); ImGui::NextColumn();
8528        ImGui::Text("...."); ImGui::NextColumn();
90918529        ImGui::Columns(1);
9092        ImGui::Separator();
9093        ImGui::EndChild();
9094        ImGui::BeginChild("##scrollingregion", ImVec2(0, 60));
9095        ImGui::Columns(3);
9096        for (int i = 0; i < 10; i++)
9097        {
9098            ImGui::Text("%04d", i); ImGui::NextColumn();
9099            ImGui::Text("Foobar"); ImGui::NextColumn();
9100            ImGui::Text("/path/foobar/%04d/", i); ImGui::NextColumn();
9101        }
9102        ImGui::Columns(1);
9103        ImGui::EndChild();
91048530
91058531        ImGui::Separator();
9106        ImGui::Spacing();
9107      */
91088532
9109        // Create multiple items in a same cell before switching to next column
9110        ImGui::Text("Mixed items:");
91118533        ImGui::Columns(3, "mixed");
9112        ImGui::Separator();
91138534
8535        // Create multiple items in a same cell because switching to next column
91148536        static int e = 0;
91158537        ImGui::Text("Hello");
91168538        ImGui::Button("Banana");
r245117r245118
91208542        ImGui::Text("ImGui");
91218543        ImGui::Button("Apple");
91228544        ImGui::RadioButton("radio b", &e, 1);
9123        static float foo = 1.0f;
9124        ImGui::InputFloat("red", &foo, 0.05f, 0, 3);
91258545        ImGui::Text("An extra line here.");
91268546        ImGui::NextColumn();
91278547
91288548        ImGui::Text("World!");
91298549        ImGui::Button("Corniflower");
91308550        ImGui::RadioButton("radio c", &e, 2);
9131        static float bar = 1.0f;
9132        ImGui::InputFloat("blue", &bar, 0.05f, 0, 3);
91338551        ImGui::NextColumn();
91348552
91358553        if (ImGui::CollapsingHeader("Category A")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
91368554        if (ImGui::CollapsingHeader("Category B")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
91378555        if (ImGui::CollapsingHeader("Category C")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
8556
91388557        ImGui::Columns(1);
91398558
91408559        ImGui::Separator();
9141        ImGui::Spacing();
91428560
9143        // Tree items
9144        ImGui::Text("Tree items:");
9145        ImGui::Columns(2, "tree items");
9146        ImGui::Separator();
9147        if (ImGui::TreeNode("Hello")) { ImGui::BulletText("World"); ImGui::TreePop(); } ImGui::NextColumn();
9148        if (ImGui::TreeNode("Bonjour")) { ImGui::BulletText("Monde"); ImGui::TreePop(); } ImGui::NextColumn();
8561        ImGui::Columns(2, "multiple components");
8562        static float foo = 1.0f;
8563        ImGui::InputFloat("red", &foo, 0.05f, 0, 3); ImGui::NextColumn();
8564        static float bar = 1.0f;
8565        ImGui::InputFloat("blue", &bar, 0.05f, 0, 3); ImGui::NextColumn();
91498566        ImGui::Columns(1);
91508567
91518568        ImGui::Separator();
9152        ImGui::Spacing();
91538569
9154        // Word-wrapping
9155        ImGui::Text("Word-wrapping:");
9156        ImGui::Columns(2, "word-wrapping");
8570        ImGui::Columns(2, "tree items");
8571        if (ImGui::TreeNode("Hello")) { ImGui::BulletText("World"); ImGui::TreePop(); } ImGui::NextColumn();
8572        if (ImGui::TreeNode("Bonjour")) { ImGui::BulletText("Monde"); ImGui::TreePop(); }
8573        ImGui::Columns(1);
91578574        ImGui::Separator();
8575
8576        ImGui::Columns(2, "word wrapping");
91588577        ImGui::TextWrapped("The quick brown fox jumps over the lazy dog.");
91598578        ImGui::Text("Hello Left");
91608579        ImGui::NextColumn();
r245117r245118
91638582        ImGui::Columns(1);
91648583
91658584        ImGui::Separator();
9166        ImGui::Spacing();
91678585
91688586        if (ImGui::TreeNode("Inside a tree.."))
91698587        {
91708588            if (ImGui::TreeNode("node 1 (with borders)"))
91718589            {
91728590                ImGui::Columns(4);
9173                for (int i = 0; i < 8; i++)
9174                {
9175                    ImGui::Text("%c%c%c", 'a'+i, 'a'+i, 'a'+i);
9176                    ImGui::NextColumn();
9177                }
8591                ImGui::Text("aaa"); ImGui::NextColumn();
8592                ImGui::Text("bbb"); ImGui::NextColumn();
8593                ImGui::Text("ccc"); ImGui::NextColumn();
8594                ImGui::Text("ddd"); ImGui::NextColumn();
8595                ImGui::Text("eee"); ImGui::NextColumn();
8596                ImGui::Text("fff"); ImGui::NextColumn();
8597                ImGui::Text("ggg"); ImGui::NextColumn();
8598                ImGui::Text("hhh"); ImGui::NextColumn();
91788599                ImGui::Columns(1);
91798600                ImGui::TreePop();
91808601            }
91818602            if (ImGui::TreeNode("node 2 (without borders)"))
91828603            {
91838604                ImGui::Columns(4, NULL, false);
9184                for (int i = 0; i < 8; i++)
9185                {
9186                    ImGui::Text("%c%c%c", 'a'+i, 'a'+i, 'a'+i);
9187                    ImGui::NextColumn();
9188                }
8605                ImGui::Text("aaa"); ImGui::NextColumn();
8606                ImGui::Text("bbb"); ImGui::NextColumn();
8607                ImGui::Text("ccc"); ImGui::NextColumn();
8608                ImGui::Text("ddd"); ImGui::NextColumn();
8609                ImGui::Text("eee"); ImGui::NextColumn();
8610                ImGui::Text("fff"); ImGui::NextColumn();
8611                ImGui::Text("ggg"); ImGui::NextColumn();
8612                ImGui::Text("hhh"); ImGui::NextColumn();
91898613                ImGui::Columns(1);
91908614                ImGui::TreePop();
91918615            }
r245117r245118
92508674                ImGui::Text("Item with focus: %d", has_focus);
92518675            else
92528676                ImGui::Text("Item with focus: <none>");
9253            ImGui::TextWrapped("Cursor & selection are preserved when refocusing last used item in code.");
92548677            ImGui::TreePop();
92558678        }
92568679    }
92578680
8681    static bool show_app_console = false;
8682    static bool show_app_long_text = false;
8683    static bool show_app_auto_resize = false;
8684    static bool show_app_fixed_overlay = false;
8685    static bool show_app_custom_rendering = false;
92588686    if (ImGui::CollapsingHeader("App Examples"))
92598687    {
92608688        ImGui::Checkbox("Console", &show_app_console);
92618689        ImGui::Checkbox("Long text display", &show_app_long_text);
92628690        ImGui::Checkbox("Auto-resizing window", &show_app_auto_resize);
92638691        ImGui::Checkbox("Simple overlay", &show_app_fixed_overlay);
9264        ImGui::Checkbox("Manipulating window title", &show_app_manipulating_window_title);
92658692        ImGui::Checkbox("Custom rendering", &show_app_custom_rendering);
92668693    }
8694    if (show_app_console)
8695        ShowExampleAppConsole(&show_app_console);
8696    if (show_app_long_text)
8697        ShowExampleAppLongText(&show_app_long_text);
8698    if (show_app_auto_resize)
8699        ShowExampleAppAutoResize(&show_app_auto_resize);
8700    if (show_app_fixed_overlay)
8701        ShowExampleAppFixedOverlay(&show_app_fixed_overlay);
8702    if (show_app_custom_rendering)
8703        ShowExampleAppCustomRendering(&show_app_custom_rendering);
92678704
92688705    ImGui::End();
92698706}
r245117r245118
93018738    ImGui::End();
93028739}
93038740
9304static void ShowExampleAppManipulatingWindowTitle(bool* /*opened*/)
9305{
9306    // By default, Windows are uniquely identified by their title.
9307    // You can use the "##" and "###" markers to manipulate the display/ID. Read FAQ at the top of this file!
9308
9309    // Using "##" to display same title but have unique identifier.
9310    ImGui::SetNextWindowPos(ImVec2(100,100), ImGuiSetCond_FirstUseEver);
9311    ImGui::Begin("Same title as another window##1");
9312    ImGui::Text("This is window 1.\nMy title is the same as window 2, but my identifier is unique.");
9313    ImGui::End();
9314
9315    ImGui::SetNextWindowPos(ImVec2(100,200), ImGuiSetCond_FirstUseEver);
9316    ImGui::Begin("Same title as another window##2");
9317    ImGui::Text("This is window 2.\nMy title is the same as window 1, but my identifier is unique.");
9318    ImGui::End();
9319
9320    // Using "###" to display a changing title but keep a static identifier "MyWindow"
9321    char buf[128];
9322    ImFormatString(buf, IM_ARRAYSIZE(buf), "Animated title %c %d###MyWindow", "|/-\\"[(int)(ImGui::GetTime()/0.25f)&3], rand());
9323    ImGui::SetNextWindowPos(ImVec2(100,300), ImGuiSetCond_FirstUseEver);
9324    ImGui::Begin(buf);
9325    ImGui::Text("This window has a changing title.");
9326    ImGui::End();
9327}
9328
93298741static void ShowExampleAppCustomRendering(bool* opened)
93308742{
9331    ImGui::SetNextWindowSize(ImVec2(300,350), ImGuiSetCond_FirstUseEver);
93328743    if (!ImGui::Begin("Example: Custom Rendering", opened))
93338744    {
93348745        ImGui::End();
r245117r245118
93438754    static ImVector<ImVec2> points;
93448755    static bool adding_line = false;
93458756    if (ImGui::Button("Clear")) points.clear();
9346    if (points.size() >= 2) { ImGui::SameLine(); if (ImGui::Button("Undo")) { points.pop_back(); points.pop_back(); } }
8757    if (points.size() > 2) { ImGui::SameLine(); if (ImGui::Button("Undo")) points.pop_back(); }
93478758    ImGui::Text("Left-click and drag to add lines");
93488759    ImGui::Text("Right-click to undo");
93498760
r245117r245118
94498860        if (ImGui::SmallButton("Add Dummy Text")) { AddLog("%d some text", Items.size()); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine();
94508861        if (ImGui::SmallButton("Add Dummy Error")) AddLog("[error] something went wrong"); ImGui::SameLine();
94518862        if (ImGui::SmallButton("Clear")) ClearLog();
9452        //static float t = 0.0f; if (ImGui::GetTime() - t > 0.02f) { t = ImGui::GetTime(); AddLog("Spam %f", t); }
9453
94548863        ImGui::Separator();
94558864
94568865        ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0));
r245117r245118
95368945        }
95378946    }
95388947
9539    static int TextEditCallbackStub(ImGuiTextEditCallbackData* data)
8948    static void TextEditCallbackStub(ImGuiTextEditCallbackData* data)
95408949    {
95418950        ExampleAppConsole* console = (ExampleAppConsole*)data->UserData;
9542        return console->TextEditCallback(data);
8951        console->TextEditCallback(data);
95438952    }
95448953
9545    int     TextEditCallback(ImGuiTextEditCallbackData* data)
8954    void    TextEditCallback(ImGuiTextEditCallbackData* data)
95468955    {
95478956        //AddLog("cursor: %d, selection: %d-%d", data->CursorPos, data->SelectionStart, data->SelectionEnd);
9548        switch (data->EventFlag)
8957        switch (data->EventKey)
95498958        {
9550        case ImGuiInputTextFlags_CallbackCompletion:
8959        case ImGuiKey_Tab:
95518960            {
95528961                // Example of TEXT COMPLETION
95538962
r245117r245118
95578966                while (word_start > data->Buf)
95588967                {
95598968                    const char c = word_start[-1];
9560                    if (ImCharIsSpace(c) || c == ',' || c == ';')
8969                    if (c == ' ' || c == '\t' || c == ',' || c == ';')
95618970                        break;
95628971                    word_start--;
95638972                }
r245117r245118
96129021
96139022                break;
96149023            }
9615        case ImGuiInputTextFlags_CallbackHistory:
9024        case ImGuiKey_UpArrow:
9025        case ImGuiKey_DownArrow:
96169026            {
96179027                // Example of HISTORY
96189028                const int prev_history_pos = HistoryPos;
r245117r245118
96399049                }
96409050            }
96419051        }
9642        return 0;
96439052    }
96449053};
96459054
trunk/3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.h
r245117r245118
1// ImGui library v1.35
1// ImGui library v1.32 wip
22// See .cpp file for documentation.
33// See ImGui::ShowTestWindow() for sample code.
44// Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
r245117r245118
66
77#pragma once
88
9#include "imconfig.h"       // User-editable configuration file
9struct ImDrawCmd;
10struct ImDrawList;
11struct ImFont;
12struct ImFontAtlas;
13struct ImGuiAabb;
14struct ImGuiIO;
15struct ImGuiStorage;
16struct ImGuiStyle;
17struct ImGuiWindow;
18
19#include "imconfig.h"
1020#include <float.h>          // FLT_MAX
1121#include <stdarg.h>         // va_list
1222#include <stddef.h>         // ptrdiff_t
1323#include <stdlib.h>         // NULL, malloc
1424#include <string.h>         // memset, memmove
1525
16// Define assertion handler.
1726#ifndef IM_ASSERT
1827#include <assert.h>
1928#define IM_ASSERT(_EXPR)    assert(_EXPR)
2029#endif
2130
22// Define attributes of all API symbols declarations, e.g. for DLL under Windows.
2331#ifndef IMGUI_API
2432#define IMGUI_API
2533#endif
2634
27// Forward declarations
28struct ImDrawCmd;
29struct ImDrawList;
30struct ImFont;
31struct ImFontAtlas;
32struct ImGuiIO;
33struct ImGuiStorage;
34struct ImGuiStyle;
35
3635typedef unsigned int ImU32;
3736typedef unsigned short ImWchar;     // character for display
3837typedef void* ImTextureID;          // user data to refer to a texture (e.g. store your texture handle/id)
r245117r245118
4241typedef int ImGuiKey;               // enum ImGuiKey_
4342typedef int ImGuiColorEditMode;     // enum ImGuiColorEditMode_
4443typedef int ImGuiWindowFlags;       // enum ImGuiWindowFlags_
45typedef int ImGuiSetCond;           // enum ImGuiSetCondition_
44typedef int ImGuiSetCondition;      // enum ImGuiSetCondition_
4645typedef int ImGuiInputTextFlags;    // enum ImGuiInputTextFlags_
47struct ImGuiTextEditCallbackData;   // for advanced uses of InputText()
48typedef int (*ImGuiTextEditCallback)(ImGuiTextEditCallbackData *data);
46struct ImGuiTextEditCallbackData;   // for advanced uses of InputText()
4947
5048struct ImVec2
5149{
r245117r245118
7674    IMGUI_API void        MemFree(void* ptr);
7775}
7876
79// std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug).
77// std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug).
8078// Use '#define ImVector std::vector' if you want to use the STL type or your own type.
8179// Our implementation does NOT call c++ constructors! because the data types we use don't need them (but that could be added as well). Only provide the minimum functionalities we need.
8280#ifndef ImVector
r245117r245118
117115    inline void                 swap(ImVector<T>& rhs)          { const size_t rhs_size = rhs.Size; rhs.Size = Size; Size = rhs_size; const size_t rhs_cap = rhs.Capacity; rhs.Capacity = Capacity; Capacity = rhs_cap; value_type* rhs_data = rhs.Data; rhs.Data = Data; Data = rhs_data; }
118116
119117    inline void                 resize(size_t new_size)         { if (new_size > Capacity) reserve(new_size); Size = new_size; }
120    inline void                 reserve(size_t new_capacity)   
121    {
118    inline void                 reserve(size_t new_capacity)
119    {
122120        if (new_capacity <= Capacity) return;
123121        T* new_data = (value_type*)ImGui::MemAlloc(new_capacity * sizeof(value_type));
124122        memcpy(new_data, Data, Size * sizeof(value_type));
125123        ImGui::MemFree(Data);
126124        Data = new_data;
127        Capacity = new_capacity;
125        Capacity = new_capacity;
128126    }
129127
130128    inline void                 push_back(const value_type& v)  { if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); Data[Size++] = v; }
r245117r245118
143141// - struct ImDrawList                  // Draw command list
144142// - struct ImFont                      // TTF font loader, bake glyphs into bitmap
145143
146// ImGui end-user API
144// ImGui End-user API
147145// In a namespace so that user can add extra functions (e.g. Value() helpers for your vector or common types)
148146namespace ImGui
149147{
r245117r245118
158156    IMGUI_API void          ShowTestWindow(bool* open = NULL);
159157
160158    // Window
161    // See implementation in .cpp for details
162    IMGUI_API bool          Begin(const char* name = "Debug", bool* p_opened = NULL, const ImVec2& initial_size = ImVec2(0,0), float bg_alpha = -1.0f, ImGuiWindowFlags flags = 0); // return false when window is collapsed, so you can early out in your code. passing 'bool* p_opened' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed.
159    IMGUI_API bool          Begin(const char* name = "Debug", bool* p_opened = NULL, ImVec2 size = ImVec2(0,0), float fill_alpha = -1.0f, ImGuiWindowFlags flags = 0);// return false when window is collapsed, so you can early out in your code. passing 'bool* p_opened' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed.
163160    IMGUI_API void          End();
164    IMGUI_API bool          BeginChild(const char* str_id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0);            // size==0.0f: use remaining window size, size<0.0f: use remaining window size minus abs(size). on each axis.
165    IMGUI_API bool          BeginChild(ImGuiID id, const ImVec2& size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0);                    // "
161    IMGUI_API void          BeginChild(const char* str_id, ImVec2 size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0);                         // size==0.0f: use remaining window size, size<0.0f: use remaining window size minus abs(size). on each axis.
162    IMGUI_API void          BeginChild(ImGuiID id, ImVec2 size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0);                                 // "
166163    IMGUI_API void          EndChild();
167164    IMGUI_API bool          GetWindowIsFocused();
168165    IMGUI_API ImVec2        GetContentRegionMax();                                              // window or current column boundaries, in windows coordinates
r245117r245118
176173    IMGUI_API ImVec2        GetWindowSize();                                                    // get current window position.
177174    IMGUI_API float         GetWindowWidth();
178175    IMGUI_API bool          GetWindowCollapsed();
176    IMGUI_API void          SetNextWindowPos(const ImVec2& pos, ImGuiSetCondition cond = 0);    // set next window position - call before Begin().
177    IMGUI_API void          SetNextWindowSize(const ImVec2& size, ImGuiSetCondition cond = 0);  // set next window size. set to ImVec2(0,0) to force an auto-fit.
178    IMGUI_API void          SetNextWindowCollapsed(bool collapsed, ImGuiSetCondition cond = 0); // set next window collapsed state.
179    IMGUI_API void          SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond = 0);        // set current window position - call within Begin()/End(). may incur tearing.
180    IMGUI_API void          SetWindowSize(const ImVec2& size, ImGuiSetCondition cond = 0);      // set current window size. set to ImVec2(0,0) to force an auto-fit. may incur tearing.
181    IMGUI_API void          SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond = 0);     // set current window collapsed state.
179182
180    IMGUI_API void          SetNextWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0);         // set next window position - call before Begin().
181    IMGUI_API void          SetNextWindowSize(const ImVec2& size, ImGuiSetCond cond = 0);       // set next window size. set to ImVec2(0,0) to force an auto-fit.
182    IMGUI_API void          SetNextWindowCollapsed(bool collapsed, ImGuiSetCond cond = 0);      // set next window collapsed state.
183    IMGUI_API void          SetNextWindowFocus();                                               // set next window to be focused / front-most
184    IMGUI_API void          SetWindowPos(const ImVec2& pos, ImGuiSetCond cond = 0);             // set current window position - call within Begin()/End(). may incur tearing.
185    IMGUI_API void          SetWindowSize(const ImVec2& size, ImGuiSetCond cond = 0);           // set current window size. set to ImVec2(0,0) to force an auto-fit. may incur tearing.
186    IMGUI_API void          SetWindowCollapsed(bool collapsed, ImGuiSetCond cond = 0);          // set current window collapsed state.
187    IMGUI_API void          SetWindowFocus();                                                   // set current window to be focused / front-most
188    IMGUI_API void          SetWindowPos(const char* name, const ImVec2& pos, ImGuiSetCond cond = 0);      // set named window position - call within Begin()/End(). may incur tearing.
189    IMGUI_API void          SetWindowSize(const char* name, const ImVec2& size, ImGuiSetCond cond = 0);    // set named window size. set to ImVec2(0,0) to force an auto-fit. may incur tearing.
190    IMGUI_API void          SetWindowCollapsed(const char* name, bool collapsed, ImGuiSetCond cond = 0);   // set named window collapsed state.
191    IMGUI_API void          SetWindowFocus(const char* name);                                              // set named window to be focused / front-most
192
193    IMGUI_API float         GetScrollPosY();                                                    // get scrolling position (0..GetScrollMaxY())
194    IMGUI_API float         GetScrollMaxY();                                                    // get maximum scrolling position == ContentSize.Y - WindowSize.Y
195183    IMGUI_API void          SetScrollPosHere();                                                 // adjust scrolling position to center into the current cursor position.
196184    IMGUI_API void          SetKeyboardFocusHere(int offset = 0);                               // focus keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget.
197185    IMGUI_API void          SetStateStorage(ImGuiStorage* tree);                                // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it).
r245117r245118
227215    IMGUI_API void          Spacing();
228216    IMGUI_API void          Columns(int count = 1, const char* id = NULL, bool border=true);    // setup number of columns
229217    IMGUI_API void          NextColumn();                                                       // next column
230    IMGUI_API int           GetColumnIndex();                                                   // get current column index
231    IMGUI_API float         GetColumnOffset(int column_index = -1);                             // get position of column line (in pixels, from the left side of the contents region). pass -1 to use current column, otherwise 0..GetcolumnsCount() inclusive. column 0 is usually 0.0f and not resizable unless you call this.
232    IMGUI_API void          SetColumnOffset(int column_index, float offset_x);                  // set position of column line (in pixels, from the left side of the contents region). pass -1 to use current column.
233    IMGUI_API float         GetColumnWidth(int column_index = -1);                              // column width (== GetColumnOffset(GetColumnIndex()+1) - GetColumnOffset(GetColumnOffset())
234    IMGUI_API int           GetColumnsCount();                                                  // number of columns (what was passed to Columns())
218    IMGUI_API float         GetColumnOffset(int column_index = -1);
219    IMGUI_API void          SetColumnOffset(int column_index, float offset);
220    IMGUI_API float         GetColumnWidth(int column_index = -1);
235221    IMGUI_API ImVec2        GetCursorPos();                                                     // cursor position is relative to window position
236222    IMGUI_API float         GetCursorPosX();                                                    // "
237223    IMGUI_API float         GetCursorPosY();                                                    // "
r245117r245118
245231    IMGUI_API float         GetTextLineHeightWithSpacing();                                     // spacing (in pixels) between 2 consecutive lines of text == GetWindowFontSize() + GetStyle().ItemSpacing.y
246232
247233    // ID scopes
248    // If you are creating widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them.
249    // You can also use "##extra" within your widget name to distinguish them from each others (see 'Programmer Guide')
234    // If you are creating repeated widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them.
235    // You can also use ## within your widget name to distinguish them from each others (see 'Programmer Guide')
250236    IMGUI_API void          PushID(const char* str_id);                                         // push identifier into the ID stack. IDs are hash of the *entire* stack!
251237    IMGUI_API void          PushID(const void* ptr_id);
252238    IMGUI_API void          PushID(const int int_id);
r245117r245118
262248    IMGUI_API void          TextWrapped(const char* fmt, ...);                                  // shortcut for PushTextWrapPos(0.0f); Text(fmt, ...); PopTextWrapPos();
263249    IMGUI_API void          TextWrappedV(const char* fmt, va_list args);
264250    IMGUI_API void          TextUnformatted(const char* text, const char* text_end = NULL);     // doesn't require null terminated string if 'text_end' is specified. no copy done to any bounded stack buffer, recommended for long chunks of text.
265    IMGUI_API void          LabelText(const char* label, const char* fmt, ...);                 // display text+label aligned the same way as value+label widgets
251    IMGUI_API void          LabelText(const char* label, const char* fmt, ...);                 // display text+label aligned the same way as value+label widgets
266252    IMGUI_API void          LabelTextV(const char* label, const char* fmt, va_list args);
267    IMGUI_API void          Bullet();
268253    IMGUI_API void          BulletText(const char* fmt, ...);
269254    IMGUI_API void          BulletTextV(const char* fmt, va_list args);
270255    IMGUI_API bool          Button(const char* label, const ImVec2& size = ImVec2(0,0), bool repeat_when_held = false);
r245117r245118
272257    IMGUI_API bool          InvisibleButton(const char* str_id, const ImVec2& size);
273258    IMGUI_API void          Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0));
274259    IMGUI_API bool          ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0),  const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,1), const ImVec4& tint_col = ImVec4(1,1,1,1));    // <0 frame_padding uses default frame padding settings. 0 for no paddnig.
275    IMGUI_API bool          CollapsingHeader(const char* label, const char* str_id = NULL, bool display_frame = true, bool default_open = false);
260    IMGUI_API bool          CollapsingHeader(const char* label, const char* str_id = NULL, const bool display_frame = true, const bool default_open = false);
276261    IMGUI_API bool          SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);     // adjust display_format to decorate the value with a prefix or a suffix. Use power!=1.0 for logarithmic sliders.
277262    IMGUI_API bool          SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
278263    IMGUI_API bool          SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
r245117r245118
290275    IMGUI_API bool          CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value);
291276    IMGUI_API bool          RadioButton(const char* label, bool active);
292277    IMGUI_API bool          RadioButton(const char* label, int* v, int v_button);
293    IMGUI_API bool          InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, ImGuiTextEditCallback callback = NULL, void* user_data = NULL);
278    IMGUI_API bool          InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, void (*callback)(ImGuiTextEditCallbackData*) = NULL, void* user_data = NULL);
294279    IMGUI_API bool          InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, int decimal_precision = -1, ImGuiInputTextFlags extra_flags = 0);
295280    IMGUI_API bool          InputFloat2(const char* label, float v[2], int decimal_precision = -1);
296281    IMGUI_API bool          InputFloat3(const char* label, float v[3], int decimal_precision = -1);
r245117r245118
303288    IMGUI_API bool          ColorEdit3(const char* label, float col[3]);
304289    IMGUI_API bool          ColorEdit4(const char* label, float col[4], bool show_alpha = true);
305290    IMGUI_API void          ColorEditMode(ImGuiColorEditMode mode);
306
307    // Trees
308291    IMGUI_API bool          TreeNode(const char* str_label_id);                                 // if returning 'true' the node is open and the user is responsible for calling TreePop
309292    IMGUI_API bool          TreeNode(const char* str_id, const char* fmt, ...);                 // "
310293    IMGUI_API bool          TreeNode(const void* ptr_id, const char* fmt, ...);                 // "
r245117r245118
313296    IMGUI_API void          TreePush(const char* str_id = NULL);                                // already called by TreeNode(), but you can call Push/Pop yourself for layouting purpose
314297    IMGUI_API void          TreePush(const void* ptr_id = NULL);                                // "
315298    IMGUI_API void          TreePop();
316    IMGUI_API void          SetNextTreeNodeOpened(bool opened, ImGuiSetCond cond = 0);          // set next tree node to be opened.
299    IMGUI_API void          OpenNextNode(bool open);                                            // force open/close the next TreeNode or CollapsingHeader
317300
318301    // Selectable / Lists
319302    IMGUI_API bool          Selectable(const char* label, bool selected, const ImVec2& size = ImVec2(0,0));
r245117r245118
343326    // Utilities
344327    IMGUI_API bool          IsItemHovered();                                                    // was the last item hovered by mouse?
345328    IMGUI_API bool          IsItemActive();                                                     // was the last item active? (e.g. button being held, text field being edited- items that don't interact will always return false)
346    IMGUI_API bool          IsAnyItemActive();                                                  //
347329    IMGUI_API ImVec2        GetItemBoxMin();                                                    // get bounding box of last item
348330    IMGUI_API ImVec2        GetItemBoxMax();                                                    // get bounding box of last item
349331    IMGUI_API bool          IsClipped(const ImVec2& item_size);                                 // to perform coarse clipping on user's side (as an optimization)
r245117r245118
375357
376358    // Obsolete (will be removed)
377359    IMGUI_API void          GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size);
378    static inline void      OpenNextNode(bool open) { ImGui::SetNextTreeNodeOpened(open, 0); }
379360
380361} // namespace ImGui
381362
r245117r245118
386367    ImGuiWindowFlags_NoTitleBar             = 1 << 0,   // Disable title-bar
387368    ImGuiWindowFlags_NoResize               = 1 << 1,   // Disable user resizing with the lower-right grip
388369    ImGuiWindowFlags_NoMove                 = 1 << 2,   // Disable user moving the window
389    ImGuiWindowFlags_NoScrollbar            = 1 << 3,   // Disable scrollbar (window can still scroll with mouse or programatically)
370    ImGuiWindowFlags_NoScrollbar            = 1 << 3,   // Disable scroll bar (window can still scroll with mouse or programatically)
390371    ImGuiWindowFlags_NoScrollWithMouse      = 1 << 4,   // Disable user scrolling with mouse wheel
391372    ImGuiWindowFlags_NoCollapse             = 1 << 5,   // Disable user collapsing window by double-clicking on it
392373    ImGuiWindowFlags_AlwaysAutoResize       = 1 << 6,   // Resize every window to its content every frame
r245117r245118
406387    // Default: 0
407388    ImGuiInputTextFlags_CharsDecimal        = 1 << 0,   // Allow 0123456789.+-*/
408389    ImGuiInputTextFlags_CharsHexadecimal    = 1 << 1,   // Allow 0123456789ABCDEFabcdef
409    ImGuiInputTextFlags_CharsUppercase      = 1 << 2,   // Turn a..z into A..Z
410    ImGuiInputTextFlags_CharsNoBlank        = 1 << 3,   // Filter out spaces, tabs
411    ImGuiInputTextFlags_AutoSelectAll       = 1 << 4,   // Select entire text when first taking mouse focus
412    ImGuiInputTextFlags_EnterReturnsTrue    = 1 << 5,   // Return 'true' when Enter is pressed (as opposed to when the value was modified)
413    ImGuiInputTextFlags_CallbackCompletion  = 1 << 6,   // Call user function on pressing TAB (for completion handling)
414    ImGuiInputTextFlags_CallbackHistory     = 1 << 7,   // Call user function on pressing Up/Down arrows (for history handling)
415    ImGuiInputTextFlags_CallbackAlways      = 1 << 8,   // Call user function every time
416    ImGuiInputTextFlags_CallbackCharFilter  = 1 << 9    // Call user function to filter character. Modify data->EventChar to replace/filter input, or return 1 to discard character.
390    ImGuiInputTextFlags_AutoSelectAll       = 1 << 2,   // Select entire text when first taking focus
391    ImGuiInputTextFlags_EnterReturnsTrue    = 1 << 3,   // Return 'true' when Enter is pressed (as opposed to when the value was modified)
392    ImGuiInputTextFlags_CallbackCompletion  = 1 << 4,   // Call user function on pressing TAB (for completion handling)
393    ImGuiInputTextFlags_CallbackHistory     = 1 << 5,   // Call user function on pressing Up/Down arrows (for history handling)
394    ImGuiInputTextFlags_CallbackAlways      = 1 << 6    // Call user function every time
395    //ImGuiInputTextFlags_AlignCenter       = 1 << 6,
417396};
418397
419398// User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array
r245117r245118
509488    ImGuiColorEditMode_HEX = 2
510489};
511490
512// Condition flags for ImGui::SetWindow***(), SetNextWindow***(), SetNextTreeNode***() functions
513// All those functions treat 0 as a shortcut to ImGuiSetCond_Always
514enum ImGuiSetCond_
491// Condition flags for ImGui::SetWindow***() and SetNextWindow***() functions
492// Those functions treat 0 as a shortcut to ImGuiSetCondition_Always
493enum ImGuiSetCondition_
515494{
516    ImGuiSetCond_Always        = 1 << 0, // Set the variable
517    ImGuiSetCond_Once          = 1 << 1, // Only set the variable on the first call per runtime session
518    ImGuiSetCond_FirstUseEver  = 1 << 2  // Only set the variable if the window doesn't exist in the .ini file
495    ImGuiSetCondition_Always              = 1 << 0, // Set the variable
496    ImGuiSetCondition_FirstUseThisSession = 1 << 1, // Only set the variable on the first call for this window (once per session)
497    ImGuiSetCondition_FirstUseEver        = 1 << 2  // Only set the variable if the window doesn't exist in the .ini file
519498};
520499
521500struct ImGuiStyle
r245117r245118
534513    float       WindowFillAlphaDefault;     // Default alpha of window background, if not specified in ImGui::Begin()
535514    float       TreeNodeSpacing;            // Horizontal spacing when entering a tree node
536515    float       ColumnsMinSpacing;          // Minimum horizontal spacing between two columns
537    float       ScrollbarWidth;             // Width of the vertical scrollbar
538    float       GrabMinSize;                // Minimum width/height of a slider or scrollbar grab
516    float       ScrollBarWidth;             // Width of the vertical scroll bar
539517    ImVec4      Colors[ImGuiCol_COUNT];
540518
541519    IMGUI_API ImGuiStyle();
r245117r245118
551529
552530    ImVec2        DisplaySize;              // <unset>              // Display size, in pixels. For clamping windows positions.
553531    float         DeltaTime;                // = 1.0f/60.0f         // Time elapsed since last frame, in seconds.
554    float         IniSavingRate;            // = 5.0f               // Maximum time between saving positions/sizes to .ini file, in seconds.
532    float         IniSavingRate;            // = 5.0f               // Maximum time between saving .ini file, in seconds.
555533    const char*   IniFilename;              // = "imgui.ini"        // Path to .ini file. NULL to disable .ini saving.
556534    const char*   LogFilename;              // = "imgui_log.txt"    // Path to .log file (default parameter to ImGui::LogToFile when no file is specified).
557535    float         MouseDoubleClickTime;     // = 0.30f              // Time for a double-click, in seconds.
r245117r245118
569547    // User Functions
570548    //------------------------------------------------------------------
571549
572    // REQUIRED: rendering function.
550    // REQUIRED: rendering function.
573551    // See example code if you are unsure of how to implement this.
574    void        (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count);     
552    void        (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count);
575553
576    // Optional: access OS clipboard
577    // (default to use native Win32 clipboard on Windows, otherwise uses a private clipboard. Override to access OS clipboard on other architectures)
554    // Optional: access OS clipboard (default to use native Win32 clipboard on Windows, otherwise use a ImGui private clipboard)
555    // Override to access OS clipboard on other architectures.
578556    const char* (*GetClipboardTextFn)();
579557    void        (*SetClipboardTextFn)(const char* text);
580558
581    // Optional: override memory allocations. MemFreeFn() may be called with a NULL pointer.
582    // (default to posix malloc/free)
559    // Optional: override memory allocations (default to posix malloc/free). MemFreeFn() may be called with a NULL pointer.
583560    void*       (*MemAllocFn)(size_t sz);
584561    void        (*MemFreeFn)(void* ptr);
585562
586    // Optional: notify OS Input Method Editor of the screen position of your cursor for text input position (e.g. when using Japanese/Chinese IME in Windows)
587    // (default to use native imm32 api on Windows)
563    // Optional: notify OS Input Method Editor of the screen position of your cursor for text input position (e.g. when using Japanese/Chinese inputs in Windows)
588564    void        (*ImeSetInputScreenPosFn)(int x, int y);
589    void*       ImeWindowHandle;            // (Windows) Set this to your HWND to get automatic IME cursor positioning.
590565
591566    //------------------------------------------------------------------
592567    // Input - Fill before calling NewFrame()
593568    //------------------------------------------------------------------
594569
595570    ImVec2      MousePos;                   // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
596    bool        MouseDown[5];               // Mouse buttons. ImGui itself only uses button 0 (left button). Others buttons allows to track if mouse is being used by your application + available to user as a convenience via IsMouse** API.
597    float       MouseWheel;                 // Mouse wheel: 1 unit scrolls about 5 lines text.
571    bool        MouseDown[5];               // Mouse buttons. ImGui itself only uses button 0 (left button) but you can use others as storage for convenience.
572    float       MouseWheel;                 // Mouse wheel: 1 unit scrolls about 5 lines text.
598573    bool        MouseDrawCursor;            // Request ImGui to draw a mouse cursor for you (if you are on a platform without a mouse cursor).
599574    bool        KeyCtrl;                    // Keyboard modifier pressed: Control
600575    bool        KeyShift;                   // Keyboard modifier pressed: Shift
601    bool        KeysDown[512];              // Keyboard keys that are pressed (in whatever storage order you naturally have access to keyboard data)
576    bool        KeysDown[512];              // Keyboard keys that are pressed (in whatever order user naturally has access to keyboard data)
602577    ImWchar     InputCharacters[16+1];      // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper.
603578
604579    // Function
r245117r245118
610585
611586    bool        WantCaptureMouse;           // Mouse is hovering a window or widget is active (= ImGui will use your mouse input)
612587    bool        WantCaptureKeyboard;        // Widget is active (= ImGui will use your keyboard input)
613    float       Framerate;                  // Framerate estimation, in frame per second. Rolling average estimation based on IO.DeltaTime over 120 frames
614588
615589    //------------------------------------------------------------------
616590    // [Internal] ImGui will maintain those fields for you
617591    //------------------------------------------------------------------
618592
619    ImVec2      MousePosPrev;               // Previous mouse position
593    ImVec2      MousePosPrev;               //
620594    ImVec2      MouseDelta;                 // Mouse delta. Note that this is zero if either current or previous position are negative to allow mouse enabling/disabling.
621595    bool        MouseClicked[5];            // Mouse button went from !Down to Down
622596    ImVec2      MouseClickedPos[5];         // Position at time of clicking
r245117r245118
672646    ImVector<TextRange> Filters;
673647    int                 CountGrep;
674648
675    ImGuiTextFilter(const char* default_filter = "");
649    ImGuiTextFilter();
676650    void Clear() { InputBuf[0] = 0; Build(); }
677651    void Draw(const char* label = "Filter (inc,-exc)", float width = -1.0f);    // Helper calling InputText+Build
678652    bool PassFilter(const char* val) const;
r245117r245118
706680// - You want to store custom debug data easily without adding or editing structures in your code.
707681struct ImGuiStorage
708682{
709    struct Pair
710    {
711        ImGuiID key;
712        union { int val_i; float val_f; void* val_p; };       
713        Pair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; }
714        Pair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; }
715        Pair(ImGuiID _key, void* _val_p) { key = _key; val_p = _val_p; }
683    struct Pair
684    {
685        ImGuiID key;
686        union { int val_i; float val_f; void* val_p; };
687        Pair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; }
688        Pair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; }
689        Pair(ImGuiID _key, void* _val_p) { key = _key; val_p = _val_p; }
716690    };
717691    ImVector<Pair>    Data;
718692
r245117r245118
727701    IMGUI_API void*   GetVoidPtr(ImGuiID key) const; // default_val is NULL
728702    IMGUI_API void    SetVoidPtr(ImGuiID key, void* val);
729703
730    // - Get***Ref() functions finds pair, insert on demand if missing, return pointer. Useful if you intend to do Get+Set.
704    // - Get***Ref() functions finds pair, insert on demand if missing, return pointer. Useful if you intend to do Get+Set.
731705    // - 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.
732706    // - A typical use case where this is convenient:
733707    //      float* pvar = ImGui::GetFloatRef(key); ImGui::SliderFloat("var", pvar, 0, 100.0f); some_var += *pvar;
r245117r245118
742716// Shared state of InputText(), passed to callback when a ImGuiInputTextFlags_Callback* flag is used.
743717struct ImGuiTextEditCallbackData
744718{
745    ImGuiInputTextFlags EventFlag;      // One of ImGuiInputTextFlags_Callback* // Read-only
746    ImGuiInputTextFlags Flags;          // What user passed to InputText()      // Read-only
747    void*               UserData;       // What user passed to InputText()      // Read-only
719    ImGuiKey            EventKey;       // Key pressed (Up/Down/TAB)        // Read-only
720    char*               Buf;            // Current text                     // Read-write (pointed data only)
721    size_t              BufSize;        //                                  // Read-only
722    bool                BufDirty;       // Set if you modify Buf directly   // Write
723    ImGuiInputTextFlags Flags;          // What user passed to InputText()  // Read-only
724    int                 CursorPos;      //                                  // Read-write
725    int                 SelectionStart; //                                  // Read-write (== to SelectionEnd when no selection)
726    int                 SelectionEnd;   //                                  // Read-write
727    void*               UserData;       // What user passed to InputText()
748728
749    // CharFilter event:
750    ImWchar             EventChar;      // Character input                      // Read-write (replace character or set to zero)
751
752    // Completion,History,Always events:
753    ImGuiKey            EventKey;       // Key pressed (Up/Down/TAB)            // Read-only
754    char*               Buf;            // Current text                         // Read-write (pointed data only)
755    size_t              BufSize;        //                                      // Read-only
756    bool                BufDirty;       // Set if you modify Buf directly       // Write
757    int                 CursorPos;      //                                      // Read-write
758    int                 SelectionStart; //                                      // Read-write (== to SelectionEnd when no selection)
759    int                 SelectionEnd;   //                                      // Read-write
760
761729    // NB: calling those function loses selection.
762730    void DeleteChars(int pos, int bytes_count);
763731    void InsertChars(int pos, const char* text, const char* text_end = NULL);
r245117r245118
772740    ImColor(int r, int g, int b, int a = 255)                       { Value.x = (float)r / 255.0f; Value.y = (float)g / 255.0f; Value.z = (float)b / 255.0f; Value.w = (float)a / 255.0f; }
773741    ImColor(float r, float g, float b, float a = 1.0f)              { Value.x = r; Value.y = g; Value.z = b; Value.w = a; }
774742    ImColor(const ImVec4& col)                                      { Value = col; }
743
775744    operator ImU32() const                                          { return ImGui::ColorConvertFloat4ToU32(Value); }
776745    operator ImVec4() const                                         { return Value; }
777746
r245117r245118
794763// It is up to you to decide if your rendering loop or the callback should be responsible for backup/restoring rendering state.
795764typedef void (*ImDrawCallback)(const ImDrawList* parent_list, const ImDrawCmd* cmd);
796765
797// Typically, 1 command = 1 gpu draw call (unless command is a callback)
766// Typically, 1 command = 1 gpu draw call
798767struct ImDrawCmd
799768{
800769    unsigned int    vtx_count;                  // Number of vertices (multiple of 3) to be drawn as triangles. The vertices are stored in the callee ImDrawList's vtx_buffer[] array.
r245117r245118
833802
834803    // [Internal to ImGui]
835804    ImVector<ImVec4>        clip_rect_stack;    // [Internal]
836    ImVector<ImTextureID>   texture_id_stack;   // [Internal]
805    ImVector<ImTextureID>   texture_id_stack;   // [Internal]
837806    ImDrawVert*             vtx_write;          // [Internal] point within vtx_buffer after each add command (to avoid using the ImVector<> operators too much)
838807
839808    ImDrawList() { Clear(); }
r245117r245118
843812    IMGUI_API void  PushTextureID(const ImTextureID& texture_id);
844813    IMGUI_API void  PopTextureID();
845814
846    // Primitives   
815    // Primitives
847816    IMGUI_API void  AddLine(const ImVec2& a, const ImVec2& b, ImU32 col);
848817    IMGUI_API void  AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F);
849818    IMGUI_API void  AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F);
r245117r245118
928897    float               FontSize;           // <user set>      // Height of characters, set during loading (don't change after loading)
929898    float               Scale;              // = 1.0f          // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
930899    ImVec2              DisplayOffset;      // = (0.0f,0.0f)   // Offset font rendering by xx pixels
931    ImWchar             FallbackChar;       // = '?'           // Replacement glyph if one isn't found. Only set via SetFallbackChar()
900    ImWchar             FallbackChar;       // = '?'           // Replacement glyph if one isn't found.
932901
933902    // Members: Runtime data
934903    struct Glyph
r245117r245118
941910    };
942911    ImFontAtlas*        ContainerAtlas;     // What we has been loaded into
943912    ImVector<Glyph>     Glyphs;
944    const Glyph*        FallbackGlyph;      // == FindGlyph(FontFallbackChar)
945    float               FallbackXAdvance;   //
946    ImVector<float>     IndexXAdvance;      // Glyphs->XAdvance directly indexable (for CalcTextSize functions which are often bottleneck in large UI)
947913    ImVector<int>       IndexLookup;        // Index glyphs by Unicode code-point
914    const Glyph*        FallbackGlyph;      // == FindGlyph(FontFallbackChar)
948915
949916    // Methods
950917    IMGUI_API ImFont();
r245117r245118
952919    IMGUI_API void                  Clear();
953920    IMGUI_API void                  BuildLookupTable();
954921    IMGUI_API const Glyph*          FindGlyph(unsigned short c) const;
955    IMGUI_API void                  SetFallbackChar(ImWchar c);
956922    IMGUI_API bool                  IsLoaded() const        { return ContainerAtlas != NULL; }
957923
958924    // 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
trunk/3rdparty/bgfx/README.md
r245117r245118
44What is it?
55-----------
66
7Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style
8rendering library.
7Cross-platform rendering library.
98
109Supported rendering backends:
1110
r245117r245118
7069how it currently looks. 
7170![mac_screenshot](https://raw.githubusercontent.com/emoon/ProDBG/master/data/screens/mac_screenshot.png)
7271
72
7373http://www.dogbytegames.com/ Dogbyte Games is an indie mobile developer studio
74focusing on racing games. 
75![ios](http://www.dogbytegames.com/bgfx/offroadlegends2_bgfx_ipad2.jpg)
74focusing on racing games.
7675
77https://github.com/andr3wmac/Torque6 Torque 6 is an MIT licensed 3D engine
78loosely based on Torque2D. Being neither Torque2D or Torque3D it is the 6th
79derivative of the original Torque Engine.
80
81https://github.com/cgbystrom/twinkle GPU-accelerated UI framework powered by
82JavaScript for desktop/mobile apps. Idea is to combine the fast workflow and
83deployment model of web with the performance of native code and GPU acceleration.
84
8576Examples
8677--------
8778
r245117r245118
320311Steps bellow are for default build system inside bgfx repository. There is
321312alterative way to build bgfx and examples with [fips](https://github.com/floooh/fips-bgfx/#fips-bgfx).
322313
314### Prerequisites
315
316Windows users download GnuWin32 utilities from: 
317[http://gnuwin32.sourceforge.net/packages/make.htm](http://gnuwin32.sourceforge.net/packages/make.htm) 
318[http://gnuwin32.sourceforge.net/packages/coreutils.htm](http://gnuwin32.sourceforge.net/packages/coreutils.htm) 
319[http://gnuwin32.sourceforge.net/packages/libiconv.htm](http://gnuwin32.sourceforge.net/packages/libiconv.htm) 
320[http://gnuwin32.sourceforge.net/packages/libintl.htm](http://gnuwin32.sourceforge.net/packages/libintl.htm)
321
323322### Getting source
324323
325324   git clone git://github.com/bkaradzic/bx.git
326325   git clone git://github.com/bkaradzic/bgfx.git
327
328### Quick start (Windows with Visual Studio)
329
330Enter bgfx directory:
331
332326   cd bgfx
333
334Generate Visual Studio 2013 project files:
335
336   ..\bx\tools\bin\windows\genie vs2013
337
338Open bgfx solution in Visual Studio 2013:
339
340   start .build\projects\vs2013\bgfx.sln
341
342### Generating project files for all targets
343
344   cd bgfx
345327   make
346328
347329After calling `make`, .build/projects/* directory will be generated. All
r245117r245118
371353
372354### Prerequisites for Windows
373355
374Windows users download GnuWin32 utilities from: 
375[http://gnuwin32.sourceforge.net/packages/make.htm](http://gnuwin32.sourceforge.net/packages/make.htm) 
376[http://gnuwin32.sourceforge.net/packages/coreutils.htm](http://gnuwin32.sourceforge.net/packages/coreutils.htm) 
377[http://gnuwin32.sourceforge.net/packages/libiconv.htm](http://gnuwin32.sourceforge.net/packages/libiconv.htm) 
378[http://gnuwin32.sourceforge.net/packages/libintl.htm](http://gnuwin32.sourceforge.net/packages/libintl.htm)
379
380356When building on Windows, you have to set DXSDK_DIR environment variable to
381357point to DirectX SDK directory.
382358
r245117r245118
617593 - Animated mesh example.
618594 - Direct3D 12 renderer backend.
619595 - Metal renderer backend.
620 - Vulkan renderer backend.
621596
622597Contact
623598-------
trunk/3rdparty/bgfx/examples/08-update/fs_update_3d.sc
r245117r245118
1$input v_texcoord0
2
3/*
4 * Copyright 2011-2015 Branimir Karadzic. All rights reserved.
5 * License: http://www.opensource.org/licenses/BSD-2-Clause
6 */
7
8#include "../common/common.sh"
9
10SAMPLER3D(u_texColor, 0);
11uniform float u_time;
12
13void main()
14{
15   vec3 uvw = vec3(v_texcoord0.xy*0.5+0.5,   sin(u_time)*0.5+0.5);
16   gl_FragColor = vec4_splat(texture3D(u_texColor, uvw).x);
17}
trunk/3rdparty/bgfx/examples/08-update/update.cpp
r245117r245118
149149      loadTexture("texture_compression_ptc24.pvr"),
150150   };
151151
152   const bgfx::Memory* mem8   = bgfx::alloc(32*32*32);
153   const bgfx::Memory* mem16f = bgfx::alloc(32*32*32*2);
154   const bgfx::Memory* mem32f = bgfx::alloc(32*32*32*4);
155   for (uint8_t zz = 0; zz < 32; ++zz)
156   {
157      for (uint8_t yy = 0; yy < 32; ++yy)
158      {
159         for (uint8_t xx = 0; xx < 32; ++xx)
160         {
161            const uint32_t offset = ( (zz*32+yy)*32+xx);
162            const uint32_t val = xx ^ yy ^ zz;
163            mem8->data[offset] = val<<3;
164            *(uint16_t*)&mem16f->data[offset*2] = bx::halfFromFloat( (float)val/32.0f);
165            *(float*)&mem32f->data[offset*4] = (float)val/32.0f;
166         }
167      }
168   }
169
170   bgfx::TextureHandle textures3d[] =
171   {
172      bgfx::createTexture3D(32, 32, 32, 0, bgfx::TextureFormat::R8,   BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP, mem8),
173      bgfx::createTexture3D(32, 32, 32, 0, bgfx::TextureFormat::R16F, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP, mem16f),
174      bgfx::createTexture3D(32, 32, 32, 0, bgfx::TextureFormat::R32F, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP, mem32f),
175   };
176
177152   // Create static vertex buffer.
178153   bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer(bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) ), PosTexcoordVertex::ms_decl);
179154
r245117r245118
181156   bgfx::IndexBufferHandle ibh = bgfx::createIndexBuffer(bgfx::makeRef(s_cubeIndices, sizeof(s_cubeIndices) ) );
182157
183158   // Create texture sampler uniforms.
184   bgfx::UniformHandle u_texCube  = bgfx::createUniform("u_texCube",  bgfx::UniformType::Uniform1iv);
159   bgfx::UniformHandle u_texCube = bgfx::createUniform("u_texCube", bgfx::UniformType::Uniform1iv);
160
185161   bgfx::UniformHandle u_texColor = bgfx::createUniform("u_texColor", bgfx::UniformType::Uniform1iv);
186162
187   bgfx::UniformHandle u_time = bgfx::createUniform("u_time", bgfx::UniformType::Uniform1f);
163   bgfx::ProgramHandle program    = loadProgram("vs_update", "fs_update");
164   bgfx::ProgramHandle programCmp = loadProgram("vs_update", "fs_update_cmp");
188165
189   bgfx::ProgramHandle program     = loadProgram("vs_update", "fs_update");
190   bgfx::ProgramHandle programCmp  = loadProgram("vs_update", "fs_update_cmp");
191   bgfx::ProgramHandle program3d   = loadProgram("vs_update", "fs_update_3d");
192
193166   const uint32_t textureSide = 2048;
194167
195168   bgfx::TextureHandle textureCube = bgfx::createTextureCube(textureSide, 1
r245117r245118
237210      const int64_t freq = bx::getHPFrequency();
238211      const double toMs = 1000.0/double(freq);
239212      float time = (float)( (now - timeOffset)/double(bx::getHPFrequency() ) );
240      bgfx::setUniform(u_time, &time);
241213
242214      // Use debug font to print information about this example.
243215      bgfx::dbgTextClear();
r245117r245118
373345      // Submit primitive for rendering to view 1.
374346      bgfx::submit(1);
375347
376      const float xpos = -8.0f - BX_COUNTOF(textures)*0.1f*0.5f;
377348
378349      for (uint32_t ii = 0; ii < BX_COUNTOF(textures); ++ii)
379350      {
380         bx::mtxTranslate(mtx, xpos + ii*2.1f, 4.0f, 0.0f);
351         bx::mtxTranslate(mtx, -8.0f - BX_COUNTOF(textures)*0.1f*0.5f + ii*2.1f, 4.0f, 0.0f);
381352
382353         // Set model matrix for rendering.
383354         bgfx::setTransform(mtx);
r245117r245118
399370         bgfx::submit(1);
400371      }
401372
402      for (uint32_t ii = 0; ii < BX_COUNTOF(textures3d); ++ii)
403      {
404         bx::mtxTranslate(mtx, xpos + ii*2.1f, -4.0f, 0.0f);
405
406         // Set model matrix for rendering.
407         bgfx::setTransform(mtx);
408
409         // Set vertex and fragment shaders.
410         bgfx::setProgram(program3d);
411
412         // Set vertex and index buffer.
413         bgfx::setVertexBuffer(vbh);
414         bgfx::setIndexBuffer(ibh, 0, 6);
415
416         // Bind texture.
417         bgfx::setTexture(0, u_texColor, textures3d[ii]);
418
419         // Set render states.
420         bgfx::setState(BGFX_STATE_DEFAULT);
421
422         // Submit primitive for rendering to view 1.
423         bgfx::submit(1);
424      }
425
426373      for (uint32_t ii = 0; ii < 3; ++ii)
427374      {
428         bx::mtxTranslate(mtx, xpos + 8*2.1f, -4.0f + ii*2.1f, 0.0f);
375         bx::mtxTranslate(mtx, -8.0f - BX_COUNTOF(textures)*0.1f*0.5f + 8*2.1f, -4.0f + ii*2.1f, 0.0f);
429376
430377         // Set model matrix for rendering.
431378         bgfx::setTransform(mtx);
r245117r245118
465412      bgfx::destroyTexture(textures[ii]);
466413   }
467414
468   for (uint32_t ii = 0; ii < BX_COUNTOF(textures3d); ++ii)
469   {
470      bgfx::destroyTexture(textures3d[ii]);
471   }
472
473415   bgfx::destroyTexture(texture2d);
474416   bgfx::destroyTexture(textureCube);
475417   bgfx::destroyIndexBuffer(ibh);
476418   bgfx::destroyVertexBuffer(vbh);
477   bgfx::destroyProgram(program3d);
478419   bgfx::destroyProgram(programCmp);
479420   bgfx::destroyProgram(program);
480   bgfx::destroyUniform(u_time);
481421   bgfx::destroyUniform(u_texColor);
482422   bgfx::destroyUniform(u_texCube);
483423
trunk/3rdparty/bgfx/examples/23-vectordisplay/vectordisplay.cpp
r245117r245118
123123
124124void VectorDisplay::teardown()
125125{
126   for (size_t i = 0; i < m_vertexBuffers.size(); ++i)
127   {
128      bgfx::destroyDynamicVertexBuffer(m_vertexBuffers[i]);
129   }
130
131126   teardownResDependent();
132127
133128   bgfx::destroyProgram(m_drawToScreenShader);
r245117r245118
152147void VectorDisplay::endFrame()
153148{
154149   float proj[16];
150   float ident[16];
151   bx::mtxIdentity(ident);
152
155153   bx::mtxOrtho(proj, 0.0f, (float)m_screenWidth, (float)m_screenHeight, 0.0f, 0.0f, 1000.0f);
156154
157155   bgfx::setViewRect(m_view, 0, 0, m_screenWidth, m_screenHeight);
r245117r245118
168166   );
169167   m_vertexBuffersSize[m_currentDrawStep] = (uint32_t)m_points.size();
170168
169   //if the index buffer is cleared from the last "submit"-call everything is fine, but if not
170   //we clear it here again just to be sure it's not set... (the same for the Transform)
171   bgfx::IndexBufferHandle ib;
172   ib.idx = bgfx::invalidHandle;
173   bgfx::setIndexBuffer(ib);
174
175   bgfx::setTransform(ident);
176
171177   for (int loopvar = 0; loopvar < m_numberDecaySteps; loopvar++)
172178   {
173179      int stepi = m_numberDecaySteps - loopvar - 1;
r245117r245118
722728   {
723729      for (size_t i = 0; i < m_vertexBuffers.size(); ++i)
724730      {
725         bgfx::destroyDynamicVertexBuffer(m_vertexBuffers[i]);
731         destroyDynamicVertexBuffer(m_vertexBuffers[i]);
726732      }
727733
728734      m_vertexBuffers.clear();
trunk/3rdparty/bgfx/examples/common/entry/entry.cpp
r245117r245118
3434   }
3535#endif // ENTRY_CONFIG_IMPLEMENT_DEFAULT_ALLOCATOR
3636
37   char keyToAscii(Key::Enum _key, uint8_t _modifiers)
38   {
39      const bool isAscii = (Key::Key0 <= _key && _key <= Key::KeyZ)
40                    || (Key::Esc  <= _key && _key <= Key::Minus);
41      if (!isAscii)
42      {
43         return '\0';
44      }
45
46      const bool isNumber = (Key::Key0 <= _key && _key <= Key::Key9);
47      if (isNumber)
48      {
49         return '0' + (_key - Key::Key0);
50      }
51
52      const bool isChar = (Key::KeyA <= _key && _key <= Key::KeyZ);
53      if (isChar)
54      {
55         enum { ShiftMask = Modifier::LeftShift|Modifier::RightShift };
56
57         const bool shift = !!(_modifiers&ShiftMask);
58         return (shift ? 'A' : 'a') + (_key - Key::KeyA);
59      }
60
61      switch (_key)
62      {
63      case Key::Esc:       return 0x1b;
64      case Key::Return:    return '\n';
65      case Key::Tab:       return '\t';
66      case Key::Space:     return ' ';
67      case Key::Backspace: return 0x08;
68      case Key::Plus:      return '+';
69      case Key::Minus:     return '-';
70      default:             break;
71      }
72
73      return '\0';
74   }
75
7637   bool setOrToggle(uint32_t& _flags, const char* _name, uint32_t _bit, int _first, int _argc, char const* const* _argv)
7738   {
7839      if (0 == strcmp(_argv[_first], _name) )
trunk/3rdparty/bgfx/examples/common/entry/entry.h
r245117r245118
211211   void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height);
212212   void setWindowTitle(WindowHandle _handle, const char* _title);
213213   void toggleWindowFrame(WindowHandle _handle);
214   void toggleFullscreen(WindowHandle _handle);
215214   void setMouseLock(WindowHandle _handle, bool _lock);
216215
217216   struct WindowState
trunk/3rdparty/bgfx/examples/common/entry/entry_android.cpp
r245117r245118
440440      BX_UNUSED(_handle);
441441   }
442442
443   void toggleFullscreen(WindowHandle _handle)
444   {
445      BX_UNUSED(_handle);
446   }
447
448443   void setMouseLock(WindowHandle _handle, bool _lock)
449444   {
450445      BX_UNUSED(_handle, _lock);
trunk/3rdparty/bgfx/examples/common/entry/entry_asmjs.cpp
r245117r245118
5959      BX_UNUSED(_handle);
6060   }
6161
62   void toggleFullscreen(WindowHandle _handle)
63   {
64      BX_UNUSED(_handle);
65   }
66
6762   void setMouseLock(WindowHandle _handle, bool _lock)
6863   {
6964      BX_UNUSED(_handle, _lock);
trunk/3rdparty/bgfx/examples/common/entry/entry_ios.mm
r245117r245118
126126      BX_UNUSED(_handle);
127127   }
128128
129   void toggleFullscreen(WindowHandle _handle)
130   {
131      BX_UNUSED(_handle);
132   }
133
134129   void setMouseLock(WindowHandle _handle, bool _lock)
135130   {
136131      BX_UNUSED(_handle, _lock);
trunk/3rdparty/bgfx/examples/common/entry/entry_nacl.cpp
r245117r245118
9494      BX_UNUSED(_handle);
9595   }
9696
97   void toggleFullscreen(WindowHandle _handle)
98   {
99      BX_UNUSED(_handle);
100   }
101
10297   void setMouseLock(WindowHandle _handle, bool _lock)
10398   {
10499      BX_UNUSED(_handle, _lock);
trunk/3rdparty/bgfx/examples/common/entry/entry_osx.mm
r245117r245118
1616#include <bx/os.h>
1717#include <bx/handlealloc.h>
1818
19#define DEFAULT_WIDTH 1280
20#define DEFAULT_HEIGHT 720
21
1922@interface AppDelegate : NSObject<NSApplicationDelegate>
2023{
2124   bool terminated;
r245117r245118
7780   struct Context
7881   {
7982      Context()
80         : m_scrollf(0.0f)
81         , m_mx(0)
82         , m_my(0)
83         , m_scroll(0)
84         , m_style(0)
85         , m_exit(false)
86         , m_fullscreen(false)
83         : m_exit(false)
8784      {
8885         s_translateKey[27]             = Key::Esc;
8986         s_translateKey[13]             = Key::Return;
r245117r245118
109106
110107         for (char ch = 'a'; ch <= 'z'; ++ch)
111108         {
112            s_translateKey[uint8_t(ch)]       =
109            s_translateKey[uint8_t(ch)]             =
113110            s_translateKey[uint8_t(ch - ' ')] = Key::KeyA + (ch - 'a');
114111         }
115112      }
r245117r245118
140137         NSWindow* window = m_window[handle.idx];
141138         NSRect originalFrame = [window frame];
142139         NSPoint location = [window mouseLocationOutsideOfEventStream];
143         NSRect adjustFrame = [window contentRectForFrameRect: originalFrame];
140         NSRect adjustFrame = [NSWindow contentRectForFrameRect: originalFrame styleMask: NSTitledWindowMask];
144141
145142         int x = location.x;
146143         int y = (int)adjustFrame.size.height - (int)location.y;
r245117r245118
175172         return mask;
176173      }
177174
178      Key::Enum handleKeyEvent(NSEvent* event, uint8_t* specialKeys, uint8_t* _pressedChar)
175      Key::Enum handleKeyEvent(NSEvent* event, uint8_t* specialKeys)
179176      {
180177         NSString* key = [event charactersIgnoringModifiers];
181178         unichar keyChar = 0;
179//DBG("keyChar %d", keyChar);
182180         if ([key length] == 0)
183181         {
184182            return Key::None;
185183         }
186184
187185         keyChar = [key characterAtIndex:0];
188         *_pressedChar = (uint8_t)keyChar;
189186
190187         int keyCode = keyChar;
188//DBG("keyCode %d", keyCode);
191189         *specialKeys = translateModifiers([event modifierFlags]);
192190
193191         // if this is a unhandled key just return None
r245117r245118
238236               case NSMouseMoved:
239237               case NSLeftMouseDragged:
240238               case NSRightMouseDragged:
241               case NSOtherMouseDragged:
242239               {
243                  getMousePos(&m_mx, &m_my);
244                  m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll);
240                  int x, y;
241                  getMousePos(&x, &y);
242                  m_eventQueue.postMouseEvent(s_defaultWindow, x, y, 0);
245243                  break;
246244               }
247245
248246               case NSLeftMouseDown:
249247               {
250                  // TODO: remove!
251                  // Command + Left Mouse Button acts as middle! This just a temporary solution!
252                  // This is becase the average OSX user doesn't have middle mouse click.
253                  MouseButton::Enum mb = ([event modifierFlags] & NSCommandKeyMask) ? MouseButton::Middle : MouseButton::Left;
254                  m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, mb, true);
248                  int x, y;
249                  getMousePos(&x, &y);
250                  m_eventQueue.postMouseEvent(s_defaultWindow, x, y, 0, MouseButton::Left, true);
255251                  break;
256252               }
257253
258254               case NSLeftMouseUp:
259255               {
260                  m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Left, false);
261                  m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Middle, false); // TODO: remove!
256                  int x, y;
257                  getMousePos(&x, &y);
258                  m_eventQueue.postMouseEvent(s_defaultWindow, x, y, 0, MouseButton::Left, false);
262259                  break;
263260               }
264261
265262               case NSRightMouseDown:
266263               {
267                  m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Right, true);
264                  int x, y;
265                  getMousePos(&x, &y);
266                  m_eventQueue.postMouseEvent(s_defaultWindow, x, y, 0, MouseButton::Right, true);
268267                  break;
269268               }
270269
271270               case NSRightMouseUp:
272271               {
273                  m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Right, false);
272                  int x, y;
273                  getMousePos(&x, &y);
274                  m_eventQueue.postMouseEvent(s_defaultWindow, x, y, 0, MouseButton::Right, false);
274275                  break;
275276               }
276277
277               case NSOtherMouseDown:
278               {
279                  m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Middle, true);
280                  break;
281               }
282
283               case NSOtherMouseUp:
284               {
285                  m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Middle, false);
286                  break;
287               }
288
289               case NSScrollWheel:
290               {
291                  m_scrollf += [event deltaY];
292
293                  m_scroll = (int32_t)m_scrollf;
294                  m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll);
295                  break;
296               }
297
298278               case NSKeyDown:
299279               {
300280                  uint8_t modifiers = 0;
301                  uint8_t pressedChar[4];
302                  Key::Enum key = handleKeyEvent(event, &modifiers, &pressedChar[0]);
281                  Key::Enum key = handleKeyEvent(event, &modifiers);
303282
304                  // Returning false means that we take care of the key (instead of the default behavior)
283                  // If KeyCode is none we don't don't handle the key and special case for cmd+q (quit)
284                  // Note that return false here means that we take care of the key (instead of the default behavior)
305285                  if (key != Key::None)
306286                  {
307                     if (key == Key::KeyQ && (modifiers & Modifier::RightMeta) )
287                     if (key != Key::KeyQ
288                     && !(modifiers & Modifier::RightMeta) )
308289                     {
309                        m_eventQueue.postExitEvent();
290                        m_eventQueue.postKeyEvent(s_defaultWindow, key, modifiers, true);
291                        return false;
310292                     }
311                     else
312                     {
313                        enum { ShiftMask = Modifier::LeftShift|Modifier::RightShift };
314                        const bool nonShiftModifiers = (0 != (modifiers&(~ShiftMask) ) );
315                        const bool isCharPressed = (Key::Key0 <= key && key <= Key::KeyZ) || (Key::Esc <= key && key <= Key::Minus);
316                        const bool isText = isCharPressed && !nonShiftModifiers;
317                        if (isText)
318                        {
319                           m_eventQueue.postCharEvent(s_defaultWindow, 1, pressedChar);
320                           return false;
321                        }
322                        else
323                        {
324                           m_eventQueue.postKeyEvent(s_defaultWindow, key, modifiers, true);
325                           return false;
326                        }
327                     }
328293                  }
329294
330295                  break;
r245117r245118
333298               case NSKeyUp:
334299               {
335300                  uint8_t modifiers  = 0;
336                  uint8_t pressedChar[4];
337                  Key::Enum key = handleKeyEvent(event, &modifiers, &pressedChar[0]);
301                  Key::Enum key = handleKeyEvent(event, &modifiers);
338302
339                  BX_UNUSED(pressedChar);
340
341303                  if (key != Key::None)
342304                  {
343305                     m_eventQueue.postKeyEvent(s_defaultWindow, key, modifiers, false);
r245117r245118
361323      {
362324         WindowHandle handle = { 0 };
363325         NSWindow* window = m_window[handle.idx];
364         NSRect originalFrame = [window frame];
365         NSRect rect = [window contentRectForFrameRect: originalFrame];
326         NSRect rect = [window frame];
366327         uint32_t width  = uint32_t(rect.size.width);
367328         uint32_t height = uint32_t(rect.size.height);
368329         m_eventQueue.postSizeEvent(handle, width, height);
369
370         // Make sure mouse button state is 'up' after resize.
371         m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Left,  false);
372         m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Right, false);
373330      }
374331
375332      int32_t run(int _argc, char** _argv)
r245117r245118
406363         [menubar addItem:appMenuItem];
407364         [NSApp setMainMenu:menubar];
408365
409         m_style = 0
410               | NSTitledWindowMask
411               | NSClosableWindowMask
412               | NSMiniaturizableWindowMask
413               | NSResizableWindowMask
414               ;
415
416         NSRect screenRect = [[NSScreen mainScreen] frame];
417         const float centerX = (screenRect.size.width  - (float)ENTRY_DEFAULT_WIDTH )*0.5f;
418         const float centerY = (screenRect.size.height - (float)ENTRY_DEFAULT_HEIGHT)*0.5f;
419
420366         m_windowAlloc.alloc();
421         NSRect rect = NSMakeRect(centerX, centerY, (float)ENTRY_DEFAULT_WIDTH, (float)ENTRY_DEFAULT_HEIGHT);
367         NSRect rect = NSMakeRect(0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT);
422368         NSWindow* window = [[NSWindow alloc]
423369            initWithContentRect:rect
424            styleMask:m_style
370            styleMask:0
371            |NSTitledWindowMask
372            |NSClosableWindowMask
373            |NSMiniaturizableWindowMask
374            |NSResizableWindowMask
425375            backing:NSBackingStoreBuffered defer:NO
426376         ];
427377         NSString* appName = [[NSProcessInfo processInfo] processName];
428378         [window setTitle:appName];
379         [window cascadeTopLeftFromPoint:NSMakePoint(20,20)];
429380         [window makeKeyAndOrderFront:window];
430381         [window setAcceptsMouseMovedEvents:YES];
431382         [window setBackgroundColor:[NSColor blackColor]];
432383         [[Window sharedDelegate] windowCreated:window];
433384
434385         m_window[0] = window;
435         m_windowFrame = [window frame];
436386
437387         bgfx::osxSetNSWindow(window);
438388
r245117r245118
455405            }
456406         }
457407
408
458409         m_eventQueue.postExitEvent();
459410
460411         while (bgfx::RenderFrame::NoContext != bgfx::renderFrame() ) {};
r245117r245118
463414         return 0;
464415      }
465416
466      bool isValid(WindowHandle _handle)
467      {
468         return m_windowAlloc.isValid(_handle.idx);
469      }
470
471417      EventQueue m_eventQueue;
472418
473419      bx::HandleAllocT<ENTRY_CONFIG_MAX_WINDOWS> m_windowAlloc;
474420      NSWindow* m_window[ENTRY_CONFIG_MAX_WINDOWS];
475      NSRect m_windowFrame;
476421
477      float   m_scrollf;
478      int32_t m_mx;
479      int32_t m_my;
480      int32_t m_scroll;
481      int32_t m_style;
482      bool    m_exit;
483      bool    m_fullscreen;
422      bool m_exit;
484423   };
485424
486425   static Context s_ctx;
r245117r245118
509448
510449   void destroyWindow(WindowHandle _handle)
511450   {
512      if (s_ctx.isValid(_handle) )
513      {
514         dispatch_async(dispatch_get_main_queue()
515         , ^{
516            [s_ctx.m_window[_handle.idx] performClose: nil];
517         });
518      }
451      BX_UNUSED(_handle);
519452   }
520453
521454   void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y)
522455   {
523      if (s_ctx.isValid(_handle) )
524      {
525         NSWindow* window = s_ctx.m_window[_handle.idx];
526         NSScreen* screen = [window screen];
527
528         NSRect screenRect = [screen frame];
529         CGFloat menuBarHeight = [[[NSApplication sharedApplication] mainMenu] menuBarHeight];
530
531         NSPoint position = { float(_x), screenRect.size.height - menuBarHeight - float(_y) };
532
533         dispatch_async(dispatch_get_main_queue()
534         , ^{
535            [window setFrameTopLeftPoint: position];
536         });
537      }
456      BX_UNUSED(_handle, _x, _y);
538457   }
539458
540459   void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height)
541460   {
542      if (s_ctx.isValid(_handle) )
543      {
544         NSSize size = { float(_width), float(_height) };
545         dispatch_async(dispatch_get_main_queue()
546         , ^{
547            [s_ctx.m_window[_handle.idx] setContentSize: size];
548         });
549      }
461      BX_UNUSED(_handle, _width, _height);
550462   }
551463
552464   void setWindowTitle(WindowHandle _handle, const char* _title)
553465   {
554      if (s_ctx.isValid(_handle) )
555      {
556         NSString* title = [[NSString alloc] initWithCString:_title encoding:1];
557         dispatch_async(dispatch_get_main_queue()
558         , ^{
559            [s_ctx.m_window[_handle.idx] setTitle: title];
560         });
561         [title release];
562      }
466      BX_UNUSED(_handle, _title);
563467   }
564468
565469   void toggleWindowFrame(WindowHandle _handle)
566470   {
567      if (s_ctx.isValid(_handle) )
568      {
569         s_ctx.m_style ^= NSTitledWindowMask;
570         dispatch_async(dispatch_get_main_queue()
571         , ^{
572            [s_ctx.m_window[_handle.idx] setStyleMask: s_ctx.m_style];
573         });
574      }
471      BX_UNUSED(_handle);
575472   }
576473
577   void toggleFullscreen(WindowHandle _handle)
578   {
579      if (s_ctx.isValid(_handle) )
580      {
581         NSWindow* window = s_ctx.m_window[_handle.idx];
582         NSScreen* screen = [window screen];
583         NSRect screenRect = [screen frame];
584
585         if (!s_ctx.m_fullscreen)
586         {
587            s_ctx.m_style &= ~NSTitledWindowMask;
588            dispatch_async(dispatch_get_main_queue()
589            , ^{
590               [NSMenu setMenuBarVisible: false];
591               [window setStyleMask: s_ctx.m_style];
592               [window setFrame:screenRect display:YES];
593            });
594
595            s_ctx.m_fullscreen = true;
596         }
597         else
598         {
599            s_ctx.m_style |= NSTitledWindowMask;
600            dispatch_async(dispatch_get_main_queue()
601            , ^{
602               [NSMenu setMenuBarVisible: true];
603               [window setStyleMask: s_ctx.m_style];
604               [window setFrame:s_ctx.m_windowFrame display:YES];
605            });
606
607            s_ctx.m_fullscreen = false;
608         }
609      }
610   }
611
612474   void setMouseLock(WindowHandle _handle, bool _lock)
613475   {
614476      BX_UNUSED(_handle, _lock);
r245117r245118
710572   using namespace entry;
711573   s_ctx.windowDidResize();
712574}
713
714575@end
715576
716577int main(int _argc, char** _argv)
trunk/3rdparty/bgfx/examples/common/entry/entry_p.h
r245117r245118
5656
5757   int main(int _argc, char** _argv);
5858
59   char keyToAscii(Key::Enum _key, uint8_t _modifiers);
60
6159   struct Event
6260   {
6361      enum Enum
trunk/3rdparty/bgfx/examples/common/entry/entry_qnx.cpp
r245117r245118
5959      BX_UNUSED(_handle);
6060   }
6161
62   void toggleFullscreen(WindowHandle _handle)
63   {
64      BX_UNUSED(_handle);
65   }
66
6762   void setMouseLock(WindowHandle _handle, bool _lock)
6863   {
6964      BX_UNUSED(_handle, _lock);
trunk/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
r245117r245118
179179      SDL_USER_WINDOW_SET_POS,
180180      SDL_USER_WINDOW_SET_SIZE,
181181      SDL_USER_WINDOW_TOGGLE_FRAME,
182      SDL_USER_WINDOW_TOGGLE_FULL_SCREEN,
183182      SDL_USER_WINDOW_MOUSE_LOCK,
184183   };
185184
r245117r245118
192191      union { void* p; WindowHandle h; } cast;
193192      cast.h = _handle;
194193      uev.data1 = cast.p;
195
194     
196195      uev.data2 = _msg;
197196      uev.code = _code;
198197      SDL_PushEvent(&event);
r245117r245118
211210         : m_width(ENTRY_DEFAULT_WIDTH)
212211         , m_height(ENTRY_DEFAULT_HEIGHT)
213212         , m_aspectRatio(16.0f/9.0f)
214         , m_mx(0)
215         , m_my(0)
216         , m_mz(0)
217213         , m_mouseLock(false)
218         , m_fullscreen(false)
219214      {
220215         memset(s_translateKey, 0, sizeof(s_translateKey) );
221216         initTranslateKey(SDL_SCANCODE_ESCAPE,       Key::Esc);
r245117r245118
379374               case SDL_MOUSEMOTION:
380375                  {
381376                     const SDL_MouseMotionEvent& mev = event.motion;
382                     m_mx = mev.x;
383                     m_my = mev.y;
384
385377                     WindowHandle handle = findHandle(mev.windowID);
386378                     if (isValid(handle) )
387379                     {
388                        m_eventQueue.postMouseEvent(handle, m_mx, m_my, m_mz);
380                        m_eventQueue.postMouseEvent(handle, mev.x, mev.y, 0);
389381                     }
390382                  }
391383                  break;
r245117r245118
417409                  }
418410                  break;
419411
420               case SDL_MOUSEWHEEL:
421                  {
422                     const SDL_MouseWheelEvent& mev = event.wheel;
423                     m_mz += mev.y;
424
425                     WindowHandle handle = findHandle(mev.windowID);
426                     if (isValid(handle) )
427                     {
428                        m_eventQueue.postMouseEvent(handle, m_mx, m_my, m_mz);
429                     }
430                  }
431                  break;
432
433               case SDL_TEXTINPUT:
434                  {
435                     const SDL_TextInputEvent& tev = event.text;
436                     WindowHandle handle = findHandle(tev.windowID);
437                     if (isValid(handle) )
438                     {
439                        m_eventQueue.postCharEvent(handle, 1, (const uint8_t*)tev.text);
440                     }
441                  }
442                  break;
443
444412               case SDL_KEYDOWN:
445                  {
446                     const SDL_KeyboardEvent& kev = event.key;
447                     WindowHandle handle = findHandle(kev.windowID);
448                     if (isValid(handle) )
449                     {
450                        uint8_t modifiers = translateKeyModifiers(kev.keysym.mod);
451                        Key::Enum key = translateKey(kev.keysym.scancode);
452
453                        const uint8_t shiftMask = Modifier::LeftShift|Modifier::RightShift;
454                        const bool nonShiftModifiers = (0 != (modifiers&(~shiftMask) ) );
455                        const bool isCharPressed = (Key::Key0 <= key && key <= Key::KeyZ) || (Key::Esc <= key && key <= Key::Minus);
456                        const bool isText = isCharPressed && !nonShiftModifiers;
457
458                        if (isText)
459                        {
460                           uint8_t pressedChar[4];
461                           pressedChar[0] = keyToAscii(key, modifiers);
462                           m_eventQueue.postCharEvent(handle, 1, pressedChar);
463                        }
464                        else
465                        {
466                           m_eventQueue.postKeyEvent(handle, key, modifiers, kev.state == SDL_PRESSED);
467                        }
468                     }
469                  }
470                  break;
471413               case SDL_KEYUP:
472414                  {
473415                     const SDL_KeyboardEvent& kev = event.key;
r245117r245118
673615                        }
674616                        break;
675617
676                     case SDL_USER_WINDOW_TOGGLE_FULL_SCREEN:
677                        {
678                           WindowHandle handle = getWindowHandle(uev);
679                           m_fullscreen = !m_fullscreen;
680                           SDL_SetWindowFullscreen(m_window[handle.idx], m_fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
681                        }
682                        break;
683
684618                     case SDL_USER_WINDOW_MOUSE_LOCK:
685619                        {
686620                           SDL_SetRelativeMouseMode(!!uev.code ? SDL_TRUE : SDL_FALSE);
r245117r245118
735669            m_width  = _width;
736670            m_height = _height;
737671
672            if (m_width < m_height)
673            {
674               float aspectRatio = 1.0f/m_aspectRatio;
675               m_width = bx::uint32_max(ENTRY_DEFAULT_WIDTH/4, m_width);
676               m_height = uint32_t(float(m_width)*aspectRatio);
677            }
678            else
679            {
680               float aspectRatio = m_aspectRatio;
681               m_height = bx::uint32_max(ENTRY_DEFAULT_HEIGHT/4, m_height);
682               m_width = uint32_t(float(m_height)*aspectRatio);
683            }
684
738685            SDL_SetWindowSize(m_window[_handle.idx], m_width, m_height);
739686            m_eventQueue.postSizeEvent(_handle, m_width, m_height);
740687         }
r245117r245118
775722
776723      int32_t m_mx;
777724      int32_t m_my;
778      int32_t m_mz;
779725      bool m_mouseLock;
780      bool m_fullscreen;
781726   };
782727
783728   static Context s_ctx;
r245117r245118
860805      sdlPostEvent(SDL_USER_WINDOW_TOGGLE_FRAME, _handle);
861806   }
862807
863   void toggleFullscreen(WindowHandle _handle)
864   {
865      sdlPostEvent(SDL_USER_WINDOW_TOGGLE_FULL_SCREEN, _handle);
866   }
867
868808   void setMouseLock(WindowHandle _handle, bool _lock)
869809   {
870810      sdlPostEvent(SDL_USER_WINDOW_MOUSE_LOCK, _handle, NULL, _lock);
trunk/3rdparty/bgfx/examples/common/entry/entry_windows.cpp
r245117r245118
706706                  ScreenToClient(_hwnd, &pt);
707707                  int32_t mx = pt.x;
708708                  int32_t my = pt.y;
709                  m_mz += GET_WHEEL_DELTA_WPARAM(_wparam)/WHEEL_DELTA;
709                  m_mz += GET_WHEEL_DELTA_WPARAM(_wparam);
710710                  m_eventQueue.postMouseEvent(findHandle(_hwnd), mx, my, m_mz);
711711               }
712712               break;
r245117r245118
10671067      PostMessage(s_ctx.m_hwnd[0], WM_USER_WINDOW_TOGGLE_FRAME, _handle.idx, 0);
10681068   }
10691069
1070   void toggleFullscreen(WindowHandle _handle)
1071   {
1072      BX_UNUSED(_handle);
1073   }
1074
10751070   void setMouseLock(WindowHandle _handle, bool _lock)
10761071   {
10771072      PostMessage(s_ctx.m_hwnd[0], WM_USER_WINDOW_MOUSE_LOCK, _handle.idx, _lock);
trunk/3rdparty/bgfx/examples/common/entry/entry_winrt.cpp
r245117r245118
175175      BX_UNUSED(_handle);
176176   }
177177
178   void toggleFullscreen(WindowHandle _handle)
179   {
180      BX_UNUSED(_handle);
181   }
182
183178   void setMouseLock(WindowHandle _handle, bool _lock)
184179   {
185180      BX_UNUSED(_handle, _lock);
trunk/3rdparty/bgfx/examples/common/entry/entry_x11.cpp
r245117r245118
267267         initTranslateKey('x',             Key::KeyX);
268268         initTranslateKey('y',             Key::KeyY);
269269         initTranslateKey('z',             Key::KeyZ);
270
271         m_mx = 0;
272         m_my = 0;
273         m_mz = 0;
274270      }
275271
276272      int32_t run(int _argc, char** _argv)
r245117r245118
371367                  case ButtonRelease:
372368                     {
373369                        const XButtonEvent& xbutton = event.xbutton;
374                        MouseButton::Enum mb = MouseButton::None;
370                        MouseButton::Enum mb;
375371                        switch (xbutton.button)
376372                        {
377373                           case Button1: mb = MouseButton::Left;   break;
378374                           case Button2: mb = MouseButton::Middle; break;
379375                           case Button3: mb = MouseButton::Right;  break;
380                           case Button4: ++m_mz; break;
381                           case Button5: --m_mz; break;
376                           default:      mb = MouseButton::None;   break;
382377                        }
383378
384                        WindowHandle handle = findHandle(xbutton.window);
385379                        if (MouseButton::None != mb)
386380                        {
381                           WindowHandle handle = findHandle(xbutton.window);
387382                           m_eventQueue.postMouseEvent(handle
388383                              , xbutton.x
389384                              , xbutton.y
r245117r245118
392387                              , event.type == ButtonPress
393388                              );
394389                        }
395                        else
396                        {
397                           m_eventQueue.postMouseEvent(handle
398                                 , m_mx
399                                 , m_my
400                                 , m_mz
401                                 );
402                        }
403390                     }
404391                     break;
405392
r245117r245118
407394                     {
408395                        const XMotionEvent& xmotion = event.xmotion;
409396                        WindowHandle handle = findHandle(xmotion.window);
410
411                        m_mx = xmotion.x;
412                        m_my = xmotion.y;
413
414397                        m_eventQueue.postMouseEvent(handle
415                              , m_mx
416                              , m_my
417                              , m_mz
398                              , xmotion.x
399                              , xmotion.y
400                              , 0
418401                              );
419402                     }
420403                     break;
r245117r245118
560543      uint8_t m_modifiers;
561544      bool m_exit;
562545
563      int32_t m_mx;
564      int32_t m_my;
565      int32_t m_mz;
566
567546      EventQueue m_eventQueue;
568547      bx::LwMutex m_lock;
569548      bx::HandleAllocT<ENTRY_CONFIG_MAX_WINDOWS> m_windowAlloc;
r245117r245118
664643      BX_UNUSED(_handle);
665644   }
666645
667   void toggleFullscreen(WindowHandle _handle)
668   {
669      BX_UNUSED(_handle);
670   }
671
672646   void setMouseLock(WindowHandle _handle, bool _lock)
673647   {
674648      BX_UNUSED(_handle, _lock);
trunk/3rdparty/bgfx/examples/common/imgui/fs_imgui_latlong.bin.h
r245117r245118
1static const uint8_t fs_imgui_latlong_glsl[649] =
1static const uint8_t fs_imgui_latlong_glsl[646] =
22{
33   0x46, 0x53, 0x48, 0x03, 0x6f, 0x1e, 0x3e, 0x3c, 0x02, 0x00, 0x11, 0x75, 0x5f, 0x69, 0x6d, 0x61, // FSH.o.><...u_ima
44   0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x07, 0x01, 0x00, 0x00, // geLodEnabled....
55   0x01, 0x00, 0x0a, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x01, 0x00, // ...s_texColor...
6   0x00, 0x01, 0x00, 0x51, 0x02, 0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, // ...Q...varying h
6   0x00, 0x01, 0x00, 0x4e, 0x02, 0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, // ...N...varying h
77   0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, // ighp vec2 v_texc
88   0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x68, // oord0;.uniform h
99   0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, // ighp vec4 u_imag
r245117r245118
2121   0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x20, 0x3d, 0x20, 0x28, 0x76, 0x5f, //   tmpvar_3 = (v_
2222   0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x2e, 0x79, 0x20, 0x2a, 0x20, 0x33, 0x2e, // texcoord0.y * 3.
2323   0x31, 0x34, 0x31, 0x35, 0x39, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, // 14159);.  result
24   0x5f, 0x31, 0x2e, 0x78, 0x20, 0x3d, 0x20, 0x28, 0x2d, 0x28, 0x73, 0x69, 0x6e, 0x28, 0x74, 0x6d, // _1.x = (-(sin(tm
25   0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x29, 0x29, 0x20, 0x2a, 0x20, 0x73, 0x69, 0x6e, 0x28, 0x74, // pvar_3)) * sin(t
26   0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x73, // mpvar_2));.  res
27   0x75, 0x6c, 0x74, 0x5f, 0x31, 0x2e, 0x79, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x73, 0x28, 0x74, 0x6d, // ult_1.y = cos(tm
28   0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, // pvar_3);.  resul
29   0x74, 0x5f, 0x31, 0x2e, 0x7a, 0x20, 0x3d, 0x20, 0x28, 0x2d, 0x28, 0x73, 0x69, 0x6e, 0x28, 0x74, // t_1.z = (-(sin(t
30   0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x33, 0x29, 0x29, 0x20, 0x2a, 0x20, 0x63, 0x6f, 0x73, 0x28, // mpvar_3)) * cos(
31   0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x6c, 0x6f, // tmpvar_2));.  lo
32   0x77, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, // wp vec4 tmpvar_4
33   0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, 0x2e, 0x78, 0x79, 0x7a, // ;.  tmpvar_4.xyz
34   0x20, 0x3d, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x43, 0x75, 0x62, 0x65, 0x4c, 0x6f, //  = textureCubeLo
35   0x64, 0x20, 0x20, 0x20, 0x20, 0x28, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, // d    (s_texColor
36   0x2c, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x5f, 0x31, 0x2c, 0x20, 0x75, 0x5f, 0x69, 0x6d, // , result_1, u_im
37   0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x2e, 0x78, 0x29, // ageLodEnabled.x)
38   0x2e, 0x78, 0x79, 0x7a, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, // .xyz;.  tmpvar_4
39   0x2e, 0x77, 0x20, 0x3d, 0x20, 0x28, 0x30, 0x2e, 0x32, 0x20, 0x2b, 0x20, 0x28, 0x30, 0x2e, 0x38, // .w = (0.2 + (0.8
40   0x20, 0x2a, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, //  * u_imageLodEna
41   0x62, 0x6c, 0x65, 0x64, 0x2e, 0x79, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, // bled.y));.  gl_F
42   0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, // ragColor = tmpva
43   0x72, 0x5f, 0x34, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00,                                           // r_4;.}...
24   0x5f, 0x31, 0x2e, 0x78, 0x20, 0x3d, 0x20, 0x28, 0x73, 0x69, 0x6e, 0x28, 0x74, 0x6d, 0x70, 0x76, // _1.x = (sin(tmpv
25   0x61, 0x72, 0x5f, 0x33, 0x29, 0x20, 0x2a, 0x20, 0x63, 0x6f, 0x73, 0x28, 0x74, 0x6d, 0x70, 0x76, // ar_3) * cos(tmpv
26   0x61, 0x72, 0x5f, 0x32, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, // ar_2));.  result
27   0x5f, 0x31, 0x2e, 0x79, 0x20, 0x3d, 0x20, 0x63, 0x6f, 0x73, 0x28, 0x74, 0x6d, 0x70, 0x76, 0x61, // _1.y = cos(tmpva
28   0x72, 0x5f, 0x33, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x5f, 0x31, // r_3);.  result_1
29   0x2e, 0x7a, 0x20, 0x3d, 0x20, 0x28, 0x2d, 0x28, 0x73, 0x69, 0x6e, 0x28, 0x74, 0x6d, 0x70, 0x76, // .z = (-(sin(tmpv
30   0x61, 0x72, 0x5f, 0x33, 0x29, 0x29, 0x20, 0x2a, 0x20, 0x73, 0x69, 0x6e, 0x28, 0x74, 0x6d, 0x70, // ar_3)) * sin(tmp
31   0x76, 0x61, 0x72, 0x5f, 0x32, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x77, 0x70, 0x20, // var_2));.  lowp
32   0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, 0x3b, 0x0a, 0x20, // vec4 tmpvar_4;.
33   0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, //  tmpvar_4.xyz =
34   0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x43, 0x75, 0x62, 0x65, 0x4c, 0x6f, 0x64, 0x20, 0x20, // textureCubeLod
35   0x20, 0x20, 0x28, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x72, //   (s_texColor, r
36   0x65, 0x73, 0x75, 0x6c, 0x74, 0x5f, 0x31, 0x2c, 0x20, 0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, // esult_1, u_image
37   0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x2e, 0x78, 0x29, 0x2e, 0x78, 0x79, // LodEnabled.x).xy
38   0x7a, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, 0x2e, 0x77, 0x20, // z;.  tmpvar_4.w
39   0x3d, 0x20, 0x28, 0x30, 0x2e, 0x32, 0x20, 0x2b, 0x20, 0x28, 0x30, 0x2e, 0x38, 0x20, 0x2a, 0x20, // = (0.2 + (0.8 *
40   0x75, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, // u_imageLodEnable
41   0x64, 0x2e, 0x79, 0x29, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, // d.y));.  gl_Frag
42   0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x34, // Color = tmpvar_4
43   0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00,                                                             // ;.}...
4444};
45static const uint8_t fs_imgui_latlong_dx9[537] =
45static const uint8_t fs_imgui_latlong_dx9[553] =
4646{
4747   0x46, 0x53, 0x48, 0x03, 0x6f, 0x1e, 0x3e, 0x3c, 0x01, 0x00, 0x11, 0x75, 0x5f, 0x69, 0x6d, 0x61, // FSH.o.><...u_ima
4848   0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x15, 0x01, 0x00, 0x00, // geLodEnabled....
49   0x01, 0x00, 0xf4, 0x01, 0x00, 0x03, 0xff, 0xff, 0xfe, 0xff, 0x30, 0x00, 0x43, 0x54, 0x41, 0x42, // ..........0.CTAB
49   0x01, 0x00, 0x04, 0x02, 0x00, 0x03, 0xff, 0xff, 0xfe, 0xff, 0x30, 0x00, 0x43, 0x54, 0x41, 0x42, // ..........0.CTAB
5050   0x1c, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, // ................
5151   0x1c, 0x00, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, // ............D...
5252   0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........P.......
r245117r245118
7171   0x01, 0x00, 0x00, 0xa0, 0x13, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x80, // ................
7272   0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x55, 0xa0, // ..............U.
7373   0x01, 0x00, 0xaa, 0xa0, 0x25, 0x00, 0x00, 0x02, 0x02, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x80, // ....%...........
74   0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x05, 0x80, 0x01, 0x00, 0xc5, 0x80, 0x02, 0x00, 0x55, 0x81, // ..............U.
74   0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01, 0x80, 0x01, 0x00, 0x00, 0x80, 0x02, 0x00, 0x55, 0x80, // ..............U.
75   0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x04, 0x80, 0x01, 0x00, 0x55, 0x80, 0x02, 0x00, 0x55, 0x81, // ..........U...U.
7576   0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x02, 0x80, 0x02, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x02, // ................
7677   0x00, 0x00, 0x08, 0x80, 0x00, 0x00, 0x00, 0xa0, 0x5f, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0x80, // ........_.......
7778   0x00, 0x00, 0xe4, 0x80, 0x00, 0x08, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x07, 0x80, // ................
r245117r245118
8384{
8485   0x46, 0x53, 0x48, 0x03, 0x6f, 0x1e, 0x3e, 0x3c, 0x01, 0x00, 0x11, 0x75, 0x5f, 0x69, 0x6d, 0x61, // FSH.o.><...u_ima
8586   0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x15, 0x00, 0x30, 0x0a, // geLodEnabled..0.
86   0x01, 0x00, 0x30, 0x02, 0x44, 0x58, 0x42, 0x43, 0xbb, 0x3e, 0xd7, 0x3a, 0x63, 0xc9, 0x70, 0x0b, // ..0.DXBC.>.:c.p.
87   0xa5, 0x2c, 0x7d, 0xb2, 0x3c, 0x0c, 0x75, 0x44, 0x01, 0x00, 0x00, 0x00, 0x30, 0x02, 0x00, 0x00, // .,}.<.uD....0...
87   0x01, 0x00, 0x30, 0x02, 0x44, 0x58, 0x42, 0x43, 0x89, 0x11, 0x25, 0xa6, 0xf5, 0x66, 0x12, 0x3f, // ..0.DXBC..%..f.?
88   0xc0, 0x1f, 0x67, 0x9b, 0x6e, 0x4e, 0xac, 0x03, 0x01, 0x00, 0x00, 0x00, 0x30, 0x02, 0x00, 0x00, // ..g.nN......0...
8889   0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, // ....,...........
8990   0x49, 0x53, 0x47, 0x4e, 0x50, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, // ISGNP...........
9091   0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // 8...............
r245117r245118
100101   0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x30, 0x00, 0x04, 0x00, 0x70, 0x10, 0x00, // .`......X0...p..
101102   0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x62, 0x10, 0x00, 0x03, 0x32, 0x10, 0x10, 0x00, // ....UU..b...2...
102103   0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ....e.... ......
103   0x68, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x0a, 0x32, 0x00, 0x10, 0x00, // h.......8...2...
104   0x00, 0x00, 0x00, 0x00, 0x16, 0x15, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, // .............@..
105   0xdb, 0x0f, 0x49, 0x40, 0xdb, 0x0f, 0xc9, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ..I@...@........
106   0x4d, 0x00, 0x00, 0x06, 0x42, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, // M...B...........
107   0x1a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, 0x07, 0x82, 0x00, 0x10, 0x00, // ........M.......
108   0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x80, 0x41, 0x00, 0x00, 0x00, // ............A...
104   0x68, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x0a, 0x32, 0x00, 0x10, 0x00, // h.......8...2...
105   0x00, 0x00, 0x00, 0x00, 0x46, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, // ....F........@..
106   0xdb, 0x0f, 0xc9, 0x40, 0xdb, 0x0f, 0x49, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ...@..I@........
107   0x4d, 0x00, 0x00, 0x07, 0x42, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, // M...B...........
108   0x1a, 0x00, 0x10, 0x80, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, 0x06, // ....A.......M...
109   0x32, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x16, 0x05, 0x10, 0x00, // 2...............
109110   0x00, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, 0x06, 0x00, 0xd0, 0x00, 0x00, 0x62, 0x00, 0x10, 0x00, // ....M.......b...
110   0x01, 0x00, 0x00, 0x00, 0x06, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x07, // ............8...
111   0x12, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ........*.......
112   0x3a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x07, 0x82, 0x00, 0x10, 0x00, // :.......8.......
113   0x01, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x10, 0x00, // ....:.......*...
114   0x01, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x0c, 0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ....H...........
115   0x46, 0x03, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x7e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // F.......F~......
111   0x02, 0x00, 0x00, 0x00, 0x06, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x07, // ............8...
112   0x82, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ........*.......
113   0x1a, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x07, 0x12, 0x00, 0x10, 0x00, // ........8.......
114   0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x10, 0x00, // ................
115   0x02, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x0c, 0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ....H...........
116   0x86, 0x03, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x7e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ........F~......
116117   0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x80, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, // .`........ .....
117118   0xa3, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, 0x72, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ....6...r ......
118119   0x46, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0a, 0x82, 0x20, 0x10, 0x00, // F.......2.... ..
trunk/3rdparty/bgfx/examples/common/imgui/fs_imgui_latlong.sc
r245117r245118
1818   float pi    = 3.14159265;
1919   float twoPi = 2.0*pi;
2020   float phi   = _uv.x * twoPi;
21   float theta = _uv.y * pi;
21   float theta = _uv.y *pi;
2222
2323   vec3 result;
24   result.x = -sin(theta)*sin(phi);
24   result.x = sin(theta)*cos(phi);
2525   result.y = cos(theta);
26   result.z = -sin(theta)*cos(phi);
26   result.z = -sin(theta)*sin(phi);
2727
2828   return result;
2929}
trunk/3rdparty/bgfx/examples/common/imgui/imgui.cpp
r245117r245118
387387      , m_textureHeight(512)
388388      , m_halfTexel(0.0f)
389389      , m_nvg(NULL)
390      , m_view(255)
391      , m_surfaceWidth(0)
392      , m_surfaceHeight(0)
390      , m_view(31)
393391      , m_viewWidth(0)
394392      , m_viewHeight(0)
395393      , m_currentFontIdx(0)
r245117r245118
812810      m_char = _inputChar;
813811   }
814812
815   void beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, uint16_t _surfaceWidth, uint16_t _surfaceHeight, char _inputChar, uint8_t _view)
813   void beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, char _inputChar, uint8_t _view)
816814   {
815      IMGUI_beginFrame(_mx, _my, _button, _width, _height, _inputChar, _view);
816
817817      m_view = _view;
818818      m_viewWidth = _width;
819819      m_viewHeight = _height;
820      m_surfaceWidth = _surfaceWidth;
821      m_surfaceHeight = _surfaceHeight;
822
823      const float xscale = float(m_surfaceWidth) /float(m_viewWidth);
824      const float yscale = float(m_surfaceHeight)/float(m_viewHeight);
825      const int32_t mx = int32_t(float(_mx)*xscale);
826      const int32_t my = int32_t(float(_my)*yscale);
827
828      IMGUI_beginFrame(mx, my, _button, _width, _height, _inputChar, _view);
829      nvgBeginFrameScaled(m_nvg, m_viewWidth, m_viewHeight, m_surfaceWidth, m_surfaceHeight, 1.0f);
830      nvgViewId(m_nvg, _view);
831
832820      bgfx::setViewName(_view, "IMGUI");
833821      bgfx::setViewSeq(_view, true);
834822
835823      const bgfx::HMD* hmd = bgfx::getHMD();
836824      if (NULL != hmd)
837825      {
838         m_viewWidth = _width / 2;
839         m_surfaceWidth = _surfaceWidth / 2;
826         m_viewWidth  = _width / 2;
840827
841828         float proj[16];
842829         bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 100.0f);
r245117r245118
849836         const float offset1 = -proj[8] + (hmd->eye[1].viewOffset[0] / dist * proj[0]);
850837
851838         float ortho[2][16];
852         const float viewOffset = _surfaceWidth/4.0f;
853         const float viewWidth  = _surfaceWidth/2.0f;
854         bx::mtxOrtho(ortho[0], viewOffset, viewOffset + viewWidth, (float)m_surfaceHeight, 0.0f, 0.0f, 1000.0f, offset0);
855         bx::mtxOrtho(ortho[1], viewOffset, viewOffset + viewWidth, (float)m_surfaceHeight, 0.0f, 0.0f, 1000.0f, offset1);
839         const float viewOffset = _width/4.0f;
840         const float viewWidth  = _width/2.0f;
841         bx::mtxOrtho(ortho[0], viewOffset, viewOffset + viewWidth, (float)m_viewHeight, 0.0f, 0.0f, 1000.0f, offset0);
842         bx::mtxOrtho(ortho[1], viewOffset, viewOffset + viewWidth, (float)m_viewHeight, 0.0f, 0.0f, 1000.0f, offset1);
856843         bgfx::setViewTransform(_view, NULL, ortho[0], BGFX_VIEW_STEREO, ortho[1]);
857844         bgfx::setViewRect(_view, 0, 0, hmd->width, hmd->height);
858845      }
859846      else
860847      {
861848         float ortho[16];
862         bx::mtxOrtho(ortho, 0.0f, (float)m_surfaceWidth, (float)m_surfaceHeight, 0.0f, 0.0f, 1000.0f);
849         bx::mtxOrtho(ortho, 0.0f, (float)m_viewWidth, (float)m_viewHeight, 0.0f, 0.0f, 1000.0f);
863850         bgfx::setViewTransform(_view, NULL, ortho);
864851         bgfx::setViewRect(_view, 0, 0, _width, _height);
865852      }
866853
867      updateInput(mx, my, _button, _scroll, _inputChar);
854      updateInput(_mx, _my, _button, _scroll, _inputChar);
868855
869856      m_hot = m_hotToBe;
870857      m_hotToBe = 0;
r245117r245118
896883
897884      clearInput();
898885
899      nvgEndFrame(m_nvg);
900886      IMGUI_endFrame();
901887   }
902888
r245117r245118
950936         setEnabled(m_areaId);
951937      }
952938
953      nvgScissor(m_nvg, area);
939      nvgScissor(m_nvg
940             , float(area.m_scissorX)
941             , float(area.m_scissorY-1)
942             , float(area.m_scissorWidth)
943             , float(area.m_scissorHeight+1)
944             );
954945
955946      m_insideArea |= area.m_inside;
956947
r245117r245118
10881079         }
10891080      }
10901081
1091      nvgScissor(m_nvg, parentArea);
1082      nvgScissor(m_nvg
1083             , float(parentArea.m_scissorX)
1084             , float(parentArea.m_scissorY-1)
1085             , float(parentArea.m_scissorWidth)
1086             , float(parentArea.m_scissorHeight+1)
1087             );
10921088   }
10931089
10941090   bool beginArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, bool _enabled, int32_t _r)
r245117r245118
11621158      }
11631159      area.m_scissorEnabled = true;
11641160
1165      nvgScissor(m_nvg, area);
1161      nvgBeginFrame(m_nvg, m_viewWidth, m_viewHeight, 1.0f);
1162      nvgScissor(m_nvg
1163             , float(area.m_scissorX)
1164             , float(area.m_scissorY-1)
1165             , float(area.m_scissorWidth)
1166             , float(area.m_scissorHeight+1)
1167             );
11661168
11671169      m_insideArea |= area.m_inside;
11681170      return area.m_inside;
r245117r245118
11701172
11711173   void endArea()
11721174   {
1173      m_areaId.pop();
11741175      nvgResetScissor(m_nvg);
1176      nvgEndFrame(m_nvg);
11751177   }
11761178
11771179   bool button(const char* _text, bool _enabled, ImguiAlign::Enum _align, uint32_t _rgb0, int32_t _r)
r245117r245118
12001202          //||  ImguiAlign::CenterIndented == _align).
12011203      {
12021204         xx = area.m_widgetX;
1203         width = area.m_widgetW - (area.m_widgetX-area.m_contentX);
1205         width = area.m_widgetW - (area.m_widgetX-area.m_scissorX);
12041206      }
12051207
12061208      const bool enabled = _enabled && isEnabled(m_areaId);
r245117r245118
13831385          //||  ImguiAlign::CenterIndented == _align).
13841386      {
13851387         xx = area.m_widgetX;
1386         width = area.m_widgetW - (area.m_widgetX-area.m_contentX);
1388         width = area.m_widgetW - (area.m_widgetX-area.m_scissorX);
13871389      }
13881390
13891391      const bool drawLabel = (NULL != _label && _label[0] != '\0');
r245117r245118
14031405      {
14041406         const size_t cursor = size_t(strlen(_str));
14051407
1406         if (m_char == 0x08 || m_char == 0x7f) //backspace or delete
1408         if (m_char == 0x08) //backspace
14071409         {
14081410            _str[cursor-1] = '\0';
14091411         }
r245117r245118
15221524          //||  ImguiAlign::CenterIndented == _align).
15231525      {
15241526         xx = area.m_widgetX;
1525         width = area.m_widgetW - (area.m_widgetX-area.m_contentX);
1527         width = area.m_widgetW - (area.m_widgetX-area.m_scissorX);
15261528      }
15271529
15281530      uint8_t selected = _selected;
r245117r245118
17421744          //||  ImguiAlign::CenterIndented == _align).
17431745      {
17441746         xx = area.m_widgetX;
1745         width = area.m_widgetW - (area.m_widgetX-area.m_contentX);
1747         width = area.m_widgetW - (area.m_widgetX-area.m_scissorX);
17461748      }
17471749
17481750      const int32_t height = width/2;
r245117r245118
17951797          //||  ImguiAlign::CenterIndented == _align).
17961798      {
17971799         xx = area.m_widgetX;
1798         width = area.m_widgetW - (area.m_widgetX-area.m_contentX);
1800         width = area.m_widgetW - (area.m_widgetX-area.m_scissorX);
17991801      }
18001802
18011803      const bool adjustHeight = (_cross && _sameHeight);
r245117r245118
20212023         xx = -borderSize;
20222024         yy = -1;
20232025         width = 2*borderSize+1;
2024         height = m_surfaceHeight+1;
2026         height = m_viewHeight;
20252027         triX = 0;
2026         triY = (m_surfaceHeight-triSize)/2;
2028         triY = (m_viewHeight-triSize)/2;
20272029         orientation = _checked ? TriangleOrientation::Left : TriangleOrientation::Right;
20282030      }
20292031      else if (ImguiBorder::Right == _border)
20302032      {
2031         xx = m_surfaceWidth - borderSize;
2033         xx = m_viewWidth - borderSize;
20322034         yy = -1;
20332035         width = 2*borderSize+1;
2034         height = m_surfaceHeight+1;
2035         triX = m_surfaceWidth - triSize - 2;
2036         triY = (m_surfaceHeight-width)/2;
2036         height = m_viewHeight;
2037         triX = m_viewWidth - triSize - 2;
2038         triY = (m_viewHeight-width)/2;
20372039         orientation = _checked ? TriangleOrientation::Right : TriangleOrientation::Left;
20382040      }
20392041      else if (ImguiBorder::Top == _border)
20402042      {
20412043         xx = 0;
20422044         yy = -borderSize;
2043         width = m_surfaceWidth;
2045         width = m_viewWidth;
20442046         height = 2*borderSize;
2045         triX = (m_surfaceWidth-triSize)/2;
2047         triX = (m_viewWidth-triSize)/2;
20462048         triY = 0;
20472049         orientation = _checked ? TriangleOrientation::Up : TriangleOrientation::Down;
20482050      }
20492051      else //if (ImguiBorder::Bottom == _border).
20502052      {
20512053         xx = 0;
2052         yy = m_surfaceHeight - borderSize;
2053         width = m_surfaceWidth;
2054         yy = m_viewHeight - borderSize;
2055         width = m_viewWidth;
20542056         height = 2*borderSize;
2055         triX = (m_surfaceWidth-triSize)/2;
2056         triY = m_surfaceHeight-triSize;
2057         triX = (m_viewWidth-triSize)/2;
2058         triY = m_viewHeight-triSize;
20572059         orientation = _checked ? TriangleOrientation::Down : TriangleOrientation::Up;
20582060      }
20592061
r245117r245118
21442146          //||  ImguiAlign::CenterIndented == _align).
21452147      {
21462148         xx = area.m_widgetX;
2147         width = area.m_widgetW - (area.m_widgetX-area.m_contentX);
2149         width = area.m_widgetW - (area.m_widgetX-area.m_scissorX);
21482150      }
21492151
21502152      drawRoundedRect( (float)xx, (float)yy, (float)width, (float)height, 4.0f, imguiRGBA(0, 0, 0, 128) );
r245117r245118
22622264      area.m_widgetY += _height;
22632265   }
22642266
2265   void separatorLine(uint16_t _height, ImguiAlign::Enum _align)
2267   void separatorLine(uint16_t _height)
22662268   {
22672269      Area& area = getCurrentArea();
2268      //const int32_t width = area.m_widgetW;
2269      const int32_t height = 1;
2270      //const int32_t xx = area.m_widgetX;
2271      const int32_t yy = area.m_widgetY + _height/2 - height;
2272
2273      int32_t xx;
2274      int32_t width;
2275      if (ImguiAlign::Left == _align)
2276      {
2277         xx = area.m_contentX + SCROLL_AREA_PADDING;
2278         width = area.m_widgetW;
2279      }
2280      else if (ImguiAlign::LeftIndented == _align
2281          ||  ImguiAlign::Right        == _align)
2282      {
2283         xx = area.m_widgetX;
2284         width = area.m_widgetW;
2285      }
2286      else //if (ImguiAlign::Center         == _align
2287          //||  ImguiAlign::CenterIndented == _align).
2288      {
2289         xx = area.m_widgetX;
2290         width = area.m_widgetW - (area.m_widgetX-area.m_contentX) + 1;
2291      }
2292
2270      const int32_t rectWidth = area.m_widgetW;
2271      const int32_t rectHeight = 1;
2272      const int32_t xx = area.m_widgetX;
2273      const int32_t yy = area.m_widgetY + _height/2 - rectHeight;
22932274      area.m_widgetY += _height;
22942275
22952276      drawRect( (float)xx
22962277            , (float)yy
2297            , (float)width
2298            , (float)height
2278            , (float)rectWidth
2279            , (float)rectHeight
22992280            , imguiRGBA(255, 255, 255, 32)
23002281            );
23012282   }
r245117r245118
30663047      const Area& area = getCurrentArea();
30673048      if (area.m_scissorEnabled)
30683049      {
3069         const float xscale = float(m_viewWidth) /float(m_surfaceWidth);
3070         const float yscale = float(m_viewHeight)/float(m_surfaceHeight);
3071         const int16_t scissorX      = int16_t(float(area.m_scissorX)*xscale);
3072         const int16_t scissorY      = int16_t(float(area.m_scissorY)*yscale);
3073         const int16_t scissorWidth  = int16_t(float(area.m_scissorWidth)*xscale);
3074         const int16_t scissorHeight = int16_t(float(area.m_scissorHeight)*yscale);
3075         bgfx::setScissor(uint16_t(IMGUI_MAX(0, scissorX) )
3076                     , uint16_t(IMGUI_MAX(0, scissorY-1) )
3077                     , scissorWidth
3078                     , scissorHeight+1
3050         bgfx::setScissor(uint16_t(IMGUI_MAX(0, area.m_scissorX) )
3051                     , uint16_t(IMGUI_MAX(0, area.m_scissorY-1) )
3052                     , area.m_scissorWidth
3053                     , area.m_scissorHeight+1
30793054                     );
30803055      }
30813056      else
r245117r245118
30843059      }
30853060   }
30863061
3087   inline void nvgScissor(NVGcontext* _ctx, const Area& _area)
3088   {
3089      if (_area.m_scissorEnabled)
3090      {
3091         ::nvgScissor(_ctx
3092                  , float(IMGUI_MAX(0, _area.m_scissorX) )
3093                  , float(IMGUI_MAX(0, _area.m_scissorY-1) )
3094                  , float(_area.m_scissorWidth)
3095                  , float(_area.m_scissorHeight+1)
3096                  );
3097      }
3098      else
3099      {
3100         nvgResetScissor(_ctx);
3101      }
3102   }
3103
31043062   template <typename Ty, uint16_t Max=64>
31053063   struct IdStack
31063064   {
r245117r245118
31883146   NVGcontext* m_nvg;
31893147
31903148   uint8_t m_view;
3191   uint16_t m_surfaceWidth;
3192   uint16_t m_surfaceHeight;
31933149   uint16_t m_viewWidth;
31943150   uint16_t m_viewHeight;
31953151
r245117r245118
32463202   return handle;
32473203}
32483204
3249void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, uint16_t _surfaceWidth, uint16_t _surfaceHeight, char _inputChar, uint8_t _view)
3250{
3251   s_imgui.beginFrame(_mx, _my, _button, _scroll, _width, _height, _surfaceWidth, _surfaceHeight, _inputChar, _view);
3252}
3253
32543205void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, char _inputChar, uint8_t _view)
32553206{
3256   s_imgui.beginFrame(_mx, _my, _button, _scroll, _width, _height, _width, _height, _inputChar, _view);
3207   s_imgui.beginFrame(_mx, _my, _button, _scroll, _width, _height, _inputChar, _view);
32573208}
32583209
32593210void imguiEndFrame()
r245117r245118
33363287   s_imgui.separator(_height);
33373288}
33383289
3339void imguiSeparatorLine(uint16_t _height, ImguiAlign::Enum _align)
3290void imguiSeparatorLine(uint16_t _height)
33403291{
3341   s_imgui.separatorLine(_height, _align);
3292   s_imgui.separatorLine(_height);
33423293}
33433294
33443295int32_t imguiGetWidgetX()
trunk/3rdparty/bgfx/examples/common/imgui/imgui.h
r245117r245118
136136ImguiFontHandle imguiCreate(const void* _data = NULL, uint32_t _size = 0, float _fontSize = 15.0f);
137137void imguiDestroy();
138138
139void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, char _inputChar = 0, uint8_t _view = 255);
140void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, uint16_t _surfaceWidth, uint16_t _surfaceHeight, char _inputChar = 0, uint8_t _view = 255);
139void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, char _inputChar = 0, uint8_t _view = 31);
141140void imguiEndFrame();
142141
143142void imguiDrawText(int _x, int _y, ImguiTextAlign::Enum _align, const char* _text, uint32_t _argb);
r245117r245118
159158void imguiIndent(uint16_t _width = IMGUI_INDENT_VALUE);
160159void imguiUnindent(uint16_t _width = IMGUI_INDENT_VALUE);
161160void imguiSeparator(uint16_t _height = IMGUI_SEPARATOR_VALUE);
162void imguiSeparatorLine(uint16_t _height = IMGUI_SEPARATOR_VALUE, ImguiAlign::Enum = ImguiAlign::LeftIndented);
161void imguiSeparatorLine(uint16_t _height = IMGUI_SEPARATOR_VALUE);
163162
164163int32_t imguiGetWidgetX();
165164int32_t imguiGetWidgetY();
trunk/3rdparty/bgfx/examples/common/imgui/ocornut_imgui.cpp
r245117r245118
8181
8282   void create(const void* _data, uint32_t _size, float _fontSize)
8383   {
84      m_viewId = 255;
84      m_viewId = 31;
8585
8686      ImGuiIO& io = ImGui::GetIO();
8787      io.DisplaySize = ImVec2(1280.0f, 720.0f);
r245117r245118
165165
166166      ImGui::NewFrame();
167167
168      //ImGui::ShowTestWindow(); //Debug only.
168//      ImGui::ShowTestWindow();
169169   }
170170
171171   void endFrame()
trunk/3rdparty/bgfx/examples/common/nanovg/nanovg.cpp
r245117r245118
296296   free(ctx);
297297}
298298
299void nvgBeginFrameScaled(NVGcontext* ctx, int windowWidth, int windowHeight, int surfaceWidth, int surfaceHeight, float devicePixelRatio)
299void nvgBeginFrame(NVGcontext* ctx, int windowWidth, int windowHeight, float devicePixelRatio)
300300{
301301/*   printf("Tris: draws:%d  fill:%d  stroke:%d  text:%d  TOT:%d\n",
302302      ctx->drawCallCount, ctx->fillTriCount, ctx->strokeTriCount, ctx->textTriCount,
r245117r245118
307307   nvgReset(ctx);
308308
309309   nvg__setDevicePixelRatio(ctx, devicePixelRatio);
310   
311   ctx->params.renderViewport(ctx->params.userPtr, windowWidth, windowHeight);
310312
311   ctx->params.renderViewport(ctx->params.userPtr, windowWidth, windowHeight, surfaceWidth, surfaceHeight);
312
313313   ctx->drawCallCount = 0;
314314   ctx->fillTriCount = 0;
315315   ctx->strokeTriCount = 0;
316316   ctx->textTriCount = 0;
317317}
318318
319void nvgBeginFrame(NVGcontext* ctx, int windowWidth, int windowHeight, float devicePixelRatio)
320{
321   nvgBeginFrameScaled(ctx, windowWidth, windowHeight, windowWidth, windowHeight, devicePixelRatio);
322}
323
324319void nvgCancelFrame(NVGcontext* ctx)
325320{
326321   ctx->params.renderCancel(ctx->params.userPtr);
trunk/3rdparty/bgfx/examples/common/nanovg/nanovg.h
r245117r245118
116116// frame buffer size. In that case you would set windowWidth/Height to the window size
117117// devicePixelRatio to: frameBufferWidth / windowWidth.
118118void nvgBeginFrame(NVGcontext* ctx, int windowWidth, int windowHeight, float devicePixelRatio);
119void nvgBeginFrameScaled(NVGcontext* ctx, int windowWidth, int windowHeight, int surfaceWidth, int surfaceHeight, float devicePixelRatio);
120119
121120// Cancels drawing the current frame.
122121void nvgCancelFrame(NVGcontext* ctx);
r245117r245118
589588   int (*renderDeleteTexture)(void* uptr, int image);
590589   int (*renderUpdateTexture)(void* uptr, int image, int x, int y, int w, int h, const unsigned char* data);
591590   int (*renderGetTextureSize)(void* uptr, int image, int* w, int* h);
592   void (*renderViewport)(void* uptr, int width, int height, int surfaceWidth, int surfaceHeight);
591   void (*renderViewport)(void* uptr, int width, int height);
593592   void (*renderCancel)(void* uptr);
594593   void (*renderFlush)(void* uptr);
595594   void (*renderFill)(void* uptr, NVGpaint* paint, NVGscissor* scissor, float fringe, const float* bounds, const NVGpath* paths, int npaths);
r245117r245118
600599typedef struct NVGparams NVGparams;
601600
602601NVGcontext* nvgCreate(int edgeaa, unsigned char viewid);
603void nvgViewId(struct NVGcontext* ctx, unsigned char viewid);
604602void nvgDelete(struct NVGcontext* ctx);
605603
606604// Contructor and destructor, called by the render back-end.
trunk/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp
r245117r245118
132132
133133      struct GLNVGtexture* textures;
134134      float view[2];
135      float surface[2];
136135      int ntextures;
137136      int ctextures;
138137      int textureId;
r245117r245118
517516      gl->th = handle;
518517   }
519518
520   static void nvgRenderViewport(void* _userPtr, int width, int height, int surfaceWidth, int surfaceHeight)
519   static void nvgRenderViewport(void* _userPtr, int width, int height)
521520   {
522521      struct GLNVGcontext* gl = (struct GLNVGcontext*)_userPtr;
523522      gl->view[0] = (float)width;
524523      gl->view[1] = (float)height;
525      gl->surface[0] = (float)surfaceWidth;
526      gl->surface[1] = (float)surfaceHeight;
527524      bgfx::setViewRect(gl->viewid, 0, 0, width, height);
528525   }
529526
r245117r245118
723720                        );
724721         }
725722
726         bgfx::setUniform(gl->u_viewSize, gl->surface);
723         bgfx::setUniform(gl->u_viewSize, gl->view);
727724
728725         for (uint32_t ii = 0, num = gl->ncalls; ii < num; ++ii)
729726         {
r245117r245118
10541051   return NULL;
10551052}
10561053
1057void nvgViewId(struct NVGcontext* ctx, unsigned char viewid)
1058{
1059   struct NVGparams* params = nvgInternalParams(ctx);
1060   struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr;
1061   gl->viewid = uint8_t(viewid);
1062}
1063
10641054void nvgDelete(struct NVGcontext* ctx)
10651055{
10661056   nvgDeleteInternal(ctx);
trunk/3rdparty/bgfx/examples/runtime/shaders/dx11/fs_update_3d.bin
r245117r245118
1FSHo><u_time$
2ÌDXBC?àZdØñÒÃÙg-
3Ì,„¸ISGNP8DSV_POSITIONTEXCOORD«««OSGN, SV_TARGET««SHDR @CYFŽ £Z`X(pUUb2eò hMЀ ¢2   B
4@?@?22F@??@??E   òFF~`6ò >0
trunk/3rdparty/bgfx/examples/runtime/shaders/dx9/fs_update_3d.bin
r245117r245118
Previous 199869 Revisions Next


© 1997-2024 The MAME Team