SDXFrameWork  0.04
SDXFrameWork
 全て クラス ネームスペース 関数 変数 ページ
Image.h
1 #pragma once
2 #include<Multimedia/SDX.h>
3 #include<Multimedia/Screen.h>
4 
5 namespace SDX
6 {
8 enum class ZMaskType
9 {
10  Clear,
11  Mask
12 };
13 
15 enum class RGBA
16 {
17  SrcR,
18  SrcG,
19 
20  SrcB,
21  SrcA,
22  BlendR,
23  BlendG,
24  BlendB,
25  BlendA
26 };
27 
29 enum class ClipType
30 {
31  Less ,
32  Greater
33 };
34 
36 class Image
38 {
39  friend class Anime;
40  friend class ImagePack;
41 
42 private:
43  bool isScreen = false;
44  bool isAlphaChannel = false;
45  bool isTrans = true;//png等の透過フラグ
46 
47 #ifdef DXLIB
48  int width = 0;
49  int height = 0;
50 #elif defined(SDL)
51  SDL_Rect part;
52 #endif
53  ImageHandle handle = 0;
54 
55 #ifdef SDL
56  // 透過状態を計算する
57  void RGBACulculate() const
58  {
59  if (Screen::Single().nowBlendMode == BlendMode::NoBlend)
60  {
61  SDL_SetTextureBlendMode(handle, (SDL_BlendMode)BlendMode::Alpha);
62  SDL_SetTextureAlphaMod(handle, 255);
63  }else{
64  SDL_SetTextureBlendMode(handle, (SDL_BlendMode)Screen::Single().nowBlendMode);
65  SDL_SetTextureAlphaMod(handle, Screen::Single().blendParam);
66  }
67 
68  SDL_SetTextureColorMod
69  (
70  handle,
71  Screen::Single().rgba.GetRed(),
72  Screen::Single().rgba.GetGreen(),
73  Screen::Single().rgba.GetBlue()
74  );
75  }
76 #endif
77 
78 public:
79  Image(){}
80 
81  Image(const char *ファイル名)
82  {
83  Load(ファイル名);
84  }
85 
86  Image(Image& コピー元, int X頂点, int Y頂点, int 幅, int 高さ)
87  {
88  Copy(コピー元, X頂点, Y頂点, 幅, 高さ);
89  }
90 
92  Image(int 幅 ,int 高さ , bool スクリーン用フラグ , bool αチャンネルフラグ = true, bool 透過フラグ = true)
93  {
94  Make(幅, 高さ, スクリーン用フラグ, αチャンネルフラグ, 透過フラグ);
95  }
96 
98  bool Load(const char *ファイル名)
99  {
100  #ifdef DXLIB
101  if (this->handle != NULL_HANDLE) DxLib::DeleteGraph(this->handle);
102  this->handle = DxLib::LoadGraph(ファイル名);
103  this->isTrans = true;
104  this->isScreen = false;
105 
106  DxLib::GetGraphSize( this->GetHandle() , &width , &height );
107  return ( this->handle != -1 );
108  #elif defined(SDL)
109  Release();
110  SDL_Surface* temp = IMG_Load(ファイル名);
111  if (temp == nullptr) return false;
112 
113  handle = SDL_CreateTextureFromSurface(Screen::GetHandle(), temp);
114 
115  part.x = 0;
116  part.y = 0;
117  part.w = temp->w;
118  part.h = temp->h;
119 
120  SDL_FreeSurface(temp);
121  return true;
122  #endif
123  }
124 
126  bool Release()
127  {
128  #ifdef DXLIB
129  return !DxLib::DeleteGraph(this->handle);
130  #elif defined(SDL)
131  if (this->handle != nullptr)
132  {
133  SDL_DestroyTexture(handle);
134  return true;
135  }
136  return false;
137  #endif
138  }
139  //bool 透過フラグ, bool スクリーン用フラグ, bool αチャンネルフラグ )
140 
142  ImageHandle Make(int 幅, int 高さ, bool スクリーン用フラグ = false, bool αチャンネルフラグ = true, bool 透過フラグ = true)
143  {
144  Release();
145  #ifdef DXLIB
146  if (スクリーン用フラグ)
147  {
148  handle = DxLib::MakeScreen(幅, 高さ, αチャンネルフラグ);
149  }else{
150  handle = DxLib::MakeGraph(幅, 高さ);
151  }
152  DxLib::GetGraphSize( GetHandle() , &width , &height );
153  #elif defined(SDL)
154  SDL_CreateTexture(Screen::GetHandle(), 0, 0, 幅, 高さ);
155  part.x = 0;
156  part.y = 0;
157  part.w = 幅;
158  part.h = 高さ;
159  #endif
160  isTrans = 透過フラグ;
161  isScreen = スクリーン用フラグ;
162  isAlphaChannel = αチャンネルフラグ;
163 
164  return handle;
165  }
166 
168  ImageHandle Copy(const Image& 元イメージ, int X原点, int Y原点, int 幅, int 高さ)
169  {
170  #ifdef DXLIB
171  this->handle = DxLib::DerivationGraph( X原点, Y原点, 幅, 高さ, 元イメージ.handle);
172  this->width = 幅;
173  this->height = 高さ;
174  #elif defined(SDL)
175  this->handle = 元イメージ.handle;
176  part.x = X原点;
177  part.y = Y原点;
178  part.w = 幅;
179  part.h = 高さ;
180  #endif
181  this->isTrans = 元イメージ.isTrans;
182  this->isScreen = false;
183  this->isAlphaChannel = false;
184 
185  return handle;
186  }
187 
189  ImageHandle GetHandle() const
190  {
191  return handle;
192  }
193 
195  bool Draw(int X座標,int Y座標 , bool 反転フラグ = false) const
196  {
197  #ifdef DXLIB
198  if( 反転フラグ )
199  {
200  return !DxLib::DrawTurnGraph( X座標 , Y座標 , this->GetHandle() , this->isTrans );
201  }else{
202  return !DxLib::DrawGraph( X座標 , Y座標 , this->GetHandle() , this->isTrans );
203  }
204  #elif defined(SDL)
205  SDL_Rect temp = { X座標, Y座標, part.w, part.h };
206  RGBACulculate();
207  if( 反転フラグ )
208  {
209  static SDL_Point point = { 0, 0 };
210  return !SDL_RenderCopyEx(Screen::GetHandle(), handle, &part, &temp , 0 , &point , SDL_RendererFlip::SDL_FLIP_HORIZONTAL );
211  }else{
212  return !SDL_RenderCopy(Screen::GetHandle(), handle, &part, &temp );
213  }
214  #endif
215 
216  }
217  bool ZMask(int X座標,int Y座標 , ZMaskType Zマスクタイプ , bool 反転フラグ = false) const
218  {
219  #ifdef DXLIB
220  if (反転フラグ)
221  {
222  return !DxLib::DrawTurnGraphToZBuffer( X座標 , Y座標 , this->GetHandle() , (int)Zマスクタイプ );
223  }
224  else{
225  return !DxLib::DrawGraphToZBuffer(X座標, Y座標, this->GetHandle(), (int)Zマスクタイプ);
226  }
227  #elif defined(SDL)
228  return false;
229  #endif
230  }
231 
233  bool DrawExtend(int X座標A,int Y座標A,int X座標B,int Y座標B ) const
234  {
235  #ifdef DXLIB
236  return !DxLib::DrawExtendGraph(X座標A, Y座標A, X座標B, Y座標B, this->GetHandle(), this->isTrans);
237  #elif defined(SDL)
238  SDL_Rect temp = { X座標A, Y座標A, X座標B - X座標A, Y座標B - Y座標A };
239  RGBACulculate();
240  return !SDL_RenderCopy(Screen::GetHandle(), handle, &part, &temp);
241  #endif
242  }
243  bool ZMaskExtend(int X座標A,int Y座標A,int X座標B,int Y座標B , ZMaskType Zマスクタイプ) const
244  {
245  #ifdef DXLIB
246  return !DxLib::DrawExtendGraphToZBuffer(X座標A, Y座標A, X座標B, Y座標B, this->GetHandle(), (int)Zマスクタイプ);
247  #elif defined(SDL)
248  return false;
249  #endif
250  }
251 
253  bool DrawRotate(int X座標, int Y座標, double 拡大率, double 角度, bool 反転フラグ = false) const
254  {
255  #ifdef DXLIB
256  return !DxLib::DrawRotaGraph(X座標, Y座標, 拡大率, 角度, this->GetHandle(), this->isTrans, 反転フラグ);
257  #elif defined(SDL)
258  const int wbuf = int(part.w*拡大率);
259  const int hbuf = int(part.h*拡大率);
260  SDL_Rect temp = { X座標 - wbuf/2, Y座標 - hbuf/2, wbuf , hbuf };
261  SDL_Point point = { wbuf / 2, hbuf / 2 };
262  RGBACulculate();
263  return !SDL_RenderCopyEx(Screen::GetHandle(), handle, &part, &temp, 角度*180 / PAI, &point, SDL_RendererFlip(反転フラグ));
264  #endif
265  }
266  bool DrawRotateZMask(int X座標, int Y座標, double 拡大率, double 角度, ZMaskType Zマスクタイプ, bool 反転フラグ = false) const
267  {
268  #ifdef DXLIB
269  return !DxLib::DrawRotaGraphToZBuffer(X座標, Y座標, 拡大率, 角度, this->GetHandle(), (int)Zマスクタイプ, 反転フラグ);
270  #elif defined(SDL)
271  return false;
272  #endif
273  }
274 
276  bool DrawRotateAxis(int X座標, int Y座標, int X軸, int Y軸, double 拡大率, double 角度, bool 反転フラグ = false) const
277  {
278  #ifdef DXLIB
279  return !DxLib::DrawRotaGraph2(X座標, Y座標, X軸, Y軸, 拡大率, 角度, this->GetHandle(), this->isTrans, 反転フラグ);
280  #elif defined(SDL)
281  const int wbuf = int(part.w*拡大率);
282  const int hbuf = int(part.h*拡大率);
283  SDL_Rect temp = { X座標 - wbuf / 2, Y座標 - hbuf / 2, wbuf, hbuf };
284  SDL_Point point = { wbuf / 2, hbuf / 2 };
285  RGBACulculate();
286  return !SDL_RenderCopyEx(Screen::GetHandle(), handle, &part, &temp, 角度, &point, SDL_RendererFlip(反転フラグ));
287  #endif
288  }
289  bool ZMaskRotateAxis(int X座標, int Y座標, int X軸, int Y軸, double 拡大率, double 角度, ZMaskType Zマスクタイプ, bool 反転フラグ = false) const
290  {
291  #ifdef DXLIB
292  return !DxLib::DrawRotaGraph2ToZBuffer(X座標, Y座標, X軸, Y軸, 拡大率, 角度, this->GetHandle(), (int)Zマスクタイプ, 反転フラグ);
293  #elif defined(SDL)
294  return false;
295  #endif
296  }
297 
299  bool DrawRotateAxis(int X座標, int Y座標, int X軸, int Y軸, double 拡大率X, double 拡大率Y, double 角度, bool 反転フラグ = false) const
300  {
301  #ifdef DXLIB
302  return !DxLib::DrawRotaGraph3(X座標, Y座標, X軸, Y軸, 拡大率X, 拡大率Y, 角度, this->GetHandle(), this->isTrans, 反転フラグ);
303  #elif defined(SDL)
304  const int wbuf = int(part.w*拡大率X);
305  const int hbuf = int(part.h*拡大率Y);
306  SDL_Rect temp = { X座標 - wbuf / 2, Y座標 - hbuf / 2, wbuf, hbuf };
307  SDL_Point point = { wbuf / 2, hbuf / 2 };
308  RGBACulculate();
309  return !SDL_RenderCopyEx(Screen::GetHandle(), handle, &part, &temp, 角度, &point, SDL_RendererFlip(反転フラグ));
310  #endif
311  }
312  bool ZMaskRotateAxis(int X座標, int Y座標, int X軸, int Y軸, double 拡大率X, double 拡大率Y, double 角度, ZMaskType Zマスクタイプ, bool 反転フラグ = false) const
313  {
314  #ifdef DXLIB
315  return !DxLib::DrawRotaGraph3ToZBuffer(X座標, Y座標, X軸, Y軸, 拡大率X, 拡大率Y, 角度, this->GetHandle(), (int)Zマスクタイプ, 反転フラグ);
316  #elif defined(SDL)
317  return false;
318  #endif
319  }
320 
322  bool DrawModify(int 頂点aX, int 頂点aY, int 頂点bX, int 頂点bY, int 頂点cX, int 頂点cY, int 頂点dX, int 頂点dY) const
323  {
324  #ifdef DXLIB
325  return !DxLib::DrawModiGraph(頂点aX, 頂点aY, 頂点bX, 頂点bY, 頂点cX, 頂点cY, 頂点dX, 頂点dY, this->GetHandle(), this->isTrans);
326  #elif defined(SDL)
327  return false;
328  #endif
329  }
330  bool ZMaskModify(int 頂点aX, int 頂点aY, int 頂点bX, int 頂点bY, int 頂点cX, int 頂点cY, int 頂点dX, int 頂点dY, ZMaskType Zマスクタイプ) const
331  {
332  #ifdef DXLIB
333  return !DxLib::DrawModiGraphToZBuffer(頂点aX, 頂点aY, 頂点bX, 頂点bY, 頂点cX, 頂点cY, 頂点dX, 頂点dY, this->GetHandle(), (int)Zマスクタイプ);
334  #elif defined(SDL)
335  return false;
336  #endif
337  }
338 
340  bool DrawPart(int 描画先X座標, int 描画先Y座標, int 描画元X原点, int 描画元Y原点, int 幅, int 高さ, bool 反転フラグ = false) const
341  {
342  #ifdef DXLIB
343  return !DxLib::DrawRectGraph(描画先X座標, 描画先Y座標, 描画元X原点, 描画元Y原点, 幅, 高さ, this->GetHandle(), this->isTrans, 反転フラグ);
344  #elif defined(SDL)
345  SDL_Rect temp = { 描画先X座標, 描画先Y座標, 幅, 高さ };
346  SDL_Rect part = { 描画元X原点 + part.w, 描画元Y原点 + part.h, 幅, 高さ };
347  static SDL_Point point = { 0, 0 };
348  RGBACulculate();
349  return !SDL_RenderCopyEx(Screen::GetHandle(), handle, &part, &temp, 0, &point, SDL_RendererFlip(反転フラグ));
350  #endif
351  }
352  bool ZMaskPart(int destX,int destY,int srcX, int srcY, int 幅, int 高さ , ZMaskType Zマスクタイプ , bool 反転フラグ = false) const
353  {
354  #ifdef DXLIB
355  return !DxLib::DrawRectGraph(destX, destY, srcX, srcY, 幅, 高さ, this->GetHandle(), (int)Zマスクタイプ, 反転フラグ);
356  #elif defined(SDL)
357  return false;
358  #endif
359  }
360 
362  int LoadScreen(int x,int y)
364  {
365  #ifdef DXLIB
366  int w, h;
367  DxLib::GetGraphSize( this->GetHandle() , &w , &h );
368  return DxLib::GetDrawScreenGraph( x , y , x + w , y + h , this->GetHandle() );
369  #elif defined(SDL)
370  return false;
371  #endif
372  }
373 
375  int GetWidth() const
376  {
377  #ifdef DXLIB
378  return width;
379  #elif defined(SDL)
380  return part.w;
381  #endif
382  }
383 
385  int GetHeight() const
386  {
387  #ifdef DXLIB
388  return height;
389  #elif defined(SDL)
390  return part.h;
391  #endif
392  }
393 
395  bool GetIsScreen() const
396  {
397  return this->isScreen;
398  }
399 
401  bool GetIsAlphaChannel() const
402  {
403  return this->isAlphaChannel;
404  }
405 
407  bool GetIsTrans() const
408  {
409  return this->isTrans;
410  }
411 
413  bool SetDrawScreen()
415  {
416  #ifdef DXLIB
417 
418  #elif defined(SDL)
419  return false;
420  #endif
421  }
422 };
423 }
bool GetIsAlphaChannel() const
αチャンネルフラグを取得.
Definition: Image.h:401
ImageHandle Make(int 幅, int 高さ, bool スクリーン用フラグ=false, bool αチャンネルフラグ=true, bool 透過フラグ=true)
空のイメージを作成.
Definition: Image.h:142
bool Draw(int X座標, int Y座標, bool 反転フラグ=false) const
指定座標に描画.
Definition: Image.h:195
ImageHandle GetHandle() const
ハンドルを取得.
Definition: Image.h:189
bool SetDrawScreen()
描画先にこのイメージに指定.
Definition: Image.h:414
画像データを表すクラス.
Definition: Image.h:37
int GetHeight() const
高さを取得.
Definition: Image.h:385
int GetWidth() const
幅を取得.
Definition: Image.h:375
bool Release()
イメージをメモリから開放.
Definition: Image.h:126
bool DrawPart(int 描画先X座標, int 描画先Y座標, int 描画元X原点, int 描画元Y原点, int 幅, int 高さ, bool 反転フラグ=false) const
一部を指定して描画.
Definition: Image.h:340
bool DrawRotateAxis(int X座標, int Y座標, int X軸, int Y軸, double 拡大率X, double 拡大率Y, double 角度, bool 反転フラグ=false) const
回転軸、角度、拡大率を縦横別に指定して描画.
Definition: Image.h:299
ImageHandle Copy(const Image &元イメージ, int X原点, int Y原点, int 幅, int 高さ)
元イメージの一部をコピーして、別イメージを作成.
Definition: Image.h:168
bool GetIsScreen() const
説明.
Definition: Image.h:395
Image(int 幅, int 高さ, bool スクリーン用フラグ, bool αチャンネルフラグ=true, bool 透過フラグ=true)
空のイメージを作成.
Definition: Image.h:92
bool DrawRotateAxis(int X座標, int Y座標, int X軸, int Y軸, double 拡大率, double 角度, bool 反転フラグ=false) const
回転軸、角度、拡大率を指定して描画.
Definition: Image.h:276
bool DrawExtend(int X座標A, int Y座標A, int X座標B, int Y座標B) const
指定矩形内に描画.
Definition: Image.h:233
bool Load(const char *ファイル名)
画像をメモリへ読み込む.
Definition: Image.h:98
int LoadScreen(int x, int y)
スクリーンの一部をイメージに取り込む.
Definition: Image.h:363
bool DrawModify(int 頂点aX, int 頂点aY, int 頂点bX, int 頂点bY, int 頂点cX, int 頂点cY, int 頂点dX, int 頂点dY) const
四角形に変形描画.
Definition: Image.h:322
bool GetIsTrans() const
透過フラグを取得.
Definition: Image.h:407
bool DrawRotate(int X座標, int Y座標, double 拡大率, double 角度, bool 反転フラグ=false) const
角度、拡大率を指定して描画.
Definition: Image.h:253