improved plugins with added Tumbler box and visible values
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / unsharp / unsharpwindow.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 "language.h"
24 #include "theme.h"
25 #include "unsharp.h"
26 #include "unsharpwindow.h"
27
28
29 UnsharpWindow::UnsharpWindow(UnsharpMain *plugin)
30  : PluginClientWindow(plugin, xS(420), yS(160), xS(420), yS(160), 0)
31 {
32         this->plugin = plugin;
33 }
34
35 UnsharpWindow::~UnsharpWindow()
36 {
37 }
38
39 void UnsharpWindow::create_objects()
40 {
41         int xs10 = xS(10), xs100 = xS(100), xs200 = xS(200);
42         int ys10 = yS(10), ys30 = yS(30), ys40 = yS(40);
43         int x = xs10, y = ys10;
44         int x2 = xS(80), x3 = xS(180);
45         int clr_x = get_w()-x - xS(22); // note: clrBtn_w = 22
46         int defaultBtn_w = xs100;
47
48         BC_Title *title;
49         BC_Bar *bar;
50
51 // Radius
52         y += ys10;
53         add_subwindow(title = new BC_Title(x, y, _("Radius:")));
54         radius_text = new UnsharpRadiusText(this, plugin, (x + x2), y);
55         radius_text->create_objects();
56         radius_slider = new UnsharpRadiusSlider(this, plugin, x3, y, xs200);
57         add_subwindow(radius_slider);
58         clr_x = x3 + radius_slider->get_w() + x;
59         add_subwindow(radius_clr = new UnsharpClr(this, plugin,
60                 clr_x, y, RESET_RADIUS));
61         y += ys30;
62 // Amount
63         add_subwindow(title = new BC_Title(x, y, _("Amount:")));
64         amount_text = new UnsharpAmountText(this, plugin, (x + x2), y);
65         amount_text->create_objects();
66         amount_slider = new UnsharpAmountSlider(this, plugin, x3, y, xs200);
67         add_subwindow(amount_slider);
68         add_subwindow(amount_clr = new UnsharpClr(this, plugin,
69                 clr_x, y, RESET_AMOUNT));
70         y += ys30;
71 // Threshold
72         add_subwindow(title = new BC_Title(x, y, _("Threshold:")));
73         threshold_text = new UnsharpThresholdText(this, plugin, (x + x2), y);
74         threshold_text->create_objects();
75         threshold_slider = new UnsharpThresholdSlider(this, plugin, x3, y, xs200);
76         add_subwindow(threshold_slider);
77         add_subwindow(threshold_clr = new UnsharpClr(this, plugin,
78                 clr_x, y, RESET_THRESHOLD));
79         y += ys40;
80
81 // Reset section
82         add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x));
83         y += ys10;
84         add_subwindow(reset = new UnsharpReset(this, plugin, x, y));
85         add_subwindow(default_settings = new UnsharpDefaultSettings(this,plugin,
86                 (get_w() - xs10 - defaultBtn_w), y, defaultBtn_w));
87
88         show_window();
89         flush();
90 }
91
92
93 void UnsharpWindow::update_gui(int clear)
94 {
95         switch(clear) {
96                 case RESET_RADIUS : 
97                         radius_text->update(plugin->config.radius);
98                         radius_slider->update(plugin->config.radius);
99                         break;
100                 case RESET_AMOUNT : 
101                         amount_text->update(plugin->config.amount);
102                         amount_slider->update(plugin->config.amount);
103                         break;
104                 case RESET_THRESHOLD : 
105                         threshold_text->update((int64_t)plugin->config.threshold);
106                         threshold_slider->update((int64_t)plugin->config.threshold);
107                         break;
108                 case RESET_ALL :
109                 case RESET_DEFAULT_SETTINGS :
110                 default:
111                         radius_text->update(plugin->config.radius);
112                         radius_slider->update(plugin->config.radius);
113                         amount_text->update(plugin->config.amount);
114                         amount_slider->update(plugin->config.amount);
115                         threshold_text->update((int64_t)plugin->config.threshold);
116                         threshold_slider->update((int64_t)plugin->config.threshold);
117                         break;
118         }
119 }
120
121
122
123 /* *********************************** */
124 /* **** UNSHARP RADIUS *************** */
125 UnsharpRadiusText::UnsharpRadiusText(UnsharpWindow *window, UnsharpMain *plugin, int x, int y)
126  : BC_TumbleTextBox(window, plugin->config.radius,
127         (float)RADIUS_MIN, (float)RADIUS_MAX, x, y, xS(60), 2)
128 {
129         this->window = window;
130         this->plugin = plugin;
131         set_increment(0.1);
132 }
133
134 UnsharpRadiusText::~UnsharpRadiusText()
135 {
136 }
137
138 int UnsharpRadiusText::handle_event()
139 {
140         float min = RADIUS_MIN, max = RADIUS_MAX;
141         float output = atof(get_text());
142         if(output > max) output = max;
143         if(output < min) output = min;
144         plugin->config.radius = output;
145         window->radius_slider->update(plugin->config.radius);
146         window->radius_text->update(plugin->config.radius);
147         plugin->send_configure_change();
148         return 1;
149 }
150
151 UnsharpRadiusSlider::UnsharpRadiusSlider(UnsharpWindow *window, UnsharpMain *plugin,
152         int x, int y, int w)
153  : BC_FSlider(x, y, 0, w, w, RADIUS_MIN, RADIUS_MAX, plugin->config.radius)
154 {
155         this->window = window;
156         this->plugin = plugin;
157         enable_show_value(0); // Hide caption
158         set_precision(0.01);
159 }
160
161 UnsharpRadiusSlider::~UnsharpRadiusSlider()
162 {
163 }
164
165 int UnsharpRadiusSlider::handle_event()
166 {
167         plugin->config.radius = get_value();
168         window->radius_text->update(plugin->config.radius);
169         plugin->send_configure_change();
170         return 1;
171 }
172 /* *********************************** */
173
174
175 /* *********************************** */
176 /* **** UNSHARP AMOUNT *************** */
177 UnsharpAmountText::UnsharpAmountText(UnsharpWindow *window, UnsharpMain *plugin, int x, int y)
178  : BC_TumbleTextBox(window, plugin->config.amount,
179         (float)AMOUNT_MIN, (float)AMOUNT_MAX, x, y, xS(60), 2)
180 {
181         this->window = window;
182         this->plugin = plugin;
183         set_increment(0.1);
184 }
185
186 UnsharpAmountText::~UnsharpAmountText()
187 {
188 }
189
190 int UnsharpAmountText::handle_event()
191 {
192         float min = AMOUNT_MIN, max = AMOUNT_MAX;
193         float output = atof(get_text());
194         if(output > max) output = max;
195         if(output < min) output = min;
196         plugin->config.amount = output;
197         window->amount_slider->update(plugin->config.amount);
198         window->amount_text->update(plugin->config.amount);
199         plugin->send_configure_change();
200         return 1;
201 }
202
203 UnsharpAmountSlider::UnsharpAmountSlider(UnsharpWindow *window, UnsharpMain *plugin,
204         int x, int y, int w)
205  : BC_FSlider(x, y, 0, w, w, AMOUNT_MIN, AMOUNT_MAX, plugin->config.amount)
206 {
207         this->window = window;
208         this->plugin = plugin;
209         enable_show_value(0); // Hide caption
210         set_precision(0.01);
211 }
212
213 UnsharpAmountSlider::~UnsharpAmountSlider()
214 {
215 }
216
217 int UnsharpAmountSlider::handle_event()
218 {
219         plugin->config.amount = get_value();
220         window->amount_text->update(plugin->config.amount);
221         plugin->send_configure_change();
222         return 1;
223 }
224 /* *********************************** */
225
226
227 /* *********************************** */
228 /* **** UNSHARP THRESHOLD ************ */
229 UnsharpThresholdText::UnsharpThresholdText(UnsharpWindow *window, UnsharpMain *plugin, int x, int y)
230  : BC_TumbleTextBox(window, plugin->config.threshold,
231         THRESHOLD_MIN, THRESHOLD_MAX, x, y, xS(60))
232 {
233         this->window = window;
234         this->plugin = plugin;
235         set_increment(1);
236 }
237
238 UnsharpThresholdText::~UnsharpThresholdText()
239 {
240 }
241
242 int UnsharpThresholdText::handle_event()
243 {
244         int min = THRESHOLD_MIN, max = THRESHOLD_MAX;
245         int output = atoi(get_text());
246         if(output > max) output = max;
247         if(output < min) output = min;
248         plugin->config.threshold = output;
249         window->threshold_slider->update(plugin->config.threshold);
250         window->threshold_text->update((int64_t)plugin->config.threshold);
251         plugin->send_configure_change();
252         return 1;
253 }
254
255 UnsharpThresholdSlider::UnsharpThresholdSlider(UnsharpWindow *window, UnsharpMain *plugin,
256         int x, int y, int w)
257  : BC_ISlider(x, y, 0, w, w, THRESHOLD_MIN, THRESHOLD_MAX, plugin->config.threshold)
258 {
259         this->window = window;
260         this->plugin = plugin;
261         enable_show_value(0); // Hide caption
262 }
263
264 UnsharpThresholdSlider::~UnsharpThresholdSlider()
265 {
266 }
267
268 int UnsharpThresholdSlider::handle_event()
269 {
270         plugin->config.threshold = get_value();
271         window->threshold_text->update((int64_t)plugin->config.threshold);
272         plugin->send_configure_change();
273         return 1;
274 }
275 /* *********************************** */
276
277
278 UnsharpReset::UnsharpReset(UnsharpWindow *window, UnsharpMain *plugin, int x, int y)
279  : BC_GenericButton(x, y, _("Reset"))
280 {
281         this->plugin = plugin;
282         this->window = window;
283 }
284 UnsharpReset::~UnsharpReset()
285 {
286 }
287 int UnsharpReset::handle_event()
288 {
289         plugin->config.reset(RESET_ALL);
290         window->update_gui(RESET_ALL);
291         plugin->send_configure_change();
292         return 1;
293 }
294
295 UnsharpDefaultSettings::UnsharpDefaultSettings(UnsharpWindow *window, UnsharpMain *plugin, int x, int y, int w)
296  : BC_GenericButton(x, y, w, _("Default"))
297 {
298         this->plugin = plugin;
299         this->window = window;
300 }
301 UnsharpDefaultSettings::~UnsharpDefaultSettings()
302 {
303 }
304 int UnsharpDefaultSettings::handle_event()
305 {
306         plugin->config.reset(RESET_DEFAULT_SETTINGS);
307         window->update_gui(RESET_DEFAULT_SETTINGS);
308         plugin->send_configure_change();
309         return 1;
310 }
311
312 UnsharpClr::UnsharpClr(UnsharpWindow *window, UnsharpMain *plugin, int x, int y, int clear)
313  : BC_Button(x, y, plugin->get_theme()->get_image_set("reset_button"))
314 {
315         this->window = window;
316         this->plugin = plugin;
317         this->clear = clear;
318 }
319 UnsharpClr::~UnsharpClr()
320 {
321 }
322 int UnsharpClr::handle_event()
323 {
324         // clear==1 ==> Radius slider
325         // clear==2 ==> Amount slider
326         // clear==3 ==> Threshold slider
327         plugin->config.reset(clear);
328         window->update_gui(clear);
329         plugin->send_configure_change();
330         return 1;
331 }