51 #include <SDL_image.h>
62 #define ERR_DP LOG_STREAM(err, log_display)
63 #define LOG_DP LOG_STREAM(info, log_display)
64 #define DBG_DP LOG_STREAM(debug, log_display)
68 const int SmallZoom = DefaultZoom / 2;
70 const int MinZoom = 4;
71 const int MaxZoom = 288;
72 size_t sunset_delay = 0;
74 bool benchmark =
false;
76 bool debug_foreground =
false;
85 for (
const game_display::overlay_map::value_type
i : *
overlays_) {
103 const overlay item(img, halo, halo_handle, team_name, item_id, visible_under_fog);
104 overlays_->insert(overlay_map::value_type(loc,item));
129 std::pair<Itor,Itor> itors =
overlays_->equal_range(loc);
130 while(itors.first != itors.second) {
132 if(itors.first->second.image == toDelete || itors.first->second.halo == toDelete || itors.first->second.id == toDelete) {
133 iteratorCopy = itors.first;
148 video2::draw_layering(auto_join),
150 halo_man_(new
halo::manager(*this)),
152 exclusive_unit_draw_requests_(),
155 dont_show_all_(false),
166 redrawMinimap_(false),
167 redraw_background_(true),
168 invalidateAll_(true),
170 diagnostic_label_(0),
174 invalidateGameStatus_(true),
176 reports_object_(&reports_object),
177 scroll_event_(
"scrolled"),
178 complete_redraw_event_(
"completely_redrawn"),
191 previous_invalidated_(),
192 mouseover_hex_overlay_(nullptr),
193 tod_hex_mask1(nullptr),
194 tod_hex_mask2(nullptr),
201 animate_water_(true),
205 map_screenshot_(false),
208 reach_map_changed_(true),
211 invalidated_hexes_(0),
214 idle_anim_rate_(1.0),
215 map_screenshot_surf_(nullptr),
217 draw_coordinates_(false),
218 draw_terrain_codes_(false),
223 , update_panel_image_(true),
271 std::vector<std::string> side_colors;
272 side_colors.reserve(
dc_->
teams().size());
276 side_colors.push_back(side_color);
285 ERR_DP <<
"Cannot rebuild flags for inexistent or unconfigured side " << side <<
'\n';
294 assert(
dc_ !=
nullptr);
296 assert(n <
flags_.size());
306 LOG_DP <<
"Adding flag for team " << n <<
" from animation " << flag <<
"\n";
312 std::vector<std::string>::const_iterator
itor = items.begin();
313 for(; itor != items.end(); ++
itor) {
314 const std::vector<std::string>& items =
utils::split(*itor,
':');
318 if(items.size() > 1) {
320 time = std::stoi(items.back());
325 std::stringstream temp;
326 temp << str <<
"~RC(" << old_rgb <<
">"<< new_rgb <<
")";
340 if(!
get_map().is_village(loc)) {
348 flags_[
i].update_last_draw_time();
355 return sdl::timage();
360 if(!
get_map().is_village(loc)) {
368 flags_[
i].update_last_draw_time();
383 if (!show_everything)
395 w->on_viewer_change(teamindex);
462 std::ostringstream
s;
468 images.push_back(s.str());
473 images.push_back(
"");
479 return variants[abs(loc.
x + loc.
y) % variants.size()];
525 static SDL_Rect max_area = {0, 0, 0, 0};
542 static SDL_Rect max_area;
553 if(max_area.w < res.w) {
555 res.x += (res.w - max_area.w)/2;
559 if(max_area.h < res.h) {
561 res.y += (res.h - max_area.h)/2;
600 const int offset = y < 0 ? 1 : 0;
606 const int tesselation_x_size =
hex_width() * 2;
607 const int tesselation_y_size =
s;
608 const int x_base = x / tesselation_x_size * 2;
609 const int x_mod = x % tesselation_x_size;
610 const int y_base = y / tesselation_y_size;
611 const int y_mod = y % tesselation_y_size;
616 if (y_mod < tesselation_y_size / 2) {
617 if ((x_mod * 2 + y_mod) < (s / 2)) {
620 }
else if ((x_mod * 2 - y_mod) < (s * 3 / 2)) {
629 if ((x_mod * 2 - (y_mod - s / 2)) < 0) {
632 }
else if ((x_mod * 2 + (y_mod - s / 2)) < s * 2) {
641 return map_location(x_base + x_modifier - offset, y_base + y_modifier - offset);
670 if (r.w<=0 || r.h<=0) {
683 int x =
xpos_ - map_rect.x + r.x;
684 int y =
ypos_ - map_rect.y + r.y;
694 res.
left =
static_cast<int>(
std::floor(-border + x / tile_width - 0.3333333));
697 res.
right =
static_cast<int>(
std::floor(-border + (x + r.w-1) / tile_width));
701 res.
top[0] =
static_cast<int>(
std::floor(-border + y / tile_size));
702 res.
top[1] =
static_cast<int>(
std::floor(-border + y / tile_size - 0.5));
703 res.
bottom[0] =
static_cast<int>(
std::floor(-border + (y + r.h-1) / tile_size));
704 res.
bottom[1] =
static_cast<int>(
std::floor(-border + (y + r.h-1) / tile_size - 0.5));
757 if (!map_screenshot) {
766 ERR_DP <<
"Screenshot failed: " << SDL_GetError() <<
'\n';
771 ERR_DP <<
"No map loaded, cannot create a map screenshot.\n";
780 ERR_DP <<
"Could not create screenshot surface, try zooming out.\n";
785 int old_xpos =
xpos_;
786 int old_ypos =
ypos_;
793 DBG_DP <<
"draw() with map_screenshot\n";
807 ERR_DP <<
"Map screenshot failed: " << SDL_GetError() <<
'\n';
859 DBG_DP <<
"positioning sliders...\n";
860 const std::vector<theme::slider>& sliders =
theme_.
sliders();
861 for(std::vector<theme::slider>::const_iterator
i = sliders.begin();
i != sliders.end(); ++
i) {
862 std::shared_ptr<gui::zoom_slider>
s =
find_slider(
i->get_id());
865 s->set_location(loc);
866 s->set_measurements(0,0);
870 DBG_DP <<
"positioning menu buttons...\n";
871 const std::vector<theme::menu>& buttons =
theme_.
menus();
872 for(std::vector<theme::menu>::const_iterator
i = buttons.begin();
i != buttons.end(); ++
i) {
876 b->set_location(loc);
877 b->set_measurements(0,0);
878 b->set_label(
i->title());
879 b->set_image(
i->image());
883 DBG_DP <<
"positioning action buttons...\n";
885 for(std::vector<theme::action>::const_iterator
i = actions.begin();
i != actions.end(); ++
i) {
889 b->set_location(loc);
890 b->set_measurements(0,0);
891 b->set_label(
i->title());
892 b->set_image(
i->image());
899 std::vector<std::shared_ptr<gui::button>> menu_work;
900 std::vector<std::shared_ptr<gui::button>> action_work;
901 std::vector<std::shared_ptr<gui::zoom_slider>> slider_work;
903 DBG_DP <<
"creating sliders...\n";
904 const std::vector<theme::slider>& sliders =
theme_.
sliders();
905 for(std::vector<theme::slider>::const_iterator
i = sliders.begin();
i != sliders.end(); ++
i) {
909 DBG_DP <<
"drawing button " <<
i->get_id() <<
"\n";
910 s->set_id(
i->get_id());
915 if (!
i->tooltip().empty()){
916 s->set_tooltip_string(
i->tooltip());
919 std::shared_ptr<gui::zoom_slider> s_prev =
find_slider(s->id());
922 s->set_max(s_prev->max_value());
923 s->set_min(s_prev->min_value());
924 s->set_value(s_prev->value());
925 s->enable(s_prev->enabled());
928 slider_work.push_back(s);
931 DBG_DP <<
"creating menu buttons...\n";
932 const std::vector<theme::menu>& buttons =
theme_.
menus();
933 for(std::vector<theme::menu>::const_iterator
i = buttons.begin();
i != buttons.end(); ++
i) {
935 if (!
i->is_button())
continue;
939 DBG_DP <<
"drawing button " <<
i->get_id() <<
"\n";
941 b->set_id(
i->get_id());
942 if (!
i->tooltip().empty()){
943 b->set_tooltip_string(
i->tooltip());
948 b->enable(b_prev->enabled());
951 menu_work.push_back(b);
953 DBG_DP <<
"creating action buttons...\n";
955 for(std::vector<theme::action>::const_iterator
i = actions.begin();
i != actions.end(); ++
i) {
959 DBG_DP <<
"drawing button " <<
i->get_id() <<
"\n";
960 b->set_id(
i->get_id());
962 if (!
i->tooltip(0).empty()){
963 b->set_tooltip_string(
i->tooltip(0));
967 if(b_prev) b->enable(b_prev->enabled());
969 action_work.push_back(b);
978 sliders_.assign(slider_work.begin(), slider_work.end());
981 DBG_DP <<
"buttons created\n";
987 btn->set_dirty(
true);
991 btn->set_dirty(
true);
994 for (std::shared_ptr<gui::slider> sld :
sliders_) {
995 sld->set_dirty(
true);
1012 static std::string const dirs[6] = {
"-n",
"-ne",
"-se",
"-s",
"-sw",
"-nw" };
1013 return dirs[n >=
sizeof(dirs)/
sizeof(*dirs) ? 0 :
n];
1022 std::vector<std::string>
names;
1027 enum visibility {FOG=0, SHROUD=1, CLEAR=2};
1028 visibility tiles[6];
1033 for(
int i = 0;
i != 6; ++
i) {
1043 for(
int v = FOG;
v != CLEAR; ++
v) {
1046 for(start = 0; start != 6; ++
start) {
1047 if(tiles[start] !=
v) {
1057 names.push_back(name);
1067 for (
int i = (start+1)%6, cap1 = 0;
i != start && cap1 != 6; ++cap1) {
1069 std::ostringstream
stream;
1071 stream << *image_prefix[
v];
1073 for (
int cap2 = 0;
v == tiles[
i] && cap2 != 6;
i = (
i+1)%6, ++cap2) {
1084 name = stream.str();
1089 names.push_back(name +
".png");
1099 std::vector<sdl::timage>
res;
1101 std::vector<surface>
res;
1106 const sdl::timage
img(image::get_texture(
name, image_type));
1112 res.push_back(surf);
1133 std::vector<sdl::timage>
res;
1135 std::vector<surface>
res;
1143 timeid, builder_terrain_type);
1152 for(
int d=0;
d<6; ++
d){
1176 if(terrains !=
nullptr) {
1182 terrains->begin(); it != terrains->end(); ++it) {
1185 it->get_current_frame() : it->get_first_frame();
1193 const bool off_map = image.
get_filename() == off_map_name;
1194 if(!use_local_light || off_map) {
1196 }
else if(lt.empty()) {
1207 const bool off_map = image.
get_filename() == off_map_name;
1210 }
else if(lt.empty()) {
1217 res.push_back(surf);
1229 const sdl::timage &
img)
1236 const std::vector<sdl::timage> &imgs)
1243 const SDL_Rect &clip)
1250 const std::vector<surface> &
surf,
1251 const SDL_Rect &clip)
1318 const unsigned int x_parity =
static_cast<unsigned int>(loc.
x) & 1;
1320 key_ |= (x_parity << SHIFT_X_PARITY);
1321 key_ |= (
static_cast<unsigned int>(
layer) << SHIFT_LAYER) |
static_cast<unsigned int>(loc.
x +
MAX_BORDER) / 2;
1331 GPU_SetClip(get_render_target(), clip_rect.x, clip_rect.y, clip_rect.w, clip_rect.h);
1347 for (sdl::timage& img : blit.images()) {
1349 screen_.draw_texture(img, blit.x(), blit.y());
1373 for (
const tblit &blit : drawing_buffer_) {
1379 SDL_Rect srcrect = blit.clip();
1380 SDL_Rect *srcrectArg = (srcrect.x | srcrect.y | srcrect.w | srcrect.h)
1381 ? &srcrect :
nullptr;
1398 sunset_delay = (sunset_delay == 0 && delay == 0) ? 3 : delay;
1403 benchmark = !benchmark;
1408 debug_foreground = !debug_foreground;
1413 if(
video().faked()) {
1420 static size_t sunset_timer = 0;
1421 if (sunset_delay && ++sunset_timer > sunset_delay) {
1424 const Uint32
color = SDL_MapRGBA(
video().getSurface()->
format,0,0,0,SDL_ALPHA_OPAQUE);
1453 static int last_sample = SDL_GetTicks();
1454 static int frames = 0;
1456 const int sample_freq = 10;
1457 if(frames == sample_freq) {
1458 const int this_sample = SDL_GetTicks();
1460 const int fps = (frames*1000)/(this_sample - last_sample);
1461 last_sample = this_sample;
1468 std::ostringstream
stream;
1469 stream <<
"fps: " << fps;
1481 flabel.set_position(10, 100);
1507 SDL_Rect& loc = panel.
location(screen);
1509 DBG_DP <<
"panel location: x=" << loc.x <<
", y=" << loc.y
1510 <<
", w=" << loc.w <<
", h=" << loc.h <<
"\n";
1513 if(surf->w != loc.w || surf->h != loc.h) {
1530 int red = (RGB & 0x00FF0000)>>16;
1531 int green = (RGB & 0x0000FF00)>>8;
1532 int blue = (RGB & 0x000000FF);
1537 std::stringstream
color;
1538 color<< c_start << red << c_sep << green << c_sep << blue << c_end;
1548 if(icon.empty() ==
false) {
1551 if(surf->w > loc.w || surf->h > loc.h) {
1555 sdl_blit(surf,
nullptr,target,&loc);
1558 if(text.empty() ==
false) {
1561 }
else if(text.empty() ==
false) {
1582 for(std::vector<theme::label>::const_iterator
i = labels.begin();
i != labels.end(); ++
i) {
1595 const std::vector<theme::panel>& panels =
theme_.
panels();
1596 for(std::vector<theme::panel>::const_iterator
p = panels.begin();
p != panels.end(); ++
p) {
1600 const std::vector<theme::label>& labels =
theme_.
labels();
1601 for(std::vector<theme::label>::const_iterator
i = labels.begin();
i != labels.end(); ++
i) {
1610 void display::draw_panel_image(SDL_Rect *clip)
1614 if (update_panel_image_) {
1616 const std::vector<theme::panel>& panels =
theme_.
panels();
1617 for(std::vector<theme::panel>::const_iterator
p = panels.begin();
p != panels.end(); ++
p) {
1621 panel_image_ = sdl::timage(surf);
1622 update_panel_image_ =
false;
1625 if (clip !=
nullptr)
1626 GPU_SetClip(get_render_target(), clip->x, clip->y, clip->w, clip->h);
1628 video().draw_texture(panel_image_, 0, 0);
1630 if (clip !=
nullptr)
1638 sdl::timage
img(image::get_texture(image));
1644 video.draw_texture(img, area.x, area.y);
1650 if(background.
null()) {
1653 const unsigned int width = background->w;
1654 const unsigned int height = background->h;
1656 const unsigned int w_count =
static_cast<int>(std::ceil(static_cast<double>(area.w) / static_cast<double>(width)));
1657 const unsigned int h_count =
static_cast<int>(std::ceil(static_cast<double>(area.h) / static_cast<double>(height)));
1659 for(
unsigned int w = 0, w_off = area.x;
w < w_count; ++
w, w_off += width) {
1660 for(
unsigned int h = 0, h_off = area.y;
h < h_count; ++
h, h_off += height) {
1662 sdl_blit(background,
nullptr, screen, &clip);
1670 size_t font_size, SDL_Color
color,
double x_in_hex,
double y_in_hex)
1672 if (text.empty())
return;
1674 const size_t font_sz =
static_cast<size_t>(font_size *
get_zoom_factor());
1679 +
static_cast<int>(x_in_hex*
hex_size());
1681 +
static_cast<int>(y_in_hex*
hex_size());
1683 sdl::timage text_img(text_surf);
1684 sdl::timage back_img(back_surf);
1686 for (
int dy=-1; dy <= 1; ++dy) {
1687 for (
int dx=-1; dx <= 1; ++dx) {
1688 if (dx!=0 || dy!=0) {
1695 for (
int dy=-1; dy <= 1; ++dy) {
1696 for (
int dx=-1; dx <= 1; ++dx) {
1697 if (dx!=0 || dy!=0) {
1710 bool hreverse,
bool greyscale,
fixed_t ,
1711 Uint32 ,
double ,
double submerged,
bool vreverse)
1713 int effect_flags = hreverse ? SHADER_EFFECT_FLIP : SHADER_EFFECT_NONE |
1714 vreverse ? SHADER_EFFECT_FLOP : SHADER_EFFECT_NONE |
1715 greyscale ? SHADER_EFFECT_GRAYSCALE : SHADER_EFFECT_NONE;
1717 image.set_effects(effect_flags);
1718 image.set_submerge(submerged);
1727 Uint32 blendto,
double blend_ratio,
double submerged,
bool vreverse)
1750 if(blend_ratio != 0) {
1753 if(alpha >
ftofxp(1.0)) {
1757 }
else if(alpha !=
ftofxp(1.0)) {
1761 if(surf ==
nullptr) {
1762 ERR_DP <<
"surface lost..." << std::endl;
1766 if(submerged > 0.0) {
1768 const int submerge_height = std::max<int>(0, surf->h*(1.0-submerged));
1769 const int depth = surf->h - submerge_height;
1773 if(submerge_height != surf->h) {
1775 float alpha_base = 0.3f;
1776 float alpha_delta = 0.015f;
1777 alpha_delta *=
zoom_ / DefaultZoom;
1778 surf =
submerge_alpha(surf, depth, alpha_base, alpha_delta,
false);
1780 srcrect.y = submerge_height;
1781 srcrect.h = surf->h-submerge_height;
1782 y += submerge_height;
1859 DBG_DP <<
"draw() with invalidateAll\n";
1872 const int current_time = SDL_GetTicks();
1873 const int wait_time =
nextDraw_ - current_time;
1882 if(!force && !benchmark && wait_time > 0) {
1884 SDL_Delay(wait_time);
1903 if((*i)->pressed()) {
1919 if((*i)->pressed()) {
1934 for(std::vector<theme::menu>::const_iterator menu =
theme_.
menus().begin();
1937 std::vector<std::string>::const_iterator hasitem =
1938 std::find(menu->items().begin(), menu->items().end(), item);
1940 if(hasitem != menu->items().end()) {
1973 if(loc.
x == -1 && loc.
y == -1) {
1976 }
else if(loc.
x ==
get_map().
w() && loc.
y == -1) {
1985 }
else if(loc.
x == -1 && loc.
y ==
get_map().
h()) {
2000 }
else if(loc.
x == -1) {
2006 }
else if(loc.
y == -1) {
2033 if(loc.
x == -1 && loc.
y == -1) {
2036 }
else if(loc.
x ==
get_map().
w() && loc.
y == -1) {
2045 }
else if(loc.
x == -1 && loc.
y ==
get_map().
h()) {
2060 }
else if(loc.
x == -1) {
2066 }
else if(loc.
y == -1) {
2092 if(area.w == 0 || area.h == 0) {
2111 SDL_Color back_color = {31,31,23,SDL_ALPHA_OPAQUE};
2133 double shift_x = - border*
hex_width() - (map_out_rect.w - map_rect.w) / 2;
2134 double shift_y = - (border+0.25)*
hex_size() - (map_out_rect.h - map_rect.h) / 2;
2136 int view_x =
static_cast<int>((
xpos_ + shift_x) * xscaling);
2137 int view_y =
static_cast<int>((
ypos_ + shift_y) * yscaling);
2138 int view_w =
static_cast<int>(map_out_rect.w * xscaling);
2139 int view_h =
static_cast<int>(map_out_rect.h * yscaling);
2141 const Uint32 box_color = SDL_MapRGB(
minimap_->format,0xFF,0xFF,0xFF);
2144 view_w + 2, view_h + 2,
2157 if (
fogged(u->get_location()) ||
2159 u->invisible(u->get_location())) ||
2164 int side = u->side();
2175 if (u->movement_left() == u->total_movement())
2177 else if (u->movement_left() == 0)
2187 double u_x = u->get_location().x * xscaling;
2188 double u_y = (u->get_location().y + (
is_odd(u->get_location().x) ? 1 : -1)/4.0) * yscaling;
2190 double u_w = 4.0 / 3.0 * xscaling;
2191 double u_h = yscaling;
2200 const Uint32 mapped_col = SDL_MapRGB(
video().getSurface()->
format,col.r,col.g,col.b);
2212 const int orig_x =
xpos_;
2213 const int orig_y =
ypos_;
2217 const int dx = orig_x -
xpos_;
2218 const int dy = orig_y -
ypos_;
2221 if(dx == 0 && dy == 0)
2234 SDL_Rect srcrect = dstrect;
2243 SDL_SetSurfaceBlendMode(screen_copy, SDL_BLENDMODE_NONE);
2244 SDL_BlitSurface(screen_copy,&srcrect,
screen,&dstrect);
2252 r.y = r.y + r.h + dy;
2259 r.x = r.x + r.w + dx;
2277 return zoom_ == MaxZoom;
2282 return zoom_ == MinZoom;
2290 if (new_zoom < MinZoom) {
2293 if (new_zoom > MaxZoom) {
2296 LOG_DP <<
"new_zoom = " << new_zoom << std::endl;
2297 if (new_zoom !=
zoom_) {
2298 std::shared_ptr<gui::slider> zoom_slider =
find_slider(
"map-zoom-slider");
2300 zoom_slider->set_value(new_zoom);
2308 if (
zoom_ != DefaultZoom) {
2328 if (
zoom_ != DefaultZoom) {
2351 return x + hs >= area.x - hw && x < area.x + area.w + hw &&
2352 y + hs >= area.y - hs && y < area.y + area.h + hs;
2362 const int xmove_expected = screenxpos - (area.x + area.w/2);
2363 const int ymove_expected = screenypos - (area.y + area.h/2);
2365 int xpos =
xpos_ + xmove_expected;
2366 int ypos =
ypos_ + ymove_expected;
2368 int xmove = xpos -
xpos_;
2369 int ymove = ypos -
ypos_;
2372 scroll(xmove,ymove,
true);
2382 const double dist_total = hypot(xmove, ymove);
2383 double dist_moved = 0.0;
2385 int t_prev = SDL_GetTicks();
2387 double velocity = 0.0;
2388 while (dist_moved < dist_total) {
2391 int t = SDL_GetTicks();
2392 double dt = (t - t_prev) / 1000.0;
2404 double accel = velocity_max / accel_time;
2405 double decel = velocity_max / decel_time;
2408 double stop_time = velocity / decel;
2409 double dist_stop = dist_moved + velocity*stop_time - 0.5*decel*stop_time*stop_time;
2410 if (dist_stop > dist_total || velocity > velocity_max) {
2411 velocity -= decel * dt;
2412 if (velocity < 1.0) velocity = 1.0;
2414 velocity += accel * dt;
2415 if (velocity > velocity_max) velocity = velocity_max;
2418 dist_moved += velocity * dt;
2419 if (dist_moved > dist_total) dist_moved = dist_total;
2421 int x_new =
round_double(xmove * dist_moved / dist_total);
2422 int y_new =
round_double(ymove * dist_moved / dist_total);
2424 int dx = x_new - x_old;
2425 int dy = y_new - y_old;
2436 if(
get_map().on_board(loc) ==
false) {
2437 ERR_DP <<
"Tile at " << loc <<
" isn't on the map, can't scroll to the tile." << std::endl;
2441 std::vector<map_location> locs;
2442 locs.push_back(loc);
2448 double add_spacing,
bool force)
2450 std::vector<map_location> locs;
2451 locs.push_back(loc1);
2452 locs.push_back(loc2);
2453 scroll_to_tiles(locs, scroll_type, check_fogged,
false, add_spacing,force);
2457 const std::vector<map_location>::const_iterator &
end,
2459 bool only_if_possible,
double add_spacing,
bool force)
2468 for(std::vector<map_location>::const_iterator
itor = begin;
itor !=
end ; ++
itor) {
2482 int minx_new = std::min<int>(minx,
x);
2483 int miny_new = std::min<int>(miny,
y);
2484 int maxx_new = std::max<int>(maxx,
x);
2485 int maxy_new = std::max<int>(maxy,
y);
2491 if (only_if_possible)
return;
2519 locs_bbox.w = maxx - minx +
hex_size();
2520 locs_bbox.h = maxy - miny +
hex_size();
2523 int target_x = locs_bbox.x + locs_bbox.w/2;
2524 int target_y = locs_bbox.y + locs_bbox.h/2;
2529 int map_center_x = r.x + r.w/2;
2530 int map_center_y = r.y + r.h/2;
2536 double inside_frac = 0.5;
2537 w =
static_cast<int>(w * inside_frac);
2538 h =
static_cast<int>(h * inside_frac);
2548 r.x = target_x - w/2;
2549 r.y = target_y - h/2;
2557 if (map_center_x < r.x) {
2559 target_y = map_center_y;
2560 if (target_y < r.y) target_y = r.y;
2561 if (target_y > r.y+r.h-1) target_y = r.y+r.h-1;
2562 }
else if (map_center_x > r.x+r.w-1) {
2563 target_x = r.x+r.w-1;
2564 target_y = map_center_y;
2565 if (target_y < r.y) target_y = r.y;
2566 if (target_y >= r.y+r.h) target_y = r.y+r.h-1;
2567 }
else if (map_center_y < r.y) {
2569 target_x = map_center_x;
2570 if (target_x < r.x) target_x = r.x;
2571 if (target_x > r.x+r.w-1) target_x = r.x+r.w-1;
2572 }
else if (map_center_y > r.y+r.h-1) {
2573 target_y = r.y+r.h-1;
2574 target_x = map_center_x;
2575 if (target_x < r.x) target_x = r.x;
2576 if (target_x > r.x+r.w-1) target_x = r.x+r.w-1;
2578 ERR_DP <<
"Bug in the scrolling code? Looks like we would not need to scroll after all..." << std::endl;
2589 const int orig_zoom =
zoom_;
2591 if(
zoom_ < MinZoom) {
2595 if(
zoom_ > MaxZoom) {
2601 if(
zoom_ != orig_zoom) {
2634 if(
keys_[SDLK_LSHIFT] ||
keys_[SDLK_RSHIFT]) {
2659 reportImages_.clear();
2682 int ticks1 = SDL_GetTicks();
2684 int ticks2 = SDL_GetTicks();
2686 int ticks3 = SDL_GetTicks();
2687 LOG_DP <<
"invalidate and draw: " << (ticks3 - ticks2) <<
" and " << (ticks2 - ticks1) <<
"\n";
2711 draw(update,
false);
2850 if(
grid_ && on_map && !off_map_tile) {
2862 if(
grid_ && on_map && !off_map_tile) {
2876 typedef overlay_map::const_iterator Itor;
2877 std::pair<Itor,Itor> overlays =
overlays_->equal_range(loc);
2878 const bool have_overlays = overlays.first != overlays.second;
2895 for( ; overlays.first != overlays.second; ++overlays.first) {
2896 if ((overlays.first->second.team_name ==
"" ||
2897 overlays.first->second.team_name.find(
dc_->
teams()[
viewing_team()].team_name()) != std::string::npos)
2898 && !(
fogged(loc) && !overlays.first->second.visible_in_fog))
2902 const sdl::timage img = use_local_light
2904 : image::get_texture(overlays.first->second.image, image_type);
2922 }
else if(!tod_hex_mask.empty()) {
2930 }
else if(!tod_hex_mask.empty()) {
2947 arrows_map_t::const_iterator arrows_in_hex =
arrows_map_.find(loc);
2949 for (
arrow*
const a : arrows_in_hex->second) {
2962 image::get_texture(shroud_image, image_type));
2966 image::get_texture(fog_image, image_type));
2994 off_x -= text->w / 2;
2998 off_y -= text->h / 2;
3015 off_x -= text->w / 2;
3017 off_y -= text->h / 2;
3029 if(debug_foreground) {
3032 image::get_texture(
"terrain/foreground.png", image_type));
3052 const float scale_factor = std::min(rect.w / img.base_width(), rect.h / img.base_height());
3053 img.set_scale(scale_factor, scale_factor);
3054 const int xpos = rect.x + (rect.w - img.width())/2;
3055 const int ypos = rect.y + (rect.h - img.height())/2;
3057 screen_.draw_texture(img, xpos, ypos);
3063 SDL_Rect target = rect;
3064 if(visible_area.x != 0 || visible_area.y != 0 || visible_area.w != img->w || visible_area.h != img->h) {
3065 if(visible_area.w == 0 || visible_area.h == 0) {
3069 if(visible_area.w > rect.w || visible_area.h > rect.h) {
3074 visible_area.w = img->w;
3075 visible_area.h = img->h;
3077 target.x = rect.x + (rect.w - visible_area.w)/2;
3078 target.y = rect.y + (rect.h - visible_area.h)/2;
3079 target.w = visible_area.w;
3080 target.h = visible_area.h;
3085 if(img->w != rect.w || img->h != rect.h) {
3104 reportImages_[report_name] = sdl::timage();
3110 boost::optional <events::mouse_handler &> mhb = boost::none;
3119 if ( new_cfg ==
nullptr )
3120 new_cfg = &generated_cfg;
3124 sdl::timage &img = reportImages_[report_name];
3128 if (!img.null() && rect == new_rect && report == *new_cfg) {
3136 screen_.draw_texture(img, rect.x, rect.y);
3140 if (img.null() || new_rect != rect)
3142 img = sdl::timage();
3160 draw_panel_image(&rect);
3162 if (report.empty())
return;
3164 int x = rect.x, y = rect.y;
3171 config &
e = report.add_child_at(
"element", config(), 0);
3173 e[
"tooltip"] = report.
child(
"element")[
"tooltip"];
3177 config &
e = report.add_child(
"element");
3179 e[
"tooltip"] = report.
child(
"element", -1)[
"tooltip"];
3184 int image_count = 0;
3185 bool used_ellipsis =
false;
3186 std::ostringstream ellipsis_tooltip;
3187 SDL_Rect ellipsis_area = rect;
3190 elements.first != elements.second; ++elements.first)
3192 SDL_Rect area =
sdl::create_rect(x, y, rect.w + rect.x - x, rect.h + rect.y - y);
3193 if (area.h <= 0)
break;
3198 if (used_ellipsis)
goto skip_element;
3209 if (t[t.size() - 1] ==
'\n') {
3211 t = t.substr(0, t.size() - 1);
3217 sdl::timage text_img = text.render_as_texture();
3220 const int minimal_text = 12;
3222 if (!eol && rect.w - (x - rect.x + text_img.width()) < minimal_text &&
3223 ++ee != elements.second && !(*ee)[
"text"].empty())
3230 text_img = text.render_as_texture();
3232 used_ellipsis =
true;
3233 ellipsis_area.x =
x;
3234 ellipsis_area.y =
y;
3235 ellipsis_area.w = text_img.width();
3236 ellipsis_area.h = text_img.height();
3239 screen_.draw_texture(text_img, x, y);
3240 area.w = text_img.width();
3241 area.h = text_img.height();
3242 if (area.h > tallest) {
3253 else if (!(t = (*elements.first)[
"image"].str()).empty())
3255 if (used_ellipsis)
goto skip_element;
3258 sdl::timage
image(image::get_texture(t));
3261 ERR_DP <<
"could not find image for report: '" << t <<
"'" << std::endl;
3265 if (area.w < image.width() && image_count) {
3268 used_ellipsis =
true;
3271 if (image.width() < area.w) area.w = image.width();
3272 if (image.height() < area.h) area.h = image.height();
3276 if (area.h > tallest) {
3280 if (!used_ellipsis) {
3283 ellipsis_area = area;
3293 t = (*elements.first)[
"tooltip"].t_str().base_str();
3295 if (!used_ellipsis) {
3301 ellipsis_tooltip <<
t;
3303 if (++ee != elements.second)
3304 ellipsis_tooltip <<
"\n _________\n\n";
3309 if (used_ellipsis) {
3321 boost::optional <events::mouse_handler &> mhb = boost::none;
3330 if ( new_cfg ==
nullptr )
3331 new_cfg = &generated_cfg;
3336 config &report =
reports_[report_name];
3339 if (surf && rect == new_rect && report == *new_cfg) {
3352 if (!surf || new_rect != rect)
3361 if (rect.w > 0 && rect.h > 0) {
3364 ERR_DP <<
"Could not backup background for report!" << std::endl;
3372 if (report.
empty())
return;
3374 int x = rect.x, y = rect.y;
3383 e[
"tooltip"] = report.
child(
"element")[
"tooltip"];
3389 e[
"tooltip"] = report.
child(
"element", -1)[
"tooltip"];
3394 int image_count = 0;
3395 bool used_ellipsis =
false;
3396 std::ostringstream ellipsis_tooltip;
3397 SDL_Rect ellipsis_area = rect;
3400 elements.first != elements.second; ++elements.first)
3402 SDL_Rect area =
sdl::create_rect(x, y, rect.w + rect.x - x, rect.h + rect.y - y);
3403 if (area.h <= 0)
break;
3408 if (used_ellipsis)
goto skip_element;
3419 if (t[t.size() - 1] ==
'\n') {
3421 t = t.substr(0, t.size() - 1);
3430 const int minimal_text = 12;
3432 if (!eol && rect.w - (x - rect.x + s->w) < minimal_text &&
3433 ++ee != elements.second && !(*ee)[
"text"].empty())
3442 used_ellipsis =
true;
3443 ellipsis_area.x =
x;
3444 ellipsis_area.y =
y;
3445 ellipsis_area.w = s->w;
3446 ellipsis_area.h = s->h;
3452 if (area.h > tallest) {
3463 else if (!(t = (*elements.first)[
"image"].str()).empty())
3465 if (used_ellipsis)
goto skip_element;
3471 ERR_DP <<
"could not find image for report: '" << t <<
"'" << std::endl;
3475 if (area.w < img->w && image_count) {
3478 used_ellipsis =
true;
3481 if (img->w < area.w) area.w = img->w;
3482 if (img->h < area.h) area.h = img->h;
3486 if (area.h > tallest) {
3490 if (!used_ellipsis) {
3493 ellipsis_area = area;
3503 t = (*elements.first)[
"tooltip"].t_str().base_str();
3505 if (!used_ellipsis) {
3511 ellipsis_tooltip <<
t;
3513 if (++ee != elements.second)
3514 ellipsis_tooltip <<
"\n _________\n\n";
3519 if (used_ellipsis) {
3527 DBG_DP <<
"invalidate_all()\n";
3530 #pragma omp critical(invalidated_)
3543 #pragma omp critical(invalidated_)
3556 #pragma omp critical(invalidated_)
3573 #pragma omp critical(invalidated_)
3577 std::set<map_location>::const_iterator
i = locs.begin();
3578 for(; i != locs.end() &&
invalidated_.count(*i) == 0 ; ++
i) {}
3580 if (i != locs.end()) {
3611 if (
get_map().is_village(loc)) {
3613 if (owner >= 0 &&
flags_[owner].need_update()
3628 if (
builder_->update_animation(loc)) {
3638 u.anim_comp().refresh();
3641 u->anim_comp().refresh();
3644 std::vector<const unit *> open_mp_list;
3646 open_mp_list.push_back(&u);
3652 for (
const unit* u : *fake_unit_man_) {
3653 open_mp_list.push_back(u);
3657 const int omp_iterations = open_mp_list.size();
3664 for (
int i = 0;
i < omp_iterations;
i++) {
3665 open_mp_list[
i]->anim_comp().refresh();
3675 new_inval |= u.anim_comp().invalidate(*
this);
3677 for (
const unit* u : *fake_unit_man_) {
3678 new_inval |= u->anim_comp().invalidate(*
this);
3681 #pragma omp parallel for reduction(|:new_inval) shared(open_mp_list)
3682 for (
int i = 0;
i < omp_iterations;
i++) {
3683 new_inval |= open_mp_list[
i]->anim_comp().invalidate(*
this);
3686 }
while (new_inval);
3746 for (;i !=
end; ++
i) {
3748 if (reach == full.end()) {
3751 }
else if (reach->second != 1) {
3764 if (reach_old->second != reach->second) {
3779 if (event.type == SDL_WINDOWEVENT) {
3780 switch (event.window.event) {
3781 case SDL_WINDOWEVENT_RESIZED:
3782 case SDL_WINDOWEVENT_RESTORED:
3783 case SDL_WINDOWEVENT_EXPOSED:
std::shared_ptr< gui::button > find_action_button(const std::string &id)
Retrieves a pointer to a theme UI button.
play_controller * controller
TYPE
UNSCALED : image will be drawn "as is" without changing size, even in case of redraw SCALED_TO_ZOOM :...
void drawing_buffer_add(const tdrawing_layer layer, const map_location &loc, int x, int y, const surface &surf, const SDL_Rect &clip=SDL_Rect())
Add an item to the drawing buffer.
static void sunset(const size_t delay=0)
Debug function to toggle the "sunset" mode.
void drawing_buffer_commit()
Draws the drawing_buffer_ and clears it.
boost::scoped_ptr< fake_unit_manager > fake_unit_man_
void draw_minimap_units()
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
child_itors child_range(const std::string &key)
void GPU_UnsetClip(GPU_Target *target)
void raise_volatile_undraw_event()
SDL_Rect intersect_rects(SDL_Rect const &rect1, SDL_Rect const &rect2)
Calculates the intersection of two rectangles.
std::string unmoved_color()
void recalculate_shroud()
Don't draw to this layer it's a dummy to size the vector.
std::set< map_location > previous_invalidated_
events::mouse_handler & get_mouse_handler_base()
Get a reference to a mouse handler member a derived class uses.
virtual void pre_draw()
Called near the beginning of each draw() call.
const std::string & id() const
bool fogged(const map_location &loc) const
Returns true if location (x,y) is covered in fog.
surface getMinimap(int w, int h, const gamemap &map, const team *vw, const std::map< map_location, unsigned int > *reach_map)
function to create the minimap for a given map the surface returned must be freed by the user ...
const std::string & text() const
surface create_neutral_surface(int w, int h)
virtual void select_hex(map_location hex)
::tod_manager * tod_manager
Arrows destined to be drawn on the map.
static const unsigned int max_layer_group
reports * reports_object_
Used for the bottom half part of grid image.
bool minimap_draw_units()
virtual void handle_window_event(const SDL_Event &event)
std::string border_image_bottom_odd
std::string border_image_top_even
void invalidate_game_status()
Function to invalidate the game status displayed on the sidebar.
Small struct to store and manipulate ToD colors.
std::shared_ptr< gui::zoom_slider > find_slider(const std::string &id)
virtual bool in_editor() const
const map_location pixel_position_to_hex(int x, int y) const
given x,y co-ordinates of a pixel on the map, will return the location of the hex that this pixel cor...
GLint GLint GLsizei GLsizei GLsizei depth
void adjust_color_overlay(int r, int g, int b)
Add r,g,b to the colors for all images displayed on the map.
std::string image_mask
The image that is to be laid over all images while this time of day lasts.
void fill_rect(surface &dst, SDL_Rect *dst_rect, const Uint32 color)
Fill a rectangle on a given surface.
void invalidate_animations()
Function to invalidate animated terrains and units which may have changed.
virtual void draw_sidebar()
Called near the end of a draw operation, derived classes can use this to render a specific sidebar...
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
void draw_wrap(bool update, bool force)
std::string border_image_bottom_even
boost::weak_ptr< wb::manager > wb_
bool animate_water_
Local version of preferences::animate_water, used to detect when it's changed.
virtual void notify_observers()
tod_color color
The color modifications that should be made to the game board to reflect the time of day...
std::map< surface, SDL_Rect > energy_bar_rects_
const std::string & get_variant(const std::vector< std::string > &variants, const map_location &loc) const
std::string border_image_top_odd
static void toggle_benchmark()
Toggle to continuously redraw the screen.
std::string corner_image_top_left
void set_clip_rect(const SDL_Rect &r)
void change_display_context(const display_context *dc)
const SDL_Rect & minimap_area() const
const SDL_Color BLACK_COLOR
bool rects_overlap(const SDL_Rect &rect1, const SDL_Rect &rect2)
Tests whether two rectangles overlap.
void set_team_colors(const std::vector< std::string > *colors)
set the team colors used by the TC image modification use a vector with one string for each team usin...
GLuint GLuint GLsizei GLenum type
Uint32 rep() const
High-contrast shade, intended for the minimap markers.
surface reverse_image(const surface &surf)
function to reverse an image.
void draw_init()
Initiate a redraw.
void set_default_zoom()
Sets the zoom amount to the default.
void set_idle_anim_rate(int rate)
void scroll_floating_labels(double xmove, double ymove)
moves all floating labels that have 'scroll_mode' set to ANCHOR_LABEL_MAP
SDL_Color int_to_color(const Uint32 rgb)
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
arrow_path_t const & get_path() const
bool minimap_movement_coding()
std::map< std::string, SDL_Rect > reportRects_
static int report(lua_State *L, int status)
void draw_all_panels()
redraw all panels associated with the map display
virtual void draw_invalidated()
Only called when there's actual redrawing to do.
const SDL_Rect empty_rect
map_location mouseoverHex_
void init_flags()
Init the flag list and the team colors used by ~TC.
Manages a list of fake units for the display object.
static void draw_background(surface screen, const SDL_Rect &area, const std::string &image)
void lock_updates(bool value)
bool draw_coordinates_
Debug flag - overlay x,y coords on tiles.
void remove_floating_label(int handle)
removes the floating label given by 'handle' from the screen
void redraw_everything()
Invalidates entire screen, including all tiles and sidebar.
static lg::log_domain log_display("display")
int fps_handle_
Handle for the label which displays frames per second.
GLenum GLsizei GLenum GLenum const GLvoid * image
The class terrain_builder is constructed from a config object, and a gamemap object.
map_location minimap_location_on(int x, int y)
given x,y co-ordinates of the mouse, will return the location of the hex in the minimap that the mous...
Layer for the terrain drawn behind the unit.
void reset_halo_manager()
void add_frame(int duration, const T &value, bool force_change=false)
Adds a frame to an animation.
virtual void draw_border(const map_location &loc, const int xpos, const int ypos)
Draws the border tile overlay.
bool tile_nearly_on_screen(const map_location &loc) const
Checks if location loc or one of the adjacent tiles is visible on screen.
const map_location hex_clicked_on(int x, int y) const
given x,y co-ordinates of an onscreen pixel, will return the location of the hex that this pixel corr...
ttext & set_font_size(const unsigned font_size)
const std::vector< menu > & menus() const
const std::string & image() const
int village_owner(const map_location &loc) const
Given the location of a village, will return the 0-based index of the team that currently owns it...
const rect_of_hexes & rect_
double get_zoom_factor() const
Returns the current zoom factor.
iterator & operator++()
increment y first, then when reaching bottom, increment x
std::vector< std::function< void(display &)> > redraw_observers_
int get_location_x(const map_location &loc) const
Functions to get the on-screen positions of hexes.
bool tile_fully_on_screen(const map_location &loc)
Check if a tile is fully visible on screen.
std::vector< surface > get_terrain_images(const map_location &loc, const std::string &timeid, image::TYPE type, TERRAIN_TYPE terrain_type)
std::string border_image_right
GLint GLint GLint GLint GLint GLint y
map_location selectedHex_
void set_font_size(int font_size)
void draw_text_in_hex(const map_location &loc, const tdrawing_layer layer, const std::string &text, size_t font_size, SDL_Color color, double x_in_hex=0.5, double y_in_hex=0.5)
Draw text on a hex.
std::string corner_image_bottom_right_even
const std::vector< std::string > items
surface scale_surface(const surface &surf, int w, int h)
static display * singleton_
ttext & set_maximum_width(int width)
void blit_surface(int x, int y, surface surf, SDL_Rect *srcrect=nullptr, SDL_Rect *clip_rect=nullptr)
virtual void draw()
Draws invalidated items.
const config & child_or_empty(const std::string &key) const
Returns the first child with the given key, or an empty config if there is none.
surface get_surface_portion(const surface &src, SDL_Rect &area)
Get a portion of the screen.
void enable_menu(const std::string &item, bool enable)
Finds the menu which has a given item in it, and enables or disables it.
Rectangular area of hexes, allowing to decide how the top and bottom edges handles the vertical shift...
an object to leave the synced context during draw or unsynced wml items when we don’t know whether w...
void clear_redraw_observers()
Clear the redraw observers.
bool font_rgb_set() const
const SDL_Color NORMAL_COLOR
const t_terrain OFF_MAP_USER
virtual const gamemap & map() const =0
std::vector< surface > get_fog_shroud_images(const map_location &loc, image::TYPE image_type)
int round_double(double d)
void remove_arrow(arrow &)
std::pair< const_child_iterator, const_child_iterator > const_child_itors
SDL_Rect get_non_transparent_portion(const surface &surf)
Layer for the terrain drawn in front of the unit.
Top half part of grid image.
void update_display()
Copy the backbuffer to the framebuffer.
std::vector< map_location > arrow_path_t
SDL_Rect & location(const SDL_Rect &screen) const
Unit and team statistics.
Mouseover overlay used by editor.
int get_location_y(const map_location &loc) const
very simple iterator to walk into the rect_of_hexes
virtual const tod_manager & get_tod_man() const
This is implemented properly in game_display. The display:: impl could be pure virtual here but we de...
bool save_image(const locator &i_locator, const std::string &filename)
"black stripes" on unreachable hexes.
std::vector< std::shared_ptr< gui::button > > action_buttons_
surface map_screenshot_surf_
static const tdrawing_layer layer_groups[]
const theme::action * action_pressed()
void blit_surface(const surface &surf, const SDL_Rect *srcrect, surface &dst, const SDL_Rect *dstrect)
Replacement for sdl_blit.
GLdouble GLdouble GLdouble b
std::vector< std::string > shroud_images_
void draw_image_for_report(surface &img, SDL_Rect &rect)
Object which defines a time of day with associated bonuses, image, sounds etc.
bool exists(const image::locator &i_locator)
returns true if the given image actually exists, without loading it.
void blindfold(bool flag)
static std::vector< team > *& teams
tdrawing_layer
The layers to render something on.
const std::vector< label > & labels() const
events::generic_event complete_redraw_event_
notify observers that the screen has been redrawn completely atm this is used for replay_controller t...
void parse_team_overlays()
Check the overlay_map for proper team-specific overlays to be displayed/hidden.
This class stores all the data for a single 'side' (in game nomenclature).
bool font_rgb_set() const
int floor(tfloat< T, S > lhs)
light_string get_light_string(int op, int r, int g, int b)
return light_string of one light operation(see above)
size_t playing_team() const
The playing team is the team whose turn it is.
const theme::menu * menu_pressed()
void draw_centered_on_background(surface surf, const SDL_Rect &rect, const SDL_Color &color, surface target)
GLenum GLenum GLuint GLint GLint layer
const SDL_Color BAD_COLOR
Arrows destined to be drawn on the map.
void set_lifetime(int lifetime)
ttext & set_maximum_height(int height, bool multiline)
bool invalidate_visible_locations_in_rect(const SDL_Rect &rect)
void recalculate_minimap()
Schedule the minimap for recalculation.
void scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_type, bool force=true)
const status_item * get_status_item(const std::string &item) const
GLubyte GLubyte GLubyte GLubyte w
const std::string & postfix() const
GLsizei const GLfloat * value
static Uint8 red(Uint32 color)
surface adjust_surface_alpha(const surface &surf, fixed_t amount, bool optimize)
bool map_screenshot_
Used to indicate to drawing functions that we are doing a map screenshot.
const std::string & get_id() const
int w() const
Effective map width.
arrows_map_t arrows_map_
Maps the list of arrows for each location.
virtual image::TYPE get_image_type(const map_location &loc)
config generate_report(const std::string &name, context &ct, bool only_static=false)
GLboolean GLboolean GLboolean GLboolean a
surface blend_surface(const surface &surf, const double amount, const Uint32 color, const bool optimize)
Blends a surface with a color.
std::string corner_image_top_right_even
const std::string & icon() const
SDL_Rect minimap_location_
void set_color(const SDL_Color &color)
void render_image(int x, int y, const display::tdrawing_layer drawing_layer, const map_location &loc, surface image, bool hreverse=false, bool greyscale=false, fixed_t alpha=ftofxp(1.0), Uint32 blendto=0, double blend_ratio=0, double submerged=0.0, bool vreverse=false)
Draw an image at a certain location.
int w() const
the dimensions of the display.
const SDL_Rect & max_map_area() const
Returns the maximum area used for the map regardless to resolution and view size. ...
bool empty() const
Tell if the map is of 0 size.
TERRAIN_TYPE
Used as a parameter for the get_terrain_at function.
config & add_child(const std::string &key)
const std::string & team_name() const
const menu * get_menu_item(const std::string &key) const
GLclampf GLclampf GLclampf alpha
std::string corner_image_bottom_left
fake_unit_manager * fake_units
default layer for drawing moving units
void bounds_check_position()
virtual void post_draw()
Called at the very end of each draw() call.
Modify, read and display user preferences.
bool invalidateGameStatus_
void set_position(double xpos, double ypos)
void update_arrow(arrow &a)
Called by arrow objects when they change.
map_display and display: classes which take care of displaying the map and game-data on the screen...
virtual const unit_map & units() const =0
int nextDraw_
Holds the tick count for when the next drawing event is scheduled.
static const std::string & get_direction(size_t n)
std::string shroud_prefix
virtual const time_of_day & get_time_of_day(const map_location &loc=map_location::null_location()) const
void invalidate_all()
Function to invalidate all tiles.
bool is_blindfolded() const
int invalidated_hexes_
Count work done for the debug info displayed under fps.
bool draw_terrain_codes_
Debug flag - overlay terrain codes on tiles.
GLuint const GLuint * names
const std::string eol
end of line + possible various character before.
GPU_Rect GPU_SetClip(GPU_Target *target, Sint16 x, Sint16 y, Uint16 w, Uint16 h)
tdrawing_buffer drawing_buffer_
surface flop_surface(const surface &surf, bool optimize)
const std::string ¶meters float amount
bool point_in_rect(int x, int y, const SDL_Rect &rect)
Tests whether a point is inside a rectangle.
void set_color_adjustment(int r, int g, int b)
will make all scaled images have these rgb values added to all their pixels.
arrow_path_t const & get_previous_path() const
void write(config &cfg) const
Encapsulates the map of the game.
void set_team(const team *)
surface submerge_alpha(const surface &surf, int depth, float alpha_base, float alpha_delta, bool optimize)
Progressively reduce alpha of bottom part of the surface.
const std::string & get_filename() const
double turbo_speed() const
Reserve layers to be selected for WML.
std::string background_image
boost::scoped_ptr< terrain_builder > builder_
default layer for drawing units
boost::scoped_ptr< map_labels > map_labels_
void process_reachmap_changes()
SDL_Rect draw_text(surface &dst, const SDL_Rect &area, int size, const SDL_Color &color, const std::string &txt, int x, int y, bool use_tooltips, int style)
Function to draw text on a surface.
void recalculate_labels()
virtual void handle_event(const SDL_Event &)
std::string corner_image_bottom_right_odd
surface & get_screen_surface()
return the screen surface or the surface used for map_screenshot.
void set_playing_team(size_t team)
set_playing_team sets the team whose turn it currently is
SDL_Rect screen_area() const
std::string allied_color()
virtual const std::vector< team > & teams() const =0
void new_animation_frame()
std::map< std::string, tfilter >::iterator itor
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
surface render() const
Returns the rendered text.
int h() const
Effective map height.
void scroll_to_tile(const map_location &loc, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true, bool force=true)
Scroll such that location loc is on-screen.
int hex_width() const
Function which returns the width of a hex in pixels, up to where the next hex starts.
virtual void highlight_hex(map_location hex)
const std::vector< action > & actions() const
bool update_locked() const
std::vector< std::shared_ptr< gui::button > > menu_buttons_
std::string moved_color()
void set_diagnostic(const std::string &msg)
const std::vector< slider > & sliders() const
void scroll_to_tiles(map_location loc1, map_location loc2, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true, double add_spacing=0.0, bool force=true)
Scroll such that location loc1 is on-screen.
void invalidate_animations_location(const map_location &loc)
Per-location invalidation called by invalidate_animations() Extra game per-location invalidation (vil...
bool shrouded(const map_location &loc) const
Returns true if location (x,y) is covered in shroud.
static SDL_Color get_minimap_color(int side)
drawing_buffer_key(const map_location &loc, tdrawing_layer layer)
void read(const config &cfg)
std::basic_string< signed char > light_string
light_string store colors info of central and adjacent hexes.
GLfloat GLfloat GLfloat GLfloat h
void undraw_floating_labels(surface screen)
void init_flags_for_side_internal(size_t side, const std::string &side_color)
void raise_volatile_draw_event()
display(const display_context *dc, CVideo &video, boost::weak_ptr< wb::manager > wb, reports &reports_object, const config &theme_cfg, const config &level, bool auto_join=true)
surface brighten_image(const surface &surf, fixed_t amount, bool optimize)
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
int add_floating_label(const floating_label &flabel)
add a label floating on the screen above everything else.
GLint GLint GLint GLint GLint x
bool invalidate_locations_in_rect(const SDL_Rect &rect)
invalidate all hexes under the rectangle rect (in screen coordinates)
bool add_exclusive_draw(const map_location &loc, unit &unit)
Allows a unit to request to be the only one drawn in its hex.
virtual void draw_hex(const map_location &loc)
Redraws a single gamemap location.
Represents terrains which are to be drawn in front of them.
void set_zoom(int amount)
sets the amount scaled images should be scaled.
GLdouble GLdouble GLdouble r
virtual const SDL_Rect & get_clip_rect()
Get the clipping rectangle for drawing.
std::string corner_image_top_right_odd
surface mouseover_hex_overlay_
Definitions for the terrain builder.
const tborder & border() const
Represents terrains which are to be drawn behind unit sprites.
Helper structure for rendering the terrains.
const rect_of_hexes hexes_under_rect(const SDL_Rect &r) const
Return the rectangular area of hexes overlapped by r (r is in screen coordinates) ...
const std::vector< panel > & panels() const
std::vector< std::string > fog_images_
const rect_of_hexes get_visible_hexes() const
Returns the rectangular area of visible hexes.
std::vector< animated< image::locator > > imagelist
A shorthand typedef for a list of animated image locators, the base data type returned by the get_ter...
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
GLuint const GLchar * name
surface & get_video_surface()
t_translation::t_terrain get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
GLint GLint GLsizei GLsizei GLsizei GLint border
surface get_lighted_image(const image::locator &i_locator, const light_string &ls, TYPE type)
function to get the surface corresponding to an image.
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an empty SDL_Rect.
bool on_board(const map_location &loc) const
Tell if a location is on the map.
std::map< map_location, unsigned int > reach_map
void add_overlay(const map_location &loc, const std::string &image, const std::string &halo="", const std::string &team_name="", const std::string &item_id="", bool visible_under_fog=true)
Functions to add and remove overlays from locations.
bool set_resolution(const SDL_Rect &screen)
std::string partial_color()
std::string border_image_left
virtual void draw_hex(map_location const &hex)
static std::map< std::string, std::string > images
const SDL_Rect & map_area() const
Returns the area used for the map.
virtual void post_commit()
Hook for actions to take right after draw() calls drawing_buffer_commit No action here by default...
exclusive_unit_draw_requests_t exclusive_unit_draw_requests_
map of hexes where only one unit should be drawn, the one identified by the associated id string ...
events::generic_event scroll_event_
Event raised when the map is being scrolled.
void reload_map()
Updates internals that cache map size.
void fill_rect_alpha(SDL_Rect &rect, Uint32 color, Uint8 alpha, surface target)
Fills a specified area of a surface with a given color and opacity.
const gamemap & get_map() const
std::map< std::string, surface > reportSurfaces_
std::set< map_location > invalidated_
bool find(E event, F functor)
Tests whether an event handler is available.
void clear_screen()
Clear the screen contents.
void drawing_buffer_clear()
Clears the drawing buffer.
surface tile_surface(const surface &surf, int w, int h, bool optimize)
Tile a surface.
std::map< std::string, config > reports_
const display_context * dc_
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
surface make_neutral_surface(const surface &surf)
const color_range & color_info(const std::string &name)
this module manages the cache of images.
void update_tod()
Add r,g,b from tod_manager to the map.
Standard logging facilities (interface).
gui::button::TYPE string_to_button_type(std::string type)
const SDL_Rect & map_outside_area() const
Returns the available area for a map, this may differ from the above.
const std::string & prefix() const
void add_redraw_observer(std::function< void(display &)> f)
Adds a redraw observer, a function object to be called when redraw_everything is used.
CVideo & video()
Gets the underlying screen object.
void assign(const surface &o)
surface create_compatible_surface(const surface &surf, int width, int height)
GLsizei GLenum GLuint GLuint GLsizei char * message
void reinit_flags_for_side(size_t side)
Rebuild the flag list (not team colors) for a single side.
static void draw_label(CVideo &video, surface target, const theme::label &label)
bool set_text(const std::string &text, const bool markedup)
Sets the text to render.
surface greyscale_image(const surface &surf, bool optimize)
static std::string get_side_color_index(int side)
GLint GLint GLint GLint GLint GLint GLsizei width
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
bool outside_area(const SDL_Rect &area, const int x, const int y) const
Check if the bbox of the hex at x,y has pixels outside the area rectangle.
void fill_images_list(const std::string &prefix, std::vector< std::string > &images)
std::vector< animated< image::locator > > flags_
Animated flags for each team.
const SDL_Color YELLOW_COLOR
size_t viewing_team() const
The viewing team is the team currently viewing the game.
unit_iterator find(size_t id)
void sdl_blit(const surface &src, SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect)
boost::scoped_ptr< halo::manager > halo_man_
static void draw_panel(CVideo &video, const theme::panel &panel, std::vector< std::shared_ptr< gui::button >> &)
A config object defines a single node in a WML file, with access to child nodes.
surface get_rendered_text(const std::string &str, int size, const SDL_Color &color, int style)
void refresh_report(std::string const &report_name, const config *new_cfg=nullptr)
Redraws the specified report (if anything has changed).
void remove_single_overlay(const map_location &loc, const std::string &toDelete)
remove_single_overlay will remove a single overlay from a tile
int hex_size() const
Function which returns the size of a hex in pixels (from top tip to bottom tip or left edge to right ...
surface get_flag(const map_location &loc)
std::vector< std::shared_ptr< gui::zoom_slider > > sliders_
void update_rect(const SDL_Rect &)
void announce(const std::string &msg, const SDL_Color &color=font::GOOD_COLOR)
Announce a message prominently.
bool scroll(int xmov, int ymov, bool force=false)
Scrolls the display by xmov,ymov pixels.
std::vector< std::string > square_parenthetical_split(std::string const &val, const char separator, std::string const &left, std::string const &right, const int flags)
Similar to parenthetical_split, but also expands embedded square brackets.
void remove_overlay(const map_location &loc)
remove_overlay will remove all overlays on a tile.
void redraw_unit(const unit &u) const
draw a unit.
bool animate_map_
Local cache for preferences::animate_map, since it is constantly queried.
static void toggle_debug_foreground()
Toggle to debug foreground terrain.
GLsizei const GLcharARB ** string
void draw_rectangle(int x, int y, int w, int h, Uint32 color, surface target)
Draw a colored rectangle on a surface.
std::string enemy_color()
std::shared_ptr< gui::button > find_menu_button(const std::string &id)
config & add_child_at(const std::string &key, const config &val, unsigned index)
void draw_floating_labels(surface screen)
#define ftofxp(x)
IN: float or int - OUT: fixed_t.
std::string remove_exclusive_draw(const map_location &loc)
Cancels an exclusive draw request.
void rebuild_all()
Rebuild all dynamic terrain.
bool set_zoom(int amount, bool absolute=false)
Zooms the display by the specified amount.
bool propagate_invalidation(const std::set< map_location > &locs)
If this set is partially invalidated, invalidate all its hexes.
const std::string valid
Little parts of regex templates used to parse Wml annoations.
bool screenshot(const std::string &filename, bool map_screenshot=false)
Save a (map-)screenshot and return whether the operation succeeded.
void set_team(size_t team, bool observe=false)
Sets the team controlled by the player using the computer.
void start_animation(int start_time, bool cycles=false)
Starts an animation cycle.
ttext & set_foreground_color(const Uint32 color)