Created common signature for panel event handling functions.
[xuni.git] / src / test / game.c
blob87323c769fdbda7d6f8729e721531c4ff6f42727
1 /*! \file game.c
3 */
5 #include "SDL_image.h"
6 #include "SDL_rotozoom.h"
8 #include "game.h"
9 #include "menu.h" /* for paint_menu_fps() */
11 #include "graphics.h"
12 #include "gui.h"
13 #include "loop.h"
14 #include "menu.h"
16 #include "widget/widgets.h"
18 #include "main.h"
20 #include "loadso.h"
22 enum wid_t {
23 WID_MENU,
24 WID_MENU_BACK,
25 WID_MENU_QUIT,
26 WIDS
29 int game_init(struct xuni_t *xuni, struct panel_data_t *data) {
30 struct widget_t *panel = data->event[PANEL_EVENT_INIT].p.init.panel;
31 struct widget_t *temppanel;
33 init_wid(xuni->gui->widget, xuni->gui->widget,
34 PANEL_GAME, "game");
35 init_wid(xuni->gui->widget, xuni->gui->widget,
36 PANEL_GAME_MENU, "game menu");
38 init_wid(xuni->gui->widget, panel, WID_MENU, "game/menu");
39 init_wid(xuni->gui->widget, panel, WID_MENU_BACK, "game menu/back");
40 init_wid(xuni->gui->widget, panel, WID_MENU_QUIT, "game menu/quit");
42 /*add_widget_accelerator(panel,
43 widget_nameid_access(panel, WID_MENU), SDLK_F10, KMOD_NONE);*/
45 temppanel = widget_nameid_access(xuni->gui->widget, PANEL_GAME_MENU);
46 add_widget_accelerator(xuni, temppanel,
47 widget_nameid_access(panel, WID_MENU_BACK), SDLK_ESCAPE, KMOD_NONE);
48 /*add_widget_accelerator(temppanel,
49 widget_nameid_access(panel, WID_MENU_BACK), SDLK_F10, KMOD_NONE);*/
51 return 0;
54 int game_start(struct xuni_t *xuni, struct panel_data_t *data) {
55 set_caption("Explore the Universe");
57 return 0;
60 int game_event(struct xuni_t *xuni, struct panel_data_t *data) {
61 panel_type_t *mode = data->event[PANEL_EVENT_EVENT].p.event.mode;
62 SDL_Event *event = data->event[PANEL_EVENT_EVENT].p.event.event;
64 switch(event->type) {
65 case SDL_KEYDOWN:
66 switch(event->key.keysym.sym) {
67 case SDLK_ESCAPE:
68 /* there is currently no widget for this */
69 if(*mode == PANEL_GAME) {
70 *mode = PANEL_MAIN_MENU;
73 break;
74 default: break;
76 break;
77 case SDL_QUIT:
78 *mode = PANEL_MAIN_MENU;
79 break;
80 default:
81 break;
84 return 0;
87 int game_paint(struct xuni_t *xuni, struct panel_data_t *data) {
88 struct widget_t *panel
89 = widget_nameid_access(xuni->gui->widget, PANEL_GAME);
90 panel_type_t mode = data->event[PANEL_EVENT_PAINT].p.paint.mode;
92 clear_screen(xuni->smode->screen);
94 widget_event(xuni, widget_nameid_access(xuni->gui->widget, PANEL_GAME),
95 WIDGET_EVENT_PAINT);
97 if(mode == PANEL_GAME_MENU) {
98 widget_event(xuni, widget_nameid_access(xuni->gui->widget,
99 PANEL_GAME_MENU), WIDGET_EVENT_PAINT);
102 paint_menu_fps(xuni, THEME_FONT_MONO);
104 if(panel->p.panel->frameupdate) {
105 paint_cursor(xuni, get_theme_widget(xuni, THEME_DEFAULT_CURSOR));
108 update_screen(xuni);
110 return 0;
113 int game_click(struct xuni_t *xuni, struct panel_data_t *data) {
114 panel_type_t *mode = data->event[PANEL_EVENT_CLICK].p.click.mode;
115 struct widget_t *widget = data->event[PANEL_EVENT_CLICK].p.click.widget;
117 switch(widget->id) {
118 case WID_MENU:
119 *mode = PANEL_GAME_MENU;
121 clear_gui(xuni, PANEL_GAME_MENU, 0);
122 break;
123 case WID_MENU_BACK:
124 *mode = PANEL_GAME;
126 clear_gui(xuni, PANEL_GAME, 0);
127 break;
128 case WID_MENU_QUIT:
129 *mode = PANEL_MAIN_MENU;
130 break;
133 return 0; /* ignored */
136 int game_free(struct xuni_t *xuni, struct panel_data_t *data) {
137 return 0;