import { safeRound } from './safe-round' /** * Draws a rounded rectangle using the current state of the canvas. * If you omit the last three params, it will draw a rectangle * outline with a 5 pixel border radius * @param {CanvasRenderingContext2D} context * @param {Number} x The top left x coordinate * @param {Number} y The top left y coordinate * @param {Number} width The width of the rectangle * @param {Number} height The height of the rectangle * @param {Number|Array} [radius = 0] The corner radius; It can also be an object * to specify different radii for corners * @param {Number} [radius.tl = 0] Top left * @param {Number} [radius.tr = 0] Top right * @param {Number} [radius.br = 0] Bottom right * @param {Number} [radius.bl = 0] Bottom left * @param {Boolean} [fill = false] Whether to fill the rectangle. * @param {Boolean} [stroke = true] Whether to stroke the rectangle. */ export function roundRect( context: CanvasRenderingContext2D, x: number, y: number, width: number, height: number, round: number = 0 ) { round = safeRound(round, width, height) if (round > 0) { context.moveTo(x + round, y) context.arcTo(x + width, y, x + width, y + height, round) context.arcTo(x + width, y + height, x, y + height, round) context.arcTo(x, y + height, x, y, round) context.arcTo(x, y, x + width, y, round) } else { context.rect(x, y, width, height) } }