Ejemplo n.º 1
0
        private void SetWindowIcon(IEnumerable <Image <Rgba32> > icons)
        {
            // Turn each image into a byte[] so we can actually pin their contents.
            // Wish I knew a clean way to do this without allocations.
            var images = icons
                         .Select(i => (MemoryMarshal.Cast <Rgba32, byte>(i.GetPixelSpan()).ToArray(), i.Width, i.Height))
                         .ToList();

            Span <GCHandle>  handles    = stackalloc GCHandle[images.Count];
            Span <GlfwImage> glfwImages = new GlfwImage[images.Count];

            for (var i = 0; i < images.Count; i++)
            {
                var image = images[i];
                handles[i] = GCHandle.Alloc(image.Item1, GCHandleType.Pinned);
                var addrOfPinnedObject = (byte *)handles[i].AddrOfPinnedObject();
                glfwImages[i] = new GlfwImage(image.Width, image.Height, addrOfPinnedObject);
            }

            GLFW.SetWindowIcon(_glfwWindow, glfwImages);

            foreach (var handle in handles)
            {
                handle.Free();
            }
        }
Ejemplo n.º 2
0
            public void LoadWindowIcon(Window *window)
            {
                var icons = _clyde.LoadWindowIcons().ToArray();

                // Turn each image into a byte[] so we can actually pin their contents.
                // Wish I knew a clean way to do this without allocations.
                var images = icons
                             .Select(i => (MemoryMarshal.Cast <Rgba32, byte>(i.GetPixelSpan()).ToArray(), i.Width, i.Height))
                             .ToList();

                // ReSharper disable once SuggestVarOrType_Elsewhere
                Span <GCHandle>  handles    = stackalloc GCHandle[images.Count];
                Span <GlfwImage> glfwImages = stackalloc GlfwImage[images.Count];

                for (var i = 0; i < images.Count; i++)
                {
                    var image = images[i];
                    handles[i] = GCHandle.Alloc(image.Item1, GCHandleType.Pinned);
                    var addrOfPinnedObject = (byte *)handles[i].AddrOfPinnedObject();
                    glfwImages[i] = new GlfwImage(image.Width, image.Height, addrOfPinnedObject);
                }

                GLFW.SetWindowIcon(window, glfwImages);

                foreach (var handle in handles)
                {
                    handle.Free();
                }
            }
Ejemplo n.º 3
0
        public unsafe ICursor CreateCursor(Image <Rgba32> image, Vector2i hotSpot)
        {
            fixed(Rgba32 *pixPtr = image.GetPixelSpan())
            {
                var gImg = new GlfwImage(image.Width, image.Height, (byte *)pixPtr);

                var(hotX, hotY) = hotSpot;
                var ptr = GLFW.CreateCursor(gImg, hotX, hotY);

                return(new CursorImpl(this, ptr, false));
            }
        }