KisaragiLibrary
 
読み取り中…
検索中…
一致する文字列を見つけられません
ImgComponent.hpp
[詳解]
1#pragma once
2#include <string>
3#include <DxLib.h>
4#include <map>
5#include <vector>
6#include <cassert>
7#include <iterator>
8#include <algorithm>
9
10#include "Const.h"
11#include "Kisaragi_Resource.h"
13#include "ComponentBase.hpp"
14#include "GameObj.hpp"
16#include "Accessor.hpp"
17#include "Matrix2D.hpp"
18
20#include "utility\Color.hpp"
21
22//TODO AddComponentの時に使えると思うんですけど、
23// https://cpprefjp.github.io/lang/cpp11/trailing_return_types.html
24// </summary>auto Pop() -> decltype(queue.back()->GetThisData())
25// <returns>ポップしたDrawBaseDataの派生クラスを返す</returns>
26
27namespace
28{
29 using std::string;
30 using std::map;
31 using std::vector;
34}
35
36
37namespace Kisaragi_Lib
38{
39 namespace ImgComponent
40 {
41
42 class LayerFacade;
43 LayerFacade& GetLayerFacade();
44
45 /// <summary>
46 /// 描画コンポーネントの基底クラス.
47 /// </summary>
48 class ImgBase : public ComponentBase
49 {
50 protected:
51 string layer;
52 public:
53
54 //TODO 消す
55 virtual void Draw(Matrix2D _drawMat) {};
56 virtual void Draw() {};
57 string Layer() const
58 {
59 return layer;
60 }
61
62 void ChangeLayer(string _layerName, bool _layerCreate);
63
64 void Start() override;
65
66 virtual ~ImgBase();
67 };
68
69 /// <summary>
70 /// 画像描画クラス
71 /// </summary>
72 class ImgGraph : public ImgBase
73 {
74 protected:
75 int img;
78 bool trans = true; //透過
79
80 public:
81 /// <summary>
82 /// 要素に応じて画像の反転を行います
83 /// </summary>
85 /// <summary>
86 /// 画像サイズ(読み取り専用)
87 /// </summary>
89 /// <summary>
90 /// 画像を透過するか否か
91 /// </summary>
93
94 ImgGraph();
95
96 void SetImg(string _imgKey);
97
98 void SetImg(string _imgKey, string _imgPass);
99
100 int GetImg();
101
102 void Draw(Matrix2D _drawMat)override;
103 void Draw()override;
104
106 {
107 return this;
108 }
109
110 };
111
112 class ImgLine : public ImgBase
113 {
114 public:
116
117 void Draw(Matrix2D _drawMat)override
118 {
119 DrawLine(_drawMat.Position().x , _drawMat.Position().y, p.x + WINDOW_WIDTH/2, p.y+WINDOW_HEIGHT/2, GetColor(255, 255, 0));
120 }
121 };
122
123 /// <summary>
124 /// 縦書きか横書きか
125 /// </summary>
127 {
128 HORIZONTAL,//横書き
129 VERTICAL,//縦書き
130 };
131
132 class ImgText : public ImgBase
133 {
134 protected:
135 string text;
136 unsigned int col;
137 unsigned int edgeCol;
139 std::shared_ptr<Font> font = FontFacade::Get("Default");
140
141
142 public:
148
149 void Draw(Matrix2D _drawMat)override
150 {
151
152 //縦書きフラグ
153 bool v = (writingType == VERTICAL);
154
155
156 int tmpX ;
157 int tmpY ;
158
159 GetDrawStringSizeToHandle(
160 &tmpX, &tmpY,
161 nullptr,
162 text.c_str(),text.size()+1, *font
163 );
164
165 tmpX /= 2;
166 tmpY /= 2;
167
168 DrawRotaStringToHandle(
169 _drawMat.Position().x, _drawMat.Position().y, //左上座標
170 _drawMat.Scale().x,_drawMat.Scale().y, //拡大率
171 tmpX, tmpY , //回転の中心(左上座標の相対座標)
172 _drawMat.Rotation(), //回転角度
173 col, //文字色
174 *font, //フォント
175 edgeCol, //文字縁の色
176 v, //縦書きか否か
177 text.c_str() //テキスト
178 );
179 }
180
181 };
182
183 /// <summary>
184 /// 円の描画クラス
185 /// </summary>
186 class ImgCircle : public ImgBase
187 {
188 public:
189 // 半径
190 double radius;
191 // 円の色
192 RGB255 rgb{ 255, 255, 0 };
193 // 塗りつぶしを行うか
194 bool isFill = false;
195
196 void Draw(Matrix2D _drawMat)override
197 {
198 DrawOval(
199 _drawMat.Position().x, _drawMat.Position().y,
200 radius * _drawMat.Scale().x, radius * _drawMat.Scale().y,
201 rgb.ToDxLibColor(),
202 isFill
203 );
204 }
205 };
206
207 class Layer
208 {
209 private:
210 map<string,ImgBase*> queue;
211
212 public:
213 //Push()
214 void Push(string _id,ImgBase* _drawComponent)
215 {
216 queue.emplace(_id, _drawComponent);
217 }
218
220 {
221 Clear();
222 }
223
224 /// <summary>
225 /// データをポップする.
226 /// </summary>
227 void Pop(string _id)
228 {
229 if (Empty())
230 {
231 return;
232 }
233
234 queue.erase(_id);
235 }
236
237 /// <summary>
238 /// キューをクリアする.
239 /// </summary>
240 void Clear()
241 {
242 queue.clear();
243 }
244
245 /// <summary>
246 /// キューが空か調べる.
247 /// </summary>
248 /// <returns>空ならtrue</returns>
249 bool Empty()
250 {
251 return queue.empty();
252 }
253
254 //TODO 描画処理はviewで行われるべき.
255 /// <summary>
256 /// 描画処理を行う.
257 /// </summary>
258 void Draw()
259 {
260 for (auto& q : queue)
261 {
262 //ここでカメラを取得
263 //if ( camera.DrawLayer != q ) { continue; }
264
265 q.second->Draw();
266 }
267 }
268
269 unsigned int Cnt()
270 {
271 return (unsigned int)queue.size();
272 }
273
274 map<string, ImgBase*> Queue()
275 {
276 return queue;
277 }
278 };
279
281 {
282 private:
283 map<string, Layer*>layers;
284 vector<string>layerName;
285
286 public:
288 {
289 AddLayer("Default");
290 }
291
293 {
294 ClearLayer();
295 }
296
297 /// <summary>
298 /// レイヤーを追加する.
299 /// </summary>
300 /// <param name="_key">レイヤー名</param>
301 /// <returns>追加に成功したかどうか</returns>
302 Result AddLayer(string _key);
303
304 /// <summary>
305 /// レイヤーを削除する
306 /// </summary>
307 /// <param name="_key">削除したいレイヤー名</param>
308 void RemoveLayer(string _key);
309
310 /// <summary>
311 /// レイヤーを全て消去する.
312 /// </summary>
313 void ClearLayer();
314
315 /// <summary>
316 /// レイヤー名を取得する
317 /// </summary>
318 /// <returns></returns>
319 vector<string> LayerName();
320
321 map<string, Layer*> Layers()
322 {
323 return layers;
324 }
325
326 /// <summary>
327 /// レイヤー順を交換する
328 /// </summary>
329 /// <param name="_key1">交換したいレイヤー名1</param>
330 /// <param name="_key2">交換したいレイヤー名2</param>
331 void SwapLayer(string _key1, string _key2);
332
333 void Draw();
334
335 //ImgComponent操作
336#pragma region ImgComponent操作
337 void ImgPush(string _layerName, ImgBase* _drawData, bool ifCreate = false);
338
339 void ImgPop(string _layerName, string _id);
340
341 void ImgClear(string _layerName);
342
343
344#pragma endregion
345
346 };
347
348 LayerFacade& GetLayerFacade();
349
350
351 }
352}
色データを扱う型の定義
Result
成否を表す.
Definition Const.h:8
const int WINDOW_WIDTH
Definition Const.h:18
const int WINDOW_HEIGHT
Library合成でカオスになったのでいったんこれで TODO 後でLibraryのコンフィグファイルとかにしていいと思います
Definition Const.h:17
独自のMathを提供します
ImgGraph()
Definition ImgComponent.cpp:177
public空間に置くことで,T*のAccessorを提供します
Definition Accessor.hpp:267
Definition ComponentBase.hpp:24
static std::shared_ptr< Font > Get(std::string _key)
Fontを取得する
Definition FontFacade.cpp:112
ID割り当てクラス
Definition IDAssignment.h:15
描画コンポーネントの基底クラス.
Definition ImgComponent.hpp:49
virtual void Draw(Matrix2D _drawMat)
Definition ImgComponent.hpp:55
string layer
Definition ImgComponent.hpp:51
virtual ~ImgBase()
Definition ImgComponent.cpp:16
string Layer() const
Definition ImgComponent.hpp:57
void Start() override
Definition ImgComponent.cpp:10
virtual void Draw()
Definition ImgComponent.hpp:56
void ChangeLayer(string _layerName, bool _layerCreate)
Definition ImgComponent.cpp:21
円の描画クラス
Definition ImgComponent.hpp:187
double radius
Definition ImgComponent.hpp:190
RGB255 rgb
Definition ImgComponent.hpp:192
void Draw(Matrix2D _drawMat) override
Definition ImgComponent.hpp:196
bool isFill
Definition ImgComponent.hpp:194
int img
Definition ImgComponent.hpp:75
Vector2D< float > size
Definition ImgComponent.hpp:76
ReadOnly< Vector2D< float > > Size
画像サイズ(読み取り専用)
Definition ImgComponent.hpp:88
ImgGraph * GetThisComponent() override
Definition ImgComponent.hpp:105
Vector2D< float > imgCentor
Definition ImgComponent.hpp:77
void SetImg(string _imgKey)
Definition ImgComponent.cpp:182
Accessor< bool > Trans
画像を透過するか否か
Definition ImgComponent.hpp:92
int GetImg()
Definition ImgComponent.cpp:195
Vector2D< bool > isTurn
要素に応じて画像の反転を行います
Definition ImgComponent.hpp:84
void Draw() override
Definition ImgComponent.cpp:200
ImgGraph()
Definition ImgComponent.cpp:177
bool trans
Definition ImgComponent.hpp:78
Definition ImgComponent.hpp:113
Point2D< double > p
Definition ImgComponent.hpp:115
void Draw(Matrix2D _drawMat) override
Definition ImgComponent.hpp:117
Definition ImgComponent.hpp:133
Accessor< WritingType > Type
Definition ImgComponent.hpp:146
Accessor< unsigned int > Col
Definition ImgComponent.hpp:144
WritingType writingType
Definition ImgComponent.hpp:138
unsigned int edgeCol
Definition ImgComponent.hpp:137
Accessor< string > Text
Definition ImgComponent.hpp:143
Accessor< std::shared_ptr< Font > > Font
Definition ImgComponent.hpp:147
std::shared_ptr< Font > font
Definition ImgComponent.hpp:139
void Draw(Matrix2D _drawMat) override
Definition ImgComponent.hpp:149
Accessor< unsigned int > EdgeCol
Definition ImgComponent.hpp:145
string text
Definition ImgComponent.hpp:135
unsigned int col
Definition ImgComponent.hpp:136
Result AddLayer(string _key)
レイヤーを追加する.
Definition ImgComponent.cpp:36
void ImgPush(string _layerName, ImgBase *_drawData, bool ifCreate=false)
Definition ImgComponent.cpp:138
void ClearLayer()
レイヤーを全て消去する.
Definition ImgComponent.cpp:75
map< string, Layer * > layers
Definition ImgComponent.hpp:283
void ImgPop(string _layerName, string _id)
Definition ImgComponent.cpp:155
void Draw()
Definition ImgComponent.cpp:122
vector< string > LayerName()
レイヤー名を取得する
Definition ImgComponent.cpp:91
void SwapLayer(string _key1, string _key2)
レイヤー順を交換する
Definition ImgComponent.cpp:101
void ImgClear(string _layerName)
Definition ImgComponent.cpp:165
void RemoveLayer(string _key)
レイヤーを削除する
Definition ImgComponent.cpp:57
map< string, Layer * > Layers()
Definition ImgComponent.hpp:321
vector< string > layerName
Definition ImgComponent.hpp:284
~LayerFacade()
Definition ImgComponent.hpp:292
LayerFacade()
Definition ImgComponent.hpp:287
Definition ImgComponent.hpp:208
void Clear()
キューをクリアする.
Definition ImgComponent.hpp:240
bool Empty()
キューが空か調べる.
Definition ImgComponent.hpp:249
unsigned int Cnt()
Definition ImgComponent.hpp:269
map< string, ImgBase * > queue
Definition ImgComponent.hpp:210
~Layer()
Definition ImgComponent.hpp:219
void Push(string _id, ImgBase *_drawComponent)
Definition ImgComponent.hpp:214
map< string, ImgBase * > Queue()
Definition ImgComponent.hpp:274
void Pop(string _id)
データをポップする.
Definition ImgComponent.hpp:227
void Draw()
描画処理を行う.
Definition ImgComponent.hpp:258
Definition Matrix2D.hpp:24
Point2D< double > Position()
Definition Matrix2D.hpp:87
double Rotation()
回転をラジアン値で返す
Definition Matrix2D.hpp:96
Point2D< double > Scale()
Definition Matrix2D.hpp:103
public空間に置くことで,T*のSetterを提供します
Definition Accessor.hpp:117
WritingType
縦書きか横書きか
Definition ImgComponent.hpp:127
@ HORIZONTAL
Definition ImgComponent.hpp:128
@ VERTICAL
Definition ImgComponent.hpp:129
LayerFacade & GetLayerFacade()
Definition ImgComponent.cpp:30
Definition Accessor.hpp:110
点を表すプリミティブ型
Definition Primitive.hpp:29
T y
Definition Primitive.hpp:30
T x
Definition Primitive.hpp:30
RGBカラーを扱う型 それぞれの値を0~255の範囲で管理します。 また自身が保持する色をDxLibのカラーに変更可能です
Definition Color.hpp:27
ベクトルを表すプリミティブ型
Definition Primitive.hpp:203