Instead of the new_intrusive<T>() functions, use intrusive(new T)

This means we no longer need 8 different functions for different numbers of arguments, and non-const references can now also be passed to constructors without problems.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1443 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2010-07-21 14:32:28 +00:00
parent 8800500d86
commit 51dfed69b4
66 changed files with 304 additions and 353 deletions
+15 -15
View File
@@ -186,7 +186,7 @@ void SymbolBasicShapeEditor::makeShape(Vector2D a, Vector2D b, bool constrained,
// TODO : Move out of this class
void SymbolBasicShapeEditor::makeCenteredShape(const Vector2D& c, Vector2D r, bool constrained) {
shape = new_intrusive<SymbolShape>();
shape = intrusive(new SymbolShape);
// What shape to make?
switch (mode) {
case ID_SHAPE_CIRCLE: {
@@ -199,10 +199,10 @@ void SymbolBasicShapeEditor::makeCenteredShape(const Vector2D& c, Vector2D r, bo
// a circle has 4 control points, the first is: (x+r, y) db(0, kr) da(0, -kr)
// kr is a magic constant
const double kr = 0.5522847498f; // = 4/3 * (sqrt(2) - 1)
shape->points.push_back(new_intrusive7<ControlPoint>(c.x + r.x, c.y, 0, kr * r.y, 0, -kr * r.y, LOCK_SIZE));
shape->points.push_back(new_intrusive7<ControlPoint>(c.x, c.y - r.y, kr * r.x, 0, -kr * r.x, 0, LOCK_SIZE));
shape->points.push_back(new_intrusive7<ControlPoint>(c.x - r.x, c.y, 0, -kr * r.y, 0, kr * r.y, LOCK_SIZE));
shape->points.push_back(new_intrusive7<ControlPoint>(c.x, c.y + r.y, -kr * r.x, 0, kr * r.x, 0, LOCK_SIZE));
shape->points.push_back(intrusive(new ControlPoint(c.x + r.x, c.y, 0, kr * r.y, 0, -kr * r.y, LOCK_SIZE)));
shape->points.push_back(intrusive(new ControlPoint(c.x, c.y - r.y, kr * r.x, 0, -kr * r.x, 0, LOCK_SIZE)));
shape->points.push_back(intrusive(new ControlPoint(c.x - r.x, c.y, 0, -kr * r.y, 0, kr * r.y, LOCK_SIZE)));
shape->points.push_back(intrusive(new ControlPoint(c.x, c.y + r.y, -kr * r.x, 0, kr * r.x, 0, LOCK_SIZE)));
break;
} case ID_SHAPE_RECTANGLE: {
// A rectangle / square
@@ -212,10 +212,10 @@ void SymbolBasicShapeEditor::makeCenteredShape(const Vector2D& c, Vector2D r, bo
shape->name = capitalize(_TYPE_("rectangle"));
}
// a rectangle just has four corners
shape->points.push_back(new_intrusive2<ControlPoint>(c.x - r.x, c.y - r.y));
shape->points.push_back(new_intrusive2<ControlPoint>(c.x + r.x, c.y - r.y));
shape->points.push_back(new_intrusive2<ControlPoint>(c.x + r.x, c.y + r.y));
shape->points.push_back(new_intrusive2<ControlPoint>(c.x - r.x, c.y + r.y));
shape->points.push_back(intrusive(new ControlPoint(c.x - r.x, c.y - r.y)));
shape->points.push_back(intrusive(new ControlPoint(c.x + r.x, c.y - r.y)));
shape->points.push_back(intrusive(new ControlPoint(c.x + r.x, c.y + r.y)));
shape->points.push_back(intrusive(new ControlPoint(c.x - r.x, c.y + r.y)));
break;
} default: {
// A polygon or star
@@ -258,10 +258,10 @@ void SymbolBasicShapeEditor::makeCenteredShape(const Vector2D& c, Vector2D r, bo
// we can generate points
for(int i = 0 ; i < n ; ++i) {
double theta = alpha * i;
shape->points.push_back(new_intrusive2<ControlPoint>(
shape->points.push_back(intrusive(new ControlPoint(
c.x + ra * r.x * sin(theta),
y - ra * r.y * cos(theta)
));
)));
}
} else {
// a star is made using a smaller, inverted polygon at the inside
@@ -280,16 +280,16 @@ void SymbolBasicShapeEditor::makeCenteredShape(const Vector2D& c, Vector2D r, bo
for(int i = 0 ; i < n ; ++i) {
double theta = alpha * i;
// from a
shape->points.push_back(new_intrusive2<ControlPoint>(
shape->points.push_back(intrusive(new ControlPoint(
c.x + ra * r.x * sin(theta),
y - ra * r.y * cos(theta)
));
)));
// from b
theta = alpha * (i + 0.5);
shape->points.push_back(new_intrusive2<ControlPoint>(
shape->points.push_back(intrusive(new ControlPoint(
c.x + rb * r.x * sin(theta),
y - rb * r.y * cos(theta)
));
)));
}
}
break;
+10 -10
View File
@@ -39,23 +39,23 @@ void SymbolControl::switchEditor(const SymbolEditorBaseP& e) {
void SymbolControl::onChangeSymbol() {
selected_parts.setSymbol(symbol);
switchEditor(new_intrusive2<SymbolSelectEditor>(this, false));
switchEditor(intrusive(new SymbolSelectEditor(this, false)));
Refresh(false);
}
void SymbolControl::onModeChange(wxCommandEvent& ev) {
switch (ev.GetId()) {
case ID_MODE_SELECT:
switchEditor(new_intrusive2<SymbolSelectEditor>(this, false));
switchEditor(intrusive(new SymbolSelectEditor(this, false)));
break;
case ID_MODE_ROTATE:
switchEditor(new_intrusive2<SymbolSelectEditor>(this, true));
switchEditor(intrusive(new SymbolSelectEditor(this, true)));
break;
case ID_MODE_POINTS:
if (selected_parts.size() == 1) {
selected_shape = selected_parts.getAShape();
if (selected_shape) {
switchEditor(new_intrusive2<SymbolPointEditor>(this, selected_shape));
switchEditor(intrusive(new SymbolPointEditor(this, selected_shape)));
}
}
break;
@@ -64,10 +64,10 @@ void SymbolControl::onModeChange(wxCommandEvent& ev) {
selected_parts.clear();
signalSelectionChange();
}
switchEditor(new_intrusive1<SymbolBasicShapeEditor>(this));
switchEditor(intrusive(new SymbolBasicShapeEditor(this)));
break;
case ID_MODE_SYMMETRY:
switchEditor(new_intrusive2<SymbolSymmetryEditor>(this, selected_parts.getASymmetry()));
switchEditor(intrusive(new SymbolSymmetryEditor(this, selected_parts.getASymmetry())));
break;
}
}
@@ -110,7 +110,7 @@ void SymbolControl::onUpdateSelection() {
}
// begin editing another part
selected_shape = shape;
editor = new_intrusive2<SymbolPointEditor>(this, selected_shape);
editor = intrusive(new SymbolPointEditor(this, selected_shape));
Refresh(false);
}
break;
@@ -147,17 +147,17 @@ void SymbolControl::onUpdateSelection() {
void SymbolControl::selectPart(const SymbolPartP& part) {
selected_parts.select(part);
switchEditor(new_intrusive2<SymbolSelectEditor>(this, false));
switchEditor(intrusive(new SymbolSelectEditor(this, false)));
signalSelectionChange();
}
void SymbolControl::activatePart(const SymbolPartP& part) {
if (part->isSymbolShape()) {
selected_parts.select(part);
switchEditor(new_intrusive2<SymbolPointEditor>(this, static_pointer_cast<SymbolShape>(part)));
switchEditor(intrusive(new SymbolPointEditor(this, static_pointer_cast<SymbolShape>(part))));
} else if (part->isSymbolSymmetry()) {
selected_parts.select(part);
switchEditor(new_intrusive2<SymbolSymmetryEditor>(this, static_pointer_cast<SymbolSymmetry>(part)));
switchEditor(intrusive(new SymbolSymmetryEditor(this, static_pointer_cast<SymbolSymmetry>(part))));
}
}
+1 -1
View File
@@ -184,7 +184,7 @@ void SymbolSelectEditor::onCommand(int id) {
control.Refresh(false);
} else if (id == ID_EDIT_GROUP && !isEditing()) {
// group selection, not when dragging
addAction(new GroupSymbolPartsAction(*getSymbol(), control.selected_parts.get(), new_intrusive<SymbolGroup>()));
addAction(new GroupSymbolPartsAction(*getSymbol(), control.selected_parts.get(), intrusive(new SymbolGroup())));
control.Refresh(false);
} else if (id == ID_EDIT_UNGROUP && !isEditing()) {
// ungroup selection, not when dragging
+1 -1
View File
@@ -118,7 +118,7 @@ void SymbolSymmetryEditor::onCommand(int id) {
}
resetActions();
} else if (id == ID_ADD_SYMMETRY) {
symmetry = new_intrusive<SymbolSymmetry>();
symmetry = intrusive(new SymbolSymmetry());
symmetry->kind = SYMMETRY_ROTATION;
symmetry->copies = 2;
symmetry->center = Vector2D(0.5,0.5);
+3 -3
View File
@@ -35,7 +35,7 @@ SymbolWindow::SymbolWindow(Window* parent, const String& filename)
: performer(nullptr)
{
// open file
Reader reader(new_shared1<wxFileInputStream>(filename), nullptr, filename);
Reader reader(shared(new wxFileInputStream(filename)), nullptr, filename);
SymbolP symbol;
reader.handle_greedy(symbol);
init(parent, symbol);
@@ -216,7 +216,7 @@ void SymbolWindow::onFileOpen(wxCommandEvent& ev) {
String ext = n.GetExt();
SymbolP symbol;
if (ext.Lower() == _("mse-symbol")) {
Reader reader(new_shared1<wxFileInputStream>(name), nullptr, name);
Reader reader(shared(new wxFileInputStream(name)), nullptr, name);
reader.handle_greedy(symbol);
} else {
wxBusyCursor busy;
@@ -239,7 +239,7 @@ void SymbolWindow::onFileSaveAs(wxCommandEvent& ev) {
String name = wxFileSelector(_("Save symbol"),settings.default_set_dir,_(""),_(""),_("Symbol files (*.mse-symbol)|*.mse-symbol"),wxSAVE, this);
if (!name.empty()) {
settings.default_set_dir = wxPathOnly(name);
Writer writer(new_shared1<wxFileOutputStream>(name), file_version_symbol);
Writer writer(shared(new wxFileOutputStream(name)), file_version_symbol);
writer.handle(control->getSymbol());
}
}