forked from QW-Group/ezquake-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.c
1125 lines (928 loc) · 26.8 KB
/
console.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 1996-1997 Id Software, Inc.
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 the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
$Id: console.c,v 1.63 2007-10-04 13:48:11 dkure Exp $
*/
// console.c
#include "quakedef.h"
#include <fcntl.h>
#ifdef _WIN32
#include <io.h>
#else
#include <stdio.h>
#endif
#include "gl_model.h"
#include "gl_local.h"
#if defined(_WIN32) || defined(__linux__) || defined(__FreeBSD__)
#include "tr_types.h"
#endif // _WIN32 || __linux__ || __FreeBSD__
#include "keys.h"
#include "ignore.h"
#include "logging.h"
#include "utils.h"
#include "localtime.h"
#include "irc.h"
#define MINIMUM_CONBUFSIZE (1 << 15)
#define DEFAULT_CONBUFSIZE (1 << 16)
#define MAXIMUM_CONBUFSIZE (1 << 22)
#define MAX_NOTIFICATION_TIME 10
console_t con;
int con_margin=0; // kazik: margin on the left side
qbool con_addtimestamp;
int con_ormask;
int con_linewidth; // characters across screen
int con_totallines; // total lines in console scrollback
float con_cursorspeed = 4;
cvar_t con_notify = {"con_notify", "1"};
cvar_t _con_notifylines = {"con_notifylines","4"};
cvar_t con_notifytime = {"con_notifytime","3"}; //seconds
cvar_t con_wordwrap = {"con_wordwrap","1"};
cvar_t con_clearnotify = {"con_clearnotify","1"};
cvar_t con_highlight = {"con_highlight","0"};
cvar_t con_highlight_mark = {"con_highlight_mark",""};
cvar_t con_sound_mm1_file = {"s_mm1_file", "misc/talk.wav"};
cvar_t con_sound_mm2_file = {"s_mm2_file", "misc/talk.wav"};
cvar_t con_sound_spec_file = {"s_spec_file", "misc/talk.wav"};
cvar_t con_sound_other_file = {"s_otherchat_file", "misc/talk.wav"};
cvar_t con_sound_mm1_volume = {"s_mm1_volume", "1"};
cvar_t con_sound_mm2_volume = {"s_mm2_volume", "1"};
cvar_t con_sound_spec_volume = {"s_spec_volume", "1"};
cvar_t con_sound_other_volume = {"s_otherchat_volume", "1"};
cvar_t con_timestamps = {"con_timestamps", "0"};
cvar_t con_shift = {"con_shift", "-10"};
cvar_t cl_textEncoding = {"cl_textencoding", "0"};
cvar_t con_mm2_only = {"con_mm2_only", "0"};
#ifdef _WIN32
cvar_t con_toggle_deadkey = {"con_deadkey", "1"};
#endif
#define NUM_CON_TIMES 16
float con_times[NUM_CON_TIMES]; // cls.realtime time the line was generated
// for transparent notify lines
int con_vislines;
int con_notifylines; // scan lines to clear for notify lines
qbool con_initialized = false;
qbool con_suppress = false;
FILE *qconsole_log = NULL;
char *months[12] = {
"jan",
"feb",
"mar",
"apr",
"may",
"jun",
"jul",
"aug",
"sep",
"oct",
"nov",
"dec" };
char *days[7] = {
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"};
void Date_f (void)
{
// Sun Nov 05 2000, 16:39
SYSTEMTIME tm;
char *day, *month;
GetLocalTime(&tm);
month = months[tm.wMonth-1];
day = days[tm.wDayOfWeek];
con_ormask = 128;
Com_Printf ("%s %s %02d, %2d:%02d %d\n", day, month, tm.wDay, tm.wHour, tm.wMinute, tm.wYear);
con_ormask = 0;
}
void MakeStringRed(char *s)
{
while (*s)
{
if (*s >= '0' && *s <= '9')
*s |= 128;
s++;
}
}
void MakeStringYellow(char *s)
{
while (*s)
{
if (*s >= '0' && *s <= '9')
*s -= 30;
s++;
}
}
/*
==================
Calendar_f - prints calendar
==================
*/
void Calendar_f(void)
{
int alldays, day, column;
SYSTEMTIME tm;
GetLocalTime(&tm);
Date_f();
Com_Printf (" mo tu we th fr sa su\n");
alldays = 31;
day = tm.wDay;
day -= (tm.wDayOfWeek==0 ? 7 : tm.wDayOfWeek) - 1;
day = (day % 7);
if (day > 1)
day -= 7;
column = 0;
switch (tm.wMonth)
{
case 1: alldays = 31; break;
case 2: alldays = (tm.wYear % 400 ? 28 : (tm.wYear % 100 ? 29 : (tm.wYear % 4) ? 28 : 29)); break;
case 3: alldays = 31; break;
case 4: alldays = 30; break;
case 5: alldays = 31; break;
case 6: alldays = 30; break;
case 7: alldays = 31; break;
case 8: alldays = 31; break;
case 9: alldays = 30; break;
case 10: alldays = 31; break;
case 11: alldays = 30; break;
case 12: alldays = 31; break;
default: alldays = 31; break;
}
while (day <= alldays)
{
column ++;
if (day > 0)
{
char buf[8];
snprintf(buf, sizeof (buf), "%3d", day);
if (day == tm.wDay)
; // MakeStringYellow(buf);
else
{
if (column == 7)
MakeStringYellow(buf);
else
MakeStringRed(buf);
}
Com_Printf ("%s", buf);
}
else
Com_Printf (" ");
if (day == alldays || column == 7)
{
column = 0;
Com_Printf ("\n");
}
day++;
}
}
void Con_ToggleConsole_f (void) {
Key_ClearTyping ();
if (key_dest == key_console) {
if (!SCR_NEED_CONSOLE_BACKGROUND)
key_dest = key_dest_beforecon;
} else {
key_dest_beforecon = key_dest;
key_dest = key_console;
#ifdef _WIN32
if (con_toggle_deadkey.integer) {
Sys_CancelDeadKey ();
}
#endif
}
if (con_clearnotify.value)
Con_ClearNotify ();
}
void Con_SetColor(int idx_from, int count, int c) {
int i;
if (idx_from < 0 || idx_from >= con.maxsize || count < 0 || idx_from + count > con.maxsize)
Sys_Error("Con_SetColor: wrong idx");;
for (i = idx_from; i < count; i++) {
memset(&con.clr[i], 0, sizeof(clrinfo_t)); // zeroing whole struct
con.clr[i].c = c;
con.clr[i].i = i;
}
}
void Con_SetWhite (void) {
// no need for memset(), Con_SetColor() do it too
// memset (con.clr, 0, con.maxsize * sizeof(clrinfo_t)); // set whole struct array to zero
Con_SetColor(0, con.maxsize, COLOR_WHITE); // set white color
}
void Con_Clear_f (void) {
int i;
con.numlines = 0;
for (i = 0; i < con.maxsize; i++)
con.text[i] = ' ';
con.display = con.current;
Con_SetWhite(); // set default color to white
}
void Con_ClearNotify (void) {
int i;
for (i = 0; i < NUM_CON_TIMES; i++)
con_times[i] = 0;
}
void Con_MessageMode_Common (chat_type t) {
if (cls.state != ca_active)
return;
chat_team = t;
key_dest_beforemm = key_dest; // where to return after we finish typing
key_dest = key_message;
chat_buffer[0] = 0;
chat_linepos = 0;
}
void Con_MessageMode_f (void) {
Con_MessageMode_Common(chat_mm1);
}
void Con_MessageMode2_f (void) {
if (cls.mvdplayback == QTV_PLAYBACK)
{
// mm2 has no meaning in QTV so let's save some keys and make it QTV->game chat
Con_MessageMode_Common(chat_qtvtogame);
}
else
{
Con_MessageMode_Common(chat_mm2);
}
}
#ifdef WITH_IRC
void Con_MessageModeIRC_f (void) {
Con_MessageMode_Common(chat_irc);
}
#endif
void Con_MessageModeQTVtoGAME_f (void) {
Con_MessageMode_Common(chat_qtvtogame);
}
//If the line width has changed, reformat the buffer
void Con_CheckResize (void) {
int i, j, width, oldwidth, oldtotallines, numlines, numchars;
wchar *tempbuf;
width = (vid.width >> 3) - 2;
if (width == con_linewidth)
return;
if (width < 1) { // video hasn't been initialized yet
#if defined(_WIN32) || defined(__linux__) || defined(__FreeBSD__)
cvar_t *cv = Cvar_Find(r_conwidth.name); // r_conwidth not yet registered, but let user specifie it via
// config.cfg or somehow else
if ( cv ) {
width = max(320, cv->integer);
width &= 0xfff8; // make it a multiple of eight
width = (width >> 3) - 2;
width = max(width, 38);
}
else
#endif
width = 38;
con_linewidth = width;
con_totallines = con.maxsize / con_linewidth;
for (i = 0; i < con.maxsize; i++)
con.text[i] = ' ';
Con_SetWhite();
} else {
int idx_old, idx_new;
clrinfo_t *clr;
oldwidth = con_linewidth;
con_linewidth = width;
oldtotallines = con_totallines;
con_totallines = con.maxsize / con_linewidth;
numlines = oldtotallines;
if (con_totallines < numlines)
numlines = con_totallines;
numchars = oldwidth;
if (con_linewidth < numchars)
numchars = con_linewidth;
tempbuf = (wchar *) Hunk_TempAlloc(con.maxsize * sizeof(wchar));
memcpy (tempbuf, con.text, con.maxsize * sizeof(wchar));
for (i = 0; i < con.maxsize; i++)
con.text[i] = ' ';
clr = Q_malloc(con.maxsize * sizeof(clrinfo_t)); // alloc temporaly
memcpy(clr, con.clr, con.maxsize * sizeof(clrinfo_t)); // save color array
Con_SetWhite(); // wipe color array entirely
for (i = 0; i < numlines; i++) {
for (j = 0; j < numchars; j++) {
idx_new = (con_totallines - 1 - i) * con_linewidth + j;
idx_old = ((con.current - i + oldtotallines) % oldtotallines) * oldwidth + j;
con.text[idx_new] = tempbuf[idx_old];
con.clr[idx_new] = clr[idx_old]; // restore color info
con.clr[idx_new].i = idx_new; // re-index
}
}
Con_ClearNotify ();
Q_free(clr); // free
}
con.current = con_totallines - 1;
con.display = con.current;
}
char readableChars[256] = { '.', '_' , '_' , '_' , '_' , '.' , '_' , '_' , '_' , '_' , '\n' , '_' , '\n' , '>' , '.' , '.',
'[', ']', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '_', '_', '_'};
static void Con_CreateReadableChars(void) {
int i;
for (i = 32; i < 127; i++)
readableChars[i] = readableChars[128 + i] = i;
readableChars[127] = readableChars[128 + 127] = '_';
for (i = 0; i < 32; i++)
readableChars[128 + i] = readableChars[i];
readableChars[128] = '_';
readableChars[10 + 128] = '_';
readableChars[12 + 128] = '_';
}
static void Con_InitConsoleBuffer(console_t *conbuffer, int size) {
con.maxsize = size;
con.text = (wchar *) Hunk_AllocName(con.maxsize * sizeof(wchar), "console_buffer");
con.clr = (clrinfo_t *) Hunk_AllocName(con.maxsize * sizeof(clrinfo_t), "console_clr");
}
void Con_Init (void) {
int i, conbufsize;
//Tei: moved there, because on windows can't capture the output for debug purposes
if (!qconsole_log && COM_CheckParm("-condebug")) {
char tmp_path[MAX_OSPATH] = {0};
snprintf(&tmp_path[0], sizeof(tmp_path), "%s/qw/qconsole.log", com_basedir);
qconsole_log = fopen(tmp_path, "a");
}
if ((i = COM_CheckParm("-conbufsize")) && i + 1 < COM_Argc()) {
conbufsize = Q_atoi(COM_Argv(i + 1)) << 10;
conbufsize = bound (MINIMUM_CONBUFSIZE , conbufsize, MAXIMUM_CONBUFSIZE);
} else {
conbufsize = DEFAULT_CONBUFSIZE;
}
Con_InitConsoleBuffer(&con, conbufsize);
con_linewidth = -1;
Con_CheckResize ();
Con_CreateReadableChars();
con_initialized = true;
Com_Printf_State (PRINT_OK, "Console initialized\n");
Cvar_SetCurrentGroup(CVAR_GROUP_CONSOLE);
// register our commands and cvars
Cvar_Register (&_con_notifylines);
Cvar_Register (&con_notifytime);
Cvar_Register (&con_wordwrap);
Cvar_Register (&con_clearnotify);
Cvar_Register (&con_notify);
#ifdef _WIN32
Cvar_Register (&con_toggle_deadkey);
#endif
// added by jogi start
Cvar_Register (&con_highlight);
Cvar_Register (&con_highlight_mark);
// added by jogi stop
Cvar_Register (&con_timestamps);
Cvar_Register (&con_shift);
Cvar_Register (&con_mm2_only);
Cvar_ResetCurrentGroup();
Cvar_SetCurrentGroup(CVAR_GROUP_SOUND);
Cvar_Register (&con_sound_mm1_file);
Cvar_Register (&con_sound_mm2_file);
Cvar_Register (&con_sound_spec_file);
Cvar_Register (&con_sound_other_file);
Cvar_Register (&con_sound_mm1_volume);
Cvar_Register (&con_sound_mm2_volume);
Cvar_Register (&con_sound_spec_volume);
Cvar_Register (&con_sound_other_volume);
// if you don't like renaming things in this way, let's have some talk with tea - johnnycz
Cmd_AddLegacyCommand("con_sound_mm1_file", "s_mm1_file");
Cmd_AddLegacyCommand("con_sound_mm2_file", "s_mm2_file");
Cmd_AddLegacyCommand("con_sound_spec_file", "s_spec_file");
Cmd_AddLegacyCommand("con_sound_other_file", "s_otherchat_file");
Cmd_AddLegacyCommand("con_sound_mm1_volume", "s_mm1_volume");
Cmd_AddLegacyCommand("con_sound_mm2_volume", "s_mm2_volume");
Cmd_AddLegacyCommand("con_sound_spec_volume", "s_spec_volume");
Cmd_AddLegacyCommand("con_sound_other_volume", "s_otherchat_volume");
Cvar_ResetCurrentGroup();
Cvar_Register(&cl_textEncoding);
Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f);
Cmd_AddCommand ("messagemode", Con_MessageMode_f);
Cmd_AddCommand ("messagemode2", Con_MessageMode2_f);
#ifdef WITH_IRC
Cmd_AddCommand ("messagemodeirc", Con_MessageModeIRC_f);
#endif
Cmd_AddCommand ("messagemodeqtvtogame", Con_MessageModeQTVtoGAME_f);
Cmd_AddCommand ("clear", Con_Clear_f);
Cmd_AddCommand ("date", Date_f);
Cmd_AddCommand ("calendar", Calendar_f);
}
void Con_Shutdown (void) {
if (qconsole_log)
fclose(qconsole_log);
}
void Con_Linefeed (void) {
int idx, i;
con.x = 0;
con.x = con_margin; // kazik
if (con.display == con.current)
con.display++;
con.current++;
if (con.numlines < con_totallines)
con.numlines++;
idx = (con.current%con_totallines)*con_linewidth;
for (i = 0; i < con_linewidth; i++)
con.text[idx + i] = ' ';
Con_SetColor(idx, con_linewidth, COLOR_WHITE);
// mark time for transparent overlay
if (con.current >= 0) {
con_times[con.current % NUM_CON_TIMES] = (Print_flags[Print_current] & PR_NONOTIFY ? 0 : cls.realtime);
}
}
/*
==================
Con_SafePrintf
Okay to call even when the screen can't be updated
==================
*/
void Con_SafePrintf (char *fmt, ...)
{
va_list argptr;
char msg[1024];
int temp;
va_start (argptr,fmt);
vsnprintf (msg,sizeof(msg),fmt,argptr);
va_end (argptr);
temp = scr_disabled_for_loading;
scr_disabled_for_loading = true;
Com_Printf ("%s", msg);
scr_disabled_for_loading = temp;
}
//Handles cursor positioning, line wrapping, etc
void Con_PrintW (wchar *txt) {
int y, c, l, d, mask, color = COLOR_WHITE, r, g, b, idx;
wchar *s;
static int cr;
if (!(Print_flags[Print_current] & PR_LOG_SKIP)) {
if (qconsole_log) {
char *tempbuf = wcs2str_malloc(txt);
fprintf(qconsole_log, "%s", tempbuf);
fflush(qconsole_log);
Q_free(tempbuf);
}
if (Log_IsLogging()) {
if (log_readable.value) {
char *s, *tempbuf = wcs2str_malloc(txt);
for (s = tempbuf; *s; s++)
*s = readableChars[(unsigned char) *s];
Log_Write(tempbuf);
Q_free(tempbuf);
} else {
Log_Write(wcs2str(txt));
}
}
}
if ((Print_flags[Print_current] & PR_SKIP))
goto zomfg;
if (!con_initialized || con_suppress)
goto zomfg;
if (txt[0] == 1 || txt[0] == 2) {
mask = 128; // go to colored text
txt++;
} else {
mask = 0;
}
while ((c = *txt)) {
// get color modificator if any
if (*txt == '&') {
if (txt[1] == 'c' && txt[2] && txt[3] && txt[4]) {
r = HexToInt(txt[2]);
g = HexToInt(txt[3]);
b = HexToInt(txt[4]);
if (r >= 0 && g >= 0 && b >= 0) {
color = RGBA_TO_COLOR(255 * r / 16, 255 * g / 16, 255 * b / 16, 255);
txt += 5;
continue; // we got color, get now normal char
}
} else if (txt[1] == 'r') {
color = COLOR_WHITE;
txt += 2;
continue; // we got color, get now normal char
}
}
// count word length
for (s = txt, l = 0; s[0] && l < con_linewidth;) {
// skip color, not count in word length
if (*s == '&') {
if (s[1] == 'c' && s[2] && s[3] && s[4]) {
r = HexToInt(s[2]);
g = HexToInt(s[3]);
b = HexToInt(s[4]);
if (r >= 0 && g >= 0 && b >= 0) {
s += 5;
continue; // we got color, get now normal char
}
} else if (s[1] == 'r') {
s += 2;
continue; // we got color, get now normal char
}
}
d = (s[0] & ~128);
if ( ( con_wordwrap.value && (!d || d == 0x09 || d == 0x0D || d == 0x0A || d == 0x20))
|| (!con_wordwrap.value && d <= 32) // 32 is a space as well as 0x20
)
break;
l++; // increase word length
s++; // get next char
}
// word wrap
if (l != con_linewidth && con.x + l > con_linewidth)
con.x = 0;
txt++;
if (cr) {
con.current--;
cr = false;
}
if (!con.x)
Con_Linefeed ();
switch (c) {
case '\n':
con.x = 0;
break;
case '\r':
con.x = 0;
cr = 1;
break;
default: // display character and advance
if (con.x >= con_linewidth)
Con_Linefeed ();
y = con.current % con_totallines;
idx = y * con_linewidth + con.x;
con.text[idx] = c | (c <= 0x7F ? mask | con_ormask : 0); // only apply mask if in 'standard' charset
memset(&con.clr[idx], 0, sizeof(clrinfo_t)); // zeroing whole struct
con.clr[idx].c = color;
con.clr[idx].i = idx; // no, that not stupid :P
con.x++;
break;
}
}
zomfg:
Print_flags[Print_current] = 0;
}
/*
==============================================================================
DRAWING
==============================================================================
*/
//The input line scrolls horizontally if typing goes beyond the right edge
static void Con_DrawInput(void) {
int len, i;
wchar *text;
wchar temp[MAXCMDLINE + 1]; //+ 1 for cursor if stlen(key_lines[edit_line]) == 255
if (key_dest != key_console && cls.state == ca_active)
return;
qwcslcpy (temp, key_lines[edit_line], MAXCMDLINE);
len = qwcslen(temp);
text = temp;
// fill out remainder with spaces
for (i = 0; i < MAXCMDLINE - len; i++)
(text + len)[i] = ' ';
text[MAXCMDLINE] = 0;
// add the cursor frame
if ( (int)(curtime*con_cursorspeed) & 1 )
text[key_linepos] = con_redchars ? (11 + 128) : 11;
// prestep if horizontally scrolling
if (key_linepos >= con_linewidth)
text += 1 + key_linepos - con_linewidth;
Draw_StringW (8, con_vislines-22 + bound(0, con_shift.value, 8), text);
}
// Returns first line to start printing from in order to fill up notify area
static int Con_FirstNotifyLine (int notification_lines, float notification_timelimit)
{
int maxlines = bound(0, notification_lines, NUM_CON_TIMES - 1);
int first_line = con.current;
float threshold_time = cls.realtime - notification_timelimit;
// Work backwards to skip non-ignored lines
while (first_line >= 0 && first_line > (con.current - NUM_CON_TIMES + 1) && maxlines) {
float line_time = con_times[first_line % NUM_CON_TIMES];
if (line_time && line_time > threshold_time) {
--maxlines;
}
if (maxlines)
--first_line;
}
return first_line;
}
//Draws the last few lines of output transparently over the game top
void Con_DrawNotify (void) {
int x, v, skip = 0, i, idx;
wchar *text, *s;
wchar buf[1024];
clrinfo_t clr[sizeof(buf)];
float time;
float timeout = bound (0, con_notifytime.value, MAX_NOTIFICATION_TIME);
int first_line = Con_FirstNotifyLine(_con_notifylines.integer, timeout);
if (!con_notify.value)
return;
v = 0;
if (_con_notifylines.integer) {
for (i = first_line; i <= con.current; i++) {
if (i < 0)
continue;
time = con_times[i % NUM_CON_TIMES];
if (time == 0)
continue;
time = cls.realtime - time;
if (time > timeout)
continue;
idx = (i % con_totallines)*con_linewidth;
text = con.text + idx;
clearnotify = 0;
scr_copytop = 1;
// copy current line to buffer
for (x = 0; x < con_linewidth; x++) {
buf[x] = text[x];
clr[x] = con.clr[idx + x]; // copy whole color struct
clr[x].i = x; // set proper index
}
buf[x] = '\0';
Draw_ColoredString3W(8, v + bound(0, con_shift.value, 8), buf, clr, con_linewidth, 0);
v += 8;
}
}
if (key_dest == key_message) {
wchar temp[MAXCMDLINE + 1];
clearnotify = 0;
scr_copytop = 1;
if (chat_team == chat_mm2) {
Draw_String (8, v + bound(0, con_shift.value, 8), "say_team:");
skip = 11;
}
else if (chat_team == chat_mm1) {
Draw_String (8, v + bound(0, con_shift.value, 8), "say:");
skip = 5;
}
#ifdef WITH_IRC
else if (chat_team == chat_irc) {
char dest[256];
strlcpy(dest, IRC_GetCurrentChan(), sizeof(dest));
strlcat(dest, ":", sizeof(dest));
skip = strlen(dest) + 1; // is this correct? not sure
Draw_String (8, v + bound(0, con_shift.value, 8), dest);
}
#endif
else if (chat_team == chat_qtvtogame) {
Draw_String (8, v + bound(0, con_shift.value, 8), "say_game:");
skip = 11;
}
// FIXME: clean this up
qwcslcpy (temp, chat_buffer, sizeof(temp) / sizeof(wchar));
s = temp;
// add the cursor frame
if ((int) (curtime * con_cursorspeed) & 1) {
if (chat_linepos == (int) qwcslen(s))
s[chat_linepos+1] = '\0';
s[chat_linepos] = 11;
}
// prestep if horizontally scrolling
if (chat_linepos + skip >= (vid.width >> 3))
s += 1 + chat_linepos + skip - (vid.width >> 3);
x = 0;
while (s[x] && x+skip < (vid.width>>3)) {
Draw_CharacterW ( (x+skip)<<3, v + bound(0, con_shift.value, 8), s[x]);
x++;
}
v += 8;
}
if (v > con_notifylines)
con_notifylines = v + bound(0, con_shift.value, 8);
}
// Draws the last few lines of output as a custom HUD element.
void SCR_DrawNotify(int posX, int posY, float scale, int notifyTime, int notifyLines, int notifyCols)
{
int v, skip, i, j, k, idx, draw, offset;
wchar *text, *s;
wchar buf[1024];
clrinfo_t clr[sizeof(buf)];
float time;
float timeout = bound (0, notifyTime, MAX_NOTIFICATION_TIME);
int first_line = Con_FirstNotifyLine(notifyLines, timeout);
if (notifyCols > (con_linewidth))
notifyCols = con_linewidth;
if (notifyCols < 10)
notifyCols = 10;
v = 0;
if (notifyLines) {
for (i = first_line; i <= con.current; i++) {
if (i < 0)
continue;
time = con_times[i % NUM_CON_TIMES];
if (time == 0)
continue;
time = cls.realtime - time;
if (time > timeout)
continue;
idx = (i % con_totallines)*con_linewidth;
text = con.text + idx;
clearnotify = 0;
scr_copytop = 1;
// Copy current line to buffer
offset = 0;
draw = 0;
for (j = 0; j < con_linewidth; j++)
{
// each new line of a notify hud element
if ((j % notifyCols) == 0 && j != 0)
{
for (k = 0; k < (j - offset); ++k)
{
if (buf[k] != ' ')
{
draw = 1;
break;
}
}
buf[j - offset] = '\0';
offset = j;
}
else if (j == (con_linewidth - 1)) // Ending of the string.
{
for (k = 0; k < (j - offset); ++k)
{
if (buf[k] != ' ')
{
draw = 1;
break;
}
}
buf[j - offset] = '\0';
}
// Output.
if (draw)
{
if (!draw)
continue;
Draw_SColoredString(
posX,
v + posY,
buf,
clr,
notifyCols,
0,
scale
);
// move text down
v += (8 * scale);
if (v > (notifyLines * scale))
notifyLines = v;
draw = 0;
}
buf[j - offset] = text[j];
clr[j - offset] = con.clr[idx + j]; // copy whole color struct
clr[j - offset].i = j; // set proper index
}
}
}
if (key_dest == key_message)
{
wchar temp[MAXCMDLINE + 1];
clearnotify = 0;
scr_copytop = 1;
if (chat_team)
{
Draw_SString (posX, v + posY, "say_team: ", scale);
skip = 10;
}
else
{
Draw_SString (posX, v + posY, "say: ", scale);
skip = 5;
}
// FIXME: clean this up
qwcslcpy (temp, chat_buffer, sizeof(temp) / sizeof(wchar));
s = temp;
// Add the cursor frame.
if ((int) (curtime * con_cursorspeed) & 1)
{
if (chat_linepos == (int) qwcslen(s))
s[chat_linepos+1] = '\0';
s[chat_linepos] = 11;
}
if (chat_linepos + skip >= notifyCols)
s += 1 + chat_linepos + skip - notifyCols;
j = 0;
while (s[j] && (j + skip < notifyCols))
{
Draw_SCharacter (
posX + (j + skip) * 8 * scale,
v + posY,
s[j],
scale
);
j++;
}
v += (8 * scale);
if (v > con_notifylines)
con_notifylines = v + bound(0, con_shift.value, 8);
}
}
//Draws the console with the solid background
void Con_DrawConsole (int lines) {
int i, j, x, y, n=0, rows, row, idx;