# HG changeset patch # User Radek Brich # Date 1359573668 -3600 # Node ID 85a282b5e4fc83c6e8caeaf7eeaee98e6a6548af # Parent 6e065660075485e4c81031aacff895e975428a74 Add mousehover event (only SDL). diff -r 6e0656600754 -r 85a282b5e4fc demo_input.py --- a/demo_input.py Wed Jan 30 19:44:01 2013 +0100 +++ b/demo_input.py Wed Jan 30 20:21:08 2013 +0100 @@ -21,6 +21,7 @@ editbox.add_handler('mouseup', self.on_any_input) editbox.add_handler('mousewheel', self.on_any_input) editbox.add_handler('mousemove', self.on_any_input) + editbox.add_handler('mousehover', self.on_any_input) def on_any_input(self, ev): if ev.event_name == 'keypress' and ev.char == 'q': diff -r 6e0656600754 -r 85a282b5e4fc docs/events.rst --- a/docs/events.rst Wed Jan 30 19:44:01 2013 +0100 +++ b/docs/events.rst Wed Jan 30 20:21:08 2013 +0100 @@ -52,3 +52,19 @@ Normal events are propagated in top down order, to all children in each level, in order of child addition. Some events choose one or more of children for event propagation. In case of mouse events, child is chosen based on mouse cursor position. + +Standard events +--------------- + +* mousedown + - report button press (left, mdiddle, right) +* mouseup + - report button released +* mousemove + - report mouse position change (only when button pressed) + - for use in combination with mousedown, mouseup +* mousehover + - report mouse position change (only when all buttons released) +* mousewheel + - report wheel up, down (as buttons) + diff -r 6e0656600754 -r 85a282b5e4fc sdlterm/cython/sdlterm.pyx --- a/sdlterm/cython/sdlterm.pyx Wed Jan 30 19:44:01 2013 +0100 +++ b/sdlterm/cython/sdlterm.pyx Wed Jan 30 20:21:08 2013 +0100 @@ -28,6 +28,7 @@ int MOUSEDOWN int MOUSEUP int MOUSEMOVE + int MOUSEHOVER int MOUSEWHEEL int type @@ -92,6 +93,8 @@ # timeout return None event = self.event + if event.type == event.MOUSEHOVER: + return ('mousehover', 0, event.mouse.x, event.mouse.y) if event.type == event.MOUSEMOVE: return ('mousemove', 0, event.mouse.x, event.mouse.y, event.mouse.relx, event.mouse.rely) if event.type == event.MOUSEDOWN: diff -r 6e0656600754 -r 85a282b5e4fc sdlterm/src/sdlterm.cc --- a/sdlterm/src/sdlterm.cc Wed Jan 30 19:44:01 2013 +0100 +++ b/sdlterm/src/sdlterm.cc Wed Jan 30 20:21:08 2013 +0100 @@ -500,25 +500,29 @@ return true; case SDL_MOUSEMOTION: - if (sdl_event.motion.state == 0 || _mousemove_last_x == -1) - { - // do not report move events when no button is pressed - return false; - } - event.type = Event::MOUSEMOVE; event.mouse.x = sdl_event.motion.x / _screen.get_cell_width(); event.mouse.y = sdl_event.motion.y / _screen.get_cell_height(); - if (_mousemove_last_x != event.mouse.x || - _mousemove_last_y != event.mouse.y) + if (_mousemove_last_x == event.mouse.x && + _mousemove_last_y == event.mouse.y) + { + // mouse position did not change + return false; + } + if (sdl_event.motion.state == 0 || _mousemove_last_x == -1) { + // no button is pressed or last pos not initialized + event.type = Event::MOUSEHOVER; + } + else + { + // some button pressed + event.type = Event::MOUSEMOVE; event.mouse.relx = event.mouse.x - _mousemove_last_x; event.mouse.rely = event.mouse.y - _mousemove_last_y; - _mousemove_last_x = event.mouse.x; - _mousemove_last_y = event.mouse.y; - return true; } - // mouse position did not change - return false; + _mousemove_last_x = event.mouse.x; + _mousemove_last_y = event.mouse.y; + return true; default: // unknown event diff -r 6e0656600754 -r 85a282b5e4fc sdlterm/src/sdlterm.h --- a/sdlterm/src/sdlterm.h Wed Jan 30 19:44:01 2013 +0100 +++ b/sdlterm/src/sdlterm.h Wed Jan 30 20:21:08 2013 +0100 @@ -177,7 +177,7 @@ struct Event { - enum { QUIT, RESIZE, KEYPRESS, MOUSEDOWN, MOUSEUP, MOUSEMOVE, MOUSEWHEEL }; + enum { QUIT, RESIZE, KEYPRESS, MOUSEDOWN, MOUSEUP, MOUSEMOVE, MOUSEHOVER, MOUSEWHEEL }; int type; union diff -r 6e0656600754 -r 85a282b5e4fc tuikit/container.py --- a/tuikit/container.py Wed Jan 30 19:44:01 2013 +0100 +++ b/tuikit/container.py Wed Jan 30 20:21:08 2013 +0100 @@ -206,6 +206,9 @@ self.mousechild.emit('mousemove', child_ev) return True + def on_mousehover(self, ev): + self.cascade_mouse_event(ev) + def on_mousewheel(self, ev): self.cascade_mouse_event(ev) diff -r 6e0656600754 -r 85a282b5e4fc tuikit/widget.py --- a/tuikit/widget.py Wed Jan 30 19:44:01 2013 +0100 +++ b/tuikit/widget.py Wed Jan 30 20:21:08 2013 +0100 @@ -73,6 +73,7 @@ 'mousedown', MouseEvent, 'mouseup', MouseEvent, 'mousemove', MouseEvent, + 'mousehover', MouseEvent, 'mousewheel', MouseEvent, 'sizereq', Event, 'spotmove', Event,