From c5abd6a796982af7cc456f832086da2e4a13ad83 Mon Sep 17 00:00:00 2001 From: Zardshard <0azrune6@zard.anonaddy.com> Date: Wed, 19 Jul 2023 12:39:42 -0400 Subject: [PATCH] libicon: Notify Shape on transformer addition/removal hrev57144 accidentally made Shape be notified only if the library was compiled for Icon-O-Matic. Also includes some miscellanious improvements. Fixes #18510 Change-Id: Ie4ae7f9b8b1a5b39f87db2dbf79064fa875b644c Reviewed-on: https://review.haiku-os.org/c/haiku/+/6705 Reviewed-by: waddlesplash --- src/libs/icon/IconRenderer.cpp | 5 +- src/libs/icon/generic/Container.h | 35 +++--------- src/libs/icon/shape/Shape.cpp | 72 ++++++++++++------------- src/libs/icon/shape/Shape.h | 12 ++--- src/libs/icon/transformer/Transformer.h | 1 + 5 files changed, 52 insertions(+), 73 deletions(-) diff --git a/src/libs/icon/IconRenderer.cpp b/src/libs/icon/IconRenderer.cpp index 9af30f57d7..5a9e4fedc2 100644 --- a/src/libs/icon/IconRenderer.cpp +++ b/src/libs/icon/IconRenderer.cpp @@ -483,10 +483,9 @@ IconRenderer::_Render(const BRect& r) Gradient* gradient = style->Gradient(); bool styleAdded = false; if (gradient && !gradient->InheritTransformation()) { - styleAdded = styleHandler.AddStyle(shape->Style(), - fGlobalTransform); + styleAdded = styleHandler.AddStyle(style, fGlobalTransform); } else { - styleAdded = styleHandler.AddStyle(shape->Style(), transform); + styleAdded = styleHandler.AddStyle(style, transform); } if (!styleAdded) { diff --git a/src/libs/icon/generic/Container.h b/src/libs/icon/generic/Container.h index fbb3f9d445..a77b15ff13 100644 --- a/src/libs/icon/generic/Container.h +++ b/src/libs/icon/generic/Container.h @@ -25,7 +25,6 @@ class BReferenceable; _BEGIN_ICON_NAMESPACE -#ifdef ICON_O_MATIC template class ContainerListener { public: @@ -35,7 +34,6 @@ class ContainerListener { virtual void ItemAdded(Type* item, int32 index) = 0; virtual void ItemRemoved(Type* item) = 0; }; -#endif // ICON_O_MATIC /*! @@ -66,12 +64,6 @@ class Container { Type* ItemAt(int32 index) const; Type* ItemAtFast(int32 index) const; - private: - BList fItems; - bool fOwnsItems; - -#ifdef ICON_O_MATIC - public: bool AddListener(ContainerListener* listener); bool RemoveListener(ContainerListener* listener); @@ -79,28 +71,27 @@ class Container { void _NotifyItemAdded(Type* item, int32 index) const; void _NotifyItemRemoved(Type* item) const; + private: + BList fItems; + bool fOwnsItems; + BList fListeners; -#endif // ICON_O_MATIC }; -#ifdef ICON_O_MATIC template ContainerListener::ContainerListener() {} template ContainerListener::~ContainerListener() {} -#endif template Container::Container(bool ownsItems) : fItems(16), - fOwnsItems(ownsItems) -#ifdef ICON_O_MATIC - , fListeners(2) -#endif + fOwnsItems(ownsItems), + fListeners(2) { } @@ -108,13 +99,11 @@ Container::Container(bool ownsItems) template Container::~Container() { -#ifdef ICON_O_MATIC int32 count = fListeners.CountItems(); if (count > 0) { debugger("~Container() - there are still" "listeners attached\n"); } -#endif // ICON_O_MATIC MakeEmpty(); } @@ -142,9 +131,7 @@ Container::AddItem(Type* item, int32 index) return false; if (fItems.AddItem((void*)item, index)) { -#ifdef ICON_O_MATIC _NotifyItemAdded(item, index); -#endif return true; } @@ -158,9 +145,7 @@ bool Container::RemoveItem(Type* item) { if (fItems.RemoveItem((void*)item)) { -#ifdef ICON_O_MATIC _NotifyItemRemoved(item); -#endif return true; } @@ -173,11 +158,9 @@ Type* Container::RemoveItem(int32 index) { Type* item = (Type*)fItems.RemoveItem(index); -#ifdef ICON_O_MATIC if (item) { _NotifyItemRemoved(item); } -#endif return item; } @@ -190,8 +173,8 @@ Container::MakeEmpty() int32 count = CountItems(); for (int32 i = 0; i < count; i++) { Type* item = ItemAtFast(i); -#ifdef ICON_O_MATIC _NotifyItemRemoved(item); +#ifdef ICON_O_MATIC if (fOwnsItems) item->ReleaseReference(); #else @@ -249,7 +232,6 @@ Container::ItemAtFast(int32 index) const // #pragma mark - -#ifdef ICON_O_MATIC template bool Container::AddListener(ContainerListener* listener) @@ -266,13 +248,11 @@ Container::RemoveListener(ContainerListener* listener) { return fListeners.RemoveItem(listener); } -#endif // ICON_O_MATIC // #pragma mark - -#ifdef ICON_O_MATIC template void Container::_NotifyItemAdded(Type* item, int32 index) const @@ -299,7 +279,6 @@ Container::_NotifyItemRemoved(Type* item) const listener->ItemRemoved(item); } } -#endif // ICON_O_MATIC _END_ICON_NAMESPACE diff --git a/src/libs/icon/shape/Shape.cpp b/src/libs/icon/shape/Shape.cpp index 250d02f1f6..a4534902a7 100644 --- a/src/libs/icon/shape/Shape.cpp +++ b/src/libs/icon/shape/Shape.cpp @@ -73,11 +73,11 @@ Shape::Shape(::Style* style) { SetStyle(style); + fTransformers.AddListener(this); + #ifdef ICON_O_MATIC if (fPaths) fPaths->AddListener(this); - - fTransformers.AddListener(this); #endif } @@ -109,11 +109,11 @@ Shape::Shape(const Shape& other) { SetStyle(other.fStyle); + fTransformers.AddListener(this); + if (fPaths) { #ifdef ICON_O_MATIC fPaths->AddListener(this); - - fTransformers.AddListener(this); #endif // copy the path references from @@ -144,11 +144,11 @@ Shape::~Shape() fPaths->MakeEmpty(); #ifdef ICON_O_MATIC fPaths->RemoveListener(this); +#endif + delete fPaths; fTransformers.MakeEmpty(); fTransformers.RemoveListener(this); -#endif - delete fPaths; SetStyle(NULL); } @@ -301,36 +301,6 @@ Shape::ItemRemoved(VectorPath* path) // #pragma mark - -void -Shape::ItemAdded(Transformer* transformer, int32 index) -{ -#ifdef ICON_O_MATIC - transformer->AddObserver(this); - - // TODO: merge Observable and ShapeListener interface - _NotifyRerender(); -#else - fNeedsUpdate = true; -#endif -} - - -void -Shape::ItemRemoved(Transformer* transformer) -{ -#ifdef ICON_O_MATIC - transformer->RemoveObserver(this); - - _NotifyRerender(); -#else - fNeedsUpdate = true; -#endif -} - - -// #pragma mark - - - void Shape::PointAdded(int32 index) { @@ -377,6 +347,36 @@ Shape::PathReversed() // #pragma mark - +void +Shape::ItemAdded(Transformer* transformer, int32 index) +{ +#ifdef ICON_O_MATIC + transformer->AddObserver(this); + + // TODO: merge Observable and ShapeListener interface + _NotifyRerender(); +#else + fNeedsUpdate = true; +#endif +} + + +void +Shape::ItemRemoved(Transformer* transformer) +{ +#ifdef ICON_O_MATIC + transformer->RemoveObserver(this); + + _NotifyRerender(); +#else + fNeedsUpdate = true; +#endif +} + + +// #pragma mark - + + status_t Shape::InitCheck() const { diff --git a/src/libs/icon/shape/Shape.h b/src/libs/icon/shape/Shape.h index e8d3e48da3..7b7f8804ed 100644 --- a/src/libs/icon/shape/Shape.h +++ b/src/libs/icon/shape/Shape.h @@ -53,7 +53,8 @@ class Shape : public IconObject, public ContainerListener, public PathListener { #else -class Shape : public _ICON_NAMESPACE Transformable { +class Shape : public _ICON_NAMESPACE Transformable, + public ContainerListener { #endif public: @@ -81,11 +82,6 @@ class Shape : public _ICON_NAMESPACE Transformable { virtual void ItemAdded(VectorPath* path, int32 index); virtual void ItemRemoved(VectorPath* path); - // ContainerListener interface - virtual void ItemAdded(Transformer* t, int32 index); - virtual void ItemRemoved(Transformer* t); - - // PathListener interface virtual void PointAdded(int32 index); virtual void PointRemoved(int32 index); @@ -97,6 +93,10 @@ class Shape : public _ICON_NAMESPACE Transformable { inline void Notify() {} #endif // ICON_O_MATIC + // ContainerListener interface + virtual void ItemAdded(Transformer* t, int32 index); + virtual void ItemRemoved(Transformer* t); + // Shape virtual status_t InitCheck() const; virtual Shape* Clone() const = 0; diff --git a/src/libs/icon/transformer/Transformer.h b/src/libs/icon/transformer/Transformer.h index b67c1b8fcc..663fe00b54 100644 --- a/src/libs/icon/transformer/Transformer.h +++ b/src/libs/icon/transformer/Transformer.h @@ -30,6 +30,7 @@ class VertexSource { virtual void rewind(unsigned path_id) = 0; virtual unsigned vertex(double* x, double* y) = 0; + /*! Determines whether open paths should be closed or left open. */ virtual bool WantsOpenPaths() const = 0; virtual double ApproximationScale() const = 0; };