コード例 #1
0
        Picture _buildPicture(_InspectorOverlayRenderState state)
        {
            PictureRecorder recorder = new PictureRecorder();
            Canvas          canvas   = new RecorderCanvas(recorder);
            Size            size     = state.overlayRect.size;

            var fillPaint = new Paint()
            {
                color = _kHighlightedRenderObjectFillColor
            };
            var borderPaint = new Paint()
            {
                color       = _kHighlightedRenderObjectBorderColor, style = PaintingStyle.stroke,
                strokeWidth = 1
            };
            Rect selectedPaintRect = state.selected.rect.deflate(0.5f);

            canvas.save();
            canvas.setMatrix(state.selected.transform);
            canvas.drawRect(selectedPaintRect, fillPaint);
            canvas.drawRect(selectedPaintRect, borderPaint);
            canvas.restore();

            foreach (var transformedRect in state.candidates)
            {
                canvas.save();
                canvas.setMatrix(transformedRect.transform);
                canvas.drawRect(transformedRect.rect.deflate(0.5f), borderPaint);
                canvas.restore();
            }

            // todo paint descipion
            return(recorder.endRecording());
        }
コード例 #2
0
ファイル: CanvasAndLayers.cs プロジェクト: weacw/RunTogether
        void drawPicture()
        {
            var pictureRecorder = new PictureRecorder();
            var canvas          = new RecorderCanvas(pictureRecorder);

            var paint = new Paint {
                color = new Color(0xFFFF0000),
            };

            var path = new Path();

            path.moveTo(10, 10);
            path.lineTo(10, 110);
            path.lineTo(90, 110);
            path.lineTo(100, 10);
            path.close();
            canvas.drawPath(path, paint);

            paint = new Paint {
                color = new Color(0xFFFFFF00),
            };

            var rect   = Unity.UIWidgets.ui.Rect.fromLTWH(10, 150, 100, 100);
            var rrect  = RRect.fromRectAndCorners(rect, 0, 4, 8, 16);
            var rect1  = Unity.UIWidgets.ui.Rect.fromLTWH(18, 152, 88, 92);
            var rrect1 = RRect.fromRectAndCorners(rect1, 0, 4, 8, 16);

            canvas.drawDRRect(rrect, rrect1, paint);

            canvas.rotate(-45 * Mathf.PI / 180, new Offset(150, 150));

            paint = new Paint {
                color      = new Color(0xFF00FFFF),
                maskFilter = MaskFilter.blur(BlurStyle.normal, 3),
            };
            canvas.drawRect(
                Unity.UIWidgets.ui.Rect.fromLTWH(150, 150, 110, 120),
                paint);

            var picture = pictureRecorder.endRecording();

            Debug.Log("picture.paintBounds: " + picture.paintBounds);

            var editorCanvas = new CommandBufferCanvas(this._renderTexture, Window.instance.devicePixelRatio,
                                                       this._meshPool);

            editorCanvas.drawPicture(picture);

            editorCanvas.rotate(-15 * Mathf.PI / 180);
            editorCanvas.translate(100, 100);
            editorCanvas.drawPicture(picture);
            editorCanvas.flush();
        }