krita
kis_iteratorpixeltrait.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KIS_ITERATORPIXELTRAIT_H_
00021 #define KIS_ITERATORPIXELTRAIT_H_
00022
00023 #include "kis_iterator.h"
00024 #include <kis_paint_device.h>
00025
00026 template< typename _iTp>
00027 class KisIteratorPixelTrait
00028 {
00029 public:
00030 KisIteratorPixelTrait(KisPaintDevice * ndevice, _iTp *underlyingIterator)
00031 : m_device(ndevice),
00032 m_underlyingIterator(underlyingIterator)
00033 {
00034 m_selectionIterator = NULL;
00035 };
00036
00037 ~KisIteratorPixelTrait()
00038 {
00039 delete m_selectionIterator;
00040 };
00041
00042 KisIteratorPixelTrait(const KisIteratorPixelTrait& rhs)
00043 {
00044 if (this == &rhs)
00045 return;
00046 m_device = rhs.m_device;
00047 m_underlyingIterator = rhs.m_underlyingIterator;
00048
00049 if (rhs.m_selectionIterator) {
00050 m_selectionIterator = new _iTp(*rhs.m_selectionIterator);
00051 } else {
00052 m_selectionIterator = 0;
00053 }
00054 }
00055
00056 KisIteratorPixelTrait& operator=(const KisIteratorPixelTrait& rhs)
00057 {
00058 if (this == &rhs)
00059 return *this;
00060 m_device = rhs.m_device;
00061 m_underlyingIterator = rhs.m_underlyingIterator;
00062
00063 delete m_selectionIterator;
00064 if (rhs.m_selectionIterator) {
00065 m_selectionIterator = new _iTp(*rhs.m_selectionIterator);
00066 } else {
00067 m_selectionIterator = 0;
00068 }
00069
00070 return *this;
00071 }
00072
00073
00074 public:
00079 inline Q_UINT8 operator[](int index) const
00080 { return m_underlyingIterator->rawData()[index]; };
00081
00085 inline bool isSelected() const
00086 {
00087 if (m_selectionIterator)
00088 return *(m_selectionIterator->rawData()) > SELECTION_THRESHOLD;
00089 else
00090 return true;
00091 };
00092
00096 inline Q_UINT8 selectedness() const
00097 {
00098 if (m_selectionIterator)
00099 return *(m_selectionIterator->rawData());
00100 else {
00101 return MAX_SELECTED;
00102 }
00103 };
00104
00110 inline Q_UINT8 * selectionMask() const
00111 {
00112 if ( m_selectionIterator )
00113 return m_selectionIterator->rawData();
00114 else
00115 return 0;
00116 }
00117
00118
00119 protected:
00120 KisPaintDevice *m_device;
00121
00122 inline void advance(int n){if (m_selectionIterator) for(int i=0; i< n; i++) ++(*m_selectionIterator);};
00123 inline void retreat(){if (m_selectionIterator) --(*m_selectionIterator);};
00124
00125 void setSelectionIterator(_iTp *si){m_selectionIterator = si;};
00126
00127 _iTp *m_underlyingIterator;
00128 _iTp *m_selectionIterator;
00129 };
00130
00131 #endif
|