SRL Archive - SRL Suggestions

More Smart painting functions


mormonman

2011-11-21 19:21:50

Few additions/one procedure title change(needs to be done).
If you have anymore post here(or if you want some other ones).

Edit: Added function list to top
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- ********* Smart Painting routines --//
//-----------------------------------------------------------------//
// Procedure SMART_ClearCanvas;
// Procedure SMART_DrawDotsMulti(Clear: boolean; pixels : T2DPointArray);
// Procedure SMART_DrawDotsEx(Clear: boolean; pixels: TPointArray; color: TColor);
// Procedure SMART_DrawDots(Dots: TPointArray);
// Procedure SMART_DrawBoxesEx(Clear: Boolean; TBA: TBoxArray; Color: Integer);
// Procedure SMART_DrawBoxes(TBA: TBoxArray);
// Procedure SMART_DrawBoxEx(Clear: boolean; Box: TBox; color: TColor);
// Procedure SMART_DrawBox(Box: TBox);
// Procedure SMART_DrawBoxMS(Clear: Boolean; Box: TBox; Color: TColor);
// Procedure SMART_DrawLine(Clear: Boolean; TP1, TP2: TPoint; Color: TColor);
// Procedure SMART_DrawCircleEx(Clear: Boolean; Center: TPoint; Radius: Integer; Fill: Boolean; Color: TColor);
// Procedure SMART_DrawCircle(Center: TPoint; Radius: Integer);
// Procedure SMART_DrawDotEx(Clear: Boolean; Point: TPoint; Big: Boolean; color: TColor);
// Procedure SMART_DrawDot(Point: TPoint);
// Procedure SMART_DrawPolygonsEx(Clear: Boolean; Polygons: T2DPointArray; color: TColor);
// Procedure SMART_DrawPolygons(Polygons: T2DPointArray);
// Procedure SMART_DrawPolygonEx(Clear: Boolean; Vertices: TPointArray; color: TColor);
// Procedure SMART_DrawPolygon(Vertices: TPointArray);
// Procedure SMART_DrawTextEx(Clear: Boolean; x, y: Integer; font, Text: string; Color:TColor);
// Procedure SMART_DrawText(x, y: Integer; font, Text: string; Color:TColor);
//-----------------------------------------------------------------//

var
SMART_Canvas: TBitmap;
SMART_DebugSetup: Boolean;

{*******************************************************************************
procedure SMART_SetupDebug();
Contributors: Unknown
Description: Creates the SMART canvas
*******************************************************************************}
procedure SMART_SetupDebug();
begin
SmartSetDebug(True);
SMART_Canvas := TBitmap.Create;
SMART_Canvas.canvas.handle := SmartGetDebugDC;
SMART_DebugSetup := true;
end;

{*******************************************************************************
Procedure ClearCanvas(canvas: TCanvas; w, h: integer);
Contributors: Sir R. Magician, mastaraymond
Description: Clears a canvas of dimensions (w, h)
*******************************************************************************}
Procedure ClearCanvas(canvas: TCanvas; w, h: integer);
var
CleanBMP: integer;
begin

CleanBMP := BitmapFromString(w, h, '');

{$ifdef Simba}
DrawBitmap(CleanBMP,Canvas,0,0);
{$else}
SafeDrawBitmap(CleanBMP, canvas, 0, 0);
{$endif}

try
FreeBitmap(CleanBMP);
except
writeln('SMART BITMAP NOT FREED');
end;

end;

{*******************************************************************************
Procedure ClearRSCanvas(canvas: TCanvas);
Contributors: Sir R. Magician
Description: Clears a canvas of RS dimensions
*******************************************************************************}
Procedure ClearRSCanvas(canvas: TCanvas);
begin
if (not SMART_DebugSetup) then
SMART_SetupDebug();

ClearCanvas(canvas, MIX2 + 100, MIY2 + 100);
end;

{*******************************************************************************
procedure SMART_ClearCanvas;
Contributors: mormonman
Description: Clears smart's canvas
*******************************************************************************}
procedure SMART_ClearCanvas;
begin
{$IFDEF SMART}
if (not SMART_DebugSetup) then
SMART_SetupDebug();
ClearRSCanvas(SMART_Canvas.canvas);
{$ENDIF}
end;

{*******************************************************************************
procedure SMART_DrawDotsMulti(Clear: boolean; pixels : T2DPointArray);
Contributors: Sir R. Magician
Description: Draws an ATPA onto the SMART Debug canvas
*******************************************************************************}
procedure SMART_DrawDotsMulti(Clear: boolean; pixels : T2DPointArray);
{$IFDEF SMART}
var
i, h, color : integer;
begin
if (not SMART_DebugSetup) then
SMART_SetupDebug();

if Clear then SMART_ClearCanvas;

for h := 0 to High(pixels) do
begin

color := h div 5 + h mod 5;
case color of
0 : SMART_Canvas.canvas.Pen.Color := clWhite;
1 : SMART_Canvas.canvas.Pen.Color := clYellow;
2 : SMART_Canvas.canvas.Pen.Color := clBlue;
3 : SMART_Canvas.canvas.Pen.Color := clLime;
4 : SMART_Canvas.canvas.Pen.Color := clGreen;
end;

for i:= 0 to High(pixels[h]) do
begin
SMART_Canvas.canvas.moveto(pixels[h][i].x-1, pixels[h][i].y);
SMART_Canvas.canvas.LineTo(pixels[h][i].x, pixels[h][i].y);
end;
end;

{$ELSE}
begin
{$ENDIF}
end;

{*******************************************************************************
Procedure SMART_DrawDotsEx(Clear: boolean; pixels: TPointArray; color: TColor);
Contributors: Sir R. Magician, caused, mastaraymond
Description: Draws a TPA onto the SMART Debug canvas
*******************************************************************************}
procedure SMART_DrawDotsEx(Clear: boolean; pixels: TPointArray; color: TColor);
{$IFDEF SMART}
var
i : integer;
begin
if (not SMART_DebugSetup) then
SMART_SetupDebug();

SMART_Canvas.canvas.Pen.Color := color;
if Clear then SMART_ClearCanvas;

for i:= 0 to high(pixels) do
begin
SMART_Canvas.canvas.moveto(pixels[i].x-1,pixels[i].y);
SMART_Canvas.canvas.LineTo(pixels[i].x,pixels[i].y);
end;

{$ELSE}
begin
{$ENDIF}

end;

{*******************************************************************************
Procedure SMART_DrawDots(Dots: TPointArray);
Contributors: Sir R. Magician
Description: Draws a TPA onto the SMART Debug canvas
*******************************************************************************}
procedure SMART_DrawDots(Dots: TPointArray);
begin
SMART_DrawDotsEx(True, Dots, clRed);
end;

{*******************************************************************************
procedure SMART_DrawBoxesEx(Clear: Boolean; TBA: TBoxArray; Color: Integer);
Contributors: mormonman
Description: Draws an array of boxes onto the SMART Debug canvas. Enter -1
for it to use different colors(like in SMART_DrawDotsMulti).
*******************************************************************************}
procedure SMART_DrawBoxesEx(Clear: Boolean; TBA: TBoxArray; Color: Integer);
{$IFDEF SMART}
var
i, colour: Integer;
begin
if (not SMART_DebugSetup) then
SMART_SetupDebug();

if Clear then SMART_ClearCanvas;

if (Length(TBA) < 1) then Exit;
for i := 0 to High(TBA) do
begin
if (Color > 0) then
begin
SMART_Canvas.canvas.Pen.Color := color;
end else
begin
colour := i div 5 + i mod 5;
case colour of
0 : SMART_Canvas.canvas.Pen.Color := clWhite;
1 : SMART_Canvas.canvas.Pen.Color := clYellow;
2 : SMART_Canvas.canvas.Pen.Color := clBlue;
3 : SMART_Canvas.canvas.Pen.Color := clLime;
4 : SMART_Canvas.canvas.Pen.Color := clGreen;
end;
end;

SMART_Canvas.canvas.moveto(TBA[i].x1,TBA[i].y1);
SMART_Canvas.canvas.LineTo(TBA[i].x2,TBA[i].y1);
SMART_Canvas.canvas.LineTo(TBA[i].x2,TBA[i].y2);
SMART_Canvas.canvas.LineTo(TBA[i].x1,TBA[i].y2);
SMART_Canvas.canvas.LineTo(TBA[i].x1,TBA[i].y1);
end;

{$ELSE}
begin
{$ENDIF}

end;

{*******************************************************************************
procedure SMART_DrawBoxes(TBA: TBoxArray);
Contributors: mormonman
Description: Draws an array of boxes onto the SMART Debug canvas.
*******************************************************************************}
procedure SMART_DrawBoxes(TBA: TBoxArray);
begin
SMART_DrawBoxesEx(True, TBA, clRed);
end;

{*******************************************************************************
procedure SMART_DrawBoxEx(Clear: boolean; Box: TBox; color: TColor);
Contributors: Sir R. Magician, caused, mastaraymond
Description: Draws a TBox onto the SMART Debug canvas
*******************************************************************************}
procedure SMART_DrawBoxEx(Clear: boolean; Box: TBox; color: TColor);
begin
SMART_DrawBoxesEx(Clear, [Box], color);
end;

{*******************************************************************************
Procedure SMART_DrawBox(Box: TBox);
Contributors: Sir R. Magician
Description: Draws a TBox onto the SMART Debug canvas
*******************************************************************************}
procedure SMART_DrawBox(Box: TBox);
begin
SMART_DrawBoxEx(True, Box, clRed);
end;

{*******************************************************************************
procedure SMART_DrawBoxMS(Clear: Boolean; Box: TBox; Color: TColor);
Contributors: Unknown
Description: Draws a TBox onto the SMART Debug canvas
*******************************************************************************}
procedure SMART_DrawBoxMS(Clear: Boolean; Box: TBox; Color: TColor);
begin
if (Box.X1 < MSX1) then Box.X1 := MSX1;
if (Box.Y1 < MSY1) then Box.Y1 := MSY1;
if (Box.X2 > MSX2) then Box.X2 := MSX2;
if (Box.Y2 > MSY2) then Box.Y2 := MSY2;
SMART_DrawBoxEx(Clear, Box, Color);
end;

{*******************************************************************************
procedure SMART_DrawLine(Clear: Boolean; TP1, TP2: TPoint; Color: TColor);
by: mormonman
Description: Draws a line on your screen.
*******************************************************************************}
procedure SMART_DrawLine(Clear: Boolean; TP1, TP2: TPoint; Color: TColor);
begin
{$IFDEF SMART}
if (not SMART_DebugSetup) then
SMART_SetupDebug();

SMART_Canvas.canvas.Pen.Color := Color;

if Clear then SMART_ClearCanvas;

SMART_Canvas.canvas.moveto(TP1.x,TP1.y);
SMART_Canvas.canvas.LineTo(TP2.x,TP2.y);
{$ENDIF}
end;

{*******************************************************************************
procedure SMART_DrawCircleEx(Clear: Boolean; Center: TPoint; Radius: Integer; Fill: Boolean; Color: TColor);
by: mormonman
Description: Draws a circle on the Smart canvas defined by center and radius. If
Fill is true it will fill the circle, otherwise it draws the border.
*******************************************************************************}
procedure SMART_DrawCircleEx(Clear: Boolean; Center: TPoint; Radius: Integer; Fill: Boolean; Color: TColor);
{$IFDEF SMART}
var
TPA: TPointArray;
begin
TPA := TPAFromBox(IntToBox(Center.X - Radius, Center.Y - Radius, Center.X + Radius, Center.Y + Radius));
FilterPointsPie(TPA, 0, 360, -1, Radius, Center.X, Center.Y);
if not Fill then FilterPointsDist(TPA, Radius-1, Radius, Center.X, Center.Y);
if (Length(TPA) < 1) then Exit;
SMART_DrawDotsEx(Clear, TPA, Color);
{$ELSE}
begin
{$ENDIF}
end;

{*******************************************************************************
procedure SMART_DrawCircle(Center: TPoint; Radius: Integer);
by: mormonman
Description: Draws a circle on the Smart canvas defined by center and radius.
*******************************************************************************}
procedure SMART_DrawCircle(Center: TPoint; Radius: Integer);
begin
SMART_DrawCircleEx(True, Center, Radius, False, clRed);
end;

{*******************************************************************************
procedure SMART_DrawDotEx(Clear: Boolean; Point: TPoint; Big: Boolean; color: TColor);
by: mormonman
Description: Draws a dot at the Point onto the Smart canvas. If Big is true then
the radius is 8 else the radius is 4.
*******************************************************************************}
procedure SMART_DrawDotEx(Clear: Boolean; Point: TPoint; Big: Boolean; color: TColor);
begin
if Big then
SMART_DrawCircleEx(Clear, Point, 11, True, Color)
else
SMART_DrawCircleEx(Clear, Point, 4, True, Color);
end;

{*******************************************************************************
procedure SMART_DrawDot(Point: TPoint);
by: mormonman
Description: Draws a dot with a radius of 4 at the Point onto the Smart canvas
*******************************************************************************}
procedure SMART_DrawDot(Point: TPoint);
begin
SMART_DrawDotEx(True, Point, False, clRed);
end;

{*******************************************************************************
procedure SMART_DrawPolygonsEx(Clear: Boolean; Polygons: T2DPointArray; color: TColor);
by: mormonman
Description: Draws an array of polygons onto the SMART canvas
*******************************************************************************}
procedure SMART_DrawPolygonsEx(Clear: Boolean; Polygons: T2DPointArray; color: TColor);
{$IFDEF SMART}
var
i, h, Hi: Integer;
begin
if Clear then SMART_ClearCanvas;
if (Length(Polygons) < 1) then Exit;
for h := 0 to High(Polygons) do
begin
Hi := High(Polygons[h]);
if (Hi < 2) then Exit;
for i := 0 to Hi - 1 do
SMART_DrawLine(False, Polygons[h][i], Polygons[h][i+1], color);
SMART_DrawLine(False, Polygons[h][Hi], Polygons[h][0], color);
end;
{$ELSE}
begin
{$ENDIF}
end;

{*******************************************************************************
procedure SMART_DrawPolygons(Polygons: T2DPointArray);
by: mormonman
Description: Draws an array of polygons onto the SMART canvas
*******************************************************************************}
procedure SMART_DrawPolygons(Polygons: T2DPointArray);
begin
SMART_DrawPolygonsEx(True, Polygons, clRed);
end;

{*******************************************************************************
procedure SMART_DrawPolygonEx(Clear: Boolean; Vertices: TPointArray; color: TColor);
by: mormonman
Description: Draws a polygon defined by Vertices onto the SMART canvas
*******************************************************************************}
procedure SMART_DrawPolygonEx(Clear: Boolean; Vertices: TPointArray; color: TColor);
begin
SMART_DrawPolygonsEx(Clear, [Vertices], color);
end;

{*******************************************************************************
procedure SMART_DrawPolygon(Vertices: TPointArray);
by: mormonman
Description: Draws a polygon defined by Vertices onto the SMART canvas
*******************************************************************************}
procedure SMART_DrawPolygon(Vertices: TPointArray);
begin
SMART_DrawPolygonEx(True, Vertices, clRed);
end;

{*******************************************************************************
procedure SMART_DrawTextEx(Clear: Boolean; x, y: Integer; font, Text: string; Color: TColor);
Contributors: Jukka, Shuttleu
Description: Draws text onto the SMART Debug canvas at position x, y
*******************************************************************************}
procedure SMART_DrawTextEx(Clear: Boolean; x, y: Integer; font, Text: string; Color:TColor);
var
i, height: integer;
tpa: tpointarray;
begin
tpa := LoadTextTPA(text,font,height);
for i:= 0 to high(tpa) do
begin
tpa[i].x := tpa[i].x + x;
tpa[i].y := tpa[i].y + y;
end;
SMART_DrawDotsEx(Clear, tpa, Color);
end;

{*******************************************************************************
procedure SMART_DrawText(x, y: Integer; font, Text: string; Color: TColor);
Contributors: Shuttleu
Description: Draws text onto the SMART Debug canvas at position x, y
*******************************************************************************}
procedure SMART_DrawText(x, y: Integer; font, Text: string; Color:TColor);
begin
SMART_DrawTextEx(False, x, y, font, Text, Color);
end;

{*******************************************************************************
procedure SMART_FreeDebug();
Contributors: Unknown
Description: Frees the smart canvas
*******************************************************************************}
procedure SMART_FreeDebug();
begin
try
if (SMART_DebugSetup) then
SMART_Canvas.Free;
except
Writeln('Failed to free SMART_Canvas bitmap: '+ExceptionToString(ExceptionType, ExceptionParam));
end;
end;

Nava2

2011-11-21 19:35:57

Diff?

mormonman

2011-11-21 19:55:11

From: Nava2
Diff?


http://diffchecker.com/A14i8Oz

euphemism

2011-11-21 21:15:48

These are all very nice, and scripters will get great use out of them. Thank you for these.

DeSnob

2011-11-21 21:24:22

YES these need to be supported. I've been wanting a circle debug on my scripts for quite some time. Thanks. :)

Coh3n

2011-11-22 02:07:49

Cool. Was the name change really that necessary? Just wondering because it may break scripts.

mormonman

2011-11-22 02:12:07

From: Coh3n
Cool. Was the name change really that necessary? Just wondering because it may break scripts.


Yes. Unification. :)

Nava2

2011-11-22 09:07:44

I feel like this:

{*******************************************************************************
procedure SMART_DrawCircleEx(Clear: Boolean; Center: TPoint; Radius: Integer; Fill: Boolean; Color: TColor);
by: mormonman
Description: Draws a circle on the Smart canvas defined by center and radius. If
Fill is true it will fill the circle, otherwise it draws the border.
*******************************************************************************}
procedure SMART_DrawCircleEx(Clear: Boolean; Center: TPoint; Radius: Integer; Fill: Boolean; Color: TColor);
{$IFDEF SMART}
var
TPA: TPointArray;
begin
TPA := TPAFromBox(IntToBox(Center.X - Radius, Center.Y - Radius, Center.X + Radius, Center.Y + Radius));
FilterPointsPie(TPA, 0, 360, -1, Radius, Center.X, Center.Y);
if not Fill then FilterPointsDist(TPA, Radius-1, Radius, Center.X, Center.Y);
if (Length(TPA) < 1) then Exit;
SMART_DrawDotsEx(Clear, TPA, Color);
{$ELSE}
begin
{$ENDIF}
end;

Is horribly inefficient.. what about doing circlewise maths.

That method is VERY slow.. especially filtering all those pts you create.

DaWu

2011-11-22 09:10:56

If only we could have the paint run in separate thread.

mormonman

2011-11-22 17:47:34

From: Nava2
I feel like this:

{*******************************************************************************
procedure SMART_DrawCircleEx(Clear: Boolean; Center: TPoint; Radius: Integer; Fill: Boolean; Color: TColor);
by: mormonman
Description: Draws a circle on the Smart canvas defined by center and radius. If
Fill is true it will fill the circle, otherwise it draws the border.
*******************************************************************************}
procedure SMART_DrawCircleEx(Clear: Boolean; Center: TPoint; Radius: Integer; Fill: Boolean; Color: TColor);
{$IFDEF SMART}
var
TPA: TPointArray;
begin
TPA := TPAFromBox(IntToBox(Center.X - Radius, Center.Y - Radius, Center.X + Radius, Center.Y + Radius));
FilterPointsPie(TPA, 0, 360, -1, Radius, Center.X, Center.Y);
if not Fill then FilterPointsDist(TPA, Radius-1, Radius, Center.X, Center.Y);
if (Length(TPA) < 1) then Exit;
SMART_DrawDotsEx(Clear, TPA, Color);
{$ELSE}
begin
{$ENDIF}
end;

Is horribly inefficient.. what about doing circlewise maths.

That method is VERY slow.. especially filtering all those pts you create.


Just made these and ran a test…
Output:
Compiled successfully in 577 ms.
SRL Compiled in 0 msec
(50, 50, 150, 150)
(50, 50, 150, 150)
(51, 51, 149, 149)
starting bresenham
starting filter
starting roundedrect
bresenham: 2.98 filter: 1.26 roundedrect: 2.57
Successfully executed.

program Default;
{$i srl\srl.scar}

const
{---SMART Setup Constants---}
WORLD = 35;
MEMBERS = false;
SIGNED = true;
SUPERDETAIL = false;
{---------------------------}

function CircleToTPA(Center: TPoint; Radius: Integer): TPointArray;
var
Len, c, i, x, y, r2, y2, y2_new, ty: Integer;
begin
c := Ceil((2.0 * Pi) * Radius);
SetLength(Result, c + 1);

Len := Ceil((Radius * 185363) shr 18);
y := Radius;

y2 := y * y;
r2 := y2;
ty := (2 * y) -1;
y2_new := r2 + 3;

i := 0;
for x := 0 to Len do
begin
y2_new := y2_new - ((2* x) - 3);

if ((y2 - y2_new) >= ty) then
begin
y2 := y2 - ty;
y := y - 1;
ty := ty - 2;
end;

Result[i] := Point(x + Center.x, y + Center.y);
i := i + 1;
Result[i] := Point(x + Center.x, -y + Center.y);
i := i + 1;
Result[i] := Point(-x + Center.x, y + Center.y);
i := i + 1;
Result[i] := Point(-x + Center.x, -y + Center.y);
i := i + 1;
Result[i] := Point(y + Center.x, x + Center.y);
i := i + 1;
Result[i] := Point(y + Center.x, -x + Center.y);
i := i + 1;
Result[i] := Point(-y + Center.x, x + Center.y);
i := i + 1;
Result[i] := Point(-y + Center.x, -x + Center.y);
i := i + 1;
end;
SetLength(Result, i);
end;

function CircleToTPA2(Center: TPoint; Radius: Integer): TPointArray;
var
Len, x, y, f, ddf_x, ddf_y: Integer;
begin
Len := Ceil((2.0 * pi) * (Radius * 1.0));
SetLength(Result, Len);
Len := 0;

f := 1 - Radius;
ddF_x := 1;
ddF_y := -2 * radius;
x := 0;
y := radius;

Result[Len] := Point(Center.x, Center.y + Radius);
Inc(Len);
Result[Len] := Point(Center.x, Center.y - Radius);
Inc(Len);
Result[Len] := Point(Center.x - Radius, Center.y);
Inc(Len);
Result[Len] := Point(Center.x + Radius, Center.y);
Inc(Len);

while (x < y) do
begin
if (f >= 0) then
begin
y := y - 1;
ddF_y := ddF_y + 2;
f := f + ddF_y;
end;
x := x + 1;
ddF_x := ddF_x + 2;
f := f + ddF_x;
Result[Len] := Point(Center.x + x, Center.y + y);
Inc(Len);
Result[Len] := Point(Center.x + x, Center.y - y);
Inc(Len);
Result[Len] := Point(Center.x - x, Center.y + y);
Inc(Len);
Result[Len] := Point(Center.x - x, Center.y - y);
Inc(Len);
Result[Len] := Point(Center.x + y, Center.y + x);
Inc(Len);
Result[Len] := Point(Center.x + y, Center.y - x);
Inc(Len);
Result[Len] := Point(Center.x - y, Center.y + x);
Inc(Len);
Result[Len] := Point(Center.x - y, Center.y - x);
Inc(Len);
end;
SetLength(Result, Len);
end;

function filtercircle(Center: TPoint; Radius: Integer): TPointArray;
begin
Result := TPAFromBox(IntToBox(Center.X - Radius, Center.Y - Radius, Center.X + Radius, Center.Y + Radius));
FilterPointsPie(Result, 0, 360, -1, Radius, Center.X, Center.Y);
FilterPointsDist(Result, Radius-1, Radius+1, Center.X, Center.Y);
end;

var
circle: TPointArray;
p: TPoint;
i, t, time, time2, time3, r: Integer;

begin
Smart_Server := 4;
SetupSRL;
p := Point(100, 100);
r := 50
i := 0;
writeln(gettpabounds(CircleToTPA(P, r)));
writeln(gettpabounds(CircleToTPA2(P, r)));
writeln(gettpabounds(filtercircle(P, r)));

writeln('starting bresenham');
MarkTime(t);
while (i < 15000)do
begin
circle := CircleToTPA(P, r);
inc(i);
end;
time := TimeFromMark(T);

i := 0;
writeln('starting filter');
marktime(t)
while (i < 15000)do
begin
circle := filtercircle(P, r);
inc(i);
end;
time2 := TimeFromMark(T);

i := 0;
writeln('starting roundedrect');
MarkTime(t);
while (i < 15000)do
begin
circle := CircleToTPA2(P, r);
inc(i);
end;
time3 := TimeFromMark(T);

writeln(format('bresenham: %f filter: %f roundedrect: %f', [time/15000.0, time2/15000.0, time3/15000.0]));

end.

mormonman

2011-11-23 16:37:46

Working on ellipse then using that to create circle.

Nava2

2011-11-23 16:54:44

From: mormonman
Just made these and ran a test…
Output:
Compiled successfully in 577 ms.
SRL Compiled in 0 msec
(50, 50, 150, 150)
(50, 50, 150, 150)
(51, 51, 149, 149)
starting bresenham
starting filter
starting roundedrect
bresenham: 2.98 filter: 1.26 roundedrect: 2.57
Successfully executed.

program Default;
{$i srl\srl.scar}

const
{---SMART Setup Constants---}
WORLD = 35;
MEMBERS = false;
SIGNED = true;
SUPERDETAIL = false;
{---------------------------}

function CircleToTPA(Center: TPoint; Radius: Integer): TPointArray;
var
Len, c, i, x, y, r2, y2, y2_new, ty: Integer;
begin
c := Ceil((2.0 * Pi) * Radius);
SetLength(Result, c + 1);

Len := Ceil((Radius * 185363) shr 18);
y := Radius;

y2 := y * y;
r2 := y2;
ty := (2 * y) -1;
y2_new := r2 + 3;

i := 0;
for x := 0 to Len do
begin
y2_new := y2_new - ((2* x) - 3);

if ((y2 - y2_new) >= ty) then
begin
y2 := y2 - ty;
y := y - 1;
ty := ty - 2;
end;

Result[i] := Point(x + Center.x, y + Center.y);
i := i + 1;
Result[i] := Point(x + Center.x, -y + Center.y);
i := i + 1;
Result[i] := Point(-x + Center.x, y + Center.y);
i := i + 1;
Result[i] := Point(-x + Center.x, -y + Center.y);
i := i + 1;
Result[i] := Point(y + Center.x, x + Center.y);
i := i + 1;
Result[i] := Point(y + Center.x, -x + Center.y);
i := i + 1;
Result[i] := Point(-y + Center.x, x + Center.y);
i := i + 1;
Result[i] := Point(-y + Center.x, -x + Center.y);
i := i + 1;
end;
SetLength(Result, i);
end;

function CircleToTPA2(Center: TPoint; Radius: Integer): TPointArray;
var
Len, x, y, f, ddf_x, ddf_y: Integer;
begin
Len := Ceil((2.0 * pi) * (Radius * 1.0));
SetLength(Result, Len);
Len := 0;

f := 1 - Radius;
ddF_x := 1;
ddF_y := -2 * radius;
x := 0;
y := radius;

Result[Len] := Point(Center.x, Center.y + Radius);
Inc(Len);
Result[Len] := Point(Center.x, Center.y - Radius);
Inc(Len);
Result[Len] := Point(Center.x - Radius, Center.y);
Inc(Len);
Result[Len] := Point(Center.x + Radius, Center.y);
Inc(Len);

while (x < y) do
begin
if (f >= 0) then
begin
y := y - 1;
ddF_y := ddF_y + 2;
f := f + ddF_y;
end;
x := x + 1;
ddF_x := ddF_x + 2;
f := f + ddF_x;
Result[Len] := Point(Center.x + x, Center.y + y);
Inc(Len);
Result[Len] := Point(Center.x + x, Center.y - y);
Inc(Len);
Result[Len] := Point(Center.x - x, Center.y + y);
Inc(Len);
Result[Len] := Point(Center.x - x, Center.y - y);
Inc(Len);
Result[Len] := Point(Center.x + y, Center.y + x);
Inc(Len);
Result[Len] := Point(Center.x + y, Center.y - x);
Inc(Len);
Result[Len] := Point(Center.x - y, Center.y + x);
Inc(Len);
Result[Len] := Point(Center.x - y, Center.y - x);
Inc(Len);
end;
SetLength(Result, Len);
end;

function filtercircle(Center: TPoint; Radius: Integer): TPointArray;
begin
Result := TPAFromBox(IntToBox(Center.X - Radius, Center.Y - Radius, Center.X + Radius, Center.Y + Radius));
FilterPointsPie(Result, 0, 360, -1, Radius, Center.X, Center.Y);
FilterPointsDist(Result, Radius-1, Radius+1, Center.X, Center.Y);
end;

var
circle: TPointArray;
p: TPoint;
i, t, time, time2, time3, r: Integer;

begin
Smart_Server := 4;
SetupSRL;
p := Point(100, 100);
r := 50
i := 0;
writeln(gettpabounds(CircleToTPA(P, r)));
writeln(gettpabounds(CircleToTPA2(P, r)));
writeln(gettpabounds(filtercircle(P, r)));

writeln('starting bresenham');
MarkTime(t);
while (i < 15000)do
begin
circle := CircleToTPA(P, r);
inc(i);
end;
time := TimeFromMark(T);

i := 0;
writeln('starting filter');
marktime(t)
while (i < 15000)do
begin
circle := filtercircle(P, r);
inc(i);
end;
time2 := TimeFromMark(T);

i := 0;
writeln('starting roundedrect');
MarkTime(t);
while (i < 15000)do
begin
circle := CircleToTPA2(P, r);
inc(i);
end;
time3 := TimeFromMark(T);

writeln(format('bresenham: %f filter: %f roundedrect: %f', [time/15000.0, time2/15000.0, time3/15000.0]));

end.


I may stand corrected! I feel like the difference might be in the precompiled code, but I am also okay with pushing this as it is. :)

Knowing if those functions are faster in a plugin would be nice, too though.. :)

mormonman

2011-11-23 19:36:22

Ya I figured that it would be faster in plugin. Arrays seems tons slower with PS, and this relies heavily on them…I'll finish it later tonight.

euphemism

2011-11-28 17:10:34

Any update on this? These are very useful.

mormonman

2011-12-05 22:21:21

Ok, so I added TPAFromCircle to tpa.pas and tested with that…

Compiled successfully in 16 ms.
(50, 50, 150, 150)
(51, 51, 149, 149)
starting bresenham
starting filter
bresenham: 0.15 filter: 1.30
Successfully executed.

I am now sending pull request to simba.

Edit: I accidentally used the rounded rect algorithm on the last build. My current function is this:
Compiled successfully in 15 ms.
(50, 50, 150, 150)
(51, 51, 149, 149)
starting new
starting filter
new: 0.01 filter: 1.30
Successfully executed.

Nava2

2011-12-06 01:36:22

Nice, can you submit a pull request on GitHub? :)

mormonman

2011-12-06 03:14:00

I completely changed my method, but it's still way faster than filter. I can't seem to get it to pull my changes tho, so I'll post them here. Then you can optimize if possible before you commit. I'm throwing SortATPAFromMidPoint in there because you main simba devs never read suggestion threads.


{/\
Sorts the T2DPointArray a from the midpoint of each TPA by From.
/\}

procedure SortATPAFromMidPoint(var a: T2DPointArray; const From: TPoint);
var
i, l: Integer;
DistArr: TIntegerArray;
MidPt: TPoint;
begin
l := High(a);
if (l < 0) then Exit;
SetLength(DistArr, l + 1);
for i := 0 to l do
begin
MidPt := MiddleTPA(a[i]);
DistArr[i] := Round(Sqr(From.x - MidPt.x) + Sqr(From.y - MidPt.y));
end;
QuickATPASort(DistArr, a, 0, l, True);
end;
{/\
Returns a TPointArray of the outline of a ellipse.
/\}
function TPAFromEllipse(const CX, CY, XRadius, YRadius : Integer): TPointArray;
var
x, y, a2, b2, h,
d1, d2, sn, sd,
a2t8, b2t8, Len : Integer;
begin
SetLength(Result, 9999);
Len := 0;
Result[Len] := Point(CX + XRadius, CY);
Inc(Len);
Result[Len] := Point(CX, CY - YRadius);
Inc(Len);
Result[Len] := Point(CX - XRadius, CY);
Inc(Len);
Result[Len] := Point(CX, CY + YRadius);
Inc(Len);
x := 0;
y := YRadius;
a2 := XRadius * XRadius;
b2 := y * y;
a2t8 := a2 * 8;
b2t8 := b2 * 8;
h := b2 * 4 + a2 * (1 - 4 * y);
d1 := 12 * b2;
d2 := -a2t8 * (y - 1);
sn := b2;
sd := (a2 * y) - (a2 shr 1);

while (sn < sd) do
begin
if (h > 0) then
begin
Dec(y);
h := h + d2;
sd := sd - a2;
d2 := d2 + a2t8;
end;
Inc(x);
h := h + d1;
sn := sn + b2;
d1 := d1 + b2t8;
Result[Len] := Point(CX + X, CY + Y);
Inc(Len);
Result[Len] := Point(CX + X, CY - Y);
Inc(Len);
Result[Len] := Point(CX - X, CY + Y);
Inc(Len);
Result[Len] := Point(CX - X, CY - Y);
Inc(Len);
end;

h := b2 * (4 * x * x + 4 * x + 1) + 4 * a2 * (y - 1) * (y - 1) - 4 * a2 * b2;
d1 := b2t8 * (x + 1);
d2 := -4 * a2 * (2 * y - 3);
while (y > 1) do
begin
if (h < 0) then
begin
Inc(x);
h := h + d1;
d1 := d1 + b2t8;
end;
Dec(y);
h := h + d2;
d2 := d2 + a2t8;
Result[Len] := Point(CX + X, CY + Y);
Inc(Len);
Result[Len] := Point(CX + X, CY - Y);
Inc(Len);
Result[Len] := Point(CX - X, CY + Y);
Inc(Len);
Result[Len] := Point(CX - X, CY - Y);
Inc(Len);
end;

SetLength(Result, Len);
end;

{/\
Returns a TPointArray of the outline of a ellipse.
/\}
function TPAFromCircle(const CX, CY, Radius: Integer): TPointArray;
begin
Result := TPAFromEllipse(CX, CY, Radius, Radius);
end;

Gu3st...

2011-12-10 18:12:21

Future notice: To make it easier for devs: Use git or bugs.villavu.com :)

Coh3n

2011-12-10 19:25:55

From: Zyt3x
Future notice: To make it easier for devs: Use git or bugs.villavu.com :)
Does anyone even check the mantis bug reports? I don't think anyone uses it, and I prefer the forums anyway.

Gu3st...

2011-12-10 19:31:51

From: Coh3n
Does anyone even check the mantis bug reports? I don't think anyone uses it, and I prefer the forums anyway.
Whaat?! This is exactly what mantis is for!

Much better to use mantis than the forums imo. 1000 times more organized :p

Coh3n

2011-12-10 19:32:57

From: Zyt3x
Whaat?! This is exactly what mantis is for!

Much better to use mantis than the forums imo. 1000 times more organized :p
I've never checked it, and I restructured the forums for a reason - so it is more organized. I think it make more sense to have it on the forums so people don't have to make another account, and everyone can see the bugs without going to another site.

Gu3st...

2011-12-10 19:35:23

From: Coh3n
I've never checked it, and I restructured the forums for a reason - so it is more organized. I think it make more sense to have it on the forums so people don't have to make another account, and everyone can see the bugs without going to another site.
I disagree :o

The reason someone made mantis was for this kind of stuff, but really; we shouldn't high-jack this thread anymore… Let's agree to disagree ;)

Wizzup?

2011-12-11 05:26:12

From: mormonman
I completely changed my method, but it's still way faster than filter. I can't seem to get it to pull my changes tho, so I'll post them here. Then you can optimize if possible before you commit. I'm throwing SortATPAFromMidPoint in there because you main simba devs never read suggestion threads.


Well, in our defense there's a lot to read out here. There's a reason we have github, pull requests, github issues, a villavu bug tracker, etc. ;)

From: mormonman


{/\
Sorts the T2DPointArray a from the midpoint of each TPA by From.
/\}

procedure SortATPAFromMidPoint(var a: T2DPointArray; const From: TPoint);
var
i, l: Integer;
DistArr: TIntegerArray;
MidPt: TPoint;
begin
l := High(a);
if (l < 0) then Exit;
SetLength(DistArr, l + 1);
for i := 0 to l do
begin
MidPt := MiddleTPA(a[i]);
DistArr[i] := Round(Sqr(From.x - MidPt.x) + Sqr(From.y - MidPt.y));
end;
QuickATPASort(DistArr, a, 0, l, True);
end;
{/\
Returns a TPointArray of the outline of a ellipse.
/\}
function TPAFromEllipse(const CX, CY, XRadius, YRadius : Integer): TPointArray;
var
x, y, a2, b2, h,
d1, d2, sn, sd,
a2t8, b2t8, Len : Integer;
begin
SetLength(Result, 9999);
Len := 0;
Result[Len] := Point(CX + XRadius, CY);
Inc(Len);
Result[Len] := Point(CX, CY - YRadius);
Inc(Len);
Result[Len] := Point(CX - XRadius, CY);
Inc(Len);
Result[Len] := Point(CX, CY + YRadius);
Inc(Len);
x := 0;
y := YRadius;
a2 := XRadius * XRadius;
b2 := y * y;
a2t8 := a2 * 8;
b2t8 := b2 * 8;
h := b2 * 4 + a2 * (1 - 4 * y);
d1 := 12 * b2;
d2 := -a2t8 * (y - 1);
sn := b2;
sd := (a2 * y) - (a2 shr 1);

while (sn < sd) do
begin
if (h > 0) then
begin
Dec(y);
h := h + d2;
sd := sd - a2;
d2 := d2 + a2t8;
end;
Inc(x);
h := h + d1;
sn := sn + b2;
d1 := d1 + b2t8;
Result[Len] := Point(CX + X, CY + Y);
Inc(Len);
Result[Len] := Point(CX + X, CY - Y);
Inc(Len);
Result[Len] := Point(CX - X, CY + Y);
Inc(Len);
Result[Len] := Point(CX - X, CY - Y);
Inc(Len);
end;

h := b2 * (4 * x * x + 4 * x + 1) + 4 * a2 * (y - 1) * (y - 1) - 4 * a2 * b2;
d1 := b2t8 * (x + 1);
d2 := -4 * a2 * (2 * y - 3);
while (y > 1) do
begin
if (h < 0) then
begin
Inc(x);
h := h + d1;
d1 := d1 + b2t8;
end;
Dec(y);
h := h + d2;
d2 := d2 + a2t8;
Result[Len] := Point(CX + X, CY + Y);
Inc(Len);
Result[Len] := Point(CX + X, CY - Y);
Inc(Len);
Result[Len] := Point(CX - X, CY + Y);
Inc(Len);
Result[Len] := Point(CX - X, CY - Y);
Inc(Len);
end;

SetLength(Result, Len);
end;

{/\
Returns a TPointArray of the outline of a ellipse.
/\}
function TPAFromCircle(const CX, CY, Radius: Integer): TPointArray;
begin
Result := TPAFromEllipse(CX, CY, Radius, Radius);
end;


Looks good, I'll merge it in a bit.

mormonman

2011-12-18 08:12:16

When this is released, please commit this to srl:
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- ********* Smart Painting routines --//
//-----------------------------------------------------------------//
// Procedure SMART_ClearCanvas;
// Procedure SMART_DrawDotsMulti(Clear: boolean; pixels : T2DPointArray);
// Procedure SMART_DrawDotsEx(Clear: boolean; pixels: TPointArray; color: TColor);
// Procedure SMART_DrawDots(Dots: TPointArray);
// Procedure SMART_DrawBoxesEx(Clear: Boolean; TBA: TBoxArray; Color: Integer);
// Procedure SMART_DrawBoxes(TBA: TBoxArray);
// Procedure SMART_DrawBoxEx(Clear: boolean; Box: TBox; color: TColor);
// Procedure SMART_DrawBox(Box: TBox);
// Procedure SMART_DrawBoxMS(Clear: Boolean; Box: TBox; Color: TColor);
// Procedure SMART_DrawLine(Clear: Boolean; TP1, TP2: TPoint; Color: TColor);
// Procedure SMART_DrawCircleEx(Clear: Boolean; Center: TPoint; Radius: Integer; Fill: Boolean; Color: TColor);
// Procedure SMART_DrawCircle(Center: TPoint; Radius: Integer);
// Procedure SMART_DrawDotEx(Clear: Boolean; Point: TPoint; Big: Boolean; color: TColor);
// Procedure SMART_DrawDot(Point: TPoint);
// Procedure SMART_DrawPolygonsEx(Clear: Boolean; Polygons: T2DPointArray; color: TColor);
// Procedure SMART_DrawPolygons(Polygons: T2DPointArray);
// Procedure SMART_DrawPolygonEx(Clear: Boolean; Vertices: TPointArray; color: TColor);
// Procedure SMART_DrawPolygon(Vertices: TPointArray);
// Procedure SMART_DrawTextEx(Clear: Boolean; x, y: Integer; font, Text: string; Color:TColor);
// Procedure SMART_DrawText(x, y: Integer; font, Text: string; Color:TColor);
//-----------------------------------------------------------------//

var
SMART_Canvas: TBitmap;
SMART_DebugSetup: Boolean;

{*******************************************************************************
procedure SMART_SetupDebug();
Contributors: Unknown
Description: Creates the SMART canvas
*******************************************************************************}
procedure SMART_SetupDebug();
begin
SmartSetDebug(True);
SMART_Canvas := TBitmap.Create;
SMART_Canvas.canvas.handle := SmartGetDebugDC;
SMART_DebugSetup := true;
end;

{*******************************************************************************
Procedure ClearCanvas(canvas: TCanvas; w, h: integer);
Contributors: Sir R. Magician, mastaraymond
Description: Clears a canvas of dimensions (w, h)
*******************************************************************************}
Procedure ClearCanvas(canvas: TCanvas; w, h: integer);
var
CleanBMP: integer;
begin

CleanBMP := BitmapFromString(w, h, '');

{$ifdef Simba}
DrawBitmap(CleanBMP,Canvas,0,0);
{$else}
SafeDrawBitmap(CleanBMP, canvas, 0, 0);
{$endif}

try
FreeBitmap(CleanBMP);
except
writeln('SMART BITMAP NOT FREED');
end;

end;

{*******************************************************************************
Procedure ClearRSCanvas(canvas: TCanvas);
Contributors: Sir R. Magician
Description: Clears a canvas of RS dimensions
*******************************************************************************}
Procedure ClearRSCanvas(canvas: TCanvas);
begin
if (not SMART_DebugSetup) then
SMART_SetupDebug();

ClearCanvas(canvas, MIX2 + 100, MIY2 + 100);
end;

{*******************************************************************************
procedure SMART_ClearCanvas;
Contributors: mormonman
Description: Clears smart's canvas
*******************************************************************************}
procedure SMART_ClearCanvas;
begin
{$IFDEF SMART}
if (not SMART_DebugSetup) then
SMART_SetupDebug();
ClearRSCanvas(SMART_Canvas.canvas);
{$ENDIF}
end;

{*******************************************************************************
procedure SMART_DrawDotsMulti(Clear: boolean; pixels : T2DPointArray);
Contributors: Sir R. Magician
Description: Draws an ATPA onto the SMART Debug canvas
*******************************************************************************}
procedure SMART_DrawDotsMulti(Clear: boolean; pixels : T2DPointArray);
{$IFDEF SMART}
var
i, h, color : integer;
begin
if (not SMART_DebugSetup) then
SMART_SetupDebug();

if Clear then SMART_ClearCanvas;

for h := 0 to High(pixels) do
begin

color := h div 5 + h mod 5;
case color of
0 : SMART_Canvas.canvas.Pen.Color := clWhite;
1 : SMART_Canvas.canvas.Pen.Color := clYellow;
2 : SMART_Canvas.canvas.Pen.Color := clBlue;
3 : SMART_Canvas.canvas.Pen.Color := clLime;
4 : SMART_Canvas.canvas.Pen.Color := clGreen;
end;

for i:= 0 to High(pixels[h]) do
begin
SMART_Canvas.canvas.moveto(pixels[h][i].x-1, pixels[h][i].y);
SMART_Canvas.canvas.LineTo(pixels[h][i].x, pixels[h][i].y);
end;
end;

{$ELSE}
begin
{$ENDIF}
end;

{*******************************************************************************
Procedure SMART_DrawDotsEx(Clear: boolean; pixels: TPointArray; color: TColor);
Contributors: Sir R. Magician, caused, mastaraymond
Description: Draws a TPA onto the SMART Debug canvas
*******************************************************************************}
procedure SMART_DrawDotsEx(Clear: boolean; pixels: TPointArray; color: TColor);
{$IFDEF SMART}
var
i : integer;
begin
if (not SMART_DebugSetup) then
SMART_SetupDebug();

SMART_Canvas.canvas.Pen.Color := color;
if Clear then SMART_ClearCanvas;

for i:= 0 to high(pixels) do
begin
SMART_Canvas.canvas.moveto(pixels[i].x-1,pixels[i].y);
SMART_Canvas.canvas.LineTo(pixels[i].x,pixels[i].y);
end;

{$ELSE}
begin
{$ENDIF}

end;

{*******************************************************************************
Procedure SMART_DrawDots(Dots: TPointArray);
Contributors: Sir R. Magician
Description: Draws a TPA onto the SMART Debug canvas
*******************************************************************************}
procedure SMART_DrawDots(Dots: TPointArray);
begin
SMART_DrawDotsEx(True, Dots, clRed);
end;

{*******************************************************************************
procedure SMART_DrawBoxesEx(Clear: Boolean; TBA: TBoxArray; Color: Integer);
Contributors: mormonman
Description: Draws an array of boxes onto the SMART Debug canvas. Enter -1
for it to use different colors(like in SMART_DrawDotsMulti).
*******************************************************************************}
procedure SMART_DrawBoxesEx(Clear: Boolean; TBA: TBoxArray; Color: Integer);
{$IFDEF SMART}
var
i, colour: Integer;
begin
if (not SMART_DebugSetup) then
SMART_SetupDebug();

if Clear then SMART_ClearCanvas;

if (Length(TBA) < 1) then Exit;
for i := 0 to High(TBA) do
begin
if (Color > 0) then
begin
SMART_Canvas.canvas.Pen.Color := color;
end else
begin
colour := i div 5 + i mod 5;
case colour of
0 : SMART_Canvas.canvas.Pen.Color := clWhite;
1 : SMART_Canvas.canvas.Pen.Color := clYellow;
2 : SMART_Canvas.canvas.Pen.Color := clBlue;
3 : SMART_Canvas.canvas.Pen.Color := clLime;
4 : SMART_Canvas.canvas.Pen.Color := clGreen;
end;
end;

SMART_Canvas.canvas.moveto(TBA[i].x1,TBA[i].y1);
SMART_Canvas.canvas.LineTo(TBA[i].x2,TBA[i].y1);
SMART_Canvas.canvas.LineTo(TBA[i].x2,TBA[i].y2);
SMART_Canvas.canvas.LineTo(TBA[i].x1,TBA[i].y2);
SMART_Canvas.canvas.LineTo(TBA[i].x1,TBA[i].y1);
end;

{$ELSE}
begin
{$ENDIF}

end;

{*******************************************************************************
procedure SMART_DrawBoxes(TBA: TBoxArray);
Contributors: mormonman
Description: Draws an array of boxes onto the SMART Debug canvas.
*******************************************************************************}
procedure SMART_DrawBoxes(TBA: TBoxArray);
begin
SMART_DrawBoxesEx(True, TBA, clRed);
end;

{*******************************************************************************
procedure SMART_DrawBoxEx(Clear: boolean; Box: TBox; color: TColor);
Contributors: Sir R. Magician, caused, mastaraymond
Description: Draws a TBox onto the SMART Debug canvas
*******************************************************************************}
procedure SMART_DrawBoxEx(Clear: boolean; Box: TBox; color: TColor);
begin
SMART_DrawBoxesEx(Clear, [Box], color);
end;

{*******************************************************************************
Procedure SMART_DrawBox(Box: TBox);
Contributors: Sir R. Magician
Description: Draws a TBox onto the SMART Debug canvas
*******************************************************************************}
procedure SMART_DrawBox(Box: TBox);
begin
SMART_DrawBoxEx(True, Box, clRed);
end;

{*******************************************************************************
procedure SMART_DrawBoxMS(Clear: Boolean; Box: TBox; Color: TColor);
Contributors: Unknown
Description: Draws a TBox onto the SMART Debug canvas
*******************************************************************************}
procedure SMART_DrawBoxMS(Clear: Boolean; Box: TBox; Color: TColor);
begin
if (Box.X1 < MSX1) then Box.X1 := MSX1;
if (Box.Y1 < MSY1) then Box.Y1 := MSY1;
if (Box.X2 > MSX2) then Box.X2 := MSX2;
if (Box.Y2 > MSY2) then Box.Y2 := MSY2;
SMART_DrawBoxEx(Clear, Box, Color);
end;

{*******************************************************************************
procedure SMART_DrawLine(Clear: Boolean; TP1, TP2: TPoint; Color: TColor);
by: mormonman
Description: Draws a line on your screen.
*******************************************************************************}
procedure SMART_DrawLine(Clear: Boolean; TP1, TP2: TPoint; Color: TColor);
begin
{$IFDEF SMART}
if (not SMART_DebugSetup) then
SMART_SetupDebug();

SMART_Canvas.canvas.Pen.Color := Color;

if Clear then SMART_ClearCanvas;

SMART_Canvas.canvas.moveto(TP1.x,TP1.y);
SMART_Canvas.canvas.LineTo(TP2.x,TP2.y);
{$ENDIF}
end;

{*******************************************************************************
procedure SMART_DrawEllipseEx(Clear: Boolean; Center: TPoint; XRadius, YRadius: Integer; Color: TColor);
by: mormonman
Description: Draws a Ellipse on the Smart canvas defined by center, xradius, and
yradius.
*******************************************************************************}
procedure SMART_DrawEllipseEx(Clear, Fill: Boolean; Center: TPoint; XRadius, YRadius: Integer; Color: TColor);
{$IFDEF SMART}
var
TPA: TPointArray;
begin
TPA := TPAFromEllipse(Center.x, Center.y, XRadius, YRadius);
if (Length(TPA) < 1) then Exit;
if Fill then FillEllipse(TPA);
SMART_DrawDotsEx(Clear, TPA, Color);
{$ELSE}
begin
{$ENDIF}
end;

{*******************************************************************************
procedure SMART_DrawEllipse(Center: TPoint; XRadius, YRadius: Integer);
by: mormonman
Description: Draws a Ellipse on the Smart canvas defined by center, xradius, and
yradius.
*******************************************************************************}
procedure SMART_DrawEllipse(Center: TPoint; XRadius, YRadius: Integer);
begin
SMART_DrawEllipseEx(True, False, Center, XRadius, YRadius, clRed);
end;

{*******************************************************************************
procedure SMART_DrawCircleEx(Clear: Boolean; Center: TPoint; Radius: Integer; Color: TColor);
by: mormonman
Description: Draws a circle on the Smart canvas defined by center and radius.
*******************************************************************************}
procedure SMART_DrawCircleEx(Clear, Fill: Boolean; Center: TPoint; Radius: Integer; Color: TColor);
begin
SMART_DrawEllipseEx(Clear, Fill, Center, Radius, Radius, Color);
end;

{*******************************************************************************
procedure SMART_DrawCircle(Center: TPoint; Radius: Integer);
by: mormonman
Description: Draws a circle on the Smart canvas defined by center and radius.
*******************************************************************************}
procedure SMART_DrawCircle(Center: TPoint; Radius: Integer);
begin
SMART_DrawCircleEx(True, False, Center, Radius, clRed);
end;

{*******************************************************************************
procedure SMART_DrawDotEx(Clear: Boolean; Point: TPoint; Big: Boolean; color: TColor);
by: mormonman
Description: Draws a dot at the Point onto the Smart canvas. If Big is true then
the radius is 8 else the radius is 4.
*******************************************************************************}
procedure SMART_DrawDotEx(Clear: Boolean; Point: TPoint; Big: Boolean; color: TColor);
begin
if Big then
SMART_DrawCircleEx(Clear, True, Point, 11, Color)
else
SMART_DrawCircleEx(Clear, True, Point, 4, Color);
end;

{*******************************************************************************
procedure SMART_DrawDot(Point: TPoint);
by: mormonman
Description: Draws a dot with a radius of 4 at the Point onto the Smart canvas
*******************************************************************************}
procedure SMART_DrawDot(Point: TPoint);
begin
SMART_DrawDotEx(True, Point, False, clRed);
end;

{*******************************************************************************
procedure SMART_DrawPolygonsEx(Clear: Boolean; Polygons: T2DPointArray; color: TColor);
by: mormonman
Description: Draws an array of polygons onto the SMART canvas
*******************************************************************************}
procedure SMART_DrawPolygonsEx(Clear: Boolean; Polygons: T2DPointArray; color: TColor);
{$IFDEF SMART}
var
i, h, Hi: Integer;
begin
if Clear then SMART_ClearCanvas;
if (Length(Polygons) < 1) then Exit;
for h := 0 to High(Polygons) do
begin
Hi := High(Polygons[h]);
if (Hi < 2) then Exit;
for i := 0 to Hi - 1 do
SMART_DrawLine(False, Polygons[h][i], Polygons[h][i+1], color);
SMART_DrawLine(False, Polygons[h][Hi], Polygons[h][0], color);
end;
{$ELSE}
begin
{$ENDIF}
end;

{*******************************************************************************
procedure SMART_DrawPolygons(Polygons: T2DPointArray);
by: mormonman
Description: Draws an array of polygons onto the SMART canvas
*******************************************************************************}
procedure SMART_DrawPolygons(Polygons: T2DPointArray);
begin
SMART_DrawPolygonsEx(True, Polygons, clRed);
end;

{*******************************************************************************
procedure SMART_DrawPolygonEx(Clear: Boolean; Vertices: TPointArray; color: TColor);
by: mormonman
Description: Draws a polygon defined by Vertices onto the SMART canvas
*******************************************************************************}
procedure SMART_DrawPolygonEx(Clear: Boolean; Vertices: TPointArray; color: TColor);
begin
SMART_DrawPolygonsEx(Clear, [Vertices], color);
end;

{*******************************************************************************
procedure SMART_DrawPolygon(Vertices: TPointArray);
by: mormonman
Description: Draws a polygon defined by Vertices onto the SMART canvas
*******************************************************************************}
procedure SMART_DrawPolygon(Vertices: TPointArray);
begin
SMART_DrawPolygonEx(True, Vertices, clRed);
end;

{*******************************************************************************
procedure SMART_DrawTextEx(Clear: Boolean; x, y: Integer; font, Text: string; Color: TColor);
Contributors: Jukka, Shuttleu
Description: Draws text onto the SMART Debug canvas at position x, y
*******************************************************************************}
procedure SMART_DrawTextEx(Clear: Boolean; x, y: Integer; font, Text: string; Color:TColor);
var
i, height: integer;
tpa: tpointarray;
begin
tpa := LoadTextTPA(text,font,height);
for i:= 0 to high(tpa) do
begin
tpa[i].x := tpa[i].x + x;
tpa[i].y := tpa[i].y + y;
end;
SMART_DrawDotsEx(Clear, tpa, Color);
end;

{*******************************************************************************
procedure SMART_DrawText(x, y: Integer; font, Text: string; Color: TColor);
Contributors: Shuttleu
Description: Draws text onto the SMART Debug canvas at position x, y
*******************************************************************************}
procedure SMART_DrawText(x, y: Integer; font, Text: string; Color:TColor);
begin
SMART_DrawTextEx(False, x, y, font, Text, Color);
end;

{*******************************************************************************
procedure SMART_FreeDebug();
Contributors: Unknown
Description: Frees the smart canvas
*******************************************************************************}
procedure SMART_FreeDebug();
begin
try
if (SMART_DebugSetup) then
SMART_Canvas.Free;
except
Writeln('Failed to free SMART_Canvas bitmap: '+ExceptionToString(ExceptionType, ExceptionParam));
end;
end;

Sir R. M8gic1an

2011-12-18 08:33:27

I actually wonder why we'd want polygons on the smart canvas…

like other than its cool to code, if you know what I mean..

-RM

mormonman

2011-12-18 08:41:18

From: Sir R. M8gic1an
I actually wonder why we'd want polygons on the smart canvas…

like other than its cool to code, if you know what I mean..

-RM


You could do FindTPAEdges on each tpa in an atpa and then draw each of those polygons, instead of using a box. It would be a more accurate portrayal of where the points are, but still less resource consuming than drawing each point in the atpa. That's just one idea ;)

Sir R. M8gic1an

2011-12-18 08:43:47

sounds fair enough, pardon my skepticism ;)

-RM

Wizzup?

2012-01-01 18:46:56

Mormonman, if I release Simba 981 we can merge this, right?

Coh3n

2012-01-10 21:49:26

Added these to paintsmart.simba.

http://villavu.com/forum/showthread.php?t=71762

mormonman

2012-01-20 20:17:39

So I added/changed some stuff, and I didn't want to make a new thread. Drawing points is now faster ;) (but not by much…anything helps right?)

(*
Paint Smart
===========

The Paint Smart include contains functions that will paint graphics on to the
SMART screen. Used to make scripts look nicer and sometimes to display
progress reports. Also used as a useful debugging tool.

*)

var
SMART_Canvas: TBitmap;
SMART_DebugSetup: Boolean;

(*
SMART_SetupDebug
~~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_SetupDebug();

Declares the SMART_Canvas bitmap. Does not need to be called in scripts as it's
called in the SMART_ functions automatically.

.. note::

Author: Coh3n
Last Modified: Unknown

Example:

.. code-block:: pascal

if (not SMART_DebugSetup) then
SMART_SetupDebug();
*)
procedure SMART_SetupDebug();
begin
SmartSetDebug(True);
SMART_Canvas := TBitmap.Create;
SMART_Canvas.canvas.handle := SmartGetDebugDC;
SMART_DebugSetup := true;
end;

(*
SMART_ClearCanvasArea
~~~~~~~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_ClearCanvasArea(Area: TBox);

Clears a specific area of the SMART canvas defined by the box, 'Area'.

.. note::

Author: Coh3n
Last Modified: January 10th, 2012 by Coh3n

Example:

.. code-block:: pascal

SMART_ClearCanvasArea(IntToBox(10, 10, 50, 50));
*)
procedure SMART_ClearCanvasArea(Area: TBox);
{$IFDEF SMART}
var
CleanBMP: integer;
begin
if (not SMART_DebugSetup) then
SMART_SetupDebug();

CleanBMP := BitmapFromString(Area.X2-Area.X1, Area.Y2-Area.Y1, '');
DrawBitmap(CleanBMP, SMART_Canvas.Canvas, Area.X1, Area.Y1);

try
FreeBitmap(CleanBMP);
except
Writeln('SMART_ClearCanvasArea: Couldn''t free CleanBMP');
end;
{$ELSE}
begin
{$ENDIF}
end;

(*
SMART_ClearCanvas
~~~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_ClearCanvas;

Clears the entire SMART canvas.

.. note::

Author: Coh3n
Last Modified: January 10th, 2012 by Coh3n

Example:

.. code-block:: pascal

SMART_ClearCanvasArea();
*)
procedure SMART_ClearCanvas;
var
w, h: integer;
begin
GetClientDimensions(w, h);
SMART_ClearCanvasArea(IntToBox(0, 0, w, h));
end;

(*
SMART_ClearMS
~~~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_ClearMS;

Clears the mainscreen section of the SMART canvas.

.. note::

Author: mormonman
Last Modified: January 20th, 2012

Example:

.. code-block:: pascal

SMART_ClearMS;
*)
procedure SMART_ClearMS;
begin
SMART_ClearCanvasArea(MSBox);
end;

(*
SMART_DrawDotsEx
~~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DrawDotsEx(Clear: boolean; pixels: TPointArray; color: TColor);

Draws a colored (color) TPA onto the SMART canvas. Will clear the canvas if
'Clear' is set to true.

.. note::

Author: Sir R. Magician
Last Modified: Unknown

Example:

.. code-block:: pascal

SMART_DrawDotsEx(true, TPA, clRed);
*)
procedure SMART_DrawDotsEx(Clear: boolean; pixels: TPointArray; color: TColor);
{$IFDEF SMART}
var
i : integer;
begin
if (not SMART_DebugSetup) then
SMART_SetupDebug();

if Clear then SMART_ClearCanvas;

for i:= 0 to high(pixels) do
SMART_Canvas.Canvas.Pixels[pixels[i].x, pixels[i].y] := color;

{$ELSE}
begin
{$ENDIF}
end;

(*
SMART_DrawDotsMulti
~~~~~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DrawDotsMulti(Clear: boolean; pixels : T2DPointArray);

Draws an ATPA onto the SMART canvas. Will clear the canvas if 'Clear' is set
to true.

.. note::

Author: Sir R. Magician
Last Modified: January 20th, 2012 by mormonman

Example:

.. code-block:: pascal

SMART_DrawDotsMulti(true, ATPA);
*)
procedure SMART_DrawDotsMulti(Clear: boolean; pixels : T2DPointArray);
{$IFDEF SMART}
var
i, h, color : integer;
begin
if (not SMART_DebugSetup) then
SMART_SetupDebug();

if Clear then SMART_ClearCanvas;

for h := 0 to High(pixels) do
begin

color := h div 10 + h mod 10;
case color of
0 : color := clWhite;
1 : color := clYellow;
2 : color := clBlue;
3 : color := clLime;
4 : color := 26367;//orange
5 : color := clPurple;
6 : color := clAqua;
7 : color := clFuchsia;
8 : color := clGreen;
9 : color := clRed;
end;

SMART_DrawDotsEx(False, pixels[i], color);
end;
{$ELSE}
begin
{$ENDIF}
end;

(*
SMART_DebugATPA
~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DebugATPA(Clear: Boolean; ATPA: T2DPointArray);

Draws the box of each TPA in the ATPA and write the index number in the top
left corner and a cross at the point found by MiddleTPA.

.. note::

Author: mormonman
Last Modified: January 20, 2012

Example:

.. code-block:: pascal

SMART_DebugATPA(True, ATPA);
*)
procedure SMART_DebugATPA(Clear: Boolean; ATPA: T2DPointArray);
{$IFDEF SMART}
var
i, h, len: Integer;
B: TBox;
MP: TPoint;
TPA: TPointArray;
begin
len := Length(ATPA);
if (Len < 1) then
Exit;

for i := 0 to High(ATPA) do
begin
B := GetTPABounds(ATPA[i]);
if len > 1 then
begin
TPA := LoadTextTPA(ToStr(i), SmallChars, h);
OffsetTPA(TPA, Point(B.X1+1, B.Y1+1));
end;
ATPA[i] := CombineTPA(FindTPAEdges(TPAFromBox(B)), TPA);
MP := MiddleTPA(ATPA[i]);
TPA := [Point(MP.x-1, MP.y), Point(MP.x+1, MP.y), Point(MP.x, MP.y-1),
Point(MP.x, MP.y+1), Point(MP.x-2, MP.y), Point(MP.x, MP.y),
Point(MP.x+2, MP.y), Point(MP.x, MP.y-2), Point(MP.x, MP.y+2)];
ATPA[i] := CombineTPA(ATPA[i], TPA);
end;

SMART_DrawDotsMulti(Clear, ATPA);
{$ELSE}
begin
{$ENDIF}
end;

(*
SMART_DebugTPA
~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DebugTPA(Clear: Boolean; TPA: TPointArray);

Draws the TPA bounds and puts a cross at the point created by MiddleTPA.

.. note::

Author: mormonman
Last Modified: January 12, 2012

Example:

.. code-block:: pascal

SMART_DebugTPA(True, TPA);
*)
procedure SMART_DebugTPA(Clear: Boolean; TPA: TPointArray);
begin
SMART_DebugATPA(Clear, [TPA]);
end;

(*
SMART_DrawDots
~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DrawDots(Dots: TPointArray);

Clears the SMART canvas, then draws a red TPA (Dots).

.. note::

Author: Sir R. Magician
Last Modified: Unknown

Example:

.. code-block:: pascal

SMART_DrawDots(TPA);
*)
procedure SMART_DrawDots(Dots: TPointArray);
begin
SMART_DrawDotsEx(True, Dots, clRed);
end;

(*
SMART_DrawDot
~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DrawDot(Clear: Boolean; Point: TPoint; Color: TColor);

Draws a single colored dot (Color) at the set point (Point) on the SMART canvas.
Will clear the SMART canvas if set to do so (Clear).

.. note::

Author: Coh3n
Last Modified: January 10th, 2012

Example:

.. code-block:: pascal

SMART_DrawDot(true, point(10, 10), clGreen);
*)
procedure SMART_DrawDot(Clear: Boolean; Point: TPoint; Color: TColor);
begin
SMART_DrawDotsEx(Clear, [Point], Color);
end;

(*
SMART_DrawBoxes
~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DrawBoxes(Clear: Boolean; TBA: TBoxArray; Color: Integer);

Draws an array of boxes onto the SMART canvas. Set Color to -1 for it to use
different colors (like in SMART_DrawDotsMulti).

.. note::

Author: mormonman
Last Modified: January 10th, 2012

Example:

.. code-block:: pascal

SMART_DrawBoxes(true, TBA, -1);
*)
procedure SMART_DrawBoxes(Clear: Boolean; TBA: TBoxArray; Color: Integer);
{$IFDEF SMART}
var
i, colour: Integer;
begin
if (not SMART_DebugSetup) then
SMART_SetupDebug();

if Clear then SMART_ClearCanvas;

if (Length(TBA) < 1) then Exit;
for i := 0 to High(TBA) do
begin
if (Color > 0) then
begin
SMART_Canvas.canvas.Pen.Color := color;
end else
begin
colour := i div 5 + i mod 5;
case colour of
0 : SMART_Canvas.canvas.Pen.Color := clWhite;
1 : SMART_Canvas.canvas.Pen.Color := clYellow;
2 : SMART_Canvas.canvas.Pen.Color := clBlue;
3 : SMART_Canvas.canvas.Pen.Color := clLime;
4 : SMART_Canvas.canvas.Pen.Color := clGreen;
end;
end;

SMART_Canvas.canvas.moveto(TBA[i].x1,TBA[i].y1);
SMART_Canvas.canvas.LineTo(TBA[i].x2,TBA[i].y1);
SMART_Canvas.canvas.LineTo(TBA[i].x2,TBA[i].y2);
SMART_Canvas.canvas.LineTo(TBA[i].x1,TBA[i].y2);
SMART_Canvas.canvas.LineTo(TBA[i].x1,TBA[i].y1);
end;

{$ELSE}
begin
{$ENDIF}
end;

(*
SMART_DrawBoxEx
~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DrawBoxEx(Clear: boolean; Box: TBox; color: TColor);

Draws a single colored (color) box (Box) on the SMART canvas. Will clear the
canvas if set to do so (Clear).

.. note::

Author: mormonman
Last Modified: January 10th, 2012

Example:

.. code-block:: pascal

SMART_DrawBoxEx(true, intToBox(50, 50, 100, 100), clGreen);
*)
procedure SMART_DrawBoxEx(Clear: boolean; Box: TBox; color: TColor);
begin
SMART_DrawBoxes(Clear, [Box], color);
end;

(*
SMART_DrawBox
~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DrawBox(Box: TBox);

Clears the SMART canvas, then draws a single red box, specified by 'Box'.

.. note::

Author: mormonman
Last Modified: January 10th, 2012

Example:

.. code-block:: pascal

SMART_DrawBox(intToBox(50, 50, 100, 100));
*)
procedure SMART_DrawBox(Box: TBox);
begin
SMART_DrawBoxEx(True, Box, clRed);
end;

(*
SMART_DrawBoxMS
~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DrawBoxMS(Clear: Boolean; Box: TBox; Color: TColor);

Draws a box on the RS mainscreen, even if the coordinates are outside client
boundaries.

.. note::

Author: Coh3n
Last Modified: Unknown

Example:

.. code-block:: pascal

SMART_DrawBoxMS(true, intToBox(50, 50, 100, 100), clBlue);
*)
procedure SMART_DrawBoxMS(Clear: Boolean; Box: TBox; Color: TColor);
begin
if (Box.X1 < MSX1) then Box.X1 := MSX1;
if (Box.Y1 < MSY1) then Box.Y1 := MSY1;
if (Box.X2 > MSX2) then Box.X2 := MSX2;
if (Box.Y2 > MSY2) then Box.Y2 := MSY2;
SMART_DrawBoxEx(Clear, Box, Color);
end;

(*
SMART_DrawLine
~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DrawLine(Clear: Boolean; TP1, TP2: TPoint; Color: TColor);

Draws a line a set color (Color) from point 1 (TP1) to point 2 (TP2). Will
clear the SMART canvas if set to do so (Clear).

.. note::

Author: mormonman
Last Modified: January 10th, 2012

Example:

.. code-block:: pascal

SMART_DrawLine(true, point(10, 10), point(10, 50), clWhite);
*)
procedure SMART_DrawLine(Clear: Boolean; TP1, TP2: TPoint; Color: TColor);
begin
{$IFDEF SMART}
if (not SMART_DebugSetup) then
SMART_SetupDebug();

SMART_Canvas.canvas.Pen.Color := Color;

if (Clear) then
SMART_ClearCanvas;

SMART_Canvas.canvas.moveto(TP1.x,TP1.y);
SMART_Canvas.canvas.LineTo(TP2.x,TP2.y);
{$ENDIF}
end;

(*
SMART_DrawEllipse
~~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DrawEllipse(Clear: Boolean; Center: TPoint; XRadius, YRadius: Integer; Fill: Boolean; Color: TColor);

Draws an ellipse on the SMART canvas defined by 'Center', 'XRadius', and
'YRadius'. If 'Fill' is true it will fill the ellipse, otherwise it draws just
the border. Will clear the SMART canvas if set to do so (Clear).

.. note::

Author: mormonman
Last Modified: January 20th, 2012

Example:

.. code-block:: pascal

SMART_DrawEllipse(true, point(300, 300), 35, 35, true, clYellow);
*)
procedure SMART_DrawEllipse(Clear: Boolean; Center: TPoint; XRadius, YRadius: Integer; Fill: Boolean; Color: TColor);
{$IFDEF SMART}
var
TPA: TPointArray;
begin
if Fill then
begin
SMART_Canvas.Canvas.Brush.COLOR := Color;
if Clear then
SMART_ClearCanvas;
SMART_Canvas.Canvas.Ellipse(Center.x - XRadius, Center.y - YRadius,
Center.x + XRadius, Center.y + YRadius);
end else
begin
TPA := TPAFromEllipse(Center.x, Center.y, XRadius, YRadius);

if (Length(TPA) >= 1) then
SMART_DrawDotsEx(Clear, TPA, Color);
end;
{$ELSE}
begin
{$ENDIF}
end;

(*
SMART_DrawCircle
~~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DrawCircle(Clear: Boolean; Center: TPoint; Radius: Integer; Fill: Boolean; Color: TColor);

Draws a circle on the SMART canvas defined by 'Center' and 'Radius'. If 'Fill'
is true it will fill the circle, otherwise it draws just the border. Will
clear the SMART canvas if set to do so (Clear).

.. note::

Author: mormonman
Last Modified: January 10th, 2012

Example:

.. code-block:: pascal

SMART_DrawCircle(true, point(300, 300), 35, true, clYellow);
*)
procedure SMART_DrawCircle(Clear: Boolean; Center: TPoint; Radius: Integer; Fill: Boolean; Color: TColor);
begin
SMART_DrawEllipse(Clear, Center, Radius, Radius, Fill, Color);
end;

(*
SMART_DrawPolygons
~~~~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DrawPolygons(Clear: Boolean; Polygons: T2DPointArray; color: TColor);

Draws an array of polygons on the SMART canvas in the set color. Will clear the
SMART canvas if set to do so (Clear).

.. note::

Author: mormonman
Last Modified: January 10th, 2012

Example:

.. code-block:: pascal

SMART_DrawPolygons(true, ATPA, clBlue);
*)
procedure SMART_DrawPolygons(Clear: Boolean; Polygons: T2DPointArray; color: TColor);
{$IFDEF SMART}
var
i, h, Hi: Integer;
begin
if (Clear) then
SMART_ClearCanvas;

if (Length(Polygons) < 1) then
Exit;

for h := 0 to High(Polygons) do
begin
Hi := High(Polygons[h]);
if (Hi < 2) then Exit;

for i := 0 to Hi - 1 do
SMART_DrawLine(False, Polygons[h][i], Polygons[h][i+1], color);

SMART_DrawLine(False, Polygons[h][Hi], Polygons[h][0], color);
end;
{$ELSE}
begin
{$ENDIF}
end;

(*
SMART_DrawTextMulti
~~~~~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DrawTextMulti(Clear, Shadow: Boolean; TSA: TStringArray; Placement: TPoint; Font: string; Colour: TColor);

Draws text on the SMART canvas. Used mainly for progress reports. Parameters
are as follows:
* Clear: Clear the SMART canvas before drawing
* Shadow: if set to true, will add a shadow to the text
* TSA: the string array of what to be printed; each element is a different line
* Placement: the point to start the text drawing
* Font: the font to use (see Simba/Fonts/)
* Colour: the color of the font

.. note::

Author: Flight & Coh3n
Last Modified: January 20th, 2012 by mormonman

Example:

.. code-block:: pascal

SMART_DrawTextMulti(true, true, ['Time Run: '+TimeRunning', 'Logs Chopped: 10'], Point(10, 10), LoginChars, clRed);
*)
procedure SMART_DrawTextMulti(Clear, Shadow: Boolean; TSA: TStringArray; Placement: TPoint; Font: string; Colour: TColor);
var
i, h, TPH: Integer;
TTP, SArr: TPointArray;
begin
if (not SMART_DebugSetup) then
SMART_SetupDebug();

if (Clear) then
SMART_ClearCanvas();

TPH := High(TSA);

for i := 0 to TPH do
begin
TTP := LoadTextTPA(TSA[i], Font, h);
OffsetTPA(TTP, Point(Placement.x, Placement.y));
SMART_DrawDotsEx(False, TTP, Colour);
if Shadow then
begin
SArr := CopyTPA(TTP);
OffsetTPA(SArr, Point(1, 1));
SArr := ClearTPAFromTPA(SArr, TTP);
SMART_DrawDotsEx(False, SArr, 65536);
end;
end;
end;

(*
SMART_DrawTextEx
~~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DrawTextEx(Clear: Boolean; x, y: Integer; font, Text: string; Color: TColor);

Draws shadowed line of text on the SMART canvas. Parameters are as follows:
* Clear: Clear the SMART canvas before drawing
* x, y: the coords of where to place the text
* font: the font to use (see Simba/Fonts/)
* Text: the text to draw to the SMART canvas
* Colour: the color of the font

.. note::

Author: Coh3n
Last Modified: January 10th, 2012 by Coh3n

Example:

.. code-block:: pascal

SMART_DrawTextEx(true, 10, 10, StatChars, 'Testing!', clBlue);
*)
procedure SMART_DrawTextEx(Clear: Boolean; x, y: Integer; font, Text: string; Color: TColor);
begin
SMART_DrawTextMulti(Clear, true, [Text], Point(x, y), font, Color);
end;

(*
SMART_DrawText
~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DrawText(x, y: Integer; font, Text: string; Color: TColor);

Same as SMART_DrawTextEx, except clears the canvas before drawing.

.. note::

Author: Coh3n
Last Modified: January 10th, 2012 by Coh3n

Example:

.. code-block:: pascal

SMART_DrawText(10, 10, StatChars, 'Testing!', clBlue);
*)
procedure SMART_DrawText(x, y: Integer; font, Text: string; Color: TColor);
begin
SMART_DrawTextEx(False, x, y, font, Text, Color);
end;

(*
SMART_DrawBitmap
~~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_DrawBitmap(Clear: Boolean; Bitmap: Integer; Placement: TPoint);

Draws a bitmap (Bitmap) on the SMART canvas at given coordinates (Placement).
Will clear the canvas beforehand if specified to do so (Clear).

.. note::

Author: Coh3n
Last Modified: January 10th, 2012 by Coh3n

Example:

.. code-block:: pascal

SMART_DrawBitmap(true, bmp, point(5, 5));
*)
procedure SMART_DrawBitmap(Clear: Boolean; Bitmap: Integer; Placement: TPoint);
begin
if (not SMART_DebugSetup) then
SMART_SetupDebug();

if (Clear) then
SMART_ClearCanvas();

DrawBitmap(Bitmap, SMART_Canvas.Canvas, Placement.X, Placement.Y);
end;

(*
SMART_FreeDebug
~~~~~~~~~~~~~~~

.. code-block:: pascal

procedure SMART_FreeDebug();

Frees the SMART_Canvas bitmap.

.. note::

Author: Coh3n
Last Modified: Unknown

Example:

.. code-block:: pascal

SMART_FreeDebug();
*)
procedure SMART_FreeDebug();
begin
try
if (SMART_DebugSetup) then
SMART_Canvas.Free;
except
Writeln('Failed to free SMART_Canvas bitmap: '+ExceptionToString(ExceptionType, ExceptionParam));
end;
end;

Coh3n

2012-01-21 14:50:25

Thanks mormonman, changed thread prefix as a reminder for us.

Coh3n

2012-01-31 17:15:39

Updated for the next version. :)