Skip to content

Commit

Permalink
Implement a simple colored box menu item type and use that for the pr…
Browse files Browse the repository at this point in the history
…eview.
  • Loading branch information
Bobby Lovell committed Dec 14, 2023
1 parent 519bd95 commit 79fb976
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
7 changes: 3 additions & 4 deletions port/src/optionsmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,6 @@ static MenuItemHandlerResult menuhandlerCrosshairColorPreview(s32 operation, str
{
if (operation == MENUOP_GETCOLOUR) {
data->label.colour1 = g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour;
data->label.colour2 = g_PlayerExtCfg[g_ExtMenuPlayer].crosshaircolour;
}

return 0;
Expand Down Expand Up @@ -1019,10 +1018,10 @@ struct menuitem g_ExtendedGameCrosshairColourMenuItems[] = {
NULL,
},
{
MENUITEMTYPE_LABEL,
MENUITEMTYPE_COLORBOX,
0,
0,
0,
MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_LABEL_CUSTOMCOLOUR | MENUITEMFLAG_SELECTABLE_CENTRE,
(uintptr_t)"PREVIEW\n",
0,
menuhandlerCrosshairColorPreview,
},
Expand Down
3 changes: 3 additions & 0 deletions src/game/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,9 @@ bool menuIsItemFocusable(struct menuitem *item, struct menudialog *dialog, s32 a
case MENUITEMTYPE_METER:
case MENUITEMTYPE_MARQUEE:
case MENUITEMTYPE_CONTROLLER:
#ifndef PLATFORM_N64
case MENUITEMTYPE_COLORBOX:
#endif
return false;
case MENUITEMTYPE_10:
case MENUITEMTYPE_14:
Expand Down
31 changes: 31 additions & 0 deletions src/game/menuitem.c
Original file line number Diff line number Diff line change
Expand Up @@ -2109,6 +2109,36 @@ Gfx *menuitemMeterRender(Gfx *gdl, struct menurendercontext *context)
return gdl;
}

#ifndef PLATFORM_N64

// Draws a colored box which fills the background of the menu item.
Gfx* menuitemColorBoxRender(Gfx *gdl, struct menurendercontext *context)
{
u32 width = context->width;
u32 height = context->height;
u32 colour1;
s32 x1;
s32 x2;

x1 = context->x;
x2 = x1 + width;

union handlerdata data;
if (context->item->handlervoid) {
context->item->handlervoid(MENUOP_GETCOLOUR, context->item, &data);
}

colour1 = data.label.colour1;

gdl = textSetPrimColour(gdl, colour1);
gDPFillRectangleScaled(gdl++, x1, context->y, x2, context->y + height);
gdl = text0f153838(gdl);

return gdl;
}

#endif

Gfx *menuitemSelectableRender(Gfx *gdl, struct menurendercontext *context)
{
u32 leftcolour;
Expand Down Expand Up @@ -4349,6 +4379,7 @@ Gfx *menuitemRender(Gfx *gdl, struct menurendercontext *context)
case MENUITEMTYPE_CAROUSEL: return menuitemCarouselRender(gdl, context);
case MENUITEMTYPE_MODEL: return menuitemModelRender(gdl, context);
case MENUITEMTYPE_CONTROLLER: return menuitemControllerRender(gdl, context);
case MENUITEMTYPE_COLORBOX: return menuitemColorBoxRender(gdl, context);
}

return gdl;
Expand Down
4 changes: 4 additions & 0 deletions src/include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,10 @@
#define MENUITEMTYPE_CONTROLLER 0x19
#define MENUITEMTYPE_END 0x1a

#ifndef PLATFORM_N64
#define MENUITEMTYPE_COLORBOX 0x1b
#endif

#define MENUMODELFLAG_HASSCALE 0x01
#define MENUMODELFLAG_HASPOSITION 0x02
#define MENUMODELFLAG_HASROTATION 0x04
Expand Down
4 changes: 4 additions & 0 deletions src/include/game/menuitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Gfx *menuitemLabelRender(Gfx *gdl, struct menurendercontext *context);

Gfx *menuitemMeterRender(Gfx *gdl, struct menurendercontext *context);

#ifndef PLATFORM_N64
Gfx *menuitemColorBoxRender(Gfx *gdl, struct menurendercontext *context);
#endif

Gfx *menuitemSelectableRender(Gfx *gdl, struct menurendercontext *context);
bool menuitemSelectableTick(struct menuitem *item, struct menuinputs *inputs, u32 tickflags);

Expand Down

0 comments on commit 79fb976

Please sign in to comment.