forked from scratchfoundation/scratch-flash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadProgress.as
More file actions
95 lines (79 loc) · 2.91 KB
/
LoadProgress.as
File metadata and controls
95 lines (79 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* Scratch Project Editor and Player
* Copyright (C) 2014 Massachusetts Institute of Technology
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package ui {
import flash.display.*;
import flash.filters.DropShadowFilter;
import flash.text.*;
import assets.Resources;
import translation.Translator;
public class LoadProgress extends Sprite {
private const titleFormat:TextFormat = new TextFormat(CSS.font, 18, CSS.textColor);
private const infoFormat:TextFormat = new TextFormat(CSS.font, 12, CSS.textColor);
private const grooveColor:int = 0xB9BBBD;
private var bkg:Shape;
private var titleField:TextField;
private var infoField:TextField;
private var groove:Shape;
private var progressBar:Shape;
public function LoadProgress():void {
addBackground(310, 120);
addChild(titleField = Resources.makeLabel('', titleFormat, 20, bkg.height - 61));
addChild(infoField = Resources.makeLabel('', infoFormat, 20, bkg.height - 35));
addChild(groove = new Shape());
addChild(progressBar = new Shape());
groove.x = progressBar.x = 30;
groove.y = progressBar.y = 25;
drawBar(groove.graphics, grooveColor, 250, 22)
}
public function getTitle():String { return titleField.text }
public function setTitle(s:String):void {
titleField.text = Translator.map(s);
titleField.x = (bkg.width - titleField.textWidth) / 2;
infoField.text = ''; // clear old info when title changes
}
public function setInfo(s:String):void {
infoField.text = Translator.map(s);
infoField.x = (bkg.width - infoField.textWidth) / 2;
}
public function setProgress(p:Number):void {
drawBar(progressBar.graphics, CSS.overColor, Math.floor(groove.width * p), groove.height);
}
private function addBackground(w:int, h:int):void {
addChild(bkg = new Shape());
var g:Graphics = bkg.graphics;
g.clear();
g.lineStyle(1, CSS.borderColor, 1, true);
g.beginFill(0xFFFFFF);
g.drawRoundRect(0, 0, w, h, 24, 24);
g.endFill();
var f:DropShadowFilter = new DropShadowFilter();
f.blurX = f.blurY = 8;
f.distance = 5;
f.alpha = 0.75;
f.color = 0x333333;
bkg.filters = [f];
}
private function drawBar(g:Graphics, c:uint, w:int, h:int):void {
var radius:int = h / 2;
g.clear();
g.beginFill(c);
g.drawRoundRect(0, 0, w, h, radius, radius);
g.endFill();
}
}}