forked from amberisvibin/bbs
prepare for compile time init of screens[]
This commit is contained in:
42
bbs.c
42
bbs.c
@@ -7,8 +7,6 @@
|
|||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "home.h"
|
#include "home.h"
|
||||||
|
|
||||||
#define MAX_ERROR_MESSAGE_SIZE 60 /* size of error_message array */
|
|
||||||
|
|
||||||
const unsigned int GETCH_TIMEOUT = 10; /* in ms */
|
const unsigned int GETCH_TIMEOUT = 10; /* in ms */
|
||||||
const char* LOCALE = "en_US.UTF-8"; /* enable unicode support, set to "ANSI_X3.4-1968" for ascii */
|
const char* LOCALE = "en_US.UTF-8"; /* enable unicode support, set to "ANSI_X3.4-1968" for ascii */
|
||||||
|
|
||||||
@@ -34,15 +32,11 @@ int main() {
|
|||||||
timeout(GETCH_TIMEOUT); /* set timeout for getch() */
|
timeout(GETCH_TIMEOUT); /* set timeout for getch() */
|
||||||
setlocale(LC_CTYPE, LOCALE); /* set locale, UTF8 support is enabled here */
|
setlocale(LC_CTYPE, LOCALE); /* set locale, UTF8 support is enabled here */
|
||||||
|
|
||||||
unsigned int start_y = 0;
|
|
||||||
unsigned int start_x = 0;
|
|
||||||
unsigned int terminal_width;
|
unsigned int terminal_width;
|
||||||
unsigned int terminal_height;
|
unsigned int terminal_height;
|
||||||
unsigned int old_terminal_width = 0;
|
unsigned int old_terminal_width = 0;
|
||||||
unsigned int old_terminal_height = 0;
|
unsigned int old_terminal_height = 0;
|
||||||
|
|
||||||
// struct Screen screens[MAX_SCREENS];
|
|
||||||
|
|
||||||
enum Status status = STATUS_NEED_REFRESH; /* refresh screens[active_screen].window on first loop */
|
enum Status status = STATUS_NEED_REFRESH; /* refresh screens[active_screen].window on first loop */
|
||||||
char input = ' ';
|
char input = ' ';
|
||||||
|
|
||||||
@@ -53,18 +47,32 @@ int main() {
|
|||||||
unsigned int screen_before_error = HOME;
|
unsigned int screen_before_error = HOME;
|
||||||
|
|
||||||
enum ActiveScreen active_screen = HOME;
|
enum ActiveScreen active_screen = HOME;
|
||||||
struct Screen home = {
|
|
||||||
"home",
|
struct Screen screens[] = {
|
||||||
newwin(terminal_height, terminal_width, start_y, start_x),
|
{
|
||||||
draw_home
|
"home",
|
||||||
|
newwin(terminal_height, terminal_width, 0, 0),
|
||||||
|
draw_home
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"error",
|
||||||
|
newwin(terminal_height, terminal_width, 0, 0),
|
||||||
|
draw_error
|
||||||
|
}
|
||||||
};
|
};
|
||||||
screens[HOME] = home;
|
|
||||||
struct Screen error = {
|
// struct Screen home = {
|
||||||
"error",
|
// "home",
|
||||||
newwin(terminal_height, terminal_width, start_y, start_x),
|
// newwin(terminal_height, terminal_width, start_y, start_x),
|
||||||
draw_error
|
// draw_home
|
||||||
};
|
// };
|
||||||
screens[ERROR] = error;
|
// screens[HOME] = home;
|
||||||
|
// struct Screen error = {
|
||||||
|
// "error",
|
||||||
|
// newwin(terminal_height, terminal_width, start_y, start_x),
|
||||||
|
// draw_error
|
||||||
|
// };
|
||||||
|
// screens[ERROR] = error;
|
||||||
|
|
||||||
/* main event loop */
|
/* main event loop */
|
||||||
while (status != STATUS_QUIT) {
|
while (status != STATUS_QUIT) {
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
/* SPDX-License-Identifier: MIT */
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
#define MAX_SCREENS 2 /* size of screens array */
|
#define MAX_ERROR_MESSAGE_SIZE 60 /* size of error_message array */
|
||||||
|
#define MAX_SCREEN_NAME_SIZE 20 /* size of the screen name array */
|
||||||
|
|
||||||
#ifndef GLOBALS_H /* header guard */
|
#ifndef GLOBALS_H /* header guard */
|
||||||
#define GLOBALS_H
|
#define GLOBALS_H
|
||||||
@@ -17,11 +18,13 @@ enum ActiveScreen {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Screen {
|
struct Screen {
|
||||||
char name[20];
|
char name[MAX_SCREEN_NAME_SIZE];
|
||||||
WINDOW *win;
|
WINDOW *win;
|
||||||
void (*draw_screen)(struct Screen *, char *input); /* GETCH_TIMEOUT determines how often this is run, in ms */
|
void (*draw_screen)(struct Screen *, char *input); /* GETCH_TIMEOUT determines how often this is run, in ms */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Screen screens[MAX_SCREENS];
|
/* TODO: put this in a screens.c file and include all screens there, that way the array can be initialized at compile
|
||||||
|
* time */
|
||||||
|
extern struct Screen screens[];
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user