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); }
//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); }
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); }
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)); } }
public UStyleRange(int start, int length, UFont?font, UBrush foreground, UBrush background) { _start = start; _length = length; _fontOverride = font; _fgOverride = foreground; _bgOverride = background; }
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)); }
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(); }
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)); } }
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)); } }
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)); }
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); }
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)); }
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(); }
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); }
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); } }
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); } }
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); }
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); }
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); } }
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); }
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)); }
Pen CreatePen(UBrush b, UStroke s) { return(s.Retreive <SDG_RenderElements>(new NoCacheDelegate(() => CreateNewPen(b, s))) as Pen); }
// 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); }
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); }
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); }
public void FillRectangle(NoForms.Common.Rectangle rect, UBrush brush) { realRenderer.graphics.FillRectangle(CreateBrush(brush), rect.left, rect.top, rect.width, rect.height); }
public void FillPath(UPath path, UBrush brush) { realRenderer.graphics.FillPath(CreateBrush(brush), CreatePath(path)); }
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); }
public void DrawPath(UPath path, UBrush brush, UStroke stroke) { realRenderer.graphics.DrawPath(CreatePen(brush, stroke), CreatePath(path)); }
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); }