diff --git a/Haxe/lib/bitmapFont/BitmapFont.hx b/Haxe/lib/bitmapFont/BitmapFont.hx index a47f87b..ad7431e 100644 --- a/Haxe/lib/bitmapFont/BitmapFont.hx +++ b/Haxe/lib/bitmapFont/BitmapFont.hx @@ -2,7 +2,7 @@ package bitmapFont; import haxe.Utf8; import haxe.xml.Fast; -import openfl.display.Tilesheet; +import openfl.display.Tileset; import openfl.display.BitmapData; import openfl.display.Graphics; import openfl.geom.ColorTransform; @@ -11,7 +11,7 @@ import openfl.geom.Point; import openfl.geom.Rectangle; #if RENDER_TILE -import openfl.display.Tilesheet; +import openfl.display.Tileset; #end /** @@ -172,7 +172,7 @@ class BitmapFont public var glyphs:Map; #if RENDER_TILE - public var tilesheet:Tilesheet; + public var tilesheet:Tileset; #end /** @@ -183,7 +183,7 @@ class BitmapFont this.bitmap = bitmap; this.fontName = name; #if RENDER_TILE - tilesheet = new Tilesheet(bitmap); + tilesheet = new Tileset(bitmap); #end glyphs = new Map(); BitmapFont.store(name, this); @@ -536,7 +536,8 @@ class BitmapFont glyphFrame.rect = frame; #if RENDER_TILE - glyphFrame.tileID = tilesheet.addTileRect(frame, new Point(0, 0)); + //glyphFrame.tileID = tilesheet.addTileRect(frame, new Point(0, 0)); + glyphFrame.tileID = tilesheet.addRect(frame); #end glyphs.set(charCode, glyphFrame); @@ -645,7 +646,7 @@ class BitmapGlyphCollection public var glyphs:Array; - public var color:UInt; + public var color:Int; public var scale:Float; diff --git a/Haxe/lib/bitmapFont/BitmapTextField.hx b/Haxe/lib/bitmapFont/BitmapTextField.hx index 4a89e3d..9e190ce 100644 --- a/Haxe/lib/bitmapFont/BitmapTextField.hx +++ b/Haxe/lib/bitmapFont/BitmapTextField.hx @@ -10,7 +10,10 @@ import flash.geom.Point; import bitmapFont.BitmapFont; import haxe.Utf8; import openfl.display.PixelSnapping; -import openfl.display.Tilesheet; +import openfl.display.Tile; +import openfl.display.Tilemap; +import openfl.display.Tileset; +import openfl.geom.ColorTransform; /** * Class for rendering text with provided bitmap font and some additional options. @@ -74,7 +77,7 @@ class BitmapTextField extends Sprite public var autoSize(default, set):Bool = true; /** - * Number of pixels between text and text field border + * Number of pixels between text and text field border. Default is 0. */ public var padding(default, set):Int = 0; @@ -94,40 +97,59 @@ class BitmapTextField extends Sprite public var lineHeight(get, null):Float; /** - * Number of space characters in one tab. + * Number of space characters in one tab. Default is 4. */ public var numSpacesInTab(default, set):Int = 4; private var _tabSpaces:String = " "; + //#if RENDER_TILE + public var textAlpha(default, set):Float = 1; + //#end + /** - * The color of the text in 0xAARRGGBB format. + * The color of the text in 0xAARRGGBB format. Default is 0xFFFFFFFF. */ - public var textColor(default, set):UInt = 0xFFFFFFFF; + public var textColor(default, set):Int = 0xFFFFFFFF; /** - * Whether to use textColor while rendering or not. + * The color of the text in 0xRRGGBB format. Default is 0xFFFFFF. + */ + public var textColorRGB(default, set):Int = 0xFFFFFFFF; + + /** + * Whether to use textColor while rendering or not. Default is false. */ public var useTextColor(default, set):Bool = false; /** - * Use a border style + * Use a border style. Default is TextBorderStyle.NONE */ public var borderStyle(default, set):TextBorderStyle = NONE; /** - * The color of the border in 0xAARRGGBB format + * + */ + public var borderAlpha(default, set):Float = 1; + + /** + * The color of the border in 0xAARRGGBB format. Default is 0xFF000000. */ - public var borderColor(default, set):UInt = 0xFF000000; + public var borderColor(default, set):Int = 0xFF000000; /** - * The size of the border, in pixels. + * The color of the border in 0xRRGGBB format. Default is 0x000000. + */ + public var borderColorRGB(default, set):Int = 0x000000; + + /** + * The size of the border, in pixels. Default is 1. */ public var borderSize(default, set):Float = 1; /** * How many iterations do use when drawing the border. 0: only 1 iteration, 1: one iteration for every pixel in borderSize * A value of 1 will have the best quality for large border sizes, but might reduce performance when changing text. - * NOTE: If the borderSize is 1, borderQuality of 0 or 1 will have the exact same effect (and performance). + * NOTE: If the borderSize is 1, borderQuality of 0 or 1 will have the exact same effect (and performance). Default is 0. */ public var borderQuality(default, set):Float = 0; @@ -145,10 +167,10 @@ class BitmapTextField extends Sprite /** * Specifies the color of background in 0xAARRGGBB format. */ - public var backgroundColor(default, set):UInt = 0x00000000; + public var backgroundColor(default, set):Int = 0x00000000; /** - * Specifies whether the text field will break into multiple lines or not on overflow. + * Specifies whether the text field will break into multiple lines or not on overflow. Default is true */ public var multiLine(default, set):Bool = true; @@ -199,7 +221,8 @@ class BitmapTextField extends Sprite private var _point:Point; #else - private var _drawData:Array; + //private var _drawData:Array; + private var _tilemap:Tilemap; #end /** @@ -220,7 +243,8 @@ class BitmapTextField extends Sprite addChild(_bitmap); _point = new Point(); #else - _drawData = []; + //_drawData = []; + //_tilemap = new Tilemap( #end if (font == null) @@ -273,7 +297,13 @@ class BitmapTextField extends Sprite } _bitmapData = null; #else - _drawData = null; + //_drawData = null; + if (_tilemap != null) + { + removeChild(_tilemap); + _tilemap.removeTiles(); + _tilemap = null; + } #end } @@ -318,42 +348,6 @@ class BitmapTextField extends Sprite } } - private function set_textColor(value:UInt):UInt - { - if (textColor != value) - { - textColor = value; - _pendingTextGlyphsChange = true; - checkImmediateChanges(); - } - - return value; - } - - private function set_useTextColor(value:Bool):Bool - { - if (useTextColor != value) - { - useTextColor = value; - _pendingTextGlyphsChange = true; - checkImmediateChanges(); - } - - return value; - } - - private function set_text(value:String):String - { - if (value != text && value != null) - { - text = value; - _pendingTextChange = true; - checkImmediateChanges(); - } - - return value; - } - private function updateText():Void { var tmp:String = (autoUpperCase) ? text.toUpperCase() : text; @@ -779,7 +773,7 @@ class BitmapTextField extends Sprite var isSpaceWord:Bool = false; // whether current word consists of spaces or not - var char:String; // current character in word + //var char:String; // current character in word var charCode:Int; var c:Int; // char index var charWidth:Float = 0; // the width of current character @@ -903,19 +897,25 @@ class BitmapTextField extends Sprite _bitmapData.fillRect(_bitmapData.rect, colorForFill); } #else - this.graphics.clear(); - - if (colorForFill != 0x00000000) - { - this.graphics.beginFill(colorForFill & 0x00FFFFFF, ((colorForFill >> 24) & 0xFF) / 255); - this.graphics.drawRect(0, 0, _fieldWidth, _fieldHeight); - this.graphics.endFill(); + //this.graphics.clear(); + // + //if (colorForFill != 0x00000000) + //{ + //this.graphics.beginFill(colorForFill & 0x00FFFFFF, ((colorForFill >> 24) & 0xFF) / 255); + //this.graphics.drawRect(0, 0, _fieldWidth, _fieldHeight); + //this.graphics.endFill(); + //} + + var colorForBorder:Int = (borderStyle != TextBorderStyle.NONE) ? borderColorRGB : 0xFFFFFF; + var colorForText:Int = (useTextColor) ? textColorRGB : 0xFFFFFF; + + //_drawData.splice(0, _drawData.length); + if (_tilemap != null) { + removeChild(_tilemap); + _tilemap.removeTiles(); } - - var colorForBorder:UInt = (borderStyle != TextBorderStyle.NONE) ? borderColor : 0xFFFFFFFF; - var colorForText:UInt = (useTextColor) ? textColor : 0xFFFFFFFF; - - _drawData.splice(0, _drawData.length); + _tilemap = new Tilemap(_fieldWidth, _fieldHeight, font.tilesheet, smoothing); + addChild(_tilemap); #end if (size > 0) @@ -985,7 +985,7 @@ class BitmapTextField extends Sprite #if RENDER_BLIT blitLine(line, borderGlyphs, ox + deltaX * (iterX + 1), oy + deltaY * (iterY + 1)); #else - renderLine(line, colorForBorder, ox + deltaX * (iterX + 1), oy + deltaY * (iterY + 1)); + renderLine(line, borderColorRGB, borderAlpha, ox + deltaX * (iterX + 1), oy + deltaY * (iterY + 1)); #end } } @@ -1015,21 +1015,21 @@ class BitmapTextField extends Sprite blitLine(line, borderGlyphs, ox + itd, oy + itd); #else //upper-left - renderLine(line, colorForBorder, ox - itd, oy - itd); + renderLine(line, borderColorRGB, borderAlpha, ox - itd, oy - itd); //upper-middle - renderLine(line, colorForBorder, ox, oy - itd); + renderLine(line, borderColorRGB, borderAlpha, ox, oy - itd); //upper-right - renderLine(line, colorForBorder, ox + itd, oy - itd); + renderLine(line, borderColorRGB, borderAlpha, ox + itd, oy - itd); //middle-left - renderLine(line, colorForBorder, ox - itd, oy); + renderLine(line, borderColorRGB, borderAlpha, ox - itd, oy); //middle-right - renderLine(line, colorForBorder, ox + itd, oy); + renderLine(line, borderColorRGB, borderAlpha, ox + itd, oy); //lower-left - renderLine(line, colorForBorder, ox - itd, oy + itd); + renderLine(line, borderColorRGB, borderAlpha, ox - itd, oy + itd); //lower-middle - renderLine(line, colorForBorder, ox, oy + itd); + renderLine(line, borderColorRGB, borderAlpha, ox, oy + itd); //lower-right - renderLine(line, colorForBorder, ox + itd, oy + itd); + renderLine(line, borderColorRGB, borderAlpha, ox + itd, oy + itd); #end } case OUTLINE_FAST: @@ -1051,13 +1051,13 @@ class BitmapTextField extends Sprite blitLine(line, borderGlyphs, ox + itd, oy + itd); #else //upper-left - renderLine(line, colorForBorder, ox - itd, oy - itd); + renderLine(line, borderColorRGB, borderAlpha, ox - itd, oy - itd); //upper-right - renderLine(line, colorForBorder, ox + itd, oy - itd); + renderLine(line, borderColorRGB, borderAlpha, ox + itd, oy - itd); //lower-left - renderLine(line, colorForBorder, ox - itd, oy + itd); + renderLine(line, borderColorRGB, borderAlpha, ox - itd, oy + itd); //lower-right - renderLine(line, colorForBorder, ox + itd, oy + itd); + renderLine(line, borderColorRGB, borderAlpha, ox + itd, oy + itd); #end } case NONE: @@ -1090,14 +1090,14 @@ class BitmapTextField extends Sprite #if RENDER_BLIT blitLine(line, textGlyphs, ox, oy); #else - renderLine(line, colorForText, ox, oy); + renderLine(line, colorForText, textAlpha, ox, oy); #end } #if RENDER_BLIT _bitmapData.unlock(); #else - font.tilesheet.drawTiles(this.graphics, _drawData, smoothing, Tilesheet.TILE_SCALE | Tilesheet.TILE_RGB | Tilesheet.TILE_ALPHA); + //font.tilesheet.drawTiles(this.graphics, _drawData, smoothing, Tilesheet.TILE_SCALE | Tilesheet.TILE_RGB | Tilesheet.TILE_ALPHA); #end } @@ -1147,7 +1147,7 @@ class BitmapTextField extends Sprite } } #else - private function renderLine(line:String, color:UInt, startX:Int, startY:Int):Void + private function renderLine(line:String, color:Int, alpha:Float, startX:Int, startY:Int):Void { var glyph:BitmapGlyphFrame; var charCode:Int; @@ -1160,9 +1160,9 @@ class BitmapTextField extends Sprite var r:Float = ((color >> 16) & 0xFF) / 255; var g:Float = ((color >> 8) & 0xFF) / 255; var b:Float = (color & 0xFF) / 255; - var a:Float = ((color >> 24) & 0xFF) / 255; + //var a:Float = ((color >> 24) & 0xFF) / 255; - var pos:Int = _drawData.length; + var tile:Tile; var lineLength:Int = Utf8.length(line); @@ -1183,17 +1183,12 @@ class BitmapTextField extends Sprite glyph = font.glyphs.get(charCode); if (glyph != null) { - _drawData[pos++] = curX + glyph.xoffset * size; - _drawData[pos++] = curY + glyph.yoffset * size; - - _drawData[pos++] = glyph.tileID; - - _drawData[pos++] = size; - - _drawData[pos++] = r; - _drawData[pos++] = g; - _drawData[pos++] = b; - _drawData[pos++] = a; + //_tilemap.addTile(new Tile(glyph.tileID, curX + glyph.xoffset * size, curY + glyph.yoffset * size, size, size)); + tile = new Tile(glyph.tileID, curX + glyph.xoffset * size, curY + glyph.yoffset * size, size, size); + //tile.colorTransform.color = color; // this colors everything the same : if you have a border it will get colored too + tile.colorTransform = new ColorTransform(r, g, b); + tile.alpha = alpha; + _tilemap.addTile(tile); curX += glyph.xadvance * size; } @@ -1212,7 +1207,7 @@ class BitmapTextField extends Sprite * @param Size outline size in pixels * @param Quality outline quality - # of iterations to use when drawing. 0:just 1, 1:equal number to BorderSize */ - public inline function setBorderStyle(Style:TextBorderStyle, Color:UInt = 0xFFFFFFFF, Size:Float = 1, Quality:Float = 1):Void + public inline function setBorderStyle(Style:TextBorderStyle, Color:Int = 0xFFFFFFFF, Size:Float = 1, Quality:Float = 1):Void { borderStyle = Style; borderColor = Color; @@ -1226,6 +1221,74 @@ class BitmapTextField extends Sprite checkImmediateChanges(); } + private function set_text(value:String):String + { + if (value != text && value != null) + { + text = value; + + _pendingTextChange = true; + checkImmediateChanges(); + } + + return value; + } + + private function set_textAlpha(value:Float):Float + { + if (textAlpha != value) + { + textAlpha = value; + textColor = TextColorUtil.getColor32(Std.int(textAlpha * 255), TextColorUtil.getRed(textColor), TextColorUtil.getGreen(textColor), TextColorUtil.getBlue(textColor)); + + _pendingTextGlyphsChange = true; + checkImmediateChanges(); + } + + return value; + } + + private function set_textColor(value:Int):Int + { + if (textColor != value) + { + textColor = value; + textColorRGB = TextColorUtil.RGBAtoRGB(value); + textAlpha = TextColorUtil.getAlphaFloat(value); + + _pendingTextGlyphsChange = true; + checkImmediateChanges(); + } + + return value; + } + + private function set_textColorRGB(value:Int):Int + { + if (textColorRGB != value) + { + textColorRGB = value; + textColor = TextColorUtil.getColor32(Std.int(textAlpha * 255), TextColorUtil.getRed(textColorRGB), TextColorUtil.getGreen(textColorRGB), TextColorUtil.getBlue(textColorRGB)); + + _pendingTextGlyphsChange = true; + checkImmediateChanges(); + } + + return value; + } + + private function set_useTextColor(value:Bool):Bool + { + if (useTextColor != value) + { + useTextColor = value; + _pendingTextGlyphsChange = true; + checkImmediateChanges(); + } + + return value; + } + /** * Sets the width of the text field. If the text does not fit, it will spread on multiple lines. */ @@ -1419,7 +1482,7 @@ class BitmapTextField extends Sprite return value; } - private function set_backgroundColor(value:UInt):UInt + private function set_backgroundColor(value:Int):Int { if (backgroundColor != value) { @@ -1443,13 +1506,53 @@ class BitmapTextField extends Sprite return borderStyle; } - private function set_borderColor(value:UInt):UInt + private function set_borderAlpha(value:Float):Float + { + if (borderAlpha != value) + { + borderAlpha = value; + borderColor = TextColorUtil.getColor32(Std.int(borderAlpha * 255), TextColorUtil.getRed(borderColor), TextColorUtil.getGreen(borderColor), TextColorUtil.getBlue(borderColor)); + + if (borderStyle != TextBorderStyle.NONE) + { + _pendingGraphicChange = true; + checkImmediateChanges(); + } + } + + return value; + } + + private function set_borderColor(value:Int):Int { if (borderColor != value) { borderColor = value; - _pendingBorderGlyphsChange = true; - checkImmediateChanges(); + borderColorRGB = TextColorUtil.RGBAtoRGB(value); + borderAlpha = TextColorUtil.getAlphaFloat(value); + + if (borderStyle != TextBorderStyle.NONE) + { + _pendingGraphicChange = true; + checkImmediateChanges(); + } + } + + return value; + } + + private function set_borderColorRGB(value:Int):Int + { + if (borderColorRGB != value) + { + borderColorRGB = value; + borderColor = TextColorUtil.getColor32(Std.int(borderAlpha * 255), TextColorUtil.getRed(borderColorRGB), TextColorUtil.getGreen(borderColorRGB), TextColorUtil.getBlue(borderColorRGB)); + + if (borderStyle != TextBorderStyle.NONE) + { + _pendingGraphicChange = true; + checkImmediateChanges(); + } } return value; @@ -1457,7 +1560,7 @@ class BitmapTextField extends Sprite private function set_borderSize(value:Float):Float { - if (value != borderSize) + if (borderSize != value) { borderSize = value; @@ -1587,4 +1690,4 @@ class BitmapTextField extends Sprite _pendingBorderGlyphsChange = false; _pendingGraphicChange = true; } -} \ No newline at end of file +} diff --git a/Haxe/lib/bitmapFont/TextColorUtil.hx b/Haxe/lib/bitmapFont/TextColorUtil.hx new file mode 100644 index 0000000..812f78b --- /dev/null +++ b/Haxe/lib/bitmapFont/TextColorUtil.hx @@ -0,0 +1,97 @@ +package bitmapFont; + +/** + * ... + * @author Matse + */ +class TextColorUtil +{ + /** + * DISCLAIMER : These functions are copied from stablexui ColorUtils, I don't know the name of the author at the time being but thanks man ! + */ + + /** + * Given a native color value (in the format 0xAARRGGBB) this will return the Alpha component as a value between 0 and 1 + * + * @param Color In the format 0xAARRGGBB + * @return The Alpha component of the color, will be between 0 and 1 (0 being no Alpha (opaque), 1 full Alpha (transparent)) + */ + inline static public function getAlphaFloat(Color:Int):Float + { + var f:Int = (Color >> 24) & 0xFF; + return f / 255; + } + + /** + * Turn a color with alpha and rgb values into a color without the alpha comoponent. + * Example: 0x55ff0000 becomes 0xff0000 + * + * @param Color The Color to convert + * @return The color without its alpha component + */ + inline static public function RGBAtoRGB(Color:Int):Int + { + return getColor24(getRed(Color), getGreen(Color), getBlue(Color)); + } + + /** + * Given 3 color values this will return an integer representation of it + * + * @param Red The Red channel value (between 0 and 255) + * @param Green The Green channel value (between 0 and 255) + * @param Blue The Blue channel value (between 0 and 255) + * @return A native color value integer (format: 0xRRGGBB) + */ + inline static public function getColor24(Red:Int, Green:Int, Blue:Int):Int + { + return Red << 16 | Green << 8 | Blue; + } + + /** + * Given an alpha and 3 color values this will return an integer representation of it + * + * @param Alpha The Alpha value (between 0 and 255) + * @param Red The Red channel value (between 0 and 255) + * @param Green The Green channel value (between 0 and 255) + * @param Blue The Blue channel value (between 0 and 255) + * @return A native color value integer (format: 0xAARRGGBB) + */ + inline static public function getColor32(Alpha:Int, Red:Int, Green:Int, Blue:Int):Int + { + return Alpha << 24 | Red << 16 | Green << 8 | Blue; + } + + /** + * Given a native color value (in the format 0xAARRGGBB) this will return the Red component, as a value between 0 and 255 + * + * @param Color In the format 0xAARRGGBB + * @return The Red component of the color, will be between 0 and 255 (0 being no color, 255 full Red) + */ + inline static public function getRed(Color:Int):Int + { + return Color >> 16 & 0xFF; + } + + /** + * Given a native color value (in the format 0xAARRGGBB) this will return the Green component, as a value between 0 and 255 + * + * @param Color In the format 0xAARRGGBB + * @return The Green component of the color, will be between 0 and 255 (0 being no color, 255 full Green) + */ + inline static public function getGreen(Color:Int):Int + { + return Color >> 8 & 0xFF; + } + + /** + * Given a native color value (in the format 0xAARRGGBB) this will return the Blue component, as a value between 0 and 255 + * + * @param Color In the format 0xAARRGGBB + * @return The Blue component of the color, will be between 0 and 255 (0 being no color, 255 full Blue) + */ + inline static public function getBlue(Color:Int):Int + { + return Color & 0xFF; + } + +} \ No newline at end of file diff --git a/Haxe/lib/include.xml b/Haxe/lib/include.xml index d1005eb..2882a64 100644 --- a/Haxe/lib/include.xml +++ b/Haxe/lib/include.xml @@ -3,7 +3,7 @@ - +