From 0fae5ae6c39b253a6b14a88367d85059763cefa2 Mon Sep 17 00:00:00 2001 From: Davis King Date: Mon, 20 Jun 2011 20:45:23 -0400 Subject: [PATCH] Added an event handler for when the user selects an overlay rectangle. --- dlib/gui_widgets/widgets.cpp | 2 ++ dlib/gui_widgets/widgets.h | 21 +++++++++++++++ dlib/gui_widgets/widgets_abstract.h | 40 +++++++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/dlib/gui_widgets/widgets.cpp b/dlib/gui_widgets/widgets.cpp index d494ca9e3..9a60acf71 100644 --- a/dlib/gui_widgets/widgets.cpp +++ b/dlib/gui_widgets/widgets.cpp @@ -5922,6 +5922,8 @@ namespace dlib { rect_is_selected = true; selected_rect = best_idx; + if (orect_selected_event_handler.is_set()) + orect_selected_event_handler(overlay_rects[best_idx]); } if (rect_is_selected || rect_was_selected) diff --git a/dlib/gui_widgets/widgets.h b/dlib/gui_widgets/widgets.h index b48381fb6..fee9b4777 100644 --- a/dlib/gui_widgets/widgets.h +++ b/dlib/gui_widgets/widgets.h @@ -3341,6 +3341,26 @@ namespace dlib event_handler = event_handler_; } + template < + typename T + > + void set_overlay_rect_selected_handler ( + T& object, + void (T::*event_handler_)(const overlay_rect& orect) + ) + { + auto_mutex M(m); + orect_selected_event_handler = make_mfp(object,event_handler_); + } + + void set_overlay_rects_changed_handler ( + const any_function& event_handler_ + ) + { + auto_mutex M(m); + orect_selected_event_handler = event_handler_; + } + private: @@ -3402,6 +3422,7 @@ namespace dlib rgb_alpha_pixel default_rect_color; std::string default_rect_label; any_function event_handler; + any_function orect_selected_event_handler; // restricted functions image_display(image_display&); // copy constructor diff --git a/dlib/gui_widgets/widgets_abstract.h b/dlib/gui_widgets/widgets_abstract.h index 1d96c5090..4070fdb28 100644 --- a/dlib/gui_widgets/widgets_abstract.h +++ b/dlib/gui_widgets/widgets_abstract.h @@ -2011,7 +2011,7 @@ namespace dlib > void set_graph_modified_handler ( T& object, - void (T::*event_handler_)() + void (T::*event_handler)() ); /*! requires @@ -2550,7 +2550,7 @@ namespace dlib > void set_overlay_rects_changed_handler ( T& object, - void (T::*event_handler_)() + void (T::*event_handler)() ); /* requires @@ -2579,6 +2579,42 @@ namespace dlib - std::bad_alloc */ + template < + typename T + > + void set_overlay_rect_selected_handler ( + T& object, + void (T::*event_handler)(const overlay_rect& orect) + ); + /* + requires + - event_handler is a valid pointer to a member function in T + ensures + - The event_handler function is called on object when the user selects + an overlay rectangle by double clicking on it. The selected rectangle + will be passed to event_handler(). + - any previous calls to this function are overridden by this new call. + (i.e. you can only have one event handler associated with this + event at a time) + throws + - std::bad_alloc + */ + + void set_overlay_rects_changed_handler ( + const any_function& event_handler + ); + /* + ensures + - The event_handler function is called when the user selects an overlay + rectangle by double clicking on it. The selected rectangle will be + passed to event_handler(). + - any previous calls to this function are overridden by this new call. + (i.e. you can only have one event handler associated with this + event at a time) + throws + - std::bad_alloc + */ + private: // restricted functions