Skip to content

Commit

Permalink
Initial SDL_gpu support for dialogs.
Browse files Browse the repository at this point in the history
  • Loading branch information
lipk committed Jul 22, 2014
1 parent 8a94ed7 commit 361beb6
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/show_dialog.cpp
Expand Up @@ -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")),
Expand All @@ -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
{
}

Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -213,6 +248,28 @@ void dialog_frame::draw_border()
return;
}

#ifdef SDL_GPU
top_.set_hscale(dim_.interior.w / top_.base_width());
video_.draw_texture(top_, dim_.interior.x, dim_.interior.y);

bot_.set_hscale(dim_.interior.w / bot_.base_width());
video_.draw_texture(bot_, dim_.interior.x, dim_.interior.y + dim_.interior.h);

left_.set_vscale(dim_.interior.h / left_.base_height());
video_.draw_texture(left_, dim_.exterior.x, dim_.interior.y);

right_.set_vscale(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) {
Expand Down Expand Up @@ -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()
Expand All @@ -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;
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/show_dialog.hpp
Expand Up @@ -105,7 +105,11 @@ class dialog_frame {
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_;
};

Expand Down

0 comments on commit 361beb6

Please sign in to comment.