Numworks Epsilon  1.4.1
Graphing Calculator Operating System
keyboard_view.cpp
Go to the documentation of this file.
1 #include "keyboard_view.h"
2 #include "../constant.h"
3 #include <poincare.h>
4 
5 using namespace Poincare;
6 
7 namespace HardwareTest {
8 
9 KeyboardView::KeyboardView() :
10  m_testedKeyIndex(0)
11 {
12 }
13 
15  return m_testedKeyIndex;
16 }
17 
19  m_testedKeyIndex = i;
21 }
22 
23 
24 void KeyboardView::drawRect(KDContext * ctx, KDRect rect) const {
25  ctx->fillRect(bounds(), KDColorWhite);
26  for (int i = 0; i < Ion::Keyboard::NumberOfValidKeys; i++) {
27  drawKey(i, ctx, rect);
28  }
29 }
30 
31 void KeyboardView::drawKey(int keyIndex, KDContext * ctx, KDRect rect) const {
32  KDColor color = keyIndex < m_testedKeyIndex ? KDColorGreen: KDColorBlack;
33  if (keyIndex == m_testedKeyIndex) {
34  color = KDColorBlue;
35  }
37  /* the key is on the cross */
38  if ((uint8_t)key < 4) {
39  KDCoordinate x = (uint8_t)key == 1 || (uint8_t)key == 2 ? k_margin + k_smallSquareSize : k_margin;
40  x = (uint8_t)key == 3 ? x + 2*k_smallSquareSize : x;
41  KDCoordinate y = (uint8_t)key == 0 || (uint8_t)key == 3 ? k_margin + k_smallSquareSize : k_margin;
42  y = (uint8_t)key == 2 ? y + 2*k_smallSquareSize : y;
43  ctx->fillRect(KDRect(x, y, k_smallSquareSize, k_smallSquareSize), color);
44  }
45  /* the key is a "OK" or "back" */
46  if ((uint8_t)key >= 4 && (uint8_t)key < 6) {
47  KDCoordinate x = (uint8_t)key == 4 ? 5*k_margin + 3*k_smallSquareSize + 2*k_bigRectWidth : 6*k_margin + 3*k_smallSquareSize + 2*k_bigRectWidth + k_bigSquareSize;
48  KDCoordinate y = 2*k_margin;
49  ctx->fillRect(KDRect(x, y, k_bigSquareSize, k_bigSquareSize), color);
50  }
51  /* the key is a "home" or "power" */
52  if ((uint8_t)key >= 6 && (uint8_t)key < 8) {
53  KDCoordinate x = 3*k_margin + 3*k_smallSquareSize;
54  KDCoordinate y = (uint8_t)key == 6 ? k_margin : 2*k_margin + k_bigRectHeight;
55  ctx->fillRect(KDRect(x, y, k_bigRectWidth, k_bigRectHeight), color);
56  }
57  /* the key is a small key as "shift", "alpha" ...*/
58  if ((uint8_t)key >= 12 && (uint8_t)key < 30) {
59  int j = ((uint8_t)key - 12)/6;
60  int i = ((uint8_t)key - 12) - 6*j;
61  KDCoordinate x = (i+1)*k_margin + i*k_smallRectWidth;
62  KDCoordinate y = 2*k_bigRectHeight + (j+3)*k_margin + j*k_smallRectHeight;
63  ctx->fillRect(KDRect(x, y, k_smallRectWidth, k_smallRectHeight), color);
64  }
65  /* the key is a big key as "7", "Ans" ...*/
66  if ((uint8_t)key >= 30 && (uint8_t)key != 35 && (uint8_t)key != 41 && (uint8_t)key != 47 && (uint8_t)key != 53) {
67  int j = ((uint8_t)key - 30)/6;
68  int i = ((uint8_t)key - 30) - 6*j;
69  KDCoordinate x = (i+1)*k_margin + i*k_bigRectWidth;
70  KDCoordinate y = 2*k_bigRectHeight + 3*k_smallRectHeight + (j+6)*k_margin + j*k_bigRectHeight;
71  ctx->fillRect(KDRect(x, y, k_bigRectWidth, k_bigRectHeight), color);
72  }
73 }
74 
75 }
constexpr KDColor KDColorBlue
Definition: color.h:45
int16_t KDCoordinate
Definition: coordinate.h:6
void markRectAsDirty(KDRect rect)
Definition: view.cpp:39
unsigned char uint8_t
Definition: stdint.h:4
constexpr int NumberOfValidKeys
Definition: keyboard.h:34
constexpr KDColor KDColorWhite
Definition: color.h:42
constexpr KDColor KDColorBlack
Definition: color.h:41
Definition: rect.h:26
void fillRect(KDRect rect, KDColor color)
Definition: context_rect.cpp:8
Definition: color.h:6
void drawRect(KDContext *ctx, KDRect rect) const override
constexpr KDColor KDColorGreen
Definition: color.h:44
constexpr Key ValidKeys[]
Definition: keyboard.h:24
KDRect bounds() const
Definition: view.cpp:157