void UXViewport::Iconify() { guard(UXViewport::Iconify); if (Iconified) return; Iconified = true; // Pause the game if applicable. if( GIsRunning ) Exec( TEXT("SETPAUSE 1"), *this ); // Release the mouse. SetMouseCapture( 0, 0, 0 ); SetDrag( 0 ); // Reset the input buffer. Input->ResetInput(); // End fullscreen. if( BlitFlags & BLIT_Fullscreen ) EndFullscreen(); GetOuterUClient()->MakeCurrent( NULL ); // Turn auto repeat back on. XAutoRepeatOn( XDisplay ); // Iconify the window. XIconifyWindow( XDisplay, XWindow, DefaultScreen(XDisplay) ); unguard; }
void DesktopWindowManager::StartResizeDrag( view::Widget* widget, const gfx::Point& point, int hittest_code) { DCHECK(!window_controller_.get()); DCHECK(!HasMouseCapture()); if(!widget->IsMaximized() && !widget->IsMinimized() && (widget->widget_delegate() || widget->widget_delegate()->CanResize())) { SetMouseCapture(); window_controller_.reset(new ResizeWindowController(widget)); } }
bool DesktopWindowManager::SetMouseCapture(view::Widget* widget) { if(mouse_capture_) { return false; } if(mouse_capture_ == widget) { return true; } DCHECK(!HasMouseCapture()); SetMouseCapture(); mouse_capture_ = widget; return true; }
void DesktopWindowManager::StartMoveDrag( view::Widget* widget, const gfx::Point& point) { DCHECK(!window_controller_.get()); DCHECK(!HasMouseCapture()); if(!widget->IsMaximized() && !widget->IsMinimized()) { gfx::Point new_point = point; if(desktop_->non_client_view()) { gfx::Rect client = desktop_->non_client_view()->frame_view()-> GetBoundsForClientView(); new_point.Offset(client.x(), client.y()); } SetMouseCapture(); window_controller_.reset(new MoveWindowController(widget, new_point)); } }
void cbRowDragPlugin::OnLButtonDown( cbLeftDownEvent& event ) { mpPane = event.mpPane; // DBG:: wxASSERT( !mDragStarted && !mDecisionMode ); if ( ItemIsInFocus() ) { mDecisionMode = true; wxPoint pos = event.mPos; mpPane->PaneToFrame( &pos.x, &pos.y ); mDragOrigin = pos; SetMouseCapture( true ); } else // propagate event to other plugins event.Skip(); }
void cbRowDragPlugin::OnLButtonUp ( cbLeftUpEvent& event ) { if ( !mDragStarted && !mDecisionMode ) { event.Skip(); return; } mpPane = event.mpPane; if ( mDecisionMode ) { cbDockPane* pPane = mpPane; SetMouseCapture( false ); mDecisionMode = false; mDragStarted = false; wxPoint frmPos = event.mPos; pPane->PaneToFrame( &frmPos.x, &frmPos.y ); if ( mpRowInFocus ) { CollapseRow( mpRowInFocus ); mpRowInFocus = 0; } else { ExpandRow( mCollapsedIconInFocus ); mCollapsedIconInFocus = -1; } mpRowInFocus = NULL; mpPane = pPane; pPane->FrameToPane( &frmPos.x, &frmPos.y ); // give it another try after relayouting bars cbMotionEvent moveEvt( frmPos, pPane ); this->OnMouseMove( moveEvt ); // this plugin has "eaten" the mouse-up event return; } else { // otherwise, the dragged row was dropped, determine // where to insert it // restore initial pane appearence ShowPaneImage(); FinishOnScreenDraw(); cbRowInfo* pRow = GetFirstRow(); mpLayout->GetUpdatesManager().OnStartChanges(); pRow->mUMgrData.SetDirty(true); cbBarInfo* pBar = mpRowInFocus->mBars[0]; while ( pBar ) { pBar->mUMgrData.SetDirty(true); if ( pBar->mpBarWnd ) { // do complete refresh pBar->mpBarWnd->Show(false); pBar->mpBarWnd->Show(true); } pBar = pBar->mpNext; } while( pRow ) { if ( mCurDragOfs < pRow->mRowY ) { InsertDraggedRowBefore( pRow ); break; } pRow = pRow->mpNext; } if ( pRow == NULL ) InsertDraggedRowBefore( NULL ); mpRowInFocus = NULL; mpLayout->RecalcLayout(false); // finish change "transaction" mpLayout->GetUpdatesManager().OnFinishChanges(); mpLayout->GetUpdatesManager().UpdateNow(); // finish drag action SetMouseCapture( false ); mDragStarted = false; } }
// handlers for plugin events void cbRowDragPlugin::OnMouseMove( cbMotionEvent& event ) { // short-cuts wxPoint pos = event.mPos; mpPane = event.mpPane; mpPane->PaneToFrame( &pos.x, &pos.y ); if ( !mDragStarted ) { if ( mDecisionMode && mpRowInFocus ) { int ofs; if ( mpPane->IsHorizontal() ) ofs = pos.y - mDragOrigin.y; else ofs = pos.x - mDragOrigin.x; // check if the item was dragged sufficeintly // far, enough to consider that user really intends // to drag it if ( ofs >= MINIMAL_ROW_DRAG_OFS || ofs <= -MINIMAL_ROW_DRAG_OFS ) { // DBG:: //.wxPoint pos = event.mPos; //wxPoint drg = mDragOrigin; //int dif = event.mPos.x - mDragOrigin.x; mDragStarted = true; mDecisionMode = false; mDragOrigin = pos; PrepareForRowDrag(); return; } // this plugin "eats" all mouse input while item is dragged, return; } cbRowInfo* pRow = GetFirstRow(); bool focusFound = false; while( pRow ) { if ( HitTestRowDragHint( pRow, pos ) ) { CheckPrevItemInFocus( pRow, -1 ); SetMouseCapture( true ); focusFound = true; mpRowInFocus = pRow; mCollapsedIconInFocus = -1; break; } pRow = pRow->mpNext; } if ( !focusFound ) { int hrCnt = GetHRowsCountForPane( event.mpPane ); for( int i = 0; i != hrCnt; ++i ) { if ( HitTestCollapsedRowIcon( i, pos ) ) { CheckPrevItemInFocus( NULL, i ); SetMouseCapture( true ); focusFound = true; mCollapsedIconInFocus = i; mpRowInFocus = NULL; break; } } } if ( !focusFound && ItemIsInFocus() ) { // kill focus from item previously been in focus UnhighlightItemInFocus(); mpRowInFocus = NULL; mCollapsedIconInFocus = -1; SetMouseCapture( false ); } if ( !ItemIsInFocus() ) // delegate it to other plugins event.Skip(); } else { // otherwise mouse pointer moves, when dragging is started if ( mpPane->IsHorizontal() ) { // row is dragged up or down; ShowDraggedRow( pos.y - mDragOrigin.y ); } else { // row is dragged left or right ShowDraggedRow( pos.x - mDragOrigin.x ); } // this plugin "eats" all mouse input while item is dragged, } }
void UXViewport::Tick() { guard(UXViewport::Tick); UXClient* Client = GetOuterUXClient(); if (!XWindow) return; // Keyboard. EInputKey Key; KeySym LowerCase, UpperCase; // Mouse movement management. UBOOL MouseMoved; INT BaseX = SizeX/2; INT BaseY = SizeY/2; INT DX = 0, DY = 0; XEvent Event; while( XPending(XDisplay) ) { XNextEvent(XDisplay, &Event); switch( Event.type ) { case CreateNotify: // Window has been created. ViewportStatus = X_ViewportNormal; // Make this viewport current and update its title bar. GetOuterUClient()->MakeCurrent( this ); break; case DestroyNotify: // Window has been destroyed. if( BlitFlags & BLIT_Fullscreen ) EndFullscreen(); if( ViewportStatus == X_ViewportNormal ) { // Closed normally. ViewportStatus = X_ViewportClosing; delete this; } break; case Expose: // Redraw the window. break; case KeyPress: // Reset timer. RepeatTimer = appSeconds(); LastKey = True; // Get key code. Key = (EInputKey) XKeycodeToKeysym( XDisplay, Event.xkey.keycode, 0 ); XConvertCase( Key, &LowerCase, &UpperCase ); Key = (EInputKey) UpperCase; // Check the Keysym map. if (KeysymMap[Key] != 0) Key = (EInputKey) KeysymMap[Key]; // Send key to input system. CauseInputEvent( Key, IST_Press ); // Emulate WM_CHAR. // Check for shift modifier. if (Event.xkey.state & ShiftMask) { Key = (EInputKey) UpperCase; if (ShiftMaskMap[Key] != 0) Key = (EInputKey) ShiftMaskMap[Key]; } else Key = (EInputKey) LowerCase; if (Key == XK_BackSpace) Key = IK_Backspace; if (Key == XK_Tab) Key = IK_Tab; if (Key == XK_Return) Key = IK_Enter; if (WMCharMap[Key] == 1) { KeyRepeatMap[Key] = 1; Client->Engine->Key( this, Key ); } break; case KeyRelease: // Get key code. Key = (EInputKey) XKeycodeToKeysym( XDisplay, Event.xkey.keycode, 0 ); XConvertCase( Key, &LowerCase, &UpperCase ); Key = (EInputKey) UpperCase; // Check the Keysym map. if (KeysymMap[Key] != 0) Key = (EInputKey) KeysymMap[Key]; // Send key to input system. CauseInputEvent( Key, IST_Release ); // Release all types of this key. if (Key == XK_BackSpace) Key = IK_Backspace; if (Key == XK_Tab) Key = IK_Tab; if (Key == XK_Return) Key = IK_Enter; KeyRepeatMap[Key] = 0; KeyRepeatMap[ShiftMaskMap[Key]] = 0; KeyRepeatMap[ShiftMaskMap[(EInputKey) LowerCase]] = 0; KeyRepeatMap[(EInputKey) LowerCase] = 0; break; case ButtonPress: switch (Event.xbutton.button) { case 1: Key = IK_LeftMouse; break; case 2: Key = IK_MiddleMouse; break; case 3: Key = IK_RightMouse; break; case 4: Key = IK_MouseWheelUp; break; case 5: Key = IK_MouseWheelDown; break; } // Send to input system. CauseInputEvent( Key, IST_Press ); break; case ButtonRelease: switch (Event.xbutton.button) { case 1: Key = IK_LeftMouse; break; case 2: Key = IK_MiddleMouse; break; case 3: Key = IK_RightMouse; break; case 4: Key = IK_MouseWheelUp; break; case 5: Key = IK_MouseWheelDown; break; } // Send to input system. CauseInputEvent( Key, IST_Release ); break; case MotionNotify: MouseMoved = True; if (UseDGA) { if (abs(Event.xmotion.x_root) > 1) DX += Event.xmotion.x_root * 2; else DX += Event.xmotion.x_root; if (abs(Event.xmotion.y_root) > 1) DY += Event.xmotion.y_root * 2; else DY += Event.xmotion.y_root; } else { DX += Event.xmotion.x - BaseX; DY += Event.xmotion.y - BaseY; BaseX = Event.xmotion.x; BaseY = Event.xmotion.y; } break; case ResizeRequest: // Eventually resize and setres. break; case MapNotify: if (Iconified) { guard(Uniconify); Iconified = false; // Unpause the game if applicable. Exec( TEXT("SETPAUSE 0"), *this ); // Reset the input buffer. Input->ResetInput(); // Snag the mouse again. SetMouseCapture( 1, 1, 0 ); // Make this viewport current. GetOuterUClient()->MakeCurrent( this ); // Turn off that damn auto repeat. XAutoRepeatOff( XDisplay ); // Return to fullscreen. if( BlitFlags & BLIT_Fullscreen ) TryRenderDevice( TEXT("ini:Engine.Engine.GameRenderDevice"), INDEX_NONE, INDEX_NONE, ColorBytes, 1 ); unguard; } break; case UnmapNotify: if (!Iconified) Iconify(); break; case FocusIn: break; case FocusOut: Iconify(); break; } } if (Iconified) return; // Deliver mouse behavior to the engine. if (MouseMoved) { if (!UseDGA) { XWarpPointer(XDisplay, None, XWindow, 0, 0, 0, 0, SizeX/2, SizeY/2); // Clear out the warp. XEvent MouseEvent; while( XCheckWindowEvent(XDisplay, XWindow, ButtonMotionMask | PointerMotionMask, &MouseEvent) ) { // Do Nothing. } } // Send to input subsystem. if( DX ) CauseInputEvent( IK_MouseX, IST_Axis, +DX ); if( DY ) CauseInputEvent( IK_MouseY, IST_Axis, -DY ); } // Send WM_CHAR for down keys. if ( LastKey && (appSeconds() - RepeatTimer < 0.5) ) return; LastKey = False; if ( appSeconds() - RepeatTimer < 0.1 ) return; RepeatTimer = appSeconds(); for (INT i=0; i<256; i++) if (KeyRepeatMap[i] != 0) { if (i == IK_Backspace) { CauseInputEvent( i, IST_Press ); CauseInputEvent( i, IST_Release ); } else Client->Engine->Key( this, (EInputKey) i ); } unguard; }
// // Resize the viewport. // UBOOL UXViewport::ResizeViewport( DWORD NewBlitFlags, INT InNewX, INT InNewY, INT InNewColorBytes ) { guard(UXViewport::ResizeViewport); UXClient* Client = GetOuterUXClient(); debugf( TEXT("Resizing X viewport. X: %i Y: %i"), InNewX, InNewY ); // Remember viewport. UViewport* SavedViewport = NULL; if( Client->Engine->Audio && !GIsEditor && !(GetFlags() & RF_Destroyed) ) SavedViewport = Client->Engine->Audio->GetViewport(); // Accept default parameters. INT NewX = InNewX ==INDEX_NONE ? SizeX : InNewX; INT NewY = InNewY ==INDEX_NONE ? SizeY : InNewY; INT NewColorBytes = InNewColorBytes==INDEX_NONE ? ColorBytes : InNewColorBytes; // Default resolution handling. NewX = InNewX!=INDEX_NONE ? InNewX : (NewBlitFlags&BLIT_Fullscreen) ? Client->FullscreenViewportX : Client->WindowedViewportX; NewY = InNewX!=INDEX_NONE ? InNewY : (NewBlitFlags&BLIT_Fullscreen) ? Client->FullscreenViewportY : Client->WindowedViewportY; if( NewBlitFlags & BLIT_Fullscreen ) { // Changing to fullscreen. XResizeWindow(XDisplay, XWindow, NewX, NewY); // Grab mouse and keyboard. SetMouseCapture( 1, 1, 0 ); } else { // Changing to windowed mode. XResizeWindow(XDisplay, XWindow, NewX, NewY); // Set focus to us. XSetInputFocus(XDisplay, XWindow, RevertToNone, CurrentTime); // End mouse and keyboard grab. SetMouseCapture( 0, 0, 0 ); } // Update audio. if( SavedViewport && SavedViewport!=Client->Engine->Audio->GetViewport() ) Client->Engine->Audio->SetViewport( SavedViewport ); // Update the window. UpdateWindowFrame(); // Set new info. DWORD OldBlitFlags = BlitFlags; BlitFlags = NewBlitFlags & ~BLIT_ParameterFlags; SizeX = NewX; SizeY = NewY; ColorBytes = NewColorBytes ? NewColorBytes : ColorBytes; // Save info. if( RenDev && !GIsEditor ) { if( NewBlitFlags & BLIT_Fullscreen ) { if( NewX && NewY ) { Client->FullscreenViewportX = NewX; Client->FullscreenViewportY = NewY; } } else { if( NewX && NewY ) { Client->WindowedViewportX = NewX; Client->WindowedViewportY = NewY; } } Client->SaveConfig(); } return 1; unguard; }