Beispiel #1
0
        public Region(RegionData otherRgnData)
        {
            if (otherRgnData == null)
            {
                throw new ArgumentNullException("rgnData", "Argument cannot be null");
            }
            Region r = otherRgnData.ConstructRegion(otherRgnData);

            this.rects   = r.rects;
            this.extent  = r.extent;
            this.rgnData = r.GetRegionData();
        }
Beispiel #2
0
		public void Region_Ctor_RegionData ()
		{
			Region region = new Region (new GraphicsPath ());
			RegionData data = region.GetRegionData ();
			Region r2 = new Region (data);
			CheckEmpty ("RegionData.", region);
		}
Beispiel #3
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);
		}
        public PdnRegion(SerializationInfo info, StreamingContext context)
        {
            byte[] data = (byte[])info.GetValue("data", typeof(byte[]));

            using (Region region = new Region())
            {
                RegionData regionData = region.GetRegionData();
                regionData.Data = data;
                this.gdiRegion = new Region(regionData);
            }

            this.lockObject = new object();
            this.cachedArea = -1;
            this.cachedBounds = Rectangle.Empty;
            this.changed = true;
            this.cachedRects = null;
            this.cachedRectsF = null;
        }
Beispiel #5
0
		public void EmptyRegion ()
		{
			// note: an empty region is (for libgdiplus) a rectangular based region
			Region empty = new Region ();
			RegionData data = empty.GetRegionData ();
			Assert.IsNotNull (data.Data, "Data");
			Region region = new Region (data);
		}
Beispiel #6
0
		public void PathRegion ()
		{
			GraphicsPath path = new GraphicsPath ();
			path.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
			Region r = new Region (path);
			RegionData data = r.GetRegionData ();
			Assert.IsNotNull (data.Data, "Data");
			Region region = new Region (data);
			Assert.IsTrue (r.GetBounds (graphic).Equals (region.GetBounds (graphic)), "Bounds");
		}
        /*
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        */
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle r = ClientRectangle;
            Graphics g = e.Graphics;
            Region originalClip = new Region(g.Clip.GetRegionData());

            DrawBackground(g, r);
            g.Clip = new Region(originalClip.GetRegionData());
            DrawRows(g, r);
            g.Clip = new Region(originalClip.GetRegionData());
            DrawHeaders(g, r);
            g.Clip = new Region(originalClip.GetRegionData());
            DrawExtra(g, r);
            g.Clip = new Region(originalClip.GetRegionData());
            DrawBorder(g, r);
            g.Clip = new Region(originalClip.GetRegionData());
        }
Beispiel #8
0
		public void CombinedPathRegion ()
		{
			// note: seems identical to PathRegion but it test another code path inside libgdiplus
			Region r = new Region (sp1);
			r.Xor (sp2);
			RegionData data = r.GetRegionData ();
			Assert.IsNotNull (data.Data, "Data");
			Region region = new Region (data);
			Assert.IsTrue (r.GetBounds (graphic).Equals (region.GetBounds (graphic)), "Bounds");
		}
Beispiel #9
0
		public void ctor_RectangleF () {
			Region r1 = new Region (rect);
			Assert.AreEqual (r.GetRegionData ().Data,
				r1.GetRegionData ().Data);
		}
Beispiel #10
0
		public void ctor_Rectangle () {
			Region r1 = new Region (new Rectangle ((int)rect.X, (int)rect.Y,
				(int)rect.Width, (int)rect.Height));
			Assert.AreEqual (r.GetRegionData ().Data,
				r1.GetRegionData ().Data);
		}
Beispiel #11
0
		public void ctor_RegionData () {
			RegionData rgnData = r.GetRegionData ();
			Region r1 = new Region (rgnData);
			Assert.AreEqual (rgnData.Data, r1.GetRegionData ().Data);
		}
Beispiel #12
0
        public void LoadData(string path)
        {
            Console.WriteLine("LoadData >>");
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.Load(path);
            XmlNodeList dataNodes = doc.GetElementsByTagName("data");
            if (dataNodes.Count > 0)
            {
                XmlNode dataNode = dataNodes[0];
                int x = 0;
                int y = 0;
                int w = 0;
                int h = 0;
                if (dataNode.Attributes["x"] != null && dataNode.Attributes["y"] != null)
                {
                    x = Int32.Parse(dataNode.Attributes["x"].Value);
                    y = Int32.Parse(dataNode.Attributes["y"].Value);
                }
                if (dataNode.Attributes["width"] != null && dataNode.Attributes["height"] != null)
                {
                    w = Int32.Parse(dataNode.Attributes["width"].Value);
                    h = Int32.Parse(dataNode.Attributes["height"].Value);
                }
                x = x < 0 ? 0 : x;
                x = (x + w) > Screen.PrimaryScreen.WorkingArea.Width ? Screen.PrimaryScreen.WorkingArea.Width - w : x;
                y = y < 0 ? 0 : y;
                y = (y + h) > Screen.PrimaryScreen.WorkingArea.Height ? Screen.PrimaryScreen.WorkingArea.Height - h : y;
                this.Location = new Point(x, y);
                this.Size = new Size(w, h);

                if (dataNode.Attributes["bgcolor"] != null)
                {
                    try
                    {
                        this.mBgColor = Color.FromArgb(Int32.Parse(dataNode.Attributes["bgcolor"].Value));
                    }
                    catch (Exception e)
                    {
                        this.mBgColor = Color.Wheat;
                    }
                }
            }
            XmlNodeList strokeNodes = doc.GetElementsByTagName("stroke");
            if (strokeNodes.Count > 0)
            {
                XmlNode strokeNode = strokeNodes[0];
                XmlCDataSection cdata_stroke = (XmlCDataSection)strokeNode.FirstChild;
                byte[] decoded = System.Convert.FromBase64String(cdata_stroke.Data);
                mInkPicture.Ink.Load(decoded);
                mInkPicture.Refresh();
            }

            XmlNodeList imageNodes = doc.GetElementsByTagName("image");
            foreach(XmlNode imageNode in imageNodes)
            {
                Bitmap bmp = null;
                Region rgn = null;
                Point loc = new Point();
                Point[] ptPolygon = null;
                loc.X = Int32.Parse(imageNode.Attributes["x"].Value);
                loc.Y = Int32.Parse(imageNode.Attributes["y"].Value);

                foreach(XmlNode node in imageNode.ChildNodes)
                {
                    if (node.Name == "region")
                    {
                        XmlCDataSection cdata_region = (XmlCDataSection)node.FirstChild;
                        byte[] decoded = System.Convert.FromBase64String(cdata_region.Data);
                        Region regionTmp = new Region();
                        System.Drawing.Drawing2D.RegionData region2Data = regionTmp.GetRegionData();
                        region2Data.Data = decoded;
                        rgn = new Region(region2Data);
                        regionTmp.Dispose();
                    }
                    else if (node.Name == "polygon")
                    {
                        string[] xdata = null;
                        string[] ydata = null;
                        foreach (XmlNode c in node.ChildNodes)
                        {
                            if(c.Name == "xdata")
                            {
                                xdata = c.InnerText.Split(',');
                            }
                            else if (c.Name == "ydata")
                            {
                                ydata = c.InnerText.Split(',');
                            }
                        }
                        if (xdata != null && ydata != null)
                        {
                            int count = xdata.Length;
                            ptPolygon = new Point[count];
                            for (int i = 0; i < count; i++)
                            {
                                int x = Convert.ToInt32(xdata[i]);
                                int y = Convert.ToInt32(ydata[i]);
                                ptPolygon[i] = new Point(x, y);
                            }
                        }
                    }
                    else if (node.Name == "bmpdata")
                    {
                        XmlCDataSection cdata_bmp = (XmlCDataSection)node.FirstChild;
                        byte[] decoded = System.Convert.FromBase64String(cdata_bmp.Data);
                        using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                        {
                            ms.Write(decoded, 0, decoded.Length);
                            Bitmap bmpTmp = (Bitmap)Bitmap.FromStream(ms, false, true);
                            // Color format of a bitmap loaded from stream is 32rgb,
                            // but default bitmap format is 32Argb
                            // it cause a problem when save this bitmap.
                            // so, create new bitmap and copy its color one by one
                            bmp = new Bitmap(bmpTmp.Width, bmpTmp.Height);
                            for (int x = 0; x < bmpTmp.Width; x++)
                            {
                                for (int y = 0; y < bmpTmp.Height; y++)
                                {
                                    Color c = bmpTmp.GetPixel(x, y);
                                    bmp.SetPixel(x, y, c);
                                }
                            }
                        }
                        /*
                        System.IO.FileStream fsw = System.IO.File.OpenWrite("temp.bmp");
                        int len = decoded.Length;
                        fsw.Write(decoded, 0, len);
                        fsw.Close();
                        System.IO.FileStream fsr = System.IO.File.OpenRead("temp.bmp");
                        bmpdt.bmp = (Bitmap)Image.FromStream(fsr);
                        fsr.Close();
                         */
                    }
                }
                BitmapPosData bmpdt = new BitmapPosData(bmp, rgn, loc, ptPolygon);
                mBgBitmaps.Add(bmpdt);
                DrawBmpToBg(bmpdt, mBmpBG);

            }
            Console.WriteLine("<< LoadData");
        }
Beispiel #13
0
        // Paints the selection.
        void PaintSelection( Region rgn )
        {
            if (null == rgn) return;

             Region rgnPaint = new Region( rgn.GetRegionData() );
             if (null != _rgnSelLast) {
            rgnPaint.Exclude(_rgnSelLast);
             }

             lock(_mapLock) {
            using (var g = picMap.CreateGraphics()) {
               Brush br = new SolidBrush(CR_SELECTION);
               g.FillRegion(br, rgnPaint);
            }
             }

             _rgnSelLast = new Region(rgn.GetRegionData());
        }