NetAnim: Provide opacity setting for background

This commit is contained in:
John Abraham
2014-01-12 11:25:42 -08:00
parent b24053a707
commit 2b72b059ae
3 changed files with 13 additions and 6 deletions

View File

@@ -171,7 +171,7 @@ int main (int argc, char *argv[])
// Provide the absolute path to the resource
resourceId1 = pAnim->AddResource ("./ns-3-logo1.png");
resourceId2 = pAnim->AddResource ("./ns-3-logo2.png");
pAnim->SetBackgroundImage ("./ns-3-background.png", 0, 0, 1, 1);
pAnim->SetBackgroundImage ("./ns-3-background.png", 0, 0, 0.2, 0.2, 0.1);
Simulator::Schedule (Seconds (0.1), modify);
// Set up the acutal simulation

View File

@@ -1798,10 +1798,14 @@ void AnimationInterface::SetBoundary (double minX, double minY, double maxX, dou
userBoundary->yMin = minY;
}
void AnimationInterface::SetBackgroundImage (std::string fileName, double x, double y, double scaleX, double scaleY)
void AnimationInterface::SetBackgroundImage (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
{
if ((opacity < 0) || (opacity > 1))
{
NS_FATAL_ERROR ("Opacity must be between 0.0 and 1.0");
}
std::ostringstream oss;
oss << GetXMLOpenCloseUpdateBackground (fileName, x, y, scaleX, scaleY);
oss << GetXMLOpenCloseUpdateBackground (fileName, x, y, scaleX, scaleY, opacity);
WriteN (oss.str (), m_f);
}
@@ -2264,7 +2268,7 @@ std::string AnimationInterface::GetXMLOpenCloseUpdateNodeDescription (uint32_t n
return oss.str ();
}
std::string AnimationInterface::GetXMLOpenCloseUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY)
std::string AnimationInterface::GetXMLOpenCloseUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity)
{
std::ostringstream oss;
oss << "<bg f=\"" << fileName << "\""
@@ -2272,6 +2276,7 @@ std::string AnimationInterface::GetXMLOpenCloseUpdateBackground (std::string fil
<< " y=\"" << y << "\""
<< " sx=\"" << scaleX << "\""
<< " sy=\"" << scaleY << "\""
<< " o=\"" << opacity << "\""
<< "/>" << std::endl;
return oss.str ();
}

View File

@@ -352,8 +352,10 @@ public:
* \param y Y co-ordinate of the image
* \param scaleX X scale of the image
* \param scaleY Y scale of the image
* \param opacity Opacity of the background: A value between 0.0 and 1.0. 0.0 is transparent,
* 1.0 is opaque
*/
void SetBackgroundImage (std::string fileName, double x, double y, double scaleX=1, double scaleY=1);
void SetBackgroundImage (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity);
/**
* \brief Helper function to set the description for a link
@@ -712,7 +714,7 @@ private:
std::string GetXMLOpenClose_NonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType);
std::string GetXMLOpenClose_routing (uint32_t id, std::string routingInfo);
std::string GetXMLOpenClose_rp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements);
std::string GetXMLOpenCloseUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY);
std::string GetXMLOpenCloseUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity);
void AppendXMLNodeDescription (std::ostream& ostream, uint32_t id) const;
void AppendXMLNodeColor (std::ostream& ostream, const Rgb& color) const;