initial commit
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / scale / scalewin.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 "mwindow.h"
26 #include "pluginserver.h"
27 #include "scale.h"
28
29
30
31 ScaleWin::ScaleWin(ScaleMain *client)
32  : PluginClientWindow(client, 400, 100, 400, 100, 0)
33 {
34         this->client = client;
35 }
36
37 ScaleWin::~ScaleWin()
38 {
39         delete x_factor;
40         delete y_factor;
41         delete width;
42         delete height;
43 }
44
45 void ScaleWin::create_objects()
46 {
47         int x0 = 10, y0 = 10;
48         int y1 = y0 + 25;
49         int y2 = y1 + 25;
50         BC_Title *title = new BC_Title(x0, y1, _("Scale:"));
51         add_tool(title);
52         int x1 = x0 + title->get_w() + 10;
53         add_tool(use_scale = new ScaleUseScale(this, client, x1, y1));
54         int x2 = x1 + use_scale->get_w() + 10;
55         x_factor = new ScaleXFactor(this, client, x2, y1);
56         x_factor->create_objects();
57         int x3 = x2 + x_factor->get_w() + 20;
58         y_factor = new ScaleYFactor(this, client, x3, y1);
59         y_factor->create_objects();
60         add_tool(constrain = new ScaleConstrain(client, x1, y2));
61
62
63         add_tool(new BC_Title(x0, y0, _("Size:")));
64         add_tool(use_size = new ScaleUseSize(this, client, x1, y0));
65         width = new ScaleWidth(this, client, x2, y0);
66         width->create_objects();
67         int x = x2 + width->get_w() + 3;
68         add_tool(new BC_Title(x, y0, _("x")));
69         height= new ScaleHeight(this, client, x3, y0);
70         height->create_objects();
71         int x4 = x3 + height->get_w() + 15;
72         add_tool(pulldown = new FrameSizePulldown(client->server->mwindow->theme,
73                         width->get_textbox(), height->get_textbox(), x4, y0));
74
75         show_window();
76         flush();
77 }
78
79 ScaleXFactor::ScaleXFactor(ScaleWin *win,
80         ScaleMain *client, int x, int y)
81  : BC_TumbleTextBox(win, (float)client->config.x_factor, 0., 100., x, y, 100)
82 {
83 //printf("ScaleXFactor::ScaleXFactor %f\n", client->config.x_factor);
84         this->client = client;
85         this->win = win;
86         set_increment(0.1);
87         enabled = 1;
88 }
89
90 ScaleXFactor::~ScaleXFactor()
91 {
92 }
93
94 int ScaleXFactor::handle_event()
95 {
96         client->config.x_factor = atof(get_text());
97         CLAMP(client->config.x_factor, 0, 100);
98
99         if(client->config.constrain)
100         {
101                 client->config.y_factor = client->config.x_factor;
102                 win->y_factor->update(client->config.y_factor);
103         }
104
105 //printf("ScaleXFactor::handle_event 1 %f\n", client->config.x_factor);
106         if(client->config.type == FIXED_SCALE && enabled) {
107                 client->send_configure_change();
108         }
109         return 1;
110 }
111
112
113
114
115 ScaleYFactor::ScaleYFactor(ScaleWin *win, ScaleMain *client, int x, int y)
116  : BC_TumbleTextBox(win, (float)client->config.y_factor, 0., 100., x, y, 100)
117 {
118         this->client = client;
119         this->win = win;
120         set_increment(0.1);
121         enabled = 1;
122 }
123 ScaleYFactor::~ScaleYFactor()
124 {
125 }
126 int ScaleYFactor::handle_event()
127 {
128         client->config.y_factor = atof(get_text());
129         CLAMP(client->config.y_factor, 0, 100);
130
131         if(client->config.constrain)
132         {
133                 client->config.x_factor = client->config.y_factor;
134                 win->x_factor->update(client->config.x_factor);
135         }
136
137         if(client->config.type == FIXED_SCALE && enabled)
138         {
139                 client->send_configure_change();
140         }
141         return 1;
142 }
143
144
145
146 ScaleWidth::ScaleWidth(ScaleWin *win,
147         ScaleMain *client, int x, int y)
148  : BC_TumbleTextBox(win, client->config.width, 0, 100000, x, y, 90)
149 {
150 //printf("ScaleWidth::ScaleWidth %f\n", client->config.x_factor);
151         this->client = client;
152         this->win = win;
153         set_increment(10);
154         enabled = 1;
155 }
156
157 ScaleWidth::~ScaleWidth()
158 {
159 }
160
161 int ScaleWidth::handle_event()
162 {
163         client->config.width = atoi(get_text());
164         if(client->config.type == FIXED_SIZE && enabled)
165         {
166                 client->send_configure_change();
167         }
168 //printf("ScaleWidth::handle_event 1 %f\n", client->config.x_factor);
169         return 1;
170 }
171
172
173
174
175 ScaleHeight::ScaleHeight(ScaleWin *win, ScaleMain *client, int x, int y)
176  : BC_TumbleTextBox(win, client->config.height, 0, 100000, x, y, 90)
177 {
178         this->client = client;
179         this->win = win;
180         set_increment(10);
181         enabled = 1;
182 }
183 ScaleHeight::~ScaleHeight()
184 {
185 }
186
187 int ScaleHeight::handle_event()
188 {
189         client->config.height = atoi(get_text());
190         if(client->config.type == FIXED_SIZE && enabled)
191         {
192                 client->send_configure_change();
193         }
194         return 1;
195 }
196
197 ScaleUseScale::ScaleUseScale(ScaleWin *win, ScaleMain *client, int x, int y)
198  : BC_Radial(x, y, client->config.type == FIXED_SCALE, "")
199 {
200         this->win = win;
201         this->client = client;
202         set_tooltip(_("Use fixed scale"));
203 }
204 ScaleUseScale::~ScaleUseScale()
205 {
206 }
207 int ScaleUseScale::handle_event()
208 {
209         client->set_type(FIXED_SCALE);
210         return 1;
211 }
212
213 ScaleUseSize::ScaleUseSize(ScaleWin *win, ScaleMain *client, int x, int y)
214  : BC_Radial(x, y, client->config.type == FIXED_SIZE, "")
215 {
216         this->win = win;
217         this->client = client;
218         set_tooltip(_("Use fixed size"));
219 }
220 ScaleUseSize::~ScaleUseSize()
221 {
222 }
223 int ScaleUseSize::handle_event()
224 {
225         client->set_type(FIXED_SIZE);
226         return 1;
227 }
228
229
230
231 ScaleConstrain::ScaleConstrain(ScaleMain *client, int x, int y)
232  : BC_CheckBox(x, y, client->config.constrain, _("Constrain ratio"))
233 {
234         this->client = client;
235 }
236 ScaleConstrain::~ScaleConstrain()
237 {
238 }
239 int ScaleConstrain::handle_event()
240 {
241         client->config.constrain = get_value();
242         client->send_configure_change();
243         return 1;
244 }
245