2
* This file is part of the dis-Emi-A HaXe Library. Copyright (c) edA-qa mort-ora-y
3
* For full copyright and license information please refer to doc/license.txt.
9
* Exposes the Button pattern for traits
14
PARAM(angleOffset,Float,0.0)
15
PARAM(outline,Pen,Pen.solid(1,Color.rgb(0,0,0) ))
16
PARAM(fill,Brush,Brush.solid(Color.rgb(0.5,0.5,0.5)))
17
PARAM(gutterSize,Float,0.1)
18
PARAM(inner,Widget,null)
19
PARAM(outerBulge,Float,1.0)
20
PARAM(outerBulgeInvertDown,Bool,true)
21
PARAM(rotateSpeed,T_Float(1.0))
22
PARAM(innerSize,T_Float(0.70711),Default is cos/sin(pi/4) for the inner-square of this item, as if perfect circle)
27
if( params.inner != null )
28
addChild( params.inner.getNative() );
33
TRAIT(Button,Up,DEFAULT)
38
TRAIT(Button,Down,NONE)
43
TRAIT(Mouse,Over,DEFAULT)
54
SEQUENCE(Still,DEFAULT)
65
VAR(angleRotate,T_Float(0.0))
66
/** Rotates polygon, not the inner item */
73
angleRotate += elapsed * params.rotateSpeed;
76
DRAWTRANSFORM_SCALE(0.5,0.5)
79
var gfxi = GraphicsX.scaled( graphics,
80
widgetSize.x/2 * (1-params.gutterSize),
81
widgetSize.y/2 * (1-params.gutterSize));
84
var angle = params.angleOffset + angleRotate;
85
var angleDelta = Math.PI*2 / params.sides;
86
var pts = new Array<Point2>();
87
var outPts = new Array<Point2>();
89
var hasBulge = params.outerBulge != 1.0; //exact mathc okay, specific value
90
var bulgeFactor = Math.cos( 0.5 * angleDelta ) /* length from center to chord*/
91
* ( down && params.outerBulgeInvertDown ? 1/params.outerBulge : params.outerBulge);
93
for( i in 0...params.sides )
95
//inner edge (will be auto-rounded)
96
pts.push( Point2.at( Math.cos( angle ), Math.sin( angle ) ) );
101
var halfAngle = angle + angleDelta/2;
102
outPts.push( pts[pts.length-1] );
105
Math.cos( halfAngle ) * bulgeFactor,
106
Math.sin( halfAngle ) * bulgeFactor
111
if( i == (params.sides - 1 ) )
112
angle = params.angleOffset; //to provide perfect alignment (no floating point error)
117
outPts.push( outPts[0] ); //close polygon
119
var outFill = params.fill.adjustBrightness( 0.5 );
120
var inFill = params.fill;
128
//TODO: optimize if gutterSize = 0
129
//draw primary polygon
131
gfx.use( params.outline );
133
gfx.polyCurve( outPts );
135
gfx.polyLine( pts, true );
140
gfxi.use( Pen.empty() );
141
gfxi.polyRound( pts, 0.2 );
144
//CLEANUP to provide general containing logic
145
if( params.inner != null )
147
params.inner.move( -actorSize.x * params.innerSize/2, -actorSize.y * params.innerSize/2 );
148
params.inner.resize( actorSize.x * params.innerSize, actorSize.y * params.innerSize );
b'\\ No newline at end of file'