d/qwerty: Implement select and menu click inputs

This commit is contained in:
Mateo de Mayo 2021-03-11 17:23:17 -03:00
parent 582a287dd4
commit 4ea696bfdd
3 changed files with 52 additions and 1 deletions

View file

@ -93,7 +93,24 @@ qwerty_controller(struct xrt_device *xd)
static void
qwerty_update_inputs(struct xrt_device *xd)
{
return;
if (xd->name != XRT_DEVICE_SIMPLE_CONTROLLER) {
return;
}
struct qwerty_controller *qc = qwerty_controller(xd);
struct qwerty_device *qd = &qc->base;
xd->inputs[QWERTY_SELECT].value.boolean = qc->select_clicked;
if (qc->select_clicked) {
QWERTY_INFO(qd, "[%s] Select click", xd->str);
qc->select_clicked = false;
}
xd->inputs[QWERTY_MENU].value.boolean = qc->menu_clicked;
if (qc->menu_clicked) {
QWERTY_INFO(qd, "[%s] Menu click", xd->str);
qc->menu_clicked = false;
}
}
static void
@ -237,6 +254,8 @@ qwerty_controller_create(bool is_left, struct qwerty_hmd *qhmd)
{
struct qwerty_controller *qc = U_DEVICE_ALLOCATE(struct qwerty_controller, U_DEVICE_ALLOC_TRACKING_NONE, 4, 1);
assert(qc);
qc->select_clicked = false;
qc->menu_clicked = false;
struct qwerty_device *qd = &qc->base;
qd->pose.orientation.w = 1.f;
@ -318,6 +337,8 @@ qwerty_setup_var_tracking(struct qwerty_system *qs)
u_var_add_ro_text(qs, "Hold for movement speed", "LSHIFT");
u_var_add_ro_text(qs, "Modify FD movement speed", "Mouse wheel");
u_var_add_ro_text(qs, "Modify FD movement speed", "Numpad +/-");
u_var_add_ro_text(qs, "FC Select click", "Left Click");
u_var_add_ro_text(qs, "FC Menu click", "Middle Click");
}
struct qwerty_system *
@ -442,3 +463,10 @@ qwerty_release_all(struct qwerty_device *qd)
qd->yaw_delta = 0;
qd->pitch_delta = 0;
}
// Controller methods
// clang-format off
void qwerty_select_click(struct qwerty_controller *qc) { qc->select_clicked = true; }
void qwerty_menu_click(struct qwerty_controller *qc) { qc->menu_clicked = true; }
// clang-format on

View file

@ -73,10 +73,14 @@ struct qwerty_hmd
struct qwerty_device base;
};
//! Supports input actions
//! @implements qwerty_device
struct qwerty_controller
{
struct qwerty_device base;
bool select_clicked;
bool menu_clicked;
};
/*!
@ -192,6 +196,14 @@ qwerty_controller_create(bool is_left, struct qwerty_hmd *qhmd);
struct qwerty_controller *
qwerty_controller(struct xrt_device *xd);
//! Simulate input/select/click
void
qwerty_select_click(struct qwerty_controller *qc);
//! Simulate input/menu/click
void
qwerty_menu_click(struct qwerty_controller *qc);
/*!
* @}
*/

View file

@ -123,6 +123,12 @@ qwerty_process_event(struct xrt_device **xdevs, size_t num_xdevs, SDL_Event even
else if (alt_pressed) qdev = qd_right;
else qdev = default_qdev;
// Default focused controller
struct qwerty_controller *default_qctrl = qright; // @todo: set this based on user devices
// Determine focused controller for qwerty_controller specific methods
struct qwerty_controller *qctrl = qdev != qd_hmd ? qwerty_controller(&qdev->base) : default_qctrl;
// Update gui tracked variables
qsys->hmd_focused = qdev == qd_hmd;
qsys->lctrl_focused = qdev == qd_left;
@ -171,5 +177,10 @@ qwerty_process_event(struct xrt_device **xdevs, size_t num_xdevs, SDL_Event even
float pitch = -event.motion.yrel * SENSITIVITY;
qwerty_add_look_delta(qdev, yaw, pitch);
}
// Select and menu clicks only for controllers.
if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) qwerty_select_click(qctrl);
if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_MIDDLE) qwerty_menu_click(qctrl);
// clang-format on
}