2
0

imgui_draw.cpp 313 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309
  1. // dear imgui, v1.92.2 WIP
  2. // (drawing and font code)
  3. /*
  4. Index of this file:
  5. // [SECTION] STB libraries implementation
  6. // [SECTION] Style functions
  7. // [SECTION] ImDrawList
  8. // [SECTION] ImTriangulator, ImDrawList concave polygon fill
  9. // [SECTION] ImDrawListSplitter
  10. // [SECTION] ImDrawData
  11. // [SECTION] Helpers ShadeVertsXXX functions
  12. // [SECTION] ImFontConfig
  13. // [SECTION] ImFontAtlas, ImFontAtlasBuilder
  14. // [SECTION] ImFontAtlas: backend for stb_truetype
  15. // [SECTION] ImFontAtlas: glyph ranges helpers
  16. // [SECTION] ImFontGlyphRangesBuilder
  17. // [SECTION] ImFont
  18. // [SECTION] ImGui Internal Render Helpers
  19. // [SECTION] Decompression code
  20. // [SECTION] Default font data (ProggyClean.ttf)
  21. */
  22. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  23. #define _CRT_SECURE_NO_WARNINGS
  24. #endif
  25. #ifndef IMGUI_DEFINE_MATH_OPERATORS
  26. #define IMGUI_DEFINE_MATH_OPERATORS
  27. #endif
  28. #include "imgui.h"
  29. #ifndef IMGUI_DISABLE
  30. #include "imgui_internal.h"
  31. #ifdef IMGUI_ENABLE_FREETYPE
  32. #include "misc/freetype/imgui_freetype.h"
  33. #endif
  34. #include <stdio.h> // vsnprintf, sscanf, printf
  35. #include <stdint.h> // intptr_t
  36. // Visual Studio warnings
  37. #ifdef _MSC_VER
  38. #pragma warning (disable: 4127) // condition expression is constant
  39. #pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
  40. #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
  41. #pragma warning (disable: 26451) // [Static Analyzer] Arithmetic overflow : Using operator 'xxx' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator 'xxx' to avoid overflow(io.2).
  42. #pragma warning (disable: 26812) // [Static Analyzer] The enum type 'xxx' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). [MSVC Static Analyzer)
  43. #endif
  44. // Clang/GCC warnings with -Weverything
  45. #if defined(__clang__)
  46. #if __has_warning("-Wunknown-warning-option")
  47. #pragma clang diagnostic ignored "-Wunknown-warning-option" // warning: unknown warning group 'xxx' // not all warnings are known by all Clang versions and they tend to be rename-happy.. so ignoring warnings triggers new warnings on some configuration. Great!
  48. #endif
  49. #pragma clang diagnostic ignored "-Wunknown-pragmas" // warning: unknown warning group 'xxx'
  50. #pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast // yes, they are more terse.
  51. #pragma clang diagnostic ignored "-Wfloat-equal" // warning: comparing floating point with == or != is unsafe // storing and comparing against same constants ok.
  52. #pragma clang diagnostic ignored "-Wglobal-constructors" // warning: declaration requires a global destructor // similar to above, not sure what the exact difference is.
  53. #pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness
  54. #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" // warning: zero as null pointer constant // some standard header variations use #define NULL 0
  55. #pragma clang diagnostic ignored "-Wcomma" // warning: possible misuse of comma operator here
  56. #pragma clang diagnostic ignored "-Wreserved-id-macro" // warning: macro name is a reserved identifier
  57. #pragma clang diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function // using printf() is a misery with this as C++ va_arg ellipsis changes float to double.
  58. #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision
  59. #pragma clang diagnostic ignored "-Wreserved-identifier" // warning: identifier '_Xxx' is reserved because it starts with '_' followed by a capital letter
  60. #pragma clang diagnostic ignored "-Wunsafe-buffer-usage" // warning: 'xxx' is an unsafe pointer used for buffer access
  61. #pragma clang diagnostic ignored "-Wnontrivial-memaccess" // warning: first argument in call to 'memset' is a pointer to non-trivially copyable type
  62. #pragma clang diagnostic ignored "-Wcast-qual" // warning: cast from 'const xxxx *' to 'xxx *' drops const qualifier
  63. #pragma clang diagnostic ignored "-Wswitch-default" // warning: 'switch' missing 'default' label
  64. #elif defined(__GNUC__)
  65. #pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
  66. #pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used
  67. #pragma GCC diagnostic ignored "-Wfloat-equal" // warning: comparing floating-point with '==' or '!=' is unsafe
  68. #pragma GCC diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function
  69. #pragma GCC diagnostic ignored "-Wconversion" // warning: conversion to 'xxxx' from 'xxxx' may alter its value
  70. #pragma GCC diagnostic ignored "-Wstack-protector" // warning: stack protector not protecting local variables: variable length buffer
  71. #pragma GCC diagnostic ignored "-Wstrict-overflow" // warning: assuming signed overflow does not occur when simplifying division / ..when changing X +- C1 cmp C2 to X cmp C2 -+ C1
  72. #pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead
  73. #pragma GCC diagnostic ignored "-Wcast-qual" // warning: cast from type 'const xxxx *' to type 'xxxx *' casts away qualifiers
  74. #endif
  75. //-------------------------------------------------------------------------
  76. // [SECTION] STB libraries implementation (for stb_truetype and stb_rect_pack)
  77. //-------------------------------------------------------------------------
  78. // Compile time options:
  79. //#define IMGUI_STB_NAMESPACE ImStb
  80. //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
  81. //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
  82. //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
  83. //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
  84. #ifdef IMGUI_STB_NAMESPACE
  85. namespace IMGUI_STB_NAMESPACE
  86. {
  87. #endif
  88. #ifdef _MSC_VER
  89. #pragma warning (push)
  90. #pragma warning (disable: 4456) // declaration of 'xx' hides previous local declaration
  91. #pragma warning (disable: 6011) // (stb_rectpack) Dereferencing NULL pointer 'cur->next'.
  92. #pragma warning (disable: 6385) // (stb_truetype) Reading invalid data from 'buffer': the readable size is '_Old_3`kernel_width' bytes, but '3' bytes may be read.
  93. #pragma warning (disable: 28182) // (stb_rectpack) Dereferencing NULL pointer. 'cur' contains the same NULL value as 'cur->next' did.
  94. #endif
  95. #if defined(__clang__)
  96. #pragma clang diagnostic push
  97. #pragma clang diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used
  98. #pragma clang diagnostic ignored "-Wmissing-prototypes"
  99. #pragma clang diagnostic ignored "-Wimplicit-fallthrough"
  100. #endif
  101. #if defined(__GNUC__)
  102. #pragma GCC diagnostic push
  103. #pragma GCC diagnostic ignored "-Wtype-limits" // warning: comparison is always true due to limited range of data type [-Wtype-limits]
  104. #pragma GCC diagnostic ignored "-Wimplicit-fallthrough" // warning: this statement may fall through
  105. #endif
  106. #ifndef STB_RECT_PACK_IMPLEMENTATION // in case the user already have an implementation in the _same_ compilation unit (e.g. unity builds)
  107. #ifndef IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION // in case the user already have an implementation in another compilation unit
  108. #define STBRP_STATIC
  109. #define STBRP_ASSERT(x) do { IM_ASSERT(x); } while (0)
  110. #define STBRP_SORT ImQsort
  111. #define STB_RECT_PACK_IMPLEMENTATION
  112. #endif
  113. #ifdef IMGUI_STB_RECT_PACK_FILENAME
  114. #include IMGUI_STB_RECT_PACK_FILENAME
  115. #else
  116. #include "imstb_rectpack.h"
  117. #endif
  118. #endif
  119. #ifdef IMGUI_ENABLE_STB_TRUETYPE
  120. #ifndef STB_TRUETYPE_IMPLEMENTATION // in case the user already have an implementation in the _same_ compilation unit (e.g. unity builds)
  121. #ifndef IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION // in case the user already have an implementation in another compilation unit
  122. #define STBTT_malloc(x,u) ((void)(u), IM_ALLOC(x))
  123. #define STBTT_free(x,u) ((void)(u), IM_FREE(x))
  124. #define STBTT_assert(x) do { IM_ASSERT(x); } while(0)
  125. #define STBTT_fmod(x,y) ImFmod(x,y)
  126. #define STBTT_sqrt(x) ImSqrt(x)
  127. #define STBTT_pow(x,y) ImPow(x,y)
  128. #define STBTT_fabs(x) ImFabs(x)
  129. #define STBTT_ifloor(x) ((int)ImFloor(x))
  130. #define STBTT_iceil(x) ((int)ImCeil(x))
  131. #define STBTT_strlen(x) ImStrlen(x)
  132. #define STBTT_STATIC
  133. #define STB_TRUETYPE_IMPLEMENTATION
  134. #else
  135. #define STBTT_DEF extern
  136. #endif
  137. #ifdef IMGUI_STB_TRUETYPE_FILENAME
  138. #include IMGUI_STB_TRUETYPE_FILENAME
  139. #else
  140. #include "imstb_truetype.h"
  141. #endif
  142. #endif
  143. #endif // IMGUI_ENABLE_STB_TRUETYPE
  144. #if defined(__GNUC__)
  145. #pragma GCC diagnostic pop
  146. #endif
  147. #if defined(__clang__)
  148. #pragma clang diagnostic pop
  149. #endif
  150. #if defined(_MSC_VER)
  151. #pragma warning (pop)
  152. #endif
  153. #ifdef IMGUI_STB_NAMESPACE
  154. } // namespace ImStb
  155. using namespace IMGUI_STB_NAMESPACE;
  156. #endif
  157. //-----------------------------------------------------------------------------
  158. // [SECTION] Style functions
  159. //-----------------------------------------------------------------------------
  160. void ImGui::StyleColorsDark(ImGuiStyle* dst)
  161. {
  162. ImGuiStyle* style = dst ? dst : &ImGui::GetStyle();
  163. ImVec4* colors = style->Colors;
  164. colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
  165. colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
  166. colors[ImGuiCol_WindowBg] = ImVec4(0.06f, 0.06f, 0.06f, 0.94f);
  167. colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
  168. colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
  169. colors[ImGuiCol_Border] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f);
  170. colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
  171. colors[ImGuiCol_FrameBg] = ImVec4(0.16f, 0.29f, 0.48f, 0.54f);
  172. colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f);
  173. colors[ImGuiCol_FrameBgActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
  174. colors[ImGuiCol_TitleBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f);
  175. colors[ImGuiCol_TitleBgActive] = ImVec4(0.16f, 0.29f, 0.48f, 1.00f);
  176. colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f);
  177. colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
  178. colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f);
  179. colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f);
  180. colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
  181. colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.51f, 0.51f, 0.51f, 1.00f);
  182. colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
  183. colors[ImGuiCol_SliderGrab] = ImVec4(0.24f, 0.52f, 0.88f, 1.00f);
  184. colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
  185. colors[ImGuiCol_Button] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f);
  186. colors[ImGuiCol_ButtonHovered] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
  187. colors[ImGuiCol_ButtonActive] = ImVec4(0.06f, 0.53f, 0.98f, 1.00f);
  188. colors[ImGuiCol_Header] = ImVec4(0.26f, 0.59f, 0.98f, 0.31f);
  189. colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f);
  190. colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
  191. colors[ImGuiCol_Separator] = colors[ImGuiCol_Border];
  192. colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.40f, 0.75f, 0.78f);
  193. colors[ImGuiCol_SeparatorActive] = ImVec4(0.10f, 0.40f, 0.75f, 1.00f);
  194. colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.20f);
  195. colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
  196. colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
  197. colors[ImGuiCol_InputTextCursor] = colors[ImGuiCol_Text];
  198. colors[ImGuiCol_TabHovered] = colors[ImGuiCol_HeaderHovered];
  199. colors[ImGuiCol_Tab] = ImLerp(colors[ImGuiCol_Header], colors[ImGuiCol_TitleBgActive], 0.80f);
  200. colors[ImGuiCol_TabSelected] = ImLerp(colors[ImGuiCol_HeaderActive], colors[ImGuiCol_TitleBgActive], 0.60f);
  201. colors[ImGuiCol_TabSelectedOverline] = colors[ImGuiCol_HeaderActive];
  202. colors[ImGuiCol_TabDimmed] = ImLerp(colors[ImGuiCol_Tab], colors[ImGuiCol_TitleBg], 0.80f);
  203. colors[ImGuiCol_TabDimmedSelected] = ImLerp(colors[ImGuiCol_TabSelected], colors[ImGuiCol_TitleBg], 0.40f);
  204. colors[ImGuiCol_TabDimmedSelectedOverline] = ImVec4(0.50f, 0.50f, 0.50f, 0.00f);
  205. colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
  206. colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
  207. colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  208. colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
  209. colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.20f, 1.00f);
  210. colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f); // Prefer using Alpha=1.0 here
  211. colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f); // Prefer using Alpha=1.0 here
  212. colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
  213. colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f);
  214. colors[ImGuiCol_TextLink] = colors[ImGuiCol_HeaderActive];
  215. colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
  216. colors[ImGuiCol_TreeLines] = colors[ImGuiCol_Border];
  217. colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
  218. colors[ImGuiCol_NavCursor] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
  219. colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
  220. colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
  221. colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
  222. }
  223. void ImGui::StyleColorsClassic(ImGuiStyle* dst)
  224. {
  225. ImGuiStyle* style = dst ? dst : &ImGui::GetStyle();
  226. ImVec4* colors = style->Colors;
  227. colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
  228. colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
  229. colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.85f);
  230. colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
  231. colors[ImGuiCol_PopupBg] = ImVec4(0.11f, 0.11f, 0.14f, 0.92f);
  232. colors[ImGuiCol_Border] = ImVec4(0.50f, 0.50f, 0.50f, 0.50f);
  233. colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
  234. colors[ImGuiCol_FrameBg] = ImVec4(0.43f, 0.43f, 0.43f, 0.39f);
  235. colors[ImGuiCol_FrameBgHovered] = ImVec4(0.47f, 0.47f, 0.69f, 0.40f);
  236. colors[ImGuiCol_FrameBgActive] = ImVec4(0.42f, 0.41f, 0.64f, 0.69f);
  237. colors[ImGuiCol_TitleBg] = ImVec4(0.27f, 0.27f, 0.54f, 0.83f);
  238. colors[ImGuiCol_TitleBgActive] = ImVec4(0.32f, 0.32f, 0.63f, 0.87f);
  239. colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.40f, 0.40f, 0.80f, 0.20f);
  240. colors[ImGuiCol_MenuBarBg] = ImVec4(0.40f, 0.40f, 0.55f, 0.80f);
  241. colors[ImGuiCol_ScrollbarBg] = ImVec4(0.20f, 0.25f, 0.30f, 0.60f);
  242. colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.40f, 0.40f, 0.80f, 0.30f);
  243. colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.80f, 0.40f);
  244. colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.41f, 0.39f, 0.80f, 0.60f);
  245. colors[ImGuiCol_CheckMark] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f);
  246. colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f);
  247. colors[ImGuiCol_SliderGrabActive] = ImVec4(0.41f, 0.39f, 0.80f, 0.60f);
  248. colors[ImGuiCol_Button] = ImVec4(0.35f, 0.40f, 0.61f, 0.62f);
  249. colors[ImGuiCol_ButtonHovered] = ImVec4(0.40f, 0.48f, 0.71f, 0.79f);
  250. colors[ImGuiCol_ButtonActive] = ImVec4(0.46f, 0.54f, 0.80f, 1.00f);
  251. colors[ImGuiCol_Header] = ImVec4(0.40f, 0.40f, 0.90f, 0.45f);
  252. colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.90f, 0.80f);
  253. colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.53f, 0.87f, 0.80f);
  254. colors[ImGuiCol_Separator] = ImVec4(0.50f, 0.50f, 0.50f, 0.60f);
  255. colors[ImGuiCol_SeparatorHovered] = ImVec4(0.60f, 0.60f, 0.70f, 1.00f);
  256. colors[ImGuiCol_SeparatorActive] = ImVec4(0.70f, 0.70f, 0.90f, 1.00f);
  257. colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.10f);
  258. colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.78f, 0.82f, 1.00f, 0.60f);
  259. colors[ImGuiCol_ResizeGripActive] = ImVec4(0.78f, 0.82f, 1.00f, 0.90f);
  260. colors[ImGuiCol_InputTextCursor] = colors[ImGuiCol_Text];
  261. colors[ImGuiCol_TabHovered] = colors[ImGuiCol_HeaderHovered];
  262. colors[ImGuiCol_Tab] = ImLerp(colors[ImGuiCol_Header], colors[ImGuiCol_TitleBgActive], 0.80f);
  263. colors[ImGuiCol_TabSelected] = ImLerp(colors[ImGuiCol_HeaderActive], colors[ImGuiCol_TitleBgActive], 0.60f);
  264. colors[ImGuiCol_TabSelectedOverline] = colors[ImGuiCol_HeaderActive];
  265. colors[ImGuiCol_TabDimmed] = ImLerp(colors[ImGuiCol_Tab], colors[ImGuiCol_TitleBg], 0.80f);
  266. colors[ImGuiCol_TabDimmedSelected] = ImLerp(colors[ImGuiCol_TabSelected], colors[ImGuiCol_TitleBg], 0.40f);
  267. colors[ImGuiCol_TabDimmedSelectedOverline] = ImVec4(0.53f, 0.53f, 0.87f, 0.00f);
  268. colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
  269. colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  270. colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  271. colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
  272. colors[ImGuiCol_TableHeaderBg] = ImVec4(0.27f, 0.27f, 0.38f, 1.00f);
  273. colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.45f, 1.00f); // Prefer using Alpha=1.0 here
  274. colors[ImGuiCol_TableBorderLight] = ImVec4(0.26f, 0.26f, 0.28f, 1.00f); // Prefer using Alpha=1.0 here
  275. colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
  276. colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.07f);
  277. colors[ImGuiCol_TextLink] = colors[ImGuiCol_HeaderActive];
  278. colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f);
  279. colors[ImGuiCol_TreeLines] = colors[ImGuiCol_Border];
  280. colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
  281. colors[ImGuiCol_NavCursor] = colors[ImGuiCol_HeaderHovered];
  282. colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
  283. colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
  284. colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
  285. }
  286. // Those light colors are better suited with a thicker font than the default one + FrameBorder
  287. void ImGui::StyleColorsLight(ImGuiStyle* dst)
  288. {
  289. ImGuiStyle* style = dst ? dst : &ImGui::GetStyle();
  290. ImVec4* colors = style->Colors;
  291. colors[ImGuiCol_Text] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
  292. colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
  293. colors[ImGuiCol_WindowBg] = ImVec4(0.94f, 0.94f, 0.94f, 1.00f);
  294. colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
  295. colors[ImGuiCol_PopupBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.98f);
  296. colors[ImGuiCol_Border] = ImVec4(0.00f, 0.00f, 0.00f, 0.30f);
  297. colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
  298. colors[ImGuiCol_FrameBg] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
  299. colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f);
  300. colors[ImGuiCol_FrameBgActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
  301. colors[ImGuiCol_TitleBg] = ImVec4(0.96f, 0.96f, 0.96f, 1.00f);
  302. colors[ImGuiCol_TitleBgActive] = ImVec4(0.82f, 0.82f, 0.82f, 1.00f);
  303. colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 1.00f, 1.00f, 0.51f);
  304. colors[ImGuiCol_MenuBarBg] = ImVec4(0.86f, 0.86f, 0.86f, 1.00f);
  305. colors[ImGuiCol_ScrollbarBg] = ImVec4(0.98f, 0.98f, 0.98f, 0.53f);
  306. colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.69f, 0.69f, 0.69f, 0.80f);
  307. colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.49f, 0.49f, 0.49f, 0.80f);
  308. colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.49f, 0.49f, 0.49f, 1.00f);
  309. colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
  310. colors[ImGuiCol_SliderGrab] = ImVec4(0.26f, 0.59f, 0.98f, 0.78f);
  311. colors[ImGuiCol_SliderGrabActive] = ImVec4(0.46f, 0.54f, 0.80f, 0.60f);
  312. colors[ImGuiCol_Button] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f);
  313. colors[ImGuiCol_ButtonHovered] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
  314. colors[ImGuiCol_ButtonActive] = ImVec4(0.06f, 0.53f, 0.98f, 1.00f);
  315. colors[ImGuiCol_Header] = ImVec4(0.26f, 0.59f, 0.98f, 0.31f);
  316. colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f);
  317. colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
  318. colors[ImGuiCol_Separator] = ImVec4(0.39f, 0.39f, 0.39f, 0.62f);
  319. colors[ImGuiCol_SeparatorHovered] = ImVec4(0.14f, 0.44f, 0.80f, 0.78f);
  320. colors[ImGuiCol_SeparatorActive] = ImVec4(0.14f, 0.44f, 0.80f, 1.00f);
  321. colors[ImGuiCol_ResizeGrip] = ImVec4(0.35f, 0.35f, 0.35f, 0.17f);
  322. colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
  323. colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
  324. colors[ImGuiCol_InputTextCursor] = colors[ImGuiCol_Text];
  325. colors[ImGuiCol_TabHovered] = colors[ImGuiCol_HeaderHovered];
  326. colors[ImGuiCol_Tab] = ImLerp(colors[ImGuiCol_Header], colors[ImGuiCol_TitleBgActive], 0.90f);
  327. colors[ImGuiCol_TabSelected] = ImLerp(colors[ImGuiCol_HeaderActive], colors[ImGuiCol_TitleBgActive], 0.60f);
  328. colors[ImGuiCol_TabSelectedOverline] = colors[ImGuiCol_HeaderActive];
  329. colors[ImGuiCol_TabDimmed] = ImLerp(colors[ImGuiCol_Tab], colors[ImGuiCol_TitleBg], 0.80f);
  330. colors[ImGuiCol_TabDimmedSelected] = ImLerp(colors[ImGuiCol_TabSelected], colors[ImGuiCol_TitleBg], 0.40f);
  331. colors[ImGuiCol_TabDimmedSelectedOverline] = ImVec4(0.26f, 0.59f, 1.00f, 0.00f);
  332. colors[ImGuiCol_PlotLines] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
  333. colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
  334. colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  335. colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.45f, 0.00f, 1.00f);
  336. colors[ImGuiCol_TableHeaderBg] = ImVec4(0.78f, 0.87f, 0.98f, 1.00f);
  337. colors[ImGuiCol_TableBorderStrong] = ImVec4(0.57f, 0.57f, 0.64f, 1.00f); // Prefer using Alpha=1.0 here
  338. colors[ImGuiCol_TableBorderLight] = ImVec4(0.68f, 0.68f, 0.74f, 1.00f); // Prefer using Alpha=1.0 here
  339. colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
  340. colors[ImGuiCol_TableRowBgAlt] = ImVec4(0.30f, 0.30f, 0.30f, 0.09f);
  341. colors[ImGuiCol_TextLink] = colors[ImGuiCol_HeaderActive];
  342. colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
  343. colors[ImGuiCol_TreeLines] = colors[ImGuiCol_Border];
  344. colors[ImGuiCol_DragDropTarget] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
  345. colors[ImGuiCol_NavCursor] = colors[ImGuiCol_HeaderHovered];
  346. colors[ImGuiCol_NavWindowingHighlight] = ImVec4(0.70f, 0.70f, 0.70f, 0.70f);
  347. colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.20f);
  348. colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
  349. }
  350. //-----------------------------------------------------------------------------
  351. // [SECTION] ImDrawList
  352. //-----------------------------------------------------------------------------
  353. ImDrawListSharedData::ImDrawListSharedData()
  354. {
  355. memset(this, 0, sizeof(*this));
  356. InitialFringeScale = 1.0f;
  357. for (int i = 0; i < IM_ARRAYSIZE(ArcFastVtx); i++)
  358. {
  359. const float a = ((float)i * 2 * IM_PI) / (float)IM_ARRAYSIZE(ArcFastVtx);
  360. ArcFastVtx[i] = ImVec2(ImCos(a), ImSin(a));
  361. }
  362. ArcFastRadiusCutoff = IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC_R(IM_DRAWLIST_ARCFAST_SAMPLE_MAX, CircleSegmentMaxError);
  363. }
  364. ImDrawListSharedData::~ImDrawListSharedData()
  365. {
  366. IM_ASSERT(DrawLists.Size == 0);
  367. }
  368. void ImDrawListSharedData::SetCircleTessellationMaxError(float max_error)
  369. {
  370. if (CircleSegmentMaxError == max_error)
  371. return;
  372. IM_ASSERT(max_error > 0.0f);
  373. CircleSegmentMaxError = max_error;
  374. for (int i = 0; i < IM_ARRAYSIZE(CircleSegmentCounts); i++)
  375. {
  376. const float radius = (float)i;
  377. CircleSegmentCounts[i] = (ImU8)((i > 0) ? IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC(radius, CircleSegmentMaxError) : IM_DRAWLIST_ARCFAST_SAMPLE_MAX);
  378. }
  379. ArcFastRadiusCutoff = IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC_R(IM_DRAWLIST_ARCFAST_SAMPLE_MAX, CircleSegmentMaxError);
  380. }
  381. ImDrawList::ImDrawList(ImDrawListSharedData* shared_data)
  382. {
  383. memset(this, 0, sizeof(*this));
  384. _SetDrawListSharedData(shared_data);
  385. }
  386. ImDrawList::~ImDrawList()
  387. {
  388. _ClearFreeMemory();
  389. _SetDrawListSharedData(NULL);
  390. }
  391. void ImDrawList::_SetDrawListSharedData(ImDrawListSharedData* data)
  392. {
  393. if (_Data != NULL)
  394. _Data->DrawLists.find_erase_unsorted(this);
  395. _Data = data;
  396. if (_Data != NULL)
  397. _Data->DrawLists.push_back(this);
  398. }
  399. // Initialize before use in a new frame. We always have a command ready in the buffer.
  400. // In the majority of cases, you would want to call PushClipRect() and PushTexture() after this.
  401. void ImDrawList::_ResetForNewFrame()
  402. {
  403. // Verify that the ImDrawCmd fields we want to memcmp() are contiguous in memory.
  404. IM_STATIC_ASSERT(offsetof(ImDrawCmd, ClipRect) == 0);
  405. IM_STATIC_ASSERT(offsetof(ImDrawCmd, TexRef) == sizeof(ImVec4));
  406. IM_STATIC_ASSERT(offsetof(ImDrawCmd, VtxOffset) == sizeof(ImVec4) + sizeof(ImTextureRef));
  407. if (_Splitter._Count > 1)
  408. _Splitter.Merge(this);
  409. CmdBuffer.resize(0);
  410. IdxBuffer.resize(0);
  411. VtxBuffer.resize(0);
  412. Flags = _Data->InitialFlags;
  413. memset(&_CmdHeader, 0, sizeof(_CmdHeader));
  414. _VtxCurrentIdx = 0;
  415. _VtxWritePtr = NULL;
  416. _IdxWritePtr = NULL;
  417. _ClipRectStack.resize(0);
  418. _TextureStack.resize(0);
  419. _CallbacksDataBuf.resize(0);
  420. _Path.resize(0);
  421. _Splitter.Clear();
  422. CmdBuffer.push_back(ImDrawCmd());
  423. _FringeScale = _Data->InitialFringeScale;
  424. }
  425. void ImDrawList::_ClearFreeMemory()
  426. {
  427. CmdBuffer.clear();
  428. IdxBuffer.clear();
  429. VtxBuffer.clear();
  430. Flags = ImDrawListFlags_None;
  431. _VtxCurrentIdx = 0;
  432. _VtxWritePtr = NULL;
  433. _IdxWritePtr = NULL;
  434. _ClipRectStack.clear();
  435. _TextureStack.clear();
  436. _CallbacksDataBuf.clear();
  437. _Path.clear();
  438. _Splitter.ClearFreeMemory();
  439. }
  440. ImDrawList* ImDrawList::CloneOutput() const
  441. {
  442. ImDrawList* dst = IM_NEW(ImDrawList(_Data));
  443. dst->CmdBuffer = CmdBuffer;
  444. dst->IdxBuffer = IdxBuffer;
  445. dst->VtxBuffer = VtxBuffer;
  446. dst->Flags = Flags;
  447. return dst;
  448. }
  449. void ImDrawList::AddDrawCmd()
  450. {
  451. ImDrawCmd draw_cmd;
  452. draw_cmd.ClipRect = _CmdHeader.ClipRect; // Same as calling ImDrawCmd_HeaderCopy()
  453. draw_cmd.TexRef = _CmdHeader.TexRef;
  454. draw_cmd.VtxOffset = _CmdHeader.VtxOffset;
  455. draw_cmd.IdxOffset = IdxBuffer.Size;
  456. IM_ASSERT(draw_cmd.ClipRect.x <= draw_cmd.ClipRect.z && draw_cmd.ClipRect.y <= draw_cmd.ClipRect.w);
  457. CmdBuffer.push_back(draw_cmd);
  458. }
  459. // Pop trailing draw command (used before merging or presenting to user)
  460. // Note that this leaves the ImDrawList in a state unfit for further commands, as most code assume that CmdBuffer.Size > 0 && CmdBuffer.back().UserCallback == NULL
  461. void ImDrawList::_PopUnusedDrawCmd()
  462. {
  463. while (CmdBuffer.Size > 0)
  464. {
  465. ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1];
  466. if (curr_cmd->ElemCount != 0 || curr_cmd->UserCallback != NULL)
  467. return;// break;
  468. CmdBuffer.pop_back();
  469. }
  470. }
  471. void ImDrawList::AddCallback(ImDrawCallback callback, void* userdata, size_t userdata_size)
  472. {
  473. IM_ASSERT_PARANOID(CmdBuffer.Size > 0);
  474. ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1];
  475. IM_ASSERT(curr_cmd->UserCallback == NULL);
  476. if (curr_cmd->ElemCount != 0)
  477. {
  478. AddDrawCmd();
  479. curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1];
  480. }
  481. curr_cmd->UserCallback = callback;
  482. if (userdata_size == 0)
  483. {
  484. // Store user data directly in command (no indirection)
  485. curr_cmd->UserCallbackData = userdata;
  486. curr_cmd->UserCallbackDataSize = 0;
  487. curr_cmd->UserCallbackDataOffset = -1;
  488. }
  489. else
  490. {
  491. // Copy and store user data in a buffer
  492. IM_ASSERT(userdata != NULL);
  493. IM_ASSERT(userdata_size < (1u << 31));
  494. curr_cmd->UserCallbackData = NULL; // Will be resolved during Render()
  495. curr_cmd->UserCallbackDataSize = (int)userdata_size;
  496. curr_cmd->UserCallbackDataOffset = _CallbacksDataBuf.Size;
  497. _CallbacksDataBuf.resize(_CallbacksDataBuf.Size + (int)userdata_size);
  498. memcpy(_CallbacksDataBuf.Data + (size_t)curr_cmd->UserCallbackDataOffset, userdata, userdata_size);
  499. }
  500. AddDrawCmd(); // Force a new command after us (see comment below)
  501. }
  502. // Compare ClipRect, TexRef and VtxOffset with a single memcmp()
  503. #define ImDrawCmd_HeaderSize (offsetof(ImDrawCmd, VtxOffset) + sizeof(unsigned int))
  504. #define ImDrawCmd_HeaderCompare(CMD_LHS, CMD_RHS) (memcmp(CMD_LHS, CMD_RHS, ImDrawCmd_HeaderSize)) // Compare ClipRect, TexRef, VtxOffset
  505. #define ImDrawCmd_HeaderCopy(CMD_DST, CMD_SRC) (memcpy(CMD_DST, CMD_SRC, ImDrawCmd_HeaderSize)) // Copy ClipRect, TexRef, VtxOffset
  506. #define ImDrawCmd_AreSequentialIdxOffset(CMD_0, CMD_1) (CMD_0->IdxOffset + CMD_0->ElemCount == CMD_1->IdxOffset)
  507. // Try to merge two last draw commands
  508. void ImDrawList::_TryMergeDrawCmds()
  509. {
  510. IM_ASSERT_PARANOID(CmdBuffer.Size > 0);
  511. ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1];
  512. ImDrawCmd* prev_cmd = curr_cmd - 1;
  513. if (ImDrawCmd_HeaderCompare(curr_cmd, prev_cmd) == 0 && ImDrawCmd_AreSequentialIdxOffset(prev_cmd, curr_cmd) && curr_cmd->UserCallback == NULL && prev_cmd->UserCallback == NULL)
  514. {
  515. prev_cmd->ElemCount += curr_cmd->ElemCount;
  516. CmdBuffer.pop_back();
  517. }
  518. }
  519. // Our scheme may appears a bit unusual, basically we want the most-common calls AddLine AddRect etc. to not have to perform any check so we always have a command ready in the stack.
  520. // The cost of figuring out if a new command has to be added or if we can merge is paid in those Update** functions only.
  521. void ImDrawList::_OnChangedClipRect()
  522. {
  523. // If current command is used with different settings we need to add a new command
  524. IM_ASSERT_PARANOID(CmdBuffer.Size > 0);
  525. ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1];
  526. if (curr_cmd->ElemCount != 0 && memcmp(&curr_cmd->ClipRect, &_CmdHeader.ClipRect, sizeof(ImVec4)) != 0)
  527. {
  528. AddDrawCmd();
  529. return;
  530. }
  531. IM_ASSERT(curr_cmd->UserCallback == NULL);
  532. // Try to merge with previous command if it matches, else use current command
  533. ImDrawCmd* prev_cmd = curr_cmd - 1;
  534. if (curr_cmd->ElemCount == 0 && CmdBuffer.Size > 1 && ImDrawCmd_HeaderCompare(&_CmdHeader, prev_cmd) == 0 && ImDrawCmd_AreSequentialIdxOffset(prev_cmd, curr_cmd) && prev_cmd->UserCallback == NULL)
  535. {
  536. CmdBuffer.pop_back();
  537. return;
  538. }
  539. curr_cmd->ClipRect = _CmdHeader.ClipRect;
  540. }
  541. void ImDrawList::_OnChangedTexture()
  542. {
  543. // If current command is used with different settings we need to add a new command
  544. IM_ASSERT_PARANOID(CmdBuffer.Size > 0);
  545. ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1];
  546. if (curr_cmd->ElemCount != 0 && curr_cmd->TexRef != _CmdHeader.TexRef)
  547. {
  548. AddDrawCmd();
  549. return;
  550. }
  551. // Unlike other _OnChangedXXX functions this may be called by ImFontAtlasUpdateDrawListsTextures() in more locations so we need to handle this case.
  552. if (curr_cmd->UserCallback != NULL)
  553. return;
  554. // Try to merge with previous command if it matches, else use current command
  555. ImDrawCmd* prev_cmd = curr_cmd - 1;
  556. if (curr_cmd->ElemCount == 0 && CmdBuffer.Size > 1 && ImDrawCmd_HeaderCompare(&_CmdHeader, prev_cmd) == 0 && ImDrawCmd_AreSequentialIdxOffset(prev_cmd, curr_cmd) && prev_cmd->UserCallback == NULL)
  557. {
  558. CmdBuffer.pop_back();
  559. return;
  560. }
  561. curr_cmd->TexRef = _CmdHeader.TexRef;
  562. }
  563. void ImDrawList::_OnChangedVtxOffset()
  564. {
  565. // We don't need to compare curr_cmd->VtxOffset != _CmdHeader.VtxOffset because we know it'll be different at the time we call this.
  566. _VtxCurrentIdx = 0;
  567. IM_ASSERT_PARANOID(CmdBuffer.Size > 0);
  568. ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1];
  569. //IM_ASSERT(curr_cmd->VtxOffset != _CmdHeader.VtxOffset); // See #3349
  570. if (curr_cmd->ElemCount != 0)
  571. {
  572. AddDrawCmd();
  573. return;
  574. }
  575. IM_ASSERT(curr_cmd->UserCallback == NULL);
  576. curr_cmd->VtxOffset = _CmdHeader.VtxOffset;
  577. }
  578. int ImDrawList::_CalcCircleAutoSegmentCount(float radius) const
  579. {
  580. // Automatic segment count
  581. const int radius_idx = (int)(radius + 0.999999f); // ceil to never reduce accuracy
  582. if (radius_idx >= 0 && radius_idx < IM_ARRAYSIZE(_Data->CircleSegmentCounts))
  583. return _Data->CircleSegmentCounts[radius_idx]; // Use cached value
  584. else
  585. return IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC(radius, _Data->CircleSegmentMaxError);
  586. }
  587. // Render-level scissoring. This is passed down to your render function but not used for CPU-side coarse clipping. Prefer using higher-level ImGui::PushClipRect() to affect logic (hit-testing and widget culling)
  588. void ImDrawList::PushClipRect(const ImVec2& cr_min, const ImVec2& cr_max, bool intersect_with_current_clip_rect)
  589. {
  590. ImVec4 cr(cr_min.x, cr_min.y, cr_max.x, cr_max.y);
  591. if (intersect_with_current_clip_rect)
  592. {
  593. ImVec4 current = _CmdHeader.ClipRect;
  594. if (cr.x < current.x) cr.x = current.x;
  595. if (cr.y < current.y) cr.y = current.y;
  596. if (cr.z > current.z) cr.z = current.z;
  597. if (cr.w > current.w) cr.w = current.w;
  598. }
  599. cr.z = ImMax(cr.x, cr.z);
  600. cr.w = ImMax(cr.y, cr.w);
  601. _ClipRectStack.push_back(cr);
  602. _CmdHeader.ClipRect = cr;
  603. _OnChangedClipRect();
  604. }
  605. void ImDrawList::PushClipRectFullScreen()
  606. {
  607. PushClipRect(ImVec2(_Data->ClipRectFullscreen.x, _Data->ClipRectFullscreen.y), ImVec2(_Data->ClipRectFullscreen.z, _Data->ClipRectFullscreen.w));
  608. }
  609. void ImDrawList::PopClipRect()
  610. {
  611. _ClipRectStack.pop_back();
  612. _CmdHeader.ClipRect = (_ClipRectStack.Size == 0) ? _Data->ClipRectFullscreen : _ClipRectStack.Data[_ClipRectStack.Size - 1];
  613. _OnChangedClipRect();
  614. }
  615. void ImDrawList::PushTexture(ImTextureRef tex_ref)
  616. {
  617. _TextureStack.push_back(tex_ref);
  618. _CmdHeader.TexRef = tex_ref;
  619. if (tex_ref._TexData != NULL)
  620. IM_ASSERT(tex_ref._TexData->WantDestroyNextFrame == false);
  621. _OnChangedTexture();
  622. }
  623. void ImDrawList::PopTexture()
  624. {
  625. _TextureStack.pop_back();
  626. _CmdHeader.TexRef = (_TextureStack.Size == 0) ? ImTextureRef() : _TextureStack.Data[_TextureStack.Size - 1];
  627. _OnChangedTexture();
  628. }
  629. // This is used by ImGui::PushFont()/PopFont(). It works because we never use _TextureIdStack[] elsewhere than in PushTexture()/PopTexture().
  630. void ImDrawList::_SetTexture(ImTextureRef tex_ref)
  631. {
  632. if (_CmdHeader.TexRef == tex_ref)
  633. return;
  634. _CmdHeader.TexRef = tex_ref;
  635. _TextureStack.back() = tex_ref;
  636. _OnChangedTexture();
  637. }
  638. // Reserve space for a number of vertices and indices.
  639. // You must finish filling your reserved data before calling PrimReserve() again, as it may reallocate or
  640. // submit the intermediate results. PrimUnreserve() can be used to release unused allocations.
  641. void ImDrawList::PrimReserve(int idx_count, int vtx_count)
  642. {
  643. // Large mesh support (when enabled)
  644. IM_ASSERT_PARANOID(idx_count >= 0 && vtx_count >= 0);
  645. if (sizeof(ImDrawIdx) == 2 && (_VtxCurrentIdx + vtx_count >= (1 << 16)) && (Flags & ImDrawListFlags_AllowVtxOffset))
  646. {
  647. // FIXME: In theory we should be testing that vtx_count <64k here.
  648. // In practice, RenderText() relies on reserving ahead for a worst case scenario so it is currently useful for us
  649. // to not make that check until we rework the text functions to handle clipping and large horizontal lines better.
  650. _CmdHeader.VtxOffset = VtxBuffer.Size;
  651. _OnChangedVtxOffset();
  652. }
  653. ImDrawCmd* draw_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1];
  654. draw_cmd->ElemCount += idx_count;
  655. int vtx_buffer_old_size = VtxBuffer.Size;
  656. VtxBuffer.resize(vtx_buffer_old_size + vtx_count);
  657. _VtxWritePtr = VtxBuffer.Data + vtx_buffer_old_size;
  658. int idx_buffer_old_size = IdxBuffer.Size;
  659. IdxBuffer.resize(idx_buffer_old_size + idx_count);
  660. _IdxWritePtr = IdxBuffer.Data + idx_buffer_old_size;
  661. }
  662. // Release the number of reserved vertices/indices from the end of the last reservation made with PrimReserve().
  663. void ImDrawList::PrimUnreserve(int idx_count, int vtx_count)
  664. {
  665. IM_ASSERT_PARANOID(idx_count >= 0 && vtx_count >= 0);
  666. ImDrawCmd* draw_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1];
  667. draw_cmd->ElemCount -= idx_count;
  668. VtxBuffer.shrink(VtxBuffer.Size - vtx_count);
  669. IdxBuffer.shrink(IdxBuffer.Size - idx_count);
  670. }
  671. // Fully unrolled with inline call to keep our debug builds decently fast.
  672. void ImDrawList::PrimRect(const ImVec2& a, const ImVec2& c, ImU32 col)
  673. {
  674. ImVec2 b(c.x, a.y), d(a.x, c.y), uv(_Data->TexUvWhitePixel);
  675. ImDrawIdx idx = (ImDrawIdx)_VtxCurrentIdx;
  676. _IdxWritePtr[0] = idx; _IdxWritePtr[1] = (ImDrawIdx)(idx+1); _IdxWritePtr[2] = (ImDrawIdx)(idx+2);
  677. _IdxWritePtr[3] = idx; _IdxWritePtr[4] = (ImDrawIdx)(idx+2); _IdxWritePtr[5] = (ImDrawIdx)(idx+3);
  678. _VtxWritePtr[0].pos = a; _VtxWritePtr[0].uv = uv; _VtxWritePtr[0].col = col;
  679. _VtxWritePtr[1].pos = b; _VtxWritePtr[1].uv = uv; _VtxWritePtr[1].col = col;
  680. _VtxWritePtr[2].pos = c; _VtxWritePtr[2].uv = uv; _VtxWritePtr[2].col = col;
  681. _VtxWritePtr[3].pos = d; _VtxWritePtr[3].uv = uv; _VtxWritePtr[3].col = col;
  682. _VtxWritePtr += 4;
  683. _VtxCurrentIdx += 4;
  684. _IdxWritePtr += 6;
  685. }
  686. void ImDrawList::PrimRectUV(const ImVec2& a, const ImVec2& c, const ImVec2& uv_a, const ImVec2& uv_c, ImU32 col)
  687. {
  688. ImVec2 b(c.x, a.y), d(a.x, c.y), uv_b(uv_c.x, uv_a.y), uv_d(uv_a.x, uv_c.y);
  689. ImDrawIdx idx = (ImDrawIdx)_VtxCurrentIdx;
  690. _IdxWritePtr[0] = idx; _IdxWritePtr[1] = (ImDrawIdx)(idx+1); _IdxWritePtr[2] = (ImDrawIdx)(idx+2);
  691. _IdxWritePtr[3] = idx; _IdxWritePtr[4] = (ImDrawIdx)(idx+2); _IdxWritePtr[5] = (ImDrawIdx)(idx+3);
  692. _VtxWritePtr[0].pos = a; _VtxWritePtr[0].uv = uv_a; _VtxWritePtr[0].col = col;
  693. _VtxWritePtr[1].pos = b; _VtxWritePtr[1].uv = uv_b; _VtxWritePtr[1].col = col;
  694. _VtxWritePtr[2].pos = c; _VtxWritePtr[2].uv = uv_c; _VtxWritePtr[2].col = col;
  695. _VtxWritePtr[3].pos = d; _VtxWritePtr[3].uv = uv_d; _VtxWritePtr[3].col = col;
  696. _VtxWritePtr += 4;
  697. _VtxCurrentIdx += 4;
  698. _IdxWritePtr += 6;
  699. }
  700. void ImDrawList::PrimQuadUV(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, const ImVec2& uv_a, const ImVec2& uv_b, const ImVec2& uv_c, const ImVec2& uv_d, ImU32 col)
  701. {
  702. ImDrawIdx idx = (ImDrawIdx)_VtxCurrentIdx;
  703. _IdxWritePtr[0] = idx; _IdxWritePtr[1] = (ImDrawIdx)(idx+1); _IdxWritePtr[2] = (ImDrawIdx)(idx+2);
  704. _IdxWritePtr[3] = idx; _IdxWritePtr[4] = (ImDrawIdx)(idx+2); _IdxWritePtr[5] = (ImDrawIdx)(idx+3);
  705. _VtxWritePtr[0].pos = a; _VtxWritePtr[0].uv = uv_a; _VtxWritePtr[0].col = col;
  706. _VtxWritePtr[1].pos = b; _VtxWritePtr[1].uv = uv_b; _VtxWritePtr[1].col = col;
  707. _VtxWritePtr[2].pos = c; _VtxWritePtr[2].uv = uv_c; _VtxWritePtr[2].col = col;
  708. _VtxWritePtr[3].pos = d; _VtxWritePtr[3].uv = uv_d; _VtxWritePtr[3].col = col;
  709. _VtxWritePtr += 4;
  710. _VtxCurrentIdx += 4;
  711. _IdxWritePtr += 6;
  712. }
  713. // On AddPolyline() and AddConvexPolyFilled() we intentionally avoid using ImVec2 and superfluous function calls to optimize debug/non-inlined builds.
  714. // - Those macros expects l-values and need to be used as their own statement.
  715. // - Those macros are intentionally not surrounded by the 'do {} while (0)' idiom because even that translates to runtime with debug compilers.
  716. #define IM_NORMALIZE2F_OVER_ZERO(VX,VY) { float d2 = VX*VX + VY*VY; if (d2 > 0.0f) { float inv_len = ImRsqrt(d2); VX *= inv_len; VY *= inv_len; } } (void)0
  717. #define IM_FIXNORMAL2F_MAX_INVLEN2 100.0f // 500.0f (see #4053, #3366)
  718. #define IM_FIXNORMAL2F(VX,VY) { float d2 = VX*VX + VY*VY; if (d2 > 0.000001f) { float inv_len2 = 1.0f / d2; if (inv_len2 > IM_FIXNORMAL2F_MAX_INVLEN2) inv_len2 = IM_FIXNORMAL2F_MAX_INVLEN2; VX *= inv_len2; VY *= inv_len2; } } (void)0
  719. // TODO: Thickness anti-aliased lines cap are missing their AA fringe.
  720. // We avoid using the ImVec2 math operators here to reduce cost to a minimum for debug/non-inlined builds.
  721. void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32 col, ImDrawFlags flags, float thickness)
  722. {
  723. if (points_count < 2 || (col & IM_COL32_A_MASK) == 0)
  724. return;
  725. const bool closed = (flags & ImDrawFlags_Closed) != 0;
  726. const ImVec2 opaque_uv = _Data->TexUvWhitePixel;
  727. const int count = closed ? points_count : points_count - 1; // The number of line segments we need to draw
  728. const bool thick_line = (thickness > _FringeScale);
  729. if (Flags & ImDrawListFlags_AntiAliasedLines)
  730. {
  731. // Anti-aliased stroke
  732. const float AA_SIZE = _FringeScale;
  733. const ImU32 col_trans = col & ~IM_COL32_A_MASK;
  734. // Thicknesses <1.0 should behave like thickness 1.0
  735. thickness = ImMax(thickness, 1.0f);
  736. const int integer_thickness = (int)thickness;
  737. const float fractional_thickness = thickness - integer_thickness;
  738. // Do we want to draw this line using a texture?
  739. // - For now, only draw integer-width lines using textures to avoid issues with the way scaling occurs, could be improved.
  740. // - If AA_SIZE is not 1.0f we cannot use the texture path.
  741. const bool use_texture = (Flags & ImDrawListFlags_AntiAliasedLinesUseTex) && (integer_thickness < IM_DRAWLIST_TEX_LINES_WIDTH_MAX) && (fractional_thickness <= 0.00001f) && (AA_SIZE == 1.0f);
  742. // We should never hit this, because NewFrame() doesn't set ImDrawListFlags_AntiAliasedLinesUseTex unless ImFontAtlasFlags_NoBakedLines is off
  743. IM_ASSERT_PARANOID(!use_texture || !(_Data->Font->ContainerAtlas->Flags & ImFontAtlasFlags_NoBakedLines));
  744. const int idx_count = use_texture ? (count * 6) : (thick_line ? count * 18 : count * 12);
  745. const int vtx_count = use_texture ? (points_count * 2) : (thick_line ? points_count * 4 : points_count * 3);
  746. PrimReserve(idx_count, vtx_count);
  747. // Temporary buffer
  748. // The first <points_count> items are normals at each line point, then after that there are either 2 or 4 temp points for each line point
  749. _Data->TempBuffer.reserve_discard(points_count * ((use_texture || !thick_line) ? 3 : 5));
  750. ImVec2* temp_normals = _Data->TempBuffer.Data;
  751. ImVec2* temp_points = temp_normals + points_count;
  752. // Calculate normals (tangents) for each line segment
  753. for (int i1 = 0; i1 < count; i1++)
  754. {
  755. const int i2 = (i1 + 1) == points_count ? 0 : i1 + 1;
  756. float dx = points[i2].x - points[i1].x;
  757. float dy = points[i2].y - points[i1].y;
  758. IM_NORMALIZE2F_OVER_ZERO(dx, dy);
  759. temp_normals[i1].x = dy;
  760. temp_normals[i1].y = -dx;
  761. }
  762. if (!closed)
  763. temp_normals[points_count - 1] = temp_normals[points_count - 2];
  764. // If we are drawing a one-pixel-wide line without a texture, or a textured line of any width, we only need 2 or 3 vertices per point
  765. if (use_texture || !thick_line)
  766. {
  767. // [PATH 1] Texture-based lines (thick or non-thick)
  768. // [PATH 2] Non texture-based lines (non-thick)
  769. // The width of the geometry we need to draw - this is essentially <thickness> pixels for the line itself, plus "one pixel" for AA.
  770. // - In the texture-based path, we don't use AA_SIZE here because the +1 is tied to the generated texture
  771. // (see ImFontAtlasBuildRenderLinesTexData() function), and so alternate values won't work without changes to that code.
  772. // - In the non texture-based paths, we would allow AA_SIZE to potentially be != 1.0f with a patch (e.g. fringe_scale patch to
  773. // allow scaling geometry while preserving one-screen-pixel AA fringe).
  774. const float half_draw_size = use_texture ? ((thickness * 0.5f) + 1) : AA_SIZE;
  775. // If line is not closed, the first and last points need to be generated differently as there are no normals to blend
  776. if (!closed)
  777. {
  778. temp_points[0] = points[0] + temp_normals[0] * half_draw_size;
  779. temp_points[1] = points[0] - temp_normals[0] * half_draw_size;
  780. temp_points[(points_count-1)*2+0] = points[points_count-1] + temp_normals[points_count-1] * half_draw_size;
  781. temp_points[(points_count-1)*2+1] = points[points_count-1] - temp_normals[points_count-1] * half_draw_size;
  782. }
  783. // Generate the indices to form a number of triangles for each line segment, and the vertices for the line edges
  784. // This takes points n and n+1 and writes into n+1, with the first point in a closed line being generated from the final one (as n+1 wraps)
  785. // FIXME-OPT: Merge the different loops, possibly remove the temporary buffer.
  786. unsigned int idx1 = _VtxCurrentIdx; // Vertex index for start of line segment
  787. for (int i1 = 0; i1 < count; i1++) // i1 is the first point of the line segment
  788. {
  789. const int i2 = (i1 + 1) == points_count ? 0 : i1 + 1; // i2 is the second point of the line segment
  790. const unsigned int idx2 = ((i1 + 1) == points_count) ? _VtxCurrentIdx : (idx1 + (use_texture ? 2 : 3)); // Vertex index for end of segment
  791. // Average normals
  792. float dm_x = (temp_normals[i1].x + temp_normals[i2].x) * 0.5f;
  793. float dm_y = (temp_normals[i1].y + temp_normals[i2].y) * 0.5f;
  794. IM_FIXNORMAL2F(dm_x, dm_y);
  795. dm_x *= half_draw_size; // dm_x, dm_y are offset to the outer edge of the AA area
  796. dm_y *= half_draw_size;
  797. // Add temporary vertices for the outer edges
  798. ImVec2* out_vtx = &temp_points[i2 * 2];
  799. out_vtx[0].x = points[i2].x + dm_x;
  800. out_vtx[0].y = points[i2].y + dm_y;
  801. out_vtx[1].x = points[i2].x - dm_x;
  802. out_vtx[1].y = points[i2].y - dm_y;
  803. if (use_texture)
  804. {
  805. // Add indices for two triangles
  806. _IdxWritePtr[0] = (ImDrawIdx)(idx2 + 0); _IdxWritePtr[1] = (ImDrawIdx)(idx1 + 0); _IdxWritePtr[2] = (ImDrawIdx)(idx1 + 1); // Right tri
  807. _IdxWritePtr[3] = (ImDrawIdx)(idx2 + 1); _IdxWritePtr[4] = (ImDrawIdx)(idx1 + 1); _IdxWritePtr[5] = (ImDrawIdx)(idx2 + 0); // Left tri
  808. _IdxWritePtr += 6;
  809. }
  810. else
  811. {
  812. // Add indexes for four triangles
  813. _IdxWritePtr[0] = (ImDrawIdx)(idx2 + 0); _IdxWritePtr[1] = (ImDrawIdx)(idx1 + 0); _IdxWritePtr[2] = (ImDrawIdx)(idx1 + 2); // Right tri 1
  814. _IdxWritePtr[3] = (ImDrawIdx)(idx1 + 2); _IdxWritePtr[4] = (ImDrawIdx)(idx2 + 2); _IdxWritePtr[5] = (ImDrawIdx)(idx2 + 0); // Right tri 2
  815. _IdxWritePtr[6] = (ImDrawIdx)(idx2 + 1); _IdxWritePtr[7] = (ImDrawIdx)(idx1 + 1); _IdxWritePtr[8] = (ImDrawIdx)(idx1 + 0); // Left tri 1
  816. _IdxWritePtr[9] = (ImDrawIdx)(idx1 + 0); _IdxWritePtr[10] = (ImDrawIdx)(idx2 + 0); _IdxWritePtr[11] = (ImDrawIdx)(idx2 + 1); // Left tri 2
  817. _IdxWritePtr += 12;
  818. }
  819. idx1 = idx2;
  820. }
  821. // Add vertices for each point on the line
  822. if (use_texture)
  823. {
  824. // If we're using textures we only need to emit the left/right edge vertices
  825. ImVec4 tex_uvs = _Data->TexUvLines[integer_thickness];
  826. /*if (fractional_thickness != 0.0f) // Currently always zero when use_texture==false!
  827. {
  828. const ImVec4 tex_uvs_1 = _Data->TexUvLines[integer_thickness + 1];
  829. tex_uvs.x = tex_uvs.x + (tex_uvs_1.x - tex_uvs.x) * fractional_thickness; // inlined ImLerp()
  830. tex_uvs.y = tex_uvs.y + (tex_uvs_1.y - tex_uvs.y) * fractional_thickness;
  831. tex_uvs.z = tex_uvs.z + (tex_uvs_1.z - tex_uvs.z) * fractional_thickness;
  832. tex_uvs.w = tex_uvs.w + (tex_uvs_1.w - tex_uvs.w) * fractional_thickness;
  833. }*/
  834. ImVec2 tex_uv0(tex_uvs.x, tex_uvs.y);
  835. ImVec2 tex_uv1(tex_uvs.z, tex_uvs.w);
  836. for (int i = 0; i < points_count; i++)
  837. {
  838. _VtxWritePtr[0].pos = temp_points[i * 2 + 0]; _VtxWritePtr[0].uv = tex_uv0; _VtxWritePtr[0].col = col; // Left-side outer edge
  839. _VtxWritePtr[1].pos = temp_points[i * 2 + 1]; _VtxWritePtr[1].uv = tex_uv1; _VtxWritePtr[1].col = col; // Right-side outer edge
  840. _VtxWritePtr += 2;
  841. }
  842. }
  843. else
  844. {
  845. // If we're not using a texture, we need the center vertex as well
  846. for (int i = 0; i < points_count; i++)
  847. {
  848. _VtxWritePtr[0].pos = points[i]; _VtxWritePtr[0].uv = opaque_uv; _VtxWritePtr[0].col = col; // Center of line
  849. _VtxWritePtr[1].pos = temp_points[i * 2 + 0]; _VtxWritePtr[1].uv = opaque_uv; _VtxWritePtr[1].col = col_trans; // Left-side outer edge
  850. _VtxWritePtr[2].pos = temp_points[i * 2 + 1]; _VtxWritePtr[2].uv = opaque_uv; _VtxWritePtr[2].col = col_trans; // Right-side outer edge
  851. _VtxWritePtr += 3;
  852. }
  853. }
  854. }
  855. else
  856. {
  857. // [PATH 2] Non texture-based lines (thick): we need to draw the solid line core and thus require four vertices per point
  858. const float half_inner_thickness = (thickness - AA_SIZE) * 0.5f;
  859. // If line is not closed, the first and last points need to be generated differently as there are no normals to blend
  860. if (!closed)
  861. {
  862. const int points_last = points_count - 1;
  863. temp_points[0] = points[0] + temp_normals[0] * (half_inner_thickness + AA_SIZE);
  864. temp_points[1] = points[0] + temp_normals[0] * (half_inner_thickness);
  865. temp_points[2] = points[0] - temp_normals[0] * (half_inner_thickness);
  866. temp_points[3] = points[0] - temp_normals[0] * (half_inner_thickness + AA_SIZE);
  867. temp_points[points_last * 4 + 0] = points[points_last] + temp_normals[points_last] * (half_inner_thickness + AA_SIZE);
  868. temp_points[points_last * 4 + 1] = points[points_last] + temp_normals[points_last] * (half_inner_thickness);
  869. temp_points[points_last * 4 + 2] = points[points_last] - temp_normals[points_last] * (half_inner_thickness);
  870. temp_points[points_last * 4 + 3] = points[points_last] - temp_normals[points_last] * (half_inner_thickness + AA_SIZE);
  871. }
  872. // Generate the indices to form a number of triangles for each line segment, and the vertices for the line edges
  873. // This takes points n and n+1 and writes into n+1, with the first point in a closed line being generated from the final one (as n+1 wraps)
  874. // FIXME-OPT: Merge the different loops, possibly remove the temporary buffer.
  875. unsigned int idx1 = _VtxCurrentIdx; // Vertex index for start of line segment
  876. for (int i1 = 0; i1 < count; i1++) // i1 is the first point of the line segment
  877. {
  878. const int i2 = (i1 + 1) == points_count ? 0 : (i1 + 1); // i2 is the second point of the line segment
  879. const unsigned int idx2 = (i1 + 1) == points_count ? _VtxCurrentIdx : (idx1 + 4); // Vertex index for end of segment
  880. // Average normals
  881. float dm_x = (temp_normals[i1].x + temp_normals[i2].x) * 0.5f;
  882. float dm_y = (temp_normals[i1].y + temp_normals[i2].y) * 0.5f;
  883. IM_FIXNORMAL2F(dm_x, dm_y);
  884. float dm_out_x = dm_x * (half_inner_thickness + AA_SIZE);
  885. float dm_out_y = dm_y * (half_inner_thickness + AA_SIZE);
  886. float dm_in_x = dm_x * half_inner_thickness;
  887. float dm_in_y = dm_y * half_inner_thickness;
  888. // Add temporary vertices
  889. ImVec2* out_vtx = &temp_points[i2 * 4];
  890. out_vtx[0].x = points[i2].x + dm_out_x;
  891. out_vtx[0].y = points[i2].y + dm_out_y;
  892. out_vtx[1].x = points[i2].x + dm_in_x;
  893. out_vtx[1].y = points[i2].y + dm_in_y;
  894. out_vtx[2].x = points[i2].x - dm_in_x;
  895. out_vtx[2].y = points[i2].y - dm_in_y;
  896. out_vtx[3].x = points[i2].x - dm_out_x;
  897. out_vtx[3].y = points[i2].y - dm_out_y;
  898. // Add indexes
  899. _IdxWritePtr[0] = (ImDrawIdx)(idx2 + 1); _IdxWritePtr[1] = (ImDrawIdx)(idx1 + 1); _IdxWritePtr[2] = (ImDrawIdx)(idx1 + 2);
  900. _IdxWritePtr[3] = (ImDrawIdx)(idx1 + 2); _IdxWritePtr[4] = (ImDrawIdx)(idx2 + 2); _IdxWritePtr[5] = (ImDrawIdx)(idx2 + 1);
  901. _IdxWritePtr[6] = (ImDrawIdx)(idx2 + 1); _IdxWritePtr[7] = (ImDrawIdx)(idx1 + 1); _IdxWritePtr[8] = (ImDrawIdx)(idx1 + 0);
  902. _IdxWritePtr[9] = (ImDrawIdx)(idx1 + 0); _IdxWritePtr[10] = (ImDrawIdx)(idx2 + 0); _IdxWritePtr[11] = (ImDrawIdx)(idx2 + 1);
  903. _IdxWritePtr[12] = (ImDrawIdx)(idx2 + 2); _IdxWritePtr[13] = (ImDrawIdx)(idx1 + 2); _IdxWritePtr[14] = (ImDrawIdx)(idx1 + 3);
  904. _IdxWritePtr[15] = (ImDrawIdx)(idx1 + 3); _IdxWritePtr[16] = (ImDrawIdx)(idx2 + 3); _IdxWritePtr[17] = (ImDrawIdx)(idx2 + 2);
  905. _IdxWritePtr += 18;
  906. idx1 = idx2;
  907. }
  908. // Add vertices
  909. for (int i = 0; i < points_count; i++)
  910. {
  911. _VtxWritePtr[0].pos = temp_points[i * 4 + 0]; _VtxWritePtr[0].uv = opaque_uv; _VtxWritePtr[0].col = col_trans;
  912. _VtxWritePtr[1].pos = temp_points[i * 4 + 1]; _VtxWritePtr[1].uv = opaque_uv; _VtxWritePtr[1].col = col;
  913. _VtxWritePtr[2].pos = temp_points[i * 4 + 2]; _VtxWritePtr[2].uv = opaque_uv; _VtxWritePtr[2].col = col;
  914. _VtxWritePtr[3].pos = temp_points[i * 4 + 3]; _VtxWritePtr[3].uv = opaque_uv; _VtxWritePtr[3].col = col_trans;
  915. _VtxWritePtr += 4;
  916. }
  917. }
  918. _VtxCurrentIdx += (ImDrawIdx)vtx_count;
  919. }
  920. else
  921. {
  922. // [PATH 4] Non texture-based, Non anti-aliased lines
  923. const int idx_count = count * 6;
  924. const int vtx_count = count * 4; // FIXME-OPT: Not sharing edges
  925. PrimReserve(idx_count, vtx_count);
  926. for (int i1 = 0; i1 < count; i1++)
  927. {
  928. const int i2 = (i1 + 1) == points_count ? 0 : i1 + 1;
  929. const ImVec2& p1 = points[i1];
  930. const ImVec2& p2 = points[i2];
  931. float dx = p2.x - p1.x;
  932. float dy = p2.y - p1.y;
  933. IM_NORMALIZE2F_OVER_ZERO(dx, dy);
  934. dx *= (thickness * 0.5f);
  935. dy *= (thickness * 0.5f);
  936. _VtxWritePtr[0].pos.x = p1.x + dy; _VtxWritePtr[0].pos.y = p1.y - dx; _VtxWritePtr[0].uv = opaque_uv; _VtxWritePtr[0].col = col;
  937. _VtxWritePtr[1].pos.x = p2.x + dy; _VtxWritePtr[1].pos.y = p2.y - dx; _VtxWritePtr[1].uv = opaque_uv; _VtxWritePtr[1].col = col;
  938. _VtxWritePtr[2].pos.x = p2.x - dy; _VtxWritePtr[2].pos.y = p2.y + dx; _VtxWritePtr[2].uv = opaque_uv; _VtxWritePtr[2].col = col;
  939. _VtxWritePtr[3].pos.x = p1.x - dy; _VtxWritePtr[3].pos.y = p1.y + dx; _VtxWritePtr[3].uv = opaque_uv; _VtxWritePtr[3].col = col;
  940. _VtxWritePtr += 4;
  941. _IdxWritePtr[0] = (ImDrawIdx)(_VtxCurrentIdx); _IdxWritePtr[1] = (ImDrawIdx)(_VtxCurrentIdx + 1); _IdxWritePtr[2] = (ImDrawIdx)(_VtxCurrentIdx + 2);
  942. _IdxWritePtr[3] = (ImDrawIdx)(_VtxCurrentIdx); _IdxWritePtr[4] = (ImDrawIdx)(_VtxCurrentIdx + 2); _IdxWritePtr[5] = (ImDrawIdx)(_VtxCurrentIdx + 3);
  943. _IdxWritePtr += 6;
  944. _VtxCurrentIdx += 4;
  945. }
  946. }
  947. }
  948. // - We intentionally avoid using ImVec2 and its math operators here to reduce cost to a minimum for debug/non-inlined builds.
  949. // - Filled shapes must always use clockwise winding order. The anti-aliasing fringe depends on it. Counter-clockwise shapes will have "inward" anti-aliasing.
  950. void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_count, ImU32 col)
  951. {
  952. if (points_count < 3 || (col & IM_COL32_A_MASK) == 0)
  953. return;
  954. const ImVec2 uv = _Data->TexUvWhitePixel;
  955. if (Flags & ImDrawListFlags_AntiAliasedFill)
  956. {
  957. // Anti-aliased Fill
  958. const float AA_SIZE = _FringeScale;
  959. const ImU32 col_trans = col & ~IM_COL32_A_MASK;
  960. const int idx_count = (points_count - 2)*3 + points_count * 6;
  961. const int vtx_count = (points_count * 2);
  962. PrimReserve(idx_count, vtx_count);
  963. // Add indexes for fill
  964. unsigned int vtx_inner_idx = _VtxCurrentIdx;
  965. unsigned int vtx_outer_idx = _VtxCurrentIdx + 1;
  966. for (int i = 2; i < points_count; i++)
  967. {
  968. _IdxWritePtr[0] = (ImDrawIdx)(vtx_inner_idx); _IdxWritePtr[1] = (ImDrawIdx)(vtx_inner_idx + ((i - 1) << 1)); _IdxWritePtr[2] = (ImDrawIdx)(vtx_inner_idx + (i << 1));
  969. _IdxWritePtr += 3;
  970. }
  971. // Compute normals
  972. _Data->TempBuffer.reserve_discard(points_count);
  973. ImVec2* temp_normals = _Data->TempBuffer.Data;
  974. for (int i0 = points_count - 1, i1 = 0; i1 < points_count; i0 = i1++)
  975. {
  976. const ImVec2& p0 = points[i0];
  977. const ImVec2& p1 = points[i1];
  978. float dx = p1.x - p0.x;
  979. float dy = p1.y - p0.y;
  980. IM_NORMALIZE2F_OVER_ZERO(dx, dy);
  981. temp_normals[i0].x = dy;
  982. temp_normals[i0].y = -dx;
  983. }
  984. for (int i0 = points_count - 1, i1 = 0; i1 < points_count; i0 = i1++)
  985. {
  986. // Average normals
  987. const ImVec2& n0 = temp_normals[i0];
  988. const ImVec2& n1 = temp_normals[i1];
  989. float dm_x = (n0.x + n1.x) * 0.5f;
  990. float dm_y = (n0.y + n1.y) * 0.5f;
  991. IM_FIXNORMAL2F(dm_x, dm_y);
  992. dm_x *= AA_SIZE * 0.5f;
  993. dm_y *= AA_SIZE * 0.5f;
  994. // Add vertices
  995. _VtxWritePtr[0].pos.x = (points[i1].x - dm_x); _VtxWritePtr[0].pos.y = (points[i1].y - dm_y); _VtxWritePtr[0].uv = uv; _VtxWritePtr[0].col = col; // Inner
  996. _VtxWritePtr[1].pos.x = (points[i1].x + dm_x); _VtxWritePtr[1].pos.y = (points[i1].y + dm_y); _VtxWritePtr[1].uv = uv; _VtxWritePtr[1].col = col_trans; // Outer
  997. _VtxWritePtr += 2;
  998. // Add indexes for fringes
  999. _IdxWritePtr[0] = (ImDrawIdx)(vtx_inner_idx + (i1 << 1)); _IdxWritePtr[1] = (ImDrawIdx)(vtx_inner_idx + (i0 << 1)); _IdxWritePtr[2] = (ImDrawIdx)(vtx_outer_idx + (i0 << 1));
  1000. _IdxWritePtr[3] = (ImDrawIdx)(vtx_outer_idx + (i0 << 1)); _IdxWritePtr[4] = (ImDrawIdx)(vtx_outer_idx + (i1 << 1)); _IdxWritePtr[5] = (ImDrawIdx)(vtx_inner_idx + (i1 << 1));
  1001. _IdxWritePtr += 6;
  1002. }
  1003. _VtxCurrentIdx += (ImDrawIdx)vtx_count;
  1004. }
  1005. else
  1006. {
  1007. // Non Anti-aliased Fill
  1008. const int idx_count = (points_count - 2)*3;
  1009. const int vtx_count = points_count;
  1010. PrimReserve(idx_count, vtx_count);
  1011. for (int i = 0; i < vtx_count; i++)
  1012. {
  1013. _VtxWritePtr[0].pos = points[i]; _VtxWritePtr[0].uv = uv; _VtxWritePtr[0].col = col;
  1014. _VtxWritePtr++;
  1015. }
  1016. for (int i = 2; i < points_count; i++)
  1017. {
  1018. _IdxWritePtr[0] = (ImDrawIdx)(_VtxCurrentIdx); _IdxWritePtr[1] = (ImDrawIdx)(_VtxCurrentIdx + i - 1); _IdxWritePtr[2] = (ImDrawIdx)(_VtxCurrentIdx + i);
  1019. _IdxWritePtr += 3;
  1020. }
  1021. _VtxCurrentIdx += (ImDrawIdx)vtx_count;
  1022. }
  1023. }
  1024. void ImDrawList::_PathArcToFastEx(const ImVec2& center, float radius, int a_min_sample, int a_max_sample, int a_step)
  1025. {
  1026. if (radius < 0.5f)
  1027. {
  1028. _Path.push_back(center);
  1029. return;
  1030. }
  1031. // Calculate arc auto segment step size
  1032. if (a_step <= 0)
  1033. a_step = IM_DRAWLIST_ARCFAST_SAMPLE_MAX / _CalcCircleAutoSegmentCount(radius);
  1034. // Make sure we never do steps larger than one quarter of the circle
  1035. a_step = ImClamp(a_step, 1, IM_DRAWLIST_ARCFAST_TABLE_SIZE / 4);
  1036. const int sample_range = ImAbs(a_max_sample - a_min_sample);
  1037. const int a_next_step = a_step;
  1038. int samples = sample_range + 1;
  1039. bool extra_max_sample = false;
  1040. if (a_step > 1)
  1041. {
  1042. samples = sample_range / a_step + 1;
  1043. const int overstep = sample_range % a_step;
  1044. if (overstep > 0)
  1045. {
  1046. extra_max_sample = true;
  1047. samples++;
  1048. // When we have overstep to avoid awkwardly looking one long line and one tiny one at the end,
  1049. // distribute first step range evenly between them by reducing first step size.
  1050. if (sample_range > 0)
  1051. a_step -= (a_step - overstep) / 2;
  1052. }
  1053. }
  1054. _Path.resize(_Path.Size + samples);
  1055. ImVec2* out_ptr = _Path.Data + (_Path.Size - samples);
  1056. int sample_index = a_min_sample;
  1057. if (sample_index < 0 || sample_index >= IM_DRAWLIST_ARCFAST_SAMPLE_MAX)
  1058. {
  1059. sample_index = sample_index % IM_DRAWLIST_ARCFAST_SAMPLE_MAX;
  1060. if (sample_index < 0)
  1061. sample_index += IM_DRAWLIST_ARCFAST_SAMPLE_MAX;
  1062. }
  1063. if (a_max_sample >= a_min_sample)
  1064. {
  1065. for (int a = a_min_sample; a <= a_max_sample; a += a_step, sample_index += a_step, a_step = a_next_step)
  1066. {
  1067. // a_step is clamped to IM_DRAWLIST_ARCFAST_SAMPLE_MAX, so we have guaranteed that it will not wrap over range twice or more
  1068. if (sample_index >= IM_DRAWLIST_ARCFAST_SAMPLE_MAX)
  1069. sample_index -= IM_DRAWLIST_ARCFAST_SAMPLE_MAX;
  1070. const ImVec2 s = _Data->ArcFastVtx[sample_index];
  1071. out_ptr->x = center.x + s.x * radius;
  1072. out_ptr->y = center.y + s.y * radius;
  1073. out_ptr++;
  1074. }
  1075. }
  1076. else
  1077. {
  1078. for (int a = a_min_sample; a >= a_max_sample; a -= a_step, sample_index -= a_step, a_step = a_next_step)
  1079. {
  1080. // a_step is clamped to IM_DRAWLIST_ARCFAST_SAMPLE_MAX, so we have guaranteed that it will not wrap over range twice or more
  1081. if (sample_index < 0)
  1082. sample_index += IM_DRAWLIST_ARCFAST_SAMPLE_MAX;
  1083. const ImVec2 s = _Data->ArcFastVtx[sample_index];
  1084. out_ptr->x = center.x + s.x * radius;
  1085. out_ptr->y = center.y + s.y * radius;
  1086. out_ptr++;
  1087. }
  1088. }
  1089. if (extra_max_sample)
  1090. {
  1091. int normalized_max_sample = a_max_sample % IM_DRAWLIST_ARCFAST_SAMPLE_MAX;
  1092. if (normalized_max_sample < 0)
  1093. normalized_max_sample += IM_DRAWLIST_ARCFAST_SAMPLE_MAX;
  1094. const ImVec2 s = _Data->ArcFastVtx[normalized_max_sample];
  1095. out_ptr->x = center.x + s.x * radius;
  1096. out_ptr->y = center.y + s.y * radius;
  1097. out_ptr++;
  1098. }
  1099. IM_ASSERT_PARANOID(_Path.Data + _Path.Size == out_ptr);
  1100. }
  1101. void ImDrawList::_PathArcToN(const ImVec2& center, float radius, float a_min, float a_max, int num_segments)
  1102. {
  1103. if (radius < 0.5f)
  1104. {
  1105. _Path.push_back(center);
  1106. return;
  1107. }
  1108. // Note that we are adding a point at both a_min and a_max.
  1109. // If you are trying to draw a full closed circle you don't want the overlapping points!
  1110. _Path.reserve(_Path.Size + (num_segments + 1));
  1111. for (int i = 0; i <= num_segments; i++)
  1112. {
  1113. const float a = a_min + ((float)i / (float)num_segments) * (a_max - a_min);
  1114. _Path.push_back(ImVec2(center.x + ImCos(a) * radius, center.y + ImSin(a) * radius));
  1115. }
  1116. }
  1117. // 0: East, 3: South, 6: West, 9: North, 12: East
  1118. void ImDrawList::PathArcToFast(const ImVec2& center, float radius, int a_min_of_12, int a_max_of_12)
  1119. {
  1120. if (radius < 0.5f)
  1121. {
  1122. _Path.push_back(center);
  1123. return;
  1124. }
  1125. _PathArcToFastEx(center, radius, a_min_of_12 * IM_DRAWLIST_ARCFAST_SAMPLE_MAX / 12, a_max_of_12 * IM_DRAWLIST_ARCFAST_SAMPLE_MAX / 12, 0);
  1126. }
  1127. void ImDrawList::PathArcTo(const ImVec2& center, float radius, float a_min, float a_max, int num_segments)
  1128. {
  1129. if (radius < 0.5f)
  1130. {
  1131. _Path.push_back(center);
  1132. return;
  1133. }
  1134. if (num_segments > 0)
  1135. {
  1136. _PathArcToN(center, radius, a_min, a_max, num_segments);
  1137. return;
  1138. }
  1139. // Automatic segment count
  1140. if (radius <= _Data->ArcFastRadiusCutoff)
  1141. {
  1142. const bool a_is_reverse = a_max < a_min;
  1143. // We are going to use precomputed values for mid samples.
  1144. // Determine first and last sample in lookup table that belong to the arc.
  1145. const float a_min_sample_f = IM_DRAWLIST_ARCFAST_SAMPLE_MAX * a_min / (IM_PI * 2.0f);
  1146. const float a_max_sample_f = IM_DRAWLIST_ARCFAST_SAMPLE_MAX * a_max / (IM_PI * 2.0f);
  1147. const int a_min_sample = a_is_reverse ? (int)ImFloor(a_min_sample_f) : (int)ImCeil(a_min_sample_f);
  1148. const int a_max_sample = a_is_reverse ? (int)ImCeil(a_max_sample_f) : (int)ImFloor(a_max_sample_f);
  1149. const int a_mid_samples = a_is_reverse ? ImMax(a_min_sample - a_max_sample, 0) : ImMax(a_max_sample - a_min_sample, 0);
  1150. const float a_min_segment_angle = a_min_sample * IM_PI * 2.0f / IM_DRAWLIST_ARCFAST_SAMPLE_MAX;
  1151. const float a_max_segment_angle = a_max_sample * IM_PI * 2.0f / IM_DRAWLIST_ARCFAST_SAMPLE_MAX;
  1152. const bool a_emit_start = ImAbs(a_min_segment_angle - a_min) >= 1e-5f;
  1153. const bool a_emit_end = ImAbs(a_max - a_max_segment_angle) >= 1e-5f;
  1154. _Path.reserve(_Path.Size + (a_mid_samples + 1 + (a_emit_start ? 1 : 0) + (a_emit_end ? 1 : 0)));
  1155. if (a_emit_start)
  1156. _Path.push_back(ImVec2(center.x + ImCos(a_min) * radius, center.y + ImSin(a_min) * radius));
  1157. if (a_mid_samples > 0)
  1158. _PathArcToFastEx(center, radius, a_min_sample, a_max_sample, 0);
  1159. if (a_emit_end)
  1160. _Path.push_back(ImVec2(center.x + ImCos(a_max) * radius, center.y + ImSin(a_max) * radius));
  1161. }
  1162. else
  1163. {
  1164. const float arc_length = ImAbs(a_max - a_min);
  1165. const int circle_segment_count = _CalcCircleAutoSegmentCount(radius);
  1166. const int arc_segment_count = ImMax((int)ImCeil(circle_segment_count * arc_length / (IM_PI * 2.0f)), (int)(2.0f * IM_PI / arc_length));
  1167. _PathArcToN(center, radius, a_min, a_max, arc_segment_count);
  1168. }
  1169. }
  1170. void ImDrawList::PathEllipticalArcTo(const ImVec2& center, const ImVec2& radius, float rot, float a_min, float a_max, int num_segments)
  1171. {
  1172. if (num_segments <= 0)
  1173. num_segments = _CalcCircleAutoSegmentCount(ImMax(radius.x, radius.y)); // A bit pessimistic, maybe there's a better computation to do here.
  1174. _Path.reserve(_Path.Size + (num_segments + 1));
  1175. const float cos_rot = ImCos(rot);
  1176. const float sin_rot = ImSin(rot);
  1177. for (int i = 0; i <= num_segments; i++)
  1178. {
  1179. const float a = a_min + ((float)i / (float)num_segments) * (a_max - a_min);
  1180. ImVec2 point(ImCos(a) * radius.x, ImSin(a) * radius.y);
  1181. const ImVec2 rel((point.x * cos_rot) - (point.y * sin_rot), (point.x * sin_rot) + (point.y * cos_rot));
  1182. point.x = rel.x + center.x;
  1183. point.y = rel.y + center.y;
  1184. _Path.push_back(point);
  1185. }
  1186. }
  1187. ImVec2 ImBezierCubicCalc(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, float t)
  1188. {
  1189. float u = 1.0f - t;
  1190. float w1 = u * u * u;
  1191. float w2 = 3 * u * u * t;
  1192. float w3 = 3 * u * t * t;
  1193. float w4 = t * t * t;
  1194. return ImVec2(w1 * p1.x + w2 * p2.x + w3 * p3.x + w4 * p4.x, w1 * p1.y + w2 * p2.y + w3 * p3.y + w4 * p4.y);
  1195. }
  1196. ImVec2 ImBezierQuadraticCalc(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, float t)
  1197. {
  1198. float u = 1.0f - t;
  1199. float w1 = u * u;
  1200. float w2 = 2 * u * t;
  1201. float w3 = t * t;
  1202. return ImVec2(w1 * p1.x + w2 * p2.x + w3 * p3.x, w1 * p1.y + w2 * p2.y + w3 * p3.y);
  1203. }
  1204. // Closely mimics ImBezierCubicClosestPointCasteljau() in imgui.cpp
  1205. static void PathBezierCubicCurveToCasteljau(ImVector<ImVec2>* path, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float tess_tol, int level)
  1206. {
  1207. float dx = x4 - x1;
  1208. float dy = y4 - y1;
  1209. float d2 = (x2 - x4) * dy - (y2 - y4) * dx;
  1210. float d3 = (x3 - x4) * dy - (y3 - y4) * dx;
  1211. d2 = (d2 >= 0) ? d2 : -d2;
  1212. d3 = (d3 >= 0) ? d3 : -d3;
  1213. if ((d2 + d3) * (d2 + d3) < tess_tol * (dx * dx + dy * dy))
  1214. {
  1215. path->push_back(ImVec2(x4, y4));
  1216. }
  1217. else if (level < 10)
  1218. {
  1219. float x12 = (x1 + x2) * 0.5f, y12 = (y1 + y2) * 0.5f;
  1220. float x23 = (x2 + x3) * 0.5f, y23 = (y2 + y3) * 0.5f;
  1221. float x34 = (x3 + x4) * 0.5f, y34 = (y3 + y4) * 0.5f;
  1222. float x123 = (x12 + x23) * 0.5f, y123 = (y12 + y23) * 0.5f;
  1223. float x234 = (x23 + x34) * 0.5f, y234 = (y23 + y34) * 0.5f;
  1224. float x1234 = (x123 + x234) * 0.5f, y1234 = (y123 + y234) * 0.5f;
  1225. PathBezierCubicCurveToCasteljau(path, x1, y1, x12, y12, x123, y123, x1234, y1234, tess_tol, level + 1);
  1226. PathBezierCubicCurveToCasteljau(path, x1234, y1234, x234, y234, x34, y34, x4, y4, tess_tol, level + 1);
  1227. }
  1228. }
  1229. static void PathBezierQuadraticCurveToCasteljau(ImVector<ImVec2>* path, float x1, float y1, float x2, float y2, float x3, float y3, float tess_tol, int level)
  1230. {
  1231. float dx = x3 - x1, dy = y3 - y1;
  1232. float det = (x2 - x3) * dy - (y2 - y3) * dx;
  1233. if (det * det * 4.0f < tess_tol * (dx * dx + dy * dy))
  1234. {
  1235. path->push_back(ImVec2(x3, y3));
  1236. }
  1237. else if (level < 10)
  1238. {
  1239. float x12 = (x1 + x2) * 0.5f, y12 = (y1 + y2) * 0.5f;
  1240. float x23 = (x2 + x3) * 0.5f, y23 = (y2 + y3) * 0.5f;
  1241. float x123 = (x12 + x23) * 0.5f, y123 = (y12 + y23) * 0.5f;
  1242. PathBezierQuadraticCurveToCasteljau(path, x1, y1, x12, y12, x123, y123, tess_tol, level + 1);
  1243. PathBezierQuadraticCurveToCasteljau(path, x123, y123, x23, y23, x3, y3, tess_tol, level + 1);
  1244. }
  1245. }
  1246. void ImDrawList::PathBezierCubicCurveTo(const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, int num_segments)
  1247. {
  1248. ImVec2 p1 = _Path.back();
  1249. if (num_segments == 0)
  1250. {
  1251. IM_ASSERT(_Data->CurveTessellationTol > 0.0f);
  1252. PathBezierCubicCurveToCasteljau(&_Path, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, _Data->CurveTessellationTol, 0); // Auto-tessellated
  1253. }
  1254. else
  1255. {
  1256. float t_step = 1.0f / (float)num_segments;
  1257. for (int i_step = 1; i_step <= num_segments; i_step++)
  1258. _Path.push_back(ImBezierCubicCalc(p1, p2, p3, p4, t_step * i_step));
  1259. }
  1260. }
  1261. void ImDrawList::PathBezierQuadraticCurveTo(const ImVec2& p2, const ImVec2& p3, int num_segments)
  1262. {
  1263. ImVec2 p1 = _Path.back();
  1264. if (num_segments == 0)
  1265. {
  1266. IM_ASSERT(_Data->CurveTessellationTol > 0.0f);
  1267. PathBezierQuadraticCurveToCasteljau(&_Path, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, _Data->CurveTessellationTol, 0);// Auto-tessellated
  1268. }
  1269. else
  1270. {
  1271. float t_step = 1.0f / (float)num_segments;
  1272. for (int i_step = 1; i_step <= num_segments; i_step++)
  1273. _Path.push_back(ImBezierQuadraticCalc(p1, p2, p3, t_step * i_step));
  1274. }
  1275. }
  1276. static inline ImDrawFlags FixRectCornerFlags(ImDrawFlags flags)
  1277. {
  1278. /*
  1279. IM_STATIC_ASSERT(ImDrawFlags_RoundCornersTopLeft == (1 << 4));
  1280. #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
  1281. // Obsoleted in 1.82 (from February 2021). This code was stripped/simplified and mostly commented in 1.90 (from September 2023)
  1282. // - Legacy Support for hard coded ~0 (used to be a suggested equivalent to ImDrawCornerFlags_All)
  1283. if (flags == ~0) { return ImDrawFlags_RoundCornersAll; }
  1284. // - Legacy Support for hard coded 0x01 to 0x0F (matching 15 out of 16 old flags combinations). Read details in older version of this code.
  1285. if (flags >= 0x01 && flags <= 0x0F) { return (flags << 4); }
  1286. // We cannot support hard coded 0x00 with 'float rounding > 0.0f' --> replace with ImDrawFlags_RoundCornersNone or use 'float rounding = 0.0f'
  1287. #endif
  1288. */
  1289. // If this assert triggers, please update your code replacing hardcoded values with new ImDrawFlags_RoundCorners* values.
  1290. // Note that ImDrawFlags_Closed (== 0x01) is an invalid flag for AddRect(), AddRectFilled(), PathRect() etc. anyway.
  1291. // See details in 1.82 Changelog as well as 2021/03/12 and 2023/09/08 entries in "API BREAKING CHANGES" section.
  1292. IM_ASSERT((flags & 0x0F) == 0 && "Misuse of legacy hardcoded ImDrawCornerFlags values!");
  1293. if ((flags & ImDrawFlags_RoundCornersMask_) == 0)
  1294. flags |= ImDrawFlags_RoundCornersAll;
  1295. return flags;
  1296. }
  1297. void ImDrawList::PathRect(const ImVec2& a, const ImVec2& b, float rounding, ImDrawFlags flags)
  1298. {
  1299. if (rounding >= 0.5f)
  1300. {
  1301. flags = FixRectCornerFlags(flags);
  1302. rounding = ImMin(rounding, ImFabs(b.x - a.x) * (((flags & ImDrawFlags_RoundCornersTop) == ImDrawFlags_RoundCornersTop) || ((flags & ImDrawFlags_RoundCornersBottom) == ImDrawFlags_RoundCornersBottom) ? 0.5f : 1.0f) - 1.0f);
  1303. rounding = ImMin(rounding, ImFabs(b.y - a.y) * (((flags & ImDrawFlags_RoundCornersLeft) == ImDrawFlags_RoundCornersLeft) || ((flags & ImDrawFlags_RoundCornersRight) == ImDrawFlags_RoundCornersRight) ? 0.5f : 1.0f) - 1.0f);
  1304. }
  1305. if (rounding < 0.5f || (flags & ImDrawFlags_RoundCornersMask_) == ImDrawFlags_RoundCornersNone)
  1306. {
  1307. PathLineTo(a);
  1308. PathLineTo(ImVec2(b.x, a.y));
  1309. PathLineTo(b);
  1310. PathLineTo(ImVec2(a.x, b.y));
  1311. }
  1312. else
  1313. {
  1314. const float rounding_tl = (flags & ImDrawFlags_RoundCornersTopLeft) ? rounding : 0.0f;
  1315. const float rounding_tr = (flags & ImDrawFlags_RoundCornersTopRight) ? rounding : 0.0f;
  1316. const float rounding_br = (flags & ImDrawFlags_RoundCornersBottomRight) ? rounding : 0.0f;
  1317. const float rounding_bl = (flags & ImDrawFlags_RoundCornersBottomLeft) ? rounding : 0.0f;
  1318. PathArcToFast(ImVec2(a.x + rounding_tl, a.y + rounding_tl), rounding_tl, 6, 9);
  1319. PathArcToFast(ImVec2(b.x - rounding_tr, a.y + rounding_tr), rounding_tr, 9, 12);
  1320. PathArcToFast(ImVec2(b.x - rounding_br, b.y - rounding_br), rounding_br, 0, 3);
  1321. PathArcToFast(ImVec2(a.x + rounding_bl, b.y - rounding_bl), rounding_bl, 3, 6);
  1322. }
  1323. }
  1324. void ImDrawList::AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float thickness)
  1325. {
  1326. if ((col & IM_COL32_A_MASK) == 0)
  1327. return;
  1328. PathLineTo(p1 + ImVec2(0.5f, 0.5f));
  1329. PathLineTo(p2 + ImVec2(0.5f, 0.5f));
  1330. PathStroke(col, 0, thickness);
  1331. }
  1332. // p_min = upper-left, p_max = lower-right
  1333. // Note we don't render 1 pixels sized rectangles properly.
  1334. void ImDrawList::AddRect(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding, ImDrawFlags flags, float thickness)
  1335. {
  1336. if ((col & IM_COL32_A_MASK) == 0)
  1337. return;
  1338. if (Flags & ImDrawListFlags_AntiAliasedLines)
  1339. PathRect(p_min + ImVec2(0.50f, 0.50f), p_max - ImVec2(0.50f, 0.50f), rounding, flags);
  1340. else
  1341. PathRect(p_min + ImVec2(0.50f, 0.50f), p_max - ImVec2(0.49f, 0.49f), rounding, flags); // Better looking lower-right corner and rounded non-AA shapes.
  1342. PathStroke(col, ImDrawFlags_Closed, thickness);
  1343. }
  1344. void ImDrawList::AddRectFilled(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding, ImDrawFlags flags)
  1345. {
  1346. if ((col & IM_COL32_A_MASK) == 0)
  1347. return;
  1348. if (rounding < 0.5f || (flags & ImDrawFlags_RoundCornersMask_) == ImDrawFlags_RoundCornersNone)
  1349. {
  1350. PrimReserve(6, 4);
  1351. PrimRect(p_min, p_max, col);
  1352. }
  1353. else
  1354. {
  1355. PathRect(p_min, p_max, rounding, flags);
  1356. PathFillConvex(col);
  1357. }
  1358. }
  1359. // p_min = upper-left, p_max = lower-right
  1360. void ImDrawList::AddRectFilledMultiColor(const ImVec2& p_min, const ImVec2& p_max, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left)
  1361. {
  1362. if (((col_upr_left | col_upr_right | col_bot_right | col_bot_left) & IM_COL32_A_MASK) == 0)
  1363. return;
  1364. const ImVec2 uv = _Data->TexUvWhitePixel;
  1365. PrimReserve(6, 4);
  1366. PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx)); PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx + 1)); PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx + 2));
  1367. PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx)); PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx + 2)); PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx + 3));
  1368. PrimWriteVtx(p_min, uv, col_upr_left);
  1369. PrimWriteVtx(ImVec2(p_max.x, p_min.y), uv, col_upr_right);
  1370. PrimWriteVtx(p_max, uv, col_bot_right);
  1371. PrimWriteVtx(ImVec2(p_min.x, p_max.y), uv, col_bot_left);
  1372. }
  1373. void ImDrawList::AddQuad(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col, float thickness)
  1374. {
  1375. if ((col & IM_COL32_A_MASK) == 0)
  1376. return;
  1377. PathLineTo(p1);
  1378. PathLineTo(p2);
  1379. PathLineTo(p3);
  1380. PathLineTo(p4);
  1381. PathStroke(col, ImDrawFlags_Closed, thickness);
  1382. }
  1383. void ImDrawList::AddQuadFilled(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col)
  1384. {
  1385. if ((col & IM_COL32_A_MASK) == 0)
  1386. return;
  1387. PathLineTo(p1);
  1388. PathLineTo(p2);
  1389. PathLineTo(p3);
  1390. PathLineTo(p4);
  1391. PathFillConvex(col);
  1392. }
  1393. void ImDrawList::AddTriangle(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col, float thickness)
  1394. {
  1395. if ((col & IM_COL32_A_MASK) == 0)
  1396. return;
  1397. PathLineTo(p1);
  1398. PathLineTo(p2);
  1399. PathLineTo(p3);
  1400. PathStroke(col, ImDrawFlags_Closed, thickness);
  1401. }
  1402. void ImDrawList::AddTriangleFilled(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col)
  1403. {
  1404. if ((col & IM_COL32_A_MASK) == 0)
  1405. return;
  1406. PathLineTo(p1);
  1407. PathLineTo(p2);
  1408. PathLineTo(p3);
  1409. PathFillConvex(col);
  1410. }
  1411. void ImDrawList::AddCircle(const ImVec2& center, float radius, ImU32 col, int num_segments, float thickness)
  1412. {
  1413. if ((col & IM_COL32_A_MASK) == 0 || radius < 0.5f)
  1414. return;
  1415. if (num_segments <= 0)
  1416. {
  1417. // Use arc with automatic segment count
  1418. _PathArcToFastEx(center, radius - 0.5f, 0, IM_DRAWLIST_ARCFAST_SAMPLE_MAX, 0);
  1419. _Path.Size--;
  1420. }
  1421. else
  1422. {
  1423. // Explicit segment count (still clamp to avoid drawing insanely tessellated shapes)
  1424. num_segments = ImClamp(num_segments, 3, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX);
  1425. // Because we are filling a closed shape we remove 1 from the count of segments/points
  1426. const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments;
  1427. PathArcTo(center, radius - 0.5f, 0.0f, a_max, num_segments - 1);
  1428. }
  1429. PathStroke(col, ImDrawFlags_Closed, thickness);
  1430. }
  1431. void ImDrawList::AddCircleFilled(const ImVec2& center, float radius, ImU32 col, int num_segments)
  1432. {
  1433. if ((col & IM_COL32_A_MASK) == 0 || radius < 0.5f)
  1434. return;
  1435. if (num_segments <= 0)
  1436. {
  1437. // Use arc with automatic segment count
  1438. _PathArcToFastEx(center, radius, 0, IM_DRAWLIST_ARCFAST_SAMPLE_MAX, 0);
  1439. _Path.Size--;
  1440. }
  1441. else
  1442. {
  1443. // Explicit segment count (still clamp to avoid drawing insanely tessellated shapes)
  1444. num_segments = ImClamp(num_segments, 3, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX);
  1445. // Because we are filling a closed shape we remove 1 from the count of segments/points
  1446. const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments;
  1447. PathArcTo(center, radius, 0.0f, a_max, num_segments - 1);
  1448. }
  1449. PathFillConvex(col);
  1450. }
  1451. // Guaranteed to honor 'num_segments'
  1452. void ImDrawList::AddNgon(const ImVec2& center, float radius, ImU32 col, int num_segments, float thickness)
  1453. {
  1454. if ((col & IM_COL32_A_MASK) == 0 || num_segments <= 2)
  1455. return;
  1456. // Because we are filling a closed shape we remove 1 from the count of segments/points
  1457. const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments;
  1458. PathArcTo(center, radius - 0.5f, 0.0f, a_max, num_segments - 1);
  1459. PathStroke(col, ImDrawFlags_Closed, thickness);
  1460. }
  1461. // Guaranteed to honor 'num_segments'
  1462. void ImDrawList::AddNgonFilled(const ImVec2& center, float radius, ImU32 col, int num_segments)
  1463. {
  1464. if ((col & IM_COL32_A_MASK) == 0 || num_segments <= 2)
  1465. return;
  1466. // Because we are filling a closed shape we remove 1 from the count of segments/points
  1467. const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments;
  1468. PathArcTo(center, radius, 0.0f, a_max, num_segments - 1);
  1469. PathFillConvex(col);
  1470. }
  1471. // Ellipse
  1472. void ImDrawList::AddEllipse(const ImVec2& center, const ImVec2& radius, ImU32 col, float rot, int num_segments, float thickness)
  1473. {
  1474. if ((col & IM_COL32_A_MASK) == 0)
  1475. return;
  1476. if (num_segments <= 0)
  1477. num_segments = _CalcCircleAutoSegmentCount(ImMax(radius.x, radius.y)); // A bit pessimistic, maybe there's a better computation to do here.
  1478. // Because we are filling a closed shape we remove 1 from the count of segments/points
  1479. const float a_max = IM_PI * 2.0f * ((float)num_segments - 1.0f) / (float)num_segments;
  1480. PathEllipticalArcTo(center, radius, rot, 0.0f, a_max, num_segments - 1);
  1481. PathStroke(col, true, thickness);
  1482. }
  1483. void ImDrawList::AddEllipseFilled(const ImVec2& center, const ImVec2& radius, ImU32 col, float rot, int num_segments)
  1484. {
  1485. if ((col & IM_COL32_A_MASK) == 0)
  1486. return;
  1487. if (num_segments <= 0)
  1488. num_segments = _CalcCircleAutoSegmentCount(ImMax(radius.x, radius.y)); // A bit pessimistic, maybe there's a better computation to do here.
  1489. // Because we are filling a closed shape we remove 1 from the count of segments/points
  1490. const float a_max = IM_PI * 2.0f * ((float)num_segments - 1.0f) / (float)num_segments;
  1491. PathEllipticalArcTo(center, radius, rot, 0.0f, a_max, num_segments - 1);
  1492. PathFillConvex(col);
  1493. }
  1494. // Cubic Bezier takes 4 controls points
  1495. void ImDrawList::AddBezierCubic(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col, float thickness, int num_segments)
  1496. {
  1497. if ((col & IM_COL32_A_MASK) == 0)
  1498. return;
  1499. PathLineTo(p1);
  1500. PathBezierCubicCurveTo(p2, p3, p4, num_segments);
  1501. PathStroke(col, 0, thickness);
  1502. }
  1503. // Quadratic Bezier takes 3 controls points
  1504. void ImDrawList::AddBezierQuadratic(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col, float thickness, int num_segments)
  1505. {
  1506. if ((col & IM_COL32_A_MASK) == 0)
  1507. return;
  1508. PathLineTo(p1);
  1509. PathBezierQuadraticCurveTo(p2, p3, num_segments);
  1510. PathStroke(col, 0, thickness);
  1511. }
  1512. void ImDrawList::AddText(ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end, float wrap_width, const ImVec4* cpu_fine_clip_rect)
  1513. {
  1514. if ((col & IM_COL32_A_MASK) == 0)
  1515. return;
  1516. // Accept null ranges
  1517. if (text_begin == text_end || text_begin[0] == 0)
  1518. return;
  1519. // No need to strlen() here: font->RenderText() will do it and may early out.
  1520. // Pull default font/size from the shared ImDrawListSharedData instance
  1521. if (font == NULL)
  1522. font = _Data->Font;
  1523. if (font_size == 0.0f)
  1524. font_size = _Data->FontSize;
  1525. ImVec4 clip_rect = _CmdHeader.ClipRect;
  1526. if (cpu_fine_clip_rect)
  1527. {
  1528. clip_rect.x = ImMax(clip_rect.x, cpu_fine_clip_rect->x);
  1529. clip_rect.y = ImMax(clip_rect.y, cpu_fine_clip_rect->y);
  1530. clip_rect.z = ImMin(clip_rect.z, cpu_fine_clip_rect->z);
  1531. clip_rect.w = ImMin(clip_rect.w, cpu_fine_clip_rect->w);
  1532. }
  1533. font->RenderText(this, font_size, pos, col, clip_rect, text_begin, text_end, wrap_width, cpu_fine_clip_rect != NULL);
  1534. }
  1535. void ImDrawList::AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end)
  1536. {
  1537. AddText(_Data->Font, _Data->FontSize, pos, col, text_begin, text_end);
  1538. }
  1539. void ImDrawList::AddImage(ImTextureRef tex_ref, const ImVec2& p_min, const ImVec2& p_max, const ImVec2& uv_min, const ImVec2& uv_max, ImU32 col)
  1540. {
  1541. if ((col & IM_COL32_A_MASK) == 0)
  1542. return;
  1543. const bool push_texture_id = tex_ref != _CmdHeader.TexRef;
  1544. if (push_texture_id)
  1545. PushTexture(tex_ref);
  1546. PrimReserve(6, 4);
  1547. PrimRectUV(p_min, p_max, uv_min, uv_max, col);
  1548. if (push_texture_id)
  1549. PopTexture();
  1550. }
  1551. void ImDrawList::AddImageQuad(ImTextureRef tex_ref, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, const ImVec2& uv1, const ImVec2& uv2, const ImVec2& uv3, const ImVec2& uv4, ImU32 col)
  1552. {
  1553. if ((col & IM_COL32_A_MASK) == 0)
  1554. return;
  1555. const bool push_texture_id = tex_ref != _CmdHeader.TexRef;
  1556. if (push_texture_id)
  1557. PushTexture(tex_ref);
  1558. PrimReserve(6, 4);
  1559. PrimQuadUV(p1, p2, p3, p4, uv1, uv2, uv3, uv4, col);
  1560. if (push_texture_id)
  1561. PopTexture();
  1562. }
  1563. void ImDrawList::AddImageRounded(ImTextureRef tex_ref, const ImVec2& p_min, const ImVec2& p_max, const ImVec2& uv_min, const ImVec2& uv_max, ImU32 col, float rounding, ImDrawFlags flags)
  1564. {
  1565. if ((col & IM_COL32_A_MASK) == 0)
  1566. return;
  1567. flags = FixRectCornerFlags(flags);
  1568. if (rounding < 0.5f || (flags & ImDrawFlags_RoundCornersMask_) == ImDrawFlags_RoundCornersNone)
  1569. {
  1570. AddImage(tex_ref, p_min, p_max, uv_min, uv_max, col);
  1571. return;
  1572. }
  1573. const bool push_texture_id = tex_ref != _CmdHeader.TexRef;
  1574. if (push_texture_id)
  1575. PushTexture(tex_ref);
  1576. int vert_start_idx = VtxBuffer.Size;
  1577. PathRect(p_min, p_max, rounding, flags);
  1578. PathFillConvex(col);
  1579. int vert_end_idx = VtxBuffer.Size;
  1580. ImGui::ShadeVertsLinearUV(this, vert_start_idx, vert_end_idx, p_min, p_max, uv_min, uv_max, true);
  1581. if (push_texture_id)
  1582. PopTexture();
  1583. }
  1584. //-----------------------------------------------------------------------------
  1585. // [SECTION] ImTriangulator, ImDrawList concave polygon fill
  1586. //-----------------------------------------------------------------------------
  1587. // Triangulate concave polygons. Based on "Triangulation by Ear Clipping" paper, O(N^2) complexity.
  1588. // Reference: https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
  1589. // Provided as a convenience for user but not used by main library.
  1590. //-----------------------------------------------------------------------------
  1591. // - ImTriangulator [Internal]
  1592. // - AddConcavePolyFilled()
  1593. //-----------------------------------------------------------------------------
  1594. enum ImTriangulatorNodeType
  1595. {
  1596. ImTriangulatorNodeType_Convex,
  1597. ImTriangulatorNodeType_Ear,
  1598. ImTriangulatorNodeType_Reflex
  1599. };
  1600. struct ImTriangulatorNode
  1601. {
  1602. ImTriangulatorNodeType Type;
  1603. int Index;
  1604. ImVec2 Pos;
  1605. ImTriangulatorNode* Next;
  1606. ImTriangulatorNode* Prev;
  1607. void Unlink() { Next->Prev = Prev; Prev->Next = Next; }
  1608. };
  1609. struct ImTriangulatorNodeSpan
  1610. {
  1611. ImTriangulatorNode** Data = NULL;
  1612. int Size = 0;
  1613. void push_back(ImTriangulatorNode* node) { Data[Size++] = node; }
  1614. void find_erase_unsorted(int idx) { for (int i = Size - 1; i >= 0; i--) if (Data[i]->Index == idx) { Data[i] = Data[Size - 1]; Size--; return; } }
  1615. };
  1616. struct ImTriangulator
  1617. {
  1618. static int EstimateTriangleCount(int points_count) { return (points_count < 3) ? 0 : points_count - 2; }
  1619. static int EstimateScratchBufferSize(int points_count) { return sizeof(ImTriangulatorNode) * points_count + sizeof(ImTriangulatorNode*) * points_count * 2; }
  1620. void Init(const ImVec2* points, int points_count, void* scratch_buffer);
  1621. void GetNextTriangle(unsigned int out_triangle[3]); // Return relative indexes for next triangle
  1622. // Internal functions
  1623. void BuildNodes(const ImVec2* points, int points_count);
  1624. void BuildReflexes();
  1625. void BuildEars();
  1626. void FlipNodeList();
  1627. bool IsEar(int i0, int i1, int i2, const ImVec2& v0, const ImVec2& v1, const ImVec2& v2) const;
  1628. void ReclassifyNode(ImTriangulatorNode* node);
  1629. // Internal members
  1630. int _TrianglesLeft = 0;
  1631. ImTriangulatorNode* _Nodes = NULL;
  1632. ImTriangulatorNodeSpan _Ears;
  1633. ImTriangulatorNodeSpan _Reflexes;
  1634. };
  1635. // Distribute storage for nodes, ears and reflexes.
  1636. // FIXME-OPT: if everything is convex, we could report it to caller and let it switch to an convex renderer
  1637. // (this would require first building reflexes to bail to convex if empty, without even building nodes)
  1638. void ImTriangulator::Init(const ImVec2* points, int points_count, void* scratch_buffer)
  1639. {
  1640. IM_ASSERT(scratch_buffer != NULL && points_count >= 3);
  1641. _TrianglesLeft = EstimateTriangleCount(points_count);
  1642. _Nodes = (ImTriangulatorNode*)scratch_buffer; // points_count x Node
  1643. _Ears.Data = (ImTriangulatorNode**)(_Nodes + points_count); // points_count x Node*
  1644. _Reflexes.Data = (ImTriangulatorNode**)(_Nodes + points_count) + points_count; // points_count x Node*
  1645. BuildNodes(points, points_count);
  1646. BuildReflexes();
  1647. BuildEars();
  1648. }
  1649. void ImTriangulator::BuildNodes(const ImVec2* points, int points_count)
  1650. {
  1651. for (int i = 0; i < points_count; i++)
  1652. {
  1653. _Nodes[i].Type = ImTriangulatorNodeType_Convex;
  1654. _Nodes[i].Index = i;
  1655. _Nodes[i].Pos = points[i];
  1656. _Nodes[i].Next = _Nodes + i + 1;
  1657. _Nodes[i].Prev = _Nodes + i - 1;
  1658. }
  1659. _Nodes[0].Prev = _Nodes + points_count - 1;
  1660. _Nodes[points_count - 1].Next = _Nodes;
  1661. }
  1662. void ImTriangulator::BuildReflexes()
  1663. {
  1664. ImTriangulatorNode* n1 = _Nodes;
  1665. for (int i = _TrianglesLeft; i >= 0; i--, n1 = n1->Next)
  1666. {
  1667. if (ImTriangleIsClockwise(n1->Prev->Pos, n1->Pos, n1->Next->Pos))
  1668. continue;
  1669. n1->Type = ImTriangulatorNodeType_Reflex;
  1670. _Reflexes.push_back(n1);
  1671. }
  1672. }
  1673. void ImTriangulator::BuildEars()
  1674. {
  1675. ImTriangulatorNode* n1 = _Nodes;
  1676. for (int i = _TrianglesLeft; i >= 0; i--, n1 = n1->Next)
  1677. {
  1678. if (n1->Type != ImTriangulatorNodeType_Convex)
  1679. continue;
  1680. if (!IsEar(n1->Prev->Index, n1->Index, n1->Next->Index, n1->Prev->Pos, n1->Pos, n1->Next->Pos))
  1681. continue;
  1682. n1->Type = ImTriangulatorNodeType_Ear;
  1683. _Ears.push_back(n1);
  1684. }
  1685. }
  1686. void ImTriangulator::GetNextTriangle(unsigned int out_triangle[3])
  1687. {
  1688. if (_Ears.Size == 0)
  1689. {
  1690. FlipNodeList();
  1691. ImTriangulatorNode* node = _Nodes;
  1692. for (int i = _TrianglesLeft; i >= 0; i--, node = node->Next)
  1693. node->Type = ImTriangulatorNodeType_Convex;
  1694. _Reflexes.Size = 0;
  1695. BuildReflexes();
  1696. BuildEars();
  1697. // If we still don't have ears, it means geometry is degenerated.
  1698. if (_Ears.Size == 0)
  1699. {
  1700. // Return first triangle available, mimicking the behavior of convex fill.
  1701. IM_ASSERT(_TrianglesLeft > 0); // Geometry is degenerated
  1702. _Ears.Data[0] = _Nodes;
  1703. _Ears.Size = 1;
  1704. }
  1705. }
  1706. ImTriangulatorNode* ear = _Ears.Data[--_Ears.Size];
  1707. out_triangle[0] = ear->Prev->Index;
  1708. out_triangle[1] = ear->Index;
  1709. out_triangle[2] = ear->Next->Index;
  1710. ear->Unlink();
  1711. if (ear == _Nodes)
  1712. _Nodes = ear->Next;
  1713. ReclassifyNode(ear->Prev);
  1714. ReclassifyNode(ear->Next);
  1715. _TrianglesLeft--;
  1716. }
  1717. void ImTriangulator::FlipNodeList()
  1718. {
  1719. ImTriangulatorNode* prev = _Nodes;
  1720. ImTriangulatorNode* temp = _Nodes;
  1721. ImTriangulatorNode* current = _Nodes->Next;
  1722. prev->Next = prev;
  1723. prev->Prev = prev;
  1724. while (current != _Nodes)
  1725. {
  1726. temp = current->Next;
  1727. current->Next = prev;
  1728. prev->Prev = current;
  1729. _Nodes->Next = current;
  1730. current->Prev = _Nodes;
  1731. prev = current;
  1732. current = temp;
  1733. }
  1734. _Nodes = prev;
  1735. }
  1736. // A triangle is an ear is no other vertex is inside it. We can test reflexes vertices only (see reference algorithm)
  1737. bool ImTriangulator::IsEar(int i0, int i1, int i2, const ImVec2& v0, const ImVec2& v1, const ImVec2& v2) const
  1738. {
  1739. ImTriangulatorNode** p_end = _Reflexes.Data + _Reflexes.Size;
  1740. for (ImTriangulatorNode** p = _Reflexes.Data; p < p_end; p++)
  1741. {
  1742. ImTriangulatorNode* reflex = *p;
  1743. if (reflex->Index != i0 && reflex->Index != i1 && reflex->Index != i2)
  1744. if (ImTriangleContainsPoint(v0, v1, v2, reflex->Pos))
  1745. return false;
  1746. }
  1747. return true;
  1748. }
  1749. void ImTriangulator::ReclassifyNode(ImTriangulatorNode* n1)
  1750. {
  1751. // Classify node
  1752. ImTriangulatorNodeType type;
  1753. const ImTriangulatorNode* n0 = n1->Prev;
  1754. const ImTriangulatorNode* n2 = n1->Next;
  1755. if (!ImTriangleIsClockwise(n0->Pos, n1->Pos, n2->Pos))
  1756. type = ImTriangulatorNodeType_Reflex;
  1757. else if (IsEar(n0->Index, n1->Index, n2->Index, n0->Pos, n1->Pos, n2->Pos))
  1758. type = ImTriangulatorNodeType_Ear;
  1759. else
  1760. type = ImTriangulatorNodeType_Convex;
  1761. // Update lists when a type changes
  1762. if (type == n1->Type)
  1763. return;
  1764. if (n1->Type == ImTriangulatorNodeType_Reflex)
  1765. _Reflexes.find_erase_unsorted(n1->Index);
  1766. else if (n1->Type == ImTriangulatorNodeType_Ear)
  1767. _Ears.find_erase_unsorted(n1->Index);
  1768. if (type == ImTriangulatorNodeType_Reflex)
  1769. _Reflexes.push_back(n1);
  1770. else if (type == ImTriangulatorNodeType_Ear)
  1771. _Ears.push_back(n1);
  1772. n1->Type = type;
  1773. }
  1774. // Use ear-clipping algorithm to triangulate a simple polygon (no self-interaction, no holes).
  1775. // (Reminder: we don't perform any coarse clipping/culling in ImDrawList layer!
  1776. // It is up to caller to ensure not making costly calls that will be outside of visible area.
  1777. // As concave fill is noticeably more expensive than other primitives, be mindful of this...
  1778. // Caller can build AABB of points, and avoid filling if 'draw_list->_CmdHeader.ClipRect.Overlays(points_bb) == false')
  1779. void ImDrawList::AddConcavePolyFilled(const ImVec2* points, const int points_count, ImU32 col)
  1780. {
  1781. if (points_count < 3 || (col & IM_COL32_A_MASK) == 0)
  1782. return;
  1783. const ImVec2 uv = _Data->TexUvWhitePixel;
  1784. ImTriangulator triangulator;
  1785. unsigned int triangle[3];
  1786. if (Flags & ImDrawListFlags_AntiAliasedFill)
  1787. {
  1788. // Anti-aliased Fill
  1789. const float AA_SIZE = _FringeScale;
  1790. const ImU32 col_trans = col & ~IM_COL32_A_MASK;
  1791. const int idx_count = (points_count - 2) * 3 + points_count * 6;
  1792. const int vtx_count = (points_count * 2);
  1793. PrimReserve(idx_count, vtx_count);
  1794. // Add indexes for fill
  1795. unsigned int vtx_inner_idx = _VtxCurrentIdx;
  1796. unsigned int vtx_outer_idx = _VtxCurrentIdx + 1;
  1797. _Data->TempBuffer.reserve_discard((ImTriangulator::EstimateScratchBufferSize(points_count) + sizeof(ImVec2)) / sizeof(ImVec2));
  1798. triangulator.Init(points, points_count, _Data->TempBuffer.Data);
  1799. while (triangulator._TrianglesLeft > 0)
  1800. {
  1801. triangulator.GetNextTriangle(triangle);
  1802. _IdxWritePtr[0] = (ImDrawIdx)(vtx_inner_idx + (triangle[0] << 1)); _IdxWritePtr[1] = (ImDrawIdx)(vtx_inner_idx + (triangle[1] << 1)); _IdxWritePtr[2] = (ImDrawIdx)(vtx_inner_idx + (triangle[2] << 1));
  1803. _IdxWritePtr += 3;
  1804. }
  1805. // Compute normals
  1806. _Data->TempBuffer.reserve_discard(points_count);
  1807. ImVec2* temp_normals = _Data->TempBuffer.Data;
  1808. for (int i0 = points_count - 1, i1 = 0; i1 < points_count; i0 = i1++)
  1809. {
  1810. const ImVec2& p0 = points[i0];
  1811. const ImVec2& p1 = points[i1];
  1812. float dx = p1.x - p0.x;
  1813. float dy = p1.y - p0.y;
  1814. IM_NORMALIZE2F_OVER_ZERO(dx, dy);
  1815. temp_normals[i0].x = dy;
  1816. temp_normals[i0].y = -dx;
  1817. }
  1818. for (int i0 = points_count - 1, i1 = 0; i1 < points_count; i0 = i1++)
  1819. {
  1820. // Average normals
  1821. const ImVec2& n0 = temp_normals[i0];
  1822. const ImVec2& n1 = temp_normals[i1];
  1823. float dm_x = (n0.x + n1.x) * 0.5f;
  1824. float dm_y = (n0.y + n1.y) * 0.5f;
  1825. IM_FIXNORMAL2F(dm_x, dm_y);
  1826. dm_x *= AA_SIZE * 0.5f;
  1827. dm_y *= AA_SIZE * 0.5f;
  1828. // Add vertices
  1829. _VtxWritePtr[0].pos.x = (points[i1].x - dm_x); _VtxWritePtr[0].pos.y = (points[i1].y - dm_y); _VtxWritePtr[0].uv = uv; _VtxWritePtr[0].col = col; // Inner
  1830. _VtxWritePtr[1].pos.x = (points[i1].x + dm_x); _VtxWritePtr[1].pos.y = (points[i1].y + dm_y); _VtxWritePtr[1].uv = uv; _VtxWritePtr[1].col = col_trans; // Outer
  1831. _VtxWritePtr += 2;
  1832. // Add indexes for fringes
  1833. _IdxWritePtr[0] = (ImDrawIdx)(vtx_inner_idx + (i1 << 1)); _IdxWritePtr[1] = (ImDrawIdx)(vtx_inner_idx + (i0 << 1)); _IdxWritePtr[2] = (ImDrawIdx)(vtx_outer_idx + (i0 << 1));
  1834. _IdxWritePtr[3] = (ImDrawIdx)(vtx_outer_idx + (i0 << 1)); _IdxWritePtr[4] = (ImDrawIdx)(vtx_outer_idx + (i1 << 1)); _IdxWritePtr[5] = (ImDrawIdx)(vtx_inner_idx + (i1 << 1));
  1835. _IdxWritePtr += 6;
  1836. }
  1837. _VtxCurrentIdx += (ImDrawIdx)vtx_count;
  1838. }
  1839. else
  1840. {
  1841. // Non Anti-aliased Fill
  1842. const int idx_count = (points_count - 2) * 3;
  1843. const int vtx_count = points_count;
  1844. PrimReserve(idx_count, vtx_count);
  1845. for (int i = 0; i < vtx_count; i++)
  1846. {
  1847. _VtxWritePtr[0].pos = points[i]; _VtxWritePtr[0].uv = uv; _VtxWritePtr[0].col = col;
  1848. _VtxWritePtr++;
  1849. }
  1850. _Data->TempBuffer.reserve_discard((ImTriangulator::EstimateScratchBufferSize(points_count) + sizeof(ImVec2)) / sizeof(ImVec2));
  1851. triangulator.Init(points, points_count, _Data->TempBuffer.Data);
  1852. while (triangulator._TrianglesLeft > 0)
  1853. {
  1854. triangulator.GetNextTriangle(triangle);
  1855. _IdxWritePtr[0] = (ImDrawIdx)(_VtxCurrentIdx + triangle[0]); _IdxWritePtr[1] = (ImDrawIdx)(_VtxCurrentIdx + triangle[1]); _IdxWritePtr[2] = (ImDrawIdx)(_VtxCurrentIdx + triangle[2]);
  1856. _IdxWritePtr += 3;
  1857. }
  1858. _VtxCurrentIdx += (ImDrawIdx)vtx_count;
  1859. }
  1860. }
  1861. //-----------------------------------------------------------------------------
  1862. // [SECTION] ImDrawListSplitter
  1863. //-----------------------------------------------------------------------------
  1864. // FIXME: This may be a little confusing, trying to be a little too low-level/optimal instead of just doing vector swap..
  1865. //-----------------------------------------------------------------------------
  1866. void ImDrawListSplitter::ClearFreeMemory()
  1867. {
  1868. for (int i = 0; i < _Channels.Size; i++)
  1869. {
  1870. if (i == _Current)
  1871. memset(&_Channels[i], 0, sizeof(_Channels[i])); // Current channel is a copy of CmdBuffer/IdxBuffer, don't destruct again
  1872. _Channels[i]._CmdBuffer.clear();
  1873. _Channels[i]._IdxBuffer.clear();
  1874. }
  1875. _Current = 0;
  1876. _Count = 1;
  1877. _Channels.clear();
  1878. }
  1879. void ImDrawListSplitter::Split(ImDrawList* draw_list, int channels_count)
  1880. {
  1881. IM_UNUSED(draw_list);
  1882. IM_ASSERT(_Current == 0 && _Count <= 1 && "Nested channel splitting is not supported. Please use separate instances of ImDrawListSplitter.");
  1883. int old_channels_count = _Channels.Size;
  1884. if (old_channels_count < channels_count)
  1885. {
  1886. _Channels.reserve(channels_count); // Avoid over reserving since this is likely to stay stable
  1887. _Channels.resize(channels_count);
  1888. }
  1889. _Count = channels_count;
  1890. // Channels[] (24/32 bytes each) hold storage that we'll swap with draw_list->_CmdBuffer/_IdxBuffer
  1891. // The content of Channels[0] at this point doesn't matter. We clear it to make state tidy in a debugger but we don't strictly need to.
  1892. // When we switch to the next channel, we'll copy draw_list->_CmdBuffer/_IdxBuffer into Channels[0] and then Channels[1] into draw_list->CmdBuffer/_IdxBuffer
  1893. memset(&_Channels[0], 0, sizeof(ImDrawChannel));
  1894. for (int i = 1; i < channels_count; i++)
  1895. {
  1896. if (i >= old_channels_count)
  1897. {
  1898. IM_PLACEMENT_NEW(&_Channels[i]) ImDrawChannel();
  1899. }
  1900. else
  1901. {
  1902. _Channels[i]._CmdBuffer.resize(0);
  1903. _Channels[i]._IdxBuffer.resize(0);
  1904. }
  1905. }
  1906. }
  1907. void ImDrawListSplitter::Merge(ImDrawList* draw_list)
  1908. {
  1909. // Note that we never use or rely on _Channels.Size because it is merely a buffer that we never shrink back to 0 to keep all sub-buffers ready for use.
  1910. if (_Count <= 1)
  1911. return;
  1912. SetCurrentChannel(draw_list, 0);
  1913. draw_list->_PopUnusedDrawCmd();
  1914. // Calculate our final buffer sizes. Also fix the incorrect IdxOffset values in each command.
  1915. int new_cmd_buffer_count = 0;
  1916. int new_idx_buffer_count = 0;
  1917. ImDrawCmd* last_cmd = (_Count > 0 && draw_list->CmdBuffer.Size > 0) ? &draw_list->CmdBuffer.back() : NULL;
  1918. int idx_offset = last_cmd ? last_cmd->IdxOffset + last_cmd->ElemCount : 0;
  1919. for (int i = 1; i < _Count; i++)
  1920. {
  1921. ImDrawChannel& ch = _Channels[i];
  1922. if (ch._CmdBuffer.Size > 0 && ch._CmdBuffer.back().ElemCount == 0 && ch._CmdBuffer.back().UserCallback == NULL) // Equivalent of PopUnusedDrawCmd()
  1923. ch._CmdBuffer.pop_back();
  1924. if (ch._CmdBuffer.Size > 0 && last_cmd != NULL)
  1925. {
  1926. // Do not include ImDrawCmd_AreSequentialIdxOffset() in the compare as we rebuild IdxOffset values ourselves.
  1927. // Manipulating IdxOffset (e.g. by reordering draw commands like done by RenderDimmedBackgroundBehindWindow()) is not supported within a splitter.
  1928. ImDrawCmd* next_cmd = &ch._CmdBuffer[0];
  1929. if (ImDrawCmd_HeaderCompare(last_cmd, next_cmd) == 0 && last_cmd->UserCallback == NULL && next_cmd->UserCallback == NULL)
  1930. {
  1931. // Merge previous channel last draw command with current channel first draw command if matching.
  1932. last_cmd->ElemCount += next_cmd->ElemCount;
  1933. idx_offset += next_cmd->ElemCount;
  1934. ch._CmdBuffer.erase(ch._CmdBuffer.Data); // FIXME-OPT: Improve for multiple merges.
  1935. }
  1936. }
  1937. if (ch._CmdBuffer.Size > 0)
  1938. last_cmd = &ch._CmdBuffer.back();
  1939. new_cmd_buffer_count += ch._CmdBuffer.Size;
  1940. new_idx_buffer_count += ch._IdxBuffer.Size;
  1941. for (int cmd_n = 0; cmd_n < ch._CmdBuffer.Size; cmd_n++)
  1942. {
  1943. ch._CmdBuffer.Data[cmd_n].IdxOffset = idx_offset;
  1944. idx_offset += ch._CmdBuffer.Data[cmd_n].ElemCount;
  1945. }
  1946. }
  1947. draw_list->CmdBuffer.resize(draw_list->CmdBuffer.Size + new_cmd_buffer_count);
  1948. draw_list->IdxBuffer.resize(draw_list->IdxBuffer.Size + new_idx_buffer_count);
  1949. // Write commands and indices in order (they are fairly small structures, we don't copy vertices only indices)
  1950. ImDrawCmd* cmd_write = draw_list->CmdBuffer.Data + draw_list->CmdBuffer.Size - new_cmd_buffer_count;
  1951. ImDrawIdx* idx_write = draw_list->IdxBuffer.Data + draw_list->IdxBuffer.Size - new_idx_buffer_count;
  1952. for (int i = 1; i < _Count; i++)
  1953. {
  1954. ImDrawChannel& ch = _Channels[i];
  1955. if (int sz = ch._CmdBuffer.Size) { memcpy(cmd_write, ch._CmdBuffer.Data, sz * sizeof(ImDrawCmd)); cmd_write += sz; }
  1956. if (int sz = ch._IdxBuffer.Size) { memcpy(idx_write, ch._IdxBuffer.Data, sz * sizeof(ImDrawIdx)); idx_write += sz; }
  1957. }
  1958. draw_list->_IdxWritePtr = idx_write;
  1959. // Ensure there's always a non-callback draw command trailing the command-buffer
  1960. if (draw_list->CmdBuffer.Size == 0 || draw_list->CmdBuffer.back().UserCallback != NULL)
  1961. draw_list->AddDrawCmd();
  1962. // If current command is used with different settings we need to add a new command
  1963. ImDrawCmd* curr_cmd = &draw_list->CmdBuffer.Data[draw_list->CmdBuffer.Size - 1];
  1964. if (curr_cmd->ElemCount == 0)
  1965. ImDrawCmd_HeaderCopy(curr_cmd, &draw_list->_CmdHeader); // Copy ClipRect, TexRef, VtxOffset
  1966. else if (ImDrawCmd_HeaderCompare(curr_cmd, &draw_list->_CmdHeader) != 0)
  1967. draw_list->AddDrawCmd();
  1968. _Count = 1;
  1969. }
  1970. void ImDrawListSplitter::SetCurrentChannel(ImDrawList* draw_list, int idx)
  1971. {
  1972. IM_ASSERT(idx >= 0 && idx < _Count);
  1973. if (_Current == idx)
  1974. return;
  1975. // Overwrite ImVector (12/16 bytes), four times. This is merely a silly optimization instead of doing .swap()
  1976. memcpy(&_Channels.Data[_Current]._CmdBuffer, &draw_list->CmdBuffer, sizeof(draw_list->CmdBuffer));
  1977. memcpy(&_Channels.Data[_Current]._IdxBuffer, &draw_list->IdxBuffer, sizeof(draw_list->IdxBuffer));
  1978. _Current = idx;
  1979. memcpy(&draw_list->CmdBuffer, &_Channels.Data[idx]._CmdBuffer, sizeof(draw_list->CmdBuffer));
  1980. memcpy(&draw_list->IdxBuffer, &_Channels.Data[idx]._IdxBuffer, sizeof(draw_list->IdxBuffer));
  1981. draw_list->_IdxWritePtr = draw_list->IdxBuffer.Data + draw_list->IdxBuffer.Size;
  1982. // If current command is used with different settings we need to add a new command
  1983. ImDrawCmd* curr_cmd = (draw_list->CmdBuffer.Size == 0) ? NULL : &draw_list->CmdBuffer.Data[draw_list->CmdBuffer.Size - 1];
  1984. if (curr_cmd == NULL)
  1985. draw_list->AddDrawCmd();
  1986. else if (curr_cmd->ElemCount == 0)
  1987. ImDrawCmd_HeaderCopy(curr_cmd, &draw_list->_CmdHeader); // Copy ClipRect, TexRef, VtxOffset
  1988. else if (ImDrawCmd_HeaderCompare(curr_cmd, &draw_list->_CmdHeader) != 0)
  1989. draw_list->AddDrawCmd();
  1990. }
  1991. //-----------------------------------------------------------------------------
  1992. // [SECTION] ImDrawData
  1993. //-----------------------------------------------------------------------------
  1994. void ImDrawData::Clear()
  1995. {
  1996. Valid = false;
  1997. CmdListsCount = TotalIdxCount = TotalVtxCount = 0;
  1998. CmdLists.resize(0); // The ImDrawList are NOT owned by ImDrawData but e.g. by ImGuiContext, so we don't clear them.
  1999. DisplayPos = DisplaySize = FramebufferScale = ImVec2(0.0f, 0.0f);
  2000. OwnerViewport = NULL;
  2001. Textures = NULL;
  2002. }
  2003. // Important: 'out_list' is generally going to be draw_data->CmdLists, but may be another temporary list
  2004. // as long at it is expected that the result will be later merged into draw_data->CmdLists[].
  2005. void ImGui::AddDrawListToDrawDataEx(ImDrawData* draw_data, ImVector<ImDrawList*>* out_list, ImDrawList* draw_list)
  2006. {
  2007. if (draw_list->CmdBuffer.Size == 0)
  2008. return;
  2009. if (draw_list->CmdBuffer.Size == 1 && draw_list->CmdBuffer[0].ElemCount == 0 && draw_list->CmdBuffer[0].UserCallback == NULL)
  2010. return;
  2011. // Draw list sanity check. Detect mismatch between PrimReserve() calls and incrementing _VtxCurrentIdx, _VtxWritePtr etc.
  2012. // May trigger for you if you are using PrimXXX functions incorrectly.
  2013. IM_ASSERT(draw_list->VtxBuffer.Size == 0 || draw_list->_VtxWritePtr == draw_list->VtxBuffer.Data + draw_list->VtxBuffer.Size);
  2014. IM_ASSERT(draw_list->IdxBuffer.Size == 0 || draw_list->_IdxWritePtr == draw_list->IdxBuffer.Data + draw_list->IdxBuffer.Size);
  2015. if (!(draw_list->Flags & ImDrawListFlags_AllowVtxOffset))
  2016. IM_ASSERT((int)draw_list->_VtxCurrentIdx == draw_list->VtxBuffer.Size);
  2017. // Check that draw_list doesn't use more vertices than indexable (default ImDrawIdx = unsigned short = 2 bytes = 64K vertices per ImDrawList = per window)
  2018. // If this assert triggers because you are drawing lots of stuff manually:
  2019. // - First, make sure you are coarse clipping yourself and not trying to draw many things outside visible bounds.
  2020. // Be mindful that the lower-level ImDrawList API doesn't filter vertices. Use the Metrics/Debugger window to inspect draw list contents.
  2021. // - If you want large meshes with more than 64K vertices, you can either:
  2022. // (A) Handle the ImDrawCmd::VtxOffset value in your renderer backend, and set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset'.
  2023. // Most example backends already support this from 1.71. Pre-1.71 backends won't.
  2024. // Some graphics API such as GL ES 1/2 don't have a way to offset the starting vertex so it is not supported for them.
  2025. // (B) Or handle 32-bit indices in your renderer backend, and uncomment '#define ImDrawIdx unsigned int' line in imconfig.h.
  2026. // Most example backends already support this. For example, the OpenGL example code detect index size at compile-time:
  2027. // glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset);
  2028. // Your own engine or render API may use different parameters or function calls to specify index sizes.
  2029. // 2 and 4 bytes indices are generally supported by most graphics API.
  2030. // - If for some reason neither of those solutions works for you, a workaround is to call BeginChild()/EndChild() before reaching
  2031. // the 64K limit to split your draw commands in multiple draw lists.
  2032. if (sizeof(ImDrawIdx) == 2)
  2033. IM_ASSERT(draw_list->_VtxCurrentIdx < (1 << 16) && "Too many vertices in ImDrawList using 16-bit indices. Read comment above");
  2034. // Resolve callback data pointers
  2035. if (draw_list->_CallbacksDataBuf.Size > 0)
  2036. for (ImDrawCmd& cmd : draw_list->CmdBuffer)
  2037. if (cmd.UserCallback != NULL && cmd.UserCallbackDataOffset != -1 && cmd.UserCallbackDataSize > 0)
  2038. cmd.UserCallbackData = draw_list->_CallbacksDataBuf.Data + cmd.UserCallbackDataOffset;
  2039. // Add to output list + records state in ImDrawData
  2040. out_list->push_back(draw_list);
  2041. draw_data->CmdListsCount++;
  2042. draw_data->TotalVtxCount += draw_list->VtxBuffer.Size;
  2043. draw_data->TotalIdxCount += draw_list->IdxBuffer.Size;
  2044. }
  2045. void ImDrawData::AddDrawList(ImDrawList* draw_list)
  2046. {
  2047. IM_ASSERT(CmdLists.Size == CmdListsCount);
  2048. draw_list->_PopUnusedDrawCmd();
  2049. ImGui::AddDrawListToDrawDataEx(this, &CmdLists, draw_list);
  2050. }
  2051. // For backward compatibility: convert all buffers from indexed to de-indexed, in case you cannot render indexed. Note: this is slow and most likely a waste of resources. Always prefer indexed rendering!
  2052. void ImDrawData::DeIndexAllBuffers()
  2053. {
  2054. ImVector<ImDrawVert> new_vtx_buffer;
  2055. TotalVtxCount = TotalIdxCount = 0;
  2056. for (int i = 0; i < CmdListsCount; i++)
  2057. {
  2058. ImDrawList* cmd_list = CmdLists[i];
  2059. if (cmd_list->IdxBuffer.empty())
  2060. continue;
  2061. new_vtx_buffer.resize(cmd_list->IdxBuffer.Size);
  2062. for (int j = 0; j < cmd_list->IdxBuffer.Size; j++)
  2063. new_vtx_buffer[j] = cmd_list->VtxBuffer[cmd_list->IdxBuffer[j]];
  2064. cmd_list->VtxBuffer.swap(new_vtx_buffer);
  2065. cmd_list->IdxBuffer.resize(0);
  2066. TotalVtxCount += cmd_list->VtxBuffer.Size;
  2067. }
  2068. }
  2069. // Helper to scale the ClipRect field of each ImDrawCmd.
  2070. // Use if your final output buffer is at a different scale than draw_data->DisplaySize,
  2071. // or if there is a difference between your window resolution and framebuffer resolution.
  2072. void ImDrawData::ScaleClipRects(const ImVec2& fb_scale)
  2073. {
  2074. for (ImDrawList* draw_list : CmdLists)
  2075. for (ImDrawCmd& cmd : draw_list->CmdBuffer)
  2076. cmd.ClipRect = ImVec4(cmd.ClipRect.x * fb_scale.x, cmd.ClipRect.y * fb_scale.y, cmd.ClipRect.z * fb_scale.x, cmd.ClipRect.w * fb_scale.y);
  2077. }
  2078. //-----------------------------------------------------------------------------
  2079. // [SECTION] Helpers ShadeVertsXXX functions
  2080. //-----------------------------------------------------------------------------
  2081. // Generic linear color gradient, write to RGB fields, leave A untouched.
  2082. void ImGui::ShadeVertsLinearColorGradientKeepAlpha(ImDrawList* draw_list, int vert_start_idx, int vert_end_idx, ImVec2 gradient_p0, ImVec2 gradient_p1, ImU32 col0, ImU32 col1)
  2083. {
  2084. ImVec2 gradient_extent = gradient_p1 - gradient_p0;
  2085. float gradient_inv_length2 = 1.0f / ImLengthSqr(gradient_extent);
  2086. ImDrawVert* vert_start = draw_list->VtxBuffer.Data + vert_start_idx;
  2087. ImDrawVert* vert_end = draw_list->VtxBuffer.Data + vert_end_idx;
  2088. const int col0_r = (int)(col0 >> IM_COL32_R_SHIFT) & 0xFF;
  2089. const int col0_g = (int)(col0 >> IM_COL32_G_SHIFT) & 0xFF;
  2090. const int col0_b = (int)(col0 >> IM_COL32_B_SHIFT) & 0xFF;
  2091. const int col_delta_r = ((int)(col1 >> IM_COL32_R_SHIFT) & 0xFF) - col0_r;
  2092. const int col_delta_g = ((int)(col1 >> IM_COL32_G_SHIFT) & 0xFF) - col0_g;
  2093. const int col_delta_b = ((int)(col1 >> IM_COL32_B_SHIFT) & 0xFF) - col0_b;
  2094. for (ImDrawVert* vert = vert_start; vert < vert_end; vert++)
  2095. {
  2096. float d = ImDot(vert->pos - gradient_p0, gradient_extent);
  2097. float t = ImClamp(d * gradient_inv_length2, 0.0f, 1.0f);
  2098. int r = (int)(col0_r + col_delta_r * t);
  2099. int g = (int)(col0_g + col_delta_g * t);
  2100. int b = (int)(col0_b + col_delta_b * t);
  2101. vert->col = (r << IM_COL32_R_SHIFT) | (g << IM_COL32_G_SHIFT) | (b << IM_COL32_B_SHIFT) | (vert->col & IM_COL32_A_MASK);
  2102. }
  2103. }
  2104. // Distribute UV over (a, b) rectangle
  2105. void ImGui::ShadeVertsLinearUV(ImDrawList* draw_list, int vert_start_idx, int vert_end_idx, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, bool clamp)
  2106. {
  2107. const ImVec2 size = b - a;
  2108. const ImVec2 uv_size = uv_b - uv_a;
  2109. const ImVec2 scale = ImVec2(
  2110. size.x != 0.0f ? (uv_size.x / size.x) : 0.0f,
  2111. size.y != 0.0f ? (uv_size.y / size.y) : 0.0f);
  2112. ImDrawVert* vert_start = draw_list->VtxBuffer.Data + vert_start_idx;
  2113. ImDrawVert* vert_end = draw_list->VtxBuffer.Data + vert_end_idx;
  2114. if (clamp)
  2115. {
  2116. const ImVec2 min = ImMin(uv_a, uv_b);
  2117. const ImVec2 max = ImMax(uv_a, uv_b);
  2118. for (ImDrawVert* vertex = vert_start; vertex < vert_end; ++vertex)
  2119. vertex->uv = ImClamp(uv_a + ImMul(ImVec2(vertex->pos.x, vertex->pos.y) - a, scale), min, max);
  2120. }
  2121. else
  2122. {
  2123. for (ImDrawVert* vertex = vert_start; vertex < vert_end; ++vertex)
  2124. vertex->uv = uv_a + ImMul(ImVec2(vertex->pos.x, vertex->pos.y) - a, scale);
  2125. }
  2126. }
  2127. void ImGui::ShadeVertsTransformPos(ImDrawList* draw_list, int vert_start_idx, int vert_end_idx, const ImVec2& pivot_in, float cos_a, float sin_a, const ImVec2& pivot_out)
  2128. {
  2129. ImDrawVert* vert_start = draw_list->VtxBuffer.Data + vert_start_idx;
  2130. ImDrawVert* vert_end = draw_list->VtxBuffer.Data + vert_end_idx;
  2131. for (ImDrawVert* vertex = vert_start; vertex < vert_end; ++vertex)
  2132. vertex->pos = ImRotate(vertex->pos- pivot_in, cos_a, sin_a) + pivot_out;
  2133. }
  2134. //-----------------------------------------------------------------------------
  2135. // [SECTION] ImFontConfig
  2136. //-----------------------------------------------------------------------------
  2137. // FIXME-NEWATLAS: Oversample specification could be more dynamic. For now, favoring automatic selection.
  2138. ImFontConfig::ImFontConfig()
  2139. {
  2140. memset(this, 0, sizeof(*this));
  2141. FontDataOwnedByAtlas = true;
  2142. OversampleH = 0; // Auto == 1 or 2 depending on size
  2143. OversampleV = 0; // Auto == 1
  2144. GlyphMaxAdvanceX = FLT_MAX;
  2145. RasterizerMultiply = 1.0f;
  2146. RasterizerDensity = 1.0f;
  2147. EllipsisChar = 0;
  2148. }
  2149. //-----------------------------------------------------------------------------
  2150. // [SECTION] ImTextureData
  2151. //-----------------------------------------------------------------------------
  2152. // - ImTextureData::Create()
  2153. // - ImTextureData::DestroyPixels()
  2154. //-----------------------------------------------------------------------------
  2155. int ImTextureDataGetFormatBytesPerPixel(ImTextureFormat format)
  2156. {
  2157. switch (format)
  2158. {
  2159. case ImTextureFormat_Alpha8: return 1;
  2160. case ImTextureFormat_RGBA32: return 4;
  2161. }
  2162. IM_ASSERT(0);
  2163. return 0;
  2164. }
  2165. const char* ImTextureDataGetStatusName(ImTextureStatus status)
  2166. {
  2167. switch (status)
  2168. {
  2169. case ImTextureStatus_OK: return "OK";
  2170. case ImTextureStatus_Destroyed: return "Destroyed";
  2171. case ImTextureStatus_WantCreate: return "WantCreate";
  2172. case ImTextureStatus_WantUpdates: return "WantUpdates";
  2173. case ImTextureStatus_WantDestroy: return "WantDestroy";
  2174. }
  2175. return "N/A";
  2176. }
  2177. const char* ImTextureDataGetFormatName(ImTextureFormat format)
  2178. {
  2179. switch (format)
  2180. {
  2181. case ImTextureFormat_Alpha8: return "Alpha8";
  2182. case ImTextureFormat_RGBA32: return "RGBA32";
  2183. }
  2184. return "N/A";
  2185. }
  2186. void ImTextureData::Create(ImTextureFormat format, int w, int h)
  2187. {
  2188. IM_ASSERT(Status == ImTextureStatus_Destroyed);
  2189. DestroyPixels();
  2190. Format = format;
  2191. Status = ImTextureStatus_WantCreate;
  2192. Width = w;
  2193. Height = h;
  2194. BytesPerPixel = ImTextureDataGetFormatBytesPerPixel(format);
  2195. UseColors = false;
  2196. Pixels = (unsigned char*)IM_ALLOC(Width * Height * BytesPerPixel);
  2197. IM_ASSERT(Pixels != NULL);
  2198. memset(Pixels, 0, Width * Height * BytesPerPixel);
  2199. UsedRect.x = UsedRect.y = UsedRect.w = UsedRect.h = 0;
  2200. UpdateRect.x = UpdateRect.y = (unsigned short)~0;
  2201. UpdateRect.w = UpdateRect.h = 0;
  2202. }
  2203. void ImTextureData::DestroyPixels()
  2204. {
  2205. if (Pixels)
  2206. IM_FREE(Pixels);
  2207. Pixels = NULL;
  2208. UseColors = false;
  2209. }
  2210. //-----------------------------------------------------------------------------
  2211. // [SECTION] ImFontAtlas, ImFontAtlasBuilder
  2212. //-----------------------------------------------------------------------------
  2213. // - Default texture data encoded in ASCII
  2214. // - ImFontAtlas()
  2215. // - ImFontAtlas::Clear()
  2216. // - ImFontAtlas::CompactCache()
  2217. // - ImFontAtlas::ClearInputData()
  2218. // - ImFontAtlas::ClearTexData()
  2219. // - ImFontAtlas::ClearFonts()
  2220. //-----------------------------------------------------------------------------
  2221. // - ImFontAtlasUpdateNewFrame()
  2222. // - ImFontAtlasTextureBlockConvert()
  2223. // - ImFontAtlasTextureBlockPostProcess()
  2224. // - ImFontAtlasTextureBlockPostProcessMultiply()
  2225. // - ImFontAtlasTextureBlockFill()
  2226. // - ImFontAtlasTextureBlockCopy()
  2227. // - ImFontAtlasTextureBlockQueueUpload()
  2228. //-----------------------------------------------------------------------------
  2229. // - ImFontAtlas::GetTexDataAsAlpha8() [legacy]
  2230. // - ImFontAtlas::GetTexDataAsRGBA32() [legacy]
  2231. // - ImFontAtlas::Build() [legacy]
  2232. //-----------------------------------------------------------------------------
  2233. // - ImFontAtlas::AddFont()
  2234. // - ImFontAtlas::AddFontDefault()
  2235. // - ImFontAtlas::AddFontFromFileTTF()
  2236. // - ImFontAtlas::AddFontFromMemoryTTF()
  2237. // - ImFontAtlas::AddFontFromMemoryCompressedTTF()
  2238. // - ImFontAtlas::AddFontFromMemoryCompressedBase85TTF()
  2239. // - ImFontAtlas::RemoveFont()
  2240. // - ImFontAtlasBuildNotifySetFont()
  2241. //-----------------------------------------------------------------------------
  2242. // - ImFontAtlas::AddCustomRect()
  2243. // - ImFontAtlas::RemoveCustomRect()
  2244. // - ImFontAtlas::GetCustomRect()
  2245. // - ImFontAtlas::AddCustomRectFontGlyph() [legacy]
  2246. // - ImFontAtlas::AddCustomRectFontGlyphForSize() [legacy]
  2247. // - ImFontAtlasGetMouseCursorTexData()
  2248. //-----------------------------------------------------------------------------
  2249. // - ImFontAtlasBuildMain()
  2250. // - ImFontAtlasBuildSetupFontLoader()
  2251. // - ImFontAtlasBuildPreloadAllGlyphRanges()
  2252. // - ImFontAtlasBuildUpdatePointers()
  2253. // - ImFontAtlasBuildRenderBitmapFromString()
  2254. // - ImFontAtlasBuildUpdateBasicTexData()
  2255. // - ImFontAtlasBuildUpdateLinesTexData()
  2256. // - ImFontAtlasBuildAddFont()
  2257. // - ImFontAtlasBuildSetupFontBakedEllipsis()
  2258. // - ImFontAtlasBuildSetupFontBakedBlanks()
  2259. // - ImFontAtlasBuildSetupFontBakedFallback()
  2260. // - ImFontAtlasBuildSetupFontSpecialGlyphs()
  2261. // - ImFontAtlasBuildDiscardBakes()
  2262. // - ImFontAtlasBuildDiscardFontBakedGlyph()
  2263. // - ImFontAtlasBuildDiscardFontBaked()
  2264. // - ImFontAtlasBuildDiscardFontBakes()
  2265. //-----------------------------------------------------------------------------
  2266. // - ImFontAtlasAddDrawListSharedData()
  2267. // - ImFontAtlasRemoveDrawListSharedData()
  2268. // - ImFontAtlasUpdateDrawListsTextures()
  2269. // - ImFontAtlasUpdateDrawListsSharedData()
  2270. //-----------------------------------------------------------------------------
  2271. // - ImFontAtlasBuildSetTexture()
  2272. // - ImFontAtlasBuildAddTexture()
  2273. // - ImFontAtlasBuildMakeSpace()
  2274. // - ImFontAtlasBuildRepackTexture()
  2275. // - ImFontAtlasBuildGrowTexture()
  2276. // - ImFontAtlasBuildRepackOrGrowTexture()
  2277. // - ImFontAtlasBuildGetTextureSizeEstimate()
  2278. // - ImFontAtlasBuildCompactTexture()
  2279. // - ImFontAtlasBuildInit()
  2280. // - ImFontAtlasBuildDestroy()
  2281. //-----------------------------------------------------------------------------
  2282. // - ImFontAtlasPackInit()
  2283. // - ImFontAtlasPackAllocRectEntry()
  2284. // - ImFontAtlasPackReuseRectEntry()
  2285. // - ImFontAtlasPackDiscardRect()
  2286. // - ImFontAtlasPackAddRect()
  2287. // - ImFontAtlasPackGetRect()
  2288. //-----------------------------------------------------------------------------
  2289. // - ImFontBaked_BuildGrowIndex()
  2290. // - ImFontBaked_BuildLoadGlyph()
  2291. // - ImFontBaked_BuildLoadGlyphAdvanceX()
  2292. // - ImFontAtlasDebugLogTextureRequests()
  2293. //-----------------------------------------------------------------------------
  2294. // - ImFontAtlasGetFontLoaderForStbTruetype()
  2295. //-----------------------------------------------------------------------------
  2296. // A work of art lies ahead! (. = white layer, X = black layer, others are blank)
  2297. // The 2x2 white texels on the top left are the ones we'll use everywhere in Dear ImGui to render filled shapes.
  2298. // (This is used when io.MouseDrawCursor = true)
  2299. const int FONT_ATLAS_DEFAULT_TEX_DATA_W = 122; // Actual texture will be 2 times that + 1 spacing.
  2300. const int FONT_ATLAS_DEFAULT_TEX_DATA_H = 27;
  2301. static const char FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS[FONT_ATLAS_DEFAULT_TEX_DATA_W * FONT_ATLAS_DEFAULT_TEX_DATA_H + 1] =
  2302. {
  2303. "..- -XXXXXXX- X - X -XXXXXXX - XXXXXXX- XX - XX XX "
  2304. "..- -X.....X- X.X - X.X -X.....X - X.....X- X..X -X..X X..X"
  2305. "--- -XXX.XXX- X...X - X...X -X....X - X....X- X..X -X...X X...X"
  2306. "X - X.X - X.....X - X.....X -X...X - X...X- X..X - X...X X...X "
  2307. "XX - X.X -X.......X- X.......X -X..X.X - X.X..X- X..X - X...X...X "
  2308. "X.X - X.X -XXXX.XXXX- XXXX.XXXX -X.X X.X - X.X X.X- X..XXX - X.....X "
  2309. "X..X - X.X - X.X - X.X -XX X.X - X.X XX- X..X..XXX - X...X "
  2310. "X...X - X.X - X.X - XX X.X XX - X.X - X.X - X..X..X..XX - X.X "
  2311. "X....X - X.X - X.X - X.X X.X X.X - X.X - X.X - X..X..X..X.X - X...X "
  2312. "X.....X - X.X - X.X - X..X X.X X..X - X.X - X.X -XXX X..X..X..X..X- X.....X "
  2313. "X......X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X XX-XX X.X -X..XX........X..X- X...X...X "
  2314. "X.......X - X.X - X.X -X.....................X- X.X X.X-X.X X.X -X...X...........X- X...X X...X "
  2315. "X........X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X..X-X..X.X - X..............X-X...X X...X"
  2316. "X.........X -XXX.XXX- X.X - X..X X.X X..X - X...X-X...X - X.............X-X..X X..X"
  2317. "X..........X-X.....X- X.X - X.X X.X X.X - X....X-X....X - X.............X- XX XX "
  2318. "X......XXXXX-XXXXXXX- X.X - XX X.X XX - X.....X-X.....X - X............X--------------"
  2319. "X...X..X --------- X.X - X.X - XXXXXXX-XXXXXXX - X...........X - "
  2320. "X..X X..X - -XXXX.XXXX- XXXX.XXXX ------------------------------------- X..........X - "
  2321. "X.X X..X - -X.......X- X.......X - XX XX - - X..........X - "
  2322. "XX X..X - - X.....X - X.....X - X.X X.X - - X........X - "
  2323. " X..X - - X...X - X...X - X..X X..X - - X........X - "
  2324. " XX - - X.X - X.X - X...XXXXXXXXXXXXX...X - - XXXXXXXXXX - "
  2325. "------------- - X - X -X.....................X- ------------------- "
  2326. " ----------------------------------- X...XXXXXXXXXXXXX...X - "
  2327. " - X..X X..X - "
  2328. " - X.X X.X - "
  2329. " - XX XX - "
  2330. };
  2331. static const ImVec2 FONT_ATLAS_DEFAULT_TEX_CURSOR_DATA[ImGuiMouseCursor_COUNT][3] =
  2332. {
  2333. // Pos ........ Size ......... Offset ......
  2334. { ImVec2( 0,3), ImVec2(12,19), ImVec2( 0, 0) }, // ImGuiMouseCursor_Arrow
  2335. { ImVec2(13,0), ImVec2( 7,16), ImVec2( 1, 8) }, // ImGuiMouseCursor_TextInput
  2336. { ImVec2(31,0), ImVec2(23,23), ImVec2(11,11) }, // ImGuiMouseCursor_ResizeAll
  2337. { ImVec2(21,0), ImVec2( 9,23), ImVec2( 4,11) }, // ImGuiMouseCursor_ResizeNS
  2338. { ImVec2(55,18),ImVec2(23, 9), ImVec2(11, 4) }, // ImGuiMouseCursor_ResizeEW
  2339. { ImVec2(73,0), ImVec2(17,17), ImVec2( 8, 8) }, // ImGuiMouseCursor_ResizeNESW
  2340. { ImVec2(55,0), ImVec2(17,17), ImVec2( 8, 8) }, // ImGuiMouseCursor_ResizeNWSE
  2341. { ImVec2(91,0), ImVec2(17,22), ImVec2( 5, 0) }, // ImGuiMouseCursor_Hand
  2342. { ImVec2(0,3), ImVec2(12,19), ImVec2(0, 0) }, // ImGuiMouseCursor_Wait // Arrow + custom code in ImGui::RenderMouseCursor()
  2343. { ImVec2(0,3), ImVec2(12,19), ImVec2(0, 0) }, // ImGuiMouseCursor_Progress // Arrow + custom code in ImGui::RenderMouseCursor()
  2344. { ImVec2(109,0),ImVec2(13,15), ImVec2( 6, 7) }, // ImGuiMouseCursor_NotAllowed
  2345. };
  2346. #define IM_FONTGLYPH_INDEX_UNUSED ((ImU16)-1) // 0xFFFF
  2347. #define IM_FONTGLYPH_INDEX_NOT_FOUND ((ImU16)-2) // 0xFFFE
  2348. ImFontAtlas::ImFontAtlas()
  2349. {
  2350. memset(this, 0, sizeof(*this));
  2351. TexDesiredFormat = ImTextureFormat_RGBA32;
  2352. TexGlyphPadding = 1;
  2353. TexMinWidth = 512;
  2354. TexMinHeight = 128;
  2355. TexMaxWidth = 8192;
  2356. TexMaxHeight = 8192;
  2357. RendererHasTextures = false; // Assumed false by default, as apps can call e.g Atlas::Build() after backend init and before ImGui can update.
  2358. TexNextUniqueID = 1;
  2359. FontNextUniqueID = 1;
  2360. Builder = NULL;
  2361. }
  2362. ImFontAtlas::~ImFontAtlas()
  2363. {
  2364. IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!");
  2365. RendererHasTextures = false; // Full Clear() is supported, but ClearTexData() only isn't.
  2366. ClearFonts();
  2367. ClearTexData();
  2368. TexList.clear_delete();
  2369. TexData = NULL;
  2370. }
  2371. void ImFontAtlas::Clear()
  2372. {
  2373. bool backup_renderer_has_textures = RendererHasTextures;
  2374. RendererHasTextures = false; // Full Clear() is supported, but ClearTexData() only isn't.
  2375. ClearFonts();
  2376. ClearTexData();
  2377. RendererHasTextures = backup_renderer_has_textures;
  2378. }
  2379. void ImFontAtlas::CompactCache()
  2380. {
  2381. ImFontAtlasTextureCompact(this);
  2382. }
  2383. void ImFontAtlas::SetFontLoader(const ImFontLoader* font_loader)
  2384. {
  2385. ImFontAtlasBuildSetupFontLoader(this, font_loader);
  2386. }
  2387. void ImFontAtlas::ClearInputData()
  2388. {
  2389. IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!");
  2390. for (ImFont* font : Fonts)
  2391. ImFontAtlasFontDestroyOutput(this, font);
  2392. for (ImFontConfig& font_cfg : Sources)
  2393. ImFontAtlasFontDestroySourceData(this, &font_cfg);
  2394. for (ImFont* font : Fonts)
  2395. {
  2396. // When clearing this we lose access to the font name and other information used to build the font.
  2397. font->Sources.clear();
  2398. font->Flags |= ImFontFlags_NoLoadGlyphs;
  2399. }
  2400. Sources.clear();
  2401. }
  2402. // Clear CPU-side copy of the texture data.
  2403. void ImFontAtlas::ClearTexData()
  2404. {
  2405. IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!");
  2406. IM_ASSERT(RendererHasTextures == false && "Not supported for dynamic atlases, but you may call Clear().");
  2407. for (ImTextureData* tex : TexList)
  2408. tex->DestroyPixels();
  2409. //Locked = true; // Hoped to be able to lock this down but some reload patterns may not be happy with it.
  2410. }
  2411. void ImFontAtlas::ClearFonts()
  2412. {
  2413. // FIXME-NEWATLAS: Illegal to remove currently bound font.
  2414. IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!");
  2415. ImFontAtlasBuildDestroy(this);
  2416. ClearInputData();
  2417. Fonts.clear_delete();
  2418. TexIsBuilt = false;
  2419. for (ImDrawListSharedData* shared_data : DrawListSharedDatas)
  2420. if (shared_data->FontAtlas == this)
  2421. {
  2422. shared_data->Font = NULL;
  2423. shared_data->FontScale = shared_data->FontSize = 0.0f;
  2424. }
  2425. }
  2426. static void ImFontAtlasBuildUpdateRendererHasTexturesFromContext(ImFontAtlas* atlas)
  2427. {
  2428. // [LEGACY] Copy back the ImGuiBackendFlags_RendererHasTextures flag from ImGui context.
  2429. // - This is the 1% exceptional case where that dependency if useful, to bypass an issue where otherwise at the
  2430. // time of an early call to Build(), it would be impossible for us to tell if the backend supports texture update.
  2431. // - Without this hack, we would have quite a pitfall as many legacy codebases have an early call to Build().
  2432. // Whereas conversely, the portion of people using ImDrawList without ImGui is expected to be pathologically rare.
  2433. for (ImDrawListSharedData* shared_data : atlas->DrawListSharedDatas)
  2434. if (ImGuiContext* imgui_ctx = shared_data->Context)
  2435. {
  2436. atlas->RendererHasTextures = (imgui_ctx->IO.BackendFlags & ImGuiBackendFlags_RendererHasTextures) != 0;
  2437. break;
  2438. }
  2439. }
  2440. // Called by NewFrame() for atlases owned by a context.
  2441. // If you manually manage font atlases, you'll need to call this yourself.
  2442. // - 'frame_count' needs to be provided because we can gc/prioritize baked fonts based on their age.
  2443. // - 'frame_count' may not match those of all imgui contexts using this atlas, as contexts may be updated as different frequencies. But generally you can use ImGui::GetFrameCount() on one of your context.
  2444. void ImFontAtlasUpdateNewFrame(ImFontAtlas* atlas, int frame_count, bool renderer_has_textures)
  2445. {
  2446. IM_ASSERT(atlas->Builder == NULL || atlas->Builder->FrameCount < frame_count); // Protection against being called twice.
  2447. atlas->RendererHasTextures = renderer_has_textures;
  2448. // Check that font atlas was built or backend support texture reload in which case we can build now
  2449. if (atlas->RendererHasTextures)
  2450. {
  2451. atlas->TexIsBuilt = true;
  2452. if (atlas->Builder == NULL) // This will only happen if fonts were not already loaded.
  2453. ImFontAtlasBuildMain(atlas);
  2454. }
  2455. else // Legacy backend
  2456. {
  2457. IM_ASSERT_USER_ERROR(atlas->TexIsBuilt, "Backend does not support ImGuiBackendFlags_RendererHasTextures, and font atlas is not built! Update backend OR make sure you called ImGui_ImplXXXX_NewFrame() function for renderer backend, which should call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8().");
  2458. }
  2459. if (atlas->TexIsBuilt && atlas->Builder->PreloadedAllGlyphsRanges)
  2460. IM_ASSERT_USER_ERROR(atlas->RendererHasTextures == false, "Called ImFontAtlas::Build() before ImGuiBackendFlags_RendererHasTextures got set! With new backends: you don't need to call Build().");
  2461. // Clear BakedCurrent cache, this is important because it ensure the uncached path gets taken once.
  2462. // We also rely on ImFontBaked* pointers never crossing frames.
  2463. ImFontAtlasBuilder* builder = atlas->Builder;
  2464. builder->FrameCount = frame_count;
  2465. for (ImFont* font : atlas->Fonts)
  2466. font->LastBaked = NULL;
  2467. // Garbage collect BakedPool
  2468. if (builder->BakedDiscardedCount > 0)
  2469. {
  2470. int dst_n = 0, src_n = 0;
  2471. for (; src_n < builder->BakedPool.Size; src_n++)
  2472. {
  2473. ImFontBaked* p_src = &builder->BakedPool[src_n];
  2474. if (p_src->WantDestroy)
  2475. continue;
  2476. ImFontBaked* p_dst = &builder->BakedPool[dst_n++];
  2477. if (p_dst == p_src)
  2478. continue;
  2479. memcpy(p_dst, p_src, sizeof(ImFontBaked));
  2480. builder->BakedMap.SetVoidPtr(p_dst->BakedId, p_dst);
  2481. }
  2482. IM_ASSERT(dst_n + builder->BakedDiscardedCount == src_n);
  2483. builder->BakedPool.Size -= builder->BakedDiscardedCount;
  2484. builder->BakedDiscardedCount = 0;
  2485. }
  2486. // Update texture status
  2487. for (int tex_n = 0; tex_n < atlas->TexList.Size; tex_n++)
  2488. {
  2489. ImTextureData* tex = atlas->TexList[tex_n];
  2490. bool remove_from_list = false;
  2491. if (tex->Status == ImTextureStatus_OK)
  2492. {
  2493. tex->Updates.resize(0);
  2494. tex->UpdateRect.x = tex->UpdateRect.y = (unsigned short)~0;
  2495. tex->UpdateRect.w = tex->UpdateRect.h = 0;
  2496. }
  2497. if (tex->Status == ImTextureStatus_WantCreate && atlas->RendererHasTextures)
  2498. IM_ASSERT(tex->TexID == ImTextureID_Invalid && tex->BackendUserData == NULL && "Backend set texture's TexID/BackendUserData but did not update Status to OK.");
  2499. if (tex->Status == ImTextureStatus_Destroyed)
  2500. {
  2501. IM_ASSERT(tex->TexID == ImTextureID_Invalid && tex->BackendUserData == NULL && "Backend set texture Status to Destroyed but did not clear TexID/BackendUserData!");
  2502. if (tex->WantDestroyNextFrame)
  2503. remove_from_list = true; // Destroy was scheduled by us
  2504. else
  2505. tex->Status = ImTextureStatus_WantCreate; // Destroy was done was backend (e.g. freed resources mid-run)
  2506. }
  2507. else if (tex->WantDestroyNextFrame && tex->Status != ImTextureStatus_WantDestroy)
  2508. {
  2509. // Request destroy. Keep bool as it allows us to keep track of things.
  2510. // We don't destroy pixels right away, as backend may have an in-flight copy from RAM.
  2511. IM_ASSERT(tex->Status == ImTextureStatus_OK || tex->Status == ImTextureStatus_WantCreate || tex->Status == ImTextureStatus_WantUpdates);
  2512. tex->Status = ImTextureStatus_WantDestroy;
  2513. }
  2514. // The backend may need defer destroying by a few frames, to handle texture used by previous in-flight rendering.
  2515. // We allow the texture staying in _WantDestroy state and increment a counter which the backend can use to take its decision.
  2516. if (tex->Status == ImTextureStatus_WantDestroy)
  2517. tex->UnusedFrames++;
  2518. // If a texture has never reached the backend, they don't need to know about it.
  2519. if (tex->Status == ImTextureStatus_WantDestroy && tex->TexID == ImTextureID_Invalid && tex->BackendUserData == NULL)
  2520. remove_from_list = true;
  2521. // Destroy and remove
  2522. if (remove_from_list)
  2523. {
  2524. tex->DestroyPixels();
  2525. IM_DELETE(tex);
  2526. atlas->TexList.erase(atlas->TexList.begin() + tex_n);
  2527. tex_n--;
  2528. }
  2529. }
  2530. }
  2531. void ImFontAtlasTextureBlockConvert(const unsigned char* src_pixels, ImTextureFormat src_fmt, int src_pitch, unsigned char* dst_pixels, ImTextureFormat dst_fmt, int dst_pitch, int w, int h)
  2532. {
  2533. IM_ASSERT(src_pixels != NULL && dst_pixels != NULL);
  2534. if (src_fmt == dst_fmt)
  2535. {
  2536. int line_sz = w * ImTextureDataGetFormatBytesPerPixel(src_fmt);
  2537. for (int ny = h; ny > 0; ny--, src_pixels += src_pitch, dst_pixels += dst_pitch)
  2538. memcpy(dst_pixels, src_pixels, line_sz);
  2539. }
  2540. else if (src_fmt == ImTextureFormat_Alpha8 && dst_fmt == ImTextureFormat_RGBA32)
  2541. {
  2542. for (int ny = h; ny > 0; ny--, src_pixels += src_pitch, dst_pixels += dst_pitch)
  2543. {
  2544. const ImU8* src_p = (const ImU8*)src_pixels;
  2545. ImU32* dst_p = (ImU32*)(void*)dst_pixels;
  2546. for (int nx = w; nx > 0; nx--)
  2547. *dst_p++ = IM_COL32(255, 255, 255, (unsigned int)(*src_p++));
  2548. }
  2549. }
  2550. else if (src_fmt == ImTextureFormat_RGBA32 && dst_fmt == ImTextureFormat_Alpha8)
  2551. {
  2552. for (int ny = h; ny > 0; ny--, src_pixels += src_pitch, dst_pixels += dst_pitch)
  2553. {
  2554. const ImU32* src_p = (const ImU32*)(void*)src_pixels;
  2555. ImU8* dst_p = (ImU8*)dst_pixels;
  2556. for (int nx = w; nx > 0; nx--)
  2557. *dst_p++ = ((*src_p++) >> IM_COL32_A_SHIFT) & 0xFF;
  2558. }
  2559. }
  2560. else
  2561. {
  2562. IM_ASSERT(0);
  2563. }
  2564. }
  2565. // Source buffer may be written to (used for in-place mods).
  2566. // Post-process hooks may eventually be added here.
  2567. void ImFontAtlasTextureBlockPostProcess(ImFontAtlasPostProcessData* data)
  2568. {
  2569. // Multiply operator (legacy)
  2570. if (data->FontSrc->RasterizerMultiply != 1.0f)
  2571. ImFontAtlasTextureBlockPostProcessMultiply(data, data->FontSrc->RasterizerMultiply);
  2572. }
  2573. void ImFontAtlasTextureBlockPostProcessMultiply(ImFontAtlasPostProcessData* data, float multiply_factor)
  2574. {
  2575. unsigned char* pixels = (unsigned char*)data->Pixels;
  2576. int pitch = data->Pitch;
  2577. if (data->Format == ImTextureFormat_Alpha8)
  2578. {
  2579. for (int ny = data->Height; ny > 0; ny--, pixels += pitch)
  2580. {
  2581. ImU8* p = (ImU8*)pixels;
  2582. for (int nx = data->Width; nx > 0; nx--, p++)
  2583. {
  2584. unsigned int v = ImMin((unsigned int)(*p * multiply_factor), (unsigned int)255);
  2585. *p = (unsigned char)v;
  2586. }
  2587. }
  2588. }
  2589. else if (data->Format == ImTextureFormat_RGBA32) //-V547
  2590. {
  2591. for (int ny = data->Height; ny > 0; ny--, pixels += pitch)
  2592. {
  2593. ImU32* p = (ImU32*)(void*)pixels;
  2594. for (int nx = data->Width; nx > 0; nx--, p++)
  2595. {
  2596. unsigned int a = ImMin((unsigned int)(((*p >> IM_COL32_A_SHIFT) & 0xFF) * multiply_factor), (unsigned int)255);
  2597. *p = IM_COL32((*p >> IM_COL32_R_SHIFT) & 0xFF, (*p >> IM_COL32_G_SHIFT) & 0xFF, (*p >> IM_COL32_B_SHIFT) & 0xFF, a);
  2598. }
  2599. }
  2600. }
  2601. else
  2602. {
  2603. IM_ASSERT(0);
  2604. }
  2605. }
  2606. // Fill with single color. We don't use this directly but it is convenient for anyone working on uploading custom rects.
  2607. void ImFontAtlasTextureBlockFill(ImTextureData* dst_tex, int dst_x, int dst_y, int w, int h, ImU32 col)
  2608. {
  2609. if (dst_tex->Format == ImTextureFormat_Alpha8)
  2610. {
  2611. ImU8 col_a = (col >> IM_COL32_A_SHIFT) & 0xFF;
  2612. for (int y = 0; y < h; y++)
  2613. memset((ImU8*)dst_tex->GetPixelsAt(dst_x, dst_y + y), col_a, w);
  2614. }
  2615. else
  2616. {
  2617. for (int y = 0; y < h; y++)
  2618. {
  2619. ImU32* p = (ImU32*)(void*)dst_tex->GetPixelsAt(dst_x, dst_y + y);
  2620. for (int x = w; x > 0; x--, p++)
  2621. *p = col;
  2622. }
  2623. }
  2624. }
  2625. // Copy block from one texture to another
  2626. void ImFontAtlasTextureBlockCopy(ImTextureData* src_tex, int src_x, int src_y, ImTextureData* dst_tex, int dst_x, int dst_y, int w, int h)
  2627. {
  2628. IM_ASSERT(src_tex->Pixels != NULL && dst_tex->Pixels != NULL);
  2629. IM_ASSERT(src_tex->Format == dst_tex->Format);
  2630. IM_ASSERT(src_x >= 0 && src_x + w <= src_tex->Width);
  2631. IM_ASSERT(src_y >= 0 && src_y + h <= src_tex->Height);
  2632. IM_ASSERT(dst_x >= 0 && dst_x + w <= dst_tex->Width);
  2633. IM_ASSERT(dst_y >= 0 && dst_y + h <= dst_tex->Height);
  2634. for (int y = 0; y < h; y++)
  2635. memcpy(dst_tex->GetPixelsAt(dst_x, dst_y + y), src_tex->GetPixelsAt(src_x, src_y + y), w * dst_tex->BytesPerPixel);
  2636. }
  2637. // Queue texture block update for renderer backend
  2638. void ImFontAtlasTextureBlockQueueUpload(ImFontAtlas* atlas, ImTextureData* tex, int x, int y, int w, int h)
  2639. {
  2640. IM_ASSERT(tex->Status != ImTextureStatus_WantDestroy && tex->Status != ImTextureStatus_Destroyed);
  2641. IM_ASSERT(x >= 0 && x <= 0xFFFF && y >= 0 && y <= 0xFFFF && w >= 0 && x + w <= 0x10000 && h >= 0 && y + h <= 0x10000);
  2642. IM_UNUSED(atlas);
  2643. ImTextureRect req = { (unsigned short)x, (unsigned short)y, (unsigned short)w, (unsigned short)h };
  2644. int new_x1 = ImMax(tex->UpdateRect.w == 0 ? 0 : tex->UpdateRect.x + tex->UpdateRect.w, req.x + req.w);
  2645. int new_y1 = ImMax(tex->UpdateRect.h == 0 ? 0 : tex->UpdateRect.y + tex->UpdateRect.h, req.y + req.h);
  2646. tex->UpdateRect.x = ImMin(tex->UpdateRect.x, req.x);
  2647. tex->UpdateRect.y = ImMin(tex->UpdateRect.y, req.y);
  2648. tex->UpdateRect.w = (unsigned short)(new_x1 - tex->UpdateRect.x);
  2649. tex->UpdateRect.h = (unsigned short)(new_y1 - tex->UpdateRect.y);
  2650. tex->UsedRect.x = ImMin(tex->UsedRect.x, req.x);
  2651. tex->UsedRect.y = ImMin(tex->UsedRect.y, req.y);
  2652. tex->UsedRect.w = (unsigned short)(ImMax(tex->UsedRect.x + tex->UsedRect.w, req.x + req.w) - tex->UsedRect.x);
  2653. tex->UsedRect.h = (unsigned short)(ImMax(tex->UsedRect.y + tex->UsedRect.h, req.y + req.h) - tex->UsedRect.y);
  2654. atlas->TexIsBuilt = false;
  2655. // No need to queue if status is _WantCreate
  2656. if (tex->Status == ImTextureStatus_OK || tex->Status == ImTextureStatus_WantUpdates)
  2657. {
  2658. tex->Status = ImTextureStatus_WantUpdates;
  2659. tex->Updates.push_back(req);
  2660. }
  2661. }
  2662. #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
  2663. static void GetTexDataAsFormat(ImFontAtlas* atlas, ImTextureFormat format, unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel)
  2664. {
  2665. ImTextureData* tex = atlas->TexData;
  2666. if (!atlas->TexIsBuilt || tex == NULL || tex->Pixels == NULL || atlas->TexDesiredFormat != format)
  2667. {
  2668. atlas->TexDesiredFormat = format;
  2669. atlas->Build();
  2670. tex = atlas->TexData;
  2671. }
  2672. if (out_pixels) { *out_pixels = (unsigned char*)tex->Pixels; };
  2673. if (out_width) { *out_width = tex->Width; };
  2674. if (out_height) { *out_height = tex->Height; };
  2675. if (out_bytes_per_pixel) { *out_bytes_per_pixel = tex->BytesPerPixel; }
  2676. }
  2677. void ImFontAtlas::GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel)
  2678. {
  2679. GetTexDataAsFormat(this, ImTextureFormat_Alpha8, out_pixels, out_width, out_height, out_bytes_per_pixel);
  2680. }
  2681. void ImFontAtlas::GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel)
  2682. {
  2683. GetTexDataAsFormat(this, ImTextureFormat_RGBA32, out_pixels, out_width, out_height, out_bytes_per_pixel);
  2684. }
  2685. bool ImFontAtlas::Build()
  2686. {
  2687. ImFontAtlasBuildMain(this);
  2688. return true;
  2689. }
  2690. #endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
  2691. ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg_in)
  2692. {
  2693. // Sanity Checks
  2694. IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!");
  2695. IM_ASSERT((font_cfg_in->FontData != NULL && font_cfg_in->FontDataSize > 0) || (font_cfg_in->FontLoader != NULL));
  2696. //IM_ASSERT(font_cfg_in->SizePixels > 0.0f && "Is ImFontConfig struct correctly initialized?");
  2697. IM_ASSERT(font_cfg_in->RasterizerDensity > 0.0f && "Is ImFontConfig struct correctly initialized?");
  2698. if (font_cfg_in->GlyphOffset.x != 0.0f || font_cfg_in->GlyphOffset.y != 0.0f || font_cfg_in->GlyphMinAdvanceX != 0.0f || font_cfg_in->GlyphMaxAdvanceX != FLT_MAX)
  2699. IM_ASSERT(font_cfg_in->SizePixels != 0.0f && "Specifying glyph offset/advances requires a reference size to base it on.");
  2700. // Lazily create builder on the first call to AddFont
  2701. if (Builder == NULL)
  2702. ImFontAtlasBuildInit(this);
  2703. // Create new font
  2704. ImFont* font;
  2705. if (!font_cfg_in->MergeMode)
  2706. {
  2707. font = IM_NEW(ImFont)();
  2708. font->FontId = FontNextUniqueID++;
  2709. font->Flags = font_cfg_in->Flags;
  2710. font->LegacySize = font_cfg_in->SizePixels;
  2711. font->CurrentRasterizerDensity = font_cfg_in->RasterizerDensity;
  2712. Fonts.push_back(font);
  2713. }
  2714. else
  2715. {
  2716. IM_ASSERT(Fonts.Size > 0 && "Cannot use MergeMode for the first font"); // When using MergeMode make sure that a font has already been added before. You can use ImGui::GetIO().Fonts->AddFontDefault() to add the default imgui font.
  2717. font = Fonts.back();
  2718. }
  2719. // Add to list
  2720. Sources.push_back(*font_cfg_in);
  2721. ImFontConfig* font_cfg = &Sources.back();
  2722. if (font_cfg->DstFont == NULL)
  2723. font_cfg->DstFont = font;
  2724. font->Sources.push_back(font_cfg);
  2725. ImFontAtlasBuildUpdatePointers(this); // Pointers to Sources are otherwise dangling after we called Sources.push_back().
  2726. if (font_cfg->FontDataOwnedByAtlas == false)
  2727. {
  2728. font_cfg->FontDataOwnedByAtlas = true;
  2729. font_cfg->FontData = ImMemdup(font_cfg->FontData, (size_t)font_cfg->FontDataSize);
  2730. }
  2731. // Sanity check
  2732. // We don't round cfg.SizePixels yet as relative size of merged fonts are used afterwards.
  2733. if (font_cfg->GlyphExcludeRanges != NULL)
  2734. {
  2735. int size = 0;
  2736. for (const ImWchar* p = font_cfg->GlyphExcludeRanges; p[0] != 0; p++, size++) {}
  2737. IM_ASSERT((size & 1) == 0 && "GlyphExcludeRanges[] size must be multiple of two!");
  2738. IM_ASSERT((size <= 64) && "GlyphExcludeRanges[] size must be small!");
  2739. font_cfg->GlyphExcludeRanges = (ImWchar*)ImMemdup(font_cfg->GlyphExcludeRanges, sizeof(font_cfg->GlyphExcludeRanges[0]) * (size + 1));
  2740. }
  2741. if (font_cfg->FontLoader != NULL)
  2742. {
  2743. IM_ASSERT(font_cfg->FontLoader->FontBakedLoadGlyph != NULL);
  2744. IM_ASSERT(font_cfg->FontLoader->LoaderInit == NULL && font_cfg->FontLoader->LoaderShutdown == NULL); // FIXME-NEWATLAS: Unsupported yet.
  2745. }
  2746. IM_ASSERT(font_cfg->FontLoaderData == NULL);
  2747. if (!ImFontAtlasFontSourceInit(this, font_cfg))
  2748. {
  2749. // Rollback (this is a fragile/rarely exercised code-path. TestSuite's "misc_atlas_add_invalid_font" aim to test this)
  2750. ImFontAtlasFontDestroySourceData(this, font_cfg);
  2751. Sources.pop_back();
  2752. font->Sources.pop_back();
  2753. if (!font_cfg->MergeMode)
  2754. {
  2755. IM_DELETE(font);
  2756. Fonts.pop_back();
  2757. }
  2758. return NULL;
  2759. }
  2760. ImFontAtlasFontSourceAddToFont(this, font, font_cfg);
  2761. return font;
  2762. }
  2763. // Default font TTF is compressed with stb_compress then base85 encoded (see misc/fonts/binary_to_compressed_c.cpp for encoder)
  2764. static unsigned int stb_decompress_length(const unsigned char* input);
  2765. static unsigned int stb_decompress(unsigned char* output, const unsigned char* input, unsigned int length);
  2766. static unsigned int Decode85Byte(char c) { return c >= '\\' ? c-36 : c-35; }
  2767. static void Decode85(const unsigned char* src, unsigned char* dst)
  2768. {
  2769. while (*src)
  2770. {
  2771. unsigned int tmp = Decode85Byte(src[0]) + 85 * (Decode85Byte(src[1]) + 85 * (Decode85Byte(src[2]) + 85 * (Decode85Byte(src[3]) + 85 * Decode85Byte(src[4]))));
  2772. dst[0] = ((tmp >> 0) & 0xFF); dst[1] = ((tmp >> 8) & 0xFF); dst[2] = ((tmp >> 16) & 0xFF); dst[3] = ((tmp >> 24) & 0xFF); // We can't assume little-endianness.
  2773. src += 5;
  2774. dst += 4;
  2775. }
  2776. }
  2777. #ifndef IMGUI_DISABLE_DEFAULT_FONT
  2778. static const char* GetDefaultCompressedFontDataTTF(int* out_size);
  2779. #endif
  2780. // Load embedded ProggyClean.ttf at size 13, disable oversampling
  2781. ImFont* ImFontAtlas::AddFontDefault(const ImFontConfig* font_cfg_template)
  2782. {
  2783. #ifndef IMGUI_DISABLE_DEFAULT_FONT
  2784. ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig();
  2785. if (!font_cfg_template)
  2786. {
  2787. font_cfg.OversampleH = font_cfg.OversampleV = 1;
  2788. font_cfg.PixelSnapH = true;
  2789. }
  2790. if (font_cfg.SizePixels <= 0.0f)
  2791. font_cfg.SizePixels = 13.0f * 1.0f;
  2792. if (font_cfg.Name[0] == '\0')
  2793. ImFormatString(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "ProggyClean.ttf");
  2794. font_cfg.EllipsisChar = (ImWchar)0x0085;
  2795. font_cfg.GlyphOffset.y += 1.0f * IM_TRUNC(font_cfg.SizePixels / 13.0f); // Add +1 offset per 13 units
  2796. int ttf_compressed_size = 0;
  2797. const char* ttf_compressed = GetDefaultCompressedFontDataTTF(&ttf_compressed_size);
  2798. const ImWchar* glyph_ranges = font_cfg.GlyphRanges != NULL ? font_cfg.GlyphRanges : GetGlyphRangesDefault();
  2799. ImFont* font = AddFontFromMemoryCompressedTTF(ttf_compressed, ttf_compressed_size, font_cfg.SizePixels, &font_cfg, glyph_ranges);
  2800. return font;
  2801. #else
  2802. IM_ASSERT(0 && "AddFontDefault() disabled in this build.");
  2803. IM_UNUSED(font_cfg_template);
  2804. return NULL;
  2805. #endif // #ifndef IMGUI_DISABLE_DEFAULT_FONT
  2806. }
  2807. ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges)
  2808. {
  2809. IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!");
  2810. size_t data_size = 0;
  2811. void* data = ImFileLoadToMemory(filename, "rb", &data_size, 0);
  2812. if (!data)
  2813. {
  2814. if (font_cfg_template == NULL || (font_cfg_template->Flags & ImFontFlags_NoLoadError) == 0)
  2815. {
  2816. IMGUI_DEBUG_LOG("While loading '%s'\n", filename);
  2817. IM_ASSERT_USER_ERROR(0, "Could not load font file!");
  2818. }
  2819. return NULL;
  2820. }
  2821. ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig();
  2822. if (font_cfg.Name[0] == '\0')
  2823. {
  2824. // Store a short copy of filename into into the font name for convenience
  2825. const char* p;
  2826. for (p = filename + ImStrlen(filename); p > filename && p[-1] != '/' && p[-1] != '\\'; p--) {}
  2827. ImFormatString(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "%s", p);
  2828. }
  2829. return AddFontFromMemoryTTF(data, (int)data_size, size_pixels, &font_cfg, glyph_ranges);
  2830. }
  2831. // NB: Transfer ownership of 'ttf_data' to ImFontAtlas, unless font_cfg_template->FontDataOwnedByAtlas == false. Owned TTF buffer will be deleted after Build().
  2832. ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* font_data, int font_data_size, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges)
  2833. {
  2834. IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!");
  2835. ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig();
  2836. IM_ASSERT(font_cfg.FontData == NULL);
  2837. IM_ASSERT(font_data_size > 100 && "Incorrect value for font_data_size!"); // Heuristic to prevent accidentally passing a wrong value to font_data_size.
  2838. font_cfg.FontData = font_data;
  2839. font_cfg.FontDataSize = font_data_size;
  2840. font_cfg.SizePixels = size_pixels > 0.0f ? size_pixels : font_cfg.SizePixels;
  2841. if (glyph_ranges)
  2842. font_cfg.GlyphRanges = glyph_ranges;
  2843. return AddFont(&font_cfg);
  2844. }
  2845. ImFont* ImFontAtlas::AddFontFromMemoryCompressedTTF(const void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges)
  2846. {
  2847. const unsigned int buf_decompressed_size = stb_decompress_length((const unsigned char*)compressed_ttf_data);
  2848. unsigned char* buf_decompressed_data = (unsigned char*)IM_ALLOC(buf_decompressed_size);
  2849. stb_decompress(buf_decompressed_data, (const unsigned char*)compressed_ttf_data, (unsigned int)compressed_ttf_size);
  2850. ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig();
  2851. IM_ASSERT(font_cfg.FontData == NULL);
  2852. font_cfg.FontDataOwnedByAtlas = true;
  2853. return AddFontFromMemoryTTF(buf_decompressed_data, (int)buf_decompressed_size, size_pixels, &font_cfg, glyph_ranges);
  2854. }
  2855. ImFont* ImFontAtlas::AddFontFromMemoryCompressedBase85TTF(const char* compressed_ttf_data_base85, float size_pixels, const ImFontConfig* font_cfg, const ImWchar* glyph_ranges)
  2856. {
  2857. int compressed_ttf_size = (((int)ImStrlen(compressed_ttf_data_base85) + 4) / 5) * 4;
  2858. void* compressed_ttf = IM_ALLOC((size_t)compressed_ttf_size);
  2859. Decode85((const unsigned char*)compressed_ttf_data_base85, (unsigned char*)compressed_ttf);
  2860. ImFont* font = AddFontFromMemoryCompressedTTF(compressed_ttf, compressed_ttf_size, size_pixels, font_cfg, glyph_ranges);
  2861. IM_FREE(compressed_ttf);
  2862. return font;
  2863. }
  2864. // On font removal we need to remove references (otherwise we could queue removal?)
  2865. // We allow old_font == new_font which forces updating all values (e.g. sizes)
  2866. static void ImFontAtlasBuildNotifySetFont(ImFontAtlas* atlas, ImFont* old_font, ImFont* new_font)
  2867. {
  2868. for (ImDrawListSharedData* shared_data : atlas->DrawListSharedDatas)
  2869. {
  2870. if (shared_data->Font == old_font)
  2871. shared_data->Font = new_font;
  2872. if (ImGuiContext* ctx = shared_data->Context)
  2873. {
  2874. if (ctx->IO.FontDefault == old_font)
  2875. ctx->IO.FontDefault = new_font;
  2876. if (ctx->Font == old_font)
  2877. {
  2878. ImGuiContext* curr_ctx = ImGui::GetCurrentContext();
  2879. bool need_bind_ctx = ctx != curr_ctx;
  2880. if (need_bind_ctx)
  2881. ImGui::SetCurrentContext(ctx);
  2882. ImGui::SetCurrentFont(new_font, ctx->FontSizeBase, ctx->FontSize);
  2883. if (need_bind_ctx)
  2884. ImGui::SetCurrentContext(curr_ctx);
  2885. }
  2886. for (ImFontStackData& font_stack_data : ctx->FontStack)
  2887. if (font_stack_data.Font == old_font)
  2888. font_stack_data.Font = new_font;
  2889. }
  2890. }
  2891. }
  2892. void ImFontAtlas::RemoveFont(ImFont* font)
  2893. {
  2894. IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!");
  2895. font->ClearOutputData();
  2896. ImFontAtlasFontDestroyOutput(this, font);
  2897. for (ImFontConfig* src : font->Sources)
  2898. ImFontAtlasFontDestroySourceData(this, src);
  2899. for (int src_n = 0; src_n < Sources.Size; src_n++)
  2900. if (Sources[src_n].DstFont == font)
  2901. Sources.erase(&Sources[src_n--]);
  2902. bool removed = Fonts.find_erase(font);
  2903. IM_ASSERT(removed);
  2904. IM_UNUSED(removed);
  2905. ImFontAtlasBuildUpdatePointers(this);
  2906. font->ContainerAtlas = NULL;
  2907. IM_DELETE(font);
  2908. // Notify external systems
  2909. ImFont* new_current_font = Fonts.empty() ? NULL : Fonts[0];
  2910. ImFontAtlasBuildNotifySetFont(this, font, new_current_font);
  2911. }
  2912. // At it is common to do an AddCustomRect() followed by a GetCustomRect(), we provide an optional 'ImFontAtlasRect* out_r = NULL' argument to retrieve the info straight away.
  2913. ImFontAtlasRectId ImFontAtlas::AddCustomRect(int width, int height, ImFontAtlasRect* out_r)
  2914. {
  2915. IM_ASSERT(width > 0 && width <= 0xFFFF);
  2916. IM_ASSERT(height > 0 && height <= 0xFFFF);
  2917. if (Builder == NULL)
  2918. ImFontAtlasBuildInit(this);
  2919. ImFontAtlasRectId r_id = ImFontAtlasPackAddRect(this, width, height);
  2920. if (r_id == ImFontAtlasRectId_Invalid)
  2921. return ImFontAtlasRectId_Invalid;
  2922. if (out_r != NULL)
  2923. GetCustomRect(r_id, out_r);
  2924. if (RendererHasTextures)
  2925. {
  2926. ImTextureRect* r = ImFontAtlasPackGetRect(this, r_id);
  2927. ImFontAtlasTextureBlockQueueUpload(this, TexData, r->x, r->y, r->w, r->h);
  2928. }
  2929. return r_id;
  2930. }
  2931. void ImFontAtlas::RemoveCustomRect(ImFontAtlasRectId id)
  2932. {
  2933. if (ImFontAtlasPackGetRectSafe(this, id) == NULL)
  2934. return;
  2935. ImFontAtlasPackDiscardRect(this, id);
  2936. }
  2937. #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
  2938. // This API does not make sense anymore with scalable fonts.
  2939. // - Prefer adding a font source (ImFontConfig) using a custom/procedural loader.
  2940. // - You may use ImFontFlags_LockBakedSizes to limit an existing font to known baked sizes:
  2941. // ImFont* myfont = io.Fonts->AddFontFromFileTTF(....);
  2942. // myfont->GetFontBaked(16.0f);
  2943. // myfont->Flags |= ImFontFlags_LockBakedSizes;
  2944. ImFontAtlasRectId ImFontAtlas::AddCustomRectFontGlyph(ImFont* font, ImWchar codepoint, int width, int height, float advance_x, const ImVec2& offset)
  2945. {
  2946. float font_size = font->LegacySize;
  2947. return AddCustomRectFontGlyphForSize(font, font_size, codepoint, width, height, advance_x, offset);
  2948. }
  2949. // FIXME: we automatically set glyph.Colored=true by default.
  2950. // If you need to alter this, you can write 'font->Glyphs.back()->Colored' after calling AddCustomRectFontGlyph().
  2951. ImFontAtlasRectId ImFontAtlas::AddCustomRectFontGlyphForSize(ImFont* font, float font_size, ImWchar codepoint, int width, int height, float advance_x, const ImVec2& offset)
  2952. {
  2953. #ifdef IMGUI_USE_WCHAR32
  2954. IM_ASSERT(codepoint <= IM_UNICODE_CODEPOINT_MAX);
  2955. #endif
  2956. IM_ASSERT(font != NULL);
  2957. IM_ASSERT(width > 0 && width <= 0xFFFF);
  2958. IM_ASSERT(height > 0 && height <= 0xFFFF);
  2959. ImFontBaked* baked = font->GetFontBaked(font_size);
  2960. ImFontAtlasRectId r_id = ImFontAtlasPackAddRect(this, width, height);
  2961. if (r_id == ImFontAtlasRectId_Invalid)
  2962. return ImFontAtlasRectId_Invalid;
  2963. ImTextureRect* r = ImFontAtlasPackGetRect(this, r_id);
  2964. if (RendererHasTextures)
  2965. ImFontAtlasTextureBlockQueueUpload(this, TexData, r->x, r->y, r->w, r->h);
  2966. if (baked->IsGlyphLoaded(codepoint))
  2967. ImFontAtlasBakedDiscardFontGlyph(this, font, baked, baked->FindGlyph(codepoint));
  2968. ImFontGlyph glyph;
  2969. glyph.Codepoint = codepoint;
  2970. glyph.AdvanceX = advance_x;
  2971. glyph.X0 = offset.x;
  2972. glyph.Y0 = offset.y;
  2973. glyph.X1 = offset.x + r->w;
  2974. glyph.Y1 = offset.y + r->h;
  2975. glyph.Visible = true;
  2976. glyph.Colored = true; // FIXME: Arbitrary
  2977. glyph.PackId = r_id;
  2978. ImFontAtlasBakedAddFontGlyph(this, baked, font->Sources[0], &glyph);
  2979. return r_id;
  2980. }
  2981. #endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
  2982. bool ImFontAtlas::GetCustomRect(ImFontAtlasRectId id, ImFontAtlasRect* out_r) const
  2983. {
  2984. ImTextureRect* r = ImFontAtlasPackGetRectSafe((ImFontAtlas*)this, id);
  2985. if (r == NULL)
  2986. return false;
  2987. IM_ASSERT(TexData->Width > 0 && TexData->Height > 0); // Font atlas needs to be built before we can calculate UV coordinates
  2988. if (out_r == NULL)
  2989. return true;
  2990. out_r->x = r->x;
  2991. out_r->y = r->y;
  2992. out_r->w = r->w;
  2993. out_r->h = r->h;
  2994. out_r->uv0 = ImVec2((float)(r->x), (float)(r->y)) * TexUvScale;
  2995. out_r->uv1 = ImVec2((float)(r->x + r->w), (float)(r->y + r->h)) * TexUvScale;
  2996. return true;
  2997. }
  2998. bool ImFontAtlasGetMouseCursorTexData(ImFontAtlas* atlas, ImGuiMouseCursor cursor_type, ImVec2* out_offset, ImVec2* out_size, ImVec2 out_uv_border[2], ImVec2 out_uv_fill[2])
  2999. {
  3000. if (cursor_type <= ImGuiMouseCursor_None || cursor_type >= ImGuiMouseCursor_COUNT)
  3001. return false;
  3002. if (atlas->Flags & ImFontAtlasFlags_NoMouseCursors)
  3003. return false;
  3004. ImTextureRect* r = ImFontAtlasPackGetRect(atlas, atlas->Builder->PackIdMouseCursors);
  3005. ImVec2 pos = FONT_ATLAS_DEFAULT_TEX_CURSOR_DATA[cursor_type][0] + ImVec2((float)r->x, (float)r->y);
  3006. ImVec2 size = FONT_ATLAS_DEFAULT_TEX_CURSOR_DATA[cursor_type][1];
  3007. *out_size = size;
  3008. *out_offset = FONT_ATLAS_DEFAULT_TEX_CURSOR_DATA[cursor_type][2];
  3009. out_uv_border[0] = (pos) * atlas->TexUvScale;
  3010. out_uv_border[1] = (pos + size) * atlas->TexUvScale;
  3011. pos.x += FONT_ATLAS_DEFAULT_TEX_DATA_W + 1;
  3012. out_uv_fill[0] = (pos) * atlas->TexUvScale;
  3013. out_uv_fill[1] = (pos + size) * atlas->TexUvScale;
  3014. return true;
  3015. }
  3016. // When atlas->RendererHasTextures = true, this is only called if no font were loaded.
  3017. void ImFontAtlasBuildMain(ImFontAtlas* atlas)
  3018. {
  3019. IM_ASSERT(!atlas->Locked && "Cannot modify a locked ImFontAtlas!");
  3020. if (atlas->TexData && atlas->TexData->Format != atlas->TexDesiredFormat)
  3021. {
  3022. ImVec2i new_tex_size = ImFontAtlasTextureGetSizeEstimate(atlas);
  3023. ImFontAtlasBuildDestroy(atlas);
  3024. ImFontAtlasTextureAdd(atlas, new_tex_size.x, new_tex_size.y);
  3025. }
  3026. if (atlas->Builder == NULL)
  3027. ImFontAtlasBuildInit(atlas);
  3028. // Default font is none are specified
  3029. if (atlas->Sources.Size == 0)
  3030. atlas->AddFontDefault();
  3031. // [LEGACY] For backends not supporting RendererHasTextures: preload all glyphs
  3032. ImFontAtlasBuildUpdateRendererHasTexturesFromContext(atlas);
  3033. if (atlas->RendererHasTextures == false) // ~ImGuiBackendFlags_RendererHasTextures
  3034. ImFontAtlasBuildLegacyPreloadAllGlyphRanges(atlas);
  3035. atlas->TexIsBuilt = true;
  3036. }
  3037. void ImFontAtlasBuildGetOversampleFactors(ImFontConfig* src, ImFontBaked* baked, int* out_oversample_h, int* out_oversample_v)
  3038. {
  3039. // Automatically disable horizontal oversampling over size 36
  3040. const float raster_size = baked->Size * baked->RasterizerDensity * src->RasterizerDensity;
  3041. *out_oversample_h = (src->OversampleH != 0) ? src->OversampleH : (raster_size > 36.0f || src->PixelSnapH) ? 1 : 2;
  3042. *out_oversample_v = (src->OversampleV != 0) ? src->OversampleV : 1;
  3043. }
  3044. // Setup main font loader for the atlas
  3045. // Every font source (ImFontConfig) will use this unless ImFontConfig::FontLoader specify a custom loader.
  3046. void ImFontAtlasBuildSetupFontLoader(ImFontAtlas* atlas, const ImFontLoader* font_loader)
  3047. {
  3048. if (atlas->FontLoader == font_loader)
  3049. return;
  3050. IM_ASSERT(!atlas->Locked && "Cannot modify a locked ImFontAtlas!");
  3051. for (ImFont* font : atlas->Fonts)
  3052. ImFontAtlasFontDestroyOutput(atlas, font);
  3053. if (atlas->Builder && atlas->FontLoader && atlas->FontLoader->LoaderShutdown)
  3054. atlas->FontLoader->LoaderShutdown(atlas);
  3055. atlas->FontLoader = font_loader;
  3056. atlas->FontLoaderName = font_loader ? font_loader->Name : "NULL";
  3057. IM_ASSERT(atlas->FontLoaderData == NULL);
  3058. if (atlas->Builder && atlas->FontLoader && atlas->FontLoader->LoaderInit)
  3059. atlas->FontLoader->LoaderInit(atlas);
  3060. for (ImFont* font : atlas->Fonts)
  3061. ImFontAtlasFontInitOutput(atlas, font);
  3062. for (ImFont* font : atlas->Fonts)
  3063. for (ImFontConfig* src : font->Sources)
  3064. ImFontAtlasFontSourceAddToFont(atlas, font, src);
  3065. }
  3066. // Preload all glyph ranges for legacy backends.
  3067. // This may lead to multiple texture creation which might be a little slower than before.
  3068. void ImFontAtlasBuildLegacyPreloadAllGlyphRanges(ImFontAtlas* atlas)
  3069. {
  3070. atlas->Builder->PreloadedAllGlyphsRanges = true;
  3071. for (ImFont* font : atlas->Fonts)
  3072. {
  3073. ImFontBaked* baked = font->GetFontBaked(font->LegacySize);
  3074. if (font->FallbackChar != 0)
  3075. baked->FindGlyph(font->FallbackChar);
  3076. if (font->EllipsisChar != 0)
  3077. baked->FindGlyph(font->EllipsisChar);
  3078. for (ImFontConfig* src : font->Sources)
  3079. {
  3080. const ImWchar* ranges = src->GlyphRanges ? src->GlyphRanges : atlas->GetGlyphRangesDefault();
  3081. for (; ranges[0]; ranges += 2)
  3082. for (unsigned int c = ranges[0]; c <= ranges[1] && c <= IM_UNICODE_CODEPOINT_MAX; c++) //-V560
  3083. baked->FindGlyph((ImWchar)c);
  3084. }
  3085. }
  3086. }
  3087. // FIXME: May make ImFont::Sources a ImSpan<> and move ownership to ImFontAtlas
  3088. void ImFontAtlasBuildUpdatePointers(ImFontAtlas* atlas)
  3089. {
  3090. for (ImFont* font : atlas->Fonts)
  3091. font->Sources.resize(0);
  3092. for (ImFontConfig& src : atlas->Sources)
  3093. src.DstFont->Sources.push_back(&src);
  3094. }
  3095. // Render a white-colored bitmap encoded in a string
  3096. void ImFontAtlasBuildRenderBitmapFromString(ImFontAtlas* atlas, int x, int y, int w, int h, const char* in_str, char in_marker_char)
  3097. {
  3098. ImTextureData* tex = atlas->TexData;
  3099. IM_ASSERT(x >= 0 && x + w <= tex->Width);
  3100. IM_ASSERT(y >= 0 && y + h <= tex->Height);
  3101. switch (tex->Format)
  3102. {
  3103. case ImTextureFormat_Alpha8:
  3104. {
  3105. ImU8* out_p = (ImU8*)tex->GetPixelsAt(x, y);
  3106. for (int off_y = 0; off_y < h; off_y++, out_p += tex->Width, in_str += w)
  3107. for (int off_x = 0; off_x < w; off_x++)
  3108. out_p[off_x] = (in_str[off_x] == in_marker_char) ? 0xFF : 0x00;
  3109. break;
  3110. }
  3111. case ImTextureFormat_RGBA32:
  3112. {
  3113. ImU32* out_p = (ImU32*)tex->GetPixelsAt(x, y);
  3114. for (int off_y = 0; off_y < h; off_y++, out_p += tex->Width, in_str += w)
  3115. for (int off_x = 0; off_x < w; off_x++)
  3116. out_p[off_x] = (in_str[off_x] == in_marker_char) ? IM_COL32_WHITE : IM_COL32_BLACK_TRANS;
  3117. break;
  3118. }
  3119. }
  3120. }
  3121. static void ImFontAtlasBuildUpdateBasicTexData(ImFontAtlas* atlas)
  3122. {
  3123. // Pack and store identifier so we can refresh UV coordinates on texture resize.
  3124. // FIXME-NEWATLAS: User/custom rects where user code wants to store UV coordinates will need to do the same thing.
  3125. ImFontAtlasBuilder* builder = atlas->Builder;
  3126. ImVec2i pack_size = (atlas->Flags & ImFontAtlasFlags_NoMouseCursors) ? ImVec2i(2, 2) : ImVec2i(FONT_ATLAS_DEFAULT_TEX_DATA_W * 2 + 1, FONT_ATLAS_DEFAULT_TEX_DATA_H);
  3127. ImFontAtlasRect r;
  3128. bool add_and_draw = (atlas->GetCustomRect(builder->PackIdMouseCursors, &r) == false);
  3129. if (add_and_draw)
  3130. {
  3131. builder->PackIdMouseCursors = atlas->AddCustomRect(pack_size.x, pack_size.y, &r);
  3132. IM_ASSERT(builder->PackIdMouseCursors != ImFontAtlasRectId_Invalid);
  3133. // Draw to texture
  3134. if (atlas->Flags & ImFontAtlasFlags_NoMouseCursors)
  3135. {
  3136. // 2x2 white pixels
  3137. ImFontAtlasBuildRenderBitmapFromString(atlas, r.x, r.y, 2, 2, "XX" "XX", 'X');
  3138. }
  3139. else
  3140. {
  3141. // 2x2 white pixels + mouse cursors
  3142. const int x_for_white = r.x;
  3143. const int x_for_black = r.x + FONT_ATLAS_DEFAULT_TEX_DATA_W + 1;
  3144. ImFontAtlasBuildRenderBitmapFromString(atlas, x_for_white, r.y, FONT_ATLAS_DEFAULT_TEX_DATA_W, FONT_ATLAS_DEFAULT_TEX_DATA_H, FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, '.');
  3145. ImFontAtlasBuildRenderBitmapFromString(atlas, x_for_black, r.y, FONT_ATLAS_DEFAULT_TEX_DATA_W, FONT_ATLAS_DEFAULT_TEX_DATA_H, FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, 'X');
  3146. }
  3147. }
  3148. // Refresh UV coordinates
  3149. atlas->TexUvWhitePixel = ImVec2((r.x + 0.5f) * atlas->TexUvScale.x, (r.y + 0.5f) * atlas->TexUvScale.y);
  3150. }
  3151. static void ImFontAtlasBuildUpdateLinesTexData(ImFontAtlas* atlas)
  3152. {
  3153. if (atlas->Flags & ImFontAtlasFlags_NoBakedLines)
  3154. return;
  3155. // Pack and store identifier so we can refresh UV coordinates on texture resize.
  3156. ImTextureData* tex = atlas->TexData;
  3157. ImFontAtlasBuilder* builder = atlas->Builder;
  3158. ImFontAtlasRect r;
  3159. bool add_and_draw = atlas->GetCustomRect(builder->PackIdLinesTexData, &r) == false;
  3160. if (add_and_draw)
  3161. {
  3162. ImVec2i pack_size = ImVec2i(IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 2, IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1);
  3163. builder->PackIdLinesTexData = atlas->AddCustomRect(pack_size.x, pack_size.y, &r);
  3164. IM_ASSERT(builder->PackIdLinesTexData != ImFontAtlasRectId_Invalid);
  3165. }
  3166. // Register texture region for thick lines
  3167. // The +2 here is to give space for the end caps, whilst height +1 is to accommodate the fact we have a zero-width row
  3168. // This generates a triangular shape in the texture, with the various line widths stacked on top of each other to allow interpolation between them
  3169. for (int n = 0; n < IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1; n++) // +1 because of the zero-width row
  3170. {
  3171. // Each line consists of at least two empty pixels at the ends, with a line of solid pixels in the middle
  3172. const int y = n;
  3173. const int line_width = n;
  3174. const int pad_left = (r.w - line_width) / 2;
  3175. const int pad_right = r.w - (pad_left + line_width);
  3176. IM_ASSERT(pad_left + line_width + pad_right == r.w && y < r.h); // Make sure we're inside the texture bounds before we start writing pixels
  3177. // Write each slice
  3178. if (add_and_draw && tex->Format == ImTextureFormat_Alpha8)
  3179. {
  3180. ImU8* write_ptr = (ImU8*)tex->GetPixelsAt(r.x, r.y + y);
  3181. for (int i = 0; i < pad_left; i++)
  3182. *(write_ptr + i) = 0x00;
  3183. for (int i = 0; i < line_width; i++)
  3184. *(write_ptr + pad_left + i) = 0xFF;
  3185. for (int i = 0; i < pad_right; i++)
  3186. *(write_ptr + pad_left + line_width + i) = 0x00;
  3187. }
  3188. else if (add_and_draw && tex->Format == ImTextureFormat_RGBA32)
  3189. {
  3190. ImU32* write_ptr = (ImU32*)(void*)tex->GetPixelsAt(r.x, r.y + y);
  3191. for (int i = 0; i < pad_left; i++)
  3192. *(write_ptr + i) = IM_COL32(255, 255, 255, 0);
  3193. for (int i = 0; i < line_width; i++)
  3194. *(write_ptr + pad_left + i) = IM_COL32_WHITE;
  3195. for (int i = 0; i < pad_right; i++)
  3196. *(write_ptr + pad_left + line_width + i) = IM_COL32(255, 255, 255, 0);
  3197. }
  3198. // Refresh UV coordinates
  3199. ImVec2 uv0 = ImVec2((float)(r.x + pad_left - 1), (float)(r.y + y)) * atlas->TexUvScale;
  3200. ImVec2 uv1 = ImVec2((float)(r.x + pad_left + line_width + 1), (float)(r.y + y + 1)) * atlas->TexUvScale;
  3201. float half_v = (uv0.y + uv1.y) * 0.5f; // Calculate a constant V in the middle of the row to avoid sampling artifacts
  3202. atlas->TexUvLines[n] = ImVec4(uv0.x, half_v, uv1.x, half_v);
  3203. }
  3204. }
  3205. //-----------------------------------------------------------------------------------------------------------------------------
  3206. // Was tempted to lazily init FontSrc but wouldn't save much + makes it more complicated to detect invalid data at AddFont()
  3207. bool ImFontAtlasFontInitOutput(ImFontAtlas* atlas, ImFont* font)
  3208. {
  3209. bool ret = true;
  3210. for (ImFontConfig* src : font->Sources)
  3211. if (!ImFontAtlasFontSourceInit(atlas, src))
  3212. ret = false;
  3213. IM_ASSERT(ret); // Unclear how to react to this meaningfully. Assume that result will be same as initial AddFont() call.
  3214. return ret;
  3215. }
  3216. // Keep source/input FontData
  3217. void ImFontAtlasFontDestroyOutput(ImFontAtlas* atlas, ImFont* font)
  3218. {
  3219. font->ClearOutputData();
  3220. for (ImFontConfig* src : font->Sources)
  3221. {
  3222. const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader;
  3223. if (loader && loader->FontSrcDestroy != NULL)
  3224. loader->FontSrcDestroy(atlas, src);
  3225. }
  3226. }
  3227. //-----------------------------------------------------------------------------------------------------------------------------
  3228. bool ImFontAtlasFontSourceInit(ImFontAtlas* atlas, ImFontConfig* src)
  3229. {
  3230. const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader;
  3231. if (loader->FontSrcInit != NULL && !loader->FontSrcInit(atlas, src))
  3232. return false;
  3233. return true;
  3234. }
  3235. void ImFontAtlasFontSourceAddToFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* src)
  3236. {
  3237. if (src->MergeMode == false)
  3238. {
  3239. font->ClearOutputData();
  3240. //font->FontSize = src->SizePixels;
  3241. font->ContainerAtlas = atlas;
  3242. IM_ASSERT(font->Sources[0] == src);
  3243. }
  3244. atlas->TexIsBuilt = false; // For legacy backends
  3245. ImFontAtlasBuildSetupFontSpecialGlyphs(atlas, font, src);
  3246. }
  3247. void ImFontAtlasFontDestroySourceData(ImFontAtlas* atlas, ImFontConfig* src)
  3248. {
  3249. IM_UNUSED(atlas);
  3250. if (src->FontDataOwnedByAtlas)
  3251. IM_FREE(src->FontData);
  3252. src->FontData = NULL;
  3253. if (src->GlyphExcludeRanges)
  3254. IM_FREE((void*)src->GlyphExcludeRanges);
  3255. src->GlyphExcludeRanges = NULL;
  3256. }
  3257. // Create a compact, baked "..." if it doesn't exist, by using the ".".
  3258. // This may seem overly complicated right now but the point is to exercise and improve a technique which should be increasingly used.
  3259. // FIXME-NEWATLAS: This borrows too much from FontLoader's FontLoadGlyph() handlers and suggest that we should add further helpers.
  3260. static ImFontGlyph* ImFontAtlasBuildSetupFontBakedEllipsis(ImFontAtlas* atlas, ImFontBaked* baked)
  3261. {
  3262. ImFont* font = baked->ContainerFont;
  3263. IM_ASSERT(font->EllipsisChar != 0);
  3264. const ImFontGlyph* dot_glyph = baked->FindGlyphNoFallback((ImWchar)'.');
  3265. if (dot_glyph == NULL)
  3266. dot_glyph = baked->FindGlyphNoFallback((ImWchar)0xFF0E);
  3267. if (dot_glyph == NULL)
  3268. return NULL;
  3269. ImFontAtlasRectId dot_r_id = dot_glyph->PackId; // Deep copy to avoid invalidation of glyphs and rect pointers
  3270. ImTextureRect* dot_r = ImFontAtlasPackGetRect(atlas, dot_r_id);
  3271. const int dot_spacing = 1;
  3272. const float dot_step = (dot_glyph->X1 - dot_glyph->X0) + dot_spacing;
  3273. ImFontAtlasRectId pack_id = ImFontAtlasPackAddRect(atlas, (dot_r->w * 3 + dot_spacing * 2), dot_r->h);
  3274. ImTextureRect* r = ImFontAtlasPackGetRect(atlas, pack_id);
  3275. ImFontGlyph glyph_in = {};
  3276. ImFontGlyph* glyph = &glyph_in;
  3277. glyph->Codepoint = font->EllipsisChar;
  3278. glyph->AdvanceX = ImMax(dot_glyph->AdvanceX, dot_glyph->X0 + dot_step * 3.0f - dot_spacing); // FIXME: Slightly odd for normally mono-space fonts but since this is used for trailing contents.
  3279. glyph->X0 = dot_glyph->X0;
  3280. glyph->Y0 = dot_glyph->Y0;
  3281. glyph->X1 = dot_glyph->X0 + dot_step * 3 - dot_spacing;
  3282. glyph->Y1 = dot_glyph->Y1;
  3283. glyph->Visible = true;
  3284. glyph->PackId = pack_id;
  3285. glyph = ImFontAtlasBakedAddFontGlyph(atlas, baked, NULL, glyph);
  3286. dot_glyph = NULL; // Invalidated
  3287. // Copy to texture, post-process and queue update for backend
  3288. // FIXME-NEWATLAS-V2: Dot glyph is already post-processed as this point, so this would damage it.
  3289. dot_r = ImFontAtlasPackGetRect(atlas, dot_r_id);
  3290. ImTextureData* tex = atlas->TexData;
  3291. for (int n = 0; n < 3; n++)
  3292. ImFontAtlasTextureBlockCopy(tex, dot_r->x, dot_r->y, tex, r->x + (dot_r->w + dot_spacing) * n, r->y, dot_r->w, dot_r->h);
  3293. ImFontAtlasTextureBlockQueueUpload(atlas, tex, r->x, r->y, r->w, r->h);
  3294. return glyph;
  3295. }
  3296. // Load fallback in order to obtain its index
  3297. // (this is called from in hot-path so we avoid extraneous parameters to minimize impact on code size)
  3298. static void ImFontAtlasBuildSetupFontBakedFallback(ImFontBaked* baked)
  3299. {
  3300. IM_ASSERT(baked->FallbackGlyphIndex == -1);
  3301. IM_ASSERT(baked->FallbackAdvanceX == 0.0f);
  3302. ImFont* font = baked->ContainerFont;
  3303. ImFontGlyph* fallback_glyph = NULL;
  3304. if (font->FallbackChar != 0)
  3305. fallback_glyph = baked->FindGlyphNoFallback(font->FallbackChar);
  3306. if (fallback_glyph == NULL)
  3307. {
  3308. ImFontGlyph* space_glyph = baked->FindGlyphNoFallback((ImWchar)' ');
  3309. ImFontGlyph glyph;
  3310. glyph.Codepoint = 0;
  3311. glyph.AdvanceX = space_glyph ? space_glyph->AdvanceX : IM_ROUND(baked->Size * 0.40f);
  3312. fallback_glyph = ImFontAtlasBakedAddFontGlyph(font->ContainerAtlas, baked, NULL, &glyph);
  3313. }
  3314. baked->FallbackGlyphIndex = baked->Glyphs.index_from_ptr(fallback_glyph); // Storing index avoid need to update pointer on growth and simplify inner loop code
  3315. baked->FallbackAdvanceX = fallback_glyph->AdvanceX;
  3316. }
  3317. static void ImFontAtlasBuildSetupFontBakedBlanks(ImFontAtlas* atlas, ImFontBaked* baked)
  3318. {
  3319. // Mark space as always hidden (not strictly correct/necessary. but some e.g. icons fonts don't have a space. it tends to look neater in previews)
  3320. ImFontGlyph* space_glyph = baked->FindGlyphNoFallback((ImWchar)' ');
  3321. if (space_glyph != NULL)
  3322. space_glyph->Visible = false;
  3323. // Setup Tab character.
  3324. // FIXME: Needs proper TAB handling but it needs to be contextualized (or we could arbitrary say that each string starts at "column 0" ?)
  3325. if (baked->FindGlyphNoFallback('\t') == NULL && space_glyph != NULL)
  3326. {
  3327. ImFontGlyph tab_glyph;
  3328. tab_glyph.Codepoint = '\t';
  3329. tab_glyph.AdvanceX = space_glyph->AdvanceX * IM_TABSIZE;
  3330. ImFontAtlasBakedAddFontGlyph(atlas, baked, NULL, &tab_glyph);
  3331. }
  3332. }
  3333. // Load/identify special glyphs
  3334. // (note that this is called again for fonts with MergeMode)
  3335. void ImFontAtlasBuildSetupFontSpecialGlyphs(ImFontAtlas* atlas, ImFont* font, ImFontConfig* src)
  3336. {
  3337. IM_UNUSED(atlas);
  3338. IM_ASSERT(font->Sources.contains(src));
  3339. // Find Fallback character. Actual glyph loaded in GetFontBaked().
  3340. const ImWchar fallback_chars[] = { font->FallbackChar, (ImWchar)IM_UNICODE_CODEPOINT_INVALID, (ImWchar)'?', (ImWchar)' ' };
  3341. if (font->FallbackChar == 0)
  3342. for (ImWchar candidate_char : fallback_chars)
  3343. if (candidate_char != 0 && font->IsGlyphInFont(candidate_char))
  3344. {
  3345. font->FallbackChar = (ImWchar)candidate_char;
  3346. break;
  3347. }
  3348. // Setup Ellipsis character. It is required for rendering elided text. We prefer using U+2026 (horizontal ellipsis).
  3349. // However some old fonts may contain ellipsis at U+0085. Here we auto-detect most suitable ellipsis character.
  3350. // FIXME: Note that 0x2026 is rarely included in our font ranges. Because of this we are more likely to use three individual dots.
  3351. const ImWchar ellipsis_chars[] = { src->EllipsisChar, (ImWchar)0x2026, (ImWchar)0x0085 };
  3352. if (font->EllipsisChar == 0)
  3353. for (ImWchar candidate_char : ellipsis_chars)
  3354. if (candidate_char != 0 && font->IsGlyphInFont(candidate_char))
  3355. {
  3356. font->EllipsisChar = candidate_char;
  3357. break;
  3358. }
  3359. if (font->EllipsisChar == 0)
  3360. {
  3361. font->EllipsisChar = 0x0085;
  3362. font->EllipsisAutoBake = true;
  3363. }
  3364. }
  3365. void ImFontAtlasBakedDiscardFontGlyph(ImFontAtlas* atlas, ImFont* font, ImFontBaked* baked, ImFontGlyph* glyph)
  3366. {
  3367. if (glyph->PackId != ImFontAtlasRectId_Invalid)
  3368. {
  3369. ImFontAtlasPackDiscardRect(atlas, glyph->PackId);
  3370. glyph->PackId = ImFontAtlasRectId_Invalid;
  3371. }
  3372. ImWchar c = (ImWchar)glyph->Codepoint;
  3373. IM_ASSERT(font->FallbackChar != c && font->EllipsisChar != c); // Unsupported for simplicity
  3374. IM_ASSERT(glyph >= baked->Glyphs.Data && glyph < baked->Glyphs.Data + baked->Glyphs.Size);
  3375. IM_UNUSED(font);
  3376. baked->IndexLookup[c] = IM_FONTGLYPH_INDEX_UNUSED;
  3377. baked->IndexAdvanceX[c] = baked->FallbackAdvanceX;
  3378. }
  3379. ImFontBaked* ImFontAtlasBakedAdd(ImFontAtlas* atlas, ImFont* font, float font_size, float font_rasterizer_density, ImGuiID baked_id)
  3380. {
  3381. IMGUI_DEBUG_LOG_FONT("[font] Created baked %.2fpx\n", font_size);
  3382. ImFontBaked* baked = atlas->Builder->BakedPool.push_back(ImFontBaked());
  3383. baked->Size = font_size;
  3384. baked->RasterizerDensity = font_rasterizer_density;
  3385. baked->BakedId = baked_id;
  3386. baked->ContainerFont = font;
  3387. baked->LastUsedFrame = atlas->Builder->FrameCount;
  3388. // Initialize backend data
  3389. size_t loader_data_size = 0;
  3390. for (ImFontConfig* src : font->Sources) // Cannot easily be cached as we allow changing backend
  3391. {
  3392. const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader;
  3393. loader_data_size += loader->FontBakedSrcLoaderDataSize;
  3394. }
  3395. baked->FontLoaderDatas = (loader_data_size > 0) ? IM_ALLOC(loader_data_size) : NULL;
  3396. char* loader_data_p = (char*)baked->FontLoaderDatas;
  3397. for (ImFontConfig* src : font->Sources)
  3398. {
  3399. const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader;
  3400. if (loader->FontBakedInit)
  3401. loader->FontBakedInit(atlas, src, baked, loader_data_p);
  3402. loader_data_p += loader->FontBakedSrcLoaderDataSize;
  3403. }
  3404. ImFontAtlasBuildSetupFontBakedBlanks(atlas, baked);
  3405. return baked;
  3406. }
  3407. // FIXME-OPT: This is not a fast query. Adding a BakedCount field in Font might allow to take a shortcut for the most common case.
  3408. ImFontBaked* ImFontAtlasBakedGetClosestMatch(ImFontAtlas* atlas, ImFont* font, float font_size, float font_rasterizer_density)
  3409. {
  3410. ImFontAtlasBuilder* builder = atlas->Builder;
  3411. for (int step_n = 0; step_n < 2; step_n++)
  3412. {
  3413. ImFontBaked* closest_larger_match = NULL;
  3414. ImFontBaked* closest_smaller_match = NULL;
  3415. for (int baked_n = 0; baked_n < builder->BakedPool.Size; baked_n++)
  3416. {
  3417. ImFontBaked* baked = &builder->BakedPool[baked_n];
  3418. if (baked->ContainerFont != font || baked->WantDestroy)
  3419. continue;
  3420. if (step_n == 0 && baked->RasterizerDensity != font_rasterizer_density) // First try with same density
  3421. continue;
  3422. if (baked->Size > font_size && (closest_larger_match == NULL || baked->Size < closest_larger_match->Size))
  3423. closest_larger_match = baked;
  3424. if (baked->Size < font_size && (closest_smaller_match == NULL || baked->Size > closest_smaller_match->Size))
  3425. closest_smaller_match = baked;
  3426. }
  3427. if (closest_larger_match)
  3428. if (closest_smaller_match == NULL || (closest_larger_match->Size >= font_size * 2.0f && closest_smaller_match->Size > font_size * 0.5f))
  3429. return closest_larger_match;
  3430. if (closest_smaller_match)
  3431. return closest_smaller_match;
  3432. }
  3433. return NULL;
  3434. }
  3435. void ImFontAtlasBakedDiscard(ImFontAtlas* atlas, ImFont* font, ImFontBaked* baked)
  3436. {
  3437. ImFontAtlasBuilder* builder = atlas->Builder;
  3438. IMGUI_DEBUG_LOG_FONT("[font] Discard baked %.2f for \"%s\"\n", baked->Size, font->GetDebugName());
  3439. for (ImFontGlyph& glyph : baked->Glyphs)
  3440. if (glyph.PackId != ImFontAtlasRectId_Invalid)
  3441. ImFontAtlasPackDiscardRect(atlas, glyph.PackId);
  3442. char* loader_data_p = (char*)baked->FontLoaderDatas;
  3443. for (ImFontConfig* src : font->Sources)
  3444. {
  3445. const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader;
  3446. if (loader->FontBakedDestroy)
  3447. loader->FontBakedDestroy(atlas, src, baked, loader_data_p);
  3448. loader_data_p += loader->FontBakedSrcLoaderDataSize;
  3449. }
  3450. if (baked->FontLoaderDatas)
  3451. {
  3452. IM_FREE(baked->FontLoaderDatas);
  3453. baked->FontLoaderDatas = NULL;
  3454. }
  3455. builder->BakedMap.SetVoidPtr(baked->BakedId, NULL);
  3456. builder->BakedDiscardedCount++;
  3457. baked->ClearOutputData();
  3458. baked->WantDestroy = true;
  3459. font->LastBaked = NULL;
  3460. }
  3461. // use unused_frames==0 to discard everything.
  3462. void ImFontAtlasFontDiscardBakes(ImFontAtlas* atlas, ImFont* font, int unused_frames)
  3463. {
  3464. if (ImFontAtlasBuilder* builder = atlas->Builder) // This can be called from font destructor
  3465. for (int baked_n = 0; baked_n < builder->BakedPool.Size; baked_n++)
  3466. {
  3467. ImFontBaked* baked = &builder->BakedPool[baked_n];
  3468. if (baked->LastUsedFrame + unused_frames > atlas->Builder->FrameCount)
  3469. continue;
  3470. if (baked->ContainerFont != font || baked->WantDestroy)
  3471. continue;
  3472. ImFontAtlasBakedDiscard(atlas, font, baked);
  3473. }
  3474. }
  3475. // use unused_frames==0 to discard everything.
  3476. void ImFontAtlasBuildDiscardBakes(ImFontAtlas* atlas, int unused_frames)
  3477. {
  3478. ImFontAtlasBuilder* builder = atlas->Builder;
  3479. for (int baked_n = 0; baked_n < builder->BakedPool.Size; baked_n++)
  3480. {
  3481. ImFontBaked* baked = &builder->BakedPool[baked_n];
  3482. if (baked->LastUsedFrame + unused_frames > atlas->Builder->FrameCount)
  3483. continue;
  3484. if (baked->WantDestroy || (baked->ContainerFont->Flags & ImFontFlags_LockBakedSizes))
  3485. continue;
  3486. ImFontAtlasBakedDiscard(atlas, baked->ContainerFont, baked);
  3487. }
  3488. }
  3489. // Those functions are designed to facilitate changing the underlying structures for ImFontAtlas to store an array of ImDrawListSharedData*
  3490. void ImFontAtlasAddDrawListSharedData(ImFontAtlas* atlas, ImDrawListSharedData* data)
  3491. {
  3492. IM_ASSERT(!atlas->DrawListSharedDatas.contains(data));
  3493. atlas->DrawListSharedDatas.push_back(data);
  3494. }
  3495. void ImFontAtlasRemoveDrawListSharedData(ImFontAtlas* atlas, ImDrawListSharedData* data)
  3496. {
  3497. IM_ASSERT(atlas->DrawListSharedDatas.contains(data));
  3498. atlas->DrawListSharedDatas.find_erase(data);
  3499. }
  3500. // Update texture identifier in all active draw lists
  3501. void ImFontAtlasUpdateDrawListsTextures(ImFontAtlas* atlas, ImTextureRef old_tex, ImTextureRef new_tex)
  3502. {
  3503. for (ImDrawListSharedData* shared_data : atlas->DrawListSharedDatas)
  3504. for (ImDrawList* draw_list : shared_data->DrawLists)
  3505. {
  3506. // Replace in command-buffer
  3507. // (there is not need to replace in ImDrawListSplitter: current channel is in ImDrawList's CmdBuffer[],
  3508. // other channels will be on SetCurrentChannel() which already needs to compare CmdHeader anyhow)
  3509. if (draw_list->CmdBuffer.Size > 0 && draw_list->_CmdHeader.TexRef == old_tex)
  3510. draw_list->_SetTexture(new_tex);
  3511. // Replace in stack
  3512. for (ImTextureRef& stacked_tex : draw_list->_TextureStack)
  3513. if (stacked_tex == old_tex)
  3514. stacked_tex = new_tex;
  3515. }
  3516. }
  3517. // Update texture coordinates in all draw list shared context
  3518. // FIXME-NEWATLAS FIXME-OPT: Doesn't seem necessary to update for all, only one bound to current context?
  3519. void ImFontAtlasUpdateDrawListsSharedData(ImFontAtlas* atlas)
  3520. {
  3521. for (ImDrawListSharedData* shared_data : atlas->DrawListSharedDatas)
  3522. if (shared_data->FontAtlas == atlas)
  3523. {
  3524. shared_data->TexUvWhitePixel = atlas->TexUvWhitePixel;
  3525. shared_data->TexUvLines = atlas->TexUvLines;
  3526. }
  3527. }
  3528. // Set current texture. This is mostly called from AddTexture() + to handle a failed resize.
  3529. static void ImFontAtlasBuildSetTexture(ImFontAtlas* atlas, ImTextureData* tex)
  3530. {
  3531. ImTextureRef old_tex_ref = atlas->TexRef;
  3532. atlas->TexData = tex;
  3533. atlas->TexUvScale = ImVec2(1.0f / tex->Width, 1.0f / tex->Height);
  3534. atlas->TexRef._TexData = tex;
  3535. //atlas->TexRef._TexID = tex->TexID; // <-- We intentionally don't do that. It would be misleading and betray promise that both fields aren't set.
  3536. ImFontAtlasUpdateDrawListsTextures(atlas, old_tex_ref, atlas->TexRef);
  3537. }
  3538. // Create a new texture, discard previous one
  3539. ImTextureData* ImFontAtlasTextureAdd(ImFontAtlas* atlas, int w, int h)
  3540. {
  3541. ImTextureData* old_tex = atlas->TexData;
  3542. ImTextureData* new_tex;
  3543. // FIXME: Cannot reuse texture because old UV may have been used already (unless we remap UV).
  3544. /*if (old_tex != NULL && old_tex->Status == ImTextureStatus_WantCreate)
  3545. {
  3546. // Reuse texture not yet used by backend.
  3547. IM_ASSERT(old_tex->TexID == ImTextureID_Invalid && old_tex->BackendUserData == NULL);
  3548. old_tex->DestroyPixels();
  3549. old_tex->Updates.clear();
  3550. new_tex = old_tex;
  3551. old_tex = NULL;
  3552. }
  3553. else*/
  3554. {
  3555. // Add new
  3556. new_tex = IM_NEW(ImTextureData)();
  3557. new_tex->UniqueID = atlas->TexNextUniqueID++;
  3558. atlas->TexList.push_back(new_tex);
  3559. }
  3560. if (old_tex != NULL)
  3561. {
  3562. // Queue old as to destroy next frame
  3563. old_tex->WantDestroyNextFrame = true;
  3564. IM_ASSERT(old_tex->Status == ImTextureStatus_OK || old_tex->Status == ImTextureStatus_WantCreate || old_tex->Status == ImTextureStatus_WantUpdates);
  3565. }
  3566. new_tex->Create(atlas->TexDesiredFormat, w, h);
  3567. atlas->TexIsBuilt = false;
  3568. ImFontAtlasBuildSetTexture(atlas, new_tex);
  3569. return new_tex;
  3570. }
  3571. #if 0
  3572. #define STB_IMAGE_WRITE_IMPLEMENTATION
  3573. #include "../stb/stb_image_write.h"
  3574. static void ImFontAtlasDebugWriteTexToDisk(ImTextureData* tex, const char* description)
  3575. {
  3576. ImGuiContext& g = *GImGui;
  3577. char buf[128];
  3578. ImFormatString(buf, IM_ARRAYSIZE(buf), "[%05d] Texture #%03d - %s.png", g.FrameCount, tex->UniqueID, description);
  3579. stbi_write_png(buf, tex->Width, tex->Height, tex->BytesPerPixel, tex->Pixels, tex->GetPitch()); // tex->BytesPerPixel is technically not component, but ok for the formats we support.
  3580. }
  3581. #endif
  3582. void ImFontAtlasTextureRepack(ImFontAtlas* atlas, int w, int h)
  3583. {
  3584. ImFontAtlasBuilder* builder = atlas->Builder;
  3585. builder->LockDisableResize = true;
  3586. ImTextureData* old_tex = atlas->TexData;
  3587. ImTextureData* new_tex = ImFontAtlasTextureAdd(atlas, w, h);
  3588. new_tex->UseColors = old_tex->UseColors;
  3589. IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: resize+repack %dx%d => Texture #%03d: %dx%d\n", old_tex->UniqueID, old_tex->Width, old_tex->Height, new_tex->UniqueID, new_tex->Width, new_tex->Height);
  3590. //for (int baked_n = 0; baked_n < builder->BakedPool.Size; baked_n++)
  3591. // IMGUI_DEBUG_LOG_FONT("[font] - Baked %.2fpx, %d glyphs, want_destroy=%d\n", builder->BakedPool[baked_n].FontSize, builder->BakedPool[baked_n].Glyphs.Size, builder->BakedPool[baked_n].WantDestroy);
  3592. //IMGUI_DEBUG_LOG_FONT("[font] - Old packed rects: %d, area %d px\n", builder->RectsPackedCount, builder->RectsPackedSurface);
  3593. //ImFontAtlasDebugWriteTexToDisk(old_tex, "Before Pack");
  3594. // Repack, lose discarded rectangle, copy pixels
  3595. // FIXME-NEWATLAS: This is unstable because packing order is based on RectsIndex
  3596. // FIXME-NEWATLAS-V2: Repacking in batch would be beneficial to packing heuristic, and fix stability.
  3597. // FIXME-NEWATLAS-TESTS: Test calling RepackTexture with size too small to fits existing rects.
  3598. ImFontAtlasPackInit(atlas);
  3599. ImVector<ImTextureRect> old_rects;
  3600. ImVector<ImFontAtlasRectEntry> old_index = builder->RectsIndex;
  3601. old_rects.swap(builder->Rects);
  3602. for (ImFontAtlasRectEntry& index_entry : builder->RectsIndex)
  3603. {
  3604. if (index_entry.IsUsed == false)
  3605. continue;
  3606. ImTextureRect& old_r = old_rects[index_entry.TargetIndex];
  3607. if (old_r.w == 0 && old_r.h == 0)
  3608. continue;
  3609. ImFontAtlasRectId new_r_id = ImFontAtlasPackAddRect(atlas, old_r.w, old_r.h, &index_entry);
  3610. if (new_r_id == ImFontAtlasRectId_Invalid)
  3611. {
  3612. // Undo, grow texture and try repacking again.
  3613. // FIXME-NEWATLAS-TESTS: This is a very rarely exercised path! It needs to be automatically tested properly.
  3614. IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: resize failed. Will grow.\n", new_tex->UniqueID);
  3615. new_tex->WantDestroyNextFrame = true;
  3616. builder->Rects.swap(old_rects);
  3617. builder->RectsIndex = old_index;
  3618. ImFontAtlasBuildSetTexture(atlas, old_tex);
  3619. ImFontAtlasTextureGrow(atlas, w, h); // Recurse
  3620. return;
  3621. }
  3622. IM_ASSERT(ImFontAtlasRectId_GetIndex(new_r_id) == builder->RectsIndex.index_from_ptr(&index_entry));
  3623. ImTextureRect* new_r = ImFontAtlasPackGetRect(atlas, new_r_id);
  3624. ImFontAtlasTextureBlockCopy(old_tex, old_r.x, old_r.y, new_tex, new_r->x, new_r->y, new_r->w, new_r->h);
  3625. }
  3626. IM_ASSERT(old_rects.Size == builder->Rects.Size + builder->RectsDiscardedCount);
  3627. builder->RectsDiscardedCount = 0;
  3628. builder->RectsDiscardedSurface = 0;
  3629. // Patch glyphs UV
  3630. for (int baked_n = 0; baked_n < builder->BakedPool.Size; baked_n++)
  3631. for (ImFontGlyph& glyph : builder->BakedPool[baked_n].Glyphs)
  3632. if (glyph.PackId != ImFontAtlasRectId_Invalid)
  3633. {
  3634. ImTextureRect* r = ImFontAtlasPackGetRect(atlas, glyph.PackId);
  3635. glyph.U0 = (r->x) * atlas->TexUvScale.x;
  3636. glyph.V0 = (r->y) * atlas->TexUvScale.y;
  3637. glyph.U1 = (r->x + r->w) * atlas->TexUvScale.x;
  3638. glyph.V1 = (r->y + r->h) * atlas->TexUvScale.y;
  3639. }
  3640. // Update other cached UV
  3641. ImFontAtlasBuildUpdateLinesTexData(atlas);
  3642. ImFontAtlasBuildUpdateBasicTexData(atlas);
  3643. builder->LockDisableResize = false;
  3644. ImFontAtlasUpdateDrawListsSharedData(atlas);
  3645. //ImFontAtlasDebugWriteTexToDisk(new_tex, "After Pack");
  3646. }
  3647. void ImFontAtlasTextureGrow(ImFontAtlas* atlas, int old_tex_w, int old_tex_h)
  3648. {
  3649. //ImFontAtlasDebugWriteTexToDisk(atlas->TexData, "Before Grow");
  3650. ImFontAtlasBuilder* builder = atlas->Builder;
  3651. if (old_tex_w == -1)
  3652. old_tex_w = atlas->TexData->Width;
  3653. if (old_tex_h == -1)
  3654. old_tex_h = atlas->TexData->Height;
  3655. // FIXME-NEWATLAS-V2: What to do when reaching limits exposed by backend?
  3656. // FIXME-NEWATLAS-V2: Does ImFontAtlasFlags_NoPowerOfTwoHeight makes sense now? Allow 'lock' and 'compact' operations?
  3657. IM_ASSERT(ImIsPowerOfTwo(old_tex_w) && ImIsPowerOfTwo(old_tex_h));
  3658. IM_ASSERT(ImIsPowerOfTwo(atlas->TexMinWidth) && ImIsPowerOfTwo(atlas->TexMaxWidth) && ImIsPowerOfTwo(atlas->TexMinHeight) && ImIsPowerOfTwo(atlas->TexMaxHeight));
  3659. // Grow texture so it follows roughly a square.
  3660. // - Grow height before width, as width imply more packing nodes.
  3661. // - Caller should be taking account of RectsDiscardedSurface and may not need to grow.
  3662. int new_tex_w = (old_tex_h <= old_tex_w) ? old_tex_w : old_tex_w * 2;
  3663. int new_tex_h = (old_tex_h <= old_tex_w) ? old_tex_h * 2 : old_tex_h;
  3664. // Handle minimum size first (for pathologically large packed rects)
  3665. const int pack_padding = atlas->TexGlyphPadding;
  3666. new_tex_w = ImMax(new_tex_w, ImUpperPowerOfTwo(builder->MaxRectSize.x + pack_padding));
  3667. new_tex_h = ImMax(new_tex_h, ImUpperPowerOfTwo(builder->MaxRectSize.y + pack_padding));
  3668. new_tex_w = ImClamp(new_tex_w, atlas->TexMinWidth, atlas->TexMaxWidth);
  3669. new_tex_h = ImClamp(new_tex_h, atlas->TexMinHeight, atlas->TexMaxHeight);
  3670. if (new_tex_w == old_tex_w && new_tex_h == old_tex_h)
  3671. return;
  3672. ImFontAtlasTextureRepack(atlas, new_tex_w, new_tex_h);
  3673. }
  3674. void ImFontAtlasTextureMakeSpace(ImFontAtlas* atlas)
  3675. {
  3676. // Can some baked contents be ditched?
  3677. //IMGUI_DEBUG_LOG_FONT("[font] ImFontAtlasBuildMakeSpace()\n");
  3678. ImFontAtlasBuilder* builder = atlas->Builder;
  3679. ImFontAtlasBuildDiscardBakes(atlas, 2);
  3680. // Currently using a heuristic for repack without growing.
  3681. if (builder->RectsDiscardedSurface < builder->RectsPackedSurface * 0.20f)
  3682. ImFontAtlasTextureGrow(atlas);
  3683. else
  3684. ImFontAtlasTextureRepack(atlas, atlas->TexData->Width, atlas->TexData->Height);
  3685. }
  3686. ImVec2i ImFontAtlasTextureGetSizeEstimate(ImFontAtlas* atlas)
  3687. {
  3688. int min_w = ImUpperPowerOfTwo(atlas->TexMinWidth);
  3689. int min_h = ImUpperPowerOfTwo(atlas->TexMinHeight);
  3690. if (atlas->Builder == NULL || atlas->TexData == NULL || atlas->TexData->Status == ImTextureStatus_WantDestroy)
  3691. return ImVec2i(min_w, min_h);
  3692. ImFontAtlasBuilder* builder = atlas->Builder;
  3693. min_w = ImMax(ImUpperPowerOfTwo(builder->MaxRectSize.x), min_w);
  3694. min_h = ImMax(ImUpperPowerOfTwo(builder->MaxRectSize.y), min_h);
  3695. const int surface_approx = builder->RectsPackedSurface - builder->RectsDiscardedSurface; // Expected surface after repack
  3696. const int surface_sqrt = (int)sqrtf((float)surface_approx);
  3697. int new_tex_w;
  3698. int new_tex_h;
  3699. if (min_w >= min_h)
  3700. {
  3701. new_tex_w = ImMax(min_w, ImUpperPowerOfTwo(surface_sqrt));
  3702. new_tex_h = ImMax(min_h, (int)((surface_approx + new_tex_w - 1) / new_tex_w));
  3703. if ((atlas->Flags & ImFontAtlasFlags_NoPowerOfTwoHeight) == 0)
  3704. new_tex_h = ImUpperPowerOfTwo(new_tex_h);
  3705. }
  3706. else
  3707. {
  3708. new_tex_h = ImMax(min_h, ImUpperPowerOfTwo(surface_sqrt));
  3709. if ((atlas->Flags & ImFontAtlasFlags_NoPowerOfTwoHeight) == 0)
  3710. new_tex_h = ImUpperPowerOfTwo(new_tex_h);
  3711. new_tex_w = ImMax(min_w, (int)((surface_approx + new_tex_h - 1) / new_tex_h));
  3712. }
  3713. IM_ASSERT(ImIsPowerOfTwo(new_tex_w) && ImIsPowerOfTwo(new_tex_h));
  3714. return ImVec2i(new_tex_w, new_tex_h);
  3715. }
  3716. // Clear all output. Invalidates all AddCustomRect() return values!
  3717. void ImFontAtlasBuildClear(ImFontAtlas* atlas)
  3718. {
  3719. ImVec2i new_tex_size = ImFontAtlasTextureGetSizeEstimate(atlas);
  3720. ImFontAtlasBuildDestroy(atlas);
  3721. ImFontAtlasTextureAdd(atlas, new_tex_size.x, new_tex_size.y);
  3722. ImFontAtlasBuildInit(atlas);
  3723. for (ImFontConfig& src : atlas->Sources)
  3724. ImFontAtlasFontSourceInit(atlas, &src);
  3725. for (ImFont* font : atlas->Fonts)
  3726. for (ImFontConfig* src : font->Sources)
  3727. ImFontAtlasFontSourceAddToFont(atlas, font, src);
  3728. }
  3729. // You should not need to call this manually!
  3730. // If you think you do, let us know and we can advise about policies auto-compact.
  3731. void ImFontAtlasTextureCompact(ImFontAtlas* atlas)
  3732. {
  3733. ImFontAtlasBuilder* builder = atlas->Builder;
  3734. ImFontAtlasBuildDiscardBakes(atlas, 1);
  3735. ImTextureData* old_tex = atlas->TexData;
  3736. ImVec2i old_tex_size = ImVec2i(old_tex->Width, old_tex->Height);
  3737. ImVec2i new_tex_size = ImFontAtlasTextureGetSizeEstimate(atlas);
  3738. if (builder->RectsDiscardedCount == 0 && new_tex_size.x == old_tex_size.x && new_tex_size.y == old_tex_size.y)
  3739. return;
  3740. ImFontAtlasTextureRepack(atlas, new_tex_size.x, new_tex_size.y);
  3741. }
  3742. // Start packing over current empty texture
  3743. void ImFontAtlasBuildInit(ImFontAtlas* atlas)
  3744. {
  3745. // Select Backend
  3746. // - Note that we do not reassign to atlas->FontLoader, since it is likely to point to static data which
  3747. // may mess with some hot-reloading schemes. If you need to assign to this (for dynamic selection) AND are
  3748. // using a hot-reloading scheme that messes up static data, store your own instance of FontLoader somewhere
  3749. // and point to it instead of pointing directly to return value of the GetFontLoaderXXX functions.
  3750. if (atlas->FontLoader == NULL)
  3751. {
  3752. #ifdef IMGUI_ENABLE_FREETYPE
  3753. atlas->SetFontLoader(ImGuiFreeType::GetFontLoader());
  3754. #elif defined(IMGUI_ENABLE_STB_TRUETYPE)
  3755. atlas->SetFontLoader(ImFontAtlasGetFontLoaderForStbTruetype());
  3756. #else
  3757. IM_ASSERT(0); // Invalid Build function
  3758. #endif
  3759. }
  3760. // Create initial texture size
  3761. if (atlas->TexData == NULL || atlas->TexData->Pixels == NULL)
  3762. ImFontAtlasTextureAdd(atlas, ImUpperPowerOfTwo(atlas->TexMinWidth), ImUpperPowerOfTwo(atlas->TexMinHeight));
  3763. atlas->Builder = IM_NEW(ImFontAtlasBuilder)();
  3764. if (atlas->FontLoader->LoaderInit)
  3765. atlas->FontLoader->LoaderInit(atlas);
  3766. ImFontAtlasBuildUpdateRendererHasTexturesFromContext(atlas);
  3767. ImFontAtlasPackInit(atlas);
  3768. // Add required texture data
  3769. ImFontAtlasBuildUpdateLinesTexData(atlas);
  3770. ImFontAtlasBuildUpdateBasicTexData(atlas);
  3771. // Register fonts
  3772. ImFontAtlasBuildUpdatePointers(atlas);
  3773. // Update UV coordinates etc. stored in bound ImDrawListSharedData instance
  3774. ImFontAtlasUpdateDrawListsSharedData(atlas);
  3775. //atlas->TexIsBuilt = true;
  3776. }
  3777. // Destroy builder and all cached glyphs. Do not destroy actual fonts.
  3778. void ImFontAtlasBuildDestroy(ImFontAtlas* atlas)
  3779. {
  3780. for (ImFont* font : atlas->Fonts)
  3781. ImFontAtlasFontDestroyOutput(atlas, font);
  3782. if (atlas->Builder && atlas->FontLoader && atlas->FontLoader->LoaderShutdown)
  3783. {
  3784. atlas->FontLoader->LoaderShutdown(atlas);
  3785. IM_ASSERT(atlas->FontLoaderData == NULL);
  3786. }
  3787. IM_DELETE(atlas->Builder);
  3788. atlas->Builder = NULL;
  3789. }
  3790. void ImFontAtlasPackInit(ImFontAtlas * atlas)
  3791. {
  3792. ImTextureData* tex = atlas->TexData;
  3793. ImFontAtlasBuilder* builder = atlas->Builder;
  3794. // In theory we could decide to reduce the number of nodes, e.g. halve them, and waste a little texture space, but it doesn't seem worth it.
  3795. const int pack_node_count = tex->Width / 2;
  3796. builder->PackNodes.resize(pack_node_count);
  3797. IM_STATIC_ASSERT(sizeof(stbrp_context) <= sizeof(stbrp_context_opaque));
  3798. stbrp_init_target((stbrp_context*)(void*)&builder->PackContext, tex->Width, tex->Height, builder->PackNodes.Data, builder->PackNodes.Size);
  3799. builder->RectsPackedSurface = builder->RectsPackedCount = 0;
  3800. builder->MaxRectSize = ImVec2i(0, 0);
  3801. builder->MaxRectBounds = ImVec2i(0, 0);
  3802. }
  3803. // This is essentially a free-list pattern, it may be nice to wrap it into a dedicated type.
  3804. static ImFontAtlasRectId ImFontAtlasPackAllocRectEntry(ImFontAtlas* atlas, int rect_idx)
  3805. {
  3806. ImFontAtlasBuilder* builder = (ImFontAtlasBuilder*)atlas->Builder;
  3807. int index_idx;
  3808. ImFontAtlasRectEntry* index_entry;
  3809. if (builder->RectsIndexFreeListStart < 0)
  3810. {
  3811. builder->RectsIndex.resize(builder->RectsIndex.Size + 1);
  3812. index_idx = builder->RectsIndex.Size - 1;
  3813. index_entry = &builder->RectsIndex[index_idx];
  3814. memset(index_entry, 0, sizeof(*index_entry));
  3815. }
  3816. else
  3817. {
  3818. index_idx = builder->RectsIndexFreeListStart;
  3819. index_entry = &builder->RectsIndex[index_idx];
  3820. IM_ASSERT(index_entry->IsUsed == false && index_entry->Generation > 0); // Generation is incremented during DiscardRect
  3821. builder->RectsIndexFreeListStart = index_entry->TargetIndex;
  3822. }
  3823. index_entry->TargetIndex = rect_idx;
  3824. index_entry->IsUsed = 1;
  3825. return ImFontAtlasRectId_Make(index_idx, index_entry->Generation);
  3826. }
  3827. // Overwrite existing entry
  3828. static ImFontAtlasRectId ImFontAtlasPackReuseRectEntry(ImFontAtlas* atlas, ImFontAtlasRectEntry* index_entry)
  3829. {
  3830. IM_ASSERT(index_entry->IsUsed);
  3831. index_entry->TargetIndex = atlas->Builder->Rects.Size - 1;
  3832. int index_idx = atlas->Builder->RectsIndex.index_from_ptr(index_entry);
  3833. return ImFontAtlasRectId_Make(index_idx, index_entry->Generation);
  3834. }
  3835. // This is expected to be called in batches and followed by a repack
  3836. void ImFontAtlasPackDiscardRect(ImFontAtlas* atlas, ImFontAtlasRectId id)
  3837. {
  3838. IM_ASSERT(id != ImFontAtlasRectId_Invalid);
  3839. ImTextureRect* rect = ImFontAtlasPackGetRect(atlas, id);
  3840. if (rect == NULL)
  3841. return;
  3842. ImFontAtlasBuilder* builder = atlas->Builder;
  3843. int index_idx = ImFontAtlasRectId_GetIndex(id);
  3844. ImFontAtlasRectEntry* index_entry = &builder->RectsIndex[index_idx];
  3845. IM_ASSERT(index_entry->IsUsed && index_entry->TargetIndex >= 0);
  3846. index_entry->IsUsed = false;
  3847. index_entry->TargetIndex = builder->RectsIndexFreeListStart;
  3848. index_entry->Generation++;
  3849. const int pack_padding = atlas->TexGlyphPadding;
  3850. builder->RectsIndexFreeListStart = index_idx;
  3851. builder->RectsDiscardedCount++;
  3852. builder->RectsDiscardedSurface += (rect->w + pack_padding) * (rect->h + pack_padding);
  3853. rect->w = rect->h = 0; // Clear rectangle so it won't be packed again
  3854. }
  3855. // Important: Calling this may recreate a new texture and therefore change atlas->TexData
  3856. // FIXME-NEWFONTS: Expose other glyph padding settings for custom alteration (e.g. drop shadows). See #7962
  3857. ImFontAtlasRectId ImFontAtlasPackAddRect(ImFontAtlas* atlas, int w, int h, ImFontAtlasRectEntry* overwrite_entry)
  3858. {
  3859. IM_ASSERT(w > 0 && w <= 0xFFFF);
  3860. IM_ASSERT(h > 0 && h <= 0xFFFF);
  3861. ImFontAtlasBuilder* builder = (ImFontAtlasBuilder*)atlas->Builder;
  3862. const int pack_padding = atlas->TexGlyphPadding;
  3863. builder->MaxRectSize.x = ImMax(builder->MaxRectSize.x, w);
  3864. builder->MaxRectSize.y = ImMax(builder->MaxRectSize.y, h);
  3865. // Pack
  3866. ImTextureRect r = { 0, 0, (unsigned short)w, (unsigned short)h };
  3867. for (int attempts_remaining = 3; attempts_remaining >= 0; attempts_remaining--)
  3868. {
  3869. // Try packing
  3870. stbrp_rect pack_r = {};
  3871. pack_r.w = w + pack_padding;
  3872. pack_r.h = h + pack_padding;
  3873. stbrp_pack_rects((stbrp_context*)(void*)&builder->PackContext, &pack_r, 1);
  3874. r.x = (unsigned short)pack_r.x;
  3875. r.y = (unsigned short)pack_r.y;
  3876. if (pack_r.was_packed)
  3877. break;
  3878. // If we ran out of attempts, return fallback
  3879. if (attempts_remaining == 0 || builder->LockDisableResize)
  3880. {
  3881. IMGUI_DEBUG_LOG_FONT("[font] Failed packing %dx%d rectangle. Returning fallback.\n", w, h);
  3882. return ImFontAtlasRectId_Invalid;
  3883. }
  3884. // Resize or repack atlas! (this should be a rare event)
  3885. ImFontAtlasTextureMakeSpace(atlas);
  3886. }
  3887. builder->MaxRectBounds.x = ImMax(builder->MaxRectBounds.x, r.x + r.w + pack_padding);
  3888. builder->MaxRectBounds.y = ImMax(builder->MaxRectBounds.y, r.y + r.h + pack_padding);
  3889. builder->RectsPackedCount++;
  3890. builder->RectsPackedSurface += (w + pack_padding) * (h + pack_padding);
  3891. builder->Rects.push_back(r);
  3892. if (overwrite_entry != NULL)
  3893. return ImFontAtlasPackReuseRectEntry(atlas, overwrite_entry); // Write into an existing entry instead of adding one (used during repack)
  3894. else
  3895. return ImFontAtlasPackAllocRectEntry(atlas, builder->Rects.Size - 1);
  3896. }
  3897. // Generally for non-user facing functions: assert on invalid ID.
  3898. ImTextureRect* ImFontAtlasPackGetRect(ImFontAtlas* atlas, ImFontAtlasRectId id)
  3899. {
  3900. IM_ASSERT(id != ImFontAtlasRectId_Invalid);
  3901. int index_idx = ImFontAtlasRectId_GetIndex(id);
  3902. ImFontAtlasBuilder* builder = (ImFontAtlasBuilder*)atlas->Builder;
  3903. ImFontAtlasRectEntry* index_entry = &builder->RectsIndex[index_idx];
  3904. IM_ASSERT(index_entry->Generation == ImFontAtlasRectId_GetGeneration(id));
  3905. IM_ASSERT(index_entry->IsUsed);
  3906. return &builder->Rects[index_entry->TargetIndex];
  3907. }
  3908. // For user-facing functions: return NULL on invalid ID.
  3909. // Important: return pointer is valid until next call to AddRect(), e.g. FindGlyph(), CalcTextSize() can all potentially invalidate previous pointers.
  3910. ImTextureRect* ImFontAtlasPackGetRectSafe(ImFontAtlas* atlas, ImFontAtlasRectId id)
  3911. {
  3912. if (id == ImFontAtlasRectId_Invalid)
  3913. return NULL;
  3914. int index_idx = ImFontAtlasRectId_GetIndex(id);
  3915. if (atlas->Builder == NULL)
  3916. ImFontAtlasBuildInit(atlas);
  3917. ImFontAtlasBuilder* builder = (ImFontAtlasBuilder*)atlas->Builder;
  3918. if (index_idx >= builder->RectsIndex.Size)
  3919. return NULL;
  3920. ImFontAtlasRectEntry* index_entry = &builder->RectsIndex[index_idx];
  3921. if (index_entry->Generation != ImFontAtlasRectId_GetGeneration(id) || !index_entry->IsUsed)
  3922. return NULL;
  3923. return &builder->Rects[index_entry->TargetIndex];
  3924. }
  3925. // Important! This assume by ImFontConfig::GlyphExcludeRanges[] is a SMALL ARRAY (e.g. <10 entries)
  3926. // Use "Input Glyphs Overlap Detection Tool" to display a list of glyphs provided by multiple sources in order to set this array up.
  3927. static bool ImFontAtlasBuildAcceptCodepointForSource(ImFontConfig* src, ImWchar codepoint)
  3928. {
  3929. if (const ImWchar* exclude_list = src->GlyphExcludeRanges)
  3930. for (; exclude_list[0] != 0; exclude_list += 2)
  3931. if (codepoint >= exclude_list[0] && codepoint <= exclude_list[1])
  3932. return false;
  3933. return true;
  3934. }
  3935. static void ImFontBaked_BuildGrowIndex(ImFontBaked* baked, int new_size)
  3936. {
  3937. IM_ASSERT(baked->IndexAdvanceX.Size == baked->IndexLookup.Size);
  3938. if (new_size <= baked->IndexLookup.Size)
  3939. return;
  3940. baked->IndexAdvanceX.resize(new_size, -1.0f);
  3941. baked->IndexLookup.resize(new_size, IM_FONTGLYPH_INDEX_UNUSED);
  3942. }
  3943. static void ImFontAtlas_FontHookRemapCodepoint(ImFontAtlas* atlas, ImFont* font, ImWchar* c)
  3944. {
  3945. IM_UNUSED(atlas);
  3946. if (font->RemapPairs.Data.Size != 0)
  3947. *c = (ImWchar)font->RemapPairs.GetInt((ImGuiID)*c, (int)*c);
  3948. }
  3949. static ImFontGlyph* ImFontBaked_BuildLoadGlyph(ImFontBaked* baked, ImWchar codepoint, float* only_load_advance_x)
  3950. {
  3951. ImFont* font = baked->ContainerFont;
  3952. ImFontAtlas* atlas = font->ContainerAtlas;
  3953. if (atlas->Locked || (font->Flags & ImFontFlags_NoLoadGlyphs))
  3954. {
  3955. // Lazily load fallback glyph
  3956. if (baked->FallbackGlyphIndex == -1 && baked->LockLoadingFallback == 0)
  3957. ImFontAtlasBuildSetupFontBakedFallback(baked);
  3958. return NULL;
  3959. }
  3960. // User remapping hooks
  3961. ImWchar src_codepoint = codepoint;
  3962. ImFontAtlas_FontHookRemapCodepoint(atlas, font, &codepoint);
  3963. //char utf8_buf[5];
  3964. //IMGUI_DEBUG_LOG("[font] BuildLoadGlyph U+%04X (%s)\n", (unsigned int)codepoint, ImTextCharToUtf8(utf8_buf, (unsigned int)codepoint));
  3965. // Special hook
  3966. // FIXME-NEWATLAS: it would be nicer if this used a more standardized way of hooking
  3967. if (codepoint == font->EllipsisChar && font->EllipsisAutoBake)
  3968. if (ImFontGlyph* glyph = ImFontAtlasBuildSetupFontBakedEllipsis(atlas, baked))
  3969. return glyph;
  3970. // Call backend
  3971. char* loader_user_data_p = (char*)baked->FontLoaderDatas;
  3972. int src_n = 0;
  3973. for (ImFontConfig* src : font->Sources)
  3974. {
  3975. const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader;
  3976. if (!src->GlyphExcludeRanges || ImFontAtlasBuildAcceptCodepointForSource(src, codepoint))
  3977. {
  3978. if (only_load_advance_x == NULL)
  3979. {
  3980. ImFontGlyph glyph_buf;
  3981. if (loader->FontBakedLoadGlyph(atlas, src, baked, loader_user_data_p, codepoint, &glyph_buf, NULL))
  3982. {
  3983. // FIXME: Add hooks for e.g. #7962
  3984. glyph_buf.Codepoint = src_codepoint;
  3985. glyph_buf.SourceIdx = src_n;
  3986. return ImFontAtlasBakedAddFontGlyph(atlas, baked, src, &glyph_buf);
  3987. }
  3988. }
  3989. else
  3990. {
  3991. // Special mode but only loading glyphs metrics. Will rasterize and pack later.
  3992. if (loader->FontBakedLoadGlyph(atlas, src, baked, loader_user_data_p, codepoint, NULL, only_load_advance_x))
  3993. {
  3994. ImFontAtlasBakedAddFontGlyphAdvancedX(atlas, baked, src, codepoint, *only_load_advance_x);
  3995. return NULL;
  3996. }
  3997. }
  3998. }
  3999. loader_user_data_p += loader->FontBakedSrcLoaderDataSize;
  4000. src_n++;
  4001. }
  4002. // Lazily load fallback glyph
  4003. if (baked->LockLoadingFallback)
  4004. return NULL;
  4005. if (baked->FallbackGlyphIndex == -1)
  4006. ImFontAtlasBuildSetupFontBakedFallback(baked);
  4007. // Mark index as not found, so we don't attempt the search twice
  4008. ImFontBaked_BuildGrowIndex(baked, codepoint + 1);
  4009. baked->IndexAdvanceX[codepoint] = baked->FallbackAdvanceX;
  4010. baked->IndexLookup[codepoint] = IM_FONTGLYPH_INDEX_NOT_FOUND;
  4011. return NULL;
  4012. }
  4013. static float ImFontBaked_BuildLoadGlyphAdvanceX(ImFontBaked* baked, ImWchar codepoint)
  4014. {
  4015. if (baked->Size >= IMGUI_FONT_SIZE_THRESHOLD_FOR_LOADADVANCEXONLYMODE)
  4016. {
  4017. // First load AdvanceX value used by CalcTextSize() API then load the rest when loaded by drawing API.
  4018. float only_advance_x = 0.0f;
  4019. ImFontGlyph* glyph = ImFontBaked_BuildLoadGlyph(baked, (ImWchar)codepoint, &only_advance_x);
  4020. return glyph ? glyph->AdvanceX : only_advance_x;
  4021. }
  4022. else
  4023. {
  4024. ImFontGlyph* glyph = ImFontBaked_BuildLoadGlyph(baked, (ImWchar)codepoint, NULL);
  4025. return glyph ? glyph->AdvanceX : baked->FallbackAdvanceX;
  4026. }
  4027. }
  4028. // The point of this indirection is to not be inlined in debug mode in order to not bloat inner loop.b
  4029. IM_MSVC_RUNTIME_CHECKS_OFF
  4030. static float BuildLoadGlyphGetAdvanceOrFallback(ImFontBaked* baked, unsigned int codepoint)
  4031. {
  4032. return ImFontBaked_BuildLoadGlyphAdvanceX(baked, (ImWchar)codepoint);
  4033. }
  4034. IM_MSVC_RUNTIME_CHECKS_RESTORE
  4035. #ifndef IMGUI_DISABLE_DEBUG_TOOLS
  4036. void ImFontAtlasDebugLogTextureRequests(ImFontAtlas* atlas)
  4037. {
  4038. // [DEBUG] Log texture update requests
  4039. ImGuiContext& g = *GImGui;
  4040. IM_UNUSED(g);
  4041. for (ImTextureData* tex : atlas->TexList)
  4042. {
  4043. if ((g.IO.BackendFlags & ImGuiBackendFlags_RendererHasTextures) == 0)
  4044. IM_ASSERT(tex->Updates.Size == 0);
  4045. if (tex->Status == ImTextureStatus_WantCreate)
  4046. IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: create %dx%d\n", tex->UniqueID, tex->Width, tex->Height);
  4047. else if (tex->Status == ImTextureStatus_WantDestroy)
  4048. IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: destroy %dx%d, texid=0x%" IM_PRIX64 ", backend_data=%p\n", tex->UniqueID, tex->Width, tex->Height, tex->TexID, tex->BackendUserData);
  4049. else if (tex->Status == ImTextureStatus_WantUpdates)
  4050. {
  4051. IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: update %d regions, texid=0x%" IM_PRIX64 ", backend_data=0x%" IM_PRIX64 "\n", tex->UniqueID, tex->Updates.Size, tex->TexID, (ImU64)(intptr_t)tex->BackendUserData);
  4052. for (const ImTextureRect& r : tex->Updates)
  4053. {
  4054. IM_UNUSED(r);
  4055. IM_ASSERT(r.x >= 0 && r.y >= 0);
  4056. IM_ASSERT(r.x + r.w <= tex->Width && r.y + r.h <= tex->Height); // In theory should subtract PackPadding but it's currently part of atlas and mid-frame change would wreck assert.
  4057. //IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: update (% 4d..%-4d)->(% 4d..%-4d), texid=0x%" IM_PRIX64 ", backend_data=0x%" IM_PRIX64 "\n", tex->UniqueID, r.x, r.y, r.x + r.w, r.y + r.h, tex->TexID, (ImU64)(intptr_t)tex->BackendUserData);
  4058. }
  4059. }
  4060. }
  4061. }
  4062. #endif
  4063. //-------------------------------------------------------------------------
  4064. // [SECTION] ImFontAtlas: backend for stb_truetype
  4065. //-------------------------------------------------------------------------
  4066. // (imstb_truetype.h in included near the top of this file, when IMGUI_ENABLE_STB_TRUETYPE is set)
  4067. //-------------------------------------------------------------------------
  4068. #ifdef IMGUI_ENABLE_STB_TRUETYPE
  4069. // One for each ConfigData
  4070. struct ImGui_ImplStbTrueType_FontSrcData
  4071. {
  4072. stbtt_fontinfo FontInfo;
  4073. float ScaleFactor;
  4074. };
  4075. static bool ImGui_ImplStbTrueType_FontSrcInit(ImFontAtlas* atlas, ImFontConfig* src)
  4076. {
  4077. IM_UNUSED(atlas);
  4078. ImGui_ImplStbTrueType_FontSrcData* bd_font_data = IM_NEW(ImGui_ImplStbTrueType_FontSrcData);
  4079. IM_ASSERT(src->FontLoaderData == NULL);
  4080. // Initialize helper structure for font loading and verify that the TTF/OTF data is correct
  4081. const int font_offset = stbtt_GetFontOffsetForIndex((unsigned char*)src->FontData, src->FontNo);
  4082. if (font_offset < 0)
  4083. {
  4084. IM_DELETE(bd_font_data);
  4085. IM_ASSERT_USER_ERROR(0, "stbtt_GetFontOffsetForIndex(): FontData is incorrect, or FontNo cannot be found.");
  4086. return false;
  4087. }
  4088. if (!stbtt_InitFont(&bd_font_data->FontInfo, (unsigned char*)src->FontData, font_offset))
  4089. {
  4090. IM_DELETE(bd_font_data);
  4091. IM_ASSERT_USER_ERROR(0, "stbtt_InitFont(): failed to parse FontData. It is correct and complete? Check FontDataSize.");
  4092. return false;
  4093. }
  4094. src->FontLoaderData = bd_font_data;
  4095. if (src->MergeMode && src->SizePixels == 0.0f)
  4096. src->SizePixels = src->DstFont->Sources[0]->SizePixels;
  4097. if (src->SizePixels >= 0.0f)
  4098. bd_font_data->ScaleFactor = stbtt_ScaleForPixelHeight(&bd_font_data->FontInfo, 1.0f);
  4099. else
  4100. bd_font_data->ScaleFactor = stbtt_ScaleForMappingEmToPixels(&bd_font_data->FontInfo, 1.0f);
  4101. if (src->MergeMode && src->SizePixels != 0.0f)
  4102. bd_font_data->ScaleFactor *= src->SizePixels / src->DstFont->Sources[0]->SizePixels; // FIXME-NEWATLAS: Should tidy up that a bit
  4103. return true;
  4104. }
  4105. static void ImGui_ImplStbTrueType_FontSrcDestroy(ImFontAtlas* atlas, ImFontConfig* src)
  4106. {
  4107. IM_UNUSED(atlas);
  4108. ImGui_ImplStbTrueType_FontSrcData* bd_font_data = (ImGui_ImplStbTrueType_FontSrcData*)src->FontLoaderData;
  4109. IM_DELETE(bd_font_data);
  4110. src->FontLoaderData = NULL;
  4111. }
  4112. static bool ImGui_ImplStbTrueType_FontSrcContainsGlyph(ImFontAtlas* atlas, ImFontConfig* src, ImWchar codepoint)
  4113. {
  4114. IM_UNUSED(atlas);
  4115. ImGui_ImplStbTrueType_FontSrcData* bd_font_data = (ImGui_ImplStbTrueType_FontSrcData*)src->FontLoaderData;
  4116. IM_ASSERT(bd_font_data != NULL);
  4117. int glyph_index = stbtt_FindGlyphIndex(&bd_font_data->FontInfo, (int)codepoint);
  4118. return glyph_index != 0;
  4119. }
  4120. static bool ImGui_ImplStbTrueType_FontBakedInit(ImFontAtlas* atlas, ImFontConfig* src, ImFontBaked* baked, void*)
  4121. {
  4122. IM_UNUSED(atlas);
  4123. ImGui_ImplStbTrueType_FontSrcData* bd_font_data = (ImGui_ImplStbTrueType_FontSrcData*)src->FontLoaderData;
  4124. if (src->MergeMode == false)
  4125. {
  4126. // FIXME-NEWFONTS: reevaluate how to use sizing metrics
  4127. // FIXME-NEWFONTS: make use of line gap value
  4128. float scale_for_layout = bd_font_data->ScaleFactor * baked->Size;
  4129. int unscaled_ascent, unscaled_descent, unscaled_line_gap;
  4130. stbtt_GetFontVMetrics(&bd_font_data->FontInfo, &unscaled_ascent, &unscaled_descent, &unscaled_line_gap);
  4131. baked->Ascent = ImCeil(unscaled_ascent * scale_for_layout);
  4132. baked->Descent = ImFloor(unscaled_descent * scale_for_layout);
  4133. }
  4134. return true;
  4135. }
  4136. static bool ImGui_ImplStbTrueType_FontBakedLoadGlyph(ImFontAtlas* atlas, ImFontConfig* src, ImFontBaked* baked, void*, ImWchar codepoint, ImFontGlyph* out_glyph, float* out_advance_x)
  4137. {
  4138. // Search for first font which has the glyph
  4139. ImGui_ImplStbTrueType_FontSrcData* bd_font_data = (ImGui_ImplStbTrueType_FontSrcData*)src->FontLoaderData;
  4140. IM_ASSERT(bd_font_data);
  4141. int glyph_index = stbtt_FindGlyphIndex(&bd_font_data->FontInfo, (int)codepoint);
  4142. if (glyph_index == 0)
  4143. return false;
  4144. // Fonts unit to pixels
  4145. int oversample_h, oversample_v;
  4146. ImFontAtlasBuildGetOversampleFactors(src, baked, &oversample_h, &oversample_v);
  4147. const float scale_for_layout = bd_font_data->ScaleFactor * baked->Size;
  4148. const float rasterizer_density = src->RasterizerDensity * baked->RasterizerDensity;
  4149. const float scale_for_raster_x = bd_font_data->ScaleFactor * baked->Size * rasterizer_density * oversample_h;
  4150. const float scale_for_raster_y = bd_font_data->ScaleFactor * baked->Size * rasterizer_density * oversample_v;
  4151. // Obtain size and advance
  4152. int x0, y0, x1, y1;
  4153. int advance, lsb;
  4154. stbtt_GetGlyphBitmapBoxSubpixel(&bd_font_data->FontInfo, glyph_index, scale_for_raster_x, scale_for_raster_y, 0, 0, &x0, &y0, &x1, &y1);
  4155. stbtt_GetGlyphHMetrics(&bd_font_data->FontInfo, glyph_index, &advance, &lsb);
  4156. // Load metrics only mode
  4157. if (out_advance_x != NULL)
  4158. {
  4159. IM_ASSERT(out_glyph == NULL);
  4160. *out_advance_x = advance * scale_for_layout;
  4161. return true;
  4162. }
  4163. // Prepare glyph
  4164. out_glyph->Codepoint = codepoint;
  4165. out_glyph->AdvanceX = advance * scale_for_layout;
  4166. // Pack and retrieve position inside texture atlas
  4167. // (generally based on stbtt_PackFontRangesRenderIntoRects)
  4168. const bool is_visible = (x0 != x1 && y0 != y1);
  4169. if (is_visible)
  4170. {
  4171. const int w = (x1 - x0 + oversample_h - 1);
  4172. const int h = (y1 - y0 + oversample_v - 1);
  4173. ImFontAtlasRectId pack_id = ImFontAtlasPackAddRect(atlas, w, h);
  4174. if (pack_id == ImFontAtlasRectId_Invalid)
  4175. {
  4176. // Pathological out of memory case (TexMaxWidth/TexMaxHeight set too small?)
  4177. IM_ASSERT(pack_id != ImFontAtlasRectId_Invalid && "Out of texture memory.");
  4178. return false;
  4179. }
  4180. ImTextureRect* r = ImFontAtlasPackGetRect(atlas, pack_id);
  4181. // Render
  4182. stbtt_GetGlyphBitmapBox(&bd_font_data->FontInfo, glyph_index, scale_for_raster_x, scale_for_raster_y, &x0, &y0, &x1, &y1);
  4183. ImFontAtlasBuilder* builder = atlas->Builder;
  4184. builder->TempBuffer.resize(w * h * 1);
  4185. unsigned char* bitmap_pixels = builder->TempBuffer.Data;
  4186. memset(bitmap_pixels, 0, w * h * 1);
  4187. stbtt_MakeGlyphBitmapSubpixel(&bd_font_data->FontInfo, bitmap_pixels, r->w - oversample_h + 1, r->h - oversample_v + 1, w,
  4188. scale_for_raster_x, scale_for_raster_y, 0, 0, glyph_index);
  4189. // Oversampling
  4190. // (those functions conveniently assert if pixels are not cleared, which is another safety layer)
  4191. if (oversample_h > 1)
  4192. stbtt__h_prefilter(bitmap_pixels, r->w, r->h, r->w, oversample_h);
  4193. if (oversample_v > 1)
  4194. stbtt__v_prefilter(bitmap_pixels, r->w, r->h, r->w, oversample_v);
  4195. const float ref_size = baked->ContainerFont->Sources[0]->SizePixels;
  4196. const float offsets_scale = (ref_size != 0.0f) ? (baked->Size / ref_size) : 1.0f;
  4197. float font_off_x = (src->GlyphOffset.x * offsets_scale);
  4198. float font_off_y = (src->GlyphOffset.y * offsets_scale);
  4199. if (src->PixelSnapH) // Snap scaled offset. This is to mitigate backward compatibility issues for GlyphOffset, but a better design would be welcome.
  4200. font_off_x = IM_ROUND(font_off_x);
  4201. if (src->PixelSnapV)
  4202. font_off_y = IM_ROUND(font_off_y);
  4203. font_off_x += stbtt__oversample_shift(oversample_h);
  4204. font_off_y += stbtt__oversample_shift(oversample_v) + IM_ROUND(baked->Ascent);
  4205. float recip_h = 1.0f / (oversample_h * rasterizer_density);
  4206. float recip_v = 1.0f / (oversample_v * rasterizer_density);
  4207. // Register glyph
  4208. // r->x r->y are coordinates inside texture (in pixels)
  4209. // glyph.X0, glyph.Y0 are drawing coordinates from base text position, and accounting for oversampling.
  4210. out_glyph->X0 = x0 * recip_h + font_off_x;
  4211. out_glyph->Y0 = y0 * recip_v + font_off_y;
  4212. out_glyph->X1 = (x0 + (int)r->w) * recip_h + font_off_x;
  4213. out_glyph->Y1 = (y0 + (int)r->h) * recip_v + font_off_y;
  4214. out_glyph->Visible = true;
  4215. out_glyph->PackId = pack_id;
  4216. ImFontAtlasBakedSetFontGlyphBitmap(atlas, baked, src, out_glyph, r, bitmap_pixels, ImTextureFormat_Alpha8, w);
  4217. }
  4218. return true;
  4219. }
  4220. const ImFontLoader* ImFontAtlasGetFontLoaderForStbTruetype()
  4221. {
  4222. static ImFontLoader loader;
  4223. loader.Name = "stb_truetype";
  4224. loader.FontSrcInit = ImGui_ImplStbTrueType_FontSrcInit;
  4225. loader.FontSrcDestroy = ImGui_ImplStbTrueType_FontSrcDestroy;
  4226. loader.FontSrcContainsGlyph = ImGui_ImplStbTrueType_FontSrcContainsGlyph;
  4227. loader.FontBakedInit = ImGui_ImplStbTrueType_FontBakedInit;
  4228. loader.FontBakedDestroy = NULL;
  4229. loader.FontBakedLoadGlyph = ImGui_ImplStbTrueType_FontBakedLoadGlyph;
  4230. return &loader;
  4231. }
  4232. #endif // IMGUI_ENABLE_STB_TRUETYPE
  4233. //-------------------------------------------------------------------------
  4234. // [SECTION] ImFontAtlas: glyph ranges helpers
  4235. //-------------------------------------------------------------------------
  4236. // - GetGlyphRangesDefault()
  4237. // Obsolete functions since 1.92:
  4238. // - GetGlyphRangesGreek()
  4239. // - GetGlyphRangesKorean()
  4240. // - GetGlyphRangesChineseFull()
  4241. // - GetGlyphRangesChineseSimplifiedCommon()
  4242. // - GetGlyphRangesJapanese()
  4243. // - GetGlyphRangesCyrillic()
  4244. // - GetGlyphRangesThai()
  4245. // - GetGlyphRangesVietnamese()
  4246. //-----------------------------------------------------------------------------
  4247. // Retrieve list of range (2 int per range, values are inclusive)
  4248. const ImWchar* ImFontAtlas::GetGlyphRangesDefault()
  4249. {
  4250. static const ImWchar ranges[] =
  4251. {
  4252. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  4253. 0,
  4254. };
  4255. return &ranges[0];
  4256. }
  4257. #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
  4258. const ImWchar* ImFontAtlas::GetGlyphRangesGreek()
  4259. {
  4260. static const ImWchar ranges[] =
  4261. {
  4262. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  4263. 0x0370, 0x03FF, // Greek and Coptic
  4264. 0,
  4265. };
  4266. return &ranges[0];
  4267. }
  4268. const ImWchar* ImFontAtlas::GetGlyphRangesKorean()
  4269. {
  4270. static const ImWchar ranges[] =
  4271. {
  4272. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  4273. 0x3131, 0x3163, // Korean alphabets
  4274. 0xAC00, 0xD7A3, // Korean characters
  4275. 0xFFFD, 0xFFFD, // Invalid
  4276. 0,
  4277. };
  4278. return &ranges[0];
  4279. }
  4280. const ImWchar* ImFontAtlas::GetGlyphRangesChineseFull()
  4281. {
  4282. static const ImWchar ranges[] =
  4283. {
  4284. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  4285. 0x2000, 0x206F, // General Punctuation
  4286. 0x3000, 0x30FF, // CJK Symbols and Punctuations, Hiragana, Katakana
  4287. 0x31F0, 0x31FF, // Katakana Phonetic Extensions
  4288. 0xFF00, 0xFFEF, // Half-width characters
  4289. 0xFFFD, 0xFFFD, // Invalid
  4290. 0x4e00, 0x9FAF, // CJK Ideograms
  4291. 0,
  4292. };
  4293. return &ranges[0];
  4294. }
  4295. static void UnpackAccumulativeOffsetsIntoRanges(int base_codepoint, const short* accumulative_offsets, int accumulative_offsets_count, ImWchar* out_ranges)
  4296. {
  4297. for (int n = 0; n < accumulative_offsets_count; n++, out_ranges += 2)
  4298. {
  4299. out_ranges[0] = out_ranges[1] = (ImWchar)(base_codepoint + accumulative_offsets[n]);
  4300. base_codepoint += accumulative_offsets[n];
  4301. }
  4302. out_ranges[0] = 0;
  4303. }
  4304. const ImWchar* ImFontAtlas::GetGlyphRangesChineseSimplifiedCommon()
  4305. {
  4306. // Store 2500 regularly used characters for Simplified Chinese.
  4307. // Sourced from https://zh.wiktionary.org/wiki/%E9%99%84%E5%BD%95:%E7%8E%B0%E4%BB%A3%E6%B1%89%E8%AF%AD%E5%B8%B8%E7%94%A8%E5%AD%97%E8%A1%A8
  4308. // This table covers 97.97% of all characters used during the month in July, 1987.
  4309. // You can use ImFontGlyphRangesBuilder to create your own ranges derived from this, by merging existing ranges or adding new characters.
  4310. // (Stored as accumulative offsets from the initial unicode codepoint 0x4E00. This encoding is designed to helps us compact the source code size.)
  4311. static const short accumulative_offsets_from_0x4E00[] =
  4312. {
  4313. 0,1,2,4,1,1,1,1,2,1,3,2,1,2,2,1,1,1,1,1,5,2,1,2,3,3,3,2,2,4,1,1,1,2,1,5,2,3,1,2,1,2,1,1,2,1,1,2,2,1,4,1,1,1,1,5,10,1,2,19,2,1,2,1,2,1,2,1,2,
  4314. 1,5,1,6,3,2,1,2,2,1,1,1,4,8,5,1,1,4,1,1,3,1,2,1,5,1,2,1,1,1,10,1,1,5,2,4,6,1,4,2,2,2,12,2,1,1,6,1,1,1,4,1,1,4,6,5,1,4,2,2,4,10,7,1,1,4,2,4,
  4315. 2,1,4,3,6,10,12,5,7,2,14,2,9,1,1,6,7,10,4,7,13,1,5,4,8,4,1,1,2,28,5,6,1,1,5,2,5,20,2,2,9,8,11,2,9,17,1,8,6,8,27,4,6,9,20,11,27,6,68,2,2,1,1,
  4316. 1,2,1,2,2,7,6,11,3,3,1,1,3,1,2,1,1,1,1,1,3,1,1,8,3,4,1,5,7,2,1,4,4,8,4,2,1,2,1,1,4,5,6,3,6,2,12,3,1,3,9,2,4,3,4,1,5,3,3,1,3,7,1,5,1,1,1,1,2,
  4317. 3,4,5,2,3,2,6,1,1,2,1,7,1,7,3,4,5,15,2,2,1,5,3,22,19,2,1,1,1,1,2,5,1,1,1,6,1,1,12,8,2,9,18,22,4,1,1,5,1,16,1,2,7,10,15,1,1,6,2,4,1,2,4,1,6,
  4318. 1,1,3,2,4,1,6,4,5,1,2,1,1,2,1,10,3,1,3,2,1,9,3,2,5,7,2,19,4,3,6,1,1,1,1,1,4,3,2,1,1,1,2,5,3,1,1,1,2,2,1,1,2,1,1,2,1,3,1,1,1,3,7,1,4,1,1,2,1,
  4319. 1,2,1,2,4,4,3,8,1,1,1,2,1,3,5,1,3,1,3,4,6,2,2,14,4,6,6,11,9,1,15,3,1,28,5,2,5,5,3,1,3,4,5,4,6,14,3,2,3,5,21,2,7,20,10,1,2,19,2,4,28,28,2,3,
  4320. 2,1,14,4,1,26,28,42,12,40,3,52,79,5,14,17,3,2,2,11,3,4,6,3,1,8,2,23,4,5,8,10,4,2,7,3,5,1,1,6,3,1,2,2,2,5,28,1,1,7,7,20,5,3,29,3,17,26,1,8,4,
  4321. 27,3,6,11,23,5,3,4,6,13,24,16,6,5,10,25,35,7,3,2,3,3,14,3,6,2,6,1,4,2,3,8,2,1,1,3,3,3,4,1,1,13,2,2,4,5,2,1,14,14,1,2,2,1,4,5,2,3,1,14,3,12,
  4322. 3,17,2,16,5,1,2,1,8,9,3,19,4,2,2,4,17,25,21,20,28,75,1,10,29,103,4,1,2,1,1,4,2,4,1,2,3,24,2,2,2,1,1,2,1,3,8,1,1,1,2,1,1,3,1,1,1,6,1,5,3,1,1,
  4323. 1,3,4,1,1,5,2,1,5,6,13,9,16,1,1,1,1,3,2,3,2,4,5,2,5,2,2,3,7,13,7,2,2,1,1,1,1,2,3,3,2,1,6,4,9,2,1,14,2,14,2,1,18,3,4,14,4,11,41,15,23,15,23,
  4324. 176,1,3,4,1,1,1,1,5,3,1,2,3,7,3,1,1,2,1,2,4,4,6,2,4,1,9,7,1,10,5,8,16,29,1,1,2,2,3,1,3,5,2,4,5,4,1,1,2,2,3,3,7,1,6,10,1,17,1,44,4,6,2,1,1,6,
  4325. 5,4,2,10,1,6,9,2,8,1,24,1,2,13,7,8,8,2,1,4,1,3,1,3,3,5,2,5,10,9,4,9,12,2,1,6,1,10,1,1,7,7,4,10,8,3,1,13,4,3,1,6,1,3,5,2,1,2,17,16,5,2,16,6,
  4326. 1,4,2,1,3,3,6,8,5,11,11,1,3,3,2,4,6,10,9,5,7,4,7,4,7,1,1,4,2,1,3,6,8,7,1,6,11,5,5,3,24,9,4,2,7,13,5,1,8,82,16,61,1,1,1,4,2,2,16,10,3,8,1,1,
  4327. 6,4,2,1,3,1,1,1,4,3,8,4,2,2,1,1,1,1,1,6,3,5,1,1,4,6,9,2,1,1,1,2,1,7,2,1,6,1,5,4,4,3,1,8,1,3,3,1,3,2,2,2,2,3,1,6,1,2,1,2,1,3,7,1,8,2,1,2,1,5,
  4328. 2,5,3,5,10,1,2,1,1,3,2,5,11,3,9,3,5,1,1,5,9,1,2,1,5,7,9,9,8,1,3,3,3,6,8,2,3,2,1,1,32,6,1,2,15,9,3,7,13,1,3,10,13,2,14,1,13,10,2,1,3,10,4,15,
  4329. 2,15,15,10,1,3,9,6,9,32,25,26,47,7,3,2,3,1,6,3,4,3,2,8,5,4,1,9,4,2,2,19,10,6,2,3,8,1,2,2,4,2,1,9,4,4,4,6,4,8,9,2,3,1,1,1,1,3,5,5,1,3,8,4,6,
  4330. 2,1,4,12,1,5,3,7,13,2,5,8,1,6,1,2,5,14,6,1,5,2,4,8,15,5,1,23,6,62,2,10,1,1,8,1,2,2,10,4,2,2,9,2,1,1,3,2,3,1,5,3,3,2,1,3,8,1,1,1,11,3,1,1,4,
  4331. 3,7,1,14,1,2,3,12,5,2,5,1,6,7,5,7,14,11,1,3,1,8,9,12,2,1,11,8,4,4,2,6,10,9,13,1,1,3,1,5,1,3,2,4,4,1,18,2,3,14,11,4,29,4,2,7,1,3,13,9,2,2,5,
  4332. 3,5,20,7,16,8,5,72,34,6,4,22,12,12,28,45,36,9,7,39,9,191,1,1,1,4,11,8,4,9,2,3,22,1,1,1,1,4,17,1,7,7,1,11,31,10,2,4,8,2,3,2,1,4,2,16,4,32,2,
  4333. 3,19,13,4,9,1,5,2,14,8,1,1,3,6,19,6,5,1,16,6,2,10,8,5,1,2,3,1,5,5,1,11,6,6,1,3,3,2,6,3,8,1,1,4,10,7,5,7,7,5,8,9,2,1,3,4,1,1,3,1,3,3,2,6,16,
  4334. 1,4,6,3,1,10,6,1,3,15,2,9,2,10,25,13,9,16,6,2,2,10,11,4,3,9,1,2,6,6,5,4,30,40,1,10,7,12,14,33,6,3,6,7,3,1,3,1,11,14,4,9,5,12,11,49,18,51,31,
  4335. 140,31,2,2,1,5,1,8,1,10,1,4,4,3,24,1,10,1,3,6,6,16,3,4,5,2,1,4,2,57,10,6,22,2,22,3,7,22,6,10,11,36,18,16,33,36,2,5,5,1,1,1,4,10,1,4,13,2,7,
  4336. 5,2,9,3,4,1,7,43,3,7,3,9,14,7,9,1,11,1,1,3,7,4,18,13,1,14,1,3,6,10,73,2,2,30,6,1,11,18,19,13,22,3,46,42,37,89,7,3,16,34,2,2,3,9,1,7,1,1,1,2,
  4337. 2,4,10,7,3,10,3,9,5,28,9,2,6,13,7,3,1,3,10,2,7,2,11,3,6,21,54,85,2,1,4,2,2,1,39,3,21,2,2,5,1,1,1,4,1,1,3,4,15,1,3,2,4,4,2,3,8,2,20,1,8,7,13,
  4338. 4,1,26,6,2,9,34,4,21,52,10,4,4,1,5,12,2,11,1,7,2,30,12,44,2,30,1,1,3,6,16,9,17,39,82,2,2,24,7,1,7,3,16,9,14,44,2,1,2,1,2,3,5,2,4,1,6,7,5,3,
  4339. 2,6,1,11,5,11,2,1,18,19,8,1,3,24,29,2,1,3,5,2,2,1,13,6,5,1,46,11,3,5,1,1,5,8,2,10,6,12,6,3,7,11,2,4,16,13,2,5,1,1,2,2,5,2,28,5,2,23,10,8,4,
  4340. 4,22,39,95,38,8,14,9,5,1,13,5,4,3,13,12,11,1,9,1,27,37,2,5,4,4,63,211,95,2,2,2,1,3,5,2,1,1,2,2,1,1,1,3,2,4,1,2,1,1,5,2,2,1,1,2,3,1,3,1,1,1,
  4341. 3,1,4,2,1,3,6,1,1,3,7,15,5,3,2,5,3,9,11,4,2,22,1,6,3,8,7,1,4,28,4,16,3,3,25,4,4,27,27,1,4,1,2,2,7,1,3,5,2,28,8,2,14,1,8,6,16,25,3,3,3,14,3,
  4342. 3,1,1,2,1,4,6,3,8,4,1,1,1,2,3,6,10,6,2,3,18,3,2,5,5,4,3,1,5,2,5,4,23,7,6,12,6,4,17,11,9,5,1,1,10,5,12,1,1,11,26,33,7,3,6,1,17,7,1,5,12,1,11,
  4343. 2,4,1,8,14,17,23,1,2,1,7,8,16,11,9,6,5,2,6,4,16,2,8,14,1,11,8,9,1,1,1,9,25,4,11,19,7,2,15,2,12,8,52,7,5,19,2,16,4,36,8,1,16,8,24,26,4,6,2,9,
  4344. 5,4,36,3,28,12,25,15,37,27,17,12,59,38,5,32,127,1,2,9,17,14,4,1,2,1,1,8,11,50,4,14,2,19,16,4,17,5,4,5,26,12,45,2,23,45,104,30,12,8,3,10,2,2,
  4345. 3,3,1,4,20,7,2,9,6,15,2,20,1,3,16,4,11,15,6,134,2,5,59,1,2,2,2,1,9,17,3,26,137,10,211,59,1,2,4,1,4,1,1,1,2,6,2,3,1,1,2,3,2,3,1,3,4,4,2,3,3,
  4346. 1,4,3,1,7,2,2,3,1,2,1,3,3,3,2,2,3,2,1,3,14,6,1,3,2,9,6,15,27,9,34,145,1,1,2,1,1,1,1,2,1,1,1,1,2,2,2,3,1,2,1,1,1,2,3,5,8,3,5,2,4,1,3,2,2,2,12,
  4347. 4,1,1,1,10,4,5,1,20,4,16,1,15,9,5,12,2,9,2,5,4,2,26,19,7,1,26,4,30,12,15,42,1,6,8,172,1,1,4,2,1,1,11,2,2,4,2,1,2,1,10,8,1,2,1,4,5,1,2,5,1,8,
  4348. 4,1,3,4,2,1,6,2,1,3,4,1,2,1,1,1,1,12,5,7,2,4,3,1,1,1,3,3,6,1,2,2,3,3,3,2,1,2,12,14,11,6,6,4,12,2,8,1,7,10,1,35,7,4,13,15,4,3,23,21,28,52,5,
  4349. 26,5,6,1,7,10,2,7,53,3,2,1,1,1,2,163,532,1,10,11,1,3,3,4,8,2,8,6,2,2,23,22,4,2,2,4,2,1,3,1,3,3,5,9,8,2,1,2,8,1,10,2,12,21,20,15,105,2,3,1,1,
  4350. 3,2,3,1,1,2,5,1,4,15,11,19,1,1,1,1,5,4,5,1,1,2,5,3,5,12,1,2,5,1,11,1,1,15,9,1,4,5,3,26,8,2,1,3,1,1,15,19,2,12,1,2,5,2,7,2,19,2,20,6,26,7,5,
  4351. 2,2,7,34,21,13,70,2,128,1,1,2,1,1,2,1,1,3,2,2,2,15,1,4,1,3,4,42,10,6,1,49,85,8,1,2,1,1,4,4,2,3,6,1,5,7,4,3,211,4,1,2,1,2,5,1,2,4,2,2,6,5,6,
  4352. 10,3,4,48,100,6,2,16,296,5,27,387,2,2,3,7,16,8,5,38,15,39,21,9,10,3,7,59,13,27,21,47,5,21,6
  4353. };
  4354. static ImWchar base_ranges[] = // not zero-terminated
  4355. {
  4356. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  4357. 0x2000, 0x206F, // General Punctuation
  4358. 0x3000, 0x30FF, // CJK Symbols and Punctuations, Hiragana, Katakana
  4359. 0x31F0, 0x31FF, // Katakana Phonetic Extensions
  4360. 0xFF00, 0xFFEF, // Half-width characters
  4361. 0xFFFD, 0xFFFD // Invalid
  4362. };
  4363. static ImWchar full_ranges[IM_ARRAYSIZE(base_ranges) + IM_ARRAYSIZE(accumulative_offsets_from_0x4E00) * 2 + 1] = { 0 };
  4364. if (!full_ranges[0])
  4365. {
  4366. memcpy(full_ranges, base_ranges, sizeof(base_ranges));
  4367. UnpackAccumulativeOffsetsIntoRanges(0x4E00, accumulative_offsets_from_0x4E00, IM_ARRAYSIZE(accumulative_offsets_from_0x4E00), full_ranges + IM_ARRAYSIZE(base_ranges));
  4368. }
  4369. return &full_ranges[0];
  4370. }
  4371. const ImWchar* ImFontAtlas::GetGlyphRangesJapanese()
  4372. {
  4373. // 2999 ideograms code points for Japanese
  4374. // - 2136 Joyo (meaning "for regular use" or "for common use") Kanji code points
  4375. // - 863 Jinmeiyo (meaning "for personal name") Kanji code points
  4376. // - Sourced from official information provided by the government agencies of Japan:
  4377. // - List of Joyo Kanji by the Agency for Cultural Affairs
  4378. // - https://www.bunka.go.jp/kokugo_nihongo/sisaku/joho/joho/kijun/naikaku/kanji/
  4379. // - List of Jinmeiyo Kanji by the Ministry of Justice
  4380. // - http://www.moj.go.jp/MINJI/minji86.html
  4381. // - Available under the terms of the Creative Commons Attribution 4.0 International (CC BY 4.0).
  4382. // - https://creativecommons.org/licenses/by/4.0/legalcode
  4383. // - You can generate this code by the script at:
  4384. // - https://github.com/vaiorabbit/everyday_use_kanji
  4385. // - References:
  4386. // - List of Joyo Kanji
  4387. // - (Wikipedia) https://en.wikipedia.org/wiki/List_of_j%C5%8Dy%C5%8D_kanji
  4388. // - List of Jinmeiyo Kanji
  4389. // - (Wikipedia) https://en.wikipedia.org/wiki/Jinmeiy%C5%8D_kanji
  4390. // - Missing 1 Joyo Kanji: U+20B9F (Kun'yomi: Shikaru, On'yomi: Shitsu,shichi), see https://github.com/ocornut/imgui/pull/3627 for details.
  4391. // You can use ImFontGlyphRangesBuilder to create your own ranges derived from this, by merging existing ranges or adding new characters.
  4392. // (Stored as accumulative offsets from the initial unicode codepoint 0x4E00. This encoding is designed to helps us compact the source code size.)
  4393. static const short accumulative_offsets_from_0x4E00[] =
  4394. {
  4395. 0,1,2,4,1,1,1,1,2,1,3,3,2,2,1,5,3,5,7,5,6,1,2,1,7,2,6,3,1,8,1,1,4,1,1,18,2,11,2,6,2,1,2,1,5,1,2,1,3,1,2,1,2,3,3,1,1,2,3,1,1,1,12,7,9,1,4,5,1,
  4396. 1,2,1,10,1,1,9,2,2,4,5,6,9,3,1,1,1,1,9,3,18,5,2,2,2,2,1,6,3,7,1,1,1,1,2,2,4,2,1,23,2,10,4,3,5,2,4,10,2,4,13,1,6,1,9,3,1,1,6,6,7,6,3,1,2,11,3,
  4397. 2,2,3,2,15,2,2,5,4,3,6,4,1,2,5,2,12,16,6,13,9,13,2,1,1,7,16,4,7,1,19,1,5,1,2,2,7,7,8,2,6,5,4,9,18,7,4,5,9,13,11,8,15,2,1,1,1,2,1,2,2,1,2,2,8,
  4398. 2,9,3,3,1,1,4,4,1,1,1,4,9,1,4,3,5,5,2,7,5,3,4,8,2,1,13,2,3,3,1,14,1,1,4,5,1,3,6,1,5,2,1,1,3,3,3,3,1,1,2,7,6,6,7,1,4,7,6,1,1,1,1,1,12,3,3,9,5,
  4399. 2,6,1,5,6,1,2,3,18,2,4,14,4,1,3,6,1,1,6,3,5,5,3,2,2,2,2,12,3,1,4,2,3,2,3,11,1,7,4,1,2,1,3,17,1,9,1,24,1,1,4,2,2,4,1,2,7,1,1,1,3,1,2,2,4,15,1,
  4400. 1,2,1,1,2,1,5,2,5,20,2,5,9,1,10,8,7,6,1,1,1,1,1,1,6,2,1,2,8,1,1,1,1,5,1,1,3,1,1,1,1,3,1,1,12,4,1,3,1,1,1,1,1,10,3,1,7,5,13,1,2,3,4,6,1,1,30,
  4401. 2,9,9,1,15,38,11,3,1,8,24,7,1,9,8,10,2,1,9,31,2,13,6,2,9,4,49,5,2,15,2,1,10,2,1,1,1,2,2,6,15,30,35,3,14,18,8,1,16,10,28,12,19,45,38,1,3,2,3,
  4402. 13,2,1,7,3,6,5,3,4,3,1,5,7,8,1,5,3,18,5,3,6,1,21,4,24,9,24,40,3,14,3,21,3,2,1,2,4,2,3,1,15,15,6,5,1,1,3,1,5,6,1,9,7,3,3,2,1,4,3,8,21,5,16,4,
  4403. 5,2,10,11,11,3,6,3,2,9,3,6,13,1,2,1,1,1,1,11,12,6,6,1,4,2,6,5,2,1,1,3,3,6,13,3,1,1,5,1,2,3,3,14,2,1,2,2,2,5,1,9,5,1,1,6,12,3,12,3,4,13,2,14,
  4404. 2,8,1,17,5,1,16,4,2,2,21,8,9,6,23,20,12,25,19,9,38,8,3,21,40,25,33,13,4,3,1,4,1,2,4,1,2,5,26,2,1,1,2,1,3,6,2,1,1,1,1,1,1,2,3,1,1,1,9,2,3,1,1,
  4405. 1,3,6,3,2,1,1,6,6,1,8,2,2,2,1,4,1,2,3,2,7,3,2,4,1,2,1,2,2,1,1,1,1,1,3,1,2,5,4,10,9,4,9,1,1,1,1,1,1,5,3,2,1,6,4,9,6,1,10,2,31,17,8,3,7,5,40,1,
  4406. 7,7,1,6,5,2,10,7,8,4,15,39,25,6,28,47,18,10,7,1,3,1,1,2,1,1,1,3,3,3,1,1,1,3,4,2,1,4,1,3,6,10,7,8,6,2,2,1,3,3,2,5,8,7,9,12,2,15,1,1,4,1,2,1,1,
  4407. 1,3,2,1,3,3,5,6,2,3,2,10,1,4,2,8,1,1,1,11,6,1,21,4,16,3,1,3,1,4,2,3,6,5,1,3,1,1,3,3,4,6,1,1,10,4,2,7,10,4,7,4,2,9,4,3,1,1,1,4,1,8,3,4,1,3,1,
  4408. 6,1,4,2,1,4,7,2,1,8,1,4,5,1,1,2,2,4,6,2,7,1,10,1,1,3,4,11,10,8,21,4,6,1,3,5,2,1,2,28,5,5,2,3,13,1,2,3,1,4,2,1,5,20,3,8,11,1,3,3,3,1,8,10,9,2,
  4409. 10,9,2,3,1,1,2,4,1,8,3,6,1,7,8,6,11,1,4,29,8,4,3,1,2,7,13,1,4,1,6,2,6,12,12,2,20,3,2,3,6,4,8,9,2,7,34,5,1,18,6,1,1,4,4,5,7,9,1,2,2,4,3,4,1,7,
  4410. 2,2,2,6,2,3,25,5,3,6,1,4,6,7,4,2,1,4,2,13,6,4,4,3,1,5,3,4,4,3,2,1,1,4,1,2,1,1,3,1,11,1,6,3,1,7,3,6,2,8,8,6,9,3,4,11,3,2,10,12,2,5,11,1,6,4,5,
  4411. 3,1,8,5,4,6,6,3,5,1,1,3,2,1,2,2,6,17,12,1,10,1,6,12,1,6,6,19,9,6,16,1,13,4,4,15,7,17,6,11,9,15,12,6,7,2,1,2,2,15,9,3,21,4,6,49,18,7,3,2,3,1,
  4412. 6,8,2,2,6,2,9,1,3,6,4,4,1,2,16,2,5,2,1,6,2,3,5,3,1,2,5,1,2,1,9,3,1,8,6,4,8,11,3,1,1,1,1,3,1,13,8,4,1,3,2,2,1,4,1,11,1,5,2,1,5,2,5,8,6,1,1,7,
  4413. 4,3,8,3,2,7,2,1,5,1,5,2,4,7,6,2,8,5,1,11,4,5,3,6,18,1,2,13,3,3,1,21,1,1,4,1,4,1,1,1,8,1,2,2,7,1,2,4,2,2,9,2,1,1,1,4,3,6,3,12,5,1,1,1,5,6,3,2,
  4414. 4,8,2,2,4,2,7,1,8,9,5,2,3,2,1,3,2,13,7,14,6,5,1,1,2,1,4,2,23,2,1,1,6,3,1,4,1,15,3,1,7,3,9,14,1,3,1,4,1,1,5,8,1,3,8,3,8,15,11,4,14,4,4,2,5,5,
  4415. 1,7,1,6,14,7,7,8,5,15,4,8,6,5,6,2,1,13,1,20,15,11,9,2,5,6,2,11,2,6,2,5,1,5,8,4,13,19,25,4,1,1,11,1,34,2,5,9,14,6,2,2,6,1,1,14,1,3,14,13,1,6,
  4416. 12,21,14,14,6,32,17,8,32,9,28,1,2,4,11,8,3,1,14,2,5,15,1,1,1,1,3,6,4,1,3,4,11,3,1,1,11,30,1,5,1,4,1,5,8,1,1,3,2,4,3,17,35,2,6,12,17,3,1,6,2,
  4417. 1,1,12,2,7,3,3,2,1,16,2,8,3,6,5,4,7,3,3,8,1,9,8,5,1,2,1,3,2,8,1,2,9,12,1,1,2,3,8,3,24,12,4,3,7,5,8,3,3,3,3,3,3,1,23,10,3,1,2,2,6,3,1,16,1,16,
  4418. 22,3,10,4,11,6,9,7,7,3,6,2,2,2,4,10,2,1,1,2,8,7,1,6,4,1,3,3,3,5,10,12,12,2,3,12,8,15,1,1,16,6,6,1,5,9,11,4,11,4,2,6,12,1,17,5,13,1,4,9,5,1,11,
  4419. 2,1,8,1,5,7,28,8,3,5,10,2,17,3,38,22,1,2,18,12,10,4,38,18,1,4,44,19,4,1,8,4,1,12,1,4,31,12,1,14,7,75,7,5,10,6,6,13,3,2,11,11,3,2,5,28,15,6,18,
  4420. 18,5,6,4,3,16,1,7,18,7,36,3,5,3,1,7,1,9,1,10,7,2,4,2,6,2,9,7,4,3,32,12,3,7,10,2,23,16,3,1,12,3,31,4,11,1,3,8,9,5,1,30,15,6,12,3,2,2,11,19,9,
  4421. 14,2,6,2,3,19,13,17,5,3,3,25,3,14,1,1,1,36,1,3,2,19,3,13,36,9,13,31,6,4,16,34,2,5,4,2,3,3,5,1,1,1,4,3,1,17,3,2,3,5,3,1,3,2,3,5,6,3,12,11,1,3,
  4422. 1,2,26,7,12,7,2,14,3,3,7,7,11,25,25,28,16,4,36,1,2,1,6,2,1,9,3,27,17,4,3,4,13,4,1,3,2,2,1,10,4,2,4,6,3,8,2,1,18,1,1,24,2,2,4,33,2,3,63,7,1,6,
  4423. 40,7,3,4,4,2,4,15,18,1,16,1,1,11,2,41,14,1,3,18,13,3,2,4,16,2,17,7,15,24,7,18,13,44,2,2,3,6,1,1,7,5,1,7,1,4,3,3,5,10,8,2,3,1,8,1,1,27,4,2,1,
  4424. 12,1,2,1,10,6,1,6,7,5,2,3,7,11,5,11,3,6,6,2,3,15,4,9,1,1,2,1,2,11,2,8,12,8,5,4,2,3,1,5,2,2,1,14,1,12,11,4,1,11,17,17,4,3,2,5,5,7,3,1,5,9,9,8,
  4425. 2,5,6,6,13,13,2,1,2,6,1,2,2,49,4,9,1,2,10,16,7,8,4,3,2,23,4,58,3,29,1,14,19,19,11,11,2,7,5,1,3,4,6,2,18,5,12,12,17,17,3,3,2,4,1,6,2,3,4,3,1,
  4426. 1,1,1,5,1,1,9,1,3,1,3,6,1,8,1,1,2,6,4,14,3,1,4,11,4,1,3,32,1,2,4,13,4,1,2,4,2,1,3,1,11,1,4,2,1,4,4,6,3,5,1,6,5,7,6,3,23,3,5,3,5,3,3,13,3,9,10,
  4427. 1,12,10,2,3,18,13,7,160,52,4,2,2,3,2,14,5,4,12,4,6,4,1,20,4,11,6,2,12,27,1,4,1,2,2,7,4,5,2,28,3,7,25,8,3,19,3,6,10,2,2,1,10,2,5,4,1,3,4,1,5,
  4428. 3,2,6,9,3,6,2,16,3,3,16,4,5,5,3,2,1,2,16,15,8,2,6,21,2,4,1,22,5,8,1,1,21,11,2,1,11,11,19,13,12,4,2,3,2,3,6,1,8,11,1,4,2,9,5,2,1,11,2,9,1,1,2,
  4429. 14,31,9,3,4,21,14,4,8,1,7,2,2,2,5,1,4,20,3,3,4,10,1,11,9,8,2,1,4,5,14,12,14,2,17,9,6,31,4,14,1,20,13,26,5,2,7,3,6,13,2,4,2,19,6,2,2,18,9,3,5,
  4430. 12,12,14,4,6,2,3,6,9,5,22,4,5,25,6,4,8,5,2,6,27,2,35,2,16,3,7,8,8,6,6,5,9,17,2,20,6,19,2,13,3,1,1,1,4,17,12,2,14,7,1,4,18,12,38,33,2,10,1,1,
  4431. 2,13,14,17,11,50,6,33,20,26,74,16,23,45,50,13,38,33,6,6,7,4,4,2,1,3,2,5,8,7,8,9,3,11,21,9,13,1,3,10,6,7,1,2,2,18,5,5,1,9,9,2,68,9,19,13,2,5,
  4432. 1,4,4,7,4,13,3,9,10,21,17,3,26,2,1,5,2,4,5,4,1,7,4,7,3,4,2,1,6,1,1,20,4,1,9,2,2,1,3,3,2,3,2,1,1,1,20,2,3,1,6,2,3,6,2,4,8,1,3,2,10,3,5,3,4,4,
  4433. 3,4,16,1,6,1,10,2,4,2,1,1,2,10,11,2,2,3,1,24,31,4,10,10,2,5,12,16,164,15,4,16,7,9,15,19,17,1,2,1,1,5,1,1,1,1,1,3,1,4,3,1,3,1,3,1,2,1,1,3,3,7,
  4434. 2,8,1,2,2,2,1,3,4,3,7,8,12,92,2,10,3,1,3,14,5,25,16,42,4,7,7,4,2,21,5,27,26,27,21,25,30,31,2,1,5,13,3,22,5,6,6,11,9,12,1,5,9,7,5,5,22,60,3,5,
  4435. 13,1,1,8,1,1,3,3,2,1,9,3,3,18,4,1,2,3,7,6,3,1,2,3,9,1,3,1,3,2,1,3,1,1,1,2,1,11,3,1,6,9,1,3,2,3,1,2,1,5,1,1,4,3,4,1,2,2,4,4,1,7,2,1,2,2,3,5,13,
  4436. 18,3,4,14,9,9,4,16,3,7,5,8,2,6,48,28,3,1,1,4,2,14,8,2,9,2,1,15,2,4,3,2,10,16,12,8,7,1,1,3,1,1,1,2,7,4,1,6,4,38,39,16,23,7,15,15,3,2,12,7,21,
  4437. 37,27,6,5,4,8,2,10,8,8,6,5,1,2,1,3,24,1,16,17,9,23,10,17,6,1,51,55,44,13,294,9,3,6,2,4,2,2,15,1,1,1,13,21,17,68,14,8,9,4,1,4,9,3,11,7,1,1,1,
  4438. 5,6,3,2,1,1,1,2,3,8,1,2,2,4,1,5,5,2,1,4,3,7,13,4,1,4,1,3,1,1,1,5,5,10,1,6,1,5,2,1,5,2,4,1,4,5,7,3,18,2,9,11,32,4,3,3,2,4,7,11,16,9,11,8,13,38,
  4439. 32,8,4,2,1,1,2,1,2,4,4,1,1,1,4,1,21,3,11,1,16,1,1,6,1,3,2,4,9,8,57,7,44,1,3,3,13,3,10,1,1,7,5,2,7,21,47,63,3,15,4,7,1,16,1,1,2,8,2,3,42,15,4,
  4440. 1,29,7,22,10,3,78,16,12,20,18,4,67,11,5,1,3,15,6,21,31,32,27,18,13,71,35,5,142,4,10,1,2,50,19,33,16,35,37,16,19,27,7,1,133,19,1,4,8,7,20,1,4,
  4441. 4,1,10,3,1,6,1,2,51,5,40,15,24,43,22928,11,1,13,154,70,3,1,1,7,4,10,1,2,1,1,2,1,2,1,2,2,1,1,2,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,
  4442. 3,2,1,1,1,1,2,1,1,
  4443. };
  4444. static ImWchar base_ranges[] = // not zero-terminated
  4445. {
  4446. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  4447. 0x3000, 0x30FF, // CJK Symbols and Punctuations, Hiragana, Katakana
  4448. 0x31F0, 0x31FF, // Katakana Phonetic Extensions
  4449. 0xFF00, 0xFFEF, // Half-width characters
  4450. 0xFFFD, 0xFFFD // Invalid
  4451. };
  4452. static ImWchar full_ranges[IM_ARRAYSIZE(base_ranges) + IM_ARRAYSIZE(accumulative_offsets_from_0x4E00)*2 + 1] = { 0 };
  4453. if (!full_ranges[0])
  4454. {
  4455. memcpy(full_ranges, base_ranges, sizeof(base_ranges));
  4456. UnpackAccumulativeOffsetsIntoRanges(0x4E00, accumulative_offsets_from_0x4E00, IM_ARRAYSIZE(accumulative_offsets_from_0x4E00), full_ranges + IM_ARRAYSIZE(base_ranges));
  4457. }
  4458. return &full_ranges[0];
  4459. }
  4460. const ImWchar* ImFontAtlas::GetGlyphRangesCyrillic()
  4461. {
  4462. static const ImWchar ranges[] =
  4463. {
  4464. 0x0020, 0x00FF, // Basic Latin + Latin Supplement
  4465. 0x0400, 0x052F, // Cyrillic + Cyrillic Supplement
  4466. 0x2DE0, 0x2DFF, // Cyrillic Extended-A
  4467. 0xA640, 0xA69F, // Cyrillic Extended-B
  4468. 0,
  4469. };
  4470. return &ranges[0];
  4471. }
  4472. const ImWchar* ImFontAtlas::GetGlyphRangesThai()
  4473. {
  4474. static const ImWchar ranges[] =
  4475. {
  4476. 0x0020, 0x00FF, // Basic Latin
  4477. 0x2010, 0x205E, // Punctuations
  4478. 0x0E00, 0x0E7F, // Thai
  4479. 0,
  4480. };
  4481. return &ranges[0];
  4482. }
  4483. const ImWchar* ImFontAtlas::GetGlyphRangesVietnamese()
  4484. {
  4485. static const ImWchar ranges[] =
  4486. {
  4487. 0x0020, 0x00FF, // Basic Latin
  4488. 0x0102, 0x0103,
  4489. 0x0110, 0x0111,
  4490. 0x0128, 0x0129,
  4491. 0x0168, 0x0169,
  4492. 0x01A0, 0x01A1,
  4493. 0x01AF, 0x01B0,
  4494. 0x1EA0, 0x1EF9,
  4495. 0,
  4496. };
  4497. return &ranges[0];
  4498. }
  4499. #endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
  4500. //-----------------------------------------------------------------------------
  4501. // [SECTION] ImFontGlyphRangesBuilder
  4502. //-----------------------------------------------------------------------------
  4503. void ImFontGlyphRangesBuilder::AddText(const char* text, const char* text_end)
  4504. {
  4505. while (text_end ? (text < text_end) : *text)
  4506. {
  4507. unsigned int c = 0;
  4508. int c_len = ImTextCharFromUtf8(&c, text, text_end);
  4509. text += c_len;
  4510. if (c_len == 0)
  4511. break;
  4512. AddChar((ImWchar)c);
  4513. }
  4514. }
  4515. void ImFontGlyphRangesBuilder::AddRanges(const ImWchar* ranges)
  4516. {
  4517. for (; ranges[0]; ranges += 2)
  4518. for (unsigned int c = ranges[0]; c <= ranges[1] && c <= IM_UNICODE_CODEPOINT_MAX; c++) //-V560
  4519. AddChar((ImWchar)c);
  4520. }
  4521. void ImFontGlyphRangesBuilder::BuildRanges(ImVector<ImWchar>* out_ranges)
  4522. {
  4523. const int max_codepoint = IM_UNICODE_CODEPOINT_MAX;
  4524. for (int n = 0; n <= max_codepoint; n++)
  4525. if (GetBit(n))
  4526. {
  4527. out_ranges->push_back((ImWchar)n);
  4528. while (n < max_codepoint && GetBit(n + 1))
  4529. n++;
  4530. out_ranges->push_back((ImWchar)n);
  4531. }
  4532. out_ranges->push_back(0);
  4533. }
  4534. //-----------------------------------------------------------------------------
  4535. // [SECTION] ImFont
  4536. //-----------------------------------------------------------------------------
  4537. ImFontBaked::ImFontBaked()
  4538. {
  4539. memset(this, 0, sizeof(*this));
  4540. FallbackGlyphIndex = -1;
  4541. }
  4542. void ImFontBaked::ClearOutputData()
  4543. {
  4544. FallbackAdvanceX = 0.0f;
  4545. Glyphs.clear();
  4546. IndexAdvanceX.clear();
  4547. IndexLookup.clear();
  4548. FallbackGlyphIndex = -1;
  4549. Ascent = Descent = 0.0f;
  4550. MetricsTotalSurface = 0;
  4551. }
  4552. ImFont::ImFont()
  4553. {
  4554. memset(this, 0, sizeof(*this));
  4555. #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
  4556. Scale = 1.0f;
  4557. #endif
  4558. }
  4559. ImFont::~ImFont()
  4560. {
  4561. ClearOutputData();
  4562. }
  4563. void ImFont::ClearOutputData()
  4564. {
  4565. if (ImFontAtlas* atlas = ContainerAtlas)
  4566. ImFontAtlasFontDiscardBakes(atlas, this, 0);
  4567. FallbackChar = EllipsisChar = 0;
  4568. memset(Used8kPagesMap, 0, sizeof(Used8kPagesMap));
  4569. LastBaked = NULL;
  4570. }
  4571. // API is designed this way to avoid exposing the 8K page size
  4572. // e.g. use with IsGlyphRangeUnused(0, 255)
  4573. bool ImFont::IsGlyphRangeUnused(unsigned int c_begin, unsigned int c_last)
  4574. {
  4575. unsigned int page_begin = (c_begin / 8192);
  4576. unsigned int page_last = (c_last / 8192);
  4577. for (unsigned int page_n = page_begin; page_n <= page_last; page_n++)
  4578. if ((page_n >> 3) < sizeof(Used8kPagesMap))
  4579. if (Used8kPagesMap[page_n >> 3] & (1 << (page_n & 7)))
  4580. return false;
  4581. return true;
  4582. }
  4583. // x0/y0/x1/y1 are offset from the character upper-left layout position, in pixels. Therefore x0/y0 are often fairly close to zero.
  4584. // Not to be mistaken with texture coordinates, which are held by u0/v0/u1/v1 in normalized format (0.0..1.0 on each texture axis).
  4585. // - 'src' is not necessarily == 'this->Sources' because multiple source fonts+configs can be used to build one target font.
  4586. ImFontGlyph* ImFontAtlasBakedAddFontGlyph(ImFontAtlas* atlas, ImFontBaked* baked, ImFontConfig* src, const ImFontGlyph* in_glyph)
  4587. {
  4588. int glyph_idx = baked->Glyphs.Size;
  4589. baked->Glyphs.push_back(*in_glyph);
  4590. ImFontGlyph* glyph = &baked->Glyphs[glyph_idx];
  4591. IM_ASSERT(baked->Glyphs.Size < 0xFFFE); // IndexLookup[] hold 16-bit values and -1/-2 are reserved.
  4592. // Set UV from packed rectangle
  4593. if (glyph->PackId != ImFontAtlasRectId_Invalid)
  4594. {
  4595. ImTextureRect* r = ImFontAtlasPackGetRect(atlas, glyph->PackId);
  4596. IM_ASSERT(glyph->U0 == 0.0f && glyph->V0 == 0.0f && glyph->U1 == 0.0f && glyph->V1 == 0.0f);
  4597. glyph->U0 = (r->x) * atlas->TexUvScale.x;
  4598. glyph->V0 = (r->y) * atlas->TexUvScale.y;
  4599. glyph->U1 = (r->x + r->w) * atlas->TexUvScale.x;
  4600. glyph->V1 = (r->y + r->h) * atlas->TexUvScale.y;
  4601. baked->MetricsTotalSurface += r->w * r->h;
  4602. }
  4603. if (src != NULL)
  4604. {
  4605. // Clamp & recenter if needed
  4606. const float ref_size = baked->ContainerFont->Sources[0]->SizePixels;
  4607. const float offsets_scale = (ref_size != 0.0f) ? (baked->Size / ref_size) : 1.0f;
  4608. float advance_x = ImClamp(glyph->AdvanceX, src->GlyphMinAdvanceX * offsets_scale, src->GlyphMaxAdvanceX * offsets_scale);
  4609. if (advance_x != glyph->AdvanceX)
  4610. {
  4611. float char_off_x = src->PixelSnapH ? ImTrunc((advance_x - glyph->AdvanceX) * 0.5f) : (advance_x - glyph->AdvanceX) * 0.5f;
  4612. glyph->X0 += char_off_x;
  4613. glyph->X1 += char_off_x;
  4614. }
  4615. // Snap to pixel
  4616. if (src->PixelSnapH)
  4617. advance_x = IM_ROUND(advance_x);
  4618. // Bake spacing
  4619. glyph->AdvanceX = advance_x + src->GlyphExtraAdvanceX;
  4620. }
  4621. if (glyph->Colored)
  4622. atlas->TexPixelsUseColors = atlas->TexData->UseColors = true;
  4623. // Update lookup tables
  4624. const int codepoint = glyph->Codepoint;
  4625. ImFontBaked_BuildGrowIndex(baked, codepoint + 1);
  4626. baked->IndexAdvanceX[codepoint] = glyph->AdvanceX;
  4627. baked->IndexLookup[codepoint] = (ImU16)glyph_idx;
  4628. const int page_n = codepoint / 8192;
  4629. baked->ContainerFont->Used8kPagesMap[page_n >> 3] |= 1 << (page_n & 7);
  4630. return glyph;
  4631. }
  4632. // FIXME: Code is duplicated with code above.
  4633. void ImFontAtlasBakedAddFontGlyphAdvancedX(ImFontAtlas* atlas, ImFontBaked* baked, ImFontConfig* src, ImWchar codepoint, float advance_x)
  4634. {
  4635. IM_UNUSED(atlas);
  4636. if (src != NULL)
  4637. {
  4638. // Clamp & recenter if needed
  4639. const float ref_size = baked->ContainerFont->Sources[0]->SizePixels;
  4640. const float offsets_scale = (ref_size != 0.0f) ? (baked->Size / ref_size) : 1.0f;
  4641. advance_x = ImClamp(advance_x, src->GlyphMinAdvanceX * offsets_scale, src->GlyphMaxAdvanceX * offsets_scale);
  4642. // Snap to pixel
  4643. if (src->PixelSnapH)
  4644. advance_x = IM_ROUND(advance_x);
  4645. // Bake spacing
  4646. advance_x += src->GlyphExtraAdvanceX;
  4647. }
  4648. ImFontBaked_BuildGrowIndex(baked, codepoint + 1);
  4649. baked->IndexAdvanceX[codepoint] = advance_x;
  4650. }
  4651. // Copy to texture, post-process and queue update for backend
  4652. void ImFontAtlasBakedSetFontGlyphBitmap(ImFontAtlas* atlas, ImFontBaked* baked, ImFontConfig* src, ImFontGlyph* glyph, ImTextureRect* r, const unsigned char* src_pixels, ImTextureFormat src_fmt, int src_pitch)
  4653. {
  4654. ImTextureData* tex = atlas->TexData;
  4655. IM_ASSERT(r->x + r->w <= tex->Width && r->y + r->h <= tex->Height);
  4656. ImFontAtlasTextureBlockConvert(src_pixels, src_fmt, src_pitch, (unsigned char*)tex->GetPixelsAt(r->x, r->y), tex->Format, tex->GetPitch(), r->w, r->h);
  4657. ImFontAtlasPostProcessData pp_data = { atlas, baked->ContainerFont, src, baked, glyph, tex->GetPixelsAt(r->x, r->y), tex->Format, tex->GetPitch(), r->w, r->h };
  4658. ImFontAtlasTextureBlockPostProcess(&pp_data);
  4659. ImFontAtlasTextureBlockQueueUpload(atlas, tex, r->x, r->y, r->w, r->h);
  4660. }
  4661. void ImFont::AddRemapChar(ImWchar from_codepoint, ImWchar to_codepoint)
  4662. {
  4663. RemapPairs.SetInt((ImGuiID)from_codepoint, (int)to_codepoint);
  4664. }
  4665. // Find glyph, load if necessary, return fallback if missing
  4666. ImFontGlyph* ImFontBaked::FindGlyph(ImWchar c)
  4667. {
  4668. if (c < (size_t)IndexLookup.Size) IM_LIKELY
  4669. {
  4670. const int i = (int)IndexLookup.Data[c];
  4671. if (i == IM_FONTGLYPH_INDEX_NOT_FOUND)
  4672. return &Glyphs.Data[FallbackGlyphIndex];
  4673. if (i != IM_FONTGLYPH_INDEX_UNUSED)
  4674. return &Glyphs.Data[i];
  4675. }
  4676. ImFontGlyph* glyph = ImFontBaked_BuildLoadGlyph(this, c, NULL);
  4677. return glyph ? glyph : &Glyphs.Data[FallbackGlyphIndex];
  4678. }
  4679. // Attempt to load but when missing, return NULL instead of FallbackGlyph
  4680. ImFontGlyph* ImFontBaked::FindGlyphNoFallback(ImWchar c)
  4681. {
  4682. if (c < (size_t)IndexLookup.Size) IM_LIKELY
  4683. {
  4684. const int i = (int)IndexLookup.Data[c];
  4685. if (i == IM_FONTGLYPH_INDEX_NOT_FOUND)
  4686. return NULL;
  4687. if (i != IM_FONTGLYPH_INDEX_UNUSED)
  4688. return &Glyphs.Data[i];
  4689. }
  4690. LockLoadingFallback = true; // This is actually a rare call, not done in hot-loop, so we prioritize not adding extra cruft to ImFontBaked_BuildLoadGlyph() call sites.
  4691. ImFontGlyph* glyph = ImFontBaked_BuildLoadGlyph(this, c, NULL);
  4692. LockLoadingFallback = false;
  4693. return glyph;
  4694. }
  4695. bool ImFontBaked::IsGlyphLoaded(ImWchar c)
  4696. {
  4697. if (c < (size_t)IndexLookup.Size) IM_LIKELY
  4698. {
  4699. const int i = (int)IndexLookup.Data[c];
  4700. if (i == IM_FONTGLYPH_INDEX_NOT_FOUND)
  4701. return false;
  4702. if (i != IM_FONTGLYPH_INDEX_UNUSED)
  4703. return true;
  4704. }
  4705. return false;
  4706. }
  4707. // This is not fast query
  4708. bool ImFont::IsGlyphInFont(ImWchar c)
  4709. {
  4710. ImFontAtlas* atlas = ContainerAtlas;
  4711. ImFontAtlas_FontHookRemapCodepoint(atlas, this, &c);
  4712. for (ImFontConfig* src : Sources)
  4713. {
  4714. const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader;
  4715. if (loader->FontSrcContainsGlyph != NULL && loader->FontSrcContainsGlyph(atlas, src, c))
  4716. return true;
  4717. }
  4718. return false;
  4719. }
  4720. // This is manually inlined in CalcTextSizeA() and CalcWordWrapPosition(), with a non-inline call to BuildLoadGlyphGetAdvanceOrFallback().
  4721. IM_MSVC_RUNTIME_CHECKS_OFF
  4722. float ImFontBaked::GetCharAdvance(ImWchar c)
  4723. {
  4724. if ((int)c < IndexAdvanceX.Size)
  4725. {
  4726. // Missing glyphs fitting inside index will have stored FallbackAdvanceX already.
  4727. const float x = IndexAdvanceX.Data[c];
  4728. if (x >= 0.0f)
  4729. return x;
  4730. }
  4731. return ImFontBaked_BuildLoadGlyphAdvanceX(this, c);
  4732. }
  4733. IM_MSVC_RUNTIME_CHECKS_RESTORE
  4734. ImGuiID ImFontAtlasBakedGetId(ImGuiID font_id, float baked_size, float rasterizer_density)
  4735. {
  4736. struct { ImGuiID FontId; float BakedSize; float RasterizerDensity; } hashed_data;
  4737. hashed_data.FontId = font_id;
  4738. hashed_data.BakedSize = baked_size;
  4739. hashed_data.RasterizerDensity = rasterizer_density;
  4740. return ImHashData(&hashed_data, sizeof(hashed_data));
  4741. }
  4742. // ImFontBaked pointers are valid for the entire frame but shall never be kept between frames.
  4743. ImFontBaked* ImFont::GetFontBaked(float size, float density)
  4744. {
  4745. ImFontBaked* baked = LastBaked;
  4746. // Round font size
  4747. // - ImGui::PushFont() will already round, but other paths calling GetFontBaked() directly also needs it (e.g. ImFontAtlasBuildPreloadAllGlyphRanges)
  4748. size = ImGui::GetRoundedFontSize(size);
  4749. if (density < 0.0f)
  4750. density = CurrentRasterizerDensity;
  4751. if (baked && baked->Size == size && baked->RasterizerDensity == density)
  4752. return baked;
  4753. ImFontAtlas* atlas = ContainerAtlas;
  4754. ImFontAtlasBuilder* builder = atlas->Builder;
  4755. baked = ImFontAtlasBakedGetOrAdd(atlas, this, size, density);
  4756. if (baked == NULL)
  4757. return NULL;
  4758. baked->LastUsedFrame = builder->FrameCount;
  4759. LastBaked = baked;
  4760. return baked;
  4761. }
  4762. ImFontBaked* ImFontAtlasBakedGetOrAdd(ImFontAtlas* atlas, ImFont* font, float font_size, float font_rasterizer_density)
  4763. {
  4764. // FIXME-NEWATLAS: Design for picking a nearest size based on some criteria?
  4765. // FIXME-NEWATLAS: Altering font density won't work right away.
  4766. IM_ASSERT(font_size > 0.0f && font_rasterizer_density > 0.0f);
  4767. ImGuiID baked_id = ImFontAtlasBakedGetId(font->FontId, font_size, font_rasterizer_density);
  4768. ImFontAtlasBuilder* builder = atlas->Builder;
  4769. ImFontBaked** p_baked_in_map = (ImFontBaked**)builder->BakedMap.GetVoidPtrRef(baked_id);
  4770. ImFontBaked* baked = *p_baked_in_map;
  4771. if (baked != NULL)
  4772. {
  4773. IM_ASSERT(baked->Size == font_size && baked->ContainerFont == font && baked->BakedId == baked_id);
  4774. return baked;
  4775. }
  4776. // If atlas is locked, find closest match
  4777. // FIXME-OPT: This is not an optimal query.
  4778. if ((font->Flags & ImFontFlags_LockBakedSizes) || atlas->Locked)
  4779. {
  4780. baked = ImFontAtlasBakedGetClosestMatch(atlas, font, font_size, font_rasterizer_density);
  4781. if (baked != NULL)
  4782. return baked;
  4783. if (atlas->Locked)
  4784. {
  4785. IM_ASSERT(!atlas->Locked && "Cannot use dynamic font size with a locked ImFontAtlas!"); // Locked because rendering backend does not support ImGuiBackendFlags_RendererHasTextures!
  4786. return NULL;
  4787. }
  4788. }
  4789. // Create new
  4790. baked = ImFontAtlasBakedAdd(atlas, font, font_size, font_rasterizer_density, baked_id);
  4791. *p_baked_in_map = baked; // To avoid 'builder->BakedMap.SetVoidPtr(baked_id, baked);' while we can.
  4792. return baked;
  4793. }
  4794. // Trim trailing space and find beginning of next line
  4795. static inline const char* CalcWordWrapNextLineStartA(const char* text, const char* text_end)
  4796. {
  4797. while (text < text_end && ImCharIsBlankA(*text))
  4798. text++;
  4799. if (*text == '\n')
  4800. text++;
  4801. return text;
  4802. }
  4803. // Simple word-wrapping for English, not full-featured. Please submit failing cases!
  4804. // This will return the next location to wrap from. If no wrapping if necessary, this will fast-forward to e.g. text_end.
  4805. // 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.)
  4806. const char* ImFont::CalcWordWrapPosition(float size, const char* text, const char* text_end, float wrap_width)
  4807. {
  4808. // For references, possible wrap point marked with ^
  4809. // "aaa bbb, ccc,ddd. eee fff. ggg!"
  4810. // ^ ^ ^ ^ ^__ ^ ^
  4811. // List of hardcoded separators: .,;!?'"
  4812. // Skip extra blanks after a line returns (that includes not counting them in width computation)
  4813. // e.g. "Hello world" --> "Hello" "World"
  4814. // Cut words that cannot possibly fit within one line.
  4815. // e.g.: "The tropical fish" with ~5 characters worth of width --> "The tr" "opical" "fish"
  4816. ImFontBaked* baked = GetFontBaked(size);
  4817. const float scale = size / baked->Size;
  4818. float line_width = 0.0f;
  4819. float word_width = 0.0f;
  4820. float blank_width = 0.0f;
  4821. wrap_width /= scale; // We work with unscaled widths to avoid scaling every characters
  4822. const char* word_end = text;
  4823. const char* prev_word_end = NULL;
  4824. bool inside_word = true;
  4825. const char* s = text;
  4826. IM_ASSERT(text_end != NULL);
  4827. while (s < text_end)
  4828. {
  4829. unsigned int c = (unsigned int)*s;
  4830. const char* next_s;
  4831. if (c < 0x80)
  4832. next_s = s + 1;
  4833. else
  4834. next_s = s + ImTextCharFromUtf8(&c, s, text_end);
  4835. if (c < 32)
  4836. {
  4837. if (c == '\n')
  4838. {
  4839. line_width = word_width = blank_width = 0.0f;
  4840. inside_word = true;
  4841. s = next_s;
  4842. continue;
  4843. }
  4844. if (c == '\r')
  4845. {
  4846. s = next_s;
  4847. continue;
  4848. }
  4849. }
  4850. // Optimized inline version of 'float char_width = GetCharAdvance((ImWchar)c);'
  4851. float char_width = (c < (unsigned int)baked->IndexAdvanceX.Size) ? baked->IndexAdvanceX.Data[c] : -1.0f;
  4852. if (char_width < 0.0f)
  4853. char_width = BuildLoadGlyphGetAdvanceOrFallback(baked, c);
  4854. if (ImCharIsBlankW(c))
  4855. {
  4856. if (inside_word)
  4857. {
  4858. line_width += blank_width;
  4859. blank_width = 0.0f;
  4860. word_end = s;
  4861. }
  4862. blank_width += char_width;
  4863. inside_word = false;
  4864. }
  4865. else
  4866. {
  4867. word_width += char_width;
  4868. if (inside_word)
  4869. {
  4870. word_end = next_s;
  4871. }
  4872. else
  4873. {
  4874. prev_word_end = word_end;
  4875. line_width += word_width + blank_width;
  4876. word_width = blank_width = 0.0f;
  4877. }
  4878. // Allow wrapping after punctuation.
  4879. inside_word = (c != '.' && c != ',' && c != ';' && c != '!' && c != '?' && c != '\"' && c != 0x3001 && c != 0x3002);
  4880. }
  4881. // We ignore blank width at the end of the line (they can be skipped)
  4882. if (line_width + word_width > wrap_width)
  4883. {
  4884. // Words that cannot possibly fit within an entire line will be cut anywhere.
  4885. if (word_width < wrap_width)
  4886. s = prev_word_end ? prev_word_end : word_end;
  4887. break;
  4888. }
  4889. s = next_s;
  4890. }
  4891. // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity.
  4892. // +1 may not be a character start point in UTF-8 but it's ok because caller loops use (text >= word_wrap_eol).
  4893. if (s == text && text < text_end)
  4894. return s + ImTextCountUtf8BytesFromChar(s, text_end);
  4895. return s;
  4896. }
  4897. ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end, const char** remaining)
  4898. {
  4899. if (!text_end)
  4900. text_end = text_begin + ImStrlen(text_begin); // FIXME-OPT: Need to avoid this.
  4901. const float line_height = size;
  4902. ImFontBaked* baked = GetFontBaked(size);
  4903. const float scale = size / baked->Size;
  4904. ImVec2 text_size = ImVec2(0, 0);
  4905. float line_width = 0.0f;
  4906. const bool word_wrap_enabled = (wrap_width > 0.0f);
  4907. const char* word_wrap_eol = NULL;
  4908. const char* s = text_begin;
  4909. while (s < text_end)
  4910. {
  4911. if (word_wrap_enabled)
  4912. {
  4913. // 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.
  4914. if (!word_wrap_eol)
  4915. word_wrap_eol = CalcWordWrapPosition(size, s, text_end, wrap_width - line_width);
  4916. if (s >= word_wrap_eol)
  4917. {
  4918. if (text_size.x < line_width)
  4919. text_size.x = line_width;
  4920. text_size.y += line_height;
  4921. line_width = 0.0f;
  4922. word_wrap_eol = NULL;
  4923. s = CalcWordWrapNextLineStartA(s, text_end); // Wrapping skips upcoming blanks
  4924. continue;
  4925. }
  4926. }
  4927. // Decode and advance source
  4928. const char* prev_s = s;
  4929. unsigned int c = (unsigned int)*s;
  4930. if (c < 0x80)
  4931. s += 1;
  4932. else
  4933. s += ImTextCharFromUtf8(&c, s, text_end);
  4934. if (c < 32)
  4935. {
  4936. if (c == '\n')
  4937. {
  4938. text_size.x = ImMax(text_size.x, line_width);
  4939. text_size.y += line_height;
  4940. line_width = 0.0f;
  4941. continue;
  4942. }
  4943. if (c == '\r')
  4944. continue;
  4945. }
  4946. // Optimized inline version of 'float char_width = GetCharAdvance((ImWchar)c);'
  4947. float char_width = (c < (unsigned int)baked->IndexAdvanceX.Size) ? baked->IndexAdvanceX.Data[c] : -1.0f;
  4948. if (char_width < 0.0f)
  4949. char_width = BuildLoadGlyphGetAdvanceOrFallback(baked, c);
  4950. char_width *= scale;
  4951. if (line_width + char_width >= max_width)
  4952. {
  4953. s = prev_s;
  4954. break;
  4955. }
  4956. line_width += char_width;
  4957. }
  4958. if (text_size.x < line_width)
  4959. text_size.x = line_width;
  4960. if (line_width > 0 || text_size.y == 0.0f)
  4961. text_size.y += line_height;
  4962. if (remaining)
  4963. *remaining = s;
  4964. return text_size;
  4965. }
  4966. // Note: as with every ImDrawList drawing function, this expects that the font atlas texture is bound.
  4967. void ImFont::RenderChar(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, ImWchar c, const ImVec4* cpu_fine_clip)
  4968. {
  4969. ImFontBaked* baked = GetFontBaked(size);
  4970. const ImFontGlyph* glyph = baked->FindGlyph(c);
  4971. if (!glyph || !glyph->Visible)
  4972. return;
  4973. if (glyph->Colored)
  4974. col |= ~IM_COL32_A_MASK;
  4975. float scale = (size >= 0.0f) ? (size / baked->Size) : 1.0f;
  4976. float x = IM_TRUNC(pos.x);
  4977. float y = IM_TRUNC(pos.y);
  4978. float x1 = x + glyph->X0 * scale;
  4979. float x2 = x + glyph->X1 * scale;
  4980. if (cpu_fine_clip && (x1 > cpu_fine_clip->z || x2 < cpu_fine_clip->x))
  4981. return;
  4982. float y1 = y + glyph->Y0 * scale;
  4983. float y2 = y + glyph->Y1 * scale;
  4984. float u1 = glyph->U0;
  4985. float v1 = glyph->V0;
  4986. float u2 = glyph->U1;
  4987. float v2 = glyph->V1;
  4988. // Always CPU fine clip. Code extracted from RenderText().
  4989. // CPU side clipping used to fit text in their frame when the frame is too small. Only does clipping for axis aligned quads.
  4990. if (cpu_fine_clip != NULL)
  4991. {
  4992. if (x1 < cpu_fine_clip->x) { u1 = u1 + (1.0f - (x2 - cpu_fine_clip->x) / (x2 - x1)) * (u2 - u1); x1 = cpu_fine_clip->x; }
  4993. if (y1 < cpu_fine_clip->y) { v1 = v1 + (1.0f - (y2 - cpu_fine_clip->y) / (y2 - y1)) * (v2 - v1); y1 = cpu_fine_clip->y; }
  4994. if (x2 > cpu_fine_clip->z) { u2 = u1 + ((cpu_fine_clip->z - x1) / (x2 - x1)) * (u2 - u1); x2 = cpu_fine_clip->z; }
  4995. if (y2 > cpu_fine_clip->w) { v2 = v1 + ((cpu_fine_clip->w - y1) / (y2 - y1)) * (v2 - v1); y2 = cpu_fine_clip->w; }
  4996. if (y1 >= y2)
  4997. return;
  4998. }
  4999. draw_list->PrimReserve(6, 4);
  5000. draw_list->PrimRectUV(ImVec2(x1, y1), ImVec2(x2, y2), ImVec2(u1, v1), ImVec2(u2, v2), col);
  5001. }
  5002. // Note: as with every ImDrawList drawing function, this expects that the font atlas texture is bound.
  5003. void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width, bool cpu_fine_clip)
  5004. {
  5005. // Align to be pixel perfect
  5006. begin:
  5007. float x = IM_TRUNC(pos.x);
  5008. float y = IM_TRUNC(pos.y);
  5009. if (y > clip_rect.w)
  5010. return;
  5011. if (!text_end)
  5012. text_end = text_begin + ImStrlen(text_begin); // ImGui:: functions generally already provides a valid text_end, so this is merely to handle direct calls.
  5013. const float line_height = size;
  5014. ImFontBaked* baked = GetFontBaked(size);
  5015. const float scale = size / baked->Size;
  5016. const float origin_x = x;
  5017. const bool word_wrap_enabled = (wrap_width > 0.0f);
  5018. // Fast-forward to first visible line
  5019. const char* s = text_begin;
  5020. if (y + line_height < clip_rect.y)
  5021. while (y + line_height < clip_rect.y && s < text_end)
  5022. {
  5023. const char* line_end = (const char*)ImMemchr(s, '\n', text_end - s);
  5024. if (word_wrap_enabled)
  5025. {
  5026. // FIXME-OPT: This is not optimal as do first do a search for \n before calling CalcWordWrapPosition().
  5027. // If the specs for CalcWordWrapPosition() were reworked to optionally return on \n we could combine both.
  5028. // However it is still better than nothing performing the fast-forward!
  5029. s = CalcWordWrapPosition(size, s, line_end ? line_end : text_end, wrap_width);
  5030. s = CalcWordWrapNextLineStartA(s, text_end);
  5031. }
  5032. else
  5033. {
  5034. s = line_end ? line_end + 1 : text_end;
  5035. }
  5036. y += line_height;
  5037. }
  5038. // For large text, scan for the last visible line in order to avoid over-reserving in the call to PrimReserve()
  5039. // Note that very large horizontal line will still be affected by the issue (e.g. a one megabyte string buffer without a newline will likely crash atm)
  5040. if (text_end - s > 10000 && !word_wrap_enabled)
  5041. {
  5042. const char* s_end = s;
  5043. float y_end = y;
  5044. while (y_end < clip_rect.w && s_end < text_end)
  5045. {
  5046. s_end = (const char*)ImMemchr(s_end, '\n', text_end - s_end);
  5047. s_end = s_end ? s_end + 1 : text_end;
  5048. y_end += line_height;
  5049. }
  5050. text_end = s_end;
  5051. }
  5052. if (s == text_end)
  5053. return;
  5054. // Reserve vertices for remaining worse case (over-reserving is useful and easily amortized)
  5055. const int vtx_count_max = (int)(text_end - s) * 4;
  5056. const int idx_count_max = (int)(text_end - s) * 6;
  5057. const int idx_expected_size = draw_list->IdxBuffer.Size + idx_count_max;
  5058. draw_list->PrimReserve(idx_count_max, vtx_count_max);
  5059. ImDrawVert* vtx_write = draw_list->_VtxWritePtr;
  5060. ImDrawIdx* idx_write = draw_list->_IdxWritePtr;
  5061. unsigned int vtx_index = draw_list->_VtxCurrentIdx;
  5062. const int cmd_count = draw_list->CmdBuffer.Size;
  5063. const ImU32 col_untinted = col | ~IM_COL32_A_MASK;
  5064. const char* word_wrap_eol = NULL;
  5065. while (s < text_end)
  5066. {
  5067. if (word_wrap_enabled)
  5068. {
  5069. // 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.
  5070. if (!word_wrap_eol)
  5071. word_wrap_eol = CalcWordWrapPosition(size, s, text_end, wrap_width - (x - origin_x));
  5072. if (s >= word_wrap_eol)
  5073. {
  5074. x = origin_x;
  5075. y += line_height;
  5076. if (y > clip_rect.w)
  5077. break; // break out of main loop
  5078. word_wrap_eol = NULL;
  5079. s = CalcWordWrapNextLineStartA(s, text_end); // Wrapping skips upcoming blanks
  5080. continue;
  5081. }
  5082. }
  5083. // Decode and advance source
  5084. unsigned int c = (unsigned int)*s;
  5085. if (c < 0x80)
  5086. s += 1;
  5087. else
  5088. s += ImTextCharFromUtf8(&c, s, text_end);
  5089. if (c < 32)
  5090. {
  5091. if (c == '\n')
  5092. {
  5093. x = origin_x;
  5094. y += line_height;
  5095. if (y > clip_rect.w)
  5096. break; // break out of main loop
  5097. continue;
  5098. }
  5099. if (c == '\r')
  5100. continue;
  5101. }
  5102. const ImFontGlyph* glyph = baked->FindGlyph((ImWchar)c);
  5103. //if (glyph == NULL)
  5104. // continue;
  5105. float char_width = glyph->AdvanceX * scale;
  5106. if (glyph->Visible)
  5107. {
  5108. // We don't do a second finer clipping test on the Y axis as we've already skipped anything before clip_rect.y and exit once we pass clip_rect.w
  5109. float x1 = x + glyph->X0 * scale;
  5110. float x2 = x + glyph->X1 * scale;
  5111. float y1 = y + glyph->Y0 * scale;
  5112. float y2 = y + glyph->Y1 * scale;
  5113. if (x1 <= clip_rect.z && x2 >= clip_rect.x)
  5114. {
  5115. // Render a character
  5116. float u1 = glyph->U0;
  5117. float v1 = glyph->V0;
  5118. float u2 = glyph->U1;
  5119. float v2 = glyph->V1;
  5120. // CPU side clipping used to fit text in their frame when the frame is too small. Only does clipping for axis aligned quads.
  5121. if (cpu_fine_clip)
  5122. {
  5123. if (x1 < clip_rect.x)
  5124. {
  5125. u1 = u1 + (1.0f - (x2 - clip_rect.x) / (x2 - x1)) * (u2 - u1);
  5126. x1 = clip_rect.x;
  5127. }
  5128. if (y1 < clip_rect.y)
  5129. {
  5130. v1 = v1 + (1.0f - (y2 - clip_rect.y) / (y2 - y1)) * (v2 - v1);
  5131. y1 = clip_rect.y;
  5132. }
  5133. if (x2 > clip_rect.z)
  5134. {
  5135. u2 = u1 + ((clip_rect.z - x1) / (x2 - x1)) * (u2 - u1);
  5136. x2 = clip_rect.z;
  5137. }
  5138. if (y2 > clip_rect.w)
  5139. {
  5140. v2 = v1 + ((clip_rect.w - y1) / (y2 - y1)) * (v2 - v1);
  5141. y2 = clip_rect.w;
  5142. }
  5143. if (y1 >= y2)
  5144. {
  5145. x += char_width;
  5146. continue;
  5147. }
  5148. }
  5149. // Support for untinted glyphs
  5150. ImU32 glyph_col = glyph->Colored ? col_untinted : col;
  5151. // We are NOT calling PrimRectUV() here because non-inlined causes too much overhead in a debug builds. Inlined here:
  5152. {
  5153. vtx_write[0].pos.x = x1; vtx_write[0].pos.y = y1; vtx_write[0].col = glyph_col; vtx_write[0].uv.x = u1; vtx_write[0].uv.y = v1;
  5154. vtx_write[1].pos.x = x2; vtx_write[1].pos.y = y1; vtx_write[1].col = glyph_col; vtx_write[1].uv.x = u2; vtx_write[1].uv.y = v1;
  5155. vtx_write[2].pos.x = x2; vtx_write[2].pos.y = y2; vtx_write[2].col = glyph_col; vtx_write[2].uv.x = u2; vtx_write[2].uv.y = v2;
  5156. vtx_write[3].pos.x = x1; vtx_write[3].pos.y = y2; vtx_write[3].col = glyph_col; vtx_write[3].uv.x = u1; vtx_write[3].uv.y = v2;
  5157. idx_write[0] = (ImDrawIdx)(vtx_index); idx_write[1] = (ImDrawIdx)(vtx_index + 1); idx_write[2] = (ImDrawIdx)(vtx_index + 2);
  5158. idx_write[3] = (ImDrawIdx)(vtx_index); idx_write[4] = (ImDrawIdx)(vtx_index + 2); idx_write[5] = (ImDrawIdx)(vtx_index + 3);
  5159. vtx_write += 4;
  5160. vtx_index += 4;
  5161. idx_write += 6;
  5162. }
  5163. }
  5164. }
  5165. x += char_width;
  5166. }
  5167. // Edge case: calling RenderText() with unloaded glyphs triggering texture change. It doesn't happen via ImGui:: calls because CalcTextSize() is always used.
  5168. if (cmd_count != draw_list->CmdBuffer.Size) //-V547
  5169. {
  5170. IM_ASSERT(draw_list->CmdBuffer[draw_list->CmdBuffer.Size - 1].ElemCount == 0);
  5171. draw_list->CmdBuffer.pop_back();
  5172. draw_list->PrimUnreserve(idx_count_max, vtx_count_max);
  5173. draw_list->AddDrawCmd();
  5174. //IMGUI_DEBUG_LOG("RenderText: cancel and retry to missing glyphs.\n"); // [DEBUG]
  5175. //draw_list->AddRectFilled(pos, pos + ImVec2(10, 10), IM_COL32(255, 0, 0, 255)); // [DEBUG]
  5176. goto begin;
  5177. //RenderText(draw_list, size, pos, col, clip_rect, text_begin, text_end, wrap_width, cpu_fine_clip); // FIXME-OPT: Would a 'goto begin' be better for code-gen?
  5178. //return;
  5179. }
  5180. // Give back unused vertices (clipped ones, blanks) ~ this is essentially a PrimUnreserve() action.
  5181. draw_list->VtxBuffer.Size = (int)(vtx_write - draw_list->VtxBuffer.Data); // Same as calling shrink()
  5182. draw_list->IdxBuffer.Size = (int)(idx_write - draw_list->IdxBuffer.Data);
  5183. draw_list->CmdBuffer[draw_list->CmdBuffer.Size - 1].ElemCount -= (idx_expected_size - draw_list->IdxBuffer.Size);
  5184. draw_list->_VtxWritePtr = vtx_write;
  5185. draw_list->_IdxWritePtr = idx_write;
  5186. draw_list->_VtxCurrentIdx = vtx_index;
  5187. }
  5188. //-----------------------------------------------------------------------------
  5189. // [SECTION] ImGui Internal Render Helpers
  5190. //-----------------------------------------------------------------------------
  5191. // Vaguely redesigned to stop accessing ImGui global state:
  5192. // - RenderArrow()
  5193. // - RenderBullet()
  5194. // - RenderCheckMark()
  5195. // - RenderArrowPointingAt()
  5196. // - RenderRectFilledRangeH()
  5197. // - RenderRectFilledWithHole()
  5198. //-----------------------------------------------------------------------------
  5199. // Function in need of a redesign (legacy mess)
  5200. // - RenderColorRectWithAlphaCheckerboard()
  5201. //-----------------------------------------------------------------------------
  5202. // Render an arrow aimed to be aligned with text (p_min is a position in the same space text would be positioned). To e.g. denote expanded/collapsed state
  5203. void ImGui::RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImU32 col, ImGuiDir dir, float scale)
  5204. {
  5205. const float h = draw_list->_Data->FontSize * 1.00f;
  5206. float r = h * 0.40f * scale;
  5207. ImVec2 center = pos + ImVec2(h * 0.50f, h * 0.50f * scale);
  5208. ImVec2 a, b, c;
  5209. switch (dir)
  5210. {
  5211. case ImGuiDir_Up:
  5212. case ImGuiDir_Down:
  5213. if (dir == ImGuiDir_Up) r = -r;
  5214. a = ImVec2(+0.000f, +0.750f) * r;
  5215. b = ImVec2(-0.866f, -0.750f) * r;
  5216. c = ImVec2(+0.866f, -0.750f) * r;
  5217. break;
  5218. case ImGuiDir_Left:
  5219. case ImGuiDir_Right:
  5220. if (dir == ImGuiDir_Left) r = -r;
  5221. a = ImVec2(+0.750f, +0.000f) * r;
  5222. b = ImVec2(-0.750f, +0.866f) * r;
  5223. c = ImVec2(-0.750f, -0.866f) * r;
  5224. break;
  5225. case ImGuiDir_None:
  5226. case ImGuiDir_COUNT:
  5227. IM_ASSERT(0);
  5228. break;
  5229. }
  5230. draw_list->AddTriangleFilled(center + a, center + b, center + c, col);
  5231. }
  5232. void ImGui::RenderBullet(ImDrawList* draw_list, ImVec2 pos, ImU32 col)
  5233. {
  5234. // FIXME-OPT: This should be baked in font.
  5235. draw_list->AddCircleFilled(pos, draw_list->_Data->FontSize * 0.20f, col, 8);
  5236. }
  5237. void ImGui::RenderCheckMark(ImDrawList* draw_list, ImVec2 pos, ImU32 col, float sz)
  5238. {
  5239. float thickness = ImMax(sz / 5.0f, 1.0f);
  5240. sz -= thickness * 0.5f;
  5241. pos += ImVec2(thickness * 0.25f, thickness * 0.25f);
  5242. float third = sz / 3.0f;
  5243. float bx = pos.x + third;
  5244. float by = pos.y + sz - third * 0.5f;
  5245. draw_list->PathLineTo(ImVec2(bx - third, by - third));
  5246. draw_list->PathLineTo(ImVec2(bx, by));
  5247. draw_list->PathLineTo(ImVec2(bx + third * 2.0f, by - third * 2.0f));
  5248. draw_list->PathStroke(col, 0, thickness);
  5249. }
  5250. // Render an arrow. 'pos' is position of the arrow tip. half_sz.x is length from base to tip. half_sz.y is length on each side.
  5251. void ImGui::RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col)
  5252. {
  5253. switch (direction)
  5254. {
  5255. case ImGuiDir_Left: draw_list->AddTriangleFilled(ImVec2(pos.x + half_sz.x, pos.y - half_sz.y), ImVec2(pos.x + half_sz.x, pos.y + half_sz.y), pos, col); return;
  5256. case ImGuiDir_Right: draw_list->AddTriangleFilled(ImVec2(pos.x - half_sz.x, pos.y + half_sz.y), ImVec2(pos.x - half_sz.x, pos.y - half_sz.y), pos, col); return;
  5257. case ImGuiDir_Up: draw_list->AddTriangleFilled(ImVec2(pos.x + half_sz.x, pos.y + half_sz.y), ImVec2(pos.x - half_sz.x, pos.y + half_sz.y), pos, col); return;
  5258. case ImGuiDir_Down: draw_list->AddTriangleFilled(ImVec2(pos.x - half_sz.x, pos.y - half_sz.y), ImVec2(pos.x + half_sz.x, pos.y - half_sz.y), pos, col); return;
  5259. case ImGuiDir_None: case ImGuiDir_COUNT: break; // Fix warnings
  5260. }
  5261. }
  5262. static inline float ImAcos01(float x)
  5263. {
  5264. if (x <= 0.0f) return IM_PI * 0.5f;
  5265. if (x >= 1.0f) return 0.0f;
  5266. return ImAcos(x);
  5267. //return (-0.69813170079773212f * x * x - 0.87266462599716477f) * x + 1.5707963267948966f; // Cheap approximation, may be enough for what we do.
  5268. }
  5269. // FIXME: Cleanup and move code to ImDrawList.
  5270. void ImGui::RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding)
  5271. {
  5272. if (x_end_norm == x_start_norm)
  5273. return;
  5274. if (x_start_norm > x_end_norm)
  5275. ImSwap(x_start_norm, x_end_norm);
  5276. ImVec2 p0 = ImVec2(ImLerp(rect.Min.x, rect.Max.x, x_start_norm), rect.Min.y);
  5277. ImVec2 p1 = ImVec2(ImLerp(rect.Min.x, rect.Max.x, x_end_norm), rect.Max.y);
  5278. if (rounding == 0.0f)
  5279. {
  5280. draw_list->AddRectFilled(p0, p1, col, 0.0f);
  5281. return;
  5282. }
  5283. rounding = ImClamp(ImMin((rect.Max.x - rect.Min.x) * 0.5f, (rect.Max.y - rect.Min.y) * 0.5f) - 1.0f, 0.0f, rounding);
  5284. const float inv_rounding = 1.0f / rounding;
  5285. const float arc0_b = ImAcos01(1.0f - (p0.x - rect.Min.x) * inv_rounding);
  5286. const float arc0_e = ImAcos01(1.0f - (p1.x - rect.Min.x) * inv_rounding);
  5287. const float half_pi = IM_PI * 0.5f; // We will == compare to this because we know this is the exact value ImAcos01 can return.
  5288. const float x0 = ImMax(p0.x, rect.Min.x + rounding);
  5289. if (arc0_b == arc0_e)
  5290. {
  5291. draw_list->PathLineTo(ImVec2(x0, p1.y));
  5292. draw_list->PathLineTo(ImVec2(x0, p0.y));
  5293. }
  5294. else if (arc0_b == 0.0f && arc0_e == half_pi)
  5295. {
  5296. draw_list->PathArcToFast(ImVec2(x0, p1.y - rounding), rounding, 3, 6); // BL
  5297. draw_list->PathArcToFast(ImVec2(x0, p0.y + rounding), rounding, 6, 9); // TR
  5298. }
  5299. else
  5300. {
  5301. draw_list->PathArcTo(ImVec2(x0, p1.y - rounding), rounding, IM_PI - arc0_e, IM_PI - arc0_b); // BL
  5302. draw_list->PathArcTo(ImVec2(x0, p0.y + rounding), rounding, IM_PI + arc0_b, IM_PI + arc0_e); // TR
  5303. }
  5304. if (p1.x > rect.Min.x + rounding)
  5305. {
  5306. const float arc1_b = ImAcos01(1.0f - (rect.Max.x - p1.x) * inv_rounding);
  5307. const float arc1_e = ImAcos01(1.0f - (rect.Max.x - p0.x) * inv_rounding);
  5308. const float x1 = ImMin(p1.x, rect.Max.x - rounding);
  5309. if (arc1_b == arc1_e)
  5310. {
  5311. draw_list->PathLineTo(ImVec2(x1, p0.y));
  5312. draw_list->PathLineTo(ImVec2(x1, p1.y));
  5313. }
  5314. else if (arc1_b == 0.0f && arc1_e == half_pi)
  5315. {
  5316. draw_list->PathArcToFast(ImVec2(x1, p0.y + rounding), rounding, 9, 12); // TR
  5317. draw_list->PathArcToFast(ImVec2(x1, p1.y - rounding), rounding, 0, 3); // BR
  5318. }
  5319. else
  5320. {
  5321. draw_list->PathArcTo(ImVec2(x1, p0.y + rounding), rounding, -arc1_e, -arc1_b); // TR
  5322. draw_list->PathArcTo(ImVec2(x1, p1.y - rounding), rounding, +arc1_b, +arc1_e); // BR
  5323. }
  5324. }
  5325. draw_list->PathFillConvex(col);
  5326. }
  5327. void ImGui::RenderRectFilledWithHole(ImDrawList* draw_list, const ImRect& outer, const ImRect& inner, ImU32 col, float rounding)
  5328. {
  5329. const bool fill_L = (inner.Min.x > outer.Min.x);
  5330. const bool fill_R = (inner.Max.x < outer.Max.x);
  5331. const bool fill_U = (inner.Min.y > outer.Min.y);
  5332. const bool fill_D = (inner.Max.y < outer.Max.y);
  5333. if (fill_L) draw_list->AddRectFilled(ImVec2(outer.Min.x, inner.Min.y), ImVec2(inner.Min.x, inner.Max.y), col, rounding, ImDrawFlags_RoundCornersNone | (fill_U ? 0 : ImDrawFlags_RoundCornersTopLeft) | (fill_D ? 0 : ImDrawFlags_RoundCornersBottomLeft));
  5334. if (fill_R) draw_list->AddRectFilled(ImVec2(inner.Max.x, inner.Min.y), ImVec2(outer.Max.x, inner.Max.y), col, rounding, ImDrawFlags_RoundCornersNone | (fill_U ? 0 : ImDrawFlags_RoundCornersTopRight) | (fill_D ? 0 : ImDrawFlags_RoundCornersBottomRight));
  5335. if (fill_U) draw_list->AddRectFilled(ImVec2(inner.Min.x, outer.Min.y), ImVec2(inner.Max.x, inner.Min.y), col, rounding, ImDrawFlags_RoundCornersNone | (fill_L ? 0 : ImDrawFlags_RoundCornersTopLeft) | (fill_R ? 0 : ImDrawFlags_RoundCornersTopRight));
  5336. if (fill_D) draw_list->AddRectFilled(ImVec2(inner.Min.x, inner.Max.y), ImVec2(inner.Max.x, outer.Max.y), col, rounding, ImDrawFlags_RoundCornersNone | (fill_L ? 0 : ImDrawFlags_RoundCornersBottomLeft) | (fill_R ? 0 : ImDrawFlags_RoundCornersBottomRight));
  5337. if (fill_L && fill_U) draw_list->AddRectFilled(ImVec2(outer.Min.x, outer.Min.y), ImVec2(inner.Min.x, inner.Min.y), col, rounding, ImDrawFlags_RoundCornersTopLeft);
  5338. if (fill_R && fill_U) draw_list->AddRectFilled(ImVec2(inner.Max.x, outer.Min.y), ImVec2(outer.Max.x, inner.Min.y), col, rounding, ImDrawFlags_RoundCornersTopRight);
  5339. if (fill_L && fill_D) draw_list->AddRectFilled(ImVec2(outer.Min.x, inner.Max.y), ImVec2(inner.Min.x, outer.Max.y), col, rounding, ImDrawFlags_RoundCornersBottomLeft);
  5340. if (fill_R && fill_D) draw_list->AddRectFilled(ImVec2(inner.Max.x, inner.Max.y), ImVec2(outer.Max.x, outer.Max.y), col, rounding, ImDrawFlags_RoundCornersBottomRight);
  5341. }
  5342. // Helper for ColorPicker4()
  5343. // NB: This is rather brittle and will show artifact when rounding this enabled if rounded corners overlap multiple cells. Caller currently responsible for avoiding that.
  5344. // Spent a non reasonable amount of time trying to getting this right for ColorButton with rounding+anti-aliasing+ImGuiColorEditFlags_HalfAlphaPreview flag + various grid sizes and offsets, and eventually gave up... probably more reasonable to disable rounding altogether.
  5345. // FIXME: uses ImGui::GetColorU32
  5346. void ImGui::RenderColorRectWithAlphaCheckerboard(ImDrawList* draw_list, ImVec2 p_min, ImVec2 p_max, ImU32 col, float grid_step, ImVec2 grid_off, float rounding, ImDrawFlags flags)
  5347. {
  5348. if ((flags & ImDrawFlags_RoundCornersMask_) == 0)
  5349. flags = ImDrawFlags_RoundCornersDefault_;
  5350. if (((col & IM_COL32_A_MASK) >> IM_COL32_A_SHIFT) < 0xFF)
  5351. {
  5352. ImU32 col_bg1 = GetColorU32(ImAlphaBlendColors(IM_COL32(204, 204, 204, 255), col));
  5353. ImU32 col_bg2 = GetColorU32(ImAlphaBlendColors(IM_COL32(128, 128, 128, 255), col));
  5354. draw_list->AddRectFilled(p_min, p_max, col_bg1, rounding, flags);
  5355. int yi = 0;
  5356. for (float y = p_min.y + grid_off.y; y < p_max.y; y += grid_step, yi++)
  5357. {
  5358. float y1 = ImClamp(y, p_min.y, p_max.y), y2 = ImMin(y + grid_step, p_max.y);
  5359. if (y2 <= y1)
  5360. continue;
  5361. for (float x = p_min.x + grid_off.x + (yi & 1) * grid_step; x < p_max.x; x += grid_step * 2.0f)
  5362. {
  5363. float x1 = ImClamp(x, p_min.x, p_max.x), x2 = ImMin(x + grid_step, p_max.x);
  5364. if (x2 <= x1)
  5365. continue;
  5366. ImDrawFlags cell_flags = ImDrawFlags_RoundCornersNone;
  5367. if (y1 <= p_min.y) { if (x1 <= p_min.x) cell_flags |= ImDrawFlags_RoundCornersTopLeft; if (x2 >= p_max.x) cell_flags |= ImDrawFlags_RoundCornersTopRight; }
  5368. if (y2 >= p_max.y) { if (x1 <= p_min.x) cell_flags |= ImDrawFlags_RoundCornersBottomLeft; if (x2 >= p_max.x) cell_flags |= ImDrawFlags_RoundCornersBottomRight; }
  5369. // Combine flags
  5370. cell_flags = (flags == ImDrawFlags_RoundCornersNone || cell_flags == ImDrawFlags_RoundCornersNone) ? ImDrawFlags_RoundCornersNone : (cell_flags & flags);
  5371. draw_list->AddRectFilled(ImVec2(x1, y1), ImVec2(x2, y2), col_bg2, rounding, cell_flags);
  5372. }
  5373. }
  5374. }
  5375. else
  5376. {
  5377. draw_list->AddRectFilled(p_min, p_max, col, rounding, flags);
  5378. }
  5379. }
  5380. //-----------------------------------------------------------------------------
  5381. // [SECTION] Decompression code
  5382. //-----------------------------------------------------------------------------
  5383. // Compressed with stb_compress() then converted to a C array and encoded as base85.
  5384. // Use the program in misc/fonts/binary_to_compressed_c.cpp to create the array from a TTF file.
  5385. // The purpose of encoding as base85 instead of "0x00,0x01,..." style is only save on _source code_ size.
  5386. // Decompression from stb.h (public domain) by Sean Barrett https://github.com/nothings/stb/blob/master/stb.h
  5387. //-----------------------------------------------------------------------------
  5388. static unsigned int stb_decompress_length(const unsigned char *input)
  5389. {
  5390. return (input[8] << 24) + (input[9] << 16) + (input[10] << 8) + input[11];
  5391. }
  5392. static unsigned char *stb__barrier_out_e, *stb__barrier_out_b;
  5393. static const unsigned char *stb__barrier_in_b;
  5394. static unsigned char *stb__dout;
  5395. static void stb__match(const unsigned char *data, unsigned int length)
  5396. {
  5397. // INVERSE of memmove... write each byte before copying the next...
  5398. IM_ASSERT(stb__dout + length <= stb__barrier_out_e);
  5399. if (stb__dout + length > stb__barrier_out_e) { stb__dout += length; return; }
  5400. if (data < stb__barrier_out_b) { stb__dout = stb__barrier_out_e+1; return; }
  5401. while (length--) *stb__dout++ = *data++;
  5402. }
  5403. static void stb__lit(const unsigned char *data, unsigned int length)
  5404. {
  5405. IM_ASSERT(stb__dout + length <= stb__barrier_out_e);
  5406. if (stb__dout + length > stb__barrier_out_e) { stb__dout += length; return; }
  5407. if (data < stb__barrier_in_b) { stb__dout = stb__barrier_out_e+1; return; }
  5408. memcpy(stb__dout, data, length);
  5409. stb__dout += length;
  5410. }
  5411. #define stb__in2(x) ((i[x] << 8) + i[(x)+1])
  5412. #define stb__in3(x) ((i[x] << 16) + stb__in2((x)+1))
  5413. #define stb__in4(x) ((i[x] << 24) + stb__in3((x)+1))
  5414. static const unsigned char *stb_decompress_token(const unsigned char *i)
  5415. {
  5416. if (*i >= 0x20) { // use fewer if's for cases that expand small
  5417. if (*i >= 0x80) stb__match(stb__dout-i[1]-1, i[0] - 0x80 + 1), i += 2;
  5418. else if (*i >= 0x40) stb__match(stb__dout-(stb__in2(0) - 0x4000 + 1), i[2]+1), i += 3;
  5419. else /* *i >= 0x20 */ stb__lit(i+1, i[0] - 0x20 + 1), i += 1 + (i[0] - 0x20 + 1);
  5420. } else { // more ifs for cases that expand large, since overhead is amortized
  5421. if (*i >= 0x18) stb__match(stb__dout-(stb__in3(0) - 0x180000 + 1), i[3]+1), i += 4;
  5422. else if (*i >= 0x10) stb__match(stb__dout-(stb__in3(0) - 0x100000 + 1), stb__in2(3)+1), i += 5;
  5423. else if (*i >= 0x08) stb__lit(i+2, stb__in2(0) - 0x0800 + 1), i += 2 + (stb__in2(0) - 0x0800 + 1);
  5424. else if (*i == 0x07) stb__lit(i+3, stb__in2(1) + 1), i += 3 + (stb__in2(1) + 1);
  5425. else if (*i == 0x06) stb__match(stb__dout-(stb__in3(1)+1), i[4]+1), i += 5;
  5426. else if (*i == 0x04) stb__match(stb__dout-(stb__in3(1)+1), stb__in2(4)+1), i += 6;
  5427. }
  5428. return i;
  5429. }
  5430. static unsigned int stb_adler32(unsigned int adler32, unsigned char *buffer, unsigned int buflen)
  5431. {
  5432. const unsigned long ADLER_MOD = 65521;
  5433. unsigned long s1 = adler32 & 0xffff, s2 = adler32 >> 16;
  5434. unsigned long blocklen = buflen % 5552;
  5435. unsigned long i;
  5436. while (buflen) {
  5437. for (i=0; i + 7 < blocklen; i += 8) {
  5438. s1 += buffer[0], s2 += s1;
  5439. s1 += buffer[1], s2 += s1;
  5440. s1 += buffer[2], s2 += s1;
  5441. s1 += buffer[3], s2 += s1;
  5442. s1 += buffer[4], s2 += s1;
  5443. s1 += buffer[5], s2 += s1;
  5444. s1 += buffer[6], s2 += s1;
  5445. s1 += buffer[7], s2 += s1;
  5446. buffer += 8;
  5447. }
  5448. for (; i < blocklen; ++i)
  5449. s1 += *buffer++, s2 += s1;
  5450. s1 %= ADLER_MOD, s2 %= ADLER_MOD;
  5451. buflen -= blocklen;
  5452. blocklen = 5552;
  5453. }
  5454. return (unsigned int)(s2 << 16) + (unsigned int)s1;
  5455. }
  5456. static unsigned int stb_decompress(unsigned char *output, const unsigned char *i, unsigned int /*length*/)
  5457. {
  5458. if (stb__in4(0) != 0x57bC0000) return 0;
  5459. if (stb__in4(4) != 0) return 0; // error! stream is > 4GB
  5460. const unsigned int olen = stb_decompress_length(i);
  5461. stb__barrier_in_b = i;
  5462. stb__barrier_out_e = output + olen;
  5463. stb__barrier_out_b = output;
  5464. i += 16;
  5465. stb__dout = output;
  5466. for (;;) {
  5467. const unsigned char *old_i = i;
  5468. i = stb_decompress_token(i);
  5469. if (i == old_i) {
  5470. if (*i == 0x05 && i[1] == 0xfa) {
  5471. IM_ASSERT(stb__dout == output + olen);
  5472. if (stb__dout != output + olen) return 0;
  5473. if (stb_adler32(1, output, olen) != (unsigned int) stb__in4(2))
  5474. return 0;
  5475. return olen;
  5476. } else {
  5477. IM_ASSERT(0); /* NOTREACHED */
  5478. return 0;
  5479. }
  5480. }
  5481. IM_ASSERT(stb__dout <= output + olen);
  5482. if (stb__dout > output + olen)
  5483. return 0;
  5484. }
  5485. }
  5486. //-----------------------------------------------------------------------------
  5487. // [SECTION] Default font data (ProggyClean.ttf)
  5488. //-----------------------------------------------------------------------------
  5489. // ProggyClean.ttf
  5490. // Copyright (c) 2004, 2005 Tristan Grimmer
  5491. // MIT license (see License.txt in http://www.proggyfonts.net/index.php?menu=download)
  5492. // Download and more information at http://www.proggyfonts.net or http://upperboundsinteractive.com/fonts.php
  5493. //-----------------------------------------------------------------------------
  5494. #ifndef IMGUI_DISABLE_DEFAULT_FONT
  5495. // File: 'ProggyClean.ttf' (41208 bytes)
  5496. // Exported using binary_to_compressed_c.exe -u8 "ProggyClean.ttf" proggy_clean_ttf
  5497. static const unsigned int proggy_clean_ttf_compressed_size = 9583;
  5498. static const unsigned char proggy_clean_ttf_compressed_data[9583] =
  5499. {
  5500. 87,188,0,0,0,0,0,0,0,0,160,248,0,4,0,0,55,0,1,0,0,0,12,0,128,0,3,0,64,79,83,47,50,136,235,116,144,0,0,1,72,130,21,44,78,99,109,97,112,2,18,35,117,0,0,3,160,130,19,36,82,99,118,116,
  5501. 32,130,23,130,2,33,4,252,130,4,56,2,103,108,121,102,18,175,137,86,0,0,7,4,0,0,146,128,104,101,97,100,215,145,102,211,130,27,32,204,130,3,33,54,104,130,16,39,8,66,1,195,0,0,1,4,130,
  5502. 15,59,36,104,109,116,120,138,0,126,128,0,0,1,152,0,0,2,6,108,111,99,97,140,115,176,216,0,0,5,130,30,41,2,4,109,97,120,112,1,174,0,218,130,31,32,40,130,16,44,32,110,97,109,101,37,89,
  5503. 187,150,0,0,153,132,130,19,44,158,112,111,115,116,166,172,131,239,0,0,155,36,130,51,44,210,112,114,101,112,105,2,1,18,0,0,4,244,130,47,32,8,132,203,46,1,0,0,60,85,233,213,95,15,60,
  5504. 245,0,3,8,0,131,0,34,183,103,119,130,63,43,0,0,189,146,166,215,0,0,254,128,3,128,131,111,130,241,33,2,0,133,0,32,1,130,65,38,192,254,64,0,0,3,128,131,16,130,5,32,1,131,7,138,3,33,2,
  5505. 0,130,17,36,1,1,0,144,0,130,121,130,23,38,2,0,8,0,64,0,10,130,9,32,118,130,9,130,6,32,0,130,59,33,1,144,131,200,35,2,188,2,138,130,16,32,143,133,7,37,1,197,0,50,2,0,131,0,33,4,9,131,
  5506. 5,145,3,43,65,108,116,115,0,64,0,0,32,172,8,0,131,0,35,5,0,1,128,131,77,131,3,33,3,128,191,1,33,1,128,130,184,35,0,0,128,0,130,3,131,11,32,1,130,7,33,0,128,131,1,32,1,136,9,32,0,132,
  5507. 15,135,5,32,1,131,13,135,27,144,35,32,1,149,25,131,21,32,0,130,0,32,128,132,103,130,35,132,39,32,0,136,45,136,97,133,17,130,5,33,0,0,136,19,34,0,128,1,133,13,133,5,32,128,130,15,132,
  5508. 131,32,3,130,5,32,3,132,27,144,71,32,0,133,27,130,29,130,31,136,29,131,63,131,3,65,63,5,132,5,132,205,130,9,33,0,0,131,9,137,119,32,3,132,19,138,243,130,55,32,1,132,35,135,19,131,201,
  5509. 136,11,132,143,137,13,130,41,32,0,131,3,144,35,33,128,0,135,1,131,223,131,3,141,17,134,13,136,63,134,15,136,53,143,15,130,96,33,0,3,131,4,130,3,34,28,0,1,130,5,34,0,0,76,130,17,131,
  5510. 9,36,28,0,4,0,48,130,17,46,8,0,8,0,2,0,0,0,127,0,255,32,172,255,255,130,9,34,0,0,129,132,9,130,102,33,223,213,134,53,132,22,33,1,6,132,6,64,4,215,32,129,165,216,39,177,0,1,141,184,
  5511. 1,255,133,134,45,33,198,0,193,1,8,190,244,1,28,1,158,2,20,2,136,2,252,3,20,3,88,3,156,3,222,4,20,4,50,4,80,4,98,4,162,5,22,5,102,5,188,6,18,6,116,6,214,7,56,7,126,7,236,8,78,8,108,
  5512. 8,150,8,208,9,16,9,74,9,136,10,22,10,128,11,4,11,86,11,200,12,46,12,130,12,234,13,94,13,164,13,234,14,80,14,150,15,40,15,176,16,18,16,116,16,224,17,82,17,182,18,4,18,110,18,196,19,
  5513. 76,19,172,19,246,20,88,20,174,20,234,21,64,21,128,21,166,21,184,22,18,22,126,22,198,23,52,23,142,23,224,24,86,24,186,24,238,25,54,25,150,25,212,26,72,26,156,26,240,27,92,27,200,28,
  5514. 4,28,76,28,150,28,234,29,42,29,146,29,210,30,64,30,142,30,224,31,36,31,118,31,166,31,166,32,16,130,1,52,46,32,138,32,178,32,200,33,20,33,116,33,152,33,238,34,98,34,134,35,12,130,1,
  5515. 33,128,35,131,1,60,152,35,176,35,216,36,0,36,74,36,104,36,144,36,174,37,6,37,96,37,130,37,248,37,248,38,88,38,170,130,1,8,190,216,39,64,39,154,40,10,40,104,40,168,41,14,41,32,41,184,
  5516. 41,248,42,54,42,96,42,96,43,2,43,42,43,94,43,172,43,230,44,32,44,52,44,154,45,40,45,92,45,120,45,170,45,232,46,38,46,166,47,38,47,182,47,244,48,94,48,200,49,62,49,180,50,30,50,158,
  5517. 51,30,51,130,51,238,52,92,52,206,53,58,53,134,53,212,54,38,54,114,54,230,55,118,55,216,56,58,56,166,57,18,57,116,57,174,58,46,58,154,59,6,59,124,59,232,60,58,60,150,61,34,61,134,61,
  5518. 236,62,86,62,198,63,42,63,154,64,18,64,106,64,208,65,54,65,162,66,8,66,64,66,122,66,184,66,240,67,98,67,204,68,42,68,138,68,238,69,88,69,182,69,226,70,84,70,180,71,20,71,122,71,218,
  5519. 72,84,72,198,73,64,0,36,70,21,8,8,77,3,0,7,0,11,0,15,0,19,0,23,0,27,0,31,0,35,0,39,0,43,0,47,0,51,0,55,0,59,0,63,0,67,0,71,0,75,0,79,0,83,0,87,0,91,0,95,0,99,0,103,0,107,0,111,0,115,
  5520. 0,119,0,123,0,127,0,131,0,135,0,139,0,143,0,0,17,53,51,21,49,150,3,32,5,130,23,32,33,130,3,211,7,151,115,32,128,133,0,37,252,128,128,2,128,128,190,5,133,74,32,4,133,6,206,5,42,0,7,
  5521. 1,128,0,0,2,0,4,0,0,65,139,13,37,0,1,53,51,21,7,146,3,32,3,130,19,32,1,141,133,32,3,141,14,131,13,38,255,0,128,128,0,6,1,130,84,35,2,128,4,128,140,91,132,89,32,51,65,143,6,139,7,33,
  5522. 1,0,130,57,32,254,130,3,32,128,132,4,32,4,131,14,138,89,35,0,0,24,0,130,0,33,3,128,144,171,66,55,33,148,115,65,187,19,32,5,130,151,143,155,163,39,32,1,136,182,32,253,134,178,132,7,
  5523. 132,200,145,17,32,3,65,48,17,165,17,39,0,0,21,0,128,255,128,3,65,175,17,65,3,27,132,253,131,217,139,201,155,233,155,27,131,67,131,31,130,241,33,255,0,131,181,137,232,132,15,132,4,138,
  5524. 247,34,255,0,128,179,238,32,0,130,0,32,20,65,239,48,33,0,19,67,235,10,32,51,65,203,14,65,215,11,32,7,154,27,135,39,32,33,130,35,33,128,128,130,231,32,253,132,231,32,128,132,232,34,
  5525. 128,128,254,133,13,136,8,32,253,65,186,5,130,36,130,42,176,234,133,231,34,128,0,0,66,215,44,33,0,1,68,235,6,68,211,19,32,49,68,239,14,139,207,139,47,66,13,7,32,51,130,47,33,1,0,130,
  5526. 207,35,128,128,1,0,131,222,131,5,130,212,130,6,131,212,32,0,130,10,133,220,130,233,130,226,32,254,133,255,178,233,39,3,1,128,3,0,2,0,4,68,15,7,68,99,12,130,89,130,104,33,128,4,133,
  5527. 93,130,10,38,0,0,11,1,0,255,0,68,63,16,70,39,9,66,215,8,32,7,68,77,6,68,175,14,32,29,68,195,6,132,7,35,2,0,128,255,131,91,132,4,65,178,5,141,111,67,129,23,165,135,140,107,142,135,33,
  5528. 21,5,69,71,6,131,7,33,1,0,140,104,132,142,130,4,137,247,140,30,68,255,12,39,11,0,128,0,128,3,0,3,69,171,15,67,251,7,65,15,8,66,249,11,65,229,7,67,211,7,66,13,7,35,1,128,128,254,133,
  5529. 93,32,254,131,145,132,4,132,18,32,2,151,128,130,23,34,0,0,9,154,131,65,207,8,68,107,15,68,51,7,32,7,70,59,7,135,121,130,82,32,128,151,111,41,0,0,4,0,128,255,0,1,128,1,137,239,33,0,
  5530. 37,70,145,10,65,77,10,65,212,14,37,0,0,0,5,0,128,66,109,5,70,123,10,33,0,19,72,33,18,133,237,70,209,11,33,0,2,130,113,137,119,136,115,33,1,0,133,43,130,5,34,0,0,10,69,135,6,70,219,
  5531. 13,66,155,7,65,9,12,66,157,11,66,9,11,32,7,130,141,132,252,66,151,9,137,9,66,15,30,36,0,20,0,128,0,130,218,71,11,42,68,51,8,65,141,7,73,19,15,69,47,23,143,39,66,81,7,32,1,66,55,6,34,
  5532. 1,128,128,68,25,5,69,32,6,137,6,136,25,32,254,131,42,32,3,66,88,26,148,26,32,0,130,0,32,14,164,231,70,225,12,66,233,7,67,133,19,71,203,15,130,161,32,255,130,155,32,254,139,127,134,
  5533. 12,164,174,33,0,15,164,159,33,59,0,65,125,20,66,25,7,32,5,68,191,6,66,29,7,144,165,65,105,9,35,128,128,255,0,137,2,133,182,164,169,33,128,128,197,171,130,155,68,235,7,32,21,70,77,19,
  5534. 66,21,10,68,97,8,66,30,5,66,4,43,34,0,17,0,71,19,41,65,253,20,71,25,23,65,91,15,65,115,7,34,2,128,128,66,9,8,130,169,33,1,0,66,212,13,132,28,72,201,43,35,0,0,0,18,66,27,38,76,231,5,
  5535. 68,157,20,135,157,32,7,68,185,13,65,129,28,66,20,5,32,253,66,210,11,65,128,49,133,61,32,0,65,135,6,74,111,37,72,149,12,66,203,19,65,147,19,68,93,7,68,85,8,76,4,5,33,255,0,133,129,34,
  5536. 254,0,128,68,69,8,181,197,34,0,0,12,65,135,32,65,123,20,69,183,27,133,156,66,50,5,72,87,10,67,137,32,33,0,19,160,139,78,251,13,68,55,20,67,119,19,65,91,36,69,177,15,32,254,143,16,65,
  5537. 98,53,32,128,130,0,32,0,66,43,54,70,141,23,66,23,15,131,39,69,47,11,131,15,70,129,19,74,161,9,36,128,255,0,128,254,130,153,65,148,32,67,41,9,34,0,0,4,79,15,5,73,99,10,71,203,8,32,3,
  5538. 72,123,6,72,43,8,32,2,133,56,131,99,130,9,34,0,0,6,72,175,5,73,159,14,144,63,135,197,132,189,133,66,33,255,0,73,6,7,70,137,12,35,0,0,0,10,130,3,73,243,25,67,113,12,65,73,7,69,161,7,
  5539. 138,7,37,21,2,0,128,128,254,134,3,73,116,27,33,128,128,130,111,39,12,0,128,1,0,3,128,2,72,219,21,35,43,0,47,0,67,47,20,130,111,33,21,1,68,167,13,81,147,8,133,230,32,128,77,73,6,32,
  5540. 128,131,142,134,18,130,6,32,255,75,18,12,131,243,37,128,0,128,3,128,3,74,231,21,135,123,32,29,134,107,135,7,32,21,74,117,7,135,7,134,96,135,246,74,103,23,132,242,33,0,10,67,151,28,
  5541. 67,133,20,66,141,11,131,11,32,3,77,71,6,32,128,130,113,32,1,81,4,6,134,218,66,130,24,131,31,34,0,26,0,130,0,77,255,44,83,15,11,148,155,68,13,7,32,49,78,231,18,79,7,11,73,243,11,32,
  5542. 33,65,187,10,130,63,65,87,8,73,239,19,35,0,128,1,0,131,226,32,252,65,100,6,32,128,139,8,33,1,0,130,21,32,253,72,155,44,73,255,20,32,128,71,67,8,81,243,39,67,15,20,74,191,23,68,121,
  5543. 27,32,1,66,150,6,32,254,79,19,11,131,214,32,128,130,215,37,2,0,128,253,0,128,136,5,65,220,24,147,212,130,210,33,0,24,72,219,42,84,255,13,67,119,16,69,245,19,72,225,19,65,3,15,69,93,
  5544. 19,131,55,132,178,71,115,14,81,228,6,142,245,33,253,0,132,43,172,252,65,16,11,75,219,8,65,219,31,66,223,24,75,223,10,33,29,1,80,243,10,66,175,8,131,110,134,203,133,172,130,16,70,30,
  5545. 7,164,183,130,163,32,20,65,171,48,65,163,36,65,143,23,65,151,19,65,147,13,65,134,17,133,17,130,216,67,114,5,164,217,65,137,12,72,147,48,79,71,19,74,169,22,80,251,8,65,173,7,66,157,
  5546. 15,74,173,15,32,254,65,170,8,71,186,45,72,131,6,77,143,40,187,195,152,179,65,123,38,68,215,57,68,179,15,65,85,7,69,187,14,32,21,66,95,15,67,19,25,32,1,83,223,6,32,2,76,240,7,77,166,
  5547. 43,65,8,5,130,206,32,0,67,39,54,143,167,66,255,19,82,193,11,151,47,85,171,5,67,27,17,132,160,69,172,11,69,184,56,66,95,6,33,12,1,130,237,32,2,68,179,27,68,175,16,80,135,15,72,55,7,
  5548. 71,87,12,73,3,12,132,12,66,75,32,76,215,5,169,139,147,135,148,139,81,12,12,81,185,36,75,251,7,65,23,27,76,215,9,87,165,12,65,209,15,72,157,7,65,245,31,32,128,71,128,6,32,1,82,125,5,
  5549. 34,0,128,254,131,169,32,254,131,187,71,180,9,132,27,32,2,88,129,44,32,0,78,47,40,65,79,23,79,171,14,32,21,71,87,8,72,15,14,65,224,33,130,139,74,27,62,93,23,7,68,31,7,75,27,7,139,15,
  5550. 74,3,7,74,23,27,65,165,11,65,177,15,67,123,5,32,1,130,221,32,252,71,96,5,74,12,12,133,244,130,25,34,1,0,128,130,2,139,8,93,26,8,65,9,32,65,57,14,140,14,32,0,73,79,67,68,119,11,135,
  5551. 11,32,51,90,75,14,139,247,65,43,7,131,19,139,11,69,159,11,65,247,6,36,1,128,128,253,0,90,71,9,33,1,0,132,14,32,128,89,93,14,69,133,6,130,44,131,30,131,6,65,20,56,33,0,16,72,179,40,
  5552. 75,47,12,65,215,19,74,95,19,65,43,11,131,168,67,110,5,75,23,17,69,106,6,75,65,5,71,204,43,32,0,80,75,47,71,203,15,159,181,68,91,11,67,197,7,73,101,13,68,85,6,33,128,128,130,214,130,
  5553. 25,32,254,74,236,48,130,194,37,0,18,0,128,255,128,77,215,40,65,139,64,32,51,80,159,10,65,147,39,130,219,84,212,43,130,46,75,19,97,74,33,11,65,201,23,65,173,31,33,1,0,79,133,6,66,150,
  5554. 5,67,75,48,85,187,6,70,207,37,32,71,87,221,13,73,163,14,80,167,15,132,15,83,193,19,82,209,8,78,99,9,72,190,11,77,110,49,89,63,5,80,91,35,99,63,32,70,235,23,81,99,10,69,148,10,65,110,
  5555. 36,32,0,65,99,47,95,219,11,68,171,51,66,87,7,72,57,7,74,45,17,143,17,65,114,50,33,14,0,65,111,40,159,195,98,135,15,35,7,53,51,21,100,78,9,95,146,16,32,254,82,114,6,32,128,67,208,37,
  5556. 130,166,99,79,58,32,17,96,99,14,72,31,19,72,87,31,82,155,7,67,47,14,32,21,131,75,134,231,72,51,17,72,78,8,133,8,80,133,6,33,253,128,88,37,9,66,124,36,72,65,12,134,12,71,55,43,66,139,
  5557. 27,85,135,10,91,33,12,65,35,11,66,131,11,71,32,8,90,127,6,130,244,71,76,11,168,207,33,0,12,66,123,32,32,0,65,183,15,68,135,11,66,111,7,67,235,11,66,111,15,32,254,97,66,12,160,154,67,
  5558. 227,52,80,33,15,87,249,15,93,45,31,75,111,12,93,45,11,77,99,9,160,184,81,31,12,32,15,98,135,30,104,175,7,77,249,36,69,73,15,78,5,12,32,254,66,151,19,34,128,128,4,87,32,12,149,35,133,
  5559. 21,96,151,31,32,19,72,35,5,98,173,15,143,15,32,21,143,99,158,129,33,0,0,65,35,52,65,11,15,147,15,98,75,11,33,1,0,143,151,132,15,32,254,99,200,37,132,43,130,4,39,0,10,0,128,1,128,3,
  5560. 0,104,151,14,97,187,20,69,131,15,67,195,11,87,227,7,33,128,128,132,128,33,254,0,68,131,9,65,46,26,42,0,0,0,7,0,0,255,128,3,128,0,88,223,15,33,0,21,89,61,22,66,209,12,65,2,12,37,0,2,
  5561. 1,0,3,128,101,83,8,36,0,1,53,51,29,130,3,34,21,1,0,66,53,8,32,0,68,215,6,100,55,25,107,111,9,66,193,11,72,167,8,73,143,31,139,31,33,1,0,131,158,32,254,132,5,33,253,128,65,16,9,133,
  5562. 17,89,130,25,141,212,33,0,0,93,39,8,90,131,25,93,39,14,66,217,6,106,179,8,159,181,71,125,15,139,47,138,141,87,11,14,76,23,14,65,231,26,140,209,66,122,8,81,179,5,101,195,26,32,47,74,
  5563. 75,13,69,159,11,83,235,11,67,21,16,136,167,131,106,130,165,130,15,32,128,101,90,24,134,142,32,0,65,103,51,108,23,11,101,231,15,75,173,23,74,237,23,66,15,6,66,46,17,66,58,17,65,105,
  5564. 49,66,247,55,71,179,12,70,139,15,86,229,7,84,167,15,32,1,95,72,12,89,49,6,33,128,128,65,136,38,66,30,9,32,0,100,239,7,66,247,29,70,105,20,65,141,19,69,81,15,130,144,32,128,83,41,5,
  5565. 32,255,131,177,68,185,5,133,126,65,97,37,32,0,130,0,33,21,0,130,55,66,195,28,67,155,13,34,79,0,83,66,213,13,73,241,19,66,59,19,65,125,11,135,201,66,249,16,32,128,66,44,11,66,56,17,
  5566. 68,143,8,68,124,38,67,183,12,96,211,9,65,143,29,112,171,5,32,0,68,131,63,34,33,53,51,71,121,11,32,254,98,251,16,32,253,74,231,10,65,175,37,133,206,37,0,0,8,1,0,0,107,123,11,113,115,
  5567. 9,33,0,1,130,117,131,3,73,103,7,66,51,18,66,44,5,133,75,70,88,5,32,254,65,39,12,68,80,9,34,12,0,128,107,179,28,68,223,6,155,111,86,147,15,32,2,131,82,141,110,33,254,0,130,15,32,4,103,
  5568. 184,15,141,35,87,176,5,83,11,5,71,235,23,114,107,11,65,189,16,70,33,15,86,153,31,135,126,86,145,30,65,183,41,32,0,130,0,32,10,65,183,24,34,35,0,39,67,85,9,65,179,15,143,15,33,1,0,65,
  5569. 28,17,157,136,130,123,32,20,130,3,32,0,97,135,24,115,167,19,80,71,12,32,51,110,163,14,78,35,19,131,19,155,23,77,229,8,78,9,17,151,17,67,231,46,94,135,8,73,31,31,93,215,56,82,171,25,
  5570. 72,77,8,162,179,169,167,99,131,11,69,85,19,66,215,15,76,129,13,68,115,22,72,79,35,67,113,5,34,0,0,19,70,31,46,65,89,52,73,223,15,85,199,33,95,33,8,132,203,73,29,32,67,48,16,177,215,
  5571. 101,13,15,65,141,43,69,141,15,75,89,5,70,0,11,70,235,21,178,215,36,10,0,128,0,0,71,207,24,33,0,19,100,67,6,80,215,11,66,67,7,80,43,12,71,106,7,80,192,5,65,63,5,66,217,26,33,0,13,156,
  5572. 119,68,95,5,72,233,12,134,129,85,81,11,76,165,20,65,43,8,73,136,8,75,10,31,38,128,128,0,0,0,13,1,130,4,32,3,106,235,29,114,179,12,66,131,23,32,7,77,133,6,67,89,12,131,139,116,60,9,
  5573. 89,15,37,32,0,74,15,7,103,11,22,65,35,5,33,55,0,93,81,28,67,239,23,78,85,5,107,93,14,66,84,17,65,193,26,74,183,10,66,67,34,143,135,79,91,15,32,7,117,111,8,75,56,9,84,212,9,154,134,
  5574. 32,0,130,0,32,18,130,3,70,171,41,83,7,16,70,131,19,84,191,15,84,175,19,84,167,30,84,158,12,154,193,68,107,15,33,0,0,65,79,42,65,71,7,73,55,7,118,191,16,83,180,9,32,255,76,166,9,154,
  5575. 141,32,0,130,0,69,195,52,65,225,15,151,15,75,215,31,80,56,10,68,240,17,100,32,9,70,147,39,65,93,12,71,71,41,92,85,15,84,135,23,78,35,15,110,27,10,84,125,8,107,115,29,136,160,38,0,0,
  5576. 14,0,128,255,0,82,155,24,67,239,8,119,255,11,69,131,11,77,29,6,112,31,8,134,27,105,203,8,32,2,75,51,11,75,195,12,74,13,29,136,161,37,128,0,0,0,11,1,130,163,82,115,8,125,191,17,69,35,
  5577. 12,74,137,15,143,15,32,1,65,157,12,136,12,161,142,65,43,40,65,199,6,65,19,24,102,185,11,76,123,11,99,6,12,135,12,32,254,130,8,161,155,101,23,9,39,8,0,0,1,128,3,128,2,78,63,17,72,245,
  5578. 12,67,41,11,90,167,9,32,128,97,49,9,32,128,109,51,14,132,97,81,191,8,130,97,125,99,12,121,35,9,127,75,15,71,79,12,81,151,23,87,97,7,70,223,15,80,245,16,105,97,15,32,254,113,17,6,32,
  5579. 128,130,8,105,105,8,76,122,18,65,243,21,74,63,7,38,4,1,0,255,0,2,0,119,247,28,133,65,32,255,141,91,35,0,0,0,16,67,63,36,34,59,0,63,77,59,9,119,147,11,143,241,66,173,15,66,31,11,67,
  5580. 75,8,81,74,16,32,128,131,255,87,181,42,127,43,5,34,255,128,2,120,235,11,37,19,0,23,0,0,37,109,191,14,118,219,7,127,43,14,65,79,14,35,0,0,0,3,73,91,5,130,5,38,3,0,7,0,11,0,0,70,205,
  5581. 11,88,221,12,32,0,73,135,7,87,15,22,73,135,10,79,153,15,97,71,19,65,49,11,32,1,131,104,121,235,11,80,65,11,142,179,144,14,81,123,46,32,1,88,217,5,112,5,8,65,201,15,83,29,15,122,147,
  5582. 11,135,179,142,175,143,185,67,247,39,66,199,7,35,5,0,128,3,69,203,15,123,163,12,67,127,7,130,119,71,153,10,141,102,70,175,8,32,128,121,235,30,136,89,100,191,11,116,195,11,111,235,15,
  5583. 72,39,7,32,2,97,43,5,132,5,94,67,8,131,8,125,253,10,32,3,65,158,16,146,16,130,170,40,0,21,0,128,0,0,3,128,5,88,219,15,24,64,159,32,135,141,65,167,15,68,163,10,97,73,49,32,255,82,58,
  5584. 7,93,80,8,97,81,16,24,67,87,52,34,0,0,5,130,231,33,128,2,80,51,13,65,129,8,113,61,6,132,175,65,219,5,130,136,77,152,17,32,0,95,131,61,70,215,6,33,21,51,90,53,10,78,97,23,105,77,31,
  5585. 65,117,7,139,75,24,68,195,9,24,64,22,9,33,0,128,130,11,33,128,128,66,25,5,121,38,5,134,5,134,45,66,40,36,66,59,18,34,128,0,0,66,59,81,135,245,123,103,19,120,159,19,77,175,12,33,255,
  5586. 0,87,29,10,94,70,21,66,59,54,39,3,1,128,3,0,2,128,4,24,65,7,15,66,47,7,72,98,12,37,0,0,0,3,1,0,24,65,55,21,131,195,32,1,67,178,6,33,4,0,77,141,8,32,6,131,47,74,67,16,24,69,3,20,24,
  5587. 65,251,7,133,234,130,229,94,108,17,35,0,0,6,0,141,175,86,59,5,162,79,85,166,8,70,112,13,32,13,24,64,67,26,24,71,255,7,123,211,12,80,121,11,69,215,15,66,217,11,69,71,10,131,113,132,
  5588. 126,119,90,9,66,117,19,132,19,32,0,130,0,24,64,47,59,33,7,0,73,227,5,68,243,15,85,13,12,76,37,22,74,254,15,130,138,33,0,4,65,111,6,137,79,65,107,16,32,1,77,200,6,34,128,128,3,75,154,
  5589. 12,37,0,16,0,0,2,0,104,115,36,140,157,68,67,19,68,51,15,106,243,15,134,120,70,37,10,68,27,10,140,152,65,121,24,32,128,94,155,7,67,11,8,24,74,11,25,65,3,12,83,89,18,82,21,37,67,200,
  5590. 5,130,144,24,64,172,12,33,4,0,134,162,74,80,14,145,184,32,0,130,0,69,251,20,32,19,81,243,5,82,143,8,33,5,53,89,203,5,133,112,79,109,15,33,0,21,130,71,80,175,41,36,75,0,79,0,83,121,
  5591. 117,9,87,89,27,66,103,11,70,13,15,75,191,11,135,67,87,97,20,109,203,5,69,246,8,108,171,5,78,195,38,65,51,13,107,203,11,77,3,17,24,75,239,17,65,229,28,79,129,39,130,175,32,128,123,253,
  5592. 7,132,142,24,65,51,15,65,239,41,36,128,128,0,0,13,65,171,5,66,163,28,136,183,118,137,11,80,255,15,67,65,7,74,111,8,32,0,130,157,32,253,24,76,35,10,103,212,5,81,175,9,69,141,7,66,150,
  5593. 29,131,158,24,75,199,28,124,185,7,76,205,15,68,124,14,32,3,123,139,16,130,16,33,128,128,108,199,6,33,0,3,65,191,35,107,11,6,73,197,11,24,70,121,15,83,247,15,24,70,173,23,69,205,14,
  5594. 32,253,131,140,32,254,136,4,94,198,9,32,3,78,4,13,66,127,13,143,13,32,0,130,0,33,16,0,24,69,59,39,109,147,12,76,253,19,24,69,207,15,69,229,15,130,195,71,90,10,139,10,130,152,73,43,
  5595. 40,91,139,10,65,131,37,35,75,0,79,0,84,227,12,143,151,68,25,15,80,9,23,95,169,11,34,128,2,128,112,186,5,130,6,83,161,19,76,50,6,130,37,65,145,44,110,83,5,32,16,67,99,6,71,67,15,76,
  5596. 55,17,140,215,67,97,23,76,69,15,77,237,11,104,211,23,77,238,11,65,154,43,33,0,10,83,15,28,83,13,20,67,145,19,67,141,14,97,149,21,68,9,15,86,251,5,66,207,5,66,27,37,82,1,23,127,71,12,
  5597. 94,235,10,110,175,24,98,243,15,132,154,132,4,24,66,69,10,32,4,67,156,43,130,198,35,2,1,0,4,75,27,9,69,85,9,95,240,7,32,128,130,35,32,28,66,43,40,24,82,63,23,83,123,12,72,231,15,127,
  5598. 59,23,116,23,19,117,71,7,24,77,99,15,67,111,15,71,101,8,36,2,128,128,252,128,127,60,11,32,1,132,16,130,18,141,24,67,107,9,32,3,68,194,15,175,15,38,0,11,0,128,1,128,2,80,63,25,32,0,
  5599. 24,65,73,11,69,185,15,83,243,16,32,0,24,81,165,8,130,86,77,35,6,155,163,88,203,5,24,66,195,30,70,19,19,24,80,133,15,32,1,75,211,8,32,254,108,133,8,79,87,20,65,32,9,41,0,0,7,0,128,0,
  5600. 0,2,128,2,68,87,15,66,1,16,92,201,16,24,76,24,17,133,17,34,128,0,30,66,127,64,34,115,0,119,73,205,9,66,43,11,109,143,15,24,79,203,11,90,143,15,131,15,155,31,65,185,15,86,87,11,35,128,
  5601. 128,253,0,69,7,6,130,213,33,1,0,119,178,15,142,17,66,141,74,83,28,6,36,7,0,0,4,128,82,39,18,76,149,12,67,69,21,32,128,79,118,15,32,0,130,0,32,8,131,206,32,2,79,83,9,100,223,14,102,
  5602. 113,23,115,115,7,24,65,231,12,130,162,32,4,68,182,19,130,102,93,143,8,69,107,29,24,77,255,12,143,197,72,51,7,76,195,15,132,139,85,49,15,130,152,131,18,71,81,23,70,14,11,36,0,10,0,128,
  5603. 2,69,59,9,89,151,15,66,241,11,76,165,12,71,43,15,75,49,13,65,12,23,132,37,32,0,179,115,130,231,95,181,16,132,77,32,254,67,224,8,65,126,20,79,171,8,32,2,89,81,5,75,143,6,80,41,8,34,
  5604. 2,0,128,24,81,72,9,32,0,130,0,35,17,0,0,255,77,99,39,95,65,36,67,109,15,24,69,93,11,77,239,5,95,77,23,35,128,1,0,128,24,86,7,8,132,167,32,2,69,198,41,130,202,33,0,26,120,75,44,24,89,
  5605. 51,15,71,243,12,70,239,11,24,84,3,11,66,7,11,71,255,10,32,21,69,155,35,88,151,12,32,128,74,38,10,65,210,8,74,251,5,65,226,5,75,201,13,32,3,65,9,41,146,41,40,0,0,0,9,1,0,1,0,2,91,99,
  5606. 19,32,35,106,119,13,70,219,15,83,239,12,137,154,32,2,67,252,19,36,128,0,0,4,1,130,196,32,2,130,8,91,107,8,32,0,135,81,24,73,211,8,132,161,73,164,13,36,0,8,0,128,2,105,123,26,139,67,
  5607. 76,99,15,34,1,0,128,135,76,83,156,20,92,104,8,67,251,30,24,86,47,27,123,207,12,24,86,7,15,71,227,8,32,4,65,20,20,131,127,32,0,130,123,32,0,71,223,26,32,19,90,195,22,71,223,15,84,200,
  5608. 6,32,128,133,241,24,84,149,9,67,41,25,36,0,0,0,22,0,88,111,49,32,87,66,21,5,77,3,27,123,75,7,71,143,19,135,183,71,183,19,130,171,74,252,5,131,5,89,87,17,32,1,132,18,130,232,68,11,10,
  5609. 33,1,128,70,208,16,66,230,18,147,18,130,254,223,255,75,27,23,65,59,15,135,39,155,255,34,128,128,254,104,92,8,33,0,128,65,32,11,65,1,58,33,26,0,130,0,72,71,18,78,55,17,76,11,19,86,101,
  5610. 12,75,223,11,89,15,11,24,76,87,15,75,235,15,131,15,72,95,7,85,71,11,72,115,11,73,64,6,34,1,128,128,66,215,9,34,128,254,128,134,14,33,128,255,67,102,5,32,0,130,16,70,38,11,66,26,57,
  5611. 88,11,8,24,76,215,34,78,139,7,95,245,7,32,7,24,73,75,23,32,128,131,167,130,170,101,158,9,82,49,22,118,139,6,32,18,67,155,44,116,187,9,108,55,14,80,155,23,66,131,15,93,77,10,131,168,
  5612. 32,128,73,211,12,24,75,187,22,32,4,96,71,20,67,108,19,132,19,120,207,8,32,5,76,79,15,66,111,21,66,95,8,32,3,190,211,111,3,8,211,212,32,20,65,167,44,34,75,0,79,97,59,13,32,33,112,63,
  5613. 10,65,147,19,69,39,19,143,39,24,66,71,9,130,224,65,185,43,94,176,12,65,183,24,71,38,8,24,72,167,7,65,191,38,136,235,24,96,167,12,65,203,62,115,131,13,65,208,42,175,235,67,127,6,32,
  5614. 4,76,171,29,114,187,5,32,71,65,211,5,65,203,68,72,51,8,164,219,32,0,172,214,71,239,58,78,3,27,66,143,15,77,19,15,147,31,35,33,53,51,21,66,183,10,173,245,66,170,30,150,30,34,0,0,23,
  5615. 80,123,54,76,1,16,73,125,15,82,245,11,167,253,24,76,85,12,70,184,5,32,254,131,185,37,254,0,128,1,0,128,133,16,117,158,18,92,27,38,65,3,17,130,251,35,17,0,128,254,24,69,83,39,140,243,
  5616. 121,73,19,109,167,7,81,41,15,24,95,175,12,102,227,15,121,96,11,24,95,189,7,32,3,145,171,154,17,24,77,47,9,33,0,5,70,71,37,68,135,7,32,29,117,171,11,69,87,15,24,79,97,19,24,79,149,23,
  5617. 131,59,32,1,75,235,5,72,115,11,72,143,7,132,188,71,27,46,131,51,32,0,69,95,6,175,215,32,21,131,167,81,15,19,151,191,151,23,131,215,71,43,5,32,254,24,79,164,24,74,109,8,77,166,13,65,
  5618. 176,26,88,162,5,98,159,6,171,219,120,247,6,79,29,8,99,169,10,103,59,19,65,209,35,131,35,91,25,19,112,94,15,83,36,8,173,229,33,20,0,88,75,43,71,31,12,65,191,71,33,1,0,130,203,32,254,
  5619. 131,4,68,66,7,67,130,6,104,61,13,173,215,38,13,1,0,0,0,2,128,67,111,28,74,129,16,104,35,19,79,161,16,87,14,7,138,143,132,10,67,62,36,114,115,5,162,151,67,33,16,108,181,15,143,151,67,
  5620. 5,5,24,100,242,15,170,153,34,0,0,14,65,51,34,32,55,79,75,9,32,51,74,7,10,65,57,38,132,142,32,254,72,0,14,139,163,32,128,80,254,8,67,158,21,65,63,7,32,4,72,227,27,95,155,12,67,119,19,
  5621. 124,91,24,149,154,72,177,34,97,223,8,155,151,24,108,227,15,88,147,16,72,117,19,68,35,11,92,253,15,70,199,15,24,87,209,17,32,2,87,233,7,32,1,24,88,195,10,119,24,8,32,3,81,227,24,65,
  5622. 125,21,35,128,128,0,25,76,59,48,24,90,187,9,97,235,12,66,61,11,91,105,19,24,79,141,11,24,79,117,15,24,79,129,27,90,53,13,130,13,32,253,131,228,24,79,133,40,69,70,8,66,137,31,65,33,
  5623. 19,96,107,8,68,119,29,66,7,5,68,125,16,65,253,19,65,241,27,24,90,179,13,24,79,143,18,33,128,128,130,246,32,254,130,168,68,154,36,77,51,9,97,47,5,167,195,32,21,131,183,78,239,27,155,
  5624. 195,78,231,14,201,196,77,11,6,32,5,73,111,37,97,247,12,77,19,31,155,207,78,215,19,162,212,69,17,14,66,91,19,80,143,57,78,203,39,159,215,32,128,93,134,8,24,80,109,24,66,113,15,169,215,
  5625. 66,115,6,32,4,69,63,33,32,0,101,113,7,86,227,35,143,211,36,49,53,51,21,1,77,185,14,65,159,28,69,251,34,67,56,8,33,9,0,24,107,175,25,90,111,12,110,251,11,119,189,24,119,187,34,87,15,
  5626. 9,32,4,66,231,37,90,39,7,66,239,8,84,219,15,69,105,23,24,85,27,27,87,31,11,33,1,128,76,94,6,32,1,85,241,7,33,128,128,106,48,10,33,128,128,69,136,11,133,13,24,79,116,49,84,236,8,24,
  5627. 91,87,9,32,5,165,255,69,115,12,66,27,15,159,15,24,72,247,12,74,178,5,24,80,64,15,33,0,128,143,17,77,89,51,130,214,24,81,43,7,170,215,74,49,8,159,199,143,31,139,215,69,143,5,32,254,
  5628. 24,81,50,35,181,217,84,123,70,143,195,159,15,65,187,16,66,123,7,65,175,15,65,193,29,68,207,39,79,27,5,70,131,6,32,4,68,211,33,33,67,0,83,143,14,159,207,143,31,140,223,33,0,128,24,80,
  5629. 82,14,24,93,16,23,32,253,65,195,5,68,227,40,133,214,107,31,7,32,5,67,115,27,87,9,8,107,31,43,66,125,6,32,0,103,177,23,131,127,72,203,36,32,0,110,103,8,155,163,73,135,6,32,19,24,112,
  5630. 99,10,65,71,11,73,143,19,143,31,126,195,5,24,85,21,9,24,76,47,14,32,254,24,93,77,36,68,207,11,39,25,0,0,255,128,3,128,4,66,51,37,95,247,13,82,255,24,76,39,19,147,221,66,85,27,24,118,
  5631. 7,8,24,74,249,12,76,74,8,91,234,8,67,80,17,131,222,33,253,0,121,30,44,73,0,16,69,15,6,32,0,65,23,38,69,231,12,65,179,6,98,131,16,86,31,27,24,108,157,14,80,160,8,24,65,46,17,33,4,0,
  5632. 96,2,18,144,191,65,226,8,68,19,5,171,199,80,9,15,180,199,67,89,5,32,255,24,79,173,28,174,201,24,79,179,50,32,1,24,122,5,10,82,61,10,180,209,83,19,8,32,128,24,80,129,27,111,248,43,131,
  5633. 71,24,115,103,8,67,127,41,78,213,24,100,247,19,66,115,39,75,107,5,32,254,165,219,78,170,40,24,112,163,49,32,1,97,203,6,65,173,64,32,0,83,54,7,133,217,88,37,12,32,254,131,28,33,128,
  5634. 3,67,71,44,84,183,6,32,5,69,223,33,96,7,7,123,137,16,192,211,24,112,14,9,32,255,67,88,29,68,14,10,84,197,38,33,0,22,116,47,50,32,87,106,99,9,116,49,15,89,225,15,97,231,23,70,41,19,
  5635. 82,85,8,93,167,6,32,253,132,236,108,190,7,89,251,5,116,49,58,33,128,128,131,234,32,15,24,74,67,38,70,227,24,24,83,45,23,89,219,12,70,187,12,89,216,19,32,2,69,185,24,141,24,70,143,66,
  5636. 24,82,119,56,78,24,10,32,253,133,149,132,6,24,106,233,7,69,198,48,178,203,81,243,12,68,211,15,106,255,23,66,91,15,69,193,7,100,39,10,24,83,72,16,176,204,33,19,0,88,207,45,68,21,12,
  5637. 68,17,10,65,157,53,68,17,6,32,254,92,67,10,65,161,25,69,182,43,24,118,91,47,69,183,18,181,209,111,253,12,89,159,8,66,112,12,69,184,45,35,0,0,0,9,24,80,227,26,73,185,16,118,195,15,131,
  5638. 15,33,1,0,65,59,15,66,39,27,160,111,66,205,12,148,111,143,110,33,128,128,156,112,24,81,199,8,75,199,23,66,117,20,155,121,32,254,68,126,12,72,213,29,134,239,149,123,89,27,16,148,117,
  5639. 65,245,8,24,71,159,14,141,134,134,28,73,51,55,109,77,15,105,131,11,68,67,11,76,169,27,107,209,12,102,174,8,32,128,72,100,18,116,163,56,79,203,11,75,183,44,85,119,19,71,119,23,151,227,
  5640. 32,1,93,27,8,65,122,5,77,102,8,110,120,20,66,23,8,66,175,17,66,63,12,133,12,79,35,8,74,235,33,67,149,16,69,243,15,78,57,15,69,235,16,67,177,7,151,192,130,23,67,84,29,141,192,174,187,
  5641. 77,67,15,69,11,12,159,187,77,59,10,199,189,24,70,235,50,96,83,19,66,53,23,105,65,19,77,47,12,163,199,66,67,37,78,207,50,67,23,23,174,205,67,228,6,71,107,13,67,22,14,66,85,11,83,187,
  5642. 38,124,47,49,95,7,19,66,83,23,67,23,19,24,96,78,17,80,101,16,71,98,40,33,0,7,88,131,22,24,89,245,12,84,45,12,102,213,5,123,12,9,32,2,126,21,14,43,255,0,128,128,0,0,20,0,128,255,128,
  5643. 3,126,19,39,32,75,106,51,7,113,129,15,24,110,135,19,126,47,15,115,117,11,69,47,11,32,2,109,76,9,102,109,9,32,128,75,2,10,130,21,32,254,69,47,6,32,3,94,217,47,32,0,65,247,10,69,15,46,
  5644. 65,235,31,65,243,15,101,139,10,66,174,14,65,247,16,72,102,28,69,17,14,84,243,9,165,191,88,47,48,66,53,12,32,128,71,108,6,203,193,32,17,75,187,42,73,65,16,65,133,52,114,123,9,167,199,
  5645. 69,21,37,86,127,44,75,171,11,180,197,78,213,12,148,200,81,97,46,24,95,243,9,32,4,66,75,33,113,103,9,87,243,36,143,225,24,84,27,31,90,145,8,148,216,67,49,5,24,84,34,14,75,155,27,67,
  5646. 52,13,140,13,36,0,20,0,128,255,24,135,99,46,88,59,43,155,249,80,165,7,136,144,71,161,23,32,253,132,33,32,254,88,87,44,136,84,35,128,0,0,21,81,103,5,94,47,44,76,51,12,143,197,151,15,
  5647. 65,215,31,24,64,77,13,65,220,20,65,214,14,71,4,40,65,213,13,32,0,130,0,35,21,1,2,0,135,0,34,36,0,72,134,10,36,1,0,26,0,130,134,11,36,2,0,14,0,108,134,11,32,3,138,23,32,4,138,11,34,
  5648. 5,0,20,134,33,34,0,0,6,132,23,32,1,134,15,32,18,130,25,133,11,37,1,0,13,0,49,0,133,11,36,2,0,7,0,38,134,11,36,3,0,17,0,45,134,11,32,4,138,35,36,5,0,10,0,62,134,23,32,6,132,23,36,3,
  5649. 0,1,4,9,130,87,131,167,133,11,133,167,133,11,133,167,133,11,37,3,0,34,0,122,0,133,11,133,167,133,11,133,167,133,11,133,167,34,50,0,48,130,1,34,52,0,47,134,5,8,49,49,0,53,98,121,32,
  5650. 84,114,105,115,116,97,110,32,71,114,105,109,109,101,114,82,101,103,117,108,97,114,84,84,88,32,80,114,111,103,103,121,67,108,101,97,110,84,84,50,48,48,52,47,130,2,53,49,53,0,98,0,121,
  5651. 0,32,0,84,0,114,0,105,0,115,0,116,0,97,0,110,130,15,32,71,132,15,36,109,0,109,0,101,130,9,32,82,130,5,36,103,0,117,0,108,130,29,32,114,130,43,34,84,0,88,130,35,32,80,130,25,34,111,
  5652. 0,103,130,1,34,121,0,67,130,27,32,101,132,59,32,84,130,31,33,0,0,65,155,9,34,20,0,0,65,11,6,130,8,135,2,33,1,1,130,9,8,120,1,1,2,1,3,1,4,1,5,1,6,1,7,1,8,1,9,1,10,1,11,1,12,1,13,1,14,
  5653. 1,15,1,16,1,17,1,18,1,19,1,20,1,21,1,22,1,23,1,24,1,25,1,26,1,27,1,28,1,29,1,30,1,31,1,32,0,3,0,4,0,5,0,6,0,7,0,8,0,9,0,10,0,11,0,12,0,13,0,14,0,15,0,16,0,17,0,18,0,19,0,20,0,21,0,
  5654. 22,0,23,0,24,0,25,0,26,0,27,0,28,0,29,0,30,0,31,130,187,8,66,33,0,34,0,35,0,36,0,37,0,38,0,39,0,40,0,41,0,42,0,43,0,44,0,45,0,46,0,47,0,48,0,49,0,50,0,51,0,52,0,53,0,54,0,55,0,56,0,
  5655. 57,0,58,0,59,0,60,0,61,0,62,0,63,0,64,0,65,0,66,130,243,9,75,68,0,69,0,70,0,71,0,72,0,73,0,74,0,75,0,76,0,77,0,78,0,79,0,80,0,81,0,82,0,83,0,84,0,85,0,86,0,87,0,88,0,89,0,90,0,91,0,
  5656. 92,0,93,0,94,0,95,0,96,0,97,1,33,1,34,1,35,1,36,1,37,1,38,1,39,1,40,1,41,1,42,1,43,1,44,1,45,1,46,1,47,1,48,1,49,1,50,1,51,1,52,1,53,1,54,1,55,1,56,1,57,1,58,1,59,1,60,1,61,1,62,1,
  5657. 63,1,64,1,65,0,172,0,163,0,132,0,133,0,189,0,150,0,232,0,134,0,142,0,139,0,157,0,169,0,164,0,239,0,138,0,218,0,131,0,147,0,242,0,243,0,141,0,151,0,136,0,195,0,222,0,241,0,158,0,170,
  5658. 0,245,0,244,0,246,0,162,0,173,0,201,0,199,0,174,0,98,0,99,0,144,0,100,0,203,0,101,0,200,0,202,0,207,0,204,0,205,0,206,0,233,0,102,0,211,0,208,0,209,0,175,0,103,0,240,0,145,0,214,0,
  5659. 212,0,213,0,104,0,235,0,237,0,137,0,106,0,105,0,107,0,109,0,108,0,110,0,160,0,111,0,113,0,112,0,114,0,115,0,117,0,116,0,118,0,119,0,234,0,120,0,122,0,121,0,123,0,125,0,124,0,184,0,
  5660. 161,0,127,0,126,0,128,0,129,0,236,0,238,0,186,14,117,110,105,99,111,100,101,35,48,120,48,48,48,49,141,14,32,50,141,14,32,51,141,14,32,52,141,14,32,53,141,14,32,54,141,14,32,55,141,
  5661. 14,32,56,141,14,32,57,141,14,32,97,141,14,32,98,141,14,32,99,141,14,32,100,141,14,32,101,141,14,32,102,140,14,33,49,48,141,14,141,239,32,49,141,239,32,49,141,239,32,49,141,239,32,49,
  5662. 141,239,32,49,141,239,32,49,141,239,32,49,141,239,32,49,141,239,32,49,141,239,32,49,141,239,32,49,141,239,32,49,141,239,32,49,141,239,45,49,102,6,100,101,108,101,116,101,4,69,117,114,
  5663. 111,140,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236,
  5664. 32,56,141,236,32,56,141,236,32,56,65,220,13,32,57,65,220,13,32,57,141,239,32,57,141,239,32,57,141,239,32,57,141,239,32,57,141,239,32,57,141,239,32,57,141,239,32,57,141,239,32,57,141,
  5665. 239,32,57,141,239,32,57,141,239,32,57,141,239,32,57,141,239,32,57,141,239,35,57,102,0,0,5,250,72,249,98,247,
  5666. };
  5667. static const char* GetDefaultCompressedFontDataTTF(int* out_size)
  5668. {
  5669. *out_size = proggy_clean_ttf_compressed_size;
  5670. return (const char*)proggy_clean_ttf_compressed_data;
  5671. }
  5672. #endif // #ifndef IMGUI_DISABLE_DEFAULT_FONT
  5673. #endif // #ifndef IMGUI_DISABLE