Commit db6a0ba5 authored by Davis King's avatar Davis King

Made the on_wheel_down() and on_wheel_up() gui events take a new

argument that lets you know the status of any buttons currently
depressed

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402522
parent e2c891f6
...@@ -746,15 +746,26 @@ namespace dlib ...@@ -746,15 +746,26 @@ namespace dlib
else else
break; break;
unsigned long state = 0;
if (wParam & MK_CONTROL)
state |= base_window::CONTROL;
if (wParam & MK_LBUTTON)
state |= base_window::LEFT;
if (wParam & MK_MBUTTON)
state |= base_window::MIDDLE;
if (wParam & MK_RBUTTON)
state |= base_window::RIGHT;
if (wParam & MK_SHIFT)
state |= base_window::SHIFT;
// signal the mouse wheel event // signal the mouse wheel event
if (GET_WHEEL_DELTA_WPARAM(wParam) > 0) if (GET_WHEEL_DELTA_WPARAM(wParam) > 0)
{ {
win->on_wheel_up(); win->on_wheel_up(state);
} }
else else
{ {
win->on_wheel_down(); win->on_wheel_down(state);
} }
} }
......
...@@ -367,9 +367,11 @@ namespace dlib ...@@ -367,9 +367,11 @@ namespace dlib
){} ){}
virtual void on_wheel_up ( virtual void on_wheel_up (
unsigned long state
){} ){}
virtual void on_wheel_down ( virtual void on_wheel_down (
unsigned long state
){} ){}
virtual void on_focus_gained ( virtual void on_focus_gained (
......
...@@ -598,22 +598,22 @@ namespace dlib ...@@ -598,22 +598,22 @@ namespace dlib
else if (e->button == Button2) else if (e->button == Button2)
btn = base_window::MIDDLE; btn = base_window::MIDDLE;
unsigned long state = 0;
if (e->state & ControlMask)
state |= base_window::CONTROL;
if (e->state & Button1Mask)
state |= base_window::LEFT;
if (e->state & Button2Mask)
state |= base_window::MIDDLE;
if (e->state & Button3Mask)
state |= base_window::RIGHT;
if (e->state & ShiftMask)
state |= base_window::SHIFT;
// only send the event if this is a button we support // only send the event if this is a button we support
if (btn != (unsigned long)base_window::NONE) if (btn != (unsigned long)base_window::NONE)
{ {
unsigned long state = 0;
if (e->state & ControlMask)
state |= base_window::CONTROL;
if (e->state & Button1Mask)
state |= base_window::LEFT;
if (e->state & Button2Mask)
state |= base_window::MIDDLE;
if (e->state & Button3Mask)
state |= base_window::RIGHT;
if (e->state & ShiftMask)
state |= base_window::SHIFT;
if (ev.type == ButtonPress) if (ev.type == ButtonPress)
{ {
...@@ -651,11 +651,11 @@ namespace dlib ...@@ -651,11 +651,11 @@ namespace dlib
} }
else if (e->button == Button4 && ev.type == ButtonPress) else if (e->button == Button4 && ev.type == ButtonPress)
{ {
win->on_wheel_up(); win->on_wheel_up(state);
} }
else if (e->button == Button5 && ev.type == ButtonPress) else if (e->button == Button5 && ev.type == ButtonPress)
{ {
win->on_wheel_down(); win->on_wheel_down(state);
} }
} break; } break;
......
...@@ -365,9 +365,11 @@ namespace dlib ...@@ -365,9 +365,11 @@ namespace dlib
){} ){}
virtual void on_wheel_up ( virtual void on_wheel_up (
unsigned long state
){} ){}
virtual void on_wheel_down ( virtual void on_wheel_down (
unsigned long state
){} ){}
virtual void on_focus_gained ( virtual void on_focus_gained (
......
...@@ -692,24 +692,30 @@ namespace dlib ...@@ -692,24 +692,30 @@ namespace dlib
// do nothing by default // do nothing by default
virtual void on_wheel_up ( virtual void on_wheel_up (
unsigned long state
){} ){}
/*! /*!
requires requires
- is_closed() == false - is_closed() == false
- mutex wm is locked - mutex wm is locked
- is called every time the mouse wheel is scrolled up one notch - is called every time the mouse wheel is scrolled up one notch
- state == the bitwise OR of the buttons that are currently depressed
(from the mouse_state_masks enum)
ensures ensures
- does not change the state of mutex wm - does not change the state of mutex wm
!*/ !*/
// do nothing by default // do nothing by default
virtual void on_wheel_down ( virtual void on_wheel_down (
unsigned long state
){} ){}
/*! /*!
requires requires
- is_closed() == false - is_closed() == false
- mutex wm is locked - mutex wm is locked
- is called every time the mouse wheel is scrolled down one notch - is called every time the mouse wheel is scrolled down one notch
- state == the bitwise OR of the buttons that are currently depressed
(from the mouse_state_masks enum)
ensures ensures
- does not change the state of mutex wm - does not change the state of mutex wm
!*/ !*/
......
...@@ -2477,6 +2477,7 @@ namespace dlib ...@@ -2477,6 +2477,7 @@ namespace dlib
// ----------- event handlers --------------- // ----------- event handlers ---------------
void on_wheel_down ( void on_wheel_down (
unsigned long state
) )
{ {
// zoom out // zoom out
...@@ -2493,6 +2494,7 @@ namespace dlib ...@@ -2493,6 +2494,7 @@ namespace dlib
} }
void on_wheel_up ( void on_wheel_up (
unsigned long state
) )
{ {
// zoom in // zoom in
...@@ -3016,6 +3018,7 @@ namespace dlib ...@@ -3016,6 +3018,7 @@ namespace dlib
} }
void on_wheel_down ( void on_wheel_down (
unsigned long state
) )
{ {
if (rect.contains(lastx,lasty) && enabled && !hidden) if (rect.contains(lastx,lasty) && enabled && !hidden)
...@@ -3036,6 +3039,7 @@ namespace dlib ...@@ -3036,6 +3039,7 @@ namespace dlib
} }
void on_wheel_up ( void on_wheel_up (
unsigned long state
) )
{ {
if (rect.contains(lastx,lasty) && enabled && !hidden) if (rect.contains(lastx,lasty) && enabled && !hidden)
......
...@@ -1542,8 +1542,8 @@ namespace dlib ...@@ -1542,8 +1542,8 @@ namespace dlib
// event for your own reasons (e.g. to override the mouse drag this object // event for your own reasons (e.g. to override the mouse drag this object
// performs) // performs)
void on_wheel_down (); void on_wheel_down (unsigned long state);
void on_wheel_up (); void on_wheel_up (unsigned long state);
void on_mouse_move ( unsigned long state, long x, long y); void on_mouse_move ( unsigned long state, long x, long y);
void on_mouse_up ( unsigned long btn, unsigned long state, long x, long y); void on_mouse_up ( unsigned long btn, unsigned long state, long x, long y);
void on_mouse_down ( unsigned long btn, unsigned long state, long x, long y, bool is_double_click); void on_mouse_down ( unsigned long btn, unsigned long state, long x, long y, bool is_double_click);
...@@ -1756,8 +1756,8 @@ namespace dlib ...@@ -1756,8 +1756,8 @@ namespace dlib
// event for your own reasons (e.g. to override the mouse wheel action // event for your own reasons (e.g. to override the mouse wheel action
// this object performs) // this object performs)
void on_wheel_down (); void on_wheel_down (unsigned long state);
void on_wheel_up (); void on_wheel_up (unsigned long state);
void draw (const canvas& c) const; void draw (const canvas& c) const;
private: private:
......
...@@ -298,6 +298,7 @@ namespace dlib ...@@ -298,6 +298,7 @@ namespace dlib
void drawable_window:: void drawable_window::
on_wheel_up ( on_wheel_up (
unsigned long state
) )
{ {
++event_id; ++event_id;
...@@ -307,7 +308,7 @@ namespace dlib ...@@ -307,7 +308,7 @@ namespace dlib
if (mouse_wheel.element()->event_id != event_id) if (mouse_wheel.element()->event_id != event_id)
{ {
mouse_wheel.element()->event_id = event_id; mouse_wheel.element()->event_id = event_id;
mouse_wheel.element()->on_wheel_up(); mouse_wheel.element()->on_wheel_up(state);
} }
} }
} }
...@@ -316,6 +317,7 @@ namespace dlib ...@@ -316,6 +317,7 @@ namespace dlib
void drawable_window:: void drawable_window::
on_wheel_down ( on_wheel_down (
unsigned long state
) )
{ {
++event_id; ++event_id;
...@@ -325,7 +327,7 @@ namespace dlib ...@@ -325,7 +327,7 @@ namespace dlib
if (mouse_wheel.element()->event_id != event_id) if (mouse_wheel.element()->event_id != event_id)
{ {
mouse_wheel.element()->event_id = event_id; mouse_wheel.element()->event_id = event_id;
mouse_wheel.element()->on_wheel_down(); mouse_wheel.element()->on_wheel_down(state);
} }
} }
} }
......
...@@ -132,9 +132,11 @@ namespace dlib ...@@ -132,9 +132,11 @@ namespace dlib
); );
void on_wheel_up ( void on_wheel_up (
unsigned long state
); );
void on_wheel_down ( void on_wheel_down (
unsigned long state
); );
void on_focus_gained ( void on_focus_gained (
...@@ -486,9 +488,11 @@ namespace dlib ...@@ -486,9 +488,11 @@ namespace dlib
){} ){}
virtual void on_wheel_up ( virtual void on_wheel_up (
unsigned long state
){} ){}
virtual void on_wheel_down ( virtual void on_wheel_down (
unsigned long state
){} ){}
virtual void on_focus_gained ( virtual void on_focus_gained (
......
...@@ -608,6 +608,7 @@ namespace dlib ...@@ -608,6 +608,7 @@ namespace dlib
!*/ !*/
virtual void on_wheel_up ( virtual void on_wheel_up (
unsigned long state
){} ){}
/*! /*!
requires requires
...@@ -620,6 +621,7 @@ namespace dlib ...@@ -620,6 +621,7 @@ namespace dlib
!*/ !*/
virtual void on_wheel_down ( virtual void on_wheel_down (
unsigned long state
){} ){}
/*! /*!
requires requires
......
...@@ -2804,6 +2804,7 @@ namespace dlib ...@@ -2804,6 +2804,7 @@ namespace dlib
template <typename S> template <typename S>
void list_box<S>:: void list_box<S>::
on_wheel_up ( on_wheel_up (
unsigned long state
) )
{ {
if (rect.contains(lastx,lasty) && enabled && !hidden) if (rect.contains(lastx,lasty) && enabled && !hidden)
...@@ -2823,6 +2824,7 @@ namespace dlib ...@@ -2823,6 +2824,7 @@ namespace dlib
template <typename S> template <typename S>
void list_box<S>:: void list_box<S>::
on_wheel_down ( on_wheel_down (
unsigned long state
) )
{ {
if (rect.contains(lastx,lasty) && enabled && !hidden) if (rect.contains(lastx,lasty) && enabled && !hidden)
......
...@@ -1575,9 +1575,11 @@ namespace dlib ...@@ -1575,9 +1575,11 @@ namespace dlib
!*/ !*/
void on_wheel_up ( void on_wheel_up (
unsigned long state
); );
void on_wheel_down ( void on_wheel_down (
unsigned long state
); );
void on_mouse_down ( void on_mouse_down (
......
...@@ -40,7 +40,7 @@ public: ...@@ -40,7 +40,7 @@ public:
unsigned char green_, unsigned char green_,
unsigned char blue_ unsigned char blue_
) : ) :
dragable(w), dragable(w, MOUSE_WHEEL),
red(red_), red(red_),
green(green_), green(green_),
blue(blue_), blue(blue_),
...@@ -80,6 +80,45 @@ private: ...@@ -80,6 +80,45 @@ private:
} }
} }
void on_wheel_up(
unsigned long state
)
{
if (state == base_window::NONE)
cout << "up scroll, NONE" << endl;
else if (state&base_window::LEFT)
cout << "up scroll, LEFT" << endl;
else if (state&base_window::RIGHT)
cout << "up scroll, RIGHT" << endl;
else if (state&base_window::MIDDLE)
cout << "up scroll, MIDDLE" << endl;
else if (state&base_window::SHIFT)
cout << "up scroll, SHIFT" << endl;
else if (state&base_window::CONTROL)
cout << "up scroll, CONTROL" << endl;
}
void on_wheel_down(
unsigned long state
)
{
if (state == base_window::NONE)
cout << "down scroll, NONE" << endl;
else if (state&base_window::LEFT)
cout << "down scroll, LEFT" << endl;
else if (state&base_window::RIGHT)
cout << "down scroll, RIGHT" << endl;
else if (state&base_window::MIDDLE)
cout << "down scroll, MIDDLE" << endl;
else if (state&base_window::SHIFT)
cout << "down scroll, SHIFT" << endl;
else if (state&base_window::CONTROL)
cout << "down scroll, CONTROL" << endl;
}
void on_window_resized () void on_window_resized ()
{ {
...@@ -645,6 +684,8 @@ private: ...@@ -645,6 +684,8 @@ private:
} }
void on_click ( void on_click (
) )
{ {
......
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