diff --git a/poincare/Makefile b/poincare/Makefile index 8c2a18e69..b46e58a1e 100644 --- a/poincare/Makefile +++ b/poincare/Makefile @@ -14,6 +14,7 @@ objs += $(addprefix poincare/src/,\ layout_cursor.o\ layout_node.o\ layout_reference.o\ + product_layout_node.o\ sequence_layout_node.o\ sum_layout_node.o\ vertical_offset_layout_node.o\ diff --git a/poincare/include/poincare.h b/poincare/include/poincare.h index 4fe451774..1b714e32a 100644 --- a/poincare/include/poincare.h +++ b/poincare/include/poincare.h @@ -67,6 +67,7 @@ #include #include #include +#include #include #include #include diff --git a/poincare/include/poincare/product_layout_node.h b/poincare/include/poincare/product_layout_node.h new file mode 100644 index 000000000..310d5450e --- /dev/null +++ b/poincare/include/poincare/product_layout_node.h @@ -0,0 +1,31 @@ +#ifndef POINCARE_PRODUCT_LAYOUT_NODE_H +#define POINCARE_PRODUCT_LAYOUT_NODE_H + +#include +#include + +namespace Poincare { + +class ProductLayoutNode : public SequenceLayoutNode { +public: + using SequenceLayoutNode::SequenceLayoutNode; + int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override; +protected: + void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; +private: + constexpr static KDCoordinate k_lineThickness = 1; +}; + +class ProductLayoutRef : public LayoutReference { +public: + ProductLayoutRef(TreeNode * n) : LayoutReference(n) {} + ProductLayoutRef(LayoutRef argument, LayoutRef lowerB, LayoutRef upperB) : LayoutReference() { + addChildTreeAtIndex(argument, 0); + addChildTreeAtIndex(lowerB, 1); + addChildTreeAtIndex(upperB, 2); + } +}; + +} + +#endif diff --git a/poincare/src/product.cpp b/poincare/src/product.cpp index 8b7b0e022..9e0b48265 100644 --- a/poincare/src/product.cpp +++ b/poincare/src/product.cpp @@ -1,7 +1,6 @@ #include #include -#include //TODO remove -//#include +#include extern "C" { #include #include @@ -28,8 +27,7 @@ int Product::emptySequenceValue() const { } LayoutRef Product::createSequenceLayout(LayoutRef argumentLayout, LayoutRef subscriptLayout, LayoutRef superscriptLayout) const { - return SumLayoutRef(argumentLayout, subscriptLayout, superscriptLayout); - // TODO return ProductLayoutRef(argumentLayout, subscriptLayout, superscriptLayout); + return ProductLayoutRef(argumentLayout, subscriptLayout, superscriptLayout); } template diff --git a/poincare/src/product_layout_node.cpp b/poincare/src/product_layout_node.cpp new file mode 100644 index 000000000..3b9bb2208 --- /dev/null +++ b/poincare/src/product_layout_node.cpp @@ -0,0 +1,31 @@ +#include +#include +#include + +namespace Poincare { + +int ProductLayoutNode::writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits) const { + return SequenceLayoutNode::writeDerivedClassInBuffer("product", buffer, bufferSize, numberOfSignificantDigits); +} + +void ProductLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) { + // Compute sizes. + KDSize upperBoundSize = upperBoundLayout()->layoutSize(); + KDSize lowerBoundSizeWithNEquals = HorizontalLayoutRef(CharLayoutRef('n'), CharLayoutRef('='), LayoutRef(lowerBoundLayout()).clone()).layoutSize(); + + // Render the Product symbol. + ctx->fillRect(KDRect(p.x() + max(max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundSizeWithNEquals.width()-k_symbolWidth)/2), + p.y() + max(upperBoundSize.height()+k_boundHeightMargin, argumentLayout()->baseline()-(k_symbolHeight+1)/2), + k_lineThickness, k_symbolHeight), expressionColor); + ctx->fillRect(KDRect(p.x() + max(max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundSizeWithNEquals.width()-k_symbolWidth)/2), + p.y() + max(upperBoundSize.height()+k_boundHeightMargin, argumentLayout()->baseline()-(k_symbolHeight+1)/2), + k_symbolWidth, k_lineThickness), expressionColor); + ctx->fillRect(KDRect(p.x() + max(max(0, (upperBoundSize.width()-k_symbolWidth)/2), (lowerBoundSizeWithNEquals.width()-k_symbolWidth)/2)+k_symbolWidth, + p.y() + max(upperBoundSize.height()+k_boundHeightMargin, argumentLayout()->baseline()-(k_symbolHeight+1)/2), + k_lineThickness, k_symbolHeight), expressionColor); + + // Render the "n=" and the parentheses. + SequenceLayoutNode::render(ctx, p, expressionColor, backgroundColor); +} + +}