Previous 199869 Revisions Next

r36608 Tuesday 24th March, 2015 at 17:35:03 UTC by Miodrag Milanović
Merge pull request #150 from fulivi/mds2_dev

A new MESS driver: Intel Intellec MDS series-II [F. Ulivi]
[/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 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* 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* 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
r245119r245120
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 =
r245119r245120
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.
r245119r245120
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
r245119r245120
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 : 0xFFFFFFFFFFFFFFFF );
99    m_bitBuffer |= ( static_cast<uint64_t>( value ) << ( 64 - m_bitsLeft ) ) & ( m_bitsLeft == 0 ? 0 : UINT64_C(0xFFFFFFFFFFFFFFFF) );
100100
101101    if ( bitCount > m_bitsLeft )
102102    {
r245119r245120
175175    m_bufferEnd    = m_buffer + newBufferSize;
176176}
177177
178#endif // -- WRITE_BIT_STREAM_H__
No newline at end of file
178#endif // -- WRITE_BIT_STREAM_H__
trunk/3rdparty/bgfx/3rdparty/ocornut-imgui/imconfig.h
r245119r245120
1414//---- Define assertion handler. Defaults to calling assert().
1515//#define IM_ASSERT(_EXPR)  MyAssert(_EXPR)
1616
17//---- Don't implement default clipboard handlers for Windows (so as not to link with OpenClipboard() and others Win32 functions)
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)
1822//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS
23//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS
1924
2025//---- Include imgui_user.inl at the end of imgui.cpp so you can include code that extends ImGui using its private data/functions.
2126//#define IMGUI_INCLUDE_IMGUI_USER_INL
r245119r245120
3641
3742//---- Freely implement extra functions within the ImGui:: namespace.
3843//---- Declare helpers or widgets implemented in imgui_user.inl or elsewhere, so end-user doesn't need to include multiple files.
39//---- e.g. you can create variants of the ImGui::Value() helper for your low-level math types.
44//---- e.g. you can create variants of the ImGui::Value() helper for your low-level math types, or your own widgets/helpers.
4045/*
4146namespace ImGui
4247{
trunk/3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.cpp
r245119r245120
1// ImGui library v1.32 wip
1// ImGui library v1.35
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
r245119r245120
99 Index
1010 - MISSION STATEMENT
1111 - END-USER GUIDE
12 - PROGRAMMER GUIDE
13 - API BREAKING CHANGES
14 - TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS
12 - PROGRAMMER GUIDE (read me!)
13 - API BREAKING CHANGES (read me when you update!)
14 - FREQUENTLY ASKED QUESTIONS (FAQ) & TROUBLESHOOTING (read me!)
1515 - ISSUES & TODO-LIST
1616 - CODE
1717 - SAMPLE CODE
r245119r245120
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, etc.)
30 - portable, minimize dependencies, run on target (consoles, phones, 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 use statically sized buffers for string manipulations - won't crash, but some long text may be clipped
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.
3838
3939
4040 END-USER GUIDE
r245119r245120
6363 PROGRAMMER GUIDE
6464 ================
6565
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
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.
6869 - see examples/ folder for standalone sample applications.
6970 - 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).
7071
71
7272 - getting started:
7373   - initialisation: call ImGui::GetIO() and fill the 'Settings' data.
7474   - every frame:
r245119r245120
9696        // TODO: store your texture pointer/identifier in 'io.Fonts->TexID'
9797
9898        // Application main loop
99        for (;;)
99        while (true)
100100        {
101101            // 1) get low-level input
102102            // e.g. on Win32, GetKeyboardState(), or poll your events, etc.
r245119r245120
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.
132136 - 2015/02/10 (1.32) - renamed GetItemWidth() to CalcItemWidth() to clarify its evolving behavior
133137 - 2015/02/08 (1.31) - renamed GetTextLineSpacing() to GetTextLineHeightWithSpacing()
134138 - 2015/02/01 (1.31) - removed IO.MemReallocFn (unused)
r245119r245120
164168 - 2014/08/28 (1.09) - changed the behavior of IO.PixelCenterOffset following various rendering fixes
165169
166170
167 TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS
168 ============================================
171 FREQUENTLY ASKED QUESTIONS (FAQ) & TROUBLESHOOTING
172 ==================================================
169173
170174 If text or lines are blurry when integrating ImGui in your engine:
175
171176   - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
172177
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.
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
177186   - 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.
190187
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
191223 If you want to load a different font than the default (ProggyClean.ttf, size 13)
192224
193225     io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);
r245119r245120
204236
205237     io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, io.Fonts->GetGlyphRangesJapanese());  // Load Japanese characters
206238     io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
239     io.ImeWindowHandle = MY_HWND;      // To input using Microsoft IME, give ImGui the hwnd of your application
207240
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
232241 - 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.
233242 - tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug"
234243 - tip: you can call Begin() multiple times with the same name during the same frame, it will keep appending to the same window.
r245119r245120
254263 - 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?
255264 - 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
256265 - 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
259266!- input number: very large int not reliably supported because of int<>float conversions.
260267 - input number: optional range min/max for Input*() functions
261268 - input number: holding [-]/[+] buttons could increase the step speed non-linearly (or user-controlled)
r245119r245120
268275 - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills)
269276 - columns: columns header to act as button (~sort op) and allow resize/reorder
270277 - columns: user specify columns size
278 - columns: tree node example, removing the last NextColumn() makes a padding difference (it should not)
271279 - combo: turn child handling code into pop up helper
272280 - combo: contents should extends to fit label if combo widget is small
273281 - listbox: multiple selection
r245119r245120
281289 - 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)
282290 - file selection widget -> build the tool in our codebase to improve model-dialog idioms
283291 - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt()
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.
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.
286294 - text edit: centered text for slider as input text so it matches typical positioning.
287295 - text edit: flag to disable live update of the user buffer.
288296 - text edit: field resize behavior - field could stretch when being edited? hover tooltip shows more text?
r245119r245120
293301 ! style: store rounded corners in texture to use 1 quad per corner (filled and wireframe). so rounding have minor cost.
294302 - style: checkbox: padding for "active" color should be a multiplier of the
295303 - style: colorbox not always square?
304 - text: simple markup language for color change?
296305 - log: LogButtons() options for specifying depth and/or hiding depth slider
297306 - log: have more control over the log scope (e.g. stop logging when leaving current tree node scope)
298307 - log: be able to right-click and log a window or tree-node into tty/file/clipboard / generalized context menu?
r245119r245120
340349#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.
341350#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.
342351#pragma clang diagnostic ignored "-Wglobal-constructors"    // warning : declaration requires a global destructor           // similar to above, not sure what the exact difference it.
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"
352#pragma clang diagnostic ignored "-Wsign-conversion"        // warning : implicit conversion changes signedness             //
348353#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
349360
350361//-------------------------------------------------------------------------
351362// STB libraries implementation
r245119r245120
384395#endif
385396#include "stb_truetype.h"
386397
387#define STB_TEXTEDIT_STRING ImGuiTextEditState
388#define STB_TEXTEDIT_CHARTYPE ImWchar
398#define STB_TEXTEDIT_STRING    ImGuiTextEditState
399#define STB_TEXTEDIT_CHARTYPE  ImWchar
389400#include "stb_textedit.h"
390401
391402#ifdef __clang__
r245119r245120
401412// Forward Declarations
402413//-------------------------------------------------------------------------
403414
415struct ImGuiColMod;
416struct ImGuiStyleMod;
404417struct ImGuiAabb;
418struct ImGuiDrawContext;
419struct ImGuiTextEditState;
420struct ImGuiIniData;
421struct ImGuiState;
422struct ImGuiWindow;
405423
406424static 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);
407425static void         LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL);
r245119r245120
413431static void         RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false);
414432
415433static void         SetFont(ImFont* font);
416static bool         ItemAdd(const ImGuiAabb& aabb, const ImGuiID* id);
434static bool         ItemAdd(const ImGuiAabb& bb, const ImGuiID* id);
417435static void         ItemSize(ImVec2 size, ImVec2* adjust_start_offset = NULL);
418static void         ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset = NULL);
436static void         ItemSize(const ImGuiAabb& bb, ImVec2* adjust_start_offset = NULL);
419437static void         PushColumnClipRect(int column_index = -1);
420static bool         IsClipped(const ImGuiAabb& aabb);
438static bool         IsClipped(const ImGuiAabb& bb);
421439
422static bool         IsMouseHoveringBox(const ImGuiAabb& box);
440static bool         IsMouseHoveringBox(const ImGuiAabb& bb);
423441static bool         IsKeyPressedMap(ImGuiKey key, bool repeat = true);
424442
443static void         Scrollbar(ImGuiWindow* window);
425444static bool         CloseWindowButton(bool* p_opened = NULL);
426445static void         FocusWindow(ImGuiWindow* window);
427446static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs);
r245119r245120
436455static size_t       ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args);
437456
438457// Helpers: Misc
439static ImU32        ImCrc32(const void* data, size_t data_size, ImU32 seed);
458static ImU32        ImHash(const void* data, size_t data_size, ImU32 seed);
440459static bool         ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes = 0);
441static int          ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; }
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; }
442462
443463// Helpers: UTF-8 <> wchar
444464static int          ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int in_char);                                // return output UTF-8 bytes count
445465static ptrdiff_t    ImTextStrToUtf8(char* buf, size_t buf_size, const ImWchar* in_text, const ImWchar* in_text_end);   // return output UTF-8 bytes count
446466static int          ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end);          // 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
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
448468static int          ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end);                            // return number of UTF-8 code-points (NOT bytes count)
449static int          ImTextCountUtf8BytesFromWchar(const ImWchar* in_text, const ImWchar* in_text_end);                 // return number of bytes to express string as UTF-8 code-points
469static int          ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end);                   // return number of bytes to express string as UTF-8 code-points
450470
451471//-----------------------------------------------------------------------------
452472// Platform dependent default implementations
r245119r245120
454474
455475static const char*  GetClipboardTextFn_DefaultImpl();
456476static void         SetClipboardTextFn_DefaultImpl(const char* text);
477static void         ImeSetInputScreenPosFn_DefaultImpl(int x, int y);
457478
458479//-----------------------------------------------------------------------------
459480// Texture Atlas data
r245119r245120
486507    WindowFillAlphaDefault  = 0.70f;            // Default alpha of window background, if not specified in ImGui::Begin()
487508    TreeNodeSpacing         = 22.0f;            // Horizontal spacing when entering a tree node
488509    ColumnsMinSpacing       = 6.0f;             // Minimum horizontal spacing between two columns
489    ScrollBarWidth          = 16.0f;            // Width of the vertical scroll bar
510    ScrollbarWidth          = 16.0f;            // Width of the vertical scrollbar
511    GrabMinSize             = 10.0f;            // Minimum width/height of a slider or scrollbar grab
490512
491513    Colors[ImGuiCol_Text]                   = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
492514    Colors[ImGuiCol_WindowBg]               = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
r245119r245120
529551    Colors[ImGuiCol_TooltipBg]              = ImVec4(0.05f, 0.05f, 0.10f, 0.90f);
530552}
531553
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)
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.
534556static ImFontAtlas GDefaultFontAtlas;
535557
536558ImGuiIO::ImGuiIO()
r245119r245120
557579    MemFreeFn = free;
558580    GetClipboardTextFn = GetClipboardTextFn_DefaultImpl;   // Platform dependent default implementations
559581    SetClipboardTextFn = SetClipboardTextFn_DefaultImpl;
560    ImeSetInputScreenPosFn = NULL;
582    ImeSetInputScreenPosFn = ImeSetInputScreenPosFn_DefaultImpl;
561583}
562584
563585// Pass in translated ASCII characters for text input.
564586// - with glfw you can get those from the callback set in glfwSetCharCallback()
565// - on Windows you can get those using ToAscii+keyboard state, or via the VM_CHAR message
587// - on Windows you can get those using ToAscii+keyboard state, or via the WM_CHAR message
566588void ImGuiIO::AddInputCharacter(ImWchar c)
567589{
568590    const size_t n = ImStrlenW(InputCharacters);
r245119r245120
588610#define IM_INT_MAX 2147483647
589611#endif
590612
591// Play it nice with Windows users. Notepad in 2014 still doesn't display text data with Unix-style \n.
613// Play it nice with Windows users. Notepad in 2015 still doesn't display text data with Unix-style \n.
592614#ifdef _MSC_VER
593615#define STR_NEWLINE "\r\n"
594616#else
r245119r245120
647669static size_t ImStrlenW(const ImWchar* str)
648670{
649671    size_t n = 0;
650    while (*str++)
651        n++;
672    while (*str++) n++;
652673    return n;
653674}
654675
r245119r245120
675696}
676697
677698// Pass data_size==0 for zero-terminated string
678static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed = 0)
699// Try to replace with FNV1a hash?
700static ImU32 ImHash(const void* data, size_t data_size, ImU32 seed = 0)
679701{
680702    static ImU32 crc32_lut[256] = { 0 };
681703    if (!crc32_lut[1])
r245119r245120
689711            crc32_lut[i] = crc;
690712        }
691713    }
692    ImU32 crc = ~seed;
714
715    seed = ~seed;
716    ImU32 crc = seed;
693717    const unsigned char* current = (const unsigned char*)data;
694718
695719    if (data_size > 0)
r245119r245120
702726    {
703727        // Zero-terminated string
704728        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
705737            crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
738        }
706739    }
707740    return ~crc;
708741}
r245119r245120
841874    ImVec2      PreviousValue;
842875};
843876
844struct ImGuiAabb    // 2D axis aligned bounding-box
877struct ImGuiAabb        // 2D axis aligned bounding-box
845878{
846879    ImVec2      Min;
847880    ImVec2      Max;
r245119r245120
887920    ImVector<float>         TextWrapPos;
888921    ImGuiColorEditMode      ColorEditMode;
889922    ImGuiStorage*           StateStorage;
890    int                     OpenNextNode;        // FIXME: Reformulate this feature like SetNextWindowCollapsed() API
891923
892924    float                   ColumnsStartX;       // Start position from left of window (increased by TreePush/TreePop, etc.)
893925    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.
r245119r245120
898930    float                   ColumnsCellMaxY;
899931    bool                    ColumnsShowBorders;
900932    ImGuiID                 ColumnsSetID;
933    ImVector<float>         ColumnsOffsetsT;     // Columns offset normalized 0.0 (far left) -> 1.0 (far right)
901934
902935    ImGuiDrawContext()
903936    {
r245119r245120
909942        LastItemAabb = ImGuiAabb(0.0f,0.0f,0.0f,0.0f);
910943        LastItemHovered = false;
911944        StateStorage = NULL;
912        OpenNextNode = -1;
913945
914946        ColumnsStartX = 0.0f;
915947        ColumnsOffsetX = 0.0f;
r245119r245120
925957// Internal state of the currently focused/edited text input box
926958struct ImGuiTextEditState
927959{
960    ImGuiID             Id;                             // widget id owning the text state
928961    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.
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)
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)
931965    float               Width;                          // widget width
932966    float               ScrollX;
933967    STB_TexteditState   StbState;
934968    float               CursorAnim;
935    ImVec2              LastCursorPos;                  // Cursor position in screen space to be used by IME callback.
969    ImVec2              InputCursorScreenPos;           // Cursor position in screen space to be used by IME callback.
936970    bool                SelectedAllMouseLock;
937971    ImFont*             Font;
938972    float               FontSize;
r245119r245120
954988    static void             RenderTextScrolledClipped(ImFont* font, float font_size, const char* text, ImVec2 pos_base, float width, float scroll_x);
955989};
956990
991// Data saved in imgui.ini file
957992struct ImGuiIniData
958993{
959994    char*   Name;
995    ImGuiID ID;
960996    ImVec2  Pos;
961997    ImVec2  Size;
962998    bool    Collapsed;
r245119r245120
9651001    ~ImGuiIniData() { if (Name) { ImGui::MemFree(Name); Name = NULL; } }
9661002};
9671003
1004// Main state for ImGui
9681005struct ImGuiState
9691006{
9701007    bool                    Initialized;
r245119r245120
9871024    ImGuiID                 ActiveId;
9881025    ImGuiID                 ActiveIdPreviousFrame;
9891026    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.
9901029    float                   SettingsDirtyTimer;
9911030    ImVector<ImGuiIniData*> Settings;
9921031    ImVector<ImGuiColMod>   ColorModifiers;
9931032    ImVector<ImGuiStyleMod> StyleModifiers;
9941033    ImVector<ImFont*>       FontStack;
1034
9951035    ImVec2                  SetNextWindowPosVal;
996    ImGuiSetCondition       SetNextWindowPosCond;
1036    ImGuiSetCond            SetNextWindowPosCond;
9971037    ImVec2                  SetNextWindowSizeVal;
998    ImGuiSetCondition       SetNextWindowSizeCond;
1038    ImGuiSetCond            SetNextWindowSizeCond;
9991039    bool                    SetNextWindowCollapsedVal;
1000    ImGuiSetCondition       SetNextWindowCollapsedCond;
1040    ImGuiSetCond            SetNextWindowCollapsedCond;
1041    bool                    SetNextWindowFocus;
1042    bool                    SetNextTreeNodeOpenedVal;
1043    ImGuiSetCond            SetNextTreeNodeOpenedCond;
10011044
10021045    // Render
10031046    ImVector<ImDrawList*>   RenderDrawLists;
r245119r245120
10081051    ImGuiID                 SliderAsInputTextId;
10091052    ImGuiStorage            ColorEditModeStorage;               // for user selection
10101053    ImGuiID                 ActiveComboID;
1054    float                   ScrollbarClickDeltaToGrabCenter;    // distance between mouse and center of grab box, normalized in parent space
10111055    char                    Tooltip[1024];
10121056    char*                   PrivateClipboard;                   // if no custom clipboard handler is defined
10131057
r245119r245120
10181062    int                     LogStartDepth;
10191063    int                     LogAutoExpandMaxDepth;
10201064
1065    // Misc
1066    float                   FramerateSecPerFrame[120];          // calculate estimate of framerate for user
1067    int                     FramerateSecPerFrameIdx;
1068    float                   FramerateSecPerFrameAccum;
1069
10211070    ImGuiState()
10221071    {
10231072        Initialized = false;
1073        Font = NULL;
1074        FontSize = 0.0f;
1075        FontTexUvWhitePixel = ImVec2(0.0f, 0.0f);
1076
10241077        Time = 0.0f;
10251078        FrameCount = 0;
10261079        FrameCountRendered = -1;
r245119r245120
10281081        FocusedWindow = NULL;
10291082        HoveredWindow = NULL;
10301083        HoveredRootWindow = NULL;
1084        HoveredId = 0;
1085        ActiveId = 0;
1086        ActiveIdPreviousFrame = 0;
10311087        ActiveIdIsAlive = false;
1088        ActiveIdIsFocusedOnly = false;
1089        MovedWindow = NULL;
10321090        SettingsDirtyTimer = 0.0f;
1091
10331092        SetNextWindowPosVal = ImVec2(0.0f, 0.0f);
10341093        SetNextWindowPosCond = 0;
10351094        SetNextWindowSizeVal = ImVec2(0.0f, 0.0f);
10361095        SetNextWindowSizeCond = 0;
10371096        SetNextWindowCollapsedVal = false;
10381097        SetNextWindowCollapsedCond = 0;
1098        SetNextWindowFocus = false;
1099        SetNextTreeNodeOpenedVal = false;
1100        SetNextTreeNodeOpenedCond = 0;
1101
10391102        SliderAsInputTextId = 0;
10401103        ActiveComboID = 0;
1104        ScrollbarClickDeltaToGrabCenter = 0.0f;
10411105        memset(Tooltip, 0, sizeof(Tooltip));
10421106        PrivateClipboard = NULL;
1107
10431108        LogEnabled = false;
10441109        LogFile = NULL;
1110        LogClipboard = NULL;
10451111        LogStartDepth = 0;
10461112        LogAutoExpandMaxDepth = 2;
1047        LogClipboard = NULL;
1113
1114        memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame));
1115        FramerateSecPerFrameIdx = 0;
1116        FramerateSecPerFrameAccum = 0.0f;
10481117    }
10491118};
10501119
r245119r245120
10601129    ImVec2                  Pos;                                // Position rounded-up to nearest pixel
10611130    ImVec2                  Size;                               // Current size (==SizeFull or collapsed title bar size)
10621131    ImVec2                  SizeFull;                           // Size when non collapsed
1063    ImVec2                  SizeContentsFit;                    // Size of contents (extents reach by the drawing cursor) - may not fit within Size.
1132    ImVec2                  SizeContents;                       // Size of contents (== extents reach of the drawing cursor) from previous frame
1133    ImVec2                  SizeContentsCurrent;                // Size of contents, currently extending
10641134    float                   ScrollY;
10651135    float                   NextScrollY;
10661136    bool                    ScrollbarY;
r245119r245120
10701140    bool                    SkipItems;                          // == Visible && !Collapsed
10711141    int                     AutoFitFrames;
10721142    bool                    AutoFitOnlyGrows;
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.
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.
10761146
10771147    ImGuiDrawContext        DC;
10781148    ImVector<ImGuiID>       IDStack;
10791149    ImVector<ImVec4>        ClipRectStack;                      // Scissoring / clipping rectangle. x1, y1, x2, y2.
1150    ImGuiAabb               ClippedAabb;                        // = ClipRectStack.front() after setup in Begin()
10801151    int                     LastFrameDrawn;
10811152    float                   ItemWidthDefault;
10821153    ImGuiStorage            StateStorage;
r245119r245120
11091180    ImVec2      CursorPos() const                       { return DC.CursorPos; }
11101181    float       TitleBarHeight() const                  { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : FontSize() + GImGui->Style.FramePadding.y * 2.0f; }
11111182    ImGuiAabb   TitleBarAabb() const                    { return ImGuiAabb(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); }
1112    ImVec2      WindowPadding() const                   { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders)) ? ImVec2(1,1) : GImGui->Style.WindowPadding; }
1183    ImVec2      WindowPadding() const                   { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders)) ? ImVec2(0,0) : GImGui->Style.WindowPadding; }
11131184    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); }
11141185    ImU32       Color(const ImVec4& col) const          { ImVec4 c = col; c.w *= GImGui->Style.Alpha; return ImGui::ColorConvertFloat4ToU32(c); }
11151186};
11161187
1117static ImGuiWindow* GetCurrentWindow()
1188static inline ImGuiWindow* GetCurrentWindow()
11181189{
11191190    ImGuiState& g = *GImGui;
11201191    IM_ASSERT(g.CurrentWindow != NULL);    // ImGui::NewFrame() hasn't been called yet?
r245119r245120
11221193    return g.CurrentWindow;
11231194}
11241195
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
11251203static void SetActiveId(ImGuiID id)
11261204{
11271205    ImGuiState& g = *GImGui;
11281206    g.ActiveId = id;
1207    g.ActiveIdIsFocusedOnly = false;
11291208}
11301209
11311210static void RegisterAliveId(const ImGuiID& id)
r245119r245120
12511330//-----------------------------------------------------------------------------
12521331
12531332// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
1254ImGuiTextFilter::ImGuiTextFilter()
1333ImGuiTextFilter::ImGuiTextFilter(const char* default_filter)
12551334{
1256    InputBuf[0] = 0;
1257    CountGrep = 0;
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    }
12581345}
12591346
12601347void ImGuiTextFilter::Draw(const char* label, float width)
12611348{
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);
1349    if (width > 0.0f)
1350        ImGui::PushItemWidth(width);
12691351    ImGui::InputText(label, InputBuf, IM_ARRAYSIZE(InputBuf));
1270    ImGui::PopItemWidth();
1352    if (width > 0.0f)
1353        ImGui::PopItemWidth();
12711354    Build();
12721355}
12731356
r245119r245120
13831466ImGuiWindow::ImGuiWindow(const char* name)
13841467{
13851468    Name = ImStrdup(name);
1386    ID = GetID(name);
1469    ID = ImHash(name, 0);
13871470    IDStack.push_back(ID);
13881471
1472    Flags = 0;
13891473    PosFloat = Pos = ImVec2(0.0f, 0.0f);
13901474    Size = SizeFull = ImVec2(0.0f, 0.0f);
1391    SizeContentsFit = ImVec2(0.0f, 0.0f);
1475    SizeContents = SizeContentsCurrent = ImVec2(0.0f, 0.0f);
13921476    ScrollY = 0.0f;
13931477    NextScrollY = 0.0f;
13941478    ScrollbarY = false;
r245119r245120
13981482    SkipItems = false;
13991483    AutoFitFrames = -1;
14001484    AutoFitOnlyGrows = false;
1401    SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiSetCondition_Always | ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver;
1485    SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiSetCond_Always | ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver;
14021486
14031487    LastFrameDrawn = -1;
14041488    ItemWidthDefault = 0.0f;
r245119r245120
14121496
14131497    DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList));
14141498    new(DrawList) ImDrawList();
1499    RootWindow = NULL;
14151500
14161501    FocusIdxAllCounter = FocusIdxTabCounter = -1;
14171502    FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = IM_INT_MAX;
r245119r245120
14291514
14301515ImGuiID ImGuiWindow::GetID(const char* str)
14311516{
1432    const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back();
1433    const ImGuiID id = ImCrc32(str, 0, seed);
1517    ImGuiID seed = IDStack.back();
1518    const ImGuiID id = ImHash(str, 0, seed);
14341519    RegisterAliveId(id);
14351520    return id;
14361521}
14371522
14381523ImGuiID ImGuiWindow::GetID(const void* ptr)
14391524{
1440    const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back();
1441    const ImGuiID id = ImCrc32(&ptr, sizeof(void*), seed);
1525    ImGuiID seed = IDStack.back();
1526    const ImGuiID id = ImHash(&ptr, sizeof(void*), seed);
14421527    RegisterAliveId(id);
14431528    return id;
14441529}
r245119r245120
15101595static ImGuiIniData* FindWindowSettings(const char* name)
15111596{
15121597    ImGuiState& g = *GImGui;
1598    ImGuiID id = ImHash(name, 0);
15131599    for (size_t i = 0; i != g.Settings.size(); i++)
15141600    {
15151601        ImGuiIniData* ini = g.Settings[i];
1516        if (ImStricmp(ini->Name, name) == 0)
1602        if (ini->ID == id)
15171603            return ini;
15181604    }
15191605    return NULL;
r245119r245120
15241610    ImGuiIniData* ini = (ImGuiIniData*)ImGui::MemAlloc(sizeof(ImGuiIniData));
15251611    new(ini) ImGuiIniData();
15261612    ini->Name = ImStrdup(name);
1613    ini->ID = ImHash(name, 0);
15271614    ini->Collapsed = false;
15281615    ini->Pos = ImVec2(FLT_MAX,FLT_MAX);
15291616    ini->Size = ImVec2(0,0);
r245119r245120
16081695        const ImGuiIniData* settings = g.Settings[i];
16091696        if (settings->Pos.x == FLT_MAX)
16101697            continue;
1611        fprintf(f, "[%s]\n", settings->Name);
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);
16121702        fprintf(f, "Pos=%d,%d\n", (int)settings->Pos.x, (int)settings->Pos.y);
16131703        fprintf(f, "Size=%d,%d\n", (int)settings->Size.x, (int)settings->Size.y);
16141704        fprintf(f, "Collapsed=%d\n", settings->Collapsed);
r245119r245120
17151805    for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++)
17161806        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;
17171807
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
17181814    // Clear reference to active widget if the widget isn't alive anymore
17191815    g.HoveredId = 0;
17201816    if (!g.ActiveIdIsAlive && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0)
17211817        SetActiveId(0);
17221818    g.ActiveIdPreviousFrame = g.ActiveId;
17231819    g.ActiveIdIsAlive = false;
1820    if (!g.ActiveId)
1821        g.MovedWindow = NULL;
17241822
17251823    // Delay saving settings so we don't spam disk too much
17261824    if (g.SettingsDirtyTimer > 0.0f)
r245119r245120
17951893    }
17961894
17971895    // Mark all windows as not visible
1798    // Clear root windows at this point.
17991896    for (size_t i = 0; i != g.Windows.size(); i++)
18001897    {
18011898        ImGuiWindow* window = g.Windows[i];
18021899        window->Visible = false;
18031900        window->Accessed = false;
1804        window->RootWindow = NULL;
18051901    }
18061902
18071903    // No window should be open at the beginning of the frame.
r245119r245120
19322028            g.CurrentWindow->Visible = false;
19332029        ImGui::End();
19342030
1935        // Select window for move/focus when we're done with all our widgets (we only consider non-child windows here)
2031        // Select window for move/focus when we're done with all our widgets (we use the root window ID here)
19362032        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;
19372036            SetActiveId(g.HoveredRootWindow->GetID("#MOVE"));
2037        }
19382038
19392039        // Sort the window list so that all child windows are after their parent
19402040        // We cannot do that on FocusWindow() because childs may not exist yet
r245119r245120
20102110static const char*  FindTextDisplayEnd(const char* text, const char* text_end = NULL)
20112111{
20122112    const char* text_display_end = text;
2013    while ((!text_end || text_display_end < text_end) && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#'))
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] != '#'))
20142116        text_display_end++;
20152117    return text_display_end;
20162118}
r245119r245120
22172319
22182320    if (shadow && (window->Flags & ImGuiWindowFlags_ShowBorders) != 0)
22192321        window->DrawList->AddTriangleFilled(a+ImVec2(2,2), b+ImVec2(2,2), c+ImVec2(2,2), window->Color(ImGuiCol_BorderShadow));
2220    window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Border));
2322    window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Text));
22212323}
22222324
22232325// Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker.
r245119r245120
22942396            continue;
22952397        if (excluding_childs && (window->Flags & ImGuiWindowFlags_ChildWindow) != 0)
22962398            continue;
2297        ImGuiAabb bb(window->Pos - g.Style.TouchExtraPadding, window->Pos + window->Size + g.Style.TouchExtraPadding);
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);
22982402        if (bb.Contains(pos))
22992403            return window;
23002404    }
r245119r245120
23042408// Test if mouse cursor is hovering given aabb
23052409// NB- Box is clipped by our current clip setting
23062410// NB- Expand the aabb to be generous on imprecise inputs systems (g.Style.TouchExtraPadding)
2307static bool IsMouseHoveringBox(const ImGuiAabb& box)
2411static bool IsMouseHoveringBox(const ImGuiAabb& bb)
23082412{
23092413    ImGuiState& g = *GImGui;
23102414    ImGuiWindow* window = GetCurrentWindow();
23112415
23122416    // Clip
2313    ImGuiAabb box_clipped = box;
2417    ImGuiAabb box_clipped = bb;
23142418    if (!window->ClipRectStack.empty())
23152419    {
23162420        const ImVec4 clip_rect = window->ClipRectStack.back();
r245119r245120
24172521    return false;
24182522}
24192523
2524bool ImGui::IsAnyItemActive()
2525{
2526    ImGuiState& g = *GImGui;
2527    return g.ActiveId != 0;
2528}
2529
24202530ImVec2 ImGui::GetItemBoxMin()
24212531{
24222532    ImGuiWindow* window = GetCurrentWindow();
r245119r245120
24672577    ImGui::End();
24682578}
24692579
2470void ImGui::BeginChild(ImGuiID id, ImVec2 size, bool border, ImGuiWindowFlags extra_flags)
2580bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags)
24712581{
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{
24792582    ImGuiState& g = *GImGui;
24802583    ImGuiWindow* window = GetCurrentWindow();
24812584
r245119r245120
24832586
24842587    const ImVec2 content_max = window->Pos + ImGui::GetContentRegionMax();
24852588    const ImVec2 cursor_pos = window->Pos + ImGui::GetCursorPos();
2589    ImVec2 size = size_arg;
24862590    if (size.x <= 0.0f)
24872591    {
24882592        if (size.x == 0.0f)
r245119r245120
25032607    ImFormatString(title, IM_ARRAYSIZE(title), "%s.%s", window->Name, str_id);
25042608
25052609    const float alpha = 1.0f;
2506    ImGui::Begin(title, NULL, size, alpha, flags);
2610    bool ret = ImGui::Begin(title, NULL, size, alpha, flags);
25072611
25082612    if (!(window->Flags & ImGuiWindowFlags_ShowBorders))
25092613        g.CurrentWindow->Flags &= ~ImGuiWindowFlags_ShowBorders;
2614
2615    return ret;
25102616}
25112617
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
25122626void ImGui::EndChild()
25132627{
25142628    ImGuiWindow* window = GetCurrentWindow();
r245119r245120
25282642            sz.y = 0;
25292643
25302644        ImGui::End();
2645
2646        window = GetCurrentWindow();
2647        ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + sz);
25312648        ItemSize(sz);
2649        ItemAdd(bb, NULL);
25322650    }
25332651}
25342652
r245119r245120
25512669
25522670static ImGuiWindow* FindWindowByName(const char* name)
25532671{
2554    // FIXME-OPT: Consider optimizing this (e.g. sorted hashes to window pointers)
2672    // FIXME-OPT: Store sorted hashes -> pointers.
25552673    ImGuiState& g = *GImGui;
2556    for (size_t i = 0; i != g.Windows.size(); i++)
2557        if (strcmp(g.Windows[i]->Name, name) == 0)
2674    ImGuiID id = ImHash(name, 0);
2675    for (size_t i = 0; i < g.Windows.size(); i++)
2676        if (g.Windows[i]->ID == id)
25582677            return g.Windows[i];
25592678    return NULL;
25602679}
r245119r245120
25872706        }
25882707        else
25892708        {
2590            window->SetWindowPosAllowFlags &= ~ImGuiSetCondition_FirstUseEver;
2591            window->SetWindowSizeAllowFlags &= ~ImGuiSetCondition_FirstUseEver;
2592            window->SetWindowCollapsedAllowFlags &= ~ImGuiSetCondition_FirstUseEver;
2709            window->SetWindowPosAllowFlags &= ~ImGuiSetCond_FirstUseEver;
2710            window->SetWindowSizeAllowFlags &= ~ImGuiSetCond_FirstUseEver;
2711            window->SetWindowCollapsedAllowFlags &= ~ImGuiSetCond_FirstUseEver;
25932712        }
25942713
25952714        if (settings->Pos.x != FLT_MAX)
r245119r245120
26082727}
26092728
26102729// Push a new ImGui window to add widgets to.
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.
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.
26142735// - 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.
26152736// - 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.
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)
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)
26182739{
26192740    ImGuiState& g = *GImGui;
26202741    const ImGuiStyle& style = g.Style;
r245119r245120
26512772        ImGui::SetWindowCollapsed(g.SetNextWindowCollapsedVal, g.SetNextWindowCollapsedCond);
26522773        g.SetNextWindowCollapsedCond = 0;
26532774    }
2775    if (g.SetNextWindowFocus)
2776    {
2777        ImGui::SetWindowFocus();
2778        g.SetNextWindowFocus = false;
2779    }
26542780
26552781    // Find parent
26562782    ImGuiWindow* parent_window = (flags & ImGuiWindowFlags_ChildWindow) != 0 ? g.CurrentWindowStack[g.CurrentWindowStack.size()-2] : NULL;
26572783
2658    // Find root (if we are a child window)
2784    // Update known root window (if we are a child window, otherwise window == window->RootWindow)
26592785    size_t root_idx = g.CurrentWindowStack.size() - 1;
26602786    while (root_idx > 0)
26612787    {
r245119r245120
26662792    window->RootWindow = g.CurrentWindowStack[root_idx];
26672793
26682794    // Default alpha
2669    if (fill_alpha < 0.0f)
2670        fill_alpha = style.WindowFillAlphaDefault;
2795    if (bg_alpha < 0.0f)
2796        bg_alpha = style.WindowFillAlphaDefault;
26712797
26722798    // When reusing window again multiple times a frame, just append content (don't need to setup again)
26732799    const int current_frame = ImGui::GetFrameCount();
r245119r245120
26842810        window->LastFrameDrawn = current_frame;
26852811        window->ClipRectStack.resize(0);
26862812
2813        // Reset contents size for auto-fitting
2814        window->SizeContents = window->SizeContentsCurrent;
2815        window->SizeContentsCurrent = ImVec2(0.0f, 0.0f);
2816
26872817        if (flags & ImGuiWindowFlags_ChildWindow)
26882818        {
26892819            parent_window->DC.ChildWindows.push_back(window);
r245119r245120
27062836    // Setup and draw window
27072837    if (first_begin_of_the_frame)
27082838    {
2709        // Seed ID stack with our window pointer
2710        window->IDStack.resize(0);
2711        ImGui::PushID(window);
2839        // Reset ID stack
2840        window->IDStack.resize(1);
27122841
2713        // Move window (at the beginning of the frame to avoid input lag or sheering)
2842        // Move window (at the beginning of the frame to avoid input lag or sheering). Only valid for root windows.
27142843        const ImGuiID move_id = window->GetID("#MOVE");
27152844        RegisterAliveId(move_id);
27162845        if (g.ActiveId == move_id)
r245119r245120
27232852                    if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
27242853                        MarkSettingsDirty();
27252854                }
2726                FocusWindow(window);
2855                IM_ASSERT(g.MovedWindow != NULL);
2856                FocusWindow(g.MovedWindow);
27272857            }
27282858            else
27292859            {
27302860                SetActiveId(0);
2861                g.MovedWindow = NULL;   // Not strictly necessary but doing it for sanity.
27312862            }
27322863        }
27332864
r245119r245120
27772908        window->ScrollY = window->NextScrollY;
27782909        window->ScrollY = ImMax(window->ScrollY, 0.0f);
27792910        if (!window->Collapsed && !window->SkipItems)
2780            window->ScrollY = ImMin(window->ScrollY, ImMax(0.0f, (float)window->SizeContentsFit.y - window->SizeFull.y));
2911            window->ScrollY = ImMin(window->ScrollY, ImMax(0.0f, window->SizeContents.y - window->SizeFull.y));
27812912        window->NextScrollY = window->ScrollY;
27822913
27832914        // At this point we don't have a clipping rectangle setup yet, so we can test and draw in title bar
r245119r245120
28172948            if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
28182949            {
28192950                // Tooltip always resize. We keep the spacing symmetric on both axises for aesthetic purpose.
2820                const ImVec2 size_auto_fit = window->SizeContentsFit + style.WindowPadding - ImVec2(0.0f, style.ItemSpacing.y);
2951                const ImVec2 size_auto_fit = window->SizeContents + style.WindowPadding - ImVec2(0.0f, style.ItemSpacing.y);
28212952                window->SizeFull = size_auto_fit;
28222953            }
28232954            else
28242955            {
2825                const ImVec2 size_auto_fit = ImClamp(window->SizeContentsFit + style.AutoFitPadding, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding));
2956                const ImVec2 size_auto_fit = ImClamp(window->SizeContents + style.AutoFitPadding, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding));
28262957                if ((window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0)
28272958                {
28282959                    // Don't continuously mark settings as dirty, the size of the window doesn't need to be stored.
r245119r245120
28422973                {
28432974                    // Manual resize grip
28442975                    const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR());
2845                    const ImGuiID resize_id = window->GetID("##RESIZE");
2976                    const ImGuiID resize_id = window->GetID("#RESIZE");
28462977                    bool hovered, held;
28472978                    ButtonBehaviour(resize_aabb, resize_id, &hovered, &held, true);
28482979                    resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip);
r245119r245120
28703001            }
28713002
28723003            // Scrollbar
2873            window->ScrollbarY = (window->SizeContentsFit.y > window->Size.y) && !(window->Flags & ImGuiWindowFlags_NoScrollbar);
3004            window->ScrollbarY = (window->SizeContents.y > window->Size.y) && !(window->Flags & ImGuiWindowFlags_NoScrollbar);
28743005
28753006            // Window background
2876            if (fill_alpha > 0.0f)
3007            if (bg_alpha > 0.0f)
28773008            {
28783009                if ((window->Flags & ImGuiWindowFlags_ComboBox) != 0)
2879                    window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_ComboBg, fill_alpha), window_rounding);
3010                    window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_ComboBg, bg_alpha), window_rounding);
28803011                else if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
2881                    window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_TooltipBg, fill_alpha), window_rounding);
3012                    window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_TooltipBg, bg_alpha), window_rounding);
28823013                else if ((window->Flags & ImGuiWindowFlags_ChildWindow) != 0)
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));
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));
28843015                else
2885                    window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, fill_alpha), window_rounding);
3016                    window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, bg_alpha), window_rounding);
28863017            }
28873018
28883019            // Title bar
r245119r245120
29003031
29013032            // Scrollbar
29023033            if (window->ScrollbarY)
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));
3034                Scrollbar(window);
29083035
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
29363036            // Render resize grip
29373037            // (after the input handling so we don't have a frame of latency)
29383038            if (!(window->Flags & ImGuiWindowFlags_NoResize))
r245119r245120
29753075        window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.ColumnsStartPos.y;
29763076        window->DC.TreeDepth = 0;
29773077        window->DC.StateStorage = &window->StateStorage;
2978        window->DC.OpenNextNode = -1;
29793078
2980        // Reset contents size for auto-fitting
2981        window->SizeContentsFit = ImVec2(0.0f, 0.0f);
29823079        if (window->AutoFitFrames > 0)
29833080            window->AutoFitFrames--;
29843081
r245119r245120
29993096            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);
30003097            RenderTextClipped(text_min, name, NULL, &text_size, text_max);
30013098        }
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());
30023103    }
30033104
30043105    // Inner clipping rectangle
r245119r245120
30063107    const ImGuiAabb title_bar_aabb = window->TitleBarAabb();
30073108    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);
30083109    if (window->ScrollbarY)
3009        clip_rect.z -= style.ScrollBarWidth;
3110        clip_rect.z -= style.ScrollbarWidth;
30103111    PushClipRect(clip_rect);
30113112
30123113    // Clear 'accessed' flag last thing
r245119r245120
30183119    if (flags & ImGuiWindowFlags_ChildWindow)
30193120    {
30203121        IM_ASSERT((flags & ImGuiWindowFlags_NoTitleBar) != 0);
3122        window->Collapsed = parent_window && parent_window->Collapsed;
3123
30213124        const ImVec4 clip_rect_t = window->ClipRectStack.back();
3022        window->Collapsed = (clip_rect_t.x >= clip_rect_t.z || clip_rect_t.y >= clip_rect_t.w);
3125        window->Collapsed |= (clip_rect_t.x >= clip_rect_t.z || clip_rect_t.y >= clip_rect_t.w);
30233126
30243127        // We also hide the window from rendering because we've already added its border to the command list.
30253128        // (we could perform the check earlier in the function but it is simpler at this point)
r245119r245120
30493152        ImGui::LogFinish();
30503153
30513154    // Pop
3052    // NB: we don't clear 'window->RootWindow' yet, it will be used then cleared in NewFrame()
3155    // NB: we don't clear 'window->RootWindow'. The pointer is allowed to live until the next call to Begin().
30533156    g.CurrentWindowStack.pop_back();
30543157    g.CurrentWindow = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back();
30553158}
30563159
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
30573229// Moving window to front of display (which happens to be back of our sorted list)
30583230static void FocusWindow(ImGuiWindow* window)
30593231{
30603232    ImGuiState& g = *GImGui;
3233
3234    // Always mark the window we passed as focused. This is used for keyboard interactions such as tabbing.
30613235    g.FocusedWindow = window;
30623236
3237    // And move its root window to the top of the pile
3238    if (window->RootWindow)
3239        window = window->RootWindow;
3240
30633241    if (g.Windows.back() == window)
30643242        return;
30653243
r245119r245120
31093287    g.Font = font;
31103288    g.FontSize = g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale;
31113289    g.FontTexUvWhitePixel = g.Font->ContainerAtlas->TexUvWhitePixel;
3112    g.Font->FallbackGlyph = NULL;
3113    g.Font->FallbackGlyph = g.Font->FindGlyph(g.Font->FallbackChar);
31143290}
31153291
31163292void ImGui::PushFont(ImFont* font)
r245119r245120
32283404    ImGuiState& g = *GImGui;
32293405
32303406    ImVec2* pvar = GetStyleVarVec2Addr(idx);
3231    IM_ASSERT(pvar != NULL); // Called function with wrong-type? Varialble is not a ImVec2.
3407    IM_ASSERT(pvar != NULL); // Called function with wrong-type? Variable is not a ImVec2.
32323408    ImGuiStyleMod backup;
32333409    backup.Var = idx;
32343410    backup.PreviousValue = *pvar;
r245119r245120
33203496    return window->Pos;
33213497}
33223498
3323void ImGui::SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond)
3499static void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiSetCond cond)
33243500{
3325    ImGuiWindow* window = GetCurrentWindow();
3326
33273501    // Test condition (NB: bit 0 is always true) and clear flags for next time
33283502    if (cond && (window->SetWindowPosAllowFlags & cond) == 0)
33293503        return;
3330    window->SetWindowPosAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver);
3504    window->SetWindowPosAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver);
33313505
33323506    // Set
33333507    const ImVec2 old_pos = window->Pos;
r245119r245120
33363510    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
33373511}
33383512
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
33393526ImVec2 ImGui::GetWindowSize()
33403527{
33413528    ImGuiWindow* window = GetCurrentWindow();
33423529    return window->Size;
33433530}
33443531
3345void ImGui::SetWindowSize(const ImVec2& size, ImGuiSetCondition cond)
3532static void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiSetCond cond)
33463533{
3347    ImGuiWindow* window = GetCurrentWindow();
3348
33493534    // Test condition (NB: bit 0 is always true) and clear flags for next time
33503535    if (cond && (window->SetWindowSizeAllowFlags & cond) == 0)
33513536        return;
3352    window->SetWindowSizeAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver);
3537    window->SetWindowSizeAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver);
33533538
33543539    // Set
33553540    if (ImLengthSqr(size) > 0.00001f)
r245119r245120
33653550    }
33663551}
33673552
3368void ImGui::SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond)
3553void ImGui::SetWindowSize(const ImVec2& size, ImGuiSetCond cond)
33693554{
33703555    ImGuiWindow* window = GetCurrentWindow();
3556    SetWindowSize(window, size, cond);
3557}
33713558
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{
33723568    // Test condition (NB: bit 0 is always true) and clear flags for next time
33733569    if (cond && (window->SetWindowCollapsedAllowFlags & cond) == 0)
33743570        return;
3375    window->SetWindowCollapsedAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver);
3571    window->SetWindowCollapsedAllowFlags &= ~(ImGuiSetCond_Once | ImGuiSetCond_FirstUseEver);
33763572
33773573    // Set
33783574    window->Collapsed = collapsed;
33793575}
33803576
3381void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiSetCondition cond)
3577void ImGui::SetWindowCollapsed(bool collapsed, ImGuiSetCond cond)
33823578{
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{
33833611    ImGuiState& g = *GImGui;
33843612    g.SetNextWindowPosVal = pos;
3385    g.SetNextWindowPosCond = cond ? cond : ImGuiSetCondition_Always;
3613    g.SetNextWindowPosCond = cond ? cond : ImGuiSetCond_Always;
33863614}
33873615
3388void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiSetCondition cond)
3616void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiSetCond cond)
33893617{
33903618    ImGuiState& g = *GImGui;
33913619    g.SetNextWindowSizeVal = size;
3392    g.SetNextWindowSizeCond = cond ? cond : ImGuiSetCondition_Always;
3620    g.SetNextWindowSizeCond = cond ? cond : ImGuiSetCond_Always;
33933621}
33943622
3395void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiSetCondition cond)
3623void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiSetCond cond)
33963624{
33973625    ImGuiState& g = *GImGui;
33983626    g.SetNextWindowCollapsedVal = collapsed;
3399    g.SetNextWindowCollapsedCond = cond ? cond : ImGuiSetCondition_Always;
3627    g.SetNextWindowCollapsedCond = cond ? cond : ImGuiSetCond_Always;
34003628}
34013629
3630void ImGui::SetNextWindowFocus()
3631{
3632    ImGuiState& g = *GImGui;
3633    g.SetNextWindowFocus = true;
3634}
3635
34023636ImVec2 ImGui::GetContentRegionMax()
34033637{
34043638    ImGuiWindow* window = GetCurrentWindow();
3405    ImVec2 mx = window->Size - window->WindowPadding();
3639    ImVec2 window_padding = window->WindowPadding();
3640    ImVec2 mx = window->Size - window_padding;
34063641    if (window->DC.ColumnsCount != 1)
34073642    {
34083643        mx.x = ImGui::GetColumnOffset(window->DC.ColumnsCurrent + 1);
3409        mx.x -= GImGui->Style.WindowPadding.x;
3644        mx.x -= window_padding.x;
34103645    }
34113646    else
34123647    {
34133648        if (window->ScrollbarY)
3414            mx.x -= GImGui->Style.ScrollBarWidth;
3649            mx.x -= GImGui->Style.ScrollbarWidth;
34153650    }
34163651    return mx;
34173652}
r245119r245120
34273662    ImGuiWindow* window = GetCurrentWindow();
34283663    ImVec2 m = window->Size - window->WindowPadding();
34293664    if (window->ScrollbarY)
3430        m.x -= GImGui->Style.ScrollBarWidth;
3665        m.x -= GImGui->Style.ScrollbarWidth;
34313666    return m;
34323667}
34333668
r245119r245120
34903725{
34913726    ImGuiWindow* window = GetCurrentWindow();
34923727    window->DC.CursorPos = window->Pos + pos;
3493    window->SizeContentsFit = ImMax(window->SizeContentsFit, pos + ImVec2(0.0f, window->ScrollY));
3728    window->SizeContentsCurrent = ImMax(window->SizeContentsCurrent, pos + ImVec2(0.0f, window->ScrollY));
34943729}
34953730
34963731void ImGui::SetCursorPosX(float x)
34973732{
34983733    ImGuiWindow* window = GetCurrentWindow();
34993734    window->DC.CursorPos.x = window->Pos.x + x;
3500    window->SizeContentsFit.x = ImMax(window->SizeContentsFit.x, x);
3735    window->SizeContentsCurrent.x = ImMax(window->SizeContentsCurrent.x, x);
35013736}
35023737
35033738void ImGui::SetCursorPosY(float y)
35043739{
35053740    ImGuiWindow* window = GetCurrentWindow();
35063741    window->DC.CursorPos.y = window->Pos.y + y;
3507    window->SizeContentsFit.y = ImMax(window->SizeContentsFit.y, y + window->ScrollY);
3742    window->SizeContentsCurrent.y = ImMax(window->SizeContentsCurrent.y, y + window->ScrollY);
35083743}
35093744
35103745ImVec2 ImGui::GetCursorScreenPos()
r245119r245120
35193754    window->DC.CursorPos = screen_pos;
35203755}
35213756
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
35223769void ImGui::SetScrollPosHere()
35233770{
35243771    ImGuiWindow* window = GetCurrentWindow();
r245119r245120
37203967    const char* value_text_begin = &buf[0];
37213968    const char* value_text_end = value_text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
37223969
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);
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);
37263973    ItemSize(bb);
37273974    if (!ItemAdd(value_bb, NULL))
37283975        return;
r245119r245120
37463993    if (g.HoveredId == 0)
37473994    {
37483995        ImGuiWindow* window = GetCurrentWindow();
3749        const bool hovered = (g.HoveredRootWindow == window->RootWindow) && (g.ActiveId == 0 || g.ActiveId == id) && IsMouseHoveringBox(bb);
3750        return hovered;
3996        if (g.HoveredRootWindow == window->RootWindow)
3997        {
3998            bool hovered = (g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdIsFocusedOnly) && IsMouseHoveringBox(bb);
3999            return hovered;
4000        }
37514001    }
37524002    return false;
37534003}
r245119r245120
38144064
38154065    const ImGuiStyle& style = g.Style;
38164066    const ImGuiID id = window->GetID(label);
3817    const ImVec2 text_size = CalcTextSize(label, NULL, true);
4067    const ImVec2 label_size = CalcTextSize(label, NULL, true);
38184068
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);
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);
38204070    const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size + style.FramePadding*2.0f);
38214071    ItemSize(bb);
38224072    if (!ItemAdd(bb, &id))
r245119r245120
38294079    const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
38304080    RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
38314081
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)
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)
38344084
38354085    return pressed;
38364086}
r245119r245120
38454095
38464096    const ImGuiStyle& style = g.Style;
38474097    const ImGuiID id = window->GetID(label);
3848    const ImVec2 text_size = CalcTextSize(label, NULL, true);
4098    const ImVec2 label_size = CalcTextSize(label, NULL, true);
38494099
3850    const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size + ImVec2(style.FramePadding.x*2,0));
4100    const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + label_size + ImVec2(style.FramePadding.x*2,0));
38514101    ItemSize(bb);
38524102    if (!ItemAdd(bb, &id))
38534103        return false;
r245119r245120
38884138{
38894139    ImGuiWindow* window = GetCurrentWindow();
38904140
3891    const ImGuiID id = window->GetID("##CLOSE");
4141    const ImGuiID id = window->GetID("#CLOSE");
38924142    const float size = window->TitleBarHeight() - 4.0f;
38934143    const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-3.0f-size,2.0f), window->Aabb().GetTR() + ImVec2(-3.0f,2.0f+size));
38944144
r245119r245120
40824332        LogToClipboard(g.LogAutoExpandMaxDepth);
40834333}
40844334
4085bool ImGui::CollapsingHeader(const char* label, const char* str_id, const bool display_frame, const bool default_open)
4335bool ImGui::CollapsingHeader(const char* label, const char* str_id, bool display_frame, bool default_open)
40864336{
40874337    ImGuiState& g = *GImGui;
40884338    ImGuiWindow* window = GetCurrentWindow();
r245119r245120
40984348        label = str_id;
40994349    const ImGuiID id = window->GetID(str_id);
41004350
4101    // We only write to the tree storage if the user clicks
4351    // We only write to the tree storage if the user clicks (or explicitely use SetNextTreeNode*** functions)
41024352    ImGuiStorage* storage = window->DC.StateStorage;
41034353    bool opened;
4104    if (window->DC.OpenNextNode != -1)
4354    if (g.SetNextTreeNodeOpenedCond != 0)
41054355    {
4106        opened = window->DC.OpenNextNode > 0;
4107        storage->SetInt(id, opened);
4108        window->DC.OpenNextNode = -1;
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;
41094376    }
41104377    else
41114378    {
r245119r245120
41144381
41154382    // Framed header expand a little outside the default padding
41164383    const ImVec2 window_padding = window->WindowPadding();
4117    const ImVec2 text_size = CalcTextSize(label, NULL, true);
4384    const ImVec2 label_size = CalcTextSize(label, NULL, true);
41184385    const ImVec2 pos_min = window->DC.CursorPos;
41194386    const ImVec2 pos_max = window->Pos + GetContentRegionMax();
4120    ImGuiAabb bb = ImGuiAabb(pos_min, ImVec2(pos_max.x, pos_min.y + text_size.y));
4387    ImGuiAabb bb = ImGuiAabb(pos_min, ImVec2(pos_max.x, pos_min.y + label_size.y));
41214388    if (display_frame)
41224389    {
41234390        bb.Min.x -= window_padding.x*0.5f - 1;
r245119r245120
41254392        bb.Max.y += style.FramePadding.y * 2;
41264393    }
41274394
4128    const ImGuiAabb text_bb(bb.Min, bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2*2,0) + text_size);
4395    const ImGuiAabb text_bb(bb.Min, bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2*2,0) + label_size);
41294396    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
41304397
41314398    // When logging is enabled, if automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behaviour).
41324399    // NB- If we are above max depth we still allow manually opened nodes to be logged.
4133    if (!display_frame)
4134        if (g.LogEnabled && window->DC.TreeDepth < g.LogAutoExpandMaxDepth)
4135            opened = true;
4400    if (g.LogEnabled && !display_frame && window->DC.TreeDepth < g.LogAutoExpandMaxDepth)
4401        opened = true;
41364402
41374403    if (!ItemAdd(bb, &id))
41384404        return opened;
r245119r245120
41794445    return opened;
41804446}
41814447
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
41824470// Text with a little bullet aligned to the typical tree node.
41834471void ImGui::BulletTextV(const char* fmt, va_list args)
41844472{
r245119r245120
41874475    if (window->SkipItems)
41884476        return;
41894477
4190    const ImGuiStyle& style = g.Style;
4191
41924478    static char buf[1024];
41934479    const char* text_begin = buf;
41944480    const char* text_end = text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
41954481
4482    const ImGuiStyle& style = g.Style;
41964483    const float line_height = window->FontSize();
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
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
41994486    ItemSize(bb);
42004487    if (!ItemAdd(bb, NULL))
42014488        return;
r245119r245120
42754562    return TreeNode(str_label_id, "%s", str_label_id);
42764563}
42774564
4278void ImGui::OpenNextNode(bool open)
4565void ImGui::SetNextTreeNodeOpened(bool opened, ImGuiSetCond cond)
42794566{
4280    ImGuiWindow* window = GetCurrentWindow();
4281    window->DC.OpenNextNode = open ? 1 : 0;
4567    ImGuiState& g = *GImGui;
4568    g.SetNextTreeNodeOpenedVal = opened;
4569    g.SetNextTreeNodeOpenedCond = cond ? cond : ImGuiSetCond_Always;
42824570}
42834571
42844572void ImGui::PushID(const char* str_id)
r245119r245120
43224610// NB: only call right after InputText because we are using its InitialValue storage
43234611static void ApplyNumericalTextInput(const char* buf, float *v)
43244612{
4325    while (*buf == ' ' || *buf == '\t')
4613    while (ImCharIsSpace(*buf))
43264614        buf++;
43274615
43284616    // We don't support '-' op because it would conflict with inputing negative value.
r245119r245120
43314619    if (op == '+' || op == '*' || op == '/')
43324620    {
43334621        buf++;
4334        while (*buf == ' ' || *buf == '\t')
4622        while (ImCharIsSpace(*buf))
43354623            buf++;
43364624    }
43374625    else
r245119r245120
43954683        }
43964684    }
43974685
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);
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);
44004688    const ImGuiAabb slider_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
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));
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));
44024690
44034691    // NB- we don't call ItemSize() yet becausae we may turn into a text edit box later in the function
44044692    if (!ItemAdd(slider_bb, &id))
r245119r245120
44144702    const float grab_size_in_units = 1.0f;                                                              // In 'v' units. Probably needs to be parametrized, based on a 'v_step' value? decimal precision?
44154703    float grab_size_in_pixels;
44164704    if (decimal_precision > 0 || is_unbound)
4417        grab_size_in_pixels = 10.0f;
4705        grab_size_in_pixels = style.GrabMinSize;
44184706    else
4419        grab_size_in_pixels = ImMax(grab_size_in_units * (w / (v_max-v_min+1.0f)), 8.0f);               // Integer sliders
4707        grab_size_in_pixels = ImMax(grab_size_in_units * (w / (v_max-v_min+1.0f)), style.GrabMinSize);  // Integer sliders
44204708    const float slider_effective_w = slider_bb.GetWidth() - grab_size_in_pixels;
44214709    const float slider_effective_x1 = slider_bb.Min.x + grab_size_in_pixels*0.5f;
44224710    const float slider_effective_x2 = slider_bb.Max.x - grab_size_in_pixels*0.5f;
r245119r245120
44714759        if (g.SliderAsInputTextId == 0)
44724760        {
44734761            // First frame
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)
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)
44754763            g.SliderAsInputTextId = g.ActiveId;
4476            SetActiveId(id);
44774764            g.HoveredId = id;
44784765        }
4479        else
4766        else if (g.ActiveId != g.SliderAsInputTextId)
44804767        {
4481            if (g.ActiveId == g.SliderAsInputTextId)
4482                SetActiveId(id);
4483            else
4484            {
4485                SetActiveId(0);
4486                g.SliderAsInputTextId = 0;
4487            }
4768            // Release
4769            g.SliderAsInputTextId = 0;
44884770        }
44894771        if (value_changed)
44904772        {
r245119r245120
45794861
45804862    // Draw value using user-provided display format so user can add prefix/suffix/decorations to the value.
45814863    char value_buf[64];
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);
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);
45844867
45854868    RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, slider_bb.Min.y), label);
45864869
r245119r245120
47215004
47225005    const ImGuiStyle& style = g.Style;
47235006
4724    const ImVec2 text_size = ImGui::CalcTextSize(label, NULL, true);
5007    const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
47255008    if (graph_size.x == 0.0f)
47265009        graph_size.x = ImGui::CalcItemWidth();
47275010    if (graph_size.y == 0.0f)
4728        graph_size.y = text_size.y;
5011        graph_size.y = label_size.y;
47295012
47305013    const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y) + style.FramePadding*2.0f);
47315014    const ImGuiAabb graph_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
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));
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));
47335016    ItemSize(bb);
47345017    if (!ItemAdd(bb, NULL))
47355018        return;
r245119r245120
48545137
48555138    const ImGuiStyle& style = g.Style;
48565139    const ImGuiID id = window->GetID(label);
4857    const ImVec2 text_size = CalcTextSize(label, NULL, true);
5140    const ImVec2 label_size = CalcTextSize(label, NULL, true);
48585141
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));
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));
48605143    ItemSize(check_bb);
48615144
48625145    ImGuiAabb total_bb = check_bb;
4863    if (text_size.x > 0)
5146    if (label_size.x > 0)
48645147        SameLine(0, (int)style.ItemInnerSpacing.x);
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)
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)
48675150    {
48685151        ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()));
48695152        total_bb = ImGuiAabb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
r245119r245120
49125195
49135196    const ImGuiStyle& style = g.Style;
49145197    const ImGuiID id = window->GetID(label);
5198    const ImVec2 label_size = CalcTextSize(label, NULL, true);
49155199
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));
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));
49195201    ItemSize(check_bb);
49205202
49215203    ImGuiAabb total_bb = check_bb;
4922    if (text_size.x > 0)
5204    if (label_size.x > 0)
49235205        SameLine(0, (int)style.ItemInnerSpacing.x);
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)
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)
49265208    {
49275209        ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()));
49285210        total_bb.Add(text_bb);
r245119r245120
49885270    r->num_chars = (int)(text_remaining - (obj->Text + line_start_idx));
49895271}
49905272
4991static bool is_white(unsigned int c)                                                              { return c==0 || c==' ' || c=='\t' || c=='\r' || c=='\n'; }
49925273static bool is_separator(unsigned int c)                                                          { return c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|'; }
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'; }
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
49955290static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const ImWchar* new_text, int new_text_len)
49965291{
4997    const size_t text_len = ImStrlenW(obj->Text);
4998    if ((size_t)new_text_len + text_len + 1 >= obj->BufSize)
5292    const size_t text_len = obj->CurLenW;
5293    if ((size_t)new_text_len + text_len + 1 > IM_ARRAYSIZE(obj->Text))
49995294        return false;
50005295
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
50015300    if (pos != (int)text_len)
50025301        memmove(obj->Text + (size_t)pos + new_text_len, obj->Text + (size_t)pos, (text_len - (size_t)pos) * sizeof(ImWchar));
50035302    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';
50055303
5304    obj->CurLenW += new_text_len;
5305    obj->CurLenA += new_text_len_utf8;
5306    obj->Text[obj->CurLenW] = '\0';
5307
50065308    return true;
50075309}
50085310
r245119r245120
50965398    const char* text_start = GetTextPointerClippedA(font, font_size, buf, scroll_x, NULL);
50975399    const char* text_end = GetTextPointerClippedA(font, font_size, text_start, width, &text_size);
50985400
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
50995405    // Draw a little clip symbol if we've got text on either left or right of the box
51005406    const char symbol_c = '~';
51015407    const float symbol_w = font_size*0.40f;     // FIXME: compute correct width
51025408    const float clip_begin = (text_start > buf && text_start < text_end) ? symbol_w : 0.0f;
5103    const float clip_end = (text_end[0] != '\0' && text_end > text_start) ? symbol_w : 0.0f;
5409    const float clip_end = (text_end_char != 0 && text_end > text_start) ? symbol_w : 0.0f;
51045410
51055411    // Draw text
51065412    RenderText(pos+ImVec2(clip_begin,0), text_start+(clip_begin>0.0f?1:0), text_end-(clip_end>0.0f?1:0), false);
r245119r245120
51225428
51235429    const ImGuiStyle& style = g.Style;
51245430    const float w = ImGui::CalcItemWidth();
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);
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);
51275433
51285434    ImGui::PushID(label);
51295435    const float button_sz = window->FontSize();
r245119r245120
51635469
51645470    ImGui::PopID();
51655471
5166    if (text_size.x > 0)
5472    if (label_size.x > 0)
51675473    {
51685474        ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
5169        ItemSize(text_size);
5475        ItemSize(label_size);
51705476        RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
51715477    }
51725478
r245119r245120
52225528    SelectionStart = SelectionEnd = CursorPos;
52235529}
52245530
5225static bool InputTextFilterCharacter(ImWchar c, ImGuiInputTextFlags flags)
5531// Return false to discard a character.
5532static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data)
52265533{
5534    unsigned int c = *p_char;
5535
52275536    if (c < 128 && c != ' ' && !isprint((int)(c & 0xFF)))
5228        return true;
5537        return false;
52295538
52305539    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.
5231        return true;
5540        return false;
52325541
5233    if (flags & ImGuiInputTextFlags_CharsDecimal)
5234        if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/'))
5235            return true;
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;
52365547
5237    if (flags & ImGuiInputTextFlags_CharsHexadecimal)
5238        if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F'))
5239            return true;
5548        if (flags & ImGuiInputTextFlags_CharsHexadecimal)
5549            if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F'))
5550                return false;
52405551
5241    return false;
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;
52425577}
52435578
52445579// Edit a string of text
5245bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, void (*callback)(ImGuiTextEditCallbackData*), void* user_data)
5580bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data)
52465581{
52475582    ImGuiState& g = *GImGui;
52485583    ImGuiWindow* window = GetCurrentWindow();
r245119r245120
52555590    const ImGuiID id = window->GetID(label);
52565591    const float w = ImGui::CalcItemWidth();
52575592
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));
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));
52615596    ItemSize(bb);
52625597    if (!ItemAdd(frame_bb, &id))
52635598        return false;
r245119r245120
52675602
52685603    const bool is_ctrl_down = io.KeyCtrl;
52695604    const bool is_shift_down = io.KeyShift;
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
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;
52725608
52735609    const bool hovered = IsHovered(frame_bb, id);
52745610    if (hovered)
52755611        g.HoveredId = id;
5612    const bool user_clicked = hovered && io.MouseClicked[0];
52765613
52775614    bool select_all = (g.ActiveId != id) && (flags & ImGuiInputTextFlags_AutoSelectAll) != 0;
5278    if (tab_focus_requested || (hovered && io.MouseClicked[0]))
5615    if (focus_requested || user_clicked)
52795616    {
52805617        if (g.ActiveId != id)
52815618        {
52825619            // Start edition
52835620            // 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'
52845622            ImFormatString(edit_state.InitialText, IM_ARRAYSIZE(edit_state.InitialText), "%s", buf);
5285            ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), buf, NULL);
5286            edit_state.ScrollX = 0.0f;
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.
52875626            edit_state.Width = w;
5288            stb_textedit_initialize_state(&edit_state.StbState, true);
5627            edit_state.InputCursorScreenPos = ImVec2(-1.f,-1.f);
52895628            edit_state.CursorAnimReset();
5290            edit_state.LastCursorPos = ImVec2(-1.f,-1.f);
52915629
5292            if (tab_focus_requested || is_ctrl_down)
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))
52935647                select_all = true;
52945648        }
52955649        SetActiveId(id);
r245119r245120
53045658        }
53055659    }
53065660
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
53075666    bool value_changed = false;
53085667    bool cancel_edit = false;
53095668    bool enter_pressed = false;
r245119r245120
53115670    if (g.ActiveId == id)
53125671    {
53135672        // Edit in progress
5314        edit_state.BufSize = buf_size < IM_ARRAYSIZE(edit_state.Text) ? buf_size : IM_ARRAYSIZE(edit_state.Text);
5673        edit_state.BufSizeA = buf_size;
53155674        edit_state.Font = window->Font();
53165675        edit_state.FontSize = window->FontSize();
53175676
r245119r245120
53435702            // Process text input (before we check for Return because using some IME will effectively send a Return?)
53445703            for (int n = 0; n < IM_ARRAYSIZE(g.IO.InputCharacters) && g.IO.InputCharacters[n]; n++)
53455704            {
5346                const ImWchar c = g.IO.InputCharacters[n];
5705                unsigned int c = (unsigned int)g.IO.InputCharacters[n];
53475706                if (c)
53485707                {
53495708                    // Insert character if they pass filtering
5350                    if (InputTextFilterCharacter(c, flags))
5709                    if (!InputTextFilterCharacter(&c, flags, callback, user_data))
53515710                        continue;
5352                    edit_state.OnKeyPressed(c);
5711                    edit_state.OnKeyPressed((int)c);
53535712                }
53545713            }
53555714
r245119r245120
53795738            if (g.IO.SetClipboardTextFn)
53805739            {
53815740                const int ib = edit_state.HasSelection() ? ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end) : 0;
5382                const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : (int)ImStrlenW(edit_state.Text);
5741                const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : edit_state.CurLenW;
53835742                ImTextStrToUtf8(text_tmp_utf8, IM_ARRAYSIZE(text_tmp_utf8), edit_state.Text+ib, edit_state.Text+ie);
53845743                g.IO.SetClipboardTextFn(text_tmp_utf8);
53855744            }
r245119r245120
53955754                if (const char* clipboard = g.IO.GetClipboardTextFn())
53965755                {
53975756                    // Remove new-line from pasted buffer
5398                    size_t clipboard_len = strlen(clipboard);
5757                    const size_t clipboard_len = strlen(clipboard);
53995758                    ImWchar* clipboard_filtered = (ImWchar*)ImGui::MemAlloc((clipboard_len+1) * sizeof(ImWchar));
54005759                    int clipboard_filtered_len = 0;
54015760                    for (const char* s = clipboard; *s; )
54025761                    {
54035762                        unsigned int c;
5404                        const int bytes_count = ImTextCharFromUtf8(&c, s, NULL);
5405                        if (bytes_count <= 0)
5763                        s += ImTextCharFromUtf8(&c, s, NULL);
5764                        if (c == 0)
54065765                            break;
5407                        s += bytes_count;
54085766                        if (c >= 0x10000)
54095767                            continue;
5410                        if (InputTextFilterCharacter((ImWchar)c, flags))
5768                        if (!InputTextFilterCharacter(&c, flags, callback, user_data))
54115769                            continue;
54125770                        clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c;
54135771                    }
r245119r245120
54425800                IM_ASSERT(callback != NULL);
54435801
54445802                // 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;
54455804                ImGuiKey event_key = ImGuiKey_COUNT;
54465805                if ((flags & ImGuiInputTextFlags_CallbackCompletion) != 0 && IsKeyPressedMap(ImGuiKey_Tab))
5806                {
5807                    event_flag = ImGuiInputTextFlags_CallbackCompletion;
54475808                    event_key = ImGuiKey_Tab;
5809                }
54485810                else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_UpArrow))
5811                {
5812                    event_flag = ImGuiInputTextFlags_CallbackHistory;
54495813                    event_key = ImGuiKey_UpArrow;
5814                }
54505815                else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_DownArrow))
5816                {
5817                    event_flag = ImGuiInputTextFlags_CallbackHistory;
54515818                    event_key = ImGuiKey_DownArrow;
5819                }
54525820
54535821                if (event_key != ImGuiKey_COUNT || (flags & ImGuiInputTextFlags_CallbackAlways) != 0)
54545822                {
54555823                    ImGuiTextEditCallbackData callback_data;
5824                    callback_data.EventFlag = event_flag;
54565825                    callback_data.EventKey = event_key;
54575826                    callback_data.Buf = text_tmp_utf8;
5458                    callback_data.BufSize = edit_state.BufSize;
5827                    callback_data.BufSize = edit_state.BufSizeA;
54595828                    callback_data.BufDirty = false;
54605829                    callback_data.Flags = flags;
54615830                    callback_data.UserData = user_data;
54625831
54635832                    // We have to convert from position from wchar to UTF-8 positions
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);
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);
54675836
54685837                    // Call user code
54695838                    callback(&callback_data);
54705839
54715840                    // Read back what user may have modified
54725841                    IM_ASSERT(callback_data.Buf == text_tmp_utf8);             // Invalid to modify those fields
5473                    IM_ASSERT(callback_data.BufSize == edit_state.BufSize);
5842                    IM_ASSERT(callback_data.BufSize == edit_state.BufSizeA);
54745843                    IM_ASSERT(callback_data.Flags == flags);
54755844                    if (callback_data.CursorPos != utf8_cursor_pos)            edit_state.StbState.cursor = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.CursorPos);
54765845                    if (callback_data.SelectionStart != utf8_selection_start)  edit_state.StbState.select_start = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionStart);
r245119r245120
55095878        }
55105879    }
55115880
5512    // FIXME: 'align_center' unsupported
55135881    ImGuiTextEditState::RenderTextScrolledClipped(window->Font(), window->FontSize(), buf, frame_bb.Min + style.FramePadding, w, (g.ActiveId == id) ? edit_state.ScrollX : 0.0f);
55145882
55155883    if (g.ActiveId == id)
r245119r245120
55205888        if (g.InputTextState.CursorIsVisible())
55215889            window->DrawList->AddRect(cursor_pos - font_off_up + ImVec2(0,2), cursor_pos + font_off_dn - ImVec2(0,3), window->Color(ImGuiCol_Text));
55225890
5523        // Notify OS of text input position
5524        if (io.ImeSetInputScreenPosFn && ImLengthSqr(edit_state.LastCursorPos - cursor_pos) > 0.0001f)
5891        // Notify OS of text input position for advanced IME
5892        if (io.ImeSetInputScreenPosFn && ImLengthSqr(edit_state.InputCursorScreenPos - cursor_pos) > 0.0001f)
55255893            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.
55265894
5527        edit_state.LastCursorPos = cursor_pos;
5895        edit_state.InputCursorScreenPos = cursor_pos;
55285896    }
55295897
5530    RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
5898    if (label_size.x > 0)
5899        RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
55315900
55325901    if ((flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0)
55335902        return enter_pressed;
r245119r245120
56466015    const ImGuiID id = window->GetID(label);
56476016    const float w = ImGui::CalcItemWidth();
56486017
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);
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);
56526022    if (!ItemAdd(frame_bb, &id))
56536023        return false;
56546024
5655    const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x,0));
56566025    const float arrow_size = (window->FontSize() + style.FramePadding.x * 2.0f);
56576026    const bool hovered = IsHovered(frame_bb, id);
56586027
r245119r245120
56696038            RenderTextClipped(frame_bb.Min + style.FramePadding, item_text, NULL, NULL, value_bb.Max);
56706039    }
56716040
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    }
6041    if (label_size.x > 0)
6042        RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
56786043
56796044    ImGui::PushID((int)id);
56806045    bool menu_toggled = false;
r245119r245120
56986063
56996064        const ImVec2 backup_pos = ImGui::GetCursorPos();
57006065        const float popup_off_x = 0.0f;//style.ItemInnerSpacing.x;
5701        const float popup_height = (text_size.y + style.ItemSpacing.y) * ImMin(items_count, height_in_items) + style.WindowPadding.y;
6066        const float popup_height = (label_size.y + style.ItemSpacing.y) * ImMin(items_count, height_in_items) + style.WindowPadding.y;
57026067        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));
57036068        ImGui::SetCursorPos(popup_aabb.Min - window->Pos);
57046069
r245119r245120
57526117
57536118    const ImGuiStyle& style = g.Style;
57546119    const ImGuiID id = window->GetID(label);
5755    const ImVec2 text_size = CalcTextSize(label, NULL, true);
6120    const ImVec2 label_size = CalcTextSize(label, NULL, true);
57566121
57576122    const float w = window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x;
5758    const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : w, size_arg.y != 0.0f ? size_arg.y : text_size.y);
6123    const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : w, size_arg.y != 0.0f ? size_arg.y : label_size.y);
57596124    const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size);
57606125    ItemSize(bb);
57616126
r245119r245120
57836148    }
57846149
57856150    //const ImVec2 off = ImVec2(ImMax(0.0f, size.x - text_size.x) * 0.5f, ImMax(0.0f, size.y - text_size.y) * 0.5f);
5786    RenderTextClipped(bb.Min, label, NULL, &text_size, bb_with_spacing.Max);
6151    RenderTextClipped(bb.Min, label, NULL, &label_size, bb_with_spacing.Max);
57876152
57886153    return pressed;
57896154}
r245119r245120
58036168bool ImGui::ListBoxHeader(const char* label, const ImVec2& size_arg)
58046169{
58056170    ImGuiWindow* window = GetCurrentWindow();
5806    if (window->SkipItems)
5807        return false;
58086171
58096172    const ImGuiStyle& style = ImGui::GetStyle();
58106173    const ImGuiID id = ImGui::GetID(label);
r245119r245120
58166179    size.y = (size_arg.y != 0.0f) ? size_arg.y : ImGui::GetTextLineHeightWithSpacing() * 7.4f + style.ItemSpacing.y;
58176180    const ImVec2 frame_size = ImVec2(size.x, ImMax(size.y, label_size.y));
58186181    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;
58196184
58206185    if (label_size.x > 0)
58216186        RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
r245119r245120
58426207
58436208void ImGui::ListBoxFooter()
58446209{
6210    ImGuiWindow* parent_window = GetParentWindow();
6211    const ImGuiAabb bb = parent_window->DC.LastItemAabb;
6212
58456213    ImGui::EndChildFrame();
6214
6215    parent_window->DC.CursorPos = bb.Min;
6216    ItemSize(bb, NULL);
58466217}
58476218
58486219bool ImGui::ListBox(const char* label, int* current_item, const char** items, int items_count, int height_items)
r245119r245120
58536224
58546225bool ImGui::ListBox(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int height_in_items)
58556226{
6227    ImGuiWindow* window = GetCurrentWindow();
6228    if (window->SkipItems)
6229        return false;
6230
58566231    if (!ImGui::ListBoxHeader(label, items_count, height_in_items))
58576232        return false;
58586233
r245119r245120
58866261        return false;
58876262
58886263    const ImGuiStyle& style = g.Style;
5889    const ImGuiID id = window->GetID("##colorbutton");
6264    const ImGuiID id = window->GetID("#colorbutton");
58906265    const float square_size = window->FontSize();
58916266    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)));
58926267    ItemSize(bb);
r245119r245120
60066381            value_changed |= ImGui::InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal);
60076382            ImGui::PopItemWidth();
60086383            char* p = buf;
6009            while (*p == '#' || *p == ' ' || *p == '\t')
6384            while (*p == '#' || ImCharIsSpace(*p))
60106385                p++;
60116386
60126387            // Treat at unsigned (%X is unsigned)
r245119r245120
60946469    window->DrawList->AddLine(bb.Min, bb.Max, window->Color(ImGuiCol_Border));
60956470
60966471    if (window->DC.ColumnsCount > 1)
6472    {
60976473        PushColumnClipRect();
6474        window->DC.ColumnsCellMinY = window->DC.CursorPos.y;
6475    }
60986476}
60996477
61006478// A little vertical spacing.
r245119r245120
61236501    window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y);
61246502    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));
61256503
6126    window->SizeContentsFit = ImMax(window->SizeContentsFit, ImVec2(window->DC.CursorPosPrevLine.x, window->DC.CursorPos.y) - window->Pos + ImVec2(0.0f, window->ScrollY));
6504    window->SizeContentsCurrent = ImMax(window->SizeContentsCurrent, ImVec2(window->DC.CursorPosPrevLine.x - window->Pos.x, window->DC.CursorPos.y + window->ScrollY - window->Pos.y));
61276505
61286506    window->DC.PrevLineHeight = line_height;
61296507    window->DC.CurrentLineHeight = 0.0f;
61306508}
61316509
6132static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset)
6510static void ItemSize(const ImGuiAabb& bb, ImVec2* adjust_start_offset)
61336511{
6134    ItemSize(aabb.GetSize(), adjust_start_offset);
6512    ItemSize(bb.GetSize(), adjust_start_offset);
61356513}
61366514
61376515static bool IsClipped(const ImGuiAabb& bb)
r245119r245120
61606538        window->DC.LastItemHovered = false;
61616539        return false;
61626540    }
6163    window->DC.LastItemHovered = IsMouseHoveringBox(bb);     // this is a sensible default but widgets are free to override it after calling ItemAdd()
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;
61646546    return true;
61656547}
61666548
r245119r245120
62256607    }
62266608}
62276609
6228// FIMXE-OPT: This is called too often. We need to cache offset for active columns set.
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
62296622float ImGui::GetColumnOffset(int column_index)
62306623{
62316624    ImGuiState& g = *GImGui;
r245119r245120
62336626    if (column_index < 0)
62346627        column_index = window->DC.ColumnsCurrent;
62356628
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?)
6629    // Read from cache
6630    IM_ASSERT(column_index < (int)window->DC.ColumnsOffsetsT.size());
6631    const float t = window->DC.ColumnsOffsetsT[column_index];
62406632
6241    const float offset = window->DC.ColumnsStartX + t * (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnsStartX);
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);
62426636    return offset;
62436637}
62446638
r245119r245120
62496643    if (column_index < 0)
62506644        column_index = window->DC.ColumnsCurrent;
62516645
6646    IM_ASSERT(column_index < (int)window->DC.ColumnsOffsetsT.size());
62526647    const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
6253    const float t = (offset - window->DC.ColumnsStartX) / (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnsStartX);
6254    window->StateStorage.SetFloat(column_id, t);
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;
62556654}
62566655
62576656float ImGui::GetColumnWidth(int column_index)
r245119r245120
62796678{
62806679    ImGuiState& g = *GImGui;
62816680    ImGuiWindow* window = GetCurrentWindow();
6282    if (window->SkipItems)
6283        return;
62846681
62856682    if (window->DC.ColumnsCount != 1)
62866683    {
r245119r245120
62946691    }
62956692
62966693    // Draw columns borders and handle resize at the time of "closing" a columns set
6297    if (window->DC.ColumnsCount != columns_count && window->DC.ColumnsCount != 1 && window->DC.ColumnsShowBorders)
6694    if (window->DC.ColumnsCount != columns_count && window->DC.ColumnsCount != 1 && window->DC.ColumnsShowBorders && !window->SkipItems)
62986695    {
62996696        const float y1 = window->DC.ColumnsStartPos.y;
63006697        const float y2 = window->DC.CursorPos.y;
r245119r245120
63386735
63396736    if (window->DC.ColumnsCount != 1)
63406737    {
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
63416749        PushColumnClipRect();
63426750        ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f);
63436751    }
6752    else
6753    {
6754        window->DC.ColumnsOffsetsT.resize(2);
6755        window->DC.ColumnsOffsetsT[0] = 0.0f;
6756        window->DC.ColumnsOffsetsT[1] = 1.0f;
6757    }
63446758}
63456759
63466760void ImGui::TreePush(const char* str_id)
r245119r245120
71467560    TexUvWhitePixel = ImVec2((TexExtraDataPos.x + 0.5f) / TexWidth, (TexExtraDataPos.y + 0.5f) / TexHeight);
71477561
71487562    // Draw a mouse cursor into texture
7149    // Because our font uses an alpha texture, we have to spread the cursor in 2 parts (black/white) which will be rendered separately.
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.
71507564    const char cursor_pixels[] =
71517565    {
71527566        "X           "
r245119r245120
71957609    DisplayOffset = ImVec2(-0.5f, 0.5f);
71967610    ContainerAtlas = NULL;
71977611    Glyphs.clear();
7612    FallbackGlyph = NULL;
7613    FallbackXAdvance = 0.0f;
7614    IndexXAdvance.clear();
71987615    IndexLookup.clear();
7199    FallbackGlyph = NULL;
72007616}
72017617
72027618// Retrieve list of range (2 int per range, values are inclusive)
r245119r245120
72157631    static const ImWchar ranges[] =
72167632    {
72177633        0x0020, 0x00FF, // Basic Latin + Latin Supplement
7218        0x3040, 0x309F, // Hiragana, Katakana
7634        0x3000, 0x30FF, // Punctuations, Hiragana, Katakana
7635        0x31F0, 0x31FF, // Katakana Phonetic Extensions
72197636        0xFF00, 0xFFEF, // Half-width characters
72207637        0x4e00, 0x9FAF, // CJK Ideograms
72217638        0,
r245119r245120
72637680        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,
72647681    };
72657682    static int ranges_unpacked = false;
7266    static ImWchar ranges[6 + 1 + IM_ARRAYSIZE(offsets_from_0x4E00)*2] =
7683    static ImWchar ranges[8 + IM_ARRAYSIZE(offsets_from_0x4E00)*2 + 1] =
72677684    {
72687685        0x0020, 0x00FF, // Basic Latin + Latin Supplement
7269        0x3040, 0x309F, // Hiragana, Katakana
7686        0x3000, 0x30FF, // Punctuations, Hiragana, Katakana
7687        0x31F0, 0x31FF, // Katakana Phonetic Extensions
72707688        0xFF00, 0xFFEF, // Half-width characters
7271        0,
72727689    };
72737690    if (!ranges_unpacked)
72747691    {
72757692        // Unpack
72767693        int codepoint = 0x4e00;
7277        ImWchar* dst = &ranges[6];
7694        ImWchar* dst = &ranges[8];
72787695        for (int n = 0; n < IM_ARRAYSIZE(offsets_from_0x4E00); n++, dst += 2)
72797696            dst[0] = dst[1] = (ImWchar)(codepoint += (offsets_from_0x4E00[n] + 1));
72807697        dst[0] = 0;
r245119r245120
72897706    for (size_t i = 0; i != Glyphs.size(); i++)
72907707        max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint);
72917708
7709    IndexXAdvance.clear();
7710    IndexXAdvance.resize((size_t)max_codepoint + 1);
72927711    IndexLookup.clear();
72937712    IndexLookup.resize((size_t)max_codepoint + 1);
7294    for (size_t i = 0; i < IndexLookup.size(); i++)
7713    for (size_t i = 0; i < (size_t)max_codepoint + 1; i++)
7714    {
7715        IndexXAdvance[i] = -1.0f;
72957716        IndexLookup[i] = -1;
7717    }
72967718    for (size_t i = 0; i < Glyphs.size(); i++)
7297        IndexLookup[(int)Glyphs[i].Codepoint] = (int)i;
7719    {
7720        const size_t codepoint = (int)Glyphs[i].Codepoint;
7721        IndexXAdvance[codepoint] = Glyphs[i].XAdvance;
7722        IndexLookup[codepoint] = (int)i;
7723    }
72987724
72997725    // Create a glyph to handle TAB
73007726    // FIXME: Needs proper TAB handling but it needs to be contextualized (can arbitrary say that each string starts at "column 0"
7301    if (const ImFont::Glyph* space_glyph = FindGlyph((unsigned short)' '))
7727    if (FindGlyph((unsigned short)' '))
73027728    {
7303        Glyphs.resize(Glyphs.size() + 1);
7729        if (Glyphs.back().Codepoint != '\t')   // So we can call this function multiple times
7730            Glyphs.resize(Glyphs.size() + 1);
73047731        ImFont::Glyph& tab_glyph = Glyphs.back();
7305        tab_glyph = *space_glyph;
7732        tab_glyph = *FindGlyph((unsigned short)' ');
73067733        tab_glyph.Codepoint = '\t';
73077734        tab_glyph.XAdvance *= 4;
7308        IndexLookup[(int)tab_glyph.Codepoint] = (int)(Glyphs.size()-1);
7735        IndexXAdvance[(size_t)tab_glyph.Codepoint] = (float)tab_glyph.XAdvance;
7736        IndexLookup[(size_t)tab_glyph.Codepoint] = (int)(Glyphs.size()-1);
73097737    }
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;
73107745}
73117746
7747void ImFont::SetFallbackChar(ImWchar c)
7748{
7749    FallbackChar = c;
7750    BuildLookupTable();
7751}
7752
73127753const ImFont::Glyph* ImFont::FindGlyph(unsigned short c) const
73137754{
73147755    if (c < (int)IndexLookup.size())
r245119r245120
73227763
73237764// Convert UTF-8 to 32-bits character, process single character input.
73247765// Based on stb_from_utf8() from github.com/nothings/stb/
7766// We handle UTF-8 decoding error by skipping forward.
73257767static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end)
73267768{
7327    if (*in_text != 0)
7769    unsigned int c = (unsigned int)-1;
7770    const unsigned char* str = (const unsigned char*)in_text;
7771    if (!(*str & 0x80))
73287772    {
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        }
7773        c = (unsigned int)(*str++);
7774        *out_char = c;
7775        return 1;
73787776    }
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    }
73797821    *out_char = 0;
73807822    return 0;
73817823}
73827824
7383static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end)
7825static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end, const char** in_text_remaining)
73847826{
73857827    ImWchar* buf_out = buf;
73867828    ImWchar* buf_end = buf + buf_size;
r245119r245120
73887830    {
73897831        unsigned int c;
73907832        in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
7833        if (c == 0)
7834            break;
73917835        if (c < 0x10000)    // FIXME: Losing characters that don't fit in 2 bytes
73927836            *buf_out++ = (ImWchar)c;
73937837    }
73947838    *buf_out = 0;
7839    if (in_text_remaining)
7840        *in_text_remaining = in_text;
73957841    return buf_out - buf;
73967842}
73977843
r245119r245120
74027848    {
74037849        unsigned int c;
74047850        in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
7851        if (c == 0)
7852            break;
74057853        if (c < 0x10000)
74067854            char_count++;
74077855    }
r245119r245120
74667914    return buf_out - buf;
74677915}
74687916
7469static int ImTextCountUtf8BytesFromWchar(const ImWchar* in_text, const ImWchar* in_text_end)
7917static int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end)
74707918{
74717919    int bytes_count = 0;
74727920    while ((!in_text_end || in_text < in_text_end) && *in_text)
r245119r245120
75067954    const char* s = text;
75077955    while (s < text_end)
75087956    {
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);
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;
75127965
75137966        if (c == '\n')
75147967        {
r245119r245120
75187971            continue;
75197972        }
75207973
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')
7974        const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance;
7975        if (ImCharIsSpace(c))
75267976        {
75277977            if (inside_word)
75287978            {
r245119r245120
76048054                while (s < text_end)
76058055                {
76068056                    const char c = *s;
7607                    if (c == ' ' || c == '\t') { s++; } else if (c == '\n') { s++; break; } else { break; }
8057                    if (ImCharIsSpace(c)) { s++; } else if (c == '\n') { s++; break; } else { break; }
76088058                }
76098059                continue;
76108060            }
76118061        }
76128062
76138063        // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
7614        unsigned int c;
7615        const int bytes_count = ImTextCharFromUtf8(&c, s, text_end);
7616        s += bytes_count > 0 ? bytes_count : 1;
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        }
76178075
76188076        if (c == '\n')
76198077        {
r245119r245120
76238081            continue;
76248082        }
76258083
7626        float char_width = 0.0f;
7627        if (const Glyph* glyph = FindGlyph((unsigned short)c))
7628            char_width = glyph->XAdvance * scale;
7629
8084        const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance;
76308085        if (line_width + char_width >= max_width)
76318086            break;
76328087
r245119r245120
76708125            continue;
76718126        }
76728127
7673        float char_width = 0.0f;
7674        if (const Glyph* glyph = FindGlyph((unsigned short)c))
7675            char_width = glyph->XAdvance * scale;
7676
8128        const float char_width = ((size_t)c < IndexXAdvance.size()) ? IndexXAdvance[(size_t)c] * scale : FallbackXAdvance;
76778129        if (line_width + char_width >= max_width)
76788130            break;
76798131
r245119r245120
77408192                while (s < text_end)
77418193                {
77428194                    const char c = *s;
7743                    if (c == ' ' || c == '\t') { s++; } else if (c == '\n') { s++; break; } else { break; }
8195                    if (ImCharIsSpace(c)) { s++; } else if (c == '\n') { s++; break; } else { break; }
77448196                }
77458197                continue;
77468198            }
77478199        }
77488200
77498201        // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
7750        unsigned int c;
7751        const int bytes_count = ImTextCharFromUtf8(&c, s, text_end);
7752        s += bytes_count > 0 ? bytes_count : 1;
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        }
77538213
77548214        if (c == '\n')
77558215        {
r245119r245120
78318291
78328292#if defined(_MSC_VER) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS)
78338293
8294#ifndef _WINDOWS_
78348295#define WIN32_LEAN_AND_MEAN
78358296#include <windows.h>
8297#endif
78368298
78378299// Win32 API clipboard implementation
7838static const char* GetClipboardTextFn_DefaultImpl()
8300static const char* GetClipboardTextFn_DefaultImpl()
78398301{
78408302    static char* buf_local = NULL;
78418303    if (buf_local)
r245119r245120
78458307    }
78468308    if (!OpenClipboard(NULL))
78478309        return NULL;
7848    HANDLE buf_handle = GetClipboardData(CF_TEXT);
7849    if (buf_handle == NULL)
8310    HANDLE wbuf_handle = GetClipboardData(CF_UNICODETEXT);
8311    if (wbuf_handle == NULL)
78508312        return NULL;
7851    if (char* buf_global = (char*)GlobalLock(buf_handle))
7852        buf_local = ImStrdup(buf_global);
7853    GlobalUnlock(buf_handle);
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);
78548320    CloseClipboard();
78558321    return buf_local;
78568322}
r245119r245120
78608326{
78618327    if (!OpenClipboard(NULL))
78628328        return;
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)
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)
78678333        return;
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);
8334    ImWchar* wbuf_global = (ImWchar*)GlobalLock(wbuf_handle);
8335    ImTextStrFromUtf8(wbuf_global, wbuf_length, text, NULL);
8336    GlobalUnlock(wbuf_handle);
78728337    EmptyClipboard();
7873    SetClipboardData(CF_TEXT, buf_handle);
8338    SetClipboardData(CF_UNICODETEXT, wbuf_handle);
78748339    CloseClipboard();
78758340}
78768341
78778342#else
78788343
78798344// Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
7880static const char* GetClipboardTextFn_DefaultImpl()
8345static const char* GetClipboardTextFn_DefaultImpl()
78818346{
78828347    return GImGui->PrivateClipboard;
78838348}
r245119r245120
78998364
79008365#endif
79018366
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
79028398//-----------------------------------------------------------------------------
79038399// HELP
79048400//-----------------------------------------------------------------------------
r245119r245120
79578453        ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f");
79588454        ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 10.0f, "%.0f");
79598455        ImGui::SliderFloat("TreeNodeSpacing", &style.TreeNodeSpacing, 0.0f, 20.0f, "%.0f");
7960        ImGui::SliderFloat("ScrollBarWidth", &style.ScrollBarWidth, 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");
79618458        ImGui::TreePop();
79628459    }
79638460
r245119r245120
80288525static void ShowExampleAppLongText(bool* opened);
80298526static void ShowExampleAppAutoResize(bool* opened);
80308527static void ShowExampleAppFixedOverlay(bool* opened);
8528static void ShowExampleAppManipulatingWindowTitle(bool* opened);
80318529static void ShowExampleAppCustomRendering(bool* opened);
80328530
80338531// Demonstrate ImGui features (unfortunately this makes this function a little bloated!)
80348532void ImGui::ShowTestWindow(bool* opened)
80358533{
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
80368554    static bool no_titlebar = false;
80378555    static bool no_border = true;
80388556    static bool no_resize = false;
80398557    static bool no_move = false;
80408558    static bool no_scrollbar = false;
80418559    static bool no_collapse = false;
8042    static float fill_alpha = 0.65f;
8560    static float bg_alpha = 0.65f;
80438561
80448562    // Demonstrate the various window flags. Typically you would just use the default.
80458563    ImGuiWindowFlags window_flags = 0;
r245119r245120
80498567    if (no_move)      window_flags |= ImGuiWindowFlags_NoMove;
80508568    if (no_scrollbar) window_flags |= ImGuiWindowFlags_NoScrollbar;
80518569    if (no_collapse)  window_flags |= ImGuiWindowFlags_NoCollapse;
8052    if (!ImGui::Begin("ImGui Test", opened, ImVec2(550,680), fill_alpha, window_flags))
8570    if (!ImGui::Begin("ImGui Test", opened, ImVec2(550,680), bg_alpha, window_flags))
80538571    {
80548572        // Early out if the window is collapsed, as an optimization.
80558573        ImGui::End();
80568574        return;
80578575    }
8058    ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f);
80598576
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
80608580    ImGui::Text("ImGui says hello.");
80618581    //ImGui::Text("MousePos (%g, %g)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
80628582    //ImGui::Text("MouseWheel %d", ImGui::GetIO().MouseWheel);
r245119r245120
80788598        ImGui::Checkbox("no move", &no_move); ImGui::SameLine(150);
80798599        ImGui::Checkbox("no scrollbar", &no_scrollbar); ImGui::SameLine(300);
80808600        ImGui::Checkbox("no collapse", &no_collapse);
8081        ImGui::SliderFloat("fill alpha", &fill_alpha, 0.0f, 1.0f);
8601        ImGui::SliderFloat("bg alpha", &bg_alpha, 0.0f, 1.0f);
80828602
80838603        if (ImGui::TreeNode("Style"))
80848604        {
r245119r245120
81498669        {
81508670            ImGui::BulletText("Bullet point 1");
81518671            ImGui::BulletText("Bullet point 2\nOn multiple lines");
8152            ImGui::BulletText("Bullet point 3");
8672            ImGui::Bullet(); ImGui::Text("Bullet point 3 (two calls)");
8673            ImGui::Bullet(); ImGui::SmallButton("Button 1");
8674            ImGui::Bullet(); ImGui::SmallButton("Button 2");
81538675            ImGui::TreePop();
81548676        }
81558677
r245119r245120
82918813            ImGui::TreePop();
82928814        }
82938815
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
82948828        static bool check = true;
82958829        ImGui::Checkbox("checkbox", &check);
82968830
r245119r245120
83928926        static int listbox_item_current = 1;
83938927        ImGui::ListBox("listbox\n(single select)", &listbox_item_current, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
83948928
8929        //static int listbox_item_current2 = 2;
83958930        //ImGui::PushItemWidth(-1);
83968931        //ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
83978932        //ImGui::PopItemWidth();
r245119r245120
84558990        ImGui::SameLine();
84568991        ImGui::Checkbox("Rich", &c4);
84578992
8458        // SliderFloat
8993        // Various
84598994        static float f0=1.0f, f1=2.0f, f2=3.0f;
84608995        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();
84619000        ImGui::SliderFloat("X", &f0, 0.0f,5.0f);
84629001        ImGui::SameLine();
84639002        ImGui::SliderFloat("Y", &f1, 0.0f,5.0f);
84649003        ImGui::SameLine();
84659004        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();
84669019    }
84679020
84689021    if (ImGui::CollapsingHeader("Child regions"))
r245119r245120
85059058
85069059    if (ImGui::CollapsingHeader("Columns"))
85079060    {
8508        ImGui::Columns(4, "data", true);
9061        // Basic columns
9062        ImGui::Text("Basic:");
9063        ImGui::Columns(4, "mycolumns");
85099064        ImGui::Text("ID"); ImGui::NextColumn();
85109065        ImGui::Text("Name"); ImGui::NextColumn();
85119066        ImGui::Text("Path"); ImGui::NextColumn();
85129067        ImGui::Text("Flags"); ImGui::NextColumn();
85139068        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);
85149079
8515        ImGui::Text("0000"); ImGui::NextColumn();
8516        ImGui::Text("Robert"); ImGui::NextColumn();
8517        ImGui::Text("/path/robert"); ImGui::NextColumn();
8518        ImGui::Text("...."); ImGui::NextColumn();
9080        ImGui::Separator();
9081        ImGui::Spacing();
85199082
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();
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();
85299091        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();
85309104
85319105        ImGui::Separator();
9106        ImGui::Spacing();
9107      */
85329108
9109        // Create multiple items in a same cell before switching to next column
9110        ImGui::Text("Mixed items:");
85339111        ImGui::Columns(3, "mixed");
9112        ImGui::Separator();
85349113
8535        // Create multiple items in a same cell because switching to next column
85369114        static int e = 0;
85379115        ImGui::Text("Hello");
85389116        ImGui::Button("Banana");
r245119r245120
85429120        ImGui::Text("ImGui");
85439121        ImGui::Button("Apple");
85449122        ImGui::RadioButton("radio b", &e, 1);
9123        static float foo = 1.0f;
9124        ImGui::InputFloat("red", &foo, 0.05f, 0, 3);
85459125        ImGui::Text("An extra line here.");
85469126        ImGui::NextColumn();
85479127
85489128        ImGui::Text("World!");
85499129        ImGui::Button("Corniflower");
85509130        ImGui::RadioButton("radio c", &e, 2);
9131        static float bar = 1.0f;
9132        ImGui::InputFloat("blue", &bar, 0.05f, 0, 3);
85519133        ImGui::NextColumn();
85529134
85539135        if (ImGui::CollapsingHeader("Category A")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
85549136        if (ImGui::CollapsingHeader("Category B")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
85559137        if (ImGui::CollapsingHeader("Category C")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
8556
85579138        ImGui::Columns(1);
85589139
85599140        ImGui::Separator();
9141        ImGui::Spacing();
85609142
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();
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();
85669149        ImGui::Columns(1);
85679150
85689151        ImGui::Separator();
9152        ImGui::Spacing();
85699153
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);
9154        // Word-wrapping
9155        ImGui::Text("Word-wrapping:");
9156        ImGui::Columns(2, "word-wrapping");
85749157        ImGui::Separator();
8575
8576        ImGui::Columns(2, "word wrapping");
85779158        ImGui::TextWrapped("The quick brown fox jumps over the lazy dog.");
85789159        ImGui::Text("Hello Left");
85799160        ImGui::NextColumn();
r245119r245120
85829163        ImGui::Columns(1);
85839164
85849165        ImGui::Separator();
9166        ImGui::Spacing();
85859167
85869168        if (ImGui::TreeNode("Inside a tree.."))
85879169        {
85889170            if (ImGui::TreeNode("node 1 (with borders)"))
85899171            {
85909172                ImGui::Columns(4);
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();
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                }
85999178                ImGui::Columns(1);
86009179                ImGui::TreePop();
86019180            }
86029181            if (ImGui::TreeNode("node 2 (without borders)"))
86039182            {
86049183                ImGui::Columns(4, NULL, false);
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();
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                }
86139189                ImGui::Columns(1);
86149190                ImGui::TreePop();
86159191            }
r245119r245120
86749250                ImGui::Text("Item with focus: %d", has_focus);
86759251            else
86769252                ImGui::Text("Item with focus: <none>");
9253            ImGui::TextWrapped("Cursor & selection are preserved when refocusing last used item in code.");
86779254            ImGui::TreePop();
86789255        }
86799256    }
86809257
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;
86869258    if (ImGui::CollapsingHeader("App Examples"))
86879259    {
86889260        ImGui::Checkbox("Console", &show_app_console);
86899261        ImGui::Checkbox("Long text display", &show_app_long_text);
86909262        ImGui::Checkbox("Auto-resizing window", &show_app_auto_resize);
86919263        ImGui::Checkbox("Simple overlay", &show_app_fixed_overlay);
9264        ImGui::Checkbox("Manipulating window title", &show_app_manipulating_window_title);
86929265        ImGui::Checkbox("Custom rendering", &show_app_custom_rendering);
86939266    }
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);
87049267
87059268    ImGui::End();
87069269}
r245119r245120
87389301    ImGui::End();
87399302}
87409303
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
87419329static void ShowExampleAppCustomRendering(bool* opened)
87429330{
9331    ImGui::SetNextWindowSize(ImVec2(300,350), ImGuiSetCond_FirstUseEver);
87439332    if (!ImGui::Begin("Example: Custom Rendering", opened))
87449333    {
87459334        ImGui::End();
r245119r245120
87549343    static ImVector<ImVec2> points;
87559344    static bool adding_line = false;
87569345    if (ImGui::Button("Clear")) points.clear();
8757    if (points.size() > 2) { ImGui::SameLine(); if (ImGui::Button("Undo")) points.pop_back(); }
9346    if (points.size() >= 2) { ImGui::SameLine(); if (ImGui::Button("Undo")) { points.pop_back(); points.pop_back(); } }
87589347    ImGui::Text("Left-click and drag to add lines");
87599348    ImGui::Text("Right-click to undo");
87609349
r245119r245120
88609449        if (ImGui::SmallButton("Add Dummy Text")) { AddLog("%d some text", Items.size()); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine();
88619450        if (ImGui::SmallButton("Add Dummy Error")) AddLog("[error] something went wrong"); ImGui::SameLine();
88629451        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
88639454        ImGui::Separator();
88649455
88659456        ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0));
r245119r245120
89459536        }
89469537    }
89479538
8948    static void TextEditCallbackStub(ImGuiTextEditCallbackData* data)
9539    static int TextEditCallbackStub(ImGuiTextEditCallbackData* data)
89499540    {
89509541        ExampleAppConsole* console = (ExampleAppConsole*)data->UserData;
8951        console->TextEditCallback(data);
9542        return console->TextEditCallback(data);
89529543    }
89539544
8954    void    TextEditCallback(ImGuiTextEditCallbackData* data)
9545    int     TextEditCallback(ImGuiTextEditCallbackData* data)
89559546    {
89569547        //AddLog("cursor: %d, selection: %d-%d", data->CursorPos, data->SelectionStart, data->SelectionEnd);
8957        switch (data->EventKey)
9548        switch (data->EventFlag)
89589549        {
8959        case ImGuiKey_Tab:
9550        case ImGuiInputTextFlags_CallbackCompletion:
89609551            {
89619552                // Example of TEXT COMPLETION
89629553
r245119r245120
89669557                while (word_start > data->Buf)
89679558                {
89689559                    const char c = word_start[-1];
8969                    if (c == ' ' || c == '\t' || c == ',' || c == ';')
9560                    if (ImCharIsSpace(c) || c == ',' || c == ';')
89709561                        break;
89719562                    word_start--;
89729563                }
r245119r245120
90219612
90229613                break;
90239614            }
9024        case ImGuiKey_UpArrow:
9025        case ImGuiKey_DownArrow:
9615        case ImGuiInputTextFlags_CallbackHistory:
90269616            {
90279617                // Example of HISTORY
90289618                const int prev_history_pos = HistoryPos;
r245119r245120
90499639                }
90509640            }
90519641        }
9642        return 0;
90529643    }
90539644};
90549645
trunk/3rdparty/bgfx/3rdparty/ocornut-imgui/imgui.h
r245119r245120
1// ImGui library v1.32 wip
1// ImGui library v1.35
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.
r245119r245120
66
77#pragma once
88
9struct ImDrawCmd;
10struct ImDrawList;
11struct ImFont;
12struct ImFontAtlas;
13struct ImGuiAabb;
14struct ImGuiIO;
15struct ImGuiStorage;
16struct ImGuiStyle;
17struct ImGuiWindow;
18
19#include "imconfig.h"
9#include "imconfig.h"       // User-editable configuration file
2010#include <float.h>          // FLT_MAX
2111#include <stdarg.h>         // va_list
2212#include <stddef.h>         // ptrdiff_t
2313#include <stdlib.h>         // NULL, malloc
2414#include <string.h>         // memset, memmove
2515
16// Define assertion handler.
2617#ifndef IM_ASSERT
2718#include <assert.h>
2819#define IM_ASSERT(_EXPR)    assert(_EXPR)
2920#endif
3021
22// Define attributes of all API symbols declarations, e.g. for DLL under Windows.
3123#ifndef IMGUI_API
3224#define IMGUI_API
3325#endif
3426
27// Forward declarations
28struct ImDrawCmd;
29struct ImDrawList;
30struct ImFont;
31struct ImFontAtlas;
32struct ImGuiIO;
33struct ImGuiStorage;
34struct ImGuiStyle;
35
3536typedef unsigned int ImU32;
3637typedef unsigned short ImWchar;     // character for display
3738typedef void* ImTextureID;          // user data to refer to a texture (e.g. store your texture handle/id)
r245119r245120
4142typedef int ImGuiKey;               // enum ImGuiKey_
4243typedef int ImGuiColorEditMode;     // enum ImGuiColorEditMode_
4344typedef int ImGuiWindowFlags;       // enum ImGuiWindowFlags_
44typedef int ImGuiSetCondition;      // enum ImGuiSetCondition_
45typedef int ImGuiSetCond;           // enum ImGuiSetCondition_
4546typedef int ImGuiInputTextFlags;    // enum ImGuiInputTextFlags_
46struct ImGuiTextEditCallbackData;   // for advanced uses of InputText()
47struct ImGuiTextEditCallbackData;   // for advanced uses of InputText()
48typedef int (*ImGuiTextEditCallback)(ImGuiTextEditCallbackData *data);
4749
4850struct ImVec2
4951{
r245119r245120
7476    IMGUI_API void        MemFree(void* ptr);
7577}
7678
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).
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).
7880// Use '#define ImVector std::vector' if you want to use the STL type or your own type.
7981// 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.
8082#ifndef ImVector
r245119r245120
115117    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; }
116118
117119    inline void                 resize(size_t new_size)         { if (new_size > Capacity) reserve(new_size); Size = new_size; }
118    inline void                 reserve(size_t new_capacity)
119    {
120    inline void                 reserve(size_t new_capacity)   
121    {
120122        if (new_capacity <= Capacity) return;
121123        T* new_data = (value_type*)ImGui::MemAlloc(new_capacity * sizeof(value_type));
122124        memcpy(new_data, Data, Size * sizeof(value_type));
123125        ImGui::MemFree(Data);
124126        Data = new_data;
125        Capacity = new_capacity;
127        Capacity = new_capacity;
126128    }
127129
128130    inline void                 push_back(const value_type& v)  { if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); Data[Size++] = v; }
r245119r245120
141143// - struct ImDrawList                  // Draw command list
142144// - struct ImFont                      // TTF font loader, bake glyphs into bitmap
143145
144// ImGui End-user API
146// ImGui end-user API
145147// In a namespace so that user can add extra functions (e.g. Value() helpers for your vector or common types)
146148namespace ImGui
147149{
r245119r245120
156158    IMGUI_API void          ShowTestWindow(bool* open = NULL);
157159
158160    // Window
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.
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.
160163    IMGUI_API void          End();
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);                                 // "
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);                    // "
163166    IMGUI_API void          EndChild();
164167    IMGUI_API bool          GetWindowIsFocused();
165168    IMGUI_API ImVec2        GetContentRegionMax();                                              // window or current column boundaries, in windows coordinates
r245119r245120
173176    IMGUI_API ImVec2        GetWindowSize();                                                    // get current window position.
174177    IMGUI_API float         GetWindowWidth();
175178    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.
182179
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
183195    IMGUI_API void          SetScrollPosHere();                                                 // adjust scrolling position to center into the current cursor position.
184196    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.
185197    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).
r245119r245120
215227    IMGUI_API void          Spacing();
216228    IMGUI_API void          Columns(int count = 1, const char* id = NULL, bool border=true);    // setup number of columns
217229    IMGUI_API void          NextColumn();                                                       // next column
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);
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())
221235    IMGUI_API ImVec2        GetCursorPos();                                                     // cursor position is relative to window position
222236    IMGUI_API float         GetCursorPosX();                                                    // "
223237    IMGUI_API float         GetCursorPosY();                                                    // "
r245119r245120
231245    IMGUI_API float         GetTextLineHeightWithSpacing();                                     // spacing (in pixels) between 2 consecutive lines of text == GetWindowFontSize() + GetStyle().ItemSpacing.y
232246
233247    // ID scopes
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')
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')
236250    IMGUI_API void          PushID(const char* str_id);                                         // push identifier into the ID stack. IDs are hash of the *entire* stack!
237251    IMGUI_API void          PushID(const void* ptr_id);
238252    IMGUI_API void          PushID(const int int_id);
r245119r245120
248262    IMGUI_API void          TextWrapped(const char* fmt, ...);                                  // shortcut for PushTextWrapPos(0.0f); Text(fmt, ...); PopTextWrapPos();
249263    IMGUI_API void          TextWrappedV(const char* fmt, va_list args);
250264    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.
251    IMGUI_API void          LabelText(const char* label, const char* fmt, ...);                 // display text+label aligned the same way as value+label widgets
265    IMGUI_API void          LabelText(const char* label, const char* fmt, ...);                 // display text+label aligned the same way as value+label widgets
252266    IMGUI_API void          LabelTextV(const char* label, const char* fmt, va_list args);
267    IMGUI_API void          Bullet();
253268    IMGUI_API void          BulletText(const char* fmt, ...);
254269    IMGUI_API void          BulletTextV(const char* fmt, va_list args);
255270    IMGUI_API bool          Button(const char* label, const ImVec2& size = ImVec2(0,0), bool repeat_when_held = false);
r245119r245120
257272    IMGUI_API bool          InvisibleButton(const char* str_id, const ImVec2& size);
258273    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));
259274    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.
260    IMGUI_API bool          CollapsingHeader(const char* label, const char* str_id = NULL, const bool display_frame = true, const bool default_open = false);
275    IMGUI_API bool          CollapsingHeader(const char* label, const char* str_id = NULL, bool display_frame = true, bool default_open = false);
261276    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.
262277    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);
263278    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);
r245119r245120
275290    IMGUI_API bool          CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value);
276291    IMGUI_API bool          RadioButton(const char* label, bool active);
277292    IMGUI_API bool          RadioButton(const char* label, int* v, int v_button);
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);
293    IMGUI_API bool          InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, ImGuiTextEditCallback callback = NULL, void* user_data = NULL);
279294    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);
280295    IMGUI_API bool          InputFloat2(const char* label, float v[2], int decimal_precision = -1);
281296    IMGUI_API bool          InputFloat3(const char* label, float v[3], int decimal_precision = -1);
r245119r245120
288303    IMGUI_API bool          ColorEdit3(const char* label, float col[3]);
289304    IMGUI_API bool          ColorEdit4(const char* label, float col[4], bool show_alpha = true);
290305    IMGUI_API void          ColorEditMode(ImGuiColorEditMode mode);
306
307    // Trees
291308    IMGUI_API bool          TreeNode(const char* str_label_id);                                 // if returning 'true' the node is open and the user is responsible for calling TreePop
292309    IMGUI_API bool          TreeNode(const char* str_id, const char* fmt, ...);                 // "
293310    IMGUI_API bool          TreeNode(const void* ptr_id, const char* fmt, ...);                 // "
r245119r245120
296313    IMGUI_API void          TreePush(const char* str_id = NULL);                                // already called by TreeNode(), but you can call Push/Pop yourself for layouting purpose
297314    IMGUI_API void          TreePush(const void* ptr_id = NULL);                                // "
298315    IMGUI_API void          TreePop();
299    IMGUI_API void          OpenNextNode(bool open);                                            // force open/close the next TreeNode or CollapsingHeader
316    IMGUI_API void          SetNextTreeNodeOpened(bool opened, ImGuiSetCond cond = 0);          // set next tree node to be opened.
300317
301318    // Selectable / Lists
302319    IMGUI_API bool          Selectable(const char* label, bool selected, const ImVec2& size = ImVec2(0,0));
r245119r245120
326343    // Utilities
327344    IMGUI_API bool          IsItemHovered();                                                    // was the last item hovered by mouse?
328345    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();                                                  //
329347    IMGUI_API ImVec2        GetItemBoxMin();                                                    // get bounding box of last item
330348    IMGUI_API ImVec2        GetItemBoxMax();                                                    // get bounding box of last item
331349    IMGUI_API bool          IsClipped(const ImVec2& item_size);                                 // to perform coarse clipping on user's side (as an optimization)
r245119r245120
357375
358376    // Obsolete (will be removed)
359377    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); }
360379
361380} // namespace ImGui
362381
r245119r245120
367386    ImGuiWindowFlags_NoTitleBar             = 1 << 0,   // Disable title-bar
368387    ImGuiWindowFlags_NoResize               = 1 << 1,   // Disable user resizing with the lower-right grip
369388    ImGuiWindowFlags_NoMove                 = 1 << 2,   // Disable user moving the window
370    ImGuiWindowFlags_NoScrollbar            = 1 << 3,   // Disable scroll bar (window can still scroll with mouse or programatically)
389    ImGuiWindowFlags_NoScrollbar            = 1 << 3,   // Disable scrollbar (window can still scroll with mouse or programatically)
371390    ImGuiWindowFlags_NoScrollWithMouse      = 1 << 4,   // Disable user scrolling with mouse wheel
372391    ImGuiWindowFlags_NoCollapse             = 1 << 5,   // Disable user collapsing window by double-clicking on it
373392    ImGuiWindowFlags_AlwaysAutoResize       = 1 << 6,   // Resize every window to its content every frame
r245119r245120
387406    // Default: 0
388407    ImGuiInputTextFlags_CharsDecimal        = 1 << 0,   // Allow 0123456789.+-*/
389408    ImGuiInputTextFlags_CharsHexadecimal    = 1 << 1,   // Allow 0123456789ABCDEFabcdef
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,
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.
396417};
397418
398419// User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array
r245119r245120
488509    ImGuiColorEditMode_HEX = 2
489510};
490511
491// Condition flags for ImGui::SetWindow***() and SetNextWindow***() functions
492// Those functions treat 0 as a shortcut to ImGuiSetCondition_Always
493enum ImGuiSetCondition_
512// Condition flags for ImGui::SetWindow***(), SetNextWindow***(), SetNextTreeNode***() functions
513// All those functions treat 0 as a shortcut to ImGuiSetCond_Always
514enum ImGuiSetCond_
494515{
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
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
498519};
499520
500521struct ImGuiStyle
r245119r245120
513534    float       WindowFillAlphaDefault;     // Default alpha of window background, if not specified in ImGui::Begin()
514535    float       TreeNodeSpacing;            // Horizontal spacing when entering a tree node
515536    float       ColumnsMinSpacing;          // Minimum horizontal spacing between two columns
516    float       ScrollBarWidth;             // Width of the vertical scroll bar
537    float       ScrollbarWidth;             // Width of the vertical scrollbar
538    float       GrabMinSize;                // Minimum width/height of a slider or scrollbar grab
517539    ImVec4      Colors[ImGuiCol_COUNT];
518540
519541    IMGUI_API ImGuiStyle();
r245119r245120
529551
530552    ImVec2        DisplaySize;              // <unset>              // Display size, in pixels. For clamping windows positions.
531553    float         DeltaTime;                // = 1.0f/60.0f         // Time elapsed since last frame, in seconds.
532    float         IniSavingRate;            // = 5.0f               // Maximum time between saving .ini file, in seconds.
554    float         IniSavingRate;            // = 5.0f               // Maximum time between saving positions/sizes to .ini file, in seconds.
533555    const char*   IniFilename;              // = "imgui.ini"        // Path to .ini file. NULL to disable .ini saving.
534556    const char*   LogFilename;              // = "imgui_log.txt"    // Path to .log file (default parameter to ImGui::LogToFile when no file is specified).
535557    float         MouseDoubleClickTime;     // = 0.30f              // Time for a double-click, in seconds.
r245119r245120
547569    // User Functions
548570    //------------------------------------------------------------------
549571
550    // REQUIRED: rendering function.
572    // REQUIRED: rendering function.
551573    // See example code if you are unsure of how to implement this.
552    void        (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count);
574    void        (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count);     
553575
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.
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)
556578    const char* (*GetClipboardTextFn)();
557579    void        (*SetClipboardTextFn)(const char* text);
558580
559    // Optional: override memory allocations (default to posix malloc/free). MemFreeFn() may be called with a NULL pointer.
581    // Optional: override memory allocations. MemFreeFn() may be called with a NULL pointer.
582    // (default to posix malloc/free)
560583    void*       (*MemAllocFn)(size_t sz);
561584    void        (*MemFreeFn)(void* ptr);
562585
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)
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)
564588    void        (*ImeSetInputScreenPosFn)(int x, int y);
589    void*       ImeWindowHandle;            // (Windows) Set this to your HWND to get automatic IME cursor positioning.
565590
566591    //------------------------------------------------------------------
567592    // Input - Fill before calling NewFrame()
568593    //------------------------------------------------------------------
569594
570595    ImVec2      MousePos;                   // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
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.
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.
573598    bool        MouseDrawCursor;            // Request ImGui to draw a mouse cursor for you (if you are on a platform without a mouse cursor).
574599    bool        KeyCtrl;                    // Keyboard modifier pressed: Control
575600    bool        KeyShift;                   // Keyboard modifier pressed: Shift
576    bool        KeysDown[512];              // Keyboard keys that are pressed (in whatever order user naturally has access to keyboard data)
601    bool        KeysDown[512];              // Keyboard keys that are pressed (in whatever storage order you naturally have access to keyboard data)
577602    ImWchar     InputCharacters[16+1];      // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper.
578603
579604    // Function
r245119r245120
585610
586611    bool        WantCaptureMouse;           // Mouse is hovering a window or widget is active (= ImGui will use your mouse input)
587612    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
588614
589615    //------------------------------------------------------------------
590616    // [Internal] ImGui will maintain those fields for you
591617    //------------------------------------------------------------------
592618
593    ImVec2      MousePosPrev;               //
619    ImVec2      MousePosPrev;               // Previous mouse position
594620    ImVec2      MouseDelta;                 // Mouse delta. Note that this is zero if either current or previous position are negative to allow mouse enabling/disabling.
595621    bool        MouseClicked[5];            // Mouse button went from !Down to Down
596622    ImVec2      MouseClickedPos[5];         // Position at time of clicking
r245119r245120
646672    ImVector<TextRange> Filters;
647673    int                 CountGrep;
648674
649    ImGuiTextFilter();
675    ImGuiTextFilter(const char* default_filter = "");
650676    void Clear() { InputBuf[0] = 0; Build(); }
651677    void Draw(const char* label = "Filter (inc,-exc)", float width = -1.0f);    // Helper calling InputText+Build
652678    bool PassFilter(const char* val) const;
r245119r245120
680706// - You want to store custom debug data easily without adding or editing structures in your code.
681707struct ImGuiStorage
682708{
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; }
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; }
690716    };
691717    ImVector<Pair>    Data;
692718
r245119r245120
701727    IMGUI_API void*   GetVoidPtr(ImGuiID key) const; // default_val is NULL
702728    IMGUI_API void    SetVoidPtr(ImGuiID key, void* val);
703729
704    // - Get***Ref() functions finds pair, insert on demand if missing, return pointer. Useful if you intend to do Get+Set.
730    // - Get***Ref() functions finds pair, insert on demand if missing, return pointer. Useful if you intend to do Get+Set.
705731    // - 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.
706732    // - A typical use case where this is convenient:
707733    //      float* pvar = ImGui::GetFloatRef(key); ImGui::SliderFloat("var", pvar, 0, 100.0f); some_var += *pvar;
r245119r245120
716742// Shared state of InputText(), passed to callback when a ImGuiInputTextFlags_Callback* flag is used.
717743struct ImGuiTextEditCallbackData
718744{
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()
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
728748
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
729761    // NB: calling those function loses selection.
730762    void DeleteChars(int pos, int bytes_count);
731763    void InsertChars(int pos, const char* text, const char* text_end = NULL);
r245119r245120
740772    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; }
741773    ImColor(float r, float g, float b, float a = 1.0f)              { Value.x = r; Value.y = g; Value.z = b; Value.w = a; }
742774    ImColor(const ImVec4& col)                                      { Value = col; }
743
744775    operator ImU32() const                                          { return ImGui::ColorConvertFloat4ToU32(Value); }
745776    operator ImVec4() const                                         { return Value; }
746777
r245119r245120
763794// It is up to you to decide if your rendering loop or the callback should be responsible for backup/restoring rendering state.
764795typedef void (*ImDrawCallback)(const ImDrawList* parent_list, const ImDrawCmd* cmd);
765796
766// Typically, 1 command = 1 gpu draw call
797// Typically, 1 command = 1 gpu draw call (unless command is a callback)
767798struct ImDrawCmd
768799{
769800    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.
r245119r245120
802833
803834    // [Internal to ImGui]
804835    ImVector<ImVec4>        clip_rect_stack;    // [Internal]
805    ImVector<ImTextureID>   texture_id_stack;   // [Internal]
836    ImVector<ImTextureID>   texture_id_stack;   // [Internal]
806837    ImDrawVert*             vtx_write;          // [Internal] point within vtx_buffer after each add command (to avoid using the ImVector<> operators too much)
807838
808839    ImDrawList() { Clear(); }
r245119r245120
812843    IMGUI_API void  PushTextureID(const ImTextureID& texture_id);
813844    IMGUI_API void  PopTextureID();
814845
815    // Primitives
846    // Primitives   
816847    IMGUI_API void  AddLine(const ImVec2& a, const ImVec2& b, ImU32 col);
817848    IMGUI_API void  AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F);
818849    IMGUI_API void  AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F);
r245119r245120
897928    float               FontSize;           // <user set>      // Height of characters, set during loading (don't change after loading)
898929    float               Scale;              // = 1.0f          // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
899930    ImVec2              DisplayOffset;      // = (0.0f,0.0f)   // Offset font rendering by xx pixels
900    ImWchar             FallbackChar;       // = '?'           // Replacement glyph if one isn't found.
931    ImWchar             FallbackChar;       // = '?'           // Replacement glyph if one isn't found. Only set via SetFallbackChar()
901932
902933    // Members: Runtime data
903934    struct Glyph
r245119r245120
910941    };
911942    ImFontAtlas*        ContainerAtlas;     // What we has been loaded into
912943    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)
913947    ImVector<int>       IndexLookup;        // Index glyphs by Unicode code-point
914    const Glyph*        FallbackGlyph;      // == FindGlyph(FontFallbackChar)
915948
916949    // Methods
917950    IMGUI_API ImFont();
r245119r245120
919952    IMGUI_API void                  Clear();
920953    IMGUI_API void                  BuildLookupTable();
921954    IMGUI_API const Glyph*          FindGlyph(unsigned short c) const;
955    IMGUI_API void                  SetFallbackChar(ImWchar c);
922956    IMGUI_API bool                  IsLoaded() const        { return ContainerAtlas != NULL; }
923957
924958    // 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
trunk/3rdparty/bgfx/README.md
r245119r245120
44What is it?
55-----------
66
7Cross-platform rendering library.
7Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style
8rendering library.
89
910Supported rendering backends:
1011
r245119r245120
6970how it currently looks. 
7071![mac_screenshot](https://raw.githubusercontent.com/emoon/ProDBG/master/data/screens/mac_screenshot.png)
7172
72
7373http://www.dogbytegames.com/ Dogbyte Games is an indie mobile developer studio
74focusing on racing games.
74focusing on racing games. 
75![ios](http://www.dogbytegames.com/bgfx/offroadlegends2_bgfx_ipad2.jpg)
7576
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
7685Examples
7786--------
7887
r245119r245120
311320Steps bellow are for default build system inside bgfx repository. There is
312321alterative way to build bgfx and examples with [fips](https://github.com/floooh/fips-bgfx/#fips-bgfx).
313322
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
322323### Getting source
323324
324325   git clone git://github.com/bkaradzic/bx.git
325326   git clone git://github.com/bkaradzic/bgfx.git
327
328### Quick start (Windows with Visual Studio)
329
330Enter bgfx directory:
331
326332   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
327345   make
328346
329347After calling `make`, .build/projects/* directory will be generated. All
r245119r245120
353371
354372### Prerequisites for Windows
355373
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
356380When building on Windows, you have to set DXSDK_DIR environment variable to
357381point to DirectX SDK directory.
358382
r245119r245120
593617 - Animated mesh example.
594618 - Direct3D 12 renderer backend.
595619 - Metal renderer backend.
620 - Vulkan renderer backend.
596621
597622Contact
598623-------
trunk/3rdparty/bgfx/examples/08-update/fs_update_3d.sc
r0r245120
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
r245119r245120
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
152177   // Create static vertex buffer.
153178   bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer(bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) ), PosTexcoordVertex::ms_decl);
154179
r245119r245120
156181   bgfx::IndexBufferHandle ibh = bgfx::createIndexBuffer(bgfx::makeRef(s_cubeIndices, sizeof(s_cubeIndices) ) );
157182
158183   // Create texture sampler uniforms.
159   bgfx::UniformHandle u_texCube = bgfx::createUniform("u_texCube", bgfx::UniformType::Uniform1iv);
160
184   bgfx::UniformHandle u_texCube  = bgfx::createUniform("u_texCube",  bgfx::UniformType::Uniform1iv);
161185   bgfx::UniformHandle u_texColor = bgfx::createUniform("u_texColor", bgfx::UniformType::Uniform1iv);
162186
163   bgfx::ProgramHandle program    = loadProgram("vs_update", "fs_update");
164   bgfx::ProgramHandle programCmp = loadProgram("vs_update", "fs_update_cmp");
187   bgfx::UniformHandle u_time = bgfx::createUniform("u_time", bgfx::UniformType::Uniform1f);
165188
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
166193   const uint32_t textureSide = 2048;
167194
168195   bgfx::TextureHandle textureCube = bgfx::createTextureCube(textureSide, 1
r245119r245120
210237      const int64_t freq = bx::getHPFrequency();
211238      const double toMs = 1000.0/double(freq);
212239      float time = (float)( (now - timeOffset)/double(bx::getHPFrequency() ) );
240      bgfx::setUniform(u_time, &time);
213241
214242      // Use debug font to print information about this example.
215243      bgfx::dbgTextClear();
r245119r245120
345373      // Submit primitive for rendering to view 1.
346374      bgfx::submit(1);
347375
376      const float xpos = -8.0f - BX_COUNTOF(textures)*0.1f*0.5f;
348377
349378      for (uint32_t ii = 0; ii < BX_COUNTOF(textures); ++ii)
350379      {
351         bx::mtxTranslate(mtx, -8.0f - BX_COUNTOF(textures)*0.1f*0.5f + ii*2.1f, 4.0f, 0.0f);
380         bx::mtxTranslate(mtx, xpos + ii*2.1f, 4.0f, 0.0f);
352381
353382         // Set model matrix for rendering.
354383         bgfx::setTransform(mtx);
r245119r245120
370399         bgfx::submit(1);
371400      }
372401
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
373426      for (uint32_t ii = 0; ii < 3; ++ii)
374427      {
375         bx::mtxTranslate(mtx, -8.0f - BX_COUNTOF(textures)*0.1f*0.5f + 8*2.1f, -4.0f + ii*2.1f, 0.0f);
428         bx::mtxTranslate(mtx, xpos + 8*2.1f, -4.0f + ii*2.1f, 0.0f);
376429
377430         // Set model matrix for rendering.
378431         bgfx::setTransform(mtx);
r245119r245120
412465      bgfx::destroyTexture(textures[ii]);
413466   }
414467
468   for (uint32_t ii = 0; ii < BX_COUNTOF(textures3d); ++ii)
469   {
470      bgfx::destroyTexture(textures3d[ii]);
471   }
472
415473   bgfx::destroyTexture(texture2d);
416474   bgfx::destroyTexture(textureCube);
417475   bgfx::destroyIndexBuffer(ibh);
418476   bgfx::destroyVertexBuffer(vbh);
477   bgfx::destroyProgram(program3d);
419478   bgfx::destroyProgram(programCmp);
420479   bgfx::destroyProgram(program);
480   bgfx::destroyUniform(u_time);
421481   bgfx::destroyUniform(u_texColor);
422482   bgfx::destroyUniform(u_texCube);
423483
trunk/3rdparty/bgfx/examples/23-vectordisplay/vectordisplay.cpp
r245119r245120
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
126131   teardownResDependent();
127132
128133   bgfx::destroyProgram(m_drawToScreenShader);
r245119r245120
147152void VectorDisplay::endFrame()
148153{
149154   float proj[16];
150   float ident[16];
151   bx::mtxIdentity(ident);
152
153155   bx::mtxOrtho(proj, 0.0f, (float)m_screenWidth, (float)m_screenHeight, 0.0f, 0.0f, 1000.0f);
154156
155157   bgfx::setViewRect(m_view, 0, 0, m_screenWidth, m_screenHeight);
r245119r245120
166168   );
167169   m_vertexBuffersSize[m_currentDrawStep] = (uint32_t)m_points.size();
168170
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
177171   for (int loopvar = 0; loopvar < m_numberDecaySteps; loopvar++)
178172   {
179173      int stepi = m_numberDecaySteps - loopvar - 1;
r245119r245120
728722   {
729723      for (size_t i = 0; i < m_vertexBuffers.size(); ++i)
730724      {
731         destroyDynamicVertexBuffer(m_vertexBuffers[i]);
725         bgfx::destroyDynamicVertexBuffer(m_vertexBuffers[i]);
732726      }
733727
734728      m_vertexBuffers.clear();
trunk/3rdparty/bgfx/examples/25-c99/helloworld.c
r0r245120
1/*
2 * Copyright 2011-2015 Branimir Karadzic. All rights reserved.
3 * License: http://www.opensource.org/licenses/BSD-2-Clause
4 */
5
6#include <bgfx.c99.h>
7#include "../00-helloworld/logo.h"
8
9extern bool entry_process_events(uint32_t* _width, uint32_t* _height, uint32_t* _debug, uint32_t* _reset);
10
11uint16_t uint16_max(uint16_t _a, uint16_t _b)
12{
13   return _a < _b ? _b : _a;
14}
15
16int _main_(int _argc, char** _argv)
17{
18   (void)_argc;
19   (void)_argv;
20   uint32_t width = 1280;
21   uint32_t height = 720;
22   uint32_t debug = BGFX_DEBUG_TEXT;
23   uint32_t reset = BGFX_RESET_VSYNC;
24
25   bgfx_init(BGFX_RENDERER_TYPE_COUNT, NULL, NULL);
26   bgfx_reset(width, height, reset);
27
28   // Enable debug text.
29   bgfx_set_debug(debug);
30
31   bgfx_set_view_clear(0
32      , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
33      , 0x303030ff
34      , 1.0f
35      , 0
36      );
37
38   while (!entry_process_events(&width, &height, &debug, &reset) )
39   {
40      // Set view 0 default viewport.
41      bgfx_set_view_rect(0, 0, 0, width, height);
42
43      // This dummy draw call is here to make sure that view 0 is cleared
44      // if no other draw calls are submitted to view 0.
45      bgfx_submit(0, 0);
46
47      // Use debug font to print information about this example.
48      bgfx_dbg_text_clear(0, false);
49      bgfx_dbg_text_image(uint16_max(width/2/8, 20)-20
50                   , uint16_max(height/2/16, 6)-6
51                   , 40
52                   , 12
53                   , s_logo
54                   , 160
55                   );
56      bgfx_dbg_text_printf(0, 1, 0x4f, "bgfx/examples/25-c99");
57      bgfx_dbg_text_printf(0, 2, 0x6f, "Description: Initialization and debug text with C99 API.");
58
59      // Advance to next frame. Rendering thread will be kicked to
60      // process submitted rendering primitives.
61      bgfx_frame();
62   }
63
64   // Shutdown bgfx.
65   bgfx_shutdown();
66
67   return 0;
68}
trunk/3rdparty/bgfx/examples/common/entry/entry.cpp
r245119r245120
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
3776   bool setOrToggle(uint32_t& _flags, const char* _name, uint32_t _bit, int _first, int _argc, char const* const* _argv)
3877   {
3978      if (0 == strcmp(_argv[_first], _name) )
trunk/3rdparty/bgfx/examples/common/entry/entry.h
r245119r245120
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);
214215   void setMouseLock(WindowHandle _handle, bool _lock);
215216
216217   struct WindowState
trunk/3rdparty/bgfx/examples/common/entry/entry_android.cpp
r245119r245120
440440      BX_UNUSED(_handle);
441441   }
442442
443   void toggleFullscreen(WindowHandle _handle)
444   {
445      BX_UNUSED(_handle);
446   }
447
443448   void setMouseLock(WindowHandle _handle, bool _lock)
444449   {
445450      BX_UNUSED(_handle, _lock);
trunk/3rdparty/bgfx/examples/common/entry/entry_asmjs.cpp
r245119r245120
5959      BX_UNUSED(_handle);
6060   }
6161
62   void toggleFullscreen(WindowHandle _handle)
63   {
64      BX_UNUSED(_handle);
65   }
66
6267   void setMouseLock(WindowHandle _handle, bool _lock)
6368   {
6469      BX_UNUSED(_handle, _lock);
trunk/3rdparty/bgfx/examples/common/entry/entry_ios.mm
r245119r245120
126126      BX_UNUSED(_handle);
127127   }
128128
129   void toggleFullscreen(WindowHandle _handle)
130   {
131      BX_UNUSED(_handle);
132   }
133
129134   void setMouseLock(WindowHandle _handle, bool _lock)
130135   {
131136      BX_UNUSED(_handle, _lock);
trunk/3rdparty/bgfx/examples/common/entry/entry_nacl.cpp
r245119r245120
9494      BX_UNUSED(_handle);
9595   }
9696
97   void toggleFullscreen(WindowHandle _handle)
98   {
99      BX_UNUSED(_handle);
100   }
101
97102   void setMouseLock(WindowHandle _handle, bool _lock)
98103   {
99104      BX_UNUSED(_handle, _lock);
trunk/3rdparty/bgfx/examples/common/entry/entry_osx.mm
r245119r245120
1616#include <bx/os.h>
1717#include <bx/handlealloc.h>
1818
19#define DEFAULT_WIDTH 1280
20#define DEFAULT_HEIGHT 720
21
2219@interface AppDelegate : NSObject<NSApplicationDelegate>
2320{
2421   bool terminated;
r245119r245120
8077   struct Context
8178   {
8279      Context()
83         : m_exit(false)
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)
8487      {
8588         s_translateKey[27]             = Key::Esc;
8689         s_translateKey[13]             = Key::Return;
r245119r245120
106109
107110         for (char ch = 'a'; ch <= 'z'; ++ch)
108111         {
109            s_translateKey[uint8_t(ch)]             =
112            s_translateKey[uint8_t(ch)]       =
110113            s_translateKey[uint8_t(ch - ' ')] = Key::KeyA + (ch - 'a');
111114         }
112115      }
r245119r245120
137140         NSWindow* window = m_window[handle.idx];
138141         NSRect originalFrame = [window frame];
139142         NSPoint location = [window mouseLocationOutsideOfEventStream];
140         NSRect adjustFrame = [NSWindow contentRectForFrameRect: originalFrame styleMask: NSTitledWindowMask];
143         NSRect adjustFrame = [window contentRectForFrameRect: originalFrame];
141144
142145         int x = location.x;
143146         int y = (int)adjustFrame.size.height - (int)location.y;
r245119r245120
172175         return mask;
173176      }
174177
175      Key::Enum handleKeyEvent(NSEvent* event, uint8_t* specialKeys)
178      Key::Enum handleKeyEvent(NSEvent* event, uint8_t* specialKeys, uint8_t* _pressedChar)
176179      {
177180         NSString* key = [event charactersIgnoringModifiers];
178181         unichar keyChar = 0;
179//DBG("keyChar %d", keyChar);
180182         if ([key length] == 0)
181183         {
182184            return Key::None;
183185         }
184186
185187         keyChar = [key characterAtIndex:0];
188         *_pressedChar = (uint8_t)keyChar;
186189
187190         int keyCode = keyChar;
188//DBG("keyCode %d", keyCode);
189191         *specialKeys = translateModifiers([event modifierFlags]);
190192
191193         // if this is a unhandled key just return None
r245119r245120
236238               case NSMouseMoved:
237239               case NSLeftMouseDragged:
238240               case NSRightMouseDragged:
241               case NSOtherMouseDragged:
239242               {
240                  int x, y;
241                  getMousePos(&x, &y);
242                  m_eventQueue.postMouseEvent(s_defaultWindow, x, y, 0);
243                  getMousePos(&m_mx, &m_my);
244                  m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll);
243245                  break;
244246               }
245247
246248               case NSLeftMouseDown:
247249               {
248                  int x, y;
249                  getMousePos(&x, &y);
250                  m_eventQueue.postMouseEvent(s_defaultWindow, x, y, 0, MouseButton::Left, true);
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);
251255                  break;
252256               }
253257
254258               case NSLeftMouseUp:
255259               {
256                  int x, y;
257                  getMousePos(&x, &y);
258                  m_eventQueue.postMouseEvent(s_defaultWindow, x, y, 0, MouseButton::Left, false);
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!
259262                  break;
260263               }
261264
262265               case NSRightMouseDown:
263266               {
264                  int x, y;
265                  getMousePos(&x, &y);
266                  m_eventQueue.postMouseEvent(s_defaultWindow, x, y, 0, MouseButton::Right, true);
267                  m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Right, true);
267268                  break;
268269               }
269270
270271               case NSRightMouseUp:
271272               {
272                  int x, y;
273                  getMousePos(&x, &y);
274                  m_eventQueue.postMouseEvent(s_defaultWindow, x, y, 0, MouseButton::Right, false);
273                  m_eventQueue.postMouseEvent(s_defaultWindow, m_mx, m_my, m_scroll, MouseButton::Right, false);
275274                  break;
276275               }
277276
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
278298               case NSKeyDown:
279299               {
280300                  uint8_t modifiers = 0;
281                  Key::Enum key = handleKeyEvent(event, &modifiers);
301                  uint8_t pressedChar[4];
302                  Key::Enum key = handleKeyEvent(event, &modifiers, &pressedChar[0]);
282303
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)
304                  // Returning false means that we take care of the key (instead of the default behavior)
285305                  if (key != Key::None)
286306                  {
287                     if (key != Key::KeyQ
288                     && !(modifiers & Modifier::RightMeta) )
307                     if (key == Key::KeyQ && (modifiers & Modifier::RightMeta) )
289308                     {
290                        m_eventQueue.postKeyEvent(s_defaultWindow, key, modifiers, true);
291                        return false;
309                        m_eventQueue.postExitEvent();
292310                     }
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                     }
293328                  }
294329
295330                  break;
r245119r245120
298333               case NSKeyUp:
299334               {
300335                  uint8_t modifiers  = 0;
301                  Key::Enum key = handleKeyEvent(event, &modifiers);
336                  uint8_t pressedChar[4];
337                  Key::Enum key = handleKeyEvent(event, &modifiers, &pressedChar[0]);
302338
339                  BX_UNUSED(pressedChar);
340
303341                  if (key != Key::None)
304342                  {
305343                     m_eventQueue.postKeyEvent(s_defaultWindow, key, modifiers, false);
r245119r245120
323361      {
324362         WindowHandle handle = { 0 };
325363         NSWindow* window = m_window[handle.idx];
326         NSRect rect = [window frame];
364         NSRect originalFrame = [window frame];
365         NSRect rect = [window contentRectForFrameRect: originalFrame];
327366         uint32_t width  = uint32_t(rect.size.width);
328367         uint32_t height = uint32_t(rect.size.height);
329368         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);
330373      }
331374
332375      int32_t run(int _argc, char** _argv)
r245119r245120
363406         [menubar addItem:appMenuItem];
364407         [NSApp setMainMenu:menubar];
365408
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
366420         m_windowAlloc.alloc();
367         NSRect rect = NSMakeRect(0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT);
421         NSRect rect = NSMakeRect(centerX, centerY, (float)ENTRY_DEFAULT_WIDTH, (float)ENTRY_DEFAULT_HEIGHT);
368422         NSWindow* window = [[NSWindow alloc]
369423            initWithContentRect:rect
370            styleMask:0
371            |NSTitledWindowMask
372            |NSClosableWindowMask
373            |NSMiniaturizableWindowMask
374            |NSResizableWindowMask
424            styleMask:m_style
375425            backing:NSBackingStoreBuffered defer:NO
376426         ];
377427         NSString* appName = [[NSProcessInfo processInfo] processName];
378428         [window setTitle:appName];
379         [window cascadeTopLeftFromPoint:NSMakePoint(20,20)];
380429         [window makeKeyAndOrderFront:window];
381430         [window setAcceptsMouseMovedEvents:YES];
382431         [window setBackgroundColor:[NSColor blackColor]];
383432         [[Window sharedDelegate] windowCreated:window];
384433
385434         m_window[0] = window;
435         m_windowFrame = [window frame];
386436
387437         bgfx::osxSetNSWindow(window);
388438
r245119r245120
405455            }
406456         }
407457
408
409458         m_eventQueue.postExitEvent();
410459
411460         while (bgfx::RenderFrame::NoContext != bgfx::renderFrame() ) {};
r245119r245120
414463         return 0;
415464      }
416465
466      bool isValid(WindowHandle _handle)
467      {
468         return m_windowAlloc.isValid(_handle.idx);
469      }
470
417471      EventQueue m_eventQueue;
418472
419473      bx::HandleAllocT<ENTRY_CONFIG_MAX_WINDOWS> m_windowAlloc;
420474      NSWindow* m_window[ENTRY_CONFIG_MAX_WINDOWS];
475      NSRect m_windowFrame;
421476
422      bool m_exit;
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;
423484   };
424485
425486   static Context s_ctx;
r245119r245120
448509
449510   void destroyWindow(WindowHandle _handle)
450511   {
451      BX_UNUSED(_handle);
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      }
452519   }
453520
454521   void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y)
455522   {
456      BX_UNUSED(_handle, _x, _y);
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      }
457538   }
458539
459540   void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height)
460541   {
461      BX_UNUSED(_handle, _width, _height);
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      }
462550   }
463551
464552   void setWindowTitle(WindowHandle _handle, const char* _title)
465553   {
466      BX_UNUSED(_handle, _title);
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      }
467563   }
468564
469565   void toggleWindowFrame(WindowHandle _handle)
470566   {
471      BX_UNUSED(_handle);
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      }
472575   }
473576
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
474612   void setMouseLock(WindowHandle _handle, bool _lock)
475613   {
476614      BX_UNUSED(_handle, _lock);
r245119r245120
572710   using namespace entry;
573711   s_ctx.windowDidResize();
574712}
713
575714@end
576715
577716int main(int _argc, char** _argv)
trunk/3rdparty/bgfx/examples/common/entry/entry_p.h
r245119r245120
5656
5757   int main(int _argc, char** _argv);
5858
59   char keyToAscii(Key::Enum _key, uint8_t _modifiers);
60
5961   struct Event
6062   {
6163      enum Enum
trunk/3rdparty/bgfx/examples/common/entry/entry_qnx.cpp
r245119r245120
5959      BX_UNUSED(_handle);
6060   }
6161
62   void toggleFullscreen(WindowHandle _handle)
63   {
64      BX_UNUSED(_handle);
65   }
66
6267   void setMouseLock(WindowHandle _handle, bool _lock)
6368   {
6469      BX_UNUSED(_handle, _lock);
trunk/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
r245119r245120
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,
182183      SDL_USER_WINDOW_MOUSE_LOCK,
183184   };
184185
r245119r245120
191192      union { void* p; WindowHandle h; } cast;
192193      cast.h = _handle;
193194      uev.data1 = cast.p;
194     
195
195196      uev.data2 = _msg;
196197      uev.code = _code;
197198      SDL_PushEvent(&event);
r245119r245120
210211         : m_width(ENTRY_DEFAULT_WIDTH)
211212         , m_height(ENTRY_DEFAULT_HEIGHT)
212213         , m_aspectRatio(16.0f/9.0f)
214         , m_mx(0)
215         , m_my(0)
216         , m_mz(0)
213217         , m_mouseLock(false)
218         , m_fullscreen(false)
214219      {
215220         memset(s_translateKey, 0, sizeof(s_translateKey) );
216221         initTranslateKey(SDL_SCANCODE_ESCAPE,       Key::Esc);
r245119r245120
374379               case SDL_MOUSEMOTION:
375380                  {
376381                     const SDL_MouseMotionEvent& mev = event.motion;
382                     m_mx = mev.x;
383                     m_my = mev.y;
384
377385                     WindowHandle handle = findHandle(mev.windowID);
378386                     if (isValid(handle) )
379387                     {
380                        m_eventQueue.postMouseEvent(handle, mev.x, mev.y, 0);
388                        m_eventQueue.postMouseEvent(handle, m_mx, m_my, m_mz);
381389                     }
382390                  }
383391                  break;
r245119r245120
409417                  }
410418                  break;
411419
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
412444               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;
413471               case SDL_KEYUP:
414472                  {
415473                     const SDL_KeyboardEvent& kev = event.key;
r245119r245120
615673                        }
616674                        break;
617675
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
618684                     case SDL_USER_WINDOW_MOUSE_LOCK:
619685                        {
620686                           SDL_SetRelativeMouseMode(!!uev.code ? SDL_TRUE : SDL_FALSE);
r245119r245120
669735            m_width  = _width;
670736            m_height = _height;
671737
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
685738            SDL_SetWindowSize(m_window[_handle.idx], m_width, m_height);
686739            m_eventQueue.postSizeEvent(_handle, m_width, m_height);
687740         }
r245119r245120
722775
723776      int32_t m_mx;
724777      int32_t m_my;
778      int32_t m_mz;
725779      bool m_mouseLock;
780      bool m_fullscreen;
726781   };
727782
728783   static Context s_ctx;
r245119r245120
805860      sdlPostEvent(SDL_USER_WINDOW_TOGGLE_FRAME, _handle);
806861   }
807862
863   void toggleFullscreen(WindowHandle _handle)
864   {
865      sdlPostEvent(SDL_USER_WINDOW_TOGGLE_FULL_SCREEN, _handle);
866   }
867
808868   void setMouseLock(WindowHandle _handle, bool _lock)
809869   {
810870      sdlPostEvent(SDL_USER_WINDOW_MOUSE_LOCK, _handle, NULL, _lock);
trunk/3rdparty/bgfx/examples/common/entry/entry_windows.cpp
r245119r245120
706706                  ScreenToClient(_hwnd, &pt);
707707                  int32_t mx = pt.x;
708708                  int32_t my = pt.y;
709                  m_mz += GET_WHEEL_DELTA_WPARAM(_wparam);
709                  m_mz += GET_WHEEL_DELTA_WPARAM(_wparam)/WHEEL_DELTA;
710710                  m_eventQueue.postMouseEvent(findHandle(_hwnd), mx, my, m_mz);
711711               }
712712               break;
r245119r245120
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
10701075   void setMouseLock(WindowHandle _handle, bool _lock)
10711076   {
10721077      PostMessage(s_ctx.m_hwnd[0], WM_USER_WINDOW_MOUSE_LOCK, _handle.idx, _lock);
trunk/3rdparty/bgfx/examples/common/entry/entry_winrt.cpp
r245119r245120
175175      BX_UNUSED(_handle);
176176   }
177177
178   void toggleFullscreen(WindowHandle _handle)
179   {
180      BX_UNUSED(_handle);
181   }
182
178183   void setMouseLock(WindowHandle _handle, bool _lock)
179184   {
180185      BX_UNUSED(_handle, _lock);
trunk/3rdparty/bgfx/examples/common/entry/entry_x11.cpp
r245119r245120
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;
270274      }
271275
272276      int32_t run(int _argc, char** _argv)
r245119r245120
367371                  case ButtonRelease:
368372                     {
369373                        const XButtonEvent& xbutton = event.xbutton;
370                        MouseButton::Enum mb;
374                        MouseButton::Enum mb = MouseButton::None;
371375                        switch (xbutton.button)
372376                        {
373377                           case Button1: mb = MouseButton::Left;   break;
374378                           case Button2: mb = MouseButton::Middle; break;
375379                           case Button3: mb = MouseButton::Right;  break;
376                           default:      mb = MouseButton::None;   break;
380                           case Button4: ++m_mz; break;
381                           case Button5: --m_mz; break;
377382                        }
378383
384                        WindowHandle handle = findHandle(xbutton.window);
379385                        if (MouseButton::None != mb)
380386                        {
381                           WindowHandle handle = findHandle(xbutton.window);
382387                           m_eventQueue.postMouseEvent(handle
383388                              , xbutton.x
384389                              , xbutton.y
r245119r245120
387392                              , event.type == ButtonPress
388393                              );
389394                        }
395                        else
396                        {
397                           m_eventQueue.postMouseEvent(handle
398                                 , m_mx
399                                 , m_my
400                                 , m_mz
401                                 );
402                        }
390403                     }
391404                     break;
392405
r245119r245120
394407                     {
395408                        const XMotionEvent& xmotion = event.xmotion;
396409                        WindowHandle handle = findHandle(xmotion.window);
410
411                        m_mx = xmotion.x;
412                        m_my = xmotion.y;
413
397414                        m_eventQueue.postMouseEvent(handle
398                              , xmotion.x
399                              , xmotion.y
400                              , 0
415                              , m_mx
416                              , m_my
417                              , m_mz
401418                              );
402419                     }
403420                     break;
r245119r245120
543560      uint8_t m_modifiers;
544561      bool m_exit;
545562
563      int32_t m_mx;
564      int32_t m_my;
565      int32_t m_mz;
566
546567      EventQueue m_eventQueue;
547568      bx::LwMutex m_lock;
548569      bx::HandleAllocT<ENTRY_CONFIG_MAX_WINDOWS> m_windowAlloc;
r245119r245120
643664      BX_UNUSED(_handle);
644665   }
645666
667   void toggleFullscreen(WindowHandle _handle)
668   {
669      BX_UNUSED(_handle);
670   }
671
646672   void setMouseLock(WindowHandle _handle, bool _lock)
647673   {
648674      BX_UNUSED(_handle, _lock);
trunk/3rdparty/bgfx/examples/common/imgui/fs_imgui_latlong.bin.h
r245119r245120
1static const uint8_t fs_imgui_latlong_glsl[646] =
1static const uint8_t fs_imgui_latlong_glsl[649] =
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, 0x4e, 0x02, 0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, // ...N...varying h
6   0x00, 0x01, 0x00, 0x51, 0x02, 0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, // ...Q...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
r245119r245120
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, 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,                                                             // ;.}...
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;.}...
4444};
45static const uint8_t fs_imgui_latlong_dx9[553] =
45static const uint8_t fs_imgui_latlong_dx9[537] =
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, 0x04, 0x02, 0x00, 0x03, 0xff, 0xff, 0xfe, 0xff, 0x30, 0x00, 0x43, 0x54, 0x41, 0x42, // ..........0.CTAB
49   0x01, 0x00, 0xf4, 0x01, 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.......
r245119r245120
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, 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.
74   0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x05, 0x80, 0x01, 0x00, 0xc5, 0x80, 0x02, 0x00, 0x55, 0x81, // ..............U.
7675   0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x02, 0x80, 0x02, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x02, // ................
7776   0x00, 0x00, 0x08, 0x80, 0x00, 0x00, 0x00, 0xa0, 0x5f, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0x80, // ........_.......
7877   0x00, 0x00, 0xe4, 0x80, 0x00, 0x08, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x07, 0x80, // ................
r245119r245120
8483{
8584   0x46, 0x53, 0x48, 0x03, 0x6f, 0x1e, 0x3e, 0x3c, 0x01, 0x00, 0x11, 0x75, 0x5f, 0x69, 0x6d, 0x61, // FSH.o.><...u_ima
8685   0x67, 0x65, 0x4c, 0x6f, 0x64, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x15, 0x00, 0x30, 0x0a, // geLodEnabled..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...
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...
8988   0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, // ....,...........
9089   0x49, 0x53, 0x47, 0x4e, 0x50, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, // ISGNP...........
9190   0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // 8...............
r245119r245120
101100   0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x30, 0x00, 0x04, 0x00, 0x70, 0x10, 0x00, // .`......X0...p..
102101   0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x62, 0x10, 0x00, 0x03, 0x32, 0x10, 0x10, 0x00, // ....UU..b...2...
103102   0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ....e.... ......
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...............
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...
110109   0x00, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, 0x06, 0x00, 0xd0, 0x00, 0x00, 0x62, 0x00, 0x10, 0x00, // ....M.......b...
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~......
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~......
117116   0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x80, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, // .`........ .....
118117   0xa3, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, 0x72, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ....6...r ......
119118   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
r245119r245120
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)*cos(phi);
24   result.x = -sin(theta)*sin(phi);
2525   result.y = cos(theta);
26   result.z = -sin(theta)*sin(phi);
26   result.z = -sin(theta)*cos(phi);
2727
2828   return result;
2929}
trunk/3rdparty/bgfx/examples/common/imgui/imgui.cpp
r245119r245120
387387      , m_textureHeight(512)
388388      , m_halfTexel(0.0f)
389389      , m_nvg(NULL)
390      , m_view(31)
390      , m_view(255)
391      , m_surfaceWidth(0)
392      , m_surfaceHeight(0)
391393      , m_viewWidth(0)
392394      , m_viewHeight(0)
393395      , m_currentFontIdx(0)
r245119r245120
810812      m_char = _inputChar;
811813   }
812814
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)
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)
814816   {
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
820832      bgfx::setViewName(_view, "IMGUI");
821833      bgfx::setViewSeq(_view, true);
822834
823835      const bgfx::HMD* hmd = bgfx::getHMD();
824836      if (NULL != hmd)
825837      {
826         m_viewWidth  = _width / 2;
838         m_viewWidth = _width / 2;
839         m_surfaceWidth = _surfaceWidth / 2;
827840
828841         float proj[16];
829842         bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 100.0f);
r245119r245120
836849         const float offset1 = -proj[8] + (hmd->eye[1].viewOffset[0] / dist * proj[0]);
837850
838851         float ortho[2][16];
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);
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);
843856         bgfx::setViewTransform(_view, NULL, ortho[0], BGFX_VIEW_STEREO, ortho[1]);
844857         bgfx::setViewRect(_view, 0, 0, hmd->width, hmd->height);
845858      }
846859      else
847860      {
848861         float ortho[16];
849         bx::mtxOrtho(ortho, 0.0f, (float)m_viewWidth, (float)m_viewHeight, 0.0f, 0.0f, 1000.0f);
862         bx::mtxOrtho(ortho, 0.0f, (float)m_surfaceWidth, (float)m_surfaceHeight, 0.0f, 0.0f, 1000.0f);
850863         bgfx::setViewTransform(_view, NULL, ortho);
851864         bgfx::setViewRect(_view, 0, 0, _width, _height);
852865      }
853866
854      updateInput(_mx, _my, _button, _scroll, _inputChar);
867      updateInput(mx, my, _button, _scroll, _inputChar);
855868
856869      m_hot = m_hotToBe;
857870      m_hotToBe = 0;
r245119r245120
883896
884897      clearInput();
885898
899      nvgEndFrame(m_nvg);
886900      IMGUI_endFrame();
887901   }
888902
r245119r245120
936950         setEnabled(m_areaId);
937951      }
938952
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             );
953      nvgScissor(m_nvg, area);
945954
946955      m_insideArea |= area.m_inside;
947956
r245119r245120
10791088         }
10801089      }
10811090
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             );
1091      nvgScissor(m_nvg, parentArea);
10881092   }
10891093
10901094   bool beginArea(const char* _name, int32_t _x, int32_t _y, int32_t _width, int32_t _height, bool _enabled, int32_t _r)
r245119r245120
11581162      }
11591163      area.m_scissorEnabled = true;
11601164
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             );
1165      nvgScissor(m_nvg, area);
11681166
11691167      m_insideArea |= area.m_inside;
11701168      return area.m_inside;
r245119r245120
11721170
11731171   void endArea()
11741172   {
1173      m_areaId.pop();
11751174      nvgResetScissor(m_nvg);
1176      nvgEndFrame(m_nvg);
11771175   }
11781176
11791177   bool button(const char* _text, bool _enabled, ImguiAlign::Enum _align, uint32_t _rgb0, int32_t _r)
r245119r245120
12021200          //||  ImguiAlign::CenterIndented == _align).
12031201      {
12041202         xx = area.m_widgetX;
1205         width = area.m_widgetW - (area.m_widgetX-area.m_scissorX);
1203         width = area.m_widgetW - (area.m_widgetX-area.m_contentX);
12061204      }
12071205
12081206      const bool enabled = _enabled && isEnabled(m_areaId);
r245119r245120
13851383          //||  ImguiAlign::CenterIndented == _align).
13861384      {
13871385         xx = area.m_widgetX;
1388         width = area.m_widgetW - (area.m_widgetX-area.m_scissorX);
1386         width = area.m_widgetW - (area.m_widgetX-area.m_contentX);
13891387      }
13901388
13911389      const bool drawLabel = (NULL != _label && _label[0] != '\0');
r245119r245120
14051403      {
14061404         const size_t cursor = size_t(strlen(_str));
14071405
1408         if (m_char == 0x08) //backspace
1406         if (m_char == 0x08 || m_char == 0x7f) //backspace or delete
14091407         {
14101408            _str[cursor-1] = '\0';
14111409         }
r245119r245120
15241522          //||  ImguiAlign::CenterIndented == _align).
15251523      {
15261524         xx = area.m_widgetX;
1527         width = area.m_widgetW - (area.m_widgetX-area.m_scissorX);
1525         width = area.m_widgetW - (area.m_widgetX-area.m_contentX);
15281526      }
15291527
15301528      uint8_t selected = _selected;
r245119r245120
17441742          //||  ImguiAlign::CenterIndented == _align).
17451743      {
17461744         xx = area.m_widgetX;
1747         width = area.m_widgetW - (area.m_widgetX-area.m_scissorX);
1745         width = area.m_widgetW - (area.m_widgetX-area.m_contentX);
17481746      }
17491747
17501748      const int32_t height = width/2;
r245119r245120
17971795          //||  ImguiAlign::CenterIndented == _align).
17981796      {
17991797         xx = area.m_widgetX;
1800         width = area.m_widgetW - (area.m_widgetX-area.m_scissorX);
1798         width = area.m_widgetW - (area.m_widgetX-area.m_contentX);
18011799      }
18021800
18031801      const bool adjustHeight = (_cross && _sameHeight);
r245119r245120
20232021         xx = -borderSize;
20242022         yy = -1;
20252023         width = 2*borderSize+1;
2026         height = m_viewHeight;
2024         height = m_surfaceHeight+1;
20272025         triX = 0;
2028         triY = (m_viewHeight-triSize)/2;
2026         triY = (m_surfaceHeight-triSize)/2;
20292027         orientation = _checked ? TriangleOrientation::Left : TriangleOrientation::Right;
20302028      }
20312029      else if (ImguiBorder::Right == _border)
20322030      {
2033         xx = m_viewWidth - borderSize;
2031         xx = m_surfaceWidth - borderSize;
20342032         yy = -1;
20352033         width = 2*borderSize+1;
2036         height = m_viewHeight;
2037         triX = m_viewWidth - triSize - 2;
2038         triY = (m_viewHeight-width)/2;
2034         height = m_surfaceHeight+1;
2035         triX = m_surfaceWidth - triSize - 2;
2036         triY = (m_surfaceHeight-width)/2;
20392037         orientation = _checked ? TriangleOrientation::Right : TriangleOrientation::Left;
20402038      }
20412039      else if (ImguiBorder::Top == _border)
20422040      {
20432041         xx = 0;
20442042         yy = -borderSize;
2045         width = m_viewWidth;
2043         width = m_surfaceWidth;
20462044         height = 2*borderSize;
2047         triX = (m_viewWidth-triSize)/2;
2045         triX = (m_surfaceWidth-triSize)/2;
20482046         triY = 0;
20492047         orientation = _checked ? TriangleOrientation::Up : TriangleOrientation::Down;
20502048      }
20512049      else //if (ImguiBorder::Bottom == _border).
20522050      {
20532051         xx = 0;
2054         yy = m_viewHeight - borderSize;
2055         width = m_viewWidth;
2052         yy = m_surfaceHeight - borderSize;
2053         width = m_surfaceWidth;
20562054         height = 2*borderSize;
2057         triX = (m_viewWidth-triSize)/2;
2058         triY = m_viewHeight-triSize;
2055         triX = (m_surfaceWidth-triSize)/2;
2056         triY = m_surfaceHeight-triSize;
20592057         orientation = _checked ? TriangleOrientation::Down : TriangleOrientation::Up;
20602058      }
20612059
r245119r245120
21462144          //||  ImguiAlign::CenterIndented == _align).
21472145      {
21482146         xx = area.m_widgetX;
2149         width = area.m_widgetW - (area.m_widgetX-area.m_scissorX);
2147         width = area.m_widgetW - (area.m_widgetX-area.m_contentX);
21502148      }
21512149
21522150      drawRoundedRect( (float)xx, (float)yy, (float)width, (float)height, 4.0f, imguiRGBA(0, 0, 0, 128) );
r245119r245120
22642262      area.m_widgetY += _height;
22652263   }
22662264
2267   void separatorLine(uint16_t _height)
2265   void separatorLine(uint16_t _height, ImguiAlign::Enum _align)
22682266   {
22692267      Area& area = getCurrentArea();
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;
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
22742293      area.m_widgetY += _height;
22752294
22762295      drawRect( (float)xx
22772296            , (float)yy
2278            , (float)rectWidth
2279            , (float)rectHeight
2297            , (float)width
2298            , (float)height
22802299            , imguiRGBA(255, 255, 255, 32)
22812300            );
22822301   }
r245119r245120
30473066      const Area& area = getCurrentArea();
30483067      if (area.m_scissorEnabled)
30493068      {
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
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
30543079                     );
30553080      }
30563081      else
r245119r245120
30593084      }
30603085   }
30613086
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
30623104   template <typename Ty, uint16_t Max=64>
30633105   struct IdStack
30643106   {
r245119r245120
31463188   NVGcontext* m_nvg;
31473189
31483190   uint8_t m_view;
3191   uint16_t m_surfaceWidth;
3192   uint16_t m_surfaceHeight;
31493193   uint16_t m_viewWidth;
31503194   uint16_t m_viewHeight;
31513195
r245119r245120
32023246   return handle;
32033247}
32043248
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
32053254void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, char _inputChar, uint8_t _view)
32063255{
3207   s_imgui.beginFrame(_mx, _my, _button, _scroll, _width, _height, _inputChar, _view);
3256   s_imgui.beginFrame(_mx, _my, _button, _scroll, _width, _height, _width, _height, _inputChar, _view);
32083257}
32093258
32103259void imguiEndFrame()
r245119r245120
32873336   s_imgui.separator(_height);
32883337}
32893338
3290void imguiSeparatorLine(uint16_t _height)
3339void imguiSeparatorLine(uint16_t _height, ImguiAlign::Enum _align)
32913340{
3292   s_imgui.separatorLine(_height);
3341   s_imgui.separatorLine(_height, _align);
32933342}
32943343
32953344int32_t imguiGetWidgetX()
trunk/3rdparty/bgfx/examples/common/imgui/imgui.h
r245119r245120
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 = 31);
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);
140141void imguiEndFrame();
141142
142143void imguiDrawText(int _x, int _y, ImguiTextAlign::Enum _align, const char* _text, uint32_t _argb);
r245119r245120
158159void imguiIndent(uint16_t _width = IMGUI_INDENT_VALUE);
159160void imguiUnindent(uint16_t _width = IMGUI_INDENT_VALUE);
160161void imguiSeparator(uint16_t _height = IMGUI_SEPARATOR_VALUE);
161void imguiSeparatorLine(uint16_t _height = IMGUI_SEPARATOR_VALUE);
162void imguiSeparatorLine(uint16_t _height = IMGUI_SEPARATOR_VALUE, ImguiAlign::Enum = ImguiAlign::LeftIndented);
162163
163164int32_t imguiGetWidgetX();
164165int32_t imguiGetWidgetY();
trunk/3rdparty/bgfx/examples/common/imgui/ocornut_imgui.cpp
r245119r245120
8181
8282   void create(const void* _data, uint32_t _size, float _fontSize)
8383   {
84      m_viewId = 31;
84      m_viewId = 255;
8585
8686      ImGuiIO& io = ImGui::GetIO();
8787      io.DisplaySize = ImVec2(1280.0f, 720.0f);
r245119r245120
165165
166166      ImGui::NewFrame();
167167
168//      ImGui::ShowTestWindow();
168      //ImGui::ShowTestWindow(); //Debug only.
169169   }
170170
171171   void endFrame()
trunk/3rdparty/bgfx/examples/common/nanovg/nanovg.cpp
r245119r245120
296296   free(ctx);
297297}
298298
299void nvgBeginFrame(NVGcontext* ctx, int windowWidth, int windowHeight, float devicePixelRatio)
299void nvgBeginFrameScaled(NVGcontext* ctx, int windowWidth, int windowHeight, int surfaceWidth, int surfaceHeight, 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,
r245119r245120
307307   nvgReset(ctx);
308308
309309   nvg__setDevicePixelRatio(ctx, devicePixelRatio);
310   
311   ctx->params.renderViewport(ctx->params.userPtr, windowWidth, windowHeight);
312310
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
319324void nvgCancelFrame(NVGcontext* ctx)
320325{
321326   ctx->params.renderCancel(ctx->params.userPtr);
trunk/3rdparty/bgfx/examples/common/nanovg/nanovg.h
r245119r245120
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);
119120
120121// Cancels drawing the current frame.
121122void nvgCancelFrame(NVGcontext* ctx);
r245119r245120
588589   int (*renderDeleteTexture)(void* uptr, int image);
589590   int (*renderUpdateTexture)(void* uptr, int image, int x, int y, int w, int h, const unsigned char* data);
590591   int (*renderGetTextureSize)(void* uptr, int image, int* w, int* h);
591   void (*renderViewport)(void* uptr, int width, int height);
592   void (*renderViewport)(void* uptr, int width, int height, int surfaceWidth, int surfaceHeight);
592593   void (*renderCancel)(void* uptr);
593594   void (*renderFlush)(void* uptr);
594595   void (*renderFill)(void* uptr, NVGpaint* paint, NVGscissor* scissor, float fringe, const float* bounds, const NVGpath* paths, int npaths);
r245119r245120
599600typedef struct NVGparams NVGparams;
600601
601602NVGcontext* nvgCreate(int edgeaa, unsigned char viewid);
603void nvgViewId(struct NVGcontext* ctx, unsigned char viewid);
602604void nvgDelete(struct NVGcontext* ctx);
603605
604606// Contructor and destructor, called by the render back-end.
trunk/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp
r245119r245120
132132
133133      struct GLNVGtexture* textures;
134134      float view[2];
135      float surface[2];
135136      int ntextures;
136137      int ctextures;
137138      int textureId;
r245119r245120
516517      gl->th = handle;
517518   }
518519
519   static void nvgRenderViewport(void* _userPtr, int width, int height)
520   static void nvgRenderViewport(void* _userPtr, int width, int height, int surfaceWidth, int surfaceHeight)
520521   {
521522      struct GLNVGcontext* gl = (struct GLNVGcontext*)_userPtr;
522523      gl->view[0] = (float)width;
523524      gl->view[1] = (float)height;
525      gl->surface[0] = (float)surfaceWidth;
526      gl->surface[1] = (float)surfaceHeight;
524527      bgfx::setViewRect(gl->viewid, 0, 0, width, height);
525528   }
526529
r245119r245120
720723                        );
721724         }
722725
723         bgfx::setUniform(gl->u_viewSize, gl->view);
726         bgfx::setUniform(gl->u_viewSize, gl->surface);
724727
725728         for (uint32_t ii = 0, num = gl->ncalls; ii < num; ++ii)
726729         {
r245119r245120
10511054   return NULL;
10521055}
10531056
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
10541064void nvgDelete(struct NVGcontext* ctx)
10551065{
10561066   nvgDeleteInternal(ctx);
trunk/3rdparty/bgfx/examples/runtime/shaders/dx11/fs_update_3d.bin
r0r245120
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
r0r245120
Previous 199869 Revisions Next


© 1997-2024 The MAME Team