imgui.cpp 208 KB

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