bwidgets/inc/basic_widgets/core/font.hpp

76 lines
2.3 KiB
C++
Raw Normal View History

2021-08-06 14:22:56 +02:00
#ifndef BWIDGETS_FONT_HPP
#define BWIDGETS_FONT_HPP
#include <string>
#include <SDL2/SDL_ttf.h>
2021-08-06 14:22:56 +02:00
#include <basic_widgets/core/type/color.hpp>
#include <basic_widgets/core/type/opaque_struct.hpp>
#include <basic_widgets/core/type/size.hpp>
2021-08-06 14:22:56 +02:00
namespace bwidgets
{
struct Font final : OpaqueStruct<TTF_Font>
{
enum struct Hinting
{
LIGHT = TTF_HINTING_LIGHT,
MONO = TTF_HINTING_MONO,
NONE = TTF_HINTING_NONE,
NORMAL = TTF_HINTING_NORMAL
};
enum struct RenderMode
{
SOLID,
SHADED,
BLENDED
};
2021-08-06 14:22:56 +02:00
enum struct Style
{
2021-08-06 14:22:56 +02:00
BOLD = TTF_STYLE_BOLD,
ITALIC = TTF_STYLE_ITALIC,
NORMAL = TTF_STYLE_NORMAL,
STRIKETHROUGH = TTF_STYLE_STRIKETHROUGH,
UNDERLINE = TTF_STYLE_UNDERLINE
};
2021-08-06 14:22:56 +02:00
inline static const Color default_color_bg {255, 255, 255, SDL_ALPHA_OPAQUE};
inline static const Color default_color_fg {0, 0, 0, SDL_ALPHA_OPAQUE};
const int ascent;
const int descent;
const long faces;
const std::string family_name;
const bool fixed_width;
const int height;
const int line_skip;
const std::string style_name;
Font(TTF_Font*);
Font(const std::string&, int);
Font(const Font&) = delete;
~Font() override;
auto operator=(const Font&) -> Font& = delete;
2021-07-19 23:50:50 +02:00
2021-08-08 14:30:56 +02:00
[[nodiscard]] auto hinting() const -> Hinting;
2021-08-06 14:22:56 +02:00
auto hinting(Hinting) -> Font*;
2021-08-08 14:30:56 +02:00
[[nodiscard]] auto kerning() const -> bool;
2021-08-06 14:22:56 +02:00
auto kerning(bool) -> Font*;
2021-08-08 14:30:56 +02:00
[[nodiscard]] auto outline() const -> int;
2021-08-06 14:22:56 +02:00
auto outline(int) -> Font*;
auto render(RenderMode, const std::string&, const Color& fg = default_color_fg,
const Color& bg = default_color_bg) -> SDL_Surface*;
2021-08-08 14:30:56 +02:00
[[nodiscard]] auto style() const -> uint8_t;
2021-08-06 14:22:56 +02:00
auto style(uint8_t) -> Font*;
2021-08-08 14:30:56 +02:00
[[nodiscard]] auto text_size(const std::string&) const -> Size;
2021-08-06 14:22:56 +02:00
[[nodiscard]] static auto find(const std::string&) -> std::string;
};
}
#endif