changeset 7:ec2d11d96fb0

image is now gdk-pixbuff; zoom implemented in a basic way
author meillo@marmaro.de
date Wed, 19 Mar 2008 23:01:43 +0100
parents f53ce3b28bb4
children b0824876d379
files callbacks.c callbacks.h interface.c interface.h
diffstat 4 files changed, 101 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/callbacks.c	Fri Dec 07 21:38:25 2007 +0100
+++ b/callbacks.c	Wed Mar 19 23:01:43 2008 +0100
@@ -1,10 +1,14 @@
 #include <gtk/gtk.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
 
 #include "main.h"
 #include "callbacks.h"
 #include "interface.h"
 #include "support.h"
 
+int image_width;
+int image_height;
+float inc = 0.1;
 /*
 void update_spin_button_ratio(GtkWidget* spinbutton) {
 	g_print("ratio change: %f\n", ratio);
@@ -161,6 +165,45 @@
 
 
 
+/* zoom */
+void on_zoom_in_button_clicked(GtkObject* object, gpointer user_data) {
+	printf("zoom in clicked\n");
+	image_width *= 1 + inc;
+	image_height *= 1 + inc;
+	gtk_image_set_from_pixbuf(lookup_widget(cropper_window, "image_area"),
+			gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR));
+}
+
+void on_zoom_out_button_clicked(GtkObject* object, gpointer user_data) {
+	printf("zoom out clicked\n");
+	image_width *= 1 - inc;
+	image_height *= 1 - inc;
+	gtk_image_set_from_pixbuf(lookup_widget(cropper_window, "image_area"),
+			gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR));
+}
+
+void on_zoom_100_button_clicked(GtkObject* object, gpointer user_data) {
+	printf("zoom 100 clicked\n");
+	image_width = gdk_pixbuf_get_width(image_buffer);
+	image_height = gdk_pixbuf_get_height(image_buffer);
+	gtk_image_set_from_pixbuf(lookup_widget(cropper_window, "image_area"),
+			gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR));
+}
+
+void on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data) {
+	printf("zoom fit clicked\n");
+	image_width = gdk_pixbuf_get_width(image_buffer) + 200; /* FIXME */
+	image_height = gdk_pixbuf_get_height(image_buffer) + 200; /* FIXME */
+	gtk_image_set_from_pixbuf(lookup_widget(cropper_window, "image_area"),
+			gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR));
+}
+
+
+
+
+
+
+
 void on_crop_clicked(GtkButton* button, gpointer user_data) {
 	char crop_call[256];
 
@@ -176,6 +219,10 @@
 	gtk_main_quit();
 }
 
+void on_cropper_window_create (GtkObject* object, gpointer user_data) {
+	image_width = gdk_pixbuf_get_width(image_buffer);
+	image_height = gdk_pixbuf_get_height(image_buffer);
+}
 
 void on_cropper_window_destroy (GtkObject* object, gpointer user_data) {
 	gtk_main_quit();
--- a/callbacks.h	Fri Dec 07 21:38:25 2007 +0100
+++ b/callbacks.h	Wed Mar 19 23:01:43 2008 +0100
@@ -25,8 +25,13 @@
 
 void on_crop_clicked(GtkButton* button, gpointer user_data);
 
+void on_cropper_window_create(GtkObject* object, gpointer user_data);
 void on_cropper_window_destroy(GtkObject* object, gpointer user_data);
 /*gboolean on_cropper_window_delete_event(GtkWidget* widget, GdkEvent *event, gpointer user_data);*/
 
+void on_zoom_in_button_clicked(GtkObject* object, gpointer user_data);
+void on_zoom_out_button_clicked(GtkObject* object, gpointer user_data);
+void on_zoom_100_button_clicked(GtkObject* object, gpointer user_data);
+void on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data);
 
 #endif
--- a/interface.c	Fri Dec 07 21:38:25 2007 +0100
+++ b/interface.c	Wed Mar 19 23:01:43 2008 +0100
@@ -6,6 +6,7 @@
 
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
 
 #include "main.h"
 #include "callbacks.h"
@@ -354,10 +355,11 @@
   gtk_box_pack_start (GTK_BOX (vbox7), nav_container, TRUE, TRUE, 0);
 
 /* image_area */
-  image_area = gtk_image_new_from_file (image_filename);
-  gtk_widget_set_name (image_area, "image_area");
-  gtk_widget_show (image_area);
-  gtk_box_pack_start (GTK_BOX (nav_container), image_area, TRUE, TRUE, 0);
+  image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL);
+  image_area = gtk_image_new_from_pixbuf(image_buffer);
+  gtk_widget_set_name(image_area, "image_area");
+  gtk_widget_show(image_area);
+  gtk_box_pack_start(GTK_BOX(nav_container), image_area, TRUE, TRUE, 0);
 
   hbox16 = gtk_hbox_new (FALSE, 6);
   gtk_widget_set_name (hbox16, "hbox16");
@@ -422,36 +424,39 @@
   gtk_box_pack_end (GTK_BOX (hbox16), okay_box, FALSE, TRUE, 0);
 */
 
-	crop_okbutton = gtk_button_new (); 
-	gtk_widget_set_name (crop_okbutton, "crop_okbutton"); 
-	gtk_widget_show (crop_okbutton); 
-	gtk_box_pack_end (GTK_BOX (dialog_vbox1), crop_okbutton, FALSE, FALSE, 0); 
-	GTK_WIDGET_SET_FLAGS (crop_okbutton, GTK_CAN_DEFAULT); 
+	crop_okbutton = gtk_button_new ();
+	gtk_widget_set_name (crop_okbutton, "crop_okbutton");
+	gtk_widget_show (crop_okbutton);
+	gtk_box_pack_end (GTK_BOX (dialog_vbox1), crop_okbutton, FALSE, FALSE, 0);
+	GTK_WIDGET_SET_FLAGS (crop_okbutton, GTK_CAN_DEFAULT);
 
-	alignment1 = gtk_alignment_new (0.5, 0.5, 0, 0); 
-	gtk_widget_set_name (alignment1, "alignment1"); 
-	gtk_widget_show (alignment1); 
-	gtk_container_add (GTK_CONTAINER (crop_okbutton), alignment1); 
+	alignment1 = gtk_alignment_new (0.5, 0.5, 0, 0);
+	gtk_widget_set_name (alignment1, "alignment1");
+	gtk_widget_show (alignment1);
+	gtk_container_add (GTK_CONTAINER (crop_okbutton), alignment1);
 
-	hbox11 = gtk_hbox_new (FALSE, 2); 
-	gtk_widget_set_name (hbox11, "hbox11"); 
-	gtk_widget_show (hbox11); 
-	gtk_container_add (GTK_CONTAINER (alignment1), hbox11); 
+	hbox11 = gtk_hbox_new (FALSE, 2);
+	gtk_widget_set_name (hbox11, "hbox11");
+	gtk_widget_show (hbox11);
+	gtk_container_add (GTK_CONTAINER (alignment1), hbox11);
 
-	crop_image = gtk_image_new_from_stock ("gtk-ok", GTK_ICON_SIZE_BUTTON); 
-	gtk_widget_set_name (crop_image, "crop_image"); 
-	gtk_widget_show (crop_image); 
-	gtk_box_pack_start (GTK_BOX (hbox11), crop_image, FALSE, FALSE, 0); 
+	crop_image = gtk_image_new_from_stock ("gtk-ok", GTK_ICON_SIZE_BUTTON);
+	gtk_widget_set_name (crop_image, "crop_image");
+	gtk_widget_show (crop_image);
+	gtk_box_pack_start (GTK_BOX (hbox11), crop_image, FALSE, FALSE, 0);
 
-	label12 = gtk_label_new_with_mnemonic ("_Crop"); 
-	gtk_widget_set_name (label12, "label12"); 
-	gtk_widget_show (label12); 
-	gtk_box_pack_start (GTK_BOX (hbox11), label12, FALSE, FALSE, 0); 
+	label12 = gtk_label_new_with_mnemonic ("_Crop");
+	gtk_widget_set_name (label12, "label12");
+	gtk_widget_show (label12);
+	gtk_box_pack_start (GTK_BOX (hbox11), label12, FALSE, FALSE, 0);
 
 
 
 
 
+  g_signal_connect (G_OBJECT (cropper_window), "show",
+                    G_CALLBACK (on_cropper_window_create),
+                    NULL);
 /* destroy */
   g_signal_connect (G_OBJECT (cropper_window), "destroy",
                     G_CALLBACK (on_cropper_window_destroy),
@@ -464,6 +469,20 @@
                     NULL);
 
 
+/* zoom */
+	g_signal_connect (G_OBJECT (crop_zoom_in_button), "clicked",
+										G_CALLBACK (on_zoom_in_button_clicked),
+										NULL);
+	g_signal_connect (G_OBJECT (crop_zoom_out_button), "clicked",
+										G_CALLBACK (on_zoom_out_button_clicked),
+										NULL);
+	g_signal_connect (G_OBJECT (crop_zoom_100_button), "clicked",
+										G_CALLBACK (on_zoom_100_button_clicked),
+										NULL);
+	g_signal_connect (G_OBJECT (crop_zoom_fit_button), "clicked",
+										G_CALLBACK (on_zoom_fit_button_clicked),
+										NULL);
+
 
 /* aspect ratio */
 /*
@@ -528,22 +547,6 @@
 */
 
 
-/* zoom */
-/*
-g_signal_connect (G_OBJECT (zoom_in_button), "clicked",
-	G_CALLBACK (zoom_in_button_clicked_cb),
-	data);
-g_signal_connect (G_OBJECT (zoom_out_button), "clicked",
-	G_CALLBACK (zoom_out_button_clicked_cb),
-	data);
-g_signal_connect (G_OBJECT (zoom_100_button), "clicked",
-	G_CALLBACK (zoom_100_button_clicked_cb),
-	data);
-g_signal_connect (G_OBJECT (zoom_fit_button), "clicked",
-	G_CALLBACK (zoom_fit_button_clicked_cb),
-	data);
-*/
-
 
 
 
@@ -604,6 +607,7 @@
   GLADE_HOOKUP_OBJECT (cropper_window, vbox7, "vbox7");
   GLADE_HOOKUP_OBJECT (cropper_window, nav_container, "nav_container");
   GLADE_HOOKUP_OBJECT (cropper_window, image_area, "image_area");
+  GLADE_HOOKUP_OBJECT (cropper_window, image_buffer, "image_buffer");
   GLADE_HOOKUP_OBJECT (cropper_window, hbox16, "hbox16");
   GLADE_HOOKUP_OBJECT (cropper_window, hbox17, "hbox17");
   GLADE_HOOKUP_OBJECT (cropper_window, crop_zoom_in_button, "crop_zoom_in_button");
@@ -615,7 +619,7 @@
   GLADE_HOOKUP_OBJECT (cropper_window, crop_zoom_fit_button, "crop_zoom_fit_button");
   GLADE_HOOKUP_OBJECT (cropper_window, image1, "image1");
 	/*GLADE_HOOKUP_OBJECT_NO_REF (cropper_window, dialog_action_area1, "dialog_action_area1"); */
-	GLADE_HOOKUP_OBJECT (cropper_window, crop_okbutton, "crop_okbutton"); 
+	GLADE_HOOKUP_OBJECT (cropper_window, crop_okbutton, "crop_okbutton");
 	GLADE_HOOKUP_OBJECT (cropper_window, alignment1, "alignment1");
 	GLADE_HOOKUP_OBJECT (cropper_window, hbox11, "hbox11");
 	GLADE_HOOKUP_OBJECT (cropper_window, crop_image, "crop_image");
--- a/interface.h	Fri Dec 07 21:38:25 2007 +0100
+++ b/interface.h	Wed Mar 19 23:01:43 2008 +0100
@@ -1,3 +1,6 @@
 #include<gtk/gtk.h>
 
 GtkWidget* create_cropper_window(void);
+
+
+GdkPixbuf *image_buffer;