Esempio n. 1
0
        void renderBox(iDrawContext context, iGeometry geometry, int id, float boundingBoxesOpacity, ref Matrix3x2 tform)
        {
            // if( id != 0 ) return;

            Rect box;

            if (geometry is iPathGeometry pathGeometry)
            {
                box = pathGeometry.getApproximateBounds(ref tform);
            }
            else
            {
                box = geometry.getBounds(ref tform);
            }

            Vector4 color = Color.moreRandomColor(id);

            if (context.device.premultipliedAlphaBrushes)
            {
                color *= boundingBoxesOpacity;
            }
            else
            {
                color.W = boundingBoxesOpacity;
            }
            context.transform.pushIdentity();
            context.drawRectangle(box, context.device.createSolidColorBrush(color), 1);
            context.transform.pop();
        }
Esempio n. 2
0
        public iImmediateDrawContext begin(iDrawContext dc, Vector4 clearColor)
        {
            if (null != context)
            {
                throw new ApplicationException("You can't call iVrmacDrawDevice.begin() several times");
            }
            dc.beginDraw();
            float clearAlpha = clearColor.W;

            if (clearAlpha >= 1.0f / 255.0f)
            {
                dc.clear(ref clearColor);
            }
            context = dc;
            transform.clear();
            return(this);
        }
Esempio n. 3
0
        public void render(iDrawContext context, Rect?box, float boundingBoxesOpacity)
        {
            Matrix3x2 view = Matrix3x2.Identity;

            if (viewBox.HasValue && box.HasValue)
            {
                view = MathUtils.createViewbox(box.Value, viewBox.Value);
            }

            if (boundingBoxesOpacity > 0)
            {
                boundingBoxesOpacity = MathF.Min(boundingBoxesOpacity, 1);
            }

            int i = 0;

            using (var t = context.transform.transform(view))
            {
                Matrix3x2 m = paths[0].style.matrix;
                context.transform.push(m);

                Matrix3x2 transform = context.transform.current;

                foreach (var p in paths)
                {
                    if (p.style.matrix != m)
                    {
                        m = p.style.matrix;
                        context.transform.pop();
                        context.transform.push(m);
                        if (boundingBoxesOpacity > 0)
                        {
                            transform = context.transform.current;
                        }
                    }

                    if (boundingBoxesOpacity > 0)
                    {
                        renderBox(context, p.geometry, i++, boundingBoxesOpacity, ref transform);
                    }

                    int mask = 0;
                    if (p.style.fillColor.HasValue && renderFills)
                    {
                        mask |= 1;
                    }
                    if (p.style.strokeColor.HasValue && renderStrokes)
                    {
                        mask |= 2;
                    }

                    var dev = context.device;
                    switch (mask)
                    {
                    case 1:
                        context.fillGeometry(p.geometry, dev.createSolidColorBrush(p.style.fillColor.Value));
                        break;

                    case 2:
                        context.drawGeometry(p.geometry, dev.createSolidColorBrush(p.style.strokeColor.Value), p.style.strokeWidth);
                        break;

                    case 3:
                        context.fillAndStroke(p.geometry, dev.createSolidColorBrush(p.style.fillColor.Value), dev.createSolidColorBrush(p.style.strokeColor.Value), p.style.strokeWidth);
                        break;
                    }
                }
                // No need to pop, the `using` statement cleans up everything pushed on top of the transform stack
            }
        }
Esempio n. 4
0
 void drawGeometry(iDrawContext dc, int i)
 {
     dc.fillGeometry(shapes[i], brush(i * 2 + 2));
     // dc.drawGeometry( shapes[ i ], brush( i * 2 + 1 ), strokeWidth, strokeStyle );
 }
Esempio n. 5
0
 void IDisposable.Dispose()
 {
     context?.endDraw();
     context = null;
 }