Made the border themable.

Still doesn't work in the editor, also the
0.5 hex border is still assumed at some places.
This commit is contained in:
Mark de Wever 2007-08-11 13:27:36 +00:00
parent 84c9884fdf
commit 246f65b846
9 changed files with 292 additions and 102 deletions

View file

@ -53,6 +53,33 @@
yanchor=top
[/main_map]
[main_map_border]
border_size = 0.5
background_image = "terrain/off-map/wood" # FIXME rename
corner_image_top_left = "terrain/off-map/fade_corner_top_left.png"
corner_image_bottom_left = "terrain/off-map/fade_corner_bottom_left.png"
# odd means the corner is on a tile with an odd x value,
# the tile is the ingame tile not the odd in C++
corner_image_top_right_odd = "terrain/off-map/fade_corner_top_right_odd.png"
corner_image_top_right_even = "terrain/off-map/fade_corner_top_right_even.png"
corner_image_bottom_right_odd = "terrain/off-map/fade_corner_bottom_right_odd.png"
corner_image_bottom_right_even = "terrain/off-map/fade_corner_bottom_right_even.png"
border_image_left = "terrain/off-map/fade_border_left.png"
border_image_right = "terrain/off-map/fade_border_right.png"
# FIXME the top and bottom images have the wrong for odd/even
border_image_top_odd = "terrain/off-map/fade_border_top_even.png"
border_image_top_even = "terrain/off-map/fade_border_top_odd.png"
border_image_bottom_odd = "terrain/off-map/fade_border_bottom_even.png"
border_image_bottom_even = "terrain/off-map/fade_border_bottom_odd.png"
[/main_map_border]
# rightside panel
[panel]
id=top-right-panel

View file

@ -89,6 +89,33 @@
ref=top-panel
[/main_map]
[main_map_border]
border_size = 0.5
background_image = "terrain/off-map/wood" # FIXME rename
corner_image_top_left = "terrain/off-map/fade_corner_top_left.png"
corner_image_bottom_left = "terrain/off-map/fade_corner_bottom_left.png"
# odd means the corner is on a tile with an odd x value,
# the tile is the ingame tile not the odd in C++
corner_image_top_right_odd = "terrain/off-map/fade_corner_top_right_odd.png"
corner_image_top_right_even = "terrain/off-map/fade_corner_top_right_even.png"
corner_image_bottom_right_odd = "terrain/off-map/fade_corner_bottom_right_odd.png"
corner_image_bottom_right_even = "terrain/off-map/fade_corner_bottom_right_even.png"
border_image_left = "terrain/off-map/fade_border_left.png"
border_image_right = "terrain/off-map/fade_border_right.png"
# FIXME the top and bottom images have the wrong for odd/even
border_image_top_odd = "terrain/off-map/fade_border_top_even.png"
border_image_top_even = "terrain/off-map/fade_border_top_odd.png"
border_image_bottom_odd = "terrain/off-map/fade_border_bottom_even.png"
border_image_bottom_even = "terrain/off-map/fade_border_bottom_odd.png"
[/main_map_border]
[mini_map]
id=mini-map
ref=minimap-panel

View file

@ -488,6 +488,33 @@
yanchor=top
[/main_map]
[main_map_border]
border_size = 0.5
background_image = "terrain/off-map/wood" # FIXME rename
corner_image_top_left = "terrain/off-map/fade_corner_top_left.png"
corner_image_bottom_left = "terrain/off-map/fade_corner_bottom_left.png"
# odd means the corner is on a tile with an odd x value,
# the tile is the ingame tile not the odd in C++
corner_image_top_right_odd = "terrain/off-map/fade_corner_top_right_odd.png"
corner_image_top_right_even = "terrain/off-map/fade_corner_top_right_even.png"
corner_image_bottom_right_odd = "terrain/off-map/fade_corner_bottom_right_odd.png"
corner_image_bottom_right_even = "terrain/off-map/fade_corner_bottom_right_even.png"
border_image_left = "terrain/off-map/fade_border_left.png"
border_image_right = "terrain/off-map/fade_border_right.png"
# FIXME the top and bottom images have the wrong for odd/even
border_image_top_odd = "terrain/off-map/fade_border_top_even.png"
border_image_top_even = "terrain/off-map/fade_border_top_odd.png"
border_image_bottom_odd = "terrain/off-map/fade_border_bottom_even.png"
border_image_bottom_even = "terrain/off-map/fade_border_bottom_odd.png"
[/main_map_border]
[menu]
title=_"File"
image=lite

View file

@ -44,6 +44,33 @@
yanchor=top
[/main_map]
[main_map_border]
border_size = 0.5
background_image = "terrain/off-map/wood" # FIXME rename
corner_image_top_left = "terrain/off-map/fade_corner_top_left.png"
corner_image_bottom_left = "terrain/off-map/fade_corner_bottom_left.png"
# odd means the corner is on a tile with an odd x value,
# the tile is the ingame tile not the odd in C++
corner_image_top_right_odd = "terrain/off-map/fade_corner_top_right_odd.png"
corner_image_top_right_even = "terrain/off-map/fade_corner_top_right_even.png"
corner_image_bottom_right_odd = "terrain/off-map/fade_corner_bottom_right_odd.png"
corner_image_bottom_right_even = "terrain/off-map/fade_corner_bottom_right_even.png"
border_image_left = "terrain/off-map/fade_border_left.png"
border_image_right = "terrain/off-map/fade_border_right.png"
# FIXME the top and bottom images have the wrong for odd/even
border_image_top_odd = "terrain/off-map/fade_border_top_even.png"
border_image_top_even = "terrain/off-map/fade_border_top_odd.png"
border_image_bottom_odd = "terrain/off-map/fade_border_bottom_even.png"
border_image_bottom_even = "terrain/off-map/fade_border_bottom_odd.png"
[/main_map_border]
# rightside panel
[panel]
id=top-right-panel

View file

@ -57,9 +57,6 @@ namespace {
bool benchmark = false;
// number of border hexes, the real size will be border
// and border + 0.5 depending whether the x is odd or even
double border = 0.5;
}
display::display(CVideo& video, const gamemap& map, const config& theme_cfg, const config& cfg, const config& level) :
@ -97,8 +94,8 @@ const SDL_Rect& display::map_area() const
// 3 so there shouldn't be off by one errors due to rounding
// To display a hex fully on screen a little bit extra space is needed
// Also added the border two times.
const int width = static_cast<int>((map_.w() + 2 * border + 1.0/3.0) * hex_width());
const int height = static_cast<int>((map_.h() + 2 * border + 0.5) * hex_size());
const int width = static_cast<int>((map_.w() + 2 * theme_.border().size + 1.0/3.0) * hex_width());
const int height = static_cast<int>((map_.h() + 2 * theme_.border().size + 0.5) * hex_size());
if(width < res.w) {
// map is smaller, center
@ -146,8 +143,8 @@ const gamemap::location display::pixel_position_to_hex(int x, int y,
gamemap::location::DIRECTION* second_nearest_hex) const
{
// adjust for the border
x -= static_cast<int>(border * hex_width());
y -= static_cast<int>(border * hex_size());
x -= static_cast<int>(theme_.border().size * hex_width());
y -= static_cast<int>(theme_.border().size * hex_size());
const int s = hex_size();
const int tesselation_x_size = hex_width() * 2;
const int tesselation_y_size = s;
@ -273,11 +270,11 @@ void display::get_rect_hex_bounds(SDL_Rect rect, gamemap::location &topleft, gam
const int tile_width = hex_width();
// adjust for the border
topleft.x = static_cast<int>(-border + (xpos_ + rect.x) / tile_width);
topleft.y = static_cast<int>(-border + (ypos_ + rect.y - (is_odd(topleft.x) ? zoom_/2 : 0)) / zoom_);
topleft.x = static_cast<int>(-theme_.border().size + (xpos_ + rect.x) / tile_width);
topleft.y = static_cast<int>(-theme_.border().size + (ypos_ + rect.y - (is_odd(topleft.x) ? zoom_/2 : 0)) / zoom_);
bottomright.x = static_cast<int>(-border + (xpos_ + rect.x + rect.w) / tile_width);
bottomright.y = static_cast<int>(-border + ((ypos_ + rect.y + rect.h) - (is_odd(bottomright.x) ? zoom_/2 : 0)) / zoom_);
bottomright.x = static_cast<int>(-theme_.border().size + (xpos_ + rect.x + rect.w) / tile_width);
bottomright.y = static_cast<int>(-theme_.border().size + ((ypos_ + rect.y + rect.h) - (is_odd(bottomright.x) ? zoom_/2 : 0)) / zoom_);
// This routine does a rough approximation so might be off by one
// to be sure enough tiles are incuded the boundries are increased
@ -301,12 +298,12 @@ void display::get_rect_hex_bounds(SDL_Rect rect, gamemap::location &topleft, gam
int display::get_location_x(const gamemap::location& loc) const
{
return static_cast<int>(map_area().x + (loc.x + border) * hex_width() - xpos_);
return static_cast<int>(map_area().x + (loc.x + theme_.border().size) * hex_width() - xpos_);
}
int display::get_location_y(const gamemap::location& loc) const
{
return static_cast<int>(map_area().y + (loc.y + border) * zoom_ - ypos_ + (is_odd(loc.x) ? zoom_/2 : 0));
return static_cast<int>(map_area().y + (loc.y + theme_.border().size) * zoom_ - ypos_ + (is_odd(loc.x) ? zoom_/2 : 0));
}
gamemap::location display::minimap_location_on(int x, int y)
@ -1078,6 +1075,93 @@ surface display::get_minimap(int w, int h)
return minimap_;
}
// FIXME we assume a hardcoded half hex border!!!
void display::draw_border(const gamemap::location& loc, const int xpos, const int ypos)
{
// first handle the corners
if(loc.x == -1 && loc.y == -1) { // top left corner
SDL_Rect rect = { xpos + zoom_/4, ypos, 3 * zoom_/4, zoom_ } ;
const surface border(image::get_image(theme_.border().corner_image_top_left, image::SCALED_TO_ZOOM));
SDL_BlitSurface( border, NULL, screen_.getSurface(), &rect);
} else if(loc.x == map_.w() && loc.y == -1) { // top right corner
SDL_Rect rect = { xpos, -1, 3 * zoom_/4, zoom_ } ;
surface border;
if(loc.x%2 == 0) {
rect.y = ypos + zoom_/2;
rect.h = zoom_/2;
// we use the map idea of odd and even and map coords are internal coords + 1
border = image::get_image(theme_.border().corner_image_top_right_odd, image::SCALED_TO_ZOOM);
} else {
rect.y = ypos;
border = image::get_image(theme_.border().corner_image_top_right_even, image::SCALED_TO_ZOOM);
}
SDL_BlitSurface( border, NULL, screen_.getSurface(), &rect);
} else if(loc.x == -1 && loc.y == map_.h()) { // bottom left corner
SDL_Rect rect = { xpos + zoom_/4, ypos, 3 * zoom_/4, zoom_/2 } ;
const surface border(image::get_image(theme_.border().corner_image_bottom_left, image::SCALED_TO_ZOOM));
SDL_BlitSurface( border, NULL, screen_.getSurface(), &rect);
} else if(loc.x == map_.w() && loc.y == map_.h()) { // bottom right corner
SDL_Rect rect = { xpos, ypos, 3 * zoom_/4, zoom_/2 } ;
surface border;
if(loc.x%2 == 1) {
// we use the map idea of odd and even and map coords are internal coords + 1
border = image::get_image(theme_.border().corner_image_bottom_right_even, image::SCALED_TO_ZOOM);
} else {
border = image::get_image(theme_.border().corner_image_bottom_right_odd, image::SCALED_TO_ZOOM);
}
SDL_BlitSurface( border, NULL, screen_.getSurface(), &rect);
// now handle the sides
} else if(loc.x == -1) { // left side
SDL_Rect rect = { xpos + zoom_/4 , ypos, zoom_/2, zoom_ } ;
const surface border(image::get_image(theme_.border().border_image_left, image::SCALED_TO_ZOOM));
SDL_BlitSurface( border, NULL, screen_.getSurface(), &rect);
} else if(loc.x == map_.w()) { // right side
SDL_Rect rect = { xpos + zoom_/4 , ypos, zoom_/2, zoom_ } ;
const surface border(image::get_image(theme_.border().border_image_right, image::SCALED_TO_ZOOM));
SDL_BlitSurface( border, NULL, screen_.getSurface(), &rect);
} else if(loc.y == -1) { // top side
SDL_Rect rect = { xpos, -1, zoom_, zoom_/2 } ;
surface border;
if(loc.x%2 == 1) {
rect.y = ypos;
border = image::get_image(theme_.border().border_image_top_even, image::SCALED_TO_ZOOM);
} else {
rect.y = ypos + zoom_/2;
border = image::get_image(theme_.border().border_image_top_even, image::SCALED_TO_ZOOM);
}
SDL_BlitSurface( border, NULL, screen_.getSurface(), &rect);
} else if(loc.y == map_.h()) { // bottom side
SDL_Rect rect = { xpos, -1, zoom_, zoom_/2 } ;
surface border;
if(loc.x%2 == 1) {
rect.y = ypos;
// NOTE here is the internal idea off odd and even used
border = image::get_image(theme_.border().border_image_bottom_even, image::SCALED_TO_ZOOM);
} else {
rect.y = ypos + zoom_/2;
border = image::get_image(theme_.border().border_image_bottom_odd, image::SCALED_TO_ZOOM);
}
SDL_BlitSurface( border, NULL, screen_.getSurface(), &rect);
}
}
void display::draw_minimap(int x, int y, int w, int h)
{
const surface surf(get_minimap(w,h));
@ -1359,8 +1443,8 @@ void display::bounds_check_position(int& xpos, int& ypos)
const int tile_width = hex_width();
// adjust for the border 2 times
const int xend = static_cast<int>(tile_width * (map_.w() + 2 * border) + tile_width/3);
const int yend = static_cast<int>(zoom_ * (map_.h() + 2 * border) + zoom_/2);
const int xend = static_cast<int>(tile_width * (map_.w() + 2 * theme_.border().size) + tile_width/3);
const int yend = static_cast<int>(zoom_ * (map_.h() + 2 * theme_.border().size) + zoom_/2);
if(xpos > xend - map_area().w) {
xpos = xend - map_area().w;

View file

@ -329,6 +329,19 @@ public:
std::map<reports::TYPE, std::string> get_report_contents() {return report_;};
protected:
/**
* draws the border tile overlay, the routine determines by itself which
* border it's on and draws an overlay accordingly. The definition of the
* border is stored in the 'main_map_border' part of the theme.
*
* param loc the map location of the tile
* param xpos the on-screen pixels x coordinate of the tile
* param ypos the on-screen pixels y coordinate of the tile
*/
virtual void draw_border(const gamemap::location& loc,
const int xpos, const int ypos);
void draw_minimap(int x, int y, int w, int h);
virtual void zoom_redraw_hook() {};

View file

@ -405,94 +405,8 @@ void game_display::draw(bool update,bool force)
//simulate_delay += 1;
// if the tile is at the border we start to blend it
// NOTE we assume a half hex border!!!
// NOTE everything is hardcoded but it will be moved to the theme code
// in the near future and then also become a separate function
if(!on_map && map_.get_terrain(*it) != t_translation::OFF_MAP_USER) {
// first handle the corners
if(it->x == -1 && it->y == -1) { // top left corner
SDL_Rect rect = { xpos + zoom_/4, ypos, 3 * zoom_/4, zoom_ } ;
const surface border(image::get_image("terrain/off-map/fade_corner_top_left.png", image::SCALED_TO_ZOOM));
SDL_BlitSurface( border, NULL, screen_.getSurface(), &rect);
} else if(it->x == map_.w() && it->y == -1) { // top right corner
SDL_Rect rect = { xpos, -1, 3 * zoom_/4, zoom_ } ;
surface border;
if(it->x%2 == 0) {
rect.y = ypos + zoom_/2;
rect.h = zoom_/2;
// we use the map idea of odd and even and map coords are internal coords + 1
border = image::get_image("terrain/off-map/fade_corner_top_right_odd.png", image::SCALED_TO_ZOOM);
} else {
rect.y = ypos;
border = image::get_image("terrain/off-map/fade_corner_top_right_even.png", image::SCALED_TO_ZOOM);
}
SDL_BlitSurface( border, NULL, screen_.getSurface(), &rect);
} else if(it->x == -1 && it->y == map_.h()) { // bottom left corner
SDL_Rect rect = { xpos + zoom_/4, ypos, 3 * zoom_/4, zoom_/2 } ;
const surface border(image::get_image("terrain/off-map/fade_corner_bottom_left.png", image::SCALED_TO_ZOOM));
SDL_BlitSurface( border, NULL, screen_.getSurface(), &rect);
} else if(it->x == map_.w() && it->y == map_.h()) { // bottom right corner
SDL_Rect rect = { xpos, ypos, 3 * zoom_/4, zoom_/2 } ;
surface border;
if(it->x%2 == 1) {
// we use the map idea of odd and even and map coords are internal coords + 1
border = image::get_image("terrain/off-map/fade_corner_bottom_right_even.png", image::SCALED_TO_ZOOM);
} else {
border = image::get_image("terrain/off-map/fade_corner_bottom_right_odd.png", image::SCALED_TO_ZOOM);
}
SDL_BlitSurface( border, NULL, screen_.getSurface(), &rect);
// now handle the sides
} else if(it->x == -1) { // left side
SDL_Rect rect = { xpos + zoom_/4 , ypos, zoom_/2, zoom_ } ;
const surface border(image::get_image("terrain/off-map/fade_border_left.png", image::SCALED_TO_ZOOM));
SDL_BlitSurface( border, NULL, screen_.getSurface(), &rect);
} else if(it->x == map_.w()) { // right side
SDL_Rect rect = { xpos + zoom_/4 , ypos, zoom_/2, zoom_ } ;
const surface border(image::get_image("terrain/off-map/fade_border_right.png", image::SCALED_TO_ZOOM));
SDL_BlitSurface( border, NULL, screen_.getSurface(), &rect);
} else if(it->y == -1) { // top side
SDL_Rect rect = { xpos, -1, zoom_, zoom_/2 } ;
surface border;
if(it->x%2 == 1) {
rect.y = ypos;
// we use the map idea of odd and even and map coords are internal coords + 1
border = image::get_image("terrain/off-map/fade_border_top_odd.png", image::SCALED_TO_ZOOM);
} else {
rect.y = ypos + zoom_/2;
border = image::get_image("terrain/off-map/fade_border_top_even.png", image::SCALED_TO_ZOOM);
}
SDL_BlitSurface( border, NULL, screen_.getSurface(), &rect);
} else if(it->y == map_.h()) { // bottom side
SDL_Rect rect = { xpos, -1, zoom_, zoom_/2 } ;
surface border;
if(it->x%2 == 1) {
rect.y = ypos;
// NOTE here is the internal idea off odd and even used
border = image::get_image("terrain/off-map/fade_border_bottom_odd.png", image::SCALED_TO_ZOOM);
} else {
rect.y = ypos + zoom_/2;
border = image::get_image("terrain/off-map/fade_border_bottom_even.png", image::SCALED_TO_ZOOM);
}
SDL_BlitSurface( border, NULL, screen_.getSurface(), &rect);
}
draw_border(*it, xpos, ypos);
}
}

View file

@ -271,6 +271,37 @@ theme::object::object(const config& cfg) :
{
}
theme::tborder::tborder() :
size(0.0)
{
}
theme::tborder::tborder(const config& cfg) :
size(lexical_cast_default<double>(cfg["border_size"], 0.0)),
background_image(cfg["background_image"]),
corner_image_top_left(cfg["corner_image_top_left"]),
corner_image_bottom_left(cfg["corner_image_bottom_left"]),
corner_image_top_right_odd(cfg["corner_image_top_right_odd"]),
corner_image_top_right_even(cfg["corner_image_top_right_even"]),
corner_image_bottom_right_odd(cfg["corner_image_bottom_right_odd"]),
corner_image_bottom_right_even(cfg["corner_image_bottom_right_even"]),
border_image_left(cfg["border_image_left"]),
border_image_right(cfg["border_image_right"]),
border_image_top_odd(cfg["border_image_top_odd"]),
border_image_top_even(cfg["border_image_top_even"]),
border_image_bottom_odd(cfg["border_image_bottom_odd"]),
border_image_bottom_even(cfg["border_image_bottom_even"])
{
wassert(size >= 0.0);
}
SDL_Rect& theme::object::location(const SDL_Rect& screen) const
{
if(last_screen_ == screen && !location_modified_)
@ -563,6 +594,12 @@ void theme::add_object(const config& cfg){
LOG_DP << "done adding menu...\n";
}
const config* const border_cfg = cfg.child("main_map_border");
if (border_cfg != NULL) {
border_ = tborder(*border_cfg);
} else {
border_ = tborder();
}
}
void theme::remove_object(std::string id){

View file

@ -63,6 +63,36 @@ class theme
static ANCHORING read_anchor(const std::string& str);
};
struct tborder
{
tborder();
tborder(const config& cfg);
double size;
std::string background_image;
std::string corner_image_top_left;
std::string corner_image_bottom_left;
std::string corner_image_top_right_odd;
std::string corner_image_top_right_even;
std::string corner_image_bottom_right_odd;
std::string corner_image_bottom_right_even;
std::string border_image_left;
std::string border_image_right;
std::string border_image_top_odd;
std::string border_image_top_even;
std::string border_image_bottom_odd;
std::string border_image_bottom_even;
};
public:
class label : public object
@ -175,6 +205,8 @@ public:
static void set_known_themes(const config* cfg);
static std::vector<std::string> get_known_themes();
const tborder& border() const { return border_; }
private:
theme::object& find_element(std::string id);
void add_object(const config& cfg);
@ -193,6 +225,8 @@ private:
std::map<std::string,status_item> status_;
object main_map_, mini_map_, unit_image_;
tborder border_;
};
#endif