Numworks Epsilon  1.4.1
Graphing Calculator Operating System
gauge_view.cpp
Go to the documentation of this file.
1 #include <escher/gauge_view.h>
2 #include <escher/palette.h>
3 
5  {0xFF, 0xFF, 0xE1, 0x0C, 0x00, 0x00, 0x0C, 0xE1, 0xFF, 0xFF},
6  {0xFF, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0xFF},
7  {0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE1},
8  {0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C},
9  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
10  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
11  {0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C},
12  {0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE1},
13  {0xFF, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0xFF},
14  {0xFF, 0xFF, 0xE1, 0x0C, 0x00, 0x00, 0x0C, 0xE1, 0xFF, 0xFF},
15 };
16 
18  View(),
19  m_level(1),
20  m_backgroundColor(KDColorWhite)
21 {
22 }
23 
25  return m_level;
26 }
27 
29  if (m_level != level) {
30  level = level < 0 ? 0 : level;
31  level = level > 1 ? 1 : level;
32  m_level = level;
34  }
35 }
36 
38  if (m_backgroundColor != color) {
39  m_backgroundColor = color;
41  }
42 }
43 
45 
46 void GaugeView::drawRect(KDContext * ctx, KDRect rect) const {
47  ctx->fillRect(bounds(), m_backgroundColor);
48  /* Draw the gauge centered vertically on all the width available */
50  KDCoordinate height = bounds().height();
51 
52  ctx->fillRect(KDRect(k_indicatorDiameter/2, (height-k_thickness)/2, width*m_level, k_thickness), Palette::YellowDark);
53  ctx->fillRect(KDRect(k_indicatorDiameter/2+width*m_level, (height-k_thickness)/2, width*(1.0f-m_level), k_thickness), Palette::GreyDark);
54  KDRect frame(width*m_level, (height-k_indicatorDiameter)/2, k_indicatorDiameter, k_indicatorDiameter);
56 }
57 
60 }
Charge level()
Definition: battery.cpp:20
static constexpr KDColor YellowDark
Definition: palette.h:8
void setBackgroundColor(KDColor color)
Definition: gauge_view.cpp:37
int16_t KDCoordinate
Definition: coordinate.h:6
static constexpr KDColor GreyDark
Definition: palette.h:15
void markRectAsDirty(KDRect rect)
Definition: view.cpp:39
void blendRectWithMask(KDRect rect, KDColor color, const uint8_t *mask, KDColor *workingBuffer)
static constexpr KDCoordinate k_indicatorDiameter
Definition: gauge_view.h:14
unsigned char uint8_t
Definition: stdint.h:4
void drawRect(KDContext *ctx, KDRect rect) const override
Definition: gauge_view.cpp:46
Definition: size.h:6
constexpr KDColor KDColorWhite
Definition: color.h:42
KDSize minimalSizeForOptimalDisplay() const override
Definition: gauge_view.cpp:58
KDColor s_gaugeIndicatorWorkingBuffer[GaugeView::k_indicatorDiameter *GaugeView::k_indicatorDiameter]
Definition: gauge_view.cpp:44
Definition: rect.h:26
void fillRect(KDRect rect, KDColor color)
Definition: context_rect.cpp:8
Definition: color.h:6
Definition: view.h:23
const uint8_t gaugeIndicatorMask[GaugeView::k_indicatorDiameter][GaugeView::k_indicatorDiameter]
Definition: gauge_view.cpp:4
KDCoordinate width() const
Definition: rect.h:39
void setLevel(float level)
Definition: gauge_view.cpp:28
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157
float level()
Definition: gauge_view.cpp:24