Mercurial > malikania
view libmlk-client/malikania/client/texture.hpp @ 208:263122adef77
client: add texture and painter
closes #966 @2h
closes #967 @2h
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 05 Dec 2018 22:24:44 +0100 |
parents | |
children | b788b6a20eea |
line wrap: on
line source
/* * texture.hpp -- main window and basic drawing * * Copyright (c) 2013-2018 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef MALIKANIA_CLIENT_TEXTURE_HPP #define MALIKANIA_CLIENT_TEXTURE_HPP #include <memory> #include <SDL.h> #include <malikania/size.hpp> namespace mlk { struct line; struct point; struct rectangle; namespace client { class window; class painter; class texture { private: using handle = std::unique_ptr<SDL_Texture, void (*)(SDL_Texture*)>; handle texture_{nullptr, nullptr}; size size_; public: /** * Create default texture. * * \param win the window */ texture(window& win); /** * Create default texture. * * \param win the window * \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*; /** * Create a texture object from a SDL_Surface. * * 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 surface the surface */ texture(SDL_Renderer* renderer, SDL_Surface* surface); /** * Copy the texture to the painter. * * \param painter the painter * \param point the point */ void draw(painter& painter, const point& point); /** * Overloaded function. * * \param painter the painter * \param source the source * \param destination the destination */ void draw(painter& painter, const rectangle& source, const rectangle& destination); }; } // !client } // !mlk #endif // !MALIKANIA_CLIENT_TEXUTRE_HPP