diff --git a/Makefile b/Makefile index d40c7419a..29a481311 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,7 @@ include libaxx/Makefile endif include ion/Makefile include kandinsky/Makefile -#include poincare/Makefile +include poincare/Makefile include escher/Makefile include apps/Makefile include quiz/Makefile # Quiz should be included at the end diff --git a/poincare/include/poincare/expression_layout.h b/poincare/include/poincare/expression_layout.h index 9b610bb25..493a55fd5 100644 --- a/poincare/include/poincare/expression_layout.h +++ b/poincare/include/poincare/expression_layout.h @@ -1,22 +1,20 @@ #ifndef POINCARE_EXPRESSION_LAYOUT_H #define POINCARE_EXPRESSION_LAYOUT_H -extern "C" { #include -} class ExpressionLayout { public: ExpressionLayout(); virtual ~ExpressionLayout(); - void draw(KDPoint point); + void draw(KDContext * ctx, KDPoint p); KDPoint origin(); KDSize size(); KDCoordinate baseline(); void setParent(ExpressionLayout* parent); protected: - virtual void render(KDPoint point) = 0; + virtual void render(KDContext * ctx, KDPoint p) = 0; virtual KDSize computeSize() = 0; virtual ExpressionLayout * child(uint16_t index) = 0; virtual KDPoint positionOfChild(ExpressionLayout * child) = 0; diff --git a/poincare/src/integer.cpp b/poincare/src/integer.cpp index b712e4f2d..785f38ddb 100644 --- a/poincare/src/integer.cpp +++ b/poincare/src/integer.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include diff --git a/poincare/src/layout/exponent_layout.cpp b/poincare/src/layout/exponent_layout.cpp index 50a7bbd99..afad9f72d 100644 --- a/poincare/src/layout/exponent_layout.cpp +++ b/poincare/src/layout/exponent_layout.cpp @@ -17,17 +17,17 @@ ExponentLayout::~ExponentLayout() { delete m_base_layout; } -// There is nothing to draw for a power, only the position of the children matters -void ExponentLayout::render(KDPoint point) { } +void ExponentLayout::render(KDContext * ctx, KDPoint p) { + // There is nothing to draw for a power, only the position of the children matters +} KDSize ExponentLayout::computeSize() { - KDSize s; - KDSize exponent_size, base_size; - exponent_size = m_exponent_layout->size(); - base_size = m_base_layout->size(); - s.height = base_size.height + exponent_size.height - EXPONENT_HEIGHT; - s.width = base_size.width + exponent_size.width; - return s; + KDSize exponent_size = m_exponent_layout->size(); + KDSize base_size = m_base_layout->size(); + return KDSize( + base_size.height() + exponent_size.height() - EXPONENT_HEIGHT, + base_size.width() + exponent_size.width() + ); } ExpressionLayout * ExponentLayout::child(uint16_t index) { @@ -42,15 +42,16 @@ ExpressionLayout * ExponentLayout::child(uint16_t index) { } KDPoint ExponentLayout::positionOfChild(ExpressionLayout * child) { - KDPoint p; + KDCoordinate x = 0; + KDCoordinate y = 0; if (child == m_base_layout) { - p.x = 0; - p.y = m_exponent_layout->baseline() - EXPONENT_HEIGHT; + x = 0; + y = m_exponent_layout->baseline() - EXPONENT_HEIGHT; } else if (child == m_exponent_layout) { - p.x = m_base_layout->size().width; - p.y = 0; + x = m_base_layout->size().width(); + y = 0; } else { assert(false); // Should not happen } - return p; + return KDPoint(x,y); } diff --git a/poincare/src/layout/exponent_layout.h b/poincare/src/layout/exponent_layout.h index c29eacc1d..727c46a1e 100644 --- a/poincare/src/layout/exponent_layout.h +++ b/poincare/src/layout/exponent_layout.h @@ -9,7 +9,7 @@ class ExponentLayout : public ExpressionLayout { ExponentLayout(ExpressionLayout * base_layout, ExpressionLayout * exponent_layout); ~ExponentLayout(); protected: - void render(KDPoint point) override; + void render(KDContext * ctx, KDPoint p) override; KDSize computeSize() override; ExpressionLayout * child(uint16_t index) override; KDPoint positionOfChild(ExpressionLayout * child) override; diff --git a/poincare/src/layout/expression_layout.cpp b/poincare/src/layout/expression_layout.cpp index 961d296c5..b353758f1 100644 --- a/poincare/src/layout/expression_layout.cpp +++ b/poincare/src/layout/expression_layout.cpp @@ -21,36 +21,37 @@ KDPoint ExpressionLayout::origin() { if (m_parent == nullptr) { return absoluteOrigin(); } else { - return KDPointMake(absoluteOrigin().x-m_parent->absoluteOrigin().x, absoluteOrigin().y-m_parent->absoluteOrigin().y); + return KDPoint(absoluteOrigin().x() - m_parent->absoluteOrigin().x(), + absoluteOrigin().y() - m_parent->absoluteOrigin().y()); } } -void ExpressionLayout::draw(KDPoint point) { +void ExpressionLayout::draw(KDContext * ctx, KDPoint p) { int i = 0; while (ExpressionLayout * c = child(i++)) { - c->draw(point); + c->draw(ctx, p); } - render(KDPointTranslate(absoluteOrigin(), point)); + render(ctx, absoluteOrigin().translatedBy(p)); } KDPoint ExpressionLayout::absoluteOrigin() { if (!m_positioned) { if (m_parent != nullptr) { - m_frame.origin = KDPointTranslate(m_parent->absoluteOrigin(), m_parent->positionOfChild(this)); + m_frame.setOrigin(m_parent->absoluteOrigin().translatedBy(m_parent->positionOfChild(this))); } else { - m_frame.origin = KDPointZero; + m_frame.setOrigin(KDPointZero); } m_positioned = true; } - return m_frame.origin; + return m_frame.origin(); } KDSize ExpressionLayout::size() { if (!m_sized) { - m_frame.size = computeSize(); + m_frame.setSize(computeSize()); m_sized = true; } - return m_frame.size; + return m_frame.size(); } void ExpressionLayout::setParent(ExpressionLayout* parent) { diff --git a/poincare/src/layout/fraction_layout.cpp b/poincare/src/layout/fraction_layout.cpp index a82e7e404..4ac655a87 100644 --- a/poincare/src/layout/fraction_layout.cpp +++ b/poincare/src/layout/fraction_layout.cpp @@ -14,7 +14,9 @@ FractionLayout::FractionLayout(ExpressionLayout * numerator_layout, ExpressionLa ExpressionLayout(), m_numerator_layout(numerator_layout), m_denominator_layout(denominator_layout) { m_numerator_layout->setParent(this); m_denominator_layout->setParent(this); - m_baseline = m_numerator_layout->size().height + FRACTION_LINE_MARGIN + KDStringSize(" ").height/2; + m_baseline = m_numerator_layout->size().height() + + FRACTION_LINE_MARGIN + + KDText::stringSize(" ").height()/2; } FractionLayout::~FractionLayout() { @@ -22,21 +24,23 @@ FractionLayout::~FractionLayout() { delete m_numerator_layout; } -void FractionLayout::render(KDPoint point) { - KDCoordinate fractionLineY = point.y + m_numerator_layout->size().height + FRACTION_LINE_MARGIN; +void FractionLayout::render(KDContext * ctx, KDPoint p) { + KDCoordinate fractionLineY = p.y() + m_numerator_layout->size().height() + FRACTION_LINE_MARGIN; - KDDrawLine( - KDPointMake(point.x, fractionLineY), - KDPointMake(point.x + size().width, fractionLineY), - 0xFF); + ctx->drawLine( + KDPoint(p.x(), fractionLineY), + KDPoint(p.x() + size().width(), fractionLineY), + KDColorRed + ); } KDSize FractionLayout::computeSize() { - KDSize s; - s.width = max(m_numerator_layout->size().width, m_denominator_layout->size().width) + 2*FRACTION_BORDER_LENGTH; - s.height = m_numerator_layout->size().height + FRACTION_LINE_MARGIN - + FRACTION_LINE_HEIGHT + FRACTION_LINE_MARGIN + m_denominator_layout->size().height; - return s; + KDCoordinate width = max(m_numerator_layout->size().width(), m_denominator_layout->size().width()) + + 2*FRACTION_BORDER_LENGTH; + KDCoordinate height = m_numerator_layout->size().height() + + FRACTION_LINE_MARGIN + FRACTION_LINE_HEIGHT + FRACTION_LINE_MARGIN + + m_denominator_layout->size().height(); + return KDSize(width, height); } ExpressionLayout * FractionLayout::child(uint16_t index) { @@ -51,15 +55,15 @@ ExpressionLayout * FractionLayout::child(uint16_t index) { } KDPoint FractionLayout::positionOfChild(ExpressionLayout * child) { - KDPoint p; + KDCoordinate x = 0; + KDCoordinate y = 0; if (child == m_numerator_layout) { - p.x = (KDCoordinate)((size().width - m_numerator_layout->size().width)/2); - p.y = 0; + x = (KDCoordinate)((size().width() - m_numerator_layout->size().width())/2); } else if (child == m_denominator_layout) { - p.x = (KDCoordinate)((size().width - m_denominator_layout->size().width)/2); - p.y = (KDCoordinate)(m_numerator_layout->size().height + 2*FRACTION_LINE_MARGIN + FRACTION_LINE_HEIGHT); + x = (KDCoordinate)((size().width() - m_denominator_layout->size().width())/2); + y = (KDCoordinate)(m_numerator_layout->size().height() + 2*FRACTION_LINE_MARGIN + FRACTION_LINE_HEIGHT); } else { assert(false); // Should not happen } - return p; + return KDPoint(x, y); } diff --git a/poincare/src/layout/fraction_layout.h b/poincare/src/layout/fraction_layout.h index 5d1953ab8..277fa357a 100644 --- a/poincare/src/layout/fraction_layout.h +++ b/poincare/src/layout/fraction_layout.h @@ -9,7 +9,7 @@ class FractionLayout : public ExpressionLayout { FractionLayout(ExpressionLayout * numerator, ExpressionLayout * denominator); ~FractionLayout(); protected: - void render(KDPoint point) override; + void render(KDContext * ctx, KDPoint p) override; KDSize computeSize() override; ExpressionLayout * child(uint16_t index) override; KDPoint positionOfChild(ExpressionLayout * child) override; diff --git a/poincare/src/layout/horizontal_layout.cpp b/poincare/src/layout/horizontal_layout.cpp index 13ef0be7b..e2702cd39 100644 --- a/poincare/src/layout/horizontal_layout.cpp +++ b/poincare/src/layout/horizontal_layout.cpp @@ -24,25 +24,25 @@ HorizontalLayout::~HorizontalLayout() { free(m_children_layouts); } -void HorizontalLayout::render(KDPoint point) { } +void HorizontalLayout::render(KDContext * ctx, KDPoint p) { +} KDSize HorizontalLayout::computeSize() { - KDSize size = (KDSize){.width = 0, .height = 0}; + KDCoordinate totalWidth = 0; int i = 0; KDCoordinate max_under_baseline = 0; KDCoordinate max_above_baseline = 0; while (ExpressionLayout * c = child(i++)) { KDSize childSize = c->size(); - size.width += childSize.width; - if (childSize.height - c->baseline() > max_under_baseline) { - max_under_baseline = childSize.height - c->baseline() ; + totalWidth += childSize.width(); + if (childSize.height() - c->baseline() > max_under_baseline) { + max_under_baseline = childSize.height() - c->baseline() ; } if (c->baseline() > max_above_baseline) { max_above_baseline = c->baseline(); } } - size.height = max_under_baseline + max_above_baseline; - return size; + return KDSize(totalWidth, max_under_baseline + max_above_baseline); } ExpressionLayout * HorizontalLayout::child(uint16_t index) { @@ -55,7 +55,8 @@ ExpressionLayout * HorizontalLayout::child(uint16_t index) { } KDPoint HorizontalLayout::positionOfChild(ExpressionLayout * child) { - KDPoint position = (KDPoint){.x = 0, .y = 0}; + KDCoordinate x = 0; + KDCoordinate y = 0; uint16_t index = 0; for (int i=0;i 0) { ExpressionLayout * previousChild = m_children_layouts[index-1]; assert(previousChild != nullptr); - position.x = previousChild->origin().x + previousChild->size().width; + x = previousChild->origin().x() + previousChild->size().width(); } - position.y = m_baseline - child->baseline(); - return position; + y = m_baseline - child->baseline(); + return KDPoint(x, y); } diff --git a/poincare/src/layout/horizontal_layout.h b/poincare/src/layout/horizontal_layout.h index 44468fc7b..6159d2646 100644 --- a/poincare/src/layout/horizontal_layout.h +++ b/poincare/src/layout/horizontal_layout.h @@ -9,7 +9,7 @@ class HorizontalLayout : public ExpressionLayout { HorizontalLayout(ExpressionLayout ** layouts, int number_of_children); ~HorizontalLayout(); protected: - void render(KDPoint point) override; + void render(KDContext * ctx, KDPoint p) override; KDSize computeSize() override; ExpressionLayout * child(uint16_t index) override; KDPoint positionOfChild(ExpressionLayout * child) override; diff --git a/poincare/src/layout/string_layout.cpp b/poincare/src/layout/string_layout.cpp index fc6148223..29891a904 100644 --- a/poincare/src/layout/string_layout.cpp +++ b/poincare/src/layout/string_layout.cpp @@ -9,7 +9,7 @@ ExpressionLayout() { memcpy(m_string, string, (length+1)); m_inverse = inverse; // Height of the font. - m_baseline = KDStringSize(" ").height; + m_baseline = KDText::stringSize(" ").height(); } StringLayout::~StringLayout() { @@ -20,8 +20,8 @@ ExpressionLayout * StringLayout::child(uint16_t index) { return nullptr; } -void StringLayout::render(KDPoint point) { - KDDrawString(m_string, point, m_inverse); +void StringLayout::render(KDContext * ctx, KDPoint p) { + ctx->drawString(m_string, p, m_inverse); } KDPoint StringLayout::positionOfChild(ExpressionLayout * child) { @@ -30,5 +30,5 @@ KDPoint StringLayout::positionOfChild(ExpressionLayout * child) { } KDSize StringLayout::computeSize() { - return KDStringSize(m_string); + return KDText::stringSize(m_string); } diff --git a/poincare/src/layout/string_layout.h b/poincare/src/layout/string_layout.h index edaed8e3b..616977dc8 100644 --- a/poincare/src/layout/string_layout.h +++ b/poincare/src/layout/string_layout.h @@ -12,7 +12,7 @@ class StringLayout : public ExpressionLayout { StringLayout(const char * string, size_t length, uint8_t inverse=0); ~StringLayout(); protected: - void render(KDPoint point) override; + void render(KDContext * ctx, KDPoint p) override; KDSize computeSize() override; ExpressionLayout * child(uint16_t index) override; KDPoint positionOfChild(ExpressionLayout * child) override;