@itwin/core-frontend
Version:
iTwin.js frontend components
88 lines • 4.34 kB
TypeScript
/** @packageDocumentation
* @module Views
*/
import { Point2d, Point3d, XYAndZ } from "@itwin/core-geometry";
import { ImageSource } from "@itwin/core-common";
import { CanvasDecoration } from "./render/CanvasDecoration";
import { DecorateContext } from "./ViewContext";
import { ScreenViewport } from "./Viewport";
/** Sprites are small raster images that are drawn *on top* of Viewports by a ViewDecoration.
* Their purpose is to draw the user's attention to something of importance.
*
* There are two classes in the Sprites subsystem: Sprite (a Sprite image) and SpriteLocation.
* Sprite are the images that define the way a type of sprite looks and are generally
* loaded one time and saved for the rest of a session. A SpriteLocation defines the current
* position of a single Sprite in a Viewport.
*
* A SpriteLocation can be either active or inactive. It becomes active by specifying a location
* (an x,y point) and a Sprite to draw at that point. A Sprite
* can be used many times by many SpriteLocations and a single SpriteLocation can
* change both position and which Sprite is shown at that position over time.
* @public
* @extensions
*/
export declare class Sprite {
/** The image for this Sprite. If undefined, the Spite is not valid. */
image?: HTMLImageElement;
/** The size of this Sprite. If not loaded, value is not meaningful. */
readonly size: Point2d;
/** Promise fulfilled when this sprite is loaded. */
loadPromise: Promise<HTMLImageElement>;
/** The offset to the middle of this Sprite. If not loaded, value is not meaningful. */
get offset(): Point2d;
/** Whether this sprite has be successfully loaded. */
get isLoaded(): boolean;
/** construct a Sprite from an ImageSource or a Url
* @param src The ImageSource holding an image to create the texture for this Sprite, or the url of the image
*/
constructor(src: ImageSource | string);
}
/** Icon sprites are loaded from .png files in the assets directory of imodeljs-native.
* They are cached by name, and the cache is cleared when the ToolAdmin is shut down.
* @public
* @extensions
*/
export declare class IconSprites {
private static readonly _sprites;
/** Look up an IconSprite by url. If not loaded, create and load it.
* @param spriteUrl The url of an image to load for this Sprite.
*/
static getSpriteFromUrl(spriteUrl: string): Sprite;
/** Empty the cache, disposing all existing Sprites. */
static emptyAll(): void;
}
/** A Sprite location. Sprites generally move around on the screen and this object holds the current location
* and current Sprite within a ScreenViewport. SpriteLocations can be either inactive (not visible) or active.
*
* A SpriteLocation can also specify that a Sprite should be drawn partially transparent.
* @public
* @extensions
*/
export declare class SpriteLocation implements CanvasDecoration {
private _viewport?;
private _sprite?;
private _alpha?;
/** The current position of this sprite in view coordinates.
* @see [[CanvasDecoration.position]]
*/
readonly position: Point3d;
get isActive(): boolean;
/** Activate this SpriteLocation to show a Sprite at a location in a single ScreenViewport.
* This call does not display the Sprite. Rather, subsequent calls to [[decorate]] from will show the Sprite.
* This SpriteLocation remains active until [[deactivate]] is called.
* @param sprite The Sprite to draw at this SpriteLocation
* @param viewport The Viewport onto which the Sprite is drawn
* @param locationWorld The position, in world coordinates
* @param alpha Optional alpha for the Sprite. Must be a number between 0 (fully transparent) and 1 (fully opaque).
*/
activate(sprite: Sprite, viewport: ScreenViewport, locationWorld: XYAndZ, alpha?: number): void;
/** Turn this SpriteLocation off so it will no longer show. */
deactivate(): void;
/** Draw this sprite onto the supplied canvas.
* @see [[CanvasDecoration.drawDecoration]]
*/
drawDecoration(ctx: CanvasRenderingContext2D): void;
/** If this SpriteLocation is active and the supplied DecorateContext is for its Viewport, add the Sprite to decorations. */
decorate(context: DecorateContext): void;
}
//# sourceMappingURL=Sprites.d.ts.map