00001
00002
00003
00004
00005
00006
00007 #pragma once
00008
00009 #include "..\kernel\value.h"
00010 #include "..\..\bmmlib.h"
00011 #include "3dmath.h"
00012
00013 #define COLOR_CACHE_SIZE 1024 // must be power of 2
00014
00015
00016
00017 applyable_class_debug_ok (ColorValue)
00018
00019 class ColorValue : public Value
00020 {
00021 public:
00022 AColor color;
00023
00024 ENABLE_STACK_ALLOCATE(ColorValue);
00025
00026 ScripterExport ColorValue (AColor col);
00027 ScripterExport ColorValue (Color col);
00028 ScripterExport ColorValue (COLORREF col);
00029 ScripterExport ColorValue (BMM_Color_64& col);
00030 ScripterExport ColorValue (Point3 col);
00031 ScripterExport ColorValue (Point3Value* col);
00032 ScripterExport ColorValue (float r, float g, float b, float a = 1.0f);
00033
00034 static ScripterExport Value* intern(AColor col);
00035 static ScripterExport Value* intern(float r, float g, float b, float a = 1.0f);
00036 static ScripterExport Value* intern(BMM_Color_64& col);
00037
00038 classof_methods (ColorValue, Value);
00039 void collect() { delete this; }
00040 ScripterExport void sprin1(CharStream* s);
00041 # define is_color(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(ColorValue))
00042
00043 #include "..\macros\define_implementations.h"
00044 # include "..\protocols\color.inl"
00045 def_generic ( coerce, "coerce");
00046 def_generic ( copy, "copy");
00047
00048 def_property ( red );
00049 def_local_prop_alias ( r, red );
00050 def_property ( green );
00051 def_local_prop_alias ( g, green );
00052 def_property ( blue );
00053 def_local_prop_alias ( b, blue );
00054 def_property ( alpha );
00055 def_local_prop_alias ( a, alpha );
00056 def_property ( hue );
00057 def_local_prop_alias ( h, hue );
00058 def_property ( saturation );
00059 def_local_prop_alias ( s, saturation );
00060 def_property ( value );
00061 def_local_prop_alias ( v, value );
00062
00063 AColor to_acolor() { return color; }
00064 Color to_color() { return Color (color.r, color.g, color.b); }
00065 COLORREF to_colorref() { return RGB((int)(color.r * 255.0f), (int)(color.g * 255.0f), (int)(color.b * 255.0f)); }
00066 Point3 to_point3() { return Point3 (color.r * 255.0, color.g * 255.0, color.b * 255.0); }
00067 Point4 to_point4() { return Point4 (color.r, color.g, color.b, color.a); }
00068 void to_fpvalue(FPValue& v);
00069
00070
00071 IOResult Save(ISave* isave);
00072 static Value* Load(ILoad* iload, USHORT chunkID, ValueLoader* vload);
00073 };
00074
00075 class ConstColorValue : public ColorValue
00076 {
00077 public:
00078 ScripterExport ConstColorValue (float r, float g, float b, float a = 1.0f)
00079 : ColorValue(r, g, b, a) { }
00080
00081 void collect() { delete this; }
00082 BOOL is_const() { return TRUE; }
00083 #pragma warning(push)
00084 #pragma warning(disable:4100)
00085 Value* set_red(Value** arg_list, int count) { throw RuntimeError (_M("Constant color, not settable")); return NULL; }
00086 Value* set_green(Value** arg_list, int count) { throw RuntimeError (_M("Constant color, not settable")); return NULL; }
00087 Value* set_blue(Value** arg_list, int count) { throw RuntimeError (_M("Constant color, not settable")); return NULL; }
00088 Value* set_alpha(Value** arg_list, int count) { throw RuntimeError (_M("Constant color, not settable")); return NULL; }
00089 Value* set_hue(Value** arg_list, int count) { throw RuntimeError (_M("Constant color, not settable")); return NULL; }
00090 Value* set_h(Value** arg_list, int count) { throw RuntimeError (_M("Constant color, not settable")); return NULL; }
00091 Value* set_saturation(Value** arg_list, int count) { throw RuntimeError (_M("Constant color, not settable")); return NULL; }
00092 Value* set_value(Value** arg_list, int count) { throw RuntimeError (_M("Constant color, not settable")); return NULL; }
00093 #pragma warning(pop)
00094 };
00095