comparison src/pixbuf-renderer.c @ 1375:df58e511d90e

Display pixel coordinates and rgb - patch by Ruben Stein
author nadvornik
date Wed, 04 Mar 2009 18:53:47 +0000
parents 168e5597ddc7
children 7e180091e0b7
comparison
equal deleted inserted replaced
1374:27ba259d3496 1375:df58e511d90e
13 #include <stdio.h> 13 #include <stdio.h>
14 #include <stdlib.h> 14 #include <stdlib.h>
15 #include <string.h> 15 #include <string.h>
16 #include <math.h> 16 #include <math.h>
17 17
18 #include "main.h"
18 #include "pixbuf-renderer.h" 19 #include "pixbuf-renderer.h"
20
19 #include "intl.h" 21 #include "intl.h"
22 #include "layout.h"
20 23
21 #include <gtk/gtk.h> 24 #include <gtk/gtk.h>
22 25
23 26
24 /* comment this out if not using this from within Geeqie 27 /* comment this out if not using this from within Geeqie
149 SIGNAL_ZOOM = 0, 152 SIGNAL_ZOOM = 0,
150 SIGNAL_CLICKED, 153 SIGNAL_CLICKED,
151 SIGNAL_SCROLL_NOTIFY, 154 SIGNAL_SCROLL_NOTIFY,
152 SIGNAL_RENDER_COMPLETE, 155 SIGNAL_RENDER_COMPLETE,
153 SIGNAL_DRAG, 156 SIGNAL_DRAG,
157 SIGNAL_UPDATE_PIXEL,
154 SIGNAL_COUNT 158 SIGNAL_COUNT
155 }; 159 };
156 160
157 enum { 161 enum {
158 PROP_0, 162 PROP_0,
473 G_STRUCT_OFFSET(PixbufRendererClass, drag), 477 G_STRUCT_OFFSET(PixbufRendererClass, drag),
474 NULL, NULL, 478 NULL, NULL,
475 g_cclosure_marshal_VOID__BOXED, 479 g_cclosure_marshal_VOID__BOXED,
476 G_TYPE_NONE, 1, 480 G_TYPE_NONE, 1,
477 GDK_TYPE_EVENT); 481 GDK_TYPE_EVENT);
482
483 signals[SIGNAL_UPDATE_PIXEL] =
484 g_signal_new("update-pixel",
485 G_OBJECT_CLASS_TYPE(gobject_class),
486 G_SIGNAL_RUN_LAST,
487 G_STRUCT_OFFSET(PixbufRendererClass, update_pixel),
488 NULL, NULL,
489 g_cclosure_marshal_VOID__VOID,
490 G_TYPE_NONE, 0);
478 } 491 }
479 492
480 static void pixbuf_renderer_init(PixbufRenderer *pr) 493 static void pixbuf_renderer_init(PixbufRenderer *pr)
481 { 494 {
482 GtkWidget *box; 495 GtkWidget *box;
505 518
506 pr->tile_cache_max = PR_CACHE_SIZE_DEFAULT; 519 pr->tile_cache_max = PR_CACHE_SIZE_DEFAULT;
507 520
508 pr->scroller_id = -1; 521 pr->scroller_id = -1;
509 pr->scroller_overlay = -1; 522 pr->scroller_overlay = -1;
523
524 pr->x_mouse = -1;
525 pr->y_mouse = -1;
510 526
511 pr->source_tiles_enabled = FALSE; 527 pr->source_tiles_enabled = FALSE;
512 pr->source_tiles = NULL; 528 pr->source_tiles = NULL;
513 529
514 pr->orientation = 1; 530 pr->orientation = 1;
3127 static void pr_drag_signal(PixbufRenderer *pr, GdkEventButton *bevent) 3143 static void pr_drag_signal(PixbufRenderer *pr, GdkEventButton *bevent)
3128 { 3144 {
3129 g_signal_emit(pr, signals[SIGNAL_DRAG], 0, bevent); 3145 g_signal_emit(pr, signals[SIGNAL_DRAG], 0, bevent);
3130 } 3146 }
3131 3147
3148 static void pr_update_pixel_signal(PixbufRenderer *pr)
3149 {
3150 g_signal_emit(pr, signals[SIGNAL_UPDATE_PIXEL], 0);
3151 }
3152
3132 /* 3153 /*
3133 *------------------------------------------------------------------- 3154 *-------------------------------------------------------------------
3134 * sync and clamp 3155 * sync and clamp
3135 *------------------------------------------------------------------- 3156 *-------------------------------------------------------------------
3136 */ 3157 */
3670 pr->subpixel_y_scroll = dst_y - (gint)dst_y; 3691 pr->subpixel_y_scroll = dst_y - (gint)dst_y;
3671 3692
3672 pixbuf_renderer_scroll(pr, (gint)dst_x, (gint)dst_y); 3693 pixbuf_renderer_scroll(pr, (gint)dst_x, (gint)dst_y);
3673 } 3694 }
3674 3695
3675
3676 /* 3696 /*
3677 *------------------------------------------------------------------- 3697 *-------------------------------------------------------------------
3678 * mouse 3698 * mouse
3679 *------------------------------------------------------------------- 3699 *-------------------------------------------------------------------
3680 */ 3700 */
3689 if (pr->scroller_id != -1) 3709 if (pr->scroller_id != -1)
3690 { 3710 {
3691 pr->scroller_xpos = bevent->x; 3711 pr->scroller_xpos = bevent->x;
3692 pr->scroller_ypos = bevent->y; 3712 pr->scroller_ypos = bevent->y;
3693 } 3713 }
3694 3714
3715 pr->x_mouse = bevent->x;
3716 pr->y_mouse = bevent->y;
3717 pr_update_pixel_signal(pr);
3718
3695 if (!pr->in_drag || !gdk_pointer_is_grabbed()) return FALSE; 3719 if (!pr->in_drag || !gdk_pointer_is_grabbed()) return FALSE;
3696 3720
3697 if (pr->drag_moved < PR_DRAG_SCROLL_THRESHHOLD) 3721 if (pr->drag_moved < PR_DRAG_SCROLL_THRESHHOLD)
3698 { 3722 {
3699 pr->drag_moved++; 3723 pr->drag_moved++;
3978 4002
3979 pr->complete = source->complete; 4003 pr->complete = source->complete;
3980 4004
3981 pr->x_scroll = source->x_scroll; 4005 pr->x_scroll = source->x_scroll;
3982 pr->y_scroll = source->y_scroll; 4006 pr->y_scroll = source->y_scroll;
4007 pr->x_mouse = source->x_mouse;
4008 pr->y_mouse = source->y_mouse;
3983 4009
3984 scroll_reset = pr->scroll_reset; 4010 scroll_reset = pr->scroll_reset;
3985 pr->scroll_reset = PR_SCROLL_RESET_NOCHANGE; 4011 pr->scroll_reset = PR_SCROLL_RESET_NOCHANGE;
3986 4012
3987 pr->func_post_process = source->func_post_process; 4013 pr->func_post_process = source->func_post_process;
4108 pr->zoom_max = max; 4134 pr->zoom_max = max;
4109 g_object_notify(G_OBJECT(pr), "zoom_max"); 4135 g_object_notify(G_OBJECT(pr), "zoom_max");
4110 } 4136 }
4111 } 4137 }
4112 4138
4139 gint pixbuf_renderer_get_pixel_colors(PixbufRenderer *pr, gint x_pixel, gint y_pixel,
4140 gint *r_mouse, gint *g_mouse, gint *b_mouse)
4141 {
4142 GdkPixbuf *pb = pr->pixbuf;
4143 gint p_alpha, prs;
4144 guchar *p_pix, *pp;
4145 gint map_x, map_y, map_w, map_h;
4146
4147 g_return_val_if_fail(IS_PIXBUF_RENDERER(pr), FALSE);
4148 g_return_val_if_fail(r_mouse != NULL && g_mouse != NULL && b_mouse != NULL, FALSE);
4149
4150 if (!pr->pixbuf && !pr->source_tiles_enabled)
4151 {
4152 *r_mouse = -1;
4153 *g_mouse = -1;
4154 *b_mouse = -1;
4155 return FALSE;
4156 }
4157
4158 if (!pb) return FALSE;
4159
4160 pr_tile_region_map_orientation(pr,
4161 x_pixel, y_pixel,
4162 pr->image_width, pr->image_height,
4163 1, 1, /*single pixel */
4164 &map_x, &map_y,
4165 &map_w, &map_h);
4166
4167 if (map_x < 0 || map_x > gdk_pixbuf_get_width(pr->pixbuf) - 1) return FALSE;
4168 if (map_y < 0 || map_y > gdk_pixbuf_get_height(pr->pixbuf) - 1) return FALSE;
4169
4170 p_alpha = gdk_pixbuf_get_has_alpha(pb);
4171 prs = gdk_pixbuf_get_rowstride(pb);
4172 p_pix = gdk_pixbuf_get_pixels(pb);
4173
4174 pp = p_pix + map_y * prs + (map_x * (p_alpha ? 4 : 3));
4175 *r_mouse = *pp;
4176 pp++;
4177 *g_mouse = *pp;
4178 pp++;
4179 *b_mouse = *pp;
4180
4181 return TRUE;
4182 }
4183
4184 gint pixbuf_renderer_get_mouse_position(PixbufRenderer *pr, gint *x_pixel_return, gint *y_pixel_return)
4185 {
4186 gint x_pixel, y_pixel, x_pixel_clamped, y_pixel_clamped;
4187
4188 g_return_val_if_fail(IS_PIXBUF_RENDERER(pr), FALSE);
4189 g_return_val_if_fail(x_pixel_return != NULL && y_pixel_return != NULL, FALSE);
4190
4191 if (!pr->pixbuf && !pr->source_tiles_enabled)
4192 {
4193 *x_pixel_return = -1;
4194 *y_pixel_return = -1;
4195 return FALSE;
4196 }
4197
4198 x_pixel = (gint)((gdouble)(pr->x_mouse - pr->x_offset + pr->x_scroll) / pr->scale);
4199 y_pixel = (gint)((gdouble)(pr->y_mouse - pr->y_offset + pr->y_scroll) / pr->scale);
4200 x_pixel_clamped = CLAMP(x_pixel, 0, pr->image_width - 1);
4201 y_pixel_clamped = CLAMP(y_pixel, 0, pr->image_height - 1);
4202
4203 if(x_pixel != x_pixel_clamped || y_pixel != y_pixel_clamped)
4204 {
4205 /* mouse is not on pr */
4206 x_pixel = y_pixel = -1;
4207 }
4208
4209 *x_pixel_return = x_pixel;
4210 *y_pixel_return = y_pixel;
4211
4212 return TRUE;
4213 }
4214
4113 gint pixbuf_renderer_get_image_size(PixbufRenderer *pr, gint *width, gint *height) 4215 gint pixbuf_renderer_get_image_size(PixbufRenderer *pr, gint *width, gint *height)
4114 { 4216 {
4115 g_return_val_if_fail(IS_PIXBUF_RENDERER(pr), FALSE); 4217 g_return_val_if_fail(IS_PIXBUF_RENDERER(pr), FALSE);
4116 g_return_val_if_fail(width != NULL && height != NULL, FALSE); 4218 g_return_val_if_fail(width != NULL && height != NULL, FALSE);
4117 4219