2 # Simple utility to manage an array of text lines in a region.
5 # Copyright (C) 2010 Scott Hamilton
7 # You should have received a copy of the GNU General Public License
8 # along with this program. If not, see <http://www.gnu.org/licenses/>.
12 new : func(lines, width, prefix){
13 var me = {parents:[TextRegion]};
16 me.baseNode = props.globals.getNode(prefix,1);
19 for(var p = 0; p != lines; p=p+1) {
20 var lineNode = me.baseNode.getNode("line["~p~"]",1);
21 var redNode = me.baseNode.getNode("red["~p~"]",1);
22 var greenNode = me.baseNode.getNode("green["~p~"]",1);
23 var blueNode = me.baseNode.getNode("blue["~p~"]",1);
24 lineNode.setValue("");
25 redNode.setValue(0.1);
26 greenNode.setValue(0.8);
27 blueNode.setValue(0.1);
34 # append some text in default colour
37 me.appendStyle(text, 0.1, 0.8, 0.1);
41 # append some text to the region and set the colour
43 appendStyle : func(text, red, green, blue) {
44 var lineNode = me.baseNode.getNode("line["~me.posLine~"]",1);
45 var redNode = me.baseNode.getNode("red["~me.posLine~"]",1);
46 var greenNode = me.baseNode.getNode("green["~me.posLine~"]",1);
47 var blueNode = me.baseNode.getNode("blue["~me.posLine~"]",1);
48 redNode.setValue(red);
49 greenNode.setValue(green);
50 blueNode.setValue(blue);
51 lineNode.setValue(text);
52 if (me.posLine < me.maxLines) {
53 me.posLine = me.posLine+1;
58 # simply replace the text at a particular line
60 textAt : func(index, text) {
61 var lineNode = me.baseNode.getNode("line["~index~"]",1);
62 lineNode.setValue(text);
67 # clears out all the lines and resets the pointer
70 for(var p = 0; p != me.maxLines; p=p+1) {
71 var lineNode = me.baseNode.getNode("line["~p~"]",1);
72 lineNode.setValue("");
78 # call reset when you are done writing to the region
79 # it will reset the pointer so next frame you start writing from the top again
82 for(var p = me.posLine; p != me.maxLines; p=p+1) {
83 var lineNode = me.baseNode.getNode("line["~p~"]",1);
84 lineNode.setValue("");