182 lines
3.7 KiB
ActionScript
Executable File
182 lines
3.7 KiB
ActionScript
Executable File
/*
|
||
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
|
||
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
|
||
*/
|
||
package com.yahoo.astra.fl.charts.skins
|
||
{
|
||
import fl.core.UIComponent;
|
||
|
||
/**
|
||
* A skin shaped like a diamond with a single color.
|
||
*
|
||
* @author Josh Tynjala
|
||
*/
|
||
public class DiamondSkin extends UIComponent implements IProgrammaticSkin
|
||
{
|
||
|
||
//--------------------------------------
|
||
// Constructor
|
||
//--------------------------------------
|
||
|
||
/**
|
||
* Constructor.
|
||
*/
|
||
public function DiamondSkin()
|
||
{
|
||
super();
|
||
}
|
||
|
||
//--------------------------------------
|
||
// Properties
|
||
//--------------------------------------
|
||
|
||
/**
|
||
* @private
|
||
* Storage for the fillColor property.
|
||
*/
|
||
private var _fillColor:uint = 0x000000;
|
||
|
||
/**
|
||
* @copy com.yahoo.astra.fl.charts.skins.IProgrammaticSkin#fillColor
|
||
*/
|
||
public function get fillColor():uint
|
||
{
|
||
return this._fillColor;
|
||
}
|
||
|
||
/**
|
||
* @private
|
||
*/
|
||
public function set fillColor(value:uint):void
|
||
{
|
||
if(this._fillColor != value)
|
||
{
|
||
this._fillColor = value;
|
||
this.invalidate();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @private
|
||
* Storage for outline color
|
||
*/
|
||
private var _borderColor:uint;
|
||
|
||
/**
|
||
* @copy com.yahoo.astra.fl.charts.skins.IProgrammaticSkin#borderColor
|
||
*/
|
||
public function get borderColor():uint
|
||
{
|
||
return _borderColor;
|
||
}
|
||
|
||
/**
|
||
* @private (setter)
|
||
*/
|
||
public function set borderColor(value:uint):void
|
||
{
|
||
if(this._borderColor != value)
|
||
{
|
||
this._borderColor = value;
|
||
this.invalidate();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @private
|
||
* Storage for the fill alpha.
|
||
*/
|
||
private var _fillAlpha:Number = 1;
|
||
|
||
/**
|
||
* The alpha value of the fill.
|
||
*/
|
||
public function get fillAlpha():Number
|
||
{
|
||
return _fillAlpha;
|
||
}
|
||
|
||
/**
|
||
* @private (setter)
|
||
*/
|
||
public function set fillAlpha(value:Number):void
|
||
{
|
||
if(this._fillAlpha != value)
|
||
{
|
||
this._fillAlpha = value;
|
||
this.invalidate();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @private
|
||
* Storage for the border alpha.
|
||
*/
|
||
private var _borderAlpha:Number = 1;
|
||
|
||
/**
|
||
* The alpha value of the border.
|
||
*/
|
||
public function get borderAlpha():Number
|
||
{
|
||
return _borderAlpha;
|
||
}
|
||
|
||
/**
|
||
* @private (setter)
|
||
*/
|
||
public function set borderAlpha(value:Number):void
|
||
{
|
||
if(this._borderAlpha != value)
|
||
{
|
||
this._borderAlpha = value;
|
||
this.invalidate();
|
||
}
|
||
}
|
||
|
||
//--------------------------------------
|
||
// Protected Methods
|
||
//--------------------------------------
|
||
|
||
/**
|
||
* @private
|
||
*/
|
||
override protected function draw():void
|
||
{
|
||
super.draw();
|
||
|
||
this.graphics.clear();
|
||
if(this.width == 0 || this.height == 0 || isNaN(this.width) || isNaN(this.height))
|
||
{
|
||
return;
|
||
}
|
||
|
||
if(this.borderColor == this.fillColor)
|
||
{
|
||
this.graphics.lineStyle(0, 0, 0);
|
||
}
|
||
else
|
||
{
|
||
this.graphics.lineStyle(1, this.borderColor, this.borderAlpha);
|
||
}
|
||
|
||
this.graphics.beginFill(this.fillColor, this.fillAlpha);
|
||
|
||
var w:Number = 5 * Math.min(this.width, this.height) / 4;
|
||
var h:Number = w;
|
||
|
||
var startX:Number = (this.width - w) / 2;
|
||
var startY:Number = (this.height - h) / 2;
|
||
var endX:Number = startX + w;
|
||
var endY:Number = startY + h;
|
||
|
||
this.graphics.moveTo(startX, this.height / 2);
|
||
this.graphics.lineTo(this.width / 2, startY);
|
||
this.graphics.lineTo(endX, this.height / 2);
|
||
this.graphics.lineTo(this.width / 2, endY);
|
||
this.graphics.lineTo(startX, this.height / 2);
|
||
this.graphics.endFill();
|
||
}
|
||
|
||
}
|
||
} |