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

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