Flex中的终端仿真

时间:2008-09-13 14:16:35

标签: flex

我需要在Flex中对一些旧的DOS或大型机终端进行一些仿真。例如下面的图像。

alt text

不同颜色的文字很容易,但是能够使用不同的背景颜色(例如黄色背景)超出了标准Flash文本的功能。

我可能还需要能够在某些地方输入文字并在“终端”上滚动文字。知道我怎么攻击这个吗?或者更好的是,这类事情的任何现有代码/组件?

2 个答案:

答案 0 :(得分:2)

使用TextField.getCharBoundaries获取您想要背景的区域中第一个和最后一个字符的矩形。从这些矩形中,您可以构建一个跨越整个区域的矩形。使用此选项可以在文本字段后面的Shape或文本字段的父项中绘制背景。

您要求提供示例的

更新,以下是如何从一系列字符中获取矩形:

var firstCharBounds : Rectangle = textField.getCharBoundaries(firstCharIndex);
var lastCharBounds  : Rectangle = textField.getCharBoundaries(lastCharIndex);

var rangeBounds : Rectangle = new Rectangle();

rangeBounds.topLeft = firstCharBounds.topLeft;
rangeBounds.bottomRight = lastCharBounds.bottomRight;

如果要为整行找到一个矩形,可以改为:

var charBounds : Rectangle = textField.getCharBoundaries(textField.getLineOffset(lineNumber));

var lineBounds : Rectangle = new Rectangle(0, charBounds.y, textField.width, firstCharBounds.height);

如果您有要为其绘制背景的文本范围的边界,则可以在文本字段的父项的updateDisplayList方法中执行此操作(假设文本字段位于[0, 0]并且有白色文本,textRangesWithYellowBackground是一个矩形数组,表示应该有黄色背景的文本范围):

graphics.clear();

// this draws the black background
graphics.beginFill(0x000000);
graphics.drawRect(0, 0, textField.width, textField.height);
graphics.endFill();

// this draws yellow text backgrounds
for each ( var r : Rectangle in textRangesWithYellowBackground )
    graphics.beginFill(0xFFFF00);
    graphics.drawRect(r.x, r.y, r.width, r.height);
    graphics.endFill();
}

答案 1 :(得分:1)

字体是固定的宽度和高度,因此动态制作背景位图并不困难,可能是最快捷,最简单的解决方案。实际上,如果你正确调整大小,每个角色只会有一个拉伸像素。

根据角色的背景为像素(或像素)着色。

- 亚当

相关问题