SDXFrameWork  0.10
SDXFrameWork
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
ImagePack.h
1 //Copyright © 2014 SDXFramework
2 //[License]GNU Affero General Public License, version 3
3 //[Contact]http://sourceforge.jp/projects/dxframework/
4 #pragma once
5 #include <Multimedia/SDX.h>
6 #include <Multimedia/Image.h>
7 #include <Multimedia/Loading.h>
8 
9 namespace SDX
10 {
14  class ImagePack
15  {
16  protected:
17  std::vector<Image*> imageS;
18  int widthMax = 0;
19  int heightMax = 0;
20  public:
21  ImagePack() = default;
22 
24  ImagePack(const char *ファイル名, int 総コマ数, int コマ割り横, int コマ割り縦)
25  {
26  ImagePack::Load(ファイル名, 総コマ数, コマ割り横, コマ割り縦);
27  }
28 
32  ImagePack(const char *ファイル名, const char *拡張子, int 総コマ数, const char* 書式 = "%03d.")
33  {
34  Load(ファイル名, 拡張子, 総コマ数, 書式);
35  }
36 
44  bool Load(const char *ファイル名, int 総コマ数, int コマ割り横, int コマ割り縦)
45  {
46  if (Loading::isLoading)
47  {
48  Loading::AddLoading([=]{ Load(ファイル名,総コマ数,コマ割り横,コマ割り縦); });
49  return true;
50  }
51 
52  int x = 0, y = 0, count = 0;
53  Image image(ファイル名);
54 
55  const int width = image.GetWidth() / コマ割り横;
56  const int height = image.GetHeight() / コマ割り縦;
57 
58  for (int a = 0; a < コマ割り縦; ++a)
59  {
60  x = 0;
61  for (int b = 0; b < コマ割り横; ++b)
62  {
63  if (count >= 総コマ数) break;
64  this->Add(new Image(image, { x, y, width, height }));
65  x += width;
66  count++;
67  }
68  y += height;
69  }
70 
71  return true;
72  }
73 
77  bool Load(const char *ファイル名, const char *拡張子, int 総コマ数, const char* 書式 = "%03d.")
78  {
79  if (Loading::isLoading)
80  {
81  Loading::AddLoading([=]{ Load(ファイル名, 拡張子 ,総コマ数, 書式); });
82  return true;
83  }
84 
85  for (int a = 0; a < 総コマ数; ++a)
86  {
87  char fileBuf[8];
88  sprintf_s(fileBuf, 8, 書式, a);
89 
90  std::string fileName = ファイル名;
91  fileName += fileBuf;
92  fileName += 拡張子;
93 
94  this->Add(new Image(fileName.c_str()));
95  }
96  return true;
97  }
98 
100  void Add(Image *追加イメージ)
101  {
102  imageS.push_back(追加イメージ);
103  this->widthMax = std::max(this->widthMax, 追加イメージ->GetWidth());
104  this->heightMax = std::max(this->heightMax, 追加イメージ->GetHeight());
105  }
107  void Add(const char *ファイル名)
108  {
109  Add(new Image(ファイル名));
110  }
111 
113  virtual void Release()
114  {
115  for (auto it : imageS)
116  {
117  it->Release();
118  }
119 
120  imageS.clear();
121  }
122 
124  int GetSize() const
125  {
126  return (int)imageS.size();
127  }
128 
130  int GetWidth() const
131  {
132  return this->widthMax;
133  }
134 
136  int GetHeight() const
137  {
138  return this->heightMax;
139  }
140 
142  void SetColor(const Color &描画色)
143  {
144  for (auto && it : imageS)
145  {
146  it->SetColor(描画色);
147  }
148  }
149 
153  void AdjustWidth(std::vector<int> 幅)
154  {
155  if (Loading::isLoading)
156  {
157  Loading::AddLoading([=]{ AdjustWidth(幅); });
158  return;
159  }
160 
161  for (unsigned int a = 0; a < 幅.size();++a)
162  {
163  imageS[a]->part.w -= 幅[a];
164  }
165  }
166 
168  Image* operator[](int index)
169  {
170  return imageS[index];
171  }
172 
174  Image* operator[](int index) const
175  {
176  return imageS[index];
177  }
178 
180  auto begin() ->decltype(imageS.begin())
181  {
182  return imageS.begin();
183  }
184 
186  auto end() ->decltype(imageS.end())
187  {
188  return imageS.end();
189  }
190 
192  auto begin() const ->decltype(imageS.begin())
193  {
194  return imageS.begin();
195  }
196 
198  auto end() const ->decltype(imageS.end())
199  {
200  return imageS.end();
201  }
202 
203 
204  };
205 }
int widthMax
最大幅
Definition: ImagePack.h:18
Image * operator[](int index) const
オペレータ.
Definition: ImagePack.h:174
ImagePack(const char *ファイル名, const char *拡張子, int 総コマ数, const char *書式="%03d.")
連番ファイルを一括して読み込む.
Definition: ImagePack.h:32
virtual void Release()
Imageをメモリから開放.
Definition: ImagePack.h:113
int GetWidth() const
最大幅を取得.
Definition: ImagePack.h:130
std::vector< Image * > imageS
保持するImage
Definition: ImagePack.h:17
auto end() -> decltype(imageS.end())
イテレータ用.
Definition: ImagePack.h:186
bool Load(const char *ファイル名, const char *拡張子, int 総コマ数, const char *書式="%03d.")
連番ファイルを一括して読み込む.
Definition: ImagePack.h:77
画像データを表すクラス.
Definition: Image.h:17
Image * operator[](int index)
オペレータ.
Definition: ImagePack.h:168
色を表すクラス.
Definition: Color.h:11
void Add(const char *ファイル名)
Imageを末尾に追加.
Definition: ImagePack.h:107
bool Load(const char *ファイル名, int 総コマ数, int コマ割り横, int コマ割り縦)
1つの画像を分割して読み込む.
Definition: ImagePack.h:44
static void AddLoading(std::function< void(void)> &&読み込み関数)
非同期読み込み処理に追加.
Definition: Loading.h:96
int GetHeight() const
高さを取得.
Definition: Image.h:310
int GetWidth() const
幅を取得.
Definition: Image.h:304
void AdjustWidth(std::vector< int > 幅)
先頭からimageの幅を差分修正.
Definition: ImagePack.h:153
int GetSize() const
要素数を取得.
Definition: ImagePack.h:124
auto end() const -> decltype(imageS.end())
イテレータ用.
Definition: ImagePack.h:198
auto begin() -> decltype(imageS.begin())
イテレータ用.
Definition: ImagePack.h:180
int GetHeight() const
最大高さを取得.
Definition: ImagePack.h:136
ImagePack(const char *ファイル名, int 総コマ数, int コマ割り横, int コマ割り縦)
1つの画像を分割して読み込む.
Definition: ImagePack.h:24
複数のImageをまとめるクラス.
Definition: ImagePack.h:14
void Add(Image *追加イメージ)
Imageを末尾に追加.
Definition: ImagePack.h:100
int heightMax
最大高さ
Definition: ImagePack.h:19
void SetColor(const Color &描画色)
描画色をまとめて変更.
Definition: ImagePack.h:142
auto begin() const -> decltype(imageS.begin())
イテレータ用.
Definition: ImagePack.h:192