Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions docs/source/techspecs/layout_files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ intensity). Alpha ranges from 0.0 (fully transparent) to 1.0 (opaque). Colour
channel values are not pre-multiplied by the alpha value.

Component and view item colour is specified using ``color`` elements.
Meaningful attributes are ``red``, ``green``, ``blue`` and ``alpha``. This
example ``color`` element specifies all channel values:
Meaningful attributes are ``red``, ``green``, ``blue`` and ``alpha`` and ``hex``. This
example ``color`` element specifies all channel values individually:

.. code-block:: XML

Expand All @@ -129,6 +129,20 @@ Any omitted channel attributes default to 1.0 (full intensity or opaque). It
is an error if any channel value falls outside the range of 0.0 to 1.0
(inclusive).

Alternatively, you can specify a single hex value, for either RGB (six hex digits)
or RGBA (eight hex digits):

.. code-block:: XML

<color hex="d9664c" />

(RGB) or

.. code-block:: XML

<color hex="d9664cff" />

(RGBA).

.. _layfile-concepts-params:

Expand Down
33 changes: 33 additions & 0 deletions src/emu/rendlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,39 @@ class layout_environment
if (!node)
return render_color{ 1.0F, 1.0F, 1.0F, 1.0F };

if (node->has_attribute("hex"))
{
// Use the single hex attribute
if (node->has_attribute("red") || node->has_attribute("green") || node->has_attribute("blue") || node->has_attribute("alpha"))
throw layout_syntax_error(util::string_format("specify either hex or (red,green,blue) colors"));

const std::string hex{node->get_attribute_string("hex", "")};
auto l = hex.length();
if (l == 6 || l == 8)
{
std::size_t pos;
unsigned long val = std::stoul(hex, &pos, 16);
if (pos != l)
throw layout_syntax_error(util::string_format("illegal hex color %s", hex));

float alpha = 1.0;
size_t offset = 0;
if (l == 8)
{
alpha = BIT(val, 0, 8) / 255.0;
offset = 8;
}
float blue = BIT(val, offset + 0, 8) / 255.0;
float green = BIT(val, offset + 8, 8) / 255.0;
float red = BIT(val, offset + 16, 8) / 255.0;
return render_color { alpha, red, green, blue };
}
else
{
throw layout_syntax_error(util::string_format("illegal hex color %s", hex));
}
}

// parse attributes
render_color const result{
get_attribute_float(*node, "alpha", 1.0F),
Expand Down
Loading
Loading