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: 21 июн. 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_LSPBUTTON_H_ 23 #define UI_TK_LSPBUTTON_H_ 24 25 namespace lsp 26 { 27 namespace tk 28 { 29 class LSPButton: public LSPWidget 30 { 31 public: 32 static const w_class_t metadata; 33 34 protected: 35 enum state_t 36 { 37 S_PRESSED = (1 << 0), 38 S_TOGGLED = (1 << 1), 39 S_OUT = (1 << 2), 40 S_LED = (1 << 3), 41 S_TRIGGER = (1 << 4), 42 S_TOGGLE = (1 << 5), 43 S_DOWN = (1 << 6), 44 S_EDITABLE = (1 << 7), 45 }; 46 47 protected: 48 LSPColor sColor; 49 LSPFont sFont; 50 LSPLocalString sTitle; 51 52 size_t nWidth; 53 size_t nHeight; 54 size_t nMinWidth; 55 size_t nMinHeight; 56 size_t nState; 57 size_t nBMask; 58 size_t nChanges; 59 60 public: 61 explicit LSPButton(LSPDisplay *dpy); 62 virtual ~LSPButton(); 63 64 virtual status_t init(); 65 66 protected: 67 bool check_mouse_over(ssize_t x, ssize_t y); 68 69 static status_t slot_on_change(LSPWidget *sender, void *ptr, void *data); 70 static status_t slot_on_submit(LSPWidget *sender, void *ptr, void *data); 71 72 public: is_trigger()73 inline bool is_trigger() const { return nState & S_TRIGGER; } is_toggle()74 inline bool is_toggle() const { return nState & S_TOGGLE; } is_normal()75 inline bool is_normal() const { return !(nState & (S_TOGGLE | S_TRIGGER)); } is_down()76 inline bool is_down() const { return nState & S_DOWN; } is_led()77 inline bool is_led() const { return nState & S_LED; } is_editable()78 inline bool is_editable() const { return nState & S_EDITABLE; } color()79 inline LSPColor *color() { return &sColor; } bg_color()80 inline LSPColor *bg_color() { return &sBgColor; } font()81 inline LSPFont *font() { return &sFont; } 82 min_width()83 inline size_t min_width() const { return nMinWidth; } min_height()84 inline size_t min_height() const { return nMinHeight; } 85 title()86 inline LSPLocalString *title() { return &sTitle; } title()87 inline const LSPLocalString *title() const { return &sTitle; } 88 89 public: 90 void set_trigger(); 91 void set_toggle(); 92 void set_normal(); 93 void set_editable(bool value = true); 94 void set_down(bool value = true); 95 void set_led(bool value = true); 96 void set_min_width(size_t value); 97 void set_min_height(size_t value); 98 void set_min_size(size_t width, size_t height); 99 100 public: 101 virtual void draw(ISurface *s); 102 103 virtual void size_request(size_request_t *r); 104 105 virtual void realize(const realize_t *r); 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_change(); 114 115 virtual status_t on_submit(); 116 }; 117 118 } /* namespace tk */ 119 } /* namespace lsp */ 120 121 #endif /* UI_TK_LSPBUTTON_H_ */ 122