diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-06-26 00:41:16 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-06-26 00:41:16 +0000 |
commit | 698569f8428ca088f764d704034a1330517b98c0 (patch) | |
tree | bf45be6946ebbbee9cce5a5bcf838f4c952d87e6 /chalk/core/kis_random_accessor.h | |
parent | 2785103a6bd4de55bd26d79e34d0fdd4b329a73a (diff) | |
download | koffice-698569f8428ca088f764d704034a1330517b98c0.tar.gz koffice-698569f8428ca088f764d704034a1330517b98c0.zip |
Finish rebranding of Krita as Chalk
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1238363 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'chalk/core/kis_random_accessor.h')
-rw-r--r-- | chalk/core/kis_random_accessor.h | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/chalk/core/kis_random_accessor.h b/chalk/core/kis_random_accessor.h new file mode 100644 index 00000000..6e2e10ad --- /dev/null +++ b/chalk/core/kis_random_accessor.h @@ -0,0 +1,95 @@ +/* + * This file is part of the Chalk project + * + * Copyright (c) 2006 Cyrille Berger <cberger@cberger.net> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef KIS_RANDOM_ACCESSOR_H +#define KIS_RANDOM_ACCESSOR_H + +#include <ksharedptr.h> + +#include <kis_global.h> + +class KisTiledRandomAccessor; +typedef KSharedPtr<KisTiledRandomAccessor> KisTiledRandomAccessorSP; + +class KisTiledDataManager; + +class KisRandomAccessor{ + public: + KisRandomAccessor(KisTiledDataManager *ktm, TQ_INT32 x, TQ_INT32 y, TQ_INT32 offsetx, TQ_INT32 offsety, bool writable); + KisRandomAccessor(const KisRandomAccessor& rhs); + ~KisRandomAccessor(); + public: + /// Move to a given x,y position, fetch tiles and data + void moveTo(TQ_INT32 x, TQ_INT32 y); + TQ_UINT8* rawData() const; + const TQ_UINT8* oldRawData() const; + private: + KisTiledRandomAccessorSP m_accessor; + TQ_INT32 m_offsetx, m_offsety; +}; + +class KisRandomAccessorPixelTrait { + public: + inline KisRandomAccessorPixelTrait(KisRandomAccessor* underlyingAccessor, KisRandomAccessor* selectionAccessor) : m_underlyingAccessor(underlyingAccessor), m_selectionAccessor(selectionAccessor) + { + } + ~KisRandomAccessorPixelTrait() { + if(m_selectionAccessor) + delete m_selectionAccessor; + } + inline bool isSelected() const + { + return (m_selectionAccessor) ? *(m_selectionAccessor->rawData()) > SELECTION_THRESHOLD : true; + }; + inline TQ_UINT8 operator[](int index) const + { return m_underlyingAccessor->rawData()[index]; }; + /** + * Returns the degree of selectedness of the pixel. + */ + inline TQ_UINT8 selectedness() const + { + return (m_selectionAccessor) ? *(m_selectionAccessor->rawData()) : MAX_SELECTED; + }; + + /** + * Returns the selectiontqmask from the current point; this is guaranteed + * to have the same number of consecutive pixels that the iterator has + * at a given point. It return a 0 if there is no selection. + */ + inline TQ_UINT8 * selectionMask() const + { + return ( m_selectionAccessor ) ? m_selectionAccessor->rawData() : 0; + } + + inline void moveTo(TQ_INT32 x, TQ_INT32 y) { if(m_selectionAccessor) m_selectionAccessor->moveTo(x,y); } + + private: + KisRandomAccessor* m_underlyingAccessor; + KisRandomAccessor* m_selectionAccessor; +}; + +class KisRandomAccessorPixel : public KisRandomAccessor, public KisRandomAccessorPixelTrait { + public: + KisRandomAccessorPixel(KisTiledDataManager *ktm, KisTiledDataManager *ktmselect, TQ_INT32 x, TQ_INT32 y, TQ_INT32 offsetx, TQ_INT32 offsety, bool writable); + public: + inline void moveTo(TQ_INT32 x, TQ_INT32 y) { KisRandomAccessor::moveTo(x,y); KisRandomAccessorPixelTrait::moveTo(x,y); } +}; + + +#endif |