[bmx] DrawPoly(), filled or unfilled by Oddball [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:43

Previous topic - Next topic

BlitzBot

Title : DrawPoly(), filled or unfilled
Author : Oddball
Posted : 1+ years ago

Description : Just add the function below to your project and it will override BlitzMaxs DrawPoly.

Function DrawPoly(xy#[],fill%=True,x#=0,y#=0)

Draws a polygon at coordinates x# and y# with corners defined by an array of x#,y# coordinate pairs. Setting fill=False draws an unfilled polygon. If the optional parameters are left blank DrawPoly acts identically to the standard BlitzMax function.

BlitzMax commands that affect the drawing of polygons include #SetColor, #SetHandle, #SetScale, #SetRotation, #SetOrigin, #SetViewPort, #SetBlend and #SetAlpha.


Code :
Code (blitzmax) Select
Function DrawPoly( xy:Float[], fill:Int=True, x:Float=0, y:Float=0 )
Local origin_x:Float
Local origin_y:Float
GetOrigin origin_x,origin_y
Local handle_x:Float
Local handle_y:Float
GetHandle handle_x,handle_y

If fill
_max2dDriver.DrawPoly xy,..
-handle_x,-handle_y,..
x+origin_x,y+origin_y
Else
Local x1:Float=xy[xy.Length-2]
Local y1:Float=xy[xy.Length-1]
For Local i:Int=0 Until Len xy Step 2
Local x2:Float=xy[i]
Local y2:Float=xy[i+1]
_max2dDriver.DrawLine..
-handle_x+x1,-handle_y+y1,..
-handle_x+x2,-handle_y+y2,..
x+origin_x-0.5,y+origin_y-0.5
x1=x2
y1=y2
Next
EndIf
End Function


Comments :


Oddball(Posted 1+ years ago)

 Slight bugfix. Apparently handle position wasn't mimiced correctly. Not sure how that slipped by for so long.