mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 21:27:01 -04:00
Use make_intrusive/make_shared for smart pointer construction.
This commit is contained in:
@@ -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 = intrusive(new SymbolShape);
|
||||
shape = make_intrusive<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(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)));
|
||||
shape->points.push_back(make_intrusive<ControlPoint>(c.x + r.x, c.y, 0, kr * r.y, 0, -kr * r.y, LOCK_SIZE));
|
||||
shape->points.push_back(make_intrusive<ControlPoint>(c.x, c.y - r.y, kr * r.x, 0, -kr * r.x, 0, LOCK_SIZE));
|
||||
shape->points.push_back(make_intrusive<ControlPoint>(c.x - r.x, c.y, 0, -kr * r.y, 0, kr * r.y, LOCK_SIZE));
|
||||
shape->points.push_back(make_intrusive<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(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)));
|
||||
shape->points.push_back(make_intrusive<ControlPoint>(c.x - r.x, c.y - r.y));
|
||||
shape->points.push_back(make_intrusive<ControlPoint>(c.x + r.x, c.y - r.y));
|
||||
shape->points.push_back(make_intrusive<ControlPoint>(c.x + r.x, c.y + r.y));
|
||||
shape->points.push_back(make_intrusive<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(intrusive(new ControlPoint(
|
||||
shape->points.push_back(make_intrusive<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(intrusive(new ControlPoint(
|
||||
shape->points.push_back(make_intrusive<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(intrusive(new ControlPoint(
|
||||
shape->points.push_back(make_intrusive<ControlPoint>(
|
||||
c.x + rb * r.x * sin(theta),
|
||||
y - rb * r.y * cos(theta)
|
||||
)));
|
||||
));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
+10
-10
@@ -39,23 +39,23 @@ void SymbolControl::switchEditor(const SymbolEditorBaseP& e) {
|
||||
|
||||
void SymbolControl::onChangeSymbol() {
|
||||
selected_parts.setSymbol(symbol);
|
||||
switchEditor(intrusive(new SymbolSelectEditor(this, false)));
|
||||
switchEditor(make_intrusive<SymbolSelectEditor>(this, false));
|
||||
Refresh(false);
|
||||
}
|
||||
|
||||
void SymbolControl::onModeChange(wxCommandEvent& ev) {
|
||||
switch (ev.GetId()) {
|
||||
case ID_MODE_SELECT:
|
||||
switchEditor(intrusive(new SymbolSelectEditor(this, false)));
|
||||
switchEditor(make_intrusive<SymbolSelectEditor>(this, false));
|
||||
break;
|
||||
case ID_MODE_ROTATE:
|
||||
switchEditor(intrusive(new SymbolSelectEditor(this, true)));
|
||||
switchEditor(make_intrusive<SymbolSelectEditor>(this, true));
|
||||
break;
|
||||
case ID_MODE_POINTS:
|
||||
if (selected_parts.size() == 1) {
|
||||
selected_shape = selected_parts.getAShape();
|
||||
if (selected_shape) {
|
||||
switchEditor(intrusive(new SymbolPointEditor(this, selected_shape)));
|
||||
switchEditor(make_intrusive<SymbolPointEditor>(this, selected_shape));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -64,10 +64,10 @@ void SymbolControl::onModeChange(wxCommandEvent& ev) {
|
||||
selected_parts.clear();
|
||||
signalSelectionChange();
|
||||
}
|
||||
switchEditor(intrusive(new SymbolBasicShapeEditor(this)));
|
||||
switchEditor(make_intrusive<SymbolBasicShapeEditor>(this));
|
||||
break;
|
||||
case ID_MODE_SYMMETRY:
|
||||
switchEditor(intrusive(new SymbolSymmetryEditor(this, selected_parts.getASymmetry())));
|
||||
switchEditor(make_intrusive<SymbolSymmetryEditor>(this, selected_parts.getASymmetry()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,7 @@ void SymbolControl::onUpdateSelection() {
|
||||
}
|
||||
// begin editing another part
|
||||
selected_shape = shape;
|
||||
editor = intrusive(new SymbolPointEditor(this, selected_shape));
|
||||
editor = make_intrusive<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(intrusive(new SymbolSelectEditor(this, false)));
|
||||
switchEditor(make_intrusive<SymbolSelectEditor>(this, false));
|
||||
signalSelectionChange();
|
||||
}
|
||||
|
||||
void SymbolControl::activatePart(const SymbolPartP& part) {
|
||||
if (part->isSymbolShape()) {
|
||||
selected_parts.select(part);
|
||||
switchEditor(intrusive(new SymbolPointEditor(this, static_pointer_cast<SymbolShape>(part))));
|
||||
switchEditor(make_intrusive<SymbolPointEditor>(this, static_pointer_cast<SymbolShape>(part)));
|
||||
} else if (part->isSymbolSymmetry()) {
|
||||
selected_parts.select(part);
|
||||
switchEditor(intrusive(new SymbolSymmetryEditor(this, static_pointer_cast<SymbolSymmetry>(part))));
|
||||
switchEditor(make_intrusive<SymbolSymmetryEditor>(this, static_pointer_cast<SymbolSymmetry>(part)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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(), intrusive(new SymbolGroup())));
|
||||
addAction(new GroupSymbolPartsAction(*getSymbol(), control.selected_parts.get(), make_intrusive<SymbolGroup>()));
|
||||
control.Refresh(false);
|
||||
} else if (id == ID_EDIT_UNGROUP && !isEditing()) {
|
||||
// ungroup selection, not when dragging
|
||||
|
||||
@@ -118,7 +118,7 @@ void SymbolSymmetryEditor::onCommand(int id) {
|
||||
}
|
||||
resetActions();
|
||||
} else if (id == ID_ADD_SYMMETRY) {
|
||||
symmetry = intrusive(new SymbolSymmetry());
|
||||
symmetry = make_intrusive<SymbolSymmetry>();
|
||||
symmetry->kind = SYMMETRY_ROTATION;
|
||||
symmetry->copies = 2;
|
||||
symmetry->center = Vector2D(0.5,0.5);
|
||||
|
||||
@@ -36,7 +36,7 @@ SymbolWindow::SymbolWindow(Window* parent, const String& filename)
|
||||
: performer(nullptr)
|
||||
{
|
||||
// open file
|
||||
Reader reader(shared(new wxFileInputStream(filename)), nullptr, filename);
|
||||
Reader reader(make_shared<wxFileInputStream>(filename), nullptr, filename);
|
||||
SymbolP symbol;
|
||||
reader.handle_greedy(symbol);
|
||||
init(parent, symbol);
|
||||
@@ -217,7 +217,7 @@ void SymbolWindow::onFileOpen(wxCommandEvent& ev) {
|
||||
String ext = n.GetExt();
|
||||
SymbolP symbol;
|
||||
if (ext.Lower() == _("mse-symbol")) {
|
||||
Reader reader(shared(new wxFileInputStream(name)), nullptr, name);
|
||||
Reader reader(make_shared<wxFileInputStream>(name), nullptr, name);
|
||||
reader.handle_greedy(symbol);
|
||||
} else {
|
||||
wxBusyCursor busy;
|
||||
@@ -240,7 +240,7 @@ void SymbolWindow::onFileSaveAs(wxCommandEvent& ev) {
|
||||
String name = wxFileSelector(_("Save symbol"),settings.default_set_dir,_(""),_(""),_("Symbol files (*.mse-symbol)|*.mse-symbol"),wxFD_SAVE, this);
|
||||
if (!name.empty()) {
|
||||
settings.default_set_dir = wxPathOnly(name);
|
||||
Writer writer(shared(new wxFileOutputStream(name)), file_version_symbol);
|
||||
Writer writer(make_shared<wxFileOutputStream>(name), file_version_symbol);
|
||||
writer.handle(control->getSymbol());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user