Skip to content

Commit a6d4d98

Browse files
committed
fix(platform-web-pixi): apply tint to graphics objects in PixiRenderingLayer
- Apply tint to existing graphics when setTint is called - Apply stored tint to new graphics objects in ensureGraphics - Add comprehensive tint-graphics interaction tests to MemoryRenderingLayer
1 parent 7e99a89 commit a6d4d98

2 files changed

Lines changed: 157 additions & 1 deletion

File tree

packages/core/tests/platform/MemoryRenderingLayer.test.ts

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,154 @@ describe("MemoryRenderingLayer", () => {
169169
})
170170
})
171171

172+
describe("Tint and Graphics Interaction", () => {
173+
it("should preserve tint when drawing graphics after setTint", () => {
174+
const node = rendering.createNode()
175+
rendering.setTint(node, 0xff0000)
176+
rendering.drawRectangle(node, 0, 0, 100, 50, 0x00ff00)
177+
178+
const tint = rendering.getTint(node)
179+
expect(tint).toBe(0xff0000)
180+
181+
const graphics = rendering.getGraphics(node)
182+
expect(graphics.length).toBe(1)
183+
})
184+
185+
it("should preserve tint when setTint is called after drawing graphics", () => {
186+
const node = rendering.createNode()
187+
rendering.drawRectangle(node, 0, 0, 100, 50, 0x00ff00)
188+
rendering.setTint(node, 0xff0000)
189+
190+
const tint = rendering.getTint(node)
191+
expect(tint).toBe(0xff0000)
192+
193+
const graphics = rendering.getGraphics(node)
194+
expect(graphics.length).toBe(1)
195+
})
196+
197+
it("should preserve tint after clearing graphics", () => {
198+
const node = rendering.createNode()
199+
rendering.setTint(node, 0xff0000)
200+
rendering.drawRectangle(node, 0, 0, 100, 50)
201+
rendering.clearGraphics(node)
202+
203+
const tint = rendering.getTint(node)
204+
expect(tint).toBe(0xff0000)
205+
206+
const graphics = rendering.getGraphics(node)
207+
expect(graphics.length).toBe(0)
208+
})
209+
210+
it("should allow updating tint multiple times with graphics", () => {
211+
const node = rendering.createNode()
212+
rendering.drawCircle(node, 50, 50, 25, 0x00ff00)
213+
214+
rendering.setTint(node, 0xff0000)
215+
expect(rendering.getTint(node)).toBe(0xff0000)
216+
217+
rendering.setTint(node, 0x0000ff)
218+
expect(rendering.getTint(node)).toBe(0x0000ff)
219+
220+
rendering.setTint(node, { r: 128, g: 128, b: 128 })
221+
expect(rendering.getTint(node)).toEqual({ r: 128, g: 128, b: 128 })
222+
})
223+
224+
it("should handle tint with multiple graphics commands", () => {
225+
const node = rendering.createNode()
226+
rendering.setTint(node, 0xff00ff)
227+
228+
rendering.drawRectangle(node, 0, 0, 50, 50, 0xffffff)
229+
rendering.drawCircle(node, 100, 100, 25, 0xffffff)
230+
rendering.drawPolygon(node, [0, 0, 50, 0, 25, 50], 0xffffff)
231+
232+
const tint = rendering.getTint(node)
233+
expect(tint).toBe(0xff00ff)
234+
235+
const graphics = rendering.getGraphics(node)
236+
expect(graphics.length).toBe(3)
237+
})
238+
239+
it("should handle tint with line drawing", () => {
240+
const node = rendering.createNode()
241+
rendering.setTint(node, 0xaabbcc)
242+
rendering.drawLine(node, 0, 0, 100, 100, 0xffffff, 2)
243+
244+
const tint = rendering.getTint(node)
245+
expect(tint).toBe(0xaabbcc)
246+
247+
const graphics = rendering.getGraphics(node)
248+
expect(graphics.length).toBe(1)
249+
expect(graphics[0].type).toBe("line")
250+
})
251+
252+
it("should handle tint with polyline drawing", () => {
253+
const node = rendering.createNode()
254+
rendering.setTint(node, 0xddeeff)
255+
rendering.drawPolyline(node, [0, 0, 50, 50, 100, 0], 0xffffff, 3)
256+
257+
const tint = rendering.getTint(node)
258+
expect(tint).toBe(0xddeeff)
259+
260+
const graphics = rendering.getGraphics(node)
261+
expect(graphics.length).toBe(1)
262+
expect(graphics[0].type).toBe("polyline")
263+
})
264+
265+
it("should handle tint with rounded rectangle", () => {
266+
const node = rendering.createNode()
267+
rendering.setTint(node, 0x112233)
268+
rendering.drawRoundRect(node, 10, 10, 80, 60, 10, 0xffffff)
269+
270+
const tint = rendering.getTint(node)
271+
expect(tint).toBe(0x112233)
272+
273+
const graphics = rendering.getGraphics(node)
274+
expect(graphics.length).toBe(1)
275+
expect(graphics[0].type).toBe("roundRect")
276+
})
277+
278+
it("should maintain separate tints for different nodes", () => {
279+
const node1 = rendering.createNode()
280+
const node2 = rendering.createNode()
281+
282+
rendering.setTint(node1, 0xff0000)
283+
rendering.setTint(node2, 0x00ff00)
284+
285+
rendering.drawRectangle(node1, 0, 0, 50, 50)
286+
rendering.drawRectangle(node2, 0, 0, 50, 50)
287+
288+
expect(rendering.getTint(node1)).toBe(0xff0000)
289+
expect(rendering.getTint(node2)).toBe(0x00ff00)
290+
})
291+
292+
it("should handle drawing graphics before any tint is set", () => {
293+
const node = rendering.createNode()
294+
rendering.drawRectangle(node, 0, 0, 100, 100, 0xffffff)
295+
296+
const tint = rendering.getTint(node)
297+
expect(tint).toBeUndefined()
298+
299+
const graphics = rendering.getGraphics(node)
300+
expect(graphics.length).toBe(1)
301+
})
302+
303+
it("should handle interleaved tint and graphics operations", () => {
304+
const node = rendering.createNode()
305+
306+
rendering.drawRectangle(node, 0, 0, 50, 50)
307+
rendering.setTint(node, 0xff0000)
308+
rendering.drawCircle(node, 100, 100, 25)
309+
rendering.setTint(node, 0x00ff00)
310+
rendering.drawPolygon(node, [0, 0, 100, 0, 50, 100])
311+
312+
const tint = rendering.getTint(node)
313+
expect(tint).toBe(0x00ff00)
314+
315+
const graphics = rendering.getGraphics(node)
316+
expect(graphics.length).toBe(3)
317+
})
318+
})
319+
172320
describe("Bounds", () => {
173321
it("should calculate bounds for positioned node", () => {
174322
const node = rendering.createNode()

packages/platform-web-pixi/src/PixiRenderingLayer.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,14 @@ export class PixiRenderingLayer implements RenderingLayer {
335335
if (!state) return
336336

337337
state.tint = color
338+
const normalizedColor = normalizeColor(color)
338339

339340
if (state.currentSprite) {
340-
state.currentSprite.tint = normalizeColor(color)
341+
state.currentSprite.tint = normalizedColor
342+
}
343+
344+
if (state.graphics) {
345+
state.graphics.tint = normalizedColor
341346
}
342347

343348
this._needsRepaint = true
@@ -874,6 +879,9 @@ export class PixiRenderingLayer implements RenderingLayer {
874879
if (!state.graphics) {
875880
state.graphics = new PIXI.Graphics()
876881
state.graphics.blendMode = this.toPixiBlendMode(state.blendMode)
882+
if (state.tint !== null) {
883+
state.graphics.tint = normalizeColor(state.tint)
884+
}
877885
state.container.addChild(state.graphics)
878886
}
879887
}

0 commit comments

Comments
 (0)