Skip to content

Commit

Permalink
Render floating images as textures on the storyscreen.
Browse files Browse the repository at this point in the history
  • Loading branch information
lipk committed Jun 17, 2014
1 parent 26d40c1 commit fac9ea5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/storyscreen/part.cpp
Expand Up @@ -67,6 +67,29 @@ void floating_image::assign(const floating_image& fi)

floating_image::render_input floating_image::get_render_input(double xscale, double yscale, SDL_Rect& dst_rect) const
{
#if SDL_VERSION_ATLEAST(2,0,0)
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 @@ -92,6 +115,7 @@ floating_image::render_input floating_image::get_render_input(double xscale, dou
}
}
return ri;
#endif
}

background_layer::background_layer()
Expand Down
5 changes: 5 additions & 0 deletions src/storyscreen/part.hpp
Expand Up @@ -25,6 +25,7 @@
#include <vector>

#include "sdl/utils.hpp"
#include "sdl/texture.hpp"

class config;
class vconfig;
Expand All @@ -42,7 +43,11 @@ class floating_image
struct render_input
{
SDL_Rect rect; /**< Corrected rectangle for rendering surf. */
#if SDL_VERSION_ATLEAST(2,0,0)
sdl::ttexture image;
#else
surface image; /**< Surface, scaled if required. */
#endif
};

/**
Expand Down
33 changes: 33 additions & 0 deletions src/storyscreen/render.cpp
Expand Up @@ -36,6 +36,7 @@

#if SDL_VERSION_ATLEAST(2,0,0)
#include "sdl/texture.hpp"
#include "sdl/window.hpp"
#endif

static lg::log_domain log_engine("engine");
Expand Down Expand Up @@ -317,6 +318,37 @@ void part_ui::render_background()

bool part_ui::render_floating_images()
{
#if SDL_VERSION_ATLEAST(2,0,0)
sdl::twindow *wnd = CVideo::get_window();

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()) {
wnd->draw(ri.image, ri.rect.x, ri.rect.y);
wnd->render();
}

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 @@ -347,6 +379,7 @@ bool part_ui::render_floating_images()
}

return true;
#endif
}

void part_ui::render_title_box()
Expand Down

0 comments on commit fac9ea5

Please sign in to comment.