Hauptseite   Klassenhierarchie   Auflistung der Dateien  

filterstatefulltrans.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 #include "filterstatefulltrans.h"
00031 #include <cmath>
00032 
00033 StatefullTransformationFilter::StatefullTransformationFilter() : ChannelFilter<unsigned char>()
00034 {
00035   src = 0;
00036   active = false;
00037   x0 = y0 = 0;
00038 }
00039 
00040 StatefullTransformationFilter::~StatefullTransformationFilter()
00041 {
00042   delete src;
00043 }
00044 
00045 void StatefullTransformationFilter::OnMouseEvent(const int button, const int state, int x, int y)
00046 {
00047   if(button!=0)
00048   {
00049     return;
00050   }
00051   ChannelFilter<unsigned char>::Normalize(&x,&y);
00052   if(state == 0 && button == 0) //start
00053   {
00054     x0 = x;
00055     y0 = y;
00056     trg = ChannelFilter<unsigned char>::GetSubChannel();
00057     src = new Channel<unsigned char>(ChannelFilter<unsigned char>::GetHeight(),ChannelFilter<unsigned char>::GetWidth());
00058     for(int x1=0;x1<trg->GetWidth();x1++)
00059       for(int y1=0;y1<trg->GetHeight();y1++)
00060         src->Set(x1,y1,trg->Get(x1,y1));
00061     OnStart(src,trg,x0,y0);
00062     active = true;
00063   }
00064   if(state == 1 && button == 0) //end
00065   {
00066     active = false;
00067     OnEnd(src,trg,x0,y0,x,y);
00068     for(int x1=0;x1<trg->GetWidth();x1++)
00069       for(int y1=0;y1<trg->GetHeight();y1++)
00070         trg->Set(x1,y1,src->Get(x1,y1));
00071     delete src;
00072     src = 0;
00073   }
00074 }
00075 
00076 void StatefullTransformationFilter::OnMotionEvent(int x, int y)
00077 {
00078   if(active)
00079   {
00080     ChannelFilter<unsigned char>::Normalize(&x,&y);
00081     OnRender(src,trg,x0,y0,x,y);
00082     x0 = x;
00083     y0 = y;
00084   }   
00085 }
00086 
00087 bool StatefullTransformationFilter::OnIdleEvent()
00088 {
00089   if(active)
00090     return(OnRender(src,trg,x0,y0,x0,y0));
00091   else
00092     return(false);
00093 }
00094 
00095 void StatefullTransformationFilter::ResetChannel()
00096 {
00097   if(active)
00098   {
00099     active = false;
00100     for(int x1=0;x1<trg->GetWidth();x1++)
00101       for(int y1=0;y1<trg->GetHeight();y1++)
00102         trg->Set(x1,y1,src->Get(x1,y1));
00103     delete src;
00104     src = 0;
00105   }
00106 }
00107 
00108 inline unsigned char StatefullTransformationFilter::Get(const int x, const int y)
00109 {
00110   if(active && src != 0)
00111     return(src->Get(x,y));
00112   else
00113     return(ChannelFilter<unsigned char>::Get(x,y));
00114 }
00115 
00116 inline void StatefullTransformationFilter::Set(const int x, const int y, const unsigned char val)
00117 {
00118   if(active && src != 0)
00119     src->Set(x,y,val);
00120   else
00121     ChannelFilter<unsigned char>::Set(x,y,val);;
00122 }
00123 

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