Blame view

Modif/epsilon-master/escher/src/key_view.cpp 3.98 KB
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
  #include <escher/key_view.h>
  
  const uint8_t upMask[KeyView::k_keySize][KeyView::k_keySize] = {
    {0xFF, 0xFF, 0xFF, 0x45, 0x45, 0xFF, 0xFF, 0xFF},
    {0xFF, 0xFF, 0xE1, 0x00, 0x00, 0xE1, 0xFF, 0xFF},
    {0xFF, 0xFF, 0x45, 0x0C, 0x0C, 0x45, 0xFF, 0xFF},
    {0xFF, 0xE1, 0x00, 0xE1, 0xE1, 0x00, 0xE1, 0xFF},
    {0xFF, 0x45, 0x0C, 0xFF, 0xFF, 0x0C, 0x45, 0xFF},
    {0xE1, 0x00, 0xE1, 0xFF, 0xFF, 0xE1, 0x00, 0xE1},
    {0x45, 0x0C, 0xE1, 0xE1, 0xE1, 0xE1, 0x0C, 0x45},
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  };
  
  const uint8_t downMask[KeyView::k_keySize][KeyView::k_keySize] = {
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    {0x45, 0x0C, 0xE1, 0xE1, 0xE1, 0xE1, 0x0C, 0x45},
    {0xE1, 0x00, 0xE1, 0xFF, 0xFF, 0xE1, 0x00, 0xE1},
    {0xFF, 0x45, 0x0C, 0xFF, 0xFF, 0x0C, 0x45, 0xFF},
    {0xFF, 0xE1, 0x00, 0xE1, 0xE1, 0x00, 0xE1, 0xFF},
    {0xFF, 0xFF, 0x45, 0x0C, 0x0C, 0x45, 0xFF, 0xFF},
    {0xFF, 0xFF, 0xE1, 0x00, 0x00, 0xE1, 0xFF, 0xFF},
    {0xFF, 0xFF, 0xFF, 0x45, 0x45, 0xFF, 0xFF, 0xFF},
  };
  
  const uint8_t leftMask[KeyView::k_keySize][KeyView::k_keySize] = {
    {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE1, 0x45, 0x00},
    {0xFF, 0xFF, 0xFF, 0xE1, 0x45, 0x00, 0x0C, 0x00},
    {0xFF, 0xE1, 0x45, 0x00, 0x0C, 0xE1, 0xE1, 0x00},
    {0x45, 0x00, 0x0C, 0xE1, 0xFF, 0xFF, 0xE1, 0x00},
    {0x45, 0x00, 0x0C, 0xE1, 0xFF, 0xFF, 0xE1, 0x00},
    {0xFF, 0xE1, 0x45, 0x00, 0x0C, 0xE1, 0xE1, 0x00},
    {0xFF, 0xFF, 0xFF, 0xE1, 0x45, 0x00, 0x0C, 0x00},
    {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE1, 0x45, 0x00},
  };
  
  const uint8_t rightMask[KeyView::k_keySize][KeyView::k_keySize] = {
    {0x00, 0x45, 0xE1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
    {0x00, 0x0C, 0x00, 0x45, 0xE1, 0xFF, 0xFF, 0xFF},
    {0x00, 0xE1, 0xE1, 0x0C, 0x00, 0x45, 0xE1, 0xFF},
    {0x00, 0xE1, 0xFF, 0xFF, 0xE1, 0x0C, 0x00, 0x45},
    {0x00, 0xE1, 0xFF, 0xFF, 0xE1, 0x0C, 0x00, 0x45},
    {0x00, 0xE1, 0xE1, 0x0C, 0x00, 0x45, 0xE1, 0xE1},
    {0x00, 0x0C, 0x00, 0x45, 0xE1, 0xFF, 0xFF, 0xFF},
    {0x00, 0x45, 0xE1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  };
  
  const uint8_t plusMask[KeyView::k_keySize][KeyView::k_keySize] = {
    {0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF},
    {0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF},
    {0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF},
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    {0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF},
    {0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF},
    {0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF},
  };
  
  const uint8_t minusMask[KeyView::k_keySize][KeyView::k_keySize] = {
    {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
    {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
    {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
    {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
    {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  };
  
  KeyView::KeyView(Type type) :
    m_type(type)
  {
  }
  
  void KeyView::setType(Type type) {
    m_type = type;
    markRectAsDirty(bounds());
  }
  
  KDColor s_keyWorkingBuffer[KeyView::k_keySize*KeyView::k_keySize];
  
  void KeyView::drawRect(KDContext * ctx, KDRect rect) const {
    /* Draw the key centered on the view. */
    KDCoordinate width = bounds().width();
    KDCoordinate height =  bounds().height();
    KDRect frame((width - k_keySize)/2, (height - k_keySize)/2, k_keySize, k_keySize);
    ctx->blendRectWithMask(frame, KDColorBlack, mask(), s_keyWorkingBuffer);
  }
  
  KDSize KeyView::minimalSizeForOptimalDisplay() const {
    return KDSize(k_keySize, k_keySize);
  }
  
  const uint8_t * KeyView::mask() const {
    switch (m_type) {
      case Type::Up:
        return (const uint8_t *)upMask;
      case Type::Down:
        return (const uint8_t *)downMask;
      case Type::Left:
        return (const uint8_t *)leftMask;
      case Type::Right:
        return (const uint8_t *)rightMask;
      case Type::Plus:
        return (const uint8_t *)plusMask;
      case Type::Minus:
        return (const uint8_t *)minusMask;
      default:
        return nullptr;
    }
  }