public Playground() { InitializeComponent(); _stm = new StateMachine(); CreatePlayground(); InitializeTextEditor(); InitializeCalculatorControls(); Load += Playground_Load; Closing += Playground_Closing; SizeChanged += Playground_SizeChanged; drawingCanvas.MouseDown += DrawingCanvas_MouseDown; drawingCanvas.MouseUp += DrawingCanvas_MouseUp; drawingCanvas.MouseMove += DrawingCanvas_MouseMove; drawingCanvas.Paint += (_, e) => e.Graphics.DrawImage(_bitmap, 0, 0); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.SupportsTransparentBackColor, true); SetStyle(ControlStyles.UserPaint, true); InitModelAndFrameTick(); _drawablePool = new List <IDrawable>(); _currentPenContext = new Curve(); _drawPen = Pens.Blue; _toolsActivator = new Dictionary <Type, Func <int, int, PointPrimitive> > { { typeof(Circle), (x, y) => new Circle(x, y, _currentHeight) },
/// <summary> /// Draws a <see cref="PointPrimitive"/>. /// </summary> protected override void DrawPointPrimitive(PointPrimitive pointPrimitive) { Surface.FinalBuffer.Graphics.Transform = pointPrimitive.SpatialTransform.CumulativeTransform; pointPrimitive.CoordinateSystem = CoordinateSystem.Source; SizeF dropShadowOffset = GetDropShadowOffset(pointPrimitive, Dpi); var width = CalculateScaledPenWidth(pointPrimitive, 1, Dpi); // Draw drop shadow _brush.Color = Color.Black; Surface.FinalBuffer.Graphics.FillRectangle( _brush, pointPrimitive.Point.X + dropShadowOffset.Width, pointPrimitive.Point.Y + dropShadowOffset.Height, width, width); // Draw point _brush.Color = pointPrimitive.Color; Surface.FinalBuffer.Graphics.FillRectangle( _brush, pointPrimitive.Point.X, pointPrimitive.Point.Y, width, width); pointPrimitive.ResetCoordinateSystem(); Surface.FinalBuffer.Graphics.ResetTransform(); }
/// <summary> /// Draws a point primitive to the specified destination buffer. /// </summary> /// <param name="buffer">The destination buffer.</param> /// <param name="brush">A GDI brush to use for drawing.</param> /// <param name="point">The point primitive to be drawn.</param> /// <param name="dpi">The intended output DPI.</param> public static void DrawPointPrimitive(IGdiBuffer buffer, SolidBrush brush, PointPrimitive point, float dpi = _nominalScreenDpi) { buffer.Graphics.Transform = point.SpatialTransform.CumulativeTransform; point.CoordinateSystem = CoordinateSystem.Source; try { var dropShadowOffset = GetDropShadowOffset(point, dpi); var width = CalculateScaledPenWidth(point, 1, dpi); // Draw drop shadow brush.Color = Color.Black; buffer.Graphics.FillRectangle( brush, point.Point.X + dropShadowOffset.Width, point.Point.Y + dropShadowOffset.Height, width, width); // Draw point brush.Color = point.Color; buffer.Graphics.FillRectangle( brush, point.Point.X, point.Point.Y, width, width); } finally { point.ResetCoordinateSystem(); buffer.Graphics.ResetTransform(); } }
public GeometricObject() { rendering = false; initialized = false; pointAppearance = new Stack <Appearance> (); pointAppearance.Push(new Appearance(Color.red, Color.red, 60f, 1f, 1f)); lineAppearance = new Stack <Appearance> (); lineAppearance.Push(new Appearance(Color.blue, Color.blue, 60f, 1f, 1f)); surfaceAppearance = new Stack <Appearance> (); surfaceAppearance.Push(new Appearance(Color.green, Color.grey, 60f, 1f, 1f)); primitives = new List <PrimitiveBase> (); ptp = new PointPrimitive(); primitives.Add(ptp); lp = new LinePrimitive(); primitives.Add(lp); pp = new PolygonPrimitive(); primitives.Add(pp); sp = new SpherePrimitive(); primitives.Add(sp); mp = new MeshPrimitive(); primitives.Add(mp); }
public GeometricObject() { rendering = false; initialized = false; primitives = new List <PrimitiveBase> (); ptp = new PointPrimitive(); primitives.Add(ptp); lp = new LinePrimitive(); primitives.Add(lp); pp = new PolygonPrimitive(); primitives.Add(pp); sp = new SpherePrimitive(); primitives.Add(sp); mp = new MeshPrimitive(); primitives.Add(mp); }
/// <summary> /// Draws a <see cref="PointPrimitive"/>. Must be overridden and implemented. /// </summary> protected abstract void DrawPointPrimitive(PointPrimitive pointPrimitive);
void UpdateRendering() { // list of primitives to be rendered: var primitives = new List <Primitive> { }; // line for basX, basY: if (tState >= 1) { Vector v1, v2; v1 = basX.Direction.UnitVector * ext; v2 = basY.Direction.UnitVector * ext; primitives.Add(CurvePrimitive.Create(CurveSegment.Create(pOrig, pOrig + v1))); primitives.Add(CurvePrimitive.Create(CurveSegment.Create(pOrig, pOrig + v2))); } if (tState >= 2) { Point p1, p2, p3, p4; Vector v1, v2; v1 = basX.Direction.UnitVector * ext; v2 = basY.Direction.UnitVector * ext; p1 = pOrig - v1 - v2; p2 = pOrig - v1 + v2; p3 = pOrig + v1 + v2; p4 = pOrig + v1 - v2; primitives.Add(CurvePrimitive.Create(CurveSegment.Create(p1, p2))); primitives.Add(CurvePrimitive.Create(CurveSegment.Create(p2, p3))); primitives.Add(CurvePrimitive.Create(CurveSegment.Create(p3, p4))); primitives.Add(CurvePrimitive.Create(CurveSegment.Create(p4, p1))); } /*{ * // show frame of the sectionPlane: * Point p0 = Window.ActiveContext.SectionPlane.Frame.Origin; * Vector vx = Window.ActiveContext.SectionPlane.Frame.DirX.UnitVector * ext * 1.2; * Vector vy = Window.ActiveContext.SectionPlane.Frame.DirY.UnitVector * ext * 0.9; * primitives.Add(CurvePrimitive.Create(CurveSegment.Create(p0, p0 + vx))); * primitives.Add(CurvePrimitive.Create(CurveSegment.Create(p0, p0 + vy))); * } */ { // show screen ScreenPoint sp1 = new ScreenPoint(10, 10); ScreenPoint sp2 = new ScreenPoint(Window.ActiveWindow.Size.Width - 10, Window.ActiveWindow.Size.Height - 10); Point p1; Single r = 1.0f; Line l; Vector v1; l = Window.ActiveContext.GetCursorRay(sp1); if (getPointUnderCursor(l, out p1, out v1)) { primitives.Add(PointPrimitive.Create(p1, r)); } l = Window.ActiveContext.GetCursorRay(sp2); if (getPointUnderCursor(l, out p1, out v1)) { primitives.Add(PointPrimitive.Create(p1, r)); } } // string msg = PlotCommands[0] + PlotCommands[1] + PlotCommands[2]; // primitives.Add(TextPrimitive.Create(msg, LocationPoint.RightSide, pCur, 0, 0, new TextPadding(3))); var style = new GraphicStyle { LineColor = Color.Blue, FillColor = Color.Black, TextColor = Color.DarkGray, LineWidth = 2 }; Rendering = Graphic.Create(style, primitives); }
protected virtual void DrawPointPrimitive(PointPrimitive pointPrimitive) { GdiRenderer.DrawPointPrimitive(Surface.OverlayBuffer, _gdiObjectFactory, pointPrimitive, Dpi); }
/// <summary> /// Draws a <see cref="PointPrimitive"/>. /// </summary> protected override void DrawPointPrimitive(PointPrimitive pointPrimitive) { DrawPointPrimitive(Surface.FinalBuffer, _brush, pointPrimitive, Dpi); }
protected virtual void DrawPointPrimitive(PointPrimitive pointPrimitive) { GdiRenderer.DrawPointPrimitive(Surface.OverlayBuffer, _brush, pointPrimitive, Dpi); }
public static void DrawPointPrimitive(IGdiBuffer buffer, SolidBrush brush, PointPrimitive point, float dpi = _nominalScreenDpi) { var fakeFactory = new LegacyGdiObjectFactory(null, brush); DrawPointPrimitive(buffer, fakeFactory, point, dpi); }