-
Notifications
You must be signed in to change notification settings - Fork 0
/
window_appears.cpp
78 lines (63 loc) · 1.35 KB
/
window_appears.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// 画面外からぬるっと現れるビューポート
#include <Siv3D.hpp> // OpenSiv3D v0.6.11
class SubWindow
{
Vec2 m_size;
Vec2 m_pos;
Vec2 m_posTo;
Vec2 m_vel;
Font m_font;
public:
SubWindow() :
m_size(700, 500),
m_pos(-m_size.x - 100, Scene::Height() / 2 - m_size.y / 2),
m_posTo(m_pos),
m_vel(),
m_font(56, Typeface::Bold)
{
}
void show()
{
m_posTo.x = Scene::Width() / 2 - m_size.x / 2;
}
void hide()
{
m_posTo.x = -m_size.x - 100;
}
void update()
{
m_pos = Math::SmoothDamp(m_pos, m_posTo, m_vel, 0.1, unspecified, Scene::DeltaTime());
}
void draw() const
{
const ScopedViewport2D viewport{ m_pos.asPoint(), m_size.asPoint() };
// ウィンドウ背景、枠
RectF(m_size)
.draw(ColorF(0, 0.80))
.drawFrame(8.0, Palette::Dodgerblue);
// ウィンドウの内容
const auto f = m_font(U"サブウィンドウだよ");
f.drawAt(m_size / 2 + Vec2(4, 4), ColorF(0.6, 0.5));
f.drawAt(m_size / 2, Palette::White);
}
};
void Main_window_appears()
{
Scene::SetBackground(ColorF(0.95, 0.95, 0.95));
Font font(40, Typeface::Bold);
SubWindow wnd;
while (System::Update())
{
font(U"Spaceキーでサブウィンドウ表示").drawAt(Scene::CenterF(), Palette::Gray);
if (KeySpace.down())
{
wnd.show();
}
else if (KeySpace.up())
{
wnd.hide();
}
wnd.update();
wnd.draw();
}
}