Numworks Epsilon  1.4.1
Graphing Calculator Operating System
integral_layout.cpp
Go to the documentation of this file.
1 #include "integral_layout.h"
2 #include <string.h>
3 #include <assert.h>
4 
5 namespace Poincare {
6 
8  {0x00, 0x00, 0xFF, 0xFF},
9  {0xFF, 0xFF, 0x00, 0xFF},
10  {0xFF, 0xFF, 0x00, 0x00},
11  {0xFF, 0xFF, 0x00, 0x00},
12 };
13 
15  {0x00, 0x00, 0xFF, 0xFF},
16  {0x00, 0x00, 0xFF, 0xFF},
17  {0xFF, 0x00, 0xFF, 0xFF},
18  {0xFF, 0xFF, 0x00, 0x00},
19 };
20 
21 IntegralLayout::IntegralLayout(ExpressionLayout * lowerBoundLayout, ExpressionLayout * upperBoundLayout, ExpressionLayout * integrandLayout) :
23  m_lowerBoundLayout(lowerBoundLayout),
24  m_upperBoundLayout(upperBoundLayout),
25  m_integrandLayout(integrandLayout)
26 {
27  m_lowerBoundLayout->setParent(this);
28  m_upperBoundLayout->setParent(this);
29  m_integrandLayout->setParent(this);
30  m_baseline = m_upperBoundLayout->size().height() + k_integrandHeigthMargin + m_integrandLayout->baseline();
31 }
32 
34  delete m_lowerBoundLayout;
35  delete m_upperBoundLayout;
36  delete m_integrandLayout;
37 }
38 
39 void IntegralLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
40  KDSize integrandSize = m_integrandLayout->size();
41  KDSize upperBoundSize = m_upperBoundLayout->size();
42  KDColor workingBuffer[k_symbolWidth*k_symbolHeight];
43  KDRect topSymbolFrame(p.x() + k_symbolWidth + k_lineThickness, p.y() + upperBoundSize.height() - k_boundHeightMargin,
45  ctx->blendRectWithMask(topSymbolFrame, expressionColor, (const uint8_t *)topSymbolPixel, (KDColor *)workingBuffer);
46  KDRect bottomSymbolFrame(p.x(),
47  p.y() + upperBoundSize.height() + 2*k_integrandHeigthMargin + integrandSize.height() + k_boundHeightMargin - k_symbolHeight,
49  ctx->blendRectWithMask(bottomSymbolFrame, expressionColor, (const uint8_t *)bottomSymbolPixel, (KDColor *)workingBuffer);
50  ctx->fillRect(KDRect(p.x() + k_symbolWidth, p.y() + upperBoundSize.height() - k_boundHeightMargin, k_lineThickness,
51  2*k_boundHeightMargin+2*k_integrandHeigthMargin+integrandSize.height()), expressionColor);
52 }
53 
55  KDSize integrandSize = m_integrandLayout->size();
56  KDSize lowerBoundSize = m_lowerBoundLayout->size();
57  KDSize upperBoundSize = m_upperBoundLayout->size();
58  return KDSize(
59  k_symbolWidth+k_lineThickness+k_boundWidthMargin+max(lowerBoundSize.width(), upperBoundSize.width())+k_integrandWidthMargin+integrandSize.width(),
60  upperBoundSize.height()+ 2*k_integrandHeigthMargin+integrandSize.height()+lowerBoundSize.height());
61 }
62 
64  switch (index) {
65  case 0:
66  return m_upperBoundLayout;
67  case 1:
68  return m_lowerBoundLayout;
69  case 2:
70  return m_integrandLayout;
71  default:
72  return nullptr;
73  }
74 }
75 
77  KDSize integrandSize = m_integrandLayout->size();
78  KDSize lowerBoundSize = m_lowerBoundLayout->size();
79  KDSize upperBoundSize = m_upperBoundLayout->size();
80  KDCoordinate x = 0;
81  KDCoordinate y = 0;
82  if (child == m_lowerBoundLayout) {
83  x = k_symbolWidth+k_lineThickness+k_boundWidthMargin;
84  y = upperBoundSize.height()+2*k_integrandHeigthMargin+integrandSize.height();
85  } else if (child == m_upperBoundLayout) {
86  x = k_symbolWidth+k_lineThickness+k_boundWidthMargin;;
87  y = 0;
88  } else if (child == m_integrandLayout) {
89  x = k_symbolWidth +k_lineThickness+ k_boundWidthMargin+max(lowerBoundSize.width(), upperBoundSize.width())+k_integrandWidthMargin;
90  y = upperBoundSize.height()+k_integrandHeigthMargin;
91  } else {
92  assert(false);
93  }
94  return KDPoint(x,y);
95 }
96 
97 }
const uint8_t topSymbolPixel[IntegralLayout::k_symbolHeight][IntegralLayout::k_symbolWidth]
KDCoordinate y() const
Definition: point.h:11
#define assert(e)
Definition: assert.h:9
int16_t KDCoordinate
Definition: coordinate.h:6
constexpr KDCoordinate width() const
Definition: size.h:10
void blendRectWithMask(KDRect rect, KDColor color, const uint8_t *mask, KDColor *workingBuffer)
unsigned short uint16_t
Definition: stdint.h:5
unsigned char uint8_t
Definition: stdint.h:4
Definition: point.h:6
Definition: size.h:6
KDSize computeSize() override
Definition: rect.h:26
void fillRect(KDRect rect, KDColor color)
Definition: context_rect.cpp:8
Definition: color.h:6
KDPoint positionOfChild(ExpressionLayout *child) override
IntegralLayout(ExpressionLayout *lowerBoundLayout, ExpressionLayout *upperBoundLayout, ExpressionLayout *integrandLayout)
static constexpr KDCoordinate k_symbolWidth
void render(KDContext *ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override
static constexpr KDCoordinate k_symbolHeight
KDCoordinate x() const
Definition: point.h:10
void setParent(ExpressionLayout *parent)
ExpressionLayout * child(uint16_t index) override
const uint8_t bottomSymbolPixel[IntegralLayout::k_symbolHeight][IntegralLayout::k_symbolWidth]
constexpr KDCoordinate height() const
Definition: size.h:11