- 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
import type { Graphics } from '@pixi/graphics';
/**
* Draw Rectangle with fillet corners. This is much like rounded rectangle
* however it support negative numbers as well for the corner radius.
*
* _Note: Only available with **@pixi/graphics-extras**._
* @method PIXI.Graphics#drawFilletRect
* @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} fillet - accept negative or positive values
* @returns {PIXI.Graphics} Returns self.
*/
export function drawFilletRect(this: Graphics,
x: number,
y: number,
width: number,
height: number,
fillet: number): Graphics
{
if (fillet === 0)
{
return this.drawRect(x, y, width, height);
}
const maxFillet = Math.min(width, height) / 2;
const inset = Math.min(maxFillet, Math.max(-maxFillet, fillet));
const right = x + width;
const bottom = y + height;
const dir = inset < 0 ? -inset : 0;
const size = Math.abs(inset);
return this
.moveTo(x, y + size)
.arcTo(x + dir, y + dir, x + size, y, size)
.lineTo(right - size, y)
.arcTo(right - dir, y + dir, right, y + size, size)
.lineTo(right, bottom - size)
.arcTo(right - dir, bottom - dir, x + width - size, bottom, size)
.lineTo(x + size, bottom)
.arcTo(x + dir, bottom - dir, x, bottom - size, size)
.closePath();
}