Icon-O-Matic: Generalize some classes

* Turns PathContainer, ShapeContainer, StyleContainer into Container.
* Makes Shape use Container for storing Tansformers instead of
  reinventing the wheel yet again.
* Moves common logic from AddPathsCommand, AddStylesCommand,
  AddShapesCommand, and AddTransformersCommand to AddCommand.
* Factors out common logic from two more commands similar to above.
  This adds the MoveCommand and RemoveCommand classes.
* Cleans up some code style.

Change-Id: I59eca94a1c45eac608514f269f6e5f8628f93fab
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6640
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Zardshard
2023-07-14 20:56:49 +00:00
committed by waddlesplash
parent a75a222b35
commit 6427935280
74 changed files with 1711 additions and 3042 deletions
+1 -3
View File
@@ -9,6 +9,7 @@ DEFINES = ICON_O_MATIC=1 ;
local iconSourceDirs = local iconSourceDirs =
icon icon
icon/flat_icon icon/flat_icon
icon/generic
icon/message icon/message
icon/shape icon/shape
icon/style icon/style
@@ -80,17 +81,14 @@ Application Icon-O-Matic :
MessageImporter.cpp MessageImporter.cpp
# icon/shape # icon/shape
PathContainer.cpp
PathSourceShape.cpp PathSourceShape.cpp
ReferenceImage.cpp ReferenceImage.cpp
Shape.cpp Shape.cpp
ShapeContainer.cpp
VectorPath.cpp VectorPath.cpp
# icon/style # icon/style
GradientTransformable.cpp GradientTransformable.cpp
Style.cpp Style.cpp
StyleContainer.cpp
# icon/transformable # icon/transformable
Transformable.cpp Transformable.cpp
+20 -24
View File
@@ -83,11 +83,9 @@
#include "PathSourceShape.h" #include "PathSourceShape.h"
#include "ReferenceImage.h" #include "ReferenceImage.h"
#include "Shape.h" #include "Shape.h"
#include "ShapeContainer.h"
#include "ShapeListView.h" #include "ShapeListView.h"
#include "StrokeTransformer.h" #include "StrokeTransformer.h"
#include "Style.h" #include "Style.h"
#include "StyleContainer.h"
#include "VectorPath.h" #include "VectorPath.h"
#include "StyledTextImporter.h" #include "StyledTextImporter.h"
@@ -202,9 +200,9 @@ MainWindow::MessageReceived(BMessage* message)
Style* style = new (nothrow) Style(*color); Style* style = new (nothrow) Style(*color);
style->SetName(name); style->SetName(name);
Style* styles[1] = { style }; Style* styles[1] = { style };
AddStylesCommand* styleCommand = new (nothrow) AddStylesCommand( AddCommand<Style>* styleCommand = new (nothrow) AddCommand<Style>(
fDocument->Icon()->Styles(), styles, 1, fDocument->Icon()->Styles(), styles, 1, true,
fDocument->Icon()->Styles()->CountStyles()); fDocument->Icon()->Styles()->CountItems());
fDocument->CommandStack()->Perform(styleCommand); fDocument->CommandStack()->Perform(styleCommand);
// don't handle anything else, // don't handle anything else,
// or we might paste the clipboard on B_PASTE // or we might paste the clipboard on B_PASTE
@@ -238,9 +236,9 @@ MainWindow::MessageReceived(BMessage* message)
// otherwise forward to the application which will open // otherwise forward to the application which will open
// it in another window, unless we append. // it in another window, unless we append.
message->what = B_REFS_RECEIVED; message->what = B_REFS_RECEIVED;
if (fDocument->Icon()->Styles()->CountStyles() == 0 if (fDocument->Icon()->Styles()->CountItems() == 0
&& fDocument->Icon()->Paths()->CountPaths() == 0 && fDocument->Icon()->Paths()->CountItems() == 0
&& fDocument->Icon()->Shapes()->CountShapes() == 0) { && fDocument->Icon()->Shapes()->CountItems() == 0) {
Open(ref); Open(ref);
break; break;
} }
@@ -301,9 +299,9 @@ MainWindow::MessageReceived(BMessage* message)
{ {
// If our icon is empty, we want the icon to open in this // If our icon is empty, we want the icon to open in this
// window. // window.
bool emptyDocument = fDocument->Icon()->Styles()->CountStyles() == 0 bool emptyDocument = fDocument->Icon()->Styles()->CountItems() == 0
&& fDocument->Icon()->Paths()->CountPaths() == 0 && fDocument->Icon()->Paths()->CountItems() == 0
&& fDocument->Icon()->Shapes()->CountShapes() == 0; && fDocument->Icon()->Shapes()->CountItems() == 0;
bool openingReferenceImage; bool openingReferenceImage;
if (message->FindBool("reference image", &openingReferenceImage) != B_OK) if (message->FindBool("reference image", &openingReferenceImage) != B_OK)
@@ -443,19 +441,18 @@ MainWindow::MessageReceived(BMessage* message)
if (!style) { if (!style) {
// use current or first style // use current or first style
int32 currentStyle = fStyleListView->CurrentSelection(0); int32 currentStyle = fStyleListView->CurrentSelection(0);
style = fDocument->Icon()->Styles()->StyleAt(currentStyle); style = fDocument->Icon()->Styles()->ItemAt(currentStyle);
if (!style) if (!style)
style = fDocument->Icon()->Styles()->StyleAt(0); style = fDocument->Icon()->Styles()->ItemAt(0);
} }
PathSourceShape* shape = new (nothrow) PathSourceShape(style); PathSourceShape* shape = new (nothrow) PathSourceShape(style);
AddShapesCommand* shapeCommand = new (nothrow) AddShapesCommand( AddShapesCommand* shapeCommand = new (nothrow) AddShapesCommand(
fDocument->Icon()->Shapes(), (Shape**) &shape, 1, fDocument->Icon()->Shapes(), (Shape**) &shape, 1,
fDocument->Icon()->Shapes()->CountShapes(), fDocument->Icon()->Shapes()->CountItems());
fDocument->Selection());
if (path && shape) if (path && shape)
shape->Paths()->AddPath(path); shape->Paths()->AddItem(path);
::Command* command = NULL; ::Command* command = NULL;
if (styleCommand || pathCommand) { if (styleCommand || pathCommand) {
@@ -503,7 +500,7 @@ case MSG_PATH_SELECTED: {
fTransformerListView->SetShape(NULL); fTransformerListView->SetShape(NULL);
fState->DeleteManipulators(); fState->DeleteManipulators();
if (fDocument->Icon()->Paths()->HasPath(path)) { if (fDocument->Icon()->Paths()->HasItem(path)) {
PathManipulator* pathManipulator = new (nothrow) PathManipulator(path); PathManipulator* pathManipulator = new (nothrow) PathManipulator(path);
fState->AddManipulator(pathManipulator); fState->AddManipulator(pathManipulator);
} }
@@ -514,7 +511,7 @@ case MSG_STYLE_TYPE_CHANGED: {
Style* style; Style* style;
if (message->FindPointer("style", (void**)&style) < B_OK) if (message->FindPointer("style", (void**)&style) < B_OK)
style = NULL; style = NULL;
if (!fDocument->Icon()->Styles()->HasStyle(style)) if (!fDocument->Icon()->Styles()->HasItem(style))
style = NULL; style = NULL;
fStyleView->SetStyle(style); fStyleView->SetStyle(style);
@@ -535,7 +532,7 @@ case MSG_SHAPE_SELECTED: {
Shape* shape; Shape* shape;
if (message->FindPointer("shape", (void**)&shape) < B_OK) if (message->FindPointer("shape", (void**)&shape) < B_OK)
shape = NULL; shape = NULL;
if (!fIcon || !fIcon->Shapes()->HasShape(shape)) if (!fIcon || !fIcon->Shapes()->HasItem(shape))
shape = NULL; shape = NULL;
fPathListView->SetCurrentShape(shape); fPathListView->SetCurrentShape(shape);
@@ -543,10 +540,10 @@ case MSG_SHAPE_SELECTED: {
fTransformerListView->SetShape(shape); fTransformerListView->SetShape(shape);
BList selectedShapes; BList selectedShapes;
ShapeContainer* shapes = fDocument->Icon()->Shapes(); Container<Shape>* shapes = fDocument->Icon()->Shapes();
int32 count = shapes->CountShapes(); int32 count = shapes->CountItems();
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
shape = shapes->ShapeAtFast(i); shape = shapes->ItemAtFast(i);
if (shape->IsSelected()) { if (shape->IsSelected()) {
selectedShapes.AddItem((void*)shape); selectedShapes.AddItem((void*)shape);
} }
@@ -868,8 +865,7 @@ MainWindow::AddReferenceImage(const entry_ref& ref)
AddShapesCommand* shapeCommand = new (nothrow) AddShapesCommand( AddShapesCommand* shapeCommand = new (nothrow) AddShapesCommand(
fDocument->Icon()->Shapes(), &shape, 1, fDocument->Icon()->Shapes(), &shape, 1,
fDocument->Icon()->Shapes()->CountShapes(), fDocument->Icon()->Shapes()->CountItems());
fDocument->Selection());
if (shapeCommand == NULL) { if (shapeCommand == NULL) {
delete shape; delete shape;
return; return;
+5 -6
View File
@@ -12,16 +12,15 @@
#include "AddPathsCommand.h" #include "AddPathsCommand.h"
#include "AddStylesCommand.h" #include "AddStylesCommand.h"
#include "PathContainer.h" #include "Container.h"
#include "Style.h" #include "Style.h"
#include "StyleContainer.h"
#include "VectorPath.h" #include "VectorPath.h"
using std::nothrow; using std::nothrow;
// new_style // new_style
void void
new_style(rgb_color color, StyleContainer* container, new_style(rgb_color color, Container<Style>* container,
Style** style, AddStylesCommand** command) Style** style, AddStylesCommand** command)
{ {
*style = new (nothrow) Style(color); *style = new (nothrow) Style(color);
@@ -30,7 +29,7 @@ new_style(rgb_color color, StyleContainer* container,
styles[0] = *style; styles[0] = *style;
*command = new (nothrow) AddStylesCommand( *command = new (nothrow) AddStylesCommand(
container, styles, 1, container, styles, 1,
container->CountStyles()); container->CountItems());
if (*command == NULL) { if (*command == NULL) {
delete *style; delete *style;
*style = NULL; *style = NULL;
@@ -42,7 +41,7 @@ new_style(rgb_color color, StyleContainer* container,
// new_path // new_path
void void
new_path(PathContainer* container, VectorPath** path, new_path(Container<VectorPath>* container, VectorPath** path,
AddPathsCommand** command, VectorPath* other) AddPathsCommand** command, VectorPath* other)
{ {
if (other) if (other)
@@ -54,7 +53,7 @@ new_path(PathContainer* container, VectorPath** path,
VectorPath* paths[1]; VectorPath* paths[1];
paths[0] = *path; paths[0] = *path;
int32 insertIndex = other ? container->IndexOf(other) + 1 int32 insertIndex = other ? container->IndexOf(other) + 1
: container->CountPaths(); : container->CountItems();
*command = new (nothrow) AddPathsCommand( *command = new (nothrow) AddPathsCommand(
container, paths, 1, true, insertIndex); container, paths, 1, true, insertIndex);
if (*command == NULL) { if (*command == NULL) {
+3 -2
View File
@@ -18,6 +18,7 @@ class AddPathsCommand;
class AddStylesCommand; class AddStylesCommand;
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
template <class Type> class Container;
class PathContainer; class PathContainer;
class Style; class Style;
class StyleContainer; class StyleContainer;
@@ -27,10 +28,10 @@ _END_ICON_NAMESPACE
_USING_ICON_NAMESPACE _USING_ICON_NAMESPACE
void new_style(rgb_color color, StyleContainer* container, void new_style(rgb_color color, Container<Style>* container,
Style** style, AddStylesCommand** command); Style** style, AddStylesCommand** command);
void new_path(PathContainer* container, VectorPath** path, void new_path(Container<VectorPath>* container, VectorPath** path,
AddPathsCommand** command, VectorPath* other = NULL); AddPathsCommand** command, VectorPath* other = NULL);
#endif // UTIL_H #endif // UTIL_H
+3 -6
View File
@@ -12,10 +12,7 @@
#include "CommandStack.h" #include "CommandStack.h"
#include "DocumentSaver.h" #include "DocumentSaver.h"
#include "Icon.h" #include "Icon.h"
#include "PathContainer.h"
#include "Selection.h" #include "Selection.h"
#include "ShapeContainer.h"
#include "StyleContainer.h"
#include <Entry.h> #include <Entry.h>
@@ -119,8 +116,8 @@ Document::MakeEmpty(bool includingSavers)
bool bool
Document::IsEmpty() const Document::IsEmpty() const
{ {
return fIcon->Styles()->CountStyles() == 0 return fIcon->Styles()->CountItems() == 0
&& fIcon->Paths()->CountPaths() == 0 && fIcon->Paths()->CountItems() == 0
&& fIcon->Shapes()->CountShapes() == 0; && fIcon->Shapes()->CountItems() == 0;
} }
@@ -0,0 +1,160 @@
/*
* Copyright 2006-2007, 2023, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <[email protected]>
* Zardshard
*/
#ifndef ADD_COMMAND_H
#define ADD_COMMAND_H
#include <new>
#include <stdio.h>
#include <string.h>
#include <Catalog.h>
#include <Locale.h>
#include <Referenceable.h>
#include "Command.h"
#include "Container.h"
#include "IconBuild.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-AddItemsCmd"
using std::nothrow;
_BEGIN_ICON_NAMESPACE
class BReferenceable;
_END_ICON_NAMESPACE
_USING_ICON_NAMESPACE
/*! Adds items to a \c Container.
\note This class should be subclassed and the \c GetName member overridden.
*/
template<class Type>
class AddCommand : public Command {
public:
AddCommand(
Container<Type>* container,
const Type* const* items,
int32 count,
bool ownsItems,
int32 index);
virtual ~AddCommand();
virtual status_t InitCheck();
virtual status_t Perform();
virtual status_t Undo();
virtual void GetName(BString& name);
protected:
Container<Type>* fContainer;
Type** fItems;
int32 fCount;
bool fOwnsItems;
int32 fIndex;
bool fItemsAdded;
};
template<class Type>
AddCommand<Type>::AddCommand(Container<Type>* container,
const Type* const* items, int32 count, bool ownsItems, int32 index)
: Command(),
fContainer(container),
fItems(items && count > 0 ? new (nothrow) Type*[count] : NULL),
fCount(count),
fOwnsItems(ownsItems),
fIndex(index),
fItemsAdded(false)
{
if (!fContainer || !fItems)
return;
memcpy(fItems, items, sizeof(Type*) * fCount);
if (!fOwnsItems) {
// Add references to items
for (int32 i = 0; i < fCount; i++) {
if (fItems[i] != NULL)
fItems[i]->AcquireReference();
}
}
}
template<class Type>
AddCommand<Type>::~AddCommand()
{
if (!fItemsAdded && fItems) {
for (int32 i = 0; i < fCount; i++) {
if (fItems[i] != NULL)
fItems[i]->ReleaseReference();
}
}
delete[] fItems;
}
template<class Type>
status_t
AddCommand<Type>::InitCheck()
{
return fContainer && fItems ? B_OK : B_NO_INIT;
}
template<class Type>
status_t
AddCommand<Type>::Perform()
{
// add items to container
for (int32 i = 0; i < fCount; i++) {
if (fItems[i] && !fContainer->AddItem(fItems[i], fIndex + i)) {
// roll back
for (int32 j = i - 1; j >= 0; j--)
fContainer->RemoveItem(fItems[j]);
return B_ERROR;
}
}
fItemsAdded = true;
return B_OK;
}
template<class Type>
status_t
AddCommand<Type>::Undo()
{
// remove items from container
for (int32 i = 0; i < fCount; i++) {
fContainer->RemoveItem(fItems[i]);
}
fItemsAdded = false;
return B_OK;
}
template<class Type>
void
AddCommand<Type>::GetName(BString& name)
{
if (fCount > 1)
name << B_TRANSLATE("Add Items");
else
name << B_TRANSLATE("Add Item");
}
#endif // ADD_COMMAND_H
@@ -0,0 +1,200 @@
/*
* Copyright 2006-2007, 2023, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <[email protected]>
* Zardshard
*/
#ifndef MOVE_COMMAND_H
#define MOVE_COMMAND_H
#include <new>
#include <stdio.h>
#include <Catalog.h>
#include <Locale.h>
#include "Command.h"
#include "Container.h"
#include "IconBuild.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-MoveItemsCmd"
using std::nothrow;
_USING_ICON_NAMESPACE
/*! Moves a set of \c items to a different location in a \c container.
\note This class should be subclassed and the \c GetName member overridden.
*/
template <class Type>
class MoveCommand : public Command {
public:
MoveCommand(
Container<Type>* container,
Type** items,
int32 count,
int32 toIndex);
virtual ~MoveCommand();
virtual status_t InitCheck();
virtual status_t Perform();
virtual status_t Undo();
virtual void GetName(BString& name);
protected:
Container<Type>* fContainer;
Type** fItems;
int32* fIndices;
int32 fToIndex;
int32 fCount;
};
template <class Type>
MoveCommand<Type>::MoveCommand(Container<Type>* container,
Type** items,
int32 count,
int32 toIndex)
: Command(),
fContainer(container),
fItems(items),
fIndices(count > 0 ? new (nothrow) int32[count] : NULL),
fToIndex(toIndex),
fCount(count)
{
if (!fContainer || !fItems || !fIndices)
return;
// init original shape indices and
// adjust toIndex compensating for items that
// are removed before that index
int32 itemsBeforeIndex = 0;
for (int32 i = 0; i < fCount; i++) {
fIndices[i] = fContainer->IndexOf(fItems[i]);
if (fIndices[i] >= 0 && fIndices[i] < fToIndex)
itemsBeforeIndex++;
}
fToIndex -= itemsBeforeIndex;
}
template <class Type>
MoveCommand<Type>::~MoveCommand()
{
delete[] fItems;
delete[] fIndices;
}
template <class Type>
status_t
MoveCommand<Type>::InitCheck()
{
if (!fContainer || !fItems || !fIndices)
return B_NO_INIT;
// analyse the move, don't return B_OK in case
// the container state does not change...
int32 index = fIndices[0];
// NOTE: fIndices == NULL if fCount < 1
if (index != fToIndex) {
// a change is guaranteed
return B_OK;
}
// the insertion index is the same as the index of the first
// moved item, a change only occures if the indices of the
// moved items is not contiguous
bool isContiguous = true;
for (int32 i = 1; i < fCount; i++) {
if (fIndices[i] != index + 1) {
isContiguous = false;
break;
}
index = fIndices[i];
}
if (isContiguous) {
// the container state will not change because of the move
return B_ERROR;
}
return B_OK;
}
template <class Type>
status_t
MoveCommand<Type>::Perform()
{
status_t ret = B_OK;
// remove paths from container
for (int32 i = 0; i < fCount; i++) {
if (fItems[i] && !fContainer->RemoveItem(fItems[i])) {
ret = B_ERROR;
break;
}
}
if (ret < B_OK)
return ret;
// add paths to container at the insertion index
int32 index = fToIndex;
for (int32 i = 0; i < fCount; i++) {
if (fItems[i] && !fContainer->AddItem(fItems[i], index++)) {
ret = B_ERROR;
break;
}
}
return ret;
}
template <class Type>
status_t
MoveCommand<Type>::Undo()
{
status_t ret = B_OK;
// remove paths from container
for (int32 i = 0; i < fCount; i++) {
if (fItems[i] && !fContainer->RemoveItem(fItems[i])) {
ret = B_ERROR;
break;
}
}
if (ret < B_OK)
return ret;
// add paths to container at remembered indices
for (int32 i = 0; i < fCount; i++) {
if (fItems[i] && !fContainer->AddItem(fItems[i], fIndices[i])) {
ret = B_ERROR;
break;
}
}
return ret;
}
template <class Type>
void
MoveCommand<Type>::GetName(BString& name)
{
if (fCount > 1)
name << B_TRANSLATE("Move Items");
else
name << B_TRANSLATE("Move Item");
}
#endif // MOVE_COMMAND_H
@@ -0,0 +1,152 @@
/*
* Copyright 2006-2007, 2023, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <[email protected]>
* Zardshard
*/
#ifndef REMOVE_COMMAND_H
#define REMOVE_COMMAND_H
#include <new>
#include <string.h>
#include <Catalog.h>
#include <Locale.h>
#include "Command.h"
#include "Container.h"
#include "IconBuild.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-RemoveItemsCmd"
using std::nothrow;
_USING_ICON_NAMESPACE
/*! Removes items located at certain \c indices from a \c Container.
\note This class should be subclassed and the \c GetName member overridden.
*/
template <class Type>
class RemoveCommand : public Command {
public:
RemoveCommand(
Container<Type>* container,
const int32* indices,
int32 count);
virtual ~RemoveCommand();
virtual status_t InitCheck();
virtual status_t Perform();
virtual status_t Undo();
virtual void GetName(BString& name);
protected:
Container<Type>* fContainer;
Type** fItems;
int32* fIndices;
int32 fCount;
bool fItemsRemoved;
};
template <class Type>
RemoveCommand<Type>::RemoveCommand(
Container<Type>* container, const int32* indices, int32 count)
: Command(),
fContainer(container),
fItems(count > 0 ? new (nothrow) Type*[count] : NULL),
fIndices(count > 0 ? new (nothrow) int32[count] : NULL),
fCount(count),
fItemsRemoved(false)
{
if (!fContainer || !fItems || !fIndices)
return;
memcpy(fIndices, indices, sizeof(int32) * fCount);
for (int32 i = 0; i < fCount; i++)
fItems[i] = fContainer->ItemAt(fIndices[i]);
}
template <class Type>
RemoveCommand<Type>::~RemoveCommand()
{
if (fItemsRemoved && fItems) {
for (int32 i = 0; i < fCount; i++) {
if (fItems[i])
fItems[i]->ReleaseReference();
}
}
delete[] fItems;
delete[] fIndices;
}
template <class Type>
status_t
RemoveCommand<Type>::InitCheck()
{
return fContainer && fItems && fIndices ? B_OK : B_NO_INIT;
}
template <class Type>
status_t
RemoveCommand<Type>::Perform()
{
status_t ret = B_OK;
// remove shapes from container
for (int32 i = 0; i < fCount; i++) {
if (fItems[i] && !fContainer->RemoveItem(fItems[i])) {
ret = B_ERROR;
break;
}
}
fItemsRemoved = true;
return ret;
}
template <class Type>
status_t
RemoveCommand<Type>::Undo()
{
status_t ret = B_OK;
// add shapes to container at remembered indices
for (int32 i = 0; i < fCount; i++) {
if (fItems[i] && !fContainer->AddItem(fItems[i], fIndices[i])) {
ret = B_ERROR;
break;
}
}
fItemsRemoved = false;
return ret;
}
template <class Type>
void
RemoveCommand<Type>::GetName(BString& name)
{
// if (fCount > 1)
// name << _GetString(MOVE_MODIFIERS, "Move Items");
// else
// name << _GetString(MOVE_MODIFIER, "Move Item");
if (fCount > 1)
name << B_TRANSLATE("Remove Items");
else
name << B_TRANSLATE("Remove Item");
}
#endif // REMOVE_COMMAND_H
+21 -28
View File
@@ -31,7 +31,6 @@
#include "ReversePathCommand.h" #include "ReversePathCommand.h"
#include "RotatePathIndicesCommand.h" #include "RotatePathIndicesCommand.h"
#include "Shape.h" #include "Shape.h"
#include "ShapeContainer.h"
#include "Selection.h" #include "Selection.h"
#include "UnassignPathCommand.h" #include "UnassignPathCommand.h"
#include "Util.h" #include "Util.h"
@@ -200,8 +199,8 @@ private:
}; };
class ShapePathListener : public PathContainerListener, class ShapePathListener : public ContainerListener<VectorPath>,
public ShapeContainerListener { public ContainerListener<Shape> {
public: public:
ShapePathListener(PathListView* listView) ShapePathListener(PathListView* listView)
: :
@@ -217,26 +216,26 @@ public:
} }
// PathContainerListener interface // ContainerListener<VectorPath> interface
virtual void PathAdded(VectorPath* path, int32 index) virtual void ItemAdded(VectorPath* path, int32 index)
{ {
fListView->_SetPathMarked(path, true); fListView->_SetPathMarked(path, true);
} }
virtual void PathRemoved(VectorPath* path) virtual void ItemRemoved(VectorPath* path)
{ {
fListView->_SetPathMarked(path, false); fListView->_SetPathMarked(path, false);
} }
// ShapeContainerListener interface // ContainerListener<Shape> interface
virtual void ShapeAdded(Shape* shape, int32 index) virtual void ItemAdded(Shape* shape, int32 index)
{ {
} }
virtual void ShapeRemoved(Shape* shape) virtual void ItemRemoved(Shape* shape)
{ {
fListView->SetCurrentShape(NULL); fListView->SetCurrentShape(NULL);
} }
@@ -363,13 +362,13 @@ PathListView::MouseDown(BPoint where)
if (itemFrame.Contains(where) && fCommandStack) { if (itemFrame.Contains(where) && fCommandStack) {
// add or remove the path to the shape // add or remove the path to the shape
::Command* command; ::Command* command;
if (fCurrentShape->Paths()->HasPath(path)) { if (fCurrentShape->Paths()->HasItem(path)) {
command = new UnassignPathCommand(fCurrentShape, path); command = new UnassignPathCommand(fCurrentShape, path);
} else { } else {
VectorPath* paths[1]; VectorPath* paths[1];
paths[0] = path; paths[0] = path;
command = new AddPathsCommand(fCurrentShape->Paths(), command = new AddPathsCommand(fCurrentShape->Paths(),
paths, 1, false, fCurrentShape->Paths()->CountPaths()); paths, 1, false, fCurrentShape->Paths()->CountItems());
} }
fCommandStack->Perform(command); fCommandStack->Perform(command);
handled = true; handled = true;
@@ -659,18 +658,12 @@ PathListView::RemoveItemList(BList& items)
return; return;
int32 count = items.CountItems(); int32 count = items.CountItems();
VectorPath* paths[count]; int32 indices[count];
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++)
PathListItem* item = dynamic_cast<PathListItem*>( indices[i] = IndexOf((BListItem*)items.ItemAtFast(i));
(BListItem*)items.ItemAtFast(i));
if (item != NULL)
paths[i] = item->path;
else
paths[i] = NULL;
}
RemovePathsCommand* command = new (nothrow) RemovePathsCommand( RemovePathsCommand* command = new (nothrow) RemovePathsCommand(
fPathContainer, paths, count); fPathContainer, indices, count);
fCommandStack->Perform(command); fCommandStack->Perform(command);
} }
@@ -718,7 +711,7 @@ PathListView::SelectableFor(BListItem* item) const
void void
PathListView::PathAdded(VectorPath* path, int32 index) PathListView::ItemAdded(VectorPath* path, int32 index)
{ {
// NOTE: we are in the thread that messed with the // NOTE: we are in the thread that messed with the
// ShapeContainer, so no need to lock the // ShapeContainer, so no need to lock the
@@ -735,7 +728,7 @@ PathListView::PathAdded(VectorPath* path, int32 index)
void void
PathListView::PathRemoved(VectorPath* path) PathListView::ItemRemoved(VectorPath* path)
{ {
// NOTE: we are in the thread that messed with the // NOTE: we are in the thread that messed with the
// ShapeContainer, so no need to lock the // ShapeContainer, so no need to lock the
@@ -755,7 +748,7 @@ PathListView::PathRemoved(VectorPath* path)
void void
PathListView::SetPathContainer(PathContainer* container) PathListView::SetPathContainer(Container<VectorPath>* container)
{ {
if (fPathContainer == container) if (fPathContainer == container)
return; return;
@@ -777,16 +770,16 @@ PathListView::SetPathContainer(PathContainer* container)
// if (!fPathContainer->ReadLock()) // if (!fPathContainer->ReadLock())
// return; // return;
int32 count = fPathContainer->CountPaths(); int32 count = fPathContainer->CountItems();
for (int32 i = 0; i < count; i++) for (int32 i = 0; i < count; i++)
_AddPath(fPathContainer->PathAtFast(i), i); _AddPath(fPathContainer->ItemAtFast(i), i);
// fPathContainer->ReadUnlock(); // fPathContainer->ReadUnlock();
} }
void void
PathListView::SetShapeContainer(ShapeContainer* container) PathListView::SetShapeContainer(Container<Shape>* container)
{ {
if (fShapeContainer == container) if (fShapeContainer == container)
return; return;
@@ -941,7 +934,7 @@ PathListView::_UpdateMarks()
if (item == NULL) if (item == NULL)
continue; continue;
item->SetMarkEnabled(true); item->SetMarkEnabled(true);
item->SetMarked(fCurrentShape->Paths()->HasPath(item->path)); item->SetMarked(fCurrentShape->Paths()->HasItem(item->path));
} }
} else { } else {
// disable display of marks // disable display of marks
+56 -56
View File
@@ -9,8 +9,9 @@
#define PATH_LIST_VIEW_H #define PATH_LIST_VIEW_H
#include "Container.h"
#include "ListViews.h" #include "ListViews.h"
#include "PathContainer.h" #include "IconBuild.h"
class BMenu; class BMenu;
@@ -20,7 +21,6 @@ _BEGIN_ICON_NAMESPACE
class VectorPath; class VectorPath;
class PathSourceShape; class PathSourceShape;
class Shape; class Shape;
class ShapeContainer;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
class CommandStack; class CommandStack;
@@ -33,85 +33,85 @@ _USING_ICON_NAMESPACE
class PathListView : public SimpleListView, class PathListView : public SimpleListView,
public PathContainerListener { public ContainerListener<VectorPath> {
public: public:
PathListView(BRect frame, PathListView(BRect frame,
const char* name, const char* name,
BMessage* selectionMessage = NULL, BMessage* selectionMessage = NULL,
BHandler* target = NULL); BHandler* target = NULL);
virtual ~PathListView(); virtual ~PathListView();
// SimpleListView interface // SimpleListView interface
virtual void SelectionChanged(); virtual void SelectionChanged();
virtual void MouseDown(BPoint where); virtual void MouseDown(BPoint where);
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual void MakeDragMessage(BMessage* message) const; virtual void MakeDragMessage(BMessage* message) const;
virtual bool AcceptDragMessage(const BMessage* message) const; virtual bool AcceptDragMessage(const BMessage* message) const;
virtual void SetDropTargetRect(const BMessage* message, virtual void SetDropTargetRect(const BMessage* message,
BPoint where); BPoint where);
virtual bool HandleDropMessage(const BMessage* message, virtual bool HandleDropMessage(const BMessage* message,
int32 dropIndex); int32 dropIndex);
virtual void MoveItems(BList& items, int32 toIndex); virtual void MoveItems(BList& items, int32 toIndex);
virtual void CopyItems(BList& items, int32 toIndex); virtual void CopyItems(BList& items, int32 toIndex);
virtual void RemoveItemList(BList& items); virtual void RemoveItemList(BList& items);
virtual BListItem* CloneItem(int32 atIndex) const; virtual BListItem* CloneItem(int32 atIndex) const;
virtual int32 IndexOfSelectable(Selectable* selectable) const; virtual int32 IndexOfSelectable(Selectable* selectable) const;
virtual Selectable* SelectableFor(BListItem* item) const; virtual Selectable* SelectableFor(BListItem* item) const;
// ShapeContainerListener interface // ContainerListener<VectorPath> interface
virtual void PathAdded(VectorPath* path, int32 index); virtual void ItemAdded(VectorPath* path, int32 index);
virtual void PathRemoved(VectorPath* path); virtual void ItemRemoved(VectorPath* path);
// PathListView // PathListView
void SetPathContainer(PathContainer* container); void SetPathContainer(Container<VectorPath>* container);
void SetShapeContainer(ShapeContainer* container); void SetShapeContainer(Container<Shape>* container);
void SetCommandStack(CommandStack* stack); void SetCommandStack(CommandStack* stack);
void SetMenu(BMenu* menu); void SetMenu(BMenu* menu);
void SetCurrentShape(Shape* shape); void SetCurrentShape(Shape* shape);
PathSourceShape* CurrentShape() const PathSourceShape* CurrentShape() const
{ return fCurrentShape; } { return fCurrentShape; }
private: private:
bool _AddPath(VectorPath* path, int32 index); bool _AddPath(VectorPath* path, int32 index);
bool _RemovePath(VectorPath* path); bool _RemovePath(VectorPath* path);
PathListItem* _ItemForPath(VectorPath* path) const; PathListItem* _ItemForPath(VectorPath* path) const;
friend class ShapePathListener; friend class ShapePathListener;
void _UpdateMarks(); void _UpdateMarks();
void _SetPathMarked(VectorPath* path, bool marked); void _SetPathMarked(VectorPath* path, bool marked);
void _UpdateMenu(); void _UpdateMenu();
BMessage* fMessage; BMessage* fMessage;
BMenu* fMenu; BMenu* fMenu;
BMenuItem* fAddMI; BMenuItem* fAddMI;
BMenuItem* fAddRectMI; BMenuItem* fAddRectMI;
BMenuItem* fAddCircleMI; BMenuItem* fAddCircleMI;
BMenuItem* fAddArcMI; BMenuItem* fAddArcMI;
BMenuItem* fDuplicateMI; BMenuItem* fDuplicateMI;
BMenuItem* fReverseMI; BMenuItem* fReverseMI;
BMenuItem* fCleanUpMI; BMenuItem* fCleanUpMI;
BMenuItem* fRotateIndicesLeftMI; BMenuItem* fRotateIndicesLeftMI;
BMenuItem* fRotateIndicesRightMI; BMenuItem* fRotateIndicesRightMI;
BMenuItem* fRemoveMI; BMenuItem* fRemoveMI;
PathContainer* fPathContainer; Container<VectorPath>* fPathContainer;
ShapeContainer* fShapeContainer; Container<Shape>* fShapeContainer;
CommandStack* fCommandStack; CommandStack* fCommandStack;
PathSourceShape* fCurrentShape; PathSourceShape* fCurrentShape;
// those path items will be marked that // those path items will be marked that
// are referenced by this shape // are referenced by this shape
ShapePathListener* fShapePathListener; ShapePathListener* fShapePathListener;
}; };
#endif // PATH_LIST_VIEW_H #endif // PATH_LIST_VIEW_H
+22 -25
View File
@@ -27,23 +27,21 @@
#include "AddStylesCommand.h" #include "AddStylesCommand.h"
#include "CommandStack.h" #include "CommandStack.h"
#include "CompoundCommand.h" #include "CompoundCommand.h"
#include "Container.h"
#include "FreezeTransformationCommand.h" #include "FreezeTransformationCommand.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "MoveShapesCommand.h" #include "MoveShapesCommand.h"
#include "Observer.h" #include "Observer.h"
#include "ReferenceImage.h"
#include "PathContainer.h"
#include "PathSourceShape.h" #include "PathSourceShape.h"
#include "ReferenceImage.h"
#include "RemoveShapesCommand.h" #include "RemoveShapesCommand.h"
#include "ResetTransformationCommand.h" #include "ResetTransformationCommand.h"
#include "Selection.h" #include "Selection.h"
#include "Shape.h" #include "Shape.h"
#include "Style.h" #include "Style.h"
#include "StyleContainer.h"
#include "Util.h" #include "Util.h"
#include "VectorPath.h" #include "VectorPath.h"
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-ShapesList" #define B_TRANSLATION_CONTEXT "Icon-O-Matic-ShapesList"
@@ -268,10 +266,10 @@ ShapeListView::MakeDragMessage(BMessage* message) const
shape->Style()->Archive(&styleArchive, true); shape->Style()->Archive(&styleArchive, true);
archive.AddMessage("style", &styleArchive); archive.AddMessage("style", &styleArchive);
PathContainer* paths = shape->Paths(); Container<VectorPath>* paths = shape->Paths();
for (int32 j = 0; j < paths->CountPaths(); j++) { for (int32 j = 0; j < paths->CountItems(); j++) {
BMessage pathArchive; BMessage pathArchive;
paths->PathAt(j)->Archive(&pathArchive, true); paths->ItemAt(j)->Archive(&pathArchive, true);
archive.AddMessage("path", &pathArchive); archive.AddMessage("path", &pathArchive);
} }
@@ -365,8 +363,8 @@ ShapeListView::HandleDropMessage(const BMessage* message, int32 dropIndex)
Style* styleToAssign = style; Style* styleToAssign = style;
// Try to find an existing style that is the same as the extracted // Try to find an existing style that is the same as the extracted
// style and use that one instead. // style and use that one instead.
for (int32 i = 0; i < fStyleContainer->CountStyles(); i++) { for (int32 i = 0; i < fStyleContainer->CountItems(); i++) {
Style* other = fStyleContainer->StyleAtFast(i); Style* other = fStyleContainer->ItemAtFast(i);
if (*other == *style) { if (*other == *style) {
styleToAssign = other; styleToAssign = other;
delete style; delete style;
@@ -407,8 +405,8 @@ ShapeListView::HandleDropMessage(const BMessage* message, int32 dropIndex)
break; break;
VectorPath* pathToInclude = path; VectorPath* pathToInclude = path;
for (int32 i = 0; i < fPathContainer->CountPaths(); i++) { for (int32 i = 0; i < fPathContainer->CountItems(); i++) {
VectorPath* other = fPathContainer->PathAtFast(i); VectorPath* other = fPathContainer->ItemAtFast(i);
if (*other == *path) { if (*other == *path) {
pathToInclude = other; pathToInclude = other;
delete path; delete path;
@@ -422,7 +420,7 @@ ShapeListView::HandleDropMessage(const BMessage* message, int32 dropIndex)
break; break;
} }
shape->Paths()->AddPath(pathToInclude); shape->Paths()->AddItem(pathToInclude);
pathIndex++; pathIndex++;
} }
@@ -454,15 +452,14 @@ ShapeListView::HandleDropMessage(const BMessage* message, int32 dropIndex)
AddStylesCommand* stylesCommand = new(std::nothrow) AddStylesCommand( AddStylesCommand* stylesCommand = new(std::nothrow) AddStylesCommand(
fStyleContainer, (Style**)styles.Items(), styles.CountItems(), fStyleContainer, (Style**)styles.Items(), styles.CountItems(),
fStyleContainer->CountStyles()); fStyleContainer->CountItems());
AddPathsCommand* pathsCommand = new(std::nothrow) AddPathsCommand( AddPathsCommand* pathsCommand = new(std::nothrow) AddPathsCommand(
fPathContainer, (VectorPath**)paths.Items(), paths.CountItems(), fPathContainer, (VectorPath**)paths.Items(), paths.CountItems(),
true, fPathContainer->CountPaths()); true, fPathContainer->CountItems());
AddShapesCommand* shapesCommand = new(std::nothrow) AddShapesCommand( AddShapesCommand* shapesCommand = new(std::nothrow) AddShapesCommand(
fShapeContainer, (Shape**)shapes.Items(), shapeCount, dropIndex, fShapeContainer, (Shape**)shapes.Items(), shapeCount, dropIndex);
fSelection);
::Command** commands = new(std::nothrow) ::Command*[3]; ::Command** commands = new(std::nothrow) ::Command*[3];
@@ -526,7 +523,7 @@ ShapeListView::CopyItems(BList& items, int32 toIndex)
} }
AddShapesCommand* command = new(nothrow) AddShapesCommand(fShapeContainer, AddShapesCommand* command = new(nothrow) AddShapesCommand(fShapeContainer,
shapes, count, toIndex, fSelection); shapes, count, toIndex);
if (command == NULL) { if (command == NULL) {
for (int32 i = 0; i < count; i++) for (int32 i = 0; i < count; i++)
delete shapes[i]; delete shapes[i];
@@ -578,7 +575,7 @@ ShapeListView::IndexOfSelectable(Selectable* selectable) const
int32 count = CountItems(); int32 count = CountItems();
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
ShapeListItem* item = dynamic_cast<ShapeListItem*>(ItemAt(i)); ShapeListItem* item = dynamic_cast<ShapeListItem*>(ItemAt(i));
if (item != NULL && item->shape->HasTransformer(transformer)) if (item != NULL && item->shape->Transformers()->HasItem(transformer))
return i; return i;
} }
} else { } else {
@@ -608,7 +605,7 @@ ShapeListView::SelectableFor(BListItem* item) const
void void
ShapeListView::ShapeAdded(Shape* shape, int32 index) ShapeListView::ItemAdded(Shape* shape, int32 index)
{ {
// NOTE: we are in the thread that messed with the // NOTE: we are in the thread that messed with the
// ShapeContainer, so no need to lock the // ShapeContainer, so no need to lock the
@@ -625,7 +622,7 @@ ShapeListView::ShapeAdded(Shape* shape, int32 index)
void void
ShapeListView::ShapeRemoved(Shape* shape) ShapeListView::ItemRemoved(Shape* shape)
{ {
// NOTE: we are in the thread that messed with the // NOTE: we are in the thread that messed with the
// ShapeContainer, so no need to lock the // ShapeContainer, so no need to lock the
@@ -715,7 +712,7 @@ ShapeListView::SetMenu(BMenu* menu)
void void
ShapeListView::SetShapeContainer(ShapeContainer* container) ShapeListView::SetShapeContainer(Container<Shape>* container)
{ {
if (fShapeContainer == container) if (fShapeContainer == container)
return; return;
@@ -734,21 +731,21 @@ ShapeListView::SetShapeContainer(ShapeContainer* container)
fShapeContainer->AddListener(this); fShapeContainer->AddListener(this);
// sync // sync
int32 count = fShapeContainer->CountShapes(); int32 count = fShapeContainer->CountItems();
for (int32 i = 0; i < count; i++) for (int32 i = 0; i < count; i++)
_AddShape(fShapeContainer->ShapeAtFast(i), i); _AddShape(fShapeContainer->ItemAtFast(i), i);
} }
void void
ShapeListView::SetStyleContainer(StyleContainer* container) ShapeListView::SetStyleContainer(Container<Style>* container)
{ {
fStyleContainer = container; fStyleContainer = container;
} }
void void
ShapeListView::SetPathContainer(PathContainer* container) ShapeListView::SetPathContainer(Container<VectorPath>* container)
{ {
fPathContainer = container; fPathContainer = container;
} }
+52 -51
View File
@@ -10,20 +10,21 @@
#define SHAPE_LIST_VIEW_H #define SHAPE_LIST_VIEW_H
#include "Container.h"
#include "ListViews.h" #include "ListViews.h"
#include "ShapeContainer.h" #include "IconBuild.h"
class BMenu; class BMenu;
class BMenuItem; class BMenuItem;
class CommandStack; class CommandStack;
class ShapeListItem; class ShapeListItem;
class StyleContainer;
class PathContainer;
class Selection; class Selection;
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
class Style;
class Shape; class Shape;
class VectorPath;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
_USING_ICON_NAMESPACE _USING_ICON_NAMESPACE
@@ -35,73 +36,73 @@ enum {
}; };
class ShapeListView : public SimpleListView, class ShapeListView : public SimpleListView,
public ShapeContainerListener { public ContainerListener<Shape> {
public: public:
ShapeListView(BRect frame, ShapeListView(BRect frame,
const char* name, const char* name,
BMessage* selectionMessage = NULL, BMessage* selectionMessage = NULL,
BHandler* target = NULL); BHandler* target = NULL);
virtual ~ShapeListView(); virtual ~ShapeListView();
// SimpleListView interface // SimpleListView interface
virtual void SelectionChanged(); virtual void SelectionChanged();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual void MakeDragMessage(BMessage* message) const; virtual void MakeDragMessage(BMessage* message) const;
virtual bool AcceptDragMessage(const BMessage* message) const; virtual bool AcceptDragMessage(const BMessage* message) const;
virtual void SetDropTargetRect(const BMessage* message, virtual void SetDropTargetRect(const BMessage* message,
BPoint where); BPoint where);
virtual bool HandleDropMessage(const BMessage* message, virtual bool HandleDropMessage(const BMessage* message,
int32 dropIndex); int32 dropIndex);
virtual void MoveItems(BList& items, int32 toIndex); virtual void MoveItems(BList& items, int32 toIndex);
virtual void CopyItems(BList& items, int32 toIndex); virtual void CopyItems(BList& items, int32 toIndex);
virtual void RemoveItemList(BList& items); virtual void RemoveItemList(BList& items);
virtual BListItem* CloneItem(int32 atIndex) const; virtual BListItem* CloneItem(int32 atIndex) const;
virtual int32 IndexOfSelectable(Selectable* selectable) const; virtual int32 IndexOfSelectable(Selectable* selectable) const;
virtual Selectable* SelectableFor(BListItem* item) const; virtual Selectable* SelectableFor(BListItem* item) const;
// ShapeContainerListener interface // ContainerListener<Shape> interface
virtual void ShapeAdded(Shape* shape, int32 index); virtual void ItemAdded(Shape* shape, int32 index);
virtual void ShapeRemoved(Shape* shape); virtual void ItemRemoved(Shape* shape);
// ShapeListView // ShapeListView
void SetMenu(BMenu* menu); void SetMenu(BMenu* menu);
void SetShapeContainer(ShapeContainer* container); void SetShapeContainer(Container<Shape>* container);
void SetStyleContainer(StyleContainer* container); void SetStyleContainer(Container<Style>* container);
void SetPathContainer(PathContainer* container); void SetPathContainer(Container<VectorPath>* container);
void SetCommandStack(CommandStack* stack); void SetCommandStack(CommandStack* stack);
private: private:
bool _AddShape(Shape* shape, int32 index); bool _AddShape(Shape* shape, int32 index);
bool _RemoveShape(Shape* shape); bool _RemoveShape(Shape* shape);
ShapeListItem* _ItemForShape(Shape* shape) const; ShapeListItem* _ItemForShape(Shape* shape) const;
void _UpdateMenu(); void _UpdateMenu();
void _GetSelectedShapes(BList& shapes) const; void _GetSelectedShapes(BList& shapes) const;
BMessage* fMessage; BMessage* fMessage;
ShapeContainer* fShapeContainer; Container<Shape>* fShapeContainer;
StyleContainer* fStyleContainer; Container<Style>* fStyleContainer;
PathContainer* fPathContainer; Container<VectorPath>* fPathContainer;
CommandStack* fCommandStack; CommandStack* fCommandStack;
BMenu* fMenu; BMenu* fMenu;
BMenuItem* fAddEmptyMI; BMenuItem* fAddEmptyMI;
BMenuItem* fAddWidthPathMI; BMenuItem* fAddWidthPathMI;
BMenuItem* fAddWidthStyleMI; BMenuItem* fAddWidthStyleMI;
BMenuItem* fAddWidthPathAndStyleMI; BMenuItem* fAddWidthPathAndStyleMI;
BMenuItem* fAddReferenceImageMI; BMenuItem* fAddReferenceImageMI;
BMenuItem* fDuplicateMI; BMenuItem* fDuplicateMI;
BMenuItem* fResetTransformationMI; BMenuItem* fResetTransformationMI;
BMenuItem* fFreezeTransformationMI; BMenuItem* fFreezeTransformationMI;
BMenuItem* fRemoveMI; BMenuItem* fRemoveMI;
}; };
#endif // SHAPE_LIST_VIEW_H #endif // SHAPE_LIST_VIEW_H
+18 -27
View File
@@ -31,7 +31,6 @@
#include "Observer.h" #include "Observer.h"
#include "ResetTransformationCommand.h" #include "ResetTransformationCommand.h"
#include "Shape.h" #include "Shape.h"
#include "ShapeContainer.h"
#include "Selection.h" #include "Selection.h"
#include "Util.h" #include "Util.h"
@@ -197,7 +196,7 @@ private:
class ShapeStyleListener : public ShapeListener, class ShapeStyleListener : public ShapeListener,
public ShapeContainerListener { public ContainerListener<Shape> {
public: public:
ShapeStyleListener(StyleListView* listView) ShapeStyleListener(StyleListView* listView)
: :
@@ -226,12 +225,12 @@ public:
fListView->_SetStyleMarked(newStyle, true); fListView->_SetStyleMarked(newStyle, true);
} }
// ShapeContainerListener interface // ContainerListener<Shape> interface
virtual void ShapeAdded(Shape* shape, int32 index) virtual void ItemAdded(Shape* shape, int32 index)
{ {
} }
virtual void ShapeRemoved(Shape* shape) virtual void ItemRemoved(Shape* shape)
{ {
fListView->SetCurrentShape(NULL); fListView->SetCurrentShape(NULL);
} }
@@ -502,8 +501,8 @@ StyleListView::HandleDropMessage(const BMessage* message, int32 dropIndex)
if (count == 0) if (count == 0)
return false; return false;
AddStylesCommand* command = new(std::nothrow) AddStylesCommand( AddCommand<Style>* command = new(std::nothrow) AddCommand<Style>(
fStyleContainer, (Style**)styles.Items(), count, dropIndex); fStyleContainer, (Style**)styles.Items(), count, true, dropIndex);
if (command == NULL) { if (command == NULL) {
for (int32 i = 0; i < count; i++) for (int32 i = 0; i < count; i++)
@@ -560,9 +559,8 @@ StyleListView::CopyItems(BList& items, int32 toIndex)
styles[i] = item ? new (nothrow) Style(*item->style) : NULL; styles[i] = item ? new (nothrow) Style(*item->style) : NULL;
} }
AddStylesCommand* command AddCommand<Style>* command
= new (nothrow) AddStylesCommand(fStyleContainer, = new (nothrow) AddCommand<Style>(fStyleContainer, styles, count, true, toIndex);
styles, count, toIndex);
if (!command) { if (!command) {
for (int32 i = 0; i < count; i++) for (int32 i = 0; i < count; i++)
delete styles[i]; delete styles[i];
@@ -580,19 +578,12 @@ StyleListView::RemoveItemList(BList& items)
return; return;
int32 count = items.CountItems(); int32 count = items.CountItems();
Style* styles[count]; int32 indices[count];
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++)
StyleListItem* item = dynamic_cast<StyleListItem*>( indices[i] = IndexOf((BListItem*)items.ItemAtFast(i));
(BListItem*)items.ItemAtFast(i));
if (item)
styles[i] = item->style;
else
styles[i] = NULL;
}
RemoveStylesCommand* command RemoveStylesCommand* command
= new (nothrow) RemoveStylesCommand(fStyleContainer, = new (nothrow) RemoveStylesCommand(fStyleContainer, indices, count);
styles, count);
fCommandStack->Perform(command); fCommandStack->Perform(command);
} }
@@ -640,7 +631,7 @@ StyleListView::SelectableFor(BListItem* item) const
void void
StyleListView::StyleAdded(Style* style, int32 index) StyleListView::ItemAdded(Style* style, int32 index)
{ {
// NOTE: we are in the thread that messed with the // NOTE: we are in the thread that messed with the
// StyleContainer, so no need to lock the // StyleContainer, so no need to lock the
@@ -657,7 +648,7 @@ StyleListView::StyleAdded(Style* style, int32 index)
void void
StyleListView::StyleRemoved(Style* style) StyleListView::ItemRemoved(Style* style)
{ {
// NOTE: we are in the thread that messed with the // NOTE: we are in the thread that messed with the
// StyleContainer, so no need to lock the // StyleContainer, so no need to lock the
@@ -711,7 +702,7 @@ StyleListView::SetMenu(BMenu* menu)
void void
StyleListView::SetStyleContainer(StyleContainer* container) StyleListView::SetStyleContainer(Container<Style>* container)
{ {
if (fStyleContainer == container) if (fStyleContainer == container)
return; return;
@@ -730,14 +721,14 @@ StyleListView::SetStyleContainer(StyleContainer* container)
fStyleContainer->AddListener(this); fStyleContainer->AddListener(this);
// sync // sync
int32 count = fStyleContainer->CountStyles(); int32 count = fStyleContainer->CountItems();
for (int32 i = 0; i < count; i++) for (int32 i = 0; i < count; i++)
_AddStyle(fStyleContainer->StyleAtFast(i), i); _AddStyle(fStyleContainer->ItemAtFast(i), i);
} }
void void
StyleListView::SetShapeContainer(ShapeContainer* container) StyleListView::SetShapeContainer(Container<Shape>* container)
{ {
if (fShapeContainer == container) if (fShapeContainer == container)
return; return;
+9 -11
View File
@@ -7,7 +7,7 @@
#include "ListViews.h" #include "ListViews.h"
#include "StyleContainer.h" #include "Container.h"
class BMenu; class BMenu;
@@ -21,15 +21,13 @@ class StyleListItem;
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
class PathSourceShape; class PathSourceShape;
class Shape; class Shape;
class ShapeContainer;
class ShapeListener;
class Style; class Style;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
_USING_ICON_NAMESPACE _USING_ICON_NAMESPACE
class StyleListView : public SimpleListView, public StyleContainerListener { class StyleListView : public SimpleListView, public ContainerListener<Style> {
public: public:
StyleListView(BRect frame, const char* name, StyleListView(BRect frame, const char* name,
BMessage* selectionMessage = NULL, BMessage* selectionMessage = NULL,
@@ -61,14 +59,14 @@ public:
virtual int32 IndexOfSelectable(Selectable* selectable) const; virtual int32 IndexOfSelectable(Selectable* selectable) const;
virtual Selectable* SelectableFor(BListItem* item) const; virtual Selectable* SelectableFor(BListItem* item) const;
// StyleContainerListener interface // ContainerListener<Style> interface
virtual void StyleAdded(Style* style, int32 index); virtual void ItemAdded(Style* style, int32 index);
virtual void StyleRemoved(Style* style); virtual void ItemRemoved(Style* style);
// StyleListView // StyleListView
void SetMenu(BMenu* menu); void SetMenu(BMenu* menu);
void SetStyleContainer(StyleContainer* container); void SetStyleContainer(Container<Style>* container);
void SetShapeContainer(ShapeContainer* container); void SetShapeContainer(Container<Shape>* container);
void SetCommandStack(CommandStack* stack); void SetCommandStack(CommandStack* stack);
void SetCurrentColor(CurrentColor* color); void SetCurrentColor(CurrentColor* color);
@@ -89,8 +87,8 @@ private:
BMessage* fMessage; BMessage* fMessage;
StyleContainer* fStyleContainer; Container<Style>* fStyleContainer;
ShapeContainer* fShapeContainer; Container<Shape>* fShapeContainer;
CommandStack* fCommandStack; CommandStack* fCommandStack;
CurrentColor* fCurrentColor; CurrentColor* fCurrentColor;
@@ -1,9 +1,10 @@
/* /*
* Copyright 2006-2009, Haiku, Inc. All rights reserved. * Copyright 2006-2009, 2023, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <[email protected]> * Stephan Aßmus <[email protected]>
* Zardshard
*/ */
#include "TransformerListView.h" #include "TransformerListView.h"
@@ -38,11 +39,11 @@
using std::nothrow; using std::nothrow;
class TransformerItem : public SimpleItem, class TransformerItem : public SimpleItem,
public Observer { public Observer {
public: public:
TransformerItem(Transformer* t, TransformerItem(Transformer* t, TransformerListView* listView)
TransformerListView* listView)
: SimpleItem(t->Name()), : SimpleItem(t->Name()),
transformer(NULL), transformer(NULL),
fListView(listView) fListView(listView)
@@ -96,14 +97,16 @@ class TransformerItem : public SimpleItem,
TransformerListView* fListView; TransformerListView* fListView;
}; };
// #pragma mark - // #pragma mark -
enum { enum {
MSG_DRAG_TRANSFORMER = 'drgt', MSG_DRAG_TRANSFORMER = 'drgt',
MSG_ADD_TRANSFORMER = 'adtr', MSG_ADD_TRANSFORMER = 'adtr',
}; };
// constructor
TransformerListView::TransformerListView(BRect frame, const char* name, TransformerListView::TransformerListView(BRect frame, const char* name,
BMessage* message, BHandler* target) BMessage* message, BHandler* target)
: SimpleListView(frame, name, : SimpleListView(frame, name,
@@ -116,17 +119,17 @@ TransformerListView::TransformerListView(BRect frame, const char* name,
SetTarget(target); SetTarget(target);
} }
// destructor
TransformerListView::~TransformerListView() TransformerListView::~TransformerListView()
{ {
_MakeEmpty(); _MakeEmpty();
delete fMessage; delete fMessage;
if (fShape) if (fShape)
fShape->RemoveListener(this); fShape->Transformers()->RemoveListener(this);
} }
// Draw
void void
TransformerListView::Draw(BRect updateRect) TransformerListView::Draw(BRect updateRect)
{ {
@@ -163,7 +166,7 @@ TransformerListView::Draw(BRect updateRect)
DrawString(message2, middle); DrawString(message2, middle);
} }
// SelectionChanged
void void
TransformerListView::SelectionChanged() TransformerListView::SelectionChanged()
{ {
@@ -184,7 +187,7 @@ TransformerListView::SelectionChanged()
} }
} }
// MessageReceived
void void
TransformerListView::MessageReceived(BMessage* message) TransformerListView::MessageReceived(BMessage* message)
{ {
@@ -192,25 +195,25 @@ TransformerListView::MessageReceived(BMessage* message)
case MSG_ADD_TRANSFORMER: { case MSG_ADD_TRANSFORMER: {
if (!fShape || !fCommandStack) if (!fShape || !fCommandStack)
break; break;
uint32 type; uint32 type;
if (message->FindInt32("type", (int32*)&type) < B_OK) if (message->FindInt32("type", (int32*)&type) < B_OK)
break; break;
Transformer* transformer Transformer* transformer
= TransformerFactory::TransformerFor(type, = TransformerFactory::TransformerFor(type,
fShape->VertexSource()); fShape->VertexSource());
if (!transformer) if (!transformer)
break; break;
Transformer* transformers[1]; Transformer* transformers[1];
transformers[0] = transformer; transformers[0] = transformer;
::Command* command = new (nothrow) AddTransformersCommand( ::Command* command = new (nothrow) AddTransformersCommand(
fShape, transformers, 1, fShape->CountTransformers()); fShape->Transformers(), transformers, 1, fShape->Transformers()->CountItems());
if (!command) if (!command)
delete transformer; delete transformer;
fCommandStack->Perform(command); fCommandStack->Perform(command);
break; break;
} }
@@ -220,7 +223,7 @@ TransformerListView::MessageReceived(BMessage* message)
} }
} }
// MakeDragMessage
void void
TransformerListView::MakeDragMessage(BMessage* message) const TransformerListView::MakeDragMessage(BMessage* message) const
{ {
@@ -236,9 +239,10 @@ TransformerListView::MakeDragMessage(BMessage* message) const
} }
} }
// #pragma mark - // #pragma mark -
// MoveItems
void void
TransformerListView::MoveItems(BList& items, int32 toIndex) TransformerListView::MoveItems(BList& items, int32 toIndex)
{ {
@@ -257,8 +261,8 @@ TransformerListView::MoveItems(BList& items, int32 toIndex)
} }
MoveTransformersCommand* command MoveTransformersCommand* command
= new (nothrow) MoveTransformersCommand(fShape, = new (nothrow) MoveTransformersCommand(
transformers, count, toIndex); fShape->Transformers(), transformers, count, toIndex);
if (!command) { if (!command) {
delete[] transformers; delete[] transformers;
return; return;
@@ -267,7 +271,7 @@ TransformerListView::MoveItems(BList& items, int32 toIndex)
fCommandStack->Perform(command); fCommandStack->Perform(command);
} }
// CopyItems
void void
TransformerListView::CopyItems(BList& items, int32 toIndex) TransformerListView::CopyItems(BList& items, int32 toIndex)
{ {
@@ -275,7 +279,7 @@ TransformerListView::CopyItems(BList& items, int32 toIndex)
// TODO: allow copying items // TODO: allow copying items
} }
// RemoveItemList
void void
TransformerListView::RemoveItemList(BList& items) TransformerListView::RemoveItemList(BList& items)
{ {
@@ -288,12 +292,11 @@ TransformerListView::RemoveItemList(BList& items)
indices[i] = IndexOf((BListItem*)items.ItemAtFast(i)); indices[i] = IndexOf((BListItem*)items.ItemAtFast(i));
RemoveTransformersCommand* command RemoveTransformersCommand* command
= new (nothrow) RemoveTransformersCommand(fShape, = new (nothrow) RemoveTransformersCommand(fShape->Transformers(), indices, count);
indices, count);
fCommandStack->Perform(command); fCommandStack->Perform(command);
} }
// CloneItem
BListItem* BListItem*
TransformerListView::CloneItem(int32 index) const TransformerListView::CloneItem(int32 index) const
{ {
@@ -304,7 +307,7 @@ TransformerListView::CloneItem(int32 index) const
return NULL; return NULL;
} }
// IndexOfSelectable
int32 int32
TransformerListView::IndexOfSelectable(Selectable* selectable) const TransformerListView::IndexOfSelectable(Selectable* selectable) const
{ {
@@ -322,7 +325,7 @@ TransformerListView::IndexOfSelectable(Selectable* selectable) const
return -1; return -1;
} }
// SelectableFor
Selectable* Selectable*
TransformerListView::SelectableFor(BListItem* item) const TransformerListView::SelectableFor(BListItem* item) const
{ {
@@ -334,9 +337,9 @@ TransformerListView::SelectableFor(BListItem* item) const
// #pragma mark - // #pragma mark -
// TransformerAdded
void void
TransformerListView::TransformerAdded(Transformer* transformer, int32 index) TransformerListView::ItemAdded(Transformer* transformer, int32 index)
{ {
// NOTE: we are in the thread that messed with the // NOTE: we are in the thread that messed with the
// Shape, so no need to lock the document, when this is // Shape, so no need to lock the document, when this is
@@ -350,9 +353,9 @@ TransformerListView::TransformerAdded(Transformer* transformer, int32 index)
UnlockLooper(); UnlockLooper();
} }
// TransformerRemoved
void void
TransformerListView::TransformerRemoved(Transformer* transformer) TransformerListView::ItemRemoved(Transformer* transformer)
{ {
// NOTE: we are in the thread that messed with the // NOTE: we are in the thread that messed with the
// Shape, so no need to lock the document, when this is // Shape, so no need to lock the document, when this is
@@ -366,16 +369,10 @@ TransformerListView::TransformerRemoved(Transformer* transformer)
UnlockLooper(); UnlockLooper();
} }
// StyleChanged
void
TransformerListView::StyleChanged(Style* oldStyle, Style* newStyle)
{
// we don't care
}
// #pragma mark - // #pragma mark -
// SetMenu
void void
TransformerListView::SetMenu(BMenu* menu) TransformerListView::SetMenu(BMenu* menu)
{ {
@@ -418,7 +415,7 @@ TransformerListView::SetMenu(BMenu* menu)
_UpdateMenu(); _UpdateMenu();
} }
// SetShape
void void
TransformerListView::SetShape(Shape* shape) TransformerListView::SetShape(Shape* shape)
{ {
@@ -427,33 +424,34 @@ TransformerListView::SetShape(Shape* shape)
// detach from old container // detach from old container
if (fShape) if (fShape)
fShape->RemoveListener(this); fShape->Transformers()->RemoveListener(this);
_MakeEmpty(); _MakeEmpty();
fShape = shape; fShape = shape;
if (fShape) { if (fShape) {
fShape->AddListener(this); fShape->Transformers()->AddListener(this);
int32 count = fShape->CountTransformers(); int32 count = fShape->Transformers()->CountItems();
for (int32 i = 0; i < count; i++) for (int32 i = 0; i < count; i++)
_AddTransformer(fShape->TransformerAtFast(i), i); _AddTransformer(fShape->Transformers()->ItemAtFast(i), i);
} }
_UpdateMenu(); _UpdateMenu();
} }
// SetCommandStack
void void
TransformerListView::SetCommandStack(CommandStack* stack) TransformerListView::SetCommandStack(CommandStack* stack)
{ {
fCommandStack = stack; fCommandStack = stack;
} }
// #pragma mark - // #pragma mark -
// _AddTransformer
bool bool
TransformerListView::_AddTransformer(Transformer* transformer, int32 index) TransformerListView::_AddTransformer(Transformer* transformer, int32 index)
{ {
@@ -462,7 +460,7 @@ TransformerListView::_AddTransformer(Transformer* transformer, int32 index)
return false; return false;
} }
// _RemoveTransformer
bool bool
TransformerListView::_RemoveTransformer(Transformer* transformer) TransformerListView::_RemoveTransformer(Transformer* transformer)
{ {
@@ -474,7 +472,7 @@ TransformerListView::_RemoveTransformer(Transformer* transformer)
return false; return false;
} }
// _ItemForTransformer
TransformerItem* TransformerItem*
TransformerListView::_ItemForTransformer(Transformer* transformer) const TransformerListView::_ItemForTransformer(Transformer* transformer) const
{ {
@@ -487,7 +485,7 @@ TransformerListView::_ItemForTransformer(Transformer* transformer) const
return NULL; return NULL;
} }
// _UpdateMenu
void void
TransformerListView::_UpdateMenu() TransformerListView::_UpdateMenu()
{ {
@@ -1,16 +1,18 @@
/* /*
* Copyright 2006-2007, Haiku. * Copyright 2006-2007, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <[email protected]> * Stephan Aßmus <[email protected]>
* Zardshard
*/ */
#ifndef TRANSFORMER_LIST_VIEW_H #ifndef TRANSFORMER_LIST_VIEW_H
#define TRANSFORMER_LIST_VIEW_H #define TRANSFORMER_LIST_VIEW_H
#include "Container.h"
#include "ListViews.h" #include "ListViews.h"
#include "Shape.h" #include "IconBuild.h"
class BMenu; class BMenu;
@@ -20,12 +22,13 @@ class TransformerItem;
class Selection; class Selection;
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
class Shape;
class Transformer; class Transformer;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
class TransformerListView : public SimpleListView, class TransformerListView : public SimpleListView,
public ShapeListener { public ContainerListener<Transformer> {
public: public:
TransformerListView(BRect frame, TransformerListView(BRect frame,
const char* name, const char* name,
@@ -51,12 +54,9 @@ class TransformerListView : public SimpleListView,
virtual int32 IndexOfSelectable(Selectable* selectable) const; virtual int32 IndexOfSelectable(Selectable* selectable) const;
virtual Selectable* SelectableFor(BListItem* item) const; virtual Selectable* SelectableFor(BListItem* item) const;
// ShapeListener interface // ContainerListener<Transformer> interface
virtual void TransformerAdded(Transformer* transformer, virtual void ItemAdded(Transformer* transformer, int32 index);
int32 index); virtual void ItemRemoved(Transformer* transformer);
virtual void TransformerRemoved(Transformer* transformer);
virtual void StyleChanged(Style* oldStyle, Style* newStyle);
// TransformerListView // TransformerListView
void SetMenu(BMenu* menu); void SetMenu(BMenu* menu);
@@ -9,8 +9,6 @@
#include "Importer.h" #include "Importer.h"
#include "Icon.h" #include "Icon.h"
#include "PathContainer.h"
#include "StyleContainer.h"
// constructor // constructor
Importer::Importer() Importer::Importer()
@@ -34,8 +32,8 @@ Importer::Init(Icon* icon)
if (!icon || icon->InitCheck() < B_OK) if (!icon || icon->InitCheck() < B_OK)
return B_BAD_VALUE; return B_BAD_VALUE;
fStyleIndexOffset = icon->Styles()->CountStyles(); fStyleIndexOffset = icon->Styles()->CountItems();
fPathIndexOffset = icon->Paths()->CountPaths(); fPathIndexOffset = icon->Paths()->CountItems();
return B_OK; return B_OK;
} }
@@ -18,25 +18,24 @@
#include <Node.h> #include <Node.h>
#include "AffineTransformer.h" #include "AffineTransformer.h"
#include "Container.h"
#include "ContourTransformer.h" #include "ContourTransformer.h"
#include "FlatIconFormat.h" #include "FlatIconFormat.h"
#include "GradientTransformable.h" #include "GradientTransformable.h"
#include "Icon.h" #include "Icon.h"
#include "LittleEndianBuffer.h" #include "LittleEndianBuffer.h"
#include "PathCommandQueue.h" #include "PathCommandQueue.h"
#include "PathContainer.h"
#include "PathSourceShape.h" #include "PathSourceShape.h"
#include "PerspectiveTransformer.h" #include "PerspectiveTransformer.h"
#include "ReferenceImage.h" #include "ReferenceImage.h"
#include "Shape.h" #include "Shape.h"
#include "StrokeTransformer.h" #include "StrokeTransformer.h"
#include "Style.h" #include "Style.h"
#include "StyleContainer.h"
#include "VectorPath.h" #include "VectorPath.h"
using std::nothrow; using std::nothrow;
// constructor
FlatIconExporter::FlatIconExporter() FlatIconExporter::FlatIconExporter()
#if PRINT_STATISTICS #if PRINT_STATISTICS
: fStyleSectionSize(0) : fStyleSectionSize(0)
@@ -49,7 +48,7 @@ FlatIconExporter::FlatIconExporter()
{ {
} }
// destructor
FlatIconExporter::~FlatIconExporter() FlatIconExporter::~FlatIconExporter()
{ {
#if PRINT_STATISTICS #if PRINT_STATISTICS
@@ -70,7 +69,7 @@ FlatIconExporter::~FlatIconExporter()
#endif // PRINT_STATISTICS #endif // PRINT_STATISTICS
} }
// Export
status_t status_t
FlatIconExporter::Export(const Icon* icon, BPositionIO* stream) FlatIconExporter::Export(const Icon* icon, BPositionIO* stream)
{ {
@@ -92,7 +91,7 @@ FlatIconExporter::Export(const Icon* icon, BPositionIO* stream)
return B_OK; return B_OK;
} }
// Export
status_t status_t
FlatIconExporter::Export(const Icon* icon, BNode* node, FlatIconExporter::Export(const Icon* icon, BNode* node,
const char* attrName) const char* attrName)
@@ -128,9 +127,10 @@ FlatIconExporter::Export(const Icon* icon, BNode* node,
return B_OK; return B_OK;
} }
// #pragma mark - // #pragma mark -
// _Export
status_t status_t
FlatIconExporter::_Export(LittleEndianBuffer& buffer, const Icon* icon) FlatIconExporter::_Export(LittleEndianBuffer& buffer, const Icon* icon)
{ {
@@ -144,7 +144,7 @@ FlatIconExporter::_Export(LittleEndianBuffer& buffer, const Icon* icon)
#endif #endif
// styles // styles
StyleContainer* styles = icon->Styles(); const Container<Style>* styles = icon->Styles();
status_t ret = _WriteStyles(buffer, styles); status_t ret = _WriteStyles(buffer, styles);
if (ret < B_OK) if (ret < B_OK)
return ret; return ret;
@@ -154,7 +154,7 @@ FlatIconExporter::_Export(LittleEndianBuffer& buffer, const Icon* icon)
#endif #endif
// paths // paths
PathContainer* paths = icon->Paths(); const Container<VectorPath>* paths = icon->Paths();
ret = _WritePaths(buffer, paths); ret = _WritePaths(buffer, paths);
if (ret < B_OK) if (ret < B_OK)
return ret; return ret;
@@ -176,10 +176,9 @@ FlatIconExporter::_Export(LittleEndianBuffer& buffer, const Icon* icon)
return B_OK; return B_OK;
} }
// _WriteTransformable
static bool static bool
_WriteTransformable(LittleEndianBuffer& buffer, _WriteTransformable(LittleEndianBuffer& buffer, const Transformable* transformable)
const Transformable* transformable)
{ {
int32 matrixSize = Transformable::matrix_size; int32 matrixSize = Transformable::matrix_size;
double matrix[matrixSize]; double matrix[matrixSize];
@@ -193,29 +192,27 @@ _WriteTransformable(LittleEndianBuffer& buffer,
return true; return true;
} }
// _WriteTranslation
static bool static bool
_WriteTranslation(LittleEndianBuffer& buffer, _WriteTranslation(LittleEndianBuffer& buffer, const Transformable* transformable)
const Transformable* transformable)
{ {
BPoint t(B_ORIGIN); BPoint t(B_ORIGIN);
transformable->Transform(&t); transformable->Transform(&t);
return write_coord(buffer, t.x) && write_coord(buffer, t.y); return write_coord(buffer, t.x) && write_coord(buffer, t.y);
} }
// _WriteStyles
status_t status_t
FlatIconExporter::_WriteStyles(LittleEndianBuffer& buffer, FlatIconExporter::_WriteStyles(LittleEndianBuffer& buffer, const Container<Style>* styles)
StyleContainer* styles)
{ {
if (styles->CountStyles() > 255) if (styles->CountItems() > 255)
return B_RESULT_NOT_REPRESENTABLE; return B_RESULT_NOT_REPRESENTABLE;
uint8 styleCount = min_c(255, styles->CountStyles()); uint8 styleCount = min_c(255, styles->CountItems());
if (!buffer.Write(styleCount)) if (!buffer.Write(styleCount))
return B_NO_MEMORY; return B_NO_MEMORY;
for (int32 i = 0; i < styleCount; i++) { for (int32 i = 0; i < styleCount; i++) {
Style* style = styles->StyleAtFast(i); Style* style = styles->ItemAtFast(i);
// style type // style type
uint8 styleType; uint8 styleType;
@@ -275,7 +272,7 @@ FlatIconExporter::_WriteStyles(LittleEndianBuffer& buffer,
return B_OK; return B_OK;
} }
// _AnalysePath
bool bool
FlatIconExporter::_AnalysePath(VectorPath* path, uint8 pointCount, FlatIconExporter::_AnalysePath(VectorPath* path, uint8 pointCount,
int32& straightCount, int32& lineCount, int32& curveCount) int32& straightCount, int32& lineCount, int32& curveCount)
@@ -312,10 +309,9 @@ FlatIconExporter::_AnalysePath(VectorPath* path, uint8 pointCount,
} }
// write_path_no_curves
static bool static bool
write_path_no_curves(LittleEndianBuffer& buffer, VectorPath* path, write_path_no_curves(LittleEndianBuffer& buffer, VectorPath* path, uint8 pointCount)
uint8 pointCount)
{ {
//printf("write_path_no_curves()\n"); //printf("write_path_no_curves()\n");
for (uint32 p = 0; p < pointCount; p++) { for (uint32 p = 0; p < pointCount; p++) {
@@ -328,10 +324,9 @@ write_path_no_curves(LittleEndianBuffer& buffer, VectorPath* path,
return true; return true;
} }
// write_path_curves
static bool static bool
write_path_curves(LittleEndianBuffer& buffer, VectorPath* path, write_path_curves(LittleEndianBuffer& buffer, VectorPath* path, uint8 pointCount)
uint8 pointCount)
{ {
//printf("write_path_curves()\n"); //printf("write_path_curves()\n");
for (uint32 p = 0; p < pointCount; p++) { for (uint32 p = 0; p < pointCount; p++) {
@@ -353,28 +348,27 @@ write_path_curves(LittleEndianBuffer& buffer, VectorPath* path,
return true; return true;
} }
// write_path_with_commands
static bool static bool
write_path_with_commands(LittleEndianBuffer& buffer, VectorPath* path, write_path_with_commands(LittleEndianBuffer& buffer, VectorPath* path, uint8 pointCount)
uint8 pointCount)
{ {
PathCommandQueue queue; PathCommandQueue queue;
return queue.Write(buffer, path, pointCount); return queue.Write(buffer, path, pointCount);
} }
// _WritePaths
status_t status_t
FlatIconExporter::_WritePaths(LittleEndianBuffer& buffer, PathContainer* paths) FlatIconExporter::_WritePaths(LittleEndianBuffer& buffer, const Container<VectorPath>* paths)
{ {
if (paths->CountPaths() > 255) if (paths->CountItems() > 255)
return B_RESULT_NOT_REPRESENTABLE; return B_RESULT_NOT_REPRESENTABLE;
uint8 pathCount = min_c(255, paths->CountPaths()); uint8 pathCount = min_c(255, paths->CountItems());
if (!buffer.Write(pathCount)) if (!buffer.Write(pathCount))
return B_NO_MEMORY; return B_NO_MEMORY;
for (uint32 i = 0; i < pathCount; i++) { for (uint32 i = 0; i < pathCount; i++) {
VectorPath* path = paths->PathAtFast(i); VectorPath* path = paths->ItemAtFast(i);
uint8 pathFlags = 0; uint8 pathFlags = 0;
if (path->IsClosed()) if (path->IsClosed())
pathFlags |= PATH_FLAG_CLOSED; pathFlags |= PATH_FLAG_CLOSED;
@@ -424,7 +418,7 @@ FlatIconExporter::_WritePaths(LittleEndianBuffer& buffer, PathContainer* paths)
return B_OK; return B_OK;
} }
// _WriteTransformer
static bool static bool
_WriteTransformer(LittleEndianBuffer& buffer, Transformer* t) _WriteTransformer(LittleEndianBuffer& buffer, Transformer* t)
{ {
@@ -478,10 +472,10 @@ _WriteTransformer(LittleEndianBuffer& buffer, Transformer* t)
return true; return true;
} }
// _WritePathSourceShape
static bool static bool
_WritePathSourceShape(LittleEndianBuffer& buffer, PathSourceShape* shape, _WritePathSourceShape(LittleEndianBuffer& buffer, PathSourceShape* shape,
StyleContainer* styles, PathContainer* paths) const Container<Style>* styles, const Container<VectorPath>* paths)
{ {
// find out which style this shape uses // find out which style this shape uses
Style* style = shape->Style(); Style* style = shape->Style();
@@ -492,9 +486,9 @@ _WritePathSourceShape(LittleEndianBuffer& buffer, PathSourceShape* shape,
if (styleIndex < 0 || styleIndex > 255) if (styleIndex < 0 || styleIndex > 255)
return false; return false;
if (shape->Paths()->CountPaths() > 255) if (shape->Paths()->CountItems() > 255)
return B_RESULT_NOT_REPRESENTABLE; return B_RESULT_NOT_REPRESENTABLE;
uint8 pathCount = min_c(255, shape->Paths()->CountPaths()); uint8 pathCount = min_c(255, shape->Paths()->CountItems());
// write shape type and style index // write shape type and style index
if (!buffer.Write((uint8)SHAPE_TYPE_PATH_SOURCE) if (!buffer.Write((uint8)SHAPE_TYPE_PATH_SOURCE)
@@ -504,7 +498,7 @@ _WritePathSourceShape(LittleEndianBuffer& buffer, PathSourceShape* shape,
// find out which paths this shape uses // find out which paths this shape uses
for (uint32 i = 0; i < pathCount; i++) { for (uint32 i = 0; i < pathCount; i++) {
VectorPath* path = shape->Paths()->PathAtFast(i); VectorPath* path = shape->Paths()->ItemAtFast(i);
int32 pathIndex = paths->IndexOf(path); int32 pathIndex = paths->IndexOf(path);
if (pathIndex < 0 || pathIndex > 255) if (pathIndex < 0 || pathIndex > 255)
return false; return false;
@@ -513,9 +507,9 @@ _WritePathSourceShape(LittleEndianBuffer& buffer, PathSourceShape* shape,
return false; return false;
} }
if (shape->CountTransformers() > 255) if (shape->Transformers()->CountItems() > 255)
return B_RESULT_NOT_REPRESENTABLE; return B_RESULT_NOT_REPRESENTABLE;
uint8 transformerCount = min_c(255, shape->CountTransformers()); uint8 transformerCount = min_c(255, shape->Transformers()->CountItems());
// shape flags // shape flags
uint8 shapeFlags = 0; uint8 shapeFlags = 0;
@@ -562,7 +556,7 @@ _WritePathSourceShape(LittleEndianBuffer& buffer, PathSourceShape* shape,
return false; return false;
for (uint32 i = 0; i < transformerCount; i++) { for (uint32 i = 0; i < transformerCount; i++) {
Transformer* transformer = shape->TransformerAtFast(i); Transformer* transformer = shape->Transformers()->ItemAtFast(i);
if (!_WriteTransformer(buffer, transformer)) if (!_WriteTransformer(buffer, transformer))
return false; return false;
} }
@@ -571,19 +565,17 @@ _WritePathSourceShape(LittleEndianBuffer& buffer, PathSourceShape* shape,
return true; return true;
} }
// _WriteShapes
status_t status_t
FlatIconExporter::_WriteShapes(LittleEndianBuffer& buffer, FlatIconExporter::_WriteShapes(LittleEndianBuffer& buffer, const Container<Style>* styles,
StyleContainer* styles, const Container<VectorPath>* paths, const Container<Shape>* shapes)
PathContainer* paths,
ShapeContainer* shapes)
{ {
uint32 shapeCount = shapes->CountShapes(); uint32 shapeCount = shapes->CountItems();
// Count the number of exportable shapes // Count the number of exportable shapes
uint32 pathShapeCount = 0; uint32 pathShapeCount = 0;
for (uint32 i = 0; i < shapeCount; i++) { for (uint32 i = 0; i < shapeCount; i++) {
Shape* shape = shapes->ShapeAtFast(i); Shape* shape = shapes->ItemAtFast(i);
if (dynamic_cast<PathSourceShape*>(shape) != NULL) if (dynamic_cast<PathSourceShape*>(shape) != NULL)
pathShapeCount++; pathShapeCount++;
} }
@@ -596,7 +588,7 @@ FlatIconExporter::_WriteShapes(LittleEndianBuffer& buffer,
// Export each shape // Export each shape
for (uint32 i = 0; i < shapeCount; i++) { for (uint32 i = 0; i < shapeCount; i++) {
Shape* shape = shapes->ShapeAtFast(i); Shape* shape = shapes->ItemAtFast(i);
PathSourceShape* pathSourceShape = dynamic_cast<PathSourceShape*>(shape); PathSourceShape* pathSourceShape = dynamic_cast<PathSourceShape*>(shape);
if (pathSourceShape != NULL) { if (pathSourceShape != NULL) {
@@ -608,10 +600,9 @@ FlatIconExporter::_WriteShapes(LittleEndianBuffer& buffer,
return B_OK; return B_OK;
} }
// _WriteGradient
bool bool
FlatIconExporter::_WriteGradient(LittleEndianBuffer& buffer, FlatIconExporter::_WriteGradient(LittleEndianBuffer& buffer, const Gradient* gradient)
const Gradient* gradient)
{ {
#if PRINT_STATISTICS #if PRINT_STATISTICS
size_t currentSize = buffer.SizeUsed(); size_t currentSize = buffer.SizeUsed();
@@ -688,5 +679,3 @@ FlatIconExporter::_WriteGradient(LittleEndianBuffer& buffer,
return true; return true;
} }
@@ -17,11 +17,11 @@ class BNode;
class BPositionIO; class BPositionIO;
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
template <class Type> class Container;
class Gradient; class Gradient;
class LittleEndianBuffer; class LittleEndianBuffer;
class PathContainer; class Shape;
class ShapeContainer; class Style;
class StyleContainer;
class VectorPath; class VectorPath;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
@@ -68,13 +68,13 @@ class FlatIconExporter : public Exporter {
const Icon* icon); const Icon* icon);
status_t _WriteStyles(LittleEndianBuffer& buffer, status_t _WriteStyles(LittleEndianBuffer& buffer,
StyleContainer* styles); const Container<Style>* styles);
status_t _WritePaths(LittleEndianBuffer& buffer, status_t _WritePaths(LittleEndianBuffer& buffer,
PathContainer* paths); const Container<VectorPath>* paths);
status_t _WriteShapes(LittleEndianBuffer& buffer, status_t _WriteShapes(LittleEndianBuffer& buffer,
StyleContainer* styles, const Container<Style>* styles,
PathContainer* paths, const Container<VectorPath>* paths,
ShapeContainer* shapes); const Container<Shape>* shapes);
bool _WriteGradient(LittleEndianBuffer& buffer, bool _WriteGradient(LittleEndianBuffer& buffer,
const Gradient* gradient); const Gradient* gradient);
@@ -14,14 +14,13 @@
#include <Message.h> #include <Message.h>
#include <TypeConstants.h> #include <TypeConstants.h>
#include "Container.h"
#include "Defines.h" #include "Defines.h"
#include "Icon.h" #include "Icon.h"
#include "PathContainer.h"
#include "PathSourceShape.h" #include "PathSourceShape.h"
#include "ReferenceImage.h" #include "ReferenceImage.h"
#include "Shape.h" #include "Shape.h"
#include "Style.h" #include "Style.h"
#include "StyleContainer.h"
#include "Transformer.h" #include "Transformer.h"
#include "VectorPath.h" #include "VectorPath.h"
@@ -42,15 +41,15 @@ MessageExporter::Export(const Icon* icon, BPositionIO* stream)
status_t ret = B_OK; status_t ret = B_OK;
BMessage archive; BMessage archive;
PathContainer* paths = icon->Paths(); const Container<VectorPath>* paths = icon->Paths();
StyleContainer* styles = icon->Styles(); const Container<Style>* styles = icon->Styles();
// paths // paths
if (ret == B_OK) { if (ret == B_OK) {
BMessage allPaths; BMessage allPaths;
int32 count = paths->CountPaths(); int32 count = paths->CountItems();
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
VectorPath* path = paths->PathAtFast(i); VectorPath* path = paths->ItemAtFast(i);
BMessage pathArchive; BMessage pathArchive;
ret = _Export(path, &pathArchive); ret = _Export(path, &pathArchive);
if (ret < B_OK) if (ret < B_OK)
@@ -67,9 +66,9 @@ MessageExporter::Export(const Icon* icon, BPositionIO* stream)
// styles // styles
if (ret == B_OK) { if (ret == B_OK) {
BMessage allStyles; BMessage allStyles;
int32 count = styles->CountStyles(); int32 count = styles->CountItems();
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
Style* style = styles->StyleAtFast(i); Style* style = styles->ItemAtFast(i);
BMessage styleArchive; BMessage styleArchive;
ret = _Export(style, &styleArchive); ret = _Export(style, &styleArchive);
if (ret < B_OK) if (ret < B_OK)
@@ -86,10 +85,10 @@ MessageExporter::Export(const Icon* icon, BPositionIO* stream)
// shapes // shapes
if (ret == B_OK) { if (ret == B_OK) {
BMessage allShapes; BMessage allShapes;
ShapeContainer* shapes = icon->Shapes(); const Container<Shape>* shapes = icon->Shapes();
int32 count = shapes->CountShapes(); int32 count = shapes->CountItems();
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
Shape* shape = shapes->ShapeAtFast(i); Shape* shape = shapes->ItemAtFast(i);
BMessage shapeArchive; BMessage shapeArchive;
ret = _Export(shape, paths, styles, &shapeArchive); ret = _Export(shape, paths, styles, &shapeArchive);
if (ret < B_OK) if (ret < B_OK)
@@ -149,8 +148,8 @@ MessageExporter::_Export(const Style* style, BMessage* into) const
// _Export // _Export
status_t status_t
MessageExporter::_Export(const Shape* shape, MessageExporter::_Export(const Shape* shape,
const PathContainer* globalPaths, const Container<VectorPath>* globalPaths,
const StyleContainer* globalStyles, const Container<Style>* globalStyles,
BMessage* into) const BMessage* into) const
{ {
status_t ret = B_OK; status_t ret = B_OK;
@@ -174,9 +173,9 @@ MessageExporter::_Export(const Shape* shape,
// indices of used paths // indices of used paths
if (ret == B_OK) { if (ret == B_OK) {
int32 count = pathSourceShape->Paths()->CountPaths(); int32 count = pathSourceShape->Paths()->CountItems();
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
VectorPath* path = pathSourceShape->Paths()->PathAtFast(i); VectorPath* path = pathSourceShape->Paths()->ItemAtFast(i);
ret = into->AddInt32("path ref", globalPaths->IndexOf(path)); ret = into->AddInt32("path ref", globalPaths->IndexOf(path));
if (ret < B_OK) if (ret < B_OK)
break; break;
@@ -15,11 +15,10 @@ class BMessage;
class BPositionIO; class BPositionIO;
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
template <class Type> class Container;
class Icon; class Icon;
class PathContainer;
class Shape; class Shape;
class Style; class Style;
class StyleContainer;
class Transformer; class Transformer;
class VectorPath; class VectorPath;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
@@ -41,8 +40,8 @@ class MessageExporter : public Exporter {
status_t _Export(const Style* style, status_t _Export(const Style* style,
BMessage* into) const; BMessage* into) const;
status_t _Export(const Shape* shape, status_t _Export(const Shape* shape,
const PathContainer* globalPaths, const Container<VectorPath>* globalPaths,
const StyleContainer* globalStyles, const Container<Style>* globalStyles,
BMessage* into) const; BMessage* into) const;
}; };
@@ -28,10 +28,8 @@
#include "Defines.h" #include "Defines.h"
#include "Icon.h" #include "Icon.h"
#include "PathContainer.h"
#include "PathSourceShape.h" #include "PathSourceShape.h"
#include "Style.h" #include "Style.h"
#include "StyleContainer.h"
#include "VectorPath.h" #include "VectorPath.h"
@@ -156,8 +154,8 @@ ShapeIterator::NextPath()
{ {
CALLED(); CALLED();
if (fPath) { if (fPath) {
fIcon->Paths()->AddPath(fPath); fIcon->Paths()->AddItem(fPath);
fShape->Paths()->AddPath(fPath); fShape->Paths()->AddItem(fPath);
} }
fPath = NULL; fPath = NULL;
} }
@@ -332,7 +330,7 @@ StyledTextImporter::_Import(Icon* icon, const char *text, text_run_array *runs)
if (shape == NULL) if (shape == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
shape->SetName(glyphName.String()); shape->SetName(glyphName.String());
if (!icon->Shapes()->AddShape(shape)) { if (!icon->Shapes()->AddItem(shape)) {
delete shape; delete shape;
return B_NO_MEMORY; return B_NO_MEMORY;
} }
@@ -386,7 +384,7 @@ StyledTextImporter::_AddStyle(Icon *icon, text_run *run)
} }
} }
if (!found && !icon->Styles()->AddStyle(style)) { if (!found && !icon->Styles()->AddItem(style)) {
delete style; delete style;
return B_NO_MEMORY; return B_NO_MEMORY;
} }
@@ -20,10 +20,6 @@ struct text_run_array;
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
class Icon; class Icon;
class Style; class Style;
class VectorPath;
class PathContainer;
class ShapeContainer;
class StyleContainer;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
struct style_map { struct style_map {
@@ -18,12 +18,9 @@
#include "AutoDeleter.h" #include "AutoDeleter.h"
#include "GradientTransformable.h" #include "GradientTransformable.h"
#include "Icon.h" #include "Icon.h"
#include "PathContainer.h"
#include "PathSourceShape.h" #include "PathSourceShape.h"
#include "ShapeContainer.h"
#include "StrokeTransformer.h" #include "StrokeTransformer.h"
#include "Style.h" #include "Style.h"
#include "StyleContainer.h"
#include "SVGImporter.h" #include "SVGImporter.h"
#include "VectorPath.h" #include "VectorPath.h"
@@ -110,9 +107,9 @@ printf("scale: %f\n", scale);
} }
// clean up styles and paths (remove duplicates) // clean up styles and paths (remove duplicates)
int32 count = icon->Shapes()->CountShapes(); int32 count = icon->Shapes()->CountItems();
for (int32 i = 1; i < count; i++) { for (int32 i = 1; i < count; i++) {
PathSourceShape* shape = dynamic_cast<PathSourceShape*>(icon->Shapes()->ShapeAtFast(i)); PathSourceShape* shape = dynamic_cast<PathSourceShape*>(icon->Shapes()->ItemAtFast(i));
if (shape == NULL) if (shape == NULL)
continue; continue;
@@ -121,10 +118,10 @@ printf("scale: %f\n", scale);
continue; continue;
int32 styleIndex = icon->Styles()->IndexOf(style); int32 styleIndex = icon->Styles()->IndexOf(style);
for (int32 j = 0; j < styleIndex; j++) { for (int32 j = 0; j < styleIndex; j++) {
Style* earlierStyle = icon->Styles()->StyleAtFast(j); Style* earlierStyle = icon->Styles()->ItemAtFast(j);
if (*style == *earlierStyle) { if (*style == *earlierStyle) {
shape->SetStyle(earlierStyle); shape->SetStyle(earlierStyle);
icon->Styles()->RemoveStyle(style); icon->Styles()->RemoveItem(style);
style->ReleaseReference(); style->ReleaseReference();
break; break;
} }
@@ -144,12 +141,12 @@ AddPathsFromVertexSource(Icon* icon, PathSourceShape* shape, NSVGshape* svgShape
for (NSVGpath* svgPath = svgShape->paths; svgPath != NULL; for (NSVGpath* svgPath = svgShape->paths; svgPath != NULL;
svgPath = svgPath->next) { svgPath = svgPath->next) {
VectorPath* path = new (nothrow) VectorPath(); VectorPath* path = new (nothrow) VectorPath();
if (!path || !icon->Paths()->AddPath(path)) { if (!path || !icon->Paths()->AddItem(path)) {
delete path; delete path;
return B_NO_MEMORY; return B_NO_MEMORY;
} }
if (!shape->Paths()->AddPath(path)) if (!shape->Paths()->AddItem(path))
return B_NO_MEMORY; return B_NO_MEMORY;
path->SetClosed(svgPath->closed); path->SetClosed(svgPath->closed);
@@ -198,7 +195,7 @@ DocumentBuilder::_AddShape(NSVGshape* svgShape, bool outline,
const Transformable& transform, Icon* icon) const Transformable& transform, Icon* icon)
{ {
PathSourceShape* shape = new (nothrow) PathSourceShape(NULL); PathSourceShape* shape = new (nothrow) PathSourceShape(NULL);
if (!shape || !icon->Shapes()->AddShape(shape)) { if (!shape || !icon->Shapes()->AddItem(shape)) {
delete shape; delete shape;
return B_NO_MEMORY; return B_NO_MEMORY;
} }
@@ -242,7 +239,7 @@ DocumentBuilder::_AddShape(NSVGshape* svgShape, bool outline,
} }
} }
if (!shape->AddTransformer(stroke)) { if (!shape->Transformers()->AddItem(stroke)) {
delete stroke; delete stroke;
stroke = NULL; stroke = NULL;
} }
@@ -325,16 +322,16 @@ DocumentBuilder::_AddShape(NSVGshape* svgShape, bool outline,
color.alpha = (uint8)(color.alpha * svgShape->opacity); color.alpha = (uint8)(color.alpha * svgShape->opacity);
Style* style = new (nothrow) Style(color); Style* style = new (nothrow) Style(color);
if (!style || !icon->Styles()->AddStyle(style)) { if (!style || !icon->Styles()->AddItem(style)) {
delete style; delete style;
return B_NO_MEMORY; return B_NO_MEMORY;
} }
// NOTE: quick hack to freeze all transformations (only works because // NOTE: quick hack to freeze all transformations (only works because
// paths and styles are not used by multiple shapes!!) // paths and styles are not used by multiple shapes!!)
int32 pathCount = shape->Paths()->CountPaths(); int32 pathCount = shape->Paths()->CountItems();
for (int32 i = 0; i < pathCount; i++) { for (int32 i = 0; i < pathCount; i++) {
VectorPath* path = shape->Paths()->PathAtFast(i); VectorPath* path = shape->Paths()->ItemAtFast(i);
path->ApplyTransform(*shape); path->ApplyTransform(*shape);
} }
@@ -103,9 +103,9 @@ SVGExporter::Export(const Icon* icon, BPositionIO* stream)
// export all shapes // export all shapes
if (ret >= B_OK) { if (ret >= B_OK) {
int32 count = icon->Shapes()->CountShapes(); int32 count = icon->Shapes()->CountItems();
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
Shape* shape = icon->Shapes()->ShapeAtFast(i); Shape* shape = icon->Shapes()->ItemAtFast(i);
ret = _ExportShape(shape, stream); ret = _ExportShape(shape, stream);
if (ret < B_OK) if (ret < B_OK)
break; break;
@@ -237,7 +237,7 @@ SVGExporter::_ExportShape(const Shape* shape, BPositionIO* stream)
// hack to see if this is an outline shape // hack to see if this is an outline shape
StrokeTransformer* stroke StrokeTransformer* stroke
= dynamic_cast<StrokeTransformer*>(pathSourceShape->TransformerAt(0)); = dynamic_cast<StrokeTransformer*>(pathSourceShape->Transformers()->ItemAt(0));
if (stroke) { if (stroke) {
helper << "style=\"fill:none; stroke:" << color; helper << "style=\"fill:none; stroke:" << color;
if (!style->Gradient() && style->Color().alpha < 255) { if (!style->Gradient() && style->Color().alpha < 255) {
@@ -279,9 +279,9 @@ SVGExporter::_ExportShape(const Shape* shape, BPositionIO* stream)
if (ret < B_OK) if (ret < B_OK)
return ret; return ret;
int32 count = pathSourceShape->Paths()->CountPaths(); int32 count = pathSourceShape->Paths()->CountItems();
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
VectorPath* path = pathSourceShape->Paths()->PathAtFast(i); VectorPath* path = pathSourceShape->Paths()->ItemAtFast(i);
if (i > 0) { if (i > 0) {
helper << "\n "; helper << "\n ";
@@ -1,21 +1,17 @@
/* /*
* Copyright 2006, Haiku. * Copyright 2006, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#include "AddPathsCommand.h" #include "AddPathsCommand.h"
#include <new>
#include <stdio.h>
#include <string.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include "PathContainer.h"
#include "VectorPath.h" #include "VectorPath.h"
@@ -23,91 +19,22 @@
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-AddPathsCmd" #define B_TRANSLATION_CONTEXT "Icon-O-Matic-AddPathsCmd"
using std::nothrow; AddPathsCommand::AddPathsCommand(Container<VectorPath>* container,
const VectorPath* const* paths, int32 count, bool ownsPaths, int32 index)
// constructor : AddCommand<VectorPath>(container, paths, count, ownsPaths, index)
AddPathsCommand::AddPathsCommand(PathContainer* container,
VectorPath** const paths,
int32 count,
bool ownsPaths,
int32 index)
: Command(),
fContainer(container),
fPaths(paths && count > 0 ? new (nothrow) VectorPath*[count] : NULL),
fCount(count),
fOwnsPaths(ownsPaths),
fIndex(index),
fPathsAdded(false)
{ {
if (!fContainer || !fPaths)
return;
memcpy(fPaths, paths, sizeof(VectorPath*) * fCount);
if (!fOwnsPaths) {
// Add references to paths
for (int32 i = 0; i < fCount; i++) {
if (fPaths[i] != NULL)
fPaths[i]->AcquireReference();
}
}
} }
// destructor
AddPathsCommand::~AddPathsCommand() AddPathsCommand::~AddPathsCommand()
{ {
if (!fPathsAdded && fPaths) {
for (int32 i = 0; i < fCount; i++) {
if (fPaths[i] != NULL)
fPaths[i]->ReleaseReference();
}
}
delete[] fPaths;
} }
// InitCheck
status_t
AddPathsCommand::InitCheck()
{
return fContainer && fPaths ? B_OK : B_NO_INIT;
}
// Perform
status_t
AddPathsCommand::Perform()
{
// add paths to container
for (int32 i = 0; i < fCount; i++) {
if (fPaths[i] && !fContainer->AddPath(fPaths[i], fIndex + i)) {
// roll back
for (int32 j = i - 1; j >= 0; j--)
fContainer->RemovePath(fPaths[j]);
return B_ERROR;
}
}
fPathsAdded = true;
return B_OK;
}
// Undo
status_t
AddPathsCommand::Undo()
{
// remove paths from container
for (int32 i = 0; i < fCount; i++) {
fContainer->RemovePath(fPaths[i]);
}
fPathsAdded = false;
return B_OK;
}
// GetName
void void
AddPathsCommand::GetName(BString& name) AddPathsCommand::GetName(BString& name)
{ {
if (fOwnsPaths) { if (fOwnsItems) {
if (fCount > 1) if (fCount > 1)
name << B_TRANSLATE("Add Paths"); name << B_TRANSLATE("Add Paths");
else else
@@ -1,50 +1,37 @@
/* /*
* Copyright 2006-2007, Haiku. * Copyright 2006-2007, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#ifndef ADD_PATHS_COMMAND_H #ifndef ADD_PATHS_COMMAND_H
#define ADD_PATHS_COMMAND_H #define ADD_PATHS_COMMAND_H
#include "Command.h" #include "AddCommand.h"
#include "IconBuild.h" #include "IconBuild.h"
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
class VectorPath; class VectorPath;
class PathContainer;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
_USING_ICON_NAMESPACE _USING_ICON_NAMESPACE
class AddPathsCommand : public Command { class AddPathsCommand : public AddCommand<VectorPath> {
public: public:
AddPathsCommand( AddPathsCommand(
PathContainer* container, Container<VectorPath>* container,
VectorPath** const paths, const VectorPath* const* paths,
int32 count, int32 count,
bool ownsPaths, bool ownsPaths,
int32 index); int32 index);
virtual ~AddPathsCommand(); virtual ~AddPathsCommand();
virtual status_t InitCheck();
virtual status_t Perform();
virtual status_t Undo();
virtual void GetName(BString& name); virtual void GetName(BString& name);
private:
PathContainer* fContainer;
VectorPath** fPaths;
int32 fCount;
bool fOwnsPaths;
int32 fIndex;
bool fPathsAdded;
}; };
#endif // ADD_PATHS_COMMAND_H #endif // ADD_PATHS_COMMAND_H
@@ -1,22 +1,17 @@
/* /*
* Copyright 2006, Haiku. * Copyright 2006, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#include "AddShapesCommand.h" #include "AddShapesCommand.h"
#include <new>
#include <stdio.h>
#include <string.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include "Selection.h"
#include "ShapeContainer.h"
#include "Shape.h" #include "Shape.h"
@@ -24,85 +19,18 @@
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-AddShapesCmd" #define B_TRANSLATION_CONTEXT "Icon-O-Matic-AddShapesCmd"
using std::nothrow; AddShapesCommand::AddShapesCommand(Container<Shape>* container,
const Shape* const* shapes, int32 count, int32 index)
// constructor : AddCommand<Shape>(container, shapes, count, true, index)
AddShapesCommand::AddShapesCommand(ShapeContainer* container,
Shape** const shapes,
int32 count,
int32 index,
Selection* selection)
: Command(),
fContainer(container),
fShapes(shapes && count > 0 ? new (nothrow) Shape*[count] : NULL),
fCount(count),
fIndex(index),
fShapesAdded(false),
fSelection(selection)
{ {
if (!fContainer || !fShapes)
return;
memcpy(fShapes, shapes, sizeof(Shape*) * fCount);
} }
// destructor
AddShapesCommand::~AddShapesCommand() AddShapesCommand::~AddShapesCommand()
{ {
if (!fShapesAdded && fShapes) {
for (int32 i = 0; i < fCount; i++)
fShapes[i]->ReleaseReference();
}
delete[] fShapes;
} }
// InitCheck
status_t
AddShapesCommand::InitCheck()
{
return fContainer && fShapes ? B_OK : B_NO_INIT;
}
// Perform
status_t
AddShapesCommand::Perform()
{
status_t ret = B_OK;
// add shapes to container
int32 index = fIndex;
for (int32 i = 0; i < fCount; i++) {
if (fShapes[i] && !fContainer->AddShape(fShapes[i], index)) {
ret = B_ERROR;
// roll back
for (int32 j = i - 1; j >= 0; j--)
fContainer->RemoveShape(fShapes[j]);
break;
}
index++;
}
fShapesAdded = true;
return ret;
}
// Undo
status_t
AddShapesCommand::Undo()
{
// remove shapes from container
for (int32 i = 0; i < fCount; i++) {
if (fSelection)
fSelection->Deselect(fShapes[i]);
fContainer->RemoveShape(fShapes[i]);
}
fShapesAdded = false;
return B_OK;
}
// GetName
void void
AddShapesCommand::GetName(BString& name) AddShapesCommand::GetName(BString& name)
{ {
@@ -1,53 +1,36 @@
/* /*
* Copyright 2006-2007, Haiku. * Copyright 2006-2007, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#ifndef ADD_SHAPES_COMMAND_H #ifndef ADD_SHAPES_COMMAND_H
#define ADD_SHAPES_COMMAND_H #define ADD_SHAPES_COMMAND_H
#include "Command.h" #include "AddCommand.h"
#include "IconBuild.h" #include "IconBuild.h"
class Selection;
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
class Shape; class Shape;
class ShapeContainer;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
_USING_ICON_NAMESPACE _USING_ICON_NAMESPACE
class AddShapesCommand : public Command { class AddShapesCommand : public AddCommand<Shape> {
public: public:
AddShapesCommand( AddShapesCommand(
ShapeContainer* container, Container<Shape>* container,
Shape** const shapes, const Shape* const* shapes,
int32 count, int32 count,
int32 index, int32 index);
Selection* selection);
virtual ~AddShapesCommand(); virtual ~AddShapesCommand();
virtual status_t InitCheck();
virtual status_t Perform();
virtual status_t Undo();
virtual void GetName(BString& name); virtual void GetName(BString& name);
private:
ShapeContainer* fContainer;
Shape** fShapes;
int32 fCount;
int32 fIndex;
bool fShapesAdded;
Selection* fSelection;
}; };
#endif // ADD_SHAPES_COMMAND_H #endif // ADD_SHAPES_COMMAND_H
@@ -1,106 +1,36 @@
/* /*
* Copyright 2006, Haiku. * Copyright 2006, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#include "AddTransformersCommand.h" #include "AddTransformersCommand.h"
#include <new>
#include <stdio.h>
#include <string.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include "ShapeContainer.h" #include "Transformer.h"
#include "Shape.h"
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-AddTransformersCmd" #define B_TRANSLATION_CONTEXT "Icon-O-Matic-AddTransformersCmd"
using std::nothrow; AddTransformersCommand::AddTransformersCommand(Container<Transformer>* container,
const Transformer* const* transformers, int32 count, int32 index)
// constructor : AddCommand<Transformer>(container, transformers, count, true, index)
AddTransformersCommand::AddTransformersCommand(Shape* container,
Transformer** const transformers,
int32 count,
int32 index)
: Command(),
fContainer(container),
fTransformers(transformers && count > 0 ?
new (nothrow) Transformer*[count] : NULL),
fCount(count),
fIndex(index),
fTransformersAdded(false)
{ {
if (!fContainer || !fTransformers)
return;
memcpy(fTransformers, transformers, sizeof(Transformer*) * fCount);
} }
// destructor
AddTransformersCommand::~AddTransformersCommand() AddTransformersCommand::~AddTransformersCommand()
{ {
if (!fTransformersAdded && fTransformers) {
for (int32 i = 0; i < fCount; i++)
delete fTransformers[i];
}
delete[] fTransformers;
} }
// InitCheck
status_t
AddTransformersCommand::InitCheck()
{
return fContainer && fTransformers ? B_OK : B_NO_INIT;
}
// Perform
status_t
AddTransformersCommand::Perform()
{
status_t ret = B_OK;
// add transformers to container
int32 index = fIndex;
for (int32 i = 0; i < fCount; i++) {
if (fTransformers[i]
&& !fContainer->AddTransformer(fTransformers[i], index)) {
ret = B_ERROR;
// roll back
for (int32 j = i - 1; j >= 0; j--)
fContainer->RemoveTransformer(fTransformers[j]);
break;
}
index++;
}
fTransformersAdded = true;
return ret;
}
// Undo
status_t
AddTransformersCommand::Undo()
{
status_t ret = B_OK;
// add shapes to container at remembered indices
for (int32 i = 0; i < fCount; i++) {
fContainer->RemoveTransformer(fTransformers[i]);
}
fTransformersAdded = false;
return ret;
}
// GetName
void void
AddTransformersCommand::GetName(BString& name) AddTransformersCommand::GetName(BString& name)
{ {
@@ -1,50 +1,36 @@
/* /*
* Copyright 2006-2007, Haiku. * Copyright 2006-2007, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#ifndef ADD_TRANSFORMERS_COMMAND_H #ifndef ADD_TRANSFORMERS_COMMAND_H
#define ADD_TRANSFORMERS_COMMAND_H #define ADD_TRANSFORMERS_COMMAND_H
#include "Command.h" #include "AddCommand.h"
#include "IconBuild.h" #include "IconBuild.h"
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
class Shape;
class Transformer; class Transformer;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
_USING_ICON_NAMESPACE _USING_ICON_NAMESPACE
// TODO: make a templated "add items" command? class AddTransformersCommand : public AddCommand<Transformer> {
class AddTransformersCommand : public Command {
public: public:
AddTransformersCommand( AddTransformersCommand(
Shape* container, Container<Transformer>* container,
Transformer** const transformers, const Transformer* const* transformers,
int32 count, int32 count,
int32 index); int32 index);
virtual ~AddTransformersCommand(); virtual ~AddTransformersCommand();
virtual status_t InitCheck();
virtual status_t Perform();
virtual status_t Undo();
virtual void GetName(BString& name); virtual void GetName(BString& name);
private:
Shape* fContainer;
Transformer** fTransformers;
int32 fCount;
int32 fIndex;
bool fTransformersAdded;
}; };
#endif // ADD_TRANSFORMERS_COMMAND_H #endif // ADD_TRANSFORMERS_COMMAND_H
@@ -132,9 +132,9 @@ FreezeTransformationCommand::_ApplyTransformation(PathSourceShape* shape,
const Transformable& transform) const Transformable& transform)
{ {
// apply inverse of old shape transformation to every assigned path // apply inverse of old shape transformation to every assigned path
int32 pathCount = shape->Paths()->CountPaths(); int32 pathCount = shape->Paths()->CountItems();
for (int32 i = 0; i < pathCount; i++) { for (int32 i = 0; i < pathCount; i++) {
VectorPath* path = shape->Paths()->PathAtFast(i); VectorPath* path = shape->Paths()->ItemAtFast(i);
int32 shapes = 0; int32 shapes = 0;
int32 listeners = path->CountListeners(); int32 listeners = path->CountListeners();
for (int32 j = 0; j < listeners; j++) { for (int32 j = 0; j < listeners; j++) {
@@ -1,20 +1,17 @@
/* /*
* Copyright 2006, Haiku. * Copyright 2006, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#include "MovePathsCommand.h" #include "MovePathsCommand.h"
#include <new>
#include <stdio.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include "PathContainer.h"
#include "VectorPath.h" #include "VectorPath.h"
@@ -22,135 +19,18 @@
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-MovePathsCmd" #define B_TRANSLATION_CONTEXT "Icon-O-Matic-MovePathsCmd"
using std::nothrow; MovePathsCommand::MovePathsCommand(Container<VectorPath>* container,
VectorPath** paths, int32 count, int32 toIndex)
// constructor : MoveCommand<VectorPath>(container, paths, count, toIndex)
MovePathsCommand::MovePathsCommand(PathContainer* container,
VectorPath** paths,
int32 count,
int32 toIndex)
: Command(),
fContainer(container),
fPaths(paths),
fIndices(count > 0 ? new (nothrow) int32[count] : NULL),
fToIndex(toIndex),
fCount(count)
{ {
if (!fContainer || !fPaths || !fIndices)
return;
// init original shape indices and
// adjust toIndex compensating for items that
// are removed before that index
int32 itemsBeforeIndex = 0;
for (int32 i = 0; i < fCount; i++) {
fIndices[i] = fContainer->IndexOf(fPaths[i]);
if (fIndices[i] >= 0 && fIndices[i] < fToIndex)
itemsBeforeIndex++;
}
fToIndex -= itemsBeforeIndex;
} }
// destructor
MovePathsCommand::~MovePathsCommand() MovePathsCommand::~MovePathsCommand()
{ {
delete[] fPaths;
delete[] fIndices;
} }
// InitCheck
status_t
MovePathsCommand::InitCheck()
{
if (!fContainer || !fPaths || !fIndices)
return B_NO_INIT;
// analyse the move, don't return B_OK in case
// the container state does not change...
int32 index = fIndices[0];
// NOTE: fIndices == NULL if fCount < 1
if (index != fToIndex) {
// a change is guaranteed
return B_OK;
}
// the insertion index is the same as the index of the first
// moved item, a change only occures if the indices of the
// moved items is not contiguous
bool isContiguous = true;
for (int32 i = 1; i < fCount; i++) {
if (fIndices[i] != index + 1) {
isContiguous = false;
break;
}
index = fIndices[i];
}
if (isContiguous) {
// the container state will not change because of the move
return B_ERROR;
}
return B_OK;
}
// Perform
status_t
MovePathsCommand::Perform()
{
status_t ret = B_OK;
// remove paths from container
for (int32 i = 0; i < fCount; i++) {
if (fPaths[i] && !fContainer->RemovePath(fPaths[i])) {
ret = B_ERROR;
break;
}
}
if (ret < B_OK)
return ret;
// add paths to container at the insertion index
int32 index = fToIndex;
for (int32 i = 0; i < fCount; i++) {
if (fPaths[i] && !fContainer->AddPath(fPaths[i], index++)) {
ret = B_ERROR;
break;
}
}
return ret;
}
// Undo
status_t
MovePathsCommand::Undo()
{
status_t ret = B_OK;
// remove paths from container
for (int32 i = 0; i < fCount; i++) {
if (fPaths[i] && !fContainer->RemovePath(fPaths[i])) {
ret = B_ERROR;
break;
}
}
if (ret < B_OK)
return ret;
// add paths to container at remembered indices
for (int32 i = 0; i < fCount; i++) {
if (fPaths[i] && !fContainer->AddPath(fPaths[i], fIndices[i])) {
ret = B_ERROR;
break;
}
}
return ret;
}
// GetName
void void
MovePathsCommand::GetName(BString& name) MovePathsCommand::GetName(BString& name)
{ {
@@ -1,50 +1,37 @@
/* /*
* Copyright 2006-2007, Haiku. * Copyright 2006-2007, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#ifndef MOVE_PATHS_COMMAND_H #ifndef MOVE_PATHS_COMMAND_H
#define MOVE_PATHS_COMMAND_H #define MOVE_PATHS_COMMAND_H
#include "Command.h"
#include "IconBuild.h" #include "IconBuild.h"
#include "MoveCommand.h"
// TODO: make a templated "move items" command?
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
template <class Type> class Container;
class VectorPath; class VectorPath;
class PathContainer;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
_USING_ICON_NAMESPACE _USING_ICON_NAMESPACE
class MovePathsCommand : public Command { class MovePathsCommand : public MoveCommand<VectorPath> {
public: public:
MovePathsCommand( MovePathsCommand(
PathContainer* container, Container<VectorPath>* container,
VectorPath** paths, VectorPath** paths,
int32 count, int32 count,
int32 toIndex); int32 toIndex);
virtual ~MovePathsCommand(); virtual ~MovePathsCommand();
virtual status_t InitCheck(); virtual void GetName(BString& name);
virtual status_t Perform();
virtual status_t Undo();
virtual void GetName(BString& name);
private:
PathContainer* fContainer;
VectorPath** fPaths;
int32* fIndices;
int32 fToIndex;
int32 fCount;
}; };
#endif // MOVE_PATHS_COMMAND_H #endif // MOVE_PATHS_COMMAND_H
@@ -1,20 +1,17 @@
/* /*
* Copyright 2006, Haiku. * Copyright 2006, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#include "MoveShapesCommand.h" #include "MoveShapesCommand.h"
#include <new>
#include <stdio.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include "ShapeContainer.h"
#include "Shape.h" #include "Shape.h"
@@ -22,135 +19,18 @@
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-MoveShapesCommand" #define B_TRANSLATION_CONTEXT "Icon-O-Matic-MoveShapesCommand"
using std::nothrow; MoveShapesCommand::MoveShapesCommand(Container<Shape>* container,
Shape** shapes, int32 count, int32 toIndex)
// constructor : MoveCommand<Shape>(container, shapes, count, toIndex)
MoveShapesCommand::MoveShapesCommand(ShapeContainer* container,
Shape** shapes,
int32 count,
int32 toIndex)
: Command(),
fContainer(container),
fShapes(shapes),
fIndices(count > 0 ? new (nothrow) int32[count] : NULL),
fToIndex(toIndex),
fCount(count)
{ {
if (!fContainer || !fShapes || !fIndices)
return;
// init original shape indices and
// adjust toIndex compensating for items that
// are removed before that index
int32 itemsBeforeIndex = 0;
for (int32 i = 0; i < fCount; i++) {
fIndices[i] = fContainer->IndexOf(fShapes[i]);
if (fIndices[i] >= 0 && fIndices[i] < fToIndex)
itemsBeforeIndex++;
}
fToIndex -= itemsBeforeIndex;
} }
// destructor
MoveShapesCommand::~MoveShapesCommand() MoveShapesCommand::~MoveShapesCommand()
{ {
delete[] fShapes;
delete[] fIndices;
} }
// InitCheck
status_t
MoveShapesCommand::InitCheck()
{
if (!fContainer || !fShapes || !fIndices)
return B_NO_INIT;
// analyse the move, don't return B_OK in case
// the container state does not change...
int32 index = fIndices[0];
// NOTE: fIndices == NULL if fCount < 1
if (index != fToIndex) {
// a change is guaranteed
return B_OK;
}
// the insertion index is the same as the index of the first
// moved item, a change only occures if the indices of the
// moved items is not contiguous
bool isContiguous = true;
for (int32 i = 1; i < fCount; i++) {
if (fIndices[i] != index + 1) {
isContiguous = false;
break;
}
index = fIndices[i];
}
if (isContiguous) {
// the container state will not change because of the move
return B_ERROR;
}
return B_OK;
}
// Perform
status_t
MoveShapesCommand::Perform()
{
status_t ret = B_OK;
// remove shapes from container
for (int32 i = 0; i < fCount; i++) {
if (fShapes[i] && !fContainer->RemoveShape(fShapes[i])) {
ret = B_ERROR;
break;
}
}
if (ret < B_OK)
return ret;
// add shapes to container at the insertion index
int32 index = fToIndex;
for (int32 i = 0; i < fCount; i++) {
if (fShapes[i] && !fContainer->AddShape(fShapes[i], index++)) {
ret = B_ERROR;
break;
}
}
return ret;
}
// Undo
status_t
MoveShapesCommand::Undo()
{
status_t ret = B_OK;
// remove shapes from container
for (int32 i = 0; i < fCount; i++) {
if (fShapes[i] && !fContainer->RemoveShape(fShapes[i])) {
ret = B_ERROR;
break;
}
}
if (ret < B_OK)
return ret;
// add shapes to container at remembered indices
for (int32 i = 0; i < fCount; i++) {
if (fShapes[i] && !fContainer->AddShape(fShapes[i], fIndices[i])) {
ret = B_ERROR;
break;
}
}
return ret;
}
// GetName
void void
MoveShapesCommand::GetName(BString& name) MoveShapesCommand::GetName(BString& name)
{ {
@@ -1,50 +1,36 @@
/* /*
* Copyright 2006-2007, Haiku. * Copyright 2006-2007, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#ifndef MOVE_SHAPES_COMMAND_H #ifndef MOVE_SHAPES_COMMAND_H
#define MOVE_SHAPES_COMMAND_H #define MOVE_SHAPES_COMMAND_H
#include "Command.h"
#include "IconBuild.h" #include "IconBuild.h"
#include "MoveCommand.h"
// TODO: make a templated "move items" command?
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
class Shape; class Shape;
class ShapeContainer;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
_USING_ICON_NAMESPACE _USING_ICON_NAMESPACE
class MoveShapesCommand : public Command { class MoveShapesCommand : public MoveCommand<Shape> {
public: public:
MoveShapesCommand( MoveShapesCommand(
ShapeContainer* container, Container<Shape>* container,
Shape** shapes, Shape** shapes,
int32 count, int32 count,
int32 toIndex); int32 toIndex);
virtual ~MoveShapesCommand(); virtual ~MoveShapesCommand();
virtual status_t InitCheck();
virtual status_t Perform();
virtual status_t Undo();
virtual void GetName(BString& name); virtual void GetName(BString& name);
private:
ShapeContainer* fContainer;
Shape** fShapes;
int32* fIndices;
int32 fToIndex;
int32 fCount;
}; };
#endif // MOVE_SHAPES_COMMAND_H #endif // MOVE_SHAPES_COMMAND_H
@@ -1,20 +1,17 @@
/* /*
* Copyright 2006, Haiku. * Copyright 2006, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#include "MoveTransformersCommand.h" #include "MoveTransformersCommand.h"
#include <new>
#include <stdio.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include "Shape.h"
#include "Transformer.h" #include "Transformer.h"
@@ -22,139 +19,18 @@
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-MoveTransformersCmd" #define B_TRANSLATION_CONTEXT "Icon-O-Matic-MoveTransformersCmd"
using std::nothrow; MoveTransformersCommand::MoveTransformersCommand(Container<Transformer>* container,
Transformer** transformers, int32 count, int32 toIndex)
// constructor : MoveCommand<Transformer>(container, transformers, count, toIndex)
MoveTransformersCommand::MoveTransformersCommand(Shape* container,
Transformer** transformers,
int32 count,
int32 toIndex)
: Command(),
fContainer(container),
fTransformers(transformers),
fIndices(count > 0 ? new (nothrow) int32[count] : NULL),
fToIndex(toIndex),
fCount(count)
{ {
if (!fContainer || !fTransformers || !fIndices)
return;
// init original shape indices and
// adjust toIndex compensating for items that
// are removed before that index
int32 itemsBeforeIndex = 0;
for (int32 i = 0; i < fCount; i++) {
fIndices[i] = fContainer->IndexOf(fTransformers[i]);
if (fIndices[i] >= 0 && fIndices[i] < fToIndex)
itemsBeforeIndex++;
}
fToIndex -= itemsBeforeIndex;
} }
// destructor
MoveTransformersCommand::~MoveTransformersCommand() MoveTransformersCommand::~MoveTransformersCommand()
{ {
delete[] fTransformers;
delete[] fIndices;
} }
// InitCheck
status_t
MoveTransformersCommand::InitCheck()
{
if (!fContainer || !fTransformers || !fIndices)
return B_NO_INIT;
// analyse the move, don't return B_OK in case
// the container state does not change...
int32 index = fIndices[0];
// NOTE: fIndices == NULL if fCount < 1
if (index != fToIndex) {
// a change is guaranteed
return B_OK;
}
// the insertion index is the same as the index of the first
// moved item, a change only occures if the indices of the
// moved items is not contiguous
bool isContiguous = true;
for (int32 i = 1; i < fCount; i++) {
if (fIndices[i] != index + 1) {
isContiguous = false;
break;
}
index = fIndices[i];
}
if (isContiguous) {
// the container state will not change because of the move
return B_ERROR;
}
return B_OK;
}
// Perform
status_t
MoveTransformersCommand::Perform()
{
status_t ret = B_OK;
// remove shapes from container
for (int32 i = 0; i < fCount; i++) {
if (fTransformers[i]
&& !fContainer->RemoveTransformer(fTransformers[i])) {
ret = B_ERROR;
break;
}
}
if (ret < B_OK)
return ret;
// add shapes to container at the insertion index
int32 index = fToIndex;
for (int32 i = 0; i < fCount; i++) {
if (fTransformers[i]
&& !fContainer->AddTransformer(fTransformers[i], index++)) {
ret = B_ERROR;
break;
}
}
return ret;
}
// Undo
status_t
MoveTransformersCommand::Undo()
{
status_t ret = B_OK;
// remove shapes from container
for (int32 i = 0; i < fCount; i++) {
if (fTransformers[i]
&& !fContainer->RemoveTransformer(fTransformers[i])) {
ret = B_ERROR;
break;
}
}
if (ret < B_OK)
return ret;
// add shapes to container at remembered indices
for (int32 i = 0; i < fCount; i++) {
if (fTransformers[i]
&& !fContainer->AddTransformer(fTransformers[i], fIndices[i])) {
ret = B_ERROR;
break;
}
}
return ret;
}
// GetName
void void
MoveTransformersCommand::GetName(BString& name) MoveTransformersCommand::GetName(BString& name)
{ {
@@ -1,51 +1,36 @@
/* /*
* Copyright 2006, Haiku. * Copyright 2006, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#ifndef MOVE_TRANSFORMERS_COMMAND_H #ifndef MOVE_TRANSFORMERS_COMMAND_H
#define MOVE_TRANSFORMERS_COMMAND_H #define MOVE_TRANSFORMERS_COMMAND_H
#include "Command.h"
#include "IconBuild.h" #include "IconBuild.h"
#include "MoveCommand.h"
// TODO: make a templated "move items" command?
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
class Shape;
class Transformer; class Transformer;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
_USING_ICON_NAMESPACE _USING_ICON_NAMESPACE
class MoveTransformersCommand : public Command { class MoveTransformersCommand : public MoveCommand<Transformer> {
public: public:
MoveTransformersCommand( MoveTransformersCommand(
Shape* shape, Container<Transformer>* shape,
Transformer** transformers, Transformer** transformers,
int32 count, int32 count,
int32 toIndex); int32 toIndex);
virtual ~MoveTransformersCommand(); virtual ~MoveTransformersCommand();
virtual status_t InitCheck();
virtual status_t Perform();
virtual status_t Undo();
virtual void GetName(BString& name); virtual void GetName(BString& name);
private:
Shape* fContainer;
Transformer** fTransformers;
int32* fIndices;
int32 fToIndex;
int32 fCount;
}; };
#endif // MOVE_TRANSFORMERS_COMMAND_H #endif // MOVE_TRANSFORMERS_COMMAND_H
@@ -1,20 +1,21 @@
/* /*
* Copyright 2006, Haiku. * Copyright 2006, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#include "RemovePathsCommand.h" #include "RemovePathsCommand.h"
#include <new> #include <new>
#include <stdio.h>
#include <Catalog.h> #include <Catalog.h>
#include <List.h>
#include <Locale.h> #include <Locale.h>
#include "PathContainer.h" #include "Container.h"
#include "PathSourceShape.h" #include "PathSourceShape.h"
#include "Shape.h" #include "Shape.h"
#include "VectorPath.h" #include "VectorPath.h"
@@ -26,108 +27,94 @@
using std::nothrow; using std::nothrow;
// constructor
RemovePathsCommand::RemovePathsCommand(PathContainer* container, RemovePathsCommand::RemovePathsCommand(
VectorPath** const paths, Container<VectorPath>* container, const int32* indices, int32 count)
int32 count) : RemoveCommand<VectorPath>(container, indices, count),
: Command(), fShapes(indices && count > 0 ? new (nothrow) BList[count] : NULL)
fContainer(container),
fInfos(paths && count > 0 ? new (nothrow) PathInfo[count] : NULL),
fCount(count),
fPathsRemoved(false)
{ {
if (!fContainer || !fInfos) if (!fShapes)
return; return;
// get the shapes associated with each path
for (int32 i = 0; i < fCount; i++) { for (int32 i = 0; i < fCount; i++) {
fInfos[i].path = paths[i]; if (fItems[i]) {
fInfos[i].index = fContainer->IndexOf(paths[i]); int32 listenerCount = fItems[i]->CountListeners();
if (paths[i]) {
int32 listenerCount = paths[i]->CountListeners();
for (int32 j = 0; j < listenerCount; j++) { for (int32 j = 0; j < listenerCount; j++) {
PathSourceShape* shape PathSourceShape* shape
= dynamic_cast<PathSourceShape*>(paths[i]->ListenerAtFast(j)); = dynamic_cast<PathSourceShape*>(fItems[i]->ListenerAtFast(j));
if (shape) if (shape)
fInfos[i].shapes.AddItem((void*)shape); fShapes[i].AddItem((void*)shape);
} }
} }
} }
} }
// destructor
RemovePathsCommand::~RemovePathsCommand() RemovePathsCommand::~RemovePathsCommand()
{ {
if (fPathsRemoved && fInfos) { delete[] fShapes;
for (int32 i = 0; i < fCount; i++) {
if (fInfos[i].path)
fInfos[i].path->ReleaseReference();
}
}
delete[] fInfos;
} }
// InitCheck
status_t status_t
RemovePathsCommand::InitCheck() RemovePathsCommand::InitCheck()
{ {
return fContainer && fInfos ? B_OK : B_NO_INIT; return fShapes ? B_OK : B_NO_INIT;
} }
// Perform
status_t status_t
RemovePathsCommand::Perform() RemovePathsCommand::Perform()
{ {
// remove paths from container and shapes that reference them // remove paths from the container
status_t ret = RemoveCommand<VectorPath>::Perform();
if (ret != B_OK)
return ret;
fItemsRemoved = false; // We're not done yet!
// remove paths from shapes that reference them
for (int32 i = 0; i < fCount; i++) { for (int32 i = 0; i < fCount; i++) {
if (!fInfos[i].path) if (!fItems[i])
continue; continue;
fContainer->RemovePath(fInfos[i].path); int32 shapeCount = fShapes[i].CountItems();
int32 shapeCount = fInfos[i].shapes.CountItems();
for (int32 j = 0; j < shapeCount; j++) { for (int32 j = 0; j < shapeCount; j++) {
PathSourceShape* shape = (PathSourceShape*)fInfos[i].shapes.ItemAtFast(j); PathSourceShape* shape = (PathSourceShape*)fShapes[i].ItemAtFast(j);
shape->Paths()->RemovePath(fInfos[i].path); shape->Paths()->RemoveItem(fItems[i]);
} }
} }
fPathsRemoved = true; fItemsRemoved = true;
return B_OK;
}
// Undo
status_t
RemovePathsCommand::Undo()
{
status_t ret = B_OK;
// add paths to container and shapes which previously referenced them
for (int32 i = 0; i < fCount; i++) {
if (!fInfos[i].path)
continue;
if (!fContainer->AddPath(fInfos[i].path, fInfos[i].index)) {
// roll back
ret = B_ERROR;
for (int32 j = i - 1; j >= 0; j--) {
fContainer->RemovePath(fInfos[j].path);
int32 shapeCount = fInfos[j].shapes.CountItems();
for (int32 k = 0; k < shapeCount; k++) {
PathSourceShape* shape = (PathSourceShape*)fInfos[j].shapes.ItemAtFast(k);
shape->Paths()->RemovePath(fInfos[j].path);
}
}
break;
}
int32 shapeCount = fInfos[i].shapes.CountItems();
for (int32 j = 0; j < shapeCount; j++) {
PathSourceShape* shape = (PathSourceShape*)fInfos[i].shapes.ItemAtFast(j);
shape->Paths()->AddPath(fInfos[i].path);
}
}
fPathsRemoved = false;
return ret; return ret;
} }
// GetName
status_t
RemovePathsCommand::Undo()
{
// add paths to the container
status_t ret = RemoveCommand<VectorPath>::Undo();
if (ret != B_OK)
return ret;
fItemsRemoved = true; // We're not done yet!
// add paths to shapes which previously referenced them
for (int32 i = 0; i < fCount; i++) {
if (!fItems[i])
continue;
int32 shapeCount = fShapes[i].CountItems();
for (int32 j = 0; j < shapeCount; j++) {
PathSourceShape* shape = (PathSourceShape*)fShapes[i].ItemAtFast(j);
shape->Paths()->AddItem(fItems[i]);
}
}
fItemsRemoved = false;
return ret;
}
void void
RemovePathsCommand::GetName(BString& name) RemovePathsCommand::GetName(BString& name)
{ {
@@ -1,9 +1,10 @@
/* /*
* Copyright 2006-2007, Haiku. * Copyright 2006-2007, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#ifndef REMOVE_PATHS_COMMAND_H #ifndef REMOVE_PATHS_COMMAND_H
#define REMOVE_PATHS_COMMAND_H #define REMOVE_PATHS_COMMAND_H
@@ -11,43 +12,36 @@
#include "Command.h" #include "Command.h"
#include "IconBuild.h" #include "IconBuild.h"
#include "RemoveCommand.h"
#include <List.h>
class BList;
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
template <class Type> class Container;
class VectorPath; class VectorPath;
class PathContainer;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
_USING_ICON_NAMESPACE _USING_ICON_NAMESPACE
class RemovePathsCommand : public Command { class RemovePathsCommand : public RemoveCommand<VectorPath> {
public: public:
RemovePathsCommand( RemovePathsCommand(
PathContainer* container, Container<VectorPath>* container,
VectorPath** const paths, const int32* indices,
int32 count); int32 count);
virtual ~RemovePathsCommand(); virtual ~RemovePathsCommand();
virtual status_t InitCheck(); virtual status_t InitCheck();
virtual status_t Perform(); virtual status_t Perform();
virtual status_t Undo(); virtual status_t Undo();
virtual void GetName(BString& name); virtual void GetName(BString& name);
private: private:
PathContainer* fContainer; BList* fShapes;
struct PathInfo {
VectorPath* path;
int32 index;
BList shapes;
};
PathInfo* fInfos;
int32 fCount;
bool fPathsRemoved;
}; };
#endif // REMOVE_PATHS_COMMAND_H #endif // REMOVE_PATHS_COMMAND_H
@@ -1,21 +1,17 @@
/* /*
* Copyright 2006, Haiku. * Copyright 2006, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#include "RemoveShapesCommand.h" #include "RemoveShapesCommand.h"
#include <new>
#include <stdio.h>
#include <string.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include "ShapeContainer.h"
#include "Shape.h" #include "Shape.h"
@@ -23,82 +19,18 @@
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-RemoveShapesCmd" #define B_TRANSLATION_CONTEXT "Icon-O-Matic-RemoveShapesCmd"
using std::nothrow; RemoveShapesCommand::RemoveShapesCommand(
Container<Shape>* container, const int32* indices, int32 count)
// constructor : RemoveCommand<Shape>(container, indices, count)
RemoveShapesCommand::RemoveShapesCommand(ShapeContainer* container,
int32* const indices,
int32 count)
: Command(),
fContainer(container),
fShapes(count > 0 ? new (nothrow) Shape*[count] : NULL),
fIndices(count > 0 ? new (nothrow) int32[count] : NULL),
fCount(count),
fShapesRemoved(false)
{ {
if (!fContainer || !fShapes || !fIndices)
return;
memcpy(fIndices, indices, sizeof(int32) * fCount);
for (int32 i = 0; i < fCount; i++)
fShapes[i] = fContainer->ShapeAt(fIndices[i]);
} }
// destructor
RemoveShapesCommand::~RemoveShapesCommand() RemoveShapesCommand::~RemoveShapesCommand()
{ {
if (fShapesRemoved && fShapes) {
for (int32 i = 0; i < fCount; i++)
fShapes[i]->ReleaseReference();
}
delete[] fShapes;
delete[] fIndices;
} }
// InitCheck
status_t
RemoveShapesCommand::InitCheck()
{
return fContainer && fShapes && fIndices ? B_OK : B_NO_INIT;
}
// Perform
status_t
RemoveShapesCommand::Perform()
{
status_t ret = B_OK;
// remove shapes from container
for (int32 i = 0; i < fCount; i++) {
if (fShapes[i] && !fContainer->RemoveShape(fShapes[i])) {
ret = B_ERROR;
break;
}
}
fShapesRemoved = true;
return ret;
}
// Undo
status_t
RemoveShapesCommand::Undo()
{
status_t ret = B_OK;
// add shapes to container at remembered indices
for (int32 i = 0; i < fCount; i++) {
if (fShapes[i] && !fContainer->AddShape(fShapes[i], fIndices[i])) {
ret = B_ERROR;
break;
}
}
fShapesRemoved = false;
return ret;
}
// GetName
void void
RemoveShapesCommand::GetName(BString& name) RemoveShapesCommand::GetName(BString& name)
{ {
@@ -1,47 +1,36 @@
/* /*
* Copyright 2006-2007, Haiku. * Copyright 2006-2007, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#ifndef REMOVE_SHAPES_COMMAND_H #ifndef REMOVE_SHAPES_COMMAND_H
#define REMOVE_SHAPES_COMMAND_H #define REMOVE_SHAPES_COMMAND_H
#include "Command.h"
#include "IconBuild.h" #include "IconBuild.h"
#include "RemoveCommand.h"
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
template <class Type> class Container;
class Shape; class Shape;
class ShapeContainer;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
_USING_ICON_NAMESPACE _USING_ICON_NAMESPACE
class RemoveShapesCommand : public Command { class RemoveShapesCommand : public RemoveCommand<Shape> {
public: public:
RemoveShapesCommand( RemoveShapesCommand(
ShapeContainer* container, Container<Shape>* container,
int32* const indices, const int32* indices,
int32 count); int32 count);
virtual ~RemoveShapesCommand(); virtual ~RemoveShapesCommand();
virtual status_t InitCheck();
virtual status_t Perform();
virtual status_t Undo();
virtual void GetName(BString& name); virtual void GetName(BString& name);
private:
ShapeContainer* fContainer;
Shape** fShapes;
int32* fIndices;
int32 fCount;
bool fShapesRemoved;
}; };
#endif // REMOVE_SHAPES_COMMAND_H #endif // REMOVE_SHAPES_COMMAND_H
@@ -1,106 +1,37 @@
/* /*
* Copyright 2006, Haiku. * Copyright 2006, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#include "RemoveTransformersCommand.h" #include "RemoveTransformersCommand.h"
#include <new>
#include <stdio.h>
#include <string.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include "ShapeContainer.h" #include "Transformer.h"
#include "Shape.h"
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-RemoveTransformersCmd" #define B_TRANSLATION_CONTEXT "Icon-O-Matic-RemoveTransformersCmd"
using std::nothrow; RemoveTransformersCommand::RemoveTransformersCommand(Container<Transformer>* container,
// constructor
RemoveTransformersCommand::RemoveTransformersCommand(Shape* container,
const int32* indices, const int32* indices,
int32 count) int32 count)
: Command(), : RemoveCommand<Transformer>(container, indices, count)
fContainer(container),
fTransformers(count > 0 ? new (nothrow) Transformer*[count] : NULL),
fIndices(count > 0 ? new (nothrow) int32[count] : NULL),
fCount(count),
fTransformersRemoved(false)
{ {
if (!fContainer || !fTransformers || !fIndices)
return;
memcpy(fIndices, indices, sizeof(int32) * fCount);
for (int32 i = 0; i < fCount; i++)
fTransformers[i] = fContainer->TransformerAt(fIndices[i]);
} }
// destructor
RemoveTransformersCommand::~RemoveTransformersCommand() RemoveTransformersCommand::~RemoveTransformersCommand()
{ {
if (fTransformersRemoved && fTransformers) {
for (int32 i = 0; i < fCount; i++)
delete fTransformers[i];
}
delete[] fTransformers;
delete[] fIndices;
} }
// InitCheck
status_t
RemoveTransformersCommand::InitCheck()
{
return fContainer && fTransformers && fIndices ? B_OK : B_NO_INIT;
}
// Perform
status_t
RemoveTransformersCommand::Perform()
{
status_t ret = B_OK;
// remove shapes from container
for (int32 i = 0; i < fCount; i++) {
if (fTransformers[i]
&& !fContainer->RemoveTransformer(fTransformers[i])) {
ret = B_ERROR;
break;
}
}
fTransformersRemoved = true;
return ret;
}
// Undo
status_t
RemoveTransformersCommand::Undo()
{
status_t ret = B_OK;
// add shapes to container at remembered indices
for (int32 i = 0; i < fCount; i++) {
if (fTransformers[i]
&& !fContainer->AddTransformer(fTransformers[i], fIndices[i])) {
ret = B_ERROR;
break;
}
}
fTransformersRemoved = false;
return ret;
}
// GetName
void void
RemoveTransformersCommand::GetName(BString& name) RemoveTransformersCommand::GetName(BString& name)
{ {
@@ -1,49 +1,35 @@
/* /*
* Copyright 2006-2007, Haiku. * Copyright 2006-2007, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#ifndef REMOVE_TRANSFORMERS_COMMAND_H #ifndef REMOVE_TRANSFORMERS_COMMAND_H
#define REMOVE_TRANSFORMERS_COMMAND_H #define REMOVE_TRANSFORMERS_COMMAND_H
#include "Command.h"
#include "IconBuild.h" #include "IconBuild.h"
#include "RemoveCommand.h"
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
class Shape;
class Transformer; class Transformer;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
_USING_ICON_NAMESPACE _USING_ICON_NAMESPACE
// TODO: make a templated "remove items" command? class RemoveTransformersCommand : public RemoveCommand<Transformer> {
class RemoveTransformersCommand : public Command {
public: public:
RemoveTransformersCommand( RemoveTransformersCommand(
Shape* container, Container<Transformer>* container,
const int32* indices, const int32* indices,
int32 count); int32 count);
virtual ~RemoveTransformersCommand(); virtual ~RemoveTransformersCommand();
virtual status_t InitCheck();
virtual status_t Perform();
virtual status_t Undo();
virtual void GetName(BString& name); virtual void GetName(BString& name);
private:
Shape* fContainer;
Transformer** fTransformers;
int32* fIndices;
int32 fCount;
bool fTransformersRemoved;
}; };
#endif // REMOVE_TRANSFORMERS_COMMAND_H #endif // REMOVE_TRANSFORMERS_COMMAND_H
@@ -11,7 +11,6 @@
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include "PathContainer.h"
#include "PathSourceShape.h" #include "PathSourceShape.h"
#include "VectorPath.h" #include "VectorPath.h"
@@ -49,7 +48,7 @@ status_t
UnassignPathCommand::Perform() UnassignPathCommand::Perform()
{ {
// remove path from shape // remove path from shape
fShape->Paths()->RemovePath(fPath); fShape->Paths()->RemoveItem(fPath);
fPathRemoved = true; fPathRemoved = true;
return B_OK; return B_OK;
@@ -60,7 +59,7 @@ status_t
UnassignPathCommand::Undo() UnassignPathCommand::Undo()
{ {
// add path to shape // add path to shape
fShape->Paths()->AddPath(fPath); fShape->Paths()->AddItem(fPath);
fPathRemoved = false; fPathRemoved = false;
return B_OK; return B_OK;
@@ -1,102 +1,35 @@
/* /*
* Copyright 2006, Haiku. * Copyright 2006, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#include "AddStylesCommand.h" #include "AddStylesCommand.h"
#include <new>
#include <stdio.h>
#include <string.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include "StyleContainer.h"
#include "Style.h" #include "Style.h"
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-AddStylesCmd" #define B_TRANSLATION_CONTEXT "Icon-O-Matic-AddStylesCmd"
using std::nothrow; AddStylesCommand::AddStylesCommand(Container<Style>* container,
const Style* const* styles, int32 count, int32 index)
// constructor : AddCommand<Style>(container, styles, count, true, index)
AddStylesCommand::AddStylesCommand(StyleContainer* container,
Style** const styles,
int32 count,
int32 index)
: Command(),
fContainer(container),
fStyles(styles && count > 0 ? new (nothrow) Style*[count] : NULL),
fCount(count),
fIndex(index),
fStylesAdded(false)
{ {
if (!fContainer || !fStyles)
return;
memcpy(fStyles, styles, sizeof(Style*) * fCount);
} }
// destructor
AddStylesCommand::~AddStylesCommand() AddStylesCommand::~AddStylesCommand()
{ {
if (!fStylesAdded && fStyles) {
for (int32 i = 0; i < fCount; i++)
fStyles[i]->ReleaseReference();
}
delete[] fStyles;
} }
// InitCheck
status_t
AddStylesCommand::InitCheck()
{
return fContainer && fStyles ? B_OK : B_NO_INIT;
}
// Perform
status_t
AddStylesCommand::Perform()
{
status_t ret = B_OK;
// add shapes to container
int32 index = fIndex;
for (int32 i = 0; i < fCount; i++) {
if (fStyles[i] && !fContainer->AddStyle(fStyles[i], index)) {
ret = B_ERROR;
// roll back
for (int32 j = i - 1; j >= 0; j--)
fContainer->RemoveStyle(fStyles[j]);
break;
}
index++;
}
fStylesAdded = true;
return ret;
}
// Undo
status_t
AddStylesCommand::Undo()
{
// remove shapes from container
for (int32 i = 0; i < fCount; i++) {
fContainer->RemoveStyle(fStyles[i]);
}
fStylesAdded = false;
return B_OK;
}
// GetName
void void
AddStylesCommand::GetName(BString& name) AddStylesCommand::GetName(BString& name)
{ {
+6 -18
View File
@@ -1,48 +1,36 @@
/* /*
* Copyright 2006-2007, Haiku. * Copyright 2006-2007, 2023, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#ifndef ADD_STYLES_COMMAND_H #ifndef ADD_STYLES_COMMAND_H
#define ADD_STYLES_COMMAND_H #define ADD_STYLES_COMMAND_H
#include "Command.h" #include "AddCommand.h"
#include "IconBuild.h" #include "IconBuild.h"
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
class Style; class Style;
class StyleContainer;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
_USING_ICON_NAMESPACE _USING_ICON_NAMESPACE
class AddStylesCommand : public Command { class AddStylesCommand : public AddCommand<Style> {
public: public:
AddStylesCommand( AddStylesCommand(
StyleContainer* container, Container<Style>* container,
Style** const styles, const Style* const* styles,
int32 count, int32 count,
int32 index); int32 index);
virtual ~AddStylesCommand(); virtual ~AddStylesCommand();
virtual status_t InitCheck();
virtual status_t Perform();
virtual status_t Undo();
virtual void GetName(BString& name); virtual void GetName(BString& name);
private:
StyleContainer* fContainer;
Style** fStyles;
int32 fCount;
int32 fIndex;
bool fStylesAdded;
}; };
#endif // ADD_STYLES_COMMAND_H #endif // ADD_STYLES_COMMAND_H
@@ -1,20 +1,17 @@
/* /*
* Copyright 2006, Haiku. All rights reserved. * Copyright 2006, 2023, Haiku. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#include "MoveStylesCommand.h" #include "MoveStylesCommand.h"
#include <new>
#include <stdio.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include "StyleContainer.h"
#include "Style.h" #include "Style.h"
@@ -22,135 +19,18 @@
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-MoveStylesCmd" #define B_TRANSLATION_CONTEXT "Icon-O-Matic-MoveStylesCmd"
using std::nothrow; MoveStylesCommand::MoveStylesCommand(Container<Style>* container,
Style** styles, int32 count, int32 toIndex)
// constructor : MoveCommand<Style>(container, styles, count, toIndex)
MoveStylesCommand::MoveStylesCommand(StyleContainer* container,
Style** styles,
int32 count,
int32 toIndex)
: Command(),
fContainer(container),
fStyles(styles),
fIndices(count > 0 ? new (nothrow) int32[count] : NULL),
fToIndex(toIndex),
fCount(count)
{ {
if (!fContainer || !fStyles || !fIndices)
return;
// init original style indices and
// adjust toIndex compensating for items that
// are removed before that index
int32 itemsBeforeIndex = 0;
for (int32 i = 0; i < fCount; i++) {
fIndices[i] = fContainer->IndexOf(fStyles[i]);
if (fIndices[i] >= 0 && fIndices[i] < fToIndex)
itemsBeforeIndex++;
}
fToIndex -= itemsBeforeIndex;
} }
// destructor
MoveStylesCommand::~MoveStylesCommand() MoveStylesCommand::~MoveStylesCommand()
{ {
delete[] fStyles;
delete[] fIndices;
} }
// InitCheck
status_t
MoveStylesCommand::InitCheck()
{
if (!fContainer || !fStyles || !fIndices)
return B_NO_INIT;
// analyse the move, don't return B_OK in case
// the container state does not change...
int32 index = fIndices[0];
// NOTE: fIndices == NULL if fCount < 1
if (index != fToIndex) {
// a change is guaranteed
return B_OK;
}
// the insertion index is the same as the index of the first
// moved item, a change only occures if the indices of the
// moved items is not contiguous
bool isContiguous = true;
for (int32 i = 1; i < fCount; i++) {
if (fIndices[i] != index + 1) {
isContiguous = false;
break;
}
index = fIndices[i];
}
if (isContiguous) {
// the container state will not change because of the move
return B_ERROR;
}
return B_OK;
}
// Perform
status_t
MoveStylesCommand::Perform()
{
status_t ret = B_OK;
// remove styles from container
for (int32 i = 0; i < fCount; i++) {
if (fStyles[i] && !fContainer->RemoveStyle(fStyles[i])) {
ret = B_ERROR;
break;
}
}
if (ret < B_OK)
return ret;
// add styles to container at the insertion index
int32 index = fToIndex;
for (int32 i = 0; i < fCount; i++) {
if (fStyles[i] && !fContainer->AddStyle(fStyles[i], index++)) {
ret = B_ERROR;
break;
}
}
return ret;
}
// Undo
status_t
MoveStylesCommand::Undo()
{
status_t ret = B_OK;
// remove styles from container
for (int32 i = 0; i < fCount; i++) {
if (fStyles[i] && !fContainer->RemoveStyle(fStyles[i])) {
ret = B_ERROR;
break;
}
}
if (ret < B_OK)
return ret;
// add styles to container at remembered indices
for (int32 i = 0; i < fCount; i++) {
if (fStyles[i] && !fContainer->AddStyle(fStyles[i], fIndices[i])) {
ret = B_ERROR;
break;
}
}
return ret;
}
// GetName
void void
MoveStylesCommand::GetName(BString& name) MoveStylesCommand::GetName(BString& name)
{ {
@@ -1,50 +1,36 @@
/* /*
* Copyright 2006-2007, Haiku. All rights reserved. * Copyright 2006-2007, 2023, Haiku. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#ifndef MOVE_STYLES_COMMAND_H #ifndef MOVE_STYLES_COMMAND_H
#define MOVE_STYLES_COMMAND_H #define MOVE_STYLES_COMMAND_H
#include "Command.h"
#include "IconBuild.h" #include "IconBuild.h"
#include "MoveCommand.h"
// TODO: make a templated "move items" command?
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
class Style; class Style;
class StyleContainer;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
_USING_ICON_NAMESPACE _USING_ICON_NAMESPACE
class MoveStylesCommand : public Command { class MoveStylesCommand : public MoveCommand<Style> {
public: public:
MoveStylesCommand( MoveStylesCommand(
StyleContainer* container, Container<Style>* container,
Style** styles, Style** styles,
int32 count, int32 count,
int32 toIndex); int32 toIndex);
virtual ~MoveStylesCommand(); virtual ~MoveStylesCommand();
virtual status_t InitCheck();
virtual status_t Perform();
virtual status_t Undo();
virtual void GetName(BString& name); virtual void GetName(BString& name);
private:
StyleContainer* fContainer;
Style** fStyles;
int32* fIndices;
int32 fToIndex;
int32 fCount;
}; };
#endif // MOVE_STYLES_COMMAND_H #endif // MOVE_STYLES_COMMAND_H
@@ -1,21 +1,20 @@
/* /*
* Copyright 2006, Haiku. All rights reserved. * Copyright 2006, 2023, Haiku. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#include "RemoveStylesCommand.h" #include "RemoveStylesCommand.h"
#include <new> #include <new>
#include <stdio.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include "PathSourceShape.h" #include "PathSourceShape.h"
#include "StyleContainer.h"
#include "Style.h" #include "Style.h"
@@ -25,118 +24,95 @@
using std::nothrow; using std::nothrow;
// constructor
RemoveStylesCommand::RemoveStylesCommand(StyleContainer* container, RemoveStylesCommand::RemoveStylesCommand(Container<Style>* container,
Style** const styles, int32* const indices, int32 count)
int32 count) : RemoveCommand<Style>(container, indices, count),
: Command(), fShapes(indices && count > 0 ? new (nothrow) BList[count] : NULL)
fContainer(container),
fInfos(styles && count > 0 ? new (nothrow) StyleInfo[count] : NULL),
fCount(count),
fStylesRemoved(false)
{ {
if (!fContainer || !fInfos) if (!fShapes)
return; return;
// get the shapes associated with each style
for (int32 i = 0; i < fCount; i++) { for (int32 i = 0; i < fCount; i++) {
fInfos[i].style = styles[i]; if (fItems[i]) {
fInfos[i].index = fContainer->IndexOf(styles[i]); int32 listenerCount = fItems[i]->CountObservers();
if (styles[i]) {
int32 listenerCount = styles[i]->CountObservers();
for (int32 j = 0; j < listenerCount; j++) { for (int32 j = 0; j < listenerCount; j++) {
PathSourceShape* shape PathSourceShape* shape
= dynamic_cast<PathSourceShape*>(styles[i]->ObserverAtFast(j)); = dynamic_cast<PathSourceShape*>(fItems[i]->ObserverAtFast(j));
if (shape != NULL) if (shape != NULL)
fInfos[i].shapes.AddItem((void*)shape); fShapes[i].AddItem((void*)shape);
} }
} }
} }
} }
// destructor
RemoveStylesCommand::~RemoveStylesCommand() RemoveStylesCommand::~RemoveStylesCommand()
{ {
if (fStylesRemoved && fInfos) { delete[] fShapes;
for (int32 i = 0; i < fCount; i++) {
if (fInfos[i].style)
fInfos[i].style->ReleaseReference();
}
}
delete[] fInfos;
} }
// InitCheck
status_t status_t
RemoveStylesCommand::InitCheck() RemoveStylesCommand::InitCheck()
{ {
return fContainer && fInfos ? B_OK : B_NO_INIT; return fShapes ? B_OK : B_NO_INIT;
} }
// Perform
status_t status_t
RemoveStylesCommand::Perform() RemoveStylesCommand::Perform()
{ {
// remove styles from container // remove styles from the container
for (int32 i = 0; i < fCount; i++) { status_t ret = RemoveCommand<Style>::Perform();
if (!fInfos[i].style) if (ret != B_OK)
continue; return ret;
fContainer->RemoveStyle(fInfos[i].style); fItemsRemoved = false; // We're not done yet!
}
// remove styles from shapes that reference them // remove styles from shapes that reference them
for (int32 i = 0; i < fCount; i++) { for (int32 i = 0; i < fCount; i++) {
if (!fInfos[i].style) if (!fItems[i])
continue; continue;
int32 shapeCount = fInfos[i].shapes.CountItems(); int32 shapeCount = fShapes[i].CountItems();
for (int32 j = 0; j < shapeCount; j++) { for (int32 j = 0; j < shapeCount; j++) {
PathSourceShape* shape = (PathSourceShape*)fInfos[i].shapes.ItemAtFast(j); PathSourceShape* shape = (PathSourceShape*)fShapes[i].ItemAtFast(j);
shape->SetStyle(fContainer->StyleAt(0)); shape->SetStyle(fContainer->ItemAt(0));
} }
} }
fStylesRemoved = true; fItemsRemoved = true;
return B_OK; return B_OK;
} }
// Undo
status_t status_t
RemoveStylesCommand::Undo() RemoveStylesCommand::Undo()
{ {
status_t ret = B_OK; // add styles to the container
status_t ret = RemoveCommand<Style>::Undo();
if (ret != B_OK)
return ret;
fItemsRemoved = true; // We're not done yet!
// add styles to container and shapes which previously referenced them // add styles to the shapes which previously referenced them
for (int32 i = 0; i < fCount; i++) { for (int32 i = 0; i < fCount; i++) {
if (!fInfos[i].style) if (!fItems[i])
continue; continue;
if (!fContainer->AddStyle(fInfos[i].style, fInfos[i].index)) { int32 shapeCount = fShapes[i].CountItems();
// roll back
ret = B_ERROR;
for (int32 j = i - 1; j >= 0; j--) {
fContainer->RemoveStyle(fInfos[j].style);
}
for (int32 j = i - 1; j >= 0; j--) {
int32 shapeCount = fInfos[j].shapes.CountItems();
for (int32 k = 0; k < shapeCount; k++) {
PathSourceShape* shape = (PathSourceShape*)fInfos[j].shapes.ItemAtFast(k);
shape->SetStyle(fContainer->StyleAt(0));
}
}
break;
}
int32 shapeCount = fInfos[i].shapes.CountItems();
for (int32 j = 0; j < shapeCount; j++) { for (int32 j = 0; j < shapeCount; j++) {
PathSourceShape* shape = (PathSourceShape*)fInfos[i].shapes.ItemAtFast(j); PathSourceShape* shape = (PathSourceShape*)fShapes[i].ItemAtFast(j);
shape->SetStyle(fInfos[i].style); shape->SetStyle(fItems[i]);
} }
} }
fStylesRemoved = false; fItemsRemoved = false;
return ret; return ret;
} }
// GetName
void void
RemoveStylesCommand::GetName(BString& name) RemoveStylesCommand::GetName(BString& name)
{ {
@@ -1,33 +1,33 @@
/* /*
* Copyright 2006-2007, Haiku. All rights reserved. * Copyright 2006-2007, 2023, Haiku. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#ifndef REMOVE_STYLES_COMMAND_H #ifndef REMOVE_STYLES_COMMAND_H
#define REMOVE_STYLES_COMMAND_H #define REMOVE_STYLES_COMMAND_H
#include "Command.h"
#include "IconBuild.h" #include "IconBuild.h"
#include "RemoveCommand.h"
#include <List.h>
class BList;
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
class Style; class Style;
class StyleContainer;
_END_ICON_NAMESPACE _END_ICON_NAMESPACE
_USING_ICON_NAMESPACE _USING_ICON_NAMESPACE
class RemoveStylesCommand : public Command { class RemoveStylesCommand : public RemoveCommand<Style> {
public: public:
RemoveStylesCommand( RemoveStylesCommand(
StyleContainer* container, Container<Style>* container,
Style** const styles, int32* const indices,
int32 count); int32 count);
virtual ~RemoveStylesCommand(); virtual ~RemoveStylesCommand();
@@ -39,15 +39,7 @@ class RemoveStylesCommand : public Command {
virtual void GetName(BString& name); virtual void GetName(BString& name);
private: private:
StyleContainer* fContainer; BList* fShapes;
struct StyleInfo {
Style* style;
int32 index;
BList shapes;
};
StyleInfo* fInfos;
int32 fCount;
bool fStylesRemoved;
}; };
#endif // REMOVE_STYLES_COMMAND_H #endif // REMOVE_STYLES_COMMAND_H
+1 -3
View File
@@ -4,6 +4,7 @@ SubDir HAIKU_TOP src build libbe icon ;
local sourceDirs = local sourceDirs =
$(DOT) $(DOT)
flat_icon flat_icon
generic
message message
shape shape
style style
@@ -37,17 +38,14 @@ BuildPlatformMergeObjectPIC <libbe_build>icon_kit.o :
MessageImporter.cpp MessageImporter.cpp
# shape # shape
PathContainer.cpp
PathSourceShape.cpp PathSourceShape.cpp
ReferenceImage.cpp ReferenceImage.cpp
Shape.cpp Shape.cpp
ShapeContainer.cpp
VectorPath.cpp VectorPath.cpp
# style # style
GradientTransformable.cpp GradientTransformable.cpp
Style.cpp Style.cpp
StyleContainer.cpp
# transformable # transformable
Transformable.cpp Transformable.cpp
+1 -3
View File
@@ -4,6 +4,7 @@ SubDir HAIKU_TOP src build libicon ;
local sourceDirs = local sourceDirs =
$(DOT) $(DOT)
flat_icon flat_icon
generic
message message
shape shape
style style
@@ -35,17 +36,14 @@ BuildPlatformStaticLibrary libicon_build.a :
MessageImporter.cpp MessageImporter.cpp
# shape # shape
PathContainer.cpp
PathSourceShape.cpp PathSourceShape.cpp
ReferenceImage.cpp ReferenceImage.cpp
Shape.cpp Shape.cpp
ShapeContainer.cpp
VectorPath.cpp VectorPath.cpp
# style # style
GradientTransformable.cpp GradientTransformable.cpp
Style.cpp Style.cpp
StyleContainer.cpp
# transformable # transformable
Transformable.cpp Transformable.cpp
+44 -57
View File
@@ -12,12 +12,11 @@
#include <new> #include <new>
#include <stdio.h> #include <stdio.h>
#include "PathContainer.h"
#include "PathSourceShape.h" #include "PathSourceShape.h"
#include "ReferenceImage.h" #include "ReferenceImage.h"
#include "Shape.h" #include "Shape.h"
#include "Style.h" #include "Style.h"
#include "StyleContainer.h" #include "VectorPath.h"
using std::nothrow; using std::nothrow;
@@ -28,62 +27,58 @@ IconListener::~IconListener() {}
// #pragma mark - // #pragma mark -
// constructor
Icon::Icon() Icon::Icon()
: fStyles(new (nothrow) StyleContainer()), : fStyles(true),
fPaths(new (nothrow) PathContainer(true)), fPaths(true),
fShapes(new (nothrow) ShapeContainer()) fShapes(true)
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
, fListeners(2) , fListeners(2)
#endif #endif
{ {
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
if (fShapes) fShapes.AddListener(this);
fShapes->AddListener(this);
#endif #endif
} }
// constructor
Icon::Icon(const Icon& other) Icon::Icon(const Icon& other)
: fStyles(new (nothrow) StyleContainer()), : fStyles(true),
fPaths(new (nothrow) PathContainer(true)), fPaths(true),
fShapes(new (nothrow) ShapeContainer()) fShapes(true)
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
, fListeners(2) , fListeners(2)
#endif #endif
{ {
if (!fStyles || !fPaths || !fShapes)
return;
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
fShapes->AddListener(this); fShapes.AddListener(this);
#endif #endif
int32 styleCount = other.fStyles->CountStyles(); int32 styleCount = other.fStyles.CountItems();
for (int32 i = 0; i < styleCount; i++) { for (int32 i = 0; i < styleCount; i++) {
Style* style = other.fStyles->StyleAtFast(i); Style* style = other.fStyles.ItemAtFast(i);
Style* clone = new (nothrow) Style(*style); Style* clone = new (nothrow) Style(*style);
if (!clone || !fStyles->AddStyle(clone)) { if (!clone || !fStyles.AddItem(clone)) {
delete clone; delete clone;
return; return;
} }
} }
int32 pathCount = other.fPaths->CountPaths(); int32 pathCount = other.fPaths.CountItems();
for (int32 i = 0; i < pathCount; i++) { for (int32 i = 0; i < pathCount; i++) {
VectorPath* path = other.fPaths->PathAtFast(i); VectorPath* path = other.fPaths.ItemAtFast(i);
VectorPath* clone = new (nothrow) VectorPath(*path); VectorPath* clone = new (nothrow) VectorPath(*path);
if (!clone || !fPaths->AddPath(clone)) { if (!clone || !fPaths.AddItem(clone)) {
delete clone; delete clone;
return; return;
} }
} }
int32 shapeCount = other.fShapes->CountShapes(); int32 shapeCount = other.fShapes.CountItems();
for (int32 i = 0; i < shapeCount; i++) { for (int32 i = 0; i < shapeCount; i++) {
Shape* shape = other.fShapes->ShapeAtFast(i); Shape* shape = other.fShapes.ItemAtFast(i);
Shape* clone = shape->Clone(); Shape* clone = shape->Clone();
if (!clone || !fShapes->AddShape(clone)) { if (!clone || !fShapes.AddItem(clone)) {
delete clone; delete clone;
return; return;
} }
@@ -96,21 +91,21 @@ Icon::Icon(const Icon& other)
// the "other" icon, replace them with "local" styles // the "other" icon, replace them with "local" styles
// and paths // and paths
int32 styleIndex = other.fStyles->IndexOf(pathSourceShape->Style()); int32 styleIndex = other.fStyles.IndexOf(pathSourceShape->Style());
pathSourceShapeClone->SetStyle(fStyles->StyleAt(styleIndex)); pathSourceShapeClone->SetStyle(fStyles.ItemAt(styleIndex));
pathSourceShapeClone->Paths()->MakeEmpty(); pathSourceShapeClone->Paths()->MakeEmpty();
pathCount = pathSourceShape->Paths()->CountPaths(); pathCount = pathSourceShape->Paths()->CountItems();
for (int32 j = 0; j < pathCount; j++) { for (int32 j = 0; j < pathCount; j++) {
VectorPath* remote = pathSourceShape->Paths()->PathAtFast(j); VectorPath* remote = pathSourceShape->Paths()->ItemAtFast(j);
int32 index = other.fPaths->IndexOf(remote); int32 index = other.fPaths.IndexOf(remote);
VectorPath* local = fPaths->PathAt(index); VectorPath* local = fPaths.ItemAt(index);
if (!local) { if (!local) {
printf("failed to match remote and " printf("failed to match remote and "
"local paths while cloning icon\n"); "local paths while cloning icon\n");
continue; continue;
} }
if (!pathSourceShapeClone->Paths()->AddPath(local)) { if (!pathSourceShapeClone->Paths()->AddItem(local)) {
return; return;
} }
} }
@@ -118,45 +113,40 @@ Icon::Icon(const Icon& other)
} }
} }
// destructor
Icon::~Icon() Icon::~Icon()
{ {
if (fShapes) { fShapes.MakeEmpty();
fShapes->MakeEmpty();
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
fShapes->RemoveListener(this); fShapes.RemoveListener(this);
#endif #endif
delete fShapes;
}
delete fPaths;
delete fStyles;
} }
// InitCheck
status_t status_t
Icon::InitCheck() const Icon::InitCheck() const
{ {
return fStyles && fPaths && fShapes ? B_OK : B_NO_MEMORY; return B_OK;
} }
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
// ShapeAdded
void void
Icon::ShapeAdded(Shape* shape, int32 index) Icon::ItemAdded(Shape* shape, int32 index)
{ {
shape->AddObserver(this); shape->AddObserver(this);
_NotifyAreaInvalidated(shape->Bounds(true)); _NotifyAreaInvalidated(shape->Bounds(true));
} }
// ShapeRemoved
void void
Icon::ShapeRemoved(Shape* shape) Icon::ItemRemoved(Shape* shape)
{ {
shape->RemoveObserver(this); shape->RemoveObserver(this);
_NotifyAreaInvalidated(shape->Bounds(true)); _NotifyAreaInvalidated(shape->Bounds(true));
} }
// ObjectChanged
void void
Icon::ObjectChanged(const Observable* object) Icon::ObjectChanged(const Observable* object)
{ {
@@ -169,7 +159,7 @@ Icon::ObjectChanged(const Observable* object)
} }
} }
// AddListener
bool bool
Icon::AddListener(IconListener* listener) Icon::AddListener(IconListener* listener)
{ {
@@ -182,7 +172,7 @@ Icon::AddListener(IconListener* listener)
return false; return false;
} }
// RemoveListener
bool bool
Icon::RemoveListener(IconListener* listener) Icon::RemoveListener(IconListener* listener)
{ {
@@ -191,26 +181,25 @@ Icon::RemoveListener(IconListener* listener)
#endif // ICON_O_MATIC #endif // ICON_O_MATIC
// Clone
Icon* Icon*
Icon::Clone() const Icon::Clone() const
{ {
return new (nothrow) Icon(*this); return new (nothrow) Icon(*this);
} }
// MakeEmpty
void void
Icon::MakeEmpty() Icon::MakeEmpty()
{ {
fShapes->MakeEmpty(); fShapes.MakeEmpty();
fPaths->MakeEmpty(); fPaths.MakeEmpty();
fStyles->MakeEmpty(); fStyles.MakeEmpty();
} }
// #pragma mark - // #pragma mark -
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
// _NotifyAreaInvalidated
void void
Icon::_NotifyAreaInvalidated(const BRect& area) const Icon::_NotifyAreaInvalidated(const BRect& area) const
{ {
@@ -223,5 +212,3 @@ Icon::_NotifyAreaInvalidated(const BRect& area) const
} }
} }
#endif // ICON_O_MATIC #endif // ICON_O_MATIC
+35 -28
View File
@@ -9,8 +9,8 @@
#define ICON_H #define ICON_H
#include "Container.h"
#include "IconBuild.h" #include "IconBuild.h"
#include "ShapeContainer.h"
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
# include <List.h> # include <List.h>
@@ -27,8 +27,9 @@ class BRect;
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
class PathContainer; class Shape;
class StyleContainer; class Style;
class VectorPath;
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
class IconListener { class IconListener {
@@ -41,7 +42,7 @@ class IconListener {
#endif #endif
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
class Icon : public ShapeContainerListener, class Icon : public ContainerListener<Shape>,
public Observer, public Observer,
public BReferenceable { public BReferenceable {
#else #else
@@ -49,45 +50,51 @@ class Icon {
#endif #endif
public: public:
Icon(); Icon();
Icon(const Icon& other); Icon(const Icon& other);
virtual ~Icon(); virtual ~Icon();
status_t InitCheck() const; status_t InitCheck() const;
StyleContainer* Styles() const const Container<Style>* Styles() const
{ return fStyles; } { return &fStyles; }
PathContainer* Paths() const Container<Style>* Styles()
{ return fPaths; } { return &fStyles; }
ShapeContainer* Shapes() const const Container<VectorPath>* Paths() const
{ return fShapes; } { return &fPaths; }
Container<VectorPath>* Paths()
{ return &fPaths; }
const Container<Shape>* Shapes() const
{ return &fShapes; }
Container<Shape>* Shapes()
{ return &fShapes; }
Icon* Clone() const; Icon* Clone() const;
void MakeEmpty(); void MakeEmpty();
private: private:
StyleContainer* fStyles; Container<Style> fStyles;
PathContainer* fPaths; Container<VectorPath> fPaths;
ShapeContainer* fShapes; Container<Shape> fShapes;
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
public: public:
// ShapeContainerListener interface // ContainerListener<Shape> interface
virtual void ShapeAdded(Shape* shape, int32 index); virtual void ItemAdded(Shape* shape, int32 index);
virtual void ShapeRemoved(Shape* shape); virtual void ItemRemoved(Shape* shape);
// Observer interface // Observer interface
virtual void ObjectChanged(const Observable* object); virtual void ObjectChanged(const Observable* object);
// Icon // Icon
bool AddListener(IconListener* listener); bool AddListener(IconListener* listener);
bool RemoveListener(IconListener* listener); bool RemoveListener(IconListener* listener);
private: private:
void _NotifyAreaInvalidated( void _NotifyAreaInvalidated(
const BRect& area) const; const BRect& area) const;
BList fListeners; BList fListeners;
#endif #endif
}; };
+2 -3
View File
@@ -24,7 +24,6 @@
#include "GradientTransformable.h" #include "GradientTransformable.h"
#include "Icon.h" #include "Icon.h"
#include "Shape.h" #include "Shape.h"
#include "ShapeContainer.h"
#include "Style.h" #include "Style.h"
#include "VectorPath.h" #include "VectorPath.h"
@@ -459,10 +458,10 @@ IconRenderer::_Render(const BRect& r)
// iterate over the shapes in the icon, // iterate over the shapes in the icon,
// add the vector paths to the rasterizer // add the vector paths to the rasterizer
// and associate each shapes style // and associate each shapes style
int32 shapeCount = fIcon->Shapes()->CountShapes(); int32 shapeCount = fIcon->Shapes()->CountItems();
int32 styleIndex = 0; int32 styleIndex = 0;
for (int32 i = 0; i < shapeCount; i++) { for (int32 i = 0; i < shapeCount; i++) {
Shape* shape = fIcon->Shapes()->ShapeAtFast(i); Shape* shape = fIcon->Shapes()->ItemAtFast(i);
if (!shape->Visible(fGlobalTransform.scale())) { if (!shape->Visible(fGlobalTransform.scale())) {
continue; continue;
+1 -3
View File
@@ -5,6 +5,7 @@ AddSubDirSupportedPlatforms libbe_test ;
# source directories # source directories
local sourceDirs = local sourceDirs =
flat_icon flat_icon
generic
message message
shape shape
style style
@@ -44,17 +45,14 @@ for architectureObject in [ MultiArchSubDirSetup ] {
MessageImporter.cpp MessageImporter.cpp
# shape # shape
PathContainer.cpp
PathSourceShape.cpp PathSourceShape.cpp
ReferenceImage.cpp ReferenceImage.cpp
Shape.cpp Shape.cpp
ShapeContainer.cpp
VectorPath.cpp VectorPath.cpp
# style # style
GradientTransformable.cpp GradientTransformable.cpp
Style.cpp Style.cpp
StyleContainer.cpp
# transformable # transformable
Transformable.cpp Transformable.cpp
+18 -20
View File
@@ -23,13 +23,11 @@
#include "Icon.h" #include "Icon.h"
#include "LittleEndianBuffer.h" #include "LittleEndianBuffer.h"
#include "PathCommandQueue.h" #include "PathCommandQueue.h"
#include "PathContainer.h"
#include "PathSourceShape.h" #include "PathSourceShape.h"
#include "PerspectiveTransformer.h" #include "PerspectiveTransformer.h"
#include "Shape.h" #include "Shape.h"
#include "StrokeTransformer.h" #include "StrokeTransformer.h"
#include "Style.h" #include "Style.h"
#include "StyleContainer.h"
#include "VectorPath.h" #include "VectorPath.h"
using std::nothrow; using std::nothrow;
@@ -112,7 +110,7 @@ FlatIconImporter::_ParseSections(LittleEndianBuffer& buffer, Icon* icon)
return B_BAD_TYPE; return B_BAD_TYPE;
// styles // styles
StyleContainer* styles = icon->Styles(); Container<Style>* styles = icon->Styles();
status_t ret = _ParseStyles(buffer, styles); status_t ret = _ParseStyles(buffer, styles);
if (ret < B_OK) { if (ret < B_OK) {
printf("FlatIconImporter::_ParseSections() - " printf("FlatIconImporter::_ParseSections() - "
@@ -121,7 +119,7 @@ FlatIconImporter::_ParseSections(LittleEndianBuffer& buffer, Icon* icon)
} }
// paths // paths
PathContainer* paths = icon->Paths(); Container<VectorPath>* paths = icon->Paths();
ret = _ParsePaths(buffer, paths); ret = _ParsePaths(buffer, paths);
if (ret < B_OK) { if (ret < B_OK) {
printf("FlatIconImporter::_ParseSections() - " printf("FlatIconImporter::_ParseSections() - "
@@ -277,7 +275,7 @@ _ReadGradientStyle(LittleEndianBuffer& buffer)
// _ParseStyles // _ParseStyles
status_t status_t
FlatIconImporter::_ParseStyles(LittleEndianBuffer& buffer, FlatIconImporter::_ParseStyles(LittleEndianBuffer& buffer,
StyleContainer* styles) Container<Style>* styles)
{ {
uint8 styleCount; uint8 styleCount;
if (!buffer.Read(styleCount)) if (!buffer.Read(styleCount))
@@ -322,7 +320,7 @@ FlatIconImporter::_ParseStyles(LittleEndianBuffer& buffer,
continue; continue;
} }
// add style if we were able to read one // add style if we were able to read one
if (style && !styles->AddStyle(style)) { if (style && !styles->AddItem(style)) {
delete style; delete style;
return B_NO_MEMORY; return B_NO_MEMORY;
} }
@@ -388,7 +386,7 @@ read_path_with_commands(LittleEndianBuffer& buffer, VectorPath* path,
// _ParsePaths // _ParsePaths
status_t status_t
FlatIconImporter::_ParsePaths(LittleEndianBuffer& buffer, FlatIconImporter::_ParsePaths(LittleEndianBuffer& buffer,
PathContainer* paths) Container<VectorPath>* paths)
{ {
uint8 pathCount; uint8 pathCount;
if (!buffer.Read(pathCount)) if (!buffer.Read(pathCount))
@@ -426,7 +424,7 @@ FlatIconImporter::_ParsePaths(LittleEndianBuffer& buffer,
if (pathFlags & PATH_FLAG_CLOSED) if (pathFlags & PATH_FLAG_CLOSED)
path->SetClosed(true); path->SetClosed(true);
// add path to container // add path to container
if (!paths->AddPath(path)) { if (!paths->AddItem(path)) {
delete path; delete path;
return B_NO_MEMORY; return B_NO_MEMORY;
} }
@@ -522,8 +520,8 @@ _ReadTransformer(LittleEndianBuffer& buffer, VertexSource& source)
// _ReadPathSourceShape // _ReadPathSourceShape
Shape* Shape*
FlatIconImporter::_ReadPathSourceShape(LittleEndianBuffer& buffer, FlatIconImporter::_ReadPathSourceShape(LittleEndianBuffer& buffer,
StyleContainer* styles, Container<Style>* styles,
PathContainer* paths) Container<VectorPath>* paths)
{ {
// find out which style this shape uses // find out which style this shape uses
uint8 styleIndex; uint8 styleIndex;
@@ -532,9 +530,9 @@ FlatIconImporter::_ReadPathSourceShape(LittleEndianBuffer& buffer,
return NULL; return NULL;
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
Style* style = styles->StyleAt(StyleIndexFor(styleIndex)); Style* style = styles->ItemAt(StyleIndexFor(styleIndex));
#else #else
Style* style = styles->StyleAt(styleIndex); Style* style = styles->ItemAt(styleIndex);
#endif #endif
if (!style) { if (!style) {
@@ -557,16 +555,16 @@ FlatIconImporter::_ReadPathSourceShape(LittleEndianBuffer& buffer,
return NULL; return NULL;
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
VectorPath* path = paths->PathAt(PathIndexFor(pathIndex)); VectorPath* path = paths->ItemAt(PathIndexFor(pathIndex));
#else #else
VectorPath* path = paths->PathAt(pathIndex); VectorPath* path = paths->ItemAt(pathIndex);
#endif #endif
if (!path) { if (!path) {
printf("_ReadPathSourceShape() - " printf("_ReadPathSourceShape() - "
"shape references non-existing path %d\n", pathIndex); "shape references non-existing path %d\n", pathIndex);
continue; continue;
} }
shape->Paths()->AddPath(path); shape->Paths()->AddItem(path);
} }
// shape flags // shape flags
@@ -604,7 +602,7 @@ FlatIconImporter::_ReadPathSourceShape(LittleEndianBuffer& buffer,
for (uint32 i = 0; i < transformerCount; i++) { for (uint32 i = 0; i < transformerCount; i++) {
Transformer* transformer Transformer* transformer
= _ReadTransformer(buffer, shape->VertexSource()); = _ReadTransformer(buffer, shape->VertexSource());
if (transformer && !shape->AddTransformer(transformer)) { if (transformer && !shape->Transformers()->AddItem(transformer)) {
delete transformer; delete transformer;
return NULL; return NULL;
} }
@@ -618,9 +616,9 @@ FlatIconImporter::_ReadPathSourceShape(LittleEndianBuffer& buffer,
// _ParseShapes // _ParseShapes
status_t status_t
FlatIconImporter::_ParseShapes(LittleEndianBuffer& buffer, FlatIconImporter::_ParseShapes(LittleEndianBuffer& buffer,
StyleContainer* styles, Container<Style>* styles,
PathContainer* paths, Container<VectorPath>* paths,
ShapeContainer* shapes) Container<Shape>* shapes)
{ {
uint8 shapeCount; uint8 shapeCount;
if (!buffer.Read(shapeCount)) if (!buffer.Read(shapeCount))
@@ -645,7 +643,7 @@ FlatIconImporter::_ParseShapes(LittleEndianBuffer& buffer,
continue; continue;
} }
// add shape if we were able to read one // add shape if we were able to read one
if (shape && !shapes->AddShape(shape)) { if (shape && !shapes->AddItem(shape)) {
delete shape; delete shape;
return B_NO_MEMORY; return B_NO_MEMORY;
} }
+10 -9
View File
@@ -15,6 +15,7 @@
# include <SupportDefs.h> # include <SupportDefs.h>
#endif #endif
#include "Container.h"
#include "IconBuild.h" #include "IconBuild.h"
@@ -29,8 +30,8 @@ class Icon;
class LittleEndianBuffer; class LittleEndianBuffer;
class PathContainer; class PathContainer;
class Shape; class Shape;
class ShapeContainer; class Style;
class StyleContainer; class VectorPath;
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
class FlatIconImporter : public Importer { class FlatIconImporter : public Importer {
@@ -53,17 +54,17 @@ class FlatIconImporter {
Icon* icon); Icon* icon);
status_t _ParseStyles(LittleEndianBuffer& buffer, status_t _ParseStyles(LittleEndianBuffer& buffer,
StyleContainer* styles); Container<Style>* styles);
status_t _ParsePaths(LittleEndianBuffer& buffer, status_t _ParsePaths(LittleEndianBuffer& buffer,
PathContainer* paths); Container<VectorPath>* paths);
Shape* _ReadPathSourceShape( Shape* _ReadPathSourceShape(
LittleEndianBuffer& buffer, LittleEndianBuffer& buffer,
StyleContainer* styles, Container<Style>* styles,
PathContainer* paths); Container<VectorPath>* paths);
status_t _ParseShapes(LittleEndianBuffer& buffer, status_t _ParseShapes(LittleEndianBuffer& buffer,
StyleContainer* styles, Container<Style>* styles,
PathContainer* paths, Container<VectorPath>* paths,
ShapeContainer* shapes); Container<Shape>* shapes);
}; };
+308
View File
@@ -0,0 +1,308 @@
/*
* Copyright 2006-2007, 2023, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/
#ifndef CONTAINER_H
#define CONTAINER_H
#include <stdio.h>
#include <string.h>
#include <List.h>
#include <OS.h>
#include <Referenceable.h>
#include "IconBuild.h"
class BReferenceable;
_BEGIN_ICON_NAMESPACE
#ifdef ICON_O_MATIC
template<class Type>
class ContainerListener {
public:
ContainerListener();
virtual ~ContainerListener();
virtual void ItemAdded(Type* item, int32 index) = 0;
virtual void ItemRemoved(Type* item) = 0;
};
#endif // ICON_O_MATIC
/*!
Wraps \c BList and provides some additional features.
-# It allows listeners to listen when an item is added or removed.
-# It can take ownership of the objects that it stores.
-# It casts list items into the correct type.
*/
// TODO: some of these features are provided by BObjectList
template<class Type>
class Container {
public:
Container(bool ownsItems);
virtual ~Container();
bool AddItem(Type* item);
bool AddItem(Type* item, int32 index);
bool RemoveItem(Type* item);
Type* RemoveItem(int32 index);
void MakeEmpty();
int32 CountItems() const;
bool HasItem(Type* item) const;
int32 IndexOf(Type* item) const;
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);
private:
void _NotifyItemAdded(Type* item, int32 index) const;
void _NotifyItemRemoved(Type* item) const;
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
{
}
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();
}
// #pragma mark -
template<class Type>
bool
Container<Type>::AddItem(Type* item)
{
return AddItem(item, CountItems());
}
template<class Type>
bool
Container<Type>::AddItem(Type* item, int32 index)
{
if (!item)
return false;
// prevent adding the same item twice
if (HasItem(item))
return false;
if (fItems.AddItem((void*)item, index)) {
#ifdef ICON_O_MATIC
_NotifyItemAdded(item, index);
#endif
return true;
}
fprintf(stderr, "Container::AddItem() - out of memory!\n");
return false;
}
template<class Type>
bool
Container<Type>::RemoveItem(Type* item)
{
if (fItems.RemoveItem((void*)item)) {
#ifdef ICON_O_MATIC
_NotifyItemRemoved(item);
#endif
return true;
}
return false;
}
template<class Type>
Type*
Container<Type>::RemoveItem(int32 index)
{
Type* item = (Type*)fItems.RemoveItem(index);
#ifdef ICON_O_MATIC
if (item) {
_NotifyItemRemoved(item);
}
#endif
return item;
}
template<class Type>
void
Container<Type>::MakeEmpty()
{
int32 count = CountItems();
for (int32 i = 0; i < count; i++) {
Type* item = ItemAtFast(i);
#ifdef ICON_O_MATIC
_NotifyItemRemoved(item);
if (fOwnsItems)
item->ReleaseReference();
#else
if (fOwnsItems)
delete item;
#endif
}
fItems.MakeEmpty();
}
// #pragma mark -
template<class Type>
int32
Container<Type>::CountItems() const
{
return fItems.CountItems();
}
template<class Type>
bool
Container<Type>::HasItem(Type* item) const
{
return fItems.HasItem(item);
}
template<class Type>
int32
Container<Type>::IndexOf(Type* item) const
{
return fItems.IndexOf((void*)item);
}
template<class Type>
Type*
Container<Type>::ItemAt(int32 index) const
{
return (Type*)fItems.ItemAt(index);
}
template<class Type>
Type*
Container<Type>::ItemAtFast(int32 index) const
{
return (Type*)fItems.ItemAtFast(index);
}
// #pragma mark -
#ifdef ICON_O_MATIC
template<class Type>
bool
Container<Type>::AddListener(ContainerListener<Type>* listener)
{
if (listener && !fListeners.HasItem(listener))
return fListeners.AddItem(listener);
return false;
}
template<class Type>
bool
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
{
BList listeners(fListeners);
int32 count = listeners.CountItems();
for (int32 i = 0; i < count; i++) {
ContainerListener<Type>* listener
= (ContainerListener<Type>*)listeners.ItemAtFast(i);
listener->ItemAdded(item, index);
}
}
template<class Type>
void
Container<Type>::_NotifyItemRemoved(Type* item) const
{
BList listeners(fListeners);
int32 count = listeners.CountItems();
for (int32 i = 0; i < count; i++) {
ContainerListener<Type>* listener
= (ContainerListener<Type>*)listeners.ItemAtFast(i);
listener->ItemRemoved(item);
}
}
#endif // ICON_O_MATIC
_END_ICON_NAMESPACE
#endif // CONTAINER_H
+16 -17
View File
@@ -21,16 +21,15 @@
#include <DataIO.h> #include <DataIO.h>
#include <Message.h> #include <Message.h>
#include "Container.h"
#include "Defines.h" #include "Defines.h"
#include "Icon.h" #include "Icon.h"
#include "PathContainer.h"
#include "PathSourceShape.h" #include "PathSourceShape.h"
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
#include "ReferenceImage.h" #include "ReferenceImage.h"
#endif #endif
#include "Shape.h" #include "Shape.h"
#include "Style.h" #include "Style.h"
#include "StyleContainer.h"
#include "VectorPath.h" #include "VectorPath.h"
@@ -92,7 +91,7 @@ MessageImporter::Import(Icon* icon, BPositionIO* stream)
return ret; return ret;
// paths // paths
PathContainer* paths = icon->Paths(); Container<VectorPath>* paths = icon->Paths();
ret = _ImportPaths(&archive, paths); ret = _ImportPaths(&archive, paths);
if (ret < B_OK) { if (ret < B_OK) {
printf("MessageImporter::Import() - " printf("MessageImporter::Import() - "
@@ -101,7 +100,7 @@ MessageImporter::Import(Icon* icon, BPositionIO* stream)
} }
// styles // styles
StyleContainer* styles = icon->Styles(); Container<Style>* styles = icon->Styles();
ret = _ImportStyles(&archive, styles); ret = _ImportStyles(&archive, styles);
if (ret < B_OK) { if (ret < B_OK) {
printf("MessageImporter::Import() - " printf("MessageImporter::Import() - "
@@ -126,7 +125,7 @@ MessageImporter::Import(Icon* icon, BPositionIO* stream)
status_t status_t
MessageImporter::_ImportPaths(const BMessage* archive, MessageImporter::_ImportPaths(const BMessage* archive,
PathContainer* paths) const Container<VectorPath>* paths) const
{ {
BMessage allPaths; BMessage allPaths;
status_t ret = archive->FindMessage("paths", &allPaths); status_t ret = archive->FindMessage("paths", &allPaths);
@@ -137,7 +136,7 @@ MessageImporter::_ImportPaths(const BMessage* archive,
for (int32 i = 0; for (int32 i = 0;
allPaths.FindMessage("path", i, &pathArchive) == B_OK; i++) { allPaths.FindMessage("path", i, &pathArchive) == B_OK; i++) {
VectorPath* path = new (nothrow) VectorPath(&pathArchive); VectorPath* path = new (nothrow) VectorPath(&pathArchive);
if (!path || !paths->AddPath(path)) { if (!path || !paths->AddItem(path)) {
delete path; delete path;
ret = B_NO_MEMORY; ret = B_NO_MEMORY;
} }
@@ -151,7 +150,7 @@ MessageImporter::_ImportPaths(const BMessage* archive,
status_t status_t
MessageImporter::_ImportStyles(const BMessage* archive, MessageImporter::_ImportStyles(const BMessage* archive,
StyleContainer* styles) const Container<Style>* styles) const
{ {
BMessage allStyles; BMessage allStyles;
status_t ret = archive->FindMessage("styles", &allStyles); status_t ret = archive->FindMessage("styles", &allStyles);
@@ -162,7 +161,7 @@ MessageImporter::_ImportStyles(const BMessage* archive,
for (int32 i = 0; for (int32 i = 0;
allStyles.FindMessage("style", i, &styleArchive) == B_OK; i++) { allStyles.FindMessage("style", i, &styleArchive) == B_OK; i++) {
Style* style = new (nothrow) Style(&styleArchive); Style* style = new (nothrow) Style(&styleArchive);
if (!style || !styles->AddStyle(style)) { if (!style || !styles->AddItem(style)) {
delete style; delete style;
ret = B_NO_MEMORY; ret = B_NO_MEMORY;
} }
@@ -175,8 +174,8 @@ MessageImporter::_ImportStyles(const BMessage* archive,
status_t status_t
MessageImporter::_ImportShapes(const BMessage* archive, PathContainer* paths, MessageImporter::_ImportShapes(const BMessage* archive, Container<VectorPath>* paths,
StyleContainer* styles, ShapeContainer* shapes) const Container<Style>* styles, Container<Shape>* shapes) const
{ {
BMessage allShapes; BMessage allShapes;
status_t ret = archive->FindMessage("shapes", &allShapes); status_t ret = archive->FindMessage("shapes", &allShapes);
@@ -200,9 +199,9 @@ MessageImporter::_ImportShapes(const BMessage* archive, PathContainer* paths,
continue; continue;
} }
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
Style* style = styles->StyleAt(StyleIndexFor(styleIndex)); Style* style = styles->ItemAt(StyleIndexFor(styleIndex));
#else #else
Style* style = styles->StyleAt(styleIndex); Style* style = styles->ItemAt(styleIndex);
#endif #endif
if (style == NULL) { if (style == NULL) {
printf("MessageImporter::_ImportShapes() - " printf("MessageImporter::_ImportShapes() - "
@@ -213,7 +212,7 @@ MessageImporter::_ImportShapes(const BMessage* archive, PathContainer* paths,
// create shape // create shape
PathSourceShape* shape = new (nothrow) PathSourceShape(style); PathSourceShape* shape = new (nothrow) PathSourceShape(style);
if (shape == NULL || shape->InitCheck() < B_OK || !shapes->AddShape(shape)) { if (shape == NULL || shape->InitCheck() < B_OK || !shapes->AddItem(shape)) {
delete shape; delete shape;
ret = B_NO_MEMORY; ret = B_NO_MEMORY;
} }
@@ -226,9 +225,9 @@ MessageImporter::_ImportShapes(const BMessage* archive, PathContainer* paths,
shapeArchive.FindInt32("path ref", j, &pathIndex) == B_OK; shapeArchive.FindInt32("path ref", j, &pathIndex) == B_OK;
j++) { j++) {
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
VectorPath* path = paths->PathAt(PathIndexFor(pathIndex)); VectorPath* path = paths->ItemAt(PathIndexFor(pathIndex));
#else #else
VectorPath* path = paths->PathAt(pathIndex); VectorPath* path = paths->ItemAt(pathIndex);
#endif #endif
if (path == NULL) { if (path == NULL) {
printf("MessageImporter::_ImportShapes() - " printf("MessageImporter::_ImportShapes() - "
@@ -236,7 +235,7 @@ MessageImporter::_ImportShapes(const BMessage* archive, PathContainer* paths,
"which does not exist\n", i, pathIndex); "which does not exist\n", i, pathIndex);
continue; continue;
} }
shape->Paths()->AddPath(path); shape->Paths()->AddItem(path);
} }
// Shape properties // Shape properties
@@ -246,7 +245,7 @@ MessageImporter::_ImportShapes(const BMessage* archive, PathContainer* paths,
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
else if (type == ReferenceImage::archive_code) { else if (type == ReferenceImage::archive_code) {
ReferenceImage* shape = new (nothrow) ReferenceImage(&shapeArchive); ReferenceImage* shape = new (nothrow) ReferenceImage(&shapeArchive);
if (shape == NULL || shape->InitCheck() < B_OK || !shapes->AddShape(shape)) { if (shape == NULL || shape->InitCheck() < B_OK || !shapes->AddItem(shape)) {
delete shape; delete shape;
ret = B_NO_MEMORY; ret = B_NO_MEMORY;
} }
+9 -7
View File
@@ -25,10 +25,12 @@ class BPositionIO;
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
template <class Type> class Container;
class Icon; class Icon;
class PathContainer; class PathContainer;
class ShapeContainer; class Shape;
class StyleContainer; class Style;
class VectorPath;
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
@@ -45,13 +47,13 @@ class MessageImporter {
private: private:
status_t _ImportPaths(const BMessage* archive, status_t _ImportPaths(const BMessage* archive,
PathContainer* paths) const; Container<VectorPath>* paths) const;
status_t _ImportStyles(const BMessage* archive, status_t _ImportStyles(const BMessage* archive,
StyleContainer* styles) const; Container<Style>* styles) const;
status_t _ImportShapes(const BMessage* archive, status_t _ImportShapes(const BMessage* archive,
PathContainer* paths, Container<VectorPath>* paths,
StyleContainer* styles, Container<Style>* styles,
ShapeContainer* shapes) const; Container<Shape>* shapes) const;
}; };
-220
View File
@@ -1,220 +0,0 @@
/*
* Copyright 2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
#include "PathContainer.h"
#include <stdio.h>
#include <string.h>
#include <OS.h>
#include "VectorPath.h"
#ifdef ICON_O_MATIC
PathContainerListener::PathContainerListener() {}
PathContainerListener::~PathContainerListener() {}
#endif
// constructor
PathContainer::PathContainer(bool ownsPaths)
: fPaths(16),
fOwnsPaths(ownsPaths)
#ifdef ICON_O_MATIC
, fListeners(2)
#endif
{
}
// destructor
PathContainer::~PathContainer()
{
#ifdef ICON_O_MATIC
int32 count = fListeners.CountItems();
if (count > 0) {
debugger("~PathContainer() - there are still"
"listeners attached\n");
}
#endif // ICON_O_MATIC
_MakeEmpty();
}
// #pragma mark -
// AddPath
bool
PathContainer::AddPath(VectorPath* path)
{
return AddPath(path, CountPaths());
}
// AddPath
bool
PathContainer::AddPath(VectorPath* path, int32 index)
{
if (!path)
return false;
// prevent adding the same path twice
if (HasPath(path))
return false;
if (fPaths.AddItem((void*)path, index)) {
#ifdef ICON_O_MATIC
_NotifyPathAdded(path, index);
#endif
return true;
}
fprintf(stderr, "PathContainer::AddPath() - out of memory!\n");
return false;
}
// RemovePath
bool
PathContainer::RemovePath(VectorPath* path)
{
if (fPaths.RemoveItem((void*)path)) {
#ifdef ICON_O_MATIC
_NotifyPathRemoved(path);
#endif
return true;
}
return false;
}
// RemovePath
VectorPath*
PathContainer::RemovePath(int32 index)
{
VectorPath* path = (VectorPath*)fPaths.RemoveItem(index);
#ifdef ICON_O_MATIC
if (path) {
_NotifyPathRemoved(path);
}
#endif
return path;
}
// MakeEmpty
void
PathContainer::MakeEmpty()
{
_MakeEmpty();
}
// #pragma mark -
// CountPaths
int32
PathContainer::CountPaths() const
{
return fPaths.CountItems();
}
// HasPath
bool
PathContainer::HasPath(VectorPath* path) const
{
return fPaths.HasItem((void*)path);
}
// IndexOf
int32
PathContainer::IndexOf(VectorPath* path) const
{
return fPaths.IndexOf((void*)path);
}
// PathAt
VectorPath*
PathContainer::PathAt(int32 index) const
{
return (VectorPath*)fPaths.ItemAt(index);
}
// PathAtFast
VectorPath*
PathContainer::PathAtFast(int32 index) const
{
return (VectorPath*)fPaths.ItemAtFast(index);
}
// #pragma mark -
#ifdef ICON_O_MATIC
// AddListener
bool
PathContainer::AddListener(PathContainerListener* listener)
{
if (listener && !fListeners.HasItem((void*)listener))
return fListeners.AddItem(listener);
return false;
}
// RemoveListener
bool
PathContainer::RemoveListener(PathContainerListener* listener)
{
return fListeners.RemoveItem(listener);
}
#endif // ICON_O_MATIC
// #pragma mark -
// _MakeEmpty
void
PathContainer::_MakeEmpty()
{
int32 count = CountPaths();
for (int32 i = 0; i < count; i++) {
VectorPath* path = PathAtFast(i);
#ifdef ICON_O_MATIC
_NotifyPathRemoved(path);
if (fOwnsPaths)
path->ReleaseReference();
#else
if (fOwnsPaths)
delete path;
#endif
}
fPaths.MakeEmpty();
}
// #pragma mark -
#ifdef ICON_O_MATIC
// _NotifyPathAdded
void
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, index);
}
}
// _NotifyPathRemoved
void
PathContainer::_NotifyPathRemoved(VectorPath* path) const
{
BList listeners(fListeners);
int32 count = listeners.CountItems();
for (int32 i = 0; i < count; i++) {
PathContainerListener* listener
= (PathContainerListener*)listeners.ItemAtFast(i);
listener->PathRemoved(path);
}
}
#endif // ICON_O_MATIC
-76
View File
@@ -1,76 +0,0 @@
/*
* Copyright 2006-2007, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
#ifndef PATH_CONTAINER_H
#define PATH_CONTAINER_H
#include <List.h>
#include "IconBuild.h"
_BEGIN_ICON_NAMESPACE
class VectorPath;
#ifdef ICON_O_MATIC
class PathContainerListener {
public:
PathContainerListener();
virtual ~PathContainerListener();
virtual void PathAdded(VectorPath* path, int32 index) = 0;
virtual void PathRemoved(VectorPath* path) = 0;
};
#endif // ICON_O_MATIC
class PathContainer {
public:
PathContainer(bool ownsPaths);
virtual ~PathContainer();
bool AddPath(VectorPath* path);
bool AddPath(VectorPath* path, int32 index);
bool RemovePath(VectorPath* path);
VectorPath* RemovePath(int32 index);
void MakeEmpty();
int32 CountPaths() const;
bool HasPath(VectorPath* path) const;
int32 IndexOf(VectorPath* path) const;
VectorPath* PathAt(int32 index) const;
VectorPath* PathAtFast(int32 index) const;
private:
void _MakeEmpty();
BList fPaths;
bool fOwnsPaths;
#ifdef ICON_O_MATIC
public:
bool AddListener(PathContainerListener* listener);
bool RemoveListener(PathContainerListener* listener);
private:
void _NotifyPathAdded(VectorPath* path,
int32 index) const;
void _NotifyPathRemoved(VectorPath* path) const;
BList fListeners;
#endif // ICON_O_MATIC
};
_END_ICON_NAMESPACE
#endif // PATH_CONTAINER_H
+1 -1
View File
@@ -216,7 +216,7 @@ ReferenceImage::SetImage(BBitmap* image)
fPath->AddPoint(BPoint(width, height)); fPath->AddPoint(BPoint(width, height));
fPath->AddPoint(BPoint(width, 0)); fPath->AddPoint(BPoint(width, 0));
fPath->SetClosed(true); fPath->SetClosed(true);
Paths()->AddPath(fPath); Paths()->AddItem(fPath);
} }
} }
-1
View File
@@ -14,7 +14,6 @@
#include "IconObject.h" #include "IconObject.h"
#include "Observer.h" #include "Observer.h"
#include "IconBuild.h" #include "IconBuild.h"
#include "PathContainer.h"
#include "PathSource.h" #include "PathSource.h"
#include "Shape.h" #include "Shape.h"
#include "Transformable.h" #include "Transformable.h"
+57 -140
View File
@@ -1,9 +1,10 @@
/* /*
* Copyright 2006, Haiku. All rights reserved. * Copyright 2006, 2023, Haiku. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#include "Shape.h" #include "Shape.h"
@@ -22,8 +23,10 @@
# include "Property.h" # include "Property.h"
# include "PropertyObject.h" # include "PropertyObject.h"
#endif // ICON_O_MATIC #endif // ICON_O_MATIC
#include "Container.h"
#include "Style.h" #include "Style.h"
#include "TransformerFactory.h" #include "TransformerFactory.h"
#include "VectorPath.h"
using std::nothrow; using std::nothrow;
@@ -48,16 +51,16 @@ Shape::Shape(::Style* style)
: IconObject("<shape>"), : IconObject("<shape>"),
Transformable(), Transformable(),
Observer(), Observer(),
PathContainerListener(), ContainerListener<VectorPath>(),
#else #else
: Transformable(), : Transformable(),
#endif #endif
fPaths(new (nothrow) PathContainer(false)), fPaths(new (nothrow) Container<VectorPath>(false)),
fStyle(NULL), fStyle(NULL),
fPathSource(fPaths), fPathSource(fPaths),
fTransformers(4), fTransformers(true),
fNeedsUpdate(true), fNeedsUpdate(true),
fLastBounds(0, 0, -1, -1), fLastBounds(0, 0, -1, -1),
@@ -73,6 +76,8 @@ Shape::Shape(::Style* style)
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
if (fPaths) if (fPaths)
fPaths->AddListener(this); fPaths->AddListener(this);
fTransformers.AddListener(this);
#endif #endif
} }
@@ -82,16 +87,16 @@ Shape::Shape(const Shape& other)
: IconObject(other), : IconObject(other),
Transformable(other), Transformable(other),
Observer(), Observer(),
PathContainerListener(), ContainerListener<VectorPath>(),
#else #else
: Transformable(other), : Transformable(other),
#endif #endif
fPaths(new (nothrow) PathContainer(false)), fPaths(new (nothrow) Container<VectorPath>(false)),
fStyle(NULL), fStyle(NULL),
fPathSource(fPaths), fPathSource(fPaths),
fTransformers(4), fTransformers(true),
fNeedsUpdate(true), fNeedsUpdate(true),
fLastBounds(0, 0, -1, -1), fLastBounds(0, 0, -1, -1),
@@ -107,24 +112,26 @@ Shape::Shape(const Shape& other)
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
// the other shape // the other shape
if (other.fPaths) { if (other.fPaths) {
int32 count = other.fPaths->CountPaths(); int32 count = other.fPaths->CountItems();
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
if (!fPaths->AddPath(other.fPaths->PathAtFast(i))) if (!fPaths->AddItem(other.fPaths->ItemAtFast(i)))
break; break;
} }
} }
} }
// clone vertex transformers // clone vertex transformers
int32 count = other.CountTransformers(); int32 count = other.Transformers()->CountItems();
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
Transformer* original = other.TransformerAtFast(i); Transformer* original = other.Transformers()->ItemAtFast(i);
Transformer* cloned = original->Clone(fPathSource); Transformer* cloned = original->Clone(fPathSource);
if (!AddTransformer(cloned)) { if (!fTransformers.AddItem(cloned)) {
delete cloned; delete cloned;
break; break;
} }
@@ -134,19 +141,12 @@ Shape::Shape(const Shape& other)
Shape::~Shape() Shape::~Shape()
{ {
int32 count = fTransformers.CountItems();
for (int32 i = 0; i < count; i++) {
Transformer* t = (Transformer*)fTransformers.ItemAtFast(i);
#ifdef ICON_O_MATIC
t->RemoveObserver(this);
_NotifyTransformerRemoved(t);
#endif
delete t;
}
fPaths->MakeEmpty(); fPaths->MakeEmpty();
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
fPaths->RemoveListener(this); fPaths->RemoveListener(this);
fTransformers.MakeEmpty();
fTransformers.RemoveListener(this);
#endif #endif
delete fPaths; delete fPaths;
@@ -182,7 +182,7 @@ Shape::Unarchive(BMessage* archive)
Transformer* transformer Transformer* transformer
= TransformerFactory::TransformerFor( = TransformerFactory::TransformerFor(
&transformerArchive, VertexSource()); &transformerArchive, VertexSource());
if (!transformer || !AddTransformer(transformer)) { if (!transformer || !fTransformers.AddItem(transformer)) {
delete transformer; delete transformer;
} }
} }
@@ -212,9 +212,9 @@ Shape::Archive(BMessage* into, bool deep) const
// transformers // transformers
if (ret == B_OK) { if (ret == B_OK) {
int32 count = CountTransformers(); int32 count = fTransformers.CountItems();
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
Transformer* transformer = TransformerAtFast(i); Transformer* transformer = fTransformers.ItemAtFast(i);
BMessage transformerArchive; BMessage transformerArchive;
ret = transformer->Archive(&transformerArchive); ret = transformer->Archive(&transformerArchive);
if (ret == B_OK) if (ret == B_OK)
@@ -281,7 +281,7 @@ Shape::ObjectChanged(const Observable* object)
void void
Shape::PathAdded(VectorPath* path, int32 index) Shape::ItemAdded(VectorPath* path, int32 index)
{ {
path->AcquireReference(); path->AcquireReference();
path->AddListener(this); path->AddListener(this);
@@ -290,7 +290,7 @@ Shape::PathAdded(VectorPath* path, int32 index)
void void
Shape::PathRemoved(VectorPath* path) Shape::ItemRemoved(VectorPath* path)
{ {
path->RemoveListener(this); path->RemoveListener(this);
_NotifyRerender(); _NotifyRerender();
@@ -301,6 +301,36 @@ Shape::PathRemoved(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)
{ {
@@ -444,89 +474,6 @@ Shape::SetGlobalScale(double scale)
} }
bool
Shape::AddTransformer(Transformer* transformer)
{
return AddTransformer(transformer, CountTransformers());
}
bool
Shape::AddTransformer(Transformer* transformer, int32 index)
{
if (!transformer)
return false;
if (!fTransformers.AddItem((void*)transformer, index))
return false;
#ifdef ICON_O_MATIC
transformer->AddObserver(this);
_NotifyTransformerAdded(transformer, index);
#else
fNeedsUpdate = true;
#endif
return true;
}
bool
Shape::RemoveTransformer(Transformer* transformer)
{
if (fTransformers.RemoveItem((void*)transformer)) {
#ifdef ICON_O_MATIC
transformer->RemoveObserver(this);
_NotifyTransformerRemoved(transformer);
#else
fNeedsUpdate = true;
#endif
return true;
}
return false;
}
// #pragma mark -
int32
Shape::CountTransformers() const
{
return fTransformers.CountItems();
}
bool
Shape::HasTransformer(Transformer* transformer) const
{
return fTransformers.HasItem((void*)transformer);
}
int32
Shape::IndexOf(Transformer* transformer) const
{
return fTransformers.IndexOf((void*)transformer);
}
Transformer*
Shape::TransformerAt(int32 index) const
{
return (Transformer*)fTransformers.ItemAt(index);
}
Transformer*
Shape::TransformerAtFast(int32 index) const
{
return (Transformer*)fTransformers.ItemAtFast(index);
}
// #pragma mark - // #pragma mark -
@@ -550,36 +497,6 @@ Shape::RemoveListener(ShapeListener* listener)
// #pragma mark - // #pragma mark -
void
Shape::_NotifyTransformerAdded(Transformer* transformer, int32 index) const
{
BList listeners(fListeners);
int32 count = listeners.CountItems();
for (int32 i = 0; i < count; i++) {
ShapeListener* listener
= (ShapeListener*)listeners.ItemAtFast(i);
listener->TransformerAdded(transformer, index);
}
// TODO: merge Observable and ShapeListener interface
_NotifyRerender();
}
void
Shape::_NotifyTransformerRemoved(Transformer* transformer) const
{
BList listeners(fListeners);
int32 count = listeners.CountItems();
for (int32 i = 0; i < count; i++) {
ShapeListener* listener
= (ShapeListener*)listeners.ItemAtFast(i);
listener->TransformerRemoved(transformer);
}
// TODO: merge Observable and ShapeListener interface
_NotifyRerender();
}
void void
Shape::_NotifyStyleChanged(::Style* oldStyle, ::Style* newStyle) const Shape::_NotifyStyleChanged(::Style* oldStyle, ::Style* newStyle) const
{ {
+64 -74
View File
@@ -1,9 +1,10 @@
/* /*
* Copyright 2006-2007, Haiku. All rights reserved. * Copyright 2006-2007, 2023, Haiku. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Zardshard
*/ */
#ifndef SHAPE_H #ifndef SHAPE_H
#define SHAPE_H #define SHAPE_H
@@ -13,8 +14,8 @@
# include "IconObject.h" # include "IconObject.h"
# include "Observer.h" # include "Observer.h"
#endif #endif
#include "Container.h"
#include "IconBuild.h" #include "IconBuild.h"
#include "PathContainer.h"
#include "PathSource.h" #include "PathSource.h"
#include "Transformable.h" #include "Transformable.h"
#include "VectorPath.h" #include "VectorPath.h"
@@ -38,10 +39,6 @@ class ShapeListener {
ShapeListener(); ShapeListener();
virtual ~ShapeListener(); virtual ~ShapeListener();
virtual void TransformerAdded(Transformer* t,
int32 index) = 0;
virtual void TransformerRemoved(Transformer* t) = 0;
// TODO: this is not useful for all subclasses of Shape (e.g. ReferenceImage) // TODO: this is not useful for all subclasses of Shape (e.g. ReferenceImage)
virtual void StyleChanged(::Style* oldStyle, virtual void StyleChanged(::Style* oldStyle,
::Style* newStyle) = 0; ::Style* newStyle) = 0;
@@ -52,117 +49,110 @@ class ShapeListener {
class Shape : public IconObject, class Shape : public IconObject,
public _ICON_NAMESPACE Transformable, public _ICON_NAMESPACE Transformable,
public Observer, // observing all the paths and the style public Observer, // observing all the paths and the style
public PathContainerListener, public ContainerListener<VectorPath>,
public ContainerListener<Transformer>,
public PathListener { public PathListener {
#else #else
class Shape : public _ICON_NAMESPACE Transformable { class Shape : public _ICON_NAMESPACE Transformable {
#endif #endif
public: public:
Shape(::Style* style); Shape(::Style* style);
Shape(const Shape& other); Shape(const Shape& other);
virtual ~Shape(); virtual ~Shape();
// IconObject interface // IconObject interface
virtual status_t Unarchive(BMessage* archive); virtual status_t Unarchive(BMessage* archive);
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
virtual status_t Archive(BMessage* into, virtual status_t Archive(BMessage* into,
bool deep = true) const; bool deep = true) const;
virtual PropertyObject* MakePropertyObject() const; virtual PropertyObject* MakePropertyObject() const;
virtual bool SetToPropertyObject( virtual bool SetToPropertyObject(
const PropertyObject* object); const PropertyObject* object);
// Transformable interface // Transformable interface
virtual void TransformationChanged(); virtual void TransformationChanged();
// Observer interface // Observer interface
virtual void ObjectChanged(const Observable* object); virtual void ObjectChanged(const Observable* object);
// ContainerListener<VectorPath> interface
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);
// PathContainerListener interface
virtual void PathAdded(VectorPath* path, int32 index);
virtual void PathRemoved(VectorPath* path);
// PathListener interface // PathListener interface
virtual void PointAdded(int32 index); virtual void PointAdded(int32 index);
virtual void PointRemoved(int32 index); virtual void PointRemoved(int32 index);
virtual void PointChanged(int32 index); virtual void PointChanged(int32 index);
virtual void PathChanged(); virtual void PathChanged();
virtual void PathClosedChanged(); virtual void PathClosedChanged();
virtual void PathReversed(); virtual void PathReversed();
#else #else
inline void Notify() {} inline void Notify() {}
#endif // ICON_O_MATIC #endif // ICON_O_MATIC
// Shape // Shape
virtual status_t InitCheck() const; virtual status_t InitCheck() const;
virtual Shape* Clone() const = 0; virtual Shape* Clone() const = 0;
inline PathContainer* Paths() const inline Container<VectorPath>* Paths() const
{ return fPaths; } { return fPaths; }
const Container<Transformer>* Transformers() const
{ return &fTransformers; }
Container<Transformer>* Transformers()
{ return &fTransformers; }
public: public:
inline ::Style* Style() const inline ::Style* Style() const
{ return fStyle; } { return fStyle; }
inline BRect LastBounds() const inline BRect LastBounds() const
{ return fLastBounds; } { return fLastBounds; }
BRect Bounds(bool updateLast = false) const; BRect Bounds(bool updateLast = false) const;
::VertexSource& VertexSource(); ::VertexSource& VertexSource();
void SetGlobalScale(double scale); void SetGlobalScale(double scale);
bool AddTransformer(Transformer* transformer); void SetHinting(bool hinting);
bool AddTransformer(Transformer* transformer, bool Hinting() const
int32 index); { return fHinting; }
bool RemoveTransformer(Transformer* transformer);
int32 CountTransformers() const; virtual bool Visible(float scale) const = 0;
bool HasTransformer(Transformer* transformer) const;
int32 IndexOf(Transformer* transformer) const;
Transformer* TransformerAt(int32 index) const;
Transformer* TransformerAtFast(int32 index) const;
void SetHinting(bool hinting);
bool Hinting() const
{ return fHinting; }
virtual bool Visible(float scale) const = 0;
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
bool AddListener(ShapeListener* listener); bool AddListener(ShapeListener* listener);
bool RemoveListener(ShapeListener* listener); bool RemoveListener(ShapeListener* listener);
private: private:
void _NotifyTransformerAdded(Transformer* t, void _NotifyStyleChanged(::Style* oldStyle,
int32 index) const; ::Style* newStyle) const;
void _NotifyTransformerRemoved(Transformer* t) const;
void _NotifyStyleChanged(::Style* oldStyle, void _NotifyRerender() const;
::Style* newStyle) const;
void _NotifyRerender() const;
#endif // ICON_O_MATIC #endif // ICON_O_MATIC
protected: protected:
void SetStyle(::Style* style); void SetStyle(::Style* style);
private: private:
PathContainer* fPaths; Container<VectorPath>* fPaths;
::Style* fStyle; ::Style* fStyle;
PathSource fPathSource; PathSource fPathSource;
BList fTransformers; Container<Transformer> fTransformers;
mutable bool fNeedsUpdate; mutable bool fNeedsUpdate;
mutable BRect fLastBounds; mutable BRect fLastBounds;
bool fHinting; bool fHinting;
#ifdef ICON_O_MATIC #ifdef ICON_O_MATIC
BList fListeners; BList fListeners;
#endif #endif
}; };
-228
View File
@@ -1,228 +0,0 @@
/*
* Copyright 2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
#include "ShapeContainer.h"
#include <stdio.h>
#include <string.h>
#include <OS.h>
#include "Shape.h"
#ifdef ICON_O_MATIC
// constructor
ShapeContainerListener::ShapeContainerListener()
{
}
// destructor
ShapeContainerListener::~ShapeContainerListener()
{
}
#endif // ICON_O_MATIC
// constructor
ShapeContainer::ShapeContainer()
: fShapes(16)
#ifdef ICON_O_MATIC
, fListeners(2)
#endif
{
}
// destructor
ShapeContainer::~ShapeContainer()
{
#ifdef ICON_O_MATIC
int32 count = fListeners.CountItems();
if (count > 0) {
debugger("~ShapeContainer() - there are still"
"listeners attached\n");
}
#endif // ICON_O_MATIC
_MakeEmpty();
}
// #pragma mark -
// AddShape
bool
ShapeContainer::AddShape(Shape* shape)
{
return AddShape(shape, CountShapes());
}
// AddShape
bool
ShapeContainer::AddShape(Shape* shape, int32 index)
{
if (!shape)
return false;
// prevent adding the same shape twice
if (HasShape(shape))
return false;
if (fShapes.AddItem((void*)shape, index)) {
#ifdef ICON_O_MATIC
_NotifyShapeAdded(shape, index);
#endif
return true;
}
fprintf(stderr, "ShapeContainer::AddShape() - out of memory!\n");
return false;
}
// RemoveShape
bool
ShapeContainer::RemoveShape(Shape* shape)
{
if (fShapes.RemoveItem((void*)shape)) {
#ifdef ICON_O_MATIC
_NotifyShapeRemoved(shape);
#endif
return true;
}
return false;
}
// RemoveShape
Shape*
ShapeContainer::RemoveShape(int32 index)
{
Shape* shape = (Shape*)fShapes.RemoveItem(index);
#ifdef ICON_O_MATIC
if (shape) {
_NotifyShapeRemoved(shape);
}
#endif
return shape;
}
// MakeEmpty
void
ShapeContainer::MakeEmpty()
{
_MakeEmpty();
}
// #pragma mark -
// CountShapes
int32
ShapeContainer::CountShapes() const
{
return fShapes.CountItems();
}
// HasShape
bool
ShapeContainer::HasShape(Shape* shape) const
{
return fShapes.HasItem((void*)shape);
}
// IndexOf
int32
ShapeContainer::IndexOf(Shape* shape) const
{
return fShapes.IndexOf((void*)shape);
}
// ShapeAt
Shape*
ShapeContainer::ShapeAt(int32 index) const
{
return (Shape*)fShapes.ItemAt(index);
}
// ShapeAtFast
Shape*
ShapeContainer::ShapeAtFast(int32 index) const
{
return (Shape*)fShapes.ItemAtFast(index);
}
// #pragma mark -
#ifdef ICON_O_MATIC
// AddListener
bool
ShapeContainer::AddListener(ShapeContainerListener* listener)
{
if (listener && !fListeners.HasItem((void*)listener))
return fListeners.AddItem((void*)listener);
return false;
}
// RemoveListener
bool
ShapeContainer::RemoveListener(ShapeContainerListener* listener)
{
return fListeners.RemoveItem((void*)listener);
}
#endif // ICON_O_MATIC
// #pragma mark -
// _MakeEmpty
void
ShapeContainer::_MakeEmpty()
{
int32 count = CountShapes();
for (int32 i = 0; i < count; i++) {
Shape* shape = ShapeAtFast(i);
#ifdef ICON_O_MATIC
_NotifyShapeRemoved(shape);
shape->ReleaseReference();
#else
delete shape;
#endif
}
fShapes.MakeEmpty();
}
// #pragma mark -
#ifdef ICON_O_MATIC
// _NotifyShapeAdded
void
ShapeContainer::_NotifyShapeAdded(Shape* shape, int32 index) const
{
BList listeners(fListeners);
int32 count = listeners.CountItems();
for (int32 i = 0; i < count; i++) {
ShapeContainerListener* listener
= (ShapeContainerListener*)listeners.ItemAtFast(i);
listener->ShapeAdded(shape, index);
}
}
// _NotifyShapeRemoved
void
ShapeContainer::_NotifyShapeRemoved(Shape* shape) const
{
BList listeners(fListeners);
int32 count = listeners.CountItems();
for (int32 i = 0; i < count; i++) {
ShapeContainerListener* listener
= (ShapeContainerListener*)listeners.ItemAtFast(i);
listener->ShapeRemoved(shape);
}
}
#endif // ICON_O_MATIC
-76
View File
@@ -1,76 +0,0 @@
/*
* Copyright 2006-2007, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
#ifndef SHAPE_CONTAINER_H
#define SHAPE_CONTAINER_H
#include <List.h>
#include "IconBuild.h"
_BEGIN_ICON_NAMESPACE
class Shape;
#ifdef ICON_O_MATIC
class ShapeContainerListener {
public:
ShapeContainerListener();
virtual ~ShapeContainerListener();
virtual void ShapeAdded(Shape* shape, int32 index) = 0;
virtual void ShapeRemoved(Shape* shape) = 0;
};
#endif // ICON_O_MATIC
class ShapeContainer {
public:
ShapeContainer();
virtual ~ShapeContainer();
bool AddShape(Shape* shape);
bool AddShape(Shape* shape, int32 index);
bool RemoveShape(Shape* shape);
Shape* RemoveShape(int32 index);
void MakeEmpty();
int32 CountShapes() const;
bool HasShape(Shape* shape) const;
int32 IndexOf(Shape* shape) const;
Shape* ShapeAt(int32 index) const;
Shape* ShapeAtFast(int32 index) const;
private:
void _MakeEmpty();
BList fShapes;
#ifdef ICON_O_MATIC
public:
bool AddListener(ShapeContainerListener* listener);
bool RemoveListener(
ShapeContainerListener* listener);
private:
void _NotifyShapeAdded(Shape* shape,
int32 index) const;
void _NotifyShapeRemoved(Shape* shape) const;
BList fListeners;
#endif // ICON_O_MATIC
};
_END_ICON_NAMESPACE
#endif // SHAPE_CONTAINER_H
-222
View File
@@ -1,222 +0,0 @@
/*
* Copyright 2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
#include "StyleContainer.h"
#include <stdio.h>
#include <string.h>
#include <OS.h>
#include "Style.h"
#ifdef ICON_O_MATIC
StyleContainerListener::StyleContainerListener() {}
StyleContainerListener::~StyleContainerListener() {}
#endif
// constructor
StyleContainer::StyleContainer()
#ifdef ICON_O_MATIC
: fStyles(32),
fListeners(2)
#else
: fStyles(32)
#endif
{
}
// destructor
StyleContainer::~StyleContainer()
{
#ifdef ICON_O_MATIC
int32 count = fListeners.CountItems();
if (count > 0) {
debugger("~StyleContainer() - there are still"
"listeners attached\n");
}
#endif // ICON_O_MATIC
_MakeEmpty();
}
// #pragma mark -
// AddStyle
bool
StyleContainer::AddStyle(Style* style)
{
return AddStyle(style, CountStyles());
}
// AddStyle
bool
StyleContainer::AddStyle(Style* style, int32 index)
{
if (!style)
return false;
// prevent adding the same style twice
if (HasStyle(style))
return false;
if (fStyles.AddItem((void*)style, index)) {
#ifdef ICON_O_MATIC
_NotifyStyleAdded(style, index);
#endif
return true;
}
fprintf(stderr, "StyleContainer::AddStyle() - out of memory!\n");
return false;
}
// RemoveStyle
bool
StyleContainer::RemoveStyle(Style* style)
{
if (fStyles.RemoveItem((void*)style)) {
#ifdef ICON_O_MATIC
_NotifyStyleRemoved(style);
#endif
return true;
}
return false;
}
// RemoveStyle
Style*
StyleContainer::RemoveStyle(int32 index)
{
Style* style = (Style*)fStyles.RemoveItem(index);
if (style) {
#ifdef ICON_O_MATIC
_NotifyStyleRemoved(style);
#endif
}
return style;
}
// MakeEmpty
void
StyleContainer::MakeEmpty()
{
_MakeEmpty();
}
// #pragma mark -
// CountStyles
int32
StyleContainer::CountStyles() const
{
return fStyles.CountItems();
}
// HasStyle
bool
StyleContainer::HasStyle(Style* style) const
{
return fStyles.HasItem((void*)style);
}
// IndexOf
int32
StyleContainer::IndexOf(Style* style) const
{
return fStyles.IndexOf((void*)style);
}
// StyleAt
Style*
StyleContainer::StyleAt(int32 index) const
{
return (Style*)fStyles.ItemAt(index);
}
// StyleAtFast
Style*
StyleContainer::StyleAtFast(int32 index) const
{
return (Style*)fStyles.ItemAtFast(index);
}
// #pragma mark -
#ifdef ICON_O_MATIC
// AddListener
bool
StyleContainer::AddListener(StyleContainerListener* listener)
{
if (listener && !fListeners.HasItem((void*)listener))
return fListeners.AddItem(listener);
return false;
}
// RemoveListener
bool
StyleContainer::RemoveListener(StyleContainerListener* listener)
{
return fListeners.RemoveItem(listener);
}
#endif // ICON_O_MATIC
// #pragma mark -
// _MakeEmpty
void
StyleContainer::_MakeEmpty()
{
int32 count = CountStyles();
for (int32 i = 0; i < count; i++) {
Style* style = StyleAtFast(i);
#ifdef ICON_O_MATIC
_NotifyStyleRemoved(style);
style->ReleaseReference();
#else
delete style;
#endif
}
fStyles.MakeEmpty();
}
// #pragma mark -
#ifdef ICON_O_MATIC
// _NotifyStyleAdded
void
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, index);
}
}
// _NotifyStyleRemoved
void
StyleContainer::_NotifyStyleRemoved(Style* style) const
{
BList listeners(fListeners);
int32 count = listeners.CountItems();
for (int32 i = 0; i < count; i++) {
StyleContainerListener* listener
= (StyleContainerListener*)listeners.ItemAtFast(i);
listener->StyleRemoved(style);
}
}
#endif // ICON_O_MATIC
-75
View File
@@ -1,75 +0,0 @@
/*
* Copyright 2006-2007, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
#ifndef STYLE_MANAGER_H
#define STYLE_MANAGER_H
#include <List.h>
#include "IconBuild.h"
_BEGIN_ICON_NAMESPACE
class Style;
#ifdef ICON_O_MATIC
class StyleContainerListener {
public:
StyleContainerListener();
virtual ~StyleContainerListener();
virtual void StyleAdded(Style* style, int32 index) = 0;
virtual void StyleRemoved(Style* style) = 0;
};
#endif // ICON_O_MATIC
class StyleContainer {
public:
StyleContainer();
virtual ~StyleContainer();
bool AddStyle(Style* style);
bool AddStyle(Style* style, int32 index);
bool RemoveStyle(Style* style);
Style* RemoveStyle(int32 index);
void MakeEmpty();
int32 CountStyles() const;
bool HasStyle(Style* style) const;
int32 IndexOf(Style* style) const;
Style* StyleAt(int32 index) const;
Style* StyleAtFast(int32 index) const;
private:
BList fStyles;
void _MakeEmpty();
#ifdef ICON_O_MATIC
public:
bool AddListener(StyleContainerListener* listener);
bool RemoveListener(StyleContainerListener* listener);
private:
void _NotifyStyleAdded(Style* style,
int32 index) const;
void _NotifyStyleRemoved(Style* style) const;
BList fListeners;
#endif // ICON_O_MATIC
};
_END_ICON_NAMESPACE
#endif // STYLE_MANAGER_H
+4 -4
View File
@@ -8,11 +8,11 @@
#include "PathSource.h" #include "PathSource.h"
#include "PathContainer.h" #include "Container.h"
#include "VectorPath.h" #include "VectorPath.h"
// constructor // constructor
PathSource::PathSource(PathContainer* paths) PathSource::PathSource(Container<VectorPath>* paths)
: VertexSource() : VertexSource()
, fPaths(paths) , fPaths(paths)
, fAGGPath() , fAGGPath()
@@ -64,9 +64,9 @@ PathSource::Update(bool leavePathsOpen, double approximationScale)
{ {
fAGGPath.remove_all(); fAGGPath.remove_all();
int32 count = fPaths->CountPaths(); int32 count = fPaths->CountItems();
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
fPaths->PathAtFast(i)->GetAGGPathStorage(fAGGPath); fPaths->ItemAtFast(i)->GetAGGPathStorage(fAGGPath);
if (!leavePathsOpen) if (!leavePathsOpen)
fAGGPath.close_polygon(); fAGGPath.close_polygon();
} }
+15 -15
View File
@@ -19,7 +19,7 @@
_BEGIN_ICON_NAMESPACE _BEGIN_ICON_NAMESPACE
class PathContainer; template <class Type> class Container;
class VectorPath; class VectorPath;
typedef agg::path_storage AGGPath; typedef agg::path_storage AGGPath;
@@ -27,28 +27,28 @@ typedef agg::conv_curve<AGGPath> AGGCurvedPath;
class PathSource : public VertexSource { class PathSource : public VertexSource {
public: public:
PathSource(PathContainer* paths); PathSource(Container<VectorPath>* paths);
virtual ~PathSource(); virtual ~PathSource();
virtual void rewind(unsigned path_id); virtual void rewind(unsigned path_id);
virtual unsigned vertex(double* x, double* y); virtual unsigned vertex(double* x, double* y);
virtual bool WantsOpenPaths() const; virtual bool WantsOpenPaths() const;
virtual double ApproximationScale() const; virtual double ApproximationScale() const;
// PathSource // PathSource
void Update(bool leavePathsOpen, void Update(bool leavePathsOpen,
double approximationScale); double approximationScale);
void SetGlobalScale(double scale); void SetGlobalScale(double scale);
private: private:
PathContainer* fPaths; Container<VectorPath>* fPaths;
AGGPath fAGGPath; AGGPath fAGGPath;
AGGCurvedPath fAGGCurvedPath; AGGCurvedPath fAGGCurvedPath;
double fGlobalScale; double fGlobalScale;
double fLastTransformerScale; double fLastTransformerScale;
}; };