ffmpeg versioning mods from Andrew
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / brightness / brightnesswindow.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 "brightnesswindow.h"
24 #include "language.h"
25 #include "theme.h"
26
27
28
29
30
31
32
33
34
35 BrightnessWindow::BrightnessWindow(BrightnessMain *client)
36  : PluginClientWindow(client, xS(420), yS(160), xS(420), yS(160), 0)
37 {
38         this->client = client;
39 }
40
41 BrightnessWindow::~BrightnessWindow()
42 {
43 }
44
45 void BrightnessWindow::create_objects()
46 {
47         int xs10 = xS(10), xs200 = xS(200);
48         int ys10 = yS(10), ys30 = yS(30), ys40 = yS(40);
49         int x = xs10, y = ys10;
50         int x2 = xS(80), x3 = xS(180);
51         int clr_x = get_w()-x - xS(22); // note: clrBtn_w = 22
52
53         BC_Bar *bar;
54
55 // Brightness
56         y += ys10;
57         add_tool(new BC_Title(x, y,_("Brightness:")));
58         brightness_text = new BrightnessFText(this, client,
59                 0, &(client->config.brightness), (x + x2), y, -MAXVALUE, MAXVALUE);
60         brightness_text->create_objects();
61         brightness_slider = new BrightnessFSlider(client,
62                 brightness_text, &(client->config.brightness), x3, y, -MAXVALUE, MAXVALUE, xs200, 1);
63         add_subwindow(brightness_slider);
64         brightness_text->slider = brightness_slider;
65         clr_x = x3 + brightness_slider->get_w() + x;
66         add_subwindow(brightness_Clr = new BrightnessClr(client, this, clr_x, y, RESET_BRIGHTNESS));
67         y += ys30;
68
69 // Contrast
70         add_tool(new BC_Title(x, y, _("Contrast:")));
71         contrast_text = new BrightnessFText(this, client,
72                 0, &(client->config.contrast), (x + x2), y, -MAXVALUE, MAXVALUE);
73         contrast_text->create_objects();
74         contrast_slider = new BrightnessFSlider(client,
75                 contrast_text, &(client->config.contrast), x3, y, -MAXVALUE, MAXVALUE, xs200, 0);
76         add_subwindow(contrast_slider);
77         contrast_text->slider = contrast_slider;
78         add_subwindow(contrast_Clr = new BrightnessClr(client, this, clr_x, y, RESET_CONTRAST));
79         y += ys30;
80
81 // Luma
82         add_tool(luma = new BrightnessLuma(client, x, y));
83         y += ys40;
84
85 // Reset section
86         add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x));
87         y += ys10;
88         add_subwindow(reset = new BrightnessReset(client, this, x, y));
89
90         show_window();
91         flush();
92 }
93
94 // for Reset button
95 void BrightnessWindow::update_gui(int clear)
96 {
97         switch(clear) {
98                 case RESET_CONTRAST :
99                         contrast_text->update(client->config.contrast);
100                         contrast_slider->update(client->config.contrast);
101                         break;
102                 case RESET_BRIGHTNESS:
103                         brightness_text->update(client->config.brightness);
104                         brightness_slider->update(client->config.brightness);
105                         break;
106                 case RESET_ALL :
107                 default:
108                         brightness_text->update(client->config.brightness);
109                         brightness_slider->update(client->config.brightness);
110                         contrast_text->update(client->config.contrast);
111                         contrast_slider->update(client->config.contrast);
112                         luma->update(client->config.luma);
113                         break;
114         }
115 }
116
117
118 /* BRIGHTNESS VALUES
119   brightness is stored    from -100.00  to +100.00
120   brightness_slider  goes from -100.00  to +100.00
121   brightness_caption goes from   -1.000 to   +1.000
122   brightness_text    goes from -100.00  to +100.00
123 */
124
125 /* CONTRAST VALUES
126   contrast is stored    from -100.00  to +100.00
127   contrast_slider  goes from -100.00  to +100.00
128   contrast_caption goes from    0.000 to   +5.000 (clear to +1.000)
129   contrast_text    goes from -100.00  to +100.00
130 */
131
132 BrightnessFText::BrightnessFText(BrightnessWindow *window, BrightnessMain *client,
133         BrightnessFSlider *slider, float *output, int x, int y, float min, float max)
134  : BC_TumbleTextBox(window, *output,
135         min, max, x, y, xS(60), 2)
136 {
137         this->window = window;
138         this->client = client;
139         this->output = output;
140         this->slider = slider;
141         this->min = min;
142         this->max = max;
143         set_increment(0.01);
144 }
145
146 BrightnessFText::~BrightnessFText()
147 {
148 }
149
150 int BrightnessFText::handle_event()
151 {
152         *output = atof(get_text());
153         if(*output > max) *output = max;
154         else if(*output < min) *output = min;
155         slider->update(*output);
156         client->send_configure_change();
157         return 1;
158 }
159
160 BrightnessFSlider::BrightnessFSlider(BrightnessMain *client,
161         BrightnessFText *text, float *output, int x, int y,
162         float min, float max, int w, int is_brightness)
163  : BC_FSlider(x, y, 0, w, w, min, max, *output)
164 {
165         this->client = client;
166         this->output = output;
167         this->text = text;
168         this->is_brightness = is_brightness;
169         enable_show_value(0); // Hide caption
170 }
171
172 BrightnessFSlider::~BrightnessFSlider()
173 {
174 }
175
176 int BrightnessFSlider::handle_event()
177 {
178         *output = get_value();
179         text->update(*output);
180         client->send_configure_change();
181         return 1;
182 }
183
184 char* BrightnessFSlider::get_caption()
185 {
186         float fraction;
187         if(is_brightness)
188         {
189                 fraction = *output / 100;
190         }
191         else
192         {
193                 fraction = (*output < 0) ?
194                         (*output + 100) / 100 :
195                         (*output + 25) / 25;
196         }
197         sprintf(string, "%0.4f", fraction);
198         return string;
199 }
200
201
202 BrightnessLuma::BrightnessLuma(BrightnessMain *client,
203         int x,
204         int y)
205  : BC_CheckBox(x,
206         y,
207         client->config.luma,
208         _("Boost luminance only"))
209 {
210         this->client = client;
211 }
212 BrightnessLuma::~BrightnessLuma()
213 {
214 }
215 int BrightnessLuma::handle_event()
216 {
217         client->config.luma = get_value();
218         client->send_configure_change();
219         return 1;
220 }
221
222
223 BrightnessReset::BrightnessReset(BrightnessMain *client, BrightnessWindow *window, int x, int y)
224  : BC_GenericButton(x, y, _("Reset"))
225 {
226         this->client = client;
227         this->window = window;
228 }
229 BrightnessReset::~BrightnessReset()
230 {
231 }
232 int BrightnessReset::handle_event()
233 {
234         client->config.reset(RESET_ALL); // clear=0 ==> reset all
235         window->update_gui(RESET_ALL);
236         client->send_configure_change();
237         return 1;
238 }
239
240 BrightnessClr::BrightnessClr(BrightnessMain *client, BrightnessWindow *window, int x, int y, int clear)
241  : BC_Button(x, y, client->get_theme()->get_image_set("reset_button"))
242 {
243         this->client = client;
244         this->window = window;
245         this->clear = clear;
246 }
247 BrightnessClr::~BrightnessClr()
248 {
249 }
250 int BrightnessClr::handle_event()
251 {
252         // clear==1 ==> Contrast text-slider
253         // clear==2 ==> Brightness text-slider
254         client->config.reset(clear);
255         window->update_gui(clear);
256         client->send_configure_change();
257         return 1;
258 }
259