SDXFrameWork  0.07
SDXFrameWork
 全て クラス ネームスペース 関数 変数 列挙型 列挙型の値 ページ
Drawing.h
1 #pragma once//☀SDL
2 #include<Multimedia/SDX.h>
3 #include<Multimedia/Color.h>
4 #include<Multimedia/Image.h>
5 #include<Multimedia/Font.h>
6 #include<Utility/VariadicStream.h>
7 
8 namespace SDX
9 {
12 class Drawing
13 {
14 private:
15  Drawing();
16  ~Drawing();
17 
18  static Font defaultFont;
19 
21  static void RGBACulculate(int 赤 , int 緑 , int 青)
22  {
23  SDL_SetRenderDrawBlendMode(Screen::GetHandle(), (SDL_BlendMode)Screen::Single().nowBlendMode);
24  SDL_SetRenderDrawColor
25  (
27  Screen::Single().rgba.GetRed() * 赤 / 255,
28  Screen::Single().rgba.GetGreen() * 緑 / 255,
29  Screen::Single().rgba.GetBlue() * 青 / 255,
30  Screen::Single().blendParam
31  );
32  }
34  static Image& circleTexture( bool 塗りつぶしフラグ)
35  {
36  static Image circleA;
37  static Image circleB;
38 
39  if (circleA.handle == nullptr)
40  {
41  Font font;
42  font.Load(SystemFont::Gothic, 1000);
43 
44  SDL_Surface* surfaceA = TTF_RenderUTF8_Blended( font.GetHandle(), "●", {255,255,255,255});
45  circleA.handle = SDL_CreateTextureFromSurface(Screen::GetHandle(), surfaceA);
46  circleA.part.w = surfaceA->w;
47  circleA.part.h = surfaceA->h;
48  SDL_FreeSurface(surfaceA);
49 
50  SDL_Surface* surfaceB = TTF_RenderUTF8_Blended(font.GetHandle(), "○", { 255, 255, 255, 255 });
51  circleB.handle = SDL_CreateTextureFromSurface(Screen::GetHandle(), surfaceB);
52  circleB.part.w = surfaceB->w;
53  circleB.part.h = surfaceB->h;
54  SDL_FreeSurface(surfaceB);
55 
56  font.Release();
57  }
58 
59  if (塗りつぶしフラグ)
60  {
61  return circleA;
62  }
63  else
64  {
65  return circleB;
66  }
67  }
68 
69 public:
70 
72  static Font& GetFont()
73  {
74  return defaultFont;
75  }
76 
78  static void SetDefaultFont( const char* フォント名 , int 大きさ)
79  {
80  GetFont().Load(フォント名, 大きさ);
81  }
82 
85  static bool Line(int 始点X, int 始点Y, int 終点X, int 終点Y, Color 色, int 太さ)
86  {
87  RGBACulculate(色.GetRed() , 色.GetGreen() , 色.GetBlue() );
88  return !SDL_RenderDrawLine(Screen::GetHandle(), 始点X, 始点Y, 終点X, 終点Y);
89  }
90 
92  static bool Rect(int 座標X, int 座標Y, int 幅, int 高さ, Color 色, bool 塗りつぶしフラグ)
93  {
94  SDL_Rect buf = { 座標X, 座標Y, 幅, 高さ };
95  RGBACulculate(色.GetRed() , 色.GetGreen() , 色.GetBlue() );
96  if (塗りつぶしフラグ)
97  {
98  return !SDL_RenderFillRect(Screen::GetHandle(), &buf);
99  }else{
100  return !SDL_RenderDrawRect(Screen::GetHandle(), &buf);
101  }
102  }
104  static bool RectZMask(int 座標X, int 座標Y, int 幅, int 高さ, ZMaskType マスクタイプ, bool 塗りつぶしフラグ)
105  {
106  return false;
107  }
108 
111  static bool Circle(int 中心X, int 中心Y, int 半径, Color 色, bool 塗りつぶしフラグ)
112  {
113  SDL_SetRenderDrawColor(Screen::GetHandle(), 色.GetRed(), 色.GetGreen(), 色.GetBlue(), 0);
114  circleTexture(塗りつぶしフラグ).DrawExtend(中心X - 半径, 中心Y - 半径, 中心X + 半径, 中心Y + 半径);
115  return true;
116  }
117 
119  static bool CircleZMask(int 中心X, int 中心Y, int 半径, Color 色, bool 塗りつぶしフラグ)
120  {
121  return false;
122  }
123 
126  static bool Oval( int 中心X , int 中心Y , int 幅 , int 高さ , Color 色 , bool 塗りつぶしフラグ )
127  {
128  SDL_SetRenderDrawColor(Screen::GetHandle(), 色.GetRed(), 色.GetGreen(), 色.GetBlue(), 0);
129  circleTexture(塗りつぶしフラグ).DrawExtend(中心X - 幅/2, 中心Y - 高さ/2, 中心X + 幅/2, 中心Y + 高さ/2);
130  return true;
131  }
132 
135  static bool Triangle(int 頂点aX, int 頂点aY, int 頂点bX, int 頂点bY, int 頂点cX, int 頂点cY, Color 色, bool 塗りつぶしフラグ)
136  {
137  RGBACulculate(色.GetRed(), 色.GetGreen(), 色.GetBlue());
138  SDL_RenderDrawLine(Screen::GetHandle(), 頂点aX , 頂点aY, 頂点bX, 頂点bY);
139  SDL_RenderDrawLine(Screen::GetHandle(), 頂点bX, 頂点bY, 頂点cX, 頂点cY);
140  SDL_RenderDrawLine(Screen::GetHandle(), 頂点cX, 頂点cY, 頂点aX, 頂点aY);
141  return true;
142  }
143 
145  static bool Pixel(int 座標X, int 座標Y, Color 色)
146  {
147  RGBACulculate(色.GetRed() , 色.GetGreen() , 色.GetBlue() );
148  SDL_RenderDrawPoint(Screen::GetHandle() ,座標X, 座標Y);
149  return false;
150  }
151 
153  static ColorData GetPixel( int 座標X , int 座標Y )
154  {
155  return SDL_Color{ 0, 0, 0 };
156  }
157 
160  static bool ImageFile( int 座標X , int 座標Y , const char *ファイル名 , bool 透過フラグ = true )
161  {
162  Image buf(ファイル名);
163  buf.Draw(座標X , 座標Y , false);
164  buf.Release();
165  return true;
166  }
167 
170  static void String(int X座標, int Y座標, Color 色, VariadicStream 描画する文字列)
171  {
172  defaultFont.Draw(X座標,Y座標,色 , 描画する文字列 );
173  }
175  static void StringZMask( int X座標 , int Y座標 , ZMaskType Zマスク , VariadicStream 描画する文字列 )
176  {
177  for (auto it : 描画する文字列.StringS)
178  {
179  Y座標 += 20;
180  }
181  }
182 };
183 }
static void StringZMask(int X座標, int Y座標, ZMaskType Zマスク, VariadicStream 描画する文字列)
文字をマスク[DXLIB].
Definition: Drawing.h:175
ZMaskType
Zマスクの種類.
Definition: Image.h:8
int GetGreen() const
緑の要素を取得.
Definition: Color.h:31
static ColorData GetPixel(int 座標X, int 座標Y)
指定座標の色を取得[DXLIB].
Definition: Drawing.h:153
FontHandle GetHandle() const
フォントのハンドルを取得.
Definition: Font.h:64
static bool Circle(int 中心X, int 中心Y, int 半径, Color 色, bool 塗りつぶしフラグ)
中心と半径を指定して円を描画.
Definition: Drawing.h:111
int GetBlue() const
青の要素を取得.
Definition: Color.h:37
static Screen & Single()
シングルトンなインスタンスを取得.
Definition: Screen.h:42
リソースを読み込まずに描画を行う関数群.
Definition: Drawing.h:12
bool Draw(int X座標, int Y座標, bool 反転フラグ=false) const
指定座標に描画.
Definition: Image.h:163
static bool RectZMask(int 座標X, int 座標Y, int 幅, int 高さ, ZMaskType マスクタイプ, bool 塗りつぶしフラグ)
左上の座標と大きさを指定して矩形をマスク[DXLIB].
Definition: Drawing.h:104
フォントデータを表すクラス.
Definition: Font.h:23
static bool Rect(int 座標X, int 座標Y, int 幅, int 高さ, Color 色, bool 塗りつぶしフラグ)
左上の座標と大きさを指定して矩形を描画.
Definition: Drawing.h:92
static void SetDefaultFont(const char *フォント名, int 大きさ)
デフォルトのフォントを設定する.
Definition: Drawing.h:78
static bool CircleZMask(int 中心X, int 中心Y, int 半径, Color 色, bool 塗りつぶしフラグ)
中心と半径を指定して円をマスク[DXLIB].
Definition: Drawing.h:119
画像データを表すクラス.
Definition: Image.h:37
色を表すクラス.
Definition: Color.h:7
static bool Triangle(int 頂点aX, int 頂点aY, int 頂点bX, int 頂点bY, int 頂点cX, int 頂点cY, Color 色, bool 塗りつぶしフラグ)
頂点を3つ指定して三角形を描画.
Definition: Drawing.h:135
static void String(int X座標, int Y座標, Color 色, VariadicStream 描画する文字列)
文字を描画.
Definition: Drawing.h:170
bool Release() const
フォントをメモリから開放する.
Definition: Font.h:55
static bool Pixel(int 座標X, int 座標Y, Color 色)
指定座標に点を描画.
Definition: Drawing.h:145
bool Release()
イメージをメモリから開放.
Definition: Image.h:112
int GetRed() const
赤の要素を取得.
Definition: Color.h:25
可変数引数な文字列を処理するクラス.
Definition: VariadicStream.h:8
static bool ImageFile(int 座標X, int 座標Y, const char *ファイル名, bool 透過フラグ=true)
画像を一時的にメモリに読み込んで描画.
Definition: Drawing.h:160
static bool Oval(int 中心X, int 中心Y, int 幅, int 高さ, Color 色, bool 塗りつぶしフラグ)
中心と外接する四角形の大きさを指定して楕円を描画[DXLIB].
Definition: Drawing.h:126
static Font & GetFont()
デフォルトのフォントを取得する[SDL].
Definition: Drawing.h:72
bool DrawExtend(int X座標A, int Y座標A, int X座標B, int Y座標B) const
指定矩形内に描画.
Definition: Image.h:182
bool Draw(int X座標, int Y座標, Color 色, VariadicStream 描画する文字列) const
文字を描画.
Definition: Font.h:135
bool Load(const char *フォント名, int 大きさ, int 太さ=1, int 改行高さ=0, FontType フォントタイプ=FontType::Normal)
メモリ上にフォントを作成する.
Definition: Font.h:43
static bool Line(int 始点X, int 始点Y, int 終点X, int 終点Y, Color 色, int 太さ)
始点と終点を結ぶ直線を描画.
Definition: Drawing.h:85
static ScreenHandle GetHandle()
スクリーンハンドルを取得.
Definition: Screen.h:49