void GuiFormCtrl::onMouseDown(const GuiEvent &event) { Point2I localClick = globalToLocalCoord(event.mousePoint); // If we're clicking in the header then resize if(localClick.y < mThumbSize.y) { mouseLock(); mDepressed = true; mMouseMovingWin = mCanMove; //update setUpdate(); } mOrigBounds = getBounds(); mMouseDownPosition = event.mousePoint; if (mMouseMovingWin ) { mouseLock(); } else { GuiControl *ctrl = findHitControl(localClick); if (ctrl && ctrl != this) ctrl->onMouseDown(event); } }
void GuiGradientCtrl::onMouseDown(const GuiEvent &event) { if (!mActive) return; mouseLock(this); if (mProfile->mCanKeyFocus) setFirstResponder(); if (mActive) onAction(); Point2I extent = getRoot()->getExtent(); Point2I resolution = getRoot()->getExtent(); GFXTexHandle bb( resolution.x, resolution.y, GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, avar("%s() - bb (line %d)", __FUNCTION__, __LINE__) ); Point2I tmpPt( event.mousePoint.x, event.mousePoint.y ); GFXTarget *targ = GFX->getActiveRenderTarget(); targ->resolveTo( bb ); GBitmap bmp( bb.getWidth(), bb.getHeight() ); bb.copyToBmp( &bmp ); ColorI tmp; bmp.getColor( event.mousePoint.x, event.mousePoint.y, tmp ); addColorRange( globalToLocalCoord(event.mousePoint), ColorF(tmp) ); mMouseDown = true; }
void GameScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { if(event->button()==Qt::LeftButton){ if(!backPackBar->isShow() && !inOpWidget){ if(!inSence){ inSence=true; mouseLock(); camera->bind(); startGame(); } else{ emit removeBlock(); } } } else if(event->button()==Qt::RightButton){ if(!backPackBar->isShow() && !inOpWidget){ if(inSence){ emit addBlock(); } } } else if(event->button() & Qt::MidButton){ //中间拾取 if(!backPackBar->isShow()){ if(inSence){ //...获得已选中方块的属性并传给物品栏 if(camera->getKeyPosition().y()>=0) itemBar->midBlock(world->getBlockIndex(world->getBlock(camera->getKeyPosition())->getId())); } } } QGraphicsScene::mousePressEvent(event); }
void GuiButtonBaseCtrl::onMouseDown(const GuiEvent &event) { if (! mActive) return; if (mProfile->mCanKeyFocus) setFirstResponder(); if (mProfile->mSoundButtonDown) SFX->playOnce(mProfile->mSoundButtonDown); mMouseDownPoint = event.mousePoint; mMouseDragged = false; if( mUseMouseEvents ) onMouseDown_callback(); //lock the mouse mouseLock(); mDepressed = true; // If we have a double click then execute the alt command. if ( event.mouseClickCount == 2 ) { onDoubleClick_callback(); execAltConsoleCallback(); } //update setUpdate(); }
void TextEdit::onMouseDown(const Event &event) { dragHit = false; //undo any block function blockStart = 0; blockEnd = 0; //find out where the cursor should be int pos = setCursorPos(event.ptMouse); //if the position is to the left if (pos == -1) cursorPos = 0; //else if the position is to the right else if (pos == -2) cursorPos = strlen(text); //else set the cursorPos else cursorPos = pos; //save the mouseDragPos mouseDragStart = cursorPos; //lock the mouse mouseLock(); //set the drag var dragHit = TRUE; //let the parent get the event Parent::onMouseDown(event); }
void GuiGradientSwatchCtrl::onMouseDown(const GuiEvent &event) { if (! mActive) return; if (mProfile->mCanKeyFocus) setFirstResponder(); //capture current bounds and mouse down position mOrigBounds = getBounds(); mMouseDownPosition = event.mousePoint; if(mUseMouseEvents) onMouseDown_callback(); //lock the mouse mouseLock(); mDepressed = true; // If we have a double click then execute the alt command. if ( event.mouseClickCount == 2 ) { onDoubleClick_callback(); execAltConsoleCallback(); } setUpdate(); }
/** * Construct a mouse driver instance. * * @copydoc FNPDMDRVCONSTRUCT */ DECLCALLBACK(int) Mouse::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags) { PDRVMAINMOUSE pData = PDMINS_2_DATA(pDrvIns, PDRVMAINMOUSE); LogFlow(("drvMainMouse_Construct: iInstance=%d\n", pDrvIns->iInstance)); PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns); /* * Validate configuration. */ if (!CFGMR3AreValuesValid(pCfg, "Object\0")) return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES; AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER, ("Configuration error: Not possible to attach anything to this driver!\n"), VERR_PDM_DRVINS_NO_ATTACH); /* * IBase. */ pDrvIns->IBase.pfnQueryInterface = Mouse::drvQueryInterface; pData->IConnector.pfnReportModes = Mouse::mouseReportModes; /* * Get the IMousePort interface of the above driver/device. */ pData->pUpPort = (PPDMIMOUSEPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMIMOUSEPORT_IID); if (!pData->pUpPort) { AssertMsgFailed(("Configuration error: No mouse port interface above!\n")); return VERR_PDM_MISSING_INTERFACE_ABOVE; } /* * Get the Mouse object pointer and update the mpDrv member. */ void *pv; int rc = CFGMR3QueryPtr(pCfg, "Object", &pv); if (RT_FAILURE(rc)) { AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc)); return rc; } pData->pMouse = (Mouse *)pv; /** @todo Check this cast! */ unsigned cDev; { AutoReadLock mouseLock(pData->pMouse COMMA_LOCKVAL_SRC_POS); for (cDev = 0; cDev < MOUSE_MAX_DEVICES; ++cDev) if (!pData->pMouse->mpDrv[cDev]) { pData->pMouse->mpDrv[cDev] = pData; break; } } if (cDev == MOUSE_MAX_DEVICES) return VERR_NO_MORE_HANDLES; return VINF_SUCCESS; }
void GameScene::mouseMove() { if(inSence){ QPoint dtPoint=gView->cursor().pos()-centerPoint; camera->sightMove(QPointF(dtPoint)); mouseLock(); } }
void GuiObjectView::onMouseDown( const GuiEvent &event ) { if( !mActive || !mVisible || !mAwake ) return; mMouseState = Rotating; mLastMousePoint = event.mousePoint; mouseLock(); }
void GameScene::continueGame() { hideBackPackBar(); inSence=true; mouseLock(); camera->bind(); startGame(); inOpWidget=false; opWidgetProxy->hide(); }
// Mouse Wheel Click void GuiMaterialPreview::onMiddleMouseDown(const GuiEvent &event) { if (!mActive || !mVisible || !mAwake) { return; } mMouseState = Panning; mLastMousePoint = event.mousePoint; mouseLock(); }
void ForestEditorCtrl::on3DMouseDown( const Gui3DMouseEvent &evt ) { if ( !mForest && !updateActiveForest( true ) ) return; if ( mTool ) mTool->on3DMouseDown( evt ); mouseLock(); }
void GuiTextEditSliderCtrl::onMouseDown(const GuiEvent &event) { // If we're not active then skip out. if ( !mActive || !mAwake || !mVisible ) { Parent::onMouseDown(event); return; } char txt[20]; Parent::getText(txt); mValue = dAtof(txt); mMouseDownTime = Sim::getCurrentTime(); GuiControl *parent = getParent(); if(!parent) return; Point2I camPos = event.mousePoint; Point2I point = parent->localToGlobalCoord(getPosition()); if(camPos.x > point.x + getExtent().x - 14) { if(camPos.y > point.y + (getExtent().y/2)) { mValue -=mIncAmount; mTextAreaHit = ArrowDown; mMulInc = -0.15f; } else { mValue +=mIncAmount; mTextAreaHit = ArrowUp; mMulInc = 0.15f; } checkRange(); setValue(); mouseLock(); // We should get the focus and set the // cursor to the start of the text to // mimic the standard Windows behavior. setFirstResponder(); mCursorPos = mBlockStart = mBlockEnd = 0; setUpdate(); return; } Parent::onMouseDown(event); }
/** * Destruct a mouse driver instance. * * @returns VBox status. * @param pDrvIns The driver instance data. */ DECLCALLBACK(void) Mouse::drvDestruct(PPDMDRVINS pDrvIns) { PDRVMAINMOUSE pData = PDMINS_2_DATA(pDrvIns, PDRVMAINMOUSE); LogFlow(("Mouse::drvDestruct: iInstance=%d\n", pDrvIns->iInstance)); PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns); if (pData->pMouse) { AutoWriteLock mouseLock(pData->pMouse COMMA_LOCKVAL_SRC_POS); for (unsigned cDev = 0; cDev < MOUSE_MAX_DEVICES; ++cDev) if (pData->pMouse->mpDrv[cDev] == pData) { pData->pMouse->mpDrv[cDev] = NULL; break; } } }
void GuiSplitContainer::onMouseDown( const GuiEvent &event ) { GuiContainer *firstPanel = dynamic_cast<GuiContainer*>(at(0)); GuiContainer *secondPanel = dynamic_cast<GuiContainer*>(at(1)); // This function will constrain the panels to their minExtents and update the mSplitPoint if ( firstPanel && secondPanel ) { mouseLock(); mDragging = true; RectI clientRect = getClientRect(); Point2I newDragPos = globalToLocalCoord( event.mousePoint ); solvePanelConstraints(newDragPos, firstPanel, secondPanel, clientRect); } }
void GuiPaneControl::onMouseDown(const GuiEvent &event) { if(!mCollapsable) return; Point2I localClick = globalToLocalCoord(event.mousePoint); // If we're clicking in the header then resize if(localClick.y < mThumbSize.y) { mouseLock(); mDepressed = true; //update setUpdate(); } }
void GuiSliderCtrl::onMouseDown(const GuiEvent &event) { if ( !mActive || !mAwake || !mVisible ) return; mouseLock(); setFirstResponder(); mDepressed = true; Point2I curMousePos = globalToLocalCoord( event.mousePoint ); F32 value; if (getWidth() >= getHeight()) value = F32(curMousePos.x-mShiftPoint) / F32(getWidth()-mShiftExtent)*(mRange.y-mRange.x) + mRange.x; else value = F32(curMousePos.y) / F32(getHeight())*(mRange.y-mRange.x) + mRange.x; _updateThumb( value, mSnap || ( event.modifier & SI_SHIFT ) ); }
void GuiTextEditCtrl::onMouseDown( const GuiEvent &event ) { if(!isActive()) return; mDragHit = false; // If we have a double click, select all text. Otherwise // act as before by clearing any selection. bool doubleClick = (event.mouseClickCount > 1); if(doubleClick) { selectAllText(); } else { //undo any block function mBlockStart = 0; mBlockEnd = 0; } //find out where the cursor should be S32 pos = calculateCursorPos( event.mousePoint ); // if the position is to the left if ( pos == -1 ) mCursorPos = 0; else if ( pos == -2 ) //else if the position is to the right mCursorPos = mTextBuffer.length(); else //else set the mCursorPos mCursorPos = pos; //save the mouseDragPos mMouseDragStart = mCursorPos; // lock the mouse mouseLock(); //set the drag var mDragHit = true; //let the parent get the event setFirstResponder(); }
//------------------------------------------------------------------------------ void GuiBubbleTextCtrl::onMouseDown(const GuiEvent &event) { if (mInAction) { popBubble(); return; } mDlg = new GuiControl(); AssertFatal(mDlg, "Failed to create the GuiControl for the BubbleTextCtrl"); mDlg->setDataField( StringTable->insert("profile"), NULL, "GuiModelessDialogProfile"); mDlg->setField("horizSizing", "width"); mDlg->setField("vertSizing", "height"); mDlg->setField("extent", "640 480"); mPopup = new GuiControl(); AssertFatal(mPopup, "Failed to create the GuiControl for the BubbleTextCtrl"); mPopup->setDataField( StringTable->insert("profile"), NULL, "GuiBubblePopupProfile"); mMLText = new GuiMLTextCtrl(); AssertFatal(mMLText, "Failed to create the GuiMLTextCtrl for the BubbleTextCtrl"); mMLText->setDataField( StringTable->insert("profile"), NULL, "GuiBubbleTextProfile"); mMLText->setField("position", "2 2"); mMLText->setField("extent", "296 51"); mMLText->setText((char*)mText,dStrlen(mText)); mMLText->registerObject(); mPopup->registerObject(); mDlg->registerObject(); mPopup->addObject(mMLText); mDlg->addObject(mPopup); mPopup->resize(event.mousePoint,Point2I(300,55)); getRoot()->pushDialogControl(mDlg,0); mouseLock(); mInAction = true; }
//-------------------------------------------------------------------------- void GuiColorPickerCtrl::onMouseDown(const GuiEvent &event) { if (!mActive) return; if (mDisplayMode == pDropperBackground) return; mouseLock(this); if (mProfile->mCanKeyFocus) setFirstResponder(); if (mActive && (mDisplayMode != pDropperBackground)) onAction(); // Update the picker cross position if (mDisplayMode != pPallet) setSelectorPos(globalToLocalCoord(event.mousePoint)); mMouseDown = true; }
void GuiDecoyCtrl::onMouseDown(const GuiEvent &event) { if ( !mVisible || !mAwake ) return; mouseLock(); if(mIsDecoy == true) { mVisible = false; GuiControl *parent = getParent(); Point2I localPoint = parent->globalToLocalCoord(event.mousePoint); GuiControl *tempControl = parent->findHitControl(localPoint); tempControl->onMouseDown(event); mVisible = true; } execConsoleCallback(); setUpdate(); }
void GuiRoadEditorCtrl::on3DMouseDown(const Gui3DMouseEvent & event) { if ( !isFirstResponder() ) setFirstResponder(); // Get the clicked terrain position. Point3F tPos; if ( !getTerrainPos( event, tPos ) ) return; mouseLock(); // Find any road / node at the clicked position. // TODO: handle overlapping roads/nodes somehow, cycle through them. DecalRoad *roadPtr = NULL; S32 closestNodeIdx = -1; F32 closestDist = F32_MAX; DecalRoad *closestNodeRoad = NULL; // First, find the closest node in any road to the clicked position. for ( SimSetIterator iter(mRoadSet); *iter; ++iter ) { roadPtr = static_cast<DecalRoad*>( *iter ); U32 idx; if ( roadPtr->getClosestNode( tPos, idx ) ) { Point3F nodePos = roadPtr->getNodePosition(idx); F32 dist = ( nodePos - tPos ).len(); if ( dist < closestDist ) { closestNodeIdx = idx; closestDist = dist; closestNodeRoad = roadPtr; } } } // // Second, determine if the screen-space node rectangle // contains the clicked position. bool nodeClicked = false; S32 clickedNodeIdx = -1; if ( closestNodeIdx != -1 ) { Point3F nodePos = closestNodeRoad->getNodePosition( closestNodeIdx ); Point3F temp; project( nodePos, &temp ); Point2I screenPos( temp.x, temp.y ); RectI nodeRect( screenPos - mNodeHalfSize, mNodeHalfSize * 2 ); nodeClicked = nodeRect.pointInRect( event.mousePoint ); if ( nodeClicked ) clickedNodeIdx = closestNodeIdx; } // // Determine the clickedRoad // DecalRoad *clickedRoadPtr = NULL; U32 insertNodeIdx = 0; if ( nodeClicked && (mSelRoad == NULL || closestNodeRoad == mSelRoad) ) { // If a node was clicked, the owning road is always // considered the clicked road. clickedRoadPtr = closestNodeRoad; } else { // check the selected road first if ( mSelRoad != NULL && mSelRoad->containsPoint( tPos, &insertNodeIdx ) ) { clickedRoadPtr = mSelRoad; nodeClicked = false; clickedNodeIdx = -1; } else { // Otherwise, we must ask each road if it contains // the clicked pos. for ( SimSetIterator iter(mRoadSet); *iter; ++iter ) { roadPtr = static_cast<DecalRoad*>( *iter ); if ( roadPtr->containsPoint( tPos, &insertNodeIdx ) ) { clickedRoadPtr = roadPtr; break; } } } } // shortcuts bool dblClick = ( event.mouseClickCount > 1 ); if( dblClick ) { if( mMode == mSelectRoadMode ) { setMode( mAddRoadMode, true ); return; } if( mMode == mAddNodeMode ) { // Delete the node attached to the cursor. deleteSelectedNode(); mMode = mAddRoadMode; return; } } //this check is here in order to bounce back from deleting a whole road with ctrl+z //this check places the editor back into addroadmode if ( mMode == mAddNodeMode ) { if ( !mSelRoad ) mMode = mAddRoadMode; } if ( mMode == mSelectRoadMode ) { // Did not click on a road or a node. if ( !clickedRoadPtr ) { setSelectedRoad( NULL ); setSelectedNode( -1 ); return; } // Clicked on a road that wasn't the currently selected road. if ( clickedRoadPtr != mSelRoad ) { setSelectedRoad( clickedRoadPtr ); setSelectedNode( -1 ); return; } // Clicked on a node in the currently selected road that wasn't // the currently selected node. if ( nodeClicked ) { setSelectedNode( clickedNodeIdx ); return; } // Clicked a position on the currently selected road // that did not contain a node. //U32 newNode = clickedRoadPtr->insertNode( tPos, mDefaultWidth, insertNodeIdx ); //setSelectedNode( newNode ); } else if ( mMode == mAddRoadMode ) { if ( nodeClicked && clickedRoadPtr ) { // A double-click on a node in Normal mode means set AddNode mode. if ( clickedNodeIdx == 0 ) { setSelectedRoad( clickedRoadPtr ); setSelectedNode( clickedNodeIdx ); mAddNodeIdx = clickedNodeIdx; mMode = mAddNodeMode; mSelNode = mSelRoad->insertNode( tPos, mDefaultWidth, mAddNodeIdx ); mIsDirty = true; return; } else if ( clickedNodeIdx == clickedRoadPtr->mNodes.size() - 1 ) { setSelectedRoad( clickedRoadPtr ); setSelectedNode( clickedNodeIdx ); mAddNodeIdx = U32_MAX; mMode = mAddNodeMode; mSelNode = mSelRoad->addNode( tPos, mDefaultWidth ); mIsDirty = true; setSelectedNode( mSelNode ); return; } } DecalRoad *newRoad = new DecalRoad; newRoad->mMaterialName = mMaterialName; newRoad->registerObject(); // Add to MissionGroup SimGroup *missionGroup; if ( !Sim::findObject( "MissionGroup", missionGroup ) ) Con::errorf( "GuiDecalRoadEditorCtrl - could not find MissionGroup to add new DecalRoad" ); else missionGroup->addObject( newRoad ); newRoad->insertNode( tPos, mDefaultWidth, 0 ); U32 newNode = newRoad->insertNode( tPos, mDefaultWidth, 1 ); // Always add to the end of the road, the first node is the start. mAddNodeIdx = U32_MAX; setSelectedRoad( newRoad ); setSelectedNode( newNode ); mMode = mAddNodeMode; // Disable the hover node while in addNodeMode, we // don't want some random node enlarged. mHoverNode = -1; // Grab the mission editor undo manager. UndoManager *undoMan = NULL; if ( !Sim::findObject( "EUndoManager", undoMan ) ) { Con::errorf( "GuiRoadEditorCtrl::on3DMouseDown() - EUndoManager not found!" ); return; } // Create the UndoAction. MECreateUndoAction *action = new MECreateUndoAction("Create Road"); action->addObject( newRoad ); // Submit it. undoMan->addAction( action ); //send a callback to script after were done here if one exists if ( isMethod( "onRoadCreation" ) ) Con::executef( this, "onRoadCreation" ); return; } else if ( mMode == mAddNodeMode ) { // Oops the road got deleted, maybe from an undo action? // Back to NormalMode. if ( mSelRoad ) { // A double-click on a node in Normal mode means set AddNode mode. if ( clickedNodeIdx == 0 ) { submitUndo( "Add Node" ); mAddNodeIdx = clickedNodeIdx; mMode = mAddNodeMode; mSelNode = mSelRoad->insertNode( tPos, mDefaultWidth, mAddNodeIdx ); mIsDirty = true; setSelectedNode( mSelNode ); return; } else { if( clickedRoadPtr && clickedNodeIdx == clickedRoadPtr->mNodes.size() - 1 ) { submitUndo( "Add Node" ); mAddNodeIdx = U32_MAX; mMode = mAddNodeMode; mSelNode = mSelRoad->addNode( tPos, mDefaultWidth ); mIsDirty = true; setSelectedNode( mSelNode ); return; } else { submitUndo( "Insert Node" ); // A single-click on empty space while in // AddNode mode means insert / add a node. //submitUndo( "Add Node" ); //F32 width = mSelRoad->getNodeWidth( mSelNode ); U32 newNode = mSelRoad->insertNode( tPos, mDefaultWidth, mAddNodeIdx); mIsDirty = true; setSelectedNode( newNode ); return; } } } } else if ( mMode == mInsertPointMode && mSelRoad != NULL) { if ( clickedRoadPtr == mSelRoad ) { F32 w0 = mSelRoad->getNodeWidth( insertNodeIdx ); F32 w1 = mSelRoad->getNodeWidth( insertNodeIdx + 1 ); F32 width = ( w0 + w1 ) * 0.5f; submitUndo( "Insert Node" ); U32 newNode = mSelRoad->insertNode( tPos, width, insertNodeIdx + 1); mIsDirty = true; setSelectedNode( newNode ); return; } } else if ( mMode == mRemovePointMode && mSelRoad != NULL) { if ( nodeClicked && clickedRoadPtr == mSelRoad ) { setSelectedNode( clickedNodeIdx ); deleteSelectedNode(); return; } } else if ( mMode == mMovePointMode ) { if ( nodeClicked && clickedRoadPtr == mSelRoad ) { setSelectedNode( clickedNodeIdx ); return; } } else if ( mMode == mScalePointMode ) { if ( nodeClicked && clickedRoadPtr == mSelRoad ) { setSelectedNode( clickedNodeIdx ); return; } } }
void GuiObjectView::onRightMouseDown( const GuiEvent &event ) { mMouseState = Zooming; mLastMousePoint = event.mousePoint; mouseLock(); }
// Left Click void GuiMaterialPreview::onMouseDown(const GuiEvent &event) { mMouseState = MovingLight; mLastMousePoint = event.mousePoint; mouseLock(); }
void EditTSCtrl::onRightMouseDown(const GuiEvent & event) { // always process the right mouse event first... mRightMouseDown = true; mLastBorderMoveTime = 0; make3DMouseEvent(mLastEvent, event); on3DRightMouseDown(mLastEvent); if(!mLeftMouseDown && mRightMousePassThru && mProfile->mCanKeyFocus) { GuiCanvas *pCanvas = getRoot(); if( !pCanvas ) return; PlatformWindow *pWindow = static_cast<GuiCanvas*>(getRoot())->getPlatformWindow(); if( !pWindow ) return; PlatformCursorController *pController = pWindow->getCursorController(); if( !pController ) return; // ok, gotta disable the mouse // script functions are lockMouse(true); Canvas.cursorOff(); pWindow->setMouseLocked(true); pCanvas->setCursorON( false ); if(mDisplayType != DisplayTypePerspective) { mouseLock(); mLastMousePos = event.mousePoint; pCanvas->setForceMouseToGUI(true); mLastMouseClamping = pCanvas->getClampTorqueCursor(); pCanvas->setClampTorqueCursor(false); } if(mDisplayType == DisplayTypeIsometric) { // Store the screen center point on the terrain for a possible rotation TerrainBlock* activeTerrain = getActiveTerrain(); if( activeTerrain ) { F32 extx, exty; if(event.modifier & SI_SHIFT) { extx = F32(event.mousePoint.x); exty = F32(event.mousePoint.y); } else { extx = getExtent().x * 0.5; exty = getExtent().y * 0.5; } Point3F sp(extx, exty, 0.0f); // Near plane projection Point3F start; unproject(sp, &start); Point3F end = start + mLastEvent.vec * 4000.0f; Point3F tStartPnt, tEndPnt; activeTerrain->getTransform().mulP(start, &tStartPnt); activeTerrain->getTransform().mulP(end, &tEndPnt); RayInfo info; bool result = activeTerrain->castRay(tStartPnt, tEndPnt, &info); if(result) { info.point.interpolate(start, end, info.t); mIsoCamRotCenter = info.point; } else { mIsoCamRotCenter = start; } } else { F32 extx = getExtent().x * 0.5; F32 exty = getExtent().y * 0.5; Point3F sp(extx, exty, 0.0f); // Near plane projection unproject(sp, &mIsoCamRotCenter); } } setFirstResponder(); } }
// Right Click void GuiMaterialPreview::onRightMouseDown(const GuiEvent &event) { mMouseState = Rotating; mLastMousePoint = event.mousePoint; mouseLock(); }
void GuiRolloutCtrl::onMouseDown( const GuiEvent &event ) { Point2I localPoint = globalToLocalCoord( event.mousePoint ); mouseLock(); }
void GameScene::keyPressEvent(QKeyEvent *event) { if(event->key()==Qt::Key_Escape){ if(inOpWidget){ continueGame(); } else if(backPackBar->isShow()){ hideBackPackBar(); inSence=true; mouseLock(); camera->bind(); startGame(); } else{ inSence=false; camera->unBind(); pauseGame(); mouseUnLock(); opWidgetProxy->show(); inOpWidget=true; } } else if(event->key()==Qt::Key_M){ if(inSence){ if(camera->getGameMode()==Camera::SURVIVAL) camera->setGameMode(Camera::GOD); else camera->setGameMode(Camera::SURVIVAL); } } else if(event->key()==Qt::Key_E){ if(backPackBar->isShow()){ hideBackPackBar(); inSence=true; mouseLock(); camera->bind(); startGame(); } else if(inSence){ showBackPackBar(); inSence=false; camera->unBind(); pauseGame(); mouseUnLock(); showMessage(tr("打开了物品栏"),2); } } else if(event->key()==Qt::Key_F2){ screenShots(); } else{ switch (event->key()) { case Qt::Key_1: itemBar->setIndex(0); break; case Qt::Key_2: itemBar->setIndex(1); break; case Qt::Key_3: itemBar->setIndex(2); break; case Qt::Key_4: itemBar->setIndex(3); break; case Qt::Key_5: itemBar->setIndex(4); break; case Qt::Key_6: itemBar->setIndex(5); break; case Qt::Key_7: itemBar->setIndex(6); break; case Qt::Key_8: itemBar->setIndex(7); break; case Qt::Key_9: itemBar->setIndex(8); break; default: camera->keyPress(event->key()); break; } } QGraphicsScene::keyPressEvent(event); }
void GuiRiverEditorCtrl::_process3DMouseDown( const Gui3DMouseEvent& event ) { // Get the raycast collision position Point3F tPos; if ( !getStaticPos( event, tPos ) ) return; mouseLock(); // Construct a LineSegment from the camera position to 1000 meters away in // the direction clicked. // If that segment hits the terrain, truncate the ray to only be that length. // We will use a LineSegment/Sphere intersection test to determine if a RiverNode // was clicked. Point3F startPnt = event.pos; Point3F endPnt = event.pos + event.vec * 1000.0f; RayInfo ri; if ( gServerContainer.castRay(startPnt, endPnt, StaticShapeObjectType, &ri) ) endPnt = ri.point; River *riverPtr = NULL; River *clickedRiverPtr = NULL; // Did we click on a river? check current selection first U32 insertNodeIdx = -1; Point3F collisionPnt; if ( mSelRiver != NULL && mSelRiver->collideRay( event.pos, event.vec, &insertNodeIdx, &collisionPnt ) ) { clickedRiverPtr = mSelRiver; } else { for ( SimSetIterator iter(mRiverSet); *iter; ++iter ) { riverPtr = static_cast<River*>( *iter ); // Do not select or edit a River within a Prefab. if ( Prefab::getPrefabByChild(riverPtr) ) continue; if ( riverPtr->collideRay( event.pos, event.vec, &insertNodeIdx, &collisionPnt ) ) { clickedRiverPtr = riverPtr; break; } } } // Did we click on a riverNode? bool nodeClicked = false; S32 clickedNodeIdx = -1; F32 clickedNodeDist = mNodeSphereRadius; // If we clicked on the currently selected river, only scan its nodes if ( mSelRiver != NULL && clickedRiverPtr == mSelRiver ) { for ( U32 i = 0; i < mSelRiver->mNodes.size(); i++ ) { const Point3F &nodePos = mSelRiver->mNodes[i].point; Point3F screenPos; project( nodePos, &screenPos ); F32 dist = ( event.mousePoint - Point2I(screenPos.x, screenPos.y) ).len(); if ( dist < clickedNodeDist ) { clickedNodeDist = dist; clickedNodeIdx = i; insertNodeIdx = i; nodeClicked = true; } } } else { for ( SimSetIterator iter(mRiverSet); *iter; ++iter ) { riverPtr = static_cast<River*>( *iter ); // Do not select or edit a River within a Prefab. if ( Prefab::getPrefabByChild(riverPtr) ) continue; for ( U32 i = 0; i < riverPtr->mNodes.size(); i++ ) { const Point3F &nodePos = riverPtr->mNodes[i].point; Point3F screenPos; project( nodePos, &screenPos ); F32 dist = ( event.mousePoint - Point2I(screenPos.x, screenPos.y) ).len(); if ( dist < clickedNodeDist ) { // we found a hit! clickedNodeDist = dist; clickedNodeIdx = i; insertNodeIdx = i; nodeClicked = true; clickedRiverPtr = riverPtr; } } } } // shortcuts bool dblClick = ( event.mouseClickCount > 1 ); if( dblClick ) { if( mMode == mSelectRiverMode ) { setMode( mAddRiverMode, true ); return; } if( mMode == mAddNodeMode ) { // Delete the node attached to the cursor. deleteSelectedNode(); mMode = mAddRiverMode; return; } } //this check is here in order to bounce back from deleting a whole road with ctrl+z //this check places the editor back into addrivermode if ( mMode == mAddNodeMode ) { if ( !mSelRiver ) mMode = mAddRiverMode; } if ( mMode == mSelectRiverMode ) { // Did not click on a River or a node. if ( !clickedRiverPtr ) { setSelectedRiver( NULL ); setSelectedNode( -1 ); return; } // Clicked on a River that wasn't the currently selected River. if ( clickedRiverPtr != mSelRiver ) { setSelectedRiver( clickedRiverPtr ); setSelectedNode( clickedNodeIdx ); return; } // Clicked on a node in the currently selected River that wasn't // the currently selected node. if ( nodeClicked ) { setSelectedNode( clickedNodeIdx ); return; } } else if ( mMode == mAddRiverMode ) { if ( nodeClicked ) { // A double-click on a node in Normal mode means set AddNode mode. if ( clickedNodeIdx == 0 ) { setSelectedRiver( clickedRiverPtr ); setSelectedNode( clickedNodeIdx ); mAddNodeIdx = clickedNodeIdx; mMode = mAddNodeMode; mSelNode = mSelRiver->insertNode( tPos, mDefaultWidth, mDefaultDepth, mDefaultNormal, mAddNodeIdx ); mIsDirty = true; return; } else if ( clickedNodeIdx == clickedRiverPtr->mNodes.size() - 1 ) { setSelectedRiver( clickedRiverPtr ); setSelectedNode( clickedNodeIdx ); mAddNodeIdx = U32_MAX; mMode = mAddNodeMode; mSelNode = mSelRiver->addNode( tPos, mDefaultWidth, mDefaultDepth, mDefaultNormal); mIsDirty = true; setSelectedNode( mSelNode ); return; } } if ( !isMethod( "createRiver" ) ) { Con::errorf( "GuiRiverEditorCtrl::on3DMouseDown - createRiver method does not exist." ); return; } const char *res = Con::executef( this, "createRiver" ); River *newRiver; if ( !Sim::findObject( res, newRiver ) ) { Con::errorf( "GuiRiverEditorCtrl::on3DMouseDown - createRiver method did not return a river object." ); return; } // Add to MissionGroup SimGroup *missionGroup; if ( !Sim::findObject( "MissionGroup", missionGroup ) ) Con::errorf( "GuiRiverEditorCtrl - could not find MissionGroup to add new River" ); else missionGroup->addObject( newRiver ); Point3F pos( endPnt ); pos.z += mDefaultDepth * 0.5f; newRiver->insertNode( pos, mDefaultWidth, mDefaultDepth, mDefaultNormal, 0 ); U32 newNode = newRiver->insertNode( pos, mDefaultWidth, mDefaultDepth, mDefaultNormal, 1 ); // Always add to the end of the road, the first node is the start. mAddNodeIdx = U32_MAX; setSelectedRiver( newRiver ); setSelectedNode( newNode ); mMode = mAddNodeMode; // Disable the hover node while in addNodeMode, we // don't want some random node enlarged. mHoverNode = -1; // Grab the mission editor undo manager. UndoManager *undoMan = NULL; if ( !Sim::findObject( "EUndoManager", undoMan ) ) { Con::errorf( "GuiMeshRoadEditorCtrl::on3DMouseDown() - EUndoManager not found!" ); return; } // Create the UndoAction. MECreateUndoAction *action = new MECreateUndoAction("Create MeshRoad"); action->addObject( newRiver ); // Submit it. undoMan->addAction( action ); return; } else if ( mMode == mAddNodeMode ) { // Oops the road got deleted, maybe from an undo action? // Back to NormalMode. if ( mSelRiver ) { // A double-click on a node in Normal mode means set AddNode mode. if ( clickedNodeIdx == 0 ) { submitUndo( "Add Node" ); mAddNodeIdx = clickedNodeIdx; mMode = mAddNodeMode; mSelNode = mSelRiver->insertNode( tPos, mDefaultWidth, mDefaultDepth, mDefaultNormal, mAddNodeIdx ); mIsDirty = true; setSelectedNode( mSelNode ); return; } else { if( clickedRiverPtr && clickedNodeIdx == clickedRiverPtr->mNodes.size() - 1 ) { submitUndo( "Add Node" ); mAddNodeIdx = U32_MAX; mMode = mAddNodeMode; U32 newNode = mSelRiver->addNode( tPos, mDefaultWidth, mDefaultDepth, mDefaultNormal); mIsDirty = true; setSelectedNode( newNode ); return; } else { submitUndo( "Insert Node" ); // A single-click on empty space while in // AddNode mode means insert / add a node. //submitUndo( "Add Node" ); //F32 width = mSelRiver->getNodeWidth( mSelNode ); U32 newNode = mSelRiver->insertNode( tPos, mDefaultWidth, mDefaultDepth, mDefaultNormal, mAddNodeIdx); mIsDirty = true; setSelectedNode( newNode ); return; } } } } else if ( mMode == mInsertPointMode && mSelRiver != NULL ) { if ( clickedRiverPtr == mSelRiver ) { // NOTE: I guess we have to determine the if the clicked ray intersects a road but not a specific node... // in order to handle inserting nodes in the same way as for DecalRoad U32 prevNodeIdx = insertNodeIdx; U32 nextNodeIdx = ( prevNodeIdx + 1 > mSelRiver->mNodes.size() - 1 ) ? prevNodeIdx : prevNodeIdx + 1; const RiverNode &prevNode = mSelRiver->mNodes[prevNodeIdx]; const RiverNode &nextNode = mSelRiver->mNodes[nextNodeIdx]; F32 width = ( prevNode.width + nextNode.width ) * 0.5f; F32 depth = ( prevNode.depth + nextNode.depth ) * 0.5f; Point3F normal = ( prevNode.normal + nextNode.normal ) * 0.5f; normal.normalize(); submitUndo( "Insert Node" ); U32 newNode = mSelRiver->insertNode( collisionPnt, width, depth, normal, insertNodeIdx + 1 ); mIsDirty = true; setSelectedNode( newNode ); return; } } else if ( mMode == mRemovePointMode && mSelRiver != NULL ) { if ( nodeClicked && clickedRiverPtr == mSelRiver ) { setSelectedNode( clickedNodeIdx ); deleteSelectedNode(); return; } } else if ( mMode == mMovePointMode ) { if ( nodeClicked && clickedRiverPtr == mSelRiver ) { setSelectedNode( clickedNodeIdx ); return; } } else if ( mMode == mScalePointMode ) { if ( nodeClicked && clickedRiverPtr == mSelRiver ) { setSelectedNode( clickedNodeIdx ); return; } } else if ( mMode == mRotatePointMode ) { if ( nodeClicked && clickedRiverPtr == mSelRiver ) { setSelectedNode( clickedNodeIdx ); return; } } }