- 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
import type { Graphics } from '@pixi/graphics';
/**
* Draw Rectangle with chamfer corners. These are angled corners.
*
* _Note: Only available with **@pixi/graphics-extras**._
* @method PIXI.Graphics#drawChamferRect
* @param this
* @param {number} x - Upper left corner of rect
* @param {number} y - Upper right corner of rect
* @param {number} width - Width of rect
* @param {number} height - Height of rect
* @param {number} chamfer - non-zero real number, size of corner cutout
* @returns {PIXI.Graphics} Returns self.
*/
export function drawChamferRect(this: Graphics,
x: number,
y: number,
width: number,
height: number,
chamfer: number): Graphics
{
if (chamfer <= 0)
{
return this.drawRect(x, y, width, height);
}
const inset = Math.min(chamfer, Math.min(width, height) / 2);
const right = x + width;
const bottom = y + height;
const points = [
x + inset, y,
right - inset, y,
right, y + inset,
right, bottom - inset,
right - inset, bottom,
x + inset, bottom,
x, bottom - inset,
x, y + inset,
];
// Remove overlapping points
for (let i = points.length - 1; i >= 2; i -= 2)
{
if (points[i] === points[i - 2] && points[i - 1] === points[i - 3])
{
points.splice(i - 1, 2);
}
}
return this.drawPolygon(points);
}