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: 18 июл. 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_LSPGRAPH_H_ 23 #define UI_TK_LSPGRAPH_H_ 24 25 namespace lsp 26 { 27 namespace tk 28 { 29 class LSPGraphItem; 30 class LSPAxis; 31 class LSPCenter; 32 33 class LSPGraph: public LSPWidgetContainer 34 { 35 public: 36 static const w_class_t metadata; 37 38 protected: 39 size_t nMinWidth; 40 size_t nMinHeight; 41 size_t nBorder; 42 size_t nRadius; 43 float fCanvasLeft; 44 float fCanvasTop; 45 float fCanvasWidth; 46 float fCanvasHeight; 47 ISurface *pGlass; 48 ISurface *pCanvas; 49 50 LSPPadding sIPadding; 51 LSPColor sColor; 52 cvector<LSPGraphItem> vObjects; 53 cvector<LSPAxis> vAxises; 54 cvector<LSPAxis> vBasises; 55 cvector<LSPCenter> vCenters; 56 57 #ifdef LSP_TRACE 58 struct timespec sClock; 59 size_t nFrames; 60 #endif /* LSP_TRACE */ 61 62 protected: 63 ISurface *get_canvas(ISurface *s, ssize_t w, ssize_t h, const Color &color); 64 void do_destroy(); 65 66 protected: 67 virtual LSPWidget *find_widget(ssize_t x, ssize_t y); 68 69 public: 70 explicit LSPGraph(LSPDisplay *dpy); 71 virtual ~LSPGraph(); 72 73 virtual status_t init(); 74 virtual void destroy(); 75 76 public: items()77 inline size_t items() const { return vObjects.size(); }; axes()78 size_t axes() const { return vAxises.size(); }; basis_axes()79 size_t basis_axes() const { return vBasises.size(); }; centers()80 size_t centers() const { return vCenters.size(); }; 81 item(size_t index)82 LSPGraphItem *item(size_t index) { return vObjects[index]; }; axis(size_t index)83 LSPAxis *axis(size_t index) { return vAxises[index]; }; basis_axis(size_t index)84 LSPAxis *basis_axis(size_t index) { return vBasises[index]; }; center(size_t index)85 LSPCenter *center(size_t index) { return vCenters[index]; }; 86 color()87 LSPColor *color() { return &sColor; }; 88 89 bool center(size_t index, float *x, float *y); 90 bool center(LSPCenter *center, float *x, float *y); 91 92 size_t get_axes(LSPAxis **dst, size_t start, size_t count); 93 size_t get_basis_axes(LSPAxis **dst, size_t start, size_t count); 94 size_t get_items(LSPGraphItem **dst, size_t start, size_t count); 95 internal_padding()96 LSPPadding *internal_padding() { return &sIPadding; }; min_width()97 size_t min_width() const { return nMinWidth; }; min_height()98 size_t min_height() const { return nMinHeight; }; border()99 size_t border() const { return nBorder; }; radius()100 size_t radius() const { return nRadius; }; canvas_left()101 inline float canvas_left() const { return fCanvasLeft; }; canvas_top()102 inline float canvas_top() const { return fCanvasTop; }; 103 104 public: 105 void set_min_width(size_t value); 106 void set_min_height(size_t value); 107 void set_border(size_t value); 108 void set_radius(size_t value); 109 110 public: area_left()111 inline float area_left() const { return 1.0f; } area_top()112 inline float area_top() const { return (pCanvas != NULL) ? pCanvas->height() - 1.0f: 0.0f; } area_bottom()113 inline float area_bottom() const { return 1.0f; } area_right()114 inline float area_right() const { return (pCanvas != NULL) ? pCanvas->width() - 1.0f: 0.0f; } area_width()115 inline float area_width() const { return fCanvasWidth; } area_height()116 inline float area_height() const { return fCanvasHeight; } 117 118 public: 119 virtual void query_draw(size_t flags); 120 121 virtual void size_request(size_request_t *r); 122 123 virtual status_t add(LSPWidget *widget); 124 125 virtual status_t remove(LSPWidget *widget); 126 127 virtual status_t on_mouse_down(const ws_event_t *e); 128 129 virtual status_t on_resize(const realize_t *r); 130 131 virtual void draw(ISurface *s); 132 133 virtual void realize(const realize_t *r); 134 }; 135 136 } /* namespace tk */ 137 } /* namespace lsp */ 138 139 #endif /* UI_TK_LSPGRAPH_H_ */ 140