-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.cpp
More file actions
242 lines (201 loc) · 7.67 KB
/
gui.cpp
File metadata and controls
242 lines (201 loc) · 7.67 KB
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#include "gui.h"
static GtkWidget *label_offset;
static GtkWidget *label_radius;
static GtkWidget *spinbutton_radius;
static GtkWidget *spinbutton_offset;
static GtkWidget *combo_box;
/**
* @brief Updates the gui (spinners, labels etc.)
*
* param[in] w the GtkWidget which caused the "trouble" (;
*
* This function has to be called every time the CUDA-Filter changes.
* It disables unneeded options
*/
static void update_gui( GtkWidget *w) {
int value = -1;
gimp_int_combo_box_get_active( GIMP_INT_COMBO_BOX( combo_box), &value);
switch ( value) {
case GREY:
gtk_label_set_text_with_mnemonic( GTK_LABEL( label_radius), "_Value");
gtk_widget_set_visible( label_offset, FALSE);
gtk_widget_set_visible( spinbutton_offset, FALSE);
gtk_widget_set_visible( label_radius, TRUE);
gtk_widget_set_visible( spinbutton_radius, TRUE);
break;
case SOBEL:
gtk_widget_set_visible( label_offset, FALSE);
gtk_widget_set_visible( spinbutton_offset, FALSE);
gtk_widget_set_visible( label_radius, FALSE);
gtk_widget_set_visible( spinbutton_radius, FALSE);
break;
case BOXBIN:
gtk_label_set_text_with_mnemonic( GTK_LABEL( label_radius), "_Radius");
gtk_label_set_text_with_mnemonic( GTK_LABEL( label_offset), "_Offset");
gtk_widget_set_visible( label_offset, TRUE);
gtk_widget_set_visible( spinbutton_offset, TRUE);
gtk_widget_set_visible( label_radius, TRUE);
gtk_widget_set_visible( spinbutton_radius, TRUE);
break;
case BOX:
gtk_label_set_text_with_mnemonic( GTK_LABEL( label_radius), "_Radius");
gtk_label_set_text_with_mnemonic( GTK_LABEL( label_offset), "_Offset");
gtk_widget_set_visible( label_offset, FALSE);
gtk_widget_set_visible( spinbutton_offset, FALSE);
gtk_widget_set_visible( label_radius, TRUE);
gtk_widget_set_visible( spinbutton_radius, TRUE);
break;
case TEST:
gtk_label_set_text_with_mnemonic( GTK_LABEL( label_radius), "_Radius");
gtk_label_set_text_with_mnemonic( GTK_LABEL( label_offset), "_Offset");
gtk_widget_set_visible( label_offset, FALSE);
gtk_widget_set_visible( spinbutton_offset, FALSE);
gtk_widget_set_visible( label_radius, FALSE);
gtk_widget_set_visible( spinbutton_radius, FALSE);
break;
case AVERAGE:
filterParm.radius = 7;
gtk_label_set_text_with_mnemonic( GTK_LABEL( label_radius), "_Radius = FIX 7!");
gtk_label_set_text_with_mnemonic( GTK_LABEL( label_offset), "_Offset");
gtk_widget_set_visible( label_offset, FALSE);
gtk_widget_set_visible( spinbutton_offset, FALSE);
gtk_widget_set_visible( label_radius, TRUE);
gtk_widget_set_visible( spinbutton_radius, FALSE);
break;
case AVERAGEBIN:
filterParm.radius = 7;
gtk_label_set_text_with_mnemonic( GTK_LABEL( label_radius), "_Radius = FIX 7!");
gtk_label_set_text_with_mnemonic( GTK_LABEL( label_offset), "_Offset");
gtk_widget_set_visible( label_offset, TRUE);
gtk_widget_set_visible( spinbutton_offset, TRUE);
gtk_widget_set_visible( label_radius, TRUE);
gtk_widget_set_visible( spinbutton_radius, FALSE);
break;
default:
gtk_label_set_text_with_mnemonic( GTK_LABEL( label_radius), "_Radius");
gtk_label_set_text_with_mnemonic( GTK_LABEL( label_offset), "_Offset");
gtk_widget_set_visible( label_offset, FALSE);
gtk_widget_set_visible( spinbutton_offset, FALSE);
gtk_widget_set_visible( label_radius, TRUE);
gtk_widget_set_visible( spinbutton_radius, TRUE);
break;
}
}
gboolean gicu_dialog (GimpDrawable *drawable) {
GtkWidget *dialog;
GtkWidget *main_vbox;
GtkWidget *main_hbox;
GtkWidget *preview;
GtkWidget *frame;
GtkWidget *alignment;
GtkObject *spinbutton_adj_radius;
GtkObject *spinbutton_adj_offset;
gboolean run;
int x1, y1, x2, y2, width;
gimp_ui_init ("gicu", FALSE);
dialog = gimp_dialog_new (
"CUDA-Filter parameter", "gicu",
NULL, GTK_DIALOG_MODAL,
gimp_standard_help_func, "plug-in-gicu",
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
main_vbox = gtk_vbox_new( FALSE, 5);
gtk_container_add( GTK_CONTAINER( GTK_DIALOG( dialog)->vbox), main_vbox);
gtk_widget_show (main_vbox);
preview = gimp_drawable_preview_new( drawable, &filterParm.preview);
gtk_box_pack_start( GTK_BOX( main_vbox), preview, FALSE, FALSE, 0);
gtk_widget_show( preview);
frame = gimp_frame_new( "CUDA-Filter-Options");
gtk_box_pack_start( GTK_BOX( main_vbox), frame, FALSE, FALSE, 0);
gtk_widget_show( frame);
alignment = gtk_alignment_new( 0.5, 0.5, 1, 1);
gtk_container_add( GTK_CONTAINER ( frame), alignment);
gtk_alignment_set_padding( GTK_ALIGNMENT( alignment), 5, 5, 5, 5);
gtk_widget_show( alignment);
main_hbox = gtk_hbox_new( FALSE, 5);
gtk_container_set_border_width( GTK_CONTAINER( main_hbox), 5);
gtk_container_add( GTK_CONTAINER( alignment), main_hbox);
gtk_widget_show( main_hbox);
label_radius = gtk_label_new_with_mnemonic( "_Radius:");
gtk_box_pack_start( GTK_BOX( main_hbox), label_radius, FALSE, FALSE, 5);
gtk_label_set_justify( GTK_LABEL( label_radius), GTK_JUSTIFY_RIGHT);
// gtk_widget_show( label_radius);
spinbutton_radius = gimp_spin_button_new (
&spinbutton_adj_radius, filterParm.radius,
1, 255, 1, 0, 0, 5, 0);
gtk_box_pack_start( GTK_BOX( main_hbox), spinbutton_radius, FALSE, FALSE, 0);
// gtk_widget_show( spinbutton_radius);
label_offset = gtk_label_new_with_mnemonic( "_Offset:");
gtk_box_pack_start( GTK_BOX( main_hbox), label_offset, FALSE, FALSE, 5);
gtk_label_set_justify( GTK_LABEL( label_offset), GTK_JUSTIFY_RIGHT);
// gtk_widget_show( label_offset);
spinbutton_offset = gimp_spin_button_new (
&spinbutton_adj_offset, filterParm.offset,
0, 255, 1, 0, 0, 5, 0);
gtk_box_pack_start( GTK_BOX( main_hbox), spinbutton_offset, FALSE, FALSE, 0);
// gtk_widget_show( spinbutton_offset);
combo_box = gimp_int_combo_box_new (
("Grey"), GREY,
("Sobel"), SOBEL,
("Boxing"), BOX,
("Boxing (Bin)"), BOXBIN,
("Fast Average"), AVERAGE,
("Fast Average (Bin)"), AVERAGEBIN,
("Test"), TEST,
NULL);
gtk_box_pack_start( GTK_BOX( main_vbox), combo_box, FALSE, FALSE, 0);
gtk_widget_show( combo_box);
/* Wenn das Bild invalid ist, cuda ausfuehren */
g_signal_connect_swapped (
preview, "invalidated",
G_CALLBACK( cuda),
drawable);
/* wenn sich radius/offset/... aendert, Bild invalid markieren */
g_signal_connect_swapped (
spinbutton_adj_radius, "value_changed",
G_CALLBACK( gimp_preview_invalidate),
preview);
g_signal_connect_swapped (
spinbutton_adj_offset, "value_changed",
G_CALLBACK( gimp_preview_invalidate),
preview);
g_signal_connect_swapped (
combo_box, "changed",
G_CALLBACK( gimp_preview_invalidate),
preview);
/* Wenn sich .... aendert, es auch in filterParm speichern */
g_signal_connect (
spinbutton_adj_radius, "value_changed",
G_CALLBACK( gimp_int_adjustment_update),
&filterParm.radius);
g_signal_connect (
spinbutton_adj_offset, "value_changed",
G_CALLBACK( gimp_int_adjustment_update),
&filterParm.offset);
/* Set signals to the combobox */
/* Wenn sich wert aendert, filterparm speicher */
gimp_int_combo_box_connect(
GIMP_INT_COMBO_BOX( combo_box), 1, /* Default active value */
G_CALLBACK( gimp_int_combo_box_get_active), &filterParm.cuda_filter);
g_signal_connect (
GIMP_INT_COMBO_BOX( combo_box), "changed",
G_CALLBACK( update_gui),
NULL);
cuda( drawable, GIMP_PREVIEW( preview));
gtk_widget_show( dialog);
run = ( gimp_dialog_run( GIMP_DIALOG( dialog)) == GTK_RESPONSE_OK);
gimp_drawable_mask_bounds(
drawable->drawable_id,
&x1, &y1,
&x2, &y2);
width = x2 - x1;
if ( width % 4 ) {
if ( filterParm.cuda_filter == AVERAGE || filterParm.cuda_filter == AVERAGEBIN) {
g_message("Width is not a multiply of 4\n");
run = FALSE;
}
}
gtk_widget_destroy( dialog);
return run;
}