Files
discoverpixy/common/gui/screen.c
2015-04-27 23:59:00 +02:00

69 lines
1.7 KiB
C

#include "screen.h"
static volatile SCREEN_STRUCT* screen_list = NULL;
static volatile SCREEN_STRUCT* screen_current = NULL;
static volatile SCREEN_STRUCT* screen_goto = NULL;
SCREEN_STRUCT* gui_screen_get_current() {
return screen_current;
}
void gui_screen_update() {
if(screen_goto!=NULL) { //we received the task to switch the screen
SCREEN_STRUCT* go = screen_goto; //Backup volatile variable
screen_goto=NULL;
if(go->next!=NULL) { //we're going back
if(go->next!=screen_current) return; //list corrupted?
screen_current->on_leave(screen_current);
go->next=NULL;
} else { //we're going forward
if(screen_current!=NULL) { //this is not the first screen
screen_current->on_leave(screen_current);
screen_current->next = go;
} else { //first screen ever seen
screen_list=go;
}
}
go->on_enter(go);
screen_current = go;
}
if(screen_current!=NULL) { //A screen has been set
screen_current->on_update(screen_current); //Update current screen
}
}
bool gui_screen_navigate(SCREEN_STRUCT* screen) {
if(screen==NULL) return false;
screen->next = NULL;
screen_goto=screen; //send message to main loop, to switch the screen
return true;
}
bool gui_screen_back() {
if(screen_list==NULL) return false;
SCREEN_STRUCT* current = screen_list;
SCREEN_STRUCT* last = NULL;
//Find second last element in list
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?
screen_goto=last; //send message to main loop, to switch the screen
return true;
}