Hauptseite   Klassenhierarchie   Auflistung der Dateien  

container.cpp

00001 /**********************************************************************************
00002 * Copyright (c) 2003, Christoph Rueegg <opendev@cdrnet.ch> and Matthias Bader     *
00003 * Partially based on ideas of Tim Weyrich <weyrich@inf.ethz.ch>                   *
00004 * and/or the Swiss Federal Institute of Technology http://www.ethz.ch             *
00005 * All rights reserved.                                                            *
00006 *                                                                                 *
00007 * Project Website: http://www.cdrnet.net/projects/painter/                        *
00008 *                                                                                 *
00009 * Redistribution and use in source and binary forms, with or without modification,*
00010 * are permitted provided that the following conditions are met:                   *
00011 *                                                                                 *
00012 * 1. Redistributions of source code must retain the above copyright notice,       *
00013 * this list of conditions and the following disclaimer.                           *
00014 *                                                                                 *
00015 * 2. Redistributions in binary form must reproduce the above copyright notice,    *
00016 * this list of conditions and the following disclaimer in the documentation       *
00017 * and/or other materials provided with the distribution.                          *
00018 *                                                                                 *
00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"     *
00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE       *
00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE      *
00022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE        *
00023 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR             *
00024 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF            *
00025 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS        *
00026 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN         *
00027 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)         *
00028 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF          *
00029 * THE POSSIBILITY OF SUCH DAMAGE.                                                 *
00030 **********************************************************************************/
00031 
00032 #include "container.h"
00033 
00034 AlphaImage* Container::currentimage = 0;
00035 RgbImage* Container::currentrgbimage = 0;
00036 ChannelFilter<unsigned char>* Container::currentfilter = 0;
00037 ChannelFilter<unsigned char>* Container::currentredfilter = 0;
00038 ChannelFilter<unsigned char>* Container::currentgreenfilter = 0;
00039 ChannelFilter<unsigned char>* Container::currentbluefilter = 0;
00040 double Container::currentzoom = 1.0;
00041 int Container::windowid = -1;
00042 int Container::channelmode = 15;
00043 
00044 void Container::StartMainLoop()
00045 {
00046   glutMainLoop();
00047 }
00048 
00049 void Container::SetImage(AlphaImage *image)
00050 {
00051   Container::DeleteImage();
00052   Container::currentimage = image;
00053   Container::currentrgbimage = 0;
00054   Container::Redisplay();
00055 }
00056 
00057 void Container::SetImage(RgbImage *image)
00058 {
00059   Container::DeleteImage();
00060   Container::currentimage = image;
00061   Container::currentrgbimage = image;
00062   Container::Redisplay();
00063 }
00064 
00065 AlphaImage* Container::GetImage()
00066 {
00067   return(Container::currentimage);
00068 }
00069 
00070 void Container::DeleteImage()
00071 {
00072   Container::DeleteFilter();
00073   delete Container::currentimage;
00074   Container::currentimage = 0;
00075   Container::currentrgbimage = 0;
00076 }
00077 
00078 void Container::SetFilter(ChannelFilter<unsigned char> *filter)
00079 {
00080   Container::DeleteFilter();
00081   if(Container::currentimage != 0 && Container::currentrgbimage == 0)
00082   {
00083     Container::currentfilter = filter;
00084     Container::currentimage->AttachLuminanceFilter(filter);
00085   }
00086   if(Container::currentimage != 0 && Container::currentrgbimage != 0)
00087   {
00088     Container::currentredfilter = filter;
00089     Container::currentrgbimage->AttachRedFilter(filter);
00090     ChannelFilter<unsigned char>* filter2 = filter->EmptyClone();
00091     ChannelFilter<unsigned char>* filter3 = filter->EmptyClone();
00092     Container::currentgreenfilter = filter2;
00093     Container::currentbluefilter = filter3;
00094     Container::currentrgbimage->AttachGreenFilter(filter2);
00095     Container::currentrgbimage->AttachBlueFilter(filter3);
00096   }
00097   Container::Redisplay();
00098 }
00099 
00100 void Container::DeleteFilter()
00101 {
00102   if(Container::currentfilter!=0)
00103   {
00104     Container::currentfilter->ResetChannel();
00105     if(Container::currentimage!=0)
00106     {
00107       Container::currentimage->RemoveLuminanceFilters();
00108     }
00109     delete Container::currentfilter;
00110     Container::currentfilter = 0;
00111   }
00112   if(Container::currentredfilter!=0)
00113   {
00114     Container::currentredfilter->ResetChannel();
00115     if(Container::currentrgbimage!=0)
00116     {
00117       Container::currentrgbimage->RemoveRedFilters();
00118     }
00119     delete Container::currentredfilter;
00120     Container::currentredfilter = 0;
00121   }
00122   if(Container::currentgreenfilter!=0)
00123   {
00124     Container::currentgreenfilter->ResetChannel();
00125     if(Container::currentrgbimage!=0)
00126     {
00127       Container::currentrgbimage->RemoveGreenFilters();
00128     }
00129     delete Container::currentgreenfilter;
00130     Container::currentgreenfilter = 0;
00131   }
00132   if(Container::currentbluefilter!=0)
00133   {
00134     Container::currentbluefilter->ResetChannel();
00135     if(Container::currentrgbimage!=0)
00136     {
00137       Container::currentrgbimage->RemoveBlueFilters();
00138     }
00139     delete Container::currentbluefilter;
00140     Container::currentbluefilter = 0;
00141   }
00142 }
00143 
00144 void Container::Redisplay()
00145 {
00146   glutPostRedisplay();
00147 }
00148 
00149 void Container::SpecialKeyboardCallback(int key, int x, int y)
00150 {
00151   switch(key)
00152   {
00153     case GLUT_KEY_F1:
00154       Container::channelmode = 15;
00155       break;
00156     case GLUT_KEY_F2:
00157       Container::channelmode ^= 2;
00158       break;
00159     case GLUT_KEY_F3:
00160       Container::channelmode ^= 4;
00161       break;
00162     case GLUT_KEY_F4:
00163       Container::channelmode ^= 8;
00164       break;
00165   }
00166 }
00167 
00168 void Container::MouseClickCallback(int button, int state, int x, int y)
00169 {
00170   if(Container::currentfilter!=0 && Container::currentrgbimage == 0)
00171   {
00172     Container::currentfilter->OnMouseEvent(button, state, (int)(x/currentzoom), (int)(y/currentzoom));
00173   }
00174   if(Container::currentredfilter!=0 && (Container::channelmode&2)!=0)
00175   {
00176     Container::currentredfilter->OnMouseEvent(button, state, (int)(x/currentzoom), (int)(y/currentzoom));
00177   }
00178   if(Container::currentgreenfilter!=0 && (Container::channelmode&4)!=0)
00179   {
00180     Container::currentgreenfilter->OnMouseEvent(button, state, (int)(x/currentzoom), (int)(y/currentzoom));
00181   }
00182   if(Container::currentbluefilter!=0 && (Container::channelmode&8)!=0)
00183   {
00184     Container::currentbluefilter->OnMouseEvent(button, state, (int)(x/currentzoom), (int)(y/currentzoom));
00185   }
00186   Container::Redisplay();
00187 }
00188 
00189 void Container::MouseMotionCallback(int x, int y)
00190 {
00191   if(Container::currentfilter!=0 && Container::currentrgbimage == 0)
00192   {
00193     Container::currentfilter->OnMotionEvent((int)(x/currentzoom), (int)(y/currentzoom));
00194   }
00195   if(Container::currentredfilter!=0 && (Container::channelmode&2)!=0)
00196   {
00197     Container::currentredfilter->OnMotionEvent((int)(x/currentzoom), (int)(y/currentzoom));
00198   }
00199   if(Container::currentgreenfilter!=0 && (Container::channelmode&4)!=0)
00200   {
00201     Container::currentgreenfilter->OnMotionEvent((int)(x/currentzoom), (int)(y/currentzoom));
00202   }
00203   if(Container::currentbluefilter!=0 && (Container::channelmode&8)!=0)
00204   {
00205     Container::currentbluefilter->OnMotionEvent((int)(x/currentzoom), (int)(y/currentzoom));
00206   }
00207   Container::Redisplay();
00208 }
00209 
00210 void Container::IdleCallback()
00211 {
00212   bool redraw = false;
00213   if(Container::currentfilter!=0 && Container::currentrgbimage == 0)
00214   {
00215     redraw |= Container::currentfilter->OnIdleEvent();
00216   }
00217   if(Container::currentredfilter!=0 && (Container::channelmode&2)!=0)
00218   {
00219     redraw |= Container::currentredfilter->OnIdleEvent();
00220   }
00221   if(Container::currentgreenfilter!=0 && (Container::channelmode&4)!=0)
00222   {
00223     redraw |= Container::currentgreenfilter->OnIdleEvent();
00224   }
00225   if(Container::currentbluefilter!=0 && (Container::channelmode&8)!=0)
00226   {
00227     redraw |= Container::currentbluefilter->OnIdleEvent();
00228   }
00229   if(redraw)
00230     Container::Redisplay();
00231 }
00232 
00233 void Container::DrawCallback()
00234 {
00235   if(Container::currentimage!=0)
00236   {
00237     Container::currentzoom = Container::currentimage->Draw();
00238   }
00239   else
00240   {
00241     glClear(GL_COLOR_BUFFER_BIT);
00242     glutSwapBuffers();
00243   }
00244 }
00245 
00246 void Container::Init()
00247 {
00248   int fake_argc = 1;
00249   char  *fake_argv[] = {"painter"};
00250   glutInit(&fake_argc, fake_argv);
00251 
00252   /* Get double-buffered rgb display without depth-buffer. */
00253   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
00254 
00255   /* Open Window */
00256   glutInitWindowSize(640, 640);
00257   windowid = glutCreateWindow("Paint Application");
00258 
00259   /* Register Callbacks. */
00260   glutDisplayFunc(Container::DrawCallback);
00261   glutKeyboardFunc(Container::KeyboardCallback);
00262   glutSpecialFunc(Container::SpecialKeyboardCallback);
00263   glutMouseFunc(Container::MouseClickCallback);
00264   glutMotionFunc(Container::MouseMotionCallback);
00265   glutIdleFunc(Container::IdleCallback);
00266 }
00267 
00268 void Container::Dispose()
00269 {
00270   Container::DeleteImage();
00271 }

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