Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/lib/customs/textzone.js
blob: c1a34d95e4d7ea24d396185868bfa039eb789d82 (plain)
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
var TextZone = Class.create();
TextZone.prototype = {
    initialize: function(x, y, width, height, fontSize, backgroundColor, textColor, stage){
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        this.fontSize = fontSize;
        this.backgroundColor = backgroundColor;
        this.textColor = textColor;
        this.stage = stage;

        this.fontStr = this.fontSize + "px Arial";
        this.text = new createjs.Text("", this.fontStr, this.textColor);
        this.stage.addChild(this.text);
        this.stage.update();
    },
    // Just call it once.
    addToStage: function(){
        var txtZone = new createjs.Shape();
        txtZone.graphics.beginFill(this.backgroundColor).drawRect(
            this.x, this.y, this.width, this.height
        );
        this.stage.addChild(txtZone);
        this.stage.update();
    },
    changeTextTo: function(newText){
        this.stage.removeChild(this.text);

        this.text.text = newText;
        this.text.lineWidth = this.width;
        this.text.x = this.x;
        this.text.y = this.y;

        this.stage.addChild(this.text);
        this.stage.update();
    }
};