mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
[escher] Add a gauge view and a message table cell with gauge
This commit is contained in:
@@ -20,6 +20,7 @@ objs += $(addprefix escher/src/,\
|
||||
expression_table_cell_with_pointer.o\
|
||||
expression_view.o\
|
||||
highlight_cell.o\
|
||||
gauge_view.o\
|
||||
image_view.o\
|
||||
invocation.o\
|
||||
input_view_controller.o\
|
||||
@@ -31,6 +32,7 @@ objs += $(addprefix escher/src/,\
|
||||
message_table_cell_with_chevron_and_message.o\
|
||||
message_table_cell_with_chevron_and_expression.o\
|
||||
message_table_cell_with_editable_text.o\
|
||||
message_table_cell_with_gauge.o\
|
||||
message_table_cell_with_message.o\
|
||||
message_table_cell_with_switch.o\
|
||||
message_text_view.o\
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <escher/expression_table_cell.h>
|
||||
#include <escher/expression_table_cell_with_pointer.h>
|
||||
#include <escher/expression_view.h>
|
||||
#include <escher/gauge_view.h>
|
||||
#include <escher/highlight_cell.h>
|
||||
#include <escher/image.h>
|
||||
#include <escher/image_view.h>
|
||||
@@ -34,6 +35,7 @@
|
||||
#include <escher/message_table_cell_with_chevron_and_message.h>
|
||||
#include <escher/message_table_cell_with_chevron_and_expression.h>
|
||||
#include <escher/message_table_cell_with_editable_text.h>
|
||||
#include <escher/message_table_cell_with_gauge.h>
|
||||
#include <escher/message_table_cell_with_message.h>
|
||||
#include <escher/message_table_cell_with_switch.h>
|
||||
#include <escher/message_text_view.h>
|
||||
|
||||
21
escher/include/escher/gauge_view.h
Normal file
21
escher/include/escher/gauge_view.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef ESCHER_GAUGE_VIEW_H
|
||||
#define ESCHER_GAUGE_VIEW_H
|
||||
|
||||
#include <escher/view.h>
|
||||
|
||||
class GaugeView : public View {
|
||||
public:
|
||||
GaugeView();
|
||||
float level();
|
||||
void setLevel(float level);
|
||||
void setBackgroundColor(KDColor color);
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
KDSize minimalSizeForOptimalDisplay() const override;
|
||||
constexpr static KDCoordinate k_indicatorDiameter = 10;
|
||||
private:
|
||||
constexpr static KDCoordinate k_thickness = 2;
|
||||
float m_level;
|
||||
KDColor m_backgroundColor;
|
||||
};
|
||||
|
||||
#endif
|
||||
16
escher/include/escher/message_table_cell_with_gauge.h
Normal file
16
escher/include/escher/message_table_cell_with_gauge.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef ESCHER_MESSAGE_TABLE_CELL_WITH_GAUGE_H
|
||||
#define ESCHER_MESSAGE_TABLE_CELL_WITH_GAUGE_H
|
||||
|
||||
#include <escher/message_table_cell.h>
|
||||
#include <escher/gauge_view.h>
|
||||
|
||||
class MessageTableCellWithGauge : public MessageTableCell {
|
||||
public:
|
||||
MessageTableCellWithGauge(I18n::Message message = (I18n::Message)0, KDText::FontSize size = KDText::FontSize::Small);
|
||||
View * accessoryView() const override;
|
||||
void setHighlighted(bool highlight) override;
|
||||
private:
|
||||
GaugeView m_accessoryView;
|
||||
};
|
||||
|
||||
#endif
|
||||
60
escher/src/gauge_view.cpp
Normal file
60
escher/src/gauge_view.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#include <escher/gauge_view.h>
|
||||
#include <escher/palette.h>
|
||||
|
||||
const uint8_t gaugeIndicatorMask[GaugeView::k_indicatorDiameter][GaugeView::k_indicatorDiameter] = {
|
||||
{0xFF, 0xFF, 0xE1, 0x0C, 0x00, 0x00, 0x0C, 0xE1, 0xFF, 0xFF},
|
||||
{0xFF, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0xFF},
|
||||
{0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE1},
|
||||
{0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C},
|
||||
{0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE1},
|
||||
{0xFF, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0xFF},
|
||||
{0xFF, 0xFF, 0xE1, 0x0C, 0x00, 0x00, 0x0C, 0xE1, 0xFF, 0xFF},
|
||||
};
|
||||
|
||||
GaugeView::GaugeView() :
|
||||
View(),
|
||||
m_level(1),
|
||||
m_backgroundColor(KDColorWhite)
|
||||
{
|
||||
}
|
||||
|
||||
float GaugeView::level() {
|
||||
return m_level;
|
||||
}
|
||||
|
||||
void GaugeView::setLevel(float level) {
|
||||
if (m_level != level) {
|
||||
level = level < 0 ? 0 : level;
|
||||
level = level > 1 ? 1 : level;
|
||||
m_level = level;
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
}
|
||||
|
||||
void GaugeView::setBackgroundColor(KDColor color) {
|
||||
if (m_backgroundColor != color) {
|
||||
m_backgroundColor = color;
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
}
|
||||
|
||||
KDColor s_gaugeIndicatorWorkingBuffer[GaugeView::k_indicatorDiameter*GaugeView::k_indicatorDiameter];
|
||||
|
||||
void GaugeView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(bounds(), m_backgroundColor);
|
||||
/* Draw the gauge centered vertically on all the width available */
|
||||
KDCoordinate width = bounds().width()-k_indicatorDiameter;
|
||||
KDCoordinate height = bounds().height();
|
||||
|
||||
ctx->fillRect(KDRect(k_indicatorDiameter/2, (height-k_thickness)/2, width*m_level, k_thickness), Palette::YellowDark);
|
||||
ctx->fillRect(KDRect(k_indicatorDiameter/2+width*m_level, (height-k_thickness)/2, width*(1.0f-m_level), k_thickness), Palette::GreyDark);
|
||||
KDRect frame(width*m_level, (height-k_indicatorDiameter)/2, k_indicatorDiameter, k_indicatorDiameter);
|
||||
ctx->blendRectWithMask(frame, Palette::YellowDark, (const uint8_t *)gaugeIndicatorMask, s_gaugeIndicatorWorkingBuffer);
|
||||
}
|
||||
|
||||
KDSize GaugeView::minimalSizeForOptimalDisplay() const {
|
||||
return KDSize(12*k_indicatorDiameter, k_indicatorDiameter);
|
||||
}
|
||||
18
escher/src/message_table_cell_with_gauge.cpp
Normal file
18
escher/src/message_table_cell_with_gauge.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <escher/message_table_cell_with_gauge.h>
|
||||
#include <escher/palette.h>
|
||||
|
||||
MessageTableCellWithGauge::MessageTableCellWithGauge(I18n::Message message, KDText::FontSize size) :
|
||||
MessageTableCell(message, size),
|
||||
m_accessoryView()
|
||||
{
|
||||
}
|
||||
|
||||
View * MessageTableCellWithGauge::accessoryView() const {
|
||||
return (View *)&m_accessoryView;
|
||||
}
|
||||
|
||||
void MessageTableCellWithGauge::setHighlighted(bool highlight) {
|
||||
MessageTableCell::setHighlighted(highlight);
|
||||
KDColor backgroundColor = highlight? Palette::Select : KDColorWhite;
|
||||
m_accessoryView.setBackgroundColor(backgroundColor);
|
||||
}
|
||||
Reference in New Issue
Block a user