Mercurial > malikania
changeset 209:b788b6a20eea
client: some cleanup in texture
While here, take a painter rather than a window as we only need a renderer.
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 18 Dec 2018 12:38:21 +0100 |
parents | 263122adef77 |
children | 1599919b5de6 |
files | libmlk-client-js/malikania/client/js/texture_js_api.cpp libmlk-client/malikania/client/image.cpp libmlk-client/malikania/client/texture.cpp libmlk-client/malikania/client/texture.hpp |
diffstat | 4 files changed, 41 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- 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<window>(ctx, 0), + mlk::js::duk::require<painter>(ctx, 0), mlk::js::duk::require<unsigned>(ctx, 1), mlk::js::duk::require<unsigned>(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) {
--- 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)
--- 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 <markand@malikania.fr> * @@ -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<unsigned>(surface->w),
--- 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 <markand@malikania.fr> * @@ -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.