Exemplo n.º 1
0
        public HardwareCursor(CursorProvider cursorProvider)
        {
            this.cursorProvider = cursorProvider;

            paletteReferences = new Cache <string, PaletteReference>(CreatePaletteReference);
            foreach (var p in cursorProvider.Palettes)
            {
                hardwarePalette.AddPalette(p.Key, p.Value, false);
            }

            hardwarePalette.Initialize();
            sheetBuilder = new SheetBuilder(SheetType.Indexed);
            foreach (var kv in cursorProvider.Cursors)
            {
                var frames  = kv.Value.Frames;
                var palette = cursorProvider.Palettes[kv.Value.Palette];

                // Hardware cursors have a number of odd platform-specific bugs/limitations.
                // Reduce the number of edge cases by padding the individual frames such that:
                // - the hotspot is inside the frame bounds (enforced by SDL)
                // - all frames within a sequence have the same size (needed for macOS 10.15)
                // - the frame size is a multiple of 8 (needed for Windows)
                var sequenceBounds = Rectangle.FromLTRB(0, 0, 1, 1);
                var frameHotspots  = new int2[frames.Length];
                for (var i = 0; i < frames.Length; i++)
                {
                    // Hotspot relative to the center of the frame
                    frameHotspots[i] = kv.Value.Hotspot - frames[i].Offset.ToInt2() + new int2(frames[i].Size) / 2;

                    // Bounds relative to the hotspot
                    sequenceBounds = Rectangle.Union(sequenceBounds, new Rectangle(-frameHotspots[i], frames[i].Size));
                }

                // Pad bottom-right edge to make the frame size a multiple of 8
                var paddedSize = 8 * new int2((sequenceBounds.Width + 7) / 8, (sequenceBounds.Height + 7) / 8);

                var cursors      = new IHardwareCursor[frames.Length];
                var frameSprites = new Sprite[frames.Length];
                for (var i = 0; i < frames.Length; i++)
                {
                    // Software rendering is used when the cursor is locked
                    frameSprites[i] = sheetBuilder.Add(frames[i].Data, frames[i].Size, 0, frames[i].Offset);

                    // Calculate the padding to position the frame within sequenceBounds
                    var paddingTL = -(sequenceBounds.Location + frameHotspots[i]);
                    var paddingBR = paddedSize - new int2(frames[i].Size) - paddingTL;
                    cursors[i] = CreateCursor(kv.Key, frames[i], palette, paddingTL, paddingBR, -sequenceBounds.Location);
                }

                hardwareCursors.Add(kv.Key, cursors);
                sprites.Add(kv.Key, frameSprites);
            }

            sheetBuilder.Current.ReleaseBuffer();

            Update();
        }
Exemplo n.º 2
0
 public void SetHardwareCursor(IHardwareCursor cursor)
 {
     VerifyThreadAffinity();
     if (cursor is Sdl2HardwareCursor c)
     {
         SDL.SDL_ShowCursor((int)SDL.SDL_bool.SDL_TRUE);
         SDL.SDL_SetCursor(c.Cursor);
     }
     else
     {
         SDL.SDL_ShowCursor((int)SDL.SDL_bool.SDL_FALSE);
     }
 }
Exemplo n.º 3
0
        public void SetHardwareCursor(IHardwareCursor cursor)
        {
            var c = cursor as SDL2HardwareCursor;

            if (c == null)
            {
                SDL.SDL_ShowCursor(0);
            }
            else
            {
                SDL.SDL_ShowCursor(1);
                SDL.SDL_SetCursor(c.Cursor);
            }
        }
        public void SetHardwareCursor(IHardwareCursor cursor)
        {
            VerifyThreadAffinity();
            var c = cursor as SDL2HardwareCursor;

            if (c == null)
            {
                SDL.SDL_ShowCursor((int)SDL.SDL_bool.SDL_FALSE);
            }
            else
            {
                SDL.SDL_ShowCursor((int)SDL.SDL_bool.SDL_TRUE);
                SDL.SDL_SetCursor(c.Cursor);
            }
        }
Exemplo n.º 5
0
		public void SetHardwareCursor(IHardwareCursor cursor)
		{
			VerifyThreadAffinity();
			var c = cursor as SDL2HardwareCursor;
			if (c == null)
				SDL.SDL_ShowCursor((int)SDL.SDL_bool.SDL_FALSE);
			else
			{
				SDL.SDL_ShowCursor((int)SDL.SDL_bool.SDL_TRUE);
				SDL.SDL_SetCursor(c.Cursor);
			}
		}
Exemplo n.º 6
0
 public void SetHardwareCursor(IHardwareCursor cursor)
 {
 }
Exemplo n.º 7
0
 public void SetHardwareCursor(IHardwareCursor cursor)
 {
     var c = cursor as SDL2HardwareCursor;
     if (c == null)
         SDL.SDL_ShowCursor(0);
     else
     {
         SDL.SDL_ShowCursor(1);
         SDL.SDL_SetCursor(c.Cursor);
     }
 }