Mana
Loading...
Searching...
No Matches
imageset.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "resources/imageset.h"
23
24#include "log.h"
25
26#include "resources/image.h"
27
28#include "utils/dtor.h"
29
30ImageSet::ImageSet(Image *img, int width, int height,
31 int margin, int spacing) :
32 mWidth(width),
33 mHeight(height)
34{
35 for (int y = margin; y + height <= img->getHeight() - margin; y += height + spacing)
36 {
37 for (int x = margin; x + width <= img->getWidth() - margin; x += width + spacing)
38 {
39 mImages.push_back(img->getSubImage(x, y, width, height));
40 }
41 }
42}
43
48
49Image *ImageSet::get(size_t i) const
50{
51 if (i >= mImages.size())
52 {
53 Log::warn("No sprite %d in this image set", (int) i);
54 return nullptr;
55 }
56
57 return mImages[i];
58}
std::vector< Image * > mImages
Definition imageset.h:73
ImageSet(Image *img, int w, int h, int margin=0, int spacing=0)
Cuts the passed image in a grid of sub images.
Definition imageset.cpp:30
~ImageSet() override
Definition imageset.cpp:44
Image * get(size_t i) const
Definition imageset.cpp:49
Defines a class for loading and storing images.
Definition image.h:45
int getHeight() const
Returns the height of the image.
Definition image.h:89
int getWidth() const
Returns the width of the image.
Definition image.h:83
Image * getSubImage(int x, int y, int width, int height)
Creates a new image with the desired clipping rectangle.
Definition image.cpp:331
void delete_all(Container &c)
Definition dtor.h:46
void warn(const char *log_text,...) LOG_PRINTF_ATTR