From 8f30223aab7787829edbb23f435a932befada35e Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Fri, 27 May 2016 12:08:00 +0200 Subject: [PATCH] Escher: Add ESCHER_VIEW_LOGGING Change-Id: Id0b588069839f9b1d2330eae55a7fd345740cf1b --- escher/include/escher/solid_color_view.h | 4 ++++ escher/include/escher/tab_view.h | 3 +++ escher/include/escher/tab_view_cell.h | 4 ++++ escher/include/escher/tab_view_controller.h | 4 ++++ escher/include/escher/text_view.h | 4 ++++ escher/include/escher/view.h | 11 ++++++++++ escher/include/escher/window.h | 3 +++ escher/src/solid_color_view.cpp | 6 ++++++ escher/src/tab_view.cpp | 6 ++++++ escher/src/tab_view_cell.cpp | 7 +++++++ escher/src/tab_view_controller.cpp | 6 ++++++ escher/src/text_view.cpp | 6 ++++++ escher/src/view.cpp | 23 +++++++++++++++++++++ escher/src/window.cpp | 6 ++++++ 14 files changed, 93 insertions(+) diff --git a/escher/include/escher/solid_color_view.h b/escher/include/escher/solid_color_view.h index 613fb1808..661f72367 100644 --- a/escher/include/escher/solid_color_view.h +++ b/escher/include/escher/solid_color_view.h @@ -7,6 +7,10 @@ class SolidColorView : public ChildlessView { public: SolidColorView(KDColor color); void drawRect(KDRect rect) const override; +protected: +#if ESCHER_VIEW_LOGGING + const char * className() const override; +#endif private: KDColor m_color; }; diff --git a/escher/include/escher/tab_view.h b/escher/include/escher/tab_view.h index 78ed48e61..079d97ff1 100644 --- a/escher/include/escher/tab_view.h +++ b/escher/include/escher/tab_view.h @@ -17,6 +17,9 @@ public: //TODO: void removeLastTab(); void setActiveIndex(int index); protected: +#if ESCHER_VIEW_LOGGING + const char * className() const override; +#endif void storeSubviewAtIndex(View * view, int index) override; private: static constexpr uint8_t k_maxNumberOfTabs = 4; diff --git a/escher/include/escher/tab_view_cell.h b/escher/include/escher/tab_view_cell.h index bf9418752..6b248c9d8 100644 --- a/escher/include/escher/tab_view_cell.h +++ b/escher/include/escher/tab_view_cell.h @@ -10,6 +10,10 @@ public: void drawRect(KDRect rect) const override; void setName(const char * name); void setActive(bool active); +protected: +#if ESCHER_VIEW_LOGGING + const char * className() const override; +#endif private: bool m_active; const char * m_name; diff --git a/escher/include/escher/tab_view_controller.h b/escher/include/escher/tab_view_controller.h index 943b04336..726d2def4 100644 --- a/escher/include/escher/tab_view_controller.h +++ b/escher/include/escher/tab_view_controller.h @@ -26,6 +26,10 @@ private: void setActiveView(View * view); TabView m_tabView; + protected: +#if ESCHER_VIEW_LOGGING + const char * className() const override; +#endif private: View * m_activeView; }; diff --git a/escher/include/escher/text_view.h b/escher/include/escher/text_view.h index 31c475537..7483b259f 100644 --- a/escher/include/escher/text_view.h +++ b/escher/include/escher/text_view.h @@ -14,6 +14,10 @@ public: float verticalAlignment); void drawRect(KDRect rect) const override; void setText(const char * text); +protected: +#if ESCHER_VIEW_LOGGING + const char * className() const override; +#endif private: const char * m_text; float m_horizontalAlignment; diff --git a/escher/include/escher/view.h b/escher/include/escher/view.h index b85be4c24..f22817936 100644 --- a/escher/include/escher/view.h +++ b/escher/include/escher/view.h @@ -6,6 +6,10 @@ extern "C" { #include } +#if ESCHER_VIEW_LOGGING +#include +#endif + /* Key concepts * - A View always clips: you cannot draw outside its frame (TODO!) * - A View can redraw its whole hierarchy, but a very important optimization is @@ -28,7 +32,14 @@ public: void setSubview(View * v, int index); KDRect bounds() const; +#if ESCHER_VIEW_LOGGING + friend std::ostream &operator<<(std::ostream &os, const View &view); +#endif protected: +#if ESCHER_VIEW_LOGGING + virtual const char * className() const; + virtual void logAttributes(std::ostream &os) const; +#endif virtual bool isOnScreen() const; virtual int numberOfSubviews() const = 0; virtual const View * subview(int index) const = 0; diff --git a/escher/include/escher/window.h b/escher/include/escher/window.h index c3d274986..a6c978a31 100644 --- a/escher/include/escher/window.h +++ b/escher/include/escher/window.h @@ -7,6 +7,9 @@ class Window : public View { public: Window(); protected: +#if ESCHER_VIEW_LOGGING + const char * className() const override; +#endif bool isOnScreen() const override; int numberOfSubviews() const override; const View * subview(int index) const override; diff --git a/escher/src/solid_color_view.cpp b/escher/src/solid_color_view.cpp index 0f8986e67..8dffd3f31 100644 --- a/escher/src/solid_color_view.cpp +++ b/escher/src/solid_color_view.cpp @@ -9,3 +9,9 @@ SolidColorView::SolidColorView(KDColor color) : void SolidColorView::drawRect(KDRect rect) const { KDFillRect(rect, m_color); } + +#if ESCHER_VIEW_LOGGING +const char * SolidColorView::className() const { + return "SolidColorView"; +} +#endif diff --git a/escher/src/tab_view.cpp b/escher/src/tab_view.cpp index 9aae44093..f40463683 100644 --- a/escher/src/tab_view.cpp +++ b/escher/src/tab_view.cpp @@ -56,3 +56,9 @@ void TabView::storeSubviewAtIndex(View * view, int index) { // We're not doing anything here, because we already store all the subviews we ever wanna have assert(&m_cells[index] == view); } + +#if ESCHER_VIEW_LOGGING +const char * TabView::className() const { + return "TabView"; +} +#endif diff --git a/escher/src/tab_view_cell.cpp b/escher/src/tab_view_cell.cpp index 9e1279fb6..da42a51ff 100644 --- a/escher/src/tab_view_cell.cpp +++ b/escher/src/tab_view_cell.cpp @@ -23,3 +23,10 @@ void TabViewCell::setActive(bool active) { void TabViewCell::drawRect(KDRect rect) const { KDDrawString(m_name, {0,0}, m_active); } + +#if ESCHER_VIEW_LOGGING +const char * TabViewCell::className() const { + return "TabViewCell"; +} +#endif + diff --git a/escher/src/tab_view_controller.cpp b/escher/src/tab_view_controller.cpp index 1a2a526bc..da089f56d 100644 --- a/escher/src/tab_view_controller.cpp +++ b/escher/src/tab_view_controller.cpp @@ -52,6 +52,12 @@ void TabViewController::ContentView::storeSubviewAtIndex(View * view, int index) } } +#if ESCHER_VIEW_LOGGING +const char * TabViewController::ContentView::className() const { + return "TabViewController::ContentView"; +} +#endif + TabViewController::TabViewController(ViewController ** children, uint8_t numberOfChildren) : m_children(children), m_numberOfChildren(numberOfChildren), diff --git a/escher/src/text_view.cpp b/escher/src/text_view.cpp index bea2f4ae7..696ef0a3f 100644 --- a/escher/src/text_view.cpp +++ b/escher/src/text_view.cpp @@ -24,3 +24,9 @@ void TextView::drawRect(KDRect rect) const { }; KDDrawString(m_text, origin, 0); } + +#if ESCHER_VIEW_LOGGING +const char * TextView::className() const { + return "TextView"; +} +#endif diff --git a/escher/src/view.cpp b/escher/src/view.cpp index aba31af29..fd0a5daf4 100644 --- a/escher/src/view.cpp +++ b/escher/src/view.cpp @@ -130,3 +130,26 @@ KDRect View::absoluteDrawingArea() const { return KDRectIntersection(absoluteFrame, parentDrawingArea); } } + +#if ESCHER_VIEW_LOGGING +const char * View::className() const { + return "View"; +} + +void View::logAttributes(std::ostream &os) const { + os << " frame=\"" << m_frame.x << "," << m_frame.y << "," << m_frame.width << "," << m_frame.height << "\""; + //os << " child_count=\"" << numberOfSubviews() << "\""; +} + +std::ostream &operator<<(std::ostream &os, const View &view) { + os << "<" << view.className(); + view.logAttributes(os); + os << ">"; + for (int i=0; i"; + return os; +} +#endif + diff --git a/escher/src/window.cpp b/escher/src/window.cpp index 30a3263e8..2cf48e8e5 100644 --- a/escher/src/window.cpp +++ b/escher/src/window.cpp @@ -31,3 +31,9 @@ void Window::storeSubviewAtIndex(View * view, int index) { assert(index == 0); m_contentView = view; } + +#if ESCHER_VIEW_LOGGING +const char * Window::className() const { + return "Window"; +} +#endif