Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / cinelerra / theme.C
blob5cb02b0fa6d7b7a3be0338345c40a5fa02fa4fdc
1 #include "awindowgui.h"
2 #include "clip.h"
3 #include "colors.h"
4 #include "cwindowgui.h"
5 #include "edl.h"
6 #include "edlsession.h"
7 #include "language.h"
8 #include "levelwindowgui.h"
9 #include "loadmode.h"
10 #include "localsession.h"
11 #include "mainmenu.h"
12 #include "mainsession.h"
13 #include "mbuttons.h"
14 #include "meterpanel.h"
15 #include "mwindowgui.h"
16 #include "mwindow.h"
17 #include "overlayframe.h"
18 #include "patchbay.h"
19 #include "playtransport.h"
20 #include "recordgui.h"
21 #include "recordmonitor.h"
22 #include "resourcepixmap.h"
23 #include "statusbar.h"
24 #include "theme.h"
25 #include "timebar.h"
26 #include "trackcanvas.h"
27 #include "vframe.h"
28 #include "vwindowgui.h"
29 #include "zoombar.h"
32 #include <errno.h>
33 #include <string.h>
39 Theme::Theme()
40  : BC_Theme()
42         this->mwindow = 0;
43         theme_title = DEFAULT_THEME;
44         data_buffer = 0;
45         contents_buffer = 0;
46         last_image = 0;
47         mtransport_margin = 0;
48         toggle_margin = 0;
50         BC_WindowBase::get_resources()->bg_color = BLOND;
51         BC_WindowBase::get_resources()->button_up = 0xffc000;
52         BC_WindowBase::get_resources()->button_highlighted = 0xffe000;
53         BC_WindowBase::get_resources()->recursive_resizing = 0;
54         audio_color = BLACK;
55         fade_h = 22;
56         meter_h = 17;
57         mode_h = 30;
58         pan_h = 32;
59         pan_x = 50;
60         play_h = 22;
61         title_h = 23;
63         preferences_category_overlap = 0;
65         loadmode_w = 350;
67 #include "data/about_png.h"
68         about_bg = new VFrame(about_png);
72         
78 // Need to delete everything here
79 Theme::~Theme()
81         flush_images(); 
83         aspect_ratios.remove_all_objects();
84         frame_rates.remove_all_objects();
85         frame_sizes.remove_all_objects();
86         sample_rates.remove_all_objects();
87         zoom_values.remove_all_objects();
90 void Theme::flush_images()
92         if(data_buffer) delete [] data_buffer;
93         if(contents_buffer) delete [] contents_buffer;
94         data_buffer = 0;
95         contents_buffer = 0;
96         contents.remove_all();
99 void Theme::initialize()
101         message_normal = BLACK;
102         message_error = RED;
104 // Force to use local data for images
105         extern unsigned char _binary_theme_data_start[];
106         set_data(_binary_theme_data_start);
108 // Set images which weren't set by subclass
109         new_image("mode_add", "mode_add.png");
110         new_image("mode_divide", "mode_divide.png");
111         new_image("mode_multiply", "mode_multiply.png");
112         new_image("mode_normal", "mode_normal.png");
113         new_image("mode_replace", "mode_replace.png");
114         new_image("mode_subtract", "mode_subtract.png");
120 void Theme::build_menus()
124         aspect_ratios.append(new BC_ListBoxItem("3:2"));
125         aspect_ratios.append(new BC_ListBoxItem("4:3"));
126         aspect_ratios.append(new BC_ListBoxItem("16:9"));
127         aspect_ratios.append(new BC_ListBoxItem("2.10:1"));
128         aspect_ratios.append(new BC_ListBoxItem("2.20:1"));
129         aspect_ratios.append(new BC_ListBoxItem("2.25:1"));
130         aspect_ratios.append(new BC_ListBoxItem("2.30:1"));
131         aspect_ratios.append(new BC_ListBoxItem("2.35:1"));
132         aspect_ratios.append(new BC_ListBoxItem("2.66:1"));
133         frame_sizes.append(new BC_ListBoxItem("160x120"));
134         frame_sizes.append(new BC_ListBoxItem("240x180"));
135         frame_sizes.append(new BC_ListBoxItem("320x240"));
136         frame_sizes.append(new BC_ListBoxItem("360x240"));
137         frame_sizes.append(new BC_ListBoxItem("400x300"));
138         frame_sizes.append(new BC_ListBoxItem("512x384"));
139         frame_sizes.append(new BC_ListBoxItem("640x480"));
140         frame_sizes.append(new BC_ListBoxItem("720x480"));
141         frame_sizes.append(new BC_ListBoxItem("720x576"));
142         frame_sizes.append(new BC_ListBoxItem("1280x720"));
143         frame_sizes.append(new BC_ListBoxItem("960x1080"));
144         frame_sizes.append(new BC_ListBoxItem("1920x1080"));
145         frame_sizes.append(new BC_ListBoxItem("1920x1088"));
146         sample_rates.append(new BC_ListBoxItem("8000"));
147         sample_rates.append(new BC_ListBoxItem("16000"));
148         sample_rates.append(new BC_ListBoxItem("22050"));
149         sample_rates.append(new BC_ListBoxItem("32000"));
150         sample_rates.append(new BC_ListBoxItem("44100"));
151         sample_rates.append(new BC_ListBoxItem("48000"));
152         sample_rates.append(new BC_ListBoxItem("96000"));
153         sample_rates.append(new BC_ListBoxItem("192000"));
154         frame_rates.append(new BC_ListBoxItem("1"));
155         frame_rates.append(new BC_ListBoxItem("5"));
156         frame_rates.append(new BC_ListBoxItem("10"));
157         frame_rates.append(new BC_ListBoxItem("12"));
158         frame_rates.append(new BC_ListBoxItem("15"));
159         frame_rates.append(new BC_ListBoxItem("23.97"));
160         frame_rates.append(new BC_ListBoxItem("24"));
161         frame_rates.append(new BC_ListBoxItem("25"));
162         frame_rates.append(new BC_ListBoxItem("29.97"));
163         frame_rates.append(new BC_ListBoxItem("30"));
164         frame_rates.append(new BC_ListBoxItem("50"));
165         frame_rates.append(new BC_ListBoxItem("59.94"));
166         frame_rates.append(new BC_ListBoxItem("60"));
167         char string[BCTEXTLEN];
168         for(int i = 1; i < 17; i++)
169         {
170                 sprintf(string, "%d", (int)pow(2, i));
171                 zoom_values.append(new BC_ListBoxItem(string));
172         }
176 void Theme::overlay(VFrame *dst, VFrame *src, int in_x1, int in_x2)
178         int w;
179         int h;
180         unsigned char **in_rows;
181         unsigned char **out_rows;
183         if(in_x1 < 0)
184         {
185                 w = MIN(src->get_w(), dst->get_w());
186                 h = MIN(dst->get_h(), src->get_h());
187                 in_x1 = 0;
188                 in_x2 = w;
189         }
190         else
191         {
192                 w = in_x2 - in_x1;
193                 h = MIN(dst->get_h(), src->get_h());
194         }
195         in_rows = src->get_rows();
196         out_rows = dst->get_rows();
198         switch(src->get_color_model())
199         {
200                 case BC_RGBA8888:
201                         switch(dst->get_color_model())
202                         {
203                                 case BC_RGBA8888:
204                                         for(int i = 0; i < h; i++)
205                                         {
206                                                 unsigned char *in_row = in_rows[i] + in_x1 * 4;
207                                                 unsigned char *out_row = out_rows[i];
208                                                 for(int j = 0; j < w; j++)
209                                                 {
210                                                         int opacity = in_row[3];
211                                                         int transparency = 0xff - opacity;
212                                                         out_row[0] = (in_row[0] * opacity + out_row[0] * transparency) / 0xff;
213                                                         out_row[1] = (in_row[1] * opacity + out_row[1] * transparency) / 0xff;
214                                                         out_row[2] = (in_row[2] * opacity + out_row[2] * transparency) / 0xff;
215                                                         out_row[3] = MAX(in_row[3], out_row[3]);
216                                                         out_row += 4;
217                                                         in_row += 4;
218                                                 }
219                                         }
220                                         break;
221                                 case BC_RGB888:
222                                         for(int i = 0; i < h; i++)
223                                         {
224                                                 unsigned char *in_row = in_rows[i] + in_x1 * 4;
225                                                 unsigned char *out_row = out_rows[i];
226                                                 for(int j = 0; j < w; j++)
227                                                 {
228                                                         int opacity = in_row[3];
229                                                         int transparency = 0xff - opacity;
230                                                         out_row[0] = (in_row[0] * opacity + out_row[0] * transparency) / 0xff;
231                                                         out_row[1] = (in_row[1] * opacity + out_row[1] * transparency) / 0xff;
232                                                         out_row[2] = (in_row[2] * opacity + out_row[2] * transparency) / 0xff;
233                                                         out_row += 3;
234                                                         in_row += 4;
235                                                 }
236                                         }
237                                         break;
238                         }
239                         break;
240         }
243 void Theme::build_transport(char *title,
244         unsigned char *png_overlay,
245         VFrame **bg_data,
246         int third)
248         if(!png_overlay) return;
249         VFrame default_data(png_overlay);
250         VFrame *data[3];
251         data[0] = new VFrame(0, default_data.get_w(), default_data.get_h(), BC_RGBA8888);
252         data[1] = new VFrame(0, default_data.get_w(), default_data.get_h(), BC_RGBA8888);
253         data[2] = new VFrame(0, default_data.get_w(), default_data.get_h(), BC_RGBA8888);
254         data[0]->clear_frame();
255         data[1]->clear_frame();
256         data[2]->clear_frame();
258         for(int i = 0; i < 3; i++)
259         {
260                 int in_x1;
261                 int in_x2;
262                 if(!bg_data[i]) break;
264                 switch(third)
265                 {
266                         case 0:
267                                 in_x1 = 0;
268                                 in_x2 = default_data.get_w();
269                                 break;
271                         case 1:
272                                 in_x1 = (int)(bg_data[i]->get_w() * 0.33);
273                                 in_x2 = in_x1 + default_data.get_w();
274                                 break;
276                         case 2:
277                                 in_x1 = bg_data[i]->get_w() - default_data.get_w();
278                                 in_x2 = in_x1 + default_data.get_w();
279                                 break;
280                 }
282                 overlay(data[i], 
283                         bg_data[i],
284                         in_x1,
285                         in_x2);
286                 overlay(data[i], 
287                         &default_data);
288         }
290         new_image_set_images(title, 3, data[0], data[1], data[2]);
301 void Theme::build_patches(VFrame** &data,
302         unsigned char *png_overlay,
303         VFrame **bg_data,
304         int region)
306         if(!png_overlay || !bg_data) return;
307         VFrame default_data(png_overlay);
308         data = new VFrame*[5];
309         data[0] = new VFrame(0, default_data.get_w(), default_data.get_h(), BC_RGBA8888);
310         data[1] = new VFrame(0, default_data.get_w(), default_data.get_h(), BC_RGBA8888);
311         data[2] = new VFrame(0, default_data.get_w(), default_data.get_h(), BC_RGBA8888);
312         data[3] = new VFrame(0, default_data.get_w(), default_data.get_h(), BC_RGBA8888);
313         data[4] = new VFrame(0, default_data.get_w(), default_data.get_h(), BC_RGBA8888);
315         for(int i = 0; i < 5; i++)
316         {
317                 int in_x1;
318                 int in_x2;
320                 switch(region)
321                 {
322                         case 0:
323                                 in_x1 = 0;
324                                 in_x2 = default_data.get_w();
325                                 break;
327                         case 1:
328                                 in_x1 = (int)(bg_data[i]->get_w() * 0.33);
329                                 in_x2 = in_x1 + default_data.get_w();
330                                 break;
332                         case 2:
333                                 in_x1 = bg_data[i]->get_w() - default_data.get_w();
334                                 in_x2 = in_x1 + default_data.get_w();
335                                 break;
336                 }
338                 overlay(data[i], 
339                         bg_data[i]);
340                 overlay(data[i], 
341                         &default_data);
342         }
352 void Theme::build_button(VFrame** &data,
353         unsigned char *png_overlay,
354         VFrame *up_vframe,
355         VFrame *hi_vframe,
356         VFrame *dn_vframe)
358         if(!png_overlay) return;
359         VFrame default_data(png_overlay);
361         if(!up_vframe || !hi_vframe || !dn_vframe) return;
362         data = new VFrame*[3];
363         data[0] = new VFrame(0, default_data.get_w(), default_data.get_h(), BC_RGBA8888);
364         data[1] = new VFrame(0, default_data.get_w(), default_data.get_h(), BC_RGBA8888);
365         data[2] = new VFrame(0, default_data.get_w(), default_data.get_h(), BC_RGBA8888);
366         data[0]->copy_from(up_vframe);
367         data[1]->copy_from(hi_vframe);
368         data[2]->copy_from(dn_vframe);
369         for(int i = 0; i < 3; i++)
370                 overlay(data[i], 
371                         &default_data);
374 void Theme::build_toggle(VFrame** &data,
375         unsigned char *png_overlay,
376         VFrame *up_vframe,
377         VFrame *hi_vframe,
378         VFrame *checked_vframe,
379         VFrame *dn_vframe,
380         VFrame *checkedhi_vframe)
382         if(!png_overlay || 
383                 !up_vframe || 
384                 !hi_vframe || 
385                 !checked_vframe || 
386                 !dn_vframe || 
387                 !checkedhi_vframe) return;
388         VFrame default_data(png_overlay);
389         data = new VFrame*[5];
390         data[0] = new VFrame(0, default_data.get_w(), default_data.get_h(), BC_RGBA8888);
391         data[1] = new VFrame(0, default_data.get_w(), default_data.get_h(), BC_RGBA8888);
392         data[2] = new VFrame(0, default_data.get_w(), default_data.get_h(), BC_RGBA8888);
393         data[3] = new VFrame(0, default_data.get_w(), default_data.get_h(), BC_RGBA8888);
394         data[4] = new VFrame(0, default_data.get_w(), default_data.get_h(), BC_RGBA8888);
395         data[0]->copy_from(up_vframe);
396         data[1]->copy_from(hi_vframe);
397         data[2]->copy_from(checked_vframe);
398         data[3]->copy_from(dn_vframe);
399         data[4]->copy_from(checkedhi_vframe);
400         for(int i = 0; i < 5; i++)
401                 overlay(data[i], 
402                         &default_data);
405 #define TIMEBAR_HEIGHT 10
406 #define PATCHBAY_W 145
407 #define STATUS_H 20
408 #define ZOOM_H 30
410 void Theme::get_mwindow_sizes(MWindowGUI *gui, int w, int h)
414 void Theme::draw_mwindow_bg(MWindowGUI *gui)
421 void Theme::draw_awindow_bg(AWindowGUI *gui)
423         gui->clear_box(0, 0, mwindow->session->awindow_w, mwindow->session->awindow_h);
424         gui->flash();
427 void Theme::draw_vwindow_bg(VWindowGUI *gui)
429 //      gui->clear_box(0, 
430 //              0, 
431 //              mwindow->session->vwindow_w, 
432 //              mwindow->session->vwindow_h);
433 // // Timebar
434 //      gui->draw_3segmenth(vtimebar_x, 
435 //              vtimebar_y, 
436 //              vtimebar_w, 
437 //              vtimebar_bg_data,
438 //              0);
439 //      gui->flash();
443 void Theme::draw_cwindow_bg(CWindowGUI *gui)
445         gui->clear_box(0, 0, mwindow->session->cwindow_w, mwindow->session->cwindow_h);
446         gui->flash();
449 void Theme::draw_lwindow_bg(LevelWindowGUI *gui)
451         gui->clear_box(0, 0, mwindow->session->lwindow_w, mwindow->session->lwindow_h);
452         gui->flash();
456 void Theme::draw_rmonitor_bg(RecordMonitorGUI *gui)
458         gui->clear_box(0, 0, mwindow->session->rmonitor_w, mwindow->session->rmonitor_h);
459         gui->flash();
463 void Theme::draw_rwindow_bg(RecordGUI *gui)
465         gui->clear_box(0, 0, mwindow->session->rwindow_w, mwindow->session->rwindow_h);
469 void Theme::draw_resource_bg(TrackCanvas *canvas,
470         ResourcePixmap *pixmap, 
471         int edit_x,
472         int edit_w,
473         int pixmap_x,
474         int x1, 
475         int y1, 
476         int x2,
477         int y2)
479         VFrame *image;
481         switch(mwindow->edl->local_session->zoom_track)
482         {
483                 case 1024: image = get_image("resource1024");  break;
484                 case 512: image = get_image("resource512");  break;
485                 case 256: image = get_image("resource256");  break;
486                 case 128: image = get_image("resource128");  break;
487                 case 64:  image = get_image("resource64");   break;
488                 default:
489                 case 32:  image = get_image("resource32");   break;
490         }
492         canvas->draw_3segmenth(x1, 
493                 y1, 
494                 x2 - x1, 
495                 edit_x - pixmap_x,
496                 edit_w,
497                 image,
498                 pixmap);
501 void Theme::get_vwindow_sizes(VWindowGUI *gui)
505 void Theme::get_cwindow_sizes(CWindowGUI *gui, int cwindow_controls)
509 void Theme::get_awindow_sizes(AWindowGUI *gui)
511         abuttons_x = 0; 
512         abuttons_y = 0;
513         afolders_x = 0;
514 //      afolders_y = deletedisk_data[0]->get_h();
515         afolders_y = 0;
516         afolders_w = mwindow->session->afolders_w;
517         afolders_h = mwindow->session->awindow_h - afolders_y;
518         adivider_x = afolders_x + afolders_w;
519         adivider_y = 0;
520         adivider_w = 5;
521         adivider_h = afolders_h;
522         alist_x = afolders_x + afolders_w + 5;
523         alist_y = afolders_y;
524         alist_w = mwindow->session->awindow_w - alist_x;
525         alist_h = afolders_h;
528 void Theme::get_rmonitor_sizes(int do_audio, 
529         int do_video,
530         int do_channel,
531         int do_interlace,
532         int do_avc,
533         int audio_channels)
535         int x = 10;
536         int y = 3;
539         if(do_avc)
540         {
541                 rmonitor_canvas_y = 30;
542                 rmonitor_tx_x = 10;
543                 rmonitor_tx_y = 0;
544         }
545         else
546         {
547                 rmonitor_canvas_y = 0;
548                 rmonitor_tx_x = 0;
549                 rmonitor_tx_y = 0;
550         }
553         if(do_channel)
554         {
555                 y = 5;
556                 rmonitor_channel_x = x;
557                 rmonitor_channel_y = 5;
558                 x += 235;
559                 rmonitor_canvas_y = 35;
560         }
562         if(do_interlace)
563         {
564                 y = 4;
565                 rmonitor_interlace_x = x;
566                 rmonitor_interlace_y = y;
567         }
570         if(do_audio)
571         {
572                 rmonitor_meter_x = mwindow->session->rmonitor_w - MeterPanel::get_meters_width(audio_channels, 1);
573                 rmonitor_meter_y = 40;
574                 rmonitor_meter_h = mwindow->session->rmonitor_h - 10 - rmonitor_meter_y;
575         }
576         else
577         {
578                 rmonitor_meter_x = mwindow->session->rmonitor_w;
579         }
581         rmonitor_canvas_x = 0;
582         rmonitor_canvas_w = rmonitor_meter_x - rmonitor_canvas_x;
583         if(do_audio) rmonitor_canvas_w -= 10;
584         rmonitor_canvas_h = mwindow->session->rmonitor_h - rmonitor_canvas_y;
587 void Theme::get_recordgui_sizes(RecordGUI *gui, int w, int h)
591 void Theme::get_batchrender_sizes(BatchRenderGUI *gui,
592         int w, 
593         int h)
595         batchrender_x1 = 5;
596         batchrender_x2 = 300;
597         batchrender_x3 = 400;
600 void Theme::get_plugindialog_sizes()
602         int x = 10, y = 30;
603         plugindialog_new_x = x;
604         plugindialog_new_y = y;
605         plugindialog_shared_x = mwindow->session->plugindialog_w / 3;
606         plugindialog_shared_y = y;
607         plugindialog_module_x = mwindow->session->plugindialog_w * 2 / 3;
608         plugindialog_module_y = y;
610         plugindialog_new_w = plugindialog_shared_x - plugindialog_new_x - 10;
611         plugindialog_new_h = mwindow->session->plugindialog_h - 100;
612         plugindialog_shared_w = plugindialog_module_x - plugindialog_shared_x - 10;
613         plugindialog_shared_h = mwindow->session->plugindialog_h - 100;
614         plugindialog_module_w = mwindow->session->plugindialog_w - plugindialog_module_x - 10;
615         plugindialog_module_h = mwindow->session->plugindialog_h - 100;
617         plugindialog_newattach_x = plugindialog_new_x + 20;
618         plugindialog_newattach_y = plugindialog_new_y + plugindialog_new_h + 10;
619         plugindialog_sharedattach_x = plugindialog_shared_x + 20;
620         plugindialog_sharedattach_y = plugindialog_shared_y + plugindialog_shared_h + 10;
621         plugindialog_moduleattach_x = plugindialog_module_x + 20;
622         plugindialog_moduleattach_y = plugindialog_module_y + plugindialog_module_h + 10;
625 void Theme::get_menueffect_sizes(int use_list)
627         if(use_list)
628         {
629                 menueffect_list_x = 10;
630                 menueffect_list_y = 10;
631                 menueffect_list_w = mwindow->session->menueffect_w - 400;
632                 menueffect_list_h = mwindow->session->menueffect_h - 
633                         menueffect_list_y -
634                         BC_OKButton::calculate_h() - 10;
635         }
636         else
637         {
638                 menueffect_list_x = 0;
639                 menueffect_list_y = 10;
640                 menueffect_list_w = 0;
641                 menueffect_list_h = 0;
642         }
644         menueffect_file_x = menueffect_list_x + menueffect_list_w + 10;
645         menueffect_file_y = 10;
647         menueffect_tools_x = menueffect_file_x;
648         menueffect_tools_y = menueffect_file_y + 20;
651 void Theme::get_preferences_sizes()
655 void Theme::draw_preferences_bg(PreferencesWindow *gui)
659 void Theme::get_new_sizes(NewWindow *gui)
663 void Theme::draw_new_bg(NewWindow *gui)
667 void Theme::draw_new_bg2(NewWindow *gui,BC_WidgetGrid *grid_A,BC_WidgetGrid *grid_V)
671 void Theme::draw_setformat_bg(SetFormatWindow *window)
682 //      Local Variables:
683 //      mode: C++
684 //      c-file-style: "linux"
685 //      End: