-
Notifications
You must be signed in to change notification settings - Fork 0
/
wave_window.c
134 lines (116 loc) · 4.73 KB
/
wave_window.c
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
/*
* Metaann
*
* Copyright (C) 2014 Benjamin Moody
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "wave.h"
#include "gtkwave.h"
void set_display_start_time(WFDB_Time t)
{
display_start_time = MAX(0, t);
gtk_widget_queue_draw(wave_view);
}
static void scroll_back_full(G_GNUC_UNUSED GtkButton *btn,
G_GNUC_UNUSED gpointer data)
{
set_display_start_time(display_start_time - nsamp);
}
static void scroll_back_half(G_GNUC_UNUSED GtkButton *btn,
G_GNUC_UNUSED gpointer data)
{
set_display_start_time(display_start_time - nsamp / 2);
}
static void scroll_forward_half(G_GNUC_UNUSED GtkButton *btn,
G_GNUC_UNUSED gpointer data)
{
set_display_start_time(display_start_time + nsamp / 2);
}
static void scroll_forward_full(G_GNUC_UNUSED GtkButton *btn,
G_GNUC_UNUSED gpointer data)
{
set_display_start_time(display_start_time + nsamp);
}
static void grid_mode_changed(GtkComboBox *combo,
G_GNUC_UNUSED gpointer data)
{
set_grid_mode(gtk_combo_box_get_active(combo));
}
static GtkWidget *make_arrows(int n, GtkArrowType type)
{
GtkWidget *box, *arrow, *align;
box = gtk_hbox_new(FALSE, 0);
while (n > 0) {
arrow = gtk_arrow_new(type, GTK_SHADOW_NONE);
gtk_box_pack_start(GTK_BOX(box), arrow, FALSE, FALSE, 0);
n--;
}
align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
gtk_container_add(GTK_CONTAINER(align), box);
return align;
}
GtkWidget *create_wave_window()
{
static const char * const grid_items[] =
{ "None", "0.2 s", "0.5 mV", "0.2 s x 0.5 mV",
"0.04 s x 0.1 mV", "1 m x 0.5 mV", "1 m x 0.1 mV" };
GtkWidget *window, *vbox, *hbox, *hbox2, *btn, *wv, *lbl, *combo;
int i;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
hbox = gtk_hbox_new(FALSE, 12);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(hbox), 3);
/* Grid options */
hbox2 = gtk_hbox_new(FALSE, 6);
gtk_box_pack_start(GTK_BOX(hbox), hbox2, FALSE, FALSE, 6);
lbl = gtk_label_new("Grid:");
gtk_box_pack_start(GTK_BOX(hbox2), lbl, FALSE, FALSE, 0);
combo = gtk_combo_box_new_text();
for (i = 0; i < (int) G_N_ELEMENTS(grid_items); i++)
gtk_combo_box_append_text(GTK_COMBO_BOX(combo), grid_items[i]);
gtk_box_pack_start(GTK_BOX(hbox2), combo, TRUE, TRUE, 0);
/* Navigation buttons */
hbox2 = gtk_hbox_new(TRUE, 6);
gtk_box_pack_start(GTK_BOX(hbox), hbox2, TRUE, TRUE, 0);
btn = gtk_button_new();
gtk_container_add(GTK_CONTAINER(btn), make_arrows(2, GTK_ARROW_LEFT));
gtk_widget_set_tooltip_text(btn, "Scroll backward by a full screen");
g_signal_connect(btn, "clicked", G_CALLBACK(scroll_back_full), NULL);
gtk_box_pack_start(GTK_BOX(hbox2), btn, FALSE, TRUE, 0);
btn = gtk_button_new();
gtk_container_add(GTK_CONTAINER(btn), make_arrows(1, GTK_ARROW_LEFT));
gtk_widget_set_tooltip_text(btn, "Scroll backward by half a screen");
g_signal_connect(btn, "clicked", G_CALLBACK(scroll_back_half), NULL);
gtk_box_pack_start(GTK_BOX(hbox2), btn, FALSE, TRUE, 0);
btn = gtk_button_new();
gtk_container_add(GTK_CONTAINER(btn), make_arrows(1, GTK_ARROW_RIGHT));
gtk_widget_set_tooltip_text(btn, "Scroll forward by half a screen");
g_signal_connect(btn, "clicked", G_CALLBACK(scroll_forward_half), NULL);
gtk_box_pack_start(GTK_BOX(hbox2), btn, FALSE, TRUE, 0);
btn = gtk_button_new();
gtk_container_add(GTK_CONTAINER(btn), make_arrows(2, GTK_ARROW_RIGHT));
gtk_widget_set_tooltip_text(btn, "Scroll forward by a full screen");
g_signal_connect(btn, "clicked", G_CALLBACK(scroll_forward_full), NULL);
gtk_box_pack_start(GTK_BOX(hbox2), btn, FALSE, TRUE, 0);
wv = create_wave_view();
gtk_widget_set_size_request(wv, 200, 200);
gtk_box_pack_start(GTK_BOX(vbox), wv, TRUE, TRUE, 0);
gtk_combo_box_set_active(GTK_COMBO_BOX(combo), grid_mode);
g_signal_connect(combo, "changed", G_CALLBACK(grid_mode_changed), NULL);
gtk_widget_show_all(vbox);
return window;
}