1 /* B.Jumblr
2  * Pattern-controlled audio stream / sample re-sequencer LV2 plugin
3  *
4  * Copyright (C) 2018, 2019 by Sven Jähnichen
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 3 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, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef BWIDGETS_LOADBUTTON_HPP_
21 #define BWIDGETS_LOADBUTTON_HPP_
22 
23 #include "BWidgets/Button.hpp"
24 
25 class LoadButton : public BWidgets::Button
26 {
27 public:
LoadButton()28 	LoadButton () : LoadButton (0.0, 0.0, BWIDGETS_DEFAULT_BUTTON_WIDTH, BWIDGETS_DEFAULT_BUTTON_HEIGHT, "loadbutton", 0.0) {}
LoadButton(const double x,const double y,const double width,const double height,const std::string & name,double defaultValue=0.0)29 	LoadButton (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue = 0.0) :
30 		Button (x, y, width, height, name, defaultValue) {}
31 
32 	/**
33 	 * Pattern cloning. Creates a new instance of the widget and copies all
34 	 * its properties.
35 	 */
clone() const36 	virtual Widget* clone () const override {return new LoadButton (*this);}
37 
38 protected:
draw(const BUtilities::RectArea & area)39 	virtual void draw (const BUtilities::RectArea& area) override
40 	{
41 		if ((!widgetSurface_) || (cairo_surface_status (widgetSurface_) != CAIRO_STATUS_SUCCESS)) return;
42 
43 		if ((getWidth () >= 6) && (getHeight () >= 6))
44 		{
45 
46 			Button::draw (area);
47 
48 			cairo_t* cr = cairo_create (widgetSurface_);
49 			if (cairo_status (cr) == CAIRO_STATUS_SUCCESS)
50 			{
51 				// Limit cairo-drawing area
52 				cairo_rectangle (cr, area.getX (), area.getY (), area.getWidth (), area.getHeight ());
53 				cairo_clip (cr);
54 
55 				double x0 = getXOffset ();
56 				double y0 = getYOffset ();
57 				double w = getEffectiveWidth ();
58 				double h = getEffectiveHeight ();
59 				double size = (w < h ? 0.8 * w : 0.8 * h);
60 				BColors::Color butColor = *bgColors.getColor (getState ()); butColor.applyBrightness (BWIDGETS_DEFAULT_NORMALLIGHTED);
61 				BColors::Color frColor= *bgColors.getColor (getState ());
62 
63 				if (value) frColor.applyBrightness (2 * BWIDGETS_DEFAULT_ILLUMINATED);
64 				else frColor.applyBrightness (2 * BWIDGETS_DEFAULT_SHADOWED);
65 
66 				// Symbol
67 				cairo_set_line_width (cr, BWIDGETS_DEFAULT_BUTTON_BORDER);
68 				cairo_move_to (cr, x0 + w/2, y0 + h/2 - 0.375 * size);
69 				cairo_line_to (cr, x0 + w/2 + 0.25 * size, y0 + h/2 - 0.125 * size);
70 				cairo_line_to (cr, x0 + w/2 + 0.15 * size, y0 + h/2 - 0.125 * size);
71 				cairo_line_to (cr, x0 + w/2 + 0.15 * size, y0 + h/2 + 0.25 * size);
72 				cairo_line_to (cr, x0 + w/2 - 0.15 * size, y0 + h/2 + 0.25 * size);
73 				cairo_line_to (cr, x0 + w/2 - 0.15 * size, y0 + h/2 - 0.125 * size);
74 				cairo_line_to (cr, x0 + w/2 - 0.25 * size, y0 + h/2 - 0.125 * size);
75 				cairo_close_path (cr);
76 
77 				cairo_move_to (cr, x0 + w/2 + 0.25 * size, y0 + h/2 + 0.125 * size);
78 				cairo_line_to (cr, x0 + w/2 + 0.375 * size, y0 + h/2 + 0.125 * size);
79 				cairo_line_to (cr, x0 + w/2 + 0.375 * size, y0 + h/2 + 0.375 * size);
80 				cairo_line_to (cr, x0 + w/2 - 0.375 * size, y0 + h/2 + 0.375 * size);
81 				cairo_line_to (cr, x0 + w/2 - 0.375 * size, y0 + h/2 + 0.125 * size);
82 				cairo_line_to (cr, x0 + w/2 - 0.25 * size, y0 + h/2 + 0.125 * size);
83 
84 				cairo_set_source_rgba (cr, CAIRO_RGBA (frColor));
85 				cairo_stroke (cr);
86 
87 				cairo_destroy (cr);
88 			}
89 		}
90 	}
91 };
92 
93 #endif /* BWIDGETS_LOADBUTTON_HPP_ */
94