1 /* HScale.hpp 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 #ifndef BWIDGETS_HSCALE_HPP_ 19 #define BWIDGETS_HSCALE_HPP_ 20 21 #include "RangeWidget.hpp" 22 23 #define BWIDGETS_DEFAULT_HSCALE_WIDTH 100.0 24 #define BWIDGETS_DEFAULT_HSCALE_HEIGHT 6.0 25 #define BWIDGETS_DEFAULT_HSCALE_DEPTH 1.0 26 27 namespace BWidgets 28 { 29 /** 30 * Class BWidgets::HScale 31 * 32 * RangeWidget class for a simple horizontal scale. 33 * The Widget is clickable by default. 34 */ 35 class HScale : public RangeWidget 36 { 37 public: 38 HScale (); 39 HScale (const double x, const double y, const double width, const double height, const std::string& name, 40 const double value, const double min, const double max, const double step); 41 42 /** 43 * Creates a new (orphan) scale and copies the scale properties from a 44 * source scale. This method doesn't copy any parent or child widgets. 45 * @param that Source scale 46 */ 47 HScale (const HScale& that); 48 49 /** 50 * Assignment. Copies the scale properties from a source scale and keeps 51 * its name and its position within the widget tree. Emits an expose event 52 * if the widget is visible and a value changed event. 53 * @param that Source slider 54 */ 55 HScale& operator= (const HScale& that); 56 57 /** 58 * Pattern cloning. Creates a new instance of the widget and copies all 59 * its properties. 60 */ 61 virtual Widget* clone () const override; 62 63 /** 64 * Calls a redraw of the widget and calls postRedisplay () if the the 65 * Widget is visible. 66 * This method should be called if the widgets properties are indirectly 67 * changed. 68 */ 69 virtual void update () override; 70 71 /** 72 * Scans theme for widget properties and applies these properties. 73 * @param theme Theme to be scanned. 74 * Styles used are: 75 * BWIDGETS_KEYWORD_BORDER 76 * BWIDGETS_KEYWORD_BACKGROUND 77 * BWIDGETS_KEYWORD_FGCOLORS 78 * BWIDGETS_KEYWORD_BGCOLORS 79 * @param name Name of the BStyles::StyleSet within the theme to be 80 * applied. 81 */ 82 virtual void applyTheme (BStyles::Theme& theme) override; 83 virtual void applyTheme (BStyles::Theme& theme, const std::string& name) override; 84 85 /** 86 * Handles the BEvents::BUTTON_PRESS_EVENT to move the slider. 87 * @param event Pointer to a pointer event emitted by the same widget. 88 */ 89 virtual void onButtonPressed (BEvents::PointerEvent* event) override; 90 91 /** 92 * Handles the BEvents::EventType::BUTTON_RELEASE_EVENT to move the slider. 93 * @param event Pointer event 94 */ 95 virtual void onButtonReleased (BEvents::PointerEvent* event) override; 96 97 /** 98 * Handles the BEvents::POINTER_DRAG_EVENT to move 99 * the slider. 100 * @param event Pointer to a pointer event emitted by the same widget. 101 */ 102 virtual void onPointerDragged (BEvents::PointerEvent* event) override; 103 104 /** 105 * Handles the BEvents::WHEEL_SCROLL_EVENT to turn 106 * the dial. 107 * @param event Pointer to a wheel event emitted by the same widget. 108 */ 109 virtual void onWheelScrolled (BEvents::WheelEvent* event) override; 110 111 protected: 112 virtual void updateCoords (); 113 virtual void draw (const BUtilities::RectArea& area) override; 114 115 BColors::ColorSet fgColors; 116 BColors::ColorSet bgColors; 117 118 BUtilities::RectArea scaleArea; 119 double scaleXValue; 120 }; 121 122 } 123 124 #endif /* BWIDGETS_HSCALE_HPP_ */ 125