You are here

public static function SassScriptFunctions::rgba in Sassy 7

Same name and namespace in other branches
  1. 7.3 phpsass/script/SassScriptFunctions.php \SassScriptFunctions::rgba()

* Creates a SassColour object from red, green, and blue values and alpha * channel (opacity). * There are two overloads: * * rgba(red, green, blue, alpha) *

Parameters

SassNumber the red component.: * A number between 0 and 255 inclusive, or between 0% and 100% inclusive * @param SassNumber the green component. * A number between 0 and 255 inclusive, or between 0% and 100% inclusive * @param SassNumber the blue component. * A number between 0 and 255 inclusive, or between 0% and 100% inclusive * @param SassNumber The alpha channel. A number between 0 and 1. * * * rgba(colour, alpha) * @param SassColour a SassColour object * @param SassNumber The alpha channel. A number between 0 and 1. * * @return new SassColour SassColour object * @throws SassScriptFunctionException if any of the red, green, or blue * colour components are out of bounds, or or the colour is not a colour, or * alpha is out of bounds

1 call to SassScriptFunctions::rgba()
SassScriptFunctions::rgb in phamlp/sass/script/SassScriptFunctions.php
* Creates a SassColour object from red, green, and blue values. *

File

phamlp/sass/script/SassScriptFunctions.php, line 84

Class

SassScriptFunctions
SassScript functions class. A collection of functions for use in SassSCript. @package PHamlP @subpackage Sass.script

Code

public static function rgba() {
  switch (func_num_args()) {
    case 2:
      $colour = func_get_arg(0);
      $alpha = func_get_arg(1);
      SassLiteral::assertType($colour, 'SassColour');
      SassLiteral::assertType($alpha, 'SassNumber');
      SassLiteral::assertInRange($alpha, 0, 1);
      return $colour
        ->with(array(
        'alpha' => $alpha->value,
      ));
      break;
    case 4:
      $rgba = array();
      $components = func_get_args();
      $alpha = array_pop($components);
      foreach ($components as $component) {
        SassLiteral::assertType($component, 'SassNumber');
        if ($component->units == '%') {
          SassLiteral::assertInRange($component, 0, 100, '%');
          $rgba[] = $component->value * 2.55;
        }
        else {
          SassLiteral::assertInRange($component, 0, 255);
          $rgba[] = $component->value;
        }
      }
      SassLiteral::assertType($alpha, 'SassNumber');
      SassLiteral::assertInRange($alpha, 0, 1);
      $rgba[] = $alpha->value;
      return new SassColour($rgba);
      break;
    default:
      throw new SassScriptFunctionException('Incorrect argument count for {method}; expected {expected}, received {received}', array(
        '{method}' => __METHOD__,
        '{expected}' => '2 or 4',
        '{received}' => func_num_args(),
      ), SassScriptParser::$context->node);
  }
}