Finished implementing resolution changes

This commit is contained in:
Dave White 2003-09-19 13:08:15 +00:00
parent cca1c2a769
commit 8402f0e0c1
3 changed files with 27 additions and 10 deletions

View file

@ -82,13 +82,12 @@ display::display(unit_map& units, CVideo& video, const gamemap& map,
invalidateAll_(true), invalidateUnit_(true),
invalidateGameStatus_(true), sideBarBgDrawn_(false),
lastTimeOfDay_(-1), currentTeam_(0), updatesLocked_(0),
turbo_(false), grid_(false)
turbo_(false), grid_(false), sidebarScaling_(1.0)
{
gameStatusRect_.w = 0;
unitDescriptionRect_.w = 0;
unitProfileRect_.w = 0;
//clear the screen contents
SDL_Surface* const disp = screen_.getSurface();
const int length = disp->w*disp->h;
@ -333,8 +332,20 @@ void display::draw(bool update,bool force)
{
if(!sideBarBgDrawn_) {
SDL_Surface* const screen = screen_.getSurface();
SDL_Surface* const image = getImage("misc/rightside.png",UNSCALED);
SDL_Surface* image = getImage("misc/rightside.png",UNSCALED);
if(image != NULL) {
if(image->h != screen->h) {
SDL_Surface* const new_image
= scale_surface(image,image->w,screen->h);
if(new_image != NULL) {
images_["misc/rightside.png"] = new_image;
SDL_FreeSurface(image);
image = new_image;
sidebarScaling_ = static_cast<double>(image->h)/768.0;
}
}
SDL_Rect dstrect;
dstrect.x = mapx();
dstrect.y = 0;
@ -360,7 +371,7 @@ void display::draw(bool update,bool force)
for(int y = -1; y <= map_.y(); ++y)
draw_tile(x,y);
invalidateAll_ = false;
draw_minimap(mapx()+30,35,(this->x()-mapx())-60,120);
draw_minimap(mapx()+30,35,(this->x()-mapx())-60,120*sidebarScaling_);
} else {
for(std::set<gamemap::location>::const_iterator it =
invalidated_.begin(); it != invalidated_.end(); ++it) {
@ -416,13 +427,13 @@ void display::draw_sidebar()
i = units_.find(selectedHex_);
if(i != units_.end())
draw_unit_details(mapx()+2,390,selectedHex_,i->second,
unitDescriptionRect_,unitProfileRect_);
draw_unit_details(mapx()+2,390*sidebarScaling_,selectedHex_,
i->second,unitDescriptionRect_,unitProfileRect_);
invalidateUnit_ = false;
}
if(invalidateGameStatus_) {
draw_game_status(mapx()+2,258);
draw_game_status(mapx()+2,258*sidebarScaling_);
invalidateGameStatus_ = false;
}
}
@ -454,10 +465,10 @@ void display::draw_game_status(int x, int y)
if(tod_surface != NULL) {
//hardcoded values as to where the time of day image appears
blit_surface(mapx() + 21,196,tod_surface);
blit_surface(mapx() + 21,196*sidebarScaling_,tod_surface);
SDL_Rect update_area;
update_area.x = mapx() + 21;
update_area.y = 196;
update_area.y = 196*sidebarScaling_;
update_area.w = tod_surface->w;
update_area.h = tod_surface->h;
update_rect(update_area);

View file

@ -220,6 +220,7 @@ private:
int updatesLocked_;
bool turbo_, grid_;
double sidebarScaling_;
//for debug mode
static std::map<gamemap::location,double> debugHighlights_;

View file

@ -10,6 +10,9 @@
See the COPYING file for more details.
*/
#include <iostream>
#include "sdl_utils.hpp"
SDL_Surface* scale_surface(SDL_Surface* surface, int w, int h)
@ -20,8 +23,10 @@ SDL_Surface* scale_surface(SDL_Surface* surface, int w, int h)
surface->format->Gmask,
surface->format->Bmask,
surface->format->Amask);
if(dest == NULL)
if(dest == NULL) {
std::cerr << "Could not create surface to scale onto\n";
return NULL;
}
const double xratio = static_cast<double>(surface->w)/
static_cast<double>(w);