void DrawScene(DrawingContext dc) { dc.DrawEllipse(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), null, new Point(50, 18), 12, 12); dc.DrawEllipse(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Point(50, 51), 12, 12); dc.DrawEllipse(null, new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Point(50, 87), 12, 12); dc.DrawRectangle(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), null, new Rect(25, 111, 24, 24)); dc.DrawRectangle(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Rect(25, 147, 24, 24)); dc.DrawRectangle(null, new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Rect(25, 184, 24, 24)); dc.DrawRoundedRectangle(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), null, new Rect(25, 237, 24, 24), 5, 5); dc.DrawRoundedRectangle(new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)), new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Rect(25, 270, 24, 24), 5, 5); dc.DrawRoundedRectangle(null, new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Rect(25, 307, 24, 24), 5, 5); dc.DrawLine(new Pen(new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)), 3), new Point(50, 340), new Point (70, 360)); }
private void DrawInnerBorder(DrawingContext dc, ref Rect bounds) { if (!base.IsEnabled && !this.RoundCorners) { return; } if (bounds.Width >= 4.0 && bounds.Height >= 4.0) { Pen innerBorderPen = this.InnerBorderPen; if (innerBorderPen != null) { dc.DrawRoundedRectangle(null, innerBorderPen, new Rect(bounds.Left + 1.5, bounds.Top + 1.5, bounds.Width - 3.0, bounds.Height - 3.0), 1.75, 1.75); } } }
protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); var brush = new SolidColorBrush(BACKGROUND_COLOR); var pen = new Pen(new SolidColorBrush(OUTLINE_COLOR), 1.0); var rect = new Rect(new Size(this.Width, this.Height)); drawingContext.DrawRoundedRectangle(brush, pen, rect, 16.0, 16.0); var textX = (this.Width - message.Width) / 2.0; var textY = (this.Height - message.Height) / 2.0; drawingContext.DrawText(message, new Point(textX, textY)); }
protected Drawing DrawTitle(Point point) { var title = new DrawingVisual(); using (DrawingContext dc = title.RenderOpen()) { var radius = 5; var brush = Brushes.AliceBlue; if (Status == EntityStatus.Selected) brush = Brushes.Orange; dc.PushOpacity(0.5); dc.DrawRoundedRectangle(brush, null, new Rect(point - new Vector(radius, radius), point + new Vector(formattedText.Width + radius, formattedText.Height + radius)), radius, radius); dc.Pop(); dc.DrawText(formattedText, point); } return title.Drawing; }
protected override void OnRender(DrawingContext drawingContext) { var adornerLocation = Location; adornerLocation.Offset(-Offset.X, -Offset.Y); Rect adornedElementRect = new Rect(adornerLocation, AdornedElement.DesiredSize); var visualBrush = new VisualBrush(AdornedElement); Pen border = new Pen(new SolidColorBrush(Color.FromRgb(229, 255, 77)), 1.5); drawingContext.DrawRoundedRectangle( visualBrush, border, adornedElementRect, this.AdornedElement.DesiredSize.Width / 2, this.AdornedElement.DesiredSize.Height / 2); }
protected static void PrintStack(DrawingContext dc, IList <FormattedText> labels) { dc.DrawRoundedRectangle(TextBackgroundBrush, TextBoxStrokePen, new Rect(-HorizontalStackPadding - TextBoxStrokePen.Thickness * 0.5, -TextBoxStrokePen.Thickness * 0.5 - VerticalStackPadding, Math.Round(labels.Max(l => l.Width)) + 2 * HorizontalStackPadding, Math.Round(labels.Sum(l => l.Height + 1)) + 2 * VerticalStackPadding), 2, 2); double yOffset = 0; foreach (var label in labels) { dc.DrawText(label, new Point(0, yOffset)); yOffset += label.Height + 1; } }
public DrawGraphicsOnBitmap() { Title = "Draw Graphics on Bitmap"; // Установка фон, чтобы продемонстрировать прозрачность растрового изображения. Background = Brushes.Khaki; // создание объекта RenderTargetBitmap RenderTargetBitmap renderbitmap = new RenderTargetBitmap(100, 100, 96, 96, PixelFormats.Default); // создание DrawingVisual объекта DrawingVisual drawvis = new DrawingVisual(); DrawingContext dc = drawvis.RenderOpen(); dc.DrawRoundedRectangle(Brushes.Blue, new Pen(Brushes.Red, 10), new Rect(25, 25, 50, 50), 1, 100); //параметры картинки(цвет, форма, положение) dc.Close(); // визуализирование DrawingVisual на RenderTargetBitmap. renderbitmap.Render(drawvis); // создание объекта Image и установка его Source изображения Image img = new Image(); img.Source = renderbitmap; // объект Image - содержимое окна Content = img; }
//Override OnRender protected override void OnRender(DrawingContext dc) { //base.OnRender(dc); RadialGradientBrush brush = new RadialGradientBrush( IsPressed ? SystemColors.ControlDarkColor : SystemColors.ControlLightLightColor, SystemColors.ControlColor); brush.GradientOrigin = IsPressed ? new Point(0.75, 0.75) : new Point(0.25, 0.25); dc.DrawRoundedRectangle(brush, new Pen(SystemColors.ControlDarkDarkBrush, 1), new Rect(new Point(0, 0), RenderSize), RenderSize.Height / 2, RenderSize.Height / 2); }
public void Draw(TextView textView, DrawingContext drawingContext) { textView.EnsureVisualLines(); foreach (Rect r in BackgroundGeometryBuilder.GetRectsForSegment(textView, new TextSegment() { StartOffset = editor.Document.GetLineByOffset(editor.CaretOffset).Offset })) { drawingContext.DrawRoundedRectangle( new SolidColorBrush(Color.FromArgb(30, 218, 165, 32)), new Pen(new SolidColorBrush(Color.FromArgb(250, 0xff, 0xff, 0xff)), 1), new Rect(r.Location, new Size(textView.ActualWidth, r.Height)), 3, 3); } }
private void _DrawBottom(DrawingContext ctx, double hoffset, double voffset, bool hasGlassBorder = true) { if (hasGlassBorder) { //绘制玻璃外观 ctx.PushOpacity(Constants.DragOpacity); ctx.DrawRectangle(Brushes.White, ResourceManager.BorderPen, new Rect(hoffset, voffset - Constants.DropUnitLength, Constants.DropUnitLength, Constants.DropUnitLength)); ctx.Pop(); } if ((Flag & DragManager.ACTIVE) == 0) { ctx.PushOpacity(Constants.DragOpacity * 1.8); } ctx.DrawRoundedRectangle(Brushes.White, null, new Rect(hoffset += Constants.DropGlassLength, (voffset -= Constants.DropGlassLength) - (Constants.DropUnitLength - Constants.DropGlassLength * 2), Constants.DropUnitLength - Constants.DropGlassLength * 2, Constants.DropUnitLength - Constants.DropGlassLength * 2), 3, 3); hoffset += Constants.DropGlassLength; voffset -= Constants.DropGlassLength; ctx.DrawLine(ResourceManager.DropRectPen_Heavy, new Point(hoffset - 0.5, voffset - 12), new Point(hoffset + Constants.DropUnitLength - Constants.DropGlassLength * 4 + 0.5, voffset - 12)); //绘制小窗口 StreamGeometry stream = new StreamGeometry(); using (var sctx = stream.Open()) { double currentX = hoffset, currentY = voffset - 12; sctx.BeginFigure(new Point(currentX, currentY), true, false); sctx.LineTo(new Point(currentX, currentY += 12), true, true); sctx.LineTo(new Point(currentX += Constants.DropUnitLength - Constants.DropGlassLength * 4, currentY), true, true); sctx.LineTo(new Point(currentX, currentY -= 12), true, true); sctx.Close(); } ctx.DrawGeometry(null, ResourceManager.DropRectPen, stream); //绘制方向箭头 stream = new StreamGeometry(); using (var sctx = stream.Open()) { double currentX = hoffset + (Constants.DropUnitLength - Constants.DropGlassLength * 4) / 2, currentY = voffset - 20; sctx.BeginFigure(new Point(currentX, currentY), true, true); sctx.LineTo(new Point(currentX += 5, currentY -= 5), true, true); sctx.LineTo(new Point(currentX -= 10, currentY), true, true); sctx.Close(); } ctx.DrawGeometry(Brushes.Black, null, stream); }
// OnRender called to redraw the button. protected override void OnRender(DrawingContext dc) { // Determine background color. Brush brushBackground = SystemColors.ControlBrush; if (isMouseReallyOver && IsMouseCaptured) { brushBackground = SystemColors.ControlDarkBrush; // allow OnRender to correctly color the button background } // Determine pen width. Pen pen = new Pen(Foreground, IsMouseOver ? 2 : 1); // Draw filled rounded rectangle. dc.DrawRoundedRectangle(brushBackground, pen, new Rect(new Point(0, 0), RenderSize), 4, 4); // draw the button border and background // Determine foreground color. formtxt.SetForegroundBrush(IsEnabled ? Foreground : SystemColors.ControlDarkBrush); // The text normally has a color based on the Foreground property defined by Control // Determine start point of text. Point ptText = new Point(2, 2); // initialized to the point (2, 2) to allow room for the border drawn by the Rectangle call. switch (HorizontalContentAlignment) // calculate a starting position of the text based on HorizontalContentAlignment. { case HorizontalAlignment.Left: ptText.X += Padding.Left; break; case HorizontalAlignment.Right: ptText.X += RenderSize.Width - formtxt.Width - Padding.Right; break; case HorizontalAlignment.Center: case HorizontalAlignment.Stretch: ptText.X += (RenderSize.Width - formtxt.Width - Padding.Left - Padding.Right) / 2; break; } switch (VerticalContentAlignment) // calculate a starting position of the text based on VerticalContentAlignment { case VerticalAlignment.Top: ptText.Y += Padding.Top; break; case VerticalAlignment.Bottom: ptText.Y += RenderSize.Height - formtxt.Height - Padding.Bottom; break; case VerticalAlignment.Center: case VerticalAlignment.Stretch: ptText.Y += (RenderSize.Height - formtxt.Height - Padding.Top - Padding.Bottom) / 2; break; } // Draw the text. dc.DrawText(formtxt, ptText); } //display the text inside the button
protected override void DrawInnerBorder(DrawingContext dc, Rect bounds) { if (base.IsEnabled || this.RoundCorners) { return; } if (bounds.Width >= 4.0 && bounds.Height >= 4.0) { return; } if (InnerBorderPen != null) { dc.DrawRoundedRectangle(null, InnerBorderPen, new Rect(bounds.Left + 1.5, bounds.Top + 1.5, bounds.Width - 3.0, bounds.Height - 3.0), 1.75, 1.75); } }
protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height) { // Clip to rounded rectangle shape. dc.PushClip(new RectangleGeometry(new Rect(new Size(width, height)), Roundness, Roundness)); // Draw image. dc.PushTransform(new TranslateTransform(BorderWidth, BorderWidth)); dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height)); dc.Pop(); dc.Pop(); // Draw border. dc.DrawRoundedRectangle(null, new Pen(new SolidColorBrush(BorderColor.ToWpfColor()), BorderWidth), new Rect(BorderWidth / 2.0, BorderWidth / 2.0, width - BorderWidth, height - BorderWidth), Roundness, Roundness); }
// Draw the inner border private void DrawInnerBorder(DrawingContext dc, ref Rect bounds) { if (!IsEnabled && !RoundCorners) { return; } if ((bounds.Width >= 4.0) && (bounds.Height >= 4.0)) { Pen innerBorder = InnerBorderPen; if (innerBorder != null) { dc.DrawRoundedRectangle(null, innerBorder, new Rect(bounds.Left + 1.5, bounds.Top + 1.5, bounds.Width - 3.0, bounds.Height - 3.0), 1.75, 1.75); } } }
protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); if (dropInfo.Effects == DragDropEffects.None) { return; } var tvItem = dropInfo.TargetItem; var header = tvItem.HeaderBorder; var indent = AdornedElement.RenderSize.Width - header.RenderSize.Width; if (dropInfo.InsertPosition == DropInfo.RelativInsertPosition.IntoTargetItem) { drawingContext.DrawRoundedRectangle(Brushes.Transparent, pen, new Rect(new Point(indent, 0), (Point)AdornedElement.RenderSize), 2, 2); } else if (dropInfo.InsertPosition != DropInfo.RelativInsertPosition.None) { double yPos = 0.0; if (dropInfo.InsertPosition.HasFlag(DropInfo.RelativInsertPosition.AfterTargetItem)) { if (dropInfo.InsertPosition.HasFlag(DropInfo.RelativInsertPosition.IntoTargetItem)) { yPos = header.RenderSize.Height; var container = (TreeViewItemEx)tvItem.ItemContainerGenerator.ContainerFromIndex(0); if (container != null) { indent = AdornedElement.RenderSize.Width - container.HeaderBorder.RenderSize.Width; } } else { yPos = tvItem.RenderSize.Height; } } var p1 = new Point(indent, yPos); var p2 = new Point(AdornedElement.RenderSize.Width, yPos); drawingContext.DrawLine(pen, p1, p2); DrawTriangle(drawingContext, p1, 0); DrawTriangle(drawingContext, p2, 180); } }
public void Draw(TextView textView, DrawingContext drawingContext) { textView.EnsureVisualLines(); var line = TextEditor.Document.GetLineByOffset(TextEditor.Caret.Offset); var segment = new TextSegment { StartOffset = line.Offset, EndOffset = line.EndOffset }; foreach (System.Windows.Rect r in BackgroundGeometryBuilder.GetRectsForSegment(textView, segment)) { drawingContext.DrawRoundedRectangle( new SolidColorBrush(Color.FromArgb(45, 180, 180, 180)), new Pen(new SolidColorBrush(Color.FromArgb(0, 255, 255, 255)), 1), new System.Windows.Rect(r.Location, new System.Windows.Size(textView.ActualWidth, r.Height)), 3, 3 ); } }
private bool DrawBackground(DrawingContext dc, ref Rect bounds) { // draw actual background Brush brush = Background; if (brush != null) { dc.DrawRoundedRectangle(brush, null, bounds, 3.0, 3.0); } if ((bounds.Width < 0.6) || (bounds.Height < 0.6)) { // out of space; we're done return(true); } return(false); }
protected override void OnRender(DrawingContext drawingContext) { var dropInfo = this.DropInfo; var visualTargetItem = dropInfo.VisualTargetItem; if (visualTargetItem != null) { var rect = Rect.Empty; if (visualTargetItem is TreeViewItem tvItem && VisualTreeHelper.GetChildrenCount(tvItem) > 0) { var descendant = VisualTreeHelper.GetDescendantBounds(tvItem); var translatePoint = tvItem.TranslatePoint(new Point(), this.AdornedElement); var itemRect = new Rect(translatePoint, tvItem.RenderSize); descendant.Union(itemRect); translatePoint.Offset(1, 0); rect = new Rect(translatePoint, new Size(descendant.Width - translatePoint.X - 1, tvItem.ActualHeight)); } if (visualTargetItem is ListBoxItem listBoxItem) { rect = new Rect(visualTargetItem.TranslatePoint(new Point(), this.AdornedElement), new Size(listBoxItem.ActualWidth, listBoxItem.ActualHeight)); var geometry = Squircle.Helpers.SquirclePathGenerator .GetGeometry(rect.Width, rect.Height); geometry.Transform = new TranslateTransform(rect.Left, rect.Top); drawingContext.DrawGeometry(null, Pen, geometry); return; } if (rect.IsEmpty) { rect = new Rect(visualTargetItem.TranslatePoint(new Point(), this.AdornedElement), VisualTreeHelper.GetDescendantBounds(visualTargetItem).Size); } drawingContext.DrawRoundedRectangle(null, this.Pen, rect, 2, 2); } }
DrawLabelBackground ( DrawingContext oDrawingContext, GraphDrawingContext oGraphDrawingContext, FormattedText oFormattedText, Color oFormattedTextColor, Byte btBackgroundAlpha, Point oTextOrigin ) { Debug.Assert(oDrawingContext != null); Debug.Assert(oGraphDrawingContext != null); Debug.Assert(oFormattedText != null); AssertValid(); if (oFormattedText.Width == 0 || oFormattedText.Height == 0) { return; } // Note: Don't make the background any more opaque than the text, which // might be translucent itself. Color oBackgroundColor = WpfGraphicsUtil.SetWpfColorAlpha( oGraphDrawingContext.BackColor, Math.Min(btBackgroundAlpha, oFormattedTextColor.A)); SolidColorBrush oBackgroundBrush = CreateFrozenSolidColorBrush( oBackgroundColor); Rect oBackgroundRectangle = WpfGraphicsUtil.GetFormattedTextBounds( oFormattedText, oTextOrigin); // Draw a rounded rectangle with a small amount of padding. const Int32 Padding = 1; const Int32 Radius = 2; oBackgroundRectangle.Inflate(Padding, Padding); oDrawingContext.DrawRoundedRectangle(oBackgroundBrush, null, oBackgroundRectangle, Radius, Radius); }
// Create a DrawingVisual that contains a rectangle. public DrawingVisual DrawRoundedRectangle(Point location, Size size, UInt16 radius, Brush brush, Pen pen) { DrawingVisual drawingVisual = new DrawingVisual(); // Retrieve the DrawingContext in order to create new drawing content. DrawingContext drawingContext = drawingVisual.RenderOpen(); // Create a rectangle and draw it in the DrawingContext. Rect rect = new Rect(location, size); drawingContext.DrawRoundedRectangle(brush, pen, rect, radius, radius); // Persist the drawing content. drawingContext.Close(); this.children.Add(drawingVisual); return(drawingVisual); }
private BitmapSource LoadHexTypesTile(int hextypes_id, BitmapImage image, bool need_upscale, bool is_highlighted, int tile_width, int tile_height) { Int32Rect rect = new Int32Rect(); //HexTypes images are 6 per 13 where odd rows are normal highlighted images and even the normal ones int nRowIndex = ((hextypes_id - 1) / 13) * 2; int nColumnIndex = (hextypes_id - 1) % 13; if (is_highlighted == false) { nRowIndex += 1; } rect.X = nColumnIndex * tile_width; rect.Y = nRowIndex * tile_height; rect.Width = tile_width; rect.Height = tile_height; //TODO: if for some reason in the future someone makes big hextypes images the random string will need to be written with rendered pixels measures instead of hard coded values BitmapSource tile = Images.Images.CopyImageRectWithDpi(image, rect, App.I.DpiX, App.I.DpiY); //this is a special tile, in-game it just randomizes the tile, so let's add text saying that if (hextypes_id == 4) { DrawingVisual visual = new DrawingVisual(); using (DrawingContext drawingContext = visual.RenderOpen()) { drawingContext.DrawImage(tile, new Rect(0, 0, tile.PixelWidth, tile.PixelHeight)); SolidColorBrush semiTransBrush = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)); drawingContext.DrawRoundedRectangle(semiTransBrush, null, new Rect(10, 34, 80, 22), 5, 5); FormattedText text = new FormattedText("Random", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Segoe UI"), 20.0, Brushes.Red); drawingContext.DrawText(text, new Point(14, 30)); } RenderTargetBitmap mergedImage = new RenderTargetBitmap(tile.PixelWidth, tile.PixelHeight, image.DpiX, image.DpiY, PixelFormats.Pbgra32); mergedImage.Render(visual); tile = Images.Images.ConvertImageDpi(mergedImage, App.I.DpiX, App.I.DpiY); } if (need_upscale) { tile = new TransformedBitmap(tile, new ScaleTransform(2, 2)); } return(tile); }
private void DrawBorder(DrawingContext dc, ref Rect bounds) { // draw border Pen borderPen = BorderPen; if ((borderPen != null) && (bounds.Width >= 1.0) && (bounds.Height >= 1.0)) { dc.DrawRoundedRectangle( null, borderPen, new Rect( bounds.Left + 0.5, bounds.Top + 0.5, bounds.Width - 1.0, bounds.Height - 1.0), 2.0, 2.0); } }
private void DrawInnerHighlight(DrawingContext dc, ref Rect bounds) { // draw inner highlight Pen pen = InnerHighlight; if (pen != null && (bounds.Width >= (8.0 / 3.0)) && (bounds.Height >= (8.0 / 3.0))) { dc.DrawRoundedRectangle( null, pen, new Rect( bounds.Left + 4.0 / 3.0, bounds.Top + 4.0 / 3.0, bounds.Width - 8.0 / 3.0, bounds.Height - 8.0 / 3.0), 2.0, 2.0); } }
protected override void OnRender(DrawingContext dc) { base.OnRender(dc); double radius = new[] { Radius, this.RenderSize.Width / 2, this.RenderSize.Height / 2 }.Min(); dc.DrawRoundedRectangle( Fill, new Pen(Stroke, StrokeThickness), new Rect( new Point(), this.RenderSize), radius, radius); }
protected override void OnRender(DrawingContext drawingContext) { if (HintText == null) { return; } var formattedHint = new FormattedText(HintText, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, ArialFace, 12, Brushes.Blue); var pos = new Point(_cursorPosition.X + CursorMargin, _cursorPosition.Y + CursorMargin); var textPos = new Point(pos.X + 3 * Padding, pos.Y + 3 * Padding); var fontRectPos = new Point(textPos.X - Padding, textPos.Y - Padding); var fontRect = new Rect(fontRectPos, new Size(formattedHint.Width + Padding * 2, formattedHint.Height + Padding * 2)); drawingContext.DrawRoundedRectangle(BackgroundBrush, BorderPen, fontRect, 5, 5); drawingContext.DrawText(formattedHint, textPos); }
private void DrawNoteBody(UNote note, DrawingContext cxt) { double left = note.PosTick * midiVM.QuarterWidth / DocManager.Inst.Project.Resolution + 1; double top = midiVM.TrackHeight * ((double)UIConstants.MaxNoteNum - 1 - note.NoteNum) + 1; double width = Math.Max(2, note.DurTick * midiVM.QuarterWidth / DocManager.Inst.Project.Resolution - 1); double height = Math.Max(2, midiVM.TrackHeight - 2); cxt.DrawRoundedRectangle( note.Error ? note.Selected ? ThemeManager.NoteFillSelectedErrorBrushes : ThemeManager.NoteFillErrorBrushes[0] : note.Selected ? ThemeManager.NoteFillSelectedBrush : ThemeManager.NoteFillBrushes[0], null, new Rect(new Point(left, top), new Size(width, height)), 2, 2); if (height >= 10) { if (note.Lyric.Length == 0) { return; } string displayLyric = note.Lyric; if (!fTextPool.ContainsKey(displayLyric)) { AddToFormattedTextPool(displayLyric); } var fText = fTextPool[displayLyric]; if (fTextWidths[displayLyric] + 5 > width) { displayLyric = note.Lyric[0] + ".."; if (!fTextPool.ContainsKey(displayLyric)) { AddToFormattedTextPool(displayLyric); } fText = fTextPool[displayLyric]; if (fTextWidths[displayLyric] + 5 > width) { return; } } cxt.DrawText(fText, new Point((int)left + 5, Math.Round(top + (height - fTextHeights[displayLyric]) / 2))); } }
protected override void OnRender(DrawingContext drawingContext) { var app = DataContext as MainViewModel; if (app?.LedStrips?.Leds is Led[] allLeds && allLeds.Where(_ => !_.GrabArea.IsEmpty).ToArray() is Led[] leds && leds.Any() && (app.ScreenGrabber.Frame is ScreenFrame frame)) { var fade = app.LedDevice?.CurrentFade ?? 1; drawingContext.DrawRectangle(Brushes.Bisque, _borderPen, new Rect(0, 0, ActualWidth, ActualHeight)); drawingContext.DrawRectangle(Brushes.Pink, _borderPen, new Rect(frame.Margins.Left, frame.Margins.Top, app.ScreenGrabber.Screen.ScreenSize.Width - frame.Margins.Left - frame.Margins.Right, app.ScreenGrabber.Screen.ScreenSize.Height - frame.Margins.Top - frame.Margins.Bottom)); //foreach (var led in leds) //{ // drawingContext.DrawRoundedRectangle(new SolidColorBrush(Color.Multiply(led.Color, (float) fade * 0.3f)), _borderPen, led.GrabArea, 5, 5); //} foreach (var led in leds) { if (led.Location != led.ConnectorPoint) { drawingContext.DrawEllipse(Brushes.Black, null, led.ConnectorPoint, 5, 5); drawingContext.DrawLine(_borderPen, led.ConnectorPoint, led.Location); } drawingContext.DrawRoundedRectangle(Brushes.Transparent, _borderPen, led.GrabArea, 5, 5); } foreach (var led in leds) { var c = Color.Multiply(led.Color, (float)fade); drawingContext.PushClip(new CombinedGeometry(GeometryCombineMode.Exclude, new RectangleGeometry(new Rect(-300, -300, ActualWidth + 600, ActualHeight + 600)), new RectangleGeometry(new Rect(0, 0, ActualWidth, ActualHeight)))); drawingContext.DrawEllipse(new SolidColorBrush(c), null, led.Location, 250, 250); drawingContext.Pop(); } } }
//protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e) //{ // Generate(); // e.Handled = true; // base.OnMouseLeftButtonDown(e); //} protected override void OnRender(DrawingContext drawingContext) { if (_childSize.Width > 0 && _childSize.Width + Padding.Right * 2 < MaxWidth) { this.Width = _childSize.Width + Padding.Right * 2; } if (_childSize.Height > 0 && _childSize.Height + Padding.Bottom * 2 < MaxHeight) { this.Height = _childSize.Height + Padding.Bottom * 2; } var bgRect = new Rect(0, 0, this.Width, this.Height); if (!bgRect.IsEmpty) { drawingContext.DrawRoundedRectangle(Background, new Pen(BorderBrush, BorderThickness), bgRect, 3, 3); } base.OnRender(drawingContext); }
private void Render(DrawingContext drawingContext) { var zoom = Convert.ToDouble(App.Current.Resources["Zoom"] ?? 1); var scrollX = 0d; var scrollY = 0d; if (_element is ScrollViewer) { scrollX = ((ScrollViewer)_element).HorizontalOffset; scrollY = ((ScrollViewer)_element).VerticalOffset; } var cursorPosition = Mouse.GetPosition(_element); var width = this.Width * zoom; var height = this.Height * zoom; var snapWidth = this.SnapWidth * zoom; var snapHeight = this.SnapHeight * zoom; var scrollOffsetX = (int)scrollX % snapWidth; var scrollOffsetY = (int)scrollY % snapHeight; var snapX = (int)((cursorPosition.X + scrollOffsetX) / snapWidth) * snapWidth - scrollOffsetX; var snapY = (int)((cursorPosition.Y + scrollOffsetY) / snapHeight) * snapHeight - scrollOffsetY; var finalX = snapX - (_hotX * zoom); var finalY = snapY - (_hotY * zoom); drawingContext.DrawImage(this.CursorImage, new Rect( finalX, finalY, width, height) ); if (DrawOutline) { drawingContext.DrawRectangle(null, outlinePen, new Rect(finalX, finalY, width, height)); drawingContext.DrawRoundedRectangle(null, shadowPen, new Rect(finalX - 1, finalY - 1, width + 2, height + 2), 2, 2); } }
internal void GiveFrame(DepthImageFrame depthFrame, PointCluster floodFill) { short[] imagePixelData = new short[depthFrame.PixelDataLength]; depthFrame.CopyPixelDataTo(imagePixelData); float RenderWidth = 640.0f; float RenderHeight = 480.0f; Bitmap bmap = new System.Drawing.Bitmap(depthFrame.Width, depthFrame.Height, System.Drawing.Imaging.PixelFormat.Format16bppRgb555); System.Drawing.Imaging.BitmapData bmapdata = bmap.LockBits(new System.Drawing.Rectangle(0, 0, depthFrame.Width , depthFrame.Height), ImageLockMode.WriteOnly, bmap.PixelFormat); IntPtr ptr = bmapdata.Scan0; System.Runtime.InteropServices.Marshal.Copy(imagePixelData, 0, ptr, depthFrame.Width * depthFrame.Height); bmap.UnlockBits(bmapdata); /*System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmap); * this.myImageBox.Source = * System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( * bmap.GetHbitmap(), * IntPtr.Zero, * System.Windows.Int32Rect.Empty, * BitmapSizeOptions.FromWidthAndHeight((int)this.myImageBox.Width, (int)this.myImageBox.Height));*/ using (DrawingContext lfdc = drawingGroup.Open())//this.liveFeedbackGroup.Open()) { lfdc.DrawImage(System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( bmap.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight((int)RenderWidth, (int)RenderHeight)), //BitmapSizeOptions.FromWidthAndHeight((int)this.myImageBox.ActualWidth, (int)this.myImageBox.ActualHeight)), new Rect(0.0, 0.0, RenderWidth, RenderHeight)); foreach (DepthPoint point in floodFill.points) { lfdc.DrawRoundedRectangle(System.Windows.Media.Brushes.Red, null, new Rect(point.x, point.y, 3, 3), null, 1, null, 1, null); } } }
protected virtual bool DrawOuterHighlight(DrawingContext dc, Rect bounds) { if (bounds.Width < 1.33 || bounds.Height < 1.33) { return(true); } if (this.OuterHighlight != null) { dc.DrawRoundedRectangle(null, this.OuterHighlight, new Rect(0.66, 0.66, bounds.Width - 1.33, bounds.Height - 1.33), 3.0, 3.0); } if (bounds.Width < 1.5 || bounds.Height < 1.5) { return(true); } bounds.Inflate(-0.75, -0.75); return(false); }