Mercurial > cropper
annotate callbacks.c @ 13:13bc21684b8a
added zooming with buttons
author | meillo@marmaro.de |
---|---|
date | Thu, 04 Mar 2010 17:05:38 +0100 |
parents | c18ba4ea1514 |
children | da18f2d4f92f |
rev | line source |
---|---|
0 | 1 #include <gtk/gtk.h> |
7
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
2 #include <gdk-pixbuf/gdk-pixbuf.h> |
13 | 3 #include <gdk/gdkkeysyms.h> |
2
e359bea4c8ac
added code for ratio swap; new names for ratio operations; added main.h; some more
meillo@marmaro.de
parents:
1
diff
changeset
|
4 #include "main.h" |
0 | 5 #include "callbacks.h" |
6 #include "support.h" | |
7 | |
7
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
8 int image_width; |
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
9 int image_height; |
10 | 10 float inc = 0.3; |
13 | 11 float zoom = 1.0; |
11 | 12 |
13 | |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
14 /* |
11 | 15 void |
16 update_spin_button_ratio(GtkWidget* spinbutton) | |
17 { | |
3 | 18 g_print("ratio change: %f\n", ratio); |
19 on_ratio_w_spinbutton_value_changed(spinbutton, NULL); | |
20 } | |
0 | 21 |
22 | |
11 | 23 void |
24 on_ratio_none_activate(GtkMenuItem* menuitem, gpointer user_data) | |
25 { | |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
26 ratio = 1; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
27 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
28 } |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
29 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
30 |
11 | 31 void |
32 on_ratio_square_activate(GtkMenuItem* menuitem, gpointer user_data) | |
33 { | |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
34 ratio = 1; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
35 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
36 } |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
37 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
38 |
11 | 39 void |
40 on_ratio_4x3_activate(GtkMenuItem* menuitem, gpointer user_data) | |
41 { | |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
42 ratio = 4.0/3.0; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
43 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
44 } |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
45 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
46 |
11 | 47 void |
48 on_ratio_3x2_activate(GtkMenuItem* menuitem, gpointer user_data) | |
49 { | |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
50 ratio = 1.5; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
51 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
52 } |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
53 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
54 |
11 | 55 void |
56 on_ratio_custom_activate(GtkMenuItem* menuitem, gpointer user_data) | |
57 { | |
58 ratio = gtk_spin_button_get_value(lookup_widget(cropper_window, "ratio_w_spinbutton")) | |
59 / gtk_spin_button_get_value(lookup_widget(cropper_window, "ratio_h_spinbutton")); | |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
60 update_spin_button_ratio(lookup_widget(cropper_window, "ratio_w_spinbutton")); |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
61 } |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
62 */ |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
63 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
64 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
65 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
66 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
67 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
68 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
69 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
70 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
71 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
72 /* |
11 | 73 static void |
74 ratio_optionmenu_changed_cb(GtkOptionMenu* optionmenu, gpointer unser_data) | |
75 { | |
76 int idx = gtk_option_menu_get_history(optionmenu); | |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
77 int w = 1, h = 1; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
78 gboolean use_ratio = TRUE; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
79 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
80 switch (idx) { |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
81 case GTH_CROP_RATIO_NONE: |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
82 use_ratio = FALSE; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
83 break; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
84 case GTH_CROP_RATIO_SQUARE: |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
85 w = h = 1; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
86 break; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
87 case GTH_CROP_RATIO_IMAGE: |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
88 w = lookup_widget(cropper_window, "image_width"); |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
89 h = lookup_widget(cropper_window, "image_height"); |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
90 break; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
91 case GTH_CROP_RATIO_DISPLAY: |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
92 w = lookup_widget(cropper_window, "display_width"); |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
93 h = lookup_widget(cropper_window, "display_height"); |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
94 break; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
95 case GTH_CROP_RATIO_4_3: |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
96 w = 4; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
97 h = 3; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
98 break; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
99 case GTH_CROP_RATIO_4_6: |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
100 w = 4; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
101 h = 6; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
102 break; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
103 case GTH_CROP_RATIO_CUSTOM: |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
104 default: |
11 | 105 w = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON( |
106 lookup_widget(cropper_window, "ratio_w_spinbutton"))); | |
107 h = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON( | |
108 lookup_widget(cropper_window, "ratio_h_spinbutton"))); | |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
109 break; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
110 } |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
111 |
11 | 112 gtk_widget_set_sensitive(lookup_widget(cropper_window, "custom_ratio_box"), |
113 idx == GTH_CROP_RATIO_CUSTOM); | |
114 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), w); | |
115 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), h); | |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
116 |
11 | 117 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR(lookup_widget(cropper_window, "crop_image")), |
118 use_ratio, (double) w / h); | |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
119 } |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
120 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
121 |
11 | 122 static void |
123 ratio_value_changed_cb(GtkSpinButton* spin, gpointer unser_data) | |
124 { | |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
125 int w, h; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
126 |
11 | 127 w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton")); |
128 h = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton")); | |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
129 |
11 | 130 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR( |
131 lookup_widget(cropper_window, "crop_image")), TRUE, (double) w / h); | |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
132 } |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
133 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
134 |
11 | 135 static void |
136 ratio_swap_button_cb(GtkButton* button, gpointer unser_data) | |
137 { | |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
138 int w, h; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
139 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
140 w = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_w_spinbutton")); |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
141 h = gtk_spin_button_get_value_as_int(lookup_widget(cropper_window, "ratio_h_spinbutton")); |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
142 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
143 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_w_spinbutton"), h); |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
144 set_spin_value(cropper_window, lookup_widget(cropper_window, "ratio_h_spinbutton"), w); |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
145 |
11 | 146 gth_image_selector_set_ratio(GTH_IMAGE_SELECTOR(lookup_widget(cropper_window, |
147 "crop_image")), TRUE, (double) h / w); | |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
148 } |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
149 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
150 */ |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
151 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
152 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
153 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
154 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
155 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
156 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
157 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
158 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
159 /* |
11 | 160 void |
161 on_ratio_w_spinbutton_value_changed(GtkSpinButton* spinbutton, gpointer user_data) | |
162 { | |
3 | 163 g_print("spinbutton W - ratio: %f\n", ratio); |
11 | 164 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_h_spinbutton"), |
165 gtk_spin_button_get_value(spinbutton) / ratio); | |
0 | 166 } |
167 | |
168 | |
11 | 169 void |
170 on_ratio_w_spinbutton_change_value(GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) | |
171 { | |
0 | 172 } |
173 | |
174 | |
11 | 175 void |
176 on_ratio_h_spinbutton_change_value(GtkSpinButton* spinbutton, GtkScrollType scroll, gpointer user_data) | |
177 { | |
0 | 178 } |
179 | |
180 | |
11 | 181 void |
182 on_ratio_h_spinbutton_value_changed(GtkSpinButton* spinbutton, gpointer user_data) | |
183 { | |
3 | 184 g_print("spinbutton H - ratio: %f\n", ratio); |
11 | 185 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), |
186 gtk_spin_button_get_value(spinbutton) * ratio); | |
0 | 187 |
188 } | |
189 | |
190 | |
11 | 191 void |
192 on_ratio_swap_button_clicked(GtkButton* button, gpointer user_data) | |
193 { | |
2
e359bea4c8ac
added code for ratio swap; new names for ratio operations; added main.h; some more
meillo@marmaro.de
parents:
1
diff
changeset
|
194 |
3 | 195 ratio = 1.0 / ratio; |
11 | 196 gtk_spin_button_set_value(lookup_widget(cropper_window, "ratio_w_spinbutton"), |
197 gtk_spin_button_get_value(lookup_widget(cropper_window, | |
198 "ratio_h_spinbutton"))); | |
3 | 199 gtk_spin_button_update(lookup_widget(cropper_window, "ratio_w_spinbutton")); |
200 | |
2
e359bea4c8ac
added code for ratio swap; new names for ratio operations; added main.h; some more
meillo@marmaro.de
parents:
1
diff
changeset
|
201 } |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
202 */ |
2
e359bea4c8ac
added code for ratio swap; new names for ratio operations; added main.h; some more
meillo@marmaro.de
parents:
1
diff
changeset
|
203 |
e359bea4c8ac
added code for ratio swap; new names for ratio operations; added main.h; some more
meillo@marmaro.de
parents:
1
diff
changeset
|
204 |
13 | 205 void |
206 update_title(char* zoom) | |
207 { | |
208 char title[128]; | |
209 snprintf(title, 128, "cropper (%s) %dx%d+%d+%d", zoom, w, h, x, y); | |
210 gtk_window_set_title(GTK_WINDOW(cropper_window), title); | |
211 } | |
212 | |
2
e359bea4c8ac
added code for ratio swap; new names for ratio operations; added main.h; some more
meillo@marmaro.de
parents:
1
diff
changeset
|
213 |
7
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
214 /* zoom */ |
11 | 215 void |
216 set_zoom() | |
217 { | |
8
b0824876d379
memory is now freed aswell; added (a crappy) zoom2fit; did some casts to get rid of warnings
meillo@marmaro.de
parents:
7
diff
changeset
|
218 static GdkPixbuf* pixbuf_new; |
b0824876d379
memory is now freed aswell; added (a crappy) zoom2fit; did some casts to get rid of warnings
meillo@marmaro.de
parents:
7
diff
changeset
|
219 g_object_unref(pixbuf_new); |
b0824876d379
memory is now freed aswell; added (a crappy) zoom2fit; did some casts to get rid of warnings
meillo@marmaro.de
parents:
7
diff
changeset
|
220 |
13 | 221 pixbuf_new = gdk_pixbuf_scale_simple(image_buffer, image_width*zoom, image_height*zoom, |
222 GDK_INTERP_BILINEAR); | |
8
b0824876d379
memory is now freed aswell; added (a crappy) zoom2fit; did some casts to get rid of warnings
meillo@marmaro.de
parents:
7
diff
changeset
|
223 gtk_image_set_from_pixbuf((GtkImage*) lookup_widget(cropper_window, "image_area"), pixbuf_new); |
b0824876d379
memory is now freed aswell; added (a crappy) zoom2fit; did some casts to get rid of warnings
meillo@marmaro.de
parents:
7
diff
changeset
|
224 } |
b0824876d379
memory is now freed aswell; added (a crappy) zoom2fit; did some casts to get rid of warnings
meillo@marmaro.de
parents:
7
diff
changeset
|
225 |
11 | 226 void |
227 on_zoom_in_button_clicked(GtkObject* object, gpointer user_data) | |
228 { | |
13 | 229 zoom *= 1 + inc; |
8
b0824876d379
memory is now freed aswell; added (a crappy) zoom2fit; did some casts to get rid of warnings
meillo@marmaro.de
parents:
7
diff
changeset
|
230 set_zoom(); |
7
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
231 } |
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
232 |
11 | 233 void |
234 on_zoom_out_button_clicked(GtkObject* object, gpointer user_data) | |
235 { | |
13 | 236 zoom *= 1 - inc; |
8
b0824876d379
memory is now freed aswell; added (a crappy) zoom2fit; did some casts to get rid of warnings
meillo@marmaro.de
parents:
7
diff
changeset
|
237 set_zoom(); |
7
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
238 } |
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
239 |
11 | 240 void |
241 on_zoom_100_button_clicked(GtkObject* object, gpointer user_data) | |
242 { | |
13 | 243 zoom = 1.0; |
8
b0824876d379
memory is now freed aswell; added (a crappy) zoom2fit; did some casts to get rid of warnings
meillo@marmaro.de
parents:
7
diff
changeset
|
244 set_zoom(); |
7
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
245 } |
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
246 |
11 | 247 void |
248 on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data) | |
249 { | |
8
b0824876d379
memory is now freed aswell; added (a crappy) zoom2fit; did some casts to get rid of warnings
meillo@marmaro.de
parents:
7
diff
changeset
|
250 int w, h; |
13 | 251 float zw, zh; |
8
b0824876d379
memory is now freed aswell; added (a crappy) zoom2fit; did some casts to get rid of warnings
meillo@marmaro.de
parents:
7
diff
changeset
|
252 GtkWidget* image_a; |
b0824876d379
memory is now freed aswell; added (a crappy) zoom2fit; did some casts to get rid of warnings
meillo@marmaro.de
parents:
7
diff
changeset
|
253 |
b0824876d379
memory is now freed aswell; added (a crappy) zoom2fit; did some casts to get rid of warnings
meillo@marmaro.de
parents:
7
diff
changeset
|
254 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area"); |
11 | 255 gdk_drawable_get_size(image_a->window, &w, &h); |
8
b0824876d379
memory is now freed aswell; added (a crappy) zoom2fit; did some casts to get rid of warnings
meillo@marmaro.de
parents:
7
diff
changeset
|
256 |
13 | 257 zw = w*1.0 / image_width; |
258 zh = h*1.0 / image_height; | |
259 | |
260 zoom = (zw < zh) ? zw : zh; | |
8
b0824876d379
memory is now freed aswell; added (a crappy) zoom2fit; did some casts to get rid of warnings
meillo@marmaro.de
parents:
7
diff
changeset
|
261 set_zoom(); |
7
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
262 } |
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
263 |
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
264 |
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
265 |
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
266 |
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
267 |
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
268 |
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
269 |
11 | 270 void |
271 on_crop_clicked(GtkButton* button, gpointer user_data) | |
272 { | |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
273 char crop_call[256]; |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
274 |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
275 sprintf(crop_call, "echo \"convert -crop %ix%i+%i+%i %s cropped_%s\"", |
11 | 276 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, |
277 "crop_width_spinbutton")), | |
278 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, | |
279 "crop_height_spinbutton")), | |
280 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, | |
281 "crop_x_spinbutton")), | |
282 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window, | |
283 "crop_y_spinbutton")), | |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
284 image_filename, |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
285 image_filename |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
286 ); |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
287 system(crop_call); |
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
288 gtk_main_quit(); |
0 | 289 } |
290 | |
11 | 291 |
292 void | |
293 on_cropper_window_create(GtkObject* object, gpointer user_data) | |
294 { | |
7
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
295 image_width = gdk_pixbuf_get_width(image_buffer); |
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
296 image_height = gdk_pixbuf_get_height(image_buffer); |
10 | 297 |
298 /* | |
11 | 299 image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL); |
300 image_area = gtk_image_new_from_pixbuf(image_buffer); | |
10 | 301 |
302 int w, h; | |
303 GtkWidget* image_a; | |
304 | |
305 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area"); | |
11 | 306 gdk_drawable_get_size(image_a->window, &w, &h); |
10 | 307 |
308 image_width = w - 200; | |
309 image_height = h - 150; | |
310 set_zoom(); | |
311 */ | |
7
ec2d11d96fb0
image is now gdk-pixbuff; zoom implemented in a basic way
meillo@marmaro.de
parents:
4
diff
changeset
|
312 } |
4
2f11ab3e6047
added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents:
3
diff
changeset
|
313 |
11 | 314 void |
315 on_cropper_window_destroy(GtkObject* object, gpointer user_data) | |
316 { | |
0 | 317 gtk_main_quit(); |
318 } | |
319 | |
13 | 320 |
321 | |
322 | |
323 gboolean | |
324 on_key_press(GtkWidget* window, GdkEventKey* pKey, gpointer userdata) | |
325 { | |
326 if (pKey->type != GDK_KEY_PRESS) { | |
327 return FALSE; | |
328 } | |
329 switch (pKey->keyval) { | |
330 case GDK_plus: | |
331 on_zoom_in_button_clicked(NULL, userdata); | |
332 break; | |
333 case GDK_minus: | |
334 on_zoom_out_button_clicked(NULL, userdata); | |
335 break; | |
336 case GDK_0: | |
337 on_zoom_100_button_clicked(NULL, userdata); | |
338 break; | |
339 case GDK_f: | |
340 on_zoom_fit_button_clicked(NULL, userdata); | |
341 break; | |
342 } | |
343 return TRUE; | |
344 } | |
345 | |
346 |