processing directives for text box widgets
few other misc things also fixed SDL audio on newer SDL vers
This commit is contained in:
parent
bd783d3195
commit
0ec3000536
5
assets/opensb/interface.config.patch
Normal file
5
assets/opensb/interface.config.patch
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"font" : {
|
||||||
|
"defaultDirectives" : ""
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"config" : {
|
"config" : {
|
||||||
"font" : {
|
"font" : {
|
||||||
"directives" : "",
|
"directives" : "?border=1;000;0000",
|
||||||
"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
|
"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" : {
|
"colors" : {
|
||||||
"local" : "^white;",
|
"local" : "^white;",
|
||||||
|
@ -277,7 +277,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
SDL_AudioSpec obtained = {};
|
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!");
|
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) {
|
} else if (obtained.freq != desired.freq || obtained.channels != desired.channels || obtained.format != desired.format) {
|
||||||
SDL_CloseAudio();
|
SDL_CloseAudio();
|
||||||
|
@ -16,7 +16,9 @@ LabelWidget::LabelWidget(String text,
|
|||||||
m_wrapWidth(move(wrapWidth)),
|
m_wrapWidth(move(wrapWidth)),
|
||||||
m_lineSpacing(move(lineSpacing)) {
|
m_lineSpacing(move(lineSpacing)) {
|
||||||
auto assets = Root::singleton().assets();
|
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));
|
setText(move(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ namespace Star {
|
|||||||
|
|
||||||
TextBoxWidget::TextBoxWidget(String const& startingText, String const& hint, WidgetCallbackFunc callback)
|
TextBoxWidget::TextBoxWidget(String const& startingText, String const& hint, WidgetCallbackFunc callback)
|
||||||
: m_text(startingText), m_hint(hint), m_callback(callback) {
|
: m_text(startingText), m_hint(hint), m_callback(callback) {
|
||||||
|
auto assets = Root::singleton().assets();
|
||||||
m_regex = ".*";
|
m_regex = ".*";
|
||||||
m_repeatKeyThreshold = 0;
|
m_repeatKeyThreshold = 0;
|
||||||
m_repeatCode = SpecialRepeatKeyCodes::None;
|
m_repeatCode = SpecialRepeatKeyCodes::None;
|
||||||
@ -15,16 +16,16 @@ TextBoxWidget::TextBoxWidget(String const& startingText, String const& hint, Wid
|
|||||||
m_cursorOffset = startingText.size();
|
m_cursorOffset = startingText.size();
|
||||||
m_hAnchor = HorizontalAnchor::LeftAnchor;
|
m_hAnchor = HorizontalAnchor::LeftAnchor;
|
||||||
m_vAnchor = VerticalAnchor::BottomAnchor;
|
m_vAnchor = VerticalAnchor::BottomAnchor;
|
||||||
m_color = Color::rgbf(1, 1, 1);
|
|
||||||
m_drawBorder = false;
|
m_drawBorder = false;
|
||||||
m_cursorHoriz = Vec2I();
|
m_cursorHoriz = Vec2I();
|
||||||
m_cursorVert = Vec2I();
|
m_cursorVert = Vec2I();
|
||||||
m_overfillMode = true;
|
m_overfillMode = true;
|
||||||
|
|
||||||
auto assets = Root::singleton().assets();
|
|
||||||
|
|
||||||
m_maxWidth = assets->json("/interface.config:textBoxDefaultWidth").toInt();
|
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
|
// Meh, padding is hard-coded here
|
||||||
setSize({m_maxWidth + 6, m_fontSize + 2});
|
setSize({m_maxWidth + 6, m_fontSize + 2});
|
||||||
@ -52,6 +53,7 @@ void TextBoxWidget::renderImpl() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
context()->setFontSize(m_fontSize);
|
context()->setFontSize(m_fontSize);
|
||||||
|
context()->setFontProcessingDirectives(m_processingDirectives);
|
||||||
if (m_text.empty()) {
|
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()->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});
|
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()->setFontColor(m_color.mix(Color::rgbf(0, 0, 1), blueRate).toRgba());
|
||||||
context()->renderInterfaceText(m_text, {pos, m_hAnchor, m_vAnchor});
|
context()->renderInterfaceText(m_text, {pos, m_hAnchor, m_vAnchor});
|
||||||
}
|
}
|
||||||
|
context()->setFontProcessingDirectives("");
|
||||||
context()->setFontColor(Vec4B::filled(255));
|
context()->setFontColor(Vec4B::filled(255));
|
||||||
|
|
||||||
if (hasFocus()) {
|
if (hasFocus()) {
|
||||||
@ -160,6 +163,10 @@ void TextBoxWidget::setColor(Color const& color) {
|
|||||||
m_color = color;
|
m_color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextBoxWidget::setDirectives(String const& directives) {
|
||||||
|
m_processingDirectives = directives;
|
||||||
|
}
|
||||||
|
|
||||||
void TextBoxWidget::setFontSize(int fontSize) {
|
void TextBoxWidget::setFontSize(int fontSize) {
|
||||||
m_fontSize = fontSize;
|
m_fontSize = fontSize;
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ public:
|
|||||||
void setRegex(String const& regex);
|
void setRegex(String const& regex);
|
||||||
|
|
||||||
void setColor(Color const& color);
|
void setColor(Color const& color);
|
||||||
|
void setDirectives(String const& directives);
|
||||||
void setFontSize(int fontSize);
|
void setFontSize(int fontSize);
|
||||||
void setMaxWidth(int maxWidth);
|
void setMaxWidth(int maxWidth);
|
||||||
void setOverfillMode(bool overfillMode);
|
void setOverfillMode(bool overfillMode);
|
||||||
@ -61,6 +62,7 @@ private:
|
|||||||
HorizontalAnchor m_hAnchor;
|
HorizontalAnchor m_hAnchor;
|
||||||
VerticalAnchor m_vAnchor;
|
VerticalAnchor m_vAnchor;
|
||||||
Color m_color;
|
Color m_color;
|
||||||
|
String m_processingDirectives;
|
||||||
int m_fontSize;
|
int m_fontSize;
|
||||||
int m_maxWidth;
|
int m_maxWidth;
|
||||||
int m_cursorOffset;
|
int m_cursorOffset;
|
||||||
|
@ -421,6 +421,8 @@ WidgetConstructResult WidgetParser::textboxHandler(String const& name, Json cons
|
|||||||
textbox->setFontSize(config.getInt("fontSize"));
|
textbox->setFontSize(config.getInt("fontSize"));
|
||||||
if (config.contains("color"))
|
if (config.contains("color"))
|
||||||
textbox->setColor(jsonToColor(config.get("color")));
|
textbox->setColor(jsonToColor(config.get("color")));
|
||||||
|
if (config.contains("directives"))
|
||||||
|
textbox->setDirectives(config.getString("directives"));
|
||||||
if (config.contains("border"))
|
if (config.contains("border"))
|
||||||
textbox->setDrawBorder(config.getBool("border"));
|
textbox->setDrawBorder(config.getBool("border"));
|
||||||
if (config.contains("maxWidth"))
|
if (config.contains("maxWidth"))
|
||||||
|
Loading…
Reference in New Issue
Block a user