예제 #1
0
        /// <summary>
        /// Clips the bounds of an image tile to the specified display location and clipping region.
        /// </summary>
        /// <param name="dest"><para>
        /// On input, the location within the entire <see cref="MapView"/> where the upper-left
        /// corner of an image tile should appear.
        /// </para><para>
        /// On output, the location within and relative to the specified <paramref name="region"/>
        /// where the upper-left corner of the returned image tile portion should be drawn.
        /// </para></param>
        /// <param name="region"><para>
        /// On input, the display region within the entire <see cref="MapView"/> to which drawing is
        /// clipped.
        /// </para><para>
        /// On output, the portion of the image tile that should be drawn at the adjusted <paramref
        /// name="dest"/> location when returning <c>true</c>; otherwise, unchanged.</para></param>
        /// <returns>
        /// <c>true</c> if <paramref name="region"/> contains the portion of the image tile to draw;
        /// <c>false</c> if nothing should be drawn.</returns>
        /// <remarks>
        /// The specified <paramref name="region"/> should indicate the portion of the entire <see
        /// cref="MapView"/> that is covered by the current contents of the paint buffer.</remarks>

        private bool ClipTile(ref PointI dest, ref RectI region)
        {
            // shift destination to clipping region
            dest -= region.Location;

            /*
             * We draw at most the area of one image tile. If the destination
             * is negative, we actually draw only the lower and/or right part
             * of an image tile, and reduce the returned bounds accordingly.
             */

            // negative offset to clipping region
            PointI neg = new PointI(Math.Max(0, -dest.X), Math.Max(0, -dest.Y));

            // reduce destination to positive offset
            dest = new PointI(Math.Max(0, dest.X), Math.Max(0, dest.Y));

            // clip image tile to destination and clipping region
            int width  = Math.Min(MapView.TileWidth - neg.X, region.Width - dest.X);
            int height = Math.Min(MapView.TileHeight - neg.Y, region.Height - dest.Y);

            // check if there is anything to draw
            if (width <= 0 || height <= 0)
            {
                return(false);
            }
            region = new RectI(neg.X, neg.Y, width, height);
            return(true);
        }
예제 #2
0
        /// <summary>
        /// Overlays pixel data from another <see cref="BitmapBuffer"/>, with alpha blending.
        /// </summary>
        /// <param name="x">
        /// The x-coordinate where to begin writing in this <see cref="BitmapBuffer"/>.</param>
        /// <param name="y">
        /// The y-coordinate where to begin writing in this <see cref="BitmapBuffer"/>.</param>
        /// <param name="source">
        /// Another <see cref="BitmapBuffer"/> containing the rectangle to overlay.</param>
        /// <param name="bounds">
        /// The pixel rectangle within the specified <paramref name="source"/> to overlay.</param>
        /// <param name="color">
        /// The <see cref="Color"/> to substitute for all <paramref name="source"/> pixels.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="source"/> is a null reference.</exception>
        /// <remarks><para>
        /// <b>Overlay</b> blends all <see cref="Pixels"/> elements within the specified <paramref
        /// name="bounds"/> of the specified <paramref name="source"/> buffer with the corresponding
        /// <see cref="Pixels"/> elements in this <see cref="BitmapBuffer"/>, starting with the
        /// specified <paramref name="x"/> and <paramref name="y"/> coordinates.
        /// </para><para>
        /// <b>Overlay</b> calls <see cref="BitmapUtility.BlendPbgra32"/> to perform alpha blending
        /// between the specified <paramref name="source"/> buffer (acting as the overlay) and this
        /// <see cref="BitmapBuffer"/> (acting as the blending target). No coordinate checking is
        /// performed.
        /// </para><para>
        /// <b>Overlay</b> substitutes the specified <paramref name="color"/> for the actual color
        /// channels of each <paramref name="source"/> pixel, while using its alpha channel to
        /// govern alpha blending with the corresponding <see cref="Pixels"/> element. The alpha
        /// channel of the specified <paramref name="color"/> is ignored.</para></remarks>

        public void Overlay(int x, int y, BitmapBuffer source, RectI bounds, Color color)
        {
            if (source == null)
            {
                ThrowHelper.ThrowArgumentNullException("source");
            }

            int sourceOffset = bounds.X + source._size.Width * bounds.Y;
            int targetOffset = x + _size.Width * y;

            for (int dy = 0; dy < bounds.Height; dy++)
            {
                for (int dx = 0; dx < bounds.Width; dx++)
                {
                    uint p0 = source._pixels[sourceOffset + dx];
                    uint p1 = _pixels[targetOffset + dx];

                    // multiply color channels with source alpha
                    color.A = (byte)(p0 >> 24);
                    p0      = BitmapUtility.ColorToPbgra32(color);

                    _pixels[targetOffset + dx] = BitmapUtility.BlendPbgra32(p0, p1);
                }

                sourceOffset += source._size.Width;
                targetOffset += _size.Width;
            }
        }
예제 #3
0
 public void Del(RectI rect)
 {
     foreach (Vector2Int position in rect)
     {
         this.positions.Remove(position);
     }
 }
    /// <summary>
    /// Presents the contents of the next buffer in the sequence of back buffers to the screen.
    /// </summary>
    /// <param name="presentFlags">The present flags.</param>
    /// <param name="sourceRectangle">The area of the back buffer that should be presented.</param>
    /// <param name="destinationRectangle">The area of the front buffer that should receive the result of the presentation.</param>
    /// <param name="windowOverride">The destination window whose client area is taken as the target for this presentation.</param>
    /// <unmanaged>HRESULT IDirect3DSwapChain9::Present([In, Optional] const void* pSourceRect,[InOut, Optional] const void* pDestRect,[In] HWND hDestWindowOverride,[In] const RGNDATA* pDirtyRegion,[In] unsigned int dwFlags)</unmanaged>
    public void Present(RectI sourceRectangle, RectI destinationRectangle, IntPtr windowOverride, Present presentFlags)
    {
        RawRect sourceRect = sourceRectangle;
        RawRect destRect   = destinationRectangle;

        Present(&sourceRect, &destRect, windowOverride, null, (int)presentFlags);
    }
예제 #5
0
		public RectI(RectI clone)
		{
			_x = clone.X;
			_y = clone.Y;
			_width = clone.Width;
			_height = clone.Height;
		}
예제 #6
0
 protected Map(int rows, int columns)
 {
     _cells  = new Cell[rows, columns];
     Bounds  = new RectI(0, 0, columns, rows);
     Rows    = rows;
     Columns = columns;
 }
 public RectI(RectI rect) : this(IronSightEnginePINVOKE.new_RectI__SWIG_2(RectI.getCPtr(rect)), true)
 {
     if (IronSightEnginePINVOKE.SWIGPendingException.Pending)
     {
         throw IronSightEnginePINVOKE.SWIGPendingException.Retrieve();
     }
 }
예제 #8
0
        public Room Generate(Random random, Area area)
        {
            if (_roomCount >= MaxRooms)
            {
                return(null);
            }

            // Don't place the room on the area's edge.
            // This will keep rooms from being adjacent to each other.
            var placeableBounds = area.Bounds.Inflate(-1);

            var width  = random.Next(MinWidth, placeableBounds.Width + 1);
            var height = random.Next(MinHeight, placeableBounds.Height + 1);

            // Find a place in the area to put the room.
            while (true)
            {
                var x          = random.Next(placeableBounds.Left, placeableBounds.Right - width + 1 + 1);
                var y          = random.Next(placeableBounds.Top, placeableBounds.Bottom - height + 1 + 1);
                var roomBounds = new RectI(x, y, width, height);
                if (placeableBounds.Contains(roomBounds))
                {
                    _roomCount++;
                    return(new Room(random, roomBounds));
                }
            }
        }
        /// <summary>
        /// Handles the face frame data arriving from the sensor
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void Reader_FaceFrameArrived(object sender, FaceFrameArrivedEventArgs e)
        {
            using (FaceFrame faceFrame = e.FrameReference.AcquireFrame())
            {
                if (faceFrame != null)
                {
                    // get the index of the face source from the face source array
                    int index = this.GetFaceSourceIndex(faceFrame.FaceFrameSource);

                    // check if this face frame has valid face frame results
                    if (this.ValidateFaceBoxAndPoints(faceFrame.FaceFrameResult))
                    {
                        // store this face frame result to draw later
                        this.faceFrameResults[index] = faceFrame.FaceFrameResult;

                        RectI oldFace = faceFrame.FaceFrameResult.FaceBoundingBoxInColorSpace;

                        FaceRectangle newface = new FaceRectangle();
                        newface.Left   = oldFace.Left;
                        newface.Top    = oldFace.Top;
                        newface.Height = (oldFace.Top - oldFace.Bottom);
                        newface.Width  = (oldFace.Left - oldFace.Right);

                        DrawRect(newface);
                    }
                    else
                    {
                        // indicates that the latest face frame result from this reader is invalid
                        this.faceFrameResults[index] = null;
                    }
                }
            }
        }
        void DrawFaceFrameResult(int faceIndex, FaceFrameResult faceResult, DrawingContext drawingContext)
        {
            //Brush/Pen
            Brush drawingBrush = faceBrush[0];

            if (faceIndex < bodyCount)
            {
                drawingBrush = faceBrush[faceIndex];
            }
            Pen drawingPen = new Pen(drawingBrush, 5);

            //Face Points
            var facePoints = faceResult.FacePointsInColorSpace;

            foreach (PointF pointF in facePoints.Values)
            {
                Point points = new Point(pointF.X, pointF.Y);

                RectI box = faceResult.FaceBoundingBoxInColorSpace;

                Target.Width  = box.Right - box.Left;
                Target.Height = box.Bottom - box.Top;

                Canvas.SetLeft(Target, (points.X / 4) - Target.Width / 2);
                Canvas.SetTop(Target, points.Y / 4 - Target.Height / 2);
            }
        }
예제 #11
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics graphics = e.Graphics;

            //  Draw AdditionLogos before foreground render
            if (!Canvas.ShouldDrawBackground)
            {
                DrawAdditionLogos(graphics);
            }


            //
            m_FPSCounter.Tick();

            if (m_IntervalTimer.IsTimeOver)
            {
                m_ExamplesHolder.FPS = FPS;
            }


            base.OnPaint(e);


            //  Need to process system redraw needs (like window overlapping etc.)
            if (Size != SizeI.Empty)
            {
                //  Draw Main Logo
                Bitmap logo     = GUI.Config.Logo;
                RectI  logoRect = m_ExamplesHolder.LogoArea;
                PointI logoPos  = new PointI(logoRect.Right - logo.PixelWidth - 10, logoRect.Top + 15);
                graphics.DrawImage(logo, logoPos);
            }
        }
예제 #12
0
        public void DrawRectangle(RectI area, ref TilePicker tile)
        {
            // Use refs for faster access (really important!) speeds up a lot!
            int w = _world.Header.WorldBounds.W;
            int h = _world.Header.WorldBounds.H;

            // Check boundaries
            area.Rebound(_world.Header.WorldBounds);

            // (needed for refs)
            int x1 = area.Left;
            int x2 = area.Right;
            int y1 = area.Top;
            int y2 = area.Bottom;

            // top and bottom horizontal scanlines
            for (int x = area.Left; x <= area.Right; x++)
            {
                UpdateTile(ref tile, ref x, ref y1, ref w);
                UpdateTile(ref tile, ref x, ref y2, ref w);
            }

            for (int y = area.Top; y <= area.Bottom; y++)
            {
                UpdateTile(ref tile, ref x1, ref y, ref w);
                UpdateTile(ref tile, ref x2, ref y, ref w);
            }
        }
예제 #13
0
        //----------------------------------------------------------------------------
        //template<class T>
        public static bool ClipMovePoint(int x1, int y1, int x2, int y2,
                                         RectI clip_box,
                                         ref int x, ref int y, uint flags)
        {
            int bound;

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

            flags = ClippingFlagsY(y, clip_box);
            if ((flags & (uint)ClippingFlags.yClipped) != 0)
            {
                if (y1 == y2)
                {
                    return(false);
                }
                bound = ((flags & (uint)ClippingFlags.x1Clipped) != 0) ? clip_box.y1 : clip_box.y2;
                x     = (int)((double)(bound - y1) * (x2 - x1) / (y2 - y1) + x1);
                y     = bound;
            }
            return(true);
        }
예제 #14
0
        /// <summary>
        /// Overlays pixel data from another <see cref="BitmapBuffer"/>, with the specified alpha
        /// channel threshold.</summary>
        /// <param name="x">
        /// The x-coordinate where to begin writing in this <see cref="BitmapBuffer"/>.</param>
        /// <param name="y">
        /// The y-coordinate where to begin writing in this <see cref="BitmapBuffer"/>.</param>
        /// <param name="source">
        /// Another <see cref="BitmapBuffer"/> containing the rectangle to overlay.</param>
        /// <param name="bounds">
        /// The pixel rectangle within the specified <paramref name="source"/> to overlay.</param>
        /// <param name="alpha">
        /// The alpha channel threshold below which <paramref name="source"/> pixels will be
        /// ignored.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="source"/> is a null reference.</exception>
        /// <remarks><para>
        /// <b>Overlay</b> copies only those <see cref="Pixels"/> elements within the specified
        /// <paramref name="bounds"/> of the specified <paramref name="source"/> buffer whose alpha
        /// channel meets or exceeds the specified <paramref name="alpha"/> threshold.
        /// </para><para>
        /// The copies are written to the <see cref="Pixels"/> array of this <see
        /// cref="BitmapBuffer"/>, starting with the specified <paramref name="x"/> and <paramref
        /// name="y"/> coordinates. No alpha blending or coordinate checking is performed.
        /// </para></remarks>

        public void Overlay(int x, int y, BitmapBuffer source, RectI bounds, byte alpha)
        {
            if (source == null)
            {
                ThrowHelper.ThrowArgumentNullException("source");
            }

            int sourceOffset = bounds.X + source._size.Width * bounds.Y;
            int targetOffset = x + _size.Width * y;

            for (int dy = 0; dy < bounds.Height; dy++)
            {
                for (int dx = 0; dx < bounds.Width; dx++)
                {
                    uint value = source._pixels[sourceOffset + dx];
                    if ((value >> 24) >= alpha)
                    {
                        _pixels[targetOffset + dx] = value;
                    }
                }

                sourceOffset += source._size.Width;
                targetOffset += _size.Width;
            }
        }
예제 #15
0
 public void Add(RectI rect)
 {
     foreach (Vector2Int position in rect)
     {
         this.AddTilable(position);
     }
 }
예제 #16
0
        /// <summary>
        /// Indicates whether the two specified <see cref="ImageFrame"/> objects define identical
        /// bitmap tiles.</summary>
        /// <param name="firstFrame">
        /// The first <see cref="ImageFrame"/> to compare.</param>
        /// <param name="secondFrame">
        /// The second <see cref="ImageFrame"/> to compare.</param>
        /// <returns>
        /// <c>true</c> if all pixels in the specified <paramref name="firstFrame"/> contain the
        /// same <see cref="Color"/> values as the corresponding pixels in the specified <paramref
        /// name="secondFrame"/>; otherwise, <c>false</c>.</returns>

        private static bool AreTilesEqual(ImageFrame firstFrame, ImageFrame secondFrame)
        {
            WriteableBitmap bitmap1 = firstFrame.Source.Value.Bitmap;
            WriteableBitmap bitmap2 = secondFrame.Source.Value.Bitmap;
            RectI           bounds1 = firstFrame.Bounds, bounds2 = secondFrame.Bounds;

            if (bounds1.Size != bounds2.Size)
            {
                return(false);
            }

            for (int x = 0; x < bounds1.Width; x++)
            {
                for (int y = 0; y < bounds1.Height; y++)
                {
                    if (bitmap1.GetPixel(x + bounds1.X, y + bounds1.Y) !=
                        bitmap2.GetPixel(x + bounds2.X, y + bounds2.Y))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
예제 #17
0
 public void CopyPixels(RectI rectangle, int stride, byte[] data)
 {
     fixed(byte *dataPtr = &data[0])
     {
         CopyPixels(&rectangle, stride, data.Length, dataPtr);
     }
 }
예제 #18
0
 public void CopyPixels <T>(RectI rectangle, int stride, Span <T> data) where T : unmanaged
 {
     fixed(T *dataPtr = data)
     {
         CopyPixels(&rectangle, stride, data.Length * sizeof(T), dataPtr);
     }
 }
예제 #19
0
        /// <summary>
        /// The show zoom rectangle.
        /// </summary>
        /// <param name="r">
        /// The r.
        /// </param>
        public void ShowZoomRectangle(OxyRect r)
        {
            this.zoomRectangle = new RectI((int)r.Left, (int)r.Top, (int)r.Width, (int)r.Height);

            //this.Invalidate();
            Refresh();
        }
예제 #20
0
 public RectI(RectI clone)
 {
     _x      = clone.X;
     _y      = clone.Y;
     _width  = clone.Width;
     _height = clone.Height;
 }
예제 #21
0
        /// <summary>
        /// The hide zoom rectangle.
        /// </summary>
        public void HideZoomRectangle()
        {
            this.zoomRectangle = RectI.Empty;

            //this.Invalidate();
            Refresh();
        }
예제 #22
0
 //----------------------------------------------------------GetClippingFlags
 // Determine the clipping code of the Vertex according to the
 // Cyrus-Beck Line clipping algorithm
 //
 //        |        |
 //  0110  |  0010  | 0011
 //        |        |
 // -------+--------+-------- ClipBox.y2
 //        |        |
 //  0100  |  0000  | 0001
 //        |        |
 // -------+--------+-------- ClipBox.y1
 //        |        |
 //  1100  |  1000  | 1001
 //        |        |
 //  ClipBox.x1  ClipBox.x2
 //
 //
 //template<class T>
 public static uint GetClippingFlags(int x, int y, RectI clip_box)
 {
     return((uint)(((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)));
 }
예제 #23
0
        private void M_FaceReader_FrameArrived(object sender, Microsoft.Kinect.Face.FaceFrameArrivedEventArgs e)
        {
            var frameRef = e.FrameReference;

            using (var faceFrame = frameRef.AcquireFrame())
            {
                if (faceFrame != null)
                {
                    //get the Color Region
                    if (faceFrame.FaceFrameResult != null)
                    {
                        m_drawingRegion = faceFrame.FaceFrameResult.FaceBoundingBoxInColorSpace;
                        var faceRegion = new RectI();
                        faceRegion.Top    = Math.Abs(m_drawingRegion.Top - 36);
                        faceRegion.Bottom = Math.Abs(m_drawingRegion.Bottom - 12);
                        faceRegion.Left   = Math.Abs(m_drawingRegion.Left + 26);
                        faceRegion.Right  = Math.Abs(m_drawingRegion.Right - 20);
                        DrawBox(faceRegion);

                        //Take the new region and record ColorFrame Data
                        if (m_timerStarted)
                        {
                            RecordData(faceRegion, faceFrame);
                            lblColorFeeds.Text = "Please be still taking measurements...";
                        }
                        else
                        {
                            lblColorFeeds.Text         = "Face Found, Click the Calculate button to start taking measurements...";
                            btnCalculateRate.IsEnabled = true;
                        }
                    }
                }
            }
        }
예제 #24
0
 public bool Contains(RectI rect)
 {
     return
         (Contains(rect.TopLeft) &&
          Contains(rect.TopRight) &&
          Contains(rect.BottomLeft) &&
          Contains(rect.BottomRight));
 }
예제 #25
0
 private bool Contains(RectI bounds, Vector2I roomLocation, Room room)
 {
     return
         (bounds.Contains(roomLocation.X, roomLocation.Y) &&
          bounds.Contains(roomLocation.X + room.Columns - 1, roomLocation.Y) &&
          bounds.Contains(roomLocation.X + room.Columns - 1, roomLocation.Y + room.Rows - 1) &&
          bounds.Contains(roomLocation.X, roomLocation.Y + room.Rows - 1));
 }
예제 #26
0
        /// <summary>
        /// Draws the specified <see cref="CatalogManager.Catalog"/> tile to the <see
        /// cref="PaintBuffer"/>, with alpha blending and color substitution.</summary>
        /// <param name="dest">
        /// The location within the <see cref="PaintBuffer"/> where to draw.</param>
        /// <param name="region">
        /// The bitmap region within the <see cref="CatalogManager.Catalog"/> to copy, relative to
        /// the tile with the specified <paramref name="index"/>.</param>
        /// <param name="index">
        /// The <see cref="CatalogManager.Catalog"/> index of the tile to draw.</param>
        /// <param name="color">
        /// The <see cref="Color"/> whose color channels are substituted for those of all <see
        /// cref="CatalogManager.Catalog"/> pixels, retaining only their alpha channel.</param>

        private void DrawTile(PointI dest, RectI region, int index, Color color)
        {
            // add upper-left corner of catalog tile
            region = region.Offset(MapView.GetTileLocation(index));

            // copy visible part of catalog tile to buffer
            PaintBuffer.Overlay(dest.X, dest.Y, MapView.Catalog, region, color);
        }
예제 #27
0
        //-------------------------------------------------------ClipLineSegment
        // 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 uint ClipLineSegment(ref int x1, ref int y1, ref int x2, ref int y2,
                                           RectI clip_box)
        {
            uint f1  = GetClippingFlags(x1, y1, clip_box);
            uint f2  = GetClippingFlags(x2, y2, clip_box);
            uint ret = 0;

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

            if ((f1 & (uint)ClippingFlags.xClipped) != 0 &&
                (f1 & (uint)ClippingFlags.xClipped) == (f2 & (uint)ClippingFlags.xClipped))
            {
                // Fully clipped
                return(4);
            }

            if ((f1 & (uint)ClippingFlags.yClipped) != 0 &&
                (f1 & (uint)ClippingFlags.yClipped) == (f2 & (uint)ClippingFlags.yClipped))
            {
                // Fully clipped
                return(4);
            }

            int tx1 = x1;
            int ty1 = y1;
            int tx2 = x2;
            int ty2 = y2;

            if (f1 != 0)
            {
                if (!ClipMovePoint(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 (!ClipMovePoint(tx1, ty1, tx2, ty2, clip_box, ref x2, ref y2, f2))
                {
                    return(4);
                }
                if (x1 == x2 && y1 == y2)
                {
                    return(4);
                }
                ret |= 2;
            }
            return(ret);
        }
예제 #28
0
        /// <summary>
        /// Draws all decoration except arrows on all map sites in the specified region.</summary>
        /// <param name="context">
        /// The <see cref="DrawingContext"/> for the drawing.</param>
        /// <param name="siteRegion">
        /// The map region containing the coordinates of every <see cref="Site"/> to decorate.
        /// </param>
        /// <remarks>
        /// <b>DrawDecoration</b> draws grid outlines, selection highlights, owner shading, unit
        /// flags, resource gauges, and variable values on every <see cref="Site"/> within the
        /// specified <paramref name="siteRegion"/>, as appropriate.</remarks>

        private void DrawDecoration(DrawingContext context, RectI siteRegion)
        {
            var sites    = MapView.WorldState.Sites;
            var geometry = MapView.ElementGeometry;

            // traverse all specified sites
            for (int x = siteRegion.Left; x < siteRegion.Right; x++)
            {
                for (int y = siteRegion.Top; y < siteRegion.Bottom; y++)
                {
                    Site site = sites[x, y];

                    // shift origin to center of current site
                    PointD pixel = MapView.SiteToView(site.Location);
                    context.PushTransform(new TranslateTransform(pixel.X, pixel.Y));

                    // brighten polygon in selected region
                    if (MapView.SelectedRegion != null && MapView.SelectedRegion[x, y])
                    {
                        context.DrawGeometry(MediaObjects.ShadeLightBrush, null, geometry);
                    }

                    // tint polygon with owner color
                    if (MapView.ShowOwner)
                    {
                        Color color = (site.Owner == null ? Colors.Black : site.Owner.Color);
                        context.DrawGeometry(MediaObjects.GetShadeBrush(color), null, geometry);
                    }

                    // draw unit flag near unit stack
                    if (MapView.ShowFlags)
                    {
                        UnitDecorator.DrawFlag(context, site);
                    }

                    // draw resource gauge below unit stack
                    if (MapView.GaugeResource != null)
                    {
                        UnitDecorator.DrawGauge(context, site);
                    }

                    // draw variable values as numbers or shades
                    if (MapView.ShownVariable != null && MapView.ShownVariableFlags != 0)
                    {
                        VariableDrawer.Draw(context, site);
                    }

                    // reset transformation matrix
                    context.Pop();
                }
            }

            // draw polygon outlines for entire grid
            if (!this._bitmapGrid && MapView.ShowGrid)
            {
                context.DrawGeometry(null, MediaObjects.ThickPen, MapView.GridGeometry);
            }
        }
예제 #29
0
    public RectI Union(RectI other)
    {
        int minX = (MinX < other.MinX) ? MinX : other.MinX,
            minY = (MinY < other.MinY) ? MinY : other.MinY,
            maxX = (MaxX < other.MaxX) ? MaxX : other.MaxX,
            maxY = (MaxY < other.MaxY) ? MaxY : other.MaxY;

        return(new RectI(minX, minY, maxX - minX + 1, maxY - minY + 1));
    }
예제 #30
0
    /// <summary>
    /// Copies the specified region from memory into the current bitmap.
    /// </summary>
    /// <param name="destinationRect">In the current bitmap, the rectangle to which the region specified by srcRect is copied.</param>
    /// <param name="data">The data to copy.</param>
    /// <param name="pitch">The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory).</param>
    /// <returns>The result of the operation.</returns>
    public Result CopyFromMemory(RectI destinationRect, byte[] data, int pitch)
    {
        RawRect dstRect = destinationRect;

        fixed(byte *dataPtr = data)
        {
            return(CopyFromMemory(&dstRect, dataPtr, pitch));
        }
    }
예제 #31
0
 public void Fill(RectI bounds, Tile tile)
 {
     for (var row = bounds.Top; row <= bounds.Bottom; row++)
     {
         for (var column = bounds.Left; column <= bounds.Right; column++)
         {
             this[row, column] = tile;
         }
     }
 }
예제 #32
0
        //-------------------------------------------------------ClipLiangbarsky
        //template<class T>
        public static uint ClipLiangbarsky(int x1, int y1, int x2, int y2,
            RectI clip_box,
            int[] x, int[] y)
        {
            uint XIndex = 0;
            uint 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;
            uint 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;
        }
예제 #33
0
 //----------------------------------------------------------GetClippingFlags
 // Determine the clipping code of the Vertex according to the
 // Cyrus-Beck Line clipping algorithm
 //
 //        |        |
 //  0110  |  0010  | 0011
 //        |        |
 // -------+--------+-------- ClipBox.y2
 //        |        |
 //  0100  |  0000  | 0001
 //        |        |
 // -------+--------+-------- ClipBox.y1
 //        |        |
 //  1100  |  1000  | 1001
 //        |        |
 //  ClipBox.x1  ClipBox.x2
 //
 //
 //template<class T>
 public static uint GetClippingFlags(int x, int y, RectI clip_box)
 {
     return (uint)(((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));
 }
예제 #34
0
 //--------------------------------------------------------ClippingFlagsY
 //template<class T>
 public static uint ClippingFlagsY(int y, RectI clip_box)
 {
     return (uint)(((y > clip_box.y2 ? 1 : 0) << 1) | ((y < clip_box.y1 ? 1 : 0) << 3));
 }
예제 #35
0
 public override void Attach(IPixelFormat ren)
 {
     base.Attach(ren);
     m_clip_box = new RectI(0, 0, (int)ren.Width - 1, (int)ren.Height - 1);
 }
예제 #36
0
        public void CopyFrom(RasterBuffer src,
					   RectI rect_src_ptr,
					   int dx,
					   int dy)
        {
            RectI rsrc = new RectI(rect_src_ptr.x1, rect_src_ptr.y1, rect_src_ptr.x2 + 1, rect_src_ptr.y2 + 1);

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

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

            RectI rc = ClipRectangleArea(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;
                }
                while (rc.y2 > 0)
                {
                    base.CopyFrom(src,
                                     rdst.x1, rdst.y1,
                                     rsrc.x1, rsrc.y1,
                                     (uint)rc.x2);
                    rdst.y1 += incy;
                    rsrc.y1 += incy;
                    --rc.y2;
                }
            }
        }
예제 #37
0
		/// <summary>
		/// Create a new rectangle, inflated by <paramref name="x"/> and <paramref name="y"/>.
		/// </summary>
		public RectI Inflate(int x, int y)
		{
			var newRect = new RectI(this);
			newRect.Left -= x;
			newRect.Right += x;
			newRect.Top -= y;
			newRect.Bottom += y;
			return newRect;
		}
예제 #38
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(RectI other)
 {
     return
         !(this.Y <= other.Bottom ||
         this.X >= other.Right ||
         this.Bottom >= other.Y ||
         this.Right <= other.X);
 }
예제 #39
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(RectI other)
 {
     return
         this.Y >= other.Y &&
         this.X <= other.X &&
         this.Bottom <= other.Bottom &&
         this.Right >= other.Right;
 }
예제 #40
0
		public bool Contains(RectI rect)
		{
			return
				Contains(rect.TopLeft) &&
				Contains(rect.TopRight) &&
				Contains(rect.BottomLeft) &&
				Contains(rect.BottomRight);
		}
예제 #41
0
		public void AddObjectToMotionMap( MapObject obj )
		{
			if( !initialized )
				return;

			OnGetMotionMapRectanglesForObject( obj, tempRectangles );

			if( tempRectangles.Count != 0 )
			{
				RectI[] rectangles = new RectI[ tempRectangles.Count ];

				for( int nRectangle = 0; nRectangle < tempRectangles.Count; nRectangle++ )
				{
					Rect rectangle = tempRectangles[ nRectangle ];
					RectI mapMotionRectangle = GetMapMotionRectangle( rectangle );

					for( int y = mapMotionRectangle.Top; y <= mapMotionRectangle.Bottom; y++ )
						for( int x = mapMotionRectangle.Left; x <= mapMotionRectangle.Right; x++ )
							mapMotion[ x, y ]++;

					rectangles[ nRectangle ] = mapMotionRectangle;
				}

				mapMotionRectangles.Add( obj, rectangles );

				tempRectangles.Clear();
			}
		}
예제 #42
0
 //--------------------------------------------------------------------
 public FormatClippingProxy(IPixelFormat ren)
     : base(ren)
 {
     m_clip_box = new RectI(0, 0, (int)ren.Width - 1, (int)ren.Height - 1);
 }
예제 #43
0
        //-------------------------------------------------------ClipLineSegment
        // 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 uint ClipLineSegment(ref int x1, ref int y1, ref int x2, ref int y2,
            RectI clip_box)
        {
            uint f1 = GetClippingFlags(x1, y1, clip_box);
            uint f2 = GetClippingFlags(x2, y2, clip_box);
            uint ret = 0;

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

            if ((f1 & (uint)ClippingFlags.xClipped) != 0 &&
               (f1 & (uint)ClippingFlags.xClipped) == (f2 & (uint)ClippingFlags.xClipped))
            {
                // Fully clipped
                return 4;
            }

            if ((f1 & (uint)ClippingFlags.yClipped) != 0 &&
               (f1 & (uint)ClippingFlags.yClipped) == (f2 & (uint)ClippingFlags.yClipped))
            {
                // Fully clipped
                return 4;
            }

            int tx1 = x1;
            int ty1 = y1;
            int tx2 = x2;
            int ty2 = y2;
            if(f1 != 0)
            {
                if(!ClipMovePoint(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(!ClipMovePoint(tx1, ty1, tx2, ty2, clip_box, ref x2, ref y2, f2))
                {
                    return 4;
                }
                if(x1 == x2 && y1 == y2)
                {
                    return 4;
                }
                ret |= 2;
            }
            return ret;
        }
예제 #44
0
        public RectI ClipRectangleArea(ref RectI dst, ref RectI src, int wsrc, int hsrc)
        {
            RectI rc = new RectI(0, 0, 0, 0);
            RectI cb = ClipBox;
            ++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;
        }
예제 #45
0
        //----------------------------------------------------------------------------
        //template<class T>
        public static bool ClipMovePoint(int x1, int y1, int x2, int y2, 
            RectI clip_box,
            ref int x, ref int y, uint flags)
        {
            int bound;

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

               flags = ClippingFlagsY(y, clip_box);
               if ((flags & (uint)ClippingFlags.yClipped) != 0)
               {
               if(y1 == y2)
               {
                   return false;
               }
               bound = ((flags & (uint)ClippingFlags.x1Clipped) != 0) ? clip_box.y1 : clip_box.y2;
               x = (int)((double)(bound - y1) * (x2 - x1) / (y2 - y1) + x1);
               y = bound;
               }
               return true;
        }
예제 #46
0
 //--------------------------------------------------------------------
 //public IPixelFormat ren() { return m_ren; }
 //--------------------------------------------------------------------
 public bool SetClippingBox(int x1, int y1, int x2, int y2)
 {
     RectI cb = new RectI(x1, y1, x2, y2);
     cb.Normalize();
     if (cb.Clip(new RectI(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;
 }
예제 #47
0
 //--------------------------------------------------------ClippingFlagsX
 //template<class T>
 public static uint ClippingFlagsX(int x, RectI clip_box)
 {
     return (uint)((x > clip_box.x2 ? 1 : 0) | ((x < clip_box.x1 ? 1 : 0) << 2));
 }
        protected override void OnUpdateRenderLightmap( out bool finished )
        {
            finished = false;

            //render bucket
            {
                //DoLogEvent( string.Format( "Render bucket {0},{1}", lightmapBucketIndex.X,
                //   lightmapBucketIndex.Y ) );

                RectI bucketRectangle = new RectI( lightmapBucketIndex * bucketSize,
                    ( lightmapBucketIndex + new Vec2I( 1, 1 ) ) * bucketSize );

                if( bucketRectangle.Right > lightmapRenderingImage.Size.X )
                    bucketRectangle.Right = lightmapRenderingImage.Size.X;
                if( bucketRectangle.Bottom > lightmapRenderingImage.Size.Y )
                    bucketRectangle.Bottom = lightmapRenderingImage.Size.Y;

                lightmapRenderingImage.Fill( bucketRectangle, new ColorValue( 1, 1, 0 ) );

                ColorValue[] colors = new ColorValue[ bucketRectangle.Size.X * bucketRectangle.Size.Y ];

                for( int y = bucketRectangle.Minimum.Y; y < bucketRectangle.Maximum.Y; y++ )
                {
                    for( int x = bucketRectangle.Minimum.X; x < bucketRectangle.Maximum.X; x++ )
                    {
                        Vec2I pixelIndex = new Vec2I( x, y );

                        ColorValue color = RenderPixel( pixelIndex );

                        Vec2I colorIndex = pixelIndex - bucketRectangle.Minimum;
                        colors[ colorIndex.Y * bucketRectangle.Size.X + colorIndex.X ] = color;
                    }
                }

                lightmapRenderingImage.Fill( bucketRectangle, colors );
            }

            //change bucket
            {
                Vec2I bucketCount = lightmapRenderingImage.Size / bucketSize;
                if( lightmapRenderingImage.Size.X % bucketSize != 0 )
                    bucketCount.X++;
                if( lightmapRenderingImage.Size.Y % bucketSize != 0 )
                    bucketCount.Y++;

                lightmapBucketIndex.X++;
                if( lightmapBucketIndex.X >= bucketCount.X )
                {
                    lightmapBucketIndex.X = 0;
                    lightmapBucketIndex.Y++;
                    if( lightmapBucketIndex.Y >= bucketCount.Y )
                        finished = true;
                }
            }

            //image finished. do final operations.
            if( finished )
            {
                lightmapRenderingImage.FillHoles( 5 );
                lightmapRenderingImage.Finish();
            }
        }
예제 #49
0
파일: RGB.cs 프로젝트: GeroL/MOSA-Project
 ///<summary>
 ///</summary>
 ///<param name="pixf"></param>
 ///<param name="x1"></param>
 ///<param name="y1"></param>
 ///<param name="x2"></param>
 ///<param name="y2"></param>
 ///<returns></returns>
 public bool Attach(IPixelFormat pixf, int x1, int y1, int x2, int y2)
 {
     RectI r = new RectI(x1, y1, x2, y2);
     if (r.Clip(new RectI(0, 0, (int)pixf.Width - 1, (int)pixf.Height - 1)))
     {
         int stride = pixf.Stride;
         unsafe
         {
             _rasterBuffer.Attach(pixf.PixelPointer(r.x1, stride < 0 ? r.y2 : r.y1),
                 (uint)(r.x2 - r.x1) + 1,
                 (uint)(r.y2 - r.y1) + 1,
                 stride, 3);
         }
         return true;
     }
     return false;
 }