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-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include "resources/image/image.h"
25 
27 
29 
30 #include "utils/checkutils.h"
31 #include "utils/stringutils.h"
32 
33 #include "debug.h"
34 
35 namespace
36 {
38  {
40 
41  Image *const parent;
42  const int x;
43  const int y;
44  const int width;
45  const int height;
46  static Resource *load(const void *const v)
47  {
48  if (v == nullptr)
49  return nullptr;
50 
51  const SubImageLoader *const
52  rl = static_cast<const SubImageLoader *>(v);
53  if (rl->parent == nullptr)
54  return nullptr;
55 
56  Image *const res = rl->parent->getSubImage(rl->x, rl->y,
57  rl->width, rl->height);
58  if (res == nullptr)
59  {
60  reportAlways("SubImage loading error: %s",
61  rl->parent->mSource.c_str())
62  }
63  return res;
64  }
65  };
66 } // namespace
67 
69  const int x,
70  const int y,
71  const int width,
72  const int height)
73 {
74  if (parent == nullptr)
75  return nullptr;
76 
77  const SubImageLoader rl = { parent, x, y, width, height};
78 
79  const std::string str = std::string(parent->mIdPath).append(
80  ",[").append(
81  toString(x)).append(
82  ",").append(
83  toString(y)).append(
84  ",").append(
85  toString(width)).append(
86  "x").append(
87  toString(height)).append(
88  "]");
89  return static_cast<Image*>(ResourceManager::get(str,
90  SubImageLoader::load, &rl));
91 }
#define reportAlways(...)
Definition: checkutils.h:253
#define final
Definition: localconsts.h:46
#define A_DEFAULT_COPY(func)
Definition: localconsts.h:41
void load()
Definition: avatardb.cpp:46
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
Image * getSubImage(Image *const parent, const int x, const int y, const int width, const int height)
Resource * get(const std::string &idPath, generator fun, const void *const data)