本文整理汇总了C++中GeneratedCode类的典型用法代码示例。如果您正苦于以下问题:C++ GeneratedCode类的具体用法?C++ GeneratedCode怎么用?C++ GeneratedCode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GeneratedCode类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generated
bool JucerDocument::flushChangesToDocuments()
{
String headerTemplate, cppTemplate;
if (! findTemplateFiles (headerTemplate, cppTemplate))
return false;
GeneratedCode generated (this);
fillInGeneratedCode (generated);
const File headerFile (getHeaderFile());
generated.includeFilesCPP.insert (0, headerFile.getFileName());
OpenDocumentManager& odm = IntrojucerApp::getApp().openDocumentManager;
if (SourceCodeDocument* header = dynamic_cast <SourceCodeDocument*> (odm.openFile (nullptr, getHeaderFile())))
{
String existingHeader (header->getCodeDocument().getAllContent());
String existingCpp (cpp->getCodeDocument().getAllContent());
generated.applyToCode (headerTemplate, headerFile.getFileNameWithoutExtension(), false, existingHeader);
generated.applyToCode (cppTemplate, headerFile.getFileNameWithoutExtension(), false, existingCpp);
headerTemplate = fixLineEndings (headerTemplate);
cppTemplate = fixLineEndings (cppTemplate);
if (header->getCodeDocument().getAllContent() != headerTemplate)
header->getCodeDocument().replaceAllContent (headerTemplate);
if (cpp->getCodeDocument().getAllContent() != cppTemplate)
cpp->getCodeDocument().replaceAllContent (cppTemplate);
}
userDocChangeTimer = nullptr;
return true;
}
示例2: fillInGeneratedCode
//==============================================================================
void ButtonDocument::fillInGeneratedCode (GeneratedCode& code) const
{
JucerDocument::fillInGeneratedCode (code);
code.parentClassInitialiser = "Button (" + quotedString (code.componentName) + ")";
code.removeCallback ("void", "paint (Graphics& g)");
}
示例3: fillInGeneratedCode
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;
}
示例4: fillInResizeCode
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;
}
示例5: fillInCreationCode
void ComponentTypeHandler::fillInCreationCode (GeneratedCode& code, Component* component, const String& memberVariableName)
{
String params (getCreationParameters (code, component));
const String virtualName (component->getProperties() ["virtualName"].toString());
String s;
s << memberVariableName << ".reset (new ";
if (virtualName.isNotEmpty())
s << CodeHelpers::makeValidIdentifier (virtualName, false, false, true);
else
s << getClassName (component);
if (params.isEmpty())
{
s << "());\n";
}
else
{
StringArray lines;
lines.addLines (params);
params = lines.joinIntoString ("\n" + String::repeatedString (" ", s.length() + 2));
s << " (" << params << "));\n";
}
s << "addAndMakeVisible (" << memberVariableName << ".get());\n";
if (SettableTooltipClient* ttc = dynamic_cast<SettableTooltipClient*> (component))
{
if (ttc->getTooltip().isNotEmpty())
{
s << memberVariableName << "->setTooltip ("
<< quotedString (ttc->getTooltip(), code.shouldUseTransMacro())
<< ");\n";
}
}
if (component->getExplicitFocusOrder() > 0)
s << memberVariableName << "->setExplicitFocusOrder ("
<< component->getExplicitFocusOrder()
<< ");\n";
code.constructorCode += s;
}
示例6: getPaintRoutine
void JucerDocument::fillInPaintCode (GeneratedCode& code) const
{
for (int i = 0; i < getNumPaintRoutines(); ++i)
getPaintRoutine (i)
->fillInGeneratedCode (code, code.getCallbackCode (String::empty, "void", "paint (Graphics& g)", false));
}
示例7: quotedString
//==============================================================================
void JucerDocument::fillInGeneratedCode (GeneratedCode& code) const
{
code.className = className;
code.componentName = componentName;
code.parentClasses = parentClasses;
code.constructorParams = constructorParams;
code.initialisers.addLines (variableInitialisers);
if (! componentName.isEmpty())
code.constructorCode << "setName (" + quotedString (componentName, false) + ");\n";
// call these now, just to make sure they're the first two methods in the list.
code.getCallbackCode (String::empty, "void", "paint (Graphics& g)", false)
<< "//[UserPrePaint] Add your own custom painting code here..\n//[/UserPrePaint]\n\n";
code.getCallbackCode (String::empty, "void", "resized()", false)
<< "//[UserPreResize] Add your own custom resize code here..\n//[/UserPreResize]\n\n";
if (ComponentLayout* l = getComponentLayout())
l->fillInGeneratedCode (code);
fillInPaintCode (code);
ScopedPointer<XmlElement> e (createXml());
jassert (e != nullptr);
code.jucerMetadata = e->createDocument ("", false, false);
resources.fillInGeneratedCode (code);
code.constructorCode
<< "\n//[UserPreSize]\n"
"//[/UserPreSize]\n";
if (initialWidth > 0 || initialHeight > 0)
code.constructorCode << "\nsetSize (" << initialWidth << ", " << initialHeight << ");\n";
code.getCallbackCode (String::empty, "void", "paint (Graphics& g)", false)
<< "//[UserPaint] Add your own custom painting code here..\n//[/UserPaint]";
code.getCallbackCode (String::empty, "void", "resized()", false)
<< "//[UserResized] Add your own custom resize handling here..\n//[/UserResized]";
// add optional methods
StringArray baseClasses, returnValues, methods, initialContents;
getOptionalMethods (baseClasses, returnValues, methods, initialContents);
for (int i = 0; i < methods.size(); ++i)
{
if (isOptionalMethodEnabled (methods[i]))
{
String baseClassToAdd (baseClasses[i]);
if (baseClassToAdd == "Component" || baseClassToAdd == "Button")
baseClassToAdd.clear();
String& s = code.getCallbackCode (baseClassToAdd, returnValues[i], methods[i], false);
if (! s.contains ("//["))
{
String userCommentTag ("UserCode_");
userCommentTag += methods[i].upToFirstOccurrenceOf ("(", false, false).trim();
s << "\n//[" << userCommentTag << "] -- Add your code here...\n"
<< initialContents[i];
if (initialContents[i].isNotEmpty() && ! initialContents[i].endsWithChar ('\n'))
s << '\n';
s << "//[/" << userCommentTag << "]\n";
}
}
}
}
示例8: jassert
void ButtonDocument::fillInPaintCode (GeneratedCode& code) const
{
jassert (paintStatesEnabled [normalOff]);
String paintCode [7];
for (int i = 0; i < 7; ++i)
if (paintStatesEnabled [i])
paintRoutines[i]->fillInGeneratedCode (code, paintCode [i]);
String& s = code.getCallbackCode ("public Button",
"void",
"paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)",
false);
int numPaintRoutines = getNumPaintRoutines();
if (paintStatesEnabled [background])
{
s << paintCode [background] << "\n";
--numPaintRoutines;
}
if (numPaintRoutines == 1)
{
s << paintCode [normalOff];
}
else if (numPaintRoutines == downOff && (paintStatesEnabled [overOff] || paintStatesEnabled [downOff] || paintStatesEnabled [normalOn]))
{
if (paintStatesEnabled [normalOn])
{
s << "if (getToggleState())\n{\n "
<< indentCode (paintCode [normalOn], 4).trimEnd();
}
else if (paintStatesEnabled [overOff])
{
s << "if (isButtonDown || isMouseOverButton)\n{\n "
<< indentCode (paintCode [overOff], 4).trimEnd();
}
else
{
s << "if (isButtonDown)\n{\n "
<< indentCode (paintCode [downOff], 4).trimEnd();
}
s << "\n}\nelse\n{\n "
<< indentCode (paintCode [normalOff], 4).trimEnd()
<< "\n}\n";
}
else if (numPaintRoutines == normalOn && paintStatesEnabled [overOff] && paintStatesEnabled [downOff])
{
s << "if (isButtonDown)\n{\n "
<< indentCode (paintCode [downOff], 4).trimEnd()
<< "\n}\nelse if (isMouseOverButton)\n{\n "
<< indentCode (paintCode [overOff], 4).trimEnd()
<< "\n}\nelse\n{\n "
<< indentCode (paintCode [normalOff], 4).trimEnd()
<< "\n}\n";
}
else
{
if (paintStatesEnabled [normalOn] || paintStatesEnabled [overOn] || paintStatesEnabled [downOn])
{
s << "switch (getToggleState() ? (isButtonDown ? "
<< chooseBestEnabledPaintRoutine (downOn) << " : (isMouseOverButton ? "
<< chooseBestEnabledPaintRoutine (overOn) << " : "
<< chooseBestEnabledPaintRoutine (normalOn) << "))\n : (isButtonDown ? "
<< chooseBestEnabledPaintRoutine (downOff) << " : (isMouseOverButton ? "
<< chooseBestEnabledPaintRoutine (overOff) << " : 0)))\n{\n";
}
else
{
s << "switch (isButtonDown ? " << chooseBestEnabledPaintRoutine (downOff)
<< " : (isMouseOverButton ? " << chooseBestEnabledPaintRoutine (overOff)
<< " : 0))\n{\n";
}
for (int i = 0; i < 6; ++i)
{
if (paintStatesEnabled [i])
{
s << "case " << i << ":\n {\n "
<< indentCode (paintCode [i], 8).trimEnd()
<< "\n break;\n }\n\n";
}
}
s << "default:\n break;\n}\n";
}
}
示例9: pathVariable
void PaintElementPath::fillInGeneratedCode (GeneratedCode& code, String& paintMethodCode)
{
if (fillType.isInvisible() && (strokeType.isInvisible() || ! isStrokePresent))
return;
const String pathVariable ("internalPath" + String (code.getUniqueSuffix()));
const ComponentLayout* layout = code.document->getComponentLayout();
code.privateMemberDeclarations
<< "Path " << pathVariable << ";\n";
String r;
bool somePointsAreRelative = false;
if (! nonZeroWinding)
r << pathVariable << ".setUsingNonZeroWinding (false);\n";
for (int i = 0; i < points.size(); ++i)
{
const PathPoint* const p = points.getUnchecked(i);
switch (p->type)
{
case Path::Iterator::startNewSubPath:
r << pathVariable << ".startNewSubPath (" << positionToPairOfValues (p->pos[0], layout) << ");\n";
somePointsAreRelative = somePointsAreRelative || ! p->pos[0].rect.isPositionAbsolute();
break;
case Path::Iterator::lineTo:
r << pathVariable << ".lineTo (" << positionToPairOfValues (p->pos[0], layout) << ");\n";
somePointsAreRelative = somePointsAreRelative || ! p->pos[0].rect.isPositionAbsolute();
break;
case Path::Iterator::quadraticTo:
r << pathVariable << ".quadraticTo (" << positionToPairOfValues (p->pos[0], layout)
<< ", " << positionToPairOfValues (p->pos[1], layout) << ");\n";
somePointsAreRelative = somePointsAreRelative || ! p->pos[0].rect.isPositionAbsolute();
somePointsAreRelative = somePointsAreRelative || ! p->pos[1].rect.isPositionAbsolute();
break;
case Path::Iterator::cubicTo:
r << pathVariable << ".cubicTo (" << positionToPairOfValues (p->pos[0], layout)
<< ", " << positionToPairOfValues (p->pos[1], layout)
<< ", " << positionToPairOfValues (p->pos[2], layout) << ");\n";
somePointsAreRelative = somePointsAreRelative || ! p->pos[0].rect.isPositionAbsolute();
somePointsAreRelative = somePointsAreRelative || ! p->pos[1].rect.isPositionAbsolute();
somePointsAreRelative = somePointsAreRelative || ! p->pos[2].rect.isPositionAbsolute();
break;
case Path::Iterator::closePath:
r << pathVariable << ".closeSubPath();\n";
break;
default:
jassertfalse;
break;
}
}
r << '\n';
if (somePointsAreRelative)
code.getCallbackCode (String::empty, "void", "resized()", false)
<< pathVariable << ".clear();\n" << r;
else
code.constructorCode << r;
if (! fillType.isInvisible())
{
fillType.fillInGeneratedCode (code, paintMethodCode);
paintMethodCode << "g.fillPath (" << pathVariable << ");\n";
}
if (isStrokePresent && ! strokeType.isInvisible())
{
String s;
strokeType.fill.fillInGeneratedCode (code, s);
s << "g.strokePath (" << pathVariable << ", " << strokeType.getPathStrokeCode() << ");\n";
paintMethodCode += s;
}
paintMethodCode += "\n";
}