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 *tail;
static Widget *selectedWidget;
static Widget *hoverWidget;
static AtlasImage *optionsLeft;
static AtlasImage *optionsRight;
static int drawingWidgets;
@ -69,6 +70,11 @@ void doWidgets(void)
}
}
if (hoverWidget != selectedWidget)
{
selectedWidget = NULL;
}
drawingWidgets = 0;
}
@ -125,6 +131,8 @@ void drawWidgets(const char *group)
drawingWidgets = 1;
mouseOver = 0;
hoverWidget = NULL;
for (w = head.next; w != NULL ; w = w->next)
{
if ((app.modalDialog.type == MD_NONE || (app.modalDialog.type != MD_NONE && w->isModal)) && w->visible && strcmp(w->group, group) == 0)
@ -133,9 +141,13 @@ 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));
if (mouseOver && selectedWidget != w)
if (mouseOver)
{
if (w->type == WT_BUTTON || w->type == WT_CONTROL_CONFIG)
hoverWidget = w;
if (selectedWidget != w)
{
if (w->type == WT_BUTTON || w->type == WT_IMG_BUTTON || w->type == WT_CONTROL_CONFIG)
{
playSound(SND_GUI_CLICK);
}
@ -143,9 +155,17 @@ void drawWidgets(const char *group)
selectedWidget = w;
}
}
}
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);
}
else

View File

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