Наследование: GDIObject
Пример #1
0
 public RegionCombineType Combine(GDIRegion aRegion, GDIRegion bRegion, RegionCombineStyles combineStyle)
 {
     int retValue = GDI32.CombineRgn(DangerousGetHandle(), aRegion.DangerousGetHandle(), bRegion.DangerousGetHandle(), (int)combineStyle);
     
     RegionCombineType result = (RegionCombineType)retValue;
     return result;
 }
Пример #2
0
        public bool Equals(GDIRegion aRegion)
        {
            bool isEqual = GDI32.EqualRgn(DangerousGetHandle(), aRegion.DangerousGetHandle());

            return isEqual;
        }
Пример #3
0
        public GDIRegion Intersect(GDIRegion aRegion)
        {
            RegionCombineType retValue = (RegionCombineType)GDI32.CombineRgn(DangerousGetHandle(), DangerousGetHandle(), aRegion.DangerousGetHandle(), (int)RegionCombineStyles.AND);

            return this;
        }
Пример #4
0
        public GDIRegion Subtract(GDIRegion aRegion)
        {
            RegionCombineType retValue = (RegionCombineType)GDI32.CombineRgn(DangerousGetHandle(), DangerousGetHandle(), aRegion.DangerousGetHandle(), (int)RegionCombineStyles.Diff);

            return this;
        }
Пример #5
0
        public static GDIRegion CreateFromRectangles(RectangleI[] rects, Guid uniqueID)
        {
            // 1.  Create a header
            RGNDATAHEADER header = new RGNDATAHEADER();
            header.dwSize = Marshal.SizeOf(header);
            header.iType = 1;
            header.nCount = (uint)rects.Length;
            header.nRgnSize = (uint)Marshal.SizeOf(typeof(RECT)) * header.nCount;
            //header.rcBound = 

            // 2. Allocate memory to hold the header plus the data for the rectangles
            int dataLengthNeeded = (int)(header.dwSize + header.nRgnSize);
            IntPtr memoryPtr = Marshal.AllocCoTaskMem((int)dataLengthNeeded);
            UnmanagedPointer structPtr = new UnmanagedPointer(memoryPtr);

            // 4. Copy the Header into the memory buffer
            Marshal.StructureToPtr(header, structPtr, false);

            // 5. Increment the memory buffer pointer to write the rectangles
            structPtr = structPtr + header.dwSize;

            // The nRgnSize / nCount will tell us how many bytes per rectangle structure
            // and therefore how much to advance the pointer as we turn the buffer
            // into a set of rectangles using PtrToStructure.
            int structIncrement = (int)(header.nRgnSize / header.nCount);

            // 6. Write the rectangles
            for (int i = 0; i < header.nCount; i++)
            {
                RECT aRect = new RECT(rects[i].Left, rects[i].Top, rects[i].Width, rects[i].Height);
                Marshal.StructureToPtr(aRect, structPtr, false);

                // Increment the structure pointer to the next position
                structPtr = structPtr + structIncrement;
            }

            // 7. Create the region
            IntPtr regionHandle = GDI32.ExtCreateRegion(IntPtr.Zero, (uint)rects.Length, memoryPtr);
            GDIRegion newRegion = new GDIRegion(regionHandle, true, uniqueID);

            // 8. Free the memory
            Marshal.FreeCoTaskMem(memoryPtr);
        
            return newRegion;
        }
Пример #6
0
        public static GDIRegion CreateFromRectangle(int left, int top, int right, int bottom, Guid uniqueID)
        {
            RECT newRect = RECT.FromLTRB(left, top, right, bottom);
            IntPtr regionHandle = GDI32.CreateRectRgnIndirect(ref newRect);

            GDIRegion newRegion = new GDIRegion(regionHandle, true, uniqueID);

            return newRegion;
        }
Пример #7
0
        public static GDIRegion CreateFromPolygon(Point2I[] points, PolygonFillMode aMode, Guid uniqueID)
        {
            TOAPI.Types.POINT[] pts = new POINT[points.Length];
            for (int i = 0; i < pts.Length; i++)
            {
                pts[i].X = points[i].x;
                pts[i].Y = points[i].y;
            }

            IntPtr regionHandle = GDI32.CreatePolygonRgn(pts, pts.Length, (int)aMode);

            GDIRegion newRegion = new GDIRegion(regionHandle, true, uniqueID);

            return newRegion;
        }
Пример #8
0
        public static GDIRegion CreateFromPath(GPath aPath, Guid uniqueID)
        {
            // 1. Create a simple device context
            GDIContext deviceContext = GDIContext.CreateForDefaultDisplay();

            // 2. Replay the path into the context
            deviceContext.ReplayPath(aPath);

            // 3. Create a region from the replayed path
            IntPtr regionHandle = GDI32.PathToRegion(deviceContext);

            GDIRegion newRegion = new GDIRegion(regionHandle, true, uniqueID);

            return newRegion;
        }