00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef __FILTER_GNX__
00031 #define __FILTER_GNX__
00032
00033
00034
00035 #include "channel.cpp"
00036
00037 template<class T>
00038 class ChannelFilter: public Channel<T>
00039 {
00040 private:
00041 Channel<T>* channel;
00042 public:
00043 ChannelFilter();
00044 virtual ~ChannelFilter();
00045 virtual int GetId();
00046
00047
00048
00049 virtual void SetId(const int id);
00050 virtual void SetSubChannel(Channel<T>* channel);
00051 virtual Channel<T>* GetSubChannel();
00052 virtual ChannelFilter<T>* EmptyClone() = 0;
00053 inline T Get(const int x, const int y);
00054 inline void Set(const int x, const int y, const T val) ;
00055 virtual void OnMouseEvent(const int button, const int state, int x, int y);
00056 virtual void OnMotionEvent(int x, int y);
00057 virtual bool OnIdleEvent();
00058 void Normalize(int* x, int* y);
00059 void Normalize(int* topleftx, int* toplefty, int* bottomrightx, int* bottomrighty);
00060 inline int GetWidth();
00061 inline int GetHeight();
00062
00063 };
00064
00065 template<class T>
00066 ChannelFilter<T>::ChannelFilter() : Channel<T>()
00067 {
00068 channel = 0;
00069 }
00070
00071 template<class T>
00072 ChannelFilter<T>::~ChannelFilter()
00073 {
00074 }
00075
00076 template<class T>
00077 void ChannelFilter<T>::SetId(const int id)
00078 {
00079 if(channel != 0)
00080 channel->SetId(id);
00081 }
00082
00083 template<class T>
00084 int ChannelFilter<T>::GetId()
00085 {
00086 if(channel != 0)
00087 return(channel->GetId());
00088 else
00089 return(0);
00090
00091 }
00092
00093 template<class T>
00094 void ChannelFilter<T>::SetSubChannel(Channel<T>* channel)
00095 {
00096 this->channel = channel;
00097 }
00098
00099 template<class T>
00100 Channel<T>* ChannelFilter<T>::GetSubChannel()
00101 {
00102 return(this->channel);
00103 }
00104
00105 template<class T>
00106 inline T ChannelFilter<T>::Get(const int x, const int y)
00107 {
00108 if(channel != 0)
00109 return(channel->Get(x,y));
00110 else
00111 return 0;
00112 }
00113
00114 template<class T>
00115 inline void ChannelFilter<T>::Set(const int x, const int y, const T val)
00116 {
00117 if(channel != 0)
00118 channel->Set(x,y,val);
00119 }
00120
00121 template<class T>
00122 void ChannelFilter<T>::OnMouseEvent(const int button, const int state, int x, int y)
00123 {
00124 }
00125
00126 template<class T>
00127 void ChannelFilter<T>::OnMotionEvent(int x, int y)
00128 {
00129 }
00130
00131 template<class T>
00132 bool ChannelFilter<T>::OnIdleEvent()
00133 {
00134 return(false);
00135 }
00136
00137 template<class T>
00138 void ChannelFilter<T>::Normalize(int* x, int* y)
00139 {
00140 if(*x<0)
00141 *x = 0;
00142 if(*y<0)
00143 *y = 0;
00144 if(*x >= channel->GetWidth())
00145 *x = channel->GetWidth();
00146 if(*y >= channel->GetHeight())
00147 *y = channel->GetHeight();
00148 }
00149
00150 template<class T>
00151 void ChannelFilter<T>::Normalize(int* topleftx, int* toplefty, int* bottomrightx, int* bottomrighty)
00152 {
00153 int temp;
00154 Normalize(topleftx,toplefty);
00155 Normalize(bottomrightx,bottomrighty);
00156 if(*topleftx > *bottomrightx)
00157 {
00158 temp = *topleftx;
00159 *topleftx = *bottomrightx;
00160 *bottomrightx = temp;
00161 }
00162 if(*toplefty > *bottomrighty)
00163 {
00164 temp = *toplefty;
00165 *toplefty = *bottomrighty;
00166 *bottomrighty = temp;
00167 }
00168 }
00169
00170 template<class T>
00171 inline int ChannelFilter<T>::GetWidth()
00172 {
00173 return(channel->GetWidth());
00174 }
00175
00176 template<class T>
00177 inline int ChannelFilter<T>::GetHeight()
00178 {
00179 return(channel->GetHeight());
00180 }
00181
00182 #endif