chalk

kis_iteratorpixeltrait.h
1/* This file is part of the KDE project
2 * Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>, the original iteratorpixel
3 * Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>, made it into a trait
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KIS_ITERATORPIXELTRAIT_H_
21#define KIS_ITERATORPIXELTRAIT_H_
22
23#include "kis_iterator.h"
24#include <kis_paint_device.h>
25
26template< typename _iTp>
27class KisIteratorPixelTrait
28{
29public:
30 KisIteratorPixelTrait(KisPaintDevice * ndevice, _iTp *underlyingIterator)
31 : m_device(ndevice),
32 m_underlyingIterator(underlyingIterator)
33 {
34 m_selectionIterator = NULL;
35 };
36
37 ~KisIteratorPixelTrait()
38 {
39 delete m_selectionIterator;
40 };
41
42 KisIteratorPixelTrait(const KisIteratorPixelTrait& rhs)
43 {
44 if (this == &rhs)
45 return;
46 m_device = rhs.m_device;
47 m_underlyingIterator = rhs.m_underlyingIterator;
48
49 if (rhs.m_selectionIterator) {
50 m_selectionIterator = new _iTp(*rhs.m_selectionIterator);
51 } else {
52 m_selectionIterator = 0;
53 }
54 }
55
56 KisIteratorPixelTrait& operator=(const KisIteratorPixelTrait& rhs)
57 {
58 if (this == &rhs)
59 return *this;
60 m_device = rhs.m_device;
61 m_underlyingIterator = rhs.m_underlyingIterator;
62
63 delete m_selectionIterator;
64 if (rhs.m_selectionIterator) {
65 m_selectionIterator = new _iTp(*rhs.m_selectionIterator);
66 } else {
67 m_selectionIterator = 0;
68 }
69
70 return *this;
71 }
72
73
74public:
79 inline TQ_UINT8 operator[](int index) const
80 { return m_underlyingIterator->rawData()[index]; };
81
85 inline bool isSelected() const
86 {
87 if (m_selectionIterator)
88 return *(m_selectionIterator->rawData()) > SELECTION_THRESHOLD;
89 else
90 return true;
91 };
92
96 inline TQ_UINT8 selectedness() const
97 {
98 if (m_selectionIterator)
99 return *(m_selectionIterator->rawData());
100 else {
101 return MAX_SELECTED;
102 }
103 };
104
110 inline TQ_UINT8 * selectionMask() const
111 {
112 if ( m_selectionIterator )
113 return m_selectionIterator->rawData();
114 else
115 return 0;
116 }
117
118
119protected:
120 KisPaintDevice *m_device;
121
122 inline void advance(int n){if (m_selectionIterator) for(int i=0; i< n; i++) ++(*m_selectionIterator);};
123 inline void retreat(){if (m_selectionIterator) --(*m_selectionIterator);};
124
125 void setSelectionIterator(_iTp *si){m_selectionIterator = si;};
126
127 _iTp *m_underlyingIterator;
128 _iTp *m_selectionIterator;
129};
130
131#endif