cropper

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 diff
     1.1 --- a/callbacks.c	Fri Dec 07 21:38:25 2007 +0100
     1.2 +++ b/callbacks.c	Wed Mar 19 23:01:43 2008 +0100
     1.3 @@ -1,10 +1,14 @@
     1.4  #include <gtk/gtk.h>
     1.5 +#include <gdk-pixbuf/gdk-pixbuf.h>
     1.6  
     1.7  #include "main.h"
     1.8  #include "callbacks.h"
     1.9  #include "interface.h"
    1.10  #include "support.h"
    1.11  
    1.12 +int image_width;
    1.13 +int image_height;
    1.14 +float inc = 0.1;
    1.15  /*
    1.16  void update_spin_button_ratio(GtkWidget* spinbutton) {
    1.17  	g_print("ratio change: %f\n", ratio);
    1.18 @@ -161,6 +165,45 @@
    1.19  
    1.20  
    1.21  
    1.22 +/* zoom */
    1.23 +void on_zoom_in_button_clicked(GtkObject* object, gpointer user_data) {
    1.24 +	printf("zoom in clicked\n");
    1.25 +	image_width *= 1 + inc;
    1.26 +	image_height *= 1 + inc;
    1.27 +	gtk_image_set_from_pixbuf(lookup_widget(cropper_window, "image_area"),
    1.28 +			gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR));
    1.29 +}
    1.30 +
    1.31 +void on_zoom_out_button_clicked(GtkObject* object, gpointer user_data) {
    1.32 +	printf("zoom out clicked\n");
    1.33 +	image_width *= 1 - inc;
    1.34 +	image_height *= 1 - inc;
    1.35 +	gtk_image_set_from_pixbuf(lookup_widget(cropper_window, "image_area"),
    1.36 +			gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR));
    1.37 +}
    1.38 +
    1.39 +void on_zoom_100_button_clicked(GtkObject* object, gpointer user_data) {
    1.40 +	printf("zoom 100 clicked\n");
    1.41 +	image_width = gdk_pixbuf_get_width(image_buffer);
    1.42 +	image_height = gdk_pixbuf_get_height(image_buffer);
    1.43 +	gtk_image_set_from_pixbuf(lookup_widget(cropper_window, "image_area"),
    1.44 +			gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR));
    1.45 +}
    1.46 +
    1.47 +void on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data) {
    1.48 +	printf("zoom fit clicked\n");
    1.49 +	image_width = gdk_pixbuf_get_width(image_buffer) + 200; /* FIXME */
    1.50 +	image_height = gdk_pixbuf_get_height(image_buffer) + 200; /* FIXME */
    1.51 +	gtk_image_set_from_pixbuf(lookup_widget(cropper_window, "image_area"),
    1.52 +			gdk_pixbuf_scale_simple(image_buffer, image_width, image_height, GDK_INTERP_BILINEAR));
    1.53 +}
    1.54 +
    1.55 +
    1.56 +
    1.57 +
    1.58 +
    1.59 +
    1.60 +
    1.61  void on_crop_clicked(GtkButton* button, gpointer user_data) {
    1.62  	char crop_call[256];
    1.63  
    1.64 @@ -176,6 +219,10 @@
    1.65  	gtk_main_quit();
    1.66  }
    1.67  
    1.68 +void on_cropper_window_create (GtkObject* object, gpointer user_data) {
    1.69 +	image_width = gdk_pixbuf_get_width(image_buffer);
    1.70 +	image_height = gdk_pixbuf_get_height(image_buffer);
    1.71 +}
    1.72  
    1.73  void on_cropper_window_destroy (GtkObject* object, gpointer user_data) {
    1.74  	gtk_main_quit();
     2.1 --- a/callbacks.h	Fri Dec 07 21:38:25 2007 +0100
     2.2 +++ b/callbacks.h	Wed Mar 19 23:01:43 2008 +0100
     2.3 @@ -25,8 +25,13 @@
     2.4  
     2.5  void on_crop_clicked(GtkButton* button, gpointer user_data);
     2.6  
     2.7 +void on_cropper_window_create(GtkObject* object, gpointer user_data);
     2.8  void on_cropper_window_destroy(GtkObject* object, gpointer user_data);
     2.9  /*gboolean on_cropper_window_delete_event(GtkWidget* widget, GdkEvent *event, gpointer user_data);*/
    2.10  
    2.11 +void on_zoom_in_button_clicked(GtkObject* object, gpointer user_data);
    2.12 +void on_zoom_out_button_clicked(GtkObject* object, gpointer user_data);
    2.13 +void on_zoom_100_button_clicked(GtkObject* object, gpointer user_data);
    2.14 +void on_zoom_fit_button_clicked(GtkObject* object, gpointer user_data);
    2.15  
    2.16  #endif
     3.1 --- a/interface.c	Fri Dec 07 21:38:25 2007 +0100
     3.2 +++ b/interface.c	Wed Mar 19 23:01:43 2008 +0100
     3.3 @@ -6,6 +6,7 @@
     3.4  
     3.5  #include <gdk/gdkkeysyms.h>
     3.6  #include <gtk/gtk.h>
     3.7 +#include <gdk-pixbuf/gdk-pixbuf.h>
     3.8  
     3.9  #include "main.h"
    3.10  #include "callbacks.h"
    3.11 @@ -354,10 +355,11 @@
    3.12    gtk_box_pack_start (GTK_BOX (vbox7), nav_container, TRUE, TRUE, 0);
    3.13  
    3.14  /* image_area */
    3.15 -  image_area = gtk_image_new_from_file (image_filename);
    3.16 -  gtk_widget_set_name (image_area, "image_area");
    3.17 -  gtk_widget_show (image_area);
    3.18 -  gtk_box_pack_start (GTK_BOX (nav_container), image_area, TRUE, TRUE, 0);
    3.19 +  image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL);
    3.20 +  image_area = gtk_image_new_from_pixbuf(image_buffer);
    3.21 +  gtk_widget_set_name(image_area, "image_area");
    3.22 +  gtk_widget_show(image_area);
    3.23 +  gtk_box_pack_start(GTK_BOX(nav_container), image_area, TRUE, TRUE, 0);
    3.24  
    3.25    hbox16 = gtk_hbox_new (FALSE, 6);
    3.26    gtk_widget_set_name (hbox16, "hbox16");
    3.27 @@ -422,36 +424,39 @@
    3.28    gtk_box_pack_end (GTK_BOX (hbox16), okay_box, FALSE, TRUE, 0);
    3.29  */
    3.30  
    3.31 -	crop_okbutton = gtk_button_new (); 
    3.32 -	gtk_widget_set_name (crop_okbutton, "crop_okbutton"); 
    3.33 -	gtk_widget_show (crop_okbutton); 
    3.34 -	gtk_box_pack_end (GTK_BOX (dialog_vbox1), crop_okbutton, FALSE, FALSE, 0); 
    3.35 -	GTK_WIDGET_SET_FLAGS (crop_okbutton, GTK_CAN_DEFAULT); 
    3.36 +	crop_okbutton = gtk_button_new ();
    3.37 +	gtk_widget_set_name (crop_okbutton, "crop_okbutton");
    3.38 +	gtk_widget_show (crop_okbutton);
    3.39 +	gtk_box_pack_end (GTK_BOX (dialog_vbox1), crop_okbutton, FALSE, FALSE, 0);
    3.40 +	GTK_WIDGET_SET_FLAGS (crop_okbutton, GTK_CAN_DEFAULT);
    3.41  
    3.42 -	alignment1 = gtk_alignment_new (0.5, 0.5, 0, 0); 
    3.43 -	gtk_widget_set_name (alignment1, "alignment1"); 
    3.44 -	gtk_widget_show (alignment1); 
    3.45 -	gtk_container_add (GTK_CONTAINER (crop_okbutton), alignment1); 
    3.46 +	alignment1 = gtk_alignment_new (0.5, 0.5, 0, 0);
    3.47 +	gtk_widget_set_name (alignment1, "alignment1");
    3.48 +	gtk_widget_show (alignment1);
    3.49 +	gtk_container_add (GTK_CONTAINER (crop_okbutton), alignment1);
    3.50  
    3.51 -	hbox11 = gtk_hbox_new (FALSE, 2); 
    3.52 -	gtk_widget_set_name (hbox11, "hbox11"); 
    3.53 -	gtk_widget_show (hbox11); 
    3.54 -	gtk_container_add (GTK_CONTAINER (alignment1), hbox11); 
    3.55 +	hbox11 = gtk_hbox_new (FALSE, 2);
    3.56 +	gtk_widget_set_name (hbox11, "hbox11");
    3.57 +	gtk_widget_show (hbox11);
    3.58 +	gtk_container_add (GTK_CONTAINER (alignment1), hbox11);
    3.59  
    3.60 -	crop_image = gtk_image_new_from_stock ("gtk-ok", GTK_ICON_SIZE_BUTTON); 
    3.61 -	gtk_widget_set_name (crop_image, "crop_image"); 
    3.62 -	gtk_widget_show (crop_image); 
    3.63 -	gtk_box_pack_start (GTK_BOX (hbox11), crop_image, FALSE, FALSE, 0); 
    3.64 +	crop_image = gtk_image_new_from_stock ("gtk-ok", GTK_ICON_SIZE_BUTTON);
    3.65 +	gtk_widget_set_name (crop_image, "crop_image");
    3.66 +	gtk_widget_show (crop_image);
    3.67 +	gtk_box_pack_start (GTK_BOX (hbox11), crop_image, FALSE, FALSE, 0);
    3.68  
    3.69 -	label12 = gtk_label_new_with_mnemonic ("_Crop"); 
    3.70 -	gtk_widget_set_name (label12, "label12"); 
    3.71 -	gtk_widget_show (label12); 
    3.72 -	gtk_box_pack_start (GTK_BOX (hbox11), label12, FALSE, FALSE, 0); 
    3.73 +	label12 = gtk_label_new_with_mnemonic ("_Crop");
    3.74 +	gtk_widget_set_name (label12, "label12");
    3.75 +	gtk_widget_show (label12);
    3.76 +	gtk_box_pack_start (GTK_BOX (hbox11), label12, FALSE, FALSE, 0);
    3.77  
    3.78  
    3.79  
    3.80  
    3.81  
    3.82 +  g_signal_connect (G_OBJECT (cropper_window), "show",
    3.83 +                    G_CALLBACK (on_cropper_window_create),
    3.84 +                    NULL);
    3.85  /* destroy */
    3.86    g_signal_connect (G_OBJECT (cropper_window), "destroy",
    3.87                      G_CALLBACK (on_cropper_window_destroy),
    3.88 @@ -464,6 +469,20 @@
    3.89                      NULL);
    3.90  
    3.91  
    3.92 +/* zoom */
    3.93 +	g_signal_connect (G_OBJECT (crop_zoom_in_button), "clicked",
    3.94 +										G_CALLBACK (on_zoom_in_button_clicked),
    3.95 +										NULL);
    3.96 +	g_signal_connect (G_OBJECT (crop_zoom_out_button), "clicked",
    3.97 +										G_CALLBACK (on_zoom_out_button_clicked),
    3.98 +										NULL);
    3.99 +	g_signal_connect (G_OBJECT (crop_zoom_100_button), "clicked",
   3.100 +										G_CALLBACK (on_zoom_100_button_clicked),
   3.101 +										NULL);
   3.102 +	g_signal_connect (G_OBJECT (crop_zoom_fit_button), "clicked",
   3.103 +										G_CALLBACK (on_zoom_fit_button_clicked),
   3.104 +										NULL);
   3.105 +
   3.106  
   3.107  /* aspect ratio */
   3.108  /*
   3.109 @@ -528,22 +547,6 @@
   3.110  */
   3.111  
   3.112  
   3.113 -/* zoom */
   3.114 -/*
   3.115 -g_signal_connect (G_OBJECT (zoom_in_button), "clicked",
   3.116 -	G_CALLBACK (zoom_in_button_clicked_cb),
   3.117 -	data);
   3.118 -g_signal_connect (G_OBJECT (zoom_out_button), "clicked",
   3.119 -	G_CALLBACK (zoom_out_button_clicked_cb),
   3.120 -	data);
   3.121 -g_signal_connect (G_OBJECT (zoom_100_button), "clicked",
   3.122 -	G_CALLBACK (zoom_100_button_clicked_cb),
   3.123 -	data);
   3.124 -g_signal_connect (G_OBJECT (zoom_fit_button), "clicked",
   3.125 -	G_CALLBACK (zoom_fit_button_clicked_cb),
   3.126 -	data);
   3.127 -*/
   3.128 -
   3.129  
   3.130  
   3.131  
   3.132 @@ -604,6 +607,7 @@
   3.133    GLADE_HOOKUP_OBJECT (cropper_window, vbox7, "vbox7");
   3.134    GLADE_HOOKUP_OBJECT (cropper_window, nav_container, "nav_container");
   3.135    GLADE_HOOKUP_OBJECT (cropper_window, image_area, "image_area");
   3.136 +  GLADE_HOOKUP_OBJECT (cropper_window, image_buffer, "image_buffer");
   3.137    GLADE_HOOKUP_OBJECT (cropper_window, hbox16, "hbox16");
   3.138    GLADE_HOOKUP_OBJECT (cropper_window, hbox17, "hbox17");
   3.139    GLADE_HOOKUP_OBJECT (cropper_window, crop_zoom_in_button, "crop_zoom_in_button");
   3.140 @@ -615,7 +619,7 @@
   3.141    GLADE_HOOKUP_OBJECT (cropper_window, crop_zoom_fit_button, "crop_zoom_fit_button");
   3.142    GLADE_HOOKUP_OBJECT (cropper_window, image1, "image1");
   3.143  	/*GLADE_HOOKUP_OBJECT_NO_REF (cropper_window, dialog_action_area1, "dialog_action_area1"); */
   3.144 -	GLADE_HOOKUP_OBJECT (cropper_window, crop_okbutton, "crop_okbutton"); 
   3.145 +	GLADE_HOOKUP_OBJECT (cropper_window, crop_okbutton, "crop_okbutton");
   3.146  	GLADE_HOOKUP_OBJECT (cropper_window, alignment1, "alignment1");
   3.147  	GLADE_HOOKUP_OBJECT (cropper_window, hbox11, "hbox11");
   3.148  	GLADE_HOOKUP_OBJECT (cropper_window, crop_image, "crop_image");
     4.1 --- a/interface.h	Fri Dec 07 21:38:25 2007 +0100
     4.2 +++ b/interface.h	Wed Mar 19 23:01:43 2008 +0100
     4.3 @@ -1,3 +1,6 @@
     4.4  #include<gtk/gtk.h>
     4.5  
     4.6  GtkWidget* create_cropper_window(void);
     4.7 +
     4.8 +
     4.9 +GdkPixbuf *image_buffer;