Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

imgui.cpp 317KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004
  1. // ImGui library v1.20
  2. // See ImGui::ShowTestWindow() for sample code.
  3. // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase.
  4. // Get latest version at https://github.com/ocornut/imgui
  5. // Developed by Omar Cornut and contributors.
  6. /*
  7. Index
  8. - MISSION STATEMENT
  9. - END-USER GUIDE
  10. - PROGRAMMER GUIDE
  11. - API BREAKING CHANGES
  12. - TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS
  13. - ISSUES & TODO-LIST
  14. - CODE
  15. - SAMPLE CODE
  16. - FONT DATA
  17. MISSION STATEMENT
  18. =================
  19. - easy to use to create code-driven and data-driven tools
  20. - easy to use to create ad hoc short-lived tools and long-lived, more elaborate tools
  21. - easy to hack and improve
  22. - minimize screen real-estate usage
  23. - minimize setup and maintenance
  24. - minimize state storage on user side
  25. - portable, minimize dependencies, run on target (consoles, etc.)
  26. - 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)
  27. - read about immediate-mode GUI principles @ http://mollyrocket.com/861, http://mollyrocket.com/forums/index.html
  28. Designed for developers and content-creators, not the typical end-user! Some of the weaknesses includes:
  29. - doesn't look fancy, doesn't animate
  30. - limited layout features, intricate layouts are typically crafted in code
  31. - occasionally use statically sized buffers for string manipulations - won't crash, but some long text may be clipped
  32. END-USER GUIDE
  33. ==============
  34. - double-click title bar to collapse window
  35. - click upper right corner to close a window, available when 'bool* p_opened' is passed to ImGui::Begin()
  36. - click and drag on lower right corner to resize window
  37. - click and drag on any empty space to move window
  38. - double-click/double-tap on lower right corner grip to auto-fit to content
  39. - TAB/SHIFT+TAB to cycle through keyboard editable fields
  40. - use mouse wheel to scroll
  41. - use CTRL+mouse wheel to zoom window contents (if IO.FontAllowScaling is true)
  42. - CTRL+Click on a slider to input value as text
  43. - text editor:
  44. - Hold SHIFT or use mouse to select text.
  45. - CTRL+Left/Right to word jump
  46. - CTRL+Shift+Left/Right to select words
  47. - CTRL+A our Double-Click to select all
  48. - CTRL+X,CTRL+C,CTRL+V to use OS clipboard
  49. - CTRL+Z,CTRL+Y to undo/redo
  50. - ESCAPE to revert text to its original value
  51. - You can apply arithmetic operators +,*,/ on numerical values. Use +- to subtract (because - would set a negative value!)
  52. PROGRAMMER GUIDE
  53. ================
  54. - 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.
  55. - see ImGui::ShowTestWindow() for user-side sample code
  56. - see examples/ folder for standalone sample applications.
  57. - customization: use the style editor to tweak the look of the interface (e.g. if you want a more compact UI or a different color scheme), and report values in your code.
  58. - getting started:
  59. - initialisation: call ImGui::GetIO() and fill the 'Settings' data.
  60. - every frame:
  61. 1/ in your mainloop or right after you got your keyboard/mouse info, call ImGui::GetIO() and fill the 'Input' data, then call ImGui::NewFrame().
  62. 2/ use any ImGui function you want between NewFrame() and Render()
  63. 3/ ImGui::Render() to render all the accumulated command-lists. it will call your RenderDrawListFn handler that you set in the IO structure.
  64. - all rendering information are stored into command-lists until ImGui::Render() is called.
  65. - effectively it means you can create widgets at any time in your code, regardless of "update" vs "render" considerations.
  66. - refer to the examples applications in the examples/ folder for instruction on how to setup your code.
  67. - a typical application skeleton may be:
  68. // Application init
  69. // TODO: Fill all settings fields of the io structure
  70. ImGuiIO& io = ImGui::GetIO();
  71. io.DisplaySize.x = 1920.0f;
  72. io.DisplaySize.y = 1280.0f;
  73. io.DeltaTime = 1.0f/60.0f;
  74. io.IniFilename = "imgui.ini";
  75. // Application main loop
  76. while (true)
  77. {
  78. // 1/ get low-level input
  79. // e.g. on Win32, GetKeyboardState(), or poll your events, etc.
  80. // 2/ TODO: Fill all 'Input' fields of io structure and call NewFrame
  81. ImGuiIO& io = ImGui::GetIO();
  82. io.MousePos = ...
  83. io.KeysDown[i] = ...
  84. ImGui::NewFrame();
  85. // 3/ most of your application code here - you can use any of ImGui::* functions between NewFrame() and Render() calls
  86. GameUpdate();
  87. GameRender();
  88. // 4/ render & swap video buffers
  89. ImGui::Render();
  90. // swap video buffer, etc.
  91. }
  92. - after calling ImGui::NewFrame() you can read back 'ImGui::GetIO().WantCaptureMouse' and 'ImGui::GetIO().WantCaptureKeyboard' to tell
  93. if ImGui wants to use your inputs. so typically can hide the mouse inputs from the rest of your application if ImGui is using it.
  94. API BREAKING CHANGES
  95. ====================
  96. Occasionally introducing changes that are breaking the API. The breakage are generally minor and easy to fix.
  97. 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.
  98. - 2014/12/10 (1.18) removed SetNewWindowDefaultPos() in favor of new generic API SetNextWindowPos(pos, ImGuiSetCondition_FirstUseEver)
  99. - 2014/11/28 (1.17) moved IO.Font*** options to inside the IO.Font-> structure.
  100. - 2014/11/26 (1.17) reworked syntax of IMGUI_ONCE_UPON_A_FRAME helper macro to increase compiler compatibility
  101. - 2014/11/07 (1.15) renamed IsHovered() to IsItemHovered()
  102. - 2014/10/02 (1.14) renamed IMGUI_INCLUDE_IMGUI_USER_CPP to IMGUI_INCLUDE_IMGUI_USER_INL and imgui_user.cpp to imgui_user.inl (more IDE friendly)
  103. - 2014/09/25 (1.13) removed 'text_end' parameter from IO.SetClipboardTextFn (the string is now always zero-terminated for simplicity)
  104. - 2014/09/24 (1.12) renamed SetFontScale() to SetWindowFontScale()
  105. - 2014/09/24 (1.12) moved IM_MALLOC/IM_REALLOC/IM_FREE preprocessor defines to IO.MemAllocFn/IO.MemReallocFn/IO.MemFreeFn
  106. - 2014/08/30 (1.09) removed IO.FontHeight (now computed automatically)
  107. - 2014/08/30 (1.09) moved IMGUI_FONT_TEX_UV_FOR_WHITE preprocessor define to IO.FontTexUvForWhite
  108. - 2014/08/28 (1.09) changed the behavior of IO.PixelCenterOffset following various rendering fixes
  109. TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS
  110. ============================================
  111. If text or lines are blurry when integrating ImGui in your engine:
  112. - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
  113. - try adjusting ImGui::GetIO().PixelCenterOffset to 0.5f or 0.375f
  114. If you are confused about the meaning or use of ID in ImGui:
  115. - some widgets requires state to be carried over multiple frames (most typically ImGui often wants remember what is the "active" widget).
  116. to do so they need an unique ID. unique ID are typically derived from a string label, an indice or a pointer.
  117. when you call Button("OK") the button shows "OK" and also use "OK" as an ID.
  118. - ID are uniquely scoped within Windows so no conflict can happen if you have two buttons called "OK" in two different Windows.
  119. within a same Window, use PushID() / PopID() to easily create scopes and avoid ID conflicts.
  120. so if you have a loop creating "multiple" items, you can use PushID() / PopID() with the index of each item, or their pointer, etc.
  121. some functions like TreeNode() implicitly creates a scope for you by calling PushID()
  122. - when dealing with trees, ID are important because you want to preserve the opened/closed state of tree nodes.
  123. depending on your use cases you may want to use strings, indices or pointers as ID. experiment and see what makes more sense!
  124. e.g. When displaying a single object, using a static string as ID will preserve your node open/closed state when the targeted object change
  125. e.g. When displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state per object
  126. - when passing a label you can optionally specify extra unique ID information within the same string using "##". This helps solving the simpler collision cases.
  127. e.g. "Label" display "Label" and uses "Label" as ID
  128. e.g. "Label##Foobar" display "Label" and uses "Label##Foobar" as ID
  129. e.g. "##Foobar" display an empty label and uses "##Foobar" as ID
  130. - read articles about the imgui principles (see web links) to understand the requirement and use of ID.
  131. If you want to use a different font than the default:
  132. - read extra_fonts/README.txt for instructions. Examples fonts are also provided.
  133. - if you can only see text but no solid shapes or lines, make sure io.Font->TexUvForWhite is set to the texture coordinates of a pure white pixel in your texture!
  134. If you want to input Japanese/Chinese/Korean in the text input widget:
  135. - make sure you are using a font that can display the glyphs you want (see above paragraph about fonts)
  136. - to have the Microsoft IME cursor appears at the right location in the screen, setup a handler for the io.ImeSetInputScreenPosFn function:
  137. #include <Windows.h>
  138. #include <Imm.h>
  139. static void ImImpl_ImeSetInputScreenPosFn(int x, int y)
  140. {
  141. // Notify OS Input Method Editor of text input position
  142. HWND hwnd = glfwGetWin32Window(window);
  143. if (HIMC himc = ImmGetContext(hwnd))
  144. {
  145. COMPOSITIONFORM cf;
  146. cf.ptCurrentPos.x = x;
  147. cf.ptCurrentPos.y = y;
  148. cf.dwStyle = CFS_FORCE_POSITION;
  149. ImmSetCompositionWindow(himc, &cf);
  150. }
  151. }
  152. // Set pointer to handler in ImGuiIO structure
  153. io.ImeSetInputScreenPosFn = ImImpl_ImeSetInputScreenPosFn;
  154. - tip: the construct 'IMGUI_ONCE_UPON_A_FRAME { ... }' will evaluate to a 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.
  155. - tip: you can call Render() multiple times (e.g for VR renders), up to you to communicate the extra state to your RenderDrawListFn function.
  156. - tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug"
  157. - tip: read the ShowTestWindow() code for more example of how to use ImGui!
  158. ISSUES & TODO-LIST
  159. ==================
  160. - misc: merge or clarify ImVec4 / ImGuiAabb, they are essentially duplicate containers
  161. - window: add horizontal scroll
  162. - window: fix resize grip rendering scaling along with Rounding style setting
  163. - window: autofit feedback loop when user relies on any dynamic layout (window width multiplier, column). maybe just clearly drop manual autofit?
  164. - window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list.
  165. - widgets: switching from "widget-label" to "label-widget" would make it more convenient to integrate widgets in trees
  166. - widgets: clip text? hover clipped text shows it in a tooltip or in-place overlay
  167. - widgets: 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?
  168. - main: make IsHovered() 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
  169. - main: make IsHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode?
  170. - scrollbar: use relative mouse movement when first-clicking inside of scroll grab box.
  171. - scrollbar: make the grab visible and a minimum size for long scroll regions
  172. !- input number: very large int not reliably supported because of int<>float conversions.
  173. - input number: optional range min/max for Input*() functions
  174. - input number: holding [-]/[+] buttons could increase the step speed non-linearly (or user-controlled)
  175. - input number: use mouse wheel to step up/down
  176. - input number: non-decimal input.
  177. - layout: horizontal layout helper (github issue #97)
  178. - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 horrible layout code. item width should include frame padding.
  179. - columns: separator function or parameter that works within the column (currently Separator() bypass all columns)
  180. - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills)
  181. - columns: columns header to act as button (~sort op) and allow resize/reorder
  182. - columns: user specify columns size
  183. - combo: turn child handling code into pop up helper
  184. - list selection, concept of a selectable "block" (that can be multiple widgets)
  185. - menubar, menus
  186. - plot: make it easier for user to draw into the graph (e.g: draw basis, highlight certain points, 2d plots, multiple plots)
  187. - plot: "smooth" automatic scale, user give an input 0.0(full user scale) 1.0(full derived from value)
  188. - 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)
  189. - file selection widget -> build the tool in our codebase to improve model-dialog idioms (may or not lead to ImGui changes)
  190. - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt()
  191. - slider: initial absolute click is imprecise. change to relative movement slider? hide mouse cursor, allow more precise input using less screen-space.
  192. - text edit: clean up the horrible mess caused by converting UTF-8 <> wchar
  193. - text edit: centered text for slider or input text to it matches typical positioning.
  194. - text edit: flag to disable live update of the user buffer.
  195. - text edit: field resize behavior - field could stretch when being edited? hover tooltip shows more text?
  196. - text edit: add multi-line text edit
  197. - settings: write more decent code to allow saving/loading new fields
  198. - settings: api for per-tool simple persistent data (bool,int,float) in .ini file
  199. - log: LogButtons() options for specifying depth and/orhiding depth slider
  200. - log: have more control over the log scope (e.g. stop logging when leaving current tree node scope)
  201. - log: be able to right-click and log a window or tree-node into tty/file/clipboard / generalized context menu?
  202. - filters: set a current filter that tree node can automatically query to hide themselves
  203. - filters: handle wildcards (with implicit leading/trailing *), regexps
  204. - shortcuts: add a shortcut api, e.g. parse "&Save" and/or "Save (CTRL+S)", pass in to widgets or provide simple ways to use (button=activate, input=focus)
  205. ! keyboard: tooltip & combo boxes are messing up / not honoring keyboard tabbing
  206. - keyboard: full keyboard navigation and focus.
  207. - input: rework IO to be able to pass actual events to fix temporal aliasing issues.
  208. - input: support track pad style scrolling & slider edit.
  209. - tooltip: move to fit within screen (e.g. when mouse cursor is right of the screen).
  210. - clipboard: automatically transform \n into \n\r or equivalent for higher compatibility on windows
  211. - portability: big-endian test/support (github issue #81)
  212. - examples: add History support in the demo console application (pertinent to github issue #68).
  213. - misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL)
  214. - misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon?
  215. - style editor: add a button to output C code.
  216. - optimization/render: use indexed rendering to reduce vertex data cost (for remote/networked imgui)
  217. - optimization/render: move clip-rect to vertex data? would allow merging all commands
  218. - optimization/render: merge command-lists with same clip-rect into one even if they aren't sequential? (as long as in-between clip rectangle don't overlap)?
  219. - optimization/render: font exported by bmfont is not tight fit on vertical axis, incur unneeded pixel-shading cost.
  220. - optimization: turn some the various stack vectors into statically-sized arrays
  221. - optimization: better clipping for multi-component widgets
  222. - optimization: specialize for height based clipping first (assume widgets never go up + height tests before width tests?)
  223. */
  224. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  225. #define _CRT_SECURE_NO_WARNINGS
  226. #endif
  227. #include "imgui.h"
  228. #include <ctype.h> // toupper
  229. #include <math.h> // sqrtf
  230. #include <stdint.h> // intptr_t
  231. #include <stdio.h> // vsnprintf
  232. #include <new> // new (ptr)
  233. #ifdef _MSC_VER
  234. #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
  235. #endif
  236. // Clang warnings with -Weverything
  237. #ifdef __clang__
  238. #pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
  239. #pragma clang diagnostic ignored "-Wfloat-equal" // warning : comparing floating point with == or != is unsafe // storing and comparing against same constants ok.
  240. #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.
  241. #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.
  242. #pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference it.
  243. #endif
  244. //-------------------------------------------------------------------------
  245. // Forward Declarations
  246. //-------------------------------------------------------------------------
  247. static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat = false);
  248. static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL);
  249. static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true, float wrap_width = 0.0f);
  250. static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
  251. static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false);
  252. static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset = NULL);
  253. static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset = NULL);
  254. static void PushColumnClipRect(int column_index = -1);
  255. static bool IsClipped(const ImGuiAabb& aabb);
  256. static bool ClipAdvance(const ImGuiAabb& aabb);
  257. static bool IsMouseHoveringBox(const ImGuiAabb& box);
  258. static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true);
  259. static bool CloseWindowButton(bool* p_opened = NULL);
  260. static void FocusWindow(ImGuiWindow* window);
  261. static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs);
  262. // Helpers: String
  263. static int ImStricmp(const char* str1, const char* str2);
  264. static int ImStrnicmp(const char* str1, const char* str2, int count);
  265. static char* ImStrdup(const char *str);
  266. static size_t ImStrlenW(const ImWchar* str);
  267. static const char* ImStristr(const char* haystack, const char* needle, const char* needle_end);
  268. static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...);
  269. static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args);
  270. // Helpers: Data
  271. static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed);
  272. static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes = 0);
  273. // Helpers: Color Conversion
  274. static ImU32 ImConvertColorFloat4ToU32(const ImVec4& in);
  275. static void ImConvertColorRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v);
  276. static void ImConvertColorHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b);
  277. // Helpers: UTF-8 <> wchar
  278. static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int in_char); // return output UTF-8 bytes count
  279. static ptrdiff_t ImTextStrToUtf8(char* buf, size_t buf_size, const ImWchar* in_text, const ImWchar* in_text_end); // return output UTF-8 bytes count
  280. static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count
  281. static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count
  282. static int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count)
  283. static int ImTextCountUtf8BytesFromWchar(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string as UTF-8 code-points
  284. //-----------------------------------------------------------------------------
  285. // Platform dependent default implementations
  286. //-----------------------------------------------------------------------------
  287. static const char* GetClipboardTextFn_DefaultImpl();
  288. static void SetClipboardTextFn_DefaultImpl(const char* text);
  289. //-----------------------------------------------------------------------------
  290. // User facing structures
  291. //-----------------------------------------------------------------------------
  292. ImGuiStyle::ImGuiStyle()
  293. {
  294. Alpha = 1.0f; // Global alpha applies to everything in ImGui
  295. WindowPadding = ImVec2(8,8); // Padding within a window
  296. WindowMinSize = ImVec2(48,48); // Minimum window size
  297. WindowRounding = 9.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows
  298. FramePadding = ImVec2(4,3); // Padding within a framed rectangle (used by most widgets)
  299. ItemSpacing = ImVec2(8,4); // Horizontal and vertical spacing between widgets/lines
  300. ItemInnerSpacing = ImVec2(4,4); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
  301. TouchExtraPadding = ImVec2(0,0); // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much!
  302. AutoFitPadding = ImVec2(8,8); // Extra space after auto-fit (double-clicking on resize grip)
  303. WindowFillAlphaDefault = 0.70f; // Default alpha of window background, if not specified in ImGui::Begin()
  304. TreeNodeSpacing = 22.0f; // Horizontal spacing when entering a tree node
  305. ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns
  306. ScrollBarWidth = 16.0f; // Width of the vertical scroll bar
  307. Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
  308. Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
  309. Colors[ImGuiCol_Border] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
  310. Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.60f);
  311. Colors[ImGuiCol_FrameBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.30f); // Background of checkbox, radio button, plot, slider, text input
  312. Colors[ImGuiCol_TitleBg] = ImVec4(0.50f, 0.50f, 1.00f, 0.45f);
  313. Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.40f, 0.40f, 0.80f, 0.20f);
  314. Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.40f, 0.40f, 0.80f, 0.15f);
  315. Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.40f, 0.40f, 0.80f, 0.30f);
  316. Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.80f, 0.40f);
  317. Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 0.40f);
  318. Colors[ImGuiCol_ComboBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.99f);
  319. Colors[ImGuiCol_CheckHovered] = ImVec4(0.60f, 0.40f, 0.40f, 0.45f);
  320. Colors[ImGuiCol_CheckActive] = ImVec4(0.65f, 0.50f, 0.50f, 0.55f);
  321. Colors[ImGuiCol_CheckMark] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f);
  322. Colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
  323. Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f);
  324. Colors[ImGuiCol_Button] = ImVec4(0.67f, 0.40f, 0.40f, 0.60f);
  325. Colors[ImGuiCol_ButtonHovered] = ImVec4(0.67f, 0.40f, 0.40f, 1.00f);
  326. Colors[ImGuiCol_ButtonActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f);
  327. Colors[ImGuiCol_Header] = ImVec4(0.40f, 0.40f, 0.90f, 0.45f);
  328. Colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.90f, 0.80f);
  329. Colors[ImGuiCol_HeaderActive] = ImVec4(0.60f, 0.60f, 0.80f, 1.00f);
  330. Colors[ImGuiCol_Column] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
  331. Colors[ImGuiCol_ColumnHovered] = ImVec4(0.60f, 0.40f, 0.40f, 1.00f);
  332. Colors[ImGuiCol_ColumnActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f);
  333. Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
  334. Colors[ImGuiCol_ResizeGripHovered] = ImVec4(1.00f, 1.00f, 1.00f, 0.60f);
  335. Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.90f);
  336. Colors[ImGuiCol_CloseButton] = ImVec4(0.50f, 0.50f, 0.90f, 0.50f);
  337. Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.70f, 0.70f, 0.90f, 0.60f);
  338. Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.70f, 0.70f, 0.70f, 1.00f);
  339. Colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
  340. Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  341. Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  342. Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
  343. Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f);
  344. Colors[ImGuiCol_TooltipBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f);
  345. }
  346. ImGuiIO::ImGuiIO()
  347. {
  348. memset(this, 0, sizeof(*this));
  349. DisplaySize = ImVec2(-1.0f, -1.0f);
  350. DeltaTime = 1.0f/60.0f;
  351. IniSavingRate = 5.0f;
  352. IniFilename = "imgui.ini";
  353. LogFilename = "imgui_log.txt";
  354. Font = NULL;
  355. FontGlobalScale = 1.0f;
  356. FontAllowUserScaling = false;
  357. PixelCenterOffset = 0.0f;
  358. MousePos = ImVec2(-1,-1);
  359. MousePosPrev = ImVec2(-1,-1);
  360. MouseDoubleClickTime = 0.30f;
  361. MouseDoubleClickMaxDist = 6.0f;
  362. UserData = NULL;
  363. // User functions
  364. RenderDrawListsFn = NULL;
  365. MemAllocFn = malloc;
  366. MemReallocFn = realloc;
  367. MemFreeFn = free;
  368. GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependent default implementations
  369. SetClipboardTextFn = SetClipboardTextFn_DefaultImpl;
  370. ImeSetInputScreenPosFn = NULL;
  371. }
  372. // Pass in translated ASCII characters for text input.
  373. // - with glfw you can get those from the callback set in glfwSetCharCallback()
  374. // - on Windows you can get those using ToAscii+keyboard state, or via the VM_CHAR message
  375. void ImGuiIO::AddInputCharacter(ImWchar c)
  376. {
  377. const size_t n = ImStrlenW(InputCharacters);
  378. if (n + 1 < sizeof(InputCharacters) / sizeof(InputCharacters[0]))
  379. {
  380. InputCharacters[n] = c;
  381. InputCharacters[n+1] = 0;
  382. }
  383. }
  384. //-----------------------------------------------------------------------------
  385. // Helpers
  386. //-----------------------------------------------------------------------------
  387. #define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR)))
  388. #undef PI
  389. const float PI = 3.14159265358979323846f;
  390. #ifdef INT_MAX
  391. #define IM_INT_MAX INT_MAX
  392. #else
  393. #define IM_INT_MAX 2147483647
  394. #endif
  395. // Play it nice with Windows users. Notepad in 2014 still doesn't display text data with Unix-style \n.
  396. #ifdef _MSC_VER
  397. #define STR_NEWLINE "\r\n"
  398. #else
  399. #define STR_NEWLINE "\n"
  400. #endif
  401. // Math bits
  402. // We are keeping those static in the .cpp file so as not to leak them outside, in the case the user has implicit cast operators between ImVec2 and its own types.
  403. static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x*rhs, lhs.y*rhs); }
  404. //static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x/rhs, lhs.y/rhs); }
  405. static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x+rhs.x, lhs.y+rhs.y); }
  406. static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); }
  407. static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); }
  408. static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); }
  409. static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; }
  410. static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; }
  411. static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; }
  412. //static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; }
  413. static inline int ImMin(int lhs, int rhs) { return lhs < rhs ? lhs : rhs; }
  414. static inline int ImMax(int lhs, int rhs) { return lhs >= rhs ? lhs : rhs; }
  415. static inline float ImMin(float lhs, float rhs) { return lhs < rhs ? lhs : rhs; }
  416. static inline float ImMax(float lhs, float rhs) { return lhs >= rhs ? lhs : rhs; }
  417. static inline ImVec2 ImMin(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMin(lhs.x,rhs.x), ImMin(lhs.y,rhs.y)); }
  418. static inline ImVec2 ImMax(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMax(lhs.x,rhs.x), ImMax(lhs.y,rhs.y)); }
  419. static inline float ImClamp(float f, float mn, float mx) { return (f < mn) ? mn : (f > mx) ? mx : f; }
  420. static inline ImVec2 ImClamp(const ImVec2& f, const ImVec2& mn, ImVec2 mx) { return ImVec2(ImClamp(f.x,mn.x,mx.x), ImClamp(f.y,mn.y,mx.y)); }
  421. static inline float ImSaturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; }
  422. static inline float ImLerp(float a, float b, float t) { return a + (b - a) * t; }
  423. static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, const ImVec2& t) { return ImVec2(a.x + (b.x - a.x) * t.x, a.y + (b.y - a.y) * t.y); }
  424. static inline float ImLengthSqr(const ImVec2& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y; }
  425. static int ImStricmp(const char* str1, const char* str2)
  426. {
  427. int d;
  428. while ((d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; }
  429. return d;
  430. }
  431. static int ImStrnicmp(const char* str1, const char* str2, int count)
  432. {
  433. int d = 0;
  434. while (count > 0 && (d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; count--; }
  435. return d;
  436. }
  437. static char* ImStrdup(const char *str)
  438. {
  439. char *buff = (char*)ImGui::MemAlloc(strlen(str) + 1);
  440. IM_ASSERT(buff);
  441. strcpy(buff, str);
  442. return buff;
  443. }
  444. static size_t ImStrlenW(const ImWchar* str)
  445. {
  446. size_t n = 0;
  447. while (*str++)
  448. n++;
  449. return n;
  450. }
  451. static const char* ImStristr(const char* haystack, const char* needle, const char* needle_end)
  452. {
  453. if (!needle_end)
  454. needle_end = needle + strlen(needle);
  455. const char un0 = (char)toupper(*needle);
  456. while (*haystack)
  457. {
  458. if (toupper(*haystack) == un0)
  459. {
  460. const char* b = needle + 1;
  461. for (const char* a = haystack + 1; b < needle_end; a++, b++)
  462. if (toupper(*a) != toupper(*b))
  463. break;
  464. if (b == needle_end)
  465. return haystack;
  466. }
  467. haystack++;
  468. }
  469. return NULL;
  470. }
  471. // Pass data_size==0 for zero-terminated string
  472. static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed = 0)
  473. {
  474. static ImU32 crc32_lut[256] = { 0 };
  475. if (!crc32_lut[1])
  476. {
  477. const ImU32 polynomial = 0xEDB88320;
  478. for (ImU32 i = 0; i < 256; i++)
  479. {
  480. ImU32 crc = i;
  481. for (ImU32 j = 0; j < 8; j++)
  482. crc = (crc >> 1) ^ (ImU32(-int(crc & 1)) & polynomial);
  483. crc32_lut[i] = crc;
  484. }
  485. }
  486. ImU32 crc = ~seed;
  487. const unsigned char* current = (const unsigned char*)data;
  488. if (data_size > 0)
  489. {
  490. // Known size
  491. while (data_size--)
  492. crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++];
  493. }
  494. else
  495. {
  496. // Zero-terminated string
  497. while (unsigned char c = *current++)
  498. crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
  499. }
  500. return ~crc;
  501. }
  502. static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...)
  503. {
  504. va_list args;
  505. va_start(args, fmt);
  506. int w = vsnprintf(buf, buf_size, fmt, args);
  507. va_end(args);
  508. buf[buf_size-1] = 0;
  509. return (w == -1) ? buf_size : (size_t)w;
  510. }
  511. static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args)
  512. {
  513. int w = vsnprintf(buf, buf_size, fmt, args);
  514. buf[buf_size-1] = 0;
  515. return (w == -1) ? buf_size : (size_t)w;
  516. }
  517. static ImU32 ImConvertColorFloat4ToU32(const ImVec4& in)
  518. {
  519. ImU32 out = ((ImU32)(ImSaturate(in.x)*255.f));
  520. out |= ((ImU32)(ImSaturate(in.y)*255.f) << 8);
  521. out |= ((ImU32)(ImSaturate(in.z)*255.f) << 16);
  522. out |= ((ImU32)(ImSaturate(in.w)*255.f) << 24);
  523. return out;
  524. }
  525. // Convert rgb floats ([0-1],[0-1],[0-1]) to hsv floats ([0-1],[0-1],[0-1]), from Foley & van Dam p592
  526. // Optimized http://lolengine.net/blog/2013/01/13/fast-rgb-to-hsv
  527. static void ImConvertColorRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v)
  528. {
  529. float K = 0.f;
  530. if (g < b)
  531. {
  532. const float tmp = g; g = b; b = tmp;
  533. K = -1.f;
  534. }
  535. if (r < g)
  536. {
  537. const float tmp = r; r = g; g = tmp;
  538. K = -2.f / 6.f - K;
  539. }
  540. const float chroma = r - (g < b ? g : b);
  541. out_h = fabsf(K + (g - b) / (6.f * chroma + 1e-20f));
  542. out_s = chroma / (r + 1e-20f);
  543. out_v = r;
  544. }
  545. // Convert hsv floats ([0-1],[0-1],[0-1]) to rgb floats ([0-1],[0-1],[0-1]), from Foley & van Dam p593
  546. // also http://en.wikipedia.org/wiki/HSL_and_HSV
  547. static void ImConvertColorHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b)
  548. {
  549. if (s == 0.0f)
  550. {
  551. // gray
  552. out_r = out_g = out_b = v;
  553. return;
  554. }
  555. h = fmodf(h, 1.0f) / (60.0f/360.0f);
  556. int i = (int)h;
  557. float f = h - (float)i;
  558. float p = v * (1.0f - s);
  559. float q = v * (1.0f - s * f);
  560. float t = v * (1.0f - s * (1.0f - f));
  561. switch (i)
  562. {
  563. case 0: out_r = v; out_g = t; out_b = p; break;
  564. case 1: out_r = q; out_g = v; out_b = p; break;
  565. case 2: out_r = p; out_g = v; out_b = t; break;
  566. case 3: out_r = p; out_g = q; out_b = v; break;
  567. case 4: out_r = t; out_g = p; out_b = v; break;
  568. case 5: default: out_r = v; out_g = p; out_b = q; break;
  569. }
  570. }
  571. // Load file content into memory
  572. // Memory allocated with ImGui::MemAlloc(), must be freed by user using ImGui::MemFree()
  573. static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes)
  574. {
  575. IM_ASSERT(filename && file_open_mode && out_file_data && out_file_size);
  576. IM_ASSERT(padding_bytes >= 0);
  577. *out_file_data = NULL;
  578. *out_file_size = 0;
  579. FILE* f;
  580. if ((f = fopen(filename, file_open_mode)) == NULL)
  581. return false;
  582. long file_size_signed;
  583. if (fseek(f, 0, SEEK_END) || (file_size_signed = ftell(f)) == -1 || fseek(f, 0, SEEK_SET))
  584. {
  585. fclose(f);
  586. return false;
  587. }
  588. size_t file_size = (size_t)file_size_signed;
  589. void* file_data = ImGui::MemAlloc(file_size + padding_bytes);
  590. if (file_data == NULL)
  591. {
  592. fclose(f);
  593. return false;
  594. }
  595. if (fread(file_data, 1, file_size, f) != file_size)
  596. {
  597. fclose(f);
  598. ImGui::MemFree(file_data);
  599. return false;
  600. }
  601. if (padding_bytes > 0)
  602. memset((void *)(((char*)file_data) + file_size), 0, padding_bytes);
  603. fclose(f);
  604. *out_file_data = file_data;
  605. *out_file_size = file_size;
  606. return true;
  607. }
  608. //-----------------------------------------------------------------------------
  609. struct ImGuiColMod // Color modifier, backup of modified data so we can restore it
  610. {
  611. ImGuiCol Col;
  612. ImVec4 PreviousValue;
  613. };
  614. struct ImGuiStyleMod // Style modifier, backup of modified data so we can restore it
  615. {
  616. ImGuiStyleVar Var;
  617. ImVec2 PreviousValue;
  618. };
  619. struct ImGuiAabb // 2D axis aligned bounding-box
  620. {
  621. ImVec2 Min;
  622. ImVec2 Max;
  623. ImGuiAabb() { Min = ImVec2(FLT_MAX,FLT_MAX); Max = ImVec2(-FLT_MAX,-FLT_MAX); }
  624. ImGuiAabb(const ImVec2& min, const ImVec2& max) { Min = min; Max = max; }
  625. ImGuiAabb(const ImVec4& v) { Min.x = v.x; Min.y = v.y; Max.x = v.z; Max.y = v.w; }
  626. ImGuiAabb(float x1, float y1, float x2, float y2) { Min.x = x1; Min.y = y1; Max.x = x2; Max.y = y2; }
  627. ImVec2 GetCenter() const { return Min + (Max-Min)*0.5f; }
  628. ImVec2 GetSize() const { return Max-Min; }
  629. float GetWidth() const { return (Max-Min).x; }
  630. float GetHeight() const { return (Max-Min).y; }
  631. ImVec2 GetTL() const { return Min; }
  632. ImVec2 GetTR() const { return ImVec2(Max.x,Min.y); }
  633. ImVec2 GetBL() const { return ImVec2(Min.x,Max.y); }
  634. ImVec2 GetBR() const { return Max; }
  635. bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x <= Max.x && p.y <= Max.y; }
  636. bool Contains(const ImGuiAabb& r) const { return r.Min.x >= Min.x && r.Min.y >= Min.y && r.Max.x <= Max.x && r.Max.y <= Max.y; }
  637. bool Overlaps(const ImGuiAabb& r) const { return r.Min.y <= Max.y && r.Max.y >= Min.y && r.Min.x <= Max.x && r.Max.x >= Min.x; }
  638. void Add(const ImVec2& rhs) { Min.x = ImMin(Min.x, rhs.x); Min.y = ImMin(Min.y, rhs.y); Max.x = ImMax(Max.x, rhs.x); Max.y = ImMax(Max.x, rhs.x); }
  639. void Add(const ImGuiAabb& rhs) { Min.x = ImMin(Min.x, rhs.Min.x); Min.y = ImMin(Min.y, rhs.Min.y); Max.x = ImMax(Max.x, rhs.Max.x); Max.y = ImMax(Max.y, rhs.Max.y); }
  640. void Expand(const ImVec2& sz) { Min -= sz; Max += sz; }
  641. void Clip(const ImGuiAabb& clip) { Min.x = ImMax(Min.x, clip.Min.x); Min.y = ImMax(Min.y, clip.Min.y); Max.x = ImMin(Max.x, clip.Max.x); Max.y = ImMin(Max.y, clip.Max.y); }
  642. };
  643. // Temporary per-window data, reset at the beginning of the frame
  644. struct ImGuiDrawContext
  645. {
  646. ImVec2 CursorPos;
  647. ImVec2 CursorPosPrevLine;
  648. ImVec2 CursorStartPos;
  649. float CurrentLineHeight;
  650. float PrevLineHeight;
  651. float LogLineHeight;
  652. int TreeDepth;
  653. ImGuiAabb LastItemAabb;
  654. bool LastItemHovered;
  655. bool LastItemFocused;
  656. ImVector<ImGuiWindow*> ChildWindows;
  657. ImVector<bool> AllowKeyboardFocus;
  658. ImVector<float> ItemWidth;
  659. ImVector<float> TextWrapPos;
  660. ImGuiColorEditMode ColorEditMode;
  661. ImGuiStorage* StateStorage;
  662. int OpenNextNode;
  663. float ColumnsStartX; // Start position from left of window (increased by TreePush/TreePop, etc.)
  664. 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.
  665. int ColumnsCurrent;
  666. int ColumnsCount;
  667. ImVec2 ColumnsStartPos;
  668. float ColumnsCellMinY;
  669. float ColumnsCellMaxY;
  670. bool ColumnsShowBorders;
  671. ImGuiID ColumnsSetID;
  672. ImGuiDrawContext()
  673. {
  674. CursorPos = CursorPosPrevLine = CursorStartPos = ImVec2(0.0f, 0.0f);
  675. CurrentLineHeight = PrevLineHeight = 0.0f;
  676. LogLineHeight = -1.0f;
  677. TreeDepth = 0;
  678. LastItemAabb = ImGuiAabb(0.0f,0.0f,0.0f,0.0f);
  679. LastItemHovered = false;
  680. LastItemFocused = true;
  681. StateStorage = NULL;
  682. OpenNextNode = -1;
  683. ColumnsStartX = 0.0f;
  684. ColumnsOffsetX = 0.0f;
  685. ColumnsCurrent = 0;
  686. ColumnsCount = 1;
  687. ColumnsStartPos = ImVec2(0.0f, 0.0f);
  688. ColumnsCellMinY = ColumnsCellMaxY = 0.0f;
  689. ColumnsShowBorders = true;
  690. ColumnsSetID = 0;
  691. }
  692. };
  693. struct ImGuiTextEditState;
  694. #define STB_TEXTEDIT_STRING ImGuiTextEditState
  695. #define STB_TEXTEDIT_CHARTYPE ImWchar
  696. #include "stb_textedit.h"
  697. // Internal state of the currently focused/edited text input box
  698. struct ImGuiTextEditState
  699. {
  700. 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.
  701. char InitialText[1024*3+1]; // backup of end-user buffer at the time of focus (in UTF-8, unconverted)
  702. size_t BufSize; // end-user buffer size, <= 1024 (or increase above)
  703. float Width; // widget width
  704. float ScrollX;
  705. STB_TexteditState StbState;
  706. float CursorAnim;
  707. ImVec2 LastCursorPos; // Cursor position in screen space to be used by IME callback.
  708. bool SelectedAllMouseLock;
  709. ImFont* Font;
  710. float FontSize;
  711. ImGuiTextEditState() { memset(this, 0, sizeof(*this)); }
  712. void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking
  713. bool CursorIsVisible() const { return CursorAnim <= 0.0f || fmodf(CursorAnim, 1.20f) <= 0.80f; } // Blinking
  714. bool HasSelection() const { return StbState.select_start != StbState.select_end; }
  715. void SelectAll() { StbState.select_start = 0; StbState.select_end = (int)ImStrlenW(Text); StbState.cursor = StbState.select_end; StbState.has_preferred_x = false; }
  716. void OnKeyPressed(int key);
  717. void UpdateScrollOffset();
  718. ImVec2 CalcDisplayOffsetFromCharIdx(int i) const;
  719. // Static functions because they are used to render non-focused instances of a text input box
  720. static const char* GetTextPointerClippedA(ImFont* font, float font_size, const char* text, float width, ImVec2* out_text_size = NULL);
  721. static const ImWchar* GetTextPointerClippedW(ImFont* font, float font_size, const ImWchar* text, float width, ImVec2* out_text_size = NULL);
  722. static void RenderTextScrolledClipped(ImFont* font, float font_size, const char* text, ImVec2 pos_base, float width, float scroll_x);
  723. };
  724. struct ImGuiIniData
  725. {
  726. char* Name;
  727. ImVec2 Pos;
  728. ImVec2 Size;
  729. bool Collapsed;
  730. ImGuiIniData() { memset(this, 0, sizeof(*this)); }
  731. ~ImGuiIniData() { if (Name) { ImGui::MemFree(Name); Name = NULL; } }
  732. };
  733. struct ImGuiState
  734. {
  735. bool Initialized;
  736. ImGuiIO IO;
  737. ImGuiStyle Style;
  738. float FontSize; // == IO.FontGlobalScale * IO.Font->Scale * IO.Font->Info->FontSize. Vertical distance between two lines of text, aka == CalcTextSize(" ").y
  739. ImVec2 FontTexUvForWhite; // == IO.Font->FontTexUvForWhite (cached copy)
  740. float Time;
  741. int FrameCount;
  742. int FrameCountRendered;
  743. ImVector<ImGuiWindow*> Windows;
  744. ImGuiWindow* CurrentWindow; // Being drawn into
  745. ImVector<ImGuiWindow*> CurrentWindowStack;
  746. ImGuiWindow* FocusedWindow; // Will catch keyboard inputs
  747. ImGuiWindow* HoveredWindow; // Will catch mouse inputs
  748. ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only)
  749. ImGuiID HoveredId;
  750. ImGuiID ActiveId;
  751. ImGuiID ActiveIdPreviousFrame;
  752. bool ActiveIdIsAlive;
  753. float SettingsDirtyTimer;
  754. ImVector<ImGuiIniData*> Settings;
  755. ImVector<ImGuiColMod> ColorModifiers;
  756. ImVector<ImGuiStyleMod> StyleModifiers;
  757. ImVec2 SetNextWindowPosVal;
  758. ImGuiSetCondition SetNextWindowPosCond;
  759. ImVec2 SetNextWindowSizeVal;
  760. ImGuiSetCondition SetNextWindowSizeCond;
  761. bool SetNextWindowCollapsedVal;
  762. ImGuiSetCondition SetNextWindowCollapsedCond;
  763. // Render
  764. ImVector<ImDrawList*> RenderDrawLists;
  765. // Widget state
  766. ImGuiTextEditState InputTextState;
  767. ImGuiID SliderAsInputTextId;
  768. ImGuiStorage ColorEditModeStorage; // for user selection
  769. ImGuiID ActiveComboID;
  770. char Tooltip[1024];
  771. char* PrivateClipboard; // if no custom clipboard handler is defined
  772. // Logging
  773. bool LogEnabled;
  774. FILE* LogFile;
  775. ImGuiTextBuffer* LogClipboard; // pointer so our GImGui static constructor doesn't call heap allocators.
  776. int LogStartDepth;
  777. int LogAutoExpandMaxDepth;
  778. ImGuiState()
  779. {
  780. Initialized = false;
  781. Time = 0.0f;
  782. FrameCount = 0;
  783. FrameCountRendered = -1;
  784. CurrentWindow = NULL;
  785. FocusedWindow = NULL;
  786. HoveredWindow = NULL;
  787. HoveredRootWindow = NULL;
  788. ActiveIdIsAlive = false;
  789. SettingsDirtyTimer = 0.0f;
  790. SetNextWindowPosVal = ImVec2(0.0f, 0.0f);
  791. SetNextWindowPosCond = 0;
  792. SetNextWindowSizeVal = ImVec2(0.0f, 0.0f);
  793. SetNextWindowSizeCond = 0;
  794. SetNextWindowCollapsedVal = false;
  795. SetNextWindowCollapsedCond = 0;
  796. SliderAsInputTextId = 0;
  797. ActiveComboID = 0;
  798. memset(Tooltip, 0, sizeof(Tooltip));
  799. PrivateClipboard = NULL;
  800. LogEnabled = false;
  801. LogFile = NULL;
  802. LogStartDepth = 0;
  803. LogAutoExpandMaxDepth = 2;
  804. LogClipboard = NULL;
  805. }
  806. };
  807. static ImGuiState GImGui;
  808. struct ImGuiWindow
  809. {
  810. char* Name;
  811. ImGuiID ID;
  812. ImGuiWindowFlags Flags;
  813. ImVec2 PosFloat;
  814. ImVec2 Pos; // Position rounded-up to nearest pixel
  815. ImVec2 Size; // Current size (==SizeFull or collapsed title bar size)
  816. ImVec2 SizeFull; // Size when non collapsed
  817. ImVec2 SizeContentsFit; // Size of contents (extents reach by the drawing cursor) - may not fit within Size.
  818. float ScrollY;
  819. float NextScrollY;
  820. bool ScrollbarY;
  821. bool Visible; // Set to true on Begin()
  822. bool Accessed; // Set to true when any widget access the current window
  823. bool Collapsed; // Set when collapsing window to become only title-bar
  824. bool SkipItems; // == Visible && !Collapsed
  825. int AutoFitFrames;
  826. bool AutoFitOnlyGrows;
  827. int SetWindowPosAllowFlags; // bit ImGuiSetCondition_*** specify if SetWindowPos() call is allowed with this particular flag.
  828. int SetWindowSizeAllowFlags; // bit ImGuiSetCondition_*** specify if SetWindowSize() call is allowed with this particular flag.
  829. int SetWindowCollapsedAllowFlags; // bit ImGuiSetCondition_*** specify if SetWindowCollapsed() call is allowed with this particular flag.
  830. ImGuiDrawContext DC;
  831. ImVector<ImGuiID> IDStack;
  832. ImVector<ImVec4> ClipRectStack;
  833. int LastFrameDrawn;
  834. float ItemWidthDefault;
  835. ImGuiStorage StateStorage;
  836. float FontWindowScale; // Scale multiplier per-window
  837. ImDrawList* DrawList;
  838. ImGuiWindow* RootWindow;
  839. // Focus
  840. int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister()
  841. int FocusIdxTabCounter; // (same, but only count widgets which you can Tab through)
  842. int FocusIdxAllRequestCurrent; // Item being requested for focus
  843. int FocusIdxTabRequestCurrent; // Tab-able item being requested for focus
  844. int FocusIdxAllRequestNext; // Item being requested for focus, for next update (relies on layout to be stable between the frame pressing TAB and the next frame)
  845. int FocusIdxTabRequestNext; // "
  846. public:
  847. ImGuiWindow(const char* name);
  848. ~ImGuiWindow();
  849. ImGuiID GetID(const char* str);
  850. ImGuiID GetID(const void* ptr);
  851. void AddToRenderList();
  852. bool FocusItemRegister(bool is_active, bool tab_stop = true); // Return true if focus is requested
  853. void FocusItemUnregister();
  854. ImGuiAabb Aabb() const { return ImGuiAabb(Pos, Pos+Size); }
  855. ImFont* Font() const { return GImGui.IO.Font; }
  856. float FontSize() const { return GImGui.FontSize * FontWindowScale; }
  857. ImVec2 CursorPos() const { return DC.CursorPos; }
  858. float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : FontSize() + GImGui.Style.FramePadding.y * 2.0f; }
  859. ImGuiAabb TitleBarAabb() const { return ImGuiAabb(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); }
  860. ImVec2 WindowPadding() const { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders)) ? ImVec2(1,1) : GImGui.Style.WindowPadding; }
  861. ImU32 Color(ImGuiCol idx, float a=1.f) const { ImVec4 c = GImGui.Style.Colors[idx]; c.w *= GImGui.Style.Alpha * a; return ImConvertColorFloat4ToU32(c); }
  862. ImU32 Color(const ImVec4& col) const { ImVec4 c = col; c.w *= GImGui.Style.Alpha; return ImConvertColorFloat4ToU32(c); }
  863. };
  864. static ImGuiWindow* GetCurrentWindow()
  865. {
  866. IM_ASSERT(GImGui.CurrentWindow != NULL); // ImGui::NewFrame() hasn't been called yet?
  867. GImGui.CurrentWindow->Accessed = true;
  868. return GImGui.CurrentWindow;
  869. }
  870. static void RegisterAliveId(const ImGuiID& id)
  871. {
  872. if (GImGui.ActiveId == id)
  873. GImGui.ActiveIdIsAlive = true;
  874. }
  875. //-----------------------------------------------------------------------------
  876. // Helper: Key->value storage
  877. void ImGuiStorage::Clear()
  878. {
  879. Data.clear();
  880. }
  881. // std::lower_bound but without the bullshit
  882. static ImVector<ImGuiStorage::Pair>::iterator LowerBound(ImVector<ImGuiStorage::Pair>& data, ImU32 key)
  883. {
  884. ImVector<ImGuiStorage::Pair>::iterator first = data.begin();
  885. ImVector<ImGuiStorage::Pair>::iterator last = data.end();
  886. int count = (int)(last - first);
  887. while (count > 0)
  888. {
  889. int count2 = count / 2;
  890. ImVector<ImGuiStorage::Pair>::iterator mid = first + count2;
  891. if (mid->key < key)
  892. {
  893. first = ++mid;
  894. count -= count2 + 1;
  895. }
  896. else
  897. {
  898. count = count2;
  899. }
  900. }
  901. return first;
  902. }
  903. int ImGuiStorage::GetInt(ImU32 key, int default_val) const
  904. {
  905. ImVector<Pair>::iterator it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
  906. if (it == Data.end() || it->key != key)
  907. return default_val;
  908. return it->val_i;
  909. }
  910. float ImGuiStorage::GetFloat(ImU32 key, float default_val) const
  911. {
  912. ImVector<Pair>::iterator it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
  913. if (it == Data.end() || it->key != key)
  914. return default_val;
  915. return it->val_f;
  916. }
  917. int* ImGuiStorage::GetIntPtr(ImGuiID key, int default_val)
  918. {
  919. ImVector<Pair>::iterator it = LowerBound(Data, key);
  920. if (it == Data.end() || it->key != key)
  921. it = Data.insert(it, Pair(key, default_val));
  922. return &it->val_i;
  923. }
  924. float* ImGuiStorage::GetFloatPtr(ImGuiID key, float default_val)
  925. {
  926. ImVector<Pair>::iterator it = LowerBound(Data, key);
  927. if (it == Data.end() || it->key != key)
  928. it = Data.insert(it, Pair(key, default_val));
  929. return &it->val_f;
  930. }
  931. // FIXME-OPT: Wasting CPU because all SetInt() are preceeded by GetInt() calls so we should have the result from lower_bound already in place.
  932. // However we only use SetInt() on explicit user action (so that's maximum once a frame) so the optimisation isn't much needed.
  933. void ImGuiStorage::SetInt(ImU32 key, int val)
  934. {
  935. ImVector<Pair>::iterator it = LowerBound(Data, key);
  936. if (it == Data.end() || it->key != key)
  937. {
  938. Data.insert(it, Pair(key, val));
  939. return;
  940. }
  941. it->val_i = val;
  942. }
  943. void ImGuiStorage::SetFloat(ImU32 key, float val)
  944. {
  945. ImVector<Pair>::iterator it = LowerBound(Data, key);
  946. if (it == Data.end() || it->key != key)
  947. {
  948. Data.insert(it, Pair(key, val));
  949. return;
  950. }
  951. it->val_f = val;
  952. }
  953. void ImGuiStorage::SetAllInt(int v)
  954. {
  955. for (size_t i = 0; i < Data.size(); i++)
  956. Data[i].val_i = v;
  957. }
  958. //-----------------------------------------------------------------------------
  959. // Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
  960. ImGuiTextFilter::ImGuiTextFilter()
  961. {
  962. InputBuf[0] = 0;
  963. CountGrep = 0;
  964. }
  965. void ImGuiTextFilter::Draw(const char* label, float width)
  966. {
  967. ImGuiWindow* window = GetCurrentWindow();
  968. if (width < 0.0f)
  969. {
  970. ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
  971. width = ImMax(window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x - (label_size.x + GImGui.Style.ItemSpacing.x*4), 10.0f);
  972. }
  973. ImGui::PushItemWidth(width);
  974. ImGui::InputText(label, InputBuf, IM_ARRAYSIZE(InputBuf));
  975. ImGui::PopItemWidth();
  976. Build();
  977. }
  978. void ImGuiTextFilter::TextRange::split(char separator, ImVector<TextRange>& out)
  979. {
  980. out.resize(0);
  981. const char* wb = b;
  982. const char* we = wb;
  983. while (we < e)
  984. {
  985. if (*we == separator)
  986. {
  987. out.push_back(TextRange(wb, we));
  988. wb = we + 1;
  989. }
  990. we++;
  991. }
  992. if (wb != we)
  993. out.push_back(TextRange(wb, we));
  994. }
  995. void ImGuiTextFilter::Build()
  996. {
  997. Filters.resize(0);
  998. TextRange input_range(InputBuf, InputBuf+strlen(InputBuf));
  999. input_range.split(',', Filters);
  1000. CountGrep = 0;
  1001. for (size_t i = 0; i != Filters.size(); i++)
  1002. {
  1003. Filters[i].trim_blanks();
  1004. if (Filters[i].empty())
  1005. continue;
  1006. if (Filters[i].front() != '-')
  1007. CountGrep += 1;
  1008. }
  1009. }
  1010. bool ImGuiTextFilter::PassFilter(const char* val) const
  1011. {
  1012. if (Filters.empty())
  1013. return true;
  1014. if (val == NULL)
  1015. val = "";
  1016. for (size_t i = 0; i != Filters.size(); i++)
  1017. {
  1018. const TextRange& f = Filters[i];
  1019. if (f.empty())
  1020. continue;
  1021. if (f.front() == '-')
  1022. {
  1023. // Subtract
  1024. if (ImStristr(val, f.begin()+1, f.end()) != NULL)
  1025. return false;
  1026. }
  1027. else
  1028. {
  1029. // Grep
  1030. if (ImStristr(val, f.begin(), f.end()) != NULL)
  1031. return true;
  1032. }
  1033. }
  1034. // Implicit * grep
  1035. if (CountGrep == 0)
  1036. return true;
  1037. return false;
  1038. }
  1039. //-----------------------------------------------------------------------------
  1040. // Helper: Text buffer for logging/accumulating text
  1041. void ImGuiTextBuffer::appendv(const char* fmt, va_list args)
  1042. {
  1043. int len = vsnprintf(NULL, 0, fmt, args); // FIXME-OPT: could do a first pass write attempt, likely successful on first pass.
  1044. if (len <= 0)
  1045. return;
  1046. const size_t write_off = Buf.size();
  1047. if (write_off + (size_t)len >= Buf.capacity())
  1048. Buf.reserve(Buf.capacity() * 2);
  1049. Buf.resize(write_off + (size_t)len);
  1050. ImFormatStringV(&Buf[write_off] - 1, (size_t)len+1, fmt, args);
  1051. }
  1052. void ImGuiTextBuffer::append(const char* fmt, ...)
  1053. {
  1054. va_list args;
  1055. va_start(args, fmt);
  1056. appendv(fmt, args);
  1057. va_end(args);
  1058. }
  1059. //-----------------------------------------------------------------------------
  1060. ImGuiWindow::ImGuiWindow(const char* name)
  1061. {
  1062. Name = ImStrdup(name);
  1063. ID = GetID(name);
  1064. IDStack.push_back(ID);
  1065. PosFloat = Pos = ImVec2(0.0f, 0.0f);
  1066. Size = SizeFull = ImVec2(0.0f, 0.0f);
  1067. SizeContentsFit = ImVec2(0.0f, 0.0f);
  1068. ScrollY = 0.0f;
  1069. NextScrollY = 0.0f;
  1070. ScrollbarY = false;
  1071. Visible = false;
  1072. Accessed = false;
  1073. Collapsed = false;
  1074. SkipItems = false;
  1075. AutoFitFrames = -1;
  1076. AutoFitOnlyGrows = false;
  1077. SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiSetCondition_Always | ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver;
  1078. LastFrameDrawn = -1;
  1079. ItemWidthDefault = 0.0f;
  1080. FontWindowScale = 1.0f;
  1081. if (ImLengthSqr(Size) < 0.00001f)
  1082. {
  1083. AutoFitFrames = 2;
  1084. AutoFitOnlyGrows = true;
  1085. }
  1086. DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList));
  1087. new(DrawList) ImDrawList();
  1088. FocusIdxAllCounter = FocusIdxTabCounter = -1;
  1089. FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = IM_INT_MAX;
  1090. FocusIdxAllRequestNext = FocusIdxTabRequestNext = IM_INT_MAX;
  1091. }
  1092. ImGuiWindow::~ImGuiWindow()
  1093. {
  1094. DrawList->~ImDrawList();
  1095. ImGui::MemFree(DrawList);
  1096. DrawList = NULL;
  1097. ImGui::MemFree(Name);
  1098. Name = NULL;
  1099. }
  1100. ImGuiID ImGuiWindow::GetID(const char* str)
  1101. {
  1102. const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back();
  1103. const ImGuiID id = ImCrc32(str, 0, seed);
  1104. RegisterAliveId(id);
  1105. return id;
  1106. }
  1107. ImGuiID ImGuiWindow::GetID(const void* ptr)
  1108. {
  1109. const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back();
  1110. const ImGuiID id = ImCrc32(&ptr, sizeof(void*), seed);
  1111. RegisterAliveId(id);
  1112. return id;
  1113. }
  1114. bool ImGuiWindow::FocusItemRegister(bool is_active, bool tab_stop)
  1115. {
  1116. ImGuiState& g = GImGui;
  1117. ImGuiWindow* window = GetCurrentWindow();
  1118. const bool allow_keyboard_focus = window->DC.AllowKeyboardFocus.back();
  1119. FocusIdxAllCounter++;
  1120. if (allow_keyboard_focus)
  1121. FocusIdxTabCounter++;
  1122. if (is_active)
  1123. window->DC.LastItemFocused = true;
  1124. // Process keyboard input at this point: TAB, Shift-TAB switch focus
  1125. // We can always TAB out of a widget that doesn't allow tabbing in.
  1126. if (tab_stop && FocusIdxAllRequestNext == IM_INT_MAX && FocusIdxTabRequestNext == IM_INT_MAX && is_active && IsKeyPressedMap(ImGuiKey_Tab))
  1127. {
  1128. // Modulo on index will be applied at the end of frame once we've got the total counter of items.
  1129. FocusIdxTabRequestNext = FocusIdxTabCounter + (g.IO.KeyShift ? (allow_keyboard_focus ? -1 : 0) : +1);
  1130. }
  1131. if (FocusIdxAllCounter == FocusIdxAllRequestCurrent)
  1132. return true;
  1133. if (allow_keyboard_focus)
  1134. if (FocusIdxTabCounter == FocusIdxTabRequestCurrent)
  1135. return true;
  1136. return false;
  1137. }
  1138. void ImGuiWindow::FocusItemUnregister()
  1139. {
  1140. FocusIdxAllCounter--;
  1141. FocusIdxTabCounter--;
  1142. }
  1143. void ImGuiWindow::AddToRenderList()
  1144. {
  1145. ImGuiState& g = GImGui;
  1146. if (!DrawList->commands.empty() && !DrawList->vtx_buffer.empty())
  1147. {
  1148. if (DrawList->commands.back().vtx_count == 0)
  1149. DrawList->commands.pop_back();
  1150. g.RenderDrawLists.push_back(DrawList);
  1151. }
  1152. for (size_t i = 0; i < DC.ChildWindows.size(); i++)
  1153. {
  1154. ImGuiWindow* child = DC.ChildWindows[i];
  1155. if (child->Visible) // clipped childs may have been marked not Visible
  1156. child->AddToRenderList();
  1157. }
  1158. }
  1159. //-----------------------------------------------------------------------------
  1160. void* ImGui::MemAlloc(size_t sz)
  1161. {
  1162. return GImGui.IO.MemAllocFn(sz);
  1163. }
  1164. void ImGui::MemFree(void* ptr)
  1165. {
  1166. return GImGui.IO.MemFreeFn(ptr);
  1167. }
  1168. void* ImGui::MemRealloc(void* ptr, size_t sz)
  1169. {
  1170. return GImGui.IO.MemReallocFn(ptr, sz);
  1171. }
  1172. static ImGuiIniData* FindWindowSettings(const char* name)
  1173. {
  1174. ImGuiState& g = GImGui;
  1175. for (size_t i = 0; i != g.Settings.size(); i++)
  1176. {
  1177. ImGuiIniData* ini = g.Settings[i];
  1178. if (ImStricmp(ini->Name, name) == 0)
  1179. return ini;
  1180. }
  1181. return NULL;
  1182. }
  1183. static ImGuiIniData* AddWindowSettings(const char* name)
  1184. {
  1185. ImGuiIniData* ini = (ImGuiIniData*)ImGui::MemAlloc(sizeof(ImGuiIniData));
  1186. new(ini) ImGuiIniData();
  1187. ini->Name = ImStrdup(name);
  1188. ini->Collapsed = false;
  1189. ini->Pos = ImVec2(FLT_MAX,FLT_MAX);
  1190. ini->Size = ImVec2(0,0);
  1191. GImGui.Settings.push_back(ini);
  1192. return ini;
  1193. }
  1194. // Zero-tolerance, poor-man .ini parsing
  1195. // FIXME: Write something less rubbish
  1196. static void LoadSettings()
  1197. {
  1198. ImGuiState& g = GImGui;
  1199. const char* filename = g.IO.IniFilename;
  1200. if (!filename)
  1201. return;
  1202. char* file_data;
  1203. size_t file_size;
  1204. if (!ImLoadFileToMemory(filename, "rb", (void**)&file_data, &file_size, 1))
  1205. return;
  1206. ImGuiIniData* settings = NULL;
  1207. const char* buf_end = file_data + file_size;
  1208. for (const char* line_start = file_data; line_start < buf_end; )
  1209. {
  1210. const char* line_end = line_start;
  1211. while (line_end < buf_end && *line_end != '\n' && *line_end != '\r')
  1212. line_end++;
  1213. if (line_start[0] == '[' && line_end > line_start && line_end[-1] == ']')
  1214. {
  1215. char name[64];
  1216. ImFormatString(name, IM_ARRAYSIZE(name), "%.*s", line_end-line_start-2, line_start+1);
  1217. settings = FindWindowSettings(name);
  1218. if (!settings)
  1219. settings = AddWindowSettings(name);
  1220. }
  1221. else if (settings)
  1222. {
  1223. float x, y;
  1224. int i;
  1225. if (sscanf(line_start, "Pos=%f,%f", &x, &y) == 2)
  1226. settings->Pos = ImVec2(x, y);
  1227. else if (sscanf(line_start, "Size=%f,%f", &x, &y) == 2)
  1228. settings->Size = ImMax(ImVec2(x, y), g.Style.WindowMinSize);
  1229. else if (sscanf(line_start, "Collapsed=%d", &i) == 1)
  1230. settings->Collapsed = (i != 0);
  1231. }
  1232. line_start = line_end+1;
  1233. }
  1234. ImGui::MemFree(file_data);
  1235. }
  1236. static void SaveSettings()
  1237. {
  1238. ImGuiState& g = GImGui;
  1239. const char* filename = g.IO.IniFilename;
  1240. if (!filename)
  1241. return;
  1242. // Gather data from windows that were active during this session
  1243. for (size_t i = 0; i != g.Windows.size(); i++)
  1244. {
  1245. ImGuiWindow* window = g.Windows[i];
  1246. if (window->Flags & ImGuiWindowFlags_NoSavedSettings)
  1247. continue;
  1248. ImGuiIniData* settings = FindWindowSettings(window->Name);
  1249. settings->Pos = window->Pos;
  1250. settings->Size = window->SizeFull;
  1251. settings->Collapsed = window->Collapsed;
  1252. }
  1253. // Write .ini file
  1254. // If a window wasn't opened in this session we preserve its settings
  1255. FILE* f = fopen(filename, "wt");
  1256. if (!f)
  1257. return;
  1258. for (size_t i = 0; i != g.Settings.size(); i++)
  1259. {
  1260. const ImGuiIniData* settings = g.Settings[i];
  1261. if (settings->Pos.x == FLT_MAX)
  1262. continue;
  1263. fprintf(f, "[%s]\n", settings->Name);
  1264. fprintf(f, "Pos=%d,%d\n", (int)settings->Pos.x, (int)settings->Pos.y);
  1265. fprintf(f, "Size=%d,%d\n", (int)settings->Size.x, (int)settings->Size.y);
  1266. fprintf(f, "Collapsed=%d\n", settings->Collapsed);
  1267. fprintf(f, "\n");
  1268. }
  1269. fclose(f);
  1270. }
  1271. static void MarkSettingsDirty()
  1272. {
  1273. ImGuiState& g = GImGui;
  1274. if (g.SettingsDirtyTimer <= 0.0f)
  1275. g.SettingsDirtyTimer = g.IO.IniSavingRate;
  1276. }
  1277. ImGuiIO& ImGui::GetIO()
  1278. {
  1279. return GImGui.IO;
  1280. }
  1281. ImGuiStyle& ImGui::GetStyle()
  1282. {
  1283. return GImGui.Style;
  1284. }
  1285. void ImGui::NewFrame()
  1286. {
  1287. ImGuiState& g = GImGui;
  1288. // Check user inputs
  1289. IM_ASSERT(g.IO.DeltaTime > 0.0f);
  1290. IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f);
  1291. IM_ASSERT(g.IO.RenderDrawListsFn != NULL); // Must be implemented
  1292. if (!g.Initialized)
  1293. {
  1294. // Initialize on first frame
  1295. g.LogClipboard = (ImGuiTextBuffer*)ImGui::MemAlloc(sizeof(ImGuiTextBuffer));
  1296. new(g.LogClipboard) ImGuiTextBuffer();
  1297. IM_ASSERT(g.Settings.empty());
  1298. LoadSettings();
  1299. if (!g.IO.Font)
  1300. {
  1301. // Default font
  1302. const void* fnt_data;
  1303. unsigned int fnt_size;
  1304. ImGui::GetDefaultFontData(&fnt_data, &fnt_size, NULL, NULL);
  1305. g.IO.Font = (ImFont*)ImGui::MemAlloc(sizeof(ImFont));
  1306. new(g.IO.Font) ImFont();
  1307. g.IO.Font->LoadFromMemory(fnt_data, fnt_size);
  1308. IM_ASSERT(g.IO.Font->IsLoaded()); // Font failed to load
  1309. g.IO.Font->DisplayOffset = ImVec2(0.0f, +1.0f);
  1310. }
  1311. g.Initialized = true;
  1312. }
  1313. IM_ASSERT(g.IO.Font && g.IO.Font->IsLoaded()); // Font not loaded
  1314. IM_ASSERT(g.IO.Font->Scale > 0.0f);
  1315. g.FontSize = g.IO.FontGlobalScale * (float)g.IO.Font->Info->FontSize * g.IO.Font->Scale;
  1316. g.FontTexUvForWhite = g.IO.Font->TexUvForWhite;
  1317. g.IO.Font->FallbackGlyph = NULL; // Because subsequent FindGlyph may return the fallback itself.
  1318. g.IO.Font->FallbackGlyph = g.IO.Font->FindGlyph(g.IO.Font->FallbackChar);
  1319. g.Time += g.IO.DeltaTime;
  1320. g.FrameCount += 1;
  1321. g.Tooltip[0] = '\0';
  1322. // Update inputs state
  1323. if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0)
  1324. g.IO.MousePos = ImVec2(-9999.0f, -9999.0f);
  1325. if ((g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0) || (g.IO.MousePosPrev.x < 0 && g.IO.MousePosPrev.y < 0)) // if mouse just appeared or disappeared (negative coordinate) we cancel out movement in MouseDelta
  1326. g.IO.MouseDelta = ImVec2(0.0f, 0.0f);
  1327. else
  1328. g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
  1329. g.IO.MousePosPrev = g.IO.MousePos;
  1330. for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
  1331. {
  1332. g.IO.MouseDownTime[i] = g.IO.MouseDown[i] ? (g.IO.MouseDownTime[i] < 0.0f ? 0.0f : g.IO.MouseDownTime[i] + g.IO.DeltaTime) : -1.0f;
  1333. g.IO.MouseClicked[i] = (g.IO.MouseDownTime[i] == 0.0f);
  1334. g.IO.MouseDoubleClicked[i] = false;
  1335. if (g.IO.MouseClicked[i])
  1336. {
  1337. if (g.Time - g.IO.MouseClickedTime[i] < g.IO.MouseDoubleClickTime)
  1338. {
  1339. if (ImLengthSqr(g.IO.MousePos - g.IO.MouseClickedPos[i]) < g.IO.MouseDoubleClickMaxDist * g.IO.MouseDoubleClickMaxDist)
  1340. g.IO.MouseDoubleClicked[i] = true;
  1341. g.IO.MouseClickedTime[i] = -FLT_MAX; // so the third click isn't turned into a double-click
  1342. }
  1343. else
  1344. {
  1345. g.IO.MouseClickedTime[i] = g.Time;
  1346. g.IO.MouseClickedPos[i] = g.IO.MousePos;
  1347. }
  1348. }
  1349. }
  1350. for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++)
  1351. 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;
  1352. // Clear reference to active widget if the widget isn't alive anymore
  1353. g.HoveredId = 0;
  1354. if (!g.ActiveIdIsAlive && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0)
  1355. g.ActiveId = 0;
  1356. g.ActiveIdPreviousFrame = g.ActiveId;
  1357. g.ActiveIdIsAlive = false;
  1358. // Delay saving settings so we don't spam disk too much
  1359. if (g.SettingsDirtyTimer > 0.0f)
  1360. {
  1361. g.SettingsDirtyTimer -= g.IO.DeltaTime;
  1362. if (g.SettingsDirtyTimer <= 0.0f)
  1363. SaveSettings();
  1364. }
  1365. // Find the window we are hovering. Child windows can extend beyond the limit of their parent so we need to derive HoveredRootWindow from HoveredWindow
  1366. g.HoveredWindow = FindHoveredWindow(g.IO.MousePos, false);
  1367. if (g.HoveredWindow && (g.HoveredWindow->Flags & ImGuiWindowFlags_ChildWindow))
  1368. g.HoveredRootWindow = g.HoveredWindow->RootWindow;
  1369. else
  1370. g.HoveredRootWindow = FindHoveredWindow(g.IO.MousePos, true);
  1371. // Are we using inputs? Tell user so they can capture/discard them.
  1372. g.IO.WantCaptureMouse = (g.HoveredWindow != NULL) || (g.ActiveId != 0);
  1373. g.IO.WantCaptureKeyboard = (g.ActiveId != 0);
  1374. // Scale & Scrolling
  1375. if (g.HoveredWindow && g.IO.MouseWheel != 0.0f)
  1376. {
  1377. ImGuiWindow* window = g.HoveredWindow;
  1378. if (g.IO.KeyCtrl)
  1379. {
  1380. if (g.IO.FontAllowUserScaling)
  1381. {
  1382. // Zoom / Scale window
  1383. float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
  1384. float scale = new_font_scale / window->FontWindowScale;
  1385. window->FontWindowScale = new_font_scale;
  1386. const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size;
  1387. window->Pos += offset;
  1388. window->PosFloat += offset;
  1389. window->Size *= scale;
  1390. window->SizeFull *= scale;
  1391. }
  1392. }
  1393. else
  1394. {
  1395. // Scroll
  1396. if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse))
  1397. {
  1398. const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5;
  1399. window->NextScrollY -= g.IO.MouseWheel * window->FontSize() * scroll_lines;
  1400. }
  1401. }
  1402. }
  1403. // Pressing TAB activate widget focus
  1404. // NB: Don't discard FocusedWindow if it isn't active, so that a window that go on/off programatically won't lose its keyboard focus.
  1405. if (g.ActiveId == 0 && g.FocusedWindow != NULL && g.FocusedWindow->Visible && IsKeyPressedMap(ImGuiKey_Tab, false))
  1406. {
  1407. g.FocusedWindow->FocusIdxTabRequestNext = 0;
  1408. }
  1409. // Mark all windows as not visible
  1410. // Clear root windows at this point.
  1411. for (size_t i = 0; i != g.Windows.size(); i++)
  1412. {
  1413. ImGuiWindow* window = g.Windows[i];
  1414. window->Visible = false;
  1415. window->Accessed = false;
  1416. window->RootWindow = NULL;
  1417. }
  1418. // No window should be open at the beginning of the frame.
  1419. // But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear.
  1420. g.CurrentWindowStack.clear();
  1421. // Create implicit window - we will only render it if the user has added something to it.
  1422. ImGui::Begin("Debug", NULL, ImVec2(400,400));
  1423. }
  1424. // NB: behaviour of ImGui after Shutdown() is not tested/guaranteed at the moment. This function is merely here to free heap allocations.
  1425. void ImGui::Shutdown()
  1426. {
  1427. ImGuiState& g = GImGui;
  1428. if (!g.Initialized)
  1429. return;
  1430. SaveSettings();
  1431. for (size_t i = 0; i < g.Windows.size(); i++)
  1432. {
  1433. g.Windows[i]->~ImGuiWindow();
  1434. ImGui::MemFree(g.Windows[i]);
  1435. }
  1436. g.Windows.clear();
  1437. g.CurrentWindowStack.clear();
  1438. g.RenderDrawLists.clear();
  1439. g.FocusedWindow = NULL;
  1440. g.HoveredWindow = NULL;
  1441. g.HoveredRootWindow = NULL;
  1442. for (size_t i = 0; i < g.Settings.size(); i++)
  1443. {
  1444. g.Settings[i]->~ImGuiIniData();
  1445. ImGui::MemFree(g.Settings[i]);
  1446. }
  1447. g.Settings.clear();
  1448. g.ColorModifiers.clear();
  1449. g.StyleModifiers.clear();
  1450. g.ColorEditModeStorage.Clear();
  1451. if (g.LogFile && g.LogFile != stdout)
  1452. {
  1453. fclose(g.LogFile);
  1454. g.LogFile = NULL;
  1455. }
  1456. if (g.IO.Font)
  1457. {
  1458. g.IO.Font->~ImFont();
  1459. ImGui::MemFree(g.IO.Font);
  1460. g.IO.Font = NULL;
  1461. }
  1462. if (g.PrivateClipboard)
  1463. {
  1464. ImGui::MemFree(g.PrivateClipboard);
  1465. g.PrivateClipboard = NULL;
  1466. }
  1467. if (g.LogClipboard)
  1468. {
  1469. g.LogClipboard->~ImGuiTextBuffer();
  1470. ImGui::MemFree(g.LogClipboard);
  1471. }
  1472. g.Initialized = false;
  1473. }
  1474. static void AddWindowToSortedBuffer(ImGuiWindow* window, ImVector<ImGuiWindow*>& sorted_windows)
  1475. {
  1476. sorted_windows.push_back(window);
  1477. if (window->Visible)
  1478. {
  1479. for (size_t i = 0; i < window->DC.ChildWindows.size(); i++)
  1480. {
  1481. ImGuiWindow* child = window->DC.ChildWindows[i];
  1482. if (child->Visible)
  1483. AddWindowToSortedBuffer(child, sorted_windows);
  1484. }
  1485. }
  1486. }
  1487. static void PushClipRect(const ImVec4& clip_rect, bool clipped = true)
  1488. {
  1489. ImGuiWindow* window = GetCurrentWindow();
  1490. ImVec4 cr = clip_rect;
  1491. if (clipped && !window->ClipRectStack.empty())
  1492. {
  1493. // Clip to new clip rect
  1494. const ImVec4 cur_cr = window->ClipRectStack.back();
  1495. cr = ImVec4(ImMax(cr.x, cur_cr.x), ImMax(cr.y, cur_cr.y), ImMin(cr.z, cur_cr.z), ImMin(cr.w, cur_cr.w));
  1496. }
  1497. window->ClipRectStack.push_back(cr);
  1498. window->DrawList->PushClipRect(cr);
  1499. }
  1500. static void PopClipRect()
  1501. {
  1502. ImGuiWindow* window = GetCurrentWindow();
  1503. window->ClipRectStack.pop_back();
  1504. window->DrawList->PopClipRect();
  1505. }
  1506. void ImGui::Render()
  1507. {
  1508. ImGuiState& g = GImGui;
  1509. IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame()
  1510. const bool first_render_of_the_frame = (g.FrameCountRendered != g.FrameCount);
  1511. g.FrameCountRendered = g.FrameCount;
  1512. if (first_render_of_the_frame)
  1513. {
  1514. // Hide implicit window if it hasn't been used
  1515. IM_ASSERT(g.CurrentWindowStack.size() == 1); // Mismatched Begin/End
  1516. if (g.CurrentWindow && !g.CurrentWindow->Accessed)
  1517. g.CurrentWindow->Visible = false;
  1518. ImGui::End();
  1519. // Sort the window list so that all child windows are after their parent
  1520. // We cannot do that on FocusWindow() because childs may not exist yet
  1521. ImVector<ImGuiWindow*> sorted_windows;
  1522. sorted_windows.reserve(g.Windows.size());
  1523. for (size_t i = 0; i != g.Windows.size(); i++)
  1524. {
  1525. ImGuiWindow* window = g.Windows[i];
  1526. if (window->Flags & ImGuiWindowFlags_ChildWindow) // if a child is visible its parent will add it
  1527. if (window->Visible)
  1528. continue;
  1529. AddWindowToSortedBuffer(window, sorted_windows);
  1530. }
  1531. IM_ASSERT(g.Windows.size() == sorted_windows.size()); // We done something wrong
  1532. g.Windows.swap(sorted_windows);
  1533. // Clear data for next frame
  1534. g.IO.MouseWheel = 0.0f;
  1535. memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters));
  1536. }
  1537. // Skip render altogether if alpha is 0.0
  1538. // Note that vertex buffers have been created, so it is best practice that you don't call Begin/End in the first place.
  1539. if (g.Style.Alpha > 0.0f)
  1540. {
  1541. // Render tooltip
  1542. if (g.Tooltip[0])
  1543. {
  1544. // Use a dummy window to render the tooltip
  1545. ImGui::BeginTooltip();
  1546. ImGui::TextUnformatted(g.Tooltip);
  1547. ImGui::EndTooltip();
  1548. }
  1549. // Gather windows to render
  1550. g.RenderDrawLists.resize(0);
  1551. for (size_t i = 0; i != g.Windows.size(); i++)
  1552. {
  1553. ImGuiWindow* window = g.Windows[i];
  1554. if (window->Visible && (window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) == 0)
  1555. window->AddToRenderList();
  1556. }
  1557. for (size_t i = 0; i != g.Windows.size(); i++)
  1558. {
  1559. ImGuiWindow* window = g.Windows[i];
  1560. if (window->Visible && (window->Flags & ImGuiWindowFlags_Tooltip))
  1561. window->AddToRenderList();
  1562. }
  1563. // Render
  1564. if (!g.RenderDrawLists.empty())
  1565. g.IO.RenderDrawListsFn(&g.RenderDrawLists[0], (int)g.RenderDrawLists.size());
  1566. g.RenderDrawLists.resize(0);
  1567. }
  1568. }
  1569. // Find the optional ## from which we stop displaying text.
  1570. static const char* FindTextDisplayEnd(const char* text, const char* text_end = NULL)
  1571. {
  1572. const char* text_display_end = text;
  1573. while ((!text_end || text_display_end < text_end) && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#'))
  1574. text_display_end++;
  1575. return text_display_end;
  1576. }
  1577. // Pass text data straight to log (without being displayed)
  1578. void ImGui::LogText(const char* fmt, ...)
  1579. {
  1580. ImGuiState& g = GImGui;
  1581. if (!g.LogEnabled)
  1582. return;
  1583. va_list args;
  1584. va_start(args, fmt);
  1585. if (g.LogFile)
  1586. {
  1587. vfprintf(g.LogFile, fmt, args);
  1588. }
  1589. else
  1590. {
  1591. g.LogClipboard->appendv(fmt, args);
  1592. }
  1593. va_end(args);
  1594. }
  1595. // Internal version that takes a position to decide on newline placement and pad items according to their depth.
  1596. static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end)
  1597. {
  1598. ImGuiState& g = GImGui;
  1599. ImGuiWindow* window = GetCurrentWindow();
  1600. if (!text_end)
  1601. text_end = FindTextDisplayEnd(text, text_end);
  1602. const bool log_new_line = ref_pos.y > window->DC.LogLineHeight+1;
  1603. window->DC.LogLineHeight = ref_pos.y;
  1604. const char* text_remaining = text;
  1605. if (g.LogStartDepth > window->DC.TreeDepth) // Re-adjust padding if we have popped out of our starting depth
  1606. g.LogStartDepth = window->DC.TreeDepth;
  1607. const int tree_depth = (window->DC.TreeDepth - g.LogStartDepth);
  1608. while (true)
  1609. {
  1610. const char* line_end = text_remaining;
  1611. while (line_end < text_end)
  1612. if (*line_end == '\n')
  1613. break;
  1614. else
  1615. line_end++;
  1616. if (line_end >= text_end)
  1617. line_end = NULL;
  1618. const bool is_first_line = (text == text_remaining);
  1619. bool is_last_line = false;
  1620. if (line_end == NULL)
  1621. {
  1622. is_last_line = true;
  1623. line_end = text_end;
  1624. }
  1625. if (line_end != NULL && !(is_last_line && (line_end - text_remaining)==0))
  1626. {
  1627. const int char_count = (int)(line_end - text_remaining);
  1628. if (log_new_line || !is_first_line)
  1629. ImGui::LogText(STR_NEWLINE "%*s%.*s", tree_depth*4, "", char_count, text_remaining);
  1630. else
  1631. ImGui::LogText(" %.*s", char_count, text_remaining);
  1632. }
  1633. if (is_last_line)
  1634. break;
  1635. text_remaining = line_end + 1;
  1636. }
  1637. }
  1638. static float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
  1639. {
  1640. if (wrap_pos_x < 0.0f)
  1641. return 0.0f;
  1642. ImGuiWindow* window = GetCurrentWindow();
  1643. if (wrap_pos_x == 0.0f)
  1644. wrap_pos_x = ImGui::GetContentRegionMax().x;
  1645. if (wrap_pos_x > 0.0f)
  1646. wrap_pos_x += window->Pos.x; // wrap_pos_x is provided is window local space
  1647. const float wrap_width = wrap_pos_x > 0.0f ? ImMax(wrap_pos_x - pos.x, 0.00001f) : 0.0f;
  1648. return wrap_width;
  1649. }
  1650. // Internal ImGui function to render text (called from ImGui::Text(), ImGui::TextUnformatted(), etc.)
  1651. // RenderText() calls ImDrawList::AddText() calls ImBitmapFont::RenderText()
  1652. static void RenderText(ImVec2 pos, const char* text, const char* text_end, bool hide_text_after_hash, float wrap_width)
  1653. {
  1654. ImGuiState& g = GImGui;
  1655. ImGuiWindow* window = GetCurrentWindow();
  1656. // Hide anything after a '##' string
  1657. const char* text_display_end;
  1658. if (hide_text_after_hash)
  1659. {
  1660. text_display_end = FindTextDisplayEnd(text, text_end);
  1661. }
  1662. else
  1663. {
  1664. if (!text_end)
  1665. text_end = text + strlen(text); // FIXME-OPT
  1666. text_display_end = text_end;
  1667. }
  1668. const int text_len = (int)(text_display_end - text);
  1669. if (text_len > 0)
  1670. {
  1671. // Render
  1672. window->DrawList->AddText(window->Font(), window->FontSize(), pos, window->Color(ImGuiCol_Text), text, text + text_len, wrap_width);
  1673. // Log as text. We split text into individual lines to add current tree level padding
  1674. if (g.LogEnabled)
  1675. LogText(pos, text, text_display_end);
  1676. }
  1677. }
  1678. // Render a rectangle shaped with optional rounding and borders
  1679. static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, float rounding)
  1680. {
  1681. ImGuiWindow* window = GetCurrentWindow();
  1682. window->DrawList->AddRectFilled(p_min, p_max, fill_col, rounding);
  1683. if (border && (window->Flags & ImGuiWindowFlags_ShowBorders))
  1684. {
  1685. // FIXME: This is the best I've found that works on multiple renderer/back ends. Rather dodgy.
  1686. const float offset = GImGui.IO.PixelCenterOffset;
  1687. window->DrawList->AddRect(p_min+ImVec2(1.5f-offset,1.5f-offset), p_max+ImVec2(1.0f-offset*2,1.0f-offset*2), window->Color(ImGuiCol_BorderShadow), rounding);
  1688. window->DrawList->AddRect(p_min+ImVec2(0.5f-offset,0.5f-offset), p_max+ImVec2(0.0f-offset*2,0.0f-offset*2), window->Color(ImGuiCol_Border), rounding);
  1689. }
  1690. }
  1691. // Render a triangle to denote expanded/collapsed state
  1692. static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale, bool shadow)
  1693. {
  1694. ImGuiWindow* window = GetCurrentWindow();
  1695. const float h = window->FontSize() * 1.00f;
  1696. const float r = h * 0.40f * scale;
  1697. ImVec2 center = p_min + ImVec2(h*0.50f, h*0.50f*scale);
  1698. ImVec2 a, b, c;
  1699. if (opened)
  1700. {
  1701. center.y -= r*0.25f;
  1702. a = center + ImVec2(0,1)*r;
  1703. b = center + ImVec2(-0.866f,-0.5f)*r;
  1704. c = center + ImVec2(0.866f,-0.5f)*r;
  1705. }
  1706. else
  1707. {
  1708. a = center + ImVec2(1,0)*r;
  1709. b = center + ImVec2(-0.500f,0.866f)*r;
  1710. c = center + ImVec2(-0.500f,-0.866f)*r;
  1711. }
  1712. if (shadow && (window->Flags & ImGuiWindowFlags_ShowBorders) != 0)
  1713. window->DrawList->AddTriangleFilled(a+ImVec2(2,2), b+ImVec2(2,2), c+ImVec2(2,2), window->Color(ImGuiCol_BorderShadow));
  1714. window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Border));
  1715. }
  1716. // Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker.
  1717. // CalcTextSize("") should return ImVec2(0.0f, GImGui.FontSize)
  1718. ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width)
  1719. {
  1720. ImGuiWindow* window = GetCurrentWindow();
  1721. const char* text_display_end;
  1722. if (hide_text_after_double_hash)
  1723. text_display_end = FindTextDisplayEnd(text, text_end); // Hide anything after a '##' string
  1724. else
  1725. text_display_end = text_end;
  1726. const ImVec2 text_size = window->Font()->CalcTextSizeA(window->FontSize(), FLT_MAX, wrap_width, text, text_display_end, NULL);
  1727. return text_size;
  1728. }
  1729. // Find window given position, search front-to-back
  1730. static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs)
  1731. {
  1732. ImGuiState& g = GImGui;
  1733. for (int i = (int)g.Windows.size()-1; i >= 0; i--)
  1734. {
  1735. ImGuiWindow* window = g.Windows[(size_t)i];
  1736. if (!window->Visible)
  1737. continue;
  1738. if (excluding_childs && (window->Flags & ImGuiWindowFlags_ChildWindow) != 0)
  1739. continue;
  1740. ImGuiAabb bb(window->Pos - g.Style.TouchExtraPadding, window->Pos+window->Size + g.Style.TouchExtraPadding);
  1741. if (bb.Contains(pos))
  1742. return window;
  1743. }
  1744. return NULL;
  1745. }
  1746. // Test if mouse cursor is hovering given aabb
  1747. // NB- Box is clipped by our current clip setting
  1748. // NB- Expand the aabb to be generous on imprecise inputs systems (g.Style.TouchExtraPadding)
  1749. static bool IsMouseHoveringBox(const ImGuiAabb& box)
  1750. {
  1751. ImGuiState& g = GImGui;
  1752. ImGuiWindow* window = GetCurrentWindow();
  1753. // Clip
  1754. ImGuiAabb box_clipped = box;
  1755. if (!window->ClipRectStack.empty())
  1756. {
  1757. const ImVec4 clip_rect = window->ClipRectStack.back();
  1758. box_clipped.Clip(ImGuiAabb(ImVec2(clip_rect.x, clip_rect.y), ImVec2(clip_rect.z, clip_rect.w)));
  1759. }
  1760. // Expand for touch input
  1761. const ImGuiAabb box_for_touch(box_clipped.Min - g.Style.TouchExtraPadding, box_clipped.Max + g.Style.TouchExtraPadding);
  1762. return box_for_touch.Contains(g.IO.MousePos);
  1763. }
  1764. bool ImGui::IsMouseHoveringBox(const ImVec2& box_min, const ImVec2& box_max)
  1765. {
  1766. return IsMouseHoveringBox(ImGuiAabb(box_min, box_max));
  1767. }
  1768. bool ImGui::IsMouseHoveringWindow()
  1769. {
  1770. ImGuiState& g = GImGui;
  1771. ImGuiWindow* window = GetCurrentWindow();
  1772. return g.HoveredWindow == window;
  1773. }
  1774. bool ImGui::IsMouseHoveringAnyWindow()
  1775. {
  1776. ImGuiState& g = GImGui;
  1777. return g.HoveredWindow != NULL;
  1778. }
  1779. bool ImGui::IsPosHoveringAnyWindow(const ImVec2& pos)
  1780. {
  1781. return FindHoveredWindow(pos, false) != NULL;
  1782. }
  1783. static bool IsKeyPressedMap(ImGuiKey key, bool repeat)
  1784. {
  1785. ImGuiState& g = GImGui;
  1786. const int key_index = g.IO.KeyMap[key];
  1787. return ImGui::IsKeyPressed(key_index, repeat);
  1788. }
  1789. bool ImGui::IsKeyPressed(int key_index, bool repeat)
  1790. {
  1791. ImGuiState& g = GImGui;
  1792. IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown));
  1793. const float t = g.IO.KeysDownTime[key_index];
  1794. if (t == 0.0f)
  1795. return true;
  1796. // FIXME: Repeat rate should be provided elsewhere?
  1797. const float KEY_REPEAT_DELAY = 0.250f;
  1798. const float KEY_REPEAT_RATE = 0.020f;
  1799. if (repeat && t > KEY_REPEAT_DELAY)
  1800. if ((fmodf(t - KEY_REPEAT_DELAY, KEY_REPEAT_RATE) > KEY_REPEAT_RATE*0.5f) != (fmodf(t - KEY_REPEAT_DELAY - g.IO.DeltaTime, KEY_REPEAT_RATE) > KEY_REPEAT_RATE*0.5f))
  1801. return true;
  1802. return false;
  1803. }
  1804. bool ImGui::IsMouseClicked(int button, bool repeat)
  1805. {
  1806. ImGuiState& g = GImGui;
  1807. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  1808. const float t = g.IO.MouseDownTime[button];
  1809. if (t == 0.0f)
  1810. return true;
  1811. // FIXME: Repeat rate should be provided elsewhere?
  1812. const float MOUSE_REPEAT_DELAY = 0.250f;
  1813. const float MOUSE_REPEAT_RATE = 0.020f;
  1814. if (repeat && t > MOUSE_REPEAT_DELAY)
  1815. if ((fmodf(t - MOUSE_REPEAT_DELAY, MOUSE_REPEAT_RATE) > MOUSE_REPEAT_RATE*0.5f) != (fmodf(t - MOUSE_REPEAT_DELAY - g.IO.DeltaTime, MOUSE_REPEAT_RATE) > MOUSE_REPEAT_RATE*0.5f))
  1816. return true;
  1817. return false;
  1818. }
  1819. bool ImGui::IsMouseDoubleClicked(int button)
  1820. {
  1821. ImGuiState& g = GImGui;
  1822. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  1823. return g.IO.MouseDoubleClicked[button];
  1824. }
  1825. ImVec2 ImGui::GetMousePos()
  1826. {
  1827. return GImGui.IO.MousePos;
  1828. }
  1829. bool ImGui::IsItemHovered()
  1830. {
  1831. ImGuiWindow* window = GetCurrentWindow();
  1832. return window->DC.LastItemHovered;
  1833. }
  1834. bool ImGui::IsItemFocused()
  1835. {
  1836. ImGuiWindow* window = GetCurrentWindow();
  1837. return window->DC.LastItemFocused;
  1838. }
  1839. ImVec2 ImGui::GetItemBoxMin()
  1840. {
  1841. ImGuiWindow* window = GetCurrentWindow();
  1842. return window->DC.LastItemAabb.Min;
  1843. }
  1844. ImVec2 ImGui::GetItemBoxMax()
  1845. {
  1846. ImGuiWindow* window = GetCurrentWindow();
  1847. return window->DC.LastItemAabb.Max;
  1848. }
  1849. // Tooltip is stored and turned into a BeginTooltip()/EndTooltip() sequence at the end of the frame. Each call override previous value.
  1850. void ImGui::SetTooltipV(const char* fmt, va_list args)
  1851. {
  1852. ImGuiState& g = GImGui;
  1853. ImFormatStringV(g.Tooltip, IM_ARRAYSIZE(g.Tooltip), fmt, args);
  1854. }
  1855. void ImGui::SetTooltip(const char* fmt, ...)
  1856. {
  1857. va_list args;
  1858. va_start(args, fmt);
  1859. SetTooltipV(fmt, args);
  1860. va_end(args);
  1861. }
  1862. float ImGui::GetTime()
  1863. {
  1864. return GImGui.Time;
  1865. }
  1866. int ImGui::GetFrameCount()
  1867. {
  1868. return GImGui.FrameCount;
  1869. }
  1870. void ImGui::BeginTooltip()
  1871. {
  1872. ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), 0.9f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_Tooltip);
  1873. }
  1874. void ImGui::EndTooltip()
  1875. {
  1876. IM_ASSERT(GetCurrentWindow()->Flags & ImGuiWindowFlags_Tooltip);
  1877. ImGui::End();
  1878. }
  1879. void ImGui::BeginChild(const char* str_id, ImVec2 size, bool border, ImGuiWindowFlags extra_flags)
  1880. {
  1881. ImGuiState& g = GImGui;
  1882. ImGuiWindow* window = GetCurrentWindow();
  1883. ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_ChildWindow;
  1884. const ImVec2 content_max = window->Pos + ImGui::GetContentRegionMax();
  1885. const ImVec2 cursor_pos = window->Pos + ImGui::GetCursorPos();
  1886. if (size.x <= 0.0f)
  1887. {
  1888. if (size.x == 0.0f)
  1889. flags |= ImGuiWindowFlags_ChildWindowAutoFitX;
  1890. size.x = ImMax(content_max.x - cursor_pos.x, g.Style.WindowMinSize.x) - fabsf(size.x);
  1891. }
  1892. if (size.y <= 0.0f)
  1893. {
  1894. if (size.y == 0.0f)
  1895. flags |= ImGuiWindowFlags_ChildWindowAutoFitY;
  1896. size.y = ImMax(content_max.y - cursor_pos.y, g.Style.WindowMinSize.y) - fabsf(size.y);
  1897. }
  1898. if (border)
  1899. flags |= ImGuiWindowFlags_ShowBorders;
  1900. flags |= extra_flags;
  1901. char title[256];
  1902. ImFormatString(title, IM_ARRAYSIZE(title), "%s.%s", window->Name, str_id);
  1903. const float alpha = (flags & ImGuiWindowFlags_ComboBox) ? 1.0f : 0.0f;
  1904. ImGui::Begin(title, NULL, size, alpha, flags);
  1905. if (!(window->Flags & ImGuiWindowFlags_ShowBorders))
  1906. g.CurrentWindow->Flags &= ~ImGuiWindowFlags_ShowBorders;
  1907. }
  1908. void ImGui::EndChild()
  1909. {
  1910. ImGuiWindow* window = GetCurrentWindow();
  1911. IM_ASSERT(window->Flags & ImGuiWindowFlags_ChildWindow);
  1912. if (window->Flags & ImGuiWindowFlags_ComboBox)
  1913. {
  1914. ImGui::End();
  1915. }
  1916. else
  1917. {
  1918. // When using auto-filling child window, we don't provide the width/height to ItemSize so that it doesn't feed back into automatic size-fitting.
  1919. ImVec2 sz = ImGui::GetWindowSize();
  1920. if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitX)
  1921. sz.x = 0;
  1922. if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitY)
  1923. sz.y = 0;
  1924. ImGui::End();
  1925. ItemSize(sz);
  1926. }
  1927. }
  1928. static ImGuiWindow* FindWindowByName(const char* name)
  1929. {
  1930. // FIXME-OPT: Consider optimizing this (e.g. sorted hashes to window pointers)
  1931. ImGuiState& g = GImGui;
  1932. for (size_t i = 0; i != g.Windows.size(); i++)
  1933. if (strcmp(g.Windows[i]->Name, name) == 0)
  1934. return g.Windows[i];
  1935. return NULL;
  1936. }
  1937. static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFlags flags)
  1938. {
  1939. ImGuiState& g = GImGui;
  1940. // Create window the first time
  1941. ImGuiWindow* window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow));
  1942. new(window) ImGuiWindow(name);
  1943. window->Flags = flags;
  1944. if (flags & ImGuiWindowFlags_NoSavedSettings)
  1945. {
  1946. // User can disable loading and saving of settings. Tooltip and child windows also don't store settings.
  1947. window->Size = window->SizeFull = size;
  1948. }
  1949. else
  1950. {
  1951. // Retrieve settings from .ini file
  1952. // Use SetWindowPos() or SetNextWindowPos() with the appropriate condition flag to change the initial position of a window.
  1953. window->PosFloat = ImVec2(60, 60);
  1954. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  1955. ImGuiIniData* settings = FindWindowSettings(name);
  1956. if (!settings)
  1957. {
  1958. settings = AddWindowSettings(name);
  1959. }
  1960. else
  1961. {
  1962. window->SetWindowPosAllowFlags &= ~ImGuiSetCondition_FirstUseEver;
  1963. window->SetWindowSizeAllowFlags &= ~ImGuiSetCondition_FirstUseEver;
  1964. window->SetWindowCollapsedAllowFlags &= ~ImGuiSetCondition_FirstUseEver;
  1965. }
  1966. if (settings->Pos.x != FLT_MAX)
  1967. {
  1968. window->PosFloat = settings->Pos;
  1969. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  1970. window->Collapsed = settings->Collapsed;
  1971. }
  1972. if (ImLengthSqr(settings->Size) > 0.00001f && !(flags & ImGuiWindowFlags_NoResize))
  1973. size = settings->Size;
  1974. window->Size = window->SizeFull = size;
  1975. }
  1976. g.Windows.push_back(window);
  1977. return window;
  1978. }
  1979. // Push a new ImGui window to add widgets to.
  1980. // - A default window called "Debug" is automatically stacked at the beginning of every frame.
  1981. // - This can be called multiple times during the frame with the same window name to append content to the same window.
  1982. // - 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.
  1983. // - 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.
  1984. // - 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.
  1985. // - Passing non-zero 'size' is roughly equivalent to calling SetNextWindowSize(size, ImGuiSetCondition_FirstUseEver) prior to calling Begin().
  1986. bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alpha, ImGuiWindowFlags flags)
  1987. {
  1988. ImGuiState& g = GImGui;
  1989. const ImGuiStyle& style = g.Style;
  1990. IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame()
  1991. IM_ASSERT(name != NULL); // Must pass a name
  1992. // Find or create
  1993. ImGuiWindow* window = FindWindowByName(name);
  1994. if (!window)
  1995. window = CreateNewWindow(name, size, flags);
  1996. window->Flags = (ImGuiWindowFlags)flags;
  1997. // Add to stack
  1998. g.CurrentWindowStack.push_back(window);
  1999. g.CurrentWindow = window;
  2000. // Process SetNextWindow***() calls
  2001. if (g.SetNextWindowPosCond)
  2002. {
  2003. const ImVec2 backup_cursor_pos = window->DC.CursorPos;
  2004. ImGui::SetWindowPos(g.SetNextWindowPosVal, g.SetNextWindowPosCond);
  2005. window->DC.CursorPos = backup_cursor_pos;
  2006. g.SetNextWindowPosCond = 0;
  2007. }
  2008. if (g.SetNextWindowSizeCond)
  2009. {
  2010. ImGui::SetWindowSize(g.SetNextWindowSizeVal, g.SetNextWindowSizeCond);
  2011. g.SetNextWindowSizeCond = 0;
  2012. }
  2013. if (g.SetNextWindowCollapsedCond)
  2014. {
  2015. ImGui::SetWindowCollapsed(g.SetNextWindowCollapsedVal, g.SetNextWindowCollapsedCond);
  2016. g.SetNextWindowCollapsedCond = 0;
  2017. }
  2018. // Find root (if we are a child window)
  2019. size_t root_idx = g.CurrentWindowStack.size() - 1;
  2020. while (root_idx > 0)
  2021. {
  2022. if ((g.CurrentWindowStack[root_idx]->Flags & ImGuiWindowFlags_ChildWindow) == 0)
  2023. break;
  2024. root_idx--;
  2025. }
  2026. window->RootWindow = g.CurrentWindowStack[root_idx];
  2027. // Default alpha
  2028. if (fill_alpha < 0.0f)
  2029. fill_alpha = style.WindowFillAlphaDefault;
  2030. // When reusing window again multiple times a frame, just append content (don't need to setup again)
  2031. const int current_frame = ImGui::GetFrameCount();
  2032. const bool first_begin_of_the_frame = (window->LastFrameDrawn != current_frame);
  2033. if (first_begin_of_the_frame)
  2034. {
  2035. window->DrawList->Clear();
  2036. window->Visible = true;
  2037. // New windows appears in front
  2038. if (window->LastFrameDrawn < current_frame - 1)
  2039. {
  2040. FocusWindow(window);
  2041. if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
  2042. {
  2043. // Hide for 1 frame while resizing
  2044. window->AutoFitFrames = 2;
  2045. window->AutoFitOnlyGrows = false;
  2046. window->Visible = false;
  2047. }
  2048. }
  2049. window->LastFrameDrawn = current_frame;
  2050. window->ClipRectStack.resize(0);
  2051. if (flags & ImGuiWindowFlags_ChildWindow)
  2052. {
  2053. ImGuiWindow* parent_window = g.CurrentWindowStack[g.CurrentWindowStack.size()-2];
  2054. parent_window->DC.ChildWindows.push_back(window);
  2055. window->Pos = window->PosFloat = parent_window->DC.CursorPos;
  2056. window->SizeFull = size;
  2057. }
  2058. // Outer clipping rectangle
  2059. if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox))
  2060. PushClipRect(g.CurrentWindowStack[g.CurrentWindowStack.size()-2]->ClipRectStack.back());
  2061. else
  2062. PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y));
  2063. // Seed ID stack with our window pointer
  2064. window->IDStack.resize(0);
  2065. ImGui::PushID(window);
  2066. // Move window (at the beginning of the frame to avoid input lag or sheering)
  2067. const ImGuiID move_id = window->GetID("#MOVE");
  2068. RegisterAliveId(move_id);
  2069. if (g.ActiveId == move_id)
  2070. {
  2071. if (g.IO.MouseDown[0])
  2072. {
  2073. if (!(window->Flags & ImGuiWindowFlags_NoMove))
  2074. {
  2075. window->PosFloat += g.IO.MouseDelta;
  2076. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2077. MarkSettingsDirty();
  2078. }
  2079. FocusWindow(window);
  2080. }
  2081. else
  2082. {
  2083. g.ActiveId = 0;
  2084. }
  2085. }
  2086. // Tooltips always follow mouse
  2087. if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
  2088. {
  2089. window->PosFloat = g.IO.MousePos + ImVec2(32,16) - style.FramePadding*2;
  2090. }
  2091. // Clamp into view
  2092. if (!(window->Flags & ImGuiWindowFlags_ChildWindow))
  2093. {
  2094. const ImVec2 pad = ImVec2(window->FontSize()*2.0f, window->FontSize()*2.0f);
  2095. if (g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f) // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing.
  2096. {
  2097. window->PosFloat = ImMax(window->PosFloat + window->Size, pad) - window->Size;
  2098. window->PosFloat = ImMin(window->PosFloat, ImVec2(g.IO.DisplaySize.x, g.IO.DisplaySize.y) - pad);
  2099. }
  2100. window->SizeFull = ImMax(window->SizeFull, pad);
  2101. }
  2102. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  2103. // Default item width
  2104. if (window->Size.x > 0.0f && !(window->Flags & ImGuiWindowFlags_Tooltip) && !(window->Flags & ImGuiWindowFlags_AlwaysAutoResize))
  2105. window->ItemWidthDefault = (float)(int)(window->Size.x * 0.65f);
  2106. else
  2107. window->ItemWidthDefault = 200.0f;
  2108. // Prepare for focus requests
  2109. if (window->FocusIdxAllRequestNext == IM_INT_MAX || window->FocusIdxAllCounter == -1)
  2110. window->FocusIdxAllRequestCurrent = IM_INT_MAX;
  2111. else
  2112. window->FocusIdxAllRequestCurrent = (window->FocusIdxAllRequestNext + (window->FocusIdxAllCounter+1)) % (window->FocusIdxAllCounter+1);
  2113. if (window->FocusIdxTabRequestNext == IM_INT_MAX || window->FocusIdxTabCounter == -1)
  2114. window->FocusIdxTabRequestCurrent = IM_INT_MAX;
  2115. else
  2116. window->FocusIdxTabRequestCurrent = (window->FocusIdxTabRequestNext + (window->FocusIdxTabCounter+1)) % (window->FocusIdxTabCounter+1);
  2117. window->FocusIdxAllCounter = window->FocusIdxTabCounter = -1;
  2118. window->FocusIdxAllRequestNext = window->FocusIdxTabRequestNext = IM_INT_MAX;
  2119. ImGuiAabb title_bar_aabb = window->TitleBarAabb();
  2120. // Apply and ImClamp scrolling
  2121. window->ScrollY = window->NextScrollY;
  2122. window->ScrollY = ImMax(window->ScrollY, 0.0f);
  2123. if (!window->Collapsed && !window->SkipItems)
  2124. window->ScrollY = ImMin(window->ScrollY, ImMax(0.0f, (float)window->SizeContentsFit.y - window->SizeFull.y));
  2125. window->NextScrollY = window->ScrollY;
  2126. // At this point we don't have a clipping rectangle setup yet, so we can test and draw in title bar
  2127. // Collapse window by double-clicking on title bar
  2128. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2129. {
  2130. if (g.HoveredWindow == window && IsMouseHoveringBox(title_bar_aabb) && g.IO.MouseDoubleClicked[0])
  2131. {
  2132. window->Collapsed = !window->Collapsed;
  2133. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2134. MarkSettingsDirty();
  2135. FocusWindow(window);
  2136. }
  2137. }
  2138. else
  2139. {
  2140. window->Collapsed = false;
  2141. }
  2142. if (window->Collapsed)
  2143. {
  2144. // Draw title bar only
  2145. window->Size = title_bar_aabb.GetSize();
  2146. window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBgCollapsed), style.WindowRounding);
  2147. if (window->Flags & ImGuiWindowFlags_ShowBorders)
  2148. {
  2149. window->DrawList->AddRect(title_bar_aabb.GetTL()+ImVec2(1,1), title_bar_aabb.GetBR()+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), style.WindowRounding);
  2150. window->DrawList->AddRect(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_Border), style.WindowRounding);
  2151. }
  2152. }
  2153. else
  2154. {
  2155. window->Size = window->SizeFull;
  2156. ImU32 resize_col = 0;
  2157. if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
  2158. {
  2159. // Tooltip always resize
  2160. if (window->AutoFitFrames > 0)
  2161. {
  2162. window->SizeFull = window->SizeContentsFit + style.WindowPadding - ImVec2(0.0f, style.ItemSpacing.y);
  2163. }
  2164. }
  2165. else
  2166. {
  2167. const ImVec2 size_auto_fit = ImClamp(window->SizeContentsFit + style.AutoFitPadding, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding));
  2168. if ((window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0)
  2169. {
  2170. // Don't continuously mark settings as dirty, the size of the window doesn't need to be stored.
  2171. window->SizeFull = size_auto_fit;
  2172. }
  2173. else if (window->AutoFitFrames > 0)
  2174. {
  2175. // Auto-fit only grows during the first few frames
  2176. if (window->AutoFitOnlyGrows)
  2177. window->SizeFull = ImMax(window->SizeFull, size_auto_fit);
  2178. else
  2179. window->SizeFull = size_auto_fit;
  2180. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2181. MarkSettingsDirty();
  2182. }
  2183. else if (!(window->Flags & ImGuiWindowFlags_NoResize))
  2184. {
  2185. // Resize grip
  2186. const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR());
  2187. const ImGuiID resize_id = window->GetID("##RESIZE");
  2188. bool hovered, held;
  2189. ButtonBehaviour(resize_aabb, resize_id, &hovered, &held, true);
  2190. resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip);
  2191. if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0])
  2192. {
  2193. // Manual auto-fit
  2194. window->SizeFull = size_auto_fit;
  2195. window->Size = window->SizeFull;
  2196. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2197. MarkSettingsDirty();
  2198. }
  2199. else if (held)
  2200. {
  2201. // Resize
  2202. window->SizeFull = ImMax(window->SizeFull + g.IO.MouseDelta, style.WindowMinSize);
  2203. window->Size = window->SizeFull;
  2204. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2205. MarkSettingsDirty();
  2206. }
  2207. }
  2208. // Update aabb immediately so that the rendering below isn't one frame late
  2209. title_bar_aabb = window->TitleBarAabb();
  2210. }
  2211. // Title bar + Window box
  2212. if (fill_alpha > 0.0f)
  2213. {
  2214. if ((window->Flags & ImGuiWindowFlags_ComboBox) != 0)
  2215. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_ComboBg, fill_alpha), 0);
  2216. else
  2217. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, fill_alpha), style.WindowRounding);
  2218. }
  2219. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2220. window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBg), style.WindowRounding, 1|2);
  2221. // Borders
  2222. if (window->Flags & ImGuiWindowFlags_ShowBorders)
  2223. {
  2224. const float rounding = (window->Flags & ImGuiWindowFlags_ComboBox) ? 0.0f : style.WindowRounding;
  2225. window->DrawList->AddRect(window->Pos+ImVec2(1,1), window->Pos+window->Size+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), rounding);
  2226. window->DrawList->AddRect(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_Border), rounding);
  2227. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2228. window->DrawList->AddLine(title_bar_aabb.GetBL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_Border));
  2229. }
  2230. // Scrollbar
  2231. window->ScrollbarY = (window->SizeContentsFit.y > window->Size.y) && !(window->Flags & ImGuiWindowFlags_NoScrollbar);
  2232. if (window->ScrollbarY)
  2233. {
  2234. ImGuiAabb scrollbar_bb(window->Aabb().Max.x - style.ScrollBarWidth, title_bar_aabb.Max.y+1, window->Aabb().Max.x, window->Aabb().Max.y-1);
  2235. //window->DrawList->AddLine(scrollbar_bb.GetTL(), scrollbar_bb.GetBL(), g.Colors[ImGuiCol_Border]);
  2236. window->DrawList->AddRectFilled(scrollbar_bb.Min, scrollbar_bb.Max, window->Color(ImGuiCol_ScrollbarBg));
  2237. scrollbar_bb.Expand(ImVec2(-3,-3));
  2238. const float grab_size_y_norm = ImSaturate(window->Size.y / ImMax(window->SizeContentsFit.y, window->Size.y));
  2239. const float grab_size_y = scrollbar_bb.GetHeight() * grab_size_y_norm;
  2240. // Handle input right away (none of the code above is relying on scrolling position)
  2241. bool held = false;
  2242. bool hovered = false;
  2243. if (grab_size_y_norm < 1.0f)
  2244. {
  2245. const ImGuiID scrollbar_id = window->GetID("#SCROLLY");
  2246. ButtonBehaviour(scrollbar_bb, scrollbar_id, &hovered, &held, true);
  2247. if (held)
  2248. {
  2249. g.HoveredId = scrollbar_id;
  2250. 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);
  2251. window->ScrollY = pos_y_norm * window->SizeContentsFit.y;
  2252. window->NextScrollY = window->ScrollY;
  2253. }
  2254. }
  2255. // Normalized height of the grab
  2256. const float pos_y_norm = ImSaturate(window->ScrollY / ImMax(0.0f, window->SizeContentsFit.y));
  2257. const ImU32 grab_col = window->Color(held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab);
  2258. window->DrawList->AddRectFilled(
  2259. ImVec2(scrollbar_bb.Min.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y, pos_y_norm)),
  2260. ImVec2(scrollbar_bb.Max.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y, pos_y_norm + grab_size_y_norm)), grab_col);
  2261. }
  2262. // Render resize grip
  2263. // (after the input handling so we don't have a frame of latency)
  2264. if (!(window->Flags & ImGuiWindowFlags_NoResize))
  2265. {
  2266. const float r = style.WindowRounding;
  2267. const ImVec2 br = window->Aabb().GetBR();
  2268. if (r == 0.0f)
  2269. {
  2270. window->DrawList->AddTriangleFilled(br, br-ImVec2(0,14), br-ImVec2(14,0), resize_col);
  2271. }
  2272. else
  2273. {
  2274. // FIXME: We should draw 4 triangles and decide on a size that's not dependant on the rounding size (previously used 18)
  2275. window->DrawList->AddArc(br - ImVec2(r,r), r, resize_col, 6, 9, true);
  2276. window->DrawList->AddTriangleFilled(br+ImVec2(0,-2*r),br+ImVec2(0,-r),br+ImVec2(-r,-r), resize_col);
  2277. window->DrawList->AddTriangleFilled(br+ImVec2(-r,-r), br+ImVec2(-r,0),br+ImVec2(-2*r,0), resize_col);
  2278. }
  2279. }
  2280. }
  2281. // Setup drawing context
  2282. window->DC.ColumnsStartX = window->WindowPadding().x;
  2283. window->DC.ColumnsOffsetX = 0.0f;
  2284. window->DC.CursorStartPos = window->Pos + ImVec2(window->DC.ColumnsStartX + window->DC.ColumnsOffsetX, window->TitleBarHeight() + window->WindowPadding().y) - ImVec2(0.0f, window->ScrollY);
  2285. window->DC.CursorPos = window->DC.CursorStartPos;
  2286. window->DC.CursorPosPrevLine = window->DC.CursorPos;
  2287. window->DC.CurrentLineHeight = window->DC.PrevLineHeight = 0.0f;
  2288. window->DC.LogLineHeight = window->DC.CursorPos.y - 9999.0f;
  2289. window->DC.ChildWindows.resize(0);
  2290. window->DC.ItemWidth.resize(0);
  2291. window->DC.ItemWidth.push_back(window->ItemWidthDefault);
  2292. window->DC.AllowKeyboardFocus.resize(0);
  2293. window->DC.AllowKeyboardFocus.push_back(true);
  2294. window->DC.TextWrapPos.resize(0);
  2295. window->DC.TextWrapPos.push_back(-1.0f); // disabled
  2296. window->DC.ColorEditMode = ImGuiColorEditMode_UserSelect;
  2297. window->DC.ColumnsCurrent = 0;
  2298. window->DC.ColumnsCount = 1;
  2299. window->DC.ColumnsStartPos = window->DC.CursorPos;
  2300. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.ColumnsStartPos.y;
  2301. window->DC.TreeDepth = 0;
  2302. window->DC.StateStorage = &window->StateStorage;
  2303. window->DC.OpenNextNode = -1;
  2304. // Reset contents size for auto-fitting
  2305. window->SizeContentsFit = ImVec2(0.0f, 0.0f);
  2306. if (window->AutoFitFrames > 0)
  2307. window->AutoFitFrames--;
  2308. // Title bar
  2309. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2310. {
  2311. RenderCollapseTriangle(window->Pos + style.FramePadding, !window->Collapsed, 1.0f, true);
  2312. if (p_opened != NULL)
  2313. CloseWindowButton(p_opened);
  2314. const ImVec2 text_size = CalcTextSize(name, NULL, true);
  2315. const ImVec2 text_min = window->Pos + style.FramePadding + ImVec2(window->FontSize() + style.ItemInnerSpacing.x, 0.0f);
  2316. const ImVec2 text_max = window->Pos + ImVec2(window->Size.x - (p_opened ? (title_bar_aabb.GetHeight()-3) : style.FramePadding.x), style.FramePadding.y + text_size.y);
  2317. const bool clip_title = text_size.x > (text_max.x - text_min.x); // only push a clip rectangle if we need to, because it may turn into a separate draw call
  2318. if (clip_title)
  2319. PushClipRect(ImVec4(text_min.x, text_min.y, text_max.x, text_max.y));
  2320. RenderText(text_min, name);
  2321. if (clip_title)
  2322. PopClipRect();
  2323. }
  2324. }
  2325. else
  2326. {
  2327. // Outer clipping rectangle
  2328. if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox))
  2329. {
  2330. ImGuiWindow* parent_window = g.CurrentWindowStack[g.CurrentWindowStack.size()-2];
  2331. PushClipRect(parent_window->ClipRectStack.back());
  2332. }
  2333. else
  2334. {
  2335. PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y));
  2336. }
  2337. }
  2338. // Inner clipping rectangle
  2339. // We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame
  2340. const ImGuiAabb title_bar_aabb = window->TitleBarAabb();
  2341. 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);
  2342. if (window->ScrollbarY)
  2343. clip_rect.z -= style.ScrollBarWidth;
  2344. PushClipRect(clip_rect);
  2345. // Clear 'accessed' flag last thing
  2346. if (first_begin_of_the_frame)
  2347. window->Accessed = false;
  2348. // Child window can be out of sight and have "negative" clip windows.
  2349. // Mark them as collapsed so commands are skipped earlier (we can't manually collapse because they have no title bar).
  2350. if (flags & ImGuiWindowFlags_ChildWindow)
  2351. {
  2352. IM_ASSERT((flags & ImGuiWindowFlags_NoTitleBar) != 0);
  2353. const ImVec4 clip_rect_t = window->ClipRectStack.back();
  2354. window->Collapsed = (clip_rect_t.x >= clip_rect_t.z || clip_rect_t.y >= clip_rect_t.w);
  2355. // We also hide the window from rendering because we've already added its border to the command list.
  2356. // (we could perform the check earlier in the function but it is simpler at this point)
  2357. if (window->Collapsed)
  2358. window->Visible = false;
  2359. }
  2360. if (style.Alpha <= 0.0f)
  2361. window->Visible = false;
  2362. // Return false if we don't intend to display anything to allow user to perform an early out optimization
  2363. window->SkipItems = window->Collapsed || (!window->Visible && window->AutoFitFrames == 0);
  2364. return !window->SkipItems;
  2365. }
  2366. void ImGui::End()
  2367. {
  2368. ImGuiState& g = GImGui;
  2369. ImGuiWindow* window = g.CurrentWindow;
  2370. ImGui::Columns(1, "#CloseColumns");
  2371. PopClipRect(); // inner window clip rectangle
  2372. PopClipRect(); // outer window clip rectangle
  2373. // Select window for move/focus when we're done with all our widgets (we only consider non-childs windows here)
  2374. const ImGuiAabb bb(window->Pos, window->Pos+window->Size);
  2375. if (g.ActiveId == 0 && g.HoveredId == 0 && g.HoveredRootWindow == window && IsMouseHoveringBox(bb) && g.IO.MouseClicked[0])
  2376. g.ActiveId = window->GetID("#MOVE");
  2377. // Stop logging
  2378. if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) // FIXME: add more options for scope of logging
  2379. ImGui::LogFinish();
  2380. // Pop
  2381. // NB: we don't clear 'window->RootWindow' yet, it will be used then cleared in NewFrame()
  2382. g.CurrentWindowStack.pop_back();
  2383. g.CurrentWindow = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back();
  2384. }
  2385. // Moving window to front of display (which happens to be back of our sorted list)
  2386. static void FocusWindow(ImGuiWindow* window)
  2387. {
  2388. ImGuiState& g = GImGui;
  2389. g.FocusedWindow = window;
  2390. if (g.Windows.back() == window)
  2391. return;
  2392. for (size_t i = 0; i < g.Windows.size(); i++)
  2393. if (g.Windows[i] == window)
  2394. {
  2395. g.Windows.erase(g.Windows.begin() + i);
  2396. break;
  2397. }
  2398. g.Windows.push_back(window);
  2399. }
  2400. void ImGui::PushItemWidth(float item_width)
  2401. {
  2402. ImGuiWindow* window = GetCurrentWindow();
  2403. item_width = (float)(int)item_width;
  2404. window->DC.ItemWidth.push_back(item_width > 0.0f ? item_width : window->ItemWidthDefault);
  2405. }
  2406. void ImGui::PopItemWidth()
  2407. {
  2408. ImGuiWindow* window = GetCurrentWindow();
  2409. window->DC.ItemWidth.pop_back();
  2410. }
  2411. float ImGui::GetItemWidth()
  2412. {
  2413. ImGuiWindow* window = GetCurrentWindow();
  2414. return window->DC.ItemWidth.back();
  2415. }
  2416. void ImGui::PushAllowKeyboardFocus(bool allow_keyboard_focus)
  2417. {
  2418. ImGuiWindow* window = GetCurrentWindow();
  2419. window->DC.AllowKeyboardFocus.push_back(allow_keyboard_focus);
  2420. }
  2421. void ImGui::PopAllowKeyboardFocus()
  2422. {
  2423. ImGuiWindow* window = GetCurrentWindow();
  2424. window->DC.AllowKeyboardFocus.pop_back();
  2425. }
  2426. void ImGui::PushTextWrapPos(float wrap_x)
  2427. {
  2428. ImGuiWindow* window = GetCurrentWindow();
  2429. window->DC.TextWrapPos.push_back(wrap_x);
  2430. }
  2431. void ImGui::PopTextWrapPos()
  2432. {
  2433. ImGuiWindow* window = GetCurrentWindow();
  2434. window->DC.TextWrapPos.pop_back();
  2435. }
  2436. void ImGui::PushStyleColor(ImGuiCol idx, const ImVec4& col)
  2437. {
  2438. ImGuiState& g = GImGui;
  2439. ImGuiColMod backup;
  2440. backup.Col = idx;
  2441. backup.PreviousValue = g.Style.Colors[idx];
  2442. g.ColorModifiers.push_back(backup);
  2443. g.Style.Colors[idx] = col;
  2444. }
  2445. void ImGui::PopStyleColor(int count)
  2446. {
  2447. ImGuiState& g = GImGui;
  2448. while (count > 0)
  2449. {
  2450. ImGuiColMod& backup = g.ColorModifiers.back();
  2451. g.Style.Colors[backup.Col] = backup.PreviousValue;
  2452. g.ColorModifiers.pop_back();
  2453. count--;
  2454. }
  2455. }
  2456. static float* GetStyleVarFloatAddr(ImGuiStyleVar idx)
  2457. {
  2458. ImGuiState& g = GImGui;
  2459. switch (idx)
  2460. {
  2461. case ImGuiStyleVar_Alpha: return &g.Style.Alpha;
  2462. case ImGuiStyleVar_WindowRounding: return &g.Style.WindowRounding;
  2463. case ImGuiStyleVar_TreeNodeSpacing: return &g.Style.TreeNodeSpacing;
  2464. }
  2465. return NULL;
  2466. }
  2467. static ImVec2* GetStyleVarVec2Addr(ImGuiStyleVar idx)
  2468. {
  2469. ImGuiState& g = GImGui;
  2470. switch (idx)
  2471. {
  2472. case ImGuiStyleVar_WindowPadding: return &g.Style.WindowPadding;
  2473. case ImGuiStyleVar_FramePadding: return &g.Style.FramePadding;
  2474. case ImGuiStyleVar_ItemSpacing: return &g.Style.ItemSpacing;
  2475. case ImGuiStyleVar_ItemInnerSpacing: return &g.Style.ItemInnerSpacing;
  2476. }
  2477. return NULL;
  2478. }
  2479. void ImGui::PushStyleVar(ImGuiStyleVar idx, float val)
  2480. {
  2481. ImGuiState& g = GImGui;
  2482. float* pvar = GetStyleVarFloatAddr(idx);
  2483. IM_ASSERT(pvar != NULL); // Called wrong function?
  2484. ImGuiStyleMod backup;
  2485. backup.Var = idx;
  2486. backup.PreviousValue = ImVec2(*pvar, 0.0f);
  2487. g.StyleModifiers.push_back(backup);
  2488. *pvar = val;
  2489. }
  2490. void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val)
  2491. {
  2492. ImGuiState& g = GImGui;
  2493. ImVec2* pvar = GetStyleVarVec2Addr(idx);
  2494. IM_ASSERT(pvar != NULL); // Called wrong function?
  2495. ImGuiStyleMod backup;
  2496. backup.Var = idx;
  2497. backup.PreviousValue = *pvar;
  2498. g.StyleModifiers.push_back(backup);
  2499. *pvar = val;
  2500. }
  2501. void ImGui::PopStyleVar(int count)
  2502. {
  2503. ImGuiState& g = GImGui;
  2504. while (count > 0)
  2505. {
  2506. ImGuiStyleMod& backup = g.StyleModifiers.back();
  2507. if (float* pvar_f = GetStyleVarFloatAddr(backup.Var))
  2508. *pvar_f = backup.PreviousValue.x;
  2509. else if (ImVec2* pvar_v = GetStyleVarVec2Addr(backup.Var))
  2510. *pvar_v = backup.PreviousValue;
  2511. g.StyleModifiers.pop_back();
  2512. count--;
  2513. }
  2514. }
  2515. const char* ImGui::GetStyleColName(ImGuiCol idx)
  2516. {
  2517. // Create switch-case from enum with regexp: ImGuiCol_{.*}, --> case ImGuiCol_\1: return "\1";
  2518. switch (idx)
  2519. {
  2520. case ImGuiCol_Text: return "Text";
  2521. case ImGuiCol_WindowBg: return "WindowBg";
  2522. case ImGuiCol_Border: return "Border";
  2523. case ImGuiCol_BorderShadow: return "BorderShadow";
  2524. case ImGuiCol_FrameBg: return "FrameBg";
  2525. case ImGuiCol_TitleBg: return "TitleBg";
  2526. case ImGuiCol_TitleBgCollapsed: return "TitleBgCollapsed";
  2527. case ImGuiCol_ScrollbarBg: return "ScrollbarBg";
  2528. case ImGuiCol_ScrollbarGrab: return "ScrollbarGrab";
  2529. case ImGuiCol_ScrollbarGrabHovered: return "ScrollbarGrabHovered";
  2530. case ImGuiCol_ScrollbarGrabActive: return "ScrollbarGrabActive";
  2531. case ImGuiCol_ComboBg: return "ComboBg";
  2532. case ImGuiCol_CheckHovered: return "CheckBgHovered";
  2533. case ImGuiCol_CheckActive: return "CheckBgActive";
  2534. case ImGuiCol_CheckMark: return "CheckSelected";
  2535. case ImGuiCol_SliderGrab: return "SliderGrab";
  2536. case ImGuiCol_SliderGrabActive: return "SliderGrabActive";
  2537. case ImGuiCol_Button: return "Button";
  2538. case ImGuiCol_ButtonHovered: return "ButtonHovered";
  2539. case ImGuiCol_ButtonActive: return "ButtonActive";
  2540. case ImGuiCol_Header: return "Header";
  2541. case ImGuiCol_HeaderHovered: return "HeaderHovered";
  2542. case ImGuiCol_HeaderActive: return "HeaderActive";
  2543. case ImGuiCol_Column: return "Column";
  2544. case ImGuiCol_ColumnHovered: return "ColumnHovered";
  2545. case ImGuiCol_ColumnActive: return "ColumnActive";
  2546. case ImGuiCol_ResizeGrip: return "ResizeGrip";
  2547. case ImGuiCol_ResizeGripHovered: return "ResizeGripHovered";
  2548. case ImGuiCol_ResizeGripActive: return "ResizeGripActive";
  2549. case ImGuiCol_CloseButton: return "CloseButton";
  2550. case ImGuiCol_CloseButtonHovered: return "CloseButtonHovered";
  2551. case ImGuiCol_CloseButtonActive: return "CloseButtonActive";
  2552. case ImGuiCol_PlotLines: return "PlotLines";
  2553. case ImGuiCol_PlotLinesHovered: return "PlotLinesHovered";
  2554. case ImGuiCol_PlotHistogram: return "PlotHistogram";
  2555. case ImGuiCol_PlotHistogramHovered: return "PlotHistogramHovered";
  2556. case ImGuiCol_TextSelectedBg: return "TextSelectedBg";
  2557. case ImGuiCol_TooltipBg: return "TooltipBg";
  2558. }
  2559. IM_ASSERT(0);
  2560. return "Unknown";
  2561. }
  2562. bool ImGui::GetWindowIsFocused()
  2563. {
  2564. ImGuiState& g = GImGui;
  2565. ImGuiWindow* window = GetCurrentWindow();
  2566. return g.FocusedWindow == window;
  2567. }
  2568. float ImGui::GetWindowWidth()
  2569. {
  2570. ImGuiWindow* window = GetCurrentWindow();
  2571. return window->Size.x;
  2572. }
  2573. ImVec2 ImGui::GetWindowPos()
  2574. {
  2575. ImGuiWindow* window = GetCurrentWindow();
  2576. return window->Pos;
  2577. }
  2578. void ImGui::SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond)
  2579. {
  2580. ImGuiWindow* window = GetCurrentWindow();
  2581. // Test condition (NB: bit 0 is always true) and clear flags for next time
  2582. if (cond && (window->SetWindowPosAllowFlags & cond) == 0)
  2583. return;
  2584. window->SetWindowPosAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver);
  2585. // Set
  2586. const ImVec2 old_pos = window->Pos;
  2587. window->PosFloat = pos;
  2588. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  2589. 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
  2590. }
  2591. ImVec2 ImGui::GetWindowSize()
  2592. {
  2593. ImGuiWindow* window = GetCurrentWindow();
  2594. return window->Size;
  2595. }
  2596. void ImGui::SetWindowSize(const ImVec2& size, ImGuiSetCondition cond)
  2597. {
  2598. ImGuiWindow* window = GetCurrentWindow();
  2599. // Test condition (NB: bit 0 is always true) and clear flags for next time
  2600. if (cond && (window->SetWindowSizeAllowFlags & cond) == 0)
  2601. return;
  2602. window->SetWindowSizeAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver);
  2603. // Set
  2604. if (ImLengthSqr(size) > 0.00001f)
  2605. {
  2606. window->SizeFull = size;
  2607. window->AutoFitFrames = 0;
  2608. }
  2609. else
  2610. {
  2611. // Autofit
  2612. window->AutoFitFrames = 2;
  2613. window->AutoFitOnlyGrows = false;
  2614. }
  2615. }
  2616. void ImGui::SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond)
  2617. {
  2618. ImGuiWindow* window = GetCurrentWindow();
  2619. // Test condition (NB: bit 0 is always true) and clear flags for next time
  2620. if (cond && (window->SetWindowCollapsedAllowFlags & cond) == 0)
  2621. return;
  2622. window->SetWindowCollapsedAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver);
  2623. // Set
  2624. window->Collapsed = collapsed;
  2625. }
  2626. void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiSetCondition cond)
  2627. {
  2628. ImGuiState& g = GImGui;
  2629. g.SetNextWindowPosVal = pos;
  2630. g.SetNextWindowPosCond = cond ? cond : ImGuiSetCondition_Always;
  2631. }
  2632. void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiSetCondition cond)
  2633. {
  2634. ImGuiState& g = GImGui;
  2635. g.SetNextWindowSizeVal = size;
  2636. g.SetNextWindowSizeCond = cond ? cond : ImGuiSetCondition_Always;
  2637. }
  2638. void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiSetCondition cond)
  2639. {
  2640. ImGuiState& g = GImGui;
  2641. g.SetNextWindowCollapsedVal = collapsed;
  2642. g.SetNextWindowCollapsedCond = cond ? cond : ImGuiSetCondition_Always;
  2643. }
  2644. ImVec2 ImGui::GetContentRegionMax()
  2645. {
  2646. ImGuiWindow* window = GetCurrentWindow();
  2647. ImVec2 m = window->Size - window->WindowPadding();
  2648. if (window->DC.ColumnsCount != 1)
  2649. {
  2650. m.x = GetColumnOffset(window->DC.ColumnsCurrent + 1);
  2651. m.x -= GImGui.Style.WindowPadding.x;
  2652. }
  2653. else
  2654. {
  2655. if (window->ScrollbarY)
  2656. m.x -= GImGui.Style.ScrollBarWidth;
  2657. }
  2658. return m;
  2659. }
  2660. ImVec2 ImGui::GetWindowContentRegionMin()
  2661. {
  2662. ImGuiWindow* window = GetCurrentWindow();
  2663. return ImVec2(0, window->TitleBarHeight()) + window->WindowPadding();
  2664. }
  2665. ImVec2 ImGui::GetWindowContentRegionMax()
  2666. {
  2667. ImGuiWindow* window = GetCurrentWindow();
  2668. ImVec2 m = window->Size - window->WindowPadding();
  2669. if (window->ScrollbarY)
  2670. m.x -= GImGui.Style.ScrollBarWidth;
  2671. return m;
  2672. }
  2673. float ImGui::GetTextLineHeight()
  2674. {
  2675. ImGuiWindow* window = GetCurrentWindow();
  2676. return window->FontSize();
  2677. }
  2678. float ImGui::GetTextLineSpacing()
  2679. {
  2680. ImGuiState& g = GImGui;
  2681. ImGuiWindow* window = GetCurrentWindow();
  2682. return window->FontSize() + g.Style.ItemSpacing.y;
  2683. }
  2684. ImDrawList* ImGui::GetWindowDrawList()
  2685. {
  2686. ImGuiWindow* window = GetCurrentWindow();
  2687. return window->DrawList;
  2688. }
  2689. ImFont* ImGui::GetWindowFont()
  2690. {
  2691. ImGuiWindow* window = GetCurrentWindow();
  2692. return window->Font();
  2693. }
  2694. float ImGui::GetWindowFontSize()
  2695. {
  2696. ImGuiWindow* window = GetCurrentWindow();
  2697. return window->FontSize();
  2698. }
  2699. void ImGui::SetWindowFontScale(float scale)
  2700. {
  2701. ImGuiWindow* window = GetCurrentWindow();
  2702. window->FontWindowScale = scale;
  2703. }
  2704. ImVec2 ImGui::GetCursorPos()
  2705. {
  2706. ImGuiWindow* window = GetCurrentWindow();
  2707. return window->DC.CursorPos - window->Pos;
  2708. }
  2709. void ImGui::SetCursorPos(const ImVec2& pos)
  2710. {
  2711. ImGuiWindow* window = GetCurrentWindow();
  2712. window->DC.CursorPos = window->Pos + pos;
  2713. }
  2714. void ImGui::SetCursorPosX(float x)
  2715. {
  2716. ImGuiWindow* window = GetCurrentWindow();
  2717. window->DC.CursorPos.x = window->Pos.x + x;
  2718. }
  2719. void ImGui::SetCursorPosY(float y)
  2720. {
  2721. ImGuiWindow* window = GetCurrentWindow();
  2722. window->DC.CursorPos.y = window->Pos.y + y;
  2723. }
  2724. ImVec2 ImGui::GetCursorScreenPos()
  2725. {
  2726. ImGuiWindow* window = GetCurrentWindow();
  2727. return window->DC.CursorPos;
  2728. }
  2729. void ImGui::SetScrollPosHere()
  2730. {
  2731. ImGuiWindow* window = GetCurrentWindow();
  2732. window->NextScrollY = (window->DC.CursorPos.y + window->ScrollY) - (window->Pos.y + window->SizeFull.y * 0.5f) - (window->TitleBarHeight() + window->WindowPadding().y);
  2733. }
  2734. void ImGui::SetKeyboardFocusHere(int offset)
  2735. {
  2736. ImGuiWindow* window = GetCurrentWindow();
  2737. window->FocusIdxAllRequestNext = window->FocusIdxAllCounter + 1 + offset;
  2738. window->FocusIdxTabRequestNext = IM_INT_MAX;
  2739. }
  2740. void ImGui::SetStateStorage(ImGuiStorage* tree)
  2741. {
  2742. ImGuiWindow* window = GetCurrentWindow();
  2743. window->DC.StateStorage = tree ? tree : &window->StateStorage;
  2744. }
  2745. ImGuiStorage* ImGui::GetStateStorage()
  2746. {
  2747. ImGuiWindow* window = GetCurrentWindow();
  2748. return window->DC.StateStorage;
  2749. }
  2750. void ImGui::TextV(const char* fmt, va_list args)
  2751. {
  2752. ImGuiWindow* window = GetCurrentWindow();
  2753. if (window->SkipItems)
  2754. return;
  2755. static char buf[1024];
  2756. const char* text_end = buf + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  2757. TextUnformatted(buf, text_end);
  2758. }
  2759. void ImGui::Text(const char* fmt, ...)
  2760. {
  2761. va_list args;
  2762. va_start(args, fmt);
  2763. TextV(fmt, args);
  2764. va_end(args);
  2765. }
  2766. void ImGui::TextColoredV(const ImVec4& col, const char* fmt, va_list args)
  2767. {
  2768. ImGui::PushStyleColor(ImGuiCol_Text, col);
  2769. TextV(fmt, args);
  2770. ImGui::PopStyleColor();
  2771. }
  2772. void ImGui::TextColored(const ImVec4& col, const char* fmt, ...)
  2773. {
  2774. va_list args;
  2775. va_start(args, fmt);
  2776. TextColoredV(col, fmt, args);
  2777. va_end(args);
  2778. }
  2779. void ImGui::TextWrappedV(const char* fmt, va_list args)
  2780. {
  2781. ImGui::PushTextWrapPos(0.0f);
  2782. TextV(fmt, args);
  2783. ImGui::PopTextWrapPos();
  2784. }
  2785. void ImGui::TextWrapped(const char* fmt, ...)
  2786. {
  2787. va_list args;
  2788. va_start(args, fmt);
  2789. TextWrappedV(fmt, args);
  2790. va_end(args);
  2791. }
  2792. void ImGui::TextUnformatted(const char* text, const char* text_end)
  2793. {
  2794. ImGuiState& g = GImGui;
  2795. ImGuiWindow* window = GetCurrentWindow();
  2796. if (window->SkipItems)
  2797. return;
  2798. IM_ASSERT(text != NULL);
  2799. const char* text_begin = text;
  2800. if (text_end == NULL)
  2801. text_end = text + strlen(text); // FIXME-OPT
  2802. const float wrap_pos_x = window->DC.TextWrapPos.back();
  2803. const bool wrap_enabled = wrap_pos_x >= 0.0f;
  2804. if (text_end - text > 2000 && !wrap_enabled)
  2805. {
  2806. // Long text!
  2807. // Perform manual coarse clipping to optimize for long multi-line text
  2808. // From this point we will only compute the width of lines that are visible.
  2809. // Optimization only available when word-wrapping is disabled.
  2810. const char* line = text;
  2811. const float line_height = ImGui::GetTextLineHeight();
  2812. const ImVec2 start_pos = window->DC.CursorPos;
  2813. const ImVec4 clip_rect = window->ClipRectStack.back();
  2814. ImVec2 text_size(0,0);
  2815. if (start_pos.y <= clip_rect.w)
  2816. {
  2817. ImVec2 pos = start_pos;
  2818. // Lines to skip (can't skip when logging text)
  2819. if (!g.LogEnabled)
  2820. {
  2821. int lines_skippable = (int)((clip_rect.y - start_pos.y) / line_height) - 1;
  2822. if (lines_skippable > 0)
  2823. {
  2824. int lines_skipped = 0;
  2825. while (line < text_end && lines_skipped <= lines_skippable)
  2826. {
  2827. const char* line_end = strchr(line, '\n');
  2828. line = line_end + 1;
  2829. lines_skipped++;
  2830. }
  2831. pos.y += lines_skipped * line_height;
  2832. }
  2833. }
  2834. // Lines to render
  2835. if (line < text_end)
  2836. {
  2837. ImGuiAabb line_box(pos, pos + ImVec2(ImGui::GetWindowWidth(), line_height));
  2838. while (line < text_end)
  2839. {
  2840. const char* line_end = strchr(line, '\n');
  2841. if (IsClipped(line_box))
  2842. break;
  2843. const ImVec2 line_size = CalcTextSize(line, line_end, false);
  2844. text_size.x = ImMax(text_size.x, line_size.x);
  2845. RenderText(pos, line, line_end, false);
  2846. if (!line_end)
  2847. line_end = text_end;
  2848. line = line_end + 1;
  2849. line_box.Min.y += line_height;
  2850. line_box.Max.y += line_height;
  2851. pos.y += line_height;
  2852. }
  2853. // Count remaining lines
  2854. int lines_skipped = 0;
  2855. while (line < text_end)
  2856. {
  2857. const char* line_end = strchr(line, '\n');
  2858. if (!line_end)
  2859. line_end = text_end;
  2860. line = line_end + 1;
  2861. lines_skipped++;
  2862. }
  2863. pos.y += lines_skipped * line_height;
  2864. }
  2865. text_size.y += (pos - start_pos).y;
  2866. }
  2867. const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size);
  2868. ItemSize(bb);
  2869. ClipAdvance(bb);
  2870. }
  2871. else
  2872. {
  2873. const float wrap_width = wrap_enabled ? CalcWrapWidthForPos(window->DC.CursorPos, wrap_pos_x) : 0.0f;
  2874. const ImVec2 text_size = CalcTextSize(text_begin, text_end, false, wrap_width);
  2875. ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size);
  2876. ItemSize(bb.GetSize(), &bb.Min);
  2877. if (ClipAdvance(bb))
  2878. return;
  2879. // Render
  2880. // We don't hide text after ## in this end-user function.
  2881. RenderText(bb.Min, text_begin, text_end, false, wrap_width);
  2882. }
  2883. }
  2884. void ImGui::AlignFirstTextHeightToWidgets()
  2885. {
  2886. ImGuiState& g = GImGui;
  2887. ImGuiWindow* window = GetCurrentWindow();
  2888. if (window->SkipItems)
  2889. return;
  2890. // Declare a dummy item size to that upcoming items that are smaller will center-align on the newly expanded line height.
  2891. ItemSize(ImVec2(0, window->FontSize() + g.Style.FramePadding.y*2));
  2892. ImGui::SameLine(0, 0);
  2893. }
  2894. // Add a label+text combo aligned to other label+value widgets
  2895. void ImGui::LabelTextV(const char* label, const char* fmt, va_list args)
  2896. {
  2897. ImGuiState& g = GImGui;
  2898. ImGuiWindow* window = GetCurrentWindow();
  2899. if (window->SkipItems)
  2900. return;
  2901. const ImGuiStyle& style = g.Style;
  2902. const float w = window->DC.ItemWidth.back();
  2903. static char buf[1024];
  2904. const char* text_begin = &buf[0];
  2905. const char* text_end = text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  2906. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  2907. const ImGuiAabb value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, text_size.y));
  2908. 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);
  2909. ItemSize(bb);
  2910. if (ClipAdvance(value_bb))
  2911. return;
  2912. // Render
  2913. RenderText(value_bb.Min, text_begin, text_end);
  2914. RenderText(ImVec2(value_bb.Max.x + style.ItemInnerSpacing.x, value_bb.Min.y), label);
  2915. }
  2916. void ImGui::LabelText(const char* label, const char* fmt, ...)
  2917. {
  2918. va_list args;
  2919. va_start(args, fmt);
  2920. LabelTextV(label, fmt, args);
  2921. va_end(args);
  2922. }
  2923. static bool IsHovered(const ImGuiAabb& bb, const ImGuiID& id)
  2924. {
  2925. ImGuiState& g = GImGui;
  2926. if (g.HoveredId == 0)
  2927. {
  2928. ImGuiWindow* window = GetCurrentWindow();
  2929. const bool hovered = (g.HoveredRootWindow == window->RootWindow) && (g.ActiveId == 0 || g.ActiveId == id) && IsMouseHoveringBox(bb);
  2930. return hovered;
  2931. }
  2932. return false;
  2933. }
  2934. static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat)
  2935. {
  2936. ImGuiState& g = GImGui;
  2937. ImGuiWindow* window = GetCurrentWindow();
  2938. const bool hovered = IsHovered(bb, id);
  2939. bool pressed = false;
  2940. if (hovered)
  2941. {
  2942. g.HoveredId = id;
  2943. if (allow_key_modifiers || (!g.IO.KeyCtrl && !g.IO.KeyShift))
  2944. {
  2945. if (g.IO.MouseClicked[0])
  2946. {
  2947. g.ActiveId = id;
  2948. FocusWindow(window);
  2949. }
  2950. else if (repeat && g.ActiveId && ImGui::IsMouseClicked(0, true))
  2951. {
  2952. pressed = true;
  2953. }
  2954. }
  2955. }
  2956. bool held = false;
  2957. if (g.ActiveId == id)
  2958. {
  2959. if (g.IO.MouseDown[0])
  2960. {
  2961. held = true;
  2962. }
  2963. else
  2964. {
  2965. if (hovered)
  2966. pressed = true;
  2967. g.ActiveId = 0;
  2968. }
  2969. }
  2970. if (out_hovered) *out_hovered = hovered;
  2971. if (out_held) *out_held = held;
  2972. return pressed;
  2973. }
  2974. bool ImGui::Button(const char* label, ImVec2 size, bool repeat_when_held)
  2975. {
  2976. ImGuiState& g = GImGui;
  2977. ImGuiWindow* window = GetCurrentWindow();
  2978. if (window->SkipItems)
  2979. return false;
  2980. const ImGuiStyle& style = g.Style;
  2981. const ImGuiID id = window->GetID(label);
  2982. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  2983. if (size.x == 0.0f)
  2984. size.x = text_size.x;
  2985. if (size.y == 0.0f)
  2986. size.y = text_size.y;
  2987. const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size + style.FramePadding*2.0f);
  2988. ItemSize(bb);
  2989. if (ClipAdvance(bb))
  2990. return false;
  2991. bool hovered, held;
  2992. bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true, repeat_when_held);
  2993. // Render
  2994. const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
  2995. RenderFrame(bb.Min, bb.Max, col);
  2996. if (size.x < text_size.x || size.y < text_size.y)
  2997. PushClipRect(ImVec4(bb.Min.x+style.FramePadding.x, bb.Min.y+style.FramePadding.y, bb.Max.x, bb.Max.y-style.FramePadding.y)); // Allow extra to draw over the horizontal padding to make it visible that text doesn't fit
  2998. const ImVec2 off = ImVec2(ImMax(0.0f, size.x - text_size.x) * 0.5f, ImMax(0.0f, size.y - text_size.y) * 0.5f);
  2999. RenderText(bb.Min + style.FramePadding + off, label);
  3000. if (size.x < text_size.x || size.y < text_size.y)
  3001. PopClipRect();
  3002. return pressed;
  3003. }
  3004. // Small buttons fits within text without additional spacing.
  3005. bool ImGui::SmallButton(const char* label)
  3006. {
  3007. ImGuiState& g = GImGui;
  3008. ImGuiWindow* window = GetCurrentWindow();
  3009. if (window->SkipItems)
  3010. return false;
  3011. const ImGuiStyle& style = g.Style;
  3012. const ImGuiID id = window->GetID(label);
  3013. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  3014. const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size + ImVec2(style.FramePadding.x*2,0));
  3015. ItemSize(bb);
  3016. if (ClipAdvance(bb))
  3017. return false;
  3018. bool hovered, held;
  3019. bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true);
  3020. // Render
  3021. const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
  3022. RenderFrame(bb.Min, bb.Max, col);
  3023. RenderText(bb.Min + ImVec2(style.FramePadding.x,0), label);
  3024. return pressed;
  3025. }
  3026. // Upper-right button to close a window.
  3027. static bool CloseWindowButton(bool* p_opened)
  3028. {
  3029. ImGuiWindow* window = GetCurrentWindow();
  3030. const ImGuiID id = window->GetID("##CLOSE");
  3031. const float size = window->TitleBarHeight() - 4.0f;
  3032. const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-3.0f-size,2.0f), window->Aabb().GetTR() + ImVec2(-3.0f,2.0f+size));
  3033. bool hovered, held;
  3034. bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true);
  3035. // Render
  3036. const ImU32 col = window->Color((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton);
  3037. const ImVec2 center = bb.GetCenter();
  3038. window->DrawList->AddCircleFilled(center, ImMax(2.0f,size*0.5f), col, 16);
  3039. const float cross_extent = (size * 0.5f * 0.7071f) - 1.0f;
  3040. if (hovered)
  3041. {
  3042. window->DrawList->AddLine(center + ImVec2(+cross_extent,+cross_extent), center + ImVec2(-cross_extent,-cross_extent), window->Color(ImGuiCol_Text));
  3043. window->DrawList->AddLine(center + ImVec2(+cross_extent,-cross_extent), center + ImVec2(-cross_extent,+cross_extent), window->Color(ImGuiCol_Text));
  3044. }
  3045. if (p_opened != NULL && pressed)
  3046. *p_opened = !*p_opened;
  3047. return pressed;
  3048. }
  3049. // Start logging ImGui output to TTY
  3050. void ImGui::LogToTTY(int max_depth)
  3051. {
  3052. ImGuiState& g = GImGui;
  3053. ImGuiWindow* window = GetCurrentWindow();
  3054. if (g.LogEnabled)
  3055. return;
  3056. g.LogEnabled = true;
  3057. g.LogFile = stdout;
  3058. g.LogStartDepth = window->DC.TreeDepth;
  3059. if (max_depth >= 0)
  3060. g.LogAutoExpandMaxDepth = max_depth;
  3061. }
  3062. // Start logging ImGui output to given file
  3063. void ImGui::LogToFile(int max_depth, const char* filename)
  3064. {
  3065. ImGuiState& g = GImGui;
  3066. ImGuiWindow* window = GetCurrentWindow();
  3067. if (g.LogEnabled)
  3068. return;
  3069. if (!filename)
  3070. filename = g.IO.LogFilename;
  3071. g.LogFile = fopen(filename, "ab");
  3072. if (!g.LogFile)
  3073. {
  3074. IM_ASSERT(g.LogFile != NULL); // Consider this an error
  3075. return;
  3076. }
  3077. g.LogEnabled = true;
  3078. g.LogStartDepth = window->DC.TreeDepth;
  3079. if (max_depth >= 0)
  3080. g.LogAutoExpandMaxDepth = max_depth;
  3081. }
  3082. // Start logging ImGui output to clipboard
  3083. void ImGui::LogToClipboard(int max_depth)
  3084. {
  3085. ImGuiWindow* window = GetCurrentWindow();
  3086. ImGuiState& g = GImGui;
  3087. if (g.LogEnabled)
  3088. return;
  3089. g.LogEnabled = true;
  3090. g.LogFile = NULL;
  3091. g.LogStartDepth = window->DC.TreeDepth;
  3092. if (max_depth >= 0)
  3093. g.LogAutoExpandMaxDepth = max_depth;
  3094. }
  3095. void ImGui::LogFinish()
  3096. {
  3097. ImGuiState& g = GImGui;
  3098. if (!g.LogEnabled)
  3099. return;
  3100. ImGui::LogText(STR_NEWLINE);
  3101. g.LogEnabled = false;
  3102. if (g.LogFile != NULL)
  3103. {
  3104. if (g.LogFile == stdout)
  3105. fflush(g.LogFile);
  3106. else
  3107. fclose(g.LogFile);
  3108. g.LogFile = NULL;
  3109. }
  3110. if (g.LogClipboard->size() > 1)
  3111. {
  3112. if (g.IO.SetClipboardTextFn)
  3113. g.IO.SetClipboardTextFn(g.LogClipboard->begin());
  3114. g.LogClipboard->clear();
  3115. }
  3116. }
  3117. // Helper to display logging buttons
  3118. void ImGui::LogButtons()
  3119. {
  3120. ImGuiState& g = GImGui;
  3121. ImGui::PushID("LogButtons");
  3122. const bool log_to_tty = ImGui::Button("Log To TTY");
  3123. ImGui::SameLine();
  3124. const bool log_to_file = ImGui::Button("Log To File");
  3125. ImGui::SameLine();
  3126. const bool log_to_clipboard = ImGui::Button("Log To Clipboard");
  3127. ImGui::SameLine();
  3128. ImGui::PushItemWidth(80.0f);
  3129. ImGui::PushAllowKeyboardFocus(false);
  3130. ImGui::SliderInt("Depth", &g.LogAutoExpandMaxDepth, 0, 9, NULL);
  3131. ImGui::PopAllowKeyboardFocus();
  3132. ImGui::PopItemWidth();
  3133. ImGui::PopID();
  3134. // Start logging at the end of the function so that the buttons don't appear in the log
  3135. if (log_to_tty)
  3136. LogToTTY(g.LogAutoExpandMaxDepth);
  3137. if (log_to_file)
  3138. LogToFile(g.LogAutoExpandMaxDepth, g.IO.LogFilename);
  3139. if (log_to_clipboard)
  3140. LogToClipboard(g.LogAutoExpandMaxDepth);
  3141. }
  3142. bool ImGui::CollapsingHeader(const char* label, const char* str_id, const bool display_frame, const bool default_open)
  3143. {
  3144. ImGuiState& g = GImGui;
  3145. ImGuiWindow* window = GetCurrentWindow();
  3146. if (window->SkipItems)
  3147. return false;
  3148. const ImGuiStyle& style = g.Style;
  3149. IM_ASSERT(str_id != NULL || label != NULL);
  3150. if (str_id == NULL)
  3151. str_id = label;
  3152. if (label == NULL)
  3153. label = str_id;
  3154. const ImGuiID id = window->GetID(str_id);
  3155. // We only write to the tree storage if the user clicks
  3156. ImGuiStorage* storage = window->DC.StateStorage;
  3157. bool opened;
  3158. if (window->DC.OpenNextNode != -1)
  3159. {
  3160. opened = window->DC.OpenNextNode > 0;
  3161. storage->SetInt(id, opened);
  3162. window->DC.OpenNextNode = -1;
  3163. }
  3164. else
  3165. {
  3166. opened = storage->GetInt(id, default_open) != 0;
  3167. }
  3168. // Framed header expand a little outside the default padding
  3169. const ImVec2 window_padding = window->WindowPadding();
  3170. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  3171. const ImVec2 pos_min = window->DC.CursorPos;
  3172. const ImVec2 pos_max = window->Pos + GetContentRegionMax();
  3173. ImGuiAabb bb = ImGuiAabb(pos_min, ImVec2(pos_max.x, pos_min.y + text_size.y));
  3174. if (display_frame)
  3175. {
  3176. bb.Min.x -= window_padding.x*0.5f - 1;
  3177. bb.Max.x += window_padding.x*0.5f - 1;
  3178. bb.Max.y += style.FramePadding.y * 2;
  3179. }
  3180. const ImGuiAabb text_bb(bb.Min, bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2*2,0) + text_size);
  3181. 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
  3182. // When logging is enabled, if automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behaviour).
  3183. // NB- If we are above max depth we still allow manually opened nodes to be logged.
  3184. if (!display_frame)
  3185. if (g.LogEnabled && window->DC.TreeDepth < g.LogAutoExpandMaxDepth)
  3186. opened = true;
  3187. if (ClipAdvance(bb))
  3188. return opened;
  3189. bool hovered, held;
  3190. bool pressed = ButtonBehaviour(display_frame ? bb : text_bb, id, &hovered, &held, false);
  3191. if (pressed)
  3192. {
  3193. opened = !opened;
  3194. storage->SetInt(id, opened);
  3195. }
  3196. // Render
  3197. const ImU32 col = window->Color((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
  3198. if (display_frame)
  3199. {
  3200. // Framed type
  3201. RenderFrame(bb.Min, bb.Max, col, true);
  3202. RenderCollapseTriangle(bb.Min + style.FramePadding, opened, 1.0f, true);
  3203. if (g.LogEnabled)
  3204. {
  3205. // NB: '##' is normally used to hide text (as a library-wide feature), so we need to specify the text range to make sure the ## aren't stripped out here.
  3206. const char log_prefix[] = "\n##";
  3207. LogText(bb.Min + style.FramePadding, log_prefix, log_prefix+3);
  3208. }
  3209. RenderText(bb.Min + style.FramePadding + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label);
  3210. if (g.LogEnabled)
  3211. {
  3212. const char log_suffix[] = "##";
  3213. LogText(bb.Min + style.FramePadding, log_suffix, log_suffix+2);
  3214. }
  3215. }
  3216. else
  3217. {
  3218. // Unframed typed for tree nodes
  3219. if ((held && hovered) || hovered)
  3220. RenderFrame(bb.Min, bb.Max, col, false);
  3221. RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, window->FontSize()*0.15f), opened, 0.70f, false);
  3222. if (g.LogEnabled)
  3223. LogText(bb.Min, ">");
  3224. RenderText(bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label);
  3225. }
  3226. return opened;
  3227. }
  3228. // Text with a little bullet aligned to the typical tree node.
  3229. void ImGui::BulletTextV(const char* fmt, va_list args)
  3230. {
  3231. ImGuiState& g = GImGui;
  3232. ImGuiWindow* window = GetCurrentWindow();
  3233. if (window->SkipItems)
  3234. return;
  3235. const ImGuiStyle& style = g.Style;
  3236. static char buf[1024];
  3237. const char* text_begin = buf;
  3238. const char* text_end = text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  3239. const float line_height = window->FontSize();
  3240. const ImVec2 text_size = CalcTextSize(text_begin, text_end, true);
  3241. 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
  3242. ItemSize(bb);
  3243. if (ClipAdvance(bb))
  3244. return;
  3245. // Render
  3246. const float bullet_size = line_height*0.15f;
  3247. window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text));
  3248. RenderText(bb.Min+ImVec2(window->FontSize() + style.FramePadding.x*2,0), text_begin, text_end);
  3249. }
  3250. void ImGui::BulletText(const char* fmt, ...)
  3251. {
  3252. va_list args;
  3253. va_start(args, fmt);
  3254. BulletTextV(fmt, args);
  3255. va_end(args);
  3256. }
  3257. // If returning 'true' the node is open and the user is responsible for calling TreePop
  3258. bool ImGui::TreeNodeV(const char* str_id, const char* fmt, va_list args)
  3259. {
  3260. static char buf[1024];
  3261. ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  3262. if (!str_id || !str_id[0])
  3263. str_id = fmt;
  3264. ImGui::PushID(str_id);
  3265. const bool opened = ImGui::CollapsingHeader(buf, "", false); // do not add to the ID so that TreeNodeSetOpen can access
  3266. ImGui::PopID();
  3267. if (opened)
  3268. ImGui::TreePush(str_id);
  3269. return opened;
  3270. }
  3271. bool ImGui::TreeNode(const char* str_id, const char* fmt, ...)
  3272. {
  3273. va_list args;
  3274. va_start(args, fmt);
  3275. bool s = TreeNodeV(str_id, fmt, args);
  3276. va_end(args);
  3277. return s;
  3278. }
  3279. // If returning 'true' the node is open and the user is responsible for calling TreePop
  3280. bool ImGui::TreeNodeV(const void* ptr_id, const char* fmt, va_list args)
  3281. {
  3282. static char buf[1024];
  3283. ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  3284. if (!ptr_id)
  3285. ptr_id = fmt;
  3286. ImGui::PushID(ptr_id);
  3287. const bool opened = ImGui::CollapsingHeader(buf, "", false);
  3288. ImGui::PopID();
  3289. if (opened)
  3290. ImGui::TreePush(ptr_id);
  3291. return opened;
  3292. }
  3293. bool ImGui::TreeNode(const void* ptr_id, const char* fmt, ...)
  3294. {
  3295. va_list args;
  3296. va_start(args, fmt);
  3297. bool s = TreeNodeV(ptr_id, fmt, args);
  3298. va_end(args);
  3299. return s;
  3300. }
  3301. bool ImGui::TreeNode(const char* str_label_id)
  3302. {
  3303. return TreeNode(str_label_id, "%s", str_label_id);
  3304. }
  3305. void ImGui::OpenNextNode(bool open)
  3306. {
  3307. ImGuiWindow* window = GetCurrentWindow();
  3308. window->DC.OpenNextNode = open ? 1 : 0;
  3309. }
  3310. void ImGui::PushID(const char* str_id)
  3311. {
  3312. ImGuiWindow* window = GetCurrentWindow();
  3313. window->IDStack.push_back(window->GetID(str_id));
  3314. }
  3315. void ImGui::PushID(const void* ptr_id)
  3316. {
  3317. ImGuiWindow* window = GetCurrentWindow();
  3318. window->IDStack.push_back(window->GetID(ptr_id));
  3319. }
  3320. void ImGui::PushID(const int int_id)
  3321. {
  3322. const void* ptr_id = (void*)(intptr_t)int_id;
  3323. ImGuiWindow* window = GetCurrentWindow();
  3324. window->IDStack.push_back(window->GetID(ptr_id));
  3325. }
  3326. void ImGui::PopID()
  3327. {
  3328. ImGuiWindow* window = GetCurrentWindow();
  3329. window->IDStack.pop_back();
  3330. }
  3331. ImGuiID ImGui::GetID(const char* str_id)
  3332. {
  3333. ImGuiWindow* window = GetCurrentWindow();
  3334. return window->GetID(str_id);
  3335. }
  3336. ImGuiID ImGui::GetID(const void* ptr_id)
  3337. {
  3338. ImGuiWindow* window = GetCurrentWindow();
  3339. return window->GetID(ptr_id);
  3340. }
  3341. // User can input math operators (e.g. +100) to edit a numerical values.
  3342. // NB: only call right after InputText because we are using its InitialValue storage
  3343. static void ApplyNumericalTextInput(const char* buf, float *v)
  3344. {
  3345. while (*buf == ' ' || *buf == '\t')
  3346. buf++;
  3347. // We don't support '-' op because it would conflict with inputing negative value.
  3348. // Instead you can use +-100 to subtract from an existing value
  3349. char op = buf[0];
  3350. if (op == '+' || op == '*' || op == '/')
  3351. {
  3352. buf++;
  3353. while (*buf == ' ' || *buf == '\t')
  3354. buf++;
  3355. }
  3356. else
  3357. {
  3358. op = 0;
  3359. }
  3360. if (!buf[0])
  3361. return;
  3362. float ref_v = *v;
  3363. if (op)
  3364. if (sscanf(GImGui.InputTextState.InitialText, "%f", &ref_v) < 1)
  3365. return;
  3366. float op_v = 0.0f;
  3367. if (sscanf(buf, "%f", &op_v) < 1)
  3368. return;
  3369. if (op == '+')
  3370. *v = ref_v + op_v;
  3371. else if (op == '*')
  3372. *v = ref_v * op_v;
  3373. else if (op == '/')
  3374. {
  3375. if (op_v == 0.0f)
  3376. return;
  3377. *v = ref_v / op_v;
  3378. }
  3379. else
  3380. *v = op_v;
  3381. }
  3382. // Use power!=1.0 for logarithmic sliders.
  3383. // Adjust display_format to decorate the value with a prefix or a suffix.
  3384. bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format, float power)
  3385. {
  3386. ImGuiState& g = GImGui;
  3387. ImGuiWindow* window = GetCurrentWindow();
  3388. if (window->SkipItems)
  3389. return false;
  3390. const ImGuiStyle& style = g.Style;
  3391. const ImGuiID id = window->GetID(label);
  3392. const float w = window->DC.ItemWidth.back();
  3393. if (!display_format)
  3394. display_format = "%.3f";
  3395. // Parse display precision back from the display format string
  3396. int decimal_precision = 3;
  3397. if (const char* p = strchr(display_format, '%'))
  3398. {
  3399. p++;
  3400. while (*p >= '0' && *p <= '9')
  3401. p++;
  3402. if (*p == '.')
  3403. {
  3404. decimal_precision = atoi(p+1);
  3405. if (decimal_precision < 0 || decimal_precision > 10)
  3406. decimal_precision = 3;
  3407. }
  3408. }
  3409. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  3410. const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f);
  3411. const ImGuiAabb slider_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
  3412. 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));
  3413. if (IsClipped(slider_bb))
  3414. {
  3415. // NB- we don't use ClipAdvance() in the if() statement because we don't want to submit ItemSize() because we may change into a text edit later which may submit an ItemSize itself
  3416. ItemSize(bb);
  3417. return false;
  3418. }
  3419. const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id);
  3420. const bool is_unbound = v_min == -FLT_MAX || v_min == FLT_MAX || v_max == -FLT_MAX || v_max == FLT_MAX;
  3421. const float grab_size_in_units = 1.0f; // In 'v' units. Probably needs to be parametrized, based on a 'v_step' value? decimal precision?
  3422. float grab_size_in_pixels;
  3423. if (decimal_precision > 0 || is_unbound)
  3424. grab_size_in_pixels = 10.0f;
  3425. else
  3426. grab_size_in_pixels = ImMax(grab_size_in_units * (w / (v_max-v_min+1.0f)), 8.0f); // Integer sliders
  3427. const float slider_effective_w = slider_bb.GetWidth() - grab_size_in_pixels;
  3428. const float slider_effective_x1 = slider_bb.Min.x + grab_size_in_pixels*0.5f;
  3429. const float slider_effective_x2 = slider_bb.Max.x - grab_size_in_pixels*0.5f;
  3430. // For logarithmic sliders that cross over sign boundary we want the exponential increase to be symmetric around 0.0f
  3431. float linear_zero_pos = 0.0f; // 0.0->1.0f
  3432. if (!is_unbound)
  3433. {
  3434. if (v_min * v_max < 0.0f)
  3435. {
  3436. // Different sign
  3437. const float linear_dist_min_to_0 = powf(fabsf(0.0f - v_min), 1.0f/power);
  3438. const float linear_dist_max_to_0 = powf(fabsf(v_max - 0.0f), 1.0f/power);
  3439. linear_zero_pos = linear_dist_min_to_0 / (linear_dist_min_to_0+linear_dist_max_to_0);
  3440. }
  3441. else
  3442. {
  3443. // Same sign
  3444. linear_zero_pos = v_min < 0.0f ? 1.0f : 0.0f;
  3445. }
  3446. }
  3447. const bool hovered = IsHovered(slider_bb, id);
  3448. if (hovered)
  3449. g.HoveredId = id;
  3450. bool start_text_input = false;
  3451. if (tab_focus_requested || (hovered && g.IO.MouseClicked[0]))
  3452. {
  3453. g.ActiveId = id;
  3454. FocusWindow(window);
  3455. const bool is_ctrl_down = g.IO.KeyCtrl;
  3456. if (tab_focus_requested || is_ctrl_down || is_unbound)
  3457. {
  3458. start_text_input = true;
  3459. g.SliderAsInputTextId = 0;
  3460. }
  3461. }
  3462. // Tabbing or CTRL-clicking through slider turns into an input box
  3463. bool value_changed = false;
  3464. if (start_text_input || (g.ActiveId == id && id == g.SliderAsInputTextId))
  3465. {
  3466. char text_buf[64];
  3467. ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%.*f", decimal_precision, *v);
  3468. g.ActiveId = g.SliderAsInputTextId;
  3469. g.HoveredId = 0;
  3470. window->FocusItemUnregister(); // Our replacement slider will override the focus ID (registered previously to allow for a TAB focus to happen)
  3471. value_changed = ImGui::InputText(label, text_buf, IM_ARRAYSIZE(text_buf), ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll);
  3472. if (g.SliderAsInputTextId == 0)
  3473. {
  3474. // First frame
  3475. IM_ASSERT(g.ActiveId == id); // InputText ID should match the Slider ID (else we'd need to store them both which is also possible)
  3476. g.SliderAsInputTextId = g.ActiveId;
  3477. g.ActiveId = id;
  3478. g.HoveredId = id;
  3479. }
  3480. else
  3481. {
  3482. if (g.ActiveId == g.SliderAsInputTextId)
  3483. g.ActiveId = id;
  3484. else
  3485. g.ActiveId = g.SliderAsInputTextId = 0;
  3486. }
  3487. if (value_changed)
  3488. {
  3489. ApplyNumericalTextInput(text_buf, v);
  3490. }
  3491. return value_changed;
  3492. }
  3493. ItemSize(bb);
  3494. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg));
  3495. // Process clicking on the slider
  3496. if (g.ActiveId == id)
  3497. {
  3498. if (g.IO.MouseDown[0])
  3499. {
  3500. if (!is_unbound)
  3501. {
  3502. const float normalized_pos = ImClamp((g.IO.MousePos.x - slider_effective_x1) / slider_effective_w, 0.0f, 1.0f);
  3503. // Linear slider
  3504. //float new_value = ImLerp(v_min, v_max, normalized_pos);
  3505. // Account for logarithmic scale on both sides of the zero
  3506. float new_value;
  3507. if (normalized_pos < linear_zero_pos)
  3508. {
  3509. // Negative: rescale to the negative range before powering
  3510. float a = 1.0f - (normalized_pos / linear_zero_pos);
  3511. a = powf(a, power);
  3512. new_value = ImLerp(ImMin(v_max,0.f), v_min, a);
  3513. }
  3514. else
  3515. {
  3516. // Positive: rescale to the positive range before powering
  3517. float a;
  3518. if (fabsf(linear_zero_pos - 1.0f) > 1.e-6)
  3519. a = (normalized_pos - linear_zero_pos) / (1.0f - linear_zero_pos);
  3520. else
  3521. a = normalized_pos;
  3522. a = powf(a, power);
  3523. new_value = ImLerp(ImMax(v_min,0.0f), v_max, a);
  3524. }
  3525. // Round past decimal precision
  3526. // 0->1, 1->0.1, 2->0.01, etc.
  3527. // So when our value is 1.99999 with a precision of 0.001 we'll end up rounding to 2.0
  3528. const float min_step = 1.0f / powf(10.0f, (float)decimal_precision);
  3529. const float remainder = fmodf(new_value, min_step);
  3530. if (remainder <= min_step*0.5f)
  3531. new_value -= remainder;
  3532. else
  3533. new_value += (min_step - remainder);
  3534. if (*v != new_value)
  3535. {
  3536. *v = new_value;
  3537. value_changed = true;
  3538. }
  3539. }
  3540. }
  3541. else
  3542. {
  3543. g.ActiveId = 0;
  3544. }
  3545. }
  3546. if (!is_unbound)
  3547. {
  3548. // Linear slider
  3549. // const float grab_t = (ImClamp(*v, v_min, v_max) - v_min) / (v_max - v_min);
  3550. // Calculate slider grab positioning
  3551. float grab_t;
  3552. float v_clamped = ImClamp(*v, v_min, v_max);
  3553. if (v_clamped < 0.0f)
  3554. {
  3555. const float f = 1.0f - (v_clamped - v_min) / (ImMin(0.0f,v_max) - v_min);
  3556. grab_t = (1.0f - powf(f, 1.0f/power)) * linear_zero_pos;
  3557. }
  3558. else
  3559. {
  3560. const float f = (v_clamped - ImMax(0.0f,v_min)) / (v_max - ImMax(0.0f,v_min));
  3561. grab_t = linear_zero_pos + powf(f, 1.0f/power) * (1.0f - linear_zero_pos);
  3562. }
  3563. // Draw
  3564. const float grab_x = ImLerp(slider_effective_x1, slider_effective_x2, grab_t);
  3565. const ImGuiAabb grab_bb(ImVec2(grab_x-grab_size_in_pixels*0.5f,frame_bb.Min.y+2.0f), ImVec2(grab_x+grab_size_in_pixels*0.5f,frame_bb.Max.y-2.0f));
  3566. window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, window->Color(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab));
  3567. }
  3568. // Draw value using user-provided display format so user can add prefix/suffix/decorations to the value.
  3569. char value_buf[64];
  3570. ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
  3571. RenderText(ImVec2(slider_bb.GetCenter().x-CalcTextSize(value_buf, NULL, true).x*0.5f, frame_bb.Min.y + style.FramePadding.y), value_buf);
  3572. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, slider_bb.Min.y), label);
  3573. return value_changed;
  3574. }
  3575. bool ImGui::SliderAngle(const char* label, float* v, float v_degrees_min, float v_degrees_max)
  3576. {
  3577. float v_deg = *v * 360.0f / (2*PI);
  3578. bool value_changed = ImGui::SliderFloat(label, &v_deg, v_degrees_min, v_degrees_max, "%.0f deg", 1.0f);
  3579. *v = v_deg * (2*PI) / 360.0f;
  3580. return value_changed;
  3581. }
  3582. bool ImGui::SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format)
  3583. {
  3584. if (!display_format)
  3585. display_format = "%.0f";
  3586. float v_f = (float)*v;
  3587. bool value_changed = ImGui::SliderFloat(label, &v_f, (float)v_min, (float)v_max, display_format, 1.0f);
  3588. *v = (int)v_f;
  3589. return value_changed;
  3590. }
  3591. // Add multiple sliders on 1 line for compact edition of multiple components
  3592. static bool SliderFloatN(const char* label, float v[3], int components, float v_min, float v_max, const char* display_format, float power)
  3593. {
  3594. ImGuiState& g = GImGui;
  3595. ImGuiWindow* window = GetCurrentWindow();
  3596. if (window->SkipItems)
  3597. return false;
  3598. const ImGuiStyle& style = g.Style;
  3599. const float w_full = window->DC.ItemWidth.back();
  3600. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)) / (float)components));
  3601. const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)));
  3602. bool value_changed = false;
  3603. ImGui::PushID(label);
  3604. ImGui::PushItemWidth(w_item_one);
  3605. for (int i = 0; i < components; i++)
  3606. {
  3607. ImGui::PushID(i);
  3608. if (i + 1 == components)
  3609. {
  3610. ImGui::PopItemWidth();
  3611. ImGui::PushItemWidth(w_item_last);
  3612. }
  3613. value_changed |= ImGui::SliderFloat("##v", &v[i], v_min, v_max, display_format, power);
  3614. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  3615. ImGui::PopID();
  3616. }
  3617. ImGui::PopItemWidth();
  3618. ImGui::PopID();
  3619. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  3620. return value_changed;
  3621. }
  3622. bool ImGui::SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format, float power)
  3623. {
  3624. return SliderFloatN(label, v, 2, v_min, v_max, display_format, power);
  3625. }
  3626. bool ImGui::SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format, float power)
  3627. {
  3628. return SliderFloatN(label, v, 3, v_min, v_max, display_format, power);
  3629. }
  3630. bool ImGui::SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format, float power)
  3631. {
  3632. return SliderFloatN(label, v, 4, v_min, v_max, display_format, power);
  3633. }
  3634. static bool SliderIntN(const char* label, int v[3], int components, int v_min, int v_max, const char* display_format)
  3635. {
  3636. ImGuiState& g = GImGui;
  3637. ImGuiWindow* window = GetCurrentWindow();
  3638. if (window->SkipItems)
  3639. return false;
  3640. const ImGuiStyle& style = g.Style;
  3641. const float w_full = window->DC.ItemWidth.back();
  3642. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)) / (float)components));
  3643. const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)));
  3644. bool value_changed = false;
  3645. ImGui::PushID(label);
  3646. ImGui::PushItemWidth(w_item_one);
  3647. for (int i = 0; i < components; i++)
  3648. {
  3649. ImGui::PushID(i);
  3650. if (i + 1 == components)
  3651. {
  3652. ImGui::PopItemWidth();
  3653. ImGui::PushItemWidth(w_item_last);
  3654. }
  3655. value_changed |= ImGui::SliderInt("##v", &v[i], v_min, v_max, display_format);
  3656. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  3657. ImGui::PopID();
  3658. }
  3659. ImGui::PopItemWidth();
  3660. ImGui::PopID();
  3661. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  3662. return value_changed;
  3663. }
  3664. bool ImGui::SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* display_format)
  3665. {
  3666. return SliderIntN(label, v, 2, v_min, v_max, display_format);
  3667. }
  3668. bool ImGui::SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* display_format)
  3669. {
  3670. return SliderIntN(label, v, 3, v_min, v_max, display_format);
  3671. }
  3672. bool ImGui::SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* display_format)
  3673. {
  3674. return SliderIntN(label, v, 4, v_min, v_max, display_format);
  3675. }
  3676. enum ImGuiPlotType
  3677. {
  3678. ImGuiPlotType_Lines,
  3679. ImGuiPlotType_Histogram
  3680. };
  3681. static void Plot(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size)
  3682. {
  3683. ImGuiState& g = GImGui;
  3684. ImGuiWindow* window = GetCurrentWindow();
  3685. if (window->SkipItems)
  3686. return;
  3687. const ImGuiStyle& style = g.Style;
  3688. const ImVec2 text_size = ImGui::CalcTextSize(label, NULL, true);
  3689. if (graph_size.x == 0.0f)
  3690. graph_size.x = window->DC.ItemWidth.back();
  3691. if (graph_size.y == 0.0f)
  3692. graph_size.y = text_size.y;
  3693. const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y) + style.FramePadding*2.0f);
  3694. const ImGuiAabb graph_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
  3695. const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(text_size.x > 0.0f ? style.ItemInnerSpacing.x + text_size.x : 0.0f, 0));
  3696. ItemSize(bb);
  3697. if (ClipAdvance(bb))
  3698. return;
  3699. // Determine scale from values if not specified
  3700. if (scale_min == FLT_MAX || scale_max == FLT_MAX)
  3701. {
  3702. float v_min = FLT_MAX;
  3703. float v_max = -FLT_MAX;
  3704. for (int i = 0; i < values_count; i++)
  3705. {
  3706. const float v = values_getter(data, i);
  3707. v_min = ImMin(v_min, v);
  3708. v_max = ImMax(v_max, v);
  3709. }
  3710. if (scale_min == FLT_MAX)
  3711. scale_min = v_min;
  3712. if (scale_max == FLT_MAX)
  3713. scale_max = v_max;
  3714. }
  3715. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg));
  3716. int res_w = ImMin((int)graph_size.x, values_count);
  3717. if (plot_type == ImGuiPlotType_Lines)
  3718. res_w -= 1;
  3719. // Tooltip on hover
  3720. int v_hovered = -1;
  3721. if (IsMouseHoveringBox(graph_bb))
  3722. {
  3723. const float t = ImClamp((g.IO.MousePos.x - graph_bb.Min.x) / (graph_bb.Max.x - graph_bb.Min.x), 0.0f, 0.9999f);
  3724. const int v_idx = (int)(t * (values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0)));
  3725. IM_ASSERT(v_idx >= 0 && v_idx < values_count);
  3726. const float v0 = values_getter(data, (v_idx + values_offset) % values_count);
  3727. const float v1 = values_getter(data, (v_idx + 1 + values_offset) % values_count);
  3728. if (plot_type == ImGuiPlotType_Lines)
  3729. ImGui::SetTooltip("%d: %8.4g\n%d: %8.4g", v_idx, v0, v_idx+1, v1);
  3730. else if (plot_type == ImGuiPlotType_Histogram)
  3731. ImGui::SetTooltip("%d: %8.4g", v_idx, v0);
  3732. v_hovered = v_idx;
  3733. }
  3734. const float t_step = 1.0f / (float)res_w;
  3735. float v0 = values_getter(data, (0 + values_offset) % values_count);
  3736. float t0 = 0.0f;
  3737. ImVec2 p0 = ImVec2( t0, 1.0f - ImSaturate((v0 - scale_min) / (scale_max - scale_min)) );
  3738. const ImU32 col_base = window->Color((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLines : ImGuiCol_PlotHistogram);
  3739. const ImU32 col_hovered = window->Color((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLinesHovered : ImGuiCol_PlotHistogramHovered);
  3740. for (int n = 0; n < res_w; n++)
  3741. {
  3742. const float t1 = t0 + t_step;
  3743. const int v_idx = (int)(t0 * values_count);
  3744. IM_ASSERT(v_idx >= 0 && v_idx < values_count);
  3745. const float v1 = values_getter(data, (v_idx + values_offset + 1) % values_count);
  3746. const ImVec2 p1 = ImVec2( t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min)) );
  3747. // NB- Draw calls are merged together by the DrawList system.
  3748. if (plot_type == ImGuiPlotType_Lines)
  3749. window->DrawList->AddLine(ImLerp(graph_bb.Min, graph_bb.Max, p0), ImLerp(graph_bb.Min, graph_bb.Max, p1), v_hovered == v_idx ? col_hovered : col_base);
  3750. else if (plot_type == ImGuiPlotType_Histogram)
  3751. window->DrawList->AddRectFilled(ImLerp(graph_bb.Min, graph_bb.Max, p0), ImLerp(graph_bb.Min, graph_bb.Max, ImVec2(p1.x, 1.0f))+ImVec2(-1,0), v_hovered == v_idx ? col_hovered : col_base);
  3752. t0 = t1;
  3753. p0 = p1;
  3754. }
  3755. // Text overlay
  3756. if (overlay_text)
  3757. RenderText(ImVec2(graph_bb.GetCenter().x - ImGui::CalcTextSize(overlay_text, NULL, true).x*0.5f, frame_bb.Min.y + style.FramePadding.y), overlay_text);
  3758. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, graph_bb.Min.y), label);
  3759. }
  3760. struct ImGuiPlotArrayGetterData
  3761. {
  3762. const float* Values;
  3763. size_t Stride;
  3764. ImGuiPlotArrayGetterData(const float* values, size_t stride) { Values = values; Stride = stride; }
  3765. };
  3766. static float Plot_ArrayGetter(void* data, int idx)
  3767. {
  3768. ImGuiPlotArrayGetterData* plot_data = (ImGuiPlotArrayGetterData*)data;
  3769. const float v = *(float*)(void*)((unsigned char*)plot_data->Values + (size_t)idx * plot_data->Stride);
  3770. return v;
  3771. }
  3772. void ImGui::PlotLines(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, size_t stride)
  3773. {
  3774. ImGuiPlotArrayGetterData data(values, stride);
  3775. Plot(ImGuiPlotType_Lines, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  3776. }
  3777. void ImGui::PlotLines(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size)
  3778. {
  3779. Plot(ImGuiPlotType_Lines, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  3780. }
  3781. void ImGui::PlotHistogram(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, size_t stride)
  3782. {
  3783. ImGuiPlotArrayGetterData data(values, stride);
  3784. Plot(ImGuiPlotType_Histogram, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  3785. }
  3786. void ImGui::PlotHistogram(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size)
  3787. {
  3788. Plot(ImGuiPlotType_Histogram, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  3789. }
  3790. bool ImGui::Checkbox(const char* label, bool* v)
  3791. {
  3792. ImGuiState& g = GImGui;
  3793. ImGuiWindow* window = GetCurrentWindow();
  3794. if (window->SkipItems)
  3795. return false;
  3796. const ImGuiStyle& style = g.Style;
  3797. const ImGuiID id = window->GetID(label);
  3798. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  3799. 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));
  3800. ItemSize(check_bb);
  3801. ImGuiAabb total_bb = check_bb;
  3802. if (text_size.x > 0)
  3803. SameLine(0, (int)style.ItemInnerSpacing.x);
  3804. const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + text_size);
  3805. if (text_size.x > 0)
  3806. {
  3807. ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()));
  3808. total_bb = ImGuiAabb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
  3809. }
  3810. if (ClipAdvance(total_bb))
  3811. return false;
  3812. bool hovered, held;
  3813. bool pressed = ButtonBehaviour(total_bb, id, &hovered, &held, true);
  3814. if (pressed)
  3815. *v = !(*v);
  3816. RenderFrame(check_bb.Min, check_bb.Max, window->Color((held && hovered) ? ImGuiCol_CheckActive : hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg));
  3817. if (*v)
  3818. {
  3819. const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
  3820. const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f;
  3821. window->DrawList->AddRectFilled(check_bb.Min+ImVec2(pad,pad), check_bb.Max-ImVec2(pad,pad), window->Color(ImGuiCol_CheckMark));
  3822. }
  3823. if (g.LogEnabled)
  3824. LogText(text_bb.GetTL(), *v ? "[x]" : "[ ]");
  3825. RenderText(text_bb.GetTL(), label);
  3826. return pressed;
  3827. }
  3828. bool ImGui::CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value)
  3829. {
  3830. bool v = (*flags & flags_value) ? true : false;
  3831. bool pressed = ImGui::Checkbox(label, &v);
  3832. if (v)
  3833. *flags |= flags_value;
  3834. else
  3835. *flags &= ~flags_value;
  3836. return pressed;
  3837. }
  3838. bool ImGui::RadioButton(const char* label, bool active)
  3839. {
  3840. ImGuiState& g = GImGui;
  3841. ImGuiWindow* window = GetCurrentWindow();
  3842. if (window->SkipItems)
  3843. return false;
  3844. const ImGuiStyle& style = g.Style;
  3845. const ImGuiID id = window->GetID(label);
  3846. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  3847. 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));
  3848. ItemSize(check_bb);
  3849. ImGuiAabb total_bb = check_bb;
  3850. if (text_size.x > 0)
  3851. SameLine(0, (int)style.ItemInnerSpacing.x);
  3852. const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + text_size);
  3853. if (text_size.x > 0)
  3854. {
  3855. ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()));
  3856. total_bb.Add(text_bb);
  3857. }
  3858. if (ClipAdvance(total_bb))
  3859. return false;
  3860. ImVec2 center = check_bb.GetCenter();
  3861. center.x = (float)(int)center.x + 0.5f;
  3862. center.y = (float)(int)center.y + 0.5f;
  3863. const float radius = check_bb.GetHeight() * 0.5f;
  3864. bool hovered, held;
  3865. bool pressed = ButtonBehaviour(total_bb, id, &hovered, &held, true);
  3866. window->DrawList->AddCircleFilled(center, radius, window->Color((held && hovered) ? ImGuiCol_CheckActive : hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg), 16);
  3867. if (active)
  3868. {
  3869. const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
  3870. const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f;
  3871. window->DrawList->AddCircleFilled(center, radius-pad, window->Color(ImGuiCol_CheckMark), 16);
  3872. }
  3873. if (window->Flags & ImGuiWindowFlags_ShowBorders)
  3874. {
  3875. window->DrawList->AddCircle(center+ImVec2(1,1), radius, window->Color(ImGuiCol_BorderShadow), 16);
  3876. window->DrawList->AddCircle(center, radius, window->Color(ImGuiCol_Border), 16);
  3877. }
  3878. if (g.LogEnabled)
  3879. LogText(text_bb.GetTL(), active ? "(x)" : "( )");
  3880. RenderText(text_bb.GetTL(), label);
  3881. return pressed;
  3882. }
  3883. bool ImGui::RadioButton(const char* label, int* v, int v_button)
  3884. {
  3885. const bool pressed = ImGui::RadioButton(label, *v == v_button);
  3886. if (pressed)
  3887. {
  3888. *v = v_button;
  3889. }
  3890. return pressed;
  3891. }
  3892. // Wrapper for stb_textedit.h to edit text (our wrapper is for: statically sized buffer, single-line, wchar characters. InputText converts between UTF-8 and wchar)
  3893. static int STB_TEXTEDIT_STRINGLEN(const STB_TEXTEDIT_STRING* obj) { return (int)ImStrlenW(obj->Text); }
  3894. static ImWchar STB_TEXTEDIT_GETCHAR(const STB_TEXTEDIT_STRING* obj, int idx) { return obj->Text[idx]; }
  3895. static float STB_TEXTEDIT_GETWIDTH(STB_TEXTEDIT_STRING* obj, int line_start_idx, int char_idx) { (void)line_start_idx; return obj->Font->CalcTextSizeW(obj->FontSize, FLT_MAX, &obj->Text[char_idx], &obj->Text[char_idx]+1, NULL).x; }
  3896. static int STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x10000 ? 0 : key; }
  3897. static ImWchar STB_TEXTEDIT_NEWLINE = '\n';
  3898. static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* obj, int line_start_idx)
  3899. {
  3900. const ImWchar* text_remaining = NULL;
  3901. const ImVec2 size = obj->Font->CalcTextSizeW(obj->FontSize, FLT_MAX, obj->Text + line_start_idx, NULL, &text_remaining);
  3902. r->x0 = 0.0f;
  3903. r->x1 = size.x;
  3904. r->baseline_y_delta = size.y;
  3905. r->ymin = 0.0f;
  3906. r->ymax = size.y;
  3907. r->num_chars = (int)(text_remaining - (obj->Text + line_start_idx));
  3908. }
  3909. static bool is_white(unsigned int c) { return c==0 || c==' ' || c=='\t' || c=='\r' || c=='\n'; }
  3910. static bool is_separator(unsigned int c) { return c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|'; }
  3911. #define STB_TEXTEDIT_IS_SPACE(CH) ( is_white((unsigned int)CH) || is_separator((unsigned int)CH) )
  3912. static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n) { ImWchar* dst = obj->Text+pos; const ImWchar* src = obj->Text+pos+n; while (ImWchar c = *src++) *dst++ = c; *dst = '\0'; }
  3913. static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const ImWchar* new_text, int new_text_len)
  3914. {
  3915. const size_t text_len = ImStrlenW(obj->Text);
  3916. if ((size_t)new_text_len + text_len + 1 >= obj->BufSize)
  3917. return false;
  3918. if (pos != (int)text_len)
  3919. memmove(obj->Text + (size_t)pos + new_text_len, obj->Text + (size_t)pos, (text_len - (size_t)pos) * sizeof(ImWchar));
  3920. memcpy(obj->Text + (size_t)pos, new_text, (size_t)new_text_len * sizeof(ImWchar));
  3921. obj->Text[text_len + (size_t)new_text_len] = '\0';
  3922. return true;
  3923. }
  3924. enum
  3925. {
  3926. STB_TEXTEDIT_K_LEFT = 1 << 16, // keyboard input to move cursor left
  3927. STB_TEXTEDIT_K_RIGHT, // keyboard input to move cursor right
  3928. STB_TEXTEDIT_K_UP, // keyboard input to move cursor up
  3929. STB_TEXTEDIT_K_DOWN, // keyboard input to move cursor down
  3930. STB_TEXTEDIT_K_LINESTART, // keyboard input to move cursor to start of line
  3931. STB_TEXTEDIT_K_LINEEND, // keyboard input to move cursor to end of line
  3932. STB_TEXTEDIT_K_TEXTSTART, // keyboard input to move cursor to start of text
  3933. STB_TEXTEDIT_K_TEXTEND, // keyboard input to move cursor to end of text
  3934. STB_TEXTEDIT_K_DELETE, // keyboard input to delete selection or character under cursor
  3935. STB_TEXTEDIT_K_BACKSPACE, // keyboard input to delete selection or character left of cursor
  3936. STB_TEXTEDIT_K_UNDO, // keyboard input to perform undo
  3937. STB_TEXTEDIT_K_REDO, // keyboard input to perform redo
  3938. STB_TEXTEDIT_K_WORDLEFT, // keyboard input to move cursor left one word
  3939. STB_TEXTEDIT_K_WORDRIGHT, // keyboard input to move cursor right one word
  3940. STB_TEXTEDIT_K_SHIFT = 1 << 17
  3941. };
  3942. #define STB_TEXTEDIT_IMPLEMENTATION
  3943. #include "stb_textedit.h"
  3944. void ImGuiTextEditState::OnKeyPressed(int key)
  3945. {
  3946. stb_textedit_key(this, &StbState, key);
  3947. CursorAnimReset();
  3948. }
  3949. void ImGuiTextEditState::UpdateScrollOffset()
  3950. {
  3951. // Scroll in chunks of quarter width
  3952. const float scroll_x_increment = Width * 0.25f;
  3953. const float cursor_offset_x = Font->CalcTextSizeW(FontSize, FLT_MAX, Text, Text+StbState.cursor, NULL).x;
  3954. if (ScrollX > cursor_offset_x)
  3955. ScrollX = ImMax(0.0f, cursor_offset_x - scroll_x_increment);
  3956. else if (ScrollX < cursor_offset_x - Width)
  3957. ScrollX = cursor_offset_x - Width + scroll_x_increment;
  3958. }
  3959. ImVec2 ImGuiTextEditState::CalcDisplayOffsetFromCharIdx(int i) const
  3960. {
  3961. const ImWchar* text_start = GetTextPointerClippedW(Font, FontSize, Text, ScrollX, NULL);
  3962. const ImWchar* text_end = (Text+i >= text_start) ? Text+i : text_start; // Clip if requested character is outside of display
  3963. IM_ASSERT(text_end >= text_start);
  3964. const ImVec2 offset = Font->CalcTextSizeW(FontSize, Width, text_start, text_end, NULL);
  3965. return offset;
  3966. }
  3967. // [Static]
  3968. const char* ImGuiTextEditState::GetTextPointerClippedA(ImFont* font, float font_size, const char* text, float width, ImVec2* out_text_size)
  3969. {
  3970. if (width <= 0.0f)
  3971. return text;
  3972. const char* text_clipped_end = NULL;
  3973. const ImVec2 text_size = font->CalcTextSizeA(font_size, width, 0.0f, text, NULL, &text_clipped_end);
  3974. if (out_text_size)
  3975. *out_text_size = text_size;
  3976. return text_clipped_end;
  3977. }
  3978. // [Static]
  3979. const ImWchar* ImGuiTextEditState::GetTextPointerClippedW(ImFont* font, float font_size, const ImWchar* text, float width, ImVec2* out_text_size)
  3980. {
  3981. if (width <= 0.0f)
  3982. return text;
  3983. const ImWchar* text_clipped_end = NULL;
  3984. const ImVec2 text_size = font->CalcTextSizeW(font_size, width, text, NULL, &text_clipped_end);
  3985. if (out_text_size)
  3986. *out_text_size = text_size;
  3987. return text_clipped_end;
  3988. }
  3989. // [Static]
  3990. void ImGuiTextEditState::RenderTextScrolledClipped(ImFont* font, float font_size, const char* buf, ImVec2 pos, float width, float scroll_x)
  3991. {
  3992. // NB- We start drawing at character boundary
  3993. ImVec2 text_size;
  3994. const char* text_start = GetTextPointerClippedA(font, font_size, buf, scroll_x, NULL);
  3995. const char* text_end = GetTextPointerClippedA(font, font_size, text_start, width, &text_size);
  3996. // Draw a little clip symbol if we've got text on either left or right of the box
  3997. const char symbol_c = '~';
  3998. const float symbol_w = font_size*0.40f; // FIXME: compute correct width
  3999. const float clip_begin = (text_start > buf && text_start < text_end) ? symbol_w : 0.0f;
  4000. const float clip_end = (text_end[0] != '\0' && text_end > text_start) ? symbol_w : 0.0f;
  4001. // Draw text
  4002. RenderText(pos+ImVec2(clip_begin,0), text_start+(clip_begin>0.0f?1:0), text_end-(clip_end>0.0f?1:0), false);//, &text_params_with_clipping);
  4003. // Draw the clip symbol
  4004. const char s[2] = {symbol_c,'\0'};
  4005. if (clip_begin > 0.0f)
  4006. RenderText(pos, s);
  4007. if (clip_end > 0.0f)
  4008. RenderText(pos+ImVec2(width-clip_end,0.0f), s);
  4009. }
  4010. bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast, int decimal_precision, ImGuiInputTextFlags extra_flags)
  4011. {
  4012. ImGuiState& g = GImGui;
  4013. ImGuiWindow* window = GetCurrentWindow();
  4014. if (window->SkipItems)
  4015. return false;
  4016. const ImGuiStyle& style = g.Style;
  4017. const float w = window->DC.ItemWidth.back();
  4018. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  4019. const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f);
  4020. ImGui::PushID(label);
  4021. const float button_sz = window->FontSize();
  4022. if (step > 0.0f)
  4023. ImGui::PushItemWidth(ImMax(1.0f, w - (button_sz + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*2));
  4024. char buf[64];
  4025. if (decimal_precision < 0)
  4026. ImFormatString(buf, IM_ARRAYSIZE(buf), "%f", *v); // Ideally we'd have a minimum decimal precision of 1 to visually denote that it is a float, while hiding non-significant digits?
  4027. else
  4028. ImFormatString(buf, IM_ARRAYSIZE(buf), "%.*f", decimal_precision, *v);
  4029. bool value_changed = false;
  4030. const ImGuiInputTextFlags flags = extra_flags | (ImGuiInputTextFlags_CharsDecimal|ImGuiInputTextFlags_AutoSelectAll);
  4031. if (ImGui::InputText("", buf, IM_ARRAYSIZE(buf), flags))
  4032. {
  4033. ApplyNumericalTextInput(buf, v);
  4034. value_changed = true;
  4035. }
  4036. // Step buttons
  4037. if (step > 0.0f)
  4038. {
  4039. ImGui::PopItemWidth();
  4040. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4041. if (ImGui::Button("-", ImVec2(button_sz,button_sz), true))
  4042. {
  4043. *v -= g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step;
  4044. value_changed = true;
  4045. }
  4046. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4047. if (ImGui::Button("+", ImVec2(button_sz,button_sz), true))
  4048. {
  4049. *v += g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step;
  4050. value_changed = true;
  4051. }
  4052. }
  4053. ImGui::PopID();
  4054. if (text_size.x > 0)
  4055. {
  4056. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4057. ItemSize(text_size);
  4058. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  4059. }
  4060. return value_changed;
  4061. }
  4062. bool ImGui::InputInt(const char* label, int *v, int step, int step_fast, ImGuiInputTextFlags extra_flags)
  4063. {
  4064. float f = (float)*v;
  4065. const bool value_changed = ImGui::InputFloat(label, &f, (float)step, (float)step_fast, 0, extra_flags);
  4066. if (value_changed)
  4067. *v = (int)f;
  4068. return value_changed;
  4069. }
  4070. // Public API to manipulate UTF-8 text
  4071. // We expose UTF-8 to the user (unlike the STB_TEXTEDIT_* functions which are manipulating wchar)
  4072. void ImGuiTextEditCallbackData::DeleteChars(int pos, int bytes_count)
  4073. {
  4074. char* dst = Buf + pos;
  4075. const char* src = Buf + pos + bytes_count;
  4076. while (char c = *src++)
  4077. *dst++ = c;
  4078. *dst = '\0';
  4079. BufDirty = true;
  4080. if (CursorPos + bytes_count >= pos)
  4081. CursorPos -= bytes_count;
  4082. else if (CursorPos >= pos)
  4083. CursorPos = pos;
  4084. SelectionStart = SelectionEnd = CursorPos;
  4085. }
  4086. void ImGuiTextEditCallbackData::InsertChars(int pos, const char* new_text, const char* new_text_end)
  4087. {
  4088. const size_t text_len = strlen(Buf);
  4089. if (!new_text_end)
  4090. new_text_end = new_text + strlen(new_text);
  4091. const size_t new_text_len = (size_t)(new_text_end - new_text);
  4092. if (new_text_len + text_len + 1 >= BufSize)
  4093. return;
  4094. size_t upos = (size_t)pos;
  4095. if (text_len != upos)
  4096. memmove(Buf + upos + new_text_len, Buf + upos, text_len - upos);
  4097. memcpy(Buf + upos, new_text, new_text_len * sizeof(char));
  4098. Buf[text_len + new_text_len] = '\0';
  4099. BufDirty = true;
  4100. if (CursorPos >= pos)
  4101. CursorPos += (int)new_text_len;
  4102. SelectionStart = SelectionEnd = CursorPos;
  4103. }
  4104. static bool InputTextFilterCharacter(ImWchar c, ImGuiInputTextFlags flags)
  4105. {
  4106. if (c < 128 && c != ' ' && !isprint((int)(c & 0xFF)))
  4107. return true;
  4108. if (flags & ImGuiInputTextFlags_CharsDecimal)
  4109. if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/'))
  4110. return true;
  4111. if (flags & ImGuiInputTextFlags_CharsHexadecimal)
  4112. if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F'))
  4113. return true;
  4114. return false;
  4115. }
  4116. // Edit a string of text
  4117. bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, void (*callback)(ImGuiTextEditCallbackData*), void* user_data)
  4118. {
  4119. ImGuiState& g = GImGui;
  4120. ImGuiWindow* window = GetCurrentWindow();
  4121. if (window->SkipItems)
  4122. return false;
  4123. const ImGuiIO& io = g.IO;
  4124. const ImGuiStyle& style = g.Style;
  4125. const ImGuiID id = window->GetID(label);
  4126. const float w = window->DC.ItemWidth.back();
  4127. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  4128. const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f);
  4129. 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));
  4130. ItemSize(bb);
  4131. if (ClipAdvance(frame_bb))
  4132. return false;
  4133. // NB: we are only allowed to access 'edit_state' if we are the active widget.
  4134. ImGuiTextEditState& edit_state = g.InputTextState;
  4135. const bool is_ctrl_down = io.KeyCtrl;
  4136. const bool is_shift_down = io.KeyShift;
  4137. const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id, (flags & ImGuiInputTextFlags_CallbackCompletion) == 0); // Using completion callback disable keyboard tabbing
  4138. //const bool align_center = (bool)(flags & ImGuiInputTextFlags_AlignCenter); // FIXME: Unsupported
  4139. const bool hovered = IsHovered(frame_bb, id);
  4140. if (hovered)
  4141. g.HoveredId = id;
  4142. bool select_all = (g.ActiveId != id) && (flags & ImGuiInputTextFlags_AutoSelectAll) != 0;
  4143. if (tab_focus_requested || (hovered && io.MouseClicked[0]))
  4144. {
  4145. if (g.ActiveId != id)
  4146. {
  4147. // Start edition
  4148. // Take a copy of the initial buffer value (both in original UTF-8 format and converted to wchar)
  4149. ImFormatString(edit_state.InitialText, IM_ARRAYSIZE(edit_state.InitialText), "%s", buf);
  4150. ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), buf, NULL);
  4151. edit_state.ScrollX = 0.0f;
  4152. edit_state.Width = w;
  4153. stb_textedit_initialize_state(&edit_state.StbState, true);
  4154. edit_state.CursorAnimReset();
  4155. edit_state.LastCursorPos = ImVec2(-1.f,-1.f);
  4156. if (tab_focus_requested || is_ctrl_down)
  4157. select_all = true;
  4158. }
  4159. g.ActiveId = id;
  4160. FocusWindow(window);
  4161. }
  4162. else if (io.MouseClicked[0])
  4163. {
  4164. // Release focus when we click outside
  4165. if (g.ActiveId == id)
  4166. {
  4167. g.ActiveId = 0;
  4168. }
  4169. }
  4170. bool value_changed = false;
  4171. bool cancel_edit = false;
  4172. bool enter_pressed = false;
  4173. static char text_tmp_utf8[IM_ARRAYSIZE(edit_state.InitialText)];
  4174. if (g.ActiveId == id)
  4175. {
  4176. // Edit in progress
  4177. edit_state.BufSize = buf_size < IM_ARRAYSIZE(edit_state.Text) ? buf_size : IM_ARRAYSIZE(edit_state.Text);
  4178. edit_state.Font = window->Font();
  4179. edit_state.FontSize = window->FontSize();
  4180. const float mx = g.IO.MousePos.x - frame_bb.Min.x - style.FramePadding.x;
  4181. const float my = window->FontSize()*0.5f; // Flatten mouse because we are doing a single-line edit
  4182. edit_state.UpdateScrollOffset();
  4183. if (select_all || (hovered && io.MouseDoubleClicked[0]))
  4184. {
  4185. edit_state.SelectAll();
  4186. edit_state.SelectedAllMouseLock = true;
  4187. }
  4188. else if (io.MouseClicked[0] && !edit_state.SelectedAllMouseLock)
  4189. {
  4190. stb_textedit_click(&edit_state, &edit_state.StbState, mx + edit_state.ScrollX, my);
  4191. edit_state.CursorAnimReset();
  4192. }
  4193. else if (io.MouseDown[0] && !edit_state.SelectedAllMouseLock)
  4194. {
  4195. stb_textedit_drag(&edit_state, &edit_state.StbState, mx + edit_state.ScrollX, my);
  4196. edit_state.CursorAnimReset();
  4197. }
  4198. if (edit_state.SelectedAllMouseLock && !io.MouseDown[0])
  4199. edit_state.SelectedAllMouseLock = false;
  4200. const int k_mask = (is_shift_down ? STB_TEXTEDIT_K_SHIFT : 0);
  4201. if (IsKeyPressedMap(ImGuiKey_LeftArrow)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDLEFT | k_mask : STB_TEXTEDIT_K_LEFT | k_mask); }
  4202. else if (IsKeyPressedMap(ImGuiKey_RightArrow)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDRIGHT | k_mask : STB_TEXTEDIT_K_RIGHT | k_mask); }
  4203. else if (IsKeyPressedMap(ImGuiKey_Home)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTSTART | k_mask : STB_TEXTEDIT_K_LINESTART | k_mask); }
  4204. else if (IsKeyPressedMap(ImGuiKey_End)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTEND | k_mask : STB_TEXTEDIT_K_LINEEND | k_mask); }
  4205. else if (IsKeyPressedMap(ImGuiKey_Delete)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_DELETE | k_mask); }
  4206. else if (IsKeyPressedMap(ImGuiKey_Backspace)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask); }
  4207. else if (IsKeyPressedMap(ImGuiKey_Enter)) { g.ActiveId = 0; enter_pressed = true; }
  4208. else if (IsKeyPressedMap(ImGuiKey_Escape)) { g.ActiveId = 0; cancel_edit = true; }
  4209. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Z)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_UNDO); }
  4210. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Y)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_REDO); }
  4211. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_A)) { edit_state.SelectAll(); }
  4212. else if (is_ctrl_down && (IsKeyPressedMap(ImGuiKey_X) || IsKeyPressedMap(ImGuiKey_C)))
  4213. {
  4214. // Cut, Copy
  4215. const bool cut = IsKeyPressedMap(ImGuiKey_X);
  4216. if (cut && !edit_state.HasSelection())
  4217. edit_state.SelectAll();
  4218. if (g.IO.SetClipboardTextFn)
  4219. {
  4220. const int ib = edit_state.HasSelection() ? ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end) : 0;
  4221. const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : (int)ImStrlenW(edit_state.Text);
  4222. ImTextStrToUtf8(text_tmp_utf8, IM_ARRAYSIZE(text_tmp_utf8), edit_state.Text+ib, edit_state.Text+ie);
  4223. g.IO.SetClipboardTextFn(text_tmp_utf8);
  4224. }
  4225. if (cut)
  4226. stb_textedit_cut(&edit_state, &edit_state.StbState);
  4227. }
  4228. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_V))
  4229. {
  4230. // Paste
  4231. if (g.IO.GetClipboardTextFn)
  4232. {
  4233. if (const char* clipboard = g.IO.GetClipboardTextFn())
  4234. {
  4235. // Remove new-line from pasted buffer
  4236. size_t clipboard_len = strlen(clipboard);
  4237. ImWchar* clipboard_filtered = (ImWchar*)ImGui::MemAlloc((clipboard_len+1) * sizeof(ImWchar));
  4238. int clipboard_filtered_len = 0;
  4239. for (const char* s = clipboard; *s; )
  4240. {
  4241. unsigned int c;
  4242. const int bytes_count = ImTextCharFromUtf8(&c, s, NULL);
  4243. if (bytes_count <= 0)
  4244. break;
  4245. s += bytes_count;
  4246. if (c >= 0x10000)
  4247. continue;
  4248. if (InputTextFilterCharacter((ImWchar)c, flags))
  4249. continue;
  4250. clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c;
  4251. }
  4252. clipboard_filtered[clipboard_filtered_len] = 0;
  4253. if (clipboard_filtered_len > 0) // If everything was filtered, ignore the pasting operation
  4254. stb_textedit_paste(&edit_state, &edit_state.StbState, clipboard_filtered, clipboard_filtered_len);
  4255. ImGui::MemFree(clipboard_filtered);
  4256. }
  4257. }
  4258. }
  4259. else if (g.IO.InputCharacters[0])
  4260. {
  4261. // Text input
  4262. for (int n = 0; n < IM_ARRAYSIZE(g.IO.InputCharacters) && g.IO.InputCharacters[n]; n++)
  4263. {
  4264. const ImWchar c = g.IO.InputCharacters[n];
  4265. if (c)
  4266. {
  4267. // Insert character if they pass filtering
  4268. if (InputTextFilterCharacter(c, flags))
  4269. continue;
  4270. edit_state.OnKeyPressed(c);
  4271. }
  4272. }
  4273. // Consume characters
  4274. memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters));
  4275. }
  4276. edit_state.CursorAnim += g.IO.DeltaTime;
  4277. edit_state.UpdateScrollOffset();
  4278. if (cancel_edit)
  4279. {
  4280. // Restore initial value
  4281. ImFormatString(buf, buf_size, "%s", edit_state.InitialText);
  4282. value_changed = true;
  4283. }
  4284. else
  4285. {
  4286. // Apply new value immediately - copy modified buffer back
  4287. // Note that as soon as we can focus into the input box, the in-widget value gets priority over any underlying modification of the input buffer
  4288. // FIXME: We actually always render 'buf' in RenderTextScrolledClipped
  4289. // FIXME-OPT: CPU waste to do this every time the widget is active, should mark dirty state from the stb_textedit callbacks
  4290. ImTextStrToUtf8(text_tmp_utf8, IM_ARRAYSIZE(text_tmp_utf8), edit_state.Text, NULL);
  4291. // User callback
  4292. if ((flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackAlways)) != 0)
  4293. {
  4294. IM_ASSERT(callback != NULL);
  4295. // The reason we specify the usage semantic (Completion/History) is that Completion needs to disable keyboard TABBING at the moment.
  4296. ImGuiKey event_key = ImGuiKey_COUNT;
  4297. if ((flags & ImGuiInputTextFlags_CallbackCompletion) != 0 && IsKeyPressedMap(ImGuiKey_Tab))
  4298. event_key = ImGuiKey_Tab;
  4299. else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_UpArrow))
  4300. event_key = ImGuiKey_UpArrow;
  4301. else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_DownArrow))
  4302. event_key = ImGuiKey_DownArrow;
  4303. if (event_key != ImGuiKey_COUNT || (flags & ImGuiInputTextFlags_CallbackAlways) != 0)
  4304. {
  4305. ImGuiTextEditCallbackData callback_data;
  4306. callback_data.EventKey = event_key;
  4307. callback_data.Buf = text_tmp_utf8;
  4308. callback_data.BufSize = edit_state.BufSize;
  4309. callback_data.BufDirty = false;
  4310. callback_data.Flags = flags;
  4311. callback_data.UserData = user_data;
  4312. // We have to convert from position from wchar to UTF-8 positions
  4313. const int utf8_cursor_pos = callback_data.CursorPos = ImTextCountUtf8BytesFromWchar(edit_state.Text, edit_state.Text + edit_state.StbState.cursor);
  4314. const int utf8_selection_start = callback_data.SelectionStart = ImTextCountUtf8BytesFromWchar(edit_state.Text, edit_state.Text + edit_state.StbState.select_start);
  4315. const int utf8_selection_end = callback_data.SelectionEnd = ImTextCountUtf8BytesFromWchar(edit_state.Text, edit_state.Text + edit_state.StbState.select_end);
  4316. // Call user code
  4317. callback(&callback_data);
  4318. // Read back what user may have modified
  4319. IM_ASSERT(callback_data.Buf == text_tmp_utf8); // Invalid to modify those fields
  4320. IM_ASSERT(callback_data.BufSize == edit_state.BufSize);
  4321. IM_ASSERT(callback_data.Flags == flags);
  4322. if (callback_data.CursorPos != utf8_cursor_pos) edit_state.StbState.cursor = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.CursorPos);
  4323. if (callback_data.SelectionStart != utf8_selection_start) edit_state.StbState.select_start = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionStart);
  4324. if (callback_data.SelectionEnd != utf8_selection_end) edit_state.StbState.select_end = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionEnd);
  4325. if (callback_data.BufDirty)
  4326. {
  4327. ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), text_tmp_utf8, NULL);
  4328. edit_state.CursorAnimReset();
  4329. }
  4330. }
  4331. }
  4332. if (strcmp(text_tmp_utf8, buf) != 0)
  4333. {
  4334. ImFormatString(buf, buf_size, "%s", text_tmp_utf8);
  4335. value_changed = true;
  4336. }
  4337. }
  4338. }
  4339. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true);
  4340. const ImVec2 font_off_up = ImVec2(0.0f,window->FontSize()+1.0f); // FIXME: those offsets are part of the style or font API
  4341. const ImVec2 font_off_dn = ImVec2(0.0f,2.0f);
  4342. if (g.ActiveId == id)
  4343. {
  4344. // Draw selection
  4345. const int select_begin_idx = edit_state.StbState.select_start;
  4346. const int select_end_idx = edit_state.StbState.select_end;
  4347. if (select_begin_idx != select_end_idx)
  4348. {
  4349. const ImVec2 select_begin_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(ImMin(select_begin_idx,select_end_idx));
  4350. const ImVec2 select_end_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(ImMax(select_begin_idx,select_end_idx));
  4351. window->DrawList->AddRectFilled(select_begin_pos - font_off_up, select_end_pos + font_off_dn, window->Color(ImGuiCol_TextSelectedBg));
  4352. }
  4353. }
  4354. // FIXME: 'align_center' unsupported
  4355. ImGuiTextEditState::RenderTextScrolledClipped(window->Font(), window->FontSize(), buf, frame_bb.Min + style.FramePadding, w, (g.ActiveId == id) ? edit_state.ScrollX : 0.0f);
  4356. if (g.ActiveId == id)
  4357. {
  4358. const ImVec2 cursor_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(edit_state.StbState.cursor);
  4359. // Draw blinking cursor
  4360. if (g.InputTextState.CursorIsVisible())
  4361. window->DrawList->AddRect(cursor_pos - font_off_up + ImVec2(0,2), cursor_pos + font_off_dn - ImVec2(0,3), window->Color(ImGuiCol_Text));
  4362. // Notify OS of text input position
  4363. if (io.ImeSetInputScreenPosFn && ImLengthSqr(edit_state.LastCursorPos - cursor_pos) > 0.0001f)
  4364. 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.
  4365. edit_state.LastCursorPos = cursor_pos;
  4366. }
  4367. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  4368. if ((flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0)
  4369. return enter_pressed;
  4370. else
  4371. return value_changed;
  4372. }
  4373. static bool InputFloatN(const char* label, float* v, int components, int decimal_precision)
  4374. {
  4375. ImGuiState& g = GImGui;
  4376. ImGuiWindow* window = GetCurrentWindow();
  4377. if (window->SkipItems)
  4378. return false;
  4379. const ImGuiStyle& style = g.Style;
  4380. const float w_full = window->DC.ItemWidth.back();
  4381. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components));
  4382. const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)));
  4383. bool value_changed = false;
  4384. ImGui::PushID(label);
  4385. ImGui::PushItemWidth(w_item_one);
  4386. for (int i = 0; i < components; i++)
  4387. {
  4388. ImGui::PushID(i);
  4389. if (i + 1 == components)
  4390. {
  4391. ImGui::PopItemWidth();
  4392. ImGui::PushItemWidth(w_item_last);
  4393. }
  4394. value_changed |= ImGui::InputFloat("##v", &v[i], 0, 0, decimal_precision);
  4395. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4396. ImGui::PopID();
  4397. }
  4398. ImGui::PopItemWidth();
  4399. ImGui::PopID();
  4400. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  4401. return value_changed;
  4402. }
  4403. bool ImGui::InputFloat2(const char* label, float v[2], int decimal_precision)
  4404. {
  4405. return InputFloatN(label, v, 2, decimal_precision);
  4406. }
  4407. bool ImGui::InputFloat3(const char* label, float v[3], int decimal_precision)
  4408. {
  4409. return InputFloatN(label, v, 3, decimal_precision);
  4410. }
  4411. bool ImGui::InputFloat4(const char* label, float v[4], int decimal_precision)
  4412. {
  4413. return InputFloatN(label, v, 4, decimal_precision);
  4414. }
  4415. static bool Combo_ArrayGetter(void* data, int idx, const char** out_text)
  4416. {
  4417. const char** items = (const char**)data;
  4418. if (out_text)
  4419. *out_text = items[idx];
  4420. return true;
  4421. }
  4422. // Combo box helper allowing to pass an array of strings.
  4423. bool ImGui::Combo(const char* label, int* current_item, const char** items, int items_count, int popup_height_items)
  4424. {
  4425. const bool value_changed = Combo(label, current_item, Combo_ArrayGetter, (void*)items, items_count, popup_height_items);
  4426. return value_changed;
  4427. }
  4428. static bool Combo_StringListGetter(void* data, int idx, const char** out_text)
  4429. {
  4430. // FIXME-OPT: we could precompute the indices to fasten this. But only 1 active combo means the waste is limited.
  4431. const char* items_separated_by_zeros = (const char*)data;
  4432. int items_count = 0;
  4433. const char* p = items_separated_by_zeros;
  4434. while (*p)
  4435. {
  4436. if (idx == items_count)
  4437. break;
  4438. p += strlen(p) + 1;
  4439. items_count++;
  4440. }
  4441. if (!*p)
  4442. return false;
  4443. if (out_text)
  4444. *out_text = p;
  4445. return true;
  4446. }
  4447. // Combo box helper allowing to pass all items in a single string.
  4448. bool ImGui::Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_height_items)
  4449. {
  4450. int items_count = 0;
  4451. const char* p = items_separated_by_zeros;
  4452. while (*p)
  4453. {
  4454. p += strlen(p) + 1;
  4455. items_count++;
  4456. }
  4457. bool value_changed = Combo(label, current_item, Combo_StringListGetter, (void*)items_separated_by_zeros, items_count, popup_height_items);
  4458. return value_changed;
  4459. }
  4460. // Combo box function.
  4461. bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int popup_height_items)
  4462. {
  4463. ImGuiState& g = GImGui;
  4464. ImGuiWindow* window = GetCurrentWindow();
  4465. if (window->SkipItems)
  4466. return false;
  4467. const ImGuiStyle& style = g.Style;
  4468. const ImGuiID id = window->GetID(label);
  4469. const float w = window->DC.ItemWidth.back();
  4470. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  4471. const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f);
  4472. ItemSize(frame_bb);
  4473. if (ClipAdvance(frame_bb))
  4474. return false;
  4475. const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x,0));
  4476. const float arrow_size = (window->FontSize() + style.FramePadding.x * 2.0f);
  4477. const bool hovered = IsHovered(frame_bb, id);
  4478. bool value_changed = false;
  4479. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg));
  4480. RenderFrame(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y), frame_bb.Max, window->Color(hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button));
  4481. RenderCollapseTriangle(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y) + style.FramePadding, true);
  4482. if (*current_item >= 0 && *current_item < items_count)
  4483. {
  4484. const char* item_text;
  4485. if (items_getter(data, *current_item, &item_text))
  4486. RenderText(frame_bb.Min + style.FramePadding, item_text, NULL, false);
  4487. }
  4488. // Empty text doesn't add padding
  4489. if (text_size.x > 0)
  4490. {
  4491. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4492. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  4493. }
  4494. ImGui::PushID((int)id);
  4495. bool menu_toggled = false;
  4496. if (hovered)
  4497. {
  4498. g.HoveredId = id;
  4499. if (g.IO.MouseClicked[0])
  4500. {
  4501. menu_toggled = true;
  4502. g.ActiveComboID = (g.ActiveComboID == id) ? 0 : id;
  4503. if (g.ActiveComboID)
  4504. FocusWindow(window);
  4505. }
  4506. }
  4507. if (g.ActiveComboID == id)
  4508. {
  4509. const ImVec2 backup_pos = ImGui::GetCursorPos();
  4510. const float popup_off_x = 0.0f;//style.ItemInnerSpacing.x;
  4511. const float popup_height = (text_size.y + style.ItemSpacing.y) * ImMin(items_count, popup_height_items) + style.WindowPadding.y;
  4512. 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));
  4513. ImGui::SetCursorPos(popup_aabb.Min - window->Pos);
  4514. const ImGuiWindowFlags flags = ImGuiWindowFlags_ComboBox | ((window->Flags & ImGuiWindowFlags_ShowBorders) ? ImGuiWindowFlags_ShowBorders : 0);
  4515. ImGui::BeginChild("#ComboBox", popup_aabb.GetSize(), false, flags);
  4516. ImGuiWindow* child_window = GetCurrentWindow();
  4517. ImGui::Spacing();
  4518. bool combo_item_active = false;
  4519. combo_item_active |= (g.ActiveId == child_window->GetID("#SCROLLY"));
  4520. // Display items
  4521. for (int item_idx = 0; item_idx < items_count; item_idx++)
  4522. {
  4523. const float item_h = child_window->FontSize();
  4524. const float spacing_up = (float)(int)(style.ItemSpacing.y/2);
  4525. const float spacing_dn = style.ItemSpacing.y - spacing_up;
  4526. const ImGuiAabb item_aabb(ImVec2(popup_aabb.Min.x, child_window->DC.CursorPos.y - spacing_up), ImVec2(popup_aabb.Max.x, child_window->DC.CursorPos.y + item_h + spacing_dn));
  4527. const ImGuiID item_id = child_window->GetID((void*)(intptr_t)item_idx);
  4528. bool item_hovered, item_held;
  4529. bool item_pressed = ButtonBehaviour(item_aabb, item_id, &item_hovered, &item_held, true);
  4530. bool item_selected = (item_idx == *current_item);
  4531. if (item_hovered || item_selected)
  4532. {
  4533. const ImU32 col = window->Color((item_held && item_hovered) ? ImGuiCol_HeaderActive : item_hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
  4534. RenderFrame(item_aabb.Min, item_aabb.Max, col, false);
  4535. }
  4536. const char* item_text;
  4537. if (!items_getter(data, item_idx, &item_text))
  4538. item_text = "*Unknown item*";
  4539. ImGui::TextUnformatted(item_text);
  4540. if (item_selected)
  4541. {
  4542. if (menu_toggled)
  4543. ImGui::SetScrollPosHere();
  4544. }
  4545. if (item_pressed)
  4546. {
  4547. g.ActiveId = 0;
  4548. g.ActiveComboID = 0;
  4549. value_changed = true;
  4550. *current_item = item_idx;
  4551. }
  4552. combo_item_active |= (g.ActiveId == item_id);
  4553. }
  4554. ImGui::EndChild();
  4555. ImGui::SetCursorPos(backup_pos);
  4556. if (!combo_item_active && g.ActiveId != 0)
  4557. g.ActiveComboID = 0;
  4558. }
  4559. ImGui::PopID();
  4560. return value_changed;
  4561. }
  4562. // A little colored square. Return true when clicked.
  4563. bool ImGui::ColorButton(const ImVec4& col, bool small_height, bool outline_border)
  4564. {
  4565. ImGuiState& g = GImGui;
  4566. ImGuiWindow* window = GetCurrentWindow();
  4567. if (window->SkipItems)
  4568. return false;
  4569. const ImGuiStyle& style = g.Style;
  4570. const float square_size = window->FontSize();
  4571. 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)));
  4572. ItemSize(bb);
  4573. if (ClipAdvance(bb))
  4574. return false;
  4575. const bool hovered = IsHovered(bb, 0);
  4576. const bool pressed = hovered && g.IO.MouseClicked[0];
  4577. RenderFrame(bb.Min, bb.Max, window->Color(col), outline_border);
  4578. if (hovered)
  4579. {
  4580. int ix = (int)(col.x * 255.0f + 0.5f);
  4581. int iy = (int)(col.y * 255.0f + 0.5f);
  4582. int iz = (int)(col.z * 255.0f + 0.5f);
  4583. int iw = (int)(col.w * 255.0f + 0.5f);
  4584. ImGui::SetTooltip("Color:\n(%.2f,%.2f,%.2f,%.2f)\n#%02X%02X%02X%02X", col.x, col.y, col.z, col.w, ix, iy, iz, iw);
  4585. }
  4586. return pressed;
  4587. }
  4588. bool ImGui::ColorEdit3(const char* label, float col[3])
  4589. {
  4590. float col4[4];
  4591. col4[0] = col[0];
  4592. col4[1] = col[1];
  4593. col4[2] = col[2];
  4594. col4[3] = 1.0f;
  4595. const bool value_changed = ImGui::ColorEdit4(label, col4, false);
  4596. col[0] = col4[0];
  4597. col[1] = col4[1];
  4598. col[2] = col4[2];
  4599. return value_changed;
  4600. }
  4601. // Edit colors components (each component in 0.0f..1.0f range
  4602. // Use CTRL-Click to input value and TAB to go to next item.
  4603. bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha)
  4604. {
  4605. ImGuiState& g = GImGui;
  4606. ImGuiWindow* window = GetCurrentWindow();
  4607. if (window->SkipItems)
  4608. return false;
  4609. const ImGuiStyle& style = g.Style;
  4610. const ImGuiID id = window->GetID(label);
  4611. const float w_full = window->DC.ItemWidth.back();
  4612. const float square_sz = (window->FontSize() + style.FramePadding.x * 2.0f);
  4613. ImGuiColorEditMode edit_mode = window->DC.ColorEditMode;
  4614. if (edit_mode == ImGuiColorEditMode_UserSelect)
  4615. edit_mode = g.ColorEditModeStorage.GetInt(id, 0) % 3;
  4616. float fx = col[0];
  4617. float fy = col[1];
  4618. float fz = col[2];
  4619. float fw = col[3];
  4620. const ImVec4 col_display(fx, fy, fz, 1.0f);
  4621. if (edit_mode == ImGuiColorEditMode_HSV)
  4622. ImConvertColorRGBtoHSV(fx, fy, fz, fx, fy, fz);
  4623. int ix = (int)(fx * 255.0f + 0.5f);
  4624. int iy = (int)(fy * 255.0f + 0.5f);
  4625. int iz = (int)(fz * 255.0f + 0.5f);
  4626. int iw = (int)(fw * 255.0f + 0.5f);
  4627. int components = alpha ? 4 : 3;
  4628. bool value_changed = false;
  4629. ImGui::PushID(label);
  4630. bool hsv = (edit_mode == 1);
  4631. switch (edit_mode)
  4632. {
  4633. case ImGuiColorEditMode_RGB:
  4634. case ImGuiColorEditMode_HSV:
  4635. {
  4636. // 0: RGB 0..255 Sliders
  4637. // 1: HSV 0..255 Sliders
  4638. const float w_items_all = w_full - (square_sz + style.ItemInnerSpacing.x);
  4639. const float w_item_one = ImMax(1.0f, (float)(int)((w_items_all - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components));
  4640. const float w_item_last = ImMax(1.0f, (float)(int)(w_items_all - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)));
  4641. ImGui::PushItemWidth(w_item_one);
  4642. value_changed |= ImGui::SliderInt("##X", &ix, 0, 255, hsv ? "H:%3.0f" : "R:%3.0f");
  4643. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4644. value_changed |= ImGui::SliderInt("##Y", &iy, 0, 255, hsv ? "S:%3.0f" : "G:%3.0f");
  4645. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4646. if (alpha)
  4647. {
  4648. value_changed |= ImGui::SliderInt("##Z", &iz, 0, 255, hsv ? "V:%3.0f" : "B:%3.0f");
  4649. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4650. ImGui::PushItemWidth(w_item_last);
  4651. value_changed |= ImGui::SliderInt("##W", &iw, 0, 255, "A:%3.0f");
  4652. }
  4653. else
  4654. {
  4655. ImGui::PushItemWidth(w_item_last);
  4656. value_changed |= ImGui::SliderInt("##Z", &iz, 0, 255, hsv ? "V:%3.0f" : "B:%3.0f");
  4657. }
  4658. ImGui::PopItemWidth();
  4659. ImGui::PopItemWidth();
  4660. }
  4661. break;
  4662. case ImGuiColorEditMode_HEX:
  4663. {
  4664. // 2: RGB Hexadecimal
  4665. const float w_slider_all = w_full - square_sz;
  4666. char buf[64];
  4667. if (alpha)
  4668. sprintf(buf, "#%02X%02X%02X%02X", ix, iy, iz, iw);
  4669. else
  4670. sprintf(buf, "#%02X%02X%02X", ix, iy, iz);
  4671. ImGui::PushItemWidth(w_slider_all - style.ItemInnerSpacing.x);
  4672. value_changed |= ImGui::InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal);
  4673. ImGui::PopItemWidth();
  4674. char* p = buf;
  4675. while (*p == '#' || *p == ' ' || *p == '\t')
  4676. p++;
  4677. // Treat at unsigned (%X is unsigned)
  4678. ix = iy = iz = iw = 0;
  4679. if (alpha)
  4680. sscanf(p, "%02X%02X%02X%02X", (unsigned int*)&ix, (unsigned int*)&iy, (unsigned int*)&iz, (unsigned int*)&iw);
  4681. else
  4682. sscanf(p, "%02X%02X%02X", (unsigned int*)&ix, (unsigned int*)&iy, (unsigned int*)&iz);
  4683. }
  4684. break;
  4685. }
  4686. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4687. ImGui::ColorButton(col_display);
  4688. if (window->DC.ColorEditMode == ImGuiColorEditMode_UserSelect)
  4689. {
  4690. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4691. const char* button_titles[3] = { "RGB", "HSV", "HEX" };
  4692. if (ImGui::Button(button_titles[edit_mode]))
  4693. {
  4694. // Don't set local copy of 'edit_mode' right away!
  4695. g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3);
  4696. }
  4697. }
  4698. ImGui::SameLine();
  4699. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  4700. // Convert back
  4701. fx = ix / 255.0f;
  4702. fy = iy / 255.0f;
  4703. fz = iz / 255.0f;
  4704. fw = iw / 255.0f;
  4705. if (edit_mode == 1)
  4706. ImConvertColorHSVtoRGB(fx, fy, fz, fx, fy, fz);
  4707. if (value_changed)
  4708. {
  4709. col[0] = fx;
  4710. col[1] = fy;
  4711. col[2] = fz;
  4712. if (alpha)
  4713. col[3] = fw;
  4714. }
  4715. ImGui::PopID();
  4716. return value_changed;
  4717. }
  4718. void ImGui::ColorEditMode(ImGuiColorEditMode mode)
  4719. {
  4720. ImGuiWindow* window = GetCurrentWindow();
  4721. window->DC.ColorEditMode = mode;
  4722. }
  4723. // Horizontal separating line.
  4724. void ImGui::Separator()
  4725. {
  4726. ImGuiWindow* window = GetCurrentWindow();
  4727. if (window->SkipItems)
  4728. return;
  4729. if (window->DC.ColumnsCount > 1)
  4730. PopClipRect();
  4731. const ImGuiAabb bb(ImVec2(window->Pos.x, window->DC.CursorPos.y), ImVec2(window->Pos.x + window->Size.x, window->DC.CursorPos.y));
  4732. ItemSize(ImVec2(0.0f, bb.GetSize().y)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit
  4733. if (ClipAdvance(bb))
  4734. {
  4735. if (window->DC.ColumnsCount > 1)
  4736. PushColumnClipRect();
  4737. return;
  4738. }
  4739. window->DrawList->AddLine(bb.Min, bb.Max, window->Color(ImGuiCol_Border));
  4740. if (window->DC.ColumnsCount > 1)
  4741. PushColumnClipRect();
  4742. }
  4743. // A little vertical spacing.
  4744. void ImGui::Spacing()
  4745. {
  4746. ImGuiWindow* window = GetCurrentWindow();
  4747. if (window->SkipItems)
  4748. return;
  4749. ItemSize(ImVec2(0,0));
  4750. }
  4751. // Advance cursor given item size.
  4752. static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset)
  4753. {
  4754. ImGuiState& g = GImGui;
  4755. ImGuiWindow* window = GetCurrentWindow();
  4756. if (window->SkipItems)
  4757. return;
  4758. const float line_height = ImMax(window->DC.CurrentLineHeight, size.y);
  4759. if (adjust_start_offset)
  4760. adjust_start_offset->y = adjust_start_offset->y + (line_height - size.y) * 0.5f;
  4761. // Always align ourselves on pixel boundaries
  4762. window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y);
  4763. 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));
  4764. window->SizeContentsFit = ImMax(window->SizeContentsFit, ImVec2(window->DC.CursorPosPrevLine.x, window->DC.CursorPos.y) - window->Pos + ImVec2(0.0f, window->ScrollY));
  4765. window->DC.PrevLineHeight = line_height;
  4766. window->DC.CurrentLineHeight = 0.0f;
  4767. }
  4768. static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset)
  4769. {
  4770. ItemSize(aabb.GetSize(), adjust_start_offset);
  4771. }
  4772. void ImGui::NextColumn()
  4773. {
  4774. ImGuiState& g = GImGui;
  4775. ImGuiWindow* window = GetCurrentWindow();
  4776. if (window->SkipItems)
  4777. return;
  4778. if (window->DC.ColumnsCount > 1)
  4779. {
  4780. ImGui::PopItemWidth();
  4781. PopClipRect();
  4782. window->DC.ColumnsCellMaxY = ImMax(window->DC.ColumnsCellMaxY, window->DC.CursorPos.y);
  4783. if (++window->DC.ColumnsCurrent < window->DC.ColumnsCount)
  4784. {
  4785. window->DC.ColumnsOffsetX = ImGui::GetColumnOffset(window->DC.ColumnsCurrent) - window->DC.ColumnsStartX + g.Style.ItemSpacing.x;
  4786. }
  4787. else
  4788. {
  4789. window->DC.ColumnsCurrent = 0;
  4790. window->DC.ColumnsOffsetX = 0.0f;
  4791. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY;
  4792. }
  4793. window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX);
  4794. window->DC.CursorPos.y = window->DC.ColumnsCellMinY;
  4795. window->DC.CurrentLineHeight = 0.0f;
  4796. PushColumnClipRect();
  4797. ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f);
  4798. }
  4799. }
  4800. static bool IsClipped(const ImGuiAabb& bb)
  4801. {
  4802. ImGuiState& g = GImGui;
  4803. ImGuiWindow* window = GetCurrentWindow();
  4804. if (!bb.Overlaps(ImGuiAabb(window->ClipRectStack.back())) && !g.LogEnabled)
  4805. return true;
  4806. return false;
  4807. }
  4808. bool ImGui::IsClipped(const ImVec2& item_size)
  4809. {
  4810. ImGuiWindow* window = GetCurrentWindow();
  4811. return IsClipped(ImGuiAabb(window->DC.CursorPos, window->DC.CursorPos + item_size));
  4812. }
  4813. static bool ClipAdvance(const ImGuiAabb& bb)
  4814. {
  4815. ImGuiWindow* window = GetCurrentWindow();
  4816. window->DC.LastItemAabb = bb;
  4817. window->DC.LastItemFocused = false;
  4818. if (IsClipped(bb))
  4819. {
  4820. window->DC.LastItemHovered = false;
  4821. return true;
  4822. }
  4823. window->DC.LastItemHovered = IsMouseHoveringBox(bb); // this is a sensible default but widgets are free to override it after calling ClipAdvance
  4824. return false;
  4825. }
  4826. // Gets back to previous line and continue with horizontal layout
  4827. // column_x == 0 : follow on previous item
  4828. // columm_x != 0 : align to specified column
  4829. // spacing_w < 0 : use default spacing if column_x==0, no spacing if column_x!=0
  4830. // spacing_w >= 0 : enforce spacing
  4831. void ImGui::SameLine(int column_x, int spacing_w)
  4832. {
  4833. ImGuiState& g = GImGui;
  4834. ImGuiWindow* window = GetCurrentWindow();
  4835. if (window->SkipItems)
  4836. return;
  4837. float x, y;
  4838. if (column_x != 0)
  4839. {
  4840. if (spacing_w < 0) spacing_w = 0;
  4841. x = window->Pos.x + (float)column_x + (float)spacing_w;
  4842. y = window->DC.CursorPosPrevLine.y;
  4843. }
  4844. else
  4845. {
  4846. if (spacing_w < 0) spacing_w = (int)g.Style.ItemSpacing.x;
  4847. x = window->DC.CursorPosPrevLine.x + (float)spacing_w;
  4848. y = window->DC.CursorPosPrevLine.y;
  4849. }
  4850. window->DC.CurrentLineHeight = window->DC.PrevLineHeight;
  4851. window->DC.CursorPos = ImVec2(x, y);
  4852. }
  4853. float ImGui::GetColumnOffset(int column_index)
  4854. {
  4855. ImGuiState& g = GImGui;
  4856. ImGuiWindow* window = GetCurrentWindow();
  4857. if (column_index < 0)
  4858. column_index = window->DC.ColumnsCurrent;
  4859. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
  4860. RegisterAliveId(column_id);
  4861. const float default_t = column_index / (float)window->DC.ColumnsCount;
  4862. 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?)
  4863. const float offset = window->DC.ColumnsStartX + t * (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnsStartX);
  4864. return offset;
  4865. }
  4866. void ImGui::SetColumnOffset(int column_index, float offset)
  4867. {
  4868. ImGuiState& g = GImGui;
  4869. ImGuiWindow* window = GetCurrentWindow();
  4870. if (column_index < 0)
  4871. column_index = window->DC.ColumnsCurrent;
  4872. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
  4873. const float t = (offset - window->DC.ColumnsStartX) / (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnsStartX);
  4874. window->StateStorage.SetFloat(column_id, t);
  4875. }
  4876. float ImGui::GetColumnWidth(int column_index)
  4877. {
  4878. ImGuiWindow* window = GetCurrentWindow();
  4879. if (column_index < 0)
  4880. column_index = window->DC.ColumnsCurrent;
  4881. const float w = GetColumnOffset(column_index+1) - GetColumnOffset(column_index);
  4882. return w;
  4883. }
  4884. static void PushColumnClipRect(int column_index)
  4885. {
  4886. ImGuiWindow* window = GetCurrentWindow();
  4887. if (column_index < 0)
  4888. column_index = window->DC.ColumnsCurrent;
  4889. const float x1 = window->Pos.x + ImGui::GetColumnOffset(column_index) - 1;
  4890. const float x2 = window->Pos.x + ImGui::GetColumnOffset(column_index+1) - 1;
  4891. PushClipRect(ImVec4(x1,-FLT_MAX,x2,+FLT_MAX));
  4892. }
  4893. void ImGui::Columns(int columns_count, const char* id, bool border)
  4894. {
  4895. ImGuiState& g = GImGui;
  4896. ImGuiWindow* window = GetCurrentWindow();
  4897. if (window->SkipItems)
  4898. return;
  4899. if (window->DC.ColumnsCount != 1)
  4900. {
  4901. if (window->DC.ColumnsCurrent != 0)
  4902. ItemSize(ImVec2(0,0)); // Advance to column 0
  4903. ImGui::PopItemWidth();
  4904. PopClipRect();
  4905. window->DC.ColumnsCellMaxY = ImMax(window->DC.ColumnsCellMaxY, window->DC.CursorPos.y);
  4906. window->DC.CursorPos.y = window->DC.ColumnsCellMaxY;
  4907. }
  4908. // Draw columns borders and handle resize at the time of "closing" a columns set
  4909. if (window->DC.ColumnsCount != columns_count && window->DC.ColumnsCount != 1 && window->DC.ColumnsShowBorders)
  4910. {
  4911. const float y1 = window->DC.ColumnsStartPos.y;
  4912. const float y2 = window->DC.CursorPos.y;
  4913. for (int i = 1; i < window->DC.ColumnsCount; i++)
  4914. {
  4915. float x = window->Pos.x + GetColumnOffset(i);
  4916. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(i);
  4917. const ImGuiAabb column_aabb(ImVec2(x-4,y1),ImVec2(x+4,y2));
  4918. if (IsClipped(column_aabb))
  4919. continue;
  4920. bool hovered, held;
  4921. ButtonBehaviour(column_aabb, column_id, &hovered, &held, true);
  4922. // Draw before resize so our items positioning are in sync with the line being drawn
  4923. const ImU32 col = window->Color(held ? ImGuiCol_ColumnActive : hovered ? ImGuiCol_ColumnHovered : ImGuiCol_Column);
  4924. const float xi = (float)(int)x;
  4925. window->DrawList->AddLine(ImVec2(xi, y1), ImVec2(xi, y2), col);
  4926. if (held)
  4927. {
  4928. x -= window->Pos.x;
  4929. x = ImClamp(x + g.IO.MouseDelta.x, ImGui::GetColumnOffset(i-1)+g.Style.ColumnsMinSpacing, ImGui::GetColumnOffset(i+1)-g.Style.ColumnsMinSpacing);
  4930. SetColumnOffset(i, x);
  4931. x += window->Pos.x;
  4932. }
  4933. }
  4934. }
  4935. // Set state for first column
  4936. window->DC.ColumnsSetID = window->GetID(id ? id : "");
  4937. window->DC.ColumnsCurrent = 0;
  4938. window->DC.ColumnsCount = columns_count;
  4939. window->DC.ColumnsShowBorders = border;
  4940. window->DC.ColumnsStartPos = window->DC.CursorPos;
  4941. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.CursorPos.y;
  4942. window->DC.ColumnsOffsetX = 0.0f;
  4943. window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX);
  4944. if (window->DC.ColumnsCount != 1)
  4945. {
  4946. PushColumnClipRect();
  4947. ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f);
  4948. }
  4949. }
  4950. void ImGui::TreePush(const char* str_id)
  4951. {
  4952. ImGuiState& g = GImGui;
  4953. ImGuiWindow* window = GetCurrentWindow();
  4954. window->DC.ColumnsStartX += g.Style.TreeNodeSpacing;
  4955. window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX;
  4956. window->DC.TreeDepth++;
  4957. PushID(str_id ? str_id : "#TreePush");
  4958. }
  4959. void ImGui::TreePush(const void* ptr_id)
  4960. {
  4961. ImGuiState& g = GImGui;
  4962. ImGuiWindow* window = GetCurrentWindow();
  4963. window->DC.ColumnsStartX += g.Style.TreeNodeSpacing;
  4964. window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX;
  4965. window->DC.TreeDepth++;
  4966. PushID(ptr_id ? ptr_id : (const void*)"#TreePush");
  4967. }
  4968. void ImGui::TreePop()
  4969. {
  4970. ImGuiState& g = GImGui;
  4971. ImGuiWindow* window = GetCurrentWindow();
  4972. window->DC.ColumnsStartX -= g.Style.TreeNodeSpacing;
  4973. window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX;
  4974. window->DC.TreeDepth--;
  4975. PopID();
  4976. }
  4977. void ImGui::Value(const char* prefix, bool b)
  4978. {
  4979. ImGui::Text("%s: %s", prefix, (b ? "true" : "false"));
  4980. }
  4981. void ImGui::Value(const char* prefix, int v)
  4982. {
  4983. ImGui::Text("%s: %d", prefix, v);
  4984. }
  4985. void ImGui::Value(const char* prefix, unsigned int v)
  4986. {
  4987. ImGui::Text("%s: %d", prefix, v);
  4988. }
  4989. void ImGui::Value(const char* prefix, float v, const char* float_format)
  4990. {
  4991. if (float_format)
  4992. {
  4993. char fmt[64];
  4994. sprintf(fmt, "%%s: %s", float_format);
  4995. ImGui::Text(fmt, prefix, v);
  4996. }
  4997. else
  4998. {
  4999. ImGui::Text("%s: %.3f", prefix, v);
  5000. }
  5001. }
  5002. void ImGui::Color(const char* prefix, const ImVec4& v)
  5003. {
  5004. ImGui::Text("%s: (%.2f,%.2f,%.2f,%.2f)", prefix, v.x, v.y, v.z, v.w);
  5005. ImGui::SameLine();
  5006. ImGui::ColorButton(v, true);
  5007. }
  5008. void ImGui::Color(const char* prefix, unsigned int v)
  5009. {
  5010. ImGui::Text("%s: %08X", prefix, v);
  5011. ImGui::SameLine();
  5012. ImVec4 col;
  5013. col.x = (float)((v >> 0) & 0xFF) / 255.0f;
  5014. col.y = (float)((v >> 8) & 0xFF) / 255.0f;
  5015. col.z = (float)((v >> 16) & 0xFF) / 255.0f;
  5016. col.w = (float)((v >> 24) & 0xFF) / 255.0f;
  5017. ImGui::ColorButton(col, true);
  5018. }
  5019. //-----------------------------------------------------------------------------
  5020. // ImDrawList
  5021. //-----------------------------------------------------------------------------
  5022. void ImDrawList::Clear()
  5023. {
  5024. commands.resize(0);
  5025. vtx_buffer.resize(0);
  5026. vtx_write = NULL;
  5027. clip_rect_stack.resize(0);
  5028. }
  5029. void ImDrawList::PushClipRect(const ImVec4& clip_rect)
  5030. {
  5031. if (!commands.empty() && commands.back().vtx_count == 0)
  5032. {
  5033. // Reuse empty command because high-level clipping may have discarded the other vertices already
  5034. commands.back().clip_rect = clip_rect;
  5035. }
  5036. else
  5037. {
  5038. ImDrawCmd draw_cmd;
  5039. draw_cmd.vtx_count = 0;
  5040. draw_cmd.clip_rect = clip_rect;
  5041. commands.push_back(draw_cmd);
  5042. }
  5043. clip_rect_stack.push_back(clip_rect);
  5044. }
  5045. void ImDrawList::PopClipRect()
  5046. {
  5047. clip_rect_stack.pop_back();
  5048. const ImVec4 clip_rect = clip_rect_stack.empty() ? ImVec4(-9999.0f,-9999.0f, +9999.0f, +9999.0f) : clip_rect_stack.back();
  5049. if (!commands.empty() && commands.back().vtx_count == 0)
  5050. {
  5051. // Reuse empty command because high-level clipping may have discarded the other vertices already
  5052. commands.back().clip_rect = clip_rect;
  5053. }
  5054. else
  5055. {
  5056. ImDrawCmd draw_cmd;
  5057. draw_cmd.vtx_count = 0;
  5058. draw_cmd.clip_rect = clip_rect;
  5059. commands.push_back(draw_cmd);
  5060. }
  5061. }
  5062. void ImDrawList::ReserveVertices(unsigned int vtx_count)
  5063. {
  5064. if (vtx_count > 0)
  5065. {
  5066. ImDrawCmd& draw_cmd = commands.back();
  5067. draw_cmd.vtx_count += vtx_count;
  5068. vtx_buffer.resize(vtx_buffer.size() + vtx_count);
  5069. vtx_write = &vtx_buffer[vtx_buffer.size() - vtx_count];
  5070. }
  5071. }
  5072. void ImDrawList::AddVtx(const ImVec2& pos, ImU32 col)
  5073. {
  5074. vtx_write->pos = pos;
  5075. vtx_write->col = col;
  5076. vtx_write->uv = GImGui.FontTexUvForWhite;
  5077. vtx_write++;
  5078. }
  5079. void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col)
  5080. {
  5081. const float offset = GImGui.IO.PixelCenterOffset;
  5082. const float length = sqrtf(ImLengthSqr(b - a));
  5083. const ImVec2 hn = (b - a) * (0.50f / length); // half normal
  5084. const ImVec2 hp0 = ImVec2(offset + hn.y, offset - hn.x); // half perpendiculars + user offset
  5085. const ImVec2 hp1 = ImVec2(offset - hn.y, offset + hn.x);
  5086. // Two triangles makes up one line. Using triangles allows us to reduce amount of draw calls.
  5087. AddVtx(a + hp0, col);
  5088. AddVtx(b + hp0, col);
  5089. AddVtx(a + hp1, col);
  5090. AddVtx(b + hp0, col);
  5091. AddVtx(b + hp1, col);
  5092. AddVtx(a + hp1, col);
  5093. }
  5094. void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col)
  5095. {
  5096. if ((col >> 24) == 0)
  5097. return;
  5098. ReserveVertices(6);
  5099. AddVtxLine(a, b, col);
  5100. }
  5101. void ImDrawList::AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris, const ImVec2& third_point_offset)
  5102. {
  5103. if ((col >> 24) == 0)
  5104. return;
  5105. static ImVec2 circle_vtx[12];
  5106. static bool circle_vtx_builds = false;
  5107. if (!circle_vtx_builds)
  5108. {
  5109. for (int i = 0; i < IM_ARRAYSIZE(circle_vtx); i++)
  5110. {
  5111. const float a = ((float)i / (float)IM_ARRAYSIZE(circle_vtx)) * 2*PI;
  5112. circle_vtx[i].x = cosf(a + PI);
  5113. circle_vtx[i].y = sinf(a + PI);
  5114. }
  5115. circle_vtx_builds = true;
  5116. }
  5117. if (tris)
  5118. {
  5119. ReserveVertices((unsigned int)(a_max-a_min) * 3);
  5120. for (int a = a_min; a < a_max; a++)
  5121. {
  5122. AddVtx(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, col);
  5123. AddVtx(center + circle_vtx[(a+1) % IM_ARRAYSIZE(circle_vtx)] * rad, col);
  5124. AddVtx(center + third_point_offset, col);
  5125. }
  5126. }
  5127. else
  5128. {
  5129. ReserveVertices((unsigned int)(a_max-a_min) * 6);
  5130. for (int a = a_min; a < a_max; a++)
  5131. AddVtxLine(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, center + circle_vtx[(a+1) % IM_ARRAYSIZE(circle_vtx)] * rad, col);
  5132. }
  5133. }
  5134. void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners)
  5135. {
  5136. if ((col >> 24) == 0)
  5137. return;
  5138. float r = rounding;
  5139. r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f ));
  5140. r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f ));
  5141. if (r == 0.0f || rounding_corners == 0)
  5142. {
  5143. ReserveVertices(4*6);
  5144. AddVtxLine(ImVec2(a.x,a.y), ImVec2(b.x,a.y), col);
  5145. AddVtxLine(ImVec2(b.x,a.y), ImVec2(b.x,b.y), col);
  5146. AddVtxLine(ImVec2(b.x,b.y), ImVec2(a.x,b.y), col);
  5147. AddVtxLine(ImVec2(a.x,b.y), ImVec2(a.x,a.y), col);
  5148. }
  5149. else
  5150. {
  5151. ReserveVertices(4*6);
  5152. AddVtxLine(ImVec2(a.x + ((rounding_corners & 1)?r:0), a.y), ImVec2(b.x - ((rounding_corners & 2)?r:0), a.y), col);
  5153. AddVtxLine(ImVec2(b.x, a.y + ((rounding_corners & 2)?r:0)), ImVec2(b.x, b.y - ((rounding_corners & 4)?r:0)), col);
  5154. AddVtxLine(ImVec2(b.x - ((rounding_corners & 4)?r:0), b.y), ImVec2(a.x + ((rounding_corners & 8)?r:0), b.y), col);
  5155. AddVtxLine(ImVec2(a.x, b.y - ((rounding_corners & 8)?r:0)), ImVec2(a.x, a.y + ((rounding_corners & 1)?r:0)), col);
  5156. if (rounding_corners & 1) AddArc(ImVec2(a.x+r,a.y+r), r, col, 0, 3);
  5157. if (rounding_corners & 2) AddArc(ImVec2(b.x-r,a.y+r), r, col, 3, 6);
  5158. if (rounding_corners & 4) AddArc(ImVec2(b.x-r,b.y-r), r, col, 6, 9);
  5159. if (rounding_corners & 8) AddArc(ImVec2(a.x+r,b.y-r), r, col, 9, 12);
  5160. }
  5161. }
  5162. void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners)
  5163. {
  5164. if ((col >> 24) == 0)
  5165. return;
  5166. float r = rounding;
  5167. r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f ));
  5168. r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f ));
  5169. if (r == 0.0f || rounding_corners == 0)
  5170. {
  5171. // Use triangle so we can merge more draw calls together (at the cost of extra vertices)
  5172. ReserveVertices(6);
  5173. AddVtx(ImVec2(a.x,a.y), col);
  5174. AddVtx(ImVec2(b.x,a.y), col);
  5175. AddVtx(ImVec2(b.x,b.y), col);
  5176. AddVtx(ImVec2(a.x,a.y), col);
  5177. AddVtx(ImVec2(b.x,b.y), col);
  5178. AddVtx(ImVec2(a.x,b.y), col);
  5179. }
  5180. else
  5181. {
  5182. ReserveVertices(6+6*2);
  5183. AddVtx(ImVec2(a.x+r,a.y), col);
  5184. AddVtx(ImVec2(b.x-r,a.y), col);
  5185. AddVtx(ImVec2(b.x-r,b.y), col);
  5186. AddVtx(ImVec2(a.x+r,a.y), col);
  5187. AddVtx(ImVec2(b.x-r,b.y), col);
  5188. AddVtx(ImVec2(a.x+r,b.y), col);
  5189. float top_y = (rounding_corners & 1) ? a.y+r : a.y;
  5190. float bot_y = (rounding_corners & 8) ? b.y-r : b.y;
  5191. AddVtx(ImVec2(a.x,top_y), col);
  5192. AddVtx(ImVec2(a.x+r,top_y), col);
  5193. AddVtx(ImVec2(a.x+r,bot_y), col);
  5194. AddVtx(ImVec2(a.x,top_y), col);
  5195. AddVtx(ImVec2(a.x+r,bot_y), col);
  5196. AddVtx(ImVec2(a.x,bot_y), col);
  5197. top_y = (rounding_corners & 2) ? a.y+r : a.y;
  5198. bot_y = (rounding_corners & 4) ? b.y-r : b.y;
  5199. AddVtx(ImVec2(b.x-r,top_y), col);
  5200. AddVtx(ImVec2(b.x,top_y), col);
  5201. AddVtx(ImVec2(b.x,bot_y), col);
  5202. AddVtx(ImVec2(b.x-r,top_y), col);
  5203. AddVtx(ImVec2(b.x,bot_y), col);
  5204. AddVtx(ImVec2(b.x-r,bot_y), col);
  5205. if (rounding_corners & 1) AddArc(ImVec2(a.x+r,a.y+r), r, col, 0, 3, true);
  5206. if (rounding_corners & 2) AddArc(ImVec2(b.x-r,a.y+r), r, col, 3, 6, true);
  5207. if (rounding_corners & 4) AddArc(ImVec2(b.x-r,b.y-r), r, col, 6, 9, true);
  5208. if (rounding_corners & 8) AddArc(ImVec2(a.x+r,b.y-r), r, col, 9, 12,true);
  5209. }
  5210. }
  5211. void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col)
  5212. {
  5213. if ((col >> 24) == 0)
  5214. return;
  5215. const ImVec2 offset(GImGui.IO.PixelCenterOffset,GImGui.IO.PixelCenterOffset);
  5216. ReserveVertices(3);
  5217. AddVtx(a + offset, col);
  5218. AddVtx(b + offset, col);
  5219. AddVtx(c + offset, col);
  5220. }
  5221. void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments)
  5222. {
  5223. if ((col >> 24) == 0)
  5224. return;
  5225. const ImVec2 offset(GImGui.IO.PixelCenterOffset,GImGui.IO.PixelCenterOffset);
  5226. ReserveVertices((unsigned int)num_segments*6);
  5227. const float a_step = 2*PI/(float)num_segments;
  5228. float a0 = 0.0f;
  5229. for (int i = 0; i < num_segments; i++)
  5230. {
  5231. const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step;
  5232. AddVtxLine(centre + offset + ImVec2(cosf(a0), sinf(a0))*radius, centre + ImVec2(cosf(a1), sinf(a1))*radius, col);
  5233. a0 = a1;
  5234. }
  5235. }
  5236. void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments)
  5237. {
  5238. if ((col >> 24) == 0)
  5239. return;
  5240. const ImVec2 offset(GImGui.IO.PixelCenterOffset,GImGui.IO.PixelCenterOffset);
  5241. ReserveVertices((unsigned int)num_segments*3);
  5242. const float a_step = 2*PI/(float)num_segments;
  5243. float a0 = 0.0f;
  5244. for (int i = 0; i < num_segments; i++)
  5245. {
  5246. const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step;
  5247. AddVtx(centre + offset + ImVec2(cosf(a0), sinf(a0))*radius, col);
  5248. AddVtx(centre + offset + ImVec2(cosf(a1), sinf(a1))*radius, col);
  5249. AddVtx(centre + offset, col);
  5250. a0 = a1;
  5251. }
  5252. }
  5253. void ImDrawList::AddText(ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end, float wrap_width)
  5254. {
  5255. if ((col >> 24) == 0)
  5256. return;
  5257. if (text_end == NULL)
  5258. text_end = text_begin + strlen(text_begin); // FIXME-OPT
  5259. // reserve vertices for worse case
  5260. const unsigned int char_count = (unsigned int)(text_end - text_begin);
  5261. const unsigned int vtx_count_max = char_count * 6;
  5262. const size_t vtx_begin = vtx_buffer.size();
  5263. ReserveVertices(vtx_count_max);
  5264. font->RenderText(font_size, pos, col, clip_rect_stack.back(), text_begin, text_end, vtx_write, wrap_width);
  5265. // give back unused vertices
  5266. vtx_buffer.resize((size_t)(vtx_write - &vtx_buffer.front()));
  5267. const size_t vtx_count = vtx_buffer.size() - vtx_begin;
  5268. commands.back().vtx_count -= (unsigned int)(vtx_count_max - vtx_count);
  5269. vtx_write -= (vtx_count_max - vtx_count);
  5270. }
  5271. //-----------------------------------------------------------------------------
  5272. // ImBitmapFont
  5273. //-----------------------------------------------------------------------------
  5274. ImFont::ImFont()
  5275. {
  5276. Scale = 1.0f;
  5277. DisplayOffset = ImVec2(0.0f,0.0f);
  5278. TexUvForWhite = ImVec2(0.0f,0.0f);
  5279. FallbackChar = (ImWchar)'?';
  5280. Data = NULL;
  5281. DataSize = 0;
  5282. DataOwned = false;
  5283. Info = NULL;
  5284. Common = NULL;
  5285. Glyphs = NULL;
  5286. GlyphsCount = 0;
  5287. Kerning = NULL;
  5288. KerningCount = 0;
  5289. FallbackGlyph = NULL;
  5290. }
  5291. void ImFont::Clear()
  5292. {
  5293. if (Data && DataOwned)
  5294. ImGui::MemFree(Data);
  5295. Data = NULL;
  5296. DataOwned = false;
  5297. Info = NULL;
  5298. Common = NULL;
  5299. Glyphs = NULL;
  5300. GlyphsCount = 0;
  5301. Filenames.clear();
  5302. IndexLookup.clear();
  5303. FallbackGlyph = NULL;
  5304. }
  5305. bool ImFont::LoadFromFile(const char* filename)
  5306. {
  5307. IM_ASSERT(!IsLoaded()); // Call Clear()
  5308. if (!ImLoadFileToMemory(filename, "rb", (void**)&Data, &DataSize))
  5309. return false;
  5310. DataOwned = true;
  5311. return LoadFromMemory(Data, DataSize);
  5312. }
  5313. bool ImFont::LoadFromMemory(const void* data, size_t data_size)
  5314. {
  5315. IM_ASSERT(!IsLoaded()); // Call Clear()
  5316. Data = (unsigned char*)data;
  5317. DataSize = data_size;
  5318. // Parse data
  5319. if (DataSize < 4 || Data[0] != 'B' || Data[1] != 'M' || Data[2] != 'F' || Data[3] != 0x03)
  5320. return false;
  5321. for (const unsigned char* p = Data+4; p < Data + DataSize; )
  5322. {
  5323. const unsigned char block_type = *(unsigned char*)p;
  5324. p += sizeof(unsigned char);
  5325. ImU32 block_size; // use memcpy to read 4-byte because they may be unaligned. This seems to break when compiling for Emscripten.
  5326. memcpy(&block_size, p, sizeof(ImU32));
  5327. p += sizeof(ImU32);
  5328. switch (block_type)
  5329. {
  5330. case 1:
  5331. IM_ASSERT(Info == NULL);
  5332. Info = (FntInfo*)p;
  5333. break;
  5334. case 2:
  5335. IM_ASSERT(Common == NULL);
  5336. Common = (FntCommon*)p;
  5337. break;
  5338. case 3:
  5339. for (const unsigned char* s = p; s < p+block_size && s < Data+DataSize; s = s + strlen((const char*)s) + 1)
  5340. Filenames.push_back((const char*)s);
  5341. break;
  5342. case 4:
  5343. IM_ASSERT(Glyphs == NULL && GlyphsCount == 0);
  5344. Glyphs = (FntGlyph*)p;
  5345. GlyphsCount = block_size / sizeof(FntGlyph);
  5346. break;
  5347. case 5:
  5348. IM_ASSERT(Kerning == NULL && KerningCount == 0);
  5349. Kerning = (FntKerning*)p;
  5350. KerningCount = block_size / sizeof(FntKerning);
  5351. break;
  5352. default:
  5353. break;
  5354. }
  5355. p += block_size;
  5356. }
  5357. BuildLookupTable();
  5358. return true;
  5359. }
  5360. void ImFont::BuildLookupTable()
  5361. {
  5362. ImU32 max_c = 0;
  5363. for (size_t i = 0; i != GlyphsCount; i++)
  5364. if (max_c < Glyphs[i].Id)
  5365. max_c = Glyphs[i].Id;
  5366. IndexLookup.clear();
  5367. IndexLookup.resize(max_c + 1);
  5368. for (size_t i = 0; i < IndexLookup.size(); i++)
  5369. IndexLookup[i] = -1;
  5370. for (size_t i = 0; i < GlyphsCount; i++)
  5371. IndexLookup[Glyphs[i].Id] = (int)i;
  5372. }
  5373. const ImFont::FntGlyph* ImFont::FindGlyph(unsigned short c) const
  5374. {
  5375. if (c < (int)IndexLookup.size())
  5376. {
  5377. const int i = IndexLookup[c];
  5378. if (i >= 0 && i < (int)GlyphsCount)
  5379. return &Glyphs[i];
  5380. }
  5381. return FallbackGlyph;
  5382. }
  5383. // Convert UTF-8 to 32-bits character, process single character input.
  5384. // Based on stb_from_utf8() from github.com/nothings/stb/
  5385. static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end)
  5386. {
  5387. if (*in_text != 0)
  5388. {
  5389. unsigned int c = (unsigned int)-1;
  5390. const unsigned char* str = (const unsigned char*)in_text;
  5391. if (!(*str & 0x80))
  5392. {
  5393. c = (unsigned int)(*str++);
  5394. *out_char = c;
  5395. return 1;
  5396. }
  5397. if ((*str & 0xe0) == 0xc0)
  5398. {
  5399. if (in_text_end && in_text_end - (const char*)str < 2) return -1;
  5400. if (*str < 0xc2) return -1;
  5401. c = (unsigned int)((*str++ & 0x1f) << 6);
  5402. if ((*str & 0xc0) != 0x80) return -1;
  5403. c += (*str++ & 0x3f);
  5404. *out_char = c;
  5405. return 2;
  5406. }
  5407. if ((*str & 0xf0) == 0xe0)
  5408. {
  5409. if (in_text_end && in_text_end - (const char*)str < 3) return -1;
  5410. if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return -1;
  5411. if (*str == 0xed && str[1] > 0x9f) return -1; // str[1] < 0x80 is checked below
  5412. c = (unsigned int)((*str++ & 0x0f) << 12);
  5413. if ((*str & 0xc0) != 0x80) return -1;
  5414. c += (unsigned int)((*str++ & 0x3f) << 6);
  5415. if ((*str & 0xc0) != 0x80) return -1;
  5416. c += (*str++ & 0x3f);
  5417. *out_char = c;
  5418. return 3;
  5419. }
  5420. if ((*str & 0xf8) == 0xf0)
  5421. {
  5422. if (in_text_end && in_text_end - (const char*)str < 4) return -1;
  5423. if (*str > 0xf4) return -1;
  5424. if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return -1;
  5425. if (*str == 0xf4 && str[1] > 0x8f) return -1; // str[1] < 0x80 is checked below
  5426. c = (unsigned int)((*str++ & 0x07) << 18);
  5427. if ((*str & 0xc0) != 0x80) return -1;
  5428. c += (unsigned int)((*str++ & 0x3f) << 12);
  5429. if ((*str & 0xc0) != 0x80) return -1;
  5430. c += (unsigned int)((*str++ & 0x3f) << 6);
  5431. if ((*str & 0xc0) != 0x80) return -1;
  5432. c += (*str++ & 0x3f);
  5433. // utf-8 encodings of values used in surrogate pairs are invalid
  5434. if ((c & 0xFFFFF800) == 0xD800) return -1;
  5435. *out_char = c;
  5436. return 4;
  5437. }
  5438. }
  5439. *out_char = 0;
  5440. return 0;
  5441. }
  5442. static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end)
  5443. {
  5444. ImWchar* buf_out = buf;
  5445. ImWchar* buf_end = buf + buf_size;
  5446. while (buf_out < buf_end-1 && (!in_text_end || in_text < in_text_end) && *in_text)
  5447. {
  5448. unsigned int c;
  5449. in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
  5450. if (c < 0x10000) // FIXME: Losing characters that don't fit in 2 bytes
  5451. *buf_out++ = (ImWchar)c;
  5452. }
  5453. *buf_out = 0;
  5454. return buf_out - buf;
  5455. }
  5456. static int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end)
  5457. {
  5458. int char_count = 0;
  5459. while ((!in_text_end || in_text < in_text_end) && *in_text)
  5460. {
  5461. unsigned int c;
  5462. in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
  5463. if (c < 0x10000)
  5464. char_count++;
  5465. }
  5466. return char_count;
  5467. }
  5468. // Based on stb_to_utf8() from github.com/nothings/stb/
  5469. static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int c)
  5470. {
  5471. if (c)
  5472. {
  5473. size_t i = 0;
  5474. size_t n = buf_size;
  5475. if (c < 0x80)
  5476. {
  5477. if (i+1 > n) return 0;
  5478. buf[i++] = (char)c;
  5479. return 1;
  5480. }
  5481. else if (c < 0x800)
  5482. {
  5483. if (i+2 > n) return 0;
  5484. buf[i++] = (char)(0xc0 + (c >> 6));
  5485. buf[i++] = (char)(0x80 + (c & 0x3f));
  5486. return 2;
  5487. }
  5488. else if (c >= 0xdc00 && c < 0xe000)
  5489. {
  5490. return 0;
  5491. }
  5492. else if (c >= 0xd800 && c < 0xdc00)
  5493. {
  5494. if (i+4 > n) return 0;
  5495. buf[i++] = (char)(0xf0 + (c >> 18));
  5496. buf[i++] = (char)(0x80 + ((c >> 12) & 0x3f));
  5497. buf[i++] = (char)(0x80 + ((c >> 6) & 0x3f));
  5498. buf[i++] = (char)(0x80 + ((c ) & 0x3f));
  5499. return 4;
  5500. }
  5501. //else if (c < 0x10000)
  5502. {
  5503. if (i+3 > n) return 0;
  5504. buf[i++] = (char)(0xe0 + (c >> 12));
  5505. buf[i++] = (char)(0x80 + ((c>> 6) & 0x3f));
  5506. buf[i++] = (char)(0x80 + ((c ) & 0x3f));
  5507. return 3;
  5508. }
  5509. }
  5510. return 0;
  5511. }
  5512. static ptrdiff_t ImTextStrToUtf8(char* buf, size_t buf_size, const ImWchar* in_text, const ImWchar* in_text_end)
  5513. {
  5514. char* buf_out = buf;
  5515. const char* buf_end = buf + buf_size;
  5516. while (buf_out < buf_end-1 && (!in_text_end || in_text < in_text_end) && *in_text)
  5517. {
  5518. buf_out += ImTextCharToUtf8(buf_out, (uintptr_t)(buf_end-buf_out-1), (unsigned int)*in_text);
  5519. in_text++;
  5520. }
  5521. *buf_out = 0;
  5522. return buf_out - buf;
  5523. }
  5524. static int ImTextCountUtf8BytesFromWchar(const ImWchar* in_text, const ImWchar* in_text_end)
  5525. {
  5526. int bytes_count = 0;
  5527. while ((!in_text_end || in_text < in_text_end) && *in_text)
  5528. {
  5529. char dummy[5]; // FIXME-OPT
  5530. bytes_count += ImTextCharToUtf8(dummy, 5, (unsigned int)*in_text);
  5531. in_text++;
  5532. }
  5533. return bytes_count;
  5534. }
  5535. const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const
  5536. {
  5537. // Simple word-wrapping for English, not full-featured. Please submit failing cases!
  5538. // FIXME: Much possible improvements (don't cut things like "word !", "word!!!" but cut within "word,,,,", more sensible support for punctuations, support for Unicode punctuations, etc.)
  5539. // For references, possible wrap point marked with ^
  5540. // "aaa bbb, ccc,ddd. eee fff. ggg!"
  5541. // ^ ^ ^ ^ ^__ ^ ^
  5542. // List of hardcoded separators: .,;!?'"
  5543. // Skip extra blanks after a line returns (that includes not counting them in width computation)
  5544. // e.g. "Hello world"
  5545. // -->
  5546. // "Hello"
  5547. // "world"
  5548. // Cut words that cannot possibly fit within one line.
  5549. // e.g.: "The tropical fish" with ~5 characters worth of width
  5550. // -->
  5551. // "The tr"
  5552. // "opical"
  5553. // "fish"
  5554. float line_width = 0.0f;
  5555. float word_width = 0.0f;
  5556. float blank_width = 0.0f;
  5557. const char* word_end = text;
  5558. const char* prev_word_end = NULL;
  5559. bool inside_word = true;
  5560. const char* s = text;
  5561. while (s < text_end)
  5562. {
  5563. unsigned int c;
  5564. const int bytes_count = ImTextCharFromUtf8(&c, s, text_end);
  5565. const char* next_s = s + (bytes_count > 0 ? bytes_count : 1);
  5566. if (c == '\n')
  5567. {
  5568. line_width = word_width = blank_width = 0.0f;
  5569. inside_word = true;
  5570. s = next_s;
  5571. continue;
  5572. }
  5573. float char_width = 0.0f;
  5574. if (c == '\t')
  5575. {
  5576. if (const FntGlyph* glyph = FindGlyph((unsigned short)' '))
  5577. char_width = (glyph->XAdvance + Info->SpacingHoriz) * 4 * scale;
  5578. }
  5579. else
  5580. {
  5581. if (const FntGlyph* glyph = FindGlyph((unsigned short)c))
  5582. char_width = (glyph->XAdvance + Info->SpacingHoriz) * scale;
  5583. }
  5584. if (c == ' ' || c == '\t')
  5585. {
  5586. if (inside_word)
  5587. {
  5588. line_width += blank_width;
  5589. blank_width = 0.0f;
  5590. }
  5591. blank_width += char_width;
  5592. inside_word = false;
  5593. }
  5594. else
  5595. {
  5596. word_width += char_width;
  5597. if (inside_word)
  5598. {
  5599. word_end = next_s;
  5600. }
  5601. else
  5602. {
  5603. prev_word_end = word_end;
  5604. line_width += word_width + blank_width;
  5605. word_width = blank_width = 0.0f;
  5606. }
  5607. // Allow wrapping after punctuation.
  5608. inside_word = !(c == '.' || c == ',' || c == ';' || c == '!' || c == '?' || c == '\"');
  5609. }
  5610. // We ignore blank width at the end of the line (they can be skipped)
  5611. if (line_width + word_width >= wrap_width)
  5612. {
  5613. // Words that cannot possibly fit within an entire line will be cut anywhere.
  5614. if (word_width < wrap_width)
  5615. s = prev_word_end ? prev_word_end : word_end;
  5616. break;
  5617. }
  5618. s = next_s;
  5619. }
  5620. return s;
  5621. }
  5622. ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end, const char** remaining) const
  5623. {
  5624. if (!text_end)
  5625. text_end = text_begin + strlen(text_begin); // FIXME-OPT
  5626. const float scale = size / (float)Info->FontSize;
  5627. const float line_height = (float)Info->FontSize * scale;
  5628. ImVec2 text_size = ImVec2(0,0);
  5629. float line_width = 0.0f;
  5630. const bool word_wrap_enabled = (wrap_width > 0.0f);
  5631. const char* word_wrap_eol = NULL;
  5632. const char* s = text_begin;
  5633. while (s < text_end)
  5634. {
  5635. if (word_wrap_enabled)
  5636. {
  5637. // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature.
  5638. if (!word_wrap_eol)
  5639. {
  5640. word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - line_width);
  5641. if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
  5642. word_wrap_eol++; // +1 may not be a character start point in UTF-8 but it's ok because we use s >= word_wrap_eol below
  5643. }
  5644. if (s >= word_wrap_eol)
  5645. {
  5646. if (text_size.x < line_width)
  5647. text_size.x = line_width;
  5648. text_size.y += line_height;
  5649. line_width = 0.0f;
  5650. word_wrap_eol = NULL;
  5651. // Wrapping skips upcoming blanks
  5652. while (s < text_end)
  5653. {
  5654. const char c = *s;
  5655. if (c == ' ' || c == '\t') { s++; } else if (c == '\n') { s++; break; } else { break; }
  5656. }
  5657. continue;
  5658. }
  5659. }
  5660. // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
  5661. unsigned int c;
  5662. const int bytes_count = ImTextCharFromUtf8(&c, s, text_end);
  5663. s += bytes_count > 0 ? bytes_count : 1;
  5664. if (c == '\n')
  5665. {
  5666. if (text_size.x < line_width)
  5667. text_size.x = line_width;
  5668. text_size.y += line_height;
  5669. line_width = 0.0f;
  5670. continue;
  5671. }
  5672. float char_width = 0.0f;
  5673. if (c == '\t')
  5674. {
  5675. // FIXME: Better TAB handling
  5676. if (const FntGlyph* glyph = FindGlyph((unsigned short)' '))
  5677. char_width = (glyph->XAdvance + Info->SpacingHoriz) * 4 * scale;
  5678. }
  5679. else if (const FntGlyph* glyph = FindGlyph((unsigned short)c))
  5680. {
  5681. char_width = (glyph->XAdvance + Info->SpacingHoriz) * scale;
  5682. }
  5683. if (line_width + char_width >= max_width)
  5684. break;
  5685. line_width += char_width;
  5686. }
  5687. if (line_width > 0 || text_size.y == 0.0f)
  5688. {
  5689. if (text_size.x < line_width)
  5690. text_size.x = line_width;
  5691. text_size.y += line_height;
  5692. }
  5693. if (remaining)
  5694. *remaining = s;
  5695. return text_size;
  5696. }
  5697. ImVec2 ImFont::CalcTextSizeW(float size, float max_width, const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining) const
  5698. {
  5699. if (!text_end)
  5700. text_end = text_begin + ImStrlenW(text_begin);
  5701. const float scale = size / (float)Info->FontSize;
  5702. const float line_height = (float)Info->FontSize * scale;
  5703. ImVec2 text_size = ImVec2(0,0);
  5704. float line_width = 0.0f;
  5705. const ImWchar* s = text_begin;
  5706. while (s < text_end)
  5707. {
  5708. const unsigned int c = (unsigned int)(*s++);
  5709. if (c == '\n')
  5710. {
  5711. if (text_size.x < line_width)
  5712. text_size.x = line_width;
  5713. text_size.y += line_height;
  5714. line_width = 0.0f;
  5715. continue;
  5716. }
  5717. float char_width = 0.0f;
  5718. if (c == '\t')
  5719. {
  5720. // FIXME: Better TAB handling
  5721. if (const FntGlyph* glyph = FindGlyph((unsigned short)' '))
  5722. char_width = (glyph->XAdvance + Info->SpacingHoriz) * 4 * scale;
  5723. }
  5724. else
  5725. {
  5726. if (const FntGlyph* glyph = FindGlyph((unsigned short)c))
  5727. char_width = (glyph->XAdvance + Info->SpacingHoriz) * scale;
  5728. }
  5729. if (line_width + char_width >= max_width)
  5730. break;
  5731. line_width += char_width;
  5732. }
  5733. if (line_width > 0 || text_size.y == 0.0f)
  5734. {
  5735. if (text_size.x < line_width)
  5736. text_size.x = line_width;
  5737. text_size.y += line_height;
  5738. }
  5739. if (remaining)
  5740. *remaining = s;
  5741. return text_size;
  5742. }
  5743. void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect_ref, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices, float wrap_width) const
  5744. {
  5745. if (!text_end)
  5746. text_end = text_begin + strlen(text_begin);
  5747. const float scale = size / (float)Info->FontSize;
  5748. const float line_height = (float)Info->FontSize * scale;
  5749. const float tex_scale_x = 1.0f / (float)Common->ScaleW;
  5750. const float tex_scale_y = 1.0f / (float)Common->ScaleH;
  5751. const float outline = (float)Info->Outline;
  5752. // Align to be pixel perfect
  5753. pos.x = (float)(int)pos.x + DisplayOffset.x;
  5754. pos.y = (float)(int)pos.y + DisplayOffset.y;
  5755. const bool word_wrap_enabled = (wrap_width > 0.0f);
  5756. const char* word_wrap_eol = NULL;
  5757. const ImVec4 clip_rect = clip_rect_ref;
  5758. float x = pos.x;
  5759. float y = pos.y;
  5760. const char* s = text_begin;
  5761. while (s < text_end)
  5762. {
  5763. if (word_wrap_enabled)
  5764. {
  5765. // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature.
  5766. if (!word_wrap_eol)
  5767. {
  5768. word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - (x - pos.x));
  5769. if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
  5770. word_wrap_eol++; // +1 may not be a character start point in UTF-8 but it's ok because we use s >= word_wrap_eol below
  5771. }
  5772. if (s >= word_wrap_eol)
  5773. {
  5774. x = pos.x;
  5775. y += line_height;
  5776. word_wrap_eol = NULL;
  5777. // Wrapping skips upcoming blanks
  5778. while (s < text_end)
  5779. {
  5780. const char c = *s;
  5781. if (c == ' ' || c == '\t') { s++; } else if (c == '\n') { s++; break; } else { break; }
  5782. }
  5783. continue;
  5784. }
  5785. }
  5786. // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
  5787. unsigned int c;
  5788. const int bytes_count = ImTextCharFromUtf8(&c, s, text_end);
  5789. s += bytes_count > 0 ? bytes_count : 1;
  5790. if (c == '\n')
  5791. {
  5792. x = pos.x;
  5793. y += line_height;
  5794. continue;
  5795. }
  5796. float char_width = 0.0f;
  5797. if (c == '\t')
  5798. {
  5799. // FIXME: Better TAB handling
  5800. if (const FntGlyph* glyph = FindGlyph((unsigned short)' '))
  5801. char_width += (glyph->XAdvance + Info->SpacingHoriz) * 4 * scale;
  5802. }
  5803. else if (const FntGlyph* glyph = FindGlyph((unsigned short)c))
  5804. {
  5805. char_width = (glyph->XAdvance + Info->SpacingHoriz) * scale;
  5806. if (c != ' ')
  5807. {
  5808. // Clipping on Y is more likely
  5809. const float y1 = (float)(y + (glyph->YOffset + outline*2) * scale);
  5810. const float y2 = (float)(y1 + glyph->Height * scale);
  5811. if (y1 <= clip_rect.w && y2 >= clip_rect.y)
  5812. {
  5813. const float x1 = (float)(x + (glyph->XOffset + outline) * scale);
  5814. const float x2 = (float)(x1 + glyph->Width * scale);
  5815. if (x1 <= clip_rect.z && x2 >= clip_rect.x)
  5816. {
  5817. // Render a character
  5818. const float s1 = (glyph->X) * tex_scale_x;
  5819. const float t1 = (glyph->Y) * tex_scale_y;
  5820. const float s2 = (glyph->X + glyph->Width) * tex_scale_x;
  5821. const float t2 = (glyph->Y + glyph->Height) * tex_scale_y;
  5822. out_vertices[0].pos = ImVec2(x1, y1);
  5823. out_vertices[0].uv = ImVec2(s1, t1);
  5824. out_vertices[0].col = col;
  5825. out_vertices[1].pos = ImVec2(x2, y1);
  5826. out_vertices[1].uv = ImVec2(s2, t1);
  5827. out_vertices[1].col = col;
  5828. out_vertices[2].pos = ImVec2(x2, y2);
  5829. out_vertices[2].uv = ImVec2(s2, t2);
  5830. out_vertices[2].col = col;
  5831. out_vertices[3] = out_vertices[0];
  5832. out_vertices[4] = out_vertices[2];
  5833. out_vertices[5].pos = ImVec2(x1, y2);
  5834. out_vertices[5].uv = ImVec2(s1, t2);
  5835. out_vertices[5].col = col;
  5836. out_vertices += 6;
  5837. }
  5838. }
  5839. }
  5840. }
  5841. x += char_width;
  5842. }
  5843. }
  5844. //-----------------------------------------------------------------------------
  5845. // PLATFORM DEPENDANT HELPERS
  5846. //-----------------------------------------------------------------------------
  5847. #if defined(_MSC_VER) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS)
  5848. #define WIN32_LEAN_AND_MEAN
  5849. #include <windows.h>
  5850. // Win32 API clipboard implementation
  5851. static const char* GetClipboardTextFn_DefaultImpl()
  5852. {
  5853. static char* buf_local = NULL;
  5854. if (buf_local)
  5855. {
  5856. ImGui::MemFree(buf_local);
  5857. buf_local = NULL;
  5858. }
  5859. if (!OpenClipboard(NULL))
  5860. return NULL;
  5861. HANDLE buf_handle = GetClipboardData(CF_TEXT);
  5862. if (buf_handle == NULL)
  5863. return NULL;
  5864. if (char* buf_global = (char*)GlobalLock(buf_handle))
  5865. buf_local = ImStrdup(buf_global);
  5866. GlobalUnlock(buf_handle);
  5867. CloseClipboard();
  5868. return buf_local;
  5869. }
  5870. // Win32 API clipboard implementation
  5871. static void SetClipboardTextFn_DefaultImpl(const char* text)
  5872. {
  5873. if (!OpenClipboard(NULL))
  5874. return;
  5875. const char* text_end = text + strlen(text);
  5876. const int buf_length = (int)(text_end - text) + 1;
  5877. HGLOBAL buf_handle = GlobalAlloc(GMEM_MOVEABLE, (SIZE_T)buf_length * sizeof(char));
  5878. if (buf_handle == NULL)
  5879. return;
  5880. char* buf_global = (char *)GlobalLock(buf_handle);
  5881. memcpy(buf_global, text, (size_t)(text_end - text));
  5882. buf_global[text_end - text] = 0;
  5883. GlobalUnlock(buf_handle);
  5884. EmptyClipboard();
  5885. SetClipboardData(CF_TEXT, buf_handle);
  5886. CloseClipboard();
  5887. }
  5888. #else
  5889. // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
  5890. static const char* GetClipboardTextFn_DefaultImpl()
  5891. {
  5892. return GImGui.PrivateClipboard;
  5893. }
  5894. // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
  5895. static void SetClipboardTextFn_DefaultImpl(const char* text)
  5896. {
  5897. if (GImGui.PrivateClipboard)
  5898. {
  5899. ImGui::MemFree(GImGui.PrivateClipboard);
  5900. GImGui.PrivateClipboard = NULL;
  5901. }
  5902. const char* text_end = text + strlen(text);
  5903. GImGui.PrivateClipboard = (char*)ImGui::MemAlloc((size_t)(text_end - text) + 1);
  5904. memcpy(GImGui.PrivateClipboard, text, (size_t)(text_end - text));
  5905. GImGui.PrivateClipboard[(size_t)(text_end - text)] = 0;
  5906. }
  5907. #endif
  5908. //-----------------------------------------------------------------------------
  5909. // HELP
  5910. //-----------------------------------------------------------------------------
  5911. void ImGui::ShowUserGuide()
  5912. {
  5913. ImGuiState& g = GImGui;
  5914. ImGui::BulletText("Double-click on title bar to collapse window.");
  5915. ImGui::BulletText("Click and drag on lower right corner to resize window.");
  5916. ImGui::BulletText("Click and drag on any empty space to move window.");
  5917. ImGui::BulletText("Mouse Wheel to scroll.");
  5918. if (g.IO.FontAllowUserScaling)
  5919. ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents.");
  5920. ImGui::BulletText("TAB/SHIFT+TAB to cycle through keyboard editable fields.");
  5921. ImGui::BulletText("CTRL+Click on a slider to input text.");
  5922. ImGui::BulletText(
  5923. "While editing text:\n"
  5924. "- Hold SHIFT or use mouse to select text\n"
  5925. "- CTRL+Left/Right to word jump\n"
  5926. "- CTRL+A select all\n"
  5927. "- CTRL+X,CTRL+C,CTRL+V clipboard\n"
  5928. "- CTRL+Z,CTRL+Y undo/redo\n"
  5929. "- ESCAPE to revert\n"
  5930. "- You can apply arithmetic operators +,*,/ on numerical values.\n"
  5931. " Use +- to subtract.\n");
  5932. }
  5933. void ImGui::ShowStyleEditor(ImGuiStyle* ref)
  5934. {
  5935. ImGuiState& g = GImGui;
  5936. ImGuiStyle& style = g.Style;
  5937. const ImGuiStyle def; // Default style
  5938. if (ImGui::Button("Revert Style"))
  5939. g.Style = ref ? *ref : def;
  5940. if (ref)
  5941. {
  5942. ImGui::SameLine();
  5943. if (ImGui::Button("Save Style"))
  5944. *ref = g.Style;
  5945. }
  5946. ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.55f);
  5947. if (ImGui::TreeNode("Sizes"))
  5948. {
  5949. ImGui::SliderFloat("Alpha", &style.Alpha, 0.20f, 1.0f, "%.2f"); // Not exposing zero here so user doesn't "lose" the UI. But application code could have a toggle to switch between zero and non-zero.
  5950. ImGui::SliderFloat2("WindowPadding", (float*)&style.WindowPadding, 0.0f, 20.0f, "%.0f");
  5951. ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 16.0f, "%.0f");
  5952. ImGui::SliderFloat2("FramePadding", (float*)&style.FramePadding, 0.0f, 20.0f, "%.0f");
  5953. ImGui::SliderFloat2("ItemSpacing", (float*)&style.ItemSpacing, 0.0f, 20.0f, "%.0f");
  5954. ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f");
  5955. ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 10.0f, "%.0f");
  5956. ImGui::SliderFloat("TreeNodeSpacing", &style.TreeNodeSpacing, 0.0f, 20.0f, "%.0f");
  5957. ImGui::SliderFloat("ScrollBarWidth", &style.ScrollBarWidth, 0.0f, 20.0f, "%.0f");
  5958. ImGui::TreePop();
  5959. }
  5960. if (ImGui::TreeNode("Colors"))
  5961. {
  5962. static int output_dest = 0;
  5963. static bool output_only_modified = false;
  5964. if (ImGui::Button("Output Colors"))
  5965. {
  5966. if (output_dest == 0)
  5967. ImGui::LogToClipboard();
  5968. else
  5969. ImGui::LogToTTY();
  5970. ImGui::LogText("ImGuiStyle& style = ImGui::GetStyle();" STR_NEWLINE);
  5971. for (int i = 0; i < ImGuiCol_COUNT; i++)
  5972. {
  5973. const ImVec4& col = style.Colors[i];
  5974. const char* name = ImGui::GetStyleColName(i);
  5975. if (!output_only_modified || memcmp(&col, (ref ? &ref->Colors[i] : &def.Colors[i]), sizeof(ImVec4)) != 0)
  5976. ImGui::LogText("style.Colors[ImGuiCol_%s]%*s= ImVec4(%.2ff, %.2ff, %.2ff, %.2ff);" STR_NEWLINE, name, 22 - strlen(name), "", col.x, col.y, col.z, col.w);
  5977. }
  5978. ImGui::LogFinish();
  5979. }
  5980. ImGui::SameLine(); ImGui::PushItemWidth(150); ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY"); ImGui::PopItemWidth();
  5981. ImGui::SameLine(); ImGui::Checkbox("Only Modified Fields", &output_only_modified);
  5982. static ImGuiColorEditMode edit_mode = ImGuiColorEditMode_RGB;
  5983. ImGui::RadioButton("RGB", &edit_mode, ImGuiColorEditMode_RGB);
  5984. ImGui::SameLine();
  5985. ImGui::RadioButton("HSV", &edit_mode, ImGuiColorEditMode_HSV);
  5986. ImGui::SameLine();
  5987. ImGui::RadioButton("HEX", &edit_mode, ImGuiColorEditMode_HEX);
  5988. static ImGuiTextFilter filter;
  5989. filter.Draw("Filter colors", 200);
  5990. ImGui::BeginChild("#colors", ImVec2(0, 300), true);
  5991. ImGui::ColorEditMode(edit_mode);
  5992. for (int i = 0; i < ImGuiCol_COUNT; i++)
  5993. {
  5994. const char* name = ImGui::GetStyleColName(i);
  5995. if (!filter.PassFilter(name))
  5996. continue;
  5997. ImGui::PushID(i);
  5998. ImGui::ColorEdit4(name, (float*)&style.Colors[i], true);
  5999. if (memcmp(&style.Colors[i], (ref ? &ref->Colors[i] : &def.Colors[i]), sizeof(ImVec4)) != 0)
  6000. {
  6001. ImGui::SameLine(); if (ImGui::Button("Revert")) style.Colors[i] = ref ? ref->Colors[i] : def.Colors[i];
  6002. if (ref) { ImGui::SameLine(); if (ImGui::Button("Save")) ref->Colors[i] = style.Colors[i]; }
  6003. }
  6004. ImGui::PopID();
  6005. }
  6006. ImGui::EndChild();
  6007. ImGui::TreePop();
  6008. }
  6009. /*
  6010. // Font scaling options
  6011. // Note that those are not actually part of the style.
  6012. if (ImGui::TreeNode("Font"))
  6013. {
  6014. static float window_scale = 1.0f;
  6015. ImGui::SliderFloat("window scale", &window_scale, 0.3f, 2.0f, "%.1f"); // scale only this window
  6016. ImGui::SliderFloat("font scale", &ImGui::GetIO().Font->Scale, 0.3f, 2.0f, "%.1f"); // scale only this font
  6017. ImGui::SliderFloat("global scale", &ImGui::GetIO().FontGlobalScale, 0.3f, 2.0f, "%.1f"); // scale everything
  6018. ImGui::SetWindowFontScale(window_scale);
  6019. ImGui::TreePop();
  6020. }
  6021. */
  6022. ImGui::PopItemWidth();
  6023. }
  6024. //-----------------------------------------------------------------------------
  6025. // SAMPLE CODE
  6026. //-----------------------------------------------------------------------------
  6027. static void ShowExampleAppConsole(bool* opened);
  6028. static void ShowExampleAppLongText(bool* opened);
  6029. static void ShowExampleAppAutoResize(bool* opened);
  6030. static void ShowExampleAppFixedOverlay(bool* opened);
  6031. // Demonstrate ImGui features (unfortunately this makes this function a little bloated!)
  6032. void ImGui::ShowTestWindow(bool* opened)
  6033. {
  6034. static bool no_titlebar = false;
  6035. static bool no_border = true;
  6036. static bool no_resize = false;
  6037. static bool no_move = false;
  6038. static bool no_scrollbar = false;
  6039. static float fill_alpha = 0.65f;
  6040. const ImGuiWindowFlags layout_flags = (no_titlebar ? ImGuiWindowFlags_NoTitleBar : 0) | (no_border ? 0 : ImGuiWindowFlags_ShowBorders) | (no_resize ? ImGuiWindowFlags_NoResize : 0) | (no_move ? ImGuiWindowFlags_NoMove : 0) | (no_scrollbar ? ImGuiWindowFlags_NoScrollbar : 0);
  6041. ImGui::Begin("ImGui Test", opened, ImVec2(550,680), fill_alpha, layout_flags);
  6042. ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f);
  6043. ImGui::Text("ImGui says hello.");
  6044. //ImGui::Text("MousePos (%g, %g)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
  6045. //ImGui::Text("MouseWheel %d", ImGui::GetIO().MouseWheel);
  6046. ImGui::Spacing();
  6047. if (ImGui::CollapsingHeader("Help"))
  6048. {
  6049. ImGui::TextWrapped("This window is being created by the ShowTestWindow() function. Please refer to the code for programming reference.\n\nUser Guide:");
  6050. ImGui::ShowUserGuide();
  6051. }
  6052. if (ImGui::CollapsingHeader("Window options"))
  6053. {
  6054. ImGui::Checkbox("no titlebar", &no_titlebar); ImGui::SameLine(150);
  6055. ImGui::Checkbox("no border", &no_border); ImGui::SameLine(300);
  6056. ImGui::Checkbox("no resize", &no_resize);
  6057. ImGui::Checkbox("no move", &no_move); ImGui::SameLine(150);
  6058. ImGui::Checkbox("no scrollbar", &no_scrollbar);
  6059. ImGui::SliderFloat("fill alpha", &fill_alpha, 0.0f, 1.0f);
  6060. if (ImGui::TreeNode("Style Editor"))
  6061. {
  6062. ImGui::ShowStyleEditor();
  6063. ImGui::TreePop();
  6064. }
  6065. if (ImGui::TreeNode("Logging"))
  6066. {
  6067. ImGui::LogButtons();
  6068. ImGui::TreePop();
  6069. }
  6070. }
  6071. if (ImGui::CollapsingHeader("Widgets"))
  6072. {
  6073. static bool a=false;
  6074. if (ImGui::Button("Button")) { printf("Clicked\n"); a ^= 1; }
  6075. if (a)
  6076. {
  6077. ImGui::SameLine();
  6078. ImGui::Text("Thanks for clicking me!");
  6079. }
  6080. if (ImGui::TreeNode("Tree"))
  6081. {
  6082. for (size_t i = 0; i < 5; i++)
  6083. {
  6084. if (ImGui::TreeNode((void*)i, "Child %d", i))
  6085. {
  6086. ImGui::Text("blah blah");
  6087. ImGui::SameLine();
  6088. if (ImGui::SmallButton("print"))
  6089. printf("Child %d pressed", (int)i);
  6090. ImGui::TreePop();
  6091. }
  6092. }
  6093. ImGui::TreePop();
  6094. }
  6095. if (ImGui::TreeNode("Bullets"))
  6096. {
  6097. ImGui::BulletText("Bullet point 1");
  6098. ImGui::BulletText("Bullet point 2\nOn multiple lines");
  6099. ImGui::BulletText("Bullet point 3");
  6100. ImGui::TreePop();
  6101. }
  6102. if (ImGui::TreeNode("Colored Text"))
  6103. {
  6104. // Using shortcut. You can use PushStyleColor()/PopStyleColor() for more flexibility.
  6105. ImGui::TextColored(ImVec4(1.0f,0.0f,1.0f,1.0f), "Pink");
  6106. ImGui::TextColored(ImVec4(1.0f,1.0f,0.0f,1.0f), "Yellow");
  6107. ImGui::TreePop();
  6108. }
  6109. if (ImGui::TreeNode("Word Wrapping"))
  6110. {
  6111. // Using shortcut. You can use PushTextWrapPos()/PopTextWrapPos() for more flexibility.
  6112. ImGui::TextWrapped("This is a long paragraph. The text should automatically wrap on the edge of the window. The current implementation follows simple rules that works for English and possibly other languages.");
  6113. ImGui::Spacing();
  6114. static float wrap_width = 200.0f;
  6115. ImGui::SliderFloat("Wrap width", &wrap_width, -20, 600, "%.0f");
  6116. ImGui::Text("Test paragraph 1:");
  6117. ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetCursorScreenPos() + ImVec2(wrap_width, 0.0f), ImGui::GetCursorScreenPos() + ImVec2(wrap_width+10, ImGui::GetTextLineHeight()), 0xFFFF00FF);
  6118. ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width);
  6119. ImGui::Text("lazy dog. This paragraph is made to fit within %.0f pixels. The quick brown fox jumps over the lazy dog.", wrap_width);
  6120. ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemBoxMin(), ImGui::GetItemBoxMax(), 0xFF00FFFF);
  6121. ImGui::PopTextWrapPos();
  6122. ImGui::Text("Test paragraph 2:");
  6123. ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetCursorScreenPos() + ImVec2(wrap_width, 0.0f), ImGui::GetCursorScreenPos() + ImVec2(wrap_width+10, ImGui::GetTextLineHeight()), 0xFFFF00FF);
  6124. ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width);
  6125. ImGui::Text("aaaaaaaa bbbbbbbb, cccccccc,dddddddd. eeeeeeee ffffffff. gggggggg!hhhhhhhh");
  6126. ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemBoxMin(), ImGui::GetItemBoxMax(), 0xFF00FFFF);
  6127. ImGui::PopTextWrapPos();
  6128. ImGui::TreePop();
  6129. }
  6130. if (ImGui::TreeNode("UTF-8 Text"))
  6131. {
  6132. // UTF-8 test (need a suitable font, try extra_fonts/mplus* files for example)
  6133. // Most compiler appears to support UTF-8 in source code (with Visual Studio you need to save your file as 'UTF-8 without signature')
  6134. // However for the sake for maximum portability here we are *not* including raw UTF-8 character in this source file, instead we encode the string with hexadecimal constants.
  6135. // In your own application please be reasonable and use UTF-8 in the source or get the data from external files! :)
  6136. ImGui::TextWrapped("(CJK text will only appears if the font supports it. Please check in the extra_fonts/ folder if you intend to use non-ASCII characters. Note that characters values are preserved even if the font cannot be displayed, so you can safely copy & paste garbled characters.)");
  6137. ImGui::Text("Hiragana: \xe3\x81\x8b\xe3\x81\x8d\xe3\x81\x8f\xe3\x81\x91\xe3\x81\x93 (kakikukeko)");
  6138. ImGui::Text("Kanjis: \xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e (nihongo)");
  6139. static char buf[32] = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e";
  6140. ImGui::InputText("UTF-8 input", buf, IM_ARRAYSIZE(buf));
  6141. ImGui::TreePop();
  6142. }
  6143. static bool check = true;
  6144. ImGui::Checkbox("checkbox", &check);
  6145. static int e = 0;
  6146. ImGui::RadioButton("radio a", &e, 0); ImGui::SameLine();
  6147. ImGui::RadioButton("radio b", &e, 1); ImGui::SameLine();
  6148. ImGui::RadioButton("radio c", &e, 2);
  6149. ImGui::Text("Hover me");
  6150. if (ImGui::IsItemHovered())
  6151. ImGui::SetTooltip("I am a tooltip");
  6152. ImGui::SameLine();
  6153. ImGui::Text("- or me");
  6154. if (ImGui::IsItemHovered())
  6155. {
  6156. ImGui::BeginTooltip();
  6157. ImGui::Text("I am a fancy tooltip");
  6158. static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
  6159. ImGui::PlotLines("Curve", arr, IM_ARRAYSIZE(arr));
  6160. ImGui::EndTooltip();
  6161. }
  6162. // Testing IMGUI_ONCE_UPON_A_FRAME macro
  6163. //for (int i = 0; i < 5; i++)
  6164. //{
  6165. // IMGUI_ONCE_UPON_A_FRAME
  6166. // {
  6167. // ImGui::Text("This will be displayed only once.");
  6168. // }
  6169. //}
  6170. ImGui::Separator();
  6171. static int item = 1;
  6172. ImGui::Combo("combo", &item, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0");
  6173. const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK" };
  6174. static int item2 = -1;
  6175. ImGui::Combo("combo scroll", &item2, items, IM_ARRAYSIZE(items));
  6176. static char str0[128] = "Hello, world!";
  6177. static int i0=123;
  6178. static float f0=0.001f;
  6179. ImGui::InputText("string", str0, IM_ARRAYSIZE(str0));
  6180. ImGui::InputInt("input int", &i0);
  6181. ImGui::InputFloat("input float", &f0, 0.01f, 1.0f);
  6182. static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f };
  6183. //ImGui::InputFloat2("input float2", vec4a);
  6184. ImGui::InputFloat3("input float3", vec4a);
  6185. //ImGui::InputFloat4("input float4", vec4a);
  6186. static int i1=0;
  6187. static int i2=42;
  6188. ImGui::SliderInt("int 0..3", &i1, 0, 3);
  6189. ImGui::SliderInt("int -100..100", &i2, -100, 100);
  6190. static float f1=1.123f;
  6191. static float f2=0;
  6192. static float f3=0;
  6193. static float f4=123456789.0f;
  6194. ImGui::SliderFloat("float", &f1, 0.0f, 2.0f);
  6195. ImGui::SliderFloat("log float", &f2, 0.0f, 10.0f, "%.4f", 2.0f);
  6196. ImGui::SliderFloat("signed log float", &f3, -10.0f, 10.0f, "%.4f", 3.0f);
  6197. ImGui::SliderFloat("unbound float", &f4, -FLT_MAX, FLT_MAX, "%.4f");
  6198. static float angle = 0.0f;
  6199. ImGui::SliderAngle("angle", &angle);
  6200. static float vec4b[4] = { 0.10f, 0.20f, 0.30f, 0.40f };
  6201. //ImGui::SliderFloat2("slider float2", vec4b, 0.0f, 1.0f);
  6202. ImGui::SliderFloat3("slider float3", vec4b, 0.0f, 1.0f);
  6203. //ImGui::SliderFloat4("slider float4", vec4b, 0.0f, 1.0f);
  6204. //static int vec4i[4] = { 1, 5, 100, 255 };
  6205. //ImGui::SliderInt2("slider int2", vec4i, 0, 255);
  6206. //ImGui::SliderInt3("slider int3", vec4i, 0, 255);
  6207. //ImGui::SliderInt4("slider int4", vec4i, 0, 255);
  6208. static float col1[3] = { 1.0f,0.0f,0.2f };
  6209. static float col2[4] = { 0.4f,0.7f,0.0f,0.5f };
  6210. ImGui::ColorEdit3("color 1", col1);
  6211. ImGui::ColorEdit4("color 2", col2);
  6212. }
  6213. if (ImGui::CollapsingHeader("Graphs widgets"))
  6214. {
  6215. static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
  6216. ImGui::PlotLines("Frame Times", arr, IM_ARRAYSIZE(arr));
  6217. static bool pause;
  6218. static ImVector<float> values; if (values.empty()) { values.resize(100); memset(&values.front(), 0, values.size()*sizeof(float)); }
  6219. static size_t values_offset = 0;
  6220. if (!pause)
  6221. {
  6222. // create dummy data at fixed 60 hz rate
  6223. static float refresh_time = -1.0f;
  6224. if (ImGui::GetTime() > refresh_time + 1.0f/60.0f)
  6225. {
  6226. refresh_time = ImGui::GetTime();
  6227. static float phase = 0.0f;
  6228. values[values_offset] = cosf(phase);
  6229. values_offset = (values_offset+1)%values.size();
  6230. phase += 0.10f*values_offset;
  6231. }
  6232. }
  6233. ImGui::PlotLines("Frame Times", &values.front(), (int)values.size(), (int)values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,70));
  6234. ImGui::SameLine(); ImGui::Checkbox("pause", &pause);
  6235. ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,70));
  6236. }
  6237. if (ImGui::CollapsingHeader("Horizontal Layout"))
  6238. {
  6239. // Text
  6240. ImGui::Text("Hello");
  6241. ImGui::SameLine();
  6242. ImGui::Text("World");
  6243. // Button
  6244. if (ImGui::Button("Banana")) printf("Pressed!\n");
  6245. ImGui::SameLine();
  6246. ImGui::Button("Apple");
  6247. ImGui::SameLine();
  6248. ImGui::Button("Corniflower");
  6249. // Button
  6250. ImGui::Text("Small buttons");
  6251. ImGui::SameLine();
  6252. ImGui::SmallButton("Like this one");
  6253. ImGui::SameLine();
  6254. ImGui::Text("can fit within a text block.");
  6255. // Checkbox
  6256. static bool c1=false,c2=false,c3=false,c4=false;
  6257. ImGui::Checkbox("My", &c1);
  6258. ImGui::SameLine();
  6259. ImGui::Checkbox("Tailor", &c2);
  6260. ImGui::SameLine();
  6261. ImGui::Checkbox("Is", &c3);
  6262. ImGui::SameLine();
  6263. ImGui::Checkbox("Rich", &c4);
  6264. // SliderFloat
  6265. static float f0=1.0f, f1=2.0f, f2=3.0f;
  6266. ImGui::PushItemWidth(80);
  6267. ImGui::SliderFloat("X", &f0, 0.0f,5.0f);
  6268. ImGui::SameLine();
  6269. ImGui::SliderFloat("Y", &f1, 0.0f,5.0f);
  6270. ImGui::SameLine();
  6271. ImGui::SliderFloat("Z", &f2, 0.0f,5.0f);
  6272. }
  6273. if (ImGui::CollapsingHeader("Child regions"))
  6274. {
  6275. ImGui::Text("Without border");
  6276. static int line = 50;
  6277. bool goto_line = ImGui::Button("Goto");
  6278. ImGui::SameLine();
  6279. ImGui::PushItemWidth(100);
  6280. goto_line |= ImGui::InputInt("##Line", &line, 0, 0, ImGuiInputTextFlags_EnterReturnsTrue);
  6281. ImGui::PopItemWidth();
  6282. ImGui::BeginChild("Sub1", ImVec2(ImGui::GetWindowWidth() * 0.5f,300));
  6283. for (int i = 0; i < 100; i++)
  6284. {
  6285. ImGui::Text("%04d: scrollable region", i);
  6286. if (goto_line && line == i)
  6287. ImGui::SetScrollPosHere();
  6288. }
  6289. if (goto_line && line >= 100)
  6290. ImGui::SetScrollPosHere();
  6291. ImGui::EndChild();
  6292. ImGui::SameLine();
  6293. ImGui::BeginChild("Sub2", ImVec2(0,300), true);
  6294. ImGui::Text("With border");
  6295. ImGui::Columns(2);
  6296. for (int i = 0; i < 100; i++)
  6297. {
  6298. char buf[32];
  6299. ImFormatString(buf, IM_ARRAYSIZE(buf), "%08x", i*5731);
  6300. ImGui::Button(buf);
  6301. ImGui::NextColumn();
  6302. }
  6303. ImGui::EndChild();
  6304. }
  6305. if (ImGui::CollapsingHeader("Columns"))
  6306. {
  6307. ImGui::Columns(4, "data", true);
  6308. ImGui::Text("ID"); ImGui::NextColumn();
  6309. ImGui::Text("Name"); ImGui::NextColumn();
  6310. ImGui::Text("Path"); ImGui::NextColumn();
  6311. ImGui::Text("Flags"); ImGui::NextColumn();
  6312. ImGui::Separator();
  6313. ImGui::Text("0000"); ImGui::NextColumn();
  6314. ImGui::Text("Robert"); ImGui::NextColumn();
  6315. ImGui::Text("/path/robert"); ImGui::NextColumn();
  6316. ImGui::Text("...."); ImGui::NextColumn();
  6317. ImGui::Text("0001"); ImGui::NextColumn();
  6318. ImGui::Text("Stephanie"); ImGui::NextColumn();
  6319. ImGui::Text("/path/stephanie"); ImGui::NextColumn();
  6320. ImGui::Text("line 1"); ImGui::Text("line 2"); ImGui::NextColumn(); // two lines, two items
  6321. ImGui::Text("0002"); ImGui::NextColumn();
  6322. ImGui::Text("C64"); ImGui::NextColumn();
  6323. ImGui::Text("/path/computer"); ImGui::NextColumn();
  6324. ImGui::Text("...."); ImGui::NextColumn();
  6325. ImGui::Columns(1);
  6326. ImGui::Separator();
  6327. ImGui::Columns(3, "mixed");
  6328. // Create multiple items in a same cell because switching to next column
  6329. static int e = 0;
  6330. ImGui::Text("Hello");
  6331. ImGui::Button("Banana");
  6332. ImGui::RadioButton("radio a", &e, 0);
  6333. ImGui::NextColumn();
  6334. ImGui::Text("ImGui");
  6335. ImGui::Button("Apple");
  6336. ImGui::RadioButton("radio b", &e, 1);
  6337. ImGui::Text("An extra line here.");
  6338. ImGui::NextColumn();
  6339. ImGui::Text("World!");
  6340. ImGui::Button("Corniflower");
  6341. ImGui::RadioButton("radio c", &e, 2);
  6342. ImGui::NextColumn();
  6343. if (ImGui::CollapsingHeader("Category A")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  6344. if (ImGui::CollapsingHeader("Category B")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  6345. if (ImGui::CollapsingHeader("Category C")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  6346. ImGui::Columns(1);
  6347. ImGui::Separator();
  6348. ImGui::Columns(2, "multiple components");
  6349. static float foo = 1.0f;
  6350. ImGui::InputFloat("red", &foo, 0.05f, 0, 3); ImGui::NextColumn();
  6351. static float bar = 1.0f;
  6352. ImGui::InputFloat("blue", &bar, 0.05f, 0, 3); ImGui::NextColumn();
  6353. ImGui::Columns(1);
  6354. ImGui::Separator();
  6355. ImGui::Columns(2, "word wrapping");
  6356. ImGui::TextWrapped("The quick brown fox jumps over the lazy dog.");
  6357. ImGui::Text("Hello Left");
  6358. ImGui::NextColumn();
  6359. ImGui::TextWrapped("The quick brown fox jumps over the lazy dog.");
  6360. ImGui::Text("Hello Right");
  6361. ImGui::Columns(1);
  6362. ImGui::Separator();
  6363. if (ImGui::TreeNode("Inside a tree.."))
  6364. {
  6365. if (ImGui::TreeNode("node 1 (with borders)"))
  6366. {
  6367. ImGui::Columns(4);
  6368. ImGui::Text("aaa"); ImGui::NextColumn();
  6369. ImGui::Text("bbb"); ImGui::NextColumn();
  6370. ImGui::Text("ccc"); ImGui::NextColumn();
  6371. ImGui::Text("ddd"); ImGui::NextColumn();
  6372. ImGui::Text("eee"); ImGui::NextColumn();
  6373. ImGui::Text("fff"); ImGui::NextColumn();
  6374. ImGui::Text("ggg"); ImGui::NextColumn();
  6375. ImGui::Text("hhh"); ImGui::NextColumn();
  6376. ImGui::Columns(1);
  6377. ImGui::TreePop();
  6378. }
  6379. if (ImGui::TreeNode("node 2 (without borders)"))
  6380. {
  6381. ImGui::Columns(4, NULL, false);
  6382. ImGui::Text("aaa"); ImGui::NextColumn();
  6383. ImGui::Text("bbb"); ImGui::NextColumn();
  6384. ImGui::Text("ccc"); ImGui::NextColumn();
  6385. ImGui::Text("ddd"); ImGui::NextColumn();
  6386. ImGui::Text("eee"); ImGui::NextColumn();
  6387. ImGui::Text("fff"); ImGui::NextColumn();
  6388. ImGui::Text("ggg"); ImGui::NextColumn();
  6389. ImGui::Text("hhh"); ImGui::NextColumn();
  6390. ImGui::Columns(1);
  6391. ImGui::TreePop();
  6392. }
  6393. ImGui::TreePop();
  6394. }
  6395. }
  6396. if (ImGui::CollapsingHeader("Filtering"))
  6397. {
  6398. static ImGuiTextFilter filter;
  6399. ImGui::Text("Filter usage:\n"
  6400. " \"\" display all lines\n"
  6401. " \"xxx\" display lines containing \"xxx\"\n"
  6402. " \"xxx,yyy\" display lines containing \"xxx\" or \"yyy\"\n"
  6403. " \"-xxx\" hide lines containing \"xxx\"");
  6404. filter.Draw();
  6405. const char* lines[] = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" };
  6406. for (size_t i = 0; i < IM_ARRAYSIZE(lines); i++)
  6407. if (filter.PassFilter(lines[i]))
  6408. ImGui::BulletText("%s", lines[i]);
  6409. }
  6410. if (ImGui::CollapsingHeader("Keyboard & Focus"))
  6411. {
  6412. if (ImGui::TreeNode("Tabbing"))
  6413. {
  6414. ImGui::Text("Use TAB/SHIFT+TAB to cycle thru keyboard editable fields.");
  6415. static char buf[32] = "dummy";
  6416. ImGui::InputText("1", buf, IM_ARRAYSIZE(buf));
  6417. ImGui::InputText("2", buf, IM_ARRAYSIZE(buf));
  6418. ImGui::InputText("3", buf, IM_ARRAYSIZE(buf));
  6419. ImGui::PushAllowKeyboardFocus(false);
  6420. ImGui::InputText("4 (tab skip)", buf, IM_ARRAYSIZE(buf));
  6421. //ImGui::SameLine(); ImGui::Text("(?)"); if (ImGui::IsHovered()) ImGui::SetTooltip("Use ImGui::PushAllowKeyboardFocus(bool)\nto disable tabbing through certain widgets.");
  6422. ImGui::PopAllowKeyboardFocus();
  6423. ImGui::InputText("5", buf, IM_ARRAYSIZE(buf));
  6424. ImGui::TreePop();
  6425. }
  6426. if (ImGui::TreeNode("Focus from code"))
  6427. {
  6428. bool focus_1 = ImGui::Button("Focus on 1"); ImGui::SameLine();
  6429. bool focus_2 = ImGui::Button("Focus on 2"); ImGui::SameLine();
  6430. bool focus_3 = ImGui::Button("Focus on 3");
  6431. int has_focus = 0;
  6432. static char buf[128] = "click on a button to set focus";
  6433. if (focus_1) ImGui::SetKeyboardFocusHere();
  6434. ImGui::InputText("1", buf, IM_ARRAYSIZE(buf));
  6435. if (ImGui::IsItemFocused()) has_focus = 1;
  6436. if (focus_2) ImGui::SetKeyboardFocusHere();
  6437. ImGui::InputText("2", buf, IM_ARRAYSIZE(buf));
  6438. if (ImGui::IsItemFocused()) has_focus = 2;
  6439. ImGui::PushAllowKeyboardFocus(false);
  6440. if (focus_3) ImGui::SetKeyboardFocusHere();
  6441. ImGui::InputText("3 (tab skip)", buf, IM_ARRAYSIZE(buf));
  6442. if (ImGui::IsItemFocused()) has_focus = 3;
  6443. ImGui::PopAllowKeyboardFocus();
  6444. if (has_focus)
  6445. ImGui::Text("Item with focus: %d", has_focus);
  6446. else
  6447. ImGui::Text("Item with focus: <none>");
  6448. ImGui::TreePop();
  6449. }
  6450. }
  6451. static bool show_app_console = false;
  6452. static bool show_app_long_text = false;
  6453. static bool show_app_auto_resize = false;
  6454. static bool show_app_fixed_overlay = false;
  6455. if (ImGui::CollapsingHeader("App Examples"))
  6456. {
  6457. ImGui::Checkbox("Console", &show_app_console);
  6458. ImGui::Checkbox("Long text display", &show_app_long_text);
  6459. ImGui::Checkbox("Auto-resizing window", &show_app_auto_resize);
  6460. ImGui::Checkbox("Simple overlay", &show_app_fixed_overlay);
  6461. }
  6462. if (show_app_console)
  6463. ShowExampleAppConsole(&show_app_console);
  6464. if (show_app_long_text)
  6465. ShowExampleAppLongText(&show_app_long_text);
  6466. if (show_app_auto_resize)
  6467. ShowExampleAppAutoResize(&show_app_auto_resize);
  6468. if (show_app_fixed_overlay)
  6469. ShowExampleAppFixedOverlay(&show_app_fixed_overlay);
  6470. ImGui::End();
  6471. }
  6472. static void ShowExampleAppAutoResize(bool* opened)
  6473. {
  6474. if (!ImGui::Begin("Example: Auto-Resizing Window", opened, ImVec2(0,0), -1.0f, ImGuiWindowFlags_AlwaysAutoResize))
  6475. {
  6476. ImGui::End();
  6477. return;
  6478. }
  6479. static int lines = 10;
  6480. ImGui::TextWrapped("Window will resize every-frame to the size of its content. Note that you don't want to query the window size to output your content because that would create a feedback loop.");
  6481. ImGui::SliderInt("Number of lines", &lines, 1, 20);
  6482. for (int i = 0; i < lines; i++)
  6483. ImGui::Text("%*sThis is line %d", i*4, "", i); // Pad with space to extend size horizontally
  6484. ImGui::End();
  6485. }
  6486. static void ShowExampleAppFixedOverlay(bool* opened)
  6487. {
  6488. if (!ImGui::Begin("Example: Fixed Overlay", opened, ImVec2(0,0), 0.3f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoSavedSettings))
  6489. {
  6490. ImGui::End();
  6491. return;
  6492. }
  6493. ImGui::SetWindowPos(ImVec2(10,10));
  6494. ImGui::Text("Simple overlay\non the top-left side of the screen.");
  6495. ImGui::Separator();
  6496. ImGui::Text("Mouse Position: (%.1f,%.1f)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
  6497. ImGui::End();
  6498. }
  6499. struct ExampleAppConsole
  6500. {
  6501. char InputBuf[256];
  6502. ImVector<char*> Items;
  6503. bool ScrollToBottom;
  6504. ImVector<char*> History;
  6505. int HistoryPos; // -1: new line, 0..History.size()-1 browsing history.
  6506. ImVector<const char*> Commands;
  6507. ExampleAppConsole()
  6508. {
  6509. ClearLog();
  6510. HistoryPos = -1;
  6511. Commands.push_back("HELP");
  6512. Commands.push_back("HISTORY");
  6513. Commands.push_back("CLEAR");
  6514. Commands.push_back("CLASSIFY"); // "classify" is here to provide an example of "C"+[tab] completing to "CL" and displaying matches.
  6515. }
  6516. ~ExampleAppConsole()
  6517. {
  6518. ClearLog();
  6519. for (size_t i = 0; i < Items.size(); i++)
  6520. ImGui::MemFree(History[i]);
  6521. }
  6522. void ClearLog()
  6523. {
  6524. for (size_t i = 0; i < Items.size(); i++)
  6525. ImGui::MemFree(Items[i]);
  6526. Items.clear();
  6527. ScrollToBottom = true;
  6528. }
  6529. void AddLog(const char* fmt, ...)
  6530. {
  6531. char buf[1024];
  6532. va_list args;
  6533. va_start(args, fmt);
  6534. ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  6535. va_end(args);
  6536. Items.push_back(ImStrdup(buf));
  6537. ScrollToBottom = true;
  6538. }
  6539. void Run(const char* title, bool* opened)
  6540. {
  6541. if (!ImGui::Begin(title, opened, ImVec2(520,600)))
  6542. {
  6543. ImGui::End();
  6544. return;
  6545. }
  6546. ImGui::TextWrapped("This example implement a console with basic coloring, completion and history. A more elaborate implementation may want to store entries along with extra data such as timestamp, emitter, etc.");
  6547. ImGui::TextWrapped("Enter 'HELP' for help, press TAB to use text completion.");
  6548. // TODO: display from bottom
  6549. // TODO: clip manually
  6550. if (ImGui::SmallButton("Add Dummy Text")) AddLog("some text\nsome more text\ndisplay very important message here!\n"); ImGui::SameLine();
  6551. if (ImGui::SmallButton("Add Dummy Error")) AddLog("[error] something went wrong"); ImGui::SameLine();
  6552. if (ImGui::SmallButton("Clear")) ClearLog();
  6553. ImGui::Separator();
  6554. ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0));
  6555. static ImGuiTextFilter filter;
  6556. filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180);
  6557. if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover
  6558. ImGui::PopStyleVar();
  6559. ImGui::Separator();
  6560. // Display every line as a separate entry so we can change their color or add custom widgets. If you only want raw text you can use ImGui::TextUnformatted(log.begin(), log.end());
  6561. // NB- if you have lots of text this approach may be too inefficient. You can seek and display only the lines that are on display using a technique similar to what TextUnformatted() does,
  6562. // or faster if your entries are already stored into a table.
  6563. ImGui::BeginChild("ScrollingRegion", ImVec2(0,-ImGui::GetTextLineSpacing()*2));
  6564. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4,1)); // Tighten spacing
  6565. for (size_t i = 0; i < Items.size(); i++)
  6566. {
  6567. const char* item = Items[i];
  6568. if (!filter.PassFilter(item))
  6569. continue;
  6570. ImVec4 col(1,1,1,1); // A better implement may store a type per-item. For the sample let's just parse the text.
  6571. if (strstr(item, "[error]")) col = ImVec4(1.0f,0.4f,0.4f,1.0f);
  6572. else if (strncmp(item, "# ", 2) == 0) col = ImVec4(1.0f,0.8f,0.6f,1.0f);
  6573. ImGui::PushStyleColor(ImGuiCol_Text, col);
  6574. ImGui::TextUnformatted(item);
  6575. ImGui::PopStyleColor();
  6576. }
  6577. if (ScrollToBottom)
  6578. ImGui::SetScrollPosHere();
  6579. ScrollToBottom = false;
  6580. ImGui::PopStyleVar();
  6581. ImGui::EndChild();
  6582. ImGui::Separator();
  6583. // Command-line
  6584. if (ImGui::InputText("Input", InputBuf, IM_ARRAYSIZE(InputBuf), ImGuiInputTextFlags_EnterReturnsTrue|ImGuiInputTextFlags_CallbackCompletion|ImGuiInputTextFlags_CallbackHistory, &TextEditCallbackStub, (void*)this))
  6585. {
  6586. char* input_end = InputBuf+strlen(InputBuf);
  6587. while (input_end > InputBuf && input_end[-1] == ' ') input_end--; *input_end = 0;
  6588. if (InputBuf[0])
  6589. ExecCommand(InputBuf);
  6590. strcpy(InputBuf, "");
  6591. }
  6592. if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover
  6593. ImGui::End();
  6594. }
  6595. void ExecCommand(const char* command_line)
  6596. {
  6597. AddLog("# %s\n", command_line);
  6598. // Insert into history. First find match and delete it so it can be pushed to the back. This isn't trying to be smart or optimal.
  6599. HistoryPos = -1;
  6600. for (int i = (int)History.size()-1; i >= 0; i--)
  6601. if (ImStricmp(History[i], command_line) == 0)
  6602. {
  6603. ImGui::MemFree(History[i]);
  6604. History.erase(History.begin() + i);
  6605. break;
  6606. }
  6607. History.push_back(ImStrdup(command_line));
  6608. // Process command
  6609. if (ImStricmp(command_line, "CLEAR") == 0)
  6610. {
  6611. ClearLog();
  6612. }
  6613. else if (ImStricmp(command_line, "HELP") == 0)
  6614. {
  6615. AddLog("Commands:");
  6616. for (size_t i = 0; i < Commands.size(); i++)
  6617. AddLog("- %s", Commands[i]);
  6618. }
  6619. else if (ImStricmp(command_line, "HISTORY") == 0)
  6620. {
  6621. for (size_t i = History.size() >= 10 ? History.size() - 10 : 0; i < History.size(); i++)
  6622. AddLog("%3d: %s\n", i, History[i]);
  6623. }
  6624. else
  6625. {
  6626. AddLog("Unknown command: '%s'\n", command_line);
  6627. }
  6628. }
  6629. static void TextEditCallbackStub(ImGuiTextEditCallbackData* data)
  6630. {
  6631. ExampleAppConsole* console = (ExampleAppConsole*)data->UserData;
  6632. console->TextEditCallback(data);
  6633. }
  6634. void TextEditCallback(ImGuiTextEditCallbackData* data)
  6635. {
  6636. //AddLog("cursor: %d, selection: %d-%d", data->CursorPos, data->SelectionStart, data->SelectionEnd);
  6637. switch (data->EventKey)
  6638. {
  6639. case ImGuiKey_Tab:
  6640. {
  6641. // Example of TEXT COMPLETION
  6642. // Locate beginning of current word
  6643. const char* word_end = data->Buf + data->CursorPos;
  6644. const char* word_start = word_end;
  6645. while (word_start > data->Buf)
  6646. {
  6647. const char c = word_start[-1];
  6648. if (c == ' ' || c == '\t' || c == ',' || c == ';')
  6649. break;
  6650. word_start--;
  6651. }
  6652. // Build a list of candidates
  6653. ImVector<const char*> candidates;
  6654. for (size_t i = 0; i < Commands.size(); i++)
  6655. if (ImStrnicmp(Commands[i], word_start, (int)(word_end-word_start)) == 0)
  6656. candidates.push_back(Commands[i]);
  6657. if (candidates.size() == 0)
  6658. {
  6659. // No match
  6660. AddLog("No match for \"%.*s\"!\n", word_end-word_start, word_start);
  6661. }
  6662. else if (candidates.size() == 1)
  6663. {
  6664. // Single match. Delete the beginning of the word and replace it entirely so we've got nice casing
  6665. data->DeleteChars((int)(word_start-data->Buf), (int)(word_end-word_start));
  6666. data->InsertChars(data->CursorPos, candidates[0]);
  6667. data->InsertChars(data->CursorPos, " ");
  6668. }
  6669. else
  6670. {
  6671. // Multiple matches. Complete as much as we can, so inputing "C" will complete to "CL" and display "CLEAR" and "CLASSIFY"
  6672. int match_len = (int)(word_end - word_start);
  6673. while (true)
  6674. {
  6675. int c = 0;
  6676. bool all_candidates_matches = true;
  6677. for (size_t i = 0; i < candidates.size() && all_candidates_matches; i++)
  6678. if (i == 0)
  6679. c = toupper(candidates[i][match_len]);
  6680. else if (c != toupper(candidates[i][match_len]))
  6681. all_candidates_matches = false;
  6682. if (!all_candidates_matches)
  6683. break;
  6684. match_len++;
  6685. }
  6686. if (match_len > 0)
  6687. {
  6688. data->DeleteChars((int)(word_start - data->Buf), (int)(word_end-word_start));
  6689. data->InsertChars(data->CursorPos, candidates[0], candidates[0] + match_len);
  6690. }
  6691. // List matches
  6692. AddLog("Possible matches:\n");
  6693. for (size_t i = 0; i < candidates.size(); i++)
  6694. AddLog("- %s\n", candidates[i]);
  6695. }
  6696. break;
  6697. }
  6698. case ImGuiKey_UpArrow:
  6699. case ImGuiKey_DownArrow:
  6700. {
  6701. // Example of HISTORY
  6702. const int prev_history_pos = HistoryPos;
  6703. if (data->EventKey == ImGuiKey_UpArrow)
  6704. {
  6705. if (HistoryPos == -1)
  6706. HistoryPos = History.size() - 1;
  6707. else if (HistoryPos > 0)
  6708. HistoryPos--;
  6709. }
  6710. else if (data->EventKey == ImGuiKey_DownArrow)
  6711. {
  6712. if (HistoryPos != -1)
  6713. if (++HistoryPos >= (int)History.size())
  6714. HistoryPos = -1;
  6715. }
  6716. // A better implementation would preserve the data on the current input line along with cursor position.
  6717. if (prev_history_pos != HistoryPos)
  6718. {
  6719. ImFormatString(data->Buf, data->BufSize, "%s", (HistoryPos >= 0) ? History[HistoryPos] : "");
  6720. data->BufDirty = true;
  6721. data->CursorPos = data->SelectionStart = data->SelectionEnd = strlen(data->Buf);
  6722. }
  6723. }
  6724. }
  6725. }
  6726. };
  6727. static void ShowExampleAppConsole(bool* opened)
  6728. {
  6729. static ExampleAppConsole console;
  6730. console.Run("Example: Console", opened);
  6731. }
  6732. static void ShowExampleAppLongText(bool* opened)
  6733. {
  6734. if (!ImGui::Begin("Example: Long text display", opened, ImVec2(520,600)))
  6735. {
  6736. ImGui::End();
  6737. return;
  6738. }
  6739. static ImGuiTextBuffer log;
  6740. static int lines = 0;
  6741. ImGui::Text("Printing unusually long amount of text.");
  6742. ImGui::Text("Buffer contents: %d lines, %d bytes", lines, log.size());
  6743. if (ImGui::Button("Clear")) { log.clear(); lines = 0; }
  6744. ImGui::SameLine();
  6745. if (ImGui::Button("Add 1000 lines"))
  6746. {
  6747. for (int i = 0; i < 1000; i++)
  6748. log.append("%i The quick brown fox jumps over the lazy dog\n", lines+i);
  6749. lines += 1000;
  6750. }
  6751. ImGui::BeginChild("Log");
  6752. ImGui::TextUnformatted(log.begin(), log.end());
  6753. ImGui::EndChild();
  6754. ImGui::End();
  6755. }
  6756. // End of Sample code
  6757. //-----------------------------------------------------------------------------
  6758. // Font data
  6759. // Bitmap exported from proggy_clean.fon (c) by Tristan Grimmer http://upperbounds.net/
  6760. // Also available on unofficial ProggyFonts mirror http://www.proggyfonts.net
  6761. //-----------------------------------------------------------------------------
  6762. /*
  6763. // Copyright (c) 2004, 2005 Tristan Grimmer
  6764. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6765. // of this software and associated documentation files (the "Software"), to deal
  6766. // in the Software without restriction, including without limitation the rights
  6767. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  6768. // copies of the Software, and to permit persons to whom the Software is
  6769. // furnished to do so, subject to the following conditions:
  6770. // The above copyright notice and this permission notice shall be included in all
  6771. // copies or substantial portions of the Software.
  6772. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  6773. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  6774. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  6775. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  6776. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  6777. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  6778. // SOFTWARE.
  6779. */
  6780. //-----------------------------------------------------------------------------
  6781. // Fonts exported with BMFont http://www.angelcode.com/products/bmfont
  6782. // We are using bmfont format and you can load your own font from a file by setting up ImGui::GetIO().Font
  6783. // PNG further compressed with pngout.exe http://advsys.net/ken/utils.htm
  6784. // Manually converted to C++ array using the following program:
  6785. /*
  6786. #include <stdio.h>
  6787. static void binary_to_c(const char* name_in, const char* symbol)
  6788. {
  6789. FILE* fi = fopen(name_in, "rb"); fseek(fi, 0, SEEK_END); long sz = ftell(fi); fseek(fi, 0, SEEK_SET);
  6790. fprintf(stdout, "static const unsigned int %s_size = %d;\n", symbol, sz);
  6791. fprintf(stdout, "static const unsigned int %s_data[%d/4] =\n{", symbol, ((sz+3)/4)*4);
  6792. int column = 0;
  6793. for (unsigned int data = 0; fread(&data, 1, 4, fi); data = 0)
  6794. if ((column++ % 12) == 0)
  6795. fprintf(stdout, "\n 0x%08x, ", data);
  6796. else
  6797. fprintf(stdout, "0x%08x, ", data);
  6798. fprintf(stdout, "\n};\n\n");
  6799. fclose(fi);
  6800. }
  6801. int main(int argc, char** argv)
  6802. {
  6803. binary_to_c("proggy_clean_13.png", "proggy_clean_13_png");
  6804. binary_to_c("proggy_clean_13.fnt", "proggy_clean_13_fnt");
  6805. return 1;
  6806. }
  6807. */
  6808. //-----------------------------------------------------------------------------
  6809. static const unsigned int proggy_clean_13_png_size = 1557;
  6810. static const unsigned int proggy_clean_13_png_data[1560/4] =
  6811. {
  6812. 0x474e5089, 0x0a1a0a0d, 0x0d000000, 0x52444849, 0x00010000, 0x80000000, 0x00000308, 0x476bd300, 0x00000038, 0x544c5006, 0x00000045, 0xa5ffffff,
  6813. 0x00dd9fd9, 0x74010000, 0x00534e52, 0x66d8e640, 0xbd050000, 0x54414449, 0x9bed5e78, 0x30e36e51, 0xeef5440c, 0x31fde97f, 0x584ec0f0, 0x681ace39,
  6814. 0xca120e6b, 0x1c5a28a6, 0xc5d98a89, 0x1a3d602e, 0x323c0043, 0xf6bc9e68, 0xbe3ad62c, 0x3d60260f, 0x82d60096, 0xe0bfc707, 0xfb9bf1d1, 0xbf0267ac,
  6815. 0x1600260f, 0x061229c0, 0x0000c183, 0x37162c58, 0xdfa088fc, 0xde7d5704, 0x77fcbb80, 0x48e5c3f1, 0x73d8b8f8, 0xc4af7802, 0x1ca111ad, 0x0001ed7a,
  6816. 0x76eda3ef, 0xb78d3e00, 0x801c7203, 0x0215c0b1, 0x0410b044, 0xa85100d4, 0x07627ec7, 0x0cf83fa8, 0x94001a22, 0xf87347f1, 0xdcb5cfc1, 0x1c3880cc,
  6817. 0xd4e034ca, 0xfa928d9d, 0xb0167e31, 0x325cc570, 0x4bbd584b, 0xbd4e6574, 0x70bae084, 0xf0c0008a, 0x3f601ddb, 0x0bba506a, 0xa58a0082, 0x5b46946e,
  6818. 0x720a4ccd, 0xdfaaed39, 0x25dc8042, 0x7ee403f4, 0x2ad69cc9, 0x6c4b3009, 0x429037ed, 0x0293f875, 0x1a69dced, 0xab120198, 0x61c01d88, 0xcf2e43dc,
  6819. 0xfc3c00ef, 0xc049a270, 0xdbbea582, 0x0d592601, 0xc3c9a8dd, 0x5013d143, 0x19a47bbb, 0xf89253dd, 0x0a9901dc, 0x38900ecd, 0xb2dec9d7, 0xc2b91230,
  6820. 0xb8e0106f, 0x976404cb, 0x5d83c3f3, 0x6e8086fd, 0x5c9ab007, 0xf50354f6, 0xe7e72002, 0x4bc870ca, 0xab49736f, 0xc137c6e0, 0xa9aa6ff3, 0xbff84f2f,
  6821. 0x673e6e20, 0xf6e3c7e0, 0x618fe05a, 0x39ca2a00, 0x93ca03b4, 0x3a9d2728, 0xbbebba41, 0xce0e3681, 0x6e29ec05, 0x111eca83, 0xfdfe7ec1, 0xa7c8a75b,
  6822. 0xac6bc3ab, 0x72a5bc25, 0x9f612c1c, 0x378ec05e, 0x7202b157, 0x789e5a82, 0x5256bc0e, 0xcb900996, 0x10721105, 0x00823ce0, 0x69ab59fb, 0x39c72084,
  6823. 0xf5e37b25, 0xd1794700, 0x538d0637, 0x9a2bff4f, 0xce0d43a4, 0xa6da7ed2, 0xd7095132, 0xf5ad6232, 0x9aaa8e9c, 0xd8d1d3ed, 0x058940a1, 0x21f00d64,
  6824. 0x89a5c9de, 0x021b3f24, 0x77a97aac, 0x714be65a, 0x5e2d57ae, 0x27e3610f, 0x28809288, 0x36b9559f, 0xd00e347a, 0x0094e385, 0x565d034d, 0x7f52d5f2,
  6825. 0x9aea81de, 0x5e804909, 0x010d7f0a, 0x8f0d3fb1, 0xbbce23bc, 0x375e85ac, 0x01fa03b9, 0xc0526c3a, 0xf7866870, 0x9d46d804, 0x158ebf64, 0x7bd534c5,
  6826. 0xd80cf202, 0x410ee80f, 0x79419915, 0x74a844ae, 0x94119881, 0xcbbcc0fc, 0xa263d471, 0x013d0269, 0x67f6a0f8, 0x3e4474d0, 0xd1e50cb5, 0x56fd0e60,
  6827. 0xc4c0fd4c, 0x940629ff, 0xe18a7a16, 0xcca0330f, 0xb8ed50b7, 0x6935778b, 0x3735c791, 0x3909eb94, 0x0be36620, 0x0ac0d7aa, 0xefe942c9, 0xf0092727,
  6828. 0x5c020ee2, 0x0246da53, 0xa24be8bc, 0xa891ab94, 0xd012c7e2, 0x9c115954, 0xde0dac8e, 0x555dc022, 0x59e84f77, 0xbed2cf80, 0xe9af2cda, 0x4b600716,
  6829. 0x8955bd80, 0x7098c3f3, 0x25a8466a, 0x4ddbf26a, 0x5f554753, 0xf4890f28, 0x886a27ab, 0x54a00413, 0x0a157ca9, 0x52909a80, 0x7122a312, 0x0024a75c,
  6830. 0xe6d72935, 0xecde29cf, 0x025de009, 0x7995a6aa, 0x4a180491, 0x013df0d8, 0xe009edba, 0xd40019dc, 0x45b36b2a, 0x0122eb0d, 0x6e80a79f, 0x746590f5,
  6831. 0xd1a6dd49, 0xc05954b6, 0x83d4b957, 0xa00fe5b1, 0x59695ad7, 0xcff8433d, 0x44a0f340, 0xdd226c73, 0x5537f08c, 0xe1e89c32, 0x431056af, 0x233eb000,
  6832. 0x60773f40, 0xed7e490a, 0xc160091f, 0x12829db5, 0x43fbe6cf, 0x0a6b26c2, 0xd5f0f35a, 0xfc09fda8, 0x73525f8c, 0x2ea38cf9, 0x32bc410b, 0x94a60a22,
  6833. 0x1f62a42b, 0x5f290034, 0x07beaa91, 0x1e8ccb40, 0x17d6b0f9, 0xa2a017c9, 0x4c79a610, 0xa1de6525, 0xe975029f, 0xe063585f, 0x6246cfbb, 0x04acad44,
  6834. 0xe6a05138, 0xd03d8434, 0xc9950013, 0x5d4c809e, 0xfd26932d, 0x739213ac, 0xe260d8ef, 0xe4164617, 0x16fc60aa, 0x1d0b21e7, 0x445004b4, 0x13fd1b59,
  6835. 0x56b0f804, 0xaa936a3a, 0x335459c1, 0xb37f8caa, 0x06b68e03, 0x14d5eb01, 0x8300c78c, 0x9674792a, 0x20ba791b, 0x4d88024d, 0xef747354, 0x451e673e,
  6836. 0xc4dafc9a, 0xe53b9cd1, 0x32b4011a, 0x3d702c0f, 0x09bc0b40, 0x220d277d, 0x47eb7809, 0x8a946500, 0x7a28c4bd, 0x96e00f99, 0xc04365da, 0x05edcf46,
  6837. 0x7dee2c27, 0xe6020b7f, 0x159ecedf, 0xcbdb00ff, 0x516bb9e3, 0xd0716161, 0xeba75956, 0xf17fc22b, 0x5c578beb, 0xfe474a09, 0xc1750a87, 0xe384c189,
  6838. 0x5df54e26, 0xa6f76b79, 0xd4b172be, 0x3e8d5ceb, 0x832d90ec, 0x180368e7, 0x354c724d, 0x1a8b1412, 0x8de07be9, 0xaf009efe, 0x4616c621, 0x2860eb01,
  6839. 0x244f1404, 0xc3de724b, 0x6497a802, 0xab2f4419, 0x4e02910d, 0xe3ecf410, 0x7a6404a8, 0x8c72b112, 0xde5bc706, 0xd4f8ffe9, 0x50176344, 0x7b49fe7d,
  6840. 0x02c1d88c, 0x25634a40, 0x194804f7, 0x03b76d84, 0x392bde58, 0xdeebad27, 0xc160c021, 0xa97a72db, 0xa8040b83, 0x78804f3e, 0x046b9433, 0x178cc824,
  6841. 0x62800897, 0x7010370b, 0x21cfe7e4, 0x8053ec40, 0xf9d60526, 0xae9d353f, 0x069b40c7, 0x80496f14, 0x57e682b3, 0x6e0273e0, 0x974e2e28, 0x60ab7c3d,
  6842. 0x2025ba33, 0x507b3a8c, 0x12b70173, 0xd095c400, 0xee012d96, 0x6e194c9a, 0xe5933f89, 0x43b70102, 0xf30306aa, 0xc5802189, 0x53c077c3, 0x86029009,
  6843. 0xa0c1e780, 0xa4c04c1f, 0x93dbd580, 0xf8149809, 0x06021893, 0x3060c183, 0x83060c18, 0x183060c1, 0xc183060c, 0x0c183060, 0x60c18306, 0xfe0c1830,
  6844. 0x0cb69501, 0x7a40d9df, 0x000000dd, 0x4e454900, 0x6042ae44, 0x00000082,
  6845. };
  6846. static const unsigned int proggy_clean_13_fnt_size = 4647;
  6847. static const unsigned int proggy_clean_13_fnt_data[4648/4] =
  6848. {
  6849. 0x03464d42, 0x00001a01, 0x40000d00, 0x01006400, 0x00000000, 0x50000101, 0x67676f72, 0x656c4379, 0x02006e61, 0x0000000f, 0x000a000d, 0x00800100,
  6850. 0x01000001, 0x03000000, 0x00000016, 0x676f7270, 0x635f7967, 0x6e61656c, 0x5f33315f, 0x6e702e30, 0xd0040067, 0x00000011, 0x2e000000, 0x07000e00,
  6851. 0x00000d00, 0x07000000, 0x010f0000, 0x36000000, 0x05003800, 0x01000d00, 0x07000000, 0x020f0000, 0x86000000, 0x07000e00, 0x00000d00, 0x07000000,
  6852. 0x030f0000, 0x07000000, 0x06001c00, 0x01000d00, 0x07000000, 0x040f0000, 0x15000000, 0x06001c00, 0x01000d00, 0x07000000, 0x050f0000, 0x23000000,
  6853. 0x06001c00, 0x01000d00, 0x07000000, 0x060f0000, 0x31000000, 0x06001c00, 0x01000d00, 0x07000000, 0x070f0000, 0xfc000000, 0x03003800, 0x02000d00,
  6854. 0x07000000, 0x080f0000, 0x54000000, 0x05003800, 0x01000d00, 0x07000000, 0x090f0000, 0x4d000000, 0x06001c00, 0x01000d00, 0x07000000, 0x0a0f0000,
  6855. 0xa8000000, 0x06001c00, 0x01000d00, 0x07000000, 0x0b0f0000, 0x6a000000, 0x04004600, 0x00000d00, 0x07000000, 0x0c0f0000, 0x74000000, 0x04004600,
  6856. 0x00000d00, 0x07000000, 0x0d0f0000, 0x88000000, 0x04004600, 0x03000d00, 0x07000000, 0x0e0f0000, 0x65000000, 0x04004600, 0x03000d00, 0x07000000,
  6857. 0x0f0f0000, 0x36000000, 0x07000e00, 0x00000d00, 0x07000000, 0x100f0000, 0x5a000000, 0x05003800, 0x00000d00, 0x07000000, 0x110f0000, 0x60000000,
  6858. 0x05003800, 0x00000d00, 0x07000000, 0x120f0000, 0xe4000000, 0x03004600, 0x01000d00, 0x07000000, 0x130f0000, 0xe0000000, 0x03004600, 0x01000d00,
  6859. 0x07000000, 0x140f0000, 0x66000000, 0x05003800, 0x00000d00, 0x07000000, 0x150f0000, 0x6c000000, 0x05003800, 0x00000d00, 0x07000000, 0x160f0000,
  6860. 0x72000000, 0x05003800, 0x00000d00, 0x07000000, 0x170f0000, 0xd8000000, 0x03004600, 0x00000d00, 0x07000000, 0x180f0000, 0xcc000000, 0x03004600,
  6861. 0x01000d00, 0x07000000, 0x190f0000, 0xc8000000, 0x03004600, 0x02000d00, 0x07000000, 0x1a0f0000, 0x78000000, 0x05003800, 0x00000d00, 0x07000000,
  6862. 0x1b0f0000, 0x84000000, 0x05003800, 0x00000d00, 0x07000000, 0x1c0f0000, 0x00000000, 0x15000000, 0xf9000d00, 0x070000ff, 0x1d0f0000, 0xb0000000,
  6863. 0x15000000, 0xf9000d00, 0x070000ff, 0x1e0f0000, 0x2c000000, 0x15000000, 0xf9000d00, 0x070000ff, 0x200f0000, 0x9a000000, 0x15000000, 0xf9000d00,
  6864. 0x070000ff, 0x210f0000, 0x0c000000, 0x01005400, 0x03000d00, 0x07000000, 0x220f0000, 0xbc000000, 0x03004600, 0x02000d00, 0x07000000, 0x230f0000,
  6865. 0x4e000000, 0x07000e00, 0x00000d00, 0x07000000, 0x240f0000, 0x8a000000, 0x05003800, 0x01000d00, 0x07000000, 0x250f0000, 0xa6000000, 0x07000e00,
  6866. 0x00000d00, 0x07000000, 0x260f0000, 0xf4000000, 0x06000e00, 0x01000d00, 0x07000000, 0x270f0000, 0x06000000, 0x01005400, 0x03000d00, 0x07000000,
  6867. 0x280f0000, 0xb8000000, 0x03004600, 0x02000d00, 0x07000000, 0x290f0000, 0xb4000000, 0x03004600, 0x02000d00, 0x07000000, 0x2a0f0000, 0x90000000,
  6868. 0x05003800, 0x01000d00, 0x07000000, 0x2b0f0000, 0x96000000, 0x05003800, 0x01000d00, 0x07000000, 0x2c0f0000, 0xe8000000, 0x02004600, 0x01000d00,
  6869. 0x07000000, 0x2d0f0000, 0x9c000000, 0x05003800, 0x01000d00, 0x07000000, 0x2e0f0000, 0x04000000, 0x01005400, 0x02000d00, 0x07000000, 0x2f0f0000,
  6870. 0xa2000000, 0x05003800, 0x01000d00, 0x07000000, 0x300f0000, 0xae000000, 0x05003800, 0x01000d00, 0x07000000, 0x310f0000, 0xd8000000, 0x05003800,
  6871. 0x01000d00, 0x07000000, 0x320f0000, 0xfa000000, 0x05000000, 0x01000d00, 0x07000000, 0x330f0000, 0x31000000, 0x05002a00, 0x01000d00, 0x07000000,
  6872. 0x340f0000, 0x3f000000, 0x06001c00, 0x01000d00, 0x07000000, 0x350f0000, 0x37000000, 0x05002a00, 0x01000d00, 0x07000000, 0x360f0000, 0x3d000000,
  6873. 0x05002a00, 0x01000d00, 0x07000000, 0x370f0000, 0x43000000, 0x05002a00, 0x01000d00, 0x07000000, 0x380f0000, 0x49000000, 0x05002a00, 0x01000d00,
  6874. 0x07000000, 0x390f0000, 0x4f000000, 0x05002a00, 0x01000d00, 0x07000000, 0x3a0f0000, 0x02000000, 0x01005400, 0x03000d00, 0x07000000, 0x3b0f0000,
  6875. 0xfa000000, 0x02004600, 0x01000d00, 0x07000000, 0x3c0f0000, 0x77000000, 0x06001c00, 0x00000d00, 0x07000000, 0x3d0f0000, 0x7e000000, 0x06001c00,
  6876. 0x01000d00, 0x07000000, 0x3e0f0000, 0x85000000, 0x06001c00, 0x01000d00, 0x07000000, 0x3f0f0000, 0x55000000, 0x05002a00, 0x01000d00, 0x07000000,
  6877. 0x400f0000, 0xae000000, 0x07000e00, 0x00000d00, 0x07000000, 0x410f0000, 0xe0000000, 0x06001c00, 0x01000d00, 0x07000000, 0x420f0000, 0xa1000000,
  6878. 0x06001c00, 0x01000d00, 0x07000000, 0x430f0000, 0x5b000000, 0x05002a00, 0x01000d00, 0x07000000, 0x440f0000, 0xaf000000, 0x06001c00, 0x01000d00,
  6879. 0x07000000, 0x450f0000, 0x61000000, 0x05002a00, 0x01000d00, 0x07000000, 0x460f0000, 0x67000000, 0x05002a00, 0x01000d00, 0x07000000, 0x470f0000,
  6880. 0x38000000, 0x06001c00, 0x01000d00, 0x07000000, 0x480f0000, 0x8c000000, 0x06001c00, 0x01000d00, 0x07000000, 0x490f0000, 0xa0000000, 0x03004600,
  6881. 0x02000d00, 0x07000000, 0x4a0f0000, 0x97000000, 0x04004600, 0x01000d00, 0x07000000, 0x4b0f0000, 0xb6000000, 0x06001c00, 0x01000d00, 0x07000000,
  6882. 0x4c0f0000, 0x6d000000, 0x05002a00, 0x01000d00, 0x07000000, 0x4d0f0000, 0x1e000000, 0x07000e00, 0x00000d00, 0x07000000, 0x4e0f0000, 0x23000000,
  6883. 0x06002a00, 0x01000d00, 0x07000000, 0x4f0f0000, 0xed000000, 0x06000e00, 0x01000d00, 0x07000000, 0x500f0000, 0x73000000, 0x05002a00, 0x01000d00,
  6884. 0x07000000, 0x510f0000, 0x00000000, 0x06001c00, 0x01000d00, 0x07000000, 0x520f0000, 0x0e000000, 0x06001c00, 0x01000d00, 0x07000000, 0x530f0000,
  6885. 0x1c000000, 0x06001c00, 0x01000d00, 0x07000000, 0x540f0000, 0x66000000, 0x07000e00, 0x00000d00, 0x07000000, 0x550f0000, 0x2a000000, 0x06001c00,
  6886. 0x01000d00, 0x07000000, 0x560f0000, 0x6e000000, 0x07000e00, 0x00000d00, 0x07000000, 0x570f0000, 0x76000000, 0x07000e00, 0x00000d00, 0x07000000,
  6887. 0x580f0000, 0x46000000, 0x06001c00, 0x01000d00, 0x07000000, 0x590f0000, 0x7e000000, 0x07000e00, 0x00000d00, 0x07000000, 0x5a0f0000, 0x54000000,
  6888. 0x06001c00, 0x01000d00, 0x07000000, 0x5b0f0000, 0x9c000000, 0x03004600, 0x02000d00, 0x07000000, 0x5c0f0000, 0x79000000, 0x05002a00, 0x01000d00,
  6889. 0x07000000, 0x5d0f0000, 0xdc000000, 0x03004600, 0x02000d00, 0x07000000, 0x5e0f0000, 0x7f000000, 0x05002a00, 0x01000d00, 0x07000000, 0x5f0f0000,
  6890. 0xc6000000, 0x07000e00, 0x00000d00, 0x07000000, 0x600f0000, 0xfd000000, 0x02004600, 0x02000d00, 0x07000000, 0x610f0000, 0x85000000, 0x05002a00,
  6891. 0x01000d00, 0x07000000, 0x620f0000, 0x8b000000, 0x05002a00, 0x01000d00, 0x07000000, 0x630f0000, 0x91000000, 0x05002a00, 0x01000d00, 0x07000000,
  6892. 0x640f0000, 0x97000000, 0x05002a00, 0x01000d00, 0x07000000, 0x650f0000, 0x9d000000, 0x05002a00, 0x01000d00, 0x07000000, 0x660f0000, 0xa3000000,
  6893. 0x05002a00, 0x01000d00, 0x07000000, 0x670f0000, 0xa9000000, 0x05002a00, 0x01000d00, 0x07000000, 0x680f0000, 0xaf000000, 0x05002a00, 0x01000d00,
  6894. 0x07000000, 0x690f0000, 0xee000000, 0x02004600, 0x02000d00, 0x07000000, 0x6a0f0000, 0x92000000, 0x04004600, 0x01000d00, 0x07000000, 0x6b0f0000,
  6895. 0xb5000000, 0x05002a00, 0x01000d00, 0x07000000, 0x6c0f0000, 0xfd000000, 0x02002a00, 0x02000d00, 0x07000000, 0x6d0f0000, 0x8e000000, 0x07000e00,
  6896. 0x00000d00, 0x07000000, 0x6e0f0000, 0xbb000000, 0x05002a00, 0x01000d00, 0x07000000, 0x6f0f0000, 0xc1000000, 0x05002a00, 0x01000d00, 0x07000000,
  6897. 0x700f0000, 0xc7000000, 0x05002a00, 0x01000d00, 0x07000000, 0x710f0000, 0xcd000000, 0x05002a00, 0x01000d00, 0x07000000, 0x720f0000, 0xd3000000,
  6898. 0x05002a00, 0x01000d00, 0x07000000, 0x730f0000, 0xd9000000, 0x05002a00, 0x01000d00, 0x07000000, 0x740f0000, 0x7e000000, 0x04004600, 0x02000d00,
  6899. 0x07000000, 0x750f0000, 0xdf000000, 0x05002a00, 0x01000d00, 0x07000000, 0x760f0000, 0xe5000000, 0x05002a00, 0x01000d00, 0x07000000, 0x770f0000,
  6900. 0xbe000000, 0x07000e00, 0x00000d00, 0x07000000, 0x780f0000, 0xeb000000, 0x05002a00, 0x01000d00, 0x07000000, 0x790f0000, 0xf1000000, 0x05002a00,
  6901. 0x01000d00, 0x07000000, 0x7a0f0000, 0xf7000000, 0x05002a00, 0x01000d00, 0x07000000, 0x7b0f0000, 0x00000000, 0x05003800, 0x01000d00, 0x07000000,
  6902. 0x7c0f0000, 0x00000000, 0x01005400, 0x03000d00, 0x07000000, 0x7d0f0000, 0x06000000, 0x05003800, 0x01000d00, 0x07000000, 0x7e0f0000, 0x16000000,
  6903. 0x07000e00, 0x00000d00, 0x07000000, 0x7f0f0000, 0x58000000, 0x15000000, 0xf9000d00, 0x070000ff, 0x810f0000, 0x16000000, 0x15000000, 0xf9000d00,
  6904. 0x070000ff, 0x8d0f0000, 0x00000000, 0x15000e00, 0xf9000d00, 0x070000ff, 0x8f0f0000, 0xc6000000, 0x15000000, 0xf9000d00, 0x070000ff, 0x900f0000,
  6905. 0x6e000000, 0x15000000, 0xf9000d00, 0x070000ff, 0x9d0f0000, 0x84000000, 0x15000000, 0xf9000d00, 0x070000ff, 0xa00f0000, 0xdc000000, 0x15000000,
  6906. 0xf9000d00, 0x070000ff, 0xa10f0000, 0x0a000000, 0x01005400, 0x03000d00, 0x07000000, 0xa20f0000, 0x0c000000, 0x05003800, 0x01000d00, 0x07000000,
  6907. 0xa30f0000, 0x12000000, 0x05003800, 0x01000d00, 0x07000000, 0xa40f0000, 0x96000000, 0x07000e00, 0x00000d00, 0x07000000, 0xa50f0000, 0x5e000000,
  6908. 0x07000e00, 0x00000d00, 0x07000000, 0xa60f0000, 0x08000000, 0x01005400, 0x03000d00, 0x07000000, 0xa70f0000, 0x18000000, 0x05003800, 0x01000d00,
  6909. 0x07000000, 0xa80f0000, 0xac000000, 0x03004600, 0x02000d00, 0x07000000, 0xa90f0000, 0x56000000, 0x07000e00, 0x00000d00, 0x07000000, 0xaa0f0000,
  6910. 0x8d000000, 0x04004600, 0x01000d00, 0x07000000, 0xab0f0000, 0x1e000000, 0x05003800, 0x01000d00, 0x07000000, 0xac0f0000, 0xfb000000, 0x04000e00,
  6911. 0x01000d00, 0x07000000, 0xad0f0000, 0x42000000, 0x15000000, 0xf9000d00, 0x070000ff, 0xae0f0000, 0x3e000000, 0x07000e00, 0x00000d00, 0x07000000,
  6912. 0xaf0f0000, 0x26000000, 0x07000e00, 0x00000d00, 0x07000000, 0xb00f0000, 0x6f000000, 0x04004600, 0x01000d00, 0x07000000, 0xb10f0000, 0x24000000,
  6913. 0x05003800, 0x01000d00, 0x07000000, 0xb20f0000, 0x79000000, 0x04004600, 0x01000d00, 0x07000000, 0xb30f0000, 0x83000000, 0x04004600, 0x01000d00,
  6914. 0x07000000, 0xb40f0000, 0xeb000000, 0x02004600, 0x03000d00, 0x07000000, 0xb50f0000, 0x46000000, 0x07000e00, 0x00000d00, 0x07000000, 0xb60f0000,
  6915. 0xe6000000, 0x06000e00, 0x01000d00, 0x07000000, 0xb70f0000, 0xc0000000, 0x03004600, 0x02000d00, 0x07000000, 0xb80f0000, 0xf7000000, 0x02004600,
  6916. 0x03000d00, 0x07000000, 0xb90f0000, 0xc4000000, 0x03004600, 0x01000d00, 0x07000000, 0xba0f0000, 0x60000000, 0x04004600, 0x01000d00, 0x07000000,
  6917. 0xbb0f0000, 0x2a000000, 0x05003800, 0x01000d00, 0x07000000, 0xbc0f0000, 0x1c000000, 0x06002a00, 0x01000d00, 0x07000000, 0xbd0f0000, 0xc4000000,
  6918. 0x06001c00, 0x01000d00, 0x07000000, 0xbe0f0000, 0x9e000000, 0x07000e00, 0x00000d00, 0x07000000, 0xbf0f0000, 0x30000000, 0x05003800, 0x01000d00,
  6919. 0x07000000, 0xc00f0000, 0x9a000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc10f0000, 0x93000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc20f0000,
  6920. 0x70000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc30f0000, 0x69000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc40f0000, 0x62000000, 0x06001c00,
  6921. 0x01000d00, 0x07000000, 0xc50f0000, 0x5b000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc60f0000, 0xf2000000, 0x07000000, 0x00000d00, 0x07000000,
  6922. 0xc70f0000, 0xbd000000, 0x06001c00, 0x01000d00, 0x07000000, 0xc80f0000, 0x3c000000, 0x05003800, 0x01000d00, 0x07000000, 0xc90f0000, 0x42000000,
  6923. 0x05003800, 0x01000d00, 0x07000000, 0xca0f0000, 0x48000000, 0x05003800, 0x01000d00, 0x07000000, 0xcb0f0000, 0x4e000000, 0x05003800, 0x01000d00,
  6924. 0x07000000, 0xcc0f0000, 0xa4000000, 0x03004600, 0x02000d00, 0x07000000, 0xcd0f0000, 0xb0000000, 0x03004600, 0x02000d00, 0x07000000, 0xce0f0000,
  6925. 0xa8000000, 0x03004600, 0x02000d00, 0x07000000, 0xcf0f0000, 0xfc000000, 0x03001c00, 0x02000d00, 0x07000000, 0xd00f0000, 0xce000000, 0x07000e00,
  6926. 0x00000d00, 0x07000000, 0xd10f0000, 0xcb000000, 0x06001c00, 0x01000d00, 0x07000000, 0xd20f0000, 0xd2000000, 0x06001c00, 0x01000d00, 0x07000000,
  6927. 0xd30f0000, 0xd9000000, 0x06001c00, 0x01000d00, 0x07000000, 0xd40f0000, 0x2a000000, 0x06002a00, 0x01000d00, 0x07000000, 0xd50f0000, 0xe7000000,
  6928. 0x06001c00, 0x01000d00, 0x07000000, 0xd60f0000, 0xee000000, 0x06001c00, 0x01000d00, 0x07000000, 0xd70f0000, 0x7e000000, 0x05003800, 0x01000d00,
  6929. 0x07000000, 0xd80f0000, 0xf5000000, 0x06001c00, 0x01000d00, 0x07000000, 0xd90f0000, 0x00000000, 0x06002a00, 0x01000d00, 0x07000000, 0xda0f0000,
  6930. 0x07000000, 0x06002a00, 0x01000d00, 0x07000000, 0xdb0f0000, 0x0e000000, 0x06002a00, 0x01000d00, 0x07000000, 0xdc0f0000, 0x15000000, 0x06002a00,
  6931. 0x01000d00, 0x07000000, 0xdd0f0000, 0xd6000000, 0x07000e00, 0x00000d00, 0x07000000, 0xde0f0000, 0xa8000000, 0x05003800, 0x01000d00, 0x07000000,
  6932. 0xdf0f0000, 0xde000000, 0x07000e00, 0x00000d00, 0x07000000, 0xe00f0000, 0xb4000000, 0x05003800, 0x01000d00, 0x07000000, 0xe10f0000, 0xba000000,
  6933. 0x05003800, 0x01000d00, 0x07000000, 0xe20f0000, 0xc0000000, 0x05003800, 0x01000d00, 0x07000000, 0xe30f0000, 0xc6000000, 0x05003800, 0x01000d00,
  6934. 0x07000000, 0xe40f0000, 0xcc000000, 0x05003800, 0x01000d00, 0x07000000, 0xe50f0000, 0xd2000000, 0x05003800, 0x01000d00, 0x07000000, 0xe60f0000,
  6935. 0xb6000000, 0x07000e00, 0x00000d00, 0x07000000, 0xe70f0000, 0xde000000, 0x05003800, 0x01000d00, 0x07000000, 0xe80f0000, 0xe4000000, 0x05003800,
  6936. 0x01000d00, 0x07000000, 0xe90f0000, 0xea000000, 0x05003800, 0x01000d00, 0x07000000, 0xea0f0000, 0xf0000000, 0x05003800, 0x01000d00, 0x07000000,
  6937. 0xeb0f0000, 0xf6000000, 0x05003800, 0x01000d00, 0x07000000, 0xec0f0000, 0xf1000000, 0x02004600, 0x02000d00, 0x07000000, 0xed0f0000, 0xf4000000,
  6938. 0x02004600, 0x02000d00, 0x07000000, 0xee0f0000, 0xd0000000, 0x03004600, 0x02000d00, 0x07000000, 0xef0f0000, 0xd4000000, 0x03004600, 0x02000d00,
  6939. 0x07000000, 0xf00f0000, 0x00000000, 0x05004600, 0x01000d00, 0x07000000, 0xf10f0000, 0x06000000, 0x05004600, 0x01000d00, 0x07000000, 0xf20f0000,
  6940. 0x0c000000, 0x05004600, 0x01000d00, 0x07000000, 0xf30f0000, 0x12000000, 0x05004600, 0x01000d00, 0x07000000, 0xf40f0000, 0x18000000, 0x05004600,
  6941. 0x01000d00, 0x07000000, 0xf50f0000, 0x1e000000, 0x05004600, 0x01000d00, 0x07000000, 0xf60f0000, 0x24000000, 0x05004600, 0x01000d00, 0x07000000,
  6942. 0xf70f0000, 0x2a000000, 0x05004600, 0x01000d00, 0x07000000, 0xf80f0000, 0x30000000, 0x05004600, 0x01000d00, 0x07000000, 0xf90f0000, 0x36000000,
  6943. 0x05004600, 0x01000d00, 0x07000000, 0xfa0f0000, 0x3c000000, 0x05004600, 0x01000d00, 0x07000000, 0xfb0f0000, 0x42000000, 0x05004600, 0x01000d00,
  6944. 0x07000000, 0xfc0f0000, 0x48000000, 0x05004600, 0x01000d00, 0x07000000, 0xfd0f0000, 0x4e000000, 0x05004600, 0x01000d00, 0x07000000, 0xfe0f0000,
  6945. 0x54000000, 0x05004600, 0x01000d00, 0x07000000, 0xff0f0000, 0x5a000000, 0x05004600, 0x01000d00, 0x07000000, 0x000f0000,
  6946. };
  6947. void ImGui::GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size)
  6948. {
  6949. if (fnt_data) *fnt_data = (const void*)proggy_clean_13_fnt_data;
  6950. if (fnt_size) *fnt_size = proggy_clean_13_fnt_size;
  6951. if (png_data) *png_data = (const void*)proggy_clean_13_png_data;
  6952. if (png_size) *png_size = proggy_clean_13_png_size;
  6953. }
  6954. //-----------------------------------------------------------------------------
  6955. //---- Include imgui_user.inl at the end of imgui.cpp
  6956. //---- So you can include code that extends ImGui using its private data/functions.
  6957. #ifdef IMGUI_INCLUDE_IMGUI_USER_INL
  6958. #include "imgui_user.inl"
  6959. #endif
  6960. //-----------------------------------------------------------------------------