Skip to content

Commit

Permalink
resizing behaviour infrastructure
Browse files Browse the repository at this point in the history
dynamically resize the battlescape and geoscape based on scale options.
maintains pixel size at all times.
  • Loading branch information
Warboy1982 committed Apr 24, 2014
1 parent 650728b commit 19751ea
Show file tree
Hide file tree
Showing 14 changed files with 216 additions and 24 deletions.
10 changes: 10 additions & 0 deletions src/Battlescape/ActionMenuState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,14 @@ void ActionMenuState::btnActionMenuItemClick(Action *action)
}
}

/**
* Updates the scale.
* @param dX delta of X;
* @param dY delta of Y;
*/
void ActionMenuState::resize(int &dX, int &dY)
{
State::recenter(dX, dY * 2);
}

}
2 changes: 2 additions & 0 deletions src/Battlescape/ActionMenuState.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class ActionMenuState : public State
void handle(Action *action);
/// Handler for clicking a action menu item.
void btnActionMenuItemClick(Action *action);
/// Update the resolution settings, we just resized the window.
void resize(int &dX, int &dY);
};

}
Expand Down
51 changes: 50 additions & 1 deletion src/Battlescape/BattlescapeState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ BattlescapeState::BattlescapeState(Game *game) : State(game), _popups(), _xBefor
int screenWidth = Options::baseXResolution;
int screenHeight = Options::baseYResolution;
int iconsWidth = 320;
int iconsHeight = 56;
int iconsHeight = Map::ICON_HEIGHT;
_mouseOverIcons = false;
// Create buttonbar - this should be on the centerbottom of the screen
_icons = new InteractiveSurface(iconsWidth, iconsHeight, screenWidth/2 - iconsWidth/2, screenHeight - iconsHeight);
Expand Down Expand Up @@ -2044,4 +2044,53 @@ void BattlescapeState::txtTooltipOut(Action *action)
}
}

/**
* Updates the scale.
* @param dX delta of X;
* @param dY delta of Y;
*/
void BattlescapeState::resize(int &dX, int &dY)
{
dX = Options::baseXResolution;
dY = Options::baseYResolution;
int divisor = 1;
switch (Options::battlescapeScale)
{
case SCALE_SCREEN_DIV_3:
divisor = 3;
break;
case SCALE_SCREEN_DIV_2:
divisor = 2;
break;
case SCALE_SCREEN:
break;
default:
return;
}

Options::baseXResolution = std::max(Screen::ORIGINAL_WIDTH, Options::displayWidth / divisor);
Options::baseYResolution = std::max(Screen::ORIGINAL_HEIGHT, Options::displayHeight / divisor);

dX = Options::baseXResolution - dX;
dY = Options::baseYResolution - dY;
_map->setWidth(Options::baseXResolution);
_map->setHeight(Options::baseYResolution);
_map->getCamera()->resize();
_map->getCamera()->jumpXY(dX/2, dY/2);

for (std::vector<Surface*>::const_iterator i = _surfaces.begin(); i != _surfaces.end(); ++i)
{
if (*i != _map && (*i) != _btnPsi && *i != _btnLaunch && *i != _txtDebug)
{
(*i)->setX((*i)->getX() + dX / 2);
(*i)->setY((*i)->getY() + dY);
}
else if (*i != _map && *i != _txtDebug)
{
(*i)->setX((*i)->getX() + dX);
}
}

}

}
2 changes: 2 additions & 0 deletions src/Battlescape/BattlescapeState.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ class BattlescapeState : public State
void txtTooltipIn(Action *action);
/// Handler for hiding tooltip.
void txtTooltipOut(Action *action);
/// Update the resolution settings, we just resized the window.
void resize(int &dX, int &dY);
};

}
Expand Down
9 changes: 9 additions & 0 deletions src/Battlescape/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,4 +581,13 @@ bool Camera::isOnScreen(const Position &mapPos) const
&& screenPos.y <= _screenHeight - 48;
}

/**
* Resizes the viewable window of the camera.
*/
void Camera::resize()
{
_screenWidth = _map->getWidth();
_screenHeight = _map->getHeight();
_visibleMapHeight = _map->getHeight() - Map::ICON_HEIGHT;
}
}
2 changes: 2 additions & 0 deletions src/Battlescape/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class Camera
bool getShowAllLayers() const;
/// Checks if map coordinates X,Y,Z are on screen.
bool isOnScreen(const Position &mapPos) const;
/// Resize the viewable area.
void resize();
};
}
#endif
10 changes: 9 additions & 1 deletion src/Battlescape/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1294,5 +1294,13 @@ void Map::refreshSelectorPosition()
setSelectorPosition(_mouseX, _mouseY);
}


/*
* Special handling for setting the height of the map viewport.
* @param height the new base screen height.
*/
void Map::setHeight(int height)
{
Surface::setHeight(height);
_visibleMapHeight = height - ICON_HEIGHT;
}
}
4 changes: 3 additions & 1 deletion src/Battlescape/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class Timer;
class Text;

enum CursorType { CT_NONE, CT_NORMAL, CT_AIM, CT_PSI, CT_WAYPOINT, CT_THROW };

/**
* Interactive map of the battlescape.
*/
Expand Down Expand Up @@ -75,6 +74,7 @@ class Map : public InteractiveSurface
void drawTerrain(Surface *surface);
int getTerrainLevel(Position pos, int size);
public:
static const int ICON_HEIGHT = 56;
/// Creates a new map at the specified position and size.
Map(Game *game, int width, int height, int x, int y, int visibleMapHeight);
/// Cleans up the map.
Expand Down Expand Up @@ -133,6 +133,8 @@ class Map : public InteractiveSurface
void setUnitDying(bool flag);
/// Refreshes the battlescape selector after scrolling.
void refreshSelectorPosition();
/// Special handling for updating map height.
void setHeight(int height);
};

}
Expand Down
50 changes: 49 additions & 1 deletion src/Geoscape/GeoscapeState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace OpenXcom
*/
GeoscapeState::GeoscapeState(Game *game) : State(game), _pause(false), _zoomInEffectDone(false), _zoomOutEffectDone(false), _popups(), _dogfights(), _dogfightsToBeStarted(), _minimizedDogfights(0)
{
int screenWidth = Options::baseXGeoscape - Options::baseXGeoscape%4;
int screenWidth = Options::baseXGeoscape;
int screenHeight = Options::baseYGeoscape;

// Create objects
Expand Down Expand Up @@ -2133,6 +2133,10 @@ void GeoscapeState::determineAlienMissions(bool atGameStart)
}
}

/**
* Handler for clicking on a timer button.
* @param action pointer to the mouse action.
*/
void GeoscapeState::btnTimerClick(Action *action)
{
SDL_Event ev;
Expand All @@ -2142,4 +2146,48 @@ void GeoscapeState::btnTimerClick(Action *action)
action->getSender()->mousePress(&a, this);
}

/**
* Updates the scale.
* @param dX delta of X;
* @param dY delta of Y;
*/
void GeoscapeState::resize(int &dX, int &dY)
{
if (_game->getSavedGame()->getSavedBattle())
return;
dX = Options::baseXResolution;
dY = Options::baseYResolution;
int divisor = 1;
switch (Options::geoscapeScale)
{
case SCALE_SCREEN_DIV_3:
divisor = 3;
break;
case SCALE_SCREEN_DIV_2:
divisor = 2;
break;
case SCALE_SCREEN:
break;
default:
return;
}

Options::baseXResolution = std::max(Screen::ORIGINAL_WIDTH, Options::displayWidth / divisor);
Options::baseYResolution = std::max(Screen::ORIGINAL_HEIGHT, Options::displayHeight / divisor);

dX = Options::baseXResolution - dX;
dY = Options::baseYResolution - dY;

_globe->resize();

for (std::vector<Surface*>::const_iterator i = _surfaces.begin(); i != _surfaces.end(); ++i)
{
if (*i != _globe)
{
(*i)->setX((*i)->getX() + dX);
(*i)->setY((*i)->getY() + dY/2);
}
}

}
}
2 changes: 2 additions & 0 deletions src/Geoscape/GeoscapeState.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class GeoscapeState : public State
bool processTerrorSite(TerrorSite *ts) const;
/// Handles base defense
void handleBaseDefense(Base *base, Ufo *ufo);
/// Update the resolution settings, we just resized the window.
void resize(int &dX, int &dY);
private:
/// Handle alien mission generation.
void determineAlienMissions(bool atGameStart = false);
Expand Down
76 changes: 57 additions & 19 deletions src/Geoscape/Globe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,25 +366,8 @@ Globe::Globe(Game *game, int cenX, int cenY, int width, int height, int x, int y
_cenLon = _game->getSavedGame()->getGlobeLongitude();
_cenLat = _game->getSavedGame()->getGlobeLatitude();
_zoom = _game->getSavedGame()->getGlobeZoom();

_radius.push_back(0.45*height);
_radius.push_back(0.60*height);
_radius.push_back(0.90*height);
_radius.push_back(1.40*height);
_radius.push_back(2.25*height);
_radius.push_back(3.60*height);
_earthData.resize(_radius.size());

//filling normal field for each radius
for(size_t r = 0; r<_radius.size(); ++r)
{
_earthData[r].resize(width * height);
for(int j=0; j<height; ++j)
for(int i=0; i<width; ++i)
{
_earthData[r][width*j + i] = static_data.circle_norm(width/2, height/2, _radius[r], i+.5, j+.5);
}
}

setupRadii(width, height);

//filling random noise "texture"
_randomNoiseData.resize(static_data.random_surf_size * static_data.random_surf_size);
Expand Down Expand Up @@ -1850,10 +1833,65 @@ bool Globe::isZoomedOutToMax() const
return (_zoom == 0);
}

/*
* Turns Radar lines on or off.
*/
void Globe::toggleRadarLines()
{
Options::globeRadarLines = !Options::globeRadarLines;
drawRadars();
}

/*
* Resizes the geoscape.
*/
void Globe::resize()
{
Surface *surfaces[4] = {this, _markers, _countries, _radars};
int width = Options::baseXGeoscape - 64;
int height = Options::baseYGeoscape;

for (int i = 0; i < 3; ++i)
{
surfaces[i]->setWidth(width);
surfaces[i]->setHeight(height);
surfaces[i]->invalidate();
}
_clipper->Wxrig = width;
_clipper->Wybot = height;
_cenX = width / 2;
_cenY = height / 2;
setupRadii(width, height);
cachePolygons();
}

/*
* Set up the Radius of earth at the various zoom levels.
* @param width the new width of the globe.
* @param height the new height of the globe.
*/
void Globe::setupRadii(int width, int height)
{
_radius.clear();

_radius.push_back(0.45*height);
_radius.push_back(0.60*height);
_radius.push_back(0.90*height);
_radius.push_back(1.40*height);
_radius.push_back(2.25*height);
_radius.push_back(3.60*height);

_earthData.resize(_radius.size());
//filling normal field for each radius

for(size_t r = 0; r<_radius.size(); ++r)
{
_earthData[r].resize(width * height);
for(int j=0; j<height; ++j)
for(int i=0; i<width; ++i)
{
_earthData[r][width*j + i] = static_data.circle_norm(width/2, height/2, _radius[r], i+.5, j+.5);
}
}
}
}//namespace OpenXcom
5 changes: 4 additions & 1 deletion src/Geoscape/Globe.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ class Globe : public InteractiveSurface
bool getShowRadar(void);
/// set the _radarLines variable
void toggleRadarLines();

/// Update the resolution settings, we just resized the window.
void resize();
/// Set up the radius of earth and stuff.
void setupRadii(int width, int height);
};

}
Expand Down
15 changes: 15 additions & 0 deletions src/Menu/MainMenuState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,19 @@ void MainMenuState::btnQuitClick(Action *)
_game->quit();
}

/**
* Updates the scale.
* @param dX delta of X;
* @param dY delta of Y;
*/
void MainMenuState::resize(int &dX, int &dY)
{
dX = Options::baseXResolution;
dY = Options::baseYResolution;
OptionsBaseState::updateScale(Options::battlescapeScale, Options::battlescapeScale, Options::baseXBattlescape, Options::baseYBattlescape, false);
OptionsBaseState::updateScale(Options::geoscapeScale, Options::geoscapeScale, Options::baseXGeoscape, Options::baseYGeoscape, true);
dX = Options::baseXResolution - dX;
dY = Options::baseYResolution - dY;
State::resize(dX, dY);
}
}
2 changes: 2 additions & 0 deletions src/Menu/MainMenuState.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class MainMenuState : public State
void btnOptionsClick(Action *action);
/// Handler for clicking the Quit button.
void btnQuitClick(Action *action);
/// Update the resolution settings, we just resized the window.
void resize(int &dX, int &dY);
};

}
Expand Down

0 comments on commit 19751ea

Please sign in to comment.