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 "globaldefs.h"
26 #include "debugging/debugging.h"
27 #include "generic/constant.h"
28 #include "generic/vector.h"
35 template<typename Element>
41 typedef Element value_type;
42 typedef value_type* iterator;
43 typedef const value_type* const_iterator;
46 : m_size( 0 ), m_data( 0 ){
48 ArrayReference( std::size_t size, Element* data )
49 : m_size( size ), m_data( data ){
55 const_iterator begin() const {
59 return m_data + m_size;
61 const_iterator end() const {
62 return m_data + m_size;
65 value_type& operator[]( std::size_t index ){
67 ASSERT_MESSAGE( index < size(), "array index out of bounds" );
71 const value_type& operator[]( std::size_t index ) const {
73 ASSERT_MESSAGE( index < size(), "array index out of bounds" );
80 const value_type* data() const {
83 std::size_t size() const {
92 template<typename Element>
102 typedef std::bidirectional_iterator_tag iterator_category;
103 typedef std::ptrdiff_t difference_type;
104 typedef difference_type distance_type;
105 typedef KeyValue<Key, Value> value_type;
106 typedef value_type* pointer;
107 typedef value_type& reference;
109 MatrixIterator( Element* position ) : m_position( position ){
116 bool operator==( const MatrixIterator& other ) const {
117 return m_position == other.m_position;
119 bool operator!=( const MatrixIterator& other ) const {
120 return !operator==( other );
122 MatrixIterator& operator++(){
126 MatrixIterator operator++( int ){
127 MatrixIterator tmp = *this;
131 value_type& operator*() const {
132 return m_position->m_value;
134 value_type* operator->() const {
135 return &( operator*() );
140 template<typename Element>
143 std::size_t m_x, m_y;
146 typedef Element value_type;
147 typedef value_type* iterator;
148 typedef const value_type* const_iterator;
151 : m_x( 0 ), m_y( 0 ), m_data( 0 ){
153 Matrix( std::size_t x, std::size_t y, Element* data )
154 : m_x( x ), m_y( y ), m_data( data ){
160 const_iterator begin() const {
164 return m_data + size();
166 const_iterator end() const {
167 return m_data + size();
170 value_type& operator[]( std::size_t index ){
172 ASSERT_MESSAGE( index < size(), "array index out of bounds" );
174 return m_data[index];
176 const value_type& operator[]( std::size_t index ) const {
178 ASSERT_MESSAGE( index < size(), "array index out of bounds" );
180 return m_data[index];
182 value_type& operator()( std::size_t x, std::size_t y ){
184 ASSERT_MESSAGE( x < m_x && y < m_y, "array index out of bounds" );
186 return m_data[x * m_y + y];
188 const value_type& operator()( std::size_t x, std::size_t y ) const {
190 ASSERT_MESSAGE( x < m_x && y < m_y, "array index out of bounds" );
192 return m_data[x * m_y + y];
197 const value_type* data() const {
200 std::size_t x() const {
203 std::size_t y() const {
206 std::size_t size() const {
221 typedef Matrix<PatchControl> PatchControlMatrix;
227 INTEGER_CONSTANT( Version, 1 );
228 STRING_CONSTANT( Name, "patch" );
229 virtual scene::Node& createPatch() = 0;
230 virtual void Patch_undoSave( scene::Node& patch ) const = 0;
231 virtual void Patch_resize( scene::Node& patch, std::size_t width, std::size_t height ) const = 0;
232 virtual PatchControlMatrix Patch_getControlPoints( scene::Node& patch ) const = 0;
233 virtual void Patch_controlPointsChanged( scene::Node& patch ) const = 0;
234 virtual const char* Patch_getShader( scene::Node& patch ) const = 0;
235 virtual void Patch_setShader( scene::Node& patch, const char* shader ) const = 0;
238 #include "modulesystem.h"
240 template<typename Type>
242 typedef ModuleRef<PatchCreator> PatchModuleRef;
244 template<typename Type>
246 typedef GlobalModule<PatchCreator> GlobalPatchModule;
248 template<typename Type>
249 class GlobalModuleRef;
250 typedef GlobalModuleRef<PatchCreator> GlobalPatchModuleRef;
252 inline PatchCreator& GlobalPatchCreator(){
253 return GlobalPatchModule::getTable();