Example #1
0
        Pen CreateNewPen(UBrush b, UStroke s)
        {
            // Link to invalidation of brush, once.
            //  the cache of the pen is stored in the stroke.
            VoidAction inval = delegate { };

            inval = () =>
            {
                s.Invalidate();
                b.changed -= inval;
            };
            b.changed += inval;

            // FIXME advanced features not used!
            Pen ret;

            ret            = new Pen(CreateBrush(b));
            ret.DashCap    = Translate1(s.dashCap);
            ret.EndCap     = Translate2(s.endCap);
            ret.StartCap   = Translate2(s.startCap);
            ret.LineJoin   = Translate(s.lineJoin);
            ret.DashStyle  = Translate(s.dashStyle);
            ret.MiterLimit = s.mitreLimit;
            ret.DashOffset = s.offset;

            // FIXME maybe not right for compatibility with other renderes?
            ret.Alignment = PenAlignment.Center;

            if (s.dashStyle == StrokeType.custom)
            {
                ret.DashPattern = s.custom;
            }

            return(ret);
        }
Example #2
0
 //void dr(UBrush b, float x, float y)
 //{
 //    GL.Vertex2(x, y);
 //    setCoordColor(b, x, y);
 //}
 void bufferRectData(Rectangle rect, UBrush brush)
 {
     setVC(brush, rect.left, rect.top);
     setVC(brush, rect.right, rect.top);
     setVC(brush, rect.right, rect.bottom);
     setVC(brush, rect.left, rect.bottom);
 }
Example #3
0
        OTK.Graphics.Color4 getCoordColor(UBrush b, float x, float y)
        {
            var ret = new OTK.Graphics.Color4();

            if (b is USolidBrush)
            {
                var usb = b as USolidBrush;
                ret.R = usb.color.r; ret.G = usb.color.g; ret.B = usb.color.b; ret.A = usb.color.a;
            }
            else if (b is ULinearGradientBrush)
            {
                var   ulgb      = b as ULinearGradientBrush;
                float axisAngle = pointsanglex(ulgb.point1, ulgb.point2);

                float cp1, cp2;
                Color cv1, cv2;
                cp1 = angleaxisxinterp(axisAngle, ulgb.point1.X, ulgb.point1.Y);
                cp2 = angleaxisxinterp(axisAngle, ulgb.point2.X, ulgb.point2.Y);
                cv1 = ulgb.color1; cv2 = ulgb.color2;
                if (cp1 > cp2)
                {
                    cp1 = angleaxisxinterp(axisAngle, ulgb.point2.X, ulgb.point2.Y);
                    cp2 = angleaxisxinterp(axisAngle, ulgb.point1.X, ulgb.point1.Y);
                    cv1 = ulgb.color2; cv2 = ulgb.color1;
                }
                ret = hcolorfour(x, y, axisAngle, cp1, cp2, cv1, cv2);
            }
            return(ret);
        }
Example #4
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));
            }
        }
Example #5
0
 public UStyleRange(int start, int length, UFont?font, UBrush foreground, UBrush background)
 {
     _start        = start;
     _length       = length;
     _fontOverride = font;
     _fgOverride   = foreground;
     _bgOverride   = background;
 }
Example #6
0
        public void FillRoundedRectangle(Rectangle rect, float radX, float radY, UBrush brush)
        {
            int st = rel.renderData.sofwareBuffer.Count;

            RRPoints(rect, radX, radY, brush);
            int cnt = rel.renderData.sofwareBuffer.Count - st;

            rel.renderData.bufferInfo.Add(new RenderInfo(st, cnt, ArrayData.Vertex | ArrayData.Color, PrimitiveType.Polygon));
        }
Example #7
0
 public void DrawLine(Point start, Point end, UBrush brush, UStroke stroke)
 {
     GL.Begin(PrimitiveType.Quads);
     setCoordColor(brush, start.X, start.Y);
     GL.Vertex2(start.X, start.Y);
     setCoordColor(brush, end.X, end.Y);
     GL.Vertex2(end.X, end.Y);
     GL.End();
 }
Example #8
0
 public void FillPath(UPath path, UBrush brush)
 {
     foreach (var f in path.figures)
     {
         int st = rel.renderData.sofwareBuffer.Count;
         BufferFigureVC(f, brush, false, false);
         int cnt = rel.renderData.sofwareBuffer.Count - st;
         rel.renderData.bufferInfo.Add(new RenderInfo(st, cnt, ArrayData.Vertex | ArrayData.Color, PrimitiveType.Polygon));
     }
 }
Example #9
0
 public void DrawPath(UPath path, UBrush brush, UStroke stroke)
 {
     foreach (var f in path.figures)
     {
         int st = rel.renderData.sofwareBuffer.Count;
         BufferFigureVC(f, brush, f.open, true);
         int cnt = rel.renderData.sofwareBuffer.Count - st;
         rel.renderData.bufferInfo.Add(new RenderInfo(st, cnt, ArrayData.Vertex | ArrayData.Color, PrimitiveType.Lines));
     }
 }
Example #10
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));
        }
Example #11
0
        public void FillRectangle(Rectangle rect, UBrush brush)
        {
            // generate sw buffer { Vx,Vy,r,g,b,a } ...
            int st = rel.renderData.sofwareBuffer.Count;

            bufferRectData(rect, brush);
            int len = rel.renderData.sofwareBuffer.Count - st;
            var ri  = new RenderInfo(st, len, ArrayData.Vertex | ArrayData.Color, PrimitiveType.Quads);

            rel.renderData.bufferInfo.Add(ri);
        }
Example #12
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));
        }
Example #13
0
 public void DrawEllipse(Point center, float radiusX, float radiusY, UBrush brush, UStroke stroke)
 {
     GL.Begin(PrimitiveType.LineLoop);
     foreach (var pt in GeometryLib.EllipseUtil.GetEllipse(radiusX, radiusX, .1f))
     {
         float x = pt.X + center.X;
         float y = pt.Y + center.Y;
         setCoordColor(brush, x, y);
         GL.Vertex2(x, y);
     }
     GL.End();
 }
Example #14
0
        void setVC(UBrush b, float vx, float vy)
        {
            var ssb = rel.renderData.sofwareBuffer;
            var cc  = getCoordColor(b, vx, vy);

            ssb.Add(vx);
            ssb.Add(vy);
            ssb.Add(cc.R);
            ssb.Add(cc.G);
            ssb.Add(cc.B);
            ssb.Add(cc.A);
        }
Example #15
0
        void BufferFigureVC(UFigure f, UBrush brush, bool open, bool doublepoints)
        {
            Point stp = f.startPoint;

            foreach (var g in f.geoElements)
            {
                PlotGeoElement(ref stp, g, brush, doublepoints);
            }
            if (!open)
            {
                setVC(brush, stp.X, stp.Y);
                setVC(brush, f.startPoint.X, f.startPoint.Y);
            }
        }
Example #16
0
        public void DrawText(UText textObject, NoForms.Common.Point location, UBrush defBrush, UTextDrawOptions opt, bool clientRendering)
        {
            var tl = glyphRunner.GetTextInfo(textObject);

            foreach (var glyphrun in tl.glyphRuns)
            {
                var       style   = glyphrun.run.drawStyle;
                UFont     font    = style != null ? (style.fontOverride ?? textObject.font) : textObject.font;
                FontStyle fs      = (font.bold ? FontStyle.Bold: 0) | (font.italic ? FontStyle.Italic: 0);
                var       sdgFont = Translate(font);
                UBrush    brsh    = style != null ? (style.fgOverride ?? defBrush) : defBrush;
                if (style != null && style.bgOverride != null)
                {
                    FillRectangle(new NoForms.Common.Rectangle(glyphrun.location, glyphrun.run.runSize), style.bgOverride);
                }
                realRenderer.graphics.DrawString(glyphrun.run.content, sdgFont, CreateBrush(brsh), SDGTr.trF(location + glyphrun.location), StringFormat.GenericTypographic);
            }
        }
Example #17
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);
        }
Example #18
0
 void RRPoints(Rectangle rect, float radX, float radY, UBrush b)
 {
     // top left arc
     ARCPoints(rect.left, rect.top + radY, 90f, 180f, radX, radY, b);
     // line to top right arc start
     setVC(b, rect.right - radX, rect.top);
     //top right arc
     ARCPoints(rect.right - radX, rect.top, 90f, 0f, radX, radY, b);
     // line top bottom right arc
     setVC(b, rect.right, rect.bottom - radY);
     //bottom right arc
     ARCPoints(rect.right, rect.bottom - radY, 0f, -90f, radX, radY, b);
     //line to bottom left arc
     setVC(b, rect.left + radX, rect.bottom);
     //bottom left arc
     ARCPoints(rect.left + radX, rect.bottom, -90f, -180f, radX, radY, b);
     // line back to top left arc
     setVC(b, rect.left, rect.top + radY);
 }
Example #19
0
        void ARCPoints(float sx, float sy, float t1, float t2, float rx, float ry, UBrush b)
        {
            var e_tl = GeometryLib.EasyEllipse.Generate(new GeometryLib.EasyEllipse.EasyEllipseInput()
            {
                rx         = rx,
                ry         = ry,
                rotation   = 0,
                resolution = .1f,
                start_x    = sx,
                start_y    = sy,
                t1         = t1,
                t2         = t2
            });

            foreach (var pt in e_tl)
            {
                setVC(b, pt.X, pt.Y);
            }
        }
Example #20
0
        Brush CreateNewBrush(UBrush b)
        {
            // FIXME can use PathGradientBrush, d2d just has gradientbrush...
            Brush ret;

            if (b is USolidBrush)
            {
                // FIXME support brushProperties
                USolidBrush sb = b as USolidBrush;
                ret = new SolidBrush(SDGTr.tr(sb.color));
            }
            else if (b is ULinearGradientBrush)
            {
                var lb = b as ULinearGradientBrush;
                ret = new LinearGradientBrush(SDGTr.trF(lb.point1), SDGTr.trF(lb.point2), SDGTr.tr(lb.color1), SDGTr.tr(lb.color2));
            }
            else
            {
                throw new NotImplementedException();
            }
            return(ret);
        }
Example #21
0
 public void DrawLine(NoForms.Common.Point start, NoForms.Common.Point end, UBrush brush, UStroke stroke)
 {
     realRenderer.graphics.DrawLine(CreatePen(brush, stroke), SDGTr.trF(start), SDGTr.trF(end));
 }
Example #22
0
 Pen CreatePen(UBrush b, UStroke s)
 {
     return(s.Retreive <SDG_RenderElements>(new NoCacheDelegate(() => CreateNewPen(b, s))) as Pen);
 }
Example #23
0
 // Element Creators
 // FIXME how to avoid switching on type, and allowing mixing of UBrush etc between renderes at runtime?  Factory method on specific class wouldnt work...
 Brush CreateBrush(UBrush b)
 {
     return(b.Retreive <SDG_RenderElements>(new NoCacheDelegate(() => CreateNewBrush(b))) as Brush);
 }
Example #24
0
        public void FillRoundedRectangle(NoForms.Common.Rectangle rect, float radX, float radY, UBrush brush)
        {
            var rr = ShapeHelpers.RoundedRectangle(rect, radX, radY);

            realRenderer.graphics.FillPath(CreateBrush(brush), rr);
        }
Example #25
0
        public void DrawRoundedRectangle(NoForms.Common.Rectangle rect, float radX, float radY, UBrush brush, UStroke stroke)
        {
            var rr = ShapeHelpers.RoundedRectangle(rect, radX, radY);

            realRenderer.graphics.DrawPath(CreatePen(brush, stroke), rr);
        }
Example #26
0
 public void FillRectangle(NoForms.Common.Rectangle rect, UBrush brush)
 {
     realRenderer.graphics.FillRectangle(CreateBrush(brush), rect.left, rect.top, rect.width, rect.height);
 }
Example #27
0
 public void FillPath(UPath path, UBrush brush)
 {
     realRenderer.graphics.FillPath(CreateBrush(brush), CreatePath(path));
 }
Example #28
0
 public void DrawEllipse(NoForms.Common.Point center, float radiusX, float radiusY, UBrush brush, UStroke stroke)
 {
     realRenderer.graphics.DrawEllipse(CreatePen(brush, stroke), center.X - radiusX, center.Y - radiusY, radiusX * 2, radiusY * 2);
 }
Example #29
0
 public void DrawPath(UPath path, UBrush brush, UStroke stroke)
 {
     realRenderer.graphics.DrawPath(CreatePen(brush, stroke), CreatePath(path));
 }
Example #30
0
 public void DrawRectangle(NoForms.Common.Rectangle rect, UBrush brush, UStroke stroke)
 {
     realRenderer.graphics.DrawRectangle(CreatePen(brush, stroke), rect.left, rect.top, rect.width, rect.height);
 }