2008-03-25 10:02:13 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2008-03-28 10:00:37 +00:00
|
|
|
const TextWindow::Color TextWindow::colors[] = {
|
|
|
|
{ COLOR_FG_DEFAULT, COLOR_BG_DEFAULT, }, // 0
|
|
|
|
{ RGB(255, 40, 40), COLOR_BG_DEFAULT, }, // 1
|
|
|
|
{ RGB(255, 255, 0), COLOR_BG_DEFAULT, }, // 2
|
|
|
|
{ RGB( 40, 255, 40), COLOR_BG_DEFAULT, }, // 3
|
|
|
|
{ RGB( 0, 255, 255), COLOR_BG_DEFAULT, }, // 4
|
|
|
|
{ RGB(140, 140, 255), COLOR_BG_DEFAULT, }, // 5
|
|
|
|
{ RGB(255, 0, 255), COLOR_BG_DEFAULT, }, // 6
|
|
|
|
};
|
|
|
|
|
2008-03-25 10:02:13 +00:00
|
|
|
void TextWindow::Init(void) {
|
2008-03-26 09:18:12 +00:00
|
|
|
ClearScreen();
|
|
|
|
ClearCommand();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextWindow::ClearScreen(void) {
|
2008-03-25 10:02:13 +00:00
|
|
|
int i, j;
|
|
|
|
for(i = 0; i < MAX_ROWS; i++) {
|
|
|
|
for(j = 0; j < MAX_COLS; j++) {
|
|
|
|
text[i][j] = ' ';
|
|
|
|
meta[i][j].color = COLOR_NORMAL;
|
|
|
|
meta[i][j].link = NOT_A_LINK;
|
|
|
|
}
|
|
|
|
}
|
2008-03-26 09:18:12 +00:00
|
|
|
row0 = 0;
|
|
|
|
rows = 0;
|
2008-03-25 10:02:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextWindow::Printf(char *fmt, ...) {
|
|
|
|
va_list vl;
|
|
|
|
va_start(vl, fmt);
|
|
|
|
|
|
|
|
int r, c;
|
|
|
|
if(rows < MAX_ROWS) {
|
|
|
|
r = rows;
|
|
|
|
rows++;
|
|
|
|
} else {
|
|
|
|
r = row0;
|
|
|
|
row0++;
|
|
|
|
}
|
|
|
|
for(c = 0; c < MAX_COLS; c++) {
|
|
|
|
text[r][c] = ' ';
|
|
|
|
meta[r][c].link = NOT_A_LINK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int color = COLOR_NORMAL;
|
2008-03-28 10:00:37 +00:00
|
|
|
int link = NOT_A_LINK;
|
|
|
|
DWORD data = 0;
|
|
|
|
LinkFunction *f = NULL;
|
2008-03-25 10:02:13 +00:00
|
|
|
|
|
|
|
c = 0;
|
|
|
|
while(*fmt) {
|
2008-03-28 10:00:37 +00:00
|
|
|
char buf[1024];
|
|
|
|
|
2008-03-25 10:02:13 +00:00
|
|
|
if(*fmt == '%') {
|
2008-03-26 09:18:12 +00:00
|
|
|
fmt++;
|
|
|
|
if(*fmt == '\0') goto done;
|
2008-03-28 10:00:37 +00:00
|
|
|
strcpy(buf, "");
|
2008-03-26 09:18:12 +00:00
|
|
|
switch(*fmt) {
|
2008-03-28 10:00:37 +00:00
|
|
|
case 'd': {
|
|
|
|
int v = va_arg(vl, int);
|
|
|
|
sprintf(buf, "%d", v);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'x': {
|
|
|
|
DWORD v = va_arg(vl, DWORD);
|
|
|
|
sprintf(buf, "%08x", v);
|
|
|
|
break;
|
|
|
|
}
|
2008-03-26 09:18:12 +00:00
|
|
|
case 's': {
|
|
|
|
char *s = va_arg(vl, char *);
|
2008-03-28 10:00:37 +00:00
|
|
|
memcpy(buf, s, min(sizeof(buf), strlen(s)+1));
|
2008-03-26 09:18:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-28 10:00:37 +00:00
|
|
|
case 'E':
|
|
|
|
color = COLOR_NORMAL;
|
|
|
|
link = NOT_A_LINK;
|
|
|
|
data = 0;
|
|
|
|
f = NULL;
|
2008-03-26 09:18:12 +00:00
|
|
|
break;
|
2008-03-28 10:00:37 +00:00
|
|
|
|
|
|
|
case 'C':
|
|
|
|
if(fmt[1] == '\0') goto done;
|
|
|
|
fmt++;
|
|
|
|
color = *fmt - '0';
|
|
|
|
if(color < 0 || color >= arraylen(colors)) color = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'L':
|
|
|
|
if(fmt[1] == '\0') goto done;
|
|
|
|
fmt++;
|
|
|
|
link = *fmt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'D':
|
|
|
|
data = va_arg(vl, DWORD);
|
|
|
|
break;
|
|
|
|
|
2008-03-26 09:18:12 +00:00
|
|
|
case '%':
|
2008-03-28 10:00:37 +00:00
|
|
|
strcpy(buf, "%");
|
2008-03-26 09:18:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-25 10:02:13 +00:00
|
|
|
} else {
|
2008-03-28 10:00:37 +00:00
|
|
|
buf[0] = *fmt;
|
|
|
|
buf[1]= '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
for(unsigned i = 0; i < strlen(buf); i++) {
|
2008-03-25 10:02:13 +00:00
|
|
|
if(c >= MAX_COLS) goto done;
|
2008-03-28 10:00:37 +00:00
|
|
|
text[r][c] = buf[i];
|
|
|
|
meta[r][c].color = color;
|
|
|
|
meta[r][c].link = link;
|
|
|
|
meta[r][c].data = data;
|
|
|
|
meta[r][c].f = f;
|
|
|
|
c++;
|
2008-03-25 10:02:13 +00:00
|
|
|
}
|
2008-03-28 10:00:37 +00:00
|
|
|
|
2008-03-25 10:02:13 +00:00
|
|
|
fmt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
va_end(vl);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextWindow::ClearCommand(void) {
|
|
|
|
int j;
|
|
|
|
for(j = 0; j < MAX_COLS; j++) {
|
|
|
|
cmd[j] = ' ';
|
|
|
|
}
|
|
|
|
memcpy(cmd, "+> ", 3);
|
|
|
|
cmdLen = 0;
|
|
|
|
cmdInsert = 3;
|
2008-03-26 09:18:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextWindow::ProcessCommand(char *cmd)
|
|
|
|
{
|
2008-03-28 10:00:37 +00:00
|
|
|
Printf("%C2command:%E '%s' done %C3(green)%E %C5%LaLink%E", cmd);
|
2008-03-25 10:02:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextWindow::KeyPressed(int c) {
|
|
|
|
if(cmdLen >= MAX_COLS - 10) {
|
|
|
|
ClearCommand();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(c == '\n' || c == '\r') {
|
2008-03-26 09:18:12 +00:00
|
|
|
cmd[cmdLen+3] = '\0';
|
|
|
|
ProcessCommand(cmd+3);
|
|
|
|
|
2008-03-25 10:02:13 +00:00
|
|
|
ClearCommand();
|
|
|
|
return;
|
|
|
|
} else if(c == 27) {
|
|
|
|
ClearCommand();
|
2008-03-26 09:18:12 +00:00
|
|
|
} else if(c == 'l' - 'a' + 1) {
|
|
|
|
ClearScreen();
|
2008-03-25 10:02:13 +00:00
|
|
|
} else if(c == '\b') {
|
|
|
|
// backspace, delete from insertion point
|
|
|
|
if(cmdInsert <= 3) return;
|
|
|
|
memmove(cmd+cmdInsert-1, cmd+cmdInsert, MAX_COLS-cmdInsert);
|
|
|
|
cmdLen--;
|
|
|
|
cmdInsert--;
|
|
|
|
} else {
|
|
|
|
cmd[cmdInsert] = c;
|
|
|
|
cmdInsert++;
|
|
|
|
cmdLen++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-08 12:54:53 +00:00
|
|
|
void TextWindow::ShowGroupList(void) {
|
|
|
|
ClearScreen();
|
|
|
|
Printf("*** ALL GROUPS IN SKETCH");
|
|
|
|
Printf("");
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < SS.group.elems; i++) {
|
2008-04-09 08:39:01 +00:00
|
|
|
Group *g = &(SS.group.elem[i].t);
|
2008-04-08 12:54:53 +00:00
|
|
|
if(g->name.str[0]) {
|
|
|
|
Printf(" %s", g->name.str);
|
|
|
|
} else {
|
|
|
|
Printf(" unnamed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextWindow::ShowRequestList(void) {
|
|
|
|
ClearScreen();
|
|
|
|
Printf("*** REQUESTS");
|
|
|
|
Printf("");
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < SS.request.elems; i++) {
|
2008-04-09 08:39:01 +00:00
|
|
|
Request *r = &(SS.request.elem[i].t);
|
2008-04-08 12:54:53 +00:00
|
|
|
|
|
|
|
if(r->name.str[0]) {
|
|
|
|
Printf(" %s", r->name.str);
|
|
|
|
} else {
|
|
|
|
Printf(" unnamed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|