Skip to content

Commit 6713923

Browse files
committed
This is my initial checkin for solvespace, a second attempt at
constraint solver drawing. I've started work on the user inteface, which will be based around two windows: one with the graphical sketch, and one command line. I've started to implement the command line, no other work. [git-p4: depot-paths = "//depot/solvespace/": change = 1652]
0 parents  commit 6713923

File tree

8 files changed

+463
-0
lines changed

8 files changed

+463
-0
lines changed

Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
DEFINES = /D_WIN32_WINNT=0x400 /DISOLATION_AWARE_ENABLED /D_WIN32_IE=0x500 /DWIN32_LEAN_AND_MEAN /DWIN32
2+
CFLAGS = /W3 /nologo -I..\common\win32 /O2 /D_DEBUG /D_CRT_SECURE_NO_WARNINGS /Zi /I.
3+
4+
HEADERS = ..\common\win32\freeze.h ui.h solvespace.h dsc.h
5+
6+
OBJDIR = obj
7+
8+
FREEZE = $(OBJDIR)\freeze.obj
9+
10+
W32OBJS = $(OBJDIR)\w32main.obj \
11+
12+
SSOBJS = $(OBJDIR)\solvespace.obj \
13+
$(OBJDIR)\cmdline.obj \
14+
15+
16+
LIBS = user32.lib gdi32.lib comctl32.lib advapi32.lib
17+
18+
all: $(OBJDIR)/solvespace.exe
19+
@cp $(OBJDIR)/solvespace.exe .
20+
solvespace
21+
22+
clean:
23+
rm -f obj/*
24+
25+
$(OBJDIR)/solvespace.exe: $(SSOBJS) $(W32OBJS) $(FREEZE)
26+
@$(CC) $(DEFINES) $(CFLAGS) -Fe$(OBJDIR)/solvespace.exe $(SSOBJS) $(W32OBJS) $(FREEZE) $(LIBS)
27+
@echo solvespace.exe
28+
29+
$(SSOBJS): $(@B).cpp $(HEADERS)
30+
@$(CC) $(CFLAGS) $(DEFINES) -c -Fo$(OBJDIR)/$(@B).obj $(@B).cpp
31+
32+
$(W32OBJS): win32/$(@B).cpp $(HEADERS)
33+
@$(CC) $(CFLAGS) $(DEFINES) -c -Fo$(OBJDIR)/$(@B).obj win32/$(@B).cpp
34+
35+
$(FREEZE): ..\common\win32\$(@B).cpp $(HEADERS)
36+
@$(CC) $(CFLAGS) $(DEFINES) -c -Fo$(OBJDIR)/$(@B).obj ..\common\win32\$(@B).cpp

cmdline.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include "solvespace.h"
2+
#include <stdarg.h>
3+
4+
void TextWindow::Init(void) {
5+
int i, j;
6+
for(i = 0; i < MAX_ROWS; i++) {
7+
for(j = 0; j < MAX_COLS; j++) {
8+
text[i][j] = ' ';
9+
meta[i][j].color = COLOR_NORMAL;
10+
meta[i][j].link = NOT_A_LINK;
11+
}
12+
}
13+
ClearCommand();
14+
}
15+
16+
void TextWindow::Printf(char *fmt, ...) {
17+
va_list vl;
18+
va_start(vl, fmt);
19+
20+
int r, c;
21+
if(rows < MAX_ROWS) {
22+
r = rows;
23+
rows++;
24+
} else {
25+
r = row0;
26+
row0++;
27+
}
28+
for(c = 0; c < MAX_COLS; c++) {
29+
text[r][c] = ' ';
30+
meta[r][c].link = NOT_A_LINK;
31+
}
32+
33+
int color = COLOR_NORMAL;
34+
35+
c = 0;
36+
while(*fmt) {
37+
if(*fmt == '%') {
38+
} else {
39+
if(c >= MAX_COLS) goto done;
40+
text[r][c++] = *fmt;
41+
}
42+
fmt++;
43+
}
44+
45+
done:
46+
va_end(vl);
47+
}
48+
49+
void TextWindow::ClearCommand(void) {
50+
int j;
51+
for(j = 0; j < MAX_COLS; j++) {
52+
cmd[j] = ' ';
53+
}
54+
memcpy(cmd, "+> ", 3);
55+
cmdLen = 0;
56+
cmdInsert = 3;
57+
row0 = 0;
58+
rows = 0;
59+
}
60+
61+
void TextWindow::KeyPressed(int c) {
62+
if(cmdLen >= MAX_COLS - 10) {
63+
ClearCommand();
64+
return;
65+
}
66+
67+
if(c == '\n' || c == '\r') {
68+
// process the command, and then
69+
ClearCommand();
70+
return;
71+
} else if(c == 27) {
72+
ClearCommand();
73+
} else if(c == '\b') {
74+
// backspace, delete from insertion point
75+
if(cmdInsert <= 3) return;
76+
memmove(cmd+cmdInsert-1, cmd+cmdInsert, MAX_COLS-cmdInsert);
77+
cmdLen--;
78+
cmdInsert--;
79+
} else {
80+
cmd[cmdInsert] = c;
81+
cmdInsert++;
82+
cmdLen++;
83+
}
84+
}
85+

dsc.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
#ifndef __DSC_H
3+
#define __DSC_H
4+
5+
typedef unsigned long DWORD;
6+
typedef unsigned char BYTE;
7+
8+
typedef struct {
9+
double x, y, z;
10+
} Vector;
11+
12+
#endif

obj/t

Whitespace-only changes.

solvespace.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "solvespace.h"
2+
3+
SolveSpace SS;
4+
5+
void SolveSpace::Init(void) {
6+
TW.Init();
7+
8+
TW.Printf("She walks in beauty");
9+
TW.Printf("like the night");
10+
}
11+

solvespace.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
#ifndef __SOLVESPACE_H
3+
#define __SOLVESPACE_H
4+
5+
#include <stdlib.h>
6+
#include <string.h>
7+
#include "dsc.h"
8+
#include "ui.h"
9+
10+
// Debugging functions
11+
#define oops() exit(-1)
12+
void dbp(char *str, ...);
13+
14+
typedef struct {
15+
TextWindow TW;
16+
GraphicsWindow GW;
17+
18+
void Init(void);
19+
} SolveSpace;
20+
21+
extern SolveSpace SS;
22+
23+
#endif

ui.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
#ifndef __UI_H
3+
#define __UI_H
4+
5+
typedef struct {
6+
static const int MAX_COLS = 200;
7+
static const int MAX_ROWS = 500;
8+
9+
// The line with the user-typed command, that is currently being edited.
10+
char cmd[MAX_COLS];
11+
int cmdInsert;
12+
int cmdLen;
13+
14+
// The rest of the window, text displayed in response to typed commands;
15+
// some of this might do something if you click on it.
16+
17+
static const int NOT_A_LINK = 0;
18+
19+
static const int COLOR_NORMAL = 0;
20+
21+
BYTE text[MAX_ROWS][MAX_COLS];
22+
struct {
23+
int color;
24+
int link;
25+
DWORD data;
26+
} meta[MAX_ROWS][MAX_COLS];
27+
28+
int row0, rows;
29+
30+
void Init(void);
31+
void Printf(char *fmt, ...);
32+
void ClearScreen(void);
33+
34+
void ClearCommand(void);
35+
36+
// These are called by the platform-specific code.
37+
void KeyPressed(int c);
38+
bool IsHyperlink(int width, int height);
39+
} TextWindow;
40+
41+
typedef struct {
42+
// These parameters define the map from 2d screen coordinates to the
43+
// coordinates of the 3d sketch points. We will use an axonometric
44+
// projection.
45+
Vector offset;
46+
double scale;
47+
Vector projRight;
48+
Vector projDown;
49+
50+
// These are called by the platform-specific code.
51+
void Paint(void);
52+
void MouseMoved(double x, double y, bool leftDown, bool middleDown,
53+
bool rightDown);
54+
void MouseLeftClick(double x, double y);
55+
void MouseLeftDoubleClick(double x, double y);
56+
void MouseScroll(int delta);
57+
} GraphicsWindow;
58+
59+
#endif

0 commit comments

Comments
 (0)