From 8d6b4788b9c5b21998974fbef25122c8608cab47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 27 Jul 2009 13:41:17 +0000 Subject: [PATCH] * Implemented rotating path point indices. * Improved menu items in Path list view. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31805 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/icon-o-matic/Jamfile | 1 + src/apps/icon-o-matic/gui/PathListView.cpp | 82 +++++++++++------- src/apps/icon-o-matic/gui/PathListView.h | 3 +- .../commands/RotatePathIndicesCommand.cpp | 83 +++++++++++++++++++ .../shape/commands/RotatePathIndicesCommand.h | 29 +++++++ 5 files changed, 167 insertions(+), 31 deletions(-) create mode 100644 src/apps/icon-o-matic/shape/commands/RotatePathIndicesCommand.cpp create mode 100644 src/apps/icon-o-matic/shape/commands/RotatePathIndicesCommand.h diff --git a/src/apps/icon-o-matic/Jamfile b/src/apps/icon-o-matic/Jamfile index 5858a889e8..66c3fd38de 100644 --- a/src/apps/icon-o-matic/Jamfile +++ b/src/apps/icon-o-matic/Jamfile @@ -267,6 +267,7 @@ Application Icon-O-Matic : RemoveShapesCommand.cpp RemoveTransformersCommand.cpp ReversePathCommand.cpp + RotatePathIndicesCommand.cpp SplitPointsCommand.cpp TransformPointsCommand.cpp UnassignPathCommand.cpp diff --git a/src/apps/icon-o-matic/gui/PathListView.cpp b/src/apps/icon-o-matic/gui/PathListView.cpp index 639aaf0230..eb24459ef1 100644 --- a/src/apps/icon-o-matic/gui/PathListView.cpp +++ b/src/apps/icon-o-matic/gui/PathListView.cpp @@ -26,6 +26,7 @@ #include "Observer.h" #include "RemovePathsCommand.h" #include "ReversePathCommand.h" +#include "RotatePathIndicesCommand.h" #include "Shape.h" #include "ShapeContainer.h" #include "Selection.h" @@ -231,19 +232,20 @@ class ShapePathListener : public PathContainerListener, // #pragma mark - enum { - MSG_ADD = 'addp', + MSG_ADD = 'addp', - MSG_ADD_RECT = 'addr', - MSG_ADD_CIRCLE = 'addc', - MSG_ADD_ARC = 'adda', + MSG_ADD_RECT = 'addr', + MSG_ADD_CIRCLE = 'addc', + MSG_ADD_ARC = 'adda', - MSG_DUPLICATE = 'dupp', + MSG_DUPLICATE = 'dupp', - MSG_REVERSE = 'rvrs', - MSG_CLEAN_UP = 'clup', - MSG_ROTATE_INDICES = 'roti', + MSG_REVERSE = 'rvrs', + MSG_CLEAN_UP = 'clup', + MSG_ROTATE_INDICES_CW = 'ricw', + MSG_ROTATE_INDICES_CCW = 'ricc', - MSG_REMOVE = 'remp', + MSG_REMOVE = 'remp', }; // constructor @@ -347,7 +349,7 @@ PathListView::MessageReceived(BMessage* message) { switch (message->what) { case MSG_ADD: - if (fCommandStack) { + if (fCommandStack != NULL) { VectorPath* path; AddPathsCommand* command; new_path(fPathContainer, &path, &command); @@ -356,11 +358,11 @@ PathListView::MessageReceived(BMessage* message) break; case MSG_ADD_RECT: - if (fCommandStack) { + if (fCommandStack != NULL) { VectorPath* path; AddPathsCommand* command; new_path(fPathContainer, &path, &command); - if (path) { + if (path != NULL) { path->AddPoint(BPoint(16, 16)); path->AddPoint(BPoint(16, 48)); path->AddPoint(BPoint(48, 48)); @@ -373,11 +375,11 @@ PathListView::MessageReceived(BMessage* message) case MSG_ADD_CIRCLE: // TODO: ask for number of secions - if (fCommandStack) { + if (fCommandStack != NULL) { VectorPath* path; AddPathsCommand* command; new_path(fPathContainer, &path, &command); - if (path) { + if (path != NULL) { // add four control points defining a circle: // a // b d @@ -409,10 +411,10 @@ PathListView::MessageReceived(BMessage* message) break; case MSG_DUPLICATE: - if (fCommandStack) { + if (fCommandStack != NULL) { PathListItem* item = dynamic_cast( ItemAt(CurrentSelection(0))); - if (!item) + if (item == NULL) break; VectorPath* path; @@ -423,10 +425,10 @@ PathListView::MessageReceived(BMessage* message) break; case MSG_REVERSE: - if (fCommandStack) { + if (fCommandStack != NULL) { PathListItem* item = dynamic_cast( ItemAt(CurrentSelection(0))); - if (!item) + if (item == NULL) break; ReversePathCommand* command @@ -436,10 +438,10 @@ PathListView::MessageReceived(BMessage* message) break; case MSG_CLEAN_UP: - if (fCommandStack) { + if (fCommandStack != NULL) { PathListItem* item = dynamic_cast( ItemAt(CurrentSelection(0))); - if (!item) + if (item == NULL) break; CleanUpPathCommand* command @@ -448,6 +450,21 @@ PathListView::MessageReceived(BMessage* message) } break; + case MSG_ROTATE_INDICES_CW: + case MSG_ROTATE_INDICES_CCW: + if (fCommandStack != NULL) { + PathListItem* item = dynamic_cast( + ItemAt(CurrentSelection(0))); + if (item == NULL) + break; + + RotatePathIndicesCommand* command + = new (nothrow) RotatePathIndicesCommand(item->path, + message->what == MSG_ROTATE_INDICES_CW); + fCommandStack->Perform(command); + } + break; + case MSG_REMOVE: RemoveSelected(); break; @@ -708,34 +725,39 @@ void PathListView::SetMenu(BMenu* menu) { fMenu = menu; - if (!fMenu) + if (fMenu == NULL) return; fAddMI = new BMenuItem("Add", new BMessage(MSG_ADD)); fAddRectMI = new BMenuItem("Add Rect", new BMessage(MSG_ADD_RECT)); - fAddCircleMI = new BMenuItem("Add Circle"B_UTF8_ELLIPSIS, - new BMessage(MSG_ADD_CIRCLE)); - fAddArcMI = new BMenuItem("Add Arc"B_UTF8_ELLIPSIS, - new BMessage(MSG_ADD_ARC)); + fAddCircleMI = new BMenuItem("Add Circle"/*B_UTF8_ELLIPSIS*/, + new BMessage(MSG_ADD_CIRCLE)); +// fAddArcMI = new BMenuItem("Add Arc"B_UTF8_ELLIPSIS, +// new BMessage(MSG_ADD_ARC)); fDuplicateMI = new BMenuItem("Duplicate", new BMessage(MSG_DUPLICATE)); fReverseMI = new BMenuItem("Reverse", new BMessage(MSG_REVERSE)); fCleanUpMI = new BMenuItem("Clean Up", new BMessage(MSG_CLEAN_UP)); - fRotateIndicesMI = new BMenuItem("Rotate Indices", - new BMessage(MSG_ROTATE_INDICES)); + fRotateIndicesLeftMI = new BMenuItem("Rotate Indices Left", + new BMessage(MSG_ROTATE_INDICES_CW), 'R'); + fRotateIndicesRightMI = new BMenuItem("Rotate Indices Right", + new BMessage(MSG_ROTATE_INDICES_CCW), 'R', B_SHIFT_KEY); fRemoveMI = new BMenuItem("Remove", new BMessage(MSG_REMOVE)); fMenu->AddItem(fAddMI); fMenu->AddItem(fAddRectMI); fMenu->AddItem(fAddCircleMI); - fMenu->AddItem(fAddArcMI); -fAddArcMI->SetEnabled(false); +// fMenu->AddItem(fAddArcMI); fMenu->AddSeparatorItem(); fMenu->AddItem(fDuplicateMI); fMenu->AddItem(fReverseMI); fMenu->AddItem(fCleanUpMI); - fMenu->AddItem(fRotateIndicesMI); + + fMenu->AddSeparatorItem(); + + fMenu->AddItem(fRotateIndicesLeftMI); + fMenu->AddItem(fRotateIndicesRightMI); fMenu->AddSeparatorItem(); diff --git a/src/apps/icon-o-matic/gui/PathListView.h b/src/apps/icon-o-matic/gui/PathListView.h index 44ebb2d462..db3c3f68e6 100644 --- a/src/apps/icon-o-matic/gui/PathListView.h +++ b/src/apps/icon-o-matic/gui/PathListView.h @@ -95,7 +95,8 @@ class PathListView : public SimpleListView, BMenuItem* fDuplicateMI; BMenuItem* fReverseMI; BMenuItem* fCleanUpMI; - BMenuItem* fRotateIndicesMI; + BMenuItem* fRotateIndicesLeftMI; + BMenuItem* fRotateIndicesRightMI; BMenuItem* fRemoveMI; PathContainer* fPathContainer; diff --git a/src/apps/icon-o-matic/shape/commands/RotatePathIndicesCommand.cpp b/src/apps/icon-o-matic/shape/commands/RotatePathIndicesCommand.cpp new file mode 100644 index 0000000000..252e44cf36 --- /dev/null +++ b/src/apps/icon-o-matic/shape/commands/RotatePathIndicesCommand.cpp @@ -0,0 +1,83 @@ +/* + * Copyright 2009, Stephan Aßmus . All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#include "RotatePathIndicesCommand.h" + +#include + +#include "VectorPath.h" + + +RotatePathIndicesCommand::RotatePathIndicesCommand(VectorPath* path, + bool clockWise) + : + PathCommand(path), + fClockWise(clockWise) +{ +} + + +RotatePathIndicesCommand::~RotatePathIndicesCommand() +{ +} + + +status_t +RotatePathIndicesCommand::InitCheck() +{ + status_t ret = PathCommand::InitCheck(); + if (ret == B_OK && fPath->CountPoints() < 2) + return B_NOT_SUPPORTED; + return ret; +} + + +status_t +RotatePathIndicesCommand::Perform() +{ + return _Rotate(fClockWise); +} + + +status_t +RotatePathIndicesCommand::Undo() +{ + return _Rotate(!fClockWise); +} + + +void +RotatePathIndicesCommand::GetName(BString& name) +{ + name << "Rotate Path Indices"; +} + + +status_t +RotatePathIndicesCommand::_Rotate(bool clockWise) +{ + BPoint point; + BPoint pointIn; + BPoint pointOut; + bool connected; + + int32 removeIndex; + int32 addIndex; + if (!clockWise) { + removeIndex = fPath->CountPoints() - 1; + addIndex = 0; + } else { + removeIndex = 0; + addIndex = fPath->CountPoints() - 1; + } + + if (!fPath->GetPointsAt(removeIndex, point, pointIn, pointOut, &connected)) + return B_ERROR; + + fPath->RemovePoint(removeIndex); + fPath->AddPoint(point, addIndex); + fPath->SetPoint(addIndex, point, pointIn, pointOut, connected); +} + diff --git a/src/apps/icon-o-matic/shape/commands/RotatePathIndicesCommand.h b/src/apps/icon-o-matic/shape/commands/RotatePathIndicesCommand.h new file mode 100644 index 0000000000..78f4f55fb5 --- /dev/null +++ b/src/apps/icon-o-matic/shape/commands/RotatePathIndicesCommand.h @@ -0,0 +1,29 @@ +/* + * Copyright 2009, Stephan Aßmus . All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef ROTATE_PATH_INDICES_COMMAND_H +#define ROTATE_PATH_INDICES_COMMAND_H + +#include "PathCommand.h" + +class RotatePathIndicesCommand : public PathCommand { +public: + RotatePathIndicesCommand(VectorPath* path, + bool clockWise); + virtual ~RotatePathIndicesCommand(); + + virtual status_t InitCheck(); + + virtual status_t Perform(); + virtual status_t Undo(); + + virtual void GetName(BString& name); + +private: + status_t _Rotate(bool clockWise); + + bool fClockWise; +}; + +#endif // ROTATE_PATH_INDICES_COMMAND_H