Blame view

epsilon-master/poincare/src/layout/left_parenthesis_layout.cpp 2.48 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
  #include "left_parenthesis_layout.h"
  extern "C" {
  #include <assert.h>
  #include <stdlib.h>
  }
  
  namespace Poincare {
  
  const uint8_t topLeftCurve[ParenthesisLayout::k_parenthesisCurveHeight][ParenthesisLayout::k_parenthesisCurveWidth] = {
    {0xFF, 0xFF, 0xFF, 0xF9, 0x66},
    {0xFF, 0xFF, 0xEB, 0x40, 0x9A},
    {0xFF, 0xF2, 0x40, 0xBF, 0xFF},
    {0xFF, 0x49, 0xB6, 0xFF, 0xFF},
    {0xA9, 0x5A, 0xFF, 0xFF, 0xFF},
    {0x45, 0xBE, 0xFF, 0xFF, 0xFF},
    {0x11, 0xEE, 0xFF, 0xFF, 0xFF},
  };
  
  const uint8_t bottomLeftCurve[ParenthesisLayout::k_parenthesisCurveHeight][ParenthesisLayout::k_parenthesisCurveWidth] = {
    {0x11, 0xEE, 0xFF, 0xFF, 0xFF},
    {0x45, 0xBE, 0xFF, 0xFF, 0xFF},
    {0xA9, 0x5A, 0xFF, 0xFF, 0xFF},
    {0xFF, 0x49, 0xB6, 0xFF, 0xFF},
    {0xFF, 0xF2, 0x40, 0xBF, 0xFF},
    {0xFF, 0xFF, 0xEB, 0x40, 0x9A},
    {0xFF, 0xFF, 0xFF, 0xF9, 0x66},
  };
  
  ExpressionLayout * LeftParenthesisLayout::clone() const {
    LeftParenthesisLayout * layout = new LeftParenthesisLayout();
    return layout;
  }
  
  bool LeftParenthesisLayout::isCollapsable(int * numberOfOpenParenthesis, bool goingLeft) const {
    if (*numberOfOpenParenthesis == 0 && goingLeft) {
      return false;
    }
    *numberOfOpenParenthesis = goingLeft ? *numberOfOpenParenthesis - 1 : *numberOfOpenParenthesis + 1;
    return true;
  }
  
  void LeftParenthesisLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
    KDRect frame(p.x()+ParenthesisLayout::k_externWidthMargin,
        p.y()+ParenthesisLayout::k_externHeightMargin,
        ParenthesisLayout::k_parenthesisCurveWidth,
        ParenthesisLayout::k_parenthesisCurveHeight);
  
    ctx->blendRectWithMask(frame, expressionColor, (const uint8_t *)topLeftCurve, (KDColor *)(ParenthesisLayout::s_parenthesisWorkingBuffer));
  
    frame = KDRect(p.x()+ParenthesisLayout::k_externWidthMargin,
        p.y() + size().height() - ParenthesisLayout::k_parenthesisCurveHeight - ParenthesisLayout::k_externHeightMargin,
        ParenthesisLayout::k_parenthesisCurveWidth,
        ParenthesisLayout::k_parenthesisCurveHeight);
  
    ctx->blendRectWithMask(frame, expressionColor, (const uint8_t *)bottomLeftCurve, (KDColor *)(ParenthesisLayout::s_parenthesisWorkingBuffer));
  
    ctx->fillRect(KDRect(p.x()+ParenthesisLayout::k_externWidthMargin,
          p.y()+ParenthesisLayout::k_parenthesisCurveHeight+ParenthesisLayout::k_externHeightMargin,
          ParenthesisLayout::k_lineThickness,
          size().height() - 2*(ParenthesisLayout::k_parenthesisCurveHeight+ParenthesisLayout::k_externHeightMargin)),
        expressionColor);
  }
  
  }