Hauptseite   Klassenhierarchie   Auflistung der Dateien  

filterdotselect.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 "filterdotselect.h"
00031 
00032 ChannelSelectDotFilter::ChannelSelectDotFilter(bool withbar) : ChannelFilter<unsigned char>()
00033 {
00034   displayBar = false;
00035   this->withbar = withbar;
00036   selectedcolor = 100;
00037   selectedx = selectedy = 0;
00038   bartlx = bartly = 2;
00039   barbrx = barbry = 4;
00040   bar = new Channel<unsigned char>(barbry-bartly,barbrx-bartly);
00041 }
00042 
00043 ChannelSelectDotFilter::~ChannelSelectDotFilter()
00044 {
00045   delete bar;
00046 }
00047 
00048 void ChannelSelectDotFilter::SetSubChannel(Channel<unsigned char>* channel)
00049 {
00050   ChannelFilter<unsigned char>::SetSubChannel(channel);
00051   bartlx = 2;
00052   barbrx = channel->GetWidth()-2;
00053   barbry = (int)(float(channel->GetHeight())/12.0)+4;
00054   bartly = 2;
00055   delete bar;
00056   bar = new Channel<unsigned char>(barbry-bartly,barbrx-bartly);
00057 }
00058 
00059 ChannelFilter<unsigned char>* ChannelSelectDotFilter::EmptyClone()
00060 {
00061   ChannelSelectDotFilter *copy = new ChannelSelectDotFilter(this->withbar);
00062   copy->SetSubChannel(ChannelFilter<unsigned char>::GetSubChannel());
00063   return(copy);
00064 }
00065 
00066 void ChannelSelectDotFilter::OnMouseEvent(const int button, const int state, int x, int y)
00067 {
00068   if(button == 2 && state == 0 && withbar)
00069   {
00070     displayBar = true;
00071     for(int xi=bartlx;xi<barbrx;xi++)
00072     for(int yi=bartly;yi<barbry;yi++)
00073     {
00074       bar->Set(xi-bartlx,yi-bartly,ChannelFilter<unsigned char>::Get(xi,yi));
00075       ChannelFilter<unsigned char>::Set(xi,yi,(int)((255.0*xi)/(barbrx-bartlx)));
00076     }
00077   }
00078   if(button == 2 && state != 0)
00079   {;
00080     ChannelFilter<unsigned char>::Normalize(&x,&y);
00081     selectedx = x;
00082     selectedy = y;
00083     selectedcolor = ChannelFilter<unsigned char>::Get(x,y);
00084     if(withbar)
00085     {
00086       for(int xi=bartlx;xi<barbrx;xi++)
00087         for(int yi=bartly;yi<barbry;yi++)
00088         {
00089           ChannelFilter<unsigned char>::Set(xi,yi,bar->Get(xi-bartlx,yi-bartly));
00090         }
00091       displayBar = false;
00092     }
00093   }
00094 }
00095 
00096 unsigned char ChannelSelectDotFilter::Get(const int x, const int y)
00097 {;
00098   if(displayBar && x>=bartlx && x<barbrx && y>=bartly && y<barbry)
00099     return(bar->Get(x,y));
00100   else
00101     return(ChannelFilter<unsigned char>::Get(x,y));
00102 }
00103 
00104 void ChannelSelectDotFilter::Set(const int x, const int y, const unsigned char val)
00105 {
00106   if(displayBar && x>=bartlx && x<barbrx && y>=bartly && y<barbry)
00107     bar->Set(x,y,val);
00108   else
00109     ChannelFilter<unsigned char>::Set(x,y,val);
00110 }
00111 
00112 void ChannelSelectDotFilter::ResetChannel()
00113 {
00114   if(displayBar && bar != 0)
00115   {
00116     for(int xi=bartlx;xi<barbrx;xi++)
00117       for(int yi=bartly;yi<barbry;yi++)
00118       {
00119         ChannelFilter<unsigned char>::Set(xi,yi,bar->Get(xi-bartlx,yi-bartly));
00120       }
00121   }
00122   ChannelFilter<unsigned char>::ResetChannel();
00123 }
00124 
00125 unsigned char ChannelSelectDotFilter::GetSelectedColor()
00126 {
00127   return(selectedcolor);
00128 }
00129 
00130 int ChannelSelectDotFilter::GetSelectedX()
00131 {
00132   return(selectedx);
00133 }
00134 
00135 int ChannelSelectDotFilter::GetSelectedY()
00136 {
00137   return(selectedy);
00138 }

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