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,
bool op_on_colors = true) noexcept
: _operate_on_alpha(op_on_alpha),
_operate_on_colors(op_on_colors),
sdl_type({r, g, b, a})
: _operate_on_alpha {op_on_alpha},
_operate_on_colors {op_on_colors},
sdl_type {r, g, b, a}
{}
inline Color(const SDL_Color& c = {}, bool op_on_alpha = false,
bool op_on_colors = true) noexcept

View File

@ -15,7 +15,7 @@ namespace bwidgets
T* _c_pod;
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(OpaqueStruct&&) = delete;

View File

@ -28,7 +28,7 @@ namespace bwidgets
protected:
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;
MouseHandler::_click_area = &_widget_area;

View File

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

View File

@ -19,6 +19,8 @@ namespace bwidgets
SDL_Rect _viewport {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_renderer_change(const std::shared_ptr<Renderer>&) {}
virtual void _handle_rendering() = 0;
@ -26,8 +28,6 @@ namespace bwidgets
public:
Widget* parent;
Widget(Widget* p = nullptr) noexcept : parent(p) {}
Widget(const Widget&) noexcept = default;
Widget(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};
Font::Font(TTF_Font* f)
: Wrapper(ptr_or_throw<SDLError>(f), [f](TTF_Font*) noexcept { TTF_CloseFont(f); }),
ascent(TTF_FontAscent(f)),
descent(TTF_FontDescent(f)),
faces(TTF_FontFaces(f)),
family_name(TTF_FontFaceFamilyName(f)),
fixed_width(TTF_FontFaceIsFixedWidth(f) != 0),
height(TTF_FontHeight(f)),
line_skip(TTF_FontLineSkip(f)),
style_name(TTF_FontFaceStyleName(f))
: Wrapper {ptr_or_throw<SDLError>(f), [f](TTF_Font*) noexcept { TTF_CloseFont(f); }},
ascent {TTF_FontAscent(f)},
descent {TTF_FontDescent(f)},
faces {TTF_FontFaces(f)},
family_name {TTF_FontFaceFamilyName(f)},
fixed_width {TTF_FontFaceIsFixedWidth(f) != 0},
height {TTF_FontHeight(f)},
line_skip {TTF_FontLineSkip(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
{

View File

@ -4,13 +4,13 @@
using namespace bwidgets;
Renderer::Renderer(SDL_Renderer* r)
: Wrapper(ptr_or_throw<SDLError>(r),
[r](SDL_Renderer*) noexcept { SDL_DestroyRenderer(r); }),
info(_info(r))
: Wrapper {ptr_or_throw<SDLError>(r),
[r](SDL_Renderer*) noexcept { SDL_DestroyRenderer(r); }},
info {_info(r)}
{}
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

View File

@ -4,19 +4,19 @@
using namespace bwidgets;
Texture::Texture(SDL_Texture* t)
: Wrapper(ptr_or_throw<SDLError>(t),
[t](SDL_Texture*) noexcept { SDL_DestroyTexture(t); })
: Wrapper {ptr_or_throw<SDLError>(t),
[t](SDL_Texture*) noexcept { SDL_DestroyTexture(t); }}
{
_attributes = attributes(t);
}
Texture::Texture(Renderer* r, const SDL_PixelFormatEnum f, const SDL_TextureAccess a,
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(SDL_CreateTextureFromSurface(r->_data(), s))
: Texture {SDL_CreateTextureFromSurface(r->_data(), s)}
{
_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_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;
_caption.alignment = Caption::Alignment::CENTER;

View File

@ -7,7 +7,7 @@
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_fg = default_font_color_fg;