Blame view

build3/poincare/src/layout/expression_layout.cpp 1.37 KB
6663b6c9   adorian   projet complet av...
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
  #include <assert.h>
  #include <stdlib.h>
  #include "string_layout.h"
  
  namespace Poincare {
  
  ExpressionLayout::ExpressionLayout() :
    m_baseline(0),
    m_parent(nullptr),
    m_sized(false),
    m_positioned(false),
    m_frame(KDRectZero) {
  }
  
  KDCoordinate ExpressionLayout::baseline() {
    return m_baseline;
  }
  
  KDPoint ExpressionLayout::origin() {
    if (m_parent == nullptr) {
      return absoluteOrigin();
    } else {
      return KDPoint(absoluteOrigin().x() - m_parent->absoluteOrigin().x(),
          absoluteOrigin().y() - m_parent->absoluteOrigin().y());
    }
  }
  
  void ExpressionLayout::draw(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
    int i = 0;
    while (ExpressionLayout * c = child(i++)) {
      c->draw(ctx, p, expressionColor, backgroundColor);
    }
    render(ctx, absoluteOrigin().translatedBy(p), expressionColor, backgroundColor);
  }
  
  KDPoint ExpressionLayout::absoluteOrigin() {
    if (!m_positioned) {
      if (m_parent != nullptr) {
        m_frame.setOrigin(m_parent->absoluteOrigin().translatedBy(m_parent->positionOfChild(this)));
      } else {
        m_frame.setOrigin(KDPointZero);
      }
      m_positioned = true;
    }
    return m_frame.origin();
  }
  
  KDSize ExpressionLayout::size() {
    if (!m_sized) {
      m_frame.setSize(computeSize());
      m_sized = true;
    }
    return m_frame.size();
  }
  
  void ExpressionLayout::setParent(ExpressionLayout* parent) {
    m_parent = parent;
  }
  
  }