[All of these changes were wrought on the Dell.]
[xuni.git] / graphics.h
blobe0c7f2fe3a0cae9f27b264267c3251755c52be6b
1 #ifndef GRAPHICS_H
2 #define GRAPHICS_H
4 #include "SDL.h"
5 #include "SDL_ttf.h"
7 /* GUI_PATH must end with a directory separator. */
8 #define GUI_PATH "gui/"
9 #define GUI_PATH_LEN 4
11 #define ICON_FILE GUI_PATH "icon.bmp"
12 #define LOG_FILE "xuni.log"
14 #define MONOSPACE_FONT GUI_PATH "FreeMono.ttf"
15 #define SANS_SERIF_FONT GUI_PATH "FreeSans.ttf"
17 #define VERSION "xuni version 1.0.0"
18 #define TITLE_PREFIX "xuni: "
20 /*#undef MIN
21 #undef MAX
22 #define MIN(x,y) ((x) < (y) ? (x) : (y))
23 #define MAX(x,y) ((x) > (y) ? (x) : (y))*/
25 struct string_t {
26 char *data;
27 size_t len;
30 struct strings_t {
31 char **data;
32 size_t *len;
33 size_t num;
36 struct font_t {
37 struct string_t mononame, sansname;
38 TTF_Font *mono, *sans;
39 int point;
42 struct resize_image_t {
43 SDL_Surface *original, *image;
46 enum widget_type_t {
47 WIDGET_BUTTON,
48 WIDGET_CHECKBOX,
49 WIDGET_TEXTBOX,
50 WIDGET_LISTBOX /* !!! needs working on */
53 struct button_t {
54 SDL_Surface *text;
57 struct checkbox_t {
58 SDL_Surface *text;
59 int checked; /* True if the checkbox is checked. */
60 int bw;
63 struct textbox_t {
64 char *data;
65 size_t len;
66 SDL_Surface *text;
67 int ra; /* !!! not used */
70 struct listbox_t {
71 struct strings_t data;
74 struct widget_t {
75 enum widget_type_t type;
77 union {
78 struct button_t *button;
79 struct checkbox_t *checkbox;
80 struct textbox_t *textbox;
81 void *all; /* Used by free(). */
82 } p;
84 SDL_Rect pos;
87 enum boxtype_t {
88 BOX_ERROR = -1,
89 BOX_OUT,
90 BOX_OUT_HOVER,
91 BOX_OUT_ACTIVE,
92 BOX_IN,
93 BOX_IN_HOVER,
94 BOX_IN_ACTIVE,
95 BOXTYPES
98 struct theme_t {
99 struct string_t name;
100 int boxw, boxh;
102 struct {
103 struct resize_image_t corners;
104 } box[BOXTYPES];
106 struct resize_image_t check;
109 struct widget_p_t {
110 struct widget_t *widget;
111 size_t id;
114 struct widget_sel_t {
115 /*Uint8 button;
116 int xp, yp;*/
117 int wasin, clickin;
118 struct widget_p_t p;
121 struct smode_t {
122 SDL_Surface *screen;
123 int width, height;
124 int depth;
125 int fullscreen;
126 int focus;
127 SDL_GrabMode restrictfocus;
129 int main_menu_quality;
131 struct widget_sel_t sel;
132 struct widget_p_t active;
135 void clear_smode(struct smode_t *smode);
136 void clear_sel(struct widget_sel_t *sel);
137 void clear_active(struct widget_p_t *wp);
138 void init_sdl(struct smode_t *smode);
139 SDL_GrabMode set_focus(SDL_GrabMode mode);
140 void quit_sdl(void);
141 void free_resize_image(struct resize_image_t *image);
142 void free_fonts(struct font_t *font);
143 void free_theme(struct theme_t *theme);
144 void load_icon(void);
145 void load_fonts(struct font_t *font);
146 void load_theme(struct theme_t *theme);
147 SDL_Surface *load_image(const char *filename);
148 void load_resize_image(struct resize_image_t *image, const char *filename);
149 int resize_screen(struct smode_t *smode, SDL_ResizeEvent *resize);
150 int toggle_fullscreen(struct smode_t *smode);
151 void reload_fonts(struct font_t *font, struct smode_t *smode);
152 void resize_theme(struct theme_t *theme, struct smode_t *smode);
153 void set_caption(const char *s);
154 void lock_screen(SDL_Surface *screen);
155 void unlock_screen(SDL_Surface *screen);
156 void blit_surface(SDL_Surface *screen, SDL_Surface *image, int xp, int yp);
157 void blit_surface_area(SDL_Surface *screen, SDL_Surface *image,
158 int tx, int ty, int fx, int fy, int fw, int fh);
159 void blit_surface_repeat(SDL_Surface *screen, SDL_Surface *image,
160 int xp, int yp, int w, int h);
161 void blit_surface_repeat_area(SDL_Surface *screen, SDL_Surface *image,
162 int tx, int ty, int tw, int th, int fx, int fy, int fw, int fh);
163 int in_rect(int xp, int yp, int x, int y, int w, int h);
164 int in_sdl_rect(int xp, int yp, SDL_Rect *r);
165 void blit_surface_fill_from(SDL_Surface *screen, SDL_Surface *image,
166 int tx, int ty, int tw, int th, int fx1, int fy1);
167 int is_box_in(enum boxtype_t bt);
168 int is_box_out(enum boxtype_t bt);
169 int is_box_normal(enum boxtype_t bt);
170 int is_box_hover(enum boxtype_t bt);
171 int is_box_active(enum boxtype_t bt);
172 enum boxtype_t paint_box(SDL_Surface *screen, struct theme_t *theme,
173 SDL_Rect *b, enum boxtype_t bt);
174 void paint_centred_text(SDL_Surface *screen, struct theme_t *theme,
175 SDL_Surface *text, SDL_Rect *b, enum boxtype_t bt);
176 void paint_textbox_text(SDL_Surface *screen, struct font_t *font,
177 struct theme_t *theme, SDL_Surface *text, SDL_Rect *b, enum boxtype_t bt,
178 int cursor);
179 void init_button(struct widget_t *widget, TTF_Font *font, const char *text,
180 int x, int y, int w, int h);
181 void init_checkbox(struct widget_t *widget, TTF_Font *font, const char *text,
182 struct theme_t *theme, int checked, int x, int y, int w, int h, int bw);
183 void init_textbox(struct widget_t *widget, TTF_Font *font, const char *data,
184 size_t len, struct theme_t *theme, int x, int y, int w, int h);
185 size_t in_widget_array(int xp, int yp, struct widget_t *widget, size_t n);
186 int set_widget_sel(struct widget_sel_t *sel, int xp, int yp, int click,
187 size_t offset, struct widget_t *widget, size_t n);
188 enum boxtype_t paint_widget(struct smode_t *smode, struct font_t *font,
189 struct theme_t *theme, struct widget_t *widget);
190 void perform_widget_click(struct widget_t *widget);
191 int render_restricted_text(SDL_Surface **text, const char *data,
192 TTF_Font *font, int w);
193 int widget_process_character(struct widget_t *widget, SDL_keysym *sym,
194 struct smode_t *smode, struct font_t *font, struct theme_t *theme);
195 void paint_widget_array(struct smode_t *smode, struct font_t *font,
196 struct theme_t *theme, struct widget_t *widget, size_t n);
197 int widget_can_be_active(enum widget_type_t wt);
198 void enable_unicode(enum widget_type_t wt);
199 void free_widget_array(struct widget_t *widget, size_t n);
201 #endif