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 241KB

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