I'm building an application ina Delphi application which simulates various levelsdisplays a blueprint of a building, including all thedoors, windows, wiring, lighting, doorsoutlets, switches, etc. It's essentially an application which displays a blueprint of a building. I have implemented a very lightweight script of my own to call drawing commands to the canvas, which is loaded from a database. For example, one command is ELP 1110,1110,1290,1290,3,8388608 which draws an ellipse, parameters are 1110x1110 to 1290x1290 with pen width of 3 and the color 8388608 converted from an integer to a TColor.
function DrawCommand(const Cmd: String; var Canvas: TCanvas): Boolean;
type
TSingleArray = array of Single;
var
Br: TBrush;
Pn: TPen;
X: Integer;
P: Integer;
L: String;
Inst: String;
T: String;
Nums: TSingleArray;
begin
Result:= False;
Br:= Canvas.Brush;
Pn:= Canvas.Pen;
if Assigned(Canvas) then begin
if Length(Cmd) > 5 then begin
L:= UpperCase(Cmd);
P:=if Pos(' ', L);
if P > 0 then begin
Inst:= Copy(L, 1, PPos(' ', L) - 1);
Delete(L, 1, PPos(' ', L));
L:= L + ',';
SetLength(Nums, 0);
X:= 0;
while Pos(',', L) > 0 do begin
P:= Pos(',', L);
T:= Copy(L, 1, P - 1);
Delete(L, 1, P);
SetLength(Nums, X + 1);
Nums[X]:= StrToFloatDef(T, 0);
Inc(X);
end;
Br.Style:= bsClear;
Pn.Style:= psSolid;
Pn.Color:= clBlack;
if Inst = 'LIN' then begin
Pn.Width:= Trunc(Nums[4]);
if Length(Nums) > 5 then begin
Br.Style:= bsSolid;
Br.Color:= Trunc(Nums[5]);
end;
Canvas.MoveTo(Trunc(Nums[0]), Trunc(Nums[1]));
Canvas.LineTo(Trunc(Nums[2]), Trunc(Nums[3]));
Result:= True;
end else
if Inst = 'ELP' then begin
Pn.Width:= Trunc(Nums[4]);
if Length(Nums) > 5 then begin
Br.Style:= bsSolid;
Br.Color:= Trunc(Nums[5]);
end;
Canvas.Ellipse(Trunc(Nums[0]),Trunc(Nums[1]),Trunc(Nums[2]),Trunc(Nums[3]));
Result:= True;
end else
if Inst = 'ARC' then begin
Pn.Width:= Trunc(Nums[8]);
Canvas.Arc(Trunc(Nums[0]),Trunc(Nums[1]),Trunc(Nums[2]),Trunc(Nums[3]),
Trunc(Nums[4]),Trunc(Nums[5]),Trunc(Nums[6]),Trunc(Nums[7]));
Result:= True;
end else
if Inst = 'TXT' then begin
Canvas.Font.Size:= Trunc(Nums[2]);
Br.Style:= bsClear;
Pn.Style:= psSolid;
T:= Cmd;
Delete(T, 1, Pos(' ', T));
Delete(T, 1, Pos(',', T));
Delete(T, 1, Pos(',', T));
Delete(T, 1, Pos(',', T));
Canvas.TextOut(Trunc(Nums[0]), Trunc(Nums[1]), T);
Result:= True;
end;
end else begin
//No space found, not a valid command
end;
end;
end;
end;