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 "debugging/debugging.h"
26 #include "generic/constant.h"
27 #include "generic/vector.h"
34 template<typename Element>
40 typedef Element value_type;
41 typedef value_type* iterator;
42 typedef const value_type* const_iterator;
45 : m_size( 0 ), m_data( 0 ){
47 ArrayReference( std::size_t size, Element* data )
48 : m_size( size ), m_data( data ){
54 const_iterator begin() const {
58 return m_data + m_size;
60 const_iterator end() const {
61 return m_data + m_size;
64 value_type& operator[]( std::size_t index ){
66 ASSERT_MESSAGE( index < size(), "array index out of bounds" );
70 const value_type& operator[]( std::size_t index ) const {
72 ASSERT_MESSAGE( index < size(), "array index out of bounds" );
79 const value_type* data() const {
82 std::size_t size() const {
91 template<typename Element>
101 typedef std::bidirectional_iterator_tag iterator_category;
102 typedef std::ptrdiff_t difference_type;
103 typedef difference_type distance_type;
104 typedef KeyValue<Key, Value> value_type;
105 typedef value_type* pointer;
106 typedef value_type& reference;
108 MatrixIterator( Element* position ) : m_position( position ){
115 bool operator==( const MatrixIterator& other ) const {
116 return m_position == other.m_position;
118 bool operator!=( const MatrixIterator& other ) const {
119 return !operator==( other );
121 MatrixIterator& operator++(){
125 MatrixIterator operator++( int ){
126 MatrixIterator tmp = *this;
130 value_type& operator*() const {
131 return m_position->m_value;
133 value_type* operator->() const {
134 return &( operator*() );
139 template<typename Element>
142 std::size_t m_x, m_y;
145 typedef Element value_type;
146 typedef value_type* iterator;
147 typedef const value_type* const_iterator;
150 : m_x( 0 ), m_y( 0 ), m_data( 0 ){
152 Matrix( std::size_t x, std::size_t y, Element* data )
153 : m_x( x ), m_y( y ), m_data( data ){
159 const_iterator begin() const {
163 return m_data + size();
165 const_iterator end() const {
166 return m_data + size();
169 value_type& operator[]( std::size_t index ){
170 #if defined( _DEBUG )
171 ASSERT_MESSAGE( index < size(), "array index out of bounds" );
173 return m_data[index];
175 const value_type& operator[]( std::size_t index ) const {
176 #if defined( _DEBUG )
177 ASSERT_MESSAGE( index < size(), "array index out of bounds" );
179 return m_data[index];
181 value_type& operator()( std::size_t x, std::size_t y ){
182 #if defined( _DEBUG )
183 ASSERT_MESSAGE( x < m_x && y < m_y, "array index out of bounds" );
185 return m_data[x * m_y + y];
187 const value_type& operator()( std::size_t x, std::size_t y ) const {
188 #if defined( _DEBUG )
189 ASSERT_MESSAGE( x < m_x && y < m_y, "array index out of bounds" );
191 return m_data[x * m_y + y];
196 const value_type* data() const {
199 std::size_t x() const {
202 std::size_t y() const {
205 std::size_t size() const {
220 typedef Matrix<PatchControl> PatchControlMatrix;
226 INTEGER_CONSTANT( Version, 1 );
227 STRING_CONSTANT( Name, "patch" );
228 virtual scene::Node& createPatch() = 0;
229 virtual void Patch_undoSave( scene::Node& patch ) const = 0;
230 virtual void Patch_resize( scene::Node& patch, std::size_t width, std::size_t height ) const = 0;
231 virtual PatchControlMatrix Patch_getControlPoints( scene::Node& patch ) const = 0;
232 virtual void Patch_controlPointsChanged( scene::Node& patch ) const = 0;
233 virtual const char* Patch_getShader( scene::Node& patch ) const = 0;
234 virtual void Patch_setShader( scene::Node& patch, const char* shader ) const = 0;
237 #include "modulesystem.h"
239 template<typename Type>
241 typedef ModuleRef<PatchCreator> PatchModuleRef;
243 template<typename Type>
245 typedef GlobalModule<PatchCreator> GlobalPatchModule;
247 template<typename Type>
248 class GlobalModuleRef;
249 typedef GlobalModuleRef<PatchCreator> GlobalPatchModuleRef;
251 inline PatchCreator& GlobalPatchCreator(){
252 return GlobalPatchModule::getTable();