Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/UI/JoystickHistoryView.cpp
5659 views
1
#include <algorithm>
2
3
#include "UI/JoystickHistoryView.h"
4
5
#include "Common/UI/Context.h"
6
#include "Common/UI/UI.h"
7
8
#include "Core/ControlMapper.h"
9
10
void JoystickHistoryView::Draw(UIContext &dc) {
11
const AtlasImage *image = dc.Draw()->GetAtlas()->getImage(ImageID("I_CROSS"));
12
if (!image) {
13
return;
14
}
15
float minRadius = std::min(bounds_.w, bounds_.h) * 0.5f - image->w;
16
dc.Flush();
17
dc.Begin();
18
Bounds textBounds(bounds_.x, bounds_.centerY() + minRadius + 5.0, bounds_.w, bounds_.h / 2 - minRadius - 5.0);
19
dc.DrawTextShadowRect(title_, textBounds, 0xFFFFFFFF, ALIGN_TOP | ALIGN_HCENTER | FLAG_WRAP_TEXT);
20
dc.Flush();
21
dc.BeginNoTex();
22
dc.Draw()->RectOutline(bounds_.centerX() - minRadius, bounds_.centerY() - minRadius, minRadius * 2.0f, minRadius * 2.0f, 0x80FFFFFF);
23
dc.Flush();
24
dc.Begin();
25
26
// First draw a grid.
27
float dx = 1.0f / 10.0f;
28
for (int ix = -10; ix <= 10; ix++) {
29
// First draw vertical lines.
30
float fx = ix * dx;
31
for (int iy = -10; iy < 10; iy++) {
32
float ax = fx;
33
float ay = iy * dx;
34
float bx = fx;
35
float by = (iy + 1) * dx;
36
37
if (type_ == StickHistoryViewType::OUTPUT) {
38
ConvertAnalogStick(ax, ay, &ax, &ay);
39
ConvertAnalogStick(bx, by, &bx, &by);
40
}
41
42
ax = ax * minRadius + bounds_.centerX();
43
ay = ay * minRadius + bounds_.centerY();
44
45
bx = bx * minRadius + bounds_.centerX();
46
by = by * minRadius + bounds_.centerY();
47
48
dc.Draw()->Line(dc.GetTheme().whiteImage, ax, ay, bx, by, 1.0, 0x70FFFFFF);
49
}
50
}
51
52
for (int iy = -10; iy <= 10; iy++) {
53
// Then horizontal.
54
float fy = iy * dx;
55
for (int ix = -10; ix < 10; ix++) {
56
float ax = ix * dx;
57
float ay = fy;
58
float bx = (ix + 1) * dx;
59
float by = fy;
60
61
if (type_ == StickHistoryViewType::OUTPUT) {
62
ConvertAnalogStick(ax, ay, &ax, &ay);
63
ConvertAnalogStick(bx, by, &bx, &by);
64
}
65
66
ax = ax * minRadius + bounds_.centerX();
67
ay = ay * minRadius + bounds_.centerY();
68
69
bx = bx * minRadius + bounds_.centerX();
70
by = by * minRadius + bounds_.centerY();
71
72
dc.Draw()->Line(dc.GetTheme().whiteImage, ax, ay, bx, by, 1.0, 0x70FFFFFF);
73
}
74
}
75
76
77
int a = maxCount_ - (int)locations_.size();
78
for (auto iter = locations_.begin(); iter != locations_.end(); ++iter) {
79
float x = bounds_.centerX() + minRadius * iter->x;
80
float y = bounds_.centerY() - minRadius * iter->y;
81
float alpha = (float)a / (float)(maxCount_ - 1);
82
if (alpha < 0.0f) {
83
alpha = 0.0f;
84
}
85
// Emphasize the newest (higher) ones.
86
alpha = powf(alpha, 3.7f);
87
// Highlight the output (and OTHER)
88
if (alpha >= 1.0f && type_ != StickHistoryViewType::INPUT) {
89
dc.Draw()->DrawImage(ImageID("I_CIRCLE"), x, y, 1.0f, colorAlpha(0xFFFFFF, 1.0), ALIGN_CENTER);
90
} else {
91
dc.Draw()->DrawImage(ImageID("I_CIRCLE"), x, y, 0.8f, colorAlpha(0xC0C0C0, alpha * 0.5f), ALIGN_CENTER);
92
}
93
a++;
94
}
95
dc.Flush();
96
}
97
98
void JoystickHistoryView::Update() {
99
locations_.push_back(Location{ curX_, curY_ });
100
if ((int)locations_.size() > maxCount_) {
101
locations_.pop_front();
102
}
103
}
104
105