Draw floating labels to the overlay texture.

This commit is contained in:
Boldizsár Lipka 2014-08-12 18:49:56 +02:00
parent 607f91a473
commit 623fd991c3
5 changed files with 47 additions and 10 deletions

View file

@ -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());

View file

@ -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),
@ -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()) {
@ -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)
@ -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
@ -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()) {

View file

@ -161,7 +161,7 @@ public:
#endif
void undraw(surface screen);
#ifdef SDL_GPU
#if 0
sdl::timage create_image();
#else
surface create_surface();
@ -176,7 +176,7 @@ public:
private:
int xpos(size_t width) const;
#ifdef SDL_GPU
#if 0
sdl::timage img_;
#else
surface surf_, buf_;

View file

@ -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()
@ -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);
@ -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)

View file

@ -27,6 +27,7 @@
struct surface;
#ifdef SDL_GPU
#include "sdl/shader.hpp"
#include "sdl/utils.hpp"
namespace sdl
{
@ -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();
@ -184,6 +186,7 @@ private:
void initSDL();
#ifdef SDL_GPU
sdl::shader_program shader_;
surface overlay_;
#endif
bool mode_changed_;