# HG changeset patch # User David Demelier # Date 1545133101 -3600 # Node ID b788b6a20eea759046b755a5b5eb1c0775038a91 # Parent 263122adef77898ab4b12f0197385d248a7c0166 client: some cleanup in texture While here, take a painter rather than a window as we only need a renderer. diff -r 263122adef77 -r b788b6a20eea libmlk-client-js/malikania/client/js/texture_js_api.cpp --- a/libmlk-client-js/malikania/client/js/texture_js_api.cpp Wed Dec 05 22:24:44 2018 +0100 +++ b/libmlk-client-js/malikania/client/js/texture_js_api.cpp Tue Dec 18 12:38:21 2018 +0100 @@ -60,14 +60,14 @@ try { duk_push_this(ctx); duk_push_pointer(ctx, new texture( - mlk::js::duk::require(ctx, 0), + mlk::js::duk::require(ctx, 0), mlk::js::duk::require(ctx, 1), mlk::js::duk::require(ctx, 2) )); - // Save window to avoid its destruction. + // Save painter to avoid its destruction. duk_dup(ctx, 0); - duk_put_prop_string(ctx, -2, DUK_HIDDEN_SYMBOL("window")); + duk_put_prop_string(ctx, -2, DUK_HIDDEN_SYMBOL("painter")); duk_put_prop_string(ctx, -2, signature.data()); duk_pop(ctx); } catch (const std::exception& ex) { diff -r 263122adef77 -r b788b6a20eea libmlk-client/malikania/client/image.cpp --- a/libmlk-client/malikania/client/image.cpp Wed Dec 05 22:24:44 2018 +0100 +++ b/libmlk-client/malikania/client/image.cpp Tue Dec 18 12:38:21 2018 +0100 @@ -26,7 +26,7 @@ void image::create_texture(painter& p) { - texture_ = texture(p.get_renderer(), surface_.get()); + texture_ = texture(p, surface_.get()); } image::image(std::string data) diff -r 263122adef77 -r b788b6a20eea libmlk-client/malikania/client/texture.cpp --- a/libmlk-client/malikania/client/texture.cpp Wed Dec 05 22:24:44 2018 +0100 +++ b/libmlk-client/malikania/client/texture.cpp Tue Dec 18 12:38:21 2018 +0100 @@ -1,5 +1,5 @@ /* - * texture.cpp -- main window and basic drawing + * texture.cpp -- off-screen texture * * Copyright (c) 2013-2018 David Demelier * @@ -26,15 +26,15 @@ namespace mlk::client { -texture::texture(window& win) +texture::texture(painter& painter) { - SDL_SetRenderTarget(win.get_renderer(), nullptr); + SDL_SetRenderTarget(painter.get_renderer(), nullptr); } -texture::texture(window& win, unsigned width, unsigned height) +texture::texture(painter& painter, unsigned width, unsigned height) { auto texture = SDL_CreateTexture( - win.get_renderer(), + painter.get_renderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width, @@ -61,8 +61,8 @@ }; } -texture::texture(SDL_Renderer* renderer, SDL_Surface* surface) - : texture_(SDL_CreateTextureFromSurface(renderer, surface), SDL_DestroyTexture) +texture::texture(painter& painter, SDL_Surface* surface) + : texture_(SDL_CreateTextureFromSurface(painter.get_renderer(), surface), SDL_DestroyTexture) { size_ = { static_cast(surface->w), diff -r 263122adef77 -r b788b6a20eea libmlk-client/malikania/client/texture.hpp --- a/libmlk-client/malikania/client/texture.hpp Wed Dec 05 22:24:44 2018 +0100 +++ b/libmlk-client/malikania/client/texture.hpp Tue Dec 18 12:38:21 2018 +0100 @@ -1,5 +1,5 @@ /* - * texture.hpp -- main window and basic drawing + * texture.hpp -- off-screen texture * * Copyright (c) 2013-2018 David Demelier * @@ -33,7 +33,6 @@ namespace client { -class window; class painter; class texture { @@ -47,29 +46,18 @@ /** * Create default texture. * - * \param win the window + * \param painter the painter */ - texture(window& win); + texture(painter& painter); /** * Create default texture. * - * \param win the window + * \param painter the painter * \param width the width * \param height the height */ - texture(window& win, unsigned width, unsigned height); - - /** - * Create a texture object from a native SDL type. - * - * \param texture the handle - */ - texture(SDL_Texture* texture); - - auto get_texture() const noexcept -> const SDL_Texture*; - - auto get_texture() noexcept -> SDL_Texture*; + texture(painter& painter, unsigned width, unsigned height); /** * Create a texture object from a SDL_Surface. @@ -77,12 +65,34 @@ * This function does not take ownership of the surface but can be * safely deleted. * - * \pre renderer != nullptr * \pre surface != nullptr - * \param renderer the renderer + * \param painter the painter * \param surface the surface */ - texture(SDL_Renderer* renderer, SDL_Surface* surface); + texture(painter& painter, SDL_Surface* surface); + + /** + * Create a texture object from a native SDL type. + * + * This function takes ownership of the texture. + * + * \param texture the handle + */ + texture(SDL_Texture* texture); + + /** + * Get the native underlying texture. + * + * \return the texture + */ + auto get_texture() const noexcept -> const SDL_Texture*; + + /** + * Overloaded function. + * + * \return the texture + */ + auto get_texture() noexcept -> SDL_Texture*; /** * Copy the texture to the painter.