SDXFrameWork  0.04
SDXFrameWork
 全て クラス ネームスペース 関数 変数 ページ
ImagePack.h
1 #pragma once
2 #include<Multimedia/SDX.h>
3 #include<Multimedia/Image.h>
4 
5 namespace SDX
6 {
8 class ImagePack
10 {
11 protected:
12  std::vector<Image*> images;
13  int widthMax;
14  int heightMax;
15 public:
16  ImagePack():
17  widthMax( 0 ),
18  heightMax( 0 )
19  {}
20 
22  ImagePack( const char *ファイル名 , int 総コマ数 , int コマ割り横,int コマ割り縦)
23  {
24  ImagePack::Load(ファイル名,総コマ数 , コマ割り横, コマ割り縦 );
25  }
26 
28  virtual bool Load(const char *ファイル名 , int 総コマ数,int コマ割り横, int コマ割り縦 )
35  {
36  int x = 0, y = 0, count = 0;
37  Image image(ファイル名);
38 
39  const int width = image.GetWidth() / コマ割り横;
40  const int height = image.GetHeight() / コマ割り縦;
41 
42  for (int i = 0; i < コマ割り縦; ++i)
43  {
44  x = 0;
45  for (int j = 0; j < コマ割り横; j++)
46  {
47  if (count >= 総コマ数) break;
48  this->Add(new Image(image, x, y, width, height));
49  x += width;
50  count++;
51  }
52  y += height;
53  }
54 
55  return true;
56  }
57 
59  virtual bool Load(const char *ファイル名 , const char *拡張子 , int 総コマ数 )
62  {
63  for(int i=0 ; i<総コマ数 ; ++i)
64  {
65  char fileBuf[8];
66  sprintf_s( fileBuf , 8 , "%03d." , i );
67 
68  std::string fileName = ファイル名;
69  fileName += fileBuf;
70  fileName += 拡張子;
71 
72  this->Add( new Image( fileName.c_str() ) );
73  }
74  return true;
75  }
76 
78  virtual void Add(Image *追加イメージ)
80  {
81  images.push_back( 追加イメージ );
82  this->widthMax = std::max( this->widthMax , 追加イメージ->GetWidth() );
83  this->heightMax = std::max( this->heightMax, 追加イメージ->GetHeight());
84  }
85  virtual void Add(const char *ファイル名)
86  {
87  Add( new Image( ファイル名 ) );
88  }
89 
91  virtual void Release()
92  {
93  for( auto it : images)
94  {
95  it->Release();
96  }
97 
98  images.clear();
99  }
100 
102  int GetSize() const
103  {
104  return images.size();
105  }
106 
108  int GetWidth() const
109  {
110  return this->widthMax;
111  }
112 
114  int GetHeight() const
115  {
116  return this->heightMax;
117  }
118 
119  Image* operator[](int index)
120  {
121  return images[index];
122  }
123 };
124 }
virtual void Add(Image *追加イメージ)
Imageを追加.
Definition: ImagePack.h:79
virtual void Release()
Imageをメモリから開放.
Definition: ImagePack.h:91
int GetWidth() const
最大幅を取得.
Definition: ImagePack.h:108
画像データを表すクラス.
Definition: Image.h:37
int GetSize() const
要素数を取得.
Definition: ImagePack.h:102
int GetHeight() const
最大高さを取得.
Definition: ImagePack.h:114
ImagePack(const char *ファイル名, int 総コマ数, int コマ割り横, int コマ割り縦)
1つの画像を分割して読み込む.
Definition: ImagePack.h:22
virtual bool Load(const char *ファイル名, int 総コマ数, int コマ割り横, int コマ割り縦)
1つの画像を分割して読み込む.
Definition: ImagePack.h:34