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: 19 нояб. 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_WIDGETS_LSPFADER_H_
23 #define UI_TK_WIDGETS_LSPFADER_H_
24 
25 namespace lsp
26 {
27     namespace tk
28     {
29 
30         class LSPFader: public LSPWidget
31         {
32             public:
33                 static const w_class_t    metadata;
34 
35             protected:
36                 enum flags_t
37                 {
38                     F_IGNORE        = 1 << 0,
39                     F_PRECISION     = 1 << 1,
40                     F_MOVER         = 1 << 2
41                 };
42 
43             protected:
44                 float           fMin;
45                 float           fMax;
46                 float           fValue;
47                 float           fStep;
48                 float           fTinyStep;
49                 ssize_t         nMinSize;
50                 size_t          nAngle;
51                 ssize_t         nLastV;
52                 size_t          nButtons;
53                 size_t          nBtnLength;
54                 size_t          nBtnWidth;
55                 size_t          nXFlags;
56                 float           fLastValue;
57                 float           fCurrValue;
58 
59                 LSPColor        sColor;
60 
61             protected:
62                 float           limit_value(float value);
63                 float           get_normalized_value();
64                 bool            check_mouse_over(ssize_t x, ssize_t y);
65                 void            do_destroy();
66                 void            update();
67                 void            update_cursor_state(ssize_t x, ssize_t y, bool set);
68 
69                 static status_t slot_on_change(LSPWidget *sender, void *ptr, void *data);
70 
71             public:
72                 explicit LSPFader(LSPDisplay *dpy);
73                 virtual ~LSPFader();
74 
75                 virtual status_t        init();
76                 virtual void            destroy();
77 
78             public:
value()79                 inline float            value() const { return fValue; }
step()80                 inline float            step() const { return fStep; }
tiny_step()81                 inline float            tiny_step() const { return fTinyStep; }
min_value()82                 inline float            min_value() const { return fMin; }
max_value()83                 inline float            max_value() const { return fMax; }
color()84                 inline LSPColor        *color() { return &sColor; }
angle()85                 inline size_t           angle() const { return nAngle; }
button_length()86                 inline size_t           button_length() const { return nBtnLength; }
button_width()87                 inline size_t           button_width() const { return nBtnWidth; }
88                 virtual mouse_pointer_t active_cursor() const;
89 
90             public:
91                 void                    set_value(float value);
92                 void                    set_default_value(float value);
93                 void                    set_step(float value);
94                 void                    set_tiny_step(float value);
95                 void                    set_min_value(float value);
96                 void                    set_max_value(float value);
97                 void                    set_min_size(ssize_t value);
98                 void                    set_angle(size_t value);
99                 void                    set_button_width(size_t value);
100                 void                    set_button_length(size_t value);
101 
102             public:
103                 virtual void size_request(size_request_t *r);
104 
105                 virtual status_t on_change();
106 
107                 virtual status_t on_mouse_down(const ws_event_t *e);
108 
109                 virtual status_t on_mouse_up(const ws_event_t *e);
110 
111                 virtual status_t on_mouse_move(const ws_event_t *e);
112 
113                 virtual status_t on_mouse_scroll(const ws_event_t *e);
114 
115                 virtual void draw(ISurface *s);
116         };
117 
118     } /* namespace tk */
119 } /* namespace lsp */
120 
121 #endif /* UI_TK_WIDGETS_LSPFADER_H_ */
122