Skip to content

Commit

Permalink
Further SDL3 compatibility changes.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Odetti <[email protected]>
  • Loading branch information
audetto committed Aug 24, 2024
1 parent a2a90fe commit c810980
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion source/frontends/sdl/imgui/sdlimguiframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ namespace sa2
{
const size_t modifiers = getCanonicalModifiers(key);

switch (key.keysym.sym)
switch (SA2_KEY_CODE(key))
{
case SDLK_F8:
{
Expand Down
2 changes: 1 addition & 1 deletion source/frontends/sdl/renderer/sdlrendererframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace sa2

private:

static constexpr SDL_PixelFormatEnum ourPixelFormat = SDL_PIXELFORMAT_ARGB8888;
static constexpr PixelFormat_t ourPixelFormat = SDL_PIXELFORMAT_ARGB8888;

Renderer_Rect_t myRect;
int myPitch;
Expand Down
2 changes: 1 addition & 1 deletion source/frontends/sdl/sdirectsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ namespace
myAudioSpec.freq = mySampleRate;
myAudioSpec.format = AUDIO_S16LSB;
myAudioSpec.channels = myChannels;
myAudioStream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &myAudioSpec, staticAudioCallback3, this);
myAudioStream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &myAudioSpec, staticAudioCallback3, this);
if (myAudioStream)
{
myAudioDevice = SDL_GetAudioStreamDevice(myAudioStream);
Expand Down
8 changes: 3 additions & 5 deletions source/frontends/sdl/sdlcompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ namespace sa2
int getNumJoysticks()
{
int count = 0;
SDL_JoystickID* joy = SDL_GetJoysticks(&count);
const SDL_JoystickID* joy = SDL_GetJoysticks(&count);
if (!joy)
{
throw std::runtime_error(decorateSDLError("SDL_GetJoysticks"));
}
SDL_free(joy);
return count;
}

Expand All @@ -35,11 +34,10 @@ namespace sa2
const SDL_DisplayMode * getCurrentDisplayMode()
{
int count = 0;
SDL_DisplayID * displays = SDL_GetDisplays(&count);
const SDL_DisplayID * displays = SDL_GetDisplays(&count);
if (displays)
{
const SDL_DisplayMode * mode = SDL_GetCurrentDisplayMode(*displays);
SDL_free(displays);
return mode;
}
throw std::runtime_error(decorateSDLError("SDL_GetDisplays"));
Expand Down Expand Up @@ -78,7 +76,7 @@ namespace sa2
const char * name = index >= 0 ? SDL_GetRenderDriver(index) : nullptr;

SDL_PropertiesID props = SDL_CreateProperties();
SDL_SetProperty(props, SDL_PROP_RENDERER_CREATE_WINDOW_POINTER, window);
SDL_SetPointerProperty(props, SDL_PROP_RENDERER_CREATE_WINDOW_POINTER, window);
SDL_SetBooleanProperty(props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER, SDL_TRUE);
if (index >= 0)
{
Expand Down
8 changes: 7 additions & 1 deletion source/frontends/sdl/sdlcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
#define SA2_CONTROLLER_BUTTON(e) e.gbutton.button
#define SA2_DROP_FILE(d) d.data
#define SA2_RENDERER_LOGICAL_SIZE(r, w, h) SDL_RenderSetLogicalSize(r, w, h, SDL_LOGICAL_PRESENTATION_STRETCH, SDL_SCALEMODE_NEAREST)
#define SA2_IMAGE_BITS(s) s->format->bits_per_pixel
#define SA2_IMAGE_BITS(s) SDL_GetPixelFormatDetails(s->format)->bits_per_pixel
#define SA2_KEY_CODE(e) e.key
#define SA2_KEY_MOD(e) e.mod

typedef SDL_FRect Renderer_Rect_t;
typedef SDL_PixelFormat PixelFormat_t;
#else
#include <SDL.h>
#include <SDL_opengl.h>
Expand All @@ -33,8 +36,11 @@
#define SA2_DROP_FILE(d) d.file
#define SA2_RENDERER_LOGICAL_SIZE(r, w, h) SDL_RenderSetLogicalSize(r, w, h)
#define SA2_IMAGE_BITS(s) s->format->BitsPerPixel
#define SA2_KEY_CODE(e) e.keysym.sym
#define SA2_KEY_MOD(e) e.keysym.mod

typedef SDL_Rect Renderer_Rect_t;
typedef SDL_PixelFormatEnum PixelFormat_t;
#endif

namespace common2
Expand Down
20 changes: 14 additions & 6 deletions source/frontends/sdl/sdlframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace
// but this makes it impossible to detect CTRL-ASCII... more to follow
BYTE ch = 0;

switch (key.keysym.sym)
switch (SA2_KEY_CODE(key))
{
case SDLK_RETURN:
case SDLK_KP_ENTER:
Expand Down Expand Up @@ -96,10 +96,10 @@ namespace
// CAPS is forced when the emulator starts
// until is used the first time
const bool capsLock = forceCapsLock || (SDL_GetModState() & KMOD_CAPS);
const bool upper = capsLock || (key.keysym.mod & KMOD_SHIFT);
const bool upper = capsLock || (SA2_KEY_MOD(key) & KMOD_SHIFT);

ch = (key.keysym.sym - SDLK_a) + 0x01;
if (key.keysym.mod & KMOD_CTRL)
ch = (SA2_KEY_CODE(key) - SDLK_a) + 0x01;
if (SA2_KEY_MOD(key) & KMOD_CTRL)
{
// ok
}
Expand Down Expand Up @@ -455,7 +455,7 @@ namespace sa2
if (!key.repeat)
{
const size_t modifiers = getCanonicalModifiers(key);
switch (key.keysym.sym)
switch (SA2_KEY_CODE(key))
{
case SDLK_F12:
{
Expand Down Expand Up @@ -581,12 +581,20 @@ namespace sa2
}
else if (modifiers == KMOD_SHIFT)
{
#ifdef SA2_SDL3
const char * text = SDL_GetClipboardText();
if (text)
{
addTextToBuffer(text);
}
#else
char * text = SDL_GetClipboardText();
if (text)
{
addTextToBuffer(text);
SDL_free(text);
}
#endif
}
else if (modifiers == KMOD_CTRL)
{
Expand Down Expand Up @@ -614,7 +622,7 @@ namespace sa2

void SDLFrame::ProcessKeyUp(const SDL_KeyboardEvent & key)
{
switch (key.keysym.sym)
switch (SA2_KEY_CODE(key))
{
case SDLK_LALT:
{
Expand Down
8 changes: 4 additions & 4 deletions source/frontends/sdl/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace sa2

void printRendererInfo(std::ostream & os,
const std::shared_ptr<SDL_Renderer> & ren,
const SDL_PixelFormatEnum pixelFormat,
const PixelFormat_t pixelFormat,
const int selectedDriver)
{
const size_t n = SDL_GetNumRenderDrivers();
Expand Down Expand Up @@ -154,15 +154,15 @@ namespace sa2
// simplification of the handling of left and right version of the modifiers
// so we can use equality == comparisons
size_t modifiers = KMOD_NONE;
if (key.keysym.mod & KMOD_CTRL)
if (SA2_KEY_MOD(key) & KMOD_CTRL)
{
modifiers |= KMOD_CTRL;
}
if (key.keysym.mod & KMOD_SHIFT)
if (SA2_KEY_MOD(key) & KMOD_SHIFT)
{
modifiers |= KMOD_SHIFT;
}
if (key.keysym.mod & KMOD_ALT)
if (SA2_KEY_MOD(key) & KMOD_ALT)
{
modifiers |= KMOD_ALT;
}
Expand Down
2 changes: 1 addition & 1 deletion source/frontends/sdl/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace sa2

void printRendererInfo(std::ostream & os,
const std::shared_ptr<SDL_Renderer> & ren,
const SDL_PixelFormatEnum pixelFormat,
const PixelFormat_t pixelFormat,
const int selectedDriver);

bool show_yes_no_dialog(const std::shared_ptr<SDL_Window> & win,
Expand Down

0 comments on commit c810980

Please sign in to comment.