Union() public method

Updates this Region to the union of itself and the specified GraphicsPath.
public Union ( GraphicsPath path ) : void
path System.Drawing.Drawing2D.GraphicsPath Path.
return void
Beispiel #1
0
 /// <summary>
 /// Called when the form loads
 /// </summary>
 /// <param name="sender">what triggered the event</param>
 /// <param name="e">event args</param>
 private void MainForm_Load(object sender, EventArgs e)
 {
     // make cool shape
     Region r = new Region();
     GraphicsPath gp = new GraphicsPath();
     gp.AddEllipse(new Rectangle(0, 0, this.Width, this.Height));
     r.MakeEmpty();
     r.Union(gp);
     gp = new GraphicsPath();
     gp.AddRectangle(new Rectangle(this.Width / 2, 0, this.Width / 2, this.Height / 2));
     r.Union(gp);
     this.Region = r;
 }
Beispiel #2
0
			protected override void OnPaint (PaintEventArgs pevent)
			{
				Console.WriteLine ("ourLabelTwoAreas pevents {0}, pos {1} - size {2}", pevent.ClipRectangle,
					Location, Size);

				Region reg = new Region (new Rectangle (20, 20, 10, 10));
				reg.Union (new Rectangle (5, 5, 10, 10));
				pevent.Graphics.Clip  = reg;
				pevent.Graphics.FillRectangle (Brushes.Red, pevent.ClipRectangle);
			}
 private Region GetRegion(Bitmap _img)
 {
     var rgn = new Region();
     rgn.MakeEmpty();
     var rc = new Rectangle(0, 0, 0, 0);
     bool inimage = false;
     for (int y = 0; y < _img.Height; y++)
     {
         for (int x = 0; x < _img.Width; x++)
         {
             if (!inimage)
             {
                 // if pixel is not transparent
                 if (_img.GetPixel(x, y).A != 0)
                 {
                     inimage = true;
                     rc.X = x;
                     rc.Y = y;
                     rc.Height = 1;
                 }
             }
             else
             {
                 // if pixel is transparent
                 if (_img.GetPixel(x, y).A == 0)
                 {
                     inimage = false;
                     rc.Width = x - rc.X;
                     rgn.Union(rc);
                 }
             }
         }
         if (inimage)
         {
             inimage = false;
             rc.Width = _img.Width - rc.X;
             rgn.Union(rc);
         }
     }
     return rgn;
 }
Beispiel #4
0
        /// <summary>
        /// Returns whether the given rectangle, in screen coordinates, is visible in any screen's
        /// working area (the monitor's visible area minus task bars and docked windows)</summary>
        /// <param name="rect">Rectangle</param>
        /// <returns>Whether the given rectangle is visible</returns>
        public static bool IsOnScreen(Rectangle rect)
        {
            using (Region region = new Region())
            {
                region.MakeEmpty();
                foreach (Screen screen in Screen.AllScreens)
                    region.Union(screen.WorkingArea);

                rect.Inflate(-Margin, -Margin);
                return region.IsVisible(rect);
            }
        }
Beispiel #5
0
 public static void CreateRegion(Control control, Rectangle bounds, int radius, RoundStyle roundStyle)
 {
     using (GraphicsPath path = GraphicsPathHelper.CreatePath(bounds, radius, roundStyle, true))
     {
         Region region = new Region(path);
         path.Widen(Pens.White);
         region.Union(path);
         if (control.Region != null)
         {
             control.Region.Dispose();
         }
         control.Region = region;
     }
 }
Beispiel #6
0
 // Convert an Xsharp.Region to System.Drawing.Region
 internal static System.Drawing.Region RegionToDrawingRegion
     (Xsharp.Region region)
 {
     Xsharp.Rectangle[]    rectangles = region.GetRectangles();
     System.Drawing.Region newRegion  = new System.Drawing.Region();
     newRegion.MakeEmpty();
     for (int i = 0; i < rectangles.Length; i++)
     {
         Xsharp.Rectangle rect = rectangles[i];
         newRegion.Union(new System.Drawing.Rectangle
                             (rect.x, rect.y, rect.width, rect.height));
     }
     return(newRegion);
 }
        public Region CombineAreas()
        {
            Region region = new Region();
            region.MakeEmpty();

            foreach (Area area in Areas)
            {
                region.Union(area.Region);
            }

            region.Intersect(new Region(Crop.Bounds));

            return region;
        }
Beispiel #8
0
		protected override Region GetTabsRegion(TabsCollection tabs, TabItem lastTab)
		{
			bool bFirstVisible=true;
			Region tabRegion=new Region();
			tabRegion.MakeEmpty();
			foreach(TabItem tab in tabs)
			{
				if(!tab.Visible)
					continue;				
				GraphicsPath path=GetTabItemPath(tab,bFirstVisible,(tab==lastTab));
				tabRegion.Union(path);
				bFirstVisible=false;
			}
			return tabRegion;
		}
Beispiel #9
0
        /// <summary>
        /// Paints to one image the series of layers between start and length
        /// and returns that image. Of all these layers, only start should have
        /// the UsesNonOpaqueOverwrite property true (and it need not have that
        /// property set to true).
        /// </summary>
        private void LayerSeriesPaint(int start, int length, Image image)
        {
            Debug.Assert(start >= 0 && start + length <= this.myLayers.Count && length > 0);

            // Establish the region that needs to be painted for all layers.
            // The region to be painted is union of all regions' dirty areas.
            System.Drawing.Region region = new System.Drawing.Region();
            for (int i = start; i < start + length; i++)
            {
                Debug.Assert(i == start ||
                             !((SlideViewLayer)this.myLayers[i]).UsesNonOpaqueOverwrite ||
                             !((SlideViewLayer)this.myLayers[i]).VisibleLayer);
                if (this.myLayerDirtyRegions[i] != null)
                {
                    region.Union((System.Drawing.Region) this.myLayerDirtyRegions[i]);
                }
            }

            // Set up the graphics context.
            Graphics g = Graphics.FromImage(image);

            g.Clip = region;

            // Clear the canvas for painting.
            g.Clear(Color.Transparent);

            // Paint the layers
            for (int i = start; i < start + length; i++)
            {
                if (((SlideViewLayer)this.myLayers[i]).VisibleLayer)
                {
                    ((SlideViewLayer)this.myLayers[i]).Paint(g);
                }
                if (this.myLayerDirtyRegions[i] != null)
                {
                    ((System.Drawing.Region) this.myLayerDirtyRegions[i]).Dispose();
                }
                this.myLayerDirtyRegions[i] = null;
            }

            g.Dispose();
            region.Dispose();
        }
        static BlockRegions()
        {
            int n = Constants.PROJ_WIDTH / 4;

            WholeBlock = new Region();
            WholeBlock.MakeEmpty();
            for (int i = 0; i <= n; i++)
            {
                WholeBlock.Union(new Rectangle(n * 2 - 1 - 2 * i, i, i * 4 + 2, Constants.PROJ_HEIGHT - 2 * i));
            }
            WholeBlock.Intersect(new Rectangle(0, 0, Constants.PROJ_WIDTH, Constants.PROJ_HEIGHT));
            InnerBlock = new Region();
            InnerBlock.MakeEmpty();
            for (int i = 0; i <= n; i++)
            {
                InnerBlock.Union(new Rectangle(n * 2 - 1 - 2 * i, i + 1, i * 4 + 2, Constants.PROJ_HEIGHT - 2 - 2 * i));
            }
            InnerBlock.Intersect(new Rectangle(1, 1, Constants.PROJ_WIDTH - 2, Constants.PROJ_HEIGHT - 2));

            OuterBorder = WholeBlock.Clone();
            OuterBorder.Exclude(InnerBlock);

            Top = InnerBlock.Clone();
            Top.Translate(0, -Constants.BLOCK_HEIGHT);
            Top.Intersect(InnerBlock);

            Left = InnerBlock.Clone();
            Left.Exclude(Top);
            Top.Translate(0, 1);
            Left.Exclude(Top);
            Top.Translate(0, -1);

            Right = Left.Clone();
            Left.Intersect(new Rectangle(0, 0, Constants.PROJ_WIDTH / 2, Constants.PROJ_HEIGHT));
            Right.Intersect(new Rectangle(Constants.PROJ_WIDTH / 2 + 1, 0, Constants.PROJ_WIDTH / 2, Constants.PROJ_HEIGHT));

            InnerBorder = InnerBlock.Clone();
            InnerBorder.Exclude(Top);
            InnerBorder.Exclude(Left);
            InnerBorder.Exclude(Right);
        }
Beispiel #11
0
		public void TestBounds()
		{
			Bitmap bmp = new Bitmap (600, 800);
			Graphics dc = Graphics.FromImage (bmp);
			Rectangle rect1, rect2;
			Region rgn1, rgn2;
			RectangleF bounds;

			rect1 = new Rectangle (500, 30, 60, 80);
			rect2 = new Rectangle (520, 40, 60, 80);
			rgn1 = new Region(rect1);
			rgn2 = new Region(rect2);
			rgn1.Union(rgn2);

			bounds = rgn1.GetBounds (dc);

			Assert.AreEqual (500, bounds.X);
			Assert.AreEqual (30, bounds.Y);
			Assert.AreEqual (80, bounds.Width);
			Assert.AreEqual (90, bounds.Height);
		}
Beispiel #12
0
        public void Tick()
        {
            System.Drawing.Region r = new System.Drawing.Region();
            int living = 0;
            var ruleset = ((RuleSet)cbRuleSet.SelectedItem);
            for (int x = 0; x <= zellen.GetUpperBound(0); x++)
            {
                for (int y = 0; y <= zellen.GetUpperBound(1); y++)
                {
                    zellen[x, y].Aenderung = ruleset.applyRuleset(zellen[x, y].Status, getLivingNeighbours(x, y));
                }
            }

            for (int x = 0; x <= zellen.GetUpperBound(0); x++)
            {
                for (int y = 0; y <= zellen.GetUpperBound(1); y++)
                {
                    if (zellen[x, y].Status != zellen[x, y].Aenderung)
                    {
                        zellen[x, y].hasChanged = true;
                        zellen[x, y].Status = zellen[x, y].Aenderung;
                        r.Union(canvas.getRectangle(x, y));
                    }
                    living += zellen[x, y].Status == ZellenStatus.Lebt ? 1 : 0;
                }
            }
            ticks++;
            lblTicks.Text = ticks.ToString();
            lblLivingCells.Text = living.ToString();
            canvas.Invalidate(r);
            if (cbLimit.Checked && ticks >= nupLimit.Value)
            {
                Stop();
            }
            if (cbEnableStats.Checked)
            {
                _stats.Add(new StatisticEntry(ticks, living));
            }
        }
Beispiel #13
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();
        }
        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();
        }
Beispiel #15
0
 public Region this[int c]
 {
     get {
     if (this.cgrom[c] == null)
     {
         int C = c * charHeight;
         Region r = new Region();
         r.MakeEmpty();
         for (int y = 0; y < charHeight; ++y)
         {
             byte row = this.cgrom_raw[C + y];
             for (int x = 0; x < charWidth && row != 0; ++x)
             {
                 if ((row & 0x80) == 0x80)
                     r.Union(new Rectangle(x, y, 1, 1));
                 row <<= 1;
             }
         }
         this.cgrom[c] = r;
     }
     return this.cgrom[c];
     }
 }
		void OnMouseLeave (object sender, EventArgs e)
		{
			Region region_to_invalidate = new Region ();
			region_to_invalidate.MakeEmpty ();
			bool dirty = false;
			if (ThemeEngine.Current.ScrollBarHasHoverArrowButtonStyle) {
				region_to_invalidate.Union (first_arrow_area);
				region_to_invalidate.Union (second_arrow_area);
				dirty = true;
			} else
				if (ThemeEngine.Current.ScrollBarHasHotElementStyles)
					if (first_button_entered) {
						region_to_invalidate.Union (first_arrow_area);
						dirty = true;
					} else if (second_button_entered) {
						region_to_invalidate.Union (second_arrow_area);
						dirty = true;
					}
			if (ThemeEngine.Current.ScrollBarHasHotElementStyles)
				if (thumb_entered) {
					region_to_invalidate.Union (thumb_pos);
					dirty = true;
				}
			first_button_entered = false;
			second_button_entered = false;
			thumb_entered = false;
			if (dirty)
				Invalidate (region_to_invalidate);
			region_to_invalidate.Dispose ();
		}
		void OnMouseEnter (object sender, EventArgs e)
		{
			if (ThemeEngine.Current.ScrollBarHasHoverArrowButtonStyle) {
				Region region_to_invalidate = new Region (first_arrow_area);
				region_to_invalidate.Union (second_arrow_area);
				Invalidate (region_to_invalidate);
			}
		}
 internal static void TakeWorkflowSnapShot(WorkflowView workflowView, ViewPortData viewPortData)
 {
     Bitmap memoryBitmap = viewPortData.MemoryBitmap;
     using (Graphics graphics = Graphics.FromImage(memoryBitmap))
     {
         graphics.SmoothingMode = SmoothingMode.HighQuality;
         graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
         using (PaintEventArgs args = new PaintEventArgs(graphics, viewPortData.LogicalViewPort))
         {
             workflowView.ActiveLayout.OnPaint(args, viewPortData);
         }
         Matrix matrix = new Matrix();
         matrix.Scale(viewPortData.Scaling.Width, viewPortData.Scaling.Height, MatrixOrder.Prepend);
         Point[] pts = new Point[] { viewPortData.LogicalViewPort.Location };
         matrix.TransformPoints(pts);
         matrix.Translate((float) (-pts[0].X + viewPortData.ShadowDepth.Width), (float) (-pts[0].Y + viewPortData.ShadowDepth.Height), MatrixOrder.Append);
         graphics.Transform = matrix;
         if (workflowView.RootDesigner != null)
         {
             using (Region region = new Region())
             {
                 using (GraphicsPath path = ActivityDesignerPaint.GetDesignerPath(workflowView.RootDesigner, false))
                 {
                     Region clip = graphics.Clip;
                     region.MakeEmpty();
                     region.Union(path);
                     graphics.Clip = region;
                     AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;
                     graphics.FillRectangle(ambientTheme.BackgroundBrush, workflowView.RootDesigner.Bounds);
                     if (ambientTheme.ShowGrid)
                     {
                         ActivityDesignerPaint.DrawGrid(graphics, workflowView.RootDesigner.Bounds);
                     }
                     graphics.Clip = clip;
                     try
                     {
                         using (PaintEventArgs args2 = new PaintEventArgs(graphics, viewPortData.LogicalViewPort))
                         {
                             ((IWorkflowDesignerMessageSink) workflowView.RootDesigner).OnPaint(args2, viewPortData.LogicalViewPort);
                         }
                     }
                     catch (Exception)
                     {
                     }
                 }
             }
         }
         using (PaintEventArgs args3 = new PaintEventArgs(graphics, workflowView.RootDesigner.Bounds))
         {
             using (WorkflowMessageDispatchData data = new WorkflowMessageDispatchData(workflowView, EventArgs.Empty))
             {
                 foreach (WorkflowDesignerMessageFilter filter in data.Filters)
                 {
                     try
                     {
                         if (((IWorkflowDesignerMessageSink) filter).OnPaint(args3, viewPortData.LogicalViewPort))
                         {
                             goto Label_0230;
                         }
                     }
                     catch (Exception)
                     {
                     }
                 }
             }
         }
     Label_0230:
         graphics.Transform = new Matrix();
         if (!viewPortData.ShadowDepth.IsEmpty)
         {
             Bitmap image = new Bitmap(memoryBitmap);
             using (Brush brush = new SolidBrush(Color.FromArgb(220, Color.White)))
             {
                 graphics.FillRectangle(brush, new Rectangle(Point.Empty, new Size((memoryBitmap.Size.Width - viewPortData.ShadowDepth.Width) - 1, (memoryBitmap.Size.Height - viewPortData.ShadowDepth.Height) - 1)));
             }
             ImageAttributes imageAttr = new ImageAttributes();
             imageAttr.SetColorKey(viewPortData.TransparentColor, viewPortData.TransparentColor, ColorAdjustType.Default);
             imageAttr.SetColorKey(viewPortData.TransparentColor, viewPortData.TransparentColor, ColorAdjustType.Bitmap);
             graphics.DrawImage(image, new Rectangle(-viewPortData.ShadowDepth.Width, -viewPortData.ShadowDepth.Height, memoryBitmap.Width, memoryBitmap.Height), 0, 0, memoryBitmap.Width, memoryBitmap.Height, GraphicsUnit.Pixel, imageAttr);
             image.Dispose();
         }
     }
 }
Beispiel #19
0
		/// <summary>
		/// When we are dragging over
		/// </summary>
		/// <param name="e"></param>
		protected override void OnDragOver(DragEventArgs e)
		{
			Rectangle screen = this.Parent.RectangleToScreen(new Rectangle(this.Location.X, this.Location.Y, this.Width, this.Height));
			Point mousePoint = new Point(e.X, e.Y);
			if (screen.Contains(mousePoint) == false)
			{
				e.Effect = DragDropEffects.None;
			}
			else if (_draggedBitmap != null)
			{
				e.Effect = DragDropEffects.Move;
				using (Graphics g = this.CreateGraphics())
				{
					Point mouseClientPoint = this.PointToClient(mousePoint);
					int x = 0;
					int y = Math.Max(mouseClientPoint.Y - _draggedBitmapOffsetY, 0);
					Rectangle rect = new Rectangle(x, y, _draggedBitmap.Width, _draggedBitmap.Height);
					g.DrawImageUnscaled(_draggedBitmap, rect);

					if (_draggedBitmapRect != Rectangle.Empty)
					{
						// invalidate the extent between the old rect and this one
						Region region = new Region(rect);
						region.Union(_draggedBitmapRect);
						region.Exclude(rect);
						this.Invalidate(region);
					}

					_draggedBitmapRect = rect;
				}
			}
		}
Beispiel #20
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");
		}
Beispiel #21
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");
		}
Beispiel #22
0
		public void SmallUnion_Self2 ()
		{
			Region region = new Region (sp2);
			region.Union (sp2);
			CompareSmallRegion (region, self2, 7, 7);

			RectangleF[] scans = region.GetRegionScans (matrix);
			Assert.AreEqual (1, scans.Length, "GetRegionScans");
			CheckRectF ("[0]", 2, 2, 3, 3, scans[0]);
		}
Beispiel #23
0
		public void SmallUnion2 ()
		{
			Region region = new Region (sp2);
			region.Union (sp1);
			CompareSmallRegion (region, sunion, 7, 7);

			RectangleF[] scans = region.GetRegionScans (matrix);
			Assert.AreEqual (3, scans.Length, "GetRegionScans");
			CheckRectF ("[0]", 0, 0, 3, 2, scans[0]);
			CheckRectF ("[1]", 0, 2, 5, 1, scans[1]);
			CheckRectF ("[2]", 2, 3, 3, 2, scans[2]);
		}
 public void CreateRegion(
     Control control,
     Rectangle bounds,
     int radius)
 {
     using (GraphicsPath path =
         CreatePath(
         bounds, radius))
     {
         Region region = new Region(path);
         path.Widen(Pens.White);
         region.Union(path);
         if (control.Region != null)
         {
             control.Region.Dispose();
         }
         control.Region = region;
     }
 }
Beispiel #25
0
        private void Invalidate(int i1, int i2)
        {
            Rectangle rect;

            if (i2 == -1)
            {
                i2 = i1;
            }

            rect = rectangles[i2];
            Region r = new Region(rect);
            if (i1 != -1)
            {
                try
                {
                    rect = rectangles[i1];
                    r.Union(rect);
                }
                catch (IndexOutOfRangeException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            r.Translate(AutoScrollPosition.X, AutoScrollPosition.Y);
            Invalidate(r);
            r.Dispose();
        }
Beispiel #26
0
		internal override PaintEventArgs PaintEventStart(ref Message msg, IntPtr handle, bool client)
		{
			PaintEventArgs	paint_event;
			Hwnd		hwnd;
			Hwnd		paint_hwnd;
			
			// 
			// handle  (and paint_hwnd) refers to the window that is should be painted.
			// msg.HWnd (and hwnd) refers to the window that got the paint message.
			// 
			
			hwnd = Hwnd.ObjectFromHandle(msg.HWnd);
			if (msg.HWnd == handle) {
				paint_hwnd = hwnd;
			} else {
				paint_hwnd = Hwnd.ObjectFromHandle (handle);
			}
	
			if (Caret.Visible == true) {
				Caret.Paused = true;
				HideCaret();
			}

			Graphics dc;

			if (client) {
				dc = Graphics.FromHwnd (paint_hwnd.client_window);

				Region clip_region = new Region ();
				clip_region.MakeEmpty();

				foreach (Rectangle r in hwnd.ClipRectangles) {
					/* Expand the region slightly.
					 * See bug 464464.
					 */
					Rectangle r2 = Rectangle.FromLTRB (r.Left, r.Top, r.Right, r.Bottom + 1);
					clip_region.Union (r2);
				}

				if (hwnd.UserClip != null) {
					clip_region.Intersect(hwnd.UserClip);
				}

				dc.Clip = clip_region;
				paint_event = new PaintEventArgs(dc, hwnd.Invalid);
				hwnd.expose_pending = false;

				hwnd.ClearInvalidArea();

				hwnd.drawing_stack.Push (paint_event);
				hwnd.drawing_stack.Push (dc);

				return paint_event;
			} else {
				dc = Graphics.FromHwnd (paint_hwnd.whole_window);

				if (!hwnd.nc_invalid.IsEmpty) {
					dc.SetClip (hwnd.nc_invalid);
					paint_event = new PaintEventArgs(dc, hwnd.nc_invalid);
				} else {
					paint_event = new PaintEventArgs(dc, new Rectangle(0, 0, hwnd.width, hwnd.height));
				}
				hwnd.nc_expose_pending = false;

				hwnd.ClearNcInvalidArea ();

				hwnd.drawing_stack.Push (paint_event);
				hwnd.drawing_stack.Push (dc);

				return paint_event;
			}
		}
        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++;
        }
Beispiel #28
0
		public void UnionWithoutIntersection ()
		{
			Region region = new Region (sp1);
			region.Union (sp3);
			CompareSmallRegion (region, ni_union, 11,5 );
		}
                private void RefreshChanges()
                {
                    Region region = new Region(Rectangle.Empty);
                    Rectangle rectDockArea = FullPanelEdge ? DockPanel.DockArea : DockPanel.DocumentWindowBounds;

                    rectDockArea = RectangleToClient(DockPanel.RectangleToScreen(rectDockArea));
                    if (ShouldPanelIndicatorVisible(DockState.DockLeft))
                    {
                        PanelLeft.Location = new Point(rectDockArea.X + _PanelIndicatorMargin, rectDockArea.Y + (rectDockArea.Height - PanelRight.Height) / 2);
                        PanelLeft.Visible = true;
                        region.Union(PanelLeft.Bounds);
                    }
                    else
                        PanelLeft.Visible = false;

                    if (ShouldPanelIndicatorVisible(DockState.DockRight))
                    {
                        PanelRight.Location = new Point(rectDockArea.X + rectDockArea.Width - PanelRight.Width - _PanelIndicatorMargin, rectDockArea.Y + (rectDockArea.Height - PanelRight.Height) / 2);
                        PanelRight.Visible = true;
                        region.Union(PanelRight.Bounds);
                    }
                    else
                        PanelRight.Visible = false;

                    if (ShouldPanelIndicatorVisible(DockState.DockTop))
                    {
                        PanelTop.Location = new Point(rectDockArea.X + (rectDockArea.Width - PanelTop.Width) / 2, rectDockArea.Y + _PanelIndicatorMargin);
                        PanelTop.Visible = true;
                        region.Union(PanelTop.Bounds);
                    }
                    else
                        PanelTop.Visible = false;

                    if (ShouldPanelIndicatorVisible(DockState.DockBottom))
                    {
                        PanelBottom.Location = new Point(rectDockArea.X + (rectDockArea.Width - PanelBottom.Width) / 2, rectDockArea.Y + rectDockArea.Height - PanelBottom.Height - _PanelIndicatorMargin);
                        PanelBottom.Visible = true;
                        region.Union(PanelBottom.Bounds);
                    }
                    else
                        PanelBottom.Visible = false;

                    if (ShouldPanelIndicatorVisible(DockState.Document))
                    {
                        Rectangle rectDocumentWindow = RectangleToClient(DockPanel.RectangleToScreen(DockPanel.DocumentWindowBounds));
                        PanelFill.Location = new Point(rectDocumentWindow.X + (rectDocumentWindow.Width - PanelFill.Width) / 2, rectDocumentWindow.Y + (rectDocumentWindow.Height - PanelFill.Height) / 2);
                        PanelFill.Visible = true;
                        region.Union(PanelFill.Bounds);
                    }
                    else
                        PanelFill.Visible = false;

                    if (ShouldPaneDiamondVisible())
                    {
                        Rectangle rect = RectangleToClient(DockPane.RectangleToScreen(DockPane.ClientRectangle));
                        PaneDiamond.Location = new Point(rect.Left + (rect.Width - PaneDiamond.Width) / 2, rect.Top + (rect.Height - PaneDiamond.Height) / 2);
                        PaneDiamond.Visible = true;
                        using (GraphicsPath graphicsPath = PaneIndicator.DisplayingGraphicsPath.Clone() as GraphicsPath)
                        {
                            Point[] pts = new Point[]
						{
							new Point(PaneDiamond.Left, PaneDiamond.Top),
							new Point(PaneDiamond.Right, PaneDiamond.Top),
							new Point(PaneDiamond.Left, PaneDiamond.Bottom)
						};
                            using (Matrix matrix = new Matrix(PaneDiamond.ClientRectangle, pts))
                            {
                                graphicsPath.Transform(matrix);
                            }
                            region.Union(graphicsPath);
                        }
                    }
                    else
                        PaneDiamond.Visible = false;

                    Region = region;
                }
Beispiel #30
0
        private void GraphPanel_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            bool Retour = BoutonGEnfonce && BoutonDEnfonce;
            if (e.Button == MouseButtons.Left) BoutonGEnfonce = false;
            else if (e.Button == MouseButtons.Right) BoutonDEnfonce = false;
            else return;
            if (Retour) return;

            switch (Mode)
            {
                case Action.Dessiner:
                    {
                        if (TempN1 == null || TempN2 == null) return;
                        bool AjouterArc = false;
                        Rectangle AncienRect = Boite(TempN1, TempN2);
                        AjouterN2 = NoeudSelonPosition(e.X, e.Y, ref TempN2);
                        if (AjouterN1) { TempN1.Isolate(); G.AddNode(TempN1); }
                        if (!Collision(TempN1, TempN2))
                        {
                            if (AjouterN2) { TempN2.Isolate(); G.AddNode(TempN2); }
                            if (e.Button == MouseButtons.Left)
                                G.AddArc(TempN1, TempN2, 1);
                            else if (e.Button == MouseButtons.Right) G.Add2Arcs(TempN1, TempN2, 1);
                            NbArcsPanel.Text = G.Arcs.Count.ToString();
                            AjouterArc = true;
                        }
                        NbNodesPanel.Text = G.Nodes.Count.ToString();

                        if (AjouterArc && (!AjouterN1 || !AjouterN2) && AdapterAEtoile()) GraphPanel.Invalidate();
                        else
                        {
                            Rectangle NouveauRect = Boite(TempN1, TempN2);
                            GraphPanel.Invalidate(Rectangle.Union(AncienRect, NouveauRect));
                        }
                        break;
                    }
                case Action.Effacer:
                    {
                        if (TempN1 == null || TempN2 == null) return;
                        bool Selection = false;
                        Rectangle Zone = RectangleCentres(TempN1, TempN2);
                        Zone.Inflate(1, 1);
                        Region Invalide = new Region(Zone);
                        if (Zone.Size.Width < 2 * Rayon && Zone.Size.Height < 2 * Rayon)
                        {
                            SimWaypoint N = NoeudSousJacent(e.X, e.Y);
                            if (N != null)
                            {
                                TestAEtoile(N, ref Invalide);
                                Invalide.Union(Boite(N.Molecule));
                                G.RemoveNode(N);
                                NbNodesPanel.Text = G.Nodes.Count.ToString();
                                NbArcsPanel.Text = G.Arcs.Count.ToString();
                                Selection = true;
                            }
                            else
                            {
                                SimRoute A = ArcSousJacent(e.X, e.Y);
                                if (A != null)
                                {
                                    Invalide.Union(Boite(A.StartNode, A.EndNode));
                                    G.RemoveArc(A);
                                    NbArcsPanel.Text = G.Arcs.Count.ToString();
                                    Selection = true;
                                }
                            }
                        }
                        else
                        {
                            ArrayList ListeNoeuds = new ArrayList();
                            foreach (SimWaypoint N in G.Nodes)
                            {
                                if (Zone.Contains(new Point((int)N.DX, (int)N.DY)))
                                {
                                    TestAEtoile(N, ref Invalide);
                                    Invalide.Union(Boite(N.Molecule));
                                    ListeNoeuds.Add(N);
                                    Selection = true;
                                }
                            }
                            foreach (SimWaypoint N in ListeNoeuds) G.RemoveNode(N);
                            NbNodesPanel.Text = G.Nodes.Count.ToString();
                            NbArcsPanel.Text = G.Arcs.Count.ToString();
                        }

                        if (Selection && AdapterAEtoile()) GraphPanel.Invalidate();
                        else GraphPanel.Invalidate(Invalide);
                        break;
                    }
                case Action.ChangerEtat:
                    {
                        SimWaypoint N = NoeudSousJacent(e.X, e.Y);
                        Region Invalide = null;
                        if (N != null)
                        {
                            N.IsPassable = !N.IsPassable;
                            Invalide = new Region(Boite(N.Molecule));
                        }
                        else
                        {
                            SimRoute A = ArcSousJacent(e.X, e.Y);
                            if (A != null)
                            {
                                A.Passable = !A.Passable;
                                Invalide = new Region(Boite(A.StartNode, A.EndNode));
                            }
                        }

                        if (Invalide != null)
                        {
                            if (AdapterAEtoile()) GraphPanel.Invalidate();
                            else GraphPanel.Invalidate(Invalide);
                        }
                        break;
                    }
                case Action.AEtoile:
                    {
                        double Distance;
                        SimWaypoint NoeudPlusProche = G.ClosestNode(e.X / DSCALE + StartX, e.Y / DSCALE + StartY, 0, out Distance, true);
                        if (NoeudPlusProche == null) break;
                        Rectangle Invalide = Boite(NoeudPlusProche);

                        if (NDepart != null) Invalide = Rectangle.Union(Invalide, Boite(NDepart));
                        if (NArrivee != null) Invalide = Rectangle.Union(Invalide, Boite(NArrivee));

                        if (e.Button == MouseButtons.Left) NDepart = NDepart == NoeudPlusProche ? null : NoeudPlusProche;
                        else if (e.Button == MouseButtons.Right) NArrivee = NArrivee == NoeudPlusProche ? null : NoeudPlusProche;

                        if (AdapterAEtoile()) GraphPanel.Invalidate();
                        else
                        {
                            if (Chemin != null)
                            {
                                Chemin = null;
                                GraphPanel.Invalidate();
                            }
                            else GraphPanel.Invalidate(Invalide);
                        }
                        break;
                    }
                default: break;
            }
            TempN1 = TempN2 = null;
        }
Beispiel #31
0
        public void Draw(Graphics g)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;

            using (Pen axisPen = new Pen(AxisColor, AxisWidth))
            using (Pen majorPen = new Pen(AxisColor, MajorTickWidth))
            using (Pen minorPen = new Pen(AxisColor, MinorTickWidth))
            using (Brush labelBrush = new SolidBrush(LabelColor))
            {
                axisPen.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Round);
                majorPen.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Round);
                minorPen.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Round);

                try
                {
                    g.DrawPath(axisPen, m_arcPath);
                    g.DrawPath(majorPen, m_majorTicksPath);
                    g.DrawPath(minorPen, m_minorTicksPath);
                    g.FillPath(labelBrush, m_labelPath);
                }
                catch { }
            }

            //now these areas need to be redrawn if they change
            m_redrawRegion.Dispose();
            m_redrawRegion = new Region();
            m_redrawRegion.Union(m_arcPath);
            m_redrawRegion.Union(m_labelPath);
            m_redrawRegion.Union(m_majorTicksPath);
            m_redrawRegion.Union(m_minorTicksPath);
        }
Beispiel #32
0
 void TestAEtoile(SimWaypoint N, ref Region ZoneInvalide)
 {
     if (N != null)
     {
         if (N == NDepart) NDepart = null;
         if (N == NArrivee) NArrivee = null;
         if (Chemin != null && Array.IndexOf(Chemin, N) >= 0)
         {
             Chemin = null;
             ZoneInvalide.Union(new Rectangle(new Point(0, 0), GraphPanel.Size));
         }
     }
 }