File: spectool_gtk_widget.h

package info (click to toggle)
spectools 200710R2-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 956 kB
  • ctags: 1,081
  • sloc: ansic: 7,407; sh: 2,466; cpp: 864; makefile: 143
file content (209 lines) | stat: -rw-r--r-- 5,752 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
/* 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 __WISPY_GTK_WIDGET_H__
#define __WISPY_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 WISPY_TYPE_WIDGET \
	(wispy_widget_get_type())
#define WISPY_WIDGET(obj) \
	(G_TYPE_CHECK_INSTANCE_CAST((obj), \
	WISPY_TYPE_WIDGET, WispyWidget))
#define WISPY_WIDGET_CLASS(klass) \
	(G_TYPE_CHECK_CLASS_CAST((klass), \
	WISPY_TYPE_WIDGET, WispyWidgetClass))
#define IS_WISPY_WIDGET(obj) \
	(G_TYPE_CHECK_INSTANCE_TYPE((obj), \
	WISPY_TYPE_WIDGET))
#define IS_WISPY_WIDGET_CLASS(klass) \
	(G_TYPE_CHECK_CLASS_TYPE((class), \
	WISPY_TYPE_WIDGET))

typedef struct _WispyWidget WispyWidget;
typedef struct _WispyWidgetClass WispyWidgetClass;

typedef struct _WispyChannelOpts {
	int chan_h;
	int *chanhit;
	double *chancolors;
	struct wispy_channels *chanset;

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

void wispychannelopts_init(WispyChannelOpts *in);

struct _WispyWidget {
	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;

	wispy_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, wispy_sample_sweep *, void *);
	void (* wdr_devbind_func)(GtkWidget *, wispy_device_registry *, int);

	wispy_device_registry *wdr;
	int wdr_slot;
	wispy_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 *, WispyWidget *);

	/* 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 *);

	WispyChannelOpts *chanopts;
};

struct _WispyWidgetClass {
	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 _WispyWidgetController {
	/* Main widget */
	GtkWidget *evbox;

	GtkWidget *label, *arrow, *menubutton;
	WispyWidget *wwidget;
} WispyWidgetController;

GType wispy_widget_get_type(void);
GtkWidget *wispy_widget_new(void);
void wispy_widget_bind_dev(GtkWidget *widget, wispy_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 wispy_widget_buildgui(WispyWidget *widget);

/* Update the backing graphics */
void wispy_widget_graphics_update(WispyWidget *wwidget);

WispyWidgetController *wispy_widget_buildcontroller(GtkWidget *widget);

void wispy_widget_link_channel(GtkWidget *widget, WispyChannelOpts *opts);

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

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

void wispy_widget_context_channels(gpointer *aux);
void wispy_widget_context_dbm(gpointer *aux);
void wispy_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