Added a background to the help menu. Made textboxes support CTRL-<key>.
[xuni.git] / src / test / help.c
blob7c24dccde6ac263e4f4688f1ff67a87c97f09802
1 /*! \file help.c
3 */
5 #include <stdio.h>
6 #include <string.h>
8 #include "help.h"
10 #include "graphics.h"
11 #include "gui.h"
12 #include "loop.h"
13 #include "menu.h"
15 #include "widget/widgets.h"
17 #include "main.h"
19 #include "loadso.h"
21 enum wid_t {
22 WID_BACK,
23 WID_README,
24 WIDS
27 static void get_readme_text(struct xuni_t *xuni, struct widget_t *panel);
29 int help_init(struct xuni_t *xuni, struct panel_data_t *data) {
30 struct widget_t *panel = data->event[PANEL_EVENT_INIT].p.init.panel;
32 init_wid(xuni->gui->widget, xuni->gui->widget, PANEL_HELP, "help");
34 init_wid(panel, panel, WID_BACK, "back");
35 init_wid(panel, panel, WID_README, "readme");
37 add_widget_accelerator(xuni, panel, widget_nameid_access(panel, WID_BACK),
38 SDLK_ESCAPE, KMOD_NONE);
40 get_readme_text(xuni, panel);
42 return 0;
45 static void get_readme_text(struct xuni_t *xuni, struct widget_t *panel) {
46 FILE *file = fopen("README", "r");
47 char line[BUFSIZ], *p;
49 if(!file) return;
51 while(fgets(line, sizeof(line), file)) {
52 if((p = strchr(line, '\n'))) *p = 0;
54 /* !!! blank labels do not work properly
55 the height of a blank label cannot be determined (with SDL_ttf)
57 if(!*line) {
58 strcpy(line, " ");
61 add_listbox_item(xuni, widget_nameid_access(panel, WID_README)
62 ->compose->widget[WID_LISTBOX_DATA],
63 strstr(line, "http") ? THEME_FONT_MONO : THEME_FONT_SANS, line);
66 widget_event(xuni, widget_nameid_access(panel, WID_README),
67 WIDGET_EVENT_RESCALE);
69 fclose(file);
72 int help_start(struct xuni_t *xuni, struct panel_data_t *data) {
73 set_caption("Help and information");
75 return 0;
78 int help_event(struct xuni_t *xuni, struct panel_data_t *data) {
79 panel_type_t *mode = data->event[PANEL_EVENT_EVENT].p.event.mode;
80 SDL_Event *event = data->event[PANEL_EVENT_EVENT].p.event.event;
82 switch(event->type) {
83 case SDL_QUIT:
84 *mode = PANEL_MAIN_MENU;
85 break;
86 default:
87 break;
90 return 0;
93 int help_paint(struct xuni_t *xuni, struct panel_data_t *data) {
94 struct widget_t *panel
95 = widget_nameid_access(xuni->gui->widget, PANEL_HELP);
96 panel_type_t mode = data->event[PANEL_EVENT_PAINT].p.paint.mode;
98 clear_screen(xuni->smode->screen);
100 widget_event(xuni, widget_nameid_access(xuni->gui->widget, PANEL_HELP),
101 WIDGET_EVENT_PAINT);
103 update_screen(xuni);
105 return 0;
108 int help_click(struct xuni_t *xuni, struct panel_data_t *data) {
109 panel_type_t *mode = data->event[PANEL_EVENT_CLICK].p.click.mode;
110 struct widget_t *widget = data->event[PANEL_EVENT_CLICK].p.click.widget;
112 switch(widget->id) {
113 case WID_BACK:
114 *mode = PANEL_MAIN_MENU;
115 break;
118 return 0; /* ignored */
121 int help_free(struct xuni_t *xuni, struct panel_data_t *data) {
122 return 0;