[vid] Add a listener for window size changes

A listener is used instead of (really, as well as) ie_app_window events
because systems that need to know about windows sizes may not have
anything to do with input and the event system.
This commit is contained in:
Bill Currie 2022-09-22 01:05:55 +09:00
parent fdfdf9056a
commit d149457241
3 changed files with 22 additions and 0 deletions

View file

@ -52,6 +52,7 @@ typedef struct {
struct vid_internal_s *vid_internal;
struct viddef_listener_set_s *onPaletteChanged;
struct viddef_listener_set_s *onVidResize;
} viddef_t;
typedef struct viddef_listener_set_s LISTENER_SET_TYPE (viddef_t)
@ -76,5 +77,7 @@ void VID_ClearMemory (void);
void VID_OnPaletteChange_AddListener (viddef_listener_t listener, void *data);
void VID_OnPaletteChange_RemoveListener (viddef_listener_t listener,
void *data);
void VID_OnVidResize_AddListener (viddef_listener_t listener, void *data);
void VID_OnVidResize_RemoveListener (viddef_listener_t listener, void *data);
#endif//__QF_vid_h

View file

@ -33,6 +33,7 @@ extern int vid_system_gamma;
extern float vid_gamma;
void VID_GetWindowSize (int def_w, int def_h);
void VID_SetWindowSize (int width, int height);
void VID_InitGamma (const byte *);
qboolean VID_SetGamma (double);

View file

@ -291,6 +291,24 @@ VID_OnPaletteChange_RemoveListener (viddef_listener_t listener, void *data)
}
}
VISIBLE void
VID_OnVidResize_AddListener (viddef_listener_t listener, void *data)
{
if (!viddef.onVidResize) {
viddef.onVidResize = malloc (sizeof (*viddef.onVidResize));
LISTENER_SET_INIT (viddef.onVidResize, 8);
}
LISTENER_ADD (viddef.onVidResize, listener, data);
}
VISIBLE void
VID_OnVidResize_RemoveListener (viddef_listener_t listener, void *data)
{
if (viddef.onVidResize) {
LISTENER_REMOVE (viddef.onVidResize, listener, data);
}
}
VISIBLE void
VID_Init (byte *palette, byte *colormap)
{