aboutsummaryrefslogtreecommitdiff
path: root/src/imagedisplay.c
diff options
context:
space:
mode:
authortaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-08-29 16:51:54 +0000
committertaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-08-29 16:51:54 +0000
commit57645119798cd7db0d64807d8b617e13ac5e65c8 (patch)
tree4b5bf9dec98460f9e761a0f171427cd14f5f9f8f /src/imagedisplay.c
parent5008d9a881f2ec07f12160025742786f73fa95ba (diff)
Pre-alignment procedure
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@89 bf6ca9ba-c028-0410-8290-897cf20841d1
Diffstat (limited to 'src/imagedisplay.c')
-rw-r--r--src/imagedisplay.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/src/imagedisplay.c b/src/imagedisplay.c
index dfe54ca..45d3fe0 100644
--- a/src/imagedisplay.c
+++ b/src/imagedisplay.c
@@ -30,7 +30,7 @@ static void imagedisplay_free_data(guchar *image_eightbit, ImageDisplay *imagedi
free(image_eightbit);
}
-void imagedisplay_rescale(ImageDisplay *imagedisplay, unsigned int v_w, unsigned int v_h) {
+static void imagedisplay_rescale(ImageDisplay *imagedisplay, unsigned int v_w, unsigned int v_h) {
unsigned int w, h;
float aspect_image, aspect_window;
@@ -64,7 +64,7 @@ static gboolean imagedisplay_configure_event(GtkWidget *widget, GdkEventConfigur
}
-static void imagedisplay_put_data(ImageDisplay *imagedisplay, ImageRecord imagerecord) {
+void imagedisplay_put_data(ImageDisplay *imagedisplay, ImageRecord imagerecord) {
unsigned int x, y;
unsigned int w, h;
@@ -74,6 +74,10 @@ static void imagedisplay_put_data(ImageDisplay *imagedisplay, ImageRecord imager
h = imagerecord.height;
w = imagerecord.width;
+ if ( imagedisplay->pixbuf ) {
+ g_object_unref(imagedisplay->pixbuf);
+ }
+
min = 2<<15; max = 0;
for ( y=0; y<h; y++ ) {
for ( x=0; x<w; x++ ) {
@@ -107,10 +111,14 @@ static void imagedisplay_put_data(ImageDisplay *imagedisplay, ImageRecord imager
/* Create the pixbuf from the 8-bit display data */
imagedisplay->pixbuf = gdk_pixbuf_new_from_data(imagedisplay->data, GDK_COLORSPACE_RGB, FALSE, 8, w, h, w*3,
(GdkPixbufDestroyNotify)imagedisplay_free_data, imagedisplay);
+
+ if ( imagedisplay->realised ) {
+ imagedisplay_force_redraw(imagedisplay);
+ }
}
-static void imagedisplay_close(GtkWidget *widget, ImageDisplay *imagedisplay) {
+static void imagedisplay_destroyed(GtkWidget *widget, ImageDisplay *imagedisplay) {
ImageDisplayMark *cur;
@@ -133,6 +141,11 @@ static void imagedisplay_close(GtkWidget *widget, ImageDisplay *imagedisplay) {
}
+void imagedisplay_close(ImageDisplay *imagedisplay) {
+ imagedisplay->flags = (imagedisplay->flags | IMAGEDISPLAY_QUIT_IF_CLOSED)^IMAGEDISPLAY_QUIT_IF_CLOSED;
+ gtk_widget_destroy(imagedisplay->window);
+}
+
#define imagedisplay_draw_line(gc,x1,y1,x2,y2) (gdk_draw_line(drawingarea->window,gc, \
xoffs+(x1), yoffs+imagedisplay->view_height-(y1), \
xoffs+(x2), yoffs+imagedisplay->view_height-(y2)))
@@ -152,6 +165,7 @@ static gboolean imagedisplay_redraw(GtkWidget *drawingarea, GdkEventExpose *even
GDK_RGB_DITHER_NONE, 0, 0);
if ( imagedisplay->flags & IMAGEDISPLAY_SHOW_TILT_AXIS ) {
+ /* This is nasty, but works */
imagedisplay_draw_line(imagedisplay->gc_tiltaxis,
imagedisplay->imagerecord.x_centre * scale,
imagedisplay->imagerecord.y_centre * scale,
@@ -208,13 +222,15 @@ static gint imagedisplay_realize(GtkWidget *widget, ImageDisplay *imagedisplay)
gdk_color_parse("#dd0000", &colour);
gdk_gc_set_rgb_fg_color(imagedisplay->gc_marks, &colour);
+ imagedisplay->realised = TRUE;
+
return 0;
}
/* Display an image */
ImageDisplay *imagedisplay_open_with_message(ImageRecord imagerecord, const char *title, const char *message,
- ImageDisplayFlags flags, GCallback mouse_click_func) {
+ ImageDisplayFlags flags, GCallback mouse_click_func, gpointer callback_data) {
ImageDisplay *imagedisplay;
GdkGeometry geom;
@@ -229,6 +245,8 @@ ImageDisplay *imagedisplay_open_with_message(ImageRecord imagerecord, const char
imagedisplay->mouse_click_func = mouse_click_func;
imagedisplay->flags = flags;
imagedisplay->marks = NULL;
+ imagedisplay->pixbuf = NULL;
+ imagedisplay->realised = FALSE;
gtk_window_set_title(GTK_WINDOW(imagedisplay->window), imagedisplay->title);
imagedisplay_put_data(imagedisplay, imagerecord);
@@ -249,11 +267,11 @@ ImageDisplay *imagedisplay_open_with_message(ImageRecord imagerecord, const char
if ( imagedisplay->mouse_click_func ) {
gtk_widget_add_events(GTK_WIDGET(imagedisplay->drawingarea), GDK_BUTTON_PRESS_MASK);
g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "button-press-event",
- G_CALLBACK(imagedisplay->mouse_click_func), imagedisplay);
+ G_CALLBACK(imagedisplay->mouse_click_func), callback_data);
}
g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "realize", G_CALLBACK(imagedisplay_realize), imagedisplay);
- g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "destroy", G_CALLBACK(imagedisplay_close), imagedisplay);
+ g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "destroy", G_CALLBACK(imagedisplay_destroyed), imagedisplay);
g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "configure_event", G_CALLBACK(imagedisplay_configure_event), imagedisplay);
g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "expose-event", G_CALLBACK(imagedisplay_redraw), imagedisplay);
@@ -269,7 +287,7 @@ ImageDisplay *imagedisplay_open_with_message(ImageRecord imagerecord, const char
}
ImageDisplay *imagedisplay_open(ImageRecord image, const char *title, ImageDisplayFlags flags) {
- return imagedisplay_open_with_message(image, title, NULL, flags, NULL);
+ return imagedisplay_open_with_message(image, title, NULL, flags, NULL, NULL);
}
void imagedisplay_mark_circle(ImageDisplay *imagedisplay, double x, double y) {
@@ -293,3 +311,8 @@ void imagedisplay_mark_circle(ImageDisplay *imagedisplay, double x, double y) {
}
+void imagedisplay_force_redraw(ImageDisplay *imagedisplay) {
+ imagedisplay_rescale(imagedisplay, imagedisplay->drawingarea_width, imagedisplay->drawingarea_height);
+ gtk_widget_queue_draw_area(imagedisplay->drawingarea, 0, 0, imagedisplay->drawingarea_width, imagedisplay->drawingarea_height);
+}
+