index.d.ts 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /// <reference path="./global.d.ts" />
  2. import type { AbstractRenderer } from '@pixi/core';
  3. import { Container } from '@pixi/display';
  4. import type { ExtensionMetadata } from '@pixi/core';
  5. import type { IDestroyOptions } from '@pixi/display';
  6. import type { IRendererOptionsAuto } from '@pixi/core';
  7. import type { Rectangle } from '@pixi/math';
  8. import type { Renderer } from '@pixi/core';
  9. export declare interface Application extends GlobalMixins.Application {
  10. }
  11. /**
  12. * Convenience class to create a new PIXI application.
  13. *
  14. * This class automatically creates the renderer, ticker and root container.
  15. * @example
  16. * // Create the application
  17. * const app = new PIXI.Application();
  18. *
  19. * // Add the view to the DOM
  20. * document.body.appendChild(app.view);
  21. *
  22. * // ex, add display objects
  23. * app.stage.addChild(PIXI.Sprite.from('something.png'));
  24. * @class
  25. * @memberof PIXI
  26. */
  27. export declare class Application {
  28. /** Collection of installed plugins. */
  29. static _plugins: IApplicationPlugin[];
  30. /**
  31. * The root display container that's rendered.
  32. * @member {PIXI.Container}
  33. */
  34. stage: Container;
  35. /**
  36. * WebGL renderer if available, otherwise CanvasRenderer.
  37. * @member {PIXI.Renderer|PIXI.CanvasRenderer}
  38. */
  39. renderer: Renderer | AbstractRenderer;
  40. /**
  41. * @param {PIXI.IApplicationOptions} [options] - The optional application and renderer parameters.
  42. * @param {boolean} [options.antialias=false] -
  43. * **WebGL Only.** Whether to enable anti-aliasing. This may affect performance.
  44. * @param {boolean} [options.autoDensity=false] -
  45. * Whether the CSS dimensions of the renderer's view should be resized automatically.
  46. * @param {boolean} [options.autoStart=true] - Automatically starts the rendering after the construction.
  47. * **Note**: Setting this parameter to false does NOT stop the shared ticker even if you set
  48. * `options.sharedTicker` to `true` in case that it is already started. Stop it by your own.
  49. * @param {number} [options.backgroundAlpha=1] -
  50. * Transparency of the background color, value from `0` (fully transparent) to `1` (fully opaque).
  51. * @param {number} [options.backgroundColor=0x000000] -
  52. * The background color used to clear the canvas. It accepts hex numbers (e.g. `0xff0000`).
  53. * @param {boolean} [options.clearBeforeRender=true] - Whether to clear the canvas before new render passes.
  54. * @param {PIXI.IRenderingContext} [options.context] - **WebGL Only.** User-provided WebGL rendering context object.
  55. * @param {boolean} [options.forceCanvas=false] -
  56. * Force using {@link PIXI.CanvasRenderer}, even if WebGL is available. This option only is available when
  57. * using **pixi.js-legacy** or **@pixi/canvas-renderer** packages, otherwise it is ignored.
  58. * @param {number} [options.height=600] - The height of the renderer's view.
  59. * @param {string} [options.powerPreference] -
  60. * **WebGL Only.** A hint indicating what configuration of GPU is suitable for the WebGL context,
  61. * can be `'default'`, `'high-performance'` or `'low-power'`.
  62. * Setting to `'high-performance'` will prioritize rendering performance over power consumption,
  63. * while setting to `'low-power'` will prioritize power saving over rendering performance.
  64. * @param {boolean} [options.premultipliedAlpha=true] -
  65. * **WebGL Only.** Whether the compositor will assume the drawing buffer contains colors with premultiplied alpha.
  66. * @param {boolean} [options.preserveDrawingBuffer=false] -
  67. * **WebGL Only.** Whether to enable drawing buffer preservation. If enabled, the drawing buffer will preserve
  68. * its value until cleared or overwritten. Enable this if you need to call `toDataUrl` on the WebGL context.
  69. * @param {Window|HTMLElement} [options.resizeTo] - Element to automatically resize stage to.
  70. * @param {number} [options.resolution=PIXI.settings.RESOLUTION] -
  71. * The resolution / device pixel ratio of the renderer.
  72. * @param {boolean} [options.sharedLoader=false] - `true` to use PIXI.Loader.shared, `false` to create new Loader.
  73. * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.Ticker.shared, `false` to create new ticker.
  74. * If set to `false`, you cannot register a handler to occur before anything that runs on the shared ticker.
  75. * The system ticker will always run before both the shared ticker and the app ticker.
  76. * @param {boolean} [options.transparent] -
  77. * **Deprecated since 6.0.0, Use `backgroundAlpha` instead.** \
  78. * `true` sets `backgroundAlpha` to `0`, `false` sets `backgroundAlpha` to `1`.
  79. * @param {boolean|'notMultiplied'} [options.useContextAlpha=true] -
  80. * Pass-through value for canvas' context attribute `alpha`. This option is for cases where the
  81. * canvas needs to be opaque, possibly for performance reasons on some older devices.
  82. * If you want to set transparency, please use `backgroundAlpha`. \
  83. * **WebGL Only:** When set to `'notMultiplied'`, the canvas' context attribute `alpha` will be
  84. * set to `true` and `premultipliedAlpha` will be to `false`.
  85. * @param {HTMLCanvasElement} [options.view=null] -
  86. * The canvas to use as the view. If omitted, a new canvas will be created.
  87. * @param {number} [options.width=800] - The width of the renderer's view.
  88. */
  89. constructor(options?: IApplicationOptions);
  90. /**
  91. * Use the {@link PIXI.extensions.add} API to register plugins.
  92. * @deprecated since 6.5.0
  93. * @static
  94. * @param {PIXI.IApplicationPlugin} plugin - Plugin being installed
  95. */
  96. static registerPlugin(plugin: IApplicationPlugin): void;
  97. /** Render the current stage. */
  98. render(): void;
  99. /**
  100. * Reference to the renderer's canvas element.
  101. * @member {HTMLCanvasElement}
  102. * @readonly
  103. */
  104. get view(): HTMLCanvasElement;
  105. /**
  106. * Reference to the renderer's screen rectangle. Its safe to use as `filterArea` or `hitArea` for the whole screen.
  107. * @member {PIXI.Rectangle}
  108. * @readonly
  109. */
  110. get screen(): Rectangle;
  111. /**
  112. * Destroy and don't use after this.
  113. * @param {boolean} [removeView=false] - Automatically remove canvas from DOM.
  114. * @param {object|boolean} [stageOptions] - Options parameter. A boolean will act as if all options
  115. * have been set to that value
  116. * @param {boolean} [stageOptions.children=false] - if set to true, all the children will have their destroy
  117. * method called as well. 'stageOptions' will be passed on to those calls.
  118. * @param {boolean} [stageOptions.texture=false] - Only used for child Sprites if stageOptions.children is set
  119. * to true. Should it destroy the texture of the child sprite
  120. * @param {boolean} [stageOptions.baseTexture=false] - Only used for child Sprites if stageOptions.children is set
  121. * to true. Should it destroy the base texture of the child sprite
  122. */
  123. destroy(removeView?: boolean, stageOptions?: IDestroyOptions | boolean): void;
  124. }
  125. /**
  126. * Application options supplied to constructor.
  127. * @memberof PIXI
  128. */
  129. export declare interface IApplicationOptions extends IRendererOptionsAuto, GlobalMixins.IApplicationOptions {
  130. }
  131. /**
  132. * Any plugin that's usable for Application should contain these methods.
  133. * @memberof PIXI
  134. */
  135. export declare interface IApplicationPlugin {
  136. /**
  137. * Called when Application is constructed, scoped to Application instance.
  138. * Passes in `options` as the only argument, which are Application constructor options.
  139. * @param {object} options - Application options.
  140. */
  141. init(options: IApplicationOptions): void;
  142. /** Called when destroying Application, scoped to Application instance. */
  143. destroy(): void;
  144. }
  145. declare type ResizeableRenderer = Pick<Renderer, 'resize'>;
  146. /**
  147. * Middleware for for Application's resize functionality
  148. * @private
  149. * @class
  150. */
  151. export declare class ResizePlugin {
  152. /** @ignore */
  153. static extension: ExtensionMetadata;
  154. static resizeTo: Window | HTMLElement;
  155. static resize: () => void;
  156. static renderer: ResizeableRenderer;
  157. static queueResize: () => void;
  158. private static _resizeId;
  159. private static _resizeTo;
  160. private static cancelResize;
  161. /**
  162. * Initialize the plugin with scope of application instance
  163. * @static
  164. * @private
  165. * @param {object} [options] - See application options
  166. */
  167. static init(options?: IApplicationOptions): void;
  168. /**
  169. * Clean up the ticker, scoped to application
  170. * @static
  171. * @private
  172. */
  173. static destroy(): void;
  174. }
  175. export { }