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: 7 июл. 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_LSPINDICATOR_H_ 23 #define UI_TK_LSPINDICATOR_H_ 24 25 #include <core/buffer.h> 26 27 namespace lsp 28 { 29 namespace tk 30 { 31 class LSPIndicator: public LSPWidget 32 { 33 public: 34 static const w_class_t metadata; 35 36 protected: 37 static const size_t DIGITS_DFL = 5; 38 static const size_t ITEMS_MAX = 16; 39 40 enum format_t 41 { 42 F_UNKNOWN, 43 F_FLOAT, 44 F_INT, 45 F_TIME 46 }; 47 48 enum flags_t 49 { 50 F_SIGN = 1 << 0, 51 F_PLUS = 1 << 1, 52 F_PAD_ZERO = 1 << 2, 53 F_FIXED_PREC = 1 << 3, 54 F_NO_ZERO = 1 << 4, 55 F_DOT = 1 << 5, 56 F_TOLERANCE = 1 << 6 57 }; 58 59 typedef struct item_t 60 { 61 char type; 62 size_t digits; 63 ssize_t precision; 64 } item_t; 65 66 LSPColor sColor; 67 LSPColor sTextColor; 68 float fValue; 69 70 // Format 71 char *sFormat; 72 format_t nFormat; 73 size_t sDigits; 74 size_t nFlags; 75 cstorage<item_t> vItems; 76 77 private: 78 bool parse_format(const char *format); 79 void draw_digit(ISurface *s, int x, int y, char ch, char mod, const Color &on, const Color &off); 80 81 bool fmt_time(buffer_t *buf, double value); 82 bool fmt_float(buffer_t *buf, double value); 83 bool fmt_int(buffer_t *buf, ssize_t value); 84 bool format(buffer_t *buf, double value); 85 86 static bool parse_long(char *p, char **ret, long *value); 87 88 void drop_data(); 89 90 //--------------------------------------------------------------------------------- 91 // Construction and destruction 92 public: 93 explicit LSPIndicator(LSPDisplay *dpy); 94 virtual ~LSPIndicator(); 95 96 virtual status_t init(); 97 virtual void destroy(); 98 99 //--------------------------------------------------------------------------------- 100 // Properties 101 public: 102 color()103 inline LSPColor *color() { return &sColor; } 104 text_color()105 inline LSPColor *text_color() { return &sTextColor; } 106 value()107 inline float value() const { return fValue; } 108 format()109 inline const char *format() const { return sFormat; } 110 111 //--------------------------------------------------------------------------------- 112 // Manipulation 113 public: 114 115 status_t set_format(const char *fmt); 116 117 void set_value(float value); 118 119 //--------------------------------------------------------------------------------- 120 // Event handling 121 public: 122 virtual void size_request(size_request_t *r); 123 124 virtual void draw(ISurface *s); 125 }; 126 127 } /* namespace tk */ 128 } /* namespace lsp */ 129 130 #endif /* UI_TK_LSPINDICATOR_H_ */ 131