constructor style refactor

This commit is contained in:
Andrea Blankenstijn 2021-08-14 11:50:37 +02:00
parent 280575a0e2
commit b11d574d9c
10 changed files with 29 additions and 28 deletions

View file

@ -57,9 +57,9 @@ namespace bwidgets
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a, bool op_on_alpha = false, Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a, bool op_on_alpha = false,
bool op_on_colors = true) noexcept bool op_on_colors = true) noexcept
: _operate_on_alpha(op_on_alpha), : _operate_on_alpha {op_on_alpha},
_operate_on_colors(op_on_colors), _operate_on_colors {op_on_colors},
sdl_type({r, g, b, a}) sdl_type {r, g, b, a}
{} {}
inline Color(const SDL_Color& c = {}, bool op_on_alpha = false, inline Color(const SDL_Color& c = {}, bool op_on_alpha = false,
bool op_on_colors = true) noexcept bool op_on_colors = true) noexcept

View file

@ -15,7 +15,7 @@ namespace bwidgets
T* _c_pod; T* _c_pod;
public: public:
OpaqueStruct(T* ptr, const Deleter& d) : _deleter(d), _c_pod(ptr) {} OpaqueStruct(T* ptr, const Deleter& d) : _deleter {d}, _c_pod {ptr} {}
OpaqueStruct(const OpaqueStruct&) = delete; OpaqueStruct(const OpaqueStruct&) = delete;
OpaqueStruct(OpaqueStruct&&) = delete; OpaqueStruct(OpaqueStruct&&) = delete;

View file

@ -28,7 +28,7 @@ namespace bwidgets
protected: protected:
Caption _input_caption; Caption _input_caption;
Input(Widget* parent = nullptr) : Widget(parent), _input_caption(this) Input(Widget* parent = nullptr) : Widget {parent}, _input_caption {this}
{ {
FocusHandler::_focus_area = &_widget_area; FocusHandler::_focus_area = &_widget_area;
MouseHandler::_click_area = &_widget_area; MouseHandler::_click_area = &_widget_area;

View file

@ -30,7 +30,7 @@ namespace bwidgets
Size margins = default_margins; Size margins = default_margins;
Layout(Widget* p = nullptr) : Widget(p) {} using Widget::Widget;
Layout(const Layout&) = delete; Layout(const Layout&) = delete;
Layout(Layout&&) = delete; Layout(Layout&&) = delete;

View file

@ -19,6 +19,8 @@ namespace bwidgets
SDL_Rect _viewport {0, 0, 0, 0}; SDL_Rect _viewport {0, 0, 0, 0};
SDL_Rect _widget_area {0, 0, 0, 0}; SDL_Rect _widget_area {0, 0, 0, 0};
explicit Widget(Widget* p = nullptr) noexcept : parent {p} {}
virtual void _handle_geometry_change(const SDL_Rect&) = 0; virtual void _handle_geometry_change(const SDL_Rect&) = 0;
virtual void _handle_renderer_change(const std::shared_ptr<Renderer>&) {} virtual void _handle_renderer_change(const std::shared_ptr<Renderer>&) {}
virtual void _handle_rendering() = 0; virtual void _handle_rendering() = 0;
@ -26,8 +28,6 @@ namespace bwidgets
public: public:
Widget* parent; Widget* parent;
Widget(Widget* p = nullptr) noexcept : parent(p) {}
Widget(const Widget&) noexcept = default; Widget(const Widget&) noexcept = default;
Widget(Widget&&) noexcept = default; Widget(Widget&&) noexcept = default;
virtual ~Widget() noexcept = default; virtual ~Widget() noexcept = default;

View file

@ -14,18 +14,19 @@ const Color Font::default_color_bg {255, 255, 255, SDL_ALPHA_OPAQUE};
const Color Font::default_color_fg {0, 0, 0, SDL_ALPHA_OPAQUE}; const Color Font::default_color_fg {0, 0, 0, SDL_ALPHA_OPAQUE};
Font::Font(TTF_Font* f) Font::Font(TTF_Font* f)
: Wrapper(ptr_or_throw<SDLError>(f), [f](TTF_Font*) noexcept { TTF_CloseFont(f); }), : Wrapper {ptr_or_throw<SDLError>(f), [f](TTF_Font*) noexcept { TTF_CloseFont(f); }},
ascent(TTF_FontAscent(f)), ascent {TTF_FontAscent(f)},
descent(TTF_FontDescent(f)), descent {TTF_FontDescent(f)},
faces(TTF_FontFaces(f)), faces {TTF_FontFaces(f)},
family_name(TTF_FontFaceFamilyName(f)), family_name {TTF_FontFaceFamilyName(f)},
fixed_width(TTF_FontFaceIsFixedWidth(f) != 0), fixed_width {TTF_FontFaceIsFixedWidth(f) != 0},
height(TTF_FontHeight(f)), height {TTF_FontHeight(f)},
line_skip(TTF_FontLineSkip(f)), line_skip {TTF_FontLineSkip(f)},
style_name(TTF_FontFaceStyleName(f)) style_name {TTF_FontFaceStyleName(f)}
{} {}
Font::Font(const std::string& file, int size) : Font(TTF_OpenFont(file.c_str(), size)) {} Font::Font(const std::string& file, int size) : Font {TTF_OpenFont(file.c_str(), size)}
{}
auto Font::hinting() const noexcept -> Font::Hinting auto Font::hinting() const noexcept -> Font::Hinting
{ {

View file

@ -4,13 +4,13 @@
using namespace bwidgets; using namespace bwidgets;
Renderer::Renderer(SDL_Renderer* r) Renderer::Renderer(SDL_Renderer* r)
: Wrapper(ptr_or_throw<SDLError>(r), : Wrapper {ptr_or_throw<SDLError>(r),
[r](SDL_Renderer*) noexcept { SDL_DestroyRenderer(r); }), [r](SDL_Renderer*) noexcept { SDL_DestroyRenderer(r); }},
info(_info(r)) info {_info(r)}
{} {}
Renderer::Renderer(SDL_Window* w, const int index, const uint32_t flags = 0) Renderer::Renderer(SDL_Window* w, const int index, const uint32_t flags = 0)
: Renderer(ptr_or_throw<SDLError>(SDL_CreateRenderer(w, index, flags))) : Renderer {ptr_or_throw<SDLError>(SDL_CreateRenderer(w, index, flags))}
{} {}
auto Renderer::blend_mode() -> SDL_BlendMode auto Renderer::blend_mode() -> SDL_BlendMode

View file

@ -4,19 +4,19 @@
using namespace bwidgets; using namespace bwidgets;
Texture::Texture(SDL_Texture* t) Texture::Texture(SDL_Texture* t)
: Wrapper(ptr_or_throw<SDLError>(t), : Wrapper {ptr_or_throw<SDLError>(t),
[t](SDL_Texture*) noexcept { SDL_DestroyTexture(t); }) [t](SDL_Texture*) noexcept { SDL_DestroyTexture(t); }}
{ {
_attributes = attributes(t); _attributes = attributes(t);
} }
Texture::Texture(Renderer* r, const SDL_PixelFormatEnum f, const SDL_TextureAccess a, Texture::Texture(Renderer* r, const SDL_PixelFormatEnum f, const SDL_TextureAccess a,
int w, int h) int w, int h)
: Texture(SDL_CreateTexture(r->_data(), f, a, w, h)) : Texture {SDL_CreateTexture(r->_data(), f, a, w, h)}
{} {}
Texture::Texture(Renderer* r, SDL_Surface* s) Texture::Texture(Renderer* r, SDL_Surface* s)
: Texture(SDL_CreateTextureFromSurface(r->_data(), s)) : Texture {SDL_CreateTextureFromSurface(r->_data(), s)}
{ {
_attributes = attributes(_data()); _attributes = attributes(_data());
} }

View file

@ -11,7 +11,7 @@ const Color Button::default_color_bg {150, 150, 150, SDL_ALPHA_OPAQUE};
const Color Button::default_color_bg_hover {175, 175, 175, SDL_ALPHA_OPAQUE}; const Color Button::default_color_bg_hover {175, 175, 175, SDL_ALPHA_OPAQUE};
const Color Button::default_color_fg {0, 0, 0, SDL_ALPHA_OPAQUE}; const Color Button::default_color_fg {0, 0, 0, SDL_ALPHA_OPAQUE};
Button::Button(Widget* parent) noexcept : Widget(parent), _caption(this) Button::Button(Widget* parent) noexcept : Widget{parent}, _caption{this}
{ {
_focus_area = _click_area = &_widget_area; _focus_area = _click_area = &_widget_area;
_caption.alignment = Caption::Alignment::CENTER; _caption.alignment = Caption::Alignment::CENTER;

View file

@ -7,7 +7,7 @@
using namespace bwidgets; using namespace bwidgets;
Caption::Caption(Widget* parent) noexcept : Widget(parent) Caption::Caption(Widget* parent) noexcept : Widget {parent}
{ {
_font_color_bg = default_font_color_bg; _font_color_bg = default_font_color_bg;
_font_color_fg = default_font_color_fg; _font_color_fg = default_font_color_fg;