Skip to content

Commit

Permalink
Merge pull request #5 from trystan/master
Browse files Browse the repository at this point in the history
Allow different fonts.
  • Loading branch information
usysrc committed Sep 2, 2012
2 parents 1a8aaab + c5a332e commit cb4a20f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions src/com/headchant/asciipanel/AsciiPanel.as
Expand Up @@ -12,8 +12,11 @@ package com.headchant.asciipanel {
*/

public class AsciiPanel extends Sprite {
[Embed(source="cp437.png", mimeType="image/png")]
private var fontImage:Class;
[Embed(source="cp437_9x16.png", mimeType = "image/png")]
public static const codePage437_9x16:Class;

[Embed(source = "cp437_8x8.png", mimeType = "image/png")]
public static const codePage437_8x8:Class;

private var glyphs : Array;
private var fontBitmapData : BitmapData;
Expand Down Expand Up @@ -48,37 +51,43 @@ package com.headchant.asciipanel {
public function getWidthInCharacters() : int { return widthInCharacters; }
public function getHeightInCharacters() : int { return heightInCharacters; }

public function AsciiPanel(widthInCharacters:int = 80, heightInCharacters:int = 24){
fontBitmap = new fontImage() as Bitmap;
fontBitmapData = fontBitmap.bitmapData;
public function AsciiPanel(widthInCharacters:int = 80, heightInCharacters:int = 24) {
this.widthInCharacters = widthInCharacters;
this.heightInCharacters = heightInCharacters;

useRasterFont(codePage437_9x16, 9, 16);
}

public function useRasterFont(fontImage:Class, charWidth:int, charHeight:int):void {
this.fontBitmap = new fontImage() as Bitmap;
this.fontBitmapData = fontBitmap.bitmapData;
this.charWidth = charWidth;
this.charHeight = charHeight;

charWidth = 9;
charHeight = 16;
var imageWidthInCharacters:int = fontBitmapData.width / charWidth;

glyphs = new Array();
trace(imageWidthInCharacters);

this.glyphs = new Array();
for (var i : int = 0; i < 256; i++) {
var sx:int = (i % 32) * charWidth + 8;
var sy:int = int(i / 32) * charHeight + 8;
var sx:int = (i % imageWidthInCharacters) * charWidth;
var sy:int = int(i / imageWidthInCharacters) * charHeight;
glyphs[i] = new BitmapData(charWidth, charHeight);
(glyphs[i] as BitmapData).copyPixels(fontBitmapData, new Rectangle(sx,sy,charWidth, charHeight), new Point(0,0));

}

this.widthInCharacters = widthInCharacters;
this.heightInCharacters = heightInCharacters;


width = charWidth*widthInCharacters;
height = charHeight*heightInCharacters;

screen = new BitmapData(charWidth*widthInCharacters+10, charHeight*heightInCharacters+10,false,0x000000);
height = charHeight * heightInCharacters;
screen = new BitmapData(charWidth*widthInCharacters, charHeight*heightInCharacters,false,0x000000);
chars = new Array();
oldchars = new Array();
foregroundColor = new Array();
backgroundColor = new Array();
oldforegroundColor = new Array();
oldbackgroundColor = new Array();

for ( i = 0; i < widthInCharacters; i++) {
for (i = 0; i < widthInCharacters; i++) {
chars[i] = [];
oldchars[i] = [];
foregroundColor[i] = [];
Expand All @@ -95,6 +104,9 @@ package com.headchant.asciipanel {
}
}

if (screenBitmap != null)
removeChild(screenBitmap);

screenBitmap = new Bitmap(screen);
screenBitmap.smoothing = false;
addChild(screenBitmap);
Expand Down
Binary file removed src/com/headchant/asciipanel/cp437.png
Binary file not shown.
Binary file added src/com/headchant/asciipanel/cp437_8x8.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/com/headchant/asciipanel/cp437_9x16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cb4a20f

Please sign in to comment.