1 /*
2  * Copyright (c) 1997 - 2001 Hansj�rg Malthaner
3  *
4  * This file is part of the Simutrans project under the artistic licence.
5  * (see licence.txt)
6  */
7 
8 #ifndef gui_theme_h
9 #define gui_theme_h
10 
11 #include "../dataobj/koord.h"
12 #include "../simcolor.h"
13 #include "../display/simgraph.h"
14 
15 class image_t;
16 
17 
18 /*
19  * The following gives positioning aids for elements in dialogues
20  * Only those, LINESPACE, and dimensions of elements itself must be
21  * exclusively used to calculate positions in dialogues to have a
22  * scalable interface
23  *
24  * Max Kielland:
25  * Added more defines for theme testing.
26  * These is going to be moved into the theme handling later.
27  */
28 
29 #define D_BUTTON_SIZE          (gui_theme_t::gui_button_size  )
30 #define D_BUTTON_WIDTH         (gui_theme_t::gui_button_size.w)
31 #define D_BUTTON_HEIGHT        (gui_theme_t::gui_button_size.h)
32 
33 #define D_FILTER_BUTTON_SIZE   (gui_theme_t::gui_color_button_size  )
34 #define D_FILTER_BUTTON_WIDTH  (gui_theme_t::gui_color_button_size.w)
35 #define D_FILTER_BUTTON_HEIGHT (gui_theme_t::gui_color_button_size.h)
36 
37 #define D_CHECKBOX_SIZE        (gui_theme_t::gui_checkbox_size  )
38 #define D_CHECKBOX_WIDTH       (gui_theme_t::gui_checkbox_size.w)
39 #define D_CHECKBOX_HEIGHT      (gui_theme_t::gui_checkbox_size.h)
40 
41 #define D_POS_BUTTON_SIZE      (gui_theme_t::gui_pos_button_size  )
42 #define D_POS_BUTTON_WIDTH     (gui_theme_t::gui_pos_button_size.w)
43 #define D_POS_BUTTON_HEIGHT    (gui_theme_t::gui_pos_button_size.h)
44 
45 #define D_ARROW_LEFT_SIZE      (gui_theme_t::gui_arrow_left_size  )
46 #define D_ARROW_LEFT_WIDTH     (gui_theme_t::gui_arrow_left_size.w)
47 #define D_ARROW_LEFT_HEIGHT    (gui_theme_t::gui_arrow_left_size.h)
48 
49 #define D_ARROW_RIGHT_SIZE     (gui_theme_t::gui_arrow_right_size  )
50 #define D_ARROW_RIGHT_WIDTH    (gui_theme_t::gui_arrow_right_size.w)
51 #define D_ARROW_RIGHT_HEIGHT   (gui_theme_t::gui_arrow_right_size.h)
52 
53 #define D_ARROW_UP_SIZE        (gui_theme_t::gui_arrow_up_size  )
54 #define D_ARROW_UP_WIDTH       (gui_theme_t::gui_arrow_up_size.w)
55 #define D_ARROW_UP_HEIGHT      (gui_theme_t::gui_arrow_up_size.h)
56 
57 #define D_ARROW_DOWN_SIZE      (gui_theme_t::gui_arrow_down_size  )
58 #define D_ARROW_DOWN_WIDTH     (gui_theme_t::gui_arrow_down_size.w)
59 #define D_ARROW_DOWN_HEIGHT    (gui_theme_t::gui_arrow_down_size.h)
60 
61 #define D_SCROLLBAR_SIZE       (gui_theme_t::gui_scrollbar_size  )
62 #define D_SCROLLBAR_HEIGHT     (gui_theme_t::gui_scrollbar_size.h)
63 #define D_SCROLLBAR_WIDTH      (gui_theme_t::gui_scrollbar_size.w)
64 
65 #define D_SCROLL_MIN_SIZE      (gui_theme_t::gui_min_scrollbar_size  )
66 #define D_SCROLL_MIN_WIDTH     (gui_theme_t::gui_min_scrollbar_size.w)
67 #define D_SCROLL_MIN_HEIGHT    (gui_theme_t::gui_min_scrollbar_size.h)
68 
69 #define D_GADGET_SIZE          (gui_theme_t::gui_gadget_size  )
70 #define D_GADGET_WIDTH         (gui_theme_t::gui_gadget_size.w)
71 #define D_GADGET_HEIGHT        (gui_theme_t::gui_gadget_size.h)
72 
73 #define D_INDICATOR_BOX_SIZE   (gui_theme_t::gui_indicator_size  )
74 #define D_INDICATOR_BOX_HEIGHT (gui_theme_t::gui_indicator_size.h)
75 #define D_INDICATOR_BOX_WIDTH  (gui_theme_t::gui_indicator_size.w)
76 
77 #define D_INDICATOR_SIZE       (gui_theme_t::gui_indicator_size  )
78 #define D_INDICATOR_WIDTH      (gui_theme_t::gui_indicator_size.w)
79 #define D_INDICATOR_HEIGHT     (gui_theme_t::gui_indicator_size.h)
80 
81 #define D_LABEL_SIZE           (gui_theme_t::gui_label_size  )
82 #define D_LABEL_WIDTH          (gui_theme_t::gui_label_size.w)
83 #define D_LABEL_HEIGHT         (gui_theme_t::gui_label_size.h)
84 
85 #define D_EDIT_SIZE            (gui_theme_t::gui_edit_size  )
86 #define D_EDIT_WIDTH           (gui_theme_t::gui_edit_size.w)
87 #define D_EDIT_HEIGHT          (gui_theme_t::gui_edit_size.h)
88 
89 #define D_FOCUS_OFFSET         (gui_theme_t::gui_focus_offset  )
90 #define D_FOCUS_OFFSET_H       (gui_theme_t::gui_focus_offset.x)
91 #define D_FOCUS_OFFSET_V       (gui_theme_t::gui_focus_offset.y)
92 
93 #define D_TITLEBAR_HEIGHT      (gui_theme_t::gui_titlebar_height)
94 #define D_DIVIDER_HEIGHT       (gui_theme_t::gui_divider_size.h)
95 #define D_STATUSBAR_HEIGHT     (max(16,LINESPACE))                    // statusbar bottom of screen
96 #define D_TAB_HEADER_HEIGHT      (gui_tab_panel_t::header_vsize)        // Tab page params (replace with real values from the skin images)
97 
98 // Dialog borders
99 #define D_MARGIN_LEFT          (gui_theme_t::gui_frame_left)
100 #define D_MARGIN_TOP           (gui_theme_t::gui_frame_top)
101 #define D_MARGIN_RIGHT         (gui_theme_t::gui_frame_right)
102 #define D_MARGIN_BOTTOM        (gui_theme_t::gui_frame_bottom)
103 
104 // Dialogue border helpers
105 #define D_MARGINS_X            (D_MARGIN_LEFT + D_MARGIN_RIGHT)
106 #define D_MARGINS_Y            (D_MARGIN_TOP + D_MARGIN_BOTTOM)
107 
108 // space between two elements
109 #define D_H_SPACE              (gui_theme_t::gui_hspace)
110 #define D_V_SPACE              (gui_theme_t::gui_vspace)
111 
112 // Button grid helpers
113 #define BUTTON1_X     (D_MARGIN_LEFT)
114 #define BUTTON2_X     (D_MARGIN_LEFT+1*(D_BUTTON_WIDTH+D_H_SPACE))
115 #define BUTTON3_X     (D_MARGIN_LEFT+2*(D_BUTTON_WIDTH+D_H_SPACE))
116 #define BUTTON4_X     (D_MARGIN_LEFT+3*(D_BUTTON_WIDTH+D_H_SPACE))
117 #define BUTTON_X(col) ( (col) * (D_BUTTON_WIDTH  + D_H_SPACE) )
118 #define BUTTON_Y(row) ( (row) * (D_BUTTON_HEIGHT + D_V_SPACE) )
119 
120 // The width of a typical dialogue (either list/covoi/factory) and initial width when it makes sense
121 #define D_DEFAULT_WIDTH (D_MARGINS_X + 4*D_BUTTON_WIDTH + 3*D_H_SPACE)
122 #define D_DEFAULT_HEIGHT (max(56, get_base_tile_raster_width() * 7 / 8) + 208 + D_SCROLLBAR_HEIGHT)
123 
124 // Max Kielland: align helper, returns the offset to apply to N1 for a center alignment around N2
125 #define D_GET_CENTER_ALIGN_OFFSET(N1,N2) ((N2-N1)>>1)
126 #define D_GET_FAR_ALIGN_OFFSET(N1,N2) (N2-N1)
127 
128 #define TOOLTIP_MOUSE_OFFSET_X (16)
129 #define TOOLTIP_MOUSE_OFFSET_Y (12)
130 
131 // these define the offset of images in their definitions
132 enum {
133 	SKIN_WINDOW_BACKGROUND=0,
134 
135 	// gadget (window GUI buttons)
136 	SKIN_GADGET_CLOSE=0,
137 	SKIN_GADGET_HELP,
138 	SKIN_GADGET_MINIMIZE,
139 	SKIN_BUTTON_PREVIOUS,
140 	SKIN_BUTTON_NEXT,
141 	SKIN_GADGET_NOTPINNED,
142 	SKIN_GADGET_PINNED,
143 	SKIN_WINDOW_RESIZE,
144 	SKIN_GADGET_GOTOPOS,
145 //	SKIN_GADGET_BUTTON,
146 	SKIN_GADGET_COUNT,	// maximum number, NOT AN IMAGE
147 
148 	// scrollbars horizontal
149 	SKIN_BUTTON_ARROW_LEFT = 0,
150 	SKIN_BUTTON_ARROW_LEFT_PRESSED,
151 	SKIN_BUTTON_ARROW_LEFT_DISABLED,
152 	SKIN_BUTTON_ARROW_RIGHT,
153 	SKIN_BUTTON_ARROW_RIGHT_PRESSED,
154 	SKIN_BUTTON_ARROW_RIGHT_DISABLED,
155 	SKIN_SCROLLBAR_H_BACKGROUND_LEFT,
156 	SKIN_SCROLLBAR_H_BACKGROUND,
157 	SKIN_SCROLLBAR_H_BACKGROUND_RIGHT,
158 	SKIN_SCROLLBAR_H_KNOB_LEFT,
159 	SKIN_SCROLLBAR_H_KNOB_BODY,
160 	SKIN_SCROLLBAR_H_KNOB_RIGHT,
161 	// and vertical
162 	SKIN_BUTTON_ARROW_UP,
163 	SKIN_BUTTON_ARROW_UP_PRESSED,
164 	SKIN_BUTTON_ARROW_UP_DISABLED,
165 	SKIN_BUTTON_ARROW_DOWN,
166 	SKIN_BUTTON_ARROW_DOWN_PRESSED,
167 	SKIN_BUTTON_ARROW_DOWN_DISABLED,
168 	SKIN_SCROLLBAR_V_BACKGROUND_TOP,
169 	SKIN_SCROLLBAR_V_BACKGROUND,
170 	SKIN_SCROLLBAR_V_BACKGROUND_BOTTOM,
171 	SKIN_SCROLLBAR_V_KNOB_TOP,
172 	SKIN_SCROLLBAR_V_KNOB_BODY,
173 	SKIN_SCROLLBAR_V_KNOB_BOTTOM,
174 
175 	// squarebutton
176 	SKIN_BUTTON_CHECKBOX = 0,
177 	SKIN_BUTTON_CHECKBOX_PRESSED,
178 	SKIN_BUTTON_CHECKBOX_DISABLED,
179 
180 	// posbutton
181 	SKIN_BUTTON_POS = 0,
182 	SKIN_BUTTON_POS_PRESSED,
183 	SKIN_BUTTON_POS_DISABLED,
184 
185 	// normal buttons and round buttons
186 	SKIN_BUTTON_SIDE_LEFT = 0,
187 	SKIN_BUTTON_BODY,
188 	SKIN_BUTTON_SIDE_RIGHT,
189 	SKIN_BUTTON_SIDE_LEFT_PRESSED,
190 	SKIN_BUTTON_BODY_PRESSED,
191 	SKIN_BUTTON_SIDE_RIGHT_PRESSED,
192 	SKIN_BUTTON_SIDE_RIGHT_DISABLED,
193 	SKIN_BUTTON_BODY_DISABLED,
194 	SKIN_BUTTON_SIDE_LEFT_DISABLED,
195 	SKIN_BUTTON_COLOR_MASK_LEFT,
196 	SKIN_BUTTON_COLOR_MASK_BODY,
197 	SKIN_BUTTON_COLOR_MASK_RIGHT
198 };
199 
200 
201 class gui_theme_t {
202 public:
203 	/// @name system colours used by gui components
204 	/// @{
205 	static PIXVAL gui_color_text;                         //@< Color to draw standard text
206 	static PIXVAL gui_color_text_highlight;               //@< Color to draw highlighted text (tabs, finance window headlines, ware list bonus text, fps info in video options, it and em tags)
207 	static PIXVAL gui_color_text_title;                   //@< Color to draw title text (banner, h1 and a tags)
208 	static PIXVAL gui_color_text_shadow;                  //@< Color to draw text shadow
209 	static PIXVAL gui_color_text_strong;                  //@< Color to draw strong text (strong tags)
210 	static PIXVAL gui_color_text_minus;                   //@< Color to draw negative values
211 	static PIXVAL gui_color_text_plus;                    //@< Color to draw positive values
212 	static PIXVAL gui_color_text_unused;                  //@< Color to draw unused items
213 	static PIXVAL gui_color_edit_text;                    //@< Color to draw text in edit areas
214 	static PIXVAL gui_color_edit_text_selected;           //@< Color to draw selected text in edit areas
215 	static PIXVAL gui_color_edit_text_disabled;           //@< Color to draw disabled text in edit areas
216 	static PIXVAL gui_color_edit_background_selected;     //@< Color to draw background of selected text in edit areas
217 	static PIXVAL gui_color_edit_beam;                    //@< Color to draw the cursor beam
218 	static PIXVAL gui_color_chart_background;             //@< Color to draw background of charts
219 	static PIXVAL gui_color_chart_lines_zero;             //@< Color to draw in-chart horizontal zero line
220 	static PIXVAL gui_color_chart_lines_odd;              //@< Color to draw in-chart vertical odd lines and text
221 	static PIXVAL gui_color_chart_lines_even;             //@< Color to draw in-chart vertical even lines and text
222 	static PIXVAL gui_color_list_text_selected_focus;     //@< Colour to draw the selected element text in list when window has focus
223 	static PIXVAL gui_color_list_text_selected_nofocus;   //@< Colour to draw the selected element text in list when window is not in focus
224 	static PIXVAL gui_color_list_background_selected_f;   //@< Colour to draw the selected element background in list when window has focus
225 	static PIXVAL gui_color_list_background_selected_nf;  //@< Colour to draw the selected element background in list when window is not in focus
226 	static PIXVAL gui_color_button_text;                  //@< Color to draw text in normal buttons
227 	static PIXVAL gui_color_button_text_disabled;         //@< Color to draw text in disabled buttons
228 	static PIXVAL gui_color_button_text_selected;         //@< Color to draw text in pressed normal buttons
229 	static PIXVAL gui_color_colored_button_text;          //@< Color to draw text in colored buttons
230 	static PIXVAL gui_color_colored_button_text_selected; //@< Color to draw text in pressed colored buttons
231 	static PIXVAL gui_color_checkbox_text;                //@< Color to draw text in checkboxes
232 	static PIXVAL gui_color_checkbox_text_disabled;       //@< Color to draw text in disabled checkboxes
233 	static PIXVAL gui_color_ticker_background;            //@< Color to draw ticker background
234 	static PIXVAL gui_color_ticker_divider;               //@< Color to draw ticker divider
235 	static PIXVAL gui_color_statusbar_text;               //@< Color to draw text in statusbar
236 	static PIXVAL gui_color_statusbar_background;         //@< Color to draw statusbar background
237 	static PIXVAL gui_color_statusbar_divider;            //@< Color to draw statusbar divider
238 	static PIXVAL gui_highlight_color;                    //@< Color to draw highlight dividers (tabs)
239 	static PIXVAL gui_shadow_color;                       //@< Color to draw shadowed dividers (tabs)
240 	/// @}
241 
242 	/// @name GUI element sizes used by gui components
243 	/// @{
244 	static scr_size gui_divider_size;
245 	static scr_size gui_button_size;
246 	static scr_size gui_color_button_text_offset; // extra offset for the text (in case of asymmetric or buttons with color on the left)
247 	static scr_size gui_button_text_offset;       // extra offset for the text (in case of asymmetric or buttons with checkmark on the left)
248 	static scr_size gui_color_button_size;
249 	static scr_size gui_checkbox_size;
250 	static scr_size gui_pos_button_size;
251 	static scr_size gui_arrow_left_size;
252 	static scr_size gui_arrow_right_size;
253 	static scr_size gui_arrow_up_size;
254 	static scr_size gui_arrow_down_size;
255 	static scr_size gui_scrollbar_size;
256 	static scr_size gui_min_scrollbar_size;	// minimum width and height of a scrollbar slider
257 	static scr_size gui_label_size;
258 	static scr_size gui_edit_size;
259 	static scr_size gui_indicator_size;
260 	static scr_size gui_gadget_size;
261 	static scr_coord gui_focus_offset;
262 	static scr_coord gui_color_button_text_offset_right; // extra right offset for the text (in case of asymmetric or buttons with color on the right)
263 	static scr_coord gui_button_text_offset_right;       // extra right offset for the text (in case of asymmetric or buttons with checkmark on the right)
264 
265 	static KOORD_VAL gui_titlebar_height;
266 	static KOORD_VAL gui_frame_left;
267 	static KOORD_VAL gui_frame_top;
268 	static KOORD_VAL gui_frame_right;
269 	static KOORD_VAL gui_frame_bottom;
270 	static KOORD_VAL gui_hspace;
271 	static KOORD_VAL gui_vspace;
272 	/// @}
273 
274 	// those are the 3x3 images which are used for stretching
275 	static stretch_map_t button_tiles[3];
276 	static stretch_map_t button_color_tiles[2];
277 	static stretch_map_t round_button_tiles[3];
278 	static stretch_map_t h_scroll_back_tiles;
279 	static stretch_map_t h_scroll_knob_tiles;
280 	static stretch_map_t v_scroll_back_tiles;
281 	static stretch_map_t v_scroll_knob_tiles;
282 	static stretch_map_t divider;
283 	static stretch_map_t editfield;
284 	static stretch_map_t listbox;
285 	static stretch_map_t windowback;
286 
287 	// those are the normal, selected and disabled simple buttons
288 	static image_id arrow_button_left_img[3];
289 	static image_id arrow_button_right_img[3];
290 	static image_id arrow_button_up_img[3];
291 	static image_id arrow_button_down_img[3];
292 	static image_id check_button_img[3];
293 	static image_id pos_button_img[3];
294 
295 	static bool gui_drop_shadows;
296 
297 public:
298 	// default dimensions and colors
299 	static void init_gui_defaults();
300 
301 	// assings k with the dimension of this image
302 	static void init_size_from_image( const image_t *pic, scr_size &k );
303 
304 	// init the skin dimensions form file
305 	static void init_gui_from_images();
306 
307 	/**
308 	 * Reads theme configuration data, still not final
309 	 * searches a theme.tab inside the specified folder
310 	 * @author prissi
311 	 */
312 	static bool themes_init(const char *dir_name,bool init_font);
313 };
314 #endif
315