def _set_icon(self): """Set the icon on the SDL window.""" mask = numpy.array(self.icon).T.repeat(2, 0).repeat(2, 1) icon = sdl2.SDL_CreateRGBSurface(0, mask.shape[0], mask.shape[1], 8, 0, 0, 0, 0) pixels2d(icon.contents)[:] = mask # icon palette (black & white) icon_palette = sdl2.SDL_AllocPalette(256) icon_colors = [ sdl2.SDL_Color(x, x, x, 255) for x in [0, 255] + [255]*254 ] sdl2.SDL_SetPaletteColors(icon_palette, (sdl2.SDL_Color * 256)(*icon_colors), 0, 2) sdl2.SDL_SetSurfacePalette(icon, icon_palette) sdl2.SDL_SetWindowIcon(self.display, icon) sdl2.SDL_FreeSurface(icon) sdl2.SDL_FreePalette(icon_palette)
def set_window_icon(icon: PathLike, bytes_per_pixel: int = 4): """ Lets you set a custom window icon for pyxel. you can call this after pyxel.init """ if not has_pil: RuntimeWarning('You need Pillow/PIL in order to use pyxelext.system.set_window_icon') return current_window = sdl2.SDL_GL_GetCurrentWindow() img = Image.open(icon) x, y = img.size rmask = 0x000000ff gmask = 0x0000ff00 bmask = 0x00ff0000 amask = 0 if bytes_per_pixel == 3 else 0xff000000 icon_surface = sdl2.SDL_CreateRGBSurfaceFrom(img.tobytes(), x, y, bytes_per_pixel*8, bytes_per_pixel*x, rmask, gmask, bmask, amask) sdl2.SDL_SetWindowIcon(current_window, icon_surface) sdl2.SDL_FreeSurface(icon_surface)
def _set_icon(self, icon_path: str) -> None: sdl2.SDL_SetWindowIcon(self._window, sdl2.ext.load_image(icon_path))