Permalink
Browse files

Some minor changes to force a rebuild

  • Loading branch information...
UnknownShadow200 committed Dec 7, 2018
1 parent 32fffb8 commit 6669d87cc12e20604c04029129c49886f4a31c4e
Showing with 114 additions and 21 deletions.
  1. +97 −14 src/LScreens.c
  2. +9 −5 src/LScreens.h
  3. +2 −2 src/LWidgets.h
  4. +6 −0 src/Launcher.c
@@ -8,6 +8,27 @@
*---------------------------------------------------------Screen base-----------------------------------------------------*
*#########################################################################################################################*/
static void LScreen_NullFunc(struct LScreen* s) { }
CC_NOINLINE static int LScreen_IndexOf(struct LScreen* s, void* w) {
int i;
for (i = 0; i < s->NumWidgets; i++) {
if (s->Widgets[i] == w) return i;
}
return -1;
}
CC_NOINLINE static struct LWidget* LScreen_WidgetAt(struct LScreen* s, int x, int y) {
struct LWidget* w;
int i = 0;
for (i = 0; i < s->NumWidgets; i++) {
w = s->Widgets[i];
if (w->Hidden) continue;
if (Gui_Contains(w->X, w->Y, w->Width, w->Height, w->X, w->Y)) return w;
}
return NULL;
}
static void LScreen_DrawAll(struct LScreen* s) {
struct LWidget* widget;
int i;
@@ -18,30 +39,98 @@ static void LScreen_DrawAll(struct LScreen* s) {
}
}
/*static void LScreen_KeyDown(struct LScreen* s, Key key) {
CC_NOINLINE static void LScreen_HandleTab(struct LScreen* s) {
struct LWidget* w;
int dir = Key_IsShiftPressed() ? -1 : 1;
int index = 0, i, j;
if (s->SelectedWidget) {
index = LScreen_IndexOf(s, s->SelectedWidget) + dir;
}
for (j = 0; j < s->NumWidgets; j++) {
i = (index + j * dir) % s->NumWidgets;
if (i < 0) i += s->NumWidgets;
w = s->Widgets[i];
if (w->Hidden || !w->TabSelectable) continue;
s->UnselectWidget(s, s->SelectedWidget);
s->SelectWidget(s, w);
return;
}
}
static void LScreen_KeyDown(struct LScreen* s, Key key) {
if (key == KEY_TAB) {
LScreen_HandleTab(s);
} else if (key == KEY_ENTER) {
if (s->SelectedWidget && s->SelectedWidget->OnClick) {
s->SelectedWidget->OnClick(s->SelectedWidget, Mouse_X, Mouse_Y);
} else if (s->OnEnterWidget) {
s->OnEnterWidget->OnClick(s->OnEnterWidget, Mouse_X, Mouse_Y);
}
}
}
static void LScreen_MouseDown(struct LScreen* s, MouseButton btn) {
struct LWidget* over = LScreen_WidgetAt(s, Mouse_X, Mouse_Y);
struct LWidget* prev = s->SelectedWidget;
if (over == prev) return;
if (prev) s->UnselectWidget(s, prev);
if (over) s->SelectWidget(s, over);
}
static void LScreen_MouseUp(struct LScreen* s, MouseButton btn) {
struct LWidget* over = LScreen_WidgetAt(s, Mouse_X, Mouse_Y);
struct LWidget* prev = s->SelectedWidget;
/* if user moves mouse away, it doesn't count */
if (over != prev) {
s->UnselectWidget(s, prev);
} else if (over && over->OnClick) {
over->OnClick(over, Mouse_X, Mouse_Y);
}
}
static void LScreen_MouseMove(struct LScreen* s, int deltaX, int deltaY) {
struct LWidget* over = LScreen_WidgetAt(s, Mouse_X, Mouse_Y);
struct LWidget* prev = s->HoveredWidget;
}*/
if (over == prev) return;
if (prev) s->UnhoverWidget(s, prev);
if (over) s->HoverWidget(s, over);
}
static void LScreen_HoverWidget(struct LScreen* s, struct LWidget* w) {
if (!w) return;
w->Hovered = true;
w->Hovered = true;
s->HoveredWidget = w;
if (w->VTABLE->OnHover) w->VTABLE->OnHover(w);
}
static void LScreen_UnhoverWidget(struct LScreen* s, struct LWidget* w) {
if (!w) return;
w->Hovered = false;
w->Hovered = false;
s->HoveredWidget = NULL;
if (w->VTABLE->OnUnhover) w->VTABLE->OnUnhover(w);
}
static void LScreen_SelectWidget(struct LScreen* s, struct LWidget* w) {
if (!w) return;
w->Selected = true;
s->SelectedWidget = w;
if (w->VTABLE->OnSelect) w->VTABLE->OnSelect(w);
}
static void LScreen_UnselectWidget(struct LScreen* s, struct LWidget* w) {
if (!w) return;
w->Selected = false;
s->SelectedWidget = NULL;
if (w->VTABLE->OnUnselect) w->VTABLE->OnUnselect(w);
}
CC_NOINLINE static void LScreen_Reset(struct LScreen* s) {
int i;
@@ -52,6 +141,7 @@ CC_NOINLINE static void LScreen_Reset(struct LScreen* s) {
s->OnDisplay = LScreen_NullFunc;
s->KeyDown = LScreen_KeyDown;
s->MouseDown = LScreen_MouseDown;
s->MouseUp = LScreen_MouseUp;
s->MouseMove = LScreen_MouseMove;
s->HoverWidget = LScreen_HoverWidget;
s->UnhoverWidget = LScreen_UnhoverWidget;
@@ -62,8 +152,9 @@ CC_NOINLINE static void LScreen_Reset(struct LScreen* s) {
s->Widgets[i]->Selected = false;
}
s->OnEnterWidget = NULL;
s->HoveredWidget = NULL;
s->OnEnterWidget = NULL;
s->HoveredWidget = NULL;
s->SelectedWidget = NULL;
}
@@ -110,14 +201,6 @@ CC_NOINLINE static void LScreen_Slider(struct LScreen* s, struct LSlider* w, int
LWidget_SetLocation(w, horAnchor, verAnchor, xOffset, yOffset);
}
CC_NOINLINE static int LScreen_IndexOf(struct LScreen* s, void* w) {
int i;
for (i = 0; i < s->NumWidgets; i++) {
if (s->Widgets[i] == w) return i;
}
return -1;
}
static void SwitchToChooseMode(void* w, int x, int y) {
Launcher_SetScreen(ChooseModeScreen_MakeInstance(false));
}
@@ -10,7 +10,7 @@ struct LWidget;
struct LScreen;
typedef void (*LScreen_Func)(struct LScreen* s);
typedef void (*LWidget_Func)(struct LScreen* s, struct LWidget* w);
typedef void(*LWidget_Func)(struct LScreen* s, struct LWidget* w);
#define LScreen_Layout \
LScreen_Func Init; /* Initialises widgets and other data. */ \
@@ -20,11 +20,15 @@ typedef void (*LWidget_Func)(struct LScreen* s, struct LWidget* w);
LScreen_Func OnDisplay; /* Called when framebuffer is about to be displayed. */ \
void (*KeyDown)(struct LScreen* s, Key key); \
void (*MouseDown)(struct LScreen* s, MouseButton btn); \
void (*MouseUp)(struct LScreen* s, MouseButton btn); \
void (*MouseMove)(struct LScreen* s, int deltaX, int deltaY); \
LWidget_Func HoverWidget; /* Called when mouse is moved over a given widget. */ \
LWidget_Func UnhoverWidget; /* Called when the mouse is moved away from a previously hovered widget. */ \
struct LWidget* OnEnterWidget; /* Default widget to auto-click when Enter is pressed. Can be NULL. */ \
struct LWidget* HoveredWidget; /* Widget the mouse is currently hovering over. */ \
LWidget_Func HoverWidget; /* Called when mouse is moved over a given widget. */ \
LWidget_Func UnhoverWidget; /* Called when the mouse is moved away from a previously hovered widget. */ \
LWidget_Func SelectWidget; /* Called when mouse clicks on a given widget. */ \
LWidget_Func UnselectWidget; /* Called when the mouse clicks on a different widget. */ \
struct LWidget* OnEnterWidget; /* Default widget to auto-click when Enter is pressed. Can be NULL. */ \
struct LWidget* HoveredWidget; /* Widget the mouse is currently hovering over. */ \
struct LWidget* SelectedWidget; /* Widget mouse last clicked on. */ \
int NumWidgets; /* Number of widgets actually used. */
struct LScreen {
@@ -17,9 +17,9 @@ struct LWidgetVTABLE {
/* Called when mouse clicks on this widget. */
/* NOTE: This function is just for general widget behaviour. */
/* OnClick callback is for per-widget instance behaviour. */
void (*OnSelected)(void* widget);
void (*OnSelect)(void* widget);
/* Called when mouse clicks on another widget. */
void (*OnUnselected)(void* widget);
void (*OnUnselect)(void* widget);
};
#define LWidget_Layout \
@@ -77,6 +77,10 @@ static void Launcher_MouseDown(void* obj, int btn) {
Launcher_Screen->MouseDown(Launcher_Screen, btn);
}
static void Launcher_MouseUp(void* obj, int btn) {
Launcher_Screen->MouseUp(Launcher_Screen, btn);
}
static void Launcher_MouseMove(void* obj, int deltaX, int deltaY) {
Launcher_Screen->MouseMove(Launcher_Screen, deltaX, deltaY);
}
@@ -123,6 +127,7 @@ static void Launcher_Init(void) {
Event_RegisterInt(&KeyEvents_Down, NULL, Launcher_KeyDown);
Event_RegisterInt(&MouseEvents_Down, NULL, Launcher_MouseDown);
Event_RegisterInt(&MouseEvents_Up, NULL, Launcher_MouseUp);
Event_RegisterMouseMove(&MouseEvents_Moved, NULL, Launcher_MouseMove);
Font_Make(&logoFont, &Drawer2D_FontName, 32, FONT_STYLE_NORMAL);
@@ -144,6 +149,7 @@ static void Launcher_Free(void) {
Event_UnregisterInt(&KeyEvents_Down, NULL, Launcher_KeyDown);
Event_UnregisterInt(&MouseEvents_Down, NULL, Launcher_MouseDown);
Event_UnregisterInt(&MouseEvents_Up, NULL, Launcher_MouseUp);
Event_UnregisterMouseMove(&MouseEvents_Moved, NULL, Launcher_MouseMove);
for (i = 0; i < FetchFlagsTask.NumDownloaded; i++) {

0 comments on commit 6669d87

Please sign in to comment.