mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-20 10:43:29 +00:00
[qwaq] Flesh out DrawBuffer's methods
This commit is contained in:
parent
b3850bbc69
commit
ce67d9b202
2 changed files with 72 additions and 0 deletions
|
@ -22,9 +22,11 @@
|
|||
- (void) printf: (string) fmt, ...;
|
||||
- (void) vprintf: (string) fmt, @va_list args;
|
||||
- (void) addch: (int) ch;
|
||||
- (void) addstr: (string) str;
|
||||
- (void) mvprintf: (Point) pos, string fmt, ...;
|
||||
- (void) mvvprintf: (Point) pos, string fmt, @va_list args;
|
||||
- (void) mvaddch: (Point) pos, int ch;
|
||||
- (void) mvaddstr: (Point) pos, string str;
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "qwaq-curses.h"
|
||||
#include "qwaq-draw.h"
|
||||
|
||||
|
@ -71,26 +73,94 @@
|
|||
|
||||
- (void) printf: (string) fmt, ...
|
||||
{
|
||||
string str = vsprintf (fmt, @args);
|
||||
[self addstr: str];
|
||||
}
|
||||
|
||||
- (void) vprintf: (string) fmt, @va_list args
|
||||
{
|
||||
string str = vsprintf (fmt, args);
|
||||
[self addstr: str];
|
||||
}
|
||||
|
||||
- (void) addch: (int) ch
|
||||
{
|
||||
if (cursor.x < 0) {
|
||||
cursor.x = 0;
|
||||
}
|
||||
if (cursor.y < 0) {
|
||||
cursor.y = 0;
|
||||
}
|
||||
if (cursor.x >= size.width && cursor.y < size.height) {
|
||||
cursor.x = 0;
|
||||
cursor.y++;
|
||||
}
|
||||
if (cursor.y >= size.height) {
|
||||
return;
|
||||
}
|
||||
if (ch == '\n') {
|
||||
cursor.x = 0;
|
||||
cursor.y++;
|
||||
} else if (ch == '\r') {
|
||||
cursor.x = 0;
|
||||
} else {
|
||||
buffer[cursor.y * size.width + cursor.x++] = ch;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) addstr: (string) str
|
||||
{
|
||||
int ind = 0;
|
||||
int ch;
|
||||
|
||||
if (cursor.y >= size.height) {
|
||||
return;
|
||||
}
|
||||
while (cursor.x < size.width && (ch = str_char (str, ind++))) {
|
||||
[self addch: ch];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) mvprintf: (Point) pos, string fmt, ...
|
||||
{
|
||||
if (pos.x < 0 || pos.x >= size.width
|
||||
|| pos.y < 0 || pos.y >= size.height) {
|
||||
return;
|
||||
}
|
||||
cursor = pos;
|
||||
string str = vsprintf (fmt, @args);
|
||||
[self addstr: str];
|
||||
}
|
||||
|
||||
- (void) mvvprintf: (Point) pos, string fmt, @va_list args
|
||||
{
|
||||
if (pos.x < 0 || pos.x >= size.width
|
||||
|| pos.y < 0 || pos.y >= size.height) {
|
||||
return;
|
||||
}
|
||||
cursor = pos;
|
||||
string str = vsprintf (fmt, args);
|
||||
[self addstr: str];
|
||||
}
|
||||
|
||||
- (void) mvaddch: (Point) pos, int ch
|
||||
{
|
||||
if (pos.x < 0 || pos.x >= size.width
|
||||
|| pos.y < 0 || pos.y >= size.height) {
|
||||
return;
|
||||
}
|
||||
cursor = pos;
|
||||
[self addch: ch];
|
||||
}
|
||||
|
||||
- (void) mvaddstr: (Point) pos, string str
|
||||
{
|
||||
if (pos.x < 0 || pos.x >= size.width
|
||||
|| pos.y < 0 || pos.y >= size.height) {
|
||||
return;
|
||||
}
|
||||
cursor = pos;
|
||||
[self addstr: str];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue