SRL Archive - S.M.A.R.T.

Alpha values when drawing on Canvas?


Waffle

2011-12-07 17:12:34

Hey all, I'm relatively new here.. I've been using Simba actively for about 5 days, after I got around to really sitting down to figure it out.

One thing I noticed about the scripts is a lack of in-game, real-time progress reports (obviously you can tell I have used certain Java bots in the past).

I know next to nothing about Pascal, but rather than create scripts to play, I am deciding to start off learning the ropes of Simba by creating paints for scripts I use (the ones that don't have them, of course).

I was taking a look through paintsmart.scar and I fully understand how to draw shapes and text onto the SMART canvas.

But is it even possible to give them elements of transparency?

And what about drawing a full box rather than just an outline? I could easily loop from outside and increment inwards to "fake" a filled box, but from what I've gathered, the box-drawing function SMART has just connects lines.

Thanks for reading and any help is greatly appreciated
_______________

Edit1:
Here's a procedure you can add to paintsmart.scar to create a "filled" shape. Was simple to implement :)

{*******************************************************************************
procedure SMART_DrawFilledBoxEx(Clear: boolean; Box: TBox; color: TColor);
Contributors: Sir R. Magician, caused, mastaraymond, Waffle
Description: Draws a "filled" TBox onto the SMART Debug canvas
*******************************************************************************}
procedure SMART_DrawFilledBoxEx(Clear: boolean; Box: TBox; color: TColor);
{$IFDEF SMART}
var
i, height: integer;

begin
if (not SMART_DebugSetup) then
SMART_SetupDebug();

SMART_Canvas.canvas.Pen.Color := color;
if Clear then ClearRSCanvas(SMART_Canvas.canvas);

height := Box.y2 - Box.y1;

for i := 0 to height do
begin
SMART_Canvas.canvas.moveto(Box.x1,Box.y1+i);
SMART_Canvas.canvas.LineTo(Box.x2,Box.y1+i);
end;

{$ELSE}
begin
{$ENDIF}

end;

- Waffle

MylesMadness

2011-12-07 17:17:33

Out of the box I don't believe so. But you could use some Alpha composting to get your result: http://en.wikipedia.org/wiki/Alpha_compositing

Waffle

2011-12-07 17:25:07

So you're suggesting I use some sort of algorithm to change the color at (x,y) based off the color I'm drawing with (black, for example) and the color of the pixel directly "beneath it" so it "looks" like there is transparency?

MylesMadness

2011-12-07 17:33:44

Yeah that sounds right.

Waffle

2011-12-07 17:39:29

Hm. Alright, this will probably be a challenge for me in Pascal.. In Java it wouldn't seem nearly half as daunting.

Once I get functions working for filled shapes and transparency, think they could be added to the official paintsmart.scar releases? I'm sure it would help future developers a ton.

Brandon

2011-12-07 17:40:58

I've attempted this already (transparency part).. impossible.. literally that was the answer the other SRL members gave me.. Also if ur thinking of making on screen GUI's its also impossible.. thats another of the answers I got.. Everything I've attempted to do to simba/smart was literally impossible because "Pascal doesn't allow it".. most overused phrase, but probably true.

If u do attempt it, I wish u the best of luck.. hope u have better luck that I do. If u do get it done damn well U beat me where I failed. Congrats on that.

MylesMadness

2011-12-07 17:46:14

Doing it is defiantly not impossible, just requires a large amount of work.

This may also be useful for later when you trying to make the progress reports intractable: http://villavu.com/forum/showthread.php?t=56774

Waffle

2011-12-07 17:58:55

^ I hadn't thought of implementing that yet, but it's definitely a more advanced possibility to be added later

mormonman

2011-12-07 18:11:50

If this could be incorporated into Simba it would be possible: http://wiki.freepascal.org/BGRABitmap#Drawing_with_the_Canvas

Waffle

2011-12-08 19:31:51

From: mormonman
If this could be incorporated into Simba it would be possible: http://wiki.freepascal.org/BGRABitmap#Drawing_with_the_Canvas


I'm researching how this could be possible, and it looks like it's really easy to create graphics with that library, but in the Lazarus IDE.

I've got the library itself downloaded, and right now I'm trying to figure out how I could use the Units it provides in a Simba script.

This is proving rather difficult because the units of the BGRABitmap library reference other units that I'm assuming are Lazarus' Units. Simba's compiler wouldn't recognize anything.

Currently I'm downloading the Lazarus source.. I'm on a rather slow internet connection right now (free wifi at Arby's ftl) so once I do some more digging around, I'll get back to you guys.

Thanks btw, mormonman, this just eliminated all need for me to develop those methods from scratch. :)

mormonman

2011-12-08 19:42:12

From: Waffle
I'm researching how this could be possible, and it looks like it's really easy to create graphics with that library, but in the Lazarus IDE.

I've got the library itself downloaded, and right now I'm trying to figure out how I could use the Units it provides in a Simba script.

This is proving rather difficult because the units of the BGRABitmap library reference other units that I'm assuming are Lazarus' Units. Simba's compiler wouldn't recognize anything.

Currently I'm downloading the Lazarus source.. I'm on a rather slow internet connection right now (free wifi at Arby's ftl) so once I do some more digging around, I'll get back to you guys.

Thanks btw, mormonman, this just eliminated all need for me to develop those methods from scratch. :)


Simba can pass units from fpc/lazarus. Get on IRC and talk to wizzup about it.

Waffle

2011-12-12 15:45:27

From: mormonman
Simba can pass units from fpc/lazarus. Get on IRC and talk to wizzup about it.


Well I talked to BenLand about it, he mentioned not using Lazarus' units or BGRABitmap.

From: BenLand100
(3:21:58 PM) BenLand100: now, what I have currently lets you set a transparent color and it updates the screen at whatever the current update rate is
(3:22:11 PM) BenLand100: you basically write a bitmap to a buffer that it copies
(3:22:44 PM) BenLand100: if you absolutely need alpha values (why? lol, idfk) there's an extra byte there, you could POTENTIALLY use ARGB in the buffer
(3:23:14 PM) BenLand100: Then in smart you'd just need to copy the back buffer into a ARGB BufferedImage then paint that to the canvas
(3:23:40 PM) Waffle`: Alpha values aren't necessary, the only reason I want them is to make script paints more aesthetically pleasing
(3:24:12 PM) BenLand100: This is cheating, not graphics design
(3:24:24 PM) Jason2gs: lol ^
(3:25:42 PM) BenLand100: Regardless, simple binary transparency is implemented, and you can even set the transparency color! Almost no one uses it, so I don't see why I should waste time implementing a more feature filled version, because, in the end, I'll be the one that has to implement it
(3:26:24 PM) BenLand100: Of all the times people have said "SMART needs this feature, if BenLand100 doesn't do it, i'll just do it myself!" you know how many non-benland100 versions of SMART there are? 1. and Harri made it
…
(3:28:57 PM) BenLand100: I just don't get why people want to paint all over runescape. I mean, all that says to me is "hey look, my script is kind of shitty, so I put a shiny graphical front end on it! could be that all the time i put into that might have benefited the script, but look how pretty it is!"
(3:29:43 PM) BenLand100: I mean, are you telling me that the good script density is so high now that the only way to distinguish yourself is by how pretty you make the screen?
(3:30:18 PM) BenLand100: Do the noobs really care how many transparent polygons you have on the screen?
(3:30:24 PM) BenLand100: I think not.

mormonman

2011-12-12 15:49:29

Would be smarter to do all the conversions on the simba side. ARGB = RGBA -.-

Waffle

2011-12-12 16:17:18

From: mormonman
Would be smarter to do all the conversions on the simba side. ARGB = RGBA -.-


I realize this :)

If you would, direct me to some tutorials for writing bitmaps like he described? Or are there any?

Edit:
I also don't see what he's talking about when he says there's already the possibility to add translucency.

Wizzup?

2011-12-12 16:50:34

What are you drawing? I can't imagine doing the conversion in the script will make it slow?

Waffle

2011-12-12 17:43:33

Something like this


Or this:

And this design is so horribly bad, but even this: