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

61 lines
2.0 KiB
C++

#ifndef BWIDGETS_FONT_HANDLER_HPP
#define BWIDGETS_FONT_HANDLER_HPP
#include <basic_widgets/core/font.hpp>
namespace bwidgets
{
class FontHandler
{
protected:
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};
virtual void _handle_font_change(Font*) = 0;
virtual void _handle_font_color_change(const Color&, const Color&) = 0;
public:
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};
virtual ~FontHandler() = default;
virtual inline auto font(Font* f) -> FontHandler* final
{
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;
}
virtual inline auto font_color_bg(const Color& c) -> FontHandler* final
{
if (c != _font_color_bg) {
_handle_font_color_change(_font_color_bg, c);
_font_color_bg = c;
}
return this;
}
virtual inline auto font_color_fg(const Color& c) -> FontHandler* final
{
if (c != _font_color_fg) {
_handle_font_color_change(c, _font_color_fg);
_font_color_fg = c;
}
return this;
}
};
}
#endif