Skip to content

Commit 2e378b6

Browse files
committed
Apply the dropShadow
1 parent c228dd5 commit 2e378b6

1 file changed

Lines changed: 50 additions & 39 deletions

File tree

src/gameobjects/bitmaptext/static/BitmapTextWebGLRenderer.js

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@
66

77
var Utils = require('../../../renderer/webgl/Utils');
88

9+
function BatchChar (pipeline, src, char, glyph, offsetX, offsetY, calcMatrix, roundPixels, tintTL, tintTR, tintBL, tintBR, tintEffect, texture, textureUnit)
10+
{
11+
var x = (char.x - src.displayOriginX) + offsetX;
12+
var y = (char.y - src.displayOriginY) + offsetY;
13+
14+
var xw = x + char.w;
15+
var yh = y + char.h;
16+
17+
var tx0 = calcMatrix.getXRound(x, y, roundPixels);
18+
var ty0 = calcMatrix.getYRound(x, y, roundPixels);
19+
20+
var tx1 = calcMatrix.getXRound(x, yh, roundPixels);
21+
var ty1 = calcMatrix.getYRound(x, yh, roundPixels);
22+
23+
var tx2 = calcMatrix.getXRound(xw, yh, roundPixels);
24+
var ty2 = calcMatrix.getYRound(xw, yh, roundPixels);
25+
26+
var tx3 = calcMatrix.getXRound(xw, y, roundPixels);
27+
var ty3 = calcMatrix.getYRound(xw, y, roundPixels);
28+
29+
pipeline.batchQuad(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, glyph.u0, glyph.v0, glyph.u1, glyph.v1, tintTL, tintTR, tintBL, tintBR, tintEffect, texture, textureUnit);
30+
}
31+
932
/**
1033
* Renders this Game Object with the WebGL Renderer to the given Camera.
1134
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
@@ -68,13 +91,28 @@ var BitmapTextWebGLRenderer = function (renderer, src, interpolationPercentage,
6891

6992
var cameraAlpha = camera.alpha;
7093

94+
var charColors = src.charColors;
95+
7196
var tintEffect = (src._isTinted && src.tintFill);
7297

7398
var tintTL = Utils.getTintAppendFloatAlpha(src._tintTL, cameraAlpha * src._alphaTL);
7499
var tintTR = Utils.getTintAppendFloatAlpha(src._tintTR, cameraAlpha * src._alphaTR);
75100
var tintBL = Utils.getTintAppendFloatAlpha(src._tintBL, cameraAlpha * src._alphaBL);
76101
var tintBR = Utils.getTintAppendFloatAlpha(src._tintBR, cameraAlpha * src._alphaBR);
77102

103+
var dropShadowX = src.dropShadowX;
104+
var dropShadowY = src.dropShadowY;
105+
106+
var dropShadow = (dropShadowX !== 0 || dropShadowY !== 0);
107+
108+
if (dropShadow)
109+
{
110+
var blackTL = Utils.getTintAppendFloatAlpha(src.dropShadowColor, cameraAlpha * src.dropShadowAlpha * src._alphaTL);
111+
var blackTR = Utils.getTintAppendFloatAlpha(src.dropShadowColor, cameraAlpha * src.dropShadowAlpha * src._alphaTR);
112+
var blackBL = Utils.getTintAppendFloatAlpha(src.dropShadowColor, cameraAlpha * src.dropShadowAlpha * src._alphaBL);
113+
var blackBR = Utils.getTintAppendFloatAlpha(src.dropShadowColor, cameraAlpha * src.dropShadowAlpha * src._alphaBR);
114+
}
115+
78116
var texture = src.frame.glTexture;
79117
var textureUnit = pipeline.setGameObject(src);
80118

@@ -93,56 +131,29 @@ var BitmapTextWebGLRenderer = function (renderer, src, interpolationPercentage,
93131
continue;
94132
}
95133

96-
var x = char.x - src.displayOriginX;
97-
var y = char.y - src.displayOriginY;
98-
99-
var xw = x + char.w;
100-
var yh = y + char.h;
101-
102-
var tx0 = calcMatrix.getX(x, y);
103-
var ty0 = calcMatrix.getY(x, y);
104-
105-
var tx1 = calcMatrix.getX(x, yh);
106-
var ty1 = calcMatrix.getY(x, yh);
107-
108-
var tx2 = calcMatrix.getX(xw, yh);
109-
var ty2 = calcMatrix.getY(xw, yh);
110-
111-
var tx3 = calcMatrix.getX(xw, y);
112-
var ty3 = calcMatrix.getY(xw, y);
113-
114-
if (roundPixels)
134+
if (dropShadow)
115135
{
116-
tx0 = Math.round(tx0);
117-
ty0 = Math.round(ty0);
118-
119-
tx1 = Math.round(tx1);
120-
ty1 = Math.round(ty1);
121-
122-
tx2 = Math.round(tx2);
123-
ty2 = Math.round(ty2);
124-
125-
tx3 = Math.round(tx3);
126-
ty3 = Math.round(ty3);
136+
BatchChar(pipeline, src, char, glyph, dropShadowX, dropShadowY, calcMatrix, roundPixels, blackTL, blackTR, blackBL, blackBR, 0, texture, textureUnit);
127137
}
128138

129-
if (char.isTinted)
139+
if (charColors[char.i])
130140
{
131-
var ctintEffect = char.tintEffect;
132-
var ctintTL = Utils.getTintAppendFloatAlpha(char.tintTL, cameraAlpha * char.alphaTL);
133-
var ctintTR = Utils.getTintAppendFloatAlpha(char.tintTR, cameraAlpha * char.alphaTR);
134-
var ctintBL = Utils.getTintAppendFloatAlpha(char.tintBL, cameraAlpha * char.alphaBL);
135-
var ctintBR = Utils.getTintAppendFloatAlpha(char.tintBR, cameraAlpha * char.alphaBR);
141+
var color = charColors[char.i];
142+
143+
var ctintEffect = color.tintEffect;
144+
var ctintTL = Utils.getTintAppendFloatAlpha(color.tintTL, cameraAlpha * src._alphaTL);
145+
var ctintTR = Utils.getTintAppendFloatAlpha(color.tintTR, cameraAlpha * src._alphaTR);
146+
var ctintBL = Utils.getTintAppendFloatAlpha(color.tintBL, cameraAlpha * src._alphaBL);
147+
var ctintBR = Utils.getTintAppendFloatAlpha(color.tintBR, cameraAlpha * src._alphaBR);
136148

137-
pipeline.batchQuad(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, glyph.u0, glyph.v0, glyph.u1, glyph.v1, ctintTL, ctintTR, ctintBL, ctintBR, ctintEffect, texture, textureUnit);
149+
BatchChar(pipeline, src, char, glyph, 0, 0, calcMatrix, roundPixels, ctintTL, ctintTR, ctintBL, ctintBR, ctintEffect, texture, textureUnit);
138150
}
139151
else
140152
{
141-
pipeline.batchQuad(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, glyph.u0, glyph.v0, glyph.u1, glyph.v1, tintTL, tintTR, tintBL, tintBR, tintEffect, texture, textureUnit);
153+
BatchChar(pipeline, src, char, glyph, 0, 0, calcMatrix, roundPixels, tintTL, tintTR, tintBL, tintBR, tintEffect, texture, textureUnit);
142154
}
143155

144156
// Debug test if the characters are in the correct place when rendered:
145-
146157
// pipeline.drawFillRect(tx0, ty0, tx2 - tx0, ty2 - ty0, 0x00ff00, 0.5);
147158
}
148159
};

0 commit comments

Comments
 (0)