/// <summary> /// Draw the specified canvas and rect. /// </summary> /// <param name="canvas">Canvas.</param> /// <param name="rect">Rect.</param> public override void Draw (NGraphics.ICanvas canvas, NGraphics.Rect rect) { base.Draw (canvas, rect); if (PageCount <= 0) return; var dotWidth = rect.Height - 16; var spacing = dotWidth; var totalWidthNeeded = (PageCount * (dotWidth + spacing)) - dotWidth; // Draw dots double midx = rect.Width / 2; double midy = rect.Height / 2; var x = midx - (totalWidthNeeded / 2); var pen = new NGraphics.Pen (IndicatorColor.ToNColor (), 0.5); var brush = new NGraphics.SolidBrush (IndicatorColor.ToNColor ()); for (int i = 0; i < PageCount; i++) { canvas.DrawEllipse (new NGraphics.Rect (x, midy - (dotWidth / 2), dotWidth, dotWidth), pen, i==Page ? brush : null); x += dotWidth + spacing; } }
public override void Draw(NGraphics.ICanvas canvas, NGraphics.Rect rect) { base.Draw(canvas, rect); rect.Inflate(-10, -10); canvas.DrawRectangle(rect, Pens.Blue, null); }
void INCustomSeriesCallback.Paint2D(NChartRenderingContext2D context, NGraphics graphics) { NVector3DF vecView = new NVector3DF(); NVector3DF vecModel = new NVector3DF(); NScaleRuler rulerX = m_Chart.Axis(m_Series.HorizontalAxes[0]).Scale.Ruler; NScaleRuler rulerY = m_Chart.Axis(m_Series.VerticalAxes[0]).Scale.Ruler; // current number of accumulated Bezier points int bpCount = 0; // accumulated Bezier points PointF[] bezierPoints = new PointF[4]; for (int i = 0; i < Points.Length; i++) { // Transform values to chart model coorinates vecModel.X = rulerX.LogicalToScale(Points[i].X); vecModel.Y = rulerY.LogicalToScale(Points[i].Y); // Transform model coordinates to view coordinates m_Chart.TransformModelToClient(vecModel, ref vecView); // Draw the current point bool isControlPoint = (i % 3) != 0; if (isControlPoint) { NRectangleF rect = new NRectangleF(vecView.X - 3, vecView.Y - 3, 6, 6); graphics.PaintEllipse(ControlPointFill, null, rect); } else { NRectangleF rect = new NRectangleF(vecView.X - 5, vecView.Y - 5, 10, 10); graphics.PaintEllipse(PointFill, null, rect); } // Accumulate Bezier point bezierPoints[bpCount] = new PointF(vecView.X, vecView.Y); bpCount++; if (bpCount == 4) { // Draw tangents graphics.DrawLine(TangentStroke, new NPointF(bezierPoints[0]), new NPointF(bezierPoints[1])); graphics.DrawLine(TangentStroke, new NPointF(bezierPoints[2]), new NPointF(bezierPoints[3])); // Draw Bezier line GraphicsPath path = new GraphicsPath(); path.AddBezier(bezierPoints[0], bezierPoints[1], bezierPoints[2], bezierPoints[3]); graphics.PaintPath(null, BezierStroke, path); path.Dispose(); // Update accumultaed points bezierPoints[0] = bezierPoints[3]; bpCount = 1; } } }
public IImage CreateImage(NGraphics.Custom.Models.Color[] colors, int width, double scale = 1.0) { var factories = Direct2DFactories.Shared; var pf = WIC.PixelFormat.Format32bppBGRA; unsafe { fixed (NGraphics.Custom.Models.Color* p = colors) { var data = new DataRectangle { Pitch = width * 4, DataPointer = (IntPtr)p, }; var bmp = new WIC.Bitmap (factories.WICFactory, width, colors.Length / width, pf, data); return new WICBitmapSourceImage (bmp, factories); } } }
public override void Draw(NGraphics.ICanvas canvas, NGraphics.Rect rect) { base.Draw(canvas, rect); const double delta = -10.0; const double yOffset = 20; var width = rect.Width; var height = rect.Height; var points = new PathOp[] { new MoveTo(0, yOffset - delta), new CurveTo(new NGraphics.Point(width/2, yOffset + delta), new NGraphics.Point(width/2, yOffset + delta), new NGraphics.Point(width, yOffset - delta)), new LineTo(width, height), new LineTo(0, height) }; canvas.DrawPath(points, null, new SolidBrush(new NGraphics.Color(0, 0.722, 1, 1))); }
private static void SaveResourceImage(NShape gdiShape, NPath npath, string fileName, int width, int height, ImageFormat imageFormat, float outputMultiple = 1) { string directory = Path.GetDirectoryName(fileName); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } using (Bitmap bmp = new Bitmap((int)Math.Ceiling((width * outputMultiple) + 2), (int)Math.Ceiling((height * outputMultiple) + 2))) { bmp.SetResolution(300, 300); using (Graphics g = Graphics.FromImage(bmp)) { g.Clear(Color.White); g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.TextRenderingHint = TextRenderingHint.AntiAlias; g.SmoothingMode = SmoothingMode.HighQuality; NGraphics.DrawGDIPaths(g, bmp.Size, gdiShape, npath, outputMultiple); } bmp.Save(fileName, imageFormat); } }
private void DrawIcon(ICanvas canvas, NGraphics.Rect rect) { if(Graphic == null) return; var padding = ((rect.Size * IconScale) - rect.Size) / 2; var transform = Transform.AspectFillRect(Graphic.ViewBox, rect.GetInflated(padding)); var transformed = Graphic.TransformGeometry(transform); var color = new NGraphics.Color( FillColor.R, FillColor.G, FillColor.B, FillColor.A); foreach(var element in transformed.Children) { if(OverpaintEnabled) { ApplyColor(element, color); } element.Draw(canvas); } }
/// <summary> /// Draws an ellipse /// </summary> /// <param name="frame"></param> /// <param name="pen"></param> /// <param name="brush"></param> public void DrawEllipse(Rect frame, Pen pen = null, NGraphics.Brush brush = null) { var ellipseEl = new System.Windows.Shapes.Ellipse(); var offset = pen != null ? pen.Width : 0.0; ellipseEl.Width = frame.Width + offset; ellipseEl.Height = frame.Height + offset; if (brush != null) ellipseEl.Fill = GetBrush(brush); if (pen != null) { ellipseEl.Stroke = GetStroke(pen); ellipseEl.StrokeThickness = pen.Width; } ellipseEl.RenderTransform = Conversions.GetTransform(CurrentTransform); _canvas.Children.Add(ellipseEl); Canvas.SetLeft(ellipseEl, frame.X - offset / 2.0); Canvas.SetTop(ellipseEl, frame.Y - offset / 2.0); }
/// <summary> /// Draws a path /// </summary> /// <param name="ops"></param> /// <param name="pen"></param> /// <param name="brush"></param> public void DrawPath(IEnumerable<PathOp> ops, Pen pen = null, NGraphics.Brush brush = null) { if (pen == null && brush == null) return; var pathEl = new System.Windows.Shapes.Path(); if (brush != null) pathEl.Fill = GetBrush(brush); if (pen != null) { pathEl.Stroke = GetStroke(pen); pathEl.StrokeThickness = pen.Width; } var geo = new StringBuilder(); foreach (var op in ops) { var mt = op as MoveTo; if (mt != null) { geo.AppendFormat(CultureInfo.InvariantCulture, " M {0},{1}", mt.Point.X, mt.Point.Y); continue; } var lt = op as LineTo; if (lt != null) { geo.AppendFormat(CultureInfo.InvariantCulture, " L {0},{1}", lt.Point.X, lt.Point.Y); continue; } var at = op as ArcTo; if (at != null) { var p = at.Point; var r = at.Radius; geo.AppendFormat(CultureInfo.InvariantCulture, " A {0},{1} 0 {2} {3} {4},{5}", r.Width, r.Height, at.LargeArc ? 1 : 0, at.SweepClockwise ? 1 : 0, p.X, p.Y); continue; } var ct = op as CurveTo; if (ct != null) { var p = ct.Point; var c1 = ct.Control1; var c2 = ct.Control2; geo.AppendFormat(CultureInfo.InvariantCulture, " C {0},{1} {2},{3} {4},{5}", c1.X, c1.Y, c2.X, c2.Y, p.X, p.Y); continue; } var cp = op as ClosePath; if (cp != null) { geo.Append(" z"); continue; } } // Convert path string to geometry var b = new Binding { Source = geo.ToString() }; BindingOperations.SetBinding(pathEl, System.Windows.Shapes.Path.DataProperty, b); pathEl.RenderTransform = Conversions.GetTransform(CurrentTransform); _canvas.Children.Add(pathEl); }
/// <summary> /// Draws text /// </summary> /// <param name="text"></param> /// <param name="frame"></param> /// <param name="font"></param> /// <param name="alignment"></param> /// <param name="pen"></param> /// <param name="brush"></param> public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, NGraphics.Brush brush = null) { var textBlock = new TextBlock(); textBlock.Text = text; textBlock.Width = frame.Width; textBlock.Height = frame.Height; Canvas.SetLeft(textBlock, frame.X); Canvas.SetTop(textBlock, frame.Y); textBlock.FontFamily = new FontFamily(font.Family); textBlock.FontSize = font.Size; switch (alignment) { case TextAlignment.Left: textBlock.TextAlignment = System.Windows.TextAlignment.Left; break; case TextAlignment.Center: textBlock.TextAlignment = System.Windows.TextAlignment.Center; break; case TextAlignment.Right: textBlock.TextAlignment = System.Windows.TextAlignment.Right; break; } if (pen != null) textBlock.Foreground = new SolidColorBrush(new System.Windows.Media.Color { A = pen.Color.A, R = pen.Color.R, G = pen.Color.G, B = pen.Color.B }); textBlock.RenderTransform = Conversions.GetTransform(CurrentTransform); _canvas.Children.Add(textBlock); }
/// <summary> /// Transforms /// </summary> /// <param name="transform"></param> public void Transform(NGraphics.Transform transform) { // Remove current state (if any). It is replaced by the new state. if(_savedStates.Count > 0) { _savedStates.Pop(); } _savedStates.Push(transform); }
/// <summary> /// Draw the specified canvas. /// </summary> /// <param name="canvas">Canvas.</param> /// <param name="rect">Rect.</param> public void DrawCalendar (NGraphics.ICanvas canvas, NGraphics.Rect rect) { _monthYearLabel.Text = _currentMonth.ToString("MMMMM yyyy"); base.Draw (canvas, rect); // Should we use last line? // var drawLastLine = true; var colWidth = rect.Width/7; var rowHeight = rect.Height/6; var hasEmptyRow = false; // Find first week of day var firstWeekDay = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek; var date = _currentMonth; while (date.DayOfWeek != firstWeekDay) { date = date.AddDays(-1); } _firstDate = date; // Set up brushes var selectedBrush = new NGraphics.SolidBrush(SelectedBackground.ToNColor()); var regularBrush = new NGraphics.SolidBrush(RegularBackground.ToNColor()); var weekendBrush = new NGraphics.SolidBrush(WeekendBackground.ToNColor()); var notInMonthBrush = new NGraphics.SolidBrush(NotInMonthBackground.ToNColor()); var disabledBrush = new NGraphics.SolidBrush(DisabledBackground.ToNColor()); var col = 0; var row = 0; for (int d = 0; d < _dayNumberLabels.Length; d++) { // Update text var label = _dayNumberLabels[d]; if (hasEmptyRow || (date.DayOfWeek == firstWeekDay && date >= _currentMonth.AddMonths(1))) { hasEmptyRow = true; label.IsVisible = false; } else { label.IsVisible = true; label.Text = date.Day.ToString(); _lastDate = date; if (HighlightDisabled && (date < MinDate - MinDate.TimeOfDay || date > MaxDate)) { _dayNumberLabels[d].TextColor = DisabledColor; canvas.DrawRectangle (new NGraphics.Rect (col * colWidth, row * rowHeight, colWidth, rowHeight), null, disabledBrush); } else if (IsSameDay (SelectedDate, date)) { // Selected date _dayNumberLabels[d].TextColor = SelectedColor; canvas.DrawRectangle (new NGraphics.Rect (col * colWidth, row * rowHeight, colWidth, rowHeight), null, selectedBrush); } else if (date.Month != _currentMonth.Month) { // Prev/next month _dayNumberLabels[d].TextColor = NotInMonthColor; canvas.DrawRectangle(new NGraphics.Rect(col * colWidth, row * rowHeight, colWidth, rowHeight), null, notInMonthBrush); } else if (date.DayOfWeek == DayOfWeek.Sunday || date.DayOfWeek == DayOfWeek.Saturday) { // Weekends _dayNumberLabels[d].TextColor = WeekendColor; canvas.DrawRectangle(new NGraphics.Rect(col * colWidth, row * rowHeight, colWidth, rowHeight), null, weekendBrush); } else { // Regular days _dayNumberLabels [d].TextColor = RegularColor; canvas.DrawRectangle (new NGraphics.Rect (col * colWidth, row * rowHeight, colWidth, rowHeight), null, regularBrush); } if (IsSameDay (DateTime.Now, date)) { // Today _dayNumberLabels[d].TextColor = TodayColor; // Background var wh = Math.Min(colWidth, rowHeight); var dx = (colWidth - wh) / 2; var dy = (rowHeight - wh) / 2; var rc = new NGraphics.Rect ((col * colWidth) + dx, (row * rowHeight) + dy, wh, wh); rc.Inflate (-1, -1); canvas.DrawEllipse (rc, null, new NGraphics.SolidBrush(TodayBackground.ToNColor())); } } // Col/row-counter col++; if (col == 7) { col = 0; row++; } date = date.AddDays(1); } var colRowPen = new NGraphics.Pen(GridColor.ToNColor (), 1); // Draw row lines for (var r = 0; r < (hasEmptyRow ? 6 : 7) ; r++) { canvas.DrawPath (new NGraphics.PathOp[] { new NGraphics.MoveTo(0, r *rowHeight), new NGraphics.LineTo(rect.Width, r*rowHeight) }, colRowPen); } // Draw col lines for (var c = 0; c < 7; c++) { canvas.DrawPath (new NGraphics.PathOp[] { new NGraphics.MoveTo(c*colWidth, 0), new NGraphics.LineTo(c*colWidth, hasEmptyRow ? rect.Height - rowHeight : rect.Height) }, colRowPen); } }
/// <summary> /// /// </summary> /// <param name="fromBrush"></param> /// <returns></returns> private System.Windows.Media.Brush GetStroke(NGraphics.Pen fromPen) { return new SolidColorBrush(new System.Windows.Media.Color { A = fromPen.Color.A, R = fromPen.Color.R, G = fromPen.Color.G, B = fromPen.Color.B }); }
private void DrawCircle(ICanvas canvas, NGraphics.Rect rect) { var color = new NGraphics.Color(BackColor.R, BackColor.G, BackColor.B, BackColor.A); canvas.FillEllipse(rect, color); }
private void ApplyColor(NGraphics.Element element, NGraphics.Color color) { var children = (element as Group)?.Children; if(children != null) { foreach(var child in children) { ApplyColor(child, color); } } if(element?.Pen != null) { element.Pen = new Pen(color, element.Pen.Width); } if(element?.Brush != null) { element.Brush = new SolidBrush(color); } }
/// <summary> /// Returns a Windows brush from the NGraphics brush /// </summary> /// <param name="fromBrush"></param> /// <returns></returns> private Windows.UI.Xaml.Media.Brush GetBrush(NGraphics.Brush fromBrush) { var sb = fromBrush as SolidBrush; if(sb != null) { // Solid brush return new SolidColorBrush(new Windows.UI.Color { A = sb.Color.A, R = sb.Color.R, G = sb.Color.G, B = sb.Color.B }); } var lb = fromBrush as NGraphics.LinearGradientBrush; if(lb != null) { // Linear gradient var gradStops = new GradientStopCollection(); var n = lb.Stops.Count; if (n >= 2) { var locs = new float[n]; var comps = new int[n]; for (var i = 0; i < n; i++) { var s = lb.Stops[i]; gradStops.Add(new Windows.UI.Xaml.Media.GradientStop { Color = new Windows.UI.Color { A = s.Color.A, R = s.Color.R, B = s.Color.B, G = s.Color.G, }, Offset = s.Offset, }); } } var grad = new Windows.UI.Xaml.Media.LinearGradientBrush(gradStops, 90); return grad; } var rb = fromBrush as NGraphics.RadialGradientBrush; if(rb != null) { // Radial gradient throw new NotSupportedException("RadialGradientBrush is not supported for Windws Store Apps."); //var grad = new Windows.UI.Xaml.Media.RadialGradientBrush(); //var n = rb.Stops.Count; //if (n >= 2) //{ // var locs = new float[n]; // var comps = new int[n]; // for (var i = 0; i < n; i++) // { // var s = rb.Stops[i]; // grad.GradientStops.Add(new Windows.UI.Xaml.Media.GradientStop // { // Color = new Windows.UI.Color // { // A = s.Color.A, // R = s.Color.R, // B = s.Color.B, // G = s.Color.G, // }, // Offset = s.Offset, // }); // } //} //return grad; } return null; }
/// <summary> /// Draws a rectangle /// </summary> /// <param name="frame"></param> /// <param name="pen"></param> /// <param name="brush"></param> public void DrawRectangle(Rect frame, Pen pen = null, NGraphics.Brush brush = null) { var rectangleEl = new Windows.UI.Xaml.Shapes.Rectangle(); var offset = pen != null ? pen.Width : 0.0; rectangleEl.Width = frame.Width + offset; rectangleEl.Height = frame.Height + offset; if (brush != null) rectangleEl.Fill = GetBrush(brush); if (pen != null) { rectangleEl.Stroke = GetStroke(pen); rectangleEl.StrokeThickness = pen.Width; } rectangleEl.RenderTransform = Conversions.GetTransform(CurrentTransform); _canvas.Children.Add(rectangleEl); Canvas.SetLeft(rectangleEl, frame.X - offset / 2.0); Canvas.SetTop(rectangleEl, frame.Y - offset / 2.0); }
public override void Draw (NGraphics.ICanvas canvas, NGraphics.Rect rect) { base.Draw (canvas, rect); canvas.DrawEllipse (rect, null, new NGraphics.SolidBrush (new NGraphics.Color (FillColor.R, FillColor.G, FillColor.B, FillColor.A))); }
/// <summary> /// Creates an object implementing the IImage interface with the given paramters /// </summary> /// <param name="colors"></param> /// <param name="width"></param> /// <param name="scale"></param> /// <returns></returns> public IImage CreateImage(NGraphics.Color[] colors, int width, double scale = 1.0) { throw new NotImplementedException(); }
/// <summary> /// Returns a Windows brush from the NGraphics brush /// </summary> /// <param name="fromBrush"></param> /// <returns></returns> private System.Windows.Media.Brush GetBrush(NGraphics.Brush fromBrush) { var sb = fromBrush as SolidBrush; if (sb != null) { // Solid brush return new SolidColorBrush(new System.Windows.Media.Color { A = sb.Color.A, R = sb.Color.R, G = sb.Color.G, B = sb.Color.B }); } var lb = fromBrush as NGraphics.LinearGradientBrush; if (lb != null) { // Linear gradient var gradStops = new GradientStopCollection(); var n = lb.Stops.Count; if (n >= 2) { var locs = new float[n]; var comps = new int[n]; for (var i = 0; i < n; i++) { var s = lb.Stops[i]; gradStops.Add(new System.Windows.Media.GradientStop { Color = new System.Windows.Media.Color { A = s.Color.A, R = s.Color.R, B = s.Color.B, G = s.Color.G, }, Offset = s.Offset, }); } } var grad = new System.Windows.Media.LinearGradientBrush(gradStops, 90); return grad; } var rb = fromBrush as NGraphics.RadialGradientBrush; if (rb != null) { // Radial gradient var grad = new System.Windows.Media.RadialGradientBrush(); var n = rb.Stops.Count; if (n >= 2) { var locs = new float[n]; var comps = new int[n]; for (var i = 0; i < n; i++) { var s = rb.Stops[i]; grad.GradientStops.Add(new System.Windows.Media.GradientStop { Color = new System.Windows.Media.Color { A = s.Color.A, R = s.Color.R, B = s.Color.B, G = s.Color.G, }, Offset = s.Offset, }); } } return grad; } return null; }
/// <summary> /// Draw the specified canvas. /// </summary> /// <param name="canvas">Canvas.</param> /// <param name="rect">Rect.</param> public override void Draw(NGraphics.ICanvas canvas, NGraphics.Rect rect) { base.Draw(canvas, rect); canvas.DrawLine(0, rect.Height-0.5, rect.Width, rect.Height-0.5, NGraphics.Colors.Gray, 0.5); canvas.DrawEllipse(new Rect(-50, -50,250, 250), null, Brushes.Red); }
/// <summary> /// Draw the specified canvas. /// </summary> /// <param name="canvas">Canvas.</param> /// <param name="rect">Rect.</param> public override void Draw(NGraphics.ICanvas canvas, NGraphics.Rect rect) { base.Draw(canvas, rect); var backgroundBrush = new SolidBrush(new NGraphics.Color(BackgroundColor.R, BackgroundColor.G, BackgroundColor.B, BackgroundColor.A)); var curveSize = CornerRadius; var width = rect.Width; var height = rect.Height; canvas.DrawPath(new PathOp []{ new MoveTo(curveSize, 0), // Top Right corner new LineTo(width-curveSize, 0), new CurveTo( new NGraphics.Point(width-curveSize, 0), new NGraphics.Point(width, 0), new NGraphics.Point(width, curveSize) ), new LineTo(width, height-curveSize), // Bottom right corner new CurveTo( new NGraphics.Point(width, height-curveSize), new NGraphics.Point(width, height), new NGraphics.Point(width-curveSize, height) ), new LineTo(curveSize, height), // Bottom left corner new CurveTo( new NGraphics.Point(curveSize, height), new NGraphics.Point(0, height), new NGraphics.Point(0, height-curveSize) ), new LineTo(0, curveSize), new CurveTo( new NGraphics.Point(0, curveSize), new NGraphics.Point(0, 0), new NGraphics.Point(curveSize, 0) ), new ClosePath() }, null, backgroundBrush); }
/// <summary> /// Draw the specified canvas. /// </summary> /// <param name="canvas">Canvas.</param> /// <param name="rect">Rect.</param> public void DrawCalendar (NGraphics.ICanvas canvas, NGraphics.Rect rect) { base.Draw (canvas, rect); // Should we use last line? // var drawLastLine = true; var colWidth = rect.Width/7; var rowHeight = rect.Height/6; // Find first week of day var firstWeekDay = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek; // Find last of this day in previous month var lastDayInPrevMonth = GetLastDayInMonth(SelectedDate.AddMonths(-1)); while (lastDayInPrevMonth.DayOfWeek != firstWeekDay) lastDayInPrevMonth = lastDayInPrevMonth.AddDays (-1); // Set up brushes var selectedBrush = new NGraphics.SolidBrush(SelectedDateColor.ToNColor()); var prevNextBrush = new NGraphics.SolidBrush(Color.FromHex("#EEEEEE").ToNColor()); var currentDate = lastDayInPrevMonth; StartDate = lastDayInPrevMonth; var col = 0; var row = 0; for (int d = 0; d < _dayNumberLabels.Length; d++) { // Update text _dayNumberLabels [d].Text = currentDate.Day.ToString(); if (currentDate.Month != SelectedDate.Month) { // Prev/next month _dayNumberLabels [d].TextColor = Color.FromHex ("#CECECE"); } else { // Background canvas.DrawRectangle (new NGraphics.Rect (col * colWidth, row * rowHeight, colWidth, rowHeight), null, prevNextBrush); if (currentDate.DayOfWeek == DayOfWeek.Sunday || currentDate.DayOfWeek == DayOfWeek.Saturday) { // Weekends _dayNumberLabels [d].TextColor = Color.FromHex ("#CACACA"); } else { // Regular days _dayNumberLabels [d].TextColor = Color.Black; } } if (IsSameDay (DateTime.Now, currentDate)) { // Today _dayNumberLabels[d].TextColor = Color.White; // Background var wh = Math.Min(colWidth, rowHeight); var rc = new NGraphics.Rect ((col * colWidth), (row * rowHeight), wh, wh); rc.Inflate (-2, -2); rc.X++; rc.Y++; canvas.DrawEllipse (rc, null, new NGraphics.SolidBrush(Color.FromHex("#fc3d39").ToNColor())); } if (IsSameDay (SelectedDate, currentDate)) { // Selected colors _dayNumberLabels[d].TextColor = Color.White; // Background canvas.DrawRectangle (new NGraphics.Rect (col * colWidth, row * rowHeight, colWidth, rowHeight), null, selectedBrush); } // Col/row-counter col++; if (col == 7) { col = 0; row++; } currentDate = currentDate.AddDays (1); } var colRowPen = new NGraphics.Pen (Color.FromHex ("#FFFFFF").ToNColor (), 1); // Draw row lines for (var r = 0; r < 7; r++) { canvas.DrawPath (new NGraphics.PathOp[] { new NGraphics.MoveTo(0, r *rowHeight), new NGraphics.LineTo(rect.Width, r*rowHeight) }, colRowPen); } // Draw col lines for (var c = 0; c < 7; c++) { canvas.DrawPath (new NGraphics.PathOp[] { new NGraphics.MoveTo(c*colWidth, 0), new NGraphics.LineTo(c*colWidth, rect.Height) }, colRowPen); } }
public override void OnAfterPaint(NPanel panel, NPanelPaintEventArgs eventArgs) { NGraphics graphics = eventArgs.Graphics; double dPreviousValue, dCurrentValue; int nBarCount = 10; NChart chart = panel as NChart; NBarSeries bar = (NBarSeries)chart.Series[0]; NAxis horzAxis = chart.Axis(StandardAxis.PrimaryX); NAxis vertAxis = chart.Axis(StandardAxis.PrimaryY); NVector3DF vecClientPoint = new NVector3DF(); NVector3DF vecModelPoint = new NVector3DF(); int nBarSize = (int)(chart.ContentArea.Width * (int)bar.WidthPercent) / (nBarCount * 200); // init pens and brushes NStrokeStyle rectStrokeStyle = new NStrokeStyle(1, Color.DarkBlue); NFillStyle rectFillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.FromArgb(125, Color.LightBlue), Color.FromArgb(125, Color.DarkBlue)); NLightingImageFilter lightingFilter = new NLightingImageFilter(); NStrokeStyle positiveArrowStrokeStyle = new NStrokeStyle(1, Color.DarkGreen); NFillStyle positiveArrowFillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.Green, Color.DarkGreen); positiveArrowFillStyle.ImageFiltersStyle.Filters.Add(lightingFilter); NStrokeStyle equalSignStrokeStyle = new NStrokeStyle(1, Color.DarkGray); NFillStyle equalSignFillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.Gray, Color.DarkGray); positiveArrowFillStyle.ImageFiltersStyle.Filters.Add(lightingFilter); NStrokeStyle negativeArrowStrokeStyle = new NStrokeStyle(1, Color.DarkRed); NFillStyle negativeArrowFillStyle = new NGradientFillStyle(GradientStyle.Horizontal, GradientVariant.Variant1, Color.Red, Color.DarkRed); positiveArrowFillStyle.ImageFiltersStyle.Filters.Add(lightingFilter); for (int i = 1; i < bar.Values.Count; i++) { dPreviousValue = (double)bar.Values[i - 1]; dCurrentValue = (double)bar.Values[i]; vecModelPoint.X = horzAxis.TransformScaleToModel(false, i); vecModelPoint.Y = vertAxis.TransformScaleToModel(false, (float)(double)bar.Values[i]); vecModelPoint.Z = 0; if (!chart.TransformModelToClient(vecModelPoint, ref vecClientPoint)) { continue; } RectangleF rcArrowRect = new RectangleF(vecClientPoint.X - nBarSize, vecClientPoint.Y - nBarSize, 2 * nBarSize, 2 * nBarSize); if (rcArrowRect.Width <= 0 || rcArrowRect.Height <= 0) { continue; } if (!DisplayMark(dCurrentValue, dPreviousValue)) { continue; } // draw arrow background GraphicsPath path = GetRoundRectanglePath(rcArrowRect); graphics.PaintPath(rectFillStyle, rectStrokeStyle, path); path.Dispose(); rcArrowRect.Inflate(-5, -5); // draw the arrow itself if (rcArrowRect.Width <= 0 || rcArrowRect.Height <= 0) { continue; } if (dCurrentValue < dPreviousValue) { // draw negative arrow path = GetArrowPath(rcArrowRect, false); graphics.PaintPath(negativeArrowFillStyle, negativeArrowStrokeStyle, path); path.Dispose(); } else if (dCurrentValue > dPreviousValue) { // draw positive arrow path = GetArrowPath(rcArrowRect, true); graphics.PaintPath(positiveArrowFillStyle, positiveArrowStrokeStyle, path); path.Dispose(); } else { // draw equal sign NRectangleF rect = new NRectangleF(rcArrowRect.Left, rcArrowRect.Top, rcArrowRect.Width, rcArrowRect.Height / 3.0f); graphics.PaintRectangle(equalSignFillStyle, equalSignStrokeStyle, rect); rect = new NRectangleF(rcArrowRect.Left, rcArrowRect.Bottom - rect.Height, rcArrowRect.Width, rect.Height); graphics.PaintRectangle(equalSignFillStyle, equalSignStrokeStyle, rect); } } }
/// <summary> /// Handles the end. /// </summary> /// <returns><c>true</c>, if end was handled, <c>false</c> otherwise.</returns> /// <param name="point">Point.</param> private bool HandleEnd(NGraphics.Point point, bool allowCancel) { _ellipse.FadeTo (0.0, 50); return true; }