pixi.js
Version:
PixiJS — The HTML5 Creation Engine =============
1 lines • 1.73 kB
Source Map (JSON)
{"version":3,"file":"viewportFromFrame.mjs","sources":["../../../../../src/rendering/renderers/shared/renderTarget/viewportFromFrame.ts"],"sourcesContent":["import { Rectangle } from '../../../../maths/shapes/Rectangle';\n\nimport type { TextureSource } from '../texture/sources/TextureSource';\n\nconst fullFrame = new Rectangle(0, 0, 1, 1);\n\n/**\n * Takes a Texture source and a normalised frame\n * and returns a viewport for that frame.\n * @param viewport - The viewport rectangle to set.\n * @param source - The source to get the pixel width and height from.\n * @param frame - The frame to get the viewport from.\n * @returns the passed in viewport.\n */\nexport function viewportFromFrame(\n viewport: Rectangle,\n source: TextureSource,\n frame?: Rectangle\n)\n{\n frame ||= fullFrame;\n\n const pixelWidth = source.pixelWidth;\n const pixelHeight = source.pixelHeight;\n\n viewport.x = (frame.x * pixelWidth) | 0;\n viewport.y = (frame.y * pixelHeight) | 0;\n viewport.width = (frame.width * pixelWidth) | 0;\n viewport.height = (frame.height * pixelHeight) | 0;\n\n return viewport;\n}\n"],"names":[],"mappings":";;;AAIA,MAAM,YAAY,IAAI,SAAA,CAAU,CAAG,EAAA,CAAA,EAAG,GAAG,CAAC,CAAA,CAAA;AAU1B,SAAA,iBAAA,CACZ,QACA,EAAA,MAAA,EACA,KAEJ,EAAA;AACI,EAAU,KAAA,KAAA,KAAA,GAAA,SAAA,CAAA,CAAA;AAEV,EAAA,MAAM,aAAa,MAAO,CAAA,UAAA,CAAA;AAC1B,EAAA,MAAM,cAAc,MAAO,CAAA,WAAA,CAAA;AAE3B,EAAS,QAAA,CAAA,CAAA,GAAK,KAAM,CAAA,CAAA,GAAI,UAAc,GAAA,CAAA,CAAA;AACtC,EAAS,QAAA,CAAA,CAAA,GAAK,KAAM,CAAA,CAAA,GAAI,WAAe,GAAA,CAAA,CAAA;AACvC,EAAS,QAAA,CAAA,KAAA,GAAS,KAAM,CAAA,KAAA,GAAQ,UAAc,GAAA,CAAA,CAAA;AAC9C,EAAS,QAAA,CAAA,MAAA,GAAU,KAAM,CAAA,MAAA,GAAS,WAAe,GAAA,CAAA,CAAA;AAEjD,EAAO,OAAA,QAAA,CAAA;AACX;;;;"}