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