From b11d574d9cba7e923b7c5a30a001274c21abe447 Mon Sep 17 00:00:00 2001 From: Andrea Blankenstijn Date: Sat, 14 Aug 2021 11:50:37 +0200 Subject: [PATCH] constructor style refactor --- inc/basic_widgets/core/type/color.hpp | 6 +++--- inc/basic_widgets/core/type/opaque_struct.hpp | 2 +- inc/basic_widgets/w/base/input.hpp | 2 +- inc/basic_widgets/w/base/layout.hpp | 2 +- inc/basic_widgets/w/base/widget.hpp | 4 ++-- src/core/font.cpp | 21 ++++++++++--------- src/core/renderer.cpp | 8 +++---- src/core/texture.cpp | 8 +++---- src/w/button.cpp | 2 +- src/w/caption.cpp | 2 +- 10 files changed, 29 insertions(+), 28 deletions(-) diff --git a/inc/basic_widgets/core/type/color.hpp b/inc/basic_widgets/core/type/color.hpp index adc450b..8c48cd1 100644 --- a/inc/basic_widgets/core/type/color.hpp +++ b/inc/basic_widgets/core/type/color.hpp @@ -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 diff --git a/inc/basic_widgets/core/type/opaque_struct.hpp b/inc/basic_widgets/core/type/opaque_struct.hpp index 3edcc96..af5c3e5 100644 --- a/inc/basic_widgets/core/type/opaque_struct.hpp +++ b/inc/basic_widgets/core/type/opaque_struct.hpp @@ -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; diff --git a/inc/basic_widgets/w/base/input.hpp b/inc/basic_widgets/w/base/input.hpp index a80b141..353578a 100644 --- a/inc/basic_widgets/w/base/input.hpp +++ b/inc/basic_widgets/w/base/input.hpp @@ -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; diff --git a/inc/basic_widgets/w/base/layout.hpp b/inc/basic_widgets/w/base/layout.hpp index 9a4b6b4..845a19f 100644 --- a/inc/basic_widgets/w/base/layout.hpp +++ b/inc/basic_widgets/w/base/layout.hpp @@ -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; diff --git a/inc/basic_widgets/w/base/widget.hpp b/inc/basic_widgets/w/base/widget.hpp index f7aa335..09aa52d 100644 --- a/inc/basic_widgets/w/base/widget.hpp +++ b/inc/basic_widgets/w/base/widget.hpp @@ -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&) {} 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; diff --git a/src/core/font.cpp b/src/core/font.cpp index 92f26af..1cfcf83 100644 --- a/src/core/font.cpp +++ b/src/core/font.cpp @@ -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(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(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 { diff --git a/src/core/renderer.cpp b/src/core/renderer.cpp index f963e05..0ddad64 100644 --- a/src/core/renderer.cpp +++ b/src/core/renderer.cpp @@ -4,13 +4,13 @@ using namespace bwidgets; Renderer::Renderer(SDL_Renderer* r) - : Wrapper(ptr_or_throw(r), - [r](SDL_Renderer*) noexcept { SDL_DestroyRenderer(r); }), - info(_info(r)) + : Wrapper {ptr_or_throw(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(SDL_CreateRenderer(w, index, flags))) + : Renderer {ptr_or_throw(SDL_CreateRenderer(w, index, flags))} {} auto Renderer::blend_mode() -> SDL_BlendMode diff --git a/src/core/texture.cpp b/src/core/texture.cpp index f303674..6b326f4 100644 --- a/src/core/texture.cpp +++ b/src/core/texture.cpp @@ -4,19 +4,19 @@ using namespace bwidgets; Texture::Texture(SDL_Texture* t) - : Wrapper(ptr_or_throw(t), - [t](SDL_Texture*) noexcept { SDL_DestroyTexture(t); }) + : Wrapper {ptr_or_throw(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()); } diff --git a/src/w/button.cpp b/src/w/button.cpp index b86ca48..24babe2 100644 --- a/src/w/button.cpp +++ b/src/w/button.cpp @@ -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; diff --git a/src/w/caption.cpp b/src/w/caption.cpp index 16d4cd5..ba571e2 100644 --- a/src/w/caption.cpp +++ b/src/w/caption.cpp @@ -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;