nux-1.14.0
|
Public Member Functions | |
unsigned int | EventProcessor (Event &event, const Geometry &g, bool process_mouse_focus) |
bool | MouseIn () |
void | ForceMouseFocus (int x, int y, const Geometry &g) |
void | StopMouseFocus (int x, int y, const Geometry &g) |
void | ResetState () |
Reset the state machine to its initial configuration. | |
Public Attributes | |
bool | _has_mouse_focus |
bool | _previous_mouse_in |
bool | _current_mouse_in |
unsigned int | _state |
int | _mouse_positionx |
Last know mouse X coordinate inside the area. | |
int | _mouse_positiony |
Last know mouse Y coordinate inside the area. | |
int | _mouse_deltax |
Mouse DeltaX coordinate inside the area. | |
int | _mouse_deltay |
Mouse DeltaY coordinate inside the area. | |
bool | _initial_state |
Friends | |
class | InputArea |
class | WindowCompositor |
Definition at line 43 of file MouseHandler.h.
unsigned int nux::AreaEventProcessor::EventProcessor | ( | Event & | event, |
const Geometry & | g, | ||
bool | process_mouse_focus | ||
) |
Return the physical status of the mouse with regard to the area.
event | The event to process. |
geo | The geometry of the area. |
process_mouse_focus | This parameter should be true if it is allowed to change the mouse focus status. process_mouse_focus should be true only when the event has not been solved yet. |
Definition at line 63 of file MouseHandler.cpp.
References _mouse_deltax, _mouse_deltay, _mouse_positionx, _mouse_positiony, nux::AREA_MOUSE_STATUS_DOWN, nux::AREA_MOUSE_STATUS_ENTER, nux::AREA_MOUSE_STATUS_FOCUS, nux::AREA_MOUSE_STATUS_LEAVE, nux::AREA_MOUSE_STATUS_MOVE, and nux::AREA_MOUSE_STATUS_UP.
{ // preserve mouse focus state. bool has_mouse_focus = ((_state & AREA_MOUSE_STATUS_FOCUS) != 0) ? true : false; _state = AREA_MOUSE_STATUS_NONE; if (has_mouse_focus) _state |= AREA_MOUSE_STATUS_FOCUS; if (event.e_event == NUX_NO_EVENT) return _state; _previous_mouse_in = _current_mouse_in; int x, y, lo_x, hi_x, lo_y, hi_y; // Usually (e_x_root, e_y_root) is equal to (0, 0). In that case, (x, y) is the mouse coordinate // that refers to the top-left corner of the window. // If (e_x_root, e_y_root) is equal to the top left corner of this area in the window, // then (x, y) represent the coordinate of the mouse based on the top-left corner of this area. x = event.e_x - event.e_x_root; y = event.e_y - event.e_y_root; lo_x = geo.x; hi_x = geo.x + geo.GetWidth() - 1; lo_y = geo.y; hi_y = geo.y + geo.GetHeight() - 1; if ((event.e_x == -1) && (event.e_y == -1)) { // e_x == -1 and e_y == -1 are associated with some specific window events that have the mouse outside of any widget. // See WM_SETFOCUS, WM_KILLFOCUS, NUX_WINDOW_MOUSELEAVE _current_mouse_in = false; } else { _current_mouse_in = PT_IN_BOX (x, y, lo_x, hi_x, lo_y, hi_y); } if (_initial_state) { _initial_state = false; } else { if ( (_previous_mouse_in == true) && (_current_mouse_in == false) ) { _state |= AREA_MOUSE_STATUS_LEAVE; } if ( (_previous_mouse_in == false) && (_current_mouse_in == true) ) { _state |= AREA_MOUSE_STATUS_ENTER; } } if (_state & AREA_MOUSE_STATUS_ENTER) { _mouse_deltax = 0; _mouse_deltay = 0; } else { _mouse_deltax = x - _mouse_positionx; _mouse_deltay = y - _mouse_positiony; } _mouse_positionx = x; _mouse_positiony = y; if ((_current_mouse_in == false) && !(_state & AREA_MOUSE_STATUS_FOCUS)) { return _state; } if (process_mouse_focus == false) { return _state; } switch (event.e_event) { case NUX_MOUSE_PRESSED: case NUX_MOUSE_DOUBLECLICK: { if (_current_mouse_in) { _state |= AREA_MOUSE_STATUS_DOWN; _state |= AREA_MOUSE_STATUS_FOCUS; //SetMouseFocus (true); } } break; case NUX_MOUSE_RELEASED: { if (_state & AREA_MOUSE_STATUS_FOCUS) { _state |= AREA_MOUSE_STATUS_UP; _state &= ~AREA_MOUSE_STATUS_FOCUS; //SetMouseFocus (false); } } break; case NUX_MOUSE_MOVE: { _state |= AREA_MOUSE_STATUS_MOVE; } break; default: break; } return _state; }