public MFTestResults DrawingContext_DrawLineTest1() { MFTestResults testResult = MFTestResults.Pass; Log.Comment("Drawing 10 diff. Lines and verifying pixel color on the center"); _pen = new Pen(Colors.Green); Random random = new Random(); for (int i = 0; i < 10; i++) { x0 = random.Next(midX); y0 = random.Next(midY); x1 = random.Next(_width); y1 = random.Next(_height); if (ClearingPanel() != MFTestResults.Pass) { return MFTestResults.Fail; } _drawLine = true; Log.Comment("Drawing Line b/n (" + x0.ToString() + ", " + y0.ToString() + ") and (" + x1.ToString() + ", " + y1.ToString() + ") and Verifying"); Master_Media._panel.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(InvalidatePanel), null); autoEvent.WaitOne(); testResult = VerifyingPixelColor(new Point[] { new Point(x0 + ((x1 - x0) / 2), y0 + ((y1 - y0) / 2)) }, Colors.Green); _drawLine = false; } return testResult; }
/// <summary> /// Creates new UniverseView for specified GameUniverse /// </summary> /// <param name="gameUniverse">GameUniverse to visualize</param> public UniverseView(GameUniverse gameUniverse) { this.gameUniverse = gameUniverse; blockPen = new Pen(Color.Black); gridPen = new Pen(ColorUtility.ColorFromRGB(25, 25, 25)); }
public MFTestResults DrawingContext_DrawRectangleTest2() { MFTestResults testResult = MFTestResults.Pass; xDimension = midX - 1; yDimension = midY - 1; r = midX; s = midY; _pen = new Pen(Colors.Green); _brush = new SolidColorBrush(Colors.Blue); if (ClearingPanel() != MFTestResults.Pass) { return MFTestResults.Fail; } _drawRectangle = true; Master_Media._panel.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(InvalidatePanel), null); autoEvent.WaitOne(); Log.Comment("Initializing 40 Random Points that are inside the rectangle"); Point[] chkPoints = GetRandomPoints_InRectangle(40, xDimension, yDimension, r + xDimension / 2, s + yDimension / 2); Log.Comment("Verifying the pixel colors inside the rectangle"); testResult = VerifyingPixelColor(chkPoints, Colors.Blue); _drawRectangle = false; return testResult; }
protected internal override void RenderRectangle(Bitmap bmp, Pen pen, int x, int y, int width, int height) { Color outlineColor = (pen != null) ? pen.Color : (Color)0x0; ushort outlineThickness = (pen != null) ? pen.Thickness : (ushort)0; int x1, y1; int x2, y2; switch (MappingMode) { case BrushMappingMode.RelativeToBoundingBox: x1 = x + (int)((long)(width - 1) * StartX / RelativeBoundingBoxSize); y1 = y + (int)((long)(height - 1) * StartY / RelativeBoundingBoxSize); x2 = x + (int)((long)(width - 1) * EndX / RelativeBoundingBoxSize); y2 = y + (int)((long)(height - 1) * EndY / RelativeBoundingBoxSize); break; default: //case BrushMappingMode.Absolute: x1 = StartX; y1 = StartY; x2 = EndX; y2 = EndY; break; } bmp.DrawRectangle(outlineColor, outlineThickness, x, y, width, height, 0, 0, StartColor, x1, y1, EndColor, x2, y2, Opacity); }
public CalibrationWindow(Font font, string txt) { Height = SystemMetrics.ScreenHeight; Width = SystemMetrics.ScreenWidth; Visibility = Visibility.Visible; //Buttons.Focus(this); pen = new Pen(ColorUtility.ColorFromRGB(255, 0, 0), 1); Text text = new Text(); text.Font = font; text.ForeColor = Colors.Blue; text.TextContent = txt; text.TextWrap = true; text.SetMargin(0, 0, 0, SystemMetrics.ScreenHeight / 2); text.TextAlignment = TextAlignment.Center; text.HorizontalAlignment = HorizontalAlignment.Center; text.VerticalAlignment = VerticalAlignment.Center; Child = text; CalibrationManager.PrepareCalibrationPoints(); CalibrationManager.StartCalibration(); idx = 0; Invalidate(); }
protected internal override void RenderEllipse(Bitmap bmp, Pen pen, int x, int y, int xRadius, int yRadius) { Color outlineColor = (pen != null) ? pen.Color : (Color)0x0; ushort outlineThickness = (pen != null) ? pen.Thickness : (ushort)0; bmp.DrawEllipse(outlineColor, outlineThickness, x, y, xRadius, yRadius, Color, 0, 0, Color, 0, 0, Opacity); }
/// <summary> /// Creates new NextBlockView element for given GameUniverse /// </summary> /// <param name="gameUniverse">GameUniverse to visualize</param> public NextBlockView(GameUniverse gameUniverse) { this._universe = gameUniverse; _blockPen = new Pen(Color.Black); _linePen = new Pen(Colors.White, 4); _fillBrush = new SolidColorBrush(ColorUtility.ColorFromRGB(164, 164, 164)); }
protected internal override void RenderRectangle(Bitmap bmp, Pen pen, int x, int y, int width, int height) { Color outlineColor = (pen != null) ? pen.Color : (Color)0x0; ushort outlineThickness = (pen != null) ? pen.Thickness : (ushort)0; bmp.DrawRectangle(outlineColor, outlineThickness, x, y, width, height, 0, 0, Color, 0, 0, Color, 0, 0, Opacity); }
public Led(int width, int height) { Width = width; Height = height; activeBrush = new SolidColorBrush(ColorUtility.ColorFromRGB(0, 240, 0)); //activeBrush = new SolidColorBrush(ColorUtility.ColorFromRGB(90, 90, 255)); inactiveBrush = new SolidColorBrush(Colors.DarkGray); border = new Pen(Colors.DarkGray, 1); Invalidate(); }
public Button(UIElement content) { brushUnpressed = new SolidColorBrush(Colors.Black); brushUnpressed.Opacity = 10; brushPressed = new SolidColorBrush(ColorUtility.ColorFromRGB(128, 255, 0)); brushPressed.Opacity = 200; brushTransparent = new SolidColorBrush(Colors.Red); brushTransparent.Opacity = Bitmap.OpacityTransparent; border = new Pen(Colors.DarkGray, 1); Content = content; }
public void DrawPolygon(Brush brush, Pen pen, int[] pts) { VerifyAccess(); brush.RenderPolygon(_bitmap, pen, pts); int nPts = pts.Length / 2; for (int i = 0; i < nPts - 1; i++) { DrawLine(pen, pts[i * 2], pts[i * 2 + 1], pts[i * 2 + 2], pts[i * 2 + 3]); } if (nPts > 2) { DrawLine(pen, pts[nPts * 2 - 2], pts[nPts * 2 - 1], pts[0], pts[1]); } }
public override void OnRender(DrawingContext dc) { base.OnRender(dc); if (isSelected) { Pen pen = new Pen(Colors.DarkGray, 1); // top border dc.DrawLine(pen, 0, 0, ActualWidth - 1, 0); // left border dc.DrawLine(pen, 0, 0, 0, ActualHeight - 1); // right border dc.DrawLine(pen, ActualWidth - 1, 0, ActualWidth - 1, ActualHeight - 1); // bottom border dc.DrawLine(pen, 0, ActualHeight - 1, ActualWidth - 1, ActualHeight - 1); } }
protected internal override void RenderRectangle(Bitmap bmp, Pen pen, int x, int y, int width, int height) { if (Stretch == Stretch.None) { bmp.DrawImage(x, y, BitmapSource, 0, 0, BitmapSource.Width, BitmapSource.Height, Opacity); } else if (width == BitmapSource.Width && height == BitmapSource.Height) { bmp.DrawImage(x, y, BitmapSource, 0, 0, width, height, Opacity); } else { bmp.StretchImage(x, y, BitmapSource, width, height, Opacity); } if (pen != null && pen.Thickness > 0) { bmp.DrawRectangle(pen.Color, pen.Thickness, x, y, width, height, 0, 0, (Color)0, 0, 0, (Color)0, 0, 0, 0); } }
public MFTestResults EllipseTest_EllipseFill9() { MFTestResults testResult = MFTestResults.Pass; int xRad = min / 3; Point pt = new Point(xRad, xRad); try { if (ClearingPanel() != MFTestResults.Pass) { return MFTestResults.Fail; } Log.Comment("Setting the Pen and Brush"); _pen = new Pen(Colors.Red, 1); _brush = new SolidColorBrush(Colors.Green); Log.Comment("Invoking the Dispatcher on a panel"); Log.Comment("Drawing a Circle(Ellipse)with radius = " + pt.x.ToString() + " and yRadius = " + pt.y.ToString()); Master_Shapes._panel.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(DrawEllipse), new Point(pt.x, pt.y)); autoEvent.WaitOne(); Thread.Sleep( 100 ); Log.Comment("Initializing 40 random points inside the largest square inside the circle"); int s = (int)(2 * xRad / sqrt2); int x = midX - s / 2; int y = midY - s / 2; Point[] chkPoints = GetRandomPoints_InRectangle(40, s-2, s-2, x+1, y+1); Log.Comment("Veifying The pixel colors inside the Circle"); if (VerifyingPixelColor(chkPoints, Colors.Green) != MFTestResults.Pass) { testResult = MFTestResults.Fail; } } catch (Exception ex) { Log.Comment("Caught : " + ex.Message); return MFTestResults.Fail; } return testResult; }
public MFTestResults DrawingContext_DrawEllipseTest4() { MFTestResults testResult = MFTestResults.Pass; xDimension = midX - 10; yDimension = midY - 10; r = midX; s = midY; _pen = new Pen(Colors.Red); _brush = new SolidColorBrush(Colors.Green); if (ClearingPanel() != MFTestResults.Pass) { return MFTestResults.Fail; } _drawEllipse = true; Master_Media._panel.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(InvalidatePanel), null); autoEvent.WaitOne(); Log.Comment("Checking pixel colors on the ellipse"); Point[] chkPoints1 = new Point[] { new Point(r+xDimension, s), new Point(r-xDimension, s), new Point(r, s+yDimension), new Point(r, s-yDimension)}; if (VerifyingPixelColor(chkPoints1, Colors.Red) != MFTestResults.Pass) { testResult = MFTestResults.Fail; } Log.Comment("Checking pixel colors inside the ellipse"); int minSquare = 2 * (int)(System.Math.Min(xDimension, yDimension) / 1.5); Log.Comment("Initializing 40 Random Points that are inside the rectangle"); Point[] chkPoints2 = GetRandomPoints_InRectangle(40, minSquare, minSquare, r, s); Log.Comment("Verifying the pixel colors inside the rectangle"); if (VerifyingPixelColor(chkPoints2, Colors.Green) != MFTestResults.Pass) { testResult = MFTestResults.Fail; } _drawEllipse = false; return testResult; }
public MFTestResults PolygonTest_PolygonFill5() { MFTestResults testResult = MFTestResults.Pass; try { if (ClearingPanel() != MFTestResults.Pass) { return MFTestResults.Fail; } Log.Comment("Setting the Pen and Brush"); _pen = new Pen(Colors.Red, 1); _brush = new SolidColorBrush(Colors.Green); Log.Comment("Draw a Regular Octagon"); DrawRegularOctagon(); autoEvent.WaitOne(); Thread.Sleep( 1000 ); Log.Comment("Initializing 40 Random Points inside the Horizontal rectangle in the Octagon"); int len = min / 6 + (int)(((double)min / 3) / sqrt2); int w1 = 2 * (len-1), h1 = (min -1) / 3; Point[] chkPoints1 = GetRandomPoints_InRectangle(40, w1, h1, midX - w1 / 2, midY - h1 / 2); Log.Comment("Veifying The pixel colors inside the Horizontal rectangle in the Octagon"); MFTestResults tRes1 = VerifyingPixelColor(chkPoints1, Colors.Green); Log.Comment("Initializing 40 Random Points inside the Vertical Rectangle in the Octagon"); int w2 = h1, h2 = w1; Point[] chkPoints2 = GetRandomPoints_InRectangle(40, w2, h2, midX - w2 / 2, midY - h2 / 2); Log.Comment("Veifying The pixel colors inside the Vertical rectangle in the Octagon"); MFTestResults tRes2 = VerifyingPixelColor(chkPoints1, Colors.Green); if ((tRes1 != MFTestResults.Pass) && (tRes2 != MFTestResults.Pass)) { testResult = MFTestResults.Fail; } } catch (Exception ex) { Log.Comment("Caught : " + ex.Message); return MFTestResults.Fail; } return testResult; }
public MFTestResults EllipseTest_EllipseThickness8() { MFTestResults testResult = MFTestResults.Pass; int xRad = min / 3, yRad = min / 3; Point pt = new Point(xRad, yRad); Point l, t, r, b; Color lc, tc, rc, bc; try { if (ClearingPanel() != MFTestResults.Pass) { return MFTestResults.Fail; } Log.Comment("Setting the Pen color and thickness"); ushort ellipseBorderThickness = 6; _ellipsePen = new Pen(Colors.Blue, ellipseBorderThickness); Log.Comment("Invoking the Dispatcher on a panel"); Log.Comment("Drawing Ellipse with xRadius = " + pt.x.ToString() + " and yRadius = " + pt.y.ToString()); Master_Shapes._panel.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(DrawEllipse), new Point(pt.x, pt.y)); autoEvent.WaitOne(); Thread.Sleep( 100 ); _ellipsePen = null; int x1 = 0 , x2 = 0, y1 = 0, y2 = 0; int i = 0; for (i = 0; i < midX; i++) { l = new Point(midX - i, midY); lc = _panel._pBitmap.GetPixel(l.x, l.y); if ((x1 == 0) && (lc == Colors.Blue)) { x1 = midX - i; } l = new Point(midX + i, midY); lc = _panel._pBitmap.GetPixel(l.x, l.y); if ((x2 == 0) && (lc == Colors.Blue)) { x2 = midX + i; } } for (i = 0; i < midY; i++) { l = new Point(midX, midY - i); lc = _panel._pBitmap.GetPixel(l.x, l.y); if ((y1 == 0) && (lc == Colors.Blue)) { y1 = midY - i; } l = new Point(midX, midY + i); lc = _panel._pBitmap.GetPixel(l.x, l.y); if ((y2 == 0) && (lc == Colors.Blue)) { y2 = midY + i; } } Log.Comment("Veifying The pixel colors at points on the Ellipse"); if ((x1 != 0) && (y1 != 0) && (x2 != 0) && (y2 != 0)) { for (i = 0; i < ellipseBorderThickness; i++) { l = new Point(x1 - i, midY); t = new Point(midX, y1 - i); r = new Point(x2 + i, midY); b = new Point(midX, y2 + i); lc = _panel._pBitmap.GetPixel(l.x, l.y); tc = _panel._pBitmap.GetPixel(t.x, t.y); rc = _panel._pBitmap.GetPixel(r.x, r.y); bc = _panel._pBitmap.GetPixel(b.x, b.y); if ((lc != Colors.Blue) || (tc != Colors.Blue) || (rc != Colors.Blue) || (bc != Colors.Blue)) { Log.Comment("Expected Color : " + Colors.Blue.ToString() + " but got "); Log.Comment(lc.ToString() + " at Left (" + l.x.ToString() + ", " + l.y.ToString() + ")"); Log.Comment(tc.ToString() + " at Top (" + t.x.ToString() + ", " + t.y.ToString() + ")"); Log.Comment(rc.ToString() + " at Right (" + r.x.ToString() + ", " + r.y.ToString() + ")"); Log.Comment(bc.ToString() + " at Bootom (" + b.x.ToString() + ", " + b.y.ToString() + ")"); testResult = MFTestResults.Fail; } } } else { testResult = MFTestResults.Fail; } } catch (Exception ex) { Log.Comment("Caught : " + ex.Message); return MFTestResults.Fail; } return testResult; }
protected internal abstract void RenderRectangle(Bitmap bmp, Pen outline, int x, int y, int width, int height);
public MFTestResults LineTest_LineThickness11() { Log.Comment("This currently fails, Change in Thickness of a Pen used to draw a line"); Log.Comment("doesn't affect the thickness of the line, see 22234 for details"); MFTestResults testResult = MFTestResults.Pass; Point[] chkPoints = new Point[thickness / 2]; for (int i = 0; i < chkPoints.Length; i++) { chkPoints[i] = new Point(midX + i, midY - 1); } try { Log.Comment("Changing the Pen Color and Thickness"); _pen = new Pen(Colors.Blue, thickness); Log.Comment("Invoking the Dispatcher on a panel and Drawing a Horizontal Line"); testResult = LineTest(new Point(_width - 1, thickness), chkPoints, Colors.Blue); } catch (Exception ex) { Log.Comment("Caught : " + ex.Message); return MFTestResults.Fail; } return testResult; }
public MFTestResults DrawingContext_DrawRectangle_ArgumentExceptionTest3() { MFTestResults testResult = MFTestResults.Pass; if (ClearingPanel() != MFTestResults.Pass) { return MFTestResults.Fail; } r = midX / 2; s = midY / 2; _pen = new Pen(Colors.Green); _brush = new SolidColorBrush(Colors.Blue); int[] dimensions = GetRandomDimensions(midX, midY); for (int i = 0; i < dimensions.Length / 2; i++) { // make at least one dimension negative if (i == 2) { xDimension = -dimensions[i]; yDimension = -dimensions[2 * i + 1]; } else { xDimension = (i % 2) == 0 ? dimensions[i] : -dimensions[i]; yDimension = (i % 2) != 0 ? dimensions[2 * i + 1] : -dimensions[2 * i + 1]; } _argumentException = false; _drawRectangle = true; Master_Media._panel.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(InvalidatePanel), null); autoEvent.WaitOne(); if (!_argumentException) { Log.Comment("Drawing a Rectangle at (" + r + ", " + s + ") with Width = " + xDimension + " and Height = " + yDimension + " didn't throw ArgumentException"); testResult = MFTestResults.Fail; } _drawRectangle = false; _argumentException = false; } return testResult; }
protected internal virtual void RenderEllipse(Bitmap bmp, Pen outline, int x, int y, int xRadius, int yRadius) { throw new NotSupportedException("RenderEllipse is not supported with this brush."); }
public MFTestResults DrawingContext_ClearTest6() { MFTestResults testResult = MFTestResults.Pass; if (ClearingPanel() != MFTestResults.Pass) { return MFTestResults.Fail; } _drawLine = true; _drawRectangle = true; _drawEllipse = true; _drawPolygon = true; Master_Media._panel.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(InvalidatePanel), null); autoEvent.WaitOne(); _pen = new Pen(Colors.Red); _brush = new SolidColorBrush(Colors.Green); Log.Comment("Clearing the DrawingContext"); _drawLine = false; _drawRectangle = false; _drawEllipse = false; _drawPolygon = false; _clear = true; Master_Media._panel.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(InvalidatePanel), null); autoEvent.WaitOne(); Log.Comment("Initializing 40 Random Points that are inside Polygon"); Point[] chkPoints = GetRandomPoints_InRectangle(40, _width, _height, midX, midY); testResult = VerifyingPixelColor(chkPoints, Colors.Black); _clear = false; return testResult; }
protected internal virtual void RenderPolygon(Bitmap bmp, Pen outline, int[] pts) { throw new NotSupportedException("RenderPolygon is not supported with this brush."); }
public MFTestResults ImageBrush_StretchTest4() { MFTestResults testResult = MFTestResults.Pass; if (ClearingPanel() != MFTestResults.Pass) { return MFTestResults.Fail; } try { Bitmap smallFlower = Resources.GetBitmap(Resources.BitmapResources.Yellow_flower_small); int w = 4 * smallFlower.Width, h = 4 * smallFlower.Height; _pen = new Pen(Colors.Black, 1); _brush = new ImageBrush(smallFlower); ((ImageBrush)_brush).Stretch = Stretch.None; Log.Comment("Drawing Rectangle : w = " + w.ToString() + ", h = " + h.ToString()); Log.Comment("filling the Rectangle with ImageBrush not stretched"); Master_Media._panel.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(DrawRectangle), new Point(w, h)); autoEvent.WaitOne(); Log.Comment("Initializing 40 Random Points inside Rectangle but not on the image"); Point[] chkPoints = GetRandomPoints_InRectangle(40, (_rectangle.ActualWidth / 2) - 1, (_rectangle.ActualHeight / 2) - 1, midX, midY); Log.Comment("Verifying pixel color around the center are white"); if (VerifyingPixelColor(chkPoints, Colors.White) != MFTestResults.Pass) { testResult = MFTestResults.Fail; } ((ImageBrush)_brush).Stretch = Stretch.Fill; Log.Comment("Drawing Rectangle : w = " + w.ToString() + ", h = " + h.ToString()); Log.Comment("filling the Rectangle with ImageBrush Stretched and Verifying"); Master_Media._panel.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(DrawRectangle), new Point(w, h)); autoEvent.WaitOne(); for (int i = 0; i < chkPoints.Length; i++) { if (_panel._pBitmap.GetPixel(chkPoints[i].x, chkPoints[i].y) == Colors.White) { testResult = MFTestResults.Fail; Log.Comment("Failure : Not expected to see White color at (" + chkPoints[i].x.ToString() + ", " + chkPoints[i].y.ToString() + ") after ImageBrush stretched"); } } } catch (Exception ex) { Log.Comment("Caught : " + ex.Message); return MFTestResults.Fail; } return testResult; }
public MFTestResults DrawingContext_DrawPolygonTest7() { MFTestResults testResult = MFTestResults.Pass; Point[] pts1 = new Point[] { new Point(35 , midY - 40 ), new Point(midX - 30 , midY - 40 ), new Point(midX , midY + 60 ), new Point(midX , midY + 60 ), new Point(midX + 30 , midY - 40 ), new Point(2 * midX - 35, midY - 40 ), new Point(midX - 10 , midY ), new Point(2 * midX - 35, 2 * midY - 35), new Point(midX , midY + 40 ), new Point(35 , 2 * midY - 35), new Point(midX + 10 , midY ), }; Log.Comment("Initializing Drawing Points"); pts = new int[pts1.Length * 2]; for (int j = 0; j < pts1.Length; j++) { pts[2 * j] = pts1[j].x; pts[2 * j + 1] = pts1[j].y; } _pen = new Pen(Colors.Blue); _brush = new SolidColorBrush(Colors.Green); if (ClearingPanel() != MFTestResults.Pass) { return MFTestResults.Fail; } _drawPolygon = true; autoEvent.Reset(); Master_Media._panel.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(InvalidatePanel), null); autoEvent.WaitOne(); Log.Comment("Verifying the pixel colors on the polygon"); if (VerifyingPixelColor(pts1, Colors.Blue) != MFTestResults.Pass) { testResult = MFTestResults.Fail; } _drawPolygon = false; return testResult; }
protected override void RenderRectangle(Bitmap bmp, Pen outline, int x, int y, int width, int height) { bmp.DrawRectangle(Colors.Blue, 1, x, y, width, height, 0, 0, Colors.Blue, 0, 0, Colors.Blue, 0, 0, Opacity); }
public BackgroundPanel(Brush background, Pen border) { Background = background; Border = border; }
/// <summary> /// Renders the items in the list view. /// </summary> /// <param name="dc"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="headerHeight"></param> /// <param name="itemHeight"></param> protected virtual void RenderItems(DrawingContext dc, int x, int y, int headerHeight, int itemHeight) { // Create the brushes and pens for drawing the items. Brush[] brushes = new Brush[] { _emptyBrush, _lightCyanBrush, _grayBrush }; Pen[] pens = new Pen[] { _emptyPen, _cyanPen }; // Set the starting location for the first item. Offset the // location by _sx and _sy, which are the scroll positions. int cx = x + 6 - _sx; int cy = y + headerHeight + 2 - _sy; int j = 0; // Iterate through all the items. for (int ii = 0; ii < Items.Count; ii++) { // Only draw the items that are visible. if (cy >= _columnHeaderHeight) { // If the item is selected... if (((ListViewItem)Items[ii]) == _selectedItem) { // Draw a rectangle alternately shaded and // transparent. dc.DrawRectangle(brushes[2], pens[j & 1], x + 2, cy, _width - 4, _itemHeight); } else { // Draw a rectangle alternately shaded and // transparent. dc.DrawRectangle(brushes[j & 1], pens[j & 1], x + 2, cy, _width - 4, _itemHeight); } // Set the starting location for the first column. // Offset the location by _sx, which is the scroll // position. cx = 4 - _sx; int i = 0; int newcx = 0; // Iterate through the sub-items, which are columns. for (int e = 0; e < ((ListViewItem)Items[ii]).SubItems.Count; e++) { // Calculate the x position of the next column. newcx = cx + ((ListViewColumn)Columns[i]).Width; // Draw only the items that will appear on the // screen. if (newcx > 0) { dc.DrawText(((ListViewSubItem)((ListViewItem)Items[ii]).SubItems[e]).Text, _font, Color.Black, cx, cy + 2); } // Move to the next column. cx = newcx; i++; // If the location is past the right side of the // screen, don't show any more columns. if (cx > _width) break; } } // Increment to the next item. cy += itemHeight; j++; // If the location is past the bottom of the screen, don't // show any more items. if (cy > _height) break; } }
/// <summary> /// Basic algorithm uses scan lines to fill the polygon. /// No multiplication or division is needed, neither is floating point calculation. /// </summary> /// <param name="bmp"></param> /// <param name="outline"></param> /// <param name="pts"></param> protected internal override void RenderPolygon(Bitmap bmp, Pen outline, int[] pts) { int n = pts.Length / 2; /// This is number of points and number of lines (closed polygon). /// Polygon to fill must have at least 3 points. if (n < 3) return; /// Nothing to do if this is a transparent brush. if (Opacity == Bitmap.OpacityTransparent) return; int i = 0; int y = 0; int yLow = 0; int yHigh = 0; LineSegment[] lines = new LineSegment[n]; int []xPoints = new int[n]; /// Initialize line segments. for (i = 0; i < n; i++) { lines[i] = new LineSegment(); lines[i].processedPts = 0; xPoints[i] = new int(); lines[i].x1 = pts[i * 2]; lines[i].y1 = pts[i * 2 + 1]; if (i < (n - 1)) { lines[i].x2 = pts[(i + 1) * 2]; lines[i].y2 = pts[(i + 1) * 2 + 1]; } else { lines[i].x2 = pts[0]; lines[i].y2 = pts[1]; } /// Reverse the points to make sure y1 <= y2 always. if (lines[i].y2 < lines[i].y1) { Swap(ref lines[i].y2, ref lines[i].y1); Swap(ref lines[i].x2, ref lines[i].x1); } /// Calculate slopes and increments. lines[i].dx = Abs(lines[i].x2 - lines[i].x1); lines[i].dy = Abs(lines[i].y2 - lines[i].y1); lines[i].cx = lines[i].x1; lines[i].e = 0; if (lines[i].dx < lines[i].dy) { /// Angle is 45 degree or more. So y increases faster. lines[i].highSlope = true; } else { lines[i].highSlope = false; } /// Actual increment direction. if (lines[i].x2 > lines[i].x1) lines[i].ix = 1; else lines[i].ix = -1; if (i == 0) { yLow = lines[i].y1; yHigh = lines[i].y2; } else { if (lines[i].y1 < yLow) yLow = lines[i].y1; if (lines[i].y2 > yHigh) yHigh = lines[i].y2; } } /// Fill via scan lines between yLow and yHigh. for (y = yLow; y <= yHigh; y++) { int j = 0; for (i = 0; i < n; i++) { xPoints[i] = Int32.MaxValue; } /// Find intersection points for given y. for (i = 0; i < n; i++) { if (y < lines[i].y1) continue; if (y > lines[i].y2) continue; lines[i].processedPts++; if (lines[i].dy != 0) { if (lines[i].highSlope) { /// For this y find the x, which either the same pixel /// in last iteration or next one. if (y == lines[i].y1) lines[i].cx = lines[i].x1; else if (y == lines[i].y2) lines[i].cx = lines[i].x2; else { lines[i].e += lines[i].dx; if ((lines[i].e << 1) >= lines[i].dy) { lines[i].cx += lines[i].ix; lines[i].e -= lines[i].dy; } } } else { /// In this case for every y pixel inc, x increases more than 1 pixel. if (y == lines[i].y1) lines[i].cx = lines[i].x1; else if (y == lines[i].y2) lines[i].cx = lines[i].x2; else { for (; ; ) { lines[i].cx += lines[i].ix; lines[i].e += lines[i].dy; if ((lines[i].e << 1) >= lines[i].dx) { lines[i].e -= lines[i].dx; break; } } } } } /// Insertion sort, do not insert back to back duplicates int x1; bool x1YMin; int x2 = int.MaxValue; bool x2YMin = false; /// /// add both x endpoints if the line is horizontal /// if (lines[i].dy == 0) { x1 = lines[i].x1; x1YMin = true; x2 = lines[i].x2; x2YMin = true; if (x2 < 0) x2 = 0; } else { x1 = lines[i].cx; x1YMin = lines[i].processedPts == 1; } // We don't need to process negative values of x if (x1 < 0) x1 = 0; int idx1 = -1; int idx2 = x2 == int.MaxValue ? x2 : -1; int offset = 0; /// /// First we search for the indexes of x1 and x2 (if neccessary) and then we will insert the /// items, by shifting the elements in the array for (j = 0; j < n; j++) { int ix = (xPoints[j] & c_XValueMask); bool isYMin = (xPoints[j] & c_YMinBit) != 0; if (idx1 == -1) { /// /// Only add duplicate x values if the intersection produces up (^) or down (v) angles /// as opposed to right (<) or left (>) angles. /// if (ix == x1 && isYMin != x1YMin) { idx1 = int.MaxValue; } else if (ix > x1 ) { idx1 = j + offset; offset++; } } if (idx2 == -1) { /// /// Only add duplicate x values if the intersection produces up (^) or down (v) angles /// as opposed to right (<) or left (>) angles. /// if (ix == x2 && isYMin != x2YMin) { idx2 = int.MaxValue; } else if (ix > x2 ) { idx2 = j + offset; offset++; } } // don't break until we have found both indexes and then end of the list if(idx1 != -1 && idx2 != -1 && xPoints[j] == int.MaxValue) break; } int idxMin = (idx1 < idx2 ? idx1 : idx2); // Because we may have two values to insert, the index to the next item to be shifted // can either be n-1 or n-2. offset = (idx2 == int.MaxValue || idx1 == int.MaxValue ? 1 : 2); // j is already one element past the last valid data item, so increase it by one if we are // inserting two elements j += (offset - 1); // Make sure the index does not overflow if (j >= xPoints.Length) j = xPoints.Length-1; for (; j >= idxMin; j--) { if (j == idx1) { xPoints[j] = x1YMin ? x1 | c_YMinBit : x1; offset--; continue; } if (j == idx2) { xPoints[j] = x2YMin ? x2 | c_YMinBit : x2; offset--; continue; } if (j < offset) break; xPoints[j] = xPoints[j - offset]; } } /// Finally draw the line segments to fill. for (i = 0; i < xPoints.Length - 1; i += 2) { int ix1 = (xPoints[i ] & c_XValueMask); int ix2 = (xPoints[i + 1] & c_XValueMask); if ((ix1 == c_XValueMask) || (ix2 == c_XValueMask)) break; bmp.DrawLine(Color, 1, ix1, y, ix2, y); } } }
public MFTestResults DrawingContext_DrawPolygonTest5() { MFTestResults testResult = MFTestResults.Pass; int min3 = min / 3; Point[] pts1 = new Point[] {new Point( midX - min3, midY),new Point(midX, midY - min3), new Point(midX + min3, midY), new Point(midX, midY + min3)}; Log.Comment("Initializing Drawing Points"); pts = new int[] { pts1[0].x, pts1[0].y, pts1[1].x, pts1[1].y, pts1[2].x, pts1[2].y, pts1[3].x, pts1[3].y }; _pen = new Pen(Colors.Blue); _brush = new SolidColorBrush(Colors.Green); if (ClearingPanel() != MFTestResults.Pass) { return MFTestResults.Fail; } _drawPolygon = true; Master_Media._panel.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(InvalidatePanel), null); autoEvent.WaitOne(); Log.Comment("Verifying the pixel colors on the polygon"); if (VerifyingPixelColor(pts1, Colors.Blue) != MFTestResults.Pass) { testResult = MFTestResults.Fail; } Log.Comment("Initializing 40 Random Points that are inside Polygon"); Point[] chkPoints = GetRandomPoints_InRectangle(40, min3, min3, midX, midY); if (VerifyingPixelColor(chkPoints, Colors.Green) != MFTestResults.Pass) { testResult = MFTestResults.Fail; } _drawPolygon = false; return testResult; }