Don't retain highlighted widget.

This commit is contained in:
Steve 2019-01-16 08:30:01 +00:00
parent d8aa7f70f2
commit 4887fd2a6c
2 changed files with 26 additions and 5 deletions

View File

@ -33,6 +33,7 @@ static void updateSelectWidgets(void);
static Widget head; static Widget head;
static Widget *tail; static Widget *tail;
static Widget *selectedWidget; static Widget *selectedWidget;
static Widget *hoverWidget;
static AtlasImage *optionsLeft; static AtlasImage *optionsLeft;
static AtlasImage *optionsRight; static AtlasImage *optionsRight;
static int drawingWidgets; static int drawingWidgets;
@ -68,6 +69,11 @@ void doWidgets(void)
handleControlWidgets(); handleControlWidgets();
} }
} }
if (hoverWidget != selectedWidget)
{
selectedWidget = NULL;
}
drawingWidgets = 0; drawingWidgets = 0;
} }
@ -124,6 +130,8 @@ void drawWidgets(const char *group)
drawingWidgets = 1; drawingWidgets = 1;
mouseOver = 0; mouseOver = 0;
hoverWidget = NULL;
for (w = head.next; w != NULL ; w = w->next) for (w = head.next; w != NULL ; w = w->next)
{ {
@ -133,19 +141,31 @@ void drawWidgets(const char *group)
{ {
mouseOver = (w->type != WT_SELECT && w->enabled && collision(w->rect.x, w->rect.y, w->rect.w, w->rect.h, app.uiMouse.x, app.uiMouse.y, 1, 1)); mouseOver = (w->type != WT_SELECT && w->enabled && collision(w->rect.x, w->rect.y, w->rect.w, w->rect.h, app.uiMouse.x, app.uiMouse.y, 1, 1));
if (mouseOver && selectedWidget != w) if (mouseOver)
{ {
if (w->type == WT_BUTTON || w->type == WT_CONTROL_CONFIG) hoverWidget = w;
if (selectedWidget != w)
{ {
playSound(SND_GUI_CLICK); if (w->type == WT_BUTTON || w->type == WT_IMG_BUTTON || w->type == WT_CONTROL_CONFIG)
} {
playSound(SND_GUI_CLICK);
}
selectedWidget = w; selectedWidget = w;
}
} }
} }
if (w->texture) if (w->texture)
{ {
setAtlasColor(255, 255, 255, 255);
if (selectedWidget == w)
{
setAtlasColor(128, 192, 255, 255);
}
blit(w->texture , w->rect.x, w->rect.y, 0); blit(w->texture , w->rect.x, w->rect.y, 0);
} }
else else

View File

@ -35,6 +35,7 @@ extern void playSound(int id);
extern char *readFile(char *filename); extern char *readFile(char *filename);
extern void updateControlButton(char *name); extern void updateControlButton(char *name);
extern void updateControlKey(char *name); extern void updateControlKey(char *name);
extern void setAtlasColor(int r, int g, int b, int a);
extern App app; extern App app;
extern Colors colors; extern Colors colors;