1 /*
2  Copyright (C) 2001-2006, William Joseph.
3  All Rights Reserved.
4 
5  This file is part of GtkRadiant.
6 
7  GtkRadiant is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  GtkRadiant is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with GtkRadiant; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21 
22 #if !defined(INCLUDED_COLOUR_H)
23 #define INCLUDED_COLOUR_H
24 
25 #include "ientity.h"
26 #include "irender.h"
27 
28 #include "eclasslib.h"
29 #include "generic/callback.h"
30 #include "stringio.h"
31 
32 class ColourKey
33 {
34 	private:
35 
default_colour()36 		void default_colour ()
37 		{
38 			m_colour = Vector3(1, 1, 1);
39 		}
40 
41 		Callback m_colourChanged;
42 		Shader* m_state;
43 
capture_state()44 		void capture_state ()
45 		{
46 			m_state = colour_capture_state_fill(m_colour);
47 		}
release_state()48 		void release_state ()
49 		{
50 			colour_release_state_fill(m_colour);
51 		}
52 
53 	public:
54 		Vector3 m_colour;
55 
ColourKey(const Callback & colourChanged)56 		ColourKey (const Callback& colourChanged) :
57 			m_colourChanged(colourChanged)
58 		{
59 			default_colour();
60 			capture_state();
61 		}
~ColourKey()62 		~ColourKey ()
63 		{
64 			release_state();
65 		}
66 
colourChanged(const std::string & value)67 		void colourChanged (const std::string& value)
68 		{
69 			release_state();
70 			if (!string_parse_vector3(value, m_colour)) {
71 				default_colour();
72 			}
73 			capture_state();
74 
75 			m_colourChanged();
76 		}
77 		typedef MemberCaller1<ColourKey, const std::string&, &ColourKey::colourChanged> ColourChangedCaller;
78 
write(Entity * entity)79 		void write (Entity* entity) const
80 		{
81 			entity->setKeyValue("_color", m_colour);
82 		}
83 
state()84 		Shader* state () const
85 		{
86 			return m_state;
87 		}
88 };
89 
90 #endif
91