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);
}
}
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);
}
}
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);
}
}
}
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);
}
}
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();
}
}
}
Aggregations