Xor() public method

Updates this Region to the union minus the intersection of itself with the specified GraphicsPath.
public Xor ( GraphicsPath path ) : void
path System.Drawing.Drawing2D.GraphicsPath Path.
return void
Esempio n. 1
0
		public void ctor_GraphicsPath () {
			GraphicsPath path = new GraphicsPath ();
			path.AddRectangle (rect);
			Region r1 = new Region (path);
			r1.Xor (r);
			Assert.IsTrue (r1.IsEmpty (t.Graphics));
		}
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            Region regionRing = new Region(outCircle.Path);
            //形成圆环
            regionRing.Xor(innerCircle.Path);
            //截取部分圆环
            regionRing.Intersect(clipRectangle);
            e.Graphics.FillRegion(Brushes.Red, regionRing);
            //画处边框
            using (Pen p = new Pen(Brushes.Black))
            {
                e.Graphics.DrawPath(p, outCircle.Path);
                e.Graphics.DrawPath(p, innerCircle.Path);
            }
        }
Esempio n. 3
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            Rectangle rect1 = new Rectangle(40, 40, 160, 160);
            Rectangle rect2 = new Rectangle(90, 90, 160, 160);
            Region rg1 = new Region(rect1);
            Region rg2 = new Region(rect2);

            g.DrawRectangle(Pens.Black, rect1);
            g.DrawRectangle(Pens.Red, rect2);

            //            rg1.Intersect(rect2);
            rg1.Xor(rect2);
            g.FillRegion(Brushes.Blue , rg1);

            g.Dispose();
        }
Esempio n. 4
0
		private static Region CreateRectangleDragOutline(Rectangle rect, int indent)
		{
			// Create region for whole of the new rectangle
			Region region = new Region(rect);

			// If the rectangle is to small to make an inner object from, then just use the outer
			if ((indent <= 0) || (rect.Width <= 2 * indent) || (rect.Height <= 2 * indent))
				return region;

			rect.X += indent;
			rect.Y += indent;
			rect.Width -= 2 * indent;
			rect.Height -= 2 * indent;

			region.Xor(rect);

			return region;
		}
 protected override void OnRenderSplitButtonBackground(ToolStripItemRenderEventArgs e)
 {
     ToolStripSplitButton item = (ToolStripSplitButton) e.Item;
     if ((e.Item.Selected || item.ButtonPressed) || item.DropDownButtonPressed)
     {
         if (!item.DropDownButtonPressed)
         {
             Rectangle dropDownButtonBounds = item.DropDownButtonBounds;
             dropDownButtonBounds = new Rectangle(dropDownButtonBounds.Left + 1, dropDownButtonBounds.Top + 5, dropDownButtonBounds.Width - 3, dropDownButtonBounds.Height - 10);
             using (Region region = new Region(new Rectangle(Point.Empty, e.Item.Size)))
             {
                 region.Xor(dropDownButtonBounds);
                 e.Graphics.SetClip(region, CombineMode.Replace);
                 base.OnRenderSplitButtonBackground(e);
                 e.Graphics.SetClip(dropDownButtonBounds);
                 e.Graphics.TranslateTransform((float) item.DropDownButtonBounds.Width, 0f);
                 if (item.ButtonPressed && (base.BaseRenderer is ToolStripProfessionalRenderer))
                 {
                     using (ToolStripButton button2 = new ToolStripButton())
                     {
                         button2.Select();
                         button2.Size = e.Item.Size;
                         base.OnRenderButtonBackground(new ToolStripItemRenderEventArgs(e.Graphics, button2));
                     }
                 }
                 else
                 {
                     base.OnRenderSplitButtonBackground(e);
                 }
                 e.Graphics.ResetTransform();
                 e.Graphics.ResetClip();
             }
         }
         else
         {
             base.OnRenderSplitButtonBackground(e);
         }
     }
     if (!item.DropDownButtonPressed)
     {
         this.OnRenderArrow(new ToolStripArrowRenderEventArgs(e.Graphics, e.Item, item.DropDownButtonBounds, Color.Black, ArrowDirection.Right));
     }
 }
Esempio n. 6
0
        void DrawRegionOperation()
        {
            g = this.CreateGraphics();
            Rectangle rect1 = new Rectangle(100, 100, 120, 120);
            Rectangle rect2 = new Rectangle(70, 70, 120, 120);

            Region rgn1 = new Region(rect1);
            Region rgn2 = new Region(rect2);

            g.DrawRectangle(Pens.Blue, rect1);
            g.DrawRectangle(Pens.Red, rect2);

            switch(rgnOperation)
            {
                case RegionOperation.Union:
                    rgn1.Union(rgn2);
                    break;
                case RegionOperation.Complement:
                    rgn1.Complement(rgn2);
                    break;
                case RegionOperation.Intersect:
                    rgn1.Intersect(rgn2);
                    break;
                case RegionOperation.Exclude:
                    rgn1.Exclude(rgn2);
                    break;
                case RegionOperation.Xor:
                    rgn1.Xor(rgn2);
                    break;
                default:
                    break;

            }

            g.FillRegion(Brushes.Tomato, rgn1);

            g.Dispose();
        }
Esempio n. 7
0
        private void DrawRegionOperations()
        {
            g = this.CreateGraphics();
            // Создаем два прямоугольника
            Rectangle rect1 = new Rectangle(100, 100, 120, 120);
            Rectangle rect2 = new Rectangle(70, 70, 120, 120);
            // Создаем два региона
            Region rgn1 = new Region(rect1);
            Region rgn2 = new Region(rect2);
            // рисуем прямоугольники
            g.DrawRectangle(Pens.Green, rect1);
            g.DrawRectangle(Pens.Black, rect2);

            // обработаем перечисление и вызовем соответствующий метод
            switch (rgnOperation)
            {
                case RegionOperations.Union:
                    rgn1.Union(rgn2);
                    break;
                case RegionOperations.Complement:
                    rgn1.Complement(rgn2);
                    break;
                case RegionOperations.Intersect:
                    rgn1.Intersect(rgn2);
                    break;
                case RegionOperations.Exclude:
                    rgn1.Exclude(rgn2);
                    break;
                case RegionOperations.Xor:
                    rgn1.Xor(rgn2);
                    break;
                default:
                    break;
            }
            // Рисуем регион
            g.FillRegion(Brushes.Blue, rgn1);
            g.Dispose();
        }
Esempio n. 8
0
		public void SmallXor_Self2 ()
		{
			Region region = new Region (sp2);
			region.Xor (sp2);
			CompareSmallRegion (region, sempty, 7, 7);

			RectangleF[] scans = region.GetRegionScans (matrix);
			Assert.AreEqual (0, scans.Length, "GetRegionScans");
		}
Esempio n. 9
0
		public void SmallXor2 ()
		{
			Region region = new Region (sp2);
			region.Xor (sp1);
			CompareSmallRegion (region, sxor, 7, 7);

			RectangleF[] scans = region.GetRegionScans (matrix);
			Assert.AreEqual (4, scans.Length, "GetRegionScans");
			CheckRectF ("[0]", 0, 0, 3, 2, scans[0]);
			CheckRectF ("[1]", 0, 2, 2, 1, scans[1]);
			CheckRectF ("[2]", 3, 2, 2, 1, scans[2]);
			CheckRectF ("[3]", 2, 3, 3, 2, scans[3]);
		}
Esempio n. 10
0
		private void PaintShadow()
		{
            if(this.Width <= 0 || this.Height <= 0) return;

			// Create bitmap for drawing onto
            using (Bitmap memoryBitmap = new Bitmap(this.Width, this.Height, PixelFormat.Format32bppArgb))
            {
                using (Graphics g = Graphics.FromImage(memoryBitmap))
                {
                    Rectangle area = new Rectangle(0, 0, this.Width, this.Height);

                    System.Drawing.Region reg = new System.Drawing.Region();
                    System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                    Rectangle r = this.ClientRectangle;
                    const int TRIANGLESIZE = 5;
                    path.StartFigure();
                    path.AddLine(r.Right - TRIANGLESIZE, r.Top, r.Right, r.Top);
                    path.AddLine(r.Right, r.Top, r.Right, r.Top + TRIANGLESIZE);
                    path.AddLine(r.Right, r.Top + TRIANGLESIZE, r.Right - TRIANGLESIZE, r.Top);
                    path.CloseFigure();
                    path.StartFigure();
                    path.AddLine(r.Left, r.Bottom - TRIANGLESIZE - 1, r.Left, r.Bottom);
                    path.AddLine(r.Left, r.Bottom, r.Left + TRIANGLESIZE, r.Bottom);
                    path.AddLine(r.Left + TRIANGLESIZE, r.Bottom, r.Left, r.Bottom - TRIANGLESIZE);
                    path.CloseFigure();
                    path.StartFigure();
                    path.AddRectangle(new Rectangle(0, 0, r.Width - TRIANGLESIZE, r.Height - TRIANGLESIZE));
                    path.CloseFigure();
                    reg.Xor(path);
                    g.SetClip(reg, System.Drawing.Drawing2D.CombineMode.Replace);
                    path.Dispose();
                    path = null;
                    reg.Dispose();
                    reg = null;
                    // Draw the background area
                    g.Clear(Color.Transparent);
                    g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                    // Draw Actual Shadow
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.Clear(Color.Black);
                    const int EDGE = 4;
                    r.Width--;
                    r.Height--;
                    Color[] clr = new Color[]{
										   Color.FromArgb(14,Color.Black),
										   Color.FromArgb(43,Color.Black),
										   Color.FromArgb(84,Color.Black),
										   Color.FromArgb(113,Color.Black),
										   Color.FromArgb(128,Color.Black)};

                    for (int i = 0; i < EDGE; i++)
                    {
                        using (Pen pen = new Pen(clr[i], 1))
                        {
                            using (GraphicsPath tempPath = GetPath(r, EDGE - i))
                                g.DrawPath(pen, tempPath);
                            r.Inflate(-1, -1);
                        }
                    }

                    // Get hold of the screen DC
                    IntPtr hDC = NativeFunctions.GetDC(IntPtr.Zero);

                    // Create a memory based DC compatible with the screen DC
                    IntPtr memoryDC = WinApi.CreateCompatibleDC(hDC);

                    // Get access to the bitmap handle contained in the Bitmap object
                    IntPtr hBitmap = memoryBitmap.GetHbitmap(Color.FromArgb(0));

                    // Select this bitmap for updating the window presentation
                    IntPtr oldBitmap = WinApi.SelectObject(memoryDC, hBitmap);

                    // New window size
                    NativeFunctions.SIZE ulwsize;
                    ulwsize.cx = this.Width;
                    ulwsize.cy = this.Height;

                    // New window position
                    NativeFunctions.POINT topPos;
                    topPos.x = this.Left;
                    topPos.y = this.Top;

                    // Offset into memory bitmap is always zero
                    NativeFunctions.POINT pointSource;
                    pointSource.x = 0;
                    pointSource.y = 0;

                    // We want to make the entire bitmap opaque 
                    NativeFunctions.BLENDFUNCTION blend = new NativeFunctions.BLENDFUNCTION();
                    blend.BlendOp = (byte)NativeFunctions.Win23AlphaFlags.AC_SRC_OVER;
                    blend.BlendFlags = 0;
                    blend.SourceConstantAlpha = 255;
                    blend.AlphaFormat = (byte)NativeFunctions.Win23AlphaFlags.AC_SRC_ALPHA;

                    // Tell operating system to use our bitmap for painting
                    NativeFunctions.UpdateLayeredWindow(Handle, hDC, ref topPos, ref ulwsize,
                        memoryDC, ref pointSource, 0, ref blend,
                        (int)NativeFunctions.Win32UpdateLayeredWindowsFlags.ULW_ALPHA);

                    // Put back the old bitmap handle
                    WinApi.SelectObject(memoryDC, oldBitmap);

                    // Cleanup resources
                    WinApi.ReleaseDC(IntPtr.Zero, hDC);
                    WinApi.DeleteObject(hBitmap);
                    WinApi.DeleteDC(memoryDC);
                }
            }
		}
Esempio n. 11
0
        protected override void OnPaint(PaintEventArgs e)
        {
            float valueStart = this.scaleFactor.ScaleScalar(this.rulerValue - offset);
            float valueEnd = this.scaleFactor.ScaleScalar(this.rulerValue + 1.0f - offset);
            float highlightStartPx = this.scaleFactor.ScaleScalar(this.highlightStart - offset);
            float highlightEndPx = this.scaleFactor.ScaleScalar(this.highlightStart + this.highlightLength - offset);

            RectangleF highlightRect;
            RectangleF valueRect;

            if (this.orientation == Orientation.Horizontal)
            {
                valueRect = new RectangleF(valueStart, this.ClientRectangle.Top, valueEnd - valueStart, this.ClientRectangle.Height);
                highlightRect = new RectangleF(highlightStartPx, this.ClientRectangle.Top, highlightEndPx - highlightStartPx, this.ClientRectangle.Height);
            }
            else // if (this.orientation == Orientation.Vertical)
            {
                valueRect = new RectangleF(this.ClientRectangle.Left, valueStart, this.ClientRectangle.Width, valueEnd - valueStart);
                highlightRect = new RectangleF(this.ClientRectangle.Left, highlightStartPx, this.ClientRectangle.Width, highlightEndPx - highlightStartPx);
            }

            if (!this.highlightEnabled)
            {
                highlightRect = RectangleF.Empty;
            }

            if (this.orientation == Orientation.Horizontal)
            {
                // This could be used in the future for making a DPI aware app. Needs a specific system layer though...
                //e.Graphics.DrawLine(
                //    SystemPens.WindowText,
                //    UI.ScaleWidth(15),
                //    ClientRectangle.Top,
                //    UI.ScaleWidth(15),
                //    ClientRectangle.Bottom);
                e.Graphics.DrawLine(
                    SystemPens.WindowText,
                    15,
                    ClientRectangle.Top,
                    15,
                    ClientRectangle.Bottom);

                //string abbStringName = "MeasurementUnit." + this.MeasurementUnit.ToString() + ".Abbreviation";
                //string abbString = PdnResources.GetString(abbStringName);
                //e.Graphics.DrawString("Unit", Font, SystemBrushes.WindowText, UI.ScaleWidth(-2), 0);
                e.Graphics.DrawString("nm", Font, SystemBrushes.WindowText, -2, 0);
            }

            Region clipRegion = new Region(highlightRect);
            clipRegion.Xor(valueRect);

            if (this.orientation == Orientation.Horizontal)
            {
                //clipRegion.Exclude(new Rectangle(0, 0, UI.ScaleWidth(16), ClientRectangle.Height));
                clipRegion.Exclude(new Rectangle(0, 0, 16, ClientRectangle.Height));
            }

            e.Graphics.SetClip(clipRegion, CombineMode.Replace);
            DrawRuler(e, true);

            clipRegion.Xor(this.ClientRectangle);

            if (this.orientation == Orientation.Horizontal)
            {
                //clipRegion.Exclude(new Rectangle(0, 0, UI.ScaleWidth(16), ClientRectangle.Height - 1));
                clipRegion.Exclude(new Rectangle(0, 0, 16, ClientRectangle.Height - 1));
            }

            e.Graphics.SetClip(clipRegion, CombineMode.Replace);
            DrawRuler(e, false);
        }
Esempio n. 12
0
        public void SetClip(Region region, CombineMode combineMode)
        {
            // We need to reset the clip that is active now so that the graphic
            // states are correct when we set them.
            ResetClip ();

            switch (combineMode)
            {
            case CombineMode.Replace:
                // Set our clip region by cloning the region that is passed for now
                clipRegion = region.Clone ();
                break;
            case CombineMode.Intersect:

                clipRegion.Intersect (region);

                break;
            case CombineMode.Union:

                clipRegion.Union (region);

                break;
            case CombineMode.Exclude:

                clipRegion.Exclude (region);

                break;
            case CombineMode.Xor:

                clipRegion.Xor (region);

                break;
            default:
                throw new NotImplementedException ("SetClip for CombineMode " + combineMode + " not implemented");
            }

            //Unlike the current path, the current clipping path is part of the graphics state.
            //Therefore, to re-enlarge the paintable area by restoring the clipping path to a
            //prior state, you must save the graphics state before you clip and restore the graphics
            //state after you’ve completed any clipped drawing.
            context.SaveState ();
            if (clipRegion.IsEmpty) {
                context.ClipToRect (CGRect.Empty);
            } else {
                //context.ClipToRect ((RectangleF)clipRegion.regionObject);
                context.AddPath (clipRegion.regionPath);
                context.ClosePath ();
                context.Clip ();
            }
            clipSet++;
        }
Esempio n. 13
0
		public void EmptyRegionWithInfiniteRegion ()
		{
			Region empty = new Region ();
			empty.MakeEmpty ();
			Assert.IsTrue (empty.IsEmpty (graphic), "IsEmpty");

			Region region = new Region ();
			Assert.IsTrue (region.IsInfinite (graphic), "IsInfinite");

			region.Union (empty);
			Assert.IsTrue (region.IsInfinite (graphic), "Union-IsInfinite");

			region.Xor (empty);
			Assert.IsTrue (region.IsInfinite (graphic), "Xor-IsInfinite");

			region.Exclude (empty);
			Assert.IsTrue (region.IsInfinite (graphic), "Exclude-IsInfinite");

			region.Intersect (empty);
			Assert.IsTrue (region.IsEmpty (graphic), "Intersect-IsEmpty");

			region.MakeInfinite ();
			region.Complement (empty);
			Assert.IsTrue (region.IsEmpty (graphic), "Complement-IsEmpty");
		}
Esempio n. 14
0
		// libgdiplus: both region aren't considered as an intersection because they do 
		// not co-exists in the same 8x8 bitmap. In this case the xor function calls the
		// union code (optimization).
		public void XorWithoutIntersection_Large ()
		{
			Region region = new Region (sp1);
			region.Xor (sp4);
			CompareSmallRegion (region, ni_xor, 13, 5);
		}
Esempio n. 15
0
        protected override void OnPaint(PaintEventArgs e)
        {
            float valueStart = this.scaleFactor.ScaleScalar(this.rulerValue - offset);
            float valueEnd = this.scaleFactor.ScaleScalar(this.rulerValue + 1.0f - offset);
            float highlightStartPx = this.scaleFactor.ScaleScalar(this.highlightStart - offset);
            float highlightEndPx = this.scaleFactor.ScaleScalar(this.highlightStart + this.highlightLength - offset);

            RectangleF highlightRect;
            RectangleF valueRect;

            if (this.orientation == Orientation.Horizontal)
            {
                valueRect = new RectangleF(valueStart, this.ClientRectangle.Top, valueEnd - valueStart, this.ClientRectangle.Height);
                highlightRect = new RectangleF(highlightStartPx, this.ClientRectangle.Top, highlightEndPx - highlightStartPx, this.ClientRectangle.Height);
            }
            else // if (this.orientation == Orientation.Vertical)
            {
                valueRect = new RectangleF(this.ClientRectangle.Left, valueStart, this.ClientRectangle.Width, valueEnd - valueStart);
                highlightRect = new RectangleF(this.ClientRectangle.Left, highlightStartPx, this.ClientRectangle.Width, highlightEndPx - highlightStartPx);
            }

            if (!this.highlightEnabled)
            {
                highlightRect = RectangleF.Empty;
            }

            if (this.orientation == Orientation.Horizontal)
            {
                e.Graphics.DrawLine(
                    SystemPens.WindowText, 
                    UI.ScaleWidth(15), 
                    ClientRectangle.Top, 
                    UI.ScaleWidth(15), 
                    ClientRectangle.Bottom);

                string abbStringName = "MeasurementUnit." + this.MeasurementUnit.ToString() + ".Abbreviation";
                string abbString = PdnResources.GetString(abbStringName);
                e.Graphics.DrawString(abbString, Font, SystemBrushes.WindowText, UI.ScaleWidth(-2), 0);
            }

            Region clipRegion = new Region(highlightRect);
            clipRegion.Xor(valueRect);

            if (this.orientation == Orientation.Horizontal)
            {
                clipRegion.Exclude(new Rectangle(0, 0, UI.ScaleWidth(16), ClientRectangle.Height));
            }

            e.Graphics.SetClip(clipRegion, CombineMode.Replace);
            DrawRuler(e, true);

            clipRegion.Xor(this.ClientRectangle);

            if (this.orientation == Orientation.Horizontal)
            {
                clipRegion.Exclude(new Rectangle(0, 0, UI.ScaleWidth(16), ClientRectangle.Height - 1));
            }

            e.Graphics.SetClip(clipRegion, CombineMode.Replace);
            DrawRuler(e, false);
            clipRegion.Dispose();
        }
Esempio n. 16
0
		public void TestXor()
		{
			Bitmap bmp = new Bitmap (600, 800);
			Graphics dc = Graphics.FromImage (bmp);
			Matrix matrix = new Matrix ();
			RectangleF [] rects;

			Rectangle rect1 = new Rectangle (380, 30, 60, 80);
			Rectangle rect2 = new Rectangle (410, 40, 60, 80);
			Region rgn1 = new Region (rect1);
			Region rgn2 = new Region (rect2);
			rgn1.Xor (rgn2);


			rects = rgn1.GetRegionScans (matrix);

			Assert.AreEqual (4, rects.Length);

			Assert.AreEqual (380, rects[0].X);
			Assert.AreEqual (30, rects[0].Y);
			Assert.AreEqual (60, rects[0].Width);
			Assert.AreEqual (10, rects[0].Height);

			Assert.AreEqual (380, rects[1].X);
			Assert.AreEqual (40, rects[1].Y);
			Assert.AreEqual (30, rects[1].Width);
			Assert.AreEqual (70, rects[1].Height);

			Assert.AreEqual (440, rects[2].X);
			Assert.AreEqual (40, rects[2].Y);
			Assert.AreEqual (30, rects[2].Width);
			Assert.AreEqual (70, rects[2].Height);

			Assert.AreEqual (410, rects[3].X);
			Assert.AreEqual (110, rects[3].Y);
			Assert.AreEqual (60, rects[3].Width);
			Assert.AreEqual (10, rects[3].Height);
		}
Esempio n. 17
0
        /// <summary>
        /// Draws each element in group on graph object
        /// </summary>
        /// <param name="graphObj">Graph object to be drawn on</param>
        /// <param name="dx">X region</param>
        /// <param name="dy">Y region</param>
        /// <param name="zoom">Zoom value</param>
        public override void Draw(Graphics graphObj, int dx, int dy, float zoom)
        {
            GraphicsState oldGraphState = graphObj.Save();    //store previos trasformation
            Matrix        matrix        = graphObj.Transform; // get previous trasformation

            PointF point = new PointF(zoom * (region.X0 + dx + (region.X1 - region.X0) / 2),
                                      zoom * (region.Y0 + dy + (region.Y1 - region.Y0) / 2));

            if (this.Rotation > 0)
            {
                matrix.RotateAt(this.Rotation, point, MatrixOrder.Append); //add a trasformation
            }
            //X MIRROR  //Y MIRROR
            if (this.xMirror || this.yMirror)
            {
                matrix.Translate(-(region.X0 + region.Width / 2 + dx) * zoom,
                                 -(region.Y0 + region.Height / 2 + dy) * zoom, MatrixOrder.Append);

                if (this.xMirror)
                {
                    matrix.Multiply(new Matrix(-1, 0, 0, 1, 0, 0), MatrixOrder.Append);
                }
                if (this.yMirror)
                {
                    matrix.Multiply(new Matrix(1, 0, 0, -1, 0, 0), MatrixOrder.Append);
                }

                matrix.Translate((region.X0 + region.Width / 2 + dx) * zoom,
                                 (region.Y0 + region.Height / 2 + dy) * zoom, MatrixOrder.Append);
            }

            if (this.groupZoomX > 0 && this.groupZoomY > 0)
            {
                matrix.Translate((-1) * zoom * (region.X0 + dx +
                                                (region.X1 - region.X0) / 2), (-1) * zoom * (region.Y0 + dy +
                                                                                             (region.Y1 - region.Y0) / 2), MatrixOrder.Append);
                matrix.Scale(this.groupZoomX, this.groupZoomY, MatrixOrder.Append);
                matrix.Translate(zoom * (region.X0 + dx + (region.X1 - region.X0) / 2),
                                 zoom * (region.Y0 + dy + (region.Y1 - region.Y0) / 2),
                                 MatrixOrder.Append);
            }
            graphObj.Transform = matrix;

            if (this.IsGraphPath)
            {
                Brush myBrush = GetBrush(dx, dy, zoom);
                Pen   myPen   = this.CreatePen(zoom);

                GraphicsPath graphPath = new GraphicsPath();

                foreach (ShapeElement element in this.elementList)
                {
                    element.AddToGraphPath(graphPath, dx, dy, zoom);
                }

                if (this.FillEnabled)
                {
                    graphObj.FillPath(myBrush, graphPath);

                    if (this.ShowBorder)
                    {
                        graphObj.DrawPath(myPen, graphPath);
                    }
                }
                else
                {
                    graphObj.DrawPath(myPen, graphPath);
                }

                if (myBrush != null)
                {
                    myBrush.Dispose();
                }
                myPen.Dispose();
            }
            else
            {
                //MANAGE This.GroupDisplay
                System.Drawing.Region gregion = new System.Drawing.Region();

                if (GroupDisplay != GroupDisplay.Default)
                {
                    bool first = true;
                    foreach (ShapeElement element in this.elementList)
                    {
                        GraphicsPath graphPath = new GraphicsPath(FillMode.Winding);
                        element.AddToGraphPath(graphPath, dx, dy, zoom);

                        if (first)
                        {
                            gregion.Intersect(graphPath);
                        }
                        else
                        {
                            switch (GroupDisplay)
                            {
                            case GroupDisplay.Intersect:
                                gregion.Intersect(graphPath);
                                break;

                            case GroupDisplay.Xor:
                                gregion.Xor(graphPath);
                                break;

                            case GroupDisplay.Exclude:
                                gregion.Exclude(graphPath);
                                break;

                            default:
                                break;
                            }
                        }
                        first = false;
                    }
                    graphObj.SetClip(gregion, CombineMode.Intersect);
                }

                foreach (ShapeElement element in this.elementList)
                {
                    element.Draw(graphObj, dx, dy, zoom);
                }

                if (GroupDisplay != GroupDisplay.Default)
                {
                    graphObj.ResetClip();
                }
            }
            graphObj.Restore(oldGraphState);//restore previos trasformation

            if (this.Selected)
            {
                Brush myBrush = GetBrush(dx, dy, zoom);
                Pen   myPen   = this.CreatePen(zoom);

                graphObj.DrawRectangle(myPen, Rectangle.Round(region.GetRectangleF(dx, dy, zoom)));
                if (myBrush != null)
                {
                    myBrush.Dispose();
                }
                myPen.Dispose();
            }
            matrix.Dispose();
        }
Esempio n. 18
0
        public bool RedrawBoard(Graphics g, int iFirst, int iLast)
        {
            int i;
            SolidBrush brBlankTile = new SolidBrush(Color.DarkGreen);
            SolidBrush brBackground = new SolidBrush(Color.White);

            if (frmParent != null)
            {
                SolidBrush brGreen = new SolidBrush(Color.Green);
                Region rgn = new Region(this.ParentRect);
                Rectangle rcBoard = new Rectangle(pt.X,pt.Y,(boardCol*cxTile)+1,(boardRow*cyTile)+1);
                rgn.Xor(rcBoard);
                g.FillRegion(brGreen,rgn);
            }

            Pen penBlack = new Pen(Color.Black);
            g.DrawRectangle(penBlack,pt.X,pt.Y,(boardCol*cxTile)+1,(boardRow*cyTile)+1);

            for (i = 1; i < boardRow; i++)
                g.DrawLine(penBlack, pt.X, pt.Y+(cyTile * i), pt.X+(cxTile*boardCol), pt.Y + (cyTile * i));

            for (i = 1; i < boardCol; i++)
                g.DrawLine(penBlack, pt.X+(cxTile*i), pt.Y, pt.X+(cxTile*i), pt.Y+(cyTile*boardRow));

            for (i = iFirst; i < (iLast+1); i++)
            {
                if (boardData[i] != 0)
                {
                    // Draw tile
                    if (bmpTile == null)
                    {
                        StringFormat strFormat = new StringFormat(StringFormatFlags.DirectionRightToLeft);
                        strFormat.Alignment = StringAlignment.Center;
                        strFormat.LineAlignment = StringAlignment.Center;

                        g.FillRectangle(brBackground,CalcRect(i));
                        g.DrawString(boardData[i].ToString(),
                            new Font("Tahoma",8.0f),
                            Brushes.Black,
                            CalcRect(i),
                            strFormat);
                    }
                    else
                    {
                        g.DrawImage(this.imgTile[boardData[i]-1],CalcRect(i));
                    }
                }
                else
                {
                    // Draw black tile
                    g.FillRectangle(brBlankTile,CalcRect(i));
                }
            }

            return (true);
        }
Esempio n. 19
0
        public void Draw()
        {
            var rectangle = this.GetRectangle();

            buffer.Graphics.Clear(Color.Transparent);
            buffer.Graphics.DrawImage(this.background, Point.Empty);

            var region = new Region();

            region.Xor(rectangle);

            buffer.Graphics.FillRegion(brush, region);
            buffer.Graphics.DrawRectangle(pen, rectangle);

            //DrawCoordinates();

            buffer.Render();
        }
Esempio n. 20
0
		private void UpdateShape3 ()
		{
			if (shape3comboBox.SelectedIndex == -1)
				return;

			if (r1 != null) {
				if (op != null)
					op.Dispose ();
				op = r1.Clone ();
				if (r2 != null) {

					switch (shape3comboBox.SelectedIndex) {
					case 0:
						op.Union (r2);
						break;
					case 1:
						op.Intersect (r2);
						break;
					case 2:
						op.Exclude (r2);
						break;
					case 3:
						op.Complement (r2);
						break;
					case 4:
						op.Xor (r2);
						break;
					}
				}
			}
		}
Esempio n. 21
0
		public void NegativeXor ()
		{
			GraphicsPath neg = new GraphicsPath ();
			// identical result (matrix) of XOR but we're using negative coordinates
			neg.AddPolygon (new Point[4] { new Point (-2, -2), new Point (1, -2), new Point (1, 1), new Point (-2, 1) });

			Region region = new Region (sp1);
			region.Xor (neg);
			CompareSmallRegion (region, sxor, -3, -3, 7, 7);
		}
Esempio n. 22
0
		// libgdiplus: both region are considered inside as intersecting rectangle because
		// part of them co-exists in the same 8x8 bitmap.
		public void XorWithoutIntersection ()
		{
			Region region = new Region (sp1);
			region.Xor (sp3);
			CompareSmallRegion (region, ni_union, 11, 5);
		}
Esempio n. 23
0
		protected void SetWindowRegion(Size winSize)
		{
			// Style specific handling
			if (_style == VisualStyle.IDE)
			{
				int shadowHeight = _position[(int)_style, (int)PI.ShadowHeight];
				int shadowWidth = _position[(int)_style, (int)PI.ShadowWidth];

				// Create a new region object
				using (Region drawRegion = new Region())
				{
				// Can draw anywhere
				drawRegion.MakeInfinite();

				// Remove the area above the right hand shadow
				drawRegion.Xor(new Rectangle(winSize.Width - shadowWidth, 0, shadowWidth, shadowHeight));

				// When drawing upwards from a vertical menu we need to allow a connection between the
				// MenuControl selection box and the PopupMenu shadow
				if (!((_direction == Direction.Vertical) && !_excludeTop))
				{
					// Remove the area left of the bottom shadow
					drawRegion.Xor(new Rectangle(0, winSize.Height - shadowHeight, shadowWidth, shadowHeight));
				}

				// Define a region to prevent drawing over exposed corners of shadows
				using(Graphics g = Graphics.FromHwnd(this.Handle))
					WindowsAPI.SetWindowRgn(this.Handle, drawRegion.GetHrgn(g), false);
			}
			}
		}
Esempio n. 24
0
		public void EmptyPathWithInfiniteRegion ()
		{
			GraphicsPath gp = new GraphicsPath ();
			Region region = new Region ();
			Assert.IsTrue (region.IsInfinite (graphic), "IsInfinite");

			region.Union (gp);
			Assert.IsTrue (region.IsInfinite (graphic), "Union-IsInfinite");

			region.Xor (gp);
			Assert.IsTrue (region.IsInfinite (graphic), "Xor-IsInfinite");

			region.Exclude (gp);
			Assert.IsTrue (region.IsInfinite (graphic), "Exclude-IsInfinite");

			region.Intersect (gp);
			Assert.IsTrue (region.IsEmpty (graphic), "Intersect-IsEmpty");

			region.MakeInfinite ();
			region.Complement (gp);
			Assert.IsTrue (region.IsEmpty (graphic), "Complement-IsEmpty");
		}
Esempio n. 25
0
		private void SetupRegion()
		{
			if(this.DisplayShadow && this.AlphaShadow || !this.DisplayShadow)
				return;
			if(m_Parent!=null)
			{
				Rectangle r=new Rectangle(0,0,this.Width,this.Height);
				System.Drawing.Region rgn=new System.Drawing.Region(r);
				r.X=this.Width-2;
				r.Y=0;
				r.Width=2;
				r.Height=2;
				rgn.Xor(r);
				r.X=0;
				r.Y=this.Height-2;
				r.Width=2;
				r.Height=2;
				rgn.Xor(r);
				this.Region=rgn;
			}
		}
Esempio n. 26
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Paints the current <see cref="T:System.Windows.Forms.DataGridViewCell"></see>.
		/// </summary>
		/// <param name="graphics">The <see cref="T:System.Drawing.Graphics"></see> used to
		/// paint the <see cref="T:System.Windows.Forms.DataGridViewCell"></see>.</param>
		/// <param name="clipBounds">A <see cref="T:System.Drawing.Rectangle"></see> that
		/// represents the area of the <see cref="T:System.Windows.Forms.DataGridView"></see>
		/// that needs to be repainted.</param>
		/// <param name="cellBounds">A <see cref="T:System.Drawing.Rectangle"></see> that
		/// contains the bounds of the <see cref="T:System.Windows.Forms.DataGridViewCell"></see>
		/// that is being painted.</param>
		/// <param name="rowIndex">The row index of the cell that is being painted.</param>
		/// <param name="cellState">A bitwise combination of
		/// <see cref="T:System.Windows.Forms.DataGridViewElementStates"></see> values that
		/// specifies the state of the cell.</param>
		/// <param name="value">The data of the <see cref="T:System.Windows.Forms.DataGridViewCell">
		/// </see> that is being painted.</param>
		/// <param name="formattedValue">The formatted data of the
		/// <see cref="T:System.Windows.Forms.DataGridViewCell"></see> that is being painted.
		/// </param>
		/// <param name="errorText">An error message that is associated with the cell.</param>
		/// <param name="cellStyle">A <see cref="T:System.Windows.Forms.DataGridViewCellStyle">
		/// </see> that contains formatting and style information about the cell.</param>
		/// <param name="advancedBorderStyle">A
		/// <see cref="T:System.Windows.Forms.DataGridViewAdvancedBorderStyle"></see> that
		/// contains border styles for the cell that is being painted.</param>
		/// <param name="paintParts">A bitwise combination of the
		/// <see cref="T:System.Windows.Forms.DataGridViewPaintParts"></see> values that
		/// specifies which parts of the cell need to be painted.</param>
		/// ------------------------------------------------------------------------------------
		protected override void Paint(Graphics graphics, Rectangle clipBounds,
			Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState,
			object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle,
			DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
		{
			if (!m_fAllowPaint)
				return;

			// Clear the background
			Region background = new Region(cellBounds);
			background.Xor(GetCellContentDisplayRectangle(advancedBorderStyle));
			background.Intersect(clipBounds);
			graphics.FillRegion(SystemBrushes.Window, background);

			// Invalidate the view so that it redraws
			if (m_Control != null)
			{
				Point pt = m_Control.PointToClient(DataGridView.PointToScreen(new Point(clipBounds.X, clipBounds.Y)));
				Rectangle borderRect = BorderWidths(advancedBorderStyle);
				Rectangle toDraw = new Rectangle(0, 0,
					cellBounds.Width, cellBounds.Height);
				Rectangle clientClip = new Rectangle(pt.X, pt.Y, clipBounds.Width, clipBounds.Height);
				toDraw.Intersect(clientClip);
				m_Control.Invalidate(toDraw, true);
				m_Control.Update();
			}

			// Finally draw the borders
			if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border)
				PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
		}
        void FillRegionXor(Graphics g)
        {
            Pen myPen = new Pen(Color.FromArgb(196, 0xC3, 0xC9, 0xCF), (float)0.6);
            SolidBrush myBrush = new SolidBrush(Color.FromArgb(127, 0xDD, 0xDD, 0xF0));

            // Create the first rectangle and draw it to the screen in black.
            g.DrawRectangle(myPen, regionRect1);
            g.FillRectangle(myBrush, regionRect1);

            myPen.Color = Color.FromArgb(196, 0xF9, 0xBE, 0xA6);
            myBrush.Color = Color.FromArgb(127, 0xFF, 0xE0, 0xE0);

            // create the second rectangle and draw it to the screen in red.
            g.DrawRectangle(myPen,
                            Rectangle.Round(regionRectF2));
            g.FillRectangle(myBrush, regionRect2);

            // Create a region using the first rectangle.
            Region myRegion = new Region(regionRect1);

            // Get the area of intersection for myRegion when combined with
            // complementRect.
            myRegion.Xor(regionRectF2);

            myBrush.Color = Color.FromArgb(127, 0x66, 0xEF, 0x7F);
            myPen.Color = Color.FromArgb(255, 0, 0x33, 0);

            g.FillRegion(myBrush, myRegion);

            title = "FillRegionXor";
        }
Esempio n. 28
0
		protected override void PaintClient(Graphics g, bool imageDataLost)
		{
			float z = Zoom;

			if (mPreviousClientSize != ClientSize)
			{
				if (!mNeedsPlayerRecenter && mCenterOnCoords == Coordinates.NO_COORDINATES)
				{
					if (CenterOnPlayer && IsCenteredOnPlayer(z, mPreviousClientSize))
						mNeedsPlayerRecenter = true;
					else
						CenterOnPix(mPreviousClientSize.Width / 2, mPreviousClientSize.Height / 2, z);
				}
				mPreviousClientSize = ClientSize;
			}

			float zoomedSize = mMapSize * z;
			if (zoomedSize < ClientSize.Width || zoomedSize < ClientSize.Height)
			{
				z = Math.Max(ClientSize.Width / (float)mMapSize, ClientSize.Height / (float)mMapSize);
				if (z > 1)
					z = 1;
				Zoom = z;
				ActualZoom = z;
				zoomedSize = mMapSize * z;
			}

			// Paint Map
			Matrix origTransform = g.Transform;
			g.Clear(Clear);

			float coordPadX = 0, coordPadY = 0;

			if (mCenterOnCoords != Coordinates.NO_COORDINATES)
			{
				CenterOnCoords(mCenterOnCoords, z);
				mCenterOnCoords = Coordinates.NO_COORDINATES;
				mNeedsPlayerRecenter = false;
			}
			else if (mNeedsPlayerRecenter && (ClientMouseButtons & DragButton) == 0)
			{
				mNeedsPlayerRecenter = false;
				if (!PlayerInDungeon)
					CenterOnCoords(mPlayerCoords, z);
			}

			if (ClientSize.Width > zoomedSize)
			{
				// Center horizontally
				mOffset.X = (ClientSize.Width - zoomedSize) / (2 * z);
				coordPadX = mOffset.X * z;
			}
			else if (mOffset.X > 0)
				mOffset.X = 0;
			else if (mOffset.X < (ClientSize.Width - zoomedSize) / z)
				mOffset.X = (ClientSize.Width - zoomedSize) / z;

			if (ClientSize.Height > zoomedSize)
			{
				// Center vertically
				mOffset.Y = (ClientSize.Height - zoomedSize) / (2 * z);
				coordPadY = mOffset.Y * z;
			}
			else if (mOffset.Y > 0)
				mOffset.Y = 0;
			else if (mOffset.Y < (ClientSize.Height - zoomedSize) / z)
				mOffset.Y = (ClientSize.Height - zoomedSize) / z;

			#region Draw Map
			if (z < 1)
			{
				// Lazy load low res map
				if (mDerethMapLowRes == null)
				{
					mDerethMapLowRes = new Bitmap(mZipFile.GetInputStream(mZipFile.GetEntry("lowres.png")));
				}

				float relSize = (float)mDerethMapLowRes.Width / mMapSize;

				if (z / relSize <= 0.5f)
					g.InterpolationMode = InterpolationMode.HighQualityBilinear;
				else
					g.InterpolationMode = InterpolationMode.Bilinear;

				RectangleF srcRect = new RectangleF(-mOffset.X * relSize, -mOffset.Y * relSize,
					ClientSize.Width * relSize / z, ClientSize.Height * relSize / z);
				RectangleF destRect = new RectangleF(0, 0, ClientSize.Width, ClientSize.Height);

				g.DrawImage(mDerethMapLowRes, destRect, srcRect, GraphicsUnit.Pixel);
			}
			else
			{
				float w = ClientSize.Width / z;

				int minTileX = Math.Max((int)(-mOffset.X / mTileSize), 0);
				int minTileY = Math.Max((int)(-mOffset.Y / mTileSize), 0);
				int maxTileX = Math.Min(
					(int)((-mOffset.X + ClientSize.Width / z) / mTileSize), mMaxTile);
				int maxTileY = Math.Min(
					(int)((-mOffset.Y + ClientSize.Height / z) / mTileSize), mMaxTile);

				if (z == 1)
				{
					int offX = (int)mOffset.X, offY = (int)mOffset.Y;
					int dX, dY;
					for (int i = minTileX; i <= maxTileX; i++)
					{
						dX = i * mTileSize + offX;
						for (int j = minTileY; j <= maxTileY; j++)
						{
							dY = j * mTileSize + offY;
							GraphicsUtil.BitBlt(GetTile(i, j), ClientImage, dX, dY);
						}
					}
				}
				else
				{
					g.InterpolationMode = InterpolationMode.NearestNeighbor;
					g.ScaleTransform(z, z);
					float dX, dY;
					for (int i = minTileX; i <= maxTileX; i++)
					{
						dX = i * mTileSize + mOffset.X;
						for (int j = minTileY; j <= maxTileY; j++)
						{
							dY = j * mTileSize + mOffset.Y;
							g.DrawImage(GetTile(i, j), dX, dY);
						}
					}
				}
			}
			#endregion

			g.Transform = origTransform;

			#region Draw Route-Finding Regions
#if false
			float regionZoom = z * mPixPerClick;
			g.ScaleTransform(z, z);
			g.TranslateTransform(mOffset.X + mMapSize / 2.0f - 1.0f, mOffset.Y + mMapSize / 2.0f);
			g.ScaleTransform(mPixPerClick, -mPixPerClick);
			Brush regionFill = new SolidBrush(Color.FromArgb(0x77CC0000));
			Brush innerRegionFill = new SolidBrush(Color.FromArgb(0x77AB10BC));
			RouteFinder.DrawRegions(g, regionFill, innerRegionFill);
			g.Transform = origTransform;
#endif
			#endregion

			Coordinates minCoords = PixToCoords(0, 0, z);
			Coordinates maxCoords = PixToCoords(ClientSize.Width, ClientSize.Height, z);

			#region Draw Coordinates (Part I: Gridlines)
			float lastTickNS = 0, firstTickEW = 0, lastTickEW = 0, firstTickNS = 0;
			RectangleF mapRect = new RectangleF(), insideGutter = new RectangleF();
			Region coordGutter = null;
			string precision = "";
			if (DrawCoords)
			{
				g.SmoothingMode = SmoothingMode.Default;

				if (mCoordTickDelta >= 1)
					precision = "0";
				else if (mCoordTickDelta >= 0.1)
					precision = "0.0";
				else
					precision = "0.00";

				lastTickNS = (float)(Math.Floor(minCoords.NS / mCoordTickDelta) * mCoordTickDelta);
				firstTickEW = (float)(Math.Floor(minCoords.EW / mCoordTickDelta) * mCoordTickDelta);
				lastTickEW = (float)(Math.Ceiling(maxCoords.EW / mCoordTickDelta) * mCoordTickDelta);
				firstTickNS = (float)(Math.Ceiling(maxCoords.NS / mCoordTickDelta) * mCoordTickDelta);

				mapRect = new RectangleF(coordPadX, coordPadY,
				   ClientSize.Width - 2 * coordPadX, ClientSize.Height - 2 * coordPadY);
				insideGutter = new RectangleF(
				   coordPadX + CoordGutterSize,
				   coordPadY + CoordGutterSize,
				   ClientSize.Width - 2 * (CoordGutterSize + coordPadX),
				   ClientSize.Height - 2 * (CoordGutterSize + coordPadY));
				coordGutter = new Region(mapRect);
				coordGutter.Xor(insideGutter);
				g.FillRegion(CoordGutterFill, coordGutter);

				// Draw Gridlines
				for (float ns = firstTickNS, ew = firstTickEW;
						ns <= lastTickNS || ew <= lastTickEW;
						ns += mCoordTickDelta, ew += mCoordTickDelta)
				{
					PointF pos = CoordsToPix(ns, ew, z);
					if (pos.Y > insideGutter.Top && pos.Y < insideGutter.Bottom)
					{
						// Draw horizontal NS gridline
						g.DrawLine(CoordGridline, CoordGutterSize + coordPadX, pos.Y,
							ClientSize.Width - CoordGutterSize - coordPadX - 1, pos.Y);
					}
					if (pos.X > insideGutter.Left && pos.X < insideGutter.Right)
					{
						// Draw vertical EW gridline
						g.DrawLine(CoordGridline, pos.X, CoordGutterSize + coordPadY,
							pos.X, ClientSize.Height - CoordGutterSize - coordPadY - 1);
					}
				}
			}
			#endregion

			#region Draw Locations
			mHotspots.Clear();
			float z2 = (float)(Math.Pow(z / ZoomBase, 0.25));
			if (ShowLocations)
			{
				g.SmoothingMode = SmoothingMode.Default;
				g.InterpolationMode = InterpolationMode.HighQualityBilinear;

				Dictionary<LocationType, List<Location>> visibleLocations
					= new Dictionary<LocationType, List<Location>>();

				foreach (Location loc in mLocDb.Locations.Values)
				{
					if (loc.Coords.NS <= minCoords.NS && loc.Coords.NS >= maxCoords.NS
							&& loc.Coords.EW >= minCoords.EW && loc.Coords.EW <= maxCoords.EW)
					{

						List<Location> addTo;
						LocationType type = loc.Type;
						if ((type & LocationType.AnyPortal) != 0)
						{
							type = LocationType.AnyPortal;
						}
						if (!visibleLocations.TryGetValue(type, out addTo))
						{
							addTo = new List<Location>();
							visibleLocations.Add(type, addTo);
						}
						addTo.Add(loc);
					}
				}

				if (ShowLocationsAllZooms || ZoomFactor >= 5)
				{
					DrawLocationType(visibleLocations, LocationType.NPC, Icons.Map.NPC, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.Vendor, Icons.Map.Store, g, z, z2);
				}
				if (ShowLocationsAllZooms || ZoomFactor >= 2)
				{
					DrawLocationType(visibleLocations, LocationType.Village, Icons.Map.Settlement, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.Landmark, Icons.Map.PointOfInterest, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.AllegianceHall, Icons.Map.Dungeon, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.Bindstone, Icons.Map.Bindstone, g, z, z2);
				}
				if (ShowLocationsAllZooms || ZoomFactor >= -1)
				{
					DrawLocationType(visibleLocations, LocationType.Custom, Icons.Map.PointOfInterest, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.Lifestone, Icons.Map.Lifestone, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.Dungeon, Icons.Map.Dungeon, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.AnyPortal, Icons.Map.Portal, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.PortalHub, Icons.Map.PortalHub, g, z, z2);
					DrawLocationType(visibleLocations, LocationType.Outpost, Icons.Map.TownSmall, g, z, z2);
				}

				DrawLocationType(visibleLocations, LocationType.Town, Icons.Map.Town, g, z, z2);

				//DrawLocationType(visibleLocations, LocationType._StartPoint, Icons.Map.StartPoint, g, z, z2);
				//DrawLocationType(visibleLocations, LocationType._EndPoint, Icons.Map.EndPoint, g, z, z2);

				if (ShowLabels)
				{
					float z3 = (float)(Math.Pow(z / ZoomBase, 0.1));
					Font f = new Font(FontFamily.GenericSerif, Math.Min(8 * z3, 10));
					Font fTown = new Font(FontFamily.GenericSerif, Math.Min(9 * z3, 12), FontStyle.Bold);
					List<RectangleF> usedLabelRects = new List<RectangleF>();

					if (ZoomFactor >= -4)
					{
						LabelLocationType(g, fTown, usedLabelRects, LocationType.Town);
					}
					if (ZoomFactor >= 1)
					{
						LabelLocationType(g, f, usedLabelRects, LocationType.Outpost);
						LabelLocationType(g, f, usedLabelRects, LocationType.PortalHub);
						LabelLocationType(g, f, usedLabelRects, LocationType.AnyPortal);
						LabelLocationType(g, f, usedLabelRects, LocationType.Dungeon);
						LabelLocationType(g, f, usedLabelRects, LocationType.Lifestone);
						LabelLocationType(g, f, usedLabelRects, LocationType.Custom);
					}
					if (ZoomFactor >= 4)
					{
						LabelLocationType(g, f, usedLabelRects, LocationType.Bindstone);
						LabelLocationType(g, f, usedLabelRects, LocationType.AllegianceHall);
						LabelLocationType(g, f, usedLabelRects, LocationType.Landmark);
						LabelLocationType(g, f, usedLabelRects, LocationType.Village);
					}
					//if (ZoomFactor >= 6) {
					//    LabelLocation(g, f, usedLabelRects, LocationType.Vendor);
					//    LabelLocation(g, f, usedLabelRects, LocationType.NPC);
					//}
				}
			}
			#endregion

			#region Draw Route
			if (ShowRoute && mRoute != null && mRoute.Count > 1)
			{
				g.SmoothingMode = SmoothingMode.AntiAlias;
				PointF lastPoint, curPoint = CoordsToPix(mRoute[0].Coords, z);
				for (int i = 1; i < mRoute.Count; i++)
				{
					// Running
					lastPoint = curPoint;
					curPoint = CoordsToPix(mRoute[i].Coords, z);

					double dX = lastPoint.X - curPoint.X;
					double dY = lastPoint.Y - curPoint.Y;
					double dist = Math.Sqrt(dX * dX + dY * dY);
					if (dist >= 5.0)
					{
						g.DrawLine(RouteLineBackground, lastPoint, curPoint);
						g.DrawLine(RouteLine, lastPoint, curPoint);
					}

					// Portals
					if (mRoute[i].HasExitCoords)
					{
						lastPoint = curPoint;
						curPoint = CoordsToPix(mRoute[i].ExitCoords, z);

						dX = lastPoint.X - curPoint.X;
						dY = lastPoint.Y - curPoint.Y;
						dist = Math.Sqrt(dX * dX + dY * dY);
						if (dist >= 5.0)
						{
							//g.DrawLine(RouteLineBackground, lastPoint, curPoint);
							g.DrawLine(RouteLinePortal, lastPoint, curPoint);
						}
					}
				}
			}
			#endregion

			#region Draw Arrow Destination
			PointF ptf = CoordsToPix(mPluginCore.mArrowHud.DestinationCoords, z);
			if (ptf.X >= 0 && ptf.Y >= 0 && ptf.X < ClientSize.Width && ptf.Y < ClientSize.Height)
			{
				float zw = z2 * Icons.Map.ArrowDest2.Width;
				float zh = z2 * Icons.Map.ArrowDest2.Height;
				RectangleF rectf = new RectangleF(ptf.X - zw / 2, ptf.Y - zh / 2, zw, zh);
				g.DrawImage(Icons.Map.ArrowDest2, rectf);
				Rectangle rect = new Rectangle(Point.Truncate(rectf.Location), Size.Ceiling(rectf.Size));
			}
			#endregion

			#region Draw Coordinates (Part II: Labels)
			if (DrawCoords)
			{
				Region clipNS = new Region(new RectangleF(mapRect.X, mapRect.Y + CoordGutterSize, mapRect.Width, mapRect.Height - 2 * CoordGutterSize));
				Region clipEW = new Region(new RectangleF(mapRect.X + CoordGutterSize, mapRect.Y, mapRect.Width - 2 * CoordGutterSize, mapRect.Height));
				Region origClip = g.Clip;

				// Draw Labels
				for (float ns = firstTickNS, ew = firstTickEW;
						ns <= lastTickNS || ew <= lastTickEW;
						ns += mCoordTickDelta, ew += mCoordTickDelta)
				{
					PointF pos = CoordsToPix(ns, ew, z);

					string nsString = Math.Abs(ns).ToString(precision) + (ns >= 0 ? "N" : "S");
					string ewString = Math.Abs(ew).ToString(precision) + (ew >= 0 ? "E" : "W");

					SizeF nsSize = g.MeasureString(nsString, CoordTextFont);
					SizeF ewSize = g.MeasureString(ewString, CoordTextFont);

					g.Clip = clipNS;
					float nsY = pos.Y - nsSize.Width / 2;
					g.DrawString(nsString, CoordTextFont, Brushes.White, coordPadX, nsY, VerticalText);
					g.DrawString(nsString, CoordTextFont, Brushes.White,
						ClientSize.Width - coordPadX - nsSize.Height, nsY, VerticalText);

					g.Clip = coordGutter;
					float ewX = pos.X - ewSize.Width / 2;
					g.DrawString(ewString, CoordTextFont, Brushes.White, ewX, coordPadY);
					g.DrawString(ewString, CoordTextFont, Brushes.White,
						ewX, ClientSize.Height - ewSize.Height - coordPadY);
				}
				g.Clip = origClip;
			}
			#endregion

			PaintSprites(z);

			mPreviousZoomMultiplier = z;
			mLastPaintedPlayerCoords = PlayerCoords;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Paints the current <see cref="T:System.Windows.Forms.DataGridViewCell"></see>.
		/// </summary>
		/// <param name="graphics">The <see cref="T:System.Drawing.Graphics"></see> used to
		/// paint the <see cref="T:System.Windows.Forms.DataGridViewCell"></see>.</param>
		/// <param name="clipBounds">A <see cref="T:System.Drawing.Rectangle"></see> that
		/// represents the area of the <see cref="T:System.Windows.Forms.DataGridView"></see>
		/// that needs to be repainted.</param>
		/// <param name="cellBounds">A <see cref="T:System.Drawing.Rectangle"></see> that
		/// contains the bounds of the <see cref="T:System.Windows.Forms.DataGridViewCell"></see>
		/// that is being painted.</param>
		/// <param name="rowIndex">The row index of the cell that is being painted.</param>
		/// <param name="cellState">A bitwise combination of
		/// <see cref="T:System.Windows.Forms.DataGridViewElementStates"></see> values that
		/// specifies the state of the cell.</param>
		/// <param name="value">The data of the <see cref="T:System.Windows.Forms.DataGridViewCell">
		/// </see> that is being painted.</param>
		/// <param name="formattedValue">The formatted data of the
		/// <see cref="T:System.Windows.Forms.DataGridViewCell"></see> that is being painted.
		/// </param>
		/// <param name="errorText">An error message that is associated with the cell.</param>
		/// <param name="cellStyle">A <see cref="T:System.Windows.Forms.DataGridViewCellStyle">
		/// </see> that contains formatting and style information about the cell.</param>
		/// <param name="advancedBorderStyle">A
		/// <see cref="T:System.Windows.Forms.DataGridViewAdvancedBorderStyle"></see> that
		/// contains border styles for the cell that is being painted.</param>
		/// <param name="paintParts">A bitwise combination of the
		/// <see cref="T:System.Windows.Forms.DataGridViewPaintParts"></see> values that
		/// specifies which parts of the cell need to be painted.</param>
		/// ------------------------------------------------------------------------------------
		protected override void Paint(Graphics graphics, Rectangle clipBounds,
			Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState,
			object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle,
			DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
		{
			if (!m_fAllowPaint)
				return;

			// Clear the background
			using (Region background = new Region(cellBounds))
			{
				background.Xor(GetCellContentDisplayRectangle(advancedBorderStyle));
				background.Intersect(clipBounds);
				graphics.FillRegion(SystemBrushes.Window, background);
			}

			// Invalidate the view so that it redraws
			if (m_Control != null)
			{
				Point pt = m_Control.PointToClient(DataGridView.PointToScreen(new Point(clipBounds.X, clipBounds.Y)));
//				Rectangle borderRect = BorderWidths(advancedBorderStyle);
				Rectangle toDraw = new Rectangle(0, 0,
					cellBounds.Width, cellBounds.Height);
				Rectangle clientClip = new Rectangle(pt.X, pt.Y, clipBounds.Width, clipBounds.Height);
				toDraw.Intersect(clientClip);
				m_Control.Invalidate(toDraw, true);
				m_Control.Update();
			}

			// Finally draw the borders
			if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border)
			{
#if !__MonoCS__
				PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
#else
				// TODO-Linux: Something possibly DataGridView (but not it seems the ViewControl itself) - if drawing border over this border
				// so to work around this problem just draw border 2 pixel's in - not a great solution :)
				// Need to fix The DataGridView not to do this.
				PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
				if (cellBounds.Width > 2)
					cellBounds.Inflate(-2, -2);
				PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
#endif
			}
		}
Esempio n. 30
0
            public override void VisitRadialGradientBrush( Types.Rectangle bounds, Paint.Brushes.RadialGradientBrush radialGradientBrush )
            {
                double dx = radialGradientBrush.InnerPoint.X - radialGradientBrush.OuterPoint.X;
                double dy = radialGradientBrush.InnerPoint.Y - radialGradientBrush.OuterPoint.Y;

                float radius = (float) Math.Sqrt( dx * dx + dy * dy );

                if( radius == 0 )
                {
                    return;
                }

                using( GraphicsPath gp = new GraphicsPath() )
                {
                    gp.StartFigure();
                    gp.AddEllipse( (float) radialGradientBrush.InnerPoint.X - radius, (float) radialGradientBrush.InnerPoint.Y - radius, radius * 2, radius * 2 );

                    Region around = new Region();

                    around.MakeInfinite();
                    around.Xor( gp );

                    SolidBrush b = new SolidBrush( GdiPlusUtility.Convert.Color( radialGradientBrush.OuterColor ) );

                    _brushes.Add( new ClippedStandardBrushStage( _graphics, b, around ) );

                    PathGradientBrush radialBrush = new PathGradientBrush( gp );

                    radialBrush.CenterColor = GdiPlusUtility.Convert.Color( radialGradientBrush.InnerColor );
                    radialBrush.CenterPoint = GdiPlusUtility.Convert.Point( radialGradientBrush.InnerPoint );
                    radialBrush.SurroundColors = new Color[] { GdiPlusUtility.Convert.Color( radialGradientBrush.OuterColor ) };
                    radialBrush.WrapMode = WrapMode.Clamp;

                    _brushes.Add( new StandardBrushStage( radialBrush ) );
                }
            }
Esempio n. 31
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (this.DesignMode) return;
            if (this.drawArea.DrawMode== DrawModeType.Normal)image=null;
            if (this.drawArea.CurrentOperation ==  ToolOperation.Roam && image!=null && beginMove)
            {
                e.Graphics.DrawImage(image,offx,offy);

                return;
            }
            else
            {
                Graphics g = e.Graphics;

                if (this.drawArea.DrawMode==DrawModeType.MemoryImage)
                {
                    if(image ==null)
                    {
                        image = new Bitmap(Width,Height);
                        MG = Graphics.FromImage(image);
                    }
                    g = MG;
                    g.Clip = new Region(new Rectangle(0, 0, Width, Height));

                }
                //�ϷŽ���ִ��
                if (image!=null&&(Math.Abs(offx) > 0 || Math.Abs(offy) > 0) )
                {
                    if(drawArea.DrawMode == DrawModeType.ScreenImage)
                    {
                        g.DrawImage(image, offx, offy);
                        Rectangle rt1 = new Rectangle(nRule, nRule, image.Width-nRule, image.Height-nRule);
                        Rectangle rt2 = rt1;
                        Rectangle rt3 = rt1;
                        rt3.Offset(offx, offy);
                        rt2.Intersect(rt3);
                        Region rg = new Region(rt1);
                        rg.Xor(rt2);
                        g.Clip = rg;
                        offx = offy = 0;
                        image = null;
                    }
                    else
                    {
                        System.Drawing.Image image2 = new Bitmap(image.Width, image.Height);
                        g = Graphics.FromImage(image2);
                        g.DrawImage(image, offx, offy);

                        Rectangle rt1 = new Rectangle(0, 0, image.Width, image.Height);
                        Rectangle rt2 = rt1;
                        Rectangle rt3 = rt1;
                        rt3.Offset(offx, offy);
                        rt2.Intersect(rt3);
                        g.SetClip(rt2, CombineMode.Exclude);

                        offx = offy = 0;
                        image = image2;
                        MG=g;
                    }
                }
                else if (this.drawArea.DrawMode==DrawModeType.MemoryImage){g.Clear(Color.Transparent);
                }
                DateTime time1=DateTime.Now;
                if (this.svgDocument != null)
                {
                    Matrix matrix1 = new Matrix();
                    matrix1.Translate(-this.virtualLeft, -this.virtualTop);
                    matrix1.Translate(this.margin.Width, this.margin.Height);
                    matrix1.Scale(this.scale, this.scale);
                    GraphicsContainer container1 = g.BeginContainer();
                    g.SmoothingMode = this.svgDocument.SmoothingMode;

                    if (this.svgDocument.RootElement is Group)
                    {
                        Group group2 = (Group) this.svgDocument.RootElement;
                        group2.GraphTransform.Matrix = matrix1.Clone();
                        try
                        {
                            group2.Draw(g, this.svgDocument.ControlTime);
                        }
                        catch
                        {}
                        this.elementList = group2.GraphList;
                    }
                    g.EndContainer(container1);
                    DateTime time2=DateTime.Now;

                    this.DrawSelection(g);

                    if (this.selectChanged)
                    {
                        RectangleF ef1 = this.selectpath.GetBounds();

                        this.oldselectPoint = new PointF(ef1.X + (ef1.Width / 2f), ef1.Y + (ef1.Height / 2f));

                        this.selectChanged = false;
                    }
                    if ( !this.oldselectPoint.IsEmpty 	)
                    {
                        PointF[] tfArray1 = new PointF[1] { this.oldselectPoint } ;
                        this.selectMatrix.TransformPoints(tfArray1);
                        this.drawArea.CenterPoint = tfArray1[0];
                        if(this.drawArea.Operation==ToolOperation.FreeTransform)
                        {
                            g.SmoothingMode =SmoothingMode.HighQuality;
                            PointF tf1 = this.drawArea.CenterPoint;
                            GraphicsPath path2 = new GraphicsPath();
                            path2.AddEllipse(tf1.X - 2.5f, tf1.Y - 2.5f, 5f, 5f);
                            g.FillPath(Brushes.White, path2);
                            g.DrawPath(Pens.Blue, path2);
                            path2.Dispose();
                        }
                    }
                    if (this.drawArea.ShowGuides)
                    {
                        foreach (RefLine line1 in this.drawArea.RefLines)
                        {
                            PointF tf2 = PointF.Empty;
                            //                        int num2 = base.Width;
                            if (line1.Hori)
                            {
                                tf2 = new PointF(0f, (float) line1.Pos);
                            }
                            else
                            {
                                tf2 = new PointF((float) line1.Pos, 0f);
                                //                            num2 = base.Height;
                            }
                            tf2 = this.drawArea.PointToSystem(tf2);
                            Pen pen1=new Pen(Color.Blue);
                            pen1.DashStyle=DashStyle.Dash;
                            if (line1.Hori)
                            {
                                g.DrawLine(pen1, 0f, tf2.Y, (float) base.Width, tf2.Y);
                                continue;
                            }
                            g.DrawLine(pen1, tf2.X, 0f, tf2.X, (float) base.Height);
                            pen1.Dispose();
                        }
                    }
                    matrix1.Dispose();
                    if(drawArea.DrawMode == DrawModeType.MemoryImage)
                    {
                        e.Graphics.DrawImage(image,0,0);
                    }
                }
                PointF pf= this.drawArea.GetCenterPoint();
                this.drawArea.ToolTip(string.Format("x:{0},y:{1}",pf.X,pf.Y),2);
            //				drawCount++;
            //				time2=DateTime.Now;
            //				TimeSpan ts=time2-time1;
            //				this.drawArea.ToolTip(this.svgDocument.SelectCollection.Count+","+this.ElementList.Count+","+ drawCount+","+ts.Seconds+":"+ts.Milliseconds+","+this.virtualLeft+":"+this.virtualTop,2);

            }
        }