| 1 | // SuperTux |
| 2 | // Copyright (C) 2016 Hume2 <teratux.mail@gmail.com> |
| 3 | // |
| 4 | // This program 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 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
| 17 | #include "editor/tile_selection.hpp" |
| 18 | |
| 19 | TileSelection::TileSelection() : |
| 20 | m_tiles(1), |
| 21 | m_width(1), |
| 22 | m_height(1) |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | uint32_t |
| 27 | TileSelection::pos(int x, int y) const |
| 28 | { |
| 29 | x = x % m_width; |
| 30 | y = y % m_height; |
| 31 | if (x < 0) { |
| 32 | x += m_width; |
| 33 | } |
| 34 | if (y < 0) { |
| 35 | y += m_height; |
| 36 | } |
| 37 | |
| 38 | return m_tiles[x + y * m_width]; |
| 39 | } |
| 40 | |
| 41 | void |
| 42 | TileSelection::set_tile(uint32_t tile) |
| 43 | { |
| 44 | m_tiles.clear(); |
| 45 | m_width = 1; |
| 46 | m_height = 1; |
| 47 | m_tiles.push_back(tile); |
| 48 | } |
| 49 | |
| 50 | bool |
| 51 | TileSelection::empty() const |
| 52 | { |
| 53 | for (const auto& tile : m_tiles) { |
| 54 | if (tile != 0) { |
| 55 | return false; |
| 56 | } |
| 57 | } |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | /* EOF */ |
| 62 | |