Search in sources :

Example 1 with RotatedBrush

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;
    }
}
Also used : Brush(org.pepsoft.worldpainter.brushes.Brush) SymmetricBrush(org.pepsoft.worldpainter.brushes.SymmetricBrush) RotatedBrush(org.pepsoft.worldpainter.brushes.RotatedBrush) BitmapBrush(org.pepsoft.worldpainter.brushes.BitmapBrush) Paint(org.pepsoft.worldpainter.painting.Paint)

Example 2 with RotatedBrush

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);
    }
}
Also used : Path2D(java.awt.geom.Path2D) Dimension(org.pepsoft.worldpainter.Dimension) Brush(org.pepsoft.worldpainter.brushes.Brush) RotatedBrush(org.pepsoft.worldpainter.brushes.RotatedBrush) Arc2D(java.awt.geom.Arc2D) RotatedBrush(org.pepsoft.worldpainter.brushes.RotatedBrush)

Aggregations

Brush (org.pepsoft.worldpainter.brushes.Brush)2 RotatedBrush (org.pepsoft.worldpainter.brushes.RotatedBrush)2 Arc2D (java.awt.geom.Arc2D)1 Path2D (java.awt.geom.Path2D)1 Dimension (org.pepsoft.worldpainter.Dimension)1 BitmapBrush (org.pepsoft.worldpainter.brushes.BitmapBrush)1 SymmetricBrush (org.pepsoft.worldpainter.brushes.SymmetricBrush)1 Paint (org.pepsoft.worldpainter.painting.Paint)1