2 #include "bcwindowbase.h"
21 image_sets.remove_all_objects();
26 printf("BC_Theme::dump 1 image_sets=%d contents=%d\n",
29 for(int i = 0; i < contents.total; i++)
30 printf(" %s %p\n", contents.values[i], pointers.values[i]);
33 BC_Resources* BC_Theme::get_resources()
35 return BC_WindowBase::get_resources();
39 // These create single images for storage in the image_sets table.
40 VFrame* BC_Theme::new_image(char *title, char *path)
42 VFrame *existing_image = title[0] ? get_image(title, 0) : 0;
43 if(existing_image) return existing_image;
45 BC_ThemeSet *result = new BC_ThemeSet(1, 0, title);
46 result->data[0] = new VFrame(get_image_data(path));
47 image_sets.append(result);
48 return result->data[0];
51 VFrame* BC_Theme::new_image(char *path)
53 return new_image("", path);
58 // These create image sets which are stored in the image_sets table.
59 VFrame** BC_Theme::new_image_set(char *title, int total, va_list *args)
61 VFrame **existing_image_set = title[0] ? get_image_set(title, 0) : 0;
62 if(existing_image_set) return existing_image_set;
64 BC_ThemeSet *result = new BC_ThemeSet(total, 1, title);
65 image_sets.append(result);
66 for(int i = 0; i < total; i++)
68 char *path = va_arg(*args, char*);
69 result->data[i] = new_image(path);
74 VFrame** BC_Theme::new_image_set_images(char *title, int total, ...)
77 va_start(list, total);
78 BC_ThemeSet *existing_image_set = title[0] ? get_image_set_object(title) : 0;
79 if(existing_image_set)
81 image_sets.remove_object(existing_image_set);
84 BC_ThemeSet *result = new BC_ThemeSet(total, 0, title);
85 image_sets.append(result);
86 for(int i = 0; i < total; i++)
88 result->data[i] = va_arg(list, VFrame*);
93 VFrame** BC_Theme::new_image_set(char *title, int total, ...)
96 va_start(list, total);
97 VFrame **result = new_image_set(title, total, &list);
103 VFrame** BC_Theme::new_image_set(int total, ...)
106 va_start(list, total);
107 VFrame **result = new_image_set("", total, &list);
113 VFrame* BC_Theme::get_image(char *title, int use_default)
115 for(int i = 0; i < image_sets.total; i++)
117 if(!strcmp(image_sets.values[i]->title, title))
119 return image_sets.values[i]->data[0];
125 // Return the first image it can find. This should always work.
128 printf("BC_Theme::get_image: image \"%s\" not found.\n",
132 return image_sets.values[0]->data[0];
136 // Give up and go to a movie.
140 VFrame** BC_Theme::get_image_set(char *title, int use_default)
142 for(int i = 0; i < image_sets.total; i++)
144 if(!strcmp(image_sets.values[i]->title, title))
146 return image_sets.values[i]->data;
150 // Get the image set with the largest number of images.
153 printf("BC_Theme::get_image_set: image set \"%s\" not found.\n",
157 for(int i = 0; i < image_sets.total; i++)
159 if(image_sets.values[i]->total > max_total)
161 max_total = image_sets.values[i]->total;
167 return image_sets.values[max_number]->data;
170 // Give up and go to a movie
174 BC_ThemeSet* BC_Theme::get_image_set_object(char *title)
176 for(int i = 0; i < image_sets.total; i++)
178 if(!strcmp(image_sets.values[i]->title, title))
180 return image_sets.values[i];
196 VFrame** BC_Theme::new_button(char *overlay_path,
202 VFrame default_data(get_image_data(overlay_path));
203 BC_ThemeSet *result = new BC_ThemeSet(3, 1, title ? title : (char*)"");
204 if(title) image_sets.append(result);
206 result->data[0] = new_image(up_path);
207 result->data[1] = new_image(hi_path);
208 result->data[2] = new_image(dn_path);
209 for(int i = 0; i < 3; i++)
211 overlay(result->data[i], &default_data, -1, -1, (i == 2));
217 VFrame** BC_Theme::new_button4(char *overlay_path,
224 VFrame default_data(get_image_data(overlay_path));
225 BC_ThemeSet *result = new BC_ThemeSet(4, 1, title ? title : (char*)"");
226 if(title) image_sets.append(result);
228 result->data[0] = new_image(up_path);
229 result->data[1] = new_image(hi_path);
230 result->data[2] = new_image(dn_path);
231 result->data[3] = new_image(disabled_path);
232 for(int i = 0; i < 4; i++)
234 overlay(result->data[i], &default_data, -1, -1, (i == 2));
240 VFrame** BC_Theme::new_button(char *overlay_path,
246 VFrame default_data(get_image_data(overlay_path));
247 BC_ThemeSet *result = new BC_ThemeSet(3, 0, title ? title : (char*)"");
248 if(title) image_sets.append(result);
250 result->data[0] = new VFrame(*up);
251 result->data[1] = new VFrame(*hi);
252 result->data[2] = new VFrame(*dn);
253 for(int i = 0; i < 3; i++)
254 overlay(result->data[i], &default_data, -1, -1, (i == 2));
259 VFrame** BC_Theme::new_toggle(char *overlay_path,
264 char *checkedhi_path,
267 VFrame default_data(get_image_data(overlay_path));
268 BC_ThemeSet *result = new BC_ThemeSet(5, 1, title ? title : (char*)"");
269 if(title) image_sets.append(result);
271 result->data[0] = new_image(up_path);
272 result->data[1] = new_image(hi_path);
273 result->data[2] = new_image(checked_path);
274 result->data[3] = new_image(dn_path);
275 result->data[4] = new_image(checkedhi_path);
276 for(int i = 0; i < 5; i++)
277 overlay(result->data[i], &default_data, -1, -1, (i == 3));
281 VFrame** BC_Theme::new_toggle(char *overlay_path,
289 VFrame default_data(get_image_data(overlay_path));
290 BC_ThemeSet *result = new BC_ThemeSet(5, 0, title ? title : (char*)"");
291 if(title) image_sets.append(result);
293 result->data[0] = new VFrame(*up);
294 result->data[1] = new VFrame(*hi);
295 result->data[2] = new VFrame(*checked);
296 result->data[3] = new VFrame(*dn);
297 result->data[4] = new VFrame(*checkedhi);
298 for(int i = 0; i < 5; i++)
299 overlay(result->data[i], &default_data, -1, -1, (i == 3));
303 void BC_Theme::overlay(VFrame *dst, VFrame *src, int in_x1, int in_x2, int shift)
307 unsigned char **in_rows;
308 unsigned char **out_rows;
312 w = MIN(src->get_w(), dst->get_w());
313 h = MIN(dst->get_h(), src->get_h());
320 h = MIN(dst->get_h(), src->get_h());
322 in_rows = src->get_rows();
323 out_rows = dst->get_rows();
325 switch(src->get_color_model())
328 switch(dst->get_color_model())
331 for(int i = shift; i < h; i++)
333 unsigned char *in_row = 0;
334 unsigned char *out_row;
338 in_row = in_rows[i] + in_x1 * 4;
339 out_row = out_rows[i];
343 in_row = in_rows[i - 1] + in_x1 * 4;
344 out_row = out_rows[i] + 4;
347 for(int j = shift; j < w; j++)
349 int opacity = in_row[3];
350 int transparency = 0xff - opacity;
352 out_row[0] = (in_row[0] * opacity + out_row[0] * transparency) / 0xff;
353 out_row[1] = (in_row[1] * opacity + out_row[1] * transparency) / 0xff;
354 out_row[2] = (in_row[2] * opacity + out_row[2] * transparency) / 0xff;
355 out_row[3] = MAX(in_row[3], out_row[3]);
363 for(int i = shift; i < h; i++)
365 unsigned char *in_row;
366 unsigned char *out_row = out_rows[i];
370 in_row = in_rows[i] + in_x1 * 3;
371 out_row = out_rows[i];
375 in_row = in_rows[i - 1] + in_x1 * 3;
376 out_row = out_rows[i] + 3;
379 for(int j = shift; j < w; j++)
381 int opacity = in_row[3];
382 int transparency = 0xff - opacity;
383 out_row[0] = (in_row[0] * opacity + out_row[0] * transparency) / 0xff;
384 out_row[1] = (in_row[1] * opacity + out_row[1] * transparency) / 0xff;
385 out_row[2] = (in_row[2] * opacity + out_row[2] * transparency) / 0xff;
396 void BC_Theme::set_data(unsigned char *ptr)
398 contents_ptr = (char*)(ptr + sizeof(int));
399 int contents_size = *(int*)ptr - sizeof(int);
400 data_ptr = contents_ptr + contents_size;
402 for(int i = 0; i < contents_size; )
405 contents.append(contents_ptr + i);
406 while(contents_ptr[i] && i < contents_size)
408 if(i < contents_size)
411 pointers.append((unsigned char*)data_ptr +
412 *(unsigned int*)(contents_ptr + i));
417 pointers.append((unsigned char*)data_ptr);
423 unsigned char* BC_Theme::get_image_data(char *title)
427 fprintf(stderr, "BC_Theme::get_image_data: no data set\n");
431 // Image is the same as the last one
432 if(last_image && !strcasecmp(last_image, title))
437 // Search for image anew.
438 for(int i = 0; i < contents.total; i++)
440 if(!strcasecmp(contents.values[i], title))
442 last_pointer = pointers.values[i];
443 last_image = contents.values[i];
445 return pointers.values[i];
449 fprintf(stderr, _("Theme::get_image: %s not found.\n"), title);
453 void BC_Theme::check_used()
455 // Can't use because some images are gotten the old fashioned way.
458 for(int i = 0; i < used.total; i++)
463 printf(_("BC_Theme::check_used: Images aren't used.\n"));
464 printf("%s ", contents.values[i]);
468 if(got_it) printf("\n");
482 BC_ThemeSet::BC_ThemeSet(int total, int is_reference, char *title)
485 this->title = new char[strlen(title) + 1];
486 strcpy(this->title, title);
487 this->is_reference = is_reference;
488 data = new VFrame*[total];
491 BC_ThemeSet::~BC_ThemeSet()
497 for(int i = 0; i < total; i++)