Parent Directory
|
Revision Log
Revision 1.3 - (view) (download)
| 1 : | dservos | 1.2 | /////////////////////////////////////////////////////////////////////////// |
| 2 : | // // | ||
| 3 : | // NOTICE OF COPYRIGHT // | ||
| 4 : | // // | ||
| 5 : | // Moodle - Modular Object-Oriented Dynamic Learning Environment // | ||
| 6 : | // http://moodle.org // | ||
| 7 : | // // | ||
| 8 : | // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com // | ||
| 9 : | // // | ||
| 10 : | // This program is free software; you can redistribute it and/or modify // | ||
| 11 : | // it under the terms of the GNU General Public License as published by // | ||
| 12 : | // the Free Software Foundation; either version 2 of the License, or // | ||
| 13 : | // (at your option) any later version. // | ||
| 14 : | // // | ||
| 15 : | // This program is distributed in the hope that it will be useful, // | ||
| 16 : | // but WITHOUT ANY WARRANTY; without even the implied warranty of // | ||
| 17 : | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | ||
| 18 : | // GNU General Public License for more details: // | ||
| 19 : | // // | ||
| 20 : | // http://www.gnu.org/copyleft/gpl.html // | ||
| 21 : | // // | ||
| 22 : | /////////////////////////////////////////////////////////////////////////// | ||
| 23 : | |||
| 24 : | dservos | 1.1 | package { |
| 25 : | import flash.display.SimpleButton; | ||
| 26 : | import flash.text.TextField; | ||
| 27 : | import flash.text.TextFormat; | ||
| 28 : | |||
| 29 : | public class Button extends SimpleButton { | ||
| 30 : | private var upColor:uint = 0x9999FF; | ||
| 31 : | private var overColor:uint = 0xBABAFF; | ||
| 32 : | private var downColor:uint = 0xBBBBFF; | ||
| 33 : | dservos | 1.3 | private var fmt:TextFormat = new TextFormat("monospace", 12, 0, null, null, null, null, null, "center"); |
| 34 : | dservos | 1.2 | private var buttonText:String; |
| 35 : | dservos | 1.3 | private var alphaValue:Number = 0.6; |
| 36 : | dservos | 1.1 | |
| 37 : | public var props:Object = new Object(); | ||
| 38 : | |||
| 39 : | dservos | 1.3 | public function Button(text:String, settings:XMLList = null) { |
| 40 : | if(settings != null) { | ||
| 41 : | upColor = parseInt(settings.bgcolor, 16); | ||
| 42 : | overColor = upColor + 0x212100; | ||
| 43 : | downColor = upColor + 0x222200; | ||
| 44 : | alphaValue = settings.alpha; | ||
| 45 : | |||
| 46 : | fmt = new TextFormat(settings.text.font, settings.text.size, 0, null, null, null, null, null, "center"); | ||
| 47 : | |||
| 48 : | downState = new ButtonDisplayState(text, fmt, downColor, alphaValue, settings.line); | ||
| 49 : | overState = new ButtonDisplayState(text, fmt, overColor, alphaValue, settings.line); | ||
| 50 : | upState = new ButtonDisplayState(text, fmt, upColor, alphaValue, settings.line); | ||
| 51 : | } else { | ||
| 52 : | downState = new ButtonDisplayState(text, fmt, downColor, alphaValue); | ||
| 53 : | overState = new ButtonDisplayState(text, fmt, overColor, alphaValue); | ||
| 54 : | upState = new ButtonDisplayState(text, fmt, upColor, alphaValue); | ||
| 55 : | } | ||
| 56 : | |||
| 57 : | dservos | 1.2 | buttonText = text; |
| 58 : | dservos | 1.1 | hitTestState = upState; |
| 59 : | useHandCursor = true; | ||
| 60 : | } | ||
| 61 : | dservos | 1.2 | |
| 62 : | public function set text(text:String):void { | ||
| 63 : | buttonText = text; | ||
| 64 : | ButtonDisplayState(downState).text = text; | ||
| 65 : | ButtonDisplayState(overState).text = text; | ||
| 66 : | ButtonDisplayState(upState).text = text; | ||
| 67 : | } | ||
| 68 : | |||
| 69 : | public function get text():String { | ||
| 70 : | return buttonText; | ||
| 71 : | } | ||
| 72 : | dservos | 1.1 | } |
| 73 : | } | ||
| 74 : | |||
| 75 : | import flash.display.Sprite; | ||
| 76 : | import flash.text.TextField; | ||
| 77 : | import flash.text.TextFormat; | ||
| 78 : | import flash.text.TextFieldAutoSize; | ||
| 79 : | import flare.display.TextSprite; | ||
| 80 : | |||
| 81 : | class ButtonDisplayState extends Sprite | ||
| 82 : | { | ||
| 83 : | private var bgColor:uint; | ||
| 84 : | private var w:uint; | ||
| 85 : | private var h:uint; | ||
| 86 : | dservos | 1.2 | private var buttonText:String; |
| 87 : | private var fmt:TextFormat; | ||
| 88 : | private var ts:TextSprite; | ||
| 89 : | dservos | 1.3 | private var alphaValue:Number |
| 90 : | private var lineSettings:XMLList; | ||
| 91 : | dservos | 1.1 | |
| 92 : | dservos | 1.3 | public function ButtonDisplayState(text:String, fmt:TextFormat, bgColor:uint = 0x9999FF, alphaValue:Number = 0.6, lineSettings:XMLList = null) { |
| 93 : | dservos | 1.1 | this.bgColor = bgColor; |
| 94 : | dservos | 1.2 | buttonText = text; |
| 95 : | this.fmt = fmt; | ||
| 96 : | this.ts = new TextSprite(text, fmt); | ||
| 97 : | dservos | 1.3 | this.alphaValue = alphaValue; |
| 98 : | this.lineSettings = lineSettings; | ||
| 99 : | dservos | 1.2 | |
| 100 : | dservos | 1.1 | var tf:TextField = ts.textField; |
| 101 : | |||
| 102 : | w = tf.width = tf.textWidth + 6; | ||
| 103 : | h = tf.height = tf.textHeight + 4; | ||
| 104 : | ts.dirty(); | ||
| 105 : | |||
| 106 : | addChild(ts); | ||
| 107 : | draw(); | ||
| 108 : | } | ||
| 109 : | |||
| 110 : | private function draw():void { | ||
| 111 : | dservos | 1.3 | graphics.beginFill(bgColor, alphaValue); |
| 112 : | |||
| 113 : | if(lineSettings == null) { | ||
| 114 : | graphics.lineStyle(1, 0x4444FF, 0.3, true); | ||
| 115 : | } else { | ||
| 116 : | graphics.lineStyle(lineSettings.size, parseInt(lineSettings.color, 16), lineSettings.alpha, true); | ||
| 117 : | } | ||
| 118 : | |||
| 119 : | dservos | 1.1 | graphics.drawRoundRect(0, 0, w, h, 10, 10); |
| 120 : | graphics.endFill(); | ||
| 121 : | } | ||
| 122 : | dservos | 1.2 | |
| 123 : | public function set text(text:String):void { | ||
| 124 : | buttonText = text; | ||
| 125 : | ts.text = text; | ||
| 126 : | } | ||
| 127 : | dservos | 1.1 | } |
| Moodle CVS Admin | ViewVC Help |
| Powered by ViewVC 1.0.7 |