[client] added draw package
This commit is contained in:
16
src/client/haxe/ru/m/draw/BitmapUtil.hx
Normal file
16
src/client/haxe/ru/m/draw/BitmapUtil.hx
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
37
src/client/haxe/ru/m/draw/Color.hx
Normal file
37
src/client/haxe/ru/m/draw/Color.hx
Normal file
@@ -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})';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user