update ffmpeg.git patch set
[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
26
27
28
29
30
31
32
33
34 BrightnessWindow::BrightnessWindow(BrightnessMain *client)
35  : PluginClientWindow(client, 370, 155, 370, 155, 0)
36 {
37         this->client = client;
38 }
39
40 BrightnessWindow::~BrightnessWindow()
41 {
42 }
43
44 void BrightnessWindow::create_objects()
45 {
46         int x = 10, y = 10, x1 = x + 90;
47         int x2 = 0; int clrBtn_w = 50;
48
49         add_tool(new BC_Title(x, y, _("Brightness/Contrast")));
50         y += 25;
51         add_tool(new BC_Title(x, y,_("Brightness:")));
52         add_tool(brightness = new BrightnessSlider(client,
53                 &(client->config.brightness),
54                 x1,
55                 y,
56                 1));
57         x2 = x1 + brightness->get_w() + 10;
58         add_subwindow(brightnessClr = new BrightnessSliderClr(client, this, x2, y, clrBtn_w, 1));
59         y += 25;
60         add_tool(new BC_Title(x, y, _("Contrast:")));
61         add_tool(contrast = new BrightnessSlider(client,
62                 &(client->config.contrast),
63                 x1,
64                 y,
65                 0));
66
67         add_subwindow(contrastClr = new BrightnessSliderClr(client, this, x2, y, clrBtn_w, 0));
68         y += 30;
69         add_tool(luma = new BrightnessLuma(client,
70                 x,
71                 y));
72
73         y += 35;
74         add_subwindow(reset = new BrightnessReset(client, this, x, y));
75
76         show_window();
77         flush();
78 }
79
80 // for Reset button
81 void BrightnessWindow::update_gui(int clear)
82 {
83         switch(clear) {
84                 case RESET_CONTRAST : contrast->update(client->config.contrast);
85                         break;
86                 case RESET_BRIGHTNESS: brightness->update(client->config.brightness);
87                         break;
88                 case RESET_ALL :
89                 default:
90                         brightness->update(client->config.brightness);
91                         contrast->update(client->config.contrast);
92                         luma->update(client->config.luma);
93                         break;
94         }
95 }
96
97 BrightnessSlider::BrightnessSlider(BrightnessMain *client,
98         float *output,
99         int x,
100         int y,
101         int is_brightness)
102  : BC_FSlider(x,
103         y,
104         0,
105         200,
106         200,
107         -100,
108         100,
109         (int)*output)
110 {
111         this->client = client;
112         this->output = output;
113         this->is_brightness = is_brightness;
114 }
115 BrightnessSlider::~BrightnessSlider()
116 {
117 }
118 int BrightnessSlider::handle_event()
119 {
120         *output = get_value();
121         client->send_configure_change();
122         return 1;
123 }
124
125 char* BrightnessSlider::get_caption()
126 {
127         float fraction;
128         if(is_brightness)
129         {
130                 fraction = *output / 100;
131         }
132         else
133         {
134                 fraction = (*output < 0) ?
135                         (*output + 100) / 100 :
136                         (*output + 25) / 25;
137         }
138         sprintf(string, "%0.4f", fraction);
139         return string;
140 }
141
142
143 BrightnessLuma::BrightnessLuma(BrightnessMain *client,
144         int x,
145         int y)
146  : BC_CheckBox(x,
147         y,
148         client->config.luma,
149         _("Boost luminance only"))
150 {
151         this->client = client;
152 }
153 BrightnessLuma::~BrightnessLuma()
154 {
155 }
156 int BrightnessLuma::handle_event()
157 {
158         client->config.luma = get_value();
159         client->send_configure_change();
160         return 1;
161 }
162
163
164 BrightnessReset::BrightnessReset(BrightnessMain *client, BrightnessWindow *window, int x, int y)
165  : BC_GenericButton(x, y, _("Reset"))
166 {
167         this->client = client;
168         this->window = window;
169 }
170 BrightnessReset::~BrightnessReset()
171 {
172 }
173 int BrightnessReset::handle_event()
174 {
175         client->config.reset(RESET_ALL); // clear=0 ==> reset all
176         window->update_gui(RESET_ALL);
177         client->send_configure_change();
178         return 1;
179 }
180
181 BrightnessSliderClr::BrightnessSliderClr(BrightnessMain *client, BrightnessWindow *window, int x, int y, int w, int is_brightness)
182  : BC_GenericButton(x, y, w, _("⌂"))
183 {
184         this->client = client;
185         this->window = window;
186         this->is_brightness = is_brightness;
187 }
188 BrightnessSliderClr::~BrightnessSliderClr()
189 {
190 }
191 int BrightnessSliderClr::handle_event()
192 {
193         // is_brightness==0 means Contrast slider   ==> "clear=1"
194         // is_brightness==1 means Brightness slider ==> "clear=2"
195         client->config.reset(is_brightness + 1);
196         window->update_gui(is_brightness + 1);
197         client->send_configure_change();
198         return 1;
199 }
200