1 // ----------------------------------------------------------------------------
2 // Copyright (C) 2014
3 //              David Freese, W1HKJ
4 //
5 // This file is part of flrig.
6 //
7 // flrig is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // flrig 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
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 // ----------------------------------------------------------------------------
20 //
21 // Please report all bugs and problems to: w1hkj@w1hkj.com
22 //
23 // Contents:
24 //
25 //   Fl_SigBar::draw()		- Draw the check button.
26 //   Fl_SigBar::Fl_SigBar() - Construct a Fl_SigBar widget.
27 //
28 
29 //
30 // Include necessary header files...
31 //
32 
33 #include <stdio.h>
34 #include <math.h>
35 
36 #include <FL/Fl.H>
37 #include <FL/fl_draw.H>
38 
39 #include "Fl_SigBar.h"
40 
41 //
42 // Fl_SigBar is a SigBar bar widget based off Fl_Widget that shows a
43 // standard Signal Bar with a peak reading indicator ...
44 //
45 
46 //
47 // 'Fl_SigBar::draw()' - Draw the check button.
48 //
49 
draw()50 void Fl_SigBar::draw()
51 {
52 // Get the box borders...
53 	int bx = Fl::box_dx(box());
54 	int by = Fl::box_dy(box());
55 	int bw = Fl::box_dw(box());
56 	int bh = Fl::box_dh(box());
57 // Size of SigBar bar...
58 	int SigBar;
59 	int PeakPos;
60 
61 
62 // Draw the SigBar bar...
63 // Draw the box and label...
64 	if (horiz == true) {
65 		int tx, tw;	 // Temporary X + width
66 		tx = x() + bx;
67 		tw = w() - bw;
68 		SigBar = (int)(tw * (value_ - minimum_) / (maximum_ - minimum_) + 0.5f);
69 		PeakPos = (int)(tw * (peakv_ - minimum_) / (maximum_ - minimum_) + 0.5f);
70 		if (SigBar > 0 ) { //|| PeakPos > 0) {
71 
72 			fl_clip(x(), y(), SigBar + bx, h());
73 			draw_box(box(), x(), y(), w(), h(), active_r() ? color() : fl_inactive(color()));
74 			fl_pop_clip();
75 
76 			fl_clip(tx + SigBar, y(), w() - SigBar, h());
77 			draw_box(box(), x(), y(), w(), h(), active_r() ? color2() : fl_inactive(color2()));
78 			fl_pop_clip();
79 
80 			fl_clip(tx + PeakPos, y(), 2, h());
81 			draw_box(box(), x(), y(), w(), h(), pkcolor);
82 			fl_pop_clip();
83 
84 		} else
85 			draw_box(box(), x(), y(), w(), h(), color2());
86 	} else {
87 		int ty, th;	 // Temporary Y + height
88 		ty = y() + by;
89 		th = h() - bh;
90 		SigBar = (int)(th * (value_ - minimum_) / (maximum_ - minimum_) + 0.5f);
91 		PeakPos = (int)(th * (peakv_ - minimum_) / (maximum_ - minimum_) + 0.5f);
92 		if (SigBar > 0 ) { //|| PeakPos > 0) {
93 
94 			fl_clip(x(), y(), w(), SigBar + by);
95 			draw_box(box(), x(), y(), w(), h(), FL_BLACK);
96 			fl_pop_clip();
97 
98 
99 			fl_clip(x(), ty + SigBar, w(), h() - SigBar);
100 			draw_box(box(), x(), y(), w(), h(), color());
101 			fl_pop_clip();
102 
103 			fl_clip(x(), ty + PeakPos, w(), 2);
104 			draw_box(box(), x(), y(), w(), h(), pkcolor);
105 			fl_pop_clip();
106 
107 		} else
108 			draw_box(box(), x(), y(), w(), h(), color2());
109 	}
110 }
111 
112 
113 //
114 // 'Fl_SigBar::Fl_SigBar()' - Construct a Fl_SigBar widget.
115 //
116 
Fl_SigBar(int X,int Y,int W,int H,const char * l)117 Fl_SigBar::Fl_SigBar(int X, int Y, int W, int H, const char* l)
118 : Fl_Widget(X, Y, W, H, l)
119 {
120 	align(FL_ALIGN_INSIDE);
121 	peakv_ = 0.0f;
122 	value_ = 0.0f;
123 	horiz = true;
124 	pkcolor = FL_RED;
125 	clear();
126 	avg_ = 5;
127 	aging_ = 5;
128 }
129 
peak(float v)130 void Fl_SigBar::peak( float v)
131 {
132 	peakv_ = v;
133 
134 	for (int i = 1; i < aging_; i++)
135 		if (peakv_ < (peak_[i-1] = peak_[i]))
136 			peakv_ = peak_[i];
137 
138 	peak_[aging_ - 1] = v;
139 
140 }
141 
value(float v)142 void Fl_SigBar::value(float v)
143 {
144 //	value_ -= vals_[0];
145 //	for (int i = 1; i < avg_; i++) vals_[i-1] = vals_[i];
146 //	value_ += (vals_[avg_- 1] = v / avg_);
147 //	peak(value_);
148 	peak(value_ = v);
149 };
150 
151 //
152 // End of "$Id: Fl_SigBar.cxx 4288 2005-04-16 00:13:17Z mike $".
153 //
154