File: spectool_gtk_widget.h

package info (click to toggle)
spectools 201601r1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 1,272 kB
  • ctags: 1,837
  • sloc: ansic: 18,708; sh: 2,476; makefile: 85
file content (215 lines) | stat: -rw-r--r-- 6,055 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/* spectool generic gtk widget 
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "config.h"

#ifndef __SPECTOOL_GTK_WIDGET_H__
#define __SPECTOOL_GTK_WIDGET_H__

#ifdef HAVE_GTK

#include <glib.h>
#include <glib-object.h>
#include <cairo.h>

#include "spectool_container.h"
#include "spectool_gtk_hw_registry.h"

/* 
 * Common GTK widget layer, provides functions for handling picking a device, 
 * determining and printing channels, etc
 *
 * Should save several hundred lines of shared code off descendant widgets
 * (Spectral, Planar, Topographic, Foo)
 *
 */

G_BEGIN_DECLS

/* Hex color to cairo color */
#define HC2CC(x)				((double) ((double) (x) / (double) 0xFF))

#define SPECTOOL_TYPE_WIDGET \
	(spectool_widget_get_type())
#define SPECTOOL_WIDGET(obj) \
	(G_TYPE_CHECK_INSTANCE_CAST((obj), \
	SPECTOOL_TYPE_WIDGET, SpectoolWidget))
#define SPECTOOL_WIDGET_CLASS(klass) \
	(G_TYPE_CHECK_CLASS_CAST((klass), \
	SPECTOOL_TYPE_WIDGET, SpectoolWidgetClass))
#define IS_SPECTOOL_WIDGET(obj) \
	(G_TYPE_CHECK_INSTANCE_TYPE((obj), \
	SPECTOOL_TYPE_WIDGET))
#define IS_SPECTOOL_WIDGET_CLASS(klass) \
	(G_TYPE_CHECK_CLASS_TYPE((class), \
	SPECTOOL_TYPE_WIDGET))

typedef struct _SpectoolWidget SpectoolWidget;
typedef struct _SpectoolWidgetClass SpectoolWidgetClass;

typedef struct _SpectoolChannelOpts {
	int chan_h;
	int *chanhit;
	double *chancolors;
	struct spectool_channels *chanset;

	/* Hilighted channel, if we're showing channels */
	int hi_chan;
} SpectoolChannelOpts;

void spectoolchannelopts_init(SpectoolChannelOpts *in);

struct _SpectoolWidget {
	GtkBinClass parent;

	int hlines;
	/* Top of DB graph, max sample reported */
	int base_db_offset;
	/* Bottom of db graph, min sample reported */
	int min_db_draw;

	/* Conversion data */
	int amp_offset_mdbm;
	int amp_res_mdbm;

	/* Graph elements we've calculated */
	int g_start_x, g_start_y, g_end_x, g_end_y,
		g_len_x, g_len_y;
	int dbm_w;
	double wbar;

	gint timeout_ref;

	GtkWidget *vbox, *hbox, *infoeb;
	GtkWidget *sweepinfo;
	GtkWidget *draw, *menubutton;

	spectool_sweep_cache *sweepcache;

	/* To be set by children to control behavior */
	int sweep_num_samples;
	int sweep_keep_avg;
	int sweep_keep_peak;
	int sweep_roll_peak;
	int sweep_num_aggregate;

	/* Callbacks used by open, sweep */
	void (* wdr_sweep_func)(int, int, spectool_sample_sweep *, void *);
	void (* wdr_devbind_func)(GtkWidget *, spectool_device_registry *, int);

	spectool_device_registry *wdr;
	int wdr_slot;
	spectool_phy *phydev;

	/* Graph title (INCLUDING formatting) */
	char *graph_title;

	/* Graph background colors */
	char *graph_title_bg, *graph_control_bg;

	/* Menu callback, allows for adding custom items to the widget dropdown
	 * arrow menu 
	 * arg1 - widget 
	 * arg2 - menu */
	void (* menu_func)(GtkWidget *, GtkWidget *);

	void (* help_func)(gpointer *);

	/* Offscreen surface for regular drawing to be copied back during an expose */
	cairo_surface_t *offscreen;
	int old_width, old_height;

	/* Callbacks for drawing */
	int draw_timeout;
	void (* draw_func)(GtkWidget *, cairo_t *, SpectoolWidget *);

	/* Callbacks on size change */
	void (* sizechange_func)(GtkWidget *, GtkAllocation *);

	/* Plot channels on the bottom */
	int show_channels;
	/* Show DBM */
	int show_dbm;
	/* Show DBM lines */
	int show_dbm_lines;

	/* Callbacks for mouse events */
	gint (* draw_mouse_click_func)(GtkWidget *, GdkEventButton *, gpointer *);
	gboolean (* draw_mouse_move_func)(GtkWidget *, GdkEventMotion *, gpointer *);

	/* Update function */
	void (* update_func)(GtkWidget *);

	SpectoolChannelOpts *chanopts;

	/* Have we gotten a sweep? */
	int dirty;
};

struct _SpectoolWidgetClass {
	GtkBinClass parent_class;
};

/* Controller item - didn't feel like making this a full widget, so you ask
 * the widget to make you a controller then embed the box prior to the widget */
typedef struct _SpectoolWidgetController {
	/* Main widget */
	GtkWidget *evbox;

	GtkWidget *label, *arrow, *menubutton;
	SpectoolWidget *wwidget;
} SpectoolWidgetController;

GType spectool_widget_get_type(void);
GtkWidget *spectool_widget_new(void);
void spectool_widget_bind_dev(GtkWidget *widget, spectool_device_registry *wdr,
						   int slot);

/* Do the heavy lifting of actually constructing the GUI, so that child
 * classes can trigger this after setting up titles, etc.  I'm sure this
 * isn't the most elegant method, someone can send me a patch */
void spectool_widget_buildgui(SpectoolWidget *widget);

/* Update the backing graphics */
void spectool_widget_graphics_update(SpectoolWidget *wwidget);

SpectoolWidgetController *spectool_widget_buildcontroller(GtkWidget *widget);

void spectool_widget_link_channel(GtkWidget *widget, SpectoolChannelOpts *opts);

/* Timeout function */
gint spectool_widget_timeout(gpointer *data);

/* Calculate the channel clicked in */
/*inline*/ int spectool_widget_find_chan_pt(SpectoolWidget *wwidget, int x, int y);

void spectool_widget_context_channels(gpointer *aux);
void spectool_widget_context_dbm(gpointer *aux);
void spectool_widget_context_dbmlines(gpointer *aux);

/* Color space conversion tools */
/*inline*/ void rgb_to_hsv(double r, double g, double b,
					   double *h, double *s, double *v);
/*inline*/ void hsv_to_rgb(double *r, double *g, double *b,
					   double h, double s, double v);

G_END_DECLS

#endif
#endif