protected override void OnDraw(Context ctx, Rectangle dirtyRect) { base.OnDraw(ctx, dirtyRect); ctx.SetColor(Colors.Gray); ctx.SetLineWidth(1); ctx.RoundRectangle(0, Padding.Top / 2 - .5, Width - 4.5, Height - Padding.Bottom * 1.5, 3); ctx.Stroke(); var tl = new TextLayout(this) { Text = title, Width = Width - Padding.Left - Padding.Right / 2 }; ctx.SetColor(Colors.White); ctx.Rectangle(Padding.Left, 0, tl.GetSize().Width, Padding.Top); ctx.Fill(); ctx.SetColor(Colors.Black); ctx.DrawTextLayout(tl, Padding.Left, 0); }
protected override void OnDraw(Context ctx, Rectangle dirtyRect) { base.OnDraw(ctx, dirtyRect); if (image != null) { if (Heighlighted && IsThumbnail) { ctx.RoundRectangle(new Rectangle(Point.Zero, image.Size), 3); ctx.SetColor(Colors.LightSteelBlue); ctx.Fill(); } ctx.DrawImage(image, (new Rectangle(Point.Zero, image.Size)).Inflate(-3, -3)); if (mask != null && ShowMask) { ctx.DrawImage(MaskBitmap, (new Rectangle(Point.Zero, image.Size)).Inflate(-3, -3), 0.6); } } if (isEditMode) { Point scaleFactor = new Point( scan.Size.Width / image.Size.Width, scan.Size.Height / image.Size.Height); ctx.SetColor(Mask.maskColor); foreach (MaskEntry p in scan.Mask.MaskPositions) { switch (p.type) { case MaskEntryType.Point: ctx.SetLineWidth(p.pointerSize / scaleFactor.Y * 2); ctx.LineTo(p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y); ctx.Stroke(); ctx.Arc( p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y, p.pointerSize / scaleFactor.Y, 0, 360); ctx.Fill(); ctx.MoveTo(p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y); break; case MaskEntryType.Space: ctx.Stroke(); ctx.ClosePath(); break; case MaskEntryType.Delete: ctx.Arc( p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y, p.pointerSize / scaleFactor.Y, 0, 360); ctx.Save(); ctx.Clip(); int newX = (int) Math.Min(Math.Max( p.position.X / scaleFactor.X - pointerSize / scaleFactor.Y, 0), scan.Size.Width); int newY = (int) Math.Min(Math.Max( p.position.Y / scaleFactor.Y - pointerSize / scaleFactor.Y, 0), scan.Size.Height); using (ImageBuilder ib = new ImageBuilder((pointerSize / scaleFactor.Y * 2), (pointerSize / scaleFactor.Y * 2))) { BitmapImage bi = ib.ToBitmap(); image.WithBoxSize(image.Size).ToBitmap().CopyArea( newX, newY, (int) (pointerSize / scaleFactor.Y * 2), (int) (pointerSize / scaleFactor.Y * 2), bi, 0, 0); ctx.DrawImage(bi, new Point(newX, newY)); } ctx.Restore(); ctx.ClosePath(); break; } } ctx.Stroke(); if (mousePosition != Point.Zero) { ctx.Arc(mousePosition.X, mousePosition.Y, pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y), 0, 360); ctx.Fill(); if (mousePositionStart != Point.Zero) { ctx.SetLineWidth((pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y)) * 2); ctx.SetColor(Mask.maskColor); ctx.Arc(mousePositionStart.X, mousePositionStart.Y, pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y), 0, 360); ctx.Fill(); ctx.MoveTo(mousePosition); ctx.LineTo(mousePositionStart); ctx.Stroke(); } } } }
/// <summary> /// Called when the widget needs to be redrawn /// </summary> /// <param name='ctx'> /// Drawing context /// </param> /// <param name="dirtyRect"></param> protected override void OnDraw(Context ctx, Rectangle dirtyRect) { if (Bounds.IsEmpty) return; base.OnDraw(ctx, dirtyRect); // apply scale factor dirtyRect.X /= scaleFactor; dirtyRect.Y /= scaleFactor; dirtyRect.Width /= scaleFactor; dirtyRect.Height /= scaleFactor; // actual drawing bool redraw = Draw(ctx, dirtyRect, scaleFactor); // draw minimap if (ShowMiniMap && MinWidth > 0 && MinHeight > 0) { Point size = new Point(180.0, 180.0 * (MinHeight / MinWidth)); double minimapScale = Math.Min(size.X / MinWidth, size.Y / MinHeight); Point minimapPosition = new Point( scrollview.HorizontalScrollControl.Value + scrollview.HorizontalScrollControl.PageSize - size.X - 16, scrollview.VerticalScrollControl.Value + 16); ctx.RoundRectangle(minimapPosition, size.X, size.Y, 6); ctx.SetColor(Colors.LightGray.WithAlpha(0.4)); ctx.Fill(); ctx.Save(); ctx.Translate(minimapPosition); Draw(ctx, new Rectangle(0, 0, MinWidth, MinHeight), minimapScale); ctx.Restore(); } // set canvas min size foreach (PipelineNode node in nodes) { Rectangle boundwe = node.BoundWithExtras; if (boundwe.Right * scaleFactor > MinWidth) { MinWidth = boundwe.Right * scaleFactor + PipelineNode.NodeMargin.Right; } if (boundwe.Bottom * scaleFactor > MinHeight) { MinHeight = boundwe.Bottom * scaleFactor + PipelineNode.NodeMargin.Bottom; } Point offset = new Point(Math.Max(0, -boundwe.Left), Math.Max(0, -boundwe.Top)); if (offset != Point.Zero) { TranslateAllNodesBy(offset); redraw = true; QueueDraw(); } } // update things if (mouseAction.HasFlag(MouseAction.MoveNode)) { // move scrollbar Rectangle boundwe = lastSelectedNode.BoundWithExtras; boundwe.X *= scaleFactor; boundwe.Y *= scaleFactor; boundwe.Height *= scaleFactor; boundwe.Width *= scaleFactor; double viewportRight = scrollview.HorizontalScrollControl.Value + scrollview.Size.Width; double offsetH = (nodeToMoveOffset.X + boundwe.Width) * 0.5 / scaleFactor; if (boundwe.Right - offsetH > viewportRight) { scrollview.HorizontalScrollControl.Value += boundwe.Right - offsetH - viewportRight; } else if (boundwe.Left + offsetH < scrollview.HorizontalScrollControl.Value) { scrollview.HorizontalScrollControl.Value -= scrollview.HorizontalScrollControl.Value - offsetH - boundwe.Left; } double viewportBottom = scrollview.VerticalScrollControl.Value + scrollview.Size.Height; double offsetV = (nodeToMoveOffset.Y + boundwe.Height) * 0.5; if (boundwe.Bottom - offsetV > viewportBottom) { scrollview.VerticalScrollControl.Value += boundwe.Bottom - offsetV - viewportBottom; } else if (boundwe.Top + offsetV < scrollview.VerticalScrollControl.Value) { scrollview.VerticalScrollControl.Value -= scrollview.VerticalScrollControl.Value - offsetV - boundwe.Top; } } if ((mouseAction.HasFlag(MouseAction.AddEdge) || mouseAction.HasFlag(MouseAction.MoveEdge)) && !mouseAction.HasFlag(MouseAction.AddEdgeNew)) { ctx.MoveTo( connectNodesStartMarker.IsInput ? connectNodesStartMarker.Bounds.Left * scaleFactor : connectNodesStartMarker.Bounds.Right * scaleFactor, connectNodesStartMarker.Bounds.Center.Y * scaleFactor ); ctx.LineTo(connectNodesEnd.X * scaleFactor, connectNodesEnd.Y * scaleFactor); ctx.Stroke(); } // set redraw finish? redrawQueued = redraw; // initial scroll position if (!initialScrollPosition.IsEmpty && !redraw && (scrollview.HorizontalScrollControl.Value < 1.0 || scrollview.VerticalScrollControl.Value < 1.0)) { scrollview.HorizontalScrollControl.Value = Math.Min( initialScrollPosition.X, scrollview.HorizontalScrollControl.UpperValue - scrollview.HorizontalScrollControl.PageSize ); scrollview.VerticalScrollControl.Value = Math.Min( initialScrollPosition.Y, scrollview.VerticalScrollControl.UpperValue - scrollview.VerticalScrollControl.PageSize ); } }
static void Draw(Context ctx, LogLevel level, Color color) { using (TextLayout text = new TextLayout()) { text.Text = level.ToString(); double height = text.GetSize().Height; ctx.SetColor(color); ctx.RoundRectangle(0, 1, height - 2, height - 2, 3); ctx.Fill(); // inner shadow ctx.RoundRectangle(0, 1, height - 2, height - 2, 3); LinearGradient g = new LinearGradient(1, 2, height - 2, height - 2); g.AddColorStop(0, Colors.Black.BlendWith(color, 0.7)); g.AddColorStop(1, color); ctx.Pattern = g; ctx.Fill(); ctx.SetColor(Colors.Black); ctx.DrawTextLayout(text, new Point(height + 3, 0)); } }
void DrawPopover(Context ctx) { lock (trackerLock) { if (actualTrackerHitResult != null) { var trackerSettings = DefaultTrackerSettings; if (actualTrackerHitResult.Series != null && !string.IsNullOrEmpty(actualTrackerHitResult.Series.TrackerKey)) trackerSettings = trackerDefinitions[actualTrackerHitResult.Series.TrackerKey]; if (trackerSettings.Enabled) { var extents = actualTrackerHitResult.LineExtents; if (Math.Abs(extents.Width) < double.Epsilon) { extents = new OxyRect(actualTrackerHitResult.XAxis.ScreenMin.X, extents.Top, actualTrackerHitResult.XAxis.ScreenMax.X - actualTrackerHitResult.XAxis.ScreenMin.X, extents.Height); } if (Math.Abs(extents.Height) < double.Epsilon) { extents = new OxyRect(extents.Left, actualTrackerHitResult.YAxis.ScreenMin.Y, extents.Width, actualTrackerHitResult.YAxis.ScreenMax.Y - actualTrackerHitResult.YAxis.ScreenMin.Y); } var pos = actualTrackerHitResult.Position; if (trackerSettings.HorizontalLineVisible) { renderContext.DrawLine( new[] { new ScreenPoint(extents.Left, pos.Y), new ScreenPoint(extents.Right, pos.Y) }, trackerSettings.HorizontalLineColor, trackerSettings.HorizontalLineWidth, trackerSettings.HorizontalLineActualDashArray, LineJoin.Miter, true); } if (trackerSettings.VerticalLineVisible) { renderContext.DrawLine( new[] { new ScreenPoint(pos.X, extents.Top), new ScreenPoint(pos.X, extents.Bottom) }, trackerSettings.VerticalLineColor, trackerSettings.VerticalLineWidth, trackerSettings.VerticalLineActualDashArray, LineJoin.Miter, true); } TextLayout text = new TextLayout(); text.Font = trackerSettings.Font; text.Text = actualTrackerHitResult.Text; var arrowTop = actualTrackerHitResult.Position.Y <= Bounds.Height / 2; const int arrowPadding = 10; var textSize = text.GetSize(); var outerSize = new Size(textSize.Width + (trackerSettings.Padding * 2), textSize.Height + (trackerSettings.Padding * 2) + arrowPadding); var trackerBounds = new Rectangle(pos.X - (outerSize.Width / 2), 0, outerSize.Width, outerSize.Height - arrowPadding); if (arrowTop) trackerBounds.Y = pos.Y + arrowPadding + trackerSettings.BorderWidth; else trackerBounds.Y = pos.Y - outerSize.Height - trackerSettings.BorderWidth; var borderColor = trackerSettings.BorderColor.ToXwtColor(); ctx.RoundRectangle(trackerBounds, 6); ctx.SetLineWidth(trackerSettings.BorderWidth); ctx.SetColor(borderColor); ctx.StrokePreserve(); ctx.SetColor(trackerSettings.Background.ToXwtColor()); ctx.Fill(); ctx.Save(); var arrowX = trackerBounds.Center.X; var arrowY = arrowTop ? trackerBounds.Top : trackerBounds.Bottom; ctx.NewPath(); ctx.MoveTo(arrowX, arrowY); var triangleSide = 2 * arrowPadding / Math.Sqrt(3); var halfSide = triangleSide / 2; var verticalModifier = arrowTop ? -1 : 1; ctx.RelMoveTo(-halfSide, 0); ctx.RelLineTo(halfSide, verticalModifier * arrowPadding); ctx.RelLineTo(halfSide, verticalModifier * -arrowPadding); ctx.SetColor(borderColor); ctx.StrokePreserve(); ctx.ClosePath(); ctx.SetColor(trackerSettings.Background.ToXwtColor()); ctx.Fill(); ctx.Restore(); ctx.SetColor(trackerSettings.TextColor.ToXwtColor()); ctx.DrawTextLayout(text, trackerBounds.Left + trackerSettings.Padding, trackerBounds.Top + trackerSettings.Padding); } } } }
/// <summary> /// Draw the marker. /// </summary> /// <param name="ctx">Context.</param> public override void Draw(Context ctx) { ctx.SetColor(PipelineNode.NodeColorBorder); Rectangle bndTmp = Bounds; ctx.RoundRectangle(bndTmp.Inflate(-2, -2), 2); if (compatible.IsFinal()) { ctx.SetColor(Colors.LightGray); } else { ctx.RoundRectangle(bndTmp.Inflate(-1, -1), 3); using (LinearGradient g = new LinearGradient(bndTmp.Left, bndTmp.Top, bndTmp.Right, bndTmp.Bottom)) { g.AddColorStop(0, Colors.Black.BlendWith(NodeColor, 0.7)); g.AddColorStop(1, NodeColor); ctx.Pattern = g; ctx.Fill(); } ctx.SetColor(NodeColor); } ctx.Fill(); if (IsInput) { int inputBufferSize = inputData.Count; List<Result> ihCopy; lock (inputHistoryLock) { ihCopy = new List<Result>(inputHistory); } foreach (Result input in ihCopy) { if (input.IsUsed(parent)) { inputBufferSize++; } else { lock (inputHistoryLock) { inputHistory.Remove(input); } } } if (inputBufferSize > 0) { bool sourceNodeIsAbove = true; if (edges.Count > 0 && edges[0] != null) { if (edges[0].to.Bounds.Center.Y > Bounds.Center.Y - 4.0) { sourceNodeIsAbove = false; } } textLayout.Text = inputBufferSize.ToString(); double textWidth = textLayout.GetSize().Width; double textHeight = textLayout.GetSize().Height; Point inputbufferSizeLocation = Bounds.Location.Offset( -24 -(textWidth/2), sourceNodeIsAbove ? textHeight + 6 : -6 - textHeight); ctx.Arc( inputbufferSizeLocation.X + textWidth / 2, inputbufferSizeLocation.Y + textHeight / 2, Math.Max(textHeight, textWidth) / 2 + 1, 0, 360 ); ctx.Fill(); ctx.SetColor(PipelineNode.NodeColor); ctx.DrawTextLayout(textLayout, inputbufferSizeLocation); } } else { // if this is a final node if (parent.algorithm.Output[positionNo].IsFinal()) { ctx.MoveTo(bndTmp.Right + 4, bndTmp.Top); ctx.LineTo(bndTmp.Right + 4, bndTmp.Bottom); ctx.Stroke(); // draw output size on end nodes (= number of features if (parent.results != null && parent.results.Count > 0 && parent.results[0].Item1 != null && parent.results[0].Item1.Length - 1 >= Position) { textLayout.Text = parent.results.Count.ToString(); double textWidth = textLayout.GetSize().Width; double textHeight = textLayout.GetSize().Height; Point outputbufferSizeLocation = Bounds.Location.Offset(Bounds.Width * 1.8, 0); ctx.Arc( outputbufferSizeLocation.X + textWidth / 2, outputbufferSizeLocation.Y + textHeight / 2, Math.Max(textHeight, textWidth) / 2 + 1, 0, 360 ); ctx.Fill(); ctx.SetColor(PipelineNode.NodeColor); ctx.DrawTextLayout(textLayout, outputbufferSizeLocation); } } } }
void DrawProgress(Context ctx) { int threadsRunning = progress.Keys.Count; Rectangle clipBound = bound.Inflate(-1, -1); clipBound.Bottom = clipBound.Top + contentOffset.Y; double height = threadsRunning == 0 ? clipBound.Height : clipBound.Height / threadsRunning; double width = clipBound.Width; clipBound.Bottom = clipBound.Top + height; List<int> toRemove = new List<int>(); foreach (var singleProgress in progress) { int progressForThread = singleProgress.Value; ctx.Save(); clipBound.Width = width * (progressForThread / 100.0); ctx.Rectangle(clipBound); ctx.Clip(); ctx.RoundRectangle(bound.Inflate(-1, -1), NodeRadius); ctx.SetColor(NodeColorProgress); ctx.Fill(); ctx.Restore(); clipBound.Top += height; if (progressForThread >= 100 && progress.ContainsKey(singleProgress.Key)) { toRemove.Add(singleProgress.Key); } } foreach (int removeID in toRemove) { progress.Remove(removeID); } }
double DrawHeader(Context ctx) { Point textOffset = new Point(8, 4); textLayoutBold.Text = algorithm.Headline(); Size textSize = textLayoutBold.GetSize(); if (textSize.Width >= AbsMaxNodeSize.Width - textSize.Height * 2) { textLayoutBold.Width = textSize.Width = AbsMaxNodeSize.Width; } Point textPosition = bound.Location.Offset(textOffset); // headline background contentOffset.X = 6; contentOffset.Y = textOffset.Y + textSize.Height + 4; ctx.RoundRectangle(bound.Left + 1, bound.Top + 1, bound.Width - 2, contentOffset.Y, NodeRadius); ctx.SetColor(NodeHeadlineBackground); ctx.Fill(); // text ctx.SetColor(NodeHeadlineTextColor); ctx.DrawTextLayout(textLayoutBold, textPosition); // icons double iconWidth = 0.0; foreach (var icon in icons) { if (icon.Value.Visible) { iconWidth = icon.Value.Bounds.Width; icon.Value.Bounds = new Rectangle(bound.Width - icon.Value.Bounds.Width - 10, 3, icon.Value.Bounds.Width, icon.Value.Bounds.Height); ctx.DrawImage( icon.Value.Image, bound.Location.Offset(icon.Value.Bounds.Location) ); } } double width = textSize.Width + iconWidth + 10 + NodeTextMargin; return width; }
void DrawBackground(Context ctx) { // draw shadow ctx.RoundRectangle(bound.Inflate(-1, -1).Offset(1, 3), NodeRadius); ctx.SetColor(NodeColorShadow); ctx.SetLineWidth(4); ctx.Stroke(); // border ctx.RoundRectangle(bound.Inflate(-1, -1), NodeRadius); ctx.SetColor(NodeColorBorder); ctx.SetLineWidth(2); ctx.StrokePreserve(); // background ctx.SetColor(NodeColor); ctx.Fill(); if (hover) { // draw glow ctx.RoundRectangle(bound.Inflate(1, 1), NodeRadius * 2); ctx.SetColor(NodeColorGlow); ctx.SetLineWidth(1); ctx.Stroke(); } }