2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
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.
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.
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
22 #if !defined(INCLUDED_IPATCH_H)
23 #define INCLUDED_IPATCH_H
25 #include "generic/constant.h"
26 #include "generic/vector.h"
33 template<typename Element>
39 typedef Element value_type;
40 typedef value_type* iterator;
41 typedef const value_type* const_iterator;
44 : m_size(0), m_data(0)
47 ArrayReference(std::size_t size, Element* data)
48 : m_size(size), m_data(data)
56 const_iterator begin() const
62 return m_data + m_size;
64 const_iterator end() const
66 return m_data + m_size;
69 value_type& operator[](std::size_t index)
72 ASSERT_MESSAGE(index < size(), "array index out of bounds");
76 const value_type& operator[](std::size_t index) const
79 ASSERT_MESSAGE(index < size(), "array index out of bounds");
87 const value_type* data() const
91 std::size_t size() const
102 template<typename Element>
113 typedef std::bidirectional_iterator_tag iterator_category;
114 typedef std::ptrdiff_t difference_type;
115 typedef difference_type distance_type;
116 typedef KeyValue<Key, Value> value_type;
117 typedef value_type* pointer;
118 typedef value_type& reference;
120 MatrixIterator(Element* position) : m_position(position)
129 bool operator==(const MatrixIterator& other) const
131 return m_position == other.m_position;
133 bool operator!=(const MatrixIterator& other) const
135 return !operator==(other);
137 MatrixIterator& operator++()
142 MatrixIterator operator++(int)
144 MatrixIterator tmp = *this;
148 value_type& operator*() const
150 return m_position->m_value;
152 value_type* operator->() const
154 return &(operator*());
159 template<typename Element>
162 std::size_t m_x, m_y;
165 typedef Element value_type;
166 typedef value_type* iterator;
167 typedef const value_type* const_iterator;
170 : m_x(0), m_y(0), m_data(0)
173 Matrix(std::size_t x, std::size_t y, Element* data)
174 : m_x(x), m_y(y), m_data(data)
182 const_iterator begin() const
188 return m_data + size();
190 const_iterator end() const
192 return m_data + size();
195 value_type& operator[](std::size_t index)
198 ASSERT_MESSAGE(index < size(), "array index out of bounds");
200 return m_data[index];
202 const value_type& operator[](std::size_t index) const
205 ASSERT_MESSAGE(index < size(), "array index out of bounds");
207 return m_data[index];
209 value_type& operator()(std::size_t x, std::size_t y)
212 ASSERT_MESSAGE(x < m_x && y < m_y, "array index out of bounds");
214 return m_data[x * m_y + y];
216 const value_type& operator()(std::size_t x, std::size_t y) const
219 ASSERT_MESSAGE(x < m_x && y < m_y, "array index out of bounds");
221 return m_data[x * m_y + y];
227 const value_type* data() const
231 std::size_t x() const
235 std::size_t y() const
239 std::size_t size() const
256 typedef Matrix<PatchControl> PatchControlMatrix;
262 INTEGER_CONSTANT(Version, 1);
263 STRING_CONSTANT(Name, "patch");
264 virtual scene::Node& createPatch() = 0;
265 virtual void Patch_undoSave(scene::Node& patch) const = 0;
266 virtual void Patch_resize(scene::Node& patch, std::size_t width, std::size_t height) const = 0;
267 virtual PatchControlMatrix Patch_getControlPoints(scene::Node& patch) const = 0;
268 virtual void Patch_controlPointsChanged(scene::Node& patch) const = 0;
269 virtual const char* Patch_getShader(scene::Node& patch) const = 0;
270 virtual void Patch_setShader(scene::Node& patch, const char* shader) const = 0;
273 #include "modulesystem.h"
275 template<typename Type>
277 typedef ModuleRef<PatchCreator> PatchModuleRef;
279 template<typename Type>
281 typedef GlobalModule<PatchCreator> GlobalPatchModule;
283 template<typename Type>
284 class GlobalModuleRef;
285 typedef GlobalModuleRef<PatchCreator> GlobalPatchModuleRef;
287 inline PatchCreator& GlobalPatchCreator()
289 return GlobalPatchModule::getTable();