FromLTRB() public static méthode

Creates a new with the specified location and size.
public static FromLTRB ( int left, int top, int right, int bottom ) : Rectangle
left int
top int
right int
bottom int
Résultat Rectangle
        /// <summary>
        /// Return a rectangle of our coordinates
        /// </summary>
        /// <param name="topLeft"></param>
        /// <param name="bottomRight"></param>
        /// <returns></returns>
        public Rectangle ConvertRectangle(PointF topLeft, PointF bottomRight)
        {
            Point topLeftXY     = ConvertPoint(topLeft);
            Point bottomRightXY = ConvertPoint(bottomRight);

            return(Rectangle.FromLTRB(Math.Min(topLeftXY.X, bottomRightXY.X), Math.Min(topLeftXY.Y, bottomRightXY.Y), Math.Max(topLeftXY.X, bottomRightXY.X), Math.Max(topLeftXY.Y, bottomRightXY.Y)));
        }
Exemple #2
0
        public override void OnPaint(IRenderEventArgs e)
        {
            Graphics g = ((GdiSurface)e.Surface).Graphics;

            SD.Drawing2D.Matrix save = g.Transform;
            g.Transform = Camera.Matrix.ToGdi();

            Rectangle smaller = new Rectangle(start, new Size(50, 20));
            Rectangle bigger  = new Rectangle(start, new Size(55, 25));

            g.DrawRectangle(rectPen, smaller);
            g.DrawRectangle(rectPen, bigger);

            smaller.Inflate(-5, -5);
            bigger.Inflate(5, 5);
            Rectangle[] pathRects =
            {
                Rectangle.FromLTRB(bigger.Left,   bigger.Top,     bigger.Right, smaller.Top),
                Rectangle.FromLTRB(bigger.Left,   smaller.Bottom, bigger.Right, bigger.Bottom),
                Rectangle.FromLTRB(bigger.Left,   smaller.Top,    smaller.Left, smaller.Bottom),
                Rectangle.FromLTRB(smaller.Right, smaller.Top,    bigger.Right, smaller.Bottom)
            };

            Region clipRegion = new Region();

            clipRegion.MakeInfinite();
            clipRegion.Intersect(
                Rectangle.FromLTRB(bigger.Left, bigger.Top, bigger.Right, smaller.Top));
            clipRegion.Union(
                Rectangle.FromLTRB(bigger.Left, smaller.Bottom, bigger.Right, bigger.Bottom));
            clipRegion.Union(
                Rectangle.FromLTRB(bigger.Left, smaller.Top, smaller.Left, smaller.Bottom));
            clipRegion.Union(
                Rectangle.FromLTRB(smaller.Right, smaller.Top, bigger.Right, smaller.Bottom));


            bool       isVisible = false;
            RectangleF testRect  = Rectangle.Inflate(smaller, -1, -1);

            isVisible = clipRegion.IsVisible(testRect);
            if (isVisible)
            {
                clipRegion.MakeInfinite();
            }
            invPath.Reset();
            invPath.FillMode = FillMode.Alternate;
            invPath.AddRectangles(pathRects);
            g.DrawPath(pathPen, invPath);
            g.FillPath(regionBrush, invPath);
        }
        public Texture2D TryGetNextFrameAsTexture2D(Device device)
        {
            if (_hWnd == IntPtr.Zero)
            {
                return(null);
            }

            var hdcSrc  = NativeMethods.GetDCEx(_hWnd, IntPtr.Zero, DeviceContextValues.Window | DeviceContextValues.Cache | DeviceContextValues.LockWindowUpdate);
            var hdcDest = NativeMethods.CreateCompatibleDC(hdcSrc);

            NativeMethods.GetWindowRect(_hWnd, out var rect);
            var(width, height) = (rect.Right - rect.Left, rect.Bottom - rect.Top);
            var hBitmap = NativeMethods.CreateCompatibleBitmap(hdcSrc, width, height);
            var hOld    = NativeMethods.SelectObject(hdcDest, hBitmap);

            NativeMethods.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, TernaryRasterOperations.SRCCOPY);
            NativeMethods.SelectObject(hdcDest, hOld);
            NativeMethods.DeleteDC(hdcDest);
            NativeMethods.ReleaseDC(_hWnd, hdcSrc);

            using var img = Image.FromHbitmap(hBitmap);
            NativeMethods.DeleteObject(hBitmap);

            using var bitmap = img.Clone(Rectangle.FromLTRB(0, 0, width, height), PixelFormat.Format32bppArgb);
            var bits = bitmap.LockBits(Rectangle.FromLTRB(0, 0, width, height), ImageLockMode.ReadOnly, img.PixelFormat);

            var data = new DataBox {
                DataPointer = bits.Scan0, RowPitch = bits.Width * 4, SlicePitch = bits.Height
            };

            var texture2dDescription = new Texture2DDescription
            {
                ArraySize         = 1,
                BindFlags         = BindFlags.ShaderResource | BindFlags.RenderTarget,
                CpuAccessFlags    = CpuAccessFlags.None,
                Format            = Format.B8G8R8A8_UNorm,
                Height            = height,
                MipLevels         = 1,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default,
                Width             = width
            };
            var texture2d = new Texture2D(device, texture2dDescription, new[] { data });

            bitmap.UnlockBits(bits);

            return(texture2d);
        }
Exemple #4
0
        static GraphicsPath roundedPath(Rectangle r, Vector4 corners)
        {
            GraphicsPath path = new GraphicsPath();

            int d = (int)(corners.W * 2);

            path.AddLine(r.Left + d, r.Top, r.Right - d, r.Top);
            if (d > 0)
            {
                path.AddArc(Rectangle.FromLTRB(r.Right - d, r.Top, r.Right, r.Top + d), -90, 90);
            }

            d = (int)(corners.X * 2);
            path.AddLine(r.Right, r.Top + d, r.Right, r.Bottom - d);
            if (d > 0)
            {
                path.AddArc(Rectangle.FromLTRB(r.Right - d, r.Bottom - d, r.Right, r.Bottom), 0, 90);
            }

            d = (int)(corners.Y * 2);
            path.AddLine(r.Right - d, r.Bottom, r.Left + d, r.Bottom);
            if (d > 0)
            {
                path.AddArc(Rectangle.FromLTRB(r.Left, r.Bottom - d, r.Left + d, r.Bottom), 90, 90);
            }

            d = (int)(corners.Z * 2);
            path.AddLine(r.Left, r.Bottom - d, r.Left, r.Top + d);
            if (d > 0)
            {
                path.AddArc(Rectangle.FromLTRB(r.Left, r.Top, r.Left + d, r.Top + d), 180, 90);
            }

            path.CloseFigure();
            return(path);
        }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            // Update depth bar...
            _depthBar.MouseMove(e, Size);
            RectangleF area = _depthBar.groupGetArea(_depthBar.getBarArea(Size), _depthBar.DepthProbes.Count); // Only redraw the depth bar group for the cursor.

            Invalidate(Rectangle.FromLTRB((int)Math.Floor(area.X) - 1, (int)Math.Floor(area.Y), (int)Math.Ceiling(area.Right) - 1, (int)Math.Ceiling(area.Bottom) - 1));

            switch (e.Button)
            {
            case MouseButtons.Left:
                if (_currentlyEditedDepthProbeIndex.HasValue)
                {
                    // Move depth probe around
                    _depthBar.DepthProbes[_currentlyEditedDepthProbeIndex.Value].Position = FromVisualCoord(e.Location);
                    Invalidate();
                }
                else if (_roomMouseClicked != null)
                {
                    bool copyMode = ModifierKeys.HasFlag(Keys.Control);

                    if (copyMode && ((Vector3)_overallDelta).Length() >= 1 * ViewScale)
                    {
                        _roomsToMove = null;
                        DoDragDrop(new RoomClipboardData(_editor, FromVisualCoord(e.Location)), DragDropEffects.Copy);
                        break;
                    }

                    if (_roomsToMove == null)
                    {
                        _roomsToMove = _editor.Level.GetConnectedRooms(_editor.SelectedRooms.Concat(new[] { _roomMouseClicked }));
                    }

                    if (_roomsToMove != null && UpdateRoomPosition(FromVisualCoord(e.Location) - _roomMouseOffset, _roomMouseClicked, !copyMode))
                    {
                        // Move rooms around
                        foreach (Room room in _roomsToMove)
                        {
                            _editor.RoomPropertiesChange(room);
                        }
                        _editor.ResetCamera();
                        Invalidate();
                    }
                }
                else if (_selectionArea != null)
                {
                    goto case MouseButtons.Middle;
                }
                break;

            case MouseButtons.Middle:
                RectangleF oldArea = ToVisualCoord(_selectionArea._area);
                _selectionArea._area.End = FromVisualCoord(e.Location);
                RectangleF newArea = ToVisualCoord(_selectionArea._area);
                _selectionArea._roomSelectionCache = null;
                Invalidate();
                break;

            case MouseButtons.Right:
                if (_viewMoveMouseWorldCoord != null)
                {
                    if (ModifierKeys.HasFlag(Keys.Control))
                    {     // Zoom
                        float relativeDeltaY = (e.Location.Y - _lastMousePosition.Y) / (float)Height;
                        ViewScale *= (float)Math.Exp(_editor.Configuration.Map2D_NavigationSpeedMouseZoom * relativeDeltaY);
                        Invalidate();
                    }
                    else
                    {     // Panning
                        MoveToFixedPoint(e.Location, _viewMoveMouseWorldCoord.Value, true);
                    }
                }
                break;
            }

            _lastMousePosition = e.Location;
        }
Exemple #6
0
        public Size GetTrueSize()
        {
            if (TrueSize != Size.Empty)
            {
                return(TrueSize);
            }

            int l = 0, t = 0, r = Width, b = Height;

            bool visible = false;

            for (int x = 0; x < r; x++)
            {
                for (int y = 0; y < b; y++)
                {
                    if (!VisiblePixel(new Point(x, y)))
                    {
                        continue;
                    }

                    visible = true;
                    break;
                }

                if (!visible)
                {
                    continue;
                }

                l = x;
                break;
            }

            visible = false;
            for (int y = 0; y < b; y++)
            {
                for (int x = l; x < r; x++)
                {
                    if (!VisiblePixel(new Point(x, y)))
                    {
                        continue;
                    }

                    visible = true;
                    break;
                }
                if (!visible)
                {
                    continue;
                }

                t = y;
                break;
            }

            visible = false;
            for (int x = r - 1; x >= l; x--)
            {
                for (int y = 0; y < b; y++)
                {
                    if (!VisiblePixel(new Point(x, y)))
                    {
                        continue;
                    }

                    visible = true;
                    break;
                }

                if (!visible)
                {
                    continue;
                }

                r = x + 1;
                break;
            }

            visible = false;
            for (int y = b - 1; y >= t; y--)
            {
                for (int x = l; x < r; x++)
                {
                    if (!VisiblePixel(new Point(x, y)))
                    {
                        continue;
                    }

                    visible = true;
                    break;
                }
                if (!visible)
                {
                    continue;
                }

                b = y + 1;
                break;
            }

            TrueSize = Rectangle.FromLTRB(l, t, r, b).Size;

            return(TrueSize);
        }
Exemple #7
0
        public void RenderLabel(DrawArgs drawArgs, int x, int y, int buttonHeight, bool selected, MenuAnchor anchor)
        {
            if (selected)
            {
                if (buttonHeight == this.curSize)
                {
                    this.alpha += alphaStep;
                    if (this.alpha > 255)
                    {
                        this.alpha = 255;
                    }
                }
            }
            else
            {
                this.alpha -= alphaStep;
                if (this.alpha < 0)
                {
                    this.alpha = 0;
                    return;
                }
            }

            int halfWidth = (int)(SelectedSize * 0.75);
            int label_x   = x - halfWidth + 1;
            int label_y   = (int)(y + SelectedSize) + 1;

            FontDrawFlags format = FontDrawFlags.NoClip | FontDrawFlags.Center | FontDrawFlags.WordBreak;

            if (anchor == MenuAnchor.Bottom)
            {
                format |= FontDrawFlags.Bottom;
                label_y = y - 202;
            }

            Rectangle rect = new Rectangle(
                label_x,
                label_y,
                (int)halfWidth * 2,
                200);

            if (rect.Right > drawArgs.screenWidth)
            {
                rect = Rectangle.FromLTRB(rect.Left, rect.Top, drawArgs.screenWidth, rect.Bottom);
            }

            drawArgs.toolbarFont.DrawText(
                null, this.Description,
                rect,
                format,
                black & 0xffffff + (this.alpha << 24));

            rect.Offset(2, 0);

            drawArgs.toolbarFont.DrawText(
                null, this.Description,
                rect,
                format,
                black & 0xffffff + (this.alpha << 24));

            rect.Offset(0, 2);

            drawArgs.toolbarFont.DrawText(
                null, this.Description,
                rect,
                format,
                black & 0xffffff + (this.alpha << 24));

            rect.Offset(-2, 0);

            drawArgs.toolbarFont.DrawText(
                null, this.Description,
                rect,
                format,
                black & 0xffffff + (this.alpha << 24));

            rect.Offset(1, -1);

            drawArgs.toolbarFont.DrawText(
                null, this.Description,
                rect,
                format,
                white & 0xffffff + (this.alpha << 24));
        }
Exemple #8
0
        /// <summary>
        ///     Trims the whitespace around a bitmap
        /// </summary>
        /// <param name="source">The bitmap to trim</param>
        /// <returns>The trimmed bitmap</returns>
        private Bitmap TrimBitmap(Bitmap source)
        {
            CSRectangle srcRect;

            CSImaging.BitmapData data = null;
            try {
                data = source.LockBits(new CSRectangle(0, 0, source.Width, source.Height),
                                       CSImaging.ImageLockMode.ReadOnly, CSImaging.PixelFormat.Format32bppArgb);
                var buffer = new byte[data.Height * data.Stride];
                Marshal.Copy(data.Scan0, buffer, 0, buffer.Length);
                var xMin = int.MaxValue;
                var xMax = 0;
                var yMin = int.MaxValue;
                var yMax = 0;
                for (var y = 0; y < data.Height; y++)
                {
                    for (var x = 0; x < data.Width; x++)
                    {
                        var alpha = buffer[y * data.Stride + 4 * x + 3];
                        if (alpha != 0)
                        {
                            if (x < xMin)
                            {
                                xMin = x;
                            }
                            if (x > xMax)
                            {
                                xMax = x;
                            }
                            if (y < yMin)
                            {
                                yMin = y;
                            }
                            if (y > yMax)
                            {
                                yMax = y;
                            }
                        }
                    }
                }
                if (xMax < xMin || yMax < yMin)
                {
                    return(null);
                }
                srcRect = CSRectangle.FromLTRB(xMin, yMin, xMax, yMax);
            }
            finally {
                if (data != null)
                {
                    source.UnlockBits(data);
                }
            }

            var dest     = new Bitmap(srcRect.Width, srcRect.Height);
            var destRect = new CSRectangle(0, 0, srcRect.Width, srcRect.Height);

            using (var graphics = Graphics.FromImage(dest)) {
                graphics.DrawImage(source, destRect, srcRect, GraphicsUnit.Pixel);
            }
            return(dest);
        }