From 863200445bde9225dc1bf61596a36d7d9e49754f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 13 Jan 2017 17:39:35 +0100 Subject: [PATCH] [poincare] Create a class integral layout Change-Id: I0d41d9b92477837ed367e6a2c4359b609aa8e1c1 --- poincare/Makefile | 1 + poincare/src/layout/integral_layout.cpp | 93 +++++++++++++++++++++++++ poincare/src/layout/integral_layout.h | 29 ++++++++ 3 files changed, 123 insertions(+) create mode 100644 poincare/src/layout/integral_layout.cpp create mode 100644 poincare/src/layout/integral_layout.h diff --git a/poincare/Makefile b/poincare/Makefile index aac9d10ba..e21184261 100644 --- a/poincare/Makefile +++ b/poincare/Makefile @@ -42,6 +42,7 @@ objs += $(addprefix poincare/src/layout/,\ expression_layout.o\ fraction_layout.o\ horizontal_layout.o\ + integral_layout.o\ matrix_layout.o\ nth_root_layout.o\ parenthesis_layout.o\ diff --git a/poincare/src/layout/integral_layout.cpp b/poincare/src/layout/integral_layout.cpp new file mode 100644 index 000000000..353420b93 --- /dev/null +++ b/poincare/src/layout/integral_layout.cpp @@ -0,0 +1,93 @@ +#include "integral_layout.h" +#include +#include + +const uint8_t topSymbolPixel[IntegralLayout::k_symbolHeight][IntegralLayout::k_symbolWidth] = { + {0x00, 0x00, 0xFF, 0xFF}, + {0xFF, 0xFF, 0x00, 0xFF}, + {0xFF, 0xFF, 0x00, 0x00}, + {0xFF, 0xFF, 0x00, 0x00}, +}; + +const uint8_t bottomSymbolPixel[IntegralLayout::k_symbolHeight][IntegralLayout::k_symbolWidth] = { + {0x00, 0x00, 0xFF, 0xFF}, + {0x00, 0x00, 0xFF, 0xFF}, + {0xFF, 0x00, 0xFF, 0xFF}, + {0xFF, 0xFF, 0x00, 0x00}, +}; + +IntegralLayout::IntegralLayout(ExpressionLayout * lowerBoundLayout, ExpressionLayout * upperBoundLayout, ExpressionLayout * integrandLayout) : + ExpressionLayout(), + m_lowerBoundLayout(lowerBoundLayout), + m_upperBoundLayout(upperBoundLayout), + m_integrandLayout(integrandLayout) +{ + m_lowerBoundLayout->setParent(this); + m_upperBoundLayout->setParent(this); + m_integrandLayout->setParent(this); + m_baseline = m_upperBoundLayout->size().height() + k_integrandHeigthMargin + m_integrandLayout->baseline(); +} + +IntegralLayout::~IntegralLayout() { + delete m_lowerBoundLayout; + delete m_upperBoundLayout; + delete m_integrandLayout; +} + +void IntegralLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) { + KDSize integrandSize = m_integrandLayout->size(); + KDSize upperBoundSize = m_upperBoundLayout->size(); + KDColor workingBuffer[k_symbolWidth*k_symbolHeight]; + KDRect topSymbolFrame(p.x() + k_symbolWidth + k_lineThickness, p.y() + upperBoundSize.height() - k_boundHeightMargin, + k_symbolWidth, k_symbolHeight); + ctx->blendRectWithMask(topSymbolFrame, expressionColor, (const uint8_t *)topSymbolPixel, (KDColor *)workingBuffer); + KDRect bottomSymbolFrame(p.x(), + p.y() + upperBoundSize.height() + 2*k_integrandHeigthMargin + integrandSize.height() + k_boundHeightMargin - k_symbolHeight, + k_symbolWidth, k_symbolHeight); + ctx->blendRectWithMask(bottomSymbolFrame, expressionColor, (const uint8_t *)bottomSymbolPixel, (KDColor *)workingBuffer); + ctx->fillRect(KDRect(p.x() + k_symbolWidth, p.y() + upperBoundSize.height() - k_boundHeightMargin, k_lineThickness, + 2*k_boundHeightMargin+2*k_integrandHeigthMargin+integrandSize.height()), expressionColor); +} + +KDSize IntegralLayout::computeSize() { + KDSize integrandSize = m_integrandLayout->size(); + KDSize lowerBoundSize = m_lowerBoundLayout->size(); + KDSize upperBoundSize = m_upperBoundLayout->size(); + return KDSize( + k_symbolWidth+k_lineThickness+k_boundWidthMargin+max(lowerBoundSize.width(), upperBoundSize.width())+k_integrandWidthMargin+integrandSize.width(), + upperBoundSize.height()+ 2*k_integrandHeigthMargin+integrandSize.height()+lowerBoundSize.height()); +} + +ExpressionLayout * IntegralLayout::child(uint16_t index) { + switch (index) { + case 0: + return m_upperBoundLayout; + case 1: + return m_lowerBoundLayout; + case 2: + return m_integrandLayout; + default: + return nullptr; + } +} + +KDPoint IntegralLayout::positionOfChild(ExpressionLayout * child) { + KDSize integrandSize = m_integrandLayout->size(); + KDSize lowerBoundSize = m_lowerBoundLayout->size(); + KDSize upperBoundSize = m_upperBoundLayout->size(); + KDCoordinate x = 0; + KDCoordinate y = 0; + if (child == m_lowerBoundLayout) { + x = k_symbolWidth+k_lineThickness+k_boundWidthMargin; + y = upperBoundSize.height()+2*k_integrandHeigthMargin+integrandSize.height(); + } else if (child == m_upperBoundLayout) { + x = k_symbolWidth+k_lineThickness+k_boundWidthMargin;; + y = 0; + } else if (child == m_integrandLayout) { + x = k_symbolWidth +k_lineThickness+ k_boundWidthMargin+max(lowerBoundSize.width(), upperBoundSize.width())+k_integrandWidthMargin; + y = upperBoundSize.height()+k_integrandHeigthMargin; + } else { + assert(false); + } + return KDPoint(x,y); +} diff --git a/poincare/src/layout/integral_layout.h b/poincare/src/layout/integral_layout.h new file mode 100644 index 000000000..c9ae69a8b --- /dev/null +++ b/poincare/src/layout/integral_layout.h @@ -0,0 +1,29 @@ +#ifndef POINCARE_INTEGRAL_LAYOUT_H +#define POINCARE_INTEGRAL_LAYOUT_H + +#include +#include + +class IntegralLayout : public ExpressionLayout { +public: + IntegralLayout(ExpressionLayout * lowerBoundLayout, ExpressionLayout * upperBoundLayout, ExpressionLayout * integrandLayout); + ~IntegralLayout(); + constexpr static KDCoordinate k_symbolHeight = 4; + constexpr static KDCoordinate k_symbolWidth = 4; +protected: + void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; + KDSize computeSize() override; + ExpressionLayout * child(uint16_t index) override; + KDPoint positionOfChild(ExpressionLayout * child) override; +private: + constexpr static KDCoordinate k_boundHeightMargin = 8; + constexpr static KDCoordinate k_boundWidthMargin = 5; + constexpr static KDCoordinate k_integrandWidthMargin = 2; + constexpr static KDCoordinate k_integrandHeigthMargin = 2; + constexpr static KDCoordinate k_lineThickness = 1; + ExpressionLayout * m_lowerBoundLayout; + ExpressionLayout * m_upperBoundLayout; + ExpressionLayout * m_integrandLayout; +}; + +#endif