From dd1014e2306b3ff3ff328326acd837fab098f5d2 Mon Sep 17 00:00:00 2001 From: shmyga Date: Thu, 8 Feb 2018 17:57:40 +0300 Subject: [PATCH] [client] added draw package --- src/client/haxe/ru/m/draw/BitmapUtil.hx | 16 ++++++++ src/client/haxe/ru/m/draw/Color.hx | 37 +++++++++++++++++++ .../haxe/ru/m/tankz/render/RenderItem.hx | 4 +- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/client/haxe/ru/m/draw/BitmapUtil.hx create mode 100644 src/client/haxe/ru/m/draw/Color.hx diff --git a/src/client/haxe/ru/m/draw/BitmapUtil.hx b/src/client/haxe/ru/m/draw/BitmapUtil.hx new file mode 100644 index 0000000..f112f48 --- /dev/null +++ b/src/client/haxe/ru/m/draw/BitmapUtil.hx @@ -0,0 +1,16 @@ +package ru.m.draw; + +import flash.geom.ColorTransform; +import flash.geom.Rectangle; +import flash.display.BitmapData; + + +class BitmapUtil { + + public static function colorize(data: BitmapData, color: Color):BitmapData { + var result = data.clone(); + var transform = new ColorTransform(1, 1, 1, 1, color.red, color.green, color.blue, color.alpha); + result.colorTransform(new Rectangle(0, 0, result.width, result.height), transform); + return result; + } +} diff --git a/src/client/haxe/ru/m/draw/Color.hx b/src/client/haxe/ru/m/draw/Color.hx new file mode 100644 index 0000000..7f4a352 --- /dev/null +++ b/src/client/haxe/ru/m/draw/Color.hx @@ -0,0 +1,37 @@ +package ru.m.draw; + +abstract Color(Int) { + public var alpha(get, never):Int; + public var red(get, never):Int; + public var green(get, never):Int; + public var blue(get, never):Int; + + public inline function new(value:Int) { + this = value; + } + + private inline function get_alpha():Int { + return (this >> 24) & 255; + } + + private inline function get_red():Int { + return (this >> 16) & 255; + } + + private inline function get_green():Int { + return (this >> 8) & 255; + } + + private inline function get_blue():Int { + return this & 255; + } + + @:from + static public inline function fromString(value:String):Color { + return new Color(Std.parseInt('0x${value.split('#').pop()}')); + } + + public function toString():String { + return 'Color(${red},${green},${blue})'; + } +} diff --git a/src/client/haxe/ru/m/tankz/render/RenderItem.hx b/src/client/haxe/ru/m/tankz/render/RenderItem.hx index 41f5239..772598c 100644 --- a/src/client/haxe/ru/m/tankz/render/RenderItem.hx +++ b/src/client/haxe/ru/m/tankz/render/RenderItem.hx @@ -1,5 +1,6 @@ package ru.m.tankz.render; +import ru.m.draw.BitmapUtil; import ru.m.tankz.game.Game.TeamId; import ru.m.tankz.config.Config.TankType; import ru.m.tankz.control.Control; @@ -154,7 +155,8 @@ class TankItem extends RenderItem { } override public function redraw():Void { - tankView.frames = getFrames().map(function(s) return Assets.getBitmapData(s)); + // ToDo: ImageBundle + tankView.frames = getFrames().map(function(s) return BitmapUtil.colorize(Assets.getBitmapData(s), '#cc0000')); } public static function getTankFrames(team:TeamId, index:Int, type:TankType, hits:Int=0):Array {