|
| 1 | +import { describe, it } from 'mocha'; |
| 2 | +import { expect } from 'chai'; |
| 3 | +import { ElementDrawingWebGL, RENDER_TARGET } from '../../src/extensions/renderer/canvas/webgl/drawing-elements-webgl.mjs'; |
| 4 | + |
| 5 | +const createBuffer = (size) => ({ |
| 6 | + view: new Float32Array(size), |
| 7 | + getView() { |
| 8 | + return this.view; |
| 9 | + } |
| 10 | +}); |
| 11 | + |
| 12 | +describe('webgl-drawing-elements', function(){ |
| 13 | + |
| 14 | + it('drawNode() uses effective opacity for simple-shape node body and border', function(){ |
| 15 | + const colorBuffer = createBuffer(4); |
| 16 | + const borderColorBuffer = createBuffer(4); |
| 17 | + const lineWidthBuffer = createBuffer(2); |
| 18 | + const vertTypeBuffer = createBuffer(1); |
| 19 | + const indexBuffer = createBuffer(4); |
| 20 | + const cornerRadiusBuffer = createBuffer(4); |
| 21 | + const transformMatrix = new Float32Array(9); |
| 22 | + const transformBuffer = { |
| 23 | + getMatrixView() { |
| 24 | + return transformMatrix; |
| 25 | + } |
| 26 | + }; |
| 27 | + |
| 28 | + const drawing = { |
| 29 | + simpleShapeOptions: new Map([[ |
| 30 | + 'node-body', |
| 31 | + { |
| 32 | + shapeProps: { |
| 33 | + shape: 'shape', |
| 34 | + color: 'background-color', |
| 35 | + opacity: 'background-opacity', |
| 36 | + radius: 'corner-radius', |
| 37 | + border: true |
| 38 | + }, |
| 39 | + getBoundingBox: () => ({ x1: 0, y1: 0, w: 10, h: 10 }) |
| 40 | + } |
| 41 | + ]]), |
| 42 | + _isVisible: () => true, |
| 43 | + _getVertTypeForShape: () => 4, |
| 44 | + colorBuffer, |
| 45 | + borderColorBuffer, |
| 46 | + lineWidthBuffer, |
| 47 | + vertTypeBuffer, |
| 48 | + indexBuffer, |
| 49 | + cornerRadiusBuffer, |
| 50 | + transformBuffer, |
| 51 | + renderTarget: RENDER_TARGET.SCREEN, |
| 52 | + instanceCount: 0, |
| 53 | + simpleCount: 0, |
| 54 | + maxInstances: 10, |
| 55 | + endBatch(){}, |
| 56 | + setTransformMatrix(){} |
| 57 | + }; |
| 58 | + |
| 59 | + const styles = { |
| 60 | + shape: { value: 'rectangle' }, |
| 61 | + 'background-color': { value: [255, 0, 0] }, |
| 62 | + 'background-opacity': { value: 0.5 }, |
| 63 | + 'corner-radius': { value: 'auto', pfValue: 0 }, |
| 64 | + 'border-width': { value: 4 }, |
| 65 | + 'border-color': { value: [0, 0, 255] }, |
| 66 | + 'border-opacity': { value: 0.25 }, |
| 67 | + 'border-position': { value: 'center' } |
| 68 | + }; |
| 69 | + |
| 70 | + const node = { |
| 71 | + visible: () => true, |
| 72 | + effectiveOpacity: () => 0.4, |
| 73 | + pstyle: (name) => styles[name] |
| 74 | + }; |
| 75 | + |
| 76 | + ElementDrawingWebGL.prototype.drawNode.call(drawing, node, 7, 'node-body'); |
| 77 | + |
| 78 | + expect(colorBuffer.view[3]).to.be.closeTo(0.2, 0.000001); |
| 79 | + expect(borderColorBuffer.view[3]).to.be.closeTo(0.1, 0.000001); |
| 80 | + expect(lineWidthBuffer.view[0]).to.equal(2); |
| 81 | + expect(lineWidthBuffer.view[1]).to.equal(-2); |
| 82 | + expect(drawing.simpleCount).to.equal(1); |
| 83 | + expect(drawing.instanceCount).to.equal(1); |
| 84 | + }); |
| 85 | + |
| 86 | +}); |
0 commit comments