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.
Thank you very much for contributing.
You're welcome, thanks for the patience.
Regards, Ruben
Index: src/layout.c
===================================================================
--- src/layout.c (Revision 1465)
+++ src/layout.c (Arbeitskopie)
@@ -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,44 @@
g_free(buf);
}
+void layout_status_update_pixel_cb(GtkWidget *widget, gpointer data)
+{
+ LayoutWindow *lw = data;
+ gchar *text;
+
+ if (!data || !layout_valid(&lw) || !lw->image) return;
+
+ if (!lw->image->unknown)
+ {
+ gint x_pixel, y_pixel;
+
+ 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];
+
+ 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(_("<tt>pos(%*d,%*d) rgb(%3d,%3d,%3d)</tt>"),
+ slen_width, x_pixel, slen_height, y_pixel,
+ r_mouse, g_mouse, b_mouse);
+ }
+ else
+ {
+ text = g_strdup("");
+ }
+ gtk_label_set_markup(GTK_LABEL(lw->info_pixel), text);
+ g_free(text);
+ }
+}
+
void layout_status_update_image(LayoutWindow *lw)
{
guint64 n;
@@ -713,6 +752,8 @@
width, height, b);
}
+ g_signal_emit_by_name (lw->image->pr, "update-pixel");
+
g_free(b);
gtk_label_set_text(GTK_LABEL(lw->info_details), text);
@@ -813,7 +854,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 +1793,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 +1952,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);
+ }
+}
+
+gint layout_info_pixel_hidden(LayoutWindow *lw)
+{
+ if (!layout_valid(&lw)) return TRUE;
+
+ return lw->options.info_pixel_hidden;
+}
+
/*
*-----------------------------------------------------------------------------
* base
@@ -2169,7 +2249,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 +2317,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: src/layout.h
===================================================================
--- src/layout.h (Revision 1465)
+++ src/layout.h (Arbeitskopie)
@@ -101,6 +101,8 @@
void layout_toolbar_toggle(LayoutWindow *lw);
gint layout_toolbar_hidden(LayoutWindow *lw);
+void layout_info_pixel_toggle(LayoutWindow *lw);
+gint layout_info_pixel_hidden(LayoutWindow *lw);
void layout_split_change(LayoutWindow *lw, ImageSplitMode mode);
Index: src/options.c
===================================================================
--- src/options.c (Revision 1465)
+++ src/options.c (Arbeitskopie)
@@ -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: src/pixbuf-renderer.c
===================================================================
--- src/pixbuf-renderer.c (Revision 1465)
+++ src/pixbuf-renderer.c (Arbeitskopie)
@@ -15,8 +15,11 @@
#include <string.h>
#include <math.h>
+#include "main.h"
#include "pixbuf-renderer.h"
+
#include "intl.h"
+#include "layout.h"
#include <gtk/gtk.h>
@@ -151,7 +154,8 @@
SIGNAL_SCROLL_NOTIFY,
SIGNAL_RENDER_COMPLETE,
SIGNAL_DRAG,
- SIGNAL_COUNT
+ SIGNAL_COUNT,
+ SIGNAL_UPDATE_PIXEL
};
enum {
@@ -474,6 +478,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 +519,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 +3108,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 +3656,6 @@
pixbuf_renderer_scroll(pr, (gint)dst_x, (gint)dst_y);
}
-
/*
*-------------------------------------------------------------------
* mouse
@@ -3654,7 +3674,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 +3965,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 +4097,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;
+
+ if (x_pixel < 0 || x_pixel > pr->image_width - 1) return;
+ if (y_pixel < 0 || y_pixel > pr->image_height - 1) return;
+
+ 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: src/pixbuf-renderer.h
===================================================================
--- src/pixbuf-renderer.h (Revision 1465)
+++ src/pixbuf-renderer.h (Arbeitskopie)
@@ -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: src/layout_util.c
===================================================================
--- src/layout_util.c (Revision 1465)
+++ src/layout_util.c (Arbeitskopie)
@@ -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: src/typedefs.h
===================================================================
--- src/typedefs.h (Revision 1465)
+++ src/typedefs.h (Arbeitskopie)
@@ -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