scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
166 lines (163 loc) • 4.09 kB
text/typescript
import { AbsDrawContext } from 'scriptable-abstract';
import { MockImage } from '../media/image.mjs';
interface DrawOperation {
type: 'image' | 'path' | 'rect' | 'ellipse' | 'text';
data: any;
}
interface DrawContextState {
size: Size;
respectScreenScale: boolean;
opaque: boolean;
currentPath?: Path;
fillColor?: Color;
strokeColor?: Color;
lineWidth: number;
canvas: MockImage;
font?: Font;
textColor?: Color;
textAlignment: 'left' | 'center' | 'right';
operations: DrawOperation[];
}
/**
* Mock implementation of Scriptable's DrawContext.
* Provides a context for drawing shapes, text and images.
* @implements DrawContext
*/
declare class MockDrawContext extends AbsDrawContext<DrawContextState> {
constructor();
/**
* Creates a new drawing context with the specified size.
*/
static create(width: number, height: number): DrawContext;
get size(): Size;
set size(value: Size);
get respectScreenScale(): boolean;
set respectScreenScale(value: boolean);
get opaque(): boolean;
set opaque(value: boolean);
/**
* Gets the image that was drawn in the context.
*/
getImage(): Image;
/**
* Draws an image in the specified rect.
*/
drawImageInRect(image: Image, rect: Rect): void;
/**
* Draws an image at the specified point.
*/
drawImageAtPoint(image: Image, point: Point): void;
/**
* Sets the fill color used when filling paths and shapes.
*/
setFillColor(color: Color): void;
/**
* Sets the stroke color used when stroking paths and shapes.
*/
setStrokeColor(color: Color): void;
/**
* Sets the width of lines when stroking paths and shapes.
*/
setLineWidth(width: number): void;
/**
* Begins a new path.
*/
beginPath(): void;
/**
* Moves to a point in the current path.
*/
moveToPoint(point: Point): void;
/**
* Adds a line to a point in the current path.
*/
addLineToPoint(point: Point): void;
/**
* Adds a curve to the current path.
*/
addCurveToPoint(point: Point, control1: Point, control2: Point): void;
/**
* Adds a quadratic curve to the current path.
*/
addQuadCurveToPoint(point: Point, control: Point): void;
/**
* Closes the current path.
*/
closePath(): void;
/**
* Strokes the current path.
*/
strokePath(): void;
/**
* Fills the current path.
*/
fillPath(): void;
/**
* Fills and strokes the current path.
*/
fillAndStrokePath(): void;
/**
* Adds a rectangle to the current path.
*/
addRect(rect: Rect): void;
/**
* Adds an ellipse to the current path.
*/
addEllipseInRect(rect: Rect): void;
/**
* Fills a rectangle.
*/
fill(rect: Rect): void;
/**
* Fills a rectangle.
*/
fillRect(rect: Rect): void;
/**
* Fills an ellipse.
*/
fillEllipse(rect: Rect): void;
/**
* Strokes a rectangle.
*/
stroke(rect: Rect): void;
/**
* Strokes a rectangle.
*/
strokeRect(rect: Rect): void;
/**
* Strokes an ellipse.
*/
strokeEllipse(rect: Rect): void;
/**
* Adds a path to the context.
*/
addPath(path: Path): void;
/**
* Draws text at a position.
*/
drawText(text: string, pos: Point): void;
/**
* Draws text in a rectangle.
*/
drawTextInRect(text: string, rect: Rect): void;
/**
* Sets the font to use when drawing text.
*/
setFont(font: Font): void;
/**
* Sets the text color used when drawing text.
*/
setTextColor(color: Color): void;
/**
* Specifies that texts should be left aligned.
*/
setTextAlignedLeft(): void;
/**
* Specifies that texts should be center aligned.
*/
setTextAlignedCenter(): void;
/**
* Specifies that texts should be right aligned.
*/
setTextAlignedRight(): void;
}
export { MockDrawContext };