* Transformable::Reset() + Invert() didn't notify

* Path and StyleContainer take an index in Add...()
* FlatIconImporter works when "appending" another icon


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18448 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2006-08-07 20:47:20 +00:00
parent 6091ae51b0
commit 014c7e9459
9 changed files with 85 additions and 21 deletions

View File

@ -35,6 +35,9 @@ using std::nothrow;
// constructor
FlatIconImporter::FlatIconImporter()
#ifdef ICON_O_MATIC
: Importer()
#endif
{
}
@ -47,6 +50,14 @@ FlatIconImporter::~FlatIconImporter()
status_t
FlatIconImporter::Import(Icon* icon, BPositionIO* stream)
{
#ifdef ICON_O_MATIC
status_t ret = Init(icon);
if (ret < B_OK)
return ret;
#else
status_t ret;
#endif
// seek around in the stream to figure out the size
off_t size = stream->Seek(0, SEEK_END);
if (stream->Seek(0, SEEK_SET) != 0)
@ -64,7 +75,7 @@ FlatIconImporter::Import(Icon* icon, BPositionIO* stream)
if (stream->Read(buffer.Buffer(), size) != size)
return B_ERROR;
status_t ret = _ParseSections(buffer, icon);
ret = _ParseSections(buffer, icon);
return ret;
}
@ -73,6 +84,12 @@ FlatIconImporter::Import(Icon* icon, BPositionIO* stream)
status_t
FlatIconImporter::Import(Icon* icon, uint8* _buffer, size_t size)
{
#ifdef ICON_O_MATIC
status_t ret = Init(icon);
if (ret < B_OK)
return ret;
#endif
if (!_buffer)
return B_BAD_VALUE;
@ -465,9 +482,10 @@ _ReadTransformer(LittleEndianBuffer& buffer, VertexSource& source)
}
// _ReadPathSourceShape
static Shape*
_ReadPathSourceShape(LittleEndianBuffer& buffer,
StyleContainer* styles, PathContainer* paths)
Shape*
FlatIconImporter::_ReadPathSourceShape(LittleEndianBuffer& buffer,
StyleContainer* styles,
PathContainer* paths)
{
// find out which style this shape uses
uint8 styleIndex;
@ -475,7 +493,12 @@ _ReadPathSourceShape(LittleEndianBuffer& buffer,
if (!buffer.Read(styleIndex) || !buffer.Read(pathCount))
return NULL;
#ifdef ICON_O_MATIC
Style* style = styles->StyleAt(StyleIndexFor(styleIndex));
#else
Style* style = styles->StyleAt(styleIndex);
#endif
if (!style) {
printf("_ReadPathSourceShape() - "
"shape references non-existing style %d\n", styleIndex);
@ -495,7 +518,11 @@ _ReadPathSourceShape(LittleEndianBuffer& buffer,
if (!buffer.Read(pathIndex))
return NULL;
#ifdef ICON_O_MATIC
VectorPath* path = paths->PathAt(PathIndexFor(pathIndex));
#else
VectorPath* path = paths->PathAt(pathIndex);
#endif
if (!path) {
printf("_ReadPathSourceShape() - "
"shape references non-existing path %d\n", pathIndex);

View File

@ -9,17 +9,26 @@
#ifndef FLAT_ICON_IMPORTER_H
#define FLAT_ICON_IMPORTER_H
#include <SupportDefs.h>
#ifdef ICON_O_MATIC
# include "Importer.h"
#else
# include <SupportDefs.h>
#endif
class BMessage;
class BPositionIO;
class Icon;
class LittleEndianBuffer;
class PathContainer;
class Shape;
class ShapeContainer;
class StyleContainer;
#ifdef ICON_O_MATIC
class FlatIconImporter : public Importer {
#else
class FlatIconImporter {
#endif
public:
FlatIconImporter();
virtual ~FlatIconImporter();
@ -40,6 +49,10 @@ class FlatIconImporter {
StyleContainer* styles);
status_t _ParsePaths(LittleEndianBuffer& buffer,
PathContainer* paths);
Shape* _ReadPathSourceShape(
LittleEndianBuffer& buffer,
StyleContainer* styles,
PathContainer* paths);
status_t _ParseShapes(LittleEndianBuffer& buffer,
StyleContainer* styles,
PathContainer* paths,

View File

@ -49,6 +49,13 @@ PathContainer::~PathContainer()
// AddPath
bool
PathContainer::AddPath(VectorPath* path)
{
return AddPath(path, CountPaths());
}
// AddPath
bool
PathContainer::AddPath(VectorPath* path, int32 index)
{
if (!path)
return false;
@ -57,9 +64,9 @@ PathContainer::AddPath(VectorPath* path)
if (HasPath(path))
return false;
if (fPaths.AddItem((void*)path)) {
if (fPaths.AddItem((void*)path, index)) {
#ifdef ICON_O_MATIC
_NotifyPathAdded(path);
_NotifyPathAdded(path, index);
#endif
return true;
}
@ -186,14 +193,14 @@ PathContainer::_MakeEmpty()
#ifdef ICON_O_MATIC
// _NotifyPathAdded
void
PathContainer::_NotifyPathAdded(VectorPath* path) const
PathContainer::_NotifyPathAdded(VectorPath* path, int32 index) const
{
BList listeners(fListeners);
int32 count = listeners.CountItems();
for (int32 i = 0; i < count; i++) {
PathContainerListener* listener
= (PathContainerListener*)listeners.ItemAtFast(i);
listener->PathAdded(path);
listener->PathAdded(path, index);
}
}

View File

@ -19,7 +19,7 @@ class PathContainerListener {
PathContainerListener();
virtual ~PathContainerListener();
virtual void PathAdded(VectorPath* path) = 0;
virtual void PathAdded(VectorPath* path, int32 index) = 0;
virtual void PathRemoved(VectorPath* path) = 0;
};
#endif // ICON_O_MATIC
@ -30,6 +30,7 @@ class PathContainer {
virtual ~PathContainer();
bool AddPath(VectorPath* path);
bool AddPath(VectorPath* path, int32 index);
bool RemovePath(VectorPath* path);
VectorPath* RemovePath(int32 index);
@ -54,7 +55,8 @@ class PathContainer {
bool RemoveListener(PathContainerListener* listener);
private:
void _NotifyPathAdded(VectorPath* path) const;
void _NotifyPathAdded(VectorPath* path,
int32 index) const;
void _NotifyPathRemoved(VectorPath* path) const;
BList fListeners;

View File

@ -329,7 +329,7 @@ Shape::ObjectChanged(const Observable* object)
// PathAdded
void
Shape::PathAdded(VectorPath* path)
Shape::PathAdded(VectorPath* path, int32 index)
{
path->Acquire();
path->AddListener(this);

View File

@ -72,7 +72,7 @@ class Shape : public Transformable {
virtual void ObjectChanged(const Observable* object);
// PathContainerListener interface
virtual void PathAdded(VectorPath* path);
virtual void PathAdded(VectorPath* path, int32 index);
virtual void PathRemoved(VectorPath* path);
// PathListener interface

View File

@ -49,6 +49,13 @@ StyleContainer::~StyleContainer()
// AddStyle
bool
StyleContainer::AddStyle(Style* style)
{
return AddStyle(style, CountStyles());
}
// AddStyle
bool
StyleContainer::AddStyle(Style* style, int32 index)
{
if (!style)
return false;
@ -57,9 +64,9 @@ StyleContainer::AddStyle(Style* style)
if (HasStyle(style))
return false;
if (fStyles.AddItem((void*)style)) {
if (fStyles.AddItem((void*)style, index)) {
#ifdef ICON_O_MATIC
_NotifyStyleAdded(style);
_NotifyStyleAdded(style, index);
#endif
return true;
}
@ -187,14 +194,14 @@ StyleContainer::_MakeEmpty()
// _NotifyStyleAdded
void
StyleContainer::_NotifyStyleAdded(Style* style) const
StyleContainer::_NotifyStyleAdded(Style* style, int32 index) const
{
BList listeners(fListeners);
int32 count = listeners.CountItems();
for (int32 i = 0; i < count; i++) {
StyleContainerListener* listener
= (StyleContainerListener*)listeners.ItemAtFast(i);
listener->StyleAdded(style);
listener->StyleAdded(style, index);
}
}

View File

@ -19,7 +19,7 @@ class StyleContainerListener {
StyleContainerListener();
virtual ~StyleContainerListener();
virtual void StyleAdded(Style* style) = 0;
virtual void StyleAdded(Style* style, int32 index) = 0;
virtual void StyleRemoved(Style* style) = 0;
};
#endif // ICON_O_MATIC
@ -30,6 +30,7 @@ class StyleContainer {
virtual ~StyleContainer();
bool AddStyle(Style* style);
bool AddStyle(Style* style, int32 index);
bool RemoveStyle(Style* style);
Style* RemoveStyle(int32 index);
@ -53,7 +54,8 @@ class StyleContainer {
bool RemoveListener(StyleContainerListener* listener);
private:
void _NotifyStyleAdded(Style* style) const;
void _NotifyStyleAdded(Style* style,
int32 index) const;
void _NotifyStyleRemoved(Style* style) const;
BList fListeners;

View File

@ -87,14 +87,20 @@ Transformable::Multiply(const Transformable& other)
void
Transformable::Reset()
{
reset();
if (!IsIdentity()) {
reset();
TransformationChanged();
}
}
// Invert
void
Transformable::Invert()
{
invert();
if (!IsIdentity()) {
invert();
TransformationChanged();
}
}
// IsIdentity