File: g_draw.cpp

package info (click to toggle)
fte 0.50.2b6-20110708-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 3,768 kB
  • ctags: 6,761
  • sloc: cpp: 47,985; ansic: 2,795; sh: 112; makefile: 71; perl: 29
file content (253 lines) | stat: -rw-r--r-- 6,277 bytes parent folder | download | duplicates (6)
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
/*    g_draw.cpp
 *
 *    Copyright (c) 1994-1996, Marko Macek
 *
 *    You may distribute under the terms of either the GNU General Public
 *    License or the Artistic License, as specified in the README file.
 *
 */

#include "console.h"

#include <stdlib.h>
#ifdef  NTCONSOLE
#   define  WIN32_LEAN_AND_MEAN 1
#   include <windows.h>
#endif

size_t CStrLen(const char *p) {
    size_t len = 0;
    while (*p) {
	if (*p++ == '&') {
	    if (*p != '&')
		continue;
	    p++;
	}
	len++; // && is one accounted as '&'
    }
    return len;
}

#ifndef NTCONSOLE

void MoveCh(PCell B, char CCh, TAttr Attr, size_t Count) {
    assert((int)Count >= 0);
    for (;Count > 0; B++, --Count)
        B->Set(CCh, Attr);
}

void MoveChar(PCell B, int Pos, int Width, const char CCh, TAttr Attr, size_t Count) {
    assert((int)Count >= 0);
    if (Pos < 0) {
	if ((int)Count < -Pos)
            return;
        Count += Pos;
        Pos = 0;
    }
    if (Pos >= Width) return;
    if ((int)Count > Width - Pos) Count = Width - Pos;
    for (B += Pos; Count > 0; B++, --Count)
        B->Set(CCh, Attr);
}

void MoveMem(PCell B, int Pos, int Width, const char* Ch, TAttr Attr, size_t Count) {
    assert((int)Count >= 0);
    if (Pos < 0) {
	if ((int)Count < -Pos)
            return;
        Count += Pos;
        Ch -= Pos;
        Pos = 0;
    }
    if (Pos >= Width) return;
    if ((int)Count > Width - Pos) Count = Width - Pos;
    for (B += Pos; Count > 0; B++, --Count)
        B->Set(*Ch++, Attr);
}

void MoveStr(PCell B, int Pos, int Width, const char* Ch, TAttr Attr, size_t MaxCount) {
    assert((int)MaxCount >= 0);
    if (Pos < 0) {
	if ((int)MaxCount < -Pos)
            return;
        MaxCount += Pos;
        Ch -= Pos;
        Pos = 0;
    }
    if (Pos >= Width) return;
    if ((int)MaxCount > Width - Pos) MaxCount = Width - Pos;
    for (B += Pos; MaxCount > 0 && *Ch; B++, --MaxCount)
        B->Set(*Ch++, Attr);
}

void MoveCStr(PCell B, int Pos, int Width, const char* Ch, TAttr A0, TAttr A1, size_t MaxCount) {
    assert((int)MaxCount >= 0);
    TAttr attr = A0;
    if (Pos < 0) {
	if ((int)MaxCount < -Pos)
            return;
        MaxCount += Pos;
        Ch -= Pos;
        Pos = 0;
    }
    if (Pos >= Width) return;
    if ((int)MaxCount > Width - Pos) MaxCount = Width - Pos;
    for (B += Pos; MaxCount > 0 && *Ch;) {
        if (*Ch == '&' && attr == A0) {
            Ch++;
            attr = A1;
            continue;
        } 
        B++->Set(*Ch++, attr);
        attr = A0;
        --MaxCount;
    }
}

void MoveAttr(PCell B, int Pos, int Width, TAttr Attr, size_t Count) {
    assert((int)Count >= 0);
    if (Pos < 0) {
	if ((int)Count < -Pos)
            return;
        Count += Pos;
        Pos = 0;
    }
    if (Pos >= Width) return;
    if ((int)Count > Width - Pos) Count = Width - Pos;
    for (B += Pos; Count > 0; B++, --Count)
        B->SetAttr(Attr);
}

void MoveBgAttr(PCell B, int Pos, int Width, TAttr Attr, size_t Count) {
    assert((int)Count >= 0);
    if (Pos < 0) {
	if ((int)Count < -Pos)
            return;
        Count += Pos;
        Pos = 0;
    }
    if (Pos >= Width) return;
    if ((int)Count > Width - Pos) Count = Width - Pos;
    for (B += Pos; Count > 0; B++, Count--)
        B->SetAttr(TAttr((B->GetAttr() & 0x0F) | Attr));
}

#else

void MoveCh(PCell B, char Ch, TAttr Attr, size_t Count) {
    PCHAR_INFO p = (PCHAR_INFO) B;
    while (Count > 0) {
        p->Char.AsciiChar = Ch;
        p->Attributes = Attr;
        p++;
        Count--;
    }
}

void MoveChar(PCell B, int Pos, int Width, const char Ch, TAttr Attr, size_t Count) {
    PCHAR_INFO p = (PCHAR_INFO) B;
    if (Pos < 0) {
        Count += Pos;
        Pos = 0;
    }
    if (Pos >= Width) return;
    if (Pos + Count > Width) Count = Width - Pos;
    for (p += Pos; Count > 0; Count--) {
        p->Char.AsciiChar = Ch;
        p->Attributes = Attr;
        p++;
    }
}

void MoveMem(PCell B, int Pos, int Width, const char* Ch, TAttr Attr, size_t Count) {
    PCHAR_INFO p = (PCHAR_INFO) B;
    
    if (Pos < 0) {
        Count += Pos;
        Ch -= Pos;
        Pos = 0;
    }
    if (Pos >= Width) return;
    if (Pos + Count > Width) Count = Width - Pos;
    for (p += Pos; Count > 0; p++, --Count) {
        p->Char.AsciiChar = *Ch++;
        p->Attributes = Attr;
    }
}

void MoveStr(PCell B, int Pos, int Width, const char* Ch, TAttr Attr, size_t MaxCount) {
    PCHAR_INFO p = (PCHAR_INFO) B;
    
    if (Pos < 0) {
        MaxCount += Pos;
        Ch -= Pos;
        Pos = 0;
    }
    if (Pos >= Width) return;
    if (Pos + MaxCount > Width) MaxCount = Width - Pos;
    for (p += Pos; MaxCount > 0 && (*Ch != 0); MaxCount--) {
        p->Char.AsciiChar = *Ch++;
        p->Attributes = Attr;
        p++;
    }
}

void MoveCStr(PCell B, int Pos, int Width, const char* Ch, TAttr A0, TAttr A1, size_t MaxCount) {
    PCHAR_INFO p = (PCHAR_INFO) B;
    char was;
    //TAttr A;
    
    if (Pos < 0) {
        MaxCount += Pos;
        Ch -= Pos;
        Pos = 0;
    }
    if (Pos >= Width) return;
    if (Pos + MaxCount > Width) MaxCount = Width - Pos;
    was = 0;
    for (p += Pos; MaxCount > 0 && (*Ch != 0); MaxCount--) {
        if (*Ch == '&' && !was) {
            Ch++;
            MaxCount++;
            was = 1;
            continue;
        } 
        p->Char.AsciiChar = (unsigned char) (*Ch++);
        if (was) {
            p->Attributes = A1;
            was = 0;
        } else
            p->Attributes = A0;
        p++;
    }
}

void MoveAttr(PCell B, int Pos, int Width, TAttr Attr, size_t Count) {
    PCHAR_INFO p = (PCHAR_INFO) B;
    
    if (Pos < 0) {
        Count += Pos;
        Pos = 0;
    }
    if (Pos >= Width) return;
    if (Pos + Count > Width) Count = Width - Pos;
    for (p += Pos; Count > 0; p++, --Count)
        p->Attributes = Attr;
}

void MoveBgAttr(PCell B, int Pos, int Width, TAttr Attr, size_t Count) {
    PCHAR_INFO p = (PCHAR_INFO) B;
    
    if (Pos < 0) {
        Count += Pos;
        Pos = 0;
    }
    if (Pos >= Width) return;
    if (Pos + Count > Width) Count = Width - Pos;
    for (p += Pos; Count > 0; p++, --Count)
        p->Attributes =
            ((unsigned char)(p->Attributes & 0xf)) |
            ((unsigned char) Attr);
}

#endif