igor b reset btns, reframert bug fix
[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,
36         330,
37         160,
38         330,
39         160,
40         0)
41 {
42         this->client = client;
43 }
44
45 BrightnessWindow::~BrightnessWindow()
46 {
47 }
48
49 void BrightnessWindow::create_objects()
50 {
51         int x = 10, y = 10;
52         add_tool(new BC_Title(x, y, _("Brightness/Contrast")));
53         y += 25;
54         add_tool(new BC_Title(x, y,_("Brightness:")));
55         add_tool(brightness = new BrightnessSlider(client,
56                 &(client->config.brightness),
57                 x + 80,
58                 y,
59                 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                 x + 80,
65                 y,
66                 0));
67         y += 30;
68         add_tool(luma = new BrightnessLuma(client,
69                 x,
70                 y));
71
72         y += 35;
73         add_subwindow(reset = new BrightnessReset(client, this, x, y));
74
75         show_window();
76         flush();
77 }
78
79 // for Reset button
80 void BrightnessWindow::update()
81 {
82         brightness->update(client->config.brightness);
83         contrast->update(client->config.contrast);
84         luma->update(client->config.luma);
85 }
86
87 BrightnessSlider::BrightnessSlider(BrightnessMain *client,
88         float *output,
89         int x,
90         int y,
91         int is_brightness)
92  : BC_FSlider(x,
93         y,
94         0,
95         200,
96         200,
97         -100,
98         100,
99         (int)*output)
100 {
101         this->client = client;
102         this->output = output;
103         this->is_brightness = is_brightness;
104 }
105 BrightnessSlider::~BrightnessSlider()
106 {
107 }
108 int BrightnessSlider::handle_event()
109 {
110         *output = get_value();
111         client->send_configure_change();
112         return 1;
113 }
114
115 char* BrightnessSlider::get_caption()
116 {
117         float fraction;
118         if(is_brightness)
119         {
120                 fraction = *output / 100;
121         }
122         else
123         {
124                 fraction = (*output < 0) ?
125                         (*output + 100) / 100 :
126                         (*output + 25) / 25;
127         }
128         sprintf(string, "%0.4f", fraction);
129         return string;
130 }
131
132
133 BrightnessLuma::BrightnessLuma(BrightnessMain *client,
134         int x,
135         int y)
136  : BC_CheckBox(x,
137         y,
138         client->config.luma,
139         _("Boost luminance only"))
140 {
141         this->client = client;
142 }
143 BrightnessLuma::~BrightnessLuma()
144 {
145 }
146 int BrightnessLuma::handle_event()
147 {
148         client->config.luma = get_value();
149         client->send_configure_change();
150         return 1;
151 }
152
153
154 BrightnessReset::BrightnessReset(BrightnessMain *client, BrightnessWindow *window, int x, int y)
155  : BC_GenericButton(x, y, _("Reset"))
156 {
157         this->client = client;
158         this->window = window;
159 }
160 BrightnessReset::~BrightnessReset()
161 {
162 }
163 int BrightnessReset::handle_event()
164 {
165         client->config.reset();
166         window->update();
167         client->send_configure_change();
168         return 1;
169 }
170