| 1 | // This file is part of Dust Racing 2D. |
| 2 | // Copyright (C) 2015 Jussi Lind <[email protected]> |
| 3 | // |
| 4 | // Dust Racing 2D is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // Dust Racing 2D is distributed in the hope that it will be useful, |
| 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | // GNU General Public License for more details. |
| 12 | // |
| 13 | // You should have received a copy of the GNU General Public License |
| 14 | // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>. |
| 15 | |
| 16 | #ifndef RENDERABLE_HPP |
| 17 | #define RENDERABLE_HPP |
| 18 | |
| 19 | #include <cstddef> |
| 20 | |
| 21 | //! Base class for items and overlays that are rendered on top of the game scene. |
| 22 | class Renderable |
| 23 | { |
| 24 | public: |
| 25 | //! Constructor. |
| 26 | Renderable() |
| 27 | : m_x(0) |
| 28 | , m_y(0) |
| 29 | , m_w(0) |
| 30 | , m_h(0) |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | //! Destructor. |
| 35 | virtual ~Renderable() = default; |
| 36 | |
| 37 | //! Render. |
| 38 | virtual void render() = 0; |
| 39 | |
| 40 | //! Set centered position. |
| 41 | void setPos(int x, int y) |
| 42 | { |
| 43 | m_x = x; |
| 44 | m_y = y; |
| 45 | } |
| 46 | |
| 47 | //! Get x. |
| 48 | int x() const |
| 49 | { |
| 50 | return m_x; |
| 51 | } |
| 52 | |
| 53 | //! Get y. |
| 54 | int y() const |
| 55 | { |
| 56 | return m_y; |
| 57 | } |
| 58 | |
| 59 | //! Set dimensions. |
| 60 | virtual void setDimensions(int width, int height) |
| 61 | { |
| 62 | m_w = width; |
| 63 | m_h = height; |
| 64 | } |
| 65 | |
| 66 | //! Get width. |
| 67 | int width() const |
| 68 | { |
| 69 | return m_w; |
| 70 | } |
| 71 | |
| 72 | //! Get height. |
| 73 | int height() const |
| 74 | { |
| 75 | return m_h; |
| 76 | } |
| 77 | |
| 78 | private: |
| 79 | int m_x; |
| 80 | |
| 81 | int m_y; |
| 82 | |
| 83 | int m_w; |
| 84 | |
| 85 | int m_h; |
| 86 | }; |
| 87 | |
| 88 | #endif // RENDERABLE_HPP |