Enable rendering text as a texture.
This commit is contained in:
parent
976e439d97
commit
c59414b121
2 changed files with 35 additions and 0 deletions
16
src/text.cpp
16
src/text.cpp
|
@ -29,6 +29,10 @@
|
|||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
#include "video.hpp"
|
||||
#endif
|
||||
|
||||
namespace font {
|
||||
|
||||
namespace {
|
||||
|
@ -155,6 +159,14 @@ surface ttext::render() const
|
|||
return surface_;
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
sdl::ttexture ttext::render_as_texture() const
|
||||
{
|
||||
rerender();
|
||||
return texture_;
|
||||
}
|
||||
#endif
|
||||
|
||||
int ttext::get_width() const
|
||||
{
|
||||
return get_size().x;
|
||||
|
@ -684,6 +696,10 @@ void ttext::rerender(const bool force) const
|
|||
surface_.assign(SDL_CreateRGBSurfaceFrom(
|
||||
surface_buffer_, width, height, 32, stride,
|
||||
0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000));
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
texture_ = CVideo::get_window()->create_texture
|
||||
(SDL_TEXTUREACCESS_STATIC, surface_);
|
||||
#endif
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_destroy(cairo_surface);
|
||||
}
|
||||
|
|
19
src/text.hpp
19
src/text.hpp
|
@ -25,6 +25,10 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
#include "sdl/texture.hpp"
|
||||
#endif
|
||||
|
||||
struct language_def;
|
||||
|
||||
namespace gui2 {
|
||||
|
@ -72,6 +76,16 @@ public:
|
|||
*/
|
||||
surface render() const;
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
/**
|
||||
* Returns the rendered text as a texture.
|
||||
*
|
||||
* Before rendering it tests whether a redraw is needed and if so it first
|
||||
* redraws the texture before returning it.
|
||||
*/
|
||||
sdl::ttexture render_as_texture() const;
|
||||
#endif
|
||||
|
||||
/** Returns the width needed for the text. */
|
||||
int get_width() const;
|
||||
|
||||
|
@ -208,6 +222,11 @@ private:
|
|||
/** The surface to render upon used as a cache. */
|
||||
mutable surface surface_;
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||
/** The texture to render upon used as a cache. */
|
||||
mutable sdl::ttexture texture_;
|
||||
#endif
|
||||
|
||||
/** The text to draw (stored as UTF-8). */
|
||||
std::string text_;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue