2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 float con_cursorspeed
= 4;
35 #define CON_TEXTSIZE 16384
37 qboolean con_forcedup
; // because no entities to refresh
39 int con_totallines
; // total lines in console scrollback
40 int con_backscroll
; // lines up from bottom to display
41 int con_current
; // where next message will be printed
42 int con_x
; // offset in current line for next print
45 cvar_t con_notifytime
= {"con_notifytime","3"}; //seconds
47 #define NUM_CON_TIMES 4
48 float con_times
[NUM_CON_TIMES
]; // realtime time the line was generated
49 // for transparent notify lines
53 qboolean con_debuglog
;
55 #define MAXCMDLINE 256
56 extern char key_lines
[32][MAXCMDLINE
];
58 extern int key_linepos
;
61 qboolean con_initialized
;
63 int con_notifylines
; // scan lines to clear for notify lines
65 extern void M_Menu_Main_f (void);
67 void M_OSK_Draw (void);
68 void Con_OSK_f (char *input
, char *output
, int outlen
);
69 void Con_OSK_Key(int key
);
70 void Con_DrawOSK(void);
77 void Con_ToggleConsole_f (void)
79 if (key_dest
== key_console
)
81 if (cls
.state
== ca_connected
)
84 key_lines
[edit_line
][1] = 0; // clear any typing
93 key_dest
= key_console
;
95 SCR_EndLoadingPlaque ();
96 memset (con_times
, 0, sizeof(con_times
));
104 void Con_Clear_f (void)
107 Q_memset (con_text
, ' ', CON_TEXTSIZE
);
116 void Con_ClearNotify (void)
120 for (i
=0 ; i
<NUM_CON_TIMES
; i
++)
130 extern qboolean team_message
;
132 void Con_MessageMode_f (void)
134 key_dest
= key_message
;
135 team_message
= false;
144 void Con_MessageMode2_f (void)
146 key_dest
= key_message
;
155 If the line width has changed, reformat the buffer.
158 void Con_CheckResize (void)
160 int i
, j
, width
, oldwidth
, oldtotallines
, numlines
, numchars
;
161 char tbuf
[CON_TEXTSIZE
];
163 width
= (vid
.width
>> 3) - 2;
165 if (width
== con_linewidth
)
168 if (width
< 1) // video hasn't been initialized yet
171 con_linewidth
= width
;
172 con_totallines
= CON_TEXTSIZE
/ con_linewidth
;
173 Q_memset (con_text
, ' ', CON_TEXTSIZE
);
177 oldwidth
= con_linewidth
;
178 con_linewidth
= width
;
179 oldtotallines
= con_totallines
;
180 con_totallines
= CON_TEXTSIZE
/ con_linewidth
;
181 numlines
= oldtotallines
;
183 if (con_totallines
< numlines
)
184 numlines
= con_totallines
;
188 if (con_linewidth
< numchars
)
189 numchars
= con_linewidth
;
191 Q_memcpy (tbuf
, con_text
, CON_TEXTSIZE
);
192 Q_memset (con_text
, ' ', CON_TEXTSIZE
);
194 for (i
=0 ; i
<numlines
; i
++)
196 for (j
=0 ; j
<numchars
; j
++)
198 con_text
[(con_totallines
- 1 - i
) * con_linewidth
+ j
] =
199 tbuf
[((con_current
- i
+ oldtotallines
) %
200 oldtotallines
) * oldwidth
+ j
];
208 con_current
= con_totallines
- 1;
219 #define MAXGAMEDIRLEN 1000
220 char temp
[MAXGAMEDIRLEN
+1];
221 char *t2
= "/qconsole.log";
223 con_debuglog
= COM_CheckParm("-condebug");
227 if (strlen (com_gamedir
) < (MAXGAMEDIRLEN
- strlen (t2
)))
229 sprintf (temp
, "%s%s", com_gamedir
, t2
);
234 con_text
= Hunk_AllocName (CON_TEXTSIZE
, "context");
235 Q_memset (con_text
, ' ', CON_TEXTSIZE
);
239 Con_Printf ("Console initialized.\n");
242 // register our commands
244 Cvar_RegisterVariable (&con_notifytime
);
246 Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f
);
247 Cmd_AddCommand ("messagemode", Con_MessageMode_f
);
248 Cmd_AddCommand ("messagemode2", Con_MessageMode2_f
);
249 Cmd_AddCommand ("clear", Con_Clear_f
);
250 con_initialized
= true;
259 void Con_Linefeed (void)
263 Q_memset (&con_text
[(con_current
%con_totallines
)*con_linewidth
]
264 , ' ', con_linewidth
);
271 Handles cursor positioning, line wrapping, etc
272 All console printing must go through this in order to be logged to disk
273 If no console is visible, the notify window will pop up.
276 void Con_Print (char *txt
)
287 mask
= 128; // go to colored text
288 S_LocalSound ("misc/talk.wav");
292 else if (txt
[0] == 2)
294 mask
= 128; // go to colored text
304 for (l
=0 ; l
< con_linewidth
; l
++)
309 if (l
!= con_linewidth
&& (con_x
+ l
> con_linewidth
) )
324 // mark time for transparent overlay
325 if (con_current
>= 0)
326 con_times
[con_current
% NUM_CON_TIMES
] = realtime
;
340 default: // display character and advance
341 y
= con_current
% con_totallines
;
342 con_text
[y
*con_linewidth
+con_x
] = c
| mask
;
344 if (con_x
>= con_linewidth
)
358 void Con_DebugLog(char *file
, char *fmt
, ...)
361 static char data
[1024];
364 va_start(argptr
, fmt
);
365 vsprintf(data
, fmt
, argptr
);
367 fd
= open(file
, O_WRONLY
| O_CREAT
| O_APPEND
, 0666);
368 write(fd
, data
, strlen(data
));
377 Handles cursor positioning, line wrapping, etc
380 #define MAXPRINTMSG 4096
381 // FIXME: make a buffer size safe vsprintf?
382 void Con_Printf (char *fmt
, ...)
385 char msg
[MAXPRINTMSG
];
386 static qboolean inupdate
;
388 va_start (argptr
,fmt
);
389 vsprintf (msg
,fmt
,argptr
);
392 // also echo to debugging console
393 Sys_Printf ("%s", msg
); // also echo to debugging console
395 // log all messages to file
397 Con_DebugLog(va("%s/qconsole.log",com_gamedir
), "%s", msg
);
399 if (!con_initialized
)
402 if (cls
.state
== ca_dedicated
)
403 return; // no graphics mode
405 // write it to the scrollable buffer
408 // update the screen if the console is displayed
409 if (cls
.signon
!= SIGNONS
&& !scr_disabled_for_loading
)
411 // protect against infinite loop if something in SCR_UpdateScreen calls
426 A Con_Printf that only shows up if the "developer" cvar is set
429 void Con_DPrintf (char *fmt
, ...)
432 char msg
[MAXPRINTMSG
];
434 if (!developer
.value
)
435 return; // don't confuse non-developers with techie stuff...
437 va_start (argptr
,fmt
);
438 vsprintf (msg
,fmt
,argptr
);
441 Con_Printf ("%s", msg
);
449 Okay to call even when the screen can't be updated
452 void Con_SafePrintf (char *fmt
, ...)
458 va_start (argptr
,fmt
);
459 vsprintf (msg
,fmt
,argptr
);
462 temp
= scr_disabled_for_loading
;
463 scr_disabled_for_loading
= true;
464 Con_Printf ("%s", msg
);
465 scr_disabled_for_loading
= temp
;
470 ==============================================================================
474 ==============================================================================
482 The input line scrolls horizontally if typing goes beyond the right edge
485 void Con_DrawInput (void)
491 if (key_dest
!= key_console
&& !con_forcedup
)
492 return; // don't draw anything
494 text
= key_lines
[edit_line
];
496 // add the cursor frame
497 text
[key_linepos
] = 10+((int)(realtime
*con_cursorspeed
)&1);
499 // fill out remainder with spaces
500 for (i
=key_linepos
+1 ; i
< con_linewidth
; i
++)
503 // prestep if horizontally scrolling
504 if (key_linepos
>= con_linewidth
)
505 text
+= 1 + key_linepos
- con_linewidth
;
510 for (i
=0 ; i
<con_linewidth
; i
++)
511 Draw_Character ( (i
+1)<<3, con_vislines
- 16, text
[i
]);
514 key_lines
[edit_line
][key_linepos
] = 0;
522 Draws the last few lines of output transparently over the game top
525 void Con_DrawNotify (void)
531 extern char chat_buffer
[];
534 for (i
= con_current
-NUM_CON_TIMES
+1 ; i
<=con_current
; i
++)
538 time
= con_times
[i
% NUM_CON_TIMES
];
541 time
= realtime
- time
;
542 if (time
> con_notifytime
.value
)
544 text
= con_text
+ (i
% con_totallines
)*con_linewidth
;
549 for (x
= 0 ; x
< con_linewidth
; x
++)
550 Draw_Character ( (x
+1)<<3, v
, text
[x
]);
556 if (key_dest
== key_message
)
563 Draw_String (8, v
, "say:");
564 while(chat_buffer
[x
])
566 Draw_Character ( (x
+5)<<3, v
, chat_buffer
[x
]);
569 Draw_Character ( (x
+5)<<3, v
, 10+((int)(realtime
*con_cursorspeed
)&1));
573 if (v
> con_notifylines
)
581 Draws the console with the solid background
582 The typing input line at the bottom should only be drawn if typing is allowed
585 void Con_DrawConsole (int lines
, qboolean drawinput
)
595 // draw the background
596 Draw_ConsoleBackground (lines
);
599 con_vislines
= lines
;
601 rows
= (lines
-16)>>3; // rows of text to draw
602 y
= lines
- 16 - (rows
<<3); // may start slightly negative
604 for (i
= con_current
- rows
+ 1 ; i
<=con_current
; i
++, y
+=8 )
606 j
= i
- con_backscroll
;
609 text
= con_text
+ (j
% con_totallines
)*con_linewidth
;
611 for (x
=0 ; x
<con_linewidth
; x
++)
612 Draw_Character ( (x
+1)<<3, y
, text
[x
]);
615 // draw the input prompt, user text, and cursor if desired
622 static qboolean scr_osk_active
= false;
625 void Con_SetOSKActive(qboolean active
) {
626 scr_osk_active
= active
;
629 qboolean
Con_isSetOSKActive(void) {
630 return scr_osk_active
;
633 void Con_DrawOSK(void) {
634 if (scr_osk_active
) {
644 void Con_NotifyBox (char *text
)
648 // during startup for sound / cd warnings
649 Con_Printf("\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n");
653 Con_Printf ("Press a key.\n");
654 Con_Printf("\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n");
656 key_count
= -2; // wait for a key down and up
657 key_dest
= key_console
;
661 t1
= Sys_FloatTime ();
663 Sys_SendKeyEvents ();
664 t2
= Sys_FloatTime ();
665 realtime
+= t2
-t1
; // make the cursor blink
666 } while (key_count
< 0);
670 realtime
= 0; // put the cursor back to invisible