refactored code. Removed orbs on enemy units
This commit is contained in:
parent
c305a5fcbb
commit
74dd9ac141
19 changed files with 99 additions and 264 deletions
Binary file not shown.
Before Width: | Height: | Size: 619 B After Width: | Height: | Size: 543 B |
BIN
images/side1.png
BIN
images/side1.png
Binary file not shown.
BIN
images/side2.png
BIN
images/side2.png
Binary file not shown.
BIN
images/side3.png
BIN
images/side3.png
Binary file not shown.
BIN
images/side4.png
BIN
images/side4.png
Binary file not shown.
BIN
images/side5.png
BIN
images/side5.png
Binary file not shown.
BIN
images/side6.png
BIN
images/side6.png
Binary file not shown.
243
src/display.cpp
243
src/display.cpp
|
@ -18,6 +18,7 @@
|
|||
#include "game.hpp"
|
||||
#include "game_config.hpp"
|
||||
#include "hotkeys.hpp"
|
||||
#include "image.hpp"
|
||||
#include "language.hpp"
|
||||
#include "log.hpp"
|
||||
#include "preferences.hpp"
|
||||
|
@ -104,6 +105,8 @@ display::display(unit_map& units, CVideo& video, const gamemap& map,
|
|||
currentTeam_(0), activeTeam_(0), updatesLocked_(0),
|
||||
turbo_(false), grid_(false), sidebarScaling_(1.0)
|
||||
{
|
||||
new_turn();
|
||||
|
||||
gameStatusRect_.w = 0;
|
||||
unitDescriptionRect_.w = 0;
|
||||
unitProfileRect_.w = 0;
|
||||
|
@ -137,18 +140,13 @@ void clear_surfaces(Map& surfaces)
|
|||
|
||||
display::~display()
|
||||
{
|
||||
clear_surfaces(images_);
|
||||
clear_surfaces(scaledImages_);
|
||||
clear_surfaces(greyedImages_);
|
||||
clear_surfaces(brightenedImages_);
|
||||
SDL_FreeSurface(minimap_);
|
||||
}
|
||||
|
||||
void display::new_turn()
|
||||
{
|
||||
clear_surfaces(scaledImages_);
|
||||
clear_surfaces(greyedImages_);
|
||||
clear_surfaces(brightenedImages_);
|
||||
const time_of_day& tod = status_.get_time_of_day();
|
||||
image::set_colour_adjustment(tod.red,tod.green,tod.blue);
|
||||
}
|
||||
|
||||
gamemap::location display::hide_unit(const gamemap::location& loc)
|
||||
|
@ -242,9 +240,6 @@ void display::scroll(double xmove, double ymove)
|
|||
|
||||
void display::zoom(double amount)
|
||||
{
|
||||
clear_surfaces(scaledImages_);
|
||||
clear_surfaces(greyedImages_);
|
||||
clear_surfaces(brightenedImages_);
|
||||
energy_bar_count_ = std::pair<int,int>(-1,-1);
|
||||
|
||||
const double orig_xpos = xpos_;
|
||||
|
@ -281,6 +276,7 @@ void display::zoom(double amount)
|
|||
return;
|
||||
}
|
||||
|
||||
image::set_zoom(zoom_);
|
||||
invalidate_all();
|
||||
}
|
||||
|
||||
|
@ -407,28 +403,14 @@ void display::draw(bool update,bool force)
|
|||
{
|
||||
if(!sideBarBgDrawn_ && !teams_.empty()) {
|
||||
SDL_Surface* const screen = screen_.getSurface();
|
||||
SDL_Surface* image_top = getImage(RightSideTop,UNSCALED);
|
||||
SDL_Surface* image = getImage(RightSideBot,UNSCALED);
|
||||
SDL_Surface* image_top = image::get_image(RightSideTop,image::UNSCALED);
|
||||
|
||||
|
||||
SDL_Surface* image = image_top != NULL ?
|
||||
image::get_image_dim(RightSideBot,image_top->w,screen->h-image_top->h)
|
||||
: NULL;
|
||||
if(image_top != NULL && image != NULL && image_top->h < screen->h) {
|
||||
|
||||
if(image_top->h+image->h != screen->h) {
|
||||
SDL_FreeSurface(image);
|
||||
images_.erase(RightSideBot);
|
||||
|
||||
image = getImage(RightSideBot,UNSCALED);
|
||||
|
||||
SDL_Surface* const new_image
|
||||
= scale_surface(image,image_top->w,screen->h-image_top->h);
|
||||
if(new_image != NULL) {
|
||||
images_[RightSideBot] = new_image;
|
||||
SDL_FreeSurface(image);
|
||||
image = new_image;
|
||||
sidebarScaling_ = static_cast<double>(screen->h)/768.0;
|
||||
} else {
|
||||
std::cerr << "Could not scale image\n";
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Rect dstrect;
|
||||
dstrect.x = mapx();
|
||||
dstrect.y = 0;
|
||||
|
@ -546,7 +528,7 @@ void display::draw_game_status(int x, int y)
|
|||
|
||||
const time_of_day& tod = timeofday_at(status_,units_,mouseoverHex_);
|
||||
|
||||
SDL_Surface* const tod_surface = getImage(tod.image,UNSCALED);
|
||||
SDL_Surface* const tod_surface = image::get_image(tod.image,image::UNSCALED);
|
||||
|
||||
if(tod_surface != NULL) {
|
||||
//hardcoded values as to where the time of day image appears
|
||||
|
@ -556,7 +538,7 @@ void display::draw_game_status(int x, int y)
|
|||
|
||||
if(gameStatusRect_.w > 0) {
|
||||
SDL_Surface* const screen = screen_.getSurface();
|
||||
SDL_Surface* const background = getImage(RightSideTop,UNSCALED);
|
||||
SDL_Surface* const background = image::get_image(RightSideTop,image::UNSCALED);
|
||||
|
||||
if(background == NULL)
|
||||
return;
|
||||
|
@ -655,8 +637,8 @@ void display::draw_unit_details(int x, int y, const gamemap::location& loc,
|
|||
|
||||
SDL_Rect clipRect = clip_rect != NULL ? *clip_rect : screen_area();
|
||||
|
||||
SDL_Surface* const background = getImage(RightSideTop,UNSCALED);
|
||||
SDL_Surface* const background_bot = getImage(RightSideBot,UNSCALED);
|
||||
SDL_Surface* const background = image::get_image(RightSideTop,image::UNSCALED);
|
||||
SDL_Surface* const background_bot = image::get_image(RightSideBot,image::UNSCALED);
|
||||
|
||||
if(background == NULL || background_bot == NULL)
|
||||
return;
|
||||
|
@ -735,7 +717,7 @@ void display::draw_unit_details(int x, int y, const gamemap::location& loc,
|
|||
|
||||
y += description_rect.h;
|
||||
|
||||
SDL_Surface* const profile = getImage(u.type().image(),UNSCALED);
|
||||
SDL_Surface* const profile = image::get_image(u.type().image(),image::UNSCALED);
|
||||
|
||||
if(profile == NULL)
|
||||
return;
|
||||
|
@ -800,7 +782,7 @@ void display::draw_terrain_palette(int x, int y, gamemap::TERRAIN selected)
|
|||
std::vector<gamemap::TERRAIN> terrains = map_.get_terrain_precedence();
|
||||
for(std::vector<gamemap::TERRAIN>::const_iterator i = terrains.begin();
|
||||
i != terrains.end(); ++i) {
|
||||
SDL_Surface* const image = getTerrain(*i,SCALED,-1,-1);
|
||||
SDL_Surface* const image = getTerrain(*i,image::SCALED,-1,-1);
|
||||
if(x + image->w >= this->x() || y + image->h >= this->y()) {
|
||||
std::cout << "terrain palette can't fit: " << x + image->w << " > " << this->x() << " or " << y+image->h << " > " << this->y() << "\n";
|
||||
return;
|
||||
|
@ -846,21 +828,12 @@ gamemap::TERRAIN display::get_terrain_on(int palx, int paly, int x, int y)
|
|||
return terrains[index];
|
||||
}
|
||||
|
||||
namespace {
|
||||
SDL_Surface* get_side_image(display& disp, int side)
|
||||
{
|
||||
std::stringstream str;
|
||||
str << "side" << side << ".png";
|
||||
return disp.getImage(str.str());
|
||||
}
|
||||
}
|
||||
|
||||
void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
||||
double highlight_ratio, Pixel blend_with)
|
||||
|
||||
{
|
||||
if(map_.on_board(gamemap::location(x,y))) {
|
||||
SDL_Surface* const tile = getTerrain(map_[x][y],UNSCALED,x,y);
|
||||
SDL_Surface* const tile = getTerrain(map_[x][y],image::UNSCALED,x,y);
|
||||
SDL_Surface* minitile = scale_surface(tile,4,4);
|
||||
|
||||
SDL_FreeSurface(minitile);
|
||||
|
@ -902,17 +875,17 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
terrain = map_[x][y];
|
||||
}
|
||||
|
||||
IMAGE_TYPE image_type = SCALED;
|
||||
image::TYPE image_type = image::SCALED;
|
||||
|
||||
//find if this tile should be greyed
|
||||
if(pathsList_ != NULL && pathsList_->routes.find(gamemap::location(x,y)) ==
|
||||
pathsList_->routes.end()) {
|
||||
image_type = GREYED;
|
||||
image_type = image::GREYED;
|
||||
}
|
||||
|
||||
if(loc == mouseoverHex_ || loc == selectedHex_ &&
|
||||
units_.count(gamemap::location(x,y)) == 1) {
|
||||
image_type = BRIGHTENED;
|
||||
image_type = image::BRIGHTENED;
|
||||
}
|
||||
|
||||
SDL_Surface* surface = getTerrain(terrain,image_type,x,y);
|
||||
|
@ -934,7 +907,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
overlays_.equal_range(gamemap::location(x,y));
|
||||
overlays.first != overlays.second; ++overlays.first) {
|
||||
SDL_Surface* const overlay_surface =
|
||||
getImage(overlays.first->second);
|
||||
image::get_image(overlays.first->second);
|
||||
|
||||
if(overlay_surface != NULL) {
|
||||
overlaps.push_back(overlay_surface);
|
||||
|
@ -979,7 +952,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
const unit_map::const_iterator it = units_.find(gamemap::location(x,y));
|
||||
if(it != units_.end()) {
|
||||
if(unit_image == NULL)
|
||||
unit_image = getImage(it->second.image());
|
||||
unit_image = image::get_image(it->second.image());
|
||||
const int unit_move = it->second.movement_left();
|
||||
const int unit_total_move = it->second.total_movement();
|
||||
|
||||
|
@ -1002,7 +975,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
}
|
||||
}
|
||||
|
||||
energy_image = getImage(energy_file);
|
||||
energy_image = image::get_image(energy_file);
|
||||
unit_energy = double(it->second.hitpoints()) /
|
||||
double(it->second.max_hitpoints());
|
||||
|
||||
|
@ -1167,7 +1140,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
}
|
||||
|
||||
if(game_config::debug && debugHighlights_.count(gamemap::location(x,y))) {
|
||||
SDL_Surface* const cross = getImage("cross.png");
|
||||
SDL_Surface* const cross = image::get_image("cross.png");
|
||||
if(cross != NULL)
|
||||
draw_unit(xpos-xsrc,ypos-ysrc,cross,face_left,false,
|
||||
debugHighlights_[loc],0);
|
||||
|
@ -1196,11 +1169,6 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
|
|||
highlight_ratio,blend_with);
|
||||
}
|
||||
|
||||
SDL_Surface* const flag = get_side_image(*this,it->second.side());
|
||||
if(flag != NULL) {
|
||||
draw_unit(xpos-xsrc,ypos-ysrc,flag,true,false);
|
||||
}
|
||||
|
||||
const bool energy_uses_alpha = highlight_ratio < 1.0 && blend_with == 0;
|
||||
|
||||
surface_lock dstlock(dst);
|
||||
|
@ -1316,7 +1284,7 @@ void display::draw_footstep(const gamemap::location& loc, int xloc, int yloc)
|
|||
}
|
||||
}
|
||||
|
||||
SDL_Surface* const image = getImage(*image_str);
|
||||
SDL_Surface* const image = image::get_image(*image_str);
|
||||
if(image == NULL) {
|
||||
std::cerr << "Could not find image: " << *image_str << "\n";
|
||||
return;
|
||||
|
@ -1359,7 +1327,7 @@ const std::string& get_direction(int n)
|
|||
}
|
||||
|
||||
std::vector<SDL_Surface*> display::getAdjacentTerrain(int x, int y,
|
||||
IMAGE_TYPE image_type)
|
||||
image::TYPE image_type)
|
||||
{
|
||||
std::vector<SDL_Surface*> res;
|
||||
gamemap::location loc(x,y);
|
||||
|
@ -1434,7 +1402,7 @@ std::vector<SDL_Surface*> display::getAdjacentTerrain(int x, int y,
|
|||
return res;
|
||||
}
|
||||
|
||||
SDL_Surface* display::getTerrain(gamemap::TERRAIN terrain,IMAGE_TYPE image_type,
|
||||
SDL_Surface* display::getTerrain(gamemap::TERRAIN terrain,image::TYPE image_type,
|
||||
int x, int y, const std::string& direction)
|
||||
{
|
||||
const bool tower = (terrain == gamemap::TOWER);
|
||||
|
@ -1465,7 +1433,7 @@ SDL_Surface* display::getTerrain(gamemap::TERRAIN terrain,IMAGE_TYPE image_type,
|
|||
|
||||
image += direction + ".png";
|
||||
|
||||
return getImage(image,image_type);
|
||||
return image::get_image(image,image_type);
|
||||
}
|
||||
|
||||
void display::blit_surface(int x, int y, SDL_Surface* surface)
|
||||
|
@ -1516,145 +1484,6 @@ void display::blit_surface(int x, int y, SDL_Surface* surface)
|
|||
}
|
||||
}
|
||||
|
||||
SDL_Surface* display::getImage(const std::string& filename,
|
||||
display::IMAGE_TYPE type)
|
||||
{
|
||||
if(type == GREYED)
|
||||
return getImageTinted(filename,GREY_IMAGE);
|
||||
else if(type == BRIGHTENED)
|
||||
return getImageTinted(filename,BRIGHTEN_IMAGE);
|
||||
|
||||
std::map<std::string,SDL_Surface*>::iterator i;
|
||||
|
||||
if(type == SCALED) {
|
||||
i = scaledImages_.find(filename);
|
||||
if(i != scaledImages_.end())
|
||||
return i->second;
|
||||
}
|
||||
|
||||
i = images_.find(filename);
|
||||
|
||||
if(i == images_.end()) {
|
||||
const std::string images_path = "images/";
|
||||
const std::string images_filename = images_path + filename;
|
||||
SDL_Surface* surf = NULL;
|
||||
|
||||
if(game_config::path.empty() == false) {
|
||||
const std::string& fullpath = game_config::path + "/" +
|
||||
images_filename;
|
||||
surf = IMG_Load(fullpath.c_str());
|
||||
}
|
||||
|
||||
if(surf == NULL)
|
||||
surf = IMG_Load(images_filename.c_str());
|
||||
|
||||
if(surf == NULL) {
|
||||
images_.insert(std::pair<std::string,SDL_Surface*>(filename,NULL));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_Surface* const conv = SDL_ConvertSurface(surf,
|
||||
screen_.getSurface()->format,
|
||||
SDL_SWSURFACE);
|
||||
SDL_FreeSurface(surf);
|
||||
|
||||
i = images_.insert(std::pair<std::string,SDL_Surface*>(filename,conv))
|
||||
.first;
|
||||
}
|
||||
|
||||
if(i->second == NULL)
|
||||
return NULL;
|
||||
|
||||
if(type == UNSCALED) {
|
||||
return i->second;
|
||||
}
|
||||
|
||||
const int z = static_cast<int>(zoom_);
|
||||
SDL_Surface* const new_surface = scale_surface(i->second,z,z);
|
||||
|
||||
if(new_surface == NULL)
|
||||
return NULL;
|
||||
|
||||
const time_of_day& tod = status_.get_time_of_day();
|
||||
adjust_surface_colour(new_surface,tod.red,tod.green,tod.blue);
|
||||
|
||||
scaledImages_.insert(std::pair<std::string,SDL_Surface*>(filename,
|
||||
new_surface));
|
||||
return new_surface;
|
||||
}
|
||||
|
||||
SDL_Surface* display::getImageTinted(const std::string& filename, TINT tint)
|
||||
{
|
||||
std::map<std::string,SDL_Surface*>& image_map =
|
||||
tint == GREY_IMAGE ? greyedImages_ : brightenedImages_;
|
||||
|
||||
const std::map<std::string,SDL_Surface*>::iterator itor =
|
||||
image_map.find(filename);
|
||||
|
||||
if(itor != image_map.end())
|
||||
return itor->second;
|
||||
|
||||
SDL_Surface* const base = getImage(filename,SCALED);
|
||||
if(base == NULL)
|
||||
return NULL;
|
||||
|
||||
SDL_Surface* const surface =
|
||||
SDL_CreateRGBSurface(SDL_SWSURFACE,base->w,base->h,
|
||||
base->format->BitsPerPixel,
|
||||
base->format->Rmask,
|
||||
base->format->Gmask,
|
||||
base->format->Bmask,
|
||||
base->format->Amask);
|
||||
|
||||
image_map.insert(std::pair<std::string,SDL_Surface*>(filename,surface));
|
||||
|
||||
surface_lock srclock(base);
|
||||
surface_lock dstlock(surface);
|
||||
short* begin = srclock.pixels();
|
||||
const short* const end = begin + base->h*(base->w + (base->w%2));
|
||||
short* dest = dstlock.pixels();
|
||||
|
||||
const int rmax = 0xFF;
|
||||
const int gmax = 0xFF;
|
||||
const int bmax = 0xFF;
|
||||
|
||||
while(begin != end) {
|
||||
Uint8 red, green, blue;
|
||||
SDL_GetRGB(*begin,base->format,&red,&green,&blue);
|
||||
int r = int(red), g = int(green), b = int(blue);
|
||||
|
||||
if(tint == GREY_IMAGE) {
|
||||
const double greyscale = (double(r)/(double)rmax +
|
||||
double(g)/(double)gmax +
|
||||
double(b)/(double)bmax)/3.0;
|
||||
|
||||
r = int(rmax*greyscale);
|
||||
g = int(gmax*greyscale);
|
||||
b = int(bmax*greyscale);
|
||||
} else {
|
||||
r = int(double(r)*1.5);
|
||||
g = int(double(g)*1.5);
|
||||
b = int(double(b)*1.5);
|
||||
|
||||
if(r > rmax)
|
||||
r = rmax;
|
||||
|
||||
if(g > gmax)
|
||||
g = gmax;
|
||||
|
||||
if(b > bmax)
|
||||
b = bmax;
|
||||
}
|
||||
|
||||
*dest = SDL_MapRGB(base->format,r,g,b);
|
||||
|
||||
++dest;
|
||||
++begin;
|
||||
}
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
||||
SDL_Surface* display::getMinimap(int w, int h)
|
||||
{
|
||||
if(minimap_ == NULL) {
|
||||
|
@ -1685,7 +1514,7 @@ SDL_Surface* display::getMinimap(int w, int h)
|
|||
|
||||
if(i == cache.end()) {
|
||||
SDL_Surface* const tile = getTerrain(map_[x][y],
|
||||
UNSCALED,x,y);
|
||||
image::UNSCALED,x,y);
|
||||
SDL_Surface* const minitile = scale_surface(tile,scale,
|
||||
scale);
|
||||
i = cache.insert(
|
||||
|
@ -1853,7 +1682,7 @@ bool display::unit_attack_ranged(const gamemap::location& a,
|
|||
|
||||
if(!hide) {
|
||||
SDL_Surface* const image = (unit_image == NULL) ?
|
||||
NULL : getImage(*unit_image);
|
||||
NULL : image::get_image(*unit_image);
|
||||
draw_tile(a.x,a.y,image);
|
||||
}
|
||||
|
||||
|
@ -1900,7 +1729,7 @@ bool display::unit_attack_ranged(const gamemap::location& a,
|
|||
missile_image = &default_diag_missile;
|
||||
}
|
||||
|
||||
SDL_Surface* const img = getImage(*missile_image);
|
||||
SDL_Surface* const img = image::get_image(*missile_image);
|
||||
if(img != NULL) {
|
||||
double pos = double(missile_impact - i)/double(missile_impact);
|
||||
if(pos < 0.0)
|
||||
|
@ -2115,7 +1944,7 @@ bool display::unit_attack(const gamemap::location& a,
|
|||
unit_image = &attacker.image();
|
||||
|
||||
SDL_Surface* const image = (unit_image == NULL) ?
|
||||
NULL : getImage(*unit_image);
|
||||
NULL : image::get_image(*unit_image);
|
||||
|
||||
const double pos = double(i)/double(i < 0 ? begin_at : end_at);
|
||||
const int posx = int(pos*xsrc + (1.0-pos)*xdst) + xoffset;
|
||||
|
@ -2175,7 +2004,7 @@ void display::move_unit_between(const gamemap::location& a,
|
|||
|
||||
//checking keys may have invalidated all images (if they have
|
||||
//zoomed in or out), so reget the image here
|
||||
SDL_Surface* const image = getImage(u.type().image());
|
||||
SDL_Surface* const image = image::get_image(u.type().image());
|
||||
if(image == NULL) {
|
||||
std::cerr << "failed to get image " << u.type().image() << "\n";
|
||||
return;
|
||||
|
@ -2372,7 +2201,7 @@ const std::pair<int,int>& display::calculate_energy_bar()
|
|||
int first_row = -1;
|
||||
int last_row = -1;
|
||||
|
||||
SDL_Surface* const image = getImage("unmoved-energy.png");
|
||||
SDL_Surface* const image = image::get_image("unmoved-energy.png");
|
||||
|
||||
surface_lock image_lock(image);
|
||||
const short* const begin = image_lock.pixels();
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#define DISPLAY_H_INCLUDED
|
||||
|
||||
#include "gamestatus.hpp"
|
||||
#include "image.hpp"
|
||||
#include "key.hpp"
|
||||
#include "map.hpp"
|
||||
#include "pathfind.hpp"
|
||||
|
@ -83,9 +84,6 @@ public:
|
|||
|
||||
CVideo& video() { return screen_; }
|
||||
|
||||
enum IMAGE_TYPE { UNSCALED, SCALED, GREYED, BRIGHTENED };
|
||||
SDL_Surface* getImage(const std::string& filename,IMAGE_TYPE type=SCALED);
|
||||
|
||||
//blits a surface with black as alpha
|
||||
void blit_surface(int x, int y, SDL_Surface* surface);
|
||||
|
||||
|
@ -153,12 +151,10 @@ private:
|
|||
|
||||
void bounds_check_position();
|
||||
|
||||
std::vector<SDL_Surface*> getAdjacentTerrain(int x, int y, IMAGE_TYPE type);
|
||||
SDL_Surface* getTerrain(gamemap::TERRAIN, IMAGE_TYPE type,
|
||||
std::vector<SDL_Surface*> getAdjacentTerrain(int x, int y, image::TYPE type);
|
||||
SDL_Surface* getTerrain(gamemap::TERRAIN, image::TYPE type,
|
||||
int x, int y, const std::string& dir="");
|
||||
|
||||
enum TINT { GREY_IMAGE, BRIGHTEN_IMAGE };
|
||||
SDL_Surface* getImageTinted(const std::string& filename, TINT tint);
|
||||
SDL_Surface* getMinimap(int w, int h);
|
||||
|
||||
void clearImageCache();
|
||||
|
@ -173,9 +169,6 @@ private:
|
|||
|
||||
unit_map& units_;
|
||||
|
||||
std::map<std::string,SDL_Surface*> images_, scaledImages_,
|
||||
greyedImages_, brightenedImages_;
|
||||
|
||||
//function which finds the start and end rows on the energy bar image
|
||||
//where white pixels are substituted for the colour of the energy
|
||||
const std::pair<int,int>& calculate_energy_bar();
|
||||
|
|
|
@ -146,6 +146,7 @@ int play_game(int argc, char** argv)
|
|||
const font::manager font_manager;
|
||||
const sound::manager sound_manager;
|
||||
const preferences::manager prefs_manager;
|
||||
const image::manager image_manager;
|
||||
|
||||
bool test_mode = false;
|
||||
|
||||
|
|
|
@ -10,7 +10,9 @@
|
|||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "game_events.hpp"
|
||||
#include "image.hpp"
|
||||
#include "language.hpp"
|
||||
#include "playlevel.hpp"
|
||||
#include "replay.hpp"
|
||||
|
@ -467,7 +469,7 @@ void event_handler::handle_event(const queued_event& event_info, config* cfg)
|
|||
|
||||
SDL_Surface* surface = NULL;
|
||||
if(image.empty() == false) {
|
||||
surface = screen->getImage(image,display::UNSCALED);
|
||||
surface = image::get_image(image,image::UNSCALED);
|
||||
}
|
||||
|
||||
gui::show_dialog(*screen,surface,caption,text);
|
||||
|
@ -547,7 +549,7 @@ void event_handler::handle_event(const queued_event& event_info, config* cfg)
|
|||
|
||||
SDL_Surface* surface = NULL;
|
||||
if(image.empty() == false) {
|
||||
surface = screen->getImage(image,display::UNSCALED);
|
||||
surface = image::get_image(image,image::UNSCALED);
|
||||
}
|
||||
|
||||
const std::string& lang_message = string_table[id];
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include "events.hpp"
|
||||
#include "font.hpp"
|
||||
#include "image.hpp"
|
||||
#include "intro.hpp"
|
||||
#include "key.hpp"
|
||||
#include "language.hpp"
|
||||
|
@ -47,7 +48,7 @@ void show_intro(display& screen, config& data)
|
|||
const std::string& image_name = (*i)->values["image"];
|
||||
SDL_Surface* image = NULL;
|
||||
if(image_name.empty() == false) {
|
||||
image = screen.getImage(image_name,display::UNSCALED);
|
||||
image = image::get_image(image_name,image::UNSCALED);
|
||||
}
|
||||
|
||||
int textx = 200;
|
||||
|
@ -154,11 +155,11 @@ void show_map_scene(display& screen, config& data)
|
|||
|
||||
const std::string& image_file = cfg.values["image"];
|
||||
|
||||
SDL_Surface* const image = screen.getImage(image_file,display::UNSCALED);
|
||||
SDL_Surface* const image = image::get_image(image_file,image::UNSCALED);
|
||||
SDL_Surface* const dot_image =
|
||||
screen.getImage("misc/dot.png",display::UNSCALED);
|
||||
image::get_image("misc/dot.png",image::UNSCALED);
|
||||
SDL_Surface* const cross_image =
|
||||
screen.getImage("misc/cross.png",display::UNSCALED);
|
||||
image::get_image("misc/cross.png",image::UNSCALED);
|
||||
if(image == NULL || dot_image == NULL || cross_image == NULL) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "events.hpp"
|
||||
#include "font.hpp"
|
||||
#include "image.hpp"
|
||||
#include "key.hpp"
|
||||
#include "language.hpp"
|
||||
#include "multiplayer_lobby.hpp"
|
||||
|
@ -23,8 +24,8 @@ RESULT enter(display& disp, config& game_data)
|
|||
|
||||
gui::textbox message_entry(disp,500);
|
||||
|
||||
SDL_Surface* const background = disp.getImage("misc/lobby.png",
|
||||
display::UNSCALED);
|
||||
SDL_Surface* const background = image::get_image("misc/lobby.png",
|
||||
image::UNSCALED);
|
||||
|
||||
update_whole_screen();
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "actions.hpp"
|
||||
#include "events.hpp"
|
||||
#include "hotkeys.hpp"
|
||||
#include "image.hpp"
|
||||
#include "language.hpp"
|
||||
#include "log.hpp"
|
||||
#include "mouse.hpp"
|
||||
|
@ -828,7 +829,7 @@ void turn_info::terrain_table()
|
|||
|
||||
const std::vector<unit> units_list(items.size(),un->second);
|
||||
SDL_Surface* const unit_image =
|
||||
gui_.getImage(un->second.type().image_profile(),display::UNSCALED);
|
||||
image::get_image(un->second.type().image_profile(),image::UNSCALED);
|
||||
gui::show_dialog(gui_,unit_image,un->second.type().language_name(),
|
||||
string_table["terrain_info"],
|
||||
gui::MESSAGE,&items,&units_list);
|
||||
|
@ -870,7 +871,7 @@ void turn_info::attack_resistance()
|
|||
|
||||
const std::vector<unit> units_list(items.size(), un->second);
|
||||
SDL_Surface* const unit_image =
|
||||
gui_.getImage(un->second.type().image_profile(),display::UNSCALED);
|
||||
image::get_image(un->second.type().image_profile(),image::UNSCALED);
|
||||
gui::show_dialog(gui_,unit_image,
|
||||
un->second.type().language_name(),
|
||||
string_table["unit_resistance_table"],
|
||||
|
@ -892,8 +893,8 @@ void turn_info::unit_description()
|
|||
options.push_back(string_table["attack_resistance"]);
|
||||
options.push_back(string_table["close_window"]);
|
||||
|
||||
SDL_Surface* const unit_image = gui_.getImage(
|
||||
un->second.type().image_profile(), display::UNSCALED);
|
||||
SDL_Surface* const unit_image = image::get_image(
|
||||
un->second.type().image_profile(), image::UNSCALED);
|
||||
|
||||
const int res = gui::show_dialog(gui_,unit_image,
|
||||
un->second.type().language_name(),
|
||||
|
|
|
@ -102,8 +102,10 @@ std::pair<int,int> resolution()
|
|||
x->second.empty() == false && y->second.empty() == false) {
|
||||
std::pair<int,int> res (maximum(atoi(x->second.c_str()),1024),
|
||||
maximum(atoi(y->second.c_str()),768));
|
||||
res.first &= ~1;
|
||||
res.second &= ~1;
|
||||
|
||||
//make sure resolutions are always divisible by 4
|
||||
res.first &= ~3;
|
||||
res.second &= ~3;
|
||||
return res;
|
||||
} else {
|
||||
return std::pair<int,int>(1024,768);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "config.hpp"
|
||||
#include "events.hpp"
|
||||
#include "font.hpp"
|
||||
#include "image.hpp"
|
||||
#include "language.hpp"
|
||||
#include "playlevel.hpp"
|
||||
#include "show_dialog.hpp"
|
||||
|
@ -43,14 +44,14 @@ void draw_dialog_frame(int x, int y, int w, int h, display& disp)
|
|||
{
|
||||
draw_dialog_background(x,y,w,h,disp);
|
||||
|
||||
SDL_Surface* const top = disp.getImage("misc/menu-border-top.png",
|
||||
display::UNSCALED);
|
||||
SDL_Surface* const bot = disp.getImage("misc/menu-border-bottom.png",
|
||||
display::UNSCALED);
|
||||
SDL_Surface* const left = disp.getImage("misc/menu-border-left.png",
|
||||
display::UNSCALED);
|
||||
SDL_Surface* const right = disp.getImage("misc/menu-border-right.png",
|
||||
display::UNSCALED);
|
||||
SDL_Surface* const top = image::get_image("misc/menu-border-top.png",
|
||||
image::UNSCALED);
|
||||
SDL_Surface* const bot = image::get_image("misc/menu-border-bottom.png",
|
||||
image::UNSCALED);
|
||||
SDL_Surface* const left = image::get_image("misc/menu-border-left.png",
|
||||
image::UNSCALED);
|
||||
SDL_Surface* const right = image::get_image("misc/menu-border-right.png",
|
||||
image::UNSCALED);
|
||||
|
||||
if(top == NULL || bot == NULL || left == NULL || right == NULL)
|
||||
return;
|
||||
|
@ -81,14 +82,14 @@ void draw_dialog_frame(int x, int y, int w, int h, display& disp)
|
|||
|
||||
update_rect(x-left->w,y-top->h,w+left->w+right->w,h+top->h+bot->h);
|
||||
|
||||
SDL_Surface* const top_left = disp.getImage("misc/menu-border-topleft.png",
|
||||
display::UNSCALED);
|
||||
SDL_Surface* const bot_left = disp.getImage("misc/menu-border-botleft.png",
|
||||
display::UNSCALED);
|
||||
SDL_Surface* const top_right=disp.getImage("misc/menu-border-topright.png",
|
||||
display::UNSCALED);
|
||||
SDL_Surface* const bot_right=disp.getImage("misc/menu-border-botright.png",
|
||||
display::UNSCALED);
|
||||
SDL_Surface* const top_left = image::get_image("misc/menu-border-topleft.png",
|
||||
image::UNSCALED);
|
||||
SDL_Surface* const bot_left = image::get_image("misc/menu-border-botleft.png",
|
||||
image::UNSCALED);
|
||||
SDL_Surface* const top_right = image::get_image("misc/menu-border-topright.png",
|
||||
image::UNSCALED);
|
||||
SDL_Surface* const bot_right = image::get_image("misc/menu-border-botright.png",
|
||||
image::UNSCALED);
|
||||
if(top_left == NULL || bot_left == NULL || top_right == NULL ||
|
||||
bot_right == NULL)
|
||||
return;
|
||||
|
@ -103,7 +104,7 @@ void draw_dialog_background(int x, int y, int w, int h, display& disp)
|
|||
{
|
||||
static const std::string menu_background = "misc/menu-background.png";
|
||||
|
||||
SDL_Surface* const bg = disp.getImage(menu_background,display::UNSCALED);
|
||||
SDL_Surface* const bg = image::get_image(menu_background,image::UNSCALED);
|
||||
|
||||
for(int i = 0; i < w; i += bg->w) {
|
||||
for(int j = 0; j < h; j += bg->h) {
|
||||
|
@ -592,8 +593,8 @@ TITLE_RESULT show_title(display& screen)
|
|||
{
|
||||
const events::resize_lock prevent_resizing;
|
||||
|
||||
SDL_Surface* const title_surface = screen.getImage("title.png",
|
||||
display::UNSCALED);
|
||||
SDL_Surface* const title_surface = image::get_image("title.png",
|
||||
image::UNSCALED);
|
||||
|
||||
if(title_surface == NULL) {
|
||||
std::cerr << "Could not find title image 'title.png'\n";
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "image.hpp"
|
||||
#include "mouse.hpp"
|
||||
#include "preferences.hpp"
|
||||
#include "video.hpp"
|
||||
|
@ -170,6 +171,7 @@ int CVideo::setMode( int x, int y, int bits_per_pixel, int flags )
|
|||
frameBuffer = SDL_SetVideoMode( x, y, bits_per_pixel, flags );
|
||||
|
||||
if( frameBuffer != NULL ) {
|
||||
image::set_pixel_format(frameBuffer->format);
|
||||
return bits_per_pixel;
|
||||
} else return 0;
|
||||
}
|
||||
|
|
|
@ -10,9 +10,11 @@
|
|||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "button.hpp"
|
||||
#include "../game.hpp"
|
||||
#include "../font.hpp"
|
||||
#include "../image.hpp"
|
||||
#include "../util.hpp"
|
||||
#include "../video.hpp"
|
||||
|
||||
|
@ -30,20 +32,19 @@ button::button(display& disp, const std::string& label, button::TYPE type,
|
|||
state_(UNINIT), type_(type)
|
||||
{
|
||||
SDL_Surface* button_image =
|
||||
disp.getImage("buttons/button.png",display::UNSCALED);
|
||||
image::get_image("buttons/button.png",image::UNSCALED);
|
||||
SDL_Surface* pressed_image =
|
||||
disp.getImage("buttons/button-pressed.png", display::UNSCALED);
|
||||
image::get_image("buttons/button-pressed.png", image::UNSCALED);
|
||||
SDL_Surface* active_image =
|
||||
disp.getImage("buttons/button-active.png", display::UNSCALED);
|
||||
|
||||
image::get_image("buttons/button-active.png", image::UNSCALED);
|
||||
|
||||
if(!button_image_name.empty()) {
|
||||
button_image = disp.getImage("buttons/" + button_image_name +
|
||||
"-button.png", display::UNSCALED);
|
||||
pressed_image = disp.getImage("buttons/" + button_image_name +
|
||||
"-button-pressed.png",display::UNSCALED);
|
||||
active_image = disp.getImage("buttons/" + button_image_name +
|
||||
"-button-active.png",display::UNSCALED);
|
||||
button_image = image::get_image("buttons/" + button_image_name +
|
||||
"-button.png", image::UNSCALED);
|
||||
pressed_image = image::get_image("buttons/" + button_image_name +
|
||||
"-button-pressed.png",image::UNSCALED);
|
||||
active_image = image::get_image("buttons/" + button_image_name +
|
||||
"-button-active.png",image::UNSCALED);
|
||||
}
|
||||
|
||||
if(pressed_image == NULL)
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
*/
|
||||
|
||||
#include "slider.hpp"
|
||||
#include "../image.hpp"
|
||||
#include "../video.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -20,8 +21,8 @@
|
|||
namespace gui {
|
||||
|
||||
slider::slider(display& disp, SDL_Rect& rect, double value)
|
||||
: disp_(disp), image_(disp.getImage("buttons/slider.png",display::UNSCALED)),
|
||||
selectedImage_(disp.getImage("buttons/slider-selected.png",display::UNSCALED)),
|
||||
: disp_(disp), image_(image::get_image("buttons/slider.png",image::UNSCALED)),
|
||||
selectedImage_(image::get_image("buttons/slider-selected.png",image::UNSCALED)),
|
||||
buffer_(NULL), area_(rect), value_(value), drawn_(false),
|
||||
highlight_(false), clicked_(true), dragging_(false)
|
||||
{
|
||||
|
@ -35,8 +36,8 @@ slider::slider(display& disp, SDL_Rect& rect, double value)
|
|||
|
||||
int slider::height(display& disp)
|
||||
{
|
||||
SDL_Surface* const image = disp.getImage("buttons/slider.png",
|
||||
display::UNSCALED);
|
||||
SDL_Surface* const image = image::get_image("buttons/slider.png",
|
||||
image::UNSCALED);
|
||||
if(image != NULL)
|
||||
return image->h;
|
||||
else
|
||||
|
|
Loading…
Add table
Reference in a new issue