Пример #1
0
        public void DrawRegions(WorldRenderer wr, IInputHandler inputHandler)
        {
            renderer.BeginFrame(scrollPosition, Zoom);
            if (wr != null)
            {
                wr.Draw();
            }

            using (new PerfSample("render_widgets"))
            {
                Widget.DoDraw();
                var cursorName     = Widget.RootWidget.GetCursorOuter(Viewport.LastMousePos) ?? "default";
                var cursorSequence = CursorProvider.GetCursorSequence(cursorName);
                var cursorSprite   = cursorSequence.GetSprite((int)cursorFrame);

                renderer.SpriteRenderer.DrawSprite(cursorSprite,
                                                   Viewport.LastMousePos - cursorSequence.Hotspot,
                                                   Game.modData.Palette.GetPaletteIndex(cursorSequence.Palette),
                                                   cursorSprite.size);
            }

            using (new PerfSample("render_flip"))
            {
                renderer.EndFrame(inputHandler);
            }
        }
Пример #2
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();
        }
Пример #3
0
		public void InitializeLoaders()
		{
			// all this manipulation of static crap here is nasty and breaks
			// horribly when you use ModData in unexpected ways.
			ChromeMetrics.Initialize(Manifest.ChromeMetrics);
			ChromeProvider.Initialize(Manifest.Chrome);
			VoxelLoader = new VoxelLoader();

			CursorProvider = new CursorProvider(this);
		}
Пример #4
0
        public CursorManager(CursorProvider cursorProvider)
        {
            hardwareCursorsDisabled = Game.Settings.Graphics.DisableHardwareCursors;

            graphicSettings = Game.Settings.Graphics;
            sheetBuilder    = new SheetBuilder(SheetType.BGRA);
            foreach (var kv in cursorProvider.Cursors)
            {
                var frames  = kv.Value.Frames;
                var palette = !string.IsNullOrEmpty(kv.Value.Palette) ? cursorProvider.Palettes[kv.Value.Palette] : null;

                var c = new Cursor
                {
                    Name   = kv.Key,
                    Bounds = Rectangle.FromLTRB(0, 0, 1, 1),

                    Length  = 0,
                    Sprites = new Sprite[frames.Length],
                    Cursors = new IHardwareCursor[frames.Length]
                };

                // 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)
                foreach (var f in frames)
                {
                    // Hotspot is specified relative to the center of the frame
                    var hotspot = f.Offset.ToInt2() - kv.Value.Hotspot - new int2(f.Size) / 2;

                    // SheetBuilder expects data in BGRA
                    var data = FrameToBGRA(kv.Key, f, palette);
                    c.Sprites[c.Length++] = sheetBuilder.Add(data, f.Size, 0, hotspot);

                    // Bounds relative to the hotspot
                    c.Bounds = Rectangle.Union(c.Bounds, new Rectangle(hotspot, f.Size));
                }

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

                cursors.Add(kv.Key, c);
            }

            CreateOrUpdateHardwareCursors();

            foreach (var s in sheetBuilder.AllSheets)
            {
                s.ReleaseBuffer();
            }

            Update();
        }
Пример #5
0
        public HardwareCursor(CursorProvider cursorProvider)
        {
            this.cursorProvider = cursorProvider;

            foreach (var kv in cursorProvider.Cursors)
            {
                var palette = cursorProvider.Palettes[kv.Value.Palette];
                var hc = kv.Value.Frames
                    .Select(f => CreateCursor(f, palette, kv.Key, kv.Value))
                    .ToArray();

                hardwareCursors.Add(kv.Key, hc);
            }

            Update();
        }
Пример #6
0
        public HardwareCursor(CursorProvider cursorProvider)
        {
            this.cursorProvider = cursorProvider;

            foreach (var kv in cursorProvider.Cursors)
            {
                var palette = cursorProvider.Palettes[kv.Value.Palette];
                var hc      = kv.Value.Frames
                              .Select(f => CreateCursor(f, palette, kv.Key, kv.Value))
                              .ToArray();

                hardwareCursors.Add(kv.Key, hc);
            }

            Update();
        }
Пример #7
0
        public void DrawRegions(WorldRenderer wr, IInputHandler inputHandler)
        {
            renderer.BeginFrame(scrollPosition, Zoom);
            if (wr != null)
            {
                wr.Draw();
            }

            using (new PerfSample("render_widgets"))
            {
                Ui.Draw();
                var cursorName = Ui.Root.GetCursorOuter(Viewport.LastMousePos) ?? "default";
                CursorProvider.DrawCursor(renderer, cursorName, Viewport.LastMousePos, (int)cursorFrame);
            }

            using (new PerfSample("render_flip"))
            {
                renderer.EndFrame(inputHandler);
            }
        }
Пример #8
0
        public SoftwareCursor(CursorProvider cursorProvider)
        {
            this.cursorProvider = cursorProvider;

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

            palette.Initialize();

            sheetBuilder = new SheetBuilder(SheetType.Indexed);
            foreach (var kv in cursorProvider.Cursors)
            {
                var s = kv.Value.Frames.Select(a => sheetBuilder.Add(a)).ToArray();
                sprites.Add(kv.Key, s);
            }

            sheetBuilder.Current.ReleaseBuffer();

            Game.Renderer.Device.SetHardwareCursor(null);
        }
Пример #9
0
        public SoftwareCursor(CursorProvider cursorProvider)
        {
            this.cursorProvider = cursorProvider;

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

            palette.Initialize();

            sheetBuilder = new SheetBuilder(SheetType.Indexed);
            foreach (var kv in cursorProvider.Cursors)
            {
                var s = kv.Value.Frames.Select(a => sheetBuilder.Add(a)).ToArray();
                sprites.Add(kv.Key, s);
            }

            sheetBuilder.Current.ReleaseBuffer();

            Game.Renderer.Window.SetHardwareCursor(null);
        }