[client,sdl] Use SDL_CreateWindowAndRenderer

Recommendated in https://github.com/libsdl-org/SDL/issues/9076
This commit is contained in:
akallabeth 2024-05-24 08:44:06 +02:00
parent 6b00517b40
commit 2efcf1c436
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5
6 changed files with 71 additions and 122 deletions

View File

@ -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)
{

View File

@ -22,23 +22,14 @@ 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");
}
else
{
_renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED);
if (_renderer == nullptr)
{
widget_log_error(-1, "SDL_CreateRenderer");
}
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);
@ -49,7 +40,6 @@ SdlInputWidgetList::SdlInputWidgetList(const std::string& title,
_buttons.set_highlight(0);
}
}
}
ssize_t SdlInputWidgetList::next(ssize_t current)
{

View File

@ -9,23 +9,15 @@ 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");
}
else
{
_renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED);
if (_renderer == nullptr)
{
widget_log_error(-1, "SDL_CreateRenderer");
}
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
{
SDL_SetWindowTitle(_window, title.c_str());
SDL_Rect rect = { 0, 0, widget_width, widget_height };
for (auto& label : labels)
{
@ -35,13 +27,12 @@ SdlSelectList::SdlSelectList(const std::string& title, const std::vector<std::st
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.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);
}
}
}
SdlSelectList::~SdlSelectList()
{

View File

@ -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,
auto rc = SDL_CreateWindowAndRenderer(title.c_str(), widget_width, total_height,
SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_MOUSE_FOCUS |
SDL_WINDOW_INPUT_FOCUS);
if (_window == nullptr)
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)
{

View File

@ -22,21 +22,12 @@ 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,
auto rc = SDL_CreateWindowAndRenderer(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");
}
else
{
_renderer = SDL_CreateRenderer(_window, nullptr, SDL_RENDERER_PRESENTVSYNC);
if (_renderer == nullptr)
{
widget_log_error(-1, "SDL_CreateRenderer");
}
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++)
@ -49,7 +40,6 @@ SdlInputWidgetList::SdlInputWidgetList(const std::string& title,
_buttons.set_highlight(0);
}
}
}
ssize_t SdlInputWidgetList::next(ssize_t current)
{

View File

@ -9,20 +9,12 @@ 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,
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);
if (_window == nullptr)
{
widget_log_error(-1, "SDL_CreateWindow");
}
else
{
_renderer = SDL_CreateRenderer(_window, nullptr, SDL_RENDERER_PRESENTVSYNC);
if (_renderer == nullptr)
{
widget_log_error(-1, "SDL_CreateRenderer");
}
SDL_WINDOW_INPUT_FOCUS,
&_window, &_renderer);
if (rc != 0)
widget_log_error(rc, "SDL_CreateWindowAndRenderer");
else
{
SDL_FRect rect = { 0, 0, widget_width, widget_height };
@ -34,13 +26,12 @@ SdlSelectList::SdlSelectList(const std::string& title, const std::vector<std::st
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.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);
}
}
}
SdlSelectList::~SdlSelectList()
{