Numworks Epsilon  1.4.1
Graphing Calculator Operating System
switch_view.cpp
Go to the documentation of this file.
1 #include <escher/switch_view.h>
2 #include <escher/palette.h>
3 
5  {0xFF, 0xFF, 0xE1, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0xE1, 0xFF, 0xFF},
6  {0xFF, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0xFF},
7  {0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE1},
8  {0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45},
9  {0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C},
10  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
11  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
12  {0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C},
13  {0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45},
14  {0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE1},
15  {0xFF, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0xFF},
16  {0xFF, 0xFF, 0xE1, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0xE1, 0xFF, 0xFF},
17 
18 };
19 
21  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
22  {0xFF, 0xFF, 0xFF, 0xE1, 0x0C, 0x00, 0x00, 0x0C, 0xE1, 0xFF, 0xFF, 0xFF},
23  {0xFF, 0xFF, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0xFF, 0xFF},
24  {0xFF, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE1, 0xFF},
25  {0xFF, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0xFF},
26  {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF},
27  {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF},
28  {0xFF, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0xFF},
29  {0xFF, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE1, 0xFF},
30  {0xFF, 0xFF, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0xFF, 0xFF},
31  {0xFF, 0xFF, 0xFF, 0xE1, 0x0C, 0x00, 0x00, 0x0C, 0xE1, 0xFF, 0xFF, 0xFF},
32  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
33 };
34 
36 View(),
37 m_state(true)
38 {
39 }
40 
42  return m_state;
43 }
44 
45 void SwitchView::setState(bool state) {
46  m_state = state;
48 }
49 
51 
52 void SwitchView::drawRect(KDContext * ctx, KDRect rect) const {
53  /* Draw the switch aligned on the right of the view and vertically centered.
54  * The heightCenter is the coordinate of the vertical middle of the view. That
55  * way, (heightCenter-switchHalfHeight) indicates the top the switch. */
56  KDCoordinate width = bounds().width();
57  KDCoordinate heightCenter = bounds().height()/2;
58  KDCoordinate switchHalfHeight = k_switchHeight/2;
59 
60  KDColor mainColor = m_state ? Palette::YellowDark : Palette::GreyDark;
61  KDRect frame(width - k_switchWidth, heightCenter -switchHalfHeight, k_switchWidth, k_switchHeight);
62  ctx->blendRectWithMask(frame, mainColor, (const uint8_t *)switchMask, s_switchWorkingBuffer);
63  KDCoordinate onOffX = width - (m_state ? k_switchWidth : k_onOffSize);
64  KDRect onOffFrame(onOffX, heightCenter -switchHalfHeight, k_onOffSize, k_onOffSize);
66 }
67 
70 }
KDColor s_switchWorkingBuffer[SwitchView::k_switchWidth *SwitchView::k_switchHeight]
Definition: switch_view.cpp:50
static constexpr KDColor YellowDark
Definition: palette.h:8
const uint8_t switchMask[SwitchView::k_switchHeight][SwitchView::k_switchWidth]
Definition: switch_view.cpp:4
void drawRect(KDContext *ctx, KDRect rect) const override
Definition: switch_view.cpp:52
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)
unsigned char uint8_t
Definition: stdint.h:4
Definition: size.h:6
constexpr KDColor KDColorWhite
Definition: color.h:42
static constexpr KDCoordinate k_switchHeight
Definition: switch_view.h:16
KDSize minimalSizeForOptimalDisplay() const override
Definition: switch_view.cpp:68
bool state()
Definition: switch_view.cpp:41
Definition: rect.h:26
static constexpr KDCoordinate k_onOffSize
Definition: switch_view.h:15
Definition: color.h:6
Definition: view.h:23
KDCoordinate width() const
Definition: rect.h:39
static constexpr KDCoordinate k_switchWidth
Definition: switch_view.h:17
const uint8_t onOffMask[SwitchView::k_onOffSize][SwitchView::k_onOffSize]
Definition: switch_view.cpp:20
void setState(bool state)
Definition: switch_view.cpp:45
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157
#define true
Definition: stdbool.h:8