Skip to content

Commit

Permalink
Use opaque colors on the Brief page
Browse files Browse the repository at this point in the history
Alpha blending is expensive.  Reducing alpha blending by using
opaque colors reduces GPU work, and thus `swap` time.
  • Loading branch information
chriadam committed Jan 29, 2024
1 parent ec4a856 commit 153b592
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 22 deletions.
4 changes: 2 additions & 2 deletions components/ArcGauge.qml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ Item {
height: width
x: arcX !== undefined ? arcX : (gauge.alignment & Qt.AlignRight ? (gauge.width - 2*radius) : 0)
y: arcY !== undefined ? arcY : ((gauge.height - height) / 2)
progressColor: Theme.statusColorValue(status)
remainderColor: Theme.statusColorValue(status, true)
progressColor: Theme.gaugeColorValue(status)
remainderColor: Theme.gaugeColorValue(status, true)
}
}
}
1 change: 1 addition & 0 deletions components/ArcGaugeQuantityLabel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Row {
property int alignment: Qt.AlignTop | Qt.AlignLeft
property alias icon: icon
property alias quantityLabel: quantityLabel
property alias useOpaqueColor: quantityLabel.useOpaqueColor
property real leftMargin

// Use x/y bindings as the layout sometimes did not update dynamically when multiple anchor
Expand Down
1 change: 1 addition & 0 deletions components/CircularSingleGauge.qml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Item {
font.pixelSize: Theme.font_briefPage_battery_percentage_pixelSize
unit: VenusOS.Units_Percentage
value: gauges.value
useOpaqueColor: true
}

Row {
Expand Down
3 changes: 2 additions & 1 deletion components/QuantityLabel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Item {
property alias unitColor: unitLabel.color
property int alignment: Qt.AlignHCenter
property int precision: Units.defaultUnitPrecision(unit)
property bool useOpaqueColor: false

readonly property quantityInfo _quantity: Units.getDisplayText(unit, value, precision)

Expand Down Expand Up @@ -64,7 +65,7 @@ Item {
id: unitLabel

text: root._quantity.unit
color: Theme.color_font_secondary
color: root.useOpaqueColor ? Theme.color_opaque_font_secondary : Theme.color_font_secondary
verticalAlignment: Qt.AlignVCenter
}
}
Expand Down
1 change: 1 addition & 0 deletions components/SideGauge.qml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ ArcGauge {
id: quantityLabel

alignment: root.alignment
useOpaqueColor: true
}
}
1 change: 1 addition & 0 deletions components/SolarYieldGauge.qml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Item {
alignment: root.alignment
icon.source: "qrc:/images/solaryield.svg"
quantityLabel.dataObject: Global.system.solar
useOpaqueColor: true
}

Connections {
Expand Down
4 changes: 4 additions & 0 deletions themes/color/Dark.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@

"color_ok": "color_blue",
"color_darkOk": "color_darkBlue",
"color_opaque_darkOk": "#11263B",
"color_warning": "color_orange",
"color_darkWarning": "color_darkOrange",
"color_opaque_darkWarning": "#482D0E",
"color_critical": "color_red",
"color_darkCritical": "color_darkRed",
"color_opaque_darkCritical": "#491C1B",

"color_font_primary": "color_white",
"color_font_secondary": "color_dimWhite",
"color_opaque_font_secondary": "#999999",
"color_font_disabled": "color_gray4",

"color_background_primary": "color_black",
Expand Down
4 changes: 4 additions & 0 deletions themes/color/Light.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@

"color_ok": "color_blue",
"color_darkOk": "color_darkBlue",
"color_opaque_darkOk": "#C0D4E6",
"color_warning": "color_orange",
"color_darkWarning": "color_darkOrange",
"color_opaque_darkWarning": "#F7DBB9",
"color_critical": "color_red",
"color_darkCritical": "color_darkRed",
"color_opaque_darkCritical": "#F8CAC6",

"color_font_primary": "color_gray2",
"color_font_secondary": "color_dimGray2",
"color_opaque_font_secondary": "#7B7A76",
"color_font_disabled": "color_gray4",

"color_background_primary": "color_white",
Expand Down
49 changes: 30 additions & 19 deletions tools/themeparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,43 @@
class ThemeSingleton : public Theme
{
Q_OBJECT
QML_NAMED_ELEMENT(Theme)
QML_SINGLETON
Q_OBJECT
QML_NAMED_ELEMENT(Theme)
QML_SINGLETON
// property declarations
// property declarations
%s
public:
ThemeSingleton(QObject *parent = nullptr)
: Theme(parent)
{
}
ThemeSingleton(QObject *parent = nullptr)
: Theme(parent)
{
}
// property accessors
// property accessors
%s
Q_INVOKABLE QColor statusColorValue(StatusLevel level, bool darkColor = false) const
{
const QVariant c = (level == Ok && darkColor) ? color_darkOk()
: (level == Ok) ? color_ok()
: (level == Warning && darkColor) ? color_darkWarning()
: (level == Warning) ? color_warning()
: (level == Critical && darkColor) ? color_darkCritical()
: color_critical();
return c.typeId() == QMetaType::QColor ? c.value<QColor>() : QColor(c.value<QString>());
}
Q_INVOKABLE QColor statusColorValue(StatusLevel level, bool darkColor = false) const
{
const QVariant c = (level == Ok && darkColor) ? color_darkOk()
: (level == Ok) ? color_ok()
: (level == Warning && darkColor) ? color_darkWarning()
: (level == Warning) ? color_warning()
: (level == Critical && darkColor) ? color_darkCritical()
: color_critical();
return c.typeId() == QMetaType::QColor ? c.value<QColor>() : QColor(c.value<QString>());
}
Q_INVOKABLE QColor gaugeColorValue(StatusLevel level, bool darkColor = false) const
{
const QVariant c = (level == Ok && darkColor) ? color_opaque_darkOk()
: (level == Ok) ? color_ok()
: (level == Warning && darkColor) ? color_opaque_darkWarning()
: (level == Warning) ? color_warning()
: (level == Critical && darkColor) ? color_opaque_darkCritical()
: color_critical();
return c.typeId() == QMetaType::QColor ? c.value<QColor>() : QColor(c.value<QString>());
}
};
Expand Down

0 comments on commit 153b592

Please sign in to comment.