SRL Archive - Outdated Tutorials

[Dev #596] PaintSmart.scar


Sir R. M8gic1an

2010-09-03 04:45:36

Dear all, a new file comes under SRL's version control. (I say this because it was a pain in the butt figuring that I had to use svn 'add' rather than 'commit' through the terminal >.>)

PaintSmart.scar

http://villavu.com/repositories/srl-opendev/SRL/misc/PaintSmart.scar

//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- � Smart Painting routines --//
//-----------------------------------------------------------------//
// Procedure ClearCanvas(canvas: TCanvas; w, h: integer); //
// Procedure ClearRSCanvas(canvas: TCanvas); //
// Procedure SMART_DrawDotsEx(Clear: boolean; pixels: TPointArray; color: TColor);
// Procedure SMART_DrawDots(Dots: TPointArray); //
// Procedure SMART_DrawBoxEx(Clear: boolean; Box: TBox; color: TColor);
// procedure SMART_DrawBox(Box: TBox); //
//-----------------------------------------------------------------//



{*******************************************************************************
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 end;

end;

{*******************************************************************************
Procedure ClearRSCanvas(canvas: TCanvas);
Contributors: Sir R. Magician
Description: Clears a canvas of RS dimensions
*******************************************************************************}
Procedure ClearRSCanvas(canvas: TCanvas);
begin
ClearCanvas(canvas, MIX2, MIY2);
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;
drawing : TBitmap;
begin

drawing := TBitmap.Create;
drawing.canvas.handle := SmartGetDebugDC;
drawing.canvas.Pen.Color := color;

ClearRSCanvas(drawing.canvas);

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

try
FreeBitmap(drawing);
except 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
DrawDotsEx(True, Dots, 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);
{$IFDEF SMART}
var
drawing : TBitmap;
TP : TPoint;
B: TBox;
begin

drawing := TBitmap.Create;
drawing.canvas.handle := SmartGetDebugDC;
drawing.canvas.Pen.Color := color;

ClearRSCanvas(drawing.canvas);

drawing.canvas.moveto(Box.x1,Box.y1);
drawing.canvas.LineTo(Box.x2,Box.y1);
drawing.canvas.LineTo(Box.x2,Box.y2);
drawing.canvas.LineTo(Box.x1,Box.y2);
drawing.canvas.LineTo(Box.x1,Box.y1);


try
FreeBitmap(drawing);
except end;

{$ELSE}
begin
{$ENDIF}

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
DrawBoxEx(True, Box, clRed);
end;

These functions allow you to debug things onto the Smart Debug. You'll have to turn it on once you load SMART. There's also a function for that, but I fail to remember which one atm.

Also, from experience, if you use this make a constant in your script to allow people to turn it off, if they so wish. Some computers might not be able to handle it properly (lagging) and some people might just not like it.

If anyone would like to write up functions to paint text or bitmaps onto the Smart Debug Canvas, go ahead.

~RM

EvilChicken!

2010-09-03 06:07:28

From: Sir R. Magician
If anyone would like to write up functions to paint text or bitmaps onto the Smart Debug Canvas, go ahead.


CreateTextFromTPA?

But, nice, you committed it. :)

JuKKa

2010-09-03 16:22:36


rocedure SMART_DrawText(x, y: Integer; font, Text: string);
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_DrawDots(tpa);
end;

you need to edit some of the functions to make it work properly

Sir R. M8gic1an

2010-09-03 23:07:16

From: JuKKa

you need to edit some of the functions to make it work properly


What do you mean?

~RM

JuKKa

2010-09-04 01:45:40

It clears the canvas every time you draw a new line of text.

Sir R. M8gic1an

2010-09-04 02:07:19



procedure SMART_DrawText(x, y: Integer; font, Text: string);
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(false, tpa, clBlack);
end;

Fixed. DrawDotsEx has a 'clear' parameter.

edit: actually the clear parameter isn't being used. Need to fix that.

~RM