colour.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if !defined(INCLUDED_COLOUR_H)
00023 #define INCLUDED_COLOUR_H
00024
00025 #include "ientity.h"
00026 #include "irender.h"
00027
00028 #include "eclasslib.h"
00029 #include "generic/callback.h"
00030 #include "stringio.h"
00031
00032 inline void default_colour (Vector3& colour)
00033 {
00034 colour = Vector3(1, 1, 1);
00035 }
00036 inline void read_colour (Vector3& colour, const char* value)
00037 {
00038 if (!string_parse_vector3(value, colour)) {
00039 default_colour(colour);
00040 }
00041 }
00042 inline void write_colour (const Vector3& colour, Entity* entity)
00043 {
00044 char value[64];
00045
00046 sprintf(value, "%f %f %f", colour[0], colour[1], colour[2]);
00047 entity->setKeyValue("_color", value);
00048 }
00049
00050 class Colour
00051 {
00052 Callback m_colourChanged;
00053 Shader* m_state;
00054
00055 void capture_state ()
00056 {
00057 m_state = colour_capture_state_fill(m_colour);
00058 }
00059 void release_state ()
00060 {
00061 colour_release_state_fill(m_colour);
00062 }
00063
00064 public:
00065 Vector3 m_colour;
00066
00067 Colour (const Callback& colourChanged) :
00068 m_colourChanged(colourChanged)
00069 {
00070 default_colour(m_colour);
00071 capture_state();
00072 }
00073 ~Colour ()
00074 {
00075 release_state();
00076 }
00077
00078 void colourChanged (const std::string& value)
00079 {
00080 release_state();
00081 read_colour(m_colour, value.c_str());
00082 capture_state();
00083
00084 m_colourChanged();
00085 }
00086 typedef MemberCaller1<Colour, const std::string&, &Colour::colourChanged> ColourChangedCaller;
00087
00088 void write (Entity* entity) const
00089 {
00090 write_colour(m_colour, entity);
00091 }
00092
00093 Shader* state () const
00094 {
00095 return m_state;
00096 }
00097 };
00098
00099 #endif