SDXFrameWork  0.04
SDXFrameWork
 全て クラス ネームスペース 関数 変数 ページ
Drawing.h
1 #pragma once
2 #include<Multimedia/SDX.h>
3 #include<Multimedia/Color.h>
4 #include<Multimedia/Image.h>
5 
6 namespace SDX
7 {
9 class Drawing
11 {
12 private:
13  Drawing();
14  ~Drawing();
15 
16 #ifdef SDL
17  //透過状態を計算する
18  void RGBACulculate(int 赤 , int 緑 , int 青) const
19  {
20  SDL_SetRenderDrawBlendMode(Screen::GetHandle(), (SDL_BlendMode)Screen::Single().nowBlendMode);
21  SDL_SetRenderDrawColor
22  (
23  Screen::GetHandle(),
24  Screen::Single().rgba.GetRed() * 赤 / 255,
25  Screen::Single().rgba.GetGreen() * 緑 / 255,
26  Screen::Single().rgba.GetBlue() * 青 / 255,
27  Screen::Single().blendParam
28  );
29  }
30 #endif
31 
32 public:
34  static bool Line(int 始点X, int 始点Y, int 終点X, int 終点Y, Color 色, int 太さ)
35  {
36  #ifdef DXLIB
37  return !DxLib::DrawLine( 始点X , 始点Y , 終点X , 終点Y , 色 , 太さ );
38  #elif defined(SDL)
39  SDL_SetRenderDrawColor(Screen::GetHandle(), 色.GetRed(), 色.GetGreen(), 色.GetBlue(), 0);
40  return !SDL_RenderDrawLine(Screen::GetHandle(), 始点X, 始点Y, 終点X, 終点Y);
41  #endif
42  }
43 
45  static bool Rect(int 座標aX, int 座標aY, int 座標bX, int 座標bY, Color 色, bool 塗りつぶしフラグ)
46  {
47  #ifdef DXLIB
48  return !DxLib::DrawBox( 座標aX , 座標aY , 座標bX , 座標bY , 色 , 塗りつぶしフラグ );
49  #elif defined(SDL)
50  SDL_Rect buf = { 座標aX, 座標aY, 座標bX - 座標aX, 座標bY - 座標aY };
51 
52  SDL_SetRenderDrawColor(Screen::GetHandle(), 色.GetRed(), 色.GetGreen(), 色.GetBlue(), 0);
53 
54  if (塗りつぶしフラグ)
55  {
56  return !SDL_RenderFillRect(Screen::GetHandle(), &buf);
57  }else{
58  return !SDL_RenderDrawRect(Screen::GetHandle(), &buf);
59  }
60  #endif
61  }
62  static bool RectZMask( int x1 , int y1 , int x2 , int y2 , ZMaskType type, bool isFill )
63  {
64  #ifdef DXLIB
65  return !DxLib::DrawBoxToZBuffer( x1 , y1 , x2 , y2 , isFill , (int)type );
66  #elif defined(SDL)
67  return false;
68  #endif
69  }
70 
72  static bool Circle(int 中心X, int 中心Y, int 半径, Color 色, bool 塗りつぶしフラグ)
73  {
74  #ifdef DXLIB
75  return !DxLib::DrawCircle( 中心X , 中心Y , 半径 , 色 , 塗りつぶしフラグ );
76  #elif defined(SDL)
77  //SDL_SetRenderDrawColor(Screen::GetHandle(), 色.GetRed(), 色.GetGreen(), 色.GetBlue(), 0);
78  //filledCircleRGBA(Screen::GetHandle() , 中心X , 中心Y , 半径 , 色.GetRed() , 色.GetGreen() , 色.GetBlue() , 0);
79  return false;
80  #endif
81  }
82  static bool CircleZMask(int 中心X, int 中心Y, int 半径, Color 色, bool 塗りつぶしフラグ)
83  {
84  #ifdef DXLIB
85  return !DxLib::DrawCircleToZBuffer( 中心X , 中心Y , 半径 , 塗りつぶしフラグ , DX_ZWRITE_MASK );
86  #elif defined(SDL)
87  return false;
88  #endif
89  }
90 
92  static bool Oval( int 中心X , int 中心Y , int 幅 , int 高さ , Color 色 , bool 塗りつぶしフラグ )
93  {
94  #ifdef DXLIB
95  return !DxLib::DrawOval( 中心X , 中心Y , 幅 , 高さ , 色 , 塗りつぶしフラグ );
96  #elif defined(SDL)
97  return false;
98  #endif
99  }
100 
102  static bool Triangle(int 頂点aX, int 頂点aY, int 頂点bX, int 頂点bY, int 頂点cX, int 頂点cY, ColorData 色, bool 塗りつぶしフラグ)
103  {
104  #ifdef DXLIB
105  return !DxLib::DrawTriangle( 頂点aX , 頂点aY , 頂点bX , 頂点bY , 頂点cX , 頂点cY , 色 , 塗りつぶしフラグ);
106  #elif defined(SDL)
107  return false;
108  #endif
109  }
110 
112  static bool Pixel(int 座標X, int 座標Y, Color 色)
113  {
114  #ifdef DXLIB
115  return !DxLib::DrawPixel( 座標X , 座標Y , 色 );
116  #elif defined(SDL)
117  SDL_SetRenderDrawColor(Screen::GetHandle(), 色.GetRed(), 色.GetGreen(), 色.GetBlue(), 0);
118  SDL_RenderDrawPoint(Screen::GetHandle() ,座標X, 座標Y);
119  return false;
120  #endif
121  }
122 
124  static ColorData GetPixel( int 座標X , int 座標Y )
125  {
126  #ifdef DXLIB
127  return DxLib::GetPixel( 座標X , 座標Y );
128  #elif defined(SDL)
129  return SDL_Color{ 0, 0, 0 };
130  #endif
131  }
132 
134  static bool ImageFile( int 座標X , int 座標Y , const char *ファイル名 , bool 透過フラグ = true )
136  {
137  #ifdef DXLIB
138  return !DxLib::LoadGraphScreen( 座標X , 座標Y , ファイル名 , 透過フラグ);
139  #elif defined(SDL)
140  Image buf(ファイル名);
141  buf.Draw(座標X , 座標Y , false);
142  buf.Release();
143  return true;
144  #endif
145  }
146 
148  static void String( int X座標 , int Y座標 , Color 色 , const char *文字列 , ... )
150  {
151  char bufstr[1024];
152  va_list args;
153  va_start(args,文字列);
154  vsprintf_s( bufstr , 1024 , 文字列 , args );
155  va_end(args);
156 
157  char *pstr,*stro;
158  stro = strtok_s( bufstr , "\n" , &pstr );
159 
160  while(stro != NULL)
161  {
162  #ifdef DXLIB
163  DxLib::DrawString( X座標 , Y座標 , stro , 色 );
164  #elif defined(SDL)
165 
166  #endif
167  stro = strtok_s( NULL , "\n" , &pstr );
168  Y座標 += 20;
169  }
170  }
171 
172  static void StringZMask( int X座標 , int Y座標 , ZMaskType Zマスク , const char *文字列 , ... )
173  {
174  char bufstr[1024];
175  va_list args;
176  va_start(args,文字列);
177  vsprintf_s( bufstr , 1024 , 文字列 , args );
178  va_end(args);
179 
180  char *pstr,*stro;
181  stro = strtok_s( bufstr , "\n" , &pstr );
182 
183  while(stro != NULL)
184  {
185  #ifdef DXLIB
186  DxLib::DrawStringToZBuffer( X座標 , Y座標 , stro , (int)Zマスク);
187  #elif defined(SDL)
188 
189  #endif
190  stro = strtok_s( NULL , "\n" , &pstr );
191  Y座標 += 20;
192  }
193 
194  }
195 };
196 }
int GetGreen() const
緑の要素を取得.
Definition: Color.h:43
static ColorData GetPixel(int 座標X, int 座標Y)
指定座標の色を取得.
Definition: Drawing.h:124
static bool Circle(int 中心X, int 中心Y, int 半径, Color 色, bool 塗りつぶしフラグ)
中心と半径を指定して円を描画.
Definition: Drawing.h:72
int GetBlue() const
青の要素を取得.
Definition: Color.h:53
画像データを表すクラス.
Definition: Image.h:37
色を表すクラス.
Definition: Color.h:7
static bool Pixel(int 座標X, int 座標Y, Color 色)
指定座標に点を描画.
Definition: Drawing.h:112
int GetRed() const
赤の要素を取得.
Definition: Color.h:33
static void String(int X座標, int Y座標, Color 色, const char *文字列,...)
書式付きで文字を描画.
Definition: Drawing.h:149
static bool Rect(int 座標aX, int 座標aY, int 座標bX, int 座標bY, Color 色, bool 塗りつぶしフラグ)
座標aと座標bを対角の頂点とする矩形を描画.
Definition: Drawing.h:45
static bool ImageFile(int 座標X, int 座標Y, const char *ファイル名, bool 透過フラグ=true)
画像を一時的にメモリに読み込んで描画.
Definition: Drawing.h:135
static bool Oval(int 中心X, int 中心Y, int 幅, int 高さ, Color 色, bool 塗りつぶしフラグ)
中心と外接する四角形の大きさを指定して楕円を描画.
Definition: Drawing.h:92
static bool Line(int 始点X, int 始点Y, int 終点X, int 終点Y, Color 色, int 太さ)
始点と終点を結ぶ直線を描画.
Definition: Drawing.h:34
static bool Triangle(int 頂点aX, int 頂点aY, int 頂点bX, int 頂点bY, int 頂点cX, int 頂点cY, ColorData 色, bool 塗りつぶしフラグ)
頂点を3つ指定して三角形を描画.
Definition: Drawing.h:102