Skip to content

Commit 8f73ec6

Browse files
Desoursfan5
authored andcommittedDec 8, 2019
Formspec: make bgcolor element less confusing and allow setting fullscreen color (#8996)
1 parent d3255f9 commit 8f73ec6

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed
 

Diff for: ‎doc/lua_api.txt

+13-5
Original file line numberDiff line numberDiff line change
@@ -2104,11 +2104,19 @@ Elements
21042104

21052105
* Show an inventory image of registered item/node
21062106

2107-
### `bgcolor[<color>;<fullscreen>]`
2108-
2109-
* Sets background color of formspec as `ColorString`
2110-
* If `true`, a fullscreen background is drawn and the color is ignored
2111-
(does not affect the size of the formspec)
2107+
### `bgcolor[<bgcolor>;<fullscreen>;<fbgcolor>]`
2108+
2109+
* Sets background color of formspec.
2110+
* `bgcolor` and `fbgcolor` (optional) are `ColorString`s, they define the color
2111+
of the non-fullscreen and the fullscreen background.
2112+
* `fullscreen` (optional) can be one of the following:
2113+
* `false`: Only the non-fullscreen background color is drawn. (default)
2114+
* `true`: Only the fullscreen background color is drawn.
2115+
* `both`: The non-fullscreen and the fullscreen background color are drawn.
2116+
* `neither`: No background color is drawn.
2117+
* Note: Leave a parameter empty to not modify the value.
2118+
* Note: `fbgcolor`, leaving parameters empty and values for `fullscreen` that
2119+
are not bools are only available since formspec version 3.
21122120

21132121
### `background[<X>,<Y>;<W>,<H>;<texture name>]`
21142122

Diff for: ‎src/gui/guiFormSpecMenu.cpp

+26-10
Original file line numberDiff line numberDiff line change
@@ -2178,21 +2178,36 @@ void GUIFormSpecMenu::parseBox(parserData* data, const std::string &element)
21782178
void GUIFormSpecMenu::parseBackgroundColor(parserData* data, const std::string &element)
21792179
{
21802180
std::vector<std::string> parts = split(element,';');
2181+
const u32 parameter_count = parts.size();
21812182

2182-
if (((parts.size() == 1) || (parts.size() == 2)) ||
2183-
((parts.size() > 2) && (m_formspec_version > FORMSPEC_API_VERSION))) {
2183+
if ((parameter_count > 2 && m_formspec_version < 3) ||
2184+
(parameter_count > 3 && m_formspec_version <= FORMSPEC_API_VERSION)) {
2185+
errorstream << "Invalid bgcolor element(" << parameter_count << "): '"
2186+
<< element << "'" << std::endl;
2187+
return;
2188+
}
2189+
2190+
// bgcolor
2191+
if (parameter_count >= 1 && parts[0] != "")
21842192
parseColorString(parts[0], m_bgcolor, false);
21852193

2186-
if (parts.size() == 2) {
2187-
std::string fullscreen = parts[1];
2188-
m_bgfullscreen = is_yes(fullscreen);
2194+
// fullscreen
2195+
if (parameter_count >= 2) {
2196+
if (parts[1] == "both") {
2197+
m_bgnonfullscreen = true;
2198+
m_bgfullscreen = true;
2199+
} else if (parts[1] == "neither") {
2200+
m_bgnonfullscreen = false;
2201+
m_bgfullscreen = false;
2202+
} else if (parts[1] != "" || m_formspec_version < 3) {
2203+
m_bgfullscreen = is_yes(parts[1]);
2204+
m_bgnonfullscreen = !m_bgfullscreen;
21892205
}
2190-
2191-
return;
21922206
}
21932207

2194-
errorstream << "Invalid bgcolor element(" << parts.size() << "): '" << element << "'"
2195-
<< std::endl;
2208+
// fbgcolor
2209+
if (parameter_count >= 3 && parts[2] != "")
2210+
parseColorString(parts[2], m_fullscreen_bgcolor, false);
21962211
}
21972212

21982213
void GUIFormSpecMenu::parseListColors(parserData* data, const std::string &element)
@@ -2735,6 +2750,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
27352750
theme_by_name.clear();
27362751
theme_by_type.clear();
27372752

2753+
m_bgnonfullscreen = true;
27382754
m_bgfullscreen = false;
27392755

27402756
m_formspec_version = 1;
@@ -3312,7 +3328,7 @@ void GUIFormSpecMenu::drawMenu()
33123328

33133329
if (m_bgfullscreen)
33143330
driver->draw2DRectangle(m_fullscreen_bgcolor, allbg, &allbg);
3315-
else
3331+
if (m_bgnonfullscreen)
33163332
driver->draw2DRectangle(m_bgcolor, AbsoluteRect, &AbsoluteClippingRect);
33173333

33183334
/*

Diff for: ‎src/gui/guiFormSpecMenu.h

+1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ class GUIFormSpecMenu : public GUIModalMenu
369369
bool m_lock = false;
370370
v2u32 m_lockscreensize;
371371

372+
bool m_bgnonfullscreen;
372373
bool m_bgfullscreen;
373374
bool m_slotborder;
374375
video::SColor m_bgcolor;

Diff for: ‎src/network/networkprotocol.h

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
231231
background9[]: 9-slice scaling parameters
232232
FORMSPEC VERSION 3:
233233
Formspec elements are drawn in the order of definition
234+
bgcolor[]: use 3 parameters (bgcolor, formspec (now an enum), fbgcolor)
234235
*/
235236
#define FORMSPEC_API_VERSION 3
236237

0 commit comments

Comments
 (0)
Please sign in to comment.