Skip to content

Commit a6da98b

Browse files
author
Timothee 'TTimo' Besset
committed
Simplify windows icon setup, with workarounds from py-sdl/py-sdl2#275
1 parent 3f075d2 commit a6da98b

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

client/devkit_client/gui2/gui2.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -3099,19 +3099,15 @@ def _create_gl_window(self, best_settings=True):
30993099
depth = tga[16]
31003100
assert depth == 32 # RGBA
31013101

3102-
# param order is red, green, blue, alpha masks. swizzle away
3103-
tga_surface = sdl2.SDL_CreateRGBSurface(0, w, h, depth, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000)
3104-
assert tga_surface.contents.format.contents.format == sdl2.SDL_PIXELFORMAT_ARGB8888
3105-
3106-
# smash the pixels in
3107-
pixies = ctypes.cast(tga_surface.contents.pixels, ctypes.POINTER(ctypes.c_byte))
3108-
i = 0
3109-
while i < w*h*4:
3110-
pixies[i] = tga[18+i]
3111-
i += 1
3112-
3113-
sdl2.SDL_SetWindowIcon(self.sdl_window, tga_surface)
3114-
sdl2.SDL_FreeSurface(tga_surface)
3102+
# Workaround for https://github.com/py-sdl/py-sdl2/issues/275
3103+
# SDL_CreateRGBSurfaceWithFormatFrom silently failing when passed a sub-array
3104+
pixels=tga[18:18+w*h*4]
3105+
icon = sdl2.SDL_CreateRGBSurfaceWithFormatFrom(pixels, w, h, 32, w*4, sdl2.SDL_PIXELFORMAT_ARGB8888)
3106+
assert icon is not None
3107+
assert icon.contents.format.contents.format == sdl2.SDL_PIXELFORMAT_ARGB8888
3108+
3109+
sdl2.SDL_SetWindowIcon(self.sdl_window, icon)
3110+
sdl2.SDL_FreeSurface(icon)
31153111

31163112
self.gl_context = sdl2.SDL_GL_CreateContext(self.sdl_window)
31173113
if self.gl_context is None:

0 commit comments

Comments
 (0)