Mercurial > malikania
view libclient/malikania/sprite.hpp @ 43:fabbe1759cec
Misc: switch to mlk namespace, closes #589
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 29 Nov 2016 22:25:17 +0100 |
parents | a47a4477f347 |
children | 858621081b95 |
line wrap: on
line source
/* * sprite.hpp -- image sprite * * Copyright (c) 2013-2016 Malikania Authors * * 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_SPRITE_HPP #define MALIKANIA_SPRITE_HPP /** * \file sprite.hpp * \brief Sprite description. */ #include "image.hpp" namespace mlk { /** * \brief A Sprite is an image divided into cells. */ class sprite { private: mlk::image m_image; mlk::size m_cell; mlk::size m_margin; mlk::size m_space; mlk::size m_size; unsigned m_rows; unsigned m_columns; public: /** * Construct a sprite. * * \pre cell must not have height or width null * \param image the image to use * \param cell size of cell in the image * \param margin the optional space from borders * \param space the optional space between cells * \param size the sprite size (if 0, taken from the image) */ sprite(mlk::image image, mlk::size cell, mlk::size margin = { 0, 0 }, mlk::size space = { 0, 0 }, mlk::size size = { 0, 0 }) noexcept; /** * Get the underlying image. * * \return the image */ inline const mlk::image& image() const noexcept { return m_image; } /** * Overloaded function. * * \return the image */ inline mlk::image& image() noexcept { return m_image; } /** * Get the cell size. * * \return the cell size */ inline const size& cell() const noexcept { return m_cell; } /** * Get the margin size. * * \return the margin size */ inline const size& margin() noexcept { return m_margin; } /** * Get the space size. * * \return the space size */ inline const size& space() const noexcept { return m_space; } /** * Get the number of rows in the grid. * * \return the number of rows */ inline unsigned rows() const noexcept { return m_rows; } /** * Get the number of columns in the grid. * * \return the number of columns */ inline unsigned columns() const noexcept { return m_columns; } /** * Draw the sprite into the window at the specified position. * * \pre cell < rows() * columns() * \param window the window * \param cell the cell index * \param position the position in the window */ void draw(window& window, unsigned cell, const point& position); }; } // !mlk #endif // !MALIKANIA_SPRITE_HPP