Clone() public méthode

public Clone ( ) : Region
Résultat Region
        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);
        }
Exemple #2
0
        /// <summary>
        /// Initialize a new instance of the Clipping class.
        /// </summary>
        /// <param name="graphics">Graphics context.</param>
        /// <param name="path">Path to clip.</param>
        /// <param name="exclude">Exclude path from clipping.</param>
        public Clipping(Graphics graphics, GraphicsPath path, bool exclude)
        {
            // Cache graphics instance
            _graphics = graphics;

            // Save the existing clipping region
            _previousRegion = _graphics.Clip;

            // Add clipping of path to existing clipping region
            _newRegion = _previousRegion.Clone();

            if (exclude)
                _newRegion.Exclude(path);
            else
                _newRegion.Intersect(path);

            _graphics.Clip = _newRegion;
        }
Exemple #3
0
		/// <summary>
		/// Paints the shape on the canvas
		/// </summary>
		/// <param name="g"></param>
		/// 

		public override void Paint(System.Drawing.Graphics g)
		{
			g.SmoothingMode = SmoothingMode.AntiAlias;
			Rectangle toggleNode = Rectangle.Empty; //the [+] [-]
			Point[] pts = new Point[12]
				{
					new Point(rectangle.X,rectangle.Y), //0
					new Point(rectangle.X+bshift,rectangle.Y), //1
					new Point(rectangle.Right-bshift,rectangle.Y), //2
					new Point(rectangle.Right,rectangle.Y), //3
					new Point(rectangle.Right,rectangle.Y+bshift), //4
					new Point(rectangle.Right,rectangle.Bottom-bshift), //5
					new Point(rectangle.Right,rectangle.Bottom), //6
					new Point(rectangle.Right-bshift,rectangle.Bottom), //7
					new Point(rectangle.X+bshift,rectangle.Bottom), //8
					new Point(rectangle.X,rectangle.Bottom), //9
					new Point(rectangle.X,rectangle.Bottom - bshift), //10
					new Point(rectangle.X,rectangle.Y+bshift), //11				
			};
			path = new GraphicsPath();
			path.AddBezier(pts[11],pts[0],pts[0],pts[1]);
			path.AddLine(pts[1],pts[2]);
			path.AddBezier(pts[2],pts[3],pts[3],pts[4]);
			path.AddLine(pts[4],pts[5]);
			path.AddBezier(pts[5],pts[6],pts[6],pts[7]);
			path.AddLine(pts[7],pts[8]);
			path.AddBezier(pts[8],pts[9],pts[9],pts[10]);
			path.AddLine(pts[10],pts[11]);
			path.CloseFigure();
			region = new Region(path);

			shapeBrush = new LinearGradientBrush(rectangle,this.shapeColor,Color.WhiteSmoke,0f);
			
			// start Draw Shadow
			shadow = region.Clone();
			shadow.Translate(5, 5);
			

			//add the amount of children
			if (childNodes.Count > 0)
			{
				plus = " [" + childNodes.Count + "]";				
			}
			else
			{
				plus = "";
			}
			
			g.FillRegion(new SolidBrush(Color.Gainsboro), shadow);
			//g.DrawPath(new Pen(Color.Gainsboro,1), shadow);
			//End Draw Shadow

			g.FillRegion(shapeBrush, region);
			
			
            
			if (hovered || isSelected)			
				pen = thickPen;				
			else			
				pen = blackPen;				
			
			g.DrawPath(pen, path);
		
			if (text != string.Empty)
			{
				//g.DrawString(text + plus,font,Brushes.Black, rectangle.X+5,rectangle.Y+5);
				g.DrawString(text,font,Brushes.Black, rectangle.X+5,rectangle.Y+5);
			}

		

			//draw the [+] expansion shape
			if (childNodes.Count > 0)
			{
				switch(site.LayoutDirection)
				{
				
					case TreeDirection.Vertical:
						toggleNode = new Rectangle(Left + this.Width/2 - 5, Bottom, 10, 10);
						break;
					case TreeDirection.Horizontal:
						toggleNode = new Rectangle(Right , Top +Height/2-5 , 10, 10);
						break;
				}
				
                
				//Draw [ ]
				g.FillRectangle(new SolidBrush(Color.White), toggleNode);
				g.DrawRectangle(blackPen, toggleNode);
                
				//Draw -
				g.DrawLine(blackPen, (toggleNode.X + 2), (toggleNode.Y + (toggleNode.Height / 2)), (toggleNode.X + (toggleNode.Width - 2)), (toggleNode.Y + (toggleNode.Height / 2)) );
                
				if (!this.Expanded)
				{
					//Draw |
					g.DrawLine(blackPen, (toggleNode.X + (toggleNode.Width /2)), (toggleNode.Y + 2), (toggleNode.X + (toggleNode.Width /2)), (toggleNode.Y + (toggleNode.Height - 2)));
				}
			}
		}
Exemple #4
0
        public static BitmapPosData CreateFromDesktopImageInClippedRegion(Region rg, Point[] ptPath)
        {
            Console.WriteLine("CopyDesktopImageToClippedRegion");

            BitmapPosData data = null;
            int screenX;
            int screenY;
            IntPtr hBmp;
            IntPtr hdcScreen = GetDC(GetDesktopWindow());
            IntPtr hdcCompatible = CreateCompatibleDC(hdcScreen);

            screenX = GetSystemMetrics(0);
            screenY = GetSystemMetrics(1);
            hBmp = CreateCompatibleBitmap(hdcScreen, screenX, screenY);

            if (hBmp != IntPtr.Zero)
            {
                IntPtr hOldBmp = (IntPtr)SelectObject(hdcCompatible, hBmp);
                BitBlt(hdcCompatible, 0, 0, screenX, screenY, hdcScreen, 0, 0, 13369376);

                SelectObject(hdcCompatible, hOldBmp);
                DeleteDC(hdcCompatible);
                ReleaseDC(GetDesktopWindow(), hdcScreen);

                Bitmap bmpDt = System.Drawing.Image.FromHbitmap(hBmp);
                Graphics gd = Graphics.FromImage(bmpDt);
                RectangleF rc = rg.GetBounds(gd);
                Bitmap bmpClip = new Bitmap((int)rc.Width, (int)rc.Height);
                Graphics gt = Graphics.FromImage(bmpClip);
                Region rgnTempPict = rg.Clone();
                rgnTempPict.Translate(-rc.X, -rc.Y);
                gt.SetClip(rgnTempPict, System.Drawing.Drawing2D.CombineMode.Replace);
                RectangleF rc2 = rg.GetBounds(gt);
                gt.DrawImage(bmpDt, new Rectangle(0, 0, bmpClip.Width, bmpClip.Height), new Rectangle((int)rc.X, (int)rc.Y, (int)rc.Width, (int)rc.Height), GraphicsUnit.Pixel);
                for (int i = 0; i < ptPath.Length; i++)
                {
                    ptPath[i].Offset((int)-rc.X, (int)-rc.Y);
                }
                data = new BitmapPosData(bmpClip, rgnTempPict.Clone(), new Point(0, 0), ptPath);
                rgnTempPict.Dispose();

                gd.Dispose();
                gt.Dispose();

                DeleteObject(hBmp);
                GC.Collect();
            }
            return data;
        }
 public PdnRegion(Region region, bool takeOwnership)
 {
     if (takeOwnership)
     {
         this.gdiRegion = region;
     }
     else
     {
         this.gdiRegion = region.Clone();
     }
 }
 /// <summary>
 /// Initialize a new instance of the UseClipping class.
 /// </summary>
 /// <param name="g">Graphics instance.</param>
 /// <param name="region">Clipping region.</param>
 public UseClipping(Graphics g, Region region)
 {
     _g = g;
     _old = g.Clip;
     Region clip = _old.Clone();
     clip.Intersect(region);
     _g.Clip = clip;
 }
Exemple #7
0
        public void CopyDesktopImageInClippedRegion(Region rg, Point[] ptPath)
        {
            Console.WriteLine("CopyDesktopImageToClippedRegion");

            int screenX;
            int screenY;
            IntPtr hBmp;
            IntPtr hdcScreen = GetDC(GetDesktopWindow());
            IntPtr hdcCompatible = CreateCompatibleDC(hdcScreen);

            screenX = GetSystemMetrics(0);
            screenY = GetSystemMetrics(1);
            hBmp = CreateCompatibleBitmap(hdcScreen, screenX, screenY);

            if (hBmp != IntPtr.Zero)
            {
                IntPtr hOldBmp = (IntPtr)SelectObject(hdcCompatible, hBmp);
                BitBlt(hdcCompatible, 0, 0, screenX, screenY, hdcScreen, 0, 0, 13369376);

                SelectObject(hdcCompatible, hOldBmp);
                DeleteDC(hdcCompatible);
                ReleaseDC(GetDesktopWindow(), hdcScreen);

                Bitmap bmpDt = System.Drawing.Image.FromHbitmap(hBmp);
                Graphics gd = Graphics.FromImage(bmpDt);
                RectangleF rc = rg.GetBounds(gd);
                Bitmap bmpClip = new Bitmap((int)rc.Width, (int)rc.Height);
                Graphics gt = Graphics.FromImage(bmpClip);
                Region rgnTempPict = rg.Clone();
                rgnTempPict.Translate(-rc.X, -rc.Y);
                gt.SetClip(rgnTempPict, System.Drawing.Drawing2D.CombineMode.Replace);
                RectangleF rc2 = rg.GetBounds(gt);
                gt.DrawImage(bmpDt, new Rectangle(0, 0, bmpClip.Width, bmpClip.Height), new Rectangle((int)rc.X, (int)rc.Y, (int)rc.Width, (int)rc.Height), GraphicsUnit.Pixel);
                for (int i = 0; i < ptPath.Length; i++)
                {
                    ptPath[i].Offset((int)-rc.X, (int)-rc.Y);
                }
                mCopiedBmpData = new FormNote.BitmapPosData(bmpClip, rgnTempPict.Clone(), new Point(0, 0), ptPath);
                /*
                //temp image for moving (transparent)
                if (mPickedBmpDataTmp != null)
                {
                    mPickedBmpDataTmp.Dispose();
                    mPickedBmpDataTmp = null;
                }
                mPickedBmpDataTmp = new BitmapPosData();
                mPickedBmpDataTmp.location = mPickedBmpData.location;
                mPickedBmpDataTmp.region = mPickedBmpData.region.Clone();
                mPickedBmpDataTmp.bmp = new Bitmap(mPickedBmpData.bmp);
                for (int y = 0; y < mPickedBmpDataTmp.bmp.Height; y++)
                {
                    for (int x = 0; x < mPickedBmpDataTmp.bmp.Width; x++)
                    {
                        Color c = mPickedBmpDataTmp.bmp.GetPixel(x, y);
                        Color cc = Color.FromArgb(127, c.R, c.G, c.B);
                        mPickedBmpDataTmp.bmp.SetPixel(x, y, cc);
                    }
                }
                */
                rgnTempPict.Dispose();

                gd.Dispose();
                gt.Dispose();

                DeleteObject(hBmp);
                GC.Collect();
            }
        }
 public void InvalidateOverlays(Region screenRegion)
 {
     for (int i = this.overlayList.Count - 1; i >= 0; i--)
     {
         Control control = this.overlayList[i] as Control;
         if (control != null)
         {
             Rectangle bounds = control.Bounds;
             bounds.Location = control.PointToScreen(control.Location);
             using (Region region = screenRegion.Clone())
             {
                 region.Intersect(bounds);
                 region.Translate(-bounds.X, -bounds.Y);
                 control.Invalidate(region);
             }
         }
     }
 }
        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++;
        }
Exemple #10
0
        /// <summary>
        /// Initialize a new instance of the Clipping class.
        /// </summary>
        /// <param name="graphics">Graphics context.</param>
        /// <param name="rect">Clipping rectangle.</param>
        /// <param name="exclude">Exclude rectangle from clipping.</param>
        public Clipping(Graphics graphics, Rectangle rect, bool exclude)
        {
            // Cache graphics instance
            _graphics = graphics;

            // Save the existing clipping region
            _previousRegion = _graphics.Clip;

            // Add clipping of rectangle to existing clipping region
            _newRegion = _previousRegion.Clone();

            if (exclude)
                _newRegion.Exclude(rect);
            else
                _newRegion.Intersect(rect);

            _graphics.Clip = _newRegion;
        }
		/// <summary>
		/// Pushes the current clip onto the clip stack and sets clip of the graphics context to
		/// the intersection of the current clip and the given clip.
		/// </summary>
		/// <remarks>
		/// The intersection of the current local clip and the new local clip is also pushed onto
		/// the local clip stack.
		/// </remarks>
		/// <param name="aClip">The clip to push.</param>
		public virtual void PushClip(Region aClip) {
			RectangleF newLocalClip = RectangleF.Intersect(LocalClip, aClip.GetBounds(graphics));
			localClipStack.Push(newLocalClip);

			Region currentClip = Graphics.Clip;
			clipStack.Push(currentClip);
			aClip = aClip.Clone();
			aClip.Intersect(currentClip);
			Graphics.Clip = aClip;
		}
Exemple #12
0
		private void DrawRegions( Graphics g, int offset, string s, Region r1, Region r2, Region r3)
		{
			using (Pen p = new Pen(Color.Black))
			{
				using (Brush b1 = new SolidBrush(Color.Red), b2 = new SolidBrush(Color.Green), bl = new SolidBrush(Color.Blue))
				{
					Region region1 = r1.Clone();
					Region region2 = r2.Clone();
					Region region3 = r3.Clone();
					int x = (offset%4) * 110;
					int y = (int)offset / 4*80;
					g.DrawString(s,Font, bl, x, y);
					region1.Translate(x, y + 20);
					region2.Translate(x, y + 20);
					region3.Translate(x + 55, y + 20);
					g.FillRegion(b1,region1);
					g.DrawRectangle(p, Rectangle.Truncate(region1.GetBounds(g)));
					g.FillRegion(b2,region2);
					g.DrawRectangle(p, Rectangle.Truncate(region2.GetBounds(g)));
					g.FillRegion(b1,region3);
					g.DrawRectangle(p, Rectangle.Truncate(region3.GetBounds(g)));
				}
			}
		}
Exemple #13
0
        // Called whenever the map display changes.
        void MapChanged(Region regionChanged)
        {
            if (regionChanged == null) {
                // null region means everything.
                MarkAllInvalid();
            }

            if (allInvalid)
                return;     // nothing more to do.

            // Copy the region and transform to bitmap coords.
            Region copy = regionChanged.Clone();
            copy.Transform(matTransform);

            // Union with the invalid region.
            if (allValid) {
                allValid = false;
                invalidRegion = regionChanged;
            }
            else
                invalidRegion.Union(regionChanged);
        }
Exemple #14
0
		public void MultiCombinedPathRegion ()
		{
			// note: seems identical to PathRegion but it test another code path inside libgdiplus
			Region r1 = new Region (sp1);
			r1.Xor (sp2);
			Region r2 = new Region (sp2);
			r2.Complement (sp1);

			Region r = r1.Clone ();
			r.Union (r2);
			RegionData data = r.GetRegionData ();
			Assert.IsNotNull (data.Data, "Data");
			Region region = new Region (data);
			Assert.IsTrue (r.GetBounds (graphic).Equals (region.GetBounds (graphic)), "Bounds");
		}
	// Uses the current selection positions to set what is selected in drawLayout
	// Sets the update to redraw only the characters that have changed
	internal override void SelectInternal(int start, int length)
	{
		if (start == selectionStartActual && length == selectionLengthActual)
		{
			return;
		}
		if (!IsHandleCreated)
		{
			return;
		}
		Region newRegion = new Region(RectangleF.Empty);
		selectionStartActual = start;
		selectionLengthActual = length;
		for (int i = 0; i < Text.Length; i++) 
		{
			bool selected = (i>=GetSelectionStart() && i < GetSelectionStart() + GetSelectionLength());
			layout.Items[i].selected = selected;
			Rectangle b = layout.Items[i].bounds;
			b = new Rectangle(b.Left, b.Top, b.Width, b.Height + 1);
			if (selected)
			{
				newRegion.Union(b);
			}
		}
		// Find the region we need to redraw by Xoring with old
		if (selectedRegion != null)
		{
			Region redrawRegion = newRegion.Clone();
			redrawRegion.Xor(selectedRegion);
			redrawRegion.Translate(-XViewOffset, -YViewOffset);
			// Only allow updates in the TextDrawArea
			redrawRegion.Intersect(new Region(TextDrawArea));
			AddUpdate(redrawRegion);
		}
		else
		{
			AddUpdate(newRegion);
		}
		selectedRegion = newRegion;

	}
        /// <summary>
        /// Pushes the current clip onto the clip stack and sets clip of the graphics context to
        /// the intersection of the current clip and the given clip.
        /// </summary>
        /// <remarks>
        /// The intersection of the current local clip and the new local clip is also pushed onto
        /// the local clip stack.
        /// </remarks>
        /// <param name="aClip">The clip to push.</param>
        public virtual void PushClip(Region aClip)
        {
            RectangleF aClipBounds = aClip.GetBounds(graphics.Graphics);
            RectangleF transformedClipBounds = Graphics.Matrix.Transform(aClipBounds);
            aClip = new Region(new Rectangle((int)Math.Floor(transformedClipBounds.X),
                (int)Math.Floor(transformedClipBounds.Y),
                (int)Math.Ceiling(transformedClipBounds.Width),
                (int)Math.Ceiling(transformedClipBounds.Height)));

            // Push the untransformed clip onto the local clip stack so that it will be transformed
            // when the matrix is pushed.
            RectangleF newLocalClip = PUtil.IntersectionOfRectangles(LocalClip, aClipBounds);
            localClipStack.Push(newLocalClip);

            // Push the transformed clip onto the clip stack since the graphics objec does not
            // contain a matrix and will not do the transforming itself.
            Region currentClip = Graphics.Clip;
            clipStack.Push(currentClip);
            aClip = aClip.Clone();
            aClip.Intersect(currentClip);
            Graphics.Clip = aClip;
        }
 /// <summary>
 /// Initialize a new instance of the UseClipping class.
 /// </summary>
 /// <param name="graphics">Graphics instance.</param>
 /// <param name="region">Clipping region.</param>
 public UseClipping(Graphics graphics, Region region)
 {
     g = graphics;
     oldRegion = g.Clip;
     Region clip = oldRegion.Clone();
     clip.Intersect(region);
     g.Clip = clip;
 }
Exemple #18
0
		public void Region_Ctor_GraphicsPath_Empty ()
		{
			Region region = new Region (new GraphicsPath ());
			CheckEmpty ("GraphicsPath.", region);

			Region clone = region.Clone ();
			CheckEmpty ("Clone.", region);
		}
 /// <summary>
 /// Initialize a new instance of the UseClipping class.
 /// </summary>
 /// <param name="graphics">Graphics instance.</param>
 /// <param name="path">Clipping path.</param>
 public UseClipping(Graphics graphics, GraphicsPath path)
 {
     g = graphics;
     oldRegion = graphics.Clip;
     Region clip = oldRegion.Clone();
     clip.Intersect(path);
     g.Clip = clip;
 }
	public void SetClip(Region region, CombineMode combineMode)
			{
				if(region == null)
				{
					throw new ArgumentNullException("region");
				}
				switch(combineMode)
				{
					case CombineMode.Replace:
					{
						clip = region.Clone();
					}
					break;

					case CombineMode.Intersect:
					{
						Clip.Intersect(region);
					}
					break;

					case CombineMode.Union:
					{
						Clip.Union(region);
					}
					break;

					case CombineMode.Xor:
					{
						Clip.Xor(region);
					}
					break;

					case CombineMode.Exclude:
					{
						Clip.Exclude(region);
					}
					break;

					case CombineMode.Complement:
					{
						Clip.Complement(region);
					}
					break;

					default: return;
				}
				UpdateClip();
			}
Exemple #21
0
		public void IsEqual ()
		{
			Region r1 = new Region (sp1);
			Region r2 = new Region (sp2);
			Region r3 = new Region (sp3);
			Region r4 = new Region (sp4);
			// with self
			Assert.IsTrue (r1.Equals (r1, graphic), "r1-r1");
			Assert.IsTrue (r2.Equals (r2, graphic), "r2-r2");
			Assert.IsTrue (r3.Equals (r3, graphic), "r3-r3");
			Assert.IsTrue (r4.Equals (r4, graphic), "r4-r4");
			// with a different
			Assert.IsFalse (r1.Equals (r4, graphic), "r1-r4");
			Assert.IsFalse (r2.Equals (r3, graphic), "r2-r3");
			Assert.IsFalse (r3.Equals (r2, graphic), "r3-r2");
			Assert.IsFalse (r4.Equals (r1, graphic), "r4-r1");
			// with same (not self)
			Region r5 = r1.Clone ();
			r1.Exclude (r4);
			Assert.IsTrue (r1.Equals (r5, graphic), "r1-r5");
			Assert.IsTrue (r5.Equals (r1, graphic), "r5-r1");
			Assert.IsFalse (r5.Equals (r4, graphic), "r5-r4");
			Assert.IsFalse (r4.Equals (r5, graphic), "r4-r5");
		}
Exemple #22
0
		public void Region_Empty ()
		{
			Region region = new Region ();
			CheckEmpty ("Empty.", region);

			Region clone = region.Clone ();
			CheckEmpty ("Clone.", region);

			RegionData data = region.GetRegionData ();
			Region r2 = new Region (data);
			CheckEmpty ("RegionData.", region);
		}
        private void plDraw_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                m_LButtonPressed = false;
            }

            switch (e.Button)
            {
                case System.Windows.Forms.MouseButtons.Left:
                {
                    switch (status.Action)
                    {
                        case UserActions.Linking:
                        {
                            for (int i = 0; i < m_rgObjects.Count; i++)
                            {
                                GOMLib.GOM_Point pt;

                                pt = m_rgObjects[i].GetConnectablePointAt(e.X, e.Y);

                                if (pt!= null)
                                {

                                    if ( m_selObjs[0]!=m_rgObjects[i] || m_selectedPoint!=pt )
                                    {
                                        GOMLib.GOM_Link				link;

                                        link = GOMLib.GOM_Default_Values.CreateLink( m_selObjs[0], m_selectedPoint, m_rgObjects[i], pt);
                                        AddLinkWithMergemence(link);
                                        m_selObjs.Clear();
                                        m_selectedLink = link;
                                        break;
                                    }

                                }
                            }

                            status.Action	= UserActions.Editing;
                            m_selectedPoint = null;
                            DrawObjectsOnCanvas();

                            break;
                        }
                        case UserActions.Sketching:
                        {
                            FinishCurrentSketchStroke();
                            break;
                        }
                        case UserActions.Editing:
                        {
                            break;
                        }
                        case UserActions.InsertObject:
                        {
                            GOMLib.GOM_Object_Primitive	primitive;

                            primitive = new GOMLib.GOM_Object_Primitive();
                            primitive.InitializeFromTemplate(status.Template);
                            primitive.xOffset = e.X;
                            primitive.yOffset = e.Y;
                            GOMLib.GOM_Default_Values.ScaleObject(primitive, 25, 25);
                            m_rgObjects.Add(primitive);

                            status.Action	= UserActions.Editing;
                            status.Template	= null;

                            m_selObjs.Clear();
                            m_selObjs.Add(primitive);

                            DrawObjectsOnCanvas();
                            break;
                        }
                        case UserActions.Controlling:
                        {
                            plDraw.Capture	= false;

                            status.Action	= UserActions.Editing;
                            m_selectedPoint	= null;
                            break;
                        }
                        case UserActions.Moving:
                        {
                            plDraw.Capture	= false;

                            status.Action	= UserActions.Editing;

                            if ( m_selObjs.Count == 1 )
                            {
                                GOMLib.GOM_Interface_Graphic_Object graphicObject = m_selObjs[0];

                                bool touched = false;
                                for ( int i=0; i<m_rgObjects.Count; i++ )
                                {
                                    GOMLib.GOM_Object_LinkNode linkNode = m_rgObjects[i] as GOMLib.GOM_Object_LinkNode;
                                    if ( !(graphicObject is GOMLib.GOM_Object_LinkNode) && linkNode != null )
                                    {
                                        GOMLib.GOM_Links links = GetLinks(linkNode);
                                        if ( links.Count == 1 )
                                        {
                                            GOMLib.GOM_Point touchedPoint = graphicObject.GetConnectablePointAt((int)linkNode.xOffset, (int)linkNode.yOffset);
                                            if ( touchedPoint != null )
                                            {
                                                if ( links[0].m_startObj == linkNode )
                                                {
                                                    links[0].m_startObj = graphicObject;
                                                    links[0].m_startPt = touchedPoint;
                                                }
                                                else
                                                {
                                                    links[0].m_endObj = graphicObject;
                                                    links[0].m_endPt = touchedPoint;
                                                }
                                                m_rgObjects.Remove(linkNode);
                                                touched = true;
                                            }
                                        }
                                    }
                                }

                                if ( touched )
                                {
                                    DrawObjectsOnCanvas();
                                }
                            }

                            break;
                        }
                        case UserActions.MovingKeyPoint:
                        {
                            m_selectedLinkKeyPoint = null;
                            status.Action	= UserActions.Editing;

                            if ( m_selectedLink.m_keyPts != null )
                            {
                                ArrayList pts = new ArrayList();
                                PointF ptf = m_selectedLink.StartPointInCanvas(m_rgObjects);
                                GOMLib.SketchPoint spt = new GOMLib.SketchPoint();
                                spt.x = (int)ptf.X;
                                spt.y = (int)ptf.Y;
                                pts.Add( spt );
                                for( int i=0; i<m_selectedLink.m_keyPts.Count; i++ )
                                {
                                    spt = new GOMLib.SketchPoint();
                                    spt.x = (int)m_selectedLink.m_keyPts[i].x;
                                    spt.y = (int)m_selectedLink.m_keyPts[i].y;
                                    pts.Add( spt );
                                }
                                ptf = m_selectedLink.EndPointInCanvas(m_rgObjects);
                                spt = new GOMLib.SketchPoint();
                                spt.x = (int)ptf.X;
                                spt.y = (int)ptf.Y;
                                pts.Add( spt );

                                pts = CalculateSegments(pts);

                                m_selectedLink.m_keyPts = new GOMLib.GOM_Points();
                                for( int i=0; i<(pts.Count-2); i++ )
                                {
                                    GOMLib.GOM_Point pt = new GOMLib.GOM_Point();
                                    pt.x = ((GOMLib.SketchPoint)pts[i+1]).x;
                                    pt.y = ((GOMLib.SketchPoint)pts[i+1]).y;
                                    m_selectedLink.m_keyPts.Add( pt );
                                }
                            }

                            DrawObjectsOnCanvas();
                            break;
                        }
                        case UserActions.Selecting:
                        {
                            System.Drawing.Region	rgn;
                            System.Drawing.Region	rgnIntersect;
                            System.Drawing.Graphics	canvas;

                            rgn		= new Region(m_selectingRect);

                            canvas	= plDraw.CreateGraphics();

                            for (int i = 0; i < m_rgObjects.Count; i++)
                            {
                                rgnIntersect = rgn.Clone();
                                rgnIntersect.Intersect(m_rgObjects[i].BoundingRegion);

                                if (!rgnIntersect.IsEmpty(canvas))
                                {
                                    m_selObjs.Add(m_rgObjects[i]);
                                }
                            }
                            plDraw.Capture	= false;

                            status.Action	= UserActions.Editing;

                            m_selectingRect.X		= 0;
                            m_selectingRect.Y		= 0;
                            m_selectingRect.Width	= 0;
                            m_selectingRect.Height	= 0;

                            DrawObjectsOnCanvas();
                            break;
                        }
                    }
                    break;
                }
            }
        }
Exemple #24
0
		public void TestCloneAndEquals()
		{
			Bitmap bmp = new Bitmap (600, 800);
			Graphics dc = Graphics.FromImage (bmp);
			Rectangle rect1, rect2;
			Region rgn1, rgn2;
			RectangleF [] rects;
			RectangleF [] rects2;
			Matrix matrix = new Matrix ();

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

			rects = rgn1.GetRegionScans (matrix);
			rects2 = rgn2.GetRegionScans (matrix);

			Assert.AreEqual (rects.Length, rects2.Length);

			for (int i = 0; i < rects.Length; i++) {

				Assert.AreEqual (rects[i].X, rects[i].X);
				Assert.AreEqual (rects[i].Y, rects[i].Y);
				Assert.AreEqual (rects[i].Width, rects[i].Width);
				Assert.AreEqual (rects[i].Height, rects[i].Height);
			}

			Assert.AreEqual (true, rgn1.Equals (rgn2, dc));
		}
 /// <summary>
 /// Initialize a new instance of the UseClipping class.
 /// </summary>
 /// <param name="g">Graphics instance.</param>
 /// <param name="path">Clipping path.</param>
 public UseClipping(Graphics g, GraphicsPath path)
 {
     _g = g;
     _old = g.Clip;
     Region clip = _old.Clone();
     clip.Intersect(path);
     _g.Clip = clip;
 }
	public void Invalidate(Region region, bool invalidateChildren)
			{
				if (!Visible)
				{
					return; // nothing to do 
				}

				if (toolkitWindow == null)
				{
					if ((parent == null) || (!parent.IsHandleCreated))
					{
						return;
					}

					CreateControl ();
				}

				using (Region region1 = region.Clone())
				{
					InvalidateInternal(region1, invalidateChildren);
					using (Graphics g = CreateGraphics())
					{
						Rectangle bounds = Rectangle.Truncate(region.GetBounds(g));
						OnInvalidated(new InvalidateEventArgs(bounds));
					}
				}
			}
 public override bool OnMouseMove(Glyph g, MouseButtons button, Point mouseLoc)
 {
     if (!this.pushedBehavior)
     {
         return false;
     }
     bool flag = Control.ModifierKeys == Keys.Alt;
     if (flag && (this.dragManager != null))
     {
         this.dragManager.EraseSnapLines();
     }
     if (flag || !mouseLoc.Equals(this.lastMouseLoc))
     {
         if (this.lastMouseAbs != null)
         {
             System.Design.NativeMethods.POINT pt = new System.Design.NativeMethods.POINT(mouseLoc.X, mouseLoc.Y);
             System.Design.UnsafeNativeMethods.ClientToScreen(new HandleRef(this, this.behaviorService.AdornerWindowControl.Handle), pt);
             if ((pt.x == this.lastMouseAbs.x) && (pt.y == this.lastMouseAbs.y))
             {
                 return true;
             }
         }
         if (!this.dragging)
         {
             if ((Math.Abs((int) (this.initialPoint.X - mouseLoc.X)) <= (DesignerUtils.MinDragSize.Width / 2)) && (Math.Abs((int) (this.initialPoint.Y - mouseLoc.Y)) <= (DesignerUtils.MinDragSize.Height / 2)))
             {
                 return false;
             }
             this.InitiateResize();
             this.dragging = true;
         }
         if ((this.resizeComponents == null) || (this.resizeComponents.Length == 0))
         {
             return false;
         }
         PropertyDescriptor descriptor = null;
         PropertyDescriptor descriptor2 = null;
         PropertyDescriptor descriptor3 = null;
         PropertyDescriptor descriptor4 = null;
         if (this.initialResize)
         {
             descriptor = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Width"];
             descriptor2 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Height"];
             descriptor3 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Top"];
             descriptor4 = TypeDescriptor.GetProperties(this.resizeComponents[0].resizeControl)["Left"];
             if ((descriptor != null) && !typeof(int).IsAssignableFrom(descriptor.PropertyType))
             {
                 descriptor = null;
             }
             if ((descriptor2 != null) && !typeof(int).IsAssignableFrom(descriptor2.PropertyType))
             {
                 descriptor2 = null;
             }
             if ((descriptor3 != null) && !typeof(int).IsAssignableFrom(descriptor3.PropertyType))
             {
                 descriptor3 = null;
             }
             if ((descriptor4 != null) && !typeof(int).IsAssignableFrom(descriptor4.PropertyType))
             {
                 descriptor4 = null;
             }
         }
         Control resizeControl = this.resizeComponents[0].resizeControl as Control;
         this.lastMouseLoc = mouseLoc;
         this.lastMouseAbs = new System.Design.NativeMethods.POINT(mouseLoc.X, mouseLoc.Y);
         System.Design.UnsafeNativeMethods.ClientToScreen(new HandleRef(this, this.behaviorService.AdornerWindowControl.Handle), this.lastMouseAbs);
         int num = Math.Max(resizeControl.MinimumSize.Height, 10);
         int num2 = Math.Max(resizeControl.MinimumSize.Width, 10);
         if (this.dragManager != null)
         {
             bool flag2 = true;
             bool shouldSnapHorizontally = true;
             if ((((this.targetResizeRules & SelectionRules.BottomSizeable) != SelectionRules.None) || ((this.targetResizeRules & SelectionRules.TopSizeable) != SelectionRules.None)) && (resizeControl.Height == num))
             {
                 flag2 = false;
             }
             else if ((((this.targetResizeRules & SelectionRules.RightSizeable) != SelectionRules.None) || ((this.targetResizeRules & SelectionRules.LeftSizeable) != SelectionRules.None)) && (resizeControl.Width == num2))
             {
                 flag2 = false;
             }
             PropertyDescriptor descriptor5 = TypeDescriptor.GetProperties(resizeControl)["IntegralHeight"];
             if (descriptor5 != null)
             {
                 object obj2 = descriptor5.GetValue(resizeControl);
                 if ((obj2 is bool) && ((bool) obj2))
                 {
                     shouldSnapHorizontally = false;
                 }
             }
             if (!flag && flag2)
             {
                 this.lastSnapOffset = this.dragManager.OnMouseMove(resizeControl, this.GenerateSnapLines(this.targetResizeRules, mouseLoc), ref this.didSnap, shouldSnapHorizontally);
             }
             else
             {
                 this.dragManager.OnMouseMove(new Rectangle(-100, -100, 0, 0));
             }
             mouseLoc.X += this.lastSnapOffset.X;
             mouseLoc.Y += this.lastSnapOffset.Y;
         }
         Rectangle rectangle = new Rectangle(this.resizeComponents[0].resizeBounds.X, this.resizeComponents[0].resizeBounds.Y, this.resizeComponents[0].resizeBounds.Width, this.resizeComponents[0].resizeBounds.Height);
         if (this.didSnap && (resizeControl.Parent != null))
         {
             rectangle.Location = this.behaviorService.MapAdornerWindowPoint(resizeControl.Parent.Handle, rectangle.Location);
             if (resizeControl.Parent.IsMirrored)
             {
                 rectangle.Offset(-rectangle.Width, 0);
             }
         }
         Rectangle empty = Rectangle.Empty;
         Rectangle dragRect = Rectangle.Empty;
         bool flag4 = true;
         Color backColor = (resizeControl.Parent != null) ? resizeControl.Parent.BackColor : Color.Empty;
         for (int i = 0; i < this.resizeComponents.Length; i++)
         {
             Control c = this.resizeComponents[i].resizeControl as Control;
             Rectangle bounds = c.Bounds;
             Rectangle rc = bounds;
             Rectangle resizeBounds = this.resizeComponents[i].resizeBounds;
             Rectangle rect = this.BehaviorService.ControlRectInAdornerWindow(c);
             bool flag5 = true;
             System.Design.UnsafeNativeMethods.SendMessage(c.Handle, 11, false, 0);
             try
             {
                 bool flag6 = false;
                 if ((c.Parent != null) && c.Parent.IsMirrored)
                 {
                     flag6 = true;
                 }
                 BoundsSpecified none = BoundsSpecified.None;
                 SelectionRules resizeRules = this.resizeComponents[i].resizeRules;
                 if (((this.targetResizeRules & SelectionRules.BottomSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.BottomSizeable) != SelectionRules.None))
                 {
                     int num4;
                     if (this.didSnap)
                     {
                         num4 = mouseLoc.Y - rectangle.Bottom;
                     }
                     else
                     {
                         num4 = AdjustPixelsForIntegralHeight(c, mouseLoc.Y - this.initialPoint.Y);
                     }
                     bounds.Height = Math.Max(num, resizeBounds.Height + num4);
                     none |= BoundsSpecified.Height;
                 }
                 if (((this.targetResizeRules & SelectionRules.TopSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.TopSizeable) != SelectionRules.None))
                 {
                     int num5;
                     if (this.didSnap)
                     {
                         num5 = rectangle.Y - mouseLoc.Y;
                     }
                     else
                     {
                         num5 = AdjustPixelsForIntegralHeight(c, this.initialPoint.Y - mouseLoc.Y);
                     }
                     none |= BoundsSpecified.Height;
                     bounds.Height = Math.Max(num, resizeBounds.Height + num5);
                     if ((bounds.Height != num) || ((bounds.Height == num) && (rc.Height != num)))
                     {
                         none |= BoundsSpecified.Y;
                         bounds.Y = Math.Min((int) (resizeBounds.Bottom - num), (int) (resizeBounds.Y - num5));
                     }
                 }
                 if (((((this.targetResizeRules & SelectionRules.RightSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.RightSizeable) != SelectionRules.None)) && !flag6) || ((((this.targetResizeRules & SelectionRules.LeftSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.LeftSizeable) != SelectionRules.None)) && flag6))
                 {
                     none |= BoundsSpecified.Width;
                     int x = this.initialPoint.X;
                     if (this.didSnap)
                     {
                         x = !flag6 ? rectangle.Right : rectangle.Left;
                     }
                     bounds.Width = Math.Max(num2, resizeBounds.Width + (!flag6 ? (mouseLoc.X - x) : (x - mouseLoc.X)));
                 }
                 if (((((this.targetResizeRules & SelectionRules.RightSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.RightSizeable) != SelectionRules.None)) && flag6) || ((((this.targetResizeRules & SelectionRules.LeftSizeable) != SelectionRules.None) && ((resizeRules & SelectionRules.LeftSizeable) != SelectionRules.None)) && !flag6))
                 {
                     none |= BoundsSpecified.Width;
                     int num7 = this.initialPoint.X;
                     if (this.didSnap)
                     {
                         num7 = !flag6 ? rectangle.Left : rectangle.Right;
                     }
                     int num8 = !flag6 ? (num7 - mouseLoc.X) : (mouseLoc.X - num7);
                     bounds.Width = Math.Max(num2, resizeBounds.Width + num8);
                     if ((bounds.Width != num2) || ((bounds.Width == num2) && (rc.Width != num2)))
                     {
                         none |= BoundsSpecified.X;
                         bounds.X = Math.Min((int) (resizeBounds.Right - num2), (int) (resizeBounds.X - num8));
                     }
                 }
                 if (!this.parentGridSize.IsEmpty)
                 {
                     bounds = this.AdjustToGrid(bounds, this.targetResizeRules);
                 }
                 if ((((none & BoundsSpecified.Width) == BoundsSpecified.Width) && this.dragging) && (this.initialResize && (descriptor != null)))
                 {
                     descriptor.SetValue(this.resizeComponents[i].resizeControl, bounds.Width);
                 }
                 if ((((none & BoundsSpecified.Height) == BoundsSpecified.Height) && this.dragging) && (this.initialResize && (descriptor2 != null)))
                 {
                     descriptor2.SetValue(this.resizeComponents[i].resizeControl, bounds.Height);
                 }
                 if ((((none & BoundsSpecified.X) == BoundsSpecified.X) && this.dragging) && (this.initialResize && (descriptor4 != null)))
                 {
                     descriptor4.SetValue(this.resizeComponents[i].resizeControl, bounds.X);
                 }
                 if ((((none & BoundsSpecified.Y) == BoundsSpecified.Y) && this.dragging) && (this.initialResize && (descriptor3 != null)))
                 {
                     descriptor3.SetValue(this.resizeComponents[i].resizeControl, bounds.Y);
                 }
                 if (this.dragging)
                 {
                     c.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height, none);
                     empty = this.BehaviorService.ControlRectInAdornerWindow(c);
                     if (c.Equals(resizeControl))
                     {
                         dragRect = empty;
                     }
                     if (c.Bounds == rc)
                     {
                         flag5 = false;
                     }
                     if (c.Bounds != bounds)
                     {
                         flag4 = false;
                     }
                 }
                 if ((c == this.primaryControl) && (this.statusCommandUI != null))
                 {
                     this.statusCommandUI.SetStatusInformation(c);
                 }
             }
             finally
             {
                 System.Design.UnsafeNativeMethods.SendMessage(c.Handle, 11, true, 0);
                 if (flag5)
                 {
                     Control parent = c.Parent;
                     if (parent != null)
                     {
                         c.Invalidate(true);
                         parent.Invalidate(rc, true);
                         parent.Update();
                     }
                     else
                     {
                         c.Refresh();
                     }
                 }
                 if (!empty.IsEmpty)
                 {
                     using (Region region = new Region(empty))
                     {
                         region.Exclude(Rectangle.Inflate(empty, -2, -2));
                         if (flag5)
                         {
                             using (Region region2 = new Region(rect))
                             {
                                 region2.Exclude(Rectangle.Inflate(rect, -2, -2));
                                 this.BehaviorService.Invalidate(region2);
                             }
                         }
                         if (!this.captureLost)
                         {
                             using (Graphics graphics = this.BehaviorService.AdornerWindowGraphics)
                             {
                                 if ((this.lastResizeRegion != null) && !this.lastResizeRegion.Equals(region, graphics))
                                 {
                                     this.lastResizeRegion.Exclude(region);
                                     this.BehaviorService.Invalidate(this.lastResizeRegion);
                                     this.lastResizeRegion.Dispose();
                                     this.lastResizeRegion = null;
                                 }
                                 DesignerUtils.DrawResizeBorder(graphics, region, backColor);
                             }
                             if (this.lastResizeRegion == null)
                             {
                                 this.lastResizeRegion = region.Clone();
                             }
                         }
                     }
                 }
             }
         }
         if ((flag4 && !flag) && (this.dragManager != null))
         {
             this.dragManager.RenderSnapLinesInternal(dragRect);
         }
         this.initialResize = false;
     }
     return true;
 }
	private void InvalidateInternal(Region region, bool invalidateChildren)
			{
				if(invalidateChildren)
				{
					for(int i = (numChildren - 1); i >= 0; --i)
					{
						Control child = children[i];
						if (child.visible)
						{
							Region region1 = (Region)region.Clone();
							region1.Intersect(child.Bounds);
							region1.Translate(-child.Left, - child.Top);
							child.InvalidateInternal(region1, true);
						}
					}
				}

				// Exclude the children from the invalidate
				for(int i = (numChildren - 1); i >= 0; --i)
				{
					Control child = children[i];
					if (child.visible)
					{
						region.Exclude(children[i].Bounds);
					}
				}

				// TODO Inefficient
				RectangleF[] rs = region.GetRegionScans(new Drawing.Drawing2D.Matrix());
				if( rs.Length > 0 ) {
					// TODO Inefficient
					Point p = ClientOrigin;
					Size  s = ClientSize;
					int xOrigin = p.X;
					int yOrigin = p.Y;
				// The rectangle relative to the toolkit that is the bounds for this control.
					Rectangle parentInvalidateBounds = new Rectangle(xOrigin, yOrigin, s.Width, s.Height);
					
					for(int i = 0; i < rs.Length; i++)
					{
						Rectangle b = Rectangle.Truncate(rs[i]);
						// Get in local coordinates.
						b.Offset(xOrigin, yOrigin);
						b.Intersect(parentInvalidateBounds);
						if(!b.IsEmpty)
						{
							if(toolkitWindow == null)
							{
								CreateControl();
							}
							toolkitWindow.Invalidate(b.X, b.Y, b.Width, b.Height);
						}
					}
				}
			}