public SDGDraw(SDG_RenderElements els) { realRenderer = els; glyphRunner = new GlyphRunGenerator <Font>( (uf, s, f) => SDGTr.tr(realRenderer.graphics.MeasureString(s, f, PointF.Empty, StringFormat.GenericTypographic)), // measurer uf => Translate(uf) // font translator (from ufont to the template) ); }
public void PushAxisAlignedClip(NoForms.Common.Rectangle clipRect, bool ignoreRenderOffset) { // This probabbly pushes an empty clip... if (PushedClips.Count == 0) { PushedClips.Push(realRenderer.graphics.Clip); } var cr = clipRect; if (ignoreRenderOffset) { cr -= new NoForms.Common.Point(realRenderer.graphics.Transform.OffsetX, realRenderer.graphics.Transform.OffsetY); } var cr2 = new System.Drawing.Region(SDGTr.trF(clipRect)); realRenderer.graphics.Clip = cr2; PushedClips.Push(cr2); }
void IController <IWFWin> .Init(IWFWin initObj, NoForm nf) { winForm = initObj.form; this.nf = nf; nf.controller = this; // Register! winForm.MouseDown += (o, e) => MouseUpDown(SDGTr.tr(e.Location), WFTr.Translate(e.Button), NoForms.Common.ButtonState.DOWN); winForm.MouseUp += (o, e) => MouseUpDown(SDGTr.tr(e.Location), WFTr.Translate(e.Button), NoForms.Common.ButtonState.UP); winForm.MouseMove += (o, e) => MouseMove(SDGTr.tr(e.Location)); winForm.KeyDown += (o, e) => KeyUpDown((NoForms.Common.Keys)e.KeyCode, NoForms.Common.ButtonState.DOWN); winForm.KeyUp += (o, e) => KeyUpDown((NoForms.Common.Keys)e.KeyCode, NoForms.Common.ButtonState.UP); winForm.KeyPress += (o, e) => KeyPress(e.KeyChar); // also the noform MouseUpDown += (a, b, c) => nf.MouseUpDown(a, b, c, true, false); MouseMove += l => nf.MouseMove(l, true, false); KeyUpDown += nf.KeyUpDown; KeyPress += nf.KeyPress; }
public void DrawBitmap(UBitmap bitmap, float opacity, UInterp interp, NoForms.Common.Rectangle source, NoForms.Common.Rectangle destination) { var bm = CreateBitmap(bitmap); if (opacity < 1.0f) { for (int x = 0; x < bm.Width; x++) { for (int y = 0; y < bm.Height; y++) { bm.SetPixel(x, y, System.Drawing.Color.FromArgb((int)(opacity * 255), bm.GetPixel(x, y))); } } } var previousInterp = realRenderer.graphics.CompositingQuality; realRenderer.graphics.CompositingQuality = Translate(interp); realRenderer.graphics.DrawImage(bm, SDGTr.trF(destination), SDGTr.trF(source), GraphicsUnit.Pixel); realRenderer.graphics.CompositingQuality = previousInterp; }
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); }
void RenderPass(Common.Region dc, Common.Size ReqSize) { renderTime.Start(); // Resize the backbuffer to noForm.Size, and fire the noForms sizechanged Resize(ReqSize); // Allow noform size to change as requested..like a layout hook (truncating layout passes with the render passes for performance) RenderSizeChanged(ReqSize); foreach (var dr in dc.AsRectangles()) { var sdr = SDGTr.trF(dr); graphics.FillRectangle(blackBack, sdr); } // Do Drawing stuff noForm.DrawBase(this, dc); //res winForm.Invoke(new System.Windows.Forms.MethodInvoker(() => { winForm.ClientSize = new System.Drawing.Size((int)ReqSize.width, (int)ReqSize.height); winForm.Location = SDGTr.trI(noForm.Location); })); // flush buffer to window var winGr = winForm.CreateGraphics(); foreach (var dr in dc.AsRectangles()) { var sdr = SDGTr.trF(dr); winGr.DrawImage(buffer, sdr, sdr, GraphicsUnit.Pixel); } winGr.Dispose(); lastFrameRenderDuration = 1f / (float)renderTime.Elapsed.TotalSeconds; renderTime.Reset(); }
// 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(ref GraphicsPath path, UGeometryBase geo, NoForms.Common.Point start) // ref GraphicsPath will allow us to recreate it if we want with new. { if (geo is UArcBase) { System.Drawing.PointF[] pts; if (geo is UArc) { UArc arc = geo as UArc; pts = (geo.Retreive <SDGDraw>(() => { var elInput = new GeometryLib.Ellipse_Input(start.X, start.Y, arc.endPoint.X, arc.endPoint.Y, arc.arcSize.width, arc.arcSize.height, arc.rotation); var elSolution = new List <GeometryLib.Ellipse_Output>(GeometryLib.Ellipse.Get_X0Y0(elInput)).ToArray(); GeometryLib.Ellipse.SampleArc(elInput, elSolution, arc.reflex, arc.sweepClockwise, arc.resolution, out pts); return(new disParr(pts)); }) as disParr).pts; } //else if (geo is UEasyArc) //{ // var arc = geo as UEasyArc; // pts = (geo.Retreive<SDGDraw>(() => // { // return new disParr(new List<System.Drawing.PointF>(EllipseLib.EasyEllipse.Generate(new EllipseLib.EasyEllipse.EasyEllipseInput() // { // rotation = arc.rotation, // start_x = start.X, // start_y = start.Y, // rx = arc.arcSize.width, // ry = arc.arcSize.height, // t1 = arc.startAngle, // t2 = arc.endAngle, // resolution = arc.resolution // })).ToArray()); // }) as disParr).pts; //} else { throw new NotImplementedException(); } // clone the data List <PointF> opts = new List <PointF>(path.PointCount > 0 ? path.PathPoints : new PointF[0]); List <byte> otyps = new List <byte>(path.PointCount > 0 ? path.PathTypes : new byte[0]); // do the types if (otyps.Count == 0 || otyps[otyps.Count - 1] != (byte)PathPointType.Start) { otyps.Add((byte)PathPointType.Start); opts.Add(SDGTr.trF(start)); } for (int i = 0; i < pts.Length; i++) { otyps.Add((byte)PathPointType.Line); // try to interpolate a bit? } // append new data opts.AddRange(pts); // Replace the path via reference path = new GraphicsPath(opts.ToArray(), otyps.ToArray(), path.FillMode); } else if (geo is ULine) { ULine line = geo as ULine; path.AddLine(SDGTr.trF(start), SDGTr.trF(line.endPoint)); } else if (geo is UBeizer) { UBeizer beizer = geo as UBeizer; path.AddBezier(SDGTr.trF(start), SDGTr.trF(beizer.controlPoint1), SDGTr.trF(beizer.controlPoint2), SDGTr.trF(beizer.endPoint)); } else { throw new NotImplementedException(); } }
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); } }
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)); }