1 // ----------------------------------------------------------------------------
2 // spectrum Spectrum display Widget based on Digiscope widget
3 //
4 // Copyright (C) 2006-2017
5 // Dave Freese, W1HKJ
6 // Copyright (C) 2008
7 // Stelios Bounanos, M0GLD
8 //
9 // This file is part of fldigi. Adapted from code contained in gmfsk source code
10 // distribution.
11 // gmfsk Copyright (C) 2001, 2002, 2003
12 // Tomi Manninen (oh2bns@sral.fi)
13 // Copyright (C) 2004
14 // Lawrence Glaister (ve7it@shaw.ca)
15 //
16 // Fldigi is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 // Fldigi is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with fldigi. If not, see <http://www.gnu.org/licenses/>.
28 // ----------------------------------------------------------------------------
29
30 #include <config.h>
31
32 #include <iostream>
33 #include <cmath>
34 #include <cstring>
35
36 #include <FL/Fl.H>
37 #include <FL/fl_draw.H>
38
39 #include "spectrum.h"
40 #include "modem.h"
41 #include "trx.h"
42 #include "fl_digi.h"
43 #include "qrunner.h"
44
45 #include "configuration.h"
46
spectrum(int x,int y,int w,int h)47 spectrum::spectrum (int x, int y, int w, int h) :
48 Digiscope (x, y, w, h)
49 {
50 _paused = false;
51 _freq = 0;
52 _db = 0;
53 _db_diff = 0;
54 _f_diff = 0;
55 _gofreq = 0;
56 mode(spectrum::SCOPE);
57 }
58
~spectrum()59 spectrum::~spectrum()
60 {
61 }
62
handle_shift_leftclick(int x1)63 void spectrum::handle_shift_leftclick(int x1)
64 {
65 _gofreq = progdefaults.fftviewer_fcenter - progdefaults.fftviewer_frng / 2
66 + (1.0 * x1 / w()) * progdefaults.fftviewer_frng;
67 }
68
handle_leftclick(int x1,int y1)69 void spectrum::handle_leftclick( int x1, int y1)
70 {
71 if (Fl::event_state() & FL_SHIFT) {
72 handle_shift_leftclick(x1);
73 return;
74 }
75 if (Fl::event_key('1') || Fl::event_key(FL_KP + '1')) {
76 _y_user1 = 1.0 * y1 / h();
77 _x_user1 = 1.0 * x1 / w();
78 } else if (Fl::event_key('2') || Fl::event_key(FL_KP + '2')) {
79 _y_user2 = 1.0 * y1 / h();
80 _x_user2 = 1.0 * x1 / w();
81 } else if (Fl::event_key('c') || Fl::event_key('3') || Fl::event_key(FL_KP + '3')) {
82 _y_user1 = _y_user2 = -1;
83 _x_user1 = _x_user2 = -1;
84 } else {
85 _freq = progdefaults.fftviewer_fcenter - progdefaults.fftviewer_frng / 2
86 + (1.0 * x1 / w()) * progdefaults.fftviewer_frng;
87 _db = progdefaults.fftviewer_maxdb - (1.0 * y1 / h()) * progdefaults.fftviewer_range;
88 return;
89 }
90
91 if ((_y_user1 != -1) && (_y_user2 != -1))
92 _db_diff = (_y_user1 - _y_user2) * progdefaults.fftviewer_range;
93 else
94 _db_diff = 0;
95
96 if ((_x_user1 != -1) && (_x_user2 != -1))
97 _f_diff = (_x_user2 - _x_user1) * progdefaults.fftviewer_frng;
98 else
99 _db_diff = 0;
100
101 }
102
handle_rightclick(int x,int y)103 void spectrum::handle_rightclick( int x, int y)
104 {
105 _paused = !_paused;
106 }
107
handle(int event)108 int spectrum::handle(int event)
109 {
110 if (event == FL_ENTER) {
111 fl_cursor(FL_CURSOR_CROSS);
112 redraw();
113 return 1;
114 }
115 if (event == FL_LEAVE) {
116 fl_cursor(FL_CURSOR_ARROW);
117 redraw();
118 return 1;
119 }
120
121 if (!Fl::event_inside(this))
122 return 0;
123
124 switch (event) {
125 case FL_PUSH :
126 break;
127 case FL_RELEASE :
128 if (!Fl::event_inside(this))
129 break;
130 switch (Fl::event_button()) {
131 case FL_LEFT_MOUSE:
132 handle_leftclick(Fl::event_x() - x(), Fl::event_y() - y());
133 break;
134 case FL_RIGHT_MOUSE :
135 handle_rightclick(Fl::event_x() - x(), Fl::event_y() - y());
136 break;
137 default :
138 break;
139 }
140 default :
141 break;
142 }
143 return 1;
144 }
145
146