Skip to content

Commit

Permalink
Draw floating labels to the overlay texture.
Browse files Browse the repository at this point in the history
  • Loading branch information
lipk committed Aug 12, 2014
1 parent 607f91a commit 623fd99
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/display.cpp
Expand Up @@ -2241,6 +2241,7 @@ bool display::scroll(int xmove, int ymove, bool force)
}
scroll_event_.notify_observers();
#ifdef SDL_GPU
screen_.clear_overlay();
invalidate_all();
#else
update_rect(map_area());
Expand Down
18 changes: 13 additions & 5 deletions src/font.cpp
Expand Up @@ -918,7 +918,7 @@ std::stack<std::set<int> > label_contexts;
namespace font {

floating_label::floating_label(const std::string& text)
#ifdef SDL_GPU
#if 0
: img_(),
#else
: surf_(NULL), buf_(NULL),
Expand Down Expand Up @@ -952,7 +952,7 @@ int floating_label::xpos(size_t width) const
return xpos;
}

#ifdef SDL_GPU
#if 0
sdl::timage floating_label::create_image()
{
if (img_.null()) {
Expand Down Expand Up @@ -1108,13 +1108,21 @@ void floating_label::draw(CVideo &video)
if (!visible_) {
return;
}

#if 0
create_image();
if (img_.null()) {
return;
}

video.draw_texture(img_, xpos(img_.width()), int(ypos_));
#else
create_surface();
if (surf_.null()) {
return;
}

video.blit_to_overlay(surf_, xpos(surf_->w), int(ypos_));
#endif
}
#else
void floating_label::draw(surface screen)
Expand Down Expand Up @@ -1149,7 +1157,7 @@ void floating_label::draw(surface screen)
}
#endif

#ifdef SDL_GPU
#if 0
// No undrawing for SDL_gpu, it won't be necessary once z-order is implemented
void floating_label::undraw(surface) {}
#else
Expand Down Expand Up @@ -1228,7 +1236,7 @@ void show_floating_label(int handle, bool value)
SDL_Rect get_floating_label_rect(int handle)
{
const label_map::iterator i = labels.find(handle);
#ifdef SDL_GPU
#if 0
if(i != labels.end()) {
const sdl::timage img = i->second.create_image();
if(!img.null()) {
Expand Down
4 changes: 2 additions & 2 deletions src/font.hpp
Expand Up @@ -161,7 +161,7 @@ class floating_label
#endif
void undraw(surface screen);

#ifdef SDL_GPU
#if 0
sdl::timage create_image();
#else
surface create_surface();
Expand All @@ -176,7 +176,7 @@ class floating_label
private:

int xpos(size_t width) const;
#ifdef SDL_GPU
#if 0
sdl::timage img_;
#else
surface surf_, buf_;
Expand Down
25 changes: 25 additions & 0 deletions src/video.cpp
Expand Up @@ -426,6 +426,23 @@ void CVideo::set_texture_effects(int effects)
{
shader_.set_effects(effects);
}

void CVideo::blit_to_overlay(surface surf, int x, int y)
{
SDL_Rect r = sdl::create_rect(x, y, surf->w, surf->h);
SDL_BlitSurface(surf, NULL, overlay_, &r);
}

void CVideo::clear_overlay_area(SDL_Rect area)
{
//TODO: proper implementation
sdl::fill_rect(overlay_, &area, 0xFF000000);
}

void CVideo::clear_overlay()
{
overlay_ = create_compatible_surface(overlay_, getx(), gety());
}
#endif

void CVideo::make_fake()
Expand Down Expand Up @@ -525,11 +542,17 @@ int CVideo::setMode( int x, int y, int bits_per_pixel, int flags )

fullScreen = (flags & FULL_SCREEN) != 0;
#ifdef SDL_GPU
//NOTE: this surface is in fact unused now. Can be removed when possible.
frameBuffer = SDL_CreateRGBSurface(SDL_SWSURFACE, x, y, 32,
0x00ff0000,
0x0000ff00,
0x000000ff,
0xff000000);
overlay_ = SDL_CreateRGBSurface(SDL_SWSURFACE, x, y, 32,
0x00ff0000,
0x0000ff00,
0x000000ff,
0xff000000);
GPU_SetWindowResolution(x, y);
if (toggle_fullscreen) {
GPU_ToggleFullscreen(1);
Expand Down Expand Up @@ -576,6 +599,8 @@ void CVideo::flip()
return;
#ifdef SDL_GPU
assert(render_target_);
sdl::timage img(overlay_);
shader_.set_overlay(img);
GPU_Flip(render_target_);
#else
#if !SDL_VERSION_ATLEAST(2, 0, 0)
Expand Down
9 changes: 6 additions & 3 deletions src/video.hpp
Expand Up @@ -27,6 +27,7 @@
struct surface;
#ifdef SDL_GPU
#include "sdl/shader.hpp"
#include "sdl/utils.hpp"

namespace sdl
{
Expand Down Expand Up @@ -87,12 +88,13 @@ class CVideo : private boost::noncopyable {
GPU_Target *render_target() const;

void draw_texture(sdl::timage &texture, int x, int y);

void set_texture_color_modulation(int r, int g, int b, int a);

void set_texture_submerge(float f);

void set_texture_effects(int effects);

void blit_to_overlay(surface surf, int x, int y);
void clear_overlay_area(SDL_Rect area);
void clear_overlay();
#endif
void flip();

Expand Down Expand Up @@ -184,6 +186,7 @@ class CVideo : private boost::noncopyable {
void initSDL();
#ifdef SDL_GPU
sdl::shader_program shader_;
surface overlay_;
#endif

bool mode_changed_;
Expand Down

0 comments on commit 623fd99

Please sign in to comment.