SDXFrameWork 0.13 SDXFrameWork

- Main Page
- Related Pages
- Classes

All Classes Namespaces Functions Variables Enumerations Enumerator Pages
BmpFrame.h
1 //Copyright © 2014 SDXFramework
2 //[License]GNU Affero General Public License, version 3
3 //[Contact]http://sourceforge.jp/projects/dxframework/
4 #pragma once
5 #include <Framework/ImagePack.h>
6 #include <Framework/IFrame.h>
7
8 namespace SDX
9 {
12 class BmpFrame : public IFrame
13 {
14 private:
15 ImagePack *frame = nullptr;
16 public:
17
18 BmpFrame() = default;
19
22 BmpFrame(ImagePack *フレーム画像)
23 {
24 Make(フレーム画像);
25 }
26
29 bool Make(ImagePack *フレーム画像)
30 {
31 if (Loading::IsLoading())
32 {
33 Loading::AddLoading([=]{ Make(フレーム画像); });
34 return true;
35 }
36
37 if (フレーム画像->GetSize() != 9) return false;
38 frame = フレーム画像;
39
40 return true;
41 }
42
46 void Draw(const Rect &領域 , const Color &描画色 = Color::White) const
47 {
48 if (frame == nullptr){ return; }
49
50 Color color = Screen::GetRenderer()->rgba;
51
52 if (描画色 != Color::White)
53 {
54 Screen::GetRenderer()->rgba.SetColor
55 (
56 color.GetRed() * 描画色.GetRed() / 255,
57 color.GetGreen() * 描画色.GetGreen() / 255,
58 color.GetBlue() * 描画色.GetBlue() / 255,
59 color.GetAlpha() * 描画色.GetAlpha() / 255
60 );
61 }
62
63 auto camera = Camera::Get();
64
65 int width = frame->GetWidth();
66 int height = frame->GetHeight();
67 bool isMin = true;//枠が小さいため部分描画が必要フラグ
68 int partW = width;
69 int partH = height;
70 int partLeft = 0;
71 int partTop = 0;
72
73 //外枠
74 if (width * 2 > 領域.GetW())
75 {
76 width = (int)領域.GetW() / 2;
77 partW = width;
78 partLeft = frame->GetWidth() - width;
79 isMin = true;
80 }
81 if (height * 2 > 領域.GetH())
82 {
83 height = (int)領域.GetH() / 2;
84 partH = height;
85 partTop = frame->GetHeight() - height;
86 isMin = true;
87 }
88
89 if (camera)
90 {
91 //隙間が出来るのでCameraの機能はここで計算
92 Camera::Set();
93
94 width = int(width * camera->zoom);
95 height = int(height *camera->zoom);
96
97 //カメラ補正有り
98 int xA = (int)camera->TransX(領域.GetLeft());
99 int xB = xA + width;
100 int xD = (int)camera->TransX(領域.GetRight());
101 int xC = xD - width;
102
103 int yA = (int)camera->TransY(領域.GetTop());
104 int yB = yA + height;
105 int yD = (int)camera->TransY(領域.GetBottom());
106 int yC = yD - height;
107
108 //内側
109 frame[0][4]->DrawExtend({ xB, yB, xC -xB, yC - yB });
110
111 if (isMin)
112 {
113 frame[0][3]->DrawPartExtend({ xA, yB, width, yC - yB }, { 0, 0, width, height});//左
114 frame[0][5]->DrawPartExtend({ xC, yB, width, yC - yB }, { partLeft, 0, width, height });//右
115
116 frame[0][1]->DrawPartExtend({ xB, yA, xC - xB, height }, { 0, 0, width, height });//上
117 frame[0][7]->DrawPartExtend({ xB, yC, xC - xB, height }, { 0, partTop, width, height });//下
118
119 frame[0][0]->DrawPartExtend({ xA, yA, width, height }, { 0, 0, width, height });//左上
120 frame[0][2]->DrawPartExtend({ xC, yA, width, height }, { partLeft, 0, width, height });//右上
121 frame[0][6]->DrawPartExtend({ xA, yC, width, height }, { 0, partTop, width, height });//左下
122 frame[0][8]->DrawPartExtend({ xC, yC, width, height }, { partLeft, partTop, width, height });//右下
123 }
124 else
125 {
126 frame[0][3]->DrawExtend({ xA, yB, width, yC - yB });//左
127 frame[0][5]->DrawExtend({ xC, yB, width, yC - yB });//右
128
129 frame[0][1]->DrawExtend({ xB, yA, xC - xB, height });//上
130 frame[0][7]->DrawExtend({ xB, yC, xC - xB, height });//下
131
132 frame[0][0]->DrawExtend({ xA, yA, width, height });//左上
133 frame[0][2]->DrawExtend({ xC, yA, width, height });//右上
134 frame[0][6]->DrawExtend({ xA, yC, width, height });//左下
135 frame[0][8]->DrawExtend({ xC, yC, width, height });//右下
136 }
137
138 Camera::Set(camera);
139 }
140 else
141 {
142 //カメラ補正無し
143 int xA = (int)領域.GetLeft();
144 int xB = (int)領域.GetLeft() + width;
145 int xC = (int)領域.GetRight() - width;
146 int yA = (int)領域.GetTop();
147 int yB = (int)領域.GetTop() + height;
148 int yC = (int)領域.GetBottom() - height;
149
150 //内側
151 frame[0][4]->DrawExtend({ xB, yB, 領域.GetW() - width * 2, 領域.GetH() - height * 2 });
152
153 if (isMin)
154 {
155 //外枠
156 frame[0][3]->DrawPartExtend({ xA, yB, width, 領域.GetH() - height * 2 }, { 0, 0, width, height });//左
157 frame[0][5]->DrawPartExtend({ xC, yB, width, 領域.GetH() - height * 2 }, { partLeft, 0, width, height });//右
158
159 frame[0][1]->DrawPartExtend({ xB, yA, 領域.GetW() - width * 2, height }, { 0, 0, width, height });//上
160 frame[0][7]->DrawPartExtend({ xB, yC, 領域.GetW() - width * 2, height }, { 0, partTop, width, height });//下
161
162 frame[0][0]->DrawPartExtend({ xA, yA, width, height }, { 0, 0, width, height });//左上
163 frame[0][2]->DrawPartExtend({ xC, yA, width, height }, { partLeft, 0, width, height });//右上
164 frame[0][6]->DrawPartExtend({ xA, yC, width, height }, { 0, partTop, width, height });//左下
165 frame[0][8]->DrawPartExtend({ xC, yC, width, height }, { partLeft, partTop, width, height });//右下
166 }
167 else
168 {
169 //外枠
170 frame[0][3]->DrawExtend({ xA, yB, width, 領域.GetH() - height * 2 });//左
171 frame[0][5]->DrawExtend({ xC, yB, width, 領域.GetH() - height * 2 });//右
172
173 frame[0][1]->DrawExtend({ xB, yA, 領域.GetW() - width * 2, height });//上
174 frame[0][7]->DrawExtend({ xB, yC, 領域.GetW() - width * 2, height });//下
175
176 frame[0][0]->DrawExtend({ xA, yA, width, height });//左上
177 frame[0][2]->DrawExtend({ xC, yA, width, height });//右上
178 frame[0][6]->DrawExtend({ xA, yC, width, height });//左下
179 frame[0][8]->DrawExtend({ xC, yC, width, height });//右下
180 }
181
182 }
183
184 Camera::Set(camera);
185
186 if (描画色 != Color::White)
187 {
188 Screen::GetRenderer()->rgba = color;
189 }
190 }
191 };
192 }
SDX::Color::GetGreen
int GetGreen() const
緑の要素を取得.
Definition: Color.h:36
SDX::Rect
矩形を表す図形クラス.
Definition: Rect.h:22
SDX::Rect::GetBottom
double GetBottom() const
下端のY座標を取得.
Definition: Rect.h:136
SDX::Renderer::rgba
Color rgba
描画輝度とα値
Definition: Renderer.h:53
SDX::Rect::GetTop
double GetTop() const
上端のY座標を取得.
Definition: Rect.h:124
SDX::Rect::GetRight
double GetRight() const
右端のX座標を取得.
Definition: Rect.h:130
SDX::ImagePack::GetWidth
int GetWidth() const
最大幅を取得.
Definition: ImagePack.h:192
SDX::Color::GetBlue
int GetBlue() const
青の要素を取得.
Definition: Color.h:42
SDX::Rect::GetLeft
double GetLeft() const
左端のX座標を取得.
Definition: Rect.h:118
SDX::Screen::GetRenderer
static Renderer * GetRenderer()
アクティブなRendererを取得.
Definition: Screen.h:33
SDX::BmpFrame::Make
bool Make(ImagePack *フレーム画像)
フレームを作成する.
Definition: BmpFrame.h:29
SDX::Color::SetColor
void SetColor(int 赤, int 緑, int 青, int α値=255)
色の各要素を設定.
Definition: Color.h:24
SDX::Loading::IsLoading
static bool IsLoading()
非同期読み込み登録中かどうか.
Definition: Loading.h:90
SDX::BmpFrame
描画用枠を表すクラス.
Definition: BmpFrame.h:12
SDX::Color::White
static const Color White
白 [RGB]255,255,255
Definition: Color.h:81
SDX::BmpFrame::Draw
void Draw(const Rect &領域, const Color &描画色=Color::White) const
矩形のフレームを描画.
Definition: BmpFrame.h:46
SDX::Color
色を表すクラス.
Definition: Color.h:11
SDX::Loading::AddLoading
static void AddLoading(std::function< void(void)> &&読み込み関数)
非同期読み込み処理に追加.
Definition: Loading.h:96
SDX::ImagePack::GetSize
int GetSize() const
要素数を取得.
Definition: ImagePack.h:186
SDX::BmpFrame::BmpFrame
BmpFrame(ImagePack *フレーム画像)
フレームを作成する.
Definition: BmpFrame.h:22
SDX::Camera::Get
static Camera * Get()
現在アクティブなカメラを取得.
Definition: Camera.h:57
SDX::Color::GetRed
int GetRed() const
赤の要素を取得.
Definition: Color.h:30
SDX::ImagePack::GetHeight
int GetHeight() const
最大高さを取得.
Definition: ImagePack.h:198
SDX::ImagePack
複数のImageをまとめるクラス.
Definition: ImagePack.h:17
SDX::Camera::Set
static void Set(Camera *アクティブにするCamera=nullptr)
現在アクティブなカメラを設定.
Definition: Camera.h:63
SDX::Color::GetAlpha
int GetAlpha() const
透明度を取得.
Definition: Color.h:48
SDX::Rect::GetW
double GetW() const override
幅を取得.
Definition: Rect.h:107
SDX::IFrame
描画用枠のインターフェース.
Definition: IFrame.h:11
SDX::Rect::GetH
double GetH() const override
高さを取得.
Definition: Rect.h:112