Add back 2 patches for histogram and overlayframe that are working correctly and...
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / blur / blurwindow.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2010 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 "blur.h"
24 #include "blurwindow.h"
25 #include "language.h"
26
27
28
29
30
31
32 BlurWindow::BlurWindow(BlurMain *client)
33  : PluginClientWindow(client,
34         xS(420),
35         yS(250),
36         xS(420),
37         yS(250),
38         0)
39 {
40         this->client = client;
41 }
42
43 BlurWindow::~BlurWindow()
44 {
45 //printf("BlurWindow::~BlurWindow 1\n");
46 }
47
48 void BlurWindow::create_objects()
49 {
50         int xs10 = xS(10), xs20 = xS(20), xs200 = xS(200);
51         int ys10 = yS(10), ys20 = yS(20), ys30 = yS(30), ys40 = yS(40);
52         int x2 = xS(80), x3 = xS(180);
53         int x = xs10, y = ys10;
54         int clr_x = get_w()-x - xS(22); // note: clrBtn_w = 22
55
56         BC_TitleBar *title_bar;
57         BC_Bar *bar;
58
59         add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xs20, xs10, _("Radius")));
60         y += ys20;
61         add_subwindow(new BC_Title(x, y, _("Radius:")));
62         radius_text = new BlurRadiusText(client, this, (x + x2), y);
63         radius_text->create_objects();
64         add_subwindow(radius_slider = new BlurRadiusSlider(client, this, x3, y, xs200));
65         clr_x = x3 + radius_slider->get_w() + x;
66         add_subwindow(radius_Clr = new BlurRadiusClr(client, this, clr_x, y));
67 // December 2021: Disable and Hide 'Alpha determines radius' checkbox for bug(?)
68 //      y += ys30;
69         add_subwindow(a_key = new BlurAKey(client, x, y));
70         y += ys40;
71
72         add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xs20, xs10, _("Direction")));
73         y += ys20;
74         add_subwindow(horizontal = new BlurHorizontal(client, this, x, y));
75         y += ys30;
76         add_subwindow(vertical = new BlurVertical(client, this, x, y));
77         y += ys40;
78
79         add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xs20, xs10, _("Color channel")));
80         y += ys20;
81         int x1 = x;
82         int toggle_w = (get_w()-2*x) / 4;
83         add_subwindow(r = new BlurR(client, x1, y));
84         x1 += toggle_w;
85         add_subwindow(g = new BlurG(client, x1, y));
86         x1 += toggle_w;
87         add_subwindow(b = new BlurB(client, x1, y));
88         x1 += toggle_w;
89         add_subwindow(a = new BlurA(client, x1, y));
90         y += ys30;
91
92 // Reset section
93         add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x));
94         y += ys10;
95         add_subwindow(reset = new BlurReset(client, this, x, y));
96
97         show_window();
98
99 // December 2021: Disable and Hide 'Alpha determines radius' checkbox for bug(?)
100         a_key->disable();
101         a_key->hide_window();
102
103         flush();
104 }
105
106 // for Reset button
107 void BlurWindow::update(int clear)
108 {
109         switch(clear) {
110                 case RESET_RADIUS :
111                         radius_slider->update(client->config.radius);
112                         radius_text->update((int64_t)client->config.radius);
113                         break;
114                 case RESET_ALL :
115                 default:
116                         horizontal->update(client->config.horizontal);
117                         vertical->update(client->config.vertical);
118                         radius_slider->update(client->config.radius);
119                         radius_text->update((int64_t)client->config.radius);
120                         a_key->update(client->config.a_key);
121                         a->update(client->config.a);
122                         r->update(client->config.r);
123                         g->update(client->config.g);
124                         b->update(client->config.b);
125                         break;
126         }
127 }
128
129
130 BlurRadiusSlider::BlurRadiusSlider(BlurMain *client, BlurWindow *gui, int x, int y, int w)
131  : BC_ISlider(x, y, 0, w, w, 0, MAXRADIUS, client->config.radius, 0, 0, 0)
132 {
133         this->client = client;
134         this->gui = gui;
135         enable_show_value(0); // Hide caption
136 }
137 BlurRadiusSlider::~BlurRadiusSlider()
138 {
139 }
140 int BlurRadiusSlider::handle_event()
141 {
142         client->config.radius = get_value();
143         gui->radius_text->update((int64_t)client->config.radius);
144         client->send_configure_change();
145         return 1;
146 }
147
148
149
150
151 BlurRadiusText::BlurRadiusText(BlurMain *client, BlurWindow *gui, int x, int y)
152  : BC_TumbleTextBox(gui, client->config.radius,
153         0, MAXRADIUS, x, y, xS(60), 0)
154 {
155         this->client = client;
156         this->gui = gui;
157         set_increment(1);
158 }
159 BlurRadiusText::~BlurRadiusText()
160 {
161 }
162 int BlurRadiusText::handle_event()
163 {
164         client->config.radius = atoi(get_text());
165         if(client->config.radius > MAXRADIUS) client->config.radius = MAXRADIUS;
166         else if(client->config.radius < 0) client->config.radius = 0;
167         gui->radius_text->update((int64_t)client->config.radius);
168         gui->radius_slider->update(client->config.radius);
169         client->send_configure_change();
170         return 1;
171 }
172
173
174
175
176 BlurVertical::BlurVertical(BlurMain *client, BlurWindow *window, int x, int y)
177  : BC_CheckBox(x,
178         y,
179         client->config.vertical,
180         _("Vertical"))
181 {
182         this->client = client;
183         this->window = window;
184 }
185 BlurVertical::~BlurVertical()
186 {
187 }
188 int BlurVertical::handle_event()
189 {
190         client->config.vertical = get_value();
191         client->send_configure_change();
192         return 1;
193 }
194
195 BlurHorizontal::BlurHorizontal(BlurMain *client, BlurWindow *window, int x, int y)
196  : BC_CheckBox(x,
197         y,
198         client->config.horizontal,
199         _("Horizontal"))
200 {
201         this->client = client;
202         this->window = window;
203 }
204 BlurHorizontal::~BlurHorizontal()
205 {
206 }
207 int BlurHorizontal::handle_event()
208 {
209         client->config.horizontal = get_value();
210         client->send_configure_change();
211         return 1;
212 }
213
214
215
216
217 BlurA::BlurA(BlurMain *client, int x, int y)
218  : BC_CheckBox(x, y, client->config.a, _("Alpha"))
219 {
220         this->client = client;
221 }
222 int BlurA::handle_event()
223 {
224         client->config.a = get_value();
225         client->send_configure_change();
226         return 1;
227 }
228
229
230
231
232 BlurAKey::BlurAKey(BlurMain *client, int x, int y)
233  : BC_CheckBox(x, y, client->config.a_key, _("Alpha determines radius"))
234 {
235         this->client = client;
236 }
237 int BlurAKey::handle_event()
238 {
239         client->config.a_key = get_value();
240         client->send_configure_change();
241         return 1;
242 }
243
244 BlurR::BlurR(BlurMain *client, int x, int y)
245  : BC_CheckBox(x, y, client->config.r, _("Red"))
246 {
247         this->client = client;
248 }
249 int BlurR::handle_event()
250 {
251         client->config.r = get_value();
252         client->send_configure_change();
253         return 1;
254 }
255
256 BlurG::BlurG(BlurMain *client, int x, int y)
257  : BC_CheckBox(x, y, client->config.g, _("Green"))
258 {
259         this->client = client;
260 }
261 int BlurG::handle_event()
262 {
263         client->config.g = get_value();
264         client->send_configure_change();
265         return 1;
266 }
267
268 BlurB::BlurB(BlurMain *client, int x, int y)
269  : BC_CheckBox(x, y, client->config.b, _("Blue"))
270 {
271         this->client = client;
272 }
273 int BlurB::handle_event()
274 {
275         client->config.b = get_value();
276         client->send_configure_change();
277         return 1;
278 }
279
280 BlurReset::BlurReset(BlurMain *client, BlurWindow *window, int x, int y)
281  : BC_GenericButton(x, y, _("Reset"))
282 {
283         this->client = client;
284         this->window = window;
285 }
286 BlurReset::~BlurReset()
287 {
288 }
289 int BlurReset::handle_event()
290 {
291         client->config.reset(RESET_ALL);
292         window->update(RESET_ALL);
293         client->send_configure_change();
294         return 1;
295 }
296
297 BlurRadiusClr::BlurRadiusClr(BlurMain *client, BlurWindow *gui, int x, int y)
298  : BC_Button(x, y, client->get_theme()->get_image_set("reset_button"))
299 {
300         this->client = client;
301         this->gui = gui;
302 }
303 BlurRadiusClr::~BlurRadiusClr()
304 {
305 }
306 int BlurRadiusClr::handle_event()
307 {
308         client->config.reset(RESET_RADIUS);
309         gui->update(RESET_RADIUS);
310         client->send_configure_change();
311         return 1;
312 }
313