mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 21:06:59 -04:00
Switched to a new coding style, which plays nicely with the Reader/Writer. This new style allows REFLECT to be used instead of REFLECT_N in most places.
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@15 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+37
-37
@@ -23,15 +23,15 @@ SymbolPartMoveAction::SymbolPartMoveAction(const set<SymbolPartP>& parts)
|
||||
, constrain(false)
|
||||
{}
|
||||
|
||||
String SymbolPartMoveAction::getName(bool toUndo) const {
|
||||
String SymbolPartMoveAction::getName(bool to_undo) const {
|
||||
return parts.size() == 1 ? _("Move shape") : _("Move shapes");
|
||||
}
|
||||
|
||||
void SymbolPartMoveAction::perform(bool toUndo) {
|
||||
void SymbolPartMoveAction::perform(bool to_undo) {
|
||||
// move the points back
|
||||
FOR_EACH(p, parts) {
|
||||
p->minPos -= moved;
|
||||
p->maxPos -= moved;
|
||||
p->min_pos -= moved;
|
||||
p->max_pos -= moved;
|
||||
FOR_EACH(pnt, p->points) {
|
||||
pnt->pos -= moved;
|
||||
}
|
||||
@@ -45,8 +45,8 @@ void SymbolPartMoveAction::move(const Vector2D& deltaDelta) {
|
||||
Vector2D d = constrainVector(delta, constrain);
|
||||
Vector2D dd = d - moved;
|
||||
FOR_EACH(p, parts) {
|
||||
p->minPos += dd;
|
||||
p->maxPos += dd;
|
||||
p->min_pos += dd;
|
||||
p->max_pos += dd;
|
||||
FOR_EACH(pnt, p->points) {
|
||||
pnt->pos += dd;
|
||||
}
|
||||
@@ -66,8 +66,8 @@ void SymbolPartMatrixAction::transform(const Vector2D& mx, const Vector2D& my) {
|
||||
FOR_EACH(p, parts) {
|
||||
FOR_EACH(pnt, p->points) {
|
||||
pnt->pos = (pnt->pos - center).mul(mx,my) + center;
|
||||
pnt->deltaBefore = pnt->deltaBefore.mul(mx,my);
|
||||
pnt->deltaAfter = pnt->deltaAfter .mul(mx,my);
|
||||
pnt->delta_before = pnt->delta_before.mul(mx,my);
|
||||
pnt->delta_after = pnt->delta_after .mul(mx,my);
|
||||
}
|
||||
// bounds change after transforming
|
||||
p->calculateBounds();
|
||||
@@ -81,11 +81,11 @@ SymbolPartRotateAction::SymbolPartRotateAction(const set<SymbolPartP>& parts, co
|
||||
, angle(0)
|
||||
{}
|
||||
|
||||
String SymbolPartRotateAction::getName(bool toUndo) const {
|
||||
String SymbolPartRotateAction::getName(bool to_undo) const {
|
||||
return parts.size() == 1 ? _("Rotate shape") : _("Rotate shapes");
|
||||
}
|
||||
|
||||
void SymbolPartRotateAction::perform(bool toUndo) {
|
||||
void SymbolPartRotateAction::perform(bool to_undo) {
|
||||
// move the points back
|
||||
rotateBy(-angle);
|
||||
angle = -angle;
|
||||
@@ -119,11 +119,11 @@ SymbolPartShearAction::SymbolPartShearAction(const set<SymbolPartP>& parts, cons
|
||||
, constrain(false)
|
||||
{}
|
||||
|
||||
String SymbolPartShearAction::getName(bool toUndo) const {
|
||||
String SymbolPartShearAction::getName(bool to_undo) const {
|
||||
return parts.size() == 1 ? _("Shear shape") : _("Shear shapes");
|
||||
}
|
||||
|
||||
void SymbolPartShearAction::perform(bool toUndo) {
|
||||
void SymbolPartShearAction::perform(bool to_undo) {
|
||||
// move the points back
|
||||
// the vector shear = (x,y) is used as:
|
||||
// <1 x>
|
||||
@@ -161,19 +161,19 @@ SymbolPartScaleAction::SymbolPartScaleAction(const set<SymbolPartP>& parts, int
|
||||
oldMin = Vector2D::infinity();
|
||||
Vector2D oldMax = -Vector2D::infinity();
|
||||
FOR_EACH(p, parts) {
|
||||
oldMin = piecewise_min(oldMin, p->minPos);
|
||||
oldMax = piecewise_max(oldMax, p->maxPos);
|
||||
oldMin = piecewise_min(oldMin, p->min_pos);
|
||||
oldMax = piecewise_max(oldMax, p->max_pos);
|
||||
}
|
||||
// new == old
|
||||
newMin = newRealMin = oldMin;
|
||||
newSize = newRealSize = oldSize = oldMax - oldMin;
|
||||
}
|
||||
|
||||
String SymbolPartScaleAction::getName(bool toUndo) const {
|
||||
String SymbolPartScaleAction::getName(bool to_undo) const {
|
||||
return parts.size() == 1 ? _("Scale shape") : _("Scale shapes");
|
||||
}
|
||||
|
||||
void SymbolPartScaleAction::perform(bool toUndo) {
|
||||
void SymbolPartScaleAction::perform(bool to_undo) {
|
||||
swap(oldMin, newMin);
|
||||
swap(oldSize, newSize);
|
||||
transformAll();
|
||||
@@ -207,17 +207,17 @@ void SymbolPartScaleAction::update() {
|
||||
void SymbolPartScaleAction::transformAll() {
|
||||
Vector2D scale = newSize.div(oldSize);
|
||||
FOR_EACH(p, parts) {
|
||||
p->minPos = transform(p->minPos);
|
||||
p->maxPos = transform(p->maxPos);
|
||||
p->min_pos = transform(p->min_pos);
|
||||
p->max_pos = transform(p->max_pos);
|
||||
// make sure that max >= min
|
||||
if (p->minPos.x > p->maxPos.x) swap(p->minPos.x, p->maxPos.x);
|
||||
if (p->minPos.y > p->maxPos.y) swap(p->minPos.y, p->maxPos.y);
|
||||
if (p->min_pos.x > p->max_pos.x) swap(p->min_pos.x, p->max_pos.x);
|
||||
if (p->min_pos.y > p->max_pos.y) swap(p->min_pos.y, p->max_pos.y);
|
||||
// scale all points
|
||||
FOR_EACH(pnt, p->points) {
|
||||
pnt->pos = transform(pnt->pos);
|
||||
// also scale handles
|
||||
pnt->deltaBefore = pnt->deltaBefore.mul(scale);
|
||||
pnt->deltaAfter = pnt->deltaAfter .mul(scale);
|
||||
pnt->delta_before = pnt->delta_before.mul(scale);
|
||||
pnt->delta_after = pnt->delta_after .mul(scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -230,11 +230,11 @@ CombiningModeAction::CombiningModeAction(const set<SymbolPartP>& parts, SymbolPa
|
||||
}
|
||||
}
|
||||
|
||||
String CombiningModeAction::getName(bool toUndo) const {
|
||||
String CombiningModeAction::getName(bool to_undo) const {
|
||||
return _("Change combine mode");
|
||||
}
|
||||
|
||||
void CombiningModeAction::perform(bool toUndo) {
|
||||
void CombiningModeAction::perform(bool to_undo) {
|
||||
FOR_EACH(pm, parts) {
|
||||
swap(pm.first->combine, pm.second);
|
||||
}
|
||||
@@ -246,11 +246,11 @@ SymbolPartNameAction::SymbolPartNameAction(const SymbolPartP& part, const String
|
||||
: part(part), partName(name)
|
||||
{}
|
||||
|
||||
String SymbolPartNameAction::getName(bool toUndo) const {
|
||||
String SymbolPartNameAction::getName(bool to_undo) const {
|
||||
return _("Change shape name");
|
||||
}
|
||||
|
||||
void SymbolPartNameAction::perform(bool toUndo) {
|
||||
void SymbolPartNameAction::perform(bool to_undo) {
|
||||
swap(part->name, partName);
|
||||
}
|
||||
|
||||
@@ -260,12 +260,12 @@ AddSymbolPartAction::AddSymbolPartAction(Symbol& symbol, const SymbolPartP& part
|
||||
: symbol(symbol), part(part)
|
||||
{}
|
||||
|
||||
String AddSymbolPartAction::getName(bool toUndo) const {
|
||||
String AddSymbolPartAction::getName(bool to_undo) const {
|
||||
return _("Add ") + part->name;
|
||||
}
|
||||
|
||||
void AddSymbolPartAction::perform(bool toUndo) {
|
||||
if (toUndo) {
|
||||
void AddSymbolPartAction::perform(bool to_undo) {
|
||||
if (to_undo) {
|
||||
assert(!symbol.parts.empty());
|
||||
symbol.parts.erase (symbol.parts.begin());
|
||||
} else {
|
||||
@@ -287,12 +287,12 @@ RemoveSymbolPartsAction::RemoveSymbolPartsAction(Symbol& symbol, const set<Symbo
|
||||
}
|
||||
}
|
||||
|
||||
String RemoveSymbolPartsAction::getName(bool toUndo) const {
|
||||
String RemoveSymbolPartsAction::getName(bool to_undo) const {
|
||||
return removals.size() == 1 ? _("Remove shape") : _("Remove shapes");
|
||||
}
|
||||
|
||||
void RemoveSymbolPartsAction::perform(bool toUndo) {
|
||||
if (toUndo) {
|
||||
void RemoveSymbolPartsAction::perform(bool to_undo) {
|
||||
if (to_undo) {
|
||||
// reinsert the parts
|
||||
// ascending order, this is the reverse of removal
|
||||
FOR_EACH(r, removals) {
|
||||
@@ -325,12 +325,12 @@ DuplicateSymbolPartsAction::DuplicateSymbolPartsAction(Symbol& symbol, const set
|
||||
}
|
||||
}
|
||||
|
||||
String DuplicateSymbolPartsAction::getName(bool toUndo) const {
|
||||
String DuplicateSymbolPartsAction::getName(bool to_undo) const {
|
||||
return duplications.size() == 1 ? _("Duplicate shape") : _("Duplicate shapes");
|
||||
}
|
||||
|
||||
void DuplicateSymbolPartsAction::perform(bool toUndo) {
|
||||
if (toUndo) {
|
||||
void DuplicateSymbolPartsAction::perform(bool to_undo) {
|
||||
if (to_undo) {
|
||||
// remove the clones
|
||||
// walk in reverse order, otherwise we will shift the vector
|
||||
FOR_EACH_REVERSE(d, duplications) {
|
||||
@@ -359,11 +359,11 @@ ReorderSymbolPartsAction::ReorderSymbolPartsAction(Symbol& symbol, size_t partId
|
||||
: symbol(symbol), partId1(partId1), partId2(partId2)
|
||||
{}
|
||||
|
||||
String ReorderSymbolPartsAction::getName(bool toUndo) const {
|
||||
String ReorderSymbolPartsAction::getName(bool to_undo) const {
|
||||
return _("Reorder");
|
||||
}
|
||||
|
||||
void ReorderSymbolPartsAction::perform(bool toUndo) {
|
||||
void ReorderSymbolPartsAction::perform(bool to_undo) {
|
||||
assert(partId1 < symbol.parts.size());
|
||||
assert(partId2 < symbol.parts.size());
|
||||
swap(symbol.parts[partId1], symbol.parts[partId2]);
|
||||
|
||||
+20
-20
@@ -33,8 +33,8 @@ class SymbolPartMoveAction : public SymbolPartAction {
|
||||
public:
|
||||
SymbolPartMoveAction(const set<SymbolPartP>& parts);
|
||||
|
||||
virtual String getName(bool toUndo) const;
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
/// Update this action to move some more
|
||||
void move(const Vector2D& delta);
|
||||
@@ -70,8 +70,8 @@ class SymbolPartRotateAction : public SymbolPartMatrixAction {
|
||||
public:
|
||||
SymbolPartRotateAction(const set<SymbolPartP>& parts, const Vector2D& center);
|
||||
|
||||
virtual String getName(bool toUndo) const;
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
/// Update this action to rotate to a different angle
|
||||
void rotateTo(double newAngle);
|
||||
@@ -93,8 +93,8 @@ class SymbolPartShearAction : public SymbolPartMatrixAction {
|
||||
public:
|
||||
SymbolPartShearAction(const set<SymbolPartP>& parts, const Vector2D& center);
|
||||
|
||||
virtual String getName(bool toUndo) const;
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
/// Change shear by a given amount
|
||||
void move(const Vector2D& deltaShear);
|
||||
@@ -114,8 +114,8 @@ class SymbolPartScaleAction : public SymbolPartAction {
|
||||
public:
|
||||
SymbolPartScaleAction(const set<SymbolPartP>& parts, int scaleX, int scaleY);
|
||||
|
||||
virtual String getName(bool toUndo) const;
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
/// Change min and max coordinates
|
||||
void move(const Vector2D& deltaMin, const Vector2D& deltaMax);
|
||||
@@ -145,8 +145,8 @@ class CombiningModeAction : public SymbolPartListAction {
|
||||
public:
|
||||
CombiningModeAction(const set<SymbolPartP>& parts, SymbolPartCombine mode);
|
||||
|
||||
virtual String getName(bool toUndo) const;
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
private:
|
||||
vector<pair<SymbolPartP,SymbolPartCombine> > parts; ///< Affected parts with new combining modes
|
||||
@@ -159,8 +159,8 @@ class SymbolPartNameAction : public SymbolPartListAction {
|
||||
public:
|
||||
SymbolPartNameAction(const SymbolPartP& part, const String& name);
|
||||
|
||||
virtual String getName(bool toUndo) const;
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
private:
|
||||
SymbolPartP part; ///< Affected part
|
||||
@@ -174,8 +174,8 @@ class AddSymbolPartAction : public SymbolPartListAction {
|
||||
public:
|
||||
AddSymbolPartAction(Symbol& symbol, const SymbolPartP& part);
|
||||
|
||||
virtual String getName(bool toUndo) const;
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
private:
|
||||
Symbol& symbol; ///< Symbol to add the part to
|
||||
@@ -189,8 +189,8 @@ class RemoveSymbolPartsAction : public SymbolPartListAction {
|
||||
public:
|
||||
RemoveSymbolPartsAction(Symbol& symbol, const set<SymbolPartP>& parts);
|
||||
|
||||
virtual String getName(bool toUndo) const;
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
private:
|
||||
Symbol& symbol;
|
||||
@@ -205,8 +205,8 @@ class DuplicateSymbolPartsAction : public SymbolPartListAction {
|
||||
public:
|
||||
DuplicateSymbolPartsAction(Symbol& symbol, const set<SymbolPartP>& parts);
|
||||
|
||||
virtual String getName(bool toUndo) const;
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
/// Fill a set with all the new parts
|
||||
void getParts(set<SymbolPartP>& parts);
|
||||
@@ -225,8 +225,8 @@ class ReorderSymbolPartsAction : public SymbolPartListAction {
|
||||
public:
|
||||
ReorderSymbolPartsAction(Symbol& symbol, size_t partId1, size_t partId2);
|
||||
|
||||
virtual String getName(bool toUndo) const;
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
private:
|
||||
Symbol& symbol; ///< Symbol to swap the parts in
|
||||
|
||||
@@ -43,11 +43,11 @@ ControlPointMoveAction::ControlPointMoveAction(const set<ControlPointP>& points)
|
||||
}
|
||||
}
|
||||
|
||||
String ControlPointMoveAction::getName(bool toUndo) const {
|
||||
String ControlPointMoveAction::getName(bool to_undo) const {
|
||||
return points.size() == 1 ? _("Move point") : _("Move points");
|
||||
}
|
||||
|
||||
void ControlPointMoveAction::perform(bool toUndo) {
|
||||
void ControlPointMoveAction::perform(bool to_undo) {
|
||||
/*
|
||||
set<ControlPointP>::const_iterator it = points.begin();
|
||||
vector<Vector2D> ::iterator it2 = oldValues.begin();
|
||||
@@ -77,23 +77,23 @@ void ControlPointMoveAction::move (const Vector2D& deltaDelta) {
|
||||
HandleMoveAction::HandleMoveAction(const SelectedHandle& handle)
|
||||
: handle(handle)
|
||||
, constrain(false)
|
||||
, oldHandle(handle.getHandle())
|
||||
, oldOther (handle.getOther())
|
||||
, old_handle(handle.getHandle())
|
||||
, old_other (handle.getOther())
|
||||
{}
|
||||
|
||||
String HandleMoveAction::getName(bool toUndo) const {
|
||||
String HandleMoveAction::getName(bool to_undo) const {
|
||||
return _("Move handle");
|
||||
}
|
||||
|
||||
void HandleMoveAction::perform(bool toUndo) {
|
||||
swap(oldHandle, handle.getHandle());
|
||||
swap(oldOther, handle.getOther());
|
||||
void HandleMoveAction::perform(bool to_undo) {
|
||||
swap(old_handle, handle.getHandle());
|
||||
swap(old_other, handle.getOther());
|
||||
}
|
||||
|
||||
void HandleMoveAction::move(const Vector2D& deltaDelta) {
|
||||
delta += deltaDelta;
|
||||
handle.getHandle() = constrainVector(oldHandle + delta, constrain);
|
||||
handle.getOther() = oldOther;
|
||||
handle.getHandle() = constrainVector(old_handle + delta, constrain);
|
||||
handle.getOther() = old_other;
|
||||
handle.onUpdateHandle();
|
||||
}
|
||||
|
||||
@@ -113,25 +113,25 @@ void ControlPointUpdate::perform() {
|
||||
SegmentModeAction::SegmentModeAction(const ControlPointP& p1, const ControlPointP& p2, SegmentMode mode)
|
||||
: point1(p1), point2(p2)
|
||||
{
|
||||
if (p1->segmentAfter == mode) return;
|
||||
point1.other.segmentAfter = point2.other.segmentBefore = mode;
|
||||
if (p1->segment_after == mode) return;
|
||||
point1.other.segment_after = point2.other.segment_before = mode;
|
||||
if (mode == SEGMENT_LINE) {
|
||||
point1.other.deltaAfter = Vector2D(0,0);
|
||||
point2.other.deltaBefore = Vector2D(0,0);
|
||||
point1.other.delta_after = Vector2D(0,0);
|
||||
point2.other.delta_before = Vector2D(0,0);
|
||||
point1.other.lock = LOCK_FREE;
|
||||
point2.other.lock = LOCK_FREE;
|
||||
} else if (mode == SEGMENT_CURVE) {
|
||||
point1.other.deltaAfter = (p2->pos - p1->pos) / 3.0f;
|
||||
point2.other.deltaBefore = (p1->pos - p2->pos) / 3.0f;
|
||||
point1.other.delta_after = (p2->pos - p1->pos) / 3.0f;
|
||||
point2.other.delta_before = (p1->pos - p2->pos) / 3.0f;
|
||||
}
|
||||
}
|
||||
String SegmentModeAction::getName(bool toUndo) const {
|
||||
SegmentMode mode = toUndo ? point1.point->segmentAfter : point1.other.segmentAfter;
|
||||
String SegmentModeAction::getName(bool to_undo) const {
|
||||
SegmentMode mode = to_undo ? point1.point->segment_after : point1.other.segment_after;
|
||||
if (mode == SEGMENT_LINE) return _("Convert to line");
|
||||
else return _("Convert to curve");
|
||||
}
|
||||
|
||||
void SegmentModeAction::perform(bool toUndo) {
|
||||
void SegmentModeAction::perform(bool to_undo) {
|
||||
point1.perform();
|
||||
point2.perform();
|
||||
}
|
||||
@@ -146,11 +146,11 @@ LockModeAction::LockModeAction(const ControlPointP& p, LockMode lock)
|
||||
point.other.onUpdateLock();
|
||||
}
|
||||
|
||||
String LockModeAction::getName(bool toUndo) const {
|
||||
String LockModeAction::getName(bool to_undo) const {
|
||||
return _("Lock point");
|
||||
}
|
||||
|
||||
void LockModeAction::perform(bool toUndo) {
|
||||
void LockModeAction::perform(bool to_undo) {
|
||||
point.perform();
|
||||
}
|
||||
|
||||
@@ -161,12 +161,12 @@ CurveDragAction::CurveDragAction(const ControlPointP& point1, const ControlPoint
|
||||
: SegmentModeAction(point1, point2, SEGMENT_CURVE)
|
||||
{}
|
||||
|
||||
String CurveDragAction::getName(bool toUndo) const {
|
||||
String CurveDragAction::getName(bool to_undo) const {
|
||||
return _("Move curve");
|
||||
}
|
||||
|
||||
void CurveDragAction::perform(bool toUndo) {
|
||||
SegmentModeAction::perform(toUndo);
|
||||
void CurveDragAction::perform(bool to_undo) {
|
||||
SegmentModeAction::perform(to_undo);
|
||||
}
|
||||
|
||||
void CurveDragAction::move(const Vector2D& delta, double t) {
|
||||
@@ -186,8 +186,8 @@ void CurveDragAction::move(const Vector2D& delta, double t) {
|
||||
// delta = p' - p
|
||||
// pointDelta = x * t * (1-t)
|
||||
Vector2D pointDelta = delta / (3 * (t * t + (1-t) * (1-t)));
|
||||
point1.point->deltaAfter += pointDelta / t;
|
||||
point2.point->deltaBefore += pointDelta / (1-t);
|
||||
point1.point->delta_after += pointDelta / t;
|
||||
point2.point->delta_before += pointDelta / (1-t);
|
||||
point1.point->onUpdateHandle(HANDLE_AFTER);
|
||||
point2.point->onUpdateHandle(HANDLE_BEFORE);
|
||||
}
|
||||
@@ -195,40 +195,40 @@ void CurveDragAction::move(const Vector2D& delta, double t) {
|
||||
|
||||
// ----------------------------------------------------------------------------- : Add control point
|
||||
|
||||
ControlPointAddAction::ControlPointAddAction(const SymbolPartP& part, UInt insertAfter, double t)
|
||||
: point1(part->getPoint(insertAfter))
|
||||
, point2(part->getPoint(insertAfter + 1))
|
||||
ControlPointAddAction::ControlPointAddAction(const SymbolPartP& part, UInt insert_after, double t)
|
||||
: point1(part->getPoint(insert_after))
|
||||
, point2(part->getPoint(insert_after + 1))
|
||||
, part(part)
|
||||
, insertAfter(insertAfter)
|
||||
, newPoint(new ControlPoint())
|
||||
, insert_after(insert_after)
|
||||
, new_point(new ControlPoint())
|
||||
{
|
||||
// calculate new point
|
||||
if (point1.other.segmentAfter == SEGMENT_CURVE) {
|
||||
if (point1.other.segment_after == SEGMENT_CURVE) {
|
||||
// calculate new handles using de Casteljau's subdivision algorithm
|
||||
deCasteljau(point1.other, point2.other, t, *newPoint);
|
||||
deCasteljau(point1.other, point2.other, t, *new_point);
|
||||
// unlock if needed
|
||||
if (point1.other.lock == LOCK_SIZE) point1.other.lock = LOCK_DIR;
|
||||
if (point2.other.lock == LOCK_SIZE) point2.other.lock = LOCK_DIR;
|
||||
newPoint->lock = LOCK_DIR;
|
||||
newPoint->segmentBefore = SEGMENT_CURVE;
|
||||
newPoint->segmentAfter = SEGMENT_CURVE;
|
||||
new_point->lock = LOCK_DIR;
|
||||
new_point->segment_before = SEGMENT_CURVE;
|
||||
new_point->segment_after = SEGMENT_CURVE;
|
||||
} else {
|
||||
newPoint->pos = point1.other.pos * (1 - t) + point2.other.pos * t;
|
||||
newPoint->lock = LOCK_FREE;
|
||||
newPoint->segmentBefore = SEGMENT_LINE;
|
||||
newPoint->segmentAfter = SEGMENT_LINE;
|
||||
new_point->pos = point1.other.pos * (1 - t) + point2.other.pos * t;
|
||||
new_point->lock = LOCK_FREE;
|
||||
new_point->segment_before = SEGMENT_LINE;
|
||||
new_point->segment_after = SEGMENT_LINE;
|
||||
}
|
||||
}
|
||||
|
||||
String ControlPointAddAction::getName(bool toUndo) const {
|
||||
String ControlPointAddAction::getName(bool to_undo) const {
|
||||
return _("Add control point");
|
||||
}
|
||||
|
||||
void ControlPointAddAction::perform(bool toUndo) {
|
||||
if (toUndo) { // remove the point
|
||||
part->points.erase( part->points.begin() + insertAfter + 1);
|
||||
void ControlPointAddAction::perform(bool to_undo) {
|
||||
if (to_undo) { // remove the point
|
||||
part->points.erase( part->points.begin() + insert_after + 1);
|
||||
} else {
|
||||
part->points.insert(part->points.begin() + insertAfter + 1, newPoint);
|
||||
part->points.insert(part->points.begin() + insert_after + 1, new_point);
|
||||
}
|
||||
// update points before/after
|
||||
point1.perform();
|
||||
@@ -249,8 +249,8 @@ class SinglePointRemoveAction : public Action {
|
||||
public:
|
||||
SinglePointRemoveAction(const SymbolPartP& part, UInt position);
|
||||
|
||||
virtual String getName(bool toUndo) const { return _("Delete point"); }
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const { return _("Delete point"); }
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
private:
|
||||
SymbolPartP part;
|
||||
@@ -266,21 +266,21 @@ SinglePointRemoveAction::SinglePointRemoveAction(const SymbolPartP& part, UInt p
|
||||
, point1(part->getPoint(position - 1))
|
||||
, point2(part->getPoint(position + 1))
|
||||
{
|
||||
if (point1.other.segmentAfter == SEGMENT_CURVE || point2.other.segmentBefore == SEGMENT_CURVE) {
|
||||
if (point1.other.segment_after == SEGMENT_CURVE || point2.other.segment_before == SEGMENT_CURVE) {
|
||||
// try to preserve curve
|
||||
Vector2D before = point->deltaBefore;
|
||||
Vector2D after = point->deltaAfter;
|
||||
Vector2D before = point->delta_before;
|
||||
Vector2D after = point->delta_after;
|
||||
|
||||
// convert both segments to curves first
|
||||
if (point1.other.segmentAfter != SEGMENT_CURVE) {
|
||||
point1.other.deltaAfter = -
|
||||
if (point1.other.segment_after != SEGMENT_CURVE) {
|
||||
point1.other.delta_after = -
|
||||
before = (point1.other.pos - point->pos) / 3.0;
|
||||
point1.other.segmentAfter = SEGMENT_CURVE;
|
||||
point1.other.segment_after = SEGMENT_CURVE;
|
||||
}
|
||||
if (point2.other.segmentBefore != SEGMENT_CURVE) {
|
||||
point2.other.deltaBefore = -
|
||||
if (point2.other.segment_before != SEGMENT_CURVE) {
|
||||
point2.other.delta_before = -
|
||||
after = (point2.other.pos - point->pos) / 3.0;
|
||||
point2.other.segmentBefore = SEGMENT_CURVE;
|
||||
point2.other.segment_before = SEGMENT_CURVE;
|
||||
}
|
||||
|
||||
// The inverse of adding a point, reconstruct the original handles
|
||||
@@ -290,8 +290,8 @@ SinglePointRemoveAction::SinglePointRemoveAction(const SymbolPartP& part, UInt p
|
||||
double al = after .length() + 0.00000001;
|
||||
double totl = bl + al;
|
||||
// set new handle sizes
|
||||
point1.other.deltaAfter *= totl / bl;
|
||||
point2.other.deltaBefore *= totl / al;
|
||||
point1.other.delta_after *= totl / bl;
|
||||
point2.other.delta_before *= totl / al;
|
||||
|
||||
// Also take in acount cases where the point does not correspond to a freshly added point.
|
||||
// distance from the point to the curve as it would be in the above case can be used,
|
||||
@@ -301,8 +301,8 @@ SinglePointRemoveAction::SinglePointRemoveAction(const SymbolPartP& part, UInt p
|
||||
Vector2D p = c.pointAt(t);
|
||||
Vector2D distP = point->pos - p;
|
||||
// adjust handle sizes
|
||||
point1.other.deltaAfter *= ssqrt(distP.dot(point1.other.deltaAfter) /point1.other.deltaAfter.lengthSqr()) + 1;
|
||||
point2.other.deltaBefore *= ssqrt(distP.dot(point2.other.deltaBefore)/point2.other.deltaBefore.lengthSqr()) + 1;
|
||||
point1.other.delta_after *= ssqrt(distP.dot(point1.other.delta_after) /point1.other.delta_after.lengthSqr()) + 1;
|
||||
point2.other.delta_before *= ssqrt(distP.dot(point2.other.delta_before)/point2.other.delta_before.lengthSqr()) + 1;
|
||||
|
||||
// unlock if needed
|
||||
if (point1.other.lock == LOCK_SIZE) point1.other.lock = LOCK_DIR;
|
||||
@@ -312,8 +312,8 @@ SinglePointRemoveAction::SinglePointRemoveAction(const SymbolPartP& part, UInt p
|
||||
}
|
||||
}
|
||||
|
||||
void SinglePointRemoveAction::perform(bool toUndo) {
|
||||
if (toUndo) {
|
||||
void SinglePointRemoveAction::perform(bool to_undo) {
|
||||
if (to_undo) {
|
||||
// reinsert the point
|
||||
part->points.insert(part->points.begin() + position, point);
|
||||
} else {
|
||||
@@ -336,8 +336,8 @@ class ControlPointRemoveAction : public Action {
|
||||
public:
|
||||
ControlPointRemoveAction(const SymbolPartP& part, const set<ControlPointP>& toDelete);
|
||||
|
||||
virtual String getName(bool toUndo) const;
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
private:
|
||||
vector<SinglePointRemoveActionP> removals;
|
||||
@@ -355,17 +355,17 @@ ControlPointRemoveAction::ControlPointRemoveAction(const SymbolPartP& part, cons
|
||||
}
|
||||
}
|
||||
|
||||
String ControlPointRemoveAction::getName(bool toUndo) const {
|
||||
String ControlPointRemoveAction::getName(bool to_undo) const {
|
||||
return removals.size() == 1 ? _("Delete point") : _("Delete points");
|
||||
}
|
||||
|
||||
void ControlPointRemoveAction::perform(bool toUndo) {
|
||||
if (toUndo) {
|
||||
FOR_EACH(r, removals) r->perform(toUndo);
|
||||
void ControlPointRemoveAction::perform(bool to_undo) {
|
||||
if (to_undo) {
|
||||
FOR_EACH(r, removals) r->perform(to_undo);
|
||||
} else {
|
||||
// in reverse order, because positions of later points will
|
||||
// change after removal of earlier points.
|
||||
FOR_EACH_REVERSE(r, removals) r->perform(toUndo);
|
||||
FOR_EACH_REVERSE(r, removals) r->perform(to_undo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ class ControlPointMoveAction : public Action {
|
||||
public:
|
||||
ControlPointMoveAction(const set<ControlPointP>& points);
|
||||
|
||||
virtual String getName(bool toUndo) const;
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
/// Update this action to move some more
|
||||
void move(const Vector2D& delta);
|
||||
@@ -52,16 +52,16 @@ class HandleMoveAction : public Action {
|
||||
public:
|
||||
HandleMoveAction(const SelectedHandle& handle);
|
||||
|
||||
virtual String getName(bool toUndo) const;
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
/// Update this action to move some more
|
||||
void move(const Vector2D& delta);
|
||||
|
||||
private:
|
||||
SelectedHandle handle; ///< The handle to move
|
||||
Vector2D oldHandle; ///< Old value of this handle
|
||||
Vector2D oldOther; ///< Old value of other handle, needed for contraints
|
||||
Vector2D old_handle; ///< Old value of this handle
|
||||
Vector2D old_other; ///< Old value of other handle, needed for contraints
|
||||
Vector2D delta; ///< Amount we moved
|
||||
public:
|
||||
bool constrain; ///< Constrain movement?
|
||||
@@ -90,8 +90,8 @@ class SegmentModeAction : public Action {
|
||||
public:
|
||||
SegmentModeAction(const ControlPointP& p1, const ControlPointP& p2, SegmentMode mode);
|
||||
|
||||
virtual String getName(bool toUndo) const;
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
protected:
|
||||
ControlPointUpdate point1, point2;
|
||||
@@ -104,8 +104,8 @@ class LockModeAction : public Action {
|
||||
public:
|
||||
LockModeAction(const ControlPointP& p, LockMode mode);
|
||||
|
||||
virtual String getName(bool toUndo) const;
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
private:
|
||||
ControlPointUpdate point; ///< The affected point
|
||||
@@ -120,8 +120,8 @@ class CurveDragAction : public SegmentModeAction {
|
||||
public:
|
||||
CurveDragAction(const ControlPointP& point1, const ControlPointP& point2);
|
||||
|
||||
virtual String getName(bool toUndo) const;
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
// Move the curve by this much, it is grabbed at time t
|
||||
void move(const Vector2D& delta, double t);
|
||||
@@ -133,17 +133,17 @@ class CurveDragAction : public SegmentModeAction {
|
||||
class ControlPointAddAction : public Action {
|
||||
public:
|
||||
/// Insert a new point in part, after position insertAfter_, at the time t on the segment
|
||||
ControlPointAddAction(const SymbolPartP& part, UInt insertAfter, double t);
|
||||
ControlPointAddAction(const SymbolPartP& part, UInt insert_after, double t);
|
||||
|
||||
virtual String getName(bool toUndo) const;
|
||||
virtual void perform(bool toUndo);
|
||||
virtual String getName(bool to_undo) const;
|
||||
virtual void perform(bool to_undo);
|
||||
|
||||
inline ControlPointP getNewPoint() const { return newPoint; }
|
||||
inline ControlPointP getNewPoint() const { return new_point; }
|
||||
|
||||
private:
|
||||
SymbolPartP part; ///< SymbolPart we are in
|
||||
ControlPointP newPoint; ///< The point to insert
|
||||
UInt insertAfter; ///< Insert after index .. in the array
|
||||
ControlPointP new_point; ///< The point to insert
|
||||
UInt insert_after; ///< Insert after index .. in the array
|
||||
ControlPointUpdate point1, point2; ///< Update the points around the new point
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user