use raw ptr instead of fancy one when no references are kept after function
exit.
This commit is contained in:
parent
0642d89803
commit
43dd6ab820
9 changed files with 18 additions and 18 deletions
|
@ -19,7 +19,7 @@ namespace bwidgets
|
|||
std::shared_ptr<Renderer>, int aa_pixels = 3)
|
||||
-> std::shared_ptr<Texture>;
|
||||
void set_pixels_color(
|
||||
std::shared_ptr<Texture>,
|
||||
Texture*,
|
||||
const std::function<uint32_t(const SDL_Point&, const SDL_PixelFormat*)>&);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace bwidgets
|
|||
[[nodiscard]] auto blend_mode() -> SDL_BlendMode;
|
||||
auto blend_mode(SDL_BlendMode) -> Renderer*;
|
||||
auto clear() -> Renderer*;
|
||||
auto copy(const std::shared_ptr<Texture>&, const SDL_Rect*, const SDL_Rect*)
|
||||
auto copy(const Texture*, const SDL_Rect*, const SDL_Rect*)
|
||||
-> Renderer*;
|
||||
[[nodiscard]] auto draw_color() -> Color;
|
||||
auto draw_color(const Color&) -> Renderer*;
|
||||
|
@ -61,19 +61,19 @@ namespace bwidgets
|
|||
[[nodiscard]] auto viewport() noexcept -> SDL_Rect;
|
||||
auto viewport(const SDL_Rect*) -> Renderer*;
|
||||
|
||||
inline auto copy(const std::shared_ptr<Texture>& t, const SDL_Rect* src,
|
||||
inline auto copy(const Texture* t, const SDL_Rect* src,
|
||||
const SDL_Rect& dst)
|
||||
{
|
||||
const auto d = dst;
|
||||
return copy(t, src, &d);
|
||||
}
|
||||
inline auto copy(const std::shared_ptr<Texture>& t, const SDL_Rect& src,
|
||||
inline auto copy(const Texture* t, const SDL_Rect& src,
|
||||
const SDL_Rect* dst)
|
||||
{
|
||||
const auto s = src;
|
||||
return copy(t, &s, dst);
|
||||
}
|
||||
inline auto copy(const std::shared_ptr<Texture>& t, const SDL_Rect& src,
|
||||
inline auto copy(const Texture* t, const SDL_Rect& src,
|
||||
const SDL_Rect& dst)
|
||||
{
|
||||
const auto s = src;
|
||||
|
|
|
@ -29,9 +29,9 @@ namespace bwidgets
|
|||
|
||||
public:
|
||||
Texture(SDL_Texture*);
|
||||
Texture(const std::shared_ptr<Renderer>&, SDL_PixelFormatEnum, SDL_TextureAccess,
|
||||
Texture(Renderer*, SDL_PixelFormatEnum, SDL_TextureAccess,
|
||||
int, int);
|
||||
Texture(const std::shared_ptr<Renderer>&, SDL_Surface*);
|
||||
Texture(Renderer*, SDL_Surface*);
|
||||
Texture(const Texture&) = delete;
|
||||
Texture(Texture&&) = delete;
|
||||
~Texture() noexcept;
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace bwidgets
|
|||
|
||||
virtual auto add_widget(const std::shared_ptr<Widget>&) -> Layout*;
|
||||
virtual void
|
||||
for_widgets(const std::function<void(const std::shared_ptr<Widget>&)>&);
|
||||
for_widgets(const std::function<void(Widget*)>&);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace bwidgets
|
|||
return c;
|
||||
}
|
||||
|
||||
auto filled_circle(const Color& c, const int resolution, std::shared_ptr<Renderer> r,
|
||||
auto filled_circle(const Color& c, const int resolution, Renderer* r,
|
||||
const int aa_pixels) -> std::shared_ptr<Texture>
|
||||
{
|
||||
// clang-format off
|
||||
|
@ -40,7 +40,7 @@ namespace bwidgets
|
|||
const SDL_Point center {radius, radius};
|
||||
|
||||
set_pixels_color(
|
||||
texture,
|
||||
texture.get(),
|
||||
[aa_pixels, c, center, radius](const SDL_Point& p,
|
||||
const SDL_PixelFormat* format) -> uint32_t {
|
||||
const auto d_delta = distance(center, p) - (float)radius;
|
||||
|
@ -56,7 +56,7 @@ namespace bwidgets
|
|||
}
|
||||
|
||||
void set_pixels_color(
|
||||
const std::shared_ptr<Texture>& t,
|
||||
Texture* t,
|
||||
const std::function<uint32_t(const SDL_Point&, const SDL_PixelFormat*)>&
|
||||
pixel_color)
|
||||
{
|
||||
|
|
|
@ -39,7 +39,7 @@ auto Renderer::clear() -> Renderer*
|
|||
return this;
|
||||
}
|
||||
|
||||
auto Renderer::copy(const std::shared_ptr<Texture>& t, const SDL_Rect* src,
|
||||
auto Renderer::copy(const Texture* t, const SDL_Rect* src,
|
||||
const SDL_Rect* dst) -> Renderer*
|
||||
{
|
||||
SDLError::success_or_throw(SDL_RenderCopy(_data(), t->_data(), src, dst), __FILE__,
|
||||
|
|
|
@ -10,12 +10,12 @@ Texture::Texture(SDL_Texture* t)
|
|||
_attributes = attributes(t);
|
||||
}
|
||||
|
||||
Texture::Texture(const std::shared_ptr<Renderer>& r, const SDL_PixelFormatEnum f,
|
||||
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::Texture(const std::shared_ptr<Renderer>& r, SDL_Surface* s)
|
||||
Texture::Texture(Renderer* r, SDL_Surface* s)
|
||||
: Texture(SDL_CreateTextureFromSurface(r->_data(), s))
|
||||
{
|
||||
_attributes = attributes(_data());
|
||||
|
|
|
@ -10,9 +10,9 @@ auto Layout::add_widget(const std::shared_ptr<Widget>& widget_ptr) -> Layout*
|
|||
return this;
|
||||
}
|
||||
|
||||
void Layout::for_widgets(const std::function<void(const std::shared_ptr<Widget>&)>& f)
|
||||
void Layout::for_widgets(const std::function<void(Widget*)>& f)
|
||||
{
|
||||
for (const auto& w : _widgets) f(w);
|
||||
for (const auto& w : _widgets) f(w.get());
|
||||
}
|
||||
|
||||
auto Layout::handle_event(const SDL_Event& ev) -> Layout*
|
||||
|
|
|
@ -96,7 +96,7 @@ void Caption::_handle_rendering()
|
|||
texture_dst.x = _widget_area.w - texture_dst.w - margins.w + _widget_area.x;
|
||||
break;
|
||||
}
|
||||
_renderer->copy(_text_texture, nullptr, texture_dst);
|
||||
_renderer->copy(_text_texture.get(), nullptr, texture_dst);
|
||||
}
|
||||
|
||||
void Caption::_handle_texture_update()
|
||||
|
@ -111,6 +111,6 @@ void Caption::_handle_texture_update()
|
|||
s = _font->render(_render_mode, _text, _font_color_fg);
|
||||
break;
|
||||
}
|
||||
_text_texture = std::make_shared<Texture>(_renderer, s);
|
||||
_text_texture = std::make_shared<Texture>(_renderer.get(), s);
|
||||
SDL_FreeSurface(s);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue