1 /* PlusButton.cpp
2  * Copyright (C) 2018, 2019  Sven Jähnichen
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 #include "PlusButton.hpp"
19 
20 namespace BWidgets
21 {
PlusButton()22 PlusButton::PlusButton () :
23 		PlusButton (0.0, 0.0, BWIDGETS_DEFAULT_BUTTON_WIDTH, BWIDGETS_DEFAULT_BUTTON_HEIGHT, "upbutton", 0.0) {}
24 
PlusButton(const double x,const double y,const double width,const double height,const std::string & name,double defaultValue)25 PlusButton::PlusButton (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue) :
26 		Button (x, y, width, height, name, defaultValue) {}
27 
clone() const28 Widget* PlusButton::clone () const {return new PlusButton (*this);}
29 
draw(const BUtilities::RectArea & area)30 void PlusButton::draw (const BUtilities::RectArea& area)
31 {
32 	if ((!widgetSurface_) || (cairo_surface_status (widgetSurface_) != CAIRO_STATUS_SUCCESS)) return;
33 
34 	if ((getWidth () >= 6) && (getHeight () >= 6))
35 	{
36 
37 		Button::draw (area);
38 
39 		cairo_t* cr = cairo_create (widgetSurface_);
40 		if (cairo_status (cr) == CAIRO_STATUS_SUCCESS)
41 		{
42 			// Limit cairo-drawing area
43 			cairo_rectangle (cr, area.getX (), area.getY (), area.getWidth (), area.getHeight ());
44 			cairo_clip (cr);
45 
46 			double x0 = getXOffset ();
47 			double y0 = getYOffset ();
48 			double w = getEffectiveWidth ();
49 			double h = getEffectiveHeight ();
50 			double size = (w < h ? w * 0.6 : h * 0.6);
51 			BColors::Color butColor = *bgColors.getColor (getState ()); butColor.applyBrightness (BWIDGETS_DEFAULT_NORMALLIGHTED);
52 			BColors::Color frColor= *bgColors.getColor (getState ());
53 
54 			if (value) frColor.applyBrightness (2 * BWIDGETS_DEFAULT_ILLUMINATED);
55 			else frColor.applyBrightness (2 * BWIDGETS_DEFAULT_SHADOWED);
56 
57 			// Symbol
58 			cairo_set_line_width (cr, BWIDGETS_DEFAULT_BUTTON_BORDER);
59 			cairo_move_to (cr, x0 + w/2 - 0.375 * size, y0 + h/2);
60 			cairo_line_to (cr, x0 + w/2 + 0.375 * size, y0 + h/2);
61 			cairo_move_to (cr, x0 + w/2, y0 + h/2 - 0.375 * size);
62 			cairo_line_to (cr, x0 + w/2, y0 + h/2 + 0.375 * size);
63 			cairo_set_source_rgba (cr, CAIRO_RGBA (frColor));
64 			cairo_stroke (cr);
65 
66 			cairo_destroy (cr);
67 		}
68 	}
69 }
70 }
71