parenthesis_layout.cpp
4.5 KB
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
#include "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},
};
const uint8_t topRightCurve[ParenthesisLayout::k_parenthesisCurveHeight][ParenthesisLayout::k_parenthesisCurveWidth] = {
{0x66, 0xF9, 0xFF, 0xFF, 0xFF},
{0x9A, 0x40, 0xEB, 0xFF, 0xFF},
{0xFF, 0xBF, 0x40, 0xF2, 0xFF},
{0xFF, 0xFF, 0xB6, 0x49, 0xFF},
{0xFF, 0xFF, 0xFF, 0x5A, 0xA9},
{0xFF, 0xFF, 0xFF, 0xBE, 0x45},
{0xFF, 0xFF, 0xFF, 0xEE, 0x11},
};
const uint8_t bottomRightCurve[ParenthesisLayout::k_parenthesisCurveHeight][ParenthesisLayout::k_parenthesisCurveWidth] = {
{0xFF, 0xFF, 0xFF, 0xEE, 0x11},
{0xFF, 0xFF, 0xFF, 0xBE, 0x45},
{0xFF, 0xFF, 0xFF, 0x5A, 0xA9},
{0xFF, 0xFF, 0xB6, 0x49, 0xFF},
{0xFF, 0xBF, 0x40, 0xF2, 0xFF},
{0x9A, 0x40, 0xEB, 0xFF, 0xFF},
{0x66, 0xF9, 0xFF, 0xFF, 0xFF},
};
ParenthesisLayout::ParenthesisLayout(ExpressionLayout * operandLayout) :
ExpressionLayout(),
m_operandLayout(operandLayout)
{
if (m_operandLayout) {
m_operandLayout->setParent(this);
m_baseline = m_operandLayout->baseline();
} else {
m_baseline = (KDText::charSize(KDText::FontSize::Large).height()+1)/2;
}
}
ParenthesisLayout::~ParenthesisLayout() {
if (m_operandLayout) {
delete m_operandLayout;
}
}
KDColor s_parenthesisWorkingBuffer[ParenthesisLayout::k_parenthesisCurveHeight*ParenthesisLayout::k_parenthesisCurveWidth];
void ParenthesisLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
KDRect frame(p.x()+k_externWidthMargin, p.y()+k_externHeightMargin, k_parenthesisCurveWidth, k_parenthesisCurveHeight);
ctx->blendRectWithMask(frame, expressionColor, (const uint8_t *)topLeftCurve, (KDColor *)s_parenthesisWorkingBuffer);
frame = KDRect(p.x()+k_externWidthMargin, p.y() + operandSize().height() - k_parenthesisCurveHeight - k_externHeightMargin,
k_parenthesisCurveWidth, k_parenthesisCurveHeight);
ctx->blendRectWithMask(frame, expressionColor, (const uint8_t *)bottomLeftCurve, (KDColor *)s_parenthesisWorkingBuffer);
frame = KDRect(p.x()+k_externWidthMargin + operandSize().width() + 2*k_widthMargin + 2*k_lineThickness - k_parenthesisCurveWidth, p.y() + k_externHeightMargin,
k_parenthesisCurveWidth, k_parenthesisCurveHeight);
ctx->blendRectWithMask(frame, expressionColor, (const uint8_t *)topRightCurve, (KDColor *)s_parenthesisWorkingBuffer);
frame = KDRect(p.x() +k_externWidthMargin + operandSize().width() + 2*k_widthMargin + 2*k_lineThickness - k_parenthesisCurveWidth, p.y() + operandSize().height() - k_parenthesisCurveHeight - k_externHeightMargin,
k_parenthesisCurveWidth, k_parenthesisCurveHeight);
ctx->blendRectWithMask(frame, expressionColor, (const uint8_t *)bottomRightCurve, (KDColor *)s_parenthesisWorkingBuffer);
ctx->fillRect(KDRect(p.x()+k_externWidthMargin, p.y()+k_parenthesisCurveHeight+k_externHeightMargin, k_lineThickness, operandSize().height() - 2*(k_parenthesisCurveHeight+k_externHeightMargin)), expressionColor);
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);
}
KDSize ParenthesisLayout::computeSize() {
return KDSize(operandSize().width() + 2*k_widthMargin + 2*k_lineThickness+2*k_externWidthMargin, operandSize().height());
}
ExpressionLayout * ParenthesisLayout::child(uint16_t index) {
if (index == 0) {
return m_operandLayout;
}
return nullptr;
}
KDPoint ParenthesisLayout::positionOfChild(ExpressionLayout * child) {
return KDPoint(k_widthMargin+k_lineThickness+k_externWidthMargin, 0);
}
KDSize ParenthesisLayout::operandSize() {
return (m_operandLayout ? m_operandLayout->size() : KDSize(0, KDText::charSize(KDText::FontSize::Large).height()));
}
}