4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #include "bcdisplayinfo.h"
26 #include "unsharpwindow.h"
29 UnsharpWindow::UnsharpWindow(UnsharpMain *plugin)
30 : PluginClientWindow(plugin, xS(420), yS(160), xS(420), yS(160), 0)
32 this->plugin = plugin;
35 UnsharpWindow::~UnsharpWindow()
39 void UnsharpWindow::create_objects()
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;
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));
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));
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));
82 add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x));
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));
93 void UnsharpWindow::update_gui(int clear)
97 radius_text->update(plugin->config.radius);
98 radius_slider->update(plugin->config.radius);
101 amount_text->update(plugin->config.amount);
102 amount_slider->update(plugin->config.amount);
104 case RESET_THRESHOLD :
105 threshold_text->update((int64_t)plugin->config.threshold);
106 threshold_slider->update((int64_t)plugin->config.threshold);
109 case RESET_DEFAULT_SETTINGS :
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);
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)
129 this->window = window;
130 this->plugin = plugin;
134 UnsharpRadiusText::~UnsharpRadiusText()
138 int UnsharpRadiusText::handle_event()
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();
151 UnsharpRadiusSlider::UnsharpRadiusSlider(UnsharpWindow *window, UnsharpMain *plugin,
153 : BC_FSlider(x, y, 0, w, w, RADIUS_MIN, RADIUS_MAX, plugin->config.radius)
155 this->window = window;
156 this->plugin = plugin;
157 enable_show_value(0); // Hide caption
161 UnsharpRadiusSlider::~UnsharpRadiusSlider()
165 int UnsharpRadiusSlider::handle_event()
167 plugin->config.radius = get_value();
168 window->radius_text->update(plugin->config.radius);
169 plugin->send_configure_change();
172 /* *********************************** */
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)
181 this->window = window;
182 this->plugin = plugin;
186 UnsharpAmountText::~UnsharpAmountText()
190 int UnsharpAmountText::handle_event()
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();
203 UnsharpAmountSlider::UnsharpAmountSlider(UnsharpWindow *window, UnsharpMain *plugin,
205 : BC_FSlider(x, y, 0, w, w, AMOUNT_MIN, AMOUNT_MAX, plugin->config.amount)
207 this->window = window;
208 this->plugin = plugin;
209 enable_show_value(0); // Hide caption
213 UnsharpAmountSlider::~UnsharpAmountSlider()
217 int UnsharpAmountSlider::handle_event()
219 plugin->config.amount = get_value();
220 window->amount_text->update(plugin->config.amount);
221 plugin->send_configure_change();
224 /* *********************************** */
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))
233 this->window = window;
234 this->plugin = plugin;
238 UnsharpThresholdText::~UnsharpThresholdText()
242 int UnsharpThresholdText::handle_event()
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();
255 UnsharpThresholdSlider::UnsharpThresholdSlider(UnsharpWindow *window, UnsharpMain *plugin,
257 : BC_ISlider(x, y, 0, w, w, THRESHOLD_MIN, THRESHOLD_MAX, plugin->config.threshold)
259 this->window = window;
260 this->plugin = plugin;
261 enable_show_value(0); // Hide caption
264 UnsharpThresholdSlider::~UnsharpThresholdSlider()
268 int UnsharpThresholdSlider::handle_event()
270 plugin->config.threshold = get_value();
271 window->threshold_text->update((int64_t)plugin->config.threshold);
272 plugin->send_configure_change();
275 /* *********************************** */
278 UnsharpReset::UnsharpReset(UnsharpWindow *window, UnsharpMain *plugin, int x, int y)
279 : BC_GenericButton(x, y, _("Reset"))
281 this->plugin = plugin;
282 this->window = window;
284 UnsharpReset::~UnsharpReset()
287 int UnsharpReset::handle_event()
289 plugin->config.reset(RESET_ALL);
290 window->update_gui(RESET_ALL);
291 plugin->send_configure_change();
295 UnsharpDefaultSettings::UnsharpDefaultSettings(UnsharpWindow *window, UnsharpMain *plugin, int x, int y, int w)
296 : BC_GenericButton(x, y, w, _("Default"))
298 this->plugin = plugin;
299 this->window = window;
301 UnsharpDefaultSettings::~UnsharpDefaultSettings()
304 int UnsharpDefaultSettings::handle_event()
306 plugin->config.reset(RESET_DEFAULT_SETTINGS);
307 window->update_gui(RESET_DEFAULT_SETTINGS);
308 plugin->send_configure_change();
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"))
315 this->window = window;
316 this->plugin = plugin;
319 UnsharpClr::~UnsharpClr()
322 int UnsharpClr::handle_event()
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();