bool iupPlotAxis::ZoomTo(double inMin, double inMax) { InitZoom(); iPlotCheckMinMax(inMin, inMax); if (inMin > mNoZoomMax || inMax < mNoZoomMin) return false; if (inMin < mNoZoomMin) inMin = mNoZoomMin; if (inMax > mNoZoomMax) inMax = mNoZoomMax; mMin = inMin; mMax = inMax; if (mMin == mNoZoomMin && mMax == mNoZoomMax) ResetZoom(); return true; }
bool iupPlotAxis::ZoomOut(double inCenter) { if (inCenter < mMin || inCenter > mMax) return false; if (!mHasZoom) return false; double theRange = mMax - mMin; double theNewRange = theRange * 1.1; // 10% double theFactor = (inCenter - mMin) / theRange; double theOffset = (theNewRange - theRange); mMin -= theOffset*theFactor; mMax += theOffset*(1.0 - theFactor); CheckZoomOutLimit(theNewRange); if (mMin == mNoZoomMin && mMax == mNoZoomMax) ResetZoom(); return true; }
/* ====================================== Getting input for actions that are the same for "editing mode" and "in game mode" ====================================== */ void Listener::ListenCommon() { // -------------------- Text -------------------- // Update info-text strcpy (mText, mModeName); // -------------------- Time measurement -------------------- mDelta = mI->_render->getFrameTime() / 1000.0f; // -------------------- Get mouse position -------------------- mMouseX = mI->_input->getMouseX(); mMouseY = mI->_input->getMouseY(); // -------------------- Update IndieLib cameras -------------------- // Update the position of the cameras mCameraB->setPosition (mCameraBX, mCameraBY); mCameraN->setPosition (mCameraNX, mCameraNY); mCameraM->setPosition (mCameraMX, mCameraMY); mCameraLayers->setPosition (mCameraLayersX, mCameraLayersY); // Update the zoom factor of the cameras mCameraB->setZoom (mCameraZoomB); mCameraN->setZoom (mCameraZoomN); mCameraM->setZoom (mCameraZoomM); mCameraLayers->setZoom (mCameraZoomLayers); // -------------------- Switch between "editing" and "in game" mode when pressing tab -------------------- if (mI->_input->onKeyRelease (IND_TAB)) { if (mMode) { strcpy (mModeName, "In game mode"); // Set text if (mBackDropNodeOver) mBackDropNodeOver->GetEntity()->showGridAreas (false); mMode = false; } else { strcpy (mModeName, "Editing mode | "); // Set text mMode = true; } } // -------------------- Save Map -------------------- if (mI->_input->isKeyPressed (IND_LCTRL) && mI->_input->onKeyPress (IND_S)) mMap->SaveMap (mResources->GetTilesetPath()); // -------------------- New Map -------------------- if (mI->_input->isKeyPressed (IND_LCTRL) && mI->_input->onKeyPress (IND_N)) { char *mTilesetPath = mMap->GetPathToTileset (); if (mTilesetPath) { // We try to load a new tileset if (mResources->LoadTileset (mTilesetPath)) { DeleteBackDropBrushes(); // Delete old brushes. TODO-> Check is the tileset is already loaded CreateBackDropBrushes(); // Create the new brushes using the new loaded tileset mMap->FreeMap(); // Free old map } else exit (0); // Just exit if we can't load it: TODO -> Show a message } } // -------------------- Load Map -------------------- if (mI->_input->isKeyPressed (IND_LCTRL) && mI->_input->onKeyPress (IND_L)) { // Try to load the map if (mMap->LoadMap (mResources)) { DeleteBackDropBrushes(); // Delete old brushes. TODO-> Check is the tileset is already loaded CreateBackDropBrushes(); // Create the new brushes using the new loaded tileset } else exit (0); // Just exit if we can't load it: TODO -> Show a message } // -------------------- Camera position -------------------- // The camera movement is time dependent, each camera has a different speed if (mI->_input->isKeyPressed (IND_A)) { mCameraBX -= CAMERA_SPEED_B * mDelta; mCameraNX -= CAMERA_SPEED_N * mDelta; mCameraMX -= CAMERA_SPEED_M * mDelta; mCameraLayersX -= CAMERA_SPEED_LAYERS * mDelta; } if (mI->_input->isKeyPressed (IND_D)) { mCameraBX += CAMERA_SPEED_B * mDelta; mCameraNX += CAMERA_SPEED_N * mDelta; mCameraMX += CAMERA_SPEED_M * mDelta; mCameraLayersX += CAMERA_SPEED_LAYERS * mDelta; } if (mI->_input->isKeyPressed (IND_W)) { mCameraBY -= CAMERA_SPEED_B * mDelta; mCameraNY -= CAMERA_SPEED_N * mDelta; mCameraMY -= CAMERA_SPEED_M * mDelta; mCameraLayersY -= CAMERA_SPEED_LAYERS * mDelta; } if (mI->_input->isKeyPressed (IND_S)) { mCameraBY += CAMERA_SPEED_B * mDelta; mCameraNY += CAMERA_SPEED_N * mDelta; mCameraMY += CAMERA_SPEED_M * mDelta; mCameraLayersY += CAMERA_SPEED_LAYERS * mDelta; } // -------------------- Camera zoom -------------------- // Zoom in if (mI->_input->isKeyPressed (IND_KEYUP)) { mCameraZoomB += (DIST_CAMERA_B * mDelta) / 1000; mCameraZoomN += (DIST_CAMERA_N * mDelta) / 1000; mCameraZoomM += (DIST_CAMERA_M * mDelta) / 1000; mCameraZoomLayers += (DIST_CAMERA_LAYERS * mDelta) / 1000; } // Zoom out if (mCameraZoomB > 0) // Avoid too much zoom-out { if (mI->_input->isKeyPressed (IND_KEYDOWN)) { mCameraZoomB -= (DIST_CAMERA_B * mDelta) / 1000; mCameraZoomN -= (DIST_CAMERA_N * mDelta) / 1000; mCameraZoomM -= (DIST_CAMERA_M * mDelta) / 1000; mCameraZoomLayers -= (DIST_CAMERA_LAYERS * mDelta) / 1000; } } // reset zoom if (mI->_input->onKeyPress (IND_R)) ResetZoom (); // -------------------- Toggle full screen-------------------- if (mI->_input->onKeyPress (IND_F1)) { //Toggle full screen IND_WindowProperties props ("",mScreenWidth,mScreenHeight, 32,0,!mI->_window->isFullScreen()); props._fullscreen = !mI->_window->isFullScreen(); mI->_render->reset (props); } // -------------------- Change screen resolution -------------------- if (mI->_input->onKeyPress (IND_F2)) if (!ResetScreen (640, 480)) exit (0); if (mI->_input->onKeyPress (IND_F3)) if (!ResetScreen (800, 600)) exit (0); if (mI->_input->onKeyPress (IND_F4)) if (!ResetScreen (1024, 768)) exit (0); if (mI->_input->onKeyPress (IND_F5)) if (!ResetScreen (1440, 900)) exit (0); }
/* ====================================== Init ====================================== */ Listener::Listener(Resources *pResources, Map *pMap) { // Get IndieLib instante mI = CIndieLib::instance(); // Classes mResources = pResources; mMap = pMap; // Screen dimensions and fullscreen flag mScreenWidth = mI->_window->getWidth(); mScreenHeight = mI->_window->getHeight(); // Backdrop mBackDropNodeOver = 0; // The mouse cursor is over this backdrop mIsRotatingBackDrop = false; // Flag used when rotating a backdrop mIsTranslatingBackDrop = false; // Flag used when translating a backdrop mIsScalingBackDrop = false; // Flag used when scaling a backdrop mIsTintingBackDrop = false; // Flag used when tinting a backdrop // Text showed mText [0] = 0; // Init mode = editing mMode = true; // Editing / In game strcpy (mModeName, "Editing mode | "); // All the backdrop objects in this editor are on one of 13 layers. // The first 3 layers are parallax layers, mapped to "B", "N" and "M" keys in they // keyboard. // // The following nine layers are mapped to the 1-9 keys. Layers 8-9 are the only layers that // go over active entities, like the main player! // // The final layer is the "dark layer", layer mapped to "J". Is another layer that you // could use in order to draw semi-translucent dark sprites in order to simulate darkness. // // For coding all this in the editor we only need a variable called mLayer that stores // the number of the layer we are working on. Later, when dropping a piece, we just have // to check in which layer we are working and to add the IndieLib entity of the dropped node // to the proper layer user IndieLib Entity2dManger class, that let you choose in which layer // you want to add an entity. Later, in the main loop, we just render each layer, starting // from 0 to the last layer, using Entity2dManger::RenderEntities2d() method. // // On the following list you can see in the first colum the number for coding the layer // and in the second colum its real name. Don't make a mistake thinking for example // than the layer named "1" is coded in mLayer variable as 1: // // 0 = b // 1 = n // 2 = m // 3-11 = 1-9 // 12 = j mLayer = 3; // (Layer 1) strcpy (mLayerName, "Layer 1 (Tiled surfaces)"); // Camera initialization (middle of the screen area) mCameraLayersX = mCameraBX = mCameraNX = mCameraMX = (float) mI->_window->getWidth () / 2; mCameraLayersY = mCameraBY = mCameraNY = mCameraMY = (float) mI->_window->getHeight () / 2; // We use 4 cameras, one for each parallax scroll and one for the rest of layers mCameraB = new IND_Camera2d (mCameraLayersX, mCameraLayersY); mCameraN = new IND_Camera2d (mCameraLayersX, mCameraLayersY); mCameraM = new IND_Camera2d (mCameraLayersX, mCameraLayersY); mCameraLayers = new IND_Camera2d (mCameraLayersX, mCameraLayersY); mCameraGui = new IND_Camera2d (mCameraLayersX, mCameraLayersY); // Set the camera zoom ResetZoom (); // Create the backdrop entities that are used to show on the screen which backdrop // sprite is currently as a brush and ready to be dropped. CreateBackDropBrushes (); }
void ImageView::OnZoomAndDragReset() { ResetZoom(); redraw(); }