Blame view

build3/poincare/src/layout/bracket_layout.cpp 1.83 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
  #include "bracket_layout.h"
  extern "C" {
  #include <assert.h>
  #include <stdlib.h>
  }
  
  namespace Poincare {
  
  BracketLayout::BracketLayout(ExpressionLayout * operandLayout) :
    ExpressionLayout(),
    m_operandLayout(operandLayout)
  {
    m_operandLayout->setParent(this);
    m_baseline = m_operandLayout->baseline();
  }
  
  BracketLayout::~BracketLayout() {
    delete m_operandLayout;
  }
  
  void BracketLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
    KDSize operandSize = m_operandLayout->size();
    ctx->fillRect(KDRect(p.x(), p.y(), k_lineThickness, m_operandLayout->size().height()), expressionColor);
    ctx->fillRect(KDRect(p.x()+operandSize.width()+2*widthMargin()+k_lineThickness, p.y(), k_lineThickness, m_operandLayout->size().height()), expressionColor);
    if (renderTopBar()) {
      ctx->fillRect(KDRect(p.x(), p.y(), k_bracketWidth, k_lineThickness), expressionColor);
      ctx->fillRect(KDRect(p.x()+2*k_lineThickness+operandSize.width()+2*widthMargin()-k_bracketWidth, p.y(), k_bracketWidth, k_lineThickness), expressionColor);
    }
    if (renderBottomBar()) {
      ctx->fillRect(KDRect(p.x(), p.y()+operandSize.height()-k_lineThickness, k_bracketWidth, k_lineThickness), expressionColor);
      ctx->fillRect(KDRect(p.x()+2*k_lineThickness+operandSize.width()+2*widthMargin()-k_bracketWidth, p.y()+operandSize.height()-k_lineThickness, k_bracketWidth, k_lineThickness), expressionColor);
    }
  }
  
  KDSize BracketLayout::computeSize() {
    KDSize operandSize = m_operandLayout->size();
    return KDSize(operandSize.width() + 2*widthMargin() + 2*k_lineThickness, operandSize.height());
  }
  
  ExpressionLayout * BracketLayout::child(uint16_t index) {
    if (index == 0) {
      return m_operandLayout;
    }
    return nullptr;
  }
  
  KDPoint BracketLayout::positionOfChild(ExpressionLayout * child) {
    return KDPoint(widthMargin()+k_lineThickness, 0);
  }
  
  }