本文整理汇总了C++中rocket::core::Element::ResolveProperty方法的典型用法代码示例。如果您正苦于以下问题:C++ Element::ResolveProperty方法的具体用法?C++ Element::ResolveProperty怎么用?C++ Element::ResolveProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rocket::core::Element
的用法示例。
在下文中一共展示了Element::ResolveProperty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ResolveProperty
// Resolves one of this element's properties.
float ElementStyle::ResolveProperty(const String& name, float base_value)
{
const Property* property = GetProperty(name);
if (!property)
{
ROCKET_ERROR;
return 0.0f;
}
if (property->unit & Property::RELATIVE_UNIT)
{
// The calculated value of the font-size property is inherited, so we need to check if this
// is an inherited property. If so, then we return our parent's font size instead.
if (name == FONT_SIZE)
{
Rocket::Core::Element* parent = element->GetParentNode();
if (parent == NULL)
return 0;
if (GetLocalProperty(FONT_SIZE) == NULL)
return parent->ResolveProperty(FONT_SIZE, 0);
// The base value for font size is always the height of *this* element's parent's font.
base_value = parent->ResolveProperty(FONT_SIZE, 0);
}
if (property->unit & Property::PERCENT)
return base_value * property->value.Get< float >() * 0.01f;
else if (property->unit & Property::EM)
{
// If an em-relative font size is specified, it is expressed relative to the parent's
// font height.
if (name == FONT_SIZE)
return property->value.Get< float >() * base_value;
else
return property->value.Get< float >() * ElementUtilities::GetFontSize(element);
}
}
if (property->unit & Property::NUMBER || property->unit & Property::PX)
{
return property->value.Get< float >();
}
// We're not a numeric property; return 0.
return 0.0f;
}
示例2: ResolveProperty
// Resolves one of this element's properties.
float ElementStyle::ResolveProperty(const String& name, float base_value)
{
const Property* property = GetProperty(name);
if (!property)
{
ROCKET_ERROR;
return 0.0f;
}
if (property->unit & Property::RELATIVE_UNIT)
{
// The calculated value of the font-size property is inherited, so we need to check if this
// is an inherited property. If so, then we return our parent's font size instead.
if (name == FONT_SIZE)
{
// If the rem unit is used, the font-size is inherited directly from the document,
// otherwise we use the parent's font size.
if (property->unit & Property::REM)
{
Rocket::Core::ElementDocument* owner_document = element->GetOwnerDocument();
if (owner_document == NULL)
return 0;
base_value = element->GetOwnerDocument()->ResolveProperty(FONT_SIZE, 0);
}
else
{
Rocket::Core::Element* parent = element->GetParentNode();
if (parent == NULL)
return 0;
if (GetLocalProperty(FONT_SIZE) == NULL)
return parent->ResolveProperty(FONT_SIZE, 0);
// The base value for font size is always the height of *this* element's parent's font.
base_value = parent->ResolveProperty(FONT_SIZE, 0);
}
}
if (property->unit & Property::PERCENT)
return base_value * property->value.Get< float >() * 0.01f;
else if (property->unit & Property::EM)
{
// If an em-relative font size is specified, it is expressed relative to the parent's
// font height.
if (name == FONT_SIZE)
return property->value.Get< float >() * base_value;
else
return property->value.Get< float >() * ElementUtilities::GetFontSize(element);
}
else if (property->unit & Property::REM)
{
// If an rem-relative font size is specified, it is expressed relative to the document's
// font height.
if (name == FONT_SIZE)
return property->value.Get< float >() * base_value;
else
return property->value.Get< float >() * ElementUtilities::GetFontSize(element->GetOwnerDocument());
}
}
if (property->unit & Property::NUMBER || property->unit & Property::PX)
{
return property->value.Get< float >();
}
// Values based on pixels-per-inch.
if (property->unit & Property::PPI_UNIT)
{
float inch = property->value.Get< float >() * element->GetRenderInterface()->GetPixelsPerInch();
if (property->unit & Property::INCH) // inch
return inch;
if (property->unit & Property::CM) // centimeter
return inch / 2.54f;
if (property->unit & Property::MM) // millimeter
return inch / 25.4f;
if (property->unit & Property::PT) // point
return inch / 72.0f;
if (property->unit & Property::PC) // pica
return inch / 6.0f;
}
// We're not a numeric property; return 0.
return 0.0f;
}