From 0ec3000536fae16ede8aa85ad22aba4d9781cc9e Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Wed, 21 Jun 2023 10:40:53 +1000 Subject: [PATCH] processing directives for text box widgets few other misc things also fixed SDL audio on newer SDL vers --- assets/opensb/interface.config.patch | 5 +++++ assets/opensb/interface/chat/chat.config.patch | 4 ++-- source/application/StarMainApplication_sdl.cpp | 2 +- source/windowing/StarLabelWidget.cpp | 4 +++- source/windowing/StarTextBoxWidget.cpp | 15 +++++++++++---- source/windowing/StarTextBoxWidget.hpp | 2 ++ source/windowing/StarWidgetParsing.cpp | 2 ++ 7 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 assets/opensb/interface.config.patch diff --git a/assets/opensb/interface.config.patch b/assets/opensb/interface.config.patch new file mode 100644 index 0000000..7a849af --- /dev/null +++ b/assets/opensb/interface.config.patch @@ -0,0 +1,5 @@ +{ + "font" : { + "defaultDirectives" : "" + } +} \ No newline at end of file diff --git a/assets/opensb/interface/chat/chat.config.patch b/assets/opensb/interface/chat/chat.config.patch index 9c69e4a..db2650d 100644 --- a/assets/opensb/interface/chat/chat.config.patch +++ b/assets/opensb/interface/chat/chat.config.patch @@ -1,8 +1,8 @@ { "config" : { "font" : { - "directives" : "", - "padding" : [0, 0] // Padding to prevent border clipping at the edges of the log canvas while keeping compatible with mods that patch the canvas size + "directives" : "?border=1;000;0000", + "padding" : [1, 1] // Padding to prevent border clipping at the edges of the log canvas while keeping compat with mods that patch the canvas size }, "colors" : { "local" : "^white;", diff --git a/source/application/StarMainApplication_sdl.cpp b/source/application/StarMainApplication_sdl.cpp index 503a8c4..12ea377 100644 --- a/source/application/StarMainApplication_sdl.cpp +++ b/source/application/StarMainApplication_sdl.cpp @@ -277,7 +277,7 @@ public: }; SDL_AudioSpec obtained = {}; - if (SDL_OpenAudio(&desired, &obtained) < 0) { + if (SDL_OpenAudioDevice(NULL, 0, &desired, &obtained, 0) < 0) { Logger::error("Application: Could not open audio device, no sound available!"); } else if (obtained.freq != desired.freq || obtained.channels != desired.channels || obtained.format != desired.format) { SDL_CloseAudio(); diff --git a/source/windowing/StarLabelWidget.cpp b/source/windowing/StarLabelWidget.cpp index f9a5110..5159704 100644 --- a/source/windowing/StarLabelWidget.cpp +++ b/source/windowing/StarLabelWidget.cpp @@ -16,7 +16,9 @@ LabelWidget::LabelWidget(String text, m_wrapWidth(move(wrapWidth)), m_lineSpacing(move(lineSpacing)) { auto assets = Root::singleton().assets(); - m_fontSize = assets->json("/interface.config:font").getInt("baseSize"); + auto fontConfig = assets->json("/interface.config:font"); + m_fontSize = fontConfig.getInt("baseSize"); + m_processingDirectives = fontConfig.getString("defaultDirectives"); setText(move(text)); } diff --git a/source/windowing/StarTextBoxWidget.cpp b/source/windowing/StarTextBoxWidget.cpp index bed6c5e..5bcdfbf 100644 --- a/source/windowing/StarTextBoxWidget.cpp +++ b/source/windowing/StarTextBoxWidget.cpp @@ -7,6 +7,7 @@ namespace Star { TextBoxWidget::TextBoxWidget(String const& startingText, String const& hint, WidgetCallbackFunc callback) : m_text(startingText), m_hint(hint), m_callback(callback) { + auto assets = Root::singleton().assets(); m_regex = ".*"; m_repeatKeyThreshold = 0; m_repeatCode = SpecialRepeatKeyCodes::None; @@ -15,16 +16,16 @@ TextBoxWidget::TextBoxWidget(String const& startingText, String const& hint, Wid m_cursorOffset = startingText.size(); m_hAnchor = HorizontalAnchor::LeftAnchor; m_vAnchor = VerticalAnchor::BottomAnchor; - m_color = Color::rgbf(1, 1, 1); m_drawBorder = false; m_cursorHoriz = Vec2I(); m_cursorVert = Vec2I(); m_overfillMode = true; - auto assets = Root::singleton().assets(); - m_maxWidth = assets->json("/interface.config:textBoxDefaultWidth").toInt(); - m_fontSize = assets->json("/interface.config:font.baseSize").toInt(); + auto fontConfig = assets->json("/interface.config:font"); + m_fontSize = fontConfig.getInt("baseSize"); + m_processingDirectives = fontConfig.getString("defaultDirectives"); + m_color = Color::rgb(jsonToVec3B(fontConfig.getArray("defaultColor"))); // Meh, padding is hard-coded here setSize({m_maxWidth + 6, m_fontSize + 2}); @@ -52,6 +53,7 @@ void TextBoxWidget::renderImpl() { } context()->setFontSize(m_fontSize); + context()->setFontProcessingDirectives(m_processingDirectives); if (m_text.empty()) { context()->setFontColor(m_color.mix(Color::rgbf(0.3f, 0.3f, 0.3f), 0.8f).mix(Color::rgbf(0.0f, 0.0f, 1.0f), blueRate).toRgba()); context()->renderInterfaceText(m_hint, {pos, m_hAnchor, m_vAnchor}); @@ -59,6 +61,7 @@ void TextBoxWidget::renderImpl() { context()->setFontColor(m_color.mix(Color::rgbf(0, 0, 1), blueRate).toRgba()); context()->renderInterfaceText(m_text, {pos, m_hAnchor, m_vAnchor}); } + context()->setFontProcessingDirectives(""); context()->setFontColor(Vec4B::filled(255)); if (hasFocus()) { @@ -160,6 +163,10 @@ void TextBoxWidget::setColor(Color const& color) { m_color = color; } +void TextBoxWidget::setDirectives(String const& directives) { + m_processingDirectives = directives; +} + void TextBoxWidget::setFontSize(int fontSize) { m_fontSize = fontSize; } diff --git a/source/windowing/StarTextBoxWidget.hpp b/source/windowing/StarTextBoxWidget.hpp index 1299d78..c24923a 100644 --- a/source/windowing/StarTextBoxWidget.hpp +++ b/source/windowing/StarTextBoxWidget.hpp @@ -22,6 +22,7 @@ public: void setRegex(String const& regex); void setColor(Color const& color); + void setDirectives(String const& directives); void setFontSize(int fontSize); void setMaxWidth(int maxWidth); void setOverfillMode(bool overfillMode); @@ -61,6 +62,7 @@ private: HorizontalAnchor m_hAnchor; VerticalAnchor m_vAnchor; Color m_color; + String m_processingDirectives; int m_fontSize; int m_maxWidth; int m_cursorOffset; diff --git a/source/windowing/StarWidgetParsing.cpp b/source/windowing/StarWidgetParsing.cpp index 4eee343..db1fa1a 100644 --- a/source/windowing/StarWidgetParsing.cpp +++ b/source/windowing/StarWidgetParsing.cpp @@ -421,6 +421,8 @@ WidgetConstructResult WidgetParser::textboxHandler(String const& name, Json cons textbox->setFontSize(config.getInt("fontSize")); if (config.contains("color")) textbox->setColor(jsonToColor(config.get("color"))); + if (config.contains("directives")) + textbox->setDirectives(config.getString("directives")); if (config.contains("border")) textbox->setDrawBorder(config.getBool("border")); if (config.contains("maxWidth"))