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 ){
46 ArrayReference( std::size_t size, Element* data )
47 : m_size( size ), m_data( data ){
53 const_iterator begin() const {
57 return m_data + m_size;
59 const_iterator end() const {
60 return m_data + m_size;
63 value_type& operator[]( std::size_t index ){
65 ASSERT_MESSAGE( index < size(), "array index out of bounds" );
69 const value_type& operator[]( std::size_t index ) const {
71 ASSERT_MESSAGE( index < size(), "array index out of bounds" );
78 const value_type* data() const {
81 std::size_t size() const {
90 template<typename Element>
100 typedef std::bidirectional_iterator_tag iterator_category;
101 typedef std::ptrdiff_t difference_type;
102 typedef difference_type distance_type;
103 typedef KeyValue<Key, Value> value_type;
104 typedef value_type* pointer;
105 typedef value_type& reference;
107 MatrixIterator( Element* position ) : m_position( position ){
114 bool operator==( const MatrixIterator& other ) const {
115 return m_position == other.m_position;
117 bool operator!=( const MatrixIterator& other ) const {
118 return !operator==( other );
120 MatrixIterator& operator++(){
124 MatrixIterator operator++( int ){
125 MatrixIterator tmp = *this;
129 value_type& operator*() const {
130 return m_position->m_value;
132 value_type* operator->() const {
133 return &( operator*() );
138 template<typename Element>
141 std::size_t m_x, m_y;
144 typedef Element value_type;
145 typedef value_type* iterator;
146 typedef const value_type* const_iterator;
149 : m_x( 0 ), m_y( 0 ), m_data( 0 ){
151 Matrix( std::size_t x, std::size_t y, Element* data )
152 : m_x( x ), m_y( y ), m_data( data ){
158 const_iterator begin() const {
162 return m_data + size();
164 const_iterator end() const {
165 return m_data + size();
168 value_type& operator[]( std::size_t index ){
169 #if defined( _DEBUG )
170 ASSERT_MESSAGE( index < size(), "array index out of bounds" );
172 return m_data[index];
174 const value_type& operator[]( std::size_t index ) const {
175 #if defined( _DEBUG )
176 ASSERT_MESSAGE( index < size(), "array index out of bounds" );
178 return m_data[index];
180 value_type& operator()( std::size_t x, std::size_t y ){
181 #if defined( _DEBUG )
182 ASSERT_MESSAGE( x < m_x && y < m_y, "array index out of bounds" );
184 return m_data[x * m_y + y];
186 const value_type& operator()( std::size_t x, std::size_t y ) const {
187 #if defined( _DEBUG )
188 ASSERT_MESSAGE( x < m_x && y < m_y, "array index out of bounds" );
190 return m_data[x * m_y + y];
195 const value_type* data() const {
198 std::size_t x() const {
201 std::size_t y() const {
204 std::size_t size() const {
219 typedef Matrix<PatchControl> PatchControlMatrix;
225 INTEGER_CONSTANT( Version, 1 );
226 STRING_CONSTANT( Name, "patch" );
227 virtual scene::Node& createPatch() = 0;
228 virtual void Patch_undoSave( scene::Node& patch ) const = 0;
229 virtual void Patch_resize( scene::Node& patch, std::size_t width, std::size_t height ) const = 0;
230 virtual PatchControlMatrix Patch_getControlPoints( scene::Node& patch ) const = 0;
231 virtual void Patch_controlPointsChanged( scene::Node& patch ) const = 0;
232 virtual const char* Patch_getShader( scene::Node& patch ) const = 0;
233 virtual void Patch_setShader( scene::Node& patch, const char* shader ) const = 0;
236 #include "modulesystem.h"
238 template<typename Type>
240 typedef ModuleRef<PatchCreator> PatchModuleRef;
242 template<typename Type>
244 typedef GlobalModule<PatchCreator> GlobalPatchModule;
246 template<typename Type>
247 class GlobalModuleRef;
248 typedef GlobalModuleRef<PatchCreator> GlobalPatchModuleRef;
250 inline PatchCreator& GlobalPatchCreator(){
251 return GlobalPatchModule::getTable();