uses Windows, Forms;
const
SCALE = 5;
TRANSLATE = 4;
ROTATE = 3;
SHEAR = 2;
REFLECT = 1;
NORMAL = 0;
{$IFDEF API} // If defined draws with pure api functions (smaller code)
procedure TransformAndDraw(Transform:TXform;DC:HDC);
var
//TransForm:TXform;
Rect:TRect;
begin
// Set the mapping mode to LOENGLISH. This moves the
// client area origin from the upper left corner of the
// window to the lower left corner (this also reorients
// the y-axis so that drawing operations occur in a true
// Cartesian space). It guarantees portability so that
// the object drawn retains its dimensions on any display.
SetGraphicsMode(DC, GM_ADVANCED);
SetMapMode(DC, MM_LOENGLISH); //inches, for metric select LOMETRIC
// Set the appropriate world transformation (based on the
// user's menu selection).
case iTransform of
SCALE: // Scale to 1/2 of the original size.
begin
TransForm.eM11 := 0.5;
TransForm.eM12 := 0.0;
TransForm.eM21 := 0.0;
TransForm.eM22 := 0.5;
TransForm.eDx := 0.0;
TransForm.eDy := 0.0;
SetWorldTransform(DC, TransForm);
end;
TRANSLATE: // Translate right by 3/4 inch.
begin
TransForm.eM11 := 1.0;
TransForm.eM12 := 0.0;
TransForm.eM21 := 0.0;
TransForm.eM22 := 1.0;
TransForm.eDx := 75.0;
TransForm.eDy := 0.0;
SetWorldTransform(DC, TransForm);
end;
ROTATE: // Rotate 30 degrees counterclockwise.
begin
TransForm.eM11 := 0.8660;
TransForm.eM12 := -0.5000;
TransForm.eM21 := 0.5000;
TransForm.eM22 := 0.8660;
TransForm.eDx := 0.0;
TransForm.eDy := 0.0;
SetWorldTransform(DC, TransForm);
end;
SHEAR: // Shear along the x-axis with a
begin // proportionality constant of 1.0.
TransForm.eM11 := 1.0;
TransForm.eM12 := 1.0;
TransForm.eM21 := 0.0;
TransForm.eM22 := 1.0;
TransForm.eDx := 0.0;
TransForm.eDy := 0.0;
SetWorldTransform(DC, TransForm);
end;
REFLECT: // Reflect about a horizontal axis.
begin
TransForm.eM11 := 1.0;
TransForm.eM12 := 0.0;
TransForm.eM21 := 0.0;
TransForm.eM22 := -1.0;
TransForm.eDx := 0.0;
TransForm.eDy := 0.0;
SetWorldTransform(DC, TransForm);
end;
NORMAL: // Set the unity transformation.
begin
TransForm.eM11 := 1.0;
TransForm.eM12 := 0.0;
TransForm.eM21 := 0.0;
TransForm.eM22 := 1.0;
TransForm.eDx := 0.0;
TransForm.eDy := 0.0;
SetWorldTransform(DC, TransForm);
end;
end;
// Find the midpoint of the client area.
GetClientRect(Form1.form.Handle, rect);
DPtoLP(DC, rect, 2);
// Select a hollow brush.
SelectObject(DC, GetStockObject(HOLLOW_BRUSH));
// Draw the exterior circle.
Ellipse(DC, Round(rect.right / 2 - 100), Round(rect.bottom / 2 + 100),
Round(rect.right / 2 + 100), Round(rect.bottom / 2 - 100));
// Draw the interior circle.
Ellipse(DC, Round(rect.right / 2 -94), Round(rect.bottom / 2 + 94),
Round(rect.right / 2 + 94), Round(rect.bottom / 2 - 94));
// Draw the key.
Rectangle(DC, Round(rect.right / 2 - 13), Round(rect.bottom / 2 + 113),
Round(rect.right / 2 + 13), Round(rect.bottom / 2 + 50));
Rectangle(DC, Round(rect.right / 2 - 13), Round(rect.bottom / 2 + 96),
Round(rect.right / 2 + 13), Round(rect.bottom / 2 + 50));
// Draw a diagonal line
MoveToEx(DC, Round(rect.right/2 ), Round(rect.bottom / 2 + 100), 0);
LineTo(DC, Round(rect.right / 2 +100), Round(rect.bottom / 2 + 0));
// Draw the horizontal lines.
MoveToEx(DC, Round(rect.right/2 - 150), Round(rect.bottom / 2 + 0), 0);
LineTo(DC, Round(rect.right / 2 - 16), Round(rect.bottom / 2 + 0));
MoveToEx(DC, Round(rect.right / 2 - 13), Round(rect.bottom / 2 + 0), 0);
LineTo(DC, Round(rect.right / 2 + 13), Round(rect.bottom / 2 + 0));
MoveToEx(DC, Round(rect.right / 2 + 16), Round(rect.bottom / 2 + 0), 0);
LineTo(DC, Round(rect.right / 2 + 150), Round(rect.bottom / 2 + 0));
// Draw the vertical lines.
MoveToEx(DC, Round(rect.right/2 + 0), Round(rect.bottom / 2 - 150), 0);
LineTo(DC, Round(rect.right / 2 + 0), Round(rect.bottom / 2 - 16));
MoveToEx(DC, Round(rect.right / 2 + 0), Round(rect.bottom / 2 - 13), 0);
LineTo(DC, Round(rect.right / 2 + 0), Round(rect.bottom / 2 + 13));
MoveToEx(DC, Round(rect.right / 2 + 0), Round(rect.bottom / 2 + 16), 0);
LineTo(DC, Round(rect.right / 2 + 0), Round(rect.bottom / 2 + 150));
end;