r370: Heroine Virutal's official release 1.2.1
[cinelerra_cv/mob.git] / hvirtual / guicast / bcresources.C
blobb59d6cb47115879b512b4e3c8bf99d26fba80b81
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 "language.h"
11 #include "vframe.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>
23 int BC_Resources::error = 0;
25 VFrame* BC_Resources::bg_image = 0;
26 VFrame* BC_Resources::menu_bg = 0;
28 #include "images/file_film_png.h"
29 #include "images/file_folder_png.h"
30 #include "images/file_sound_png.h"
31 #include "images/file_unknown_png.h"
32 #include "images/file_column_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),
39         new VFrame(file_column_png)
42 char* BC_Resources::small_font = N_("-*-helvetica-medium-r-normal-*-10-*");
43 char* BC_Resources::small_font2 = N_("-*-helvetica-medium-r-normal-*-11-*");
44 char* BC_Resources::medium_font = N_("-*-helvetica-bold-r-normal-*-14-*");
45 char* BC_Resources::medium_font2 = N_("-*-helvetica-bold-r-normal-*-14-*");
46 char* BC_Resources::large_font = N_("-*-helvetica-bold-r-normal-*-18-*");
47 char* BC_Resources::large_font2 = N_("-*-helvetica-bold-r-normal-*-20-*");
49 char* BC_Resources::small_fontset = "6x12,*";
50 char* BC_Resources::medium_fontset = "7x14,*";
51 char* BC_Resources::large_fontset = "8x16,*";
53 char* BC_Resources::small_font_xft = N_("-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*");
54 char* BC_Resources::medium_font_xft = N_("-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*");
55 char* BC_Resources::large_font_xft = N_("-microsoft-verdana-*-*-*-*-*-*-*-*-*-*-*-*");
57 suffix_to_type_t BC_Resources::suffix_to_type[] = 
59         { "m2v", ICON_FILM },
60         { "mov", ICON_FILM },
61         { "mp2", ICON_SOUND },
62         { "mp3", ICON_SOUND },
63         { "mpg", ICON_FILM },
64         { "vob", ICON_FILM },
65         { "wav", ICON_SOUND }
68 BC_Signals* BC_Resources::signal_handler = 0;
70 int BC_Resources::x_error_handler(Display *display, XErrorEvent *event)
72         char string[1024];
73         XGetErrorText(event->display, event->error_code, string, 1024);
74 //      printf("BC_Resources::x_error_handler: %s\n", string);
75         BC_Resources::error = 1;
76         return 0;
81 BC_Resources::BC_Resources()
83         display_info = new BC_DisplayInfo("", 0);
85 #ifdef HAVE_XFT
86         XftInitFtLibrary();
87 #endif
89         use_xvideo = 1;
90 #include "images/cancel_up_png.h"
91 #include "images/cancel_hi_png.h"
92 #include "images/cancel_dn_png.h"
93         static VFrame* default_cancel_images[] = 
94         {
95                 new VFrame(cancel_up_png),
96                 new VFrame(cancel_hi_png),
97                 new VFrame(cancel_dn_png)
98         };
100 #include "images/ok_up_png.h"
101 #include "images/ok_hi_png.h"
102 #include "images/ok_dn_png.h"
103         static VFrame* default_ok_images[] = 
104         {
105                 new VFrame(ok_up_png),
106                 new VFrame(ok_hi_png),
107                 new VFrame(ok_dn_png)
108         };
110 #include "images/usethis_up_png.h"
111 #include "images/usethis_uphi_png.h"
112 #include "images/usethis_dn_png.h"
113         static VFrame* default_usethis_images[] = 
114         {
115                 new VFrame(usethis_up_png),
116                 new VFrame(usethis_uphi_png),
117                 new VFrame(usethis_dn_png)
118         };
120 #include "images/checkbox_checked_png.h"
121 #include "images/checkbox_down_png.h"
122 #include "images/checkbox_checkedhi_png.h"
123 #include "images/checkbox_up_png.h"
124 #include "images/checkbox_uphi_png.h"
125         static VFrame* default_checkbox_images[] =  
126         {
127                 new VFrame(checkbox_up_png),
128                 new VFrame(checkbox_uphi_png),
129                 new VFrame(checkbox_checked_png),
130                 new VFrame(checkbox_down_png),
131                 new VFrame(checkbox_checkedhi_png)
132         };
134 #include "images/radial_checked_png.h"
135 #include "images/radial_down_png.h"
136 #include "images/radial_checkedhi_png.h"
137 #include "images/radial_up_png.h"
138 #include "images/radial_uphi_png.h"
139         static VFrame* default_radial_images[] =  
140         {
141                 new VFrame(radial_up_png),
142                 new VFrame(radial_uphi_png),
143                 new VFrame(radial_checked_png),
144                 new VFrame(radial_down_png),
145                 new VFrame(radial_checkedhi_png)
146         };
148         static VFrame* default_label_images[] =  
149         {
150                 new VFrame(radial_up_png),
151                 new VFrame(radial_uphi_png),
152                 new VFrame(radial_checked_png),
153                 new VFrame(radial_down_png),
154                 new VFrame(radial_checkedhi_png)
155         };
158 #include "images/file_text_up_png.h"
159 #include "images/file_text_uphi_png.h"
160 #include "images/file_text_dn_png.h"
161 #include "images/file_icons_up_png.h"
162 #include "images/file_icons_uphi_png.h"
163 #include "images/file_icons_dn_png.h"
164 #include "images/file_newfolder_up_png.h"
165 #include "images/file_newfolder_uphi_png.h"
166 #include "images/file_newfolder_dn_png.h"
167 #include "images/file_updir_up_png.h"
168 #include "images/file_updir_uphi_png.h"
169 #include "images/file_updir_dn_png.h"
170         static VFrame* default_filebox_text_images[] = 
171         {
172                 new VFrame(file_text_up_png),
173                 new VFrame(file_text_uphi_png),
174                 new VFrame(file_text_dn_png)
175         };
177         static VFrame* default_filebox_icons_images[] = 
178         {
179                 new VFrame(file_icons_up_png),
180                 new VFrame(file_icons_uphi_png),
181                 new VFrame(file_icons_dn_png)
182         };
184         static VFrame* default_filebox_updir_images[] =  
185         {
186                 new VFrame(file_updir_up_png),
187                 new VFrame(file_updir_uphi_png),
188                 new VFrame(file_updir_dn_png)
189         };
191         static VFrame* default_filebox_newfolder_images[] = 
192         {
193                 new VFrame(file_newfolder_up_png),
194                 new VFrame(file_newfolder_uphi_png),
195                 new VFrame(file_newfolder_dn_png)
196         };
198 #include "images/listbox_button_dn_png.h"
199 #include "images/listbox_button_hi_png.h"
200 #include "images/listbox_button_up_png.h"
201         static VFrame* default_listbox_button[] = 
202         {
203                 new VFrame(listbox_button_up_png),
204                 new VFrame(listbox_button_hi_png),
205                 new VFrame(listbox_button_dn_png)
206         };
207         listbox_button = default_listbox_button;
209 #include "images/list_bg_png.h"
210         static VFrame* default_listbox_bg = new VFrame(list_bg_png);
211         listbox_bg = default_listbox_bg;
213 #include "images/listbox_expandchecked_png.h"
214 #include "images/listbox_expandcheckedhi_png.h"
215 #include "images/listbox_expanddn_png.h"
216 #include "images/listbox_expandup_png.h"
217 #include "images/listbox_expanduphi_png.h"
218         static VFrame* default_listbox_expand[] = 
219         {
220                 new VFrame(listbox_expandup_png),
221                 new VFrame(listbox_expanduphi_png),
222                 new VFrame(listbox_expandchecked_png),
223                 new VFrame(listbox_expanddn_png),
224                 new VFrame(listbox_expandcheckedhi_png),
225         };
226         listbox_expand = default_listbox_expand;
228 #include "images/listbox_columnup_png.h"
229 #include "images/listbox_columnhi_png.h"
230 #include "images/listbox_columndn_png.h"
231         static VFrame* default_listbox_column[] = 
232         {
233                 new VFrame(listbox_columnup_png),
234                 new VFrame(listbox_columnhi_png),
235                 new VFrame(listbox_columndn_png)
236         };
237         listbox_column = default_listbox_column;
240 #include "images/listbox_up_png.h"
241 #include "images/listbox_dn_png.h"
242         listbox_up = new VFrame(listbox_up_png);
243         listbox_dn = new VFrame(listbox_dn_png);
253 #include "images/horizontal_slider_bg_up_png.h"
254 #include "images/horizontal_slider_bg_hi_png.h"
255 #include "images/horizontal_slider_bg_dn_png.h"
256 #include "images/horizontal_slider_fg_up_png.h"
257 #include "images/horizontal_slider_fg_hi_png.h"
258 #include "images/horizontal_slider_fg_dn_png.h"
259         static VFrame *default_horizontal_slider_data[] = 
260         {
261                 new VFrame(horizontal_slider_fg_up_png),
262                 new VFrame(horizontal_slider_fg_hi_png),
263                 new VFrame(horizontal_slider_fg_dn_png),
264                 new VFrame(horizontal_slider_bg_up_png),
265                 new VFrame(horizontal_slider_bg_hi_png),
266                 new VFrame(horizontal_slider_bg_dn_png),
267         };
269 #include "images/vertical_slider_bg_up_png.h"
270 #include "images/vertical_slider_bg_hi_png.h"
271 #include "images/vertical_slider_bg_dn_png.h"
272 #include "images/vertical_slider_fg_up_png.h"
273 #include "images/vertical_slider_fg_hi_png.h"
274 #include "images/vertical_slider_fg_dn_png.h"
275         static VFrame *default_vertical_slider_data[] = 
276         {
277                 new VFrame(vertical_slider_fg_up_png),
278                 new VFrame(vertical_slider_fg_hi_png),
279                 new VFrame(vertical_slider_fg_dn_png),
280                 new VFrame(vertical_slider_bg_up_png),
281                 new VFrame(vertical_slider_bg_hi_png),
282                 new VFrame(vertical_slider_bg_dn_png),
283         };
284         horizontal_slider_data = default_horizontal_slider_data;
285         vertical_slider_data = default_vertical_slider_data;
287 #include "images/pot_hi_png.h"
288 #include "images/pot_up_png.h"
289 #include "images/pot_dn_png.h"
290         static VFrame *default_pot_images[] = 
291         {
292                 new VFrame(pot_up_png),
293                 new VFrame(pot_hi_png),
294                 new VFrame(pot_dn_png)
295         };
297 #include "images/progress_up_png.h"
298 #include "images/progress_hi_png.h"
299         static VFrame* default_progress_images[] = 
300         {
301                 new VFrame(progress_up_png),
302                 new VFrame(progress_hi_png)
303         };
306 #include "images/pan_up_png.h"
307 #include "images/pan_hi_png.h"
308 #include "images/pan_popup_png.h"
309 #include "images/pan_channel_png.h"
310 #include "images/pan_stick_png.h"
311 #include "images/pan_channel_small_png.h"
312 #include "images/pan_stick_small_png.h"
313         static VFrame* default_pan_data[] = 
314         {
315                 new VFrame(pan_up_png),
316                 new VFrame(pan_hi_png),
317                 new VFrame(pan_popup_png),
318                 new VFrame(pan_channel_png),
319                 new VFrame(pan_stick_png),
320                 new VFrame(pan_channel_small_png),
321                 new VFrame(pan_stick_small_png)
322         };
323         pan_data = default_pan_data;
324         pan_text_color = YELLOW;
326 #include "images/7seg_small/0_png.h"
327 #include "images/7seg_small/1_png.h"
328 #include "images/7seg_small/2_png.h"
329 #include "images/7seg_small/3_png.h"
330 #include "images/7seg_small/4_png.h"
331 #include "images/7seg_small/5_png.h"
332 #include "images/7seg_small/6_png.h"
333 #include "images/7seg_small/7_png.h"
334 #include "images/7seg_small/8_png.h"
335 #include "images/7seg_small/9_png.h"
336 #include "images/7seg_small/colon_png.h"
337 #include "images/7seg_small/period_png.h"
338 #include "images/7seg_small/a_png.h"
339 #include "images/7seg_small/b_png.h"
340 #include "images/7seg_small/c_png.h"
341 #include "images/7seg_small/d_png.h"
342 #include "images/7seg_small/e_png.h"
343 #include "images/7seg_small/f_png.h"
344 #include "images/7seg_small/space_png.h"
345 #include "images/7seg_small/dash_png.h"
346         static VFrame* default_medium_7segment[] = 
347         {
348                 new VFrame(_0_png),
349                 new VFrame(_1_png),
350                 new VFrame(_2_png),
351                 new VFrame(_3_png),
352                 new VFrame(_4_png),
353                 new VFrame(_5_png),
354                 new VFrame(_6_png),
355                 new VFrame(_7_png),
356                 new VFrame(_8_png),
357                 new VFrame(_9_png),
358                 new VFrame(colon_png),
359                 new VFrame(period_png),
360                 new VFrame(a_png),
361                 new VFrame(b_png),
362                 new VFrame(c_png),
363                 new VFrame(d_png),
364                 new VFrame(e_png),
365                 new VFrame(f_png),
366                 new VFrame(space_png),
367                 new VFrame(dash_png)
368         };
370 #include "images/tumble_bottomdn_png.h"
371 #include "images/tumble_topdn_png.h"
372 #include "images/tumble_hi_png.h"
373 #include "images/tumble_up_png.h"
374         static VFrame* default_tumbler_data[] = 
375         {
376                 new VFrame(tumble_up_png),
377                 new VFrame(tumble_hi_png),
378                 new VFrame(tumble_bottomdn_png),
379                 new VFrame(tumble_topdn_png)
380         };
382 #include "images/xmeter_normal_png.h"
383 #include "images/xmeter_green_png.h"
384 #include "images/xmeter_red_png.h"
385 #include "images/xmeter_yellow_png.h"
386 #include "images/xmeter_white_png.h"
387 #include "images/over_horiz_png.h"
388 #include "images/ymeter_normal_png.h"
389 #include "images/ymeter_green_png.h"
390 #include "images/ymeter_red_png.h"
391 #include "images/ymeter_yellow_png.h"
392 #include "images/ymeter_white_png.h"
393 #include "images/over_vertical_png.h"
394         static VFrame* default_xmeter_data[] =
395         {
396                 new VFrame(xmeter_normal_png),
397                 new VFrame(xmeter_green_png),
398                 new VFrame(xmeter_red_png),
399                 new VFrame(xmeter_yellow_png),
400                 new VFrame(xmeter_white_png),
401                 new VFrame(over_horiz_png)
402         };
404         static VFrame* default_ymeter_data[] =
405         {
406                 new VFrame(ymeter_normal_png),
407                 new VFrame(ymeter_green_png),
408                 new VFrame(ymeter_red_png),
409                 new VFrame(ymeter_yellow_png),
410                 new VFrame(ymeter_white_png),
411                 new VFrame(over_vertical_png)
412         };
414 #include "images/generic_up_png.h"
415 #include "images/generic_hi_png.h"
416 #include "images/generic_dn_png.h"
417         
418         static VFrame* default_generic_button_data[] = 
419         {
420                 new VFrame(generic_up_png),
421                 new VFrame(generic_hi_png),
422                 new VFrame(generic_dn_png)
423         };
424         
425         generic_button_images = default_generic_button_data;
430 #include "images/hscroll_handle_up_png.h"
431 #include "images/hscroll_handle_hi_png.h"
432 #include "images/hscroll_handle_dn_png.h"
433 #include "images/hscroll_handle_bg_png.h"
434 #include "images/hscroll_left_up_png.h"
435 #include "images/hscroll_left_hi_png.h"
436 #include "images/hscroll_left_dn_png.h"
437 #include "images/hscroll_right_up_png.h"
438 #include "images/hscroll_right_hi_png.h"
439 #include "images/hscroll_right_dn_png.h"
440 #include "images/vscroll_handle_up_png.h"
441 #include "images/vscroll_handle_hi_png.h"
442 #include "images/vscroll_handle_dn_png.h"
443 #include "images/vscroll_handle_bg_png.h"
444 #include "images/vscroll_left_up_png.h"
445 #include "images/vscroll_left_hi_png.h"
446 #include "images/vscroll_left_dn_png.h"
447 #include "images/vscroll_right_up_png.h"
448 #include "images/vscroll_right_hi_png.h"
449 #include "images/vscroll_right_dn_png.h"
450         static VFrame *default_hscroll_data[] = 
451         {
452                 new VFrame(hscroll_handle_up_png), 
453                 new VFrame(hscroll_handle_hi_png), 
454                 new VFrame(hscroll_handle_dn_png), 
455                 new VFrame(hscroll_handle_bg_png), 
456                 new VFrame(hscroll_left_up_png), 
457                 new VFrame(hscroll_left_hi_png), 
458                 new VFrame(hscroll_left_dn_png), 
459                 new VFrame(hscroll_right_up_png), 
460                 new VFrame(hscroll_right_hi_png), 
461                 new VFrame(hscroll_right_dn_png)
462         };
463         static VFrame *default_vscroll_data[] = 
464         {
465                 new VFrame(vscroll_handle_up_png), 
466                 new VFrame(vscroll_handle_hi_png), 
467                 new VFrame(vscroll_handle_dn_png), 
468                 new VFrame(vscroll_handle_bg_png), 
469                 new VFrame(vscroll_left_up_png), 
470                 new VFrame(vscroll_left_hi_png), 
471                 new VFrame(vscroll_left_dn_png), 
472                 new VFrame(vscroll_right_up_png), 
473                 new VFrame(vscroll_right_hi_png), 
474                 new VFrame(vscroll_right_dn_png)
475         };
476         hscroll_data = default_hscroll_data;
477         vscroll_data = default_vscroll_data;
478         scroll_minhandle = 10;
482         use_shm = -1;
484 // Initialize
485         bg_color = MEGREY;
486         bg_shadow1 = DKGREY;
487         bg_shadow2 = BLACK;
488         bg_light1 = WHITE;
489         bg_light2 = bg_color;
491         default_text_color = BLACK;
492         disabled_text_color = MEGREY;
494         button_light = WHITE;           // bright corner
495         button_highlighted = LTGREY;  // face when highlighted
496         button_down = MDGREY;         // face when down
497         button_up = MEGREY;           // face when up
498         button_shadow = DKGREY;       // dark corner
500         tumble_data = default_tumbler_data;
501         tumble_duration = 150;
503         ok_images = default_ok_images;
504         cancel_images = default_cancel_images;
505         usethis_button_images = default_usethis_images;
507         checkbox_images = default_checkbox_images;
508         radial_images = default_radial_images;
509         label_images = default_label_images;
511         menu_light = LTCYAN;
512         menu_highlighted = LTBLUE;
513         menu_down = MDCYAN;
514         menu_up = MECYAN;
515         menu_shadow = DKCYAN;
517         popup_title_text = BLACK;
518         menu_item_text = BLACK;
519         progress_text = BLACK;
521         text_default = BLACK;
522         text_background = WHITE;
523         highlight_inverse = WHITE ^ BLUE;
524         text_highlight = BLUE;
526 // Delays must all be different for repeaters
527         double_click = 300;
528         blink_rate = 250;
529         scroll_repeat = 150;
530         tooltip_delay = 1000;
531         tooltip_bg_color = YELLOW;
532         tooltips_enabled = 1;
534         filebox_mode = LISTBOX_TEXT;
535         sprintf(filebox_filter, "*");
536         filebox_w = 640;
537         filebox_h = 480;
538         filebox_columntype[0] = FILEBOX_NAME;
539         filebox_columntype[1] = FILEBOX_SIZE;
540         filebox_columntype[2] = FILEBOX_DATE;
541         filebox_columnwidth[0] = 200;
542         filebox_columnwidth[1] = 100;
543         filebox_columnwidth[2] = 100;
545         filebox_text_images = default_filebox_text_images;
546         filebox_icons_images = default_filebox_icons_images;
547         filebox_updir_images = default_filebox_updir_images;
548         filebox_newfolder_images = default_filebox_newfolder_images;
550         filebox_sortcolumn = 0;
551         filebox_sortorder = BC_ListBox::SORT_ASCENDING;
554         pot_images = default_pot_images;
555         pot_x1 = pot_images[0]->get_w() / 2 - 2;
556         pot_y1 = pot_images[0]->get_h() / 2 - 2;;
557         pot_r = pot_x1;
558         pot_needle_color = BLACK;
560         progress_images = default_progress_images;
562         xmeter_images = default_xmeter_data;
563         ymeter_images = default_ymeter_data;
564         meter_font = SMALLFONT_3D;
565         meter_font_color = RED;
566         meter_title_w = 20;
567         meter_3d = 1;
568         medium_7segment = default_medium_7segment;
571         use_fontset = 0;
573 // Xft has priority over font set
574 #ifdef HAVE_XFT
575         use_xft = 1;
576 #else
577         use_xft = 0;
578 #endif
581         drag_radius = 10;
582         recursive_resizing = 1;
584         
587 BC_Resources::~BC_Resources()
591 int BC_Resources::initialize_display(BC_WindowBase *window)
593 // Set up IPC cleanup handlers
594         bc_init_ipc();
596 // Test for shm.  Must come before yuv test
597         init_shm(window);
598         return 0;
602 int BC_Resources::init_shm(BC_WindowBase *window)
604         use_shm = 1;
605         XSetErrorHandler(BC_Resources::x_error_handler);
607         if(!XShmQueryExtension(window->display)) use_shm = 0;
608         else
609         {
610                 XShmSegmentInfo test_shm;
611                 XImage *test_image;
612                 unsigned char *data;
613                 test_image = XShmCreateImage(window->display, window->vis, window->default_depth,
614                 ZPixmap, (char*)NULL, &test_shm, 5, 5);
616                 test_shm.shmid = shmget(IPC_PRIVATE, 5 * test_image->bytes_per_line, (IPC_CREAT | 0777 ));
617                 data = (unsigned char *)shmat(test_shm.shmid, NULL, 0);
618         shmctl(test_shm.shmid, IPC_RMID, 0);
619                 BC_Resources::error = 0;
620                 XShmAttach(window->display, &test_shm);
621         XSync(window->display, False);
622                 if(BC_Resources::error) use_shm = 0;
623                 XDestroyImage(test_image);
624                 shmdt(test_shm.shmaddr);
625         }
626 //      XSetErrorHandler(0);
627         return 0;
630 int BC_Resources::get_top_border()
632         return display_info->get_top_border();
635 int BC_Resources::get_left_border()
637         return display_info->get_left_border();
640 int BC_Resources::get_right_border()
642         return display_info->get_right_border();
645 int BC_Resources::get_bottom_border()
647         return display_info->get_bottom_border();
651 int BC_Resources::get_bg_color() { return bg_color; }
653 int BC_Resources::get_bg_shadow1() { return bg_shadow1; }
655 int BC_Resources::get_bg_shadow2() { return bg_shadow2; }
657 int BC_Resources::get_bg_light1() { return bg_light1; }
659 int BC_Resources::get_bg_light2() { return bg_light2; }