Skip to content

Commit 98f97f1

Browse files
committed
Add alpha support for circular progress colors
Introduces `barAlpha`, `trackAlpha`, and `centerAlpha` options to CircularProgress, allowing control over the alpha (opacity) of bar, track, and center colors. Updates documentation, type definitions, and rendering logic to support these new properties.
1 parent bdf4fe3 commit 98f97f1

File tree

4 files changed

+76
-13
lines changed

4 files changed

+76
-13
lines changed

docs/docs/shape-circularprogress.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,13 @@ var game = new Phaser.Game(config);
9696
### Create instance
9797

9898
```javascript
99-
var circularProgress = scene.add.rexCircularProgress(x, y, radius, barColor, value, {
99+
var circularProgress = scene.add.rexCircularProgress(x, y, radius, barColor, value, {
100+
barAlpha: 1,
100101
trackColor: undefined,
102+
trackAlpha: 1,
101103
centerColor: undefined,
104+
centerAlpha: 1,
105+
102106
thickness: 0.2,
103107
startAngle: Phaser.Math.DegToRad(270),
104108
anticlockwise: false,
@@ -122,8 +126,12 @@ var circularProgress = scene.add.rexCircularProgress({
122126
radius: 1,
123127
124128
barColor: undefined,
129+
barAlpha: 1,
125130
trackColor: undefined,
131+
trackAlpha: 1,
126132
centerColor: undefined,
133+
centerAlpha: 1,
134+
127135
thickness: 0.2,
128136
startAngle: Phaser.Math.DegToRad(270),
129137
anticlockwise: false,
@@ -141,9 +149,9 @@ var circularProgress = scene.add.rexCircularProgress({
141149

142150
- `x`, `y` : Position of this object.
143151
- `radius` : Radius of this circle. Size will be `(radius*2, radius*2)`.
144-
- `barColor` : Color of circular bar, in number or css string value.
145-
- `trackColor` : Color of circular track, in number or css string value.
146-
- `centerColor` : Color of center circle, in number or css string value.
152+
- `barColor`, `barAlpha` : Color/alpha of circular bar, in number or css string value.
153+
- `trackColor`, `trackAlpha` : Color/alpha of circular track, in number or css string value.
154+
- `centerColor`, `centerAlpha` : Color/alpha of center circle, in number or css string value.
147155
- `thickness` : `0` ~ `1`, thickness of circular bar. Default value is `0.2` (`0.2*radius`)
148156
- `startAngle` : Start angle of circular bar, in radians. Default value is 270 degrees.
149157
- `anticlockwise` : Set `true` to put anticlockwise circular bar. Default value is `false`.

plugins/gameobjects/shape/circularprogress/CircularProgress.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ declare namespace CircularProgress {
1616
radius?: number,
1717

1818
barColor?: string | number,
19+
barAlpha?: number,
1920
trackColor?: string | number,
21+
trackAlpha?: number,
2022
centerColor?: string | number,
23+
centerAlpha?: number,
2124
thickness?: number,
2225
startAngle?: number,
2326
anticlockwise?: boolean,

plugins/gameobjects/shape/circularprogress/CircularProgress.js

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const DefaultStartAngle = Phaser.Math.DegToRad(270);
1010

1111
class CircularProgress extends ProgressBase(BaseShapes) {
1212
constructor(scene, x, y, radius, barColor, value, config) {
13+
var barAlpha;
14+
var trackColor, trackAlpha;
15+
var centerColor, centerAlpha;
1316
if (IsPlainObject(x)) {
1417
config = x;
1518
x = GetValue(config, 'x', 0);
@@ -19,6 +22,12 @@ class CircularProgress extends ProgressBase(BaseShapes) {
1922
value = GetValue(config, 'value', 0);
2023
}
2124

25+
barAlpha = GetValue(config, 'barAlpha', 1);
26+
trackColor = GetValue(config, 'trackColor', undefined);
27+
trackAlpha = GetValue(config, 'trackAlpha', 1);
28+
centerColor = GetValue(config, 'centerColor', undefined);
29+
centerAlpha = GetValue(config, 'centerAlpha', 1);
30+
2231
if (radius === undefined) { radius = 1; }
2332

2433
var width = radius * 2;
@@ -28,9 +37,9 @@ class CircularProgress extends ProgressBase(BaseShapes) {
2837
this.bootProgressBase(config);
2938

3039
this.setRadius(radius);
31-
this.setTrackColor(GetValue(config, 'trackColor', undefined));
32-
this.setBarColor(barColor);
33-
this.setCenterColor(GetValue(config, 'centerColor', undefined));
40+
this.setTrackColor(trackColor, trackAlpha);
41+
this.setBarColor(barColor, barAlpha);
42+
this.setCenterColor(centerColor, centerAlpha);
3443

3544
this.setThickness(GetValue(config, 'thickness', 0.2));
3645
this.setStartAngle(GetValue(config, 'startAngle', DefaultStartAngle));
@@ -79,8 +88,23 @@ class CircularProgress extends ProgressBase(BaseShapes) {
7988
this._trackColor = value;
8089
}
8190

82-
setTrackColor(color) {
91+
get trackAlpha() {
92+
return this._trackColor;
93+
}
94+
95+
set trackAlpha(value) {
96+
this.dirty = this.dirty || (this._trackAlpha != value);
97+
this._trackAlpha = value;
98+
}
99+
100+
101+
setTrackColor(color, alpha) {
102+
if (alpha === undefined) {
103+
alpha = 1;
104+
}
105+
83106
this.trackColor = color;
107+
this.trackAlpha = alpha;
84108
return this;
85109
}
86110

@@ -93,8 +117,22 @@ class CircularProgress extends ProgressBase(BaseShapes) {
93117
this._barColor = value;
94118
}
95119

96-
setBarColor(color) {
120+
get barAlpha() {
121+
return this._barAlpha;
122+
}
123+
124+
set barAlpha(value) {
125+
this.dirty = this.dirty || (this._barAlpha != value);
126+
this._barAlpha = value;
127+
}
128+
129+
setBarColor(color, alpha) {
130+
if (alpha === undefined) {
131+
alpha = 1;
132+
}
133+
97134
this.barColor = color;
135+
this.barAlpha = alpha;
98136
return this;
99137
}
100138

@@ -153,8 +191,22 @@ class CircularProgress extends ProgressBase(BaseShapes) {
153191
this._centerColor = value;
154192
}
155193

156-
setCenterColor(color) {
194+
get centerAlpha() {
195+
return this._centerAlpha;
196+
}
197+
198+
set centerAlpha(value) {
199+
this.dirty = this.dirty || (this._centerAlpha != value);
200+
this._centerAlpha = value;
201+
}
202+
203+
setCenterColor(color, alpha) {
204+
if (alpha === undefined) {
205+
alpha = 1;
206+
}
207+
157208
this.centerColor = color;
209+
this.centerAlpha = alpha;
158210
return this;
159211
}
160212

plugins/gameobjects/shape/circularprogress/ShapesUpdateMethods.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default {
4848
// Track shape
4949
var trackShape = this.getShape('track');
5050
if ((this.trackColor != null) && (this.thickness > 0)) {
51-
trackShape.fillStyle(this.trackColor);
51+
trackShape.fillStyle(this.trackColor, this.trackAlpha);
5252
FillArc(trackShape, x, x, barOuterRadius, barInnerRadius, 0, 360, false);
5353
} else {
5454
trackShape.reset();
@@ -69,7 +69,7 @@ export default {
6969
endAngle = deltaAngle + startAngle;
7070
}
7171

72-
barShape.fillStyle(this.barColor);
72+
barShape.fillStyle(this.barColor, this.barAlpha);
7373
FillArc(barShape, x, x, barOuterRadius + 1, barInnerRadius - 1, startAngle, endAngle, false);
7474

7575
} else {
@@ -82,7 +82,7 @@ export default {
8282
centerShape
8383
.setCenterPosition(x, x)
8484
.setRadius(barInnerRadius)
85-
.fillStyle(this.centerColor);
85+
.fillStyle(this.centerColor, this.centerAlpha);
8686
} else {
8787
centerShape.reset();
8888
}

0 commit comments

Comments
 (0)