annotate main.c @ 17:4453456abad1

gathered all code in one file
author meillo@marmaro.de
date Thu, 04 Mar 2010 19:34:12 +0100
parents 7dbf3879939a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
1 #include <sys/types.h>
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
2 #include <sys/stat.h>
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
3 #include <unistd.h>
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
4 #include <string.h>
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
5 #include <stdio.h>
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
6
0
ca9155129253 initial commit
meillo@marmaro.de
parents:
diff changeset
7 #include <gtk/gtk.h>
17
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
8 #include <gdk/gdkkeysyms.h>
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
9 #include <gdk-pixbuf/gdk-pixbuf.h>
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
10
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
11
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
12
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
13
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
14 GtkWidget* cropper_window;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
15 char* image_filename;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
16
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
17 /* from interface.h */
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
18 GtkWidget* create_cropper_window(void);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
19 GtkWidget* image_area;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
20 GdkPixbuf* image_buffer;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
21
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
22 int w, h, x, y;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
23
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
24 int image_width;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
25 int image_height;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
26 float inc = 0.3;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
27 float zoom = 1.0;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
28
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
29 /* from callbacks.h */
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
30 double ratio;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
31
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
32 void crop(void);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
33 gboolean on_key_press(GtkWidget* window, GdkEventKey* pKey, gpointer userdata);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
34 void on_cropper_window_create(GtkObject* object, gpointer user_data);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
35 void on_cropper_window_destroy(GtkObject* object, gpointer user_data);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
36
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
37
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
38
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
39
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
40
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
41 #define GLADE_HOOKUP_OBJECT(component,widget,name) \
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
42 g_object_set_data_full(G_OBJECT(component), name, \
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
43 gtk_widget_ref(widget),(GDestroyNotify) gtk_widget_unref)
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
44
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
45 #define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
46 g_object_set_data(G_OBJECT(component), name, widget)
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
47
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
48
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
49 /*
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
50 * This function returns a widget in a component created by Glade.
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
51 * Call it with the toplevel widget in the component (i.e. a window/dialog),
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
52 * or alternatively any widget in the component, and the name of the widget
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
53 * you want returned.
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
54 */
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
55 GtkWidget*
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
56 lookup_widget(GtkWidget* widget, const gchar* widget_name)
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
57 {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
58 GtkWidget* parent;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
59 GtkWidget* found_widget;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
60
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
61 for (;;) {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
62 if (GTK_IS_MENU(widget)) {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
63 parent = gtk_menu_get_attach_widget(GTK_MENU(widget));
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
64 } else {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
65 parent = widget->parent;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
66 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
67 if (!parent) {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
68 parent = (GtkWidget*) g_object_get_data(G_OBJECT(widget), "GladeParentKey");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
69 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
70 if (parent == NULL) {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
71 break;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
72 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
73 widget = parent;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
74 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
75
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
76 found_widget = (GtkWidget*) g_object_get_data(G_OBJECT(widget), widget_name);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
77 if (!found_widget) {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
78 g_warning("Widget not found: %s", widget_name);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
79 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
80 return found_widget;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
81 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
82
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
83
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
84
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
85 GtkWidget*
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
86 create_cropper_window(void)
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
87 {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
88 GtkWidget *cropper_window;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
89 GtkWidget *dialog_vbox1;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
90 GtkWidget *status;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
91 GtkWidget *label1;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
92 GtkWidget *label2;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
93
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
94
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
95 cropper_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
96 gtk_widget_set_name(cropper_window, "cropper_window");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
97 gtk_container_set_border_width(GTK_CONTAINER(cropper_window), 6);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
98 gtk_window_set_title(GTK_WINDOW(cropper_window), "cropper-0.2");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
99
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
100 dialog_vbox1 = gtk_vbox_new(FALSE, 6);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
101 gtk_widget_set_name(dialog_vbox1, "dialog_vbox1");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
102 gtk_widget_show(dialog_vbox1);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
103 gtk_container_add(GTK_CONTAINER(cropper_window), dialog_vbox1);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
104
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
105
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
106 status = gtk_hbox_new(FALSE, 0);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
107 gtk_widget_set_name(status, "status");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
108 gtk_widget_show(status);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
109 gtk_box_pack_end(GTK_BOX(dialog_vbox1), status, FALSE, FALSE, 0);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
110
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
111 label1 = gtk_label_new("zoom:");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
112 gtk_widget_set_name(label1, "label1");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
113 gtk_widget_show(label1);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
114 gtk_box_pack_start(GTK_BOX(status), label1, FALSE, FALSE, 0);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
115
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
116 label2 = gtk_label_new("1.0");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
117 gtk_widget_set_name(label2, "label2");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
118 gtk_widget_show(label2);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
119 gtk_box_pack_start(GTK_BOX(status), label2, FALSE, FALSE, 0);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
120
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
121 /* image_area */
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
122 image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
123 image_area = gtk_image_new_from_pixbuf(image_buffer);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
124
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
125 gtk_widget_set_name(image_area, "image_area");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
126 gtk_widget_show(image_area);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
127 gtk_box_pack_start(GTK_BOX(dialog_vbox1), image_area, TRUE, TRUE, 0);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
128
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
129
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
130
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
131
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
132
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
133 g_signal_connect(G_OBJECT(cropper_window), "show",
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
134 G_CALLBACK(on_cropper_window_create), NULL);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
135
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
136 g_signal_connect(G_OBJECT(cropper_window), "destroy",
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
137 G_CALLBACK(on_cropper_window_destroy), NULL);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
138
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
139 g_signal_connect(cropper_window, "key-press-event",
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
140 G_CALLBACK(on_key_press), NULL);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
141
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
142
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
143 /* Store pointers to all widgets, for use by lookup_widget(). */
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
144
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
145 GLADE_HOOKUP_OBJECT_NO_REF(cropper_window, cropper_window, "cropper_window");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
146 GLADE_HOOKUP_OBJECT(cropper_window, dialog_vbox1, "dialog_vbox1");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
147
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
148 GLADE_HOOKUP_OBJECT(cropper_window, label1, "label1");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
149 GLADE_HOOKUP_OBJECT(cropper_window, label2, "label2");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
150 GLADE_HOOKUP_OBJECT(cropper_window, status, "status");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
151 GLADE_HOOKUP_OBJECT(cropper_window, image_area, "image_area");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
152 GLADE_HOOKUP_OBJECT(cropper_window,(GtkWidget*) image_buffer, "image_buffer");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
153
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
154
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
155 return cropper_window;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
156 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
157
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
158
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
159
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
160
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
161
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
162
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
163
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
164
0
ca9155129253 initial commit
meillo@marmaro.de
parents:
diff changeset
165
17
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
166
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
167
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
168
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
169
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
170
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
171
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
172
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
173
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
174
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
175
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
176
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
177
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
178 void
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
179 update_title(char* zoom)
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
180 {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
181 char title[128];
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
182 snprintf(title, 128, "cropper (%s) %dx%d+%d+%d", zoom, w, h, x, y);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
183 gtk_window_set_title(GTK_WINDOW(cropper_window), title);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
184 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
185
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
186
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
187 /* zoom */
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
188 void
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
189 set_zoom()
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
190 {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
191 static GdkPixbuf* pixbuf_new;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
192 g_object_unref(pixbuf_new);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
193
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
194 pixbuf_new = gdk_pixbuf_scale_simple(image_buffer, image_width*zoom, image_height*zoom,
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
195 GDK_INTERP_BILINEAR);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
196 gtk_image_set_from_pixbuf((GtkImage*) lookup_widget(cropper_window, "image_area"), pixbuf_new);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
197 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
198
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
199 void
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
200 on_zoom_in_button_clicked(GtkObject* object, gpointer user_data)
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
201 {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
202 zoom *= 1 + inc;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
203 set_zoom();
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
204 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
205
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
206 void
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
207 on_zoom_out_button_clicked(GtkObject* object, gpointer user_data)
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
208 {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
209 zoom *= 1 - inc;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
210 set_zoom();
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
211 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
212
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
213 void
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
214 on_zoom_100_button_clicked(GtkObject* object, gpointer user_data)
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
215 {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
216 zoom = 1.0;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
217 set_zoom();
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
218 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
219
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
220 void
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
221 on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data)
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
222 {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
223 int w, h;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
224 float zw, zh;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
225 GtkWidget* image_a;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
226
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
227 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
228 gdk_drawable_get_size(image_a->window, &w, &h);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
229
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
230 zw = w*1.0 / image_width;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
231 zh = h*1.0 / image_height;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
232
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
233 zoom = (zw < zh) ? zw : zh;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
234 set_zoom();
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
235 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
236
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
237
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
238
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
239
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
240
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
241
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
242
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
243 void
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
244 crop(void)
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
245 {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
246 char crop_call[256];
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
247
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
248 sprintf(crop_call, "echo \"convert -crop %ix%i+%i+%i %s cropped_%s\"",
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
249 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
250 "crop_width_spinbutton")),
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
251 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
252 "crop_height_spinbutton")),
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
253 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
254 "crop_x_spinbutton")),
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
255 gtk_spin_button_get_value_as_int((GtkSpinButton*) lookup_widget(cropper_window,
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
256 "crop_y_spinbutton")),
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
257 image_filename,
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
258 image_filename
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
259 );
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
260 system(crop_call);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
261 gtk_main_quit();
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
262 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
263
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
264
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
265 void
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
266 on_cropper_window_create(GtkObject* object, gpointer user_data)
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
267 {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
268 image_width = gdk_pixbuf_get_width(image_buffer);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
269 image_height = gdk_pixbuf_get_height(image_buffer);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
270
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
271 /*
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
272 image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
273 image_area = gtk_image_new_from_pixbuf(image_buffer);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
274
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
275 int w, h;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
276 GtkWidget* image_a;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
277
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
278 image_a = (GtkWidget*) lookup_widget(cropper_window, "image_area");
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
279 gdk_drawable_get_size(image_a->window, &w, &h);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
280
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
281 image_width = w - 200;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
282 image_height = h - 150;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
283 set_zoom();
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
284 */
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
285 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
286
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
287 void
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
288 on_cropper_window_destroy(GtkObject* object, gpointer user_data)
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
289 {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
290 gtk_main_quit();
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
291 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
292
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
293
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
294
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
295
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
296 gboolean
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
297 on_key_press(GtkWidget* window, GdkEventKey* pKey, gpointer userdata)
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
298 {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
299 if (pKey->type != GDK_KEY_PRESS) {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
300 return FALSE;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
301 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
302 switch (pKey->keyval) {
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
303 case GDK_q:
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
304 gtk_main_quit();
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
305 break;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
306 case GDK_Return:
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
307 crop();
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
308 break;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
309 case GDK_plus:
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
310 on_zoom_in_button_clicked(NULL, userdata);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
311 break;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
312 case GDK_minus:
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
313 on_zoom_out_button_clicked(NULL, userdata);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
314 break;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
315 case GDK_0:
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
316 on_zoom_100_button_clicked(NULL, userdata);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
317 break;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
318 case GDK_f:
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
319 on_zoom_fit_button_clicked(NULL, userdata);
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
320 break;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
321 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
322 return TRUE;
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
323 }
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
324
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
325
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
326
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
327
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
328
4453456abad1 gathered all code in one file
meillo@marmaro.de
parents: 15
diff changeset
329
0
ca9155129253 initial commit
meillo@marmaro.de
parents:
diff changeset
330
2
e359bea4c8ac added code for ratio swap; new names for ratio operations; added main.h; some more
meillo@marmaro.de
parents: 1
diff changeset
331
11
c18ba4ea1514 just cosmetic changes
meillo@marmaro.de
parents: 10
diff changeset
332 int
c18ba4ea1514 just cosmetic changes
meillo@marmaro.de
parents: 10
diff changeset
333 main(int argc, char* argv[])
c18ba4ea1514 just cosmetic changes
meillo@marmaro.de
parents: 10
diff changeset
334 {
4
2f11ab3e6047 added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents: 2
diff changeset
335 /* commandline option handling */
11
c18ba4ea1514 just cosmetic changes
meillo@marmaro.de
parents: 10
diff changeset
336 if (argc != 2) {
10
5e282003f0c1 minor changes; besser indenting
meillo@marmaro.de
parents: 9
diff changeset
337 g_print("cropper -- a crop frontend to convert\n");
5e282003f0c1 minor changes; besser indenting
meillo@marmaro.de
parents: 9
diff changeset
338 g_print("usage: cropper IMAGE\n");
5e282003f0c1 minor changes; besser indenting
meillo@marmaro.de
parents: 9
diff changeset
339 return 1;
4
2f11ab3e6047 added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents: 2
diff changeset
340 }
2f11ab3e6047 added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents: 2
diff changeset
341
11
c18ba4ea1514 just cosmetic changes
meillo@marmaro.de
parents: 10
diff changeset
342 image_filename = argv[1];
10
5e282003f0c1 minor changes; besser indenting
meillo@marmaro.de
parents: 9
diff changeset
343 gtk_init(&argc, &argv);
4
2f11ab3e6047 added option handling; added output for convert; commented all ratio code cause it is not really important now
meillo@marmaro.de
parents: 2
diff changeset
344
10
5e282003f0c1 minor changes; besser indenting
meillo@marmaro.de
parents: 9
diff changeset
345 cropper_window = create_cropper_window();
5e282003f0c1 minor changes; besser indenting
meillo@marmaro.de
parents: 9
diff changeset
346 gtk_widget_show(cropper_window);
11
c18ba4ea1514 just cosmetic changes
meillo@marmaro.de
parents: 10
diff changeset
347 gtk_main();
0
ca9155129253 initial commit
meillo@marmaro.de
parents:
diff changeset
348
10
5e282003f0c1 minor changes; besser indenting
meillo@marmaro.de
parents: 9
diff changeset
349 return 0;
0
ca9155129253 initial commit
meillo@marmaro.de
parents:
diff changeset
350 }
ca9155129253 initial commit
meillo@marmaro.de
parents:
diff changeset
351