Example #1
0
 def __init__(self):
     self.textformat = TextFormat("Consolas", 18, 0xDDDDDD)
     self.lineheight = 24
     self.textfield = TextField()
     self.textfield.setTextFormat(self.textformat)
     self.textfield.defaultTextFormat = self.textformat
     self.glyphs = {}
     self.colorcache = {}
Example #2
0
class GlyphCache:
    def __init__(self):
        self.textformat = TextFormat("Consolas", 18, 0xDDDDDD)
        self.lineheight = 24
        self.textfield = TextField()
        self.textfield.setTextFormat(self.textformat)
        self.textfield.defaultTextFormat = self.textformat
        self.glyphs = {}
        self.colorcache = {}

    def draw_line(self, text, x, y, color, target, cursor=undefined):
        cbmp = self.colorcache[color]
        if not cbmp:
            cbmp = BitmapData(self.lineheight, self.lineheight, False, color)
            self.colorcache[color] = cbmp

        pt = Point(x, y)
        lines = 1

        for i in range(text.length):
            char = text.charCodeAt(i)
            if char == 10:
                pt.x = x
                pt.y += self.lineheight
                lines += 1
                continue
            glyph = self.glyphs[char]
            if not glyph:
                glyph = self._make_glyph(char)
                self.glyphs[char] = glyph
            target.copyPixels(cbmp, glyph.rect, pt, glyph, None, True)
            if cursor == i:
                target.copyPixels(cbmp, Rectangle(0, 0, 2, self.lineheight), pt)
            pt.x += glyph.rect.width - 1
        if cursor == text.length:
            target.copyPixels(cbmp, Rectangle(0, 0, 2, self.lineheight), pt)
        return lines

    def _make_glyph(self, code):
        self.textfield.text = String.fromCharCode(code)
        bmp = BitmapData(self.textfield.textWidth + 1, self.lineheight, True, 0x0)
        bmp.draw(self.textfield)
        return bmp
Example #3
0
 def init(self):
     self.stage.align = StageAlign.TOP_LEFT
     label = TextField()
     label.background = True
     label.border = True
     label.text = "Testing:\n"
     label.width = self.stage.stageWidth
     label.height = self.stage.stageHeight
     self.addChild(label)
     self.label = label
     self.reporter = Reporter(label)
     self.addEventListener(Event.ENTER_FRAME, self.start_tests)
Example #4
0
            stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			var tmp:Bitmap;
			if((myURL != null) && (myURL.length > 0) && (root.loaderInfo.url.indexOf(myURL) < 0) && (root.loaderInfo.url.indexOf("localhost") < 0))
			{
				tmp = new Bitmap(new BitmapData(stage.stageWidth,stage.stageHeight,true,0xFFFFFFFF));
				addChild(tmp);
				
				var fmt:TextFormat = new TextFormat();
				fmt.color = 0x000000;
				fmt.size = 16;
				fmt.align = "center";
				fmt.bold = true;
				
				var txt:TextField = new TextField();
				txt.width = tmp.width-16;
				txt.height = tmp.height-16;
				txt.y = 8;
				txt.multiline = true;
				txt.wordWrap = true;
				txt.defaultTextFormat = fmt;
				txt.text = "Hi there!  It looks like somebody copied this game without my permission.  It is meant to be played ad-free!  If you would like to play it at my site with NO annoying ads, just click anywhere, or copy-paste this URL into your browser.\n\n"+myURL+"\n\nThanks, and have fun!";
				addChild(txt);
				
				txt.addEventListener(MouseEvent.CLICK,goToMyURL);
				tmp.addEventListener(MouseEvent.CLICK,goToMyURL);
				return;
			}
			
			Buffer = new Sprite();