2
0
Эх сурвалжийг харах

Expose Color constants in AngelScript. Use them in sample app.

Yao Wei Tjong 姚伟忠 11 жил өмнө
parent
commit
41df6dc2e0

+ 5 - 5
Bin/Data/Scripts/30_LightAnimation.as

@@ -56,11 +56,11 @@ void CreateScene()
 
     // Create light color animation
     AttributeAnimation@ colorAnimation = AttributeAnimation();
-    colorAnimation.SetKeyFrame(0.0f, Variant(Color(1.0f, 1.0f, 1.0f)));
-    colorAnimation.SetKeyFrame(1.0f, Variant(Color(1.0f, 0.0f, 0.0f)));
-    colorAnimation.SetKeyFrame(2.0f, Variant(Color(1.0f, 1.0f, 0.0f)));
-    colorAnimation.SetKeyFrame(3.0f, Variant(Color(0.0f, 1.0f, 0.0f)));
-    colorAnimation.SetKeyFrame(4.0f, Variant(Color(1.0f, 1.0f, 1.0f)));
+    colorAnimation.SetKeyFrame(0.0f, Variant(WHITE));
+    colorAnimation.SetKeyFrame(1.0f, Variant(RED));
+    colorAnimation.SetKeyFrame(2.0f, Variant(YELLOW));
+    colorAnimation.SetKeyFrame(3.0f, Variant(GREEN));
+    colorAnimation.SetKeyFrame(4.0f, Variant(WHITE));
     light.SetAttributeAnimation("Color", colorAnimation);
 
     // Create more StaticModel objects to the scene, randomly positioned, rotated and scaled. For rotation, we construct a

+ 11 - 0
Source/Engine/Script/MathAPI.cpp

@@ -1149,6 +1149,17 @@ static void RegisterColor(asIScriptEngine* engine)
     engine->RegisterObjectProperty("Color", "float g", offsetof(Color, g_));
     engine->RegisterObjectProperty("Color", "float b", offsetof(Color, b_));
     engine->RegisterObjectProperty("Color", "float a", offsetof(Color, a_));
+
+    engine->RegisterGlobalProperty("const Color WHITE", (void*)&Color::WHITE);
+    engine->RegisterGlobalProperty("const Color GRAY", (void*)&Color::GRAY);
+    engine->RegisterGlobalProperty("const Color BLACK", (void*)&Color::BLACK);
+    engine->RegisterGlobalProperty("const Color RED", (void*)&Color::RED);
+    engine->RegisterGlobalProperty("const Color GREEN", (void*)&Color::GREEN);
+    engine->RegisterGlobalProperty("const Color BLUE", (void*)&Color::BLUE);
+    engine->RegisterGlobalProperty("const Color CYAN", (void*)&Color::CYAN);
+    engine->RegisterGlobalProperty("const Color MAGENTA", (void*)&Color::MAGENTA);
+    engine->RegisterGlobalProperty("const Color YELLOW", (void*)&Color::YELLOW);
+    engine->RegisterGlobalProperty("const Color TRANSPARENT", (void*)&Color::TRANSPARENT);
 }
 
 void RegisterMathAPI(asIScriptEngine* engine)