Search in sources :

Example 6 with SVGRectElement

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);
    }
}
Also used : SVGRectElement(org.w3c.dom.svg.SVGRectElement) Element(org.w3c.dom.Element) Rectangle2D(java.awt.geom.Rectangle2D)

Example 7 with SVGRectElement

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);
    }
}
Also used : SVGRectElement(org.w3c.dom.svg.SVGRectElement) SVGRectElement(org.w3c.dom.svg.SVGRectElement) Element(org.w3c.dom.Element)

Aggregations

Element (org.w3c.dom.Element)7 SVGRectElement (org.w3c.dom.svg.SVGRectElement)7 Rectangle2D (java.awt.geom.Rectangle2D)5 StringJoiner (java.util.StringJoiner)2 MiscType (megamek.common.MiscType)2 Mounted (megamek.common.Mounted)2 IOption (megamek.common.options.IOption)2 IOptionGroup (megamek.common.options.IOptionGroup)2 SVGGraphicsElement (org.apache.batik.anim.dom.SVGGraphicsElement)2 SVGTextContentElement (org.w3c.dom.svg.SVGTextContentElement)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 AmmoType (megamek.common.AmmoType)1 CriticalSlot (megamek.common.CriticalSlot)1 UnitRole (megamek.common.UnitRole)1 PilotOptions (megamek.common.options.PilotOptions)1 Quirks (megamek.common.options.Quirks)1 RecordSheetEquipmentLine (megameklab.com.util.RecordSheetEquipmentLine)1