From 16c3140d19054c41ba858e87787ff6a688291333 Mon Sep 17 00:00:00 2001 From: Maria Date: Wed, 8 Jan 2014 18:06:56 +0100 Subject: Draw ROI-rectangle --- bin/gui/control.c | 48 +++++++++++++++++++++++++++++++++ bin/gui/control.glade | 74 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 93 insertions(+), 29 deletions(-) (limited to 'bin') diff --git a/bin/gui/control.c b/bin/gui/control.c index c4248f0..71a94c5 100644 --- a/bin/gui/control.c +++ b/bin/gui/control.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "config.h" #include "uca-camera.h" @@ -47,6 +48,7 @@ typedef struct { GtkWidget *zoom_in_button; GtkWidget *zoom_out_button; GtkWidget *zoom_normal_button; + GtkWidget *rect_color_button; GtkWidget *acquisition_expander; GtkWidget *properties_expander; GtkWidget *colormap_box; @@ -98,6 +100,10 @@ typedef struct { gint from_x, from_y; gint to_x, to_y; gint adj_width, adj_height; + gint rect_x, rect_y; + gint rect_evx, rect_evy; + cairo_t *cr; + gdouble red, green, blue; } ThreadData; static UcaPluginManager *plugin_manager; @@ -357,6 +363,8 @@ on_motion_notify (GtkWidget *event_box, GdkEventMotion *event, ThreadData *data) gint start_hval = gtk_adjustment_get_value (GTK_ADJUSTMENT (data->vadjustment)); page_width += start_wval; page_height += start_hval; + data->rect_evx = event->x; + data->rect_evy = event->y; if ((data->display_width < page_width) && (data->display_height < page_height)) { gint startx = (page_width - data->display_width) / 2; @@ -445,6 +453,10 @@ normalize_event_coords (ThreadData *data) static void on_button_press (GtkWidget *event_box, GdkEventMotion *event, ThreadData *data) { + data->cr = gdk_cairo_create(event_box->window); + data->rect_x = event->x; + data->rect_y = event->y; + normalize_event_coords (data); gtk_adjustment_set_upper (GTK_ADJUSTMENT (data->x_adjustment), data->display_width); @@ -461,6 +473,8 @@ on_button_press (GtkWidget *event_box, GdkEventMotion *event, ThreadData *data) static void on_button_release (GtkWidget *event_box, GdkEventMotion *event, ThreadData *data) { + cairo_destroy (data->cr); + normalize_event_coords (data); gtk_adjustment_set_upper (GTK_ADJUSTMENT (data->width_adjustment), data->display_width); @@ -494,6 +508,22 @@ on_button_release (GtkWidget *event_box, GdkEventMotion *event, ThreadData *data update_pixbuf (data); } +static gboolean +on_expose (GtkWidget *event_box, GdkEventExpose *event, ThreadData *data) +{ + if (data->cr != NULL) { + gdouble dash = 5.0; + cairo_set_source_rgb (data->cr, data->red, data->green, data->blue); + gint rect_width = data->rect_evx - data->rect_x; + gint rect_height = data->rect_evy - data->rect_y; + cairo_rectangle (data->cr, data->rect_x, data->rect_y, rect_width, rect_height); + cairo_set_dash (data->cr, &dash, 1, 0); + cairo_stroke (data->cr); + gtk_widget_queue_draw (event_box); + } + return FALSE; +} + static void update_pixbuf (ThreadData *data) { @@ -986,6 +1016,21 @@ on_zoom_normal_button_clicked (GtkWidget *widget, ThreadData *data) update_zoomed_pixbuf (data); } +static void +on_rect_color_button_clicked (GtkWidget *widget, ThreadData *data) +{ + if ((data->red == 0.0 && data->green == 0.0) && data->blue == 0.0) { + data->red = 1.0; + data->green = 1.0; + data->blue = 1.0; + } + else { + data->red = 0.0; + data->green = 0.0; + data->blue = 0.0; + } +} + static void on_histogram_changed (EggHistogramView *view, ThreadData *data) { @@ -1084,6 +1129,7 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) td.zoom_in_button = GTK_WIDGET (gtk_builder_get_object (builder, "zoom-in-button")); td.zoom_out_button = GTK_WIDGET (gtk_builder_get_object (builder, "zoom-out-button")); td.zoom_normal_button = GTK_WIDGET (gtk_builder_get_object (builder, "zoom-normal-button")); + td.rect_color_button = GTK_WIDGET (gtk_builder_get_object (builder, "rectangle-button")); td.download_button = GTK_WIDGET (gtk_builder_get_object (builder, "download-button")); td.histogram_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "histogram-checkbutton")); td.log_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "logarithm-checkbutton")); @@ -1175,6 +1221,7 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) g_signal_connect (td.event_box, "motion-notify-event", G_CALLBACK (on_motion_notify), &td); g_signal_connect (td.event_box, "button-press-event", G_CALLBACK (on_button_press), &td); g_signal_connect (td.event_box, "button-release-event", G_CALLBACK (on_button_release), &td); + g_signal_connect (td.event_box, "expose-event", G_CALLBACK (on_expose), &td); g_signal_connect (td.frame_slider, "value-changed", G_CALLBACK (on_frame_slider_changed), &td); g_signal_connect (td.start_button, "clicked", G_CALLBACK (on_start_button_clicked), &td); g_signal_connect (td.stop_button, "clicked", G_CALLBACK (on_stop_button_clicked), &td); @@ -1183,6 +1230,7 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) g_signal_connect (td.zoom_in_button, "clicked", G_CALLBACK (on_zoom_in_button_clicked), &td); g_signal_connect (td.zoom_out_button, "clicked", G_CALLBACK (on_zoom_out_button_clicked), &td); g_signal_connect (td.zoom_normal_button, "clicked", G_CALLBACK (on_zoom_normal_button_clicked), &td); + g_signal_connect (td.rect_color_button, "clicked", G_CALLBACK (on_rect_color_button_clicked), &td); g_signal_connect (histogram_view, "changed", G_CALLBACK (on_histogram_changed), &td); g_signal_connect (window, "destroy", G_CALLBACK (on_destroy), &td); diff --git a/bin/gui/control.glade b/bin/gui/control.glade index 95184ed..967fdf0 100644 --- a/bin/gui/control.glade +++ b/bin/gui/control.glade @@ -72,10 +72,10 @@ gtk-quit + False True True True - False True @@ -88,10 +88,10 @@ gtk-ok + False True True True - False True @@ -152,10 +152,10 @@ gtk-close + False True True True - False True @@ -230,17 +230,17 @@ 1 10 - - 100 - 1 - 10 - 65535 256 1 10 + + 100 + 1 + 10 + 65535 1 @@ -272,9 +272,9 @@ False + False True False - False _File True @@ -284,9 +284,9 @@ gtk-new + False True False - False True True @@ -294,9 +294,9 @@ gtk-open + False True False - False True True @@ -304,9 +304,9 @@ gtk-save-as + False True False - False True True @@ -320,9 +320,9 @@ gtk-quit + False True False - False True True @@ -334,9 +334,9 @@ + False True False - False _Help True @@ -346,9 +346,9 @@ gtk-about + False True False - False True True @@ -370,9 +370,9 @@ False + False True False - False Run True gtk-media-play @@ -384,9 +384,9 @@ + False True False - False Record True gtk-media-record @@ -398,9 +398,9 @@ + False True False - False Stop True gtk-media-stop @@ -412,9 +412,9 @@ + False True False - False Download True network-receive @@ -426,9 +426,9 @@ + False True False - False False @@ -437,9 +437,9 @@ + False True False - False Zoom in True gtk-zoom-in @@ -451,9 +451,9 @@ + False True False - False Zoom out True gtk-zoom-out @@ -465,9 +465,9 @@ + False True False - False 100 % True gtk-zoom-100 @@ -477,6 +477,20 @@ True + + + False + True + False + rectangle color + True + gtk-color-picker + + + False + True + + False @@ -507,9 +521,11 @@ True + True False GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_STRUCTURE_MASK queue + True True @@ -685,10 +701,10 @@ Repeat + False True True False - False 0 True @@ -925,11 +941,11 @@ Live Update + False True True False 6 - False 0 True True @@ -956,6 +972,9 @@ 2 6 6 + + + True @@ -1088,9 +1107,6 @@ - - - True @@ -1262,11 +1278,11 @@ Logarithm + False True True False 10 - False 0 True -- cgit v1.2.3 From e62f4f920e007d548fade076f2229d2526d47d38 Mon Sep 17 00:00:00 2001 From: Maria Date: Wed, 8 Jan 2014 18:20:19 +0100 Subject: Fix ROI-rectangle --- bin/gui/control.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'bin') diff --git a/bin/gui/control.c b/bin/gui/control.c index 71a94c5..545c095 100644 --- a/bin/gui/control.c +++ b/bin/gui/control.c @@ -432,6 +432,16 @@ on_motion_notify (GtkWidget *event_box, GdkEventMotion *event, ThreadData *data) g_string_free (string, TRUE); } + if (data->cr != NULL) { + gdouble dash = 5.0; + cairo_set_source_rgb (data->cr, data->red, data->green, data->blue); + gint rect_width = data->rect_evx - data->rect_x; + gint rect_height = data->rect_evy - data->rect_y; + cairo_rectangle (data->cr, data->rect_x, data->rect_y, rect_width, rect_height); + cairo_set_dash (data->cr, &dash, 1, 0); + cairo_stroke (data->cr); + gtk_widget_queue_draw (event_box); + } } static void @@ -474,6 +484,7 @@ static void on_button_release (GtkWidget *event_box, GdkEventMotion *event, ThreadData *data) { cairo_destroy (data->cr); + data->cr = NULL; normalize_event_coords (data); -- cgit v1.2.3