|
1 | 1 | #include "RE/G/GFxValue.h" |
2 | 2 |
|
| 3 | +#include "RE/G/GColor.h" |
| 4 | + |
3 | 5 | namespace RE |
4 | 6 | { |
5 | 7 | GFxValue::DisplayInfo::DisplayInfo(double a_x, double a_y) : |
@@ -992,6 +994,54 @@ namespace RE |
992 | 994 | return _objectInterface->GotoAndPlay(_value.obj, a_frame, true); |
993 | 995 | } |
994 | 996 |
|
| 997 | + bool GFxValue::SetColorTint(const GColor& a_tint) |
| 998 | + { |
| 999 | + assert(IsDisplayObject()); |
| 1000 | + |
| 1001 | + using Cxform = GRenderer::Cxform; |
| 1002 | + |
| 1003 | + Cxform colorTransform; |
| 1004 | + if (!GetCxform(&colorTransform)) { |
| 1005 | + return false; |
| 1006 | + } |
| 1007 | + |
| 1008 | + // Normalize color values from 0-255 to 0-1 |
| 1009 | + float normalizedRed = a_tint.colorData.channels.red / 255.0f; |
| 1010 | + float normalizedGreen = a_tint.colorData.channels.green / 255.0f; |
| 1011 | + float normalizedBlue = a_tint.colorData.channels.blue / 255.0f; |
| 1012 | + |
| 1013 | + // Use alpha channel as intensity (0-255 -> 0-1) |
| 1014 | + float intensity = a_tint.colorData.channels.alpha / 255.0f; |
| 1015 | + |
| 1016 | + // Apply color transform |
| 1017 | + // Multiply: reduce the original color channels that aren't the tint color |
| 1018 | + colorTransform.matrix[Cxform::kR][Cxform::kMult] = 1.0f - (intensity * (1.0f - normalizedRed)); |
| 1019 | + colorTransform.matrix[Cxform::kG][Cxform::kMult] = 1.0f - (intensity * (1.0f - normalizedGreen)); |
| 1020 | + colorTransform.matrix[Cxform::kB][Cxform::kMult] = 1.0f - (intensity * (1.0f - normalizedBlue)); |
| 1021 | + colorTransform.matrix[Cxform::kA][Cxform::kMult] = 1.0f; |
| 1022 | + |
| 1023 | + // Add: boost the tint color channels |
| 1024 | + colorTransform.matrix[Cxform::kR][Cxform::kAdd] = intensity * normalizedRed * 0.5f; |
| 1025 | + colorTransform.matrix[Cxform::kG][Cxform::kAdd] = intensity * normalizedGreen * 0.5f; |
| 1026 | + colorTransform.matrix[Cxform::kB][Cxform::kAdd] = intensity * normalizedBlue * 0.5f; |
| 1027 | + colorTransform.matrix[Cxform::kA][Cxform::kAdd] = 0.0f; |
| 1028 | + |
| 1029 | + return SetCxform(colorTransform); |
| 1030 | + } |
| 1031 | + |
| 1032 | + bool GFxValue::RemoveColorTint() |
| 1033 | + { |
| 1034 | + assert(IsDisplayObject()); |
| 1035 | + |
| 1036 | + GRenderer::Cxform colorTransform; |
| 1037 | + if (!GetCxform(&colorTransform)) { |
| 1038 | + return false; |
| 1039 | + } |
| 1040 | + colorTransform.SetIdentity(); |
| 1041 | + |
| 1042 | + return SetCxform(colorTransform); |
| 1043 | + } |
| 1044 | + |
995 | 1045 | bool GFxValue::IsManagedValue() const |
996 | 1046 | { |
997 | 1047 | return _type.all(ValueType::kManagedBit); |
|
0 commit comments