bool XMLScreenLoader::loadText(XMLHandle &rootHandle, std::vector<Text>* text) { XMLElement *currElement = rootHandle.FirstChildElement("text").ToElement(); //grab the first element under the text section if (currElement){ do { Text tempText{}; currElement->QueryFloatAttribute("z", &tempText.z); currElement->QueryFloatAttribute("top", &tempText.top); currElement->QueryFloatAttribute("size", &tempText.size); if(!extractColor(currElement, &tempText.color)) return false; tempText.align = currElement->Attribute("align"); if (tempText.align != "centered" and tempText.align != "left" and tempText.align != "right") { Util::Log(Error, "XMLScreenLoader") << "Alignment \"" << tempText.align << "\" is not supported!"; continue; } tempText.text = currElement->GetText(); text->push_back(tempText); } while((currElement = currElement->NextSiblingElement("text")) != nullptr); } else return false; return true; }
std::shared_ptr<Screen> XMLScreenLoader::loadScreen(const std::string &path) { std::shared_ptr<Screen> screen = std::make_shared<Screen>(); //setup screen pointer XMLDocument doc; XMLError error = doc.LoadFile(path.c_str()); //load in XML document if (error == 0){ XMLHandle docHandle(&doc); XMLElement *element = docHandle.FirstChildElement("screen").ToElement(); XMLHandle rootHandle = XMLHandle(element); //screen->textColor = loadTextColor(rootHandle); //screen->bgColor = loadbgColor(rootHandle); if (!loadText(rootHandle, &screen->text)) Util::Log(Error, "XMLScreenLoader") << "Failed to load text in " << path; if (!extractColor(element, &screen->color)) Util::Log(Error, "XMLScreenLoader") << "Failed to load color in " << path; //if (screen->bgColor.x == 0) Util::Log(Error, "XMLScreenLoader") << "Failed to find background color element in " << path; Util::Log(Debug, "XMLScreenLoader") << "Screen " << path << " loaded"; return screen; } else { Util::Log(Error, "XMLScreenLoader") << "Failed to load screen " << path; return nullptr; } }
bool Label::setProperty(std::string property, const std::string& value) { property = toLower(property); if (property == "configfile") { load(value); } else if (property == "text") { std::string text; decodeString(value, text); setText(text); } else if (property == "textcolor") { setTextColor(extractColor(value)); } else if (property == "textsize") { setTextSize(atoi(value.c_str())); } else if (property == "backgroundcolor") { setBackgroundColor(extractColor(value)); } else if (property == "autosize") { if ((value == "true") || (value == "True")) setAutoSize(true); else if ((value == "false") || (value == "False")) setAutoSize(false); else TGUI_OUTPUT("TGUI error: Failed to parse 'AutoSize' property."); } else // The property didn't match return ClickableWidget::setProperty(property, value); // You pass here when one of the properties matched return true; }
bool FourierDCT::setup(const FilterData &data) { if (ImageTransformFilter::setup(data)) { if (mFormat == QImage::Format_ARGB32 || mFormat == QImage::Format_ARGB32_Premultiplied) { qWarning() << "transparancy in the image is discarded"; mImg.convertToFormat(QImage::Format_RGB32); } mSize = QSize(1, 1); while (mSize.width() < mImg.width() || mSize.height() < mImg.height()) { mSize *= 2; } int layers; switch (mFormat) { case QImage::Format_Indexed8: layers = 1; break; case QImage::Format_ARGB32: case QImage::Format_RGB32: layers = 3; break; default: return false; } // the array created here might be bigger than image size - it has to be // a square of side length 2^n delete mCA; int w = mSize.width(); int h = mSize.height(); mCA = new ComplexArray(boost::extents[layers * 2][w][h]); mFirst = false; // fill only the data that exists in the image for (int i = 0; i < layers; i++) { for (int y = 0; y < mImg.height(); y++) { for (int x = 0; x < mImg.width(); x++) { (*mCA)[i * 2][y][x] = Complex(extractColor(mImg.pixel(x, y), i), 0); } } } return true; } else { return false; } }
bool Label::load(const std::string& configFileFilename) { m_LoadedConfigFile = configFileFilename; // Open the config file ConfigFile configFile; if (!configFile.open(configFileFilename)) { TGUI_OUTPUT("TGUI error: Failed to open " + configFileFilename + "."); return false; } // Read the properties and their values (as strings) std::vector<std::string> properties; std::vector<std::string> values; if (!configFile.read("Label", properties, values)) { TGUI_OUTPUT("TGUI error: Failed to parse " + configFileFilename + "."); return false; } // Close the config file configFile.close(); // Handle the read properties for (unsigned int i = 0; i < properties.size(); ++i) { std::string property = properties[i]; std::string value = values[i]; if (property == "textcolor") { setTextColor(extractColor(value)); } else TGUI_OUTPUT("TGUI warning: Unrecognized property '" + property + "' in section Label in " + configFileFilename + "."); } return false; }
bool XmlScreenLoader::loadText(XMLHandle &rootHandle, std::vector<Text>* textVector) { //grab the first element under the text section XMLElement *currentElement = rootHandle.FirstChildElement("text").ToElement(); if (currentElement) { do { Text text{}; std::string align; currentElement->QueryFloatAttribute("z", &text.z); currentElement->QueryFloatAttribute("top", &text.top); currentElement->QueryFloatAttribute("size", &text.size); if (not extractColor(currentElement, &text.color)) { return false; } align = currentElement->Attribute("align"); if (align == "center") { text.align = Text::Center; } else if (align == "left") { text.align = Text::Left; } else if (align == "right") { text.align = Text::Right; } else { Util::Log(Error, XmlScreenLoader::MODULE_NAME) << "Alignment \"" << align << "\" is not supported!"; continue; } text.content = currentElement->GetText(); textVector->push_back(text); } while ((currentElement = currentElement->NextSiblingElement("text")) != nullptr); } else { return false; } return true; }
std::shared_ptr<Screen> XmlScreenLoader::loadScreen(const std::string &path) { XMLDocument doc(true, COLLAPSE_WHITESPACE); XMLError error = doc.LoadFile(path.c_str()); const std::string &module = XmlScreenLoader::MODULE_NAME; if (error == 0) { std::shared_ptr<Screen> screen = std::make_shared<Screen>(); //setup screen pointer XMLHandle docHandle(&doc); XMLElement *element = docHandle.FirstChildElement("screen").ToElement(); XMLHandle rootHandle = XMLHandle(element); if (not loadText(rootHandle, &screen->text)) { XmlScreenLoader::handleFailureForElement(module, std::string("text"), path); } if (not extractColor(element, &screen->color)) { XmlScreenLoader::handleFailureForElement(module, std::string("color"), path); } Util::Log(Debug, module) << "Screen " << path << " loaded"; return screen; } throw std::runtime_error("Failed to load " + path + ": " + errorName(error)); }
void AIPlayer::decide(int partial, int depth) { //fprintf(stderr, " Decision %d on %d - Depth = %d\n",partial+1,DISPATCHCYCLES,depth); if (partial == 0) { // get flobo binoms to drop FloboState etat; etat = attachedGame->getFallingState(); if (etat == FLOBO_EMPTY) return; current.falling = extractColor(etat); etat = attachedGame->getCompanionState(); if (etat == FLOBO_EMPTY) return; current.companion = extractColor(etat); current.orientation = extractOrientation(attachedGame->getFallingCompanionDir()); current.position.x = attachedGame->getFallingX(); current.position.y = FLOBOBAN_DIMY - attachedGame->getFallingY(); originalFlobo = current; next.falling = extractColor(attachedGame->getNextFalling()); next.companion = extractColor(attachedGame->getNextCompanion()); next.orientation = Left; next.position.x = 0; next.position.y = IA_FLOBOBAN_DIMY+1; bestl1=1; foundOne = false; bestEvaluation = 0; } switch (depth) { case 1: for (unsigned int l1 = 1+partial; l1 <= MAXCOMBINATION; l1+=DISPATCHCYCLES) { // set position of binom 1 serialPosition(l1,¤t); // reset evaluation GridEvaluation evaluation1 = nullEvaluation; GridState state1; // drop the binom (including destroying eligible groups) and continue if game not lost if (canReach(originalFlobo, current, internalGrid, 1) && dropBinom(current, internalGrid, &state1, &evaluation1)) { evalWith(&state1, &nullEvaluation, &evaluation1); if (foundOne == false || selectIfBetterEvaluation(&bestEvaluation, &evaluation1, current, &state1)) { bestl1 = l1; } foundOne = true; } } if (foundOne) serialPosition(bestl1,¤t); objective = current; break; case 2: for (unsigned int l1 = 1+partial; l1 <= MAXCOMBINATION; l1+=DISPATCHCYCLES) { // set position of binom 1 serialPosition(l1,¤t); // reset evaluation GridEvaluation evaluation1 = nullEvaluation; GridState state1; // drop the binom (including destroying eligible groups) and continue if game not lost if (canReach(originalFlobo, current, internalGrid, 1) && dropBinom(current, internalGrid, &state1, &evaluation1)) { for (unsigned int l2 = 1; l2 <= MAXCOMBINATION; l2++) { // set position of binom 1 serialPosition(l2,&next); // copy evaluation GridEvaluation evaluation2 = evaluation1; GridState state1bis; GridState state2; dropNeutrals(lastNumberOfBadFlobos-evaluation1.floboSuppressed, totalNumberOfBadFlobos, &state1bis, &state1); // drop the binom (including destroying eligible groups) and eval board if game not lost if (canReach(originalFlobo, next, &state1bis, 1) && dropBinom(next, &state1bis, &state2, &evaluation2)) { evalWith(&state2, &evaluation1, &evaluation2); if (foundOne == false || selectIfBetterEvaluation(&bestEvaluation, &evaluation2, current, &state2)) { bestl1 = l1; } foundOne = true; } } } } if (foundOne) serialPosition(bestl1,¤t); objective = current; break; default: objective.position.x = (random() % IA_FLOBOBAN_DIMX); objective.orientation = (FloboOrientation)(random() % 4); break; } }
// identifierar alla mesharna i scenen och extraherar data fr�n dem bool Exporter::IdentifyAndExtractMeshes() { UINT index = 0; scene_.meshes.clear(); //itererar �ver DG:n och lagrar rgba-v�rden och texturnamn i ett tempor�rt material material tempmaterial; MItDependencyNodes matIt(MFn::kLambert); MString aC("ambientColor"), dC("color"), sC("specularColor"), gC("incandescence"), tC("transparency"); while (!matIt.isDone()){ if (matIt.item().hasFn(MFn::kPhong)) { MFnPhongShader tempphong(matIt.item()); tempmaterial.type = PHONG; extractColor(tempmaterial.ambient, tempphong, aC); extractColor(tempmaterial.diffuse, tempphong, dC); extractColor(tempmaterial.specular, tempphong, sC); extractColor(tempmaterial.glow, tempphong, gC); extractColor(tempmaterial.transparency, tempphong, tC); } else if (matIt.thisNode().hasFn(MFn::kBlinn)) { MFnBlinnShader tempblinn(matIt.item()); tempmaterial.type = BLINN; extractColor(tempmaterial.ambient, tempblinn, aC); extractColor(tempmaterial.diffuse, tempblinn, dC); extractColor(tempmaterial.specular, tempblinn, sC); extractColor(tempmaterial.glow, tempblinn, gC); extractColor(tempmaterial.transparency, tempblinn, tC); } else if (matIt.item().hasFn(MFn::kLambert)) { MFnLambertShader templamb(matIt.item()); tempmaterial.type = LAMBERT; extractColor(tempmaterial.ambient, templamb, aC); extractColor(tempmaterial.diffuse, templamb, dC); extractColor(tempmaterial.specular, templamb, sC); extractColor(tempmaterial.glow, templamb, gC); extractColor(tempmaterial.transparency, templamb, tC); } else printf("No material found\n"); scene_.materials.push_back(tempmaterial); matIt.next(); } //Turn off or on Blendshapes matIt.reset(MFn::kBlendShape); while (!matIt.isDone()) { MFnBlendShapeDeformer bs(matIt.item()); //Get the envelope attribute plug MPlug pl = bs.findPlug("en"); //Set the 0 to disable FFD effect, enable by setting it to 1: pl.setValue(1.0f); matIt.next(); } //Get Actual Blendshapes matIt.reset(MFn::kBlendShape); while (!matIt.isDone()) { MFnBlendShapeDeformer bs(matIt.item()); MObjectArray base_objects; //print blend shape name cout << "Blendshape " << bs.name().asChar() << endl; //Get a list of objects that this blend shape deforms bs.getBaseObjects(base_objects); cout << "NumBaseOBjects " << base_objects.length() << endl; //loop through each blendshaped object for (int i = 0; i < base_objects.length(); ++i) { //Get the base shape MObject Base = base_objects[i]; //Output all of the target shapes and weights OutputBlendShapes(bs, Base); } //Get next blend shapes matIt.next(); } MDagPath dag_path; MItDag dag_iter(MItDag::kBreadthFirst, MFn::kMesh); while (!dag_iter.isDone()) { if (dag_iter.getPath(dag_path)) { MFnDagNode dag_node = dag_path.node(); // vill endast ha "icke-history"-f�rem�l if (!dag_node.isIntermediateObject()) { // triangulera meshen innan man h�mtar punkterna MFnMesh mesh(dag_path); ExtractMeshData(mesh, index); index++; } } dag_iter.next(); } MItDependencyNodes it(MFn::kSkinClusterFilter); for (; !it.isDone(); it.next()) { MObject object = it.item(); OutputSkinCluster(object); } //Hitta kamera data dag_iter.reset(dag_iter.root(), MItDag::kBreadthFirst, MFn::kCamera); while (!dag_iter.isDone()) { extractCamera(dag_iter.item()); dag_iter.next(); } //itererar dag och s�ker data f�r tillg�ngliga ljus //om ej ljus finns i scenen ignoreras denna iteration f�r sagda scen. dag_iter.reset(dag_iter.root(), MItDag::kBreadthFirst, MFn::kLight); while (!dag_iter.isDone()) { //funktion till v�r iterator MFnLight func(dag_iter.item()); //namn: export_stream_ << "Light: " << func.name().asChar() << std::endl; //kalla p�EextractLight function extractLight(dag_iter.item()); //vidare till n�sta ljus i dag'en dag_iter.next(); /* if (dag_iter.getPath(dag_path)) { auto test = dag_path.fullPathName(); export_stream_ << "light: " << test << std::endl; } dag_iter.next(); */ } dag_iter.reset(dag_iter.root(), MItDag::kBreadthFirst, MFn::kJoint); while (!dag_iter.isDone()) { if (dag_iter.getPath(dag_path)) { MFnDagNode dag_node = dag_path.node(); if (!dag_node.isIntermediateObject()) { extractJointData(dag_path); } } dag_iter.next(); } int breadth=0; dag_iter.reset(dag_iter.root(), MItDag::kBreadthFirst, MFn::kTransform); while (!dag_iter.isDone()) { int depth = dag_iter.depth(); if (depth > 1) break; if (dag_iter.getPath(dag_path)) { createSceneGraph(MFnDagNode(dag_path),-1); } breadth++; dag_iter.next(); } /* //general purpose iterator, sista argument �r filtret dag_iter.reset(dag_iter.root(), MItDag::kBreadthFirst, MFn::kLight); while (!dag_iter.isDone()) { if (dag_iter.getPath(dag_path)) { } dag_iter.next(); } */ return true; }
bool Checkbox::load(const std::string pathname) { // When everything is loaded successfully, this will become true. m_Loaded = false; // Make sure that the pathname isn't empty if (pathname.empty()) return false; // Store the pathname m_LoadedPathname = pathname; // When the pathname does not end with a "/" then we will add it if (m_LoadedPathname.at(m_LoadedPathname.length()-1) != '/') m_LoadedPathname.push_back('/'); // Open the info file InfoFileParser infoFile; if (infoFile.openFile(m_LoadedPathname + "info.txt") == false) { TGUI_OUTPUT((((std::string("TGUI: Failed to open ")).append(m_LoadedPathname)).append("info.txt")).c_str()); return false; } std::string property; std::string value; std::string imageExtension = "png"; // Read untill the end of the file while (infoFile.readProperty(property, value)) { // Check what the property is if (property.compare("phases") == 0) { // Get and store the different phases extractPhases(value); } else if (property.compare("textcolor") == 0) { m_Text.setColor(extractColor(value)); } else if (property.compare("extension") == 0) { imageExtension = value; } } // Close the info file infoFile.closeFile(); // If the checkbox was loaded before then remove the old textures if (m_TextureUnchecked != NULL) TGUI_TextureManager.removeTexture(m_TextureUnchecked); if (m_TextureChecked != NULL) TGUI_TextureManager.removeTexture(m_TextureChecked); if (m_TextureMouseHover != NULL) TGUI_TextureManager.removeTexture(m_TextureMouseHover); if (m_TextureFocused != NULL) TGUI_TextureManager.removeTexture(m_TextureFocused); // load the required textures if ((TGUI_TextureManager.getTexture(m_LoadedPathname + "Checked." + imageExtension, m_TextureChecked)) && (TGUI_TextureManager.getTexture(m_LoadedPathname + "Unchecked." + imageExtension, m_TextureUnchecked))) { m_SpriteChecked.setTexture(*m_TextureChecked, true); m_SpriteUnchecked.setTexture(*m_TextureUnchecked, true); } else return false; bool error = false; // load the optional textures if (m_ObjectPhase & objectPhase::focused) { if (TGUI_TextureManager.getTexture(m_LoadedPathname + "Focus." + imageExtension, m_TextureFocused)) { m_SpriteFocused.setTexture(*m_TextureFocused, true); m_AllowFocus = true; } else error = true; } if (m_ObjectPhase & objectPhase::hover) { if (TGUI_TextureManager.getTexture(m_LoadedPathname + "Hover." + imageExtension, m_TextureMouseHover)) m_SpriteMouseHover.setTexture(*m_TextureMouseHover, true); else error = true; } // When there is no error we will return true m_Loaded = !error; return !error; }
bool Checkbox::setProperty(std::string property, const std::string& value) { property = toLower(property); if (property == "configfile") { load(value); } else if (property == "checked") { if ((value == "true") || (value == "True")) check(); else if ((value == "false") || (value == "False")) uncheck(); else TGUI_OUTPUT("TGUI error: Failed to parse 'Checked' property."); } else if (property == "text") { setText(value); } else if (property == "textcolor") { setTextColor(extractColor(value)); } else if (property == "textsize") { setTextSize(atoi(value.c_str())); } else if (property == "allowtextclick") { if ((value == "true") || (value == "True")) allowTextClick(true); else if ((value == "false") || (value == "False")) allowTextClick(false); else TGUI_OUTPUT("TGUI error: Failed to parse 'AllowTextClick' property."); } else if (property == "callback") { ClickableWidget::setProperty(property, value); std::vector<sf::String> callbacks; decodeList(value, callbacks); for (auto it = callbacks.begin(); it != callbacks.end(); ++it) { if ((*it == "Checked") || (*it == "checked")) bindCallback(Checked); else if ((*it == "Unchecked") || (*it == "unchecked")) bindCallback(Unchecked); else if ((*it == "SpaceKeyPressed") || (*it == "spacekeypressed")) bindCallback(SpaceKeyPressed); else if ((*it == "ReturnKeyPressed") || (*it == "returnkeypressed")) bindCallback(ReturnKeyPressed); } } else // The property didn't match return ClickableWidget::setProperty(property, value); // You pass here when one of the properties matched return true; }