Numworks Epsilon  1.4.1
Graphing Calculator Operating System
parenthesis_layout.cpp
Go to the documentation of this file.
1 #include "parenthesis_layout.h"
2 extern "C" {
3 #include <assert.h>
4 #include <stdlib.h>
5 }
6 
7 namespace Poincare {
8 
10  {0xFF, 0xFF, 0xFF, 0xF9, 0x66},
11  {0xFF, 0xFF, 0xEB, 0x40, 0x9A},
12  {0xFF, 0xF2, 0x40, 0xBF, 0xFF},
13  {0xFF, 0x49, 0xB6, 0xFF, 0xFF},
14  {0xA9, 0x5A, 0xFF, 0xFF, 0xFF},
15  {0x45, 0xBE, 0xFF, 0xFF, 0xFF},
16  {0x11, 0xEE, 0xFF, 0xFF, 0xFF},
17 
18 };
19 
21  {0x11, 0xEE, 0xFF, 0xFF, 0xFF},
22  {0x45, 0xBE, 0xFF, 0xFF, 0xFF},
23  {0xA9, 0x5A, 0xFF, 0xFF, 0xFF},
24  {0xFF, 0x49, 0xB6, 0xFF, 0xFF},
25  {0xFF, 0xF2, 0x40, 0xBF, 0xFF},
26  {0xFF, 0xFF, 0xEB, 0x40, 0x9A},
27  {0xFF, 0xFF, 0xFF, 0xF9, 0x66},
28 
29 };
30 
32  {0x66, 0xF9, 0xFF, 0xFF, 0xFF},
33  {0x9A, 0x40, 0xEB, 0xFF, 0xFF},
34  {0xFF, 0xBF, 0x40, 0xF2, 0xFF},
35  {0xFF, 0xFF, 0xB6, 0x49, 0xFF},
36  {0xFF, 0xFF, 0xFF, 0x5A, 0xA9},
37  {0xFF, 0xFF, 0xFF, 0xBE, 0x45},
38  {0xFF, 0xFF, 0xFF, 0xEE, 0x11},
39 };
40 
42  {0xFF, 0xFF, 0xFF, 0xEE, 0x11},
43  {0xFF, 0xFF, 0xFF, 0xBE, 0x45},
44  {0xFF, 0xFF, 0xFF, 0x5A, 0xA9},
45  {0xFF, 0xFF, 0xB6, 0x49, 0xFF},
46  {0xFF, 0xBF, 0x40, 0xF2, 0xFF},
47  {0x9A, 0x40, 0xEB, 0xFF, 0xFF},
48  {0x66, 0xF9, 0xFF, 0xFF, 0xFF},
49 
50 };
51 
54  m_operandLayout(operandLayout)
55 {
56  if (m_operandLayout) {
57  m_operandLayout->setParent(this);
58  m_baseline = m_operandLayout->baseline();
59  } else {
61  }
62 }
63 
65  if (m_operandLayout) {
66  delete m_operandLayout;
67  }
68 }
69 
71 
72 void ParenthesisLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
73  KDRect frame(p.x()+k_externWidthMargin, p.y()+k_externHeightMargin, k_parenthesisCurveWidth, k_parenthesisCurveHeight);
74  ctx->blendRectWithMask(frame, expressionColor, (const uint8_t *)topLeftCurve, (KDColor *)s_parenthesisWorkingBuffer);
75  frame = KDRect(p.x()+k_externWidthMargin, p.y() + operandSize().height() - k_parenthesisCurveHeight - k_externHeightMargin,
77  ctx->blendRectWithMask(frame, expressionColor, (const uint8_t *)bottomLeftCurve, (KDColor *)s_parenthesisWorkingBuffer);
78  frame = KDRect(p.x()+k_externWidthMargin + operandSize().width() + 2*k_widthMargin + 2*k_lineThickness - k_parenthesisCurveWidth, p.y() + k_externHeightMargin,
80  ctx->blendRectWithMask(frame, expressionColor, (const uint8_t *)topRightCurve, (KDColor *)s_parenthesisWorkingBuffer);
81  frame = KDRect(p.x() +k_externWidthMargin + operandSize().width() + 2*k_widthMargin + 2*k_lineThickness - k_parenthesisCurveWidth, p.y() + operandSize().height() - k_parenthesisCurveHeight - k_externHeightMargin,
83  ctx->blendRectWithMask(frame, expressionColor, (const uint8_t *)bottomRightCurve, (KDColor *)s_parenthesisWorkingBuffer);
84 
85  ctx->fillRect(KDRect(p.x()+k_externWidthMargin, p.y()+k_parenthesisCurveHeight+k_externHeightMargin, k_lineThickness, operandSize().height() - 2*(k_parenthesisCurveHeight+k_externHeightMargin)), expressionColor);
86  ctx->fillRect(KDRect(p.x()+k_externWidthMargin+operandSize().width()+2*k_widthMargin+k_lineThickness, p.y()+k_parenthesisCurveHeight+2, k_lineThickness, operandSize().height()- 2*(k_parenthesisCurveHeight+k_externHeightMargin)), expressionColor);
87 }
88 
90  return KDSize(operandSize().width() + 2*k_widthMargin + 2*k_lineThickness+2*k_externWidthMargin, operandSize().height());
91 }
92 
94  if (index == 0) {
95  return m_operandLayout;
96  }
97  return nullptr;
98 }
99 
101  return KDPoint(k_widthMargin+k_lineThickness+k_externWidthMargin, 0);
102 }
103 
104 KDSize ParenthesisLayout::operandSize() {
105  return (m_operandLayout ? m_operandLayout->size() : KDSize(0, KDText::charSize(KDText::FontSize::Large).height()));
106 }
107 
108 }
KDCoordinate y() const
Definition: point.h:11
KDColor s_parenthesisWorkingBuffer[ParenthesisLayout::k_parenthesisCurveHeight *ParenthesisLayout::k_parenthesisCurveWidth]
constexpr KDCoordinate width() const
Definition: size.h:10
static constexpr KDCoordinate k_parenthesisCurveHeight
void blendRectWithMask(KDRect rect, KDColor color, const uint8_t *mask, KDColor *workingBuffer)
void render(KDContext *ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override
ExpressionLayout * child(uint16_t index) override
unsigned short uint16_t
Definition: stdint.h:5
unsigned char uint8_t
Definition: stdint.h:4
Definition: point.h:6
Definition: size.h:6
const uint8_t bottomLeftCurve[ParenthesisLayout::k_parenthesisCurveHeight][ParenthesisLayout::k_parenthesisCurveWidth]
KDPoint positionOfChild(ExpressionLayout *child) override
static constexpr KDCoordinate k_parenthesisCurveWidth
const uint8_t topRightCurve[ParenthesisLayout::k_parenthesisCurveHeight][ParenthesisLayout::k_parenthesisCurveWidth]
Definition: rect.h:26
void fillRect(KDRect rect, KDColor color)
Definition: context_rect.cpp:8
Definition: color.h:6
static constexpr KDSize charSize(FontSize size=FontSize::Large)
Definition: text.h:16
KDCoordinate x() const
Definition: point.h:10
void setParent(ExpressionLayout *parent)
const uint8_t topLeftCurve[ParenthesisLayout::k_parenthesisCurveHeight][ParenthesisLayout::k_parenthesisCurveWidth]
const uint8_t bottomRightCurve[ParenthesisLayout::k_parenthesisCurveHeight][ParenthesisLayout::k_parenthesisCurveWidth]
ParenthesisLayout(ExpressionLayout *operandLayout)
constexpr KDCoordinate height() const
Definition: size.h:11