Add virtual touch buttons for Monopoly game and centralize configuration in ModalButtonHelper

This commit is contained in:
Adolfo Reyna
2026-02-06 22:11:24 -05:00
parent eb86c3fc0e
commit e2817262b0
11 changed files with 194 additions and 8 deletions

View File

@@ -93,6 +93,14 @@ InputEvent InputManager::process_touch_input(uint32_t* last_time) {
// Determine event type
if (*last_time == 0) {
event.type = INPUT_TOUCH_DOWN;
// Check for virtual buttons
InputType virtual_type;
if (check_virtual_buttons(event.x, event.y, virtual_type)) {
event.type = virtual_type;
event.button_id = (virtual_type == INPUT_BUTTON_0) ? 0 : 1;
printf("Virtual button %d pressed via touch\n", event.button_id);
}
} else {
event.type = INPUT_TOUCH_MOVE;
}
@@ -164,3 +172,38 @@ const char* InputManager::get_gesture_name(uint8_t gesture_code) {
default: return "Unknown";
}
}
void InputManager::get_virtual_button_regions(int* a_rect, int* b_rect) const {
for (int i = 0; i < 4; i++) {
a_rect[i] = v_button_a[i];
b_rect[i] = v_button_b[i];
}
}
void InputManager::set_virtual_button_regions(int ax, int ay, int aw, int ah, int bx, int by, int bw, int bh) {
v_button_a[0] = ax; v_button_a[1] = ay; v_button_a[2] = aw; v_button_a[3] = ah;
v_button_b[0] = bx; v_button_b[1] = by; v_button_b[2] = bw; v_button_b[3] = bh;
v_buttons_active = true;
}
void InputManager::clear_virtual_button_regions() {
v_buttons_active = false;
}
bool InputManager::check_virtual_buttons(int16_t x, int16_t y, InputType& out_type) const {
if (!v_buttons_active) return false;
if (x >= v_button_a[0] && x <= v_button_a[0] + v_button_a[2] &&
y >= v_button_a[1] && y <= v_button_a[1] + v_button_a[3]) {
out_type = INPUT_BUTTON_0;
return true;
}
if (x >= v_button_b[0] && x <= v_button_b[0] + v_button_b[2] &&
y >= v_button_b[1] && y <= v_button_b[1] + v_button_b[3]) {
out_type = INPUT_BUTTON_1;
return true;
}
return false;
}

View File

@@ -48,6 +48,32 @@ public:
* @return InputEvent (valid=false if no valid input)
*/
InputEvent process_button_input();
/**
* @brief Get virtual button regions for drawing
* @param a_rect Pointer to rectangle for Button A [x, y, w, h]
* @param b_rect Pointer to rectangle for Button B [x, y, w, h]
*/
void get_virtual_button_regions(int* a_rect, int* b_rect) const;
/**
* @brief Set virtual button regions
*/
void set_virtual_button_regions(int ax, int ay, int aw, int ah, int bx, int by, int bw, int bh);
/**
* @brief Clear virtual button regions (disables detection)
*/
void clear_virtual_button_regions();
/**
* @brief Check if a touch event hits a virtual button
* @param x Touch X coordinate
* @param y Touch Y coordinate
* @param out_type Output parameter for the button type if hit
* @return true if a virtual button was hit
*/
bool check_virtual_buttons(int16_t x, int16_t y, InputType& out_type) const;
/**
* @brief Get human-readable gesture name
@@ -71,6 +97,11 @@ public:
private:
LowLevelTouch* touch;
const GameConfig* config;
// Virtual button regions
int v_button_a[4] = {0, 0, 0, 0}; // [x, y, w, h]
int v_button_b[4] = {0, 0, 0, 0};
bool v_buttons_active = false;
};
#endif // INPUT_MANAGER_H