Blame view

build6/epsilon-master/escher/src/scroll_view_indicator.cpp 2.23 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  #include <escher/scroll_view_indicator.h>
  #include <escher/palette.h>
  extern "C" {
  #include <assert.h>
  }
  
  ScrollViewIndicator::ScrollViewIndicator(ScrollViewIndicator::Direction direction) :
    View(),
    m_direction(direction),
    m_start(0),
    m_end(0),
    m_indicatorColor(Palette::GreyDark),
    m_backgroundColor(Palette::GreyMiddle),
    m_margin(14)
  {
  }
  
  void ScrollViewIndicator::drawRect(KDContext * ctx, KDRect rect) const {
    KDRect frame = KDRectZero;
    if (m_direction == Direction::Horizontal) {
      frame = KDRect(m_margin, (m_frame.height() - k_indicatorThickness)/2,
          m_frame.width() - 2*m_margin, k_indicatorThickness);
    } else {
      assert(m_direction == Direction::Vertical);
      frame = KDRect((m_frame.width() - k_indicatorThickness)/2, m_margin,
          k_indicatorThickness, m_frame.height() - 2*m_margin);
    }
    ctx->fillRect(frame, m_backgroundColor);
    KDRect indicatorFrame = KDRectZero;
    if (m_direction == Direction::Horizontal) {
      KDCoordinate indicatorWidth = m_frame.width() - 2*m_margin;
      indicatorFrame = KDRect(m_margin+m_start*indicatorWidth, (m_frame.height() - k_indicatorThickness)/2,
          (m_end-m_start)*indicatorWidth, k_indicatorThickness);
    } else {
      assert(m_direction == Direction::Vertical);
      KDCoordinate indicatorHeight = m_frame.height() - 2*m_margin;
      indicatorFrame = KDRect((m_frame.width() - k_indicatorThickness)/2, m_margin+m_start*indicatorHeight,
          k_indicatorThickness, (m_end-m_start)*indicatorHeight);
    }
    ctx->fillRect(indicatorFrame, m_indicatorColor);
  }
  
  float ScrollViewIndicator::start() const {
    return m_start;
  }
  
  void ScrollViewIndicator::setStart(float start) {
    if (m_start != start) {
      m_start = start;
      markRectAsDirty(bounds());
    }
  }
  
  float ScrollViewIndicator::end() const {
    return m_end;
  }
  
  void ScrollViewIndicator::setEnd(float end) {
    if (m_end != end) {
      m_end = end;
      markRectAsDirty(bounds());
    }
  }
  
  KDRect ScrollViewIndicator::frame() {
    return m_frame;
  }
  #if ESCHER_VIEW_LOGGING
  const char * ScrollViewIndicator::className() const {
    return "ScrollViewIndicator";
  }
  
  void ScrollViewIndicator::logAttributes(std::ostream &os) const {
    View::logAttributes(os);
    os << " start=\"" << m_start << "\"";
    os << " end=\"" << m_end << "\"";
  }
  #endif