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

imgui.cpp 307KB

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