1 /* B.Shapr 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, or (at your option) 9 * 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 Foundation, 18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 */ 20 21 #ifndef EDITWIDGET_HPP_ 22 #define EDITWIDGET_HPP_ 23 24 #include "BWidgets/Widget.hpp" 25 #include "BWidgets/Focusable.hpp" 26 #include "BWidgets/Label.hpp" 27 28 class EditWidget : public BWidgets::Widget, public BWidgets::Focusable 29 { 30 public: EditWidget()31 EditWidget () : EditWidget (0, 0, 0, 0, "editwidget", "") {} 32 EditWidget(const double x,const double y,const double width,const double height,const std::string & name,const std::string & focusText)33 EditWidget (const double x, const double y, const double width, const double height, const std::string& name, const std::string& focusText) : 34 Widget (x, y, width, height, name), 35 Focusable (std::chrono::milliseconds (BWIDGETS_DEFAULT_FOCUS_IN_MS), 36 std::chrono::milliseconds (BWIDGETS_DEFAULT_FOCUS_OUT_MS)), 37 focusLabel_ (0, 0, 40, 20, name_ + BWIDGETS_DEFAULT_FOCUS_NAME, focusText) 38 { 39 focusLabel_.setStacking (BWidgets::STACKING_OVERSIZE); 40 focusLabel_.resize (); 41 focusLabel_.hide (); 42 add (focusLabel_); 43 } 44 EditWidget(const EditWidget & that)45 EditWidget (const EditWidget& that) : 46 Widget (that), Focusable (that), 47 focusLabel_ (that.focusLabel_) 48 { 49 focusLabel_.hide(); 50 add (focusLabel_); 51 } 52 operator =(const EditWidget & that)53 EditWidget& operator= (const EditWidget& that) 54 { 55 release (&focusLabel_); 56 focusLabel_ = that.focusLabel_; 57 focusLabel_.hide(); 58 59 Widget::operator= (that); 60 Focusable::operator= (that); 61 62 add (focusLabel_); 63 64 return *this; 65 66 } 67 applyTheme(BStyles::Theme & theme)68 virtual void applyTheme (BStyles::Theme& theme) override {applyTheme (theme, name_);} 69 applyTheme(BStyles::Theme & theme,const std::string & name)70 virtual void applyTheme (BStyles::Theme& theme, const std::string& name) override 71 { 72 Widget::applyTheme (theme, name); 73 focusLabel_.applyTheme (theme, name + BWIDGETS_DEFAULT_FOCUS_NAME); 74 focusLabel_.resize(); 75 } 76 onFocusIn(BEvents::FocusEvent * event)77 virtual void onFocusIn (BEvents::FocusEvent* event) override 78 { 79 if (event && event->getWidget()) 80 { 81 BUtilities::Point pos = event->getPosition(); 82 focusLabel_.moveTo (pos.x - 0.5 * focusLabel_.getWidth(), pos.y - focusLabel_.getHeight()); 83 focusLabel_.show(); 84 } 85 Widget::onFocusIn (event); 86 } 87 onFocusOut(BEvents::FocusEvent * event)88 virtual void onFocusOut (BEvents::FocusEvent* event) override 89 { 90 if (event && event->getWidget()) focusLabel_.hide(); 91 Widget::onFocusOut (event); 92 } 93 94 protected: 95 BWidgets::Label focusLabel_; 96 }; 97 98 #endif /* EDITWIDGET_HPP_ */ 99