forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdrawRoundRect.as
More file actions
69 lines (62 loc) · 2.58 KB
/
drawRoundRect.as
File metadata and controls
69 lines (62 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package utils.draw
{
import flash.display.Graphics;
/**
Draws a rounded rectangle. Act identically to <code>Graphics.drawRoundRect</code> but allows the specification of which corners are rounded.
@param graphics: The location where drawing should occur.
@param x: The horizontal position of the rectangle.
@param y: The vertical position of the rectangle.
@param width: The width of the rectangle.
@param height: The height of the rectangle.
@param ellipseWidth: The width in pixels of the ellipse used to draw the rounded corners.
@param ellipseHeight: The height in pixels of the ellipse used to draw the rounded corners.
@param topLeft: Specifies if the top left corner of the rectangle should be rounded <code>true</code>, or should be square <code>false</code>.
@param topRight:Specifies if the top right corner of the rectangle should be rounded <code>true</code>, or should be square <code>false</code>.
@param bottomRight: Specifies if the bottom right corner of the rectangle should be rounded <code>true</code>, or should be square <code>false</code>.
@param bottomLeft: Specifies if the bottom left corner of the rectangle should be rounded <code>true</code>, or should be square <code>false</code>.
@usage
<code>
this.graphics.beginFill(0xFF00FF);
DrawUtil.drawRoundRect(this.graphics, 10, 10, 200, 200, 50, 50, true, false, true, false);
this.graphics.endFill();
</code>
*/
public function drawRoundRect(graphics:Graphics, x:Number, y:Number, width:Number, height:Number, ellipseWidth:Number, ellipseHeight:Number, topLeft:Boolean = true, topRight:Boolean = true,
bottomRight:Boolean = true, bottomLeft:Boolean = true):void
{
const radiusWidth:Number = ellipseWidth * 0.5;
const radiusHeight:Number = ellipseHeight * 0.5;
if (topLeft)
graphics.moveTo(x + radiusWidth, y);
else
graphics.moveTo(x, y);
if (topRight)
{
graphics.lineTo(x + width - radiusWidth, y);
graphics.curveTo(x + width, y, x + width, y + radiusHeight);
}
else
graphics.lineTo(x + width, y);
if (bottomRight)
{
graphics.lineTo(x + width, y + height - radiusHeight);
graphics.curveTo(x + width, y + height, x + width - radiusWidth, y + height);
}
else
graphics.lineTo(x + width, y + height);
if (bottomLeft)
{
graphics.lineTo(x + radiusWidth, y + height);
graphics.curveTo(x, y + height, x, y + height - radiusHeight);
}
else
graphics.lineTo(x, y + height);
if (topLeft)
{
graphics.lineTo(x, y + radiusHeight);
graphics.curveTo(x, y, x + radiusWidth, y);
}
else
graphics.lineTo(x, y);
}
}