1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
/**
* Paints the equipment.
*/
private void paintEquipment(Graphics2D g2D, List<Object> selectedItems,
Paint selectionOutlinePaint, Stroke selectionOutlineStroke,
Paint indicatorPaint, float planScale,
Color backgroundColor, Color foregroundColor, PaintMode paintMode) {
BasicStroke pieceBorderStroke = new BasicStroke(1f / planScale);
if (this.sortedDrawingEquipment == null) {
// Sort slip equipment in elevation order
this.sortedDrawingEquipment =
new ArrayList<DrawingEquipment>(this.slip.getEquipment());
}
// Draw furniture
for (DrawingEquipment piece : this.sortedDrawingEquipment) {
if (piece.isVisible()) {
boolean selectedPiece = selectedItems.contains(piece);
// In clipboard paint mode, paint piece only if it is selected
if (paintMode != PaintMode.CLIPBOARD
|| selectedPiece) {
Shape pieceShape = getShape(piece.getPoints());
// Fill piece area
g2D.setPaint(backgroundColor);
g2D.fill(pieceShape);
// Draw its icon
paintEquipmentIcon(g2D, piece, pieceShape, planScale);
if (selectedPiece
&& paintMode == PaintMode.PAINT) {
// Draw selection border
g2D.setPaint(selectionOutlinePaint);
g2D.setStroke(selectionOutlineStroke);
g2D.draw(pieceShape);
}
// Draw its border
g2D.setPaint(foregroundColor);
g2D.setStroke(pieceBorderStroke);
g2D.draw(pieceShape);
if (selectedItems.size() == 1
&& selectedItems.get(0) == piece
&& paintMode == PaintMode.PAINT) {
paintEquipmentIndicators(g2D,
(DrawingEquipment)selectedItems.get(0), indicatorPaint, planScale);
}
}
}
}
}
/**
* dessine un icône avec g2D
*/
private void paintEquipmentIcon(Graphics2D g2D, DrawingEquipment piece,
Shape pieceShape, float planScale) {
Shape previousClip = g2D.getClip();
// Clip icon drawing into piece shape
g2D.clip(pieceShape);
AffineTransform previousTransform = g2D.getTransform();
// Get piece icon
Icon icon = IconManager.getInstance().getIcon(piece.getIcon(), 128, this);
// Translate to piece center
g2D.translate(piece.getX(), piece.getY());
// Scale icon to fit in its area
float minDimension = Math.min(piece.getWidth(), piece.getHeight());
float iconScale = Math.min(1 / planScale, minDimension / icon.getIconHeight());
g2D.scale(iconScale, iconScale);
// Paint piece icon
icon.paintIcon(this, g2D, -icon.getIconWidth() / 2, -icon.getIconHeight() / 2);
// Revert g2D transformation to previous value
g2D.setTransform(previousTransform);
g2D.setClip(previousClip);
} |
Partager