<?php
/**
* This file is part of the easy-CMS project.
* easy-CMS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* 
* easy-CMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with easy-CMS; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

include_once('config.inc.php');

/**
* Allows colors operations and outputs.
*
* @access   private
* @author	Cedric Francoys <cedric.francoys@easy-cms.org>
* @version	Color.class, Sun Nov 28 13:25:40 CET 2004
* @package	Types
*/
class Color {
	
	// hexadecimal values
  var $red;
  var $green;
  var $blue;

  function Color($red, $green, $blue) {
      $this->setRed($red);
      $this->setGreen($green);
      $this->setBlue($blue);
  } 

  function setValue($color) {
		if(is_array($color)) {
      $red   = $color['red'];
      $green = $color['green'];
      $blue	 = $color['blue'];
	  }
    else {
		 list($red, $green, $blue) = sscanf($color, "#%02x%02x%02x");
    }
    $this->setRed($red);
    $this->setGreen($green);
    $this->setBlue($blue);
  }

  function compareTo(&$colorObj){
    return strcmp($this->getValue(), $colorObj->getValue());
  }

	function getType() {
    return EASY_CMS_TYPE_COLOR;
	}
	
  function setRed($red) {
    $this->red = $red;
  } 

  function setGreen($green) {
    $this->green = $green;
  } 

  function setBlue($blue) {
    $this->blue = $blue;
  } 

  function getRed() {
    return $this->red;
  } 

  function getGreen() {
    return $this->green;
  } 

  function getBlue() {
    return $this->blue;
  } 

  function getValue() {
    return sprintf("%02x%02x%02x", $this->red, $this->green, $this->blue);
  }
	
  function toString() {
    return $this->getRed().", ".$this->getGreen().", ".$this->getBlue();
  } 

  function toXML() {
    return "<red>".$this->getRed()."</red>\n<green>".$this->getGreen()."</green>\n<blue>".$this->getBlue()."</blue>\n";
  } 

  function toSQL() {
    return sprintf("%02x%02x%02x", $this->red, $this->green, $this->blue);
  } 
}
?>