forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSS3Filters.js
180 lines (147 loc) · 6.13 KB
/
CSS3Filters.js
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
/**
* Phaser - Display - CSS3Filters
*
* Allows for easy addition and modification of CSS3 Filters on DOM objects (typically the Game.Stage.canvas).
*/
Phaser.Plugins.CSS3Filters = function (parent) {
this.parent = parent;
this._blur = 0;
this._grayscale = 0;
this._sepia = 0;
this._brightness = 0;
this._contrast = 0;
this._hueRotate = 0;
this._invert = 0;
this._opacity = 0;
this._saturate = 0;
};
Phaser.Plugins.CSS3Filters.prototype = {
setFilter: function (local, prefix, value, unit) {
this[local] = value;
if (this.parent)
{
this.parent.style['-webkit-filter'] = prefix + '(' + value + unit + ')';
}
}
};
Object.defineProperty(Phaser.Plugins.CSS3Filters.prototype, "blur", {
get: function () {
return this._blur;
},
/**
* Applies a Gaussian blur to the DOM element. The value of 'radius' defines the value of the standard deviation to the Gaussian function,
* or how many pixels on the screen blend into each other, so a larger value will create more blur.
* If no parameter is provided, then a value 0 is used. The parameter is specified as a CSS length, but does not accept percentage values.
*/
set: function (radius) {
this.setFilter('_blur', 'blur', radius, 'px');
}
});
Object.defineProperty(Phaser.Plugins.CSS3Filters.prototype, "grayscale", {
get: function () {
return this._grayscale;
},
/**
* Converts the input image to grayscale. The value of 'amount' defines the proportion of the conversion.
* A value of 100% is completely grayscale. A value of 0% leaves the input unchanged.
* Values between 0% and 100% are linear multipliers on the effect. If the 'amount' parameter is missing, a value of 100% is used.
*/
set: function (amount) {
this.setFilter('_grayscale', 'grayscale', amount, '%');
}
});
Object.defineProperty(Phaser.Plugins.CSS3Filters.prototype, "sepia", {
get: function () {
return this._sepia;
},
/**
* Converts the input image to sepia. The value of 'amount' defines the proportion of the conversion.
* A value of 100% is completely sepia. A value of 0 leaves the input unchanged.
* Values between 0% and 100% are linear multipliers on the effect. If the 'amount' parameter is missing, a value of 100% is used.
*/
set: function (amount) {
this.setFilter('_sepia', 'sepia', amount, '%');
}
});
Object.defineProperty(Phaser.Plugins.CSS3Filters.prototype, "brightness", {
get: function () {
return this._brightness;
},
/**
* Applies a linear multiplier to input image, making it appear more or less bright.
* A value of 0% will create an image that is completely black. A value of 100% leaves the input unchanged.
* Other values are linear multipliers on the effect. Values of an amount over 100% are allowed, providing brighter results.
* If the 'amount' parameter is missing, a value of 100% is used.
*/
set: function (amount) {
this.setFilter('_brightness', 'brightness', amount, '%');
}
});
Object.defineProperty(Phaser.Plugins.CSS3Filters.prototype, "contrast", {
get: function () {
return this._contrast;
},
/**
* Adjusts the contrast of the input. A value of 0% will create an image that is completely black.
* A value of 100% leaves the input unchanged. Values of amount over 100% are allowed, providing results with less contrast.
* If the 'amount' parameter is missing, a value of 100% is used.
*/
set: function (amount) {
this.setFilter('_contrast', 'contrast', amount, '%');
}
});
Object.defineProperty(Phaser.Plugins.CSS3Filters.prototype, "hueRotate", {
get: function () {
return this._hueRotate;
},
/**
* Applies a hue rotation on the input image. The value of 'angle' defines the number of degrees around the color circle
* the input samples will be adjusted. A value of 0deg leaves the input unchanged. If the 'angle' parameter is missing,
* a value of 0deg is used. Maximum value is 360deg.
*/
set: function (angle) {
this.setFilter('_hueRotate', 'hue-rotate', angle, 'deg');
}
});
Object.defineProperty(Phaser.Plugins.CSS3Filters.prototype, "invert", {
get: function () {
return this._invert;
},
/**
* Inverts the samples in the input image. The value of 'amount' defines the proportion of the conversion.
* A value of 100% is completely inverted. A value of 0% leaves the input unchanged.
* Values between 0% and 100% are linear multipliers on the effect. If the 'amount' parameter is missing, a value of 100% is used.
*/
set: function (value) {
this.setFilter('_invert', 'invert', value, '%');
}
});
Object.defineProperty(Phaser.Plugins.CSS3Filters.prototype, "opacity", {
get: function () {
return this._opacity;
},
/**
* Applies transparency to the samples in the input image. The value of 'amount' defines the proportion of the conversion.
* A value of 0% is completely transparent. A value of 100% leaves the input unchanged.
* Values between 0% and 100% are linear multipliers on the effect. This is equivalent to multiplying the input image samples by amount.
* If the 'amount' parameter is missing, a value of 100% is used.
* This function is similar to the more established opacity property; the difference is that with filters, some browsers provide hardware acceleration for better performance.
*/
set: function (value) {
this.setFilter('_opacity', 'opacity', value, '%');
}
});
Object.defineProperty(Phaser.Plugins.CSS3Filters.prototype, "saturate", {
get: function () {
return this._saturate;
},
/**
* Saturates the input image. The value of 'amount' defines the proportion of the conversion.
* A value of 0% is completely un-saturated. A value of 100% leaves the input unchanged.
* Other values are linear multipliers on the effect. Values of amount over 100% are allowed, providing super-saturated results.
* If the 'amount' parameter is missing, a value of 100% is used.
*/
set: function (value) {
this.setFilter('_saturate', 'saturate', value, '%');
}
});