SDXFrameWork  0.09
SDXFrameWork
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Image.h
1 #pragma once//☀SDL
2 #include <Multimedia/SDX.h>
3 #include <Multimedia/Screen.h>
4 #include <Framework/Shape.h>
5 
6 namespace SDX
7 {
9 enum class ZMaskType
10 {
11  Clear,
12  Mask,
13 };
14 
16 enum class RGBA
17 {
18  SrcR,
19  SrcG,
20 
21  SrcB,
22  SrcA,
23  BlendR,
24  BlendG,
25  BlendB,
26  BlendA,
27 };
28 
30 enum class ClipType
31 {
32  Less ,
33  Greater,
34 };
35 
38 class Image
39 {
40  friend class Anime;
41  friend class ImagePack;
42  friend class Font;
43  friend class Drawing;
44 private:
45  bool isScreen = false;
46  bool isAlphaChannel = false;
47  bool isTrans = true;//png等の透過フラグ
48 
49  SDL_Rect part;
50 
51  ImageHandle handle = 0;
52 
53  // 透過状態を計算する
54  void RGBACulculate() const
55  {
56  if (Screen::Single().nowBlendMode == BlendMode::NoBlend)
57  {
58  SDL_SetTextureBlendMode(handle, (SDL_BlendMode)BlendMode::Alpha);
59  SDL_SetTextureAlphaMod(handle, 255);
60  }else{
61  SDL_SetTextureBlendMode(handle, (SDL_BlendMode)Screen::Single().nowBlendMode);
62  SDL_SetTextureAlphaMod(handle, Screen::Single().blendParam);
63  }
64 
65  SDL_SetTextureColorMod
66  (
67  handle,
68  Screen::Single().rgba.GetRed(),
69  Screen::Single().rgba.GetGreen(),
70  Screen::Single().rgba.GetBlue()
71  );
72  }
73 
74 public:
75  Image(){}
76 
77  Image(const char *ファイル名)
78  {
79  Load(ファイル名);
80  }
81 
82  Image(Image& コピー元, int X頂点, int Y頂点, int 幅, int 高さ)
83  {
84  Copy(コピー元, X頂点, Y頂点, 幅, 高さ);
85  }
86 
88  Image(int 幅 ,int 高さ , bool スクリーン用フラグ , bool αチャンネルフラグ = true, bool 透過フラグ = true)
89  {
90  Make(幅, 高さ, スクリーン用フラグ, αチャンネルフラグ, 透過フラグ);
91  }
92 
94  bool Load(const char *ファイル名)
95  {
96  Release();
97  SDL_Surface* temp = IMG_Load(ファイル名);
98 
99  if (temp == nullptr) return false;
100 
101  handle = SDL_CreateTextureFromSurface(Screen::GetHandle(), temp);
102 
103  part.x = 0;
104  part.y = 0;
105  part.w = temp->w;
106  part.h = temp->h;
107 
108  SDL_FreeSurface(temp);
109  return (handle != nullptr);
110  }
111 
113  bool Release()
114  {
115  if (this->handle != nullptr)
116  {
117  SDL_DestroyTexture(handle);
118  return true;
119  }
120  return false;
121  }
122 
124  ImageHandle Make(int 幅, int 高さ, bool スクリーン用フラグ = false, bool αチャンネルフラグ = true, bool 透過フラグ = true)
125  {
126  Release();
127 
128  handle = SDL_CreateTexture(Screen::GetHandle(), SDL_TEXTUREACCESS_TARGET * スクリーン用フラグ, 0, 幅, 高さ);
129  part.x = 0;
130  part.y = 0;
131  part.w = 幅;
132  part.h = 高さ;
133 
134  isTrans = 透過フラグ;
135  isScreen = スクリーン用フラグ;
136  isAlphaChannel = αチャンネルフラグ;
137 
138  return handle;
139  }
140 
142  ImageHandle Copy(const Image& 元イメージ, int X原点, int Y原点, int 幅, int 高さ)
143  {
144  this->handle = 元イメージ.handle;
145  part.x = X原点;
146  part.y = Y原点;
147  part.w = 幅;
148  part.h = 高さ;
149 
150  this->isTrans = 元イメージ.isTrans;
151  this->isScreen = false;
152  this->isAlphaChannel = false;
153 
154  return handle;
155  }
156 
158  ImageHandle GetHandle() const
159  {
160  return handle;
161  }
162 
164  bool Draw(const Point &座標 , bool 反転フラグ = false) const
165  {
166  SDL_Rect temp = { (int)座標.x, (int)座標.y, part.w, part.h };
167  RGBACulculate();
168  if( 反転フラグ )
169  {
170  static SDL_Point point = { 0, 0 };
171  return !SDL_RenderCopyEx(Screen::GetHandle(), handle, &part, &temp , 0 , &point , SDL_RendererFlip::SDL_FLIP_HORIZONTAL );
172  }else{
173  return !SDL_RenderCopy(Screen::GetHandle(), handle, &part, &temp );
174  }
175  }
176 
178  bool DrawExtend(const Point &座標A,const Point &座標B ) const
179  {
180  SDL_Rect temp = { (int)座標A.x, (int)座標A.y, (int)(座標B.x - 座標A.x), (int)(座標B.y - 座標A.y) };
181  RGBACulculate();
182  return !SDL_RenderCopy(Screen::GetHandle(), handle, &part, &temp);
183  }
184 
186  bool DrawRotate(const Point &座標, double 拡大率, double 角度, bool 反転フラグ = false) const
187  {
188  const int wbuf = int(part.w*拡大率);
189  const int hbuf = int(part.h*拡大率);
190  SDL_Rect temp = { (int)座標.x - wbuf / 2, (int)座標.y - hbuf / 2, wbuf, hbuf };
191  SDL_Point point = { wbuf / 2, hbuf / 2 };
192  RGBACulculate();
193  return !SDL_RenderCopyEx(Screen::GetHandle(), handle, &part, &temp, 角度*180 / PAI, &point, SDL_RendererFlip(反転フラグ));
194  }
195 
197  bool DrawRotateAxis(const Point &座標, const Point &回転軸座標, double 拡大率, double 角度, bool 反転フラグ = false) const
198  {
199  const int wbuf = int(part.w*拡大率);
200  const int hbuf = int(part.h*拡大率);
201  SDL_Rect temp = { (int)座標.x - wbuf / 2, (int)座標.y - hbuf / 2, wbuf, hbuf };
202  SDL_Point point = { int(回転軸座標.x*拡大率), int(回転軸座標.y*拡大率) };
203  RGBACulculate();
204  return !SDL_RenderCopyEx(Screen::GetHandle(), handle, &part, &temp, 角度*180 / PAI , &point, SDL_RendererFlip(反転フラグ));
205  }
206 
208  bool DrawRotateAxis(const Point &座標, const Point &回転軸座標 , double 拡大率X, double 拡大率Y, double 角度, bool 反転フラグ = false) const
209  {
210  const int wbuf = int(part.w*拡大率X);
211  const int hbuf = int(part.h*拡大率Y);
212  SDL_Rect temp = { (int)座標.x - wbuf / 2, (int)座標.y - hbuf / 2, wbuf, hbuf };
213  SDL_Point point = { int(回転軸座標.x*拡大率X), int(回転軸座標.y*拡大率Y) };
214  RGBACulculate();
215  return !SDL_RenderCopyEx(Screen::GetHandle(), handle, &part, &temp, 角度*180/PAI, &point, SDL_RendererFlip(反転フラグ));
216  }
217 
219  bool DrawModify(const Point &頂点A,const Point &頂点B, const Point &頂点C, const Point &頂点D ) const
220  {
221  return false;
222  }
223 
225  bool DrawPart(int 描画先X座標, int 描画先Y座標, int 描画元X原点, int 描画元Y原点, int 幅, int 高さ, bool 反転フラグ = false) const
226  {
227  SDL_Rect temp = { 描画先X座標, 描画先Y座標, 幅, 高さ };
228  SDL_Rect part = { 描画元X原点 + this->part.x, 描画元Y原点 + this->part.y, 幅, 高さ };
229  static SDL_Point point = { 0, 0 };
230  RGBACulculate();
231  return !SDL_RenderCopyEx(Screen::GetHandle(), handle, &part, &temp, 0, &point, SDL_RendererFlip(反転フラグ));
232  }
233 
236  int LoadScreen(int X座標,int Y座標)
237  {
238  return false;
239  }
240 
242  int GetWidth() const
243  {
244  return part.w;
245  }
246 
248  int GetHeight() const
249  {
250  return part.h;
251  }
252 
254  bool GetIsScreen() const
255  {
256  return this->isScreen;
257  }
258 
260  bool GetIsAlphaChannel() const
261  {
262  return this->isAlphaChannel;
263  }
264 
266  bool GetIsTrans() const
267  {
268  return this->isTrans;
269  }
270 
274  {
275  return false;
276  }
277 };
278 }
ZMaskType
Zマスクの種類.
Definition: Image.h:9
int GetGreen() const
緑の要素を取得.
Definition: Color.h:31
bool Draw(const Point &座標, bool 反転フラグ=false) const
指定座標に描画.
Definition: Image.h:164
static RendererHandle GetHandle()
スクリーンハンドルを取得.
Definition: Screen.h:77
ClipType
説明.
Definition: Image.h:30
bool DrawExtend(const Point &座標A, const Point &座標B) const
指定矩形内に描画.
Definition: Image.h:178
int GetBlue() const
青の要素を取得.
Definition: Color.h:37
bool GetIsAlphaChannel() const
αチャンネルフラグを取得.
Definition: Image.h:260
static Screen & Single()
シングルトンなインスタンスを取得.
Definition: Screen.h:70
リソースを読み込まずに描画を行う関数群.
Definition: Drawing.h:13
ImageHandle Make(int 幅, int 高さ, bool スクリーン用フラグ=false, bool αチャンネルフラグ=true, bool 透過フラグ=true)
空のイメージを作成.
Definition: Image.h:124
ImageHandle GetHandle() const
ハンドルを取得.
Definition: Image.h:158
点を表す図形クラス.
Definition: Shape.h:129
フォントデータを表すクラス.
Definition: Font.h:23
bool SetDrawScreen()
描画先にこのイメージに指定[未実装].
Definition: Image.h:273
画像データを表すクラス.
Definition: Image.h:38
int GetHeight() const
高さを取得.
Definition: Image.h:248
int GetWidth() const
幅を取得.
Definition: Image.h:242
bool DrawModify(const Point &頂点A, const Point &頂点B, const Point &頂点C, const Point &頂点D) const
四角形に変形描画[未実装].
Definition: Image.h:219
bool Release()
イメージをメモリから開放.
Definition: Image.h:113
bool DrawPart(int 描画先X座標, int 描画先Y座標, int 描画元X原点, int 描画元Y原点, int 幅, int 高さ, bool 反転フラグ=false) const
一部を指定して描画.
Definition: Image.h:225
int LoadScreen(int X座標, int Y座標)
スクリーンの一部をイメージに取り込む[未実装].
Definition: Image.h:236
ImageHandle Copy(const Image &元イメージ, int X原点, int Y原点, int 幅, int 高さ)
元イメージの一部をコピーして、別イメージを作成.
Definition: Image.h:142
bool DrawRotateAxis(const Point &座標, const Point &回転軸座標, double 拡大率X, double 拡大率Y, double 角度, bool 反転フラグ=false) const
回転軸、角度、拡大率を縦横別に指定して描画.
Definition: Image.h:208
RGBA
説明.
Definition: Image.h:16
Imageをまとめてコマ送りアニメとして表すクラス.
Definition: Anime.h:28
bool GetIsScreen() const
説明.
Definition: Image.h:254
複数のImageをまとめるクラス.
Definition: ImagePack.h:9
マスクする
Image(int 幅, int 高さ, bool スクリーン用フラグ, bool αチャンネルフラグ=true, bool 透過フラグ=true)
空のイメージを作成.
Definition: Image.h:88
マスクを切り取る
bool DrawRotate(const Point &座標, double 拡大率, double 角度, bool 反転フラグ=false) const
角度、拡大率を指定して描画.
Definition: Image.h:186
bool DrawRotateAxis(const Point &座標, const Point &回転軸座標, double 拡大率, double 角度, bool 反転フラグ=false) const
回転軸、角度、拡大率を指定して描画.
Definition: Image.h:197
bool Load(const char *ファイル名)
画像をメモリへ読み込む.
Definition: Image.h:94
bool GetIsTrans() const
透過フラグを取得.
Definition: Image.h:266