This repository was archived by the owner on Jul 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 393
Expand file tree
/
Copy pathGradientGlowFilter.ts
More file actions
232 lines (212 loc) · 7.18 KB
/
Copy pathGradientGlowFilter.ts
File metadata and controls
232 lines (212 loc) · 7.18 KB
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/**
* Copyright 2014 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Class: GradientGlowFilter
module Shumway.AVMX.AS.flash.filters {
import Rectangle = flash.geom.Rectangle;
import axCoerceString = Shumway.AVMX.axCoerceString;
export class GradientGlowFilter extends flash.filters.BitmapFilter {
static axClass: typeof GradientGlowFilter;
static classInitializer: any = null;
public static FromUntyped(obj: any) {
// obj.colors is an array of RGBA colors.
// The RGB and alpha parts must be separated into colors and alphas arrays.
var colors: number[] = [];
var alphas: number[] = [];
for (var i = 0; i < obj.colors.length; i++) {
var color = obj.colors[i];
colors.push(color >>> 8);
alphas.push((color & 0xff) / 0xff);
}
// type is derived from obj.onTop and obj.innerShadow
// obj.onTop true: type is FULL
// obj.inner true: type is INNER
// neither true: type is OUTER
var type: string = flash.filters.BitmapFilterType.OUTER;
if (!!obj.onTop) {
type = flash.filters.BitmapFilterType.FULL;
} else if (!!obj.inner) {
type = flash.filters.BitmapFilterType.INNER;
}
// obj.angle is represented in radians, the api needs degrees
var angle: number = obj.angle * 180 / Math.PI;
return new this.sec.flash.filters.GradientGlowFilter(
obj.distance,
angle,
// Boxing these is obviously not ideal, but everything else is just annoying.
this.sec.createArrayUnsafe(colors),
this.sec.createArrayUnsafe(alphas),
this.sec.createArrayUnsafe(obj.ratios),
obj.blurX,
obj.blurY,
obj.strength,
obj.quality,
type,
obj.knockout
);
}
constructor(distance: number = 4, angle: number = 45, colors: ASArray = null,
alphas: ASArray = null, ratios: ASArray = null, blurX: number = 4, blurY: number = 4,
strength: number = 1, quality: number /*int*/ = 1, type: string = "inner",
knockout: boolean = false)
{
super();
this.distance = distance;
this.angle = angle;
GradientArrays.sanitize(colors ? colors.value : null, alphas ? alphas.value : null,
ratios ? ratios.value : null);
this._colors = GradientArrays.colors;
this._alphas = GradientArrays.alphas;
this._ratios = GradientArrays.ratios;
this.blurX = blurX;
this.blurY = blurY;
this.strength = strength;
this.quality = quality;
this.type = type;
this.knockout = knockout;
}
_updateFilterBounds(bounds: Rectangle) {
if (this.type !== BitmapFilterType.INNER) {
BitmapFilter._updateBlurBounds(bounds, this._blurX, this._blurY, this._quality);
if (this._distance !== 0) {
var a: number = this._angle * Math.PI / 180;
bounds.x += Math.floor(Math.cos(a) * this._distance);
bounds.y += Math.floor(Math.sin(a) * this._distance);
if (bounds.left > 0) { bounds.left = 0; }
if (bounds.top > 0) { bounds.top = 0; }
}
}
}
private _distance: number;
private _angle: number;
private _colors: any [];
private _alphas: any [];
private _ratios: any [];
private _blurX: number;
private _blurY: number;
private _knockout: boolean;
private _quality: number /*int*/;
private _strength: number;
private _type: string;
get distance(): number {
return this._distance;
}
set distance(value: number) {
this._distance = +value;
}
get angle(): number {
return this._angle;
}
set angle(value: number) {
this._angle = +value % 360;
}
get colors(): ASArray {
return this.sec.createArrayUnsafe(this._colors.concat());
}
set colors(value: ASArray) {
if (isNullOrUndefined(value)) {
this.sec.throwError("TypeError", Errors.NullPointerError, "colors");
}
this._colors = GradientArrays.sanitizeColors(value.value);
var len: number = this._colors.length;
this._alphas = GradientArrays.sanitizeAlphas(this._alphas, len, len);
this._ratios = GradientArrays.sanitizeRatios(this._ratios, len, len);
}
get alphas(): ASArray {
return this.sec.createArrayUnsafe(this._alphas.concat());
}
set alphas(value: ASArray) {
if (isNullOrUndefined(value)) {
this.sec.throwError("TypeError", Errors.NullPointerError, "alphas");
}
GradientArrays.sanitize(this._colors, value.value, this._ratios);
this._colors = GradientArrays.colors;
this._alphas = GradientArrays.alphas;
this._ratios = GradientArrays.ratios;
}
get ratios(): ASArray {
return this.sec.createArrayUnsafe(this._ratios.concat());
}
set ratios(value_: ASArray) {
if (isNullOrUndefined(value_)) {
this.sec.throwError("TypeError", Errors.NullPointerError, "ratios");
}
GradientArrays.sanitize(this._colors, this._alphas, value_.value);
this._colors = GradientArrays.colors;
this._alphas = GradientArrays.alphas;
this._ratios = GradientArrays.ratios;
}
get blurX(): number {
return this._blurX;
}
set blurX(value: number) {
this._blurX = NumberUtilities.clamp(+value, 0, 255);
}
get blurY(): number {
return this._blurY;
}
set blurY(value: number) {
this._blurY = NumberUtilities.clamp(+value, 0, 255);
}
get knockout(): boolean {
return this._knockout;
}
set knockout(value: boolean) {
this._knockout = !!value;
}
get quality(): number /*int*/ {
return this._quality;
}
set quality(value: number /*int*/) {
this._quality = NumberUtilities.clamp(value | 0, 0, 15);
}
get strength(): number {
return this._strength;
}
set strength(value: number) {
this._strength = NumberUtilities.clamp(+value, 0, 255);
}
get type(): string {
return this._type;
}
set type(value: string) {
value = axCoerceString(value);
if (value === null) {
this.sec.throwError("TypeError", Errors.NullPointerError, "type");
} else {
if (value === BitmapFilterType.INNER || value === BitmapFilterType.OUTER) {
this._type = value;
} else {
this._type = BitmapFilterType.FULL;
}
}
}
clone(): BitmapFilter {
return new this.sec.flash.filters.GradientGlowFilter(
this._distance,
this._angle,
this.colors,
this.alphas,
this.ratios,
this._blurX,
this._blurY,
this._strength,
this._quality,
this._type,
this._knockout
);
}
}
}