diff --git a/escher/Makefile b/escher/Makefile index b167eda82..7c5f07c5f 100644 --- a/escher/Makefile +++ b/escher/Makefile @@ -5,6 +5,7 @@ objs += $(addprefix escher/src/,\ childless_view.o\ responder.o\ scroll_view.o\ + scroll_view_indicator.o\ solid_color_view.o\ tab_view.o\ tab_view_cell.o\ diff --git a/escher/include/escher.h b/escher/include/escher.h index b6d9a57ff..2a57be397 100644 --- a/escher/include/escher.h +++ b/escher/include/escher.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include diff --git a/escher/include/escher/scroll_view_indicator.h b/escher/include/escher/scroll_view_indicator.h new file mode 100644 index 000000000..0e4787067 --- /dev/null +++ b/escher/include/escher/scroll_view_indicator.h @@ -0,0 +1,28 @@ +#ifndef ESCHER_SCROLL_VIEW_INDICATOR_H +#define ESCHER_SCROLL_VIEW_INDICATOR_H + +#include + +class ScrollViewIndicator : public ChildlessView { +public: + enum class Direction { + Horizontal, + Vertical + }; + ScrollViewIndicator(Direction direction); + void drawRect(KDRect rect) const override; + + void setStart(float start); + void setEnd(float end); +protected: +#if ESCHER_VIEW_LOGGING + virtual const char * className() const override; + virtual void logAttributes(std::ostream &os) const override; +#endif +private: + Direction m_direction; + float m_start; + float m_end; +}; + +#endif diff --git a/escher/src/scroll_view_indicator.cpp b/escher/src/scroll_view_indicator.cpp new file mode 100644 index 000000000..2f4dd7382 --- /dev/null +++ b/escher/src/scroll_view_indicator.cpp @@ -0,0 +1,55 @@ +#include +extern "C" { +#include +} + +constexpr KDColor k_backgroundColor = 0x00; +constexpr KDColor k_indicatorColor = 0x30; + +ScrollViewIndicator::ScrollViewIndicator(ScrollViewIndicator::Direction direction) : + ChildlessView(), + m_direction(direction), + m_start(0), + m_end(0) +{ +} + +void ScrollViewIndicator::drawRect(KDRect rect) const { + KDFillRect(bounds(), k_backgroundColor); + KDRect indicatorFrame; + if (m_direction == Direction::Horizontal) { + indicatorFrame.x = m_start*bounds().width; + indicatorFrame.y = 0; + indicatorFrame.width = (m_end-m_start)*bounds().width; + indicatorFrame.height = bounds().height; + } else { + assert(m_direction == Direction::Vertical); + indicatorFrame.x = 0; + indicatorFrame.y = m_start*bounds().height; + indicatorFrame.width = bounds().width; + indicatorFrame.height = (m_end-m_start)*bounds().height; + } + KDFillRect(indicatorFrame, k_indicatorColor); +} + +void ScrollViewIndicator::setStart(float start) { + m_start = start; + redraw(); +} + +void ScrollViewIndicator::setEnd(float end) { + m_end = end; + redraw(); +} + +#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