ManaPlus
subimageloader.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/image/image.h"
24 
26 
28 
29 #include "utils/checkutils.h"
30 #include "utils/stringutils.h"
31 
32 #include "debug.h"
33 
34 namespace
35 {
37  {
39 
40  Image *const parent;
41  const int x;
42  const int y;
43  const int width;
44  const int height;
45  static Resource *load(const void *const v)
46  {
47  if (v == nullptr)
48  return nullptr;
49 
50  const SubImageLoader *const
51  rl = static_cast<const SubImageLoader *>(v);
52  if (rl->parent == nullptr)
53  return nullptr;
54 
55  Image *const res = rl->parent->getSubImage(rl->x, rl->y,
56  rl->width, rl->height);
57  if (res == nullptr)
58  {
59  reportAlways("SubImage loading error: %s",
60  rl->parent->mSource.c_str());
61  }
62  return res;
63  }
64  };
65 } // namespace
66 
68  const int x,
69  const int y,
70  const int width,
71  const int height)
72 {
73  if (parent == nullptr)
74  return nullptr;
75 
76  const SubImageLoader rl = { parent, x, y, width, height};
77 
78  const std::string str = std::string(parent->mIdPath).append(
79  ",[").append(
80  toString(x)).append(
81  ",").append(
82  toString(y)).append(
83  ",").append(
84  toString(width)).append(
85  "x").append(
86  toString(height)).append(
87  "]");
88  return static_cast<Image*>(ResourceManager::get(str,
89  SubImageLoader::load, &rl));
90 }
std::string mSource
Definition: resource.h:84
Resource * get(const std::string &idPath, generator fun, const void *const data)
#define final
Definition: localconsts.h:45
#define A_DEFAULT_COPY(func)
Definition: localconsts.h:40
virtual Image * getSubImage(const int x, const int y, const int width, const int height)
Definition: image.cpp:465
Image * getSubImage(Image *const parent, const int x, const int y, const int width, const int height)
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
Definition: image.h:61
std::string mIdPath
Definition: resource.h:83
#define reportAlways(...)
Definition: checkutils.h:252