Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Knox on Sat 21/05/2011 00:02:06

Title: Anti-Aliased for drawing on a gui...part 2!
Post by: Knox on Sat 21/05/2011 00:02:06
I started this thread a while ago but pretty much got my answers myself screwing around and what not: http://www.adventuregamestudio.co.uk/yabb/index.php?PHPSESSID=6ve262cd3e75q7svke88rgrs74&topic=43454.0 (http://www.adventuregamestudio.co.uk/yabb/index.php?PHPSESSID=6ve262cd3e75q7svke88rgrs74&topic=43454.0)

However, I ran into a problem:

Im not sure why but it seems that when I draw onto a gui with my "pen", the line is totally opaque (I cant see the semi-transparent "edge" of the "pen-dot" sprite to make the line look anti-aliased).

I tried a 2nd way by using a different script that I modified a bit (still contains bugs/errors), but its much closer to the effect Im searching for.

Here are the videos...how can I get Mode 1 (using a sprite + Wyz's BrushLine code) to match the second's anti-aliased look (Kweepa's DrawAntialiased v1.1: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=39846.0 (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=39846.0))

Mode 1: http://www.youtube.com/watch?v=Wo0HpJN9f78 (http://www.youtube.com/watch?v=Wo0HpJN9f78)

Mode 2: http://www.youtube.com/watch?v=IklxVuY06gg (http://www.youtube.com/watch?v=IklxVuY06gg)



SCRIPT:

DynamicSprite *dsWriteOnSurface;
DrawingSurface *DrawSurface;
Overlay *ovPen;
int iPenColor;
int iTrans = 0;

function BrushLine(this DrawingSurface*, int x1, int y1, int x2, int y2, int slot, float spread)
{
 x1 -= Game.SpriteWidth[slot] / 2;
 y1 -= Game.SpriteHeight[slot];
 x2 -= Game.SpriteWidth[slot] / 2;
 y2 -= Game.SpriteHeight[slot];
 
 float dx = IntToFloat(x2 - x1);
 float dy = IntToFloat(y2 - y1);
 
 float interval = Maths.Sqrt(dx*dx + dy*dy);
 interval = interval / (IntToFloat(Game.SpriteWidth[slot] + Game.SpriteHeight[slot]) / (spread * 2.0));
 
 if (interval < 1.0)
   interval = 1.0;
 
 float i = 0.0;
 float xoffset = dx / interval;
 float yoffset = dy / interval;
 float xx = IntToFloat(x1);
 float yy = IntToFloat(y1);
 
 while (i < interval)
 {
   this.DrawImage(FloatToInt(xx), FloatToInt(yy), slot, iTrans);
   xx += xoffset;
   yy += yoffset;
   i++;
 }
}

void DynamicDraw(this Button*, int iMode)
{
 if (iMode == 1) //Draw BrushLine with Sprite ON GUI
 {
   if (bIsDrawing == true)
   {
     if (Mouse.IsButtonDown(eMouseLeft) == true)
     {
       iPenColor = 2720; //Black pen Small

       dsWriteOnSurface = DynamicSprite.CreateFromExistingSprite(this.NormalGraphic);
       DrawSurface = dsWriteOnSurface.GetDrawingSurface();
       DrawSurface.BrushLine(mouse.x-iGuiX, mouse.y-iGuiY, iPrevX-iGuiX, iPrevY-  iGuiY, iPenColor, 20.0);

       //Anti-Aliased:
       //int iX = mouse.x-iGuiX;
       //float fX = IntToFloat(iX);
       //int iY = mouse.y-iGuiY;
       //float fY = IntToFloat(iY);
       //int iX2 = iPrevX-iGuiX;
       //fPrevX = IntToFloat(iX2);
       //int iY2 = iPrevY-iGuiY;
       //fPrevY = IntToFloat(iY2);
       //DrawAntialiasedLine(DrawSurface, fX, fY, fPrevX, fPrevY, 0);

       this.NormalGraphic = dsWriteOnSurface.Graphic;
       iPrevX = mouse.x;
       iPrevY = mouse.y;
       //fPrevX = IntToFloat(iPrevX);
       //fPrevY = IntToFloat(iPrevY);
     }
     else bIsDrawing = false;
   }
 }  
}

void on_event (EventType event, int data)
{
if (oTg == gTicketBook_Cit)
{
 bIsDrawing = true;
 iPrevX = mouse.x;
 iPrevY = mouse.y;  
 //fPrevX = IntToFloat(iPrevX);
 //fPrevY = IntToFloat(iPrevY);    
 return;
}
else
{
 if (bIsDrawing == true) bIsDrawing = false;
}
}

function repeatedly_execute()
{
 if (gTicketBook_Cit.Visible && mouse.GetModeGraphic(eModePointer) == 3901)
 {
   iGuiX=484;
   iGuiY=152;
   btnCitation.DynamicDraw(1);
 }
}
Title: Re: Anti-Aliased for drawing on a gui...part 2!
Post by: Wyz on Mon 23/05/2011 22:36:55
That looks pretty neat, great job!
Title: Re: Anti-Aliased for drawing on a gui...part 2!
Post by: Knox on Tue 24/05/2011 01:32:54
Thanks Wyz...thanks for your code snippit :)

I just need to figure out how to make the edges of the line look anti-aliased and we're all set. ;D
Title: Re: Anti-Aliased for drawing on a gui...part 2!
Post by: Knox on Fri 27/05/2011 14:35:55
Does anyone have a theory as to why the edges seem "blocky" while drawing the line, when the sprite being used to draw with has semi-transparentcy on its edges (its a spot with faded/blurred halo).

Im guessing cause the sprite gets redrawn over and over as you make a line, so the semi-transparent part gets added to itself, making it opaque?