mask xy scale, mask boundary only overlay, fix 8 char mask nm bug, rework maskgui...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / formatpresets.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "clip.h"
23 #include "edl.h"
24 #include "edlsession.h"
25 #include "formatpresets.h"
26 #include "mwindow.h"
27 #include "new.h"
28 #include "setformat.h"
29
30
31 FormatPresets::FormatPresets(MWindow *mwindow,
32         NewWindow *new_gui,
33         SetFormatWindow *format_gui,
34         int x,
35         int y)
36 {
37         this->mwindow = mwindow;
38         this->new_gui = new_gui;
39         this->format_gui = format_gui;
40         gui_base = new_gui ? (BC_WindowBase*)new_gui : (BC_WindowBase*)(format_gui);
41         this->x = x;
42         this->y = y;
43         text = 0;
44         pulldown = 0;
45 }
46
47 FormatPresets::~FormatPresets()
48 {
49         if(text) delete text;
50         if(pulldown) delete pulldown;
51         for(int i = 0; i < preset_items.total; i++)
52                 delete preset_items.values[i];
53 }
54
55 void FormatPresets::create_objects()
56 {
57         FormatPresetItem * item = new FormatPresetItem(mwindow, this, _("User Defined"));
58         preset_items.append(item);
59
60         int i;  const char *p;
61         for(i = 0; (p = mwindow->get_preset_name(i)) != 0; i++) {
62                 item = new FormatPresetItem(mwindow, this, p);
63                 mwindow->fill_preset_defaults(p, item->edl->session);
64                 preset_items.append(item);
65         }
66
67         gui_base->add_subwindow(new BC_Title(x, y, _("Presets:")));
68         int x1 = x;
69         y += 20;
70
71
72         gui_base->add_subwindow(text = new FormatPresetsText(mwindow,
73                 this,
74                 x,
75                 y));
76         x += text->get_w();
77         gui_base->add_subwindow(pulldown = new FormatPresetsPulldown(mwindow,
78                 this,
79                 x,
80                 y));
81         x = x1;
82 }
83
84 FormatPresetItem* FormatPresets::find_preset(EDL *edl)
85 {
86         for(int i = 1; i < preset_items.total; i++)
87         {
88                 FormatPresetItem *preset = preset_items.values[i];
89                 if(edl->session->audio_tracks == preset->edl->session->audio_tracks &&
90                         edl->session->audio_channels == preset->edl->session->audio_channels &&
91                         edl->session->sample_rate == preset->edl->session->sample_rate &&
92                         edl->session->video_tracks == preset->edl->session->video_tracks &&
93                         EQUIV(edl->session->frame_rate, preset->edl->session->frame_rate) &&
94                         edl->session->output_w == preset->edl->session->output_w &&
95                         edl->session->output_h == preset->edl->session->output_h &&
96                         EQUIV(edl->session->aspect_w, preset->edl->session->aspect_w) &&
97                         EQUIV(edl->session->aspect_h, preset->edl->session->aspect_h) &&
98                         edl->session->interlace_mode == preset->edl->session->interlace_mode &&
99                         edl->session->color_model == preset->edl->session->color_model)
100                 {
101                         return preset;
102                 }
103         }
104         return 0;
105 }
106
107 const char* FormatPresets::get_preset_text(EDL *edl)
108 {
109         FormatPresetItem *item = edl ? find_preset(edl) : 0;
110         return item ? item->get_text() : _("User Defined");
111 }
112
113
114 int FormatPresets::handle_event()
115 {
116         return 0;
117 }
118
119 EDL* FormatPresets::get_edl()
120 {
121         return 0;
122 }
123
124
125
126
127
128 FormatPresetsText::FormatPresetsText(MWindow *mwindow,
129         FormatPresets *gui,
130         int x,
131         int y)
132  : BC_TextBox(x,
133         y,
134         200,
135         1,
136         gui->get_preset_text(gui->get_edl()))
137 {
138         this->gui =  gui;
139         this->mwindow = mwindow;
140 }
141
142 int FormatPresetsText::handle_event()
143 {
144         return 1;
145 }
146
147
148
149
150
151
152
153
154
155
156 FormatPresetsPulldown::FormatPresetsPulldown(MWindow *mwindow,
157         FormatPresets *gui,
158         int x,
159         int y)
160  : BC_ListBox(x, y, 200, 250,
161                 LISTBOX_TEXT,                   // Display text list or icons
162                 (ArrayList<BC_ListBoxItem*>*)&gui->preset_items, // Each column has an ArrayList of BC_ListBoxItems.
163                 0,  // Titles for columns.  Set to 0 for no titles
164                 0,  // width of each column
165                 1,  // Total columns.
166                 0,  // Pixel of top of window.
167                 1)
168 {
169         this->mwindow = mwindow;
170         this->gui = gui;
171 }
172
173 int FormatPresetsPulldown::handle_event()
174 {
175         gui->handle_event();
176         FormatPresetItem *preset = ((FormatPresetItem*)get_selection(0, 0));
177         gui->get_edl()->copy_all(preset->edl);
178         gui->text->update(preset->get_text());
179         gui->handle_event();
180         return 1;
181 }
182
183 FormatPresetItem::FormatPresetItem(MWindow *mwindow,
184         FormatPresets *gui,
185         const char *text)
186  : BC_ListBoxItem(text)
187 {
188         this->mwindow = mwindow;
189         this->gui = gui;
190         edl = new EDL;
191         edl->create_objects();
192         edl->copy_all(gui->get_edl());
193 }
194
195 FormatPresetItem::~FormatPresetItem()
196 {
197         edl->Garbage::remove_user();
198 }
199
200