SDXFrameWork  0.04
SDXFrameWork
 全て クラス ネームスペース 関数 変数 ページ
Screen.h
1 #pragma once
2 #include<Multimedia/SDX.h>
3 #include<Multimedia/Color.h>
4 
5 namespace SDX
6 {
8 enum class DrawMode
9 {
10  Nearest,
11  Bilinear
12 };
13 
15 enum class BlendMode
16 {
17 #ifdef DXLIB
18  NoBlend,
19  Alpha,
20  Add,
21  Sub,
22  Mula,
23  Invsrc
24 #elif defined(SDL)
25  NoBlend = SDL_BLENDMODE_NONE,
26  Alpha = SDL_BLENDMODE_BLEND,
27  Add = SDL_BLENDMODE_ADD,
28  Sub,
29  Mula = SDL_BLENDMODE_MOD,
30  Invsrc
31 #endif
32 
33 };
34 
35 class Image;
37 class Screen
39 {
40 private:
41  Screen(){};
42  ~Screen(){};
43  ScreenHandle handle = 0;
44 public:
45 
46  BlendMode nowBlendMode = BlendMode::NoBlend;
47  int blendParam = 0;
48  Color clearColor = Color(0, 0, 0);//消去時の色
49  Color rgba = Color(255, 255, 255, 0);//描画輝度と透明度
50 
51  static Screen& Single()
52  {
53  static Screen single;
54  return single;
55  }
56  static ScreenHandle GetHandle()
57  {
58  return Single().handle;
59  }
60 
61  static void SetRenderer(ScreenHandle handle)
62  {
63  Single().handle = handle;
64  }
65 
67  static bool SetArea(int x1,int y1,int x2,int y2)
68  {
69  #ifdef DXLIB
70  return !DxLib::SetDrawArea(x1, y1, x2, y2);
71  #elif defined(SDL)
72  return false;
73  #endif
74  }
75 
77  static bool SetCreateGraphColorBitDepth(int ビット深度)
81  {
82  #ifdef DXLIB
83  return !DxLib::SetCreateGraphColorBitDepth(ビット深度);
84  #elif defined(SDL)
85  return false;
86  #endif
87  }
88 
90  static bool SetCreateValidGraphChannelNum(int チャンネル数)
94  {
95  #ifdef DXLIB
96  return !DxLib::SetCreateDrawValidGraphChannelNum(チャンネル数);
97  #elif defined(SDL)
98  return false;
99  #endif
100  }
101 
103  static bool SetBack()
106  {
107  #ifdef DXLIB
108  return !DxLib::SetDrawScreen(DX_SCREEN_BACK);
109  #elif defined(SDL)
110  return false;
111  #endif
112  }
113 
115  static bool SetBackColor( Color 背景色 )
116  {
117  Single().clearColor.SetColor(背景色.GetRed(), 背景色.GetGreen(), 背景色.GetBlue());
118  #ifdef DXLIB
119  return !DxLib::SetBackgroundColor(背景色.GetRed(), 背景色.GetGreen(), 背景色.GetBlue() );
120  #elif defined(SDL)
121  return true;
122  #endif
123  }
124 
126  static bool Flip()
127  {
128  #ifdef DXLIB
129  return !DxLib::ScreenFlip();
130  #elif defined(SDL)
131  static double nextFrame = SDL_GetTicks();
132  const static double wait = 1000.0 / 60;
133 
134  while (true)
135  {
136  if (SDL_GetTicks() >= nextFrame)
137  {
138  nextFrame = SDL_GetTicks() + wait;
139  SDL_Delay(0);
140  break;
141  }
142  }
143  SDL_RenderPresent(GetHandle());
144  return true;
145  #endif
146  }
147 
149  static bool Copy()
150  {
151  #ifdef DXLIB
152  return !DxLib::ScreenCopy();
153  #elif defined(SDL)
154  SDL_RenderPresent(GetHandle());
155  return true;
156  #endif
157  }
158 
160  static bool Clear()
161  {
162  #ifdef DXLIB
163  return !DxLib::ClearDrawScreen();
164  #elif defined(SDL)
165  SDL_SetRenderDrawColor
166  (
167  Screen::GetHandle(),
168  Single().clearColor.GetRed(),
169  Single().clearColor.GetGreen(),
170  Single().clearColor.GetBlue(),
171  0
172  );
173  SDL_RenderClear(GetHandle());
174  return true;
175  #endif
176  }
177 
179  static bool SetMode(DrawMode 補完モード)
180  {
181  #ifdef DXLIB
182  return !DxLib::SetDrawMode((int)補完モード);
183  #elif defined(SDL)
184  return false;
185  #endif
186  }
187 
189  static bool SetBlendMode(BlendMode ブレンドモード,int 設定値)
190  {
191  Single().nowBlendMode = ブレンドモード;
192  Single().blendParam = 設定値;
193  #ifdef DXLIB
194  return !DxLib::SetDrawBlendMode((int)ブレンドモード, 設定値);
195  #elif defined(SDL)
196  return true;
197  #endif
198  }
199 
201  static bool SaveBmp(int x1, int y1 , int x2 , int y2 , const char *ファイル名 )
202  {
203  #ifdef DXLIB
204  return !DxLib::SaveDrawScreen(x1, y1, x2, y2, ファイル名);
205  #elif defined(SDL)
206  return false;
207  #endif
208  }
209 
211  static bool SetBright( Color 輝度 )
212  {
213  #ifdef DXLIB
214  return !DxLib::SetDrawBright(輝度.GetRed(), 輝度.GetGreen(), 輝度.GetBlue());
215  #elif defined(SDL)
216  Single().rgba.SetColor(輝度.GetRed(), 輝度.GetGreen(), 輝度.GetBlue());
217  return true;
218  #endif
219  }
220 
222  static bool SetTransColor(Color 輝度)
223  {
224  #ifdef DXLIB
225  return !DxLib::SetTransColor(輝度.GetRed(), 輝度.GetGreen(), 輝度.GetBlue());
226  #elif defined(SDL)
227  return false;
228  #endif
229  }
230 
232  static void SetZUse(bool 使用フラグ )
233  {
234  #ifdef DXLIB
235  DxLib::SetUseZBufferFlag(使用フラグ);
236  #elif defined(SDL)
237  return;
238  #endif
239  }
240 
242  static void SetZWrite(bool 使用フラグ )
243  {
244  #ifdef DXLIB
245  DxLib::SetWriteZBufferFlag(使用フラグ);
246  #elif defined(SDL)
247  return;
248  #endif
249  }
250 
252  static void SetZDepth(double Z深度)
253  {
254  #ifdef DXLIB
255  DxLib::SetDrawZ((float)Z深度);
256  #elif defined(SDL)
257  return;
258  #endif
259  }
260 };
261 }
static bool SetBlendMode(BlendMode ブレンドモード, int 設定値)
ブレンド描画のモードを設定.
Definition: Screen.h:189
int GetGreen() const
緑の要素を取得.
Definition: Color.h:43
static bool Flip()
描画内容を反映.
Definition: Screen.h:126
int GetBlue() const
青の要素を取得.
Definition: Color.h:53
static bool SetBright(Color 輝度)
描画輝度を設定.
Definition: Screen.h:211
static bool SetCreateGraphColorBitDepth(int ビット深度)
作成する画像のビット深度を設定.
Definition: Screen.h:80
static void SetZUse(bool 使用フラグ)
Zバッファ使用フラグを設定.
Definition: Screen.h:232
static bool Clear()
画面を消去する.
Definition: Screen.h:160
static void SetZDepth(double Z深度)
Z描画深度0.0~1.0の範囲で設定.
Definition: Screen.h:252
static bool SetCreateValidGraphChannelNum(int チャンネル数)
スクリーン用Imageのチャンネル数を設定.
Definition: Screen.h:93
色を表すクラス.
Definition: Color.h:7
static bool SetBack()
描画先の設定.
Definition: Screen.h:105
static bool SetTransColor(Color 輝度)
透過色を設定.
Definition: Screen.h:222
static void SetZWrite(bool 使用フラグ)
Zバッファ描画フラグを設定.
Definition: Screen.h:242
int GetRed() const
赤の要素を取得.
Definition: Color.h:33
static bool SaveBmp(int x1, int y1, int x2, int y2, const char *ファイル名)
描画対象になっている画面の一部をBMP形式で保存.
Definition: Screen.h:201
static bool SetBackColor(Color 背景色)
Screen::Clear後の色を設定.
Definition: Screen.h:115
static bool SetArea(int x1, int y1, int x2, int y2)
描画範囲を設定する、設定範囲外には描画されない.
Definition: Screen.h:67
static bool SetMode(DrawMode 補完モード)
拡大描画の補完方法を設定.
Definition: Screen.h:179
static bool Copy()
裏画面の内容を、表画面にコピー.
Definition: Screen.h:149