Ejemplo n.º 1
0
        internal static ResizedFrame GetResizedFrame(Frame frame, Size renderSize)
        {
            var          settings = EngineConfiguration.Open().Settings;
            ResizedFrame resizedFrame;

            if (ResizedFrameCache.TryGetValue(GetId(frame, renderSize), out resizedFrame) == false)
            {
                resizedFrame = new ResizedFrame(frame, renderSize);

                // check cache limit; if over, trim cache
                while (ResizedFrameCache.Count > settings.ResizedFrameCacheLimit)
                {
                    var oldestInCache   = ResizedFrameCache.OrderBy(kvp => kvp.Value.CreationTick).First();
                    var oldResizedFrame = oldestInCache.Value;
                    ResizedFrameCache.Remove(oldestInCache.Key);
                    oldResizedFrame.Dispose();
                }
            }

            return(resizedFrame);
        }
Ejemplo n.º 2
0
        private void DrawTile(Tile tile, ref IntPtr hDC)
        {
            Rectangle tileLoc = tile.DrawLocation;

            // redraw each "refresh area"
            foreach (Rectangle refreshRect in tile.DrawLocationRefresh)
            {
                // clip the DrawLocationRefresh to Backbuffer if necessary
                Rectangle tempRefreshLoc = Rectangle.Intersect(refreshRect, range);

                // if the Tile is outside the range, has no Tilesheet, or is not visible, return without blitting
                if ((tempRefreshLoc.IsEmpty) || (tile.CurrentFrame.Tilesheet == null) || (tile.Visible == false))
                {
                    return;
                }

                // check if source Frame needs to be resized
                ResizedFrame resizedFrame = null;
                if (tileLoc.Size != tile.CurrentFrame.Tilesheet.TileSize)
                {
                    resizedFrame = ResizedFrame.GetResizedFrame(tile.CurrentFrame, tileLoc.Size);
                }

                // get source refresh range, hDC, and related mask hdc
                Rectangle _srcRefreshRange;
                IntPtr    _srcHDCMask;
                IntPtr    _srcHDC;

                if (resizedFrame == null)
                {
                    // get the source Rectangle being rendered and Graphics / DC handles from the Tilesheet object
                    _srcRefreshRange = tile.CurrentFrame.Tilesheet.GetSourceRange(tile.CurrentFrame.XTile, tile.CurrentFrame.YTile);
                    _srcHDC          = tile.CurrentFrame.Tilesheet.hDC;

                    if (tile.CurrentFrame.Tilesheet.Mask != null)
                    {
                        _srcHDCMask = tile.CurrentFrame.Tilesheet.Mask.hDC;
                    }
                    else
                    {
                        _srcHDCMask = default(IntPtr);
                    }
                }
                else
                {
                    // get the source Rectangle being rendered and Graphics / DC handles from the ResizedFrame object
                    _srcRefreshRange = new Rectangle(new Point(0, 0), resizedFrame.RenderSize);
                    _srcHDCMask      = resizedFrame.hDCMask;
                    _srcHDC          = resizedFrame.hDC;
                }

                // if only refreshing part of the Tile...
                if (tileLoc.Size != tempRefreshLoc.Size)
                {
                    // capture just the section of the source Tilesheet that needs to be refreshed on Backbuffer
                    _srcRefreshRange = GetSourceBmpRangeForRefresh(_srcRefreshRange, tempRefreshLoc, tileLoc);
                }

                // if the Tilesheet has a mask...
                if (tile.CurrentFrame.Tilesheet.Mask != null)
                {
                    // AND the mask
                    Win32Support.DrawBitmap(hDC, tempRefreshLoc,
                                            _srcHDCMask, _srcRefreshRange,
                                            TernaryRasterOperations.SRCAND);

                    // PAINT the primary
                    Win32Support.DrawBitmap(hDC, tempRefreshLoc,
                                            _srcHDC, _srcRefreshRange,
                                            TernaryRasterOperations.SRCPAINT);
                }
                else
                {
                    // use the specified Tile.RasterOp
                    Win32Support.DrawBitmap(hDC, tempRefreshLoc,
                                            _srcHDC, _srcRefreshRange, tile.RasterOp);
                }
            }
        }
Ejemplo n.º 3
0
        internal static ResizedFrame GetResizedFrame(Frame frame, Size renderSize)
        {
            var settings = EngineConfiguration.Open().Settings;
            ResizedFrame resizedFrame;

            if (ResizedFrameCache.TryGetValue(GetId(frame, renderSize), out resizedFrame) == false)
            {
                resizedFrame = new ResizedFrame(frame, renderSize);

                // check cache limit; if over, trim cache
                while (ResizedFrameCache.Count > settings.ResizedFrameCacheLimit)
                {
                    var oldestInCache = ResizedFrameCache.OrderBy(kvp => kvp.Value.CreationTick).First();
                    var oldResizedFrame = oldestInCache.Value;
                    ResizedFrameCache.Remove(oldestInCache.Key);
                    oldResizedFrame.Dispose();
                }
            }

            return resizedFrame;
        }