void LevelEditor::CheckForSpriteScaling() { if (mSelectedObject) { static bool pressingScale = false; static Vector2 mouseStartPos = Vector2(0,0); static Vector2 originalDimensions = Vector2(0,0); if (!pressingScale && GetAsyncKeyState('X') < 0 && GetAsyncKeyState(VK_LBUTTON) < 0 && GetAsyncKeyState(VK_CONTROL) >= 0) { pressingScale = true; POINT currentMouse; GetCursorPos(¤tMouse); ScreenToClient(DXWindow::GetInstance()->Hwnd(), ¤tMouse); mouseStartPos = Vector2(currentMouse.x, currentMouse.y); originalDimensions = Vector2(mSelectedObject->Dimensions().X, mSelectedObject->Dimensions().Y); } else if (pressingScale && GetAsyncKeyState(VK_LBUTTON) < 0) { // get the initial distance between the game object and the mouse Vector2 origDistance = mouseStartPos - Vector2(mSelectedObject->X(), mSelectedObject->Y()); // origDistance = Vector2(abs(origDistance.X), abs(origDistance.Y)); float origLength = origDistance.Length(); // now get the distance between the current mouse position POINT currentMouse; GetCursorPos(¤tMouse); ScreenToClient(DXWindow::GetInstance()->Hwnd(), ¤tMouse); Vector2 newDistance = Vector2(currentMouse.x, currentMouse.y) - Vector2(mSelectedObject->X(), mSelectedObject->Y()); float newLength = newDistance.Length(); float scale = newLength / origLength; if (scale != 0) { mSelectedObject->SetDimensionsXYZ(originalDimensions.X * scale, originalDimensions.Y * scale, mSelectedObject->Dimensions().Z); Sprite * s = GetAsSprite(mSelectedObject); if (s) { s->ScaleSpriteOnly(scale, scale); s->SetIsNativeDimensions(false); s->ApplyChange(Graphics::GetInstance()->Device()); } } } if (GetAsyncKeyState('X') >= 0) { pressingScale = false; mouseStartPos = Vector2(0,0); originalDimensions = Vector2(0,0); } } }
void LevelEditor::CheckForSettingNativeRes() { if (mSelectedObject) { if (GetAsyncKeyState('N') < 0 && GetAsyncKeyState(VK_CONTROL) < 0) { Sprite * s = GetAsSprite(mSelectedObject); if (s) { s->SetIsNativeDimensions(true); s->ScaleSpriteOnly(1,1); // resets vertices and debug bounding box s->ApplyChange(Graphics::GetInstance()->Device()); } } } }
void LevelEditor::CheckInput_Regular() { list<shared_ptr<GameObject> > & gameObjects = GameObjectManager::Instance()->GetGameObjectList(); static bool pressingSelect = false; static bool pressingPlace = false; if (mSelectedObject) { if (!pressingSelect && GetAsyncKeyState(VK_RBUTTON) < 0 && GetAsyncKeyState('R') >= 0) { GameObject * obj = GetGameObjectClickedOn(gameObjects); if (obj) { if (obj == mSelectedObject) { // deselect mSelectedObject->ShowDebugText(false); mSelectedObject->SetLevelEditShowSelected(false); mSelectedObject = nullptr; } else { mSelectedObject->ShowDebugText(false); mSelectedObject->SetLevelEditShowSelected(false); mSelectedObject = obj; mSelectedObject->ShowDebugText(true); mSelectedObject->SetLevelEditShowSelected(true); } } pressingSelect = true; } if (mSelectedObject) { if (GetAsyncKeyState(VK_LBUTTON) < 0 && GetAsyncKeyState('X') >= 0 && GetAsyncKeyState('C') >= 0 && GetAsyncKeyState('R') >= 0) { // drag // get the mouse in world coordinates and set the game objects position POINT currentMouse; GetCursorPos(¤tMouse); ScreenToClient(DXWindow::GetInstance()->Hwnd(), ¤tMouse); // the backbuffer may be larger in size than the the window (Windows scaling) so scale accordingly float scaleX = Graphics::GetInstance()->BackBufferWidth() / DXWindow::GetInstance()->GetWindowDimensions().X; float scaleY = Graphics::GetInstance()->BackBufferHeight() / DXWindow::GetInstance()->GetWindowDimensions().Y; Vector2 worldPos = Utilities::ScreenToWorld(Vector2(currentMouse.x * scaleX, currentMouse.y * scaleY)); mSelectedObject->SetX(worldPos.X); mSelectedObject->SetY(worldPos.Y); Sprite * sprite = GetAsSprite(mSelectedObject); if (sprite) { sprite->ApplyChange(Graphics::GetInstance()->Device()); sprite->Update(0); } MovingSprite * movingSprite = GetAsMovingSprite(mSelectedObject); if (movingSprite) { movingSprite->SetVelocityXYZ(0, 0, 0); } ScrollingSprite * scrollingSprite = GetAsScrollingSprite(mSelectedObject); if (scrollingSprite) { scrollingSprite->SetLerpStartPos(worldPos); } SolidLineStrip * solidLineStrip = GetAsSolidLineStrip(mSelectedObject); if (solidLineStrip) { vector<SolidLineStrip::SolidLinePoint> points = solidLineStrip->GetLinePoints(); solidLineStrip->RecalculateLines(points); } ParticleSpray * particleSpray = GetAsParticleSpray(mSelectedObject); if (particleSpray) { particleSpray->Reset(); } pressingPlace = true; } } } else { if (!pressingSelect && GetAsyncKeyState(VK_RBUTTON) < 0 && GetAsyncKeyState('R') >= 0) { mSelectedObject = GetGameObjectClickedOn(gameObjects); if (mSelectedObject) { mSelectedObject->ShowDebugText(true); mSelectedObject->SetLevelEditShowSelected(true); } pressingSelect = true; } } if (GetAsyncKeyState(VK_RBUTTON) >= 0) { pressingSelect = false; } if (GetAsyncKeyState(VK_LBUTTON) >= 0) { pressingPlace = false; } CheckForZChange(); CheckForSpriteScaling(); CheckForCollisionBoxScaling(); CheckFlippingSprite(); CheckForSettingNativeRes(); CheckForRotating(); CheckForDeleting(); CheckForSavePressed(); CheckForCopy(); CheckForLayerAssign(); CheckForMaterialAssign(); CheckForPixelMovement(); for (auto & obj : gameObjects) { if (dynamic_cast<ParticleSpray*>(obj.get())) { obj->Update(Timing::Instance()->GetLastUpdateDelta()); } } }