3 This is the driver for the xuni test program "test". It implements main()
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.)
19 #include "resource/resource.h"
28 #include "widget/widgets.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,
41 /*#define BUILTIN_THEME*/
43 static void load_resource(struct resource_t
*settings
);
44 static void save_resource(struct resource_t
*resource
);
48 int STDCALL
WinMain(HINSTANCE hInst
, HINSTANCE hPrev
, LPSTR lpCmd
, int nShow
) {
50 int main(int argc
, char *argv
[]) {
52 struct resource_t settings
;
53 struct xuni_t
*xuni
= allocate_xuni();
55 struct widget_t
*theme
= allocate_widget("default theme", 0);
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));
69 init_widget_pos(theme
, 0, 0, 100, 100, POS_PACK_NONE
);
70 build_theme(xuni
, theme
, 100.0 / 60, 100.0 / 60,
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
);
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
);
99 widget_event(xuni
, theme
, WIDGET_EVENT_FREE
);
103 quit_sdl_libraries();
105 xuni_memory_free_all();
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 {"free_game", (func_point_t
)free_game
},
127 {"free_main_menu", (func_point_t
)free_main_menu
},
128 {"free_options", (func_point_t
)free_options
},
129 {"game_event", (func_point_t
)game_event
},
130 {"game_perform_click", (func_point_t
)game_perform_click
},
131 {"init_game", (func_point_t
)init_game
},
132 {"init_menu", (func_point_t
)init_menu
},
133 {"init_options", (func_point_t
)init_options
},
134 {"menu_event", (func_point_t
)menu_event
},
135 {"menu_perform_click", (func_point_t
)menu_perform_click
},
136 {"options_event", (func_point_t
)options_event
},
137 {"options_graphics_deactivate",
138 (func_point_t
)options_graphics_deactivate
},
139 {"options_perform_click", (func_point_t
)options_perform_click
},
140 {"options_theme_deactivate", (func_point_t
)options_theme_deactivate
},
141 {"paint_game", (func_point_t
)paint_game
},
142 {"paint_menu", (func_point_t
)paint_menu
},
143 {"paint_options", (func_point_t
)paint_options
},
144 {"start_game", (func_point_t
)start_game
},
145 {"start_menu", (func_point_t
)start_menu
},
146 {"start_options", (func_point_t
)start_options
}
149 = string_to_function(data
, sizeof(data
) / sizeof(*data
), func
);
152 log_message(ERROR_TYPE_RESOURCE
, 0, __FILE__
, __LINE__
,
153 "Unknown function: \"%s\"", func
);