Last active
August 2, 2024 00:58
-
-
Save JettMonstersGoBoom/4ea50df7ba3bfef1d5d8f027fcc4f747 to your computer and use it in GitHub Desktop.
menu bar hack for raygui.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const char *Menu[]= | |
{ | |
"File:#05# Open:#06# Save:#01# Open PRJ:#02# Save PRJ:#113#Exit", | |
"Edit:#56#Undo:#57#Redo:#17#Cut:#16#Copy:#18#Paste", | |
"Demo:#56#Stuff:#57#Things", | |
NULL | |
}; | |
static int FocusedGuiRect(Rectangle bounds) | |
{ | |
int result = 0; | |
GuiState state = GuiGetState(); | |
if ((state != STATE_DISABLED) && !guiLocked && !guiSliderDragging) | |
{ | |
Vector2 mousePoint = GetMousePosition(); | |
// Check button state | |
if (CheckCollisionPointRec(mousePoint, bounds)) | |
{ | |
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) | |
state = STATE_PRESSED; | |
else | |
state = STATE_FOCUSED; | |
} | |
} | |
return (state); | |
} | |
// returns 16 bit number | |
// 11111111-------- menu index | |
// --------11111111 submenu index | |
// 0x0103 menu 1, subutem 3 | |
unsigned short GuiShowMenuAscii(char **menu,int w,int h) | |
{ | |
static int GuiShowMenuAsciiOpen = -1; | |
bool isFocused = false; | |
unsigned short ret = 0; | |
// full bar across | |
GuiStatusBar((Rectangle){0,0,GetScreenWidth(),h},""); | |
for (int m=0;menu[m]!=NULL;m++) | |
{ | |
Rectangle rect=(Rectangle){m*w,0,w,h}; | |
char *ent = strdup(menu[m]); | |
char *tok = strtok(ent,":"); | |
if (FocusedGuiRect(rect)) isFocused=true; | |
if (GuiButton(rect,TextFormat(" %s",tok))) GuiShowMenuAsciiOpen = m; | |
int subItem=0; | |
if (GuiShowMenuAsciiOpen==m) | |
{ | |
while(tok!=NULL) | |
{ | |
rect.y+=h; | |
tok = strtok(NULL,":"); | |
subItem++; | |
if (tok!=NULL) | |
{ | |
if (FocusedGuiRect(rect)) isFocused=true; | |
if (GuiButton(rect,tok)) | |
{ | |
ret = (m<<8) | subItem; | |
} | |
} | |
} | |
} | |
free(ent); | |
} | |
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && (isFocused==false)) | |
GuiShowMenuAsciiOpen = -1; | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment