示例#1
0
        public void DrawText(UText textObject, Point location, UBrush defBrush, UTextDrawOptions opt, bool clientRendering)
        {
            var tl = CreateTextElements(textObject);

            foreach (var ord in textObject.SafeGetStyleRanges)
            {
                if (ord.bgOverride != null)
                {
                    foreach (var r in HitTextRange(ord.start, ord.length, location, textObject))
                    {
                        FillRectangle(r, ord.bgOverride);
                    }
                }
            }

            if (clientRendering)
            {
                // set default foreground brush
                tl.textRenderer.defaultEffect.fgBrush = CreateBrush(defBrush);

                // Draw the text (foreground & background in the client renderer)
                tl.textLayout.Draw(new Object[] { location, textObject }, tl.textRenderer, location.X, location.Y);
            }
            else
            {
                // Use D2D implimentation of text layout rendering
                realRenderer.renderTarget.DrawTextLayout(D2DTr.tr(location), tl.textLayout, CreateBrush(defBrush));
            }
        }
示例#2
0
        public void PushAxisAlignedClip(Rectangle clipRect, bool ignoreRenderOffset)
        {
            var cr = clipRect;

            if (ignoreRenderOffset)
            {
                cr -= new Point(realRenderer.renderTarget.Transform.M31, realRenderer.renderTarget.Transform.M32);
            }
            realRenderer.renderTarget.PushAxisAlignedClip(D2DTr.tr(cr), AntialiasMode.PerPrimitive);
        }
示例#3
0
        public void FillRoundedRectangle(Rectangle rect, float radX, float radY, UBrush brush)
        {
            var rr = new RoundedRectangle()
            {
                Rect    = D2DTr.tr(rect),
                RadiusX = radX,
                RadiusY = radY
            };

            realRenderer.renderTarget.FillRoundedRectangle(rr, CreateBrush(brush));
        }
示例#4
0
        public void DrawRoundedRectangle(Rectangle rect, float radX, float radY, UBrush brush, UStroke stroke)
        {
            var rr = new RoundedRectangle()
            {
                Rect    = D2DTr.tr(rect),
                RadiusX = radX,
                RadiusY = radY
            };

            realRenderer.renderTarget.DrawRoundedRectangle(rr, CreateBrush(brush), stroke.strokeWidth, CreateStroke(stroke));
        }
示例#5
0
        public override SharpDXLib.Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, SharpDXLib.ComObject clientDrawingEffect)
        {
            var cce  = (ClientTextEffect)clientDrawingEffect;
            var args = (Object[])clientDrawingContext;
            var ofs  = (Point)args[0];
            var ut   = (UText)args[1];

            Point origin = new Point(baselineOriginX, baselineOriginY);

            var fgb = cce == null ? defaultEffect.fgBrush : cce.fgBrush;

            rt.DrawGlyphRun(D2DTr.tr(origin), glyphRun, fgb, MeasuringMode.Natural);

            return(SharpDXLib.Result.Ok);
        }
示例#6
0
        Geometry CreateNewGeometry(UPath p)
        {
            var pg = new PathGeometry(realRenderer.renderTarget.Factory);
            var gs = pg.Open();

            foreach (var f in p.figures)
            {
                gs.BeginFigure(D2DTr.tr(f.startPoint), f.filled ? FigureBegin.Filled : FigureBegin.Hollow);
                foreach (var gb in f.geoElements)
                {
                    AppendGeometry(gs, gb);
                }
                gs.EndFigure(f.open ? FigureEnd.Open : FigureEnd.Closed);
            }
            gs.Close();
            return(pg);
        }
示例#7
0
        Brush CreateNewBrush(UBrush b)
        {
            Brush ret;

            if (b is USolidBrush)
            {
                // FIXME support brushProperties
                USolidBrush sb = b as USolidBrush;
                ret = new SolidColorBrush(realRenderer.renderTarget, D2DTr.tr(sb.color));
            }
            else if (b is ULinearGradientBrush)
            {
                // FIXME advanced features not used
                var lb = b as ULinearGradientBrush;
                LinearGradientBrush lgb = new LinearGradientBrush(realRenderer.renderTarget,
                                                                  new LinearGradientBrushProperties()
                {
                    StartPoint = D2DTr.tr(lb.point1),
                    EndPoint   = D2DTr.tr(lb.point2)
                },
                                                                  new GradientStopCollection(realRenderer.renderTarget,
                                                                                             new GradientStop[] {
                    new GradientStop()
                    {
                        Color = D2DTr.tr(lb.color1), Position = 0f
                    },
                    new GradientStop()
                    {
                        Color = D2DTr.tr(lb.color2), Position = 1f
                    }
                },
                                                                                             Gamma.StandardRgb,
                                                                                             ExtendMode.Clamp)
                                                                  );
                ret = lgb;
            }
            else
            {
                throw new NotImplementedException();
            }
            // Extra invalidation condition besides colors changeing etc as handled by the ObjStore descendants:  renderTarget disposed (eg resize).
            realRenderer.renderTarget.Disposed += new EventHandler <EventArgs>((o, e) => b.Invalidate());
            return(ret);
        }
示例#8
0
 public void DrawEllipse(Point center, float radiusX, float radiusY, UBrush brush, UStroke stroke)
 {
     realRenderer.renderTarget.DrawEllipse(new Ellipse(D2DTr.tr(center), radiusX, radiusY), CreateBrush(brush), stroke.strokeWidth, CreateStroke(stroke));
 }
示例#9
0
 public void FillEllipse(Point center, float radiusX, float radiusY, UBrush brush)
 {
     realRenderer.renderTarget.FillEllipse(new Ellipse(D2DTr.tr(center), radiusX, radiusY), CreateBrush(brush));
 }
示例#10
0
 public void DrawBitmap(UBitmap bitmap, float opacity, UInterp interp, Rectangle source, Rectangle destination)
 {
     realRenderer.renderTarget.DrawBitmap(CreateBitmap(bitmap), D2DTr.tr(destination), opacity, Translate(interp), D2DTr.tr(source));
 }
示例#11
0
        // FIXME another example of type switching.  Cant put d2d code on other side of bridge in eg UGeometryBase abstraction
        //       and also, using a factory to create the UGeometryBase will make d2d specific versions.
        // IDEA  This is possible:  Use factory (DI?) and check the Uxxx instances when passed to this type of class, and recreate
        //       a portion of the Uxxx if it doesnt match D2D?  Factory could be configured for d2d/ogl etc.  This links in with cacheing
        //       code too? Not sure if this will static compile :/ thats kinda the point...  we'd need the Uxxx.ICreateStuff to be a specific
        //       D2D interface...could subclass... would check if(ICreateStuff is D2DCreator) as d2dcreator else Icreatestuff=new d2dcreator...

        void AppendGeometry(GeometrySink sink, UGeometryBase geo)
        {
            if (geo is UArc)
            {
                UArc arc = geo as UArc;
                sink.AddArc(new ArcSegment()
                {
                    SweepDirection = arc.sweepClockwise ? SweepDirection.Clockwise : SweepDirection.CounterClockwise,
                    RotationAngle  = -arc.rotation,
                    ArcSize        = arc.reflex ? ArcSize.Large : ArcSize.Small,
                    Point          = D2DTr.tr(arc.endPoint),
                    Size           = D2DTr.tr(arc.arcSize)
                });
            }
            //else if (geo is UEasyArc)
            //{
            //    UEasyArc arc = geo as UEasyArc;
            //    var eco = geo.Retreive<D2DDraw>(() =>
            //        {
            //            var cp = gcpt();
            //            return EllipseLib.EasyEllipse.ConvertEndPoint(new EllipseLib.EasyEllipse.EasyEllipseInput()
            //            {
            //                resolution = arc.resolution,
            //                t1 = arc.startAngle,
            //                t2 = arc.endAngle,
            //                rx = arc.arcSize.width,
            //                ry = arc.arcSize.height,
            //                rotation = arc.rotation,
            //                start_x = cp.X,
            //                start_y = cp.Y
            //            });
            //        }) as EllipseLib.EasyEllipse.EECOut;

            //    sink.AddArc(new ArcSegment()
            //    {
            //        SweepDirection = eco.clockwise ? SweepDirection.Clockwise : SweepDirection.CounterClockwise,
            //        RotationAngle = -arc.rotation,
            //        ArcSize = eco.reflex ? ArcSize.Large : ArcSize.Small,
            //        Point = new SharpDXLib.DrawingPointF(eco.x, eco.y),
            //        Size = D2DTr.tr(arc.arcSize)
            //    });
            //}
            else if (geo is ULine)
            {
                ULine line = geo as ULine;
                sink.AddLine(D2DTr.tr(line.endPoint));
            }
            else if (geo is UBeizer)
            {
                UBeizer beizer = geo as UBeizer;
                sink.AddBezier(new BezierSegment()
                {
                    Point1 = D2DTr.tr(beizer.controlPoint1),
                    Point2 = D2DTr.tr(beizer.controlPoint2),
                    Point3 = D2DTr.tr(beizer.endPoint)
                });
            }
            else
            {
                throw new NotImplementedException();
            }
        }
示例#12
0
 public void FillRectangle(Rectangle rect, UBrush brush)
 {
     realRenderer.renderTarget.FillRectangle(D2DTr.tr(rect), CreateBrush(brush));
 }
示例#13
0
 public void DrawRectangle(Rectangle rect, UBrush brush, UStroke stroke)
 {
     realRenderer.renderTarget.DrawRectangle(D2DTr.tr(rect), CreateBrush(brush), stroke.strokeWidth, CreateStroke(stroke));
 }
示例#14
0
 public void DrawLine(Point start, Point end, UBrush brush, UStroke stroke)
 {
     realRenderer.renderTarget.DrawLine(D2DTr.tr(start), D2DTr.tr(end), CreateBrush(brush), stroke.strokeWidth, CreateStroke(stroke));
 }