Introduced a Screen (sub) module and divided app into multiple screens.
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
#ifndef BUTTON_H
|
||||
#define BUTTON_H
|
||||
|
||||
|
||||
#include "touch.h"
|
||||
|
||||
|
||||
typedef void (*BUTTON_CALLBACK)(void *button); //!< Function pointer used...
|
||||
typedef struct {
|
||||
@@ -31,5 +37,8 @@ void gui_button_redraw(BUTTON_STRUCT* button);
|
||||
bool guiAddBitmapButton(BITMAPBUTTON_STRUCT* button);
|
||||
void guiRemoveBitmapButton(BITMAPBUTTON_STRUCT* button);
|
||||
void guiRedrawBitmapButton(BITMAPBUTTON_STRUCT* button);
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#endif /* BUTTON_H */
|
||||
|
||||
58
common/gui/screen.c
Normal file
58
common/gui/screen.c
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "screen.h"
|
||||
|
||||
|
||||
static SCREEN_STRUCT* screen_list = NULL;
|
||||
static SCREEN_STRUCT* screen_current = NULL;
|
||||
|
||||
|
||||
SCREEN_STRUCT* gui_screen_get_current() {
|
||||
return screen_current;
|
||||
}
|
||||
|
||||
void gui_screen_update() {
|
||||
if(screen_current!=NULL) {
|
||||
screen_current->on_update(screen_current);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool gui_screen_navigate(SCREEN_STRUCT* screen) {
|
||||
if(screen==NULL) return false;
|
||||
screen->next = NULL;
|
||||
if(screen_current!=NULL) {
|
||||
screen_current->on_leave(screen_current);
|
||||
screen_current->next = screen;
|
||||
} else {
|
||||
screen_list=screen;
|
||||
}
|
||||
screen->on_enter(screen);
|
||||
screen_current = screen;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool gui_screen_back() {
|
||||
if(screen_list==NULL) return false;
|
||||
SCREEN_STRUCT* current = screen_list;
|
||||
SCREEN_STRUCT* last = NULL;
|
||||
while(current->next != NULL) {
|
||||
last = current;
|
||||
current = current->next;
|
||||
}
|
||||
if(last==NULL) return false; //There's only a single screen.
|
||||
if(current!=screen_current) return false; //List corrupted?
|
||||
current->on_leave(current);
|
||||
last->next=NULL;
|
||||
last->on_enter(last);
|
||||
screen_current=last;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
25
common/gui/screen.h
Normal file
25
common/gui/screen.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef SCREEN_H
|
||||
#define SCREEN_H
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef void (*SCREEN_CALLBACK)(void* screen); //!< Function pointer used...
|
||||
|
||||
typedef struct SCREEN_S{
|
||||
SCREEN_CALLBACK on_enter;
|
||||
SCREEN_CALLBACK on_leave;
|
||||
SCREEN_CALLBACK on_update;
|
||||
|
||||
|
||||
struct SCREEN_S* next; //Used internally. do not modify
|
||||
|
||||
} SCREEN_STRUCT;
|
||||
|
||||
bool gui_screen_navigate(SCREEN_STRUCT* screen);
|
||||
bool gui_screen_back();
|
||||
SCREEN_STRUCT* gui_screen_get_current();
|
||||
void gui_screen_update();
|
||||
|
||||
#endif /* SCREEN_H */
|
||||
Reference in New Issue
Block a user