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.

I just need to figure out how to make the edges of the line look anti-aliased and we're all set.

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
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);
}
}
function repeatedly_execute()
{
if (bIsDrawing == true)
{
if (Mouse.IsButtonDown(eMouseLeft) == true)
{
//Display("Draw!");
int iPenColor = 2716; //Blue pen
//int iPenColor = 2718; //Black pen
//int iPenColor = 2720; //Red pen
//int iPenColor = 3853; //Highlighter
//A:
//DrawingSurface *DrawSurface = Room.GetDrawingSurfaceForBackground();
//B:
DynamicSprite *dsNotePad = DynamicSprite.CreateFromExistingSprite(gNotePad.BackgroundGraphic);
//DynamicSprite *dsNotePad = DynamicSprite.CreateFromExistingSprite(3854);
DrawingSurface *DrawSurface = dsNotePad.GetDrawingSurface();
DrawSurface.BrushLine(mouse.x, mouse.y, iPrevX, iPrevY, iPenColor, 7.0);
DrawSurface.Release();
//B:
gNotePad.BackgroundGraphic = dsNotePad.Graphic;
//Wait(120);
//dsNotePad.Delete();
iPrevX = mouse.x;
iPrevY = mouse.y;
}
else bIsDrawing = false;
}
function on_mouse_click(MouseButton button)
{
if (button == eMouseLeft)
{
bIsDrawing = true;
iPrevX = mouse.x;
iPrevY = mouse.y;
}
}
QuoteIn order to use DynamicSprites as button or GUI backgrounds, they have to be defined outside any function (otherwise they are destroyed as soon as the function finishes, ending the element that uses them up at displaying sprite 0/the blue cup).
function repeatedly_execute()
{
if (bIsDrawing == true)
{
if (Mouse.IsButtonDown(eMouseLeft) == true)
{
int iPenColor = 2716; //blue pen ...2718 black pen ...2720 red pen
DrawingSurface *DrawSurface = Room.GetDrawingSurfaceForBackground();
DrawSurface.BrushLine(mouse.x, mouse.y, iPrevX, iPrevY, iPenColor, 7.0);
iPrevX = mouse.x;
iPrevY = mouse.y;
}
else bIsDrawing = false;
}
}
function on_mouse_click(MouseButton button)
{
if (button == eMouseLeft)
{
bIsDrawing = true;
iPrevX = mouse.x;
iPrevY = mouse.y;
}
}
if (bIsDrawing == true)
{
if (Mouse.IsButtonDown(eMouseLeft) == true)
{
DrawingSurface *DrawSurface = Room.GetDrawingSurfaceForBackground();
float fMouseX = IntToFloat(mouse.x);
float fMouseY = IntToFloat(mouse.y);
DrawAntialiasedLine(DrawSurface, fMouseX, fMouseY, fMouseX*1.2, fMouseY*1.2, 0); <--what do I put here for smooth lines?
DrawSurface.Release();
}
else bIsDrawing = false;
}
gQG_PageTurnGUI.Animate(iLoop, 0.5, eOnce, eBlock, eForwards);
if (btnMyBtn.NormalGraphic != 17) btnMyBtn.NormalGraphic = 17;
By continuing to use this site you agree to the use of cookies. Please visit this page to see exactly how we use these.
Page created in 0.166 seconds with 14 queries.