add BC_SCALE env var for hi def monitors, cleanup theme data
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / scaleratio / scaleratiowin.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 "bcdisplayinfo.h"
23 #include "clip.h"
24 #include "language.h"
25 #include "rescale.h"
26 #include "scaleratio.h"
27 #include "scaleratiowin.h"
28 #include "mwindow.h"
29
30
31 ScaleRatioWin::ScaleRatioWin(ScaleRatioMain *client)
32  : PluginClientWindow(client, xS(400), yS(320), xS(400), yS(320), 0)
33 {
34         this->client = client;
35 }
36
37 ScaleRatioWin::~ScaleRatioWin()
38 {
39 }
40
41 void ScaleRatioWin::create_objects()
42 {
43         int xs10 = xS(10), xs50 = xS(50);
44         int ys5 = yS(5), ys8 = yS(8), ys10 = yS(10), ys30 = yS(30);
45         int x = xs10, y = ys10;
46         int x0 = x, x1 = x0 + xs50;
47         int y0 = y;
48         client->load_configuration();
49
50         add_tool(new BC_Title(x0, y0, _("In R:")));
51         add_tool(in_r = new ScaleRatioRatio(this, client, x1, y0, &client->config.in_r));
52         in_r->create_objects();
53         y0 += in_r->get_th() + ys10;
54
55         add_tool(new BC_Title(x0, y0, _("In W:")));
56         in_w = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.in_w);
57         in_w->create_objects();
58         y0 += in_w->get_h() + ys8;
59
60         add_tool(new BC_Title(x0, y0, _("In H:")));
61         in_h = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.in_h);
62         in_h->create_objects();
63
64         x0 = get_w()/2;  y0 = y;
65         x1 = x0 + xs50;
66
67         add_tool(new BC_Title(x0, y0, _("Out R:")));
68         add_tool(out_r = new ScaleRatioRatio(this, client, x1, y0, &client->config.out_r));
69         out_r->create_objects();
70         y0 += out_r->get_th() + ys10;
71
72         add_tool(new BC_Title(x0, y0, _("Out W:")));
73         out_w = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.out_w);
74         out_w->create_objects();
75         y0 += out_w->get_h() + ys8;
76
77         add_tool(new BC_Title(x0, y0, _("Out H:")));
78         out_h = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.out_h);
79         out_h->create_objects();
80         y0 += out_h->get_h() + ys8;
81
82         y = y0 + ys5;
83         add_tool(apply_button = new ScaleRatioApply(this, x, y));
84         int x2 = x + apply_button->get_w() + xs50;
85         add_tool(type_popup = new ScaleRatioType(this, x2, y, &client->config.type));
86         type_popup->create_objects();
87         y += apply_button->get_h() + ys30;
88
89         x0 = x;  y0 = y;
90         x1 = x0 + xs50;
91
92         add_tool(new BC_Title(x0, y0, _("Src X:")));
93         src_x = new ScaleRatioCoord(this, client, x1, y0, 1, &client->config.src_x);
94         src_x->create_objects();
95         y0 += ys30;
96
97         add_tool(new BC_Title(x0, y0, _("Src Y:")));
98         src_y = new ScaleRatioCoord(this, client, x1, y0, 1, &client->config.src_y);
99         src_y->create_objects();
100         y0 += ys30;
101
102
103         add_tool(new BC_Title(x0, y0, _("Src W:")));
104         src_w = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.src_w);
105         src_w->create_objects();
106         y0 += ys30;
107
108         add_tool(new BC_Title(x0, y0, _("Src H:")));
109         src_h = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.src_h);
110         src_h->create_objects();
111         y0 += ys30;
112
113         x0 = get_w()/2;
114         x1 = x0 + xs50;
115         y0 = y;
116         add_tool(new BC_Title(x0, y0, _("Dst X:")));
117         dst_x = new ScaleRatioCoord(this, client, x1, y0, 1, &client->config.dst_x);
118         dst_x->create_objects();
119         y0 += ys30;
120
121         add_tool(new BC_Title(x0, y0, _("Dst Y:")));
122         dst_y = new ScaleRatioCoord(this, client, x1, y0, 1, &client->config.dst_y);
123         dst_y->create_objects();
124         y0 += ys30;
125
126         add_tool(new BC_Title(x0, y0, _("Dst W:")));
127         dst_w = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.dst_w);
128         dst_w->create_objects();
129         y0 += ys30;
130
131         add_tool(new BC_Title(x0, y0, _("Dst H:")));
132         dst_h = new ScaleRatioCoord(this, client, x1, y0, 0, &client->config.dst_h);
133         dst_h->create_objects();
134         y0 += ys30;
135
136         show_window();
137         flush();
138 }
139
140
141
142 ScaleRatioCoord::ScaleRatioCoord(ScaleRatioWin *win,
143         ScaleRatioMain *client, int x, int y, int s, float *value)
144  : BC_TumbleTextBox(win, (int)*value, (int)-10000*s, (int)10000, x, y, xS(100))
145 {
146         this->client = client;
147         this->win = win;
148         this->value = value;
149 }
150
151 ScaleRatioCoord::~ScaleRatioCoord()
152 {
153 }
154
155 int ScaleRatioCoord::handle_event()
156 {
157         *value = atof(get_text());
158         client->send_configure_change();
159         return 1;
160 }
161
162
163 ScaleRatioTumbler::ScaleRatioTumbler(ScaleRatioRatio *ratio, int value, int x, int y)
164  : BC_TumbleTextBox(ratio->win, value, 0, 10000, x, y, xS(45))
165 {
166         this->ratio = ratio;
167 }
168
169 ScaleRatioTumbler::~ScaleRatioTumbler()
170 {
171 }
172
173 int ScaleRatioTumbler::handle_event()
174 {
175         ratio->update_ratio();
176         return 1;
177 }
178
179 ScaleRatioRatio::ScaleRatioRatio(ScaleRatioWin *win,
180         ScaleRatioMain *client, int x, int y, float *value)
181  : BC_TextBox(x, y, xS(100), 1, *value)
182 {
183         this->client = client;
184         this->win = win;
185         this->value = value;
186         this->ah = 0;
187         this->aw = 0;
188 }
189
190 ScaleRatioRatio::~ScaleRatioRatio()
191 {
192         delete ah;
193         delete aw;
194 }
195
196 int ScaleRatioRatio::handle_event()
197 {
198         *value = atof(get_text());
199         float fah = 0, faw = 0;
200         MWindow::create_aspect_ratio(faw, fah, *value*1000000, 1000000);
201         ah->update((int64_t)fah);
202         aw->update((int64_t)faw);
203         win->update_config();
204         win->update_gui();
205         return 1;
206 }
207
208 void ScaleRatioRatio::create_objects()
209 {
210         int tx = BC_TextBox::get_x();
211         int ty = BC_TextBox::get_y();
212         int x = tx;
213         int y = ty + BC_TextBox::get_h() + yS(5);
214         float faw = 0, fah = 0;
215         MWindow::create_aspect_ratio(faw, fah, *value*1000000, 1000000);
216         aw = new ScaleRatioTumbler(this, faw, x, y);
217         aw->create_objects();
218         x += aw->get_w() + xS(5);
219         ah = new ScaleRatioTumbler(this, fah, x, y);
220         ah->create_objects();
221         x += ah->get_w();
222         y += ah->get_h();
223         tw = x - tx;
224         int w = BC_TextBox::get_w();
225         if( tw < w ) tw = w;
226         th = y - ty;
227 }
228
229 void ScaleRatioRatio::update_ratio()
230 {
231         float fah = atof(ah->get_text());
232         float faw = atof(aw->get_text());
233         *value = fah > 0 ? faw / fah : 1.f;
234         win->update_config();
235         win->update_gui();
236 }
237
238 ScaleRatioTypeItem::ScaleRatioTypeItem(ScaleRatioType *popup, int type, const char *text)
239  : BC_MenuItem(text)
240 {
241         this->popup = popup;
242         this->type = type;
243 }
244
245 ScaleRatioTypeItem::~ScaleRatioTypeItem()
246 {
247 }
248
249 int ScaleRatioTypeItem::handle_event()
250 {
251         popup->win->client->config.type = type;
252         popup->set_value(type);
253         return popup->handle_event();
254 }
255
256
257 ScaleRatioType::ScaleRatioType(ScaleRatioWin *win, int x, int y, int *value)
258  : BC_PopupMenu(x, y, xS(180), "", 1)
259 {
260         this->win = win;
261         this->value = value;
262 }
263
264 ScaleRatioType::~ScaleRatioType()
265 {
266 }
267
268 void ScaleRatioType::create_objects()
269 {
270         for( int i=1; i<Rescale::n_scale_types; ++i )
271                 add_item(new ScaleRatioTypeItem(this, i, Rescale::scale_types[i]));
272         set_value(*value);
273 }
274
275 void ScaleRatioType::update(int v)
276 {
277         set_value(*value = v);
278 }
279
280 int ScaleRatioType::handle_event()
281 {
282         win->update_config();
283         win->update_gui();
284         return 1;
285 }
286
287 int ScaleRatioApply::handle_event()
288 {
289         win->update_config();
290         win->update_gui();
291         win->client->send_configure_change();
292         return 1;
293 }
294
295 void ScaleRatioWin::update_config()
296 {
297         ScaleRatioConfig *conf = &client->config;
298         Rescale in(conf->in_w, conf->in_h, conf->in_r);
299         Rescale out(conf->out_w, conf->out_h, conf->out_r);
300         in.rescale(out,conf->type, conf->src_w,conf->src_h, conf->dst_w,conf->dst_h);
301 }
302
303 void ScaleRatioWin::update_gui()
304 {
305         ScaleRatioConfig *conf = &client->config;
306         type_popup->update(conf->type);
307         in_r->update(conf->in_r);
308         out_r->update(conf->out_r);
309         in_w->update(conf->in_w);
310         in_h->update(conf->in_h);
311         src_x->update(conf->src_x);
312         src_y->update(conf->src_y);
313         src_w->update(conf->src_w);
314         src_h->update(conf->src_h);
315         out_w->update(conf->out_w);
316         out_h->update(conf->out_h);
317         dst_x->update(conf->dst_x);
318         dst_y->update(conf->dst_y);
319         dst_w->update(conf->dst_w);
320         dst_h->update(conf->dst_h);
321 }
322