Search in sources :

Example 1 with Brush

use of org.pepsoft.worldpainter.brushes.Brush 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 Brush

use of org.pepsoft.worldpainter.brushes.Brush 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)

Example 3 with Brush

use of org.pepsoft.worldpainter.brushes.Brush in project WorldPainter by Captain-Chaos.

the class App method loadCustomBrushes.

private void loadCustomBrushes(String category, File brushesDir) {
    File[] files = brushesDir.listFiles(new java.io.FileFilter() {

        @Override
        public boolean accept(File pathname) {
            if (pathname.isDirectory()) {
                return true;
            }
            String name = pathname.getName();
            for (String extension : extensions) {
                if (name.toLowerCase().endsWith(extension)) {
                    return true;
                }
            }
            return false;
        }

        private final String[] extensions = ImageIO.getReaderFileSuffixes();
    });
    List<Brush> brushes = new ArrayList<>();
    for (File file : files) {
        if (file.isDirectory()) {
            loadCustomBrushes(file.getName(), file);
        } else {
            try {
                brushes.add(new BitmapBrush(file));
            } catch (RuntimeException e) {
                logger.error("There was an error loading custom brush image file " + file.getName() + "; skipping file", e);
            }
        }
    }
    if (!brushes.isEmpty()) {
        customBrushes.put(category, brushes);
    }
}
Also used : BitmapBrush(org.pepsoft.worldpainter.brushes.BitmapBrush) java.io(java.io) Brush(org.pepsoft.worldpainter.brushes.Brush) SymmetricBrush(org.pepsoft.worldpainter.brushes.SymmetricBrush) RotatedBrush(org.pepsoft.worldpainter.brushes.RotatedBrush) BitmapBrush(org.pepsoft.worldpainter.brushes.BitmapBrush)

Example 4 with Brush

use of org.pepsoft.worldpainter.brushes.Brush in project WorldPainter by Captain-Chaos.

the class App method createCustomBrushPanel.

private JPanel createCustomBrushPanel(String title, List<Brush> customBrushes) {
    JPanel customBrushesPanel = new JPanel();
    customBrushesPanel.setLayout(new GridBagLayout());
    JPanel customBrushPanel = new JPanel(new GridLayout(0, 3));
    for (Brush customBrush : customBrushes) {
        customBrushPanel.add(createBrushButton(customBrush));
    }
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.anchor = GridBagConstraints.FIRST_LINE_START;
    constraints.weightx = 1.0;
    constraints.insets = new Insets(1, 1, 1, 1);
    customBrushesPanel.add(customBrushPanel, constraints);
    return customBrushesPanel;
}
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)

Aggregations

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