GradientDecorator( const PropertyDictionary& properties ) { // fetch the properties from the dict String prop_dir = properties.GetProperty( "dir" )->Get<String>(); start = properties.GetProperty( "start" )->Get<Colourb>(); end = properties.GetProperty( "end" )->Get<Colourb>(); // enumerate direction property dir = ( prop_dir == "horizontal" ? HORIZONTAL : VERTICAL ); }
// Retrieves all the properties for a tile from the property dictionary. void DecoratorTiledInstancer::GetTileProperties(DecoratorTiled::Tile& tile, String& texture_name, String& rcss_path, const PropertyDictionary& properties, const String& name) { LoadTexCoord(properties, String(32, "%s-s-begin", name.CString()), tile.texcoords[0].x, tile.texcoords_absolute[0][0]); LoadTexCoord(properties, String(32, "%s-t-begin", name.CString()), tile.texcoords[0].y, tile.texcoords_absolute[0][1]); LoadTexCoord(properties, String(32, "%s-s-end", name.CString()), tile.texcoords[1].x, tile.texcoords_absolute[1][0]); LoadTexCoord(properties, String(32, "%s-t-end", name.CString()), tile.texcoords[1].y, tile.texcoords_absolute[1][1]); const Property* repeat_property = properties.GetProperty(String(32, "%s-repeat", name.CString())); if (repeat_property != NULL) tile.repeat_mode = (DecoratorTiled::TileRepeatMode) repeat_property->value.Get< int >(); const Property* texture_property = properties.GetProperty(String(32, "%s-src", name.CString())); texture_name = texture_property->Get< String >(); rcss_path = texture_property->source; }
// Sets all undefined properties in the dictionary to their defaults. void PropertySpecification::SetPropertyDefaults(PropertyDictionary& dictionary) const { for (PropertyMap::const_iterator i = properties.begin(); i != properties.end(); ++i) { if (dictionary.GetProperty((*i).first) == NULL) dictionary.SetProperty((*i).first, *(*i).second->GetDefaultValue()); } }
// Get decorator-id property from properties or "" if not id is given. String DecoratorInstancer::GetDecoratorIdProperty(const PropertyDictionary& properties) { const Property* id_property = properties.GetProperty("decorator-id"); if (id_property) { String decorator_id = id_property->Get< String >(); return decorator_id; } return ""; }
// Loads a single texture coordinate value from the properties. void DecoratorTiledInstancer::LoadTexCoord(const PropertyDictionary& properties, const String& name, float& tex_coord, bool& tex_coord_absolute) { const Property* property = properties.GetProperty(name); if (property == NULL) return; tex_coord = property->value.Get< float >(); if (property->unit == Property::PX) tex_coord_absolute = true; else { tex_coord_absolute = false; if (property->unit == Property::PERCENT) tex_coord *= 0.01f; } }
// Returns the floating-point value of a numerical property from a dictionary of properties. float Decorator::ResolveProperty(const PropertyDictionary& properties, const String& name, float base_value) const { const Property* property = properties.GetProperty(name); if (property == NULL) { ROCKET_ERROR; return 0; } // Need to include em! if (property->unit & Property::RELATIVE_UNIT) return base_value * property->value.Get< float >() * 0.01f; if (property->unit & Property::NUMBER || property->unit & Property::PX) return property->value.Get< float >(); if (property->unit & Property::GSP) return property->value.Get< float >() * Rocket::Core::GetRenderInterface()->GetPixelScale(); // Values based on pixels-per-inch. if (property->unit & Property::PPI_UNIT) { float inch = property->value.Get< float >() * 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; } ROCKET_ERROR; return 0; }