bwidgets/inc/basic_widgets/w/feat/font_handler.hpp

62 lines
2 KiB
C++
Raw Normal View History

2021-08-06 14:22:56 +02:00
#ifndef BWIDGETS_FONT_HANDLER_HPP
#define BWIDGETS_FONT_HANDLER_HPP
#include <basic_widgets/core/font.hpp>
2021-08-06 14:22:56 +02:00
namespace bwidgets
{
class FontHandler
{
protected:
2021-08-06 14:22:56 +02:00
Font* _font {nullptr};
Color _font_color_bg = default_font_color_bg;
Color _font_color_fg = default_font_color_fg;
Font::RenderMode _font_render_mode {Font::RenderMode::SHADED};
2021-08-06 14:22:56 +02:00
virtual void _handle_font_change(Font*) = 0;
virtual void _handle_font_color_change(const Color&, const Color&) = 0;
public:
2021-08-06 14:22:56 +02:00
inline static const Color default_font_color_bg {255, 255, 255,
SDL_ALPHA_OPAQUE};
inline static const Color default_font_color_fg {0, 0, 0, SDL_ALPHA_OPAQUE};
2021-08-08 14:30:56 +02:00
virtual ~FontHandler() = default;
2021-08-06 14:22:56 +02:00
virtual inline auto font(Font* f) -> FontHandler* final
{
2021-08-06 14:22:56 +02:00
if (f != nullptr
&& (f != _font || f->family_name != _font->family_name
|| f->height != _font->height || f->hinting() != _font->hinting()
|| f->kerning() != _font->kerning()
|| f->outline() != _font->outline()
|| f->style_name != _font->style_name))
{
_handle_font_change(f);
_font = f;
}
return this;
}
2021-08-06 14:22:56 +02:00
virtual inline auto font_color_bg(const Color& c) -> FontHandler* final
{
2021-08-06 14:22:56 +02:00
if (c != _font_color_bg) {
_handle_font_color_change(_font_color_bg, c);
_font_color_bg = c;
}
return this;
}
2021-08-06 14:22:56 +02:00
virtual inline auto font_color_fg(const Color& c) -> FontHandler* final
{
2021-08-06 14:22:56 +02:00
if (c != _font_color_fg) {
_handle_font_color_change(c, _font_color_fg);
_font_color_fg = c;
}
return this;
}
};
}
#endif