UNPKG

malwoden

Version:

![alt text](./coverage/badge-lines.svg) ![alt text](./coverage/badge-statements.svg) ![alt text](./coverage/badge-functions.svg) ![alt text](./coverage/badge-branches.svg)

96 lines (95 loc) 2.88 kB
import { Vector2 } from "../struct"; export interface MouseContextCallback { (pos: MouseHandlerEvent): void; } export interface MouseHandlerEvent { x: number; y: number; button: number; type: "mousedown" | "mouseup"; } /** * Represents a global mouse. Will likely only create one per app. * * You can bind/switch MouseContexts to the MouseHandler * to change input 'modes'. */ export declare class MouseHandler { private x; private y; private context?; private _isDown; /** Creates a new Mouse Handler */ constructor(); private onMouseDownEvent; private onMouseUpEvent; private onMouseUpdateEvent; /** * Returns true if the given mouse button is down. * @param mouseButton number - Default 0 for left click. */ isMouseDown(mouseButton?: number): boolean; /** * Gets the current position of the mouse * @returns Vector2 */ getPos(): Vector2; /** * Sets the active mouse context * @param context MouseContext * @returns this */ setContext(context: MouseContext): this; /** * Clears the active mouse context * @returns this */ clearContext(): this; } /** * MouseContext represents a single 'mode' of the game's mouse controls. * For instance, you might have one context to use for the overworld, another for * menus, another for inventory, etc. * * You can set the active context through a MouseHandler's setContext(ctx) * and clearContext() methods. * * * You can register multiple callbacks for onUp/onDown. */ export declare class MouseContext { private _onDown; private _onUp; /** * Registers a callback for a mousedown event. * @param callback - The function to call on mousedown * @return this */ onMouseDown(callback: MouseContextCallback): this; /** * Registers a callback for a mouseup event. * @param callback - The function to call on mousedown * @return this */ onMouseUp(callback: MouseContextCallback): this; /** * Clears a registered function for mousedown. If no callback is provided will clear all. * @param callback - The callback to clear. */ clearMouseDown(callback?: MouseContextCallback): this; /** * Clears a registered function for mouseup. If no callback is provided will clear all. * @param callback - The callback to clear. */ clearMouseUp(callback?: MouseContextCallback): this; /** * Invokes a registered callback for mousedown * @param e MouseHandlerEvent */ callOnMouseDown(e: MouseHandlerEvent): void; /** * Invokes a registered callback for mouseup * @param e MouseHandlerEvent */ callOnMouseUp(e: MouseHandlerEvent): void; }