forked from crosspoint-reader/crosspoint-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMappedInputManager.h
More file actions
106 lines (94 loc) · 4.57 KB
/
Copy pathMappedInputManager.h
File metadata and controls
106 lines (94 loc) · 4.57 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#pragma once
#include <HalGPIO.h>
class GfxRenderer;
class MappedInputManager {
public:
enum class Button {
Back,
Confirm,
Left,
Right,
Up,
Down,
Power,
PageBack,
PageForward,
NavNext,
NavPrevious,
ScreenLeft,
ScreenRight,
ScreenUp,
ScreenDown
};
enum class SwipeDir { None, Left, Right, Up, Down };
struct Labels {
const char* btn1;
const char* btn2;
const char* btn3;
const char* btn4;
};
MappedInputManager(HalGPIO& gpio, const GfxRenderer& renderer) : gpio(gpio), renderer(renderer) {}
void update() const { gpio.update(); }
bool wasPressed(Button button) const;
bool wasReleased(Button button) const;
bool isPressed(Button button) const;
bool hasTouch() const;
bool wasScreenTapped(int& x, int& y) const;
bool wasScreenTouchDown(int& x, int& y) const;
bool isScreenTouchHeld(int& x, int& y) const;
bool wasTapInRect(int x, int y, int width, int height) const;
bool wasListItemTapped(int& index, int itemCount, int selectedIndex, int listTop, int listHeight,
bool hasSubtitle) const;
bool wasListItemTouchedDown(int& index, int itemCount, int selectedIndex, int listTop, int listHeight,
bool hasSubtitle) const;
// Combined touch interaction for a band of equal rows with caller-supplied
// geometry — the shared hit-test for lists the theme helpers above do not
// cover (custom row heights, option prompts, menus). Down = a held
// tap-candidate is on a row (update the selection highlight); Tap = a tap
// released on one (activate). rowHeight limits the hit to the top rowHeight
// px of each step (0 = the full step, no gap band).
enum class RowTouch : uint8_t { None, Down, Tap };
RowTouch rowTouch(int& row, int top, int rowStep, int rowCount, int xStart = 0, int xEnd = INT32_MAX,
int rowHeight = 0) const;
// Horizontal variant for side-by-side button pairs (confirmation prompts).
RowTouch colTouch(int& col, int left, int colStep, int colCount, int yStart, int yEnd, int colWidth = 0) const;
SwipeDir wasSwipe() const;
bool wasHomeGesture() const;
bool wasMenuGesture() const;
bool wasAnyPressed() const;
bool wasAnyReleased() const;
unsigned long getHeldTime() const;
const GfxRenderer& getRenderer() const { return renderer; }
Labels mapLabels(const char* back, const char* confirm, const char* previous, const char* next) const;
// Maps four screen-direction labels onto the two physical front-button roles
// using the same live-orientation transform as ScreenLeft/Right/Up/Down.
Labels mapDirectionalLabels(const char* back, const char* confirm, const char* left, const char* right,
const char* up, const char* down) const;
// Returns the raw front button index that was pressed this frame (or -1 if none).
int getPressedFrontButton() const;
// True when the control axis is flipped relative to the physical buttons: the user opted into
// orientation-following front buttons AND the screen is *currently rendered* rotated (INVERTED /
// LANDSCAPE_CCW). Keyed on the live renderer orientation rather than the persisted reader setting,
// so portrait UI (home, settings) never swaps while the reader and its menus do.
[[nodiscard]] bool isNavDirectionSwapped() const;
private:
HalGPIO& gpio;
// Logical-to-physical button mapping depends on what the user is actually looking at: when the
// screen is rendered rotated, the directional buttons must flip to match. The renderer is the only
// authority on the *live* orientation (the reader rotates it and restores portrait on exit), so we
// read it here instead of CrossPointSettings.orientation, which is just the persisted reader
// preference and stays "rotated" even while portrait UI like home/settings is on screen.
const GfxRenderer& renderer;
Button mapScreenDirection(Button button) const;
Labels mapFrontLabels(const char* back, const char* confirm, const char* left, const char* right) const;
bool mapButton(Button button, bool (HalGPIO::*fn)(uint8_t) const) const;
bool wasBackGesture() const;
// Fetch the pending swipe (if any) and map both endpoints to logical screen coords
bool decodeSwipe(int& sx, int& sy, int& ex, int& ey) const;
bool listItemFromPoint(int x, int y, int& index, int itemCount, int selectedIndex, int listTop, int listHeight,
bool hasSubtitle) const;
void rememberTouchHeldTime() const;
mutable bool touchHeldOverrideValid = false;
mutable unsigned long touchHeldOverrideMs = 0;
mutable unsigned long touchHeldOverrideAt = 0;
};