ManaPlus
imagesetloader.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2017 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "resources/imageset.h"
24 
25 #include "resources/image/image.h"
26 
29 
31 
32 #include "utils/checkutils.h"
33 #include "utils/stringutils.h"
34 
35 #include "debug.h"
36 
38 {
39  const std::string path;
40  const int w;
41  const int h;
42 
44 
45  static Resource *load(const void *const v)
46  {
47  if (v == nullptr)
48  return nullptr;
49 
50  const ImageSetLoader *const
51  rl = static_cast<const ImageSetLoader *>(v);
52 
53  Image *const img = Loader::getImage(rl->path);
54  if (img == nullptr)
55  {
56  reportAlways("Image loading error: %s", rl->path.c_str());
57  return nullptr;
58  }
59  ImageSet *const res = new ImageSet(img, rl->w, rl->h);
60  img->decRef();
61  return res;
62  }
63 };
64 
65 ImageSet *Loader::getImageSet(const std::string &imagePath,
66  const int w,
67  const int h)
68 {
69  ImageSetLoader rl = { imagePath, w, h };
70  const std::string str = std::string(
71  imagePath).append(
72  "[").append(toString(
73  w)).append(
74  "x").append(toString(
75  h)).append(
76  "]");
77  return static_cast<ImageSet*>(ResourceManager::get(str,
78  ImageSetLoader::load, &rl));
79 }
Resource * get(const std::string &idPath, generator fun, const void *const data)
ImageSet * getImageSet(const std::string &imagePath, const int w, const int h)
#define final
Definition: localconsts.h:45
#define A_DEFAULT_COPY(func)
Definition: localconsts.h:40
Image * getImage(const std::string &idPath)
Definition: imageloader.cpp:85
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
const std::string path
static Resource * load(const void *const v)
Definition: image.h:61
#define reportAlways(...)
Definition: checkutils.h:252
void decRef()
Definition: image.cpp:521