]> icculus.org git repositories - dana/openbox.git/blob - render2/theme.c
smaller again :>
[dana/openbox.git] / render2 / theme.c
1 #include "render.h"
2 #include "theme.h"
3 #include "planar.h"
4 #include <stdlib.h>
5
6 struct RrTheme *RrThemeLoad(struct RrInstance *inst, const char *name)
7 {
8     struct RrTheme *theme;
9     struct RrColor pri, sec, bor;
10
11     theme = malloc(sizeof(struct RrTheme));
12     theme->inst = inst;
13
14 #define MERRY
15 #ifdef MERRY
16
17     theme->bevel = 1;
18     theme->bwidth = 1;
19     theme->cbwidth = 0;
20     theme->handle_height = 4;
21
22     theme->title_layout = "NLIMC";
23
24     theme->title_font = RrFontOpen(inst,
25                                   "arial:bold:pixelsize=10:"
26                                   "shadow=true:shadowoffset=1:shadowtint=0.1");
27     theme->title_justify = RR_CENTER;
28
29     RrColorSet(&theme->b_color, 0, 0, 0, 1);
30     RrColorSet(&theme->cb_color, 0, 0, 0, 1);
31     RrColorSet(&theme->cb_color_f, 0, 0, 0, 1);
32     RrColorSet(&theme->title_color, 1, 1, 1, 1);
33     RrColorSet(&theme->title_color_f, 1, 1, 1, 1);
34     RrColorSet(&theme->button_color, 0.3, 0.3, 0.3, 1);
35     RrColorSet(&theme->button_color_f, 0.12, 0.12, 0.12, 1);
36     RrColorSet(&theme->menu_title_color, 1, 1, 1, 1);
37     RrColorSet(&theme->menu_item_color, 1, 1, 1, 1);
38     RrColorSet(&theme->menu_disabled_color, 1, 1, 1, 1);
39     RrColorSet(&theme->menu_hilite_color, 1, 1, 1, 1);
40
41     theme->max = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
42     theme->max_f = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
43     theme->max_p = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
44     theme->max_p_f = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
45     theme->iconify = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
46     theme->iconify_f = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
47     theme->iconify_p = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
48     theme->iconify_p_f = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
49     theme->close = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
50     theme->close_f = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
51     theme->close_p = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
52     theme->close_p_f = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
53     theme->desk = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
54     theme->desk_f = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
55     theme->desk_p = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
56     theme->desk_p_f = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
57     theme->shade = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
58     theme->shade_f = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
59     theme->shade_p = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
60     theme->shade_p_f = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
61
62     RrColorSet(&pri, 0.9, 0.91, 0.9, 1);
63     RrPlanarSet(theme->max, RR_PLANAR_SOLID, RR_BEVEL_NONE,
64                 &pri, NULL, 0, NULL);
65     RrPlanarSet(theme->max_f, RR_PLANAR_SOLID, RR_BEVEL_NONE,
66                 &pri, NULL, 0, NULL);
67
68     RrColorSet(&pri, 0.71, 0.7, 0.68, 1);
69     RrPlanarSet(theme->max_p, RR_PLANAR_SOLID, RR_SUNKEN_OUTER,
70                 &pri, NULL, 0, NULL);
71     RrPlanarSet(theme->max_p_f, RR_PLANAR_SOLID, RR_SUNKEN_OUTER,
72                 &pri, NULL, 0, NULL);
73
74     RrColorSet(&pri, 0.9, 0.91, 0.9, 1);
75     RrPlanarSet(theme->iconify, RR_PLANAR_SOLID, RR_BEVEL_NONE,
76                 &pri, NULL, 0, NULL);
77     RrPlanarSet(theme->iconify_f, RR_PLANAR_SOLID, RR_BEVEL_NONE,
78                 &pri, NULL, 0, NULL);
79
80     RrColorSet(&pri, 0.71, 0.7, 0.68, 1);
81     RrPlanarSet(theme->iconify_p, RR_PLANAR_SOLID, RR_SUNKEN_OUTER,
82                 &pri, NULL, 0, NULL);
83     RrPlanarSet(theme->iconify_p_f, RR_PLANAR_SOLID, RR_SUNKEN_OUTER,
84                 &pri, NULL, 0, NULL);
85
86     RrColorSet(&pri, 0.9, 0.91, 0.9, 1);
87     RrPlanarSet(theme->close, RR_PLANAR_SOLID, RR_BEVEL_NONE,
88                 &pri, NULL, 0, NULL);
89     RrPlanarSet(theme->close_f, RR_PLANAR_SOLID, RR_BEVEL_NONE,
90                 &pri, NULL, 0, NULL);
91
92     RrColorSet(&pri, 0.71, 0.7, 0.68, 1);
93     RrPlanarSet(theme->close_p, RR_PLANAR_SOLID, RR_SUNKEN_OUTER,
94                 &pri, NULL, 0, NULL);
95     RrPlanarSet(theme->close_p_f, RR_PLANAR_SOLID, RR_SUNKEN_OUTER,
96                 &pri, NULL, 0, NULL);
97
98     RrColorSet(&pri, 0.9, 0.91, 0.9, 1);
99     RrPlanarSet(theme->desk, RR_PLANAR_SOLID, RR_BEVEL_NONE,
100                 &pri, NULL, 0, NULL);
101     RrPlanarSet(theme->desk_f, RR_PLANAR_SOLID, RR_BEVEL_NONE,
102                 &pri, NULL, 0, NULL);
103
104     RrColorSet(&pri, 0.71, 0.7, 0.68, 1);
105     RrPlanarSet(theme->desk_p, RR_PLANAR_SOLID, RR_SUNKEN_OUTER,
106                 &pri, NULL, 0, NULL);
107     RrPlanarSet(theme->desk_p_f, RR_PLANAR_SOLID, RR_SUNKEN_OUTER,
108                 &pri, NULL, 0, NULL);
109
110     RrColorSet(&pri, 0.9, 0.91, 0.9, 1);
111     RrPlanarSet(theme->shade, RR_PLANAR_SOLID, RR_BEVEL_NONE,
112                 &pri, NULL, 0, NULL);
113     RrPlanarSet(theme->shade_f, RR_PLANAR_SOLID, RR_BEVEL_NONE,
114                 &pri, NULL, 0, NULL);
115
116     RrColorSet(&pri, 0.71, 0.7, 0.68, 1);
117     RrPlanarSet(theme->shade_p, RR_PLANAR_SOLID, RR_SUNKEN_OUTER,
118                 &pri, NULL, 0, NULL);
119     RrPlanarSet(theme->shade_p_f, RR_PLANAR_SOLID, RR_SUNKEN_OUTER,
120                 &pri, NULL, 0, NULL);
121
122     theme->frame = RrSurfaceNewProto(RR_SURFACE_PLANAR, 0);
123
124     RrColorSet(&pri, 0.9, 0.91, 0.9, 1);
125     RrColorSet(&bor, 0, 0, 0, 1);
126     RrPlanarSet(theme->frame, RR_PLANAR_SOLID, RR_BEVEL_NONE,
127                 &pri, NULL, 1, &bor);
128
129     theme->title = RrSurfaceNewProto(RR_SURFACE_PLANAR, 0);
130     theme->title_f = RrSurfaceNewProto(RR_SURFACE_PLANAR, 0);
131
132     RrColorSet(&pri, 0.9, 0.91, 0.9, 1);
133     RrColorSet(&bor, 0, 0, 0, 1);
134     RrPlanarSet(theme->title, RR_PLANAR_SOLID, RR_BEVEL_NONE,
135                 &pri, NULL, 1, &bor);
136     RrPlanarSet(theme->title_f, RR_PLANAR_SOLID, RR_BEVEL_NONE,
137                 &pri, NULL, 1, &bor);
138
139     theme->plate = RrSurfaceNewProto(RR_SURFACE_PLANAR, 0);
140     theme->plate_f = RrSurfaceNewProto(RR_SURFACE_PLANAR, 0);
141
142     RrColorSet(&pri, 0, 0, 0, 1);
143     RrPlanarSet(theme->plate, RR_PLANAR_SOLID, RR_BEVEL_NONE,
144                 &pri, NULL, 0, NULL);
145     RrPlanarSet(theme->plate_f, RR_PLANAR_SOLID, RR_BEVEL_NONE,
146                 &pri, NULL, 0, NULL);
147
148     theme->label = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
149     theme->label_f = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
150
151     RrColorSet(&pri, 0.70, 0.70, 0.68, 1);
152     RrColorSet(&sec, 0.75, 0.73, 0.71, 1);
153     RrColorSet(&bor, 0.42, 0.41, 0.42, 1);
154     RrPlanarSet(theme->label, RR_PLANAR_VERTICAL, RR_BEVEL_NONE,
155                 &pri, &sec, 1, &bor);
156     RrColorSet(&pri, 0.30, 0.34, 0.65, 1);
157     RrColorSet(&sec, 0.35, 0.43, 0.75, 1);
158     RrColorSet(&bor, 0, 0, 0, 1);
159     RrPlanarSet(theme->label_f, RR_PLANAR_SOLID, RR_BEVEL_NONE,
160                 &pri, &sec, 1, &bor);
161
162
163     theme->grip = RrSurfaceNewProto(RR_SURFACE_PLANAR, 0);
164     theme->grip_f = RrSurfaceNewProto(RR_SURFACE_PLANAR, 0);
165
166     RrColorSet(&pri, 0.9, 0.91, 0.9, 1);
167     RrColorSet(&bor, 0, 0, 0, 1);
168     RrPlanarSet(theme->grip, RR_PLANAR_SOLID, RR_BEVEL_NONE,
169                 &pri, NULL, 1, &bor);
170     RrPlanarSet(theme->grip_f, RR_PLANAR_SOLID, RR_BEVEL_NONE,
171                 &pri, NULL, 1, &bor);
172
173     theme->handle = RrSurfaceNewProto(RR_SURFACE_PLANAR, 0);
174     theme->handle_f = RrSurfaceNewProto(RR_SURFACE_PLANAR, 0);
175
176     RrColorSet(&pri, 0.9, 0.91, 0.9, 1);
177     RrColorSet(&bor, 0, 0, 0, 1);
178     RrPlanarSet(theme->handle, RR_PLANAR_SOLID, RR_BEVEL_NONE,
179                 &pri, NULL, 1, &bor);
180     RrPlanarSet(theme->handle_f, RR_PLANAR_SOLID, RR_BEVEL_NONE,
181                 &pri, NULL, 1, &bor);
182
183     theme->menu_title = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
184
185     RrColorSet(&pri, 0.29, 0.35, 0.65, 1);
186     RrColorSet(&bor, 0, 0, 0, 1);
187     RrPlanarSet(theme->menu_title, RR_PLANAR_SOLID, RR_BEVEL_NONE,
188                 &pri, NULL, 1, &bor);
189
190     theme->menu_item = RrSurfaceNewProto(RR_SURFACE_PLANAR, 0);
191
192     RrColorSet(&pri, 0.9, 0.91, 0.9, 1);
193     RrPlanarSet(theme->menu_item, RR_PLANAR_SOLID, RR_BEVEL_NONE,
194                 &pri, NULL, 0, NULL);
195
196     theme->menu_disabled = RrSurfaceNewProto(RR_SURFACE_PLANAR, 0);
197
198     RrColorSet(&pri, 0.9, 0.91, 0.9, 1);
199     RrPlanarSet(theme->menu_item, RR_PLANAR_SOLID, RR_BEVEL_NONE,
200                 &pri, NULL, 0, NULL);
201
202     theme->menu_hilite = RrSurfaceNewProto(RR_SURFACE_PLANAR, 0);
203
204     /* app stuff */
205
206     RrColorSet(&theme->app_label_color, 1, 1, 1, 1);
207     RrColorSet(&theme->app_label_color_h, 1, 1, 1, 1);
208
209     RrColorSet(&pri, 0.9, 0.91, 0.9, 1);
210     RrPlanarSet(theme->menu_item, RR_PLANAR_SOLID, RR_BEVEL_NONE,
211                 &pri, NULL, 0, NULL);
212
213     theme->app_bg = RrSurfaceNewProto(RR_SURFACE_PLANAR, 0);
214     theme->app_bg_h = RrSurfaceNewProto(RR_SURFACE_PLANAR, 0);
215
216     RrColorSet(&pri, 0.9, 0.91, 0.9, 1);
217     RrColorSet(&bor, 0, 0, 0, 1);
218     RrPlanarSet(theme->app_bg, RR_PLANAR_SOLID, RR_BEVEL_NONE,
219                 &pri, NULL, 1, &bor);
220     RrPlanarSet(theme->app_bg_h, RR_PLANAR_SOLID, RR_BEVEL_NONE,
221                 &pri, NULL, 1, &bor);
222
223     theme->app_label = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
224     theme->app_label_h = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
225
226     RrColorSet(&pri, 0.70, 0.70, 0.68, 1);
227     RrColorSet(&sec, 0.75, 0.73, 0.71, 1);
228     RrColorSet(&bor, 0.42, 0.41, 0.42, 1);
229     RrPlanarSet(theme->app_label, RR_PLANAR_VERTICAL, RR_BEVEL_NONE,
230                 &pri, &sec, 1, &bor); 
231     RrColorSet(&pri, 0.30, 0.34, 0.65, 1);
232     RrColorSet(&sec, 0.35, 0.43, 0.75, 1);
233     RrColorSet(&bor, 0, 0, 0, 1);
234     RrPlanarSet(theme->app_label_h, RR_PLANAR_SOLID, RR_BEVEL_NONE,
235                 &pri, &sec, 1, &bor);
236
237 #endif
238
239     RrColorSet(&pri, 0, 0, 0, 0); /* clear */
240
241     theme->icon = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
242     RrPlanarSet(theme->icon, RR_PLANAR_SOLID, RR_BEVEL_NONE,
243                 &pri, NULL, 0, NULL);
244
245     theme->app_icon = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1);
246     RrPlanarSet(theme->app_icon, RR_PLANAR_SOLID, RR_BEVEL_NONE,
247                 &pri, NULL, 0, NULL);
248
249     return theme;
250 }
251
252 void RrThemeDestroy(struct RrTheme *theme)
253 {
254     if (theme) {
255         RrFontClose(theme->title_font);
256
257         RrSurfaceFree(theme->max);
258         RrSurfaceFree(theme->max_f);
259         RrSurfaceFree(theme->max_p);
260         RrSurfaceFree(theme->max_p_f);
261
262         RrSurfaceFree(theme->iconify);
263         RrSurfaceFree(theme->iconify_f);
264         RrSurfaceFree(theme->iconify_p);
265         RrSurfaceFree(theme->iconify_p_f);
266
267         RrSurfaceFree(theme->close);
268         RrSurfaceFree(theme->close_f);
269         RrSurfaceFree(theme->close_p);
270         RrSurfaceFree(theme->close_p_f);
271
272         RrSurfaceFree(theme->desk);
273         RrSurfaceFree(theme->desk_f);
274         RrSurfaceFree(theme->desk_p);
275         RrSurfaceFree(theme->desk_p_f);
276
277         RrSurfaceFree(theme->shade);
278         RrSurfaceFree(theme->shade_f);
279         RrSurfaceFree(theme->shade_p);
280         RrSurfaceFree(theme->shade_p_f);
281
282         RrSurfaceFree(theme->icon);
283
284         RrSurfaceFree(theme->frame);
285
286         RrSurfaceFree(theme->title);
287         RrSurfaceFree(theme->title_f);
288
289         RrSurfaceFree(theme->label);
290         RrSurfaceFree(theme->label_f);
291
292         RrSurfaceFree(theme->grip);
293         RrSurfaceFree(theme->grip_f);
294
295         RrSurfaceFree(theme->handle);
296         RrSurfaceFree(theme->handle_f);
297
298         RrSurfaceFree(theme->menu_title);
299         RrSurfaceFree(theme->menu_item);
300         RrSurfaceFree(theme->menu_disabled);
301         RrSurfaceFree(theme->menu_hilite);
302
303         RrSurfaceFree(theme->app_bg);
304         RrSurfaceFree(theme->app_bg_h);
305         RrSurfaceFree(theme->app_label);
306         RrSurfaceFree(theme->app_label_h);
307         RrSurfaceFree(theme->app_icon);
308
309         free(theme);
310     }
311 }
312
313 int RrThemeLabelHeight(struct RrTheme *t)
314 {
315     int h;
316     h = RrFontHeight(t->title_font);
317     h += 2 * MAX(RrPlanarEdgeWidth(t->label),
318                  RrPlanarEdgeWidth(t->label_f));
319     return h;
320 }