UNPKG

@avolutions/canvas-painter

Version:

CanvasPainter.js is a simple yet powerful JavaScript library for drawing basic shapes (rectangles, circles, etc.) on HTML5 Canvas with ease. Perfect for creating 2D graphics in your web projects.

126 lines (125 loc) 4.77 kB
import { Angle } from "../types/Angle.js"; import { Point } from "../types/Point.js"; import { RectangleDefinition } from "../definitions/RectangleDefinition.js"; import { Shape } from "./Shape.js"; import { RectangleStyle } from "../styles/RectangleStyle.js"; import { RectangleOptions } from "../options/RectangleOptions.js"; import { IRectangleOptions } from "../options/interfaces/IRectangleOptions.js"; import { IRectangleStyle } from "../styles/interfaces/IRectangleStyle.js"; /** * Class representing a Rectangle, extending the Shape class with a RectangleDefinition. * Provides functionality for rendering, resizing, moving, and rotating the rectangle. */ export declare class Rectangle extends Shape<RectangleDefinition, RectangleStyle, RectangleOptions> { /** * Constructs a new Rectangle instance. * * @param x - The x-coordinate of the rectangle's position. * @param y - The y-coordinate of the rectangle's position. * @param width - The width of the rectangle. * @param height - The height of the rectangle. * @param rotation - The initial rotation of the rectangle in degrees clockwise. * @param style - The style options for the rectangle. * @param options - The configuration options for the rectangle. */ constructor(x: number, y: number, width: number, height: number, rotation?: number, style?: IRectangleStyle, options?: IRectangleOptions); /** * Gets the width of the rectangle. * @returns The width of the rectangle. */ get width(): number; /** * Gets the height of the rectangle. * @returns The height of the rectangle. */ get height(): number; /** * Gets the position (Point) of the rectangle. * @returns The position of the rectangle. */ get position(): Point; /** * Gets the angle of the rectangle. * @returns The angle (rotation) of the rectangle. */ get angle(): Angle; /** * Gets the rotation of the rectangle in degrees. * @returns The rotation of the rectangle. */ get rotation(): number; /** * Sets the width of the rectangle. * @param width - The new width of the rectangle. */ set width(width: number); /** * Sets the height of the rectangle. * @param height - The new height of the rectangle. */ set height(height: number); /** * Sets the position (Point) of the rectangle. * @param position - The new position of the rectangle. */ set position(position: Point); /** * Sets the rotation of the rectangle. * @param rotation - The new rotation of the rectangle. */ set rotation(rotation: number); /** * Updates the size of the rectangle by setting new width and height values. * * @param width - The new width of the rectangle. * @param height - The new height of the rectangle. */ setSize(width: number, height: number): void; /** * Resizes the rectangle by adjusting the current width and height by delta values. * * @param deltaWidth - The change in width. * @param deltaHeight - The change in height. */ resize(deltaWidth?: number, deltaHeight?: number): void; /** * Moves the rectangle by adjusting the current position by delta values. * * @param deltaX - The change in the x-coordinate. * @param deltaY - The change in the y-coordinate. */ move(deltaX?: number, deltaY?: number): void; /** * Rotates the rectangle by adjusting its current angle. * * @param deltaRotation - The amount to adjust the rectangle's rotation, in degrees. */ rotate(deltaRotation: number): void; /** * Gets the top-left position of the rectangle. * If the rectangle is centered, it adjusts based on the width and height. * @returns The top-left position of the rectangle. */ private getTopLeftPosition; /** * Renders the rectangle on the canvas using the provided 2D rendering context. * * The rectangle will be rendered with its current position, size, and rotation. * * @param context - The 2D rendering context of the canvas where the rectangle will be drawn. */ render(context: CanvasRenderingContext2D): void; /** * Determines if the mouse is currently over the shape. * * @param mousePosition - The current mouse position. * @returns True if the mouse is over the shape, false otherwise. */ isMouseOver(mousePosition: Point): boolean; /** * Handles the drag operation by applying the given delta to the current position. * * @param delta - The change in position represented as a `Point`. */ onDrag(delta: Point): void; }