[ui] Create library for UI support code

Currently this has text buffer, input line, vrect and view code.
This commit is contained in:
Bill Currie 2021-06-12 22:50:51 +09:00
parent 2572011a4b
commit 813497a1aa
37 changed files with 152 additions and 71 deletions

View file

@ -68,12 +68,9 @@ include_qf = \
include/QF/sys.h \
include/QF/teamplay.h \
include/QF/tga.h \
include/QF/txtbuffer.h \
include/QF/va.h \
include/QF/ver_check.h \
include/QF/vid.h \
include/QF/vrect.h \
include/QF/view.h \
include/QF/wad.h \
include/QF/wadfile.h \
include/QF/winding.h \
@ -134,6 +131,12 @@ include_qf_simd = \
include/QF/simd/vec4d.h \
include/QF/simd/vec4f.h
include_qf_ui = \
include/QF/ui/inputline.h \
include/QF/ui/txtbuffer.h \
include/QF/ui/view.h \
include/QF/ui/vrect.h
include_qf_vulkan = \
include/QF/Vulkan/barrier.h \
include/QF/Vulkan/buffer.h \

View file

@ -46,27 +46,6 @@ typedef struct
int numlines; // number of non-blank text lines, used for backscroling
} old_console_t;
typedef struct inputline_s
{
char **lines; // array of lines for input history
int num_lines; // number of lines in arry. 1 == no history
size_t line_size; // space available in each line. includes \0
char prompt_char; // char placed at the beginning of the line
int edit_line; // current line being edited
int history_line; // current history line
size_t linepos; // cursor position within the current edit line
size_t scroll; // beginning of displayed line
size_t width; // viewable width for horizontal scrolling
const char *line;
void *user_data; // eg: window pointer
void (*complete)(struct inputline_s *); // tab key pressed
void (*enter)(struct inputline_s *); // enter key pressed
void (*draw)(struct inputline_s *); // draw input line to screen
int x, y; // coordinates depend on display
int cursor; // is the cursor active (drawn?)
} inputline_t;
typedef struct {
byte *text;
size_t len;
@ -96,22 +75,18 @@ void Con_Printf (const char *fmt, ...) __attribute__((format(PRINTF, 1, 2)));
void Con_Print (const char *fmt, va_list args) __attribute__((format(PRINTF, 1, 0)));
void Con_ToggleConsole_f (void);
struct inputline_s;
// wrapper function to attempt to either complete the command line
// or to list possible matches grouped by type
// (i.e. will display possible variables, aliases, commands
// that match what they've typed so far)
void Con_BasicCompleteCommandLine (inputline_t *il);
void Con_BasicCompleteCommandLine (struct inputline_s *il);
// Generic libs/util/console.c function to display a list
// formatted in columns on the console
void Con_DisplayList(const char **list, int con_linewidth);
extern void (*con_list_print)(const char *fmt, ...) __attribute__((format(PRINTF, 1, 2)));
inputline_t *Con_CreateInputLine (int lines, int lsize, char prompt);
void Con_DestroyInputLine (inputline_t *inputline);
void Con_ClearTyping (inputline_t *il, int save);
void Con_ProcessInputLine (inputline_t *il, int ch);
con_buffer_t *Con_CreateBuffer (size_t buffer_size, int max_lines);
void Con_DestroyBuffer (con_buffer_t *buffer);
void Con_BufferAddText (con_buffer_t *buf, const char *text);
@ -134,7 +109,7 @@ void Con_Demolist_DEM_f (void);
//FIXME need a better way to communicate this (bah, need a better menu system
// in general :P)
void C_DrawInputLine (inputline_t *il);
void C_DrawInputLine (struct inputline_s *il);
struct view_s;
void Menu_Init (void);

View file

@ -33,6 +33,7 @@
#include "QF/qdefs.h" // FIXME
#include "QF/vid.h"
#include "QF/simd/types.h"
#include "QF/ui/vrect.h"
typedef enum {
pt_static,

60
include/QF/ui/inputline.h Normal file
View file

@ -0,0 +1,60 @@
/*
inputline.h
Input line support
Copyright (C) 2001 Bill Currie <bill@taniwha.org>
Copyright (C) 2021 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
*/
#ifndef __QF_ui_inputline_h
#define __QF_ui_inputline_h
#include <stdlib.h>
typedef struct inputline_s
{
char **lines; // array of lines for input history
int num_lines; // number of lines in arry. 1 == no history
size_t line_size; // space available in each line. includes \0
char prompt_char; // char placed at the beginning of the line
int edit_line; // current line being edited
int history_line; // current history line
size_t linepos; // cursor position within the current edit line
size_t scroll; // beginning of displayed line
size_t width; // viewable width for horizontal scrolling
const char *line;
void *user_data; // eg: window pointer
void (*complete)(struct inputline_s *); // tab key pressed
void (*enter)(struct inputline_s *); // enter key pressed
void (*draw)(struct inputline_s *); // draw input line to screen
int x, y; // coordinates depend on display
int cursor; // is the cursor active (drawn?)
} inputline_t;
inputline_t *Con_CreateInputLine (int lines, int lsize, char prompt);
void Con_DestroyInputLine (inputline_t *inputline);
void Con_ClearTyping (inputline_t *il, int save);
void Con_ProcessInputLine (inputline_t *il, int ch);
#endif//__QF_ui_inputline_h

View file

@ -25,8 +25,8 @@
*/
#ifndef __QF_txtbuffer_h
#define __QF_txtbuffer_h
#ifndef __QF_ui_txtbuffer_h
#define __QF_ui_txtbuffer_h
#include <stdint.h>
#include <stdlib.h>
@ -109,4 +109,4 @@ int TextBuffer_DeleteAt (txtbuffer_t *buffer, size_t offset, size_t len);
///@}
#endif//__QF_txtbuffer_h
#endif//__QF_ui_txtbuffer_h

View file

@ -28,8 +28,8 @@
*/
#ifndef __QF_view_h
#define __QF_view_h
#ifndef __QF_ui_view_h
#define __QF_ui_view_h
/** \defgroup console_view Console View Objects
\ingroup console
@ -40,8 +40,8 @@
the standard compass rose (north, east, south, west in clockwise order)
with north at the top.
The origin of the view is taken to be the point corresponding point on the
edge of the view (eg, southeast is bottom right), or the view's center for
The origin of the view is taken to be the corresponding point on the edge
of the view (eg, southeast is bottom right), or the view's center for
center gravity. When the relative coordinates of the view are (0,0), the
view's origin is placed on the parent view's gravity point using the view's
gravity (\em not the parent view's gravity). That is, the parent view's
@ -217,4 +217,4 @@ void view_move (view_t *view, int xp, int yp);
///@}
#endif//__QF_view_h
#endif//__QF_ui_view_h

View file

@ -28,8 +28,8 @@
*/
#ifndef __QF_vrect_h
#define __QF_vrect_h
#ifndef __QF_ui_vrect_h
#define __QF_ui_vrect_h
typedef struct vrect_s {
int x;
@ -165,4 +165,4 @@ vrect_t *VRect_Union (const vrect_t *r1, const vrect_t *r2);
*/
vrect_t *VRect_Merge (const vrect_t *r1, const vrect_t *r2);
#endif//__QF_vrect_h
#endif//__QF_ui_vrect_h

View file

@ -29,7 +29,6 @@
#define __QF_vid_h
#include "QF/qtypes.h"
#include "QF/vrect.h"
#define VID_CBITS 6
#define VID_GRADES (1 << VID_CBITS)

View file

@ -1,4 +1,5 @@
include libs/util/Makemodule.am
include libs/ui/Makemodule.am
include libs/gamecode/Makemodule.am
include libs/ruamoko/Makemodule.am
include libs/gib/Makemodule.am

View file

@ -4,12 +4,23 @@ noinst_LTLIBRARIES += @client_static_plugins@ @server_static_plugins@
EXTRA_LTLIBRARIES += libs/console/console_server.la libs/console/console_client.la
console_common_sources= \
libs/console/buffer.c libs/console/complete.c libs/console/console.c libs/console/inputline.c libs/console/list.c libs/console/filelist.c libs/console/view.c
client_sources= libs/console/bi_inputline.c libs/console/client.c libs/console/menu.c
server_sources= libs/console/server.c
libs/console/buffer.c \
libs/console/complete.c \
libs/console/console.c \
libs/console/list.c \
libs/console/filelist.c
client_sources= \
libs/console/bi_inputline.c \
libs/console/client.c \
libs/console/menu.c
server_sources= \
libs/console/server.c
console_deps=libs/util/libQFutil.la
client_deps= libs/console/libQFconsole.la \
console_deps=\
libs/ui/libQFui.la \
libs/util/libQFutil.la
client_deps= \
libs/console/libQFconsole.la \
libs/audio/libQFsound.la \
libs/ruamoko/libQFruamoko.la \
libs/gib/libQFgib.la \

View file

@ -36,13 +36,14 @@
# include <strings.h>
#endif
#include "QF/console.h"
#include "QF/csqc.h"
#include "QF/draw.h"
#include "QF/progs.h"
#include "QF/sys.h"
#include "QF/zone.h"
#include "QF/ui/inputline.h"
typedef struct il_data_s {
struct il_data_s *next;
struct il_data_s **prev;

View file

@ -58,12 +58,15 @@
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/vid.h"
#include "QF/view.h"
#include "QF/plugin/general.h"
#include "QF/plugin/console.h"
#include "QF/plugin/vid_render.h"
#include "QF/ui/view.h"
#include "QF/ui/inputline.h"
#include "compat.h"
static general_data_t plugin_info_general_data;

View file

@ -47,6 +47,8 @@
#include "QF/plugin/console.h"
#include "QF/ui/inputline.h"
#include "compat.h"
/*

View file

@ -42,6 +42,8 @@
#include "QF/plugin/general.h"
#include "QF/plugin/console.h"
#include "QF/ui/inputline.h"
//FIXME probably shouldn't be visible
VISIBLE int con_linewidth; // characters across screen

View file

@ -46,7 +46,8 @@
#include "QF/ruamoko.h"
#include "QF/sound.h"
#include "QF/sys.h"
#include "QF/view.h"
#include "QF/ui/view.h"
#include "QF/plugin/console.h"
#include "QF/plugin/vid_render.h"

View file

@ -68,11 +68,14 @@
#include "QF/quakefs.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/view.h"
#include "QF/plugin/general.h"
#include "QF/plugin/console.h"
#include "QF/ui/view.h"
#include "QF/ui/inputline.h"
#include "compat.h"
#include "sv_console.h"

12
libs/ui/Makemodule.am Normal file
View file

@ -0,0 +1,12 @@
#include libs/ui/test/Makemodule.am
lib_LTLIBRARIES += libs/ui/libQFui.la
libs_ui_libQFui_la_LDFLAGS= $(lib_ldflags)
libs_ui_libQFui_la_LIBADD= $(ui_deps)
libs_ui_libQFui_la_DEPENDENCIES= $(ui_deps)
libs_ui_libQFui_la_SOURCES= \
libs/ui/inputline.c \
libs/ui/txtbuffer.c \
libs/ui/view.c \
libs/ui/vrect.c

View file

@ -39,12 +39,10 @@
# include <strings.h>
#endif
#include "QF/cmd.h"
#include "QF/console.h"
#include "QF/keys.h"
#include "QF/mathlib.h"
#include "compat.h"
#include "QF/ui/inputline.h"
VISIBLE struct inputline_s *
Con_CreateInputLine (int lines, int lsize, char prompt)

View file

@ -38,7 +38,8 @@
#include "QF/alloc.h"
#include "QF/qtypes.h"
#include "QF/sys.h"
#include "QF/txtbuffer.h"
#include "QF/ui/txtbuffer.h"
#include "compat.h"

View file

@ -39,7 +39,7 @@
#endif
#include <stdlib.h>
#include "QF/view.h"
#include "QF/ui/view.h"
static void
setgeometry (view_t *view)

View file

@ -34,7 +34,8 @@
#include <stdlib.h>
#include "QF/mathlib.h"
#include "QF/vrect.h"
#include "QF/ui/vrect.h"
//#define TEST_MEMORY

View file

@ -80,10 +80,8 @@ libs_util_libQFutil_la_SOURCES= \
libs/util/sizebuf.c \
libs/util/string.c \
libs/util/sys.c \
libs/util/txtbuffer.c \
libs/util/va.c \
libs/util/ver_check.c \
libs/util/vrect.c \
libs/util/wad.c \
libs/util/wadfile.c \
libs/util/zone.c \

View file

@ -51,7 +51,6 @@
#include "QF/render.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/vrect.h"
#include "QF/GLSL/defines.h"
#include "QF/GLSL/funcs.h"

View file

@ -46,12 +46,13 @@
#include "QF/model.h"
#include "QF/render.h"
#include "QF/sys.h"
#include "QF/vrect.h"
#include "QF/GLSL/defines.h"
#include "QF/GLSL/funcs.h"
#include "QF/GLSL/qf_textures.h"
#include "QF/ui/vrect.h"
#include "r_scrap.h"
struct scrap_s {

View file

@ -32,7 +32,8 @@
#endif
#include "QF/sys.h"
#include "QF/vrect.h"
#include "QF/ui/vrect.h"
#include "compat.h"
#include "r_scrap.h"

View file

@ -43,7 +43,6 @@
#include "QF/render.h"
#include "QF/screen.h"
#include "QF/sys.h"
#include "QF/view.h"
#include "compat.h"
#include "r_internal.h"

View file

@ -51,7 +51,6 @@
#include "QF/skin.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/vrect.h"
#include "QF/Vulkan/qf_alias.h"
#include "QF/Vulkan/qf_texture.h"

View file

@ -50,7 +50,6 @@
#include "QF/render.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/vrect.h"
#include "QF/Vulkan/qf_bsp.h"
#include "QF/Vulkan/qf_lightmap.h"

View file

@ -61,6 +61,7 @@ nq_common_LIBFILES= \
libs/gib/libQFgib.la \
libs/ruamoko/libQFruamoko.la \
libs/gamecode/libQFgamecode.la \
libs/ui/libQFui.la \
libs/util/libQFutil.la
nq_client_LIBS= $(nq_client_LIBFILES) $(nq_common_LIBFILES)

View file

@ -47,12 +47,13 @@
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/vid.h"
#include "QF/view.h"
#include "QF/wad.h"
#include "QF/plugin/console.h"
#include "QF/plugin/vid_render.h"
#include "QF/ui/view.h"
#include "compat.h"
#include "sbar.h"

View file

@ -36,6 +36,7 @@ qtv_LIBS= \
libs/qw/libqw.a \
libs/net/libnet_chan.la \
libs/console/libQFconsole.la \
libs/ui/libQFui.la \
libs/util/libQFutil.la
qtv_server_SOURCES= qtv/source/client.c qtv/source/connection.c qtv/source/qtv.c qtv/source/sbar.c qtv/source/server.c qtv/source/sv_parse.c

View file

@ -32,11 +32,12 @@
#endif
#include "QF/console.h"
#include "QF/view.h"
#include "QF/va.h"
#include "QF/plugin/console.h"
#include "QF/ui/view.h"
#include "sv_console.h"
#include "qtv/include/client.h"

View file

@ -67,6 +67,7 @@ qw_server_LIBS= \
libs/ruamoko/libQFruamoko.la \
libs/gamecode/libQFgamecode.la \
libs/console/libQFconsole.la \
libs/ui/libQFui.la \
libs/util/libQFutil.la
qw_server_deps=qw/source/libqw_server.a qw/source/libqw_common.a $(qw_server_LIBS)
@ -95,6 +96,7 @@ qw_client_LIBS= \
libs/image/libQFimage.la \
libs/gib/libQFgib.la \
libs/ruamoko/libQFruamoko.la \
libs/ui/libQFui.la \
libs/util/libQFutil.la
qw_client_libs= qw/source/libqw_client.a qw/source/libqw_common.a \
libs/client/libQFclient.la

View file

@ -50,10 +50,11 @@
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/vid.h"
#include "QF/view.h"
#include "QF/plugin/console.h"
#include "QF/ui/view.h"
#include "compat.h"
#include "qw/bothdefs.h"

View file

@ -32,9 +32,10 @@
#endif
#include "QF/console.h"
#include "QF/view.h"
#include "QF/va.h"
#include "QF/ui/view.h"
#include "QF/plugin/console.h"
#include "sv_console.h"

View file

@ -46,6 +46,7 @@ qwaq_app_dat_src= \
qwaq_curses_libs= \
libs/video/targets/libvid_common.la \
libs/console/libQFconsole.la \
libs/ui/libQFui.la \
libs/gib/libQFgib.la
ruamoko_qwaq_qwaq_curses_SOURCES= \
@ -66,6 +67,7 @@ qwaq_cl_plugin_libs= \
qwaq_client_libs= \
$(top_builddir)/libs/entity/libQFentity.la \
$(top_builddir)/libs/console/libQFconsole.la \
$(top_builddir)/libs/ui/libQFui.la \
$(top_builddir)/libs/video/targets/libQFjs.la \
$(top_builddir)/libs/audio/libQFcd.la \
$(top_builddir)/libs/audio/libQFsound.la \

View file

@ -9,7 +9,8 @@
#include "QF/progs.h"
#include "QF/ruamoko.h"
#include "QF/quakeio.h"
#include "QF/txtbuffer.h"
#include "QF/ui/txtbuffer.h"
#include "ruamoko/qwaq/qwaq.h"
#include "ruamoko/qwaq/editor/editbuffer.h"