3
// Signal Bar widget definitions.
5
// Copyright 2011 Dave Freese, W1HKJ
7
// This source code is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Library General Public
9
// License as published by the Free Software Foundation; either
10
// version 2 of the License, or (at your option) any later version.
12
// This source code is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
// Library General Public License for more details.
17
// You should have received a copy of the GNU Library General Public
18
// License along with this library; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22
// Please report all bugs and problems to: w1hkj@w1hkj.com
26
// Fl_SigBar::draw() - Draw the check button.
27
// Fl_SigBar::Fl_SigBar() - Construct a Fl_SigBar widget.
31
// Include necessary header files...
38
#include <FL/fl_draw.H>
40
#include "Fl_SigBar.h"
43
// Fl_SigBar is a SigBar bar widget based off Fl_Widget that shows a
44
// standard Signal Bar with a peak reading indicator ...
48
// 'Fl_SigBar::draw()' - Draw the check button.
51
void Fl_SigBar::draw()
53
// Get the box borders...
54
int bx = Fl::box_dx(box());
55
int by = Fl::box_dy(box());
56
int bw = Fl::box_dw(box());
57
int bh = Fl::box_dh(box());
58
// Size of SigBar bar...
63
// Draw the SigBar bar...
64
// Draw the box and label...
66
int tx, tw; // Temporary X + width
69
SigBar = (int)(tw * (value_ - minimum_) / (maximum_ - minimum_) + 0.5f);
70
PeakPos = (int)(tw * (peakv_ - minimum_) / (maximum_ - minimum_) + 0.5f);
71
if (SigBar > 0 ) { //|| PeakPos > 0) {
73
fl_clip(x(), y(), SigBar + bx, h());
74
draw_box(box(), x(), y(), w(), h(), active_r() ? color() : fl_inactive(color()));
77
fl_clip(tx + SigBar, y(), w() - SigBar, h());
78
draw_box(box(), x(), y(), w(), h(), active_r() ? color2() : fl_inactive(color2()));
81
fl_clip(tx + PeakPos, y(), 2, h());
82
draw_box(box(), x(), y(), w(), h(), pkcolor);
86
draw_box(box(), x(), y(), w(), h(), color2());
88
int ty, th; // Temporary Y + height
91
SigBar = (int)(th * (value_ - minimum_) / (maximum_ - minimum_) + 0.5f);
92
PeakPos = (int)(th * (peakv_ - minimum_) / (maximum_ - minimum_) + 0.5f);
93
if (SigBar > 0 ) { //|| PeakPos > 0) {
95
fl_clip(x(), y(), w(), SigBar + by);
96
draw_box(box(), x(), y(), w(), h(), FL_BLACK);
100
fl_clip(x(), ty + SigBar, w(), h() - SigBar);
101
draw_box(box(), x(), y(), w(), h(), color());
104
fl_clip(x(), ty + PeakPos, w(), 2);
105
draw_box(box(), x(), y(), w(), h(), pkcolor);
109
draw_box(box(), x(), y(), w(), h(), color2());
115
// 'Fl_SigBar::Fl_SigBar()' - Construct a Fl_SigBar widget.
118
Fl_SigBar::Fl_SigBar(int X, int Y, int W, int H, const char* l)
119
: Fl_Widget(X, Y, W, H, l)
121
align(FL_ALIGN_INSIDE);
131
void Fl_SigBar::peak( float v)
135
for (int i = 1; i < aging_; i++)
136
if (peakv_ < (peak_[i-1] = peak_[i]))
139
peak_[aging_ - 1] = v;
143
void Fl_SigBar::value(float v)
147
for (int i = 1; i < avg_; i++) vals_[i-1] = vals_[i];
149
value_ += (vals_[avg_- 1] = v / avg_);
155
// End of "$Id: Fl_SigBar.cxx 4288 2005-04-16 00:13:17Z mike $".