rename sb::Text::size to sb::Text::dimensions
This commit is contained in:
parent
1d527898aa
commit
b93aae19e0
16
src/Text.cpp
16
src/Text.cpp
|
@ -26,9 +26,9 @@ void Text::font(std::shared_ptr<TTF_Font> font)
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::size(const glm::vec2 &size)
|
void Text::dimensions(const glm::vec2 &dimensions)
|
||||||
{
|
{
|
||||||
_size = size;
|
_dimensions = dimensions;
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,21 +48,21 @@ void Text::refresh()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Use the size of the rendered text unless size has been set. */
|
/* Use the size of the rendered text unless dimensions has been set. */
|
||||||
glm::vec2 size;
|
glm::vec2 dimensions;
|
||||||
if (_size.has_value())
|
if (_dimensions.has_value())
|
||||||
{
|
{
|
||||||
size = _size.value();
|
dimensions = _dimensions.value();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
size = glm::vec2{blended->w, blended->h};
|
dimensions = glm::vec2{blended->w, blended->h};
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a container surface with the same format as the rendered text that the rendered text will be composited onto. */
|
/* Create a container surface with the same format as the rendered text that the rendered text will be composited onto. */
|
||||||
std::shared_ptr<SDL_Surface> container
|
std::shared_ptr<SDL_Surface> container
|
||||||
{
|
{
|
||||||
SDL_CreateRGBSurfaceWithFormat(0, size.x, size.y, blended->format->BitsPerPixel, blended->format->format),
|
SDL_CreateRGBSurfaceWithFormat(0, dimensions.x, dimensions.y, blended->format->BitsPerPixel, blended->format->format),
|
||||||
SDL_FreeSurface
|
SDL_FreeSurface
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
14
src/Text.hpp
14
src/Text.hpp
|
@ -20,7 +20,7 @@ namespace sb
|
||||||
std::string _content;
|
std::string _content;
|
||||||
sb::Color _foreground, _background;
|
sb::Color _foreground, _background;
|
||||||
std::shared_ptr<TTF_Font> _font;
|
std::shared_ptr<TTF_Font> _font;
|
||||||
std::optional<glm::vec2> _size;
|
std::optional<glm::vec2> _dimensions;
|
||||||
GLint _scaling_quality = GL_LINEAR;
|
GLint _scaling_quality = GL_LINEAR;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -36,7 +36,7 @@ namespace sb
|
||||||
*
|
*
|
||||||
* The font must be wrapped in a shared pointer. A default loaded font is available from Game::font().
|
* The font must be wrapped in a shared pointer. A default loaded font is available from Game::font().
|
||||||
*
|
*
|
||||||
* A size can be given in pixels, in which case the text will be rendered at the center of a texture in exactly the given dimensions,
|
* Dimensions can be given in pixels, in which case the text will be rendered at the center of a texture in exactly the given dimensions,
|
||||||
* regardless of the length of the text. If the given dimensions are larger than the text, the resulting texture will have padding around
|
* regardless of the length of the text. If the given dimensions are larger than the text, the resulting texture will have padding around
|
||||||
* the text. This can be useful, for example, for creating identically sized text buttons.
|
* the text. This can be useful, for example, for creating identically sized text buttons.
|
||||||
*
|
*
|
||||||
|
@ -44,11 +44,11 @@ namespace sb
|
||||||
* @param content text content
|
* @param content text content
|
||||||
* @param foreground text color
|
* @param foreground text color
|
||||||
* @param background background color
|
* @param background background color
|
||||||
* @param size force the texture to be a certain size in pixels, extra area is filled with the background color
|
* @param dimensions force the texture to be a certain size in pixels, extra area is filled with the background color
|
||||||
*/
|
*/
|
||||||
Text(std::shared_ptr<TTF_Font> font, const std::string& content = "", const sb::Color& foreground = DEFAULT_FG,
|
Text(std::shared_ptr<TTF_Font> font, const std::string& content = "", const sb::Color& foreground = DEFAULT_FG,
|
||||||
const sb::Color& background = DEFAULT_BG, std::optional<glm::vec2> size = std::nullopt) :
|
const sb::Color& background = DEFAULT_BG, std::optional<glm::vec2> dimensions = std::nullopt) :
|
||||||
_content(content), _foreground(foreground), _background(background), _font(font), _size(size)
|
_content(content), _foreground(foreground), _background(background), _font(font), _dimensions(dimensions)
|
||||||
{
|
{
|
||||||
/* Add an empty Texture object */
|
/* Add an empty Texture object */
|
||||||
texture(sb::Texture());
|
texture(sb::Texture());
|
||||||
|
@ -75,9 +75,9 @@ namespace sb
|
||||||
void font(std::shared_ptr<TTF_Font> font);
|
void font(std::shared_ptr<TTF_Font> font);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @param size force the texture to be a certain size in pixels, extra area is filled with the background color
|
* @param dimensions force the texture to be a certain size in pixels, extra area is filled with the background color
|
||||||
*/
|
*/
|
||||||
void size(const glm::vec2& size);
|
void dimensions(const glm::vec2& dimensions);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* This GL parameter will be passed to `glTexParameter` for `GL_TEXTURE_MIN_FILTER` and `GL_TEXTURE_MAG_FILTER`.
|
* This GL parameter will be passed to `glTexParameter` for `GL_TEXTURE_MIN_FILTER` and `GL_TEXTURE_MAG_FILTER`.
|
||||||
|
|
Loading…
Reference in New Issue