Search in sources :

Example 11 with Dimension

use of org.pepsoft.worldpainter.Dimension 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 12 with Dimension

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

the class Sponge method tick.

@Override
protected void tick(int centreX, int centreY, boolean inverse, boolean first, float dynamicLevel) {
    final int waterHeight;
    final Dimension dimension = getDimension();
    final TileFactory tileFactory = dimension.getTileFactory();
    if (tileFactory instanceof HeightMapTileFactory) {
        waterHeight = ((HeightMapTileFactory) tileFactory).getWaterHeight();
    } else {
        // If we can't determine the water height disable the inverse
        // functionality, which resets to the default water height
        waterHeight = -1;
    }
    dimension.setEventsInhibited(true);
    try {
        final int radius = getEffectiveRadius();
        for (int dx = -radius; dx <= radius; dx++) {
            for (int dy = -radius; dy <= radius; dy++) {
                if (getStrength(centreX, centreY, centreX + dx, centreY + dy) != 0f) {
                    if (inverse) {
                        if (waterHeight != -1) {
                            dimension.setWaterLevelAt(centreX + dx, centreY + dy, waterHeight);
                            dimension.setBitLayerValueAt(FloodWithLava.INSTANCE, centreX + dx, centreY + dy, false);
                        }
                    } else {
                        dimension.setWaterLevelAt(centreX + dx, centreY + dy, 0);
                    }
                }
            }
        }
    } finally {
        dimension.setEventsInhibited(false);
    }
}
Also used : HeightMapTileFactory(org.pepsoft.worldpainter.HeightMapTileFactory) Dimension(org.pepsoft.worldpainter.Dimension) TileFactory(org.pepsoft.worldpainter.TileFactory) HeightMapTileFactory(org.pepsoft.worldpainter.HeightMapTileFactory)

Example 13 with Dimension

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

the class Text method tick.

@Override
protected void tick(int centreX, int centreY, boolean inverse, boolean first, float dynamicLevel) {
    if (painter.getPaint() instanceof PaintFactory.NullPaint) {
        // No paint set yet; do nothing
        return;
    }
    AnnotationsExporter.AnnotationsSettings settings = (AnnotationsExporter.AnnotationsSettings) getDimension().getLayerSettings(Annotations.INSTANCE);
    if (settings == null) {
        settings = new AnnotationsExporter.AnnotationsSettings();
    }
    TextDialog dialog = new TextDialog(SwingUtilities.getWindowAncestor(getView()), settings.getDefaultFont(), settings.getDefaultSize(), savedText);
    dialog.setVisible(true);
    if (!dialog.isCancelled()) {
        Font font = dialog.getSelectedFont();
        settings.setDefaultFont(font.getFamily());
        settings.setDefaultSize(font.getSize());
        Dimension dimension = getDimension();
        dimension.setLayerSettings(Annotations.INSTANCE, settings);
        painter.setFont(font);
        painter.setTextAngle(dialog.getSelectedAngle());
        savedText = dialog.getText();
        dimension.setEventsInhibited(true);
        try {
            painter.drawText(dimension, centreX, centreY, savedText);
        } finally {
            dimension.setEventsInhibited(false);
        }
    }
}
Also used : AnnotationsExporter(org.pepsoft.worldpainter.layers.exporters.AnnotationsExporter) Dimension(org.pepsoft.worldpainter.Dimension)

Example 14 with Dimension

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

the class Flatten method tick.

@Override
protected void tick(final int centreX, final int centreY, final boolean inverse, final boolean first, final float dynamicLevel) {
    Dimension dimension = getDimension();
    if (first) {
        targetHeight = dimension.getHeightAt(centreX, centreY);
    }
    dimension.setEventsInhibited(true);
    try {
        int radius = getEffectiveRadius();
        boolean applyTheme = options.isApplyTheme();
        for (int x = centreX - radius; x <= centreX + radius; x++) {
            for (int y = centreY - radius; y <= centreY + radius; y++) {
                float currentHeight = dimension.getHeightAt(x, y);
                float strength = dynamicLevel * getStrength(centreX, centreY, x, y);
                if (strength > 0.0f) {
                    float newHeight = strength * targetHeight + (1f - strength) * currentHeight;
                    dimension.setHeightAt(x, y, newHeight);
                    if (applyTheme) {
                        dimension.applyTheme(x, y);
                    }
                }
            }
        }
    } finally {
        dimension.setEventsInhibited(false);
    }
}
Also used : Dimension(org.pepsoft.worldpainter.Dimension)

Example 15 with Dimension

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

the class MouseOrTabletOperation method mouseReleased.

@Override
public void mouseReleased(MouseEvent me) {
    if (!oneShot) {
        if (timer != null) {
            logOperation(undo ? statisticsKeyUndo : statisticsKey);
            timer.stop();
            timer = null;
        }
        finished();
        Dimension dimension = getDimension();
        if (dimension != null) {
            dimension.armSavePoint();
        }
    }
}
Also used : Dimension(org.pepsoft.worldpainter.Dimension)

Aggregations

Dimension (org.pepsoft.worldpainter.Dimension)39 File (java.io.File)9 Tile (org.pepsoft.worldpainter.Tile)7 World2 (org.pepsoft.worldpainter.World2)6 EventVO (org.pepsoft.worldpainter.vo.EventVO)6 FileOutputStream (java.io.FileOutputStream)5 ProgressReceiver (org.pepsoft.util.ProgressReceiver)5 java.awt (java.awt)4 FileInputStream (java.io.FileInputStream)4 ObjectInputStream (java.io.ObjectInputStream)4 GZIPInputStream (java.util.zip.GZIPInputStream)4 SubProgressReceiver (org.pepsoft.util.SubProgressReceiver)4 ObjectOutputStream (java.io.ObjectOutputStream)3 java.util (java.util)3 List (java.util.List)3 Map (java.util.Map)3 GZIPOutputStream (java.util.zip.GZIPOutputStream)3 FileInUseException (org.pepsoft.worldpainter.util.FileInUseException)3 java.awt.event (java.awt.event)2 PropertyVetoException (java.beans.PropertyVetoException)2