Skip to content

Commit

Permalink
[client,sdl] update to SDL3
Browse files Browse the repository at this point in the history
update client for SDL3. Not compatible with SDL2
  • Loading branch information
akallabeth committed May 7, 2024
1 parent 61d3f1f commit 5c3ce4e
Show file tree
Hide file tree
Showing 36 changed files with 558 additions and 593 deletions.
6 changes: 3 additions & 3 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ if(FREERDP_VENDOR AND WITH_CLIENT)
endif()

if(WITH_CLIENT_SDL)
find_package(SDL2)
if (SDL2_FOUND)
find_package(SDL3)
if (SDL3_FOUND)
add_subdirectory(SDL)
else()
message(WARNING "SDL2 requested but not found, continuing build without SDL client")
message(WARNING "SDL3 requested but not found, continuing build without SDL client")
endif()
endif()

Expand Down
10 changes: 5 additions & 5 deletions client/SDL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ if (WITH_DEBUG_SDL_KBD_EVENTS)
add_definitions(-DWITH_DEBUG_SDL_KBD_EVENTS)
endif()

find_package(SDL2 REQUIRED COMPONENTS)
include_directories(${SDL2_INCLUDE_DIR})
include_directories(${SDL2_INCLUDE_DIRS})
find_package(SDL3 REQUIRED COMPONENTS)
include_directories(${SDL3_INCLUDE_DIR})
include_directories(${SDL3_INCLUDE_DIRS})
find_package(cJSON)

set(LIBS "")
Expand Down Expand Up @@ -108,9 +108,9 @@ list(APPEND LIBS
)

if (NOT WITH_SDL_LINK_SHARED)
list(APPEND LIBS ${SDL2_STATIC_LIBRARIES})
list(APPEND LIBS ${SDL3_STATIC_LIBRARIES})
else()
list(APPEND LIBS ${SDL2_LIBRARIES})
list(APPEND LIBS ${SDL3_LIBRARIES})
endif()

AddTargetWithResourceFile(${PROJECT_NAME} "${WIN32_GUI_FLAG}" "${PROJECT_VERSION}" SRCS)
Expand Down
33 changes: 10 additions & 23 deletions client/SDL/dialogs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,27 @@ list(APPEND LIBS
)

if (NOT WITH_SDL_LINK_SHARED)
list(APPEND LIBS ${SDL2_STATIC_LIBRARIES})
list(APPEND LIBS ${SDL3_STATIC_LIBRARIES})
else()
list(APPEND LIBS ${SDL2_LIBRARIES})
list(APPEND LIBS ${SDL3_LIBRARIES})
endif()

macro(find_sdl_component name)
find_package(${name})
if (NOT ${name}_FOUND)
find_package(PkgConfig REQUIRED)
pkg_check_modules(${name} REQUIRED ${name})

if (BUILD_SHARED_LIBS)
list(APPEND LIBS ${${name}_LIBRARIES})
link_directories(${${name}_LIBRARY_DIRS})
include_directories(${${name}_INCLUDE_DIRS})
else()
list(APPEND LIBS ${${name}_STATIC_LIBRARIES})
link_directories(${${name}_STATIC_LIBRARY_DIRS})
include_directories(${${name}_STATIC_INCLUDE_DIRS})
endif()
find_package(${name} REQUIRED)
if (WITH_SDL_LINK_SHARED)
list(APPEND LIBS ${name}::${name})
else()
if (WITH_SDL_LINK_SHARED)
list(APPEND LIBS ${name}::${name})
else()
list(APPEND LIBS ${name}::${name}-static)
endif()
list(APPEND LIBS ${name}::${name}-static)
endif()
get_target_property(${name}_INCLUDE_DIRS ${name}::${name} INTERFACE_INCLUDE_DIRECTORIES)
include_directories(${${name}_INCLUDE_DIRS})
endmacro()

find_sdl_component(SDL2_ttf)
find_sdl_component(SDL3_ttf)

option(WITH_SDL_IMAGE_DIALOGS "Build with SDL_image support (recommended)" OFF)
if (WITH_SDL_IMAGE_DIALOGS)
find_sdl_component(SDL2_image)
find_sdl_component(SDL3_image)
add_definitions(-DWITH_SDL_IMAGE_DIALOGS)
endif()

Expand Down
6 changes: 3 additions & 3 deletions client/SDL/dialogs/res/sdl_resource_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace fs = std::experimental::filesystem;
#error Could not find system header "<filesystem>" or "<experimental/filesystem>"
#endif

SDL_RWops* SDLResourceManager::get(const std::string& type, const std::string& id)
SDL_IOStream* SDLResourceManager::get(const std::string& type, const std::string& id)
{
std::string uuid = type + "/" + id;

Expand All @@ -37,7 +37,7 @@ SDL_RWops* SDLResourceManager::get(const std::string& type, const std::string& i
return nullptr;

const auto& v = val->second;
return SDL_RWFromConstMem(v.data(), v.size());
return SDL_IOFromConstMem(v.data(), v.size());
#else
fs::path path(SDL_RESOURCE_ROOT);
path /= type;
Expand All @@ -49,7 +49,7 @@ SDL_RWops* SDLResourceManager::get(const std::string& type, const std::string& i
<< fs::absolute(path) << std::endl;
std::cerr << "file not found, application will fail" << std::endl;
}
return SDL_RWFromFile(path.u8string().c_str(), "rb");
return SDL_IOFromFile(path.u8string().c_str(), "rb");
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions client/SDL/dialogs/res/sdl_resource_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
#include <string>
#include <map>
#include <vector>
#include <SDL.h>
#include <SDL3/SDL.h>

class SDLResourceManager
{
friend class SDLResourceFile;

public:
static SDL_RWops* get(const std::string& type, const std::string& id);
static SDL_IOStream* get(const std::string& type, const std::string& id);

static const std::string typeFonts();
static const std::string typeImages();
Expand Down
3 changes: 2 additions & 1 deletion client/SDL/dialogs/sdl_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ static const SDL_Color buttonhighlightcolor = { 0xcd, 0xca, 0x35, 0x60 };
static const SDL_Color buttonmouseovercolor = { 0x66, 0xff, 0x66, 0x60 };
static const SDL_Color buttonfontcolor = { 0xd1, 0xcf, 0xcd, 0xff };

SdlButton::SdlButton(SDL_Renderer* renderer, const std::string& label, int id, const SDL_Rect& rect)
SdlButton::SdlButton(SDL_Renderer* renderer, const std::string& label, int id,
const SDL_FRect& rect)
: SdlWidget(renderer, rect, false), _name(label), _id(id)
{
assert(renderer);
Expand Down
2 changes: 1 addition & 1 deletion client/SDL/dialogs/sdl_button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class SdlButton : public SdlWidget
{
public:
SdlButton(SDL_Renderer* renderer, const std::string& label, int id, const SDL_Rect& rect);
SdlButton(SDL_Renderer* renderer, const std::string& label, int id, const SDL_FRect& rect);
SdlButton(SdlButton&& other) noexcept;
~SdlButton() override = default;

Expand Down
3 changes: 2 additions & 1 deletion client/SDL/dialogs/sdl_buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ bool SdlButtonList::populate(SDL_Renderer* renderer, const std::vector<std::stri
for (size_t x = 0; x < ids.size(); x++)
{
const size_t curOffsetX = offsetX + x * (static_cast<size_t>(width) + hpadding);
const SDL_Rect rect = { static_cast<int>(curOffsetX), offsetY, width, height };
const SDL_FRect rect = { static_cast<float>(curOffsetX), static_cast<float>(offsetY),
static_cast<float>(width), static_cast<float>(height) };
_list.emplace_back(renderer, labels[x], ids[x], rect);
}
return true;
Expand Down
87 changes: 42 additions & 45 deletions client/SDL/dialogs/sdl_connection_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ bool SDLConnectionDialog::handle(const SDL_Event& event)

switch (event.type)
{
case SDL_USEREVENT_RETRY_DIALOG:
case SDL_EVENT_USER_RETRY_DIALOG:
return update();
case SDL_QUIT:
case SDL_EVENT_QUIT:
resetTimer();
destroyWindow();
return false;
case SDL_KEYDOWN:
case SDL_KEYUP:
case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
if (visible())
{
auto& ev = reinterpret_cast<const SDL_KeyboardEvent&>(event);
Expand All @@ -230,7 +230,7 @@ bool SDLConnectionDialog::handle(const SDL_Event& event)
case SDLK_RETURN2:
case SDLK_ESCAPE:
case SDLK_KP_ENTER:
if (event.type == SDL_KEYUP)
if (event.type == SDL_EVENT_KEY_UP)
{
freerdp_abort_event(_context);
sdl_push_quit();
Expand All @@ -246,7 +246,7 @@ bool SDLConnectionDialog::handle(const SDL_Event& event)
return windowID == ev.windowID;
}
return false;
case SDL_MOUSEMOTION:
case SDL_EVENT_MOUSE_MOTION:
if (visible())
{
auto& ev = reinterpret_cast<const SDL_MouseMotionEvent&>(event);
Expand All @@ -256,8 +256,8 @@ bool SDLConnectionDialog::handle(const SDL_Event& event)
return windowID == ev.windowID;
}
return false;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
case SDL_EVENT_MOUSE_BUTTON_DOWN:
case SDL_EVENT_MOUSE_BUTTON_UP:
if (visible())
{
auto& ev = reinterpret_cast<const SDL_MouseButtonEvent&>(event);
Expand All @@ -266,7 +266,7 @@ bool SDLConnectionDialog::handle(const SDL_Event& event)
auto button = _buttons.get_selected(event.button);
if (button)
{
if (event.type == SDL_MOUSEBUTTONUP)
if (event.type == SDL_EVENT_MOUSE_BUTTON_UP)
{
freerdp_abort_event(_context);
sdl_push_quit();
Expand All @@ -276,48 +276,44 @@ bool SDLConnectionDialog::handle(const SDL_Event& event)
return windowID == ev.windowID;
}
return false;
case SDL_MOUSEWHEEL:
case SDL_EVENT_MOUSE_WHEEL:
if (visible())
{
auto& ev = reinterpret_cast<const SDL_MouseWheelEvent&>(event);
update(_renderer);
return windowID == ev.windowID;
}
return false;
case SDL_FINGERUP:
case SDL_FINGERDOWN:
case SDL_EVENT_FINGER_UP:
case SDL_EVENT_FINGER_DOWN:
if (visible())
{
auto& ev = reinterpret_cast<const SDL_TouchFingerEvent&>(event);
update(_renderer);
#if SDL_VERSION_ATLEAST(2, 0, 18)
return windowID == ev.windowID;
#else
return false;
#endif
}
return false;
case SDL_WINDOWEVENT:
{
auto& ev = reinterpret_cast<const SDL_WindowEvent&>(event);
switch (ev.event)
default:
if ((event.type >= SDL_EVENT_WINDOW_FIRST) && (event.type <= SDL_EVENT_WINDOW_LAST))
{
case SDL_WINDOWEVENT_CLOSE:
if (windowID == ev.windowID)
{
freerdp_abort_event(_context);
sdl_push_quit();
}
break;
default:
update(_renderer);
setModal();
break;
}
auto& ev = reinterpret_cast<const SDL_WindowEvent&>(event);
switch (ev.type)
{
case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
if (windowID == ev.windowID)
{
freerdp_abort_event(_context);
sdl_push_quit();
}
break;
default:
update(_renderer);
setModal();
break;
}

return windowID == ev.windowID;
}
default:
return windowID == ev.windowID;
}
return false;
}
}
Expand All @@ -330,17 +326,17 @@ bool SDLConnectionDialog::createWindow()
const size_t widget_width = 600;
const size_t total_height = 300;

_window = SDL_CreateWindow(
_title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, widget_width,
total_height, SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_FOCUS);
_window = SDL_CreateWindow(_title.c_str(), widget_width, total_height,
SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_MOUSE_FOCUS |
SDL_WINDOW_INPUT_FOCUS);
if (_window == nullptr)
{
widget_log_error(-1, "SDL_CreateWindow");
return false;
}
setModal();

_renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED);
_renderer = SDL_CreateRenderer(_window, nullptr, SDL_RENDERER_PRESENTVSYNC);
if (_renderer == nullptr)
{
widget_log_error(-1, "SDL_CreateRenderer");
Expand Down Expand Up @@ -385,7 +381,8 @@ bool SDLConnectionDialog::createWindow()
}

int height = (total_height - 3ul * vpadding) / 2ul;
SDL_Rect iconRect{ hpadding, vpadding, widget_width / 4ul - 2ul * hpadding, height };
SDL_FRect iconRect{ hpadding, vpadding, widget_width / 4ul - 2ul * hpadding,
static_cast<float>(height) };
widget_cfg_t icon{ textcolor,
res_bgcolor,
{ _renderer, iconRect,
Expand All @@ -401,11 +398,11 @@ bool SDLConnectionDialog::createWindow()
"FreeRDP_Icon.svg") } };
_list.emplace_back(std::move(logo));

SDL_Rect rect = { widget_width / 4ul, vpadding, widget_width * 3ul / 4ul,
total_height - 3ul * vpadding - widget_height };
SDL_FRect rect = { widget_width / 4ul, vpadding, widget_width * 3ul / 4ul,
total_height - 3ul * vpadding - widget_height };
#else
SDL_Rect rect = { hpadding, vpadding, widget_width - 2ul * hpadding,
total_height - 2ul * vpadding };
SDL_FRect rect = { hpadding, vpadding, widget_width - 2ul * hpadding,
total_height - 2ul * vpadding };
#endif

widget_cfg_t w{ textcolor, backgroundcolor, { _renderer, rect, false } };
Expand Down Expand Up @@ -446,7 +443,7 @@ bool SDLConnectionDialog::show(MsgType type, const char* fmt, va_list ap)
bool SDLConnectionDialog::show(MsgType type)
{
_type = type;
return sdl_push_user_event(SDL_USEREVENT_RETRY_DIALOG);
return sdl_push_user_event(SDL_EVENT_USER_RETRY_DIALOG);
}

std::string SDLConnectionDialog::print(const char* fmt, va_list ap)
Expand Down
2 changes: 1 addition & 1 deletion client/SDL/dialogs/sdl_connection_dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <string>
#include <vector>

#include <SDL.h>
#include <SDL3/SDL.h>

#include <freerdp/freerdp.h>

Expand Down

0 comments on commit 5c3ce4e

Please sign in to comment.