mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-03-03 05:06:31 +00:00
t/gui: Add main menu and pure debug scene
This commit is contained in:
parent
387bc123f8
commit
b50415a367
|
@ -22,6 +22,7 @@ set(SOURCE_FILES
|
|||
gui_prober.c
|
||||
gui_scene.cpp
|
||||
gui_scene_debug.c
|
||||
gui_scene_main_menu.c
|
||||
gui_scene_video.c
|
||||
gui_sdl2.c
|
||||
../../../external/glad/gl.h
|
||||
|
|
|
@ -62,6 +62,7 @@ struct program
|
|||
struct xrt_prober *xp;
|
||||
|
||||
struct gui_ogl_texture *texs[256];
|
||||
size_t num_texs;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
@ -70,7 +71,7 @@ struct program
|
|||
struct gui_scene
|
||||
{
|
||||
void (*render)(struct gui_scene *, struct program *);
|
||||
void (*destroy)(struct gui_scene *);
|
||||
void (*destroy)(struct gui_scene *, struct program *);
|
||||
};
|
||||
|
||||
/*!
|
||||
|
@ -141,6 +142,14 @@ gui_sdl2_quit(struct program *p);
|
|||
int
|
||||
gui_prober_init(struct program *p);
|
||||
|
||||
/*!
|
||||
* Create devices.
|
||||
*
|
||||
* @ingroup gui
|
||||
*/
|
||||
int
|
||||
gui_prober_select(struct program *p);
|
||||
|
||||
/*!
|
||||
* Update all devices.
|
||||
*
|
||||
|
@ -225,6 +234,14 @@ gui_scene_manager_destroy(struct program *p);
|
|||
*
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Shows the main menu.
|
||||
*
|
||||
* @ingroup gui
|
||||
*/
|
||||
void
|
||||
gui_scene_main_menu(struct program *p);
|
||||
|
||||
/*!
|
||||
* Shows a UI that lets you select a video device and mode.
|
||||
*
|
||||
|
@ -233,6 +250,14 @@ gui_scene_manager_destroy(struct program *p);
|
|||
void
|
||||
gui_scene_select_video(struct program *p);
|
||||
|
||||
/*!
|
||||
* Regular debug UI.
|
||||
*
|
||||
* @ingroup gui
|
||||
*/
|
||||
void
|
||||
gui_scene_debug(struct program *p);
|
||||
|
||||
/*!
|
||||
* Given the frameserver runs some debug code on it.
|
||||
*
|
||||
|
|
|
@ -33,7 +33,11 @@ main(int argc, char **argv)
|
|||
gui_prober_init(&p);
|
||||
|
||||
// First scene to start with.
|
||||
gui_scene_select_video(&p);
|
||||
if (argc >= 2 && strcmp("debug", argv[1]) == 0) {
|
||||
gui_scene_debug(&p);
|
||||
} else {
|
||||
gui_scene_main_menu(&p);
|
||||
}
|
||||
|
||||
// Main loop.
|
||||
gui_imgui_loop(&p);
|
||||
|
|
|
@ -39,39 +39,29 @@ gui_prober_init(struct program *p)
|
|||
p->timekeeping = time_state_create();
|
||||
|
||||
// Initialize the prober.
|
||||
printf(" :: Creating prober!\n");
|
||||
|
||||
ret = xrt_prober_create(&p->xp);
|
||||
if (ret != 0) {
|
||||
return do_exit(p, ret);
|
||||
}
|
||||
|
||||
// Need to prime the prober with devices before dumping and listing.
|
||||
printf(" :: Probing!\n");
|
||||
|
||||
ret = xrt_prober_probe(p->xp);
|
||||
if (ret != 0) {
|
||||
return do_exit(p, ret);
|
||||
}
|
||||
|
||||
// Multiple devices can be found.
|
||||
printf(" :: Selecting devices!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
gui_prober_select(struct program *p)
|
||||
{
|
||||
int ret;
|
||||
|
||||
// Multiple devices can be found.
|
||||
ret = xrt_prober_select(p->xp, p->xdevs, NUM_XDEVS);
|
||||
if (ret != 0) {
|
||||
do_exit(p, ret);
|
||||
}
|
||||
if (p->xdevs[0] == NULL) {
|
||||
printf("\tNo HMD found! :(\n");
|
||||
return do_exit(p, -1);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < NUM_XDEVS; i++) {
|
||||
if (p->xdevs[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("\tFound '%s'\n", p->xdevs[i]->str);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -73,7 +73,7 @@ gui_scene_manager_render(struct program *p)
|
|||
copy = gsm.del;
|
||||
gsm.del.clear();
|
||||
for (auto scene : copy) {
|
||||
scene->destroy(scene);
|
||||
scene->destroy(scene, p);
|
||||
}
|
||||
|
||||
// If there are no scenes left stop the program.
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "xrt/xrt_frame.h"
|
||||
#include "xrt/xrt_prober.h"
|
||||
#include "xrt/xrt_tracking.h"
|
||||
#include "xrt/xrt_frameserver.h"
|
||||
|
||||
#include "gui_common.h"
|
||||
|
@ -181,7 +182,7 @@ scene_render(struct gui_scene *scene, struct program *p)
|
|||
}
|
||||
|
||||
static void
|
||||
scene_destroy(struct gui_scene *scene)
|
||||
scene_destroy(struct gui_scene *scene, struct program *p)
|
||||
{
|
||||
struct debug_scene *ds = (struct debug_scene *)scene;
|
||||
|
||||
|
@ -241,3 +242,54 @@ gui_scene_debug_video(struct program *p,
|
|||
// Now that we have setup a node graph, start it.
|
||||
xrt_fs_stream_start(xfs, xsink, mode);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
on_root_enter_sink(const char *name, void *priv)
|
||||
{}
|
||||
|
||||
static void
|
||||
on_elem_sink(const char *name, enum u_var_kind kind, void *ptr, void *priv)
|
||||
{
|
||||
struct program *p = (struct program *)priv;
|
||||
|
||||
if (kind != U_VAR_KIND_SINK) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (p->xp->tracking == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct xrt_frame_context *xfctx = p->xp->tracking->xfctx;
|
||||
struct xrt_frame_sink **xsink_ptr = (struct xrt_frame_sink **)ptr;
|
||||
struct xrt_frame_sink *split = NULL;
|
||||
|
||||
|
||||
p->texs[p->num_texs++] = gui_ogl_sink_create(name, xfctx, &split);
|
||||
|
||||
if (*xsink_ptr != NULL) {
|
||||
u_sink_split_create(xfctx, split, *xsink_ptr, xsink_ptr);
|
||||
} else {
|
||||
*xsink_ptr = split;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_root_exit_sink(const char *name, void *priv)
|
||||
{}
|
||||
|
||||
void
|
||||
gui_scene_debug(struct program *p)
|
||||
{
|
||||
struct debug_scene *ds = U_TYPED_CALLOC(struct debug_scene);
|
||||
|
||||
ds->base.render = scene_render;
|
||||
ds->base.destroy = scene_destroy;
|
||||
|
||||
gui_scene_push_front(p, &ds->base);
|
||||
|
||||
gui_prober_select(p);
|
||||
|
||||
u_var_visit(on_root_enter_sink, on_root_exit_sink, on_elem_sink, p);
|
||||
}
|
||||
|
|
67
src/xrt/targets/gui/gui_scene_main_menu.c
Normal file
67
src/xrt/targets/gui/gui_scene_main_menu.c
Normal file
|
@ -0,0 +1,67 @@
|
|||
// Copyright 2019, Collabora, Ltd.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
* @brief Main menu.
|
||||
* @author Jakob Bornecrantz <jakob@collabora.com>
|
||||
* @ingroup gui
|
||||
*/
|
||||
|
||||
#include "util/u_misc.h"
|
||||
|
||||
#include "gui_common.h"
|
||||
#include "gui_imgui.h"
|
||||
|
||||
|
||||
static ImVec2 button_dims = {256, 0};
|
||||
|
||||
struct main_menu
|
||||
{
|
||||
struct gui_scene base;
|
||||
};
|
||||
|
||||
static void
|
||||
scene_render(struct gui_scene *scene, struct program *p)
|
||||
{
|
||||
igBegin("Main Meun", NULL, 0);
|
||||
|
||||
if (igButton("Debug", button_dims)) {
|
||||
gui_scene_delete_me(p, scene);
|
||||
gui_scene_debug(p);
|
||||
}
|
||||
|
||||
if (igButton("Select Video", button_dims)) {
|
||||
gui_scene_delete_me(p, scene);
|
||||
gui_scene_select_video(p);
|
||||
}
|
||||
|
||||
if (igButton("Exit", button_dims)) {
|
||||
gui_scene_delete_me(p, scene);
|
||||
}
|
||||
|
||||
igEnd();
|
||||
}
|
||||
|
||||
static void
|
||||
scene_destroy(struct gui_scene *scene, struct program *p)
|
||||
{
|
||||
free(scene);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* 'Exported' functions.
|
||||
*
|
||||
*/
|
||||
|
||||
void
|
||||
gui_scene_main_menu(struct program *p)
|
||||
{
|
||||
struct main_menu *mm = U_TYPED_CALLOC(struct main_menu);
|
||||
|
||||
mm->base.render = scene_render;
|
||||
mm->base.destroy = scene_destroy;
|
||||
|
||||
gui_scene_push_front(p, &mm->base);
|
||||
}
|
|
@ -110,7 +110,7 @@ scene_render(struct gui_scene *scene, struct program *p)
|
|||
}
|
||||
|
||||
static void
|
||||
scene_destroy(struct gui_scene *scene)
|
||||
scene_destroy(struct gui_scene *scene, struct program *p)
|
||||
{
|
||||
struct video_select *vs = (struct video_select *)scene;
|
||||
|
||||
|
|
Loading…
Reference in a new issue