Began creating the listbox widget. It's still just a structure.
[xuni.git] / graphics.h
blobd23399130c3c4d16349a592ed7642da060438e56
1 #ifndef GRAPHICS_H
2 #define GRAPHICS_H
4 #include "SDL.h"
5 #include "SDL_image.h"
6 #include "SDL_ttf.h"
7 #include "SDL_rotozoom.h"
9 /* GUI_PATH must end with a directory separator. */
10 #define GUI_PATH "gui/"
11 #define GUI_PATH_LEN 4
13 #define ICON_FILE GUI_PATH "icon.bmp"
14 #define LOG_FILE "xuni.log"
16 #define MONOSPACE_FONT GUI_PATH "FreeMono.ttf"
17 #define SANS_SERIF_FONT GUI_PATH "FreeSans.ttf"
19 #define VERSION "xuni version 1.0.0"
20 #define TITLE_PREFIX "xuni: "
22 /*#undef MIN
23 #undef MAX
24 #define MIN(x,y) ((x) < (y) ? (x) : (y))
25 #define MAX(x,y) ((x) > (y) ? (x) : (y))*/
27 struct strings_t {
28 char **data;
29 size_t *len;
30 size_t num;
33 struct font_t {
34 TTF_Font *mono, *sans;
35 int point;
38 struct resize_image_t {
39 SDL_Surface *original, *image;
42 enum widget_type_t {
43 WIDGET_BUTTON,
44 WIDGET_CHECKBOX,
45 WIDGET_TEXTBOX,
46 WIDGET_LISTBOX
49 struct button_t {
50 SDL_Surface *text;
53 struct checkbox_t {
54 SDL_Surface *text;
55 int checked;
56 int bw;
59 struct textbox_t {
60 char *data;
61 size_t len;
62 SDL_Surface *text;
63 int ra;
66 struct listbox_t {
67 struct strings_t data;
70 struct widget_t {
71 enum widget_type_t type;
73 union {
74 struct button_t *button;
75 struct checkbox_t *checkbox;
76 struct textbox_t *textbox;
77 void *all;
78 } p;
80 SDL_Rect pos;
83 enum boxtype_t {
84 BOX_ERROR = -1,
85 BOX_OUT,
86 BOX_OUT_HOVER,
87 BOX_OUT_ACTIVE,
88 BOX_IN,
89 BOX_IN_HOVER,
90 BOX_IN_ACTIVE,
91 BOXTYPES
94 struct theme_t {
95 int boxw, boxh;
97 struct {
98 struct resize_image_t corners;
99 } box[BOXTYPES];
101 struct resize_image_t check;
104 struct widget_p_t {
105 struct widget_t *widget;
106 size_t id;
109 struct widget_sel_t {
110 /*Uint8 button;
111 int xp, yp;*/
112 int wasin, clickin;
113 struct widget_p_t p;
116 struct smode_t {
117 SDL_Surface *screen;
118 int width, height;
119 int depth;
120 int fullscreen;
121 int focus;
122 SDL_GrabMode restrictfocus;
124 struct widget_sel_t sel;
125 struct widget_p_t active;
128 void default_smode(struct smode_t *smode);
129 void clear_smode(struct smode_t *smode);
130 void clear_sel(struct widget_sel_t *sel);
131 SDL_Surface *init_sdl(struct smode_t *smode);
132 SDL_GrabMode set_focus(SDL_GrabMode mode);
133 void quit_sdl(void);
134 void free_resize_image(struct resize_image_t *image);
135 void free_fonts(struct font_t *font);
136 void free_theme(struct theme_t *theme);
137 void load_icon(void);
138 void load_fonts(struct font_t *font);
139 void load_theme(struct theme_t *theme, const char *path);
140 SDL_Surface *load_image(const char *filename);
141 void load_resize_image(struct resize_image_t *image, const char *filename);
142 SDL_Surface *resize_screen(struct smode_t *smode, SDL_ResizeEvent *resize);
143 int toggle_fullscreen(SDL_Surface **screen, struct smode_t *smode);
144 void reload_fonts(struct font_t *font, struct smode_t *smode);
145 void resize_theme(struct theme_t *theme, struct smode_t *smode);
146 void set_caption(const char *s);
147 void lock_screen(SDL_Surface *screen);
148 void unlock_screen(SDL_Surface *screen);
149 void blit_surface(SDL_Surface *screen, SDL_Surface *image, int xp, int yp);
150 void blit_surface_area(SDL_Surface *screen, SDL_Surface *image,
151 int tx, int ty, int fx, int fy, int fw, int fh);
152 void blit_surface_repeat(SDL_Surface *screen, SDL_Surface *image,
153 int xp, int yp, int w, int h);
154 void blit_surface_repeat_area(SDL_Surface *screen, SDL_Surface *image,
155 int tx, int ty, int tw, int th, int fx, int fy, int fw, int fh);
156 int in_rect(int xp, int yp, int x, int y, int w, int h);
157 int in_sdl_rect(int xp, int yp, SDL_Rect *r);
158 void blit_surface_fill_from(SDL_Surface *screen, SDL_Surface *image,
159 int tx, int ty, int tw, int th, int fx1, int fy1);
160 int is_box_in(enum boxtype_t bt);
161 int is_box_out(enum boxtype_t bt);
162 int is_box_normal(enum boxtype_t bt);
163 int is_box_hover(enum boxtype_t bt);
164 int is_box_active(enum boxtype_t bt);
165 enum boxtype_t paint_box(SDL_Surface *screen, struct smode_t *smode,
166 struct theme_t *theme, SDL_Surface *text, SDL_Rect *b,
167 enum boxtype_t bt, int centre);
168 void init_button(struct widget_t *widget, TTF_Font *font, const char *text,
169 int x, int y, int w, int h);
170 void init_checkbox(struct widget_t *widget, TTF_Font *font, const char *text,
171 struct theme_t *theme, int checked, int x, int y, int w, int h, int bw);
172 void init_textbox(struct widget_t *widget, TTF_Font *font, const char *data,
173 size_t len, struct theme_t *theme, int x, int y, int w, int h);
174 size_t in_widget_array(int xp, int yp, struct widget_t *widget, size_t n);
175 int set_widget_sel(struct widget_sel_t *sel, int xp, int yp, int click,
176 size_t offset, struct widget_t *widget, size_t n);
177 enum boxtype_t paint_widget(SDL_Surface *screen, struct smode_t *smode,
178 struct theme_t *theme, struct widget_t *widget);
179 void perform_widget_click(struct widget_t *widget);
180 int render_restricted_text(SDL_Surface **text, const char *data,
181 TTF_Font *font, int w);
182 int widget_process_character(struct widget_t *widget, SDL_keysym *sym,
183 struct font_t *font, struct theme_t *theme);
184 void paint_widget_array(SDL_Surface *screen, struct smode_t *smode,
185 struct theme_t *theme, struct widget_t *widget, size_t n);
186 int widget_can_be_active(enum widget_type_t wt);
187 void enable_unicode(enum widget_type_t wt);
188 void free_widget_array(struct widget_t *widget, size_t n);
190 #endif