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;
}