Exemplo n.º 1
0
        /// <summary>
        /// Applies a new viewport rectangle.
        /// </summary>
        /// <param name="viewport">The viewport rectangle.</param>
        public static void PushViewport(RectangleI viewport)
        {
            var actualRect = viewport;

            if (actualRect.Width < 0)
            {
                actualRect.X    += viewport.Width;
                actualRect.Width = -viewport.Width;
            }

            if (actualRect.Height < 0)
            {
                actualRect.Y     += viewport.Height;
                actualRect.Height = -viewport.Height;
            }

            PushOrtho(viewport);

            viewport_stack.Push(actualRect);

            if (Viewport == actualRect)
            {
                return;
            }
            Viewport = actualRect;

            GL.Viewport(Viewport.Left, Viewport.Top, Viewport.Width, Viewport.Height);

            UpdateScissorToCurrentViewportAndOrtho();
        }
Exemplo n.º 2
0
        private void refreshScreens()
        {
            screenContainer.Remove(windowContainer);
            screenContainer.Clear();
            var bounds = new RectangleI();

            for (int i = 0;; i++)
            {
                var device = DisplayDevice.GetDisplay((DisplayIndex)i);
                if (device == null)
                {
                    break;
                }

                screenContainer.Add(createScreen(device, device.IsPrimary ? $"Screen {i} (Primary)" : $"Screen {i}"));
                bounds = RectangleI.Union(bounds, new RectangleI(device.Bounds.X, device.Bounds.Y, device.Width, device.Height));
            }

            screenContainer.Add(windowContainer);
            screenContainerOffset = bounds.Location;

            foreach (var box in screenContainer.Children)
            {
                box.Position -= bounds.Location;
            }

            screenContainer.Size = bounds.Size;
        }
Exemplo n.º 3
0
        public static SizeI GetAdjustedBoundingRectangleOffsetSize(this UIObject obj)
        {
            RectangleI boundingRectangle1 = obj.GetAdjustedBoundingRectangle();
            RectangleI boundingRectangle2 = obj.BoundingRectangle;

            return(new SizeI(boundingRectangle2.Width - boundingRectangle1.Width, boundingRectangle2.Height - boundingRectangle1.Height));
        }
        public TextureGLAtlas(int width, int height, bool manualMipmaps, All filteringMode = All.Linear, int padding = 0)
            : base(width, height, manualMipmaps, filteringMode)
        {
            this.padding = padding;

            atlasBounds = new RectangleI(0, 0, Width, Height);
        }
        internal override void SetData(ITextureUpload upload, WrapMode wrapModeS, WrapMode wrapModeT, Opacity?uploadOpacity)
        {
            // Can only perform padding when the bounds are a sub-part of the texture
            RectangleI middleBounds = upload.Bounds;

            if (middleBounds.IsEmpty || middleBounds.Width * middleBounds.Height > upload.Data.Length)
            {
                // For a texture atlas, we don't care about opacity, so we avoid
                // any computations related to it by assuming it to be mixed.
                base.SetData(upload, wrapModeS, wrapModeT, Opacity.Mixed);
                return;
            }

            int actualPadding = padding / (1 << upload.Level);

            if (wrapModeS != WrapMode.None && wrapModeT != WrapMode.None)
            {
                uploadCornerPadding(upload, middleBounds, actualPadding);
            }

            if (wrapModeS != WrapMode.None)
            {
                uploadHorizontalPadding(upload, middleBounds, actualPadding);
            }

            if (wrapModeT != WrapMode.None)
            {
                uploadVerticalPadding(upload, middleBounds, actualPadding);
            }

            // Upload the middle part of the texture
            // For a texture atlas, we don't care about opacity, so we avoid
            // any computations related to it by assuming it to be mixed.
            base.SetData(upload, wrapModeS, wrapModeT, Opacity.Mixed);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 点是否在区域内
        /// </summary>
        /// <param name="Rect">矩形区域</param>
        /// <param name="P">点P</param>
        /// <returns>
        /// 返回True表示点P在区域内,返回False则不在区域内.
        /// </returns>
        public static Boolean InRectangle(RectangleI Rect, PointI P)
        {
            MinMax <Int32> MX = new MinMax <Int32>(Rect.Left, Rect.Right);
            MinMax <Int32> MY = new MinMax <Int32>(Rect.Top, Rect.Bottom);

            return(MX.InRange(P.X) && MY.InRange(P.Y));
        }
Exemplo n.º 7
0
        public override void ProcessPixels(RectangleI region)
        {
            ComplexGrid gridDirect  = new ComplexGrid(ImageBounds, ProjectionBounds, fDir);
            ComplexGrid gridInverse = new ComplexGrid(ImageBounds, ProjectionBounds, fInv);

            Parallel.For(region.TopLeft.Y, region.BottomRight.Y, y =>
            {
                Parallel.For(region.TopLeft.X, region.BottomRight.X, x =>
                {
                    var pDir = (PointI)lerpPoint(new PointD(x, y), gridDirect[x, y], Alpha);
                    var pInv = (PointI)lerpPoint(new PointD(x, y), gridInverse[x, y], Alpha);
                    SKColor color;
                    if (IsPointInRange(pDir, ImageBounds))
                    {
                        color = SourceImage.GetPixel(pDir.X, pDir.Y);
                    }
                    else if (IsPointInRange(pInv, ImageBounds))
                    {
                        color = SourceImage.GetPixel(pInv.X, pInv.Y);
                    }
                    else
                    {
                        color = SKColor.Empty;
                    }
                    DestImage.SetPixel(x, y, color);
                });
            });
        }
Exemplo n.º 8
0
        public static RectangleI GetAdjustedBoundingRectangle(this UIObject obj)
        {
            RectangleI rectangleI = obj.BoundingRectangle;

            if (obj != UIObject.Root)
            {
                IntPtr nativeWindowHandle = obj.NativeWindowHandle;
                if (nativeWindowHandle != IntPtr.Zero)
                {
                    RECT extendedFrameBoundsRect = new RECT();
                    int  dwmRectangle            = GetDwmRectangle(nativeWindowHandle, ref extendedFrameBoundsRect);
                    switch (dwmRectangle)
                    {
                    case -2147024890:
                        break;

                    case 0:
                        rectangleI = new RectangleI(extendedFrameBoundsRect.Left, extendedFrameBoundsRect.Top, extendedFrameBoundsRect.Right - extendedFrameBoundsRect.Left, extendedFrameBoundsRect.Bottom - extendedFrameBoundsRect.Top);
                        break;

                    default:
                        throw new ExternalException("DwmGetWindowAttribute failed.", dwmRectangle);
                    }
                }
            }

            return(rectangleI);
        }
Exemplo n.º 9
0
        public static PointI GetAdjustedBoundingRectangleOffsetPosition(this UIObject obj)
        {
            RectangleI boundingRectangle1 = obj.GetAdjustedBoundingRectangle();
            RectangleI boundingRectangle2 = obj.BoundingRectangle;

            return(new PointI(boundingRectangle2.Left - boundingRectangle1.Left, boundingRectangle2.Top - boundingRectangle1.Top));
        }
Exemplo n.º 10
0
        internal TextureGL Add(int width, int height)
        {
            if (width > atlasWidth)
            {
                throw new ArgumentOutOfRangeException(nameof(width), width, $"Must be less than this atlas' width ({atlasWidth}px).");
            }

            if (height > atlasHeight)
            {
                throw new ArgumentOutOfRangeException(nameof(height), height, $"Must be less than this atlas' height ({atlasHeight}px).");
            }

            lock (textureRetrievalLock)
            {
                if (AtlasTexture == null)
                {
                    Reset();
                }

                Vector2I   position = findPosition(width, height);
                RectangleI bounds   = new RectangleI(position.X, position.Y, width, height);
                subTextureBounds.Add(bounds);

                return(new TextureGLSub(bounds, AtlasTexture));
            }
        }
        private InvokeOnDisposal establishFrameBufferViewport(Vector2 roundedSize)
        {
            // Disable masking for generating the frame buffer since masking will be re-applied
            // when actually drawing later on anyways. This allows more information to be captured
            // in the frame buffer and helps with cached buffers being re-used.
            RectangleI screenSpaceMaskingRect = new RectangleI((int)Math.Floor(ScreenSpaceDrawRectangle.X), (int)Math.Floor(ScreenSpaceDrawRectangle.Y), (int)roundedSize.X + 1, (int)roundedSize.Y + 1);

            GLWrapper.PushMaskingInfo(new MaskingInfo
            {
                ScreenSpaceAABB = screenSpaceMaskingRect,
                MaskingRect     = ScreenSpaceDrawRectangle,
                ToMaskingSpace  = Matrix3.Identity,
                BlendRange      = 1,
                AlphaExponent   = 1,
            }, true);

            // Match viewport to FrameBuffer such that we don't draw unnecessary pixels.
            GLWrapper.PushViewport(new RectangleI(0, 0, (int)roundedSize.X, (int)roundedSize.Y));

            return(new InvokeOnDisposal(delegate
            {
                GLWrapper.PopViewport();
                GLWrapper.PopMaskingInfo();
            }));
        }
Exemplo n.º 12
0
            protected void UpdateCursorTransitionOnScreenBorder()
            {
                System.Drawing.Point p        = Cursor.Position;
                Vector2I             position = new Vector2I(p.X, p.Y);

                System.Drawing.Rectangle r = cursorTransitionOnScreenBorderScreen.Bounds;
                RectangleI rectangle       = new RectangleI(r.Left, r.Top, r.Right, r.Bottom);

                if (position.X < rectangle.Left + 3)
                {
                    Cursor.Position = new System.Drawing.Point(rectangle.Right - 6, position.Y);
                    cursorTransitionOnScreenBorderOffset -= new Vector2(rectangle.Size.X, 0);
                }
                if (position.X > rectangle.Right - 3)
                {
                    Cursor.Position = new System.Drawing.Point(rectangle.Left + 6, position.Y);
                    cursorTransitionOnScreenBorderOffset += new Vector2(rectangle.Size.X, 0);
                }
                if (position.Y < rectangle.Top + 3)
                {
                    Cursor.Position = new System.Drawing.Point(position.X, rectangle.Bottom - 6);
                    cursorTransitionOnScreenBorderOffset -= new Vector2(0, rectangle.Size.Y);
                }
                if (position.Y > rectangle.Bottom - 3)
                {
                    Cursor.Position = new System.Drawing.Point(position.X, rectangle.Top + 6);
                    cursorTransitionOnScreenBorderOffset += new Vector2(0, rectangle.Size.Y);
                }
            }
Exemplo n.º 13
0
        static ImageHelpers.IWICBitmap GetImageMobile(RectangleI rectangle)
        {
            var deviceFamily = AnalyticsInfo.VersionInfo.DeviceFamily;

            if (!deviceFamily.Equals(value: "Windows.Mobile", comparisonType: StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidOperationException(message: string.Format(format: "GetImageMobile not supported on your platform: {0}", arg0: deviceFamily));
            }
            if (rectangle.Width <= 0)
            {
                throw new ArgumentOutOfRangeException(paramName: "width", actualValue: rectangle.Width, message: StringResource.Get(id: "RectangleMustBeNonEmpty"));
            }
            if (rectangle.Height <= 0)
            {
                throw new ArgumentOutOfRangeException(paramName: "height", actualValue: rectangle.Height, message: StringResource.Get(id: "RectangleMustBeNonEmpty"));
            }
            var bitmap = ImageHelpers.CaptureMobileScreenshot();

            if (bitmap == null)
            {
                throw new ScreenCaptureException(message: "CaptureMobileScreenshot failed to capture screen. Returned bitmap is null.");
            }
            uint puiWidth  = 0;
            uint puiHeight = 0;

            bitmap.GetSize(puiWidth: out puiWidth, puiHeight: out puiHeight);
            if (rectangle.Width == puiWidth && rectangle.Height == puiHeight)
            {
                return(bitmap);
            }
            Log.Out(msg: "Requested capture area is different than screen size:");
            Log.Out(msg: "    Requested: Width: {0} Height: {1} Left: {2} Top {3}", (object)rectangle.Width, (object)rectangle.Height, (object)rectangle.Left, (object)rectangle.Top);
            Log.Out(msg: "    Screen: Width: {0} Height: {1}", (object)puiWidth, (object)puiHeight);
            return(ClipImage(bitmap: bitmap, rectangle: rectangle));
        }
Exemplo n.º 14
0
        private void DrawPrinterPreview(Context context, int i, RectangleI currentPage)
        {
            if (i + StartPage >= document.PageContexts.Count)
            {
                return;
            }

            var page = document.PageContexts [i + StartPage];
            int left = document.FormArea.X;
            int top  = document.FormArea.Y;

            Surface cache;

            if (!pageCache.TryGetValue(i + startPage, out cache))
            {
                cache = zoom < 0.5 ?
                        page.Target.ScaleSmooth(document.FormArea.Width, document.FormArea.Height, zoom, zoom) :
                        page.Target.ScaleFast(document.FormArea.Width, document.FormArea.Height, zoom, zoom);

                pageCache [i + startPage] = cache;
            }

            context.SetSourceSurface(cache,
                                     (int)Math.Round(currentPage.X + left * zoom),
                                     (int)Math.Round(currentPage.Y + top * zoom));
            context.Paint();
        }
Exemplo n.º 15
0
 //----------------------------------------------------------clipping_flags
 // Determine the clipping code of the vertex according to the 
 // Cyrus-Beck line clipping algorithm
 //
 //        |        |
 //  0110  |  0010  | 0011
 //        |        |
 // -------+--------+-------- clip_box.y2
 //        |        |
 //  0100  |  0000  | 0001
 //        |        |
 // -------+--------+-------- clip_box.y1
 //        |        |
 //  1100  |  1000  | 1001
 //        |        |
 //  clip_box.x1  clip_box.x2
 //
 // 
 //template<class T>
 public static int clipping_flags(int x, int y, RectangleI clip_box)
 {
     return ((x > clip_box.x2) ? 1 : 0)
         | ((y > clip_box.y2) ? 1 << 1 : 0)
         | ((x < clip_box.x1) ? 1 << 2 : 0)
         | ((y < clip_box.y1) ? 1 << 3 : 0);
 }
Exemplo n.º 16
0
        public override Bitmap Bitmap(TextureAttachment textureAttachment, RectangleI rectangle)
        {
            if (textureAttachment == TextureAttachment.Depth || textureAttachment == TextureAttachment.DepthStencil)
            {
                throw new CKGLException("Cannot read pixels of the Depth(Stecil) attachment.");
            }
            if (rectangle.X < 0 || rectangle.Y < 0 || rectangle.X + rectangle.W > Width || rectangle.Y + rectangle.H > Height)
            {
                throw new CKGLException("Rectangle outside of Framebuffer bounds.");
            }

            Framebuffer originalFramebuffer = Current;

            Bind();

            if (IsDefault)
            {
                if (textureAttachment == TextureAttachment.Depth || textureAttachment == TextureAttachment.DepthStencil)
                {
                    throw new IllegalValueException(typeof(TextureAttachment), textureAttachment);
                }
                GL.ReadBuffer(ReadBuffer.Back);
            }
            else
            {
                GL.ReadBuffer((ReadBuffer)textureAttachment.ToOpenGL());
            }

            Bitmap bitmap = new Bitmap(GL.ReadPixelsAsColourArray(rectangle, PixelFormat.RGBA), rectangle.W, rectangle.H);

            originalFramebuffer.Bind();

            return(bitmap);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Get the estimated bounding box of a text rendering.
        /// </summary>
        /// <param name="font">Font to use.</param>
        /// <param name="text">Text to draw.</param>
        /// <param name="position">Text position.</param>
        /// <param name="fontSize">Font size.</param>
        /// <param name="maxWidth">Max line width.</param>
        /// <param name="origin">Text origin.</param>
        /// <param name="rotation">Text rotation.</param>
        /// <returns>Estimated text drawing bounding box.</returns>
        public RectangleI GetTextBoundingBox(FontAsset font, string text, PointF position, int fontSize, int maxWidth, PointF origin, float rotation)
        {
            RectangleI ret = new RectangleI();

            _BonEngineBind.BON_Gfx_GetTextBoundingBox(font._handle, text, position.X, position.Y, fontSize, maxWidth, origin.X, origin.Y, rotation, ref ret.X, ref ret.Y, ref ret.Width, ref ret.Height);
            return(ret);
        }
Exemplo n.º 18
0
        private static void setMaskingInfo(MaskingInfo maskingInfo, bool isPushing, bool overwritePreviousScissor)
        {
            FlushCurrentBatch();

            GlobalPropertyManager.Set(GlobalProperty.MaskingRect, new Vector4(
                                          maskingInfo.MaskingRect.Left,
                                          maskingInfo.MaskingRect.Top,
                                          maskingInfo.MaskingRect.Right,
                                          maskingInfo.MaskingRect.Bottom));

            GlobalPropertyManager.Set(GlobalProperty.ToMaskingSpace, maskingInfo.ToMaskingSpace);
            GlobalPropertyManager.Set(GlobalProperty.CornerRadius, maskingInfo.CornerRadius);

            GlobalPropertyManager.Set(GlobalProperty.BorderThickness, maskingInfo.BorderThickness / maskingInfo.BlendRange);
            if (maskingInfo.BorderThickness > 0)
            {
                GlobalPropertyManager.Set(GlobalProperty.BorderColour, new Vector4(
                                              maskingInfo.BorderColour.Linear.R,
                                              maskingInfo.BorderColour.Linear.G,
                                              maskingInfo.BorderColour.Linear.B,
                                              maskingInfo.BorderColour.Linear.A));
            }

            GlobalPropertyManager.Set(GlobalProperty.MaskingBlendRange, maskingInfo.BlendRange);
            GlobalPropertyManager.Set(GlobalProperty.AlphaExponent, maskingInfo.AlphaExponent);

            GlobalPropertyManager.Set(GlobalProperty.EdgeOffset, maskingInfo.EdgeOffset);

            GlobalPropertyManager.Set(GlobalProperty.DiscardInner, maskingInfo.Hollow);

            RectangleI actualRect = maskingInfo.ScreenSpaceAABB;

            actualRect.X += Viewport.X;
            actualRect.Y += Viewport.Y;

            // Ensure the rectangle only has positive width and height. (Required by OGL)
            if (actualRect.Width < 0)
            {
                actualRect.X    += actualRect.Width;
                actualRect.Width = -actualRect.Width;
            }

            if (actualRect.Height < 0)
            {
                actualRect.Y     += actualRect.Height;
                actualRect.Height = -actualRect.Height;
            }

            if (isPushing)
            {
                scissor_rect_stack.Push(overwritePreviousScissor ? actualRect : RectangleI.Intersect(scissor_rect_stack.Peek(), actualRect));
            }
            else
            {
                Trace.Assert(scissor_rect_stack.Count > 1);
                scissor_rect_stack.Pop();
            }

            UpdateScissorToCurrentViewportAndOrtho();
        }
Exemplo n.º 19
0
        public static PointI GetWindowTopLeft(this RectangleI rect, IntPtr nativeWindowHandle)
        {
            int xClient;
            int yClient;

            ConvertScreenToClient(nativeWindowHandle, rect.Left, rect.Top, out xClient, out yClient);
            return(new PointI(xClient, yClient));
        }
Exemplo n.º 20
0
 public static SDL.SDL_Rect ToSDLRect(this RectangleI rectangle) =>
 new SDL.SDL_Rect
 {
     x = rectangle.X,
     y = rectangle.Y,
     h = rectangle.Height,
     w = rectangle.Width,
 };
Exemplo n.º 21
0
 //--------------------------------------------------------------------
 public VectorClipper_DoClip()
 {
     m_clip_box = new RectangleI(0, 0, 0, 0);
     m_x1 = (0);
     m_y1 = (0);
     m_f1 = (0);
     m_clipping = (false);
 }
Exemplo n.º 22
0
        private static void setMaskingInfo(MaskingInfo maskingInfo, bool isPushing, bool overwritePreviousScissor)
        {
            FlushCurrentBatch();

            GlobalPropertyManager.Set(GlobalProperty.MaskingRect, new Vector4(
                                          maskingInfo.MaskingRect.Left,
                                          maskingInfo.MaskingRect.Top,
                                          maskingInfo.MaskingRect.Right,
                                          maskingInfo.MaskingRect.Bottom));

            GlobalPropertyManager.Set(GlobalProperty.ToMaskingSpace, maskingInfo.ToMaskingSpace);

            GlobalPropertyManager.Set(GlobalProperty.CornerRadius, maskingInfo.CornerRadius);
            GlobalPropertyManager.Set(GlobalProperty.CornerExponent, maskingInfo.CornerExponent);

            GlobalPropertyManager.Set(GlobalProperty.BorderThickness, maskingInfo.BorderThickness / maskingInfo.BlendRange);

            if (maskingInfo.BorderThickness > 0)
            {
                GlobalPropertyManager.Set(GlobalProperty.BorderColour, new Vector4(
                                              maskingInfo.BorderColour.Linear.R,
                                              maskingInfo.BorderColour.Linear.G,
                                              maskingInfo.BorderColour.Linear.B,
                                              maskingInfo.BorderColour.Linear.A));
            }

            GlobalPropertyManager.Set(GlobalProperty.MaskingBlendRange, maskingInfo.BlendRange);
            GlobalPropertyManager.Set(GlobalProperty.AlphaExponent, maskingInfo.AlphaExponent);

            GlobalPropertyManager.Set(GlobalProperty.EdgeOffset, maskingInfo.EdgeOffset);

            GlobalPropertyManager.Set(GlobalProperty.DiscardInner, maskingInfo.Hollow);
            if (maskingInfo.Hollow)
            {
                GlobalPropertyManager.Set(GlobalProperty.InnerCornerRadius, maskingInfo.HollowCornerRadius);
            }

            if (isPushing)
            {
                // When drawing to a viewport that doesn't match the projection size (e.g. via framebuffers), the resultant image will be scaled
                Vector2 viewportScale = Vector2.Divide(Viewport.Size, Ortho.Size);

                Vector2 location = (maskingInfo.ScreenSpaceAABB.Location - ScissorOffset) * viewportScale;
                Vector2 size     = maskingInfo.ScreenSpaceAABB.Size * viewportScale;

                RectangleI actualRect = new RectangleI(
                    (int)Math.Floor(location.X),
                    (int)Math.Floor(location.Y),
                    (int)Math.Ceiling(size.X),
                    (int)Math.Ceiling(size.Y));

                PushScissor(overwritePreviousScissor ? actualRect : RectangleI.Intersect(scissor_rect_stack.Peek(), actualRect));
            }
            else
            {
                PopScissor();
            }
        }
Exemplo n.º 23
0
        public void TestRectangleICenter()
        {
            // ARRANGE.
            var rectangle = new RectangleI(new Vector2I(2, 3), new Vector2I(6, 8));
            var center = new Vector2I(5, 7);

            // ASSERT.
            Assert.AreEqual(center, rectangle.Center);
        }
Exemplo n.º 24
0
        public void TestRectangleICenter()
        {
            // ARRANGE.
            var rectangle = new RectangleI(new Vector2I(2, 3), new Vector2I(6, 8));
            var center    = new Vector2I(5, 7);

            // ASSERT.
            Assert.AreEqual(center, rectangle.Center);
        }
Exemplo n.º 25
0
 public GuiView(Shader shader, int width, int height, LayoutMode layout) : base(width, height, layout)
 {
     rect     = new RectangleI(width, height);
     FlexX    = FlexY = false;
     View     = this;
     Texture  = new Texture2D(width, height, TextureFormat.RGBA);
     target   = new RenderTarget(Texture);
     material = new Material(shader);
 }
Exemplo n.º 26
0
    public static int Main()
    {
        int iRetVal = 100;
        
        var rF = new RectangleF(1.2f, 3.4f, 5.6f, 7.8f);
        var rD = new RectangleD(1.7E+3d, 4.5d, 500.1d, 60.0d);
        var rI = new RectangleI(100, -2, 3, 64);
        var rLSmall = new RectangleLSmall(11231L);
        var rLLarge = new RectangleLLarge(1L, 20041L, 22L, 88L);
        var rNestedFSmall = new RectangleNestedF(1.2f, 3.4f, 5.6f, 7.8f);

        typeof(Test7685).GetTypeInfo().GetDeclaredMethod("DoStuffF").Invoke(null, new object[] { rF });
        typeof(Test7685).GetTypeInfo().GetDeclaredMethod("DoStuffD").Invoke(null, new object[] { rD });
        typeof(Test7685).GetTypeInfo().GetDeclaredMethod("DoStuffI").Invoke(null, new object[] { rI });
        typeof(Test7685).GetTypeInfo().GetDeclaredMethod("DoStuffLSmall").Invoke(null, new object[] { rLSmall });
        typeof(Test7685).GetTypeInfo().GetDeclaredMethod("DoStuffLLarge").Invoke(null, new object[] { rLLarge });
        typeof(Test7685).GetTypeInfo().GetDeclaredMethod("DoStuffNestedF").Invoke(null, new object[] { rNestedFSmall });

        if (!RectangleF.Equals(ref passedFloatStruct, ref rF))
        {
            TestLibrary.Logging.WriteLine($"Error: passing struct with floats via reflection. Callee received {passedFloatStruct} instead of {rF}");
            iRetVal = 0;
        }

        if (!RectangleD.Equals(ref passedDoubleStruct, ref rD))
        {
            TestLibrary.Logging.WriteLine($"Error: passing struct with doubles via reflection. Callee received {passedDoubleStruct} instead of {rD}");
            iRetVal = 1;
        }

        if (!RectangleI.Equals(ref passedIntStruct, ref rI))
        {
            TestLibrary.Logging.WriteLine($"Error: passing struct with ints via reflection. Callee received {passedIntStruct} instead of {rI}");
            iRetVal = 2;
        }

        if (!RectangleLSmall.Equals(ref passedLongSmallStruct, ref rLSmall))
        {
            TestLibrary.Logging.WriteLine($"Error: passing struct with a long via reflection. Callee received {passedLongSmallStruct} instead of {rLSmall}");
            iRetVal = 3;
        }

        if (!RectangleLLarge.Equals(ref passedLongLargeStruct, ref rLLarge))
        {
            TestLibrary.Logging.WriteLine($"Error: passing struct with longs via reflection. Callee received {passedLongLargeStruct} instead of {rLLarge}");
            iRetVal = 4;
        }

        if (!RectangleNestedF.Equals(ref passedNestedSmallFStruct, ref rNestedFSmall))
        {
            TestLibrary.Logging.WriteLine($"Error: passing struct with longs via reflection. Callee received {passedNestedSmallFStruct} instead of {rNestedFSmall}");
            iRetVal = 5;
        }
        
        return iRetVal;
    }
Exemplo n.º 27
0
        /// <summary>
        /// Get RectangleI from config.
        /// </summary>
        /// <param name="section">Section to get value from.</param>
        /// <param name="key">Key to get.</param>
        /// <param name="defaultVal">Default value to return if not found.</param>
        /// <returns>Value from config, or defaultVal if not found.</returns>
        public RectangleI GetRectangleI(string section, string key, RectangleI defaultVal)
        {
            var asStr = GetStr(section, key, null);

            if (asStr == null)
            {
                return(defaultVal);
            }
            return(RectangleI.FromString(asStr.Trim()));
        }
Exemplo n.º 28
0
        /// <summary>
        /// Get the estimated bounding box of a text rendering.
        /// </summary>
        /// <param name="font">Font to use.</param>
        /// <param name="text">Text to draw.</param>
        /// <param name="position">Text position.</param>
        /// <param name="fontSize">Font size.</param>
        /// <param name="maxWidth">Max line width.</param>
        /// <param name="origin">Text origin.</param>
        /// <param name="rotation">Text rotation.</param>
        /// <returns>Estimated text drawing bounding box.</returns>
        public RectangleI GetTextBoundingBox(FontAsset font, string text, PointF position, int fontSize, int maxWidth, PointF origin, float rotation)
        {
            if (!font.HaveHandle)
            {
                throw new Exception("Tried to render a font without handle!");
            }
            RectangleI ret = new RectangleI();

            _BonEngineBind.BON_Gfx_GetTextBoundingBox(font._handle, text, position.X, position.Y, fontSize, maxWidth, origin.X, origin.Y, rotation, ref ret.X, ref ret.Y, ref ret.Width, ref ret.Height);
            return(ret);
        }
Exemplo n.º 29
0
 /// <summary>
 /// 判断矩形R是否在多边形内
 /// </summary>
 /// <param name="PG">PG多边形</param>
 /// <param name="R">R矩形</param>
 /// <returns>如果R矩形在区域内返回True,否则返回False.</returns>
 public static Boolean InPolygon(PolygonI PG, RectangleI R)
 {
     foreach (LineD L in R)
     {
         if (InPolygon(PG, L) == false)
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 30
0
        private void uploadHorizontalPadding(ReadOnlySpan <Rgba32> upload, RectangleI middleBounds, int actualPadding, bool fillOpaque)
        {
            RectangleI[] sideBoundsArray =
            {
                new RectangleI(middleBounds.X - actualPadding,      middleBounds.Y, actualPadding, middleBounds.Height).Intersect(atlasBounds), // Left
                new RectangleI(middleBounds.X + middleBounds.Width, middleBounds.Y, actualPadding, middleBounds.Height).Intersect(atlasBounds), // Right
            };

            int[] sideIndices =
            {
                0,                      // Left
                middleBounds.Width - 1, // Right
            };

            for (int i = 0; i < 2; ++i)
            {
                RectangleI sideBounds = sideBoundsArray[i];

                if (!sideBounds.IsEmpty)
                {
                    bool allTransparent = true;
                    int  index          = sideIndices[i];

                    var sideUpload = new MemoryAllocatorTextureUpload(sideBounds.Width, sideBounds.Height)
                    {
                        Bounds = sideBounds
                    };
                    var data = sideUpload.RawData;

                    int stride = middleBounds.Width;

                    for (int y = 0; y < sideBounds.Height; ++y)
                    {
                        for (int x = 0; x < sideBounds.Width; ++x)
                        {
                            Rgba32 pixel = upload[index + y * stride];

                            allTransparent &= checkEdgeRGB(pixel);

                            transferBorderPixel(ref data[y * sideBounds.Width + x], pixel, fillOpaque);
                        }
                    }

                    // Only upload padding if the border isn't completely transparent.
                    if (!allTransparent)
                    {
                        // For a texture atlas, we don't care about opacity, so we avoid
                        // any computations related to it by assuming it to be mixed.
                        base.SetData(sideUpload, WrapMode.None, WrapMode.None, Opacity.Mixed);
                    }
                }
            }
        }
Exemplo n.º 31
0
 /// <summary>
 /// 判断折线PL是否在圆内
 /// </summary>
 /// <param name="C">圆C</param>
 /// <param name="R">矩形R</param>
 /// <returns>如果在圆内返回True,否则返回False。</returns>
 public static Boolean InCircle(CircleI C, RectangleI R)
 {
     if (PointAlgorithm.Distance(new PointI(R.Left, R.Top), C.Center) > C.Radius)
     {
         return(false);
     }
     if (PointAlgorithm.Distance(new PointI(R.Right, R.Bottom), C.Center) > C.Radius)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 32
0
        public RectangleG(int x, int y, int width, int height)
        {
            fRectangle = new RectangleI(x, y, width, height);

            Begin();
            MoveTo(x, y, false);
            LineTo(x, y + height, false);
            LineTo(x + width, y + height, false);
            LineTo(x + width, y, false);
            LineTo(x, y, true);
            End();
        }
Exemplo n.º 33
0
        public TextureGLSub(RectangleI bounds, TextureGLSingle parent)
        {
            // If GLWrapper is not initialized at this point, it means we do not have OpenGL available
            // and thus will never draw anything. In this case it is fine if the parent texture is null.
            if (GLWrapper.IsInitialized && parent == null)
            {
                throw new InvalidOperationException("May not construct a subtexture without a parent texture to refer to.");
            }

            this.bounds = bounds;
            this.parent = parent;
        }
Exemplo n.º 34
0
        /// <summary>
        /// Applies a new scissor rectangle.
        /// </summary>
        /// <param name="scissor">The scissor rectangle.</param>
        public static void PushScissor(RectangleI scissor)
        {
            FlushCurrentBatch();

            scissor_rect_stack.Push(scissor);
            if (Scissor == scissor)
            {
                return;
            }

            Scissor = scissor;
            setScissor(scissor);
        }
Exemplo n.º 35
0
		public Graphic(String name, int x, int y, int width, int height)
		{
            fName = name;

            fOrigin = new Point3D(0, 0);
            fDimension = new Vector3D(width, height);

            fFrame = new RectangleI(x, y, width, height);

            //fGraphicsUnit = GraphicsUnit.Display;
			fVisible = true;
            fActive = true;
            fEnabled = false;
        }
Exemplo n.º 36
0
        //public IPixelFormat ren() { return m_ren; }

        public bool SetClippingBox(int x1, int y1, int x2, int y2)
        {
            RectangleI cb = new RectangleI(x1, y1, x2, y2);
            if (cb.Clip(new RectangleI(0, 0, (int)Width() - 1, (int)Height() - 1)))
            {
                m_clip_box = cb;
                return true;
            }
            m_clip_box.x1 = 1;
            m_clip_box.y1 = 1;
            m_clip_box.x2 = 0;
            m_clip_box.y2 = 0;

            return false;
        }
Exemplo n.º 37
0
        public RectangleI clip_rect_area(ref RectangleI dst, ref RectangleI src, int wsrc, int hsrc)
        {
            RectangleI rc = new RectangleI(0, 0, 0, 0);
            RectangleI cb = clip_box();
            ++cb.x2;
            ++cb.y2;

            if (src.x1 < 0)
            {
                dst.x1 -= src.x1;
                src.x1 = 0;
            }
            if (src.y1 < 0)
            {
                dst.y1 -= src.y1;
                src.y1 = 0;
            }

            if (src.x2 > wsrc) src.x2 = wsrc;
            if (src.y2 > hsrc) src.y2 = hsrc;

            if (dst.x1 < cb.x1)
            {
                src.x1 += cb.x1 - dst.x1;
                dst.x1 = cb.x1;
            }
            if (dst.y1 < cb.y1)
            {
                src.y1 += cb.y1 - dst.y1;
                dst.y1 = cb.y1;
            }

            if (dst.x2 > cb.x2) dst.x2 = cb.x2;
            if (dst.y2 > cb.y2) dst.y2 = cb.y2;

            rc.x2 = dst.x2 - dst.x1;
            rc.y2 = dst.y2 - dst.y1;

            if (rc.x2 > src.x2 - src.x1) rc.x2 = src.x2 - src.x1;
            if (rc.y2 > src.y2 - src.y1) rc.y2 = src.y2 - src.y1;
            return rc;
        }
Exemplo n.º 38
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;
        }
Exemplo n.º 39
0
        public static bool clip_move_point(int x1, int y1, int x2, int y2,
                             RectangleI clip_box,
                             ref int x, ref int y, int flags)
        {
            int bound;

            if ((flags & (int)clipping_flags_e.clipping_flags_x_clipped) != 0)
            {
                if (x1 == x2)
                {
                    return false;
                }
                bound = ((flags & (int)clipping_flags_e.clipping_flags_x1_clipped) != 0) ? clip_box.x1 : clip_box.x2;
                y = (int)((double)(bound - x1) * (y2 - y1) / (x2 - x1) + y1);
                x = bound;
            }

            flags = clipping_flags_y(y, clip_box);
            if ((flags & (int)clipping_flags_e.clipping_flags_y_clipped) != 0)
            {
                if (y1 == y2)
                {
                    return false;
                }
                bound = ((flags & (int)clipping_flags_e.clipping_flags_x1_clipped) != 0) ? clip_box.y1 : clip_box.y2;
                x = (int)((double)(bound - y1) * (x2 - x1) / (y2 - y1) + x1);
                y = bound;
            }
            return true;
        }
Exemplo n.º 40
0
 // By default, debugging will just draw a red rectangle around the frame
 protected virtual void OnDebug(DrawEvent devent)
 {
     RectangleI aRect = new RectangleI((int)Origin.x, (int)Origin.y, (int)Dimension.x, (int)Dimension.y);
     devent.GraphPort.DrawRectangle(GDICosmeticPen.Red, aRect);
 }
Exemplo n.º 41
0
        /// <summary>
        /// Whenever a frame is received from the camera, this routine is called.
        /// </summary>
        /// <param name="sender">the object that hosts the callback routine for the received frame.</param>
        /// <param name="camEvent">Event containing video frame information</param>
        void OnFrameReceived(object sender, CameraEventArgs camEvent)
        {

            RectangleI srcRect = new RectangleI(0, 0, camEvent.Width, camEvent.Height);
            RectangleI dstRect = srcRect;


            if (fUseScaling)
            {
                dstRect = this.ClientRectangle;
            }

            DeviceContextClientArea.PixelBlt(srcRect, dstRect, camEvent.fData, BitCount.Bits24);
        }
Exemplo n.º 42
0
 public override void LinkToImage(IImage ren)
 {
     base.LinkToImage(ren);
     m_clip_box = new RectangleI(0, 0, (int)ren.Width() - 1, (int)ren.Height() - 1);
 }
Exemplo n.º 43
0
        public virtual void ResizeBy(int dw, int dh)
        {
            fFrame = new RectangleI(new Point2I(fFrame.Left, fFrame.Top), 
                new Size2I(Frame.Width+dw, Frame.Height+dh));
            fDimension.x = fFrame.Width;
            fDimension.y = fFrame.Height;

            UpdateGeometryState();
        }
Exemplo n.º 44
0
        public virtual void ResizeTo(int width, int height)
        {
            fFrame = new RectangleI(new Point2I(fFrame.Left, fFrame.Top), new Size2I(width, height));
            fDimension.x = width;
            fDimension.y = height;

            UpdateGeometryState();
        }
Exemplo n.º 45
0
        public virtual void OnGraphicAdded(IGraphic aGraphic)
        {
            // Layout the graphic again
            LayoutHandler.AddToLayout(aGraphic);

            if (AutoGrow)
            {
                // Make sure our frame expands appropriately
                RectangleI frame = Frame;

                Point2I gOrigin = new Point2I(frame.Left + aGraphic.Frame.Left, frame.Top + aGraphic.Frame.Top);
                //float3 iPoint = WorldTransform.ApplyInverse(new float3(gOrigin.X, gOrigin.Y, 0));
                //Point tOrigin = new Point((int)iPoint.x, (int)iPoint.y);
                RectangleI tRect = new RectangleI((int)gOrigin.x, (int)gOrigin.y, (int)aGraphic.Dimension.x, (int)aGraphic.Dimension.y);

                // WAA - need to do this
                frame = RectangleI.Union(frame, tRect);

                Dimension = new Vector3D(frame.Width, frame.Height);
                fFrame = frame;
            }
        }
Exemplo n.º 46
0
 //--------------------------------------------------------------------
 public void clip_box(int x1, int y1, int x2, int y2)
 {
     m_clip_box = new RectangleI(x1, y1, x2, y2);
     m_clipping = true;
 }
Exemplo n.º 47
0
 public PushButton(string name, RectangleI frame, IGraphic label)
     : this(name, frame.Left, frame.Top, frame.Width, frame.Height, label)
 {
 }
Exemplo n.º 48
0
 public static int clipping_flags_y(int y, RectangleI clip_box)
 {
     return (((y > clip_box.y2 ? 1 : 0) << 1) | ((y < clip_box.y1 ? 1 : 0) << 3));
 }
Exemplo n.º 49
0
 /// <summary>
 ///   Checks whether the two specified rectangles at least partially intersect each other.
 /// </summary>
 /// <param name="first">
 ///   First rectangle to check.
 /// </param>
 /// <param name="second">
 ///   Second rectangle to check.
 /// </param>
 /// <returns>
 ///   <c>true</c>, if the two rectangles intersect each other, and <c>false</c> otherwise.
 /// </returns>
 public static bool Intersects(this RectangleI first, RectangleI second)
 {
     return (first.MaxX > second.X && first.X < second.MaxX)
            && (first.MaxY > second.Y && first.Y < second.MaxY);
 }
Exemplo n.º 50
0
 public Graphic(String name, RectangleI frame)
     : this(name, frame.Left, frame.Top, frame.Width, frame.Height)
 {
     // Do nothing in here.  It's just a convenience for the
     // more general call.
 }
Exemplo n.º 51
0
        public static int clip_liang_barsky(int x1, int y1, int x2, int y2,
                                          RectangleI clip_box,
                                          int[] x, int[] y)
        {
            int XIndex = 0;
            int YIndex = 0;
            double nearzero = 1e-30;

            double deltax = x2 - x1;
            double deltay = y2 - y1;
            double xin;
            double xout;
            double yin;
            double yout;
            double tinx;
            double tiny;
            double toutx;
            double touty;
            double tin1;
            double tin2;
            double tout1;
            int np = 0;

            if (deltax == 0.0)
            {
                // bump off of the vertical
                deltax = (x1 > clip_box.x1) ? -nearzero : nearzero;
            }

            if (deltay == 0.0)
            {
                // bump off of the horizontal 
                deltay = (y1 > clip_box.y1) ? -nearzero : nearzero;
            }

            if (deltax > 0.0)
            {
                // points to right
                xin = clip_box.x1;
                xout = clip_box.x2;
            }
            else
            {
                xin = clip_box.x2;
                xout = clip_box.x1;
            }

            if (deltay > 0.0)
            {
                // points up
                yin = clip_box.y1;
                yout = clip_box.y2;
            }
            else
            {
                yin = clip_box.y2;
                yout = clip_box.y1;
            }

            tinx = (xin - x1) / deltax;
            tiny = (yin - y1) / deltay;

            if (tinx < tiny)
            {
                // hits x first
                tin1 = tinx;
                tin2 = tiny;
            }
            else
            {
                // hits y first
                tin1 = tiny;
                tin2 = tinx;
            }

            if (tin1 <= 1.0)
            {
                if (0.0 < tin1)
                {
                    x[XIndex++] = (int)xin;
                    y[YIndex++] = (int)yin;
                    ++np;
                }

                if (tin2 <= 1.0)
                {
                    toutx = (xout - x1) / deltax;
                    touty = (yout - y1) / deltay;

                    tout1 = (toutx < touty) ? toutx : touty;

                    if (tin2 > 0.0 || tout1 > 0.0)
                    {
                        if (tin2 <= tout1)
                        {
                            if (tin2 > 0.0)
                            {
                                if (tinx > tiny)
                                {
                                    x[XIndex++] = (int)xin;
                                    y[YIndex++] = (int)(y1 + tinx * deltay);
                                }
                                else
                                {
                                    x[XIndex++] = (int)(x1 + tiny * deltax);
                                    y[YIndex++] = (int)yin;
                                }
                                ++np;
                            }

                            if (tout1 < 1.0)
                            {
                                if (toutx < touty)
                                {
                                    x[XIndex++] = (int)xout;
                                    y[YIndex++] = (int)(y1 + toutx * deltay);
                                }
                                else
                                {
                                    x[XIndex++] = (int)(x1 + touty * deltax);
                                    y[YIndex++] = (int)yout;
                                }
                            }
                            else
                            {
                                x[XIndex++] = x2;
                                y[YIndex++] = y2;
                            }
                            ++np;
                        }
                        else
                        {
                            if (tinx > tiny)
                            {
                                x[XIndex++] = (int)xin;
                                y[YIndex++] = (int)yout;
                            }
                            else
                            {
                                x[XIndex++] = (int)xout;
                                y[YIndex++] = (int)yin;
                            }
                            ++np;
                        }
                    }
                }
            }
            return np;
        }
Exemplo n.º 52
0
 public ImageClippingProxy(IImage ren)
     : base(ren)
 {
     m_clip_box = new RectangleI(0, 0, (int)ren.Width() - 1, (int)ren.Height() - 1);
 }
Exemplo n.º 53
0
 public static int clipping_flags_x(int x, RectangleI clip_box)
 {
     return ((x > clip_box.x2 ? 1 : 0) | ((x < clip_box.x1 ? 1 : 0) << 2));
 }
Exemplo n.º 54
0
 /// <summary>
 /// Determine whether this rectangle contains the given rectangle.
 /// </summary>
 /// <param name="other">The rectangle to test.</param>
 /// <returns>True if this rectangle contains the given rectangle.</returns>
 public bool Contains(RectangleI other)
 {
     return
         this.Y >= other.Y &&
         this.X <= other.X &&
         this.Bottom <= other.Bottom &&
         this.Right >= other.Right;
 }
Exemplo n.º 55
0
        //-------------------------------------------------------clip_line_segment
        // Returns: ret >= 4        - Fully clipped
        //          (ret & 1) != 0  - First point has been moved
        //          (ret & 2) != 0  - Second point has been moved
        //
        //template<class T>
        public static int clip_line_segment(ref int x1, ref int y1, ref int x2, ref int y2,
                                   RectangleI clip_box)
        {
            int f1 = clipping_flags(x1, y1, clip_box);
            int f2 = clipping_flags(x2, y2, clip_box);
            int ret = 0;

            if ((f2 | f1) == 0)
            {
                // Fully visible
                return 0;
            }

            if ((f1 & (int)clipping_flags_e.clipping_flags_x_clipped) != 0 &&
               (f1 & (int)clipping_flags_e.clipping_flags_x_clipped) == (f2 & (int)clipping_flags_e.clipping_flags_x_clipped))
            {
                // Fully clipped
                return 4;
            }

            if ((f1 & (int)clipping_flags_e.clipping_flags_y_clipped) != 0 &&
               (f1 & (int)clipping_flags_e.clipping_flags_y_clipped) == (f2 & (int)clipping_flags_e.clipping_flags_y_clipped))
            {
                // Fully clipped
                return 4;
            }

            int tx1 = x1;
            int ty1 = y1;
            int tx2 = x2;
            int ty2 = y2;
            if (f1 != 0)
            {
                if (!clip_move_point(tx1, ty1, tx2, ty2, clip_box, ref x1, ref y1, f1))
                {
                    return 4;
                }
                if (x1 == x2 && y1 == y2)
                {
                    return 4;
                }
                ret |= 1;
            }
            if (f2 != 0)
            {
                if (!clip_move_point(tx1, ty1, tx2, ty2, clip_box, ref x2, ref y2, f2))
                {
                    return 4;
                }
                if (x1 == x2 && y1 == y2)
                {
                    return 4;
                }
                ret |= 2;
            }
            return ret;
        }
Exemplo n.º 56
0
 /// <summary>
 /// Determine whether this rectangle intersects the given rectangle.
 /// </summary>
 /// <param name="other">The rectangle to test.</param>
 /// <returns>True if this rectangle intersects the given rectangle.</returns>
 public bool Intersects(RectangleI other)
 {
     return
         !(this.Y <= other.Bottom ||
         this.X >= other.Right ||
         this.Bottom >= other.Y ||
         this.Right <= other.X);
 }
Exemplo n.º 57
0
        public RectangleI[] GetRectangles()
        {

            // If the region is empty, return a single empty rectangle
            if (IsEmpty)
            {
                return new RectangleI[1];
            }

            // 1. Call GetRgnData with null to get size
            uint dataLengthNeeded = GDI32.GetRegionData(DangerousGetHandle(), 0, IntPtr.Zero);

            // 2. allocate some memory to hold the data
            UnmanagedMemory uMem = new UnmanagedMemory((int)dataLengthNeeded);
            IntPtr memoryPtr = uMem.MemoryPointer;
            UnmanagedPointer structPtr = new UnmanagedPointer(memoryPtr);

            // 3. call again passing in memory
            uint bytesFilled = GDI32.GetRegionData(DangerousGetHandle(), dataLengthNeeded, structPtr);
            
            // If the return value is 0, then the call failed.
            if (0 == bytesFilled)
                return null;

            // 4. convert memory to data structures
            // First get the RGNDATAHEADER
            RGNDATAHEADER dataHeader;
            dataHeader = (RGNDATAHEADER)Marshal.PtrToStructure(structPtr, typeof(RGNDATAHEADER));

            // dataHeader.dwSize    - tells us how big the header is, and thus how many bytes to skip to get
            //                          to the rectangle information
            // dataHeader.nRgnSize  - tells us how many bytes are needed for the rectangle information
            // dataHeader.nCount    - tells us how many rectangles there are


            structPtr = structPtr + dataHeader.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)(dataHeader.nRgnSize / dataHeader.nCount);

            // Create a list to add the rectangles to.  This is simply convenient.
            RectangleI[] rects = new RectangleI[dataHeader.nCount];

            // Loop through creating as many rectangles as indicated by the dataheader nCount field
            for (int i = 0; i < dataHeader.nCount; i++)
            {
                RECT rect = (RECT)Marshal.PtrToStructure(structPtr, typeof(RECT));
                rects[i].x1 = rect.X;
                rects[i].y1 = rect.Y;
                rects[i].x2 = rect.X + rect.Width;
                rects[i].y2 = rect.Y + rect.Height;
                rects[i].Normalize();

                structPtr = structPtr + structIncrement;
            }


            // 5. free memory
            uMem.Dispose();

            return rects;
        }
Exemplo n.º 58
0
 public GraphicGroup(String name, RectangleI rect)
     : this(name, rect.Left, rect.Top, rect.Width, rect.Height, LayoutManager.Empty)
 {
 }
Exemplo n.º 59
0
        /// <summary>
        /// Invalidate a portion of the client rectangle.
        /// </summary>
        /// <param name="partialFrame"></param>
        public virtual void Invalidate(RectangleI portionOfClientRectangle)
        {
            // The portion to be invalidated is given in the coordinate space
            // of the client rectangle.  That portion needs to be converted
            // into the parent's space and sent to the parent for evaluation
            portionOfClientRectangle.Offset(Frame.Left, Frame.Top);

            if (null != Container)
            {
                Container.Invalidate(portionOfClientRectangle);
            }
            else if (null != Window)
                Window.Invalidate(portionOfClientRectangle);
        }
Exemplo n.º 60
0
        public void copy_from(IImage src,
                       RectangleI rect_src_ptr,
                       int dx,
                       int dy)
        {
            RectangleI rsrc = new RectangleI(rect_src_ptr.x1, rect_src_ptr.y1, rect_src_ptr.x2 + 1, rect_src_ptr.y2 + 1);

            // Version with xdst, ydst (absolute positioning)
            //rect_i rdst(xdst, ydst, xdst + rsrc.x2 - rsrc.x1, ydst + rsrc.y2 - rsrc.y1);

            // Version with dx, dy (relative positioning)
            RectangleI rdst = new RectangleI(rsrc.x1 + dx, rsrc.y1 + dy, rsrc.x2 + dx, rsrc.y2 + dy);

            RectangleI rc = clip_rect_area(ref rdst, ref rsrc, (int)src.Width(), (int)src.Height());

            if (rc.x2 > 0)
            {
                int incy = 1;
                if (rdst.y1 > rsrc.y1)
                {
                    rsrc.y1 += rc.y2 - 1;
                    rdst.y1 += rc.y2 - 1;
                    incy = -1;
                }
                int getDistanceBetweenPixelsInclusive = src.GetDistanceBetweenPixelsInclusive();
                while (rc.y2 > 0)
                {
                    base.CopyFrom(src,
                                     rdst.x1, rdst.y1,
                                     rsrc.x1, rsrc.y1,
                                     rc.x2 * getDistanceBetweenPixelsInclusive);
                    rdst.y1 += incy;
                    rsrc.y1 += incy;
                    --rc.y2;
                }
            }
        }