Numworks Epsilon  1.4.1
Graphing Calculator Operating System
scroll_view_indicator.cpp
Go to the documentation of this file.
2 #include <escher/palette.h>
3 extern "C" {
4 #include <assert.h>
5 }
6 
8  View(),
9  m_direction(direction),
10  m_start(0),
11  m_end(0),
12  m_indicatorColor(Palette::GreyDark),
13  m_backgroundColor(Palette::GreyMiddle),
14  m_margin(14)
15 {
16 }
17 
20  if (m_direction == Direction::Horizontal) {
21  frame = KDRect(m_margin, (m_frame.height() - k_indicatorThickness)/2,
22  m_frame.width() - 2*m_margin, k_indicatorThickness);
23  } else {
24  assert(m_direction == Direction::Vertical);
25  frame = KDRect((m_frame.width() - k_indicatorThickness)/2, m_margin,
26  k_indicatorThickness, m_frame.height() - 2*m_margin);
27  }
28  ctx->fillRect(frame, m_backgroundColor);
29  KDRect indicatorFrame = KDRectZero;
30  if (m_direction == Direction::Horizontal) {
31  KDCoordinate indicatorWidth = m_frame.width() - 2*m_margin;
32  indicatorFrame = KDRect(m_margin+m_start*indicatorWidth, (m_frame.height() - k_indicatorThickness)/2,
33  (m_end-m_start)*indicatorWidth, k_indicatorThickness);
34  } else {
35  assert(m_direction == Direction::Vertical);
36  KDCoordinate indicatorHeight = m_frame.height() - 2*m_margin;
37  indicatorFrame = KDRect((m_frame.width() - k_indicatorThickness)/2, m_margin+m_start*indicatorHeight,
38  k_indicatorThickness, (m_end-m_start)*indicatorHeight);
39  }
40  ctx->fillRect(indicatorFrame, m_indicatorColor);
41 }
42 
44  return m_start;
45 }
46 
48  if (m_start != start) {
49  m_start = start;
51  }
52 }
53 
54 float ScrollViewIndicator::end() const {
55  return m_end;
56 }
57 
58 void ScrollViewIndicator::setEnd(float end) {
59  if (m_end != end) {
60  m_end = end;
62  }
63 }
64 
66  return m_frame;
67 }
68 #if ESCHER_VIEW_LOGGING
69 const char * ScrollViewIndicator::className() const {
70  return "ScrollViewIndicator";
71 }
72 
73 void ScrollViewIndicator::logAttributes(std::ostream &os) const {
74  View::logAttributes(os);
75  os << " start=\"" << m_start << "\"";
76  os << " end=\"" << m_end << "\"";
77 }
78 #endif
#define assert(e)
Definition: assert.h:9
int16_t KDCoordinate
Definition: coordinate.h:6
void markRectAsDirty(KDRect rect)
Definition: view.cpp:39
KDRect m_frame
Definition: view.h:66
void start()
Definition: rt0.cpp:31
ScrollViewIndicator(Direction direction)
constexpr KDRect KDRectZero
Definition: rect.h:70
Definition: rect.h:26
void fillRect(KDRect rect, KDColor color)
Definition: context_rect.cpp:8
Definition: view.h:23
void setStart(float start)
KDCoordinate width() const
Definition: rect.h:39
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157
void drawRect(KDContext *ctx, KDRect rect) const override
Definition: palette.h:6