Patch for Electric Eyes




I was using electric eyes the other day, and though that the following
feature might be useful:

When an image is too large to display display it at half size by
default.  If the user wishes to override this behavior provid a menu
item so they can do so.

So I added a patch to do this(I have attached the patch to the end of
this mail message).  I was wondering how one goes about gettng these
sort of things added to the devel tree, or does the anon cvs allow
commits:).  The patch works, but I would like to add a preferences
feature so the user can enable or disable this behavior.  I'll do this
once I figure out the GNOME way to store user settings.

Also, I was wondering if anyone was going to do a code cleanup of
Electric Eyes, if not I will do so when I get a chance, if it is ok
with everyone else.

-- 
Manish Vachharajani 		            <mvachhar@noc.rutgers.edu>
Rutgers University 		      http://www.rutgers.net/~mvachhar	
Telecommunications Division   
Systems Programmer

******Patch starts here

Index: ee.h
===================================================================
RCS file: /debian/home/gnomecvs/gnome-graphics/ee/ee.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 ee.h
--- ee.h	1998/02/02 19:57:25	1.1.1.1
+++ ee.h	1998/04/03 16:29:49
@@ -68,12 +68,15 @@
    char          *file;
 };
 
+extern gint          display_mode;
 extern gint          mini_w,mini_h;
 extern gint          autoapply;
 extern gint          keep_aspect;
 extern gint          new_image;
 extern gint          new_draw;
 
+GtkWidget     *mode_menu;
+
 void make_logo();
 void make_icons();
 GtkWidget *make_mods(gchar *name, gint width,
@@ -188,6 +191,11 @@
 void create_progress();
 
 
+#define EE_DM_AUTO 1
+#define EE_DM_NORMAL 2
+#define EE_DM_DOUBLE 3
+#define EE_DM_HALF 4
+#define EE_DM_FOURTH 5
 
 
 
Index: globals.c
===================================================================
RCS file: /debian/home/gnomecvs/gnome-graphics/ee/globals.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 globals.c
--- globals.c	1998/02/02 19:57:25	1.1.1.1
+++ globals.c	1998/04/03 16:29:49
@@ -10,6 +10,7 @@
 #include <gtk/gtk.h>
 #include "ee.h"
 
+gint          display_mode;
 gint          didsize;
 gint          thumbsup;
 gint          dosave;
@@ -20,6 +21,7 @@
 gint          max_thumb_h;
 gint          current_sel;
 GtkWidget     *thumb_scroll_window;
+GtkWidget     *mode_menu;
 GtkWidget     *image_window;
 GtkWidget     *control_window;
 GtkWidget     *list_window;
Index: main.c
===================================================================
RCS file: /debian/home/gnomecvs/gnome-graphics/ee/main.c,v
retrieving revision 1.9
diff -u -r1.9 main.c
--- main.c	1998/03/10 20:13:34	1.9
+++ main.c	1998/04/03 16:29:49
@@ -12,6 +12,9 @@
 #include <gtk/gtk.h>
 #include "ee.h"
 
+static GtkWidget *mode_menu_item[5];
+static void mode_menu_popup(GtkWidget *,gpointer *);
+
 static error_t parse_an_arg (int key, char *arg, struct argp_state *state);
 
 /* This describes how to parse our command-line arguments.  We don't
@@ -1085,6 +1088,11 @@
    gtk_box_pack_start (GTK_BOX(box2),button,TRUE,TRUE,0);
    gtk_widget_show(button);
    gtk_signal_connect(GTK_OBJECT(button),"clicked",GTK_SIGNAL_FUNC(show_widget),&thumb_window);
+
+   button=gtk_button_new_with_label(_("Display Mode"));
+   gtk_box_pack_start (GTK_BOX(box2),button,TRUE,TRUE,0);
+   gtk_widget_show(button);
+   gtk_signal_connect(GTK_OBJECT(button),"clicked",GTK_SIGNAL_FUNC(mode_menu_popup),(gpointer) &mode_menu);
    
    button=gtk_button_new_with_label(_("Edit"));
    gtk_box_pack_start (GTK_BOX(box2),button,TRUE,TRUE,0);
@@ -1147,6 +1155,55 @@
 }
 
 
+void set_new_image_size(GtkWidget *id,gint w,gint h)
+{
+  char size[64];
+  char *title;
+  /* FIX ME - I should decide to scale the image when it doesn't fit on the
+     screen, for now I do this kludge */
+  
+  size[0]='\0';
+
+  switch(display_mode) {
+  case EE_DM_AUTO:
+    if((w > 1280) || (h > 1024)) { 
+      snprintf(size,64," (displaying at half size)");
+      h/=2; w/=2;
+    } else {
+      strcpy(size,"");
+    }
+    break;
+  case EE_DM_NORMAL:
+    snprintf(size,64," (Normal size)");
+    break;
+  case EE_DM_HALF:
+    snprintf(size,64," (Half size)");
+    h /= 2; w /= 2;
+    break;
+  case EE_DM_FOURTH:
+    snprintf(size,64," (quarter size)");
+    h /= 4; w /= 4;
+    break;
+  case EE_DM_DOUBLE:
+    snprintf(size,64," (double size)");
+    h *= 2; w *= 2;
+    break;
+  }
+
+  gtk_drawing_area_size(GTK_DRAWING_AREA(image_drawing),w,h);
+  gtk_widget_queue_resize(id);
+
+  title=(char *)g_malloc(strlen(size) + strlen(image->filename) + 1);
+  if(!title) {
+    title=image->filename;
+  } else {
+    strcpy(title,image->filename);
+    strcat(title,size);
+  }
+  gtk_window_set_title(GTK_WINDOW(image_window),title);
+  free(title);
+}
+
 void create_drawing()
 {
    GdkVisual *gdk_visual;
@@ -1159,7 +1216,8 @@
    image_drawing=gtk_drawing_area_new();
    gtk_signal_connect(GTK_OBJECT(image_drawing),"configure_event",GTK_SIGNAL_FUNC(draw_img),NULL);
    gtk_signal_connect(GTK_OBJECT(image_drawing),"button_press_event",GTK_SIGNAL_FUNC(button_win),NULL);
-   gtk_drawing_area_size(GTK_DRAWING_AREA(image_drawing),image->rgb_width,image->rgb_height);
+   set_new_image_size(image_drawing,image->rgb_width,image->rgb_height);
+   //   gtk_drawing_area_size(GTK_DRAWING_AREA(image_drawing),image->rgb_width,image->rgb_height);
    gtk_widget_set_events(image_drawing,GDK_BUTTON_PRESS_MASK);
    gtk_container_add(GTK_CONTAINER(image_window),image_drawing);
    gtk_widget_show(image_drawing);
@@ -1696,8 +1754,9 @@
    image=im;
    gtk_window_set_title(GTK_WINDOW(image_window),image->filename);
    a=image->rgb_width;b=image->rgb_height;
-   gtk_drawing_area_size(GTK_DRAWING_AREA(image_drawing),a,b);
-   gtk_widget_queue_resize(image_drawing);
+   set_new_image_size(image_drawing,a,b);
+   //   gtk_drawing_area_size(GTK_DRAWING_AREA(image_drawing),a,b);
+   //   gtk_widget_queue_resize(image_drawing);
    calc_mini();
    if (edwin.window) reset_all(NULL,NULL);
    return 1;
@@ -1721,8 +1780,9 @@
 	image=im;
 	gtk_window_set_title(GTK_WINDOW(image_window),image->filename);
 	a=image->rgb_width;b=image->rgb_height;
-	gtk_drawing_area_size(GTK_DRAWING_AREA(image_drawing),a,b);
-	gtk_widget_queue_resize(image_drawing);
+	set_new_image_size(image_drawing,a,b);
+	//	gtk_drawing_area_size(GTK_DRAWING_AREA(image_drawing),a,b);
+	//	gtk_widget_queue_resize(image_drawing);
 	calc_mini();
 	if (edwin.window) reset_all(NULL,NULL);
 	add_new_file_to_list(file);
@@ -1864,9 +1924,9 @@
 
 void button_win(GtkWidget *widget, GdkEventButton *event) 
 {
-   if (event->button==3) show_widget(NULL,(gpointer *)&control_window);
-   else if (event->button==2) prev_img(NULL,NULL);
-   else if (event->button==1) next_img(NULL,NULL);
+  if (event->button==3) show_widget(NULL,(gpointer *)&control_window);
+  else if (event->button==2) prev_img(NULL,NULL);
+  else if (event->button==1) next_img(NULL,NULL);
 }
 
 void quit_app(GtkWidget *widget, gpointer *data)
@@ -1907,6 +1967,88 @@
    return 0;
 }
 
+static void mode_menu_popup(GtkWidget *button,gpointer *w)
+{
+  gtk_menu_popup (GTK_MENU(mode_menu), 
+		  NULL, NULL, NULL, NULL,             
+		  0, 0);
+  gtk_widget_show(GTK_WIDGET(mode_menu));
+}
+
+static void mode_menu_do (gchar *string)
+{
+  int i;
+  for(i=0;i<5;i++) {
+    gtk_menu_item_configure(GTK_MENU_ITEM(mode_menu_item[i]),0,0);
+  }
+
+  if(!strcmp(string,"fourth")) {
+    display_mode=EE_DM_FOURTH;
+    gtk_menu_item_configure(GTK_MENU_ITEM(mode_menu_item[0]),1,0);
+  } else if(!strcmp(string,"half")) {
+    display_mode=EE_DM_HALF;
+    gtk_menu_item_configure(GTK_MENU_ITEM(mode_menu_item[1]),1,0);
+  } else if(!strcmp(string,"auto")) {
+    display_mode=EE_DM_AUTO;
+    gtk_menu_item_configure(GTK_MENU_ITEM(mode_menu_item[2]),1,0);
+  } else if(!strcmp(string,"normal")) {
+    display_mode=EE_DM_NORMAL;
+    gtk_menu_item_configure(GTK_MENU_ITEM(mode_menu_item[3]),1,0);
+  } else if(!strcmp(string,"double")) {
+    display_mode=EE_DM_DOUBLE;
+    gtk_menu_item_configure(GTK_MENU_ITEM(mode_menu_item[4]),1,0);
+  }
+  set_new_image_size(image_drawing,image->rgb_width,image->rgb_height);
+
+}
+
+void create_mode_menu()
+{
+  GtkWidget *item;
+  mode_menu = gtk_menu_new();
+
+
+  item = gtk_menu_item_new_with_label("1/4 size");
+  mode_menu_item[0]=item;
+  gtk_menu_append(GTK_MENU(mode_menu), item);
+  gtk_signal_connect_object(GTK_OBJECT(item), "activate",
+			    GTK_SIGNAL_FUNC(mode_menu_do), 
+			    (gpointer) "fourth"); 
+  gtk_widget_show(item);
+
+  item = gtk_menu_item_new_with_label("1/2 size");
+  mode_menu_item[1]=item;
+  gtk_menu_append(GTK_MENU(mode_menu), item);
+  gtk_signal_connect_object(GTK_OBJECT(item), "activate",
+			    GTK_SIGNAL_FUNC(mode_menu_do), 
+			    (gpointer) "half"); 
+  gtk_widget_show(item);
+
+  item = gtk_menu_item_new_with_label("Normal size");
+  mode_menu_item[2]=item;
+  gtk_menu_append(GTK_MENU(mode_menu), item);
+  gtk_signal_connect_object(GTK_OBJECT(item), "activate",
+			    GTK_SIGNAL_FUNC(mode_menu_do), 
+			    (gpointer) "normal"); 
+  gtk_widget_show(item);
+
+  item = gtk_menu_item_new_with_label("Auto size");
+  mode_menu_item[3]=item;
+  gtk_menu_append(GTK_MENU(mode_menu), item);
+  gtk_signal_connect_object(GTK_OBJECT(item), "activate",
+			    GTK_SIGNAL_FUNC(mode_menu_do), 
+			    (gpointer) "auto"); 
+  gtk_widget_show(item);
+
+  item = gtk_menu_item_new_with_label("Double size");
+  mode_menu_item[4]=item;
+  gtk_menu_append(GTK_MENU(mode_menu), item);
+  gtk_signal_connect_object(GTK_OBJECT(item), "activate",
+			    GTK_SIGNAL_FUNC(mode_menu_do), 
+			    (gpointer) "double"); 
+  gtk_widget_show(item);
+}
+
 int main(int argc, char **argv)
 {
    bindtextdomain (PACKAGE, GNOMELOCALEDIR);
@@ -1951,6 +2093,7 @@
 		fprintf (stderr, _("No file was specified on the command line"));
 		exit(0);
 	}
+	display_mode = EE_DM_AUTO;
 	image=gdk_imlib_load_image(gl->data);
      }
    if (!image) gtk_main_quit();
@@ -1962,6 +2105,7 @@
    create_list();
    create_thumbnails();
    create_edit();
+   create_mode_menu();
    configure_drop_regular_widget (image_drawing);
      {
         GList *gl;






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]