raygui.h 262 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525
  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 4.6-dev 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 codepoint = 0;
  2302. int codepointSize = 0;
  2303. int codepointIndex = 0;
  2304. float glyphWidth = 0.0f;
  2305. float widthToMouseX = 0;
  2306. int mouseCursorIndex = 0;
  2307. for (int i = textIndexOffset; i < textLength; i++)
  2308. {
  2309. codepoint = GetCodepointNext(&text[i], &codepointSize);
  2310. codepointIndex = GetGlyphIndex(guiFont, codepoint);
  2311. if (guiFont.glyphs[codepointIndex].advanceX == 0) glyphWidth = ((float)guiFont.recs[codepointIndex].width*scaleFactor);
  2312. else glyphWidth = ((float)guiFont.glyphs[codepointIndex].advanceX*scaleFactor);
  2313. if (mousePosition.x <= (textBounds.x + (widthToMouseX + glyphWidth/2)))
  2314. {
  2315. mouseCursor.x = textBounds.x + widthToMouseX;
  2316. mouseCursorIndex = i;
  2317. break;
  2318. }
  2319. widthToMouseX += (glyphWidth + (float)GuiGetStyle(DEFAULT, TEXT_SPACING));
  2320. }
  2321. // Check if mouse cursor is at the last position
  2322. int textEndWidth = GetTextWidth(text + textIndexOffset);
  2323. if (GetMousePosition().x >= (textBounds.x + textEndWidth - glyphWidth/2))
  2324. {
  2325. mouseCursor.x = textBounds.x + textEndWidth;
  2326. mouseCursorIndex = strlen(text);
  2327. }
  2328. // Place cursor at required index on mouse click
  2329. if ((mouseCursor.x >= 0) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
  2330. {
  2331. cursor.x = mouseCursor.x;
  2332. textBoxCursorIndex = mouseCursorIndex;
  2333. }
  2334. }
  2335. else mouseCursor.x = -1;
  2336. // Recalculate cursor position.y depending on textBoxCursorIndex
  2337. cursor.x = bounds.x + GuiGetStyle(TEXTBOX, TEXT_PADDING) + GetTextWidth(text + textIndexOffset) - GetTextWidth(text + textBoxCursorIndex) + GuiGetStyle(DEFAULT, TEXT_SPACING);
  2338. //if (multiline) cursor.y = GetTextLines()
  2339. // Finish text editing on ENTER or mouse click outside bounds
  2340. if ((!multiline && IsKeyPressed(KEY_ENTER)) ||
  2341. (!CheckCollisionPointRec(mousePosition, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)))
  2342. {
  2343. textBoxCursorIndex = 0; // GLOBAL: Reset the shared cursor index
  2344. result = 1;
  2345. }
  2346. }
  2347. else
  2348. {
  2349. if (CheckCollisionPointRec(mousePosition, bounds))
  2350. {
  2351. state = STATE_FOCUSED;
  2352. if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
  2353. {
  2354. textBoxCursorIndex = (int)strlen(text); // GLOBAL: Place cursor index to the end of current text
  2355. result = 1;
  2356. }
  2357. }
  2358. }
  2359. }
  2360. //--------------------------------------------------------------------
  2361. // Draw control
  2362. //--------------------------------------------------------------------
  2363. if (state == STATE_PRESSED)
  2364. {
  2365. GuiDrawRectangle(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), GetColor(GuiGetStyle(TEXTBOX, BORDER + (state*3))), GetColor(GuiGetStyle(TEXTBOX, BASE_COLOR_PRESSED)));
  2366. }
  2367. else if (state == STATE_DISABLED)
  2368. {
  2369. GuiDrawRectangle(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), GetColor(GuiGetStyle(TEXTBOX, BORDER + (state*3))), GetColor(GuiGetStyle(TEXTBOX, BASE_COLOR_DISABLED)));
  2370. }
  2371. else GuiDrawRectangle(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), GetColor(GuiGetStyle(TEXTBOX, BORDER + (state*3))), BLANK);
  2372. // Draw text considering index offset if required
  2373. // NOTE: Text index offset depends on cursor position
  2374. GuiDrawText(text + textIndexOffset, textBounds, GuiGetStyle(TEXTBOX, TEXT_ALIGNMENT), GetColor(GuiGetStyle(TEXTBOX, TEXT + (state*3))));
  2375. // Draw cursor
  2376. if (editMode && !GuiGetStyle(TEXTBOX, TEXT_READONLY))
  2377. {
  2378. //if (autoCursorMode || ((blinkCursorFrameCounter/40)%2 == 0))
  2379. GuiDrawRectangle(cursor, 0, BLANK, GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_PRESSED)));
  2380. // Draw mouse position cursor (if required)
  2381. if (mouseCursor.x >= 0) GuiDrawRectangle(mouseCursor, 0, BLANK, GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_PRESSED)));
  2382. }
  2383. else if (state == STATE_FOCUSED) GuiTooltip(bounds);
  2384. //--------------------------------------------------------------------
  2385. return result; // Mouse button pressed: result = 1
  2386. }
  2387. /*
  2388. // Text Box control with multiple lines and word-wrap
  2389. // NOTE: This text-box is readonly, no editing supported by default
  2390. bool GuiTextBoxMulti(Rectangle bounds, char *text, int bufferSize, bool editMode)
  2391. {
  2392. bool pressed = false;
  2393. GuiSetStyle(TEXTBOX, TEXT_READONLY, 1);
  2394. GuiSetStyle(DEFAULT, TEXT_WRAP_MODE, TEXT_WRAP_WORD); // WARNING: If wrap mode enabled, text editing is not supported
  2395. GuiSetStyle(DEFAULT, TEXT_ALIGNMENT_VERTICAL, TEXT_ALIGN_TOP);
  2396. // TODO: Implement methods to calculate cursor position properly
  2397. pressed = GuiTextBox(bounds, text, bufferSize, editMode);
  2398. GuiSetStyle(DEFAULT, TEXT_ALIGNMENT_VERTICAL, TEXT_ALIGN_MIDDLE);
  2399. GuiSetStyle(DEFAULT, TEXT_WRAP_MODE, TEXT_WRAP_NONE);
  2400. GuiSetStyle(TEXTBOX, TEXT_READONLY, 0);
  2401. return pressed;
  2402. }
  2403. */
  2404. // Spinner control, returns selected value
  2405. int GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode)
  2406. {
  2407. int result = 1;
  2408. GuiState state = guiState;
  2409. int tempValue = *value;
  2410. Rectangle spinner = { bounds.x + GuiGetStyle(SPINNER, SPIN_BUTTON_WIDTH) + GuiGetStyle(SPINNER, SPIN_BUTTON_SPACING), bounds.y,
  2411. bounds.width - 2*(GuiGetStyle(SPINNER, SPIN_BUTTON_WIDTH) + GuiGetStyle(SPINNER, SPIN_BUTTON_SPACING)), bounds.height };
  2412. Rectangle leftButtonBound = { (float)bounds.x, (float)bounds.y, (float)GuiGetStyle(SPINNER, SPIN_BUTTON_WIDTH), (float)bounds.height };
  2413. Rectangle rightButtonBound = { (float)bounds.x + bounds.width - GuiGetStyle(SPINNER, SPIN_BUTTON_WIDTH), (float)bounds.y, (float)GuiGetStyle(SPINNER, SPIN_BUTTON_WIDTH), (float)bounds.height };
  2414. Rectangle textBounds = { 0 };
  2415. if (text != NULL)
  2416. {
  2417. textBounds.width = (float)GetTextWidth(text) + 2;
  2418. textBounds.height = (float)GuiGetStyle(DEFAULT, TEXT_SIZE);
  2419. textBounds.x = bounds.x + bounds.width + GuiGetStyle(SPINNER, TEXT_PADDING);
  2420. textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
  2421. if (GuiGetStyle(SPINNER, TEXT_ALIGNMENT) == TEXT_ALIGN_LEFT) textBounds.x = bounds.x - textBounds.width - GuiGetStyle(SPINNER, TEXT_PADDING);
  2422. }
  2423. // Update control
  2424. //--------------------------------------------------------------------
  2425. if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
  2426. {
  2427. Vector2 mousePoint = GetMousePosition();
  2428. // Check spinner state
  2429. if (CheckCollisionPointRec(mousePoint, bounds))
  2430. {
  2431. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
  2432. else state = STATE_FOCUSED;
  2433. }
  2434. }
  2435. #if defined(RAYGUI_NO_ICONS)
  2436. if (GuiButton(leftButtonBound, "<")) tempValue--;
  2437. if (GuiButton(rightButtonBound, ">")) tempValue++;
  2438. #else
  2439. if (GuiButton(leftButtonBound, GuiIconText(ICON_ARROW_LEFT_FILL, NULL))) tempValue--;
  2440. if (GuiButton(rightButtonBound, GuiIconText(ICON_ARROW_RIGHT_FILL, NULL))) tempValue++;
  2441. #endif
  2442. if (!editMode)
  2443. {
  2444. if (tempValue < minValue) tempValue = minValue;
  2445. if (tempValue > maxValue) tempValue = maxValue;
  2446. }
  2447. //--------------------------------------------------------------------
  2448. // Draw control
  2449. //--------------------------------------------------------------------
  2450. result = GuiValueBox(spinner, NULL, &tempValue, minValue, maxValue, editMode);
  2451. // Draw value selector custom buttons
  2452. // NOTE: BORDER_WIDTH and TEXT_ALIGNMENT forced values
  2453. int tempBorderWidth = GuiGetStyle(BUTTON, BORDER_WIDTH);
  2454. int tempTextAlign = GuiGetStyle(BUTTON, TEXT_ALIGNMENT);
  2455. GuiSetStyle(BUTTON, BORDER_WIDTH, GuiGetStyle(SPINNER, BORDER_WIDTH));
  2456. GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
  2457. GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlign);
  2458. GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth);
  2459. // Draw text label if provided
  2460. GuiDrawText(text, textBounds, (GuiGetStyle(SPINNER, TEXT_ALIGNMENT) == TEXT_ALIGN_RIGHT)? TEXT_ALIGN_LEFT : TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(LABEL, TEXT + (state*3))));
  2461. //--------------------------------------------------------------------
  2462. *value = tempValue;
  2463. return result;
  2464. }
  2465. // Value Box control, updates input text with numbers
  2466. // NOTE: Requires static variables: frameCounter
  2467. int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode)
  2468. {
  2469. #if !defined(RAYGUI_VALUEBOX_MAX_CHARS)
  2470. #define RAYGUI_VALUEBOX_MAX_CHARS 32
  2471. #endif
  2472. int result = 0;
  2473. GuiState state = guiState;
  2474. char textValue[RAYGUI_VALUEBOX_MAX_CHARS + 1] = "\0";
  2475. sprintf(textValue, "%i", *value);
  2476. Rectangle textBounds = { 0 };
  2477. if (text != NULL)
  2478. {
  2479. textBounds.width = (float)GetTextWidth(text) + 2;
  2480. textBounds.height = (float)GuiGetStyle(DEFAULT, TEXT_SIZE);
  2481. textBounds.x = bounds.x + bounds.width + GuiGetStyle(VALUEBOX, TEXT_PADDING);
  2482. textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
  2483. if (GuiGetStyle(VALUEBOX, TEXT_ALIGNMENT) == TEXT_ALIGN_LEFT) textBounds.x = bounds.x - textBounds.width - GuiGetStyle(VALUEBOX, TEXT_PADDING);
  2484. }
  2485. // Update control
  2486. //--------------------------------------------------------------------
  2487. if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
  2488. {
  2489. Vector2 mousePoint = GetMousePosition();
  2490. bool valueHasChanged = false;
  2491. if (editMode)
  2492. {
  2493. state = STATE_PRESSED;
  2494. int keyCount = (int)strlen(textValue);
  2495. // Only allow keys in range [48..57]
  2496. if (keyCount < RAYGUI_VALUEBOX_MAX_CHARS)
  2497. {
  2498. if (GetTextWidth(textValue) < bounds.width)
  2499. {
  2500. int key = GetCharPressed();
  2501. if ((key >= 48) && (key <= 57))
  2502. {
  2503. textValue[keyCount] = (char)key;
  2504. keyCount++;
  2505. valueHasChanged = true;
  2506. }
  2507. }
  2508. }
  2509. // Delete text
  2510. if (keyCount > 0)
  2511. {
  2512. if (IsKeyPressed(KEY_BACKSPACE))
  2513. {
  2514. keyCount--;
  2515. textValue[keyCount] = '\0';
  2516. valueHasChanged = true;
  2517. }
  2518. }
  2519. if (valueHasChanged) *value = TextToInteger(textValue);
  2520. // NOTE: We are not clamp values until user input finishes
  2521. //if (*value > maxValue) *value = maxValue;
  2522. //else if (*value < minValue) *value = minValue;
  2523. if (IsKeyPressed(KEY_ENTER) || (!CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) result = 1;
  2524. }
  2525. else
  2526. {
  2527. if (*value > maxValue) *value = maxValue;
  2528. else if (*value < minValue) *value = minValue;
  2529. if (CheckCollisionPointRec(mousePoint, bounds))
  2530. {
  2531. state = STATE_FOCUSED;
  2532. if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) result = 1;
  2533. }
  2534. }
  2535. }
  2536. //--------------------------------------------------------------------
  2537. // Draw control
  2538. //--------------------------------------------------------------------
  2539. Color baseColor = BLANK;
  2540. if (state == STATE_PRESSED) baseColor = GetColor(GuiGetStyle(VALUEBOX, BASE_COLOR_PRESSED));
  2541. else if (state == STATE_DISABLED) baseColor = GetColor(GuiGetStyle(VALUEBOX, BASE_COLOR_DISABLED));
  2542. GuiDrawRectangle(bounds, GuiGetStyle(VALUEBOX, BORDER_WIDTH), GetColor(GuiGetStyle(VALUEBOX, BORDER + (state*3))), baseColor);
  2543. GuiDrawText(textValue, GetTextBounds(VALUEBOX, bounds), TEXT_ALIGN_CENTER, GetColor(GuiGetStyle(VALUEBOX, TEXT + (state*3))));
  2544. // Draw cursor
  2545. if (editMode)
  2546. {
  2547. // NOTE: ValueBox internal text is always centered
  2548. 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) };
  2549. GuiDrawRectangle(cursor, 0, BLANK, GetColor(GuiGetStyle(VALUEBOX, BORDER_COLOR_PRESSED)));
  2550. }
  2551. // Draw text label if provided
  2552. GuiDrawText(text, textBounds, (GuiGetStyle(VALUEBOX, TEXT_ALIGNMENT) == TEXT_ALIGN_RIGHT)? TEXT_ALIGN_LEFT : TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(LABEL, TEXT + (state*3))));
  2553. //--------------------------------------------------------------------
  2554. return result;
  2555. }
  2556. // Slider control with pro parameters
  2557. // NOTE: Other GuiSlider*() controls use this one
  2558. int GuiSliderPro(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue, int sliderWidth)
  2559. {
  2560. int result = 0;
  2561. GuiState state = guiState;
  2562. float temp = (maxValue - minValue)/2.0f;
  2563. if (value == NULL) value = &temp;
  2564. int sliderValue = (int)(((*value - minValue)/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH)));
  2565. Rectangle slider = { bounds.x, bounds.y + GuiGetStyle(SLIDER, BORDER_WIDTH) + GuiGetStyle(SLIDER, SLIDER_PADDING),
  2566. 0, bounds.height - 2*GuiGetStyle(SLIDER, BORDER_WIDTH) - 2*GuiGetStyle(SLIDER, SLIDER_PADDING) };
  2567. if (sliderWidth > 0) // Slider
  2568. {
  2569. slider.x += (sliderValue - sliderWidth/2);
  2570. slider.width = (float)sliderWidth;
  2571. }
  2572. else if (sliderWidth == 0) // SliderBar
  2573. {
  2574. slider.x += GuiGetStyle(SLIDER, BORDER_WIDTH);
  2575. slider.width = (float)sliderValue;
  2576. }
  2577. // Update control
  2578. //--------------------------------------------------------------------
  2579. if ((state != STATE_DISABLED) && !guiLocked)
  2580. {
  2581. Vector2 mousePoint = GetMousePosition();
  2582. if (guiSliderDragging) // Keep dragging outside of bounds
  2583. {
  2584. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  2585. {
  2586. if (CHECK_BOUNDS_ID(bounds, guiSliderActive))
  2587. {
  2588. state = STATE_PRESSED;
  2589. // Get equivalent value and slider position from mousePosition.x
  2590. *value = ((maxValue - minValue)*(mousePoint.x - (float)(bounds.x + sliderWidth/2)))/(float)(bounds.width - sliderWidth) + minValue;
  2591. }
  2592. }
  2593. else
  2594. {
  2595. guiSliderDragging = false;
  2596. guiSliderActive = RAYGUI_CLITERAL(Rectangle){ 0, 0, 0, 0 };
  2597. }
  2598. }
  2599. else if (CheckCollisionPointRec(mousePoint, bounds))
  2600. {
  2601. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  2602. {
  2603. state = STATE_PRESSED;
  2604. guiSliderDragging = true;
  2605. guiSliderActive = bounds; // Store bounds as an identifier when dragging starts
  2606. if (!CheckCollisionPointRec(mousePoint, slider))
  2607. {
  2608. // Get equivalent value and slider position from mousePosition.x
  2609. *value = ((maxValue - minValue)*(mousePoint.x - (float)(bounds.x + sliderWidth/2)))/(float)(bounds.width - sliderWidth) + minValue;
  2610. if (sliderWidth > 0) slider.x = mousePoint.x - slider.width/2; // Slider
  2611. else if (sliderWidth == 0) slider.width = (float)sliderValue; // SliderBar
  2612. }
  2613. }
  2614. else state = STATE_FOCUSED;
  2615. }
  2616. if (*value > maxValue) *value = maxValue;
  2617. else if (*value < minValue) *value = minValue;
  2618. }
  2619. // Bar limits check
  2620. if (sliderWidth > 0) // Slider
  2621. {
  2622. if (slider.x <= (bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH))) slider.x = bounds.x + GuiGetStyle(SLIDER, BORDER_WIDTH);
  2623. else if ((slider.x + slider.width) >= (bounds.x + bounds.width)) slider.x = bounds.x + bounds.width - slider.width - GuiGetStyle(SLIDER, BORDER_WIDTH);
  2624. }
  2625. else if (sliderWidth == 0) // SliderBar
  2626. {
  2627. if (slider.width > bounds.width) slider.width = bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH);
  2628. }
  2629. //--------------------------------------------------------------------
  2630. // Draw control
  2631. //--------------------------------------------------------------------
  2632. GuiDrawRectangle(bounds, GuiGetStyle(SLIDER, BORDER_WIDTH), GetColor(GuiGetStyle(SLIDER, BORDER + (state*3))), GetColor(GuiGetStyle(SLIDER, (state != STATE_DISABLED)? BASE_COLOR_NORMAL : BASE_COLOR_DISABLED)));
  2633. // Draw slider internal bar (depends on state)
  2634. if (state == STATE_NORMAL) GuiDrawRectangle(slider, 0, BLANK, GetColor(GuiGetStyle(SLIDER, BASE_COLOR_PRESSED)));
  2635. else if (state == STATE_FOCUSED) GuiDrawRectangle(slider, 0, BLANK, GetColor(GuiGetStyle(SLIDER, TEXT_COLOR_FOCUSED)));
  2636. else if (state == STATE_PRESSED) GuiDrawRectangle(slider, 0, BLANK, GetColor(GuiGetStyle(SLIDER, TEXT_COLOR_PRESSED)));
  2637. // Draw left/right text if provided
  2638. if (textLeft != NULL)
  2639. {
  2640. Rectangle textBounds = { 0 };
  2641. textBounds.width = (float)GetTextWidth(textLeft);
  2642. textBounds.height = (float)GuiGetStyle(DEFAULT, TEXT_SIZE);
  2643. textBounds.x = bounds.x - textBounds.width - GuiGetStyle(SLIDER, TEXT_PADDING);
  2644. textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
  2645. GuiDrawText(textLeft, textBounds, TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(SLIDER, TEXT + (state*3))));
  2646. }
  2647. if (textRight != NULL)
  2648. {
  2649. Rectangle textBounds = { 0 };
  2650. textBounds.width = (float)GetTextWidth(textRight);
  2651. textBounds.height = (float)GuiGetStyle(DEFAULT, TEXT_SIZE);
  2652. textBounds.x = bounds.x + bounds.width + GuiGetStyle(SLIDER, TEXT_PADDING);
  2653. textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
  2654. GuiDrawText(textRight, textBounds, TEXT_ALIGN_LEFT, GetColor(GuiGetStyle(SLIDER, TEXT + (state*3))));
  2655. }
  2656. //--------------------------------------------------------------------
  2657. return result;
  2658. }
  2659. // Slider control extended, returns selected value and has text
  2660. int GuiSlider(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue)
  2661. {
  2662. return GuiSliderPro(bounds, textLeft, textRight, value, minValue, maxValue, GuiGetStyle(SLIDER, SLIDER_WIDTH));
  2663. }
  2664. // Slider Bar control extended, returns selected value
  2665. int GuiSliderBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue)
  2666. {
  2667. return GuiSliderPro(bounds, textLeft, textRight, value, minValue, maxValue, 0);
  2668. }
  2669. // Progress Bar control extended, shows current progress value
  2670. int GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue)
  2671. {
  2672. int result = 0;
  2673. GuiState state = guiState;
  2674. float temp = (maxValue - minValue)/2.0f;
  2675. if (value == NULL) value = &temp;
  2676. // Progress bar
  2677. Rectangle progress = { bounds.x + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH),
  2678. bounds.y + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) + GuiGetStyle(PROGRESSBAR, PROGRESS_PADDING), 0,
  2679. bounds.height - 2*GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) - 2*GuiGetStyle(PROGRESSBAR, PROGRESS_PADDING) };
  2680. // Update control
  2681. //--------------------------------------------------------------------
  2682. if (*value > maxValue) *value = maxValue;
  2683. // WARNING: Working with floats could lead to rounding issues
  2684. if ((state != STATE_DISABLED)) progress.width = (float)(*value/(maxValue - minValue))*bounds.width - ((*value >= maxValue) ? (float)(2*GuiGetStyle(PROGRESSBAR, BORDER_WIDTH)) : 0.0f);
  2685. //--------------------------------------------------------------------
  2686. // Draw control
  2687. //--------------------------------------------------------------------
  2688. if (state == STATE_DISABLED)
  2689. {
  2690. GuiDrawRectangle(bounds, GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), GetColor(GuiGetStyle(PROGRESSBAR, BORDER + (state*3))), BLANK);
  2691. }
  2692. else
  2693. {
  2694. if (*value > minValue)
  2695. {
  2696. // Draw progress bar with colored border, more visual
  2697. 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)));
  2698. 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)));
  2699. 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)));
  2700. }
  2701. else GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x, bounds.y, (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), bounds.height }, 0, BLANK, GetColor(GuiGetStyle(PROGRESSBAR, BORDER_COLOR_NORMAL)));
  2702. 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)));
  2703. else
  2704. {
  2705. // Draw borders not yet reached by value
  2706. 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)));
  2707. 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)));
  2708. 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)));
  2709. }
  2710. // Draw slider internal progress bar (depends on state)
  2711. GuiDrawRectangle(progress, 0, BLANK, GetColor(GuiGetStyle(PROGRESSBAR, BASE_COLOR_PRESSED)));
  2712. }
  2713. // Draw left/right text if provided
  2714. if (textLeft != NULL)
  2715. {
  2716. Rectangle textBounds = { 0 };
  2717. textBounds.width = (float)GetTextWidth(textLeft);
  2718. textBounds.height = (float)GuiGetStyle(DEFAULT, TEXT_SIZE);
  2719. textBounds.x = bounds.x - textBounds.width - GuiGetStyle(PROGRESSBAR, TEXT_PADDING);
  2720. textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
  2721. GuiDrawText(textLeft, textBounds, TEXT_ALIGN_RIGHT, GetColor(GuiGetStyle(PROGRESSBAR, TEXT + (state*3))));
  2722. }
  2723. if (textRight != NULL)
  2724. {
  2725. Rectangle textBounds = { 0 };
  2726. textBounds.width = (float)GetTextWidth(textRight);
  2727. textBounds.height = (float)GuiGetStyle(DEFAULT, TEXT_SIZE);
  2728. textBounds.x = bounds.x + bounds.width + GuiGetStyle(PROGRESSBAR, TEXT_PADDING);
  2729. textBounds.y = bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)/2;
  2730. GuiDrawText(textRight, textBounds, TEXT_ALIGN_LEFT, GetColor(GuiGetStyle(PROGRESSBAR, TEXT + (state*3))));
  2731. }
  2732. //--------------------------------------------------------------------
  2733. return result;
  2734. }
  2735. // Status Bar control
  2736. int GuiStatusBar(Rectangle bounds, const char *text)
  2737. {
  2738. int result = 0;
  2739. GuiState state = guiState;
  2740. // Draw control
  2741. //--------------------------------------------------------------------
  2742. GuiDrawRectangle(bounds, GuiGetStyle(STATUSBAR, BORDER_WIDTH), GetColor(GuiGetStyle(STATUSBAR, BORDER + (state*3))), GetColor(GuiGetStyle(STATUSBAR, BASE + (state*3))));
  2743. GuiDrawText(text, GetTextBounds(STATUSBAR, bounds), GuiGetStyle(STATUSBAR, TEXT_ALIGNMENT), GetColor(GuiGetStyle(STATUSBAR, TEXT + (state*3))));
  2744. //--------------------------------------------------------------------
  2745. return result;
  2746. }
  2747. // Dummy rectangle control, intended for placeholding
  2748. int GuiDummyRec(Rectangle bounds, const char *text)
  2749. {
  2750. int result = 0;
  2751. GuiState state = guiState;
  2752. // Update control
  2753. //--------------------------------------------------------------------
  2754. if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
  2755. {
  2756. Vector2 mousePoint = GetMousePosition();
  2757. // Check button state
  2758. if (CheckCollisionPointRec(mousePoint, bounds))
  2759. {
  2760. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
  2761. else state = STATE_FOCUSED;
  2762. }
  2763. }
  2764. //--------------------------------------------------------------------
  2765. // Draw control
  2766. //--------------------------------------------------------------------
  2767. GuiDrawRectangle(bounds, 0, BLANK, GetColor(GuiGetStyle(DEFAULT, (state != STATE_DISABLED)? BASE_COLOR_NORMAL : BASE_COLOR_DISABLED)));
  2768. GuiDrawText(text, GetTextBounds(DEFAULT, bounds), TEXT_ALIGN_CENTER, GetColor(GuiGetStyle(BUTTON, (state != STATE_DISABLED)? TEXT_COLOR_NORMAL : TEXT_COLOR_DISABLED)));
  2769. //------------------------------------------------------------------
  2770. return result;
  2771. }
  2772. // List View control
  2773. int GuiListView(Rectangle bounds, const char *text, int *scrollIndex, int *active)
  2774. {
  2775. int result = 0;
  2776. int itemCount = 0;
  2777. const char **items = NULL;
  2778. if (text != NULL) items = GuiTextSplit(text, ';', &itemCount, NULL);
  2779. result = GuiListViewEx(bounds, items, itemCount, scrollIndex, active, NULL);
  2780. return result;
  2781. }
  2782. // List View control with extended parameters
  2783. int GuiListViewEx(Rectangle bounds, const char **text, int count, int *scrollIndex, int *active, int *focus)
  2784. {
  2785. int result = 0;
  2786. GuiState state = guiState;
  2787. int itemFocused = (focus == NULL)? -1 : *focus;
  2788. int itemSelected = (active == NULL)? -1 : *active;
  2789. // Check if we need a scroll bar
  2790. bool useScrollBar = false;
  2791. if ((GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) + GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING))*count > bounds.height) useScrollBar = true;
  2792. // Define base item rectangle [0]
  2793. Rectangle itemBounds = { 0 };
  2794. itemBounds.x = bounds.x + GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING);
  2795. itemBounds.y = bounds.y + GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING) + GuiGetStyle(DEFAULT, BORDER_WIDTH);
  2796. itemBounds.width = bounds.width - 2*GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING) - GuiGetStyle(DEFAULT, BORDER_WIDTH);
  2797. itemBounds.height = (float)GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT);
  2798. if (useScrollBar) itemBounds.width -= GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH);
  2799. // Get items on the list
  2800. int visibleItems = (int)bounds.height/(GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) + GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING));
  2801. if (visibleItems > count) visibleItems = count;
  2802. int startIndex = (scrollIndex == NULL)? 0 : *scrollIndex;
  2803. if ((startIndex < 0) || (startIndex > (count - visibleItems))) startIndex = 0;
  2804. int endIndex = startIndex + visibleItems;
  2805. // Update control
  2806. //--------------------------------------------------------------------
  2807. if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
  2808. {
  2809. Vector2 mousePoint = GetMousePosition();
  2810. // Check mouse inside list view
  2811. if (CheckCollisionPointRec(mousePoint, bounds))
  2812. {
  2813. state = STATE_FOCUSED;
  2814. // Check focused and selected item
  2815. for (int i = 0; i < visibleItems; i++)
  2816. {
  2817. if (CheckCollisionPointRec(mousePoint, itemBounds))
  2818. {
  2819. itemFocused = startIndex + i;
  2820. if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
  2821. {
  2822. if (itemSelected == (startIndex + i)) itemSelected = -1;
  2823. else itemSelected = startIndex + i;
  2824. }
  2825. break;
  2826. }
  2827. // Update item rectangle y position for next item
  2828. itemBounds.y += (GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) + GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING));
  2829. }
  2830. if (useScrollBar)
  2831. {
  2832. int wheelMove = (int)GetMouseWheelMove();
  2833. startIndex -= wheelMove;
  2834. if (startIndex < 0) startIndex = 0;
  2835. else if (startIndex > (count - visibleItems)) startIndex = count - visibleItems;
  2836. endIndex = startIndex + visibleItems;
  2837. if (endIndex > count) endIndex = count;
  2838. }
  2839. }
  2840. else itemFocused = -1;
  2841. // Reset item rectangle y to [0]
  2842. itemBounds.y = bounds.y + GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING) + GuiGetStyle(DEFAULT, BORDER_WIDTH);
  2843. }
  2844. //--------------------------------------------------------------------
  2845. // Draw control
  2846. //--------------------------------------------------------------------
  2847. GuiDrawRectangle(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), GetColor(GuiGetStyle(LISTVIEW, BORDER + state*3)), GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR))); // Draw background
  2848. // Draw visible items
  2849. for (int i = 0; ((i < visibleItems) && (text != NULL)); i++)
  2850. {
  2851. if (state == STATE_DISABLED)
  2852. {
  2853. if ((startIndex + i) == itemSelected) GuiDrawRectangle(itemBounds, GuiGetStyle(LISTVIEW, BORDER_WIDTH), GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_DISABLED)), GetColor(GuiGetStyle(LISTVIEW, BASE_COLOR_DISABLED)));
  2854. GuiDrawText(text[startIndex + i], GetTextBounds(DEFAULT, itemBounds), GuiGetStyle(LISTVIEW, TEXT_ALIGNMENT), GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_DISABLED)));
  2855. }
  2856. else
  2857. {
  2858. if (((startIndex + i) == itemSelected) && (active != NULL))
  2859. {
  2860. // Draw item selected
  2861. GuiDrawRectangle(itemBounds, GuiGetStyle(LISTVIEW, BORDER_WIDTH), GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_PRESSED)), GetColor(GuiGetStyle(LISTVIEW, BASE_COLOR_PRESSED)));
  2862. GuiDrawText(text[startIndex + i], GetTextBounds(DEFAULT, itemBounds), GuiGetStyle(LISTVIEW, TEXT_ALIGNMENT), GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_PRESSED)));
  2863. }
  2864. else if (((startIndex + i) == itemFocused)) // && (focus != NULL)) // NOTE: We want items focused, despite not returned!
  2865. {
  2866. // Draw item focused
  2867. GuiDrawRectangle(itemBounds, GuiGetStyle(LISTVIEW, BORDER_WIDTH), GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_FOCUSED)), GetColor(GuiGetStyle(LISTVIEW, BASE_COLOR_FOCUSED)));
  2868. GuiDrawText(text[startIndex + i], GetTextBounds(DEFAULT, itemBounds), GuiGetStyle(LISTVIEW, TEXT_ALIGNMENT), GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_FOCUSED)));
  2869. }
  2870. else
  2871. {
  2872. // Draw item normal
  2873. GuiDrawText(text[startIndex + i], GetTextBounds(DEFAULT, itemBounds), GuiGetStyle(LISTVIEW, TEXT_ALIGNMENT), GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_NORMAL)));
  2874. }
  2875. }
  2876. // Update item rectangle y position for next item
  2877. itemBounds.y += (GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) + GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING));
  2878. }
  2879. if (useScrollBar)
  2880. {
  2881. Rectangle scrollBarBounds = {
  2882. bounds.x + bounds.width - GuiGetStyle(LISTVIEW, BORDER_WIDTH) - GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH),
  2883. bounds.y + GuiGetStyle(LISTVIEW, BORDER_WIDTH), (float)GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH),
  2884. bounds.height - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH)
  2885. };
  2886. // Calculate percentage of visible items and apply same percentage to scrollbar
  2887. float percentVisible = (float)(endIndex - startIndex)/count;
  2888. float sliderSize = bounds.height*percentVisible;
  2889. int prevSliderSize = GuiGetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE); // Save default slider size
  2890. int prevScrollSpeed = GuiGetStyle(SCROLLBAR, SCROLL_SPEED); // Save default scroll speed
  2891. GuiSetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE, (int)sliderSize); // Change slider size
  2892. GuiSetStyle(SCROLLBAR, SCROLL_SPEED, count - visibleItems); // Change scroll speed
  2893. startIndex = GuiScrollBar(scrollBarBounds, startIndex, 0, count - visibleItems);
  2894. GuiSetStyle(SCROLLBAR, SCROLL_SPEED, prevScrollSpeed); // Reset scroll speed to default
  2895. GuiSetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE, prevSliderSize); // Reset slider size to default
  2896. }
  2897. //--------------------------------------------------------------------
  2898. if (active != NULL) *active = itemSelected;
  2899. if (focus != NULL) *focus = itemFocused;
  2900. if (scrollIndex != NULL) *scrollIndex = startIndex;
  2901. return result;
  2902. }
  2903. // Color Panel control
  2904. int GuiColorPanel(Rectangle bounds, const char *text, Color *color)
  2905. {
  2906. int result = 0;
  2907. GuiState state = guiState;
  2908. Vector2 pickerSelector = { 0 };
  2909. const Color colWhite = { 255, 255, 255, 255 };
  2910. const Color colBlack = { 0, 0, 0, 255 };
  2911. Vector3 vcolor = { (float)color->r/255.0f, (float)color->g/255.0f, (float)color->b/255.0f };
  2912. Vector3 hsv = ConvertRGBtoHSV(vcolor);
  2913. pickerSelector.x = bounds.x + (float)hsv.y*bounds.width; // HSV: Saturation
  2914. pickerSelector.y = bounds.y + (1.0f - (float)hsv.z)*bounds.height; // HSV: Value
  2915. float hue = -1.0f;
  2916. Vector3 maxHue = { hue >= 0.0f ? hue : hsv.x, 1.0f, 1.0f };
  2917. Vector3 rgbHue = ConvertHSVtoRGB(maxHue);
  2918. Color maxHueCol = { (unsigned char)(255.0f*rgbHue.x),
  2919. (unsigned char)(255.0f*rgbHue.y),
  2920. (unsigned char)(255.0f*rgbHue.z), 255 };
  2921. // Update control
  2922. //--------------------------------------------------------------------
  2923. if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
  2924. {
  2925. Vector2 mousePoint = GetMousePosition();
  2926. if (CheckCollisionPointRec(mousePoint, bounds))
  2927. {
  2928. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  2929. {
  2930. state = STATE_PRESSED;
  2931. pickerSelector = mousePoint;
  2932. // Calculate color from picker
  2933. Vector2 colorPick = { pickerSelector.x - bounds.x, pickerSelector.y - bounds.y };
  2934. colorPick.x /= (float)bounds.width; // Get normalized value on x
  2935. colorPick.y /= (float)bounds.height; // Get normalized value on y
  2936. hsv.y = colorPick.x;
  2937. hsv.z = 1.0f - colorPick.y;
  2938. Vector3 rgb = ConvertHSVtoRGB(hsv);
  2939. // NOTE: Vector3ToColor() only available on raylib 1.8.1
  2940. *color = RAYGUI_CLITERAL(Color){ (unsigned char)(255.0f*rgb.x),
  2941. (unsigned char)(255.0f*rgb.y),
  2942. (unsigned char)(255.0f*rgb.z),
  2943. (unsigned char)(255.0f*(float)color->a/255.0f) };
  2944. }
  2945. else state = STATE_FOCUSED;
  2946. }
  2947. }
  2948. //--------------------------------------------------------------------
  2949. // Draw control
  2950. //--------------------------------------------------------------------
  2951. if (state != STATE_DISABLED)
  2952. {
  2953. DrawRectangleGradientEx(bounds, Fade(colWhite, guiAlpha), Fade(colWhite, guiAlpha), Fade(maxHueCol, guiAlpha), Fade(maxHueCol, guiAlpha));
  2954. DrawRectangleGradientEx(bounds, Fade(colBlack, 0), Fade(colBlack, guiAlpha), Fade(colBlack, guiAlpha), Fade(colBlack, 0));
  2955. // Draw color picker: selector
  2956. 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) };
  2957. GuiDrawRectangle(selector, 0, BLANK, colWhite);
  2958. }
  2959. else
  2960. {
  2961. 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));
  2962. }
  2963. GuiDrawRectangle(bounds, GuiGetStyle(COLORPICKER, BORDER_WIDTH), GetColor(GuiGetStyle(COLORPICKER, BORDER + state*3)), BLANK);
  2964. //--------------------------------------------------------------------
  2965. return result;
  2966. }
  2967. // Color Bar Alpha control
  2968. // NOTE: Returns alpha value normalized [0..1]
  2969. int GuiColorBarAlpha(Rectangle bounds, const char *text, float *alpha)
  2970. {
  2971. #if !defined(RAYGUI_COLORBARALPHA_CHECKED_SIZE)
  2972. #define RAYGUI_COLORBARALPHA_CHECKED_SIZE 10
  2973. #endif
  2974. int result = 0;
  2975. GuiState state = guiState;
  2976. 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 };
  2977. // Update control
  2978. //--------------------------------------------------------------------
  2979. if ((state != STATE_DISABLED) && !guiLocked)
  2980. {
  2981. Vector2 mousePoint = GetMousePosition();
  2982. if (guiSliderDragging) // Keep dragging outside of bounds
  2983. {
  2984. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  2985. {
  2986. if (CHECK_BOUNDS_ID(bounds, guiSliderActive))
  2987. {
  2988. state = STATE_PRESSED;
  2989. *alpha = (mousePoint.x - bounds.x)/bounds.width;
  2990. if (*alpha <= 0.0f) *alpha = 0.0f;
  2991. if (*alpha >= 1.0f) *alpha = 1.0f;
  2992. }
  2993. }
  2994. else
  2995. {
  2996. guiSliderDragging = false;
  2997. guiSliderActive = RAYGUI_CLITERAL(Rectangle){ 0, 0, 0, 0 };
  2998. }
  2999. }
  3000. else if (CheckCollisionPointRec(mousePoint, bounds) || CheckCollisionPointRec(mousePoint, selector))
  3001. {
  3002. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  3003. {
  3004. state = STATE_PRESSED;
  3005. guiSliderDragging = true;
  3006. guiSliderActive = bounds; // Store bounds as an identifier when dragging starts
  3007. *alpha = (mousePoint.x - bounds.x)/bounds.width;
  3008. if (*alpha <= 0.0f) *alpha = 0.0f;
  3009. if (*alpha >= 1.0f) *alpha = 1.0f;
  3010. //selector.x = bounds.x + (int)(((alpha - 0)/(100 - 0))*(bounds.width - 2*GuiGetStyle(SLIDER, BORDER_WIDTH))) - selector.width/2;
  3011. }
  3012. else state = STATE_FOCUSED;
  3013. }
  3014. }
  3015. //--------------------------------------------------------------------
  3016. // Draw control
  3017. //--------------------------------------------------------------------
  3018. // Draw alpha bar: checked background
  3019. if (state != STATE_DISABLED)
  3020. {
  3021. int checksX = (int)bounds.width/RAYGUI_COLORBARALPHA_CHECKED_SIZE;
  3022. int checksY = (int)bounds.height/RAYGUI_COLORBARALPHA_CHECKED_SIZE;
  3023. for (int x = 0; x < checksX; x++)
  3024. {
  3025. for (int y = 0; y < checksY; y++)
  3026. {
  3027. Rectangle check = { bounds.x + x*RAYGUI_COLORBARALPHA_CHECKED_SIZE, bounds.y + y*RAYGUI_COLORBARALPHA_CHECKED_SIZE, RAYGUI_COLORBARALPHA_CHECKED_SIZE, RAYGUI_COLORBARALPHA_CHECKED_SIZE };
  3028. 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));
  3029. }
  3030. }
  3031. 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));
  3032. }
  3033. 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));
  3034. GuiDrawRectangle(bounds, GuiGetStyle(COLORPICKER, BORDER_WIDTH), GetColor(GuiGetStyle(COLORPICKER, BORDER + state*3)), BLANK);
  3035. // Draw alpha bar: selector
  3036. GuiDrawRectangle(selector, 0, BLANK, GetColor(GuiGetStyle(COLORPICKER, BORDER + state*3)));
  3037. //--------------------------------------------------------------------
  3038. return result;
  3039. }
  3040. // Color Bar Hue control
  3041. // Returns hue value normalized [0..1]
  3042. // NOTE: Other similar bars (for reference):
  3043. // Color GuiColorBarSat() [WHITE->color]
  3044. // Color GuiColorBarValue() [BLACK->color], HSV/HSL
  3045. // float GuiColorBarLuminance() [BLACK->WHITE]
  3046. int GuiColorBarHue(Rectangle bounds, const char *text, float *hue)
  3047. {
  3048. int result = 0;
  3049. GuiState state = guiState;
  3050. 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) };
  3051. // Update control
  3052. //--------------------------------------------------------------------
  3053. if ((state != STATE_DISABLED) && !guiLocked)
  3054. {
  3055. Vector2 mousePoint = GetMousePosition();
  3056. if (guiSliderDragging) // Keep dragging outside of bounds
  3057. {
  3058. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  3059. {
  3060. if (CHECK_BOUNDS_ID(bounds, guiSliderActive))
  3061. {
  3062. state = STATE_PRESSED;
  3063. *hue = (mousePoint.y - bounds.y)*360/bounds.height;
  3064. if (*hue <= 0.0f) *hue = 0.0f;
  3065. if (*hue >= 359.0f) *hue = 359.0f;
  3066. }
  3067. }
  3068. else
  3069. {
  3070. guiSliderDragging = false;
  3071. guiSliderActive = RAYGUI_CLITERAL(Rectangle){ 0, 0, 0, 0 };
  3072. }
  3073. }
  3074. else if (CheckCollisionPointRec(mousePoint, bounds) || CheckCollisionPointRec(mousePoint, selector))
  3075. {
  3076. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  3077. {
  3078. state = STATE_PRESSED;
  3079. guiSliderDragging = true;
  3080. guiSliderActive = bounds; // Store bounds as an identifier when dragging starts
  3081. *hue = (mousePoint.y - bounds.y)*360/bounds.height;
  3082. if (*hue <= 0.0f) *hue = 0.0f;
  3083. if (*hue >= 359.0f) *hue = 359.0f;
  3084. }
  3085. else state = STATE_FOCUSED;
  3086. /*if (IsKeyDown(KEY_UP))
  3087. {
  3088. hue -= 2.0f;
  3089. if (hue <= 0.0f) hue = 0.0f;
  3090. }
  3091. else if (IsKeyDown(KEY_DOWN))
  3092. {
  3093. hue += 2.0f;
  3094. if (hue >= 360.0f) hue = 360.0f;
  3095. }*/
  3096. }
  3097. }
  3098. //--------------------------------------------------------------------
  3099. // Draw control
  3100. //--------------------------------------------------------------------
  3101. if (state != STATE_DISABLED)
  3102. {
  3103. // Draw hue bar:color bars
  3104. // TODO: Use directly DrawRectangleGradientEx(bounds, color1, color2, color2, color1);
  3105. 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));
  3106. 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));
  3107. 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));
  3108. 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));
  3109. 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));
  3110. 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));
  3111. }
  3112. 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));
  3113. GuiDrawRectangle(bounds, GuiGetStyle(COLORPICKER, BORDER_WIDTH), GetColor(GuiGetStyle(COLORPICKER, BORDER + state*3)), BLANK);
  3114. // Draw hue bar: selector
  3115. GuiDrawRectangle(selector, 0, BLANK, GetColor(GuiGetStyle(COLORPICKER, BORDER + state*3)));
  3116. //--------------------------------------------------------------------
  3117. return result;
  3118. }
  3119. // Color Picker control
  3120. // NOTE: It's divided in multiple controls:
  3121. // Color GuiColorPanel(Rectangle bounds, Color color)
  3122. // float GuiColorBarAlpha(Rectangle bounds, float alpha)
  3123. // float GuiColorBarHue(Rectangle bounds, float value)
  3124. // NOTE: bounds define GuiColorPanel() size
  3125. int GuiColorPicker(Rectangle bounds, const char *text, Color *color)
  3126. {
  3127. int result = 0;
  3128. Color temp = { 200, 0, 0, 255 };
  3129. if (color == NULL) color = &temp;
  3130. GuiColorPanel(bounds, NULL, color);
  3131. Rectangle boundsHue = { (float)bounds.x + bounds.width + GuiGetStyle(COLORPICKER, HUEBAR_PADDING), (float)bounds.y, (float)GuiGetStyle(COLORPICKER, HUEBAR_WIDTH), (float)bounds.height };
  3132. //Rectangle boundsAlpha = { bounds.x, bounds.y + bounds.height + GuiGetStyle(COLORPICKER, BARS_PADDING), bounds.width, GuiGetStyle(COLORPICKER, BARS_THICK) };
  3133. Vector3 hsv = ConvertRGBtoHSV(RAYGUI_CLITERAL(Vector3){ (*color).r/255.0f, (*color).g/255.0f, (*color).b/255.0f });
  3134. GuiColorBarHue(boundsHue, NULL, &hsv.x);
  3135. //color.a = (unsigned char)(GuiColorBarAlpha(boundsAlpha, (float)color.a/255.0f)*255.0f);
  3136. Vector3 rgb = ConvertHSVtoRGB(hsv);
  3137. *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 };
  3138. return result;
  3139. }
  3140. // Color Picker control that avoids conversion to RGB and back to HSV on each call, thus avoiding jittering.
  3141. // The user can call ConvertHSVtoRGB() to convert *colorHsv value to RGB.
  3142. // NOTE: It's divided in multiple controls:
  3143. // int GuiColorPanelHSV(Rectangle bounds, const char *text, Vector3 *colorHsv)
  3144. // int GuiColorBarAlpha(Rectangle bounds, const char *text, float *alpha)
  3145. // float GuiColorBarHue(Rectangle bounds, float value)
  3146. // NOTE: bounds define GuiColorPanelHSV() size
  3147. int GuiColorPickerHSV(Rectangle bounds, const char *text, Vector3 *colorHsv)
  3148. {
  3149. int result = 0;
  3150. Vector3 tempHsv = { 0 };
  3151. if (colorHsv == NULL)
  3152. {
  3153. const Vector3 tempColor = { 200.0f/255.0f, 0.0f, 0.0f };
  3154. tempHsv = ConvertRGBtoHSV(tempColor);
  3155. colorHsv = &tempHsv;
  3156. }
  3157. GuiColorPanelHSV(bounds, NULL, colorHsv);
  3158. const Rectangle boundsHue = { (float)bounds.x + bounds.width + GuiGetStyle(COLORPICKER, HUEBAR_PADDING), (float)bounds.y, (float)GuiGetStyle(COLORPICKER, HUEBAR_WIDTH), (float)bounds.height };
  3159. GuiColorBarHue(boundsHue, NULL, &colorHsv->x);
  3160. return result;
  3161. }
  3162. // Color Panel control, returns HSV color value in *colorHsv.
  3163. // Used by GuiColorPickerHSV()
  3164. int GuiColorPanelHSV(Rectangle bounds, const char *text, Vector3 *colorHsv)
  3165. {
  3166. int result = 0;
  3167. GuiState state = guiState;
  3168. Vector2 pickerSelector = { 0 };
  3169. const Color colWhite = { 255, 255, 255, 255 };
  3170. const Color colBlack = { 0, 0, 0, 255 };
  3171. pickerSelector.x = bounds.x + (float)colorHsv->y*bounds.width; // HSV: Saturation
  3172. pickerSelector.y = bounds.y + (1.0f - (float)colorHsv->z)*bounds.height; // HSV: Value
  3173. float hue = -1.0f;
  3174. Vector3 maxHue = { hue >= 0.0f ? hue : 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 = { 0 };
  3348. float spaceWidth = spacing/(float)subdivs;
  3349. int linesV = (int)(bounds.width/spaceWidth) + 1;
  3350. int linesH = (int)(bounds.height/spaceWidth) + 1;
  3351. // Update control
  3352. //--------------------------------------------------------------------
  3353. if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging)
  3354. {
  3355. if (CheckCollisionPointRec(mousePoint, bounds))
  3356. {
  3357. // NOTE: Cell values must be the upper left of the cell the mouse is in
  3358. currentMouseCell.x = floorf((mousePoint.x - bounds.x)/spacing);
  3359. currentMouseCell.y = floorf((mousePoint.y - bounds.y)/spacing);
  3360. }
  3361. }
  3362. //--------------------------------------------------------------------
  3363. // Draw control
  3364. //--------------------------------------------------------------------
  3365. switch (state)
  3366. {
  3367. case STATE_NORMAL:
  3368. {
  3369. if (subdivs > 0)
  3370. {
  3371. // Draw vertical grid lines
  3372. for (int i = 0; i < linesV; i++)
  3373. {
  3374. Rectangle lineV = { bounds.x + spacing*i/subdivs, bounds.y, 1, bounds.height };
  3375. GuiDrawRectangle(lineV, 0, BLANK, ((i%subdivs) == 0)? GuiFade(GetColor(GuiGetStyle(DEFAULT, LINE_COLOR)), RAYGUI_GRID_ALPHA*4) : GuiFade(GetColor(GuiGetStyle(DEFAULT, LINE_COLOR)), RAYGUI_GRID_ALPHA));
  3376. }
  3377. // Draw horizontal grid lines
  3378. for (int i = 0; i < linesH; i++)
  3379. {
  3380. Rectangle lineH = { bounds.x, bounds.y + spacing*i/subdivs, bounds.width, 1 };
  3381. GuiDrawRectangle(lineH, 0, BLANK, ((i%subdivs) == 0)? GuiFade(GetColor(GuiGetStyle(DEFAULT, LINE_COLOR)), RAYGUI_GRID_ALPHA*4) : GuiFade(GetColor(GuiGetStyle(DEFAULT, LINE_COLOR)), RAYGUI_GRID_ALPHA));
  3382. }
  3383. }
  3384. } break;
  3385. default: break;
  3386. }
  3387. if (mouseCell != NULL) *mouseCell = currentMouseCell;
  3388. return result;
  3389. }
  3390. //----------------------------------------------------------------------------------
  3391. // Tooltip management functions
  3392. // NOTE: Tooltips requires some global variables: tooltipPtr
  3393. //----------------------------------------------------------------------------------
  3394. // Enable gui tooltips (global state)
  3395. void GuiEnableTooltip(void) { guiTooltip = true; }
  3396. // Disable gui tooltips (global state)
  3397. void GuiDisableTooltip(void) { guiTooltip = false; }
  3398. // Set tooltip string
  3399. void GuiSetTooltip(const char *tooltip) { guiTooltipPtr = tooltip; }
  3400. //----------------------------------------------------------------------------------
  3401. // Styles loading functions
  3402. //----------------------------------------------------------------------------------
  3403. // Load raygui style file (.rgs)
  3404. // NOTE: By default a binary file is expected, that file could contain a custom font,
  3405. // in that case, custom font image atlas is GRAY+ALPHA and pixel data can be compressed (DEFLATE)
  3406. void GuiLoadStyle(const char *fileName)
  3407. {
  3408. #define MAX_LINE_BUFFER_SIZE 256
  3409. bool tryBinary = false;
  3410. // Try reading the files as text file first
  3411. FILE *rgsFile = fopen(fileName, "rt");
  3412. if (rgsFile != NULL)
  3413. {
  3414. char buffer[MAX_LINE_BUFFER_SIZE] = { 0 };
  3415. fgets(buffer, MAX_LINE_BUFFER_SIZE, rgsFile);
  3416. if (buffer[0] == '#')
  3417. {
  3418. int controlId = 0;
  3419. int propertyId = 0;
  3420. unsigned int propertyValue = 0;
  3421. while (!feof(rgsFile))
  3422. {
  3423. switch (buffer[0])
  3424. {
  3425. case 'p':
  3426. {
  3427. // Style property: p <control_id> <property_id> <property_value> <property_name>
  3428. sscanf(buffer, "p %d %d 0x%x", &controlId, &propertyId, &propertyValue);
  3429. GuiSetStyle(controlId, propertyId, (int)propertyValue);
  3430. } break;
  3431. case 'f':
  3432. {
  3433. // Style font: f <gen_font_size> <charmap_file> <font_file>
  3434. int fontSize = 0;
  3435. char charmapFileName[256] = { 0 };
  3436. char fontFileName[256] = { 0 };
  3437. sscanf(buffer, "f %d %s %[^\r\n]s", &fontSize, charmapFileName, fontFileName);
  3438. Font font = { 0 };
  3439. int *codepoints = NULL;
  3440. int codepointCount = 0;
  3441. if (charmapFileName[0] != '0')
  3442. {
  3443. // Load text data from file
  3444. // NOTE: Expected an UTF-8 array of codepoints, no separation
  3445. char *textData = LoadFileText(TextFormat("%s/%s", GetDirectoryPath(fileName), charmapFileName));
  3446. codepoints = LoadCodepoints(textData, &codepointCount);
  3447. UnloadFileText(textData);
  3448. }
  3449. if (fontFileName[0] != '\0')
  3450. {
  3451. // In case a font is already loaded and it is not default internal font, unload it
  3452. if (font.texture.id != GetFontDefault().texture.id) UnloadTexture(font.texture);
  3453. if (codepointCount > 0) font = LoadFontEx(TextFormat("%s/%s", GetDirectoryPath(fileName), fontFileName), fontSize, codepoints, codepointCount);
  3454. else font = LoadFontEx(TextFormat("%s/%s", GetDirectoryPath(fileName), fontFileName), fontSize, NULL, 0); // Default to 95 standard codepoints
  3455. }
  3456. // If font texture not properly loaded, revert to default font and size/spacing
  3457. if (font.texture.id == 0)
  3458. {
  3459. font = GetFontDefault();
  3460. GuiSetStyle(DEFAULT, TEXT_SIZE, 10);
  3461. GuiSetStyle(DEFAULT, TEXT_SPACING, 1);
  3462. }
  3463. UnloadCodepoints(codepoints);
  3464. if ((font.texture.id > 0) && (font.glyphCount > 0)) GuiSetFont(font);
  3465. } break;
  3466. default: break;
  3467. }
  3468. fgets(buffer, MAX_LINE_BUFFER_SIZE, rgsFile);
  3469. }
  3470. }
  3471. else tryBinary = true;
  3472. fclose(rgsFile);
  3473. }
  3474. if (tryBinary)
  3475. {
  3476. rgsFile = fopen(fileName, "rb");
  3477. if (rgsFile != NULL)
  3478. {
  3479. fseek(rgsFile, 0, SEEK_END);
  3480. int fileDataSize = ftell(rgsFile);
  3481. fseek(rgsFile, 0, SEEK_SET);
  3482. if (fileDataSize > 0)
  3483. {
  3484. unsigned char *fileData = (unsigned char *)RAYGUI_MALLOC(fileDataSize*sizeof(unsigned char));
  3485. fread(fileData, sizeof(unsigned char), fileDataSize, rgsFile);
  3486. GuiLoadStyleFromMemory(fileData, fileDataSize);
  3487. RAYGUI_FREE(fileData);
  3488. }
  3489. fclose(rgsFile);
  3490. }
  3491. }
  3492. }
  3493. // Load style default over global style
  3494. void GuiLoadStyleDefault(void)
  3495. {
  3496. // We set this variable first to avoid cyclic function calls
  3497. // when calling GuiSetStyle() and GuiGetStyle()
  3498. guiStyleLoaded = true;
  3499. // Initialize default LIGHT style property values
  3500. // WARNING: Default value are applied to all controls on set but
  3501. // they can be overwritten later on for every custom control
  3502. GuiSetStyle(DEFAULT, BORDER_COLOR_NORMAL, 0x838383ff);
  3503. GuiSetStyle(DEFAULT, BASE_COLOR_NORMAL, 0xc9c9c9ff);
  3504. GuiSetStyle(DEFAULT, TEXT_COLOR_NORMAL, 0x686868ff);
  3505. GuiSetStyle(DEFAULT, BORDER_COLOR_FOCUSED, 0x5bb2d9ff);
  3506. GuiSetStyle(DEFAULT, BASE_COLOR_FOCUSED, 0xc9effeff);
  3507. GuiSetStyle(DEFAULT, TEXT_COLOR_FOCUSED, 0x6c9bbcff);
  3508. GuiSetStyle(DEFAULT, BORDER_COLOR_PRESSED, 0x0492c7ff);
  3509. GuiSetStyle(DEFAULT, BASE_COLOR_PRESSED, 0x97e8ffff);
  3510. GuiSetStyle(DEFAULT, TEXT_COLOR_PRESSED, 0x368bafff);
  3511. GuiSetStyle(DEFAULT, BORDER_COLOR_DISABLED, 0xb5c1c2ff);
  3512. GuiSetStyle(DEFAULT, BASE_COLOR_DISABLED, 0xe6e9e9ff);
  3513. GuiSetStyle(DEFAULT, TEXT_COLOR_DISABLED, 0xaeb7b8ff);
  3514. GuiSetStyle(DEFAULT, BORDER_WIDTH, 1);
  3515. GuiSetStyle(DEFAULT, TEXT_PADDING, 0);
  3516. GuiSetStyle(DEFAULT, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
  3517. // Initialize default extended property values
  3518. // NOTE: By default, extended property values are initialized to 0
  3519. GuiSetStyle(DEFAULT, TEXT_SIZE, 10); // DEFAULT, shared by all controls
  3520. GuiSetStyle(DEFAULT, TEXT_SPACING, 1); // DEFAULT, shared by all controls
  3521. GuiSetStyle(DEFAULT, LINE_COLOR, 0x90abb5ff); // DEFAULT specific property
  3522. GuiSetStyle(DEFAULT, BACKGROUND_COLOR, 0xf5f5f5ff); // DEFAULT specific property
  3523. GuiSetStyle(DEFAULT, TEXT_LINE_SPACING, 15); // DEFAULT, 15 pixels between lines
  3524. GuiSetStyle(DEFAULT, TEXT_ALIGNMENT_VERTICAL, TEXT_ALIGN_MIDDLE); // DEFAULT, text aligned vertically to middle of text-bounds
  3525. // Initialize control-specific property values
  3526. // NOTE: Those properties are in default list but require specific values by control type
  3527. GuiSetStyle(LABEL, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
  3528. GuiSetStyle(BUTTON, BORDER_WIDTH, 2);
  3529. GuiSetStyle(SLIDER, TEXT_PADDING, 4);
  3530. GuiSetStyle(PROGRESSBAR, TEXT_PADDING, 4);
  3531. GuiSetStyle(CHECKBOX, TEXT_PADDING, 4);
  3532. GuiSetStyle(CHECKBOX, TEXT_ALIGNMENT, TEXT_ALIGN_RIGHT);
  3533. GuiSetStyle(DROPDOWNBOX, TEXT_PADDING, 0);
  3534. GuiSetStyle(DROPDOWNBOX, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
  3535. GuiSetStyle(TEXTBOX, TEXT_PADDING, 4);
  3536. GuiSetStyle(TEXTBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
  3537. GuiSetStyle(VALUEBOX, TEXT_PADDING, 0);
  3538. GuiSetStyle(VALUEBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
  3539. GuiSetStyle(SPINNER, TEXT_PADDING, 0);
  3540. GuiSetStyle(SPINNER, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
  3541. GuiSetStyle(STATUSBAR, TEXT_PADDING, 8);
  3542. GuiSetStyle(STATUSBAR, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
  3543. // Initialize extended property values
  3544. // NOTE: By default, extended property values are initialized to 0
  3545. GuiSetStyle(TOGGLE, GROUP_PADDING, 2);
  3546. GuiSetStyle(SLIDER, SLIDER_WIDTH, 16);
  3547. GuiSetStyle(SLIDER, SLIDER_PADDING, 1);
  3548. GuiSetStyle(PROGRESSBAR, PROGRESS_PADDING, 1);
  3549. GuiSetStyle(CHECKBOX, CHECK_PADDING, 1);
  3550. GuiSetStyle(COMBOBOX, COMBO_BUTTON_WIDTH, 32);
  3551. GuiSetStyle(COMBOBOX, COMBO_BUTTON_SPACING, 2);
  3552. GuiSetStyle(DROPDOWNBOX, ARROW_PADDING, 16);
  3553. GuiSetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_SPACING, 2);
  3554. GuiSetStyle(SPINNER, SPIN_BUTTON_WIDTH, 24);
  3555. GuiSetStyle(SPINNER, SPIN_BUTTON_SPACING, 2);
  3556. GuiSetStyle(SCROLLBAR, BORDER_WIDTH, 0);
  3557. GuiSetStyle(SCROLLBAR, ARROWS_VISIBLE, 0);
  3558. GuiSetStyle(SCROLLBAR, ARROWS_SIZE, 6);
  3559. GuiSetStyle(SCROLLBAR, SCROLL_SLIDER_PADDING, 0);
  3560. GuiSetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE, 16);
  3561. GuiSetStyle(SCROLLBAR, SCROLL_PADDING, 0);
  3562. GuiSetStyle(SCROLLBAR, SCROLL_SPEED, 12);
  3563. GuiSetStyle(LISTVIEW, LIST_ITEMS_HEIGHT, 28);
  3564. GuiSetStyle(LISTVIEW, LIST_ITEMS_SPACING, 2);
  3565. GuiSetStyle(LISTVIEW, SCROLLBAR_WIDTH, 12);
  3566. GuiSetStyle(LISTVIEW, SCROLLBAR_SIDE, SCROLLBAR_RIGHT_SIDE);
  3567. GuiSetStyle(COLORPICKER, COLOR_SELECTOR_SIZE, 8);
  3568. GuiSetStyle(COLORPICKER, HUEBAR_WIDTH, 16);
  3569. GuiSetStyle(COLORPICKER, HUEBAR_PADDING, 8);
  3570. GuiSetStyle(COLORPICKER, HUEBAR_SELECTOR_HEIGHT, 8);
  3571. GuiSetStyle(COLORPICKER, HUEBAR_SELECTOR_OVERFLOW, 2);
  3572. if (guiFont.texture.id != GetFontDefault().texture.id)
  3573. {
  3574. // Unload previous font texture
  3575. UnloadTexture(guiFont.texture);
  3576. RL_FREE(guiFont.recs);
  3577. RL_FREE(guiFont.glyphs);
  3578. guiFont.recs = NULL;
  3579. guiFont.glyphs = NULL;
  3580. // Setup default raylib font
  3581. guiFont = GetFontDefault();
  3582. // NOTE: Default raylib font character 95 is a white square
  3583. Rectangle whiteChar = guiFont.recs[95];
  3584. // NOTE: We set up a 1px padding on char rectangle to avoid pixel bleeding on MSAA filtering
  3585. SetShapesTexture(guiFont.texture, RAYGUI_CLITERAL(Rectangle){ whiteChar.x + 1, whiteChar.y + 1, whiteChar.width - 2, whiteChar.height - 2 });
  3586. }
  3587. }
  3588. // Get text with icon id prepended
  3589. // NOTE: Useful to add icons by name id (enum) instead of
  3590. // a number that can change between ricon versions
  3591. const char *GuiIconText(int iconId, const char *text)
  3592. {
  3593. #if defined(RAYGUI_NO_ICONS)
  3594. return NULL;
  3595. #else
  3596. static char buffer[1024] = { 0 };
  3597. static char iconBuffer[6] = { 0 };
  3598. if (text != NULL)
  3599. {
  3600. memset(buffer, 0, 1024);
  3601. sprintf(buffer, "#%03i#", iconId);
  3602. for (int i = 5; i < 1024; i++)
  3603. {
  3604. buffer[i] = text[i - 5];
  3605. if (text[i - 5] == '\0') break;
  3606. }
  3607. return buffer;
  3608. }
  3609. else
  3610. {
  3611. sprintf(iconBuffer, "#%03i#", iconId & 0x1ff);
  3612. return iconBuffer;
  3613. }
  3614. #endif
  3615. }
  3616. #if !defined(RAYGUI_NO_ICONS)
  3617. // Get full icons data pointer
  3618. unsigned int *GuiGetIcons(void) { return guiIconsPtr; }
  3619. // Load raygui icons file (.rgi)
  3620. // NOTE: In case nameIds are required, they can be requested with loadIconsName,
  3621. // they are returned as a guiIconsName[iconCount][RAYGUI_ICON_MAX_NAME_LENGTH],
  3622. // WARNING: guiIconsName[]][] memory should be manually freed!
  3623. char **GuiLoadIcons(const char *fileName, bool loadIconsName)
  3624. {
  3625. // Style File Structure (.rgi)
  3626. // ------------------------------------------------------
  3627. // Offset | Size | Type | Description
  3628. // ------------------------------------------------------
  3629. // 0 | 4 | char | Signature: "rGI "
  3630. // 4 | 2 | short | Version: 100
  3631. // 6 | 2 | short | reserved
  3632. // 8 | 2 | short | Num icons (N)
  3633. // 10 | 2 | short | Icons size (Options: 16, 32, 64) (S)
  3634. // Icons name id (32 bytes per name id)
  3635. // foreach (icon)
  3636. // {
  3637. // 12+32*i | 32 | char | Icon NameId
  3638. // }
  3639. // Icons data: One bit per pixel, stored as unsigned int array (depends on icon size)
  3640. // S*S pixels/32bit per unsigned int = K unsigned int per icon
  3641. // foreach (icon)
  3642. // {
  3643. // ... | K | unsigned int | Icon Data
  3644. // }
  3645. FILE *rgiFile = fopen(fileName, "rb");
  3646. char **guiIconsName = NULL;
  3647. if (rgiFile != NULL)
  3648. {
  3649. char signature[5] = { 0 };
  3650. short version = 0;
  3651. short reserved = 0;
  3652. short iconCount = 0;
  3653. short iconSize = 0;
  3654. fread(signature, 1, 4, rgiFile);
  3655. fread(&version, sizeof(short), 1, rgiFile);
  3656. fread(&reserved, sizeof(short), 1, rgiFile);
  3657. fread(&iconCount, sizeof(short), 1, rgiFile);
  3658. fread(&iconSize, sizeof(short), 1, rgiFile);
  3659. if ((signature[0] == 'r') &&
  3660. (signature[1] == 'G') &&
  3661. (signature[2] == 'I') &&
  3662. (signature[3] == ' '))
  3663. {
  3664. if (loadIconsName)
  3665. {
  3666. guiIconsName = (char **)RAYGUI_MALLOC(iconCount*sizeof(char **));
  3667. for (int i = 0; i < iconCount; i++)
  3668. {
  3669. guiIconsName[i] = (char *)RAYGUI_MALLOC(RAYGUI_ICON_MAX_NAME_LENGTH);
  3670. fread(guiIconsName[i], 1, RAYGUI_ICON_MAX_NAME_LENGTH, rgiFile);
  3671. }
  3672. }
  3673. else fseek(rgiFile, iconCount*RAYGUI_ICON_MAX_NAME_LENGTH, SEEK_CUR);
  3674. // Read icons data directly over internal icons array
  3675. fread(guiIconsPtr, sizeof(unsigned int), iconCount*(iconSize*iconSize/32), rgiFile);
  3676. }
  3677. fclose(rgiFile);
  3678. }
  3679. return guiIconsName;
  3680. }
  3681. // Draw selected icon using rectangles pixel-by-pixel
  3682. void GuiDrawIcon(int iconId, int posX, int posY, int pixelSize, Color color)
  3683. {
  3684. #define BIT_CHECK(a,b) ((a) & (1u<<(b)))
  3685. for (int i = 0, y = 0; i < RAYGUI_ICON_SIZE*RAYGUI_ICON_SIZE/32; i++)
  3686. {
  3687. for (int k = 0; k < 32; k++)
  3688. {
  3689. if (BIT_CHECK(guiIconsPtr[iconId*RAYGUI_ICON_DATA_ELEMENTS + i], k))
  3690. {
  3691. #if !defined(RAYGUI_STANDALONE)
  3692. GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ (float)posX + (k%RAYGUI_ICON_SIZE)*pixelSize, (float)posY + y*pixelSize, (float)pixelSize, (float)pixelSize }, 0, BLANK, color);
  3693. #endif
  3694. }
  3695. if ((k == 15) || (k == 31)) y++;
  3696. }
  3697. }
  3698. }
  3699. // Set icon drawing size
  3700. void GuiSetIconScale(int scale)
  3701. {
  3702. if (scale >= 1) guiIconScale = scale;
  3703. }
  3704. #endif // !RAYGUI_NO_ICONS
  3705. //----------------------------------------------------------------------------------
  3706. // Module specific Functions Definition
  3707. //----------------------------------------------------------------------------------
  3708. // Load style from memory
  3709. // WARNING: Binary files only
  3710. static void GuiLoadStyleFromMemory(const unsigned char *fileData, int dataSize)
  3711. {
  3712. unsigned char *fileDataPtr = (unsigned char *)fileData;
  3713. char signature[5] = { 0 };
  3714. short version = 0;
  3715. short reserved = 0;
  3716. int propertyCount = 0;
  3717. memcpy(signature, fileDataPtr, 4);
  3718. memcpy(&version, fileDataPtr + 4, sizeof(short));
  3719. memcpy(&reserved, fileDataPtr + 4 + 2, sizeof(short));
  3720. memcpy(&propertyCount, fileDataPtr + 4 + 2 + 2, sizeof(int));
  3721. fileDataPtr += 12;
  3722. if ((signature[0] == 'r') &&
  3723. (signature[1] == 'G') &&
  3724. (signature[2] == 'S') &&
  3725. (signature[3] == ' '))
  3726. {
  3727. short controlId = 0;
  3728. short propertyId = 0;
  3729. unsigned int propertyValue = 0;
  3730. for (int i = 0; i < propertyCount; i++)
  3731. {
  3732. memcpy(&controlId, fileDataPtr, sizeof(short));
  3733. memcpy(&propertyId, fileDataPtr + 2, sizeof(short));
  3734. memcpy(&propertyValue, fileDataPtr + 2 + 2, sizeof(unsigned int));
  3735. fileDataPtr += 8;
  3736. if (controlId == 0) // DEFAULT control
  3737. {
  3738. // If a DEFAULT property is loaded, it is propagated to all controls
  3739. // NOTE: All DEFAULT properties should be defined first in the file
  3740. GuiSetStyle(0, (int)propertyId, propertyValue);
  3741. if (propertyId < RAYGUI_MAX_PROPS_BASE) for (int i = 1; i < RAYGUI_MAX_CONTROLS; i++) GuiSetStyle(i, (int)propertyId, propertyValue);
  3742. }
  3743. else GuiSetStyle((int)controlId, (int)propertyId, propertyValue);
  3744. }
  3745. // Font loading is highly dependant on raylib API to load font data and image
  3746. #if !defined(RAYGUI_STANDALONE)
  3747. // Load custom font if available
  3748. int fontDataSize = 0;
  3749. memcpy(&fontDataSize, fileDataPtr, sizeof(int));
  3750. fileDataPtr += 4;
  3751. if (fontDataSize > 0)
  3752. {
  3753. Font font = { 0 };
  3754. int fontType = 0; // 0-Normal, 1-SDF
  3755. memcpy(&font.baseSize, fileDataPtr, sizeof(int));
  3756. memcpy(&font.glyphCount, fileDataPtr + 4, sizeof(int));
  3757. memcpy(&fontType, fileDataPtr + 4 + 4, sizeof(int));
  3758. fileDataPtr += 12;
  3759. // Load font white rectangle
  3760. Rectangle fontWhiteRec = { 0 };
  3761. memcpy(&fontWhiteRec, fileDataPtr, sizeof(Rectangle));
  3762. fileDataPtr += 16;
  3763. // Load font image parameters
  3764. int fontImageUncompSize = 0;
  3765. int fontImageCompSize = 0;
  3766. memcpy(&fontImageUncompSize, fileDataPtr, sizeof(int));
  3767. memcpy(&fontImageCompSize, fileDataPtr + 4, sizeof(int));
  3768. fileDataPtr += 8;
  3769. Image imFont = { 0 };
  3770. imFont.mipmaps = 1;
  3771. memcpy(&imFont.width, fileDataPtr, sizeof(int));
  3772. memcpy(&imFont.height, fileDataPtr + 4, sizeof(int));
  3773. memcpy(&imFont.format, fileDataPtr + 4 + 4, sizeof(int));
  3774. fileDataPtr += 12;
  3775. if ((fontImageCompSize > 0) && (fontImageCompSize != fontImageUncompSize))
  3776. {
  3777. // Compressed font atlas image data (DEFLATE), it requires DecompressData()
  3778. int dataUncompSize = 0;
  3779. unsigned char *compData = (unsigned char *)RAYGUI_MALLOC(fontImageCompSize);
  3780. memcpy(compData, fileDataPtr, fontImageCompSize);
  3781. fileDataPtr += fontImageCompSize;
  3782. imFont.data = DecompressData(compData, fontImageCompSize, &dataUncompSize);
  3783. // Security check, dataUncompSize must match the provided fontImageUncompSize
  3784. if (dataUncompSize != fontImageUncompSize) RAYGUI_LOG("WARNING: Uncompressed font atlas image data could be corrupted");
  3785. RAYGUI_FREE(compData);
  3786. }
  3787. else
  3788. {
  3789. // Font atlas image data is not compressed
  3790. imFont.data = (unsigned char *)RAYGUI_MALLOC(fontImageUncompSize);
  3791. memcpy(imFont.data, fileDataPtr, fontImageUncompSize);
  3792. fileDataPtr += fontImageUncompSize;
  3793. }
  3794. if (font.texture.id != GetFontDefault().texture.id) UnloadTexture(font.texture);
  3795. font.texture = LoadTextureFromImage(imFont);
  3796. RAYGUI_FREE(imFont.data);
  3797. // Validate font atlas texture was loaded correctly
  3798. if (font.texture.id != 0)
  3799. {
  3800. // Load font recs data
  3801. int recsDataSize = font.glyphCount*sizeof(Rectangle);
  3802. int recsDataCompressedSize = 0;
  3803. // WARNING: Version 400 adds the compression size parameter
  3804. if (version >= 400)
  3805. {
  3806. // RGS files version 400 support compressed recs data
  3807. memcpy(&recsDataCompressedSize, fileDataPtr, sizeof(int));
  3808. fileDataPtr += sizeof(int);
  3809. }
  3810. if ((recsDataCompressedSize > 0) && (recsDataCompressedSize != recsDataSize))
  3811. {
  3812. // Recs data is compressed, uncompress it
  3813. unsigned char *recsDataCompressed = (unsigned char *)RAYGUI_MALLOC(recsDataCompressedSize);
  3814. memcpy(recsDataCompressed, fileDataPtr, recsDataCompressedSize);
  3815. fileDataPtr += recsDataCompressedSize;
  3816. int recsDataUncompSize = 0;
  3817. font.recs = (Rectangle *)DecompressData(recsDataCompressed, recsDataCompressedSize, &recsDataUncompSize);
  3818. // Security check, data uncompressed size must match the expected original data size
  3819. if (recsDataUncompSize != recsDataSize) RAYGUI_LOG("WARNING: Uncompressed font recs data could be corrupted");
  3820. RAYGUI_FREE(recsDataCompressed);
  3821. }
  3822. else
  3823. {
  3824. // Recs data is uncompressed
  3825. font.recs = (Rectangle *)RAYGUI_CALLOC(font.glyphCount, sizeof(Rectangle));
  3826. for (int i = 0; i < font.glyphCount; i++)
  3827. {
  3828. memcpy(&font.recs[i], fileDataPtr, sizeof(Rectangle));
  3829. fileDataPtr += sizeof(Rectangle);
  3830. }
  3831. }
  3832. // Load font glyphs info data
  3833. int glyphsDataSize = font.glyphCount*16; // 16 bytes data per glyph
  3834. int glyphsDataCompressedSize = 0;
  3835. // WARNING: Version 400 adds the compression size parameter
  3836. if (version >= 400)
  3837. {
  3838. // RGS files version 400 support compressed glyphs data
  3839. memcpy(&glyphsDataCompressedSize, fileDataPtr, sizeof(int));
  3840. fileDataPtr += sizeof(int);
  3841. }
  3842. // Allocate required glyphs space to fill with data
  3843. font.glyphs = (GlyphInfo *)RAYGUI_CALLOC(font.glyphCount, sizeof(GlyphInfo));
  3844. if ((glyphsDataCompressedSize > 0) && (glyphsDataCompressedSize != glyphsDataSize))
  3845. {
  3846. // Glyphs data is compressed, uncompress it
  3847. unsigned char *glypsDataCompressed = (unsigned char *)RAYGUI_MALLOC(glyphsDataCompressedSize);
  3848. memcpy(glypsDataCompressed, fileDataPtr, glyphsDataCompressedSize);
  3849. fileDataPtr += glyphsDataCompressedSize;
  3850. int glyphsDataUncompSize = 0;
  3851. unsigned char *glyphsDataUncomp = DecompressData(glypsDataCompressed, glyphsDataCompressedSize, &glyphsDataUncompSize);
  3852. // Security check, data uncompressed size must match the expected original data size
  3853. if (glyphsDataUncompSize != glyphsDataSize) RAYGUI_LOG("WARNING: Uncompressed font glyphs data could be corrupted");
  3854. unsigned char *glyphsDataUncompPtr = glyphsDataUncomp;
  3855. for (int i = 0; i < font.glyphCount; i++)
  3856. {
  3857. memcpy(&font.glyphs[i].value, glyphsDataUncompPtr, sizeof(int));
  3858. memcpy(&font.glyphs[i].offsetX, glyphsDataUncompPtr + 4, sizeof(int));
  3859. memcpy(&font.glyphs[i].offsetY, glyphsDataUncompPtr + 8, sizeof(int));
  3860. memcpy(&font.glyphs[i].advanceX, glyphsDataUncompPtr + 12, sizeof(int));
  3861. glyphsDataUncompPtr += 16;
  3862. }
  3863. RAYGUI_FREE(glypsDataCompressed);
  3864. RAYGUI_FREE(glyphsDataUncomp);
  3865. }
  3866. else
  3867. {
  3868. // Glyphs data is uncompressed
  3869. for (int i = 0; i < font.glyphCount; i++)
  3870. {
  3871. memcpy(&font.glyphs[i].value, fileDataPtr, sizeof(int));
  3872. memcpy(&font.glyphs[i].offsetX, fileDataPtr + 4, sizeof(int));
  3873. memcpy(&font.glyphs[i].offsetY, fileDataPtr + 8, sizeof(int));
  3874. memcpy(&font.glyphs[i].advanceX, fileDataPtr + 12, sizeof(int));
  3875. fileDataPtr += 16;
  3876. }
  3877. }
  3878. }
  3879. else font = GetFontDefault(); // Fallback in case of errors loading font atlas texture
  3880. GuiSetFont(font);
  3881. // Set font texture source rectangle to be used as white texture to draw shapes
  3882. // NOTE: It makes possible to draw shapes and text (full UI) in a single draw call
  3883. if ((fontWhiteRec.x > 0) &&
  3884. (fontWhiteRec.y > 0) &&
  3885. (fontWhiteRec.width > 0) &&
  3886. (fontWhiteRec.height > 0)) SetShapesTexture(font.texture, fontWhiteRec);
  3887. }
  3888. #endif
  3889. }
  3890. }
  3891. // Gui get text width considering icon
  3892. static int GetTextWidth(const char *text)
  3893. {
  3894. #if !defined(ICON_TEXT_PADDING)
  3895. #define ICON_TEXT_PADDING 4
  3896. #endif
  3897. Vector2 textSize = { 0 };
  3898. int textIconOffset = 0;
  3899. if ((text != NULL) && (text[0] != '\0'))
  3900. {
  3901. if (text[0] == '#')
  3902. {
  3903. for (int i = 1; (i < 5) && (text[i] != '\0'); i++)
  3904. {
  3905. if (text[i] == '#')
  3906. {
  3907. textIconOffset = i;
  3908. break;
  3909. }
  3910. }
  3911. }
  3912. text += textIconOffset;
  3913. // Make sure guiFont is set, GuiGetStyle() initializes it lazynessly
  3914. float fontSize = (float)GuiGetStyle(DEFAULT, TEXT_SIZE);
  3915. // Custom MeasureText() implementation
  3916. if ((guiFont.texture.id > 0) && (text != NULL))
  3917. {
  3918. // Get size in bytes of text, considering end of line and line break
  3919. int size = 0;
  3920. for (int i = 0; i < MAX_LINE_BUFFER_SIZE; i++)
  3921. {
  3922. if ((text[i] != '\0') && (text[i] != '\n')) size++;
  3923. else break;
  3924. }
  3925. float scaleFactor = fontSize/(float)guiFont.baseSize;
  3926. textSize.y = (float)guiFont.baseSize*scaleFactor;
  3927. float glyphWidth = 0.0f;
  3928. for (int i = 0, codepointSize = 0; i < size; i += codepointSize)
  3929. {
  3930. int codepoint = GetCodepointNext(&text[i], &codepointSize);
  3931. int codepointIndex = GetGlyphIndex(guiFont, codepoint);
  3932. if (guiFont.glyphs[codepointIndex].advanceX == 0) glyphWidth = ((float)guiFont.recs[codepointIndex].width*scaleFactor);
  3933. else glyphWidth = ((float)guiFont.glyphs[codepointIndex].advanceX*scaleFactor);
  3934. textSize.x += (glyphWidth + (float)GuiGetStyle(DEFAULT, TEXT_SPACING));
  3935. }
  3936. }
  3937. if (textIconOffset > 0) textSize.x += (RAYGUI_ICON_SIZE - ICON_TEXT_PADDING);
  3938. }
  3939. return (int)textSize.x;
  3940. }
  3941. // Get text bounds considering control bounds
  3942. static Rectangle GetTextBounds(int control, Rectangle bounds)
  3943. {
  3944. Rectangle textBounds = bounds;
  3945. textBounds.x = bounds.x + GuiGetStyle(control, BORDER_WIDTH);
  3946. textBounds.y = bounds.y + GuiGetStyle(control, BORDER_WIDTH) + GuiGetStyle(control, TEXT_PADDING);
  3947. textBounds.width = bounds.width - 2*GuiGetStyle(control, BORDER_WIDTH) - 2*GuiGetStyle(control, TEXT_PADDING);
  3948. textBounds.height = bounds.height - 2*GuiGetStyle(control, BORDER_WIDTH) - 2*GuiGetStyle(control, TEXT_PADDING); // NOTE: Text is processed line per line!
  3949. // Depending on control, TEXT_PADDING and TEXT_ALIGNMENT properties could affect the text-bounds
  3950. switch (control)
  3951. {
  3952. case COMBOBOX:
  3953. case DROPDOWNBOX:
  3954. case LISTVIEW:
  3955. // TODO: Special cases (no label): COMBOBOX, DROPDOWNBOX, LISTVIEW
  3956. case SLIDER:
  3957. case CHECKBOX:
  3958. case VALUEBOX:
  3959. case SPINNER:
  3960. // TODO: More special cases (label on side): SLIDER, CHECKBOX, VALUEBOX, SPINNER
  3961. default:
  3962. {
  3963. // TODO: WARNING: TEXT_ALIGNMENT is already considered in GuiDrawText()
  3964. if (GuiGetStyle(control, TEXT_ALIGNMENT) == TEXT_ALIGN_RIGHT) textBounds.x -= GuiGetStyle(control, TEXT_PADDING);
  3965. else textBounds.x += GuiGetStyle(control, TEXT_PADDING);
  3966. }
  3967. break;
  3968. }
  3969. return textBounds;
  3970. }
  3971. // Get text icon if provided and move text cursor
  3972. // NOTE: We support up to 999 values for iconId
  3973. static const char *GetTextIcon(const char *text, int *iconId)
  3974. {
  3975. #if !defined(RAYGUI_NO_ICONS)
  3976. *iconId = -1;
  3977. if (text[0] == '#') // Maybe we have an icon!
  3978. {
  3979. char iconValue[4] = { 0 }; // Maximum length for icon value: 3 digits + '\0'
  3980. int pos = 1;
  3981. while ((pos < 4) && (text[pos] >= '0') && (text[pos] <= '9'))
  3982. {
  3983. iconValue[pos - 1] = text[pos];
  3984. pos++;
  3985. }
  3986. if (text[pos] == '#')
  3987. {
  3988. *iconId = TextToInteger(iconValue);
  3989. // Move text pointer after icon
  3990. // WARNING: If only icon provided, it could point to EOL character: '\0'
  3991. if (*iconId >= 0) text += (pos + 1);
  3992. }
  3993. }
  3994. #endif
  3995. return text;
  3996. }
  3997. // Get text divided into lines (by line-breaks '\n')
  3998. const char **GetTextLines(const char *text, int *count)
  3999. {
  4000. #define RAYGUI_MAX_TEXT_LINES 128
  4001. static const char *lines[RAYGUI_MAX_TEXT_LINES] = { 0 };
  4002. for (int i = 0; i < RAYGUI_MAX_TEXT_LINES; i++) lines[i] = NULL; // Init NULL pointers to substrings
  4003. int textSize = (int)strlen(text);
  4004. lines[0] = text;
  4005. int len = 0;
  4006. *count = 1;
  4007. //int lineSize = 0; // Stores current line size, not returned
  4008. for (int i = 0, k = 0; (i < textSize) && (*count < RAYGUI_MAX_TEXT_LINES); i++)
  4009. {
  4010. if (text[i] == '\n')
  4011. {
  4012. //lineSize = len;
  4013. k++;
  4014. lines[k] = &text[i + 1]; // WARNING: next value is valid?
  4015. len = 0;
  4016. *count += 1;
  4017. }
  4018. else len++;
  4019. }
  4020. //lines[*count - 1].size = len;
  4021. return lines;
  4022. }
  4023. // Get text width to next space for provided string
  4024. static float GetNextSpaceWidth(const char *text, int *nextSpaceIndex)
  4025. {
  4026. float width = 0;
  4027. int codepointByteCount = 0;
  4028. int codepoint = 0;
  4029. int index = 0;
  4030. float glyphWidth = 0;
  4031. float scaleFactor = (float)GuiGetStyle(DEFAULT, TEXT_SIZE)/guiFont.baseSize;
  4032. for (int i = 0; text[i] != '\0'; i++)
  4033. {
  4034. if (text[i] != ' ')
  4035. {
  4036. codepoint = GetCodepoint(&text[i], &codepointByteCount);
  4037. index = GetGlyphIndex(guiFont, codepoint);
  4038. glyphWidth = (guiFont.glyphs[index].advanceX == 0)? guiFont.recs[index].width*scaleFactor : guiFont.glyphs[index].advanceX*scaleFactor;
  4039. width += (glyphWidth + (float)GuiGetStyle(DEFAULT, TEXT_SPACING));
  4040. }
  4041. else
  4042. {
  4043. *nextSpaceIndex = i;
  4044. break;
  4045. }
  4046. }
  4047. return width;
  4048. }
  4049. // Gui draw text using default font
  4050. static void GuiDrawText(const char *text, Rectangle textBounds, int alignment, Color tint)
  4051. {
  4052. #define TEXT_VALIGN_PIXEL_OFFSET(h) ((int)h%2) // Vertical alignment for pixel perfect
  4053. #if !defined(ICON_TEXT_PADDING)
  4054. #define ICON_TEXT_PADDING 4
  4055. #endif
  4056. if ((text == NULL) || (text[0] == '\0')) return; // Security check
  4057. // PROCEDURE:
  4058. // - Text is processed line per line
  4059. // - For every line, horizontal alignment is defined
  4060. // - For all text, vertical alignment is defined (multiline text only)
  4061. // - For every line, wordwrap mode is checked (useful for GuitextBox(), read-only)
  4062. // Get text lines (using '\n' as delimiter) to be processed individually
  4063. // WARNING: We can't use GuiTextSplit() function because it can be already used
  4064. // before the GuiDrawText() call and its buffer is static, it would be overriden :(
  4065. int lineCount = 0;
  4066. const char **lines = GetTextLines(text, &lineCount);
  4067. // Text style variables
  4068. //int alignment = GuiGetStyle(DEFAULT, TEXT_ALIGNMENT);
  4069. int alignmentVertical = GuiGetStyle(DEFAULT, TEXT_ALIGNMENT_VERTICAL);
  4070. int wrapMode = GuiGetStyle(DEFAULT, TEXT_WRAP_MODE); // Wrap-mode only available in read-only mode, no for text editing
  4071. // TODO: WARNING: This totalHeight is not valid for vertical alignment in case of word-wrap
  4072. float totalHeight = (float)(lineCount*GuiGetStyle(DEFAULT, TEXT_SIZE) + (lineCount - 1)*GuiGetStyle(DEFAULT, TEXT_SIZE)/2);
  4073. float posOffsetY = 0.0f;
  4074. for (int i = 0; i < lineCount; i++)
  4075. {
  4076. int iconId = 0;
  4077. lines[i] = GetTextIcon(lines[i], &iconId); // Check text for icon and move cursor
  4078. // Get text position depending on alignment and iconId
  4079. //---------------------------------------------------------------------------------
  4080. Vector2 textBoundsPosition = { textBounds.x, textBounds.y };
  4081. // NOTE: We get text size after icon has been processed
  4082. // WARNING: GetTextWidth() also processes text icon to get width! -> Really needed?
  4083. int textSizeX = GetTextWidth(lines[i]);
  4084. // If text requires an icon, add size to measure
  4085. if (iconId >= 0)
  4086. {
  4087. textSizeX += RAYGUI_ICON_SIZE*guiIconScale;
  4088. // WARNING: If only icon provided, text could be pointing to EOF character: '\0'
  4089. #if !defined(RAYGUI_NO_ICONS)
  4090. if ((lines[i] != NULL) && (lines[i][0] != '\0')) textSizeX += ICON_TEXT_PADDING;
  4091. #endif
  4092. }
  4093. // Check guiTextAlign global variables
  4094. switch (alignment)
  4095. {
  4096. case TEXT_ALIGN_LEFT: textBoundsPosition.x = textBounds.x; break;
  4097. case TEXT_ALIGN_CENTER: textBoundsPosition.x = textBounds.x + textBounds.width/2 - textSizeX/2; break;
  4098. case TEXT_ALIGN_RIGHT: textBoundsPosition.x = textBounds.x + textBounds.width - textSizeX; break;
  4099. default: break;
  4100. }
  4101. switch (alignmentVertical)
  4102. {
  4103. // Only valid in case of wordWrap = 0;
  4104. case TEXT_ALIGN_TOP: textBoundsPosition.y = textBounds.y + posOffsetY; break;
  4105. case TEXT_ALIGN_MIDDLE: textBoundsPosition.y = textBounds.y + posOffsetY + textBounds.height/2 - totalHeight/2 + TEXT_VALIGN_PIXEL_OFFSET(textBounds.height); break;
  4106. case TEXT_ALIGN_BOTTOM: textBoundsPosition.y = textBounds.y + posOffsetY + textBounds.height - totalHeight + TEXT_VALIGN_PIXEL_OFFSET(textBounds.height); break;
  4107. default: break;
  4108. }
  4109. // NOTE: Make sure we get pixel-perfect coordinates,
  4110. // In case of decimals we got weird text positioning
  4111. textBoundsPosition.x = (float)((int)textBoundsPosition.x);
  4112. textBoundsPosition.y = (float)((int)textBoundsPosition.y);
  4113. //---------------------------------------------------------------------------------
  4114. // Draw text (with icon if available)
  4115. //---------------------------------------------------------------------------------
  4116. #if !defined(RAYGUI_NO_ICONS)
  4117. if (iconId >= 0)
  4118. {
  4119. // NOTE: We consider icon height, probably different than text size
  4120. GuiDrawIcon(iconId, (int)textBoundsPosition.x, (int)(textBounds.y + textBounds.height/2 - RAYGUI_ICON_SIZE*guiIconScale/2 + TEXT_VALIGN_PIXEL_OFFSET(textBounds.height)), guiIconScale, tint);
  4121. textBoundsPosition.x += (RAYGUI_ICON_SIZE*guiIconScale + ICON_TEXT_PADDING);
  4122. }
  4123. #endif
  4124. // Get size in bytes of text,
  4125. // considering end of line and line break
  4126. int lineSize = 0;
  4127. for (int c = 0; (lines[i][c] != '\0') && (lines[i][c] != '\n') && (lines[i][c] != '\r'); c++, lineSize++){ }
  4128. float scaleFactor = (float)GuiGetStyle(DEFAULT, TEXT_SIZE)/guiFont.baseSize;
  4129. int textOffsetY = 0;
  4130. float textOffsetX = 0.0f;
  4131. float glyphWidth = 0;
  4132. for (int c = 0, codepointSize = 0; c < lineSize; c += codepointSize)
  4133. {
  4134. int codepoint = GetCodepointNext(&lines[i][c], &codepointSize);
  4135. int index = GetGlyphIndex(guiFont, codepoint);
  4136. // NOTE: Normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f)
  4137. // but we need to draw all of the bad bytes using the '?' symbol moving one byte
  4138. if (codepoint == 0x3f) codepointSize = 1; // TODO: Review not recognized codepoints size
  4139. // Wrap mode text measuring to space to validate if it can be drawn or
  4140. // a new line is required
  4141. if (wrapMode == TEXT_WRAP_CHAR)
  4142. {
  4143. // Get glyph width to check if it goes out of bounds
  4144. if (guiFont.glyphs[index].advanceX == 0) glyphWidth = ((float)guiFont.recs[index].width*scaleFactor);
  4145. else glyphWidth = (float)guiFont.glyphs[index].advanceX*scaleFactor;
  4146. // Jump to next line if current character reach end of the box limits
  4147. if ((textOffsetX + glyphWidth) > textBounds.width)
  4148. {
  4149. textOffsetX = 0.0f;
  4150. textOffsetY += GuiGetStyle(DEFAULT, TEXT_LINE_SPACING);
  4151. }
  4152. }
  4153. else if (wrapMode == TEXT_WRAP_WORD)
  4154. {
  4155. // Get width to next space in line
  4156. int nextSpaceIndex = 0;
  4157. float nextSpaceWidth = GetNextSpaceWidth(lines[i] + c, &nextSpaceIndex);
  4158. if ((textOffsetX + nextSpaceWidth) > textBounds.width)
  4159. {
  4160. textOffsetX = 0.0f;
  4161. textOffsetY += GuiGetStyle(DEFAULT, TEXT_LINE_SPACING);
  4162. }
  4163. // TODO: Consider case: (nextSpaceWidth >= textBounds.width)
  4164. }
  4165. if (codepoint == '\n') break; // WARNING: Lines are already processed manually, no need to keep drawing after this codepoint
  4166. else
  4167. {
  4168. // TODO: There are multiple types of spaces in Unicode,
  4169. // maybe it's a good idea to add support for more: http://jkorpela.fi/chars/spaces.html
  4170. if ((codepoint != ' ') && (codepoint != '\t')) // Do not draw codepoints with no glyph
  4171. {
  4172. if (wrapMode == TEXT_WRAP_NONE)
  4173. {
  4174. // Draw only required text glyphs fitting the textBounds.width
  4175. if (textOffsetX <= (textBounds.width - glyphWidth))
  4176. {
  4177. DrawTextCodepoint(guiFont, codepoint, RAYGUI_CLITERAL(Vector2){ textBoundsPosition.x + textOffsetX, textBoundsPosition.y + textOffsetY }, (float)GuiGetStyle(DEFAULT, TEXT_SIZE), GuiFade(tint, guiAlpha));
  4178. }
  4179. }
  4180. else if ((wrapMode == TEXT_WRAP_CHAR) || (wrapMode == TEXT_WRAP_WORD))
  4181. {
  4182. // Draw only glyphs inside the bounds
  4183. if ((textBoundsPosition.y + textOffsetY) <= (textBounds.y + textBounds.height - GuiGetStyle(DEFAULT, TEXT_SIZE)))
  4184. {
  4185. DrawTextCodepoint(guiFont, codepoint, RAYGUI_CLITERAL(Vector2){ textBoundsPosition.x + textOffsetX, textBoundsPosition.y + textOffsetY }, (float)GuiGetStyle(DEFAULT, TEXT_SIZE), GuiFade(tint, guiAlpha));
  4186. }
  4187. }
  4188. }
  4189. if (guiFont.glyphs[index].advanceX == 0) textOffsetX += ((float)guiFont.recs[index].width*scaleFactor + (float)GuiGetStyle(DEFAULT, TEXT_SPACING));
  4190. else textOffsetX += ((float)guiFont.glyphs[index].advanceX*scaleFactor + (float)GuiGetStyle(DEFAULT, TEXT_SPACING));
  4191. }
  4192. }
  4193. if (wrapMode == TEXT_WRAP_NONE) posOffsetY += (float)GuiGetStyle(DEFAULT, TEXT_LINE_SPACING);
  4194. else if ((wrapMode == TEXT_WRAP_CHAR) || (wrapMode == TEXT_WRAP_WORD)) posOffsetY += (textOffsetY + (float)GuiGetStyle(DEFAULT, TEXT_LINE_SPACING));
  4195. //---------------------------------------------------------------------------------
  4196. }
  4197. #if defined(RAYGUI_DEBUG_TEXT_BOUNDS)
  4198. GuiDrawRectangle(textBounds, 0, WHITE, Fade(BLUE, 0.4f));
  4199. #endif
  4200. }
  4201. // Gui draw rectangle using default raygui plain style with borders
  4202. static void GuiDrawRectangle(Rectangle rec, int borderWidth, Color borderColor, Color color)
  4203. {
  4204. if (color.a > 0)
  4205. {
  4206. // Draw rectangle filled with color
  4207. DrawRectangle((int)rec.x, (int)rec.y, (int)rec.width, (int)rec.height, GuiFade(color, guiAlpha));
  4208. }
  4209. if (borderWidth > 0)
  4210. {
  4211. // Draw rectangle border lines with color
  4212. DrawRectangle((int)rec.x, (int)rec.y, (int)rec.width, borderWidth, GuiFade(borderColor, guiAlpha));
  4213. DrawRectangle((int)rec.x, (int)rec.y + borderWidth, borderWidth, (int)rec.height - 2*borderWidth, GuiFade(borderColor, guiAlpha));
  4214. DrawRectangle((int)rec.x + (int)rec.width - borderWidth, (int)rec.y + borderWidth, borderWidth, (int)rec.height - 2*borderWidth, GuiFade(borderColor, guiAlpha));
  4215. DrawRectangle((int)rec.x, (int)rec.y + (int)rec.height - borderWidth, (int)rec.width, borderWidth, GuiFade(borderColor, guiAlpha));
  4216. }
  4217. #if defined(RAYGUI_DEBUG_RECS_BOUNDS)
  4218. DrawRectangle((int)rec.x, (int)rec.y, (int)rec.width, (int)rec.height, Fade(RED, 0.4f));
  4219. #endif
  4220. }
  4221. // Draw tooltip using control bounds
  4222. static void GuiTooltip(Rectangle controlRec)
  4223. {
  4224. if (!guiLocked && guiTooltip && (guiTooltipPtr != NULL) && !guiSliderDragging)
  4225. {
  4226. Vector2 textSize = MeasureTextEx(GuiGetFont(), guiTooltipPtr, (float)GuiGetStyle(DEFAULT, TEXT_SIZE), (float)GuiGetStyle(DEFAULT, TEXT_SPACING));
  4227. if ((controlRec.x + textSize.x + 16) > GetScreenWidth()) controlRec.x -= (textSize.x + 16 - controlRec.width);
  4228. GuiPanel(RAYGUI_CLITERAL(Rectangle){ controlRec.x, controlRec.y + controlRec.height + 4, textSize.x + 16, GuiGetStyle(DEFAULT, TEXT_SIZE) + 8.f }, NULL);
  4229. int textPadding = GuiGetStyle(LABEL, TEXT_PADDING);
  4230. int textAlignment = GuiGetStyle(LABEL, TEXT_ALIGNMENT);
  4231. GuiSetStyle(LABEL, TEXT_PADDING, 0);
  4232. GuiSetStyle(LABEL, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
  4233. GuiLabel(RAYGUI_CLITERAL(Rectangle){ controlRec.x, controlRec.y + controlRec.height + 4, textSize.x + 16, GuiGetStyle(DEFAULT, TEXT_SIZE) + 8.f }, guiTooltipPtr);
  4234. GuiSetStyle(LABEL, TEXT_ALIGNMENT, textAlignment);
  4235. GuiSetStyle(LABEL, TEXT_PADDING, textPadding);
  4236. }
  4237. }
  4238. // Split controls text into multiple strings
  4239. // Also check for multiple columns (required by GuiToggleGroup())
  4240. static const char **GuiTextSplit(const char *text, char delimiter, int *count, int *textRow)
  4241. {
  4242. // NOTE: Current implementation returns a copy of the provided string with '\0' (string end delimiter)
  4243. // inserted between strings defined by "delimiter" parameter. No memory is dynamically allocated,
  4244. // all used memory is static... it has some limitations:
  4245. // 1. Maximum number of possible split strings is set by RAYGUI_TEXTSPLIT_MAX_ITEMS
  4246. // 2. Maximum size of text to split is RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE
  4247. // NOTE: Those definitions could be externally provided if required
  4248. // TODO: HACK: GuiTextSplit() - Review how textRows are returned to user
  4249. // textRow is an externally provided array of integers that stores row number for every splitted string
  4250. #if !defined(RAYGUI_TEXTSPLIT_MAX_ITEMS)
  4251. #define RAYGUI_TEXTSPLIT_MAX_ITEMS 128
  4252. #endif
  4253. #if !defined(RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE)
  4254. #define RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE 1024
  4255. #endif
  4256. static const char *result[RAYGUI_TEXTSPLIT_MAX_ITEMS] = { NULL }; // String pointers array (points to buffer data)
  4257. static char buffer[RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE] = { 0 }; // Buffer data (text input copy with '\0' added)
  4258. memset(buffer, 0, RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE);
  4259. result[0] = buffer;
  4260. int counter = 1;
  4261. if (textRow != NULL) textRow[0] = 0;
  4262. // Count how many substrings we have on text and point to every one
  4263. for (int i = 0; i < RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE; i++)
  4264. {
  4265. buffer[i] = text[i];
  4266. if (buffer[i] == '\0') break;
  4267. else if ((buffer[i] == delimiter) || (buffer[i] == '\n'))
  4268. {
  4269. result[counter] = buffer + i + 1;
  4270. if (textRow != NULL)
  4271. {
  4272. if (buffer[i] == '\n') textRow[counter] = textRow[counter - 1] + 1;
  4273. else textRow[counter] = textRow[counter - 1];
  4274. }
  4275. buffer[i] = '\0'; // Set an end of string at this point
  4276. counter++;
  4277. if (counter == RAYGUI_TEXTSPLIT_MAX_ITEMS) break;
  4278. }
  4279. }
  4280. *count = counter;
  4281. return result;
  4282. }
  4283. // Convert color data from RGB to HSV
  4284. // NOTE: Color data should be passed normalized
  4285. static Vector3 ConvertRGBtoHSV(Vector3 rgb)
  4286. {
  4287. Vector3 hsv = { 0 };
  4288. float min = 0.0f;
  4289. float max = 0.0f;
  4290. float delta = 0.0f;
  4291. min = (rgb.x < rgb.y)? rgb.x : rgb.y;
  4292. min = (min < rgb.z)? min : rgb.z;
  4293. max = (rgb.x > rgb.y)? rgb.x : rgb.y;
  4294. max = (max > rgb.z)? max : rgb.z;
  4295. hsv.z = max; // Value
  4296. delta = max - min;
  4297. if (delta < 0.00001f)
  4298. {
  4299. hsv.y = 0.0f;
  4300. hsv.x = 0.0f; // Undefined, maybe NAN?
  4301. return hsv;
  4302. }
  4303. if (max > 0.0f)
  4304. {
  4305. // NOTE: If max is 0, this divide would cause a crash
  4306. hsv.y = (delta/max); // Saturation
  4307. }
  4308. else
  4309. {
  4310. // NOTE: If max is 0, then r = g = b = 0, s = 0, h is undefined
  4311. hsv.y = 0.0f;
  4312. hsv.x = 0.0f; // Undefined, maybe NAN?
  4313. return hsv;
  4314. }
  4315. // NOTE: Comparing float values could not work properly
  4316. if (rgb.x >= max) hsv.x = (rgb.y - rgb.z)/delta; // Between yellow & magenta
  4317. else
  4318. {
  4319. if (rgb.y >= max) hsv.x = 2.0f + (rgb.z - rgb.x)/delta; // Between cyan & yellow
  4320. else hsv.x = 4.0f + (rgb.x - rgb.y)/delta; // Between magenta & cyan
  4321. }
  4322. hsv.x *= 60.0f; // Convert to degrees
  4323. if (hsv.x < 0.0f) hsv.x += 360.0f;
  4324. return hsv;
  4325. }
  4326. // Convert color data from HSV to RGB
  4327. // NOTE: Color data should be passed normalized
  4328. static Vector3 ConvertHSVtoRGB(Vector3 hsv)
  4329. {
  4330. Vector3 rgb = { 0 };
  4331. float hh = 0.0f, p = 0.0f, q = 0.0f, t = 0.0f, ff = 0.0f;
  4332. long i = 0;
  4333. // NOTE: Comparing float values could not work properly
  4334. if (hsv.y <= 0.0f)
  4335. {
  4336. rgb.x = hsv.z;
  4337. rgb.y = hsv.z;
  4338. rgb.z = hsv.z;
  4339. return rgb;
  4340. }
  4341. hh = hsv.x;
  4342. if (hh >= 360.0f) hh = 0.0f;
  4343. hh /= 60.0f;
  4344. i = (long)hh;
  4345. ff = hh - i;
  4346. p = hsv.z*(1.0f - hsv.y);
  4347. q = hsv.z*(1.0f - (hsv.y*ff));
  4348. t = hsv.z*(1.0f - (hsv.y*(1.0f - ff)));
  4349. switch (i)
  4350. {
  4351. case 0:
  4352. {
  4353. rgb.x = hsv.z;
  4354. rgb.y = t;
  4355. rgb.z = p;
  4356. } break;
  4357. case 1:
  4358. {
  4359. rgb.x = q;
  4360. rgb.y = hsv.z;
  4361. rgb.z = p;
  4362. } break;
  4363. case 2:
  4364. {
  4365. rgb.x = p;
  4366. rgb.y = hsv.z;
  4367. rgb.z = t;
  4368. } break;
  4369. case 3:
  4370. {
  4371. rgb.x = p;
  4372. rgb.y = q;
  4373. rgb.z = hsv.z;
  4374. } break;
  4375. case 4:
  4376. {
  4377. rgb.x = t;
  4378. rgb.y = p;
  4379. rgb.z = hsv.z;
  4380. } break;
  4381. case 5:
  4382. default:
  4383. {
  4384. rgb.x = hsv.z;
  4385. rgb.y = p;
  4386. rgb.z = q;
  4387. } break;
  4388. }
  4389. return rgb;
  4390. }
  4391. // Scroll bar control (used by GuiScrollPanel())
  4392. static int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue)
  4393. {
  4394. GuiState state = guiState;
  4395. // Is the scrollbar horizontal or vertical?
  4396. bool isVertical = (bounds.width > bounds.height)? false : true;
  4397. // The size (width or height depending on scrollbar type) of the spinner buttons
  4398. const int spinnerSize = GuiGetStyle(SCROLLBAR, ARROWS_VISIBLE)?
  4399. (isVertical? (int)bounds.width - 2*GuiGetStyle(SCROLLBAR, BORDER_WIDTH) :
  4400. (int)bounds.height - 2*GuiGetStyle(SCROLLBAR, BORDER_WIDTH)) : 0;
  4401. // Arrow buttons [<] [>] [∧] [∨]
  4402. Rectangle arrowUpLeft = { 0 };
  4403. Rectangle arrowDownRight = { 0 };
  4404. // Actual area of the scrollbar excluding the arrow buttons
  4405. Rectangle scrollbar = { 0 };
  4406. // Slider bar that moves --[///]-----
  4407. Rectangle slider = { 0 };
  4408. // Normalize value
  4409. if (value > maxValue) value = maxValue;
  4410. if (value < minValue) value = minValue;
  4411. const int valueRange = maxValue - minValue;
  4412. int sliderSize = GuiGetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE);
  4413. // Calculate rectangles for all of the components
  4414. arrowUpLeft = RAYGUI_CLITERAL(Rectangle){
  4415. (float)bounds.x + GuiGetStyle(SCROLLBAR, BORDER_WIDTH),
  4416. (float)bounds.y + GuiGetStyle(SCROLLBAR, BORDER_WIDTH),
  4417. (float)spinnerSize, (float)spinnerSize };
  4418. if (isVertical)
  4419. {
  4420. 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 };
  4421. 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) };
  4422. // Make sure the slider won't get outside of the scrollbar
  4423. sliderSize = (sliderSize >= scrollbar.height)? ((int)scrollbar.height - 2) : sliderSize;
  4424. slider = RAYGUI_CLITERAL(Rectangle){
  4425. bounds.x + GuiGetStyle(SCROLLBAR, BORDER_WIDTH) + GuiGetStyle(SCROLLBAR, SCROLL_SLIDER_PADDING),
  4426. scrollbar.y + (int)(((float)(value - minValue)/valueRange)*(scrollbar.height - sliderSize)),
  4427. bounds.width - 2*(GuiGetStyle(SCROLLBAR, BORDER_WIDTH) + GuiGetStyle(SCROLLBAR, SCROLL_SLIDER_PADDING)),
  4428. (float)sliderSize };
  4429. }
  4430. else // horizontal
  4431. {
  4432. 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 };
  4433. 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)) };
  4434. // Make sure the slider won't get outside of the scrollbar
  4435. sliderSize = (sliderSize >= scrollbar.width)? ((int)scrollbar.width - 2) : sliderSize;
  4436. slider = RAYGUI_CLITERAL(Rectangle){
  4437. scrollbar.x + (int)(((float)(value - minValue)/valueRange)*(scrollbar.width - sliderSize)),
  4438. bounds.y + GuiGetStyle(SCROLLBAR, BORDER_WIDTH) + GuiGetStyle(SCROLLBAR, SCROLL_SLIDER_PADDING),
  4439. (float)sliderSize,
  4440. bounds.height - 2*(GuiGetStyle(SCROLLBAR, BORDER_WIDTH) + GuiGetStyle(SCROLLBAR, SCROLL_SLIDER_PADDING)) };
  4441. }
  4442. // Update control
  4443. //--------------------------------------------------------------------
  4444. if ((state != STATE_DISABLED) && !guiLocked)
  4445. {
  4446. Vector2 mousePoint = GetMousePosition();
  4447. if (guiSliderDragging) // Keep dragging outside of bounds
  4448. {
  4449. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) &&
  4450. !CheckCollisionPointRec(mousePoint, arrowUpLeft) &&
  4451. !CheckCollisionPointRec(mousePoint, arrowDownRight))
  4452. {
  4453. if (CHECK_BOUNDS_ID(bounds, guiSliderActive))
  4454. {
  4455. state = STATE_PRESSED;
  4456. if (isVertical) value = (int)(((float)(mousePoint.y - scrollbar.y - slider.height/2)*valueRange)/(scrollbar.height - slider.height) + minValue);
  4457. else value = (int)(((float)(mousePoint.x - scrollbar.x - slider.width/2)*valueRange)/(scrollbar.width - slider.width) + minValue);
  4458. }
  4459. }
  4460. else
  4461. {
  4462. guiSliderDragging = false;
  4463. guiSliderActive = RAYGUI_CLITERAL(Rectangle){ 0, 0, 0, 0 };
  4464. }
  4465. }
  4466. else if (CheckCollisionPointRec(mousePoint, bounds))
  4467. {
  4468. state = STATE_FOCUSED;
  4469. // Handle mouse wheel
  4470. int wheel = (int)GetMouseWheelMove();
  4471. if (wheel != 0) value += wheel;
  4472. // Handle mouse button down
  4473. if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
  4474. {
  4475. guiSliderDragging = true;
  4476. guiSliderActive = bounds; // Store bounds as an identifier when dragging starts
  4477. // Check arrows click
  4478. if (CheckCollisionPointRec(mousePoint, arrowUpLeft)) value -= valueRange/GuiGetStyle(SCROLLBAR, SCROLL_SPEED);
  4479. else if (CheckCollisionPointRec(mousePoint, arrowDownRight)) value += valueRange/GuiGetStyle(SCROLLBAR, SCROLL_SPEED);
  4480. else if (!CheckCollisionPointRec(mousePoint, slider))
  4481. {
  4482. // If click on scrollbar position but not on slider, place slider directly on that position
  4483. if (isVertical) value = (int)(((float)(mousePoint.y - scrollbar.y - slider.height/2)*valueRange)/(scrollbar.height - slider.height) + minValue);
  4484. else value = (int)(((float)(mousePoint.x - scrollbar.x - slider.width/2)*valueRange)/(scrollbar.width - slider.width) + minValue);
  4485. }
  4486. state = STATE_PRESSED;
  4487. }
  4488. // Keyboard control on mouse hover scrollbar
  4489. /*
  4490. if (isVertical)
  4491. {
  4492. if (IsKeyDown(KEY_DOWN)) value += 5;
  4493. else if (IsKeyDown(KEY_UP)) value -= 5;
  4494. }
  4495. else
  4496. {
  4497. if (IsKeyDown(KEY_RIGHT)) value += 5;
  4498. else if (IsKeyDown(KEY_LEFT)) value -= 5;
  4499. }
  4500. */
  4501. }
  4502. // Normalize value
  4503. if (value > maxValue) value = maxValue;
  4504. if (value < minValue) value = minValue;
  4505. }
  4506. //--------------------------------------------------------------------
  4507. // Draw control
  4508. //--------------------------------------------------------------------
  4509. GuiDrawRectangle(bounds, GuiGetStyle(SCROLLBAR, BORDER_WIDTH), GetColor(GuiGetStyle(LISTVIEW, BORDER + state*3)), GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED))); // Draw the background
  4510. GuiDrawRectangle(scrollbar, 0, BLANK, GetColor(GuiGetStyle(BUTTON, BASE_COLOR_NORMAL))); // Draw the scrollbar active area background
  4511. GuiDrawRectangle(slider, 0, BLANK, GetColor(GuiGetStyle(SLIDER, BORDER + state*3))); // Draw the slider bar
  4512. // Draw arrows (using icon if available)
  4513. if (GuiGetStyle(SCROLLBAR, ARROWS_VISIBLE))
  4514. {
  4515. #if defined(RAYGUI_NO_ICONS)
  4516. GuiDrawText(isVertical? "^" : "<",
  4517. RAYGUI_CLITERAL(Rectangle){ arrowUpLeft.x, arrowUpLeft.y, isVertical? bounds.width : bounds.height, isVertical? bounds.width : bounds.height },
  4518. TEXT_ALIGN_CENTER, GetColor(GuiGetStyle(DROPDOWNBOX, TEXT + (state*3))));
  4519. GuiDrawText(isVertical? "v" : ">",
  4520. RAYGUI_CLITERAL(Rectangle){ arrowDownRight.x, arrowDownRight.y, isVertical? bounds.width : bounds.height, isVertical? bounds.width : bounds.height },
  4521. TEXT_ALIGN_CENTER, GetColor(GuiGetStyle(DROPDOWNBOX, TEXT + (state*3))));
  4522. #else
  4523. GuiDrawText(isVertical? "#121#" : "#118#",
  4524. RAYGUI_CLITERAL(Rectangle){ arrowUpLeft.x, arrowUpLeft.y, isVertical? bounds.width : bounds.height, isVertical? bounds.width : bounds.height },
  4525. TEXT_ALIGN_CENTER, GetColor(GuiGetStyle(SCROLLBAR, TEXT + state*3))); // ICON_ARROW_UP_FILL / ICON_ARROW_LEFT_FILL
  4526. GuiDrawText(isVertical? "#120#" : "#119#",
  4527. RAYGUI_CLITERAL(Rectangle){ arrowDownRight.x, arrowDownRight.y, isVertical? bounds.width : bounds.height, isVertical? bounds.width : bounds.height },
  4528. TEXT_ALIGN_CENTER, GetColor(GuiGetStyle(SCROLLBAR, TEXT + state*3))); // ICON_ARROW_DOWN_FILL / ICON_ARROW_RIGHT_FILL
  4529. #endif
  4530. }
  4531. //--------------------------------------------------------------------
  4532. return value;
  4533. }
  4534. // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f
  4535. // WARNING: It multiplies current alpha by alpha scale factor
  4536. static Color GuiFade(Color color, float alpha)
  4537. {
  4538. if (alpha < 0.0f) alpha = 0.0f;
  4539. else if (alpha > 1.0f) alpha = 1.0f;
  4540. Color result = { color.r, color.g, color.b, (unsigned char)(color.a*alpha) };
  4541. return result;
  4542. }
  4543. #if defined(RAYGUI_STANDALONE)
  4544. // Returns a Color struct from hexadecimal value
  4545. static Color GetColor(int hexValue)
  4546. {
  4547. Color color;
  4548. color.r = (unsigned char)(hexValue >> 24) & 0xFF;
  4549. color.g = (unsigned char)(hexValue >> 16) & 0xFF;
  4550. color.b = (unsigned char)(hexValue >> 8) & 0xFF;
  4551. color.a = (unsigned char)hexValue & 0xFF;
  4552. return color;
  4553. }
  4554. // Returns hexadecimal value for a Color
  4555. static int ColorToInt(Color color)
  4556. {
  4557. return (((int)color.r << 24) | ((int)color.g << 16) | ((int)color.b << 8) | (int)color.a);
  4558. }
  4559. // Check if point is inside rectangle
  4560. static bool CheckCollisionPointRec(Vector2 point, Rectangle rec)
  4561. {
  4562. bool collision = false;
  4563. if ((point.x >= rec.x) && (point.x <= (rec.x + rec.width)) &&
  4564. (point.y >= rec.y) && (point.y <= (rec.y + rec.height))) collision = true;
  4565. return collision;
  4566. }
  4567. // Formatting of text with variables to 'embed'
  4568. static const char *TextFormat(const char *text, ...)
  4569. {
  4570. #if !defined(RAYGUI_TEXTFORMAT_MAX_SIZE)
  4571. #define RAYGUI_TEXTFORMAT_MAX_SIZE 256
  4572. #endif
  4573. static char buffer[RAYGUI_TEXTFORMAT_MAX_SIZE];
  4574. va_list args;
  4575. va_start(args, text);
  4576. vsprintf(buffer, text, args);
  4577. va_end(args);
  4578. return buffer;
  4579. }
  4580. // Draw rectangle with vertical gradient fill color
  4581. // NOTE: This function is only used by GuiColorPicker()
  4582. static void DrawRectangleGradientV(int posX, int posY, int width, int height, Color color1, Color color2)
  4583. {
  4584. Rectangle bounds = { (float)posX, (float)posY, (float)width, (float)height };
  4585. DrawRectangleGradientEx(bounds, color1, color2, color2, color1);
  4586. }
  4587. // Split string into multiple strings
  4588. const char **TextSplit(const char *text, char delimiter, int *count)
  4589. {
  4590. // NOTE: Current implementation returns a copy of the provided string with '\0' (string end delimiter)
  4591. // inserted between strings defined by "delimiter" parameter. No memory is dynamically allocated,
  4592. // all used memory is static... it has some limitations:
  4593. // 1. Maximum number of possible split strings is set by RAYGUI_TEXTSPLIT_MAX_ITEMS
  4594. // 2. Maximum size of text to split is RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE
  4595. #if !defined(RAYGUI_TEXTSPLIT_MAX_ITEMS)
  4596. #define RAYGUI_TEXTSPLIT_MAX_ITEMS 128
  4597. #endif
  4598. #if !defined(RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE)
  4599. #define RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE 1024
  4600. #endif
  4601. static const char *result[RAYGUI_TEXTSPLIT_MAX_ITEMS] = { NULL };
  4602. static char buffer[RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE] = { 0 };
  4603. memset(buffer, 0, RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE);
  4604. result[0] = buffer;
  4605. int counter = 0;
  4606. if (text != NULL)
  4607. {
  4608. counter = 1;
  4609. // Count how many substrings we have on text and point to every one
  4610. for (int i = 0; i < RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE; i++)
  4611. {
  4612. buffer[i] = text[i];
  4613. if (buffer[i] == '\0') break;
  4614. else if (buffer[i] == delimiter)
  4615. {
  4616. buffer[i] = '\0'; // Set an end of string at this point
  4617. result[counter] = buffer + i + 1;
  4618. counter++;
  4619. if (counter == RAYGUI_TEXTSPLIT_MAX_ITEMS) break;
  4620. }
  4621. }
  4622. }
  4623. *count = counter;
  4624. return result;
  4625. }
  4626. // Get integer value from text
  4627. // NOTE: This function replaces atoi() [stdlib.h]
  4628. static int TextToInteger(const char *text)
  4629. {
  4630. int value = 0;
  4631. int sign = 1;
  4632. if ((text[0] == '+') || (text[0] == '-'))
  4633. {
  4634. if (text[0] == '-') sign = -1;
  4635. text++;
  4636. }
  4637. for (int i = 0; ((text[i] >= '0') && (text[i] <= '9')); ++i) value = value*10 + (int)(text[i] - '0');
  4638. return value*sign;
  4639. }
  4640. // Encode codepoint into UTF-8 text (char array size returned as parameter)
  4641. static const char *CodepointToUTF8(int codepoint, int *byteSize)
  4642. {
  4643. static char utf8[6] = { 0 };
  4644. int size = 0;
  4645. if (codepoint <= 0x7f)
  4646. {
  4647. utf8[0] = (char)codepoint;
  4648. size = 1;
  4649. }
  4650. else if (codepoint <= 0x7ff)
  4651. {
  4652. utf8[0] = (char)(((codepoint >> 6) & 0x1f) | 0xc0);
  4653. utf8[1] = (char)((codepoint & 0x3f) | 0x80);
  4654. size = 2;
  4655. }
  4656. else if (codepoint <= 0xffff)
  4657. {
  4658. utf8[0] = (char)(((codepoint >> 12) & 0x0f) | 0xe0);
  4659. utf8[1] = (char)(((codepoint >> 6) & 0x3f) | 0x80);
  4660. utf8[2] = (char)((codepoint & 0x3f) | 0x80);
  4661. size = 3;
  4662. }
  4663. else if (codepoint <= 0x10ffff)
  4664. {
  4665. utf8[0] = (char)(((codepoint >> 18) & 0x07) | 0xf0);
  4666. utf8[1] = (char)(((codepoint >> 12) & 0x3f) | 0x80);
  4667. utf8[2] = (char)(((codepoint >> 6) & 0x3f) | 0x80);
  4668. utf8[3] = (char)((codepoint & 0x3f) | 0x80);
  4669. size = 4;
  4670. }
  4671. *byteSize = size;
  4672. return utf8;
  4673. }
  4674. // Get next codepoint in a UTF-8 encoded text, scanning until '\0' is found
  4675. // When a invalid UTF-8 byte is encountered we exit as soon as possible and a '?'(0x3f) codepoint is returned
  4676. // Total number of bytes processed are returned as a parameter
  4677. // NOTE: the standard says U+FFFD should be returned in case of errors
  4678. // but that character is not supported by the default font in raylib
  4679. static int GetCodepointNext(const char *text, int *codepointSize)
  4680. {
  4681. const char *ptr = text;
  4682. int codepoint = 0x3f; // Codepoint (defaults to '?')
  4683. *codepointSize = 1;
  4684. // Get current codepoint and bytes processed
  4685. if (0xf0 == (0xf8 & ptr[0]))
  4686. {
  4687. // 4 byte UTF-8 codepoint
  4688. if(((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80) || ((ptr[3] & 0xC0) ^ 0x80)) { return codepoint; } //10xxxxxx checks
  4689. codepoint = ((0x07 & ptr[0]) << 18) | ((0x3f & ptr[1]) << 12) | ((0x3f & ptr[2]) << 6) | (0x3f & ptr[3]);
  4690. *codepointSize = 4;
  4691. }
  4692. else if (0xe0 == (0xf0 & ptr[0]))
  4693. {
  4694. // 3 byte UTF-8 codepoint */
  4695. if(((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80)) { return codepoint; } //10xxxxxx checks
  4696. codepoint = ((0x0f & ptr[0]) << 12) | ((0x3f & ptr[1]) << 6) | (0x3f & ptr[2]);
  4697. *codepointSize = 3;
  4698. }
  4699. else if (0xc0 == (0xe0 & ptr[0]))
  4700. {
  4701. // 2 byte UTF-8 codepoint
  4702. if((ptr[1] & 0xC0) ^ 0x80) { return codepoint; } //10xxxxxx checks
  4703. codepoint = ((0x1f & ptr[0]) << 6) | (0x3f & ptr[1]);
  4704. *codepointSize = 2;
  4705. }
  4706. else if (0x00 == (0x80 & ptr[0]))
  4707. {
  4708. // 1 byte UTF-8 codepoint
  4709. codepoint = ptr[0];
  4710. *codepointSize = 1;
  4711. }
  4712. return codepoint;
  4713. }
  4714. #endif // RAYGUI_STANDALONE
  4715. #endif // RAYGUI_IMPLEMENTATION