浏览代码

move ColorAjust to Matrix

ncannasse 6 年之前
父节点
当前提交
7741600ad6
共有 2 个文件被更改,包括 18 次插入14 次删除
  1. 2 14
      h2d/Drawable.hx
  2. 16 0
      h3d/Matrix.hx

+ 2 - 14
h2d/Drawable.hx

@@ -1,13 +1,5 @@
 package h2d;
 
-typedef ColorAdjust = {
-	?saturation : Float,
-	?lightness : Float,
-	?hue : Float,
-	?contrast : Float,
-	?gain : { color : Int, alpha : Float },
-};
-
 /**
 	h2d.Drawable is the base class for all 2D objects that will draw something on screen.
 	Unlike Object base class, all properties of Drawable only apply to the current object and are not inherited by its children.
@@ -100,7 +92,7 @@ class Drawable extends Object {
 	/**
 		Set the `colorMatrix` value by specifying which effects to apply. Calling adjustColor() reset the colorMatrix to `null`
 	**/
-	public function adjustColor( ?col : ColorAdjust ) : Void {
+	public function adjustColor( ?col : h3d.Matrix.ColorAdjust ) : Void {
 		if( col == null )
 			colorMatrix = null;
 		else {
@@ -110,11 +102,7 @@ class Drawable extends Object {
 				colorMatrix = m;
 			}
 			m.identity();
-			if( col.hue != null ) m.colorHue(col.hue);
-			if( col.saturation != null ) m.colorSaturate(col.saturation);
-			if( col.contrast != null ) m.colorContrast(col.contrast);
-			if( col.lightness != null ) m.colorLightness(col.lightness);
-			if( col.gain != null ) m.colorGain(col.gain.color, col.gain.alpha);
+			m.adjustColor(col);
 		}
 	}
 

+ 16 - 0
h3d/Matrix.hx

@@ -1,6 +1,14 @@
 package h3d;
 import hxd.Math;
 
+typedef ColorAdjust = {
+	?saturation : Float,
+	?lightness : Float,
+	?hue : Float,
+	?contrast : Float,
+	?gain : { color : Int, alpha : Float },
+};
+
 @:noDebug
 class Matrix {
 
@@ -708,6 +716,14 @@ class Matrix {
 		colorAdd(c);
 	}
 
+	public function adjustColor( col : ColorAdjust ) {
+		if( col.hue != null ) colorHue(col.hue);
+		if( col.saturation != null ) colorSaturate(col.saturation);
+		if( col.contrast != null ) colorContrast(col.contrast);
+		if( col.lightness != null ) colorLightness(col.lightness);
+		if( col.gain != null ) colorGain(col.gain.color, col.gain.alpha);
+	}
+
 	// STATICS
 
 	public static function I() {