Skip to content

Commit 388c63a

Browse files
Improve touch overlays (#112)
* Improve touch DPAD overlay * update
1 parent 0e1db03 commit 388c63a

File tree

2 files changed

+68
-14
lines changed

2 files changed

+68
-14
lines changed

src/common.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ void init()
482482
style.WindowRounding = 0.0f;
483483
style.Colors[ImGuiCol_WindowBg].w = 1.0f;
484484
style.Colors[ImGuiCol_PopupBg].w = 1.0f;
485+
style.AntiAliasedFill = true;
486+
style.AntiAliasedLines = true;
487+
style.AntiAliasedLinesUseTex = true;
485488

486489
default_style = style;
487490

src/view_player.cpp

+65-14
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,70 @@ static void draw_button(ImDrawList* d, int btn, touched_buttons_t const& pressed
5656
constexpr ImU32 pcol = IM_COL32(150, 150, 150, 150);
5757
constexpr ImU32 col = IM_COL32(100, 100, 100, 70);
5858
constexpr ImU32 outline_col = IM_COL32(50, 50, 50, 150);
59+
constexpr float ROT[4] = { 270, 90, 180, 0 };
60+
float thickness = pixel_ratio * 3.f;
5961
auto r = touch_rect(btn);
60-
float s = 0.1f * (r.x1 - r.x0);
61-
r.x0 += s;
62-
r.y0 += s;
63-
r.x1 -= s;
64-
r.y1 -= s;
65-
float rounding = pixel_ratio * s;
66-
d->AddRectFilled(
67-
{ r.x0, r.y0 }, { r.x1, r.y1 },
68-
pressed.btns[btn] ? pcol : col,
69-
rounding, 0);
70-
d->AddRect(
71-
{ r.x0, r.y0 }, { r.x1, r.y1 },
72-
outline_col,
73-
rounding, 0, 5.f * pixel_ratio);
62+
63+
switch(btn)
64+
{
65+
case TOUCH_U:
66+
case TOUCH_D:
67+
case TOUCH_L:
68+
case TOUCH_R:
69+
{
70+
// bevel
71+
constexpr float B = 0.075f;
72+
constexpr ImVec2 DPAD[] =
73+
{
74+
{ -1.f, +0.f + B },
75+
{ -1.f, +0.f - B },
76+
{ +0.f - B, -1.f },
77+
{ +1.f - B, -1.f },
78+
{ +1.f, -1.f + B },
79+
{ +1.f, +1.f - B },
80+
{ +1.f - B, +1.f },
81+
{ +0.f - B, +1.f },
82+
};
83+
constexpr int N_DPAD = sizeof(DPAD) / sizeof(DPAD[0]);
84+
float rot = ROT[btn] * (3.1415926535f / 180);
85+
float tc = cosf(rot);
86+
float ts = sinf(rot);
87+
float scale = (r.x1 - r.x0) * 0.72f;
88+
r.x0 = (r.x0 + r.x1) * 0.5f;
89+
r.y0 = (r.y0 + r.y1) * 0.5f;
90+
ImVec2 dp[N_DPAD + 2];
91+
for(int i = 0; i < N_DPAD; ++i)
92+
{
93+
dp[i].x = (tc * DPAD[i].x - ts * DPAD[i].y) * scale + r.x0;
94+
dp[i].y = (ts * DPAD[i].x + tc * DPAD[i].y) * scale + r.y0;
95+
}
96+
dp[N_DPAD + 0] = dp[0];
97+
dp[N_DPAD + 1] = dp[1];
98+
d->AddConvexPolyFilled(dp, N_DPAD, pressed.btns[btn] ? pcol : col);
99+
d->AddPolyline(dp, N_DPAD, outline_col, ImDrawFlags_Closed, thickness);
100+
break;
101+
}
102+
case TOUCH_A:
103+
case TOUCH_B:
104+
{
105+
constexpr int SEGMENTS = 32;
106+
float radius = (r.x1 - r.x0) * 0.65f;
107+
r.x0 = (r.x0 + r.x1) * 0.5f;
108+
r.y0 = (r.y0 + r.y1) * 0.5f;
109+
d->AddCircleFilled(
110+
{ r.x0, r.y0 }, radius,
111+
pressed.btns[btn] ? pcol : col,
112+
SEGMENTS);
113+
d->AddCircle(
114+
{ r.x0, r.y0 }, radius,
115+
outline_col,
116+
SEGMENTS,
117+
thickness);
118+
break;
119+
}
120+
default:
121+
break;
122+
}
74123
}
75124

76125
touched_buttons_t touched_buttons()
@@ -92,6 +141,8 @@ touched_buttons_t touched_buttons()
92141

93142
void display_with_scanlines(ImDrawList* d, ImVec2 const& a, ImVec2 const& b)
94143
{
144+
platform_texture_scale_nearest(display_texture);
145+
95146
{
96147
std::array<ImVec2, 4> vs;
97148
vs[0] = {a.x, a.y};

0 commit comments

Comments
 (0)