Painting on SMART
By Flight
I've seen quite a few posts on the forum for people wanting to know how some scripts are able to paint on SMART, so I'm gonna show you how I do it.
Things may or may not be 100% accurate, and I'm sure there's better ways of doing so, but this is simple enough to understand.
Requirements:
What we'll cover:
- Writing text on SMART
- Painting an image on SMART
Step One: Getting our procedures
Starting off we're gonna need to import 'PaintSmart.scar' from the SRL Include so we can use it within our script. Let's do that by adding this line up with the rest of the includes: (near the top of your script)
Simba Code:
{$i SRL/SRL/misc/paintsmart.scar}
Note that this is not my procedure, I believe it was BobboHobbo. This is the procedure we'll use to draw an array of text on SMART at a specific point we define using a specific color we define. For those of you who don't know an array of text (TStringArray) is really simple to make. Here's an example:
Simba Code:
PrintTexts := ['Hello', 'there', 'my name', 'is Flight'];
You can see how anything in the array is defined within the "[]" and separated with commas. And because it's text (strings) each text will have (''). Alright, so let's get our procedure.
Simba Code:
Procedure PrintOnSmart(TP: TStringArray; Placement: TPoint; Colour: integer);
var
mx, my, Pic, I, B, H, TPH, Numb: Integer;
TTP: TPointArray;
Canvas: TCanvas;
begin
SmartSetDebug(True);
GetClientDimensions(mx, my);
Pic := BitmapFromString(mx, my, '');
TPH := High(TP);
for I := 0 to TPH do
begin
TTP := LoadTextTPA(TP[i], SmallChars, H);
for B := 0 to High(TTP) do
begin
Numb := ((I + 1) * 13);
FastSetPixel(Pic, TTP[b].x + 1, TTP[b].y + Numb + 1,131072);
FastSetPixel(Pic, TTP[b].x, TTP[b].y + Numb, Colour);
end;
end;
Canvas := TCANVAS.Create;
Canvas.Handle := SmartGetDebugDC;
DrawBitmap(Pic, Canvas, Placement.x, Placement.y);
FreeBitmap(Pic);
end;
The parameters for this procedure is (TStringArray, Placement, Color), very simple, ya? We already know what to put in place for "TP", but what about the other two? Easy peasy. Placement is where the top-left corner of first text will appear. So, to get an accurate coordinate of where you'll want to place your text, what I always do is load up SMART and drag the "Select a client" button (near the top of Simba, looks like a green scope with a target in the middle) over to SMART.
Now when you hover your mouse over SMART the coords displayed in Simba (bottom left-hand corner) are now accurate. So, move your mouse over SMART where you want to place your text. I chose the point (40, 50):
Now we just need a color for our text. I simply use Simba's Colour-Picker tool (just left of the 'Select a client' tool) and get a color that way. I picked 255, which is a pure red. So it looks like we have everything we need to start using the procedure, let's do it!
Step Two: Printing text
Hopefully you've already thought of what you're gonna print on your SMART canvas. For this tutorial I'm gonna use ['A painted canvas', 'by Flight'], with my placement being Point(40, 50) and my color being 255. So where ever you want your on-screen painting go ahead an use it as such. So here's what my test script is looking like so far:
Simba Code:
program PaintStuff;
{$define SMART}
{$i srl/srl.scar}
{$i SRL/SRL/misc/paintsmart.scar}
Procedure PrintOnSmart(TP: TStringArray; Placement: TPoint; Colour: integer);
var
mx, my, Pic, I, B, H, TPH, Numb: Integer;
TTP: TPointArray;
Canvas: TCanvas;
begin
SmartSetDebug(True);
GetClientDimensions(mx, my);
Pic := BitmapFromString(mx, my, '');
TPH := High(TP);
for I := 0 to TPH do
begin
TTP := LoadTextTPA(TP[i], SmallChars, H);
for B := 0 to High(TTP) do
begin
Numb := ((I + 1) * 13);
FastSetPixel(Pic, TTP[b].x + 1, TTP[b].y + Numb + 1,8388736);
FastSetPixel(Pic, TTP[b].x, TTP[b].y + Numb, Colour);
end;
end;
Canvas := TCANVAS.Create;
Canvas.Handle := SmartGetDebugDC;
DrawBitmap(Pic, Canvas, Placement.x, Placement.y);
FreeBitmap(Pic);
end;
Procedure DoThePainting;
begin
PrintOnSmart(['A painted canvas', 'by Flight'], Point(40, 50), 255);
end;
begin
Smart_Server := 86;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
SetupSRL; //This must be called before any canvas painting
DoThePainting;
end.
Alright, let's run it and see how she turned out.
Wonderful! Also you're probably asking why the text was written from top to bottom. Well that's how the procedure works, for each independent string (text) you paint, it will appear below the last text. Because I had two strings ("A painted canvas" and "By Flight") I had two lines of text painted on SMART.
There's no limit to what all you can print on SMART with text. If you've used some of my scripts before you've noticed I use this for the on-screen printing of progress reports and such. But for now, this is a good place to begin and experiment.
Step Three: Printing images
Ok this... I'm sure there's a much simpler way of doing so, but this is the way I do it. It's a cheap hack pretty much. What we're gonna do here is modify (butcher) the "PrintOnSmart" procedure. If you've read over the procedure you'll see what it does is draw your text on the screen in the form of a Bitmap. So what we'll do is create our own bitmap (image) to be drawn in the procedure.
Go ahead and make the image you want to draw in paint, photoshop, whatever, just make sure you save it as Bitmap (.bmp, 24-bit). I'll be using this:
Alright, let's modify the procedure to make two "Pic"s. I'll make the new modified procedure, assuming we'll be placing our image at (40, 100) (slightly below where our text ends).
Simba Code:
Procedure PrintOnSmart(TP: TStringArray; Placement: TPoint; Colour: integer);
var
mx, my, Pic, Pic2, I, B, H, TPH, Numb: Integer; //Add another Pic here (I used Pic2)
TTP: TPointArray;
Canvas: TCanvas;
begin
SmartSetDebug(True);
GetClientDimensions(mx, my);
Pic := BitmapFromString(mx, my, '');
Pic2 := //Here is where we'll put the BMP info from our image
TPH := High(TP);
for I := 0 to TPH do
begin
TTP := LoadTextTPA(TP[i], SmallChars, H);
for B := 0 to High(TTP) do
begin
Numb := ((I + 1) * 13);
FastSetPixel(Pic, TTP[b].x + 1, TTP[b].y + Numb + 1,8388736);
FastSetPixel(Pic, TTP[b].x, TTP[b].y + Numb, Colour);
end;
end;
Canvas := TCANVAS.Create;
Canvas.Handle := SmartGetDebugDC;
DrawBitmap(Pic, Canvas, Placement.x, Placement.y);
DrawBitmap(Pic2, Canvas, 40, 100); //The 40 & 100 is the X/Y of where the image will be printed
FreeBitmap(Pic);
FreeBitmap(Pic2);
end;
Luckily Simba has a tool for converting a Bitmap to a string, which we can use within this procedure. So let's go up to 'Tools > Bitmap conversion' and open the image we want to use. Now just hit the 'To string' button and your image's BMP info will be printed in Simba. Here's mine:
Simba Code:
Bmp := BitmapFromString(22, 19, 'meJytk7ENAjEMRVNSsgprsApr3A' +
'iU11KySsoraRnDZ/Glr499CS6wopPPsV9sx2ntn3K+3ny5cnlasJy' +
'WrUhwTzgDopYKhP50DpYKRMODvV4LSkAVUFgX9bks/Ss8Q9DbSjj0' +
'QHCFF5QzzwRClABIJYFDQsjqZwKBoJBDwlweb/Ol3chb9hEq1Hvv6' +
'pabqQRYTITh+LKE0Ez/hU/fbF1jRZr/aK5AgBtDdDUZp9E8MA0NvL' +
'+MreYrm8ykb+VLYdTo6Cx8zuGlj2QHxKVFOg==');
Alright, let's plug that into the procedure:
Simba Code:
Procedure PrintOnSmart(TP: TStringArray; Placement: TPoint; Colour: integer);
var
mx, my, Pic, Pic2, I, B, H, TPH, Numb: Integer;
TTP: TPointArray;
Canvas: TCanvas;
begin
SmartSetDebug(True);
GetClientDimensions(mx, my);
Pic := BitmapFromString(mx, my, '');
Pic2 := BitmapFromString(22, 19, 'meJytk7ENAjEMRVNSsgprsApr3A' +
'iU11KySsoraRnDZ/Glr499CS6wopPPsV9sx2ntn3K+3ny5cnlasJy' +
'WrUhwTzgDopYKhP50DpYKRMODvV4LSkAVUFgX9bks/Ss8Q9DbSjj0' +
'QHCFF5QzzwRClABIJYFDQsjqZwKBoJBDwlweb/Ol3chb9hEq1Hvv6' +
'pabqQRYTITh+LKE0Ez/hU/fbF1jRZr/aK5AgBtDdDUZp9E8MA0NvL' +
'+MreYrm8ykb+VLYdTo6Cx8zuGlj2QHxKVFOg==');
TPH := High(TP);
for I := 0 to TPH do
begin
TTP := LoadTextTPA(TP[i], SmallChars, H);
for B := 0 to High(TTP) do
begin
Numb := ((I + 1) * 13);
FastSetPixel(Pic, TTP[b].x + 1, TTP[b].y + Numb + 1,8388736);
FastSetPixel(Pic, TTP[b].x, TTP[b].y + Numb, Colour);
end;
end;
Canvas := TCANVAS.Create;
Canvas.Handle := SmartGetDebugDC;
DrawBitmap(Pic, Canvas, Placement.x, Placement.y);
DrawBitmap(Pic2, Canvas, 40, 100);
FreeBitmap(Pic);
FreeBitmap(Pic2);
end;
Now let's run it and see what happens.
Yaya, success!
So this concludes the super simple SMART painting tutorial. Like I mentioned before this is just how I do it personally, you're in no way limited to using my methods. So be creative, play around with this and see what you can come up with. If you've any questions ask away.
~Cheerz