colour.h

Go to the documentation of this file.
00001 /*
00002  Copyright (C) 2001-2006, William Joseph.
00003  All Rights Reserved.
00004 
00005  This file is part of GtkRadiant.
00006 
00007  GtkRadiant is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU General Public License as published by
00009  the Free Software Foundation; either version 2 of the License, or
00010  (at your option) any later version.
00011 
00012  GtkRadiant is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU General Public License for more details.
00016 
00017  You should have received a copy of the GNU General Public License
00018  along with GtkRadiant; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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

Generated by  doxygen 1.6.2