btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / icon-o-matic / shape / commands / FlipPointsCommand.cpp
blob9226916b9d70dbea3e0ae56d7328c75f744cb89f
1 /*
2 * Copyright 2007, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Stephan Aßmus <superstippi@gmx.de>
7 */
9 #include "FlipPointsCommand.h"
11 #include <new>
12 #include <stdio.h>
14 #include <Catalog.h>
15 #include <Locale.h>
17 #include "VectorPath.h"
20 #undef B_TRANSLATION_CONTEXT
21 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-FlipPointsCmd"
24 using std::nothrow;
26 // constructor
27 FlipPointsCommand::FlipPointsCommand(VectorPath* path,
28 const int32* indices,
29 int32 count)
30 : PathCommand(path),
31 fIndex(NULL),
32 fCount(0)
34 if (indices && count > 0) {
35 fIndex = new (nothrow) int32[count];
36 fCount = count;
39 if (InitCheck() < B_OK)
40 return;
42 memcpy(fIndex, indices, count * sizeof(int32));
45 // destructor
46 FlipPointsCommand::~FlipPointsCommand()
48 delete[] fIndex;
51 // InitCheck
52 status_t
53 FlipPointsCommand::InitCheck()
55 status_t status = PathCommand::InitCheck();
56 if (status < B_OK)
57 return status;
58 if (!fIndex)
59 status = B_NO_MEMORY;
60 return status;
63 // Perform
64 status_t
65 FlipPointsCommand::Perform()
67 status_t status = B_OK;
69 AutoNotificationSuspender _(fPath);
71 // NOTE: fCount guaranteed > 0
72 for (int32 i = 0; i < fCount; i++) {
73 BPoint point;
74 BPoint pointIn;
75 BPoint pointOut;
76 bool connected;
78 if (fPath->GetPointsAt(fIndex[i], point, pointIn, pointOut, &connected)) {
79 BPoint p1(point - (pointOut - point));
80 printf("flip: (%.1f, %.1f) -> (%.1f, %.1f)\n", pointOut.x, pointOut.y, p1.x, p1.y);
81 // flip "in" and "out" control points
82 fPath->SetPoint(fIndex[i],
83 point,
84 point - (pointIn - point),
85 point - (pointOut - point),
86 connected);
87 } else {
88 status = B_ERROR;
89 break;
93 return status;
96 // Undo
97 status_t
98 FlipPointsCommand::Undo()
100 status_t status = Perform();
102 if (status >= B_OK) {
103 // restore selection
104 _Select(fIndex, fCount);
107 return status;
110 // GetName
111 void
112 FlipPointsCommand::GetName(BString& name)
114 if (fCount > 1)
115 name << B_TRANSLATE("Flip Control Points");
116 else
117 name << B_TRANSLATE("Flip Control Point");