r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / guicast / bcresources.C
blob999f0356a9f45bcdd8d645e6446f73be776eda52
1 #include "bcdisplayinfo.h"
2 #include "bcipc.h"
3 #include "bclistbox.inc"
4 #include "bcresources.h"
5 #include "bcsignals.h"
6 #include "bcwindowbase.h"
7 #include "colors.h"
8 #include "colormodels.h"
9 #include "fonts.h"
10 #include "vframe.h"
12 #include <locale.h>
13 #include <string.h>
14 #include <sys/ipc.h>
15 #include <sys/shm.h>
16 #include <X11/extensions/XShm.h>
17 #include <unistd.h>
19 #include <libintl.h>
20 #define _(String) gettext(String)
21 #define gettext_noop(String) String
22 #define N_(String) gettext_noop (String)
24 int BC_Resources::error = 0;
26 VFrame* BC_Resources::bg_image = 0;
27 VFrame* BC_Resources::menu_bg = 0;
29 #include "images/file_film_png.h"
30 #include "images/file_folder_png.h"
31 #include "images/file_sound_png.h"
32 #include "images/file_unknown_png.h"
33 VFrame* BC_Resources::type_to_icon[] = 
35         new VFrame(file_folder_png),
36         new VFrame(file_unknown_png),
37         new VFrame(file_film_png),
38         new VFrame(file_sound_png)
41 char* BC_Resources::small_font = N_("-*-helvetica-medium-r-normal-*-10-*");
42 char* BC_Resources::medium_font = N_("-*-helvetica-bold-r-normal-*-14-*");
43 char* BC_Resources::large_font = N_("-*-helvetica-bold-r-normal-*-18-*");
44 char* BC_Resources::small_fontset = "6x12,*";
45 char* BC_Resources::medium_fontset = "7x14,*";
46 char* BC_Resources::large_fontset = "8x16,*";
48 suffix_to_type_t BC_Resources::suffix_to_type[] = 
50         { "m2v", ICON_FILM },
51         { "mov", ICON_FILM },
52         { "mp2", ICON_SOUND },
53         { "mp3", ICON_SOUND },
54         { "mpg", ICON_FILM },
55         { "vob", ICON_FILM },
56         { "wav", ICON_SOUND }
59 BC_Signals* BC_Resources::signal_handler = 0;
61 int BC_Resources::x_error_handler(Display *display, XErrorEvent *event)
63         char string[1024];
64         XGetErrorText(event->display, event->error_code, string, 1024);
65 //      printf("BC_Resources::x_error_handler: %s\n", string);
66         BC_Resources::error = 1;
67         return 0;
72 BC_Resources::BC_Resources()
74         display_info = new BC_DisplayInfo("", 0);
75         use_xvideo = 1;
76 #include "images/cancel_up_png.h"
77 #include "images/cancel_hi_png.h"
78 #include "images/cancel_dn_png.h"
79         static VFrame* default_cancel_images[] = 
80         {
81                 new VFrame(cancel_up_png),
82                 new VFrame(cancel_hi_png),
83                 new VFrame(cancel_dn_png)
84         };
86 #include "images/ok_up_png.h"
87 #include "images/ok_hi_png.h"
88 #include "images/ok_dn_png.h"
89         static VFrame* default_ok_images[] = 
90         {
91                 new VFrame(ok_up_png),
92                 new VFrame(ok_hi_png),
93                 new VFrame(ok_dn_png)
94         };
96 #include "images/usethis_up_png.h"
97 #include "images/usethis_uphi_png.h"
98 #include "images/usethis_dn_png.h"
99         static VFrame* default_usethis_images[] = 
100         {
101                 new VFrame(usethis_up_png),
102                 new VFrame(usethis_uphi_png),
103                 new VFrame(usethis_dn_png)
104         };
106 #include "images/checkbox_checked_png.h"
107 #include "images/checkbox_down_png.h"
108 #include "images/checkbox_checkedhi_png.h"
109 #include "images/checkbox_up_png.h"
110 #include "images/checkbox_uphi_png.h"
111         static VFrame* default_checkbox_images[] =  
112         {
113                 new VFrame(checkbox_up_png),
114                 new VFrame(checkbox_uphi_png),
115                 new VFrame(checkbox_checked_png),
116                 new VFrame(checkbox_down_png),
117                 new VFrame(checkbox_checkedhi_png)
118         };
120 #include "images/radial_checked_png.h"
121 #include "images/radial_down_png.h"
122 #include "images/radial_checkedhi_png.h"
123 #include "images/radial_up_png.h"
124 #include "images/radial_uphi_png.h"
125         static VFrame* default_radial_images[] =  
126         {
127                 new VFrame(radial_up_png),
128                 new VFrame(radial_uphi_png),
129                 new VFrame(radial_checked_png),
130                 new VFrame(radial_down_png),
131                 new VFrame(radial_checkedhi_png)
132         };
134         static VFrame* default_label_images[] =  
135         {
136                 new VFrame(radial_up_png),
137                 new VFrame(radial_uphi_png),
138                 new VFrame(radial_checked_png),
139                 new VFrame(radial_down_png),
140                 new VFrame(radial_checkedhi_png)
141         };
144 #include "images/file_text_up_png.h"
145 #include "images/file_text_uphi_png.h"
146 #include "images/file_text_dn_png.h"
147 #include "images/file_icons_up_png.h"
148 #include "images/file_icons_uphi_png.h"
149 #include "images/file_icons_dn_png.h"
150 #include "images/file_newfolder_up_png.h"
151 #include "images/file_newfolder_uphi_png.h"
152 #include "images/file_newfolder_dn_png.h"
153 #include "images/file_updir_up_png.h"
154 #include "images/file_updir_uphi_png.h"
155 #include "images/file_updir_dn_png.h"
156         static VFrame* default_filebox_text_images[] = 
157         {
158                 new VFrame(file_text_up_png),
159                 new VFrame(file_text_uphi_png),
160                 new VFrame(file_text_dn_png)
161         };
163         static VFrame* default_filebox_icons_images[] = 
164         {
165                 new VFrame(file_icons_up_png),
166                 new VFrame(file_icons_uphi_png),
167                 new VFrame(file_icons_dn_png)
168         };
170         static VFrame* default_filebox_updir_images[] =  
171         {
172                 new VFrame(file_updir_up_png),
173                 new VFrame(file_updir_uphi_png),
174                 new VFrame(file_updir_dn_png)
175         };
177         static VFrame* default_filebox_newfolder_images[] = 
178         {
179                 new VFrame(file_newfolder_up_png),
180                 new VFrame(file_newfolder_uphi_png),
181                 new VFrame(file_newfolder_dn_png)
182         };
184 #include "images/listbox_button_dn_png.h"
185 #include "images/listbox_button_hi_png.h"
186 #include "images/listbox_button_up_png.h"
187         static VFrame* default_listbox_button[] = 
188         {
189                 new VFrame(listbox_button_up_png),
190                 new VFrame(listbox_button_hi_png),
191                 new VFrame(listbox_button_dn_png)
192         };
193         listbox_button = default_listbox_button;
195 #include "images/list_bg_png.h"
196         static VFrame* default_listbox_bg = new VFrame(list_bg_png);
197         listbox_bg = default_listbox_bg;
199 #include "images/listbox_expandchecked_png.h"
200 #include "images/listbox_expandcheckedhi_png.h"
201 #include "images/listbox_expanddn_png.h"
202 #include "images/listbox_expandup_png.h"
203 #include "images/listbox_expanduphi_png.h"
204         static VFrame* default_listbox_expand[] = 
205         {
206                 new VFrame(listbox_expandup_png),
207                 new VFrame(listbox_expanduphi_png),
208                 new VFrame(listbox_expandchecked_png),
209                 new VFrame(listbox_expanddn_png),
210                 new VFrame(listbox_expandcheckedhi_png),
211         };
212         listbox_expand = default_listbox_expand;
215 #include "images/horizontal_slider_bg_up_png.h"
216 #include "images/horizontal_slider_bg_hi_png.h"
217 #include "images/horizontal_slider_bg_dn_png.h"
218 #include "images/horizontal_slider_fg_up_png.h"
219 #include "images/horizontal_slider_fg_hi_png.h"
220 #include "images/horizontal_slider_fg_dn_png.h"
221         static VFrame *default_horizontal_slider_data[] = 
222         {
223                 new VFrame(horizontal_slider_fg_up_png),
224                 new VFrame(horizontal_slider_fg_hi_png),
225                 new VFrame(horizontal_slider_fg_dn_png),
226                 new VFrame(horizontal_slider_bg_up_png),
227                 new VFrame(horizontal_slider_bg_hi_png),
228                 new VFrame(horizontal_slider_bg_dn_png),
229         };
231 #include "images/vertical_slider_bg_up_png.h"
232 #include "images/vertical_slider_bg_hi_png.h"
233 #include "images/vertical_slider_bg_dn_png.h"
234 #include "images/vertical_slider_fg_up_png.h"
235 #include "images/vertical_slider_fg_hi_png.h"
236 #include "images/vertical_slider_fg_dn_png.h"
237         static VFrame *default_vertical_slider_data[] = 
238         {
239                 new VFrame(vertical_slider_fg_up_png),
240                 new VFrame(vertical_slider_fg_hi_png),
241                 new VFrame(vertical_slider_fg_dn_png),
242                 new VFrame(vertical_slider_bg_up_png),
243                 new VFrame(vertical_slider_bg_hi_png),
244                 new VFrame(vertical_slider_bg_dn_png),
245         };
246         horizontal_slider_data = default_horizontal_slider_data;
247         vertical_slider_data = default_vertical_slider_data;
249 #include "images/pot_hi_png.h"
250 #include "images/pot_up_png.h"
251 #include "images/pot_dn_png.h"
252         static VFrame *default_pot_images[] = 
253         {
254                 new VFrame(pot_up_png),
255                 new VFrame(pot_hi_png),
256                 new VFrame(pot_dn_png)
257         };
259 #include "images/progress_up_png.h"
260 #include "images/progress_hi_png.h"
261         static VFrame* default_progress_images[] = 
262         {
263                 new VFrame(progress_up_png),
264                 new VFrame(progress_hi_png)
265         };
268 #include "images/pan_up_png.h"
269 #include "images/pan_hi_png.h"
270 #include "images/pan_popup_png.h"
271 #include "images/pan_channel_png.h"
272 #include "images/pan_stick_png.h"
273 #include "images/pan_channel_small_png.h"
274 #include "images/pan_stick_small_png.h"
275         static VFrame* default_pan_data[] = 
276         {
277                 new VFrame(pan_up_png),
278                 new VFrame(pan_hi_png),
279                 new VFrame(pan_popup_png),
280                 new VFrame(pan_channel_png),
281                 new VFrame(pan_stick_png),
282                 new VFrame(pan_channel_small_png),
283                 new VFrame(pan_stick_small_png)
284         };
285         pan_data = default_pan_data;
286         pan_text_color = YELLOW;
288 #include "images/7seg_small/0_png.h"
289 #include "images/7seg_small/1_png.h"
290 #include "images/7seg_small/2_png.h"
291 #include "images/7seg_small/3_png.h"
292 #include "images/7seg_small/4_png.h"
293 #include "images/7seg_small/5_png.h"
294 #include "images/7seg_small/6_png.h"
295 #include "images/7seg_small/7_png.h"
296 #include "images/7seg_small/8_png.h"
297 #include "images/7seg_small/9_png.h"
298 #include "images/7seg_small/colon_png.h"
299 #include "images/7seg_small/period_png.h"
300 #include "images/7seg_small/a_png.h"
301 #include "images/7seg_small/b_png.h"
302 #include "images/7seg_small/c_png.h"
303 #include "images/7seg_small/d_png.h"
304 #include "images/7seg_small/e_png.h"
305 #include "images/7seg_small/f_png.h"
306 #include "images/7seg_small/space_png.h"
307 #include "images/7seg_small/dash_png.h"
308         static VFrame* default_medium_7segment[] = 
309         {
310                 new VFrame(_0_png),
311                 new VFrame(_1_png),
312                 new VFrame(_2_png),
313                 new VFrame(_3_png),
314                 new VFrame(_4_png),
315                 new VFrame(_5_png),
316                 new VFrame(_6_png),
317                 new VFrame(_7_png),
318                 new VFrame(_8_png),
319                 new VFrame(_9_png),
320                 new VFrame(colon_png),
321                 new VFrame(period_png),
322                 new VFrame(a_png),
323                 new VFrame(b_png),
324                 new VFrame(c_png),
325                 new VFrame(d_png),
326                 new VFrame(e_png),
327                 new VFrame(f_png),
328                 new VFrame(space_png),
329                 new VFrame(dash_png)
330         };
332 #include "images/tumble_bottomdn_png.h"
333 #include "images/tumble_topdn_png.h"
334 #include "images/tumble_hi_png.h"
335 #include "images/tumble_up_png.h"
336         static VFrame* default_tumbler_data[] = 
337         {
338                 new VFrame(tumble_up_png),
339                 new VFrame(tumble_hi_png),
340                 new VFrame(tumble_bottomdn_png),
341                 new VFrame(tumble_topdn_png)
342         };
344 #include "images/xmeter_normal_png.h"
345 #include "images/xmeter_green_png.h"
346 #include "images/xmeter_red_png.h"
347 #include "images/xmeter_yellow_png.h"
348 #include "images/over_horiz_png.h"
349 #include "images/ymeter_normal_png.h"
350 #include "images/ymeter_green_png.h"
351 #include "images/ymeter_red_png.h"
352 #include "images/ymeter_yellow_png.h"
353 #include "images/over_vertical_png.h"
354         static VFrame* default_xmeter_data[] =
355         {
356                 new VFrame(xmeter_normal_png),
357                 new VFrame(xmeter_green_png),
358                 new VFrame(xmeter_red_png),
359                 new VFrame(xmeter_yellow_png),
360                 new VFrame(over_horiz_png)
361         };
363         static VFrame* default_ymeter_data[] =
364         {
365                 new VFrame(ymeter_normal_png),
366                 new VFrame(ymeter_green_png),
367                 new VFrame(ymeter_red_png),
368                 new VFrame(ymeter_yellow_png),
369                 new VFrame(over_vertical_png)
370         };
372 #include "images/generic_up_png.h"
373 #include "images/generic_hi_png.h"
374 #include "images/generic_dn_png.h"
375         
376         static VFrame* default_generic_button_data[] = 
377         {
378                 new VFrame(generic_up_png),
379                 new VFrame(generic_hi_png),
380                 new VFrame(generic_dn_png)
381         };
382         
383         generic_button_images = default_generic_button_data;
388 #include "images/hscroll_handle_up_png.h"
389 #include "images/hscroll_handle_hi_png.h"
390 #include "images/hscroll_handle_dn_png.h"
391 #include "images/hscroll_handle_bg_png.h"
392 #include "images/hscroll_left_up_png.h"
393 #include "images/hscroll_left_hi_png.h"
394 #include "images/hscroll_left_dn_png.h"
395 #include "images/hscroll_right_up_png.h"
396 #include "images/hscroll_right_hi_png.h"
397 #include "images/hscroll_right_dn_png.h"
398 #include "images/vscroll_handle_up_png.h"
399 #include "images/vscroll_handle_hi_png.h"
400 #include "images/vscroll_handle_dn_png.h"
401 #include "images/vscroll_handle_bg_png.h"
402 #include "images/vscroll_left_up_png.h"
403 #include "images/vscroll_left_hi_png.h"
404 #include "images/vscroll_left_dn_png.h"
405 #include "images/vscroll_right_up_png.h"
406 #include "images/vscroll_right_hi_png.h"
407 #include "images/vscroll_right_dn_png.h"
408         static VFrame *default_hscroll_data[] = 
409         {
410                 new VFrame(hscroll_handle_up_png), 
411                 new VFrame(hscroll_handle_hi_png), 
412                 new VFrame(hscroll_handle_dn_png), 
413                 new VFrame(hscroll_handle_bg_png), 
414                 new VFrame(hscroll_left_up_png), 
415                 new VFrame(hscroll_left_hi_png), 
416                 new VFrame(hscroll_left_dn_png), 
417                 new VFrame(hscroll_right_up_png), 
418                 new VFrame(hscroll_right_hi_png), 
419                 new VFrame(hscroll_right_dn_png)
420         };
421         static VFrame *default_vscroll_data[] = 
422         {
423                 new VFrame(vscroll_handle_up_png), 
424                 new VFrame(vscroll_handle_hi_png), 
425                 new VFrame(vscroll_handle_dn_png), 
426                 new VFrame(vscroll_handle_bg_png), 
427                 new VFrame(vscroll_left_up_png), 
428                 new VFrame(vscroll_left_hi_png), 
429                 new VFrame(vscroll_left_dn_png), 
430                 new VFrame(vscroll_right_up_png), 
431                 new VFrame(vscroll_right_hi_png), 
432                 new VFrame(vscroll_right_dn_png)
433         };
434         hscroll_data = default_hscroll_data;
435         vscroll_data = default_vscroll_data;
440         use_shm = -1;
442 // Initialize
443         bg_color = MEGREY;
444         bg_shadow1 = DKGREY;
445         bg_shadow2 = BLACK;
446         bg_light1 = WHITE;
447         bg_light2 = bg_color;
449         button_light = WHITE;           // bright corner
450         button_highlighted = LTGREY;  // face when highlighted
451         button_down = MDGREY;         // face when down
452         button_up = MEGREY;           // face when up
453         button_shadow = DKGREY;       // dark corner
455         tumble_data = default_tumbler_data;
456         tumble_duration = 150;
458         ok_images = default_ok_images;
459         cancel_images = default_cancel_images;
460         usethis_button_images = default_usethis_images;
462         filebox_text_images = default_filebox_text_images;
463         filebox_icons_images = default_filebox_icons_images;
464         filebox_updir_images = default_filebox_updir_images;
465         filebox_newfolder_images = default_filebox_newfolder_images;
467         checkbox_images = default_checkbox_images;
468         radial_images = default_radial_images;
469         label_images = default_label_images;
471         menu_light = LTCYAN;
472         menu_highlighted = LTBLUE;
473         menu_down = MDCYAN;
474         menu_up = MECYAN;
475         menu_shadow = DKCYAN;
477         text_default = BLACK;
478         text_background = WHITE;
479         highlight_inverse = WHITE ^ BLUE;
480         text_highlight = BLUE;
482 // Delays must all be different for repeaters
483         double_click = 300;
484         blink_rate = 250;
485         scroll_repeat = 150;
486         tooltip_delay = 1000;
487         tooltip_bg_color = YELLOW;
488         tooltips_enabled = 1;
490         filebox_mode = LISTBOX_TEXT;
491         sprintf(filebox_filter, "*");
492         filebox_w = 640;
493         filebox_h = 480;
496         pot_images = default_pot_images;
497         pot_x1 = pot_images[0]->get_w() / 2 - 2;
498         pot_y1 = pot_images[0]->get_h() / 2 - 2;;
499         pot_r = pot_x1;
501         progress_images = default_progress_images;
503         xmeter_images = default_xmeter_data;
504         ymeter_images = default_ymeter_data;
505         meter_font = SMALLFONT_3D;
506         meter_font_color = RED;
507         meter_title_w = 20;
508         meter_3d = 1;
509         medium_7segment = default_medium_7segment;
510         use_fontset = 0;
511         if(use_fontset) setlocale(LC_ALL, "");
512         drag_radius = 10;
513         recursive_resizing = 1;
515         
518 BC_Resources::~BC_Resources()
522 int BC_Resources::initialize_display(BC_WindowBase *window)
524 // Set up IPC cleanup handlers
525         bc_init_ipc();
527 // Test for shm.  Must come before yuv test
528         init_shm(window);
529         return 0;
533 int BC_Resources::init_shm(BC_WindowBase *window)
535         use_shm = 1;
536         XSetErrorHandler(BC_Resources::x_error_handler);
538         if(!XShmQueryExtension(window->display)) use_shm = 0;
539         else
540         {
541                 XShmSegmentInfo test_shm;
542                 XImage *test_image;
543                 unsigned char *data;
544                 test_image = XShmCreateImage(window->display, window->vis, window->default_depth,
545                 ZPixmap, (char*)NULL, &test_shm, 5, 5);
547                 test_shm.shmid = shmget(IPC_PRIVATE, 5 * test_image->bytes_per_line, (IPC_CREAT | 0777 ));
548                 data = (unsigned char *)shmat(test_shm.shmid, NULL, 0);
549         shmctl(test_shm.shmid, IPC_RMID, 0);
550                 BC_Resources::error = 0;
551                 XShmAttach(window->display, &test_shm);
552         XSync(window->display, False);
553                 if(BC_Resources::error) use_shm = 0;
554                 XDestroyImage(test_image);
555                 shmdt(test_shm.shmaddr);
556         }
557 //      XSetErrorHandler(0);
558         return 0;
561 int BC_Resources::get_top_border()
563         return display_info->get_top_border();
566 int BC_Resources::get_left_border()
568         return display_info->get_left_border();
571 int BC_Resources::get_right_border()
573         return display_info->get_right_border();
576 int BC_Resources::get_bottom_border()
578         return display_info->get_bottom_border();
582 int BC_Resources::get_bg_color() { return bg_color; }
584 int BC_Resources::get_bg_shadow1() { return bg_shadow1; }
586 int BC_Resources::get_bg_shadow2() { return bg_shadow2; }
588 int BC_Resources::get_bg_light1() { return bg_light1; }
590 int BC_Resources::get_bg_light2() { return bg_light2; }