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

which mouse button was double clicked.
This commit is contained in:
Davis King 2013-01-16 20:38:58 -05:00
parent 578107c364
commit 567aeab023
3 changed files with 43 additions and 17 deletions

View File

@ -6096,7 +6096,7 @@ namespace dlib
p = p*zoom_out_scale;
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)
@ -6450,6 +6450,7 @@ namespace dlib
gui_img(*this),
window_has_closed(false),
have_last_click(false),
mouse_btn(0),
clicked_signaler(this->wm)
{
@ -6485,7 +6486,8 @@ namespace dlib
bool image_window::
get_next_double_click (
point& p
point& p,
unsigned long& mouse_button
)
{
auto_mutex lock(wm);
@ -6500,6 +6502,7 @@ namespace dlib
// Mark that we are taking the point click so the next call to get_next_click()
// will have to wait for another click.
have_last_click = false;
mouse_button = mouse_btn;
p = last_clicked_point;
return true;
}
@ -6509,13 +6512,15 @@ namespace dlib
void image_window::
on_image_clicked (
const point& p,
bool is_double_click
bool is_double_click,
unsigned long btn
)
{
if (is_double_click)
{
have_last_click = true;
last_clicked_point = p;
mouse_btn = btn;
clicked_signaler.signal();
}
}

View File

@ -3435,7 +3435,7 @@ namespace dlib
>
void set_image_clicked_handler (
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);
@ -3443,7 +3443,7 @@ namespace dlib
}
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);
@ -3532,7 +3532,7 @@ namespace dlib
std::string default_rect_label;
any_function<void()> 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;
point last_right_click_pos;
const int part_width;
@ -3563,6 +3563,7 @@ namespace dlib
gui_img(*this),
window_has_closed(false),
have_last_click(false),
mouse_btn(0),
clicked_signaler(this->wm)
{
gui_img.set_image_clicked_handler(*this, &image_window::on_image_clicked);
@ -3578,6 +3579,7 @@ namespace dlib
gui_img(*this),
window_has_closed(false),
have_last_click(false),
mouse_btn(0),
clicked_signaler(this->wm)
{
gui_img.set_image_clicked_handler(*this, &image_window::on_image_clicked);
@ -3744,15 +3746,17 @@ namespace dlib
);
bool get_next_double_click (
point& p
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 place the user clicked
!*/
bool get_next_double_click (
point& p
)
{
unsigned long mouse_button;
return get_next_double_click(p, mouse_btn);
}
private:
@ -3764,7 +3768,8 @@ namespace dlib
void on_image_clicked (
const point& p,
bool is_double_click
bool is_double_click,
unsigned long btn
);
// restricted functions
@ -3777,6 +3782,7 @@ namespace dlib
bool window_has_closed;
bool have_last_click;
point last_clicked_point;
unsigned long mouse_btn;
rsignaler clicked_signaler;
};

View File

@ -3024,12 +3024,27 @@ namespace dlib
);
/*!
ensures
- This function blocks until the user double left clicks on the image or
the window is closed by the user.
- 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.
!*/
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:
// restricted functions