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 <[email protected]>
This commit is contained in:
@@ -483,10 +483,9 @@ IconRenderer::_Render(const BRect& r)
|
|||||||
Gradient* gradient = style->Gradient();
|
Gradient* gradient = style->Gradient();
|
||||||
bool styleAdded = false;
|
bool styleAdded = false;
|
||||||
if (gradient && !gradient->InheritTransformation()) {
|
if (gradient && !gradient->InheritTransformation()) {
|
||||||
styleAdded = styleHandler.AddStyle(shape->Style(),
|
styleAdded = styleHandler.AddStyle(style, fGlobalTransform);
|
||||||
fGlobalTransform);
|
|
||||||
} else {
|
} else {
|
||||||
styleAdded = styleHandler.AddStyle(shape->Style(), transform);
|
styleAdded = styleHandler.AddStyle(style, transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!styleAdded) {
|
if (!styleAdded) {
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ class BReferenceable;
|
|||||||
_BEGIN_ICON_NAMESPACE
|
_BEGIN_ICON_NAMESPACE
|
||||||
|
|
||||||
|
|
||||||
#ifdef ICON_O_MATIC
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
class ContainerListener {
|
class ContainerListener {
|
||||||
public:
|
public:
|
||||||
@@ -35,7 +34,6 @@ class ContainerListener {
|
|||||||
virtual void ItemAdded(Type* item, int32 index) = 0;
|
virtual void ItemAdded(Type* item, int32 index) = 0;
|
||||||
virtual void ItemRemoved(Type* item) = 0;
|
virtual void ItemRemoved(Type* item) = 0;
|
||||||
};
|
};
|
||||||
#endif // ICON_O_MATIC
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -66,12 +64,6 @@ class Container {
|
|||||||
Type* ItemAt(int32 index) const;
|
Type* ItemAt(int32 index) const;
|
||||||
Type* ItemAtFast(int32 index) const;
|
Type* ItemAtFast(int32 index) const;
|
||||||
|
|
||||||
private:
|
|
||||||
BList fItems;
|
|
||||||
bool fOwnsItems;
|
|
||||||
|
|
||||||
#ifdef ICON_O_MATIC
|
|
||||||
public:
|
|
||||||
bool AddListener(ContainerListener<Type>* listener);
|
bool AddListener(ContainerListener<Type>* listener);
|
||||||
bool RemoveListener(ContainerListener<Type>* listener);
|
bool RemoveListener(ContainerListener<Type>* listener);
|
||||||
|
|
||||||
@@ -79,28 +71,27 @@ class Container {
|
|||||||
void _NotifyItemAdded(Type* item, int32 index) const;
|
void _NotifyItemAdded(Type* item, int32 index) const;
|
||||||
void _NotifyItemRemoved(Type* item) const;
|
void _NotifyItemRemoved(Type* item) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
BList fItems;
|
||||||
|
bool fOwnsItems;
|
||||||
|
|
||||||
BList fListeners;
|
BList fListeners;
|
||||||
#endif // ICON_O_MATIC
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#ifdef ICON_O_MATIC
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
ContainerListener<Type>::ContainerListener() {}
|
ContainerListener<Type>::ContainerListener() {}
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
ContainerListener<Type>::~ContainerListener() {}
|
ContainerListener<Type>::~ContainerListener() {}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
Container<Type>::Container(bool ownsItems)
|
Container<Type>::Container(bool ownsItems)
|
||||||
: fItems(16),
|
: fItems(16),
|
||||||
fOwnsItems(ownsItems)
|
fOwnsItems(ownsItems),
|
||||||
#ifdef ICON_O_MATIC
|
fListeners(2)
|
||||||
, fListeners(2)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,13 +99,11 @@ Container<Type>::Container(bool ownsItems)
|
|||||||
template<class Type>
|
template<class Type>
|
||||||
Container<Type>::~Container()
|
Container<Type>::~Container()
|
||||||
{
|
{
|
||||||
#ifdef ICON_O_MATIC
|
|
||||||
int32 count = fListeners.CountItems();
|
int32 count = fListeners.CountItems();
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
debugger("~Container() - there are still"
|
debugger("~Container() - there are still"
|
||||||
"listeners attached\n");
|
"listeners attached\n");
|
||||||
}
|
}
|
||||||
#endif // ICON_O_MATIC
|
|
||||||
MakeEmpty();
|
MakeEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,9 +131,7 @@ Container<Type>::AddItem(Type* item, int32 index)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (fItems.AddItem((void*)item, index)) {
|
if (fItems.AddItem((void*)item, index)) {
|
||||||
#ifdef ICON_O_MATIC
|
|
||||||
_NotifyItemAdded(item, index);
|
_NotifyItemAdded(item, index);
|
||||||
#endif
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,9 +145,7 @@ bool
|
|||||||
Container<Type>::RemoveItem(Type* item)
|
Container<Type>::RemoveItem(Type* item)
|
||||||
{
|
{
|
||||||
if (fItems.RemoveItem((void*)item)) {
|
if (fItems.RemoveItem((void*)item)) {
|
||||||
#ifdef ICON_O_MATIC
|
|
||||||
_NotifyItemRemoved(item);
|
_NotifyItemRemoved(item);
|
||||||
#endif
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,11 +158,9 @@ Type*
|
|||||||
Container<Type>::RemoveItem(int32 index)
|
Container<Type>::RemoveItem(int32 index)
|
||||||
{
|
{
|
||||||
Type* item = (Type*)fItems.RemoveItem(index);
|
Type* item = (Type*)fItems.RemoveItem(index);
|
||||||
#ifdef ICON_O_MATIC
|
|
||||||
if (item) {
|
if (item) {
|
||||||
_NotifyItemRemoved(item);
|
_NotifyItemRemoved(item);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@@ -190,8 +173,8 @@ Container<Type>::MakeEmpty()
|
|||||||
int32 count = CountItems();
|
int32 count = CountItems();
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
Type* item = ItemAtFast(i);
|
Type* item = ItemAtFast(i);
|
||||||
#ifdef ICON_O_MATIC
|
|
||||||
_NotifyItemRemoved(item);
|
_NotifyItemRemoved(item);
|
||||||
|
#ifdef ICON_O_MATIC
|
||||||
if (fOwnsItems)
|
if (fOwnsItems)
|
||||||
item->ReleaseReference();
|
item->ReleaseReference();
|
||||||
#else
|
#else
|
||||||
@@ -249,7 +232,6 @@ Container<Type>::ItemAtFast(int32 index) const
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
#ifdef ICON_O_MATIC
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
bool
|
bool
|
||||||
Container<Type>::AddListener(ContainerListener<Type>* listener)
|
Container<Type>::AddListener(ContainerListener<Type>* listener)
|
||||||
@@ -266,13 +248,11 @@ Container<Type>::RemoveListener(ContainerListener<Type>* listener)
|
|||||||
{
|
{
|
||||||
return fListeners.RemoveItem(listener);
|
return fListeners.RemoveItem(listener);
|
||||||
}
|
}
|
||||||
#endif // ICON_O_MATIC
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
#ifdef ICON_O_MATIC
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
void
|
void
|
||||||
Container<Type>::_NotifyItemAdded(Type* item, int32 index) const
|
Container<Type>::_NotifyItemAdded(Type* item, int32 index) const
|
||||||
@@ -299,7 +279,6 @@ Container<Type>::_NotifyItemRemoved(Type* item) const
|
|||||||
listener->ItemRemoved(item);
|
listener->ItemRemoved(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // ICON_O_MATIC
|
|
||||||
|
|
||||||
|
|
||||||
_END_ICON_NAMESPACE
|
_END_ICON_NAMESPACE
|
||||||
|
|||||||
@@ -73,11 +73,11 @@ Shape::Shape(::Style* style)
|
|||||||
{
|
{
|
||||||
SetStyle(style);
|
SetStyle(style);
|
||||||
|
|
||||||
|
fTransformers.AddListener(this);
|
||||||
|
|
||||||
#ifdef ICON_O_MATIC
|
#ifdef ICON_O_MATIC
|
||||||
if (fPaths)
|
if (fPaths)
|
||||||
fPaths->AddListener(this);
|
fPaths->AddListener(this);
|
||||||
|
|
||||||
fTransformers.AddListener(this);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,11 +109,11 @@ Shape::Shape(const Shape& other)
|
|||||||
{
|
{
|
||||||
SetStyle(other.fStyle);
|
SetStyle(other.fStyle);
|
||||||
|
|
||||||
|
fTransformers.AddListener(this);
|
||||||
|
|
||||||
if (fPaths) {
|
if (fPaths) {
|
||||||
#ifdef ICON_O_MATIC
|
#ifdef ICON_O_MATIC
|
||||||
fPaths->AddListener(this);
|
fPaths->AddListener(this);
|
||||||
|
|
||||||
fTransformers.AddListener(this);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// copy the path references from
|
// copy the path references from
|
||||||
@@ -144,11 +144,11 @@ Shape::~Shape()
|
|||||||
fPaths->MakeEmpty();
|
fPaths->MakeEmpty();
|
||||||
#ifdef ICON_O_MATIC
|
#ifdef ICON_O_MATIC
|
||||||
fPaths->RemoveListener(this);
|
fPaths->RemoveListener(this);
|
||||||
|
#endif
|
||||||
|
delete fPaths;
|
||||||
|
|
||||||
fTransformers.MakeEmpty();
|
fTransformers.MakeEmpty();
|
||||||
fTransformers.RemoveListener(this);
|
fTransformers.RemoveListener(this);
|
||||||
#endif
|
|
||||||
delete fPaths;
|
|
||||||
|
|
||||||
SetStyle(NULL);
|
SetStyle(NULL);
|
||||||
}
|
}
|
||||||
@@ -301,36 +301,6 @@ Shape::ItemRemoved(VectorPath* path)
|
|||||||
// #pragma mark -
|
// #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
|
void
|
||||||
Shape::PointAdded(int32 index)
|
Shape::PointAdded(int32 index)
|
||||||
{
|
{
|
||||||
@@ -377,6 +347,36 @@ Shape::PathReversed()
|
|||||||
// #pragma mark -
|
// #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
|
status_t
|
||||||
Shape::InitCheck() const
|
Shape::InitCheck() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -53,7 +53,8 @@ class Shape : public IconObject,
|
|||||||
public ContainerListener<Transformer>,
|
public ContainerListener<Transformer>,
|
||||||
public PathListener {
|
public PathListener {
|
||||||
#else
|
#else
|
||||||
class Shape : public _ICON_NAMESPACE Transformable {
|
class Shape : public _ICON_NAMESPACE Transformable,
|
||||||
|
public ContainerListener<Transformer> {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -81,11 +82,6 @@ class Shape : public _ICON_NAMESPACE Transformable {
|
|||||||
virtual void ItemAdded(VectorPath* path, int32 index);
|
virtual void ItemAdded(VectorPath* path, int32 index);
|
||||||
virtual void ItemRemoved(VectorPath* path);
|
virtual void ItemRemoved(VectorPath* path);
|
||||||
|
|
||||||
// ContainerListener<Transformer> interface
|
|
||||||
virtual void ItemAdded(Transformer* t, int32 index);
|
|
||||||
virtual void ItemRemoved(Transformer* t);
|
|
||||||
|
|
||||||
|
|
||||||
// PathListener interface
|
// PathListener interface
|
||||||
virtual void PointAdded(int32 index);
|
virtual void PointAdded(int32 index);
|
||||||
virtual void PointRemoved(int32 index);
|
virtual void PointRemoved(int32 index);
|
||||||
@@ -97,6 +93,10 @@ class Shape : public _ICON_NAMESPACE Transformable {
|
|||||||
inline void Notify() {}
|
inline void Notify() {}
|
||||||
#endif // ICON_O_MATIC
|
#endif // ICON_O_MATIC
|
||||||
|
|
||||||
|
// ContainerListener<Transformer> interface
|
||||||
|
virtual void ItemAdded(Transformer* t, int32 index);
|
||||||
|
virtual void ItemRemoved(Transformer* t);
|
||||||
|
|
||||||
// Shape
|
// Shape
|
||||||
virtual status_t InitCheck() const;
|
virtual status_t InitCheck() const;
|
||||||
virtual Shape* Clone() const = 0;
|
virtual Shape* Clone() const = 0;
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class VertexSource {
|
|||||||
virtual void rewind(unsigned path_id) = 0;
|
virtual void rewind(unsigned path_id) = 0;
|
||||||
virtual unsigned vertex(double* x, double* y) = 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 bool WantsOpenPaths() const = 0;
|
||||||
virtual double ApproximationScale() const = 0;
|
virtual double ApproximationScale() const = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user