std::string ConvertIntRect(const sf::IntRect theRect) { // Use StringStream class to convert theRect to a string std::stringstream anResult; // Add theRect to the stringstream #if (SFML_VERSION_MAJOR < 2) anResult << theRect.Top << ", "; anResult << theRect.Left << ", "; anResult << theRect.GetWidth() << ", "; anResult << theRect.GetHeight(); #else anResult << theRect.top << ", "; anResult << theRect.left << ", "; anResult << theRect.width << ", "; anResult << theRect.height; #endif // Return the string result created by stringstream return anResult.str(); }
sf::IntRect ParseIntRect(const std::string theValue, const sf::IntRect theDefault) { sf::IntRect anResult = theDefault; // Try to find the first comma size_t anComma1Offset = theValue.find_first_of(','); if(anComma1Offset != std::string::npos) { #if (SFML_VERSION_MAJOR < 2) sf::Int32 anLeft = ParseInt32(theValue.substr(0,anComma1Offset), theDefault.Left); #else sf::Int32 anLeft = ParseInt32(theValue.substr(0,anComma1Offset), theDefault.left); #endif // Try to find the next comma size_t anComma2Offset = theValue.find_first_of(',',anComma1Offset+1); if(anComma2Offset != std::string::npos) { #if (SFML_VERSION_MAJOR < 2) sf::Int32 anTop = ParseInt32(theValue.substr(anComma1Offset+1,anComma2Offset), theDefault.Top); #else sf::Int32 anTop = ParseInt32(theValue.substr(anComma1Offset+1,anComma2Offset), theDefault.top); #endif // Try to find the next comma size_t anComma3Offset = theValue.find_first_of(',',anComma2Offset+1); if(anComma3Offset != std::string::npos) { #if (SFML_VERSION_MAJOR < 2) // Get the width and height values sf::Int32 anWidth = ParseInt32(theValue.substr(anComma2Offset+1,anComma3Offset), theDefault.GetWidth()); sf::Int32 anHeight = ParseInt32(theValue.substr(anComma3Offset+1), theDefault.GetHeight()); // Now that all 4 values have been parsed, return the color found anResult.Left = anLeft; anResult.Top = anTop; anResult.Right = anLeft+anWidth; anResult.Bottom = anTop+anHeight; #else // Get the width and height values sf::Int32 anWidth = ParseInt32(theValue.substr(anComma2Offset+1,anComma3Offset), theDefault.width); sf::Int32 anHeight = ParseInt32(theValue.substr(anComma3Offset+1), theDefault.height); // Now that all 4 values have been parsed, return the color found anResult.left = anLeft; anResult.top = anTop; anResult.width = anWidth; anResult.height = anHeight; #endif } } } // Return the result found or theDefault assigned above return anResult; }