1 /* B.Harvestr 2 * Beat / envelope shaper LV2 plugin 3 * 4 * Copyright (C) 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 STOPBUTTON_HPP_ 21 #define STOPBUTTON_HPP_ 22 23 #include "BWidgets/Button.hpp" 24 25 class StopButton : public BWidgets::Button 26 { 27 public: StopButton()28 StopButton () : StopButton (0.0, 0.0, BWIDGETS_DEFAULT_BUTTON_WIDTH, BWIDGETS_DEFAULT_BUTTON_HEIGHT, "button", 0.0) {} 29 StopButton(const double x,const double y,const double width,const double height,const std::string & name,double defaultValue=0.0)30 StopButton (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue = 0.0) : 31 Button (x, y, width, height, name, defaultValue) {} 32 clone() const33 virtual Widget* clone () const override {return new StopButton (*this);} 34 35 protected: draw(const BUtilities::RectArea & area)36 virtual void draw (const BUtilities::RectArea& area) override 37 { 38 if ((!widgetSurface_) || (cairo_surface_status (widgetSurface_) != CAIRO_STATUS_SUCCESS)) return; 39 40 if ((getWidth () >= 6) && (getHeight () >= 6)) 41 { 42 43 Button::draw (area); 44 45 cairo_t* cr = cairo_create (widgetSurface_); 46 if (cairo_status (cr) == CAIRO_STATUS_SUCCESS) 47 { 48 // Limit cairo-drawing area 49 cairo_rectangle (cr, area.getX (), area.getY (), area.getWidth (), area.getHeight ()); 50 cairo_clip (cr); 51 52 double x0 = getXOffset (); 53 double y0 = getYOffset (); 54 double w = getEffectiveWidth (); 55 double h = getEffectiveHeight (); 56 double size = (w < h ? w * 0.6 : h * 0.6); 57 BColors::Color butColor = *bgColors.getColor (getState ()); butColor.applyBrightness (BWIDGETS_DEFAULT_NORMALLIGHTED); 58 BColors::Color frColor= *bgColors.getColor (getState ()); 59 60 if (value) frColor.applyBrightness (2 * BWIDGETS_DEFAULT_ILLUMINATED); 61 else frColor.applyBrightness (2 * BWIDGETS_DEFAULT_SHADOWED); 62 63 // Symbol 64 cairo_set_line_width (cr, BWIDGETS_DEFAULT_BUTTON_BORDER); 65 cairo_move_to (cr, x0 + w/2 - size/4, y0 + h/2 - size/4); 66 cairo_line_to (cr, x0 + w/2 + size/4, y0 + h/2 - size/4); 67 cairo_line_to (cr, x0 + w/2 + size/4, y0 + h/2 + size/4); 68 cairo_line_to (cr, x0 + w/2 - size/4, y0 + h/2 + size/4); 69 cairo_close_path (cr); 70 cairo_set_source_rgba (cr, CAIRO_RGBA (frColor)); 71 cairo_fill (cr); 72 73 cairo_destroy (cr); 74 } 75 } 76 } 77 }; 78 79 #endif /* STOPBUTTON_HPP_ */ 80