// Menu quad for questshock's immersive Quest build: MenuOverlay.java's
// off-screen-rendered View tree (currently just a "Keyboard" button - see
// the plan's step D for the on-screen keyboard that goes behind it),
// toggled by xr_input.c's menu_toggle action and hit-tested by the same ray
// xr_input.c already computes per hand.
//
// The menu's content shares xr_session.c's single OpenXR swapchain (see
// that file for why: two independently-created swapchains submitted as
// separate composition layers make the Horizon OS compositor show the
// game's own content on the menu quad instead of the menu's - a
// compositor-level limitation, not anything under this app's control).
// xr_session.c sizes its shared swapchain to fit both the game's and the
// menu's content side by side, and calls into this file to render the
// menu's own sub-rectangle each visible frame.
#ifndef QUESTSHOCK_XR_MENU_H
#define QUESTSHOCK_XR_MENU_H

#include <stdbool.h>

#define XR_USE_PLATFORM_ANDROID 1
#define XR_USE_GRAPHICS_API_OPENGL_ES 1
#include <openxr/openxr.h>

#ifdef __cplusplus
extern "C" {
#endif

// Pixel size of the menu's own content region - xr_session.c needs this
// before it creates its shared swapchain, to size it to fit both the
// game's and the menu's content. Has no OpenXR/GL dependency, safe to call
// before xr_menu_init().
void xr_menu_get_content_size(int *width, int *height);

// Call once, after xr_session.c has created its shared swapchain - sets up
// the MenuOverlay Java-side singleton and the gl4es-owned texture its
// pixels get uploaded into. Returns false (logged, non-fatal - the caller
// just has no menu) on failure.
bool xr_menu_init(XrInstance instance, XrSession session);

// Flips menu-quad visibility - called by xr_input.c on the menu_toggle
// action's rising edge.
void xr_menu_toggle_visible(void);
bool xr_menu_is_visible(void);

// Local-space pose/size of the menu quad, valid regardless of visibility -
// shared with xr_input.c's ray/quad hit-testing, the same way
// xr_get_game_quad_extent() (xr_session.h) is for the game quad.
void xr_menu_get_quad_extent(float *center_x_m, float *center_y_m, float *distance_m,
                              float *half_width_m, float *half_height_m);

// Forwards a hit on the menu quad (in the quad's own 0..1 u/v, top-left
// origin) to the MenuOverlay Java view as a synthetic touch down/up -
// called by xr_input.c on the select_click action's edges, only while a
// hand's aim ray currently hits the menu quad.
void xr_menu_touch(float u, float v, bool down);

// Refreshes MenuOverlay's pixels from Java if they changed since the last
// call, and blits them into whichever framebuffer is currently bound -
// xr_session.c binds its shared swapchain image and sets the
// viewport/scissor to the menu's own sub-rectangle within it before calling
// this. Only called while xr_menu_is_visible().
void xr_menu_render_if_visible(void);

void xr_menu_shutdown(void);

#ifdef __cplusplus
}
#endif

#endif
