processing directives for text box widgets

few other misc things
also fixed SDL audio on newer SDL vers
This commit is contained in:
Kae 2023-06-21 10:40:53 +10:00
parent bd783d3195
commit 0ec3000536
7 changed files with 26 additions and 8 deletions

View File

@ -0,0 +1,5 @@
{
"font" : {
"defaultDirectives" : ""
}
}

View File

@ -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;",

View File

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

View File

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

View File

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

View File

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

View File

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