2008-03-25 10:02:13 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
#define COLOR_BG_HEADER RGB(50, 20, 50)
|
2008-03-28 10:00:37 +00:00
|
|
|
const TextWindow::Color TextWindow::colors[] = {
|
2008-04-12 14:12:26 +00:00
|
|
|
{ RGB(255, 255, 255), COLOR_BG_DEFAULT, }, // 0
|
|
|
|
|
|
|
|
{ RGB(170, 0, 0), COLOR_BG_HEADER, }, // 1 hidden label
|
|
|
|
{ RGB( 40, 255, 40), COLOR_BG_HEADER, }, // 2 shown label
|
|
|
|
{ RGB(200, 200, 0), COLOR_BG_HEADER, }, // 3 mixed label
|
2008-04-18 07:06:37 +00:00
|
|
|
{ RGB(255, 200, 40), COLOR_BG_HEADER, }, // 4 yellow text
|
|
|
|
{ RGB(255, 255, 255), COLOR_BG_HEADER, }, // 5 white text
|
2008-04-12 14:12:26 +00:00
|
|
|
{ RGB( 0, 0, 0), COLOR_BG_DEFAULT, }, // 6
|
|
|
|
{ RGB( 0, 0, 0), COLOR_BG_DEFAULT, }, // 7
|
|
|
|
|
|
|
|
{ RGB(255, 255, 255), COLOR_BG_DEFAULT, }, // 8 title
|
|
|
|
{ RGB(100, 100, 255), COLOR_BG_DEFAULT, }, // 9 link
|
2008-03-28 10:00:37 +00:00
|
|
|
};
|
|
|
|
|
2008-03-25 10:02:13 +00:00
|
|
|
void TextWindow::Init(void) {
|
2008-04-12 14:12:26 +00:00
|
|
|
memset(this, 0, sizeof(*this));
|
|
|
|
shown = &(showns[shownIndex]);
|
|
|
|
|
2008-03-26 09:18:12 +00:00
|
|
|
ClearScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
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] = ' ';
|
2008-04-12 14:12:26 +00:00
|
|
|
meta[i][j].color = COLOR_DEFAULT;
|
2008-03-25 10:02:13 +00:00
|
|
|
meta[i][j].link = NOT_A_LINK;
|
|
|
|
}
|
|
|
|
}
|
2008-03-26 09:18:12 +00:00
|
|
|
rows = 0;
|
2008-03-25 10:02:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextWindow::Printf(char *fmt, ...) {
|
|
|
|
va_list vl;
|
|
|
|
va_start(vl, fmt);
|
|
|
|
|
2008-04-09 09:35:09 +00:00
|
|
|
if(rows >= MAX_ROWS) return;
|
|
|
|
|
2008-03-25 10:02:13 +00:00
|
|
|
int r, c;
|
2008-04-09 09:35:09 +00:00
|
|
|
r = rows;
|
|
|
|
rows++;
|
|
|
|
|
2008-03-25 10:02:13 +00:00
|
|
|
for(c = 0; c < MAX_COLS; c++) {
|
|
|
|
text[r][c] = ' ';
|
|
|
|
meta[r][c].link = NOT_A_LINK;
|
|
|
|
}
|
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
int color = COLOR_DEFAULT;
|
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':
|
2008-04-12 14:12:26 +00:00
|
|
|
color = COLOR_DEFAULT;
|
2008-03-28 10:00:37 +00:00
|
|
|
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++;
|
2008-04-11 12:47:14 +00:00
|
|
|
if(*fmt == 'p') {
|
|
|
|
color = va_arg(vl, int);
|
|
|
|
} else {
|
|
|
|
color = *fmt - '0';
|
|
|
|
}
|
2008-03-28 10:00:37 +00:00
|
|
|
if(color < 0 || color >= arraylen(colors)) color = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'L':
|
|
|
|
if(fmt[1] == '\0') goto done;
|
|
|
|
fmt++;
|
|
|
|
link = *fmt;
|
|
|
|
break;
|
|
|
|
|
2008-04-11 12:47:14 +00:00
|
|
|
case 'f':
|
|
|
|
f = va_arg(vl, LinkFunction *);
|
|
|
|
break;
|
|
|
|
|
2008-03-28 10:00:37 +00:00
|
|
|
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++;
|
|
|
|
}
|
2008-04-12 14:12:26 +00:00
|
|
|
while(c < MAX_COLS) {
|
|
|
|
meta[r][c].color = color;
|
|
|
|
c++;
|
|
|
|
}
|
2008-03-25 10:02:13 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
va_end(vl);
|
|
|
|
}
|
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
void TextWindow::Show(void) {
|
2008-04-13 10:57:41 +00:00
|
|
|
if(!(SS.GW.pendingOperation)) SS.GW.pendingDescription = NULL;
|
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
ShowHeader();
|
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
if(SS.GW.pendingDescription) {
|
|
|
|
// A pending operation (that must be completed with the mouse in
|
|
|
|
// the graphics window) will preempt our usual display.
|
|
|
|
Printf("");
|
|
|
|
Printf("%s", SS.GW.pendingDescription);
|
|
|
|
} else {
|
|
|
|
switch(shown->screen) {
|
|
|
|
default:
|
2008-04-18 07:06:37 +00:00
|
|
|
shown->screen = SCREEN_ALL_GROUPS;
|
2008-04-13 10:57:41 +00:00
|
|
|
// fall through
|
2008-04-18 07:06:37 +00:00
|
|
|
case SCREEN_ALL_GROUPS:
|
|
|
|
ShowAllGroups();
|
2008-04-13 10:57:41 +00:00
|
|
|
break;
|
|
|
|
|
2008-04-18 07:06:37 +00:00
|
|
|
case SCREEN_REQUESTS_IN_GROUP:
|
|
|
|
ShowRequestsInGroup();
|
2008-04-13 10:57:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-25 10:02:13 +00:00
|
|
|
}
|
2008-04-12 14:12:26 +00:00
|
|
|
InvalidateText();
|
2008-03-26 09:18:12 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
void TextWindow::OneScreenForward(void) {
|
|
|
|
SS.TW.shownIndex++;
|
|
|
|
if(SS.TW.shownIndex >= HISTORY_LEN) SS.TW.shownIndex = 0;
|
|
|
|
SS.TW.shown = &(SS.TW.showns[SS.TW.shownIndex]);
|
|
|
|
history++;
|
2008-03-25 10:02:13 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
void TextWindow::ScreenNavigaton(int link, DWORD v) {
|
|
|
|
switch(link) {
|
|
|
|
default:
|
|
|
|
case 'h':
|
|
|
|
SS.TW.OneScreenForward();
|
2008-04-18 07:06:37 +00:00
|
|
|
SS.TW.shown->screen = SCREEN_ALL_GROUPS;
|
2008-04-12 14:12:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'b':
|
|
|
|
if(SS.TW.history > 0) {
|
|
|
|
SS.TW.shownIndex--;
|
|
|
|
if(SS.TW.shownIndex < 0) SS.TW.shownIndex = (HISTORY_LEN-1);
|
|
|
|
SS.TW.shown = &(SS.TW.showns[SS.TW.shownIndex]);
|
|
|
|
SS.TW.history--;
|
|
|
|
}
|
|
|
|
break;
|
2008-03-25 10:02:13 +00:00
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
case 'f':
|
|
|
|
SS.TW.OneScreenForward();
|
|
|
|
break;
|
2008-03-25 10:02:13 +00:00
|
|
|
}
|
2008-04-12 14:12:26 +00:00
|
|
|
SS.TW.Show();
|
2008-03-25 10:02:13 +00:00
|
|
|
}
|
2008-04-11 12:47:14 +00:00
|
|
|
void TextWindow::ShowHeader(void) {
|
2008-04-08 12:54:53 +00:00
|
|
|
ClearScreen();
|
|
|
|
|
2008-04-18 07:06:37 +00:00
|
|
|
SS.GW.EnsureValidActives();
|
2008-04-13 10:57:41 +00:00
|
|
|
|
|
|
|
if(SS.GW.pendingDescription) {
|
2008-04-17 06:42:32 +00:00
|
|
|
Printf(" %C4 group:%s",
|
|
|
|
SS.group.FindById(SS.GW.activeGroup)->DescriptionString());
|
2008-04-13 10:57:41 +00:00
|
|
|
} else {
|
|
|
|
// Navigation buttons
|
2008-04-18 07:06:37 +00:00
|
|
|
char *cd;
|
|
|
|
if(SS.GW.activeCsys.v == Entity::NO_CSYS.v) {
|
|
|
|
cd = "free in 3d";
|
|
|
|
} else {
|
|
|
|
cd = SS.GetEntity(SS.GW.activeCsys)->DescriptionString();
|
|
|
|
}
|
|
|
|
Printf(" %Lb%f<<%E %Lh%fhome%E %C4 csys:%C5 %s",
|
2008-04-13 10:57:41 +00:00
|
|
|
(DWORD)(&TextWindow::ScreenNavigaton),
|
|
|
|
(DWORD)(&TextWindow::ScreenNavigaton),
|
2008-04-18 07:06:37 +00:00
|
|
|
cd);
|
2008-04-13 10:57:41 +00:00
|
|
|
}
|
2008-04-12 14:12:26 +00:00
|
|
|
|
2008-04-11 12:47:14 +00:00
|
|
|
int datumColor;
|
|
|
|
if(SS.GW.show2dCsyss && SS.GW.showAxes && SS.GW.showPoints) {
|
|
|
|
datumColor = COLOR_MEANS_SHOWN;
|
|
|
|
} else if(!(SS.GW.show2dCsyss || SS.GW.showAxes || SS.GW.showPoints)) {
|
|
|
|
datumColor = COLOR_MEANS_HIDDEN;
|
|
|
|
} else {
|
|
|
|
datumColor = COLOR_MEANS_MIXED;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define hs(b) ((b) ? COLOR_MEANS_SHOWN : COLOR_MEANS_HIDDEN)
|
2008-04-12 14:12:26 +00:00
|
|
|
Printf("%C4show: "
|
|
|
|
"%Cp%Ll%D%f2d-csys%E%C4 "
|
|
|
|
"%Cp%Ll%D%faxes%E%C4 "
|
|
|
|
"%Cp%Ll%D%fpoints%E%C4 "
|
|
|
|
"%Cp%Ll%fany-datum%E%C4",
|
2008-04-11 12:47:14 +00:00
|
|
|
hs(SS.GW.show2dCsyss), (DWORD)&(SS.GW.show2dCsyss), &(SS.GW.ToggleBool),
|
|
|
|
hs(SS.GW.showAxes), (DWORD)&(SS.GW.showAxes), &(SS.GW.ToggleBool),
|
|
|
|
hs(SS.GW.showPoints), (DWORD)&(SS.GW.showPoints), &(SS.GW.ToggleBool),
|
|
|
|
datumColor, &(SS.GW.ToggleAnyDatumShown)
|
|
|
|
);
|
2008-04-12 14:12:26 +00:00
|
|
|
Printf("%C4 "
|
|
|
|
"%Cp%Ll%D%fall-groups%E%C4 "
|
|
|
|
"%Cp%Ll%D%fconstraints%E%C4",
|
2008-04-11 12:47:14 +00:00
|
|
|
hs(SS.GW.showAllGroups), (DWORD)(&SS.GW.showAllGroups),
|
|
|
|
&(SS.GW.ToggleBool),
|
|
|
|
hs(SS.GW.showConstraints), (DWORD)(&SS.GW.showConstraints),
|
|
|
|
&(SS.GW.ToggleBool)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-04-18 07:06:37 +00:00
|
|
|
void TextWindow::ShowAllGroups(void) {
|
2008-04-13 14:28:35 +00:00
|
|
|
Printf("%C8[[all groups in sketch follow]]%E");
|
2008-04-08 12:54:53 +00:00
|
|
|
int i;
|
2008-04-18 11:11:48 +00:00
|
|
|
for(i = 0; i <= SS.group.n; i++) {
|
2008-04-12 14:12:26 +00:00
|
|
|
DWORD v;
|
|
|
|
char *s;
|
2008-04-18 11:11:48 +00:00
|
|
|
if(i == SS.group.n) {
|
2008-04-12 14:12:26 +00:00
|
|
|
s = "all requests from all groups";
|
|
|
|
v = 0;
|
2008-04-08 12:54:53 +00:00
|
|
|
} else {
|
2008-04-18 07:21:17 +00:00
|
|
|
Group *g = &(SS.group.elem[i]);
|
2008-04-12 14:12:26 +00:00
|
|
|
s = g->DescriptionString();
|
|
|
|
v = g->h.v;
|
2008-04-08 12:54:53 +00:00
|
|
|
}
|
2008-04-12 14:12:26 +00:00
|
|
|
Printf(" %C9%Ll%D%f%s%E", v, (DWORD)(&TextWindow::ScreenSelectGroup), s);
|
2008-04-08 12:54:53 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-12 14:12:26 +00:00
|
|
|
void TextWindow::ScreenSelectGroup(int link, DWORD v) {
|
|
|
|
SS.TW.OneScreenForward();
|
|
|
|
|
2008-04-18 07:06:37 +00:00
|
|
|
SS.TW.shown->screen = SCREEN_REQUESTS_IN_GROUP;
|
2008-04-12 14:12:26 +00:00
|
|
|
SS.TW.shown->group.v = v;
|
|
|
|
|
|
|
|
SS.TW.Show();
|
|
|
|
}
|
2008-04-08 12:54:53 +00:00
|
|
|
|
2008-04-18 07:06:37 +00:00
|
|
|
void TextWindow::ShowRequestsInGroup(void) {
|
2008-04-12 14:12:26 +00:00
|
|
|
if(shown->group.v == 0) {
|
|
|
|
Printf("%C8[[requests in all groups]]%E");
|
|
|
|
} else {
|
|
|
|
Group *g = SS.group.FindById(shown->group);
|
2008-04-13 14:28:35 +00:00
|
|
|
if(SS.GW.activeGroup.v == shown->group.v) {
|
|
|
|
Printf("%C8[[this is the active group]]");
|
2008-04-18 07:06:37 +00:00
|
|
|
} else if(shown->group.v == Group::HGROUP_REFERENCES.v) {
|
|
|
|
Printf("%C8[[this group contains the references]]");
|
2008-04-13 14:28:35 +00:00
|
|
|
} else {
|
2008-04-18 07:06:37 +00:00
|
|
|
Printf("%C8[[not active; %C9%Llactivate this group%E%C8]]");
|
2008-04-13 14:28:35 +00:00
|
|
|
}
|
2008-04-12 14:12:26 +00:00
|
|
|
Printf("%C8[[requests in group %s]]%E", g->DescriptionString());
|
|
|
|
}
|
2008-04-08 12:54:53 +00:00
|
|
|
|
|
|
|
int i;
|
2008-04-18 11:11:48 +00:00
|
|
|
for(i = 0; i < SS.request.n; i++) {
|
2008-04-18 07:21:17 +00:00
|
|
|
Request *r = &(SS.request.elem[i]);
|
2008-04-08 12:54:53 +00:00
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
if(r->group.v == shown->group.v || shown->group.v == 0) {
|
|
|
|
char *s = r->DescriptionString();
|
|
|
|
Printf(" %s", s);
|
2008-04-08 12:54:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-18 07:06:37 +00:00
|
|
|
|