chalk

kis_random_accessor.h
1/*
2 * This file is part of the Chalk project
3 *
4 * Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
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_RANDOM_ACCESSOR_H
21#define KIS_RANDOM_ACCESSOR_H
22
23#include <ksharedptr.h>
24
25#include <kis_global.h>
26
27class KisTiledRandomAccessor;
28typedef TDESharedPtr<KisTiledRandomAccessor> KisTiledRandomAccessorSP;
29
30class KisTiledDataManager;
31
32class KisRandomAccessor{
33 public:
34 KisRandomAccessor(KisTiledDataManager *ktm, TQ_INT32 x, TQ_INT32 y, TQ_INT32 offsetx, TQ_INT32 offsety, bool writable);
35 KisRandomAccessor(const KisRandomAccessor& rhs);
36 ~KisRandomAccessor();
37 public:
39 void moveTo(TQ_INT32 x, TQ_INT32 y);
40 TQ_UINT8* rawData() const;
41 const TQ_UINT8* oldRawData() const;
42 private:
43 KisTiledRandomAccessorSP m_accessor;
44 TQ_INT32 m_offsetx, m_offsety;
45};
46
47class KisRandomAccessorPixelTrait {
48 public:
49 inline KisRandomAccessorPixelTrait(KisRandomAccessor* underlyingAccessor, KisRandomAccessor* selectionAccessor) : m_underlyingAccessor(underlyingAccessor), m_selectionAccessor(selectionAccessor)
50 {
51 }
52 ~KisRandomAccessorPixelTrait() {
53 if(m_selectionAccessor)
54 delete m_selectionAccessor;
55 }
56 inline bool isSelected() const
57 {
58 return (m_selectionAccessor) ? *(m_selectionAccessor->rawData()) > SELECTION_THRESHOLD : true;
59 };
60 inline TQ_UINT8 operator[](int index) const
61 { return m_underlyingAccessor->rawData()[index]; };
65 inline TQ_UINT8 selectedness() const
66 {
67 return (m_selectionAccessor) ? *(m_selectionAccessor->rawData()) : MAX_SELECTED;
68 };
69
75 inline TQ_UINT8 * selectionMask() const
76 {
77 return ( m_selectionAccessor ) ? m_selectionAccessor->rawData() : 0;
78 }
79
80 inline void moveTo(TQ_INT32 x, TQ_INT32 y) { if(m_selectionAccessor) m_selectionAccessor->moveTo(x,y); }
81
82 private:
83 KisRandomAccessor* m_underlyingAccessor;
84 KisRandomAccessor* m_selectionAccessor;
85};
86
87class KisRandomAccessorPixel : public KisRandomAccessor, public KisRandomAccessorPixelTrait {
88 public:
89 KisRandomAccessorPixel(KisTiledDataManager *ktm, KisTiledDataManager *ktmselect, TQ_INT32 x, TQ_INT32 y, TQ_INT32 offsetx, TQ_INT32 offsety, bool writable);
90 public:
91 inline void moveTo(TQ_INT32 x, TQ_INT32 y) { KisRandomAccessor::moveTo(x,y); KisRandomAccessorPixelTrait::moveTo(x,y); }
92};
93
94
95#endif