コード例 #1
0
ファイル: Color.php プロジェクト: MrHidalgo/css-crush
 public static function parse($str)
 {
     if ($test = Color::test($str)) {
         $color = $test['value'];
         $type = $test['type'];
     } else {
         return false;
     }
     $rgba = false;
     switch ($type) {
         case 'hex':
             $rgba = Color::hexToRgb($color);
             break;
         case 'rgb':
         case 'rgba':
         case 'hsl':
         case 'hsla':
             $function = $type;
             $vals = substr($color, strlen($function) + 1);
             // Trim function name and start paren.
             $vals = substr($vals, 0, strlen($vals) - 1);
             // Trim end paren.
             $vals = array_map('trim', explode(',', $vals));
             // Explode to array of arguments.
             // Always set the alpha channel.
             $vals[3] = isset($vals[3]) ? floatval($vals[3]) : 1;
             if (strpos($function, 'rgb') === 0) {
                 $rgba = Color::normalizeCssRgb($vals);
             } else {
                 $rgba = Color::cssHslToRgb($vals);
             }
             break;
         case 'keyword':
             $keywords = self::getKeywords();
             $rgba = $keywords[$color];
             break;
     }
     return $rgba;
 }
コード例 #2
0
 /**
  * Get attributes for steel meter shortcodes.
  *
  * @return  string  $attributes The attributes of the value queryed by the shortcode.
  * @since    2.2.0
  */
 public function steelmeter_attributes($attributes)
 {
     require_once LWS_INCLUDES_DIR . 'phpcolors/Color.php';
     $result = array();
     $values = $this->steelmeter_value($attributes, true);
     $result['minValue'] = $values['min'];
     $result['maxValue'] = $values['max'];
     $min = $values['min'];
     $max = $values['max'];
     if (strpos($attributes['design'], 'windcompass') !== false) {
         $min = 0;
         $max = 360;
     }
     $digital = strpos($attributes['design'], 'digital') > -1;
     if (strpos($attributes['design'], '-1-4') !== false) {
         $result['gaugeType'] = 'steelseries.GaugeType.TYPE1';
     }
     if (strpos($attributes['design'], '-2-4') !== false) {
         $result['gaugeType'] = 'steelseries.GaugeType.TYPE2';
     }
     if (strpos($attributes['design'], '-3-4') !== false) {
         $result['gaugeType'] = 'steelseries.GaugeType.TYPE3';
     }
     if (strpos($attributes['design'], '-4-4') !== false) {
         $result['gaugeType'] = 'steelseries.GaugeType.TYPE4';
     }
     if (strpos($attributes['design'], '-left') !== false) {
         $result['orientation'] = 'steelseries.Orientation.WEST';
     }
     if (strpos($attributes['design'], '-right') !== false) {
         $result['orientation'] = 'steelseries.Orientation.EAST';
     }
     if (strpos($attributes['design'], 'windcompass-modern') !== false) {
         $result['pointSymbolsVisible'] = false;
     }
     $result['frameDesign'] = 'steelseries.FrameDesign.' . $attributes['frame'];
     $result['backgroundColor'] = 'steelseries.BackgroundColor.' . $attributes['background'];
     if ($attributes['orientation'] != 'AUTO') {
         $result['tickLabelOrientation'] = 'steelseries.TickLabelOrientation.' . $attributes['orientation'];
     }
     $result['pointerType'] = 'steelseries.PointerType.' . $attributes['main_pointer_type'];
     $result['pointerTypeLatest'] = 'steelseries.PointerType.' . $attributes['main_pointer_type'];
     $result['pointerColor'] = 'steelseries.ColorDef.' . $attributes['main_pointer_color'];
     $result['pointerTypeAverage'] = 'steelseries.PointerType.' . $attributes['aux_pointer_type'];
     $result['pointerColorAverage'] = 'steelseries.ColorDef.' . $attributes['aux_pointer_color'];
     $knob = explode('-', $attributes['knob']);
     $result['knobType'] = 'steelseries.KnobType.' . $knob[0];
     $result['knobStyle'] = 'steelseries.KnobStyle.' . $knob[1];
     if ($attributes['lcd'] == 'NONE') {
         $result['lcdVisible'] = false;
     } else {
         $result['lcdColor'] = 'steelseries.LcdColor.' . $attributes['lcd'];
     }
     if ($attributes['alarm'] != 'NONE') {
         $result['userLedVisible'] = true;
         $result['userLedColor'] = 'steelseries.LedColor.' . $attributes['alarm'];
     }
     if ($attributes['trend'] != 'NONE') {
         $result['trendVisible'] = true;
         $result['trendColors'] = '[steelseries.LedColor.' . $attributes['trend'] . ', steelseries.LedColor.' . $attributes['trend'] . ', steelseries.LedColor.' . $attributes['trend'] . ']';
     }
     if ($attributes['minmax'] == 'cursor') {
         $result['minMeasuredValueVisible'] = true;
         $result['maxMeasuredValueVisible'] = true;
     }
     if ($attributes['index_style'] != 'NONE') {
         $style = explode('-', $attributes['index_style']);
         $tcolor = new Color(Color::nameToHex($attributes['index_color']));
         $alpha = 0;
         $lighten = 1;
         if (isset($style[1])) {
             switch (strtolower($style[1])) {
                 case 'translucent':
                     $alpha = 0.1;
                     if ($tcolor->isVeryDark()) {
                         $lighten = 40;
                     } else {
                         $lighten = 20;
                     }
                     break;
                 case 'liquid':
                     $alpha = 0.25;
                     if ($tcolor->isVeryDark()) {
                         $lighten = 28;
                     } else {
                         $lighten = 15;
                     }
                     break;
                 case 'soft':
                     $alpha = 0.5;
                     if ($tcolor->isVeryDark()) {
                         $lighten = 15;
                     } else {
                         $lighten = 10;
                     }
                     break;
                 case 'hard':
                     $alpha = 0.9;
                     $lighten = 1;
                     break;
             }
         }
         if (isset($style[0])) {
             switch (strtolower($style[0])) {
                 case 'fixed':
                     if ($digital) {
                         $color = new Color(Color::nameToHex($attributes['index_color']));
                         $rgb1 = Color::hexToRgb($color->lighten($lighten));
                         $result['valueGradient'] = 'new steelseries.gradientWrapper(' . $min . ', ' . $max . ', [0,1], [new steelseries.rgbaColor(' . $rgb1['R'] . ',' . $rgb1['G'] . ',' . $rgb1['B'] . ', 1), new steelseries.rgbaColor(' . $rgb1['R'] . ',' . $rgb1['G'] . ',' . $rgb1['B'] . ', 1)])';
                         $result['useValueGradient'] = true;
                     } else {
                         $rgb = Color::nameToRgb($attributes['index_color']);
                         $result['section'] = '[steelseries.Section(' . $min . ', ' . $max . ', "rgba(' . $rgb['R'] . ',' . $rgb['G'] . ',' . $rgb['B'] . ', ' . $alpha . ')")]';
                         $result['useSectionColors'] = true;
                     }
                     break;
                 case 'fadein':
                     if ($digital) {
                         $color = new Color(Color::nameToHex($attributes['index_color']));
                         $rgb1 = Color::hexToRgb($color->lighten($lighten * 2));
                         $rgb2 = Color::nameToRgb($attributes['index_color']);
                         $result['valueGradient'] = 'new steelseries.gradientWrapper(' . $min . ', ' . $max . ', [0,1], [new steelseries.rgbaColor(' . $rgb1['R'] . ',' . $rgb1['G'] . ',' . $rgb1['B'] . ', 1), new steelseries.rgbaColor(' . $rgb2['R'] . ',' . $rgb2['G'] . ',' . $rgb2['B'] . ', 1)])';
                         $result['useValueGradient'] = true;
                     } else {
                         $rgb = Color::nameToRgb($attributes['index_color']);
                         $s = '';
                         $step = 20;
                         $size = ($max - $min) / $step;
                         for ($i = 0; $i < $step; $i++) {
                             $mi = $min + $i * $size;
                             $ma = $min + ($i + 1) * $size;
                             $a = $alpha - $alpha * ($step - $i) * 0.9 / $step;
                             $s = $s . 'steelseries.Section(' . $mi . ', ' . $ma . ', "rgba(' . $rgb['R'] . ',' . $rgb['G'] . ',' . $rgb['B'] . ', ' . $a . ')"),';
                         }
                         $result['section'] = '[' . substr($s, 0, strlen($s) - 1) . ']';
                         $result['useSectionColors'] = true;
                     }
                     break;
                 case 'fadeout':
                     if ($digital) {
                         $color = new Color(Color::nameToHex($attributes['index_color']));
                         $rgb2 = Color::hexToRgb($color->lighten($lighten * 2));
                         $rgb1 = Color::nameToRgb($attributes['index_color']);
                         $result['valueGradient'] = 'new steelseries.gradientWrapper(' . $min . ', ' . $max . ', [0,1], [new steelseries.rgbaColor(' . $rgb1['R'] . ',' . $rgb1['G'] . ',' . $rgb1['B'] . ', 1), new steelseries.rgbaColor(' . $rgb2['R'] . ',' . $rgb2['G'] . ',' . $rgb2['B'] . ', 1)])';
                         $result['useValueGradient'] = true;
                     } else {
                         $rgb = Color::nameToRgb($attributes['index_color']);
                         $s = '';
                         $step = 20;
                         $size = ($max - $min) / $step;
                         for ($i = 0; $i < $step; $i++) {
                             $mi = $min + $i * $size;
                             $ma = $min + ($i + 1) * $size;
                             $a = $alpha - $alpha * $i * 0.9 / $step;
                             $s = $s . 'steelseries.Section(' . $mi . ', ' . $ma . ', "rgba(' . $rgb['R'] . ',' . $rgb['G'] . ',' . $rgb['B'] . ', ' . $a . ')"),';
                         }
                         $result['section'] = '[' . substr($s, 0, strlen($s) - 1) . ']';
                         $result['useSectionColors'] = true;
                     }
                     break;
                 case 'complementary':
                     if ($digital) {
                         $color = new Color(Color::nameToHex($attributes['index_color']));
                         $rgb1 = Color::nameToRgb($attributes['index_color']);
                         $rgb2 = Color::hexToRgb($color->complementary());
                         $result['valueGradient'] = 'new steelseries.gradientWrapper(' . $min . ', ' . $max . ', [0,1], [new steelseries.rgbaColor(' . $rgb1['R'] . ',' . $rgb1['G'] . ',' . $rgb1['B'] . ', 1), new steelseries.rgbaColor(' . $rgb2['R'] . ',' . $rgb2['G'] . ',' . $rgb2['B'] . ', 1)])';
                         $result['useValueGradient'] = true;
                     } else {
                         $color2 = new Color(Color::nameToHex($attributes['index_color']));
                         $color = new Color($color2->complementary());
                         $rgb2 = $color->complementary();
                         $s = '';
                         $step = 20;
                         $size = ($max - $min) / $step;
                         for ($i = 0; $i < $step; $i++) {
                             $rgb = Color::hexToRgb($color->mix($rgb2, round(200 / $step * $i) - 100));
                             $mi = $min + $i * $size;
                             $ma = $min + ($i + 1) * $size;
                             $s = $s . 'steelseries.Section(' . $mi . ', ' . $ma . ', "rgba(' . $rgb['R'] . ',' . $rgb['G'] . ',' . $rgb['B'] . ', ' . $alpha . ')"),';
                         }
                         $result['section'] = '[' . substr($s, 0, strlen($s) - 1) . ']';
                         $result['useSectionColors'] = true;
                     }
                     break;
                 case 'invcomplementary':
                     if ($digital) {
                         $color = new Color(Color::nameToHex($attributes['index_color']));
                         $rgb2 = Color::nameToRgb($attributes['index_color']);
                         $rgb1 = Color::hexToRgb($color->complementary());
                         $result['valueGradient'] = 'new steelseries.gradientWrapper(' . $min . ', ' . $max . ', [0,1], [new steelseries.rgbaColor(' . $rgb1['R'] . ',' . $rgb1['G'] . ',' . $rgb1['B'] . ', 1), new steelseries.rgbaColor(' . $rgb2['R'] . ',' . $rgb2['G'] . ',' . $rgb2['B'] . ', 1)])';
                         $result['useValueGradient'] = true;
                     } else {
                         $color = new Color(Color::nameToHex($attributes['index_color']));
                         $rgb2 = $color->complementary();
                         $s = '';
                         $step = 20;
                         $size = ($max - $min) / $step;
                         for ($i = 0; $i < $step; $i++) {
                             $rgb = Color::hexToRgb($color->mix($rgb2, round(200 / $step * $i) - 100));
                             $mi = $min + $i * $size;
                             $ma = $min + ($i + 1) * $size;
                             $s = $s . 'steelseries.Section(' . $mi . ', ' . $ma . ', "rgba(' . $rgb['R'] . ',' . $rgb['G'] . ',' . $rgb['B'] . ', ' . $alpha . ')"),';
                         }
                         $result['section'] = '[' . substr($s, 0, strlen($s) - 1) . ']';
                         $result['useSectionColors'] = true;
                     }
                     break;
             }
         }
     } else {
         if ($digital) {
             $rgb = Color::nameToRgb('antiquewhite');
             $result['valueGradient'] = 'new steelseries.gradientWrapper(' . $min . ', ' . $max . ', [0,1], [new steelseries.rgbaColor(' . $rgb['R'] . ',' . $rgb['G'] . ',' . $rgb['B'] . ', 1), new steelseries.rgbaColor(' . $rgb['R'] . ',' . $rgb['G'] . ',' . $rgb['B'] . ', 1)])';
             $result['useValueGradient'] = true;
         }
     }
     $result['foregroundType'] = 'steelseries.ForegroundType.' . $attributes['glass'];
     switch ($attributes['size']) {
         case 'small':
             $result['size'] = 150;
             break;
         case 'medium':
             $result['size'] = 200;
             break;
         case 'large':
             $result['size'] = 250;
             break;
         case 'macro':
             $result['size'] = 300;
             break;
     }
     $result['thresholdVisible'] = false;
     $result['ledVisible'] = false;
     $result['niceScale'] = false;
     if ($digital) {
         $result['valueColor'] = 'steelseries.ColorDef.WHITE';
     }
     $result['lcdDecimals'] = $values['decimals'];
     $result['titleString'] = '"' . $values['type'] . '"';
     $result['unitString'] = '"• ' . $values['unit'] . ' •"';
     $result['digitalFont'] = true;
     if (strpos($attributes['design'], 'digital') !== false) {
         unset($result['titleString']);
         $result['unitString'] = '"' . $values['type'] . ' • ' . $values['unit'] . '"';
     }
     if (strpos($attributes['design'], 'meter-') !== false) {
         unset($result['titleString']);
         $result['niceScale'] = true;
     }
     if (strpos($attributes['design'], 'windcompass') !== false) {
         unset($result['titleString']);
         unset($result['unitString']);
         $result['lcdTitleStrings'] = '["' . __('Wind', 'live-weather-station') . '", "' . __('Gust', 'live-weather-station') . '"]';
     }
     if (strpos($attributes['design'], 'altimeter') !== false) {
         unset($result['titleString']);
         $result['unitString'] = '"' . $values['type'] . '"';
     }
     if (strpos($attributes['design'], 'windcompass-vintage') !== false) {
         $result['roseVisible'] = true;
         $result['degreeScale'] = false;
     }
     if (strpos($attributes['design'], 'windcompass-standard') !== false) {
         $result['roseVisible'] = true;
     }
     return $result;
 }