CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

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