- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
import { MASK_TYPES } from '@pixi/constants';
import { settings } from '@pixi/settings';
import type { ISpriteMaskFilter } from '@pixi/core';
import type { COLOR_MASK_BITS, MSAA_QUALITY } from '@pixi/constants';
import type { Rectangle, Matrix } from '@pixi/math';
import type { IFilterTarget } from '../filters/IFilterTarget';
import type { Renderer } from '../Renderer';
export interface IMaskTarget extends IFilterTarget
{
renderable: boolean;
isSprite?: boolean;
worldTransform: Matrix;
isFastRect?(): boolean;
getBounds(skipUpdate?: boolean, rect?: Rectangle): Rectangle;
render(renderer: Renderer): void;
}
/**
* Component for masked elements.
*
* Holds mask mode and temporary data about current mask.
* @memberof PIXI
*/
export class MaskData
{
/** Mask type */
public type: MASK_TYPES;
/**
* Whether we know the mask type beforehand
* @default true
*/
public autoDetect: boolean;
/**
* Which element we use to mask
* @member {PIXI.DisplayObject}
*/
public maskObject: IMaskTarget;
/** Whether it belongs to MaskSystem pool */
public pooled: boolean;
/** Indicator of the type (always true for {@link MaskData} objects) */
public isMaskData: boolean;// webdoc crashes if the type is true because reasons... (will fix)
/**
* Resolution of the sprite mask filter.
* If set to `null` or `0`, the resolution of the current render target is used.
* @default null
*/
public resolution: number;
/**
* Number of samples of the sprite mask filter.
* If set to `null`, the sample count of the current render target is used.
* @default PIXI.settings.FILTER_MULTISAMPLE
*/
public multisample: MSAA_QUALITY;
/** If enabled is true the mask is applied, if false it will not. */
public enabled: boolean;
/** Color mask. */
public colorMask: COLOR_MASK_BITS;
/**
* The sprite mask filter wrapped in an array.
* @private
*/
_filters: ISpriteMaskFilter[];
/**
* Stencil counter above the mask in stack
* @private
*/
_stencilCounter: number;
/**
* Scissor counter above the mask in stack
* @private
*/
_scissorCounter: number;
/**
* Scissor operation above the mask in stack.
* Null if _scissorCounter is zero, rectangle instance if positive.
* @private
*/
_scissorRect: Rectangle;
/**
* pre-computed scissor rect
* does become _scissorRect when mask is actually pushed
* @private
*/
_scissorRectLocal: Rectangle;
/**
* pre-computed color mask
* @private
*/
_colorMask: number;
/**
* Targeted element. Temporary variable set by MaskSystem
* @member {PIXI.DisplayObject}
* @private
*/
_target: IMaskTarget;
/**
* Create MaskData
* @param {PIXI.DisplayObject} [maskObject=null] - object that describes the mask
*/
constructor(maskObject: IMaskTarget = null)
{
this.type = MASK_TYPES.NONE;
this.autoDetect = true;
this.maskObject = maskObject || null;
this.pooled = false;
this.isMaskData = true;
this.resolution = null;
this.multisample = settings.FILTER_MULTISAMPLE;
this.enabled = true;
this.colorMask = 0xf;
this._filters = null;
this._stencilCounter = 0;
this._scissorCounter = 0;
this._scissorRect = null;
this._scissorRectLocal = null;
this._colorMask = 0xf;
this._target = null;
}
/**
* The sprite mask filter.
* If set to `null`, the default sprite mask filter is used.
* @default null
*/
get filter(): ISpriteMaskFilter
{
return this._filters ? this._filters[0] : null;
}
set filter(value: ISpriteMaskFilter)
{
if (value)
{
if (this._filters)
{
this._filters[0] = value;
}
else
{
this._filters = [value];
}
}
else
{
this._filters = null;
}
}
/** Resets the mask data after popMask(). */
reset(): void
{
if (this.pooled)
{
this.maskObject = null;
this.type = MASK_TYPES.NONE;
this.autoDetect = true;
}
this._target = null;
this._scissorRectLocal = null;
}
/**
* Copies counters from maskData above, called from pushMask().
* @param maskAbove
*/
copyCountersOrReset(maskAbove?: MaskData): void
{
if (maskAbove)
{
this._stencilCounter = maskAbove._stencilCounter;
this._scissorCounter = maskAbove._scissorCounter;
this._scissorRect = maskAbove._scissorRect;
}
else
{
this._stencilCounter = 0;
this._scissorCounter = 0;
this._scissorRect = null;
}
}
}