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