1 // 2 // smeter.h 3 // 4 // Smeter bar widget routines. 5 // ---------------------------------------------------------------------------- 6 // Copyright (C) 2014 7 // David Freese, W1HKJ 8 // 9 // This file is part of fldigi 10 // 11 // fldigi is free software; you can redistribute it and/or modify 12 // it under the terms of the GNU General Public License as published by 13 // the Free Software Foundation; either version 3 of the License, or 14 // (at your option) any later version. 15 // 16 // fldigi is distributed in the hope that it will be useful, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 // GNU General Public License for more details. 20 // 21 // You should have received a copy of the GNU General Public License 22 // along with this program. If not, see <http://www.gnu.org/licenses/>. 23 // ---------------------------------------------------------------------------- 24 25 26 #ifndef SMETER 27 #define SMETER 28 29 // 30 // Include necessary headers. 31 // 32 33 #include <FL/Fl.H> 34 #include <FL/Fl_Widget.H> 35 36 // 37 // Smeter class... 38 // 39 40 class Smeter : public Fl_Widget 41 { 42 private: 43 double value_, 44 minimum_, 45 maximum_; 46 int sval; // Size of sval bar... 47 int bx, by, bw, bh; // Box areas... 48 int tx, tw; // Temporary X + width 49 int ty, th; // Temporary Y + height 50 int sx; // meter left offset 51 int meter_width; 52 int meter_height; 53 Fl_Color bgnd_; 54 Fl_Color fgnd_; 55 Fl_Color scale_color; 56 static const char *meter_face; 57 58 void (*cbFunc)(Fl_Widget *, void *); 59 60 protected: 61 62 virtual void draw(); 63 64 public: 65 66 Smeter(int x, int y, int w, int h, const char *l = 0); 67 maximum(double v)68 void maximum(double v) { maximum_ = v; redraw(); } maximum()69 double maximum() const { return (maximum_); } 70 minimum(double v)71 void minimum(double v) { minimum_ = v; redraw(); } minimum()72 double minimum() const { return (minimum_); } 73 value(double v)74 void value(double v) { 75 value_ = v; 76 if (value_ < minimum_) value_ = minimum_; 77 if (value_ > maximum_) value_ = maximum_; 78 redraw(); 79 } value()80 double value() const { return (value_); } 81 void resize(int x, int y, int w, int h); 82 int handle(int); 83 set_background(Fl_Color c1)84 void set_background(Fl_Color c1) { bgnd_ = c1; redraw(); } set_metercolor(Fl_Color c2)85 void set_metercolor(Fl_Color c2) { fgnd_ = c2; redraw(); } set_scalecolor(Fl_Color c3)86 void set_scalecolor(Fl_Color c3) { scale_color = c3; redraw(); } 87 callback(void (* cbf)(Fl_Widget *,void *))88 void callback (void (*cbf)(Fl_Widget *, void *) ){ cbFunc = cbf;} do_callback()89 void do_callback() { 90 if (cbFunc) cbFunc(this, (void*)0); 91 } 92 93 }; 94 95 #endif // !smeter 96 97