Merge pull request #10211 from akallabeth/sdl-window-renderer
[client,sdl] Use SDL_CreateWindowAndRenderer
This commit is contained in:
commit
a046314d98
3
.github/workflows/clang-tidy.yml
vendored
3
.github/workflows/clang-tidy.yml
vendored
@ -3,6 +3,9 @@ on:
|
||||
pull_request:
|
||||
branches: [ master, stable* ]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -330,23 +330,16 @@ 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);
|
||||
if (_window == nullptr)
|
||||
auto flags = SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_FOCUS;
|
||||
auto rc = SDL_CreateWindowAndRenderer(widget_width, widget_height, flags, &_window, &_renderer);
|
||||
if (rc != 0)
|
||||
{
|
||||
widget_log_error(-1, "SDL_CreateWindow");
|
||||
widget_log_error(rc, "SDL_CreateWindowAndRenderer");
|
||||
return false;
|
||||
}
|
||||
SDL_SetWindowTitle(_window, _title.c_str());
|
||||
setModal();
|
||||
|
||||
_renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED);
|
||||
if (_renderer == nullptr)
|
||||
{
|
||||
widget_log_error(-1, "SDL_CreateRenderer");
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_Color res_bgcolor;
|
||||
switch (_type_active)
|
||||
{
|
||||
|
@ -22,32 +22,22 @@ SdlInputWidgetList::SdlInputWidgetList(const std::string& title,
|
||||
const size_t total_width = widget_width + widget_width;
|
||||
const size_t input_height = labels.size() * (widget_heigth + vpadding) + vpadding;
|
||||
const size_t total_height = input_height + widget_heigth;
|
||||
_window = SDL_CreateWindow(
|
||||
title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, total_width, total_height,
|
||||
SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_FOCUS);
|
||||
if (_window == nullptr)
|
||||
{
|
||||
widget_log_error(-1, "SDL_CreateWindow");
|
||||
}
|
||||
|
||||
auto wflags = SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_FOCUS;
|
||||
auto rc = SDL_CreateWindowAndRenderer(total_width, total_height, wflags, &_window, &_renderer);
|
||||
if (rc != 0)
|
||||
widget_log_error(rc, "SDL_CreateWindowAndRenderer");
|
||||
else
|
||||
{
|
||||
SDL_SetWindowTitle(_window, title.c_str());
|
||||
for (size_t x = 0; x < labels.size(); x++)
|
||||
_list.emplace_back(_renderer, labels[x], initial[x], flags[x], x, widget_width,
|
||||
widget_heigth);
|
||||
|
||||
_renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED);
|
||||
if (_renderer == nullptr)
|
||||
{
|
||||
widget_log_error(-1, "SDL_CreateRenderer");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t x = 0; x < labels.size(); x++)
|
||||
_list.emplace_back(_renderer, labels[x], initial[x], flags[x], x, widget_width,
|
||||
widget_heigth);
|
||||
|
||||
_buttons.populate(_renderer, buttonlabels, buttonids, total_width,
|
||||
static_cast<Sint32>(input_height), static_cast<Sint32>(widget_width),
|
||||
static_cast<Sint32>(widget_heigth));
|
||||
_buttons.set_highlight(0);
|
||||
}
|
||||
_buttons.populate(_renderer, buttonlabels, buttonids, total_width,
|
||||
static_cast<Sint32>(input_height), static_cast<Sint32>(widget_width),
|
||||
static_cast<Sint32>(widget_heigth));
|
||||
_buttons.set_highlight(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,37 +9,28 @@ SdlSelectList::SdlSelectList(const std::string& title, const std::vector<std::st
|
||||
const size_t widget_width = 600;
|
||||
|
||||
const size_t total_height = labels.size() * (widget_height + vpadding) + vpadding;
|
||||
_window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
widget_width, total_height + widget_height,
|
||||
SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_MOUSE_FOCUS |
|
||||
SDL_WINDOW_INPUT_FOCUS);
|
||||
if (_window == nullptr)
|
||||
{
|
||||
widget_log_error(-1, "SDL_CreateWindow");
|
||||
}
|
||||
auto flags = SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_FOCUS;
|
||||
auto rc = SDL_CreateWindowAndRenderer(widget_width, total_height + widget_height, flags,
|
||||
&_window, &_renderer);
|
||||
if (rc != 0)
|
||||
widget_log_error(rc, "SDL_CreateWindowAndRenderer");
|
||||
else
|
||||
{
|
||||
_renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED);
|
||||
if (_renderer == nullptr)
|
||||
{
|
||||
widget_log_error(-1, "SDL_CreateRenderer");
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_Rect rect = { 0, 0, widget_width, widget_height };
|
||||
for (auto& label : labels)
|
||||
{
|
||||
_list.emplace_back(_renderer, label, rect);
|
||||
rect.y += widget_height + vpadding;
|
||||
}
|
||||
SDL_SetWindowTitle(_window, title.c_str());
|
||||
|
||||
const std::vector<int> buttonids = { INPUT_BUTTON_ACCEPT, INPUT_BUTTON_CANCEL };
|
||||
const std::vector<std::string> buttonlabels = { "accept", "cancel" };
|
||||
_buttons.populate(
|
||||
_renderer, buttonlabels, buttonids, widget_width, static_cast<Sint32>(total_height),
|
||||
static_cast<Sint32>(widget_width / 2), static_cast<Sint32>(widget_height));
|
||||
_buttons.set_highlight(0);
|
||||
SDL_Rect rect = { 0, 0, widget_width, widget_height };
|
||||
for (auto& label : labels)
|
||||
{
|
||||
_list.emplace_back(_renderer, label, rect);
|
||||
rect.y += widget_height + vpadding;
|
||||
}
|
||||
|
||||
const std::vector<int> buttonids = { INPUT_BUTTON_ACCEPT, INPUT_BUTTON_CANCEL };
|
||||
const std::vector<std::string> buttonlabels = { "accept", "cancel" };
|
||||
_buttons.populate(_renderer, buttonlabels, buttonids, widget_width,
|
||||
static_cast<Sint32>(total_height), static_cast<Sint32>(widget_width / 2),
|
||||
static_cast<Sint32>(widget_height));
|
||||
_buttons.set_highlight(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,9 @@ class SdlWidget
|
||||
{
|
||||
public:
|
||||
SdlWidget(SDL_Renderer* renderer, const SDL_Rect& rect, bool input);
|
||||
#if defined(WITH_SDL_IMAGE_DIALOGS)
|
||||
SdlWidget(SDL_Renderer* renderer, const SDL_Rect& rect, SDL_RWops* ops);
|
||||
#endif
|
||||
SdlWidget(SdlWidget&& other) noexcept;
|
||||
virtual ~SdlWidget();
|
||||
|
||||
|
@ -326,23 +326,17 @@ bool SDLConnectionDialog::createWindow()
|
||||
const size_t widget_width = 600;
|
||||
const size_t total_height = 300;
|
||||
|
||||
_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)
|
||||
auto rc = SDL_CreateWindowAndRenderer(title.c_str(), widget_width, total_height,
|
||||
SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_MOUSE_FOCUS |
|
||||
SDL_WINDOW_INPUT_FOCUS,
|
||||
&_window, &_renderer);
|
||||
if (rc != 0)
|
||||
{
|
||||
widget_log_error(-1, "SDL_CreateWindow");
|
||||
widget_log_error(rc, "SDL_CreateWindowAndRenderer");
|
||||
return false;
|
||||
}
|
||||
setModal();
|
||||
|
||||
_renderer = SDL_CreateRenderer(_window, nullptr, SDL_RENDERER_PRESENTVSYNC);
|
||||
if (_renderer == nullptr)
|
||||
{
|
||||
widget_log_error(-1, "SDL_CreateRenderer");
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_Color res_bgcolor;
|
||||
switch (_type_active)
|
||||
{
|
||||
|
@ -22,32 +22,22 @@ SdlInputWidgetList::SdlInputWidgetList(const std::string& title,
|
||||
const size_t total_width = widget_width + widget_width;
|
||||
const size_t input_height = labels.size() * (widget_heigth + vpadding) + vpadding;
|
||||
const size_t total_height = input_height + widget_heigth;
|
||||
_window = SDL_CreateWindow(title.c_str(), total_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");
|
||||
}
|
||||
auto rc = SDL_CreateWindowAndRenderer(title.c_str(), total_width, total_height,
|
||||
SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_MOUSE_FOCUS |
|
||||
SDL_WINDOW_INPUT_FOCUS,
|
||||
&_window, &_renderer);
|
||||
if (rc != 0)
|
||||
widget_log_error(rc, "SDL_CreateWindowAndRenderer");
|
||||
else
|
||||
{
|
||||
for (size_t x = 0; x < labels.size(); x++)
|
||||
_list.emplace_back(_renderer, labels[x], initial[x], flags[x], x, widget_width,
|
||||
widget_heigth);
|
||||
|
||||
_renderer = SDL_CreateRenderer(_window, nullptr, SDL_RENDERER_PRESENTVSYNC);
|
||||
if (_renderer == nullptr)
|
||||
{
|
||||
widget_log_error(-1, "SDL_CreateRenderer");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t x = 0; x < labels.size(); x++)
|
||||
_list.emplace_back(_renderer, labels[x], initial[x], flags[x], x, widget_width,
|
||||
widget_heigth);
|
||||
|
||||
_buttons.populate(_renderer, buttonlabels, buttonids, total_width,
|
||||
static_cast<Sint32>(input_height), static_cast<Sint32>(widget_width),
|
||||
static_cast<Sint32>(widget_heigth));
|
||||
_buttons.set_highlight(0);
|
||||
}
|
||||
_buttons.populate(_renderer, buttonlabels, buttonids, total_width,
|
||||
static_cast<Sint32>(input_height), static_cast<Sint32>(widget_width),
|
||||
static_cast<Sint32>(widget_heigth));
|
||||
_buttons.set_highlight(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,36 +9,27 @@ SdlSelectList::SdlSelectList(const std::string& title, const std::vector<std::st
|
||||
const size_t widget_width = 600;
|
||||
|
||||
const size_t total_height = labels.size() * (widget_height + vpadding) + vpadding;
|
||||
_window = SDL_CreateWindow(title.c_str(), widget_width, total_height + widget_height,
|
||||
SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_MOUSE_FOCUS |
|
||||
SDL_WINDOW_INPUT_FOCUS);
|
||||
if (_window == nullptr)
|
||||
{
|
||||
widget_log_error(-1, "SDL_CreateWindow");
|
||||
}
|
||||
auto rc = SDL_CreateWindowAndRenderer(title.c_str(), widget_width, total_height + widget_height,
|
||||
SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_MOUSE_FOCUS |
|
||||
SDL_WINDOW_INPUT_FOCUS,
|
||||
&_window, &_renderer);
|
||||
if (rc != 0)
|
||||
widget_log_error(rc, "SDL_CreateWindowAndRenderer");
|
||||
else
|
||||
{
|
||||
_renderer = SDL_CreateRenderer(_window, nullptr, SDL_RENDERER_PRESENTVSYNC);
|
||||
if (_renderer == nullptr)
|
||||
SDL_FRect rect = { 0, 0, widget_width, widget_height };
|
||||
for (auto& label : labels)
|
||||
{
|
||||
widget_log_error(-1, "SDL_CreateRenderer");
|
||||
_list.emplace_back(_renderer, label, rect);
|
||||
rect.y += widget_height + vpadding;
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_FRect rect = { 0, 0, widget_width, widget_height };
|
||||
for (auto& label : labels)
|
||||
{
|
||||
_list.emplace_back(_renderer, label, rect);
|
||||
rect.y += widget_height + vpadding;
|
||||
}
|
||||
|
||||
const std::vector<int> buttonids = { INPUT_BUTTON_ACCEPT, INPUT_BUTTON_CANCEL };
|
||||
const std::vector<std::string> buttonlabels = { "accept", "cancel" };
|
||||
_buttons.populate(
|
||||
_renderer, buttonlabels, buttonids, widget_width, static_cast<Sint32>(total_height),
|
||||
static_cast<Sint32>(widget_width / 2), static_cast<Sint32>(widget_height));
|
||||
_buttons.set_highlight(0);
|
||||
}
|
||||
const std::vector<int> buttonids = { INPUT_BUTTON_ACCEPT, INPUT_BUTTON_CANCEL };
|
||||
const std::vector<std::string> buttonlabels = { "accept", "cancel" };
|
||||
_buttons.populate(_renderer, buttonlabels, buttonids, widget_width,
|
||||
static_cast<Sint32>(total_height), static_cast<Sint32>(widget_width / 2),
|
||||
static_cast<Sint32>(widget_height));
|
||||
_buttons.set_highlight(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,10 @@ add_executable(sdl-common-res2bin
|
||||
convert_res_to_c.cpp
|
||||
)
|
||||
|
||||
set(FACTORY_SRCS "")
|
||||
set(FACTORY_HDR "")
|
||||
set(FACTORY_CLASSES "")
|
||||
|
||||
macro(convert_to_bin FILE FILE_TYPE)
|
||||
get_filename_component(FILE_NAME ${FILE} NAME)
|
||||
string(REGEX REPLACE "[^a-zA-Z0-9]" "_" TARGET_NAME ${FILE_NAME})
|
||||
@ -26,9 +30,16 @@ macro(convert_to_bin FILE FILE_TYPE)
|
||||
set(FILE_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin)
|
||||
set(FILE_BYPRODUCTS ${FILE_BIN_DIR}/${TARGET_NAME}.hpp ${FILE_BIN_DIR}/${TARGET_NAME}.cpp)
|
||||
|
||||
list(APPEND FACTORY_SRCS
|
||||
${FILE_BYPRODUCTS}
|
||||
list(APPEND FACTORY_HDR
|
||||
${FILE_BIN_DIR}/${TARGET_NAME}.hpp
|
||||
)
|
||||
list(APPEND FACTORY_SRCS
|
||||
${FILE_BIN_DIR}/${TARGET_NAME}.cpp
|
||||
)
|
||||
|
||||
list(APPEND FACTORY_CLASSES
|
||||
${TARGET_NAME}
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${FILE_BYPRODUCTS}
|
||||
@ -68,14 +79,28 @@ if (SDL_USE_COMPILED_RESOURCES)
|
||||
|
||||
if (WITH_SDL_IMAGE_DIALOGS)
|
||||
foreach(FILE ${RES_SVG_FILES})
|
||||
convert_to_bin("${FILE}" "images")
|
||||
convert_to_bin("${FILE}" "images")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
foreach(FILE ${RES_FONT_FILES})
|
||||
convert_to_bin("${FILE}" "fonts")
|
||||
convert_to_bin("${FILE}" "fonts")
|
||||
endforeach()
|
||||
add_definitions(-DSDL_USE_COMPILED_RESOURCES)
|
||||
|
||||
set(FINIT ${CMAKE_CURRENT_BINARY_DIR}/resource-init.cpp)
|
||||
list(APPEND FACTORY_SRCS ${FINIT})
|
||||
|
||||
write_file(${FINIT} "#include <sdl_resource_manager.hpp>")
|
||||
foreach(HDR ${FACTORY_HDR})
|
||||
write_file(${FINIT} "#include <${HDR}>" APPEND)
|
||||
endforeach()
|
||||
|
||||
write_file(${FINIT} "void SDLResourceManager::init() {" APPEND)
|
||||
foreach(CLASS ${FACTORY_CLASSES})
|
||||
write_file(${FINIT} "\t${CLASS}::init();" APPEND)
|
||||
endforeach()
|
||||
write_file(${FINIT} "}" APPEND)
|
||||
else()
|
||||
set(SDL_RESOURCE_ROOT ${CMAKE_INSTALL_FULL_DATAROOTDIR}/FreeRDP)
|
||||
if (WITH_BINARY_VERSIONING)
|
||||
@ -97,9 +122,10 @@ else()
|
||||
)
|
||||
endif()
|
||||
|
||||
add_library(sdl-common-client-res OBJECT
|
||||
add_library(sdl-common-client-res STATIC
|
||||
${RES_FILES}
|
||||
${SRCS}
|
||||
${FACTORY_HDR}
|
||||
${FACTORY_SRCS}
|
||||
)
|
||||
set_property(TARGET sdl-common-client-res PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
@ -128,13 +128,14 @@ static int write_hpp_header(const fs::path& prg, const fs::path& file, const std
|
||||
<< "#include \"sdl_resource_file.hpp\"" << std::endl
|
||||
<< std::endl
|
||||
<< "class " << name << " {" << std::endl
|
||||
<< "friend class SDLResourceManager;" << std::endl
|
||||
<< "public:" << std::endl
|
||||
<< name << "() = delete;" << std::endl
|
||||
<< std::endl
|
||||
<< "static std::string name();" << std::endl
|
||||
<< "static std::string type();" << std::endl
|
||||
<< std::endl
|
||||
<< "private:" << std::endl
|
||||
<< "protected:" << std::endl
|
||||
<< "static std::vector<unsigned char> init();" << std::endl
|
||||
<< "static const SDLResourceFile _initializer;" << std::endl
|
||||
<< std::endl
|
||||
|
@ -93,5 +93,7 @@ std::map<std::string, std::vector<unsigned char>>& SDLResourceManager::resources
|
||||
{
|
||||
|
||||
static std::map<std::string, std::vector<unsigned char>> resources = {};
|
||||
if (resources.empty())
|
||||
init();
|
||||
return resources;
|
||||
}
|
||||
|
@ -47,4 +47,5 @@ class SDLResourceManager
|
||||
|
||||
private:
|
||||
static std::map<std::string, std::vector<unsigned char>>& resources();
|
||||
static void init(); // implemented in generated file
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user