Open Source Tomb Raider Engine
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

imgui.cpp 257KB

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