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 <waddlesplash@gmail.com>
This commit is contained in:
Zardshard 2023-07-19 12:39:42 -04:00 committed by waddlesplash
parent b7b57869e8
commit c5abd6a796
5 changed files with 52 additions and 73 deletions

View File

@ -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) {

View File

@ -25,7 +25,6 @@ class BReferenceable;
_BEGIN_ICON_NAMESPACE
#ifdef ICON_O_MATIC
template<class Type>
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<Type>* listener);
bool RemoveListener(ContainerListener<Type>* 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<class Type>
ContainerListener<Type>::ContainerListener() {}
template<class Type>
ContainerListener<Type>::~ContainerListener() {}
#endif
template<class Type>
Container<Type>::Container(bool ownsItems)
: fItems(16),
fOwnsItems(ownsItems)
#ifdef ICON_O_MATIC
, fListeners(2)
#endif
fOwnsItems(ownsItems),
fListeners(2)
{
}
@ -108,13 +99,11 @@ Container<Type>::Container(bool ownsItems)
template<class Type>
Container<Type>::~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<Type>::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<Type>::RemoveItem(Type* item)
{
if (fItems.RemoveItem((void*)item)) {
#ifdef ICON_O_MATIC
_NotifyItemRemoved(item);
#endif
return true;
}
@ -173,11 +158,9 @@ Type*
Container<Type>::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<Type>::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<Type>::ItemAtFast(int32 index) const
// #pragma mark -
#ifdef ICON_O_MATIC
template<class Type>
bool
Container<Type>::AddListener(ContainerListener<Type>* listener)
@ -266,13 +248,11 @@ Container<Type>::RemoveListener(ContainerListener<Type>* listener)
{
return fListeners.RemoveItem(listener);
}
#endif // ICON_O_MATIC
// #pragma mark -
#ifdef ICON_O_MATIC
template<class Type>
void
Container<Type>::_NotifyItemAdded(Type* item, int32 index) const
@ -299,7 +279,6 @@ Container<Type>::_NotifyItemRemoved(Type* item) const
listener->ItemRemoved(item);
}
}
#endif // ICON_O_MATIC
_END_ICON_NAMESPACE

View File

@ -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
{

View File

@ -53,7 +53,8 @@ class Shape : public IconObject,
public ContainerListener<Transformer>,
public PathListener {
#else
class Shape : public _ICON_NAMESPACE Transformable {
class Shape : public _ICON_NAMESPACE Transformable,
public ContainerListener<Transformer> {
#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<Transformer> 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<Transformer> interface
virtual void ItemAdded(Transformer* t, int32 index);
virtual void ItemRemoved(Transformer* t);
// Shape
virtual status_t InitCheck() const;
virtual Shape* Clone() const = 0;

View File

@ -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;
};