Merge branch 'master' of git://github.com/wesnoth/wesnoth

This commit is contained in:
Chris Beck 2014-07-22 15:00:05 -04:00
commit b548a90c65
14 changed files with 441 additions and 103 deletions

View file

@ -1066,14 +1066,159 @@ void unit_preview_pane::draw_contents()
const bool right_align = left_side();
surface screen = video().getSurface();
SDL_Rect const &loc = location();
const SDL_Rect area = sdl::create_rect(loc.x + unit_preview_border
, loc.y + unit_preview_border
, loc.w - unit_preview_border * 2
, loc.h - unit_preview_border * 2);
#ifdef SDL_GPU
GPU_SetClip(get_render_target(), area.x, area.y, area.w, area.h);
sdl::timage unit_image = det.image;
// TODO: port this to SDL_gpu
// if (!left_)
// unit_image = image::reverse_image(unit_image);
SDL_Rect image_rect = sdl::create_rect(area.x, area.y, 0, 0);
if(!unit_image.null()) {
SDL_Rect rect = sdl::create_rect(
right_align
? area.x
: area.x + area.w - unit_image.width()
, area.y
, unit_image.width()
, unit_image.height());
video().draw_texture(unit_image, rect.x, rect.y);
image_rect = rect;
if(!det.overlays.empty()) {
BOOST_FOREACH(const std::string& overlay, det.overlays) {
sdl::timage oi = image::get_texture(overlay);
if(!oi.null()) {
continue;
}
if(oi.width() > rect.w || oi.height() > rect.h) {
oi.set_scale(float(rect.w) / oi.width(), float(rect.h) / oi.height());
}
video().draw_texture(oi, rect.x, rect.y);
}
}
}
// Place the 'unit profile' button
const SDL_Rect button_loc = sdl::create_rect(
right_align
? area.x
: area.x + area.w - details_button_.location().w
, image_rect.y + image_rect.h
, details_button_.location().w
, details_button_.location().h);
details_button_.set_location(button_loc);
SDL_Rect description_rect = sdl::create_rect(image_rect.x
, image_rect.y + image_rect.h + details_button_.location().h
, 0
, 0);
if(det.name.empty() == false) {
std::stringstream desc;
desc << font::BOLD_TEXT << det.name;
const std::string description = desc.str();
description_rect = font::text_area(description, font::SIZE_NORMAL);
sdl::timage img = font::draw_text_to_texture(area,
font::SIZE_NORMAL, font::NORMAL_COLOR,
desc.str());
video().draw_texture(img, right_align ? image_rect.x :
image_rect.x + image_rect.w - description_rect.w,
image_rect.y + image_rect.h + details_button_.location().h);
}
std::stringstream text;
text << font::unit_type << det.type_name << "\n"
<< font::race
<< (right_align && !weapons_ ? det.race+" " : " "+det.race) << "\n"
<< _("level") << " " << det.level << "\n"
<< det.alignment << "\n"
<< det.traits << "\n";
for(std::vector<t_string>::const_iterator a = det.abilities.begin(); a != det.abilities.end(); ++a) {
if(a != det.abilities.begin()) {
text << ", ";
}
text << (*a);
}
text << "\n";
// Use same coloring as in generate_report.cpp:
text << det.hp_color << _("HP: ")
<< det.hitpoints << "/" << det.max_hitpoints << "\n";
text << det.xp_color << _("XP: ")
<< det.experience << "/" << det.max_experience << "\n";
if(weapons_) {
text << _("Moves: ")
<< det.movement_left << "/" << det.total_movement << "\n";
for(std::vector<attack_type>::const_iterator at_it = det.attacks.begin();
at_it != det.attacks.end(); ++at_it) {
// see generate_report() in generate_report.cpp
text << font::weapon
<< at_it->damage()
<< font::weapon_numbers_sep
<< at_it->num_attacks()
<< " " << at_it->name() << "\n";
text << font::weapon_details
<< " " << string_table["range_" + at_it->range()]
<< font::weapon_details_sep
<< string_table["type_" + at_it->type()] << "\n";
std::string accuracy_parry = at_it->accuracy_parry_description();
if(accuracy_parry.empty() == false) {
text << font::weapon_details << " " << accuracy_parry << "\n";
}
std::string special = at_it->weapon_specials();
if (!special.empty()) {
text << font::weapon_details << " " << special << "\n";
}
}
}
// we don't remove empty lines, so all fields stay at the same place
const std::vector<std::string> lines = utils::split(text.str(), '\n',
utils::STRIP_SPACES & !utils::REMOVE_EMPTY);
int ypos = area.y;
if(weapons_) {
ypos += image_rect.h + description_rect.h + details_button_.location().h;
}
for(std::vector<std::string>::const_iterator line = lines.begin(); line != lines.end(); ++line) {
int xpos = area.x;
if(right_align && !weapons_) {
const SDL_Rect& line_area = font::text_area(*line,font::SIZE_SMALL);
// right align, but if too long, don't hide line's beginning
if (line_area.w < area.w)
xpos = area.x + area.w - line_area.w;
}
sdl::timage img = font::draw_text_to_texture(location(),font::SIZE_SMALL,font::NORMAL_COLOR,*line);
video().draw_texture(img, xpos, ypos);
ypos += img.height();
}
GPU_UnsetClip(get_render_target());
#else
surface screen(video().getSurface());
const clip_rect_setter clipper(screen, &area);
surface unit_image = det.image;
@ -1166,7 +1311,7 @@ void unit_preview_pane::draw_contents()
<< det.movement_left << "/" << det.total_movement << "\n";
for(std::vector<attack_type>::const_iterator at_it = det.attacks.begin();
at_it != det.attacks.end(); ++at_it) {
at_it != det.attacks.end(); ++at_it) {
// see generate_report() in generate_report.cpp
text << font::weapon
<< at_it->damage()
@ -1213,6 +1358,7 @@ void unit_preview_pane::draw_contents()
SDL_Rect cur_area = font::draw_text(&video(),location(),font::SIZE_SMALL,font::NORMAL_COLOR,*line,xpos,ypos);
ypos += cur_area.h;
}
#endif
}
units_list_preview_pane::units_list_preview_pane(unit_const_ptr u, TYPE type, bool on_left_side) :

View file

@ -70,7 +70,11 @@ public:
struct details {
details();
#ifdef SDL_GPU
sdl::timage image;
#else
surface image;
#endif
std::string name, type_name, race;
int level;
std::string alignment, traits;

View file

@ -220,6 +220,10 @@ display::display(const display_context * dc, CVideo& video, boost::weak_ptr<wb::
draw_terrain_codes_(false),
arrows_map_(),
color_adjust_()
#ifdef SDL_GPU
, update_panel_image_(true),
panel_image_()
#endif
#if defined(__GLIBC__)
, do_reverse_memcpy_workaround_(false)
#endif
@ -1439,6 +1443,10 @@ void display::update_display()
flabel.set_alignment(font::LEFT_ALIGN);
fps_handle_ = font::add_floating_label(flabel);
#ifdef SDL_GPU
std::cerr << "fps: " << fps << std::endl;
#endif
}
} else if(fps_handle_ != 0) {
font::remove_floating_label(fps_handle_);
@ -1450,27 +1458,8 @@ void display::update_display()
flip();
}
static void draw_panel(CVideo& video, const theme::panel& panel, std::vector<gui::button>& /*buttons*/)
static void draw_panel(surface& target, const theme::panel& panel, std::vector<gui::button>& /*buttons*/)
{
#ifdef SDL_GPU
//log_scope("draw panel");
DBG_DP << "drawing panel " << panel.get_id() << "\n";
sdl::timage img(image::get_texture(panel.image()));
const SDL_Rect screen = screen_area();
SDL_Rect& loc = panel.location(screen);
DBG_DP << "panel location: x=" << loc.x << ", y=" << loc.y
<< ", w=" << loc.w << ", h=" << loc.h << "\n";
if(!img.null()) {
img.set_clip(sdl::create_rect(0, 0, loc.w, loc.h));
img.set_wrap(GPU_WRAP_REPEAT, GPU_WRAP_REPEAT);
video.draw_texture(img, loc.x, loc.y);
}
#else
//log_scope("draw panel");
DBG_DP << "drawing panel " << panel.get_id() << "\n";
@ -1487,10 +1476,9 @@ static void draw_panel(CVideo& video, const theme::panel& panel, std::vector<gui
surf.assign(tile_surface(surf,loc.w,loc.h));
}
video.blit_surface(loc.x,loc.y,surf);
blit_surface(surf, NULL, target, &loc);
update_rect(loc);
}
#endif
}
static void draw_label(CVideo& video, surface target, const theme::label& label)
@ -1538,6 +1526,7 @@ static void draw_label(CVideo& video, surface target, const theme::label& label)
void display::draw_all_panels()
{
#ifdef SDL_GPU
const surface& screen(screen_.getSurface());
/*
@ -1546,23 +1535,63 @@ void display::draw_all_panels()
*/
recalculate_minimap();
draw_panel_image();
const std::vector<theme::label>& labels = theme_.labels();
for(std::vector<theme::label>::const_iterator i = labels.begin(); i != labels.end(); ++i) {
draw_label(video(),screen,*i);
}
render_buttons();
#else
surface& screen(screen_.getSurface());
/*
* The minimap is also a panel, force it to update its contents.
* This is required when the size of the minimap has been modified.
*/
recalculate_minimap();
const std::vector<theme::panel>& panels = theme_.panels();
for(std::vector<theme::panel>::const_iterator p = panels.begin(); p != panels.end(); ++p) {
draw_panel(video(), *p, menu_buttons_);
draw_panel(screen, *p, menu_buttons_);
}
const std::vector<theme::label>& labels = theme_.labels();
for(std::vector<theme::label>::const_iterator i = labels.begin(); i != labels.end(); ++i) {
draw_label(video(),screen,*i);
}
#ifdef SDL_GPU
render_buttons();
#else
//FIXME: does it really make sense to recreate buttons all the time?
create_buttons();
#endif
}
#ifdef SDL_GPU
void display::draw_panel_image(SDL_Rect *clip)
{
surface screen(video().getSurface());
if (update_panel_image_) {
surface surf = create_neutral_surface(screen->w, screen->h);
const std::vector<theme::panel>& panels = theme_.panels();
for(std::vector<theme::panel>::const_iterator p = panels.begin(); p != panels.end(); ++p) {
draw_panel(surf, *p, menu_buttons_);
}
panel_image_ = sdl::timage(surf);
update_panel_image_ = false;
}
if (clip != NULL)
GPU_SetClip(get_render_target(), clip->x, clip->y, clip->w, clip->h);
video().draw_texture(panel_image_, 0, 0);
if (clip != NULL)
GPU_UnsetClip(get_render_target());
}
#endif
static void draw_background(surface screen, const SDL_Rect& area, const std::string& image)
{
const surface background(image::get_image(image));
@ -3086,6 +3115,7 @@ void display::refresh_report(std::string const &report_name, const config * new_
}
tooltips::clear_tooltips(rect);
draw_panel_image(&rect);
if (report.empty()) return;

View file

@ -1067,6 +1067,10 @@ protected:
/** redraw all panels associated with the map display */
void draw_all_panels();
#ifdef SDL_GPU
void draw_panel_image(SDL_Rect *clip = NULL);
#endif
/**
* Initiate a redraw.
*
@ -1129,6 +1133,11 @@ private:
tod_color color_adjust_;
#ifdef SDL_GPU
bool update_panel_image_;
sdl::timage panel_image_;
#endif
#if defined(__GLIBC__)
/** Flag for bug #17573 - this is set in the constructor **/
bool do_reverse_memcpy_workaround_;

View file

@ -466,10 +466,6 @@ void game_display::draw_sidebar()
{
wb::future_map future; // start planned unit map scope
#ifdef SDL_GPU
draw_all_panels();
#endif
// We display the unit the mouse is over if it is over a unit,
// otherwise we display the unit that is selected.
BOOST_FOREACH(const std::string &name, reports::report_list()) {

View file

@ -557,5 +557,16 @@ SDL_Rect draw_wrapped_text(CVideo* gui, const SDL_Rect& area, int font_size,
return font::draw_text(gui, area, font_size, color, wrapped_text, x, y, false);
}
#ifdef SDL_GPU
sdl::timage draw_text_to_texture(const SDL_Rect &area, int size, const SDL_Color &color, const std::string &text, bool use_tooltips, int style)
{
SDL_Rect rect = text_area(text, size, style);
surface surf = create_neutral_surface(rect.w, rect.h);
draw_text(surf, area, size, color, text, 0, 0, use_tooltips, style);
return sdl::timage(surf);
}
#endif
} // end namespace font

View file

@ -24,6 +24,10 @@ struct surface;
#include <string>
#include "serialization/unicode.hpp"
#ifdef SDL_GPU
#include "sdl/image.hpp"
#endif
namespace font {
/** Standard markups for color, size, font, images. */
@ -81,6 +85,13 @@ SDL_Rect draw_text(CVideo* gui, const SDL_Rect& area, int size,
const SDL_Color& color, const std::string& text,
int x, int y, bool use_tooltips = false, int style = 0);
#ifdef SDL_GPU
sdl::timage draw_text_to_texture(const SDL_Rect& area, int size,
const SDL_Color& color,
const std::string& text,
bool use_tooltips = false, int style = 0);
#endif
/** Calculate the size of a text (in pixels) if it were to be drawn. */
SDL_Rect text_area(const std::string& text, int size, int style=0);

View file

@ -328,7 +328,19 @@ SDL_Rect draw_minimap(CVideo &video, const SDL_Rect &area, const gamemap &map, c
img.set_scale(scale_factor, scale_factor);
video.draw_texture(img, xpos, ypos);
img.set_color_mod(255, 255, 255);
if (terrain_info.is_combined()) {
sdl::timage overlay = image::get_texture("terrain/" + terrain_info.minimap_image_overlay() + ".png", image::HEXED);
if (fogged) {
overlay.set_color_mod(100, 100, 100);
}
if (highlighted) {
overlay.set_color_mod(150, 150, 150);
}
overlay.set_scale(scale_factor, scale_factor);
video.draw_texture(overlay, xpos, ypos);
}
} else {
SDL_Color col;
std::map<std::string, color_range>::const_iterator it = game_config::team_rgb_range.find(terrain_info.id());

View file

@ -28,12 +28,15 @@ namespace sdl
{
timage::timage(Uint16 w, Uint16 h)
: image_(NULL)
, rotation_(new float(0))
, hscale_(new float(1))
, vscale_(new float(1))
, clip_(new GPU_Rect)
, rotation_(0)
, hscale_(1)
, vscale_(1)
, clip_()
, color_mod_()
, hwrap_(GPU_WRAP_NONE)
, vwrap_(GPU_WRAP_NONE)
{
*clip_ = create_gpu_rect(0, 0, w, h);
clip_ = create_gpu_rect(0, 0, w, h);
image_ = GPU_CreateImage(w, h, GPU_FORMAT_RGBA);
if (image_ == NULL) {
//TODO: report errorr
@ -44,55 +47,70 @@ timage::timage(Uint16 w, Uint16 h)
timage::timage(const std::string &file)
: image_(GPU_LoadImage(file.c_str()))
, rotation_(new float(0))
, hscale_(new float(1))
, vscale_(new float(1))
, clip_(new GPU_Rect)
, rotation_(0)
, hscale_(1)
, vscale_(1)
, clip_()
, color_mod_()
, hwrap_(GPU_WRAP_NONE)
, vwrap_(GPU_WRAP_NONE)
{
if (image_ == NULL) {
//TODO: report error
} else {
*clip_ = create_gpu_rect(0, 0, image_->w, image_->h);
clip_ = create_gpu_rect(0, 0, image_->w, image_->h);
image_->refcount = 1;
}
}
timage::timage(const surface &source)
: image_(GPU_CopyImageFromSurface(source))
, rotation_(new float(0))
, hscale_(new float(1))
, vscale_(new float(1))
, clip_(new GPU_Rect)
, rotation_(0)
, hscale_(1)
, vscale_(1)
, clip_()
, color_mod_()
, hwrap_(GPU_WRAP_NONE)
, vwrap_(GPU_WRAP_NONE)
, smooth_(false)
{
if (image_ == NULL) {
//TODO: report error
} else {
*clip_ = create_gpu_rect(0, 0, image_->w, image_->h);
clip_ = create_gpu_rect(0, 0, image_->w, image_->h);
image_->refcount = 1;
}
}
timage::timage(SDL_Surface *source)
: image_(GPU_CopyImageFromSurface(source))
, rotation_(new float(0))
, hscale_(new float(1))
, vscale_(new float(1))
, clip_(new GPU_Rect)
, rotation_(0)
, hscale_(1)
, vscale_(1)
, clip_()
, color_mod_()
, hwrap_(GPU_WRAP_NONE)
, vwrap_(GPU_WRAP_NONE)
, smooth_(false)
{
if (image_ == NULL) {
//TODO: report error
} else {
*clip_ = create_gpu_rect(0, 0, image_->w, image_->h);
clip_ = create_gpu_rect(0, 0, image_->w, image_->h);
image_->refcount = 1;
}
}
timage::timage()
: image_(NULL)
, rotation_(new float(0))
, hscale_(new float(1))
, vscale_(new float(1))
, clip_(new GPU_Rect)
, rotation_(0)
, hscale_(1)
, vscale_(1)
, clip_()
, color_mod_()
, hwrap_(GPU_WRAP_NONE)
, vwrap_(GPU_WRAP_NONE)
, smooth_(false)
{
}
@ -102,10 +120,6 @@ sdl::timage::~timage()
image_->refcount -= 1;
if (image_->refcount == 0) {
GPU_FreeImage(image_);
delete clip_;
delete hscale_;
delete vscale_;
delete rotation_;
}
}
}
@ -116,6 +130,10 @@ timage::timage(const timage &texture)
, hscale_(texture.hscale_)
, vscale_(texture.vscale_)
, clip_(texture.clip_)
, color_mod_(texture.color_mod_)
, hwrap_(texture.hwrap_)
, vwrap_(texture.vwrap_)
, smooth_(texture.smooth_)
{
if (image_ != NULL) {
image_->refcount += 1;
@ -134,65 +152,67 @@ timage &timage::operator =(const timage &texture)
void timage::draw(GPU_Target &target, const int x, const int y)
{
GPU_BlitTransform(image_, clip_, &target, x + width()/2, y + height()/2,
*rotation_, *hscale_, *vscale_);
GPU_SetImageFilter(image_, smooth_ ? GPU_FILTER_LINEAR : GPU_FILTER_NEAREST);
GPU_SetWrapMode(image_, hwrap_, vwrap_);
//GPU_SetColor(image_, &color);
GPU_BlitTransform(image_, &clip_, &target, x + width()/2, y + height()/2,
rotation_, hscale_, vscale_);
}
void timage::set_rotation(float rotation)
{
*rotation_ = rotation;
rotation_ = rotation;
}
float timage::rotation() const
{
return *rotation_;
return rotation_;
}
void timage::set_hscale(float factor)
{
*hscale_ = factor;
hscale_ = factor;
}
void timage::set_vscale(float factor)
{
*vscale_ = factor;
vscale_ = factor;
}
void timage::set_scale(float hfactor, float vfactor)
{
*hscale_ = hfactor;
*vscale_ = vfactor;
hscale_ = hfactor;
vscale_ = vfactor;
}
float timage::hscale() const
{
return *hscale_;
return hscale_;
}
float timage::vscale() const
{
return *vscale_;
return vscale_;
}
void timage::set_smooth_scaling(bool use_smooth)
{
GPU_SetImageFilter(image_,
use_smooth ? GPU_FILTER_LINEAR : GPU_FILTER_NEAREST);
smooth_ = use_smooth;
}
bool timage::smooth_scaling() const
{
return image_->filter_mode == GPU_FILTER_LINEAR;
return smooth_;
}
int timage::width() const
{
return clip_->w * *hscale_;
return clip_.w * hscale_;
}
int timage::height() const
{
return clip_->h * *vscale_;
return clip_.h * vscale_;
}
Uint16 timage::base_width() const
@ -207,79 +227,79 @@ Uint16 timage::base_height() const
void timage::set_clip(const SDL_Rect &rect)
{
clip_->x = rect.x;
clip_->y = rect.y;
clip_->w = rect.w;
clip_->h = rect.h;
clip_.x = rect.x;
clip_.y = rect.y;
clip_.w = rect.w;
clip_.h = rect.h;
}
SDL_Rect timage::clip() const
{
SDL_Rect result;
result.x = clip_->x;
result.y = clip_->y;
result.w = clip_->w;
result.h = clip_->h;
result.x = clip_.x;
result.y = clip_.y;
result.w = clip_.w;
result.h = clip_.h;
return result;
}
void timage::set_alpha(Uint8 alpha)
{
const SDL_Color prev = image_->color;
SDL_Color next = create_color(prev.r, prev.g, prev.b, alpha);
GPU_SetColor(image_, &next);
color_mod_.unused = alpha;
}
Uint8 timage::alpha() const
{
return image_->color.unused;
return color_mod_.unused;
}
void timage::set_color_mod(Uint8 r, Uint8 g, Uint8 b)
{
SDL_Color c = create_color(r, g, b, image_->color.unused);
GPU_SetColor(image_, &c);
color_mod_.r = r;
color_mod_.g = g;
color_mod_.b = b;
}
Uint8 timage::red_mod() const
{
return image_->color.r;
return color_mod_.r;
}
Uint8 timage::green_mod() const
{
return image_->color.g;
return color_mod_.g;
}
Uint8 timage::blue_mod() const
{
return image_->color.b;
return color_mod_.b;
}
void timage::set_hwrap(GPU_WrapEnum mode)
{
GPU_SetWrapMode(image_, mode, image_->wrap_mode_y);
hwrap_ = mode;
}
void timage::set_vwrap(GPU_WrapEnum mode)
{
GPU_SetWrapMode(image_, image_->wrap_mode_x, mode);
vwrap_ = mode;
}
void timage::set_wrap(GPU_WrapEnum hmode, GPU_WrapEnum vmode)
{
GPU_SetWrapMode(image_, hmode, vmode);
hwrap_ = hmode;
vwrap_ = vmode;
}
GPU_WrapEnum timage::hwrap() const
{
return image_->wrap_mode_x;
return hwrap_;
}
GPU_WrapEnum timage::vwrap() const
{
return image_->wrap_mode_y;
return vwrap_;
}
bool timage::null() const

View file

@ -250,16 +250,25 @@ private:
GPU_Image *image_;
/** How much will it be rotated. */
float *rotation_;
float rotation_;
/** How much will it be scaled horizontally. */
float *hscale_;
float hscale_;
/** How much will it be scaled vertically. */
float *vscale_;
float vscale_;
/** Which part of the texture should be displayed. */
GPU_Rect *clip_;
GPU_Rect clip_;
/** Color mod. */
SDL_Color color_mod_;
/** Wrap policy. */
GPU_WrapEnum hwrap_, vwrap_;
/** Smooth scaling. */
bool smooth_;
};
}
#endif

View file

@ -85,6 +85,18 @@ dialog_frame::dialog_frame(CVideo &video, const std::string& title,
restorer_(NULL),
auto_restore_(auto_restore),
dim_(),
#ifdef SDL_GPU
top_(image::get_texture("dialogs/" + dialog_style_.panel + "-border-top.png")),
bot_(image::get_texture("dialogs/" + dialog_style_.panel + "-border-bottom.png")),
left_(image::get_texture("dialogs/" + dialog_style_.panel + "-border-left.png")),
right_(image::get_texture("dialogs/" + dialog_style_.panel + "-border-right.png")),
top_left_(image::get_texture("dialogs/" + dialog_style_.panel + "-border-topleft.png")),
bot_left_(image::get_texture("dialogs/" + dialog_style_.panel + "-border-botleft.png")),
top_right_(image::get_texture("dialogs/" + dialog_style_.panel + "-border-topright.png")),
bot_right_(image::get_texture("dialogs/" + dialog_style_.panel + "-border-botright.png")),
bg_(image::get_texture("dialogs/" + dialog_style_.panel + "-background.png")),
have_border_(!top_.null() && !bot_.null() && !left_.null() && !right_.null())
#else
top_(image::get_image("dialogs/" + dialog_style_.panel + "-border-top.png")),
bot_(image::get_image("dialogs/" + dialog_style_.panel + "-border-bottom.png")),
left_(image::get_image("dialogs/" + dialog_style_.panel + "-border-left.png")),
@ -95,6 +107,7 @@ dialog_frame::dialog_frame(CVideo &video, const std::string& title,
bot_right_(image::get_image("dialogs/" + dialog_style_.panel + "-border-botright.png")),
bg_(image::get_image("dialogs/" + dialog_style_.panel + "-background.png")),
have_border_(top_ != NULL && bot_ != NULL && left_ != NULL && right_ != NULL)
#endif
{
}
@ -114,7 +127,11 @@ dialog_frame::dimension_measurements dialog_frame::layout(SDL_Rect const& rect)
int dialog_frame::top_padding() const {
int padding = 0;
if(have_border_) {
#ifdef SDL_GPU
padding += top_.height();
#else
padding += top_->h;
#endif
}
if(!title_.empty()) {
padding += font::get_max_height(font::SIZE_LARGE) + 2*dialog_frame::title_border_h;
@ -130,7 +147,11 @@ int dialog_frame::bottom_padding() const {
}
}
if(have_border_) {
#ifdef SDL_GPU
padding += bot_.height();
#else
padding += bot_->h;
#endif
}
return padding;
}
@ -167,10 +188,17 @@ dialog_frame::dimension_measurements dialog_frame::layout(int x, int y, int w, i
SDL_Rect bounds = screen_area();
if(have_border_) {
#ifdef SDL_GPU
bounds.x += left_.width();
bounds.y += top_.height();
bounds.w -= left_.width();
bounds.h -= top_.height();
#else
bounds.x += left_->w;
bounds.y += top_->h;
bounds.w -= left_->w;
bounds.h -= top_->h;
#endif
}
if(x < bounds.x) {
w += x;
@ -195,10 +223,17 @@ dialog_frame::dimension_measurements dialog_frame::layout(int x, int y, int w, i
dim_.interior.w = w;
dim_.interior.h = h;
if(have_border_) {
#ifdef SDL_GPU
dim_.exterior.x = dim_.interior.x - left_.width();
dim_.exterior.y = dim_.interior.y - top_.height();
dim_.exterior.w = dim_.interior.w + left_.width() + right_.width();
dim_.exterior.h = dim_.interior.h + top_.height() + bot_.height();
#else
dim_.exterior.x = dim_.interior.x - left_->w;
dim_.exterior.y = dim_.interior.y - top_->h;
dim_.exterior.w = dim_.interior.w + left_->w + right_->w;
dim_.exterior.h = dim_.interior.h + top_->h + bot_->h;
#endif
} else {
dim_.exterior = dim_.interior;
}
@ -213,6 +248,28 @@ void dialog_frame::draw_border()
return;
}
#ifdef SDL_GPU
top_.set_hscale(float(dim_.interior.w )/ top_.base_width());
video_.draw_texture(top_, dim_.interior.x, dim_.exterior.y);
bot_.set_hscale(float(dim_.interior.w) / bot_.base_width());
video_.draw_texture(bot_, dim_.interior.x, dim_.interior.y + dim_.interior.h);
left_.set_vscale(float(dim_.interior.h) / left_.base_height());
video_.draw_texture(left_, dim_.exterior.x, dim_.interior.y);
right_.set_vscale(float(dim_.interior.h) / right_.base_height());
video_.draw_texture(right_, dim_.interior.x + dim_.interior.w, dim_.interior.y);
if(top_left_.null() || bot_left_.null() || top_right_.null() || bot_right_.null()) {
return;
}
video_.draw_texture(top_left_, dim_.interior.x - left_.width(), dim_.interior.y - top_.height());
video_.draw_texture(bot_left_, dim_.interior.x - left_.width(), dim_.interior.y + dim_.interior.h + bot_.height() - bot_left_.height());
video_.draw_texture(top_right_, dim_.interior.x + dim_.interior.w + right_.width() - top_right_.width(), dim_.interior.y - top_.height());
video_.draw_texture(bot_right_, dim_.interior.x + dim_.interior.w + right_.width() - bot_right_.width(), dim_.interior.y + dim_.interior.h + bot_.height() - bot_right_.height());
#else
surface top_image(scale_surface(top_, dim_.interior.w, top_->h));
if(top_image != NULL) {
@ -247,6 +304,7 @@ void dialog_frame::draw_border()
video_.blit_surface(dim_.interior.x - left_->w, dim_.interior.y + dim_.interior.h + bot_->h - bot_left_->h, bot_left_);
video_.blit_surface(dim_.interior.x + dim_.interior.w + right_->w - top_right_->w, dim_.interior.y - top_->h, top_right_);
video_.blit_surface(dim_.interior.x + dim_.interior.w + right_->w - bot_right_->w, dim_.interior.y + dim_.interior.h + bot_->h - bot_right_->h, bot_right_);
#endif
}
void dialog_frame::clear_background()
@ -268,6 +326,24 @@ void dialog_frame::draw_background()
sdl_blit(surf, NULL, video_.getSurface(), &dim_.exterior);
}
#ifdef SDL_GPU
if(bg_.null()) {
ERR_DP << "could not find dialog background '" << dialog_style_.panel << "'" << std::endl;
return;
}
for(int i = 0; i < dim_.interior.w; i += bg_.width()) {
for(int j = 0; j < dim_.interior.h; j += bg_.height()) {
SDL_Rect src = {0,0,0,0};
src.w = std::min(dim_.interior.w - i, bg_.width());
src.h = std::min(dim_.interior.h - j, bg_.height());
SDL_Rect dst = src;
dst.x = dim_.interior.x + i;
dst.y = dim_.interior.y + j;
bg_.set_clip(src);
video_.draw_texture(bg_, dst.x, dst.y);
}
}
#else
if(bg_ == NULL) {
ERR_DP << "could not find dialog background '" << dialog_style_.panel << "'" << std::endl;
return;
@ -283,6 +359,7 @@ void dialog_frame::draw_background()
sdl_blit(bg_, &src, video_.getSurface(), &dst);
}
}
#endif
}
SDL_Rect dialog_frame::draw_title(CVideo* video)

View file

@ -105,7 +105,11 @@ private:
surface_restorer* restorer_;
bool auto_restore_;
dimension_measurements dim_;
#ifdef SDL_GPU
sdl::timage top_, bot_, left_, right_, top_left_, bot_left_, top_right_, bot_right_, bg_;
#else
surface top_, bot_, left_, right_, top_left_, bot_left_, top_right_, bot_right_, bg_;
#endif
bool have_border_;
};

View file

@ -370,6 +370,13 @@ ttext& ttext::set_foreground_color(const Uint32 color)
return *this;
}
ttext &ttext::set_foreground_color(const SDL_Color color)
{
set_foreground_color((color.r << 16) + (color.g << 8) + color.b);
return *this;
}
ttext& ttext::set_maximum_width(int width)
{
if(width <= 0) {

View file

@ -205,6 +205,8 @@ public:
ttext& set_foreground_color(const Uint32 color);
ttext& set_foreground_color(const SDL_Color color);
ttext& set_maximum_width(int width);
ttext& set_characters_per_line(const unsigned characters_per_line);