raygui.h 262 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523
  1. /*******************************************************************************************
  2. *
  3. * raygui v4.0 - A simple and easy-to-use immediate-mode gui library
  4. *
  5. * DESCRIPTION:
  6. * raygui is a tools-dev-focused immediate-mode-gui library based on raylib but also
  7. * available as a standalone library, as long as input and drawing functions are provided.
  8. *
  9. * FEATURES:
  10. * - Immediate-mode gui, minimal retained data
  11. * - +25 controls provided (basic and advanced)
  12. * - Styling system for colors, font and metrics
  13. * - Icons supported, embedded as a 1-bit icons pack
  14. * - Standalone mode option (custom input/graphics backend)
  15. * - Multiple support tools provided for raygui development
  16. *
  17. * POSSIBLE IMPROVEMENTS:
  18. * - Better standalone mode API for easy plug of custom backends
  19. * - Externalize required inputs, allow user easier customization
  20. *
  21. * LIMITATIONS:
  22. * - No editable multi-line word-wraped text box supported
  23. * - No auto-layout mechanism, up to the user to define controls position and size
  24. * - Standalone mode requires library modification and some user work to plug another backend
  25. *
  26. * NOTES:
  27. * - WARNING: GuiLoadStyle() and GuiLoadStyle{Custom}() functions, allocate memory for
  28. * font atlas recs and glyphs, freeing that memory is (usually) up to the user,
  29. * no unload function is explicitly provided... but note that GuiLoadStyleDefaulf() unloads
  30. * by default any previously loaded font (texture, recs, glyphs).
  31. * - Global UI alpha (guiAlpha) is applied inside GuiDrawRectangle() and GuiDrawText() functions
  32. *
  33. * CONTROLS PROVIDED:
  34. * # Container/separators Controls
  35. * - WindowBox --> StatusBar, Panel
  36. * - GroupBox --> Line
  37. * - Line
  38. * - Panel --> StatusBar
  39. * - ScrollPanel --> StatusBar
  40. * - TabBar --> Button
  41. *
  42. * # Basic Controls
  43. * - Label
  44. * - LabelButton --> Label
  45. * - Button
  46. * - Toggle
  47. * - ToggleGroup --> Toggle
  48. * - ToggleSlider
  49. * - CheckBox
  50. * - ComboBox
  51. * - DropdownBox
  52. * - TextBox
  53. * - ValueBox --> TextBox
  54. * - Spinner --> Button, ValueBox
  55. * - Slider
  56. * - SliderBar --> Slider
  57. * - ProgressBar
  58. * - StatusBar
  59. * - DummyRec
  60. * - Grid
  61. *
  62. * # Advance Controls
  63. * - ListView
  64. * - ColorPicker --> ColorPanel, ColorBarHue
  65. * - MessageBox --> Window, Label, Button
  66. * - TextInputBox --> Window, Label, TextBox, Button
  67. *
  68. * It also provides a set of functions for styling the controls based on its properties (size, color).
  69. *
  70. *
  71. * RAYGUI STYLE (guiStyle):
  72. * raygui uses a global data array for all gui style properties (allocated on data segment by default),
  73. * when a new style is loaded, it is loaded over the global style... but a default gui style could always be
  74. * recovered with GuiLoadStyleDefault() function, that overwrites the current style to the default one
  75. *
  76. * The global style array size is fixed and depends on the number of controls and properties:
  77. *
  78. * static unsigned int guiStyle[RAYGUI_MAX_CONTROLS*(RAYGUI_MAX_PROPS_BASE + RAYGUI_MAX_PROPS_EXTENDED)];
  79. *
  80. * guiStyle size is by default: 16*(16 + 8) = 384*4 = 1536 bytes = 1.5 KB
  81. *
  82. * Note that the first set of BASE properties (by default guiStyle[0..15]) belong to the generic style
  83. * used for all controls, when any of those base values is set, it is automatically populated to all
  84. * controls, so, specific control values overwriting generic style should be set after base values.
  85. *
  86. * After the first BASE set we have the EXTENDED properties (by default guiStyle[16..23]), those
  87. * properties are actually common to all controls and can not be overwritten individually (like BASE ones)
  88. * Some of those properties are: TEXT_SIZE, TEXT_SPACING, LINE_COLOR, BACKGROUND_COLOR
  89. *
  90. * Custom control properties can be defined using the EXTENDED properties for each independent control.
  91. *
  92. * TOOL: rGuiStyler is a visual tool to customize raygui style: github.com/raysan5/rguistyler
  93. *
  94. *
  95. * RAYGUI ICONS (guiIcons):
  96. * raygui could use a global array containing icons data (allocated on data segment by default),
  97. * a custom icons set could be loaded over this array using GuiLoadIcons(), but loaded icons set
  98. * must be same RAYGUI_ICON_SIZE and no more than RAYGUI_ICON_MAX_ICONS will be loaded
  99. *
  100. * Every icon is codified in binary form, using 1 bit per pixel, so, every 16x16 icon
  101. * requires 8 integers (16*16/32) to be stored in memory.
  102. *
  103. * When the icon is draw, actually one quad per pixel is drawn if the bit for that pixel is set.
  104. *
  105. * The global icons array size is fixed and depends on the number of icons and size:
  106. *
  107. * static unsigned int guiIcons[RAYGUI_ICON_MAX_ICONS*RAYGUI_ICON_DATA_ELEMENTS];
  108. *
  109. * guiIcons size is by default: 256*(16*16/32) = 2048*4 = 8192 bytes = 8 KB
  110. *
  111. * TOOL: rGuiIcons is a visual tool to customize/create raygui icons: github.com/raysan5/rguiicons
  112. *
  113. * RAYGUI LAYOUT:
  114. * raygui currently does not provide an auto-layout mechanism like other libraries,
  115. * layouts must be defined manually on controls drawing, providing the right bounds Rectangle for it.
  116. *
  117. * TOOL: rGuiLayout is a visual tool to create raygui layouts: github.com/raysan5/rguilayout
  118. *
  119. * CONFIGURATION:
  120. * #define RAYGUI_IMPLEMENTATION
  121. * Generates the implementation of the library into the included file.
  122. * If not defined, the library is in header only mode and can be included in other headers
  123. * or source files without problems. But only ONE file should hold the implementation.
  124. *
  125. * #define RAYGUI_STANDALONE
  126. * Avoid raylib.h header inclusion in this file. Data types defined on raylib are defined
  127. * internally in the library and input management and drawing functions must be provided by
  128. * the user (check library implementation for further details).
  129. *
  130. * #define RAYGUI_NO_ICONS
  131. * Avoid including embedded ricons data (256 icons, 16x16 pixels, 1-bit per pixel, 2KB)
  132. *
  133. * #define RAYGUI_CUSTOM_ICONS
  134. * Includes custom ricons.h header defining a set of custom icons,
  135. * this file can be generated using rGuiIcons tool
  136. *
  137. * #define RAYGUI_DEBUG_RECS_BOUNDS
  138. * Draw control bounds rectangles for debug
  139. *
  140. * #define RAYGUI_DEBUG_TEXT_BOUNDS
  141. * Draw text bounds rectangles for debug
  142. *
  143. * VERSIONS HISTORY:
  144. * 4.0 (12-Sep-2023) ADDED: GuiToggleSlider()
  145. * ADDED: GuiColorPickerHSV() and GuiColorPanelHSV()
  146. * ADDED: Multiple new icons, mostly compiler related
  147. * ADDED: New DEFAULT properties: TEXT_LINE_SPACING, TEXT_ALIGNMENT_VERTICAL, TEXT_WRAP_MODE
  148. * ADDED: New enum values: GuiTextAlignment, GuiTextAlignmentVertical, GuiTextWrapMode
  149. * ADDED: Support loading styles with custom font charset from external file
  150. * REDESIGNED: GuiTextBox(), support mouse cursor positioning
  151. * REDESIGNED: GuiDrawText(), support multiline and word-wrap modes (read only)
  152. * REDESIGNED: GuiProgressBar() to be more visual, progress affects border color
  153. * REDESIGNED: Global alpha consideration moved to GuiDrawRectangle() and GuiDrawText()
  154. * REDESIGNED: GuiScrollPanel(), get parameters by reference and return result value
  155. * REDESIGNED: GuiToggleGroup(), get parameters by reference and return result value
  156. * REDESIGNED: GuiComboBox(), get parameters by reference and return result value
  157. * REDESIGNED: GuiCheckBox(), get parameters by reference and return result value
  158. * REDESIGNED: GuiSlider(), get parameters by reference and return result value
  159. * REDESIGNED: GuiSliderBar(), get parameters by reference and return result value
  160. * REDESIGNED: GuiProgressBar(), get parameters by reference and return result value
  161. * REDESIGNED: GuiListView(), get parameters by reference and return result value
  162. * REDESIGNED: GuiColorPicker(), get parameters by reference and return result value
  163. * REDESIGNED: GuiColorPanel(), get parameters by reference and return result value
  164. * REDESIGNED: GuiColorBarAlpha(), get parameters by reference and return result value
  165. * REDESIGNED: GuiColorBarHue(), get parameters by reference and return result value
  166. * REDESIGNED: GuiGrid(), get parameters by reference and return result value
  167. * REDESIGNED: GuiGrid(), added extra parameter
  168. * REDESIGNED: GuiListViewEx(), change parameters order
  169. * REDESIGNED: All controls return result as int value
  170. * REVIEWED: GuiScrollPanel() to avoid smallish scroll-bars
  171. * REVIEWED: All examples and specially controls_test_suite
  172. * RENAMED: gui_file_dialog module to gui_window_file_dialog
  173. * UPDATED: All styles to include ISO-8859-15 charset (as much as possible)
  174. *
  175. * 3.6 (10-May-2023) ADDED: New icon: SAND_TIMER
  176. * ADDED: GuiLoadStyleFromMemory() (binary only)
  177. * REVIEWED: GuiScrollBar() horizontal movement key
  178. * REVIEWED: GuiTextBox() crash on cursor movement
  179. * REVIEWED: GuiTextBox(), additional inputs support
  180. * REVIEWED: GuiLabelButton(), avoid text cut
  181. * REVIEWED: GuiTextInputBox(), password input
  182. * REVIEWED: Local GetCodepointNext(), aligned with raylib
  183. * REDESIGNED: GuiSlider*()/GuiScrollBar() to support out-of-bounds
  184. *
  185. * 3.5 (20-Apr-2023) ADDED: GuiTabBar(), based on GuiToggle()
  186. * ADDED: Helper functions to split text in separate lines
  187. * ADDED: Multiple new icons, useful for code editing tools
  188. * REMOVED: Unneeded icon editing functions
  189. * REMOVED: GuiTextBoxMulti(), very limited and broken
  190. * REMOVED: MeasureTextEx() dependency, logic directly implemented
  191. * REMOVED: DrawTextEx() dependency, logic directly implemented
  192. * REVIEWED: GuiScrollBar(), improve mouse-click behaviour
  193. * REVIEWED: Library header info, more info, better organized
  194. * REDESIGNED: GuiTextBox() to support cursor movement
  195. * REDESIGNED: GuiDrawText() to divide drawing by lines
  196. *
  197. * 3.2 (22-May-2022) RENAMED: Some enum values, for unification, avoiding prefixes
  198. * REMOVED: GuiScrollBar(), only internal
  199. * REDESIGNED: GuiPanel() to support text parameter
  200. * REDESIGNED: GuiScrollPanel() to support text parameter
  201. * REDESIGNED: GuiColorPicker() to support text parameter
  202. * REDESIGNED: GuiColorPanel() to support text parameter
  203. * REDESIGNED: GuiColorBarAlpha() to support text parameter
  204. * REDESIGNED: GuiColorBarHue() to support text parameter
  205. * REDESIGNED: GuiTextInputBox() to support password
  206. *
  207. * 3.1 (12-Jan-2022) REVIEWED: Default style for consistency (aligned with rGuiLayout v2.5 tool)
  208. * REVIEWED: GuiLoadStyle() to support compressed font atlas image data and unload previous textures
  209. * REVIEWED: External icons usage logic
  210. * REVIEWED: GuiLine() for centered alignment when including text
  211. * RENAMED: Multiple controls properties definitions to prepend RAYGUI_
  212. * RENAMED: RICON_ references to RAYGUI_ICON_ for library consistency
  213. * Projects updated and multiple tweaks
  214. *
  215. * 3.0 (04-Nov-2021) Integrated ricons data to avoid external file
  216. * REDESIGNED: GuiTextBoxMulti()
  217. * REMOVED: GuiImageButton*()
  218. * Multiple minor tweaks and bugs corrected
  219. *
  220. * 2.9 (17-Mar-2021) REMOVED: Tooltip API
  221. * 2.8 (03-May-2020) Centralized rectangles drawing to GuiDrawRectangle()
  222. * 2.7 (20-Feb-2020) ADDED: Possible tooltips API
  223. * 2.6 (09-Sep-2019) ADDED: GuiTextInputBox()
  224. * REDESIGNED: GuiListView*(), GuiDropdownBox(), GuiSlider*(), GuiProgressBar(), GuiMessageBox()
  225. * REVIEWED: GuiTextBox(), GuiSpinner(), GuiValueBox(), GuiLoadStyle()
  226. * Replaced property INNER_PADDING by TEXT_PADDING, renamed some properties
  227. * ADDED: 8 new custom styles ready to use
  228. * Multiple minor tweaks and bugs corrected
  229. *
  230. * 2.5 (28-May-2019) Implemented extended GuiTextBox(), GuiValueBox(), GuiSpinner()
  231. * 2.3 (29-Apr-2019) ADDED: rIcons auxiliar library and support for it, multiple controls reviewed
  232. * Refactor all controls drawing mechanism to use control state
  233. * 2.2 (05-Feb-2019) ADDED: GuiScrollBar(), GuiScrollPanel(), reviewed GuiListView(), removed Gui*Ex() controls
  234. * 2.1 (26-Dec-2018) REDESIGNED: GuiCheckBox(), GuiComboBox(), GuiDropdownBox(), GuiToggleGroup() > Use combined text string
  235. * REDESIGNED: Style system (breaking change)
  236. * 2.0 (08-Nov-2018) ADDED: Support controls guiLock and custom fonts
  237. * REVIEWED: GuiComboBox(), GuiListView()...
  238. * 1.9 (09-Oct-2018) REVIEWED: GuiGrid(), GuiTextBox(), GuiTextBoxMulti(), GuiValueBox()...
  239. * 1.8 (01-May-2018) Lot of rework and redesign to align with rGuiStyler and rGuiLayout
  240. * 1.5 (21-Jun-2017) Working in an improved styles system
  241. * 1.4 (15-Jun-2017) Rewritten all GUI functions (removed useless ones)
  242. * 1.3 (12-Jun-2017) Complete redesign of style system
  243. * 1.1 (01-Jun-2017) Complete review of the library
  244. * 1.0 (07-Jun-2016) Converted to header-only by Ramon Santamaria.
  245. * 0.9 (07-Mar-2016) Reviewed and tested by Albert Martos, Ian Eito, Sergio Martinez and Ramon Santamaria.
  246. * 0.8 (27-Aug-2015) Initial release. Implemented by Kevin Gato, Daniel Nicolás and Ramon Santamaria.
  247. *
  248. * DEPENDENCIES:
  249. * raylib 5.0 - Inputs reading (keyboard/mouse), shapes drawing, font loading and text drawing
  250. *
  251. * STANDALONE MODE:
  252. * By default raygui depends on raylib mostly for the inputs and the drawing functionality but that dependency can be disabled
  253. * with the config flag RAYGUI_STANDALONE. In that case is up to the user to provide another backend to cover library needs.
  254. *
  255. * The following functions should be redefined for a custom backend:
  256. *
  257. * - Vector2 GetMousePosition(void);
  258. * - float GetMouseWheelMove(void);
  259. * - bool IsMouseButtonDown(int button);
  260. * - bool IsMouseButtonPressed(int button);
  261. * - bool IsMouseButtonReleased(int button);
  262. * - bool IsKeyDown(int key);
  263. * - bool IsKeyPressed(int key);
  264. * - int GetCharPressed(void); // -- GuiTextBox(), GuiValueBox()
  265. *
  266. * - void DrawRectangle(int x, int y, int width, int height, Color color); // -- GuiDrawRectangle()
  267. * - void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3, Color col4); // -- GuiColorPicker()
  268. *
  269. * - Font GetFontDefault(void); // -- GuiLoadStyleDefault()
  270. * - Font LoadFontEx(const char *fileName, int fontSize, int *codepoints, int codepointCount); // -- GuiLoadStyle()
  271. * - Texture2D LoadTextureFromImage(Image image); // -- GuiLoadStyle(), required to load texture from embedded font atlas image
  272. * - void SetShapesTexture(Texture2D tex, Rectangle rec); // -- GuiLoadStyle(), required to set shapes rec to font white rec (optimization)
  273. * - char *LoadFileText(const char *fileName); // -- GuiLoadStyle(), required to load charset data
  274. * - void UnloadFileText(char *text); // -- GuiLoadStyle(), required to unload charset data
  275. * - const char *GetDirectoryPath(const char *filePath); // -- GuiLoadStyle(), required to find charset/font file from text .rgs
  276. * - int *LoadCodepoints(const char *text, int *count); // -- GuiLoadStyle(), required to load required font codepoints list
  277. * - void UnloadCodepoints(int *codepoints); // -- GuiLoadStyle(), required to unload codepoints list
  278. * - unsigned char *DecompressData(const unsigned char *compData, int compDataSize, int *dataSize); // -- GuiLoadStyle()
  279. *
  280. * CONTRIBUTORS:
  281. * Ramon Santamaria: Supervision, review, redesign, update and maintenance
  282. * Vlad Adrian: Complete rewrite of GuiTextBox() to support extended features (2019)
  283. * Sergio Martinez: Review, testing (2015) and redesign of multiple controls (2018)
  284. * Adria Arranz: Testing and implementation of additional controls (2018)
  285. * Jordi Jorba: Testing and implementation of additional controls (2018)
  286. * Albert Martos: Review and testing of the library (2015)
  287. * Ian Eito: Review and testing of the library (2015)
  288. * Kevin Gato: Initial implementation of basic components (2014)
  289. * Daniel Nicolas: Initial implementation of basic components (2014)
  290. *
  291. *
  292. * LICENSE: zlib/libpng
  293. *
  294. * Copyright (c) 2014-2023 Ramon Santamaria (@raysan5)
  295. *
  296. * This software is provided "as-is", without any express or implied warranty. In no event
  297. * will the authors be held liable for any damages arising from the use of this software.
  298. *
  299. * Permission is granted to anyone to use this software for any purpose, including commercial
  300. * applications, and to alter it and redistribute it freely, subject to the following restrictions:
  301. *
  302. * 1. The origin of this software must not be misrepresented; you must not claim that you
  303. * wrote the original software. If you use this software in a product, an acknowledgment
  304. * in the product documentation would be appreciated but is not required.
  305. *
  306. * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
  307. * as being the original software.
  308. *
  309. * 3. This notice may not be removed or altered from any source distribution.
  310. *
  311. **********************************************************************************************/
  312. #ifndef RAYGUI_H
  313. #define RAYGUI_H
  314. #define RAYGUI_VERSION_MAJOR 4
  315. #define RAYGUI_VERSION_MINOR 0
  316. #define RAYGUI_VERSION_PATCH 0
  317. #define RAYGUI_VERSION "4.0"
  318. #if !defined(RAYGUI_STANDALONE)
  319. #include "raylib.h"
  320. #endif
  321. // Function specifiers in case library is build/used as a shared library (Windows)
  322. // NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
  323. #if defined(_WIN32)
  324. #if defined(BUILD_LIBTYPE_SHARED)
  325. #define RAYGUIAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll)
  326. #elif defined(USE_LIBTYPE_SHARED)
  327. #define RAYGUIAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll)
  328. #endif
  329. #endif
  330. // Function specifiers definition
  331. #ifndef RAYGUIAPI
  332. #define RAYGUIAPI // Functions defined as 'extern' by default (implicit specifiers)
  333. #endif
  334. //----------------------------------------------------------------------------------
  335. // Defines and Macros
  336. //----------------------------------------------------------------------------------
  337. // Allow custom memory allocators
  338. #ifndef RAYGUI_MALLOC
  339. #define RAYGUI_MALLOC(sz) malloc(sz)
  340. #endif
  341. #ifndef RAYGUI_CALLOC
  342. #define RAYGUI_CALLOC(n,sz) calloc(n,sz)
  343. #endif
  344. #ifndef RAYGUI_FREE
  345. #define RAYGUI_FREE(p) free(p)
  346. #endif
  347. // Simple log system to avoid printf() calls if required
  348. // NOTE: Avoiding those calls, also avoids const strings memory usage
  349. #define RAYGUI_SUPPORT_LOG_INFO
  350. #if defined(RAYGUI_SUPPORT_LOG_INFO)
  351. #define RAYGUI_LOG(...) printf(__VA_ARGS__)
  352. #else
  353. #define RAYGUI_LOG(...)
  354. #endif
  355. //----------------------------------------------------------------------------------
  356. // Types and Structures Definition
  357. // NOTE: Some types are required for RAYGUI_STANDALONE usage
  358. //----------------------------------------------------------------------------------
  359. #if defined(RAYGUI_STANDALONE)
  360. #ifndef __cplusplus
  361. // Boolean type
  362. #ifndef true
  363. typedef enum { false, true } bool;
  364. #endif
  365. #endif
  366. // Vector2 type
  367. typedef struct Vector2 {
  368. float x;
  369. float y;
  370. } Vector2;
  371. // Vector3 type // -- ConvertHSVtoRGB(), ConvertRGBtoHSV()
  372. typedef struct Vector3 {
  373. float x;
  374. float y;
  375. float z;
  376. } Vector3;
  377. // Color type, RGBA (32bit)
  378. typedef struct Color {
  379. unsigned char r;
  380. unsigned char g;
  381. unsigned char b;
  382. unsigned char a;
  383. } Color;
  384. // Rectangle type
  385. typedef struct Rectangle {
  386. float x;
  387. float y;
  388. float width;
  389. float height;
  390. } Rectangle;
  391. // TODO: Texture2D type is very coupled to raylib, required by Font type
  392. // It should be redesigned to be provided by user
  393. typedef struct Texture2D {
  394. unsigned int id; // OpenGL texture id
  395. int width; // Texture base width
  396. int height; // Texture base height
  397. int mipmaps; // Mipmap levels, 1 by default
  398. int format; // Data format (PixelFormat type)
  399. } Texture2D;
  400. // Image, pixel data stored in CPU memory (RAM)
  401. typedef struct Image {
  402. void *data; // Image raw data
  403. int width; // Image base width
  404. int height; // Image base height
  405. int mipmaps; // Mipmap levels, 1 by default
  406. int format; // Data format (PixelFormat type)
  407. } Image;
  408. // GlyphInfo, font characters glyphs info
  409. typedef struct GlyphInfo {
  410. int value; // Character value (Unicode)
  411. int offsetX; // Character offset X when drawing
  412. int offsetY; // Character offset Y when drawing
  413. int advanceX; // Character advance position X
  414. Image image; // Character image data
  415. } GlyphInfo;
  416. // TODO: Font type is very coupled to raylib, mostly required by GuiLoadStyle()
  417. // It should be redesigned to be provided by user
  418. typedef struct Font {
  419. int baseSize; // Base size (default chars height)
  420. int glyphCount; // Number of glyph characters
  421. int glyphPadding; // Padding around the glyph characters
  422. Texture2D texture; // Texture atlas containing the glyphs
  423. Rectangle *recs; // Rectangles in texture for the glyphs
  424. GlyphInfo *glyphs; // Glyphs info data
  425. } Font;
  426. #endif
  427. // Style property
  428. // NOTE: Used when exporting style as code for convenience
  429. typedef struct GuiStyleProp {
  430. unsigned short controlId; // Control identifier
  431. unsigned short propertyId; // Property identifier
  432. int propertyValue; // Property value
  433. } GuiStyleProp;
  434. /*
  435. // Controls text style -NOT USED-
  436. // NOTE: Text style is defined by control
  437. typedef struct GuiTextStyle {
  438. unsigned int size;
  439. int charSpacing;
  440. int lineSpacing;
  441. int alignmentH;
  442. int alignmentV;
  443. int padding;
  444. } GuiTextStyle;
  445. */
  446. // Gui control state
  447. typedef enum {
  448. STATE_NORMAL = 0,
  449. STATE_FOCUSED,
  450. STATE_PRESSED,
  451. STATE_DISABLED
  452. } GuiState;
  453. // Gui control text alignment
  454. typedef enum {
  455. TEXT_ALIGN_LEFT = 0,
  456. TEXT_ALIGN_CENTER,
  457. TEXT_ALIGN_RIGHT
  458. } GuiTextAlignment;
  459. // Gui control text alignment vertical
  460. // NOTE: Text vertical position inside the text bounds
  461. typedef enum {
  462. TEXT_ALIGN_TOP = 0,
  463. TEXT_ALIGN_MIDDLE,
  464. TEXT_ALIGN_BOTTOM
  465. } GuiTextAlignmentVertical;
  466. // Gui control text wrap mode
  467. // NOTE: Useful for multiline text
  468. typedef enum {
  469. TEXT_WRAP_NONE = 0,
  470. TEXT_WRAP_CHAR,
  471. TEXT_WRAP_WORD
  472. } GuiTextWrapMode;
  473. // Gui controls
  474. typedef enum {
  475. // Default -> populates to all controls when set
  476. DEFAULT = 0,
  477. // Basic controls
  478. LABEL, // Used also for: LABELBUTTON
  479. BUTTON,
  480. TOGGLE, // Used also for: TOGGLEGROUP
  481. SLIDER, // Used also for: SLIDERBAR, TOGGLESLIDER
  482. PROGRESSBAR,
  483. CHECKBOX,
  484. COMBOBOX,
  485. DROPDOWNBOX,
  486. TEXTBOX, // Used also for: TEXTBOXMULTI
  487. VALUEBOX,
  488. SPINNER, // Uses: BUTTON, VALUEBOX
  489. LISTVIEW,
  490. COLORPICKER,
  491. SCROLLBAR,
  492. STATUSBAR
  493. } GuiControl;
  494. // Gui base properties for every control
  495. // NOTE: RAYGUI_MAX_PROPS_BASE properties (by default 16 properties)
  496. typedef enum {
  497. BORDER_COLOR_NORMAL = 0, // Control border color in STATE_NORMAL
  498. BASE_COLOR_NORMAL, // Control base color in STATE_NORMAL
  499. TEXT_COLOR_NORMAL, // Control text color in STATE_NORMAL
  500. BORDER_COLOR_FOCUSED, // Control border color in STATE_FOCUSED
  501. BASE_COLOR_FOCUSED, // Control base color in STATE_FOCUSED
  502. TEXT_COLOR_FOCUSED, // Control text color in STATE_FOCUSED
  503. BORDER_COLOR_PRESSED, // Control border color in STATE_PRESSED
  504. BASE_COLOR_PRESSED, // Control base color in STATE_PRESSED
  505. TEXT_COLOR_PRESSED, // Control text color in STATE_PRESSED
  506. BORDER_COLOR_DISABLED, // Control border color in STATE_DISABLED
  507. BASE_COLOR_DISABLED, // Control base color in STATE_DISABLED
  508. TEXT_COLOR_DISABLED, // Control text color in STATE_DISABLED
  509. BORDER_WIDTH, // Control border size, 0 for no border
  510. //TEXT_SIZE, // Control text size (glyphs max height) -> GLOBAL for all controls
  511. //TEXT_SPACING, // Control text spacing between glyphs -> GLOBAL for all controls
  512. //TEXT_LINE_SPACING // Control text spacing between lines -> GLOBAL for all controls
  513. TEXT_PADDING, // Control text padding, not considering border
  514. TEXT_ALIGNMENT, // Control text horizontal alignment inside control text bound (after border and padding)
  515. //TEXT_WRAP_MODE // Control text wrap-mode inside text bounds -> GLOBAL for all controls
  516. } GuiControlProperty;
  517. // TODO: Which text styling properties should be global or per-control?
  518. // At this moment TEXT_PADDING and TEXT_ALIGNMENT is configured and saved per control while
  519. // TEXT_SIZE, TEXT_SPACING, TEXT_LINE_SPACING, TEXT_ALIGNMENT_VERTICAL, TEXT_WRAP_MODE are global and
  520. // should be configured by user as needed while defining the UI layout
  521. // Gui extended properties depend on control
  522. // NOTE: RAYGUI_MAX_PROPS_EXTENDED properties (by default, max 8 properties)
  523. //----------------------------------------------------------------------------------
  524. // DEFAULT extended properties
  525. // NOTE: Those properties are common to all controls or global
  526. // WARNING: We only have 8 slots for those properties by default!!! -> New global control: TEXT?
  527. typedef enum {
  528. TEXT_SIZE = 16, // Text size (glyphs max height)
  529. TEXT_SPACING, // Text spacing between glyphs
  530. LINE_COLOR, // Line control color
  531. BACKGROUND_COLOR, // Background color
  532. TEXT_LINE_SPACING, // Text spacing between lines
  533. TEXT_ALIGNMENT_VERTICAL, // Text vertical alignment inside text bounds (after border and padding)
  534. TEXT_WRAP_MODE // Text wrap-mode inside text bounds
  535. //TEXT_DECORATION // Text decoration: 0-None, 1-Underline, 2-Line-through, 3-Overline
  536. //TEXT_DECORATION_THICK // Text decoration line thikness
  537. } GuiDefaultProperty;
  538. // Other possible text properties:
  539. // TEXT_WEIGHT // Normal, Italic, Bold -> Requires specific font change
  540. // TEXT_INDENT // Text indentation -> Now using TEXT_PADDING...
  541. // Label
  542. //typedef enum { } GuiLabelProperty;
  543. // Button/Spinner
  544. //typedef enum { } GuiButtonProperty;
  545. // Toggle/ToggleGroup
  546. typedef enum {
  547. GROUP_PADDING = 16, // ToggleGroup separation between toggles
  548. } GuiToggleProperty;
  549. // Slider/SliderBar
  550. typedef enum {
  551. SLIDER_WIDTH = 16, // Slider size of internal bar
  552. SLIDER_PADDING // Slider/SliderBar internal bar padding
  553. } GuiSliderProperty;
  554. // ProgressBar
  555. typedef enum {
  556. PROGRESS_PADDING = 16, // ProgressBar internal padding
  557. } GuiProgressBarProperty;
  558. // ScrollBar
  559. typedef enum {
  560. ARROWS_SIZE = 16, // ScrollBar arrows size
  561. ARROWS_VISIBLE, // ScrollBar arrows visible
  562. SCROLL_SLIDER_PADDING, // ScrollBar slider internal padding
  563. SCROLL_SLIDER_SIZE, // ScrollBar slider size
  564. SCROLL_PADDING, // ScrollBar scroll padding from arrows
  565. SCROLL_SPEED, // ScrollBar scrolling speed
  566. } GuiScrollBarProperty;
  567. // CheckBox
  568. typedef enum {
  569. CHECK_PADDING = 16 // CheckBox internal check padding
  570. } GuiCheckBoxProperty;
  571. // ComboBox
  572. typedef enum {
  573. COMBO_BUTTON_WIDTH = 16, // ComboBox right button width
  574. COMBO_BUTTON_SPACING // ComboBox button separation
  575. } GuiComboBoxProperty;
  576. // DropdownBox
  577. typedef enum {
  578. ARROW_PADDING = 16, // DropdownBox arrow separation from border and items
  579. DROPDOWN_ITEMS_SPACING // DropdownBox items separation
  580. } GuiDropdownBoxProperty;
  581. // TextBox/TextBoxMulti/ValueBox/Spinner
  582. typedef enum {
  583. TEXT_READONLY = 16, // TextBox in read-only mode: 0-text editable, 1-text no-editable
  584. } GuiTextBoxProperty;
  585. // Spinner
  586. typedef enum {
  587. SPIN_BUTTON_WIDTH = 16, // Spinner left/right buttons width
  588. SPIN_BUTTON_SPACING, // Spinner buttons separation
  589. } GuiSpinnerProperty;
  590. // ListView
  591. typedef enum {
  592. LIST_ITEMS_HEIGHT = 16, // ListView items height
  593. LIST_ITEMS_SPACING, // ListView items separation
  594. SCROLLBAR_WIDTH, // ListView scrollbar size (usually width)
  595. SCROLLBAR_SIDE, // ListView scrollbar side (0-SCROLLBAR_LEFT_SIDE, 1-SCROLLBAR_RIGHT_SIDE)
  596. } GuiListViewProperty;
  597. // ColorPicker
  598. typedef enum {
  599. COLOR_SELECTOR_SIZE = 16,
  600. HUEBAR_WIDTH, // ColorPicker right hue bar width
  601. HUEBAR_PADDING, // ColorPicker right hue bar separation from panel
  602. HUEBAR_SELECTOR_HEIGHT, // ColorPicker right hue bar selector height
  603. HUEBAR_SELECTOR_OVERFLOW // ColorPicker right hue bar selector overflow
  604. } GuiColorPickerProperty;
  605. #define SCROLLBAR_LEFT_SIDE 0
  606. #define SCROLLBAR_RIGHT_SIDE 1
  607. //----------------------------------------------------------------------------------
  608. // Global Variables Definition
  609. //----------------------------------------------------------------------------------
  610. // ...
  611. //----------------------------------------------------------------------------------
  612. // Module Functions Declaration
  613. //----------------------------------------------------------------------------------
  614. #if defined(__cplusplus)
  615. extern "C" { // Prevents name mangling of functions
  616. #endif
  617. // Global gui state control functions
  618. RAYGUIAPI void GuiEnable(void); // Enable gui controls (global state)
  619. RAYGUIAPI void GuiDisable(void); // Disable gui controls (global state)
  620. RAYGUIAPI void GuiLock(void); // Lock gui controls (global state)
  621. RAYGUIAPI void GuiUnlock(void); // Unlock gui controls (global state)
  622. RAYGUIAPI bool GuiIsLocked(void); // Check if gui is locked (global state)
  623. RAYGUIAPI void GuiSetAlpha(float alpha); // Set gui controls alpha (global state), alpha goes from 0.0f to 1.0f
  624. RAYGUIAPI void GuiSetState(int state); // Set gui state (global state)
  625. RAYGUIAPI int GuiGetState(void); // Get gui state (global state)
  626. // Font set/get functions
  627. RAYGUIAPI void GuiSetFont(Font font); // Set gui custom font (global state)
  628. RAYGUIAPI Font GuiGetFont(void); // Get gui custom font (global state)
  629. // Style set/get functions
  630. RAYGUIAPI void GuiSetStyle(int control, int property, int value); // Set one style property
  631. RAYGUIAPI int GuiGetStyle(int control, int property); // Get one style property
  632. // Styles loading functions
  633. RAYGUIAPI void GuiLoadStyle(const char *fileName); // Load style file over global style variable (.rgs)
  634. RAYGUIAPI void GuiLoadStyleDefault(void); // Load style default over global style
  635. // Tooltips management functions
  636. RAYGUIAPI void GuiEnableTooltip(void); // Enable gui tooltips (global state)
  637. RAYGUIAPI void GuiDisableTooltip(void); // Disable gui tooltips (global state)
  638. RAYGUIAPI void GuiSetTooltip(const char *tooltip); // Set tooltip string
  639. // Icons functionality
  640. RAYGUIAPI const char *GuiIconText(int iconId, const char *text); // Get text with icon id prepended (if supported)
  641. #if !defined(RAYGUI_NO_ICONS)
  642. RAYGUIAPI void GuiSetIconScale(int scale); // Set default icon drawing size
  643. RAYGUIAPI unsigned int *GuiGetIcons(void); // Get raygui icons data pointer
  644. RAYGUIAPI char **GuiLoadIcons(const char *fileName, bool loadIconsName); // Load raygui icons file (.rgi) into internal icons data
  645. RAYGUIAPI void GuiDrawIcon(int iconId, int posX, int posY, int pixelSize, Color color); // Draw icon using pixel size at specified position
  646. #endif
  647. // Controls
  648. //----------------------------------------------------------------------------------------------------------
  649. // Container/separator controls, useful for controls organization
  650. RAYGUIAPI int GuiWindowBox(Rectangle bounds, const char *title); // Window Box control, shows a window that can be closed
  651. RAYGUIAPI int GuiGroupBox(Rectangle bounds, const char *text); // Group Box control with text name
  652. RAYGUIAPI int GuiLine(Rectangle bounds, const char *text); // Line separator control, could contain text
  653. RAYGUIAPI int GuiPanel(Rectangle bounds, const char *text); // Panel control, useful to group controls
  654. RAYGUIAPI int GuiTabBar(Rectangle bounds, const char **text, int count, int *active); // Tab Bar control, returns TAB to be closed or -1
  655. RAYGUIAPI int GuiScrollPanel(Rectangle bounds, const char *text, Rectangle content, Vector2 *scroll, Rectangle *view); // Scroll Panel control
  656. // Basic controls set
  657. RAYGUIAPI int GuiLabel(Rectangle bounds, const char *text); // Label control, shows text
  658. RAYGUIAPI int GuiButton(Rectangle bounds, const char *text); // Button control, returns true when clicked
  659. RAYGUIAPI int GuiLabelButton(Rectangle bounds, const char *text); // Label button control, show true when clicked
  660. RAYGUIAPI int GuiToggle(Rectangle bounds, const char *text, bool *active); // Toggle Button control, returns true when active
  661. RAYGUIAPI int GuiToggleGroup(Rectangle bounds, const char *text, int *active); // Toggle Group control, returns active toggle index
  662. RAYGUIAPI int GuiToggleSlider(Rectangle bounds, const char *text, int *active); // Toggle Slider control, returns true when clicked
  663. RAYGUIAPI int GuiCheckBox(Rectangle bounds, const char *text, bool *checked); // Check Box control, returns true when active
  664. RAYGUIAPI int GuiComboBox(Rectangle bounds, const char *text, int *active); // Combo Box control, returns selected item index
  665. RAYGUIAPI int GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMode); // Dropdown Box control, returns selected item
  666. RAYGUIAPI int GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); // Spinner control, returns selected value
  667. RAYGUIAPI int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); // Value Box control, updates input text with numbers
  668. RAYGUIAPI int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode); // Text Box control, updates input text
  669. RAYGUIAPI int GuiSlider(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue); // Slider control, returns selected value
  670. RAYGUIAPI int GuiSliderBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue); // Slider Bar control, returns selected value
  671. RAYGUIAPI int GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue); // Progress Bar control, shows current progress value
  672. RAYGUIAPI int GuiStatusBar(Rectangle bounds, const char *text); // Status Bar control, shows info text
  673. RAYGUIAPI int GuiDummyRec(Rectangle bounds, const char *text); // Dummy control for placeholders
  674. RAYGUIAPI int GuiGrid(Rectangle bounds, const char *text, float spacing, int subdivs, Vector2 *mouseCell); // Grid control, returns mouse cell position
  675. // Advance controls set
  676. RAYGUIAPI int GuiListView(Rectangle bounds, const char *text, int *scrollIndex, int *active); // List View control, returns selected list item index
  677. RAYGUIAPI int GuiListViewEx(Rectangle bounds, const char **text, int count, int *scrollIndex, int *active, int *focus); // List View with extended parameters
  678. RAYGUIAPI int GuiMessageBox(Rectangle bounds, const char *title, const char *message, const char *buttons); // Message Box control, displays a message
  679. RAYGUIAPI int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text, int textMaxSize, bool *secretViewActive); // Text Input Box control, ask for text, supports secret
  680. RAYGUIAPI int GuiColorPicker(Rectangle bounds, const char *text, Color *color); // Color Picker control (multiple color controls)
  681. RAYGUIAPI int GuiColorPanel(Rectangle bounds, const char *text, Color *color); // Color Panel control
  682. RAYGUIAPI int GuiColorBarAlpha(Rectangle bounds, const char *text, float *alpha); // Color Bar Alpha control
  683. RAYGUIAPI int GuiColorBarHue(Rectangle bounds, const char *text, float *value); // Color Bar Hue control
  684. RAYGUIAPI int GuiColorPickerHSV(Rectangle bounds, const char *text, Vector3 *colorHsv); // Color Picker control that avoids conversion to RGB on each call (multiple color controls)
  685. RAYGUIAPI int GuiColorPanelHSV(Rectangle bounds, const char *text, Vector3 *colorHsv); // Color Panel control that returns HSV color value, used by GuiColorPickerHSV()
  686. //----------------------------------------------------------------------------------------------------------
  687. #if !defined(RAYGUI_NO_ICONS)
  688. #if !defined(RAYGUI_CUSTOM_ICONS)
  689. //----------------------------------------------------------------------------------
  690. // Icons enumeration
  691. //----------------------------------------------------------------------------------
  692. typedef enum {
  693. ICON_NONE = 0,
  694. ICON_FOLDER_FILE_OPEN = 1,
  695. ICON_FILE_SAVE_CLASSIC = 2,
  696. ICON_FOLDER_OPEN = 3,
  697. ICON_FOLDER_SAVE = 4,
  698. ICON_FILE_OPEN = 5,
  699. ICON_FILE_SAVE = 6,
  700. ICON_FILE_EXPORT = 7,
  701. ICON_FILE_ADD = 8,
  702. ICON_FILE_DELETE = 9,
  703. ICON_FILETYPE_TEXT = 10,
  704. ICON_FILETYPE_AUDIO = 11,
  705. ICON_FILETYPE_IMAGE = 12,
  706. ICON_FILETYPE_PLAY = 13,
  707. ICON_FILETYPE_VIDEO = 14,
  708. ICON_FILETYPE_INFO = 15,
  709. ICON_FILE_COPY = 16,
  710. ICON_FILE_CUT = 17,
  711. ICON_FILE_PASTE = 18,
  712. ICON_CURSOR_HAND = 19,
  713. ICON_CURSOR_POINTER = 20,
  714. ICON_CURSOR_CLASSIC = 21,
  715. ICON_PENCIL = 22,
  716. ICON_PENCIL_BIG = 23,
  717. ICON_BRUSH_CLASSIC = 24,
  718. ICON_BRUSH_PAINTER = 25,
  719. ICON_WATER_DROP = 26,
  720. ICON_COLOR_PICKER = 27,
  721. ICON_RUBBER = 28,
  722. ICON_COLOR_BUCKET = 29,
  723. ICON_TEXT_T = 30,
  724. ICON_TEXT_A = 31,
  725. ICON_SCALE = 32,
  726. ICON_RESIZE = 33,
  727. ICON_FILTER_POINT = 34,
  728. ICON_FILTER_BILINEAR = 35,
  729. ICON_CROP = 36,
  730. ICON_CROP_ALPHA = 37,
  731. ICON_SQUARE_TOGGLE = 38,
  732. ICON_SYMMETRY = 39,
  733. ICON_SYMMETRY_HORIZONTAL = 40,
  734. ICON_SYMMETRY_VERTICAL = 41,
  735. ICON_LENS = 42,
  736. ICON_LENS_BIG = 43,
  737. ICON_EYE_ON = 44,
  738. ICON_EYE_OFF = 45,
  739. ICON_FILTER_TOP = 46,
  740. ICON_FILTER = 47,
  741. ICON_TARGET_POINT = 48,
  742. ICON_TARGET_SMALL = 49,
  743. ICON_TARGET_BIG = 50,
  744. ICON_TARGET_MOVE = 51,
  745. ICON_CURSOR_MOVE = 52,
  746. ICON_CURSOR_SCALE = 53,
  747. ICON_CURSOR_SCALE_RIGHT = 54,
  748. ICON_CURSOR_SCALE_LEFT = 55,
  749. ICON_UNDO = 56,
  750. ICON_REDO = 57,
  751. ICON_REREDO = 58,
  752. ICON_MUTATE = 59,
  753. ICON_ROTATE = 60,
  754. ICON_REPEAT = 61,
  755. ICON_SHUFFLE = 62,
  756. ICON_EMPTYBOX = 63,
  757. ICON_TARGET = 64,
  758. ICON_TARGET_SMALL_FILL = 65,
  759. ICON_TARGET_BIG_FILL = 66,
  760. ICON_TARGET_MOVE_FILL = 67,
  761. ICON_CURSOR_MOVE_FILL = 68,
  762. ICON_CURSOR_SCALE_FILL = 69,
  763. ICON_CURSOR_SCALE_RIGHT_FILL = 70,
  764. ICON_CURSOR_SCALE_LEFT_FILL = 71,
  765. ICON_UNDO_FILL = 72,
  766. ICON_REDO_FILL = 73,
  767. ICON_REREDO_FILL = 74,
  768. ICON_MUTATE_FILL = 75,
  769. ICON_ROTATE_FILL = 76,
  770. ICON_REPEAT_FILL = 77,
  771. ICON_SHUFFLE_FILL = 78,
  772. ICON_EMPTYBOX_SMALL = 79,
  773. ICON_BOX = 80,
  774. ICON_BOX_TOP = 81,
  775. ICON_BOX_TOP_RIGHT = 82,
  776. ICON_BOX_RIGHT = 83,
  777. ICON_BOX_BOTTOM_RIGHT = 84,
  778. ICON_BOX_BOTTOM = 85,
  779. ICON_BOX_BOTTOM_LEFT = 86,
  780. ICON_BOX_LEFT = 87,
  781. ICON_BOX_TOP_LEFT = 88,
  782. ICON_BOX_CENTER = 89,
  783. ICON_BOX_CIRCLE_MASK = 90,
  784. ICON_POT = 91,
  785. ICON_ALPHA_MULTIPLY = 92,
  786. ICON_ALPHA_CLEAR = 93,
  787. ICON_DITHERING = 94,
  788. ICON_MIPMAPS = 95,
  789. ICON_BOX_GRID = 96,
  790. ICON_GRID = 97,
  791. ICON_BOX_CORNERS_SMALL = 98,
  792. ICON_BOX_CORNERS_BIG = 99,
  793. ICON_FOUR_BOXES = 100,
  794. ICON_GRID_FILL = 101,
  795. ICON_BOX_MULTISIZE = 102,
  796. ICON_ZOOM_SMALL = 103,
  797. ICON_ZOOM_MEDIUM = 104,
  798. ICON_ZOOM_BIG = 105,
  799. ICON_ZOOM_ALL = 106,
  800. ICON_ZOOM_CENTER = 107,
  801. ICON_BOX_DOTS_SMALL = 108,
  802. ICON_BOX_DOTS_BIG = 109,
  803. ICON_BOX_CONCENTRIC = 110,
  804. ICON_BOX_GRID_BIG = 111,
  805. ICON_OK_TICK = 112,
  806. ICON_CROSS = 113,
  807. ICON_ARROW_LEFT = 114,
  808. ICON_ARROW_RIGHT = 115,
  809. ICON_ARROW_DOWN = 116,
  810. ICON_ARROW_UP = 117,
  811. ICON_ARROW_LEFT_FILL = 118,
  812. ICON_ARROW_RIGHT_FILL = 119,
  813. ICON_ARROW_DOWN_FILL = 120,
  814. ICON_ARROW_UP_FILL = 121,
  815. ICON_AUDIO = 122,
  816. ICON_FX = 123,
  817. ICON_WAVE = 124,
  818. ICON_WAVE_SINUS = 125,
  819. ICON_WAVE_SQUARE = 126,
  820. ICON_WAVE_TRIANGULAR = 127,
  821. ICON_CROSS_SMALL = 128,
  822. ICON_PLAYER_PREVIOUS = 129,
  823. ICON_PLAYER_PLAY_BACK = 130,
  824. ICON_PLAYER_PLAY = 131,
  825. ICON_PLAYER_PAUSE = 132,
  826. ICON_PLAYER_STOP = 133,
  827. ICON_PLAYER_NEXT = 134,
  828. ICON_PLAYER_RECORD = 135,
  829. ICON_MAGNET = 136,
  830. ICON_LOCK_CLOSE = 137,
  831. ICON_LOCK_OPEN = 138,
  832. ICON_CLOCK = 139,
  833. ICON_TOOLS = 140,
  834. ICON_GEAR = 141,
  835. ICON_GEAR_BIG = 142,
  836. ICON_BIN = 143,
  837. ICON_HAND_POINTER = 144,
  838. ICON_LASER = 145,
  839. ICON_COIN = 146,
  840. ICON_EXPLOSION = 147,
  841. ICON_1UP = 148,
  842. ICON_PLAYER = 149,
  843. ICON_PLAYER_JUMP = 150,
  844. ICON_KEY = 151,
  845. ICON_DEMON = 152,
  846. ICON_TEXT_POPUP = 153,
  847. ICON_GEAR_EX = 154,
  848. ICON_CRACK = 155,
  849. ICON_CRACK_POINTS = 156,
  850. ICON_STAR = 157,
  851. ICON_DOOR = 158,
  852. ICON_EXIT = 159,
  853. ICON_MODE_2D = 160,
  854. ICON_MODE_3D = 161,
  855. ICON_CUBE = 162,
  856. ICON_CUBE_FACE_TOP = 163,
  857. ICON_CUBE_FACE_LEFT = 164,
  858. ICON_CUBE_FACE_FRONT = 165,
  859. ICON_CUBE_FACE_BOTTOM = 166,
  860. ICON_CUBE_FACE_RIGHT = 167,
  861. ICON_CUBE_FACE_BACK = 168,
  862. ICON_CAMERA = 169,
  863. ICON_SPECIAL = 170,
  864. ICON_LINK_NET = 171,
  865. ICON_LINK_BOXES = 172,
  866. ICON_LINK_MULTI = 173,
  867. ICON_LINK = 174,
  868. ICON_LINK_BROKE = 175,
  869. ICON_TEXT_NOTES = 176,
  870. ICON_NOTEBOOK = 177,
  871. ICON_SUITCASE = 178,
  872. ICON_SUITCASE_ZIP = 179,
  873. ICON_MAILBOX = 180,
  874. ICON_MONITOR = 181,
  875. ICON_PRINTER = 182,
  876. ICON_PHOTO_CAMERA = 183,
  877. ICON_PHOTO_CAMERA_FLASH = 184,
  878. ICON_HOUSE = 185,
  879. ICON_HEART = 186,
  880. ICON_CORNER = 187,
  881. ICON_VERTICAL_BARS = 188,
  882. ICON_VERTICAL_BARS_FILL = 189,
  883. ICON_LIFE_BARS = 190,
  884. ICON_INFO = 191,
  885. ICON_CROSSLINE = 192,
  886. ICON_HELP = 193,
  887. ICON_FILETYPE_ALPHA = 194,
  888. ICON_FILETYPE_HOME = 195,
  889. ICON_LAYERS_VISIBLE = 196,
  890. ICON_LAYERS = 197,
  891. ICON_WINDOW = 198,
  892. ICON_HIDPI = 199,
  893. ICON_FILETYPE_BINARY = 200,
  894. ICON_HEX = 201,
  895. ICON_SHIELD = 202,
  896. ICON_FILE_NEW = 203,
  897. ICON_FOLDER_ADD = 204,
  898. ICON_ALARM = 205,
  899. ICON_CPU = 206,
  900. ICON_ROM = 207,
  901. ICON_STEP_OVER = 208,
  902. ICON_STEP_INTO = 209,
  903. ICON_STEP_OUT = 210,
  904. ICON_RESTART = 211,
  905. ICON_BREAKPOINT_ON = 212,
  906. ICON_BREAKPOINT_OFF = 213,
  907. ICON_BURGER_MENU = 214,
  908. ICON_CASE_SENSITIVE = 215,
  909. ICON_REG_EXP = 216,
  910. ICON_FOLDER = 217,
  911. ICON_FILE = 218,
  912. ICON_SAND_TIMER = 219,
  913. ICON_220 = 220,
  914. ICON_221 = 221,
  915. ICON_222 = 222,
  916. ICON_223 = 223,
  917. ICON_224 = 224,
  918. ICON_225 = 225,
  919. ICON_226 = 226,
  920. ICON_227 = 227,
  921. ICON_228 = 228,
  922. ICON_229 = 229,
  923. ICON_230 = 230,
  924. ICON_231 = 231,
  925. ICON_232 = 232,
  926. ICON_233 = 233,
  927. ICON_234 = 234,
  928. ICON_235 = 235,
  929. ICON_236 = 236,
  930. ICON_237 = 237,
  931. ICON_238 = 238,
  932. ICON_239 = 239,
  933. ICON_240 = 240,
  934. ICON_241 = 241,
  935. ICON_242 = 242,
  936. ICON_243 = 243,
  937. ICON_244 = 244,
  938. ICON_245 = 245,
  939. ICON_246 = 246,
  940. ICON_247 = 247,
  941. ICON_248 = 248,
  942. ICON_249 = 249,
  943. ICON_250 = 250,
  944. ICON_251 = 251,
  945. ICON_252 = 252,
  946. ICON_253 = 253,
  947. ICON_254 = 254,
  948. ICON_255 = 255,
  949. } GuiIconName;
  950. #endif
  951. #endif
  952. #if defined(__cplusplus)
  953. } // Prevents name mangling of functions
  954. #endif
  955. #endif // RAYGUI_H
  956. /***********************************************************************************
  957. *
  958. * RAYGUI IMPLEMENTATION
  959. *
  960. ************************************************************************************/
  961. #if defined(RAYGUI_IMPLEMENTATION)
  962. #include <stdio.h> // Required for: FILE, fopen(), fclose(), fprintf(), feof(), fscanf(), vsprintf() [GuiLoadStyle(), GuiLoadIcons()]
  963. #include <stdlib.h> // Required for: malloc(), calloc(), free() [GuiLoadStyle(), GuiLoadIcons()]
  964. #include <string.h> // Required for: strlen() [GuiTextBox(), GuiValueBox()], memset(), memcpy()
  965. #include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end() [TextFormat()]
  966. #include <math.h> // Required for: roundf() [GuiColorPicker()]
  967. #ifdef __cplusplus
  968. #define RAYGUI_CLITERAL(name) name
  969. #else
  970. #define RAYGUI_CLITERAL(name) (name)
  971. #endif
  972. // Check if two rectangles are equal, used to validate a slider bounds as an id
  973. #ifndef CHECK_BOUNDS_ID
  974. #define CHECK_BOUNDS_ID(src, dst) ((src.x == dst.x) && (src.y == dst.y) && (src.width == dst.width) && (src.height == dst.height))
  975. #endif
  976. #if !defined(RAYGUI_NO_ICONS) && !defined(RAYGUI_CUSTOM_ICONS)
  977. // Embedded icons, no external file provided
  978. #define RAYGUI_ICON_SIZE 16 // Size of icons in pixels (squared)
  979. #define RAYGUI_ICON_MAX_ICONS 256 // Maximum number of icons
  980. #define RAYGUI_ICON_MAX_NAME_LENGTH 32 // Maximum length of icon name id
  981. // Icons data is defined by bit array (every bit represents one pixel)
  982. // Those arrays are stored as unsigned int data arrays, so,
  983. // every array element defines 32 pixels (bits) of information
  984. // One icon is defined by 8 int, (8 int * 32 bit = 256 bit = 16*16 pixels)
  985. // NOTE: Number of elemens depend on RAYGUI_ICON_SIZE (by default 16x16 pixels)
  986. #define RAYGUI_ICON_DATA_ELEMENTS (RAYGUI_ICON_SIZE*RAYGUI_ICON_SIZE/32)
  987. //----------------------------------------------------------------------------------
  988. // Icons data for all gui possible icons (allocated on data segment by default)
  989. //
  990. // NOTE 1: Every icon is codified in binary form, using 1 bit per pixel, so,
  991. // every 16x16 icon requires 8 integers (16*16/32) to be stored
  992. //
  993. // NOTE 2: A different icon set could be loaded over this array using GuiLoadIcons(),
  994. // but loaded icons set must be same RAYGUI_ICON_SIZE and no more than RAYGUI_ICON_MAX_ICONS
  995. //
  996. // guiIcons size is by default: 256*(16*16/32) = 2048*4 = 8192 bytes = 8 KB
  997. //----------------------------------------------------------------------------------
  998. static unsigned int guiIcons[RAYGUI_ICON_MAX_ICONS*RAYGUI_ICON_DATA_ELEMENTS] = {
  999. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_NONE
  1000. 0x3ff80000, 0x2f082008, 0x2042207e, 0x40027fc2, 0x40024002, 0x40024002, 0x40024002, 0x00007ffe, // ICON_FOLDER_FILE_OPEN
  1001. 0x3ffe0000, 0x44226422, 0x400247e2, 0x5ffa4002, 0x57ea500a, 0x500a500a, 0x40025ffa, 0x00007ffe, // ICON_FILE_SAVE_CLASSIC
  1002. 0x00000000, 0x0042007e, 0x40027fc2, 0x40024002, 0x41024002, 0x44424282, 0x793e4102, 0x00000100, // ICON_FOLDER_OPEN
  1003. 0x00000000, 0x0042007e, 0x40027fc2, 0x40024002, 0x41024102, 0x44424102, 0x793e4282, 0x00000000, // ICON_FOLDER_SAVE
  1004. 0x3ff00000, 0x201c2010, 0x20042004, 0x21042004, 0x24442284, 0x21042104, 0x20042104, 0x00003ffc, // ICON_FILE_OPEN
  1005. 0x3ff00000, 0x201c2010, 0x20042004, 0x21042004, 0x21042104, 0x22842444, 0x20042104, 0x00003ffc, // ICON_FILE_SAVE
  1006. 0x3ff00000, 0x201c2010, 0x00042004, 0x20041004, 0x20844784, 0x00841384, 0x20042784, 0x00003ffc, // ICON_FILE_EXPORT
  1007. 0x3ff00000, 0x201c2010, 0x20042004, 0x20042004, 0x22042204, 0x22042f84, 0x20042204, 0x00003ffc, // ICON_FILE_ADD
  1008. 0x3ff00000, 0x201c2010, 0x20042004, 0x20042004, 0x25042884, 0x25042204, 0x20042884, 0x00003ffc, // ICON_FILE_DELETE
  1009. 0x3ff00000, 0x201c2010, 0x20042004, 0x20042ff4, 0x20042ff4, 0x20042ff4, 0x20042004, 0x00003ffc, // ICON_FILETYPE_TEXT
  1010. 0x3ff00000, 0x201c2010, 0x27042004, 0x244424c4, 0x26442444, 0x20642664, 0x20042004, 0x00003ffc, // ICON_FILETYPE_AUDIO
  1011. 0x3ff00000, 0x201c2010, 0x26042604, 0x20042004, 0x35442884, 0x2414222c, 0x20042004, 0x00003ffc, // ICON_FILETYPE_IMAGE
  1012. 0x3ff00000, 0x201c2010, 0x20c42004, 0x22442144, 0x22442444, 0x20c42144, 0x20042004, 0x00003ffc, // ICON_FILETYPE_PLAY
  1013. 0x3ff00000, 0x3ffc2ff0, 0x3f3c2ff4, 0x3dbc2eb4, 0x3dbc2bb4, 0x3f3c2eb4, 0x3ffc2ff4, 0x00002ff4, // ICON_FILETYPE_VIDEO
  1014. 0x3ff00000, 0x201c2010, 0x21842184, 0x21842004, 0x21842184, 0x21842184, 0x20042184, 0x00003ffc, // ICON_FILETYPE_INFO
  1015. 0x0ff00000, 0x381c0810, 0x28042804, 0x28042804, 0x28042804, 0x28042804, 0x20102ffc, 0x00003ff0, // ICON_FILE_COPY
  1016. 0x00000000, 0x701c0000, 0x079c1e14, 0x55a000f0, 0x079c00f0, 0x701c1e14, 0x00000000, 0x00000000, // ICON_FILE_CUT
  1017. 0x01c00000, 0x13e41bec, 0x3f841004, 0x204420c4, 0x20442044, 0x20442044, 0x207c2044, 0x00003fc0, // ICON_FILE_PASTE
  1018. 0x00000000, 0x3aa00fe0, 0x2abc2aa0, 0x2aa42aa4, 0x20042aa4, 0x20042004, 0x3ffc2004, 0x00000000, // ICON_CURSOR_HAND
  1019. 0x00000000, 0x003c000c, 0x030800c8, 0x30100c10, 0x10202020, 0x04400840, 0x01800280, 0x00000000, // ICON_CURSOR_POINTER
  1020. 0x00000000, 0x00180000, 0x01f00078, 0x03e007f0, 0x07c003e0, 0x04000e40, 0x00000000, 0x00000000, // ICON_CURSOR_CLASSIC
  1021. 0x00000000, 0x04000000, 0x11000a00, 0x04400a80, 0x01100220, 0x00580088, 0x00000038, 0x00000000, // ICON_PENCIL
  1022. 0x04000000, 0x15000a00, 0x50402880, 0x14102820, 0x05040a08, 0x015c028c, 0x007c00bc, 0x00000000, // ICON_PENCIL_BIG
  1023. 0x01c00000, 0x01400140, 0x01400140, 0x0ff80140, 0x0ff80808, 0x0aa80808, 0x0aa80aa8, 0x00000ff8, // ICON_BRUSH_CLASSIC
  1024. 0x1ffc0000, 0x5ffc7ffe, 0x40004000, 0x00807f80, 0x01c001c0, 0x01c001c0, 0x01c001c0, 0x00000080, // ICON_BRUSH_PAINTER
  1025. 0x00000000, 0x00800000, 0x01c00080, 0x03e001c0, 0x07f003e0, 0x036006f0, 0x000001c0, 0x00000000, // ICON_WATER_DROP
  1026. 0x00000000, 0x3e003800, 0x1f803f80, 0x0c201e40, 0x02080c10, 0x00840104, 0x00380044, 0x00000000, // ICON_COLOR_PICKER
  1027. 0x00000000, 0x07800300, 0x1fe00fc0, 0x3f883fd0, 0x0e021f04, 0x02040402, 0x00f00108, 0x00000000, // ICON_RUBBER
  1028. 0x00c00000, 0x02800140, 0x08200440, 0x20081010, 0x2ffe3004, 0x03f807fc, 0x00e001f0, 0x00000040, // ICON_COLOR_BUCKET
  1029. 0x00000000, 0x21843ffc, 0x01800180, 0x01800180, 0x01800180, 0x01800180, 0x03c00180, 0x00000000, // ICON_TEXT_T
  1030. 0x00800000, 0x01400180, 0x06200340, 0x0c100620, 0x1ff80c10, 0x380c1808, 0x70067004, 0x0000f80f, // ICON_TEXT_A
  1031. 0x78000000, 0x50004000, 0x00004800, 0x03c003c0, 0x03c003c0, 0x00100000, 0x0002000a, 0x0000000e, // ICON_SCALE
  1032. 0x75560000, 0x5e004002, 0x54001002, 0x41001202, 0x408200fe, 0x40820082, 0x40820082, 0x00006afe, // ICON_RESIZE
  1033. 0x00000000, 0x3f003f00, 0x3f003f00, 0x3f003f00, 0x00400080, 0x001c0020, 0x001c001c, 0x00000000, // ICON_FILTER_POINT
  1034. 0x6d800000, 0x00004080, 0x40804080, 0x40800000, 0x00406d80, 0x001c0020, 0x001c001c, 0x00000000, // ICON_FILTER_BILINEAR
  1035. 0x40080000, 0x1ffe2008, 0x14081008, 0x11081208, 0x10481088, 0x10081028, 0x10047ff8, 0x00001002, // ICON_CROP
  1036. 0x00100000, 0x3ffc0010, 0x2ab03550, 0x22b02550, 0x20b02150, 0x20302050, 0x2000fff0, 0x00002000, // ICON_CROP_ALPHA
  1037. 0x40000000, 0x1ff82000, 0x04082808, 0x01082208, 0x00482088, 0x00182028, 0x35542008, 0x00000002, // ICON_SQUARE_TOGGLE
  1038. 0x00000000, 0x02800280, 0x06c006c0, 0x0ea00ee0, 0x1e901eb0, 0x3e883e98, 0x7efc7e8c, 0x00000000, // ICON_SYMMETRY
  1039. 0x01000000, 0x05600100, 0x1d480d50, 0x7d423d44, 0x3d447d42, 0x0d501d48, 0x01000560, 0x00000100, // ICON_SYMMETRY_HORIZONTAL
  1040. 0x01800000, 0x04200240, 0x10080810, 0x00001ff8, 0x00007ffe, 0x0ff01ff8, 0x03c007e0, 0x00000180, // ICON_SYMMETRY_VERTICAL
  1041. 0x00000000, 0x010800f0, 0x02040204, 0x02040204, 0x07f00308, 0x1c000e00, 0x30003800, 0x00000000, // ICON_LENS
  1042. 0x00000000, 0x061803f0, 0x08240c0c, 0x08040814, 0x0c0c0804, 0x23f01618, 0x18002400, 0x00000000, // ICON_LENS_BIG
  1043. 0x00000000, 0x00000000, 0x1c7007c0, 0x638e3398, 0x1c703398, 0x000007c0, 0x00000000, 0x00000000, // ICON_EYE_ON
  1044. 0x00000000, 0x10002000, 0x04700fc0, 0x610e3218, 0x1c703098, 0x001007a0, 0x00000008, 0x00000000, // ICON_EYE_OFF
  1045. 0x00000000, 0x00007ffc, 0x40047ffc, 0x10102008, 0x04400820, 0x02800280, 0x02800280, 0x00000100, // ICON_FILTER_TOP
  1046. 0x00000000, 0x40027ffe, 0x10082004, 0x04200810, 0x02400240, 0x02400240, 0x01400240, 0x000000c0, // ICON_FILTER
  1047. 0x00800000, 0x00800080, 0x00000080, 0x3c9e0000, 0x00000000, 0x00800080, 0x00800080, 0x00000000, // ICON_TARGET_POINT
  1048. 0x00800000, 0x00800080, 0x00800080, 0x3f7e01c0, 0x008001c0, 0x00800080, 0x00800080, 0x00000000, // ICON_TARGET_SMALL
  1049. 0x00800000, 0x00800080, 0x03e00080, 0x3e3e0220, 0x03e00220, 0x00800080, 0x00800080, 0x00000000, // ICON_TARGET_BIG
  1050. 0x01000000, 0x04400280, 0x01000100, 0x43842008, 0x43849ab2, 0x01002008, 0x04400100, 0x01000280, // ICON_TARGET_MOVE
  1051. 0x01000000, 0x04400280, 0x01000100, 0x41042108, 0x41049ff2, 0x01002108, 0x04400100, 0x01000280, // ICON_CURSOR_MOVE
  1052. 0x781e0000, 0x500a4002, 0x04204812, 0x00000240, 0x02400000, 0x48120420, 0x4002500a, 0x0000781e, // ICON_CURSOR_SCALE
  1053. 0x00000000, 0x20003c00, 0x24002800, 0x01000200, 0x00400080, 0x00140024, 0x003c0004, 0x00000000, // ICON_CURSOR_SCALE_RIGHT
  1054. 0x00000000, 0x0004003c, 0x00240014, 0x00800040, 0x02000100, 0x28002400, 0x3c002000, 0x00000000, // ICON_CURSOR_SCALE_LEFT
  1055. 0x00000000, 0x00100020, 0x10101fc8, 0x10001020, 0x10001000, 0x10001000, 0x00001fc0, 0x00000000, // ICON_UNDO
  1056. 0x00000000, 0x08000400, 0x080813f8, 0x00080408, 0x00080008, 0x00080008, 0x000003f8, 0x00000000, // ICON_REDO
  1057. 0x00000000, 0x3ffc0000, 0x20042004, 0x20002000, 0x20402000, 0x3f902020, 0x00400020, 0x00000000, // ICON_REREDO
  1058. 0x00000000, 0x3ffc0000, 0x20042004, 0x27fc2004, 0x20202000, 0x3fc82010, 0x00200010, 0x00000000, // ICON_MUTATE
  1059. 0x00000000, 0x0ff00000, 0x10081818, 0x11801008, 0x10001180, 0x18101020, 0x00100fc8, 0x00000020, // ICON_ROTATE
  1060. 0x00000000, 0x04000200, 0x240429fc, 0x20042204, 0x20442004, 0x3f942024, 0x00400020, 0x00000000, // ICON_REPEAT
  1061. 0x00000000, 0x20001000, 0x22104c0e, 0x00801120, 0x11200040, 0x4c0e2210, 0x10002000, 0x00000000, // ICON_SHUFFLE
  1062. 0x7ffe0000, 0x50024002, 0x44024802, 0x41024202, 0x40424082, 0x40124022, 0x4002400a, 0x00007ffe, // ICON_EMPTYBOX
  1063. 0x00800000, 0x03e00080, 0x08080490, 0x3c9e0808, 0x08080808, 0x03e00490, 0x00800080, 0x00000000, // ICON_TARGET
  1064. 0x00800000, 0x00800080, 0x00800080, 0x3ffe01c0, 0x008001c0, 0x00800080, 0x00800080, 0x00000000, // ICON_TARGET_SMALL_FILL
  1065. 0x00800000, 0x00800080, 0x03e00080, 0x3ffe03e0, 0x03e003e0, 0x00800080, 0x00800080, 0x00000000, // ICON_TARGET_BIG_FILL
  1066. 0x01000000, 0x07c00380, 0x01000100, 0x638c2008, 0x638cfbbe, 0x01002008, 0x07c00100, 0x01000380, // ICON_TARGET_MOVE_FILL
  1067. 0x01000000, 0x07c00380, 0x01000100, 0x610c2108, 0x610cfffe, 0x01002108, 0x07c00100, 0x01000380, // ICON_CURSOR_MOVE_FILL
  1068. 0x781e0000, 0x6006700e, 0x04204812, 0x00000240, 0x02400000, 0x48120420, 0x700e6006, 0x0000781e, // ICON_CURSOR_SCALE_FILL
  1069. 0x00000000, 0x38003c00, 0x24003000, 0x01000200, 0x00400080, 0x000c0024, 0x003c001c, 0x00000000, // ICON_CURSOR_SCALE_RIGHT_FILL
  1070. 0x00000000, 0x001c003c, 0x0024000c, 0x00800040, 0x02000100, 0x30002400, 0x3c003800, 0x00000000, // ICON_CURSOR_SCALE_LEFT_FILL
  1071. 0x00000000, 0x00300020, 0x10301ff8, 0x10001020, 0x10001000, 0x10001000, 0x00001fc0, 0x00000000, // ICON_UNDO_FILL
  1072. 0x00000000, 0x0c000400, 0x0c081ff8, 0x00080408, 0x00080008, 0x00080008, 0x000003f8, 0x00000000, // ICON_REDO_FILL
  1073. 0x00000000, 0x3ffc0000, 0x20042004, 0x20002000, 0x20402000, 0x3ff02060, 0x00400060, 0x00000000, // ICON_REREDO_FILL
  1074. 0x00000000, 0x3ffc0000, 0x20042004, 0x27fc2004, 0x20202000, 0x3ff82030, 0x00200030, 0x00000000, // ICON_MUTATE_FILL
  1075. 0x00000000, 0x0ff00000, 0x10081818, 0x11801008, 0x10001180, 0x18301020, 0x00300ff8, 0x00000020, // ICON_ROTATE_FILL
  1076. 0x00000000, 0x06000200, 0x26042ffc, 0x20042204, 0x20442004, 0x3ff42064, 0x00400060, 0x00000000, // ICON_REPEAT_FILL
  1077. 0x00000000, 0x30001000, 0x32107c0e, 0x00801120, 0x11200040, 0x7c0e3210, 0x10003000, 0x00000000, // ICON_SHUFFLE_FILL
  1078. 0x00000000, 0x30043ffc, 0x24042804, 0x21042204, 0x20442084, 0x20142024, 0x3ffc200c, 0x00000000, // ICON_EMPTYBOX_SMALL
  1079. 0x00000000, 0x20043ffc, 0x20042004, 0x20042004, 0x20042004, 0x20042004, 0x3ffc2004, 0x00000000, // ICON_BOX
  1080. 0x00000000, 0x23c43ffc, 0x23c423c4, 0x200423c4, 0x20042004, 0x20042004, 0x3ffc2004, 0x00000000, // ICON_BOX_TOP
  1081. 0x00000000, 0x3e043ffc, 0x3e043e04, 0x20043e04, 0x20042004, 0x20042004, 0x3ffc2004, 0x00000000, // ICON_BOX_TOP_RIGHT
  1082. 0x00000000, 0x20043ffc, 0x20042004, 0x3e043e04, 0x3e043e04, 0x20042004, 0x3ffc2004, 0x00000000, // ICON_BOX_RIGHT
  1083. 0x00000000, 0x20043ffc, 0x20042004, 0x20042004, 0x3e042004, 0x3e043e04, 0x3ffc3e04, 0x00000000, // ICON_BOX_BOTTOM_RIGHT
  1084. 0x00000000, 0x20043ffc, 0x20042004, 0x20042004, 0x23c42004, 0x23c423c4, 0x3ffc23c4, 0x00000000, // ICON_BOX_BOTTOM
  1085. 0x00000000, 0x20043ffc, 0x20042004, 0x20042004, 0x207c2004, 0x207c207c, 0x3ffc207c, 0x00000000, // ICON_BOX_BOTTOM_LEFT
  1086. 0x00000000, 0x20043ffc, 0x20042004, 0x207c207c, 0x207c207c, 0x20042004, 0x3ffc2004, 0x00000000, // ICON_BOX_LEFT
  1087. 0x00000000, 0x207c3ffc, 0x207c207c, 0x2004207c, 0x20042004, 0x20042004, 0x3ffc2004, 0x00000000, // ICON_BOX_TOP_LEFT
  1088. 0x00000000, 0x20043ffc, 0x20042004, 0x23c423c4, 0x23c423c4, 0x20042004, 0x3ffc2004, 0x00000000, // ICON_BOX_CENTER
  1089. 0x7ffe0000, 0x40024002, 0x47e24182, 0x4ff247e2, 0x47e24ff2, 0x418247e2, 0x40024002, 0x00007ffe, // ICON_BOX_CIRCLE_MASK
  1090. 0x7fff0000, 0x40014001, 0x40014001, 0x49555ddd, 0x4945495d, 0x400149c5, 0x40014001, 0x00007fff, // ICON_POT
  1091. 0x7ffe0000, 0x53327332, 0x44ce4cce, 0x41324332, 0x404e40ce, 0x48125432, 0x4006540e, 0x00007ffe, // ICON_ALPHA_MULTIPLY
  1092. 0x7ffe0000, 0x53327332, 0x44ce4cce, 0x41324332, 0x5c4e40ce, 0x44124432, 0x40065c0e, 0x00007ffe, // ICON_ALPHA_CLEAR
  1093. 0x7ffe0000, 0x42fe417e, 0x42fe417e, 0x42fe417e, 0x42fe417e, 0x42fe417e, 0x42fe417e, 0x00007ffe, // ICON_DITHERING
  1094. 0x07fe0000, 0x1ffa0002, 0x7fea000a, 0x402a402a, 0x5b2a512a, 0x5128552a, 0x40205128, 0x00007fe0, // ICON_MIPMAPS
  1095. 0x00000000, 0x1ff80000, 0x12481248, 0x12481ff8, 0x1ff81248, 0x12481248, 0x00001ff8, 0x00000000, // ICON_BOX_GRID
  1096. 0x12480000, 0x7ffe1248, 0x12481248, 0x12487ffe, 0x7ffe1248, 0x12481248, 0x12487ffe, 0x00001248, // ICON_GRID
  1097. 0x00000000, 0x1c380000, 0x1c3817e8, 0x08100810, 0x08100810, 0x17e81c38, 0x00001c38, 0x00000000, // ICON_BOX_CORNERS_SMALL
  1098. 0x700e0000, 0x700e5ffa, 0x20042004, 0x20042004, 0x20042004, 0x20042004, 0x5ffa700e, 0x0000700e, // ICON_BOX_CORNERS_BIG
  1099. 0x3f7e0000, 0x21422142, 0x21422142, 0x00003f7e, 0x21423f7e, 0x21422142, 0x3f7e2142, 0x00000000, // ICON_FOUR_BOXES
  1100. 0x00000000, 0x3bb80000, 0x3bb83bb8, 0x3bb80000, 0x3bb83bb8, 0x3bb80000, 0x3bb83bb8, 0x00000000, // ICON_GRID_FILL
  1101. 0x7ffe0000, 0x7ffe7ffe, 0x77fe7000, 0x77fe77fe, 0x777e7700, 0x777e777e, 0x777e777e, 0x0000777e, // ICON_BOX_MULTISIZE
  1102. 0x781e0000, 0x40024002, 0x00004002, 0x01800000, 0x00000180, 0x40020000, 0x40024002, 0x0000781e, // ICON_ZOOM_SMALL
  1103. 0x781e0000, 0x40024002, 0x00004002, 0x03c003c0, 0x03c003c0, 0x40020000, 0x40024002, 0x0000781e, // ICON_ZOOM_MEDIUM
  1104. 0x781e0000, 0x40024002, 0x07e04002, 0x07e007e0, 0x07e007e0, 0x400207e0, 0x40024002, 0x0000781e, // ICON_ZOOM_BIG
  1105. 0x781e0000, 0x5ffa4002, 0x1ff85ffa, 0x1ff81ff8, 0x1ff81ff8, 0x5ffa1ff8, 0x40025ffa, 0x0000781e, // ICON_ZOOM_ALL
  1106. 0x00000000, 0x2004381c, 0x00002004, 0x00000000, 0x00000000, 0x20040000, 0x381c2004, 0x00000000, // ICON_ZOOM_CENTER
  1107. 0x00000000, 0x1db80000, 0x10081008, 0x10080000, 0x00001008, 0x10081008, 0x00001db8, 0x00000000, // ICON_BOX_DOTS_SMALL
  1108. 0x35560000, 0x00002002, 0x00002002, 0x00002002, 0x00002002, 0x00002002, 0x35562002, 0x00000000, // ICON_BOX_DOTS_BIG
  1109. 0x7ffe0000, 0x40024002, 0x48124ff2, 0x49924812, 0x48124992, 0x4ff24812, 0x40024002, 0x00007ffe, // ICON_BOX_CONCENTRIC
  1110. 0x00000000, 0x10841ffc, 0x10841084, 0x1ffc1084, 0x10841084, 0x10841084, 0x00001ffc, 0x00000000, // ICON_BOX_GRID_BIG
  1111. 0x00000000, 0x00000000, 0x10000000, 0x04000800, 0x01040200, 0x00500088, 0x00000020, 0x00000000, // ICON_OK_TICK
  1112. 0x00000000, 0x10080000, 0x04200810, 0x01800240, 0x02400180, 0x08100420, 0x00001008, 0x00000000, // ICON_CROSS
  1113. 0x00000000, 0x02000000, 0x00800100, 0x00200040, 0x00200010, 0x00800040, 0x02000100, 0x00000000, // ICON_ARROW_LEFT
  1114. 0x00000000, 0x00400000, 0x01000080, 0x04000200, 0x04000800, 0x01000200, 0x00400080, 0x00000000, // ICON_ARROW_RIGHT
  1115. 0x00000000, 0x00000000, 0x00000000, 0x08081004, 0x02200410, 0x00800140, 0x00000000, 0x00000000, // ICON_ARROW_DOWN
  1116. 0x00000000, 0x00000000, 0x01400080, 0x04100220, 0x10040808, 0x00000000, 0x00000000, 0x00000000, // ICON_ARROW_UP
  1117. 0x00000000, 0x02000000, 0x03800300, 0x03e003c0, 0x03e003f0, 0x038003c0, 0x02000300, 0x00000000, // ICON_ARROW_LEFT_FILL
  1118. 0x00000000, 0x00400000, 0x01c000c0, 0x07c003c0, 0x07c00fc0, 0x01c003c0, 0x004000c0, 0x00000000, // ICON_ARROW_RIGHT_FILL
  1119. 0x00000000, 0x00000000, 0x00000000, 0x0ff81ffc, 0x03e007f0, 0x008001c0, 0x00000000, 0x00000000, // ICON_ARROW_DOWN_FILL
  1120. 0x00000000, 0x00000000, 0x01c00080, 0x07f003e0, 0x1ffc0ff8, 0x00000000, 0x00000000, 0x00000000, // ICON_ARROW_UP_FILL
  1121. 0x00000000, 0x18a008c0, 0x32881290, 0x24822686, 0x26862482, 0x12903288, 0x08c018a0, 0x00000000, // ICON_AUDIO
  1122. 0x00000000, 0x04800780, 0x004000c0, 0x662000f0, 0x08103c30, 0x130a0e18, 0x0000318e, 0x00000000, // ICON_FX
  1123. 0x00000000, 0x00800000, 0x08880888, 0x2aaa0a8a, 0x0a8a2aaa, 0x08880888, 0x00000080, 0x00000000, // ICON_WAVE
  1124. 0x00000000, 0x00600000, 0x01080090, 0x02040108, 0x42044204, 0x24022402, 0x00001800, 0x00000000, // ICON_WAVE_SINUS
  1125. 0x00000000, 0x07f80000, 0x04080408, 0x04080408, 0x04080408, 0x7c0e0408, 0x00000000, 0x00000000, // ICON_WAVE_SQUARE
  1126. 0x00000000, 0x00000000, 0x00a00040, 0x22084110, 0x08021404, 0x00000000, 0x00000000, 0x00000000, // ICON_WAVE_TRIANGULAR
  1127. 0x00000000, 0x00000000, 0x04200000, 0x01800240, 0x02400180, 0x00000420, 0x00000000, 0x00000000, // ICON_CROSS_SMALL
  1128. 0x00000000, 0x18380000, 0x12281428, 0x10a81128, 0x112810a8, 0x14281228, 0x00001838, 0x00000000, // ICON_PLAYER_PREVIOUS
  1129. 0x00000000, 0x18000000, 0x11801600, 0x10181060, 0x10601018, 0x16001180, 0x00001800, 0x00000000, // ICON_PLAYER_PLAY_BACK
  1130. 0x00000000, 0x00180000, 0x01880068, 0x18080608, 0x06081808, 0x00680188, 0x00000018, 0x00000000, // ICON_PLAYER_PLAY
  1131. 0x00000000, 0x1e780000, 0x12481248, 0x12481248, 0x12481248, 0x12481248, 0x00001e78, 0x00000000, // ICON_PLAYER_PAUSE
  1132. 0x00000000, 0x1ff80000, 0x10081008, 0x10081008, 0x10081008, 0x10081008, 0x00001ff8, 0x00000000, // ICON_PLAYER_STOP
  1133. 0x00000000, 0x1c180000, 0x14481428, 0x15081488, 0x14881508, 0x14281448, 0x00001c18, 0x00000000, // ICON_PLAYER_NEXT
  1134. 0x00000000, 0x03c00000, 0x08100420, 0x10081008, 0x10081008, 0x04200810, 0x000003c0, 0x00000000, // ICON_PLAYER_RECORD
  1135. 0x00000000, 0x0c3007e0, 0x13c81818, 0x14281668, 0x14281428, 0x1c381c38, 0x08102244, 0x00000000, // ICON_MAGNET
  1136. 0x07c00000, 0x08200820, 0x3ff80820, 0x23882008, 0x21082388, 0x20082108, 0x1ff02008, 0x00000000, // ICON_LOCK_CLOSE
  1137. 0x07c00000, 0x08000800, 0x3ff80800, 0x23882008, 0x21082388, 0x20082108, 0x1ff02008, 0x00000000, // ICON_LOCK_OPEN
  1138. 0x01c00000, 0x0c180770, 0x3086188c, 0x60832082, 0x60034781, 0x30062002, 0x0c18180c, 0x01c00770, // ICON_CLOCK
  1139. 0x0a200000, 0x1b201b20, 0x04200e20, 0x04200420, 0x04700420, 0x0e700e70, 0x0e700e70, 0x04200e70, // ICON_TOOLS
  1140. 0x01800000, 0x3bdc318c, 0x0ff01ff8, 0x7c3e1e78, 0x1e787c3e, 0x1ff80ff0, 0x318c3bdc, 0x00000180, // ICON_GEAR
  1141. 0x01800000, 0x3ffc318c, 0x1c381ff8, 0x781e1818, 0x1818781e, 0x1ff81c38, 0x318c3ffc, 0x00000180, // ICON_GEAR_BIG
  1142. 0x00000000, 0x08080ff8, 0x08081ffc, 0x0aa80aa8, 0x0aa80aa8, 0x0aa80aa8, 0x08080aa8, 0x00000ff8, // ICON_BIN
  1143. 0x00000000, 0x00000000, 0x20043ffc, 0x08043f84, 0x04040f84, 0x04040784, 0x000007fc, 0x00000000, // ICON_HAND_POINTER
  1144. 0x00000000, 0x24400400, 0x00001480, 0x6efe0e00, 0x00000e00, 0x24401480, 0x00000400, 0x00000000, // ICON_LASER
  1145. 0x00000000, 0x03c00000, 0x08300460, 0x11181118, 0x11181118, 0x04600830, 0x000003c0, 0x00000000, // ICON_COIN
  1146. 0x00000000, 0x10880080, 0x06c00810, 0x366c07e0, 0x07e00240, 0x00001768, 0x04200240, 0x00000000, // ICON_EXPLOSION
  1147. 0x00000000, 0x3d280000, 0x2528252c, 0x3d282528, 0x05280528, 0x05e80528, 0x00000000, 0x00000000, // ICON_1UP
  1148. 0x01800000, 0x03c003c0, 0x018003c0, 0x0ff007e0, 0x0bd00bd0, 0x0a500bd0, 0x02400240, 0x02400240, // ICON_PLAYER
  1149. 0x01800000, 0x03c003c0, 0x118013c0, 0x03c81ff8, 0x07c003c8, 0x04400440, 0x0c080478, 0x00000000, // ICON_PLAYER_JUMP
  1150. 0x3ff80000, 0x30183ff8, 0x30183018, 0x3ff83ff8, 0x03000300, 0x03c003c0, 0x03e00300, 0x000003e0, // ICON_KEY
  1151. 0x3ff80000, 0x3ff83ff8, 0x33983ff8, 0x3ff83398, 0x3ff83ff8, 0x00000540, 0x0fe00aa0, 0x00000fe0, // ICON_DEMON
  1152. 0x00000000, 0x0ff00000, 0x20041008, 0x25442004, 0x10082004, 0x06000bf0, 0x00000300, 0x00000000, // ICON_TEXT_POPUP
  1153. 0x00000000, 0x11440000, 0x07f00be8, 0x1c1c0e38, 0x1c1c0c18, 0x07f00e38, 0x11440be8, 0x00000000, // ICON_GEAR_EX
  1154. 0x00000000, 0x20080000, 0x0c601010, 0x07c00fe0, 0x07c007c0, 0x0c600fe0, 0x20081010, 0x00000000, // ICON_CRACK
  1155. 0x00000000, 0x20080000, 0x0c601010, 0x04400fe0, 0x04405554, 0x0c600fe0, 0x20081010, 0x00000000, // ICON_CRACK_POINTS
  1156. 0x00000000, 0x00800080, 0x01c001c0, 0x1ffc3ffe, 0x03e007f0, 0x07f003e0, 0x0c180770, 0x00000808, // ICON_STAR
  1157. 0x0ff00000, 0x08180810, 0x08100818, 0x0a100810, 0x08180810, 0x08100818, 0x08100810, 0x00001ff8, // ICON_DOOR
  1158. 0x0ff00000, 0x08100810, 0x08100810, 0x10100010, 0x4f902010, 0x10102010, 0x08100010, 0x00000ff0, // ICON_EXIT
  1159. 0x00040000, 0x001f000e, 0x0ef40004, 0x12f41284, 0x0ef41214, 0x10040004, 0x7ffc3004, 0x10003000, // ICON_MODE_2D
  1160. 0x78040000, 0x501f600e, 0x0ef44004, 0x12f41284, 0x0ef41284, 0x10140004, 0x7ffc300c, 0x10003000, // ICON_MODE_3D
  1161. 0x7fe00000, 0x50286030, 0x47fe4804, 0x44224402, 0x44224422, 0x241275e2, 0x0c06140a, 0x000007fe, // ICON_CUBE
  1162. 0x7fe00000, 0x5ff87ff0, 0x47fe4ffc, 0x44224402, 0x44224422, 0x241275e2, 0x0c06140a, 0x000007fe, // ICON_CUBE_FACE_TOP
  1163. 0x7fe00000, 0x50386030, 0x47c2483c, 0x443e443e, 0x443e443e, 0x241e75fe, 0x0c06140e, 0x000007fe, // ICON_CUBE_FACE_LEFT
  1164. 0x7fe00000, 0x50286030, 0x47fe4804, 0x47fe47fe, 0x47fe47fe, 0x27fe77fe, 0x0ffe17fe, 0x000007fe, // ICON_CUBE_FACE_FRONT
  1165. 0x7fe00000, 0x50286030, 0x47fe4804, 0x44224402, 0x44224422, 0x3bf27be2, 0x0bfe1bfa, 0x000007fe, // ICON_CUBE_FACE_BOTTOM
  1166. 0x7fe00000, 0x70286030, 0x7ffe7804, 0x7c227c02, 0x7c227c22, 0x3c127de2, 0x0c061c0a, 0x000007fe, // ICON_CUBE_FACE_RIGHT
  1167. 0x7fe00000, 0x6fe85ff0, 0x781e77e4, 0x7be27be2, 0x7be27be2, 0x24127be2, 0x0c06140a, 0x000007fe, // ICON_CUBE_FACE_BACK
  1168. 0x00000000, 0x2a0233fe, 0x22022602, 0x22022202, 0x2a022602, 0x00a033fe, 0x02080110, 0x00000000, // ICON_CAMERA
  1169. 0x00000000, 0x200c3ffc, 0x000c000c, 0x3ffc000c, 0x30003000, 0x30003000, 0x3ffc3004, 0x00000000, // ICON_SPECIAL
  1170. 0x00000000, 0x0022003e, 0x012201e2, 0x0100013e, 0x01000100, 0x79000100, 0x4f004900, 0x00007800, // ICON_LINK_NET
  1171. 0x00000000, 0x44007c00, 0x45004600, 0x00627cbe, 0x00620022, 0x45007cbe, 0x44004600, 0x00007c00, // ICON_LINK_BOXES
  1172. 0x00000000, 0x0044007c, 0x0010007c, 0x3f100010, 0x3f1021f0, 0x3f100010, 0x3f0021f0, 0x00000000, // ICON_LINK_MULTI
  1173. 0x00000000, 0x0044007c, 0x00440044, 0x0010007c, 0x00100010, 0x44107c10, 0x440047f0, 0x00007c00, // ICON_LINK
  1174. 0x00000000, 0x0044007c, 0x00440044, 0x0000007c, 0x00000010, 0x44007c10, 0x44004550, 0x00007c00, // ICON_LINK_BROKE
  1175. 0x02a00000, 0x22a43ffc, 0x20042004, 0x20042ff4, 0x20042ff4, 0x20042ff4, 0x20042004, 0x00003ffc, // ICON_TEXT_NOTES
  1176. 0x3ffc0000, 0x20042004, 0x245e27c4, 0x27c42444, 0x2004201e, 0x201e2004, 0x20042004, 0x00003ffc, // ICON_NOTEBOOK
  1177. 0x00000000, 0x07e00000, 0x04200420, 0x24243ffc, 0x24242424, 0x24242424, 0x3ffc2424, 0x00000000, // ICON_SUITCASE
  1178. 0x00000000, 0x0fe00000, 0x08200820, 0x40047ffc, 0x7ffc5554, 0x40045554, 0x7ffc4004, 0x00000000, // ICON_SUITCASE_ZIP
  1179. 0x00000000, 0x20043ffc, 0x3ffc2004, 0x13c81008, 0x100813c8, 0x10081008, 0x1ff81008, 0x00000000, // ICON_MAILBOX
  1180. 0x00000000, 0x40027ffe, 0x5ffa5ffa, 0x5ffa5ffa, 0x40025ffa, 0x03c07ffe, 0x1ff81ff8, 0x00000000, // ICON_MONITOR
  1181. 0x0ff00000, 0x6bfe7ffe, 0x7ffe7ffe, 0x68167ffe, 0x08106816, 0x08100810, 0x0ff00810, 0x00000000, // ICON_PRINTER
  1182. 0x3ff80000, 0xfffe2008, 0x870a8002, 0x904a888a, 0x904a904a, 0x870a888a, 0xfffe8002, 0x00000000, // ICON_PHOTO_CAMERA
  1183. 0x0fc00000, 0xfcfe0cd8, 0x8002fffe, 0x84428382, 0x84428442, 0x80028382, 0xfffe8002, 0x00000000, // ICON_PHOTO_CAMERA_FLASH
  1184. 0x00000000, 0x02400180, 0x08100420, 0x20041008, 0x23c42004, 0x22442244, 0x3ffc2244, 0x00000000, // ICON_HOUSE
  1185. 0x00000000, 0x1c700000, 0x3ff83ef8, 0x3ff83ff8, 0x0fe01ff0, 0x038007c0, 0x00000100, 0x00000000, // ICON_HEART
  1186. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x80000000, 0xe000c000, // ICON_CORNER
  1187. 0x00000000, 0x14001c00, 0x15c01400, 0x15401540, 0x155c1540, 0x15541554, 0x1ddc1554, 0x00000000, // ICON_VERTICAL_BARS
  1188. 0x00000000, 0x03000300, 0x1b001b00, 0x1b601b60, 0x1b6c1b60, 0x1b6c1b6c, 0x1b6c1b6c, 0x00000000, // ICON_VERTICAL_BARS_FILL
  1189. 0x00000000, 0x00000000, 0x403e7ffe, 0x7ffe403e, 0x7ffe0000, 0x43fe43fe, 0x00007ffe, 0x00000000, // ICON_LIFE_BARS
  1190. 0x7ffc0000, 0x43844004, 0x43844284, 0x43844004, 0x42844284, 0x42844284, 0x40044384, 0x00007ffc, // ICON_INFO
  1191. 0x40008000, 0x10002000, 0x04000800, 0x01000200, 0x00400080, 0x00100020, 0x00040008, 0x00010002, // ICON_CROSSLINE
  1192. 0x00000000, 0x1ff01ff0, 0x18301830, 0x1f001830, 0x03001f00, 0x00000300, 0x03000300, 0x00000000, // ICON_HELP
  1193. 0x3ff00000, 0x2abc3550, 0x2aac3554, 0x2aac3554, 0x2aac3554, 0x2aac3554, 0x2aac3554, 0x00003ffc, // ICON_FILETYPE_ALPHA
  1194. 0x3ff00000, 0x201c2010, 0x22442184, 0x28142424, 0x29942814, 0x2ff42994, 0x20042004, 0x00003ffc, // ICON_FILETYPE_HOME
  1195. 0x07fe0000, 0x04020402, 0x7fe20402, 0x44224422, 0x44224422, 0x402047fe, 0x40204020, 0x00007fe0, // ICON_LAYERS_VISIBLE
  1196. 0x07fe0000, 0x04020402, 0x7c020402, 0x44024402, 0x44024402, 0x402047fe, 0x40204020, 0x00007fe0, // ICON_LAYERS
  1197. 0x00000000, 0x40027ffe, 0x7ffe4002, 0x40024002, 0x40024002, 0x40024002, 0x7ffe4002, 0x00000000, // ICON_WINDOW
  1198. 0x09100000, 0x09f00910, 0x09100910, 0x00000910, 0x24a2779e, 0x27a224a2, 0x709e20a2, 0x00000000, // ICON_HIDPI
  1199. 0x3ff00000, 0x201c2010, 0x2a842e84, 0x2e842a84, 0x2ba42004, 0x2aa42aa4, 0x20042ba4, 0x00003ffc, // ICON_FILETYPE_BINARY
  1200. 0x00000000, 0x00000000, 0x00120012, 0x4a5e4bd2, 0x485233d2, 0x00004bd2, 0x00000000, 0x00000000, // ICON_HEX
  1201. 0x01800000, 0x381c0660, 0x23c42004, 0x23c42044, 0x13c82204, 0x08101008, 0x02400420, 0x00000180, // ICON_SHIELD
  1202. 0x007e0000, 0x20023fc2, 0x40227fe2, 0x400a403a, 0x400a400a, 0x400a400a, 0x4008400e, 0x00007ff8, // ICON_FILE_NEW
  1203. 0x00000000, 0x0042007e, 0x40027fc2, 0x44024002, 0x5f024402, 0x44024402, 0x7ffe4002, 0x00000000, // ICON_FOLDER_ADD
  1204. 0x44220000, 0x12482244, 0xf3cf0000, 0x14280420, 0x48122424, 0x08100810, 0x1ff81008, 0x03c00420, // ICON_ALARM
  1205. 0x0aa00000, 0x1ff80aa0, 0x1068700e, 0x1008706e, 0x1008700e, 0x1008700e, 0x0aa01ff8, 0x00000aa0, // ICON_CPU
  1206. 0x07e00000, 0x04201db8, 0x04a01c38, 0x04a01d38, 0x04a01d38, 0x04a01d38, 0x04201d38, 0x000007e0, // ICON_ROM
  1207. 0x00000000, 0x03c00000, 0x3c382ff0, 0x3c04380c, 0x01800000, 0x03c003c0, 0x00000180, 0x00000000, // ICON_STEP_OVER
  1208. 0x01800000, 0x01800180, 0x01800180, 0x03c007e0, 0x00000180, 0x01800000, 0x03c003c0, 0x00000180, // ICON_STEP_INTO
  1209. 0x01800000, 0x07e003c0, 0x01800180, 0x01800180, 0x00000180, 0x01800000, 0x03c003c0, 0x00000180, // ICON_STEP_OUT
  1210. 0x00000000, 0x0ff003c0, 0x181c1c34, 0x303c301c, 0x30003000, 0x1c301800, 0x03c00ff0, 0x00000000, // ICON_RESTART
  1211. 0x00000000, 0x00000000, 0x07e003c0, 0x0ff00ff0, 0x0ff00ff0, 0x03c007e0, 0x00000000, 0x00000000, // ICON_BREAKPOINT_ON
  1212. 0x00000000, 0x00000000, 0x042003c0, 0x08100810, 0x08100810, 0x03c00420, 0x00000000, 0x00000000, // ICON_BREAKPOINT_OFF
  1213. 0x00000000, 0x00000000, 0x1ff81ff8, 0x1ff80000, 0x00001ff8, 0x1ff81ff8, 0x00000000, 0x00000000, // ICON_BURGER_MENU
  1214. 0x00000000, 0x00000000, 0x00880070, 0x0c880088, 0x1e8810f8, 0x3e881288, 0x00000000, 0x00000000, // ICON_CASE_SENSITIVE
  1215. 0x00000000, 0x02000000, 0x07000a80, 0x07001fc0, 0x02000a80, 0x00300030, 0x00000000, 0x00000000, // ICON_REG_EXP
  1216. 0x00000000, 0x0042007e, 0x40027fc2, 0x40024002, 0x40024002, 0x40024002, 0x7ffe4002, 0x00000000, // ICON_FOLDER
  1217. 0x3ff00000, 0x201c2010, 0x20042004, 0x20042004, 0x20042004, 0x20042004, 0x20042004, 0x00003ffc, // ICON_FILE
  1218. 0x1ff00000, 0x20082008, 0x17d02fe8, 0x05400ba0, 0x09200540, 0x23881010, 0x2fe827c8, 0x00001ff0, // ICON_SAND_TIMER
  1219. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_220
  1220. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_221
  1221. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_222
  1222. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_223
  1223. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_224
  1224. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_225
  1225. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_226
  1226. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_227
  1227. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_228
  1228. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_229
  1229. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_230
  1230. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_231
  1231. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_232
  1232. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_233
  1233. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_234
  1234. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_235
  1235. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_236
  1236. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_237
  1237. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_238
  1238. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_239
  1239. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_240
  1240. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_241
  1241. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_242
  1242. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_243
  1243. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_244
  1244. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_245
  1245. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_246
  1246. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_247
  1247. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_248
  1248. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_249
  1249. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_250
  1250. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_251
  1251. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_252
  1252. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_253
  1253. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_254
  1254. 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, // ICON_255
  1255. };
  1256. // NOTE: We keep a pointer to the icons array, useful to point to other sets if required
  1257. static unsigned int *guiIconsPtr = guiIcons;
  1258. #endif // !RAYGUI_NO_ICONS && !RAYGUI_CUSTOM_ICONS
  1259. #ifndef RAYGUI_ICON_SIZE
  1260. #define RAYGUI_ICON_SIZE 0
  1261. #endif
  1262. // WARNING: Those values define the total size of the style data array,
  1263. // if changed, previous saved styles could become incompatible
  1264. #define RAYGUI_MAX_CONTROLS 16 // Maximum number of controls
  1265. #define RAYGUI_MAX_PROPS_BASE 16 // Maximum number of base properties
  1266. #define RAYGUI_MAX_PROPS_EXTENDED 8 // Maximum number of extended properties
  1267. //----------------------------------------------------------------------------------
  1268. // Types and Structures Definition
  1269. //----------------------------------------------------------------------------------
  1270. // Gui control property style color element
  1271. typedef enum { BORDER = 0, BASE, TEXT, OTHER } GuiPropertyElement;
  1272. //----------------------------------------------------------------------------------
  1273. // Global Variables Definition
  1274. //----------------------------------------------------------------------------------
  1275. static GuiState guiState = STATE_NORMAL; // Gui global state, if !STATE_NORMAL, forces defined state
  1276. static Font guiFont = { 0 }; // Gui current font (WARNING: highly coupled to raylib)
  1277. static bool guiLocked = false; // Gui lock state (no inputs processed)
  1278. static float guiAlpha = 1.0f; // Gui controls transparency
  1279. static unsigned int guiIconScale = 1; // Gui icon default scale (if icons enabled)
  1280. static bool guiTooltip = false; // Tooltip enabled/disabled
  1281. static const char *guiTooltipPtr = NULL; // Tooltip string pointer (string provided by user)
  1282. static bool guiSliderDragging = false; // Gui slider drag state (no inputs processed except dragged slider)
  1283. static Rectangle guiSliderActive = { 0 }; // Gui slider active bounds rectangle, used as an unique identifier
  1284. static int textBoxCursorIndex = 0; // Cursor index, shared by all GuiTextBox*()
  1285. //static int blinkCursorFrameCounter = 0; // Frame counter for cursor blinking
  1286. static int autoCursorCooldownCounter = 0; // Cooldown frame counter for automatic cursor movement on key-down
  1287. static int autoCursorDelayCounter = 0; // Delay frame counter for automatic cursor movement
  1288. //----------------------------------------------------------------------------------
  1289. // Style data array for all gui style properties (allocated on data segment by default)
  1290. //
  1291. // NOTE 1: First set of BASE properties are generic to all controls but could be individually
  1292. // overwritten per control, first set of EXTENDED properties are generic to all controls and
  1293. // can not be overwritten individually but custom EXTENDED properties can be used by control
  1294. //
  1295. // NOTE 2: A new style set could be loaded over this array using GuiLoadStyle(),
  1296. // but default gui style could always be recovered with GuiLoadStyleDefault()
  1297. //
  1298. // guiStyle size is by default: 16*(16 + 8) = 384*4 = 1536 bytes = 1.5 KB
  1299. //----------------------------------------------------------------------------------
  1300. static unsigned int guiStyle[RAYGUI_MAX_CONTROLS*(RAYGUI_MAX_PROPS_BASE + RAYGUI_MAX_PROPS_EXTENDED)] = { 0 };
  1301. static bool guiStyleLoaded = false; // Style loaded flag for lazy style initialization
  1302. //----------------------------------------------------------------------------------
  1303. // Standalone Mode Functions Declaration
  1304. //
  1305. // NOTE: raygui depend on some raylib input and drawing functions
  1306. // To use raygui as standalone library, below functions must be defined by the user
  1307. //----------------------------------------------------------------------------------
  1308. #if defined(RAYGUI_STANDALONE)
  1309. #define KEY_RIGHT 262
  1310. #define KEY_LEFT 263
  1311. #define KEY_DOWN 264
  1312. #define KEY_UP 265
  1313. #define KEY_BACKSPACE 259
  1314. #define KEY_ENTER 257
  1315. #define MOUSE_LEFT_BUTTON 0
  1316. // Input required functions
  1317. //-------------------------------------------------------------------------------
  1318. static Vector2 GetMousePosition(void);
  1319. static float GetMouseWheelMove(void);
  1320. static bool IsMouseButtonDown(int button);
  1321. static bool IsMouseButtonPressed(int button);
  1322. static bool IsMouseButtonReleased(int button);
  1323. static bool IsKeyDown(int key);
  1324. static bool IsKeyPressed(int key);
  1325. static int GetCharPressed(void); // -- GuiTextBox(), GuiValueBox()
  1326. //-------------------------------------------------------------------------------
  1327. // Drawing required functions
  1328. //-------------------------------------------------------------------------------
  1329. static void DrawRectangle(int x, int y, int width, int height, Color color); // -- GuiDrawRectangle()
  1330. static void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3, Color col4); // -- GuiColorPicker()
  1331. //-------------------------------------------------------------------------------
  1332. // Text required functions
  1333. //-------------------------------------------------------------------------------
  1334. static Font GetFontDefault(void); // -- GuiLoadStyleDefault()
  1335. static Font LoadFontEx(const char *fileName, int fontSize, int *codepoints, int codepointCount); // -- GuiLoadStyle(), load font
  1336. static Texture2D LoadTextureFromImage(Image image); // -- GuiLoadStyle(), required to load texture from embedded font atlas image
  1337. static void SetShapesTexture(Texture2D tex, Rectangle rec); // -- GuiLoadStyle(), required to set shapes rec to font white rec (optimization)
  1338. static char *LoadFileText(const char *fileName); // -- GuiLoadStyle(), required to load charset data
  1339. static void UnloadFileText(char *text); // -- GuiLoadStyle(), required to unload charset data
  1340. static const char *GetDirectoryPath(const char *filePath); // -- GuiLoadStyle(), required to find charset/font file from text .rgs
  1341. static int *LoadCodepoints(const char *text, int *count); // -- GuiLoadStyle(), required to load required font codepoints list
  1342. static void UnloadCodepoints(int *codepoints); // -- GuiLoadStyle(), required to unload codepoints list
  1343. static unsigned char *DecompressData(const unsigned char *compData, int compDataSize, int *dataSize); // -- GuiLoadStyle()
  1344. //-------------------------------------------------------------------------------
  1345. // raylib functions already implemented in raygui
  1346. //-------------------------------------------------------------------------------
  1347. static Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value
  1348. static int ColorToInt(Color color); // Returns hexadecimal value for a Color
  1349. static bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle
  1350. static const char *TextFormat(const char *text, ...); // Formatting of text with variables to 'embed'
  1351. static const char **TextSplit(const char *text, char delimiter, int *count); // Split text into multiple strings
  1352. static int TextToInteger(const char *text); // Get integer value from text
  1353. static int GetCodepointNext(const char *text, int *codepointSize); // Get next codepoint in a UTF-8 encoded text
  1354. static const char *CodepointToUTF8(int codepoint, int *byteSize); // Encode codepoint into UTF-8 text (char array size returned as parameter)
  1355. static void DrawRectangleGradientV(int posX, int posY, int width, int height, Color color1, Color color2); // Draw rectangle vertical gradient
  1356. //-------------------------------------------------------------------------------
  1357. #endif // RAYGUI_STANDALONE
  1358. //----------------------------------------------------------------------------------
  1359. // Module specific Functions Declaration
  1360. //----------------------------------------------------------------------------------
  1361. static void GuiLoadStyleFromMemory(const unsigned char *fileData, int dataSize); // Load style from memory (binary only)
  1362. static int GetTextWidth(const char *text); // Gui get text width using gui font and style
  1363. static Rectangle GetTextBounds(int control, Rectangle bounds); // Get text bounds considering control bounds
  1364. static const char *GetTextIcon(const char *text, int *iconId); // Get text icon if provided and move text cursor
  1365. static void GuiDrawText(const char *text, Rectangle textBounds, int alignment, Color tint); // Gui draw text using default font
  1366. static void GuiDrawRectangle(Rectangle rec, int borderWidth, Color borderColor, Color color); // Gui draw rectangle using default raygui style
  1367. static const char **GuiTextSplit(const char *text, char delimiter, int *count, int *textRow); // Split controls text into multiple strings
  1368. static Vector3 ConvertHSVtoRGB(Vector3 hsv); // Convert color data from HSV to RGB
  1369. static Vector3 ConvertRGBtoHSV(Vector3 rgb); // Convert color data from RGB to HSV
  1370. static int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue); // Scroll bar control, used by GuiScrollPanel()
  1371. static void GuiTooltip(Rectangle controlRec); // Draw tooltip using control rec position
  1372. static Color GuiFade(Color color, float alpha); // Fade color by an alpha factor
  1373. //----------------------------------------------------------------------------------
  1374. // Gui Setup Functions Definition
  1375. //----------------------------------------------------------------------------------
  1376. // Enable gui global state
  1377. // NOTE: We check for STATE_DISABLED to avoid messing custom global state setups
  1378. void GuiEnable(void) { if (guiState == STATE_DISABLED) guiState = STATE_NORMAL; }
  1379. // Disable gui global state
  1380. // NOTE: We check for STATE_NORMAL to avoid messing custom global state setups
  1381. void GuiDisable(void) { if (guiState == STATE_NORMAL) guiState = STATE_DISABLED; }
  1382. // Lock gui global state
  1383. void GuiLock(void) { guiLocked = true; }
  1384. // Unlock gui global state
  1385. void GuiUnlock(void) { guiLocked = false; }
  1386. // Check if gui is locked (global state)
  1387. bool GuiIsLocked(void) { return guiLocked; }
  1388. // Set gui controls alpha global state
  1389. void GuiSetAlpha(float alpha)
  1390. {
  1391. if (alpha < 0.0f) alpha = 0.0f;
  1392. else if (alpha > 1.0f) alpha = 1.0f;
  1393. guiAlpha = alpha;
  1394. }
  1395. // Set gui state (global state)
  1396. void GuiSetState(int state) { guiState = (GuiState)state; }
  1397. // Get gui state (global state)
  1398. int GuiGetState(void) { return guiState; }
  1399. // Set custom gui font
  1400. // NOTE: Font loading/unloading is external to raygui
  1401. void GuiSetFont(Font font)
  1402. {
  1403. if (font.texture.id > 0)
  1404. {
  1405. // NOTE: If we try to setup a font but default style has not been
  1406. // lazily loaded before, it will be overwritten, so we need to force
  1407. // default style loading first
  1408. if (!guiStyleLoaded) GuiLoadStyleDefault();
  1409. guiFont = font;
  1410. }
  1411. }
  1412. // Get custom gui font
  1413. Font GuiGetFont(void)
  1414. {
  1415. return guiFont;
  1416. }
  1417. // Set control style property value
  1418. void GuiSetStyle(int control, int property, int value)
  1419. {
  1420. if (!guiStyleLoaded) GuiLoadStyleDefault();
  1421. guiStyle[control*(RAYGUI_MAX_PROPS_BASE + RAYGUI_MAX_PROPS_EXTENDED) + property] = value;
  1422. // Default properties are propagated to all controls
  1423. if ((control == 0) && (property < RAYGUI_MAX_PROPS_BASE))
  1424. {
  1425. for (int i = 1; i < RAYGUI_MAX_CONTROLS; i++) guiStyle[i*(RAYGUI_MAX_PROPS_BASE + RAYGUI_MAX_PROPS_EXTENDED) + property] = value;
  1426. }
  1427. }
  1428. // Get control style property value
  1429. int GuiGetStyle(int control, int property)
  1430. {
  1431. if (!guiStyleLoaded) GuiLoadStyleDefault();
  1432. return guiStyle[control*(RAYGUI_MAX_PROPS_BASE + RAYGUI_MAX_PROPS_EXTENDED) + property];
  1433. }
  1434. //----------------------------------------------------------------------------------
  1435. // Gui Controls Functions Definition
  1436. //----------------------------------------------------------------------------------
  1437. // Window Box control
  1438. int GuiWindowBox(Rectangle bounds, const char *title)
  1439. {
  1440. // Window title bar height (including borders)
  1441. // NOTE: This define is also used by GuiMessageBox() and GuiTextInputBox()
  1442. #if !defined(RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT)
  1443. #define RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT 24
  1444. #endif
  1445. int result = 0;
  1446. //GuiState state = guiState;
  1447. int statusBarHeight = RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT;
  1448. Rectangle statusBar = { bounds.x, bounds.y, bounds.width, (float)statusBarHeight };
  1449. if (bounds.height < statusBarHeight*2.0f) bounds.height = statusBarHeight*2.0f;
  1450. Rectangle windowPanel = { bounds.x, bounds.y + (float)statusBarHeight - 1, bounds.width, bounds.height - (float)statusBarHeight + 1 };
  1451. Rectangle closeButtonRec = { statusBar.x + statusBar.width - GuiGetStyle(STATUSBAR, BORDER_WIDTH) - 20,
  1452. statusBar.y + statusBarHeight/2.0f - 18.0f/2.0f, 18, 18 };
  1453. // Update control
  1454. //--------------------------------------------------------------------
  1455. // NOTE: Logic is directly managed by button
  1456. //--------------------------------------------------------------------
  1457. // Draw control
  1458. //--------------------------------------------------------------------
  1459. GuiStatusBar(statusBar, title); // Draw window header as status bar
  1460. GuiPanel(windowPanel, NULL); // Draw window base
  1461. // Draw window close button
  1462. int tempBorderWidth = GuiGetStyle(BUTTON, BORDER_WIDTH);
  1463. int tempTextAlignment = GuiGetStyle(BUTTON, TEXT_ALIGNMENT);
  1464. GuiSetStyle(BUTTON, BORDER_WIDTH, 1);
  1465. GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
  1466. #if defined(RAYGUI_NO_ICONS)
  1467. result = GuiButton(closeButtonRec, "x");
  1468. #else
  1469. result = GuiButton(closeButtonRec, GuiIconText(ICON_CROSS_SMALL, NULL));
  1470. #endif
  1471. GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth);
  1472. GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlignment);
  1473. //--------------------------------------------------------------------
  1474. return result; // Window close button clicked: result = 1
  1475. }
  1476. // Group Box control with text name
  1477. int GuiGroupBox(Rectangle bounds, const char *text)
  1478. {
  1479. #if !defined(RAYGUI_GROUPBOX_LINE_THICK)
  1480. #define RAYGUI_GROUPBOX_LINE_THICK 1
  1481. #endif
  1482. int result = 0;
  1483. GuiState state = guiState;
  1484. // Draw control
  1485. //--------------------------------------------------------------------
  1486. GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y, RAYGUI_GROUPBOX_LINE_THICK, bounds.height }, 0, BLANK, GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? BORDER_COLOR_DISABLED : LINE_COLOR)));
  1487. GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y + bounds.height - 1, bounds.width, RAYGUI_GROUPBOX_LINE_THICK }, 0, BLANK, GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? BORDER_COLOR_DISABLED : LINE_COLOR)));
  1488. GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x + bounds.width - 1, bounds.y, RAYGUI_GROUPBOX_LINE_THICK, bounds.height }, 0, BLANK, GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? BORDER_COLOR_DISABLED : LINE_COLOR)));
  1489. GuiLine(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y - GuiGetStyle(DEFAULT, TEXT_SIZE)/2, bounds.width, (float)GuiGetStyle(DEFAULT, TEXT_SIZE) }, text);
  1490. //--------------------------------------------------------------------
  1491. return result;
  1492. }
  1493. // Line control
  1494. int GuiLine(Rectangle bounds, const char *text)
  1495. {
  1496. #if !defined(RAYGUI_LINE_ORIGIN_SIZE)
  1497. #define RAYGUI_LINE_MARGIN_TEXT 12
  1498. #endif
  1499. #if !defined(RAYGUI_LINE_TEXT_PADDING)
  1500. #define RAYGUI_LINE_TEXT_PADDING 4
  1501. #endif
  1502. int result = 0;
  1503. GuiState state = guiState;
  1504. Color color = GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? BORDER_COLOR_DISABLED : LINE_COLOR));
  1505. // Draw control
  1506. //--------------------------------------------------------------------
  1507. if (text == NULL) GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y + bounds.height/2, bounds.width, 1 }, 0, BLANK, color);
  1508. else
  1509. {
  1510. Rectangle textBounds = { 0 };
  1511. textBounds.width = (float)GetTextWidth(text) + 2;
  1512. textBounds.height = bounds.height;
  1513. textBounds.x = bounds.x + RAYGUI_LINE_MARGIN_TEXT;
  1514. textBounds.y = bounds.y;
  1515. // Draw line with embedded text label: "--- text --------------"
  1516. GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y + bounds.height/2, RAYGUI_LINE_MARGIN_TEXT - RAYGUI_LINE_TEXT_PADDING, 1 }, 0, BLANK, color);
  1517. GuiDrawText(text, textBounds, TEXT_ALIGN_LEFT, color);
  1518. GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x + 12 + textBounds.width + 4, bounds.y + bounds.height/2, bounds.width - textBounds.width - RAYGUI_LINE_MARGIN_TEXT - RAYGUI_LINE_TEXT_PADDING, 1 }, 0, BLANK, color);
  1519. }
  1520. //--------------------------------------------------------------------
  1521. return result;
  1522. }
  1523. // Panel control
  1524. int GuiPanel(Rectangle bounds, const char *text)
  1525. {
  1526. #if !defined(RAYGUI_PANEL_BORDER_WIDTH)
  1527. #define RAYGUI_PANEL_BORDER_WIDTH 1
  1528. #endif
  1529. int result = 0;
  1530. GuiState state = guiState;
  1531. // Text will be drawn as a header bar (if provided)
  1532. Rectangle statusBar = { bounds.x, bounds.y, bounds.width, (float)RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT };
  1533. if ((text != NULL) && (bounds.height < RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT*2.0f)) bounds.height = RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT*2.0f;
  1534. if (text != NULL)
  1535. {
  1536. // Move panel bounds after the header bar
  1537. bounds.y += (float)RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT - 1;
  1538. bounds.height -= (float)RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT - 1;
  1539. }
  1540. // Draw control
  1541. //--------------------------------------------------------------------
  1542. if (text != NULL) GuiStatusBar(statusBar, text); // Draw panel header as status bar
  1543. GuiDrawRectangle(bounds, RAYGUI_PANEL_BORDER_WIDTH, GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? BORDER_COLOR_DISABLED: LINE_COLOR)),
  1544. GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? BASE_COLOR_DISABLED : BACKGROUND_COLOR)));
  1545. //--------------------------------------------------------------------
  1546. return result;
  1547. }
  1548. // Tab Bar control
  1549. // NOTE: Using GuiToggle() for the TABS
  1550. int GuiTabBar(Rectangle bounds, const char **text, int count, int *active)
  1551. {
  1552. #define RAYGUI_TABBAR_ITEM_WIDTH 160
  1553. int result = -1;
  1554. //GuiState state = guiState;
  1555. Rectangle tabBounds = { bounds.x, bounds.y, RAYGUI_TABBAR_ITEM_WIDTH, bounds.height };
  1556. if (*active < 0) *active = 0;
  1557. else if (*active > count - 1) *active = count - 1;
  1558. int offsetX = 0; // Required in case tabs go out of screen
  1559. offsetX = (*active + 2)*RAYGUI_TABBAR_ITEM_WIDTH - GetScreenWidth();
  1560. if (offsetX < 0) offsetX = 0;
  1561. bool toggle = false; // Required for individual toggles
  1562. // Draw control
  1563. //--------------------------------------------------------------------
  1564. for (int i = 0; i < count; i++)
  1565. {
  1566. tabBounds.x = bounds.x + (RAYGUI_TABBAR_ITEM_WIDTH + 4)*i - offsetX;
  1567. if (tabBounds.x < GetScreenWidth())
  1568. {
  1569. // Draw tabs as toggle controls
  1570. int textAlignment = GuiGetStyle(TOGGLE, TEXT_ALIGNMENT);
  1571. int textPadding = GuiGetStyle(TOGGLE, TEXT_PADDING);
  1572. GuiSetStyle(TOGGLE, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
  1573. GuiSetStyle(TOGGLE, TEXT_PADDING, 8);
  1574. if (i == (*active))
  1575. {
  1576. toggle = true;
  1577. GuiToggle(tabBounds, GuiIconText(12, text[i]), &toggle);
  1578. }
  1579. else
  1580. {
  1581. toggle = false;
  1582. GuiToggle(tabBounds, GuiIconText(12, text[i]), &toggle);
  1583. if (toggle) *active = i;
  1584. }
  1585. GuiSetStyle(TOGGLE, TEXT_PADDING, textPadding);
  1586. GuiSetStyle(TOGGLE, TEXT_ALIGNMENT, textAlignment);
  1587. // Draw tab close button
  1588. // NOTE: Only draw close button for current tab: if (CheckCollisionPointRec(mousePosition, tabBounds))
  1589. int tempBorderWidth = GuiGetStyle(BUTTON, BORDER_WIDTH);
  1590. int tempTextAlignment = GuiGetStyle(BUTTON, TEXT_ALIGNMENT);
  1591. GuiSetStyle(BUTTON, BORDER_WIDTH, 1);
  1592. GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
  1593. #if defined(RAYGUI_NO_ICONS)
  1594. if (GuiButton(RAYGUI_CLITERAL(Rectangle){ tabBounds.x + tabBounds.width - 14 - 5, tabBounds.y + 5, 14, 14 }, "x")) result = i;
  1595. #else
  1596. if (GuiButton(RAYGUI_CLITERAL(Rectangle){ tabBounds.x + tabBounds.width - 14 - 5, tabBounds.y + 5, 14, 14 }, GuiIconText(ICON_CROSS_SMALL, NULL))) result = i;
  1597. #endif
  1598. GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth);
  1599. GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlignment);
  1600. }
  1601. }
  1602. // Draw tab-bar bottom line
  1603. GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y + bounds.height - 1, bounds.width, 1 }, 0, BLANK, GetColor(GuiGetStyle(TOGGLE, BORDER_COLOR_NORMAL)));
  1604. //--------------------------------------------------------------------
  1605. return result; // Return as result the current TAB closing requested
  1606. }
  1607. // Scroll Panel control
  1608. int GuiScrollPanel(Rectangle bounds, const char *text, Rectangle content, Vector2 *scroll, Rectangle *view)
  1609. {
  1610. #define RAYGUI_MIN_SCROLLBAR_WIDTH 40
  1611. #define RAYGUI_MIN_SCROLLBAR_HEIGHT 40
  1612. int result = 0;
  1613. GuiState state = guiState;
  1614. float mouseWheelSpeed = 20.0f; // Default movement speed with mouse wheel
  1615. Rectangle temp = { 0 };
  1616. if (view == NULL) view = &temp;
  1617. Vector2 scrollPos = { 0.0f, 0.0f };
  1618. if (scroll != NULL) scrollPos = *scroll;
  1619. // Text will be drawn as a header bar (if provided)
  1620. Rectangle statusBar = { bounds.x, bounds.y, bounds.width, (float)RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT };
  1621. if (bounds.height < RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT*2.0f) bounds.height = RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT*2.0f;
  1622. if (text != NULL)
  1623. {
  1624. // Move panel bounds after the header bar
  1625. bounds.y += (float)RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT - 1;
  1626. bounds.height -= (float)RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT + 1;
  1627. }
  1628. bool hasHorizontalScrollBar = (content.width > bounds.width - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH))? true : false;
  1629. bool hasVerticalScrollBar = (content.height > bounds.height - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH))? true : false;
  1630. // Recheck to account for the other scrollbar being visible
  1631. if (!hasHorizontalScrollBar) hasHorizontalScrollBar = (hasVerticalScrollBar && (content.width > (bounds.width - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH) - GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH))))? true : false;
  1632. if (!hasVerticalScrollBar) hasVerticalScrollBar = (hasHorizontalScrollBar && (content.height > (bounds.height - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH) - GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH))))? true : false;
  1633. int horizontalScrollBarWidth = hasHorizontalScrollBar? GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH) : 0;
  1634. int verticalScrollBarWidth = hasVerticalScrollBar? GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH) : 0;
  1635. Rectangle horizontalScrollBar = {
  1636. (float)((GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE) == SCROLLBAR_LEFT_SIDE)? (float)bounds.x + verticalScrollBarWidth : (float)bounds.x) + GuiGetStyle(DEFAULT, BORDER_WIDTH),
  1637. (float)bounds.y + bounds.height - horizontalScrollBarWidth - GuiGetStyle(DEFAULT, BORDER_WIDTH),
  1638. (float)bounds.width - verticalScrollBarWidth - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH),
  1639. (float)horizontalScrollBarWidth
  1640. };
  1641. Rectangle verticalScrollBar = {
  1642. (float)((GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE) == SCROLLBAR_LEFT_SIDE)? (float)bounds.x + GuiGetStyle(DEFAULT, BORDER_WIDTH) : (float)bounds.x + bounds.width - verticalScrollBarWidth - GuiGetStyle(DEFAULT, BORDER_WIDTH)),
  1643. (float)bounds.y + GuiGetStyle(DEFAULT, BORDER_WIDTH),
  1644. (float)verticalScrollBarWidth,
  1645. (float)bounds.height - horizontalScrollBarWidth - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH)
  1646. };
  1647. // Make sure scroll bars have a minimum width/height
  1648. // NOTE: If content >>> bounds, size could be very small or even 0
  1649. if (horizontalScrollBar.width < RAYGUI_MIN_SCROLLBAR_WIDTH)
  1650. {
  1651. horizontalScrollBar.width = RAYGUI_MIN_SCROLLBAR_WIDTH;
  1652. mouseWheelSpeed = 30.0f; // TODO: Calculate speed increment based on content.height vs bounds.height
  1653. }
  1654. if (verticalScrollBar.height < RAYGUI_MIN_SCROLLBAR_HEIGHT)
  1655. {
  1656. verticalScrollBar.height = RAYGUI_MIN_SCROLLBAR_HEIGHT;
  1657. mouseWheelSpeed = 30.0f; // TODO: Calculate speed increment based on content.width vs bounds.width
  1658. }
  1659. // Calculate view area (area without the scrollbars)
  1660. *view = (GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE) == SCROLLBAR_LEFT_SIDE)?
  1661. RAYGUI_CLITERAL(Rectangle){ bounds.x + verticalScrollBarWidth + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.y + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH) - verticalScrollBarWidth, bounds.height - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH) - horizontalScrollBarWidth } :
  1662. RAYGUI_CLITERAL(Rectangle){ bounds.x + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.y + GuiGetStyle(DEFAULT, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH) - verticalScrollBarWidth, bounds.height - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH) - horizontalScrollBarWidth };
  1663. // Clip view area to the actual content size
  1664. if (view->width > content.width) view->width = content.width;
  1665. if (view->height > content.height) view->height = content.height;
  1666. float horizontalMin = hasHorizontalScrollBar? ((GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE) == SCROLLBAR_LEFT_SIDE)? (float)-verticalScrollBarWidth : 0) - (float)GuiGetStyle(DEFAULT, BORDER_WIDTH) : (((float)GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE) == SCROLLBAR_LEFT_SIDE)? (float)-verticalScrollBarWidth : 0) - (float)GuiGetStyle(DEFAULT, BORDER_WIDTH);
  1667. float horizontalMax = hasHorizontalScrollBar? content.width - bounds.width + (float)verticalScrollBarWidth + GuiGetStyle(DEFAULT, BORDER_WIDTH) - (((float)GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE) == SCROLLBAR_LEFT_SIDE)? (float)verticalScrollBarWidth : 0) : (float)-GuiGetStyle(DEFAULT, BORDER_WIDTH);
  1668. float verticalMin = hasVerticalScrollBar? 0.0f : -1.0f;
  1669. float verticalMax = hasVerticalScrollBar? content.height - bounds.height + (float)horizontalScrollBarWidth + (float)GuiGetStyle(DEFAULT, BORDER_WIDTH) : (float)-GuiGetStyle(DEFAULT, BORDER_WIDTH);
  1670. // Update control
  1671. //--------------------------------------------------------------------
  1672. if ((state != STATE_DISABLED) && !guiLocked)
  1673. {
  1674. Vector2 mousePoint = GetMousePosition();
  1675. // Check button state
  1676. if (CheckCollisionPointRec(mousePoint, bounds))
  1677. {
  1678. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
  1679. else state = STATE_FOCUSED;
  1680. #if defined(SUPPORT_SCROLLBAR_KEY_INPUT)
  1681. if (hasHorizontalScrollBar)
  1682. {
  1683. if (IsKeyDown(KEY_RIGHT)) scrollPos.x -= GuiGetStyle(SCROLLBAR, SCROLL_SPEED);
  1684. if (IsKeyDown(KEY_LEFT)) scrollPos.x += GuiGetStyle(SCROLLBAR, SCROLL_SPEED);
  1685. }
  1686. if (hasVerticalScrollBar)
  1687. {
  1688. if (IsKeyDown(KEY_DOWN)) scrollPos.y -= GuiGetStyle(SCROLLBAR, SCROLL_SPEED);
  1689. if (IsKeyDown(KEY_UP)) scrollPos.y += GuiGetStyle(SCROLLBAR, SCROLL_SPEED);
  1690. }
  1691. #endif
  1692. float wheelMove = GetMouseWheelMove();
  1693. // Horizontal and vertical scrolling with mouse wheel
  1694. if (hasHorizontalScrollBar && (IsKeyDown(KEY_LEFT_CONTROL) || IsKeyDown(KEY_LEFT_SHIFT))) scrollPos.x += wheelMove*mouseWheelSpeed;
  1695. else scrollPos.y += wheelMove*mouseWheelSpeed; // Vertical scroll
  1696. }
  1697. }
  1698. // Normalize scroll values
  1699. if (scrollPos.x > -horizontalMin) scrollPos.x = -horizontalMin;
  1700. if (scrollPos.x < -horizontalMax) scrollPos.x = -horizontalMax;
  1701. if (scrollPos.y > -verticalMin) scrollPos.y = -verticalMin;
  1702. if (scrollPos.y < -verticalMax) scrollPos.y = -verticalMax;
  1703. //--------------------------------------------------------------------
  1704. // Draw control
  1705. //--------------------------------------------------------------------
  1706. if (text != NULL) GuiStatusBar(statusBar, text); // Draw panel header as status bar
  1707. GuiDrawRectangle(bounds, 0, BLANK, GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR))); // Draw background
  1708. // Save size of the scrollbar slider
  1709. const int slider = GuiGetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE);
  1710. // Draw horizontal scrollbar if visible
  1711. if (hasHorizontalScrollBar)
  1712. {
  1713. // Change scrollbar slider size to show the diff in size between the content width and the widget width
  1714. GuiSetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE, (int)(((bounds.width - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH) - verticalScrollBarWidth)/(int)content.width)*((int)bounds.width - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH) - verticalScrollBarWidth)));
  1715. scrollPos.x = (float)-GuiScrollBar(horizontalScrollBar, (int)-scrollPos.x, (int)horizontalMin, (int)horizontalMax);
  1716. }
  1717. else scrollPos.x = 0.0f;
  1718. // Draw vertical scrollbar if visible
  1719. if (hasVerticalScrollBar)
  1720. {
  1721. // Change scrollbar slider size to show the diff in size between the content height and the widget height
  1722. GuiSetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE, (int)(((bounds.height - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH) - horizontalScrollBarWidth)/(int)content.height)*((int)bounds.height - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH) - horizontalScrollBarWidth)));
  1723. scrollPos.y = (float)-GuiScrollBar(verticalScrollBar, (int)-scrollPos.y, (int)verticalMin, (int)verticalMax);
  1724. }
  1725. else scrollPos.y = 0.0f;
  1726. // Draw detail corner rectangle if both scroll bars are visible
  1727. if (hasHorizontalScrollBar && hasVerticalScrollBar)
  1728. {
  1729. Rectangle corner = { (GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE) == SCROLLBAR_LEFT_SIDE)? (bounds.x + GuiGetStyle(DEFAULT, BORDER_WIDTH) + 2) : (horizontalScrollBar.x + horizontalScrollBar.width + 2), verticalScrollBar.y + verticalScrollBar.height + 2, (float)horizontalScrollBarWidth - 4, (float)verticalScrollBarWidth - 4 };
  1730. GuiDrawRectangle(corner, 0, BLANK, GetColor(GuiGetStyle(LISTVIEW, TEXT + (state*3))));
  1731. }
  1732. // Draw scrollbar lines depending on current state
  1733. GuiDrawRectangle(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), GetColor(GuiGetStyle(LISTVIEW, BORDER + (state*3))), BLANK);
  1734. // Set scrollbar slider size back to the way it was before
  1735. GuiSetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE, slider);
  1736. //--------------------------------------------------------------------
  1737. if (scroll != NULL) *scroll = scrollPos;
  1738. return result;
  1739. }
  1740. // Label control
  1741. int GuiLabel(Rectangle bounds, const char *text)
  1742. {
  1743. int result = 0;
  1744. GuiState state = guiState;
  1745. // Update control
  1746. //--------------------------------------------------------------------
  1747. //...
  1748. //--------------------------------------------------------------------
  1749. // Draw control
  1750. //--------------------------------------------------------------------
  1751. GuiDrawText(text, GetTextBounds(LABEL, bounds), GuiGetStyle(LABEL, TEXT_ALIGNMENT), GetColor(GuiGetStyle(LABEL, TEXT + (state*3))));
  1752. //--------------------------------------------------------------------
  1753. return result;
  1754. }
  1755. // Button control, returns true when clicked
  1756. int GuiButton(Rectangle bounds, const char *text)
  1757. {
  1758. int result = 0;
  1759. GuiState state = guiState;
  1760. // Update control
  1761. //--------------------------------------------------------------------
  1762. if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
  1763. {
  1764. Vector2 mousePoint = GetMousePosition();
  1765. // Check button state
  1766. if (CheckCollisionPointRec(mousePoint, bounds))
  1767. {
  1768. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
  1769. else state = STATE_FOCUSED;
  1770. if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) result = 1;
  1771. }
  1772. }
  1773. //--------------------------------------------------------------------
  1774. // Draw control
  1775. //--------------------------------------------------------------------
  1776. GuiDrawRectangle(bounds, GuiGetStyle(BUTTON, BORDER_WIDTH), GetColor(GuiGetStyle(BUTTON, BORDER + (state*3))), GetColor(GuiGetStyle(BUTTON, BASE + (state*3))));
  1777. GuiDrawText(text, GetTextBounds(BUTTON, bounds), GuiGetStyle(BUTTON, TEXT_ALIGNMENT), GetColor(GuiGetStyle(BUTTON, TEXT + (state*3))));
  1778. if (state == STATE_FOCUSED) GuiTooltip(bounds);
  1779. //------------------------------------------------------------------
  1780. return result; // Button pressed: result = 1
  1781. }
  1782. // Label button control
  1783. int GuiLabelButton(Rectangle bounds, const char *text)
  1784. {
  1785. GuiState state = guiState;
  1786. bool pressed = false;
  1787. // NOTE: We force bounds.width to be all text
  1788. float textWidth = (float)GetTextWidth(text);
  1789. if ((bounds.width - 2*GuiGetStyle(LABEL, BORDER_WIDTH) - 2*GuiGetStyle(LABEL, TEXT_PADDING)) < textWidth) bounds.width = textWidth + 2*GuiGetStyle(LABEL, BORDER_WIDTH) + 2*GuiGetStyle(LABEL, TEXT_PADDING) + 2;
  1790. // Update control
  1791. //--------------------------------------------------------------------
  1792. if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
  1793. {
  1794. Vector2 mousePoint = GetMousePosition();
  1795. // Check checkbox state
  1796. if (CheckCollisionPointRec(mousePoint, bounds))
  1797. {
  1798. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
  1799. else state = STATE_FOCUSED;
  1800. if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) pressed = true;
  1801. }
  1802. }
  1803. //--------------------------------------------------------------------
  1804. // Draw control
  1805. //--------------------------------------------------------------------
  1806. GuiDrawText(text, GetTextBounds(LABEL, bounds), GuiGetStyle(LABEL, TEXT_ALIGNMENT), GetColor(GuiGetStyle(LABEL, TEXT + (state*3))));
  1807. //--------------------------------------------------------------------
  1808. return pressed;
  1809. }
  1810. // Toggle Button control, returns true when active
  1811. int GuiToggle(Rectangle bounds, const char *text, bool *active)
  1812. {
  1813. int result = 0;
  1814. GuiState state = guiState;
  1815. bool temp = false;
  1816. if (active == NULL) active = &temp;
  1817. // Update control
  1818. //--------------------------------------------------------------------
  1819. if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
  1820. {
  1821. Vector2 mousePoint = GetMousePosition();
  1822. // Check toggle button state
  1823. if (CheckCollisionPointRec(mousePoint, bounds))
  1824. {
  1825. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
  1826. else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
  1827. {
  1828. state = STATE_NORMAL;
  1829. *active = !(*active);
  1830. }
  1831. else state = STATE_FOCUSED;
  1832. }
  1833. }
  1834. //--------------------------------------------------------------------
  1835. // Draw control
  1836. //--------------------------------------------------------------------
  1837. if (state == STATE_NORMAL)
  1838. {
  1839. GuiDrawRectangle(bounds, GuiGetStyle(TOGGLE, BORDER_WIDTH), GetColor(GuiGetStyle(TOGGLE, ((*active)? BORDER_COLOR_PRESSED : (BORDER + state*3)))), GetColor(GuiGetStyle(TOGGLE, ((*active)? BASE_COLOR_PRESSED : (BASE + state*3)))));
  1840. GuiDrawText(text, GetTextBounds(TOGGLE, bounds), GuiGetStyle(TOGGLE, TEXT_ALIGNMENT), GetColor(GuiGetStyle(TOGGLE, ((*active)? TEXT_COLOR_PRESSED : (TEXT + state*3)))));
  1841. }
  1842. else
  1843. {
  1844. GuiDrawRectangle(bounds, GuiGetStyle(TOGGLE, BORDER_WIDTH), GetColor(GuiGetStyle(TOGGLE, BORDER + state*3)), GetColor(GuiGetStyle(TOGGLE, BASE + state*3)));
  1845. GuiDrawText(text, GetTextBounds(TOGGLE, bounds), GuiGetStyle(TOGGLE, TEXT_ALIGNMENT), GetColor(GuiGetStyle(TOGGLE, TEXT + state*3)));
  1846. }
  1847. if (state == STATE_FOCUSED) GuiTooltip(bounds);
  1848. //--------------------------------------------------------------------
  1849. return result;
  1850. }
  1851. // Toggle Group control, returns toggled button codepointIndex
  1852. int GuiToggleGroup(Rectangle bounds, const char *text, int *active)
  1853. {
  1854. #if !defined(RAYGUI_TOGGLEGROUP_MAX_ITEMS)
  1855. #define RAYGUI_TOGGLEGROUP_MAX_ITEMS 32
  1856. #endif
  1857. int result = 0;
  1858. float initBoundsX = bounds.x;
  1859. int temp = 0;
  1860. if (active == NULL) active = &temp;
  1861. bool toggle = false; // Required for individual toggles
  1862. // Get substrings items from text (items pointers)
  1863. int rows[RAYGUI_TOGGLEGROUP_MAX_ITEMS] = { 0 };
  1864. int itemCount = 0;
  1865. const char **items = GuiTextSplit(text, ';', &itemCount, rows);
  1866. int prevRow = rows[0];
  1867. for (int i = 0; i < itemCount; i++)
  1868. {
  1869. if (prevRow != rows[i])
  1870. {
  1871. bounds.x = initBoundsX;
  1872. bounds.y += (bounds.height + GuiGetStyle(TOGGLE, GROUP_PADDING));
  1873. prevRow = rows[i];
  1874. }
  1875. if (i == (*active))
  1876. {
  1877. toggle = true;
  1878. GuiToggle(bounds, items[i], &toggle);
  1879. }
  1880. else
  1881. {
  1882. toggle = false;
  1883. GuiToggle(bounds, items[i], &toggle);
  1884. if (toggle) *active = i;
  1885. }
  1886. bounds.x += (bounds.width + GuiGetStyle(TOGGLE, GROUP_PADDING));
  1887. }
  1888. return result;
  1889. }
  1890. // Toggle Slider control extended, returns true when clicked
  1891. int GuiToggleSlider(Rectangle bounds, const char *text, int *active)
  1892. {
  1893. int result = 0;
  1894. GuiState state = guiState;
  1895. int temp = 0;
  1896. if (active == NULL) active = &temp;
  1897. //bool toggle = false; // Required for individual toggles
  1898. // Get substrings items from text (items pointers)
  1899. int itemCount = 0;
  1900. const char **items = GuiTextSplit(text, ';', &itemCount, NULL);
  1901. Rectangle slider = {
  1902. 0, // Calculated later depending on the active toggle
  1903. bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH) + GuiGetStyle(SLIDER, SLIDER_PADDING),
  1904. (bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH) - (itemCount + 1)*GuiGetStyle(SLIDER, SLIDER_PADDING))/itemCount,
  1905. bounds.height - 2*GuiGetStyle(SLIDER, BORDER_WIDTH) - 2*GuiGetStyle(SLIDER, SLIDER_PADDING) };
  1906. // Update control
  1907. //--------------------------------------------------------------------
  1908. if ((state != STATE_DISABLED) && !guiLocked)
  1909. {
  1910. Vector2 mousePoint = GetMousePosition();
  1911. if (CheckCollisionPointRec(mousePoint, bounds))
  1912. {
  1913. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
  1914. else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
  1915. {
  1916. state = STATE_PRESSED;
  1917. (*active)++;
  1918. result = 1;
  1919. }
  1920. else state = STATE_FOCUSED;
  1921. }
  1922. if ((*active) && (state != STATE_FOCUSED)) state = STATE_PRESSED;
  1923. }
  1924. if (*active >= itemCount) *active = 0;
  1925. slider.x = bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH) + (*active + 1)*GuiGetStyle(SLIDER, SLIDER_PADDING) + (*active)*slider.width;
  1926. //--------------------------------------------------------------------
  1927. // Draw control
  1928. //--------------------------------------------------------------------
  1929. GuiDrawRectangle(bounds, GuiGetStyle(SLIDER, BORDER_WIDTH), GetColor(GuiGetStyle(TOGGLE, BORDER + (state*3))),
  1930. GetColor(GuiGetStyle(TOGGLE, BASE_COLOR_NORMAL)));
  1931. // Draw internal slider
  1932. if (state == STATE_NORMAL) GuiDrawRectangle(slider, 0, BLANK, GetColor(GuiGetStyle(SLIDER, BASE_COLOR_PRESSED)));
  1933. else if (state == STATE_FOCUSED) GuiDrawRectangle(slider, 0, BLANK, GetColor(GuiGetStyle(SLIDER, BASE_COLOR_FOCUSED)));
  1934. else if (state == STATE_PRESSED) GuiDrawRectangle(slider, 0, BLANK, GetColor(GuiGetStyle(SLIDER, BASE_COLOR_PRESSED)));
  1935. // Draw text in slider
  1936. if (text != NULL)
  1937. {
  1938. Rectangle textBounds = { 0 };
  1939. textBounds.width = (float)GetTextWidth(text);
  1940. textBounds.height = (float)GuiGetStyle(DEFAULT, TEXT_SIZE);
  1941. textBounds.x = slider.x + slider.width/2 - textBounds.width/2;
  1942. textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
  1943. GuiDrawText(items[*active], textBounds, GuiGetStyle(TOGGLE, TEXT_ALIGNMENT), Fade(GetColor(GuiGetStyle(TOGGLE, TEXT + (state*3))), guiAlpha));
  1944. }
  1945. //--------------------------------------------------------------------
  1946. return result;
  1947. }
  1948. // Check Box control, returns 1 when state changed
  1949. int GuiCheckBox(Rectangle bounds, const char *text, bool *checked)
  1950. {
  1951. int result = 0;
  1952. GuiState state = guiState;
  1953. bool temp = false;
  1954. if (checked == NULL) checked = &temp;
  1955. Rectangle textBounds = { 0 };
  1956. if (text != NULL)
  1957. {
  1958. textBounds.width = (float)GetTextWidth(text) + 2;
  1959. textBounds.height = (float)GuiGetStyle(DEFAULT, TEXT_SIZE);
  1960. textBounds.x = bounds.x + bounds.width + GuiGetStyle(CHECKBOX, TEXT_PADDING);
  1961. textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
  1962. if (GuiGetStyle(CHECKBOX, TEXT_ALIGNMENT) == TEXT_ALIGN_LEFT) textBounds.x = bounds.x - textBounds.width - GuiGetStyle(CHECKBOX, TEXT_PADDING);
  1963. }
  1964. // Update control
  1965. //--------------------------------------------------------------------
  1966. if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
  1967. {
  1968. Vector2 mousePoint = GetMousePosition();
  1969. Rectangle totalBounds = {
  1970. (GuiGetStyle(CHECKBOX, TEXT_ALIGNMENT) == TEXT_ALIGN_LEFT)? textBounds.x : bounds.x,
  1971. bounds.y,
  1972. bounds.width + textBounds.width + GuiGetStyle(CHECKBOX, TEXT_PADDING),
  1973. bounds.height,
  1974. };
  1975. // Check checkbox state
  1976. if (CheckCollisionPointRec(mousePoint, totalBounds))
  1977. {
  1978. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
  1979. else state = STATE_FOCUSED;
  1980. if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
  1981. {
  1982. *checked = !(*checked);
  1983. result = 1;
  1984. }
  1985. }
  1986. }
  1987. //--------------------------------------------------------------------
  1988. // Draw control
  1989. //--------------------------------------------------------------------
  1990. GuiDrawRectangle(bounds, GuiGetStyle(CHECKBOX, BORDER_WIDTH), GetColor(GuiGetStyle(CHECKBOX, BORDER + (state*3))), BLANK);
  1991. if (*checked)
  1992. {
  1993. Rectangle check = { bounds.x + GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, CHECK_PADDING),
  1994. bounds.y + GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, CHECK_PADDING),
  1995. bounds.width - 2*(GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, CHECK_PADDING)),
  1996. bounds.height - 2*(GuiGetStyle(CHECKBOX, BORDER_WIDTH) + GuiGetStyle(CHECKBOX, CHECK_PADDING)) };
  1997. GuiDrawRectangle(check, 0, BLANK, GetColor(GuiGetStyle(CHECKBOX, TEXT + state*3)));
  1998. }
  1999. GuiDrawText(text, textBounds, (GuiGetStyle(CHECKBOX, TEXT_ALIGNMENT) == TEXT_ALIGN_RIGHT)? TEXT_ALIGN_LEFT : TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(LABEL, TEXT + (state*3))));
  2000. //--------------------------------------------------------------------
  2001. return result;
  2002. }
  2003. // Combo Box control, returns selected item codepointIndex
  2004. int GuiComboBox(Rectangle bounds, const char *text, int *active)
  2005. {
  2006. int result = 0;
  2007. GuiState state = guiState;
  2008. int temp = 0;
  2009. if (active == NULL) active = &temp;
  2010. bounds.width -= (GuiGetStyle(COMBOBOX, COMBO_BUTTON_WIDTH) + GuiGetStyle(COMBOBOX, COMBO_BUTTON_SPACING));
  2011. Rectangle selector = { (float)bounds.x + bounds.width + GuiGetStyle(COMBOBOX, COMBO_BUTTON_SPACING),
  2012. (float)bounds.y, (float)GuiGetStyle(COMBOBOX, COMBO_BUTTON_WIDTH), (float)bounds.height };
  2013. // Get substrings items from text (items pointers, lengths and count)
  2014. int itemCount = 0;
  2015. const char **items = GuiTextSplit(text, ';', &itemCount, NULL);
  2016. if (*active < 0) *active = 0;
  2017. else if (*active > (itemCount - 1)) *active = itemCount - 1;
  2018. // Update control
  2019. //--------------------------------------------------------------------
  2020. if ((state != STATE_DISABLED) && !guiLocked && (itemCount > 1) && !guiSliderDragging)
  2021. {
  2022. Vector2 mousePoint = GetMousePosition();
  2023. if (CheckCollisionPointRec(mousePoint, bounds) ||
  2024. CheckCollisionPointRec(mousePoint, selector))
  2025. {
  2026. if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
  2027. {
  2028. *active += 1;
  2029. if (*active >= itemCount) *active = 0; // Cyclic combobox
  2030. }
  2031. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
  2032. else state = STATE_FOCUSED;
  2033. }
  2034. }
  2035. //--------------------------------------------------------------------
  2036. // Draw control
  2037. //--------------------------------------------------------------------
  2038. // Draw combo box main
  2039. GuiDrawRectangle(bounds, GuiGetStyle(COMBOBOX, BORDER_WIDTH), GetColor(GuiGetStyle(COMBOBOX, BORDER + (state*3))), GetColor(GuiGetStyle(COMBOBOX, BASE + (state*3))));
  2040. GuiDrawText(items[*active], GetTextBounds(COMBOBOX, bounds), GuiGetStyle(COMBOBOX, TEXT_ALIGNMENT), GetColor(GuiGetStyle(COMBOBOX, TEXT + (state*3))));
  2041. // Draw selector using a custom button
  2042. // NOTE: BORDER_WIDTH and TEXT_ALIGNMENT forced values
  2043. int tempBorderWidth = GuiGetStyle(BUTTON, BORDER_WIDTH);
  2044. int tempTextAlign = GuiGetStyle(BUTTON, TEXT_ALIGNMENT);
  2045. GuiSetStyle(BUTTON, BORDER_WIDTH, 1);
  2046. GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
  2047. GuiButton(selector, TextFormat("%i/%i", *active + 1, itemCount));
  2048. GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlign);
  2049. GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth);
  2050. //--------------------------------------------------------------------
  2051. return result;
  2052. }
  2053. // Dropdown Box control
  2054. // NOTE: Returns mouse click
  2055. int GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMode)
  2056. {
  2057. int result = 0;
  2058. GuiState state = guiState;
  2059. int itemSelected = *active;
  2060. int itemFocused = -1;
  2061. // Get substrings items from text (items pointers, lengths and count)
  2062. int itemCount = 0;
  2063. const char **items = GuiTextSplit(text, ';', &itemCount, NULL);
  2064. Rectangle boundsOpen = bounds;
  2065. boundsOpen.height = (itemCount + 1)*(bounds.height + GuiGetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_SPACING));
  2066. Rectangle itemBounds = bounds;
  2067. // Update control
  2068. //--------------------------------------------------------------------
  2069. if ((state != STATE_DISABLED) && (editMode || !guiLocked) && (itemCount > 1) && !guiSliderDragging)
  2070. {
  2071. Vector2 mousePoint = GetMousePosition();
  2072. if (editMode)
  2073. {
  2074. state = STATE_PRESSED;
  2075. // Check if mouse has been pressed or released outside limits
  2076. if (!CheckCollisionPointRec(mousePoint, boundsOpen))
  2077. {
  2078. if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) || IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) result = 1;
  2079. }
  2080. // Check if already selected item has been pressed again
  2081. if (CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) result = 1;
  2082. // Check focused and selected item
  2083. for (int i = 0; i < itemCount; i++)
  2084. {
  2085. // Update item rectangle y position for next item
  2086. itemBounds.y += (bounds.height + GuiGetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_SPACING));
  2087. if (CheckCollisionPointRec(mousePoint, itemBounds))
  2088. {
  2089. itemFocused = i;
  2090. if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
  2091. {
  2092. itemSelected = i;
  2093. result = 1; // Item selected
  2094. }
  2095. break;
  2096. }
  2097. }
  2098. itemBounds = bounds;
  2099. }
  2100. else
  2101. {
  2102. if (CheckCollisionPointRec(mousePoint, bounds))
  2103. {
  2104. if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
  2105. {
  2106. result = 1;
  2107. state = STATE_PRESSED;
  2108. }
  2109. else state = STATE_FOCUSED;
  2110. }
  2111. }
  2112. }
  2113. //--------------------------------------------------------------------
  2114. // Draw control
  2115. //--------------------------------------------------------------------
  2116. if (editMode) GuiPanel(boundsOpen, NULL);
  2117. GuiDrawRectangle(bounds, GuiGetStyle(DROPDOWNBOX, BORDER_WIDTH), GetColor(GuiGetStyle(DROPDOWNBOX, BORDER + state*3)), GetColor(GuiGetStyle(DROPDOWNBOX, BASE + state*3)));
  2118. GuiDrawText(items[itemSelected], GetTextBounds(DROPDOWNBOX, bounds), GuiGetStyle(DROPDOWNBOX, TEXT_ALIGNMENT), GetColor(GuiGetStyle(DROPDOWNBOX, TEXT + state*3)));
  2119. if (editMode)
  2120. {
  2121. // Draw visible items
  2122. for (int i = 0; i < itemCount; i++)
  2123. {
  2124. // Update item rectangle y position for next item
  2125. itemBounds.y += (bounds.height + GuiGetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_SPACING));
  2126. if (i == itemSelected)
  2127. {
  2128. GuiDrawRectangle(itemBounds, GuiGetStyle(DROPDOWNBOX, BORDER_WIDTH), GetColor(GuiGetStyle(DROPDOWNBOX, BORDER_COLOR_PRESSED)), GetColor(GuiGetStyle(DROPDOWNBOX, BASE_COLOR_PRESSED)));
  2129. GuiDrawText(items[i], GetTextBounds(DROPDOWNBOX, itemBounds), GuiGetStyle(DROPDOWNBOX, TEXT_ALIGNMENT), GetColor(GuiGetStyle(DROPDOWNBOX, TEXT_COLOR_PRESSED)));
  2130. }
  2131. else if (i == itemFocused)
  2132. {
  2133. GuiDrawRectangle(itemBounds, GuiGetStyle(DROPDOWNBOX, BORDER_WIDTH), GetColor(GuiGetStyle(DROPDOWNBOX, BORDER_COLOR_FOCUSED)), GetColor(GuiGetStyle(DROPDOWNBOX, BASE_COLOR_FOCUSED)));
  2134. GuiDrawText(items[i], GetTextBounds(DROPDOWNBOX, itemBounds), GuiGetStyle(DROPDOWNBOX, TEXT_ALIGNMENT), GetColor(GuiGetStyle(DROPDOWNBOX, TEXT_COLOR_FOCUSED)));
  2135. }
  2136. else GuiDrawText(items[i], GetTextBounds(DROPDOWNBOX, itemBounds), GuiGetStyle(DROPDOWNBOX, TEXT_ALIGNMENT), GetColor(GuiGetStyle(DROPDOWNBOX, TEXT_COLOR_NORMAL)));
  2137. }
  2138. }
  2139. // Draw arrows (using icon if available)
  2140. #if defined(RAYGUI_NO_ICONS)
  2141. GuiDrawText("v", RAYGUI_CLITERAL(Rectangle){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_PADDING), bounds.y + bounds.height/2 - 2, 10, 10 },
  2142. TEXT_ALIGN_CENTER, GetColor(GuiGetStyle(DROPDOWNBOX, TEXT + (state*3))));
  2143. #else
  2144. GuiDrawText("#120#", RAYGUI_CLITERAL(Rectangle){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_PADDING), bounds.y + bounds.height/2 - 6, 10, 10 },
  2145. TEXT_ALIGN_CENTER, GetColor(GuiGetStyle(DROPDOWNBOX, TEXT + (state*3)))); // ICON_ARROW_DOWN_FILL
  2146. #endif
  2147. //--------------------------------------------------------------------
  2148. *active = itemSelected;
  2149. // TODO: Use result to return more internal states: mouse-press out-of-bounds, mouse-press over selected-item...
  2150. return result; // Mouse click: result = 1
  2151. }
  2152. // Text Box control
  2153. // NOTE: Returns true on ENTER pressed (useful for data validation)
  2154. int GuiTextBox(Rectangle bounds, char *text, int bufferSize, bool editMode)
  2155. {
  2156. #if !defined(RAYGUI_TEXTBOX_AUTO_CURSOR_COOLDOWN)
  2157. #define RAYGUI_TEXTBOX_AUTO_CURSOR_COOLDOWN 40 // Frames to wait for autocursor movement
  2158. #endif
  2159. #if !defined(RAYGUI_TEXTBOX_AUTO_CURSOR_DELAY)
  2160. #define RAYGUI_TEXTBOX_AUTO_CURSOR_DELAY 1 // Frames delay for autocursor movement
  2161. #endif
  2162. int result = 0;
  2163. GuiState state = guiState;
  2164. bool multiline = false; // TODO: Consider multiline text input
  2165. int wrapMode = GuiGetStyle(DEFAULT, TEXT_WRAP_MODE);
  2166. Rectangle textBounds = GetTextBounds(TEXTBOX, bounds);
  2167. int textWidth = GetTextWidth(text) - GetTextWidth(text + textBoxCursorIndex);
  2168. int textIndexOffset = 0; // Text index offset to start drawing in the box
  2169. // Cursor rectangle
  2170. // NOTE: Position X value should be updated
  2171. Rectangle cursor = {
  2172. textBounds.x + textWidth + GuiGetStyle(DEFAULT, TEXT_SPACING),
  2173. textBounds.y + textBounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE),
  2174. 2,
  2175. (float)GuiGetStyle(DEFAULT, TEXT_SIZE)*2
  2176. };
  2177. if (cursor.height >= bounds.height) cursor.height = bounds.height - GuiGetStyle(TEXTBOX, BORDER_WIDTH)*2;
  2178. if (cursor.y < (bounds.y + GuiGetStyle(TEXTBOX, BORDER_WIDTH))) cursor.y = bounds.y + GuiGetStyle(TEXTBOX, BORDER_WIDTH);
  2179. // Mouse cursor rectangle
  2180. // NOTE: Initialized outside of screen
  2181. Rectangle mouseCursor = cursor;
  2182. mouseCursor.x = -1;
  2183. mouseCursor.width = 1;
  2184. // Auto-cursor movement logic
  2185. // NOTE: Cursor moves automatically when key down after some time
  2186. if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_UP) || IsKeyDown(KEY_DOWN) || IsKeyDown(KEY_BACKSPACE) || IsKeyDown(KEY_DELETE)) autoCursorCooldownCounter++;
  2187. else
  2188. {
  2189. autoCursorCooldownCounter = 0; // GLOBAL: Cursor cooldown counter
  2190. autoCursorDelayCounter = 0; // GLOBAL: Cursor delay counter
  2191. }
  2192. // Blink-cursor frame counter
  2193. //if (!autoCursorMode) blinkCursorFrameCounter++;
  2194. //else blinkCursorFrameCounter = 0;
  2195. // Update control
  2196. //--------------------------------------------------------------------
  2197. // WARNING: Text editing is only supported under certain conditions:
  2198. if ((state != STATE_DISABLED) && // Control not disabled
  2199. !GuiGetStyle(TEXTBOX, TEXT_READONLY) && // TextBox not on read-only mode
  2200. !guiLocked && // Gui not locked
  2201. !guiSliderDragging && // No gui slider on dragging
  2202. (wrapMode == TEXT_WRAP_NONE)) // No wrap mode
  2203. {
  2204. Vector2 mousePosition = GetMousePosition();
  2205. if (editMode)
  2206. {
  2207. state = STATE_PRESSED;
  2208. // If text does not fit in the textbox and current cursor position is out of bounds,
  2209. // we add an index offset to text for drawing only what requires depending on cursor
  2210. while (textWidth >= textBounds.width)
  2211. {
  2212. int nextCodepointSize = 0;
  2213. GetCodepointNext(text + textIndexOffset, &nextCodepointSize);
  2214. textIndexOffset += nextCodepointSize;
  2215. textWidth = GetTextWidth(text + textIndexOffset) - GetTextWidth(text + textBoxCursorIndex);
  2216. }
  2217. int textLength = (int)strlen(text); // Get current text length
  2218. int codepoint = GetCharPressed(); // Get Unicode codepoint
  2219. if (multiline && IsKeyPressed(KEY_ENTER)) codepoint = (int)'\n';
  2220. if (textBoxCursorIndex > textLength) textBoxCursorIndex = textLength;
  2221. // Encode codepoint as UTF-8
  2222. int codepointSize = 0;
  2223. const char *charEncoded = CodepointToUTF8(codepoint, &codepointSize);
  2224. // Add codepoint to text, at current cursor position
  2225. // NOTE: Make sure we do not overflow buffer size
  2226. if (((multiline && (codepoint == (int)'\n')) || (codepoint >= 32)) && ((textLength + codepointSize) < bufferSize))
  2227. {
  2228. // Move forward data from cursor position
  2229. for (int i = (textLength + codepointSize); i > textBoxCursorIndex; i--) text[i] = text[i - codepointSize];
  2230. // Add new codepoint in current cursor position
  2231. for (int i = 0; i < codepointSize; i++) text[textBoxCursorIndex + i] = charEncoded[i];
  2232. textBoxCursorIndex += codepointSize;
  2233. textLength += codepointSize;
  2234. // Make sure text last character is EOL
  2235. text[textLength] = '\0';
  2236. }
  2237. // Move cursor to start
  2238. if ((textLength > 0) && IsKeyPressed(KEY_HOME)) textBoxCursorIndex = 0;
  2239. // Move cursor to end
  2240. if ((textLength > textBoxCursorIndex) && IsKeyPressed(KEY_END)) textBoxCursorIndex = textLength;
  2241. // Delete codepoint from text, after current cursor position
  2242. if ((textLength > textBoxCursorIndex) && (IsKeyPressed(KEY_DELETE) || (IsKeyDown(KEY_DELETE) && (autoCursorCooldownCounter >= RAYGUI_TEXTBOX_AUTO_CURSOR_COOLDOWN))))
  2243. {
  2244. autoCursorDelayCounter++;
  2245. if (IsKeyPressed(KEY_DELETE) || (autoCursorDelayCounter%RAYGUI_TEXTBOX_AUTO_CURSOR_DELAY) == 0) // Delay every movement some frames
  2246. {
  2247. int nextCodepointSize = 0;
  2248. GetCodepointNext(text + textBoxCursorIndex, &nextCodepointSize);
  2249. // Move backward text from cursor position
  2250. for (int i = textBoxCursorIndex; i < textLength; i++) text[i] = text[i + nextCodepointSize];
  2251. textLength -= codepointSize;
  2252. // Make sure text last character is EOL
  2253. text[textLength] = '\0';
  2254. }
  2255. }
  2256. // Delete codepoint from text, before current cursor position
  2257. if ((textLength > 0) && (IsKeyPressed(KEY_BACKSPACE) || (IsKeyDown(KEY_BACKSPACE) && (autoCursorCooldownCounter >= RAYGUI_TEXTBOX_AUTO_CURSOR_COOLDOWN))))
  2258. {
  2259. autoCursorDelayCounter++;
  2260. if (IsKeyPressed(KEY_BACKSPACE) || (autoCursorDelayCounter%RAYGUI_TEXTBOX_AUTO_CURSOR_DELAY) == 0) // Delay every movement some frames
  2261. {
  2262. int prevCodepointSize = 0;
  2263. GetCodepointPrevious(text + textBoxCursorIndex, &prevCodepointSize);
  2264. // Move backward text from cursor position
  2265. for (int i = (textBoxCursorIndex - prevCodepointSize); i < textLength; i++) text[i] = text[i + prevCodepointSize];
  2266. // Prevent cursor index from decrementing past 0
  2267. if (textBoxCursorIndex > 0)
  2268. {
  2269. textBoxCursorIndex -= codepointSize;
  2270. textLength -= codepointSize;
  2271. }
  2272. // Make sure text last character is EOL
  2273. text[textLength] = '\0';
  2274. }
  2275. }
  2276. // Move cursor position with keys
  2277. if (IsKeyPressed(KEY_LEFT) || (IsKeyDown(KEY_LEFT) && (autoCursorCooldownCounter > RAYGUI_TEXTBOX_AUTO_CURSOR_COOLDOWN)))
  2278. {
  2279. autoCursorDelayCounter++;
  2280. if (IsKeyPressed(KEY_LEFT) || (autoCursorDelayCounter%RAYGUI_TEXTBOX_AUTO_CURSOR_DELAY) == 0) // Delay every movement some frames
  2281. {
  2282. int prevCodepointSize = 0;
  2283. GetCodepointPrevious(text + textBoxCursorIndex, &prevCodepointSize);
  2284. if (textBoxCursorIndex >= prevCodepointSize) textBoxCursorIndex -= prevCodepointSize;
  2285. }
  2286. }
  2287. else if (IsKeyPressed(KEY_RIGHT) || (IsKeyDown(KEY_RIGHT) && (autoCursorCooldownCounter > RAYGUI_TEXTBOX_AUTO_CURSOR_COOLDOWN)))
  2288. {
  2289. autoCursorDelayCounter++;
  2290. if (IsKeyPressed(KEY_RIGHT) || (autoCursorDelayCounter%RAYGUI_TEXTBOX_AUTO_CURSOR_DELAY) == 0) // Delay every movement some frames
  2291. {
  2292. int nextCodepointSize = 0;
  2293. GetCodepointNext(text + textBoxCursorIndex, &nextCodepointSize);
  2294. if ((textBoxCursorIndex + nextCodepointSize) <= textLength) textBoxCursorIndex += nextCodepointSize;
  2295. }
  2296. }
  2297. // Move cursor position with mouse
  2298. if (CheckCollisionPointRec(mousePosition, textBounds)) // Mouse hover text
  2299. {
  2300. float scaleFactor = (float)GuiGetStyle(DEFAULT, TEXT_SIZE)/(float)guiFont.baseSize;
  2301. int codepointIndex = 0;
  2302. float glyphWidth = 0.0f;
  2303. float widthToMouseX = 0;
  2304. int mouseCursorIndex = 0;
  2305. for (int i = textIndexOffset; i < textLength; i++)
  2306. {
  2307. codepoint = GetCodepointNext(&text[i], &codepointSize);
  2308. codepointIndex = GetGlyphIndex(guiFont, codepoint);
  2309. if (guiFont.glyphs[codepointIndex].advanceX == 0) glyphWidth = ((float)guiFont.recs[codepointIndex].width*scaleFactor);
  2310. else glyphWidth = ((float)guiFont.glyphs[codepointIndex].advanceX*scaleFactor);
  2311. if (mousePosition.x <= (textBounds.x + (widthToMouseX + glyphWidth/2)))
  2312. {
  2313. mouseCursor.x = textBounds.x + widthToMouseX;
  2314. mouseCursorIndex = i;
  2315. break;
  2316. }
  2317. widthToMouseX += (glyphWidth + (float)GuiGetStyle(DEFAULT, TEXT_SPACING));
  2318. }
  2319. // Check if mouse cursor is at the last position
  2320. int textEndWidth = GetTextWidth(text + textIndexOffset);
  2321. if (GetMousePosition().x >= (textBounds.x + textEndWidth - glyphWidth/2))
  2322. {
  2323. mouseCursor.x = textBounds.x + textEndWidth;
  2324. mouseCursorIndex = (int)strlen(text);
  2325. }
  2326. // Place cursor at required index on mouse click
  2327. if ((mouseCursor.x >= 0) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
  2328. {
  2329. cursor.x = mouseCursor.x;
  2330. textBoxCursorIndex = mouseCursorIndex;
  2331. }
  2332. }
  2333. else mouseCursor.x = -1;
  2334. // Recalculate cursor position.y depending on textBoxCursorIndex
  2335. cursor.x = bounds.x + GuiGetStyle(TEXTBOX, TEXT_PADDING) + GetTextWidth(text + textIndexOffset) - GetTextWidth(text + textBoxCursorIndex) + GuiGetStyle(DEFAULT, TEXT_SPACING);
  2336. //if (multiline) cursor.y = GetTextLines()
  2337. // Finish text editing on ENTER or mouse click outside bounds
  2338. if ((!multiline && IsKeyPressed(KEY_ENTER)) ||
  2339. (!CheckCollisionPointRec(mousePosition, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)))
  2340. {
  2341. textBoxCursorIndex = 0; // GLOBAL: Reset the shared cursor index
  2342. result = 1;
  2343. }
  2344. }
  2345. else
  2346. {
  2347. if (CheckCollisionPointRec(mousePosition, bounds))
  2348. {
  2349. state = STATE_FOCUSED;
  2350. if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
  2351. {
  2352. textBoxCursorIndex = (int)strlen(text); // GLOBAL: Place cursor index to the end of current text
  2353. result = 1;
  2354. }
  2355. }
  2356. }
  2357. }
  2358. //--------------------------------------------------------------------
  2359. // Draw control
  2360. //--------------------------------------------------------------------
  2361. if (state == STATE_PRESSED)
  2362. {
  2363. GuiDrawRectangle(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), GetColor(GuiGetStyle(TEXTBOX, BORDER + (state*3))), GetColor(GuiGetStyle(TEXTBOX, BASE_COLOR_PRESSED)));
  2364. }
  2365. else if (state == STATE_DISABLED)
  2366. {
  2367. GuiDrawRectangle(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), GetColor(GuiGetStyle(TEXTBOX, BORDER + (state*3))), GetColor(GuiGetStyle(TEXTBOX, BASE_COLOR_DISABLED)));
  2368. }
  2369. else GuiDrawRectangle(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), GetColor(GuiGetStyle(TEXTBOX, BORDER + (state*3))), BLANK);
  2370. // Draw text considering index offset if required
  2371. // NOTE: Text index offset depends on cursor position
  2372. GuiDrawText(text + textIndexOffset, textBounds, GuiGetStyle(TEXTBOX, TEXT_ALIGNMENT), GetColor(GuiGetStyle(TEXTBOX, TEXT + (state*3))));
  2373. // Draw cursor
  2374. if (editMode && !GuiGetStyle(TEXTBOX, TEXT_READONLY))
  2375. {
  2376. //if (autoCursorMode || ((blinkCursorFrameCounter/40)%2 == 0))
  2377. GuiDrawRectangle(cursor, 0, BLANK, GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_PRESSED)));
  2378. // Draw mouse position cursor (if required)
  2379. if (mouseCursor.x >= 0) GuiDrawRectangle(mouseCursor, 0, BLANK, GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_PRESSED)));
  2380. }
  2381. else if (state == STATE_FOCUSED) GuiTooltip(bounds);
  2382. //--------------------------------------------------------------------
  2383. return result; // Mouse button pressed: result = 1
  2384. }
  2385. /*
  2386. // Text Box control with multiple lines and word-wrap
  2387. // NOTE: This text-box is readonly, no editing supported by default
  2388. bool GuiTextBoxMulti(Rectangle bounds, char *text, int bufferSize, bool editMode)
  2389. {
  2390. bool pressed = false;
  2391. GuiSetStyle(TEXTBOX, TEXT_READONLY, 1);
  2392. GuiSetStyle(DEFAULT, TEXT_WRAP_MODE, TEXT_WRAP_WORD); // WARNING: If wrap mode enabled, text editing is not supported
  2393. GuiSetStyle(DEFAULT, TEXT_ALIGNMENT_VERTICAL, TEXT_ALIGN_TOP);
  2394. // TODO: Implement methods to calculate cursor position properly
  2395. pressed = GuiTextBox(bounds, text, bufferSize, editMode);
  2396. GuiSetStyle(DEFAULT, TEXT_ALIGNMENT_VERTICAL, TEXT_ALIGN_MIDDLE);
  2397. GuiSetStyle(DEFAULT, TEXT_WRAP_MODE, TEXT_WRAP_NONE);
  2398. GuiSetStyle(TEXTBOX, TEXT_READONLY, 0);
  2399. return pressed;
  2400. }
  2401. */
  2402. // Spinner control, returns selected value
  2403. int GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode)
  2404. {
  2405. int result = 1;
  2406. GuiState state = guiState;
  2407. int tempValue = *value;
  2408. Rectangle spinner = { bounds.x + GuiGetStyle(SPINNER, SPIN_BUTTON_WIDTH) + GuiGetStyle(SPINNER, SPIN_BUTTON_SPACING), bounds.y,
  2409. bounds.width - 2*(GuiGetStyle(SPINNER, SPIN_BUTTON_WIDTH) + GuiGetStyle(SPINNER, SPIN_BUTTON_SPACING)), bounds.height };
  2410. Rectangle leftButtonBound = { (float)bounds.x, (float)bounds.y, (float)GuiGetStyle(SPINNER, SPIN_BUTTON_WIDTH), (float)bounds.height };
  2411. Rectangle rightButtonBound = { (float)bounds.x + bounds.width - GuiGetStyle(SPINNER, SPIN_BUTTON_WIDTH), (float)bounds.y, (float)GuiGetStyle(SPINNER, SPIN_BUTTON_WIDTH), (float)bounds.height };
  2412. Rectangle textBounds = { 0 };
  2413. if (text != NULL)
  2414. {
  2415. textBounds.width = (float)GetTextWidth(text) + 2;
  2416. textBounds.height = (float)GuiGetStyle(DEFAULT, TEXT_SIZE);
  2417. textBounds.x = bounds.x + bounds.width + GuiGetStyle(SPINNER, TEXT_PADDING);
  2418. textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
  2419. if (GuiGetStyle(SPINNER, TEXT_ALIGNMENT) == TEXT_ALIGN_LEFT) textBounds.x = bounds.x - textBounds.width - GuiGetStyle(SPINNER, TEXT_PADDING);
  2420. }
  2421. // Update control
  2422. //--------------------------------------------------------------------
  2423. if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
  2424. {
  2425. Vector2 mousePoint = GetMousePosition();
  2426. // Check spinner state
  2427. if (CheckCollisionPointRec(mousePoint, bounds))
  2428. {
  2429. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
  2430. else state = STATE_FOCUSED;
  2431. }
  2432. }
  2433. #if defined(RAYGUI_NO_ICONS)
  2434. if (GuiButton(leftButtonBound, "<")) tempValue--;
  2435. if (GuiButton(rightButtonBound, ">")) tempValue++;
  2436. #else
  2437. if (GuiButton(leftButtonBound, GuiIconText(ICON_ARROW_LEFT_FILL, NULL))) tempValue--;
  2438. if (GuiButton(rightButtonBound, GuiIconText(ICON_ARROW_RIGHT_FILL, NULL))) tempValue++;
  2439. #endif
  2440. if (!editMode)
  2441. {
  2442. if (tempValue < minValue) tempValue = minValue;
  2443. if (tempValue > maxValue) tempValue = maxValue;
  2444. }
  2445. //--------------------------------------------------------------------
  2446. // Draw control
  2447. //--------------------------------------------------------------------
  2448. result = GuiValueBox(spinner, NULL, &tempValue, minValue, maxValue, editMode);
  2449. // Draw value selector custom buttons
  2450. // NOTE: BORDER_WIDTH and TEXT_ALIGNMENT forced values
  2451. int tempBorderWidth = GuiGetStyle(BUTTON, BORDER_WIDTH);
  2452. int tempTextAlign = GuiGetStyle(BUTTON, TEXT_ALIGNMENT);
  2453. GuiSetStyle(BUTTON, BORDER_WIDTH, GuiGetStyle(SPINNER, BORDER_WIDTH));
  2454. GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
  2455. GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlign);
  2456. GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth);
  2457. // Draw text label if provided
  2458. GuiDrawText(text, textBounds, (GuiGetStyle(SPINNER, TEXT_ALIGNMENT) == TEXT_ALIGN_RIGHT)? TEXT_ALIGN_LEFT : TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(LABEL, TEXT + (state*3))));
  2459. //--------------------------------------------------------------------
  2460. *value = tempValue;
  2461. return result;
  2462. }
  2463. // Value Box control, updates input text with numbers
  2464. // NOTE: Requires static variables: frameCounter
  2465. int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode)
  2466. {
  2467. #if !defined(RAYGUI_VALUEBOX_MAX_CHARS)
  2468. #define RAYGUI_VALUEBOX_MAX_CHARS 32
  2469. #endif
  2470. int result = 0;
  2471. GuiState state = guiState;
  2472. char textValue[RAYGUI_VALUEBOX_MAX_CHARS + 1] = "\0";
  2473. sprintf(textValue, "%i", *value);
  2474. Rectangle textBounds = { 0 };
  2475. if (text != NULL)
  2476. {
  2477. textBounds.width = (float)GetTextWidth(text) + 2;
  2478. textBounds.height = (float)GuiGetStyle(DEFAULT, TEXT_SIZE);
  2479. textBounds.x = bounds.x + bounds.width + GuiGetStyle(VALUEBOX, TEXT_PADDING);
  2480. textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
  2481. if (GuiGetStyle(VALUEBOX, TEXT_ALIGNMENT) == TEXT_ALIGN_LEFT) textBounds.x = bounds.x - textBounds.width - GuiGetStyle(VALUEBOX, TEXT_PADDING);
  2482. }
  2483. // Update control
  2484. //--------------------------------------------------------------------
  2485. if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
  2486. {
  2487. Vector2 mousePoint = GetMousePosition();
  2488. bool valueHasChanged = false;
  2489. if (editMode)
  2490. {
  2491. state = STATE_PRESSED;
  2492. int keyCount = (int)strlen(textValue);
  2493. // Only allow keys in range [48..57]
  2494. if (keyCount < RAYGUI_VALUEBOX_MAX_CHARS)
  2495. {
  2496. if (GetTextWidth(textValue) < bounds.width)
  2497. {
  2498. int key = GetCharPressed();
  2499. if ((key >= 48) && (key <= 57))
  2500. {
  2501. textValue[keyCount] = (char)key;
  2502. keyCount++;
  2503. valueHasChanged = true;
  2504. }
  2505. }
  2506. }
  2507. // Delete text
  2508. if (keyCount > 0)
  2509. {
  2510. if (IsKeyPressed(KEY_BACKSPACE))
  2511. {
  2512. keyCount--;
  2513. textValue[keyCount] = '\0';
  2514. valueHasChanged = true;
  2515. }
  2516. }
  2517. if (valueHasChanged) *value = TextToInteger(textValue);
  2518. // NOTE: We are not clamp values until user input finishes
  2519. //if (*value > maxValue) *value = maxValue;
  2520. //else if (*value < minValue) *value = minValue;
  2521. if (IsKeyPressed(KEY_ENTER) || (!CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) result = 1;
  2522. }
  2523. else
  2524. {
  2525. if (*value > maxValue) *value = maxValue;
  2526. else if (*value < minValue) *value = minValue;
  2527. if (CheckCollisionPointRec(mousePoint, bounds))
  2528. {
  2529. state = STATE_FOCUSED;
  2530. if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) result = 1;
  2531. }
  2532. }
  2533. }
  2534. //--------------------------------------------------------------------
  2535. // Draw control
  2536. //--------------------------------------------------------------------
  2537. Color baseColor = BLANK;
  2538. if (state == STATE_PRESSED) baseColor = GetColor(GuiGetStyle(VALUEBOX, BASE_COLOR_PRESSED));
  2539. else if (state == STATE_DISABLED) baseColor = GetColor(GuiGetStyle(VALUEBOX, BASE_COLOR_DISABLED));
  2540. GuiDrawRectangle(bounds, GuiGetStyle(VALUEBOX, BORDER_WIDTH), GetColor(GuiGetStyle(VALUEBOX, BORDER + (state*3))), baseColor);
  2541. GuiDrawText(textValue, GetTextBounds(VALUEBOX, bounds), TEXT_ALIGN_CENTER, GetColor(GuiGetStyle(VALUEBOX, TEXT + (state*3))));
  2542. // Draw cursor
  2543. if (editMode)
  2544. {
  2545. // NOTE: ValueBox internal text is always centered
  2546. Rectangle cursor = { bounds.x + GetTextWidth(textValue)/2 + bounds.width/2 + 1, bounds.y + 2*GuiGetStyle(VALUEBOX, BORDER_WIDTH), 4, bounds.height - 4*GuiGetStyle(VALUEBOX, BORDER_WIDTH) };
  2547. GuiDrawRectangle(cursor, 0, BLANK, GetColor(GuiGetStyle(VALUEBOX, BORDER_COLOR_PRESSED)));
  2548. }
  2549. // Draw text label if provided
  2550. GuiDrawText(text, textBounds, (GuiGetStyle(VALUEBOX, TEXT_ALIGNMENT) == TEXT_ALIGN_RIGHT)? TEXT_ALIGN_LEFT : TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(LABEL, TEXT + (state*3))));
  2551. //--------------------------------------------------------------------
  2552. return result;
  2553. }
  2554. // Slider control with pro parameters
  2555. // NOTE: Other GuiSlider*() controls use this one
  2556. int GuiSliderPro(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue, int sliderWidth)
  2557. {
  2558. int result = 0;
  2559. float oldValue = *value;
  2560. GuiState state = guiState;
  2561. float temp = (maxValue - minValue)/2.0f;
  2562. if (value == NULL) value = &temp;
  2563. int sliderValue = (int)(((*value - minValue)/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH)));
  2564. Rectangle slider = { bounds.x, bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH) + GuiGetStyle(SLIDER, SLIDER_PADDING),
  2565. 0, bounds.height - 2*GuiGetStyle(SLIDER, BORDER_WIDTH) - 2*GuiGetStyle(SLIDER, SLIDER_PADDING) };
  2566. if (sliderWidth > 0) // Slider
  2567. {
  2568. slider.x += (sliderValue - sliderWidth/2);
  2569. slider.width = (float)sliderWidth;
  2570. }
  2571. else if (sliderWidth == 0) // SliderBar
  2572. {
  2573. slider.x += GuiGetStyle(SLIDER, BORDER_WIDTH);
  2574. slider.width = (float)sliderValue;
  2575. }
  2576. // Update control
  2577. //--------------------------------------------------------------------
  2578. if ((state != STATE_DISABLED) && !guiLocked)
  2579. {
  2580. Vector2 mousePoint = GetMousePosition();
  2581. if (guiSliderDragging) // Keep dragging outside of bounds
  2582. {
  2583. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  2584. {
  2585. if (CHECK_BOUNDS_ID(bounds, guiSliderActive))
  2586. {
  2587. state = STATE_PRESSED;
  2588. // Get equivalent value and slider position from mousePosition.x
  2589. *value = ((maxValue - minValue)*(mousePoint.x - (float)(bounds.x + sliderWidth/2)))/(float)(bounds.width - sliderWidth) + minValue;
  2590. }
  2591. }
  2592. else
  2593. {
  2594. guiSliderDragging = false;
  2595. guiSliderActive = RAYGUI_CLITERAL(Rectangle){ 0, 0, 0, 0 };
  2596. }
  2597. }
  2598. else if (CheckCollisionPointRec(mousePoint, bounds))
  2599. {
  2600. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  2601. {
  2602. state = STATE_PRESSED;
  2603. guiSliderDragging = true;
  2604. guiSliderActive = bounds; // Store bounds as an identifier when dragging starts
  2605. if (!CheckCollisionPointRec(mousePoint, slider))
  2606. {
  2607. // Get equivalent value and slider position from mousePosition.x
  2608. *value = ((maxValue - minValue)*(mousePoint.x - (float)(bounds.x + sliderWidth/2)))/(float)(bounds.width - sliderWidth) + minValue;
  2609. if (sliderWidth > 0) slider.x = mousePoint.x - slider.width/2; // Slider
  2610. else if (sliderWidth == 0) slider.width = (float)sliderValue; // SliderBar
  2611. }
  2612. }
  2613. else state = STATE_FOCUSED;
  2614. }
  2615. if (*value > maxValue) *value = maxValue;
  2616. else if (*value < minValue) *value = minValue;
  2617. }
  2618. // Control value change check
  2619. if(oldValue == *value) result = 0;
  2620. else result = 1;
  2621. // Bar limits check
  2622. if (sliderWidth > 0) // Slider
  2623. {
  2624. if (slider.x <= (bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH))) slider.x = bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH);
  2625. else if ((slider.x + slider.width) >= (bounds.x + bounds.width)) slider.x = bounds.x + bounds.width - slider.width - GuiGetStyle(SLIDER, BORDER_WIDTH);
  2626. }
  2627. else if (sliderWidth == 0) // SliderBar
  2628. {
  2629. if (slider.width > bounds.width) slider.width = bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH);
  2630. }
  2631. //--------------------------------------------------------------------
  2632. // Draw control
  2633. //--------------------------------------------------------------------
  2634. GuiDrawRectangle(bounds, GuiGetStyle(SLIDER, BORDER_WIDTH), GetColor(GuiGetStyle(SLIDER, BORDER + (state*3))), GetColor(GuiGetStyle(SLIDER, (state != STATE_DISABLED)? BASE_COLOR_NORMAL : BASE_COLOR_DISABLED)));
  2635. // Draw slider internal bar (depends on state)
  2636. if (state == STATE_NORMAL) GuiDrawRectangle(slider, 0, BLANK, GetColor(GuiGetStyle(SLIDER, BASE_COLOR_PRESSED)));
  2637. else if (state == STATE_FOCUSED) GuiDrawRectangle(slider, 0, BLANK, GetColor(GuiGetStyle(SLIDER, TEXT_COLOR_FOCUSED)));
  2638. else if (state == STATE_PRESSED) GuiDrawRectangle(slider, 0, BLANK, GetColor(GuiGetStyle(SLIDER, TEXT_COLOR_PRESSED)));
  2639. // Draw left/right text if provided
  2640. if (textLeft != NULL)
  2641. {
  2642. Rectangle textBounds = { 0 };
  2643. textBounds.width = (float)GetTextWidth(textLeft);
  2644. textBounds.height = (float)GuiGetStyle(DEFAULT, TEXT_SIZE);
  2645. textBounds.x = bounds.x - textBounds.width - GuiGetStyle(SLIDER, TEXT_PADDING);
  2646. textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
  2647. GuiDrawText(textLeft, textBounds, TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(SLIDER, TEXT + (state*3))));
  2648. }
  2649. if (textRight != NULL)
  2650. {
  2651. Rectangle textBounds = { 0 };
  2652. textBounds.width = (float)GetTextWidth(textRight);
  2653. textBounds.height = (float)GuiGetStyle(DEFAULT, TEXT_SIZE);
  2654. textBounds.x = bounds.x + bounds.width + GuiGetStyle(SLIDER, TEXT_PADDING);
  2655. textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
  2656. GuiDrawText(textRight, textBounds, TEXT_ALIGN_LEFT, GetColor(GuiGetStyle(SLIDER, TEXT + (state*3))));
  2657. }
  2658. //--------------------------------------------------------------------
  2659. return result;
  2660. }
  2661. // Slider control extended, returns selected value and has text
  2662. int GuiSlider(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue)
  2663. {
  2664. return GuiSliderPro(bounds, textLeft, textRight, value, minValue, maxValue, GuiGetStyle(SLIDER, SLIDER_WIDTH));
  2665. }
  2666. // Slider Bar control extended, returns selected value
  2667. int GuiSliderBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue)
  2668. {
  2669. return GuiSliderPro(bounds, textLeft, textRight, value, minValue, maxValue, 0);
  2670. }
  2671. // Progress Bar control extended, shows current progress value
  2672. int GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue)
  2673. {
  2674. int result = 0;
  2675. GuiState state = guiState;
  2676. float temp = (maxValue - minValue)/2.0f;
  2677. if (value == NULL) value = &temp;
  2678. // Progress bar
  2679. Rectangle progress = { bounds.x + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH),
  2680. bounds.y + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) + GuiGetStyle(PROGRESSBAR, PROGRESS_PADDING), 0,
  2681. bounds.height - 2*GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) - 2*GuiGetStyle(PROGRESSBAR, PROGRESS_PADDING) };
  2682. // Update control
  2683. //--------------------------------------------------------------------
  2684. if (*value > maxValue) *value = maxValue;
  2685. // WARNING: Working with floats could lead to rounding issues
  2686. if ((state != STATE_DISABLED)) progress.width = (float)(*value/(maxValue - minValue))*bounds.width - ((*value >= maxValue)? (float)(2*GuiGetStyle(PROGRESSBAR, BORDER_WIDTH)) : 0.0f);
  2687. //--------------------------------------------------------------------
  2688. // Draw control
  2689. //--------------------------------------------------------------------
  2690. if (state == STATE_DISABLED)
  2691. {
  2692. GuiDrawRectangle(bounds, GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), GetColor(GuiGetStyle(PROGRESSBAR, BORDER + (state*3))), BLANK);
  2693. }
  2694. else
  2695. {
  2696. if (*value > minValue)
  2697. {
  2698. // Draw progress bar with colored border, more visual
  2699. GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y, (int)progress.width + (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) }, 0, BLANK, GetColor(GuiGetStyle(PROGRESSBAR, BORDER_COLOR_FOCUSED)));
  2700. GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y + 1, (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), bounds.height - 2 }, 0, BLANK, GetColor(GuiGetStyle(PROGRESSBAR, BORDER_COLOR_FOCUSED)));
  2701. GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y + bounds.height - 1, (int)progress.width + (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) }, 0, BLANK, GetColor(GuiGetStyle(PROGRESSBAR, BORDER_COLOR_FOCUSED)));
  2702. }
  2703. else GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y, (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), bounds.height }, 0, BLANK, GetColor(GuiGetStyle(PROGRESSBAR, BORDER_COLOR_NORMAL)));
  2704. if (*value >= maxValue) GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x + progress.width + 1, bounds.y, (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), bounds.height }, 0, BLANK, GetColor(GuiGetStyle(PROGRESSBAR, BORDER_COLOR_FOCUSED)));
  2705. else
  2706. {
  2707. // Draw borders not yet reached by value
  2708. GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x + (int)progress.width + 1, bounds.y, bounds.width - (int)progress.width - 1, (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) }, 0, BLANK, GetColor(GuiGetStyle(PROGRESSBAR, BORDER_COLOR_NORMAL)));
  2709. GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x + (int)progress.width + 1, bounds.y + bounds.height - 1, bounds.width - (int)progress.width - 1, (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) }, 0, BLANK, GetColor(GuiGetStyle(PROGRESSBAR, BORDER_COLOR_NORMAL)));
  2710. GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x + bounds.width - 1, bounds.y + 1, (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), bounds.height - 2 }, 0, BLANK, GetColor(GuiGetStyle(PROGRESSBAR, BORDER_COLOR_NORMAL)));
  2711. }
  2712. // Draw slider internal progress bar (depends on state)
  2713. GuiDrawRectangle(progress, 0, BLANK, GetColor(GuiGetStyle(PROGRESSBAR, BASE_COLOR_PRESSED)));
  2714. }
  2715. // Draw left/right text if provided
  2716. if (textLeft != NULL)
  2717. {
  2718. Rectangle textBounds = { 0 };
  2719. textBounds.width = (float)GetTextWidth(textLeft);
  2720. textBounds.height = (float)GuiGetStyle(DEFAULT, TEXT_SIZE);
  2721. textBounds.x = bounds.x - textBounds.width - GuiGetStyle(PROGRESSBAR, TEXT_PADDING);
  2722. textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
  2723. GuiDrawText(textLeft, textBounds, TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(PROGRESSBAR, TEXT + (state*3))));
  2724. }
  2725. if (textRight != NULL)
  2726. {
  2727. Rectangle textBounds = { 0 };
  2728. textBounds.width = (float)GetTextWidth(textRight);
  2729. textBounds.height = (float)GuiGetStyle(DEFAULT, TEXT_SIZE);
  2730. textBounds.x = bounds.x + bounds.width + GuiGetStyle(PROGRESSBAR, TEXT_PADDING);
  2731. textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
  2732. GuiDrawText(textRight, textBounds, TEXT_ALIGN_LEFT, GetColor(GuiGetStyle(PROGRESSBAR, TEXT + (state*3))));
  2733. }
  2734. //--------------------------------------------------------------------
  2735. return result;
  2736. }
  2737. // Status Bar control
  2738. int GuiStatusBar(Rectangle bounds, const char *text)
  2739. {
  2740. int result = 0;
  2741. GuiState state = guiState;
  2742. // Draw control
  2743. //--------------------------------------------------------------------
  2744. GuiDrawRectangle(bounds, GuiGetStyle(STATUSBAR, BORDER_WIDTH), GetColor(GuiGetStyle(STATUSBAR, BORDER + (state*3))), GetColor(GuiGetStyle(STATUSBAR, BASE + (state*3))));
  2745. GuiDrawText(text, GetTextBounds(STATUSBAR, bounds), GuiGetStyle(STATUSBAR, TEXT_ALIGNMENT), GetColor(GuiGetStyle(STATUSBAR, TEXT + (state*3))));
  2746. //--------------------------------------------------------------------
  2747. return result;
  2748. }
  2749. // Dummy rectangle control, intended for placeholding
  2750. int GuiDummyRec(Rectangle bounds, const char *text)
  2751. {
  2752. int result = 0;
  2753. GuiState state = guiState;
  2754. // Update control
  2755. //--------------------------------------------------------------------
  2756. if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
  2757. {
  2758. Vector2 mousePoint = GetMousePosition();
  2759. // Check button state
  2760. if (CheckCollisionPointRec(mousePoint, bounds))
  2761. {
  2762. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
  2763. else state = STATE_FOCUSED;
  2764. }
  2765. }
  2766. //--------------------------------------------------------------------
  2767. // Draw control
  2768. //--------------------------------------------------------------------
  2769. GuiDrawRectangle(bounds, 0, BLANK, GetColor(GuiGetStyle(DEFAULT, (state != STATE_DISABLED)? BASE_COLOR_NORMAL : BASE_COLOR_DISABLED)));
  2770. GuiDrawText(text, GetTextBounds(DEFAULT, bounds), TEXT_ALIGN_CENTER, GetColor(GuiGetStyle(BUTTON, (state != STATE_DISABLED)? TEXT_COLOR_NORMAL : TEXT_COLOR_DISABLED)));
  2771. //------------------------------------------------------------------
  2772. return result;
  2773. }
  2774. // List View control
  2775. int GuiListView(Rectangle bounds, const char *text, int *scrollIndex, int *active)
  2776. {
  2777. int result = 0;
  2778. int itemCount = 0;
  2779. const char **items = NULL;
  2780. if (text != NULL) items = GuiTextSplit(text, ';', &itemCount, NULL);
  2781. result = GuiListViewEx(bounds, items, itemCount, scrollIndex, active, NULL);
  2782. return result;
  2783. }
  2784. // List View control with extended parameters
  2785. int GuiListViewEx(Rectangle bounds, const char **text, int count, int *scrollIndex, int *active, int *focus)
  2786. {
  2787. int result = 0;
  2788. GuiState state = guiState;
  2789. int itemFocused = (focus == NULL)? -1 : *focus;
  2790. int itemSelected = (active == NULL)? -1 : *active;
  2791. // Check if we need a scroll bar
  2792. bool useScrollBar = false;
  2793. if ((GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) + GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING))*count > bounds.height) useScrollBar = true;
  2794. // Define base item rectangle [0]
  2795. Rectangle itemBounds = { 0 };
  2796. itemBounds.x = bounds.x + GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING);
  2797. itemBounds.y = bounds.y + GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING) + GuiGetStyle(DEFAULT, BORDER_WIDTH);
  2798. itemBounds.width = bounds.width - 2*GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING) - GuiGetStyle(DEFAULT, BORDER_WIDTH);
  2799. itemBounds.height = (float)GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT);
  2800. if (useScrollBar) itemBounds.width -= GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH);
  2801. // Get items on the list
  2802. int visibleItems = (int)bounds.height/(GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) + GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING));
  2803. if (visibleItems > count) visibleItems = count;
  2804. int startIndex = (scrollIndex == NULL)? 0 : *scrollIndex;
  2805. if ((startIndex < 0) || (startIndex > (count - visibleItems))) startIndex = 0;
  2806. int endIndex = startIndex + visibleItems;
  2807. // Update control
  2808. //--------------------------------------------------------------------
  2809. if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
  2810. {
  2811. Vector2 mousePoint = GetMousePosition();
  2812. // Check mouse inside list view
  2813. if (CheckCollisionPointRec(mousePoint, bounds))
  2814. {
  2815. state = STATE_FOCUSED;
  2816. // Check focused and selected item
  2817. for (int i = 0; i < visibleItems; i++)
  2818. {
  2819. if (CheckCollisionPointRec(mousePoint, itemBounds))
  2820. {
  2821. itemFocused = startIndex + i;
  2822. if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
  2823. {
  2824. if (itemSelected == (startIndex + i)) itemSelected = -1;
  2825. else itemSelected = startIndex + i;
  2826. }
  2827. break;
  2828. }
  2829. // Update item rectangle y position for next item
  2830. itemBounds.y += (GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) + GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING));
  2831. }
  2832. if (useScrollBar)
  2833. {
  2834. int wheelMove = (int)GetMouseWheelMove();
  2835. startIndex -= wheelMove;
  2836. if (startIndex < 0) startIndex = 0;
  2837. else if (startIndex > (count - visibleItems)) startIndex = count - visibleItems;
  2838. endIndex = startIndex + visibleItems;
  2839. if (endIndex > count) endIndex = count;
  2840. }
  2841. }
  2842. else itemFocused = -1;
  2843. // Reset item rectangle y to [0]
  2844. itemBounds.y = bounds.y + GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING) + GuiGetStyle(DEFAULT, BORDER_WIDTH);
  2845. }
  2846. //--------------------------------------------------------------------
  2847. // Draw control
  2848. //--------------------------------------------------------------------
  2849. GuiDrawRectangle(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), GetColor(GuiGetStyle(LISTVIEW, BORDER + state*3)), GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR))); // Draw background
  2850. // Draw visible items
  2851. for (int i = 0; ((i < visibleItems) && (text != NULL)); i++)
  2852. {
  2853. if (state == STATE_DISABLED)
  2854. {
  2855. if ((startIndex + i) == itemSelected) GuiDrawRectangle(itemBounds, GuiGetStyle(LISTVIEW, BORDER_WIDTH), GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_DISABLED)), GetColor(GuiGetStyle(LISTVIEW, BASE_COLOR_DISABLED)));
  2856. GuiDrawText(text[startIndex + i], GetTextBounds(DEFAULT, itemBounds), GuiGetStyle(LISTVIEW, TEXT_ALIGNMENT), GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_DISABLED)));
  2857. }
  2858. else
  2859. {
  2860. if (((startIndex + i) == itemSelected) && (active != NULL))
  2861. {
  2862. // Draw item selected
  2863. GuiDrawRectangle(itemBounds, GuiGetStyle(LISTVIEW, BORDER_WIDTH), GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_PRESSED)), GetColor(GuiGetStyle(LISTVIEW, BASE_COLOR_PRESSED)));
  2864. GuiDrawText(text[startIndex + i], GetTextBounds(DEFAULT, itemBounds), GuiGetStyle(LISTVIEW, TEXT_ALIGNMENT), GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_PRESSED)));
  2865. }
  2866. else if (((startIndex + i) == itemFocused)) // && (focus != NULL)) // NOTE: We want items focused, despite not returned!
  2867. {
  2868. // Draw item focused
  2869. GuiDrawRectangle(itemBounds, GuiGetStyle(LISTVIEW, BORDER_WIDTH), GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_FOCUSED)), GetColor(GuiGetStyle(LISTVIEW, BASE_COLOR_FOCUSED)));
  2870. GuiDrawText(text[startIndex + i], GetTextBounds(DEFAULT, itemBounds), GuiGetStyle(LISTVIEW, TEXT_ALIGNMENT), GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_FOCUSED)));
  2871. }
  2872. else
  2873. {
  2874. // Draw item normal
  2875. GuiDrawText(text[startIndex + i], GetTextBounds(DEFAULT, itemBounds), GuiGetStyle(LISTVIEW, TEXT_ALIGNMENT), GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_NORMAL)));
  2876. }
  2877. }
  2878. // Update item rectangle y position for next item
  2879. itemBounds.y += (GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) + GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING));
  2880. }
  2881. if (useScrollBar)
  2882. {
  2883. Rectangle scrollBarBounds = {
  2884. bounds.x + bounds.width - GuiGetStyle(LISTVIEW, BORDER_WIDTH) - GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH),
  2885. bounds.y + GuiGetStyle(LISTVIEW, BORDER_WIDTH), (float)GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH),
  2886. bounds.height - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH)
  2887. };
  2888. // Calculate percentage of visible items and apply same percentage to scrollbar
  2889. float percentVisible = (float)(endIndex - startIndex)/count;
  2890. float sliderSize = bounds.height*percentVisible;
  2891. int prevSliderSize = GuiGetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE); // Save default slider size
  2892. int prevScrollSpeed = GuiGetStyle(SCROLLBAR, SCROLL_SPEED); // Save default scroll speed
  2893. GuiSetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE, (int)sliderSize); // Change slider size
  2894. GuiSetStyle(SCROLLBAR, SCROLL_SPEED, count - visibleItems); // Change scroll speed
  2895. startIndex = GuiScrollBar(scrollBarBounds, startIndex, 0, count - visibleItems);
  2896. GuiSetStyle(SCROLLBAR, SCROLL_SPEED, prevScrollSpeed); // Reset scroll speed to default
  2897. GuiSetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE, prevSliderSize); // Reset slider size to default
  2898. }
  2899. //--------------------------------------------------------------------
  2900. if (active != NULL) *active = itemSelected;
  2901. if (focus != NULL) *focus = itemFocused;
  2902. if (scrollIndex != NULL) *scrollIndex = startIndex;
  2903. return result;
  2904. }
  2905. // Color Panel control
  2906. int GuiColorPanel(Rectangle bounds, const char *text, Color *color)
  2907. {
  2908. int result = 0;
  2909. GuiState state = guiState;
  2910. Vector2 pickerSelector = { 0 };
  2911. const Color colWhite = { 255, 255, 255, 255 };
  2912. const Color colBlack = { 0, 0, 0, 255 };
  2913. Vector3 vcolor = { (float)color->r/255.0f, (float)color->g/255.0f, (float)color->b/255.0f };
  2914. Vector3 hsv = ConvertRGBtoHSV(vcolor);
  2915. pickerSelector.x = bounds.x + (float)hsv.y*bounds.width; // HSV: Saturation
  2916. pickerSelector.y = bounds.y + (1.0f - (float)hsv.z)*bounds.height; // HSV: Value
  2917. Vector3 maxHue = { hsv.x, 1.0f, 1.0f };
  2918. Vector3 rgbHue = ConvertHSVtoRGB(maxHue);
  2919. Color maxHueCol = { (unsigned char)(255.0f*rgbHue.x),
  2920. (unsigned char)(255.0f*rgbHue.y),
  2921. (unsigned char)(255.0f*rgbHue.z), 255 };
  2922. // Update control
  2923. //--------------------------------------------------------------------
  2924. if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
  2925. {
  2926. Vector2 mousePoint = GetMousePosition();
  2927. if (CheckCollisionPointRec(mousePoint, bounds))
  2928. {
  2929. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  2930. {
  2931. state = STATE_PRESSED;
  2932. pickerSelector = mousePoint;
  2933. // Calculate color from picker
  2934. Vector2 colorPick = { pickerSelector.x - bounds.x, pickerSelector.y - bounds.y };
  2935. colorPick.x /= (float)bounds.width; // Get normalized value on x
  2936. colorPick.y /= (float)bounds.height; // Get normalized value on y
  2937. hsv.y = colorPick.x;
  2938. hsv.z = 1.0f - colorPick.y;
  2939. Vector3 rgb = ConvertHSVtoRGB(hsv);
  2940. // NOTE: Vector3ToColor() only available on raylib 1.8.1
  2941. *color = RAYGUI_CLITERAL(Color){ (unsigned char)(255.0f*rgb.x),
  2942. (unsigned char)(255.0f*rgb.y),
  2943. (unsigned char)(255.0f*rgb.z),
  2944. (unsigned char)(255.0f*(float)color->a/255.0f) };
  2945. }
  2946. else state = STATE_FOCUSED;
  2947. }
  2948. }
  2949. //--------------------------------------------------------------------
  2950. // Draw control
  2951. //--------------------------------------------------------------------
  2952. if (state != STATE_DISABLED)
  2953. {
  2954. DrawRectangleGradientEx(bounds, Fade(colWhite, guiAlpha), Fade(colWhite, guiAlpha), Fade(maxHueCol, guiAlpha), Fade(maxHueCol, guiAlpha));
  2955. DrawRectangleGradientEx(bounds, Fade(colBlack, 0), Fade(colBlack, guiAlpha), Fade(colBlack, guiAlpha), Fade(colBlack, 0));
  2956. // Draw color picker: selector
  2957. Rectangle selector = { pickerSelector.x - GuiGetStyle(COLORPICKER, COLOR_SELECTOR_SIZE)/2, pickerSelector.y - GuiGetStyle(COLORPICKER, COLOR_SELECTOR_SIZE)/2, (float)GuiGetStyle(COLORPICKER, COLOR_SELECTOR_SIZE), (float)GuiGetStyle(COLORPICKER, COLOR_SELECTOR_SIZE) };
  2958. GuiDrawRectangle(selector, 0, BLANK, colWhite);
  2959. }
  2960. else
  2961. {
  2962. DrawRectangleGradientEx(bounds, Fade(Fade(GetColor(GuiGetStyle(COLORPICKER, BASE_COLOR_DISABLED)), 0.1f), guiAlpha), Fade(Fade(colBlack, 0.6f), guiAlpha), Fade(Fade(colBlack, 0.6f), guiAlpha), Fade(Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_DISABLED)), 0.6f), guiAlpha));
  2963. }
  2964. GuiDrawRectangle(bounds, GuiGetStyle(COLORPICKER, BORDER_WIDTH), GetColor(GuiGetStyle(COLORPICKER, BORDER + state*3)), BLANK);
  2965. //--------------------------------------------------------------------
  2966. return result;
  2967. }
  2968. // Color Bar Alpha control
  2969. // NOTE: Returns alpha value normalized [0..1]
  2970. int GuiColorBarAlpha(Rectangle bounds, const char *text, float *alpha)
  2971. {
  2972. #if !defined(RAYGUI_COLORBARALPHA_CHECKED_SIZE)
  2973. #define RAYGUI_COLORBARALPHA_CHECKED_SIZE 10
  2974. #endif
  2975. int result = 0;
  2976. GuiState state = guiState;
  2977. Rectangle selector = { (float)bounds.x + (*alpha)*bounds.width - GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_HEIGHT)/2, (float)bounds.y - GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW), (float)GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_HEIGHT), (float)bounds.height + GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW)*2 };
  2978. // Update control
  2979. //--------------------------------------------------------------------
  2980. if ((state != STATE_DISABLED) && !guiLocked)
  2981. {
  2982. Vector2 mousePoint = GetMousePosition();
  2983. if (guiSliderDragging) // Keep dragging outside of bounds
  2984. {
  2985. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  2986. {
  2987. if (CHECK_BOUNDS_ID(bounds, guiSliderActive))
  2988. {
  2989. state = STATE_PRESSED;
  2990. *alpha = (mousePoint.x - bounds.x)/bounds.width;
  2991. if (*alpha <= 0.0f) *alpha = 0.0f;
  2992. if (*alpha >= 1.0f) *alpha = 1.0f;
  2993. }
  2994. }
  2995. else
  2996. {
  2997. guiSliderDragging = false;
  2998. guiSliderActive = RAYGUI_CLITERAL(Rectangle){ 0, 0, 0, 0 };
  2999. }
  3000. }
  3001. else if (CheckCollisionPointRec(mousePoint, bounds) || CheckCollisionPointRec(mousePoint, selector))
  3002. {
  3003. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  3004. {
  3005. state = STATE_PRESSED;
  3006. guiSliderDragging = true;
  3007. guiSliderActive = bounds; // Store bounds as an identifier when dragging starts
  3008. *alpha = (mousePoint.x - bounds.x)/bounds.width;
  3009. if (*alpha <= 0.0f) *alpha = 0.0f;
  3010. if (*alpha >= 1.0f) *alpha = 1.0f;
  3011. //selector.x = bounds.x + (int)(((alpha - 0)/(100 - 0))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH))) - selector.width/2;
  3012. }
  3013. else state = STATE_FOCUSED;
  3014. }
  3015. }
  3016. //--------------------------------------------------------------------
  3017. // Draw control
  3018. //--------------------------------------------------------------------
  3019. // Draw alpha bar: checked background
  3020. if (state != STATE_DISABLED)
  3021. {
  3022. int checksX = (int)bounds.width/RAYGUI_COLORBARALPHA_CHECKED_SIZE;
  3023. int checksY = (int)bounds.height/RAYGUI_COLORBARALPHA_CHECKED_SIZE;
  3024. for (int x = 0; x < checksX; x++)
  3025. {
  3026. for (int y = 0; y < checksY; y++)
  3027. {
  3028. Rectangle check = { bounds.x + x*RAYGUI_COLORBARALPHA_CHECKED_SIZE, bounds.y + y*RAYGUI_COLORBARALPHA_CHECKED_SIZE, RAYGUI_COLORBARALPHA_CHECKED_SIZE, RAYGUI_COLORBARALPHA_CHECKED_SIZE };
  3029. GuiDrawRectangle(check, 0, BLANK, ((x + y)%2)? Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_DISABLED)), 0.4f) : Fade(GetColor(GuiGetStyle(COLORPICKER, BASE_COLOR_DISABLED)), 0.4f));
  3030. }
  3031. }
  3032. DrawRectangleGradientEx(bounds, RAYGUI_CLITERAL(Color){ 255, 255, 255, 0 }, RAYGUI_CLITERAL(Color){ 255, 255, 255, 0 }, Fade(RAYGUI_CLITERAL(Color){ 0, 0, 0, 255 }, guiAlpha), Fade(RAYGUI_CLITERAL(Color){ 0, 0, 0, 255 }, guiAlpha));
  3033. }
  3034. else DrawRectangleGradientEx(bounds, Fade(GetColor(GuiGetStyle(COLORPICKER, BASE_COLOR_DISABLED)), 0.1f), Fade(GetColor(GuiGetStyle(COLORPICKER, BASE_COLOR_DISABLED)), 0.1f), Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_DISABLED)), guiAlpha), Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_DISABLED)), guiAlpha));
  3035. GuiDrawRectangle(bounds, GuiGetStyle(COLORPICKER, BORDER_WIDTH), GetColor(GuiGetStyle(COLORPICKER, BORDER + state*3)), BLANK);
  3036. // Draw alpha bar: selector
  3037. GuiDrawRectangle(selector, 0, BLANK, GetColor(GuiGetStyle(COLORPICKER, BORDER + state*3)));
  3038. //--------------------------------------------------------------------
  3039. return result;
  3040. }
  3041. // Color Bar Hue control
  3042. // Returns hue value normalized [0..1]
  3043. // NOTE: Other similar bars (for reference):
  3044. // Color GuiColorBarSat() [WHITE->color]
  3045. // Color GuiColorBarValue() [BLACK->color], HSV/HSL
  3046. // float GuiColorBarLuminance() [BLACK->WHITE]
  3047. int GuiColorBarHue(Rectangle bounds, const char *text, float *hue)
  3048. {
  3049. int result = 0;
  3050. GuiState state = guiState;
  3051. Rectangle selector = { (float)bounds.x - GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW), (float)bounds.y + (*hue)/360.0f*bounds.height - GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_HEIGHT)/2, (float)bounds.width + GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW)*2, (float)GuiGetStyle(COLORPICKER, HUEBAR_SELECTOR_HEIGHT) };
  3052. // Update control
  3053. //--------------------------------------------------------------------
  3054. if ((state != STATE_DISABLED) && !guiLocked)
  3055. {
  3056. Vector2 mousePoint = GetMousePosition();
  3057. if (guiSliderDragging) // Keep dragging outside of bounds
  3058. {
  3059. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  3060. {
  3061. if (CHECK_BOUNDS_ID(bounds, guiSliderActive))
  3062. {
  3063. state = STATE_PRESSED;
  3064. *hue = (mousePoint.y - bounds.y)*360/bounds.height;
  3065. if (*hue <= 0.0f) *hue = 0.0f;
  3066. if (*hue >= 359.0f) *hue = 359.0f;
  3067. }
  3068. }
  3069. else
  3070. {
  3071. guiSliderDragging = false;
  3072. guiSliderActive = RAYGUI_CLITERAL(Rectangle){ 0, 0, 0, 0 };
  3073. }
  3074. }
  3075. else if (CheckCollisionPointRec(mousePoint, bounds) || CheckCollisionPointRec(mousePoint, selector))
  3076. {
  3077. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  3078. {
  3079. state = STATE_PRESSED;
  3080. guiSliderDragging = true;
  3081. guiSliderActive = bounds; // Store bounds as an identifier when dragging starts
  3082. *hue = (mousePoint.y - bounds.y)*360/bounds.height;
  3083. if (*hue <= 0.0f) *hue = 0.0f;
  3084. if (*hue >= 359.0f) *hue = 359.0f;
  3085. }
  3086. else state = STATE_FOCUSED;
  3087. /*if (IsKeyDown(KEY_UP))
  3088. {
  3089. hue -= 2.0f;
  3090. if (hue <= 0.0f) hue = 0.0f;
  3091. }
  3092. else if (IsKeyDown(KEY_DOWN))
  3093. {
  3094. hue += 2.0f;
  3095. if (hue >= 360.0f) hue = 360.0f;
  3096. }*/
  3097. }
  3098. }
  3099. //--------------------------------------------------------------------
  3100. // Draw control
  3101. //--------------------------------------------------------------------
  3102. if (state != STATE_DISABLED)
  3103. {
  3104. // Draw hue bar:color bars
  3105. // TODO: Use directly DrawRectangleGradientEx(bounds, color1, color2, color2, color1);
  3106. DrawRectangleGradientV((int)bounds.x, (int)(bounds.y), (int)bounds.width, (int)ceilf(bounds.height/6), Fade(RAYGUI_CLITERAL(Color){ 255, 0, 0, 255 }, guiAlpha), Fade(RAYGUI_CLITERAL(Color){ 255, 255, 0, 255 }, guiAlpha));
  3107. DrawRectangleGradientV((int)bounds.x, (int)(bounds.y + bounds.height/6), (int)bounds.width, (int)ceilf(bounds.height/6), Fade(RAYGUI_CLITERAL(Color){ 255, 255, 0, 255 }, guiAlpha), Fade(RAYGUI_CLITERAL(Color){ 0, 255, 0, 255 }, guiAlpha));
  3108. DrawRectangleGradientV((int)bounds.x, (int)(bounds.y + 2*(bounds.height/6)), (int)bounds.width, (int)ceilf(bounds.height/6), Fade(RAYGUI_CLITERAL(Color){ 0, 255, 0, 255 }, guiAlpha), Fade(RAYGUI_CLITERAL(Color){ 0, 255, 255, 255 }, guiAlpha));
  3109. DrawRectangleGradientV((int)bounds.x, (int)(bounds.y + 3*(bounds.height/6)), (int)bounds.width, (int)ceilf(bounds.height/6), Fade(RAYGUI_CLITERAL(Color){ 0, 255, 255, 255 }, guiAlpha), Fade(RAYGUI_CLITERAL(Color){ 0, 0, 255, 255 }, guiAlpha));
  3110. DrawRectangleGradientV((int)bounds.x, (int)(bounds.y + 4*(bounds.height/6)), (int)bounds.width, (int)ceilf(bounds.height/6), Fade(RAYGUI_CLITERAL(Color){ 0, 0, 255, 255 }, guiAlpha), Fade(RAYGUI_CLITERAL(Color){ 255, 0, 255, 255 }, guiAlpha));
  3111. DrawRectangleGradientV((int)bounds.x, (int)(bounds.y + 5*(bounds.height/6)), (int)bounds.width, (int)(bounds.height/6), Fade(RAYGUI_CLITERAL(Color){ 255, 0, 255, 255 }, guiAlpha), Fade(RAYGUI_CLITERAL(Color){ 255, 0, 0, 255 }, guiAlpha));
  3112. }
  3113. else DrawRectangleGradientV((int)bounds.x, (int)bounds.y, (int)bounds.width, (int)bounds.height, Fade(Fade(GetColor(GuiGetStyle(COLORPICKER, BASE_COLOR_DISABLED)), 0.1f), guiAlpha), Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_DISABLED)), guiAlpha));
  3114. GuiDrawRectangle(bounds, GuiGetStyle(COLORPICKER, BORDER_WIDTH), GetColor(GuiGetStyle(COLORPICKER, BORDER + state*3)), BLANK);
  3115. // Draw hue bar: selector
  3116. GuiDrawRectangle(selector, 0, BLANK, GetColor(GuiGetStyle(COLORPICKER, BORDER + state*3)));
  3117. //--------------------------------------------------------------------
  3118. return result;
  3119. }
  3120. // Color Picker control
  3121. // NOTE: It's divided in multiple controls:
  3122. // Color GuiColorPanel(Rectangle bounds, Color color)
  3123. // float GuiColorBarAlpha(Rectangle bounds, float alpha)
  3124. // float GuiColorBarHue(Rectangle bounds, float value)
  3125. // NOTE: bounds define GuiColorPanel() size
  3126. int GuiColorPicker(Rectangle bounds, const char *text, Color *color)
  3127. {
  3128. int result = 0;
  3129. Color temp = { 200, 0, 0, 255 };
  3130. if (color == NULL) color = &temp;
  3131. GuiColorPanel(bounds, NULL, color);
  3132. Rectangle boundsHue = { (float)bounds.x + bounds.width + GuiGetStyle(COLORPICKER, HUEBAR_PADDING), (float)bounds.y, (float)GuiGetStyle(COLORPICKER, HUEBAR_WIDTH), (float)bounds.height };
  3133. //Rectangle boundsAlpha = { bounds.x, bounds.y + bounds.height + GuiGetStyle(COLORPICKER, BARS_PADDING), bounds.width, GuiGetStyle(COLORPICKER, BARS_THICK) };
  3134. Vector3 hsv = ConvertRGBtoHSV(RAYGUI_CLITERAL(Vector3){ (*color).r/255.0f, (*color).g/255.0f, (*color).b/255.0f });
  3135. GuiColorBarHue(boundsHue, NULL, &hsv.x);
  3136. //color.a = (unsigned char)(GuiColorBarAlpha(boundsAlpha, (float)color.a/255.0f)*255.0f);
  3137. Vector3 rgb = ConvertHSVtoRGB(hsv);
  3138. *color = RAYGUI_CLITERAL(Color){ (unsigned char)roundf(rgb.x*255.0f), (unsigned char)roundf(rgb.y*255.0f), (unsigned char)roundf(rgb.z*255.0f), (*color).a };
  3139. return result;
  3140. }
  3141. // Color Picker control that avoids conversion to RGB and back to HSV on each call, thus avoiding jittering.
  3142. // The user can call ConvertHSVtoRGB() to convert *colorHsv value to RGB.
  3143. // NOTE: It's divided in multiple controls:
  3144. // int GuiColorPanelHSV(Rectangle bounds, const char *text, Vector3 *colorHsv)
  3145. // int GuiColorBarAlpha(Rectangle bounds, const char *text, float *alpha)
  3146. // float GuiColorBarHue(Rectangle bounds, float value)
  3147. // NOTE: bounds define GuiColorPanelHSV() size
  3148. int GuiColorPickerHSV(Rectangle bounds, const char *text, Vector3 *colorHsv)
  3149. {
  3150. int result = 0;
  3151. Vector3 tempHsv = { 0 };
  3152. if (colorHsv == NULL)
  3153. {
  3154. const Vector3 tempColor = { 200.0f/255.0f, 0.0f, 0.0f };
  3155. tempHsv = ConvertRGBtoHSV(tempColor);
  3156. colorHsv = &tempHsv;
  3157. }
  3158. GuiColorPanelHSV(bounds, NULL, colorHsv);
  3159. const Rectangle boundsHue = { (float)bounds.x + bounds.width + GuiGetStyle(COLORPICKER, HUEBAR_PADDING), (float)bounds.y, (float)GuiGetStyle(COLORPICKER, HUEBAR_WIDTH), (float)bounds.height };
  3160. GuiColorBarHue(boundsHue, NULL, &colorHsv->x);
  3161. return result;
  3162. }
  3163. // Color Panel control, returns HSV color value in *colorHsv.
  3164. // Used by GuiColorPickerHSV()
  3165. int GuiColorPanelHSV(Rectangle bounds, const char *text, Vector3 *colorHsv)
  3166. {
  3167. int result = 0;
  3168. GuiState state = guiState;
  3169. Vector2 pickerSelector = { 0 };
  3170. const Color colWhite = { 255, 255, 255, 255 };
  3171. const Color colBlack = { 0, 0, 0, 255 };
  3172. pickerSelector.x = bounds.x + (float)colorHsv->y*bounds.width; // HSV: Saturation
  3173. pickerSelector.y = bounds.y + (1.0f - (float)colorHsv->z)*bounds.height; // HSV: Value
  3174. Vector3 maxHue = { colorHsv->x, 1.0f, 1.0f };
  3175. Vector3 rgbHue = ConvertHSVtoRGB(maxHue);
  3176. Color maxHueCol = { (unsigned char)(255.0f*rgbHue.x),
  3177. (unsigned char)(255.0f*rgbHue.y),
  3178. (unsigned char)(255.0f*rgbHue.z), 255 };
  3179. // Update control
  3180. //--------------------------------------------------------------------
  3181. if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
  3182. {
  3183. Vector2 mousePoint = GetMousePosition();
  3184. if (CheckCollisionPointRec(mousePoint, bounds))
  3185. {
  3186. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  3187. {
  3188. state = STATE_PRESSED;
  3189. pickerSelector = mousePoint;
  3190. // Calculate color from picker
  3191. Vector2 colorPick = { pickerSelector.x - bounds.x, pickerSelector.y - bounds.y };
  3192. colorPick.x /= (float)bounds.width; // Get normalized value on x
  3193. colorPick.y /= (float)bounds.height; // Get normalized value on y
  3194. colorHsv->y = colorPick.x;
  3195. colorHsv->z = 1.0f - colorPick.y;
  3196. }
  3197. else state = STATE_FOCUSED;
  3198. }
  3199. }
  3200. //--------------------------------------------------------------------
  3201. // Draw control
  3202. //--------------------------------------------------------------------
  3203. if (state != STATE_DISABLED)
  3204. {
  3205. DrawRectangleGradientEx(bounds, Fade(colWhite, guiAlpha), Fade(colWhite, guiAlpha), Fade(maxHueCol, guiAlpha), Fade(maxHueCol, guiAlpha));
  3206. DrawRectangleGradientEx(bounds, Fade(colBlack, 0), Fade(colBlack, guiAlpha), Fade(colBlack, guiAlpha), Fade(colBlack, 0));
  3207. // Draw color picker: selector
  3208. Rectangle selector = { pickerSelector.x - GuiGetStyle(COLORPICKER, COLOR_SELECTOR_SIZE)/2, pickerSelector.y - GuiGetStyle(COLORPICKER, COLOR_SELECTOR_SIZE)/2, (float)GuiGetStyle(COLORPICKER, COLOR_SELECTOR_SIZE), (float)GuiGetStyle(COLORPICKER, COLOR_SELECTOR_SIZE) };
  3209. GuiDrawRectangle(selector, 0, BLANK, colWhite);
  3210. }
  3211. else
  3212. {
  3213. DrawRectangleGradientEx(bounds, Fade(Fade(GetColor(GuiGetStyle(COLORPICKER, BASE_COLOR_DISABLED)), 0.1f), guiAlpha), Fade(Fade(colBlack, 0.6f), guiAlpha), Fade(Fade(colBlack, 0.6f), guiAlpha), Fade(Fade(GetColor(GuiGetStyle(COLORPICKER, BORDER_COLOR_DISABLED)), 0.6f), guiAlpha));
  3214. }
  3215. GuiDrawRectangle(bounds, GuiGetStyle(COLORPICKER, BORDER_WIDTH), GetColor(GuiGetStyle(COLORPICKER, BORDER + state*3)), BLANK);
  3216. //--------------------------------------------------------------------
  3217. return result;
  3218. }
  3219. // Message Box control
  3220. int GuiMessageBox(Rectangle bounds, const char *title, const char *message, const char *buttons)
  3221. {
  3222. #if !defined(RAYGUI_MESSAGEBOX_BUTTON_HEIGHT)
  3223. #define RAYGUI_MESSAGEBOX_BUTTON_HEIGHT 24
  3224. #endif
  3225. #if !defined(RAYGUI_MESSAGEBOX_BUTTON_PADDING)
  3226. #define RAYGUI_MESSAGEBOX_BUTTON_PADDING 12
  3227. #endif
  3228. int result = -1; // Returns clicked button from buttons list, 0 refers to closed window button
  3229. int buttonCount = 0;
  3230. const char **buttonsText = GuiTextSplit(buttons, ';', &buttonCount, NULL);
  3231. Rectangle buttonBounds = { 0 };
  3232. buttonBounds.x = bounds.x + RAYGUI_MESSAGEBOX_BUTTON_PADDING;
  3233. buttonBounds.y = bounds.y + bounds.height - RAYGUI_MESSAGEBOX_BUTTON_HEIGHT - RAYGUI_MESSAGEBOX_BUTTON_PADDING;
  3234. buttonBounds.width = (bounds.width - RAYGUI_MESSAGEBOX_BUTTON_PADDING*(buttonCount + 1))/buttonCount;
  3235. buttonBounds.height = RAYGUI_MESSAGEBOX_BUTTON_HEIGHT;
  3236. int textWidth = GetTextWidth(message) + 2;
  3237. Rectangle textBounds = { 0 };
  3238. textBounds.x = bounds.x + bounds.width/2 - textWidth/2;
  3239. textBounds.y = bounds.y + RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT + RAYGUI_MESSAGEBOX_BUTTON_PADDING;
  3240. textBounds.width = (float)textWidth;
  3241. textBounds.height = bounds.height - RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT - 3*RAYGUI_MESSAGEBOX_BUTTON_PADDING - RAYGUI_MESSAGEBOX_BUTTON_HEIGHT;
  3242. // Draw control
  3243. //--------------------------------------------------------------------
  3244. if (GuiWindowBox(bounds, title)) result = 0;
  3245. int prevTextAlignment = GuiGetStyle(LABEL, TEXT_ALIGNMENT);
  3246. GuiSetStyle(LABEL, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
  3247. GuiLabel(textBounds, message);
  3248. GuiSetStyle(LABEL, TEXT_ALIGNMENT, prevTextAlignment);
  3249. prevTextAlignment = GuiGetStyle(BUTTON, TEXT_ALIGNMENT);
  3250. GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
  3251. for (int i = 0; i < buttonCount; i++)
  3252. {
  3253. if (GuiButton(buttonBounds, buttonsText[i])) result = i + 1;
  3254. buttonBounds.x += (buttonBounds.width + RAYGUI_MESSAGEBOX_BUTTON_PADDING);
  3255. }
  3256. GuiSetStyle(BUTTON, TEXT_ALIGNMENT, prevTextAlignment);
  3257. //--------------------------------------------------------------------
  3258. return result;
  3259. }
  3260. // Text Input Box control, ask for text
  3261. int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, const char *buttons, char *text, int textMaxSize, bool *secretViewActive)
  3262. {
  3263. #if !defined(RAYGUI_TEXTINPUTBOX_BUTTON_HEIGHT)
  3264. #define RAYGUI_TEXTINPUTBOX_BUTTON_HEIGHT 24
  3265. #endif
  3266. #if !defined(RAYGUI_TEXTINPUTBOX_BUTTON_PADDING)
  3267. #define RAYGUI_TEXTINPUTBOX_BUTTON_PADDING 12
  3268. #endif
  3269. #if !defined(RAYGUI_TEXTINPUTBOX_HEIGHT)
  3270. #define RAYGUI_TEXTINPUTBOX_HEIGHT 26
  3271. #endif
  3272. // Used to enable text edit mode
  3273. // WARNING: No more than one GuiTextInputBox() should be open at the same time
  3274. static bool textEditMode = false;
  3275. int result = -1;
  3276. int buttonCount = 0;
  3277. const char **buttonsText = GuiTextSplit(buttons, ';', &buttonCount, NULL);
  3278. Rectangle buttonBounds = { 0 };
  3279. buttonBounds.x = bounds.x + RAYGUI_TEXTINPUTBOX_BUTTON_PADDING;
  3280. buttonBounds.y = bounds.y + bounds.height - RAYGUI_TEXTINPUTBOX_BUTTON_HEIGHT - RAYGUI_TEXTINPUTBOX_BUTTON_PADDING;
  3281. buttonBounds.width = (bounds.width - RAYGUI_TEXTINPUTBOX_BUTTON_PADDING*(buttonCount + 1))/buttonCount;
  3282. buttonBounds.height = RAYGUI_TEXTINPUTBOX_BUTTON_HEIGHT;
  3283. int messageInputHeight = (int)bounds.height - RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT - GuiGetStyle(STATUSBAR, BORDER_WIDTH) - RAYGUI_TEXTINPUTBOX_BUTTON_HEIGHT - 2*RAYGUI_TEXTINPUTBOX_BUTTON_PADDING;
  3284. Rectangle textBounds = { 0 };
  3285. if (message != NULL)
  3286. {
  3287. int textSize = GetTextWidth(message) + 2;
  3288. textBounds.x = bounds.x + bounds.width/2 - textSize/2;
  3289. textBounds.y = bounds.y + RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT + messageInputHeight/4 - (float)GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
  3290. textBounds.width = (float)textSize;
  3291. textBounds.height = (float)GuiGetStyle(DEFAULT, TEXT_SIZE);
  3292. }
  3293. Rectangle textBoxBounds = { 0 };
  3294. textBoxBounds.x = bounds.x + RAYGUI_TEXTINPUTBOX_BUTTON_PADDING;
  3295. textBoxBounds.y = bounds.y + RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT - RAYGUI_TEXTINPUTBOX_HEIGHT/2;
  3296. if (message == NULL) textBoxBounds.y = bounds.y + 24 + RAYGUI_TEXTINPUTBOX_BUTTON_PADDING;
  3297. else textBoxBounds.y += (messageInputHeight/2 + messageInputHeight/4);
  3298. textBoxBounds.width = bounds.width - RAYGUI_TEXTINPUTBOX_BUTTON_PADDING*2;
  3299. textBoxBounds.height = RAYGUI_TEXTINPUTBOX_HEIGHT;
  3300. // Draw control
  3301. //--------------------------------------------------------------------
  3302. if (GuiWindowBox(bounds, title)) result = 0;
  3303. // Draw message if available
  3304. if (message != NULL)
  3305. {
  3306. int prevTextAlignment = GuiGetStyle(LABEL, TEXT_ALIGNMENT);
  3307. GuiSetStyle(LABEL, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
  3308. GuiLabel(textBounds, message);
  3309. GuiSetStyle(LABEL, TEXT_ALIGNMENT, prevTextAlignment);
  3310. }
  3311. if (secretViewActive != NULL)
  3312. {
  3313. static char stars[] = "****************";
  3314. if (GuiTextBox(RAYGUI_CLITERAL(Rectangle){ textBoxBounds.x, textBoxBounds.y, textBoxBounds.width - 4 - RAYGUI_TEXTINPUTBOX_HEIGHT, textBoxBounds.height },
  3315. ((*secretViewActive == 1) || textEditMode)? text : stars, textMaxSize, textEditMode)) textEditMode = !textEditMode;
  3316. GuiToggle(RAYGUI_CLITERAL(Rectangle){ textBoxBounds.x + textBoxBounds.width - RAYGUI_TEXTINPUTBOX_HEIGHT, textBoxBounds.y, RAYGUI_TEXTINPUTBOX_HEIGHT, RAYGUI_TEXTINPUTBOX_HEIGHT }, (*secretViewActive == 1)? "#44#" : "#45#", secretViewActive);
  3317. }
  3318. else
  3319. {
  3320. if (GuiTextBox(textBoxBounds, text, textMaxSize, textEditMode)) textEditMode = !textEditMode;
  3321. }
  3322. int prevBtnTextAlignment = GuiGetStyle(BUTTON, TEXT_ALIGNMENT);
  3323. GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
  3324. for (int i = 0; i < buttonCount; i++)
  3325. {
  3326. if (GuiButton(buttonBounds, buttonsText[i])) result = i + 1;
  3327. buttonBounds.x += (buttonBounds.width + RAYGUI_MESSAGEBOX_BUTTON_PADDING);
  3328. }
  3329. if (result >= 0) textEditMode = false;
  3330. GuiSetStyle(BUTTON, TEXT_ALIGNMENT, prevBtnTextAlignment);
  3331. //--------------------------------------------------------------------
  3332. return result; // Result is the pressed button index
  3333. }
  3334. // Grid control
  3335. // NOTE: Returns grid mouse-hover selected cell
  3336. // About drawing lines at subpixel spacing, simple put, not easy solution:
  3337. // https://stackoverflow.com/questions/4435450/2d-opengl-drawing-lines-that-dont-exactly-fit-pixel-raster
  3338. int GuiGrid(Rectangle bounds, const char *text, float spacing, int subdivs, Vector2 *mouseCell)
  3339. {
  3340. // Grid lines alpha amount
  3341. #if !defined(RAYGUI_GRID_ALPHA)
  3342. #define RAYGUI_GRID_ALPHA 0.15f
  3343. #endif
  3344. int result = 0;
  3345. GuiState state = guiState;
  3346. Vector2 mousePoint = GetMousePosition();
  3347. Vector2 currentMouseCell = { -1, -1 };
  3348. float spaceWidth = spacing/(float)subdivs;
  3349. int linesV = (int)(bounds.width/spaceWidth) + 1;
  3350. int linesH = (int)(bounds.height/spaceWidth) + 1;
  3351. int color = GuiGetStyle(DEFAULT, LINE_COLOR);
  3352. // Update control
  3353. //--------------------------------------------------------------------
  3354. if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
  3355. {
  3356. if (CheckCollisionPointRec(mousePoint, bounds))
  3357. {
  3358. // NOTE: Cell values must be the upper left of the cell the mouse is in
  3359. currentMouseCell.x = floorf((mousePoint.x - bounds.x)/spacing);
  3360. currentMouseCell.y = floorf((mousePoint.y - bounds.y)/spacing);
  3361. }
  3362. }
  3363. //--------------------------------------------------------------------
  3364. // Draw control
  3365. //--------------------------------------------------------------------
  3366. if (state == STATE_DISABLED) color = GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED);
  3367. if (subdivs > 0)
  3368. {
  3369. // Draw vertical grid lines
  3370. for (int i = 0; i < linesV; i++)
  3371. {
  3372. Rectangle lineV = { bounds.x + spacing*i/subdivs, bounds.y, 1, bounds.height };
  3373. GuiDrawRectangle(lineV, 0, BLANK, ((i%subdivs) == 0)? GuiFade(GetColor(color), RAYGUI_GRID_ALPHA*4) : GuiFade(GetColor(color), RAYGUI_GRID_ALPHA));
  3374. }
  3375. // Draw horizontal grid lines
  3376. for (int i = 0; i < linesH; i++)
  3377. {
  3378. Rectangle lineH = { bounds.x, bounds.y + spacing*i/subdivs, bounds.width, 1 };
  3379. GuiDrawRectangle(lineH, 0, BLANK, ((i%subdivs) == 0)? GuiFade(GetColor(color), RAYGUI_GRID_ALPHA*4) : GuiFade(GetColor(color), RAYGUI_GRID_ALPHA));
  3380. }
  3381. }
  3382. if (mouseCell != NULL) *mouseCell = currentMouseCell;
  3383. return result;
  3384. }
  3385. //----------------------------------------------------------------------------------
  3386. // Tooltip management functions
  3387. // NOTE: Tooltips requires some global variables: tooltipPtr
  3388. //----------------------------------------------------------------------------------
  3389. // Enable gui tooltips (global state)
  3390. void GuiEnableTooltip(void) { guiTooltip = true; }
  3391. // Disable gui tooltips (global state)
  3392. void GuiDisableTooltip(void) { guiTooltip = false; }
  3393. // Set tooltip string
  3394. void GuiSetTooltip(const char *tooltip) { guiTooltipPtr = tooltip; }
  3395. //----------------------------------------------------------------------------------
  3396. // Styles loading functions
  3397. //----------------------------------------------------------------------------------
  3398. // Load raygui style file (.rgs)
  3399. // NOTE: By default a binary file is expected, that file could contain a custom font,
  3400. // in that case, custom font image atlas is GRAY+ALPHA and pixel data can be compressed (DEFLATE)
  3401. void GuiLoadStyle(const char *fileName)
  3402. {
  3403. #define MAX_LINE_BUFFER_SIZE 256
  3404. bool tryBinary = false;
  3405. // Try reading the files as text file first
  3406. FILE *rgsFile = fopen(fileName, "rt");
  3407. if (rgsFile != NULL)
  3408. {
  3409. char buffer[MAX_LINE_BUFFER_SIZE] = { 0 };
  3410. fgets(buffer, MAX_LINE_BUFFER_SIZE, rgsFile);
  3411. if (buffer[0] == '#')
  3412. {
  3413. int controlId = 0;
  3414. int propertyId = 0;
  3415. unsigned int propertyValue = 0;
  3416. while (!feof(rgsFile))
  3417. {
  3418. switch (buffer[0])
  3419. {
  3420. case 'p':
  3421. {
  3422. // Style property: p <control_id> <property_id> <property_value> <property_name>
  3423. sscanf(buffer, "p %d %d 0x%x", &controlId, &propertyId, &propertyValue);
  3424. GuiSetStyle(controlId, propertyId, (int)propertyValue);
  3425. } break;
  3426. case 'f':
  3427. {
  3428. // Style font: f <gen_font_size> <charmap_file> <font_file>
  3429. int fontSize = 0;
  3430. char charmapFileName[256] = { 0 };
  3431. char fontFileName[256] = { 0 };
  3432. sscanf(buffer, "f %d %s %[^\r\n]s", &fontSize, charmapFileName, fontFileName);
  3433. Font font = { 0 };
  3434. int *codepoints = NULL;
  3435. int codepointCount = 0;
  3436. if (charmapFileName[0] != '0')
  3437. {
  3438. // Load text data from file
  3439. // NOTE: Expected an UTF-8 array of codepoints, no separation
  3440. char *textData = LoadFileText(TextFormat("%s/%s", GetDirectoryPath(fileName), charmapFileName));
  3441. codepoints = LoadCodepoints(textData, &codepointCount);
  3442. UnloadFileText(textData);
  3443. }
  3444. if (fontFileName[0] != '\0')
  3445. {
  3446. // In case a font is already loaded and it is not default internal font, unload it
  3447. if (font.texture.id != GetFontDefault().texture.id) UnloadTexture(font.texture);
  3448. if (codepointCount > 0) font = LoadFontEx(TextFormat("%s/%s", GetDirectoryPath(fileName), fontFileName), fontSize, codepoints, codepointCount);
  3449. else font = LoadFontEx(TextFormat("%s/%s", GetDirectoryPath(fileName), fontFileName), fontSize, NULL, 0); // Default to 95 standard codepoints
  3450. }
  3451. // If font texture not properly loaded, revert to default font and size/spacing
  3452. if (font.texture.id == 0)
  3453. {
  3454. font = GetFontDefault();
  3455. GuiSetStyle(DEFAULT, TEXT_SIZE, 10);
  3456. GuiSetStyle(DEFAULT, TEXT_SPACING, 1);
  3457. }
  3458. UnloadCodepoints(codepoints);
  3459. if ((font.texture.id > 0) && (font.glyphCount > 0)) GuiSetFont(font);
  3460. } break;
  3461. default: break;
  3462. }
  3463. fgets(buffer, MAX_LINE_BUFFER_SIZE, rgsFile);
  3464. }
  3465. }
  3466. else tryBinary = true;
  3467. fclose(rgsFile);
  3468. }
  3469. if (tryBinary)
  3470. {
  3471. rgsFile = fopen(fileName, "rb");
  3472. if (rgsFile != NULL)
  3473. {
  3474. fseek(rgsFile, 0, SEEK_END);
  3475. int fileDataSize = ftell(rgsFile);
  3476. fseek(rgsFile, 0, SEEK_SET);
  3477. if (fileDataSize > 0)
  3478. {
  3479. unsigned char *fileData = (unsigned char *)RAYGUI_MALLOC(fileDataSize*sizeof(unsigned char));
  3480. fread(fileData, sizeof(unsigned char), fileDataSize, rgsFile);
  3481. GuiLoadStyleFromMemory(fileData, fileDataSize);
  3482. RAYGUI_FREE(fileData);
  3483. }
  3484. fclose(rgsFile);
  3485. }
  3486. }
  3487. }
  3488. // Load style default over global style
  3489. void GuiLoadStyleDefault(void)
  3490. {
  3491. // We set this variable first to avoid cyclic function calls
  3492. // when calling GuiSetStyle() and GuiGetStyle()
  3493. guiStyleLoaded = true;
  3494. // Initialize default LIGHT style property values
  3495. // WARNING: Default value are applied to all controls on set but
  3496. // they can be overwritten later on for every custom control
  3497. GuiSetStyle(DEFAULT, BORDER_COLOR_NORMAL, 0x838383ff);
  3498. GuiSetStyle(DEFAULT, BASE_COLOR_NORMAL, 0xc9c9c9ff);
  3499. GuiSetStyle(DEFAULT, TEXT_COLOR_NORMAL, 0x686868ff);
  3500. GuiSetStyle(DEFAULT, BORDER_COLOR_FOCUSED, 0x5bb2d9ff);
  3501. GuiSetStyle(DEFAULT, BASE_COLOR_FOCUSED, 0xc9effeff);
  3502. GuiSetStyle(DEFAULT, TEXT_COLOR_FOCUSED, 0x6c9bbcff);
  3503. GuiSetStyle(DEFAULT, BORDER_COLOR_PRESSED, 0x0492c7ff);
  3504. GuiSetStyle(DEFAULT, BASE_COLOR_PRESSED, 0x97e8ffff);
  3505. GuiSetStyle(DEFAULT, TEXT_COLOR_PRESSED, 0x368bafff);
  3506. GuiSetStyle(DEFAULT, BORDER_COLOR_DISABLED, 0xb5c1c2ff);
  3507. GuiSetStyle(DEFAULT, BASE_COLOR_DISABLED, 0xe6e9e9ff);
  3508. GuiSetStyle(DEFAULT, TEXT_COLOR_DISABLED, 0xaeb7b8ff);
  3509. GuiSetStyle(DEFAULT, BORDER_WIDTH, 1);
  3510. GuiSetStyle(DEFAULT, TEXT_PADDING, 0);
  3511. GuiSetStyle(DEFAULT, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
  3512. // Initialize default extended property values
  3513. // NOTE: By default, extended property values are initialized to 0
  3514. GuiSetStyle(DEFAULT, TEXT_SIZE, 10); // DEFAULT, shared by all controls
  3515. GuiSetStyle(DEFAULT, TEXT_SPACING, 1); // DEFAULT, shared by all controls
  3516. GuiSetStyle(DEFAULT, LINE_COLOR, 0x90abb5ff); // DEFAULT specific property
  3517. GuiSetStyle(DEFAULT, BACKGROUND_COLOR, 0xf5f5f5ff); // DEFAULT specific property
  3518. GuiSetStyle(DEFAULT, TEXT_LINE_SPACING, 15); // DEFAULT, 15 pixels between lines
  3519. GuiSetStyle(DEFAULT, TEXT_ALIGNMENT_VERTICAL, TEXT_ALIGN_MIDDLE); // DEFAULT, text aligned vertically to middle of text-bounds
  3520. // Initialize control-specific property values
  3521. // NOTE: Those properties are in default list but require specific values by control type
  3522. GuiSetStyle(LABEL, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
  3523. GuiSetStyle(BUTTON, BORDER_WIDTH, 2);
  3524. GuiSetStyle(SLIDER, TEXT_PADDING, 4);
  3525. GuiSetStyle(PROGRESSBAR, TEXT_PADDING, 4);
  3526. GuiSetStyle(CHECKBOX, TEXT_PADDING, 4);
  3527. GuiSetStyle(CHECKBOX, TEXT_ALIGNMENT, TEXT_ALIGN_RIGHT);
  3528. GuiSetStyle(DROPDOWNBOX, TEXT_PADDING, 0);
  3529. GuiSetStyle(DROPDOWNBOX, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
  3530. GuiSetStyle(TEXTBOX, TEXT_PADDING, 4);
  3531. GuiSetStyle(TEXTBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
  3532. GuiSetStyle(VALUEBOX, TEXT_PADDING, 0);
  3533. GuiSetStyle(VALUEBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
  3534. GuiSetStyle(SPINNER, TEXT_PADDING, 0);
  3535. GuiSetStyle(SPINNER, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
  3536. GuiSetStyle(STATUSBAR, TEXT_PADDING, 8);
  3537. GuiSetStyle(STATUSBAR, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
  3538. // Initialize extended property values
  3539. // NOTE: By default, extended property values are initialized to 0
  3540. GuiSetStyle(TOGGLE, GROUP_PADDING, 2);
  3541. GuiSetStyle(SLIDER, SLIDER_WIDTH, 16);
  3542. GuiSetStyle(SLIDER, SLIDER_PADDING, 1);
  3543. GuiSetStyle(PROGRESSBAR, PROGRESS_PADDING, 1);
  3544. GuiSetStyle(CHECKBOX, CHECK_PADDING, 1);
  3545. GuiSetStyle(COMBOBOX, COMBO_BUTTON_WIDTH, 32);
  3546. GuiSetStyle(COMBOBOX, COMBO_BUTTON_SPACING, 2);
  3547. GuiSetStyle(DROPDOWNBOX, ARROW_PADDING, 16);
  3548. GuiSetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_SPACING, 2);
  3549. GuiSetStyle(SPINNER, SPIN_BUTTON_WIDTH, 24);
  3550. GuiSetStyle(SPINNER, SPIN_BUTTON_SPACING, 2);
  3551. GuiSetStyle(SCROLLBAR, BORDER_WIDTH, 0);
  3552. GuiSetStyle(SCROLLBAR, ARROWS_VISIBLE, 0);
  3553. GuiSetStyle(SCROLLBAR, ARROWS_SIZE, 6);
  3554. GuiSetStyle(SCROLLBAR, SCROLL_SLIDER_PADDING, 0);
  3555. GuiSetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE, 16);
  3556. GuiSetStyle(SCROLLBAR, SCROLL_PADDING, 0);
  3557. GuiSetStyle(SCROLLBAR, SCROLL_SPEED, 12);
  3558. GuiSetStyle(LISTVIEW, LIST_ITEMS_HEIGHT, 28);
  3559. GuiSetStyle(LISTVIEW, LIST_ITEMS_SPACING, 2);
  3560. GuiSetStyle(LISTVIEW, SCROLLBAR_WIDTH, 12);
  3561. GuiSetStyle(LISTVIEW, SCROLLBAR_SIDE, SCROLLBAR_RIGHT_SIDE);
  3562. GuiSetStyle(COLORPICKER, COLOR_SELECTOR_SIZE, 8);
  3563. GuiSetStyle(COLORPICKER, HUEBAR_WIDTH, 16);
  3564. GuiSetStyle(COLORPICKER, HUEBAR_PADDING, 8);
  3565. GuiSetStyle(COLORPICKER, HUEBAR_SELECTOR_HEIGHT, 8);
  3566. GuiSetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW, 2);
  3567. if (guiFont.texture.id != GetFontDefault().texture.id)
  3568. {
  3569. // Unload previous font texture
  3570. UnloadTexture(guiFont.texture);
  3571. RL_FREE(guiFont.recs);
  3572. RL_FREE(guiFont.glyphs);
  3573. guiFont.recs = NULL;
  3574. guiFont.glyphs = NULL;
  3575. // Setup default raylib font
  3576. guiFont = GetFontDefault();
  3577. // NOTE: Default raylib font character 95 is a white square
  3578. Rectangle whiteChar = guiFont.recs[95];
  3579. // NOTE: We set up a 1px padding on char rectangle to avoid pixel bleeding on MSAA filtering
  3580. SetShapesTexture(guiFont.texture, RAYGUI_CLITERAL(Rectangle){ whiteChar.x + 1, whiteChar.y + 1, whiteChar.width - 2, whiteChar.height - 2 });
  3581. }
  3582. }
  3583. // Get text with icon id prepended
  3584. // NOTE: Useful to add icons by name id (enum) instead of
  3585. // a number that can change between ricon versions
  3586. const char *GuiIconText(int iconId, const char *text)
  3587. {
  3588. #if defined(RAYGUI_NO_ICONS)
  3589. return NULL;
  3590. #else
  3591. static char buffer[1024] = { 0 };
  3592. static char iconBuffer[16] = { 0 };
  3593. if (text != NULL)
  3594. {
  3595. memset(buffer, 0, 1024);
  3596. sprintf(buffer, "#%03i#", iconId);
  3597. for (int i = 5; i < 1024; i++)
  3598. {
  3599. buffer[i] = text[i - 5];
  3600. if (text[i - 5] == '\0') break;
  3601. }
  3602. return buffer;
  3603. }
  3604. else
  3605. {
  3606. sprintf(iconBuffer, "#%03i#", iconId);
  3607. return iconBuffer;
  3608. }
  3609. #endif
  3610. }
  3611. #if !defined(RAYGUI_NO_ICONS)
  3612. // Get full icons data pointer
  3613. unsigned int *GuiGetIcons(void) { return guiIconsPtr; }
  3614. // Load raygui icons file (.rgi)
  3615. // NOTE: In case nameIds are required, they can be requested with loadIconsName,
  3616. // they are returned as a guiIconsName[iconCount][RAYGUI_ICON_MAX_NAME_LENGTH],
  3617. // WARNING: guiIconsName[]][] memory should be manually freed!
  3618. char **GuiLoadIcons(const char *fileName, bool loadIconsName)
  3619. {
  3620. // Style File Structure (.rgi)
  3621. // ------------------------------------------------------
  3622. // Offset | Size | Type | Description
  3623. // ------------------------------------------------------
  3624. // 0 | 4 | char | Signature: "rGI "
  3625. // 4 | 2 | short | Version: 100
  3626. // 6 | 2 | short | reserved
  3627. // 8 | 2 | short | Num icons (N)
  3628. // 10 | 2 | short | Icons size (Options: 16, 32, 64) (S)
  3629. // Icons name id (32 bytes per name id)
  3630. // foreach (icon)
  3631. // {
  3632. // 12+32*i | 32 | char | Icon NameId
  3633. // }
  3634. // Icons data: One bit per pixel, stored as unsigned int array (depends on icon size)
  3635. // S*S pixels/32bit per unsigned int = K unsigned int per icon
  3636. // foreach (icon)
  3637. // {
  3638. // ... | K | unsigned int | Icon Data
  3639. // }
  3640. FILE *rgiFile = fopen(fileName, "rb");
  3641. char **guiIconsName = NULL;
  3642. if (rgiFile != NULL)
  3643. {
  3644. char signature[5] = { 0 };
  3645. short version = 0;
  3646. short reserved = 0;
  3647. short iconCount = 0;
  3648. short iconSize = 0;
  3649. fread(signature, 1, 4, rgiFile);
  3650. fread(&version, sizeof(short), 1, rgiFile);
  3651. fread(&reserved, sizeof(short), 1, rgiFile);
  3652. fread(&iconCount, sizeof(short), 1, rgiFile);
  3653. fread(&iconSize, sizeof(short), 1, rgiFile);
  3654. if ((signature[0] == 'r') &&
  3655. (signature[1] == 'G') &&
  3656. (signature[2] == 'I') &&
  3657. (signature[3] == ' '))
  3658. {
  3659. if (loadIconsName)
  3660. {
  3661. guiIconsName = (char **)RAYGUI_MALLOC(iconCount*sizeof(char **));
  3662. for (int i = 0; i < iconCount; i++)
  3663. {
  3664. guiIconsName[i] = (char *)RAYGUI_MALLOC(RAYGUI_ICON_MAX_NAME_LENGTH);
  3665. fread(guiIconsName[i], 1, RAYGUI_ICON_MAX_NAME_LENGTH, rgiFile);
  3666. }
  3667. }
  3668. else fseek(rgiFile, iconCount*RAYGUI_ICON_MAX_NAME_LENGTH, SEEK_CUR);
  3669. // Read icons data directly over internal icons array
  3670. fread(guiIconsPtr, sizeof(unsigned int), iconCount*(iconSize*iconSize/32), rgiFile);
  3671. }
  3672. fclose(rgiFile);
  3673. }
  3674. return guiIconsName;
  3675. }
  3676. // Draw selected icon using rectangles pixel-by-pixel
  3677. void GuiDrawIcon(int iconId, int posX, int posY, int pixelSize, Color color)
  3678. {
  3679. #define BIT_CHECK(a,b) ((a) & (1u<<(b)))
  3680. for (int i = 0, y = 0; i < RAYGUI_ICON_SIZE*RAYGUI_ICON_SIZE/32; i++)
  3681. {
  3682. for (int k = 0; k < 32; k++)
  3683. {
  3684. if (BIT_CHECK(guiIconsPtr[iconId*RAYGUI_ICON_DATA_ELEMENTS + i], k))
  3685. {
  3686. #if !defined(RAYGUI_STANDALONE)
  3687. GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ (float)posX + (k%RAYGUI_ICON_SIZE)*pixelSize, (float)posY + y*pixelSize, (float)pixelSize, (float)pixelSize }, 0, BLANK, color);
  3688. #endif
  3689. }
  3690. if ((k == 15) || (k == 31)) y++;
  3691. }
  3692. }
  3693. }
  3694. // Set icon drawing size
  3695. void GuiSetIconScale(int scale)
  3696. {
  3697. if (scale >= 1) guiIconScale = scale;
  3698. }
  3699. #endif // !RAYGUI_NO_ICONS
  3700. //----------------------------------------------------------------------------------
  3701. // Module specific Functions Definition
  3702. //----------------------------------------------------------------------------------
  3703. // Load style from memory
  3704. // WARNING: Binary files only
  3705. static void GuiLoadStyleFromMemory(const unsigned char *fileData, int dataSize)
  3706. {
  3707. unsigned char *fileDataPtr = (unsigned char *)fileData;
  3708. char signature[5] = { 0 };
  3709. short version = 0;
  3710. short reserved = 0;
  3711. int propertyCount = 0;
  3712. memcpy(signature, fileDataPtr, 4);
  3713. memcpy(&version, fileDataPtr + 4, sizeof(short));
  3714. memcpy(&reserved, fileDataPtr + 4 + 2, sizeof(short));
  3715. memcpy(&propertyCount, fileDataPtr + 4 + 2 + 2, sizeof(int));
  3716. fileDataPtr += 12;
  3717. if ((signature[0] == 'r') &&
  3718. (signature[1] == 'G') &&
  3719. (signature[2] == 'S') &&
  3720. (signature[3] == ' '))
  3721. {
  3722. short controlId = 0;
  3723. short propertyId = 0;
  3724. unsigned int propertyValue = 0;
  3725. for (int i = 0; i < propertyCount; i++)
  3726. {
  3727. memcpy(&controlId, fileDataPtr, sizeof(short));
  3728. memcpy(&propertyId, fileDataPtr + 2, sizeof(short));
  3729. memcpy(&propertyValue, fileDataPtr + 2 + 2, sizeof(unsigned int));
  3730. fileDataPtr += 8;
  3731. if (controlId == 0) // DEFAULT control
  3732. {
  3733. // If a DEFAULT property is loaded, it is propagated to all controls
  3734. // NOTE: All DEFAULT properties should be defined first in the file
  3735. GuiSetStyle(0, (int)propertyId, propertyValue);
  3736. if (propertyId < RAYGUI_MAX_PROPS_BASE) for (int i = 1; i < RAYGUI_MAX_CONTROLS; i++) GuiSetStyle(i, (int)propertyId, propertyValue);
  3737. }
  3738. else GuiSetStyle((int)controlId, (int)propertyId, propertyValue);
  3739. }
  3740. // Font loading is highly dependant on raylib API to load font data and image
  3741. #if !defined(RAYGUI_STANDALONE)
  3742. // Load custom font if available
  3743. int fontDataSize = 0;
  3744. memcpy(&fontDataSize, fileDataPtr, sizeof(int));
  3745. fileDataPtr += 4;
  3746. if (fontDataSize > 0)
  3747. {
  3748. Font font = { 0 };
  3749. int fontType = 0; // 0-Normal, 1-SDF
  3750. memcpy(&font.baseSize, fileDataPtr, sizeof(int));
  3751. memcpy(&font.glyphCount, fileDataPtr + 4, sizeof(int));
  3752. memcpy(&fontType, fileDataPtr + 4 + 4, sizeof(int));
  3753. fileDataPtr += 12;
  3754. // Load font white rectangle
  3755. Rectangle fontWhiteRec = { 0 };
  3756. memcpy(&fontWhiteRec, fileDataPtr, sizeof(Rectangle));
  3757. fileDataPtr += 16;
  3758. // Load font image parameters
  3759. int fontImageUncompSize = 0;
  3760. int fontImageCompSize = 0;
  3761. memcpy(&fontImageUncompSize, fileDataPtr, sizeof(int));
  3762. memcpy(&fontImageCompSize, fileDataPtr + 4, sizeof(int));
  3763. fileDataPtr += 8;
  3764. Image imFont = { 0 };
  3765. imFont.mipmaps = 1;
  3766. memcpy(&imFont.width, fileDataPtr, sizeof(int));
  3767. memcpy(&imFont.height, fileDataPtr + 4, sizeof(int));
  3768. memcpy(&imFont.format, fileDataPtr + 4 + 4, sizeof(int));
  3769. fileDataPtr += 12;
  3770. if ((fontImageCompSize > 0) && (fontImageCompSize != fontImageUncompSize))
  3771. {
  3772. // Compressed font atlas image data (DEFLATE), it requires DecompressData()
  3773. int dataUncompSize = 0;
  3774. unsigned char *compData = (unsigned char *)RAYGUI_MALLOC(fontImageCompSize);
  3775. memcpy(compData, fileDataPtr, fontImageCompSize);
  3776. fileDataPtr += fontImageCompSize;
  3777. imFont.data = DecompressData(compData, fontImageCompSize, &dataUncompSize);
  3778. // Security check, dataUncompSize must match the provided fontImageUncompSize
  3779. if (dataUncompSize != fontImageUncompSize) RAYGUI_LOG("WARNING: Uncompressed font atlas image data could be corrupted");
  3780. RAYGUI_FREE(compData);
  3781. }
  3782. else
  3783. {
  3784. // Font atlas image data is not compressed
  3785. imFont.data = (unsigned char *)RAYGUI_MALLOC(fontImageUncompSize);
  3786. memcpy(imFont.data, fileDataPtr, fontImageUncompSize);
  3787. fileDataPtr += fontImageUncompSize;
  3788. }
  3789. if (font.texture.id != GetFontDefault().texture.id) UnloadTexture(font.texture);
  3790. font.texture = LoadTextureFromImage(imFont);
  3791. RAYGUI_FREE(imFont.data);
  3792. // Validate font atlas texture was loaded correctly
  3793. if (font.texture.id != 0)
  3794. {
  3795. // Load font recs data
  3796. int recsDataSize = font.glyphCount*sizeof(Rectangle);
  3797. int recsDataCompressedSize = 0;
  3798. // WARNING: Version 400 adds the compression size parameter
  3799. if (version >= 400)
  3800. {
  3801. // RGS files version 400 support compressed recs data
  3802. memcpy(&recsDataCompressedSize, fileDataPtr, sizeof(int));
  3803. fileDataPtr += sizeof(int);
  3804. }
  3805. if ((recsDataCompressedSize > 0) && (recsDataCompressedSize != recsDataSize))
  3806. {
  3807. // Recs data is compressed, uncompress it
  3808. unsigned char *recsDataCompressed = (unsigned char *)RAYGUI_MALLOC(recsDataCompressedSize);
  3809. memcpy(recsDataCompressed, fileDataPtr, recsDataCompressedSize);
  3810. fileDataPtr += recsDataCompressedSize;
  3811. int recsDataUncompSize = 0;
  3812. font.recs = (Rectangle *)DecompressData(recsDataCompressed, recsDataCompressedSize, &recsDataUncompSize);
  3813. // Security check, data uncompressed size must match the expected original data size
  3814. if (recsDataUncompSize != recsDataSize) RAYGUI_LOG("WARNING: Uncompressed font recs data could be corrupted");
  3815. RAYGUI_FREE(recsDataCompressed);
  3816. }
  3817. else
  3818. {
  3819. // Recs data is uncompressed
  3820. font.recs = (Rectangle *)RAYGUI_CALLOC(font.glyphCount, sizeof(Rectangle));
  3821. for (int i = 0; i < font.glyphCount; i++)
  3822. {
  3823. memcpy(&font.recs[i], fileDataPtr, sizeof(Rectangle));
  3824. fileDataPtr += sizeof(Rectangle);
  3825. }
  3826. }
  3827. // Load font glyphs info data
  3828. int glyphsDataSize = font.glyphCount*16; // 16 bytes data per glyph
  3829. int glyphsDataCompressedSize = 0;
  3830. // WARNING: Version 400 adds the compression size parameter
  3831. if (version >= 400)
  3832. {
  3833. // RGS files version 400 support compressed glyphs data
  3834. memcpy(&glyphsDataCompressedSize, fileDataPtr, sizeof(int));
  3835. fileDataPtr += sizeof(int);
  3836. }
  3837. // Allocate required glyphs space to fill with data
  3838. font.glyphs = (GlyphInfo *)RAYGUI_CALLOC(font.glyphCount, sizeof(GlyphInfo));
  3839. if ((glyphsDataCompressedSize > 0) && (glyphsDataCompressedSize != glyphsDataSize))
  3840. {
  3841. // Glyphs data is compressed, uncompress it
  3842. unsigned char *glypsDataCompressed = (unsigned char *)RAYGUI_MALLOC(glyphsDataCompressedSize);
  3843. memcpy(glypsDataCompressed, fileDataPtr, glyphsDataCompressedSize);
  3844. fileDataPtr += glyphsDataCompressedSize;
  3845. int glyphsDataUncompSize = 0;
  3846. unsigned char *glyphsDataUncomp = DecompressData(glypsDataCompressed, glyphsDataCompressedSize, &glyphsDataUncompSize);
  3847. // Security check, data uncompressed size must match the expected original data size
  3848. if (glyphsDataUncompSize != glyphsDataSize) RAYGUI_LOG("WARNING: Uncompressed font glyphs data could be corrupted");
  3849. unsigned char *glyphsDataUncompPtr = glyphsDataUncomp;
  3850. for (int i = 0; i < font.glyphCount; i++)
  3851. {
  3852. memcpy(&font.glyphs[i].value, glyphsDataUncompPtr, sizeof(int));
  3853. memcpy(&font.glyphs[i].offsetX, glyphsDataUncompPtr + 4, sizeof(int));
  3854. memcpy(&font.glyphs[i].offsetY, glyphsDataUncompPtr + 8, sizeof(int));
  3855. memcpy(&font.glyphs[i].advanceX, glyphsDataUncompPtr + 12, sizeof(int));
  3856. glyphsDataUncompPtr += 16;
  3857. }
  3858. RAYGUI_FREE(glypsDataCompressed);
  3859. RAYGUI_FREE(glyphsDataUncomp);
  3860. }
  3861. else
  3862. {
  3863. // Glyphs data is uncompressed
  3864. for (int i = 0; i < font.glyphCount; i++)
  3865. {
  3866. memcpy(&font.glyphs[i].value, fileDataPtr, sizeof(int));
  3867. memcpy(&font.glyphs[i].offsetX, fileDataPtr + 4, sizeof(int));
  3868. memcpy(&font.glyphs[i].offsetY, fileDataPtr + 8, sizeof(int));
  3869. memcpy(&font.glyphs[i].advanceX, fileDataPtr + 12, sizeof(int));
  3870. fileDataPtr += 16;
  3871. }
  3872. }
  3873. }
  3874. else font = GetFontDefault(); // Fallback in case of errors loading font atlas texture
  3875. GuiSetFont(font);
  3876. // Set font texture source rectangle to be used as white texture to draw shapes
  3877. // NOTE: It makes possible to draw shapes and text (full UI) in a single draw call
  3878. if ((fontWhiteRec.x > 0) &&
  3879. (fontWhiteRec.y > 0) &&
  3880. (fontWhiteRec.width > 0) &&
  3881. (fontWhiteRec.height > 0)) SetShapesTexture(font.texture, fontWhiteRec);
  3882. }
  3883. #endif
  3884. }
  3885. }
  3886. // Gui get text width considering icon
  3887. static int GetTextWidth(const char *text)
  3888. {
  3889. #if !defined(ICON_TEXT_PADDING)
  3890. #define ICON_TEXT_PADDING 4
  3891. #endif
  3892. Vector2 textSize = { 0 };
  3893. int textIconOffset = 0;
  3894. if ((text != NULL) && (text[0] != '\0'))
  3895. {
  3896. if (text[0] == '#')
  3897. {
  3898. for (int i = 1; (i < 5) && (text[i] != '\0'); i++)
  3899. {
  3900. if (text[i] == '#')
  3901. {
  3902. textIconOffset = i;
  3903. break;
  3904. }
  3905. }
  3906. }
  3907. text += textIconOffset;
  3908. // Make sure guiFont is set, GuiGetStyle() initializes it lazynessly
  3909. float fontSize = (float)GuiGetStyle(DEFAULT, TEXT_SIZE);
  3910. // Custom MeasureText() implementation
  3911. if ((guiFont.texture.id > 0) && (text != NULL))
  3912. {
  3913. // Get size in bytes of text, considering end of line and line break
  3914. int size = 0;
  3915. for (int i = 0; i < MAX_LINE_BUFFER_SIZE; i++)
  3916. {
  3917. if ((text[i] != '\0') && (text[i] != '\n')) size++;
  3918. else break;
  3919. }
  3920. float scaleFactor = fontSize/(float)guiFont.baseSize;
  3921. textSize.y = (float)guiFont.baseSize*scaleFactor;
  3922. float glyphWidth = 0.0f;
  3923. for (int i = 0, codepointSize = 0; i < size; i += codepointSize)
  3924. {
  3925. int codepoint = GetCodepointNext(&text[i], &codepointSize);
  3926. int codepointIndex = GetGlyphIndex(guiFont, codepoint);
  3927. if (guiFont.glyphs[codepointIndex].advanceX == 0) glyphWidth = ((float)guiFont.recs[codepointIndex].width*scaleFactor);
  3928. else glyphWidth = ((float)guiFont.glyphs[codepointIndex].advanceX*scaleFactor);
  3929. textSize.x += (glyphWidth + (float)GuiGetStyle(DEFAULT, TEXT_SPACING));
  3930. }
  3931. }
  3932. if (textIconOffset > 0) textSize.x += (RAYGUI_ICON_SIZE - ICON_TEXT_PADDING);
  3933. }
  3934. return (int)textSize.x;
  3935. }
  3936. // Get text bounds considering control bounds
  3937. static Rectangle GetTextBounds(int control, Rectangle bounds)
  3938. {
  3939. Rectangle textBounds = bounds;
  3940. textBounds.x = bounds.x + GuiGetStyle(control, BORDER_WIDTH);
  3941. textBounds.y = bounds.y + GuiGetStyle(control, BORDER_WIDTH) + GuiGetStyle(control, TEXT_PADDING);
  3942. textBounds.width = bounds.width - 2*GuiGetStyle(control, BORDER_WIDTH) - 2*GuiGetStyle(control, TEXT_PADDING);
  3943. textBounds.height = bounds.height - 2*GuiGetStyle(control, BORDER_WIDTH) - 2*GuiGetStyle(control, TEXT_PADDING); // NOTE: Text is processed line per line!
  3944. // Depending on control, TEXT_PADDING and TEXT_ALIGNMENT properties could affect the text-bounds
  3945. switch (control)
  3946. {
  3947. case COMBOBOX:
  3948. case DROPDOWNBOX:
  3949. case LISTVIEW:
  3950. // TODO: Special cases (no label): COMBOBOX, DROPDOWNBOX, LISTVIEW
  3951. case SLIDER:
  3952. case CHECKBOX:
  3953. case VALUEBOX:
  3954. case SPINNER:
  3955. // TODO: More special cases (label on side): SLIDER, CHECKBOX, VALUEBOX, SPINNER
  3956. default:
  3957. {
  3958. // TODO: WARNING: TEXT_ALIGNMENT is already considered in GuiDrawText()
  3959. if (GuiGetStyle(control, TEXT_ALIGNMENT) == TEXT_ALIGN_RIGHT) textBounds.x -= GuiGetStyle(control, TEXT_PADDING);
  3960. else textBounds.x += GuiGetStyle(control, TEXT_PADDING);
  3961. }
  3962. break;
  3963. }
  3964. return textBounds;
  3965. }
  3966. // Get text icon if provided and move text cursor
  3967. // NOTE: We support up to 999 values for iconId
  3968. static const char *GetTextIcon(const char *text, int *iconId)
  3969. {
  3970. #if !defined(RAYGUI_NO_ICONS)
  3971. *iconId = -1;
  3972. if (text[0] == '#') // Maybe we have an icon!
  3973. {
  3974. char iconValue[4] = { 0 }; // Maximum length for icon value: 3 digits + '\0'
  3975. int pos = 1;
  3976. while ((pos < 4) && (text[pos] >= '0') && (text[pos] <= '9'))
  3977. {
  3978. iconValue[pos - 1] = text[pos];
  3979. pos++;
  3980. }
  3981. if (text[pos] == '#')
  3982. {
  3983. *iconId = TextToInteger(iconValue);
  3984. // Move text pointer after icon
  3985. // WARNING: If only icon provided, it could point to EOL character: '\0'
  3986. if (*iconId >= 0) text += (pos + 1);
  3987. }
  3988. }
  3989. #endif
  3990. return text;
  3991. }
  3992. // Get text divided into lines (by line-breaks '\n')
  3993. const char **GetTextLines(const char *text, int *count)
  3994. {
  3995. #define RAYGUI_MAX_TEXT_LINES 128
  3996. static const char *lines[RAYGUI_MAX_TEXT_LINES] = { 0 };
  3997. for (int i = 0; i < RAYGUI_MAX_TEXT_LINES; i++) lines[i] = NULL; // Init NULL pointers to substrings
  3998. int textSize = (int)strlen(text);
  3999. lines[0] = text;
  4000. int len = 0;
  4001. *count = 1;
  4002. //int lineSize = 0; // Stores current line size, not returned
  4003. for (int i = 0, k = 0; (i < textSize) && (*count < RAYGUI_MAX_TEXT_LINES); i++)
  4004. {
  4005. if (text[i] == '\n')
  4006. {
  4007. //lineSize = len;
  4008. k++;
  4009. lines[k] = &text[i + 1]; // WARNING: next value is valid?
  4010. len = 0;
  4011. *count += 1;
  4012. }
  4013. else len++;
  4014. }
  4015. //lines[*count - 1].size = len;
  4016. return lines;
  4017. }
  4018. // Get text width to next space for provided string
  4019. static float GetNextSpaceWidth(const char *text, int *nextSpaceIndex)
  4020. {
  4021. float width = 0;
  4022. int codepointByteCount = 0;
  4023. int codepoint = 0;
  4024. int index = 0;
  4025. float glyphWidth = 0;
  4026. float scaleFactor = (float)GuiGetStyle(DEFAULT, TEXT_SIZE)/guiFont.baseSize;
  4027. for (int i = 0; text[i] != '\0'; i++)
  4028. {
  4029. if (text[i] != ' ')
  4030. {
  4031. codepoint = GetCodepoint(&text[i], &codepointByteCount);
  4032. index = GetGlyphIndex(guiFont, codepoint);
  4033. glyphWidth = (guiFont.glyphs[index].advanceX == 0)? guiFont.recs[index].width*scaleFactor : guiFont.glyphs[index].advanceX*scaleFactor;
  4034. width += (glyphWidth + (float)GuiGetStyle(DEFAULT, TEXT_SPACING));
  4035. }
  4036. else
  4037. {
  4038. *nextSpaceIndex = i;
  4039. break;
  4040. }
  4041. }
  4042. return width;
  4043. }
  4044. // Gui draw text using default font
  4045. static void GuiDrawText(const char *text, Rectangle textBounds, int alignment, Color tint)
  4046. {
  4047. #define TEXT_VALIGN_PIXEL_OFFSET(h) ((int)h%2) // Vertical alignment for pixel perfect
  4048. #if !defined(ICON_TEXT_PADDING)
  4049. #define ICON_TEXT_PADDING 4
  4050. #endif
  4051. if ((text == NULL) || (text[0] == '\0')) return; // Security check
  4052. // PROCEDURE:
  4053. // - Text is processed line per line
  4054. // - For every line, horizontal alignment is defined
  4055. // - For all text, vertical alignment is defined (multiline text only)
  4056. // - For every line, wordwrap mode is checked (useful for GuitextBox(), read-only)
  4057. // Get text lines (using '\n' as delimiter) to be processed individually
  4058. // WARNING: We can't use GuiTextSplit() function because it can be already used
  4059. // before the GuiDrawText() call and its buffer is static, it would be overriden :(
  4060. int lineCount = 0;
  4061. const char **lines = GetTextLines(text, &lineCount);
  4062. // Text style variables
  4063. //int alignment = GuiGetStyle(DEFAULT, TEXT_ALIGNMENT);
  4064. int alignmentVertical = GuiGetStyle(DEFAULT, TEXT_ALIGNMENT_VERTICAL);
  4065. int wrapMode = GuiGetStyle(DEFAULT, TEXT_WRAP_MODE); // Wrap-mode only available in read-only mode, no for text editing
  4066. // TODO: WARNING: This totalHeight is not valid for vertical alignment in case of word-wrap
  4067. float totalHeight = (float)(lineCount*GuiGetStyle(DEFAULT, TEXT_SIZE) + (lineCount - 1)*GuiGetStyle(DEFAULT, TEXT_SIZE)/2);
  4068. float posOffsetY = 0.0f;
  4069. for (int i = 0; i < lineCount; i++)
  4070. {
  4071. int iconId = 0;
  4072. lines[i] = GetTextIcon(lines[i], &iconId); // Check text for icon and move cursor
  4073. // Get text position depending on alignment and iconId
  4074. //---------------------------------------------------------------------------------
  4075. Vector2 textBoundsPosition = { textBounds.x, textBounds.y };
  4076. // NOTE: We get text size after icon has been processed
  4077. // WARNING: GetTextWidth() also processes text icon to get width! -> Really needed?
  4078. int textSizeX = GetTextWidth(lines[i]);
  4079. // If text requires an icon, add size to measure
  4080. if (iconId >= 0)
  4081. {
  4082. textSizeX += RAYGUI_ICON_SIZE*guiIconScale;
  4083. // WARNING: If only icon provided, text could be pointing to EOF character: '\0'
  4084. #if !defined(RAYGUI_NO_ICONS)
  4085. if ((lines[i] != NULL) && (lines[i][0] != '\0')) textSizeX += ICON_TEXT_PADDING;
  4086. #endif
  4087. }
  4088. // Check guiTextAlign global variables
  4089. switch (alignment)
  4090. {
  4091. case TEXT_ALIGN_LEFT: textBoundsPosition.x = textBounds.x; break;
  4092. case TEXT_ALIGN_CENTER: textBoundsPosition.x = textBounds.x + textBounds.width/2 - textSizeX/2; break;
  4093. case TEXT_ALIGN_RIGHT: textBoundsPosition.x = textBounds.x + textBounds.width - textSizeX; break;
  4094. default: break;
  4095. }
  4096. switch (alignmentVertical)
  4097. {
  4098. // Only valid in case of wordWrap = 0;
  4099. case TEXT_ALIGN_TOP: textBoundsPosition.y = textBounds.y + posOffsetY; break;
  4100. case TEXT_ALIGN_MIDDLE: textBoundsPosition.y = textBounds.y + posOffsetY + textBounds.height/2 - totalHeight/2 + TEXT_VALIGN_PIXEL_OFFSET(textBounds.height); break;
  4101. case TEXT_ALIGN_BOTTOM: textBoundsPosition.y = textBounds.y + posOffsetY + textBounds.height - totalHeight + TEXT_VALIGN_PIXEL_OFFSET(textBounds.height); break;
  4102. default: break;
  4103. }
  4104. // NOTE: Make sure we get pixel-perfect coordinates,
  4105. // In case of decimals we got weird text positioning
  4106. textBoundsPosition.x = (float)((int)textBoundsPosition.x);
  4107. textBoundsPosition.y = (float)((int)textBoundsPosition.y);
  4108. //---------------------------------------------------------------------------------
  4109. // Draw text (with icon if available)
  4110. //---------------------------------------------------------------------------------
  4111. #if !defined(RAYGUI_NO_ICONS)
  4112. if (iconId >= 0)
  4113. {
  4114. // NOTE: We consider icon height, probably different than text size
  4115. GuiDrawIcon(iconId, (int)textBoundsPosition.x, (int)(textBounds.y + textBounds.height/2 - RAYGUI_ICON_SIZE*guiIconScale/2 + TEXT_VALIGN_PIXEL_OFFSET(textBounds.height)), guiIconScale, tint);
  4116. textBoundsPosition.x += (RAYGUI_ICON_SIZE*guiIconScale + ICON_TEXT_PADDING);
  4117. }
  4118. #endif
  4119. // Get size in bytes of text,
  4120. // considering end of line and line break
  4121. int lineSize = 0;
  4122. for (int c = 0; (lines[i][c] != '\0') && (lines[i][c] != '\n') && (lines[i][c] != '\r'); c++, lineSize++){ }
  4123. float scaleFactor = (float)GuiGetStyle(DEFAULT, TEXT_SIZE)/guiFont.baseSize;
  4124. int textOffsetY = 0;
  4125. float textOffsetX = 0.0f;
  4126. float glyphWidth = 0;
  4127. for (int c = 0, codepointSize = 0; c < lineSize; c += codepointSize)
  4128. {
  4129. int codepoint = GetCodepointNext(&lines[i][c], &codepointSize);
  4130. int index = GetGlyphIndex(guiFont, codepoint);
  4131. // NOTE: Normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f)
  4132. // but we need to draw all of the bad bytes using the '?' symbol moving one byte
  4133. if (codepoint == 0x3f) codepointSize = 1; // TODO: Review not recognized codepoints size
  4134. // Wrap mode text measuring to space to validate if it can be drawn or
  4135. // a new line is required
  4136. if (wrapMode == TEXT_WRAP_CHAR)
  4137. {
  4138. // Get glyph width to check if it goes out of bounds
  4139. if (guiFont.glyphs[index].advanceX == 0) glyphWidth = ((float)guiFont.recs[index].width*scaleFactor);
  4140. else glyphWidth = (float)guiFont.glyphs[index].advanceX*scaleFactor;
  4141. // Jump to next line if current character reach end of the box limits
  4142. if ((textOffsetX + glyphWidth) > textBounds.width)
  4143. {
  4144. textOffsetX = 0.0f;
  4145. textOffsetY += GuiGetStyle(DEFAULT, TEXT_LINE_SPACING);
  4146. }
  4147. }
  4148. else if (wrapMode == TEXT_WRAP_WORD)
  4149. {
  4150. // Get width to next space in line
  4151. int nextSpaceIndex = 0;
  4152. float nextSpaceWidth = GetNextSpaceWidth(lines[i] + c, &nextSpaceIndex);
  4153. if ((textOffsetX + nextSpaceWidth) > textBounds.width)
  4154. {
  4155. textOffsetX = 0.0f;
  4156. textOffsetY += GuiGetStyle(DEFAULT, TEXT_LINE_SPACING);
  4157. }
  4158. // TODO: Consider case: (nextSpaceWidth >= textBounds.width)
  4159. }
  4160. if (codepoint == '\n') break; // WARNING: Lines are already processed manually, no need to keep drawing after this codepoint
  4161. else
  4162. {
  4163. // TODO: There are multiple types of spaces in Unicode,
  4164. // maybe it's a good idea to add support for more: http://jkorpela.fi/chars/spaces.html
  4165. if ((codepoint != ' ') && (codepoint != '\t')) // Do not draw codepoints with no glyph
  4166. {
  4167. if (wrapMode == TEXT_WRAP_NONE)
  4168. {
  4169. // Draw only required text glyphs fitting the textBounds.width
  4170. if (textOffsetX <= (textBounds.width - glyphWidth))
  4171. {
  4172. DrawTextCodepoint(guiFont, codepoint, RAYGUI_CLITERAL(Vector2){ textBoundsPosition.x + textOffsetX, textBoundsPosition.y + textOffsetY }, (float)GuiGetStyle(DEFAULT, TEXT_SIZE), GuiFade(tint, guiAlpha));
  4173. }
  4174. }
  4175. else if ((wrapMode == TEXT_WRAP_CHAR) || (wrapMode == TEXT_WRAP_WORD))
  4176. {
  4177. // Draw only glyphs inside the bounds
  4178. if ((textBoundsPosition.y + textOffsetY) <= (textBounds.y + textBounds.height - GuiGetStyle(DEFAULT, TEXT_SIZE)))
  4179. {
  4180. DrawTextCodepoint(guiFont, codepoint, RAYGUI_CLITERAL(Vector2){ textBoundsPosition.x + textOffsetX, textBoundsPosition.y + textOffsetY }, (float)GuiGetStyle(DEFAULT, TEXT_SIZE), GuiFade(tint, guiAlpha));
  4181. }
  4182. }
  4183. }
  4184. if (guiFont.glyphs[index].advanceX == 0) textOffsetX += ((float)guiFont.recs[index].width*scaleFactor + (float)GuiGetStyle(DEFAULT, TEXT_SPACING));
  4185. else textOffsetX += ((float)guiFont.glyphs[index].advanceX*scaleFactor + (float)GuiGetStyle(DEFAULT, TEXT_SPACING));
  4186. }
  4187. }
  4188. if (wrapMode == TEXT_WRAP_NONE) posOffsetY += (float)GuiGetStyle(DEFAULT, TEXT_LINE_SPACING);
  4189. else if ((wrapMode == TEXT_WRAP_CHAR) || (wrapMode == TEXT_WRAP_WORD)) posOffsetY += (textOffsetY + (float)GuiGetStyle(DEFAULT, TEXT_LINE_SPACING));
  4190. //---------------------------------------------------------------------------------
  4191. }
  4192. #if defined(RAYGUI_DEBUG_TEXT_BOUNDS)
  4193. GuiDrawRectangle(textBounds, 0, WHITE, Fade(BLUE, 0.4f));
  4194. #endif
  4195. }
  4196. // Gui draw rectangle using default raygui plain style with borders
  4197. static void GuiDrawRectangle(Rectangle rec, int borderWidth, Color borderColor, Color color)
  4198. {
  4199. if (color.a > 0)
  4200. {
  4201. // Draw rectangle filled with color
  4202. DrawRectangle((int)rec.x, (int)rec.y, (int)rec.width, (int)rec.height, GuiFade(color, guiAlpha));
  4203. }
  4204. if (borderWidth > 0)
  4205. {
  4206. // Draw rectangle border lines with color
  4207. DrawRectangle((int)rec.x, (int)rec.y, (int)rec.width, borderWidth, GuiFade(borderColor, guiAlpha));
  4208. DrawRectangle((int)rec.x, (int)rec.y + borderWidth, borderWidth, (int)rec.height - 2*borderWidth, GuiFade(borderColor, guiAlpha));
  4209. DrawRectangle((int)rec.x + (int)rec.width - borderWidth, (int)rec.y + borderWidth, borderWidth, (int)rec.height - 2*borderWidth, GuiFade(borderColor, guiAlpha));
  4210. DrawRectangle((int)rec.x, (int)rec.y + (int)rec.height - borderWidth, (int)rec.width, borderWidth, GuiFade(borderColor, guiAlpha));
  4211. }
  4212. #if defined(RAYGUI_DEBUG_RECS_BOUNDS)
  4213. DrawRectangle((int)rec.x, (int)rec.y, (int)rec.width, (int)rec.height, Fade(RED, 0.4f));
  4214. #endif
  4215. }
  4216. // Draw tooltip using control bounds
  4217. static void GuiTooltip(Rectangle controlRec)
  4218. {
  4219. if (!guiLocked && guiTooltip && (guiTooltipPtr != NULL) && !guiSliderDragging)
  4220. {
  4221. Vector2 textSize = MeasureTextEx(GuiGetFont(), guiTooltipPtr, (float)GuiGetStyle(DEFAULT, TEXT_SIZE), (float)GuiGetStyle(DEFAULT, TEXT_SPACING));
  4222. if ((controlRec.x + textSize.x + 16) > GetScreenWidth()) controlRec.x -= (textSize.x + 16 - controlRec.width);
  4223. GuiPanel(RAYGUI_CLITERAL(Rectangle){ controlRec.x, controlRec.y + controlRec.height + 4, textSize.x + 16, GuiGetStyle(DEFAULT, TEXT_SIZE) + 8.f }, NULL);
  4224. int textPadding = GuiGetStyle(LABEL, TEXT_PADDING);
  4225. int textAlignment = GuiGetStyle(LABEL, TEXT_ALIGNMENT);
  4226. GuiSetStyle(LABEL, TEXT_PADDING, 0);
  4227. GuiSetStyle(LABEL, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
  4228. GuiLabel(RAYGUI_CLITERAL(Rectangle){ controlRec.x, controlRec.y + controlRec.height + 4, textSize.x + 16, GuiGetStyle(DEFAULT, TEXT_SIZE) + 8.f }, guiTooltipPtr);
  4229. GuiSetStyle(LABEL, TEXT_ALIGNMENT, textAlignment);
  4230. GuiSetStyle(LABEL, TEXT_PADDING, textPadding);
  4231. }
  4232. }
  4233. // Split controls text into multiple strings
  4234. // Also check for multiple columns (required by GuiToggleGroup())
  4235. static const char **GuiTextSplit(const char *text, char delimiter, int *count, int *textRow)
  4236. {
  4237. // NOTE: Current implementation returns a copy of the provided string with '\0' (string end delimiter)
  4238. // inserted between strings defined by "delimiter" parameter. No memory is dynamically allocated,
  4239. // all used memory is static... it has some limitations:
  4240. // 1. Maximum number of possible split strings is set by RAYGUI_TEXTSPLIT_MAX_ITEMS
  4241. // 2. Maximum size of text to split is RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE
  4242. // NOTE: Those definitions could be externally provided if required
  4243. // TODO: HACK: GuiTextSplit() - Review how textRows are returned to user
  4244. // textRow is an externally provided array of integers that stores row number for every splitted string
  4245. #if !defined(RAYGUI_TEXTSPLIT_MAX_ITEMS)
  4246. #define RAYGUI_TEXTSPLIT_MAX_ITEMS 128
  4247. #endif
  4248. #if !defined(RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE)
  4249. #define RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE 1024
  4250. #endif
  4251. static const char *result[RAYGUI_TEXTSPLIT_MAX_ITEMS] = { NULL }; // String pointers array (points to buffer data)
  4252. static char buffer[RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE] = { 0 }; // Buffer data (text input copy with '\0' added)
  4253. memset(buffer, 0, RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE);
  4254. result[0] = buffer;
  4255. int counter = 1;
  4256. if (textRow != NULL) textRow[0] = 0;
  4257. // Count how many substrings we have on text and point to every one
  4258. for (int i = 0; i < RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE; i++)
  4259. {
  4260. buffer[i] = text[i];
  4261. if (buffer[i] == '\0') break;
  4262. else if ((buffer[i] == delimiter) || (buffer[i] == '\n'))
  4263. {
  4264. result[counter] = buffer + i + 1;
  4265. if (textRow != NULL)
  4266. {
  4267. if (buffer[i] == '\n') textRow[counter] = textRow[counter - 1] + 1;
  4268. else textRow[counter] = textRow[counter - 1];
  4269. }
  4270. buffer[i] = '\0'; // Set an end of string at this point
  4271. counter++;
  4272. if (counter == RAYGUI_TEXTSPLIT_MAX_ITEMS) break;
  4273. }
  4274. }
  4275. *count = counter;
  4276. return result;
  4277. }
  4278. // Convert color data from RGB to HSV
  4279. // NOTE: Color data should be passed normalized
  4280. static Vector3 ConvertRGBtoHSV(Vector3 rgb)
  4281. {
  4282. Vector3 hsv = { 0 };
  4283. float min = 0.0f;
  4284. float max = 0.0f;
  4285. float delta = 0.0f;
  4286. min = (rgb.x < rgb.y)? rgb.x : rgb.y;
  4287. min = (min < rgb.z)? min : rgb.z;
  4288. max = (rgb.x > rgb.y)? rgb.x : rgb.y;
  4289. max = (max > rgb.z)? max : rgb.z;
  4290. hsv.z = max; // Value
  4291. delta = max - min;
  4292. if (delta < 0.00001f)
  4293. {
  4294. hsv.y = 0.0f;
  4295. hsv.x = 0.0f; // Undefined, maybe NAN?
  4296. return hsv;
  4297. }
  4298. if (max > 0.0f)
  4299. {
  4300. // NOTE: If max is 0, this divide would cause a crash
  4301. hsv.y = (delta/max); // Saturation
  4302. }
  4303. else
  4304. {
  4305. // NOTE: If max is 0, then r = g = b = 0, s = 0, h is undefined
  4306. hsv.y = 0.0f;
  4307. hsv.x = 0.0f; // Undefined, maybe NAN?
  4308. return hsv;
  4309. }
  4310. // NOTE: Comparing float values could not work properly
  4311. if (rgb.x >= max) hsv.x = (rgb.y - rgb.z)/delta; // Between yellow & magenta
  4312. else
  4313. {
  4314. if (rgb.y >= max) hsv.x = 2.0f + (rgb.z - rgb.x)/delta; // Between cyan & yellow
  4315. else hsv.x = 4.0f + (rgb.x - rgb.y)/delta; // Between magenta & cyan
  4316. }
  4317. hsv.x *= 60.0f; // Convert to degrees
  4318. if (hsv.x < 0.0f) hsv.x += 360.0f;
  4319. return hsv;
  4320. }
  4321. // Convert color data from HSV to RGB
  4322. // NOTE: Color data should be passed normalized
  4323. static Vector3 ConvertHSVtoRGB(Vector3 hsv)
  4324. {
  4325. Vector3 rgb = { 0 };
  4326. float hh = 0.0f, p = 0.0f, q = 0.0f, t = 0.0f, ff = 0.0f;
  4327. long i = 0;
  4328. // NOTE: Comparing float values could not work properly
  4329. if (hsv.y <= 0.0f)
  4330. {
  4331. rgb.x = hsv.z;
  4332. rgb.y = hsv.z;
  4333. rgb.z = hsv.z;
  4334. return rgb;
  4335. }
  4336. hh = hsv.x;
  4337. if (hh >= 360.0f) hh = 0.0f;
  4338. hh /= 60.0f;
  4339. i = (long)hh;
  4340. ff = hh - i;
  4341. p = hsv.z*(1.0f - hsv.y);
  4342. q = hsv.z*(1.0f - (hsv.y*ff));
  4343. t = hsv.z*(1.0f - (hsv.y*(1.0f - ff)));
  4344. switch (i)
  4345. {
  4346. case 0:
  4347. {
  4348. rgb.x = hsv.z;
  4349. rgb.y = t;
  4350. rgb.z = p;
  4351. } break;
  4352. case 1:
  4353. {
  4354. rgb.x = q;
  4355. rgb.y = hsv.z;
  4356. rgb.z = p;
  4357. } break;
  4358. case 2:
  4359. {
  4360. rgb.x = p;
  4361. rgb.y = hsv.z;
  4362. rgb.z = t;
  4363. } break;
  4364. case 3:
  4365. {
  4366. rgb.x = p;
  4367. rgb.y = q;
  4368. rgb.z = hsv.z;
  4369. } break;
  4370. case 4:
  4371. {
  4372. rgb.x = t;
  4373. rgb.y = p;
  4374. rgb.z = hsv.z;
  4375. } break;
  4376. case 5:
  4377. default:
  4378. {
  4379. rgb.x = hsv.z;
  4380. rgb.y = p;
  4381. rgb.z = q;
  4382. } break;
  4383. }
  4384. return rgb;
  4385. }
  4386. // Scroll bar control (used by GuiScrollPanel())
  4387. static int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue)
  4388. {
  4389. GuiState state = guiState;
  4390. // Is the scrollbar horizontal or vertical?
  4391. bool isVertical = (bounds.width > bounds.height)? false : true;
  4392. // The size (width or height depending on scrollbar type) of the spinner buttons
  4393. const int spinnerSize = GuiGetStyle(SCROLLBAR, ARROWS_VISIBLE)?
  4394. (isVertical? (int)bounds.width - 2*GuiGetStyle(SCROLLBAR, BORDER_WIDTH) :
  4395. (int)bounds.height - 2*GuiGetStyle(SCROLLBAR, BORDER_WIDTH)) : 0;
  4396. // Arrow buttons [<] [>] [∧] [∨]
  4397. Rectangle arrowUpLeft = { 0 };
  4398. Rectangle arrowDownRight = { 0 };
  4399. // Actual area of the scrollbar excluding the arrow buttons
  4400. Rectangle scrollbar = { 0 };
  4401. // Slider bar that moves --[///]-----
  4402. Rectangle slider = { 0 };
  4403. // Normalize value
  4404. if (value > maxValue) value = maxValue;
  4405. if (value < minValue) value = minValue;
  4406. const int valueRange = maxValue - minValue;
  4407. int sliderSize = GuiGetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE);
  4408. // Calculate rectangles for all of the components
  4409. arrowUpLeft = RAYGUI_CLITERAL(Rectangle){
  4410. (float)bounds.x + GuiGetStyle(SCROLLBAR, BORDER_WIDTH),
  4411. (float)bounds.y + GuiGetStyle(SCROLLBAR, BORDER_WIDTH),
  4412. (float)spinnerSize, (float)spinnerSize };
  4413. if (isVertical)
  4414. {
  4415. arrowDownRight = RAYGUI_CLITERAL(Rectangle){ (float)bounds.x + GuiGetStyle(SCROLLBAR, BORDER_WIDTH), (float)bounds.y + bounds.height - spinnerSize - GuiGetStyle(SCROLLBAR, BORDER_WIDTH), (float)spinnerSize, (float)spinnerSize };
  4416. scrollbar = RAYGUI_CLITERAL(Rectangle){ bounds.x + GuiGetStyle(SCROLLBAR, BORDER_WIDTH) + GuiGetStyle(SCROLLBAR, SCROLL_PADDING), arrowUpLeft.y + arrowUpLeft.height, bounds.width - 2*(GuiGetStyle(SCROLLBAR, BORDER_WIDTH) + GuiGetStyle(SCROLLBAR, SCROLL_PADDING)), bounds.height - arrowUpLeft.height - arrowDownRight.height - 2*GuiGetStyle(SCROLLBAR, BORDER_WIDTH) };
  4417. // Make sure the slider won't get outside of the scrollbar
  4418. sliderSize = (sliderSize >= scrollbar.height)? ((int)scrollbar.height - 2) : sliderSize;
  4419. slider = RAYGUI_CLITERAL(Rectangle){
  4420. bounds.x + GuiGetStyle(SCROLLBAR, BORDER_WIDTH) + GuiGetStyle(SCROLLBAR, SCROLL_SLIDER_PADDING),
  4421. scrollbar.y + (int)(((float)(value - minValue)/valueRange)*(scrollbar.height - sliderSize)),
  4422. bounds.width - 2*(GuiGetStyle(SCROLLBAR, BORDER_WIDTH) + GuiGetStyle(SCROLLBAR, SCROLL_SLIDER_PADDING)),
  4423. (float)sliderSize };
  4424. }
  4425. else // horizontal
  4426. {
  4427. arrowDownRight = RAYGUI_CLITERAL(Rectangle){ (float)bounds.x + bounds.width - spinnerSize - GuiGetStyle(SCROLLBAR, BORDER_WIDTH), (float)bounds.y + GuiGetStyle(SCROLLBAR, BORDER_WIDTH), (float)spinnerSize, (float)spinnerSize };
  4428. scrollbar = RAYGUI_CLITERAL(Rectangle){ arrowUpLeft.x + arrowUpLeft.width, bounds.y + GuiGetStyle(SCROLLBAR, BORDER_WIDTH) + GuiGetStyle(SCROLLBAR, SCROLL_PADDING), bounds.width - arrowUpLeft.width - arrowDownRight.width - 2*GuiGetStyle(SCROLLBAR, BORDER_WIDTH), bounds.height - 2*(GuiGetStyle(SCROLLBAR, BORDER_WIDTH) + GuiGetStyle(SCROLLBAR, SCROLL_PADDING)) };
  4429. // Make sure the slider won't get outside of the scrollbar
  4430. sliderSize = (sliderSize >= scrollbar.width)? ((int)scrollbar.width - 2) : sliderSize;
  4431. slider = RAYGUI_CLITERAL(Rectangle){
  4432. scrollbar.x + (int)(((float)(value - minValue)/valueRange)*(scrollbar.width - sliderSize)),
  4433. bounds.y + GuiGetStyle(SCROLLBAR, BORDER_WIDTH) + GuiGetStyle(SCROLLBAR, SCROLL_SLIDER_PADDING),
  4434. (float)sliderSize,
  4435. bounds.height - 2*(GuiGetStyle(SCROLLBAR, BORDER_WIDTH) + GuiGetStyle(SCROLLBAR, SCROLL_SLIDER_PADDING)) };
  4436. }
  4437. // Update control
  4438. //--------------------------------------------------------------------
  4439. if ((state != STATE_DISABLED) && !guiLocked)
  4440. {
  4441. Vector2 mousePoint = GetMousePosition();
  4442. if (guiSliderDragging) // Keep dragging outside of bounds
  4443. {
  4444. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) &&
  4445. !CheckCollisionPointRec(mousePoint, arrowUpLeft) &&
  4446. !CheckCollisionPointRec(mousePoint, arrowDownRight))
  4447. {
  4448. if (CHECK_BOUNDS_ID(bounds, guiSliderActive))
  4449. {
  4450. state = STATE_PRESSED;
  4451. if (isVertical) value = (int)(((float)(mousePoint.y - scrollbar.y - slider.height/2)*valueRange)/(scrollbar.height - slider.height) + minValue);
  4452. else value = (int)(((float)(mousePoint.x - scrollbar.x - slider.width/2)*valueRange)/(scrollbar.width - slider.width) + minValue);
  4453. }
  4454. }
  4455. else
  4456. {
  4457. guiSliderDragging = false;
  4458. guiSliderActive = RAYGUI_CLITERAL(Rectangle){ 0, 0, 0, 0 };
  4459. }
  4460. }
  4461. else if (CheckCollisionPointRec(mousePoint, bounds))
  4462. {
  4463. state = STATE_FOCUSED;
  4464. // Handle mouse wheel
  4465. int wheel = (int)GetMouseWheelMove();
  4466. if (wheel != 0) value += wheel;
  4467. // Handle mouse button down
  4468. if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
  4469. {
  4470. guiSliderDragging = true;
  4471. guiSliderActive = bounds; // Store bounds as an identifier when dragging starts
  4472. // Check arrows click
  4473. if (CheckCollisionPointRec(mousePoint, arrowUpLeft)) value -= valueRange/GuiGetStyle(SCROLLBAR, SCROLL_SPEED);
  4474. else if (CheckCollisionPointRec(mousePoint, arrowDownRight)) value += valueRange/GuiGetStyle(SCROLLBAR, SCROLL_SPEED);
  4475. else if (!CheckCollisionPointRec(mousePoint, slider))
  4476. {
  4477. // If click on scrollbar position but not on slider, place slider directly on that position
  4478. if (isVertical) value = (int)(((float)(mousePoint.y - scrollbar.y - slider.height/2)*valueRange)/(scrollbar.height - slider.height) + minValue);
  4479. else value = (int)(((float)(mousePoint.x - scrollbar.x - slider.width/2)*valueRange)/(scrollbar.width - slider.width) + minValue);
  4480. }
  4481. state = STATE_PRESSED;
  4482. }
  4483. // Keyboard control on mouse hover scrollbar
  4484. /*
  4485. if (isVertical)
  4486. {
  4487. if (IsKeyDown(KEY_DOWN)) value += 5;
  4488. else if (IsKeyDown(KEY_UP)) value -= 5;
  4489. }
  4490. else
  4491. {
  4492. if (IsKeyDown(KEY_RIGHT)) value += 5;
  4493. else if (IsKeyDown(KEY_LEFT)) value -= 5;
  4494. }
  4495. */
  4496. }
  4497. // Normalize value
  4498. if (value > maxValue) value = maxValue;
  4499. if (value < minValue) value = minValue;
  4500. }
  4501. //--------------------------------------------------------------------
  4502. // Draw control
  4503. //--------------------------------------------------------------------
  4504. GuiDrawRectangle(bounds, GuiGetStyle(SCROLLBAR, BORDER_WIDTH), GetColor(GuiGetStyle(LISTVIEW, BORDER + state*3)), GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED))); // Draw the background
  4505. GuiDrawRectangle(scrollbar, 0, BLANK, GetColor(GuiGetStyle(BUTTON, BASE_COLOR_NORMAL))); // Draw the scrollbar active area background
  4506. GuiDrawRectangle(slider, 0, BLANK, GetColor(GuiGetStyle(SLIDER, BORDER + state*3))); // Draw the slider bar
  4507. // Draw arrows (using icon if available)
  4508. if (GuiGetStyle(SCROLLBAR, ARROWS_VISIBLE))
  4509. {
  4510. #if defined(RAYGUI_NO_ICONS)
  4511. GuiDrawText(isVertical? "^" : "<",
  4512. RAYGUI_CLITERAL(Rectangle){ arrowUpLeft.x, arrowUpLeft.y, isVertical? bounds.width : bounds.height, isVertical? bounds.width : bounds.height },
  4513. TEXT_ALIGN_CENTER, GetColor(GuiGetStyle(DROPDOWNBOX, TEXT + (state*3))));
  4514. GuiDrawText(isVertical? "v" : ">",
  4515. RAYGUI_CLITERAL(Rectangle){ arrowDownRight.x, arrowDownRight.y, isVertical? bounds.width : bounds.height, isVertical? bounds.width : bounds.height },
  4516. TEXT_ALIGN_CENTER, GetColor(GuiGetStyle(DROPDOWNBOX, TEXT + (state*3))));
  4517. #else
  4518. GuiDrawText(isVertical? "#121#" : "#118#",
  4519. RAYGUI_CLITERAL(Rectangle){ arrowUpLeft.x, arrowUpLeft.y, isVertical? bounds.width : bounds.height, isVertical? bounds.width : bounds.height },
  4520. TEXT_ALIGN_CENTER, GetColor(GuiGetStyle(SCROLLBAR, TEXT + state*3))); // ICON_ARROW_UP_FILL / ICON_ARROW_LEFT_FILL
  4521. GuiDrawText(isVertical? "#120#" : "#119#",
  4522. RAYGUI_CLITERAL(Rectangle){ arrowDownRight.x, arrowDownRight.y, isVertical? bounds.width : bounds.height, isVertical? bounds.width : bounds.height },
  4523. TEXT_ALIGN_CENTER, GetColor(GuiGetStyle(SCROLLBAR, TEXT + state*3))); // ICON_ARROW_DOWN_FILL / ICON_ARROW_RIGHT_FILL
  4524. #endif
  4525. }
  4526. //--------------------------------------------------------------------
  4527. return value;
  4528. }
  4529. // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f
  4530. // WARNING: It multiplies current alpha by alpha scale factor
  4531. static Color GuiFade(Color color, float alpha)
  4532. {
  4533. if (alpha < 0.0f) alpha = 0.0f;
  4534. else if (alpha > 1.0f) alpha = 1.0f;
  4535. Color result = { color.r, color.g, color.b, (unsigned char)(color.a*alpha) };
  4536. return result;
  4537. }
  4538. #if defined(RAYGUI_STANDALONE)
  4539. // Returns a Color struct from hexadecimal value
  4540. static Color GetColor(int hexValue)
  4541. {
  4542. Color color;
  4543. color.r = (unsigned char)(hexValue >> 24) & 0xFF;
  4544. color.g = (unsigned char)(hexValue >> 16) & 0xFF;
  4545. color.b = (unsigned char)(hexValue >> 8) & 0xFF;
  4546. color.a = (unsigned char)hexValue & 0xFF;
  4547. return color;
  4548. }
  4549. // Returns hexadecimal value for a Color
  4550. static int ColorToInt(Color color)
  4551. {
  4552. return (((int)color.r << 24) | ((int)color.g << 16) | ((int)color.b << 8) | (int)color.a);
  4553. }
  4554. // Check if point is inside rectangle
  4555. static bool CheckCollisionPointRec(Vector2 point, Rectangle rec)
  4556. {
  4557. bool collision = false;
  4558. if ((point.x >= rec.x) && (point.x <= (rec.x + rec.width)) &&
  4559. (point.y >= rec.y) && (point.y <= (rec.y + rec.height))) collision = true;
  4560. return collision;
  4561. }
  4562. // Formatting of text with variables to 'embed'
  4563. static const char *TextFormat(const char *text, ...)
  4564. {
  4565. #if !defined(RAYGUI_TEXTFORMAT_MAX_SIZE)
  4566. #define RAYGUI_TEXTFORMAT_MAX_SIZE 256
  4567. #endif
  4568. static char buffer[RAYGUI_TEXTFORMAT_MAX_SIZE];
  4569. va_list args;
  4570. va_start(args, text);
  4571. vsprintf(buffer, text, args);
  4572. va_end(args);
  4573. return buffer;
  4574. }
  4575. // Draw rectangle with vertical gradient fill color
  4576. // NOTE: This function is only used by GuiColorPicker()
  4577. static void DrawRectangleGradientV(int posX, int posY, int width, int height, Color color1, Color color2)
  4578. {
  4579. Rectangle bounds = { (float)posX, (float)posY, (float)width, (float)height };
  4580. DrawRectangleGradientEx(bounds, color1, color2, color2, color1);
  4581. }
  4582. // Split string into multiple strings
  4583. const char **TextSplit(const char *text, char delimiter, int *count)
  4584. {
  4585. // NOTE: Current implementation returns a copy of the provided string with '\0' (string end delimiter)
  4586. // inserted between strings defined by "delimiter" parameter. No memory is dynamically allocated,
  4587. // all used memory is static... it has some limitations:
  4588. // 1. Maximum number of possible split strings is set by RAYGUI_TEXTSPLIT_MAX_ITEMS
  4589. // 2. Maximum size of text to split is RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE
  4590. #if !defined(RAYGUI_TEXTSPLIT_MAX_ITEMS)
  4591. #define RAYGUI_TEXTSPLIT_MAX_ITEMS 128
  4592. #endif
  4593. #if !defined(RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE)
  4594. #define RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE 1024
  4595. #endif
  4596. static const char *result[RAYGUI_TEXTSPLIT_MAX_ITEMS] = { NULL };
  4597. static char buffer[RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE] = { 0 };
  4598. memset(buffer, 0, RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE);
  4599. result[0] = buffer;
  4600. int counter = 0;
  4601. if (text != NULL)
  4602. {
  4603. counter = 1;
  4604. // Count how many substrings we have on text and point to every one
  4605. for (int i = 0; i < RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE; i++)
  4606. {
  4607. buffer[i] = text[i];
  4608. if (buffer[i] == '\0') break;
  4609. else if (buffer[i] == delimiter)
  4610. {
  4611. buffer[i] = '\0'; // Set an end of string at this point
  4612. result[counter] = buffer + i + 1;
  4613. counter++;
  4614. if (counter == RAYGUI_TEXTSPLIT_MAX_ITEMS) break;
  4615. }
  4616. }
  4617. }
  4618. *count = counter;
  4619. return result;
  4620. }
  4621. // Get integer value from text
  4622. // NOTE: This function replaces atoi() [stdlib.h]
  4623. static int TextToInteger(const char *text)
  4624. {
  4625. int value = 0;
  4626. int sign = 1;
  4627. if ((text[0] == '+') || (text[0] == '-'))
  4628. {
  4629. if (text[0] == '-') sign = -1;
  4630. text++;
  4631. }
  4632. for (int i = 0; ((text[i] >= '0') && (text[i] <= '9')); ++i) value = value*10 + (int)(text[i] - '0');
  4633. return value*sign;
  4634. }
  4635. // Encode codepoint into UTF-8 text (char array size returned as parameter)
  4636. static const char *CodepointToUTF8(int codepoint, int *byteSize)
  4637. {
  4638. static char utf8[6] = { 0 };
  4639. int size = 0;
  4640. if (codepoint <= 0x7f)
  4641. {
  4642. utf8[0] = (char)codepoint;
  4643. size = 1;
  4644. }
  4645. else if (codepoint <= 0x7ff)
  4646. {
  4647. utf8[0] = (char)(((codepoint >> 6) & 0x1f) | 0xc0);
  4648. utf8[1] = (char)((codepoint & 0x3f) | 0x80);
  4649. size = 2;
  4650. }
  4651. else if (codepoint <= 0xffff)
  4652. {
  4653. utf8[0] = (char)(((codepoint >> 12) & 0x0f) | 0xe0);
  4654. utf8[1] = (char)(((codepoint >> 6) & 0x3f) | 0x80);
  4655. utf8[2] = (char)((codepoint & 0x3f) | 0x80);
  4656. size = 3;
  4657. }
  4658. else if (codepoint <= 0x10ffff)
  4659. {
  4660. utf8[0] = (char)(((codepoint >> 18) & 0x07) | 0xf0);
  4661. utf8[1] = (char)(((codepoint >> 12) & 0x3f) | 0x80);
  4662. utf8[2] = (char)(((codepoint >> 6) & 0x3f) | 0x80);
  4663. utf8[3] = (char)((codepoint & 0x3f) | 0x80);
  4664. size = 4;
  4665. }
  4666. *byteSize = size;
  4667. return utf8;
  4668. }
  4669. // Get next codepoint in a UTF-8 encoded text, scanning until '\0' is found
  4670. // When a invalid UTF-8 byte is encountered we exit as soon as possible and a '?'(0x3f) codepoint is returned
  4671. // Total number of bytes processed are returned as a parameter
  4672. // NOTE: the standard says U+FFFD should be returned in case of errors
  4673. // but that character is not supported by the default font in raylib
  4674. static int GetCodepointNext(const char *text, int *codepointSize)
  4675. {
  4676. const char *ptr = text;
  4677. int codepoint = 0x3f; // Codepoint (defaults to '?')
  4678. *codepointSize = 1;
  4679. // Get current codepoint and bytes processed
  4680. if (0xf0 == (0xf8 & ptr[0]))
  4681. {
  4682. // 4 byte UTF-8 codepoint
  4683. if(((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80) || ((ptr[3] & 0xC0) ^ 0x80)) { return codepoint; } //10xxxxxx checks
  4684. codepoint = ((0x07 & ptr[0]) << 18) | ((0x3f & ptr[1]) << 12) | ((0x3f & ptr[2]) << 6) | (0x3f & ptr[3]);
  4685. *codepointSize = 4;
  4686. }
  4687. else if (0xe0 == (0xf0 & ptr[0]))
  4688. {
  4689. // 3 byte UTF-8 codepoint */
  4690. if(((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80)) { return codepoint; } //10xxxxxx checks
  4691. codepoint = ((0x0f & ptr[0]) << 12) | ((0x3f & ptr[1]) << 6) | (0x3f & ptr[2]);
  4692. *codepointSize = 3;
  4693. }
  4694. else if (0xc0 == (0xe0 & ptr[0]))
  4695. {
  4696. // 2 byte UTF-8 codepoint
  4697. if((ptr[1] & 0xC0) ^ 0x80) { return codepoint; } //10xxxxxx checks
  4698. codepoint = ((0x1f & ptr[0]) << 6) | (0x3f & ptr[1]);
  4699. *codepointSize = 2;
  4700. }
  4701. else if (0x00 == (0x80 & ptr[0]))
  4702. {
  4703. // 1 byte UTF-8 codepoint
  4704. codepoint = ptr[0];
  4705. *codepointSize = 1;
  4706. }
  4707. return codepoint;
  4708. }
  4709. #endif // RAYGUI_STANDALONE
  4710. #endif // RAYGUI_IMPLEMENTATION