krita

kis_random_accessor.h

00001 /*
00002  * This file is part of the Krita project
00003  *
00004  *  Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #ifndef KIS_RANDOM_ACCESSOR_H
00021 #define KIS_RANDOM_ACCESSOR_H
00022 
00023 #include <ksharedptr.h>
00024 
00025 #include <kis_global.h>
00026 
00027 class KisTiledRandomAccessor;
00028 typedef KSharedPtr<KisTiledRandomAccessor> KisTiledRandomAccessorSP;
00029 
00030 class KisTiledDataManager;
00031 
00032 class KisRandomAccessor{
00033     public:
00034         KisRandomAccessor(KisTiledDataManager *ktm, Q_INT32 x, Q_INT32 y, Q_INT32 offsetx, Q_INT32 offsety, bool writable);
00035         KisRandomAccessor(const KisRandomAccessor& rhs);
00036         ~KisRandomAccessor();
00037     public:
00039         void moveTo(Q_INT32 x, Q_INT32 y);
00040         Q_UINT8* rawData() const;
00041         const Q_UINT8* oldRawData() const;
00042     private:
00043         KisTiledRandomAccessorSP m_accessor;
00044         Q_INT32 m_offsetx, m_offsety;
00045 };
00046 
00047 class KisRandomAccessorPixelTrait {
00048     public:
00049         inline KisRandomAccessorPixelTrait(KisRandomAccessor* underlyingAccessor, KisRandomAccessor* selectionAccessor) : m_underlyingAccessor(underlyingAccessor), m_selectionAccessor(selectionAccessor)
00050         {
00051         }
00052     ~KisRandomAccessorPixelTrait() {
00053         if(m_selectionAccessor)
00054             delete m_selectionAccessor;
00055     }
00056         inline bool isSelected() const
00057         {
00058             return (m_selectionAccessor) ? *(m_selectionAccessor->rawData()) > SELECTION_THRESHOLD : true;
00059         };
00060         inline Q_UINT8 operator[](int index) const
00061         { return m_underlyingAccessor->rawData()[index]; };
00065         inline Q_UINT8 selectedness() const
00066         {
00067             return (m_selectionAccessor) ? *(m_selectionAccessor->rawData()) : MAX_SELECTED;
00068         };
00069 
00075         inline Q_UINT8 * selectionMask() const
00076         {
00077             return ( m_selectionAccessor ) ? m_selectionAccessor->rawData() : 0;
00078         }
00079 
00080         inline void moveTo(Q_INT32 x, Q_INT32 y) { if(m_selectionAccessor) m_selectionAccessor->moveTo(x,y); }
00081         
00082     private:
00083         KisRandomAccessor* m_underlyingAccessor;
00084         KisRandomAccessor* m_selectionAccessor;
00085 };
00086 
00087 class KisRandomAccessorPixel : public KisRandomAccessor, public KisRandomAccessorPixelTrait {
00088     public:
00089         KisRandomAccessorPixel(KisTiledDataManager *ktm, KisTiledDataManager *ktmselect, Q_INT32 x, Q_INT32 y, Q_INT32 offsetx, Q_INT32 offsety, bool writable);
00090     public:
00091         inline void moveTo(Q_INT32 x, Q_INT32 y) { KisRandomAccessor::moveTo(x,y); KisRandomAccessorPixelTrait::moveTo(x,y); }
00092 };
00093 
00094 
00095 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys