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