[client] Further decouple screen and console

The wording might seem a little odd, but cl_screen is really the full 2D
client HUD while the console is completely independent of the client and
shouldn't know that the client even exists. Ideally, the resize events
would be handled by the canvas system, to which end this is a small
step.
This commit is contained in:
Bill Currie 2023-01-16 13:23:44 +09:00
parent 8833518826
commit 31c1420682
3 changed files with 36 additions and 10 deletions

View file

@ -51,7 +51,6 @@ typedef struct console_data_s {
int ormask;
void (*quit) (void);
struct cbuf_s *cbuf;
struct view_s *screen_view;
struct view_s *status_view;
float lines;
int (*exec_line)(void *data, const char *line);

View file

@ -164,15 +164,45 @@ static SCR_Func *scr_funcs[] = {
scr_funcs_intermission,
};
static int cl_scale;
static int cl_xlen;
static int cl_ylen;
static void
cl_set_size (void)
{
int xlen = cl_xlen / cl_scale;
int ylen = cl_ylen / cl_scale;
printf ("cl_set_size: %d %d %d\n", cl_scale, xlen, ylen);
View_SetLen (cl_screen_view, xlen, ylen);
View_UpdateHierarchy (cl_screen_view);
}
static void
cl_scale_listener (void *data, const cvar_t *cvar)
{
cl_scale = *(int *) cvar->value.value;
cl_set_size ();
}
static void
cl_vidsize_listener (void *data, const viddef_t *vdef)
{
cl_xlen = vdef->width;
cl_ylen = vdef->height;
cl_set_size ();
}
void
CL_Init_Screen (void)
{
qpic_t *pic;
HUD_Init ();
cl_xlen = viddef.width;
cl_ylen = viddef.height;
cl_screen_view = View_New (hud_viewsys, nullview);
con_module->data->console->screen_view = &cl_screen_view;
View_SetPos (cl_screen_view, 0, 0);
View_SetLen (cl_screen_view, viddef.width, viddef.height);
@ -240,6 +270,11 @@ CL_Init_Screen (void)
View_SetGravity (pause_view, grav_center);
Ent_SetComponent (pause_view.id, hud_cachepic, pause_view.reg, &name);
View_SetVisible (pause_view, 0);
cvar_t *con_scale = Cvar_FindVar ("con_scale");
Cvar_AddListener (con_scale, cl_scale_listener, 0);
cl_scale_listener (0, con_scale);
VID_OnVidResize_AddListener (cl_vidsize_listener, 0);
}
void

View file

@ -830,17 +830,9 @@ con_set_size (void)
if (xlen > 0 && ylen > 0) {
View_SetLen (screen_view, xlen, ylen);
View_UpdateHierarchy (screen_view);
if (con_data.screen_view) {
View_SetLen (*con_data.screen_view, xlen, ylen);
View_UpdateHierarchy (*con_data.screen_view);
}
}
}
// The console view is not a child of the client's screen view, so it won't
// get resized automatically when the screen changes size. However, since the
// console has to process input events anyway, handling ie_app_window is a
// reasonable alternative.
static void
con_app_window (const IE_event_t *event)
{