Start to use that text window a bit; user interface to show and

hide things.

[git-p4: depot-paths = "//depot/solvespace/": change = 1661]
solver
Jonathan Westhues 2008-04-11 04:47:14 -08:00
parent 181e50f1d9
commit bf8ef7b196
7 changed files with 153 additions and 37 deletions

View File

@ -3,12 +3,13 @@
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
{ RGB(170, 0, 0), COLOR_BG_DEFAULT, }, // 1
{ RGB( 40, 255, 40), COLOR_BG_DEFAULT, }, // 2
{ RGB(200, 200, 0), COLOR_BG_DEFAULT, }, // 3
{ RGB(255, 200, 40), COLOR_BG_DEFAULT, }, // 4
{ RGB(255, 40, 40), COLOR_BG_DEFAULT, }, // 5
{ RGB( 0, 255, 255), COLOR_BG_DEFAULT, }, // 6
{ RGB(255, 0, 255), COLOR_BG_DEFAULT, }, // 7
};
void TextWindow::Init(void) {
@ -82,7 +83,11 @@ void TextWindow::Printf(char *fmt, ...) {
case 'C':
if(fmt[1] == '\0') goto done;
fmt++;
if(*fmt == 'p') {
color = va_arg(vl, int);
} else {
color = *fmt - '0';
}
if(color < 0 || color >= arraylen(colors)) color = 0;
break;
@ -92,6 +97,10 @@ void TextWindow::Printf(char *fmt, ...) {
link = *fmt;
break;
case 'f':
f = va_arg(vl, LinkFunction *);
break;
case 'D':
data = va_arg(vl, DWORD);
break;
@ -166,11 +175,49 @@ void TextWindow::KeyPressed(int c) {
}
}
void TextWindow::ShowGroupList(void) {
ClearScreen();
Printf("*** ALL GROUPS IN SKETCH");
Printf("");
void TextWindow::Show(void) {
ShowRequestList();
InvalidateText();
}
void TextWindow::ShowHeader(void) {
ClearScreen();
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)
Printf("show: "
"%Cp%Ll%D%f2d-csys%E "
"%Cp%Ll%D%faxes%E "
"%Cp%Ll%D%fpoints%E "
"%Cp%Ll%fany-datum%E",
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)
);
Printf(" "
"%Cp%Ll%D%fall-groups%E "
"%Cp%Ll%D%fconstraints%E",
hs(SS.GW.showAllGroups), (DWORD)(&SS.GW.showAllGroups),
&(SS.GW.ToggleBool),
hs(SS.GW.showConstraints), (DWORD)(&SS.GW.showConstraints),
&(SS.GW.ToggleBool)
);
}
void TextWindow::ShowGroupList(void) {
ShowHeader();
Printf("%C4[[all groups in sketch]]%E");
int i;
for(i = 0; i < SS.group.elems; i++) {
Group *g = &(SS.group.elem[i].t);
@ -183,10 +230,9 @@ void TextWindow::ShowGroupList(void) {
}
void TextWindow::ShowRequestList(void) {
ClearScreen();
Printf("*** REQUESTS");
Printf("");
ShowHeader();
Printf("%C4[[all requests in sketch]]%E");
int i;
for(i = 0; i < SS.request.elems; i++) {
Request *r = &(SS.request.elem[i].t);

View File

@ -10,6 +10,8 @@ void Entity::LineDrawHitTest(Vector a, Vector b) {
void Entity::Draw(void) {
switch(type) {
case CSYS_2D: {
if(!SS.GW.show2dCsyss) break;
Vector p;
double a, b, c, d;

View File

@ -40,6 +40,11 @@ void GraphicsWindow::Init(void) {
projRight.x = 1; projRight.y = projRight.z = 0;
projDown.y = 1; projDown.z = projDown.x = 0;
show2dCsyss = true;
showAxes = true;
showPoints = true;
showAllGroups = true;
showConstraints = true;
}
void GraphicsWindow::NormalizeProjectionVectors(void) {
@ -84,7 +89,7 @@ void GraphicsWindow::MouseMoved(double x, double y, bool leftDown,
orig.mouse.x = x;
orig.mouse.y = y;
Invalidate();
InvalidateGraphics();
}
}
@ -118,7 +123,25 @@ void GraphicsWindow::MouseScroll(double x, double y, int delta) {
offset = offset.Plus(projRight.ScaledBy(rightf - righti));
offset = offset.Plus(projDown.ScaledBy(downf - downi));
Invalidate();
InvalidateGraphics();
}
void GraphicsWindow::ToggleBool(int link, DWORD v) {
bool *vb = (bool *)v;
*vb = !*vb;
InvalidateGraphics();
SS.TW.Show();
}
void GraphicsWindow::ToggleAnyDatumShown(int link, DWORD v) {
bool t = !(SS.GW.show2dCsyss && SS.GW.showAxes && SS.GW.showPoints);
SS.GW.show2dCsyss = t;
SS.GW.showAxes = t;
SS.GW.showPoints = t;
InvalidateGraphics();
SS.TW.Show();
}
void GraphicsWindow::Paint(int w, int h) {
@ -153,6 +176,8 @@ void GraphicsWindow::Paint(int w, int h) {
glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1, 1, 1);
int i;
for(i = 0; i < SS.entity.elems; i++) {
SS.entity.elem[i].t.Draw();

View File

@ -20,7 +20,7 @@ void SolveSpace::Init(void) {
Group g;
memset(&g, 0, sizeof(g));
g.csys = Entity::NO_CSYS;
g.name.strcpy("__references");
g.name.strcpy("#references");
g.h = Group::HGROUP_REFERENCES;
group.Add(&g);
@ -36,21 +36,19 @@ void SolveSpace::Init(void) {
r.type = Request::CSYS_2D;
r.group = Group::HGROUP_REFERENCES;
r.name.strcpy("#xy-plane");
r.name.strcpy("#XY-csys");
r.h = Request::HREQUEST_REFERENCE_XY;
request.Add(&r);
r.name.strcpy("#yz-plane");
r.name.strcpy("#YZ-csys");
r.h = Request::HREQUEST_REFERENCE_YZ;
request.Add(&r);
r.name.strcpy("#zx-plane");
r.name.strcpy("#ZX-csys");
r.h = Request::HREQUEST_REFERENCE_ZX;
request.Add(&r);
TW.ShowGroupList();
TW.ShowRequestList();
TW.Show();
Solve();
}

View File

@ -28,7 +28,8 @@ class Expr;
#include "expr.h"
// From the platform-specific code.
void Invalidate(void);
void InvalidateGraphics(void);
void InvalidateText(void);
// Utility functions that are provided in the platform-independent code.
void glxVertex3v(Vector u);

16
ui.h
View File

@ -20,6 +20,10 @@ public:
int bg;
} Color;
static const Color colors[];
static const int COLOR_DEFAULT = 0;
static const int COLOR_MEANS_HIDDEN = 1;
static const int COLOR_MEANS_SHOWN = 2;
static const int COLOR_MEANS_MIXED = 3;
// The line with the user-typed command, that is currently being edited.
char cmd[MAX_COLS];
@ -56,6 +60,9 @@ public:
void KeyPressed(int c);
bool IsHyperlink(int width, int height);
void Show(void);
void ShowHeader(void);
// These are self-contained screens, that show some information about
// the sketch.
void ShowGroupList(void);
@ -93,6 +100,15 @@ public:
void Init(void);
void NormalizeProjectionVectors(void);
// This sets what gets displayed.
bool show2dCsyss;
bool showAxes;
bool showPoints;
bool showAllGroups;
bool showConstraints;
static void ToggleBool(int link, DWORD v);
static void ToggleAnyDatumShown(int link, DWORD v);
// These are called by the platform-specific code.
void Paint(int w, int h);
void MouseMoved(double x, double y, bool leftDown, bool middleDown,

View File

@ -11,7 +11,8 @@
#define FREEZE_SUBKEY "SolveSpace"
#include "freeze.h"
#define TEXT_HEIGHT 18
#define MIN_COLS 42
#define TEXT_HEIGHT 19
#define TEXT_WIDTH 10
HINSTANCE Instance;
@ -94,14 +95,15 @@ static void PaintTextWnd(HDC hdc)
} else {
SelectObject(backDc, FixedFont);
}
TextOut(backDc, 4 + c*TEXT_WIDTH, (r-TextWndScrollPos)*TEXT_HEIGHT,
TextOut(backDc, 4 + c*TEXT_WIDTH,
(r-TextWndScrollPos)*TEXT_HEIGHT + 1,
(char *)&(SS.TW.text[r][c]), 1);
}
}
SetTextColor(backDc, SS.TW.COLOR_FG_CMDLINE);
SetBkColor(backDc, SS.TW.COLOR_BG_CMDLINE);
TextOut(backDc, 4, rows*TEXT_HEIGHT, SS.TW.cmd, SS.TW.MAX_COLS);
TextOut(backDc, 4, rows*TEXT_HEIGHT+1, SS.TW.cmd, SS.TW.MAX_COLS);
HPEN cpen = CreatePen(PS_SOLID, 3, RGB(255, 0, 0));
SelectObject(backDc, cpen);
@ -180,8 +182,22 @@ LRESULT CALLBACK TextWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
r->top += extra;
break;
}
hc = (r->bottom - r->top) - ClientIsSmallerBy;
extra = hc % TEXT_HEIGHT;
int tooNarrow = (MIN_COLS*TEXT_WIDTH) - (r->right - r->left);
if(tooNarrow >= 0) {
switch(wParam) {
case WMSZ_RIGHT:
case WMSZ_BOTTOMRIGHT:
case WMSZ_TOPRIGHT:
r->right += tooNarrow;
break;
case WMSZ_LEFT:
case WMSZ_BOTTOMLEFT:
case WMSZ_TOPLEFT:
r->left -= tooNarrow;
break;
}
}
break;
}
@ -205,6 +221,13 @@ LRESULT CALLBACK TextWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
} else {
SetCursor(LoadCursor(NULL, IDC_ARROW));
}
} else {
if(SS.TW.meta[r][c].link && SS.TW.meta[r][c].f) {
(SS.TW.meta[r][c].f)(
SS.TW.meta[r][c].link,
SS.TW.meta[r][c].data
);
}
}
break;
}
@ -264,10 +287,14 @@ static HGLRC CreateGlContext(HDC hdc)
return hgrc;
}
void Invalidate(void)
void InvalidateGraphics(void)
{
InvalidateRect(GraphicsWnd, NULL, FALSE);
}
void InvalidateText(void)
{
InvalidateRect(TextWnd, NULL, FALSE);
}
LRESULT CALLBACK GraphicsWndProc(HWND hwnd, UINT msg, WPARAM wParam,
LPARAM lParam)
@ -415,6 +442,7 @@ static void CreateMainWindows(void)
// The text window, with a comand line and some textual information
// about the sketch.
wc.style &= ~CS_DBLCLKS;
wc.lpfnWndProc = (WNDPROC)TextWndProc;
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszClassName = "TextWnd";
@ -458,10 +486,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
ThawWindowPos(GraphicsWnd);
// A monospaced font
FixedFont = CreateFont(TEXT_HEIGHT-1, TEXT_WIDTH, 0, 0, FW_REGULAR, FALSE,
FixedFont = CreateFont(TEXT_HEIGHT-2, TEXT_WIDTH, 0, 0, FW_REGULAR, FALSE,
FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, FF_DONTCARE, "Lucida Console");
LinkFont = CreateFont(TEXT_HEIGHT-1, TEXT_WIDTH, 0, 0, FW_REGULAR, TRUE,
LinkFont = CreateFont(TEXT_HEIGHT-2, TEXT_WIDTH, 0, 0, FW_REGULAR, FALSE,
TRUE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, FF_DONTCARE, "Lucida Console");
if(!FixedFont)