/**\brief Generic mouse down function. */ bool UIContainer::MouseLDown( int xi, int yi ) { // Relative coordinate - to current widget int xr = xi - this->x; int yr = yi - this->y; // update drag coordinates in case this is draggable dragX = xr; dragY = yr; Widget *event_on = DetermineMouseFocus( xr, yr ); if( !event_on ){ //LogMsg(INFO,"Mouse Left down detect in %s.",this->name.c_str()); // Nothing was clicked on if( this->keyboardFocus ) this->keyboardFocus->KeyboardLeave(); this->keyboardFocus = NULL; return this->mouseHandled; } // We clicked on a widget event_on->MouseLDown( xr, yr ); this->lmouseDown = event_on; if( !this->keyboardFocus ) // No widget had keyboard focus before event_on->KeyboardEnter(); else if( this->keyboardFocus != event_on ){ // keyboard focus changed this->keyboardFocus->KeyboardLeave(); event_on->KeyboardEnter(); } this->keyboardFocus = event_on; return true; }
/**\brief Generic mouse wheel down function. */ bool UIContainer::MouseWDown( int xi, int yi ){ // Relative coordinate - to current widget int xr = xi - this->x; int yr = yi - this->y; Widget *event_on = DetermineMouseFocus( xr, yr ); if( event_on ) return event_on->MouseWDown( xr,yr ); //LogMsg(INFO,"Mouse Wheel down detect in %s.",this->name.c_str()); return this->mouseHandled; }
/**\brief Generic right mouse down function. */ bool Container::MouseRDown( int xi, int yi ){ // Relative coordinate - to current widget int xr = xi - this->x; int yr = yi - this->y; int yoffset = this->vscrollbar ? this->vscrollbar->pos : 0; Widget *event_on = DetermineMouseFocus( xr, yr ); if( event_on ){ this->rmouseDown=event_on; return event_on->MouseRDown( xr, yr + yoffset ); } //LogMsg(INFO,"Mouse Right down detect in %s.",this->name.c_str()); return this->mouseHandled; }
/**\brief Generic mouse wheel down function. */ bool Container::MouseWDown( int xi, int yi ){ // Relative coordinate - to current widget int xr = xi - this->x; int yr = yi - this->y; int yoffset = this->vscrollbar ? this->vscrollbar->pos : 0; Widget *event_on = DetermineMouseFocus( xr, yr ); if( event_on && event_on->MouseWDown( xr,yr + yoffset ) ) { return true; } if( vscrollbar ) { vscrollbar->ScrollDown(); return true; } //LogMsg(INFO,"Mouse Wheel down detect in %s.",this->name.c_str()); return false; }
/**\brief Generic right mouse up function. */ bool UIContainer::MouseRUp( int xi, int yi ){ // Relative coordinate - to current widget int xr = xi - this->x; int yr = yi - this->y; Widget *event_on = DetermineMouseFocus( xr, yr ); if( this->rmouseDown ){ if ( this->rmouseDown == event_on ){ // Mouse up is on the same widget as mouse down, send event this->rmouseDown = NULL; return event_on->MouseRUp( xr, yr ); }else{ // Mouse up is on a different widget, send release event to old this->rmouseDown->MouseRRelease(); this->rmouseDown = NULL; } } //LogMsg(INFO,"Mouse Right up detect in %s.",this->name.c_str()); return this->mouseHandled; }
/**\brief Mouse is currently moving over the widget, without button down. */ bool Container::MouseMotion( int xi, int yi ){ // Relative coordinate - to current widget int xr = xi - this->x; int yr = yi - this->y; int yoffset = this->vscrollbar ? this->vscrollbar->pos : 0; Widget *event_on = DetermineMouseFocus( xr, yr ); if ( this->lmouseDown ){ // Mouse button is held down, send drag event this->lmouseDown->MouseDrag(xr,yr); } if( !event_on ){ // Not on a widget if( this->mouseHover ){ // We were on a widget, send leave event this->mouseHover->MouseLeave(); this->mouseHover=NULL; } return this->mouseHandled; } if( !this->mouseHover ){ // We're on a widget, but nothing was hovered on before // send enter event only event_on->MouseEnter( xr,yr + yoffset ); this->mouseHover=event_on; return true; } if( this->mouseHover != event_on ){ // We're on a widget, and leaving another widget // send both enter and leave event this->mouseHover->MouseLeave(); event_on->MouseEnter( xr,yr + yoffset ); this->mouseHover=event_on; } event_on->MouseMotion( xr, yr + yoffset ); return true; }
/**\brief Generic mouse up function. */ bool Container::MouseLUp( int xi, int yi ){ // Relative coordinate - to current widget int xr = xi - this->x; int yr = yi - this->y; int yoffset = this->vscrollbar ? this->vscrollbar->pos : 0; Widget *event_on = DetermineMouseFocus( xr, yr ); if( this->lmouseDown ){ if (this->lmouseDown == event_on) { // Mouse up is on the same widget as the mouse down, send up event event_on->MouseLUp( xr,yr + yoffset ); this->lmouseDown = NULL; return true; }else{ // Mouse up is on a different widget, send release event to old this->lmouseDown->MouseLRelease(); this->lmouseDown = NULL; } } //LogMsg(INFO,"Mouse Left up detect in %s.",this->name.c_str()); return this->mouseHandled; }
// list of events is passed from main input handler. we remove the events we handle and leave the rest to be handled // by the next input handler. the order of input handlers is in input.cpp void UI::HandleInput( list<InputEvent> & events ) { // Go through all input events to see if they apply to any top-level widget. top-level widgets // (like windows) will then take the input and pass it to any children (like the ok button in the window) // where appropriate list<InputEvent>::iterator i = events.begin(); while( i != events.end() ) { bool eventWasHandled = false; switch( i->type ) { case KEY: switch(i->kstate) { case KEYTYPED: if( keyboardFocus ) { bool handled = keyboardFocus->KeyPress( i->key ); // if the input was handled, we need to remove it from the queue so no other // subsystem sees it and acts on it if( handled ) { events.erase(i); i = events.begin(); } } break; default: break; } break; case MOUSE: int x, y; // mouse coordinates associated with the mouse event x = i->mx; y = i->my; switch(i->mstate) { case MOUSEMOTION: // if a widget has mouse focus, we are dragging if( mouseFocus ) { int dx, dy; // original point of click for the drag dx = mouseFocus->GetDragX(); dy = mouseFocus->GetDragY(); mouseFocus->SetX( x - dx ); mouseFocus->SetY( y - dy ); eventWasHandled = true; } break; case MOUSEUP: // release focus if needed if( mouseFocus ) { // let the focused widget know it's no longer focused mouseFocus->UnfocusMouse(); mouseFocus = NULL; eventWasHandled = true; } break; case MOUSEDOWN: Widget *focusedWidget = DetermineMouseFocus( x, y ); // did they click a different widget than the one already in focus? if( mouseFocus != focusedWidget ) { // A new widget now has focus if( mouseFocus ) mouseFocus->UnfocusMouse(); mouseFocus = focusedWidget; if( mouseFocus ) { mouseFocus->FocusMouse( x - mouseFocus->GetX(), y - mouseFocus->GetY() ); } } // mouse down also changes keyboard focus (e.g. clicked on a new text field) if( keyboardFocus != focusedWidget ) { if( keyboardFocus ) keyboardFocus->UnfocusKeyboard(); keyboardFocus = focusedWidget; if( keyboardFocus ) { keyboardFocus->FocusKeyboard(); } } // pass the event to the widget if( mouseFocus ) { mouseFocus->MouseDown( x - mouseFocus->GetX(), y - mouseFocus->GetY() ); eventWasHandled = true; } break; } break; } if( eventWasHandled ) { i = events.erase( i ); } else { i++; } } }