From 8bd9dd49bb86df7bbcab26f44a766d50675924a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20W=C5=82ostowski?= Date: Wed, 18 Feb 2015 00:43:02 +0100 Subject: [PATCH] view: added quick hiding mechanism in VIEW/VIEW_ITEM --- common/view/view.cpp | 2 +- common/view/view_item.cpp | 11 -------- include/view/view_item.h | 58 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 55 insertions(+), 16 deletions(-) diff --git a/common/view/view.cpp b/common/view/view.cpp index 981c8b0d31..2186c87264 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -564,7 +564,7 @@ struct VIEW::drawItem bool operator()( VIEW_ITEM* aItem ) { // Conditions that have te be fulfilled for an item to be drawn - bool drawCondition = aItem->ViewIsVisible() && + bool drawCondition = aItem->isRenderable() && aItem->ViewGetLOD( layer ) < view->m_scale; if( !drawCondition ) return true; diff --git a/common/view/view_item.cpp b/common/view/view_item.cpp index 900e030e61..f1713f3f0f 100644 --- a/common/view/view_item.cpp +++ b/common/view/view_item.cpp @@ -29,17 +29,6 @@ using namespace KIGFX; -void VIEW_ITEM::ViewSetVisible( bool aIsVisible ) -{ - // update only if the visibility has really changed - if( m_visible != aIsVisible ) - { - m_visible = aIsVisible; - ViewUpdate( APPEARANCE ); - } -} - - void VIEW_ITEM::ViewRelease() { if( m_view && m_view->IsDynamic() ) diff --git a/include/view/view_item.h b/include/view/view_item.h index b2fc558f94..be28c9230f 100644 --- a/include/view/view_item.h +++ b/include/view/view_item.h @@ -76,7 +76,17 @@ public: ALL = 0xff }; - VIEW_ITEM() : m_view( NULL ), m_visible( true ), m_requiredUpdate( ALL ), + /** + * Enum VIEW_VISIBILITY_FLAGS. + * Defines the visibility of the item (temporarily hidden, invisible, etc). + */ + enum VIEW_VISIBILITY_FLAGS { + VISIBLE = 0x01, /// Item is visible (in general) + HIDDEN = 0x02 /// Item is temporarily hidden (e.g. being used by a tool). Overrides VISIBLE flag. + }; + + + VIEW_ITEM() : m_view( NULL ), m_flags( VISIBLE ), m_requiredUpdate( ALL ), m_groups( NULL ), m_groupsSize( 0 ) {} /** @@ -128,7 +138,38 @@ public: * * @param aIsVisible: whether the item is visible (on all layers), or not. */ - void ViewSetVisible( bool aIsVisible = true ); + void ViewSetVisible( bool aIsVisible = true ) + { + bool cur_visible = m_flags & VISIBLE; + + if( cur_visible != aIsVisible ) + { + if(aIsVisible) + m_flags |= VISIBLE; + else + m_flags &= ~VISIBLE; + ViewUpdate( APPEARANCE | COLOR ); + } + } + + /** + * Function ViewHide() + * Temporarily hides the item in the view (e.g. for overlaying) + * + * @param aHide: whether the item is hidden (on all layers), or not. + */ + void ViewHide ( bool aHide = true ) + { + if(! (m_flags & VISIBLE) ) + return; + + if(aHide) + m_flags |= HIDDEN; + else + m_flags &= ~HIDDEN; + + ViewUpdate( APPEARANCE ); + } /** * Function ViewIsVisible() @@ -139,7 +180,7 @@ public: */ bool ViewIsVisible() const { - return m_visible; + return m_flags & VISIBLE; } /** @@ -201,7 +242,7 @@ protected: } VIEW* m_view; ///< Current dynamic view the item is assigned to. - bool m_visible; ///< Are we visible in the current dynamic VIEW. + int m_flags; ///< Visibility flags int m_requiredUpdate; ///< Flag required for updating ///* Helper for storing cached items group ids @@ -295,6 +336,15 @@ protected: { m_requiredUpdate = NONE; } + + /** + * Function isRenderable() + * Returns if the item should be drawn or not. + */ + bool isRenderable() const + { + return m_flags == VISIBLE; + } }; } // namespace KIGFX