Hauptseite   Klassenhierarchie   Auflistung der Dateien  

filter.cpp

00001 /**********************************************************************************
00002 * Copyright (c) 2003, Christoph Rueegg <opendev@cdrnet.ch> and Matthias Bader     *
00003 * All rights reserved.                                                            *
00004 *                                                                                 *
00005 * Project Website: http://www.cdrnet.net/projects/painter/                        *
00006 *                                                                                 *
00007 * Redistribution and use in source and binary forms, with or without modification,*
00008 * are permitted provided that the following conditions are met:                   *
00009 *                                                                                 *
00010 * 1. Redistributions of source code must retain the above copyright notice,       *
00011 * this list of conditions and the following disclaimer.                           *
00012 *                                                                                 *
00013 * 2. Redistributions in binary form must reproduce the above copyright notice,    *
00014 * this list of conditions and the following disclaimer in the documentation       *
00015 * and/or other materials provided with the distribution.                          *
00016 *                                                                                 *
00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"     *
00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE       *
00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE      *
00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE        *
00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR             *
00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF            *
00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS        *
00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN         *
00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)         *
00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF          *
00027 * THE POSSIBILITY OF SUCH DAMAGE.                                                 *
00028 **********************************************************************************/
00029 
00030 #ifndef __FILTER_GNX__
00031 #define __FILTER_GNX__
00032 
00033 //NOTE: no separated headerfiles = generics workaround (missing support for token 'extern')
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

Erzeugt am Fri Jan 31 15:27:35 2003 für OOP Miniprojekt von doxygen1.3-rc2