mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-04-08 02:12:17 +00:00
[ruamoko] Add bindings for imui
Things are a little clunky, but I've got a little window I can manipulate in my test scene :)
This commit is contained in:
parent
866cdcf068
commit
4483368319
9 changed files with 684 additions and 4 deletions
|
@ -61,6 +61,7 @@ QFile *QFile_GetFile (struct progs_s *pr, int handle);
|
|||
struct plitem_s *Plist_GetItem (struct progs_s *pr, int handle);
|
||||
|
||||
void RUA_GUI_Init (struct progs_s *pr, int secure);
|
||||
void RUA_IMUI_Init (struct progs_s *pr, int secure);
|
||||
void RUA_Input_Init (struct progs_s *pr, int secure);
|
||||
void RUA_Mersenne_Init (struct progs_s *pr, int secure);
|
||||
void RUA_Model_Init (struct progs_s *pr, int secure);
|
||||
|
|
|
@ -39,6 +39,7 @@ libs_ruamoko_libQFruamoko_client_la_DEPENDENCIES= \
|
|||
libs_ruamoko_libQFruamoko_client_la_SOURCES= \
|
||||
libs/ruamoko/rua_game_init.c \
|
||||
libs/ruamoko/rua_gui.c \
|
||||
libs/ruamoko/rua_imui.c \
|
||||
libs/ruamoko/rua_input.c \
|
||||
libs/ruamoko/rua_mersenne.c \
|
||||
libs/ruamoko/rua_model.c \
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
static void (*init_funcs[])(progs_t *, int) = {
|
||||
RUA_GUI_Init,
|
||||
RUA_IMUI_Init,
|
||||
RUA_Input_Init,
|
||||
RUA_Mersenne_Init,
|
||||
RUA_Model_Init,
|
||||
|
|
465
libs/ruamoko/rua_imui.c
Normal file
465
libs/ruamoko/rua_imui.c
Normal file
|
@ -0,0 +1,465 @@
|
|||
/*
|
||||
r_imui.c
|
||||
|
||||
Ruamoko IMUI support functions
|
||||
|
||||
Copyright (C) 2023 Bill Currie <bill@taniwha.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "QF/dstring.h"
|
||||
#include "QF/progs.h"
|
||||
|
||||
#include "QF/ui/canvas.h"
|
||||
#include "QF/ui/imui.h"
|
||||
#include "QF/ui/passage.h"
|
||||
|
||||
#include "rua_internal.h"
|
||||
|
||||
typedef struct bi_imui_ctx_s {
|
||||
struct bi_imui_ctx_s *next;
|
||||
struct bi_imui_ctx_s **prev;
|
||||
imui_ctx_t *imui_ctx;
|
||||
} bi_imui_ctx_t;
|
||||
|
||||
typedef struct {
|
||||
progs_t *pr;
|
||||
ecs_registry_t *reg;
|
||||
canvas_system_t canvas_sys;
|
||||
uint32_t passage_base;
|
||||
|
||||
PR_RESMAP (bi_imui_ctx_t) imui_ctx_map;
|
||||
bi_imui_ctx_t *imui_ctxs;
|
||||
dstring_t *dstr;
|
||||
} imui_resources_t;
|
||||
|
||||
static bi_imui_ctx_t *
|
||||
imui_ctx_new (imui_resources_t *res)
|
||||
{
|
||||
return PR_RESNEW (res->imui_ctx_map);
|
||||
}
|
||||
|
||||
static void
|
||||
imui_ctx_free (imui_resources_t *res, bi_imui_ctx_t *imui_ctx)
|
||||
{
|
||||
PR_RESFREE (res->imui_ctx_map, imui_ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
imui_ctx_reset (imui_resources_t *res)
|
||||
{
|
||||
PR_RESRESET (res->imui_ctx_map);
|
||||
}
|
||||
|
||||
static inline bi_imui_ctx_t *
|
||||
imui_ctx_get (imui_resources_t *res, int index)
|
||||
{
|
||||
return PR_RESGET(res->imui_ctx_map, index);
|
||||
}
|
||||
|
||||
static inline int __attribute__((pure))
|
||||
imui_ctx_index (imui_resources_t *res, bi_imui_ctx_t *imui_ctx)
|
||||
{
|
||||
return PR_RESINDEX(res->imui_ctx_map, imui_ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_imui_clear (progs_t *pr, void *_res)
|
||||
{
|
||||
imui_resources_t *res = _res;
|
||||
|
||||
for (auto bi_ctx = res->imui_ctxs; bi_ctx; bi_ctx = bi_ctx->next) {
|
||||
IMUI_DestroyContext (bi_ctx->imui_ctx);
|
||||
}
|
||||
res->imui_ctxs = 0;
|
||||
imui_ctx_reset (res);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_imui_destroy (progs_t *pr, void *_res)
|
||||
{
|
||||
imui_resources_t *res = _res;
|
||||
PR_RESDELMAP (res->imui_ctx_map);
|
||||
dstring_delete (res->dstr);
|
||||
free (res);
|
||||
}
|
||||
|
||||
#define bi(x) static void bi_##x (progs_t *pr, void *_res)
|
||||
|
||||
bi(IMUI_NewWindow)
|
||||
{
|
||||
const char *name = P_GSTRING (pr, 0);
|
||||
|
||||
imui_window_t *window = PR_Zone_Malloc (pr, sizeof (imui_window_t));
|
||||
*window = (imui_window_t) {
|
||||
.name = name,
|
||||
.is_open = true,
|
||||
};
|
||||
RETURN_POINTER (pr, window);
|
||||
}
|
||||
|
||||
bi(IMUI_DeleteWindow)
|
||||
{
|
||||
auto window = (imui_window_t *) P_GPOINTER (pr, 0);
|
||||
PR_Zone_Free (pr, window);
|
||||
}
|
||||
|
||||
bi(IMUI_Window_IsOpen)
|
||||
{
|
||||
auto window = (imui_window_t *) P_GPOINTER (pr, 0);
|
||||
R_INT (pr) = window->is_open;
|
||||
}
|
||||
|
||||
bi(IMUI_Window_IsCollapsed)
|
||||
{
|
||||
auto window = (imui_window_t *) P_GPOINTER (pr, 0);
|
||||
R_INT (pr) = window->is_collapsed;
|
||||
}
|
||||
|
||||
bi(IMUI_NewContext)
|
||||
{
|
||||
imui_resources_t *res = _res;
|
||||
const char *font = P_GSTRING (pr, 0);
|
||||
float font_size = P_FLOAT (pr, 1);
|
||||
|
||||
auto bi_ctx = imui_ctx_new (res);
|
||||
bi_ctx->imui_ctx = IMUI_NewContext (res->canvas_sys, font, font_size);
|
||||
|
||||
bi_ctx->next = res->imui_ctxs;
|
||||
bi_ctx->prev = &res->imui_ctxs;
|
||||
if (res->imui_ctxs) {
|
||||
res->imui_ctxs->prev = &bi_ctx->next;
|
||||
}
|
||||
res->imui_ctxs = bi_ctx;
|
||||
|
||||
R_INT (pr) = imui_ctx_index (res, bi_ctx);
|
||||
}
|
||||
|
||||
static bi_imui_ctx_t *__attribute__((pure))
|
||||
_get_imui_ctx (imui_resources_t *res, const char *name, int index)
|
||||
{
|
||||
auto bi_ctx = imui_ctx_get (res, index);
|
||||
|
||||
if (!bi_ctx) {
|
||||
PR_RunError (res->pr, "invalid imui context index passed to %s",
|
||||
name + 3);
|
||||
}
|
||||
return bi_ctx;
|
||||
}
|
||||
#define get_imui_ctx(index) _get_imui_ctx(res,__FUNCTION__,index)
|
||||
|
||||
bi(IMUI_DestroyContext)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_DestroyContext (bi_ctx->imui_ctx);
|
||||
*bi_ctx->prev = bi_ctx->next;
|
||||
if (bi_ctx->next) {
|
||||
bi_ctx->next->prev = bi_ctx->prev;
|
||||
}
|
||||
imui_ctx_free (res, bi_ctx);
|
||||
}
|
||||
|
||||
bi (IMUI_SetVisible)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_SetVisible (bi_ctx->imui_ctx, P_INT (pr, 1));
|
||||
}
|
||||
|
||||
bi (IMUI_SetSize)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_SetSize (bi_ctx->imui_ctx, P_INT (pr, 1), P_INT (pr, 2));
|
||||
}
|
||||
|
||||
bi (IMUI_ProcessEvent)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
auto ie_event = (struct IE_event_s *) P_GPOINTER (pr, 1);
|
||||
IMUI_ProcessEvent (bi_ctx->imui_ctx, ie_event);
|
||||
}
|
||||
|
||||
bi (IMUI_BeginFrame)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_BeginFrame (bi_ctx->imui_ctx);
|
||||
}
|
||||
|
||||
bi (IMUI_Draw)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_Draw (bi_ctx->imui_ctx);
|
||||
Canvas_Draw (res->canvas_sys);
|
||||
}
|
||||
|
||||
bi (IMUI_PushLayout)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
R_INT (pr) = IMUI_PushLayout (bi_ctx->imui_ctx, P_INT (pr, 1));
|
||||
}
|
||||
|
||||
bi (IMUI_PopLayout)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_PopLayout (bi_ctx->imui_ctx);
|
||||
}
|
||||
|
||||
bi (IMUI_Layout_SetXSize)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_Layout_SetXSize (bi_ctx->imui_ctx, P_INT (pr, 1), P_INT (pr, 2));
|
||||
}
|
||||
|
||||
bi (IMUI_Layout_SetYSize)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_Layout_SetYSize (bi_ctx->imui_ctx, P_INT (pr, 1), P_INT (pr, 2));
|
||||
}
|
||||
|
||||
bi (IMUI_PushStyle)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
R_INT (pr) = IMUI_PushStyle (bi_ctx->imui_ctx,
|
||||
&P_PACKED (pr, imui_style_t, 1));
|
||||
}
|
||||
|
||||
bi (IMUI_PopStyle)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_PopStyle (bi_ctx->imui_ctx);
|
||||
}
|
||||
|
||||
bi (IMUI_Style_Update)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_Style_Update (bi_ctx->imui_ctx, (imui_style_t *) P_GPOINTER (pr, 1));
|
||||
}
|
||||
|
||||
bi (IMUI_Style_Fetch)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_Style_Fetch (bi_ctx->imui_ctx, (imui_style_t *) P_GPOINTER (pr, 1));
|
||||
}
|
||||
|
||||
bi (IMUI_Label)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_Label (bi_ctx->imui_ctx, P_GSTRING (pr, 1));
|
||||
}
|
||||
|
||||
bi (IMUI_Labelf)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
RUA_Sprintf (pr, res->dstr, "IMUI_Labelf", 1);
|
||||
IMUI_Label (bi_ctx->imui_ctx, res->dstr->str);
|
||||
}
|
||||
|
||||
bi (IMUI_Button)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_Button (bi_ctx->imui_ctx, P_GSTRING (pr, 1));
|
||||
}
|
||||
|
||||
bi (IMUI_Checkbox)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
bool flag = *(bool *) P_GPOINTER (pr, 1);
|
||||
IMUI_Checkbox (bi_ctx->imui_ctx, &flag, P_GSTRING (pr, 2));
|
||||
*(bool *) P_GPOINTER (pr, 1) = flag;
|
||||
}
|
||||
|
||||
bi (IMUI_Radio)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_Radio (bi_ctx->imui_ctx, (int *) P_GPOINTER (pr, 1), P_INT (pr, 2),
|
||||
P_GSTRING (pr, 3));
|
||||
}
|
||||
|
||||
bi (IMUI_Slider)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_Slider (bi_ctx->imui_ctx, (float *) P_GPOINTER (pr, 1),
|
||||
P_FLOAT (pr, 2), P_FLOAT (pr, 3), P_GSTRING (pr, 4));
|
||||
}
|
||||
|
||||
bi (IMUI_Spacer)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_Spacer (bi_ctx->imui_ctx, P_INT (pr, 1), P_INT (pr, 2),
|
||||
P_INT (pr, 3), P_INT (pr, 4));
|
||||
}
|
||||
|
||||
bi (IMUI_FlexibleSpace)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
//IMUI_FlexibleSpace (bi_ctx->imui_ctx);
|
||||
IMUI_Spacer(bi_ctx->imui_ctx, imui_size_expand, 100, imui_size_expand, 100);
|
||||
}
|
||||
|
||||
bi (IMUI_StartPanel)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
R_INT (pr) = IMUI_StartPanel (bi_ctx->imui_ctx,
|
||||
&P_PACKED (pr, imui_window_t, 1));
|
||||
}
|
||||
|
||||
bi (IMUI_ExtendPanel)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
R_INT (pr) = IMUI_ExtendPanel (bi_ctx->imui_ctx, P_GSTRING (pr, 1));
|
||||
}
|
||||
|
||||
bi (IMUI_EndPanel)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_EndPanel (bi_ctx->imui_ctx);
|
||||
}
|
||||
|
||||
bi (IMUI_StartMenu)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
R_INT (pr) = IMUI_StartMenu (bi_ctx->imui_ctx,
|
||||
&P_PACKED (pr, imui_window_t, 1),
|
||||
P_INT (pr, 2));
|
||||
}
|
||||
|
||||
bi (IMUI_EndMenu)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_EndMenu (bi_ctx->imui_ctx);
|
||||
}
|
||||
|
||||
bi (IMUI_MenuItem)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
R_INT (pr) = IMUI_MenuItem (bi_ctx->imui_ctx, P_GSTRING (pr, 1),
|
||||
P_INT (pr, 2));
|
||||
}
|
||||
|
||||
bi (IMUI_StartWindow)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
auto window = (imui_window_t *) P_GPOINTER (pr, 1);
|
||||
R_INT (pr) = IMUI_StartWindow (bi_ctx->imui_ctx, window);
|
||||
}
|
||||
|
||||
bi (IMUI_EndWindow)
|
||||
{
|
||||
auto res = (imui_resources_t *) _res;
|
||||
auto bi_ctx = get_imui_ctx (P_INT (pr, 0));
|
||||
IMUI_EndWindow (bi_ctx->imui_ctx);
|
||||
}
|
||||
|
||||
#undef bi
|
||||
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}
|
||||
#define p(type) PR_PARAM(type)
|
||||
#define P(a, s) { .size = (s), .alignment = BITOP_LOG2 (a), }
|
||||
static builtin_t builtins[] = {
|
||||
bi(IMUI_NewWindow, 1, p(string)),
|
||||
bi(IMUI_DeleteWindow, 1, p(ptr)),
|
||||
bi(IMUI_Window_IsOpen, 1, p(ptr)),
|
||||
bi(IMUI_Window_IsCollapsed, 1, p(ptr)),
|
||||
|
||||
bi(IMUI_NewContext, 2, p(string), p(float)),
|
||||
bi(IMUI_DestroyContext, 2, p(int)),
|
||||
bi(IMUI_SetVisible, 2, p(int), p(int)),
|
||||
bi(IMUI_SetSize, 3, p(int), p(int), p(int)),
|
||||
bi(IMUI_ProcessEvent, 3, p(int), p(ptr)),
|
||||
bi(IMUI_BeginFrame, 1, p(int)),
|
||||
bi(IMUI_Draw, 1, p(int)),
|
||||
bi(IMUI_PushLayout, 2, p(int), p(int)),
|
||||
bi(IMUI_PopLayout, 1, p(int)),
|
||||
bi(IMUI_Layout_SetXSize, 3, p(int), p(int), p(int)),
|
||||
bi(IMUI_Layout_SetYSize, 3, p(int), p(int), p(int)),
|
||||
bi(IMUI_PushStyle, 2, p(int), p(ptr)),
|
||||
bi(IMUI_PopStyle, 1, p(int)),
|
||||
bi(IMUI_Style_Update, 2, p(int), p(ptr)),
|
||||
bi(IMUI_Style_Fetch, 2, p(int), p(ptr)),
|
||||
bi(IMUI_Label, 2, p(int), p(string)),
|
||||
bi(IMUI_Labelf, -3, p(int), p(string)),
|
||||
bi(IMUI_Button, 2, p(int), p(string)),
|
||||
bi(IMUI_Checkbox, 3, p(int), p(ptr), p(string)),
|
||||
bi(IMUI_Radio, 4, p(int), p(ptr), p(int), p(string)),
|
||||
bi(IMUI_Slider, 5, p(int), p(ptr), p(float), p(float), p(string)),
|
||||
bi(IMUI_Spacer, 5, p(int), p(int), p(int), p(int), p(int)),
|
||||
bi(IMUI_FlexibleSpace, 1, p(int)),
|
||||
bi(IMUI_StartPanel, 3, p(int), p(ptr)),
|
||||
bi(IMUI_ExtendPanel, 3, p(int), p(string)),
|
||||
bi(IMUI_EndPanel, 1, p(int)),
|
||||
bi(IMUI_StartMenu, 3, p(int), p(ptr), p(int)),
|
||||
bi(IMUI_EndMenu, 1, p(int)),
|
||||
bi(IMUI_MenuItem, 3, p(int), p(string), p(int)),
|
||||
bi(IMUI_StartWindow, 3, p(int), p(ptr)),
|
||||
bi(IMUI_EndWindow, 1, p(int)),
|
||||
|
||||
{0}
|
||||
};
|
||||
|
||||
void
|
||||
RUA_IMUI_Init (progs_t *pr, int secure)
|
||||
{
|
||||
imui_resources_t *res = calloc (1, sizeof (imui_resources_t));
|
||||
res->pr = pr;
|
||||
|
||||
PR_Resources_Register (pr, "IMUI", res, bi_imui_clear, bi_imui_destroy);
|
||||
PR_RegisterBuiltins (pr, builtins, res);
|
||||
|
||||
res->reg = ECS_NewRegistry ();
|
||||
Canvas_InitSys (&res->canvas_sys, res->reg);
|
||||
res->passage_base = ECS_RegisterComponents (res->reg, passage_components,
|
||||
passage_comp_count);
|
||||
ECS_CreateComponentPools (res->reg);
|
||||
res->dstr = dstring_new ();
|
||||
}
|
|
@ -2,6 +2,7 @@ ruamoko_include = \
|
|||
ruamoko/include/crudefile.h \
|
||||
ruamoko/include/debug.h \
|
||||
ruamoko/include/entities.h \
|
||||
ruamoko/include/imui.h \
|
||||
ruamoko/include/infokey.h \
|
||||
ruamoko/include/input.h \
|
||||
ruamoko/include/math.h \
|
||||
|
|
143
ruamoko/include/imui.h
Normal file
143
ruamoko/include/imui.h
Normal file
|
@ -0,0 +1,143 @@
|
|||
#ifndef __ruamoko_imui_h
|
||||
#define __ruamoko_imui_h
|
||||
|
||||
typedef @handle imui_ctx_h imui_ctx_t;
|
||||
|
||||
typedef enum {
|
||||
imui_size_none,
|
||||
imui_size_pixels,
|
||||
imui_size_fittext,
|
||||
imui_size_percent,
|
||||
imui_size_fitchildren,
|
||||
imui_size_expand,
|
||||
} imui_size_t;
|
||||
|
||||
typedef union imui_color_s {
|
||||
struct {
|
||||
unsigned normal;
|
||||
unsigned hot;
|
||||
unsigned active;
|
||||
};
|
||||
unsigned color[3];
|
||||
} imui_color_t;
|
||||
|
||||
typedef struct imui_style_s {
|
||||
imui_color_t background;
|
||||
imui_color_t foreground;
|
||||
imui_color_t text;
|
||||
} imui_style_t;
|
||||
|
||||
typedef struct imui_reference_s {
|
||||
unsigned ref_id;
|
||||
} imui_reference_t;
|
||||
|
||||
// opaque due to having C pointers, but allocated in progs space
|
||||
typedef struct imui_window_s imui_window_t;
|
||||
|
||||
imui_window_t *IMUI_NewWindow (string name);
|
||||
void IMUI_DeleteWindow (imui_window_t *window);
|
||||
int IMUI_Window_IsOpen (imui_window_t *window);
|
||||
int IMUI_Window_IsCollapsed (imui_window_t *window);
|
||||
|
||||
imui_ctx_t IMUI_NewContext (string font, float fontsize);
|
||||
void IMUI_DestroyContext (imui_ctx_t ctx);
|
||||
|
||||
void IMUI_SetVisible (imui_ctx_t ctx, int visible);
|
||||
void IMUI_SetSize (imui_ctx_t ctx, int xlen, int ylen);
|
||||
/*bool*/int IMUI_ProcessEvent (imui_ctx_t ctx, /*const*/ struct IE_event_s *ie_event);
|
||||
void IMUI_BeginFrame (imui_ctx_t ctx);
|
||||
void IMUI_Draw (imui_ctx_t ctx);
|
||||
|
||||
int IMUI_PushLayout (imui_ctx_t ctx, int vertical);
|
||||
void IMUI_PopLayout (imui_ctx_t ctx);
|
||||
void IMUI_Layout_SetXSize (imui_ctx_t ctx, imui_size_t size, int value);
|
||||
void IMUI_Layout_SetYSize (imui_ctx_t ctx, imui_size_t size, int value);
|
||||
|
||||
int IMUI_PushStyle (imui_ctx_t ctx, imui_style_t *style);
|
||||
void IMUI_PopStyle (imui_ctx_t ctx);
|
||||
void IMUI_Style_Update (imui_ctx_t ctx, imui_style_t *style);
|
||||
void IMUI_Style_Fetch (imui_ctx_t ctx, imui_style_t *style);
|
||||
|
||||
void IMUI_Label (imui_ctx_t ctx, string label);
|
||||
void IMUI_Labelf (imui_ctx_t ctx, string fmt, ...);
|
||||
int IMUI_Button (imui_ctx_t ctx, string label);
|
||||
int IMUI_Checkbox (imui_ctx_t ctx, int *flag, string label);
|
||||
void IMUI_Radio (imui_ctx_t ctx, int *curvalue, int value, string label);
|
||||
void IMUI_Slider (imui_ctx_t ctx, float *value, float minval, float maxval,
|
||||
string label);
|
||||
void IMUI_Spacer (imui_ctx_t ctx,
|
||||
imui_size_t xsize, int xvalue,
|
||||
imui_size_t ysize, int yvalue);
|
||||
|
||||
int IMUI_StartPanel (imui_ctx_t ctx, imui_window_t *panel);
|
||||
int IMUI_ExtendPanel (imui_ctx_t ctx, string panel_name);
|
||||
void IMUI_EndPanel (imui_ctx_t ctx);
|
||||
|
||||
int IMUI_StartMenu (imui_ctx_t ctx, imui_window_t *menu, int vertical);
|
||||
void IMUI_EndMenu (imui_ctx_t ctx);
|
||||
int IMUI_MenuItem (imui_ctx_t ctx, string label, int collapse);
|
||||
|
||||
int IMUI_StartWindow (imui_ctx_t ctx, imui_window_t *window);
|
||||
void IMUI_EndWindow (imui_ctx_t ctx);
|
||||
|
||||
#define IMUI_DeferLoop(begin, end) \
|
||||
for (int _i_ = (begin); !_i_; _i_++, (end))
|
||||
|
||||
// #define IMUI_context to an imui_ctx_t * variable
|
||||
|
||||
#define UI_Label(label) \
|
||||
IMUI_Label(IMUI_context, label)
|
||||
|
||||
#define UI_Labelf(fmt...) \
|
||||
IMUI_Labelf(IMUI_context, fmt)
|
||||
|
||||
#define UI_Button(label) \
|
||||
IMUI_Button(IMUI_context, label)
|
||||
|
||||
#define UI_Checkbox(flag, label) \
|
||||
IMUI_Checkbox(IMUI_context, flag, label)
|
||||
|
||||
#define UI_Radio(state, value, label) \
|
||||
IMUI_Radio(IMUI_context, state, value, label)
|
||||
|
||||
#define UI_Slider(value, minval, maxval, label) \
|
||||
IMUI_Slider(IMUI_context, value, minval, maxval, label)
|
||||
|
||||
#define UI_FlexibleSpace() \
|
||||
IMUI_Spacer(IMUI_context, imui_size_expand, 100, imui_size_expand, 100)
|
||||
|
||||
#define UI_Layout(vertical) \
|
||||
IMUI_DeferLoop (IMUI_PushLayout (IMUI_context, vertical), \
|
||||
IMUI_PopLayout (IMUI_context ))
|
||||
|
||||
#define UI_Panel(panel) \
|
||||
IMUI_DeferLoop (IMUI_StartPanel (IMUI_context, panel), \
|
||||
IMUI_EndPanel (IMUI_context))
|
||||
|
||||
#define UI_ExtendPanel(panel_name) \
|
||||
IMUI_DeferLoop (IMUI_ExtendPanel (IMUI_context, panel_name), \
|
||||
IMUI_EndPanel (IMUI_context))
|
||||
|
||||
#define UI_Menu(menu) \
|
||||
IMUI_DeferLoop (IMUI_StartMenu (IMUI_context, menu, true), \
|
||||
IMUI_EndMenu (IMUI_context))
|
||||
|
||||
#define UI_MenuBar(menu) \
|
||||
IMUI_DeferLoop (IMUI_StartMenu (IMUI_context, menu, false), \
|
||||
IMUI_EndMenu (IMUI_context))
|
||||
|
||||
#define UI_MenuItem(label) \
|
||||
IMUI_MenuItem (IMUI_context, label, true)
|
||||
|
||||
#define UI_Window(window) \
|
||||
IMUI_DeferLoop (IMUI_StartWindow (IMUI_context, window), \
|
||||
IMUI_EndWindow (IMUI_context))
|
||||
|
||||
#define UI_Style(style) \
|
||||
IMUI_DeferLoop (IMUI_PushStyle (IMUI_context, style), \
|
||||
IMUI_PopStyle (IMUI_context ))
|
||||
|
||||
#define UI_Horizontal UI_Layout(false)
|
||||
#define UI_Vertical UI_Layout(true)
|
||||
|
||||
#endif//__ruamoko_imui_h
|
|
@ -63,6 +63,7 @@ ruamoko_lib_libnq_a_src= \
|
|||
ruamoko_lib_libcsqc_a_src= \
|
||||
ruamoko/lib/draw.r \
|
||||
ruamoko/lib/gib.r \
|
||||
ruamoko/lib/imui.r \
|
||||
ruamoko/lib/input.r \
|
||||
ruamoko/lib/mersenne.r \
|
||||
ruamoko/lib/scene.r
|
||||
|
|
47
ruamoko/lib/imui.r
Normal file
47
ruamoko/lib/imui.r
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include "imui.h"
|
||||
|
||||
imui_window_t *IMUI_NewWindow (string name) = #0;
|
||||
void IMUI_DeleteWindow (imui_window_t *window) = #0;
|
||||
|
||||
imui_ctx_t IMUI_NewContext (string font, float fontsize) = #0;
|
||||
void IMUI_DestroyContext (imui_ctx_t ctx) = #0;
|
||||
int IMUI_Window_IsOpen (imui_window_t *window) = #0;
|
||||
int IMUI_Window_IsCollapsed (imui_window_t *window) = #0;
|
||||
|
||||
void IMUI_SetVisible (imui_ctx_t ctx, int visible) = #0;
|
||||
void IMUI_SetSize (imui_ctx_t ctx, int xlen, int ylen) = #0;
|
||||
int IMUI_ProcessEvent (imui_ctx_t ctx, /*const*/ struct IE_event_s *ie_event) = #0;
|
||||
void IMUI_BeginFrame (imui_ctx_t ctx) = #0;
|
||||
void IMUI_Draw (imui_ctx_t ctx) = #0;
|
||||
|
||||
int IMUI_PushLayout (imui_ctx_t ctx, int vertical) = #0;
|
||||
void IMUI_PopLayout (imui_ctx_t ctx) = #0;
|
||||
void IMUI_Layout_SetXSize (imui_ctx_t ctx, imui_size_t size, int value) = #0;
|
||||
void IMUI_Layout_SetYSize (imui_ctx_t ctx, imui_size_t size, int value) = #0;
|
||||
|
||||
int IMUI_PushStyle (imui_ctx_t ctx, imui_style_t *style) = #0;
|
||||
void IMUI_PopStyle (imui_ctx_t ctx) = #0;
|
||||
void IMUI_Style_Update (imui_ctx_t ctx, imui_style_t *style) = #0;
|
||||
void IMUI_Style_Fetch (imui_ctx_t ctx, imui_style_t *style) = #0;
|
||||
|
||||
void IMUI_Label (imui_ctx_t ctx, string label) = #0;
|
||||
void IMUI_Labelf (imui_ctx_t ctx, string fmt, ...) = #0;
|
||||
int IMUI_Button (imui_ctx_t ctx, string label) = #0;
|
||||
int IMUI_Checkbox (imui_ctx_t ctx, int *flag, string label) = #0;
|
||||
void IMUI_Radio (imui_ctx_t ctx, int *curvalue, int value, string label) = #0;
|
||||
void IMUI_Slider (imui_ctx_t ctx, float *value, float minval, float maxval,
|
||||
string label) = #0;
|
||||
void IMUI_Spacer (imui_ctx_t ctx,
|
||||
imui_size_t xsize, int xvalue,
|
||||
imui_size_t ysize, int yvalue) = #0;
|
||||
|
||||
int IMUI_StartPanel (imui_ctx_t ctx, imui_window_t *panel) = #0;
|
||||
int IMUI_ExtendPanel (imui_ctx_t ctx, string panel_name) = #0;
|
||||
void IMUI_EndPanel (imui_ctx_t ctx) = #0;
|
||||
|
||||
int IMUI_StartMenu (imui_ctx_t ctx, imui_window_t *menu, int vertical) = #0;
|
||||
void IMUI_EndMenu (imui_ctx_t ctx) = #0;
|
||||
int IMUI_MenuItem (imui_ctx_t ctx, string label, int collapse) = #0;
|
||||
|
||||
int IMUI_StartWindow (imui_ctx_t ctx, imui_window_t *window) = #0;
|
||||
void IMUI_EndWindow (imui_ctx_t ctx) = #0;
|
|
@ -86,6 +86,8 @@ quit_f (void)
|
|||
|
||||
static progs_t *bi_rprogs;
|
||||
static pr_func_t qc2d;
|
||||
static pr_func_t qcevent;
|
||||
static pr_ptr_t qcevent_data;
|
||||
static int event_handler_id;
|
||||
static canvas_system_t canvas_sys;
|
||||
static view_t screen_view;
|
||||
|
@ -141,6 +143,13 @@ bi_setpalette (progs_t *pr, void *_res)
|
|||
VID_SetPalette (palette, colormap);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_setevents (progs_t *pr, void *_res)
|
||||
{
|
||||
qcevent = P_FUNCTION (pr, 0);
|
||||
qcevent_data = P_POINTER (pr, 1);
|
||||
}
|
||||
|
||||
#define bi(x,n,np,params...) {#x, bi_##x, n, np, {params}}
|
||||
#define p(type) PR_PARAM(type)
|
||||
static builtin_t builtins[] = {
|
||||
|
@ -148,16 +157,27 @@ static builtin_t builtins[] = {
|
|||
bi(refresh, -1, 0),
|
||||
bi(refresh_2d, -1, 1, p(func)),
|
||||
bi(setpalette, -1, 2, p(ptr), p(ptr)),
|
||||
bi(setevents, -1, 2, p(func), p(ptr)),
|
||||
{0}
|
||||
};
|
||||
|
||||
static int
|
||||
event_handler (const IE_event_t *ie_event, void *_pr)
|
||||
{
|
||||
// FIXME rethink event handling for qwaq
|
||||
if (ie_event->type == ie_key && ie_event->key.code == QFK_ESCAPE) {
|
||||
Con_SetState (con_active, false);
|
||||
return 1;
|
||||
if (qcevent) {
|
||||
progs_t *pr = _pr;
|
||||
int num_params = sizeof (IE_event_t) / sizeof (pr_type_t);
|
||||
num_params = (num_params + 3) / 4 + 2;
|
||||
|
||||
PR_PushFrame (pr);
|
||||
PR_SetupParams (pr, num_params, 2);
|
||||
auto event = &P_PACKED (pr, IE_event_t, 2);
|
||||
P_POINTER (pr, 0) = PR_SetPointer (pr, event);
|
||||
P_POINTER (pr, 1) = qcevent_data;
|
||||
*event = *ie_event;
|
||||
PR_ExecuteProgram (pr, qcevent);
|
||||
PR_PopFrame (pr);
|
||||
return R_INT (pr);
|
||||
}
|
||||
return IN_Binding_HandleEvent (ie_event);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue