Commit 567aeab0 authored by Davis King's avatar Davis King

Added an overload of get_next_double_click() that allows the user to find out

which mouse button was double clicked.
parent 578107c3
...@@ -6096,7 +6096,7 @@ namespace dlib ...@@ -6096,7 +6096,7 @@ namespace dlib
p = p*zoom_out_scale; p = p*zoom_out_scale;
if (dlib::get_rect(img).contains(p)) if (dlib::get_rect(img).contains(p))
image_clicked_handler(p, is_double_click); image_clicked_handler(p, is_double_click, btn);
} }
if (btn == base_window::RIGHT && rect_is_selected) if (btn == base_window::RIGHT && rect_is_selected)
...@@ -6450,6 +6450,7 @@ namespace dlib ...@@ -6450,6 +6450,7 @@ namespace dlib
gui_img(*this), gui_img(*this),
window_has_closed(false), window_has_closed(false),
have_last_click(false), have_last_click(false),
mouse_btn(0),
clicked_signaler(this->wm) clicked_signaler(this->wm)
{ {
...@@ -6485,7 +6486,8 @@ namespace dlib ...@@ -6485,7 +6486,8 @@ namespace dlib
bool image_window:: bool image_window::
get_next_double_click ( get_next_double_click (
point& p point& p,
unsigned long& mouse_button
) )
{ {
auto_mutex lock(wm); auto_mutex lock(wm);
...@@ -6500,6 +6502,7 @@ namespace dlib ...@@ -6500,6 +6502,7 @@ namespace dlib
// Mark that we are taking the point click so the next call to get_next_click() // Mark that we are taking the point click so the next call to get_next_click()
// will have to wait for another click. // will have to wait for another click.
have_last_click = false; have_last_click = false;
mouse_button = mouse_btn;
p = last_clicked_point; p = last_clicked_point;
return true; return true;
} }
...@@ -6509,13 +6512,15 @@ namespace dlib ...@@ -6509,13 +6512,15 @@ namespace dlib
void image_window:: void image_window::
on_image_clicked ( on_image_clicked (
const point& p, const point& p,
bool is_double_click bool is_double_click,
unsigned long btn
) )
{ {
if (is_double_click) if (is_double_click)
{ {
have_last_click = true; have_last_click = true;
last_clicked_point = p; last_clicked_point = p;
mouse_btn = btn;
clicked_signaler.signal(); clicked_signaler.signal();
} }
} }
......
...@@ -3435,7 +3435,7 @@ namespace dlib ...@@ -3435,7 +3435,7 @@ namespace dlib
> >
void set_image_clicked_handler ( void set_image_clicked_handler (
T& object, T& object,
void (T::*event_handler_)(const point& p, bool is_double_click) void (T::*event_handler_)(const point& p, bool is_double_click, unsigned long btn)
) )
{ {
auto_mutex M(m); auto_mutex M(m);
...@@ -3443,7 +3443,7 @@ namespace dlib ...@@ -3443,7 +3443,7 @@ namespace dlib
} }
void set_image_clicked_handler ( void set_image_clicked_handler (
const any_function<void(const point& p, bool is_double_click)>& event_handler_ const any_function<void(const point& p, bool is_double_click, unsigned long btn)>& event_handler_
) )
{ {
auto_mutex M(m); auto_mutex M(m);
...@@ -3532,7 +3532,7 @@ namespace dlib ...@@ -3532,7 +3532,7 @@ namespace dlib
std::string default_rect_label; std::string default_rect_label;
any_function<void()> event_handler; any_function<void()> event_handler;
any_function<void(const overlay_rect& orect)> orect_selected_event_handler; any_function<void(const overlay_rect& orect)> orect_selected_event_handler;
any_function<void(const point& p, bool is_double_click)> image_clicked_handler; any_function<void(const point& p, bool is_double_click, unsigned long btn)> image_clicked_handler;
popup_menu_region parts_menu; popup_menu_region parts_menu;
point last_right_click_pos; point last_right_click_pos;
const int part_width; const int part_width;
...@@ -3563,6 +3563,7 @@ namespace dlib ...@@ -3563,6 +3563,7 @@ namespace dlib
gui_img(*this), gui_img(*this),
window_has_closed(false), window_has_closed(false),
have_last_click(false), have_last_click(false),
mouse_btn(0),
clicked_signaler(this->wm) clicked_signaler(this->wm)
{ {
gui_img.set_image_clicked_handler(*this, &image_window::on_image_clicked); gui_img.set_image_clicked_handler(*this, &image_window::on_image_clicked);
...@@ -3578,6 +3579,7 @@ namespace dlib ...@@ -3578,6 +3579,7 @@ namespace dlib
gui_img(*this), gui_img(*this),
window_has_closed(false), window_has_closed(false),
have_last_click(false), have_last_click(false),
mouse_btn(0),
clicked_signaler(this->wm) clicked_signaler(this->wm)
{ {
gui_img.set_image_clicked_handler(*this, &image_window::on_image_clicked); gui_img.set_image_clicked_handler(*this, &image_window::on_image_clicked);
...@@ -3744,15 +3746,17 @@ namespace dlib ...@@ -3744,15 +3746,17 @@ namespace dlib
); );
bool get_next_double_click ( bool get_next_double_click (
point& p point& p,
unsigned long& mouse_button
); );
/*!
ensures bool get_next_double_click (
- This function blocks until the user double clicks on the image point& p
or the window is closed by the user. )
- if (this function returns true) then {
- #p == the next place the user clicked unsigned long mouse_button;
!*/ return get_next_double_click(p, mouse_btn);
}
private: private:
...@@ -3764,7 +3768,8 @@ namespace dlib ...@@ -3764,7 +3768,8 @@ namespace dlib
void on_image_clicked ( void on_image_clicked (
const point& p, const point& p,
bool is_double_click bool is_double_click,
unsigned long btn
); );
// restricted functions // restricted functions
...@@ -3777,6 +3782,7 @@ namespace dlib ...@@ -3777,6 +3782,7 @@ namespace dlib
bool window_has_closed; bool window_has_closed;
bool have_last_click; bool have_last_click;
point last_clicked_point; point last_clicked_point;
unsigned long mouse_btn;
rsignaler clicked_signaler; rsignaler clicked_signaler;
}; };
......
...@@ -3024,12 +3024,27 @@ namespace dlib ...@@ -3024,12 +3024,27 @@ namespace dlib
); );
/*! /*!
ensures ensures
- This function blocks until the user double left clicks on the image or - This function blocks until the user double clicks on the image or the
the window is closed by the user. window is closed by the user.
- if (this function returns true) then - if (this function returns true) then
- #p == the next image pixel the user clicked. - #p == the next image pixel the user clicked.
!*/ !*/
bool get_next_double_click (
point& p,
unsigned long& mouse_button
);
/*!
ensures
- This function blocks until the user double clicks on the image or the
window is closed by the user.
- if (this function returns true) then
- #p == the next image pixel the user clicked.
- #mouse_button == the mouse button which was used to double click.
This will be either dlib::base_window::LEFT,
dlib::base_window::MIDDLE, or dlib::base_window::RIGHT
!*/
private: private:
// restricted functions // restricted functions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment