use of org.pepsoft.worldpainter.brushes.RotatedBrush in project WorldPainter by Captain-Chaos.
the class App method updateBrushRotation.
private void updateBrushRotation() {
int desiredBrushRotation = (activeOperation instanceof PaintOperation) ? brushRotation : toolBrushRotation;
if (desiredBrushRotation != previousBrushRotation) {
// long start = System.currentTimeMillis();
if (desiredBrushRotation == 0) {
for (Map.Entry<Brush, JToggleButton> entry : brushButtons.entrySet()) {
Brush brush = entry.getKey();
JToggleButton button = entry.getValue();
if (button.isSelected() && (activeOperation instanceof BrushOperation)) {
button.setIcon(createBrushIcon(brush, 0));
((BrushOperation) activeOperation).setBrush(brush);
}
}
} else {
for (Map.Entry<Brush, JToggleButton> entry : brushButtons.entrySet()) {
Brush brush = entry.getKey();
JToggleButton button = entry.getValue();
if (button.isSelected() && (activeOperation instanceof BrushOperation)) {
button.setIcon(createBrushIcon(brush, desiredBrushRotation));
Brush rotatedBrush = RotatedBrush.rotate(brush, desiredBrushRotation);
((BrushOperation) activeOperation).setBrush(rotatedBrush);
}
}
}
view.setBrushRotation(desiredBrushRotation);
// if (logger.isDebugEnabled()) {
// logger.debug("Updating brush rotation took " + (System.currentTimeMillis() - start) + " ms");
// }
previousBrushRotation = desiredBrushRotation;
}
}
use of org.pepsoft.worldpainter.brushes.RotatedBrush in project WorldPainter by Captain-Chaos.
the class EditSelectionOperation method tick.
@Override
protected void tick(int centreX, int centreY, boolean inverse, boolean first, float dynamicLevel) {
// Create a geometric shape corresponding to the brush size, shape and
// rotation
Shape shape;
final Brush brush = getBrush();
final int brushRadius = brush.getRadius();
switch(brush.getBrushShape()) {
case BITMAP:
case SQUARE:
shape = new Rectangle(centreX - brushRadius, centreY - brushRadius, brushRadius * 2 + 1, brushRadius * 2 + 1);
if (brush instanceof RotatedBrush) {
int rotation = ((RotatedBrush) brush).getDegrees();
if (rotation != 0) {
shape = new Path2D.Float(shape, AffineTransform.getRotateInstance(rotation / DEGREES_TO_RADIANS, centreX, centreY));
}
}
break;
case CIRCLE:
shape = new Arc2D.Float(centreX - brushRadius, centreY - brushRadius, brushRadius * 2 + 1, brushRadius * 2 + 1, 0.0f, 360.0f, Arc2D.CHORD);
break;
default:
throw new InternalError();
}
final Dimension dimension = getDimension();
dimension.setEventsInhibited(true);
try {
SelectionHelper selectionHelper = new SelectionHelper(dimension);
if (inverse) {
selectionHelper.removeFromSelection(shape);
} else {
selectionHelper.addToSelection(shape);
// TODO: make this work correctly with undo/redo, and make "inside selection" ineffective when there is no selection, to avoid confusion
// selectionState.setValue(true);
}
} finally {
dimension.setEventsInhibited(false);
}
}
Aggregations