Skip to content

Commit

Permalink
Migrate to latest SDL3 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
misl6 committed Jan 17, 2025
1 parent 2ff82cb commit 5380b27
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 61 deletions.
10 changes: 5 additions & 5 deletions kivy/core/audio_output/audio_sdl3.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ cdef mix_init():
desired_spec.channels = 2
if Mix_OpenAudio(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &desired_spec):
Logger.critical('AudioSDL3: Unable to open mixer: {}'.format(
Mix_GetError()))
SDL_GetError()))
mix_is_init = -1
return 0

Expand Down Expand Up @@ -209,7 +209,7 @@ class SoundSDL3(Sound):
cc.channel = Mix_PlayChannel(-1, cc.chunk, 0)
if cc.channel == -1:
Logger.warning('AudioSDL3: Unable to play {}: {}'.format(
self.source, Mix_GetError()))
self.source, SDL_GetError()))
return
# schedule event to check if the sound is still playing or not
self._check_play_ev = Clock.schedule_interval(self._check_play, 0.1)
Expand Down Expand Up @@ -241,7 +241,7 @@ class SoundSDL3(Sound):
cc.chunk = Mix_LoadWAV(<char *><bytes>fn)
if cc.chunk == NULL:
Logger.warning('AudioSDL3: Unable to load {}: {}'.format(
self.source, Mix_GetError()))
self.source, SDL_GetError()))
else:
cc.original_chunk = Mix_QuickLoad_RAW(cc.chunk.abuf, cc.chunk.alen)
cc.chunk.volume = int(self.volume * 128)
Expand Down Expand Up @@ -322,7 +322,7 @@ class MusicSDL3(Sound):
Mix_VolumeMusic(int(self.volume * 128))
if Mix_PlayMusic(mc.music, 1) == -1:
Logger.warning('AudioSDL3: Unable to play music {}: {}'.format(
self.source, Mix_GetError()))
self.source, SDL_GetError()))
return
mc.playing = 1
# schedule event to check if the sound is still playing or not
Expand Down Expand Up @@ -354,7 +354,7 @@ class MusicSDL3(Sound):
mc.music = Mix_LoadMUS(<char *><bytes>fn)
if mc.music == NULL:
Logger.warning('AudioSDL3: Unable to load music {}: {}'.format(
self.source, Mix_GetError()))
self.source, SDL_GetError()))
else:
Mix_VolumeMusic(int(self.volume * 128))

Expand Down
2 changes: 1 addition & 1 deletion kivy/core/clipboard/_clipboard_sdl3.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include '../../lib/sdl3.pxi'


def _has_text():
return True if SDL_HasClipboardText() == SDL_TRUE else False
return SDL_HasClipboardText()


def _get_text():
Expand Down
10 changes: 7 additions & 3 deletions kivy/core/image/_img_sdl3.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io
from kivy.logger import Logger
from libc.string cimport memset
from libc.stdlib cimport malloc
from cpython cimport bool

cdef int _is_init = 0

Expand All @@ -19,9 +20,10 @@ cdef size_t rwops_bytesio_write(void *userdata, const void *ptr, size_t size, SD
return size * 1


cdef int rwops_bytesio_close(void *userdata) noexcept:
cdef bint rwops_bytesio_close(void *userdata) noexcept:
byteio = <object>(<BytesIODataContainer*>userdata).data
byteio.seek(0)
return True


cdef SDL_IOStream *rwops_bridge_to_bytesio(byteio):
Expand All @@ -34,7 +36,9 @@ cdef SDL_IOStream *rwops_bridge_to_bytesio(byteio):
io_interface.seek = NULL
io_interface.read = NULL
io_interface.write = &rwops_bytesio_write
io_interface.close = &rwops_bytesio_close
# io_interface.close = <bint (*)(void *) noexcept>&rwops_bytesio_close
# FIXME:
io_interface.close = NULL

rwops = SDL_OpenIO(&io_interface, bytesiocontainer)

Expand All @@ -53,7 +57,7 @@ def init():
# FIXME replace flags by a good string
Logger.error(
'ImageSDL3: Failed to init required {} support'.format(flags))
Logger.error('ImageSDL3: {}'.format(IMG_GetError()))
Logger.error('ImageSDL3: {}'.format(SDL_GetError()))

_is_init = 1

Expand Down
20 changes: 10 additions & 10 deletions kivy/core/text/_text_sdl3.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -100,32 +100,32 @@ cdef class _SurfaceContainer:
TTF_SetFontDirection(font, TTF_DIRECTION_BTT)

fontscript = container.options['font_script_name']
TTF_SetFontScriptName(font, fontscript)
TTF_SetFontScript(font, fontscript)

if outline_width:
TTF_SetFontOutline(font, outline_width)
oc.r = <int>(outline_color[0] * 255)
oc.g = <int>(outline_color[1] * 255)
oc.b = <int>(outline_color[2] * 255)
st = (
TTF_RenderUTF8_Blended(font, <char *>bytes_text, oc)
TTF_RenderText_Blended(font, <char *>bytes_text, 0, oc)
if container.options['font_blended']
else TTF_RenderUTF8_Solid(font, <char *>bytes_text, oc)
else TTF_RenderText_Blended(font, <char *>bytes_text, 0, oc)
)
TTF_SetFontOutline(font, 0)
else:
st = (
TTF_RenderUTF8_Blended(font, <char *>bytes_text, c)
TTF_RenderText_Blended(font, <char *>bytes_text, 0, c)
if container.options['font_blended']
else TTF_RenderUTF8_Solid(font, <char *>bytes_text, c)
else TTF_RenderText_Solid(font, <char *>bytes_text, 0, c)
)
if st == NULL:
return
if outline_width:
fgst = (
TTF_RenderUTF8_Blended(font, <char *>bytes_text, c)
TTF_RenderText_Blended(font, <char *>bytes_text, 0, c)
if container.options['font_blended']
else TTF_RenderUTF8_Solid(font, <char *>bytes_text, c)
else TTF_RenderText_Solid(font, <char *>bytes_text, 0, c)
)
if fgst == NULL:
SDL_DestroySurface(st)
Expand Down Expand Up @@ -225,13 +225,13 @@ def _get_extents(container, text):
bytes_text = <bytes>text
if outline_width:
TTF_SetFontOutline(font, outline_width)
TTF_SizeUTF8(font, <char *>bytes_text, &w, &h)
TTF_GetStringSize(font, <char *>bytes_text, 0, &w, &h)
if outline_width:
TTF_SetFontOutline(font, 0)
return w, h

def _get_fontdescent(container):
return TTF_FontDescent(_get_font(container))
return TTF_GetFontDescent(_get_font(container))

def _get_fontascent(container):
return TTF_FontAscent(_get_font(container))
return TTF_GetFontAscent(_get_font(container))
16 changes: 8 additions & 8 deletions kivy/core/window/_window_sdl3.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,10 @@ cdef class _WindowSDL3Storage:

SDL_SetEventFilter(<SDL_EventFilter>_event_filter, <void *>self)

SDL_SetEventEnabled(SDL_EVENT_DROP_FILE, SDL_TRUE)
SDL_SetEventEnabled(SDL_EVENT_DROP_TEXT, SDL_TRUE)
SDL_SetEventEnabled(SDL_EVENT_DROP_BEGIN, SDL_TRUE)
SDL_SetEventEnabled(SDL_EVENT_DROP_COMPLETE, SDL_TRUE)
SDL_SetEventEnabled(SDL_EVENT_DROP_FILE, True)
SDL_SetEventEnabled(SDL_EVENT_DROP_TEXT, True)
SDL_SetEventEnabled(SDL_EVENT_DROP_BEGIN, True)
SDL_SetEventEnabled(SDL_EVENT_DROP_COMPLETE, True)
cdef int w, h
SDL_GetWindowSize(self.win, &w, &h)

Expand Down Expand Up @@ -411,7 +411,7 @@ cdef class _WindowSDL3Storage:
SDL_SetWindowMinimumSize(self.win, w, h)

def set_always_on_top(self, always_on_top):
SDL_SetWindowAlwaysOnTop(self.win, SDL_TRUE if always_on_top else SDL_FALSE)
SDL_SetWindowAlwaysOnTop(self.win, always_on_top)

def set_allow_screensaver(self, allow_screensaver):
if allow_screensaver:
Expand All @@ -435,7 +435,7 @@ cdef class _WindowSDL3Storage:
SDL_ShowWindow(self.win)

def set_border_state(self, state):
SDL_SetWindowBordered(self.win, SDL_FALSE if state else SDL_TRUE)
SDL_SetWindowBordered(self.win, state)

def set_fullscreen_mode(self, mode):
if mode is True:
Expand Down Expand Up @@ -934,7 +934,7 @@ cdef class _WindowSDL3Storage:
SDL_DestroySurface(flipped_surface)

def grab_mouse(self, grab):
SDL_SetWindowMouseGrab(self.win, SDL_TRUE if grab else SDL_FALSE)
SDL_SetWindowMouseGrab(self.win, grab)

def get_relative_mouse_pos(self):
cdef int x, y
Expand All @@ -943,7 +943,7 @@ cdef class _WindowSDL3Storage:
return x - wx, y - wy

def set_custom_titlebar(self, titlebar_widget):
SDL_SetWindowBordered(self.win, SDL_FALSE)
SDL_SetWindowBordered(self.win, False)
return SDL_SetWindowHitTest(self.win, <SDL_HitTest>custom_titlebar_handler_callback,<void *>titlebar_widget)

@property
Expand Down
Loading

0 comments on commit 5380b27

Please sign in to comment.