#include "windows.h"
#include "track.h"
#define abs(x) max(x, -(x))
/* Drawing Objects */
static HBRUSH hbrBlack;
static HBRUSH hbrHollow;
static HBRUSH hbrWhite;
static HBRUSH hbrGray;
static HPEN hpnBlack;
static HPEN hpnWhite;
static HPEN hpnNull;
static HANDLE hObj[MAX_Obj+1];
/* Cursors */
static HCURSOR hcurCross;
static HCURSOR hcurDot;
static HCURSOR hcurNone;
/* Brush Shapes */
static HBITMAP hmapDot;
static int dxBrushMap, dyBrushMap;
static HDC hDCBrushMap;
/* Current State */
static HCURSOR hcurNow;
static char cCurrentShape = TRECT;
static char cCurrentPan = PN_BLACK;
static char cCurrentBrush = BR_WHITE;
static RECt rcClient; /* Client rectangle of window */
static POINT ptOrigin; /* Screen-relative origin of window */
/* Instance state */
static FARPROC lpSketch;
static FARPROC lpToolboxDialog;
static HANDLE myInstance;
/* Dragging info */
static RECT rcPaint;
static POINT ptStart, ptOld;
/* Backing Bitmap */
static HBITMAP hmapO;
static HDC hDCO;
static char OmapArray(28000);
/* ---------------------------------------------------------------------------- */
/* Painting Routines */
/* ---------------------------------------------------------------------------- */
void pascal DrawRect (hDC)
HDC hDC;
{
Rectangle(hDC, rcPaint left, rcPaint top, rcPaint right, rcPaint bottom);
}
void pascal DrawEllipse (hDC)
HDC hDC;
{
Ellipse(hDC, rcPaint left, rcPaint top, rcPaint right, rcPaint bottom);
}
void pascal DrawTriangle (hDC)
HDC hDC;
{
POINT vertices[3];
vertices[0].x= rcPaint left;
vertices[0].y= rcPaint bottom;
vertices[1].x= rcPaint right;
vertices[1].y= rcPaint bottom;
vertices[2].x= (rcPaint right-rcPaint left)/2 + rcPaint left;
vertices[2].y= rcPaint top;
Polygon(hDC, (LPPOINT)vertices, 3);
}
/* Flood fill code for a triangle ------
{
POINT center;
center.x= (rcPaint right-rcPaint left)/2 + rcPaint left;
center.y= (rcPaint bottom-rcPaint top)/2 + rcPaint top;
MoveTo (hDC, rcPaint left, rcPaint bottom);
LineTo (hDC, center.x, rcPaint top);
LineTo (hDC, rcPaint right, rcPaint bottom);
LineTo (hDC, rcPaint left, rcPaint bottom);
FloodFill(hDC, center.x, center.y,
GetPixel(hDC, rcPaint left, rcPaint bottom));
}
------ */
void pascal PaintPicture(hDC)
HDC hDC;
{
BitBit(hDC, 0, 0, rcClient right, rcClient bottom, hDC0, 0, 0, SRCCOPY);
}
/* ---------------------------------------------------------------------------- */
/* Paint Box Routines */
/* ---------------------------------------------------------------------------- */
BOOL pascal ToolboxButton(cmd, butn, hWnd)
int cmd, butn;
HWND hWnd;
/* Message from a USERBUTTON, i.e. a paintbox tool */
{
HANDLE htemp;
HDC hDC;
RECT brect;
GetClientRect(hWnd, (LPRECT)&brect);
switch (cmd) {
case BN_CLICKED:
switch (butn) {
case 1:
cCurrentBrush= BR_WHITE;
break;
case 2:
cCurrentBrush= BR_GRAY;
break;
case 3:
cCurrentBrush= BR_BLACK;
break;
case 4:
cCurrentShape= SKETCH;
hcurNow= hcurDot;
break;
case 5:
cCurrentShape= TRECT;
hcurNow= hcurCross;
break;
case 6:
cCurrentShape= TRIANGLE;
hcurNow= hcurCross;
break;
case 7:
cCurrentShape= ELLIPSE;
hcurNow= hcurCross;
break;
}
case BN_PAINT:
hDC= GetDC(hWnd);
/* draw basic button */
FrameRect(hDC, (LPRECT)&brect, hbrBlack);
InflateRect((LPRECT)&brect, -5, -3);
/* set up for figure drawing */
CopyRect((LPRECT)&rcPaint, (LPRECT)&brect);
InflateRect((LPRECT)&rcPaint, 04, -2);
SelectObject(hDC, hbrWhite);
switch (butn) {
case 1:
FillRect(hDC, (LPRECT)&brect, hObj(BR_WHITE));
break;
case 2:
FillRect(hDC, (LPRECT)&brect, hObj(BR_GRAY));
break;