SDXFrameWork  0.09
SDXFrameWork
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
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 #include<Framework/Shape.h>
8 
9 namespace SDX
10 {
13 class Drawing
14 {
15 private:
16  Drawing();
17  ~Drawing();
18 
19  static Font defaultFont;
20 
22  static void RGBACulculate(int 赤 , int 緑 , int 青)
23  {
24  SDL_SetRenderDrawBlendMode(Screen::GetHandle(), (SDL_BlendMode)Screen::Single().nowBlendMode);
25  SDL_SetRenderDrawColor
26  (
28  Screen::Single().rgba.GetRed() * 赤 / 255,
29  Screen::Single().rgba.GetGreen() * 緑 / 255,
30  Screen::Single().rgba.GetBlue() * 青 / 255,
31  Screen::Single().blendParam
32  );
33  }
35  static Image& circleTexture( bool 塗りつぶしフラグ)
36  {
37  static Image circleA;
38  static Image circleB;
39 
40  if (circleA.handle == nullptr)
41  {
42  Font font;
43  font.Load(SystemFont::Gothic, 1000);
44 
45  SDL_Surface* surfaceA = TTF_RenderUTF8_Blended( font.GetHandle(), "●", {255,255,255,255});
46  circleA.handle = SDL_CreateTextureFromSurface(Screen::GetHandle(), surfaceA);
47  circleA.part.w = surfaceA->w;
48  circleA.part.h = surfaceA->h;
49  SDL_FreeSurface(surfaceA);
50 
51  SDL_Surface* surfaceB = TTF_RenderUTF8_Blended(font.GetHandle(), "○", { 255, 255, 255, 255 });
52  circleB.handle = SDL_CreateTextureFromSurface(Screen::GetHandle(), surfaceB);
53  circleB.part.w = surfaceB->w;
54  circleB.part.h = surfaceB->h;
55  SDL_FreeSurface(surfaceB);
56 
57  font.Release();
58  }
59 
60  if (塗りつぶしフラグ)
61  {
62  return circleA;
63  }
64  else
65  {
66  return circleB;
67  }
68  }
69 
70 public:
71 
73  static Font& GetFont()
74  {
75  return defaultFont;
76  }
77 
79  static void SetDefaultFont( const char* フォント名 , int 大きさ)
80  {
81  GetFont().Load(フォント名, 大きさ);
82  }
83 
86  static bool Line(const Point &始点, const Point &終点, Color 色, int 太さ)
87  {
88  RGBACulculate(色.GetRed() , 色.GetGreen() , 色.GetBlue() );
89  return !SDL_RenderDrawLine(Screen::GetHandle(), (int)始点.x, (int)始点.y, (int)終点.x, (int)終点.y);
90  }
91 
93  static bool Rect(const Rect &領域, Color 色, bool 塗りつぶしフラグ)
94  {
95  SDL_Rect buf = { (int)領域.GetLeft(),(int)領域.GetTop(),(int)領域.GetW(),(int)領域.GetH() };
96  RGBACulculate(色.GetRed() , 色.GetGreen() , 色.GetBlue() );
97  if (塗りつぶしフラグ)
98  {
99  return !SDL_RenderFillRect(Screen::GetHandle(), &buf);
100  }else{
101  return !SDL_RenderDrawRect(Screen::GetHandle(), &buf);
102  }
103  }
104 
107  static void Circle(const Circle &円形, Color 色, bool 塗りつぶしフラグ)
108  {
109  SDL_SetRenderDrawColor(Screen::GetHandle(), 色.GetRed(), 色.GetGreen(), 色.GetBlue(), 0);
110  circleTexture(塗りつぶしフラグ).DrawExtend({ 円形.x - 円形.radius, 円形.y - 円形.radius }, { 円形.x + 円形.radius, 円形.y + 円形.radius });
111  }
112 
115  static void Oval( const Point &中心 , int 幅 , int 高さ , Color 色 , bool 塗りつぶしフラグ )
116  {
117  SDL_SetRenderDrawColor(Screen::GetHandle(), 色.GetRed(), 色.GetGreen(), 色.GetBlue(), 0);
118  circleTexture(塗りつぶしフラグ).DrawExtend({ 中心.x - 幅 / 2, 中心.y - 高さ / 2 }, { 中心.x + 幅 / 2, 中心.y + 高さ / 2 });
119  }
120 
123  static void Triangle(const Point &頂点A, const Point &頂点B, const Point &頂点C, Color 色, bool 塗りつぶしフラグ)
124  {
125  RGBACulculate(色.GetRed(), 色.GetGreen(), 色.GetBlue());
126  SDL_RenderDrawLine(Screen::GetHandle(), (int)頂点A.x, (int)頂点A.y, (int)頂点B.x, (int)頂点B.y);
127  SDL_RenderDrawLine(Screen::GetHandle(), (int)頂点B.x, (int)頂点B.y, (int)頂点C.x, (int)頂点C.y);
128  SDL_RenderDrawLine(Screen::GetHandle(), (int)頂点C.x, (int)頂点C.y, (int)頂点A.x, (int)頂点A.y);
129  }
130 
132  static void Pixel(const Point &座標 , Color 色)
133  {
134  RGBACulculate(色.GetRed() , 色.GetGreen() , 色.GetBlue() );
135  SDL_RenderDrawPoint(Screen::GetHandle(), (int)座標.x, (int)座標.y);
136  }
137 
139  static ColorData GetPixel( const Point &座標 )
140  {
141  return SDL_Color{ 0, 0, 0 };
142  }
143 
146  static void ImageFile( const Point &座標 , const char *ファイル名 , bool 透過フラグ = true )
147  {
148  Image buf(ファイル名);
149  buf.Draw( 座標 , false);
150  buf.Release();
151  }
152 
155  static void String( const Point &座標 , Color 色, VariadicStream 描画する文字列)
156  {
157  defaultFont.Draw( 座標 ,色 , 描画する文字列 );
158  }
159 };
160 }
static void Circle(const Circle &円形, Color 色, bool 塗りつぶしフラグ)
中心と半径を指定して円を描画.
Definition: Drawing.h:107
static void Oval(const Point &中心, int 幅, int 高さ, Color 色, bool 塗りつぶしフラグ)
中心と外接する四角形の大きさを指定して楕円を描画.
Definition: Drawing.h:115
int GetGreen() const
緑の要素を取得.
Definition: Color.h:31
矩形を表す図形クラス.
Definition: Shape.h:536
bool Draw(const Point &座標, bool 反転フラグ=false) const
指定座標に描画.
Definition: Image.h:164
static RendererHandle GetHandle()
スクリーンハンドルを取得.
Definition: Screen.h:77
double GetW() const
幅を取得.
Definition: Shape.h:616
FontHandle GetHandle() const
フォントのハンドルを取得.
Definition: Font.h:64
bool DrawExtend(const Point &座標A, const Point &座標B) const
指定矩形内に描画.
Definition: Image.h:178
int GetBlue() const
青の要素を取得.
Definition: Color.h:37
static Screen & Single()
シングルトンなインスタンスを取得.
Definition: Screen.h:70
リソースを読み込まずに描画を行う関数群.
Definition: Drawing.h:13
点を表す図形クラス.
Definition: Shape.h:129
static ColorData GetPixel(const Point &座標)
指定座標の色を取得[未実装].
Definition: Drawing.h:139
フォントデータを表すクラス.
Definition: Font.h:23
static void Triangle(const Point &頂点A, const Point &頂点B, const Point &頂点C, Color 色, bool 塗りつぶしフラグ)
頂点を3つ指定して三角形を描画.
Definition: Drawing.h:123
static void Pixel(const Point &座標, Color 色)
指定座標に点を描画.
Definition: Drawing.h:132
static void SetDefaultFont(const char *フォント名, int 大きさ)
デフォルトのフォントを設定する.
Definition: Drawing.h:79
画像データを表すクラス.
Definition: Image.h:38
色を表すクラス.
Definition: Color.h:7
bool Draw(const Point &座標, Color 色, VariadicStream 描画する文字列) const override
文字を描画.
Definition: Font.h:135
bool Release() const
フォントをメモリから開放する.
Definition: Font.h:55
bool Release()
イメージをメモリから開放.
Definition: Image.h:113
int GetRed() const
赤の要素を取得.
Definition: Color.h:25
可変数引数な文字列を処理するクラス.
Definition: VariadicStream.h:8
static void ImageFile(const Point &座標, const char *ファイル名, bool 透過フラグ=true)
画像を一時的にメモリに読み込んで描画.
Definition: Drawing.h:146
static void String(const Point &座標, Color 色, VariadicStream 描画する文字列)
文字を描画.
Definition: Drawing.h:155
static Font & GetFont()
デフォルトのフォントを取得する[SDL].
Definition: Drawing.h:73
円を表す図形クラス.
Definition: Shape.h:789
static bool Line(const Point &始点, const Point &終点, Color 色, int 太さ)
始点と終点を結ぶ直線を描画.
Definition: Drawing.h:86
bool Load(const char *フォント名, int 大きさ, int 太さ=1, int 改行高さ=0, FontType フォントタイプ=FontType::Normal)
メモリ上にフォントを作成する.
Definition: Font.h:43
double GetH() const
高さを取得.
Definition: Shape.h:621
static bool Rect(const Rect &領域, Color 色, bool 塗りつぶしフラグ)
左上の座標と大きさを指定して矩形を描画.
Definition: Drawing.h:93