From bc34529a80604b8f7e2457b9187d7c68f8fdc583 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 9 Aug 2001 23:16:54 +0000 Subject: [PATCH] code for the input event system --- include/QF/in_event.h | 4 +- libs/video/targets/Makefile.am | 20 +++---- libs/video/targets/in_event.c | 98 ++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 11 deletions(-) create mode 100644 libs/video/targets/in_event.c diff --git a/include/QF/in_event.h b/include/QF/in_event.h index 5ef47219d..e7cf95faf 100644 --- a/include/QF/in_event.h +++ b/include/QF/in_event.h @@ -68,8 +68,8 @@ typedef struct { void IE_Init (void); void IE_Init_Cvars (void); -int IE_Send_Event (const Qevent_t *event); -int IE_Add_Handler (int (*event_handler)(const Qevent_t*)); +int IE_Send_Event (const IE_event_t *event); +int IE_Add_Handler (int (*event_handler)(const IE_event_t*)); void IE_Remove_Handler (int handle); void IE_Set_Focus (int handle); diff --git a/libs/video/targets/Makefile.am b/libs/video/targets/Makefile.am index 3a79de2e9..4ebebdfb6 100644 --- a/libs/video/targets/Makefile.am +++ b/libs/video/targets/Makefile.am @@ -30,13 +30,15 @@ libQFjs.la: $(libQFjs_la_OBJECTS) $(libQFjs_la_DEPENDENCIES) $(LINK) -rpath $(libdir) $(libQFjs_la_LDFLAGS) $(libQFjs_la_OBJECTS) $(libQFjs_la_LIBADD) $(LIBS) EXTRA_DIST= joy.c joy_linux.c joy_null.c joy_win.c +in_common_SOURCE= in_common.c in_event.c + # Linux FBdev YFLAGS = -d YACCLEX_CLEANFILES= fbset_modes_y.c fbset_modes_y.h \ fbset_modes_y.tab.h fbset_modes_l.c libQFfbdev_la_LDFLAGS= -version-info 1:0:0 libQFfbdev_la_SOURCES= fbset.c fbset_modes_y.y fbset_modes_l.l \ - in_common.c in_fbdev.c vid.c vid_common_sw.c vid_fbdev.c + $(in_common_SOURCE) in_fbdev.c vid.c vid_common_sw.c vid_fbdev.c EXTRA_libQFfbdev_la_SOURCES=fbset_modes_y.h libQFfbdev.la: $(libQFfbdev_la_OBJECTS) $(libQFfbdev_la_DEPENDENCIES) $(LINK) -rpath $(libdir) $(libQFfbdev_la_LDFLAGS) $(libQFfbdev_la_OBJECTS) $(libQFfbdev_la_LIBADD) $(LIBS) @@ -46,52 +48,52 @@ fbset_modes_l.lo: $(srcdir)/fbset_modes_l.c $(LTCOMPILE) -Wno-error -c $< libQFglx_la_LDFLAGS= -version-info 1:0:0 $(X_PRE_LIBS) $(VIDMODE_LIBS) $(DGA_LIBS) $(X_LIBS) -lX11 $(X_EXTRA_LIBS) -libQFglx_la_SOURCES= in_common.c in_x11.c vid.c context_x11.c dga_check.c \ +libQFglx_la_SOURCES= $(in_common_SOURCE) in_x11.c vid.c context_x11.c dga_check.c \ qfgl_ext.c vid_common_gl.c vid_glx.c libQFglx.la: $(libQFglx_la_OBJECTS) $(libQFglx_la_DEPENDENCIES) $(LINK) -rpath $(libdir) $(libQFglx_la_LDFLAGS) $(libQFglx_la_OBJECTS) $(libQFglx_la_LIBADD) $(LIBS) libQFmgl_la_LDFLAGS= -version-info 1:0:0 -libQFmgl_la_SOURCES= in_common.c in_win.c vid.c vid_common_sw.c vid_mgl.c +libQFmgl_la_SOURCES= $(in_common_SOURCE) in_win.c vid.c vid_common_sw.c vid_mgl.c libQFmgl.la: $(libQFmgl_la_OBJECTS) $(libQFmgl_la_DEPENDENCIES) $(LINK) -rpath $(libdir) $(libQFmgl_la_LDFLAGS) $(libQFmgl_la_OBJECTS) $(libQFmgl_la_LIBADD) $(LIBS) libQFsdl_la_LDFLAGS= -version-info 1:0:0 -libQFsdl_la_SOURCES= in_common.c in_sdl.c vid.c vid_common_sw.c vid_sdl.c +libQFsdl_la_SOURCES= $(in_common_SOURCE) in_sdl.c vid.c vid_common_sw.c vid_sdl.c libQFsdl.la: $(libQFsdl_la_OBJECTS) $(libQFsdl_la_DEPENDENCIES) $(LINK) -rpath $(libdir) $(libQFsdl_la_LDFLAGS) $(libQFsdl_la_OBJECTS) $(libQFsdl_la_LIBADD) $(LIBS) libQFsgl_la_LDFLAGS= -version-info 1:0:0 -libQFsgl_la_SOURCES= in_common.c in_sdl.c qfgl_ext.c vid.c vid_common_gl.c vid_sgl.c +libQFsgl_la_SOURCES= $(in_common_SOURCE) in_sdl.c qfgl_ext.c vid.c vid_common_gl.c vid_sgl.c libQFsgl.la: $(libQFsgl_la_OBJECTS) $(libQFsgl_la_DEPENDENCIES) $(LINK) -rpath $(libdir) $(libQFsgl_la_LDFLAGS) $(libQFsgl_la_OBJECTS) $(libQFsgl_la_LIBADD) $(LIBS) libQFsvga_la_LDFLAGS= -version-info 1:0:0 libQFsvga_la_LIBADD=$(ASM) -libQFsvga_la_SOURCES= in_common.c in_svgalib.c vid.c vid_common_sw.c \ +libQFsvga_la_SOURCES= $(in_common_SOURCE) in_svgalib.c vid.c vid_common_sw.c \ vid_svgalib.c libQFsvga.la: $(libQFsvga_la_OBJECTS) $(libQFsvga_la_DEPENDENCIES) $(LINK) -rpath $(libdir) $(libQFsvga_la_LDFLAGS) $(libQFsvga_la_OBJECTS) $(libQFsvga_la_LIBADD) $(LIBS) libQFtdfx_la_LDFLAGS= -version-info 1:0:0 -libQFtdfx_la_SOURCES= in_common.c in_svgalib.c qfgl_ext.c vid.c vid_common_gl.c vid_3dfxsvga.c +libQFtdfx_la_SOURCES= $(in_common_SOURCE) in_svgalib.c qfgl_ext.c vid.c vid_common_gl.c vid_3dfxsvga.c libQFtdfx.la: $(libQFtdfx_la_OBJECTS) $(libQFtdfx_la_DEPENDENCIES) $(LINK) -rpath $(libdir) $(libQFtdfx_la_LDFLAGS) $(libQFtdfx_la_OBJECTS) $(libQFtdfx_la_LIBADD) $(LIBS) libQFwgl_la_LDFLAGS= -version-info 1:0:0 -libQFwgl_la_SOURCES= in_common.c in_win.c qfgl_ext.c vid.c vid_common_gl.c vid_wgl.c +libQFwgl_la_SOURCES= $(in_common_SOURCE) in_win.c qfgl_ext.c vid.c vid_common_gl.c vid_wgl.c libQFwgl.la: $(libQFwgl_la_OBJECTS) $(libQFwgl_la_DEPENDENCIES) $(LINK) -rpath $(libdir) $(libQFwgl_la_LDFLAGS) $(libQFwgl_la_OBJECTS) $(libQFwgl_la_LIBADD) $(LIBS) libQFx11_la_LDFLAGS= -version-info 1:0:0 $(X_PRE_LIBS) $(VIDMODE_LIBS) $(DGA_LIBS) $(X_LIBS) -lX11 $(X_EXTRA_LIBS) $(X_SHM_LIB) -libQFx11_la_SOURCES= in_common.c in_x11.c vid.c context_x11.c dga_check.c \ +libQFx11_la_SOURCES= $(in_common_SOURCE) in_x11.c vid.c context_x11.c dga_check.c \ vid_common_sw.c vid_x11.c libQFx11.la: $(libQFx11_la_OBJECTS) $(libQFx11_la_DEPENDENCIES) $(LINK) -rpath $(libdir) $(libQFx11_la_LDFLAGS) $(libQFx11_la_OBJECTS) $(libQFx11_la_LIBADD) $(LIBS) diff --git a/libs/video/targets/in_event.c b/libs/video/targets/in_event.c new file mode 100644 index 000000000..7fd3c3a46 --- /dev/null +++ b/libs/video/targets/in_event.c @@ -0,0 +1,98 @@ +/* + in_event.c + + input event handling + + Copyright (C) 2001 Bill Currie + + Author: Bill Currie + Date: 2001/8/9 + + 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 + + $Id$ +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "QF/in_event.h" + +static int (**event_handler_list)(const IE_event_t*); +static int eh_list_size; +static int focus; + +void +IE_Init (void) +{ + eh_list_size = 8; // start with 8 slots. will grow dynamicly if needed + event_handler_list = calloc (eh_list_size, sizeof (event_handler_list[0])); +} + +void +IE_Init_Cvars (void) +{ +} + +int +IE_Send_Event (const IE_event_t *event) +{ + if (event_handler_list[focus]) + return event_handler_list[focus](event); + return 0; +} + +int +IE_Add_Handler (int (*event_handler)(const IE_event_t*)) +{ + int i; + + while (1) { + int (**t)(const IE_event_t*); + for (i = 0; i < eh_list_size; i++) { + if (!event_handler_list[i]) { + event_handler_list[i] = event_handler; + return i; + } + } + if (!(t = realloc (event_handler_list, eh_list_size + 8))) + return -1; + event_handler_list = t; + memset (event_handler_list + eh_list_size, 0, + 8 * sizeof (event_handler_list[0])); + eh_list_size += 8; + } +} + +void +IE_Remove_Handler (int handle) +{ + if (handle >= 0 && handle < eh_list_size) + event_handler_list[handle] = 0; +} + +void +IE_Set_Focus (int handle) +{ + if (handle >= 0 && handle < eh_list_size && event_handler_list[handle]) + focus = eh_list_size; +}