Ejemplo n.º 1
0
        public void CanReadAniCursors()
        {
            InstalledFilesTestData.ReadFiles(".ani", _output, entry =>
            {
                switch (entry.FilePath)
                {
                // BFME cursors - don't know how to parse them yet.
                case @"data\cursors\Beam.ani":
                case @"data\cursors\magnify.ani":
                case @"data\cursors\sccmagic.ani":
                    return;
                }

                var aniFile = AniFile.FromFileSystemEntry(entry);

                Assert.NotNull(aniFile);

                Assert.True(aniFile.ArtistName == null || aniFile.ArtistName == "PRobb");
            });
        }
Ejemplo n.º 2
0
        public unsafe Cursor(FileSystemEntry entry, GameWindow window)
        {
            _aniFile = AniFile.FromFileSystemEntry(entry);

            var width  = (int)_aniFile.IconWidth;
            var height = (int)_aniFile.IconHeight;

            _surfaces = new Sdl2Interop.SDL_Surface[_aniFile.Images.Length];
            _cursors  = new Sdl2Interop.SDL_Cursor[_aniFile.Images.Length];

            var windowScale = window.WindowScale;

            for (var i = 0; i < _aniFile.Images.Length; i++)
            {
                var pixels = _aniFile.Images[i].PixelsBgra;

                fixed(byte *pixelsPtr = pixels)
                {
                    var surface = Sdl2Interop.SDL_CreateRGBSurfaceWithFormatFrom(
                        pixelsPtr,
                        width,
                        height,
                        32,
                        width * 4,
                        Sdl2Interop.SDL_PixelFormat.SDL_PIXELFORMAT_ABGR8888);

                    if (windowScale != 1.0f)
                    {
                        var scaledWidth  = (int)(windowScale * width);
                        var scaledHeight = (int)(windowScale * height);

                        var scaledSurface = Sdl2Interop.SDL_CreateRGBSurfaceWithFormat(
                            0,
                            scaledWidth,
                            scaledHeight,
                            32,
                            Sdl2Interop.SDL_PixelFormat.SDL_PIXELFORMAT_ABGR8888);

                        Sdl2Interop.SDL_BlitScaled(
                            surface,
                            new Sdl2Interop.SDL_Rect(0, 0, width, height),
                            scaledSurface,
                            new Sdl2Interop.SDL_Rect(0, 0, scaledWidth, scaledHeight));

                        Sdl2Interop.SDL_FreeSurface(surface);

                        surface = scaledSurface;
                    }

                    AddDisposeAction(() => Sdl2Interop.SDL_FreeSurface(surface));

                    _surfaces[i] = surface;
                }

                var cursor = Sdl2Interop.SDL_CreateColorCursor(
                    _surfaces[i],
                    (int)_aniFile.HotspotX,
                    (int)_aniFile.HotspotY);

                AddDisposeAction(() => Sdl2Interop.SDL_FreeCursor(cursor));

                _cursors[i] = cursor;
            }
        }