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

imgui.cpp 372KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038
  1. // ImGui library v1.31 wip
  2. // See ImGui::ShowTestWindow() for sample code.
  3. // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase.
  4. // Get latest version at https://github.com/ocornut/imgui
  5. // Developed by Omar Cornut and contributors.
  6. /*
  7. Index
  8. - MISSION STATEMENT
  9. - END-USER GUIDE
  10. - PROGRAMMER GUIDE
  11. - API BREAKING CHANGES
  12. - TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS
  13. - ISSUES & TODO-LIST
  14. - CODE
  15. - SAMPLE CODE
  16. - FONT DATA
  17. MISSION STATEMENT
  18. =================
  19. - easy to use to create code-driven and data-driven tools
  20. - easy to use to create ad hoc short-lived tools and long-lived, more elaborate tools
  21. - easy to hack and improve
  22. - minimize screen real-estate usage
  23. - minimize setup and maintenance
  24. - minimize state storage on user side
  25. - portable, minimize dependencies, run on target (consoles, etc.)
  26. - efficient runtime (NB- we do allocate when "growing" content - creating a window / opening a tree node for the first time, etc. - but a typical frame won't allocate anything)
  27. - read about immediate-mode GUI principles @ http://mollyrocket.com/861, http://mollyrocket.com/forums/index.html
  28. Designed for developers and content-creators, not the typical end-user! Some of the weaknesses includes:
  29. - doesn't look fancy, doesn't animate
  30. - limited layout features, intricate layouts are typically crafted in code
  31. - occasionally use statically sized buffers for string manipulations - won't crash, but some long text may be clipped
  32. END-USER GUIDE
  33. ==============
  34. - double-click title bar to collapse window
  35. - click upper right corner to close a window, available when 'bool* p_opened' is passed to ImGui::Begin()
  36. - click and drag on lower right corner to resize window
  37. - click and drag on any empty space to move window
  38. - double-click/double-tap on lower right corner grip to auto-fit to content
  39. - TAB/SHIFT+TAB to cycle through keyboard editable fields
  40. - use mouse wheel to scroll
  41. - use CTRL+mouse wheel to zoom window contents (if IO.FontAllowScaling is true)
  42. - CTRL+Click on a slider to input value as text
  43. - text editor:
  44. - Hold SHIFT or use mouse to select text.
  45. - CTRL+Left/Right to word jump
  46. - CTRL+Shift+Left/Right to select words
  47. - CTRL+A our Double-Click to select all
  48. - CTRL+X,CTRL+C,CTRL+V to use OS clipboard
  49. - CTRL+Z,CTRL+Y to undo/redo
  50. - ESCAPE to revert text to its original value
  51. - You can apply arithmetic operators +,*,/ on numerical values. Use +- to subtract (because - would set a negative value!)
  52. PROGRAMMER GUIDE
  53. ================
  54. - your code creates the UI, if your code doesn't run the UI is gone! == dynamic UI, no construction step, less data retention on your side, no state duplication, less sync, less errors.
  55. - call and read ImGui::ShowTestWindow() for user-side sample code
  56. - see examples/ folder for standalone sample applications.
  57. - customization: use the style editor to tweak the look of the interface (e.g. if you want a more compact UI or a different color scheme), and report values in your code.
  58. - getting started:
  59. - initialisation: call ImGui::GetIO() and fill the 'Settings' data.
  60. - every frame:
  61. 1/ in your mainloop or right after you got your keyboard/mouse info, call ImGui::GetIO() and fill the 'Input' data, then call ImGui::NewFrame().
  62. 2/ use any ImGui function you want between NewFrame() and Render()
  63. 3/ ImGui::Render() to render all the accumulated command-lists. it will call your RenderDrawListFn handler that you set in the IO structure.
  64. - all rendering information are stored into command-lists until ImGui::Render() is called.
  65. - effectively it means you can create widgets at any time in your code, regardless of "update" vs "render" considerations.
  66. - refer to the examples applications in the examples/ folder for instruction on how to setup your code.
  67. - a typical application skeleton may be:
  68. // Application init
  69. ImGuiIO& io = ImGui::GetIO();
  70. io.DisplaySize.x = 1920.0f;
  71. io.DisplaySize.y = 1280.0f;
  72. io.DeltaTime = 1.0f/60.0f;
  73. io.IniFilename = "imgui.ini";
  74. // TODO: Fill others settings of the io structure
  75. // Load texture
  76. unsigned char* pixels;
  77. int width, height, bytes_per_pixels;
  78. io.Fonts->GetTexDataAsRGBA32(pixels, &width, &height, &bytes_per_pixels);
  79. // TODO: copy texture to graphics memory.
  80. // TODO: store your texture pointer/identifier in 'io.Fonts->TexID'
  81. // Application main loop
  82. while (true)
  83. {
  84. // 1) get low-level input
  85. // e.g. on Win32, GetKeyboardState(), or poll your events, etc.
  86. // 2) TODO: fill all fields of IO structure and call NewFrame
  87. ImGuiIO& io = ImGui::GetIO();
  88. io.MousePos = ...
  89. io.KeysDown[i] = ...
  90. ImGui::NewFrame();
  91. // 3) most of your application code here - you can use any of ImGui::* functions at any point in the frame
  92. ImGui::Begin("My window");
  93. ImGui::Text("Hello, world.");
  94. ImGui::End();
  95. GameUpdate();
  96. GameRender();
  97. // 4) render & swap video buffers
  98. ImGui::Render();
  99. // swap video buffer, etc.
  100. }
  101. - after calling ImGui::NewFrame() you can read back 'io.WantCaptureMouse' and 'io.WantCaptureKeyboard' to tell
  102. if ImGui wants to use your inputs. so typically can hide the mouse inputs from the rest of your application if ImGui is using it.
  103. API BREAKING CHANGES
  104. ====================
  105. Occasionally introducing changes that are breaking the API. The breakage are generally minor and easy to fix.
  106. Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code.
  107. - 2015/02/01 (1.31) - removed IO.MemReallocFn (unused)
  108. - 2015/01/19 (1.30) - renamed ImGuiStorage::GetIntPtr()/GetFloatPtr() to GetIntRef()/GetIntRef() because Ptr was conflicting with actual pointer storage functions.
  109. - 2015/01/11 (1.30) - big font/image API change! now loads TTF file. allow for multiple fonts. no need for a PNG loader.
  110. (1.30) - removed GetDefaultFontData(). uses io.Fonts->GetTextureData*() API to retrieve uncompressed pixels.
  111. this sequence:
  112. const void* png_data;
  113. unsigned int png_size;
  114. ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size);
  115. // <Copy to GPU>
  116. became:
  117. unsigned char* pixels;
  118. int width, height;
  119. io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
  120. // <Copy to GPU>
  121. io.Fonts->TexID = (your_texture_identifier);
  122. you now have much more flexibility to load multiple TTF fonts and manage the texture buffer for internal needs.
  123. it is now recommended your sample the font texture with bilinear interpolation.
  124. (1.30) - added texture identifier in ImDrawCmd passed to your render function (we can now render images). make sure to set io.Fonts->TexID.
  125. (1.30) - removed IO.PixelCenterOffset (unnecessary, can be handled in user projection matrix)
  126. (1.30) - removed ImGui::IsItemFocused() in favor of ImGui::IsItemActive() which handles all widgets
  127. - 2014/12/10 (1.18) - removed SetNewWindowDefaultPos() in favor of new generic API SetNextWindowPos(pos, ImGuiSetCondition_FirstUseEver)
  128. - 2014/11/28 (1.17) - moved IO.Font*** options to inside the IO.Font-> structure (FontYOffset, FontTexUvForWhite, FontBaseScale, FontFallbackGlyph)
  129. - 2014/11/26 (1.17) - reworked syntax of IMGUI_ONCE_UPON_A_FRAME helper macro to increase compiler compatibility
  130. - 2014/11/07 (1.15) - renamed IsHovered() to IsItemHovered()
  131. - 2014/10/02 (1.14) - renamed IMGUI_INCLUDE_IMGUI_USER_CPP to IMGUI_INCLUDE_IMGUI_USER_INL and imgui_user.cpp to imgui_user.inl (more IDE friendly)
  132. - 2014/09/25 (1.13) - removed 'text_end' parameter from IO.SetClipboardTextFn (the string is now always zero-terminated for simplicity)
  133. - 2014/09/24 (1.12) - renamed SetFontScale() to SetWindowFontScale()
  134. - 2014/09/24 (1.12) - moved IM_MALLOC/IM_REALLOC/IM_FREE preprocessor defines to IO.MemAllocFn/IO.MemReallocFn/IO.MemFreeFn
  135. - 2014/08/30 (1.09) - removed IO.FontHeight (now computed automatically)
  136. - 2014/08/30 (1.09) - moved IMGUI_FONT_TEX_UV_FOR_WHITE preprocessor define to IO.FontTexUvForWhite
  137. - 2014/08/28 (1.09) - changed the behavior of IO.PixelCenterOffset following various rendering fixes
  138. TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS
  139. ============================================
  140. If text or lines are blurry when integrating ImGui in your engine:
  141. - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
  142. If you are confused about the meaning or use of ID in ImGui:
  143. - some widgets requires state to be carried over multiple frames (most typically ImGui often wants remember what is the "active" widget).
  144. to do so they need an unique ID. unique ID are typically derived from a string label, an indice or a pointer.
  145. when you call Button("OK") the button shows "OK" and also use "OK" as an ID.
  146. - ID are uniquely scoped within Windows so no conflict can happen if you have two buttons called "OK" in two different Windows.
  147. within a same Window, use PushID() / PopID() to easily create scopes and avoid ID conflicts.
  148. so if you have a loop creating "multiple" items, you can use PushID() / PopID() with the index of each item, or their pointer, etc.
  149. some functions like TreeNode() implicitly creates a scope for you by calling PushID()
  150. - when dealing with trees, ID are important because you want to preserve the opened/closed state of tree nodes.
  151. depending on your use cases you may want to use strings, indices or pointers as ID. experiment and see what makes more sense!
  152. e.g. When displaying a single object, using a static string as ID will preserve your node open/closed state when the targeted object change
  153. e.g. When displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state per object
  154. - when passing a label you can optionally specify extra unique ID information within the same string using "##". This helps solving the simpler collision cases.
  155. e.g. "Label" display "Label" and uses "Label" as ID
  156. e.g. "Label##Foobar" display "Label" and uses "Label##Foobar" as ID
  157. e.g. "##Foobar" display an empty label and uses "##Foobar" as ID
  158. - read articles about the imgui principles (see web links) to understand the requirement and use of ID.
  159. If you want to load a different font than the default (ProggyClean.ttf, size 13)
  160. io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);
  161. io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
  162. If you want to load multiple fonts, use the font atlas to pack them into a single texture!
  163. ImFont* font0 = io.Fonts->AddFontDefault();
  164. ImFont* font1 = io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);
  165. io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
  166. If you want to display Chinese, Japanese, Korean characters, pass custom Unicode ranges when loading a font:
  167. io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, io.Fonts->GetGlyphRangesJapanese()); // Load Japanese characters
  168. io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
  169. If you want to input Japanese/Chinese/Korean in the text input widget:
  170. - when loading the font, pass a range that contains the characters you need, e.g.: io.Fonts->GetGlyphRangesJapanese()
  171. - to have the Microsoft IME cursor appears at the right location in the screen, setup a handler for the io.ImeSetInputScreenPosFn function:
  172. #include <Windows.h>
  173. #include <Imm.h>
  174. static void ImImpl_ImeSetInputScreenPosFn(int x, int y)
  175. {
  176. // Notify OS Input Method Editor of text input position
  177. HWND hwnd = glfwGetWin32Window(window);
  178. if (HIMC himc = ImmGetContext(hwnd))
  179. {
  180. COMPOSITIONFORM cf;
  181. cf.ptCurrentPos.x = x;
  182. cf.ptCurrentPos.y = y;
  183. cf.dwStyle = CFS_FORCE_POSITION;
  184. ImmSetCompositionWindow(himc, &cf);
  185. }
  186. }
  187. // Set pointer to handler in ImGuiIO structure
  188. io.ImeSetInputScreenPosFn = ImImpl_ImeSetInputScreenPosFn;
  189. - tip: the construct 'IMGUI_ONCE_UPON_A_FRAME { ... }' will evaluate to a block of code only once a frame. You can use it to quickly add custom UI in the middle of a deep nested inner loop in your code.
  190. - tip: you can call Render() multiple times (e.g for VR renders), up to you to communicate the extra state to your RenderDrawListFn function.
  191. - tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug"
  192. - tip: call and read the ShowTestWindow() code for more example of how to use ImGui!
  193. ISSUES & TODO-LIST
  194. ==================
  195. - misc: merge or clarify ImVec4 / ImGuiAabb, they are essentially duplicate containers
  196. - window: add horizontal scroll
  197. - window: fix resize grip rendering scaling along with Rounding style setting
  198. - window: autofit feedback loop when user relies on any dynamic layout (window width multiplier, column). maybe just clearly drop manual autofit?
  199. - window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list.
  200. - window: allow resizing of child windows (possibly given min/max for each axis?)
  201. - window: background options for child windows, border option (disable rounding)
  202. - window: resizing from any sides? + mouse cursor directives for app.
  203. - widgets: display mode: widget-label, label-widget (aligned on column or using fixed size), label-newline-tab-widget etc.
  204. - widgets: clip text? hover clipped text shows it in a tooltip or in-place overlay
  205. - main: considering adding EndFrame() - optional, else done in Render(). and Init()
  206. - main: IsItemHovered() returns true even if mouse is active on another widget (e.g. dragging outside of sliders). Maybe not a sensible default? Add parameter or alternate function?
  207. - main: IsItemHovered() make it more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes
  208. - main: IsItemHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode?
  209. - scrollbar: use relative mouse movement when first-clicking inside of scroll grab box.
  210. - scrollbar: make the grab visible and a minimum size for long scroll regions
  211. !- input number: very large int not reliably supported because of int<>float conversions.
  212. - input number: optional range min/max for Input*() functions
  213. - input number: holding [-]/[+] buttons could increase the step speed non-linearly (or user-controlled)
  214. - input number: use mouse wheel to step up/down
  215. - input number: non-decimal input.
  216. - layout: horizontal layout helper (github issue #97)
  217. - layout: more generic alignment state (left/right/centered) for single items?
  218. - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 layout code. item width should include frame padding.
  219. - columns: separator function or parameter that works within the column (currently Separator() bypass all columns)
  220. - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills)
  221. - columns: columns header to act as button (~sort op) and allow resize/reorder
  222. - columns: user specify columns size
  223. - combo: turn child handling code into pop up helper
  224. - list selection, concept of a selectable "block" (that can be multiple widgets)
  225. - menubar, menus
  226. - tabs
  227. - gauge: various forms of gauge/loading bars widgets
  228. - color: better color editor.
  229. - plot: make it easier for user to draw into the graph (e.g: draw basis, highlight certain points, 2d plots, multiple plots)
  230. - plot: "smooth" automatic scale, user give an input 0.0(full user scale) 1.0(full derived from value)
  231. - 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)
  232. - file selection widget -> build the tool in our codebase to improve model-dialog idioms (may or not lead to ImGui changes)
  233. - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt()
  234. - slider: initial absolute click is imprecise. change to relative movement slider? hide mouse cursor, allow more precise input using less screen-space.
  235. - text edit: clean up the mess caused by converting UTF-8 <> wchar
  236. - text edit: centered text for slider or input text to it matches typical positioning.
  237. - text edit: flag to disable live update of the user buffer.
  238. - text edit: field resize behavior - field could stretch when being edited? hover tooltip shows more text?
  239. - text edit: add multi-line text edit
  240. - tree: add treenode/treepush int variants? because (void*) cast from int warns on some platforms/settings
  241. - settings: write more decent code to allow saving/loading new fields
  242. - settings: api for per-tool simple persistent data (bool,int,float) in .ini file
  243. ! style: store rounded corners in texture to use 1 quad per corner (filled and wireframe).
  244. - style: checkbox: padding for "active" color should be a multiplier of the
  245. - style: colorbox not always square?
  246. - log: LogButtons() options for specifying depth and/or hiding depth slider
  247. - log: have more control over the log scope (e.g. stop logging when leaving current tree node scope)
  248. - log: be able to right-click and log a window or tree-node into tty/file/clipboard / generalized context menu?
  249. - filters: set a current filter that tree node can automatically query to hide themselves
  250. - filters: handle wildcards (with implicit leading/trailing *), regexps
  251. - 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)
  252. ! keyboard: tooltip & combo boxes are messing up / not honoring keyboard tabbing
  253. - keyboard: full keyboard navigation and focus.
  254. - input: rework IO to be able to pass actual events to fix temporal aliasing issues.
  255. - input: support track pad style scrolling & slider edit.
  256. - tooltip: move to fit within screen (e.g. when mouse cursor is right of the screen).
  257. - portability: big-endian test/support (github issue #81)
  258. - misc: mark printf compiler attributes on relevant functions
  259. - misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL)
  260. - misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon?
  261. - style editor: have a more global HSV setter (e.g. alter hue on all elements). consider replacing active/hovered by offset in HSV space?
  262. - style editor: color child window height expressed in multiple of line height.
  263. - optimization/render: use indexed rendering to reduce vertex data cost (for remote/networked imgui)
  264. - optimization/render: move clip-rect to vertex data? would allow merging all commands
  265. - optimization/render: merge command-lists with same clip-rect into one even if they aren't sequential? (as long as in-between clip rectangle don't overlap)?
  266. - optimization: turn some the various stack vectors into statically-sized arrays
  267. - optimization: better clipping for multi-component widgets
  268. - optimization: specialize for height based clipping first (assume widgets never go up + height tests before width tests?)
  269. */
  270. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  271. #define _CRT_SECURE_NO_WARNINGS
  272. #endif
  273. #include "imgui.h"
  274. #include <ctype.h> // toupper
  275. #include <math.h> // sqrtf
  276. #include <stdint.h> // intptr_t
  277. #include <stdio.h> // vsnprintf
  278. #include <new> // new (ptr)
  279. #ifdef _MSC_VER
  280. #pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
  281. #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
  282. #endif
  283. // Clang warnings with -Weverything
  284. #ifdef __clang__
  285. #pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
  286. #pragma clang diagnostic ignored "-Wfloat-equal" // warning : comparing floating point with == or != is unsafe // storing and comparing against same constants ok.
  287. #pragma clang diagnostic ignored "-Wformat-nonliteral" // warning : format string is not a string literal // passing non-literal to vsnformat(). yes, user passing incorrect format strings can crash the code.
  288. #pragma clang diagnostic ignored "-Wexit-time-destructors" // warning : declaration requires an exit-time destructor // exit-time destruction order is undefined. if MemFree() leads to users code that has been disabled before exit it might cause problems. ImGui coding style welcomes static/globals.
  289. #pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference it.
  290. #pragma clang diagnostic ignored "-Wsign-conversion" // warning : implicit conversion changes signedness //
  291. #endif
  292. #ifdef __GNUC__
  293. #pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used
  294. #endif
  295. //-------------------------------------------------------------------------
  296. // STB libraries implementation
  297. //-------------------------------------------------------------------------
  298. struct ImGuiTextEditState;
  299. //#define IMGUI_STB_NAMESPACE ImStb
  300. //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
  301. //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
  302. #ifdef IMGUI_STB_NAMESPACE
  303. namespace IMGUI_STB_NAMESPACE
  304. {
  305. #endif
  306. #ifdef __clang__
  307. #pragma clang diagnostic push
  308. #pragma clang diagnostic ignored "-Wunused-function"
  309. #pragma clang diagnostic ignored "-Wmissing-prototypes"
  310. #endif
  311. #define STBRP_ASSERT(x) IM_ASSERT(x)
  312. #ifndef IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
  313. #define STBRP_STATIC
  314. #define STB_RECT_PACK_IMPLEMENTATION
  315. #endif
  316. #include "stb_rect_pack.h"
  317. #define STBTT_malloc(x,u) ((void)(u), ImGui::MemAlloc(x))
  318. #define STBTT_free(x,u) ((void)(u), ImGui::MemFree(x))
  319. #define STBTT_assert(x) IM_ASSERT(x)
  320. #ifndef IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
  321. #define STBTT_STATIC
  322. #define STB_TRUETYPE_IMPLEMENTATION
  323. #endif
  324. #include "stb_truetype.h"
  325. #define STB_TEXTEDIT_STRING ImGuiTextEditState
  326. #define STB_TEXTEDIT_CHARTYPE ImWchar
  327. #include "stb_textedit.h"
  328. #ifdef __clang__
  329. #pragma clang diagnostic pop
  330. #endif
  331. #ifdef IMGUI_STB_NAMESPACE
  332. } // namespace ImStb
  333. using namespace IMGUI_STB_NAMESPACE;
  334. #endif
  335. //-------------------------------------------------------------------------
  336. // Forward Declarations
  337. //-------------------------------------------------------------------------
  338. static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat = false);
  339. static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL);
  340. static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true, float wrap_width = 0.0f);
  341. static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
  342. static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false);
  343. static void SetFont(ImFont* font);
  344. static bool ItemAdd(const ImGuiAabb& aabb, const ImGuiID* id);
  345. static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset = NULL);
  346. static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset = NULL);
  347. static void PushColumnClipRect(int column_index = -1);
  348. static bool IsClipped(const ImGuiAabb& aabb);
  349. static bool IsMouseHoveringBox(const ImGuiAabb& box);
  350. static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true);
  351. static bool CloseWindowButton(bool* p_opened = NULL);
  352. static void FocusWindow(ImGuiWindow* window);
  353. static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs);
  354. // Helpers: String
  355. static int ImStricmp(const char* str1, const char* str2);
  356. static int ImStrnicmp(const char* str1, const char* str2, int count);
  357. static char* ImStrdup(const char *str);
  358. static size_t ImStrlenW(const ImWchar* str);
  359. static const char* ImStristr(const char* haystack, const char* needle, const char* needle_end);
  360. static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...);
  361. static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args);
  362. // Helpers: Misc
  363. static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed);
  364. static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes = 0);
  365. static int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; }
  366. // Helpers: UTF-8 <> wchar
  367. static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int in_char); // return output UTF-8 bytes count
  368. static ptrdiff_t ImTextStrToUtf8(char* buf, size_t buf_size, const ImWchar* in_text, const ImWchar* in_text_end); // return output UTF-8 bytes count
  369. static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count
  370. static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end); // return input UTF-8 bytes count
  371. static int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end); // return number of UTF-8 code-points (NOT bytes count)
  372. static int ImTextCountUtf8BytesFromWchar(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string as UTF-8 code-points
  373. //-----------------------------------------------------------------------------
  374. // Platform dependent default implementations
  375. //-----------------------------------------------------------------------------
  376. static const char* GetClipboardTextFn_DefaultImpl();
  377. static void SetClipboardTextFn_DefaultImpl(const char* text);
  378. //-----------------------------------------------------------------------------
  379. // Texture Atlas data
  380. //-----------------------------------------------------------------------------
  381. // Technically we should use the rect pack API for that, but it's just simpler to hard-core the positions for now.
  382. // As we start using more of the texture atlas (for rounded corners) we can change that.
  383. static const ImVec2 TEX_ATLAS_SIZE(32, 32);
  384. static const ImVec2 TEX_ATLAS_POS_MOUSE_CURSOR_BLACK(1, 3);
  385. static const ImVec2 TEX_ATLAS_POS_MOUSE_CURSOR_WHITE(14, 3);
  386. static const ImVec2 TEX_ATLAS_SIZE_MOUSE_CURSOR(12, 19);
  387. //-----------------------------------------------------------------------------
  388. // User facing structures
  389. //-----------------------------------------------------------------------------
  390. ImGuiStyle::ImGuiStyle()
  391. {
  392. Alpha = 1.0f; // Global alpha applies to everything in ImGui
  393. WindowPadding = ImVec2(8,8); // Padding within a window
  394. WindowMinSize = ImVec2(32,32); // Minimum window size
  395. WindowRounding = 9.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows
  396. FramePadding = ImVec2(4,3); // Padding within a framed rectangle (used by most widgets)
  397. FrameRounding = 0.0f; // Radius of frame corners rounding. Set to 0.0f to have rectangular frames (used by most widgets).
  398. ItemSpacing = ImVec2(8,4); // Horizontal and vertical spacing between widgets/lines
  399. ItemInnerSpacing = ImVec2(4,4); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
  400. 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!
  401. AutoFitPadding = ImVec2(8,8); // Extra space after auto-fit (double-clicking on resize grip)
  402. WindowFillAlphaDefault = 0.70f; // Default alpha of window background, if not specified in ImGui::Begin()
  403. TreeNodeSpacing = 22.0f; // Horizontal spacing when entering a tree node
  404. ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns
  405. ScrollBarWidth = 16.0f; // Width of the vertical scroll bar
  406. Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
  407. Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
  408. Colors[ImGuiCol_Border] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
  409. Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.60f);
  410. Colors[ImGuiCol_FrameBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.30f); // Background of checkbox, radio button, plot, slider, text input
  411. Colors[ImGuiCol_TitleBg] = ImVec4(0.50f, 0.50f, 1.00f, 0.45f);
  412. Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.40f, 0.40f, 0.80f, 0.20f);
  413. Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.40f, 0.40f, 0.80f, 0.15f);
  414. Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.40f, 0.40f, 0.80f, 0.30f);
  415. Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.80f, 0.40f);
  416. Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 0.40f);
  417. Colors[ImGuiCol_ComboBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.99f);
  418. Colors[ImGuiCol_CheckHovered] = ImVec4(0.60f, 0.40f, 0.40f, 0.45f);
  419. Colors[ImGuiCol_CheckActive] = ImVec4(0.65f, 0.50f, 0.50f, 0.55f);
  420. Colors[ImGuiCol_CheckMark] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f);
  421. Colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
  422. Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f);
  423. Colors[ImGuiCol_Button] = ImVec4(0.67f, 0.40f, 0.40f, 0.60f);
  424. Colors[ImGuiCol_ButtonHovered] = ImVec4(0.67f, 0.40f, 0.40f, 1.00f);
  425. Colors[ImGuiCol_ButtonActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f);
  426. Colors[ImGuiCol_Header] = ImVec4(0.40f, 0.40f, 0.90f, 0.45f);
  427. Colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.90f, 0.80f);
  428. Colors[ImGuiCol_HeaderActive] = ImVec4(0.60f, 0.60f, 0.80f, 1.00f);
  429. Colors[ImGuiCol_Column] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
  430. Colors[ImGuiCol_ColumnHovered] = ImVec4(0.60f, 0.40f, 0.40f, 1.00f);
  431. Colors[ImGuiCol_ColumnActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f);
  432. Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
  433. Colors[ImGuiCol_ResizeGripHovered] = ImVec4(1.00f, 1.00f, 1.00f, 0.60f);
  434. Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.90f);
  435. Colors[ImGuiCol_CloseButton] = ImVec4(0.50f, 0.50f, 0.90f, 0.50f);
  436. Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.70f, 0.70f, 0.90f, 0.60f);
  437. Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.70f, 0.70f, 0.70f, 1.00f);
  438. Colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
  439. Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  440. Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  441. Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
  442. Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f);
  443. Colors[ImGuiCol_TooltipBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f);
  444. }
  445. // Statically allocated font atlas. This is merely a maneuver to keep its definition at the bottom of the .H file.
  446. // Because we cannot new() at this point (before users may define IO.MemAllocFn)
  447. static ImFontAtlas GDefaultFontAtlas;
  448. ImGuiIO::ImGuiIO()
  449. {
  450. // Most fields are initialized with zero
  451. memset(this, 0, sizeof(*this));
  452. DisplaySize = ImVec2(-1.0f, -1.0f);
  453. DeltaTime = 1.0f/60.0f;
  454. IniSavingRate = 5.0f;
  455. IniFilename = "imgui.ini";
  456. LogFilename = "imgui_log.txt";
  457. Fonts = &GDefaultFontAtlas;
  458. FontGlobalScale = 1.0f;
  459. MousePos = ImVec2(-1,-1);
  460. MousePosPrev = ImVec2(-1,-1);
  461. MouseDoubleClickTime = 0.30f;
  462. MouseDoubleClickMaxDist = 6.0f;
  463. UserData = NULL;
  464. // User functions
  465. RenderDrawListsFn = NULL;
  466. MemAllocFn = malloc;
  467. MemFreeFn = free;
  468. GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependent default implementations
  469. SetClipboardTextFn = SetClipboardTextFn_DefaultImpl;
  470. ImeSetInputScreenPosFn = NULL;
  471. }
  472. // Pass in translated ASCII characters for text input.
  473. // - with glfw you can get those from the callback set in glfwSetCharCallback()
  474. // - on Windows you can get those using ToAscii+keyboard state, or via the VM_CHAR message
  475. void ImGuiIO::AddInputCharacter(ImWchar c)
  476. {
  477. const size_t n = ImStrlenW(InputCharacters);
  478. if (n + 1 < sizeof(InputCharacters) / sizeof(InputCharacters[0]))
  479. {
  480. InputCharacters[n] = c;
  481. InputCharacters[n+1] = 0;
  482. }
  483. }
  484. //-----------------------------------------------------------------------------
  485. // Helpers
  486. //-----------------------------------------------------------------------------
  487. #define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR)))
  488. #undef PI
  489. const float PI = 3.14159265358979323846f;
  490. #ifdef INT_MAX
  491. #define IM_INT_MAX INT_MAX
  492. #else
  493. #define IM_INT_MAX 2147483647
  494. #endif
  495. // Play it nice with Windows users. Notepad in 2014 still doesn't display text data with Unix-style \n.
  496. #ifdef _MSC_VER
  497. #define STR_NEWLINE "\r\n"
  498. #else
  499. #define STR_NEWLINE "\n"
  500. #endif
  501. // Math bits
  502. // 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.
  503. static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x*rhs, lhs.y*rhs); }
  504. //static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x/rhs, lhs.y/rhs); }
  505. static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x+rhs.x, lhs.y+rhs.y); }
  506. static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); }
  507. static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); }
  508. static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); }
  509. static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; }
  510. static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; }
  511. static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; }
  512. //static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; }
  513. static inline int ImMin(int lhs, int rhs) { return lhs < rhs ? lhs : rhs; }
  514. static inline int ImMax(int lhs, int rhs) { return lhs >= rhs ? lhs : rhs; }
  515. static inline float ImMin(float lhs, float rhs) { return lhs < rhs ? lhs : rhs; }
  516. static inline float ImMax(float lhs, float rhs) { return lhs >= rhs ? lhs : rhs; }
  517. static inline ImVec2 ImMin(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMin(lhs.x,rhs.x), ImMin(lhs.y,rhs.y)); }
  518. static inline ImVec2 ImMax(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMax(lhs.x,rhs.x), ImMax(lhs.y,rhs.y)); }
  519. static inline float ImClamp(float f, float mn, float mx) { return (f < mn) ? mn : (f > mx) ? mx : f; }
  520. 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)); }
  521. static inline float ImSaturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; }
  522. static inline float ImLerp(float a, float b, float t) { return a + (b - a) * t; }
  523. 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); }
  524. static inline float ImLengthSqr(const ImVec2& lhs) { return lhs.x*lhs.x + lhs.y*lhs.y; }
  525. static int ImStricmp(const char* str1, const char* str2)
  526. {
  527. int d;
  528. while ((d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; }
  529. return d;
  530. }
  531. static int ImStrnicmp(const char* str1, const char* str2, int count)
  532. {
  533. int d = 0;
  534. while (count > 0 && (d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; count--; }
  535. return d;
  536. }
  537. static char* ImStrdup(const char *str)
  538. {
  539. char *buff = (char*)ImGui::MemAlloc(strlen(str) + 1);
  540. IM_ASSERT(buff);
  541. strcpy(buff, str);
  542. return buff;
  543. }
  544. static size_t ImStrlenW(const ImWchar* str)
  545. {
  546. size_t n = 0;
  547. while (*str++)
  548. n++;
  549. return n;
  550. }
  551. static const char* ImStristr(const char* haystack, const char* needle, const char* needle_end)
  552. {
  553. if (!needle_end)
  554. needle_end = needle + strlen(needle);
  555. const char un0 = (char)toupper(*needle);
  556. while (*haystack)
  557. {
  558. if (toupper(*haystack) == un0)
  559. {
  560. const char* b = needle + 1;
  561. for (const char* a = haystack + 1; b < needle_end; a++, b++)
  562. if (toupper(*a) != toupper(*b))
  563. break;
  564. if (b == needle_end)
  565. return haystack;
  566. }
  567. haystack++;
  568. }
  569. return NULL;
  570. }
  571. // Pass data_size==0 for zero-terminated string
  572. static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed = 0)
  573. {
  574. static ImU32 crc32_lut[256] = { 0 };
  575. if (!crc32_lut[1])
  576. {
  577. const ImU32 polynomial = 0xEDB88320;
  578. for (ImU32 i = 0; i < 256; i++)
  579. {
  580. ImU32 crc = i;
  581. for (ImU32 j = 0; j < 8; j++)
  582. crc = (crc >> 1) ^ (ImU32(-int(crc & 1)) & polynomial);
  583. crc32_lut[i] = crc;
  584. }
  585. }
  586. ImU32 crc = ~seed;
  587. const unsigned char* current = (const unsigned char*)data;
  588. if (data_size > 0)
  589. {
  590. // Known size
  591. while (data_size--)
  592. crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++];
  593. }
  594. else
  595. {
  596. // Zero-terminated string
  597. while (unsigned char c = *current++)
  598. crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
  599. }
  600. return ~crc;
  601. }
  602. static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...)
  603. {
  604. va_list args;
  605. va_start(args, fmt);
  606. int w = vsnprintf(buf, buf_size, fmt, args);
  607. va_end(args);
  608. buf[buf_size-1] = 0;
  609. return (w == -1) ? buf_size : (size_t)w;
  610. }
  611. static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args)
  612. {
  613. int w = vsnprintf(buf, buf_size, fmt, args);
  614. buf[buf_size-1] = 0;
  615. return (w == -1) ? buf_size : (size_t)w;
  616. }
  617. ImU32 ImGui::ColorConvertFloat4ToU32(const ImVec4& in)
  618. {
  619. ImU32 out = ((ImU32)(ImSaturate(in.x)*255.f));
  620. out |= ((ImU32)(ImSaturate(in.y)*255.f) << 8);
  621. out |= ((ImU32)(ImSaturate(in.z)*255.f) << 16);
  622. out |= ((ImU32)(ImSaturate(in.w)*255.f) << 24);
  623. return out;
  624. }
  625. // Convert rgb floats ([0-1],[0-1],[0-1]) to hsv floats ([0-1],[0-1],[0-1]), from Foley & van Dam p592
  626. // Optimized http://lolengine.net/blog/2013/01/13/fast-rgb-to-hsv
  627. void ImGui::ColorConvertRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v)
  628. {
  629. float K = 0.f;
  630. if (g < b)
  631. {
  632. const float tmp = g; g = b; b = tmp;
  633. K = -1.f;
  634. }
  635. if (r < g)
  636. {
  637. const float tmp = r; r = g; g = tmp;
  638. K = -2.f / 6.f - K;
  639. }
  640. const float chroma = r - (g < b ? g : b);
  641. out_h = fabsf(K + (g - b) / (6.f * chroma + 1e-20f));
  642. out_s = chroma / (r + 1e-20f);
  643. out_v = r;
  644. }
  645. // Convert hsv floats ([0-1],[0-1],[0-1]) to rgb floats ([0-1],[0-1],[0-1]), from Foley & van Dam p593
  646. // also http://en.wikipedia.org/wiki/HSL_and_HSV
  647. void ImGui::ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b)
  648. {
  649. if (s == 0.0f)
  650. {
  651. // gray
  652. out_r = out_g = out_b = v;
  653. return;
  654. }
  655. h = fmodf(h, 1.0f) / (60.0f/360.0f);
  656. int i = (int)h;
  657. float f = h - (float)i;
  658. float p = v * (1.0f - s);
  659. float q = v * (1.0f - s * f);
  660. float t = v * (1.0f - s * (1.0f - f));
  661. switch (i)
  662. {
  663. case 0: out_r = v; out_g = t; out_b = p; break;
  664. case 1: out_r = q; out_g = v; out_b = p; break;
  665. case 2: out_r = p; out_g = v; out_b = t; break;
  666. case 3: out_r = p; out_g = q; out_b = v; break;
  667. case 4: out_r = t; out_g = p; out_b = v; break;
  668. case 5: default: out_r = v; out_g = p; out_b = q; break;
  669. }
  670. }
  671. // Load file content into memory
  672. // Memory allocated with ImGui::MemAlloc(), must be freed by user using ImGui::MemFree()
  673. static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes)
  674. {
  675. IM_ASSERT(filename && file_open_mode && out_file_data && out_file_size);
  676. IM_ASSERT(padding_bytes >= 0);
  677. *out_file_data = NULL;
  678. *out_file_size = 0;
  679. FILE* f;
  680. if ((f = fopen(filename, file_open_mode)) == NULL)
  681. return false;
  682. long file_size_signed;
  683. if (fseek(f, 0, SEEK_END) || (file_size_signed = ftell(f)) == -1 || fseek(f, 0, SEEK_SET))
  684. {
  685. fclose(f);
  686. return false;
  687. }
  688. size_t file_size = (size_t)file_size_signed;
  689. void* file_data = ImGui::MemAlloc(file_size + padding_bytes);
  690. if (file_data == NULL)
  691. {
  692. fclose(f);
  693. return false;
  694. }
  695. if (fread(file_data, 1, file_size, f) != file_size)
  696. {
  697. fclose(f);
  698. ImGui::MemFree(file_data);
  699. return false;
  700. }
  701. if (padding_bytes > 0)
  702. memset((void *)(((char*)file_data) + file_size), 0, padding_bytes);
  703. fclose(f);
  704. *out_file_data = file_data;
  705. *out_file_size = file_size;
  706. return true;
  707. }
  708. //-----------------------------------------------------------------------------
  709. struct ImGuiColMod // Color modifier, backup of modified data so we can restore it
  710. {
  711. ImGuiCol Col;
  712. ImVec4 PreviousValue;
  713. };
  714. struct ImGuiStyleMod // Style modifier, backup of modified data so we can restore it
  715. {
  716. ImGuiStyleVar Var;
  717. ImVec2 PreviousValue;
  718. };
  719. struct ImGuiAabb // 2D axis aligned bounding-box
  720. {
  721. ImVec2 Min;
  722. ImVec2 Max;
  723. ImGuiAabb() { Min = ImVec2(FLT_MAX,FLT_MAX); Max = ImVec2(-FLT_MAX,-FLT_MAX); }
  724. ImGuiAabb(const ImVec2& min, const ImVec2& max) { Min = min; Max = max; }
  725. ImGuiAabb(const ImVec4& v) { Min.x = v.x; Min.y = v.y; Max.x = v.z; Max.y = v.w; }
  726. ImGuiAabb(float x1, float y1, float x2, float y2) { Min.x = x1; Min.y = y1; Max.x = x2; Max.y = y2; }
  727. ImVec2 GetCenter() const { return Min + (Max-Min)*0.5f; }
  728. ImVec2 GetSize() const { return Max-Min; }
  729. float GetWidth() const { return (Max-Min).x; }
  730. float GetHeight() const { return (Max-Min).y; }
  731. ImVec2 GetTL() const { return Min; }
  732. ImVec2 GetTR() const { return ImVec2(Max.x,Min.y); }
  733. ImVec2 GetBL() const { return ImVec2(Min.x,Max.y); }
  734. ImVec2 GetBR() const { return Max; }
  735. bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x <= Max.x && p.y <= Max.y; }
  736. 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; }
  737. 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; }
  738. void Add(const ImVec2& rhs) { Min.x = ImMin(Min.x, rhs.x); Min.y = ImMin(Min.y, rhs.y); Max.x = ImMax(Max.x, rhs.x); Max.y = ImMax(Max.x, rhs.x); }
  739. void Add(const ImGuiAabb& rhs) { Min.x = ImMin(Min.x, rhs.Min.x); Min.y = ImMin(Min.y, rhs.Min.y); Max.x = ImMax(Max.x, rhs.Max.x); Max.y = ImMax(Max.y, rhs.Max.y); }
  740. void Expand(const ImVec2& sz) { Min -= sz; Max += sz; }
  741. 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); }
  742. };
  743. // Temporary per-window data, reset at the beginning of the frame
  744. struct ImGuiDrawContext
  745. {
  746. ImVec2 CursorPos;
  747. ImVec2 CursorPosPrevLine;
  748. ImVec2 CursorStartPos;
  749. float CurrentLineHeight;
  750. float PrevLineHeight;
  751. float LogLineHeight;
  752. int TreeDepth;
  753. ImGuiID LastItemID;
  754. ImGuiAabb LastItemAabb;
  755. bool LastItemHovered;
  756. ImVector<ImGuiWindow*> ChildWindows;
  757. ImVector<bool> AllowKeyboardFocus;
  758. ImVector<float> ItemWidth;
  759. ImVector<float> TextWrapPos;
  760. ImGuiColorEditMode ColorEditMode;
  761. ImGuiStorage* StateStorage;
  762. int OpenNextNode;
  763. float ColumnsStartX; // Start position from left of window (increased by TreePush/TreePop, etc.)
  764. float ColumnsOffsetX; // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API.
  765. int ColumnsCurrent;
  766. int ColumnsCount;
  767. ImVec2 ColumnsStartPos;
  768. float ColumnsCellMinY;
  769. float ColumnsCellMaxY;
  770. bool ColumnsShowBorders;
  771. ImGuiID ColumnsSetID;
  772. ImGuiDrawContext()
  773. {
  774. CursorPos = CursorPosPrevLine = CursorStartPos = ImVec2(0.0f, 0.0f);
  775. CurrentLineHeight = PrevLineHeight = 0.0f;
  776. LogLineHeight = -1.0f;
  777. TreeDepth = 0;
  778. LastItemID = 0;
  779. LastItemAabb = ImGuiAabb(0.0f,0.0f,0.0f,0.0f);
  780. LastItemHovered = false;
  781. StateStorage = NULL;
  782. OpenNextNode = -1;
  783. ColumnsStartX = 0.0f;
  784. ColumnsOffsetX = 0.0f;
  785. ColumnsCurrent = 0;
  786. ColumnsCount = 1;
  787. ColumnsStartPos = ImVec2(0.0f, 0.0f);
  788. ColumnsCellMinY = ColumnsCellMaxY = 0.0f;
  789. ColumnsShowBorders = true;
  790. ColumnsSetID = 0;
  791. }
  792. };
  793. // Internal state of the currently focused/edited text input box
  794. struct ImGuiTextEditState
  795. {
  796. 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.
  797. char InitialText[1024*3+1]; // backup of end-user buffer at the time of focus (in UTF-8, unconverted)
  798. size_t BufSize; // end-user buffer size, <= 1024 (or increase above)
  799. float Width; // widget width
  800. float ScrollX;
  801. STB_TexteditState StbState;
  802. float CursorAnim;
  803. ImVec2 LastCursorPos; // Cursor position in screen space to be used by IME callback.
  804. bool SelectedAllMouseLock;
  805. ImFont* Font;
  806. float FontSize;
  807. ImGuiTextEditState() { memset(this, 0, sizeof(*this)); }
  808. void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking
  809. bool CursorIsVisible() const { return CursorAnim <= 0.0f || fmodf(CursorAnim, 1.20f) <= 0.80f; } // Blinking
  810. bool HasSelection() const { return StbState.select_start != StbState.select_end; }
  811. void SelectAll() { StbState.select_start = 0; StbState.select_end = (int)ImStrlenW(Text); StbState.cursor = StbState.select_end; StbState.has_preferred_x = false; }
  812. void OnKeyPressed(int key);
  813. void UpdateScrollOffset();
  814. ImVec2 CalcDisplayOffsetFromCharIdx(int i) const;
  815. // Static functions because they are used to render non-focused instances of a text input box
  816. static const char* GetTextPointerClippedA(ImFont* font, float font_size, const char* text, float width, ImVec2* out_text_size = NULL);
  817. static const ImWchar* GetTextPointerClippedW(ImFont* font, float font_size, const ImWchar* text, float width, ImVec2* out_text_size = NULL);
  818. static void RenderTextScrolledClipped(ImFont* font, float font_size, const char* text, ImVec2 pos_base, float width, float scroll_x);
  819. };
  820. struct ImGuiIniData
  821. {
  822. char* Name;
  823. ImVec2 Pos;
  824. ImVec2 Size;
  825. bool Collapsed;
  826. ImGuiIniData() { memset(this, 0, sizeof(*this)); }
  827. ~ImGuiIniData() { if (Name) { ImGui::MemFree(Name); Name = NULL; } }
  828. };
  829. struct ImGuiState
  830. {
  831. bool Initialized;
  832. ImGuiIO IO;
  833. ImGuiStyle Style;
  834. ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back()
  835. float FontSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Size of characters.
  836. ImVec2 FontTexUvWhitePixel; // (Shortcut) == Font->TexUvForWhite
  837. float Time;
  838. int FrameCount;
  839. int FrameCountRendered;
  840. ImVector<ImGuiWindow*> Windows;
  841. ImGuiWindow* CurrentWindow; // Being drawn into
  842. ImVector<ImGuiWindow*> CurrentWindowStack;
  843. ImGuiWindow* FocusedWindow; // Will catch keyboard inputs
  844. ImGuiWindow* HoveredWindow; // Will catch mouse inputs
  845. ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only)
  846. ImGuiID HoveredId;
  847. ImGuiID ActiveId;
  848. ImGuiID ActiveIdPreviousFrame;
  849. bool ActiveIdIsAlive;
  850. float SettingsDirtyTimer;
  851. ImVector<ImGuiIniData*> Settings;
  852. ImVector<ImGuiColMod> ColorModifiers;
  853. ImVector<ImGuiStyleMod> StyleModifiers;
  854. ImVector<ImFont*> FontStack;
  855. ImVec2 SetNextWindowPosVal;
  856. ImGuiSetCondition SetNextWindowPosCond;
  857. ImVec2 SetNextWindowSizeVal;
  858. ImGuiSetCondition SetNextWindowSizeCond;
  859. bool SetNextWindowCollapsedVal;
  860. ImGuiSetCondition SetNextWindowCollapsedCond;
  861. // Render
  862. ImVector<ImDrawList*> RenderDrawLists;
  863. ImVector<ImGuiWindow*> RenderSortedWindows;
  864. // Widget state
  865. ImGuiTextEditState InputTextState;
  866. ImGuiID SliderAsInputTextId;
  867. ImGuiStorage ColorEditModeStorage; // for user selection
  868. ImGuiID ActiveComboID;
  869. char Tooltip[1024];
  870. char* PrivateClipboard; // if no custom clipboard handler is defined
  871. // Logging
  872. bool LogEnabled;
  873. FILE* LogFile;
  874. ImGuiTextBuffer* LogClipboard; // pointer so our GImGui static constructor doesn't call heap allocators.
  875. int LogStartDepth;
  876. int LogAutoExpandMaxDepth;
  877. ImGuiState()
  878. {
  879. Initialized = false;
  880. Time = 0.0f;
  881. FrameCount = 0;
  882. FrameCountRendered = -1;
  883. CurrentWindow = NULL;
  884. FocusedWindow = NULL;
  885. HoveredWindow = NULL;
  886. HoveredRootWindow = NULL;
  887. ActiveIdIsAlive = false;
  888. SettingsDirtyTimer = 0.0f;
  889. SetNextWindowPosVal = ImVec2(0.0f, 0.0f);
  890. SetNextWindowPosCond = 0;
  891. SetNextWindowSizeVal = ImVec2(0.0f, 0.0f);
  892. SetNextWindowSizeCond = 0;
  893. SetNextWindowCollapsedVal = false;
  894. SetNextWindowCollapsedCond = 0;
  895. SliderAsInputTextId = 0;
  896. ActiveComboID = 0;
  897. memset(Tooltip, 0, sizeof(Tooltip));
  898. PrivateClipboard = NULL;
  899. LogEnabled = false;
  900. LogFile = NULL;
  901. LogStartDepth = 0;
  902. LogAutoExpandMaxDepth = 2;
  903. LogClipboard = NULL;
  904. }
  905. };
  906. static ImGuiState GImGui;
  907. struct ImGuiWindow
  908. {
  909. char* Name;
  910. ImGuiID ID;
  911. ImGuiWindowFlags Flags;
  912. ImVec2 PosFloat;
  913. ImVec2 Pos; // Position rounded-up to nearest pixel
  914. ImVec2 Size; // Current size (==SizeFull or collapsed title bar size)
  915. ImVec2 SizeFull; // Size when non collapsed
  916. ImVec2 SizeContentsFit; // Size of contents (extents reach by the drawing cursor) - may not fit within Size.
  917. float ScrollY;
  918. float NextScrollY;
  919. bool ScrollbarY;
  920. bool Visible; // Set to true on Begin()
  921. bool Accessed; // Set to true when any widget access the current window
  922. bool Collapsed; // Set when collapsing window to become only title-bar
  923. bool SkipItems; // == Visible && !Collapsed
  924. int AutoFitFrames;
  925. bool AutoFitOnlyGrows;
  926. int SetWindowPosAllowFlags; // bit ImGuiSetCondition_*** specify if SetWindowPos() call is allowed with this particular flag.
  927. int SetWindowSizeAllowFlags; // bit ImGuiSetCondition_*** specify if SetWindowSize() call is allowed with this particular flag.
  928. int SetWindowCollapsedAllowFlags; // bit ImGuiSetCondition_*** specify if SetWindowCollapsed() call is allowed with this particular flag.
  929. ImGuiDrawContext DC;
  930. ImVector<ImGuiID> IDStack;
  931. ImVector<ImVec4> ClipRectStack; // Scissoring / clipping rectangle. x1, y1, x2, y2.
  932. int LastFrameDrawn;
  933. float ItemWidthDefault;
  934. ImGuiStorage StateStorage;
  935. float FontWindowScale; // Scale multiplier per-window
  936. ImDrawList* DrawList;
  937. ImGuiWindow* RootWindow;
  938. // Focus
  939. int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister()
  940. int FocusIdxTabCounter; // (same, but only count widgets which you can Tab through)
  941. int FocusIdxAllRequestCurrent; // Item being requested for focus
  942. int FocusIdxTabRequestCurrent; // Tab-able item being requested for focus
  943. int FocusIdxAllRequestNext; // Item being requested for focus, for next update (relies on layout to be stable between the frame pressing TAB and the next frame)
  944. int FocusIdxTabRequestNext; // "
  945. public:
  946. ImGuiWindow(const char* name);
  947. ~ImGuiWindow();
  948. ImGuiID GetID(const char* str);
  949. ImGuiID GetID(const void* ptr);
  950. void AddToRenderList();
  951. bool FocusItemRegister(bool is_active, bool tab_stop = true); // Return true if focus is requested
  952. void FocusItemUnregister();
  953. ImGuiAabb Aabb() const { return ImGuiAabb(Pos, Pos+Size); }
  954. ImFont* Font() const { return GImGui.Font; }
  955. float FontSize() const { return GImGui.FontSize * FontWindowScale; }
  956. ImVec2 CursorPos() const { return DC.CursorPos; }
  957. float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : FontSize() + GImGui.Style.FramePadding.y * 2.0f; }
  958. ImGuiAabb TitleBarAabb() const { return ImGuiAabb(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); }
  959. ImVec2 WindowPadding() const { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders)) ? ImVec2(1,1) : GImGui.Style.WindowPadding; }
  960. ImU32 Color(ImGuiCol idx, float a=1.f) const { ImVec4 c = GImGui.Style.Colors[idx]; c.w *= GImGui.Style.Alpha * a; return ImGui::ColorConvertFloat4ToU32(c); }
  961. ImU32 Color(const ImVec4& col) const { ImVec4 c = col; c.w *= GImGui.Style.Alpha; return ImGui::ColorConvertFloat4ToU32(c); }
  962. };
  963. static ImGuiWindow* GetCurrentWindow()
  964. {
  965. IM_ASSERT(GImGui.CurrentWindow != NULL); // ImGui::NewFrame() hasn't been called yet?
  966. GImGui.CurrentWindow->Accessed = true;
  967. return GImGui.CurrentWindow;
  968. }
  969. static void SetActiveId(ImGuiID id)
  970. {
  971. GImGui.ActiveId = id;
  972. }
  973. static void RegisterAliveId(const ImGuiID& id)
  974. {
  975. if (GImGui.ActiveId == id)
  976. GImGui.ActiveIdIsAlive = true;
  977. }
  978. //-----------------------------------------------------------------------------
  979. // Helper: Key->value storage
  980. void ImGuiStorage::Clear()
  981. {
  982. Data.clear();
  983. }
  984. // std::lower_bound but without the bullshit
  985. static ImVector<ImGuiStorage::Pair>::iterator LowerBound(ImVector<ImGuiStorage::Pair>& data, ImU32 key)
  986. {
  987. ImVector<ImGuiStorage::Pair>::iterator first = data.begin();
  988. ImVector<ImGuiStorage::Pair>::iterator last = data.end();
  989. int count = (int)(last - first);
  990. while (count > 0)
  991. {
  992. int count2 = count / 2;
  993. ImVector<ImGuiStorage::Pair>::iterator mid = first + count2;
  994. if (mid->key < key)
  995. {
  996. first = ++mid;
  997. count -= count2 + 1;
  998. }
  999. else
  1000. {
  1001. count = count2;
  1002. }
  1003. }
  1004. return first;
  1005. }
  1006. int ImGuiStorage::GetInt(ImU32 key, int default_val) const
  1007. {
  1008. ImVector<Pair>::iterator it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
  1009. if (it == Data.end() || it->key != key)
  1010. return default_val;
  1011. return it->val_i;
  1012. }
  1013. float ImGuiStorage::GetFloat(ImU32 key, float default_val) const
  1014. {
  1015. ImVector<Pair>::iterator it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
  1016. if (it == Data.end() || it->key != key)
  1017. return default_val;
  1018. return it->val_f;
  1019. }
  1020. void* ImGuiStorage::GetVoidPtr(ImGuiID key) const
  1021. {
  1022. ImVector<Pair>::iterator it = LowerBound(const_cast<ImVector<ImGuiStorage::Pair>&>(Data), key);
  1023. if (it == Data.end() || it->key != key)
  1024. return NULL;
  1025. return it->val_p;
  1026. }
  1027. // References are only valid until a new value is added to the storage. Calling a Set***() function or a Get***Ref() function invalidates the pointer.
  1028. int* ImGuiStorage::GetIntRef(ImGuiID key, int default_val)
  1029. {
  1030. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1031. if (it == Data.end() || it->key != key)
  1032. it = Data.insert(it, Pair(key, default_val));
  1033. return &it->val_i;
  1034. }
  1035. float* ImGuiStorage::GetFloatRef(ImGuiID key, float default_val)
  1036. {
  1037. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1038. if (it == Data.end() || it->key != key)
  1039. it = Data.insert(it, Pair(key, default_val));
  1040. return &it->val_f;
  1041. }
  1042. // FIXME-OPT: Wasting CPU because all SetInt() are preceeded by GetInt() calls so we should have the result from lower_bound already in place.
  1043. // However we only use SetInt() on explicit user action (so that's maximum once a frame) so the optimisation isn't much needed.
  1044. void ImGuiStorage::SetInt(ImU32 key, int val)
  1045. {
  1046. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1047. if (it == Data.end() || it->key != key)
  1048. {
  1049. Data.insert(it, Pair(key, val));
  1050. return;
  1051. }
  1052. it->val_i = val;
  1053. }
  1054. void ImGuiStorage::SetFloat(ImU32 key, float val)
  1055. {
  1056. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1057. if (it == Data.end() || it->key != key)
  1058. {
  1059. Data.insert(it, Pair(key, val));
  1060. return;
  1061. }
  1062. it->val_f = val;
  1063. }
  1064. void ImGuiStorage::SetVoidPtr(ImU32 key, void* val)
  1065. {
  1066. ImVector<Pair>::iterator it = LowerBound(Data, key);
  1067. if (it == Data.end() || it->key != key)
  1068. {
  1069. Data.insert(it, Pair(key, val));
  1070. return;
  1071. }
  1072. it->val_p = val;
  1073. }
  1074. void ImGuiStorage::SetAllInt(int v)
  1075. {
  1076. for (size_t i = 0; i < Data.size(); i++)
  1077. Data[i].val_i = v;
  1078. }
  1079. //-----------------------------------------------------------------------------
  1080. // Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
  1081. ImGuiTextFilter::ImGuiTextFilter()
  1082. {
  1083. InputBuf[0] = 0;
  1084. CountGrep = 0;
  1085. }
  1086. void ImGuiTextFilter::Draw(const char* label, float width)
  1087. {
  1088. ImGuiWindow* window = GetCurrentWindow();
  1089. if (width < 0.0f)
  1090. {
  1091. ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
  1092. width = ImMax(window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x - (label_size.x + GImGui.Style.ItemSpacing.x*4), 10.0f);
  1093. }
  1094. ImGui::PushItemWidth(width);
  1095. ImGui::InputText(label, InputBuf, IM_ARRAYSIZE(InputBuf));
  1096. ImGui::PopItemWidth();
  1097. Build();
  1098. }
  1099. void ImGuiTextFilter::TextRange::split(char separator, ImVector<TextRange>& out)
  1100. {
  1101. out.resize(0);
  1102. const char* wb = b;
  1103. const char* we = wb;
  1104. while (we < e)
  1105. {
  1106. if (*we == separator)
  1107. {
  1108. out.push_back(TextRange(wb, we));
  1109. wb = we + 1;
  1110. }
  1111. we++;
  1112. }
  1113. if (wb != we)
  1114. out.push_back(TextRange(wb, we));
  1115. }
  1116. void ImGuiTextFilter::Build()
  1117. {
  1118. Filters.resize(0);
  1119. TextRange input_range(InputBuf, InputBuf+strlen(InputBuf));
  1120. input_range.split(',', Filters);
  1121. CountGrep = 0;
  1122. for (size_t i = 0; i != Filters.size(); i++)
  1123. {
  1124. Filters[i].trim_blanks();
  1125. if (Filters[i].empty())
  1126. continue;
  1127. if (Filters[i].front() != '-')
  1128. CountGrep += 1;
  1129. }
  1130. }
  1131. bool ImGuiTextFilter::PassFilter(const char* val) const
  1132. {
  1133. if (Filters.empty())
  1134. return true;
  1135. if (val == NULL)
  1136. val = "";
  1137. for (size_t i = 0; i != Filters.size(); i++)
  1138. {
  1139. const TextRange& f = Filters[i];
  1140. if (f.empty())
  1141. continue;
  1142. if (f.front() == '-')
  1143. {
  1144. // Subtract
  1145. if (ImStristr(val, f.begin()+1, f.end()) != NULL)
  1146. return false;
  1147. }
  1148. else
  1149. {
  1150. // Grep
  1151. if (ImStristr(val, f.begin(), f.end()) != NULL)
  1152. return true;
  1153. }
  1154. }
  1155. // Implicit * grep
  1156. if (CountGrep == 0)
  1157. return true;
  1158. return false;
  1159. }
  1160. //-----------------------------------------------------------------------------
  1161. // On some platform vsnprintf() takes va_list by reference and modifies it.
  1162. // va_copy is the 'correct' way to copy a va_list but Visual Studio prior to 2013 doesn't have it.
  1163. #ifndef va_copy
  1164. #define va_copy(dest, src) (dest = src)
  1165. #endif
  1166. // Helper: Text buffer for logging/accumulating text
  1167. void ImGuiTextBuffer::appendv(const char* fmt, va_list args)
  1168. {
  1169. va_list args_copy;
  1170. va_copy(args_copy, args);
  1171. int len = vsnprintf(NULL, 0, fmt, args); // FIXME-OPT: could do a first pass write attempt, likely successful on first pass.
  1172. if (len <= 0)
  1173. return;
  1174. const size_t write_off = Buf.size();
  1175. const size_t needed_sz = write_off + (size_t)len;
  1176. if (write_off + (size_t)len >= Buf.capacity())
  1177. {
  1178. const size_t double_capacity = Buf.capacity() * 2;
  1179. Buf.reserve(needed_sz > double_capacity ? needed_sz : double_capacity);
  1180. }
  1181. Buf.resize(needed_sz);
  1182. ImFormatStringV(&Buf[write_off] - 1, (size_t)len+1, fmt, args_copy);
  1183. }
  1184. void ImGuiTextBuffer::append(const char* fmt, ...)
  1185. {
  1186. va_list args;
  1187. va_start(args, fmt);
  1188. appendv(fmt, args);
  1189. va_end(args);
  1190. }
  1191. //-----------------------------------------------------------------------------
  1192. ImGuiWindow::ImGuiWindow(const char* name)
  1193. {
  1194. Name = ImStrdup(name);
  1195. ID = GetID(name);
  1196. IDStack.push_back(ID);
  1197. PosFloat = Pos = ImVec2(0.0f, 0.0f);
  1198. Size = SizeFull = ImVec2(0.0f, 0.0f);
  1199. SizeContentsFit = ImVec2(0.0f, 0.0f);
  1200. ScrollY = 0.0f;
  1201. NextScrollY = 0.0f;
  1202. ScrollbarY = false;
  1203. Visible = false;
  1204. Accessed = false;
  1205. Collapsed = false;
  1206. SkipItems = false;
  1207. AutoFitFrames = -1;
  1208. AutoFitOnlyGrows = false;
  1209. SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiSetCondition_Always | ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver;
  1210. LastFrameDrawn = -1;
  1211. ItemWidthDefault = 0.0f;
  1212. FontWindowScale = 1.0f;
  1213. if (ImLengthSqr(Size) < 0.00001f)
  1214. {
  1215. AutoFitFrames = 2;
  1216. AutoFitOnlyGrows = true;
  1217. }
  1218. DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList));
  1219. new(DrawList) ImDrawList();
  1220. FocusIdxAllCounter = FocusIdxTabCounter = -1;
  1221. FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = IM_INT_MAX;
  1222. FocusIdxAllRequestNext = FocusIdxTabRequestNext = IM_INT_MAX;
  1223. }
  1224. ImGuiWindow::~ImGuiWindow()
  1225. {
  1226. DrawList->~ImDrawList();
  1227. ImGui::MemFree(DrawList);
  1228. DrawList = NULL;
  1229. ImGui::MemFree(Name);
  1230. Name = NULL;
  1231. }
  1232. ImGuiID ImGuiWindow::GetID(const char* str)
  1233. {
  1234. const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back();
  1235. const ImGuiID id = ImCrc32(str, 0, seed);
  1236. RegisterAliveId(id);
  1237. return id;
  1238. }
  1239. ImGuiID ImGuiWindow::GetID(const void* ptr)
  1240. {
  1241. const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back();
  1242. const ImGuiID id = ImCrc32(&ptr, sizeof(void*), seed);
  1243. RegisterAliveId(id);
  1244. return id;
  1245. }
  1246. bool ImGuiWindow::FocusItemRegister(bool is_active, bool tab_stop)
  1247. {
  1248. ImGuiState& g = GImGui;
  1249. ImGuiWindow* window = GetCurrentWindow();
  1250. const bool allow_keyboard_focus = window->DC.AllowKeyboardFocus.back();
  1251. FocusIdxAllCounter++;
  1252. if (allow_keyboard_focus)
  1253. FocusIdxTabCounter++;
  1254. // Process keyboard input at this point: TAB, Shift-TAB switch focus
  1255. // We can always TAB out of a widget that doesn't allow tabbing in.
  1256. if (tab_stop && FocusIdxAllRequestNext == IM_INT_MAX && FocusIdxTabRequestNext == IM_INT_MAX && is_active && IsKeyPressedMap(ImGuiKey_Tab))
  1257. {
  1258. // Modulo on index will be applied at the end of frame once we've got the total counter of items.
  1259. FocusIdxTabRequestNext = FocusIdxTabCounter + (g.IO.KeyShift ? (allow_keyboard_focus ? -1 : 0) : +1);
  1260. }
  1261. if (FocusIdxAllCounter == FocusIdxAllRequestCurrent)
  1262. return true;
  1263. if (allow_keyboard_focus)
  1264. if (FocusIdxTabCounter == FocusIdxTabRequestCurrent)
  1265. return true;
  1266. return false;
  1267. }
  1268. void ImGuiWindow::FocusItemUnregister()
  1269. {
  1270. FocusIdxAllCounter--;
  1271. FocusIdxTabCounter--;
  1272. }
  1273. void ImGuiWindow::AddToRenderList()
  1274. {
  1275. ImGuiState& g = GImGui;
  1276. if (!DrawList->commands.empty() && !DrawList->vtx_buffer.empty())
  1277. {
  1278. if (DrawList->commands.back().vtx_count == 0)
  1279. DrawList->commands.pop_back();
  1280. g.RenderDrawLists.push_back(DrawList);
  1281. }
  1282. for (size_t i = 0; i < DC.ChildWindows.size(); i++)
  1283. {
  1284. ImGuiWindow* child = DC.ChildWindows[i];
  1285. if (child->Visible) // clipped childs may have been marked not Visible
  1286. child->AddToRenderList();
  1287. }
  1288. }
  1289. //-----------------------------------------------------------------------------
  1290. void* ImGui::MemAlloc(size_t sz)
  1291. {
  1292. return GImGui.IO.MemAllocFn(sz);
  1293. }
  1294. void ImGui::MemFree(void* ptr)
  1295. {
  1296. return GImGui.IO.MemFreeFn(ptr);
  1297. }
  1298. static ImGuiIniData* FindWindowSettings(const char* name)
  1299. {
  1300. ImGuiState& g = GImGui;
  1301. for (size_t i = 0; i != g.Settings.size(); i++)
  1302. {
  1303. ImGuiIniData* ini = g.Settings[i];
  1304. if (ImStricmp(ini->Name, name) == 0)
  1305. return ini;
  1306. }
  1307. return NULL;
  1308. }
  1309. static ImGuiIniData* AddWindowSettings(const char* name)
  1310. {
  1311. ImGuiIniData* ini = (ImGuiIniData*)ImGui::MemAlloc(sizeof(ImGuiIniData));
  1312. new(ini) ImGuiIniData();
  1313. ini->Name = ImStrdup(name);
  1314. ini->Collapsed = false;
  1315. ini->Pos = ImVec2(FLT_MAX,FLT_MAX);
  1316. ini->Size = ImVec2(0,0);
  1317. GImGui.Settings.push_back(ini);
  1318. return ini;
  1319. }
  1320. // Zero-tolerance, poor-man .ini parsing
  1321. // FIXME: Write something less rubbish
  1322. static void LoadSettings()
  1323. {
  1324. ImGuiState& g = GImGui;
  1325. const char* filename = g.IO.IniFilename;
  1326. if (!filename)
  1327. return;
  1328. char* file_data;
  1329. size_t file_size;
  1330. if (!ImLoadFileToMemory(filename, "rb", (void**)&file_data, &file_size, 1))
  1331. return;
  1332. ImGuiIniData* settings = NULL;
  1333. const char* buf_end = file_data + file_size;
  1334. for (const char* line_start = file_data; line_start < buf_end; )
  1335. {
  1336. const char* line_end = line_start;
  1337. while (line_end < buf_end && *line_end != '\n' && *line_end != '\r')
  1338. line_end++;
  1339. if (line_start[0] == '[' && line_end > line_start && line_end[-1] == ']')
  1340. {
  1341. char name[64];
  1342. ImFormatString(name, IM_ARRAYSIZE(name), "%.*s", line_end-line_start-2, line_start+1);
  1343. settings = FindWindowSettings(name);
  1344. if (!settings)
  1345. settings = AddWindowSettings(name);
  1346. }
  1347. else if (settings)
  1348. {
  1349. float x, y;
  1350. int i;
  1351. if (sscanf(line_start, "Pos=%f,%f", &x, &y) == 2)
  1352. settings->Pos = ImVec2(x, y);
  1353. else if (sscanf(line_start, "Size=%f,%f", &x, &y) == 2)
  1354. settings->Size = ImMax(ImVec2(x, y), g.Style.WindowMinSize);
  1355. else if (sscanf(line_start, "Collapsed=%d", &i) == 1)
  1356. settings->Collapsed = (i != 0);
  1357. }
  1358. line_start = line_end+1;
  1359. }
  1360. ImGui::MemFree(file_data);
  1361. }
  1362. static void SaveSettings()
  1363. {
  1364. ImGuiState& g = GImGui;
  1365. const char* filename = g.IO.IniFilename;
  1366. if (!filename)
  1367. return;
  1368. // Gather data from windows that were active during this session
  1369. for (size_t i = 0; i != g.Windows.size(); i++)
  1370. {
  1371. ImGuiWindow* window = g.Windows[i];
  1372. if (window->Flags & ImGuiWindowFlags_NoSavedSettings)
  1373. continue;
  1374. ImGuiIniData* settings = FindWindowSettings(window->Name);
  1375. settings->Pos = window->Pos;
  1376. settings->Size = window->SizeFull;
  1377. settings->Collapsed = window->Collapsed;
  1378. }
  1379. // Write .ini file
  1380. // If a window wasn't opened in this session we preserve its settings
  1381. FILE* f = fopen(filename, "wt");
  1382. if (!f)
  1383. return;
  1384. for (size_t i = 0; i != g.Settings.size(); i++)
  1385. {
  1386. const ImGuiIniData* settings = g.Settings[i];
  1387. if (settings->Pos.x == FLT_MAX)
  1388. continue;
  1389. fprintf(f, "[%s]\n", settings->Name);
  1390. fprintf(f, "Pos=%d,%d\n", (int)settings->Pos.x, (int)settings->Pos.y);
  1391. fprintf(f, "Size=%d,%d\n", (int)settings->Size.x, (int)settings->Size.y);
  1392. fprintf(f, "Collapsed=%d\n", settings->Collapsed);
  1393. fprintf(f, "\n");
  1394. }
  1395. fclose(f);
  1396. }
  1397. static void MarkSettingsDirty()
  1398. {
  1399. ImGuiState& g = GImGui;
  1400. if (g.SettingsDirtyTimer <= 0.0f)
  1401. g.SettingsDirtyTimer = g.IO.IniSavingRate;
  1402. }
  1403. ImGuiIO& ImGui::GetIO()
  1404. {
  1405. return GImGui.IO;
  1406. }
  1407. ImGuiStyle& ImGui::GetStyle()
  1408. {
  1409. return GImGui.Style;
  1410. }
  1411. void ImGui::NewFrame()
  1412. {
  1413. ImGuiState& g = GImGui;
  1414. // Check user data
  1415. IM_ASSERT(g.IO.DeltaTime > 0.0f);
  1416. IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f);
  1417. IM_ASSERT(g.IO.RenderDrawListsFn != NULL); // Must be implemented
  1418. IM_ASSERT(g.IO.Fonts->Fonts.size() > 0); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
  1419. IM_ASSERT(g.IO.Fonts->Fonts[0]->IsLoaded()); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
  1420. if (!g.Initialized)
  1421. {
  1422. // Initialize on first frame
  1423. g.LogClipboard = (ImGuiTextBuffer*)ImGui::MemAlloc(sizeof(ImGuiTextBuffer));
  1424. new(g.LogClipboard) ImGuiTextBuffer();
  1425. IM_ASSERT(g.Settings.empty());
  1426. LoadSettings();
  1427. g.Initialized = true;
  1428. }
  1429. SetFont(g.IO.Fonts->Fonts[0]);
  1430. g.Time += g.IO.DeltaTime;
  1431. g.FrameCount += 1;
  1432. g.Tooltip[0] = '\0';
  1433. // Update inputs state
  1434. if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0)
  1435. g.IO.MousePos = ImVec2(-9999.0f, -9999.0f);
  1436. 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
  1437. g.IO.MouseDelta = ImVec2(0.0f, 0.0f);
  1438. else
  1439. g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
  1440. g.IO.MousePosPrev = g.IO.MousePos;
  1441. for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
  1442. {
  1443. 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;
  1444. g.IO.MouseClicked[i] = (g.IO.MouseDownTime[i] == 0.0f);
  1445. g.IO.MouseDoubleClicked[i] = false;
  1446. if (g.IO.MouseClicked[i])
  1447. {
  1448. if (g.Time - g.IO.MouseClickedTime[i] < g.IO.MouseDoubleClickTime)
  1449. {
  1450. if (ImLengthSqr(g.IO.MousePos - g.IO.MouseClickedPos[i]) < g.IO.MouseDoubleClickMaxDist * g.IO.MouseDoubleClickMaxDist)
  1451. g.IO.MouseDoubleClicked[i] = true;
  1452. g.IO.MouseClickedTime[i] = -FLT_MAX; // so the third click isn't turned into a double-click
  1453. }
  1454. else
  1455. {
  1456. g.IO.MouseClickedTime[i] = g.Time;
  1457. g.IO.MouseClickedPos[i] = g.IO.MousePos;
  1458. }
  1459. }
  1460. }
  1461. for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++)
  1462. 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;
  1463. // Clear reference to active widget if the widget isn't alive anymore
  1464. g.HoveredId = 0;
  1465. if (!g.ActiveIdIsAlive && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0)
  1466. SetActiveId(0);
  1467. g.ActiveIdPreviousFrame = g.ActiveId;
  1468. g.ActiveIdIsAlive = false;
  1469. // Delay saving settings so we don't spam disk too much
  1470. if (g.SettingsDirtyTimer > 0.0f)
  1471. {
  1472. g.SettingsDirtyTimer -= g.IO.DeltaTime;
  1473. if (g.SettingsDirtyTimer <= 0.0f)
  1474. SaveSettings();
  1475. }
  1476. // Find the window we are hovering. Child windows can extend beyond the limit of their parent so we need to derive HoveredRootWindow from HoveredWindow
  1477. g.HoveredWindow = FindHoveredWindow(g.IO.MousePos, false);
  1478. if (g.HoveredWindow && (g.HoveredWindow->Flags & ImGuiWindowFlags_ChildWindow))
  1479. g.HoveredRootWindow = g.HoveredWindow->RootWindow;
  1480. else
  1481. g.HoveredRootWindow = FindHoveredWindow(g.IO.MousePos, true);
  1482. // Are we using inputs? Tell user so they can capture/discard the inputs away from the rest of their application.
  1483. // When clicking outside of a window we assume the click is owned by the application and won't request capture.
  1484. int mouse_earliest_button_down = -1;
  1485. for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
  1486. {
  1487. if (g.IO.MouseClicked[i])
  1488. g.IO.MouseDownOwned[i] = (g.HoveredWindow != NULL);
  1489. if (g.IO.MouseDown[i])
  1490. if (mouse_earliest_button_down == -1 || g.IO.MouseClickedTime[mouse_earliest_button_down] > g.IO.MouseClickedTime[i])
  1491. mouse_earliest_button_down = i;
  1492. }
  1493. bool mouse_owned_by_application = mouse_earliest_button_down != -1 && !g.IO.MouseDownOwned[mouse_earliest_button_down];
  1494. g.IO.WantCaptureMouse = (!mouse_owned_by_application && g.HoveredWindow != NULL) || (g.ActiveId != 0);
  1495. g.IO.WantCaptureKeyboard = (g.ActiveId != 0);
  1496. // If mouse was first clicked outside of ImGui bounds we also cancel out hovering.
  1497. if (mouse_owned_by_application)
  1498. g.HoveredWindow = g.HoveredRootWindow = NULL;
  1499. // Scale & Scrolling
  1500. if (g.HoveredWindow && g.IO.MouseWheel != 0.0f)
  1501. {
  1502. ImGuiWindow* window = g.HoveredWindow;
  1503. if (g.IO.KeyCtrl)
  1504. {
  1505. if (g.IO.FontAllowUserScaling)
  1506. {
  1507. // Zoom / Scale window
  1508. float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
  1509. float scale = new_font_scale / window->FontWindowScale;
  1510. window->FontWindowScale = new_font_scale;
  1511. const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size;
  1512. window->Pos += offset;
  1513. window->PosFloat += offset;
  1514. window->Size *= scale;
  1515. window->SizeFull *= scale;
  1516. }
  1517. }
  1518. else
  1519. {
  1520. // Scroll
  1521. if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse))
  1522. {
  1523. const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5;
  1524. window->NextScrollY -= g.IO.MouseWheel * window->FontSize() * scroll_lines;
  1525. }
  1526. }
  1527. }
  1528. // Pressing TAB activate widget focus
  1529. // 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.
  1530. if (g.ActiveId == 0 && g.FocusedWindow != NULL && g.FocusedWindow->Visible && IsKeyPressedMap(ImGuiKey_Tab, false))
  1531. {
  1532. g.FocusedWindow->FocusIdxTabRequestNext = 0;
  1533. }
  1534. // Mark all windows as not visible
  1535. // Clear root windows at this point.
  1536. for (size_t i = 0; i != g.Windows.size(); i++)
  1537. {
  1538. ImGuiWindow* window = g.Windows[i];
  1539. window->Visible = false;
  1540. window->Accessed = false;
  1541. window->RootWindow = NULL;
  1542. }
  1543. // No window should be open at the beginning of the frame.
  1544. // But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear.
  1545. g.CurrentWindowStack.resize(0);
  1546. // Create implicit window - we will only render it if the user has added something to it.
  1547. ImGui::Begin("Debug", NULL, ImVec2(400,400));
  1548. }
  1549. // NB: behaviour of ImGui after Shutdown() is not tested/guaranteed at the moment. This function is merely here to free heap allocations.
  1550. void ImGui::Shutdown()
  1551. {
  1552. ImGuiState& g = GImGui;
  1553. if (!g.Initialized)
  1554. return;
  1555. SaveSettings();
  1556. for (size_t i = 0; i < g.Windows.size(); i++)
  1557. {
  1558. g.Windows[i]->~ImGuiWindow();
  1559. ImGui::MemFree(g.Windows[i]);
  1560. }
  1561. g.Windows.clear();
  1562. g.CurrentWindowStack.clear();
  1563. g.RenderDrawLists.clear();
  1564. g.FocusedWindow = NULL;
  1565. g.HoveredWindow = NULL;
  1566. g.HoveredRootWindow = NULL;
  1567. for (size_t i = 0; i < g.Settings.size(); i++)
  1568. {
  1569. g.Settings[i]->~ImGuiIniData();
  1570. ImGui::MemFree(g.Settings[i]);
  1571. }
  1572. g.Settings.clear();
  1573. g.ColorModifiers.clear();
  1574. g.StyleModifiers.clear();
  1575. g.FontStack.clear();
  1576. g.ColorEditModeStorage.Clear();
  1577. if (g.LogFile && g.LogFile != stdout)
  1578. {
  1579. fclose(g.LogFile);
  1580. g.LogFile = NULL;
  1581. }
  1582. g.IO.Fonts->Clear();
  1583. if (g.PrivateClipboard)
  1584. {
  1585. ImGui::MemFree(g.PrivateClipboard);
  1586. g.PrivateClipboard = NULL;
  1587. }
  1588. if (g.LogClipboard)
  1589. {
  1590. g.LogClipboard->~ImGuiTextBuffer();
  1591. ImGui::MemFree(g.LogClipboard);
  1592. }
  1593. g.Initialized = false;
  1594. }
  1595. static void AddWindowToSortedBuffer(ImGuiWindow* window, ImVector<ImGuiWindow*>& sorted_windows)
  1596. {
  1597. sorted_windows.push_back(window);
  1598. if (window->Visible)
  1599. {
  1600. for (size_t i = 0; i < window->DC.ChildWindows.size(); i++)
  1601. {
  1602. ImGuiWindow* child = window->DC.ChildWindows[i];
  1603. if (child->Visible)
  1604. AddWindowToSortedBuffer(child, sorted_windows);
  1605. }
  1606. }
  1607. }
  1608. static void PushClipRect(const ImVec4& clip_rect, bool clipped = true)
  1609. {
  1610. ImGuiWindow* window = GetCurrentWindow();
  1611. ImVec4 cr = clip_rect;
  1612. if (clipped && !window->ClipRectStack.empty())
  1613. {
  1614. // Clip with existing clip rect
  1615. const ImVec4 cur_cr = window->ClipRectStack.back();
  1616. 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));
  1617. }
  1618. window->ClipRectStack.push_back(cr);
  1619. window->DrawList->PushClipRect(cr);
  1620. }
  1621. static void PopClipRect()
  1622. {
  1623. ImGuiWindow* window = GetCurrentWindow();
  1624. window->ClipRectStack.pop_back();
  1625. window->DrawList->PopClipRect();
  1626. }
  1627. void ImGui::Render()
  1628. {
  1629. ImGuiState& g = GImGui;
  1630. IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame()
  1631. const bool first_render_of_the_frame = (g.FrameCountRendered != g.FrameCount);
  1632. g.FrameCountRendered = g.FrameCount;
  1633. if (first_render_of_the_frame)
  1634. {
  1635. // Hide implicit window if it hasn't been used
  1636. IM_ASSERT(g.CurrentWindowStack.size() == 1); // Mismatched Begin/End
  1637. if (g.CurrentWindow && !g.CurrentWindow->Accessed)
  1638. g.CurrentWindow->Visible = false;
  1639. ImGui::End();
  1640. // Select window for move/focus when we're done with all our widgets (we only consider non-childs windows here)
  1641. if (g.ActiveId == 0 && g.HoveredId == 0 && g.HoveredRootWindow != NULL && g.IO.MouseClicked[0])
  1642. SetActiveId(g.HoveredRootWindow->GetID("#MOVE"));
  1643. // Sort the window list so that all child windows are after their parent
  1644. // We cannot do that on FocusWindow() because childs may not exist yet
  1645. g.RenderSortedWindows.resize(0);
  1646. g.RenderSortedWindows.reserve(g.Windows.size());
  1647. for (size_t i = 0; i != g.Windows.size(); i++)
  1648. {
  1649. ImGuiWindow* window = g.Windows[i];
  1650. if (window->Flags & ImGuiWindowFlags_ChildWindow) // if a child is visible its parent will add it
  1651. if (window->Visible)
  1652. continue;
  1653. AddWindowToSortedBuffer(window, g.RenderSortedWindows);
  1654. }
  1655. IM_ASSERT(g.Windows.size() == g.RenderSortedWindows.size()); // We done something wrong
  1656. g.Windows.swap(g.RenderSortedWindows);
  1657. // Clear data for next frame
  1658. g.IO.MouseWheel = 0.0f;
  1659. memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters));
  1660. }
  1661. // Skip render altogether if alpha is 0.0
  1662. // Note that vertex buffers have been created, so it is best practice that you don't call Begin/End in the first place.
  1663. if (g.Style.Alpha > 0.0f)
  1664. {
  1665. // Render tooltip
  1666. if (g.Tooltip[0])
  1667. {
  1668. // Use a dummy window to render the tooltip
  1669. ImGui::BeginTooltip();
  1670. ImGui::TextUnformatted(g.Tooltip);
  1671. ImGui::EndTooltip();
  1672. }
  1673. // Gather windows to render
  1674. g.RenderDrawLists.resize(0);
  1675. for (size_t i = 0; i != g.Windows.size(); i++)
  1676. {
  1677. ImGuiWindow* window = g.Windows[i];
  1678. if (window->Visible && (window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) == 0)
  1679. window->AddToRenderList();
  1680. }
  1681. for (size_t i = 0; i != g.Windows.size(); i++)
  1682. {
  1683. ImGuiWindow* window = g.Windows[i];
  1684. if (window->Visible && (window->Flags & ImGuiWindowFlags_Tooltip))
  1685. window->AddToRenderList();
  1686. }
  1687. if (g.IO.MouseDrawCursor)
  1688. {
  1689. const ImVec2 pos = g.IO.MousePos;
  1690. const ImVec2 size = TEX_ATLAS_SIZE_MOUSE_CURSOR;
  1691. const ImTextureID tex_id = g.IO.Fonts->TexID;
  1692. const ImVec2 tex_uv_scale(1.0f/g.IO.Fonts->TexWidth, 1.0f/g.IO.Fonts->TexHeight);
  1693. static ImDrawList draw_list;
  1694. draw_list.Clear();
  1695. draw_list.AddImage(tex_id, pos+ImVec2(1,0), pos+ImVec2(1,0) + size, TEX_ATLAS_POS_MOUSE_CURSOR_BLACK * tex_uv_scale, (TEX_ATLAS_POS_MOUSE_CURSOR_BLACK + size) * tex_uv_scale, 0x30000000); // Shadow
  1696. draw_list.AddImage(tex_id, pos+ImVec2(2,0), pos+ImVec2(2,0) + size, TEX_ATLAS_POS_MOUSE_CURSOR_BLACK * tex_uv_scale, (TEX_ATLAS_POS_MOUSE_CURSOR_BLACK + size) * tex_uv_scale, 0x30000000); // Shadow
  1697. draw_list.AddImage(tex_id, pos, pos + size, TEX_ATLAS_POS_MOUSE_CURSOR_BLACK * tex_uv_scale, (TEX_ATLAS_POS_MOUSE_CURSOR_BLACK + size) * tex_uv_scale, 0xFF000000); // Black border
  1698. draw_list.AddImage(tex_id, pos, pos + size, TEX_ATLAS_POS_MOUSE_CURSOR_WHITE * tex_uv_scale, (TEX_ATLAS_POS_MOUSE_CURSOR_WHITE + size) * tex_uv_scale, 0xFFFFFFFF); // White fill
  1699. g.RenderDrawLists.push_back(&draw_list);
  1700. }
  1701. // Render
  1702. if (!g.RenderDrawLists.empty())
  1703. g.IO.RenderDrawListsFn(&g.RenderDrawLists[0], (int)g.RenderDrawLists.size());
  1704. g.RenderDrawLists.resize(0);
  1705. }
  1706. }
  1707. // Find the optional ## from which we stop displaying text.
  1708. static const char* FindTextDisplayEnd(const char* text, const char* text_end = NULL)
  1709. {
  1710. const char* text_display_end = text;
  1711. while ((!text_end || text_display_end < text_end) && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#'))
  1712. text_display_end++;
  1713. return text_display_end;
  1714. }
  1715. // Pass text data straight to log (without being displayed)
  1716. void ImGui::LogText(const char* fmt, ...)
  1717. {
  1718. ImGuiState& g = GImGui;
  1719. if (!g.LogEnabled)
  1720. return;
  1721. va_list args;
  1722. va_start(args, fmt);
  1723. if (g.LogFile)
  1724. {
  1725. vfprintf(g.LogFile, fmt, args);
  1726. }
  1727. else
  1728. {
  1729. g.LogClipboard->appendv(fmt, args);
  1730. }
  1731. va_end(args);
  1732. }
  1733. // Internal version that takes a position to decide on newline placement and pad items according to their depth.
  1734. static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end)
  1735. {
  1736. ImGuiState& g = GImGui;
  1737. ImGuiWindow* window = GetCurrentWindow();
  1738. if (!text_end)
  1739. text_end = FindTextDisplayEnd(text, text_end);
  1740. const bool log_new_line = ref_pos.y > window->DC.LogLineHeight+1;
  1741. window->DC.LogLineHeight = ref_pos.y;
  1742. const char* text_remaining = text;
  1743. if (g.LogStartDepth > window->DC.TreeDepth) // Re-adjust padding if we have popped out of our starting depth
  1744. g.LogStartDepth = window->DC.TreeDepth;
  1745. const int tree_depth = (window->DC.TreeDepth - g.LogStartDepth);
  1746. for (;;)
  1747. {
  1748. // Split the string. Each new line (after a '\n') is followed by spacing corresponding to the current depth of our log entry.
  1749. const char* line_end = text_remaining;
  1750. while (line_end < text_end)
  1751. if (*line_end == '\n')
  1752. break;
  1753. else
  1754. line_end++;
  1755. if (line_end >= text_end)
  1756. line_end = NULL;
  1757. const bool is_first_line = (text == text_remaining);
  1758. bool is_last_line = false;
  1759. if (line_end == NULL)
  1760. {
  1761. is_last_line = true;
  1762. line_end = text_end;
  1763. }
  1764. if (line_end != NULL && !(is_last_line && (line_end - text_remaining)==0))
  1765. {
  1766. const int char_count = (int)(line_end - text_remaining);
  1767. if (log_new_line || !is_first_line)
  1768. ImGui::LogText(STR_NEWLINE "%*s%.*s", tree_depth*4, "", char_count, text_remaining);
  1769. else
  1770. ImGui::LogText(" %.*s", char_count, text_remaining);
  1771. }
  1772. if (is_last_line)
  1773. break;
  1774. text_remaining = line_end + 1;
  1775. }
  1776. }
  1777. static float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
  1778. {
  1779. if (wrap_pos_x < 0.0f)
  1780. return 0.0f;
  1781. ImGuiWindow* window = GetCurrentWindow();
  1782. if (wrap_pos_x == 0.0f)
  1783. wrap_pos_x = ImGui::GetContentRegionMax().x;
  1784. if (wrap_pos_x > 0.0f)
  1785. wrap_pos_x += window->Pos.x; // wrap_pos_x is provided is window local space
  1786. const float wrap_width = wrap_pos_x > 0.0f ? ImMax(wrap_pos_x - pos.x, 0.00001f) : 0.0f;
  1787. return wrap_width;
  1788. }
  1789. // Internal ImGui function to render text (called from ImGui::Text(), ImGui::TextUnformatted(), etc.)
  1790. // RenderText() calls ImDrawList::AddText() calls ImBitmapFont::RenderText()
  1791. static void RenderText(ImVec2 pos, const char* text, const char* text_end, bool hide_text_after_hash, float wrap_width)
  1792. {
  1793. ImGuiState& g = GImGui;
  1794. ImGuiWindow* window = GetCurrentWindow();
  1795. // Hide anything after a '##' string
  1796. const char* text_display_end;
  1797. if (hide_text_after_hash)
  1798. {
  1799. text_display_end = FindTextDisplayEnd(text, text_end);
  1800. }
  1801. else
  1802. {
  1803. if (!text_end)
  1804. text_end = text + strlen(text); // FIXME-OPT
  1805. text_display_end = text_end;
  1806. }
  1807. const int text_len = (int)(text_display_end - text);
  1808. if (text_len > 0)
  1809. {
  1810. // Render
  1811. window->DrawList->AddText(window->Font(), window->FontSize(), pos, window->Color(ImGuiCol_Text), text, text + text_len, wrap_width);
  1812. // Log as text. We split text into individual lines to add current tree level padding
  1813. if (g.LogEnabled)
  1814. LogText(pos, text, text_display_end);
  1815. }
  1816. }
  1817. // Render a rectangle shaped with optional rounding and borders
  1818. static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, float rounding)
  1819. {
  1820. ImGuiWindow* window = GetCurrentWindow();
  1821. window->DrawList->AddRectFilled(p_min, p_max, fill_col, rounding);
  1822. if (border && (window->Flags & ImGuiWindowFlags_ShowBorders))
  1823. {
  1824. // FIXME: This is the best I've found that works on multiple renderer/back ends. Bit dodgy.
  1825. window->DrawList->AddRect(p_min+ImVec2(1.5f,1.5f), p_max+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), rounding);
  1826. window->DrawList->AddRect(p_min+ImVec2(0.5f,0.5f), p_max+ImVec2(0,0), window->Color(ImGuiCol_Border), rounding);
  1827. }
  1828. }
  1829. // Render a triangle to denote expanded/collapsed state
  1830. static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale, bool shadow)
  1831. {
  1832. ImGuiWindow* window = GetCurrentWindow();
  1833. const float h = window->FontSize() * 1.00f;
  1834. const float r = h * 0.40f * scale;
  1835. ImVec2 center = p_min + ImVec2(h*0.50f, h*0.50f*scale);
  1836. ImVec2 a, b, c;
  1837. if (opened)
  1838. {
  1839. center.y -= r*0.25f;
  1840. a = center + ImVec2(0,1)*r;
  1841. b = center + ImVec2(-0.866f,-0.5f)*r;
  1842. c = center + ImVec2(0.866f,-0.5f)*r;
  1843. }
  1844. else
  1845. {
  1846. a = center + ImVec2(1,0)*r;
  1847. b = center + ImVec2(-0.500f,0.866f)*r;
  1848. c = center + ImVec2(-0.500f,-0.866f)*r;
  1849. }
  1850. if (shadow && (window->Flags & ImGuiWindowFlags_ShowBorders) != 0)
  1851. window->DrawList->AddTriangleFilled(a+ImVec2(2,2), b+ImVec2(2,2), c+ImVec2(2,2), window->Color(ImGuiCol_BorderShadow));
  1852. window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Border));
  1853. }
  1854. // Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker.
  1855. // CalcTextSize("") should return ImVec2(0.0f, GImGui.FontSize)
  1856. ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width)
  1857. {
  1858. ImGuiWindow* window = GetCurrentWindow();
  1859. const char* text_display_end;
  1860. if (hide_text_after_double_hash)
  1861. text_display_end = FindTextDisplayEnd(text, text_end); // Hide anything after a '##' string
  1862. else
  1863. text_display_end = text_end;
  1864. ImFont* font = window->Font();
  1865. const float font_size = window->FontSize();
  1866. ImVec2 text_size = font->CalcTextSizeA(font_size, FLT_MAX, wrap_width, text, text_display_end, NULL);
  1867. // Cancel out character spacing for the last character of a line (it is baked into glyph->XAdvance field)
  1868. const float font_scale = font_size / font->FontSize;
  1869. const float character_spacing_x = 1.0f * font_scale;
  1870. if (text_size.x > 0.0f)
  1871. text_size.x -= character_spacing_x;
  1872. return text_size;
  1873. }
  1874. // Find window given position, search front-to-back
  1875. static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs)
  1876. {
  1877. ImGuiState& g = GImGui;
  1878. for (int i = (int)g.Windows.size()-1; i >= 0; i--)
  1879. {
  1880. ImGuiWindow* window = g.Windows[(size_t)i];
  1881. if (!window->Visible)
  1882. continue;
  1883. if (excluding_childs && (window->Flags & ImGuiWindowFlags_ChildWindow) != 0)
  1884. continue;
  1885. ImGuiAabb bb(window->Pos - g.Style.TouchExtraPadding, window->Pos + window->Size + g.Style.TouchExtraPadding);
  1886. if (bb.Contains(pos))
  1887. return window;
  1888. }
  1889. return NULL;
  1890. }
  1891. // Test if mouse cursor is hovering given aabb
  1892. // NB- Box is clipped by our current clip setting
  1893. // NB- Expand the aabb to be generous on imprecise inputs systems (g.Style.TouchExtraPadding)
  1894. static bool IsMouseHoveringBox(const ImGuiAabb& box)
  1895. {
  1896. ImGuiState& g = GImGui;
  1897. ImGuiWindow* window = GetCurrentWindow();
  1898. // Clip
  1899. ImGuiAabb box_clipped = box;
  1900. if (!window->ClipRectStack.empty())
  1901. {
  1902. const ImVec4 clip_rect = window->ClipRectStack.back();
  1903. box_clipped.Clip(ImGuiAabb(ImVec2(clip_rect.x, clip_rect.y), ImVec2(clip_rect.z, clip_rect.w)));
  1904. }
  1905. // Expand for touch input
  1906. const ImGuiAabb box_for_touch(box_clipped.Min - g.Style.TouchExtraPadding, box_clipped.Max + g.Style.TouchExtraPadding);
  1907. return box_for_touch.Contains(g.IO.MousePos);
  1908. }
  1909. bool ImGui::IsMouseHoveringBox(const ImVec2& box_min, const ImVec2& box_max)
  1910. {
  1911. return IsMouseHoveringBox(ImGuiAabb(box_min, box_max));
  1912. }
  1913. bool ImGui::IsMouseHoveringWindow()
  1914. {
  1915. ImGuiState& g = GImGui;
  1916. ImGuiWindow* window = GetCurrentWindow();
  1917. return g.HoveredWindow == window;
  1918. }
  1919. bool ImGui::IsMouseHoveringAnyWindow()
  1920. {
  1921. ImGuiState& g = GImGui;
  1922. return g.HoveredWindow != NULL;
  1923. }
  1924. bool ImGui::IsPosHoveringAnyWindow(const ImVec2& pos)
  1925. {
  1926. return FindHoveredWindow(pos, false) != NULL;
  1927. }
  1928. static bool IsKeyPressedMap(ImGuiKey key, bool repeat)
  1929. {
  1930. ImGuiState& g = GImGui;
  1931. const int key_index = g.IO.KeyMap[key];
  1932. return ImGui::IsKeyPressed(key_index, repeat);
  1933. }
  1934. bool ImGui::IsKeyPressed(int key_index, bool repeat)
  1935. {
  1936. ImGuiState& g = GImGui;
  1937. IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown));
  1938. const float t = g.IO.KeysDownTime[key_index];
  1939. if (t == 0.0f)
  1940. return true;
  1941. // FIXME: Repeat rate should be provided elsewhere?
  1942. const float KEY_REPEAT_DELAY = 0.250f;
  1943. const float KEY_REPEAT_RATE = 0.020f;
  1944. if (repeat && t > KEY_REPEAT_DELAY)
  1945. 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))
  1946. return true;
  1947. return false;
  1948. }
  1949. bool ImGui::IsMouseClicked(int button, bool repeat)
  1950. {
  1951. ImGuiState& g = GImGui;
  1952. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  1953. const float t = g.IO.MouseDownTime[button];
  1954. if (t == 0.0f)
  1955. return true;
  1956. // FIXME: Repeat rate should be provided elsewhere?
  1957. const float MOUSE_REPEAT_DELAY = 0.250f;
  1958. const float MOUSE_REPEAT_RATE = 0.020f;
  1959. if (repeat && t > MOUSE_REPEAT_DELAY)
  1960. 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))
  1961. return true;
  1962. return false;
  1963. }
  1964. bool ImGui::IsMouseDoubleClicked(int button)
  1965. {
  1966. ImGuiState& g = GImGui;
  1967. IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
  1968. return g.IO.MouseDoubleClicked[button];
  1969. }
  1970. ImVec2 ImGui::GetMousePos()
  1971. {
  1972. return GImGui.IO.MousePos;
  1973. }
  1974. bool ImGui::IsItemHovered()
  1975. {
  1976. ImGuiWindow* window = GetCurrentWindow();
  1977. return window->DC.LastItemHovered;
  1978. }
  1979. bool ImGui::IsItemActive()
  1980. {
  1981. ImGuiState& g = GImGui;
  1982. if (g.ActiveId)
  1983. {
  1984. ImGuiWindow* window = GetCurrentWindow();
  1985. return g.ActiveId == window->DC.LastItemID;
  1986. }
  1987. return false;
  1988. }
  1989. ImVec2 ImGui::GetItemBoxMin()
  1990. {
  1991. ImGuiWindow* window = GetCurrentWindow();
  1992. return window->DC.LastItemAabb.Min;
  1993. }
  1994. ImVec2 ImGui::GetItemBoxMax()
  1995. {
  1996. ImGuiWindow* window = GetCurrentWindow();
  1997. return window->DC.LastItemAabb.Max;
  1998. }
  1999. // Tooltip is stored and turned into a BeginTooltip()/EndTooltip() sequence at the end of the frame. Each call override previous value.
  2000. void ImGui::SetTooltipV(const char* fmt, va_list args)
  2001. {
  2002. ImGuiState& g = GImGui;
  2003. ImFormatStringV(g.Tooltip, IM_ARRAYSIZE(g.Tooltip), fmt, args);
  2004. }
  2005. void ImGui::SetTooltip(const char* fmt, ...)
  2006. {
  2007. va_list args;
  2008. va_start(args, fmt);
  2009. SetTooltipV(fmt, args);
  2010. va_end(args);
  2011. }
  2012. float ImGui::GetTime()
  2013. {
  2014. return GImGui.Time;
  2015. }
  2016. int ImGui::GetFrameCount()
  2017. {
  2018. return GImGui.FrameCount;
  2019. }
  2020. void ImGui::BeginTooltip()
  2021. {
  2022. ImGuiState& g = GImGui;
  2023. ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_Tooltip;
  2024. ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), g.Style.Colors[ImGuiCol_TooltipBg].w, window_flags);
  2025. }
  2026. void ImGui::EndTooltip()
  2027. {
  2028. IM_ASSERT(GetCurrentWindow()->Flags & ImGuiWindowFlags_Tooltip);
  2029. ImGui::End();
  2030. }
  2031. void ImGui::BeginChild(const char* str_id, ImVec2 size, bool border, ImGuiWindowFlags extra_flags)
  2032. {
  2033. ImGuiState& g = GImGui;
  2034. ImGuiWindow* window = GetCurrentWindow();
  2035. ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_ChildWindow;
  2036. const ImVec2 content_max = window->Pos + ImGui::GetContentRegionMax();
  2037. const ImVec2 cursor_pos = window->Pos + ImGui::GetCursorPos();
  2038. if (size.x <= 0.0f)
  2039. {
  2040. if (size.x == 0.0f)
  2041. flags |= ImGuiWindowFlags_ChildWindowAutoFitX;
  2042. size.x = ImMax(content_max.x - cursor_pos.x, g.Style.WindowMinSize.x) - fabsf(size.x);
  2043. }
  2044. if (size.y <= 0.0f)
  2045. {
  2046. if (size.y == 0.0f)
  2047. flags |= ImGuiWindowFlags_ChildWindowAutoFitY;
  2048. size.y = ImMax(content_max.y - cursor_pos.y, g.Style.WindowMinSize.y) - fabsf(size.y);
  2049. }
  2050. if (border)
  2051. flags |= ImGuiWindowFlags_ShowBorders;
  2052. flags |= extra_flags;
  2053. char title[256];
  2054. ImFormatString(title, IM_ARRAYSIZE(title), "%s.%s", window->Name, str_id);
  2055. const float alpha = (flags & ImGuiWindowFlags_ComboBox) ? 1.0f : 0.0f;
  2056. ImGui::Begin(title, NULL, size, alpha, flags);
  2057. if (!(window->Flags & ImGuiWindowFlags_ShowBorders))
  2058. g.CurrentWindow->Flags &= ~ImGuiWindowFlags_ShowBorders;
  2059. }
  2060. void ImGui::EndChild()
  2061. {
  2062. ImGuiWindow* window = GetCurrentWindow();
  2063. IM_ASSERT(window->Flags & ImGuiWindowFlags_ChildWindow);
  2064. if (window->Flags & ImGuiWindowFlags_ComboBox)
  2065. {
  2066. ImGui::End();
  2067. }
  2068. else
  2069. {
  2070. // 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.
  2071. ImVec2 sz = ImGui::GetWindowSize();
  2072. if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitX)
  2073. sz.x = 0;
  2074. if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitY)
  2075. sz.y = 0;
  2076. ImGui::End();
  2077. ItemSize(sz);
  2078. }
  2079. }
  2080. static ImGuiWindow* FindWindowByName(const char* name)
  2081. {
  2082. // FIXME-OPT: Consider optimizing this (e.g. sorted hashes to window pointers)
  2083. ImGuiState& g = GImGui;
  2084. for (size_t i = 0; i != g.Windows.size(); i++)
  2085. if (strcmp(g.Windows[i]->Name, name) == 0)
  2086. return g.Windows[i];
  2087. return NULL;
  2088. }
  2089. static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFlags flags)
  2090. {
  2091. ImGuiState& g = GImGui;
  2092. // Create window the first time
  2093. ImGuiWindow* window = (ImGuiWindow*)ImGui::MemAlloc(sizeof(ImGuiWindow));
  2094. new(window) ImGuiWindow(name);
  2095. window->Flags = flags;
  2096. if (flags & ImGuiWindowFlags_NoSavedSettings)
  2097. {
  2098. // User can disable loading and saving of settings. Tooltip and child windows also don't store settings.
  2099. window->Size = window->SizeFull = size;
  2100. }
  2101. else
  2102. {
  2103. // Retrieve settings from .ini file
  2104. // Use SetWindowPos() or SetNextWindowPos() with the appropriate condition flag to change the initial position of a window.
  2105. window->PosFloat = ImVec2(60, 60);
  2106. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  2107. ImGuiIniData* settings = FindWindowSettings(name);
  2108. if (!settings)
  2109. {
  2110. settings = AddWindowSettings(name);
  2111. }
  2112. else
  2113. {
  2114. window->SetWindowPosAllowFlags &= ~ImGuiSetCondition_FirstUseEver;
  2115. window->SetWindowSizeAllowFlags &= ~ImGuiSetCondition_FirstUseEver;
  2116. window->SetWindowCollapsedAllowFlags &= ~ImGuiSetCondition_FirstUseEver;
  2117. }
  2118. if (settings->Pos.x != FLT_MAX)
  2119. {
  2120. window->PosFloat = settings->Pos;
  2121. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  2122. window->Collapsed = settings->Collapsed;
  2123. }
  2124. if (ImLengthSqr(settings->Size) > 0.00001f && !(flags & ImGuiWindowFlags_NoResize))
  2125. size = settings->Size;
  2126. window->Size = window->SizeFull = size;
  2127. }
  2128. g.Windows.push_back(window);
  2129. return window;
  2130. }
  2131. // Push a new ImGui window to add widgets to.
  2132. // - A default window called "Debug" is automatically stacked at the beginning of every frame.
  2133. // - This can be called multiple times during the frame with the same window name to append content to the same window.
  2134. // - The window name is used as a unique identifier to preserve window information across frames (and save rudimentary information to the .ini file). Note that you can use ## to append unique data that isn't displayed, e.g. "My window##1" will use "My window##1" as unique window ID but display "My window" to the user.
  2135. // - Return false when window is collapsed, so you can early out in your code. You always need to call ImGui::End() even if false is returned.
  2136. // - Passing 'bool* p_opened' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed.
  2137. // - Passing non-zero 'size' is roughly equivalent to calling SetNextWindowSize(size, ImGuiSetCondition_FirstUseEver) prior to calling Begin().
  2138. bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alpha, ImGuiWindowFlags flags)
  2139. {
  2140. ImGuiState& g = GImGui;
  2141. const ImGuiStyle& style = g.Style;
  2142. IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame()
  2143. IM_ASSERT(name != NULL); // Must pass a name
  2144. // Find or create
  2145. ImGuiWindow* window = FindWindowByName(name);
  2146. if (!window)
  2147. window = CreateNewWindow(name, size, flags);
  2148. window->Flags = (ImGuiWindowFlags)flags;
  2149. // Add to stack
  2150. g.CurrentWindowStack.push_back(window);
  2151. g.CurrentWindow = window;
  2152. // Process SetNextWindow***() calls
  2153. bool window_pos_set_by_api = false;
  2154. if (g.SetNextWindowPosCond)
  2155. {
  2156. const ImVec2 backup_cursor_pos = window->DC.CursorPos;
  2157. ImGui::SetWindowPos(g.SetNextWindowPosVal, g.SetNextWindowPosCond);
  2158. window->DC.CursorPos = backup_cursor_pos;
  2159. window_pos_set_by_api = true;
  2160. g.SetNextWindowPosCond = 0;
  2161. }
  2162. if (g.SetNextWindowSizeCond)
  2163. {
  2164. ImGui::SetWindowSize(g.SetNextWindowSizeVal, g.SetNextWindowSizeCond);
  2165. g.SetNextWindowSizeCond = 0;
  2166. }
  2167. if (g.SetNextWindowCollapsedCond)
  2168. {
  2169. ImGui::SetWindowCollapsed(g.SetNextWindowCollapsedVal, g.SetNextWindowCollapsedCond);
  2170. g.SetNextWindowCollapsedCond = 0;
  2171. }
  2172. // Find parent
  2173. ImGuiWindow* parent_window = (flags & ImGuiWindowFlags_ChildWindow) != 0 ? g.CurrentWindowStack[g.CurrentWindowStack.size()-2] : NULL;
  2174. // Find root (if we are a child window)
  2175. size_t root_idx = g.CurrentWindowStack.size() - 1;
  2176. while (root_idx > 0)
  2177. {
  2178. if ((g.CurrentWindowStack[root_idx]->Flags & ImGuiWindowFlags_ChildWindow) == 0)
  2179. break;
  2180. root_idx--;
  2181. }
  2182. window->RootWindow = g.CurrentWindowStack[root_idx];
  2183. // Default alpha
  2184. if (fill_alpha < 0.0f)
  2185. fill_alpha = style.WindowFillAlphaDefault;
  2186. // When reusing window again multiple times a frame, just append content (don't need to setup again)
  2187. const int current_frame = ImGui::GetFrameCount();
  2188. const bool first_begin_of_the_frame = (window->LastFrameDrawn != current_frame);
  2189. if (first_begin_of_the_frame)
  2190. {
  2191. window->DrawList->Clear();
  2192. window->Visible = true;
  2193. // New windows appears in front
  2194. if (window->LastFrameDrawn < current_frame - 1)
  2195. FocusWindow(window);
  2196. window->LastFrameDrawn = current_frame;
  2197. window->ClipRectStack.resize(0);
  2198. if (flags & ImGuiWindowFlags_ChildWindow)
  2199. {
  2200. parent_window->DC.ChildWindows.push_back(window);
  2201. window->Pos = window->PosFloat = parent_window->DC.CursorPos;
  2202. window->SizeFull = size;
  2203. }
  2204. }
  2205. // Setup texture
  2206. window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID);
  2207. // Setup outer clipping rectangle
  2208. if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox))
  2209. PushClipRect(parent_window->ClipRectStack.back());
  2210. else if (g.IO.DisplayVisibleMin.x != g.IO.DisplayVisibleMax.x && g.IO.DisplayVisibleMin.y != g.IO.DisplayVisibleMax.y)
  2211. PushClipRect(ImVec4(g.IO.DisplayVisibleMin.x, g.IO.DisplayVisibleMin.y, g.IO.DisplayVisibleMax.x, g.IO.DisplayVisibleMax.y));
  2212. else
  2213. PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y));
  2214. // Setup and draw window
  2215. if (first_begin_of_the_frame)
  2216. {
  2217. // Seed ID stack with our window pointer
  2218. window->IDStack.resize(0);
  2219. ImGui::PushID(window);
  2220. // Move window (at the beginning of the frame to avoid input lag or sheering)
  2221. const ImGuiID move_id = window->GetID("#MOVE");
  2222. RegisterAliveId(move_id);
  2223. if (g.ActiveId == move_id)
  2224. {
  2225. if (g.IO.MouseDown[0])
  2226. {
  2227. if (!(window->Flags & ImGuiWindowFlags_NoMove))
  2228. {
  2229. window->PosFloat += g.IO.MouseDelta;
  2230. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2231. MarkSettingsDirty();
  2232. }
  2233. FocusWindow(window);
  2234. }
  2235. else
  2236. {
  2237. SetActiveId(0);
  2238. }
  2239. }
  2240. // Tooltips always follows mouse
  2241. if (!window_pos_set_by_api && (window->Flags & ImGuiWindowFlags_Tooltip) != 0)
  2242. {
  2243. window->PosFloat = g.IO.MousePos + ImVec2(32,16) - style.FramePadding*2;
  2244. }
  2245. // Clamp into view
  2246. if (!(window->Flags & ImGuiWindowFlags_ChildWindow) && !(window->Flags & ImGuiWindowFlags_Tooltip))
  2247. {
  2248. // FIXME: Parameterize padding.
  2249. const ImVec2 pad = ImVec2(window->FontSize()*2.0f, window->FontSize()*2.0f); // FIXME: Parametrize of clarify this behavior.
  2250. if (g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f) // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing.
  2251. {
  2252. ImVec2 clip_min = pad;
  2253. ImVec2 clip_max = g.IO.DisplaySize - pad;
  2254. window->PosFloat = ImMax(window->PosFloat + window->Size, clip_min) - window->Size;
  2255. window->PosFloat = ImMin(window->PosFloat, clip_max);
  2256. }
  2257. window->SizeFull = ImMax(window->SizeFull, style.WindowMinSize);
  2258. }
  2259. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  2260. // Default item width. Make it proportional to window size if window manually resizes
  2261. if (window->Size.x > 0.0f && !(window->Flags & ImGuiWindowFlags_Tooltip) && !(window->Flags & ImGuiWindowFlags_AlwaysAutoResize))
  2262. window->ItemWidthDefault = (float)(int)(window->Size.x * 0.65f);
  2263. else
  2264. window->ItemWidthDefault = 200.0f;
  2265. // Prepare for focus requests
  2266. if (window->FocusIdxAllRequestNext == IM_INT_MAX || window->FocusIdxAllCounter == -1)
  2267. window->FocusIdxAllRequestCurrent = IM_INT_MAX;
  2268. else
  2269. window->FocusIdxAllRequestCurrent = (window->FocusIdxAllRequestNext + (window->FocusIdxAllCounter+1)) % (window->FocusIdxAllCounter+1);
  2270. if (window->FocusIdxTabRequestNext == IM_INT_MAX || window->FocusIdxTabCounter == -1)
  2271. window->FocusIdxTabRequestCurrent = IM_INT_MAX;
  2272. else
  2273. window->FocusIdxTabRequestCurrent = (window->FocusIdxTabRequestNext + (window->FocusIdxTabCounter+1)) % (window->FocusIdxTabCounter+1);
  2274. window->FocusIdxAllCounter = window->FocusIdxTabCounter = -1;
  2275. window->FocusIdxAllRequestNext = window->FocusIdxTabRequestNext = IM_INT_MAX;
  2276. ImGuiAabb title_bar_aabb = window->TitleBarAabb();
  2277. // Apply and ImClamp scrolling
  2278. window->ScrollY = window->NextScrollY;
  2279. window->ScrollY = ImMax(window->ScrollY, 0.0f);
  2280. if (!window->Collapsed && !window->SkipItems)
  2281. window->ScrollY = ImMin(window->ScrollY, ImMax(0.0f, (float)window->SizeContentsFit.y - window->SizeFull.y));
  2282. window->NextScrollY = window->ScrollY;
  2283. // At this point we don't have a clipping rectangle setup yet, so we can test and draw in title bar
  2284. // Collapse window by double-clicking on title bar
  2285. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2286. {
  2287. if (!(window->Flags & ImGuiWindowFlags_NoCollapse) && g.HoveredWindow == window && IsMouseHoveringBox(title_bar_aabb) && g.IO.MouseDoubleClicked[0])
  2288. {
  2289. window->Collapsed = !window->Collapsed;
  2290. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2291. MarkSettingsDirty();
  2292. FocusWindow(window);
  2293. }
  2294. }
  2295. else
  2296. {
  2297. window->Collapsed = false;
  2298. }
  2299. if (window->Collapsed)
  2300. {
  2301. // Draw title bar only
  2302. window->Size = title_bar_aabb.GetSize();
  2303. window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBgCollapsed), style.WindowRounding);
  2304. if (window->Flags & ImGuiWindowFlags_ShowBorders)
  2305. {
  2306. window->DrawList->AddRect(title_bar_aabb.GetTL()+ImVec2(1,1), title_bar_aabb.GetBR()+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), style.WindowRounding);
  2307. window->DrawList->AddRect(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_Border), style.WindowRounding);
  2308. }
  2309. }
  2310. else
  2311. {
  2312. window->Size = window->SizeFull;
  2313. ImU32 resize_col = 0;
  2314. if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
  2315. {
  2316. // Tooltip always resize. We keep the spacing symmetric on both axises for aesthetic purpose.
  2317. const ImVec2 size_auto_fit = window->SizeContentsFit + style.WindowPadding - ImVec2(0.0f, style.ItemSpacing.y);
  2318. window->SizeFull = size_auto_fit;
  2319. }
  2320. else
  2321. {
  2322. const ImVec2 size_auto_fit = ImClamp(window->SizeContentsFit + style.AutoFitPadding, style.WindowMinSize, ImMax(style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding));
  2323. if ((window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0)
  2324. {
  2325. // Don't continuously mark settings as dirty, the size of the window doesn't need to be stored.
  2326. window->SizeFull = size_auto_fit;
  2327. }
  2328. else if (window->AutoFitFrames > 0)
  2329. {
  2330. // Auto-fit only grows during the first few frames
  2331. if (window->AutoFitOnlyGrows)
  2332. window->SizeFull = ImMax(window->SizeFull, size_auto_fit);
  2333. else
  2334. window->SizeFull = size_auto_fit;
  2335. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2336. MarkSettingsDirty();
  2337. }
  2338. else if (!(window->Flags & ImGuiWindowFlags_NoResize))
  2339. {
  2340. // Manual resize grip
  2341. const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR());
  2342. const ImGuiID resize_id = window->GetID("##RESIZE");
  2343. bool hovered, held;
  2344. ButtonBehaviour(resize_aabb, resize_id, &hovered, &held, true);
  2345. resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip);
  2346. if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0])
  2347. {
  2348. // Manual auto-fit when double-clicking
  2349. window->SizeFull = size_auto_fit;
  2350. window->Size = window->SizeFull;
  2351. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2352. MarkSettingsDirty();
  2353. }
  2354. else if (held)
  2355. {
  2356. // Resize
  2357. window->SizeFull = ImMax(window->SizeFull + g.IO.MouseDelta, style.WindowMinSize);
  2358. window->Size = window->SizeFull;
  2359. if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
  2360. MarkSettingsDirty();
  2361. }
  2362. }
  2363. // Update aabb immediately so that rendering right below us isn't one frame late
  2364. title_bar_aabb = window->TitleBarAabb();
  2365. }
  2366. // Title bar + Window box
  2367. if (fill_alpha > 0.0f)
  2368. {
  2369. if ((window->Flags & ImGuiWindowFlags_ComboBox) != 0)
  2370. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_ComboBg, fill_alpha), 0);
  2371. else if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0)
  2372. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_TooltipBg, fill_alpha), style.WindowRounding);
  2373. else
  2374. window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, fill_alpha), style.WindowRounding);
  2375. }
  2376. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2377. window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBg), style.WindowRounding, 1|2);
  2378. // Borders
  2379. if (window->Flags & ImGuiWindowFlags_ShowBorders)
  2380. {
  2381. const float rounding = (window->Flags & ImGuiWindowFlags_ComboBox) ? 0.0f : style.WindowRounding;
  2382. window->DrawList->AddRect(window->Pos+ImVec2(1,1), window->Pos+window->Size+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), rounding);
  2383. window->DrawList->AddRect(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_Border), rounding);
  2384. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2385. window->DrawList->AddLine(title_bar_aabb.GetBL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_Border));
  2386. }
  2387. // Scrollbar
  2388. window->ScrollbarY = (window->SizeContentsFit.y > window->Size.y) && !(window->Flags & ImGuiWindowFlags_NoScrollbar);
  2389. if (window->ScrollbarY)
  2390. {
  2391. ImGuiAabb scrollbar_bb(window->Aabb().Max.x - style.ScrollBarWidth, title_bar_aabb.Max.y+1, window->Aabb().Max.x, window->Aabb().Max.y-1);
  2392. //window->DrawList->AddLine(scrollbar_bb.GetTL(), scrollbar_bb.GetBL(), g.Colors[ImGuiCol_Border]);
  2393. window->DrawList->AddRectFilled(scrollbar_bb.Min, scrollbar_bb.Max, window->Color(ImGuiCol_ScrollbarBg));
  2394. scrollbar_bb.Expand(ImVec2(-3,-3));
  2395. const float grab_size_y_norm = ImSaturate(window->Size.y / ImMax(window->SizeContentsFit.y, window->Size.y));
  2396. const float grab_size_y = scrollbar_bb.GetHeight() * grab_size_y_norm;
  2397. // Handle input right away (none of the code above is relying on scrolling position)
  2398. bool held = false;
  2399. bool hovered = false;
  2400. if (grab_size_y_norm < 1.0f)
  2401. {
  2402. const ImGuiID scrollbar_id = window->GetID("#SCROLLY");
  2403. ButtonBehaviour(scrollbar_bb, scrollbar_id, &hovered, &held, true);
  2404. if (held)
  2405. {
  2406. g.HoveredId = scrollbar_id;
  2407. 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);
  2408. window->ScrollY = pos_y_norm * window->SizeContentsFit.y;
  2409. window->NextScrollY = window->ScrollY;
  2410. }
  2411. }
  2412. // Normalized height of the grab
  2413. const float pos_y_norm = ImSaturate(window->ScrollY / ImMax(0.0f, window->SizeContentsFit.y));
  2414. const ImU32 grab_col = window->Color(held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab);
  2415. window->DrawList->AddRectFilled(
  2416. ImVec2(scrollbar_bb.Min.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y, pos_y_norm)),
  2417. ImVec2(scrollbar_bb.Max.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y, pos_y_norm + grab_size_y_norm)), grab_col);
  2418. }
  2419. // Render resize grip
  2420. // (after the input handling so we don't have a frame of latency)
  2421. if (!(window->Flags & ImGuiWindowFlags_NoResize))
  2422. {
  2423. const float r = style.WindowRounding;
  2424. const ImVec2 br = window->Aabb().GetBR();
  2425. if (r == 0.0f)
  2426. {
  2427. window->DrawList->AddTriangleFilled(br, br-ImVec2(0,14), br-ImVec2(14,0), resize_col);
  2428. }
  2429. else
  2430. {
  2431. // FIXME: We should draw 4 triangles and decide on a size that's not dependent on the rounding size (previously used 18)
  2432. window->DrawList->AddArc(br - ImVec2(r,r), r, resize_col, 6, 9, true);
  2433. window->DrawList->AddTriangleFilled(br+ImVec2(0,-2*r),br+ImVec2(0,-r),br+ImVec2(-r,-r), resize_col);
  2434. window->DrawList->AddTriangleFilled(br+ImVec2(-r,-r), br+ImVec2(-r,0),br+ImVec2(-2*r,0), resize_col);
  2435. }
  2436. }
  2437. }
  2438. // Setup drawing context
  2439. window->DC.ColumnsStartX = window->WindowPadding().x;
  2440. window->DC.ColumnsOffsetX = 0.0f;
  2441. window->DC.CursorStartPos = window->Pos + ImVec2(window->DC.ColumnsStartX + window->DC.ColumnsOffsetX, window->TitleBarHeight() + window->WindowPadding().y) - ImVec2(0.0f, window->ScrollY);
  2442. window->DC.CursorPos = window->DC.CursorStartPos;
  2443. window->DC.CursorPosPrevLine = window->DC.CursorPos;
  2444. window->DC.CurrentLineHeight = window->DC.PrevLineHeight = 0.0f;
  2445. window->DC.LogLineHeight = window->DC.CursorPos.y - 9999.0f;
  2446. window->DC.ChildWindows.resize(0);
  2447. window->DC.ItemWidth.resize(0);
  2448. window->DC.ItemWidth.push_back(window->ItemWidthDefault);
  2449. window->DC.AllowKeyboardFocus.resize(0);
  2450. window->DC.AllowKeyboardFocus.push_back(true);
  2451. window->DC.TextWrapPos.resize(0);
  2452. window->DC.TextWrapPos.push_back(-1.0f); // disabled
  2453. window->DC.ColorEditMode = ImGuiColorEditMode_UserSelect;
  2454. window->DC.ColumnsCurrent = 0;
  2455. window->DC.ColumnsCount = 1;
  2456. window->DC.ColumnsStartPos = window->DC.CursorPos;
  2457. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.ColumnsStartPos.y;
  2458. window->DC.TreeDepth = 0;
  2459. window->DC.StateStorage = &window->StateStorage;
  2460. window->DC.OpenNextNode = -1;
  2461. // Reset contents size for auto-fitting
  2462. window->SizeContentsFit = ImVec2(0.0f, 0.0f);
  2463. if (window->AutoFitFrames > 0)
  2464. window->AutoFitFrames--;
  2465. // Title bar
  2466. if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
  2467. {
  2468. if (p_opened != NULL)
  2469. CloseWindowButton(p_opened);
  2470. ImVec2 text_min = window->Pos + style.FramePadding;
  2471. if (!(window->Flags & ImGuiWindowFlags_NoCollapse))
  2472. {
  2473. RenderCollapseTriangle(window->Pos + style.FramePadding, !window->Collapsed, 1.0f, true);
  2474. text_min.x += window->FontSize() + style.ItemInnerSpacing.x;
  2475. }
  2476. const ImVec2 text_size = CalcTextSize(name, NULL, true);
  2477. const ImVec2 text_max = window->Pos + ImVec2(window->Size.x - (p_opened ? (title_bar_aabb.GetHeight()-3) : style.FramePadding.x), style.FramePadding.y + text_size.y);
  2478. 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 // FIXME-OPT: CPU side clipping would work well for this kind of case.
  2479. if (clip_title)
  2480. PushClipRect(ImVec4(text_min.x, text_min.y, text_max.x, text_max.y));
  2481. RenderText(text_min, name);
  2482. if (clip_title)
  2483. PopClipRect();
  2484. }
  2485. }
  2486. // Inner clipping rectangle
  2487. // We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame
  2488. const ImGuiAabb title_bar_aabb = window->TitleBarAabb();
  2489. 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);
  2490. if (window->ScrollbarY)
  2491. clip_rect.z -= style.ScrollBarWidth;
  2492. PushClipRect(clip_rect);
  2493. // Clear 'accessed' flag last thing
  2494. if (first_begin_of_the_frame)
  2495. window->Accessed = false;
  2496. // Child window can be out of sight and have "negative" clip windows.
  2497. // Mark them as collapsed so commands are skipped earlier (we can't manually collapse because they have no title bar).
  2498. if (flags & ImGuiWindowFlags_ChildWindow)
  2499. {
  2500. IM_ASSERT((flags & ImGuiWindowFlags_NoTitleBar) != 0);
  2501. const ImVec4 clip_rect_t = window->ClipRectStack.back();
  2502. window->Collapsed = (clip_rect_t.x >= clip_rect_t.z || clip_rect_t.y >= clip_rect_t.w);
  2503. // We also hide the window from rendering because we've already added its border to the command list.
  2504. // (we could perform the check earlier in the function but it is simpler at this point)
  2505. if (window->Collapsed)
  2506. window->Visible = false;
  2507. }
  2508. if (style.Alpha <= 0.0f)
  2509. window->Visible = false;
  2510. // Return false if we don't intend to display anything to allow user to perform an early out optimization
  2511. window->SkipItems = window->Collapsed || (!window->Visible && window->AutoFitFrames == 0);
  2512. return !window->SkipItems;
  2513. }
  2514. void ImGui::End()
  2515. {
  2516. ImGuiState& g = GImGui;
  2517. ImGuiWindow* window = g.CurrentWindow;
  2518. ImGui::Columns(1, "#CloseColumns");
  2519. PopClipRect(); // inner window clip rectangle
  2520. PopClipRect(); // outer window clip rectangle
  2521. window->DrawList->PopTextureID();
  2522. // Stop logging
  2523. if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) // FIXME: add more options for scope of logging
  2524. ImGui::LogFinish();
  2525. // Pop
  2526. // NB: we don't clear 'window->RootWindow' yet, it will be used then cleared in NewFrame()
  2527. g.CurrentWindowStack.pop_back();
  2528. g.CurrentWindow = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back();
  2529. }
  2530. // Moving window to front of display (which happens to be back of our sorted list)
  2531. static void FocusWindow(ImGuiWindow* window)
  2532. {
  2533. ImGuiState& g = GImGui;
  2534. g.FocusedWindow = window;
  2535. if (g.Windows.back() == window)
  2536. return;
  2537. for (size_t i = 0; i < g.Windows.size(); i++)
  2538. if (g.Windows[i] == window)
  2539. {
  2540. g.Windows.erase(g.Windows.begin() + i);
  2541. break;
  2542. }
  2543. g.Windows.push_back(window);
  2544. }
  2545. void ImGui::PushItemWidth(float item_width)
  2546. {
  2547. ImGuiWindow* window = GetCurrentWindow();
  2548. item_width = (float)(int)item_width;
  2549. window->DC.ItemWidth.push_back(item_width > 0.0f ? item_width : window->ItemWidthDefault);
  2550. }
  2551. void ImGui::PopItemWidth()
  2552. {
  2553. ImGuiWindow* window = GetCurrentWindow();
  2554. window->DC.ItemWidth.pop_back();
  2555. }
  2556. float ImGui::GetItemWidth()
  2557. {
  2558. ImGuiWindow* window = GetCurrentWindow();
  2559. return window->DC.ItemWidth.back();
  2560. }
  2561. static void SetFont(ImFont* font)
  2562. {
  2563. ImGuiState& g = GImGui;
  2564. IM_ASSERT(font && font->IsLoaded());
  2565. IM_ASSERT(font->Scale > 0.0f);
  2566. g.Font = font;
  2567. g.FontSize = g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale;
  2568. g.FontTexUvWhitePixel = g.Font->ContainerAtlas->TexUvWhitePixel;
  2569. g.Font->FallbackGlyph = NULL;
  2570. g.Font->FallbackGlyph = g.Font->FindGlyph(g.Font->FallbackChar);
  2571. }
  2572. void ImGui::PushFont(ImFont* font)
  2573. {
  2574. ImGuiState& g = GImGui;
  2575. if (!font)
  2576. font = g.IO.Fonts->Fonts[0];
  2577. SetFont(font);
  2578. g.FontStack.push_back(font);
  2579. g.CurrentWindow->DrawList->PushTextureID(font->ContainerAtlas->TexID);
  2580. }
  2581. void ImGui::PopFont()
  2582. {
  2583. ImGuiState& g = GImGui;
  2584. g.CurrentWindow->DrawList->PopTextureID();
  2585. g.FontStack.pop_back();
  2586. SetFont(g.FontStack.empty() ? g.IO.Fonts->Fonts[0] : g.FontStack.back());
  2587. }
  2588. void ImGui::PushAllowKeyboardFocus(bool allow_keyboard_focus)
  2589. {
  2590. ImGuiWindow* window = GetCurrentWindow();
  2591. window->DC.AllowKeyboardFocus.push_back(allow_keyboard_focus);
  2592. }
  2593. void ImGui::PopAllowKeyboardFocus()
  2594. {
  2595. ImGuiWindow* window = GetCurrentWindow();
  2596. window->DC.AllowKeyboardFocus.pop_back();
  2597. }
  2598. void ImGui::PushTextWrapPos(float wrap_x)
  2599. {
  2600. ImGuiWindow* window = GetCurrentWindow();
  2601. window->DC.TextWrapPos.push_back(wrap_x);
  2602. }
  2603. void ImGui::PopTextWrapPos()
  2604. {
  2605. ImGuiWindow* window = GetCurrentWindow();
  2606. window->DC.TextWrapPos.pop_back();
  2607. }
  2608. void ImGui::PushStyleColor(ImGuiCol idx, const ImVec4& col)
  2609. {
  2610. ImGuiState& g = GImGui;
  2611. ImGuiColMod backup;
  2612. backup.Col = idx;
  2613. backup.PreviousValue = g.Style.Colors[idx];
  2614. g.ColorModifiers.push_back(backup);
  2615. g.Style.Colors[idx] = col;
  2616. }
  2617. void ImGui::PopStyleColor(int count)
  2618. {
  2619. ImGuiState& g = GImGui;
  2620. while (count > 0)
  2621. {
  2622. ImGuiColMod& backup = g.ColorModifiers.back();
  2623. g.Style.Colors[backup.Col] = backup.PreviousValue;
  2624. g.ColorModifiers.pop_back();
  2625. count--;
  2626. }
  2627. }
  2628. static float* GetStyleVarFloatAddr(ImGuiStyleVar idx)
  2629. {
  2630. ImGuiState& g = GImGui;
  2631. switch (idx)
  2632. {
  2633. case ImGuiStyleVar_Alpha: return &g.Style.Alpha;
  2634. case ImGuiStyleVar_WindowRounding: return &g.Style.WindowRounding;
  2635. case ImGuiStyleVar_FrameRounding: return &g.Style.FrameRounding;
  2636. case ImGuiStyleVar_TreeNodeSpacing: return &g.Style.TreeNodeSpacing;
  2637. }
  2638. return NULL;
  2639. }
  2640. static ImVec2* GetStyleVarVec2Addr(ImGuiStyleVar idx)
  2641. {
  2642. ImGuiState& g = GImGui;
  2643. switch (idx)
  2644. {
  2645. case ImGuiStyleVar_WindowPadding: return &g.Style.WindowPadding;
  2646. case ImGuiStyleVar_FramePadding: return &g.Style.FramePadding;
  2647. case ImGuiStyleVar_ItemSpacing: return &g.Style.ItemSpacing;
  2648. case ImGuiStyleVar_ItemInnerSpacing: return &g.Style.ItemInnerSpacing;
  2649. }
  2650. return NULL;
  2651. }
  2652. void ImGui::PushStyleVar(ImGuiStyleVar idx, float val)
  2653. {
  2654. ImGuiState& g = GImGui;
  2655. float* pvar = GetStyleVarFloatAddr(idx);
  2656. IM_ASSERT(pvar != NULL); // Called function with wrong-type? Variable is not a float.
  2657. ImGuiStyleMod backup;
  2658. backup.Var = idx;
  2659. backup.PreviousValue = ImVec2(*pvar, 0.0f);
  2660. g.StyleModifiers.push_back(backup);
  2661. *pvar = val;
  2662. }
  2663. void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val)
  2664. {
  2665. ImGuiState& g = GImGui;
  2666. ImVec2* pvar = GetStyleVarVec2Addr(idx);
  2667. IM_ASSERT(pvar != NULL); // Called function with wrong-type? Varialble is not a ImVec2.
  2668. ImGuiStyleMod backup;
  2669. backup.Var = idx;
  2670. backup.PreviousValue = *pvar;
  2671. g.StyleModifiers.push_back(backup);
  2672. *pvar = val;
  2673. }
  2674. void ImGui::PopStyleVar(int count)
  2675. {
  2676. ImGuiState& g = GImGui;
  2677. while (count > 0)
  2678. {
  2679. ImGuiStyleMod& backup = g.StyleModifiers.back();
  2680. if (float* pvar_f = GetStyleVarFloatAddr(backup.Var))
  2681. *pvar_f = backup.PreviousValue.x;
  2682. else if (ImVec2* pvar_v = GetStyleVarVec2Addr(backup.Var))
  2683. *pvar_v = backup.PreviousValue;
  2684. g.StyleModifiers.pop_back();
  2685. count--;
  2686. }
  2687. }
  2688. const char* ImGui::GetStyleColName(ImGuiCol idx)
  2689. {
  2690. // Create switch-case from enum with regexp: ImGuiCol_{.*}, --> case ImGuiCol_\1: return "\1";
  2691. switch (idx)
  2692. {
  2693. case ImGuiCol_Text: return "Text";
  2694. case ImGuiCol_WindowBg: return "WindowBg";
  2695. case ImGuiCol_Border: return "Border";
  2696. case ImGuiCol_BorderShadow: return "BorderShadow";
  2697. case ImGuiCol_FrameBg: return "FrameBg";
  2698. case ImGuiCol_TitleBg: return "TitleBg";
  2699. case ImGuiCol_TitleBgCollapsed: return "TitleBgCollapsed";
  2700. case ImGuiCol_ScrollbarBg: return "ScrollbarBg";
  2701. case ImGuiCol_ScrollbarGrab: return "ScrollbarGrab";
  2702. case ImGuiCol_ScrollbarGrabHovered: return "ScrollbarGrabHovered";
  2703. case ImGuiCol_ScrollbarGrabActive: return "ScrollbarGrabActive";
  2704. case ImGuiCol_ComboBg: return "ComboBg";
  2705. case ImGuiCol_CheckHovered: return "CheckHovered";
  2706. case ImGuiCol_CheckActive: return "CheckActive";
  2707. case ImGuiCol_CheckMark: return "CheckMark";
  2708. case ImGuiCol_SliderGrab: return "SliderGrab";
  2709. case ImGuiCol_SliderGrabActive: return "SliderGrabActive";
  2710. case ImGuiCol_Button: return "Button";
  2711. case ImGuiCol_ButtonHovered: return "ButtonHovered";
  2712. case ImGuiCol_ButtonActive: return "ButtonActive";
  2713. case ImGuiCol_Header: return "Header";
  2714. case ImGuiCol_HeaderHovered: return "HeaderHovered";
  2715. case ImGuiCol_HeaderActive: return "HeaderActive";
  2716. case ImGuiCol_Column: return "Column";
  2717. case ImGuiCol_ColumnHovered: return "ColumnHovered";
  2718. case ImGuiCol_ColumnActive: return "ColumnActive";
  2719. case ImGuiCol_ResizeGrip: return "ResizeGrip";
  2720. case ImGuiCol_ResizeGripHovered: return "ResizeGripHovered";
  2721. case ImGuiCol_ResizeGripActive: return "ResizeGripActive";
  2722. case ImGuiCol_CloseButton: return "CloseButton";
  2723. case ImGuiCol_CloseButtonHovered: return "CloseButtonHovered";
  2724. case ImGuiCol_CloseButtonActive: return "CloseButtonActive";
  2725. case ImGuiCol_PlotLines: return "PlotLines";
  2726. case ImGuiCol_PlotLinesHovered: return "PlotLinesHovered";
  2727. case ImGuiCol_PlotHistogram: return "PlotHistogram";
  2728. case ImGuiCol_PlotHistogramHovered: return "PlotHistogramHovered";
  2729. case ImGuiCol_TextSelectedBg: return "TextSelectedBg";
  2730. case ImGuiCol_TooltipBg: return "TooltipBg";
  2731. }
  2732. IM_ASSERT(0);
  2733. return "Unknown";
  2734. }
  2735. bool ImGui::GetWindowIsFocused()
  2736. {
  2737. ImGuiState& g = GImGui;
  2738. ImGuiWindow* window = GetCurrentWindow();
  2739. return g.FocusedWindow == window;
  2740. }
  2741. float ImGui::GetWindowWidth()
  2742. {
  2743. ImGuiWindow* window = GetCurrentWindow();
  2744. return window->Size.x;
  2745. }
  2746. ImVec2 ImGui::GetWindowPos()
  2747. {
  2748. ImGuiWindow* window = GetCurrentWindow();
  2749. return window->Pos;
  2750. }
  2751. void ImGui::SetWindowPos(const ImVec2& pos, ImGuiSetCondition cond)
  2752. {
  2753. ImGuiWindow* window = GetCurrentWindow();
  2754. // Test condition (NB: bit 0 is always true) and clear flags for next time
  2755. if (cond && (window->SetWindowPosAllowFlags & cond) == 0)
  2756. return;
  2757. window->SetWindowPosAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver);
  2758. // Set
  2759. const ImVec2 old_pos = window->Pos;
  2760. window->PosFloat = pos;
  2761. window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y);
  2762. window->DC.CursorPos += (window->Pos - old_pos); // As we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least offset the cursor
  2763. }
  2764. ImVec2 ImGui::GetWindowSize()
  2765. {
  2766. ImGuiWindow* window = GetCurrentWindow();
  2767. return window->Size;
  2768. }
  2769. void ImGui::SetWindowSize(const ImVec2& size, ImGuiSetCondition cond)
  2770. {
  2771. ImGuiWindow* window = GetCurrentWindow();
  2772. // Test condition (NB: bit 0 is always true) and clear flags for next time
  2773. if (cond && (window->SetWindowSizeAllowFlags & cond) == 0)
  2774. return;
  2775. window->SetWindowSizeAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver);
  2776. // Set
  2777. if (ImLengthSqr(size) > 0.00001f)
  2778. {
  2779. window->SizeFull = size;
  2780. window->AutoFitFrames = 0;
  2781. }
  2782. else
  2783. {
  2784. // Autofit
  2785. window->AutoFitFrames = 2;
  2786. window->AutoFitOnlyGrows = false;
  2787. }
  2788. }
  2789. void ImGui::SetWindowCollapsed(bool collapsed, ImGuiSetCondition cond)
  2790. {
  2791. ImGuiWindow* window = GetCurrentWindow();
  2792. // Test condition (NB: bit 0 is always true) and clear flags for next time
  2793. if (cond && (window->SetWindowCollapsedAllowFlags & cond) == 0)
  2794. return;
  2795. window->SetWindowCollapsedAllowFlags &= ~(ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver);
  2796. // Set
  2797. window->Collapsed = collapsed;
  2798. }
  2799. void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiSetCondition cond)
  2800. {
  2801. ImGuiState& g = GImGui;
  2802. g.SetNextWindowPosVal = pos;
  2803. g.SetNextWindowPosCond = cond ? cond : ImGuiSetCondition_Always;
  2804. }
  2805. void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiSetCondition cond)
  2806. {
  2807. ImGuiState& g = GImGui;
  2808. g.SetNextWindowSizeVal = size;
  2809. g.SetNextWindowSizeCond = cond ? cond : ImGuiSetCondition_Always;
  2810. }
  2811. void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiSetCondition cond)
  2812. {
  2813. ImGuiState& g = GImGui;
  2814. g.SetNextWindowCollapsedVal = collapsed;
  2815. g.SetNextWindowCollapsedCond = cond ? cond : ImGuiSetCondition_Always;
  2816. }
  2817. ImVec2 ImGui::GetContentRegionMax()
  2818. {
  2819. ImGuiWindow* window = GetCurrentWindow();
  2820. ImVec2 m = window->Size - window->WindowPadding();
  2821. if (window->DC.ColumnsCount != 1)
  2822. {
  2823. m.x = GetColumnOffset(window->DC.ColumnsCurrent + 1);
  2824. m.x -= GImGui.Style.WindowPadding.x;
  2825. }
  2826. else
  2827. {
  2828. if (window->ScrollbarY)
  2829. m.x -= GImGui.Style.ScrollBarWidth;
  2830. }
  2831. return m;
  2832. }
  2833. ImVec2 ImGui::GetWindowContentRegionMin()
  2834. {
  2835. ImGuiWindow* window = GetCurrentWindow();
  2836. return ImVec2(0, window->TitleBarHeight()) + window->WindowPadding();
  2837. }
  2838. ImVec2 ImGui::GetWindowContentRegionMax()
  2839. {
  2840. ImGuiWindow* window = GetCurrentWindow();
  2841. ImVec2 m = window->Size - window->WindowPadding();
  2842. if (window->ScrollbarY)
  2843. m.x -= GImGui.Style.ScrollBarWidth;
  2844. return m;
  2845. }
  2846. float ImGui::GetTextLineHeight()
  2847. {
  2848. ImGuiWindow* window = GetCurrentWindow();
  2849. return window->FontSize();
  2850. }
  2851. float ImGui::GetTextLineSpacing()
  2852. {
  2853. ImGuiState& g = GImGui;
  2854. ImGuiWindow* window = GetCurrentWindow();
  2855. return window->FontSize() + g.Style.ItemSpacing.y;
  2856. }
  2857. ImDrawList* ImGui::GetWindowDrawList()
  2858. {
  2859. ImGuiWindow* window = GetCurrentWindow();
  2860. return window->DrawList;
  2861. }
  2862. ImFont* ImGui::GetWindowFont()
  2863. {
  2864. ImGuiWindow* window = GetCurrentWindow();
  2865. return window->Font();
  2866. }
  2867. float ImGui::GetWindowFontSize()
  2868. {
  2869. ImGuiWindow* window = GetCurrentWindow();
  2870. return window->FontSize();
  2871. }
  2872. void ImGui::SetWindowFontScale(float scale)
  2873. {
  2874. ImGuiWindow* window = GetCurrentWindow();
  2875. window->FontWindowScale = scale;
  2876. }
  2877. // NB: internally we store CursorPos in absolute screen coordinates because it is more convenient.
  2878. // Conversion happens as we pass the value to user, but it makes our naming convention dodgy. May want to rename 'DC.CursorPos'.
  2879. ImVec2 ImGui::GetCursorPos()
  2880. {
  2881. ImGuiWindow* window = GetCurrentWindow();
  2882. return window->DC.CursorPos - window->Pos;
  2883. }
  2884. void ImGui::SetCursorPos(const ImVec2& pos)
  2885. {
  2886. ImGuiWindow* window = GetCurrentWindow();
  2887. window->DC.CursorPos = window->Pos + pos;
  2888. }
  2889. void ImGui::SetCursorPosX(float x)
  2890. {
  2891. ImGuiWindow* window = GetCurrentWindow();
  2892. window->DC.CursorPos.x = window->Pos.x + x;
  2893. }
  2894. void ImGui::SetCursorPosY(float y)
  2895. {
  2896. ImGuiWindow* window = GetCurrentWindow();
  2897. window->DC.CursorPos.y = window->Pos.y + y;
  2898. }
  2899. ImVec2 ImGui::GetCursorScreenPos()
  2900. {
  2901. ImGuiWindow* window = GetCurrentWindow();
  2902. return window->DC.CursorPos;
  2903. }
  2904. void ImGui::SetCursorScreenPos(const ImVec2& screen_pos)
  2905. {
  2906. ImGuiWindow* window = GetCurrentWindow();
  2907. window->DC.CursorPos = screen_pos;
  2908. }
  2909. void ImGui::SetScrollPosHere()
  2910. {
  2911. ImGuiWindow* window = GetCurrentWindow();
  2912. window->NextScrollY = (window->DC.CursorPos.y + window->ScrollY) - (window->Pos.y + window->SizeFull.y * 0.5f) - (window->TitleBarHeight() + window->WindowPadding().y);
  2913. }
  2914. void ImGui::SetKeyboardFocusHere(int offset)
  2915. {
  2916. ImGuiWindow* window = GetCurrentWindow();
  2917. window->FocusIdxAllRequestNext = window->FocusIdxAllCounter + 1 + offset;
  2918. window->FocusIdxTabRequestNext = IM_INT_MAX;
  2919. }
  2920. void ImGui::SetStateStorage(ImGuiStorage* tree)
  2921. {
  2922. ImGuiWindow* window = GetCurrentWindow();
  2923. window->DC.StateStorage = tree ? tree : &window->StateStorage;
  2924. }
  2925. ImGuiStorage* ImGui::GetStateStorage()
  2926. {
  2927. ImGuiWindow* window = GetCurrentWindow();
  2928. return window->DC.StateStorage;
  2929. }
  2930. void ImGui::TextV(const char* fmt, va_list args)
  2931. {
  2932. ImGuiWindow* window = GetCurrentWindow();
  2933. if (window->SkipItems)
  2934. return;
  2935. static char buf[1024];
  2936. const char* text_end = buf + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  2937. TextUnformatted(buf, text_end);
  2938. }
  2939. void ImGui::Text(const char* fmt, ...)
  2940. {
  2941. va_list args;
  2942. va_start(args, fmt);
  2943. TextV(fmt, args);
  2944. va_end(args);
  2945. }
  2946. void ImGui::TextColoredV(const ImVec4& col, const char* fmt, va_list args)
  2947. {
  2948. ImGui::PushStyleColor(ImGuiCol_Text, col);
  2949. TextV(fmt, args);
  2950. ImGui::PopStyleColor();
  2951. }
  2952. void ImGui::TextColored(const ImVec4& col, const char* fmt, ...)
  2953. {
  2954. va_list args;
  2955. va_start(args, fmt);
  2956. TextColoredV(col, fmt, args);
  2957. va_end(args);
  2958. }
  2959. void ImGui::TextWrappedV(const char* fmt, va_list args)
  2960. {
  2961. ImGui::PushTextWrapPos(0.0f);
  2962. TextV(fmt, args);
  2963. ImGui::PopTextWrapPos();
  2964. }
  2965. void ImGui::TextWrapped(const char* fmt, ...)
  2966. {
  2967. va_list args;
  2968. va_start(args, fmt);
  2969. TextWrappedV(fmt, args);
  2970. va_end(args);
  2971. }
  2972. void ImGui::TextUnformatted(const char* text, const char* text_end)
  2973. {
  2974. ImGuiState& g = GImGui;
  2975. ImGuiWindow* window = GetCurrentWindow();
  2976. if (window->SkipItems)
  2977. return;
  2978. IM_ASSERT(text != NULL);
  2979. const char* text_begin = text;
  2980. if (text_end == NULL)
  2981. text_end = text + strlen(text); // FIXME-OPT
  2982. const float wrap_pos_x = window->DC.TextWrapPos.back();
  2983. const bool wrap_enabled = wrap_pos_x >= 0.0f;
  2984. if (text_end - text > 2000 && !wrap_enabled)
  2985. {
  2986. // Long text!
  2987. // Perform manual coarse clipping to optimize for long multi-line text
  2988. // From this point we will only compute the width of lines that are visible.
  2989. // Optimization only available when word-wrapping is disabled.
  2990. const char* line = text;
  2991. const float line_height = ImGui::GetTextLineHeight();
  2992. const ImVec2 start_pos = window->DC.CursorPos;
  2993. const ImVec4 clip_rect = window->ClipRectStack.back();
  2994. ImVec2 text_size(0,0);
  2995. if (start_pos.y <= clip_rect.w)
  2996. {
  2997. ImVec2 pos = start_pos;
  2998. // Lines to skip (can't skip when logging text)
  2999. if (!g.LogEnabled)
  3000. {
  3001. int lines_skippable = (int)((clip_rect.y - start_pos.y) / line_height) - 1;
  3002. if (lines_skippable > 0)
  3003. {
  3004. int lines_skipped = 0;
  3005. while (line < text_end && lines_skipped <= lines_skippable)
  3006. {
  3007. const char* line_end = strchr(line, '\n');
  3008. line = line_end + 1;
  3009. lines_skipped++;
  3010. }
  3011. pos.y += lines_skipped * line_height;
  3012. }
  3013. }
  3014. // Lines to render
  3015. if (line < text_end)
  3016. {
  3017. ImGuiAabb line_box(pos, pos + ImVec2(ImGui::GetWindowWidth(), line_height));
  3018. while (line < text_end)
  3019. {
  3020. const char* line_end = strchr(line, '\n');
  3021. if (IsClipped(line_box))
  3022. break;
  3023. const ImVec2 line_size = CalcTextSize(line, line_end, false);
  3024. text_size.x = ImMax(text_size.x, line_size.x);
  3025. RenderText(pos, line, line_end, false);
  3026. if (!line_end)
  3027. line_end = text_end;
  3028. line = line_end + 1;
  3029. line_box.Min.y += line_height;
  3030. line_box.Max.y += line_height;
  3031. pos.y += line_height;
  3032. }
  3033. // Count remaining lines
  3034. int lines_skipped = 0;
  3035. while (line < text_end)
  3036. {
  3037. const char* line_end = strchr(line, '\n');
  3038. if (!line_end)
  3039. line_end = text_end;
  3040. line = line_end + 1;
  3041. lines_skipped++;
  3042. }
  3043. pos.y += lines_skipped * line_height;
  3044. }
  3045. text_size.y += (pos - start_pos).y;
  3046. }
  3047. const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size);
  3048. ItemSize(bb);
  3049. ItemAdd(bb, NULL);
  3050. }
  3051. else
  3052. {
  3053. const float wrap_width = wrap_enabled ? CalcWrapWidthForPos(window->DC.CursorPos, wrap_pos_x) : 0.0f;
  3054. const ImVec2 text_size = CalcTextSize(text_begin, text_end, false, wrap_width);
  3055. ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size);
  3056. ItemSize(bb.GetSize(), &bb.Min);
  3057. if (!ItemAdd(bb, NULL))
  3058. return;
  3059. // Render
  3060. // We don't hide text after ## in this end-user function.
  3061. RenderText(bb.Min, text_begin, text_end, false, wrap_width);
  3062. }
  3063. }
  3064. void ImGui::AlignFirstTextHeightToWidgets()
  3065. {
  3066. ImGuiState& g = GImGui;
  3067. ImGuiWindow* window = GetCurrentWindow();
  3068. if (window->SkipItems)
  3069. return;
  3070. // Declare a dummy item size to that upcoming items that are smaller will center-align on the newly expanded line height.
  3071. ItemSize(ImVec2(0, window->FontSize() + g.Style.FramePadding.y*2));
  3072. ImGui::SameLine(0, 0);
  3073. }
  3074. // Add a label+text combo aligned to other label+value widgets
  3075. void ImGui::LabelTextV(const char* label, const char* fmt, va_list args)
  3076. {
  3077. ImGuiState& g = GImGui;
  3078. ImGuiWindow* window = GetCurrentWindow();
  3079. if (window->SkipItems)
  3080. return;
  3081. const ImGuiStyle& style = g.Style;
  3082. const float w = window->DC.ItemWidth.back();
  3083. static char buf[1024];
  3084. const char* text_begin = &buf[0];
  3085. const char* text_end = text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  3086. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  3087. const ImGuiAabb value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, text_size.y));
  3088. const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + (text_size.x > 0.0f ? style.ItemInnerSpacing.x : 0.0f), 0.0f) + text_size);
  3089. ItemSize(bb);
  3090. if (!ItemAdd(value_bb, NULL))
  3091. return;
  3092. // Render
  3093. RenderText(value_bb.Min, text_begin, text_end);
  3094. RenderText(ImVec2(value_bb.Max.x + style.ItemInnerSpacing.x, value_bb.Min.y), label);
  3095. }
  3096. void ImGui::LabelText(const char* label, const char* fmt, ...)
  3097. {
  3098. va_list args;
  3099. va_start(args, fmt);
  3100. LabelTextV(label, fmt, args);
  3101. va_end(args);
  3102. }
  3103. static bool IsHovered(const ImGuiAabb& bb, const ImGuiID& id)
  3104. {
  3105. ImGuiState& g = GImGui;
  3106. if (g.HoveredId == 0)
  3107. {
  3108. ImGuiWindow* window = GetCurrentWindow();
  3109. const bool hovered = (g.HoveredRootWindow == window->RootWindow) && (g.ActiveId == 0 || g.ActiveId == id) && IsMouseHoveringBox(bb);
  3110. return hovered;
  3111. }
  3112. return false;
  3113. }
  3114. static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat)
  3115. {
  3116. ImGuiState& g = GImGui;
  3117. ImGuiWindow* window = GetCurrentWindow();
  3118. const bool hovered = IsHovered(bb, id);
  3119. bool pressed = false;
  3120. if (hovered)
  3121. {
  3122. g.HoveredId = id;
  3123. if (allow_key_modifiers || (!g.IO.KeyCtrl && !g.IO.KeyShift))
  3124. {
  3125. if (g.IO.MouseClicked[0])
  3126. {
  3127. SetActiveId(id);
  3128. FocusWindow(window);
  3129. }
  3130. else if (repeat && g.ActiveId && ImGui::IsMouseClicked(0, true))
  3131. {
  3132. pressed = true;
  3133. }
  3134. }
  3135. }
  3136. bool held = false;
  3137. if (g.ActiveId == id)
  3138. {
  3139. if (g.IO.MouseDown[0])
  3140. {
  3141. held = true;
  3142. }
  3143. else
  3144. {
  3145. if (hovered)
  3146. pressed = true;
  3147. SetActiveId(0);
  3148. }
  3149. }
  3150. if (out_hovered) *out_hovered = hovered;
  3151. if (out_held) *out_held = held;
  3152. return pressed;
  3153. }
  3154. bool ImGui::Button(const char* label, const ImVec2& size_arg, bool repeat_when_held)
  3155. {
  3156. ImGuiState& g = GImGui;
  3157. ImGuiWindow* window = GetCurrentWindow();
  3158. if (window->SkipItems)
  3159. return false;
  3160. const ImGuiStyle& style = g.Style;
  3161. const ImGuiID id = window->GetID(label);
  3162. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  3163. const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : text_size.x, size_arg.y != 0.0f ? size_arg.y : text_size.y);
  3164. const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size + style.FramePadding*2.0f);
  3165. ItemSize(bb);
  3166. if (!ItemAdd(bb, &id))
  3167. return false;
  3168. bool hovered, held;
  3169. bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true, repeat_when_held);
  3170. // Render
  3171. const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
  3172. RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
  3173. if (size.x < text_size.x || size.y < text_size.y)
  3174. 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
  3175. const ImVec2 off = ImVec2(ImMax(0.0f, size.x - text_size.x) * 0.5f, ImMax(0.0f, size.y - text_size.y) * 0.5f);
  3176. RenderText(bb.Min + style.FramePadding + off, label);
  3177. if (size.x < text_size.x || size.y < text_size.y)
  3178. PopClipRect();
  3179. return pressed;
  3180. }
  3181. // Small buttons fits within text without additional spacing.
  3182. bool ImGui::SmallButton(const char* label)
  3183. {
  3184. ImGuiState& g = GImGui;
  3185. ImGuiWindow* window = GetCurrentWindow();
  3186. if (window->SkipItems)
  3187. return false;
  3188. const ImGuiStyle& style = g.Style;
  3189. const ImGuiID id = window->GetID(label);
  3190. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  3191. const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size + ImVec2(style.FramePadding.x*2,0));
  3192. ItemSize(bb);
  3193. if (!ItemAdd(bb, &id))
  3194. return false;
  3195. bool hovered, held;
  3196. bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true);
  3197. // Render
  3198. const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
  3199. RenderFrame(bb.Min, bb.Max, col);
  3200. RenderText(bb.Min + ImVec2(style.FramePadding.x,0), label);
  3201. return pressed;
  3202. }
  3203. // Tip: use ImGui::PushID()/PopID() to push indices or pointers in the ID stack.
  3204. // Then you can keep 'str_id' empty or the same for all your buttons (instead of creating a string based on a non-string id)
  3205. bool ImGui::InvisibleButton(const char* str_id, const ImVec2& size)
  3206. {
  3207. ImGuiWindow* window = GetCurrentWindow();
  3208. if (window->SkipItems)
  3209. return false;
  3210. const ImGuiID id = window->GetID(str_id);
  3211. const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size);
  3212. ItemSize(bb);
  3213. if (!ItemAdd(bb, &id))
  3214. return false;
  3215. bool hovered, held;
  3216. bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true);
  3217. return pressed;
  3218. }
  3219. // Upper-right button to close a window.
  3220. static bool CloseWindowButton(bool* p_opened)
  3221. {
  3222. ImGuiWindow* window = GetCurrentWindow();
  3223. const ImGuiID id = window->GetID("##CLOSE");
  3224. const float size = window->TitleBarHeight() - 4.0f;
  3225. const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-3.0f-size,2.0f), window->Aabb().GetTR() + ImVec2(-3.0f,2.0f+size));
  3226. bool hovered, held;
  3227. bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true);
  3228. // Render
  3229. const ImU32 col = window->Color((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton);
  3230. const ImVec2 center = bb.GetCenter();
  3231. window->DrawList->AddCircleFilled(center, ImMax(2.0f,size*0.5f), col, 16);
  3232. const float cross_extent = (size * 0.5f * 0.7071f) - 1.0f;
  3233. if (hovered)
  3234. {
  3235. window->DrawList->AddLine(center + ImVec2(+cross_extent,+cross_extent), center + ImVec2(-cross_extent,-cross_extent), window->Color(ImGuiCol_Text));
  3236. window->DrawList->AddLine(center + ImVec2(+cross_extent,-cross_extent), center + ImVec2(-cross_extent,+cross_extent), window->Color(ImGuiCol_Text));
  3237. }
  3238. if (p_opened != NULL && pressed)
  3239. *p_opened = !*p_opened;
  3240. return pressed;
  3241. }
  3242. void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col)
  3243. {
  3244. ImGuiWindow* window = GetCurrentWindow();
  3245. if (window->SkipItems)
  3246. return;
  3247. ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size);
  3248. if (border_col.w > 0.0f)
  3249. bb.Max += ImVec2(2,2);
  3250. ItemSize(bb);
  3251. if (!ItemAdd(bb, NULL))
  3252. return;
  3253. if (border_col.w > 0.0f)
  3254. {
  3255. window->DrawList->AddRect(bb.Min, bb.Max, window->Color(border_col), 0.0f);
  3256. window->DrawList->AddImage(user_texture_id, bb.Min+ImVec2(1,1), bb.Max-ImVec2(1,1), uv0, uv1, window->Color(tint_col));
  3257. }
  3258. else
  3259. {
  3260. window->DrawList->AddImage(user_texture_id, bb.Min, bb.Max, uv0, uv1, window->Color(tint_col));
  3261. }
  3262. }
  3263. // frame_padding < 0: uses FramePadding from style (default)
  3264. // frame_padding = 0: no framing
  3265. // frame_padding > 0: set framing size
  3266. // The color used are the button colors.
  3267. bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, int frame_padding, const ImVec4& bg_col)
  3268. {
  3269. ImGuiState& g = GImGui;
  3270. ImGuiWindow* window = GetCurrentWindow();
  3271. if (window->SkipItems)
  3272. return false;
  3273. const ImGuiStyle& style = g.Style;
  3274. // Default to using texture ID as ID. User can still push string/integer prefixes.
  3275. // We could hash the size/uv to create a unique ID but that would prevent the user from animating buttons.
  3276. ImGui::PushID((void *)user_texture_id);
  3277. const ImGuiID id = window->GetID("#image");
  3278. ImGui::PopID();
  3279. const ImVec2 padding = (frame_padding >= 0) ? ImVec2((float)frame_padding, (float)frame_padding) : style.FramePadding;
  3280. const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size + padding*2);
  3281. const ImGuiAabb image_bb(window->DC.CursorPos + padding, window->DC.CursorPos + padding + size);
  3282. ItemSize(bb);
  3283. if (!ItemAdd(bb, &id))
  3284. return false;
  3285. bool hovered, held;
  3286. bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true);
  3287. // Render
  3288. const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
  3289. if (padding.x > 0.0f || padding.y > 0.0f)
  3290. RenderFrame(bb.Min, bb.Max, col);
  3291. if (bg_col.w > 0.0f)
  3292. window->DrawList->AddRectFilled(image_bb.Min, image_bb.Max, window->Color(bg_col));
  3293. window->DrawList->AddImage(user_texture_id, image_bb.Min, image_bb.Max, uv0, uv1);
  3294. return pressed;
  3295. }
  3296. // Start logging ImGui output to TTY
  3297. void ImGui::LogToTTY(int max_depth)
  3298. {
  3299. ImGuiState& g = GImGui;
  3300. ImGuiWindow* window = GetCurrentWindow();
  3301. if (g.LogEnabled)
  3302. return;
  3303. g.LogEnabled = true;
  3304. g.LogFile = stdout;
  3305. g.LogStartDepth = window->DC.TreeDepth;
  3306. if (max_depth >= 0)
  3307. g.LogAutoExpandMaxDepth = max_depth;
  3308. }
  3309. // Start logging ImGui output to given file
  3310. void ImGui::LogToFile(int max_depth, const char* filename)
  3311. {
  3312. ImGuiState& g = GImGui;
  3313. ImGuiWindow* window = GetCurrentWindow();
  3314. if (g.LogEnabled)
  3315. return;
  3316. if (!filename)
  3317. filename = g.IO.LogFilename;
  3318. g.LogFile = fopen(filename, "ab");
  3319. if (!g.LogFile)
  3320. {
  3321. IM_ASSERT(g.LogFile != NULL); // Consider this an error
  3322. return;
  3323. }
  3324. g.LogEnabled = true;
  3325. g.LogStartDepth = window->DC.TreeDepth;
  3326. if (max_depth >= 0)
  3327. g.LogAutoExpandMaxDepth = max_depth;
  3328. }
  3329. // Start logging ImGui output to clipboard
  3330. void ImGui::LogToClipboard(int max_depth)
  3331. {
  3332. ImGuiWindow* window = GetCurrentWindow();
  3333. ImGuiState& g = GImGui;
  3334. if (g.LogEnabled)
  3335. return;
  3336. g.LogEnabled = true;
  3337. g.LogFile = NULL;
  3338. g.LogStartDepth = window->DC.TreeDepth;
  3339. if (max_depth >= 0)
  3340. g.LogAutoExpandMaxDepth = max_depth;
  3341. }
  3342. void ImGui::LogFinish()
  3343. {
  3344. ImGuiState& g = GImGui;
  3345. if (!g.LogEnabled)
  3346. return;
  3347. ImGui::LogText(STR_NEWLINE);
  3348. g.LogEnabled = false;
  3349. if (g.LogFile != NULL)
  3350. {
  3351. if (g.LogFile == stdout)
  3352. fflush(g.LogFile);
  3353. else
  3354. fclose(g.LogFile);
  3355. g.LogFile = NULL;
  3356. }
  3357. if (g.LogClipboard->size() > 1)
  3358. {
  3359. if (g.IO.SetClipboardTextFn)
  3360. g.IO.SetClipboardTextFn(g.LogClipboard->begin());
  3361. g.LogClipboard->clear();
  3362. }
  3363. }
  3364. // Helper to display logging buttons
  3365. void ImGui::LogButtons()
  3366. {
  3367. ImGuiState& g = GImGui;
  3368. ImGui::PushID("LogButtons");
  3369. const bool log_to_tty = ImGui::Button("Log To TTY");
  3370. ImGui::SameLine();
  3371. const bool log_to_file = ImGui::Button("Log To File");
  3372. ImGui::SameLine();
  3373. const bool log_to_clipboard = ImGui::Button("Log To Clipboard");
  3374. ImGui::SameLine();
  3375. ImGui::PushItemWidth(80.0f);
  3376. ImGui::PushAllowKeyboardFocus(false);
  3377. ImGui::SliderInt("Depth", &g.LogAutoExpandMaxDepth, 0, 9, NULL);
  3378. ImGui::PopAllowKeyboardFocus();
  3379. ImGui::PopItemWidth();
  3380. ImGui::PopID();
  3381. // Start logging at the end of the function so that the buttons don't appear in the log
  3382. if (log_to_tty)
  3383. LogToTTY(g.LogAutoExpandMaxDepth);
  3384. if (log_to_file)
  3385. LogToFile(g.LogAutoExpandMaxDepth, g.IO.LogFilename);
  3386. if (log_to_clipboard)
  3387. LogToClipboard(g.LogAutoExpandMaxDepth);
  3388. }
  3389. bool ImGui::CollapsingHeader(const char* label, const char* str_id, const bool display_frame, const bool default_open)
  3390. {
  3391. ImGuiState& g = GImGui;
  3392. ImGuiWindow* window = GetCurrentWindow();
  3393. if (window->SkipItems)
  3394. return false;
  3395. const ImGuiStyle& style = g.Style;
  3396. IM_ASSERT(str_id != NULL || label != NULL);
  3397. if (str_id == NULL)
  3398. str_id = label;
  3399. if (label == NULL)
  3400. label = str_id;
  3401. const ImGuiID id = window->GetID(str_id);
  3402. // We only write to the tree storage if the user clicks
  3403. ImGuiStorage* storage = window->DC.StateStorage;
  3404. bool opened;
  3405. if (window->DC.OpenNextNode != -1)
  3406. {
  3407. opened = window->DC.OpenNextNode > 0;
  3408. storage->SetInt(id, opened);
  3409. window->DC.OpenNextNode = -1;
  3410. }
  3411. else
  3412. {
  3413. opened = storage->GetInt(id, default_open) != 0;
  3414. }
  3415. // Framed header expand a little outside the default padding
  3416. const ImVec2 window_padding = window->WindowPadding();
  3417. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  3418. const ImVec2 pos_min = window->DC.CursorPos;
  3419. const ImVec2 pos_max = window->Pos + GetContentRegionMax();
  3420. ImGuiAabb bb = ImGuiAabb(pos_min, ImVec2(pos_max.x, pos_min.y + text_size.y));
  3421. if (display_frame)
  3422. {
  3423. bb.Min.x -= window_padding.x*0.5f - 1;
  3424. bb.Max.x += window_padding.x*0.5f - 1;
  3425. bb.Max.y += style.FramePadding.y * 2;
  3426. }
  3427. const ImGuiAabb text_bb(bb.Min, bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2*2,0) + text_size);
  3428. 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
  3429. // When logging is enabled, if automatically expand tree nodes (but *NOT* collapsing headers.. seems like sensible behaviour).
  3430. // NB- If we are above max depth we still allow manually opened nodes to be logged.
  3431. if (!display_frame)
  3432. if (g.LogEnabled && window->DC.TreeDepth < g.LogAutoExpandMaxDepth)
  3433. opened = true;
  3434. if (!ItemAdd(bb, &id))
  3435. return opened;
  3436. bool hovered, held;
  3437. bool pressed = ButtonBehaviour(display_frame ? bb : text_bb, id, &hovered, &held, false);
  3438. if (pressed)
  3439. {
  3440. opened = !opened;
  3441. storage->SetInt(id, opened);
  3442. }
  3443. // Render
  3444. const ImU32 col = window->Color((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
  3445. if (display_frame)
  3446. {
  3447. // Framed type
  3448. RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
  3449. RenderCollapseTriangle(bb.Min + style.FramePadding, opened, 1.0f, true);
  3450. if (g.LogEnabled)
  3451. {
  3452. // NB: '##' is normally used to hide text (as a library-wide feature), so we need to specify the text range to make sure the ## aren't stripped out here.
  3453. const char log_prefix[] = "\n##";
  3454. LogText(bb.Min + style.FramePadding, log_prefix, log_prefix+3);
  3455. }
  3456. RenderText(bb.Min + style.FramePadding + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label);
  3457. if (g.LogEnabled)
  3458. {
  3459. const char log_suffix[] = "##";
  3460. LogText(bb.Min + style.FramePadding, log_suffix, log_suffix+2);
  3461. }
  3462. }
  3463. else
  3464. {
  3465. // Unframed typed for tree nodes
  3466. if ((held && hovered) || hovered)
  3467. RenderFrame(bb.Min, bb.Max, col, false);
  3468. RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, window->FontSize()*0.15f), opened, 0.70f, false);
  3469. if (g.LogEnabled)
  3470. LogText(bb.Min, ">");
  3471. RenderText(bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label);
  3472. }
  3473. return opened;
  3474. }
  3475. // Text with a little bullet aligned to the typical tree node.
  3476. void ImGui::BulletTextV(const char* fmt, va_list args)
  3477. {
  3478. ImGuiState& g = GImGui;
  3479. ImGuiWindow* window = GetCurrentWindow();
  3480. if (window->SkipItems)
  3481. return;
  3482. const ImGuiStyle& style = g.Style;
  3483. static char buf[1024];
  3484. const char* text_begin = buf;
  3485. const char* text_end = text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  3486. const float line_height = window->FontSize();
  3487. const ImVec2 text_size = CalcTextSize(text_begin, text_end, true);
  3488. const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (text_size.x > 0.0f ? (style.FramePadding.x*2) : 0.0f),0) + text_size); // Empty text doesn't add padding
  3489. ItemSize(bb);
  3490. if (!ItemAdd(bb, NULL))
  3491. return;
  3492. // Render
  3493. const float bullet_size = line_height*0.15f;
  3494. window->DrawList->AddCircleFilled(bb.Min + ImVec2(style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text));
  3495. RenderText(bb.Min+ImVec2(window->FontSize() + style.FramePadding.x*2,0), text_begin, text_end);
  3496. }
  3497. void ImGui::BulletText(const char* fmt, ...)
  3498. {
  3499. va_list args;
  3500. va_start(args, fmt);
  3501. BulletTextV(fmt, args);
  3502. va_end(args);
  3503. }
  3504. // If returning 'true' the node is open and the user is responsible for calling TreePop
  3505. bool ImGui::TreeNodeV(const char* str_id, const char* fmt, va_list args)
  3506. {
  3507. static char buf[1024];
  3508. ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  3509. if (!str_id || !str_id[0])
  3510. str_id = fmt;
  3511. ImGui::PushID(str_id);
  3512. const bool opened = ImGui::CollapsingHeader(buf, "", false); // do not add to the ID so that TreeNodeSetOpen can access
  3513. ImGui::PopID();
  3514. if (opened)
  3515. ImGui::TreePush(str_id);
  3516. return opened;
  3517. }
  3518. bool ImGui::TreeNode(const char* str_id, const char* fmt, ...)
  3519. {
  3520. va_list args;
  3521. va_start(args, fmt);
  3522. bool s = TreeNodeV(str_id, fmt, args);
  3523. va_end(args);
  3524. return s;
  3525. }
  3526. // If returning 'true' the node is open and the user is responsible for calling TreePop
  3527. bool ImGui::TreeNodeV(const void* ptr_id, const char* fmt, va_list args)
  3528. {
  3529. static char buf[1024];
  3530. ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  3531. if (!ptr_id)
  3532. ptr_id = fmt;
  3533. ImGui::PushID(ptr_id);
  3534. const bool opened = ImGui::CollapsingHeader(buf, "", false);
  3535. ImGui::PopID();
  3536. if (opened)
  3537. ImGui::TreePush(ptr_id);
  3538. return opened;
  3539. }
  3540. bool ImGui::TreeNode(const void* ptr_id, const char* fmt, ...)
  3541. {
  3542. va_list args;
  3543. va_start(args, fmt);
  3544. bool s = TreeNodeV(ptr_id, fmt, args);
  3545. va_end(args);
  3546. return s;
  3547. }
  3548. bool ImGui::TreeNode(const char* str_label_id)
  3549. {
  3550. return TreeNode(str_label_id, "%s", str_label_id);
  3551. }
  3552. void ImGui::OpenNextNode(bool open)
  3553. {
  3554. ImGuiWindow* window = GetCurrentWindow();
  3555. window->DC.OpenNextNode = open ? 1 : 0;
  3556. }
  3557. void ImGui::PushID(const char* str_id)
  3558. {
  3559. ImGuiWindow* window = GetCurrentWindow();
  3560. window->IDStack.push_back(window->GetID(str_id));
  3561. }
  3562. void ImGui::PushID(const void* ptr_id)
  3563. {
  3564. ImGuiWindow* window = GetCurrentWindow();
  3565. window->IDStack.push_back(window->GetID(ptr_id));
  3566. }
  3567. void ImGui::PushID(const int int_id)
  3568. {
  3569. const void* ptr_id = (void*)(intptr_t)int_id;
  3570. ImGuiWindow* window = GetCurrentWindow();
  3571. window->IDStack.push_back(window->GetID(ptr_id));
  3572. }
  3573. void ImGui::PopID()
  3574. {
  3575. ImGuiWindow* window = GetCurrentWindow();
  3576. window->IDStack.pop_back();
  3577. }
  3578. ImGuiID ImGui::GetID(const char* str_id)
  3579. {
  3580. ImGuiWindow* window = GetCurrentWindow();
  3581. return window->GetID(str_id);
  3582. }
  3583. ImGuiID ImGui::GetID(const void* ptr_id)
  3584. {
  3585. ImGuiWindow* window = GetCurrentWindow();
  3586. return window->GetID(ptr_id);
  3587. }
  3588. // User can input math operators (e.g. +100) to edit a numerical values.
  3589. // NB: only call right after InputText because we are using its InitialValue storage
  3590. static void ApplyNumericalTextInput(const char* buf, float *v)
  3591. {
  3592. while (*buf == ' ' || *buf == '\t')
  3593. buf++;
  3594. // We don't support '-' op because it would conflict with inputing negative value.
  3595. // Instead you can use +-100 to subtract from an existing value
  3596. char op = buf[0];
  3597. if (op == '+' || op == '*' || op == '/')
  3598. {
  3599. buf++;
  3600. while (*buf == ' ' || *buf == '\t')
  3601. buf++;
  3602. }
  3603. else
  3604. {
  3605. op = 0;
  3606. }
  3607. if (!buf[0])
  3608. return;
  3609. float ref_v = *v;
  3610. if (op)
  3611. if (sscanf(GImGui.InputTextState.InitialText, "%f", &ref_v) < 1)
  3612. return;
  3613. float op_v = 0.0f;
  3614. if (sscanf(buf, "%f", &op_v) < 1)
  3615. return;
  3616. if (op == '+')
  3617. *v = ref_v + op_v;
  3618. else if (op == '*')
  3619. *v = ref_v * op_v;
  3620. else if (op == '/')
  3621. {
  3622. if (op_v == 0.0f)
  3623. return;
  3624. *v = ref_v / op_v;
  3625. }
  3626. else
  3627. *v = op_v;
  3628. }
  3629. // Use power!=1.0 for logarithmic sliders.
  3630. // Adjust display_format to decorate the value with a prefix or a suffix.
  3631. bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format, float power)
  3632. {
  3633. ImGuiState& g = GImGui;
  3634. ImGuiWindow* window = GetCurrentWindow();
  3635. if (window->SkipItems)
  3636. return false;
  3637. const ImGuiStyle& style = g.Style;
  3638. const ImGuiID id = window->GetID(label);
  3639. const float w = window->DC.ItemWidth.back();
  3640. if (!display_format)
  3641. display_format = "%.3f";
  3642. // Parse display precision back from the display format string
  3643. int decimal_precision = 3;
  3644. if (const char* p = strchr(display_format, '%'))
  3645. {
  3646. p++;
  3647. while (*p >= '0' && *p <= '9')
  3648. p++;
  3649. if (*p == '.')
  3650. {
  3651. decimal_precision = atoi(p+1);
  3652. if (decimal_precision < 0 || decimal_precision > 10)
  3653. decimal_precision = 3;
  3654. }
  3655. }
  3656. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  3657. const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f);
  3658. const ImGuiAabb slider_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
  3659. const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(text_size.x > 0.0f ? style.ItemInnerSpacing.x + text_size.x : 0.0f, 0.0f));
  3660. // NB- we don't call ItemSize() yet becausae we may turn into a text edit box later in the function
  3661. if (!ItemAdd(slider_bb, &id))
  3662. {
  3663. ItemSize(bb);
  3664. return false;
  3665. }
  3666. const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id);
  3667. const bool is_unbound = v_min == -FLT_MAX || v_min == FLT_MAX || v_max == -FLT_MAX || v_max == FLT_MAX;
  3668. const float grab_size_in_units = 1.0f; // In 'v' units. Probably needs to be parametrized, based on a 'v_step' value? decimal precision?
  3669. float grab_size_in_pixels;
  3670. if (decimal_precision > 0 || is_unbound)
  3671. grab_size_in_pixels = 10.0f;
  3672. else
  3673. grab_size_in_pixels = ImMax(grab_size_in_units * (w / (v_max-v_min+1.0f)), 8.0f); // Integer sliders
  3674. const float slider_effective_w = slider_bb.GetWidth() - grab_size_in_pixels;
  3675. const float slider_effective_x1 = slider_bb.Min.x + grab_size_in_pixels*0.5f;
  3676. const float slider_effective_x2 = slider_bb.Max.x - grab_size_in_pixels*0.5f;
  3677. // For logarithmic sliders that cross over sign boundary we want the exponential increase to be symmetric around 0.0f
  3678. float linear_zero_pos = 0.0f; // 0.0->1.0f
  3679. if (!is_unbound)
  3680. {
  3681. if (v_min * v_max < 0.0f)
  3682. {
  3683. // Different sign
  3684. const float linear_dist_min_to_0 = powf(fabsf(0.0f - v_min), 1.0f/power);
  3685. const float linear_dist_max_to_0 = powf(fabsf(v_max - 0.0f), 1.0f/power);
  3686. linear_zero_pos = linear_dist_min_to_0 / (linear_dist_min_to_0+linear_dist_max_to_0);
  3687. }
  3688. else
  3689. {
  3690. // Same sign
  3691. linear_zero_pos = v_min < 0.0f ? 1.0f : 0.0f;
  3692. }
  3693. }
  3694. const bool hovered = IsHovered(slider_bb, id);
  3695. if (hovered)
  3696. g.HoveredId = id;
  3697. bool start_text_input = false;
  3698. if (tab_focus_requested || (hovered && g.IO.MouseClicked[0]))
  3699. {
  3700. SetActiveId(id);
  3701. FocusWindow(window);
  3702. const bool is_ctrl_down = g.IO.KeyCtrl;
  3703. if (tab_focus_requested || is_ctrl_down || is_unbound)
  3704. {
  3705. start_text_input = true;
  3706. g.SliderAsInputTextId = 0;
  3707. }
  3708. }
  3709. // Tabbing or CTRL-clicking through slider turns into an input box
  3710. bool value_changed = false;
  3711. if (start_text_input || (g.ActiveId == id && id == g.SliderAsInputTextId))
  3712. {
  3713. char text_buf[64];
  3714. ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%.*f", decimal_precision, *v);
  3715. SetActiveId(g.SliderAsInputTextId);
  3716. g.HoveredId = 0;
  3717. window->FocusItemUnregister(); // Our replacement slider will override the focus ID (registered previously to allow for a TAB focus to happen)
  3718. value_changed = ImGui::InputText(label, text_buf, IM_ARRAYSIZE(text_buf), ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll);
  3719. if (g.SliderAsInputTextId == 0)
  3720. {
  3721. // First frame
  3722. IM_ASSERT(g.ActiveId == id); // InputText ID should match the Slider ID (else we'd need to store them both which is also possible)
  3723. g.SliderAsInputTextId = g.ActiveId;
  3724. SetActiveId(id);
  3725. g.HoveredId = id;
  3726. }
  3727. else
  3728. {
  3729. if (g.ActiveId == g.SliderAsInputTextId)
  3730. SetActiveId(id);
  3731. else
  3732. {
  3733. SetActiveId(0);
  3734. g.SliderAsInputTextId = 0;
  3735. }
  3736. }
  3737. if (value_changed)
  3738. {
  3739. ApplyNumericalTextInput(text_buf, v);
  3740. }
  3741. return value_changed;
  3742. }
  3743. ItemSize(bb);
  3744. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
  3745. // Process clicking on the slider
  3746. if (g.ActiveId == id)
  3747. {
  3748. if (g.IO.MouseDown[0])
  3749. {
  3750. if (!is_unbound)
  3751. {
  3752. const float normalized_pos = ImClamp((g.IO.MousePos.x - slider_effective_x1) / slider_effective_w, 0.0f, 1.0f);
  3753. // Linear slider
  3754. //float new_value = ImLerp(v_min, v_max, normalized_pos);
  3755. // Account for logarithmic scale on both sides of the zero
  3756. float new_value;
  3757. if (normalized_pos < linear_zero_pos)
  3758. {
  3759. // Negative: rescale to the negative range before powering
  3760. float a = 1.0f - (normalized_pos / linear_zero_pos);
  3761. a = powf(a, power);
  3762. new_value = ImLerp(ImMin(v_max,0.f), v_min, a);
  3763. }
  3764. else
  3765. {
  3766. // Positive: rescale to the positive range before powering
  3767. float a;
  3768. if (fabsf(linear_zero_pos - 1.0f) > 1.e-6)
  3769. a = (normalized_pos - linear_zero_pos) / (1.0f - linear_zero_pos);
  3770. else
  3771. a = normalized_pos;
  3772. a = powf(a, power);
  3773. new_value = ImLerp(ImMax(v_min,0.0f), v_max, a);
  3774. }
  3775. // Round past decimal precision
  3776. // 0->1, 1->0.1, 2->0.01, etc.
  3777. // So when our value is 1.99999 with a precision of 0.001 we'll end up rounding to 2.0
  3778. const float min_step = 1.0f / powf(10.0f, (float)decimal_precision);
  3779. const float remainder = fmodf(new_value, min_step);
  3780. if (remainder <= min_step*0.5f)
  3781. new_value -= remainder;
  3782. else
  3783. new_value += (min_step - remainder);
  3784. if (*v != new_value)
  3785. {
  3786. *v = new_value;
  3787. value_changed = true;
  3788. }
  3789. }
  3790. }
  3791. else
  3792. {
  3793. SetActiveId(0);
  3794. }
  3795. }
  3796. if (!is_unbound)
  3797. {
  3798. // Linear slider
  3799. // const float grab_t = (ImClamp(*v, v_min, v_max) - v_min) / (v_max - v_min);
  3800. // Calculate slider grab positioning
  3801. float grab_t;
  3802. float v_clamped = ImClamp(*v, v_min, v_max);
  3803. if (v_clamped < 0.0f)
  3804. {
  3805. const float f = 1.0f - (v_clamped - v_min) / (ImMin(0.0f,v_max) - v_min);
  3806. grab_t = (1.0f - powf(f, 1.0f/power)) * linear_zero_pos;
  3807. }
  3808. else
  3809. {
  3810. const float f = (v_clamped - ImMax(0.0f,v_min)) / (v_max - ImMax(0.0f,v_min));
  3811. grab_t = linear_zero_pos + powf(f, 1.0f/power) * (1.0f - linear_zero_pos);
  3812. }
  3813. // Draw
  3814. const float grab_x = ImLerp(slider_effective_x1, slider_effective_x2, grab_t);
  3815. 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));
  3816. window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, window->Color(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab));
  3817. }
  3818. // Draw value using user-provided display format so user can add prefix/suffix/decorations to the value.
  3819. char value_buf[64];
  3820. ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
  3821. RenderText(ImVec2(slider_bb.GetCenter().x-CalcTextSize(value_buf, NULL, true).x*0.5f, frame_bb.Min.y + style.FramePadding.y), value_buf);
  3822. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, slider_bb.Min.y), label);
  3823. return value_changed;
  3824. }
  3825. bool ImGui::SliderAngle(const char* label, float* v, float v_degrees_min, float v_degrees_max)
  3826. {
  3827. float v_deg = *v * 360.0f / (2*PI);
  3828. bool value_changed = ImGui::SliderFloat(label, &v_deg, v_degrees_min, v_degrees_max, "%.0f deg", 1.0f);
  3829. *v = v_deg * (2*PI) / 360.0f;
  3830. return value_changed;
  3831. }
  3832. bool ImGui::SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format)
  3833. {
  3834. if (!display_format)
  3835. display_format = "%.0f";
  3836. float v_f = (float)*v;
  3837. bool value_changed = ImGui::SliderFloat(label, &v_f, (float)v_min, (float)v_max, display_format, 1.0f);
  3838. *v = (int)v_f;
  3839. return value_changed;
  3840. }
  3841. // Add multiple sliders on 1 line for compact edition of multiple components
  3842. static bool SliderFloatN(const char* label, float v[3], int components, float v_min, float v_max, const char* display_format, float power)
  3843. {
  3844. ImGuiState& g = GImGui;
  3845. ImGuiWindow* window = GetCurrentWindow();
  3846. if (window->SkipItems)
  3847. return false;
  3848. const ImGuiStyle& style = g.Style;
  3849. const float w_full = window->DC.ItemWidth.back();
  3850. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)) / (float)components));
  3851. 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)));
  3852. bool value_changed = false;
  3853. ImGui::PushID(label);
  3854. ImGui::PushItemWidth(w_item_one);
  3855. for (int i = 0; i < components; i++)
  3856. {
  3857. ImGui::PushID(i);
  3858. if (i + 1 == components)
  3859. {
  3860. ImGui::PopItemWidth();
  3861. ImGui::PushItemWidth(w_item_last);
  3862. }
  3863. value_changed |= ImGui::SliderFloat("##v", &v[i], v_min, v_max, display_format, power);
  3864. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  3865. ImGui::PopID();
  3866. }
  3867. ImGui::PopItemWidth();
  3868. ImGui::PopID();
  3869. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  3870. return value_changed;
  3871. }
  3872. bool ImGui::SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format, float power)
  3873. {
  3874. return SliderFloatN(label, v, 2, v_min, v_max, display_format, power);
  3875. }
  3876. bool ImGui::SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format, float power)
  3877. {
  3878. return SliderFloatN(label, v, 3, v_min, v_max, display_format, power);
  3879. }
  3880. bool ImGui::SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format, float power)
  3881. {
  3882. return SliderFloatN(label, v, 4, v_min, v_max, display_format, power);
  3883. }
  3884. static bool SliderIntN(const char* label, int v[3], int components, int v_min, int v_max, const char* display_format)
  3885. {
  3886. ImGuiState& g = GImGui;
  3887. ImGuiWindow* window = GetCurrentWindow();
  3888. if (window->SkipItems)
  3889. return false;
  3890. const ImGuiStyle& style = g.Style;
  3891. const float w_full = window->DC.ItemWidth.back();
  3892. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*(components-1)) / (float)components));
  3893. 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)));
  3894. bool value_changed = false;
  3895. ImGui::PushID(label);
  3896. ImGui::PushItemWidth(w_item_one);
  3897. for (int i = 0; i < components; i++)
  3898. {
  3899. ImGui::PushID(i);
  3900. if (i + 1 == components)
  3901. {
  3902. ImGui::PopItemWidth();
  3903. ImGui::PushItemWidth(w_item_last);
  3904. }
  3905. value_changed |= ImGui::SliderInt("##v", &v[i], v_min, v_max, display_format);
  3906. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  3907. ImGui::PopID();
  3908. }
  3909. ImGui::PopItemWidth();
  3910. ImGui::PopID();
  3911. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  3912. return value_changed;
  3913. }
  3914. bool ImGui::SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* display_format)
  3915. {
  3916. return SliderIntN(label, v, 2, v_min, v_max, display_format);
  3917. }
  3918. bool ImGui::SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* display_format)
  3919. {
  3920. return SliderIntN(label, v, 3, v_min, v_max, display_format);
  3921. }
  3922. bool ImGui::SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* display_format)
  3923. {
  3924. return SliderIntN(label, v, 4, v_min, v_max, display_format);
  3925. }
  3926. enum ImGuiPlotType
  3927. {
  3928. ImGuiPlotType_Lines,
  3929. ImGuiPlotType_Histogram
  3930. };
  3931. static void Plot(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size)
  3932. {
  3933. ImGuiState& g = GImGui;
  3934. ImGuiWindow* window = GetCurrentWindow();
  3935. if (window->SkipItems)
  3936. return;
  3937. const ImGuiStyle& style = g.Style;
  3938. const ImVec2 text_size = ImGui::CalcTextSize(label, NULL, true);
  3939. if (graph_size.x == 0.0f)
  3940. graph_size.x = window->DC.ItemWidth.back();
  3941. if (graph_size.y == 0.0f)
  3942. graph_size.y = text_size.y;
  3943. const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y) + style.FramePadding*2.0f);
  3944. const ImGuiAabb graph_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
  3945. const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(text_size.x > 0.0f ? style.ItemInnerSpacing.x + text_size.x : 0.0f, 0));
  3946. ItemSize(bb);
  3947. if (!ItemAdd(bb, NULL))
  3948. return;
  3949. // Determine scale from values if not specified
  3950. if (scale_min == FLT_MAX || scale_max == FLT_MAX)
  3951. {
  3952. float v_min = FLT_MAX;
  3953. float v_max = -FLT_MAX;
  3954. for (int i = 0; i < values_count; i++)
  3955. {
  3956. const float v = values_getter(data, i);
  3957. v_min = ImMin(v_min, v);
  3958. v_max = ImMax(v_max, v);
  3959. }
  3960. if (scale_min == FLT_MAX)
  3961. scale_min = v_min;
  3962. if (scale_max == FLT_MAX)
  3963. scale_max = v_max;
  3964. }
  3965. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
  3966. int res_w = ImMin((int)graph_size.x, values_count);
  3967. if (plot_type == ImGuiPlotType_Lines)
  3968. res_w -= 1;
  3969. // Tooltip on hover
  3970. int v_hovered = -1;
  3971. if (IsMouseHoveringBox(graph_bb))
  3972. {
  3973. const float t = ImClamp((g.IO.MousePos.x - graph_bb.Min.x) / (graph_bb.Max.x - graph_bb.Min.x), 0.0f, 0.9999f);
  3974. const int v_idx = (int)(t * (values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0)));
  3975. IM_ASSERT(v_idx >= 0 && v_idx < values_count);
  3976. const float v0 = values_getter(data, (v_idx + values_offset) % values_count);
  3977. const float v1 = values_getter(data, (v_idx + 1 + values_offset) % values_count);
  3978. if (plot_type == ImGuiPlotType_Lines)
  3979. ImGui::SetTooltip("%d: %8.4g\n%d: %8.4g", v_idx, v0, v_idx+1, v1);
  3980. else if (plot_type == ImGuiPlotType_Histogram)
  3981. ImGui::SetTooltip("%d: %8.4g", v_idx, v0);
  3982. v_hovered = v_idx;
  3983. }
  3984. const float t_step = 1.0f / (float)res_w;
  3985. float v0 = values_getter(data, (0 + values_offset) % values_count);
  3986. float t0 = 0.0f;
  3987. ImVec2 p0 = ImVec2( t0, 1.0f - ImSaturate((v0 - scale_min) / (scale_max - scale_min)) );
  3988. const ImU32 col_base = window->Color((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLines : ImGuiCol_PlotHistogram);
  3989. const ImU32 col_hovered = window->Color((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLinesHovered : ImGuiCol_PlotHistogramHovered);
  3990. for (int n = 0; n < res_w; n++)
  3991. {
  3992. const float t1 = t0 + t_step;
  3993. const int v_idx = (int)(t0 * values_count);
  3994. IM_ASSERT(v_idx >= 0 && v_idx < values_count);
  3995. const float v1 = values_getter(data, (v_idx + values_offset + 1) % values_count);
  3996. const ImVec2 p1 = ImVec2( t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min)) );
  3997. // NB- Draw calls are merged together by the DrawList system.
  3998. if (plot_type == ImGuiPlotType_Lines)
  3999. 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);
  4000. else if (plot_type == ImGuiPlotType_Histogram)
  4001. 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);
  4002. t0 = t1;
  4003. p0 = p1;
  4004. }
  4005. // Text overlay
  4006. if (overlay_text)
  4007. RenderText(ImVec2(graph_bb.GetCenter().x - ImGui::CalcTextSize(overlay_text, NULL, true).x*0.5f, frame_bb.Min.y + style.FramePadding.y), overlay_text);
  4008. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, graph_bb.Min.y), label);
  4009. }
  4010. struct ImGuiPlotArrayGetterData
  4011. {
  4012. const float* Values;
  4013. size_t Stride;
  4014. ImGuiPlotArrayGetterData(const float* values, size_t stride) { Values = values; Stride = stride; }
  4015. };
  4016. static float Plot_ArrayGetter(void* data, int idx)
  4017. {
  4018. ImGuiPlotArrayGetterData* plot_data = (ImGuiPlotArrayGetterData*)data;
  4019. const float v = *(float*)(void*)((unsigned char*)plot_data->Values + (size_t)idx * plot_data->Stride);
  4020. return v;
  4021. }
  4022. void ImGui::PlotLines(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, size_t stride)
  4023. {
  4024. ImGuiPlotArrayGetterData data(values, stride);
  4025. Plot(ImGuiPlotType_Lines, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  4026. }
  4027. void ImGui::PlotLines(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size)
  4028. {
  4029. Plot(ImGuiPlotType_Lines, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  4030. }
  4031. void ImGui::PlotHistogram(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, size_t stride)
  4032. {
  4033. ImGuiPlotArrayGetterData data(values, stride);
  4034. Plot(ImGuiPlotType_Histogram, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  4035. }
  4036. void ImGui::PlotHistogram(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size)
  4037. {
  4038. Plot(ImGuiPlotType_Histogram, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size);
  4039. }
  4040. bool ImGui::Checkbox(const char* label, bool* v)
  4041. {
  4042. ImGuiState& g = GImGui;
  4043. ImGuiWindow* window = GetCurrentWindow();
  4044. if (window->SkipItems)
  4045. return false;
  4046. const ImGuiStyle& style = g.Style;
  4047. const ImGuiID id = window->GetID(label);
  4048. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  4049. 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));
  4050. ItemSize(check_bb);
  4051. ImGuiAabb total_bb = check_bb;
  4052. if (text_size.x > 0)
  4053. SameLine(0, (int)style.ItemInnerSpacing.x);
  4054. const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + text_size);
  4055. if (text_size.x > 0)
  4056. {
  4057. ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()));
  4058. total_bb = ImGuiAabb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max));
  4059. }
  4060. if (!ItemAdd(total_bb, &id))
  4061. return false;
  4062. bool hovered, held;
  4063. bool pressed = ButtonBehaviour(total_bb, id, &hovered, &held, true);
  4064. if (pressed)
  4065. *v = !(*v);
  4066. RenderFrame(check_bb.Min, check_bb.Max, window->Color((held && hovered) ? ImGuiCol_CheckActive : hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg), true, style.FrameRounding);
  4067. if (*v)
  4068. {
  4069. const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
  4070. const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f;
  4071. window->DrawList->AddRectFilled(check_bb.Min+ImVec2(pad,pad), check_bb.Max-ImVec2(pad,pad), window->Color(ImGuiCol_CheckMark), style.FrameRounding);
  4072. }
  4073. if (g.LogEnabled)
  4074. LogText(text_bb.GetTL(), *v ? "[x]" : "[ ]");
  4075. RenderText(text_bb.GetTL(), label);
  4076. return pressed;
  4077. }
  4078. bool ImGui::CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value)
  4079. {
  4080. bool v = (*flags & flags_value) ? true : false;
  4081. bool pressed = ImGui::Checkbox(label, &v);
  4082. if (v)
  4083. *flags |= flags_value;
  4084. else
  4085. *flags &= ~flags_value;
  4086. return pressed;
  4087. }
  4088. bool ImGui::RadioButton(const char* label, bool active)
  4089. {
  4090. ImGuiState& g = GImGui;
  4091. ImGuiWindow* window = GetCurrentWindow();
  4092. if (window->SkipItems)
  4093. return false;
  4094. const ImGuiStyle& style = g.Style;
  4095. const ImGuiID id = window->GetID(label);
  4096. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  4097. 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));
  4098. ItemSize(check_bb);
  4099. ImGuiAabb total_bb = check_bb;
  4100. if (text_size.x > 0)
  4101. SameLine(0, (int)style.ItemInnerSpacing.x);
  4102. const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + text_size);
  4103. if (text_size.x > 0)
  4104. {
  4105. ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight()));
  4106. total_bb.Add(text_bb);
  4107. }
  4108. if (!ItemAdd(total_bb, &id))
  4109. return false;
  4110. ImVec2 center = check_bb.GetCenter();
  4111. center.x = (float)(int)center.x + 0.5f;
  4112. center.y = (float)(int)center.y + 0.5f;
  4113. const float radius = check_bb.GetHeight() * 0.5f;
  4114. bool hovered, held;
  4115. bool pressed = ButtonBehaviour(total_bb, id, &hovered, &held, true);
  4116. window->DrawList->AddCircleFilled(center, radius, window->Color((held && hovered) ? ImGuiCol_CheckActive : hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg), 16);
  4117. if (active)
  4118. {
  4119. const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight());
  4120. const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f;
  4121. window->DrawList->AddCircleFilled(center, radius-pad, window->Color(ImGuiCol_CheckMark), 16);
  4122. }
  4123. if (window->Flags & ImGuiWindowFlags_ShowBorders)
  4124. {
  4125. window->DrawList->AddCircle(center+ImVec2(1,1), radius, window->Color(ImGuiCol_BorderShadow), 16);
  4126. window->DrawList->AddCircle(center, radius, window->Color(ImGuiCol_Border), 16);
  4127. }
  4128. if (g.LogEnabled)
  4129. LogText(text_bb.GetTL(), active ? "(x)" : "( )");
  4130. RenderText(text_bb.GetTL(), label);
  4131. return pressed;
  4132. }
  4133. bool ImGui::RadioButton(const char* label, int* v, int v_button)
  4134. {
  4135. const bool pressed = ImGui::RadioButton(label, *v == v_button);
  4136. if (pressed)
  4137. {
  4138. *v = v_button;
  4139. }
  4140. return pressed;
  4141. }
  4142. // Wrapper for stb_textedit.h to edit text (our wrapper is for: statically sized buffer, single-line, wchar characters. InputText converts between UTF-8 and wchar)
  4143. static int STB_TEXTEDIT_STRINGLEN(const STB_TEXTEDIT_STRING* obj) { return (int)ImStrlenW(obj->Text); }
  4144. static ImWchar STB_TEXTEDIT_GETCHAR(const STB_TEXTEDIT_STRING* obj, int idx) { return obj->Text[idx]; }
  4145. static float STB_TEXTEDIT_GETWIDTH(STB_TEXTEDIT_STRING* obj, int line_start_idx, int char_idx) { (void)line_start_idx; return obj->Font->CalcTextSizeW(obj->FontSize, FLT_MAX, &obj->Text[char_idx], &obj->Text[char_idx]+1, NULL).x; }
  4146. static int STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x10000 ? 0 : key; }
  4147. static ImWchar STB_TEXTEDIT_NEWLINE = '\n';
  4148. static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* obj, int line_start_idx)
  4149. {
  4150. const ImWchar* text_remaining = NULL;
  4151. const ImVec2 size = obj->Font->CalcTextSizeW(obj->FontSize, FLT_MAX, obj->Text + line_start_idx, NULL, &text_remaining);
  4152. r->x0 = 0.0f;
  4153. r->x1 = size.x;
  4154. r->baseline_y_delta = size.y;
  4155. r->ymin = 0.0f;
  4156. r->ymax = size.y;
  4157. r->num_chars = (int)(text_remaining - (obj->Text + line_start_idx));
  4158. }
  4159. static bool is_white(unsigned int c) { return c==0 || c==' ' || c=='\t' || c=='\r' || c=='\n'; }
  4160. static bool is_separator(unsigned int c) { return c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|'; }
  4161. #define STB_TEXTEDIT_IS_SPACE(CH) ( is_white((unsigned int)CH) || is_separator((unsigned int)CH) )
  4162. static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n) { ImWchar* dst = obj->Text+pos; const ImWchar* src = obj->Text+pos+n; while (ImWchar c = *src++) *dst++ = c; *dst = '\0'; }
  4163. static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const ImWchar* new_text, int new_text_len)
  4164. {
  4165. const size_t text_len = ImStrlenW(obj->Text);
  4166. if ((size_t)new_text_len + text_len + 1 >= obj->BufSize)
  4167. return false;
  4168. if (pos != (int)text_len)
  4169. memmove(obj->Text + (size_t)pos + new_text_len, obj->Text + (size_t)pos, (text_len - (size_t)pos) * sizeof(ImWchar));
  4170. memcpy(obj->Text + (size_t)pos, new_text, (size_t)new_text_len * sizeof(ImWchar));
  4171. obj->Text[text_len + (size_t)new_text_len] = '\0';
  4172. return true;
  4173. }
  4174. enum
  4175. {
  4176. STB_TEXTEDIT_K_LEFT = 1 << 16, // keyboard input to move cursor left
  4177. STB_TEXTEDIT_K_RIGHT, // keyboard input to move cursor right
  4178. STB_TEXTEDIT_K_UP, // keyboard input to move cursor up
  4179. STB_TEXTEDIT_K_DOWN, // keyboard input to move cursor down
  4180. STB_TEXTEDIT_K_LINESTART, // keyboard input to move cursor to start of line
  4181. STB_TEXTEDIT_K_LINEEND, // keyboard input to move cursor to end of line
  4182. STB_TEXTEDIT_K_TEXTSTART, // keyboard input to move cursor to start of text
  4183. STB_TEXTEDIT_K_TEXTEND, // keyboard input to move cursor to end of text
  4184. STB_TEXTEDIT_K_DELETE, // keyboard input to delete selection or character under cursor
  4185. STB_TEXTEDIT_K_BACKSPACE, // keyboard input to delete selection or character left of cursor
  4186. STB_TEXTEDIT_K_UNDO, // keyboard input to perform undo
  4187. STB_TEXTEDIT_K_REDO, // keyboard input to perform redo
  4188. STB_TEXTEDIT_K_WORDLEFT, // keyboard input to move cursor left one word
  4189. STB_TEXTEDIT_K_WORDRIGHT, // keyboard input to move cursor right one word
  4190. STB_TEXTEDIT_K_SHIFT = 1 << 17
  4191. };
  4192. #ifdef IMGUI_STB_NAMESPACE
  4193. namespace IMGUI_STB_NAMESPACE
  4194. {
  4195. #endif
  4196. #define STB_TEXTEDIT_IMPLEMENTATION
  4197. #include "stb_textedit.h"
  4198. #ifdef IMGUI_STB_NAMESPACE
  4199. }
  4200. #endif
  4201. void ImGuiTextEditState::OnKeyPressed(int key)
  4202. {
  4203. stb_textedit_key(this, &StbState, key);
  4204. CursorAnimReset();
  4205. }
  4206. void ImGuiTextEditState::UpdateScrollOffset()
  4207. {
  4208. // Scroll in chunks of quarter width
  4209. const float scroll_x_increment = Width * 0.25f;
  4210. const float cursor_offset_x = Font->CalcTextSizeW(FontSize, FLT_MAX, Text, Text+StbState.cursor, NULL).x;
  4211. if (ScrollX > cursor_offset_x)
  4212. ScrollX = ImMax(0.0f, cursor_offset_x - scroll_x_increment);
  4213. else if (ScrollX < cursor_offset_x - Width)
  4214. ScrollX = cursor_offset_x - Width + scroll_x_increment;
  4215. }
  4216. ImVec2 ImGuiTextEditState::CalcDisplayOffsetFromCharIdx(int i) const
  4217. {
  4218. const ImWchar* text_start = GetTextPointerClippedW(Font, FontSize, Text, ScrollX, NULL);
  4219. const ImWchar* text_end = (Text+i >= text_start) ? Text+i : text_start; // Clip if requested character is outside of display
  4220. IM_ASSERT(text_end >= text_start);
  4221. const ImVec2 offset = Font->CalcTextSizeW(FontSize, Width, text_start, text_end, NULL);
  4222. return offset;
  4223. }
  4224. // [Static]
  4225. const char* ImGuiTextEditState::GetTextPointerClippedA(ImFont* font, float font_size, const char* text, float width, ImVec2* out_text_size)
  4226. {
  4227. if (width <= 0.0f)
  4228. return text;
  4229. const char* text_clipped_end = NULL;
  4230. const ImVec2 text_size = font->CalcTextSizeA(font_size, width, 0.0f, text, NULL, &text_clipped_end);
  4231. if (out_text_size)
  4232. *out_text_size = text_size;
  4233. return text_clipped_end;
  4234. }
  4235. // [Static]
  4236. const ImWchar* ImGuiTextEditState::GetTextPointerClippedW(ImFont* font, float font_size, const ImWchar* text, float width, ImVec2* out_text_size)
  4237. {
  4238. if (width <= 0.0f)
  4239. return text;
  4240. const ImWchar* text_clipped_end = NULL;
  4241. const ImVec2 text_size = font->CalcTextSizeW(font_size, width, text, NULL, &text_clipped_end);
  4242. if (out_text_size)
  4243. *out_text_size = text_size;
  4244. return text_clipped_end;
  4245. }
  4246. // [Static]
  4247. void ImGuiTextEditState::RenderTextScrolledClipped(ImFont* font, float font_size, const char* buf, ImVec2 pos, float width, float scroll_x)
  4248. {
  4249. // NB- We start drawing at character boundary
  4250. ImVec2 text_size;
  4251. const char* text_start = GetTextPointerClippedA(font, font_size, buf, scroll_x, NULL);
  4252. const char* text_end = GetTextPointerClippedA(font, font_size, text_start, width, &text_size);
  4253. // Draw a little clip symbol if we've got text on either left or right of the box
  4254. const char symbol_c = '~';
  4255. const float symbol_w = font_size*0.40f; // FIXME: compute correct width
  4256. const float clip_begin = (text_start > buf && text_start < text_end) ? symbol_w : 0.0f;
  4257. const float clip_end = (text_end[0] != '\0' && text_end > text_start) ? symbol_w : 0.0f;
  4258. // Draw text
  4259. 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);
  4260. // Draw the clip symbol
  4261. const char s[2] = {symbol_c,'\0'};
  4262. if (clip_begin > 0.0f)
  4263. RenderText(pos, s);
  4264. if (clip_end > 0.0f)
  4265. RenderText(pos+ImVec2(width-clip_end,0.0f), s);
  4266. }
  4267. bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast, int decimal_precision, ImGuiInputTextFlags extra_flags)
  4268. {
  4269. ImGuiState& g = GImGui;
  4270. ImGuiWindow* window = GetCurrentWindow();
  4271. if (window->SkipItems)
  4272. return false;
  4273. const ImGuiStyle& style = g.Style;
  4274. const float w = window->DC.ItemWidth.back();
  4275. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  4276. const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f);
  4277. ImGui::PushID(label);
  4278. const float button_sz = window->FontSize();
  4279. if (step > 0.0f)
  4280. ImGui::PushItemWidth(ImMax(1.0f, w - (button_sz + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*2));
  4281. char buf[64];
  4282. if (decimal_precision < 0)
  4283. 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?
  4284. else
  4285. ImFormatString(buf, IM_ARRAYSIZE(buf), "%.*f", decimal_precision, *v);
  4286. bool value_changed = false;
  4287. const ImGuiInputTextFlags flags = extra_flags | (ImGuiInputTextFlags_CharsDecimal|ImGuiInputTextFlags_AutoSelectAll);
  4288. if (ImGui::InputText("", buf, IM_ARRAYSIZE(buf), flags))
  4289. {
  4290. ApplyNumericalTextInput(buf, v);
  4291. value_changed = true;
  4292. }
  4293. // Step buttons
  4294. if (step > 0.0f)
  4295. {
  4296. ImGui::PopItemWidth();
  4297. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4298. if (ImGui::Button("-", ImVec2(button_sz,button_sz), true))
  4299. {
  4300. *v -= g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step;
  4301. value_changed = true;
  4302. }
  4303. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4304. if (ImGui::Button("+", ImVec2(button_sz,button_sz), true))
  4305. {
  4306. *v += g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step;
  4307. value_changed = true;
  4308. }
  4309. }
  4310. ImGui::PopID();
  4311. if (text_size.x > 0)
  4312. {
  4313. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4314. ItemSize(text_size);
  4315. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  4316. }
  4317. return value_changed;
  4318. }
  4319. bool ImGui::InputInt(const char* label, int *v, int step, int step_fast, ImGuiInputTextFlags extra_flags)
  4320. {
  4321. float f = (float)*v;
  4322. const bool value_changed = ImGui::InputFloat(label, &f, (float)step, (float)step_fast, 0, extra_flags);
  4323. if (value_changed)
  4324. *v = (int)f;
  4325. return value_changed;
  4326. }
  4327. // Public API to manipulate UTF-8 text
  4328. // We expose UTF-8 to the user (unlike the STB_TEXTEDIT_* functions which are manipulating wchar)
  4329. void ImGuiTextEditCallbackData::DeleteChars(int pos, int bytes_count)
  4330. {
  4331. char* dst = Buf + pos;
  4332. const char* src = Buf + pos + bytes_count;
  4333. while (char c = *src++)
  4334. *dst++ = c;
  4335. *dst = '\0';
  4336. BufDirty = true;
  4337. if (CursorPos + bytes_count >= pos)
  4338. CursorPos -= bytes_count;
  4339. else if (CursorPos >= pos)
  4340. CursorPos = pos;
  4341. SelectionStart = SelectionEnd = CursorPos;
  4342. }
  4343. void ImGuiTextEditCallbackData::InsertChars(int pos, const char* new_text, const char* new_text_end)
  4344. {
  4345. const size_t text_len = strlen(Buf);
  4346. if (!new_text_end)
  4347. new_text_end = new_text + strlen(new_text);
  4348. const size_t new_text_len = (size_t)(new_text_end - new_text);
  4349. if (new_text_len + text_len + 1 >= BufSize)
  4350. return;
  4351. size_t upos = (size_t)pos;
  4352. if (text_len != upos)
  4353. memmove(Buf + upos + new_text_len, Buf + upos, text_len - upos);
  4354. memcpy(Buf + upos, new_text, new_text_len * sizeof(char));
  4355. Buf[text_len + new_text_len] = '\0';
  4356. BufDirty = true;
  4357. if (CursorPos >= pos)
  4358. CursorPos += (int)new_text_len;
  4359. SelectionStart = SelectionEnd = CursorPos;
  4360. }
  4361. static bool InputTextFilterCharacter(ImWchar c, ImGuiInputTextFlags flags)
  4362. {
  4363. if (c < 128 && c != ' ' && !isprint((int)(c & 0xFF)))
  4364. return true;
  4365. if (c >= 0xE000 && c <= 0xF8FF) // Filter private Unicode range. I don't imagine anybody would want to input them. GLFW on OSX seems to send private characters for special keys like arrow keys.
  4366. return true;
  4367. if (flags & ImGuiInputTextFlags_CharsDecimal)
  4368. if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/'))
  4369. return true;
  4370. if (flags & ImGuiInputTextFlags_CharsHexadecimal)
  4371. if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F'))
  4372. return true;
  4373. return false;
  4374. }
  4375. // Edit a string of text
  4376. bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, void (*callback)(ImGuiTextEditCallbackData*), void* user_data)
  4377. {
  4378. ImGuiState& g = GImGui;
  4379. ImGuiWindow* window = GetCurrentWindow();
  4380. if (window->SkipItems)
  4381. return false;
  4382. const ImGuiIO& io = g.IO;
  4383. const ImGuiStyle& style = g.Style;
  4384. const ImGuiID id = window->GetID(label);
  4385. const float w = window->DC.ItemWidth.back();
  4386. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  4387. const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f);
  4388. const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(text_size.x > 0.0f ? (style.ItemInnerSpacing.x + text_size.x) : 0.0f, 0.0f));
  4389. ItemSize(bb);
  4390. if (!ItemAdd(frame_bb, &id))
  4391. return false;
  4392. // NB: we are only allowed to access 'edit_state' if we are the active widget.
  4393. ImGuiTextEditState& edit_state = g.InputTextState;
  4394. const bool is_ctrl_down = io.KeyCtrl;
  4395. const bool is_shift_down = io.KeyShift;
  4396. const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id, (flags & ImGuiInputTextFlags_CallbackCompletion) == 0); // Using completion callback disable keyboard tabbing
  4397. //const bool align_center = (bool)(flags & ImGuiInputTextFlags_AlignCenter); // FIXME: Unsupported
  4398. const bool hovered = IsHovered(frame_bb, id);
  4399. if (hovered)
  4400. g.HoveredId = id;
  4401. bool select_all = (g.ActiveId != id) && (flags & ImGuiInputTextFlags_AutoSelectAll) != 0;
  4402. if (tab_focus_requested || (hovered && io.MouseClicked[0]))
  4403. {
  4404. if (g.ActiveId != id)
  4405. {
  4406. // Start edition
  4407. // Take a copy of the initial buffer value (both in original UTF-8 format and converted to wchar)
  4408. ImFormatString(edit_state.InitialText, IM_ARRAYSIZE(edit_state.InitialText), "%s", buf);
  4409. ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), buf, NULL);
  4410. edit_state.ScrollX = 0.0f;
  4411. edit_state.Width = w;
  4412. stb_textedit_initialize_state(&edit_state.StbState, true);
  4413. edit_state.CursorAnimReset();
  4414. edit_state.LastCursorPos = ImVec2(-1.f,-1.f);
  4415. if (tab_focus_requested || is_ctrl_down)
  4416. select_all = true;
  4417. }
  4418. SetActiveId(id);
  4419. FocusWindow(window);
  4420. }
  4421. else if (io.MouseClicked[0])
  4422. {
  4423. // Release focus when we click outside
  4424. if (g.ActiveId == id)
  4425. {
  4426. SetActiveId(0);
  4427. }
  4428. }
  4429. bool value_changed = false;
  4430. bool cancel_edit = false;
  4431. bool enter_pressed = false;
  4432. static char text_tmp_utf8[IM_ARRAYSIZE(edit_state.InitialText)];
  4433. if (g.ActiveId == id)
  4434. {
  4435. // Edit in progress
  4436. edit_state.BufSize = buf_size < IM_ARRAYSIZE(edit_state.Text) ? buf_size : IM_ARRAYSIZE(edit_state.Text);
  4437. edit_state.Font = window->Font();
  4438. edit_state.FontSize = window->FontSize();
  4439. const float mx = g.IO.MousePos.x - frame_bb.Min.x - style.FramePadding.x;
  4440. const float my = window->FontSize()*0.5f; // Flatten mouse because we are doing a single-line edit
  4441. edit_state.UpdateScrollOffset();
  4442. if (select_all || (hovered && io.MouseDoubleClicked[0]))
  4443. {
  4444. edit_state.SelectAll();
  4445. edit_state.SelectedAllMouseLock = true;
  4446. }
  4447. else if (io.MouseClicked[0] && !edit_state.SelectedAllMouseLock)
  4448. {
  4449. stb_textedit_click(&edit_state, &edit_state.StbState, mx + edit_state.ScrollX, my);
  4450. edit_state.CursorAnimReset();
  4451. }
  4452. else if (io.MouseDown[0] && !edit_state.SelectedAllMouseLock)
  4453. {
  4454. stb_textedit_drag(&edit_state, &edit_state.StbState, mx + edit_state.ScrollX, my);
  4455. edit_state.CursorAnimReset();
  4456. }
  4457. if (edit_state.SelectedAllMouseLock && !io.MouseDown[0])
  4458. edit_state.SelectedAllMouseLock = false;
  4459. if (g.IO.InputCharacters[0])
  4460. {
  4461. // Process text input (before we check for Return because using some IME will effectively send a Return?)
  4462. for (int n = 0; n < IM_ARRAYSIZE(g.IO.InputCharacters) && g.IO.InputCharacters[n]; n++)
  4463. {
  4464. const ImWchar c = g.IO.InputCharacters[n];
  4465. if (c)
  4466. {
  4467. // Insert character if they pass filtering
  4468. if (InputTextFilterCharacter(c, flags))
  4469. continue;
  4470. edit_state.OnKeyPressed(c);
  4471. }
  4472. }
  4473. // Consume characters
  4474. memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters));
  4475. }
  4476. const int k_mask = (is_shift_down ? STB_TEXTEDIT_K_SHIFT : 0);
  4477. if (IsKeyPressedMap(ImGuiKey_LeftArrow)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDLEFT | k_mask : STB_TEXTEDIT_K_LEFT | k_mask); }
  4478. else if (IsKeyPressedMap(ImGuiKey_RightArrow)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDRIGHT | k_mask : STB_TEXTEDIT_K_RIGHT | k_mask); }
  4479. else if (IsKeyPressedMap(ImGuiKey_Home)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTSTART | k_mask : STB_TEXTEDIT_K_LINESTART | k_mask); }
  4480. else if (IsKeyPressedMap(ImGuiKey_End)) { edit_state.OnKeyPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTEND | k_mask : STB_TEXTEDIT_K_LINEEND | k_mask); }
  4481. else if (IsKeyPressedMap(ImGuiKey_Delete)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_DELETE | k_mask); }
  4482. else if (IsKeyPressedMap(ImGuiKey_Backspace)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask); }
  4483. else if (IsKeyPressedMap(ImGuiKey_Enter)) { SetActiveId(0); enter_pressed = true; }
  4484. else if (IsKeyPressedMap(ImGuiKey_Escape)) { SetActiveId(0); cancel_edit = true; }
  4485. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Z)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_UNDO); }
  4486. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Y)) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_REDO); }
  4487. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_A)) { edit_state.SelectAll(); }
  4488. else if (is_ctrl_down && (IsKeyPressedMap(ImGuiKey_X) || IsKeyPressedMap(ImGuiKey_C)))
  4489. {
  4490. // Cut, Copy
  4491. const bool cut = IsKeyPressedMap(ImGuiKey_X);
  4492. if (cut && !edit_state.HasSelection())
  4493. edit_state.SelectAll();
  4494. if (g.IO.SetClipboardTextFn)
  4495. {
  4496. const int ib = edit_state.HasSelection() ? ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end) : 0;
  4497. const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : (int)ImStrlenW(edit_state.Text);
  4498. ImTextStrToUtf8(text_tmp_utf8, IM_ARRAYSIZE(text_tmp_utf8), edit_state.Text+ib, edit_state.Text+ie);
  4499. g.IO.SetClipboardTextFn(text_tmp_utf8);
  4500. }
  4501. if (cut)
  4502. stb_textedit_cut(&edit_state, &edit_state.StbState);
  4503. }
  4504. else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_V))
  4505. {
  4506. // Paste
  4507. if (g.IO.GetClipboardTextFn)
  4508. {
  4509. if (const char* clipboard = g.IO.GetClipboardTextFn())
  4510. {
  4511. // Remove new-line from pasted buffer
  4512. size_t clipboard_len = strlen(clipboard);
  4513. ImWchar* clipboard_filtered = (ImWchar*)ImGui::MemAlloc((clipboard_len+1) * sizeof(ImWchar));
  4514. int clipboard_filtered_len = 0;
  4515. for (const char* s = clipboard; *s; )
  4516. {
  4517. unsigned int c;
  4518. const int bytes_count = ImTextCharFromUtf8(&c, s, NULL);
  4519. if (bytes_count <= 0)
  4520. break;
  4521. s += bytes_count;
  4522. if (c >= 0x10000)
  4523. continue;
  4524. if (InputTextFilterCharacter((ImWchar)c, flags))
  4525. continue;
  4526. clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c;
  4527. }
  4528. clipboard_filtered[clipboard_filtered_len] = 0;
  4529. if (clipboard_filtered_len > 0) // If everything was filtered, ignore the pasting operation
  4530. stb_textedit_paste(&edit_state, &edit_state.StbState, clipboard_filtered, clipboard_filtered_len);
  4531. ImGui::MemFree(clipboard_filtered);
  4532. }
  4533. }
  4534. }
  4535. edit_state.CursorAnim += g.IO.DeltaTime;
  4536. edit_state.UpdateScrollOffset();
  4537. if (cancel_edit)
  4538. {
  4539. // Restore initial value
  4540. ImFormatString(buf, buf_size, "%s", edit_state.InitialText);
  4541. value_changed = true;
  4542. }
  4543. else
  4544. {
  4545. // Apply new value immediately - copy modified buffer back
  4546. // 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
  4547. // FIXME: We actually always render 'buf' in RenderTextScrolledClipped
  4548. // FIXME-OPT: CPU waste to do this every time the widget is active, should mark dirty state from the stb_textedit callbacks
  4549. ImTextStrToUtf8(text_tmp_utf8, IM_ARRAYSIZE(text_tmp_utf8), edit_state.Text, NULL);
  4550. // User callback
  4551. if ((flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackAlways)) != 0)
  4552. {
  4553. IM_ASSERT(callback != NULL);
  4554. // The reason we specify the usage semantic (Completion/History) is that Completion needs to disable keyboard TABBING at the moment.
  4555. ImGuiKey event_key = ImGuiKey_COUNT;
  4556. if ((flags & ImGuiInputTextFlags_CallbackCompletion) != 0 && IsKeyPressedMap(ImGuiKey_Tab))
  4557. event_key = ImGuiKey_Tab;
  4558. else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_UpArrow))
  4559. event_key = ImGuiKey_UpArrow;
  4560. else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_DownArrow))
  4561. event_key = ImGuiKey_DownArrow;
  4562. if (event_key != ImGuiKey_COUNT || (flags & ImGuiInputTextFlags_CallbackAlways) != 0)
  4563. {
  4564. ImGuiTextEditCallbackData callback_data;
  4565. callback_data.EventKey = event_key;
  4566. callback_data.Buf = text_tmp_utf8;
  4567. callback_data.BufSize = edit_state.BufSize;
  4568. callback_data.BufDirty = false;
  4569. callback_data.Flags = flags;
  4570. callback_data.UserData = user_data;
  4571. // We have to convert from position from wchar to UTF-8 positions
  4572. const int utf8_cursor_pos = callback_data.CursorPos = ImTextCountUtf8BytesFromWchar(edit_state.Text, edit_state.Text + edit_state.StbState.cursor);
  4573. const int utf8_selection_start = callback_data.SelectionStart = ImTextCountUtf8BytesFromWchar(edit_state.Text, edit_state.Text + edit_state.StbState.select_start);
  4574. const int utf8_selection_end = callback_data.SelectionEnd = ImTextCountUtf8BytesFromWchar(edit_state.Text, edit_state.Text + edit_state.StbState.select_end);
  4575. // Call user code
  4576. callback(&callback_data);
  4577. // Read back what user may have modified
  4578. IM_ASSERT(callback_data.Buf == text_tmp_utf8); // Invalid to modify those fields
  4579. IM_ASSERT(callback_data.BufSize == edit_state.BufSize);
  4580. IM_ASSERT(callback_data.Flags == flags);
  4581. if (callback_data.CursorPos != utf8_cursor_pos) edit_state.StbState.cursor = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.CursorPos);
  4582. if (callback_data.SelectionStart != utf8_selection_start) edit_state.StbState.select_start = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionStart);
  4583. if (callback_data.SelectionEnd != utf8_selection_end) edit_state.StbState.select_end = ImTextCountCharsFromUtf8(callback_data.Buf, callback_data.Buf + callback_data.SelectionEnd);
  4584. if (callback_data.BufDirty)
  4585. {
  4586. ImTextStrFromUtf8(edit_state.Text, IM_ARRAYSIZE(edit_state.Text), text_tmp_utf8, NULL);
  4587. edit_state.CursorAnimReset();
  4588. }
  4589. }
  4590. }
  4591. if (strcmp(text_tmp_utf8, buf) != 0)
  4592. {
  4593. ImFormatString(buf, buf_size, "%s", text_tmp_utf8);
  4594. value_changed = true;
  4595. }
  4596. }
  4597. }
  4598. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
  4599. const ImVec2 font_off_up = ImVec2(0.0f,window->FontSize()+1.0f); // FIXME: those offsets are part of the style or font API
  4600. const ImVec2 font_off_dn = ImVec2(0.0f,2.0f);
  4601. if (g.ActiveId == id)
  4602. {
  4603. // Draw selection
  4604. const int select_begin_idx = edit_state.StbState.select_start;
  4605. const int select_end_idx = edit_state.StbState.select_end;
  4606. if (select_begin_idx != select_end_idx)
  4607. {
  4608. const ImVec2 select_begin_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(ImMin(select_begin_idx,select_end_idx));
  4609. const ImVec2 select_end_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(ImMax(select_begin_idx,select_end_idx));
  4610. window->DrawList->AddRectFilled(select_begin_pos - font_off_up, select_end_pos + font_off_dn, window->Color(ImGuiCol_TextSelectedBg));
  4611. }
  4612. }
  4613. // FIXME: 'align_center' unsupported
  4614. ImGuiTextEditState::RenderTextScrolledClipped(window->Font(), window->FontSize(), buf, frame_bb.Min + style.FramePadding, w, (g.ActiveId == id) ? edit_state.ScrollX : 0.0f);
  4615. if (g.ActiveId == id)
  4616. {
  4617. const ImVec2 cursor_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(edit_state.StbState.cursor);
  4618. // Draw blinking cursor
  4619. if (g.InputTextState.CursorIsVisible())
  4620. window->DrawList->AddRect(cursor_pos - font_off_up + ImVec2(0,2), cursor_pos + font_off_dn - ImVec2(0,3), window->Color(ImGuiCol_Text));
  4621. // Notify OS of text input position
  4622. if (io.ImeSetInputScreenPosFn && ImLengthSqr(edit_state.LastCursorPos - cursor_pos) > 0.0001f)
  4623. 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.
  4624. edit_state.LastCursorPos = cursor_pos;
  4625. }
  4626. RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
  4627. if ((flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0)
  4628. return enter_pressed;
  4629. else
  4630. return value_changed;
  4631. }
  4632. static bool InputFloatN(const char* label, float* v, int components, int decimal_precision)
  4633. {
  4634. ImGuiState& g = GImGui;
  4635. ImGuiWindow* window = GetCurrentWindow();
  4636. if (window->SkipItems)
  4637. return false;
  4638. const ImGuiStyle& style = g.Style;
  4639. const float w_full = window->DC.ItemWidth.back();
  4640. const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components));
  4641. 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)));
  4642. bool value_changed = false;
  4643. ImGui::PushID(label);
  4644. ImGui::PushItemWidth(w_item_one);
  4645. for (int i = 0; i < components; i++)
  4646. {
  4647. ImGui::PushID(i);
  4648. if (i + 1 == components)
  4649. {
  4650. ImGui::PopItemWidth();
  4651. ImGui::PushItemWidth(w_item_last);
  4652. }
  4653. value_changed |= ImGui::InputFloat("##v", &v[i], 0, 0, decimal_precision);
  4654. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4655. ImGui::PopID();
  4656. }
  4657. ImGui::PopItemWidth();
  4658. ImGui::PopID();
  4659. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  4660. return value_changed;
  4661. }
  4662. bool ImGui::InputFloat2(const char* label, float v[2], int decimal_precision)
  4663. {
  4664. return InputFloatN(label, v, 2, decimal_precision);
  4665. }
  4666. bool ImGui::InputFloat3(const char* label, float v[3], int decimal_precision)
  4667. {
  4668. return InputFloatN(label, v, 3, decimal_precision);
  4669. }
  4670. bool ImGui::InputFloat4(const char* label, float v[4], int decimal_precision)
  4671. {
  4672. return InputFloatN(label, v, 4, decimal_precision);
  4673. }
  4674. static bool Combo_ArrayGetter(void* data, int idx, const char** out_text)
  4675. {
  4676. const char** items = (const char**)data;
  4677. if (out_text)
  4678. *out_text = items[idx];
  4679. return true;
  4680. }
  4681. // Combo box helper allowing to pass an array of strings.
  4682. bool ImGui::Combo(const char* label, int* current_item, const char** items, int items_count, int popup_height_items)
  4683. {
  4684. const bool value_changed = Combo(label, current_item, Combo_ArrayGetter, (void*)items, items_count, popup_height_items);
  4685. return value_changed;
  4686. }
  4687. static bool Combo_StringListGetter(void* data, int idx, const char** out_text)
  4688. {
  4689. // FIXME-OPT: we could precompute the indices to fasten this. But only 1 active combo means the waste is limited.
  4690. const char* items_separated_by_zeros = (const char*)data;
  4691. int items_count = 0;
  4692. const char* p = items_separated_by_zeros;
  4693. while (*p)
  4694. {
  4695. if (idx == items_count)
  4696. break;
  4697. p += strlen(p) + 1;
  4698. items_count++;
  4699. }
  4700. if (!*p)
  4701. return false;
  4702. if (out_text)
  4703. *out_text = p;
  4704. return true;
  4705. }
  4706. // Combo box helper allowing to pass all items in a single string.
  4707. bool ImGui::Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_height_items)
  4708. {
  4709. int items_count = 0;
  4710. const char* p = items_separated_by_zeros;
  4711. while (*p)
  4712. {
  4713. p += strlen(p) + 1;
  4714. items_count++;
  4715. }
  4716. bool value_changed = Combo(label, current_item, Combo_StringListGetter, (void*)items_separated_by_zeros, items_count, popup_height_items);
  4717. return value_changed;
  4718. }
  4719. // Combo box function.
  4720. bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int popup_height_items)
  4721. {
  4722. ImGuiState& g = GImGui;
  4723. ImGuiWindow* window = GetCurrentWindow();
  4724. if (window->SkipItems)
  4725. return false;
  4726. const ImGuiStyle& style = g.Style;
  4727. const ImGuiID id = window->GetID(label);
  4728. const float w = window->DC.ItemWidth.back();
  4729. const ImVec2 text_size = CalcTextSize(label, NULL, true);
  4730. const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f);
  4731. ItemSize(frame_bb);
  4732. if (!ItemAdd(frame_bb, &id))
  4733. return false;
  4734. const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x,0));
  4735. const float arrow_size = (window->FontSize() + style.FramePadding.x * 2.0f);
  4736. const bool hovered = IsHovered(frame_bb, id);
  4737. bool value_changed = false;
  4738. RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding);
  4739. RenderFrame(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y), frame_bb.Max, window->Color(hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button), true, style.FrameRounding); // FIXME-ROUNDING
  4740. RenderCollapseTriangle(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y) + style.FramePadding, true);
  4741. if (*current_item >= 0 && *current_item < items_count)
  4742. {
  4743. const char* item_text;
  4744. if (items_getter(data, *current_item, &item_text))
  4745. RenderText(frame_bb.Min + style.FramePadding, item_text, NULL, false);
  4746. }
  4747. // Empty text doesn't add padding
  4748. if (text_size.x > 0)
  4749. {
  4750. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4751. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  4752. }
  4753. ImGui::PushID((int)id);
  4754. bool menu_toggled = false;
  4755. if (hovered)
  4756. {
  4757. g.HoveredId = id;
  4758. if (g.IO.MouseClicked[0])
  4759. {
  4760. menu_toggled = true;
  4761. g.ActiveComboID = (g.ActiveComboID == id) ? 0 : id;
  4762. if (g.ActiveComboID)
  4763. FocusWindow(window);
  4764. }
  4765. }
  4766. if (g.ActiveComboID == id)
  4767. {
  4768. const ImVec2 backup_pos = ImGui::GetCursorPos();
  4769. const float popup_off_x = 0.0f;//style.ItemInnerSpacing.x;
  4770. const float popup_height = (text_size.y + style.ItemSpacing.y) * ImMin(items_count, popup_height_items) + style.WindowPadding.y;
  4771. 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));
  4772. ImGui::SetCursorPos(popup_aabb.Min - window->Pos);
  4773. const ImGuiWindowFlags flags = ImGuiWindowFlags_ComboBox | ((window->Flags & ImGuiWindowFlags_ShowBorders) ? ImGuiWindowFlags_ShowBorders : 0);
  4774. ImGui::BeginChild("#ComboBox", popup_aabb.GetSize(), false, flags);
  4775. ImGuiWindow* child_window = GetCurrentWindow();
  4776. ImGui::Spacing();
  4777. bool combo_item_active = false;
  4778. combo_item_active |= (g.ActiveId == child_window->GetID("#SCROLLY"));
  4779. // Display items
  4780. for (int item_idx = 0; item_idx < items_count; item_idx++)
  4781. {
  4782. const float item_h = child_window->FontSize();
  4783. const float spacing_up = (float)(int)(style.ItemSpacing.y/2);
  4784. const float spacing_dn = style.ItemSpacing.y - spacing_up;
  4785. 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));
  4786. const ImGuiID item_id = child_window->GetID((void*)(intptr_t)item_idx);
  4787. bool item_hovered, item_held;
  4788. bool item_pressed = ButtonBehaviour(item_aabb, item_id, &item_hovered, &item_held, true);
  4789. bool item_selected = (item_idx == *current_item);
  4790. if (item_hovered || item_selected)
  4791. {
  4792. const ImU32 col = window->Color((item_held && item_hovered) ? ImGuiCol_HeaderActive : item_hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
  4793. RenderFrame(item_aabb.Min, item_aabb.Max, col, false);
  4794. }
  4795. const char* item_text;
  4796. if (!items_getter(data, item_idx, &item_text))
  4797. item_text = "*Unknown item*";
  4798. ImGui::TextUnformatted(item_text);
  4799. if (item_selected)
  4800. {
  4801. if (menu_toggled)
  4802. ImGui::SetScrollPosHere();
  4803. }
  4804. if (item_pressed)
  4805. {
  4806. SetActiveId(0);
  4807. g.ActiveComboID = 0;
  4808. value_changed = true;
  4809. *current_item = item_idx;
  4810. }
  4811. combo_item_active |= (g.ActiveId == item_id);
  4812. }
  4813. ImGui::EndChild();
  4814. ImGui::SetCursorPos(backup_pos);
  4815. if (!combo_item_active && g.ActiveId != 0)
  4816. g.ActiveComboID = 0;
  4817. }
  4818. ImGui::PopID();
  4819. return value_changed;
  4820. }
  4821. // A little colored square. Return true when clicked.
  4822. bool ImGui::ColorButton(const ImVec4& col, bool small_height, bool outline_border)
  4823. {
  4824. ImGuiState& g = GImGui;
  4825. ImGuiWindow* window = GetCurrentWindow();
  4826. if (window->SkipItems)
  4827. return false;
  4828. const ImGuiStyle& style = g.Style;
  4829. const ImGuiID id = window->GetID("##colorbutton");
  4830. const float square_size = window->FontSize();
  4831. 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)));
  4832. ItemSize(bb);
  4833. if (!ItemAdd(bb, &id))
  4834. return false;
  4835. bool hovered, held;
  4836. bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true);
  4837. RenderFrame(bb.Min, bb.Max, window->Color(col), outline_border, style.FrameRounding);
  4838. if (hovered)
  4839. {
  4840. int ix = (int)(col.x * 255.0f + 0.5f);
  4841. int iy = (int)(col.y * 255.0f + 0.5f);
  4842. int iz = (int)(col.z * 255.0f + 0.5f);
  4843. int iw = (int)(col.w * 255.0f + 0.5f);
  4844. 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);
  4845. }
  4846. return pressed;
  4847. }
  4848. bool ImGui::ColorEdit3(const char* label, float col[3])
  4849. {
  4850. float col4[4];
  4851. col4[0] = col[0];
  4852. col4[1] = col[1];
  4853. col4[2] = col[2];
  4854. col4[3] = 1.0f;
  4855. const bool value_changed = ImGui::ColorEdit4(label, col4, false);
  4856. col[0] = col4[0];
  4857. col[1] = col4[1];
  4858. col[2] = col4[2];
  4859. return value_changed;
  4860. }
  4861. // Edit colors components (each component in 0.0f..1.0f range
  4862. // Use CTRL-Click to input value and TAB to go to next item.
  4863. bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha)
  4864. {
  4865. ImGuiState& g = GImGui;
  4866. ImGuiWindow* window = GetCurrentWindow();
  4867. if (window->SkipItems)
  4868. return false;
  4869. const ImGuiStyle& style = g.Style;
  4870. const ImGuiID id = window->GetID(label);
  4871. const float w_full = window->DC.ItemWidth.back();
  4872. const float square_sz = (window->FontSize() + style.FramePadding.x * 2.0f);
  4873. ImGuiColorEditMode edit_mode = window->DC.ColorEditMode;
  4874. if (edit_mode == ImGuiColorEditMode_UserSelect || edit_mode == ImGuiColorEditMode_UserSelectShowButton)
  4875. edit_mode = g.ColorEditModeStorage.GetInt(id, 0) % 3;
  4876. float fx = col[0];
  4877. float fy = col[1];
  4878. float fz = col[2];
  4879. float fw = col[3];
  4880. const ImVec4 col_display(fx, fy, fz, 1.0f);
  4881. if (edit_mode == ImGuiColorEditMode_HSV)
  4882. ImGui::ColorConvertRGBtoHSV(fx, fy, fz, fx, fy, fz);
  4883. int ix = (int)(fx * 255.0f + 0.5f);
  4884. int iy = (int)(fy * 255.0f + 0.5f);
  4885. int iz = (int)(fz * 255.0f + 0.5f);
  4886. int iw = (int)(fw * 255.0f + 0.5f);
  4887. int components = alpha ? 4 : 3;
  4888. bool value_changed = false;
  4889. ImGui::PushID(label);
  4890. bool hsv = (edit_mode == 1);
  4891. switch (edit_mode)
  4892. {
  4893. case ImGuiColorEditMode_RGB:
  4894. case ImGuiColorEditMode_HSV:
  4895. {
  4896. // 0: RGB 0..255 Sliders
  4897. // 1: HSV 0..255 Sliders
  4898. const float w_items_all = w_full - (square_sz + style.ItemInnerSpacing.x);
  4899. 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));
  4900. 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)));
  4901. ImGui::PushItemWidth(w_item_one);
  4902. value_changed |= ImGui::SliderInt("##X", &ix, 0, 255, hsv ? "H:%3.0f" : "R:%3.0f");
  4903. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4904. value_changed |= ImGui::SliderInt("##Y", &iy, 0, 255, hsv ? "S:%3.0f" : "G:%3.0f");
  4905. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4906. if (alpha)
  4907. {
  4908. value_changed |= ImGui::SliderInt("##Z", &iz, 0, 255, hsv ? "V:%3.0f" : "B:%3.0f");
  4909. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4910. ImGui::PushItemWidth(w_item_last);
  4911. value_changed |= ImGui::SliderInt("##W", &iw, 0, 255, "A:%3.0f");
  4912. }
  4913. else
  4914. {
  4915. ImGui::PushItemWidth(w_item_last);
  4916. value_changed |= ImGui::SliderInt("##Z", &iz, 0, 255, hsv ? "V:%3.0f" : "B:%3.0f");
  4917. }
  4918. ImGui::PopItemWidth();
  4919. ImGui::PopItemWidth();
  4920. }
  4921. break;
  4922. case ImGuiColorEditMode_HEX:
  4923. {
  4924. // 2: RGB Hexadecimal
  4925. const float w_slider_all = w_full - square_sz;
  4926. char buf[64];
  4927. if (alpha)
  4928. sprintf(buf, "#%02X%02X%02X%02X", ix, iy, iz, iw);
  4929. else
  4930. sprintf(buf, "#%02X%02X%02X", ix, iy, iz);
  4931. ImGui::PushItemWidth(w_slider_all - style.ItemInnerSpacing.x);
  4932. value_changed |= ImGui::InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal);
  4933. ImGui::PopItemWidth();
  4934. char* p = buf;
  4935. while (*p == '#' || *p == ' ' || *p == '\t')
  4936. p++;
  4937. // Treat at unsigned (%X is unsigned)
  4938. ix = iy = iz = iw = 0;
  4939. if (alpha)
  4940. sscanf(p, "%02X%02X%02X%02X", (unsigned int*)&ix, (unsigned int*)&iy, (unsigned int*)&iz, (unsigned int*)&iw);
  4941. else
  4942. sscanf(p, "%02X%02X%02X", (unsigned int*)&ix, (unsigned int*)&iy, (unsigned int*)&iz);
  4943. }
  4944. break;
  4945. }
  4946. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4947. if (ImGui::ColorButton(col_display))
  4948. {
  4949. // Don't set local copy of 'edit_mode' right away!
  4950. g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3);
  4951. }
  4952. if (window->DC.ColorEditMode == ImGuiColorEditMode_UserSelectShowButton)
  4953. {
  4954. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4955. const char* button_titles[3] = { "RGB", "HSV", "HEX" };
  4956. if (ImGui::Button(button_titles[edit_mode]))
  4957. {
  4958. // Don't set local copy of 'edit_mode' right away!
  4959. g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3);
  4960. }
  4961. ImGui::SameLine();
  4962. }
  4963. else
  4964. {
  4965. ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
  4966. }
  4967. ImGui::TextUnformatted(label, FindTextDisplayEnd(label));
  4968. // Convert back
  4969. fx = ix / 255.0f;
  4970. fy = iy / 255.0f;
  4971. fz = iz / 255.0f;
  4972. fw = iw / 255.0f;
  4973. if (edit_mode == 1)
  4974. ImGui::ColorConvertHSVtoRGB(fx, fy, fz, fx, fy, fz);
  4975. if (value_changed)
  4976. {
  4977. col[0] = fx;
  4978. col[1] = fy;
  4979. col[2] = fz;
  4980. if (alpha)
  4981. col[3] = fw;
  4982. }
  4983. ImGui::PopID();
  4984. return value_changed;
  4985. }
  4986. void ImGui::ColorEditMode(ImGuiColorEditMode mode)
  4987. {
  4988. ImGuiWindow* window = GetCurrentWindow();
  4989. window->DC.ColorEditMode = mode;
  4990. }
  4991. // Horizontal separating line.
  4992. void ImGui::Separator()
  4993. {
  4994. ImGuiWindow* window = GetCurrentWindow();
  4995. if (window->SkipItems)
  4996. return;
  4997. if (window->DC.ColumnsCount > 1)
  4998. PopClipRect();
  4999. const ImGuiAabb bb(ImVec2(window->Pos.x, window->DC.CursorPos.y), ImVec2(window->Pos.x + window->Size.x, window->DC.CursorPos.y));
  5000. ItemSize(ImVec2(0.0f, bb.GetSize().y)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit
  5001. if (!ItemAdd(bb, NULL))
  5002. {
  5003. if (window->DC.ColumnsCount > 1)
  5004. PushColumnClipRect();
  5005. return;
  5006. }
  5007. window->DrawList->AddLine(bb.Min, bb.Max, window->Color(ImGuiCol_Border));
  5008. if (window->DC.ColumnsCount > 1)
  5009. PushColumnClipRect();
  5010. }
  5011. // A little vertical spacing.
  5012. void ImGui::Spacing()
  5013. {
  5014. ImGuiWindow* window = GetCurrentWindow();
  5015. if (window->SkipItems)
  5016. return;
  5017. ItemSize(ImVec2(0,0));
  5018. }
  5019. // Advance cursor given item size.
  5020. static void ItemSize(ImVec2 size, ImVec2* adjust_vertical_offset)
  5021. {
  5022. ImGuiState& g = GImGui;
  5023. ImGuiWindow* window = GetCurrentWindow();
  5024. if (window->SkipItems)
  5025. return;
  5026. const float line_height = ImMax(window->DC.CurrentLineHeight, size.y);
  5027. if (adjust_vertical_offset)
  5028. adjust_vertical_offset->y = adjust_vertical_offset->y + (line_height - size.y) * 0.5f;
  5029. // Always align ourselves on pixel boundaries
  5030. window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y);
  5031. window->DC.CursorPos = ImVec2((float)(int)(window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX), (float)(int)(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y));
  5032. window->SizeContentsFit = ImMax(window->SizeContentsFit, ImVec2(window->DC.CursorPosPrevLine.x, window->DC.CursorPos.y) - window->Pos + ImVec2(0.0f, window->ScrollY));
  5033. window->DC.PrevLineHeight = line_height;
  5034. window->DC.CurrentLineHeight = 0.0f;
  5035. }
  5036. static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset)
  5037. {
  5038. ItemSize(aabb.GetSize(), adjust_start_offset);
  5039. }
  5040. static bool IsClipped(const ImGuiAabb& bb)
  5041. {
  5042. ImGuiState& g = GImGui;
  5043. ImGuiWindow* window = GetCurrentWindow();
  5044. if (!bb.Overlaps(ImGuiAabb(window->ClipRectStack.back())) && !g.LogEnabled)
  5045. return true;
  5046. return false;
  5047. }
  5048. bool ImGui::IsClipped(const ImVec2& item_size)
  5049. {
  5050. ImGuiWindow* window = GetCurrentWindow();
  5051. return IsClipped(ImGuiAabb(window->DC.CursorPos, window->DC.CursorPos + item_size));
  5052. }
  5053. static bool ItemAdd(const ImGuiAabb& bb, const ImGuiID* id)
  5054. {
  5055. ImGuiWindow* window = GetCurrentWindow();
  5056. window->DC.LastItemID = id ? *id : 0;
  5057. window->DC.LastItemAabb = bb;
  5058. if (IsClipped(bb))
  5059. {
  5060. window->DC.LastItemHovered = false;
  5061. return false;
  5062. }
  5063. window->DC.LastItemHovered = IsMouseHoveringBox(bb); // this is a sensible default but widgets are free to override it after calling ItemAdd()
  5064. return true;
  5065. }
  5066. // Gets back to previous line and continue with horizontal layout
  5067. // column_x == 0 : follow on previous item
  5068. // columm_x != 0 : align to specified column
  5069. // spacing_w < 0 : use default spacing if column_x==0, no spacing if column_x!=0
  5070. // spacing_w >= 0 : enforce spacing
  5071. void ImGui::SameLine(int column_x, int spacing_w)
  5072. {
  5073. ImGuiState& g = GImGui;
  5074. ImGuiWindow* window = GetCurrentWindow();
  5075. if (window->SkipItems)
  5076. return;
  5077. float x, y;
  5078. if (column_x != 0)
  5079. {
  5080. if (spacing_w < 0) spacing_w = 0;
  5081. x = window->Pos.x + (float)column_x + (float)spacing_w;
  5082. y = window->DC.CursorPosPrevLine.y;
  5083. }
  5084. else
  5085. {
  5086. if (spacing_w < 0) spacing_w = (int)g.Style.ItemSpacing.x;
  5087. x = window->DC.CursorPosPrevLine.x + (float)spacing_w;
  5088. y = window->DC.CursorPosPrevLine.y;
  5089. }
  5090. window->DC.CurrentLineHeight = window->DC.PrevLineHeight;
  5091. window->DC.CursorPos = ImVec2(x, y);
  5092. }
  5093. void ImGui::NextColumn()
  5094. {
  5095. ImGuiState& g = GImGui;
  5096. ImGuiWindow* window = GetCurrentWindow();
  5097. if (window->SkipItems)
  5098. return;
  5099. if (window->DC.ColumnsCount > 1)
  5100. {
  5101. ImGui::PopItemWidth();
  5102. PopClipRect();
  5103. window->DC.ColumnsCellMaxY = ImMax(window->DC.ColumnsCellMaxY, window->DC.CursorPos.y);
  5104. if (++window->DC.ColumnsCurrent < window->DC.ColumnsCount)
  5105. {
  5106. window->DC.ColumnsOffsetX = ImGui::GetColumnOffset(window->DC.ColumnsCurrent) - window->DC.ColumnsStartX + g.Style.ItemSpacing.x;
  5107. }
  5108. else
  5109. {
  5110. window->DC.ColumnsCurrent = 0;
  5111. window->DC.ColumnsOffsetX = 0.0f;
  5112. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY;
  5113. }
  5114. window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX);
  5115. window->DC.CursorPos.y = window->DC.ColumnsCellMinY;
  5116. window->DC.CurrentLineHeight = 0.0f;
  5117. PushColumnClipRect();
  5118. ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f);
  5119. }
  5120. }
  5121. float ImGui::GetColumnOffset(int column_index)
  5122. {
  5123. ImGuiState& g = GImGui;
  5124. ImGuiWindow* window = GetCurrentWindow();
  5125. if (column_index < 0)
  5126. column_index = window->DC.ColumnsCurrent;
  5127. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
  5128. RegisterAliveId(column_id);
  5129. const float default_t = column_index / (float)window->DC.ColumnsCount;
  5130. const float t = window->StateStorage.GetFloat(column_id, default_t); // Cheaply store our floating point value inside the integer (could store an union into the map?)
  5131. const float offset = window->DC.ColumnsStartX + t * (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnsStartX);
  5132. return offset;
  5133. }
  5134. void ImGui::SetColumnOffset(int column_index, float offset)
  5135. {
  5136. ImGuiState& g = GImGui;
  5137. ImGuiWindow* window = GetCurrentWindow();
  5138. if (column_index < 0)
  5139. column_index = window->DC.ColumnsCurrent;
  5140. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index);
  5141. const float t = (offset - window->DC.ColumnsStartX) / (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnsStartX);
  5142. window->StateStorage.SetFloat(column_id, t);
  5143. }
  5144. float ImGui::GetColumnWidth(int column_index)
  5145. {
  5146. ImGuiWindow* window = GetCurrentWindow();
  5147. if (column_index < 0)
  5148. column_index = window->DC.ColumnsCurrent;
  5149. const float w = GetColumnOffset(column_index+1) - GetColumnOffset(column_index);
  5150. return w;
  5151. }
  5152. static void PushColumnClipRect(int column_index)
  5153. {
  5154. ImGuiWindow* window = GetCurrentWindow();
  5155. if (column_index < 0)
  5156. column_index = window->DC.ColumnsCurrent;
  5157. const float x1 = window->Pos.x + ImGui::GetColumnOffset(column_index) - 1;
  5158. const float x2 = window->Pos.x + ImGui::GetColumnOffset(column_index+1) - 1;
  5159. PushClipRect(ImVec4(x1,-FLT_MAX,x2,+FLT_MAX));
  5160. }
  5161. void ImGui::Columns(int columns_count, const char* id, bool border)
  5162. {
  5163. ImGuiState& g = GImGui;
  5164. ImGuiWindow* window = GetCurrentWindow();
  5165. if (window->SkipItems)
  5166. return;
  5167. if (window->DC.ColumnsCount != 1)
  5168. {
  5169. if (window->DC.ColumnsCurrent != 0)
  5170. ItemSize(ImVec2(0,0)); // Advance to column 0
  5171. ImGui::PopItemWidth();
  5172. PopClipRect();
  5173. window->DC.ColumnsCellMaxY = ImMax(window->DC.ColumnsCellMaxY, window->DC.CursorPos.y);
  5174. window->DC.CursorPos.y = window->DC.ColumnsCellMaxY;
  5175. }
  5176. // Draw columns borders and handle resize at the time of "closing" a columns set
  5177. if (window->DC.ColumnsCount != columns_count && window->DC.ColumnsCount != 1 && window->DC.ColumnsShowBorders)
  5178. {
  5179. const float y1 = window->DC.ColumnsStartPos.y;
  5180. const float y2 = window->DC.CursorPos.y;
  5181. for (int i = 1; i < window->DC.ColumnsCount; i++)
  5182. {
  5183. float x = window->Pos.x + GetColumnOffset(i);
  5184. const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(i);
  5185. const ImGuiAabb column_aabb(ImVec2(x-4,y1),ImVec2(x+4,y2));
  5186. if (IsClipped(column_aabb))
  5187. continue;
  5188. bool hovered, held;
  5189. ButtonBehaviour(column_aabb, column_id, &hovered, &held, true);
  5190. // Draw before resize so our items positioning are in sync with the line being drawn
  5191. const ImU32 col = window->Color(held ? ImGuiCol_ColumnActive : hovered ? ImGuiCol_ColumnHovered : ImGuiCol_Column);
  5192. const float xi = (float)(int)x;
  5193. window->DrawList->AddLine(ImVec2(xi, y1), ImVec2(xi, y2), col);
  5194. if (held)
  5195. {
  5196. x -= window->Pos.x;
  5197. x = ImClamp(x + g.IO.MouseDelta.x, ImGui::GetColumnOffset(i-1)+g.Style.ColumnsMinSpacing, ImGui::GetColumnOffset(i+1)-g.Style.ColumnsMinSpacing);
  5198. SetColumnOffset(i, x);
  5199. x += window->Pos.x;
  5200. }
  5201. }
  5202. }
  5203. // Set state for first column
  5204. window->DC.ColumnsSetID = window->GetID(id ? id : "");
  5205. window->DC.ColumnsCurrent = 0;
  5206. window->DC.ColumnsCount = columns_count;
  5207. window->DC.ColumnsShowBorders = border;
  5208. window->DC.ColumnsStartPos = window->DC.CursorPos;
  5209. window->DC.ColumnsCellMinY = window->DC.ColumnsCellMaxY = window->DC.CursorPos.y;
  5210. window->DC.ColumnsOffsetX = 0.0f;
  5211. window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX);
  5212. if (window->DC.ColumnsCount != 1)
  5213. {
  5214. PushColumnClipRect();
  5215. ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f);
  5216. }
  5217. }
  5218. void ImGui::TreePush(const char* str_id)
  5219. {
  5220. ImGuiState& g = GImGui;
  5221. ImGuiWindow* window = GetCurrentWindow();
  5222. window->DC.ColumnsStartX += g.Style.TreeNodeSpacing;
  5223. window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX;
  5224. window->DC.TreeDepth++;
  5225. PushID(str_id ? str_id : "#TreePush");
  5226. }
  5227. void ImGui::TreePush(const void* ptr_id)
  5228. {
  5229. ImGuiState& g = GImGui;
  5230. ImGuiWindow* window = GetCurrentWindow();
  5231. window->DC.ColumnsStartX += g.Style.TreeNodeSpacing;
  5232. window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX;
  5233. window->DC.TreeDepth++;
  5234. PushID(ptr_id ? ptr_id : (const void*)"#TreePush");
  5235. }
  5236. void ImGui::TreePop()
  5237. {
  5238. ImGuiState& g = GImGui;
  5239. ImGuiWindow* window = GetCurrentWindow();
  5240. window->DC.ColumnsStartX -= g.Style.TreeNodeSpacing;
  5241. window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnsStartX + window->DC.ColumnsOffsetX;
  5242. window->DC.TreeDepth--;
  5243. PopID();
  5244. }
  5245. void ImGui::Value(const char* prefix, bool b)
  5246. {
  5247. ImGui::Text("%s: %s", prefix, (b ? "true" : "false"));
  5248. }
  5249. void ImGui::Value(const char* prefix, int v)
  5250. {
  5251. ImGui::Text("%s: %d", prefix, v);
  5252. }
  5253. void ImGui::Value(const char* prefix, unsigned int v)
  5254. {
  5255. ImGui::Text("%s: %d", prefix, v);
  5256. }
  5257. void ImGui::Value(const char* prefix, float v, const char* float_format)
  5258. {
  5259. if (float_format)
  5260. {
  5261. char fmt[64];
  5262. sprintf(fmt, "%%s: %s", float_format);
  5263. ImGui::Text(fmt, prefix, v);
  5264. }
  5265. else
  5266. {
  5267. ImGui::Text("%s: %.3f", prefix, v);
  5268. }
  5269. }
  5270. void ImGui::Color(const char* prefix, const ImVec4& v)
  5271. {
  5272. ImGui::Text("%s: (%.2f,%.2f,%.2f,%.2f)", prefix, v.x, v.y, v.z, v.w);
  5273. ImGui::SameLine();
  5274. ImGui::ColorButton(v, true);
  5275. }
  5276. void ImGui::Color(const char* prefix, unsigned int v)
  5277. {
  5278. ImGui::Text("%s: %08X", prefix, v);
  5279. ImGui::SameLine();
  5280. ImVec4 col;
  5281. col.x = (float)((v >> 0) & 0xFF) / 255.0f;
  5282. col.y = (float)((v >> 8) & 0xFF) / 255.0f;
  5283. col.z = (float)((v >> 16) & 0xFF) / 255.0f;
  5284. col.w = (float)((v >> 24) & 0xFF) / 255.0f;
  5285. ImGui::ColorButton(col, true);
  5286. }
  5287. //-----------------------------------------------------------------------------
  5288. // ImDrawList
  5289. //-----------------------------------------------------------------------------
  5290. static ImVec4 GNullClipRect(-9999.0f,-9999.0f, +9999.0f, +9999.0f);
  5291. void ImDrawList::Clear()
  5292. {
  5293. commands.resize(0);
  5294. vtx_buffer.resize(0);
  5295. vtx_write = NULL;
  5296. clip_rect_stack.resize(0);
  5297. texture_id_stack.resize(0);
  5298. }
  5299. void ImDrawList::AddDrawCmd()
  5300. {
  5301. ImDrawCmd draw_cmd;
  5302. draw_cmd.vtx_count = 0;
  5303. draw_cmd.clip_rect = clip_rect_stack.empty() ? GNullClipRect : clip_rect_stack.back();
  5304. draw_cmd.texture_id = texture_id_stack.empty() ? NULL : texture_id_stack.back();
  5305. draw_cmd.user_callback = NULL;
  5306. draw_cmd.user_callback_data = NULL;
  5307. commands.push_back(draw_cmd);
  5308. }
  5309. void ImDrawList::AddCallback(ImDrawCallback callback, void* callback_data)
  5310. {
  5311. ImDrawCmd* current_cmd = commands.empty() ? NULL : &commands.back();
  5312. if (!current_cmd || current_cmd->vtx_count != 0 || current_cmd->user_callback != NULL)
  5313. {
  5314. AddDrawCmd();
  5315. current_cmd = &commands.back();
  5316. }
  5317. current_cmd->user_callback = callback;
  5318. current_cmd->user_callback_data = callback_data;
  5319. // Force a new command after us
  5320. // We function this way so that the most common calls (AddLine, AddRect..) always have a command to add to without doing any check.
  5321. AddDrawCmd();
  5322. }
  5323. void ImDrawList::UpdateClipRect()
  5324. {
  5325. ImDrawCmd* current_cmd = commands.empty() ? NULL : &commands.back();
  5326. if (!current_cmd || (current_cmd->vtx_count != 0) || current_cmd->user_callback != NULL)
  5327. {
  5328. AddDrawCmd();
  5329. }
  5330. else
  5331. {
  5332. current_cmd->clip_rect = clip_rect_stack.empty() ? GNullClipRect : clip_rect_stack.back();
  5333. }
  5334. }
  5335. // Scissoring. The values in clip_rect are x1, y1, x2, y2.
  5336. void ImDrawList::PushClipRect(const ImVec4& clip_rect)
  5337. {
  5338. clip_rect_stack.push_back(clip_rect);
  5339. UpdateClipRect();
  5340. }
  5341. void ImDrawList::PopClipRect()
  5342. {
  5343. IM_ASSERT(clip_rect_stack.size() > 0);
  5344. clip_rect_stack.pop_back();
  5345. UpdateClipRect();
  5346. }
  5347. void ImDrawList::UpdateTextureID()
  5348. {
  5349. ImDrawCmd* current_cmd = commands.empty() ? NULL : &commands.back();
  5350. const ImTextureID texture_id = texture_id_stack.empty() ? NULL : texture_id_stack.back();
  5351. if (!current_cmd || (current_cmd->vtx_count != 0 && current_cmd->texture_id != texture_id) || current_cmd->user_callback != NULL)
  5352. {
  5353. AddDrawCmd();
  5354. }
  5355. else
  5356. {
  5357. current_cmd->texture_id = texture_id;
  5358. }
  5359. }
  5360. void ImDrawList::PushTextureID(const ImTextureID& texture_id)
  5361. {
  5362. texture_id_stack.push_back(texture_id);
  5363. UpdateTextureID();
  5364. }
  5365. void ImDrawList::PopTextureID()
  5366. {
  5367. IM_ASSERT(texture_id_stack.size() > 0);
  5368. texture_id_stack.pop_back();
  5369. UpdateTextureID();
  5370. }
  5371. void ImDrawList::ReserveVertices(unsigned int vtx_count)
  5372. {
  5373. if (vtx_count > 0)
  5374. {
  5375. ImDrawCmd& draw_cmd = commands.back();
  5376. draw_cmd.vtx_count += vtx_count;
  5377. vtx_buffer.resize(vtx_buffer.size() + vtx_count);
  5378. vtx_write = &vtx_buffer[vtx_buffer.size() - vtx_count];
  5379. }
  5380. }
  5381. void ImDrawList::AddVtx(const ImVec2& pos, ImU32 col)
  5382. {
  5383. vtx_write->pos = pos;
  5384. vtx_write->col = col;
  5385. vtx_write->uv = GImGui.FontTexUvWhitePixel;
  5386. vtx_write++;
  5387. }
  5388. void ImDrawList::AddVtxUV(const ImVec2& pos, ImU32 col, const ImVec2& uv)
  5389. {
  5390. vtx_write->pos = pos;
  5391. vtx_write->col = col;
  5392. vtx_write->uv = uv;
  5393. vtx_write++;
  5394. }
  5395. // NB: memory should be reserved for 6 vertices by the caller.
  5396. void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col)
  5397. {
  5398. const float length = sqrtf(ImLengthSqr(b - a));
  5399. const ImVec2 hn = (b - a) * (0.50f / length); // half normal
  5400. const ImVec2 hp0 = ImVec2(+hn.y, -hn.x); // half perpendiculars + user offset
  5401. const ImVec2 hp1 = ImVec2(-hn.y, +hn.x);
  5402. // Two triangles makes up one line. Using triangles allows us to reduce amount of draw calls.
  5403. AddVtx(a + hp0, col);
  5404. AddVtx(b + hp0, col);
  5405. AddVtx(a + hp1, col);
  5406. AddVtx(b + hp0, col);
  5407. AddVtx(b + hp1, col);
  5408. AddVtx(a + hp1, col);
  5409. }
  5410. void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col)
  5411. {
  5412. if ((col >> 24) == 0)
  5413. return;
  5414. ReserveVertices(6);
  5415. AddVtxLine(a, b, col);
  5416. }
  5417. void ImDrawList::AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris, const ImVec2& third_point_offset)
  5418. {
  5419. if ((col >> 24) == 0)
  5420. return;
  5421. static ImVec2 circle_vtx[12];
  5422. static bool circle_vtx_builds = false;
  5423. if (!circle_vtx_builds)
  5424. {
  5425. for (int i = 0; i < IM_ARRAYSIZE(circle_vtx); i++)
  5426. {
  5427. const float a = ((float)i / (float)IM_ARRAYSIZE(circle_vtx)) * 2*PI;
  5428. circle_vtx[i].x = cosf(a + PI);
  5429. circle_vtx[i].y = sinf(a + PI);
  5430. }
  5431. circle_vtx_builds = true;
  5432. }
  5433. if (tris)
  5434. {
  5435. ReserveVertices((unsigned int)(a_max-a_min) * 3);
  5436. for (int a = a_min; a < a_max; a++)
  5437. {
  5438. AddVtx(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, col);
  5439. AddVtx(center + circle_vtx[(a+1) % IM_ARRAYSIZE(circle_vtx)] * rad, col);
  5440. AddVtx(center + third_point_offset, col);
  5441. }
  5442. }
  5443. else
  5444. {
  5445. ReserveVertices((unsigned int)(a_max-a_min) * 6);
  5446. for (int a = a_min; a < a_max; a++)
  5447. AddVtxLine(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, center + circle_vtx[(a+1) % IM_ARRAYSIZE(circle_vtx)] * rad, col);
  5448. }
  5449. }
  5450. void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners)
  5451. {
  5452. if ((col >> 24) == 0)
  5453. return;
  5454. float r = rounding;
  5455. r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f ));
  5456. r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f ));
  5457. if (r == 0.0f || rounding_corners == 0)
  5458. {
  5459. ReserveVertices(4*6);
  5460. AddVtxLine(ImVec2(a.x,a.y), ImVec2(b.x,a.y), col);
  5461. AddVtxLine(ImVec2(b.x,a.y), ImVec2(b.x,b.y), col);
  5462. AddVtxLine(ImVec2(b.x,b.y), ImVec2(a.x,b.y), col);
  5463. AddVtxLine(ImVec2(a.x,b.y), ImVec2(a.x,a.y), col);
  5464. }
  5465. else
  5466. {
  5467. ReserveVertices(4*6);
  5468. AddVtxLine(ImVec2(a.x + ((rounding_corners & 1)?r:0), a.y), ImVec2(b.x - ((rounding_corners & 2)?r:0), a.y), col);
  5469. AddVtxLine(ImVec2(b.x, a.y + ((rounding_corners & 2)?r:0)), ImVec2(b.x, b.y - ((rounding_corners & 4)?r:0)), col);
  5470. AddVtxLine(ImVec2(b.x - ((rounding_corners & 4)?r:0), b.y), ImVec2(a.x + ((rounding_corners & 8)?r:0), b.y), col);
  5471. AddVtxLine(ImVec2(a.x, b.y - ((rounding_corners & 8)?r:0)), ImVec2(a.x, a.y + ((rounding_corners & 1)?r:0)), col);
  5472. if (rounding_corners & 1) AddArc(ImVec2(a.x+r,a.y+r), r, col, 0, 3);
  5473. if (rounding_corners & 2) AddArc(ImVec2(b.x-r,a.y+r), r, col, 3, 6);
  5474. if (rounding_corners & 4) AddArc(ImVec2(b.x-r,b.y-r), r, col, 6, 9);
  5475. if (rounding_corners & 8) AddArc(ImVec2(a.x+r,b.y-r), r, col, 9, 12);
  5476. }
  5477. }
  5478. void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners)
  5479. {
  5480. if ((col >> 24) == 0)
  5481. return;
  5482. float r = rounding;
  5483. r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f ));
  5484. r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f ));
  5485. if (r == 0.0f || rounding_corners == 0)
  5486. {
  5487. // Use triangle so we can merge more draw calls together (at the cost of extra vertices)
  5488. ReserveVertices(6);
  5489. AddVtx(ImVec2(a.x,a.y), col);
  5490. AddVtx(ImVec2(b.x,a.y), col);
  5491. AddVtx(ImVec2(b.x,b.y), col);
  5492. AddVtx(ImVec2(a.x,a.y), col);
  5493. AddVtx(ImVec2(b.x,b.y), col);
  5494. AddVtx(ImVec2(a.x,b.y), col);
  5495. }
  5496. else
  5497. {
  5498. ReserveVertices(6+6*2);
  5499. AddVtx(ImVec2(a.x+r,a.y), col);
  5500. AddVtx(ImVec2(b.x-r,a.y), col);
  5501. AddVtx(ImVec2(b.x-r,b.y), col);
  5502. AddVtx(ImVec2(a.x+r,a.y), col);
  5503. AddVtx(ImVec2(b.x-r,b.y), col);
  5504. AddVtx(ImVec2(a.x+r,b.y), col);
  5505. float top_y = (rounding_corners & 1) ? a.y+r : a.y;
  5506. float bot_y = (rounding_corners & 8) ? b.y-r : b.y;
  5507. AddVtx(ImVec2(a.x,top_y), col);
  5508. AddVtx(ImVec2(a.x+r,top_y), col);
  5509. AddVtx(ImVec2(a.x+r,bot_y), col);
  5510. AddVtx(ImVec2(a.x,top_y), col);
  5511. AddVtx(ImVec2(a.x+r,bot_y), col);
  5512. AddVtx(ImVec2(a.x,bot_y), col);
  5513. top_y = (rounding_corners & 2) ? a.y+r : a.y;
  5514. bot_y = (rounding_corners & 4) ? b.y-r : b.y;
  5515. AddVtx(ImVec2(b.x-r,top_y), col);
  5516. AddVtx(ImVec2(b.x,top_y), col);
  5517. AddVtx(ImVec2(b.x,bot_y), col);
  5518. AddVtx(ImVec2(b.x-r,top_y), col);
  5519. AddVtx(ImVec2(b.x,bot_y), col);
  5520. AddVtx(ImVec2(b.x-r,bot_y), col);
  5521. if (rounding_corners & 1) AddArc(ImVec2(a.x+r,a.y+r), r, col, 0, 3, true);
  5522. if (rounding_corners & 2) AddArc(ImVec2(b.x-r,a.y+r), r, col, 3, 6, true);
  5523. if (rounding_corners & 4) AddArc(ImVec2(b.x-r,b.y-r), r, col, 6, 9, true);
  5524. if (rounding_corners & 8) AddArc(ImVec2(a.x+r,b.y-r), r, col, 9, 12,true);
  5525. }
  5526. }
  5527. void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col)
  5528. {
  5529. if ((col >> 24) == 0)
  5530. return;
  5531. ReserveVertices(3);
  5532. AddVtx(a, col);
  5533. AddVtx(b, col);
  5534. AddVtx(c, col);
  5535. }
  5536. void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments)
  5537. {
  5538. if ((col >> 24) == 0)
  5539. return;
  5540. ReserveVertices((unsigned int)num_segments*6);
  5541. const float a_step = 2*PI/(float)num_segments;
  5542. float a0 = 0.0f;
  5543. for (int i = 0; i < num_segments; i++)
  5544. {
  5545. const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step;
  5546. AddVtxLine(centre + ImVec2(cosf(a0), sinf(a0))*radius, centre + ImVec2(cosf(a1), sinf(a1))*radius, col);
  5547. a0 = a1;
  5548. }
  5549. }
  5550. void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments)
  5551. {
  5552. if ((col >> 24) == 0)
  5553. return;
  5554. ReserveVertices((unsigned int)num_segments*3);
  5555. const float a_step = 2*PI/(float)num_segments;
  5556. float a0 = 0.0f;
  5557. for (int i = 0; i < num_segments; i++)
  5558. {
  5559. const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step;
  5560. AddVtx(centre + ImVec2(cosf(a0), sinf(a0))*radius, col);
  5561. AddVtx(centre + ImVec2(cosf(a1), sinf(a1))*radius, col);
  5562. AddVtx(centre, col);
  5563. a0 = a1;
  5564. }
  5565. }
  5566. void ImDrawList::AddText(ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end, float wrap_width)
  5567. {
  5568. if ((col >> 24) == 0)
  5569. return;
  5570. if (text_end == NULL)
  5571. text_end = text_begin + strlen(text_begin);
  5572. IM_ASSERT(font->ContainerAtlas->TexID == texture_id_stack.back()); // Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font.
  5573. // reserve vertices for worse case
  5574. const unsigned int char_count = (unsigned int)(text_end - text_begin);
  5575. const unsigned int vtx_count_max = char_count * 6;
  5576. const size_t vtx_begin = vtx_buffer.size();
  5577. ReserveVertices(vtx_count_max);
  5578. font->RenderText(font_size, pos, col, clip_rect_stack.back(), text_begin, text_end, vtx_write, wrap_width);
  5579. // give back unused vertices
  5580. vtx_buffer.resize((size_t)(vtx_write - &vtx_buffer.front()));
  5581. const size_t vtx_count = vtx_buffer.size() - vtx_begin;
  5582. commands.back().vtx_count -= (unsigned int)(vtx_count_max - vtx_count);
  5583. vtx_write -= (vtx_count_max - vtx_count);
  5584. }
  5585. void ImDrawList::AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col)
  5586. {
  5587. if ((col >> 24) == 0)
  5588. return;
  5589. const bool push_texture_id = texture_id_stack.empty() || user_texture_id != texture_id_stack.back();
  5590. if (push_texture_id)
  5591. PushTextureID(user_texture_id);
  5592. ReserveVertices(6);
  5593. AddVtxUV(ImVec2(a.x,a.y), col, uv0);
  5594. AddVtxUV(ImVec2(b.x,a.y), col, ImVec2(uv1.x,uv0.y));
  5595. AddVtxUV(ImVec2(b.x,b.y), col, uv1);
  5596. AddVtxUV(ImVec2(a.x,a.y), col, ImVec2(uv0.x,uv0.y));
  5597. AddVtxUV(ImVec2(b.x,b.y), col, uv1);
  5598. AddVtxUV(ImVec2(a.x,b.y), col, ImVec2(uv0.x,uv1.y));
  5599. if (push_texture_id)
  5600. PopTextureID();
  5601. }
  5602. //-----------------------------------------------------------------------------
  5603. // ImFontAtlias
  5604. //-----------------------------------------------------------------------------
  5605. struct ImFontAtlas::ImFontAtlasData
  5606. {
  5607. // Input
  5608. ImFont* OutFont; // Load into this font
  5609. void* TTFData; // TTF data, we own the memory
  5610. size_t TTFDataSize; // TTF data size, in bytes
  5611. float SizePixels; // Desired output size, in pixels
  5612. const ImWchar* GlyphRanges; // List of Unicode range (2 value per range, values are inclusive, zero-terminated list)
  5613. int FontNo; // Index of font within .TTF file (0)
  5614. // Temporary Build Data
  5615. stbtt_fontinfo FontInfo;
  5616. stbrp_rect* Rects;
  5617. stbtt_pack_range* Ranges;
  5618. int RangesCount;
  5619. };
  5620. ImFontAtlas::ImFontAtlas()
  5621. {
  5622. TexID = NULL;
  5623. TexPixelsAlpha8 = NULL;
  5624. TexPixelsRGBA32 = NULL;
  5625. TexWidth = TexHeight = 0;
  5626. TexExtraDataPos = TexUvWhitePixel = ImVec2(0, 0);
  5627. }
  5628. ImFontAtlas::~ImFontAtlas()
  5629. {
  5630. Clear();
  5631. }
  5632. void ImFontAtlas::ClearInputData()
  5633. {
  5634. for (size_t i = 0; i < InputData.size(); i++)
  5635. {
  5636. if (InputData[i]->TTFData)
  5637. ImGui::MemFree(InputData[i]->TTFData);
  5638. ImGui::MemFree(InputData[i]);
  5639. }
  5640. InputData.clear();
  5641. }
  5642. void ImFontAtlas::ClearTexData()
  5643. {
  5644. if (TexPixelsAlpha8)
  5645. ImGui::MemFree(TexPixelsAlpha8);
  5646. if (TexPixelsRGBA32)
  5647. ImGui::MemFree(TexPixelsRGBA32);
  5648. TexPixelsAlpha8 = NULL;
  5649. TexPixelsRGBA32 = NULL;
  5650. }
  5651. void ImFontAtlas::Clear()
  5652. {
  5653. ClearInputData();
  5654. ClearTexData();
  5655. for (size_t i = 0; i < Fonts.size(); i++)
  5656. {
  5657. Fonts[i]->~ImFont();
  5658. ImGui::MemFree(Fonts[i]);
  5659. }
  5660. Fonts.clear();
  5661. }
  5662. void ImGui::GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size)
  5663. {
  5664. printf("GetDefaultFontData() is obsoleted in ImGui 1.30.\n");
  5665. printf("Please use ImGui::GetIO().Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() functions to retrieve uncompressed texture data.\n");
  5666. if (fnt_data) *fnt_data = NULL;
  5667. if (fnt_size) *fnt_size = 0;
  5668. if (png_data) *png_data = NULL;
  5669. if (png_size) *png_size = 0;
  5670. IM_ASSERT(false);
  5671. }
  5672. void ImFontAtlas::GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel)
  5673. {
  5674. // Lazily build
  5675. if (TexPixelsAlpha8 == NULL)
  5676. {
  5677. if (InputData.empty())
  5678. AddFontDefault();
  5679. Build();
  5680. }
  5681. *out_pixels = TexPixelsAlpha8;
  5682. if (out_width) *out_width = TexWidth;
  5683. if (out_height) *out_height = TexHeight;
  5684. if (out_bytes_per_pixel) *out_bytes_per_pixel = 1;
  5685. }
  5686. void ImFontAtlas::GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel)
  5687. {
  5688. // Lazily convert to RGBA32 format
  5689. // Although it is likely to be the most commonly used format, our font rendering is 8 bpp
  5690. if (!TexPixelsRGBA32)
  5691. {
  5692. unsigned char* pixels;
  5693. GetTexDataAsAlpha8(&pixels, NULL, NULL);
  5694. TexPixelsRGBA32 = (unsigned int*)ImGui::MemAlloc((size_t)(TexWidth * TexHeight * 4));
  5695. const unsigned char* src = pixels;
  5696. unsigned int* dst = TexPixelsRGBA32;
  5697. for (int n = TexWidth * TexHeight; n > 0; n--)
  5698. *dst++ = ((unsigned int)(*src++) << 24) | 0x00FFFFFF;
  5699. }
  5700. *out_pixels = (unsigned char*)TexPixelsRGBA32;
  5701. if (out_width) *out_width = TexWidth;
  5702. if (out_height) *out_height = TexHeight;
  5703. if (out_bytes_per_pixel) *out_bytes_per_pixel = 4;
  5704. }
  5705. static void GetDefaultCompressedFontDataTTF(const void** ttf_compressed_data, unsigned int* ttf_compressed_size);
  5706. static unsigned int stb_decompress_length(unsigned char *input);
  5707. static unsigned int stb_decompress(unsigned char *output, unsigned char *i, unsigned int length);
  5708. // Load embedded ProggyClean.ttf at size 13
  5709. ImFont* ImFontAtlas::AddFontDefault()
  5710. {
  5711. // Get compressed data
  5712. unsigned int ttf_compressed_size;
  5713. const void* ttf_compressed;
  5714. GetDefaultCompressedFontDataTTF(&ttf_compressed, &ttf_compressed_size);
  5715. // Decompress
  5716. const size_t buf_decompressed_size = stb_decompress_length((unsigned char*)ttf_compressed);
  5717. unsigned char* buf_decompressed = (unsigned char *)ImGui::MemAlloc(buf_decompressed_size);
  5718. stb_decompress(buf_decompressed, (unsigned char*)ttf_compressed, ttf_compressed_size);
  5719. // Add
  5720. ImFont* font = AddFontFromMemoryTTF(buf_decompressed, buf_decompressed_size, 13.0f, GetGlyphRangesDefault(), 0);
  5721. font->DisplayOffset.y += 1;
  5722. return font;
  5723. }
  5724. ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, const ImWchar* glyph_ranges, int font_no)
  5725. {
  5726. void* data = NULL;
  5727. size_t data_size = 0;
  5728. if (!ImLoadFileToMemory(filename, "rb", (void**)&data, &data_size))
  5729. {
  5730. IM_ASSERT(0); // Could not load file.
  5731. return NULL;
  5732. }
  5733. // Add
  5734. ImFont* font = AddFontFromMemoryTTF(data, data_size, size_pixels, glyph_ranges, font_no);
  5735. return font;
  5736. }
  5737. // NB: ownership of 'data' is given to ImFontAtlas which will clear it.
  5738. ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* in_ttf_data, size_t in_ttf_data_size, float size_pixels, const ImWchar* glyph_ranges, int font_no)
  5739. {
  5740. // Create new font
  5741. ImFont* font = (ImFont*)ImGui::MemAlloc(sizeof(ImFont));
  5742. new (font) ImFont();
  5743. Fonts.push_back(font);
  5744. // Add to build list
  5745. ImFontAtlasData* data = (ImFontAtlasData*)ImGui::MemAlloc(sizeof(ImFontAtlasData));
  5746. memset(data, 0, sizeof(ImFontAtlasData));
  5747. data->OutFont = font;
  5748. data->TTFData = in_ttf_data;
  5749. data->TTFDataSize = in_ttf_data_size;
  5750. data->SizePixels = size_pixels;
  5751. data->GlyphRanges = glyph_ranges;
  5752. data->FontNo = font_no;
  5753. InputData.push_back(data);
  5754. // Invalidate texture
  5755. ClearTexData();
  5756. return font;
  5757. }
  5758. bool ImFontAtlas::Build()
  5759. {
  5760. IM_ASSERT(InputData.size() > 0);
  5761. TexID = NULL;
  5762. TexWidth = TexHeight = 0;
  5763. TexExtraDataPos = TexUvWhitePixel = ImVec2(0, 0);
  5764. ClearTexData();
  5765. // Initialize font information early (so we can error without any cleanup) + count glyphs
  5766. int total_glyph_count = 0;
  5767. int total_glyph_range_count = 0;
  5768. for (size_t input_i = 0; input_i < InputData.size(); input_i++)
  5769. {
  5770. ImFontAtlasData& data = *InputData[input_i];
  5771. IM_ASSERT(data.OutFont && !data.OutFont->IsLoaded());
  5772. const int font_offset = stbtt_GetFontOffsetForIndex((unsigned char*)data.TTFData, data.FontNo);
  5773. IM_ASSERT(font_offset >= 0);
  5774. if (!stbtt_InitFont(&data.FontInfo, (unsigned char*)data.TTFData, font_offset))
  5775. return false;
  5776. if (!data.GlyphRanges)
  5777. data.GlyphRanges = GetGlyphRangesDefault();
  5778. for (const ImWchar* in_range = data.GlyphRanges; in_range[0] && in_range[1]; in_range += 2)
  5779. {
  5780. total_glyph_count += (in_range[1] - in_range[0]) + 1;
  5781. total_glyph_range_count++;
  5782. }
  5783. }
  5784. // Start packing
  5785. TexWidth = (total_glyph_count > 1000) ? 1024 : 512; // Width doesn't actually matters.
  5786. TexHeight = 0;
  5787. const int max_tex_height = 1024*32;
  5788. stbtt_pack_context spc;
  5789. int ret = stbtt_PackBegin(&spc, NULL, TexWidth, max_tex_height, 0, 1, NULL);
  5790. IM_ASSERT(ret);
  5791. stbtt_PackSetOversampling(&spc, 1, 1);
  5792. // Pack our extra data rectangle first, so it will be on the upper-left corner of our texture (UV will have small values).
  5793. stbrp_rect extra_rect;
  5794. extra_rect.w = (stbrp_coord)TEX_ATLAS_SIZE.x;
  5795. extra_rect.h = (stbrp_coord)TEX_ATLAS_SIZE.y;
  5796. stbrp_pack_rects((stbrp_context*)spc.pack_info, &extra_rect, 1);
  5797. TexExtraDataPos = ImVec2(extra_rect.x, extra_rect.y);
  5798. // Allocate packing character data and flag packed characters buffer as non-packed (x0=y0=x1=y1=0)
  5799. int buf_packedchars_n = 0, buf_rects_n = 0, buf_ranges_n = 0;
  5800. stbtt_packedchar* buf_packedchars = (stbtt_packedchar*)ImGui::MemAlloc(total_glyph_count * sizeof(stbtt_packedchar));
  5801. stbrp_rect* buf_rects = (stbrp_rect*)ImGui::MemAlloc(total_glyph_count * sizeof(stbrp_rect));
  5802. stbtt_pack_range* buf_ranges = (stbtt_pack_range*)ImGui::MemAlloc(total_glyph_range_count * sizeof(stbtt_pack_range));
  5803. memset(buf_packedchars, 0, total_glyph_count * sizeof(stbtt_packedchar));
  5804. memset(buf_rects, 0, total_glyph_count * sizeof(stbrp_rect)); // Unnessary but let's clear this for the sake of sanity.
  5805. memset(buf_ranges, 0, total_glyph_range_count * sizeof(stbtt_pack_range));
  5806. // First pass: pack all glyphs (no rendering at this point, we are working with glyph sizes only)
  5807. int tex_height = extra_rect.y + extra_rect.h;
  5808. for (size_t input_i = 0; input_i < InputData.size(); input_i++)
  5809. {
  5810. ImFontAtlasData& data = *InputData[input_i];
  5811. // Setup ranges
  5812. int glyph_count = 0;
  5813. int glyph_ranges_count = 0;
  5814. for (const ImWchar* in_range = data.GlyphRanges; in_range[0] && in_range[1]; in_range += 2)
  5815. {
  5816. glyph_count += (in_range[1] - in_range[0]) + 1;
  5817. glyph_ranges_count++;
  5818. }
  5819. data.Ranges = buf_ranges + buf_ranges_n;
  5820. data.RangesCount = glyph_ranges_count;
  5821. buf_ranges_n += glyph_ranges_count;
  5822. for (int i = 0; i < glyph_ranges_count; i++)
  5823. {
  5824. const ImWchar* in_range = &data.GlyphRanges[i * 2];
  5825. stbtt_pack_range& range = data.Ranges[i];
  5826. range.font_size = data.SizePixels;
  5827. range.first_unicode_char_in_range = in_range[0];
  5828. range.num_chars_in_range = (in_range[1] - in_range[0]) + 1;
  5829. range.chardata_for_range = buf_packedchars + buf_packedchars_n;
  5830. buf_packedchars_n += range.num_chars_in_range;
  5831. }
  5832. // Pack
  5833. data.Rects = buf_rects + buf_rects_n;
  5834. buf_rects_n += glyph_count;
  5835. const int n = stbtt_PackFontRangesGatherRects(&spc, &data.FontInfo, data.Ranges, data.RangesCount, data.Rects);
  5836. stbrp_pack_rects((stbrp_context*)spc.pack_info, data.Rects, n);
  5837. // Extend texture height
  5838. for (int i = 0; i < n; i++)
  5839. if (data.Rects[i].was_packed)
  5840. tex_height = ImMax(tex_height, data.Rects[i].y + data.Rects[i].h);
  5841. }
  5842. IM_ASSERT(buf_rects_n == total_glyph_count);
  5843. IM_ASSERT(buf_packedchars_n == total_glyph_count);
  5844. IM_ASSERT(buf_ranges_n == total_glyph_range_count);
  5845. // Create texture
  5846. TexHeight = ImUpperPowerOfTwo(tex_height);
  5847. TexPixelsAlpha8 = (unsigned char*)ImGui::MemAlloc(TexWidth * TexHeight);
  5848. memset(TexPixelsAlpha8, 0, TexWidth * TexHeight);
  5849. spc.pixels = TexPixelsAlpha8;
  5850. spc.height = TexHeight;
  5851. // Second pass: render characters
  5852. for (size_t input_i = 0; input_i < InputData.size(); input_i++)
  5853. {
  5854. ImFontAtlasData& data = *InputData[input_i];
  5855. ret = stbtt_PackFontRangesRenderIntoRects(&spc, &data.FontInfo, data.Ranges, data.RangesCount, data.Rects);
  5856. data.Rects = NULL;
  5857. }
  5858. // End packing
  5859. stbtt_PackEnd(&spc);
  5860. ImGui::MemFree(buf_rects);
  5861. buf_rects = NULL;
  5862. // Third pass: setup ImFont and glyphs for runtime
  5863. for (size_t input_i = 0; input_i < InputData.size(); input_i++)
  5864. {
  5865. ImFontAtlasData& data = *InputData[input_i];
  5866. data.OutFont->ContainerAtlas = this;
  5867. data.OutFont->FontSize = data.SizePixels;
  5868. const float font_scale = stbtt_ScaleForPixelHeight(&data.FontInfo, data.SizePixels);
  5869. int font_ascent, font_descent, font_line_gap;
  5870. stbtt_GetFontVMetrics(&data.FontInfo, &font_ascent, &font_descent, &font_line_gap);
  5871. const float uv_scale_x = 1.0f / TexWidth;
  5872. const float uv_scale_y = 1.0f / TexHeight;
  5873. const int character_spacing_x = 1;
  5874. for (int i = 0; i < data.RangesCount; i++)
  5875. {
  5876. stbtt_pack_range& range = data.Ranges[i];
  5877. for (int char_idx = 0; char_idx < range.num_chars_in_range; char_idx += 1)
  5878. {
  5879. const int codepoint = range.first_unicode_char_in_range + char_idx;
  5880. const stbtt_packedchar& pc = range.chardata_for_range[char_idx];
  5881. if (!pc.x0 && !pc.x1 && !pc.y0 && !pc.y1)
  5882. continue;
  5883. data.OutFont->Glyphs.resize(data.OutFont->Glyphs.size() + 1);
  5884. ImFont::Glyph& glyph = data.OutFont->Glyphs.back();
  5885. glyph.Codepoint = (ImWchar)codepoint;
  5886. glyph.Width = (signed short)pc.x1 - pc.x0 + 1;
  5887. glyph.Height = (signed short)pc.y1 - pc.y0 + 1;
  5888. glyph.XOffset = (signed short)(pc.xoff);
  5889. glyph.YOffset = (signed short)(pc.yoff + (int)(font_ascent * font_scale));
  5890. glyph.XAdvance = (signed short)(pc.xadvance + character_spacing_x); // Bake spacing into XAdvance
  5891. glyph.U0 = ((float)pc.x0 - 0.5f) * uv_scale_x;
  5892. glyph.V0 = ((float)pc.y0 - 0.5f) * uv_scale_y;
  5893. glyph.U1 = ((float)pc.x0 - 0.5f + glyph.Width) * uv_scale_x;
  5894. glyph.V1 = ((float)pc.y0 - 0.5f + glyph.Height) * uv_scale_y;
  5895. }
  5896. }
  5897. data.OutFont->BuildLookupTable();
  5898. }
  5899. // Cleanup temporaries
  5900. ImGui::MemFree(buf_packedchars);
  5901. ImGui::MemFree(buf_ranges);
  5902. buf_packedchars = NULL;
  5903. buf_ranges = NULL;
  5904. ClearInputData();
  5905. // Render into our custom data block
  5906. RenderCustomTexData();
  5907. return true;
  5908. }
  5909. void ImFontAtlas::RenderCustomTexData()
  5910. {
  5911. IM_ASSERT(TexExtraDataPos.x == 0.0f && TexExtraDataPos.y == 0.0f);
  5912. // Draw white pixel into texture and make UV points to it
  5913. TexPixelsAlpha8[0] = TexPixelsAlpha8[1] = TexPixelsAlpha8[TexWidth+0] = TexPixelsAlpha8[TexWidth+1] = 0xFF;
  5914. TexUvWhitePixel = ImVec2((TexExtraDataPos.x + 0.5f) / TexWidth, (TexExtraDataPos.y + 0.5f) / TexHeight);
  5915. // Draw a mouse cursor into texture
  5916. // Because our font uses an alpha texture, we have to spread the cursor in 2 parts (black/white) which will be rendered separately.
  5917. const char cursor_pixels[] =
  5918. {
  5919. "X "
  5920. "XX "
  5921. "X.X "
  5922. "X..X "
  5923. "X...X "
  5924. "X....X "
  5925. "X.....X "
  5926. "X......X "
  5927. "X.......X "
  5928. "X........X "
  5929. "X.........X "
  5930. "X..........X"
  5931. "X......XXXXX"
  5932. "X...X..X "
  5933. "X..X X..X "
  5934. "X.X X..X "
  5935. "XX X..X "
  5936. " X..X "
  5937. " XX "
  5938. };
  5939. IM_ASSERT(sizeof(cursor_pixels)-1 == (int)TEX_ATLAS_SIZE_MOUSE_CURSOR.x * (int)TEX_ATLAS_SIZE_MOUSE_CURSOR.y);
  5940. for (int y = 0, n = 0; y < 19; y++)
  5941. for (int x = 0; x < 12; x++, n++)
  5942. {
  5943. TexPixelsAlpha8[((int)TEX_ATLAS_POS_MOUSE_CURSOR_BLACK.x + x) + ((int)TEX_ATLAS_POS_MOUSE_CURSOR_BLACK.y + y) * TexWidth] = (cursor_pixels[n] == 'X') ? 0xFF : 0x00;
  5944. TexPixelsAlpha8[((int)TEX_ATLAS_POS_MOUSE_CURSOR_WHITE.x + x) + ((int)TEX_ATLAS_POS_MOUSE_CURSOR_WHITE.y + y) * TexWidth] = (cursor_pixels[n] == '.') ? 0xFF : 0x00;
  5945. }
  5946. }
  5947. //-----------------------------------------------------------------------------
  5948. // ImFont
  5949. //-----------------------------------------------------------------------------
  5950. ImFont::ImFont()
  5951. {
  5952. Scale = 1.0f;
  5953. FallbackChar = (ImWchar)'?';
  5954. Clear();
  5955. }
  5956. void ImFont::Clear()
  5957. {
  5958. FontSize = 0.0f;
  5959. DisplayOffset = ImVec2(-0.5f, 0.5f);
  5960. ContainerAtlas = NULL;
  5961. Glyphs.clear();
  5962. IndexLookup.clear();
  5963. FallbackGlyph = NULL;
  5964. }
  5965. // Retrieve list of range (2 int per range, values are inclusive)
  5966. const ImWchar* ImFontAtlas::GetGlyphRangesDefault()
  5967. {
  5968. static const ImWchar ranges[] =
  5969. {
  5970. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  5971. 0,
  5972. };
  5973. return &ranges[0];
  5974. }
  5975. const ImWchar* ImFontAtlas::GetGlyphRangesChinese()
  5976. {
  5977. static const ImWchar ranges[] =
  5978. {
  5979. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  5980. 0x3040, 0x309F, // Hiragana, Katakana
  5981. 0xFF00, 0xFFEF, // Half-width characters
  5982. 0x4e00, 0x9FAF, // CJK Ideograms
  5983. 0,
  5984. };
  5985. return &ranges[0];
  5986. }
  5987. const ImWchar* ImFontAtlas::GetGlyphRangesJapanese()
  5988. {
  5989. // Store the 1946 ideograms code points as successive offsets from the initial unicode codepoint 0x4E00. Each offset has an implicit +1.
  5990. // This encoding helps us reduce the source code size.
  5991. static const short offsets_from_0x4E00[] =
  5992. {
  5993. -1,0,1,3,0,0,0,0,1,0,5,1,1,0,7,4,6,10,0,1,9,9,7,1,3,19,1,10,7,1,0,1,0,5,1,0,6,4,2,6,0,0,12,6,8,0,3,5,0,1,0,9,0,0,8,1,1,3,4,5,13,0,0,8,2,17,
  5994. 4,3,1,1,9,6,0,0,0,2,1,3,2,22,1,9,11,1,13,1,3,12,0,5,9,2,0,6,12,5,3,12,4,1,2,16,1,1,4,6,5,3,0,6,13,15,5,12,8,14,0,0,6,15,3,6,0,18,8,1,6,14,1,
  5995. 5,4,12,24,3,13,12,10,24,0,0,0,1,0,1,1,2,9,10,2,2,0,0,3,3,1,0,3,8,0,3,2,4,4,1,6,11,10,14,6,15,3,4,15,1,0,0,5,2,2,0,0,1,6,5,5,6,0,3,6,5,0,0,1,0,
  5996. 11,2,2,8,4,7,0,10,0,1,2,17,19,3,0,2,5,0,6,2,4,4,6,1,1,11,2,0,3,1,2,1,2,10,7,6,3,16,0,8,24,0,0,3,1,1,3,0,1,6,0,0,0,2,0,1,5,15,0,1,0,0,2,11,19,
  5997. 1,4,19,7,6,5,1,0,0,0,0,5,1,0,1,9,0,0,5,0,2,0,1,0,3,0,11,3,0,2,0,0,0,0,0,9,3,6,4,12,0,14,0,0,29,10,8,0,14,37,13,0,31,16,19,0,8,30,1,20,8,3,48,
  5998. 21,1,0,12,0,10,44,34,42,54,11,18,82,0,2,1,2,12,1,0,6,2,17,2,12,7,0,7,17,4,2,6,24,23,8,23,39,2,16,23,1,0,5,1,2,15,14,5,6,2,11,0,8,6,2,2,2,14,
  5999. 20,4,15,3,4,11,10,10,2,5,2,1,30,2,1,0,0,22,5,5,0,3,1,5,4,1,0,0,2,2,21,1,5,1,2,16,2,1,3,4,0,8,4,0,0,5,14,11,2,16,1,13,1,7,0,22,15,3,1,22,7,14,
  6000. 22,19,11,24,18,46,10,20,64,45,3,2,0,4,5,0,1,4,25,1,0,0,2,10,0,0,0,1,0,1,2,0,0,9,1,2,0,0,0,2,5,2,1,1,5,5,8,1,1,1,5,1,4,9,1,3,0,1,0,1,1,2,0,0,
  6001. 2,0,1,8,22,8,1,0,0,0,0,4,2,1,0,9,8,5,0,9,1,30,24,2,6,4,39,0,14,5,16,6,26,179,0,2,1,1,0,0,0,5,2,9,6,0,2,5,16,7,5,1,1,0,2,4,4,7,15,13,14,0,0,
  6002. 3,0,1,0,0,0,2,1,6,4,5,1,4,9,0,3,1,8,0,0,10,5,0,43,0,2,6,8,4,0,2,0,0,9,6,0,9,3,1,6,20,14,6,1,4,0,7,2,3,0,2,0,5,0,3,1,0,3,9,7,0,3,4,0,4,9,1,6,0,
  6003. 9,0,0,2,3,10,9,28,3,6,2,4,1,2,32,4,1,18,2,0,3,1,5,30,10,0,2,2,2,0,7,9,8,11,10,11,7,2,13,7,5,10,0,3,40,2,0,1,6,12,0,4,5,1,5,11,11,21,4,8,3,7,
  6004. 8,8,33,5,23,0,0,19,8,8,2,3,0,6,1,1,1,5,1,27,4,2,5,0,3,5,6,3,1,0,3,1,12,5,3,3,2,0,7,7,2,1,0,4,0,1,1,2,0,10,10,6,2,5,9,7,5,15,15,21,6,11,5,20,
  6005. 4,3,5,5,2,5,0,2,1,0,1,7,28,0,9,0,5,12,5,5,18,30,0,12,3,3,21,16,25,32,9,3,14,11,24,5,66,9,1,2,0,5,9,1,5,1,8,0,8,3,3,0,1,15,1,4,8,1,2,7,0,7,2,
  6006. 8,3,7,5,3,7,10,2,1,0,0,2,25,0,6,4,0,10,0,4,2,4,1,12,5,38,4,0,4,1,10,5,9,4,0,14,4,2,5,18,20,21,1,3,0,5,0,7,0,3,7,1,3,1,1,8,1,0,0,0,3,2,5,2,11,
  6007. 6,0,13,1,3,9,1,12,0,16,6,2,1,0,2,1,12,6,13,11,2,0,28,1,7,8,14,13,8,13,0,2,0,5,4,8,10,2,37,42,19,6,6,7,4,14,11,18,14,80,7,6,0,4,72,12,36,27,
  6008. 7,7,0,14,17,19,164,27,0,5,10,7,3,13,6,14,0,2,2,5,3,0,6,13,0,0,10,29,0,4,0,3,13,0,3,1,6,51,1,5,28,2,0,8,0,20,2,4,0,25,2,10,13,10,0,16,4,0,1,0,
  6009. 2,1,7,0,1,8,11,0,0,1,2,7,2,23,11,6,6,4,16,2,2,2,0,22,9,3,3,5,2,0,15,16,21,2,9,20,15,15,5,3,9,1,0,0,1,7,7,5,4,2,2,2,38,24,14,0,0,15,5,6,24,14,
  6010. 5,5,11,0,21,12,0,3,8,4,11,1,8,0,11,27,7,2,4,9,21,59,0,1,39,3,60,62,3,0,12,11,0,3,30,11,0,13,88,4,15,5,28,13,1,4,48,17,17,4,28,32,46,0,16,0,
  6011. 18,11,1,8,6,38,11,2,6,11,38,2,0,45,3,11,2,7,8,4,30,14,17,2,1,1,65,18,12,16,4,2,45,123,12,56,33,1,4,3,4,7,0,0,0,3,2,0,16,4,2,4,2,0,7,4,5,2,26,
  6012. 2,25,6,11,6,1,16,2,6,17,77,15,3,35,0,1,0,5,1,0,38,16,6,3,12,3,3,3,0,9,3,1,3,5,2,9,0,18,0,25,1,3,32,1,72,46,6,2,7,1,3,14,17,0,28,1,40,13,0,20,
  6013. 15,40,6,38,24,12,43,1,1,9,0,12,6,0,6,2,4,19,3,7,1,48,0,9,5,0,5,6,9,6,10,15,2,11,19,3,9,2,0,1,10,1,27,8,1,3,6,1,14,0,26,0,27,16,3,4,9,6,2,23,
  6014. 9,10,5,25,2,1,6,1,1,48,15,9,15,14,3,4,26,60,29,13,37,21,1,6,4,0,2,11,22,23,16,16,2,2,1,3,0,5,1,6,4,0,0,4,0,0,8,3,0,2,5,0,7,1,7,3,13,2,4,10,
  6015. 3,0,2,31,0,18,3,0,12,10,4,1,0,7,5,7,0,5,4,12,2,22,10,4,2,15,2,8,9,0,23,2,197,51,3,1,1,4,13,4,3,21,4,19,3,10,5,40,0,4,1,1,10,4,1,27,34,7,21,
  6016. 2,17,2,9,6,4,2,3,0,4,2,7,8,2,5,1,15,21,3,4,4,2,2,17,22,1,5,22,4,26,7,0,32,1,11,42,15,4,1,2,5,0,19,3,1,8,6,0,10,1,9,2,13,30,8,2,24,17,19,1,4,
  6017. 4,25,13,0,10,16,11,39,18,8,5,30,82,1,6,8,18,77,11,13,20,75,11,112,78,33,3,0,0,60,17,84,9,1,1,12,30,10,49,5,32,158,178,5,5,6,3,3,1,3,1,4,7,6,
  6018. 19,31,21,0,2,9,5,6,27,4,9,8,1,76,18,12,1,4,0,3,3,6,3,12,2,8,30,16,2,25,1,5,5,4,3,0,6,10,2,3,1,0,5,1,19,3,0,8,1,5,2,6,0,0,0,19,1,2,0,5,1,2,5,
  6019. 1,3,7,0,4,12,7,3,10,22,0,9,5,1,0,2,20,1,1,3,23,30,3,9,9,1,4,191,14,3,15,6,8,50,0,1,0,0,4,0,0,1,0,2,4,2,0,2,3,0,2,0,2,2,8,7,0,1,1,1,3,3,17,11,
  6020. 91,1,9,3,2,13,4,24,15,41,3,13,3,1,20,4,125,29,30,1,0,4,12,2,21,4,5,5,19,11,0,13,11,86,2,18,0,7,1,8,8,2,2,22,1,2,6,5,2,0,1,2,8,0,2,0,5,2,1,0,
  6021. 2,10,2,0,5,9,2,1,2,0,1,0,4,0,0,10,2,5,3,0,6,1,0,1,4,4,33,3,13,17,3,18,6,4,7,1,5,78,0,4,1,13,7,1,8,1,0,35,27,15,3,0,0,0,1,11,5,41,38,15,22,6,
  6022. 14,14,2,1,11,6,20,63,5,8,27,7,11,2,2,40,58,23,50,54,56,293,8,8,1,5,1,14,0,1,12,37,89,8,8,8,2,10,6,0,0,0,4,5,2,1,0,1,1,2,7,0,3,3,0,4,6,0,3,2,
  6023. 19,3,8,0,0,0,4,4,16,0,4,1,5,1,3,0,3,4,6,2,17,10,10,31,6,4,3,6,10,126,7,3,2,2,0,9,0,0,5,20,13,0,15,0,6,0,2,5,8,64,50,3,2,12,2,9,0,0,11,8,20,
  6024. 109,2,18,23,0,0,9,61,3,0,28,41,77,27,19,17,81,5,2,14,5,83,57,252,14,154,263,14,20,8,13,6,57,39,38,
  6025. };
  6026. static int ranges_unpacked = false;
  6027. static ImWchar ranges[6 + 1 + IM_ARRAYSIZE(offsets_from_0x4E00)*2] =
  6028. {
  6029. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  6030. 0x3040, 0x309F, // Hiragana, Katakana
  6031. 0xFF00, 0xFFEF, // Half-width characters
  6032. 0,
  6033. };
  6034. if (!ranges_unpacked)
  6035. {
  6036. // Unpack
  6037. int codepoint = 0x4e00;
  6038. ImWchar* dst = &ranges[6];
  6039. for (int n = 0; n < IM_ARRAYSIZE(offsets_from_0x4E00); n++, dst += 2)
  6040. dst[0] = dst[1] = (ImWchar)(codepoint += (offsets_from_0x4E00[n] + 1));
  6041. dst[0] = 0;
  6042. ranges_unpacked = true;
  6043. }
  6044. return &ranges[0];
  6045. }
  6046. void ImFont::BuildLookupTable()
  6047. {
  6048. int max_codepoint = 0;
  6049. for (size_t i = 0; i != Glyphs.size(); i++)
  6050. max_codepoint = ImMax(max_codepoint, (int)Glyphs[i].Codepoint);
  6051. IndexLookup.clear();
  6052. IndexLookup.resize((size_t)max_codepoint + 1);
  6053. for (size_t i = 0; i < IndexLookup.size(); i++)
  6054. IndexLookup[i] = -1;
  6055. for (size_t i = 0; i < Glyphs.size(); i++)
  6056. IndexLookup[(int)Glyphs[i].Codepoint] = (int)i;
  6057. // Create a glyph to handle TAB
  6058. // FIXME: Needs proper TAB handling but it needs to be contextualized (can arbitrary say that each string starts at "column 0"
  6059. if (const ImFont::Glyph* space_glyph = FindGlyph((unsigned short)' '))
  6060. {
  6061. Glyphs.resize(Glyphs.size() + 1);
  6062. ImFont::Glyph& tab_glyph = Glyphs.back();
  6063. tab_glyph = *space_glyph;
  6064. tab_glyph.Codepoint = '\t';
  6065. tab_glyph.XAdvance *= 4;
  6066. IndexLookup[(int)tab_glyph.Codepoint] = (int)(Glyphs.size()-1);
  6067. }
  6068. }
  6069. const ImFont::Glyph* ImFont::FindGlyph(unsigned short c) const
  6070. {
  6071. if (c < (int)IndexLookup.size())
  6072. {
  6073. const int i = IndexLookup[c];
  6074. if (i != -1)
  6075. return &Glyphs[i];
  6076. }
  6077. return FallbackGlyph;
  6078. }
  6079. // Convert UTF-8 to 32-bits character, process single character input.
  6080. // Based on stb_from_utf8() from github.com/nothings/stb/
  6081. static int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end)
  6082. {
  6083. if (*in_text != 0)
  6084. {
  6085. unsigned int c = (unsigned int)-1;
  6086. const unsigned char* str = (const unsigned char*)in_text;
  6087. if (!(*str & 0x80))
  6088. {
  6089. c = (unsigned int)(*str++);
  6090. *out_char = c;
  6091. return 1;
  6092. }
  6093. if ((*str & 0xe0) == 0xc0)
  6094. {
  6095. if (in_text_end && in_text_end - (const char*)str < 2) return -1;
  6096. if (*str < 0xc2) return -1;
  6097. c = (unsigned int)((*str++ & 0x1f) << 6);
  6098. if ((*str & 0xc0) != 0x80) return -1;
  6099. c += (*str++ & 0x3f);
  6100. *out_char = c;
  6101. return 2;
  6102. }
  6103. if ((*str & 0xf0) == 0xe0)
  6104. {
  6105. if (in_text_end && in_text_end - (const char*)str < 3) return -1;
  6106. if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return -1;
  6107. if (*str == 0xed && str[1] > 0x9f) return -1; // str[1] < 0x80 is checked below
  6108. c = (unsigned int)((*str++ & 0x0f) << 12);
  6109. if ((*str & 0xc0) != 0x80) return -1;
  6110. c += (unsigned int)((*str++ & 0x3f) << 6);
  6111. if ((*str & 0xc0) != 0x80) return -1;
  6112. c += (*str++ & 0x3f);
  6113. *out_char = c;
  6114. return 3;
  6115. }
  6116. if ((*str & 0xf8) == 0xf0)
  6117. {
  6118. if (in_text_end && in_text_end - (const char*)str < 4) return -1;
  6119. if (*str > 0xf4) return -1;
  6120. if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return -1;
  6121. if (*str == 0xf4 && str[1] > 0x8f) return -1; // str[1] < 0x80 is checked below
  6122. c = (unsigned int)((*str++ & 0x07) << 18);
  6123. if ((*str & 0xc0) != 0x80) return -1;
  6124. c += (unsigned int)((*str++ & 0x3f) << 12);
  6125. if ((*str & 0xc0) != 0x80) return -1;
  6126. c += (unsigned int)((*str++ & 0x3f) << 6);
  6127. if ((*str & 0xc0) != 0x80) return -1;
  6128. c += (*str++ & 0x3f);
  6129. // utf-8 encodings of values used in surrogate pairs are invalid
  6130. if ((c & 0xFFFFF800) == 0xD800) return -1;
  6131. *out_char = c;
  6132. return 4;
  6133. }
  6134. }
  6135. *out_char = 0;
  6136. return 0;
  6137. }
  6138. static ptrdiff_t ImTextStrFromUtf8(ImWchar* buf, size_t buf_size, const char* in_text, const char* in_text_end)
  6139. {
  6140. ImWchar* buf_out = buf;
  6141. ImWchar* buf_end = buf + buf_size;
  6142. while (buf_out < buf_end-1 && (!in_text_end || in_text < in_text_end) && *in_text)
  6143. {
  6144. unsigned int c;
  6145. in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
  6146. if (c < 0x10000) // FIXME: Losing characters that don't fit in 2 bytes
  6147. *buf_out++ = (ImWchar)c;
  6148. }
  6149. *buf_out = 0;
  6150. return buf_out - buf;
  6151. }
  6152. static int ImTextCountCharsFromUtf8(const char* in_text, const char* in_text_end)
  6153. {
  6154. int char_count = 0;
  6155. while ((!in_text_end || in_text < in_text_end) && *in_text)
  6156. {
  6157. unsigned int c;
  6158. in_text += ImTextCharFromUtf8(&c, in_text, in_text_end);
  6159. if (c < 0x10000)
  6160. char_count++;
  6161. }
  6162. return char_count;
  6163. }
  6164. // Based on stb_to_utf8() from github.com/nothings/stb/
  6165. static int ImTextCharToUtf8(char* buf, size_t buf_size, unsigned int c)
  6166. {
  6167. if (c)
  6168. {
  6169. size_t i = 0;
  6170. size_t n = buf_size;
  6171. if (c < 0x80)
  6172. {
  6173. if (i+1 > n) return 0;
  6174. buf[i++] = (char)c;
  6175. return 1;
  6176. }
  6177. else if (c < 0x800)
  6178. {
  6179. if (i+2 > n) return 0;
  6180. buf[i++] = (char)(0xc0 + (c >> 6));
  6181. buf[i++] = (char)(0x80 + (c & 0x3f));
  6182. return 2;
  6183. }
  6184. else if (c >= 0xdc00 && c < 0xe000)
  6185. {
  6186. return 0;
  6187. }
  6188. else if (c >= 0xd800 && c < 0xdc00)
  6189. {
  6190. if (i+4 > n) return 0;
  6191. buf[i++] = (char)(0xf0 + (c >> 18));
  6192. buf[i++] = (char)(0x80 + ((c >> 12) & 0x3f));
  6193. buf[i++] = (char)(0x80 + ((c >> 6) & 0x3f));
  6194. buf[i++] = (char)(0x80 + ((c ) & 0x3f));
  6195. return 4;
  6196. }
  6197. //else if (c < 0x10000)
  6198. {
  6199. if (i+3 > n) return 0;
  6200. buf[i++] = (char)(0xe0 + (c >> 12));
  6201. buf[i++] = (char)(0x80 + ((c>> 6) & 0x3f));
  6202. buf[i++] = (char)(0x80 + ((c ) & 0x3f));
  6203. return 3;
  6204. }
  6205. }
  6206. return 0;
  6207. }
  6208. static ptrdiff_t ImTextStrToUtf8(char* buf, size_t buf_size, const ImWchar* in_text, const ImWchar* in_text_end)
  6209. {
  6210. char* buf_out = buf;
  6211. const char* buf_end = buf + buf_size;
  6212. while (buf_out < buf_end-1 && (!in_text_end || in_text < in_text_end) && *in_text)
  6213. {
  6214. buf_out += ImTextCharToUtf8(buf_out, (uintptr_t)(buf_end-buf_out-1), (unsigned int)*in_text);
  6215. in_text++;
  6216. }
  6217. *buf_out = 0;
  6218. return buf_out - buf;
  6219. }
  6220. static int ImTextCountUtf8BytesFromWchar(const ImWchar* in_text, const ImWchar* in_text_end)
  6221. {
  6222. int bytes_count = 0;
  6223. while ((!in_text_end || in_text < in_text_end) && *in_text)
  6224. {
  6225. char dummy[5]; // FIXME-OPT
  6226. bytes_count += ImTextCharToUtf8(dummy, 5, (unsigned int)*in_text);
  6227. in_text++;
  6228. }
  6229. return bytes_count;
  6230. }
  6231. const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const
  6232. {
  6233. // Simple word-wrapping for English, not full-featured. Please submit failing cases!
  6234. // FIXME: Much possible improvements (don't cut things like "word !", "word!!!" but cut within "word,,,,", more sensible support for punctuations, support for Unicode punctuations, etc.)
  6235. // For references, possible wrap point marked with ^
  6236. // "aaa bbb, ccc,ddd. eee fff. ggg!"
  6237. // ^ ^ ^ ^ ^__ ^ ^
  6238. // List of hardcoded separators: .,;!?'"
  6239. // Skip extra blanks after a line returns (that includes not counting them in width computation)
  6240. // e.g. "Hello world" --> "Hello" "World"
  6241. // Cut words that cannot possibly fit within one line.
  6242. // e.g.: "The tropical fish" with ~5 characters worth of width --> "The tr" "opical" "fish"
  6243. float line_width = 0.0f;
  6244. float word_width = 0.0f;
  6245. float blank_width = 0.0f;
  6246. const char* word_end = text;
  6247. const char* prev_word_end = NULL;
  6248. bool inside_word = true;
  6249. const char* s = text;
  6250. while (s < text_end)
  6251. {
  6252. unsigned int c;
  6253. const int bytes_count = ImTextCharFromUtf8(&c, s, text_end);
  6254. const char* next_s = s + (bytes_count > 0 ? bytes_count : 1);
  6255. if (c == '\n')
  6256. {
  6257. line_width = word_width = blank_width = 0.0f;
  6258. inside_word = true;
  6259. s = next_s;
  6260. continue;
  6261. }
  6262. float char_width = 0.0f;
  6263. if (const Glyph* glyph = FindGlyph((unsigned short)c))
  6264. char_width = glyph->XAdvance * scale;
  6265. if (c == ' ' || c == '\t')
  6266. {
  6267. if (inside_word)
  6268. {
  6269. line_width += blank_width;
  6270. blank_width = 0.0f;
  6271. }
  6272. blank_width += char_width;
  6273. inside_word = false;
  6274. }
  6275. else
  6276. {
  6277. word_width += char_width;
  6278. if (inside_word)
  6279. {
  6280. word_end = next_s;
  6281. }
  6282. else
  6283. {
  6284. prev_word_end = word_end;
  6285. line_width += word_width + blank_width;
  6286. word_width = blank_width = 0.0f;
  6287. }
  6288. // Allow wrapping after punctuation.
  6289. inside_word = !(c == '.' || c == ',' || c == ';' || c == '!' || c == '?' || c == '\"');
  6290. }
  6291. // We ignore blank width at the end of the line (they can be skipped)
  6292. if (line_width + word_width >= wrap_width)
  6293. {
  6294. // Words that cannot possibly fit within an entire line will be cut anywhere.
  6295. if (word_width < wrap_width)
  6296. s = prev_word_end ? prev_word_end : word_end;
  6297. break;
  6298. }
  6299. s = next_s;
  6300. }
  6301. return s;
  6302. }
  6303. ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end, const char** remaining) const
  6304. {
  6305. if (!text_end)
  6306. text_end = text_begin + strlen(text_begin); // FIXME-OPT: Need to avoid this.
  6307. const float scale = size / FontSize;
  6308. const float line_height = FontSize * scale;
  6309. ImVec2 text_size = ImVec2(0,0);
  6310. float line_width = 0.0f;
  6311. const bool word_wrap_enabled = (wrap_width > 0.0f);
  6312. const char* word_wrap_eol = NULL;
  6313. const char* s = text_begin;
  6314. while (s < text_end)
  6315. {
  6316. if (word_wrap_enabled)
  6317. {
  6318. // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature.
  6319. if (!word_wrap_eol)
  6320. {
  6321. word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - line_width);
  6322. if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
  6323. word_wrap_eol++; // +1 may not be a character start point in UTF-8 but it's ok because we use s >= word_wrap_eol below
  6324. }
  6325. if (s >= word_wrap_eol)
  6326. {
  6327. if (text_size.x < line_width)
  6328. text_size.x = line_width;
  6329. text_size.y += line_height;
  6330. line_width = 0.0f;
  6331. word_wrap_eol = NULL;
  6332. // Wrapping skips upcoming blanks
  6333. while (s < text_end)
  6334. {
  6335. const char c = *s;
  6336. if (c == ' ' || c == '\t') { s++; } else if (c == '\n') { s++; break; } else { break; }
  6337. }
  6338. continue;
  6339. }
  6340. }
  6341. // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
  6342. unsigned int c;
  6343. const int bytes_count = ImTextCharFromUtf8(&c, s, text_end);
  6344. s += bytes_count > 0 ? bytes_count : 1;
  6345. if (c == '\n')
  6346. {
  6347. text_size.x = ImMax(text_size.x, line_width);
  6348. text_size.y += line_height;
  6349. line_width = 0.0f;
  6350. continue;
  6351. }
  6352. float char_width = 0.0f;
  6353. if (const Glyph* glyph = FindGlyph((unsigned short)c))
  6354. char_width = glyph->XAdvance * scale;
  6355. if (line_width + char_width >= max_width)
  6356. break;
  6357. line_width += char_width;
  6358. }
  6359. if (line_width > 0 || text_size.y == 0.0f)
  6360. {
  6361. if (text_size.x < line_width)
  6362. text_size.x = line_width;
  6363. text_size.y += line_height;
  6364. }
  6365. if (remaining)
  6366. *remaining = s;
  6367. return text_size;
  6368. }
  6369. ImVec2 ImFont::CalcTextSizeW(float size, float max_width, const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining) const
  6370. {
  6371. if (!text_end)
  6372. text_end = text_begin + ImStrlenW(text_begin);
  6373. const float scale = size / FontSize;
  6374. const float line_height = FontSize * scale;
  6375. ImVec2 text_size = ImVec2(0,0);
  6376. float line_width = 0.0f;
  6377. const ImWchar* s = text_begin;
  6378. while (s < text_end)
  6379. {
  6380. const unsigned int c = (unsigned int)(*s++);
  6381. if (c == '\n')
  6382. {
  6383. text_size.x = ImMax(text_size.x, line_width);
  6384. text_size.y += line_height;
  6385. line_width = 0.0f;
  6386. continue;
  6387. }
  6388. float char_width = 0.0f;
  6389. if (const Glyph* glyph = FindGlyph((unsigned short)c))
  6390. char_width = glyph->XAdvance * scale;
  6391. if (line_width + char_width >= max_width)
  6392. break;
  6393. line_width += char_width;
  6394. }
  6395. if (line_width > 0 || text_size.y == 0.0f)
  6396. {
  6397. if (text_size.x < line_width)
  6398. text_size.x = line_width;
  6399. text_size.y += line_height;
  6400. }
  6401. if (remaining)
  6402. *remaining = s;
  6403. return text_size;
  6404. }
  6405. void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect_ref, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices, float wrap_width) const
  6406. {
  6407. if (!text_end)
  6408. text_end = text_begin + strlen(text_begin);
  6409. const float scale = size / FontSize;
  6410. const float line_height = FontSize * scale;
  6411. // Align to be pixel perfect
  6412. pos.x = (float)(int)pos.x + DisplayOffset.x;
  6413. pos.y = (float)(int)pos.y + DisplayOffset.y;
  6414. const bool word_wrap_enabled = (wrap_width > 0.0f);
  6415. const char* word_wrap_eol = NULL;
  6416. const ImVec4 clip_rect = clip_rect_ref;
  6417. float x = pos.x;
  6418. float y = pos.y;
  6419. const char* s = text_begin;
  6420. while (s < text_end)
  6421. {
  6422. if (word_wrap_enabled)
  6423. {
  6424. // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature.
  6425. if (!word_wrap_eol)
  6426. {
  6427. word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - (x - pos.x));
  6428. if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
  6429. word_wrap_eol++; // +1 may not be a character start point in UTF-8 but it's ok because we use s >= word_wrap_eol below
  6430. }
  6431. if (s >= word_wrap_eol)
  6432. {
  6433. x = pos.x;
  6434. y += line_height;
  6435. word_wrap_eol = NULL;
  6436. // Wrapping skips upcoming blanks
  6437. while (s < text_end)
  6438. {
  6439. const char c = *s;
  6440. if (c == ' ' || c == '\t') { s++; } else if (c == '\n') { s++; break; } else { break; }
  6441. }
  6442. continue;
  6443. }
  6444. }
  6445. // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
  6446. unsigned int c;
  6447. const int bytes_count = ImTextCharFromUtf8(&c, s, text_end);
  6448. s += bytes_count > 0 ? bytes_count : 1;
  6449. if (c == '\n')
  6450. {
  6451. x = pos.x;
  6452. y += line_height;
  6453. continue;
  6454. }
  6455. float char_width = 0.0f;
  6456. if (const Glyph* glyph = FindGlyph((unsigned short)c))
  6457. {
  6458. char_width = glyph->XAdvance * scale;
  6459. if (c != ' ' && c != '\t')
  6460. {
  6461. // Clipping on Y is more likely
  6462. const float y1 = (float)(y + glyph->YOffset * scale);
  6463. const float y2 = (float)(y1 + glyph->Height * scale);
  6464. if (y1 <= clip_rect.w && y2 >= clip_rect.y)
  6465. {
  6466. const float x1 = (float)(x + glyph->XOffset * scale);
  6467. const float x2 = (float)(x1 + glyph->Width * scale);
  6468. if (x1 <= clip_rect.z && x2 >= clip_rect.x)
  6469. {
  6470. // Render a character
  6471. const float u0 = glyph->U0;
  6472. const float v0 = glyph->V0;
  6473. const float u1 = glyph->U1;
  6474. const float v1 = glyph->V1;
  6475. out_vertices[0].pos = ImVec2(x1, y1);
  6476. out_vertices[0].uv = ImVec2(u0, v0);
  6477. out_vertices[0].col = col;
  6478. out_vertices[1].pos = ImVec2(x2, y1);
  6479. out_vertices[1].uv = ImVec2(u1, v0);
  6480. out_vertices[1].col = col;
  6481. out_vertices[2].pos = ImVec2(x2, y2);
  6482. out_vertices[2].uv = ImVec2(u1, v1);
  6483. out_vertices[2].col = col;
  6484. out_vertices[3] = out_vertices[0];
  6485. out_vertices[4] = out_vertices[2];
  6486. out_vertices[5].pos = ImVec2(x1, y2);
  6487. out_vertices[5].uv = ImVec2(u0, v1);
  6488. out_vertices[5].col = col;
  6489. out_vertices += 6;
  6490. }
  6491. }
  6492. }
  6493. }
  6494. x += char_width;
  6495. }
  6496. }
  6497. //-----------------------------------------------------------------------------
  6498. // PLATFORM DEPENDANT HELPERS
  6499. //-----------------------------------------------------------------------------
  6500. #if defined(_MSC_VER) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS)
  6501. #define WIN32_LEAN_AND_MEAN
  6502. #include <windows.h>
  6503. // Win32 API clipboard implementation
  6504. static const char* GetClipboardTextFn_DefaultImpl()
  6505. {
  6506. static char* buf_local = NULL;
  6507. if (buf_local)
  6508. {
  6509. ImGui::MemFree(buf_local);
  6510. buf_local = NULL;
  6511. }
  6512. if (!OpenClipboard(NULL))
  6513. return NULL;
  6514. HANDLE buf_handle = GetClipboardData(CF_TEXT);
  6515. if (buf_handle == NULL)
  6516. return NULL;
  6517. if (char* buf_global = (char*)GlobalLock(buf_handle))
  6518. buf_local = ImStrdup(buf_global);
  6519. GlobalUnlock(buf_handle);
  6520. CloseClipboard();
  6521. return buf_local;
  6522. }
  6523. // Win32 API clipboard implementation
  6524. static void SetClipboardTextFn_DefaultImpl(const char* text)
  6525. {
  6526. if (!OpenClipboard(NULL))
  6527. return;
  6528. const char* text_end = text + strlen(text);
  6529. const int buf_length = (int)(text_end - text) + 1;
  6530. HGLOBAL buf_handle = GlobalAlloc(GMEM_MOVEABLE, (SIZE_T)buf_length * sizeof(char));
  6531. if (buf_handle == NULL)
  6532. return;
  6533. char* buf_global = (char *)GlobalLock(buf_handle);
  6534. memcpy(buf_global, text, (size_t)(text_end - text));
  6535. buf_global[text_end - text] = 0;
  6536. GlobalUnlock(buf_handle);
  6537. EmptyClipboard();
  6538. SetClipboardData(CF_TEXT, buf_handle);
  6539. CloseClipboard();
  6540. }
  6541. #else
  6542. // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
  6543. static const char* GetClipboardTextFn_DefaultImpl()
  6544. {
  6545. return GImGui.PrivateClipboard;
  6546. }
  6547. // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
  6548. static void SetClipboardTextFn_DefaultImpl(const char* text)
  6549. {
  6550. if (GImGui.PrivateClipboard)
  6551. {
  6552. ImGui::MemFree(GImGui.PrivateClipboard);
  6553. GImGui.PrivateClipboard = NULL;
  6554. }
  6555. const char* text_end = text + strlen(text);
  6556. GImGui.PrivateClipboard = (char*)ImGui::MemAlloc((size_t)(text_end - text) + 1);
  6557. memcpy(GImGui.PrivateClipboard, text, (size_t)(text_end - text));
  6558. GImGui.PrivateClipboard[(size_t)(text_end - text)] = 0;
  6559. }
  6560. #endif
  6561. //-----------------------------------------------------------------------------
  6562. // HELP
  6563. //-----------------------------------------------------------------------------
  6564. void ImGui::ShowUserGuide()
  6565. {
  6566. ImGuiState& g = GImGui;
  6567. ImGui::BulletText("Double-click on title bar to collapse window.");
  6568. ImGui::BulletText("Click and drag on lower right corner to resize window.");
  6569. ImGui::BulletText("Click and drag on any empty space to move window.");
  6570. ImGui::BulletText("Mouse Wheel to scroll.");
  6571. if (g.IO.FontAllowUserScaling)
  6572. ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents.");
  6573. ImGui::BulletText("TAB/SHIFT+TAB to cycle through keyboard editable fields.");
  6574. ImGui::BulletText("CTRL+Click on a slider to input text.");
  6575. ImGui::BulletText(
  6576. "While editing text:\n"
  6577. "- Hold SHIFT or use mouse to select text\n"
  6578. "- CTRL+Left/Right to word jump\n"
  6579. "- CTRL+A select all\n"
  6580. "- CTRL+X,CTRL+C,CTRL+V clipboard\n"
  6581. "- CTRL+Z,CTRL+Y undo/redo\n"
  6582. "- ESCAPE to revert\n"
  6583. "- You can apply arithmetic operators +,*,/ on numerical values.\n"
  6584. " Use +- to subtract.\n");
  6585. }
  6586. void ImGui::ShowStyleEditor(ImGuiStyle* ref)
  6587. {
  6588. ImGuiState& g = GImGui;
  6589. ImGuiStyle& style = g.Style;
  6590. const ImGuiStyle def; // Default style
  6591. if (ImGui::Button("Revert Style"))
  6592. g.Style = ref ? *ref : def;
  6593. if (ref)
  6594. {
  6595. ImGui::SameLine();
  6596. if (ImGui::Button("Save Style"))
  6597. *ref = g.Style;
  6598. }
  6599. ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.55f);
  6600. if (ImGui::TreeNode("Sizes"))
  6601. {
  6602. 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.
  6603. ImGui::SliderFloat2("WindowPadding", (float*)&style.WindowPadding, 0.0f, 20.0f, "%.0f");
  6604. ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 16.0f, "%.0f");
  6605. ImGui::SliderFloat2("FramePadding", (float*)&style.FramePadding, 0.0f, 20.0f, "%.0f");
  6606. ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 16.0f, "%.0f");
  6607. ImGui::SliderFloat2("ItemSpacing", (float*)&style.ItemSpacing, 0.0f, 20.0f, "%.0f");
  6608. ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f");
  6609. ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 10.0f, "%.0f");
  6610. ImGui::SliderFloat("TreeNodeSpacing", &style.TreeNodeSpacing, 0.0f, 20.0f, "%.0f");
  6611. ImGui::SliderFloat("ScrollBarWidth", &style.ScrollBarWidth, 0.0f, 20.0f, "%.0f");
  6612. ImGui::TreePop();
  6613. }
  6614. if (ImGui::TreeNode("Colors"))
  6615. {
  6616. static int output_dest = 0;
  6617. static bool output_only_modified = false;
  6618. if (ImGui::Button("Output Colors"))
  6619. {
  6620. if (output_dest == 0)
  6621. ImGui::LogToClipboard();
  6622. else
  6623. ImGui::LogToTTY();
  6624. ImGui::LogText("ImGuiStyle& style = ImGui::GetStyle();" STR_NEWLINE);
  6625. for (int i = 0; i < ImGuiCol_COUNT; i++)
  6626. {
  6627. const ImVec4& col = style.Colors[i];
  6628. const char* name = ImGui::GetStyleColName(i);
  6629. if (!output_only_modified || memcmp(&col, (ref ? &ref->Colors[i] : &def.Colors[i]), sizeof(ImVec4)) != 0)
  6630. ImGui::LogText("style.Colors[ImGuiCol_%s]%*s= ImVec4(%.2ff, %.2ff, %.2ff, %.2ff);" STR_NEWLINE, name, 22 - strlen(name), "", col.x, col.y, col.z, col.w);
  6631. }
  6632. ImGui::LogFinish();
  6633. }
  6634. ImGui::SameLine(); ImGui::PushItemWidth(150); ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY"); ImGui::PopItemWidth();
  6635. ImGui::SameLine(); ImGui::Checkbox("Only Modified Fields", &output_only_modified);
  6636. static ImGuiColorEditMode edit_mode = ImGuiColorEditMode_RGB;
  6637. ImGui::RadioButton("RGB", &edit_mode, ImGuiColorEditMode_RGB);
  6638. ImGui::SameLine();
  6639. ImGui::RadioButton("HSV", &edit_mode, ImGuiColorEditMode_HSV);
  6640. ImGui::SameLine();
  6641. ImGui::RadioButton("HEX", &edit_mode, ImGuiColorEditMode_HEX);
  6642. //ImGui::Text("Tip: Click on colored square to change edit mode.");
  6643. static ImGuiTextFilter filter;
  6644. filter.Draw("Filter colors", 200);
  6645. ImGui::BeginChild("#colors", ImVec2(0, 300), true);
  6646. ImGui::ColorEditMode(edit_mode);
  6647. for (int i = 0; i < ImGuiCol_COUNT; i++)
  6648. {
  6649. const char* name = ImGui::GetStyleColName(i);
  6650. if (!filter.PassFilter(name))
  6651. continue;
  6652. ImGui::PushID(i);
  6653. ImGui::ColorEdit4(name, (float*)&style.Colors[i], true);
  6654. if (memcmp(&style.Colors[i], (ref ? &ref->Colors[i] : &def.Colors[i]), sizeof(ImVec4)) != 0)
  6655. {
  6656. ImGui::SameLine(); if (ImGui::Button("Revert")) style.Colors[i] = ref ? ref->Colors[i] : def.Colors[i];
  6657. if (ref) { ImGui::SameLine(); if (ImGui::Button("Save")) ref->Colors[i] = style.Colors[i]; }
  6658. }
  6659. ImGui::PopID();
  6660. }
  6661. ImGui::EndChild();
  6662. ImGui::TreePop();
  6663. }
  6664. ImGui::PopItemWidth();
  6665. }
  6666. //-----------------------------------------------------------------------------
  6667. // SAMPLE CODE
  6668. //-----------------------------------------------------------------------------
  6669. static void ShowExampleAppConsole(bool* opened);
  6670. static void ShowExampleAppLongText(bool* opened);
  6671. static void ShowExampleAppAutoResize(bool* opened);
  6672. static void ShowExampleAppFixedOverlay(bool* opened);
  6673. static void ShowExampleAppCustomRendering(bool* opened);
  6674. // Demonstrate ImGui features (unfortunately this makes this function a little bloated!)
  6675. void ImGui::ShowTestWindow(bool* opened)
  6676. {
  6677. static bool no_titlebar = false;
  6678. static bool no_border = true;
  6679. static bool no_resize = false;
  6680. static bool no_move = false;
  6681. static bool no_scrollbar = false;
  6682. static bool no_collapse = false;
  6683. static float fill_alpha = 0.65f;
  6684. // Demonstrate the various window flags. Typically you would just use the default.
  6685. ImGuiWindowFlags window_flags = 0;
  6686. if (no_titlebar) window_flags |= ImGuiWindowFlags_NoTitleBar;
  6687. if (!no_border) window_flags |= ImGuiWindowFlags_ShowBorders;
  6688. if (no_resize) window_flags |= ImGuiWindowFlags_NoResize;
  6689. if (no_move) window_flags |= ImGuiWindowFlags_NoMove;
  6690. if (no_scrollbar) window_flags |= ImGuiWindowFlags_NoScrollbar;
  6691. if (no_collapse) window_flags |= ImGuiWindowFlags_NoCollapse;
  6692. if (!ImGui::Begin("ImGui Test", opened, ImVec2(550,680), fill_alpha, window_flags))
  6693. {
  6694. // Early out if the window is collapsed, as an optimization.
  6695. ImGui::End();
  6696. return;
  6697. }
  6698. ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f);
  6699. ImGui::Text("ImGui says hello.");
  6700. //ImGui::Text("MousePos (%g, %g)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
  6701. //ImGui::Text("MouseWheel %d", ImGui::GetIO().MouseWheel);
  6702. //ImGui::Text("WantCaptureMouse: %d", ImGui::GetIO().WantCaptureMouse);
  6703. //ImGui::Text("WantCaptureKeyboard: %d", ImGui::GetIO().WantCaptureKeyboard);
  6704. ImGui::Spacing();
  6705. if (ImGui::CollapsingHeader("Help"))
  6706. {
  6707. ImGui::TextWrapped("This window is being created by the ShowTestWindow() function. Please refer to the code for programming reference.\n\nUser Guide:");
  6708. ImGui::ShowUserGuide();
  6709. }
  6710. if (ImGui::CollapsingHeader("Window options"))
  6711. {
  6712. ImGui::Checkbox("no titlebar", &no_titlebar); ImGui::SameLine(150);
  6713. ImGui::Checkbox("no border", &no_border); ImGui::SameLine(300);
  6714. ImGui::Checkbox("no resize", &no_resize);
  6715. ImGui::Checkbox("no move", &no_move); ImGui::SameLine(150);
  6716. ImGui::Checkbox("no scrollbar", &no_scrollbar); ImGui::SameLine(300);
  6717. ImGui::Checkbox("no collapse", &no_collapse);
  6718. ImGui::SliderFloat("fill alpha", &fill_alpha, 0.0f, 1.0f);
  6719. if (ImGui::TreeNode("Style"))
  6720. {
  6721. ImGui::ShowStyleEditor();
  6722. ImGui::TreePop();
  6723. }
  6724. if (ImGui::TreeNode("Fonts"))
  6725. {
  6726. ImGui::TextWrapped("Tip: Load fonts with GetIO().Fonts->AddFontFromFileTTF().");
  6727. for (size_t i = 0; i < ImGui::GetIO().Fonts->Fonts.size(); i++)
  6728. {
  6729. ImFont* font = ImGui::GetIO().Fonts->Fonts[i];
  6730. ImGui::BulletText("Font %d: %.2f pixels, %d glyphs", i, font->FontSize, font->Glyphs.size());
  6731. ImGui::TreePush((void*)i);
  6732. ImGui::PushFont(font);
  6733. ImGui::Text("The quick brown fox jumps over the lazy dog");
  6734. ImGui::PopFont();
  6735. if (i > 0 && ImGui::Button("Set as default"))
  6736. {
  6737. ImGui::GetIO().Fonts->Fonts[i] = ImGui::GetIO().Fonts->Fonts[0];
  6738. ImGui::GetIO().Fonts->Fonts[0] = font;
  6739. }
  6740. ImGui::SliderFloat("font scale", &font->Scale, 0.3f, 2.0f, "%.1f"); // scale only this font
  6741. ImGui::TreePop();
  6742. }
  6743. static float window_scale = 1.0f;
  6744. ImGui::SliderFloat("this window scale", &window_scale, 0.3f, 2.0f, "%.1f"); // scale only this window
  6745. ImGui::SliderFloat("global scale", &ImGui::GetIO().FontGlobalScale, 0.3f, 2.0f, "%.1f"); // scale everything
  6746. ImGui::SetWindowFontScale(window_scale);
  6747. ImGui::TreePop();
  6748. }
  6749. if (ImGui::TreeNode("Logging"))
  6750. {
  6751. ImGui::LogButtons();
  6752. ImGui::TreePop();
  6753. }
  6754. }
  6755. if (ImGui::CollapsingHeader("Widgets"))
  6756. {
  6757. static bool a=false;
  6758. if (ImGui::Button("Button")) { printf("Clicked\n"); a ^= 1; }
  6759. if (a)
  6760. {
  6761. ImGui::SameLine();
  6762. ImGui::Text("Thanks for clicking me!");
  6763. }
  6764. if (ImGui::TreeNode("Tree"))
  6765. {
  6766. for (size_t i = 0; i < 5; i++)
  6767. {
  6768. if (ImGui::TreeNode((void*)i, "Child %d", i))
  6769. {
  6770. ImGui::Text("blah blah");
  6771. ImGui::SameLine();
  6772. if (ImGui::SmallButton("print"))
  6773. printf("Child %d pressed", (int)i);
  6774. ImGui::TreePop();
  6775. }
  6776. }
  6777. ImGui::TreePop();
  6778. }
  6779. if (ImGui::TreeNode("Bullets"))
  6780. {
  6781. ImGui::BulletText("Bullet point 1");
  6782. ImGui::BulletText("Bullet point 2\nOn multiple lines");
  6783. ImGui::BulletText("Bullet point 3");
  6784. ImGui::TreePop();
  6785. }
  6786. if (ImGui::TreeNode("Colored Text"))
  6787. {
  6788. // Using shortcut. You can use PushStyleColor()/PopStyleColor() for more flexibility.
  6789. ImGui::TextColored(ImVec4(1.0f,0.0f,1.0f,1.0f), "Pink");
  6790. ImGui::TextColored(ImVec4(1.0f,1.0f,0.0f,1.0f), "Yellow");
  6791. ImGui::TreePop();
  6792. }
  6793. if (ImGui::TreeNode("Word Wrapping"))
  6794. {
  6795. // Using shortcut. You can use PushTextWrapPos()/PopTextWrapPos() for more flexibility.
  6796. ImGui::TextWrapped("This text should automatically wrap on the edge of the window. The current implementation for text wrapping follows simple rules that works for English and possibly other languages.");
  6797. ImGui::Spacing();
  6798. static float wrap_width = 200.0f;
  6799. ImGui::SliderFloat("Wrap width", &wrap_width, -20, 600, "%.0f");
  6800. ImGui::Text("Test paragraph 1:");
  6801. ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetCursorScreenPos() + ImVec2(wrap_width, 0.0f), ImGui::GetCursorScreenPos() + ImVec2(wrap_width+10, ImGui::GetTextLineHeight()), 0xFFFF00FF);
  6802. ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width);
  6803. ImGui::Text("lazy dog. This paragraph is made to fit within %.0f pixels. The quick brown fox jumps over the lazy dog.", wrap_width);
  6804. ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemBoxMin(), ImGui::GetItemBoxMax(), 0xFF00FFFF);
  6805. ImGui::PopTextWrapPos();
  6806. ImGui::Text("Test paragraph 2:");
  6807. ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetCursorScreenPos() + ImVec2(wrap_width, 0.0f), ImGui::GetCursorScreenPos() + ImVec2(wrap_width+10, ImGui::GetTextLineHeight()), 0xFFFF00FF);
  6808. ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width);
  6809. ImGui::Text("aaaaaaaa bbbbbbbb, cccccccc,dddddddd. eeeeeeee ffffffff. gggggggg!hhhhhhhh");
  6810. ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemBoxMin(), ImGui::GetItemBoxMax(), 0xFF00FFFF);
  6811. ImGui::PopTextWrapPos();
  6812. ImGui::TreePop();
  6813. }
  6814. if (ImGui::TreeNode("UTF-8 Text"))
  6815. {
  6816. // UTF-8 test with Japanese characters
  6817. // (needs a suitable font, try Arial Unicode or M+ fonts http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html)
  6818. // Most compiler appears to support UTF-8 in source code (with Visual Studio you need to save your file as 'UTF-8 without signature')
  6819. // However for the sake for maximum portability here we are *not* including raw UTF-8 character in this source file, instead we encode the string with hexadecimal constants.
  6820. // In your own application be reasonable and use UTF-8 in source or retrieve the data from file system!
  6821. // Note that characters values are preserved even if the font cannot be displayed, so you can safely copy & paste garbled characters into another application.
  6822. ImGui::TextWrapped("CJK text will only appears if the font was loaded with the appropriate CJK character ranges. Call io.Font->LoadFromFileTTF() manually to load extra character ranges.");
  6823. ImGui::Text("Hiragana: \xe3\x81\x8b\xe3\x81\x8d\xe3\x81\x8f\xe3\x81\x91\xe3\x81\x93 (kakikukeko)");
  6824. ImGui::Text("Kanjis: \xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e (nihongo)");
  6825. static char buf[32] = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e";
  6826. ImGui::InputText("UTF-8 input", buf, IM_ARRAYSIZE(buf));
  6827. ImGui::TreePop();
  6828. }
  6829. if (ImGui::TreeNode("Images"))
  6830. {
  6831. ImGui::TextWrapped("Below we are displaying the font texture (which is the only texture we have access to in this demo). Use the 'ImTextureID' type as storage to pass pointers or identifier to your own texture data. Hover the texture for a zoomed view!");
  6832. ImVec2 tex_screen_pos = ImGui::GetCursorScreenPos();
  6833. float tex_w = (float)ImGui::GetIO().Fonts->TexWidth;
  6834. float tex_h = (float)ImGui::GetIO().Fonts->TexHeight;
  6835. ImTextureID tex_id = ImGui::GetIO().Fonts->TexID;
  6836. ImGui::Image(tex_id, ImVec2(tex_w, tex_h), ImVec2(0,0), ImVec2(1,1), ImColor(255,255,255,255), ImColor(255,255,255,128));
  6837. if (ImGui::IsItemHovered())
  6838. {
  6839. ImGui::BeginTooltip();
  6840. float focus_sz = 32.0f;
  6841. float focus_x = ImClamp(ImGui::GetMousePos().x - tex_screen_pos.x - focus_sz * 0.5f, 0.0f, tex_w - focus_sz);
  6842. float focus_y = ImClamp(ImGui::GetMousePos().y - tex_screen_pos.y - focus_sz * 0.5f, 0.0f, tex_h - focus_sz);
  6843. ImGui::Text("Min: (%.2f, %.2f)", focus_x, focus_y);
  6844. ImGui::Text("Max: (%.2f, %.2f)", focus_x + focus_sz, focus_y + focus_sz);
  6845. ImVec2 uv0 = ImVec2((focus_x) / tex_w, (focus_y) / tex_h);
  6846. ImVec2 uv1 = ImVec2((focus_x + focus_sz) / tex_w, (focus_y + focus_sz) / tex_h);
  6847. ImGui::Image(tex_id, ImVec2(128,128), uv0, uv1, ImColor(255,255,255,255), ImColor(255,255,255,128));
  6848. ImGui::EndTooltip();
  6849. }
  6850. ImGui::TextWrapped("And now some textured buttons..");
  6851. static int pressed_count = 0;
  6852. for (int i = 0; i < 8; i++)
  6853. {
  6854. if (i > 0)
  6855. ImGui::SameLine();
  6856. ImGui::PushID(i);
  6857. int frame_padding = -1 + i; // -1 padding uses default padding
  6858. if (ImGui::ImageButton(tex_id, ImVec2(32,32), ImVec2(0,0), ImVec2(32.0f/tex_w,32/tex_h), frame_padding))
  6859. pressed_count += 1;
  6860. ImGui::PopID();
  6861. }
  6862. ImGui::Text("Pressed %d times.", pressed_count);
  6863. ImGui::TreePop();
  6864. }
  6865. static bool check = true;
  6866. ImGui::Checkbox("checkbox", &check);
  6867. static int e = 0;
  6868. ImGui::RadioButton("radio a", &e, 0); ImGui::SameLine();
  6869. ImGui::RadioButton("radio b", &e, 1); ImGui::SameLine();
  6870. ImGui::RadioButton("radio c", &e, 2);
  6871. // Color buttons, demonstrate using PushID() to add unique identifier in the ID stack, and changing style.
  6872. for (int i = 0; i < 7; i++)
  6873. {
  6874. if (i > 0) ImGui::SameLine();
  6875. ImGui::PushID(i);
  6876. ImGui::PushStyleColor(ImGuiCol_Button, ImColor::HSV(i/7.0f, 0.6f, 0.6f));
  6877. ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImColor::HSV(i/7.0f, 0.7f, 0.7f));
  6878. ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImColor::HSV(i/7.0f, 0.8f, 0.8f));
  6879. ImGui::Button("Click");
  6880. ImGui::PopStyleColor(3);
  6881. ImGui::PopID();
  6882. }
  6883. ImGui::Text("Hover over me");
  6884. if (ImGui::IsItemHovered())
  6885. ImGui::SetTooltip("I am a tooltip");
  6886. ImGui::SameLine();
  6887. ImGui::Text("- or me");
  6888. if (ImGui::IsItemHovered())
  6889. {
  6890. ImGui::BeginTooltip();
  6891. ImGui::Text("I am a fancy tooltip");
  6892. static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
  6893. ImGui::PlotLines("Curve", arr, IM_ARRAYSIZE(arr));
  6894. ImGui::EndTooltip();
  6895. }
  6896. // Testing IMGUI_ONCE_UPON_A_FRAME macro
  6897. //for (int i = 0; i < 5; i++)
  6898. //{
  6899. // IMGUI_ONCE_UPON_A_FRAME
  6900. // {
  6901. // ImGui::Text("This will be displayed only once.");
  6902. // }
  6903. //}
  6904. ImGui::Separator();
  6905. static int item = 1;
  6906. ImGui::Combo("combo", &item, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0");
  6907. const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK" };
  6908. static int item2 = -1;
  6909. ImGui::Combo("combo scroll", &item2, items, IM_ARRAYSIZE(items));
  6910. static char str0[128] = "Hello, world!";
  6911. static int i0=123;
  6912. static float f0=0.001f;
  6913. ImGui::InputText("string", str0, IM_ARRAYSIZE(str0));
  6914. ImGui::InputInt("input int", &i0);
  6915. ImGui::InputFloat("input float", &f0, 0.01f, 1.0f);
  6916. static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f };
  6917. //ImGui::InputFloat2("input float2", vec4a);
  6918. ImGui::InputFloat3("input float3", vec4a);
  6919. //ImGui::InputFloat4("input float4", vec4a);
  6920. static int i1=0;
  6921. static int i2=42;
  6922. ImGui::SliderInt("int 0..3", &i1, 0, 3);
  6923. ImGui::SliderInt("int -100..100", &i2, -100, 100);
  6924. static float f1=1.123f;
  6925. static float f2=0;
  6926. static float f3=0;
  6927. static float f4=123456789.0f;
  6928. ImGui::SliderFloat("float", &f1, 0.0f, 2.0f);
  6929. ImGui::SliderFloat("log float", &f2, 0.0f, 10.0f, "%.4f", 2.0f);
  6930. ImGui::SliderFloat("signed log float", &f3, -10.0f, 10.0f, "%.4f", 3.0f);
  6931. ImGui::SliderFloat("unbound float", &f4, -FLT_MAX, FLT_MAX, "%.4f");
  6932. static float angle = 0.0f;
  6933. ImGui::SliderAngle("angle", &angle);
  6934. static float vec4b[4] = { 0.10f, 0.20f, 0.30f, 0.40f };
  6935. //ImGui::SliderFloat2("slider float2", vec4b, 0.0f, 1.0f);
  6936. ImGui::SliderFloat3("slider float3", vec4b, 0.0f, 1.0f);
  6937. //ImGui::SliderFloat4("slider float4", vec4b, 0.0f, 1.0f);
  6938. //static int vec4i[4] = { 1, 5, 100, 255 };
  6939. //ImGui::SliderInt2("slider int2", vec4i, 0, 255);
  6940. //ImGui::SliderInt3("slider int3", vec4i, 0, 255);
  6941. //ImGui::SliderInt4("slider int4", vec4i, 0, 255);
  6942. static float col1[3] = { 1.0f,0.0f,0.2f };
  6943. static float col2[4] = { 0.4f,0.7f,0.0f,0.5f };
  6944. ImGui::ColorEdit3("color 1", col1);
  6945. ImGui::ColorEdit4("color 2", col2);
  6946. }
  6947. if (ImGui::CollapsingHeader("Graphs widgets"))
  6948. {
  6949. static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
  6950. ImGui::PlotLines("Frame Times", arr, IM_ARRAYSIZE(arr));
  6951. static bool pause;
  6952. static ImVector<float> values; if (values.empty()) { values.resize(100); memset(&values.front(), 0, values.size()*sizeof(float)); }
  6953. static size_t values_offset = 0;
  6954. if (!pause)
  6955. {
  6956. // create dummy data at fixed 60 hz rate
  6957. static float refresh_time = -1.0f;
  6958. if (ImGui::GetTime() > refresh_time + 1.0f/60.0f)
  6959. {
  6960. refresh_time = ImGui::GetTime();
  6961. static float phase = 0.0f;
  6962. values[values_offset] = cosf(phase);
  6963. values_offset = (values_offset+1)%values.size();
  6964. phase += 0.10f*values_offset;
  6965. }
  6966. }
  6967. ImGui::PlotLines("Frame Times", &values.front(), (int)values.size(), (int)values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,70));
  6968. ImGui::SameLine(); ImGui::Checkbox("pause", &pause);
  6969. ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,70));
  6970. }
  6971. if (ImGui::CollapsingHeader("Horizontal Layout"))
  6972. {
  6973. // Text
  6974. ImGui::Text("Hello");
  6975. ImGui::SameLine();
  6976. ImGui::Text("World");
  6977. // Button
  6978. if (ImGui::Button("Banana")) printf("Pressed!\n");
  6979. ImGui::SameLine();
  6980. ImGui::Button("Apple");
  6981. ImGui::SameLine();
  6982. ImGui::Button("Corniflower");
  6983. // Button
  6984. ImGui::Text("Small buttons");
  6985. ImGui::SameLine();
  6986. ImGui::SmallButton("Like this one");
  6987. ImGui::SameLine();
  6988. ImGui::Text("can fit within a text block.");
  6989. // Checkbox
  6990. static bool c1=false,c2=false,c3=false,c4=false;
  6991. ImGui::Checkbox("My", &c1);
  6992. ImGui::SameLine();
  6993. ImGui::Checkbox("Tailor", &c2);
  6994. ImGui::SameLine();
  6995. ImGui::Checkbox("Is", &c3);
  6996. ImGui::SameLine();
  6997. ImGui::Checkbox("Rich", &c4);
  6998. // SliderFloat
  6999. static float f0=1.0f, f1=2.0f, f2=3.0f;
  7000. ImGui::PushItemWidth(80);
  7001. ImGui::SliderFloat("X", &f0, 0.0f,5.0f);
  7002. ImGui::SameLine();
  7003. ImGui::SliderFloat("Y", &f1, 0.0f,5.0f);
  7004. ImGui::SameLine();
  7005. ImGui::SliderFloat("Z", &f2, 0.0f,5.0f);
  7006. }
  7007. if (ImGui::CollapsingHeader("Child regions"))
  7008. {
  7009. ImGui::Text("Without border");
  7010. static int line = 50;
  7011. bool goto_line = ImGui::Button("Goto");
  7012. ImGui::SameLine();
  7013. ImGui::PushItemWidth(100);
  7014. goto_line |= ImGui::InputInt("##Line", &line, 0, 0, ImGuiInputTextFlags_EnterReturnsTrue);
  7015. ImGui::PopItemWidth();
  7016. ImGui::BeginChild("Sub1", ImVec2(ImGui::GetWindowWidth() * 0.5f,300));
  7017. for (int i = 0; i < 100; i++)
  7018. {
  7019. ImGui::Text("%04d: scrollable region", i);
  7020. if (goto_line && line == i)
  7021. ImGui::SetScrollPosHere();
  7022. }
  7023. if (goto_line && line >= 100)
  7024. ImGui::SetScrollPosHere();
  7025. ImGui::EndChild();
  7026. ImGui::SameLine();
  7027. ImGui::BeginChild("Sub2", ImVec2(0,300), true);
  7028. ImGui::Text("With border");
  7029. ImGui::Columns(2);
  7030. for (int i = 0; i < 100; i++)
  7031. {
  7032. if (i == 50)
  7033. ImGui::NextColumn();
  7034. char buf[32];
  7035. ImFormatString(buf, IM_ARRAYSIZE(buf), "%08x", i*5731);
  7036. ImGui::Button(buf);
  7037. }
  7038. ImGui::EndChild();
  7039. }
  7040. if (ImGui::CollapsingHeader("Columns"))
  7041. {
  7042. ImGui::Columns(4, "data", true);
  7043. ImGui::Text("ID"); ImGui::NextColumn();
  7044. ImGui::Text("Name"); ImGui::NextColumn();
  7045. ImGui::Text("Path"); ImGui::NextColumn();
  7046. ImGui::Text("Flags"); ImGui::NextColumn();
  7047. ImGui::Separator();
  7048. ImGui::Text("0000"); ImGui::NextColumn();
  7049. ImGui::Text("Robert"); ImGui::NextColumn();
  7050. ImGui::Text("/path/robert"); ImGui::NextColumn();
  7051. ImGui::Text("...."); ImGui::NextColumn();
  7052. ImGui::Text("0001"); ImGui::NextColumn();
  7053. ImGui::Text("Stephanie"); ImGui::NextColumn();
  7054. ImGui::Text("/path/stephanie"); ImGui::NextColumn();
  7055. ImGui::Text("line 1"); ImGui::Text("line 2"); ImGui::NextColumn(); // two lines, two items
  7056. ImGui::Text("0002"); ImGui::NextColumn();
  7057. ImGui::Text("C64"); ImGui::NextColumn();
  7058. ImGui::Text("/path/computer"); ImGui::NextColumn();
  7059. ImGui::Text("...."); ImGui::NextColumn();
  7060. ImGui::Columns(1);
  7061. ImGui::Separator();
  7062. ImGui::Columns(3, "mixed");
  7063. // Create multiple items in a same cell because switching to next column
  7064. static int e = 0;
  7065. ImGui::Text("Hello");
  7066. ImGui::Button("Banana");
  7067. ImGui::RadioButton("radio a", &e, 0);
  7068. ImGui::NextColumn();
  7069. ImGui::Text("ImGui");
  7070. ImGui::Button("Apple");
  7071. ImGui::RadioButton("radio b", &e, 1);
  7072. ImGui::Text("An extra line here.");
  7073. ImGui::NextColumn();
  7074. ImGui::Text("World!");
  7075. ImGui::Button("Corniflower");
  7076. ImGui::RadioButton("radio c", &e, 2);
  7077. ImGui::NextColumn();
  7078. if (ImGui::CollapsingHeader("Category A")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  7079. if (ImGui::CollapsingHeader("Category B")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  7080. if (ImGui::CollapsingHeader("Category C")) ImGui::Text("Blah blah blah"); ImGui::NextColumn();
  7081. ImGui::Columns(1);
  7082. ImGui::Separator();
  7083. ImGui::Columns(2, "multiple components");
  7084. static float foo = 1.0f;
  7085. ImGui::InputFloat("red", &foo, 0.05f, 0, 3); ImGui::NextColumn();
  7086. static float bar = 1.0f;
  7087. ImGui::InputFloat("blue", &bar, 0.05f, 0, 3); ImGui::NextColumn();
  7088. ImGui::Columns(1);
  7089. ImGui::Separator();
  7090. ImGui::Columns(2, "word wrapping");
  7091. ImGui::TextWrapped("The quick brown fox jumps over the lazy dog.");
  7092. ImGui::Text("Hello Left");
  7093. ImGui::NextColumn();
  7094. ImGui::TextWrapped("The quick brown fox jumps over the lazy dog.");
  7095. ImGui::Text("Hello Right");
  7096. ImGui::Columns(1);
  7097. ImGui::Separator();
  7098. if (ImGui::TreeNode("Inside a tree.."))
  7099. {
  7100. if (ImGui::TreeNode("node 1 (with borders)"))
  7101. {
  7102. ImGui::Columns(4);
  7103. ImGui::Text("aaa"); ImGui::NextColumn();
  7104. ImGui::Text("bbb"); ImGui::NextColumn();
  7105. ImGui::Text("ccc"); ImGui::NextColumn();
  7106. ImGui::Text("ddd"); ImGui::NextColumn();
  7107. ImGui::Text("eee"); ImGui::NextColumn();
  7108. ImGui::Text("fff"); ImGui::NextColumn();
  7109. ImGui::Text("ggg"); ImGui::NextColumn();
  7110. ImGui::Text("hhh"); ImGui::NextColumn();
  7111. ImGui::Columns(1);
  7112. ImGui::TreePop();
  7113. }
  7114. if (ImGui::TreeNode("node 2 (without borders)"))
  7115. {
  7116. ImGui::Columns(4, NULL, false);
  7117. ImGui::Text("aaa"); ImGui::NextColumn();
  7118. ImGui::Text("bbb"); ImGui::NextColumn();
  7119. ImGui::Text("ccc"); ImGui::NextColumn();
  7120. ImGui::Text("ddd"); ImGui::NextColumn();
  7121. ImGui::Text("eee"); ImGui::NextColumn();
  7122. ImGui::Text("fff"); ImGui::NextColumn();
  7123. ImGui::Text("ggg"); ImGui::NextColumn();
  7124. ImGui::Text("hhh"); ImGui::NextColumn();
  7125. ImGui::Columns(1);
  7126. ImGui::TreePop();
  7127. }
  7128. ImGui::TreePop();
  7129. }
  7130. }
  7131. if (ImGui::CollapsingHeader("Filtering"))
  7132. {
  7133. static ImGuiTextFilter filter;
  7134. ImGui::Text("Filter usage:\n"
  7135. " \"\" display all lines\n"
  7136. " \"xxx\" display lines containing \"xxx\"\n"
  7137. " \"xxx,yyy\" display lines containing \"xxx\" or \"yyy\"\n"
  7138. " \"-xxx\" hide lines containing \"xxx\"");
  7139. filter.Draw();
  7140. const char* lines[] = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" };
  7141. for (size_t i = 0; i < IM_ARRAYSIZE(lines); i++)
  7142. if (filter.PassFilter(lines[i]))
  7143. ImGui::BulletText("%s", lines[i]);
  7144. }
  7145. if (ImGui::CollapsingHeader("Keyboard & Focus"))
  7146. {
  7147. if (ImGui::TreeNode("Tabbing"))
  7148. {
  7149. ImGui::Text("Use TAB/SHIFT+TAB to cycle thru keyboard editable fields.");
  7150. static char buf[32] = "dummy";
  7151. ImGui::InputText("1", buf, IM_ARRAYSIZE(buf));
  7152. ImGui::InputText("2", buf, IM_ARRAYSIZE(buf));
  7153. ImGui::InputText("3", buf, IM_ARRAYSIZE(buf));
  7154. ImGui::PushAllowKeyboardFocus(false);
  7155. ImGui::InputText("4 (tab skip)", buf, IM_ARRAYSIZE(buf));
  7156. //ImGui::SameLine(); ImGui::Text("(?)"); if (ImGui::IsHovered()) ImGui::SetTooltip("Use ImGui::PushAllowKeyboardFocus(bool)\nto disable tabbing through certain widgets.");
  7157. ImGui::PopAllowKeyboardFocus();
  7158. ImGui::InputText("5", buf, IM_ARRAYSIZE(buf));
  7159. ImGui::TreePop();
  7160. }
  7161. if (ImGui::TreeNode("Focus from code"))
  7162. {
  7163. bool focus_1 = ImGui::Button("Focus on 1"); ImGui::SameLine();
  7164. bool focus_2 = ImGui::Button("Focus on 2"); ImGui::SameLine();
  7165. bool focus_3 = ImGui::Button("Focus on 3");
  7166. int has_focus = 0;
  7167. static char buf[128] = "click on a button to set focus";
  7168. if (focus_1) ImGui::SetKeyboardFocusHere();
  7169. ImGui::InputText("1", buf, IM_ARRAYSIZE(buf));
  7170. if (ImGui::IsItemActive()) has_focus = 1;
  7171. if (focus_2) ImGui::SetKeyboardFocusHere();
  7172. ImGui::InputText("2", buf, IM_ARRAYSIZE(buf));
  7173. if (ImGui::IsItemActive()) has_focus = 2;
  7174. ImGui::PushAllowKeyboardFocus(false);
  7175. if (focus_3) ImGui::SetKeyboardFocusHere();
  7176. ImGui::InputText("3 (tab skip)", buf, IM_ARRAYSIZE(buf));
  7177. if (ImGui::IsItemActive()) has_focus = 3;
  7178. ImGui::PopAllowKeyboardFocus();
  7179. if (has_focus)
  7180. ImGui::Text("Item with focus: %d", has_focus);
  7181. else
  7182. ImGui::Text("Item with focus: <none>");
  7183. ImGui::TreePop();
  7184. }
  7185. }
  7186. static bool show_app_console = false;
  7187. static bool show_app_long_text = false;
  7188. static bool show_app_auto_resize = false;
  7189. static bool show_app_fixed_overlay = false;
  7190. static bool show_app_custom_rendering = false;
  7191. if (ImGui::CollapsingHeader("App Examples"))
  7192. {
  7193. ImGui::Checkbox("Console", &show_app_console);
  7194. ImGui::Checkbox("Long text display", &show_app_long_text);
  7195. ImGui::Checkbox("Auto-resizing window", &show_app_auto_resize);
  7196. ImGui::Checkbox("Simple overlay", &show_app_fixed_overlay);
  7197. ImGui::Checkbox("Custom rendering", &show_app_custom_rendering);
  7198. }
  7199. if (show_app_console)
  7200. ShowExampleAppConsole(&show_app_console);
  7201. if (show_app_long_text)
  7202. ShowExampleAppLongText(&show_app_long_text);
  7203. if (show_app_auto_resize)
  7204. ShowExampleAppAutoResize(&show_app_auto_resize);
  7205. if (show_app_fixed_overlay)
  7206. ShowExampleAppFixedOverlay(&show_app_fixed_overlay);
  7207. if (show_app_custom_rendering)
  7208. ShowExampleAppCustomRendering(&show_app_custom_rendering);
  7209. ImGui::End();
  7210. }
  7211. static void ShowExampleAppAutoResize(bool* opened)
  7212. {
  7213. if (!ImGui::Begin("Example: Auto-Resizing Window", opened, ImVec2(0,0), -1.0f, ImGuiWindowFlags_AlwaysAutoResize))
  7214. {
  7215. ImGui::End();
  7216. return;
  7217. }
  7218. static int lines = 10;
  7219. ImGui::TextWrapped("Window will resize every-frame to the size of its content. Note that you don't want to query the window size to output your content because that would create a feedback loop.");
  7220. ImGui::SliderInt("Number of lines", &lines, 1, 20);
  7221. for (int i = 0; i < lines; i++)
  7222. ImGui::Text("%*sThis is line %d", i*4, "", i); // Pad with space to extend size horizontally
  7223. ImGui::End();
  7224. }
  7225. static void ShowExampleAppFixedOverlay(bool* opened)
  7226. {
  7227. if (!ImGui::Begin("Example: Fixed Overlay", opened, ImVec2(0,0), 0.3f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoSavedSettings))
  7228. {
  7229. ImGui::End();
  7230. return;
  7231. }
  7232. ImGui::SetWindowPos(ImVec2(10,10));
  7233. ImGui::Text("Simple overlay\non the top-left side of the screen.");
  7234. ImGui::Separator();
  7235. ImGui::Text("Mouse Position: (%.1f,%.1f)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
  7236. ImGui::End();
  7237. }
  7238. static void ShowExampleAppCustomRendering(bool* opened)
  7239. {
  7240. if (!ImGui::Begin("Example: Custom Rendering", opened))
  7241. {
  7242. ImGui::End();
  7243. return;
  7244. }
  7245. // Tip: If you do a lot of custom rendering, you probably want to use your own geometrical types and benefit of overloaded operators, etc.
  7246. // Define IM_VEC2_CLASS_EXTRA in imconfig.h to create implicit conversions between your types and ImVec2/ImVec4.
  7247. // ImGui defines overloaded operators but they are internal to imgui.cpp and not exposed outside (to avoid messing with your types)
  7248. // In this example we aren't using the operators.
  7249. static ImVector<ImVec2> points;
  7250. static bool adding_line = false;
  7251. if (ImGui::Button("Clear")) points.clear();
  7252. if (points.size() > 2) { ImGui::SameLine(); if (ImGui::Button("Undo")) points.pop_back(); }
  7253. ImGui::Text("Left-click and drag to add lines");
  7254. ImGui::Text("Right-click to undo");
  7255. ImDrawList* draw_list = ImGui::GetWindowDrawList();
  7256. // Here we are using InvisibleButton() as a convenience to 1) advance the cursor and 2) allows us to use IsItemHovered()
  7257. // However you can draw directly and poll mouse/keyboard by yourself. You can manipulate the cursor using GetCursorPos() and SetCursorPos().
  7258. // If you only use the ImDrawList API, you can notify the owner window of its extends by using SetCursorPos(max) followed by an empty Text("") statement.
  7259. ImVec2 canvas_pos = ImGui::GetCursorScreenPos(); // ImDrawList API uses screen coordinates!
  7260. ImVec2 canvas_size = ImVec2(ImMax(50.0f,ImGui::GetWindowContentRegionMax().x-ImGui::GetCursorPos().x), ImMax(50.0f,ImGui::GetWindowContentRegionMax().y-ImGui::GetCursorPos().y)); // Resize canvas what's available
  7261. draw_list->AddRect(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), 0xFFFFFFFF);
  7262. bool adding_preview = false;
  7263. ImGui::InvisibleButton("canvas", canvas_size);
  7264. if (ImGui::IsItemHovered())
  7265. {
  7266. ImVec2 mouse_pos_in_canvas = ImVec2(ImGui::GetIO().MousePos.x - canvas_pos.x, ImGui::GetIO().MousePos.y - canvas_pos.y);
  7267. if (!adding_line && ImGui::GetIO().MouseClicked[0])
  7268. {
  7269. points.push_back(mouse_pos_in_canvas);
  7270. adding_line = true;
  7271. }
  7272. if (adding_line)
  7273. {
  7274. adding_preview = true;
  7275. points.push_back(mouse_pos_in_canvas);
  7276. if (!ImGui::GetIO().MouseDown[0])
  7277. adding_line = adding_preview = false;
  7278. }
  7279. if (ImGui::GetIO().MouseClicked[1] && !points.empty())
  7280. {
  7281. adding_line = false;
  7282. points.pop_back();
  7283. points.pop_back();
  7284. }
  7285. }
  7286. draw_list->PushClipRect(ImVec4(canvas_pos.x, canvas_pos.y, canvas_pos.x+canvas_size.x, canvas_pos.y+canvas_size.y)); // clip lines within the canvas (if we resize it, etc.)
  7287. for (int i = 0; i < (int)points.size() - 1; i += 2)
  7288. draw_list->AddLine(ImVec2(canvas_pos.x + points[i].x, canvas_pos.y + points[i].y), ImVec2(canvas_pos.x + points[i+1].x, canvas_pos.y + points[i+1].y), 0xFF00FFFF);
  7289. draw_list->PopClipRect();
  7290. if (adding_preview)
  7291. points.pop_back();
  7292. ImGui::End();
  7293. }
  7294. struct ExampleAppConsole
  7295. {
  7296. char InputBuf[256];
  7297. ImVector<char*> Items;
  7298. bool ScrollToBottom;
  7299. ImVector<char*> History;
  7300. int HistoryPos; // -1: new line, 0..History.size()-1 browsing history.
  7301. ImVector<const char*> Commands;
  7302. ExampleAppConsole()
  7303. {
  7304. ClearLog();
  7305. HistoryPos = -1;
  7306. Commands.push_back("HELP");
  7307. Commands.push_back("HISTORY");
  7308. Commands.push_back("CLEAR");
  7309. Commands.push_back("CLASSIFY"); // "classify" is here to provide an example of "C"+[tab] completing to "CL" and displaying matches.
  7310. }
  7311. ~ExampleAppConsole()
  7312. {
  7313. ClearLog();
  7314. for (size_t i = 0; i < Items.size(); i++)
  7315. ImGui::MemFree(History[i]);
  7316. }
  7317. void ClearLog()
  7318. {
  7319. for (size_t i = 0; i < Items.size(); i++)
  7320. ImGui::MemFree(Items[i]);
  7321. Items.clear();
  7322. ScrollToBottom = true;
  7323. }
  7324. void AddLog(const char* fmt, ...)
  7325. {
  7326. char buf[1024];
  7327. va_list args;
  7328. va_start(args, fmt);
  7329. ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args);
  7330. va_end(args);
  7331. Items.push_back(ImStrdup(buf));
  7332. ScrollToBottom = true;
  7333. }
  7334. void Run(const char* title, bool* opened)
  7335. {
  7336. if (!ImGui::Begin(title, opened, ImVec2(520,600)))
  7337. {
  7338. ImGui::End();
  7339. return;
  7340. }
  7341. ImGui::TextWrapped("This example implements a console with basic coloring, completion and history. A more elaborate implementation may want to store entries along with extra data such as timestamp, emitter, etc.");
  7342. ImGui::TextWrapped("Enter 'HELP' for help, press TAB to use text completion.");
  7343. // TODO: display from bottom
  7344. // TODO: clip manually
  7345. if (ImGui::SmallButton("Add Dummy Text")) AddLog("some text\nsome more text\ndisplay very important message here!\n"); ImGui::SameLine();
  7346. if (ImGui::SmallButton("Add Dummy Error")) AddLog("[error] something went wrong"); ImGui::SameLine();
  7347. if (ImGui::SmallButton("Clear")) ClearLog();
  7348. ImGui::Separator();
  7349. ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0));
  7350. static ImGuiTextFilter filter;
  7351. filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180);
  7352. if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover
  7353. ImGui::PopStyleVar();
  7354. ImGui::Separator();
  7355. // Display every line as a separate entry so we can change their color or add custom widgets. If you only want raw text you can use ImGui::TextUnformatted(log.begin(), log.end());
  7356. // NB- if you have lots of text this approach may be too inefficient. You can seek and display only the lines that are on display using a technique similar to what TextUnformatted() does,
  7357. // or faster if your entries are already stored into a table.
  7358. ImGui::BeginChild("ScrollingRegion", ImVec2(0,-ImGui::GetTextLineSpacing()*2));
  7359. ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4,1)); // Tighten spacing
  7360. for (size_t i = 0; i < Items.size(); i++)
  7361. {
  7362. const char* item = Items[i];
  7363. if (!filter.PassFilter(item))
  7364. continue;
  7365. ImVec4 col(1,1,1,1); // A better implement may store a type per-item. For the sample let's just parse the text.
  7366. if (strstr(item, "[error]")) col = ImVec4(1.0f,0.4f,0.4f,1.0f);
  7367. else if (strncmp(item, "# ", 2) == 0) col = ImVec4(1.0f,0.8f,0.6f,1.0f);
  7368. ImGui::PushStyleColor(ImGuiCol_Text, col);
  7369. ImGui::TextUnformatted(item);
  7370. ImGui::PopStyleColor();
  7371. }
  7372. if (ScrollToBottom)
  7373. ImGui::SetScrollPosHere();
  7374. ScrollToBottom = false;
  7375. ImGui::PopStyleVar();
  7376. ImGui::EndChild();
  7377. ImGui::Separator();
  7378. // Command-line
  7379. if (ImGui::InputText("Input", InputBuf, IM_ARRAYSIZE(InputBuf), ImGuiInputTextFlags_EnterReturnsTrue|ImGuiInputTextFlags_CallbackCompletion|ImGuiInputTextFlags_CallbackHistory, &TextEditCallbackStub, (void*)this))
  7380. {
  7381. char* input_end = InputBuf+strlen(InputBuf);
  7382. while (input_end > InputBuf && input_end[-1] == ' ') input_end--; *input_end = 0;
  7383. if (InputBuf[0])
  7384. ExecCommand(InputBuf);
  7385. strcpy(InputBuf, "");
  7386. }
  7387. if (ImGui::IsItemHovered()) ImGui::SetKeyboardFocusHere(-1); // Auto focus on hover
  7388. ImGui::End();
  7389. }
  7390. void ExecCommand(const char* command_line)
  7391. {
  7392. AddLog("# %s\n", command_line);
  7393. // Insert into history. First find match and delete it so it can be pushed to the back. This isn't trying to be smart or optimal.
  7394. HistoryPos = -1;
  7395. for (int i = (int)History.size()-1; i >= 0; i--)
  7396. if (ImStricmp(History[i], command_line) == 0)
  7397. {
  7398. ImGui::MemFree(History[i]);
  7399. History.erase(History.begin() + i);
  7400. break;
  7401. }
  7402. History.push_back(ImStrdup(command_line));
  7403. // Process command
  7404. if (ImStricmp(command_line, "CLEAR") == 0)
  7405. {
  7406. ClearLog();
  7407. }
  7408. else if (ImStricmp(command_line, "HELP") == 0)
  7409. {
  7410. AddLog("Commands:");
  7411. for (size_t i = 0; i < Commands.size(); i++)
  7412. AddLog("- %s", Commands[i]);
  7413. }
  7414. else if (ImStricmp(command_line, "HISTORY") == 0)
  7415. {
  7416. for (size_t i = History.size() >= 10 ? History.size() - 10 : 0; i < History.size(); i++)
  7417. AddLog("%3d: %s\n", i, History[i]);
  7418. }
  7419. else
  7420. {
  7421. AddLog("Unknown command: '%s'\n", command_line);
  7422. }
  7423. }
  7424. static void TextEditCallbackStub(ImGuiTextEditCallbackData* data)
  7425. {
  7426. ExampleAppConsole* console = (ExampleAppConsole*)data->UserData;
  7427. console->TextEditCallback(data);
  7428. }
  7429. void TextEditCallback(ImGuiTextEditCallbackData* data)
  7430. {
  7431. //AddLog("cursor: %d, selection: %d-%d", data->CursorPos, data->SelectionStart, data->SelectionEnd);
  7432. switch (data->EventKey)
  7433. {
  7434. case ImGuiKey_Tab:
  7435. {
  7436. // Example of TEXT COMPLETION
  7437. // Locate beginning of current word
  7438. const char* word_end = data->Buf + data->CursorPos;
  7439. const char* word_start = word_end;
  7440. while (word_start > data->Buf)
  7441. {
  7442. const char c = word_start[-1];
  7443. if (c == ' ' || c == '\t' || c == ',' || c == ';')
  7444. break;
  7445. word_start--;
  7446. }
  7447. // Build a list of candidates
  7448. ImVector<const char*> candidates;
  7449. for (size_t i = 0; i < Commands.size(); i++)
  7450. if (ImStrnicmp(Commands[i], word_start, (int)(word_end-word_start)) == 0)
  7451. candidates.push_back(Commands[i]);
  7452. if (candidates.size() == 0)
  7453. {
  7454. // No match
  7455. AddLog("No match for \"%.*s\"!\n", word_end-word_start, word_start);
  7456. }
  7457. else if (candidates.size() == 1)
  7458. {
  7459. // Single match. Delete the beginning of the word and replace it entirely so we've got nice casing
  7460. data->DeleteChars((int)(word_start-data->Buf), (int)(word_end-word_start));
  7461. data->InsertChars(data->CursorPos, candidates[0]);
  7462. data->InsertChars(data->CursorPos, " ");
  7463. }
  7464. else
  7465. {
  7466. // Multiple matches. Complete as much as we can, so inputing "C" will complete to "CL" and display "CLEAR" and "CLASSIFY"
  7467. int match_len = (int)(word_end - word_start);
  7468. for (;;)
  7469. {
  7470. int c = 0;
  7471. bool all_candidates_matches = true;
  7472. for (size_t i = 0; i < candidates.size() && all_candidates_matches; i++)
  7473. if (i == 0)
  7474. c = toupper(candidates[i][match_len]);
  7475. else if (c != toupper(candidates[i][match_len]))
  7476. all_candidates_matches = false;
  7477. if (!all_candidates_matches)
  7478. break;
  7479. match_len++;
  7480. }
  7481. if (match_len > 0)
  7482. {
  7483. data->DeleteChars((int)(word_start - data->Buf), (int)(word_end-word_start));
  7484. data->InsertChars(data->CursorPos, candidates[0], candidates[0] + match_len);
  7485. }
  7486. // List matches
  7487. AddLog("Possible matches:\n");
  7488. for (size_t i = 0; i < candidates.size(); i++)
  7489. AddLog("- %s\n", candidates[i]);
  7490. }
  7491. break;
  7492. }
  7493. case ImGuiKey_UpArrow:
  7494. case ImGuiKey_DownArrow:
  7495. {
  7496. // Example of HISTORY
  7497. const int prev_history_pos = HistoryPos;
  7498. if (data->EventKey == ImGuiKey_UpArrow)
  7499. {
  7500. if (HistoryPos == -1)
  7501. HistoryPos = (int)(History.size() - 1);
  7502. else if (HistoryPos > 0)
  7503. HistoryPos--;
  7504. }
  7505. else if (data->EventKey == ImGuiKey_DownArrow)
  7506. {
  7507. if (HistoryPos != -1)
  7508. if (++HistoryPos >= (int)History.size())
  7509. HistoryPos = -1;
  7510. }
  7511. // A better implementation would preserve the data on the current input line along with cursor position.
  7512. if (prev_history_pos != HistoryPos)
  7513. {
  7514. ImFormatString(data->Buf, data->BufSize, "%s", (HistoryPos >= 0) ? History[HistoryPos] : "");
  7515. data->BufDirty = true;
  7516. data->CursorPos = data->SelectionStart = data->SelectionEnd = (int)strlen(data->Buf);
  7517. }
  7518. }
  7519. }
  7520. }
  7521. };
  7522. static void ShowExampleAppConsole(bool* opened)
  7523. {
  7524. static ExampleAppConsole console;
  7525. console.Run("Example: Console", opened);
  7526. }
  7527. static void ShowExampleAppLongText(bool* opened)
  7528. {
  7529. if (!ImGui::Begin("Example: Long text display", opened, ImVec2(520,600)))
  7530. {
  7531. ImGui::End();
  7532. return;
  7533. }
  7534. static ImGuiTextBuffer log;
  7535. static int lines = 0;
  7536. ImGui::Text("Printing unusually long amount of text.");
  7537. ImGui::Text("Buffer contents: %d lines, %d bytes", lines, log.size());
  7538. if (ImGui::Button("Clear")) { log.clear(); lines = 0; }
  7539. ImGui::SameLine();
  7540. if (ImGui::Button("Add 1000 lines"))
  7541. {
  7542. for (int i = 0; i < 1000; i++)
  7543. log.append("%i The quick brown fox jumps over the lazy dog\n", lines+i);
  7544. lines += 1000;
  7545. }
  7546. ImGui::BeginChild("Log");
  7547. ImGui::TextUnformatted(log.begin(), log.end());
  7548. ImGui::EndChild();
  7549. ImGui::End();
  7550. }
  7551. // End of Sample code
  7552. //-----------------------------------------------------------------------------
  7553. // FONT DATA
  7554. //-----------------------------------------------------------------------------
  7555. //-----------------------------------------------------------------------------
  7556. // ProggyClean.ttf
  7557. // Copyright (c) 2004, 2005 Tristan Grimmer
  7558. // MIT license (see License.txt in http://www.upperbounds.net/download/ProggyClean.ttf.zip)
  7559. // Download and more information at http://upperbounds.net
  7560. //-----------------------------------------------------------------------------
  7561. // Compressed with stb_compress() then converted to a C array.
  7562. // Decompressor from stb.h (public domain) by Sean Barrett
  7563. // https://github.com/nothings/stb/blob/master/stb.h
  7564. //-----------------------------------------------------------------------------
  7565. static unsigned int stb_decompress_length(unsigned char *input)
  7566. {
  7567. return (input[8] << 24) + (input[9] << 16) + (input[10] << 8) + input[11];
  7568. }
  7569. static unsigned char *stb__barrier, *stb__barrier2, *stb__barrier3, *stb__barrier4;
  7570. static unsigned char *stb__dout;
  7571. static void stb__match(unsigned char *data, unsigned int length)
  7572. {
  7573. // INVERSE of memmove... write each byte before copying the next...
  7574. assert (stb__dout + length <= stb__barrier);
  7575. if (stb__dout + length > stb__barrier) { stb__dout += length; return; }
  7576. if (data < stb__barrier4) { stb__dout = stb__barrier+1; return; }
  7577. while (length--) *stb__dout++ = *data++;
  7578. }
  7579. static void stb__lit(unsigned char *data, unsigned int length)
  7580. {
  7581. assert (stb__dout + length <= stb__barrier);
  7582. if (stb__dout + length > stb__barrier) { stb__dout += length; return; }
  7583. if (data < stb__barrier2) { stb__dout = stb__barrier+1; return; }
  7584. memcpy(stb__dout, data, length);
  7585. stb__dout += length;
  7586. }
  7587. #define stb__in2(x) ((i[x] << 8) + i[(x)+1])
  7588. #define stb__in3(x) ((i[x] << 16) + stb__in2((x)+1))
  7589. #define stb__in4(x) ((i[x] << 24) + stb__in3((x)+1))
  7590. static unsigned char *stb_decompress_token(unsigned char *i)
  7591. {
  7592. if (*i >= 0x20) { // use fewer if's for cases that expand small
  7593. if (*i >= 0x80) stb__match(stb__dout-i[1]-1, i[0] - 0x80 + 1), i += 2;
  7594. else if (*i >= 0x40) stb__match(stb__dout-(stb__in2(0) - 0x4000 + 1), i[2]+1), i += 3;
  7595. else /* *i >= 0x20 */ stb__lit(i+1, i[0] - 0x20 + 1), i += 1 + (i[0] - 0x20 + 1);
  7596. } else { // more ifs for cases that expand large, since overhead is amortized
  7597. if (*i >= 0x18) stb__match(stb__dout-(stb__in3(0) - 0x180000 + 1), i[3]+1), i += 4;
  7598. else if (*i >= 0x10) stb__match(stb__dout-(stb__in3(0) - 0x100000 + 1), stb__in2(3)+1), i += 5;
  7599. else if (*i >= 0x08) stb__lit(i+2, stb__in2(0) - 0x0800 + 1), i += 2 + (stb__in2(0) - 0x0800 + 1);
  7600. else if (*i == 0x07) stb__lit(i+3, stb__in2(1) + 1), i += 3 + (stb__in2(1) + 1);
  7601. else if (*i == 0x06) stb__match(stb__dout-(stb__in3(1)+1), i[4]+1), i += 5;
  7602. else if (*i == 0x04) stb__match(stb__dout-(stb__in3(1)+1), stb__in2(4)+1), i += 6;
  7603. }
  7604. return i;
  7605. }
  7606. static unsigned int stb_adler32(unsigned int adler32, unsigned char *buffer, unsigned int buflen)
  7607. {
  7608. const unsigned long ADLER_MOD = 65521;
  7609. unsigned long s1 = adler32 & 0xffff, s2 = adler32 >> 16;
  7610. unsigned long blocklen, i;
  7611. blocklen = buflen % 5552;
  7612. while (buflen) {
  7613. for (i=0; i + 7 < blocklen; i += 8) {
  7614. s1 += buffer[0], s2 += s1;
  7615. s1 += buffer[1], s2 += s1;
  7616. s1 += buffer[2], s2 += s1;
  7617. s1 += buffer[3], s2 += s1;
  7618. s1 += buffer[4], s2 += s1;
  7619. s1 += buffer[5], s2 += s1;
  7620. s1 += buffer[6], s2 += s1;
  7621. s1 += buffer[7], s2 += s1;
  7622. buffer += 8;
  7623. }
  7624. for (; i < blocklen; ++i)
  7625. s1 += *buffer++, s2 += s1;
  7626. s1 %= ADLER_MOD, s2 %= ADLER_MOD;
  7627. buflen -= blocklen;
  7628. blocklen = 5552;
  7629. }
  7630. return (unsigned int)(s2 << 16) + (unsigned int)s1;
  7631. }
  7632. static unsigned int stb_decompress(unsigned char *output, unsigned char *i, unsigned int length)
  7633. {
  7634. unsigned int olen;
  7635. if (stb__in4(0) != 0x57bC0000) return 0;
  7636. if (stb__in4(4) != 0) return 0; // error! stream is > 4GB
  7637. olen = stb_decompress_length(i);
  7638. stb__barrier2 = i;
  7639. stb__barrier3 = i+length;
  7640. stb__barrier = output + olen;
  7641. stb__barrier4 = output;
  7642. i += 16;
  7643. stb__dout = output;
  7644. for (;;) {
  7645. unsigned char *old_i = i;
  7646. i = stb_decompress_token(i);
  7647. if (i == old_i) {
  7648. if (*i == 0x05 && i[1] == 0xfa) {
  7649. assert(stb__dout == output + olen);
  7650. if (stb__dout != output + olen) return 0;
  7651. if (stb_adler32(1, output, olen) != (unsigned int) stb__in4(2))
  7652. return 0;
  7653. return olen;
  7654. } else {
  7655. assert(0); /* NOTREACHED */
  7656. return 0;
  7657. }
  7658. }
  7659. assert(stb__dout <= output + olen);
  7660. if (stb__dout > output + olen)
  7661. return 0;
  7662. }
  7663. }
  7664. static const unsigned int proggy_clean_ttf_compressed_size = 9583;
  7665. static const unsigned int proggy_clean_ttf_compressed_data[9584/4] =
  7666. {
  7667. 0x0000bc57, 0x00000000, 0xf8a00000, 0x00000400, 0x00010037, 0x000c0000, 0x00030080, 0x2f534f40, 0x74eb8832, 0x01000090, 0x2c158248, 0x616d634e,
  7668. 0x23120270, 0x03000075, 0x241382a0, 0x74766352, 0x82178220, 0xfc042102, 0x02380482, 0x66796c67, 0x5689af12, 0x04070000, 0x80920000, 0x64616568,
  7669. 0xd36691d7, 0xcc201b82, 0x36210382, 0x27108268, 0xc3014208, 0x04010000, 0x243b0f82, 0x78746d68, 0x807e008a, 0x98010000, 0x06020000, 0x61636f6c,
  7670. 0xd8b0738c, 0x82050000, 0x0402291e, 0x7078616d, 0xda00ae01, 0x28201f82, 0x202c1082, 0x656d616e, 0x96bb5925, 0x84990000, 0x9e2c1382, 0x74736f70,
  7671. 0xef83aca6, 0x249b0000, 0xd22c3382, 0x70657270, 0x12010269, 0xf4040000, 0x08202f82, 0x012ecb84, 0x553c0000, 0x0f5fd5e9, 0x0300f53c, 0x00830008,
  7672. 0x7767b722, 0x002b3f82, 0xa692bd00, 0xfe0000d7, 0x83800380, 0x21f1826f, 0x00850002, 0x41820120, 0x40fec026, 0x80030000, 0x05821083, 0x07830120,
  7673. 0x0221038a, 0x24118200, 0x90000101, 0x82798200, 0x00022617, 0x00400008, 0x2009820a, 0x82098276, 0x82002006, 0x9001213b, 0x0223c883, 0x828a02bc,
  7674. 0x858f2010, 0xc5012507, 0x00023200, 0x04210083, 0x91058309, 0x6c412b03, 0x40007374, 0xac200000, 0x00830008, 0x01000523, 0x834d8380, 0x80032103,
  7675. 0x012101bf, 0x23b88280, 0x00800000, 0x0b830382, 0x07820120, 0x83800021, 0x88012001, 0x84002009, 0x2005870f, 0x870d8301, 0x2023901b, 0x83199501,
  7676. 0x82002015, 0x84802000, 0x84238267, 0x88002027, 0x8561882d, 0x21058211, 0x13880000, 0x01800022, 0x05850d85, 0x0f828020, 0x03208384, 0x03200582,
  7677. 0x47901b84, 0x1b850020, 0x1f821d82, 0x3f831d88, 0x3f410383, 0x84058405, 0x210982cd, 0x09830000, 0x03207789, 0xf38a1384, 0x01203782, 0x13872384,
  7678. 0x0b88c983, 0x0d898f84, 0x00202982, 0x23900383, 0x87008021, 0x83df8301, 0x86118d03, 0x863f880d, 0x8f35880f, 0x2160820f, 0x04830300, 0x1c220382,
  7679. 0x05820100, 0x4c000022, 0x09831182, 0x04001c24, 0x11823000, 0x0800082e, 0x00000200, 0xff007f00, 0xffffac20, 0x00220982, 0x09848100, 0xdf216682,
  7680. 0x843586d5, 0x06012116, 0x04400684, 0xa58120d7, 0x00b127d8, 0x01b88d01, 0x2d8685ff, 0xc100c621, 0xf4be0801, 0x9e011c01, 0x88021402, 0x1403fc02,
  7681. 0x9c035803, 0x1404de03, 0x50043204, 0xa2046204, 0x66051605, 0x1206bc05, 0xd6067406, 0x7e073807, 0x4e08ec07, 0x96086c08, 0x1009d008, 0x88094a09,
  7682. 0x800a160a, 0x560b040b, 0x2e0cc80b, 0xea0c820c, 0xa40d5e0d, 0x500eea0d, 0x280f960e, 0x1210b00f, 0xe0107410, 0xb6115211, 0x6e120412, 0x4c13c412,
  7683. 0xf613ac13, 0xae145814, 0x4015ea14, 0xa6158015, 0x1216b815, 0xc6167e16, 0x8e173417, 0x5618e017, 0xee18ba18, 0x96193619, 0x481ad419, 0xf01a9c1a,
  7684. 0xc81b5c1b, 0x4c1c041c, 0xea1c961c, 0x921d2a1d, 0x401ed21d, 0xe01e8e1e, 0x761f241f, 0xa61fa61f, 0x01821020, 0x8a202e34, 0xc820b220, 0x74211421,
  7685. 0xee219821, 0x86226222, 0x01820c23, 0x83238021, 0x23983c01, 0x24d823b0, 0x244a2400, 0x24902468, 0x250625ae, 0x25822560, 0x26f825f8, 0x82aa2658,
  7686. 0xd8be0801, 0x9a274027, 0x68280a28, 0x0e29a828, 0xb8292029, 0x362af829, 0x602a602a, 0x2a2b022b, 0xac2b5e2b, 0x202ce62b, 0x9a2c342c, 0x5c2d282d,
  7687. 0xaa2d782d, 0x262ee82d, 0x262fa62e, 0xf42fb62f, 0xc8305e30, 0xb4313e31, 0x9e321e32, 0x82331e33, 0x5c34ee33, 0x3a35ce34, 0xd4358635, 0x72362636,
  7688. 0x7637e636, 0x3a38d837, 0x1239a638, 0xae397439, 0x9a3a2e3a, 0x7c3b063b, 0x3a3ce83b, 0x223d963c, 0xec3d863d, 0xc63e563e, 0x9a3f2a3f, 0x6a401240,
  7689. 0x3641d040, 0x0842a241, 0x7a424042, 0xf042b842, 0xcc436243, 0x8a442a44, 0x5845ee44, 0xe245b645, 0xb4465446, 0x7a471447, 0x5448da47, 0x4049c648,
  7690. 0x15462400, 0x034d0808, 0x0b000700, 0x13000f00, 0x1b001700, 0x23001f00, 0x2b002700, 0x33002f00, 0x3b003700, 0x43003f00, 0x4b004700, 0x53004f00,
  7691. 0x5b005700, 0x63005f00, 0x6b006700, 0x73006f00, 0x7b007700, 0x83007f00, 0x8b008700, 0x00008f00, 0x15333511, 0x20039631, 0x20178205, 0xd3038221,
  7692. 0x20739707, 0x25008580, 0x028080fc, 0x05be8080, 0x04204a85, 0x05ce0685, 0x0107002a, 0x02000080, 0x00000400, 0x250d8b41, 0x33350100, 0x03920715,
  7693. 0x13820320, 0x858d0120, 0x0e8d0320, 0xff260d83, 0x00808000, 0x54820106, 0x04800223, 0x845b8c80, 0x41332059, 0x078b068f, 0x82000121, 0x82fe2039,
  7694. 0x84802003, 0x83042004, 0x23598a0e, 0x00180000, 0x03210082, 0x42ab9080, 0x73942137, 0x2013bb41, 0x8f978205, 0x2027a39b, 0x20b68801, 0x84b286fd,
  7695. 0x91c88407, 0x41032011, 0x11a51130, 0x15000027, 0x80ff8000, 0x11af4103, 0x841b0341, 0x8bd983fd, 0x9be99bc9, 0x8343831b, 0x21f1821f, 0xb58300ff,
  7696. 0x0f84e889, 0xf78a0484, 0x8000ff22, 0x0020eeb3, 0x14200082, 0x2130ef41, 0xeb431300, 0x4133200a, 0xd7410ecb, 0x9a07200b, 0x2027871b, 0x21238221,
  7697. 0xe7828080, 0xe784fd20, 0xe8848020, 0xfe808022, 0x08880d85, 0xba41fd20, 0x82248205, 0x85eab02a, 0x008022e7, 0x2cd74200, 0x44010021, 0xd34406eb,
  7698. 0x44312013, 0xcf8b0eef, 0x0d422f8b, 0x82332007, 0x0001212f, 0x8023cf82, 0x83000180, 0x820583de, 0x830682d4, 0x820020d4, 0x82dc850a, 0x20e282e9,
  7699. 0xb2ff85fe, 0x010327e9, 0x02000380, 0x0f440400, 0x0c634407, 0x68825982, 0x85048021, 0x260a825d, 0x010b0000, 0x4400ff00, 0x2746103f, 0x08d74209,
  7700. 0x4d440720, 0x0eaf4406, 0xc3441d20, 0x23078406, 0xff800002, 0x04845b83, 0x8d05b241, 0x1781436f, 0x6b8c87a5, 0x1521878e, 0x06474505, 0x01210783,
  7701. 0x84688c00, 0x8904828e, 0x441e8cf7, 0x0b270cff, 0x80008000, 0x45030003, 0xfb430fab, 0x080f4107, 0x410bf942, 0xd34307e5, 0x070d4207, 0x80800123,
  7702. 0x205d85fe, 0x849183fe, 0x20128404, 0x82809702, 0x00002217, 0x41839a09, 0x6b4408cf, 0x0733440f, 0x3b460720, 0x82798707, 0x97802052, 0x0000296f,
  7703. 0xff800004, 0x01800100, 0x0021ef89, 0x0a914625, 0x410a4d41, 0x00250ed4, 0x00050000, 0x056d4280, 0x210a7b46, 0x21481300, 0x46ed8512, 0x00210bd1,
  7704. 0x89718202, 0x21738877, 0x2b850001, 0x00220582, 0x87450a00, 0x0ddb4606, 0x41079b42, 0x9d420c09, 0x0b09420b, 0x8d820720, 0x9742fc84, 0x42098909,
  7705. 0x00241e0f, 0x00800014, 0x0b47da82, 0x0833442a, 0x49078d41, 0x2f450f13, 0x42278f17, 0x01200751, 0x22063742, 0x44808001, 0x20450519, 0x88068906,
  7706. 0x83fe2019, 0x4203202a, 0x1a941a58, 0x00820020, 0xe7a40e20, 0x420ce146, 0x854307e9, 0x0fcb4713, 0xff20a182, 0xfe209b82, 0x0c867f8b, 0x0021aea4,
  7707. 0x219fa40f, 0x7d41003b, 0x07194214, 0xbf440520, 0x071d4206, 0x6941a590, 0x80802309, 0x028900ff, 0xa9a4b685, 0xc5808021, 0x449b82ab, 0x152007eb,
  7708. 0x42134d46, 0x61440a15, 0x051e4208, 0x222b0442, 0x47001100, 0xfd412913, 0x17194714, 0x410f5b41, 0x02220773, 0x09428080, 0x21a98208, 0xd4420001,
  7709. 0x481c840d, 0x00232bc9, 0x42120000, 0xe74c261b, 0x149d4405, 0x07209d87, 0x410db944, 0x14421c81, 0x42fd2005, 0x80410bd2, 0x203d8531, 0x06874100,
  7710. 0x48256f4a, 0xcb420c95, 0x13934113, 0x44075d44, 0x044c0855, 0x00ff2105, 0xfe228185, 0x45448000, 0x22c5b508, 0x410c0000, 0x7b412087, 0x1bb74514,
  7711. 0x32429c85, 0x0a574805, 0x21208943, 0x8ba01300, 0x440dfb4e, 0x77431437, 0x245b4113, 0x200fb145, 0x41108ffe, 0x80203562, 0x00200082, 0x46362b42,
  7712. 0x1742178d, 0x4527830f, 0x0f830b2f, 0x4a138146, 0x802409a1, 0xfe8000ff, 0x94419982, 0x09294320, 0x04000022, 0x49050f4f, 0xcb470a63, 0x48032008,
  7713. 0x2b48067b, 0x85022008, 0x82638338, 0x00002209, 0x05af4806, 0x900e9f49, 0x84c5873f, 0x214285bd, 0x064900ff, 0x0c894607, 0x00000023, 0x4903820a,
  7714. 0x714319f3, 0x0749410c, 0x8a07a145, 0x02152507, 0xfe808000, 0x74490386, 0x8080211b, 0x0c276f82, 0x00018000, 0x48028003, 0x2b2315db, 0x43002f00,
  7715. 0x6f82142f, 0x44011521, 0x93510da7, 0x20e68508, 0x06494d80, 0x8e838020, 0x06821286, 0x124bff20, 0x25f3830c, 0x03800080, 0xe74a0380, 0x207b8715,
  7716. 0x876b861d, 0x4a152007, 0x07870775, 0xf6876086, 0x8417674a, 0x0a0021f2, 0x431c9743, 0x8d421485, 0x200b830b, 0x06474d03, 0x71828020, 0x04510120,
  7717. 0x42da8606, 0x1f831882, 0x001a0022, 0xff4d0082, 0x0b0f532c, 0x0d449b94, 0x4e312007, 0x074f12e7, 0x0bf3490b, 0xbb412120, 0x413f820a, 0xef490857,
  7718. 0x80002313, 0xe2830001, 0x6441fc20, 0x8b802006, 0x00012108, 0xfd201582, 0x492c9b48, 0x802014ff, 0x51084347, 0x0f4327f3, 0x17bf4a14, 0x201b7944,
  7719. 0x06964201, 0x134ffe20, 0x20d6830b, 0x25d78280, 0xfd800002, 0x05888000, 0x9318dc41, 0x21d282d4, 0xdb481800, 0x0dff542a, 0x45107743, 0xe14813f5,
  7720. 0x0f034113, 0x83135d45, 0x47b28437, 0xe4510e73, 0x21f58e06, 0x2b8400fd, 0x1041fcac, 0x08db4b0b, 0x421fdb41, 0xdf4b18df, 0x011d210a, 0x420af350,
  7721. 0x6e8308af, 0xac85cb86, 0x1e461082, 0x82b7a407, 0x411420a3, 0xa34130ab, 0x178f4124, 0x41139741, 0x86410d93, 0x82118511, 0x057243d8, 0x8941d9a4,
  7722. 0x3093480c, 0x4a13474f, 0xfb5016a9, 0x07ad4108, 0x4a0f9d42, 0xfe200fad, 0x4708aa41, 0x83482dba, 0x288f4d06, 0xb398c3bb, 0x44267b41, 0xb34439d7,
  7723. 0x0755410f, 0x200ebb45, 0x0f5f4215, 0x20191343, 0x06df5301, 0xf04c0220, 0x2ba64d07, 0x82050841, 0x430020ce, 0xa78f3627, 0x5213ff42, 0x2f970bc1,
  7724. 0x4305ab55, 0xa084111b, 0x450bac45, 0x5f4238b8, 0x010c2106, 0x0220ed82, 0x441bb344, 0x875010af, 0x0737480f, 0x490c5747, 0x0c840c03, 0x4c204b42,
  7725. 0x8ba905d7, 0x8b948793, 0x510c0c51, 0xfb4b24b9, 0x1b174107, 0x5709d74c, 0xd1410ca5, 0x079d480f, 0x201ff541, 0x06804780, 0x7d520120, 0x80002205,
  7726. 0x20a983fe, 0x47bb83fe, 0x1b8409b4, 0x81580220, 0x4e00202c, 0x4f41282f, 0x0eab4f17, 0x57471520, 0x0e0f4808, 0x8221e041, 0x3e1b4a8b, 0x4407175d,
  7727. 0x1b4b071f, 0x4a0f8b07, 0x174a0703, 0x0ba5411b, 0x430fb141, 0x0120057b, 0xfc20dd82, 0x4a056047, 0xf4850c0c, 0x01221982, 0x02828000, 0x1a5d088b,
  7728. 0x20094108, 0x8c0e3941, 0x4900200e, 0x7744434f, 0x200b870b, 0x0e4b5a33, 0x2b41f78b, 0x8b138307, 0x0b9f450b, 0x2406f741, 0xfd808001, 0x09475a00,
  7729. 0x84000121, 0x5980200e, 0x85450e5d, 0x832c8206, 0x4106831e, 0x00213814, 0x28b34810, 0x410c2f4b, 0x5f4a13d7, 0x0b2b4113, 0x6e43a883, 0x11174b05,
  7730. 0x4b066a45, 0xcc470541, 0x5000202b, 0xcb472f4b, 0x44b59f0f, 0xc5430b5b, 0x0d654907, 0x21065544, 0xd6828080, 0xfe201982, 0x8230ec4a, 0x120025c2,
  7731. 0x80ff8000, 0x4128d74d, 0x3320408b, 0x410a9f50, 0xdb822793, 0x822bd454, 0x61134b2e, 0x410b214a, 0xad4117c9, 0x0001211f, 0x4206854f, 0x4b430596,
  7732. 0x06bb5530, 0x2025cf46, 0x0ddd5747, 0x500ea349, 0x0f840fa7, 0x5213c153, 0x634e08d1, 0x0bbe4809, 0x59316e4d, 0x5b50053f, 0x203f6323, 0x5117eb46,
  7733. 0x94450a63, 0x246e410a, 0x63410020, 0x0bdb5f2f, 0x4233ab44, 0x39480757, 0x112d4a07, 0x7241118f, 0x000e2132, 0x9f286f41, 0x0f8762c3, 0x33350723,
  7734. 0x094e6415, 0x2010925f, 0x067252fe, 0xd0438020, 0x63a68225, 0x11203a4f, 0x480e6360, 0x5748131f, 0x079b521f, 0x200e2f43, 0x864b8315, 0x113348e7,
  7735. 0x85084e48, 0x06855008, 0x5880fd21, 0x7c420925, 0x0c414824, 0x37470c86, 0x1b8b422b, 0x5b0a8755, 0x23410c21, 0x0b83420b, 0x5a082047, 0xf482067f,
  7736. 0xa80b4c47, 0x0c0021cf, 0x20207b42, 0x0fb74100, 0x420b8744, 0xeb43076f, 0x0f6f420b, 0x4261fe20, 0x439aa00c, 0x215034e3, 0x0ff9570f, 0x4b1f2d5d,
  7737. 0x2d5d0c6f, 0x09634d0b, 0x1f51b8a0, 0x620f200c, 0xaf681e87, 0x24f94d07, 0x4e0f4945, 0xfe200c05, 0x22139742, 0x57048080, 0x23950c20, 0x97601585,
  7738. 0x4813201f, 0xad620523, 0x200f8f0f, 0x9e638f15, 0x00002181, 0x41342341, 0x0f930f0b, 0x210b4b62, 0x978f0001, 0xfe200f84, 0x8425c863, 0x2704822b,
  7739. 0x80000a00, 0x00038001, 0x610e9768, 0x834514bb, 0x0bc3430f, 0x2107e357, 0x80848080, 0x4400fe21, 0x2e410983, 0x00002a1a, 0x00000700, 0x800380ff,
  7740. 0x0fdf5800, 0x59150021, 0xd142163d, 0x0c02410c, 0x01020025, 0x65800300, 0x00240853, 0x1d333501, 0x15220382, 0x35420001, 0x44002008, 0x376406d7,
  7741. 0x096f6b19, 0x480bc142, 0x8f4908a7, 0x211f8b1f, 0x9e830001, 0x0584fe20, 0x4180fd21, 0x11850910, 0x8d198259, 0x000021d4, 0x5a08275d, 0x275d1983,
  7742. 0x06d9420e, 0x9f08b36a, 0x0f7d47b5, 0x8d8a2f8b, 0x4c0e0b57, 0xe7410e17, 0x42d18c1a, 0xb351087a, 0x1ac36505, 0x4b4a2f20, 0x0b9f450d, 0x430beb53,
  7743. 0xa7881015, 0xa5826a83, 0x80200f82, 0x86185a65, 0x4100208e, 0x176c3367, 0x0fe7650b, 0x4a17ad4b, 0x0f4217ed, 0x112e4206, 0x41113a42, 0xf7423169,
  7744. 0x0cb34737, 0x560f8b46, 0xa75407e5, 0x5f01200f, 0x31590c48, 0x80802106, 0x42268841, 0x0020091e, 0x4207ef64, 0x69461df7, 0x138d4114, 0x820f5145,
  7745. 0x53802090, 0xff200529, 0xb944b183, 0x417e8505, 0x00202561, 0x15210082, 0x42378200, 0x9b431cc3, 0x004f220d, 0x0dd54253, 0x4213f149, 0x7d41133b,
  7746. 0x42c9870b, 0x802010f9, 0x420b2c42, 0x8f441138, 0x267c4408, 0x600cb743, 0x8f4109d3, 0x05ab701d, 0x83440020, 0x3521223f, 0x0b794733, 0xfb62fe20,
  7747. 0x4afd2010, 0xaf410ae7, 0x25ce8525, 0x01080000, 0x7b6b0000, 0x0973710b, 0x82010021, 0x49038375, 0x33420767, 0x052c4212, 0x58464b85, 0x41fe2005,
  7748. 0x50440c27, 0x000c2209, 0x1cb36b80, 0x9b06df44, 0x0f93566f, 0x52830220, 0xfe216e8d, 0x200f8200, 0x0fb86704, 0xb057238d, 0x050b5305, 0x7217eb47,
  7749. 0xbd410b6b, 0x0f214610, 0x871f9956, 0x1e91567e, 0x2029b741, 0x20008200, 0x18b7410a, 0x27002322, 0x41095543, 0x0f8f0fb3, 0x41000121, 0x889d111c,
  7750. 0x14207b82, 0x00200382, 0x73188761, 0x475013a7, 0x6e33200c, 0x234e0ea3, 0x9b138313, 0x08e54d17, 0x9711094e, 0x2ee74311, 0x4908875e, 0xd75d1f1f,
  7751. 0x19ab5238, 0xa2084d48, 0x63a7a9b3, 0x55450b83, 0x0fd74213, 0x440d814c, 0x4f481673, 0x05714323, 0x13000022, 0x412e1f46, 0xdf493459, 0x21c7550f,
  7752. 0x8408215f, 0x201d49cb, 0xb1103043, 0x0f0d65d7, 0x452b8d41, 0x594b0f8d, 0x0b004605, 0xb215eb46, 0x000a24d7, 0x47000080, 0x002118cf, 0x06436413,
  7753. 0x420bd750, 0x2b500743, 0x076a470c, 0x4105c050, 0xd942053f, 0x0d00211a, 0x5f44779c, 0x0ce94805, 0x51558186, 0x14a54c0b, 0x49082b41, 0x0a4b0888,
  7754. 0x8080261f, 0x0d000000, 0x20048201, 0x1deb6a03, 0x420cb372, 0x07201783, 0x4306854d, 0x8b830c59, 0x59093c74, 0x0020250f, 0x67070f4a, 0x2341160b,
  7755. 0x00372105, 0x431c515d, 0x554e17ef, 0x0e5d6b05, 0x41115442, 0xb74a1ac1, 0x2243420a, 0x5b4f878f, 0x7507200f, 0x384b086f, 0x09d45409, 0x0020869a,
  7756. 0x12200082, 0xab460382, 0x10075329, 0x54138346, 0xaf540fbf, 0x1ea75413, 0x9a0c9e54, 0x0f6b44c1, 0x41000021, 0x47412a4f, 0x07374907, 0x5310bf76,
  7757. 0xff2009b4, 0x9a09a64c, 0x8200208d, 0x34c34500, 0x970fe141, 0x1fd74b0f, 0x440a3850, 0x206411f0, 0x27934609, 0x470c5d41, 0x555c2947, 0x1787540f,
  7758. 0x6e0f234e, 0x7d540a1b, 0x1d736b08, 0x0026a088, 0x80000e00, 0x9b5200ff, 0x08ef4318, 0x450bff77, 0x1d4d0b83, 0x081f7006, 0xcb691b86, 0x4b022008,
  7759. 0xc34b0b33, 0x1d0d4a0c, 0x8025a188, 0x0b000000, 0x52a38201, 0xbf7d0873, 0x0c234511, 0x8f0f894a, 0x4101200f, 0x0c880c9d, 0x2b418ea1, 0x06c74128,
  7760. 0x66181341, 0x7b4c0bb9, 0x0c06630b, 0xfe200c87, 0x9ba10882, 0x27091765, 0x01000008, 0x02800380, 0x48113f4e, 0x29430cf5, 0x09a75a0b, 0x31618020,
  7761. 0x6d802009, 0x61840e33, 0x8208bf51, 0x0c637d61, 0x7f092379, 0x4f470f4b, 0x1797510c, 0x46076157, 0xf5500fdf, 0x0f616910, 0x1171fe20, 0x82802006,
  7762. 0x08696908, 0x41127a4c, 0x3f4a15f3, 0x01042607, 0x0200ff00, 0x1cf77700, 0xff204185, 0x00235b8d, 0x43100000, 0x3b22243f, 0x3b4d3f00, 0x0b937709,
  7763. 0xad42f18f, 0x0b1f420f, 0x51084b43, 0x8020104a, 0xb557ff83, 0x052b7f2a, 0x0280ff22, 0x250beb78, 0x00170013, 0xbf6d2500, 0x07db760e, 0x410e2b7f,
  7764. 0x00230e4f, 0x49030000, 0x0582055b, 0x07000326, 0x00000b00, 0x580bcd46, 0x00200cdd, 0x57078749, 0x8749160f, 0x0f994f0a, 0x41134761, 0x01200b31,
  7765. 0xeb796883, 0x0b41500b, 0x0e90b38e, 0x202e7b51, 0x05d95801, 0x41080570, 0x1d530fc9, 0x0b937a0f, 0xaf8eb387, 0xf743b98f, 0x07c74227, 0x80000523,
  7766. 0x0fcb4503, 0x430ca37b, 0x7782077f, 0x8d0a9947, 0x08af4666, 0xeb798020, 0x6459881e, 0xc3740bbf, 0x0feb6f0b, 0x20072748, 0x052b6102, 0x435e0584,
  7767. 0x7d088308, 0x03200afd, 0x92109e41, 0x28aa8210, 0x80001500, 0x80030000, 0x0fdb5805, 0x209f4018, 0xa7418d87, 0x0aa3440f, 0x20314961, 0x073a52ff,
  7768. 0x6108505d, 0x43181051, 0x00223457, 0xe7820500, 0x50028021, 0x81410d33, 0x063d7108, 0xdb41af84, 0x4d888205, 0x00201198, 0x463d835f, 0x152106d7,
  7769. 0x0a355a33, 0x6917614e, 0x75411f4d, 0x184b8b07, 0x1809c344, 0x21091640, 0x0b828000, 0x42808021, 0x26790519, 0x86058605, 0x2428422d, 0x22123b42,
  7770. 0x42000080, 0xf587513b, 0x7813677b, 0xaf4d139f, 0x00ff210c, 0x5e0a1d57, 0x3b421546, 0x01032736, 0x02000380, 0x41180480, 0x2f420f07, 0x0c624807,
  7771. 0x00000025, 0x18000103, 0x83153741, 0x430120c3, 0x042106b2, 0x088d4d00, 0x2f830620, 0x1810434a, 0x18140345, 0x8507fb41, 0x5ee582ea, 0x0023116c,
  7772. 0x8d000600, 0x053b56af, 0xa6554fa2, 0x0d704608, 0x40180d20, 0x47181a43, 0xd37b07ff, 0x0b79500c, 0x420fd745, 0x47450bd9, 0x8471830a, 0x095a777e,
  7773. 0x84137542, 0x82002013, 0x2f401800, 0x0007213b, 0x4405e349, 0x0d550ff3, 0x16254c0c, 0x820ffe4a, 0x0400218a, 0x89066f41, 0x106b414f, 0xc84d0120,
  7774. 0x80802206, 0x0c9a4b03, 0x00100025, 0x68000200, 0x9d8c2473, 0x44134344, 0xf36a0f33, 0x4678860f, 0x1b440a25, 0x41988c0a, 0x80201879, 0x43079b5e,
  7775. 0x4a18080b, 0x0341190b, 0x1259530c, 0x43251552, 0x908205c8, 0x0cac4018, 0x86000421, 0x0e504aa2, 0x0020b891, 0xfb450082, 0x51132014, 0x8f5205f3,
  7776. 0x35052108, 0x8505cb59, 0x0f6d4f70, 0x82150021, 0x29af5047, 0x4f004b24, 0x75795300, 0x1b595709, 0x460b6742, 0xbf4b0f0d, 0x5743870b, 0xcb6d1461,
  7777. 0x08f64505, 0x4e05ab6c, 0x334126c3, 0x0bcb6b0d, 0x1811034d, 0x4111ef4b, 0x814f1ce5, 0x20af8227, 0x07fd7b80, 0x41188e84, 0xef410f33, 0x80802429,
  7778. 0x410d0000, 0xa34205ab, 0x76b7881c, 0xff500b89, 0x0741430f, 0x20086f4a, 0x209d8200, 0x234c18fd, 0x05d4670a, 0x4509af51, 0x9642078d, 0x189e831d,
  7779. 0x7c1cc74b, 0xcd4c07b9, 0x0e7c440f, 0x8b7b0320, 0x21108210, 0xc76c8080, 0x03002106, 0x6b23bf41, 0xc549060b, 0x7946180b, 0x0ff7530f, 0x17ad4618,
  7780. 0x200ecd45, 0x208c83fd, 0x5e0488fe, 0x032009c6, 0x420d044e, 0x0d8f0d7f, 0x00820020, 0x18001021, 0x6d273b45, 0xfd4c0c93, 0xcf451813, 0x0fe5450f,
  7781. 0x5a47c382, 0x820a8b0a, 0x282b4998, 0x410a8b5b, 0x4b232583, 0x54004f00, 0x978f0ce3, 0x500f1944, 0xa95f1709, 0x0280220b, 0x05ba7080, 0xa1530682,
  7782. 0x06324c13, 0x91412582, 0x05536e2c, 0x63431020, 0x0f434706, 0x8c11374c, 0x176143d7, 0x4d0f454c, 0xd3680bed, 0x0bee4d17, 0x212b9a41, 0x0f530a00,
  7783. 0x140d531c, 0x43139143, 0x95610e8d, 0x0f094415, 0x4205fb56, 0x1b4205cf, 0x17015225, 0x5e0c477f, 0xaf6e0aeb, 0x0ff36218, 0x04849a84, 0x0a454218,
  7784. 0x9c430420, 0x23c6822b, 0x04000102, 0x45091b4b, 0xf05f0955, 0x82802007, 0x421c2023, 0x5218282b, 0x7b53173f, 0x0fe7480c, 0x74173b7f, 0x47751317,
  7785. 0x634d1807, 0x0f6f430f, 0x24086547, 0xfc808002, 0x0b3c7f80, 0x10840120, 0x188d1282, 0x20096b43, 0x0fc24403, 0x00260faf, 0x0180000b, 0x3f500280,
  7786. 0x18002019, 0x450b4941, 0xf3530fb9, 0x18002010, 0x8208a551, 0x06234d56, 0xcb58a39b, 0xc3421805, 0x1313461e, 0x0f855018, 0xd34b0120, 0x6cfe2008,
  7787. 0x574f0885, 0x09204114, 0x07000029, 0x00008000, 0x44028002, 0x01420f57, 0x10c95c10, 0x11184c18, 0x80221185, 0x7f421e00, 0x00732240, 0x09cd4977,
  7788. 0x6d0b2b42, 0x4f180f8f, 0x8f5a0bcb, 0x9b0f830f, 0x0fb9411f, 0x230b5756, 0x00fd8080, 0x82060745, 0x000121d5, 0x8e0fb277, 0x4a8d4211, 0x24061c53,
  7789. 0x04000007, 0x12275280, 0x430c954c, 0x80201545, 0x200f764f, 0x20008200, 0x20ce8308, 0x09534f02, 0x660edf64, 0x73731771, 0xe7411807, 0x20a2820c,
  7790. 0x13b64404, 0x8f5d6682, 0x1d6b4508, 0x0cff4d18, 0x3348c58f, 0x0fc34c07, 0x31558b84, 0x8398820f, 0x17514712, 0x240b0e46, 0x80000a00, 0x093b4502,
  7791. 0x420f9759, 0xa54c0bf1, 0x0f2b470c, 0x410d314b, 0x2584170c, 0x73b30020, 0xb55fe782, 0x204d8410, 0x08e043fe, 0x4f147e41, 0x022008ab, 0x4b055159,
  7792. 0x2950068f, 0x00022208, 0x48511880, 0x82002009, 0x00112300, 0x634dff00, 0x24415f27, 0x180f6d43, 0x4d0b5d45, 0x4d5f05ef, 0x01802317, 0x56188000,
  7793. 0xa7840807, 0xc6450220, 0x21ca8229, 0x4b781a00, 0x3359182c, 0x0cf3470f, 0x180bef46, 0x420b0354, 0xff470b07, 0x4515200a, 0x9758239b, 0x4a80200c,
  7794. 0xd2410a26, 0x05fb4a08, 0x4b05e241, 0x03200dc9, 0x92290941, 0x00002829, 0x00010900, 0x5b020001, 0x23201363, 0x460d776a, 0xef530fdb, 0x209a890c,
  7795. 0x13fc4302, 0x00008024, 0xc4820104, 0x08820220, 0x20086b5b, 0x18518700, 0x8408d349, 0x0da449a1, 0x00080024, 0x7b690280, 0x4c438b1a, 0x01220f63,
  7796. 0x4c878000, 0x5c149c53, 0xfb430868, 0x2f56181e, 0x0ccf7b1b, 0x0f075618, 0x2008e347, 0x14144104, 0x00207f83, 0x00207b82, 0x201adf47, 0x16c35a13,
  7797. 0x540fdf47, 0x802006c8, 0x5418f185, 0x29430995, 0x00002419, 0x58001600, 0x5720316f, 0x4d051542, 0x4b7b1b03, 0x138f4707, 0xb747b787, 0x4aab8213,
  7798. 0x058305fc, 0x20115759, 0x82128401, 0x0a0b44e8, 0x46800121, 0xe64210d0, 0x82129312, 0x4bffdffe, 0x3b41171b, 0x9b27870f, 0x808022ff, 0x085c68fe,
  7799. 0x41800021, 0x01410b20, 0x001a213a, 0x47480082, 0x11374e12, 0x56130b4c, 0xdf4b0c65, 0x0b0f590b, 0x0f574c18, 0x830feb4b, 0x075f480f, 0x480b4755,
  7800. 0x40490b73, 0x80012206, 0x09d74280, 0x80fe8022, 0x80210e86, 0x056643ff, 0x10820020, 0x420b2646, 0x0b58391a, 0xd74c1808, 0x078b4e22, 0x2007f55f,
  7801. 0x4b491807, 0x83802017, 0x65aa82a7, 0x3152099e, 0x068b7616, 0x9b431220, 0x09bb742c, 0x500e376c, 0x8342179b, 0x0a4d5d0f, 0x8020a883, 0x180cd349,
  7802. 0x2016bb4b, 0x14476004, 0x84136c43, 0x08cf7813, 0x4f4c0520, 0x156f420f, 0x20085f42, 0x6fd3be03, 0xd4d30803, 0xa7411420, 0x004b222c, 0x0d3b614f,
  7803. 0x3f702120, 0x1393410a, 0x8f132745, 0x47421827, 0x41e08209, 0xb05e2bb9, 0x18b7410c, 0x18082647, 0x4107a748, 0xeb8826bf, 0x0ca76018, 0x733ecb41,
  7804. 0xd0410d83, 0x43ebaf2a, 0x0420067f, 0x721dab4c, 0x472005bb, 0x4105d341, 0x334844cb, 0x20dba408, 0x47d6ac00, 0x034e3aef, 0x0f8f421b, 0x930f134d,
  7805. 0x3521231f, 0xb7421533, 0x42f5ad0a, 0x1e961eaa, 0x17000022, 0x4c367b50, 0x7d491001, 0x0bf5520f, 0x4c18fda7, 0xb8460c55, 0x83fe2005, 0x00fe25b9,
  7806. 0x80000180, 0x9e751085, 0x261b5c12, 0x82110341, 0x001123fb, 0x4518fe80, 0xf38c2753, 0x6d134979, 0x295107a7, 0xaf5f180f, 0x0fe3660c, 0x180b6079,
  7807. 0x2007bd5f, 0x9aab9103, 0x2f4d1811, 0x05002109, 0x44254746, 0x1d200787, 0x450bab75, 0x4f180f57, 0x4f181361, 0x3b831795, 0xeb4b0120, 0x0b734805,
  7808. 0x84078f48, 0x2e1b47bc, 0x00203383, 0xaf065f45, 0x831520d7, 0x130f51a7, 0x1797bf97, 0x2b47d783, 0x18fe2005, 0x4a18a44f, 0xa64d086d, 0x1ab0410d,
  7809. 0x6205a258, 0xdbab069f, 0x4f06f778, 0xa963081d, 0x133b670a, 0x8323d141, 0x13195b23, 0x530f5e70, 0xe5ad0824, 0x58001421, 0x1f472b4b, 0x47bf410c,
  7810. 0x82000121, 0x83fe20cb, 0x07424404, 0x68068243, 0xd7ad0d3d, 0x00010d26, 0x80020000, 0x4a1c6f43, 0x23681081, 0x10a14f13, 0x8a070e57, 0x430a848f,
  7811. 0x7372243e, 0x4397a205, 0xb56c1021, 0x43978f0f, 0x64180505, 0x99aa0ff2, 0x0e000022, 0x20223341, 0x094b4f37, 0x074a3320, 0x2639410a, 0xfe208e84,
  7812. 0x8b0e0048, 0x508020a3, 0x9e4308fe, 0x073f4115, 0xe3480420, 0x0c9b5f1b, 0x7c137743, 0x9a95185b, 0x6122b148, 0x979b08df, 0x0fe36c18, 0x48109358,
  7813. 0x23441375, 0x0ffd5c0b, 0x180fc746, 0x2011d157, 0x07e95702, 0x58180120, 0x18770ac3, 0x51032008, 0x7d4118e3, 0x80802315, 0x3b4c1900, 0xbb5a1830,
  7814. 0x0ceb6109, 0x5b0b3d42, 0x4f181369, 0x4f180b8d, 0x4f180f75, 0x355a1b81, 0x200d820d, 0x18e483fd, 0x4528854f, 0x89420846, 0x1321411f, 0x44086b60,
  7815. 0x07421d77, 0x107d4405, 0x4113fd41, 0x5a181bf1, 0x4f180db3, 0x8021128f, 0x20f68280, 0x44a882fe, 0x334d249a, 0x052f6109, 0x1520c3a7, 0xef4eb783,
  7816. 0x4ec39b1b, 0xc4c90ee7, 0x20060b4d, 0x256f4905, 0x4d0cf761, 0xcf9b1f13, 0xa213d74e, 0x0e1145d4, 0x50135b42, 0xcb4e398f, 0x20d79f27, 0x08865d80,
  7817. 0x186d5018, 0xa90f7142, 0x067342d7, 0x3f450420, 0x65002021, 0xe3560771, 0x24d38f23, 0x15333531, 0x0eb94d01, 0x451c9f41, 0x384322fb, 0x00092108,
  7818. 0x19af6b18, 0x6e0c6f5a, 0xbd770bfb, 0x22bb7718, 0x20090f57, 0x25e74204, 0x4207275a, 0xdb5408ef, 0x1769450f, 0x1b1b5518, 0x210b1f57, 0x5e4c8001,
  7819. 0x55012006, 0x802107f1, 0x0a306a80, 0x45808021, 0x0d850b88, 0x31744f18, 0x1808ec54, 0x2009575b, 0x45ffa505, 0x1b420c73, 0x180f9f0f, 0x4a0cf748,
  7820. 0x501805b2, 0x00210f40, 0x4d118f80, 0xd6823359, 0x072b5118, 0x314ad7aa, 0x8fc79f08, 0x45d78b1f, 0xfe20058f, 0x23325118, 0x7b54d9b5, 0x9fc38f46,
  7821. 0x10bb410f, 0x41077b42, 0xc1410faf, 0x27cf441d, 0x46051b4f, 0x04200683, 0x2121d344, 0x8f530043, 0x8fcf9f0e, 0x21df8c1f, 0x50188000, 0x5d180e52,
  7822. 0xfd201710, 0x4405c341, 0xd68528e3, 0x20071f6b, 0x1b734305, 0x6b080957, 0x7d422b1f, 0x67002006, 0x7f8317b1, 0x2024cb48, 0x08676e00, 0x8749a39b,
  7823. 0x18132006, 0x410a6370, 0x8f490b47, 0x7e1f8f13, 0x551805c3, 0x4c180915, 0xfe200e2f, 0x244d5d18, 0x270bcf44, 0xff000019, 0x04800380, 0x5f253342,
  7824. 0xff520df7, 0x13274c18, 0x5542dd93, 0x0776181b, 0xf94a1808, 0x084a4c0c, 0x4308ea5b, 0xde831150, 0x7900fd21, 0x00492c1e, 0x060f4510, 0x17410020,
  7825. 0x0ce74526, 0x6206b341, 0x1f561083, 0x9d6c181b, 0x08a0500e, 0x112e4118, 0x60000421, 0xbf901202, 0x4408e241, 0xc7ab0513, 0xb40f0950, 0x055943c7,
  7826. 0x4f18ff20, 0xc9ae1cad, 0x32b34f18, 0x7a180120, 0x3d520a05, 0x53d1b40a, 0x80200813, 0x1b815018, 0x832bf86f, 0x67731847, 0x297f4308, 0x6418d54e,
  7827. 0x734213f7, 0x056b4b27, 0xdba5fe20, 0x1828aa4e, 0x2031a370, 0x06cb6101, 0x2040ad41, 0x07365300, 0x2558d985, 0x83fe200c, 0x0380211c, 0x542c4743,
  7828. 0x052006b7, 0x6021df45, 0x897b0707, 0x18d3c010, 0x20090e70, 0x1d5843ff, 0x540a0e44, 0x002126c5, 0x322f7416, 0x636a5720, 0x0f317409, 0x610fe159,
  7829. 0x294617e7, 0x08555213, 0x2006a75d, 0x6cec84fd, 0xfb5907be, 0x3a317405, 0x83808021, 0x180f20ea, 0x4626434a, 0x531818e3, 0xdb59172d, 0x0cbb460c,
  7830. 0x2013d859, 0x18b94502, 0x8f46188d, 0x77521842, 0x0a184e38, 0x9585fd20, 0x6a180684, 0xc64507e9, 0x51cbb230, 0xd3440cf3, 0x17ff6a0f, 0x450f5b42,
  7831. 0x276407c1, 0x4853180a, 0x21ccb010, 0xcf580013, 0x0c15442d, 0x410a1144, 0x1144359d, 0x5cfe2006, 0xa1410a43, 0x2bb64519, 0x2f5b7618, 0xb512b745,
  7832. 0x0cfd6fd1, 0x42089f59, 0xb8450c70, 0x0000232d, 0x50180900, 0xb9491ae3, 0x0fc37610, 0x01210f83, 0x0f3b4100, 0xa01b2742, 0x0ccd426f, 0x6e8f6f94,
  7833. 0x9c808021, 0xc7511870, 0x17c74b08, 0x9b147542, 0x44fe2079, 0xd5480c7e, 0x95ef861d, 0x101b597b, 0xf5417594, 0x9f471808, 0x86868d0e, 0x3733491c,
  7834. 0x690f4d6d, 0x43440b83, 0x1ba94c0b, 0x660cd16b, 0x802008ae, 0x74126448, 0xcb4f38a3, 0x2cb74b0b, 0x47137755, 0xe3971777, 0x1b5d0120, 0x057a4108,
  7835. 0x6e08664d, 0x17421478, 0x11af4208, 0x850c3f42, 0x08234f0c, 0x4321eb4a, 0xf3451095, 0x0f394e0f, 0x4310eb45, 0xc09707b1, 0x54431782, 0xaec08d1d,
  7836. 0x0f434dbb, 0x9f0c0b45, 0x0a3b4dbb, 0x4618bdc7, 0x536032eb, 0x17354213, 0x4d134169, 0xc7a30c2f, 0x4e254342, 0x174332cf, 0x43cdae17, 0x6b4706e4,
  7837. 0x0e16430d, 0x530b5542, 0x2f7c26bb, 0x13075f31, 0x43175342, 0x60181317, 0x6550114e, 0x28624710, 0x58070021, 0x59181683, 0x2d540cf5, 0x05d5660c,
  7838. 0x20090c7b, 0x0e157e02, 0x8000ff2b, 0x14000080, 0x80ff8000, 0x27137e03, 0x336a4b20, 0x0f817107, 0x13876e18, 0x730f2f7e, 0x2f450b75, 0x6d02200b,
  7839. 0x6d66094c, 0x4b802009, 0x15820a02, 0x2f45fe20, 0x5e032006, 0x00202fd9, 0x450af741, 0xeb412e0f, 0x0ff3411f, 0x420a8b65, 0xf7410eae, 0x1c664810,
  7840. 0x540e1145, 0xbfa509f3, 0x42302f58, 0x80200c35, 0xcb066c47, 0x4b1120c1, 0x41492abb, 0x34854110, 0xa7097b72, 0x251545c7, 0x4b2c7f56, 0xc5b40bab,
  7841. 0x940cd54e, 0x2e6151c8, 0x09f35f18, 0x4b420420, 0x09677121, 0x8f24f357, 0x1b5418e1, 0x08915a1f, 0x3143d894, 0x22541805, 0x1b9b4b0e, 0x8c0d3443,
  7842. 0x1400240d, 0x18ff8000, 0x582e6387, 0xf99b2b3b, 0x8807a550, 0x17a14790, 0x2184fd20, 0x5758fe20, 0x2354882c, 0x15000080, 0x5e056751, 0x334c2c2f,
  7843. 0x97c58f0c, 0x1fd7410f, 0x0d4d4018, 0x4114dc41, 0x04470ed6, 0x0dd54128, 0x00820020, 0x02011523, 0x22008700, 0x86480024, 0x0001240a, 0x8682001a,
  7844. 0x0002240b, 0x866c000e, 0x8a03200b, 0x8a042017, 0x0005220b, 0x22218614, 0x84060000, 0x86012017, 0x8212200f, 0x250b8519, 0x000d0001, 0x0b850031,
  7845. 0x07000224, 0x0b862600, 0x11000324, 0x0b862d00, 0x238a0420, 0x0a000524, 0x17863e00, 0x17840620, 0x01000324, 0x57820904, 0x0b85a783, 0x0b85a785,
  7846. 0x0b85a785, 0x22000325, 0x85007a00, 0x85a7850b, 0x85a7850b, 0x22a7850b, 0x82300032, 0x00342201, 0x0805862f, 0x35003131, 0x54207962, 0x74736972,
  7847. 0x47206e61, 0x6d6d6972, 0x65527265, 0x616c7567, 0x58545472, 0x6f725020, 0x43796767, 0x6e61656c, 0x30325454, 0x822f3430, 0x35313502, 0x79006200,
  7848. 0x54002000, 0x69007200, 0x74007300, 0x6e006100, 0x47200f82, 0x6d240f84, 0x65006d00, 0x52200982, 0x67240582, 0x6c007500, 0x72201d82, 0x54222b82,
  7849. 0x23825800, 0x19825020, 0x67006f22, 0x79220182, 0x1b824300, 0x3b846520, 0x1f825420, 0x41000021, 0x1422099b, 0x0b410000, 0x87088206, 0x01012102,
  7850. 0x78080982, 0x01020101, 0x01040103, 0x01060105, 0x01080107, 0x010a0109, 0x010c010b, 0x010e010d, 0x0110010f, 0x01120111, 0x01140113, 0x01160115,
  7851. 0x01180117, 0x011a0119, 0x011c011b, 0x011e011d, 0x0020011f, 0x00040003, 0x00060005, 0x00080007, 0x000a0009, 0x000c000b, 0x000e000d, 0x0010000f,
  7852. 0x00120011, 0x00140013, 0x00160015, 0x00180017, 0x001a0019, 0x001c001b, 0x001e001d, 0x08bb821f, 0x22002142, 0x24002300, 0x26002500, 0x28002700,
  7853. 0x2a002900, 0x2c002b00, 0x2e002d00, 0x30002f00, 0x32003100, 0x34003300, 0x36003500, 0x38003700, 0x3a003900, 0x3c003b00, 0x3e003d00, 0x40003f00,
  7854. 0x42004100, 0x4b09f382, 0x00450044, 0x00470046, 0x00490048, 0x004b004a, 0x004d004c, 0x004f004e, 0x00510050, 0x00530052, 0x00550054, 0x00570056,
  7855. 0x00590058, 0x005b005a, 0x005d005c, 0x005f005e, 0x01610060, 0x01220121, 0x01240123, 0x01260125, 0x01280127, 0x012a0129, 0x012c012b, 0x012e012d,
  7856. 0x0130012f, 0x01320131, 0x01340133, 0x01360135, 0x01380137, 0x013a0139, 0x013c013b, 0x013e013d, 0x0140013f, 0x00ac0041, 0x008400a3, 0x00bd0085,
  7857. 0x00e80096, 0x008e0086, 0x009d008b, 0x00a400a9, 0x008a00ef, 0x008300da, 0x00f20093, 0x008d00f3, 0x00880097, 0x00de00c3, 0x009e00f1, 0x00f500aa,
  7858. 0x00f600f4, 0x00ad00a2, 0x00c700c9, 0x006200ae, 0x00900063, 0x00cb0064, 0x00c80065, 0x00cf00ca, 0x00cd00cc, 0x00e900ce, 0x00d30066, 0x00d100d0,
  7859. 0x006700af, 0x009100f0, 0x00d400d6, 0x006800d5, 0x00ed00eb, 0x006a0089, 0x006b0069, 0x006c006d, 0x00a0006e, 0x0071006f, 0x00720070, 0x00750073,
  7860. 0x00760074, 0x00ea0077, 0x007a0078, 0x007b0079, 0x007c007d, 0x00a100b8, 0x007e007f, 0x00810080, 0x00ee00ec, 0x6e750eba, 0x646f6369, 0x78302365,
  7861. 0x31303030, 0x32200e8d, 0x33200e8d, 0x34200e8d, 0x35200e8d, 0x36200e8d, 0x37200e8d, 0x38200e8d, 0x39200e8d, 0x61200e8d, 0x62200e8d, 0x63200e8d,
  7862. 0x64200e8d, 0x65200e8d, 0x66200e8d, 0x31210e8c, 0x8d0e8d30, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef,
  7863. 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x8d3120ef, 0x66312def, 0x6c656406, 0x04657465, 0x6f727545, 0x3820ec8c, 0x3820ec8d,
  7864. 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d, 0x3820ec8d,
  7865. 0x3820ec8d, 0x200ddc41, 0x0ddc4139, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920,
  7866. 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0xef8d3920, 0x00663923, 0x48fa0500, 0x00f762f9,
  7867. };
  7868. static void GetDefaultCompressedFontDataTTF(const void** ttf_compressed_data, unsigned int* ttf_compressed_size)
  7869. {
  7870. *ttf_compressed_data = proggy_clean_ttf_compressed_data;
  7871. *ttf_compressed_size = proggy_clean_ttf_compressed_size;
  7872. }
  7873. //-----------------------------------------------------------------------------
  7874. //---- Include imgui_user.inl at the end of imgui.cpp
  7875. //---- So you can include code that extends ImGui using its private data/functions.
  7876. #ifdef IMGUI_INCLUDE_IMGUI_USER_INL
  7877. #include "imgui_user.inl"
  7878. #endif
  7879. //-----------------------------------------------------------------------------