1 //
2 // smeter.cxx
3 //
4 // Smeter bar widget routines.
5 //
6 // A part of the fldigi.
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
12 //
13 // This library 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 GNU
16 // Library General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 // ----------------------------------------------------------------------------
21
22 #include <iostream>
23 #include <config.h>
24 #include <cmath>
25
26 #include <FL/Fl.H>
27 #include <FL/fl_draw.H>
28
29 #include "smeter.h"
30
31 //
32 // smeter is a smeter bar widget based off Fl_Widget that shows a
33 // standard smeter bar in horizontal format
34
draw()35 void Smeter::draw()
36 {
37 if (maximum_ > minimum_)
38 sval = round(meter_width * (value_ - minimum_) / (maximum_ - minimum_));
39 else
40 sval = 0;
41
42 // Draw the box and label...
43 draw_box();
44 draw_box(box(), tx, ty, tw, th, bgnd_);
45 if (sval > 0)
46 draw_box(FL_FLAT_BOX,
47 tx + sx, ty + 2,
48 sval,
49 th - 4,
50 fgnd_);
51 labelcolor(scale_color);
52 draw_label();
53 }
54
55 const char * Smeter::meter_face = "| : : S3 : : S6 : : S9 :: 20 :: 40 :: |";
56
Smeter(int X,int Y,int W,int H,const char * l)57 Smeter::Smeter(int X, int Y, int W, int H, const char* l)
58 : Fl_Widget(X, Y, W, H, "")
59 {
60 align(FL_ALIGN_INSIDE);
61 box(FL_DOWN_BOX);
62 bgnd_ = FL_BACKGROUND2_COLOR;
63 fgnd_ = FL_GREEN;
64 scale_color = FL_BLACK;
65
66 minimum_ = 0.0;
67 maximum_ = 100.0;
68 value_ = 0;
69
70 // Get the box borders...
71 bx = Fl::box_dx(box());
72 by = Fl::box_dy(box());
73 bw = Fl::box_dw(box());
74 bh = Fl::box_dh(box());
75
76 tx = X + bx;
77 tw = W - bw;
78 ty = Y + by;
79 th = H - bh;
80
81 static int fsize = 6;
82 fl_font(FL_HELVETICA, fsize);
83 meter_width = fl_width(meter_face);
84 while ((meter_width < tw) && (fl_height() < th)) {
85 fsize++;
86 fl_font(FL_HELVETICA, fsize);
87 meter_width = fl_width(meter_face);
88 }
89 fsize--;
90 fl_font(FL_HELVETICA, fsize);
91 meter_width = fl_width(meter_face);
92 meter_height = fl_height();
93 label(meter_face);
94 labelfont(FL_HELVETICA);
95 labelsize(fsize);
96 labelcolor(scale_color);
97
98 meter_width -= fl_width("|");
99 sx = (tw - meter_width) / 2;
100
101 }
102
resize(int X,int Y,int W,int H)103 void Smeter::resize(int X, int Y, int W, int H) {
104 Fl_Widget::resize(X,Y,W,H);
105
106 bx = Fl::box_dx(box());
107 by = Fl::box_dy(box());
108 bw = Fl::box_dw(box());
109 bh = Fl::box_dh(box());
110
111 tx = X + bx;
112 tw = W - bw;
113 ty = Y + by;
114 th = H - bh;
115
116 static int fsize = 6;
117 fl_font(FL_HELVETICA, fsize);
118 meter_width = fl_width(meter_face);
119 while ((meter_width < tw) && (fl_height() < th)) {
120 fsize++;
121 fl_font(FL_HELVETICA, fsize);
122 meter_width = fl_width(meter_face);
123 }
124 fsize--;
125 fl_font(FL_HELVETICA, fsize);
126 meter_width = fl_width(meter_face);
127 meter_height = fl_height();
128 label(meter_face);
129 labelfont(FL_HELVETICA);
130 labelsize(fsize);
131 labelcolor(scale_color);
132
133 meter_width -= fl_width("|");
134 sx = (tw - meter_width) / 2;
135 }
136
handle(int event)137 int Smeter::handle(int event)
138 {
139 if (Fl::event_inside( this )) {
140 if (event == FL_RELEASE) {
141 do_callback();
142 return 1;
143 }
144 }
145 return 0;
146 }
147
148
149 //
150 // End of Smeter.cxx
151 //
152