On Mon, 02 Mar 2009 11:32:08 +0100
Ruben Stein <m...@grumb.net> wrote:

> Zitat von Laurent Monin <z...@norz.org>:
> 
> > Please can you just modify it putting all variables declarations at the
> > top of functions (as indicated in CODING document) ?
> 
> I think this should do the trick now. One comment: In the CODING  
> document it is written to put declarations to the block begin. If you  
> really want to put them to the function begin in any case, this should  
> be noted there.

Sorry, I made a mistake in my previous email, s/function/block/.

Your new patch is nicer, i tried to improve it a bit, try this one.
I modified the info provided to get rid of the need of i18n, but i'm still 
unsure about that.

It still has an issue since layout_status_update_pixel_cb() is always called 
even when pixel info is hidden.

-- 
Laurent MONIN aka Zas
Index: layout.c
===================================================================
--- layout.c	(révision 1465)
+++ layout.c	(copie de travail)
@@ -51,6 +51,7 @@
 #define TOOLWINDOW_DEF_HEIGHT 450
 
 #define PROGRESS_WIDTH 150
+#define PIXEL_LABEL_WIDTH 130
 #define ZOOM_LABEL_WIDTH 64
 
 #define PANE_DIVIDER_SIZE 10
@@ -669,6 +670,40 @@
 	g_free(buf);
 }
 
+void layout_status_update_pixel_cb(GtkWidget *widget, gpointer data)
+{
+	LayoutWindow *lw = data;
+	gint x_pixel, y_pixel;
+
+	if (!data || !layout_valid(&lw) || !lw->image || lw->image->unknown || lw->options.info_pixel_hidden) return;
+
+	pixbuf_renderer_get_mouse_position(PIXBUF_RENDERER(lw->image->pr), &x_pixel, &y_pixel);
+	
+	if(x_pixel > 0 && y_pixel > 0)
+		{
+		gint r_mouse, g_mouse, b_mouse;
+		gint width, height, slen_width, slen_height;
+		gchar str_temp[10];
+		gchar *text;
+
+		pixbuf_renderer_get_pixel_colors(PIXBUF_RENDERER(lw->image->pr), x_pixel, y_pixel,
+						 &r_mouse, &g_mouse, &b_mouse);			
+		pixbuf_renderer_get_image_size(PIXBUF_RENDERER(lw->image->pr), &width, &height);
+		slen_width = sprintf(str_temp, "%d", width - 1);
+		slen_height = sprintf(str_temp, "%d", height - 1);
+		
+		text = g_strdup_printf("<span size=\"smaller\"><tt>(%*d,%*d) <span background=\"#ff9999\">%3d</span>,<span background=\"#99ff99\">%3d</span>,<span background=\"#9999ff\">%3d</span>)</tt></span>", 
+					 slen_width, x_pixel, slen_height, y_pixel,
+					 r_mouse, g_mouse, b_mouse);
+		gtk_label_set_markup(GTK_LABEL(lw->info_pixel), text);
+		g_free(text);
+		}
+	else
+		{
+		gtk_label_set_markup(GTK_LABEL(lw->info_pixel), "");
+		}
+}
+
 void layout_status_update_image(LayoutWindow *lw)
 {
 	guint64 n;
@@ -711,6 +746,11 @@
 			image_get_image_size(lw->image, &width, &height);
 			text = g_strdup_printf(_("( %d x %d ) %s bytes"),
 					       width, height, b);
+
+			if (!lw->options.info_pixel_hidden)
+				{
+				g_signal_emit_by_name(lw->image->pr, "update-pixel");
+				}
 			}
 
 		g_free(b);
@@ -813,7 +853,12 @@
 	lw->info_details = layout_status_label(NULL, hbox, TRUE, 0, TRUE);
 	if (!small_format) gtk_box_pack_start(GTK_BOX(hbox), lw->info_color, FALSE, FALSE, 0);
 	if (!small_format) gtk_box_pack_start(GTK_BOX(hbox), lw->info_write, FALSE, FALSE, 0);
+	lw->info_pixel = layout_status_label(NULL, hbox, FALSE, PIXEL_LABEL_WIDTH, TRUE);
+	if (lw->options.info_pixel_hidden) gtk_widget_hide(gtk_widget_get_parent(lw->info_pixel));
 	lw->info_zoom = layout_status_label(NULL, hbox, FALSE, ZOOM_LABEL_WIDTH, FALSE);
+	
+	g_signal_connect(G_OBJECT(lw->image->pr), "update-pixel",
+	                 G_CALLBACK(layout_status_update_pixel_cb), lw);
 }
 
 /*
@@ -1747,6 +1792,7 @@
 	lw->info_color = NULL;
 	lw->info_status = NULL;
 	lw->info_details = NULL;
+	lw->info_pixel = NULL;
 	lw->info_zoom = NULL;
 
 	if (lw->ui_manager) g_object_unref(lw->ui_manager);
@@ -1905,6 +1951,39 @@
 	return lw->options.toolbar_hidden;
 }
 
+void layout_info_pixel_toggle(LayoutWindow *lw)
+{
+	GtkWidget *frame;
+	
+	if (!layout_valid(&lw)) return;
+	if (!lw->info_pixel) return;
+
+	lw->options.info_pixel_hidden = !lw->options.info_pixel_hidden;
+
+	frame = gtk_widget_get_parent(lw->info_pixel);
+	if (lw->options.info_pixel_hidden)
+		{
+		if (GTK_WIDGET_VISIBLE(frame)) gtk_widget_hide(frame);
+		g_signal_handlers_block_by_func(G_OBJECT(lw->image->pr),
+		                                G_CALLBACK(layout_status_update_pixel_cb),
+		                                lw);
+		}
+	else
+		{
+		if (!GTK_WIDGET_VISIBLE(frame)) gtk_widget_show(frame);
+		g_signal_handlers_unblock_by_func(G_OBJECT(lw->image->pr),
+						  G_CALLBACK(layout_status_update_pixel_cb),
+		                      		  lw);
+		}
+}
+
+gboolean layout_info_pixel_hidden(LayoutWindow *lw)
+{
+	if (!layout_valid(&lw)) return TRUE;
+
+	return lw->options.info_pixel_hidden;
+}
+
 /*
  *-----------------------------------------------------------------------------
  * base
@@ -2169,7 +2248,8 @@
 	WRITE_SEPARATOR();
 
 	WRITE_BOOL(*layout, toolbar_hidden);
-	
+	WRITE_BOOL(*layout, info_pixel_hidden);
+
 	WRITE_UINT(*layout, image_overlay.state);
 	WRITE_INT(*layout, image_overlay.histogram_channel);
 	WRITE_INT(*layout, image_overlay.histogram_mode);
@@ -2236,6 +2316,7 @@
 		if (READ_BOOL(*layout, tools_hidden)) continue;
 		if (READ_BOOL(*layout, tools_restore_state)) continue;
 		if (READ_BOOL(*layout, toolbar_hidden)) continue;
+		if (READ_BOOL(*layout, info_pixel_hidden)) continue;
 
 		if (READ_UINT(*layout, image_overlay.state)) continue;
 		if (READ_INT(*layout, image_overlay.histogram_channel)) continue;
Index: layout.h
===================================================================
--- layout.h	(révision 1465)
+++ layout.h	(copie de travail)
@@ -101,6 +101,8 @@
 
 void layout_toolbar_toggle(LayoutWindow *lw);
 gint layout_toolbar_hidden(LayoutWindow *lw);
+void layout_info_pixel_toggle(LayoutWindow *lw);
+gboolean layout_info_pixel_hidden(LayoutWindow *lw);
 
 void layout_split_change(LayoutWindow *lw, ImageSplitMode mode);
 
Index: options.c
===================================================================
--- options.c	(révision 1465)
+++ options.c	(copie de travail)
@@ -105,6 +105,7 @@
 	options->layout.show_marks = FALSE;
 	options->layout.show_thumbnails = FALSE;
 	options->layout.style = 0;
+	options->layout.info_pixel_hidden = TRUE;
 	options->layout.toolbar_hidden = FALSE;
 	options->layout.tools_float = FALSE;
 	options->layout.tools_hidden = FALSE;
Index: pixbuf-renderer.c
===================================================================
--- pixbuf-renderer.c	(révision 1465)
+++ pixbuf-renderer.c	(copie de travail)
@@ -151,7 +151,8 @@
 	SIGNAL_SCROLL_NOTIFY,
 	SIGNAL_RENDER_COMPLETE,
 	SIGNAL_DRAG,
-	SIGNAL_COUNT
+	SIGNAL_UPDATE_PIXEL,
+	SIGNAL_COUNT /* must be last one */
 };
 
 enum {
@@ -474,6 +475,15 @@
 			     g_cclosure_marshal_VOID__BOXED,
 			     G_TYPE_NONE, 1,
 			     GDK_TYPE_EVENT);
+			     
+	signals[SIGNAL_UPDATE_PIXEL] =
+		g_signal_new("update-pixel",
+			     G_OBJECT_CLASS_TYPE(gobject_class),
+			     G_SIGNAL_RUN_LAST,
+			     G_STRUCT_OFFSET(PixbufRendererClass, update_pixel),
+			     NULL, NULL,
+			     g_cclosure_marshal_VOID__VOID,
+			     G_TYPE_NONE, 0);
 }
 
 static void pixbuf_renderer_init(PixbufRenderer *pr)
@@ -506,6 +516,9 @@
 
 	pr->scroller_id = -1;
 	pr->scroller_overlay = -1;
+	
+	pr->x_mouse = -1;
+	pr->y_mouse = -1;
 
 	pr->source_tiles_enabled = FALSE;
 	pr->source_tiles = NULL;
@@ -3092,6 +3105,11 @@
 	g_signal_emit(pr, signals[SIGNAL_DRAG], 0, bevent);
 }
 
+static void pr_update_pixel_signal(PixbufRenderer *pr)
+{
+	g_signal_emit(pr, signals[SIGNAL_UPDATE_PIXEL], 0);
+}
+
 /*
  *-------------------------------------------------------------------
  * sync and clamp
@@ -3635,7 +3653,6 @@
 	pixbuf_renderer_scroll(pr, (gint)dst_x, (gint)dst_y);
 }
 
-
 /*
  *-------------------------------------------------------------------
  * mouse
@@ -3654,7 +3671,11 @@
 		pr->scroller_xpos = bevent->x;
 		pr->scroller_ypos = bevent->y;
 		}
-
+	
+	pr->x_mouse = bevent->x;
+	pr->y_mouse = bevent->y;
+	pr_update_pixel_signal(pr);
+	
 	if (!pr->in_drag || !gdk_pointer_is_grabbed()) return FALSE;
 
 	if (pr->drag_moved < PR_DRAG_SCROLL_THRESHHOLD)
@@ -3941,6 +3962,8 @@
 
 	pr->x_scroll = source->x_scroll;
 	pr->y_scroll = source->y_scroll;
+	pr->x_mouse  = source->x_mouse;
+	pr->y_mouse  = source->y_mouse;
 
 	scroll_reset = pr->scroll_reset;
 	pr->scroll_reset = PR_SCROLL_RESET_NOCHANGE;
@@ -4071,6 +4094,74 @@
 		}
 }
 
+gint pixbuf_renderer_get_pixel_colors(PixbufRenderer *pr, gint x_pixel, gint y_pixel, 
+                                      gint *r_mouse, gint *g_mouse, gint *b_mouse)
+{
+	GdkPixbuf *pb = pr->pixbuf;
+	gint p_alpha, prs;
+	guchar *p_pix, *pp;
+	
+	g_return_val_if_fail(IS_PIXBUF_RENDERER(pr), FALSE);
+	g_return_val_if_fail(r_mouse != NULL && g_mouse != NULL && b_mouse != NULL, FALSE);
+
+	if (!pr->pixbuf && !pr->source_tiles_enabled)
+		{
+		*r_mouse = -1;
+		*g_mouse = -1;
+		*b_mouse = -1;
+		return FALSE;
+		}
+	
+	if (!pb) return FALSE;
+
+	if (x_pixel < 0 || x_pixel > pr->image_width - 1) return FALSE;
+	if (y_pixel < 0 || y_pixel > pr->image_height - 1) return FALSE;
+
+	p_alpha = gdk_pixbuf_get_has_alpha(pb);
+	prs = gdk_pixbuf_get_rowstride(pb);
+	p_pix = gdk_pixbuf_get_pixels(pb);
+
+	pp = p_pix + y_pixel * prs + (x_pixel * (p_alpha ? 4 : 3));
+	*r_mouse = *pp;
+	pp++;
+	*g_mouse = *pp;
+	pp++;
+	*b_mouse = *pp;
+	
+	return TRUE;
+}
+
+gint pixbuf_renderer_get_mouse_position(PixbufRenderer *pr, gint *x_pixel_return, gint *y_pixel_return)
+{
+	gint x_pixel, y_pixel, x_pixel_clamped, y_pixel_clamped;
+	     
+	g_return_val_if_fail(IS_PIXBUF_RENDERER(pr), FALSE);
+	g_return_val_if_fail(x_pixel_return != NULL && y_pixel_return != NULL, FALSE);
+
+	if (!pr->pixbuf && !pr->source_tiles_enabled)
+		{
+		*x_pixel_return = -1;
+		*y_pixel_return = -1;
+		return FALSE;
+		}
+	
+	x_pixel = (gint)((gdouble)(pr->x_mouse - pr->x_offset + pr->x_scroll) / pr->scale);
+	y_pixel = (gint)((gdouble)(pr->y_mouse - pr->y_offset + pr->y_scroll) / pr->scale);
+	x_pixel_clamped = CLAMP(x_pixel, 0, pr->image_width - 1);
+	y_pixel_clamped = CLAMP(y_pixel, 0, pr->image_height - 1);
+	
+	if(x_pixel != x_pixel_clamped || y_pixel != y_pixel_clamped)
+		{
+		/* mouse is not on pr */
+		x_pixel = y_pixel = -1;
+		}
+
+	*x_pixel_return = x_pixel;
+	*y_pixel_return = y_pixel;
+	
+	return TRUE;
+}
+
 gint pixbuf_renderer_get_image_size(PixbufRenderer *pr, gint *width, gint *height)
 {
 	g_return_val_if_fail(IS_PIXBUF_RENDERER(pr), FALSE);
Index: pixbuf-renderer.h
===================================================================
--- pixbuf-renderer.h	(révision 1465)
+++ pixbuf-renderer.h	(copie de travail)
@@ -58,6 +58,9 @@
 
 	gint x_offset;		/* offset of image start (non-zero when image < window) */
 	gint y_offset;
+	
+	gint x_mouse; /* coordinates of the mouse taken from GtkEvent */
+	gint y_mouse;
 
 	gint vis_width;		/* dimensions of visible part of image */
 	gint vis_height;
@@ -163,6 +166,7 @@
 	void (*zoom)(PixbufRenderer *pr, gdouble zoom);
 	void (*clicked)(PixbufRenderer *pr, GdkEventButton *event);
 	void (*scroll_notify)(PixbufRenderer *pr);
+	void (*update_pixel)(PixbufRenderer *pr);
 
 	void (*render_complete)(PixbufRenderer *pr);
 	void (*drag)(PixbufRenderer *pr, GdkEventButton *event);
@@ -258,6 +262,10 @@
 gint pixbuf_renderer_overlay_get(PixbufRenderer *pr, gint id, GdkPixbuf **pixbuf, gint *x, gint *y);
 void pixbuf_renderer_overlay_remove(PixbufRenderer *pr, gint id);
 
+gint pixbuf_renderer_get_mouse_position(PixbufRenderer *pr, gint *x_pixel, gint *y_pixel);
+/* x_pixel and y_pixel are the pixel coordinates \see pixbuf_renderer_get_mouse_position */
+gint pixbuf_renderer_get_pixel_colors(PixbufRenderer *pr, gint x_pixel, gint y_pixel,
+															 				gint *r_mouse, gint *g_mouse, gint *b_mouse);
 
 #endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
Index: layout_util.c
===================================================================
--- layout_util.c	(révision 1465)
+++ layout_util.c	(copie de travail)
@@ -666,6 +666,16 @@
 	layout_toolbar_toggle(lw);
 }
 
+static void layout_menu_info_pixel_cb(GtkToggleAction *action, gpointer data)
+{
+	LayoutWindow *lw = data;
+
+	if (lw->options.info_pixel_hidden == gtk_toggle_action_get_active(action)) return;
+
+	layout_exit_fullscreen(lw);
+	layout_info_pixel_toggle(lw);
+}
+
 /* NOTE: these callbacks are called also from layout_util_sync_views */
 static void layout_menu_bar_cb(GtkToggleAction *action, gpointer data)
 {
@@ -1260,6 +1270,7 @@
   { "ShowMarks",        NULL,		N_("Show _Marks"),	"M",		NULL,	CB(layout_menu_marks_cb),	 FALSE  },
   { "FloatTools",	PIXBUF_INLINE_ICON_FLOAT,		N_("_Float file list"),	"L",		NULL,	CB(layout_menu_float_cb),	 FALSE  },
   { "HideToolbar",	NULL,		N_("Hide tool_bar"),	NULL,		NULL,	CB(layout_menu_toolbar_cb),	 FALSE  },
+  { "HideInfoPixel",	NULL,		N_("Hide Pi_xel Info"),	NULL,		NULL,	CB(layout_menu_info_pixel_cb),	 FALSE  },
   { "SBar",		NULL,		N_("_Info"),		"<control>K",	NULL,	CB(layout_menu_bar_cb),		 FALSE  },
   { "ExifWin",		NULL,		N_("E_xif window"),	"<control>E",	NULL,	CB(layout_menu_bar_exif_cb),	 FALSE  },
   { "SBarSort",		NULL,		N_("Sort _manager"),	"<control>S",	NULL,	CB(layout_menu_bar_sort_cb),	 FALSE  },
@@ -1418,6 +1429,7 @@
 "      <menuitem action='FloatTools'/>"
 "      <menuitem action='HideTools'/>"
 "      <menuitem action='HideToolbar'/>"
+"      <menuitem action='HideInfoPixel'/>"
 "      <placeholder name='ToolsSection'/>"
 "      <separator/>"
 "      <menuitem action='SBar'/>"
@@ -1852,6 +1864,9 @@
 
 	action = gtk_action_group_get_action(lw->action_group, "HideToolbar");
 	gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.toolbar_hidden);
+	
+	action = gtk_action_group_get_action(lw->action_group, "HideInfoPixel");
+	gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.info_pixel_hidden);
 
 	action = gtk_action_group_get_action(lw->action_group, "ShowMarks");
 	gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.show_marks);
Index: typedefs.h
===================================================================
--- typedefs.h	(révision 1465)
+++ typedefs.h	(copie de travail)
@@ -532,7 +532,8 @@
 	gboolean tools_restore_state;
 
 	gboolean toolbar_hidden;
-	
+	gboolean info_pixel_hidden;
+
 	gchar *home_path;
 };
 
@@ -625,7 +626,8 @@
 	GtkWidget *info_details;
 	GtkWidget *info_zoom;
 	GtkWidget *info_write;
-
+	GtkWidget *info_pixel;
+	
 	/* slide show */
 
 	SlideShowData *slideshow;
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Geeqie-devel mailing list
Geeqie-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geeqie-devel

Reply via email to