Commit c26367a8 authored by Davis King's avatar Davis King

Added image_window::get_next_keypress()

parent 9dfcd9a5
......@@ -6480,6 +6480,51 @@ namespace dlib
return base_window::CLOSE_WINDOW;
}
// ----------------------------------------------------------------------------------------
bool image_window::
get_next_keypress (
unsigned long& key,
bool& is_printable,
unsigned long& state
)
{
auto_mutex lock(wm);
while (have_last_keypress == false && !window_has_closed)
{
clicked_signaler.wait();
}
if (window_has_closed)
return false;
// Mark that we are taking the key click so the next call to get_next_keypress()
// will have to wait for another click.
have_last_keypress = false;
key = next_key;
is_printable = next_is_printable;
state = next_state;
return true;
}
// ----------------------------------------------------------------------------------------
void image_window::
on_keydown (
unsigned long key,
bool is_printable,
unsigned long state
)
{
dlib::base_window::on_keydown(key,is_printable,state);
have_last_keypress = true;
next_key = key;
next_is_printable = is_printable;
next_state = state;
clicked_signaler.signal();
}
// ----------------------------------------------------------------------------------------
bool image_window::
......@@ -6497,8 +6542,8 @@ namespace dlib
if (window_has_closed)
return false;
// Mark that we are taking the point click so the next call to get_next_click()
// will have to wait for another click.
// Mark that we are taking the point click so the next call to
// get_next_double_click() will have to wait for another click.
have_last_click = false;
mouse_button = mouse_btn;
p = last_clicked_point;
......
......@@ -3564,7 +3564,8 @@ namespace dlib
window_has_closed(false),
have_last_click(false),
mouse_btn(0),
clicked_signaler(this->wm)
clicked_signaler(this->wm),
have_last_keypress(false)
{
gui_img.set_image_clicked_handler(*this, &image_window::on_image_clicked);
set_image(img);
......@@ -3580,7 +3581,8 @@ namespace dlib
window_has_closed(false),
have_last_click(false),
mouse_btn(0),
clicked_signaler(this->wm)
clicked_signaler(this->wm),
have_last_keypress(false)
{
gui_img.set_image_clicked_handler(*this, &image_window::on_image_clicked);
set_image(img);
......@@ -3758,6 +3760,21 @@ namespace dlib
return get_next_double_click(p, mouse_button);
}
bool get_next_keypress (
unsigned long& key,
bool& is_printable,
unsigned long& state
);
bool get_next_keypress (
unsigned long& key,
bool& is_printable
)
{
unsigned long state;
return get_next_keypress(key,is_printable,state);
}
private:
virtual base_window::on_close_return_code on_window_close(
......@@ -3772,6 +3789,12 @@ namespace dlib
unsigned long btn
);
virtual void on_keydown (
unsigned long key,
bool is_printable,
unsigned long state
);
// restricted functions
image_window(image_window&);
image_window& operator= (image_window&);
......@@ -3784,6 +3807,11 @@ namespace dlib
point last_clicked_point;
unsigned long mouse_btn;
rsignaler clicked_signaler;
bool have_last_keypress;
unsigned long next_key;
bool next_is_printable;
unsigned long next_state;
};
// ----------------------------------------------------------------------------------------
......
......@@ -3045,6 +3045,35 @@ namespace dlib
dlib::base_window::MIDDLE, or dlib::base_window::RIGHT
!*/
bool get_next_keypress (
unsigned long& key,
bool& is_printable,
unsigned long& state
);
/*!
ensures
- This function blocks until the user presses a keyboard key or the
window is closed by the user.
- if (this function returns true) then
- The keyboard button press is recorded into #key, #is_printable, and
#state. In particular, these variables are populated with the three
identically named arguments to the base_window::on_keydown(key,is_printable,state)
event.
!*/
bool get_next_keypress (
unsigned long& key,
bool& is_printable
);
/*!
ensures
- This function blocks until the user presses a keyboard key or the
window is closed by the user.
- This function is the equivalent to calling get_next_keypress(key,is_printable,temp)
and then discarding temp.
!*/
private:
// 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