Skip to content

Commit

Permalink
SDL_gpu implementation for rendering floating images.
Browse files Browse the repository at this point in the history
  • Loading branch information
lipk committed Jul 3, 2014
1 parent dfc2a57 commit 6db593c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/storyscreen/part.cpp
Expand Up @@ -90,6 +90,29 @@ floating_image::render_input floating_image::get_render_input(double xscale, dou
}
return ri;
#else
#ifdef SDL_GPU
render_input ri = {
{0,0,0,0},
file_.empty() ? sdl::ttexture() : image::get_texture(file_)
};

if(!ri.image.null()) {
if(autoscaled_) {
ri.image.set_scale(xscale, yscale);
}

ri.rect.x = static_cast<int>(x_*xscale) + dst_rect.x;
ri.rect.y = static_cast<int>(y_*yscale) + dst_rect.y;
ri.rect.w = ri.image.width();
ri.rect.h = ri.image.height();

if(centered_) {
ri.rect.x -= ri.rect.w / 2;
ri.rect.y -= ri.rect.h / 2;
}
}
return ri;
#else
render_input ri = {
{0,0,0,0},
file_.empty() ? NULL : image::get_image(file_)
Expand All @@ -116,6 +139,7 @@ floating_image::render_input floating_image::get_render_input(double xscale, dou
}
return ri;
#endif
#endif
}

background_layer::background_layer()
Expand Down
4 changes: 4 additions & 0 deletions src/storyscreen/part.hpp
Expand Up @@ -45,8 +45,12 @@ class floating_image
SDL_Rect rect; /**< Corrected rectangle for rendering surf. */
#if SDL_VERSION_ATLEAST(2,0,0)
sdl::ttexture image;
#else
#ifdef SDL_GPU
sdl::ttexture image;
#else
surface image; /**< Surface, scaled if required. */
#endif
#endif
};

Expand Down
32 changes: 32 additions & 0 deletions src/storyscreen/render.cpp
Expand Up @@ -422,6 +422,37 @@ bool part_ui::render_floating_images()

return true;
#else
#ifdef SDL_GPU
GPU_Target *target = get_render_target();

skip_ = false;
last_key_ = true;

size_t fi_n = 0;
BOOST_FOREACH(floating_image::render_input& ri, imgs_) {
const floating_image& fi = p_.get_floating_images()[fi_n];

if(!ri.image.null()) {
ri.image.draw(*target, ri.rect.x, ri.rect.y);
GPU_Flip(target);
}

if (!skip_)
{
int delay = fi.display_delay(), delay_step = 20;
for (int i = 0; i != (delay + delay_step - 1) / delay_step; ++i)
{
if (handle_interface()) return false;
if (skip_) break;
disp_.delay(std::min<int>(delay_step, delay - i * delay_step));
}
}

++fi_n;
}

return true;
#else
events::raise_draw_event();
update_whole_screen();

Expand Down Expand Up @@ -453,6 +484,7 @@ bool part_ui::render_floating_images()

return true;
#endif
#endif
}

void part_ui::render_title_box()
Expand Down

0 comments on commit 6db593c

Please sign in to comment.