├── .gitignore ├── BSpacr.cpp ├── BSpacr.ttl ├── BSpacr_GUI.cpp ├── BUtilities ├── Any.hpp ├── Path.hpp ├── Point.hpp ├── RectArea.hpp ├── mix.hpp ├── stof.cpp ├── stof.hpp ├── to_string.cpp └── to_string.hpp ├── BWidgets ├── BColors.cpp ├── BColors.hpp ├── BDevices.hpp ├── BEvents.hpp ├── BItems.cpp ├── BItems.hpp ├── BStyles.cpp ├── BStyles.hpp ├── BWidgets.hpp ├── Button.cpp ├── Button.hpp ├── ChoiceBox.cpp ├── ChoiceBox.hpp ├── Dial.cpp ├── Dial.hpp ├── DialValue.cpp ├── DialValue.hpp ├── Display.cpp ├── Display.hpp ├── DownButton.cpp ├── DownButton.hpp ├── DrawingSurface.cpp ├── DrawingSurface.hpp ├── FileChooser.cpp ├── FileChooser.hpp ├── Focusable.hpp ├── HPianoRoll.cpp ├── HPianoRoll.hpp ├── HScale.cpp ├── HScale.hpp ├── HSlider.cpp ├── HSlider.hpp ├── HSliderValue.cpp ├── HSliderValue.hpp ├── HSwitch.cpp ├── HSwitch.hpp ├── Icon.cpp ├── Icon.hpp ├── ImageIcon.cpp ├── ImageIcon.hpp ├── ItemBox.cpp ├── ItemBox.hpp ├── Knob.cpp ├── Knob.hpp ├── Label.cpp ├── Label.hpp ├── LeftButton.cpp ├── LeftButton.hpp ├── ListBox.cpp ├── ListBox.hpp ├── MessageBox.cpp ├── MessageBox.hpp ├── MinusButton.cpp ├── MinusButton.hpp ├── PianoWidget.cpp ├── PianoWidget.hpp ├── PlusButton.cpp ├── PlusButton.hpp ├── PopupListBox.cpp ├── PopupListBox.hpp ├── RangeWidget.cpp ├── RangeWidget.hpp ├── RightButton.cpp ├── RightButton.hpp ├── StateDisplay.cpp ├── StateDisplay.hpp ├── Text.cpp ├── Text.hpp ├── TextButton.cpp ├── TextButton.hpp ├── TextToggleButton.cpp ├── TextToggleButton.hpp ├── ToggleButton.cpp ├── ToggleButton.hpp ├── UpButton.cpp ├── UpButton.hpp ├── VScale.cpp ├── VScale.hpp ├── VSlider.cpp ├── VSlider.hpp ├── VSliderValue.cpp ├── VSliderValue.hpp ├── VSwitch.cpp ├── VSwitch.hpp ├── ValueWidget.cpp ├── ValueWidget.hpp ├── Widget.cpp ├── Widget.hpp ├── Window.cpp ├── Window.hpp ├── cairoplus.c ├── cairoplus.h ├── pugl │ ├── .clang-tidy │ ├── AUTHORS │ ├── COPYING │ ├── README.md │ ├── implementation.c │ ├── implementation.h │ ├── mac.h │ ├── mac.m │ ├── mac_cairo.m │ ├── mac_gl.m │ ├── mac_stub.m │ ├── mac_vulkan.m │ ├── pugl │ │ ├── cairo.h │ │ ├── gl.h │ │ ├── pugl.h │ │ ├── stub.h │ │ └── vulkan.h │ ├── stub.h │ ├── types.h │ ├── win.c │ ├── win.h │ ├── win_cairo.c │ ├── win_gl.c │ ├── win_stub.c │ ├── win_vulkan.c │ ├── x11.c │ ├── x11.h │ ├── x11_cairo.c │ ├── x11_gl.c │ ├── x11_stub.c │ └── x11_vulkan.c └── pugl_cairo_test.c ├── Definitions.hpp ├── LICENSE ├── Ports.hpp ├── README.md ├── makefile ├── manifest.ttl ├── surface.png └── surface.svg /.gitignore: -------------------------------------------------------------------------------- 1 | /BSpacr.lv2/** 2 | -------------------------------------------------------------------------------- /BSpacr.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "Definitions.hpp" 5 | #include "Ports.hpp" 6 | 7 | class BSpacr { 8 | public: 9 | BSpacr (); 10 | void run (uint32_t n_samples); 11 | void connect_port (uint32_t portnr, float* data); 12 | 13 | private: 14 | std::array port; 15 | }; 16 | 17 | BSpacr::BSpacr () 18 | { 19 | port.fill (NULL); 20 | } 21 | 22 | void BSpacr::connect_port (uint32_t portnr, float* data) 23 | { 24 | if (portnr < BSPACR_N_PORTS) port [portnr] = data; 25 | } 26 | 27 | void BSpacr::run (uint32_t n_samples) 28 | { 29 | for (int i = 0; i < BSPACR_N_PORTS; ++i) 30 | { 31 | if (!port[i]) return; 32 | } 33 | 34 | const float* const input1 = port[BSPACR_INPUT]; 35 | const float* const input2 = port[BSPACR_INPUT + 1]; 36 | float* const output1 = port[BSPACR_OUTPUT]; 37 | float* const output2 = port[BSPACR_OUTPUT + 1]; 38 | 39 | for (uint32_t i = 0; i < n_samples; ++i) 40 | { 41 | output1[i] = input1[i]; 42 | output2[i] = input2[i]; 43 | } 44 | } 45 | 46 | static LV2_Handle 47 | instantiate(const LV2_Descriptor* descriptor, double rate, 48 | const char* bundle_path, const LV2_Feature* const* features) 49 | { 50 | BSpacr* instance = new BSpacr (); 51 | return (LV2_Handle) instance; 52 | } 53 | 54 | static void 55 | connect_port(LV2_Handle instance, uint32_t port, void* data) 56 | { 57 | BSpacr* bSpacr = (BSpacr*)instance; 58 | if (bSpacr) bSpacr->connect_port (port, (float*) data); 59 | } 60 | 61 | static void 62 | run(LV2_Handle instance, uint32_t n_samples) 63 | { 64 | BSpacr* bSpacr = (BSpacr*) instance; 65 | if (bSpacr) bSpacr->run (n_samples); 66 | } 67 | 68 | static void 69 | cleanup(LV2_Handle instance) 70 | { 71 | BSpacr* bSpacr = (BSpacr*) instance; 72 | if (bSpacr) delete bSpacr; 73 | } 74 | 75 | static const LV2_Descriptor descriptor = 76 | { 77 | BSPACR_URI, 78 | instantiate, 79 | connect_port, 80 | NULL, 81 | run, 82 | NULL, 83 | cleanup, 84 | NULL 85 | }; 86 | 87 | LV2_SYMBOL_EXPORT 88 | const LV2_Descriptor* 89 | lv2_descriptor(uint32_t index) 90 | { 91 | switch (index) 92 | { 93 | case 0: return &descriptor; 94 | default: return NULL; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /BSpacr.ttl: -------------------------------------------------------------------------------- 1 | @prefix lv2: . 2 | @prefix foaf: . 3 | @prefix doap: . 4 | @prefix ui: . 5 | 6 | 7 | a ui:X11UI ; 8 | lv2:binary ; 9 | lv2:extensionData ui:idleInterface , ui:resize ; 10 | lv2:optionalFeature ui:resize ; 11 | lv2:requiredFeature ui:idleInterface . 12 | 13 | a lv2:Plugin ; 14 | a lv2:Plugin, lv2:AmplifierPlugin, doap:Project; 15 | doap:name "B.Spacr"; 16 | doap:license ; 17 | lv2:binary ; 18 | lv2:microVersion 0 ; 19 | lv2:minorVersion 2 ; 20 | ui:ui ; 21 | lv2:optionalFeature lv2:hardRTCapable ; 22 | lv2:port [ 23 | a lv2:AudioPort ; 24 | a lv2:InputPort ; 25 | lv2:index 0 ; 26 | lv2:symbol "in_1" ; 27 | lv2:name "In 1" 28 | ] , [ 29 | a lv2:AudioPort ; 30 | a lv2:InputPort ; 31 | lv2:index 1 ; 32 | lv2:symbol "in_2" ; 33 | lv2:name "In 2" 34 | ] , [ 35 | a lv2:AudioPort ; 36 | a lv2:OutputPort ; 37 | lv2:index 2 ; 38 | lv2:symbol "out_1" ; 39 | lv2:name "Out 1" 40 | ] , [ 41 | a lv2:AudioPort ; 42 | a lv2:OutputPort ; 43 | lv2:index 3 ; 44 | lv2:symbol "out_2" ; 45 | lv2:name "Out 2" 46 | ] , [ 47 | a lv2:InputPort , lv2:ControlPort ; 48 | lv2:index 4 ; 49 | lv2:symbol "mix" ; 50 | lv2:name "Mix" ; 51 | lv2:default 1.0 ; 52 | lv2:minimum 0.0 ; 53 | lv2:maximum 1.0 54 | ] . 55 | -------------------------------------------------------------------------------- /BUtilities/Any.hpp: -------------------------------------------------------------------------------- 1 | /* Any.hpp 2 | * Copyright (C) 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 . 16 | */ 17 | 18 | #ifndef BUTILITIES_ANY_HPP_ 19 | #define BUTILITIES_ANY_HPP_ 20 | 21 | #include 22 | #include 23 | 24 | namespace BUtilities 25 | { 26 | 27 | class Any 28 | { 29 | protected: 30 | struct Envelope 31 | { 32 | virtual ~Envelope () {} 33 | virtual Envelope* clone () {return new Envelope (*this);} 34 | }; 35 | 36 | template struct Data : Envelope 37 | { 38 | Data (const T& t) : data (t) {} 39 | virtual ~Data () {} 40 | virtual Envelope* clone () override {return new Data (*this);} 41 | T data; 42 | }; 43 | 44 | Envelope* dataptr = nullptr; 45 | size_t dataTypeHash = typeid (void).hash_code (); 46 | 47 | Envelope* clone () const 48 | { 49 | if (dataptr == nullptr) return nullptr; 50 | return dataptr->clone (); 51 | } 52 | 53 | public: 54 | Any () {} 55 | Any (const Any& that) : dataTypeHash (that.dataTypeHash) 56 | {dataptr = that.clone ();} 57 | 58 | ~Any () {if (dataptr) delete dataptr;} 59 | 60 | Any& operator= (const Any& that) 61 | { 62 | if (dataptr) delete dataptr; 63 | dataptr = that.clone (); 64 | dataTypeHash = that.dataTypeHash; 65 | return *this; 66 | } 67 | 68 | template void set (const T& t) 69 | { 70 | if (dataptr) delete dataptr; 71 | dataptr = new Data (t); 72 | dataTypeHash = typeid (T).hash_code (); 73 | } 74 | 75 | template T get () const 76 | { 77 | if ((!dataptr) || (typeid (T).hash_code () != dataTypeHash)) return T (); // Return () better throw exception 78 | return ((Data*)dataptr)->data; 79 | } 80 | 81 | }; 82 | 83 | template Any makeAny (const T& t) 84 | { 85 | Any a; 86 | a.set (t); 87 | return a; 88 | } 89 | 90 | } 91 | 92 | #endif /* BUTILITIES_ANY_HPP_ */ 93 | -------------------------------------------------------------------------------- /BUtilities/Path.hpp: -------------------------------------------------------------------------------- 1 | /* Path.hpp 2 | * Copyright (C) 2021 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 PATH 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 . 16 | */ 17 | 18 | #ifndef BUTILITIES_PATH_HPP_ 19 | #define BUTILITIES_PATH_HPP_ 20 | 21 | #include 22 | 23 | #ifdef _WIN32 24 | #define BUTILITIES_PATH_SLASH "\\" 25 | #else 26 | #define BUTILITIES_PATH_SLASH "/" 27 | #endif 28 | 29 | namespace BUtilities 30 | { 31 | 32 | class Path 33 | { 34 | public: 35 | Path () : dir_(), file_(), ext_() {} 36 | Path (const std::string& path) {split (path);} 37 | 38 | Path& operator= (const std::string& path) 39 | { 40 | split (path); 41 | return *this; 42 | } 43 | 44 | operator std::string() const {return (dir().empty() || (dir() == BUTILITIES_PATH_SLASH) ? dir() : dir() + BUTILITIES_PATH_SLASH) + filename();} 45 | 46 | std::string dir() const {return dir_;} 47 | std::string filename() const {return file_ + (ext_.empty() ? "" : "." + ext_);} 48 | std::string ext() const {return ext_;} 49 | 50 | protected: 51 | std::string dir_; 52 | std::string file_; 53 | std::string ext_; 54 | 55 | void split (const std::string& path) 56 | { 57 | const size_t spos = path.find_last_of (BUTILITIES_PATH_SLASH); 58 | if (spos == std::string::npos) dir_ = ""; 59 | else if (spos == 0) dir_ = BUTILITIES_PATH_SLASH; 60 | else dir_ = path.substr (0, spos); 61 | 62 | file_ = path.substr (spos + 1); 63 | 64 | if (file_ == "") ext_ = ""; 65 | 66 | else if ((file_ == ".") || (file_ == "..")) 67 | { 68 | dir_ = (dir_.empty() || (dir_ == BUTILITIES_PATH_SLASH) ? dir_ : dir_ + BUTILITIES_PATH_SLASH) + file_; 69 | file_ = ""; 70 | ext_ = ""; 71 | } 72 | 73 | else 74 | { 75 | const size_t dpos = file_.find_last_of ("."); 76 | if ((dpos != std::string::npos) && (dpos != 0)) 77 | { 78 | ext_ = file_.substr (dpos + 1); 79 | file_ = file_.substr (0, dpos); 80 | } 81 | 82 | else ext_ = ""; 83 | 84 | } 85 | } 86 | 87 | 88 | }; 89 | 90 | } 91 | 92 | #endif /* BUTILITIES_PATH_HPP_ */ 93 | -------------------------------------------------------------------------------- /BUtilities/Point.hpp: -------------------------------------------------------------------------------- 1 | /* Point.hpp 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 BUTILITIES_POINT_HPP_ 22 | #define BUTILITIES_POINT_HPP_ 23 | 24 | namespace BUtilities 25 | { 26 | 27 | struct Point 28 | { 29 | double x, y; 30 | 31 | Point () : Point (0, 0) {} 32 | Point (double x, double y) : x (x), y (y) {} 33 | 34 | Point& operator+= (const Point& rhs) 35 | { 36 | this->x += rhs.x; 37 | this->y += rhs.y; 38 | return *this; 39 | } 40 | 41 | Point& operator-= (const Point& rhs) 42 | { 43 | this->x -= rhs.x; 44 | this->y -= rhs.y; 45 | return *this; 46 | } 47 | 48 | friend bool operator== (const Point& lhs, const Point& rhs) {return ((lhs.x == rhs.x) && (lhs.y == rhs.y));} 49 | friend bool operator!= (const Point& lhs, const Point& rhs) {return !(lhs == rhs);} 50 | friend Point operator+ (Point lhs, const Point& rhs) {return (lhs += rhs);} 51 | friend Point operator- (Point lhs, const Point& rhs) {return (lhs -= rhs);} 52 | 53 | }; 54 | 55 | } 56 | 57 | #endif /* BUTILITIES_POINT_HPP_ */ 58 | -------------------------------------------------------------------------------- /BUtilities/RectArea.hpp: -------------------------------------------------------------------------------- 1 | /* RectArea.hpp 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 BUTILITIES_RECTAREA_HPP_ 22 | #define BUTILITIES_RECTAREA_HPP_ 23 | 24 | #include "Point.hpp" 25 | 26 | namespace BUtilities 27 | { 28 | 29 | class RectArea 30 | { 31 | protected: 32 | Point p1, p2; 33 | 34 | public: 35 | RectArea () : RectArea (Point (), Point ()) {} 36 | RectArea (const double x1, const double y1, const double width, const double height) : 37 | RectArea (Point (x1, y1), Point (x1 + width, y1 + height)) {} 38 | RectArea (const Point& p1, const Point& p2) : 39 | p1 (Point ((p1.x < p2.x ? p1.x : p2.x), (p1.y < p2.y ? p1.y : p2.y))), 40 | p2 (Point ((p1.x > p2.x ? p1.x : p2.x), (p1.y > p2.y ? p1.y : p2.y))) 41 | {} 42 | 43 | Point getPosition () const {return p1;} 44 | double getX () const {return p1.x;} 45 | double getY () const {return p1.y;} 46 | 47 | Point getExtends () const {return Point (p2.x - p1.x, p2.y - p1.y);} 48 | double getWidth () const {return (p2.x - p1.x);} 49 | double getHeight () const {return (p2.y - p1.y);} 50 | 51 | void setX (const double x) {moveTo (x, getY());} 52 | void setY (const double y) {moveTo (getX(), y);} 53 | void moveTo (const double x, const double y) {moveTo (Point (x, y));} 54 | void moveTo (const Point& position) 55 | { 56 | p2 = p2 - p1 + position; 57 | p1 = position; 58 | } 59 | 60 | void setWidth (const double width) {resize (width, getHeight());} 61 | void setHeight (const double height) {resize (getWidth(), height);} 62 | void resize (const double width, const double height) {resize (Point (width, height));} 63 | void resize (const Point& extends) {p2 = p1 + extends;} 64 | 65 | bool contains (const Point& p) const 66 | { 67 | return ((p.x > p1.x) && (p.x < p2.x) && (p.y > p1.y) && (p.y < p2.y)); 68 | } 69 | 70 | bool includes (const RectArea& ra) const 71 | { 72 | return ((ra.p1.x >= p1.x) && (ra.p1.y >= p1.y) && (ra.p2.x <= p2.x) && (ra.p2.y <= p2.y)); 73 | } 74 | 75 | bool overlaps (const RectArea& ra) const 76 | { 77 | return !((ra.p2.x < p1.x) || (ra.p2.y < p1.y) || (ra.p1.x > p2.x) || (ra.p1.y > p2.y)); 78 | } 79 | 80 | void extend (const RectArea& ra) 81 | { 82 | if (*this == RectArea ()) *this = ra; 83 | else if (ra != RectArea ()) 84 | { 85 | p1 = Point ((p1.x < ra.p1.x ? p1.x : ra.p1.x), (p1.y < ra.p1.y ? p1.y : ra.p1.y)); 86 | p2 = Point ((p2.x > ra.p2.x ? p2.x : ra.p2.x), (p2.y > ra.p2.y ? p2.y : ra.p2.y)); 87 | } 88 | } 89 | 90 | void intersect (const RectArea& ra) 91 | { 92 | if ((*this == RectArea ()) || (ra == RectArea ()) || (!overlaps (ra))) *this = RectArea (); 93 | 94 | else 95 | { 96 | double x1 = (ra.p1.x < p1.x ? p1.x : ra.p1.x); 97 | double y1 = (ra.p1.y < p1.y ? p1.y : ra.p1.y); 98 | double x2 = (ra.p2.x > p2.x ? p2.x : ra.p2.x); 99 | double y2 = (ra.p2.y > p2.y ? p2.y : ra.p2.y); 100 | p1 = Point (x1, y1); 101 | p2 = Point (x2, y2); 102 | } 103 | } 104 | 105 | RectArea& operator+= (const RectArea& rhs) 106 | { 107 | this->extend (rhs); 108 | return *this; 109 | } 110 | 111 | RectArea& operator*= (const RectArea& rhs) 112 | { 113 | this->intersect (rhs); 114 | return *this; 115 | } 116 | 117 | friend bool operator== (const RectArea& lhs, const RectArea& rhs) 118 | { 119 | return ((lhs.p1 == rhs.p1) && (lhs.p2 == rhs.p2)); 120 | } 121 | 122 | friend bool operator!= (const RectArea& lhs, const RectArea& rhs) {return !(lhs == rhs);} 123 | friend RectArea operator+ (RectArea lhs, const RectArea& rhs) {return (lhs += rhs);} 124 | friend RectArea operator* (RectArea lhs, const RectArea& rhs) {return (lhs *= rhs);} 125 | 126 | }; 127 | 128 | } 129 | 130 | #endif /* BUTILITIES_RECTAREA_HPP_ */ 131 | -------------------------------------------------------------------------------- /BUtilities/mix.hpp: -------------------------------------------------------------------------------- 1 | /* mix.hpp 2 | * Copyright (C) 2020 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 . 16 | */ 17 | 18 | #ifndef BUTILITIES_MIX_HPP_ 19 | #define BUTILITIES_MIX_HPP_ 20 | 21 | namespace BUtilities { 22 | 23 | template inline T mix (const T& t0, const T& t1, const double ratio) 24 | { 25 | return t1 * ratio + t0 * (1.0f - ratio); 26 | } 27 | 28 | } 29 | 30 | #endif /* BUTILITIES_MIX_HPP_ */ 31 | -------------------------------------------------------------------------------- /BUtilities/stof.cpp: -------------------------------------------------------------------------------- 1 | /* stof.cpp 2 | * Copyright (C) 2020 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 . 16 | */ 17 | 18 | #include "stof.hpp" 19 | #include 20 | 21 | namespace BUtilities { 22 | 23 | float stof (const std::string& str, size_t* idx) 24 | { 25 | const std::string numbers = "0123456789"; 26 | bool isNumber = false; 27 | float sign = 1.0f; 28 | float predec = 0.0f; 29 | float dec = 0.0f; 30 | float decfac = 0.1f; 31 | size_t i = 0; 32 | 33 | // Ignore spaces before 34 | while (str[i] == ' ') ++i; 35 | 36 | // Check sign 37 | if ((str[i] == '+') || (str[i] == '-')) 38 | { 39 | if (str[i] == '-') sign = -1.0f; 40 | ++i; 41 | } 42 | 43 | // Interpret pre-decimal digits 44 | while ((str[i] != 0) && (numbers.find_first_of (str[i]) != std::string::npos)) 45 | { 46 | predec = predec * 10.0f + str[i] - '0'; 47 | ++i; 48 | isNumber = true; 49 | } 50 | 51 | // Check decimal sign 52 | if ((str[i] == '.') || (str[i] == ',')) 53 | { 54 | ++i; 55 | 56 | // Interpret decimal digits 57 | while ((str[i] != 0) && (numbers.find_first_of (str[i]) != std::string::npos)) 58 | { 59 | dec += (str[i] - '0') * decfac; 60 | decfac *= 0.1f; 61 | ++i; 62 | isNumber = true; 63 | } 64 | } 65 | 66 | // Communicate next position 67 | if (idx != nullptr) *idx = i; 68 | 69 | // Not a number: invalid argument exception 70 | if (!isNumber) throw std::invalid_argument (str + " is not a number"); 71 | 72 | return sign * (predec + dec); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /BUtilities/stof.hpp: -------------------------------------------------------------------------------- 1 | /* stof.hpp 2 | * Copyright (C) 2020 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 . 16 | */ 17 | 18 | #ifndef BUTILITIES_STOF_HPP_ 19 | #define BUTILITIES_STOF_HPP_ 20 | 21 | #include 22 | #include 23 | 24 | namespace BUtilities { 25 | 26 | float stof (const std::string& str, size_t* idx = 0); 27 | 28 | } 29 | 30 | #endif /* BUTILITIES_STOF_HPP_ */ 31 | -------------------------------------------------------------------------------- /BUtilities/to_string.cpp: -------------------------------------------------------------------------------- 1 | /* to_string.cpp 2 | * Copyright (C) 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 . 16 | */ 17 | 18 | #include "to_string.hpp" 19 | #include 20 | 21 | namespace BUtilities { 22 | 23 | std::string to_string (const double value) 24 | { 25 | std::ostringstream os; 26 | os << value; 27 | std::string str = os.str(); 28 | return str; 29 | } 30 | 31 | std::string to_string (const double value, const std::string& format) 32 | { 33 | char c[64]; 34 | snprintf (c, 64, format.c_str (), value); 35 | std::string str = c; 36 | return c; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /BUtilities/to_string.hpp: -------------------------------------------------------------------------------- 1 | /* to_string.hpp 2 | * Copyright (C) 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 . 16 | */ 17 | 18 | #ifndef BUTILITIES_TO_STRING_HPP_ 19 | #define BUTILITIES_TO_STRING_HPP_ 20 | 21 | #include 22 | 23 | namespace BUtilities { 24 | 25 | std::string to_string (const double value); 26 | std::string to_string (const double value, const std::string& format); 27 | 28 | } 29 | 30 | #endif /* BUTILITIES_TO_STRING_HPP_ */ 31 | -------------------------------------------------------------------------------- /BWidgets/BItems.hpp: -------------------------------------------------------------------------------- 1 | /* BItems.hpp 2 | * Copyright (C) 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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_BITEMS_HPP_ 19 | #define BWIDGETS_BITEMS_HPP_ 20 | 21 | #include 22 | #include 23 | #include "Widget.hpp" 24 | #include 25 | 26 | #ifndef UNSELECTED 27 | #define UNSELECTED -HUGE_VAL 28 | #define BITEMS_DEFAULT_TEXT_PADDING 4.0 29 | #endif 30 | 31 | namespace BItems 32 | { 33 | 34 | class Item 35 | { 36 | public: 37 | Item (); 38 | Item (const double value, BWidgets::Widget* widget); 39 | Item (const double value, const std::string& text); 40 | Item (const Item& that); 41 | 42 | ~Item (); 43 | 44 | Item& operator= (const Item& that); 45 | 46 | void setValue (const double value); 47 | double getValue () const; 48 | void setWidget (BWidgets::Widget* widget); 49 | void setWidget (const std::string& text); 50 | void cloneWidgetFrom (BWidgets::Widget* widget); 51 | BWidgets::Widget* getWidget () const; 52 | 53 | protected: 54 | void deleteInternal (); 55 | 56 | double value; 57 | BWidgets::Widget* widget; 58 | BWidgets::Widget* internal; 59 | }; 60 | 61 | class ItemList : private std::list 62 | { 63 | public: 64 | ItemList (); 65 | ItemList (const Item& item); 66 | ItemList (const std::list& items); 67 | ItemList (BWidgets::Widget* widget); 68 | ItemList (const std::initializer_list& widgets); 69 | ItemList (const std::string& text); 70 | ItemList (const std::initializer_list& texts); 71 | 72 | using std::list::operator=; 73 | using std::list::begin; 74 | using std::list::end; 75 | using std::list::size; 76 | using std::list::empty; 77 | using std::list::front; 78 | using std::list::back; 79 | using std::list::pop_back; 80 | using std::list::pop_front; 81 | using std::list::erase; 82 | using std::list::iterator; 83 | 84 | void push_back (const Item& item); 85 | void push_back (BWidgets::Widget* widget); 86 | void push_back (const std::string& text); 87 | // TODO void push_front 88 | // TODO iterator insert 89 | 90 | Item* getItem (const double value); 91 | // TODO renumber 92 | 93 | protected: 94 | double getNextValue () const; 95 | }; 96 | 97 | } 98 | 99 | #endif /* BWIDGETS_BITEMS_HPP_ */ 100 | -------------------------------------------------------------------------------- /BWidgets/BWidgets.hpp: -------------------------------------------------------------------------------- 1 | /* BWidgets.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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_HPP_ 19 | #define BWIDGETS_HPP_ 20 | 21 | #include "Window.hpp" 22 | #include "Display.hpp" 23 | #include "StateDisplay.hpp" 24 | #include "Label.hpp" 25 | #include "Text.hpp" 26 | #include "Knob.hpp" 27 | #include "ValueWidget.hpp" 28 | #include "RangeWidget.hpp" 29 | #include "HScale.hpp" 30 | #include "HSlider.hpp" 31 | #include "VScale.hpp" 32 | #include "VSlider.hpp" 33 | #include "Dial.hpp" 34 | #include "DialValue.hpp" 35 | #include "HSliderValue.hpp" 36 | #include "VSliderValue.hpp" 37 | #include "Button.hpp" 38 | #include "ToggleButton.hpp" 39 | #include "TextButton.hpp" 40 | #include "TextToggleButton.hpp" 41 | #include "UpButton.hpp" 42 | #include "DownButton.hpp" 43 | #include "LeftButton.hpp" 44 | #include "RightButton.hpp" 45 | #include "PlusButton.hpp" 46 | #include "MinusButton.hpp" 47 | #include "HSwitch.hpp" 48 | #include "VSwitch.hpp" 49 | #include "DrawingSurface.hpp" 50 | #include "MessageBox.hpp" 51 | #include "ChoiceBox.hpp" 52 | #include "ListBox.hpp" 53 | #include "ItemBox.hpp" 54 | #include "PopupListBox.hpp" 55 | #include "PianoWidget.hpp" 56 | #include "HPianoRoll.hpp" 57 | #include "Icon.hpp" 58 | #include "ImageIcon.hpp" 59 | #include "FileChooser.hpp" 60 | 61 | #endif /*BWIDGETS_HPP_*/ 62 | -------------------------------------------------------------------------------- /BWidgets/Button.cpp: -------------------------------------------------------------------------------- 1 | /* Button.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 . 16 | */ 17 | 18 | #include "Button.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | Button::Button () : Button (0.0, 0.0, BWIDGETS_DEFAULT_BUTTON_WIDTH, BWIDGETS_DEFAULT_BUTTON_HEIGHT, "button", 0.0) {} 23 | 24 | Button::Button (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue) : 25 | ValueWidget (x, y, width, height, name, defaultValue), 26 | bgColors (BWIDGETS_DEFAULT_BGCOLORS) 27 | { 28 | setClickable (true); 29 | } 30 | 31 | Button::Button (const Button& that) : ValueWidget (that), bgColors (that.bgColors) {} 32 | 33 | Button:: ~Button () {} 34 | 35 | Button& Button::operator= (const Button& that) 36 | { 37 | bgColors = that.bgColors; 38 | ValueWidget::operator= (that); 39 | return *this; 40 | } 41 | 42 | Widget* Button::clone () const {return new Button (*this);} 43 | 44 | void Button::applyTheme (BStyles::Theme& theme) {applyTheme (theme, name_);} 45 | 46 | void Button::applyTheme (BStyles::Theme& theme, const std::string& name) 47 | { 48 | Widget::applyTheme (theme, name); 49 | 50 | void* bgPtr = theme.getStyle(name, BWIDGETS_KEYWORD_BGCOLORS); 51 | if (bgPtr) 52 | { 53 | bgColors = *((BColors::ColorSet*) bgPtr); 54 | update (); 55 | } 56 | } 57 | 58 | void Button::onButtonPressed (BEvents::PointerEvent* event) 59 | { 60 | setValue (1.0); 61 | Widget::cbfunction_[BEvents::EventType::BUTTON_PRESS_EVENT] (event); 62 | } 63 | 64 | void Button::onButtonReleased (BEvents::PointerEvent* event) 65 | { 66 | setValue (0.0); 67 | Widget::cbfunction_[BEvents::EventType::BUTTON_RELEASE_EVENT] (event); 68 | } 69 | 70 | void Button::draw (const BUtilities::RectArea& area) 71 | { 72 | if ((!widgetSurface_) || (cairo_surface_status (widgetSurface_) != CAIRO_STATUS_SUCCESS)) return; 73 | 74 | if ((getWidth () >= 6) && (getHeight () >= 6)) 75 | { 76 | // Draw super class widget elements first 77 | Widget::draw (area); 78 | 79 | cairo_t* cr = cairo_create (widgetSurface_); 80 | if (cairo_status (cr) == CAIRO_STATUS_SUCCESS) 81 | { 82 | // Limit cairo-drawing area 83 | cairo_rectangle (cr, area.getX (), area.getY (), area.getWidth (), area.getHeight ()); 84 | cairo_clip (cr); 85 | 86 | double x0 = getXOffset (); 87 | double y0 = getYOffset (); 88 | double w = getEffectiveWidth (); 89 | double h = getEffectiveHeight (); 90 | BColors::Color butColor = *bgColors.getColor (getState ()); butColor.applyBrightness (BWIDGETS_DEFAULT_NORMALLIGHTED); 91 | BColors::Color frColor= *bgColors.getColor (getState ()); 92 | 93 | if (value) frColor.applyBrightness (2 * BWIDGETS_DEFAULT_ILLUMINATED); 94 | else frColor.applyBrightness (2 * BWIDGETS_DEFAULT_SHADOWED); 95 | 96 | cairo_set_line_width (cr, 0.0); 97 | cairo_set_source_rgba (cr, CAIRO_RGBA (butColor)); 98 | cairo_rectangle_rounded (cr, x0, y0, w, h, BWIDGETS_DEFAULT_BUTTON_RAD, 0b1111); 99 | cairo_fill_preserve (cr); 100 | 101 | cairo_set_line_width (cr, BWIDGETS_DEFAULT_BUTTON_BORDER); 102 | cairo_set_source_rgba (cr, CAIRO_RGBA (frColor)); 103 | cairo_stroke (cr); 104 | 105 | } 106 | cairo_destroy (cr); 107 | } 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /BWidgets/Button.hpp: -------------------------------------------------------------------------------- 1 | /* Button.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 . 16 | */ 17 | 18 | #ifndef BUTTON_HPP_ 19 | #define BUTTON_HPP_ 20 | 21 | #include "ValueWidget.hpp" 22 | 23 | #define BWIDGETS_DEFAULT_BUTTON_WIDTH 50.0 24 | #define BWIDGETS_DEFAULT_BUTTON_HEIGHT 20.0 25 | #define BWIDGETS_KEYWORD_BUTTONCOLORS "buttoncolors" 26 | #define BWIDGETS_DEFAULT_BUTTON_BORDER 1.0 27 | #define BWIDGETS_DEFAULT_BUTTON_RAD 4.0 28 | 29 | namespace BWidgets 30 | { 31 | /** 32 | * Class BWidgets::Button 33 | * 34 | * Basic button widget drawing a button. Is is a BWidgets::ValueWidget having 35 | * two conditions: on (value != 0) or off (value == 0). The Widget is clickable 36 | * by default. 37 | */ 38 | class Button : public ValueWidget 39 | { 40 | public: 41 | Button (); 42 | Button (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue = 0.0); 43 | 44 | /** 45 | * Creates a new (orphan) button and copies the button properties from a 46 | * source button. This method doesn't copy any parent or child widgets. 47 | * @param that Source button 48 | */ 49 | Button (const Button& that); 50 | 51 | ~Button (); 52 | 53 | /** 54 | * Assignment. Copies the widget properties from a source button and keeps 55 | * its name and its position within the widget tree. Emits a 56 | * BEvents::ExposeEvent if the widget is visible. 57 | * @param that Source button 58 | */ 59 | Button& operator= (const Button& that); 60 | 61 | /** 62 | * Pattern cloning. Creates a new instance of the widget and copies all 63 | * its properties. 64 | */ 65 | virtual Widget* clone () const override; 66 | 67 | /** 68 | * Scans theme for widget properties and applies these properties. 69 | * @param theme Theme to be scanned. 70 | * Styles used are: 71 | * "buttoncolors" for BStyles::ColorSet 72 | * @param name Name of the BStyles::StyleSet within the theme to be 73 | * applied. 74 | */ 75 | virtual void applyTheme (BStyles::Theme& theme) override; 76 | virtual void applyTheme (BStyles::Theme& theme, const std::string& name) override; 77 | 78 | /** 79 | * Handles the BEvents::BUTTON_PRESS_EVENT. 80 | * @param event Pointer to a pointer event emitted by the same widget. 81 | */ 82 | virtual void onButtonPressed (BEvents::PointerEvent* event) override; 83 | 84 | /** 85 | * Handles the BEvents::BUTTON_RELEASED_EVENT. 86 | * @param event Pointer to a pointer event emitted by the same widget. 87 | */ 88 | virtual void onButtonReleased (BEvents::PointerEvent* event) override; 89 | 90 | protected: 91 | virtual void draw (const BUtilities::RectArea& area) override; 92 | 93 | BColors::ColorSet bgColors; 94 | }; 95 | 96 | } 97 | 98 | #endif /* BUTTON_HPP_ */ 99 | -------------------------------------------------------------------------------- /BWidgets/DialValue.hpp: -------------------------------------------------------------------------------- 1 | /* DialValue.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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_DIALVALUE_HPP_ 19 | #define BWIDGETS_DIALVALUE_HPP_ 20 | 21 | #include "Dial.hpp" 22 | #include "Label.hpp" 23 | 24 | #define BWIDGETS_DEFAULT_DIALVALUE_WIDTH BWIDGETS_DEFAULT_DIAL_WIDTH 25 | #define BWIDGETS_DEFAULT_DIALVALUE_HEIGHT (BWIDGETS_DEFAULT_DIAL_HEIGHT * 1.2) 26 | 27 | namespace BWidgets 28 | { 29 | /** 30 | * Class BWidgets::DialValue 31 | * 32 | * Composite dial widget that additionally displays the value of the dial. 33 | */ 34 | class DialValue : public Dial 35 | { 36 | public: 37 | DialValue (); 38 | DialValue (const double x, const double y, const double width, const double height, const std::string& name, 39 | const double value, const double min, const double max, const double step, const std::string& valueFormat); 40 | 41 | /** 42 | * Creates a new (orphan) dial and copies the dial properties from a 43 | * source dial. 44 | * @param that Source dial 45 | */ 46 | DialValue (const DialValue& that); 47 | 48 | ~DialValue (); 49 | 50 | /** 51 | * Assignment. Copies the dial properties from a source dial and keeps 52 | * its name and its position within the widget tree. Emits an expose event 53 | * if the widget is visible and a value changed event. 54 | * @param that Source widget 55 | */ 56 | DialValue& operator= (const DialValue& that); 57 | 58 | /** 59 | * Pattern cloning. Creates a new instance of the widget and copies all 60 | * its properties. 61 | */ 62 | virtual Widget* clone () const override; 63 | 64 | /** 65 | * Changes the value of the widget and keeps it within the defined range. 66 | * Passes the value to its predefined child widgets. 67 | * Emits a value changed event and (if visible) an expose event. 68 | * @param val Value 69 | */ 70 | virtual void setValue (const double val) override; 71 | 72 | /** 73 | * Sets the value output format. 74 | * @valueFormat Format of the output in printf standard for type double. 75 | */ 76 | void setValueFormat (const std::string& valueFormat); 77 | 78 | /** 79 | * Gets the value output format. 80 | * @return Format of the output in printf standard for type double. 81 | */ 82 | std::string getValueFormat () const; 83 | 84 | /** 85 | * Gets (a pointer to) the Label for direct access. 86 | * @return Pointer to the label 87 | */ 88 | Label* getDisplayLabel (); 89 | 90 | /** 91 | * Calls a redraw of the widget and calls postRedisplay () if the the 92 | * Widget is visible. 93 | * This method should be called if the widgets properties are indirectly 94 | * changed. 95 | */ 96 | virtual void update () override; 97 | 98 | /** 99 | * Scans theme for widget properties and applies these properties. 100 | * @param theme Theme to be scanned. 101 | * Styles used are: 102 | * BWIDGETS_KEYWORD_BORDER 103 | * BWIDGETS_KEYWORD_BACKGROUND 104 | * BWIDGETS_KEYWORD_FGCOLORS 105 | * BWIDGETS_KEYWORD_BGCOLORS 106 | * BWIDGETS_KEYWORD_TEXTCOLORS 107 | * BWIDGETS_KEYWORD_FONT 108 | * @param name Name of the BStyles::StyleSet within the theme to be 109 | * applied. 110 | */ 111 | virtual void applyTheme (BStyles::Theme& theme) override; 112 | virtual void applyTheme (BStyles::Theme& theme, const std::string& name) override; 113 | 114 | protected: 115 | virtual void updateCoords () override; 116 | static void displayDraggedCallback (BEvents::Event* event); 117 | static void displayMessageCallback (BEvents::Event* event); 118 | 119 | Label valueDisplay; 120 | 121 | std::string valFormat; 122 | }; 123 | 124 | /*****************************************************************************/ 125 | 126 | } 127 | 128 | #endif /* BWIDGETS_DIALVALUE_HPP_ */ 129 | -------------------------------------------------------------------------------- /BWidgets/Display.cpp: -------------------------------------------------------------------------------- 1 | /* Display.cpp 2 | * Copyright (C) 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 . 16 | */ 17 | 18 | #include "Display.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | Display::Display () : Display (0.0, 0.0, 0.0, 0.0, "display") {} 23 | 24 | Display::Display (const double x, const double y, const double width, 25 | const double height, const std::string& text) : 26 | Widget (x, y, width, height, text) 27 | { 28 | 29 | } 30 | 31 | Widget* Display::clone () const {return new Display (*this);} 32 | 33 | bool Display::filter (Widget* widget) {return true;} 34 | 35 | } 36 | -------------------------------------------------------------------------------- /BWidgets/Display.hpp: -------------------------------------------------------------------------------- 1 | /* Display.hpp 2 | * Copyright (C) 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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_DISPLAY_HPP_ 19 | #define BWIDGETS_DISPLAY_HPP_ 20 | 21 | #include "Widget.hpp" 22 | 23 | namespace BWidgets 24 | { 25 | 26 | /** 27 | * Class BWidgets::Display 28 | * 29 | * Container widget. Children of this widget will only be displayed (and handled 30 | * by the event handler) if the passWidget method returns true (default). This 31 | * class allows filtering of child widgets. 32 | */ 33 | class Display : public Widget 34 | { 35 | public: 36 | Display (); 37 | Display (const double x, const double y, const double width, const double height, 38 | const std::string& text); 39 | 40 | /** 41 | * Pattern cloning. Creates a new instance of the widget and copies all 42 | * its properties. 43 | */ 44 | virtual Widget* clone () const override; 45 | 46 | protected: 47 | virtual bool filter (Widget* widget) override; 48 | }; 49 | 50 | } 51 | 52 | #endif /* BWIDGETS_DISPLAY_HPP_ */ 53 | -------------------------------------------------------------------------------- /BWidgets/DownButton.cpp: -------------------------------------------------------------------------------- 1 | /* DownButton.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 . 16 | */ 17 | 18 | #include "DownButton.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | DownButton::DownButton () : 23 | DownButton (0.0, 0.0, BWIDGETS_DEFAULT_BUTTON_WIDTH, BWIDGETS_DEFAULT_BUTTON_HEIGHT, "upbutton", 0.0) {} 24 | 25 | DownButton::DownButton (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 | 28 | Widget* DownButton::clone () const {return new DownButton (*this);} 29 | 30 | void DownButton::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 - size/2, y0 + h/2 - size/4); 60 | cairo_line_to (cr, x0 + w/2, y0 + h/2 + size/4); 61 | cairo_line_to (cr, x0 + w/2 + size/2, y0 + h/2 - size/4); 62 | cairo_set_source_rgba (cr, CAIRO_RGBA (frColor)); 63 | cairo_stroke (cr); 64 | 65 | cairo_destroy (cr); 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /BWidgets/DownButton.hpp: -------------------------------------------------------------------------------- 1 | /* DownButton.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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_DOWNBUTTON_HPP_ 19 | #define BWIDGETS_DOWNBUTTON_HPP_ 20 | 21 | #include "Button.hpp" 22 | #include "Label.hpp" 23 | 24 | namespace BWidgets 25 | { 26 | /** 27 | * Class BWidgets::DownButton 28 | * 29 | * Text button widget. Is is a BWidgets::Button and thus a 30 | * BWidgets::ValueWidget having two conditions: on (value != 0) or off 31 | * (value == 0) 32 | */ 33 | class DownButton : public Button 34 | { 35 | public: 36 | DownButton (); 37 | DownButton (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue = 0.0); 38 | 39 | /** 40 | * Pattern cloning. Creates a new instance of the widget and copies all 41 | * its properties. 42 | */ 43 | virtual Widget* clone () const override; 44 | 45 | protected: 46 | virtual void draw (const BUtilities::RectArea& area) override; 47 | }; 48 | 49 | } 50 | 51 | #endif /* BWIDGETS_TOGGLEBUTTON_HPP_ */ 52 | -------------------------------------------------------------------------------- /BWidgets/DrawingSurface.hpp: -------------------------------------------------------------------------------- 1 | /* DrawingSurface.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 . 16 | */ 17 | 18 | #ifndef DRAWINGSURFACE_HPP_ 19 | #define DRAWINGSURFACE_HPP_ 20 | 21 | #include "Widget.hpp" 22 | 23 | namespace BWidgets 24 | { 25 | /** 26 | * Class BWidgets::DrawingSurface 27 | * 28 | * Basic button widget drawing a button. Is is a BWidgets::ValueWidget having 29 | * two conditions: on (value != 0) or off (value == 0). The Widget is clickable 30 | * by default. 31 | */ 32 | class DrawingSurface : public Widget 33 | { 34 | public: 35 | DrawingSurface (); 36 | DrawingSurface (const double x, const double y, const double width, const double height, const std::string& name); 37 | 38 | /** 39 | * Creates a new (orphan) drawing surface widget and copies the widget 40 | * properties from a source drawing surface widget. This method doesn't 41 | * copy any parent or child widgets. 42 | * @param that Source drawing surface widget 43 | */ 44 | DrawingSurface (const DrawingSurface& that); 45 | 46 | ~DrawingSurface (); 47 | 48 | /** 49 | * Assignment. Copies the widget properties from a source widget and keeps 50 | * its name and its position within the widget tree. Emits a 51 | * BEvents::ExposeEvent if the widget is visible. 52 | * @param that Source widget 53 | */ 54 | DrawingSurface& operator= (const DrawingSurface& that); 55 | 56 | /** 57 | * Pattern cloning. Creates a new instance of the widget and copies all 58 | * its properties. 59 | */ 60 | virtual Widget* clone () const override; 61 | 62 | /** 63 | * Gets (a pointer to) the Cairo surface for direct drawing provided by the 64 | * widget. 65 | * @return Cairo surface 66 | */ 67 | cairo_surface_t* getDrawingSurface (); 68 | 69 | /** 70 | * Resizes the widget and the drawing surface, redraw and emits a 71 | * BEvents::ExposeEvent if the widget is visible. 72 | * @param width New widgets width 73 | */ 74 | virtual void setWidth (const double width) override; 75 | 76 | /** 77 | * Resizes the widget and the drawing surface, redraw and emits a 78 | * BEvents::ExposeEvent if the widget is visible. 79 | * @param height New widgets height 80 | */ 81 | virtual void setHeight (const double height) override; 82 | 83 | /** 84 | * Resizes the widget and the drawing surface, 85 | * redraw and emits a BEvents::ExposeEvent if the 86 | * widget is visible. If no parameters are given, the widget will be 87 | * resized to the size of the containing child widgets. 88 | * @param width New widgets width 89 | * @param height New widgets height 90 | * @param extends New widget extends 91 | */ 92 | virtual void resize () override; 93 | virtual void resize (const double width, const double height) override; 94 | virtual void resize (const BUtilities::Point extends) override; 95 | 96 | /** 97 | * (Re-)Defines the border of the widget and resizes the drawing surface. 98 | * Redraws widget and emits a BEvents::ExposeEvent if the widget is 99 | * visible. 100 | * @param border New widgets border 101 | */ 102 | virtual void setBorder (const BStyles::Border& border) override; 103 | 104 | protected: 105 | virtual void draw (const BUtilities::RectArea& area) override; 106 | 107 | cairo_surface_t* drawingSurface; 108 | }; 109 | 110 | } 111 | 112 | #endif /* DRAWINGSURFACE_HPP_ */ 113 | -------------------------------------------------------------------------------- /BWidgets/Focusable.hpp: -------------------------------------------------------------------------------- 1 | /* Focusable.hpp 2 | * Copyright (C) 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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_FOCUSABLE_HPP_ 19 | #define BWIDGETS_FOCUSABLE_HPP_ 20 | 21 | #define BWIDGETS_DEFAULT_FOCUS_IN_MS 200 22 | #define BWIDGETS_DEFAULT_FOCUS_OUT_MS 5000 23 | #define BWIDGETS_DEFAULT_FOCUS_NAME "/focus" 24 | 25 | #include 26 | 27 | namespace BWidgets 28 | { 29 | 30 | class Focusable 31 | { 32 | protected: 33 | std::chrono::milliseconds focusInMs; 34 | std::chrono::milliseconds focusOutMs; 35 | 36 | public: 37 | Focusable (const std::chrono::milliseconds focusInMs, const std::chrono::milliseconds focusOutMs) : 38 | focusInMs (focusInMs), focusOutMs (focusOutMs) {} 39 | 40 | void setFocusInMilliseconds (const std::chrono::milliseconds ms) {focusInMs = ms;} 41 | 42 | std::chrono::milliseconds getFocusInMilliseconds () const {return focusInMs;} 43 | 44 | void setFocusOutMilliseconds (const std::chrono::milliseconds ms) {focusOutMs = ms;} 45 | 46 | std::chrono::milliseconds getFocusOutMilliseconds () const {return focusOutMs;} 47 | 48 | bool isFocusActive (const std::chrono::milliseconds diffMs) const {return ((diffMs >= focusInMs) && (diffMs < focusOutMs));} 49 | }; 50 | 51 | } 52 | 53 | #endif /*BWIDGETS_FOCUSABLE_HPP_*/ 54 | -------------------------------------------------------------------------------- /BWidgets/HPianoRoll.hpp: -------------------------------------------------------------------------------- 1 | /* HPianoRoll.hpp 2 | * Copyright (C) 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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_HPIANOROLL_HPP_ 19 | #define BWIDGETS_HPIANOROLL_HPP_ 20 | 21 | #include "PianoWidget.hpp" 22 | #include 23 | 24 | namespace BWidgets 25 | { 26 | 27 | /* 28 | * Piano roll widget 29 | */ 30 | class HPianoRoll : public PianoWidget 31 | { 32 | public: 33 | HPianoRoll (); 34 | HPianoRoll (const double x, const double y, const double width, const double height, const std::string& name); 35 | HPianoRoll (const double x, const double y, const double width, const double height, const std::string& name, 36 | const int startMidiKey, const int endMidiKey); 37 | 38 | /** 39 | * Pattern cloning. Creates a new instance of the widget and copies all 40 | * its properties. 41 | */ 42 | virtual Widget* clone () const override; 43 | 44 | /* 45 | * Defines how the keys respond upon pointer events. 46 | * @param toggle True, if the key is toggled if button pressed. False, 47 | * if the key is pressed if button pressed and released, 48 | * if button released. 49 | */ 50 | void setKeysToggleable (const bool toggle); 51 | 52 | /* 53 | * Gets how the keys respond upon pointer events. 54 | * @param return True, if the key is toggled if button pressed. False, 55 | * if the key is pressed if button pressed and released, 56 | * if button released. 57 | */ 58 | bool isKeysToggleable () const; 59 | 60 | // TODO key colors 61 | // virtual void applyTheme (BStyles::Theme& theme, const std::string& name) override; 62 | 63 | /** 64 | * Handles the BEvents::BUTTON_PRESS_EVENT to press the keys. 65 | * @param event Pointer to a pointer event emitted by the same widget. 66 | */ 67 | virtual void onButtonPressed (BEvents::PointerEvent* event) override; 68 | 69 | /** 70 | * Handles the BEvents::BUTTON_RELEASE_EVENT to release the keys. Takes 71 | * only effect if keys are NOT toggleable. 72 | * @param event Pointer to a pointer event emitted by the same widget. 73 | */ 74 | virtual void onButtonReleased (BEvents::PointerEvent* event) override; 75 | 76 | /** 77 | * Handles the BEvents::POINTER_DRAGGED_EVENT to press or release the keys. 78 | * @param event Pointer to a pointer event emitted by the same widget. 79 | */ 80 | virtual void onPointerDragged (BEvents::PointerEvent* event) override; 81 | 82 | protected: 83 | int getKey (const BUtilities::Point position); 84 | virtual void draw (const BUtilities::RectArea& area) override; 85 | 86 | bool toggleKeys; 87 | int actKeyNr; 88 | 89 | BColors::ColorSet blackBgColors; 90 | BColors::ColorSet whiteBgColors; 91 | }; 92 | } 93 | 94 | #endif /* BWIDGETS_HPIANOROLL_HPP_ */ 95 | -------------------------------------------------------------------------------- /BWidgets/HScale.hpp: -------------------------------------------------------------------------------- 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 . 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 | -------------------------------------------------------------------------------- /BWidgets/HSlider.hpp: -------------------------------------------------------------------------------- 1 | /* HSlider.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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_HSLIDER_HPP_ 19 | #define BWIDGETS_HSLIDER_HPP_ 20 | 21 | #include "Knob.hpp" 22 | #include "HScale.hpp" 23 | #include "Label.hpp" 24 | #include "Focusable.hpp" 25 | 26 | #define BWIDGETS_DEFAULT_HSLIDER_WIDTH BWIDGETS_DEFAULT_HSCALE_WIDTH 27 | #define BWIDGETS_DEFAULT_HSLIDER_HEIGHT (BWIDGETS_DEFAULT_HSCALE_HEIGHT * 2) 28 | #define BWIDGETS_DEFAULT_HSLIDER_DEPTH 1.0 29 | 30 | namespace BWidgets 31 | { 32 | /** 33 | * Class BWidgets::HSlider 34 | * 35 | * RangeWidget class for a horizontal slider. 36 | * The Widget is clickable by default. 37 | */ 38 | class HSlider : public HScale, public Focusable 39 | { 40 | public: 41 | HSlider (); 42 | HSlider (const double x, const double y, const double width, const double height, const std::string& name, 43 | const double value, const double min, const double max, const double step); 44 | 45 | /** 46 | * Creates a new (orphan) slider and copies the slider properties from a 47 | * source slider. 48 | * @param that Source slider 49 | */ 50 | HSlider (const HSlider& that); 51 | 52 | /** 53 | * Pattern cloning. Creates a new instance of the widget and copies all 54 | * its properties. 55 | */ 56 | virtual Widget* clone () const override; 57 | 58 | /** 59 | * Changes the value of the widget and keeps it within the defined range. 60 | * Passes the value to its predefined child widgets. 61 | * Emits a value changed event and (if visible) an expose event. 62 | * @param val Value 63 | */ 64 | virtual void setValue (const double val) override; 65 | 66 | /** 67 | * Assignment. Copies the slider properties from a source slider and keeps 68 | * its name and its position within the widget tree. Emits an expose event 69 | * if the widget is visible and a value changed event. 70 | * @param that Source slider 71 | */ 72 | HSlider& operator= (const HSlider& that); 73 | 74 | /** 75 | * Calls a redraw of the widget and calls postRedisplay () if the the 76 | * Widget is visible. 77 | * This method should be called if the widgets properties are indirectly 78 | * changed. 79 | */ 80 | virtual void update () override; 81 | 82 | /** 83 | * Scans theme for widget properties and applies these properties. 84 | * @param theme Theme to be scanned. 85 | * tyles used are: 86 | * BWIDGETS_KEYWORD_BORDER 87 | * BWIDGETS_KEYWORD_BACKGROUND 88 | * BWIDGETS_KEYWORD_FGCOLORS 89 | * BWIDGETS_KEYWORD_BGCOLORS 90 | * @param name Name of the BStyles::StyleSet within the theme to be 91 | * applied. 92 | */ 93 | virtual void applyTheme (BStyles::Theme& theme) override; 94 | virtual void applyTheme (BStyles::Theme& theme, const std::string& name) override; 95 | 96 | /** 97 | * Predefined empty method to handle a 98 | * BEvents::EventType::FOCUS_IN_EVENT. 99 | * @param event Focus event 100 | */ 101 | virtual void onFocusIn (BEvents::FocusEvent* event) override; 102 | 103 | /** 104 | * Predefined empty method to handle a 105 | * BEvents::EventType::FOCUS_OUT_EVENT. 106 | * @param event Focus event 107 | */ 108 | virtual void onFocusOut (BEvents::FocusEvent* event) override; 109 | 110 | protected: 111 | virtual void updateCoords () override; 112 | 113 | Knob knob; 114 | Label focusLabel; 115 | double knobRadius; 116 | BUtilities::Point knobPosition; 117 | }; 118 | 119 | } 120 | 121 | #endif /* BWIDGETS_HSLIDER_HPP_ */ 122 | -------------------------------------------------------------------------------- /BWidgets/HSwitch.cpp: -------------------------------------------------------------------------------- 1 | /* HSwitch.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 . 16 | */ 17 | 18 | #include "HSwitch.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | HSwitch::HSwitch () : HSwitch (0.0, 0.0, BWIDGETS_DEFAULT_HSWITCH_WIDTH, BWIDGETS_DEFAULT_HSWITCH_HEIGHT, "hswitch", BWIDGETS_DEFAULT_VALUE) {} 23 | 24 | HSwitch::HSwitch (const double x, const double y, const double width, const double height, const std::string& name, 25 | const double defaultvalue) : 26 | HSlider (x, y, width, height, name, defaultvalue, 0.0, 1.0, 1.0), dragged (false) {} 27 | 28 | Widget* HSwitch::clone () const {return new HSwitch (*this);} 29 | 30 | void HSwitch::onButtonPressed (BEvents::PointerEvent* event) {dragged = false;} 31 | 32 | void HSwitch::onButtonReleased (BEvents::PointerEvent* event) 33 | { 34 | if (!dragged) 35 | { 36 | if (getValue() == getMin ()) setValue (getMax ()); 37 | else setValue (getMin ()); 38 | } 39 | } 40 | 41 | void HSwitch::onPointerDragged (BEvents::PointerEvent* event) 42 | { 43 | dragged = true; 44 | HScale::onButtonPressed (event); 45 | } 46 | 47 | void HSwitch::updateCoords () 48 | { 49 | double w = getEffectiveWidth (); 50 | double h = getEffectiveHeight (); 51 | 52 | knobRadius = (h < w / 2 ? h / 2 : w / 4); 53 | scaleArea = BUtilities::RectArea 54 | ( 55 | getXOffset (), 56 | getYOffset () + h / 2 - knobRadius, 57 | w, 58 | 2 * knobRadius 59 | ); 60 | scaleXValue = scaleArea.getX() + knobRadius + getRelativeValue () * (scaleArea.getWidth() - 2 * knobRadius); 61 | knobPosition = BUtilities::Point 62 | ( 63 | scaleXValue + BWIDGETS_DEFAULT_KNOB_DEPTH, 64 | scaleArea.getY() + scaleArea.getHeight() / 2 + BWIDGETS_DEFAULT_KNOB_DEPTH 65 | ); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /BWidgets/HSwitch.hpp: -------------------------------------------------------------------------------- 1 | /* HSwitch.hpp 2 | * Copyright (C) 2018 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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_HSWITCH_HPP_ 19 | #define BWIDGETS_HSWITCH_HPP_ 20 | 21 | #include "Knob.hpp" 22 | #include "HSlider.hpp" 23 | 24 | #define BWIDGETS_DEFAULT_HSWITCH_WIDTH 40.0 25 | #define BWIDGETS_DEFAULT_HSWITCH_HEIGHT 20.0 26 | #define BWIDGETS_DEFAULT_HSWITCH_DEPTH 1.0 27 | 28 | namespace BWidgets 29 | { 30 | /** 31 | * Class BWidgets::HSwitch 32 | * 33 | * On/OFF switch widget. Is is a BWidgets::HSlider having two conditions: on 34 | * (value != 0) or off (value == 0) 35 | */ 36 | class HSwitch : public HSlider 37 | { 38 | public: 39 | HSwitch (); 40 | HSwitch (const double x, const double y, const double width, const double height, const std::string& name, const double defaultvalue); 41 | 42 | /** 43 | * Pattern cloning. Creates a new instance of the widget and copies all 44 | * its properties. 45 | */ 46 | virtual Widget* clone () const override; 47 | 48 | /** 49 | * Handles the BEvents::BUTTON_PRESS_EVENT to move the slider. 50 | * @param event Pointer to a pointer event emitted by the same widget. 51 | */ 52 | virtual void onButtonPressed (BEvents::PointerEvent* event) override; 53 | 54 | /** 55 | * Handles the BEvents::EventType::BUTTON_RELEASE_EVENT to move the slider. 56 | * @param event Pointer event 57 | */ 58 | virtual void onButtonReleased (BEvents::PointerEvent* event) override; 59 | 60 | /** 61 | * Handles the BEvents::POINTER_DRAG_EVENT to move 62 | * the slider. 63 | * @param event Pointer to a pointer event emitted by the same widget. 64 | */ 65 | virtual void onPointerDragged (BEvents::PointerEvent* event) override; 66 | 67 | protected: 68 | virtual void updateCoords () override; 69 | 70 | bool dragged; 71 | }; 72 | 73 | } 74 | 75 | #endif /* BWIDGETS_HSWITCH_HPP_ */ 76 | -------------------------------------------------------------------------------- /BWidgets/Icon.cpp: -------------------------------------------------------------------------------- 1 | /* ImageIcon.cpp 2 | * Copyright (C) 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 . 16 | */ 17 | 18 | #include "Icon.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | Icon::Icon () : Icon (0.0, 0.0, BWIDGETS_DEFAULT_WIDTH, BWIDGETS_DEFAULT_HEIGHT, "icon") {} 23 | 24 | Icon::Icon (const double x, const double y, const double width, const double height, const std::string& name) : 25 | Widget (x, y, width, height, name), iconSurface ({}) 26 | { 27 | //iconSurface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, getEffectiveWidth (), getEffectiveHeight ()); 28 | } 29 | 30 | Icon::Icon (const Icon& that) : Widget (that) 31 | { 32 | // Copy icons 33 | for (cairo_surface_t* s : that.iconSurface) 34 | { 35 | cairo_surface_t* n = nullptr; 36 | if (s) n = cairo_image_surface_clone_from_image_surface (s); 37 | iconSurface.push_back (n); 38 | } 39 | } 40 | 41 | Icon::~Icon () 42 | { 43 | while (!iconSurface.empty()) 44 | { 45 | cairo_surface_t* s = iconSurface.back (); 46 | if (s) cairo_surface_destroy (s); 47 | iconSurface.pop_back (); 48 | } 49 | } 50 | 51 | Icon& Icon::operator= (const Icon& that) 52 | { 53 | Widget::operator= (that); 54 | 55 | // Clear old icons 56 | while (!iconSurface.empty()) 57 | { 58 | cairo_surface_t* s = iconSurface.back (); 59 | if (s) cairo_surface_destroy (s); 60 | iconSurface.pop_back (); 61 | } 62 | 63 | // Copy new icons 64 | for (cairo_surface_t* s : that.iconSurface) 65 | { 66 | cairo_surface_t* n = nullptr; 67 | if (s) n = cairo_image_surface_clone_from_image_surface (s); 68 | iconSurface.push_back (n); 69 | } 70 | 71 | return *this; 72 | } 73 | 74 | Widget* Icon::clone () const {return new Icon (*this);} 75 | 76 | cairo_surface_t* Icon::getIconSurface (BColors::State state) const 77 | { 78 | return iconSurface [getState ()]; 79 | } 80 | 81 | void Icon::draw (const BUtilities::RectArea& area) 82 | { 83 | if ((!widgetSurface_) || (cairo_surface_status (widgetSurface_) != CAIRO_STATUS_SUCCESS)) return; 84 | 85 | if ((getWidth () >= 1) && (getHeight () >= 1)) 86 | { 87 | // Draw super class widget elements first 88 | Widget::draw (area); 89 | 90 | double w = getEffectiveWidth (); 91 | double h = getEffectiveHeight (); 92 | 93 | if (iconSurface.size () > getState ()) 94 | { 95 | cairo_surface_t* stateSurface = iconSurface [getState ()]; 96 | 97 | if (stateSurface && (cairo_surface_status (stateSurface) == CAIRO_STATUS_SUCCESS) && (w > 0) && (h > 0)) 98 | { 99 | cairo_t* cr = cairo_create (widgetSurface_); 100 | if (cairo_status (cr) == CAIRO_STATUS_SUCCESS) 101 | { 102 | // Limit cairo-drawing area 103 | cairo_rectangle (cr, area.getX (), area.getY (), area.getWidth (), area.getHeight ()); 104 | cairo_clip (cr); 105 | //TODO also clip to inner borders 106 | 107 | double oriw = cairo_image_surface_get_width (stateSurface); 108 | double orih = cairo_image_surface_get_height (stateSurface); 109 | double sz = ((w / oriw < h / orih) ? (w / oriw) : (h / orih)); 110 | double x0 = getXOffset () + w / 2 - oriw * sz / 2; 111 | double y0 = getYOffset () + h / 2 - orih * sz / 2; 112 | 113 | cairo_scale (cr, sz, sz); 114 | cairo_set_source_surface(cr, stateSurface, x0, y0); 115 | cairo_paint (cr); 116 | } 117 | 118 | cairo_destroy (cr); 119 | } 120 | } 121 | } 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /BWidgets/Icon.hpp: -------------------------------------------------------------------------------- 1 | /* ImageIcon.hpp 2 | * Copyright (C) 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 . 16 | */ 17 | 18 | #ifndef ICON_HPP_ 19 | #define ICON_HPP_ 20 | 21 | #include "Widget.hpp" 22 | 23 | namespace BWidgets 24 | { 25 | /** 26 | * Class BWidgets::Icon 27 | * 28 | * Widget displaying an icon. 29 | */ 30 | class Icon : public Widget 31 | { 32 | public: 33 | Icon (); 34 | Icon (const double x, const double y, const double width, const double height, const std::string& name); 35 | 36 | /** 37 | * Creates a new (orphan) image icon widget and copies the widget 38 | * properties from a source image icon widget. This method doesn't 39 | * copy any parent or child widgets. 40 | * @param that Source drawing surface widget 41 | */ 42 | Icon (const Icon& that); 43 | 44 | ~Icon (); 45 | 46 | /** 47 | * Assignment. Copies the widget properties from a source widget and keeps 48 | * its name and its position within the widget tree. Emits a 49 | * BEvents::ExposeEvent if the widget is visible. 50 | * @param that Source widget 51 | */ 52 | Icon& operator= (const Icon& that); 53 | 54 | /** 55 | * Pattern cloning. Creates a new instance of the widget and copies all 56 | * its properties. 57 | */ 58 | virtual Widget* clone () const override; 59 | 60 | cairo_surface_t* getIconSurface (BColors::State state) const; 61 | 62 | protected: 63 | virtual void draw (const BUtilities::RectArea& area) override; 64 | 65 | std::vector iconSurface; 66 | }; 67 | 68 | } 69 | 70 | #endif /* ICON_HPP_ */ 71 | -------------------------------------------------------------------------------- /BWidgets/ImageIcon.cpp: -------------------------------------------------------------------------------- 1 | /* ImageIcon.cpp 2 | * Copyright (C) 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 . 16 | */ 17 | 18 | #include "ImageIcon.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | ImageIcon::ImageIcon () : ImageIcon (0.0, 0.0, BWIDGETS_DEFAULT_WIDTH, BWIDGETS_DEFAULT_HEIGHT, "icon") {} 23 | 24 | ImageIcon::ImageIcon (const double x, const double y, const double width, const double height, 25 | const std::string& name) : 26 | Icon (x, y, width, height, name) {} 27 | 28 | ImageIcon::ImageIcon (const double x, const double y, const double width, const double height, 29 | const std::string& name, cairo_surface_t* surface) : 30 | Icon (x, y, width, height, name) 31 | { 32 | // Fill all standard states with the image from surface 33 | for (int i = BColors::NORMAL; i < BColors::USER_DEFINED; ++i) 34 | { 35 | loadImage (BColors::State (i), surface); 36 | } 37 | } 38 | 39 | ImageIcon::ImageIcon (const double x, const double y, const double width, const double height, 40 | const std::string& name, const std::string& filename) : 41 | Icon (x, y, width, height, name) 42 | { 43 | // Fill all standard states with the image from filename 44 | for (unsigned int i = BColors::NORMAL; i < BColors::USER_DEFINED; ++i) 45 | { 46 | loadImage (BColors::State (i), filename); 47 | } 48 | } 49 | 50 | ImageIcon::ImageIcon (const double x, const double y, const double width, const double height, 51 | const std::string& name, const std::vector& surfaces) : 52 | Icon (x, y, width, height, name) 53 | { 54 | for (unsigned int i = 0; i < surfaces.size (); ++i) loadImage (BColors::State (i), surfaces[i]); 55 | } 56 | 57 | ImageIcon::ImageIcon (const double x, const double y, const double width, const double height, 58 | const std::string& name, const std::vector& filenames) : 59 | Icon (x, y, width, height, name) 60 | { 61 | for (unsigned int i = 0; i < filenames.size (); ++i) loadImage (BColors::State (i), filenames[i]); 62 | } 63 | 64 | Widget* ImageIcon::clone () const {return new ImageIcon (*this);} 65 | 66 | void ImageIcon::loadImage (BColors::State state, cairo_surface_t* surface) 67 | { 68 | // Fill empty states with nullptr 69 | while (state >= iconSurface.size ()) iconSurface.push_back (nullptr); 70 | 71 | // Clear old surface 72 | if (iconSurface[state] && (cairo_surface_status (iconSurface[state]) == CAIRO_STATUS_SUCCESS)) 73 | { 74 | cairo_surface_destroy (iconSurface[state]); 75 | iconSurface[state] = nullptr; 76 | } 77 | 78 | iconSurface[state] = cairo_image_surface_clone_from_image_surface (surface); 79 | } 80 | 81 | void ImageIcon::loadImage (BColors::State state, const std::string& filename) 82 | { 83 | // Fill empty states with nullptr 84 | while (state >= iconSurface.size ()) iconSurface.push_back (nullptr); 85 | 86 | // Clear old surface 87 | if (iconSurface[state] && (cairo_surface_status (iconSurface[state]) == CAIRO_STATUS_SUCCESS)) 88 | { 89 | cairo_surface_destroy (iconSurface[state]); 90 | iconSurface[state] = nullptr; 91 | } 92 | 93 | iconSurface[state] = cairo_image_surface_create_from_png (filename.c_str()); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /BWidgets/ImageIcon.hpp: -------------------------------------------------------------------------------- 1 | /* ImageIcon.hpp 2 | * Copyright (C) 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 . 16 | */ 17 | 18 | #ifndef IMAGEICON_HPP_ 19 | #define IMAGEICON_HPP_ 20 | 21 | #include "Icon.hpp" 22 | 23 | namespace BWidgets 24 | { 25 | /** 26 | * Class BWidgets::ImageIcon 27 | * 28 | * Icon widget displaying an image file or a Cairo surface. 29 | */ 30 | class ImageIcon : public Icon 31 | { 32 | public: 33 | ImageIcon (); 34 | ImageIcon (const double x, const double y, const double width, const double height, const std::string& name); 35 | ImageIcon (const double x, const double y, const double width, const double height, const std::string& name, cairo_surface_t* surface); 36 | ImageIcon (const double x, const double y, const double width, const double height, const std::string& name, const std::string& filename); 37 | ImageIcon (const double x, const double y, const double width, const double height, const std::string& name, const std::vector& surfaces); 38 | ImageIcon (const double x, const double y, const double width, const double height, const std::string& name, const std::vector& filenames); 39 | 40 | /** 41 | * Pattern cloning. Creates a new instance of the widget and copies all 42 | * its properties. 43 | */ 44 | virtual Widget* clone () const override; 45 | 46 | /** 47 | * Loads an image from a Cairo surface or an image file. 48 | * @param surface Cairo surface 49 | * @param filename Filename 50 | */ 51 | void loadImage (BColors::State state, cairo_surface_t* surface); 52 | void loadImage (BColors::State state, const std::string& filename); 53 | }; 54 | 55 | } 56 | 57 | #endif /* IMAGEICON_HPP_ */ 58 | -------------------------------------------------------------------------------- /BWidgets/ItemBox.cpp: -------------------------------------------------------------------------------- 1 | /* ItemBox.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 . 16 | */ 17 | 18 | #include "ItemBox.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | ItemBox::ItemBox () : 23 | ItemBox (0.0, 0.0, 0.0, 0.0, "itembox", BItems::Item {UNSELECTED, nullptr}) {} 24 | 25 | ItemBox::ItemBox (const double x, const double y, const double width, 26 | const double height, const std::string& name, const BItems::Item item) : 27 | ValueWidget (x, y, width, height, name, UNSELECTED), item (item) 28 | 29 | { 30 | value = this->item.getValue (); 31 | background_ = BWIDGETS_DEFAULT_MENU_BACKGROUND; 32 | border_ = BWIDGETS_DEFAULT_MENU_BORDER; 33 | 34 | Widget* w = this->item.getWidget (); 35 | if (w) 36 | { 37 | w->setClickable (false); 38 | add (*w); 39 | } 40 | } 41 | 42 | ItemBox::ItemBox (const ItemBox& that) : 43 | ValueWidget (that), item (that.item) 44 | { 45 | if (item.getWidget ()) add (*item.getWidget ()); 46 | } 47 | 48 | ItemBox::~ItemBox () {} 49 | 50 | ItemBox& ItemBox::operator= (const ItemBox& that) 51 | { 52 | setItem (that.item); 53 | ValueWidget::operator= (that); 54 | return *this; 55 | } 56 | 57 | Widget* ItemBox::clone () const {return new ItemBox (*this);} 58 | 59 | void ItemBox::setItem (const BItems::Item item) 60 | { 61 | bool wasClickable = false; 62 | 63 | // Release old item.widget 64 | Widget* oldW = item.getWidget (); 65 | if (oldW && isChild (oldW)) release (oldW); 66 | 67 | // Copy item and set value 68 | this->item = item; 69 | setValue (this->item.getValue()); 70 | 71 | // Add new item.widget 72 | Widget* newW = item.getWidget (); 73 | if (newW) 74 | { 75 | newW->setClickable (wasClickable); 76 | add (*newW); 77 | } 78 | 79 | update (); 80 | } 81 | 82 | BItems::Item* ItemBox::getItem () {return &item;} 83 | 84 | void ItemBox::applyTheme (BStyles::Theme& theme) {applyTheme (theme, name_);} 85 | 86 | void ItemBox::applyTheme (BStyles::Theme& theme, const std::string& name) 87 | { 88 | Widget::applyTheme (theme, name); 89 | if (item.getWidget ()) 90 | { 91 | item.getWidget ()->applyTheme (theme, name + BWIDGETS_DEFAULT_ITEMBOX_ITEM_NAME); 92 | } 93 | 94 | update (); 95 | } 96 | 97 | void ItemBox::update () 98 | { 99 | // Update super widget first 100 | Widget::update (); 101 | 102 | Widget* widget = item.getWidget (); 103 | if (widget) 104 | { 105 | // Set position of label 106 | double x0 = getXOffset (); 107 | double y0 = getYOffset (); 108 | double w = getEffectiveWidth (); 109 | double h = getEffectiveHeight (); 110 | 111 | widget->moveTo (x0, y0); 112 | widget->resize (BUtilities::Point (w, h)); 113 | } 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /BWidgets/ItemBox.hpp: -------------------------------------------------------------------------------- 1 | /* ItemBox.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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_ITEMBOX_HPP_ 19 | #define BWIDGETS_ITEMBOX_HPP_ 20 | 21 | #include "BItems.hpp" 22 | #include "Label.hpp" 23 | #include "ValueWidget.hpp" 24 | #include 25 | 26 | #define BWIDGETS_DEFAULT_ITEMBOX_WIDTH 100.0 27 | #define BWIDGETS_DEFAULT_ITEMBOX_HEIGHT 20.0 28 | 29 | #define BWIDGETS_DEFAULT_ITEMBOX_ITEM_NAME "/item" 30 | 31 | #ifndef UNSELECTED 32 | #define UNSELECTED -HUGE_VAL 33 | #endif 34 | 35 | namespace BWidgets 36 | { 37 | 38 | /** 39 | * Class BWidgets::ItemBox 40 | * 41 | * Single line box widget displaying an item widget. An item is a value 42 | * associated with a widget. If no widget has been selected (nullptr), an 43 | * internal label widget will be used. 44 | * 45 | * TODO: Flexible padding 46 | */ 47 | class ItemBox : public ValueWidget 48 | { 49 | public: 50 | ItemBox (); 51 | ItemBox (const double x, const double y, const double width, const double height, 52 | const std::string& name, const BItems::Item item); 53 | 54 | /** 55 | * Creates a new (orphan) item box and copies the properties from a 56 | * source item box widget. 57 | * @param that Source choice box 58 | */ 59 | ItemBox (const ItemBox& that); 60 | 61 | ~ItemBox (); 62 | 63 | /** 64 | * Assignment. Copies the properties from a source item box widget 65 | * and keeps its name and its position within the widget tree. Emits a 66 | * BEvents::ExposeEvent if the text widget is visible. 67 | * @param that Source text widget 68 | */ 69 | ItemBox& operator= (const ItemBox& that); 70 | 71 | /** 72 | * Pattern cloning. Creates a new instance of the widget and copies all 73 | * its properties. 74 | */ 75 | virtual Widget* clone () const override; 76 | 77 | /** 78 | * Sets the item stored in this widget. 79 | * @param item Item. 80 | */ 81 | void setItem (const BItems::Item item); 82 | 83 | /** 84 | * Gets (a pointer to) the item stored in this widget. 85 | * @return Item. 86 | */ 87 | BItems::Item* getItem (); 88 | 89 | /** 90 | * Scans theme for widget properties and applies these properties. 91 | * @param theme Theme to be scanned. 92 | * @param name Name of the BStyles::StyleSet within the theme to be 93 | * applied. 94 | */ 95 | virtual void applyTheme (BStyles::Theme& theme) override; 96 | virtual void applyTheme (BStyles::Theme& theme, const std::string& name) override; 97 | 98 | /** 99 | * Calls a redraw of the widget and calls postRedisplay () if the the 100 | * Widget is visible. 101 | * This method should be called if the widgets properties are indirectly 102 | * changed. 103 | */ 104 | virtual void update () override; 105 | 106 | protected: 107 | BItems::Item item; 108 | }; 109 | 110 | } 111 | 112 | #endif /* BWIDGETS_ITEMBOX_HPP_ */ 113 | -------------------------------------------------------------------------------- /BWidgets/Knob.hpp: -------------------------------------------------------------------------------- 1 | /* Knob.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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_KNOB_HPP_ 19 | #define BWIDGETS_KNOB_HPP_ 20 | 21 | #include "RangeWidget.hpp" 22 | 23 | #define BWIDGETS_DEFAULT_KNOB_WIDTH 20.0 24 | #define BWIDGETS_DEFAULT_KNOB_HEIGHT 20.0 25 | #define BWIDGETS_DEFAULT_KNOB_DEPTH 1.0 26 | 27 | namespace BWidgets 28 | { 29 | /** 30 | * Class BWidgets::Knob 31 | * 32 | * Drawing widget. Draws a 3d knob. 33 | */ 34 | class Knob : public Widget 35 | { 36 | public: 37 | Knob (); 38 | Knob (const double x, const double y, const double width, const double height, const double depth, const std::string& name); 39 | 40 | /** 41 | * Creates a new (orphan) knob and copies the knob properties from a 42 | * source knob. This method doesn't copy any parent or child widgets. 43 | * @param that Source knob 44 | */ 45 | Knob (const Knob& that); 46 | 47 | ~Knob (); 48 | 49 | /** 50 | * Assignment. Copies the knob properties from a source knob and keeps 51 | * its name and its position within the widget tree. Emits an expose event 52 | * if the widget is visible. 53 | * @param that Source knob 54 | */ 55 | Knob& operator= (const Knob& 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 | * Sets the depth of the 3d knob 65 | * @param depth Depth 66 | */ 67 | void setDepth (const double depth); 68 | 69 | /** 70 | * Sets the depth of the 3d knob 71 | * @return Depth 72 | */ 73 | double getDepth () const; 74 | 75 | /** 76 | * Scans theme for widget properties and applies these properties. 77 | * @param theme Theme to be scanned. 78 | * @param name Name of the BStyles::StyleSet within the theme to be 79 | * applied. 80 | */ 81 | virtual void applyTheme (BStyles::Theme& theme) override; 82 | virtual void applyTheme (BStyles::Theme& theme, const std::string& name) override; 83 | 84 | protected: 85 | virtual void draw (const BUtilities::RectArea& area) override; 86 | 87 | double knobDepth; 88 | BColors::ColorSet bgColors; 89 | }; 90 | 91 | } 92 | 93 | #endif /* BWIDGETS_KNOB_HPP_ */ 94 | -------------------------------------------------------------------------------- /BWidgets/LeftButton.cpp: -------------------------------------------------------------------------------- 1 | /* LeftButton.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 . 16 | */ 17 | 18 | #include "LeftButton.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | LeftButton::LeftButton () : 23 | LeftButton (0.0, 0.0, BWIDGETS_DEFAULT_BUTTON_WIDTH, BWIDGETS_DEFAULT_BUTTON_HEIGHT, "upbutton", 0.0) {} 24 | 25 | LeftButton::LeftButton (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 | 28 | Widget* LeftButton::clone () const {return new LeftButton (*this);} 29 | 30 | void LeftButton::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 + size/4, y0 + h/2 - size/2); 60 | cairo_line_to (cr, x0 + w/2 - size/4, y0 + h/2); 61 | cairo_line_to (cr, x0 + w/2 + size/4, y0 + h/2 + size/2); 62 | cairo_set_source_rgba (cr, CAIRO_RGBA (frColor)); 63 | cairo_stroke (cr); 64 | 65 | cairo_destroy (cr); 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /BWidgets/LeftButton.hpp: -------------------------------------------------------------------------------- 1 | /* LeftButton.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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_LEFTBUTTON_HPP_ 19 | #define BWIDGETS_LEFTBUTTON_HPP_ 20 | 21 | #include "Button.hpp" 22 | #include "Label.hpp" 23 | 24 | namespace BWidgets 25 | { 26 | /** 27 | * Class BWidgets::LeftButton 28 | * 29 | * Text button widget. Is is a BWidgets::Button and thus a 30 | * BWidgets::ValueWidget having two conditions: on (value != 0) or off 31 | * (value == 0) 32 | */ 33 | class LeftButton : public Button 34 | { 35 | public: 36 | LeftButton (); 37 | LeftButton (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue = 0.0); 38 | 39 | /** 40 | * Pattern cloning. Creates a new instance of the widget and copies all 41 | * its properties. 42 | */ 43 | virtual Widget* clone () const override; 44 | 45 | protected: 46 | virtual void draw (const BUtilities::RectArea& area) override; 47 | }; 48 | 49 | } 50 | 51 | #endif /* BWIDGETS_LEFTBUTTON_HPP_ */ 52 | -------------------------------------------------------------------------------- /BWidgets/ListBox.hpp: -------------------------------------------------------------------------------- 1 | /* ListBox.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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_LISTBOX_HPP_ 19 | #define BWIDGETS_LISTBOX_HPP_ 20 | 21 | #include "ChoiceBox.hpp" 22 | 23 | #ifndef BWIDGETS_DEFAULT_LISTBOX_WIDTH 24 | #define BWIDGETS_DEFAULT_LISTBOX_WIDTH BWIDGETS_DEFAULT_CHOICEBOX_WIDTH 25 | #endif 26 | 27 | #ifndef BWIDGETS_DEFAULT_LISTBOX_HEIGHTH 28 | #define BWIDGETS_DEFAULT_LISTBOX_HEIGHTH 100.0 29 | #endif 30 | 31 | namespace BWidgets 32 | { 33 | 34 | /** 35 | * Class BWidgets::ListBox 36 | * 37 | * Widget for selection of one item out of a vector of items. 38 | * It is a composite value widget consisting of a label, an up button, and a 39 | * down button. The value of this widget reflects the number the item selected 40 | * starting with 1.0. On change, a value changed event is emitted and this 41 | * widget. 42 | */ 43 | class ListBox : public ChoiceBox 44 | { 45 | public: 46 | ListBox (); 47 | ListBox (const double x, const double y, const double width, const double height, 48 | const std::string& name); 49 | ListBox (const double x, const double y, const double width, const double height, 50 | const std::string& name, const BItems::ItemList& items, double preselection = UNSELECTED); 51 | 52 | /** 53 | * Creates a new (orphan) list box and copies the properties from a 54 | * source list box widget. 55 | * @param that Source choice box 56 | */ 57 | ListBox (const ListBox& that); 58 | 59 | ~ListBox (); 60 | 61 | /** 62 | * Assignment. Copies the properties from a source list box widget 63 | * and keeps its name and its position within the widget tree. Emits a 64 | * BEvents::ExposeEvent if the text widget is visible. 65 | * @param that Source list box widget 66 | */ 67 | ListBox& operator= (const ListBox& that); 68 | 69 | /** 70 | * Pattern cloning. Creates a new instance of the widget and copies all 71 | * its properties. 72 | */ 73 | virtual Widget* clone () const override; 74 | 75 | /** 76 | * Sets the top line of the shown list. 77 | * @param top Top Line of the list (starting with 1.0) 78 | */ 79 | void setTop (const int top); 80 | 81 | /** 82 | * Gets the top line of the shown list. 83 | * @param return Top Line of the list (starting with 1.0) 84 | */ 85 | virtual int getTop () const override; 86 | 87 | /** 88 | * Handles the BEvents::WHEEL_SCROLL_EVENT to scroll the displayed part of 89 | * the list (via setTop). 90 | * @param event Pointer to a wheel event emitted by the same widget. 91 | */ 92 | virtual void onWheelScrolled (BEvents::WheelEvent* event) override; 93 | 94 | protected: 95 | static void handleButtonClicked (BEvents::Event* event); 96 | virtual void updateItems () override; 97 | virtual int getLines () override; 98 | 99 | int listTop; 100 | }; 101 | 102 | } 103 | 104 | #endif /* BWIDGETS_LISTBOX_HPP_ */ 105 | -------------------------------------------------------------------------------- /BWidgets/MinusButton.cpp: -------------------------------------------------------------------------------- 1 | /* MinusButton.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 . 16 | */ 17 | 18 | #include "MinusButton.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | MinusButton::MinusButton () : 23 | MinusButton (0.0, 0.0, BWIDGETS_DEFAULT_BUTTON_WIDTH, BWIDGETS_DEFAULT_BUTTON_HEIGHT, "upbutton", 0.0) {} 24 | 25 | MinusButton::MinusButton (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 | 28 | Widget* MinusButton::clone () const {return new MinusButton (*this);} 29 | 30 | void MinusButton::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_set_source_rgba (cr, CAIRO_RGBA (frColor)); 62 | cairo_stroke (cr); 63 | 64 | cairo_destroy (cr); 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /BWidgets/MinusButton.hpp: -------------------------------------------------------------------------------- 1 | /* MinusButton.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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_MINUSBUTTON_HPP_ 19 | #define BWIDGETS_MINUSBUTTON_HPP_ 20 | 21 | #include "Button.hpp" 22 | #include "Label.hpp" 23 | 24 | namespace BWidgets 25 | { 26 | /** 27 | * Class BWidgets::MinusButton 28 | * 29 | * Text button widget. Is is a BWidgets::Button and thus a 30 | * BWidgets::ValueWidget having two conditions: on (value != 0) or off 31 | * (value == 0) 32 | */ 33 | class MinusButton : public Button 34 | { 35 | public: 36 | MinusButton (); 37 | MinusButton (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue = 0.0); 38 | 39 | /** 40 | * Pattern cloning. Creates a new instance of the widget and copies all 41 | * its properties. 42 | */ 43 | virtual Widget* clone () const override; 44 | 45 | protected: 46 | virtual void draw (const BUtilities::RectArea& area) override; 47 | }; 48 | 49 | } 50 | 51 | #endif /* BWIDGETS_MINUSBUTTON_HPP_ */ 52 | -------------------------------------------------------------------------------- /BWidgets/PianoWidget.cpp: -------------------------------------------------------------------------------- 1 | /* PianoWidget.cpp 2 | * Copyright (C) 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 . 16 | */ 17 | 18 | #include "PianoWidget.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | 23 | PianoWidget::PianoWidget () : PianoWidget (0, 0, 0, 0, "piano", 0, 0) {} 24 | 25 | PianoWidget::PianoWidget (const double x, const double y, const double width, const double height, const std::string& name) : 26 | PianoWidget (x, y, width, height, name, 0, 119) {} 27 | 28 | PianoWidget::PianoWidget (const double x, const double y, const double width, const double height, const std::string& name, 29 | const int startMidiKey, const int endMidiKey) : 30 | Widget (x, y, width, height, name), 31 | startMidiKey (startMidiKey), endMidiKey (endMidiKey), 32 | activeKeys (endMidiKey - startMidiKey + 1, true), pressedKeys (endMidiKey - startMidiKey + 1, false) {} 33 | 34 | Widget* PianoWidget::clone () const {return new PianoWidget (*this);} 35 | 36 | void PianoWidget::pressKeys (std::vector& keys) 37 | { 38 | if (((int) keys.size()) == endMidiKey - startMidiKey + 1) pressedKeys = keys; 39 | // TODO else throw exception 40 | update (); 41 | } 42 | 43 | std::vector PianoWidget::getPressedKeys () const {return pressedKeys;} 44 | 45 | void PianoWidget::activateKeys (std::vector& keys) 46 | { 47 | if (((int) keys.size()) == endMidiKey - startMidiKey + 1) activeKeys = keys; 48 | // TODO else throw exception 49 | update (); 50 | } 51 | 52 | std::vector PianoWidget::getActiveKeys () const {return activeKeys;} 53 | 54 | } 55 | -------------------------------------------------------------------------------- /BWidgets/PianoWidget.hpp: -------------------------------------------------------------------------------- 1 | /* PianoWidget.hpp 2 | * Copyright (C) 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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_PIANOWIDGET_HPP_ 19 | #define BWIDGETS_PIANOWIDGET_HPP_ 20 | 21 | #include "Widget.hpp" 22 | 23 | #define BWIDGETS_PIANO_KEY_PRESSED_MESSAGE "PIANO_KEY_PRESSED" 24 | #define BWIDGETS_PIANO_KEY_RELEASED_MESSAGE "PIANO_KEY_RELEASED" 25 | 26 | namespace BWidgets 27 | { 28 | 29 | #ifndef BWIDGETS_KEYCOORDS_ 30 | #define BWIDGETS_KEYCOORDS_ 31 | typedef struct { 32 | bool whiteKey; 33 | double x; 34 | double dx1; 35 | double dx2; 36 | double width; 37 | } KeyCoords; 38 | 39 | const std::array keyCoords= 40 | {{ 41 | {true, 0.0, 0.0, 0.4167, 1.0}, 42 | {false, 0.5833, 0.0, 0.0, 0.6667}, 43 | {true, 1.0, 0.25, 0.25, 1.0}, 44 | {false, 1.75, 0, 0, 0.6667}, 45 | {true, 2, 0.4167, 0, 1}, 46 | {true, 3, 0, 0.5, 1}, 47 | {false, 3.5, 0, 0, 0.6667}, 48 | {true, 4, 0.1667, 0.3333, 1}, 49 | {false, 4.6667, 0, 0, 0.6667}, 50 | {true, 5, 0.3333, 0.1667, 1}, 51 | {false, 5.8333, 0, 0, 0.6667}, 52 | {true, 6, 0.5, 0, 1} 53 | }}; 54 | #endif /* BWIDGETS_KEYCOORDS_ */ 55 | 56 | /* 57 | * Class that handles keyboard widget specific data. This class doesn't 58 | * implement an own draw method and thus it doesn't draw a keyboard! Use 59 | * HPianoRoll or VPianoRoll instead. 60 | */ 61 | class PianoWidget : public Widget 62 | { 63 | public: 64 | PianoWidget (); 65 | PianoWidget (const double x, const double y, const double width, const double height, const std::string& name); 66 | PianoWidget (const double x, const double y, const double width, const double height, const std::string& name, 67 | const int startMidiKey, const int endMidiKey); 68 | 69 | /** 70 | * Pattern cloning. Creates a new instance of the widget and copies all 71 | * its properties. 72 | */ 73 | virtual Widget* clone () const override; 74 | 75 | /* 76 | * Sets the press status of the respective keys. 77 | * @param keys Vector of bool with a size that represents the number of 78 | * keys. The first vector element represents the first key. 79 | * True = pressed and false = released. 80 | */ 81 | void pressKeys (std::vector& keys); 82 | 83 | /* 84 | * Gets the press status of the respective keys. 85 | * @param return Vector of bool with a size that represents the number 86 | * of keys. The first vector element represents the first 87 | * key. True = pressed and false = released. 88 | */ 89 | std::vector getPressedKeys () const; 90 | 91 | /* 92 | * Sets the activity status of the respective keys. Active keys are 93 | * highlighted and respond to pointer events. 94 | * @param keys Vector of bool with a size that represents the number of 95 | * keys. The first vector element represents the first key. 96 | * True = active and false = inactive. 97 | */ 98 | void activateKeys (std::vector& keys); 99 | 100 | /* 101 | * Gets the activity status of the respective keys. Active keys are 102 | * highlighted and respond to pointer events. 103 | * @param return Vector of bool with a size that represents the number 104 | * of keys. The first vector element represents the first 105 | * key. True = active and false = inactive. 106 | */ 107 | std::vector getActiveKeys () const; 108 | 109 | protected: 110 | 111 | int startMidiKey; 112 | int endMidiKey; 113 | std::vector activeKeys; 114 | std::vector pressedKeys; 115 | }; 116 | 117 | } 118 | 119 | #endif /* BWIDGETS_PIANOWIDGET_HPP_ */ 120 | -------------------------------------------------------------------------------- /BWidgets/PlusButton.cpp: -------------------------------------------------------------------------------- 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 . 16 | */ 17 | 18 | #include "PlusButton.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | PlusButton::PlusButton () : 23 | PlusButton (0.0, 0.0, BWIDGETS_DEFAULT_BUTTON_WIDTH, BWIDGETS_DEFAULT_BUTTON_HEIGHT, "upbutton", 0.0) {} 24 | 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 | 28 | Widget* PlusButton::clone () const {return new PlusButton (*this);} 29 | 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 | -------------------------------------------------------------------------------- /BWidgets/PlusButton.hpp: -------------------------------------------------------------------------------- 1 | /* PlusButton.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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_PLUSBUTTON_HPP_ 19 | #define BWIDGETS_PLUSBUTTON_HPP_ 20 | 21 | #include "Button.hpp" 22 | #include "Label.hpp" 23 | 24 | namespace BWidgets 25 | { 26 | /** 27 | * Class BWidgets::PlusButton 28 | * 29 | * Text button widget. Is is a BWidgets::Button and thus a 30 | * BWidgets::ValueWidget having two conditions: on (value != 0) or off 31 | * (value == 0) 32 | */ 33 | class PlusButton : public Button 34 | { 35 | public: 36 | PlusButton (); 37 | PlusButton (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue = 0.0); 38 | 39 | /** 40 | * Pattern cloning. Creates a new instance of the widget and copies all 41 | * its properties. 42 | */ 43 | virtual Widget* clone () const override; 44 | 45 | protected: 46 | virtual void draw (const BUtilities::RectArea& area) override; 47 | }; 48 | 49 | } 50 | 51 | #endif /* BWIDGETS_PLUSBUTTON_HPP_ */ 52 | -------------------------------------------------------------------------------- /BWidgets/RangeWidget.cpp: -------------------------------------------------------------------------------- 1 | /* RangeWidget.cpp 2 | * Copyright (C) 2018 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 . 16 | */ 17 | 18 | #include "RangeWidget.hpp" 19 | 20 | #ifndef LIMIT 21 | #define LIMIT(val, min, max) (val < min ? min : (val < max ? val : max)) 22 | #endif 23 | 24 | namespace BWidgets 25 | { 26 | RangeWidget::RangeWidget () : 27 | RangeWidget (0.0, 0.0, BWIDGETS_DEFAULT_WIDTH, BWIDGETS_DEFAULT_HEIGHT, "rangewidget", 28 | BWIDGETS_DEFAULT_VALUE, BWIDGETS_DEFAULT_RANGE_MIN, BWIDGETS_DEFAULT_RANGE_MAX, BWIDGETS_DEFAULT_RANGE_STEP) {} 29 | 30 | RangeWidget::RangeWidget (const double x, const double y, const double width, const double height, const std::string& name, 31 | const double value, const double min, const double max, const double step) : 32 | ValueWidget (x, y, width, height, name, value), rangeMin (min <= max ? min : max), 33 | rangeMax (max), rangeStep (step) 34 | { 35 | this->value = LIMIT (value, min, max); 36 | } 37 | 38 | RangeWidget::RangeWidget (const RangeWidget& that) : 39 | ValueWidget (that), rangeMin (that.rangeMin <= that.rangeMax ? that.rangeMin : that.rangeMax), rangeMax (that.rangeMax), rangeStep (that.rangeStep) {} 40 | 41 | RangeWidget::~RangeWidget () {} 42 | 43 | RangeWidget& RangeWidget::operator= (const RangeWidget& that) 44 | { 45 | Widget::operator= (that); 46 | rangeMin = that.rangeMin; 47 | rangeMax = that.rangeMax; 48 | rangeStep = that.rangeStep; 49 | setValue (that.value); 50 | 51 | return *this; 52 | } 53 | 54 | Widget* RangeWidget::clone () const {return new RangeWidget (*this);} 55 | 56 | void RangeWidget::setValue (const double val) 57 | { 58 | double valRounded = LIMIT (val, rangeMin, rangeMax); 59 | if ((rangeStep != 0.0) && (rangeMax >= rangeMin)) 60 | { 61 | if (rangeStep > 0.0) valRounded = LIMIT (rangeMin + round ((val - rangeMin) / rangeStep) * rangeStep, rangeMin, rangeMax); 62 | else valRounded = LIMIT (rangeMax - round ((rangeMax - val) / rangeStep) * rangeStep, rangeMin, rangeMax); 63 | } 64 | 65 | if (value != valRounded) ValueWidget::setValue (valRounded); 66 | } 67 | 68 | double RangeWidget::getRelativeValue () const 69 | { 70 | double relVal; 71 | if (getMax () != getMin ()) relVal = (getValue () - getMin ()) / (getMax () - getMin ()); 72 | else relVal = 0.5; // min == max doesn't make any sense, but need to be handled 73 | if (getStep() < 0) relVal = 1 - relVal; // Swap if reverse orientation 74 | return relVal; 75 | } 76 | 77 | void RangeWidget::setMin (const double min) 78 | { 79 | double newMin = (min <= rangeMax ? min: rangeMax); 80 | if (rangeMin != newMin) 81 | { 82 | rangeMin = newMin; 83 | if (getValue () < rangeMin) setValue (rangeMin); 84 | update (); 85 | } 86 | } 87 | 88 | double RangeWidget::getMin () const {return rangeMin;} 89 | 90 | void RangeWidget::setMax (const double max) 91 | { 92 | double newMax = (max >= rangeMin ? max: rangeMin); 93 | if (rangeMax != newMax) 94 | { 95 | rangeMax = newMax; 96 | if (getValue () > rangeMax) setValue (rangeMax); 97 | update (); 98 | } 99 | } 100 | 101 | double RangeWidget::getMax () const {return rangeMax;} 102 | 103 | void RangeWidget::setStep (const double step) {rangeStep = step;} 104 | 105 | double RangeWidget::getStep () const {return rangeStep;} 106 | 107 | void RangeWidget::setLimits (const double min, const double max, const double step) 108 | { 109 | double newMin = min <= max ? min : max; 110 | 111 | if ((newMin != rangeMin) || (max != rangeMax) || (step != rangeStep)) 112 | { 113 | rangeMin = newMin; 114 | rangeMax = max; 115 | rangeStep = step; 116 | if (getValue () < rangeMin) setValue (rangeMin); 117 | else if (getValue () > rangeMax) setValue (rangeMax); 118 | update (); 119 | } 120 | } 121 | 122 | 123 | } 124 | -------------------------------------------------------------------------------- /BWidgets/RightButton.cpp: -------------------------------------------------------------------------------- 1 | /* RightButton.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 . 16 | */ 17 | 18 | #include "RightButton.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | RightButton::RightButton () : 23 | RightButton (0.0, 0.0, BWIDGETS_DEFAULT_BUTTON_WIDTH, BWIDGETS_DEFAULT_BUTTON_HEIGHT, "upbutton", 0.0) {} 24 | 25 | RightButton::RightButton (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 | 28 | Widget* RightButton::clone () const {return new RightButton (*this);} 29 | 30 | void RightButton::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 - size/4, y0 + h/2 - size/2); 60 | cairo_line_to (cr, x0 + w/2 + size/4, y0 + h/2); 61 | cairo_line_to (cr, x0 + w/2 - size/4, y0 + h/2 + size/2); 62 | cairo_set_source_rgba (cr, CAIRO_RGBA (frColor)); 63 | cairo_stroke (cr); 64 | 65 | cairo_destroy (cr); 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /BWidgets/RightButton.hpp: -------------------------------------------------------------------------------- 1 | /* RightButton.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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_RIGHTBUTTON_HPP_ 19 | #define BWIDGETS_RIGHTBUTTON_HPP_ 20 | 21 | #include "Button.hpp" 22 | #include "Label.hpp" 23 | 24 | namespace BWidgets 25 | { 26 | /** 27 | * Class BWidgets::RightButton 28 | * 29 | * Text button widget. Is is a BWidgets::Button and thus a 30 | * BWidgets::ValueWidget having two conditions: on (value != 0) or off 31 | * (value == 0) 32 | */ 33 | class RightButton : public Button 34 | { 35 | public: 36 | RightButton (); 37 | RightButton (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue = 0.0); 38 | 39 | /** 40 | * Pattern cloning. Creates a new instance of the widget and copies all 41 | * its properties. 42 | */ 43 | virtual Widget* clone () const override; 44 | 45 | protected: 46 | virtual void draw (const BUtilities::RectArea& area) override; 47 | }; 48 | 49 | } 50 | 51 | #endif /* BWIDGETS_RIGHTBUTTON_HPP_ */ 52 | -------------------------------------------------------------------------------- /BWidgets/StateDisplay.cpp: -------------------------------------------------------------------------------- 1 | /* StateDisplay.cpp 2 | * Copyright (C) 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 . 16 | */ 17 | 18 | #include "StateDisplay.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | StateDisplay::StateDisplay () : StateDisplay (0.0, 0.0, 0.0, 0.0, "display") {} 23 | 24 | StateDisplay::StateDisplay (const double x, const double y, const double width, 25 | const double height, const std::string& text) : 26 | Display (x, y, width, height, text) 27 | { 28 | 29 | } 30 | 31 | Widget* StateDisplay::clone () const {return new StateDisplay (*this);} 32 | 33 | bool StateDisplay::filter (Widget* widget) {return (getState () == widget->getState ());} 34 | 35 | } 36 | -------------------------------------------------------------------------------- /BWidgets/StateDisplay.hpp: -------------------------------------------------------------------------------- 1 | /* StateDisplay.hpp 2 | * Copyright (C) 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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_STATEDISPLAY_HPP_ 19 | #define BWIDGETS_STATEDISPLAY_HPP_ 20 | 21 | #include "Display.hpp" 22 | 23 | namespace BWidgets 24 | { 25 | 26 | /** 27 | * Class BWidgets::StateDisplay 28 | * 29 | * Display widget that displays only child widgets of the same state. 30 | */ 31 | class StateDisplay : public Display 32 | { 33 | public: 34 | StateDisplay (); 35 | StateDisplay (const double x, const double y, const double width, const double height, 36 | const std::string& text); 37 | 38 | /** 39 | * Pattern cloning. Creates a new instance of the widget and copies all 40 | * its properties. 41 | */ 42 | virtual Widget* clone () const override; 43 | 44 | protected: 45 | virtual bool filter (Widget* widget) override; 46 | }; 47 | 48 | } 49 | 50 | #endif /* BWIDGETS_STATEDISPLAY_HPP_ */ 51 | -------------------------------------------------------------------------------- /BWidgets/TextButton.cpp: -------------------------------------------------------------------------------- 1 | /* TextButton.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 . 16 | */ 17 | 18 | #include "TextButton.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | TextButton::TextButton () : 23 | TextButton (0.0, 0.0, BWIDGETS_DEFAULT_BUTTON_WIDTH, BWIDGETS_DEFAULT_BUTTON_HEIGHT, "textbutton", "", 0.0) {} 24 | 25 | TextButton::TextButton (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue) : 26 | TextButton (x, y, width, height, name, name, defaultValue) {} 27 | 28 | TextButton::TextButton (const double x, const double y, const double width, const double height, 29 | const std::string& name, const std::string& label, double defaultValue) : 30 | Button (x, y, width, height, name, defaultValue), 31 | buttonLabel (0, 0, width, height, name, label) 32 | { 33 | buttonLabel.setClickable (false); 34 | buttonLabel.setState (defaultValue ? BColors::ACTIVE : BColors::NORMAL); 35 | buttonLabel.setBorder (BWIDGETS_DEFAULT_MENU_TEXTBORDER); 36 | add (buttonLabel); 37 | } 38 | 39 | TextButton::TextButton (const TextButton& that) : Button (that), buttonLabel (that.buttonLabel) 40 | { 41 | add (buttonLabel); 42 | } 43 | 44 | TextButton:: ~TextButton () {} 45 | 46 | TextButton& TextButton::operator= (const TextButton& that) 47 | { 48 | release (&buttonLabel); 49 | 50 | Button::operator= (that); 51 | buttonLabel = that.buttonLabel; 52 | 53 | add (buttonLabel); 54 | 55 | return *this; 56 | } 57 | 58 | Widget* TextButton::clone () const {return new TextButton (*this);} 59 | 60 | void TextButton::setWidth (const double width) 61 | { 62 | Button::setWidth (width); 63 | buttonLabel.setWidth (width); 64 | } 65 | 66 | void TextButton::setHeight (const double height) 67 | { 68 | Button::setHeight (height); 69 | buttonLabel.setHeight (height); 70 | } 71 | 72 | void TextButton::resize () 73 | { 74 | buttonLabel.resize (); 75 | Widget::resize (); 76 | } 77 | 78 | void TextButton::resize (const double width, const double height) {TextButton::resize (BUtilities::Point (width, height));} 79 | 80 | void TextButton::resize (const BUtilities::Point extends) 81 | { 82 | Widget::resize (BUtilities::Point (extends.x, extends.y)); 83 | buttonLabel.resize (BUtilities::Point (extends.x, extends.y)); 84 | } 85 | 86 | void TextButton::setValue (const double val) 87 | { 88 | if (val) buttonLabel.setState (BColors::ACTIVE); 89 | else buttonLabel.setState (BColors::NORMAL); 90 | Button::setValue (val); 91 | } 92 | 93 | Label* TextButton::getLabel () {return &buttonLabel;} 94 | 95 | void TextButton::applyTheme (BStyles::Theme& theme) {applyTheme (theme, name_);} 96 | void TextButton::applyTheme (BStyles::Theme& theme, const std::string& name) 97 | { 98 | Button::applyTheme (theme, name); 99 | buttonLabel.applyTheme (theme, name); 100 | update (); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /BWidgets/TextButton.hpp: -------------------------------------------------------------------------------- 1 | /* TextButton.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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_TEXTBUTTON_HPP_ 19 | #define BWIDGETS_TEXTBUTTON_HPP_ 20 | 21 | #include "Button.hpp" 22 | #include "Label.hpp" 23 | 24 | namespace BWidgets 25 | { 26 | /** 27 | * Class BWidgets::TextButton 28 | * 29 | * Text button widget. Is is a BWidgets::Button and thus a 30 | * BWidgets::ValueWidget having two conditions: on (value != 0) or off 31 | * (value == 0) 32 | */ 33 | class TextButton : public Button 34 | { 35 | public: 36 | TextButton (); 37 | TextButton (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue = 0.0); 38 | TextButton (const double x, const double y, const double width, const double height, 39 | const std::string& name, const std::string& label, double defaultValue = 0.0); 40 | 41 | /** 42 | * Creates a new (orphan) button and copies the button properties from a 43 | * source button. 44 | * @param that Source button 45 | */ 46 | TextButton (const TextButton& that); 47 | 48 | ~TextButton (); 49 | 50 | /** 51 | * Assignment. Copies the widget properties from a source button and keeps 52 | * its name and its position within the widget tree. Emits a 53 | * BEvents::ExposeEvent if the widget is visible. 54 | * @param that Source button 55 | */ 56 | TextButton& operator= (const TextButton& that); 57 | 58 | /** 59 | * Pattern cloning. Creates a new instance of the widget and copies all 60 | * its properties. 61 | */ 62 | virtual Widget* clone () const override; 63 | 64 | /** 65 | * Resizes the widget and its predefined child, redraw and emits a 66 | * BEvents::ExposeEvent if the widget is visible. 67 | * @param width New widgets width 68 | */ 69 | virtual void setWidth (const double width) override; 70 | 71 | /** 72 | * Resizes the widget and its predefined child, redraw and emits a 73 | * BEvents::ExposeEvent if the widget is visible. 74 | * @param height New widgets height 75 | */ 76 | virtual void setHeight (const double height) override; 77 | 78 | /** 79 | * Resizes the widget, redraw and emits a BEvents::ExposeEvent if the 80 | * widget is visible. If no parameters are given, the widget will be 81 | * resized to the size of the containing child widgets. 82 | * @param width New widgets width 83 | * @param height New widgets height 84 | * @param extends New widget extends 85 | */ 86 | virtual void resize () override; 87 | virtual void resize (const double width, const double height) override; 88 | virtual void resize (const BUtilities::Point extends) override; 89 | 90 | /** 91 | * Changes the value of the widget (0.0 == off, 0.0 != off) and relocates 92 | * the embedded label widget.. 93 | * Emits a value changed event and (if visible) an expose event. 94 | * @param val Value 95 | */ 96 | virtual void setValue (const double val) override; 97 | 98 | /** 99 | * Gets (a pointer to) the Label for direct access. 100 | * @return Pointer to the label 101 | */ 102 | Label* getLabel (); 103 | 104 | /** 105 | * Scans theme for widget properties and applies these properties. 106 | * @param theme Theme to be scanned. 107 | * For styles used see BWidgets::Button::applyTheme and 108 | * BWidgets::Label::applyTheme. 109 | * @param name Name of the BStyles::StyleSet within the theme to be 110 | * applied. 111 | */ 112 | virtual void applyTheme (BStyles::Theme& theme) override; 113 | virtual void applyTheme (BStyles::Theme& theme, const std::string& name) override; 114 | 115 | protected: 116 | Label buttonLabel; 117 | }; 118 | 119 | } 120 | 121 | #endif /* BWIDGETS_TOGGLEBUTTON_HPP_ */ 122 | -------------------------------------------------------------------------------- /BWidgets/TextToggleButton.cpp: -------------------------------------------------------------------------------- 1 | /* TextToggleButton.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 . 16 | */ 17 | 18 | #include "TextToggleButton.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | TextToggleButton::TextToggleButton () : TextToggleButton (0.0, 0.0, BWIDGETS_DEFAULT_BUTTON_WIDTH, BWIDGETS_DEFAULT_BUTTON_HEIGHT, 23 | "texttogglebutton", "", 0.0) {} 24 | 25 | TextToggleButton::TextToggleButton (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue) : 26 | TextToggleButton (x, y, width, height, name, name, defaultValue) {} 27 | 28 | TextToggleButton::TextToggleButton (const double x, const double y, const double width, const double height, 29 | const std::string& name, const std::string& label, double defaultValue) : 30 | ToggleButton (x, y, width, height, name, defaultValue), 31 | buttonLabel (0, 0, width, height, name, label) 32 | { 33 | buttonLabel.setClickable (false); 34 | buttonLabel.setState (defaultValue ? BColors::ACTIVE : BColors::NORMAL); 35 | buttonLabel.setBorder (BWIDGETS_DEFAULT_MENU_TEXTBORDER); 36 | add (buttonLabel); 37 | } 38 | 39 | TextToggleButton::TextToggleButton (const TextToggleButton& that) : ToggleButton (that), buttonLabel (that.buttonLabel) 40 | { 41 | add (buttonLabel); 42 | } 43 | 44 | TextToggleButton:: ~TextToggleButton () {} 45 | 46 | TextToggleButton& TextToggleButton::operator= (const TextToggleButton& that) 47 | { 48 | release (&buttonLabel); 49 | 50 | ToggleButton::operator= (that); 51 | buttonLabel = that.buttonLabel; 52 | 53 | add (buttonLabel); 54 | 55 | return *this; 56 | } 57 | 58 | Widget* TextToggleButton::clone () const {return new TextToggleButton (*this);} 59 | 60 | void TextToggleButton::setWidth (const double width) 61 | { 62 | Button::setWidth (width); 63 | buttonLabel.setWidth (width); 64 | } 65 | 66 | void TextToggleButton::setHeight (const double height) 67 | { 68 | Button::setHeight (height); 69 | buttonLabel.setHeight (height); 70 | } 71 | 72 | void TextToggleButton::resize () 73 | { 74 | buttonLabel.resize (); 75 | Widget::resize (); 76 | } 77 | 78 | void TextToggleButton::resize (const double width, const double height) {TextToggleButton::resize (BUtilities::Point (width, height));} 79 | 80 | void TextToggleButton::resize (const BUtilities::Point extends) 81 | { 82 | Widget::resize (BUtilities::Point (extends.x, extends.y)); 83 | buttonLabel.resize (BUtilities::Point (extends.x, extends.y)); 84 | } 85 | 86 | void TextToggleButton::setValue (const double val) 87 | { 88 | if (val) buttonLabel.setState (BColors::ACTIVE); 89 | else buttonLabel.setState (BColors::NORMAL); 90 | Button::setValue (val); 91 | } 92 | 93 | Label* TextToggleButton::getLabel () {return &buttonLabel;} 94 | 95 | void TextToggleButton::applyTheme (BStyles::Theme& theme) {applyTheme (theme, name_);} 96 | void TextToggleButton::applyTheme (BStyles::Theme& theme, const std::string& name) 97 | { 98 | ToggleButton::applyTheme (theme, name); 99 | buttonLabel.applyTheme (theme, name); 100 | update (); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /BWidgets/TextToggleButton.hpp: -------------------------------------------------------------------------------- 1 | /* TextToggleButton.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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_TEXTTOGGLEBUTTON_HPP_ 19 | #define BWIDGETS_TEXTTOGGLEBUTTON_HPP_ 20 | 21 | #include "ToggleButton.hpp" 22 | #include "Label.hpp" 23 | 24 | namespace BWidgets 25 | { 26 | /** 27 | * Class BWidgets::TextToggleButton 28 | * 29 | * Text button widget. Is is a BWidgets::ToggleButton and thus a 30 | * BWidgets::ValueWidget having two conditions: on (value != 0) or off 31 | * (value == 0) 32 | */ 33 | class TextToggleButton : public ToggleButton 34 | { 35 | public: 36 | TextToggleButton (); 37 | TextToggleButton (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue = 0.0); 38 | TextToggleButton (const double x, const double y, const double width, const double height, 39 | const std::string& name, const std::string& label, double defaultValue = 0.0); 40 | 41 | /** 42 | * Creates a new (orphan) button and copies the button properties from a 43 | * source button. 44 | * @param that Source button 45 | */ 46 | TextToggleButton (const TextToggleButton& that); 47 | 48 | ~TextToggleButton (); 49 | 50 | /** 51 | * Assignment. Copies the widget properties from a source button and keeps 52 | * its name and its position within the widget tree. Emits a 53 | * BEvents::ExposeEvent if the widget is visible. 54 | * @param that Source button 55 | */ 56 | TextToggleButton& operator= (const TextToggleButton& that); 57 | 58 | /** 59 | * Pattern cloning. Creates a new instance of the widget and copies all 60 | * its properties. 61 | */ 62 | virtual Widget* clone () const override; 63 | 64 | /** 65 | * Resizes the widget and its predefined child, redraw and emits a 66 | * BEvents::ExposeEvent if the widget is visible. 67 | * @param width New widgets width 68 | */ 69 | virtual void setWidth (const double width) override; 70 | 71 | /** 72 | * Resizes the widget and its predefined child, redraw and emits a 73 | * BEvents::ExposeEvent if the widget is visible. 74 | * @param height New widgets height 75 | */ 76 | virtual void setHeight (const double height) override; 77 | 78 | /** 79 | * Resizes the widget, redraw and emits a BEvents::ExposeEvent if the 80 | * widget is visible. If no parameters are given, the widget will be 81 | * resized to the size of the containing child widgets. 82 | * @param width New widgets width 83 | * @param height New widgets height 84 | * @param extends New widget extends 85 | */ 86 | virtual void resize () override; 87 | virtual void resize (const double width, const double height) override; 88 | virtual void resize (const BUtilities::Point extends) override; 89 | 90 | /** 91 | * Changes the value of the widget (0.0 == off, 0.0 != off) and relocates 92 | * the embedded label widget.. 93 | * Emits a value changed event and (if visible) an expose event. 94 | * @param val Value 95 | */ 96 | virtual void setValue (const double val) override; 97 | 98 | /** 99 | * Gets (a pointer to) the Label for direct access. 100 | * @return Pointer to the label 101 | */ 102 | Label* getLabel (); 103 | 104 | /** 105 | * Scans theme for widget properties and applies these properties. 106 | * @param theme Theme to be scanned. 107 | * For styles used see BWidgets::Button::applyTheme and 108 | * BWidgets::Label::applyTheme. 109 | * @param name Name of the BStyles::StyleSet within the theme to be 110 | * applied. 111 | */ 112 | virtual void applyTheme (BStyles::Theme& theme) override; 113 | virtual void applyTheme (BStyles::Theme& theme, const std::string& name) override; 114 | 115 | protected: 116 | Label buttonLabel; 117 | }; 118 | 119 | } 120 | 121 | #endif /* BWIDGETS_TEXTTOGGLEBUTTON_HPP_ */ 122 | -------------------------------------------------------------------------------- /BWidgets/ToggleButton.cpp: -------------------------------------------------------------------------------- 1 | /* ToggleButton.cpp 2 | * Copyright (C) 2018 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 . 16 | */ 17 | 18 | #include "ToggleButton.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | ToggleButton::ToggleButton () : ToggleButton (0.0, 0.0, BWIDGETS_DEFAULT_BUTTON_WIDTH, BWIDGETS_DEFAULT_BUTTON_HEIGHT, "togglebutton", 0.0) {} 23 | 24 | ToggleButton::ToggleButton (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue) : 25 | Button (x, y, width, height, name, defaultValue) {} 26 | 27 | Widget* ToggleButton::clone () const {return new ToggleButton (*this);} 28 | 29 | void ToggleButton::onButtonPressed (BEvents::PointerEvent* event) 30 | { 31 | if (getValue ()) setValue (0.0); 32 | else setValue (1.0); 33 | 34 | Widget::cbfunction_[BEvents::EventType::BUTTON_PRESS_EVENT] (event); 35 | } 36 | 37 | void ToggleButton::onButtonReleased (BEvents::PointerEvent* event) 38 | { 39 | Widget::cbfunction_[BEvents::EventType::BUTTON_RELEASE_EVENT] (event); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /BWidgets/ToggleButton.hpp: -------------------------------------------------------------------------------- 1 | /* ToggleButton.hpp 2 | * Copyright (C) 2018 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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_TOGGLEBUTTON_HPP_ 19 | #define BWIDGETS_TOGGLEBUTTON_HPP_ 20 | 21 | #include "Button.hpp" 22 | 23 | namespace BWidgets 24 | { 25 | /** 26 | * Class BWidgets::ToggleButton 27 | * 28 | * Basic toggle button widget. Is is a BWidgets::Button and thus a 29 | * BWidgets::ValueWidget having two conditions: on (value != 0) or off 30 | * (value == 0) 31 | */ 32 | class ToggleButton : public Button 33 | { 34 | public: 35 | ToggleButton (); 36 | ToggleButton (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue = 0.0); 37 | 38 | /** 39 | * Pattern cloning. Creates a new instance of the widget and copies all 40 | * its properties. 41 | */ 42 | virtual Widget* clone () const override; 43 | 44 | /** 45 | * Handles the BEvents::BUTTON_PRESS_EVENT. 46 | * @param event Pointer to a pointer event emitted by the same widget. 47 | */ 48 | virtual void onButtonPressed (BEvents::PointerEvent* event) override; 49 | 50 | /** 51 | * Overrides the BEvents::BUTTON_RELEASED_EVENT handled by 52 | * BWidgets::Button. 53 | * @param event Pointer to a pointer event emitted by the same widget. 54 | */ 55 | virtual void onButtonReleased (BEvents::PointerEvent* event) override; 56 | }; 57 | 58 | } 59 | 60 | 61 | 62 | 63 | #endif /* BWIDGETS_TOGGLEBUTTON_HPP_ */ 64 | -------------------------------------------------------------------------------- /BWidgets/UpButton.cpp: -------------------------------------------------------------------------------- 1 | /* UpButton.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 . 16 | */ 17 | 18 | #include "UpButton.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | UpButton::UpButton () : 23 | UpButton (0.0, 0.0, BWIDGETS_DEFAULT_BUTTON_WIDTH, BWIDGETS_DEFAULT_BUTTON_HEIGHT, "upbutton", 0.0) {} 24 | 25 | UpButton::UpButton (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 | 28 | Widget* UpButton::clone () const {return new UpButton (*this);} 29 | 30 | void UpButton::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 - size/2, y0 + h/2 + size/4); 60 | cairo_line_to (cr, x0 + w/2, y0 + h/2 - size/4); 61 | cairo_line_to (cr, x0 + w/2 + size/2, y0 + h/2 + size/4); 62 | cairo_set_source_rgba (cr, CAIRO_RGBA (frColor)); 63 | cairo_stroke (cr); 64 | 65 | cairo_destroy (cr); 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /BWidgets/UpButton.hpp: -------------------------------------------------------------------------------- 1 | /* UpButton.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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_UPBUTTON_HPP_ 19 | #define BWIDGETS_UPBUTTON_HPP_ 20 | 21 | #include "Button.hpp" 22 | #include "Label.hpp" 23 | 24 | namespace BWidgets 25 | { 26 | /** 27 | * Class BWidgets::UpButton 28 | * 29 | * Text button widget. Is is a BWidgets::Button and thus a 30 | * BWidgets::ValueWidget having two conditions: on (value != 0) or off 31 | * (value == 0) 32 | */ 33 | class UpButton : public Button 34 | { 35 | public: 36 | UpButton (); 37 | UpButton (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue = 0.0); 38 | 39 | /** 40 | * Pattern cloning. Creates a new instance of the widget and copies all 41 | * its properties. 42 | */ 43 | virtual Widget* clone () const override; 44 | 45 | protected: 46 | virtual void draw (const BUtilities::RectArea& area) override; 47 | }; 48 | 49 | } 50 | 51 | #endif /* BWIDGETS_TOGGLEBUTTON_HPP_ */ 52 | -------------------------------------------------------------------------------- /BWidgets/VScale.hpp: -------------------------------------------------------------------------------- 1 | /* VScale.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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_VSCALE_HPP_ 19 | #define BWIDGETS_VSCALE_HPP_ 20 | 21 | #include "RangeWidget.hpp" 22 | 23 | #define BWIDGETS_DEFAULT_VSCALE_WIDTH 100.0 24 | #define BWIDGETS_DEFAULT_VSCALE_HEIGHT 6.0 25 | #define BWIDGETS_DEFAULT_VSCALE_DEPTH 1.0 26 | 27 | namespace BWidgets 28 | { 29 | /** 30 | * Class BWidgets::VScale 31 | * 32 | * RangeWidget class for a simple vertical scale. 33 | * The Widget is clickable by default. 34 | */ 35 | class VScale : public RangeWidget 36 | { 37 | public: 38 | VScale (); 39 | VScale (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 | VScale (const VScale& 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 | VScale& operator= (const VScale& 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 | BUtilities::RectArea scaleArea; 118 | double scaleYValue; 119 | }; 120 | 121 | } 122 | 123 | #endif /* BWIDGETS_VSCALE_HPP_ */ 124 | -------------------------------------------------------------------------------- /BWidgets/VSlider.hpp: -------------------------------------------------------------------------------- 1 | /* VSlider.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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_VSLIDER_HPP_ 19 | #define BWIDGETS_VSLIDER_HPP_ 20 | 21 | #define BWIDGETS_DEFAULT_VSLIDER_WIDTH (BWIDGETS_DEFAULT_VSCALE_WIDTH * 2) 22 | #define BWIDGETS_DEFAULT_VSLIDER_HEIGHT BWIDGETS_DEFAULT_VSCALE_HEIGHT 23 | #define BWIDGETS_DEFAULT_VSLIDER_DEPTH 1.0 24 | 25 | #include "Knob.hpp" 26 | #include "VScale.hpp" 27 | #include "Label.hpp" 28 | #include "Focusable.hpp" 29 | 30 | namespace BWidgets 31 | { 32 | /** 33 | * Class BWidgets::VSlider 34 | * 35 | * RangeWidget class for a vertical slider. 36 | * The Widget is clickable by default. 37 | */ 38 | class VSlider : public VScale, public Focusable 39 | { 40 | public: 41 | VSlider (); 42 | VSlider (const double x, const double y, const double width, const double height, const std::string& name, 43 | const double value, const double min, const double max, const double step); 44 | 45 | /** 46 | * Creates a new (orphan) slider and copies the slider properties from a 47 | * source slider. 48 | * @param that Source slider 49 | */ 50 | VSlider (const VSlider& that); 51 | 52 | /** 53 | * Assignment. Copies the slider properties from a source slider and keeps 54 | * its name and its position within the widget tree. Emits an expose event 55 | * if the widget is visible and a value changed event. 56 | * @param that Source slider 57 | */ 58 | VSlider& operator= (const VSlider& that); 59 | 60 | /** 61 | * Pattern cloning. Creates a new instance of the widget and copies all 62 | * its properties. 63 | */ 64 | virtual Widget* clone () const override; 65 | 66 | /** 67 | * Changes the value of the widget and keeps it within the defined range. 68 | * Passes the value to its predefined child widgets. 69 | * Emits a value changed event and (if visible) an expose event. 70 | * @param val Value 71 | */ 72 | virtual void setValue (const double val) override; 73 | 74 | /** 75 | * Calls a redraw of the widget and calls postRedisplay () if the the 76 | * Widget is visible. 77 | * This method should be called if the widgets properties are indirectly 78 | * changed. 79 | */ 80 | virtual void update () override; 81 | 82 | /** 83 | * Scans theme for widget properties and applies these properties. 84 | * @param theme Theme to be scanned. 85 | * styles used are: 86 | * BWIDGETS_KEYWORD_BORDER 87 | * BWIDGETS_KEYWORD_BACKGROUND 88 | * BWIDGETS_KEYWORD_FGCOLORS 89 | * BWIDGETS_KEYWORD_BGCOLORS 90 | * @param name Name of the BStyles::StyleSet within the theme to be 91 | * applied. 92 | */ 93 | virtual void applyTheme (BStyles::Theme& theme) override; 94 | virtual void applyTheme (BStyles::Theme& theme, const std::string& name) override; 95 | 96 | /** 97 | * Predefined empty method to handle a 98 | * BEvents::EventType::FOCUS_IN_EVENT. 99 | * @param event Focus event 100 | */ 101 | virtual void onFocusIn (BEvents::FocusEvent* event) override; 102 | 103 | /** 104 | * Predefined empty method to handle a 105 | * BEvents::EventType::FOCUS_OUT_EVENT. 106 | * @param event Focus event 107 | */ 108 | virtual void onFocusOut (BEvents::FocusEvent* event) override; 109 | 110 | protected: 111 | virtual void updateCoords () override; 112 | 113 | Knob knob; 114 | Label focusLabel; 115 | double knobRadius; 116 | BUtilities::Point knobPosition; 117 | }; 118 | 119 | } 120 | 121 | #endif /* BWIDGETS_VSLIDER_HPP_ */ 122 | -------------------------------------------------------------------------------- /BWidgets/VSwitch.cpp: -------------------------------------------------------------------------------- 1 | /* VSwitch.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 . 16 | */ 17 | 18 | #include "VSwitch.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | VSwitch::VSwitch () : VSwitch (0.0, 0.0, BWIDGETS_DEFAULT_VSWITCH_WIDTH, BWIDGETS_DEFAULT_VSWITCH_HEIGHT, "vswitch", BWIDGETS_DEFAULT_VALUE) {} 23 | 24 | VSwitch::VSwitch (const double x, const double y, const double width, const double height, const std::string& name, 25 | const double defaultvalue) : 26 | VSlider (x, y, width, height, name, defaultvalue, 0.0, 1.0, 1.0), dragged (false) {} 27 | 28 | Widget* VSwitch::clone () const {return new VSwitch (*this);} 29 | 30 | void VSwitch::onButtonPressed (BEvents::PointerEvent* event) {dragged = false;} 31 | 32 | void VSwitch::onButtonReleased (BEvents::PointerEvent* event) 33 | { 34 | if (!dragged) 35 | { 36 | if (getValue() == getMin ()) setValue (getMax ()); 37 | else setValue (getMin ()); 38 | } 39 | } 40 | 41 | void VSwitch::onPointerDragged (BEvents::PointerEvent* event) 42 | { 43 | dragged = true; 44 | VScale::onButtonPressed (event); 45 | } 46 | 47 | void VSwitch::updateCoords () 48 | { 49 | double w = getEffectiveWidth (); 50 | double h = getEffectiveHeight (); 51 | 52 | knobRadius = (w < h / 2 ? w / 2 : h / 4); 53 | scaleArea = BUtilities::RectArea 54 | ( 55 | getXOffset () + w / 2 - knobRadius, 56 | getYOffset (), 57 | 2 * knobRadius, 58 | h 59 | ); 60 | scaleYValue = scaleArea.getY() + knobRadius + (1 - getRelativeValue ()) * (scaleArea.getHeight() - 2 * knobRadius); 61 | 62 | knobPosition = BUtilities::Point 63 | ( 64 | scaleArea.getX() + scaleArea.getWidth() / 2 + BWIDGETS_DEFAULT_KNOB_DEPTH, 65 | scaleYValue + BWIDGETS_DEFAULT_KNOB_DEPTH 66 | ); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /BWidgets/VSwitch.hpp: -------------------------------------------------------------------------------- 1 | /* VSwitch.hpp 2 | * Copyright (C) 2018 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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_VSWITCH_HPP_ 19 | #define BWIDGETS_VSWITCH_HPP_ 20 | 21 | #include "Knob.hpp" 22 | #include "VSlider.hpp" 23 | 24 | #define BWIDGETS_DEFAULT_VSWITCH_WIDTH 40.0 25 | #define BWIDGETS_DEFAULT_VSWITCH_HEIGHT 20.0 26 | #define BWIDGETS_DEFAULT_VSWITCH_DEPTH 1.0 27 | 28 | namespace BWidgets 29 | { 30 | /** 31 | * Class BWidgets::VSwitch 32 | * 33 | * On/OFF switch widget. Is is a BWidgets::VSlider having two conditions: on 34 | * (value != 0) or off (value == 0) 35 | */ 36 | class VSwitch : public VSlider 37 | { 38 | public: 39 | VSwitch (); 40 | VSwitch (const double x, const double y, const double width, const double height, const std::string& name, const double defaultvalue); 41 | 42 | /** 43 | * Pattern cloning. Creates a new instance of the widget and copies all 44 | * its properties. 45 | */ 46 | virtual Widget* clone () const override; 47 | 48 | /** 49 | * Handles the BEvents::BUTTON_PRESS_EVENT to move the slider. 50 | * @param event Pointer to a pointer event emitted by the same widget. 51 | */ 52 | virtual void onButtonPressed (BEvents::PointerEvent* event) override; 53 | 54 | /** 55 | * Handles the BEvents::EventType::BUTTON_RELEASE_EVENT to move the slider. 56 | * @param event Pointer event 57 | */ 58 | virtual void onButtonReleased (BEvents::PointerEvent* event) override; 59 | 60 | /** 61 | * Handles the BEvents::POINTER_DRAG_EVENT to move 62 | * the slider. 63 | * @param event Pointer to a pointer event emitted by the same widget. 64 | */ 65 | virtual void onPointerDragged (BEvents::PointerEvent* event) override; 66 | 67 | protected: 68 | virtual void updateCoords () override; 69 | 70 | bool dragged; 71 | }; 72 | 73 | } 74 | 75 | #endif /* BWIDGETS_VSWITCH_HPP_ */ 76 | -------------------------------------------------------------------------------- /BWidgets/ValueWidget.cpp: -------------------------------------------------------------------------------- 1 | /* ValueWidget.cpp 2 | * Copyright (C) 2018 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 . 16 | */ 17 | 18 | #include "ValueWidget.hpp" 19 | 20 | namespace BWidgets 21 | { 22 | ValueWidget::ValueWidget () : ValueWidget (0, 0, BWIDGETS_DEFAULT_WIDTH, BWIDGETS_DEFAULT_HEIGHT, "valuewidget", BWIDGETS_DEFAULT_VALUE) {} 23 | 24 | ValueWidget::ValueWidget (const double x, const double y, const double width, const double height, const std::string& name, const double value) : 25 | Widget (x, y, width, height, name), value (value), valueable_ (true), hardChangeable (true), softValue (0.0) {} 26 | 27 | ValueWidget::ValueWidget (const ValueWidget& that) : 28 | Widget (that), value (that.value), valueable_ (that.valueable_), hardChangeable (that.hardChangeable), softValue (that.softValue) {} 29 | 30 | ValueWidget::~ValueWidget () {} 31 | 32 | ValueWidget& ValueWidget::operator= (const ValueWidget& that) 33 | { 34 | Widget::operator= (that); 35 | valueable_ = that.valueable_; 36 | hardChangeable = that.hardChangeable; 37 | softValue = that.softValue; 38 | setValue (that.value); 39 | return *this; 40 | } 41 | 42 | Widget* ValueWidget::clone () const {return new ValueWidget (*this);} 43 | 44 | void ValueWidget::setValue (const double val) 45 | { 46 | if (val != value) 47 | { 48 | value = val; 49 | softValue = 0.0; 50 | update (); 51 | if (valueable_) postValueChanged (); 52 | } 53 | } 54 | 55 | double ValueWidget::getValue () const {return value;} 56 | 57 | void ValueWidget::setValueable (const bool status) {valueable_ = status;} 58 | 59 | bool ValueWidget::isValueable () const {return valueable_;} 60 | 61 | void ValueWidget::setHardChangeable (const bool status) {hardChangeable = status;} 62 | 63 | bool ValueWidget::isHardChangeable () const {return hardChangeable;} 64 | 65 | void ValueWidget::postValueChanged () 66 | { 67 | if (main_) 68 | { 69 | BEvents::ValueChangedEvent* event = new BEvents::ValueChangedEvent (this, value); 70 | main_->addEventToQueue (event); 71 | } 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /BWidgets/ValueWidget.hpp: -------------------------------------------------------------------------------- 1 | /* ValueWidget.hpp 2 | * Copyright (C) 2018 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 . 16 | */ 17 | 18 | #ifndef BWIDGETS_VALUEWIDGET_HPP_ 19 | #define BWIDGETS_VALUEWIDGET_HPP_ 20 | 21 | #include "Widget.hpp" 22 | #include "Window.hpp" 23 | 24 | #define BWIDGETS_DEFAULT_VALUE 0.0 25 | #define BWIDGETS_DEFAULT_VALUE_FORMAT "%3.2f" 26 | 27 | namespace BWidgets 28 | { 29 | 30 | /** 31 | * Class BWidgets::ValueWidget 32 | * 33 | * Root class for all widgets that deal with values (dials, sliders, ...). 34 | */ 35 | class ValueWidget : public Widget 36 | { 37 | public: 38 | ValueWidget (); 39 | ValueWidget (const double x, const double y, const double width, const double height, const std::string& name, const double value); 40 | 41 | /** 42 | * Creates a new (orphan) widget and copies the widget properties from a 43 | * source widget. This method doesn't copy any parent or child widgets. 44 | * @param that Source widget 45 | */ 46 | ValueWidget (const ValueWidget& that); 47 | 48 | ~ValueWidget (); 49 | 50 | /** 51 | * Assignment. Copies the widget properties from a source widget and keeps 52 | * its name and its position within the widget tree. Emits an expose event 53 | * if the widget is visible and a value changed event. 54 | * @param that Source widget 55 | */ 56 | ValueWidget& operator= (const ValueWidget& that); 57 | 58 | /** 59 | * Pattern cloning. Creates a new instance of the widget and copies all 60 | * its properties. 61 | */ 62 | virtual Widget* clone () const override; 63 | 64 | /** 65 | * Changes the value of the widget. Emits a value changed event and (if 66 | * visible) an expose event. 67 | * @param val Value 68 | */ 69 | virtual void setValue (const double val); 70 | 71 | /** 72 | * Gets the value of the widget. 73 | * @return Value 74 | */ 75 | virtual double getValue () const; 76 | 77 | virtual void setValueable (const bool status); 78 | 79 | virtual bool isValueable () const; 80 | 81 | /** 82 | * Defines whether the widget may allow direct setting of a value by 83 | * clicking or it only allows relative changes by dragging. 84 | * @param status TRUE if direct setting is allowed, otherwise false 85 | */ 86 | void setHardChangeable (const bool status); 87 | 88 | /** 89 | * Gets whether the widget may allow direct setting of a value by 90 | * clicking or it only allows relative changes by dragging. 91 | * @return TRUE if direct setting is allowed, otherwise false 92 | */ 93 | bool isHardChangeable () const; 94 | 95 | protected: 96 | void postValueChanged (); 97 | double value; 98 | bool valueable_; 99 | bool hardChangeable; 100 | double softValue; 101 | }; 102 | 103 | } 104 | 105 | #endif /* BWIDGETS_VALUEWIDGET_HPP_ */ 106 | -------------------------------------------------------------------------------- /BWidgets/cairoplus.h: -------------------------------------------------------------------------------- 1 | /* cairoplus.h 2 | * Copyright (C) 2018 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 . 16 | */ 17 | 18 | #ifndef CAIROPLUS_H_ 19 | #define CAIROPLUS_H_ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif /* __cplusplus */ 30 | 31 | typedef struct { 32 | double red; 33 | double green; 34 | double blue; 35 | double alpha; 36 | } cairo_rgba; 37 | 38 | typedef struct { 39 | char family[64]; 40 | double size; 41 | cairo_font_slant_t slant; 42 | cairo_font_weight_t weight; 43 | } cairo_text_decorations; 44 | 45 | /** 46 | * Draws a rectangle with selected rounded edges. 47 | * @param cr Cairo context. 48 | * @param x X coordinate upper right 49 | * @param y Y coordinate upper right 50 | * @param width Rectangle width 51 | * @param height Rectangle height 52 | * @param radius Radius of edges 53 | * @param corners Optional, bits set for the corners with rounded edges in 54 | * clockwise direction starting with upper right 55 | */ 56 | void cairo_rectangle_rounded (cairo_t* cr, double x, double y, double width, double height, double radius, uint8_t corners); 57 | 58 | /** 59 | * Creates a new Cairo image surface and copies the content from a source Cairo 60 | * image surface. 61 | * @param sourceSurface Source Cairo (image) surface. 62 | * @return Created new Cairo image surface. 63 | */ 64 | cairo_surface_t* cairo_image_surface_clone_from_image_surface (cairo_surface_t* sourceSurface); 65 | 66 | /** 67 | * Clears a Cairo surface. 68 | * @param surface Cairo surface. 69 | */ 70 | void cairo_surface_clear (cairo_surface_t* surface); 71 | 72 | /** 73 | * Splits off a text that fits within an output area defined by its width. 74 | * @param cr Cairo context. 75 | * @param decorations Cairo plus font decorations 76 | * @param text Text to be parsed. The output text will be clipped off 77 | * and thus the text will be shortened 78 | * @return New created output text. Note, it will never return NULL. 79 | * If memory allocation fails, a pointer to a nil text will 80 | * be returned. 81 | */ 82 | char* cairo_create_text_fitted (cairo_t* cr, double width, cairo_text_decorations decorations, char* text); 83 | 84 | /** 85 | * Destroys a Cairo plus text and frees memory. 86 | * @param text Cairo plus text. 87 | */ 88 | void cairo_text_destroy (char* text); 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif /* __cplusplus */ 93 | 94 | #endif /* CAIROPLUS_H_ */ 95 | -------------------------------------------------------------------------------- /BWidgets/pugl/.clang-tidy: -------------------------------------------------------------------------------- 1 | Checks: > 2 | *, 3 | -*-uppercase-literal-suffix, 4 | -*magic-numbers, 5 | -bugprone-reserved-identifier, 6 | -bugprone-suspicious-string-compare, 7 | -cert-dcl37-c, 8 | -cert-dcl51-cpp, 9 | -cert-flp30-c, 10 | -clang-analyzer-security.FloatLoopCounter, 11 | -clang-diagnostic-unused-macros, 12 | -hicpp-multiway-paths-covered, 13 | -hicpp-signed-bitwise, 14 | -llvm-header-guard, 15 | -llvmlibc-*, 16 | FormatStyle: file 17 | HeaderFilterRegex: 'pugl/.*' 18 | -------------------------------------------------------------------------------- /BWidgets/pugl/AUTHORS: -------------------------------------------------------------------------------- 1 | Pugl is primarily written and maintained by David Robillard 2 | with contributions from (in increasing chronological order): 3 | 4 | Ben Loftis 5 | Robin Gareus 6 | Erik Åldstedt Sund 7 | Hanspeter Portner 8 | Stefan Westerfeld 9 | Jordan Halase 10 | Oliver Schmidt 11 | Zoë Sparks 12 | Jean Pierre Cimalando 13 | Thomas Brand 14 | -------------------------------------------------------------------------------- /BWidgets/pugl/COPYING: -------------------------------------------------------------------------------- 1 | Copyright 2011-2020 David Robillard 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any 4 | purpose with or without fee is hereby granted, provided that the above 5 | copyright notice and this permission notice appear in all copies. 6 | 7 | THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | -------------------------------------------------------------------------------- /BWidgets/pugl/README.md: -------------------------------------------------------------------------------- 1 | Pugl 2 | ==== 3 | 4 | Pugl (PlUgin Graphics Library) is a minimal portable API for GUIs which is 5 | suitable for use in plugins. It works on X11, MacOS, and Windows, and 6 | optionally supports Vulkan, OpenGL, and Cairo graphics contexts. 7 | 8 | Pugl is vaguely similar to libraries like GLUT and GLFW, but with some 9 | distinguishing features: 10 | 11 | * Minimal in scope, providing only a thin interface to isolate 12 | platform-specific details from applications. 13 | 14 | * Zero dependencies, aside from standard system libraries. 15 | 16 | * Support for embedding in native windows, for example as a plugin or 17 | component within a larger application that is not based on Pugl. 18 | 19 | * Simple and extensible event-based API that makes dispatching in application 20 | or toolkit code easy with minimal boilerplate. 21 | 22 | * Suitable not only for continuously rendering applications like games, but 23 | also event-driven applications that only draw when necessary. 24 | 25 | * Explicit context and no static data whatsoever, so that several instances 26 | can be used within a single program at once. 27 | 28 | * Small, liberally licensed Free Software implementation that is suitable for 29 | vendoring and/or static linking. Pugl can be installed as a library, or 30 | used by simply copying the headers into a project. 31 | 32 | Stability 33 | --------- 34 | 35 | Pugl is currently being developed towards a long-term stable API. For the time 36 | being, however, the API may break occasionally. Please report any relevant 37 | feedback, or file feature requests, so that we can ensure that the released API 38 | is stable for as long as possible. 39 | 40 | Documentation 41 | ------------- 42 | 43 | Pugl is a C library that includes C++ bindings. 44 | Each API is documented separately: 45 | 46 | * [C Documentation (single page)](https://lv2.gitlab.io/pugl/c/singlehtml/) 47 | * [C Documentation (paginated)](https://lv2.gitlab.io/pugl/c/html/) 48 | * [C++ Documentation (single page)](https://lv2.gitlab.io/pugl/cpp/singlehtml/) 49 | * [C++ Documentation (paginated)](https://lv2.gitlab.io/pugl/cpp/html/) 50 | 51 | The documentation can also be built from the source by configuring with `--docs`. 52 | 53 | Testing 54 | ------- 55 | 56 | There are a few unit tests included, but unfortunately manual testing is still 57 | required. The tests and example programs will be built if you pass the 58 | `--test` option when configuring: 59 | 60 | ./waf configure --test 61 | 62 | Then, after building, the unit tests can be run: 63 | 64 | ./waf 65 | ./waf test --gui-tests 66 | 67 | The `examples` directory contains several programs that serve as both manual 68 | tests and demonstrations: 69 | 70 | * `pugl_embed_demo` shows a view embedded in another, and also tests 71 | requesting attention (which happens after 5 seconds), keyboard focus 72 | (switched by pressing tab), view moving (with the arrow keys), and view 73 | resizing (with the arrow keys while shift is held). This program uses only 74 | very old OpenGL and should work on any system. 75 | 76 | * `pugl_window_demo` demonstrates multiple top-level windows. 77 | 78 | * `pugl_shader_demo` demonstrates using more modern OpenGL (version 3 or 4) 79 | where dynamic loading and shaders are required. It can also be used to test 80 | performance by passing the number of rectangles to draw on the command line. 81 | 82 | * `pugl_cairo_demo` demonstrates using Cairo on top of the native windowing 83 | system (without OpenGL), and partial redrawing. 84 | 85 | * `pugl_print_events` is a utility that prints all received events to the 86 | console in a human readable format. 87 | 88 | * `pugl_cxx_demo` is a simple cube demo that uses the C++ API. 89 | 90 | * `pugl_vulkan_demo` is a simple example of using Vulkan in C that simply 91 | clears the window. 92 | 93 | * `pugl_vulkan_cxx_demo` is a more advanced Vulkan demo in C++ that draws many 94 | animated rectangles like `pugl_shader_demo`. 95 | 96 | All example programs support several command line options to control various 97 | behaviours, see the output of `--help` for details. Please file an issue if 98 | any of these programs do not work as expected on your system. 99 | 100 | -- David Robillard 101 | -------------------------------------------------------------------------------- /BWidgets/pugl/implementation.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2020 David Robillard 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef PUGL_IMPLEMENTATION_H 18 | #define PUGL_IMPLEMENTATION_H 19 | 20 | #include "types.h" 21 | 22 | #include "pugl/pugl.h" 23 | 24 | #include 25 | #include 26 | 27 | PUGL_BEGIN_DECLS 28 | 29 | /// Set `blob` to `data` with length `len`, reallocating if necessary 30 | void 31 | puglSetBlob(PuglBlob* dest, const void* data, size_t len); 32 | 33 | /// Reallocate and set `*dest` to `string` 34 | void 35 | puglSetString(char** dest, const char* string); 36 | 37 | /// Allocate and initialise world internals (implemented once per platform) 38 | PuglWorldInternals* 39 | puglInitWorldInternals(PuglWorldType type, PuglWorldFlags flags); 40 | 41 | /// Destroy and free world internals (implemented once per platform) 42 | void 43 | puglFreeWorldInternals(PuglWorld* world); 44 | 45 | /// Allocate and initialise view internals (implemented once per platform) 46 | PuglInternals* 47 | puglInitViewInternals(void); 48 | 49 | /// Destroy and free view internals (implemented once per platform) 50 | void 51 | puglFreeViewInternals(PuglView* view); 52 | 53 | /// Return the Unicode code point for `buf` or the replacement character 54 | uint32_t 55 | puglDecodeUTF8(const uint8_t* buf); 56 | 57 | /// Dispatch an event with a simple `type` to `view` 58 | void 59 | puglDispatchSimpleEvent(PuglView* view, PuglEventType type); 60 | 61 | /// Dispatch `event` to `view` while already in the graphics context 62 | void 63 | puglDispatchEventInContext(PuglView* view, const PuglEvent* event); 64 | 65 | /// Dispatch `event` to `view`, entering graphics context if necessary 66 | void 67 | puglDispatchEvent(PuglView* view, const PuglEvent* event); 68 | 69 | /// Set internal (stored in view) clipboard contents 70 | const void* 71 | puglGetInternalClipboard(const PuglView* view, const char** type, size_t* len); 72 | 73 | /// Set internal (stored in view) clipboard contents 74 | PuglStatus 75 | puglSetInternalClipboard(PuglView* view, 76 | const char* type, 77 | const void* data, 78 | size_t len); 79 | 80 | PUGL_END_DECLS 81 | 82 | #endif // PUGL_IMPLEMENTATION_H 83 | -------------------------------------------------------------------------------- /BWidgets/pugl/mac.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2020 David Robillard 3 | Copyright 2017 Hanspeter Portner 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #ifndef PUGL_DETAIL_MAC_H 19 | #define PUGL_DETAIL_MAC_H 20 | 21 | #include "pugl/pugl.h" 22 | 23 | #import 24 | 25 | #include 26 | 27 | @interface PuglWrapperView : NSView 28 | 29 | - (void)dispatchExpose:(NSRect)rect; 30 | - (void)setReshaped; 31 | 32 | @end 33 | 34 | @interface PuglWindow : NSWindow 35 | 36 | - (void)setPuglview:(PuglView*)view; 37 | 38 | @end 39 | 40 | struct PuglWorldInternalsImpl { 41 | NSApplication* app; 42 | NSAutoreleasePool* autoreleasePool; 43 | }; 44 | 45 | struct PuglInternalsImpl { 46 | NSApplication* app; 47 | PuglWrapperView* wrapperView; 48 | NSView* drawView; 49 | NSCursor* cursor; 50 | PuglWindow* window; 51 | uint32_t mods; 52 | bool mouseTracked; 53 | }; 54 | 55 | #endif // PUGL_DETAIL_MAC_H 56 | -------------------------------------------------------------------------------- /BWidgets/pugl/mac_stub.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019-2020 David Robillard 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "implementation.h" 18 | #include "mac.h" 19 | #include "stub.h" 20 | 21 | #include "pugl/stub.h" 22 | 23 | #import 24 | 25 | @interface PuglStubView : NSView 26 | @end 27 | 28 | @implementation PuglStubView { 29 | @public 30 | PuglView* puglview; 31 | } 32 | 33 | - (void)resizeWithOldSuperviewSize:(NSSize)oldSize 34 | { 35 | PuglWrapperView* wrapper = (PuglWrapperView*)[self superview]; 36 | 37 | [super resizeWithOldSuperviewSize:oldSize]; 38 | [wrapper setReshaped]; 39 | } 40 | 41 | - (void)drawRect:(NSRect)rect 42 | { 43 | PuglWrapperView* wrapper = (PuglWrapperView*)[self superview]; 44 | 45 | [wrapper dispatchExpose:rect]; 46 | } 47 | 48 | @end 49 | 50 | static PuglStatus 51 | puglMacStubCreate(PuglView* view) 52 | { 53 | PuglInternals* impl = view->impl; 54 | PuglStubView* drawView = [PuglStubView alloc]; 55 | 56 | drawView->puglview = view; 57 | [drawView 58 | initWithFrame:NSMakeRect(0, 0, view->frame.width, view->frame.height)]; 59 | if (view->hints[PUGL_RESIZABLE]) { 60 | [drawView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; 61 | } else { 62 | [drawView setAutoresizingMask:NSViewNotSizable]; 63 | } 64 | 65 | impl->drawView = drawView; 66 | return PUGL_SUCCESS; 67 | } 68 | 69 | static PuglStatus 70 | puglMacStubDestroy(PuglView* view) 71 | { 72 | PuglStubView* const drawView = (PuglStubView*)view->impl->drawView; 73 | 74 | [drawView removeFromSuperview]; 75 | [drawView release]; 76 | 77 | view->impl->drawView = nil; 78 | return PUGL_SUCCESS; 79 | } 80 | 81 | const PuglBackend* 82 | puglStubBackend(void) 83 | { 84 | static const PuglBackend backend = {puglStubConfigure, 85 | puglMacStubCreate, 86 | puglMacStubDestroy, 87 | puglStubEnter, 88 | puglStubLeave, 89 | puglStubGetContext}; 90 | 91 | return &backend; 92 | } 93 | -------------------------------------------------------------------------------- /BWidgets/pugl/pugl/cairo.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2020 David Robillard 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef PUGL_CAIRO_H 18 | #define PUGL_CAIRO_H 19 | 20 | #include "pugl.h" 21 | 22 | PUGL_BEGIN_DECLS 23 | 24 | /** 25 | @defgroup cairo Cairo 26 | Cairo graphics support. 27 | @ingroup pugl 28 | @{ 29 | */ 30 | 31 | /** 32 | Cairo graphics backend accessor. 33 | 34 | Pass the returned value to puglSetBackend() to draw to a view with Cairo. 35 | */ 36 | PUGL_CONST_API 37 | const PuglBackend* 38 | puglCairoBackend(void); 39 | 40 | /** 41 | @} 42 | */ 43 | 44 | PUGL_END_DECLS 45 | 46 | #endif // PUGL_CAIRO_H 47 | -------------------------------------------------------------------------------- /BWidgets/pugl/pugl/gl.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2020 David Robillard 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef PUGL_GL_H 18 | #define PUGL_GL_H 19 | 20 | #include "pugl.h" 21 | 22 | // IWYU pragma: begin_exports 23 | 24 | /* Unfortunately, GL includes vary across platforms, so include them here to 25 | enable pure portable programs. */ 26 | 27 | #ifndef PUGL_NO_INCLUDE_GL_H 28 | # ifdef __APPLE__ 29 | # include 30 | # else 31 | # ifdef _WIN32 32 | # include 33 | # endif 34 | # include 35 | # endif 36 | #endif 37 | 38 | #ifndef PUGL_NO_INCLUDE_GLU_H 39 | # ifdef __APPLE__ 40 | # include 41 | # else 42 | # ifdef _WIN32 43 | # include 44 | # endif 45 | # include 46 | # endif 47 | #endif 48 | 49 | // IWYU pragma: end_exports 50 | 51 | PUGL_BEGIN_DECLS 52 | 53 | /** 54 | @defgroup gl OpenGL 55 | OpenGL graphics support. 56 | @ingroup pugl 57 | @{ 58 | */ 59 | 60 | /** 61 | OpenGL extension function. 62 | */ 63 | typedef void (*PuglGlFunc)(void); 64 | 65 | /** 66 | Return the address of an OpenGL extension function. 67 | */ 68 | PUGL_API 69 | PuglGlFunc 70 | puglGetProcAddress(const char* name); 71 | 72 | /** 73 | Enter the OpenGL context. 74 | 75 | This can be used to enter the graphics context in unusual situations, for 76 | doing things like loading textures. Note that this must not be used for 77 | drawing, which may only be done while processing an expose event. 78 | */ 79 | PUGL_API 80 | PuglStatus 81 | puglEnterContext(PuglView* view); 82 | 83 | /** 84 | Leave the OpenGL context. 85 | 86 | This must only be called after puglEnterContext(). 87 | */ 88 | PUGL_API 89 | PuglStatus 90 | puglLeaveContext(PuglView* view); 91 | 92 | /** 93 | OpenGL graphics backend. 94 | 95 | Pass the returned value to puglSetBackend() to draw to a view with OpenGL. 96 | */ 97 | PUGL_CONST_API 98 | const PuglBackend* 99 | puglGlBackend(void); 100 | 101 | PUGL_END_DECLS 102 | 103 | /** 104 | @} 105 | */ 106 | 107 | #endif // PUGL_GL_H 108 | -------------------------------------------------------------------------------- /BWidgets/pugl/pugl/stub.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019-2020 David Robillard 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef PUGL_STUB_H 18 | #define PUGL_STUB_H 19 | 20 | #include "pugl.h" 21 | 22 | PUGL_BEGIN_DECLS 23 | 24 | /** 25 | @defgroup stub Stub 26 | Native graphics support. 27 | @ingroup pugl 28 | @{ 29 | */ 30 | 31 | /** 32 | Stub graphics backend accessor. 33 | 34 | This backend just creates a simple native window without setting up any 35 | portable graphics API. 36 | */ 37 | PUGL_CONST_API 38 | const PuglBackend* 39 | puglStubBackend(void); 40 | 41 | /** 42 | @} 43 | */ 44 | 45 | PUGL_END_DECLS 46 | 47 | #endif // PUGL_STUB_H 48 | -------------------------------------------------------------------------------- /BWidgets/pugl/stub.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2020 David Robillard 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef PUGL_DETAIL_STUB_H 18 | #define PUGL_DETAIL_STUB_H 19 | 20 | #include "pugl/pugl.h" 21 | 22 | #include 23 | 24 | PUGL_BEGIN_DECLS 25 | 26 | static inline PuglStatus 27 | puglStubConfigure(PuglView* view) 28 | { 29 | (void)view; 30 | return PUGL_SUCCESS; 31 | } 32 | 33 | static inline PuglStatus 34 | puglStubCreate(PuglView* view) 35 | { 36 | (void)view; 37 | return PUGL_SUCCESS; 38 | } 39 | 40 | static inline PuglStatus 41 | puglStubDestroy(PuglView* view) 42 | { 43 | (void)view; 44 | return PUGL_SUCCESS; 45 | } 46 | 47 | static inline PuglStatus 48 | puglStubEnter(PuglView* view, const PuglEventExpose* expose) 49 | { 50 | (void)view; 51 | (void)expose; 52 | return PUGL_SUCCESS; 53 | } 54 | 55 | static inline PuglStatus 56 | puglStubLeave(PuglView* view, const PuglEventExpose* expose) 57 | { 58 | (void)view; 59 | (void)expose; 60 | return PUGL_SUCCESS; 61 | } 62 | 63 | static inline void* 64 | puglStubGetContext(PuglView* view) 65 | { 66 | (void)view; 67 | return NULL; 68 | } 69 | 70 | PUGL_END_DECLS 71 | 72 | #endif // PUGL_DETAIL_STUB_H 73 | -------------------------------------------------------------------------------- /BWidgets/pugl/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2020 David Robillard 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef PUGL_DETAIL_TYPES_H 18 | #define PUGL_DETAIL_TYPES_H 19 | 20 | #include "pugl/pugl.h" 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | // Unused parameter macro to suppresses warnings and make it impossible to use 27 | #if defined(__cplusplus) 28 | # define PUGL_UNUSED(name) 29 | #elif defined(__GNUC__) || defined(__clang__) 30 | # define PUGL_UNUSED(name) name##_unused __attribute__((__unused__)) 31 | #else 32 | # define PUGL_UNUSED(name) name 33 | #endif 34 | 35 | /// Platform-specific world internals 36 | typedef struct PuglWorldInternalsImpl PuglWorldInternals; 37 | 38 | /// Platform-specific view internals 39 | typedef struct PuglInternalsImpl PuglInternals; 40 | 41 | /// View hints 42 | typedef int PuglHints[PUGL_NUM_VIEW_HINTS]; 43 | 44 | /// Blob of arbitrary data 45 | typedef struct { 46 | void* data; ///< Dynamically allocated data 47 | size_t len; ///< Length of data in bytes 48 | } PuglBlob; 49 | 50 | /// Cross-platform view definition 51 | struct PuglViewImpl { 52 | PuglWorld* world; 53 | const PuglBackend* backend; 54 | PuglInternals* impl; 55 | PuglHandle handle; 56 | PuglEventFunc eventFunc; 57 | char* title; 58 | PuglBlob clipboard; 59 | PuglNativeView parent; 60 | uintptr_t transientParent; 61 | PuglRect frame; 62 | PuglEventConfigure lastConfigure; 63 | PuglHints hints; 64 | int defaultWidth; 65 | int defaultHeight; 66 | int minWidth; 67 | int minHeight; 68 | int maxWidth; 69 | int maxHeight; 70 | int minAspectX; 71 | int minAspectY; 72 | int maxAspectX; 73 | int maxAspectY; 74 | bool visible; 75 | }; 76 | 77 | /// Cross-platform world definition 78 | struct PuglWorldImpl { 79 | PuglWorldInternals* impl; 80 | PuglWorldHandle handle; 81 | char* className; 82 | double startTime; 83 | size_t numViews; 84 | PuglView** views; 85 | }; 86 | 87 | /// Opaque surface used by graphics backend 88 | typedef void PuglSurface; 89 | 90 | /// Graphics backend interface 91 | struct PuglBackendImpl { 92 | /// Get visual information from display and setup view as necessary 93 | PuglStatus (*configure)(PuglView*); 94 | 95 | /// Create surface and drawing context 96 | PuglStatus (*create)(PuglView*); 97 | 98 | /// Destroy surface and drawing context 99 | PuglStatus (*destroy)(PuglView*); 100 | 101 | /// Enter drawing context, for drawing if expose is non-null 102 | PuglStatus (*enter)(PuglView*, const PuglEventExpose*); 103 | 104 | /// Leave drawing context, after drawing if expose is non-null 105 | PuglStatus (*leave)(PuglView*, const PuglEventExpose*); 106 | 107 | /// Return the puglGetContext() handle for the application, if any 108 | void* (*getContext)(PuglView*); 109 | }; 110 | 111 | #endif // PUGL_DETAIL_TYPES_H 112 | -------------------------------------------------------------------------------- /BWidgets/pugl/win_stub.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2020 David Robillard 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "stub.h" 18 | #include "types.h" 19 | #include "win.h" 20 | 21 | #include "pugl/stub.h" 22 | 23 | PuglStatus 24 | puglWinStubConfigure(PuglView* view) 25 | { 26 | PuglInternals* const impl = view->impl; 27 | PuglStatus st = PUGL_SUCCESS; 28 | 29 | if ((st = puglWinCreateWindow(view, "Pugl", &impl->hwnd, &impl->hdc))) { 30 | return st; 31 | } 32 | 33 | impl->pfd = puglWinGetPixelFormatDescriptor(view->hints); 34 | impl->pfId = ChoosePixelFormat(impl->hdc, &impl->pfd); 35 | 36 | if (!SetPixelFormat(impl->hdc, impl->pfId, &impl->pfd)) { 37 | ReleaseDC(impl->hwnd, impl->hdc); 38 | DestroyWindow(impl->hwnd); 39 | impl->hwnd = NULL; 40 | impl->hdc = NULL; 41 | return PUGL_SET_FORMAT_FAILED; 42 | } 43 | 44 | return PUGL_SUCCESS; 45 | } 46 | 47 | PuglStatus 48 | puglWinStubEnter(PuglView* view, const PuglEventExpose* expose) 49 | { 50 | if (expose) { 51 | PAINTSTRUCT ps; 52 | BeginPaint(view->impl->hwnd, &ps); 53 | } 54 | 55 | return PUGL_SUCCESS; 56 | } 57 | 58 | PuglStatus 59 | puglWinStubLeave(PuglView* view, const PuglEventExpose* expose) 60 | { 61 | if (expose) { 62 | PAINTSTRUCT ps; 63 | EndPaint(view->impl->hwnd, &ps); 64 | } 65 | 66 | return PUGL_SUCCESS; 67 | } 68 | 69 | const PuglBackend* 70 | puglStubBackend(void) 71 | { 72 | static const PuglBackend backend = {puglWinStubConfigure, 73 | puglStubCreate, 74 | puglStubDestroy, 75 | puglWinStubEnter, 76 | puglWinStubLeave, 77 | puglStubGetContext}; 78 | 79 | return &backend; 80 | } 81 | -------------------------------------------------------------------------------- /BWidgets/pugl/win_vulkan.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2020 David Robillard 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #define VK_NO_PROTOTYPES 1 18 | 19 | #include "stub.h" 20 | #include "types.h" 21 | #include "win.h" 22 | 23 | #include "pugl/stub.h" 24 | #include "pugl/vulkan.h" 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | struct PuglVulkanLoaderImpl { 32 | HMODULE libvulkan; 33 | PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr; 34 | PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr; 35 | }; 36 | 37 | PuglVulkanLoader* 38 | puglNewVulkanLoader(PuglWorld* PUGL_UNUSED(world)) 39 | { 40 | PuglVulkanLoader* loader = 41 | (PuglVulkanLoader*)calloc(1, sizeof(PuglVulkanLoader)); 42 | if (!loader) { 43 | return NULL; 44 | } 45 | 46 | if (!(loader->libvulkan = LoadLibrary("vulkan-1.dll"))) { 47 | free(loader); 48 | return NULL; 49 | } 50 | 51 | loader->vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)GetProcAddress( 52 | loader->libvulkan, "vkGetInstanceProcAddr"); 53 | 54 | loader->vkGetDeviceProcAddr = (PFN_vkGetDeviceProcAddr)GetProcAddress( 55 | loader->libvulkan, "vkGetDeviceProcAddr"); 56 | 57 | return loader; 58 | } 59 | 60 | void 61 | puglFreeVulkanLoader(PuglVulkanLoader* loader) 62 | { 63 | if (loader) { 64 | FreeLibrary(loader->libvulkan); 65 | free(loader); 66 | } 67 | } 68 | 69 | PFN_vkGetInstanceProcAddr 70 | puglGetInstanceProcAddrFunc(const PuglVulkanLoader* loader) 71 | { 72 | return loader->vkGetInstanceProcAddr; 73 | } 74 | 75 | PFN_vkGetDeviceProcAddr 76 | puglGetDeviceProcAddrFunc(const PuglVulkanLoader* loader) 77 | { 78 | return loader->vkGetDeviceProcAddr; 79 | } 80 | 81 | const PuglBackend* 82 | puglVulkanBackend() 83 | { 84 | static const PuglBackend backend = {puglWinStubConfigure, 85 | puglStubCreate, 86 | puglStubDestroy, 87 | puglWinStubEnter, 88 | puglWinStubLeave, 89 | puglStubGetContext}; 90 | 91 | return &backend; 92 | } 93 | 94 | const char* const* 95 | puglGetInstanceExtensions(uint32_t* const count) 96 | { 97 | static const char* const extensions[] = {"VK_KHR_surface", 98 | "VK_KHR_win32_surface"}; 99 | 100 | *count = 2; 101 | return extensions; 102 | } 103 | 104 | VkResult 105 | puglCreateSurface(PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr, 106 | PuglView* const view, 107 | VkInstance instance, 108 | const VkAllocationCallbacks* const pAllocator, 109 | VkSurfaceKHR* const pSurface) 110 | { 111 | PuglInternals* const impl = view->impl; 112 | 113 | PFN_vkCreateWin32SurfaceKHR vkCreateWin32SurfaceKHR = 114 | (PFN_vkCreateWin32SurfaceKHR)vkGetInstanceProcAddr( 115 | instance, "vkCreateWin32SurfaceKHR"); 116 | 117 | const VkWin32SurfaceCreateInfoKHR createInfo = { 118 | VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR, 119 | NULL, 120 | 0, 121 | GetModuleHandle(NULL), 122 | impl->hwnd, 123 | }; 124 | 125 | return vkCreateWin32SurfaceKHR(instance, &createInfo, pAllocator, pSurface); 126 | } 127 | -------------------------------------------------------------------------------- /BWidgets/pugl/x11.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2020 David Robillard 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef PUGL_DETAIL_X11_H 18 | #define PUGL_DETAIL_X11_H 19 | 20 | #include "types.h" 21 | 22 | #include "pugl/pugl.h" 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | typedef struct { 33 | Atom CLIPBOARD; 34 | Atom UTF8_STRING; 35 | Atom WM_PROTOCOLS; 36 | Atom WM_DELETE_WINDOW; 37 | Atom PUGL_CLIENT_MSG; 38 | Atom NET_WM_NAME; 39 | Atom NET_WM_STATE; 40 | Atom NET_WM_STATE_DEMANDS_ATTENTION; 41 | } PuglX11Atoms; 42 | 43 | typedef struct { 44 | XID alarm; 45 | PuglView* view; 46 | uintptr_t id; 47 | } PuglTimer; 48 | 49 | struct PuglWorldInternalsImpl { 50 | Display* display; 51 | PuglX11Atoms atoms; 52 | XIM xim; 53 | PuglTimer* timers; 54 | size_t numTimers; 55 | XID serverTimeCounter; 56 | int syncEventBase; 57 | bool syncSupported; 58 | bool dispatchingEvents; 59 | }; 60 | 61 | struct PuglInternalsImpl { 62 | Display* display; 63 | XVisualInfo* vi; 64 | Window win; 65 | XIC xic; 66 | PuglSurface* surface; 67 | PuglEvent pendingConfigure; 68 | PuglEvent pendingExpose; 69 | int screen; 70 | #ifdef HAVE_XCURSOR 71 | unsigned cursorShape; 72 | #endif 73 | }; 74 | 75 | PuglStatus 76 | puglX11StubConfigure(PuglView* view); 77 | 78 | #endif // PUGL_DETAIL_X11_H 79 | -------------------------------------------------------------------------------- /BWidgets/pugl/x11_stub.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2020 David Robillard 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "pugl/stub.h" 18 | 19 | #include "stub.h" 20 | #include "types.h" 21 | #include "x11.h" 22 | 23 | #include "pugl/pugl.h" 24 | 25 | #include 26 | 27 | PuglStatus 28 | puglX11StubConfigure(PuglView* view) 29 | { 30 | PuglInternals* const impl = view->impl; 31 | XVisualInfo pat = {0}; 32 | int n = 0; 33 | 34 | pat.screen = impl->screen; 35 | impl->vi = XGetVisualInfo(impl->display, VisualScreenMask, &pat, &n); 36 | 37 | view->hints[PUGL_RED_BITS] = impl->vi->bits_per_rgb; 38 | view->hints[PUGL_GREEN_BITS] = impl->vi->bits_per_rgb; 39 | view->hints[PUGL_BLUE_BITS] = impl->vi->bits_per_rgb; 40 | view->hints[PUGL_ALPHA_BITS] = 0; 41 | 42 | return PUGL_SUCCESS; 43 | } 44 | 45 | const PuglBackend* 46 | puglStubBackend(void) 47 | { 48 | static const PuglBackend backend = { 49 | puglX11StubConfigure, 50 | puglStubCreate, 51 | puglStubDestroy, 52 | puglStubEnter, 53 | puglStubLeave, 54 | puglStubGetContext, 55 | }; 56 | 57 | return &backend; 58 | } 59 | -------------------------------------------------------------------------------- /BWidgets/pugl/x11_vulkan.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012-2020 David Robillard 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #define VK_NO_PROTOTYPES 1 18 | 19 | #include "stub.h" 20 | #include "types.h" 21 | #include "x11.h" 22 | 23 | #include "pugl/pugl.h" 24 | #include "pugl/vulkan.h" 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | struct PuglVulkanLoaderImpl { 35 | void* libvulkan; 36 | PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr; 37 | PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr; 38 | }; 39 | 40 | PuglVulkanLoader* 41 | puglNewVulkanLoader(PuglWorld* PUGL_UNUSED(world)) 42 | { 43 | PuglVulkanLoader* loader = 44 | (PuglVulkanLoader*)calloc(1, sizeof(PuglVulkanLoader)); 45 | if (!loader) { 46 | return NULL; 47 | } 48 | 49 | if (!(loader->libvulkan = dlopen("libvulkan.so", RTLD_LAZY))) { 50 | free(loader); 51 | return NULL; 52 | } 53 | 54 | loader->vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)dlsym( 55 | loader->libvulkan, "vkGetInstanceProcAddr"); 56 | 57 | loader->vkGetDeviceProcAddr = 58 | (PFN_vkGetDeviceProcAddr)dlsym(loader->libvulkan, "vkGetDeviceProcAddr"); 59 | 60 | return loader; 61 | } 62 | 63 | void 64 | puglFreeVulkanLoader(PuglVulkanLoader* loader) 65 | { 66 | if (loader) { 67 | dlclose(loader->libvulkan); 68 | free(loader); 69 | } 70 | } 71 | 72 | PFN_vkGetInstanceProcAddr 73 | puglGetInstanceProcAddrFunc(const PuglVulkanLoader* loader) 74 | { 75 | return loader->vkGetInstanceProcAddr; 76 | } 77 | 78 | PFN_vkGetDeviceProcAddr 79 | puglGetDeviceProcAddrFunc(const PuglVulkanLoader* loader) 80 | { 81 | return loader->vkGetDeviceProcAddr; 82 | } 83 | 84 | const PuglBackend* 85 | puglVulkanBackend(void) 86 | { 87 | static const PuglBackend backend = {puglX11StubConfigure, 88 | puglStubCreate, 89 | puglStubDestroy, 90 | puglStubEnter, 91 | puglStubLeave, 92 | puglStubGetContext}; 93 | 94 | return &backend; 95 | } 96 | 97 | const char* const* 98 | puglGetInstanceExtensions(uint32_t* const count) 99 | { 100 | static const char* const extensions[] = {"VK_KHR_surface", 101 | "VK_KHR_xlib_surface"}; 102 | 103 | *count = 2; 104 | return extensions; 105 | } 106 | 107 | VkResult 108 | puglCreateSurface(PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr, 109 | PuglView* const view, 110 | VkInstance instance, 111 | const VkAllocationCallbacks* const allocator, 112 | VkSurfaceKHR* const surface) 113 | { 114 | PuglInternals* const impl = view->impl; 115 | PuglWorldInternals* world_impl = view->world->impl; 116 | 117 | PFN_vkCreateXlibSurfaceKHR vkCreateXlibSurfaceKHR = 118 | (PFN_vkCreateXlibSurfaceKHR)vkGetInstanceProcAddr(instance, 119 | "vkCreateXlibSurfaceKHR"); 120 | 121 | const VkXlibSurfaceCreateInfoKHR info = { 122 | VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR, 123 | NULL, 124 | 0, 125 | world_impl->display, 126 | impl->win, 127 | }; 128 | 129 | return vkCreateXlibSurfaceKHR(instance, &info, allocator, surface); 130 | } 131 | -------------------------------------------------------------------------------- /Definitions.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DEFINITIONS_HPP_ 2 | #define DEFINITIONS_HPP_ 3 | 4 | #define BSPACR_URI "https://www.jahnichen.de/plugins/lv2/BSpacr" 5 | #define BSPACR_GUI_URI "https://www.jahnichen.de/plugins/lv2/BSpacr#GUI" 6 | #define BSPACR_N_PORTS 4 7 | 8 | #endif /* DEFINITIONS_HPP_ */ 9 | -------------------------------------------------------------------------------- /Ports.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PORTS_HPP_ 2 | #define PORTS_HPP_ 3 | 4 | enum PortIndex { 5 | BSPACR_INPUT = 0, 6 | BSPACR_OUTPUT = 2, 7 | BSPACR_MIX = 4 8 | }; 9 | 10 | #endif /* PORTS_HPP_ */ 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # B.Spacr 2 | 3 | Description: LV2 sound effect plugin 4 | 5 | B.Spacr is a unique LV2 effect plugin that enables a clear and brilliant audibility of your music production. 6 | B.Spacr is suited for **any** kind of music, including rock, funk, pop, rap, and electronic music. 7 | This plugin can be added to each track individually or to the master bus with **zero latency**. 8 | The result is a space-clear sound **without any loss** of audio signal information and without 9 | any artifacts only depending on the quality of the input signal. In contrast to many over-complex 10 | audio plugins, the number of parameters have been reduced to the minimum for the **best user experience**. 11 | 12 | April 1, 2021 13 | 14 | ## Installation 15 | 16 | Build your own binaries in the following three steps. 17 | 18 | Step 1: [Download the latest published version](https://github.com/sjaehn/BSpacr/releases) of B.Spacr. Or clone or 19 | [download the master](https://github.com/sjaehn/BSpacr/archive/master.zip) of this repository. 20 | 21 | Step 2: Install pkg-config and the development packages for x11, cairo, and lv2 if not done yet. If you 22 | don't have already got the build tools (compilers, make, libraries) then install them too. 23 | 24 | On Debian-based systems you may run: 25 | ``` 26 | sudo apt-get install build-essential 27 | sudo apt-get install pkg-config libx11-dev libcairo2-dev lv2-dev 28 | ``` 29 | 30 | On Arch-based systems you may run: 31 | ``` 32 | sudo pacman -S base-devel 33 | sudo pacman -S pkg-config libx11 cairo lv2 34 | ``` 35 | 36 | Step 3: Building and installing into the default lv2 directory (/usr/local/lib/lv2/) is easy using `make` and 37 | `make install`. Simply call: 38 | ``` 39 | make 40 | sudo make install 41 | ``` 42 | 43 | **Optional:** Standard `make` and `make install` parameters are supported. Compiling using `make CPPFLAGS+=-O3` 44 | is recommended to improve the plugin performance. Alternatively, you may build a debugging version using 45 | `make CPPFLAGS+=-g`. For installation into an alternative directory (e.g., /usr/lib/lv2/), change the 46 | variable `PREFIX` while installing: `sudo make install PREFIX=/usr`. If you want to freely choose the 47 | install target directory, change the variable `LV2DIR` (e.g., `make install LV2DIR=~/.lv2`). 48 | 49 | 50 | ## Running 51 | 52 | After the installation Ardour, Reaper, Qtractor, Zrythm, Carla, and any other LV2 host should automatically 53 | detect B.Spacr. 54 | 55 | If jalv is installed, you can also call it using one of the graphical jalv executables (like 56 | jalv.gtk, or jalv.gtk3, or jalv.qt4, or jalv.qt5, depending on what is installed), like 57 | 58 | ``` 59 | jalv.gtk https://www.jahnichen.de/plugins/lv2/BSpacr 60 | ``` 61 | 62 | to run it stand-alone and connect it to the JACK system. 63 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | BUNDLE = BSpacr.lv2 2 | PREFIX ?= /usr/local 3 | LV2DIR ?= $(PREFIX)/lib/lv2 4 | 5 | CC ?= gcc 6 | CXX ?= g++ 7 | 8 | CPPFLAGS += -DPIC 9 | CFLAGS += -std=c99 -fvisibility=hidden -fPIC 10 | CXXFLAGS += -std=c++11 -fvisibility=hidden -fPIC 11 | LDFLAGS += -shared 12 | PUGLFLAGS += -DPUGL_HAVE_CAIRO 13 | 14 | DSPFLAGS = `pkg-config --cflags --libs lv2` 15 | GUICFLAGS = `pkg-config --cflags lv2 x11 cairo` 16 | GUILFLAGS = `pkg-config --libs lv2 x11 cairo` 17 | 18 | TKCXX = \ 19 | BWidgets/Window.cpp \ 20 | BWidgets/Widget.cpp \ 21 | BWidgets/BStyles.cpp \ 22 | BWidgets/BColors.cpp \ 23 | BWidgets/Label.cpp \ 24 | BWidgets/Knob.cpp \ 25 | BWidgets/Dial.cpp \ 26 | BWidgets/DialValue.cpp \ 27 | BWidgets/ValueWidget.cpp \ 28 | BWidgets/RangeWidget.cpp \ 29 | BWidgets/DrawingSurface.cpp \ 30 | BUtilities/stof.cpp \ 31 | BUtilities/to_string.cpp 32 | 33 | TKC = BWidgets/cairoplus.c \ 34 | BWidgets/pugl/implementation.c \ 35 | BWidgets/pugl/x11_stub.c \ 36 | BWidgets/pugl/x11_cairo.c \ 37 | BWidgets/pugl/x11.c 38 | 39 | $(BUNDLE): clean BSpacr.so BSpacr_GUI.so 40 | cp manifest.ttl BSpacr.ttl surface.png LICENSE $(BUNDLE) 41 | 42 | all: $(BUNDLE) 43 | 44 | BSpacr.so: ./BSpacr.cpp 45 | mkdir -p $(BUNDLE) 46 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(DSPFLAGS) $< -o $(BUNDLE)/$@ 47 | 48 | BSpacr_GUI.so: ./BSpacr_GUI.cpp 49 | mkdir -p $(BUNDLE) 50 | mkdir -p $(BUNDLE)/tmp 51 | cd $(BUNDLE)/tmp; $(CC) $(CPPFLAGS) $(PUGLFLAGS) $(CFLAGS) $(GUICFLAGS) $(addprefix ../../, $(TKC)) -c 52 | cd $(BUNDLE)/tmp; $(CXX) $(CPPFLAGS) $(PUGLFLAGS) $(CXXFLAGS) $(GUICFLAGS) $(addprefix ../../, $< $(TKCXX)) -c 53 | $(CXX) $(CPPFLAGS) $(PUGLFLAGS) $(CXXFLAGS) $(LDFLAGS) $(GUICFLAGS) -Wl,--start-group $(GUILFLAGS) $(BUNDLE)/tmp/*.o -Wl,--end-group -o $(BUNDLE)/$@ 54 | rm -rf $(BUNDLE)/tmp 55 | 56 | install: 57 | mkdir -p $(DESTDIR)$(LV2DIR) 58 | rm -rf $(DESTDIR)$(LV2DIR)/$(BUNDLE) 59 | cp -R $(BUNDLE) $(DESTDIR)$(LV2DIR) 60 | 61 | .PHONY: all 62 | 63 | clean: 64 | rm -rf $(BUNDLE) 65 | -------------------------------------------------------------------------------- /manifest.ttl: -------------------------------------------------------------------------------- 1 | @prefix lv2: . 2 | @prefix rdfs: . 3 | @prefix ui: . 4 | 5 | 6 | a ui:X11UI ; 7 | ui:binary ; 8 | rdfs:seeAlso . 9 | 10 | 11 | a lv2:Plugin ; 12 | lv2:binary ; 13 | rdfs:seeAlso . 14 | -------------------------------------------------------------------------------- /surface.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sjaehn/BSpacr/cd486de1dd17f4bf496978da8cd8accca6453027/surface.png --------------------------------------------------------------------------------