1 /*
2  * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3  *           (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
4  *
5  * This file is part of lsp-plugins
6  * Created on: 1 июл. 2017 г.
7  *
8  * lsp-plugins is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * any later version.
12  *
13  * lsp-plugins is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef UI_TK_LSPSWITCH_H_
23 #define UI_TK_LSPSWITCH_H_
24 
25 namespace lsp
26 {
27     namespace tk
28     {
29 
30         class LSPSwitch: public LSPWidget
31         {
32             public:
33                 static const w_class_t    metadata;
34 
35             protected:
36                 enum state_t
37                 {
38                     S_PRESSED   = (1 << 0),
39                     S_TOGGLED   = (1 << 1)
40                 };
41 
42                 LSPColor        sColor;
43                 LSPColor        sTextColor;
44                 LSPColor        sBorderColor;
45                 LSPColor        sHoleColor;
46 
47                 size_t          nSize;
48                 size_t          nBorder;
49                 float           nAspect;
50                 size_t          nState;
51                 size_t          nBMask;
52                 size_t          nAngle;
53 
54             protected:
55                 bool        check_mouse_over(ssize_t x, ssize_t y);
56                 void        dimensions(ssize_t &w, ssize_t &h);
57 
58                 void        on_click(bool down);
59 
60             public:
61                 explicit LSPSwitch(LSPDisplay *dpy);
62                 virtual ~LSPSwitch();
63 
64                 virtual status_t init();
65 
66             public:
is_down()67                 inline bool is_down() const     { return nState & S_TOGGLED; }
68 
is_up()69                 inline bool is_up() const       { return !(nState & S_TOGGLED); }
70 
color()71                 inline LSPColor *color()        { return &sColor; }
72 
text_color()73                 inline LSPColor *text_color()   { return &sTextColor; }
74 
border_color()75                 inline LSPColor *border_color() { return &sBorderColor; }
76 
hole_color()77                 inline LSPColor *hole_color()   { return &sHoleColor; }
78 
size()79                 inline ssize_t size() const     { return nSize; }
80 
border()81                 inline size_t border() const    { return nBorder; }
82 
aspect()83                 inline float aspect() const     { return nAspect; }
84 
angle()85                 inline size_t angle() const     { return nAngle; }
86 
87             public:
88                 void set_down(bool down = true);
89 
90                 void set_up(bool up = true);
91 
92                 void set_size(ssize_t size);
93 
94                 void set_border(size_t border);
95 
96                 void set_aspect(float aspect);
97 
98                 void set_angle(size_t angle);
99 
100             public:
101                 virtual void draw(ISurface *s);
102 
103                 virtual void size_request(size_request_t *r);
104 
105                 virtual status_t on_mouse_down(const ws_event_t *e);
106 
107                 virtual status_t on_mouse_up(const ws_event_t *e);
108 
109                 virtual status_t on_mouse_move(const ws_event_t *e);
110         };
111 
112     } /* namespace tk */
113 } /* namespace lsp */
114 
115 #endif /* UI_TK_LSPSWITCH_H_ */
116