[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,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);
}
}

View File

@ -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);
}
}

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

View File

@ -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);
}
}

View File

@ -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);
}
}