void JucerFillType::fillInGeneratedCode (GeneratedCode& code, String& paintMethodCode) const { String s; switch (mode) { case solidColour: s << "g.setColour (" << colourToCode (colour) << ");\n"; break; case linearGradient: case radialGradient: { String x1, y1, w, h, x2, y2; positionToCode (gradPos1, code.document->getComponentLayout(), x1, y1, w, h); positionToCode (gradPos2, code.document->getComponentLayout(), x2, y2, w, h); s << "g.setGradientFill (ColourGradient ("; const String indent (String::repeatedString (T(" "), s.length())); s << colourToCode (gradCol1) << ",\n" << indent << castToFloat (x1) << ", " << castToFloat (y1) << ",\n" << indent << colourToCode (gradCol2) << ",\n" << indent << castToFloat (x2) << ", " << castToFloat (y2) << ",\n" << indent << boolToString (mode == radialGradient) << "));\n"; break; } case imageBrush: { const String imageVariable ("cachedImage_" + imageResourceName + "_" + String (code.getUniqueSuffix())); code.addImageResourceLoader (imageVariable, imageResourceName); String x, y, w, h; positionToCode (imageAnchor, code.document->getComponentLayout(), x, y, w, h); s << "g.setTiledImageFill (*"; const String indent (String::repeatedString (T(" "), s.length())); s << imageVariable << ",\n" << indent << x << ", " << y << ",\n" << indent << valueToFloat (imageOpacity) << ");\n"; break; } default: jassertfalse break; } paintMethodCode += s; }
//============================================================================== static String positionToPairOfValues (const RelativePositionedRectangle& position, const ComponentLayout* layout) { String x, y, w, h; positionToCode (position, layout, x, y, w, h); return castToFloat (x) + ", " + castToFloat (y); }
void ComponentTypeHandler::fillInResizeCode (GeneratedCode& code, Component* component, const String& memberVariableName) { const RelativePositionedRectangle pos (getComponentPosition (component)); String x, y, w, h, r; positionToCode (pos, code.document->getComponentLayout(), x, y, w, h); r << memberVariableName << "->setBounds (" << x << ", " << y << ", " << w << ", " << h << ");\n"; if (pos.rect.isPositionAbsolute()) code.constructorCode += r + "\n"; else code.getCallbackCode (String::empty, "void", "resized()", false) += r; }
void positionToCode (const RelativePositionedRectangle& position, const ComponentLayout* layout, String& x, String& y, String& w, String& h) { // these are the code sections for the positions of the relative comps String xrx, xry, xrw, xrh; Component* const relCompX = layout != 0 ? layout->findComponentWithId (position.relativeToX) : 0; if (relCompX != 0) positionToCode (ComponentTypeHandler::getComponentPosition (relCompX), layout, xrx, xry, xrw, xrh); String yrx, yry, yrw, yrh; Component* const relCompY = layout != 0 ? layout->findComponentWithId (position.relativeToY) : 0; if (relCompY != 0) positionToCode (ComponentTypeHandler::getComponentPosition (relCompY), layout, yrx, yry, yrw, yrh); String wrx, wry, wrw, wrh; Component* const relCompW = (layout != 0 && position.rect.getWidthMode() != PositionedRectangle::absoluteSize) ? layout->findComponentWithId (position.relativeToW) : 0; if (relCompW != 0) positionToCode (ComponentTypeHandler::getComponentPosition (relCompW), layout, wrx, wry, wrw, wrh); String hrx, hry, hrw, hrh; Component* const relCompH = (layout != 0 && position.rect.getHeightMode() != PositionedRectangle::absoluteSize) ? layout->findComponentWithId (position.relativeToH) : 0; if (relCompH != 0) positionToCode (ComponentTypeHandler::getComponentPosition (relCompH), layout, hrx, hry, hrw, hrh); // width if (position.rect.getWidthMode() == PositionedRectangle::proportionalSize) { if (wrw.isNotEmpty()) w << "roundFloatToInt ((" << wrw << ") * " << valueToFloat (position.rect.getWidth()) << ")"; else w << "proportionOfWidth (" << valueToFloat (position.rect.getWidth()) << ")"; } else if (position.rect.getWidthMode() == PositionedRectangle::parentSizeMinusAbsolute) { if (wrw.isNotEmpty()) w << "(" << wrw << ") - " << roundToInt (position.rect.getWidth()); else w << "getWidth() - " << roundToInt (position.rect.getWidth()); } else { if (wrw.isNotEmpty()) w << "(" << wrw << ") + "; w << roundToInt (position.rect.getWidth()); } // height if (position.rect.getHeightMode() == PositionedRectangle::proportionalSize) { if (hrh.isNotEmpty()) h << "roundFloatToInt ((" << hrh << ") * " << valueToFloat (position.rect.getHeight()) << ")"; else h << "proportionOfHeight (" << valueToFloat (position.rect.getHeight()) << ")"; } else if (position.rect.getHeightMode() == PositionedRectangle::parentSizeMinusAbsolute) { if (hrh.isNotEmpty()) h << "(" << hrh << ") - " << roundToInt (position.rect.getHeight()); else h << "getHeight() - " << roundToInt (position.rect.getHeight()); } else { if (hrh.isNotEmpty()) h << "(" << hrh << ") + "; h << roundToInt (position.rect.getHeight()); } // x-pos if (position.rect.getPositionModeX() == PositionedRectangle::proportionOfParentSize) { if (xrx.isNotEmpty() && xrw.isNotEmpty()) x << "(" << xrx << ") + roundFloatToInt ((" << xrw << ") * " << valueToFloat (position.rect.getX()) << ")"; else x << "proportionOfWidth (" << valueToFloat (position.rect.getX()) << ")"; } else if (position.rect.getPositionModeX() == PositionedRectangle::absoluteFromParentTopLeft) { if (xrx.isNotEmpty()) x << "(" << xrx << ") + "; x << roundToInt (position.rect.getX()); } else if (position.rect.getPositionModeX() == PositionedRectangle::absoluteFromParentBottomRight) { if (xrx.isNotEmpty()) x << "(" << xrx << ") + (" << xrw << ")"; else x << "getWidth()"; const int d = roundToInt (position.rect.getX()); if (d != 0) x << " - " << d; } else if (position.rect.getPositionModeX() == PositionedRectangle::absoluteFromParentCentre) { if (xrx.isNotEmpty()) x << "(" << xrx << ") + (" << xrw << ") / 2"; else x << "(getWidth() / 2)"; const int d = roundToInt (position.rect.getX()); if (d != 0) x << " + " << d; } if (w != "0") { if (position.rect.getAnchorPointX() == PositionedRectangle::anchorAtRightOrBottom) x << " - " << w; else if (position.rect.getAnchorPointX() == PositionedRectangle::anchorAtCentre) x << " - ((" << w << ") / 2)"; } // y-pos if (position.rect.getPositionModeY() == PositionedRectangle::proportionOfParentSize) { if (yry.isNotEmpty() && yrh.isNotEmpty()) y << "(" << yry << ") + roundFloatToInt ((" << yrh << ") * " << valueToFloat (position.rect.getY()) << ")"; else y << "proportionOfHeight (" << valueToFloat (position.rect.getY()) << ")"; } else if (position.rect.getPositionModeY() == PositionedRectangle::absoluteFromParentTopLeft) { if (yry.isNotEmpty()) y << "(" << yry << ") + "; y << roundToInt (position.rect.getY()); } else if (position.rect.getPositionModeY() == PositionedRectangle::absoluteFromParentBottomRight) { if (yry.isNotEmpty()) y << "(" << yry << ") + (" << yrh << ")"; else y << "getHeight()"; const int d = roundToInt (position.rect.getY()); if (d != 0) y << " - " << d; } else if (position.rect.getPositionModeY() == PositionedRectangle::absoluteFromParentCentre) { if (yry.isNotEmpty()) y << "(" << yry << ") + (" << yrh << ") / 2"; else y << "(getHeight() / 2)"; const int d = roundToInt (position.rect.getY()); if (d != 0) y << " + " << d; } if (h != "0") { if (position.rect.getAnchorPointY() == PositionedRectangle::anchorAtRightOrBottom) y << " - " << h; else if (position.rect.getAnchorPointY() == PositionedRectangle::anchorAtCentre) y << " - ((" << h << ") / 2)"; } }