Skip to content

Commit

Permalink
added AngelCode support for cpp target
Browse files Browse the repository at this point in the history
  • Loading branch information
Beeblerox committed Jul 3, 2012
1 parent 7424980 commit 7dfec98
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 36 deletions.
47 changes: 26 additions & 21 deletions Haxe/src/pxBitmapFont/PxBitmapFont.hx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ class PxBitmapFont
#if (flash || js)
private var _glyphs:Array<BitmapData>;
#else
private var _glyphs:IntHash<Int>;
private var _glyphs:IntHash<PxFontSymbol>;
private var _num_letters:Int;
private var _tileSheet:Tilesheet;
private static var _flags = Tilesheet.TILE_SCALE | Tilesheet.TILE_ROTATION | Tilesheet.TILE_ALPHA | Tilesheet.TILE_RGB;
private var _glyphWidthData:Array<Int>;
#end
private var _glyphString:String;
private var _maxHeight:Int;
Expand All @@ -55,8 +54,7 @@ class PxBitmapFont
_colorTransform = new ColorTransform();
_glyphs = [];
#else
_glyphWidthData = [];
_glyphs = new IntHash<Int>();
_glyphs = new IntHash<PxFontSymbol>();
_num_letters = 0;
#end
}
Expand Down Expand Up @@ -94,7 +92,7 @@ class PxBitmapFont
// store glyph
setGlyph(_glyphString.charCodeAt(letterID), bd);
#else
setGlyph(_glyphString.charCodeAt(letterID), currRect, letterID);
setGlyph(_glyphString.charCodeAt(letterID), currRect, letterID, 0, 0, Math.floor(currRect.width));
#end
}
}
Expand Down Expand Up @@ -122,7 +120,7 @@ class PxBitmapFont
var charCode:Int;

#if (cpp || neko)
_tileSheet = new Tilesheet(result);
_tileSheet = new Tilesheet(pBitmapData);
#end

var chars:Xml = null;
Expand Down Expand Up @@ -166,7 +164,7 @@ class PxBitmapFont
// store glyph
setGlyph(charCode, bd);
#else
setGlyph(charCode, rect, letterID);
setGlyph(charCode, rect, letterID, Math.floor(point.x), Math.floor(point.y), Std.parseInt(node.get("xadvance")));
#end

letterID++;
Expand All @@ -188,7 +186,7 @@ class PxBitmapFont
#if (flash || js)
_glyphs = [];
#else
_glyphs = new IntHash<Int>();
_glyphs = new IntHash<PxFontSymbol>();
#end
_glyphString = "";
}
Expand Down Expand Up @@ -379,12 +377,20 @@ class PxBitmapFont
}
}
#else
private function setGlyph(pCharID:Int, pRect:Rectangle, pGlyphID:Int):Void
private function setGlyph(pCharID:Int, pRect:Rectangle, pGlyphID:Int, ?pOffsetX:Int = 0, ?pOffsetY:Int = 0, ?pAdvanceX:Int = 0):Void
{
_tileSheet.addTileRect(pRect);
_glyphs.set(pCharID, pGlyphID);

var symbol:PxFontSymbol = new PxFontSymbol();
symbol.tileID = pGlyphID;
symbol.xoffset = pOffsetX;
symbol.yoffset = pOffsetY;
symbol.xadvance = pAdvanceX;

trace("pAdvanceX = " + pAdvanceX);

_glyphs.set(pCharID, symbol);
_num_letters++;
_glyphWidthData[pCharID] = Math.floor(pRect.width);

if (Math.floor(pRect.height) > _maxHeight)
{
Expand Down Expand Up @@ -414,7 +420,7 @@ class PxBitmapFont
#if (flash || js)
var glyph:BitmapData;
#else
var glyph:Int;
var glyph:PxFontSymbol;
var glyphWidth:Int;
#end

Expand All @@ -433,20 +439,20 @@ class PxBitmapFont
pBitmapData.copyPixels(glyph, glyph.rect, _point, null, null, true);
_point.x += glyph.width + pLetterSpacing;
#else
glyphWidth = _glyphWidthData[charCode];
glyphWidth = glyph.xadvance;
var red:Float = (pColor >> 16 & 0xFF) / 255;
var green:Float = (pColor >> 8 & 0xFF) / 255;
var blue:Float = (pColor & 0xFF) / 255;
// x, y, tile_ID, scale, rotation, red, green, blue, alpha
drawData.push(_point.x); // x
drawData.push(_point.y); // y
drawData.push(glyph); // tile_ID
drawData.push(pScale); // scale
drawData.push(0); // rotation
drawData.push(_point.x + glyph.xoffset * pScale); // x
drawData.push(_point.y + glyph.yoffset * pScale); // y
drawData.push(glyph.tileID); // tile_ID
drawData.push(pScale); // scale
drawData.push(0); // rotation
drawData.push(red);
drawData.push(green);
drawData.push(blue);
drawData.push(pAlpha); // alpha
drawData.push(pAlpha); // alpha
_point.x += glyphWidth * pScale + pLetterSpacing;
#end
}
Expand Down Expand Up @@ -488,11 +494,10 @@ class PxBitmapFont
w += glyph.width;
}
#else
var glyphWidth:Int = _glyphWidthData[charCode];
if (_glyphs.exists(charCode))
{

w += glyphWidth;
w += _glyphs.get(charCode).xadvance;
}
#end
}
Expand Down
15 changes: 0 additions & 15 deletions Haxe/src/pxBitmapFont/PxFontSymbol.hx
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,9 @@ class PxFontSymbol
*/
public var tileID:Int;

/**
* image of symbol
*/
public var bitmapData:BitmapData;

public function new()
{

}

public function dispose():PxFontSymbol
{
if (bitmapData != null)
{
bitmapData.dispose();
}
bitmapData = null;
return this;
}

}

0 comments on commit 7dfec98

Please sign in to comment.