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