| 59 | } |
| 60 | |
| 61 | void DrawableImageParser::registerBaseParsers() { |
| 62 | mFuncs["linear-gradient"] = []( const FunctionString& functionType, const Sizef& /*size*/, |
| 63 | bool& ownIt, UINode* node ) -> Drawable* { |
| 64 | if ( functionType.getParameters().size() < 2 ) { |
| 65 | return NULL; |
| 66 | } |
| 67 | |
| 68 | RectangleDrawable* drawable = RectangleDrawable::New(); |
| 69 | RectColors rectColors; |
| 70 | const auto& params( functionType.getParameters() ); |
| 71 | |
| 72 | if ( Color::isColorString( params.at( 0 ) ) && params.size() >= 2 ) { |
| 73 | rectColors.TopLeft = rectColors.TopRight = Color::fromString( params.at( 0 ) ); |
| 74 | rectColors.BottomLeft = rectColors.BottomRight = Color::fromString( params.at( 1 ) ); |
| 75 | } else if ( params.size() >= 3 ) { |
| 76 | std::string direction = params.at( 0 ); |
| 77 | String::toLowerInPlace( direction ); |
| 78 | |
| 79 | if ( direction == "to bottom" ) { |
| 80 | rectColors.TopLeft = rectColors.TopRight = Color::fromString( params.at( 1 ) ); |
| 81 | rectColors.BottomLeft = rectColors.BottomRight = |
| 82 | Color::fromString( params.at( 2 ) ); |
| 83 | } else if ( direction == "to left" ) { |
| 84 | rectColors.TopLeft = rectColors.BottomLeft = Color::fromString( params.at( 2 ) ); |
| 85 | rectColors.TopRight = rectColors.BottomRight = Color::fromString( params.at( 1 ) ); |
| 86 | } else if ( direction == "to right" ) { |
| 87 | rectColors.TopLeft = rectColors.BottomLeft = Color::fromString( params.at( 1 ) ); |
| 88 | rectColors.TopRight = rectColors.BottomRight = Color::fromString( params.at( 2 ) ); |
| 89 | } else if ( direction == "to top" ) { |
| 90 | rectColors.TopLeft = rectColors.TopRight = Color::fromString( params.at( 2 ) ); |
| 91 | rectColors.BottomLeft = rectColors.BottomRight = |
| 92 | Color::fromString( params.at( 1 ) ); |
| 93 | } else { |
| 94 | rectColors.TopLeft = rectColors.TopRight = Color::fromString( params.at( 1 ) ); |
| 95 | rectColors.BottomLeft = rectColors.BottomRight = |
| 96 | Color::fromString( params.at( 2 ) ); |
| 97 | } |
| 98 | } else { |
| 99 | node->setBackgroundColor( Color::fromString( params.at( 0 ) ) ); |
| 100 | return NULL; |
| 101 | } |
| 102 | |
| 103 | drawable->setRectColors( rectColors ); |
| 104 | ownIt = true; |
| 105 | return drawable; |
| 106 | }; |
| 107 | |
| 108 | mFuncs["circle"] = []( const FunctionString& functionType, const Sizef& size, bool& ownIt, |
| 109 | UINode* node ) -> Drawable* { |
| 110 | if ( functionType.getParameters().size() < 1 ) { |
| 111 | return NULL; |
| 112 | } |
| 113 | |
| 114 | CircleDrawable* drawable = CircleDrawable::New(); |
| 115 | |
| 116 | const auto& params( functionType.getParameters() ); |
| 117 | |
| 118 | CSS::StyleSheetLength length( params[0] ); |
no test coverage detected