Minor syntactical changes for readability.
[xuni.git] / src / test / main.c
blob11ed6304333095e1e76de808833f0dd51521ee6a
1 /*! \file main.c
3 This is the driver for the xuni test program "test". It implements main()
4 and not much else.
6 The other source files in src/test/ implement the code for specific
7 panels. They are loaded dynamically at runtime, if the XML files in
8 gui/data/ are as expected, and if xuni was compiled with dynamic library
9 loading support. (If it was not, this file supplies a
10 xuni_loadso_load_function() which is used to the same effect, only the
11 other source files in src/test/ are statically linked to the program.)
14 #include "xuni.h"
15 #include "error.h"
16 #include "graphics.h"
17 #include "loadso.h"
18 #include "loop.h"
19 #include "resource/resource.h"
20 #include "memory.h"
21 #include "utility.h"
22 #include "version.h"
24 #include "game.h"
25 #include "menu.h"
26 #include "options.h"
28 #include "widget/widgets.h"
30 #include "main.h"
32 /*! \def BUILTIN_THEME
33 When defined, tests the new and badly implemented feature that allows
34 static themes. It is designed to allow the program to supply a theme in
35 case the XML data files do not contain any.
37 It is badly implemented because the theme widget that is created is
38 currently not added to the widget tree -- i.e., it will not be rescaled,
39 and so on.
41 /*#define BUILTIN_THEME*/
43 static void load_resource(struct resource_t *settings);
44 static void save_resource(struct resource_t *resource);
46 #ifdef VERSION_WIN32
47 #include <windows.h>
48 int STDCALL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow) {
49 #else
50 int main(int argc, char *argv[]) {
51 #endif
52 struct resource_t settings;
53 struct xuni_t *xuni = allocate_xuni();
54 #ifdef BUILTIN_THEME
55 struct widget_t *theme = allocate_widget("default theme", 0);
56 #endif
58 xuni_error_initialize();
59 xuni_error_add_stream(0, stderr);
60 xuni_error_add_stream(LOG_FILE, 0);
62 load_resource(&settings);
64 init_xuni(xuni, &settings,
65 lookup_resource_string(&settings, 0, "xuni-resource", "icon", 0));
67 #ifdef BUILTIN_THEME
69 init_widget_pos(theme, 0, 0, 100, 100, POS_PACK_NONE);
70 build_theme(xuni, theme, 100.0 / 60, 100.0 / 60,
71 "gui/FreeMono.ttf",
72 "gui/FreeSans.ttf",
73 "gui/alienglow/cursor.png",
74 "gui/alienglow/check.png",
75 "gui/shadow/corners.png",
76 "gui/shadow/corners.png",
77 "gui/shadow/corners.png",
78 "gui/alienglow/corners/out/normal.png",
79 "gui/alienglow/corners/out/hover.png",
80 "gui/alienglow/corners/out/active.png",
81 "gui/alienglow/scrollbar.png",
82 "gui/alienglow/scrollbar.png");
83 xuni->theme->current = theme;
84 widget_event(xuni, theme, WIDGET_EVENT_RESCALE);
85 widget_event(xuni, xuni->gui->widget, WIDGET_EVENT_RESCALE);
87 #endif
89 /*use_theme(xuni, find_widget(xuni->gui->widget, "theme"));*/
91 call_init_funcs(xuni, xuni->gui->widget, &settings);
92 main_loop(xuni, 0, PANEL_MAIN_MENU);
94 xuni_memory_keep_freed_blocks(1);
96 save_resource(&settings);
97 free_resource(&settings);
98 #ifdef BUILTIN_THEME
99 widget_event(xuni, theme, WIDGET_EVENT_FREE);
100 #endif
101 free_xuni(xuni);
103 quit_sdl_libraries();
104 xuni_error_quit();
105 xuni_memory_free_all();
107 return 0;
110 static void load_resource(struct resource_t *settings) {
111 init_resource(settings);
113 if(parse_resource(settings->data, SETTINGS_FILE)) {
114 log_message(ERROR_TYPE_RESOURCE, 0, __FILE__, __LINE__,
115 "Failed to load resource \"%s\"", SETTINGS_FILE);
119 static void save_resource(struct resource_t *resource) {
120 write_resource(resource->data, SETTINGS_FILE ".generated");
123 #ifdef LOADSO_STATIC_VERSION
124 func_point_t xuni_loadso_load_function(loadso_t object, const char *func) {
125 struct string_function_t data[] = {
126 {"game_click", (func_point_t)game_click},
127 {"game_event", (func_point_t)game_event},
128 {"game_free", (func_point_t)game_free},
129 {"game_init", (func_point_t)game_init},
130 {"game_paint", (func_point_t)game_paint},
131 {"game_start", (func_point_t)game_start},
132 {"menu_click", (func_point_t)menu_click},
133 {"menu_event", (func_point_t)menu_event},
134 {"menu_free", (func_point_t)menu_free},
135 {"menu_init", (func_point_t)menu_init},
136 {"menu_paint", (func_point_t)menu_paint},
137 {"menu_start", (func_point_t)menu_start},
138 {"options_click", (func_point_t)options_click},
139 {"options_event", (func_point_t)options_event},
140 {"options_free", (func_point_t)options_free},
141 {"options_graphics_deactivate",
142 (func_point_t)options_graphics_deactivate},
143 {"options_init", (func_point_t)options_init},
144 {"options_paint", (func_point_t)options_paint},
145 {"options_start", (func_point_t)options_start},
146 {"options_theme_deactivate", (func_point_t)options_theme_deactivate}
148 func_point_t funcp
149 = string_to_function(data, sizeof(data) / sizeof(*data), func);
151 if(!funcp) {
152 log_message(ERROR_TYPE_RESOURCE, 0, __FILE__, __LINE__,
153 "Unknown function: \"%s\"", func);
156 return funcp;
158 #endif