use of org.w3c.dom.svg.SVGRectElement in project megameklab by MegaMek.
the class PrintMech method drawHeatSinkPips.
private void drawHeatSinkPips(SVGRectElement svgRect) {
Rectangle2D bbox = getRectBBox(svgRect);
Element canvas = (Element) ((Node) svgRect).getParentNode();
int viewWidth = (int) bbox.getWidth();
int viewHeight = (int) bbox.getHeight();
int viewX = (int) bbox.getX();
int viewY = (int) bbox.getY();
int hsCount = mech.heatSinks();
// r = 3.5
// spacing = 9.66
// stroke width = 0.9
double size = 9.66;
int cols = (int) (viewWidth / size);
int rows = (int) (viewHeight / size);
// Use 10 pips/column unless there are too many sinks for the space.
if (hsCount <= cols * 10) {
rows = 10;
}
// The rare unit with this many heat sinks will require us to shrink the pips
while (hsCount > rows * cols) {
// Figure out how much we will have to shrink to add another column
double nextCol = (cols + 1.0) / cols;
// First check whether we can shrink them less than what is required for a new column
if (cols * (int) (rows * nextCol) > hsCount) {
rows = (int) Math.ceil((double) hsCount / cols);
size = viewHeight / rows;
} else {
cols++;
size = viewWidth / (cols * size);
rows = (int) (viewHeight / size);
}
}
double radius = size * 0.36;
double strokeWidth = 0.9;
for (int i = 0; i < hsCount; i++) {
int row = i % rows;
int col = i / rows;
Element pip = createPip(viewX + size * col, viewY + size * row, radius, strokeWidth);
canvas.appendChild(pip);
}
}
use of org.w3c.dom.svg.SVGRectElement in project megameklab by MegaMek.
the class PrintMech method printImage.
@Override
public void printImage(Graphics2D g2d, PageFormat pageFormat, int pageNum) {
printShields();
super.printImage(g2d, pageFormat, pageNum);
for (int loc = 0; loc < mech.locations(); loc++) {
Element critRect = getSVGDocument().getElementById("crits_" + mech.getLocationAbbr(loc));
if ((null != critRect) && (critRect instanceof SVGRectElement)) {
writeLocationCriticals(loc, (SVGRectElement) critRect);
}
}
hideElement("heavyDutyGyroPip", mech.getGyroType() != Mech.GYRO_HEAVY_DUTY);
Element hsRect = getSVGDocument().getElementById("heatSinkPips");
if ((null != hsRect) && (hsRect instanceof SVGRectElement)) {
drawHeatSinkPips((SVGRectElement) hsRect);
}
if (mech.hasETypeFlag(Entity.ETYPE_LAND_AIR_MECH)) {
Element si = getSVGDocument().getElementById("siPips");
addPips(si, mech.getOInternal(Mech.LOC_CT), true, PipType.CIRCLE, 0.38, 0.957);
}
}
Aggregations