Skip to content

Commit

Permalink
Formspecs: Allow setting alpha value for the box[] element
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas--S authored and rubenwardy committed Apr 23, 2018
1 parent 12a8f88 commit 9577a43
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
5 changes: 3 additions & 2 deletions doc/lua_api.txt
Expand Up @@ -2283,10 +2283,11 @@ appearing when you don't expect them to. See `no_prepend[]`
* `draw_border` (optional): draw border

#### `box[<X>,<Y>;<W>,<H>;<color>]`
* Simple colored semitransparent box
* Simple colored box
* `x` and `y` position the box relative to the top left of the menu
* `w` and `h` are the size of box
* `color` is color specified as a `ColorString`
* `color` is color specified as a `ColorString`.
If the alpha component is left blank, the box will be semitransparent.

#### `dropdown[<X>,<Y>;<W>;<name>;<item 1>,<item 2>, ...,<item n>;<selected idx>]`
* Show a dropdown field
Expand Down
4 changes: 1 addition & 3 deletions src/gui/guiFormSpecMenu.cpp
Expand Up @@ -1560,7 +1560,7 @@ void GUIFormSpecMenu::parseBox(parserData* data, const std::string &element)

video::SColor tmp_color;

if (parseColorString(parts[2], tmp_color, false)) {
if (parseColorString(parts[2], tmp_color, false, 0x8C)) {
BoxDrawSpec spec(pos, geom, tmp_color);

m_boxes.push_back(spec);
Expand Down Expand Up @@ -2515,8 +2515,6 @@ void GUIFormSpecMenu::drawMenu()
for (const GUIFormSpecMenu::BoxDrawSpec &spec : m_boxes) {
irr::video::SColor todraw = spec.color;

todraw.setAlpha(140);

core::rect<s32> rect(spec.pos.X,spec.pos.Y,
spec.pos.X + spec.geom.X,spec.pos.Y + spec.geom.Y);

Expand Down
2 changes: 1 addition & 1 deletion src/gui/guiFormSpecMenu.h
Expand Up @@ -223,7 +223,7 @@ class GUIFormSpecMenu : public GUIModalMenu

struct BoxDrawSpec
{
BoxDrawSpec(v2s32 a_pos, v2s32 a_geom,irr::video::SColor a_color):
BoxDrawSpec(v2s32 a_pos, v2s32 a_geom, irr::video::SColor a_color):
pos(a_pos),
geom(a_geom),
color(a_color)
Expand Down
13 changes: 8 additions & 5 deletions src/util/string.cpp
Expand Up @@ -43,7 +43,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define BSD_ICONV_USED
#endif

static bool parseHexColorString(const std::string &value, video::SColor &color);
static bool parseHexColorString(const std::string &value, video::SColor &color,
unsigned char default_alpha = 0xff);
static bool parseNamedColorString(const std::string &value, video::SColor &color);

#ifndef _WIN32
Expand Down Expand Up @@ -464,12 +465,13 @@ u64 read_seed(const char *str)
return num;
}

bool parseColorString(const std::string &value, video::SColor &color, bool quiet)
bool parseColorString(const std::string &value, video::SColor &color, bool quiet,
unsigned char default_alpha)
{
bool success;

if (value[0] == '#')
success = parseHexColorString(value, color);
success = parseHexColorString(value, color, default_alpha);
else
success = parseNamedColorString(value, color);

Expand All @@ -479,9 +481,10 @@ bool parseColorString(const std::string &value, video::SColor &color, bool quiet
return success;
}

static bool parseHexColorString(const std::string &value, video::SColor &color)
static bool parseHexColorString(const std::string &value, video::SColor &color,
unsigned char default_alpha)
{
unsigned char components[] = { 0x00, 0x00, 0x00, 0xff }; // R,G,B,A
unsigned char components[] = { 0x00, 0x00, 0x00, default_alpha }; // R,G,B,A

if (value[0] != '#')
return false;
Expand Down
3 changes: 2 additions & 1 deletion src/util/string.h
Expand Up @@ -85,7 +85,8 @@ std::string writeFlagString(u32 flags, const FlagDesc *flagdesc, u32 flagmask);
size_t mystrlcpy(char *dst, const char *src, size_t size);
char *mystrtok_r(char *s, const char *sep, char **lasts);
u64 read_seed(const char *str);
bool parseColorString(const std::string &value, video::SColor &color, bool quiet);
bool parseColorString(const std::string &value, video::SColor &color, bool quiet,
unsigned char default_alpha = 0xff);


/**
Expand Down

0 comments on commit 9577a43

Please sign in to comment.