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
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;