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.
8
import flash.display.Sprite;
9
import flash.events.MouseEvent;
11
import flash.filters.BitmapFilter;
12
import flash.filters.BevelFilter;
14
class CheckBox extends Sprite, implements Widget, implements Selectable
16
var checked : Bool; //state of checkbox
17
var down : Bool; //stage of mouse
20
var filtersUp : Array<BitmapFilter>;
21
var filtersDown : Array<BitmapFilter>;
23
var bevelSize : Float;
26
var color : draw.Color;
29
private function new( text : String, ?color : draw.Color )
38
color = draw.Color.int(0x8080A0);
42
filtersUp = new Array();
43
filtersUp.push( new BevelFilter( bevelSize, 45) );
44
filtersDown = new Array();
45
var bf = new BevelFilter( bevelSize, 180 + 45);
46
//bf.highlightAlpha = 0; //Unlike a button we need to keep this obrder otherwise it is hard to see
47
filtersDown.push( bf );
49
tf = StaticText.singleLine( text, StaticTextAlign.Left );
52
//use a separate box for the box to avoid applying filter to text
56
addEventListener( MouseEvent.MOUSE_DOWN, onMouseDown,false, 0, true /*weak*/ );
57
addEventListener( MouseEvent.MOUSE_UP, onMouseUp,false, 0, true /*weak*/ );
58
addEventListener( MouseEvent.MOUSE_OVER, onMouseOver,false, 0, true /*weak*/ );
59
addEventListener( MouseEvent.MOUSE_OUT, onMouseOut,false, 0, true /*weak*/ );
63
* Constructs a standard check box.
65
static public function plain( text : String, ?color : draw.Color )
67
return new CheckBox( text, color );
70
function onMouseDown( evt : MouseEvent )
76
function onMouseUp( evt : MouseEvent )
79
setSelected( !checked );
82
function onMouseOver( evt : MouseEvent )
84
down = evt.buttonDown;
88
function onMouseOut( evt : MouseEvent )
94
function _resize( w : Float, h : Float )
96
var ds : Bool = down != checked;
100
tf.resize( w - tf.x, h );
102
box.graphics.clear();
103
box.graphics.beginFill( ds ? color.darken().asInt() : color.asInt() );
105
box.graphics.drawEllipse( h/5,h/5,3*h/5,3*h/5 );
107
box.graphics.drawRect( h/5,h/5,3*h/5,3*h/5 );
108
box.graphics.endFill();
110
box.filters = if( ds ) filtersDown else filtersUp;
113
public function getSelected() : Bool
118
public function setSelected( sel : Bool )
124
if( onSelectChange != null )
125
Action.handle( this, onSelectChange );
129
var onSelectChange : Dynamic;
130
public function setOnSelectChange( action : Dynamic )
132
onSelectChange = action;
135
public function getPrefWidth() : SizeType
138
tf.getPrefHeight(), //box is as wide as is high
140
SizeType.Fixed( bevelSize ),
146
public function getPrefHeight() : SizeType
148
return tf.getPrefHeight();
151
define(`NoSizing',`')
152
include(`MixinWidget.ihx')
b'\\ No newline at end of file'