Skip to content

Commit

Permalink
Support alpha for shape backgrounds
Browse files Browse the repository at this point in the history
  • Loading branch information
kasemir committed Mar 6, 2024
1 parent 9eccd48 commit b43e99d
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 4 deletions.
106 changes: 106 additions & 0 deletions examples/ShapeAlpha.bob
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--Saved on 2024-03-06 10:55:41 by ky9-->
<display version="2.0.0">
<name>Display</name>
<width>320</width>
<height>490</height>
<widget type="rectangle" version="2.0.0">
<name>Rectangle_1</name>
<x>70</x>
<width>80</width>
<height>490</height>
<line_color>
<color name="Off" red="60" green="100" blue="60">
</color>
</line_color>
<background_color>
<color name="OK" red="0" green="255" blue="0">
</color>
</background_color>
</widget>
<widget type="label" version="2.0.0">
<name>Label</name>
<text>Colors with Alpha</text>
<x>20</x>
<y>10</y>
<width>290</width>
<height>31</height>
<font>
<font name="Header 1" family="Liberation Sans" style="BOLD" size="22.0">
</font>
</font>
</widget>
<widget type="label" version="2.0.0">
<name>Label_1</name>
<text>Colors with Alpha</text>
<x>20</x>
<y>41</y>
<width>290</width>
<height>31</height>
<font>
<font name="Header 1" family="Liberation Sans" style="BOLD" size="22.0">
</font>
</font>
<background_color>
<color red="179" green="179" blue="179" alpha="102">
</color>
</background_color>
<transparent>false</transparent>
</widget>
<widget type="rectangle" version="2.0.0">
<name>Rectangle</name>
<x>30</x>
<y>80</y>
<width>190</width>
<height>60</height>
<background_color>
<color red="30" green="144" blue="255" alpha="123">
</color>
</background_color>
</widget>
<widget type="ellipse" version="2.0.0">
<name>Ellipse</name>
<x>70</x>
<y>159</y>
<background_color>
<color red="30" green="144" blue="255" alpha="123">
</color>
</background_color>
</widget>
<widget type="arc" version="2.0.0">
<name>Arc</name>
<x>70</x>
<y>229</y>
<background_color>
<color red="30" green="144" blue="255" alpha="123">
</color>
</background_color>
</widget>
<widget type="polygon" version="2.0.0">
<name>Polygon</name>
<x>10</x>
<y>289</y>
<width>260</width>
<height>170</height>
<points>
<point x="0.0" y="50.0">
</point>
<point x="160.0" y="0.0">
</point>
<point x="240.0" y="30.0">
</point>
<point x="260.0" y="110.0">
</point>
<point x="210.0" y="150.0">
</point>
<point x="90.0" y="170.0">
</point>
<point x="20.0" y="150.0">
</point>
</points>
<background_color>
<color red="30" green="144" blue="255" alpha="123">
</color>
</background_color>
</widget>
</display>
16 changes: 12 additions & 4 deletions src/main/java/dbwr/parser/XMLUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019-2023 Oak Ridge National Laboratory.
* Copyright (c) 2019-2024 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -363,16 +363,24 @@ public static Color getAWTColor(final Element xml, final String name)
if (col_xml.getAttribute("red").isEmpty())
return null;
// <color name="OK" red="0" green="255" blue="0"></color>
final int red = Integer.parseInt(col_xml.getAttribute("red"));
final int red = Integer.parseInt(col_xml.getAttribute("red"));
final int green = Integer.parseInt(col_xml.getAttribute("green"));
final int blue = Integer.parseInt(col_xml.getAttribute("blue"));
return new Color(red, green, blue);
final int blue = Integer.parseInt(col_xml.getAttribute("blue"));
final int alpha = col_xml.hasAttribute("alpha")
? Integer.parseInt(col_xml.getAttribute("alpha"))
: 255;
return new Color(red, green, blue, alpha);
}

public static String getWebColor(final Color awt_color)
{
if (awt_color == null)
return null;
if (awt_color.getAlpha() < 255)
return String.format("#%02X%02X%02X%02X", awt_color.getRed(),
awt_color.getGreen(),
awt_color.getBlue(),
awt_color.getAlpha());
return String.format("#%02X%02X%02X", awt_color.getRed(),
awt_color.getGreen(),
awt_color.getBlue());
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ view.jsp?cache=false&amp;display=file:/Path/to/Display+Builder/01_main.bob
<hr>

<div id="versions">
2024-03-06 Support alpha for shape backgrounds<br>
2024-02-26 Version: Treat missing as 0.0.0<br>
2024-01-31 Group widget: Correct inset for style 'None' and fix colors for newly added example.<br>
2023-09-11 LED only displayed values above zero instead of non-zero, incl. negative. Byte monitor layout float calc<br>
Expand Down

0 comments on commit b43e99d

Please sign in to comment.