forked from openfl/openfl
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply ColorTransform directly when rendering text and shapes
This patch refactors and de-duplicates code in the Cairo and Canvas rendering classes and implements the application of color transforms to TextFields and (Shape) Graphics. It introduces 2 new macros to ColorTransform that help calculate the RGBA values without temporary allocations. If and when Haxe supports multiple inline return values, these could be rewritten. Drawing Bitmaps with ColorTransform is untested and not implemented by this patch.
- Loading branch information
Showing
11 changed files
with
205 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package openfl._internal.renderer.cairo; | ||
|
||
|
||
import haxe.macro.Expr; | ||
import openfl.geom.ColorTransform; | ||
|
||
|
||
class CairoUtils | ||
{ | ||
public static inline var scale = 1/0xFF; | ||
|
||
public static macro function applyColorTransform(colorTransform : ExprOf<ColorTransform>, rgb : ExprOf<Int>, a : ExprOf<Float>, rgbaExpr : Expr) : Expr | ||
{ | ||
return macro ColorTransform.__with_var_rgba($rgb, $a, | ||
{ | ||
var r:Float = r; | ||
var g:Float = g; | ||
var b:Float = b; | ||
|
||
if ($colorTransform != null) | ||
colorTransform.__apply_to_var_rgba(); | ||
|
||
r *= CairoUtils.scale; | ||
g *= CairoUtils.scale; | ||
b *= CairoUtils.scale; | ||
$rgbaExpr; | ||
} | ||
); | ||
} | ||
} |
Oops, something went wrong.