Commit 45820803 by Aaron Leung

Implemented "opacify" and "transparentize" and their aliases.

parent 664c020b
...@@ -44,6 +44,10 @@ namespace Sass { ...@@ -44,6 +44,10 @@ namespace Sass {
// Opacity Functions // Opacity Functions
register_function(alpha_descriptor, alpha); register_function(alpha_descriptor, alpha);
register_function(opacity_descriptor, alpha); register_function(opacity_descriptor, alpha);
register_function(opacify_descriptor, opacify);
register_function(fade_in_descriptor, opacify);
register_function(transparentize_descriptor, transparentize);
register_function(fade_out_descriptor, transparentize);
// String Functions // String Functions
register_function(unquote_descriptor, unquote); register_function(unquote_descriptor, unquote);
register_function(quote_descriptor, quote); register_function(quote_descriptor, quote);
......
#include "functions.hpp" #include "functions.hpp"
#include <iostream> #include <iostream>
#include <cmath>
using std::cerr; using std::endl; using std::cerr; using std::endl;
namespace Sass { namespace Sass {
...@@ -111,6 +112,28 @@ namespace Sass { ...@@ -111,6 +112,28 @@ namespace Sass {
Node alpha(const vector<Token>& parameters, map<Token, Node>& bindings) { Node alpha(const vector<Token>& parameters, map<Token, Node>& bindings) {
return bindings[parameters[0]][3]; return bindings[parameters[0]][3];
} }
Function_Descriptor opacify_descriptor =
{ "opacify", "$color", "$amount", 0 };
Function_Descriptor fade_in_descriptor =
{ "fade_in", "$color", "$amount", 0 };
Node opacify(const vector<Token>& parameters, map<Token, Node>& bindings) {
Node cpy(bindings[parameters[0]].clone());
cpy[3].content.numeric_value += bindings[parameters[1]].content.numeric_value;
if (cpy[3].content.numeric_value >= 1) cpy[3].content.numeric_value = 1;
return cpy;
}
Function_Descriptor transparentize_descriptor =
{ "transparentize", "$color", "$amount", 0 };
Function_Descriptor fade_out_descriptor =
{ "fade_out", "$color", "$amount", 0 };
Node transparentize(const vector<Token>& parameters, map<Token, Node>& bindings) {
Node cpy(bindings[parameters[0]].clone());
cpy[3].content.numeric_value -= bindings[parameters[1]].content.numeric_value;
if (cpy[3].content.numeric_value <= 0) cpy[3].content.numeric_value = 0;
return cpy;
}
// String Functions //////////////////////////////////////////////////// // String Functions ////////////////////////////////////////////////////
......
...@@ -77,6 +77,14 @@ namespace Sass { ...@@ -77,6 +77,14 @@ namespace Sass {
extern Function_Descriptor opacity_descriptor; extern Function_Descriptor opacity_descriptor;
Node alpha(const vector<Token>& parameters, map<Token, Node>& bindings); Node alpha(const vector<Token>& parameters, map<Token, Node>& bindings);
extern Function_Descriptor opacify_descriptor;
extern Function_Descriptor fade_in_descriptor;
Node opacify(const vector<Token>& parameters, map<Token, Node>& bindings);
extern Function_Descriptor transparentize_descriptor;
extern Function_Descriptor fade_out_descriptor;
Node transparentize(const vector<Token>& parameters, map<Token, Node>& bindings);
// String Functions //////////////////////////////////////////////////// // String Functions ////////////////////////////////////////////////////
extern Function_Descriptor unquote_descriptor; extern Function_Descriptor unquote_descriptor;
Node unquote(const vector<Token>& parameters, map<Token, Node>& bindings); Node unquote(const vector<Token>& parameters, map<Token, Node>& bindings);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment