4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #include "bcdisplayinfo.h"
23 #include "brightnesswindow.h"
35 BrightnessWindow::BrightnessWindow(BrightnessMain *client)
36 : PluginClientWindow(client, xS(420), yS(160), xS(420), yS(160), 0)
38 this->client = client;
41 BrightnessWindow::~BrightnessWindow()
45 void BrightnessWindow::create_objects()
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
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));
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));
82 add_tool(luma = new BrightnessLuma(client, x, y));
86 add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x));
88 add_subwindow(reset = new BrightnessReset(client, this, x, y));
95 void BrightnessWindow::update_gui(int clear)
99 contrast_text->update(client->config.contrast);
100 contrast_slider->update(client->config.contrast);
102 case RESET_BRIGHTNESS:
103 brightness_text->update(client->config.brightness);
104 brightness_slider->update(client->config.brightness);
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);
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
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
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)
137 this->window = window;
138 this->client = client;
139 this->output = output;
140 this->slider = slider;
146 BrightnessFText::~BrightnessFText()
150 int BrightnessFText::handle_event()
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();
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)
165 this->client = client;
166 this->output = output;
168 this->is_brightness = is_brightness;
169 enable_show_value(0); // Hide caption
172 BrightnessFSlider::~BrightnessFSlider()
176 int BrightnessFSlider::handle_event()
178 *output = get_value();
179 text->update(*output);
180 client->send_configure_change();
184 char* BrightnessFSlider::get_caption()
189 fraction = *output / 100;
193 fraction = (*output < 0) ?
194 (*output + 100) / 100 :
197 sprintf(string, "%0.4f", fraction);
202 BrightnessLuma::BrightnessLuma(BrightnessMain *client,
208 _("Boost luminance only"))
210 this->client = client;
212 BrightnessLuma::~BrightnessLuma()
215 int BrightnessLuma::handle_event()
217 client->config.luma = get_value();
218 client->send_configure_change();
223 BrightnessReset::BrightnessReset(BrightnessMain *client, BrightnessWindow *window, int x, int y)
224 : BC_GenericButton(x, y, _("Reset"))
226 this->client = client;
227 this->window = window;
229 BrightnessReset::~BrightnessReset()
232 int BrightnessReset::handle_event()
234 client->config.reset(RESET_ALL); // clear=0 ==> reset all
235 window->update_gui(RESET_ALL);
236 client->send_configure_change();
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"))
243 this->client = client;
244 this->window = window;
247 BrightnessClr::~BrightnessClr()
250 int BrightnessClr::handle_event()
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();