diff --git a/src/apps/icon-o-matic/CanvasView.cpp b/src/apps/icon-o-matic/CanvasView.cpp index cfa54b6d52..c2ddd0a63a 100644 --- a/src/apps/icon-o-matic/CanvasView.cpp +++ b/src/apps/icon-o-matic/CanvasView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -9,10 +9,14 @@ #include "CanvasView.h" #include +#include +#include #include +#include #include +#include "cursors.h" #include "ui_defines.h" #include "CommandStack.h" @@ -33,6 +37,10 @@ CanvasView::CanvasView(BRect frame) fCanvasOrigin(0.0, 0.0), fZoomLevel(1.0), + fSpaceHeldDown(false), + fScrollTracking(false), + fScrollTrackingStart(0.0, 0.0), + fMouseFilterMode(SNAPPING_OFF), fOffsreenBitmap(NULL), @@ -136,7 +144,66 @@ CanvasView::MouseDown(BPoint where) if (!IsFocus()) MakeFocus(true); - StateView::MouseDown(where); + uint32 buttons; + if (Window()->CurrentMessage()->FindInt32("buttons", + (int32*)&buttons) < B_OK) + buttons = 0; + + // handle clicks of the third mouse button ourselves (panning), + // otherwise have StateView handle it (normal clicks) + if (fSpaceHeldDown || buttons & B_TERTIARY_MOUSE_BUTTON) { + // switch into scrolling mode and update cursor + fScrollTracking = true; + where.x = roundf(where.x); + where.y = roundf(where.y); + fScrollOffsetStart = ScrollOffset(); + fScrollTrackingStart = where - fScrollOffsetStart; + _UpdateToolCursor(); + SetMouseEventMask(B_POINTER_EVENTS, + B_LOCK_WINDOW_FOCUS | B_SUSPEND_VIEW_FOCUS); + } else { + StateView::MouseDown(where); + } +} + +// MouseUp +void +CanvasView::MouseUp(BPoint where) +{ + if (fScrollTracking) { + // stop scroll tracking and update cursor + fScrollTracking = false; + _UpdateToolCursor(); + // update StateView mouse position + uint32 transit = Bounds().Contains(where) ? + B_INSIDE_VIEW : B_OUTSIDE_VIEW; + StateView::MouseMoved(where, transit, NULL); + } else { + StateView::MouseUp(where); + } +} + +// MouseMoved +void +CanvasView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) +{ + if (fScrollTracking) { + uint32 buttons; + GetMouse(&where, &buttons, false); + if (!buttons) { + MouseUp(where); + return; + } + where.x = roundf(where.x); + where.y = roundf(where.y); + where -= ScrollOffset(); + BPoint offset = where - fScrollTrackingStart; + SetScrollOffset(fScrollOffsetStart - offset); + } else { + // normal mouse movement handled by StateView + if (!fSpaceHeldDown) + StateView::MouseMoved(where, transit, dragMessage); + } } // FilterMouse @@ -180,6 +247,23 @@ CanvasView::FilterMouse(BPoint* where) const } } +// MouseWheelChanged +bool +CanvasView::MouseWheelChanged(BPoint where, float x, float y) +{ + if (!Bounds().Contains(where)) + return false; + + if (y > 0.0) { + _SetZoom(_NextZoomOutLevel(fZoomLevel)); + return true; + } else if (y < 0.0) { + _SetZoom(_NextZoomInLevel(fZoomLevel)); + return true; + } + return false; +} + // #pragma mark - // ScrollOffsetChanged @@ -187,9 +271,15 @@ void CanvasView::ScrollOffsetChanged(BPoint oldOffset, BPoint newOffset) { BPoint offset = newOffset - oldOffset; + + if (offset == B_ORIGIN) + // prevent circular code (MouseMoved might call ScrollBy...) + return; + ScrollBy(offset.x, offset.y); - MouseMoved(fMouseInfo.position + offset, fMouseInfo.transit, NULL); + if (!fScrollTracking) + MouseMoved(fMouseInfo.position + offset, fMouseInfo.transit, NULL); } // VisibleSizeChanged @@ -308,6 +398,11 @@ CanvasView::_HandleKeyDown(uint32 key, uint32 modifiers) _SetZoom(_NextZoomOutLevel(fZoomLevel)); break; + case B_SPACE: + fSpaceHeldDown = true; + _UpdateToolCursor(); + break; + default: return StateView::_HandleKeyDown(key, modifiers); } @@ -315,6 +410,23 @@ CanvasView::_HandleKeyDown(uint32 key, uint32 modifiers) return true; } +// _HandleKeyUp +bool +CanvasView::_HandleKeyUp(uint32 key, uint32 modifiers) +{ + switch (key) { + case B_SPACE: + fSpaceHeldDown = false; + _UpdateToolCursor(); + break; + + default: + return StateView::_HandleKeyUp(key, modifiers); + } + + return true; +} + // _CanvasRect() BRect CanvasView::_CanvasRect() const @@ -473,6 +585,26 @@ CanvasView::_MakeBackground() } } +// _UpdateToolCursor +void +CanvasView::_UpdateToolCursor() +{ + if (fIcon) { + if (fScrollTracking || fSpaceHeldDown) { + // indicate scrolling mode + const uchar* cursorData = fScrollTracking ? kGrabCursor : kHandCursor; + BCursor cursor(cursorData); + SetViewCursor(&cursor, true); + } else { + // pass on to current state of StateView + UpdateStateCursor(); + } + } else { + BCursor cursor(kStopCursor); + SetViewCursor(&cursor, true); + } +} + // #pragma mark - // _NextZoomInLevel diff --git a/src/apps/icon-o-matic/CanvasView.h b/src/apps/icon-o-matic/CanvasView.h index 72286c5b55..f1fe7b4f60 100644 --- a/src/apps/icon-o-matic/CanvasView.h +++ b/src/apps/icon-o-matic/CanvasView.h @@ -43,8 +43,14 @@ class CanvasView : public StateView, virtual void Draw(BRect updateRect); virtual void MouseDown(BPoint where); + virtual void MouseUp(BPoint where); + virtual void MouseMoved(BPoint where, uint32 transit, + const BMessage* dragMessage); virtual void FilterMouse(BPoint* where) const; + virtual bool MouseWheelChanged(BPoint where, + float x, float y); + // Scrollable interface protected: virtual void ScrollOffsetChanged(BPoint oldOffset, @@ -76,6 +82,7 @@ class CanvasView : public StateView, protected: // StateView interface virtual bool _HandleKeyDown(uint32 key, uint32 modifiers); + virtual bool _HandleKeyUp(uint32 key, uint32 modifiers); // CanvasView BRect _CanvasRect() const; @@ -88,6 +95,8 @@ class CanvasView : public StateView, void _MakeBackground(); + void _UpdateToolCursor(); + private: double _NextZoomInLevel(double zoom) const; double _NextZoomOutLevel(double zoom) const; @@ -105,6 +114,11 @@ class CanvasView : public StateView, BPoint fCanvasOrigin; double fZoomLevel; + bool fSpaceHeldDown; + bool fScrollTracking; + BPoint fScrollTrackingStart; + BPoint fScrollOffsetStart; + uint32 fMouseFilterMode; BBitmap* fOffsreenBitmap; diff --git a/src/apps/icon-o-matic/Jamfile b/src/apps/icon-o-matic/Jamfile index ffcb055511..69e9803876 100644 --- a/src/apps/icon-o-matic/Jamfile +++ b/src/apps/icon-o-matic/Jamfile @@ -243,6 +243,7 @@ Application Icon-O-Matic : AddTransformersCommand.cpp ChangePointCommand.cpp CleanUpPathCommand.cpp + FlipPointsCommand.cpp FreezeTransformationCommand.cpp InsertPointCommand.cpp MoveShapesCommand.cpp diff --git a/src/apps/icon-o-matic/generic/command/Command.cpp b/src/apps/icon-o-matic/generic/command/Command.cpp index 87cbbf83da..5728d5142f 100644 --- a/src/apps/icon-o-matic/generic/command/Command.cpp +++ b/src/apps/icon-o-matic/generic/command/Command.cpp @@ -58,6 +58,13 @@ Command::GetName(BString& name) name << "Name of action goes here."; } +// UndoesPrevious +bool +Command::UndoesPrevious(const Command* previous) +{ + return false; +} + // CombineWithNext bool Command::CombineWithNext(const Command* next) diff --git a/src/apps/icon-o-matic/generic/command/Command.h b/src/apps/icon-o-matic/generic/command/Command.h index 6f907c4a6e..d43c19dc8a 100644 --- a/src/apps/icon-o-matic/generic/command/Command.h +++ b/src/apps/icon-o-matic/generic/command/Command.h @@ -27,6 +27,7 @@ class Command { virtual void GetName(BString& name); + virtual bool UndoesPrevious(const Command* previous); virtual bool CombineWithNext(const Command* next); virtual bool CombineWithPrevious(const Command* previous); diff --git a/src/apps/icon-o-matic/generic/command/CommandStack.cpp b/src/apps/icon-o-matic/generic/command/CommandStack.cpp index 041e1adb07..f257268916 100644 --- a/src/apps/icon-o-matic/generic/command/CommandStack.cpp +++ b/src/apps/icon-o-matic/generic/command/CommandStack.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -34,23 +34,25 @@ CommandStack::~CommandStack() status_t CommandStack::Perform(Command* command) { + if (!Lock()) + return B_ERROR; + status_t ret = command ? B_OK : B_BAD_VALUE; - if (Lock()) { - if (ret == B_OK) - ret = command->InitCheck(); - - if (ret == B_OK) - ret = command->Perform(); - - if (ret == B_OK) - ret = _AddCommand(command); - - if (ret != B_OK) { - // no one else feels responsible... - delete command; - } - Unlock(); + if (ret == B_OK) + ret = command->InitCheck(); + + if (ret == B_OK) + ret = command->Perform(); + + if (ret == B_OK) + ret = _AddCommand(command); + + if (ret != B_OK) { + // no one else feels responsible... + delete command; } + + Unlock(); return ret; } @@ -58,19 +60,20 @@ CommandStack::Perform(Command* command) status_t CommandStack::Undo() { + if (!Lock()) + return B_ERROR; + status_t status = B_ERROR; - if (Lock()) { - if (!fUndoHistory.empty()) { - Command* command = fUndoHistory.top(); - fUndoHistory.pop(); - status = command->Undo(); - if (status == B_OK) - fRedoHistory.push(command); - else - fUndoHistory.push(command); - } - Unlock(); + if (!fUndoHistory.empty()) { + Command* command = fUndoHistory.top(); + fUndoHistory.pop(); + status = command->Undo(); + if (status == B_OK) + fRedoHistory.push(command); + else + fUndoHistory.push(command); } + Unlock(); Notify(); @@ -81,19 +84,20 @@ CommandStack::Undo() status_t CommandStack::Redo() { + if (!Lock()) + return B_ERROR; + status_t status = B_ERROR; - if (Lock()) { - if (!fRedoHistory.empty()) { - Command* command = fRedoHistory.top(); - fRedoHistory.pop(); - status = command->Redo(); - if (status == B_OK) - fUndoHistory.push(command); - else - fRedoHistory.push(command); - } - Unlock(); + if (!fRedoHistory.empty()) { + Command* command = fRedoHistory.top(); + fRedoHistory.pop(); + status = command->Redo(); + if (status == B_OK) + fUndoHistory.push(command); + else + fRedoHistory.push(command); } + Unlock(); Notify(); @@ -187,29 +191,56 @@ status_t CommandStack::_AddCommand(Command* command) { status_t status = B_OK; - // try to collapse commands to a single command + bool add = true; if (!fUndoHistory.empty()) { + // try to collapse commands to a single command + // or remove this and the previous command if + // they reverse each other if (Command* top = fUndoHistory.top()) { - if (top->CombineWithNext(command)) { + if (command->UndoesPrevious(top)) { + add = false; + fUndoHistory.pop(); + delete top; + delete command; + } else if (top->CombineWithNext(command)) { add = false; delete command; + // after collapsing, the command might + // have changed it's mind about InitCheck() + // (the commands reversed each other) + if (top->InitCheck() < B_OK) { + fUndoHistory.pop(); + delete top; + } } else if (command->CombineWithPrevious(top)) { fUndoHistory.pop(); delete top; + // after collapsing, the command might + // have changed it's mind about InitCheck() + // (the commands reversed each other) + if (command->InitCheck() < B_OK) { + delete command; + add = false; + } } } } if (add) { - // TODO: check return value and set status - fUndoHistory.push(command); + try { + fUndoHistory.push(command); + } catch (...) { + status = B_ERROR; + } } - // the redo stack needs to be empty - // as soon as a command was added (also in case of collapsing) - while (!fRedoHistory.empty()) { - delete fRedoHistory.top(); - fRedoHistory.pop(); + if (status == B_OK) { + // the redo stack needs to be empty + // as soon as a command was added (also in case of collapsing) + while (!fRedoHistory.empty()) { + delete fRedoHistory.top(); + fRedoHistory.pop(); + } } Notify(); diff --git a/src/apps/icon-o-matic/generic/gui/stateview/Manipulator.cpp b/src/apps/icon-o-matic/generic/gui/stateview/Manipulator.cpp index 90a5089716..28c81bdb97 100644 --- a/src/apps/icon-o-matic/generic/gui/stateview/Manipulator.cpp +++ b/src/apps/icon-o-matic/generic/gui/stateview/Manipulator.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -106,9 +106,10 @@ Manipulator::HandleKeyUp(uint32 key, uint32 modifiers, Command** _command) } // UpdateCursor -void +bool Manipulator::UpdateCursor() { + return false; } // #pragma mark - diff --git a/src/apps/icon-o-matic/generic/gui/stateview/Manipulator.h b/src/apps/icon-o-matic/generic/gui/stateview/Manipulator.h index 3c701102c0..40b788fafb 100644 --- a/src/apps/icon-o-matic/generic/gui/stateview/Manipulator.h +++ b/src/apps/icon-o-matic/generic/gui/stateview/Manipulator.h @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -44,7 +44,7 @@ class Manipulator : public Observer { virtual bool HandleKeyUp(uint32 key, uint32 modifiers, Command** _command); - virtual void UpdateCursor(); + virtual bool UpdateCursor(); virtual BRect Bounds() = 0; // the area that the manipulator is diff --git a/src/apps/icon-o-matic/generic/gui/stateview/MultipleManipulatorState.cpp b/src/apps/icon-o-matic/generic/gui/stateview/MultipleManipulatorState.cpp index c660031854..4fa69603c2 100644 --- a/src/apps/icon-o-matic/generic/gui/stateview/MultipleManipulatorState.cpp +++ b/src/apps/icon-o-matic/generic/gui/stateview/MultipleManipulatorState.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -172,6 +172,10 @@ bool MultipleManipulatorState::HandleKeyDown(uint32 key, uint32 modifiers, Command** _command) { + // TODO: somehow this looks suspicious, because it doesn't + // seem guaranteed that the manipulator having indicated to + // handle the key down handles the matching key up event... + // maybe there should be the concept of the "focused manipulator" int32 count = fManipulators.CountItems(); for (int32 i = 0; i < count; i++) { Manipulator* manipulator = @@ -197,6 +201,15 @@ MultipleManipulatorState::HandleKeyUp(uint32 key, uint32 modifiers, return false; } +// UpdateCursor +bool +MultipleManipulatorState::UpdateCursor() +{ + if (fPreviousManipulator && fManipulators.HasItem(fPreviousManipulator)) + return fPreviousManipulator->UpdateCursor(); + return false; +} + // #pragma mark - // AddManipulator diff --git a/src/apps/icon-o-matic/generic/gui/stateview/MultipleManipulatorState.h b/src/apps/icon-o-matic/generic/gui/stateview/MultipleManipulatorState.h index b1690fe748..596b69bc97 100644 --- a/src/apps/icon-o-matic/generic/gui/stateview/MultipleManipulatorState.h +++ b/src/apps/icon-o-matic/generic/gui/stateview/MultipleManipulatorState.h @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -44,6 +44,8 @@ class MultipleManipulatorState : public ViewState { virtual bool HandleKeyUp(uint32 key, uint32 modifiers, Command** _command); + virtual bool UpdateCursor(); + // MultipleManipulatorState bool AddManipulator(Manipulator* manipulator); Manipulator* RemoveManipulator(int32 index); diff --git a/src/apps/icon-o-matic/generic/gui/stateview/StateView.cpp b/src/apps/icon-o-matic/generic/gui/stateview/StateView.cpp index 657173c709..09d185a933 100644 --- a/src/apps/icon-o-matic/generic/gui/stateview/StateView.cpp +++ b/src/apps/icon-o-matic/generic/gui/stateview/StateView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -78,7 +78,8 @@ if (dynamic_cast(*target)) float y; if (message->FindFloat("be:wheel_delta_x", &x) >= B_OK && message->FindFloat("be:wheel_delta_y", &y) >= B_OK) { - if (fTarget->MouseWheelChanged(x, y)) + if (fTarget->MouseWheelChanged( + fTarget->MouseInfo()->position, x, y)) result = B_SKIP_MESSAGE; } break; @@ -330,6 +331,15 @@ StateView::SetState(ViewState* state) fCurrentState->Init(); } +// UpdateStateCursor +void +StateView::UpdateStateCursor() +{ + if (!fCurrentState || !fCurrentState->UpdateCursor()) { + SetViewCursor(B_CURSOR_SYSTEM_DEFAULT, true); + } +} + // Draw void StateView::Draw(BView* into, BRect updateRect) @@ -350,7 +360,7 @@ StateView::Draw(BView* into, BRect updateRect) // MouseWheelChanged bool -StateView::MouseWheelChanged(float x, float y) +StateView::MouseWheelChanged(BPoint where, float x, float y) { return false; } @@ -359,6 +369,11 @@ StateView::MouseWheelChanged(float x, float y) bool StateView::HandleKeyDown(uint32 key, uint32 modifiers) { + // down't allow key events if mouse already pressed + // (central place to prevent command stack mix up) + if (fMouseInfo.buttons != 0) + return false; + AutoWriteLocker locker(fLocker); if (fLocker && !locker.IsLocked()) return false; @@ -380,6 +395,11 @@ StateView::HandleKeyDown(uint32 key, uint32 modifiers) bool StateView::HandleKeyUp(uint32 key, uint32 modifiers) { + // down't allow key events if mouse already pressed + // (central place to prevent command stack mix up) + if (fMouseInfo.buttons != 0) + return false; + AutoWriteLocker locker(fLocker); if (fLocker && !locker.IsLocked()) return false; diff --git a/src/apps/icon-o-matic/generic/gui/stateview/StateView.h b/src/apps/icon-o-matic/generic/gui/stateview/StateView.h index 25975c2957..6103c43a31 100644 --- a/src/apps/icon-o-matic/generic/gui/stateview/StateView.h +++ b/src/apps/icon-o-matic/generic/gui/stateview/StateView.h @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -40,10 +40,12 @@ class StateView : public BView { // StateView interface void SetState(ViewState* state); + void UpdateStateCursor(); void Draw(BView* into, BRect updateRect); - virtual bool MouseWheelChanged(float x, float y); + virtual bool MouseWheelChanged(BPoint where, + float x, float y); bool HandleKeyDown(uint32 key, uint32 modifiers); bool HandleKeyUp(uint32 key, uint32 modifiers); diff --git a/src/apps/icon-o-matic/generic/gui/stateview/ViewState.cpp b/src/apps/icon-o-matic/generic/gui/stateview/ViewState.cpp index 8e293a2b1c..ff94b4e6e0 100644 --- a/src/apps/icon-o-matic/generic/gui/stateview/ViewState.cpp +++ b/src/apps/icon-o-matic/generic/gui/stateview/ViewState.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -109,4 +109,9 @@ ViewState::HandleKeyUp(uint32 key, uint32 modifiers, Command** _command) return false; } - +// UpdateCursor +bool +ViewState::UpdateCursor() +{ + return false; +} diff --git a/src/apps/icon-o-matic/generic/gui/stateview/ViewState.h b/src/apps/icon-o-matic/generic/gui/stateview/ViewState.h index 814b9ce6fc..c12f3ad20d 100644 --- a/src/apps/icon-o-matic/generic/gui/stateview/ViewState.h +++ b/src/apps/icon-o-matic/generic/gui/stateview/ViewState.h @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -57,6 +57,8 @@ class ViewState { virtual bool HandleKeyUp(uint32 key, uint32 modifiers, Command** _command); + virtual bool UpdateCursor(); + inline uint32 PressedMouseButtons() const { return fMouseInfo->buttons; } diff --git a/src/apps/icon-o-matic/generic/gui/ui_defines.h b/src/apps/icon-o-matic/generic/gui/ui_defines.h index 68bd131149..7ce0382942 100644 --- a/src/apps/icon-o-matic/generic/gui/ui_defines.h +++ b/src/apps/icon-o-matic/generic/gui/ui_defines.h @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: diff --git a/src/apps/icon-o-matic/import_export/svg/DocumentBuilder.h b/src/apps/icon-o-matic/import_export/svg/DocumentBuilder.h index c96b97aa78..28b33bd324 100644 --- a/src/apps/icon-o-matic/import_export/svg/DocumentBuilder.h +++ b/src/apps/icon-o-matic/import_export/svg/DocumentBuilder.h @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. All rights reserved. + * Copyright 2006-2007, Haiku. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: diff --git a/src/apps/icon-o-matic/shape/PathManipulator.cpp b/src/apps/icon-o-matic/shape/PathManipulator.cpp index 3725a10c59..ffe1b9944b 100644 --- a/src/apps/icon-o-matic/shape/PathManipulator.cpp +++ b/src/apps/icon-o-matic/shape/PathManipulator.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -26,6 +26,7 @@ #include "ChangePointCommand.h" //#include "CloseCommand.h" #include "InsertPointCommand.h" +#include "FlipPointsCommand.h" //#include "NewPathCommand.h" #include "NudgePointsCommand.h" //#include "RemovePathCommand.h" @@ -74,6 +75,7 @@ enum { MSG_UPDATE_SHAPE_UI = 'udsi', MSG_SPLIT_POINTS = 'splt', + MSG_FLIP_POINTS = 'flip', }; inline const char* @@ -773,6 +775,11 @@ PathManipulator::ShowContextMenu(BPoint where) item->SetEnabled(hasSelection); menu->AddItem(item); + message = new BMessage(MSG_FLIP_POINTS); + item = new BMenuItem("Flip", message); + item->SetEnabled(hasSelection); + menu->AddItem(item); + message = new BMessage(MSG_REMOVE_POINTS); item = new BMenuItem("Remove", message, 'A'); item->SetEnabled(hasSelection); @@ -829,6 +836,11 @@ PathManipulator::MessageReceived(BMessage* message, Command** _command) fSelection->Items(), fSelection->CountItems()); break; + case MSG_FLIP_POINTS: + *_command = new FlipPointsCommand(fPath, + fSelection->Items(), + fSelection->CountItems()); + break; case B_SELECT_ALL: { *fOldSelection = *fSelection; fSelection->MakeEmpty(); @@ -958,13 +970,12 @@ PathManipulator::HandleKeyUp(uint32 key, uint32 modifiers, Command** _command) } // UpdateCursor -void +bool PathManipulator::UpdateCursor() { - if (fTransformBox) { - fTransformBox->UpdateCursor(); - return; - } + if (fTransformBox) + return fTransformBox->UpdateCursor(); + const uchar* cursorData; switch (fMode) { case ADD_POINT: @@ -1008,6 +1019,8 @@ PathManipulator::UpdateCursor() BCursor cursor(cursorData); fCanvasView->SetViewCursor(&cursor, true); fCanvasView->Sync(); + + return true; } // AttachedToView diff --git a/src/apps/icon-o-matic/shape/PathManipulator.h b/src/apps/icon-o-matic/shape/PathManipulator.h index ae3a7a9076..af00b8fca1 100644 --- a/src/apps/icon-o-matic/shape/PathManipulator.h +++ b/src/apps/icon-o-matic/shape/PathManipulator.h @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -59,7 +59,7 @@ class PathManipulator : public Manipulator, virtual bool HandleKeyUp(uint32 key, uint32 modifiers, Command** _command); - virtual void UpdateCursor(); + virtual bool UpdateCursor(); virtual void AttachedToView(BView* view); virtual void DetachedFromView(BView* view); diff --git a/src/apps/icon-o-matic/shape/commands/ChangePointCommand.cpp b/src/apps/icon-o-matic/shape/commands/ChangePointCommand.cpp index dbf5b64f1e..e684ca8425 100644 --- a/src/apps/icon-o-matic/shape/commands/ChangePointCommand.cpp +++ b/src/apps/icon-o-matic/shape/commands/ChangePointCommand.cpp @@ -39,6 +39,32 @@ ChangePointCommand::~ChangePointCommand() delete[] fOldSelection; } +// InitCheck +status_t +ChangePointCommand::InitCheck() +{ + // TODO: figure out if selection changed!!! + // (this command is also used to undo changes to the selection) + // (but tracking the selection does not yet work in Icon-O-Matic) + + status_t ret = PathCommand::InitCheck(); + if (ret < B_OK) + return ret; + + BPoint point; + BPoint pointIn; + BPoint pointOut; + bool connected; + if (!fPath->GetPointsAt(fIndex, point, pointIn, pointOut, &connected)) + return B_ERROR; + + if (point != fPoint || pointIn != fPointIn + || pointOut != fPointOut || connected != fConnected) + return B_OK; + + return B_ERROR; +} + // Perform status_t ChangePointCommand::Perform() diff --git a/src/apps/icon-o-matic/shape/commands/ChangePointCommand.h b/src/apps/icon-o-matic/shape/commands/ChangePointCommand.h index 0dc5ebcd20..1d348c0e18 100644 --- a/src/apps/icon-o-matic/shape/commands/ChangePointCommand.h +++ b/src/apps/icon-o-matic/shape/commands/ChangePointCommand.h @@ -21,6 +21,8 @@ class ChangePointCommand : public PathCommand { int32 count); virtual ~ChangePointCommand(); + virtual status_t InitCheck(); + virtual status_t Perform(); virtual status_t Undo(); virtual status_t Redo(); diff --git a/src/apps/icon-o-matic/transformable/ResetTransformationCommand.h b/src/apps/icon-o-matic/transformable/ResetTransformationCommand.h index 9d3aa4a8ee..788ec480e7 100644 --- a/src/apps/icon-o-matic/transformable/ResetTransformationCommand.h +++ b/src/apps/icon-o-matic/transformable/ResetTransformationCommand.h @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. All rights reserved. + * Copyright 2006-2007, Haiku. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: diff --git a/src/apps/icon-o-matic/transformable/TransformBox.cpp b/src/apps/icon-o-matic/transformable/TransformBox.cpp index 9504c599e7..391dca0082 100644 --- a/src/apps/icon-o-matic/transformable/TransformBox.cpp +++ b/src/apps/icon-o-matic/transformable/TransformBox.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -299,16 +299,19 @@ TransformBox::HandleKeyUp(uint32 key, uint32 modifiers, Command** _command) return false; } -// #pragma mark - - // UpdateCursor -void +bool TransformBox::UpdateCursor() { - if (fCurrentState) + if (fCurrentState) { fCurrentState->UpdateViewCursor(fView, fMousePos); + return true; + } + return false; } +// #pragma mark - + // AttachedToView void TransformBox::AttachedToView(BView* view) diff --git a/src/apps/icon-o-matic/transformable/TransformBox.h b/src/apps/icon-o-matic/transformable/TransformBox.h index f46976e8b7..140c3c9a49 100644 --- a/src/apps/icon-o-matic/transformable/TransformBox.h +++ b/src/apps/icon-o-matic/transformable/TransformBox.h @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -54,7 +54,7 @@ class TransformBox : public ChannelTransform, virtual bool HandleKeyUp(uint32 key, uint32 modifiers, Command** _command); - virtual void UpdateCursor(); + virtual bool UpdateCursor(); virtual void AttachedToView(BView* view); virtual void DetachedFromView(BView* view); diff --git a/src/apps/icon-o-matic/transformable/TransformCommand.cpp b/src/apps/icon-o-matic/transformable/TransformCommand.cpp index d2a518bedb..f4fe01deb6 100644 --- a/src/apps/icon-o-matic/transformable/TransformCommand.cpp +++ b/src/apps/icon-o-matic/transformable/TransformCommand.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2007, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -72,8 +72,8 @@ TransformCommand::InitCheck() || fNewXScale != fOldXScale || fNewYScale != fOldYScale)) return B_OK; - else - return B_NO_INIT; + + return B_NO_INIT; } // Perform @@ -88,30 +88,24 @@ TransformCommand::Perform() status_t TransformCommand::Undo() { - status_t status = InitCheck(); - if (status >= B_OK) { - _SetTransformation(fOldPivot, - fOldTranslation, - fOldRotation, - fOldXScale, - fOldYScale); - } - return status; + _SetTransformation(fOldPivot, + fOldTranslation, + fOldRotation, + fOldXScale, + fOldYScale); + return B_OK; } // Redo status_t TransformCommand::Redo() { - status_t status = InitCheck(); - if (status >= B_OK) { - _SetTransformation(fNewPivot, - fNewTranslation, - fNewRotation, - fNewXScale, - fNewYScale); - } - return status; + _SetTransformation(fNewPivot, + fNewTranslation, + fNewRotation, + fNewXScale, + fNewYScale); + return B_OK; } // GetName diff --git a/src/apps/icon-o-matic/transformable/TransformObjectsCommand.h b/src/apps/icon-o-matic/transformable/TransformObjectsCommand.h index 8f1e2756f1..150ad077cb 100644 --- a/src/apps/icon-o-matic/transformable/TransformObjectsCommand.h +++ b/src/apps/icon-o-matic/transformable/TransformObjectsCommand.h @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007, Haiku. + * Copyright 2006-2007, Haiku. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: