mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
implement the "new" inputline api making it possible to pull the Draw_*
functions out of bi_inputline.c. now somebody can be insane enough to implement a qc controled console for the server ;) (more importantly, one step closer to being able to have the server link with libQFcsqc (hah!))
This commit is contained in:
parent
5d51e0151e
commit
d328e18de2
6 changed files with 63 additions and 47 deletions
|
@ -36,6 +36,7 @@ void BI_Init ();
|
||||||
|
|
||||||
struct progs_s;
|
struct progs_s;
|
||||||
struct cbuf_s;
|
struct cbuf_s;
|
||||||
|
struct inputline_s;
|
||||||
|
|
||||||
void Cbuf_Progs_Init (struct progs_s *pr);
|
void Cbuf_Progs_Init (struct progs_s *pr);
|
||||||
void Cbuf_Progs_SetCbuf (struct progs_s *pr, struct cbuf_s *cbuf);
|
void Cbuf_Progs_SetCbuf (struct progs_s *pr, struct cbuf_s *cbuf);
|
||||||
|
@ -43,6 +44,8 @@ void Cmd_Progs_Init (struct progs_s *pr);
|
||||||
void Cvar_Progs_Init (struct progs_s *pr);
|
void Cvar_Progs_Init (struct progs_s *pr);
|
||||||
void File_Progs_Init (struct progs_s *pr);
|
void File_Progs_Init (struct progs_s *pr);
|
||||||
void InputLine_Progs_Init (struct progs_s *pr);
|
void InputLine_Progs_Init (struct progs_s *pr);
|
||||||
|
void InputLine_Progs_SetDraw (struct progs_s *pr,
|
||||||
|
void (*draw)(struct inputline_s*));
|
||||||
void Key_Progs_Init (struct progs_s *pr);
|
void Key_Progs_Init (struct progs_s *pr);
|
||||||
void String_Progs_Init (struct progs_s *pr);
|
void String_Progs_Init (struct progs_s *pr);
|
||||||
void StringHash_Progs_Init (struct progs_s *pr);
|
void StringHash_Progs_Init (struct progs_s *pr);
|
||||||
|
|
|
@ -58,6 +58,12 @@ static const char rcsid[] =
|
||||||
|
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
|
|
||||||
|
// XXX check InputLine.h in ruamoko/include
|
||||||
|
typedef struct {
|
||||||
|
int x, y;
|
||||||
|
int cursor;
|
||||||
|
} il_data_t;
|
||||||
|
|
||||||
static general_data_t plugin_info_general_data;
|
static general_data_t plugin_info_general_data;
|
||||||
console_data_t con_data;
|
console_data_t con_data;
|
||||||
|
|
||||||
|
@ -355,21 +361,21 @@ C_Init (void)
|
||||||
input_line->enter = C_ExecLine;
|
input_line->enter = C_ExecLine;
|
||||||
input_line->width = con_linewidth;
|
input_line->width = con_linewidth;
|
||||||
input_line->user_data = 0;
|
input_line->user_data = 0;
|
||||||
input_line->draw = 0;//C_DrawInput;
|
input_line->draw = 0;
|
||||||
|
|
||||||
say_line = Con_CreateInputLine (32, MAXCMDLINE, ' ');
|
say_line = Con_CreateInputLine (32, MAXCMDLINE, ' ');
|
||||||
say_line->complete = 0;
|
say_line->complete = 0;
|
||||||
say_line->enter = C_Say;
|
say_line->enter = C_Say;
|
||||||
say_line->width = con_linewidth - 5;
|
say_line->width = con_linewidth - 5;
|
||||||
say_line->user_data = 0;
|
say_line->user_data = 0;
|
||||||
say_line->draw = 0;//C_DrawInput;
|
say_line->draw = 0;
|
||||||
|
|
||||||
say_team_line = Con_CreateInputLine (32, MAXCMDLINE, ' ');
|
say_team_line = Con_CreateInputLine (32, MAXCMDLINE, ' ');
|
||||||
say_team_line->complete = 0;
|
say_team_line->complete = 0;
|
||||||
say_team_line->enter = C_SayTeam;
|
say_team_line->enter = C_SayTeam;
|
||||||
say_team_line->width = con_linewidth - 10;
|
say_team_line->width = con_linewidth - 10;
|
||||||
say_team_line->user_data = 0;
|
say_team_line->user_data = 0;
|
||||||
say_team_line->draw = 0;//C_DrawInput;
|
say_team_line->draw = 0;
|
||||||
|
|
||||||
C_CheckResize ();
|
C_CheckResize ();
|
||||||
|
|
||||||
|
@ -575,7 +581,7 @@ C_KeyEvent (knum_t key, short unicode, qboolean down)
|
||||||
/* DRAWING */
|
/* DRAWING */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
DrawInputLine (int x, int y, inputline_t *il)
|
DrawInputLine (int x, int y, int cursor, inputline_t *il)
|
||||||
{
|
{
|
||||||
const char *s = il->lines[il->edit_line] + il->scroll;
|
const char *s = il->lines[il->edit_line] + il->scroll;
|
||||||
|
|
||||||
|
@ -585,19 +591,29 @@ DrawInputLine (int x, int y, inputline_t *il)
|
||||||
} else {
|
} else {
|
||||||
Draw_nString (x, y, s, il->width - 1);
|
Draw_nString (x, y, s, il->width - 1);
|
||||||
}
|
}
|
||||||
Draw_Character (x + ((il->linepos - il->scroll) << 3), y,
|
if (cursor) {
|
||||||
10 + ((int) (*con_data.realtime * con_cursorspeed) & 1));
|
float t = *con_data.realtime * con_cursorspeed;
|
||||||
|
int ch = 10 + ((int) (t) & 1);
|
||||||
|
Draw_Character (x + ((il->linepos - il->scroll) << 3), y, ch);
|
||||||
|
}
|
||||||
if (strlen (s) >= il->width)
|
if (strlen (s) >= il->width)
|
||||||
Draw_Character (x + ((il->width - 1) << 3), y, '>' | 0x80);
|
Draw_Character (x + ((il->width - 1) << 3), y, '>' | 0x80);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
C_DrawInputLine (inputline_t *il)
|
||||||
|
{
|
||||||
|
il_data_t *data = il->user_data;
|
||||||
|
DrawInputLine (data->x, data->y, data->cursor, il);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
DrawInput (void)
|
DrawInput (void)
|
||||||
{
|
{
|
||||||
if (key_dest != key_console)// && !con_data.force_commandline)
|
if (key_dest != key_console)// && !con_data.force_commandline)
|
||||||
return; // don't draw anything (always draw if not active)
|
return; // don't draw anything (always draw if not active)
|
||||||
|
|
||||||
DrawInputLine (8, con_vislines - 22, input_line);
|
DrawInputLine (8, con_vislines - 22, 1, input_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -637,10 +653,10 @@ DrawNotify (void)
|
||||||
|
|
||||||
if (chat_team) {
|
if (chat_team) {
|
||||||
Draw_String (8, v, "say_team:");
|
Draw_String (8, v, "say_team:");
|
||||||
DrawInputLine (80, v, say_team_line);
|
DrawInputLine (80, v, 1, say_team_line);
|
||||||
} else {
|
} else {
|
||||||
Draw_String (8, v, "say:");
|
Draw_String (8, v, "say:");
|
||||||
DrawInputLine (40, v, say_line);
|
DrawInputLine (40, v, 1, say_line);
|
||||||
}
|
}
|
||||||
v += 8;
|
v += 8;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,10 @@ static const char rcsid[] =
|
||||||
#include "QF/sys.h"
|
#include "QF/sys.h"
|
||||||
#include "QF/vfs.h"
|
#include "QF/vfs.h"
|
||||||
|
|
||||||
|
//FIXME need a better way to communicate this (bah, need a better menu system
|
||||||
|
// in general :P)
|
||||||
|
void C_DrawInputLine (inputline_t *il);
|
||||||
|
|
||||||
typedef struct menu_pic_s {
|
typedef struct menu_pic_s {
|
||||||
struct menu_pic_s *next;
|
struct menu_pic_s *next;
|
||||||
int x, y;
|
int x, y;
|
||||||
|
@ -477,6 +481,7 @@ Menu_Load (void)
|
||||||
}
|
}
|
||||||
PR_InitRuntime (&menu_pr_state);
|
PR_InitRuntime (&menu_pr_state);
|
||||||
Cbuf_Progs_SetCbuf (&menu_pr_state, con_data.cbuf);
|
Cbuf_Progs_SetCbuf (&menu_pr_state, con_data.cbuf);
|
||||||
|
InputLine_Progs_SetDraw (&menu_pr_state, C_DrawInputLine);
|
||||||
PR_ExecuteProgram (&menu_pr_state, menu_init);
|
PR_ExecuteProgram (&menu_pr_state, menu_init);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ static const char rcsid[] =
|
||||||
typedef struct {
|
typedef struct {
|
||||||
inputline_t **lines;
|
inputline_t **lines;
|
||||||
int max_lines;
|
int max_lines;
|
||||||
|
void (*draw)(inputline_t *il);
|
||||||
} il_resources_t;
|
} il_resources_t;
|
||||||
|
|
||||||
//FIXME need to robustify the interface to avoid segfaults caused by errant
|
//FIXME need to robustify the interface to avoid segfaults caused by errant
|
||||||
|
@ -99,6 +100,7 @@ bi_InputLine_Create (progs_t *pr)
|
||||||
R_INT (pr) = 0;
|
R_INT (pr) = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
(*line)->draw = res->draw;
|
||||||
handle = PR_Zone_Malloc (pr, sizeof (inputline_t *));
|
handle = PR_Zone_Malloc (pr, sizeof (inputline_t *));
|
||||||
*(inputline_t**)handle = *line;
|
*(inputline_t**)handle = *line;
|
||||||
R_INT (pr) = handle - pr->pr_globals;
|
R_INT (pr) = handle - pr->pr_globals;
|
||||||
|
@ -203,22 +205,8 @@ static void
|
||||||
bi_InputLine_Draw (progs_t *pr)
|
bi_InputLine_Draw (progs_t *pr)
|
||||||
{
|
{
|
||||||
inputline_t *il = get_inputline (pr, P_INT (pr, 0), "InputLine_Draw");
|
inputline_t *il = get_inputline (pr, P_INT (pr, 0), "InputLine_Draw");
|
||||||
int x = P_INT (pr, 1);
|
|
||||||
int y = P_INT (pr, 2);
|
|
||||||
int cursor = P_INT (pr, 3);
|
|
||||||
const char *s = il->lines[il->edit_line] + il->scroll;
|
|
||||||
|
|
||||||
if (il->scroll) {
|
il->draw (il);
|
||||||
Draw_Character (x, y, '<' | 0x80);
|
|
||||||
Draw_nString (x + 8, y, s + 1, il->width - 2);
|
|
||||||
} else {
|
|
||||||
Draw_nString (x, y, s, il->width - 1);
|
|
||||||
}
|
|
||||||
if (cursor)
|
|
||||||
Draw_Character (x + ((il->linepos - il->scroll) << 3), y,
|
|
||||||
10 + ((int) (*pr->time * 4) & 1));
|
|
||||||
if (strlen (s) >= il->width)
|
|
||||||
Draw_Character (x + ((il->width - 1) << 3), y, '>' | 0x80);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -253,3 +241,10 @@ InputLine_Progs_Init (progs_t *pr)
|
||||||
PR_AddBuiltin (pr, "InputLine_Process", bi_InputLine_Process, -1);
|
PR_AddBuiltin (pr, "InputLine_Process", bi_InputLine_Process, -1);
|
||||||
PR_AddBuiltin (pr, "InputLine_Draw", bi_InputLine_Draw, -1);
|
PR_AddBuiltin (pr, "InputLine_Draw", bi_InputLine_Draw, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
InputLine_Progs_SetDraw (progs_t *pr, void (*draw)(inputline_t *))
|
||||||
|
{
|
||||||
|
il_resources_t *res = PR_Resources_Find (pr, "InputLine");
|
||||||
|
res->draw = draw;
|
||||||
|
}
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
#ifndef __ruamoko_InputLine_h
|
#ifndef __ruamoko_InputLine_h
|
||||||
#define __ruamoko_InputLine_h
|
#define __ruamoko_InputLine_h
|
||||||
|
|
||||||
#include "Rect.h"
|
#include "Object.h"
|
||||||
|
|
||||||
#define OLD_API // FIXME update the input line api
|
|
||||||
|
|
||||||
struct _inputline_t = {}; // opaque type :)
|
struct _inputline_t = {}; // opaque type :)
|
||||||
typedef _inputline_t [] inputline_t;
|
typedef _inputline_t [] inputline_t;
|
||||||
|
@ -14,17 +12,20 @@ typedef _inputline_t [] inputline_t;
|
||||||
@extern void (inputline_t il) InputLine_Destroy;
|
@extern void (inputline_t il) InputLine_Destroy;
|
||||||
@extern void (inputline_t il) InputLine_Clear;
|
@extern void (inputline_t il) InputLine_Clear;
|
||||||
@extern void (inputline_t il, integer ch) InputLine_Process;
|
@extern void (inputline_t il, integer ch) InputLine_Process;
|
||||||
#ifdef OLD_API
|
@extern void (inputline_t il) InputLine_Draw;
|
||||||
@extern void (inputline_t il, integer x, integer y, integer cursor) InputLine_Draw;
|
|
||||||
#else
|
|
||||||
@extern void (inputline_t il, integer cursor) InputLine_Draw;
|
|
||||||
#endif
|
|
||||||
@extern void (inputline_t il, string str) InputLine_SetText;
|
@extern void (inputline_t il, string str) InputLine_SetText;
|
||||||
@extern string (inputline_t il) InputLine_GetText;
|
@extern string (inputline_t il) InputLine_GetText;
|
||||||
|
|
||||||
|
struct il_data_t = {
|
||||||
|
integer x, y;
|
||||||
|
BOOL cursor;
|
||||||
|
};
|
||||||
|
|
||||||
|
@class Rect;
|
||||||
|
|
||||||
@interface InputLine: Object
|
@interface InputLine: Object
|
||||||
{
|
{
|
||||||
Rect frame;
|
il_data_t control;
|
||||||
inputline_t il;
|
inputline_t il;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
#include "InputLine.h"
|
#include "InputLine.h"
|
||||||
|
|
||||||
|
#include "Rect.h"
|
||||||
|
|
||||||
inputline_t (integer lines, integer size, integer prompt) InputLine_Create = #0;
|
inputline_t (integer lines, integer size, integer prompt) InputLine_Create = #0;
|
||||||
void (inputline_t il, void [] data) InputLine_SetUserData = #0;
|
void (inputline_t il, void [] data) InputLine_SetUserData = #0;
|
||||||
void (inputline_t il, integer width) InputLine_SetWidth = #0;
|
void (inputline_t il, integer width) InputLine_SetWidth = #0;
|
||||||
void (inputline_t il) InputLine_Destroy = #0;
|
void (inputline_t il) InputLine_Destroy = #0;
|
||||||
void (inputline_t il) InputLine_Clear = #0;
|
void (inputline_t il) InputLine_Clear = #0;
|
||||||
void (inputline_t il, integer ch) InputLine_Process = #0;
|
void (inputline_t il, integer ch) InputLine_Process = #0;
|
||||||
#ifdef OLD_API
|
void (inputline_t il) InputLine_Draw = #0;
|
||||||
void (inputline_t il, integer x, integer y, integer cursor) InputLine_Draw = #0;
|
|
||||||
#else
|
|
||||||
void (inputline_t il, integer cursor) InputLine_Draw = #0;
|
|
||||||
#endif
|
|
||||||
void (inputline_t il, string str) InputLine_SetText = #0;
|
void (inputline_t il, string str) InputLine_SetText = #0;
|
||||||
string (inputline_t il) InputLine_GetText = #0;
|
string (inputline_t il) InputLine_GetText = #0;
|
||||||
|
|
||||||
|
@ -19,17 +17,18 @@ string (inputline_t il) InputLine_GetText = #0;
|
||||||
- (id) initWithBounds: (Rect)aRect promptCharacter: (integer)char
|
- (id) initWithBounds: (Rect)aRect promptCharacter: (integer)char
|
||||||
{
|
{
|
||||||
id (self) = [super init];
|
id (self) = [super init];
|
||||||
id (frame) = [aRect copy];
|
control.x = aRect.origin.x;
|
||||||
|
control.y = aRect.origin.y;
|
||||||
|
control.cursor = NO;
|
||||||
|
|
||||||
il = InputLine_Create (frame.size.height, frame.size.width, char);
|
il = InputLine_Create (aRect.size.height, aRect.size.width, char);
|
||||||
InputLine_SetUserData (il, frame);
|
InputLine_SetUserData (il, &control);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) free
|
- (void) free
|
||||||
{
|
{
|
||||||
[frame free];
|
|
||||||
InputLine_Destroy (il);
|
InputLine_Destroy (il);
|
||||||
[super free];
|
[super free];
|
||||||
}
|
}
|
||||||
|
@ -46,11 +45,8 @@ string (inputline_t il) InputLine_GetText = #0;
|
||||||
|
|
||||||
- (void) draw: (BOOL)cursor
|
- (void) draw: (BOOL)cursor
|
||||||
{
|
{
|
||||||
#ifdef OLD_API
|
control.cursor = cursor;
|
||||||
InputLine_Draw (il, frame.origin.x, frame.origin.y, cursor);
|
InputLine_Draw (il);
|
||||||
#else
|
|
||||||
InputLine_Draw (il, cursor);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setText: (string)text
|
- (void) setText: (string)text
|
||||||
|
|
Loading…
Reference in a new issue