chalk

kis_selection.h
1/*
2 * Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * this program is free software; you can redistribute it and/or modify
5 * it under the terms of the gnu general public license as published by
6 * the free software foundation; either version 2 of the license, or
7 * (at your option) any later version.
8 *
9 * this program is distributed in the hope that it will be useful,
10 * but without any warranty; without even the implied warranty of
11 * merchantability or fitness for a particular purpose. see the
12 * gnu general public license for more details.
13 *
14 * you should have received a copy of the gnu general public license
15 * along with this program; if not, write to the free software
16 * foundation, inc., 675 mass ave, cambridge, ma 02139, usa.
17 */
18#ifndef KIS_SELECTION_H_
19#define KIS_SELECTION_H_
20
21#include <tqrect.h>
22
23#include "kis_types.h"
24#include "kis_paint_device.h"
25
26#include <koffice_export.h>
27
28
29enum enumSelectionMode {
30 SELECTION_ADD,
31 SELECTION_SUBTRACT
32};
33
43class KRITACORE_EXPORT KisSelection : public KisPaintDevice {
44
45 typedef KisPaintDevice super;
46
47public:
53 KisSelection(KisPaintDeviceSP dev);
54
59
63 KisSelection(const KisSelection& rhs);
64
65 virtual ~KisSelection();
66
67 // Returns selectedness, or 0 if invalid coordinates
68 TQ_UINT8 selected(TQ_INT32 x, TQ_INT32 y);
69
70 void setSelected(TQ_INT32 x, TQ_INT32 y, TQ_UINT8 s);
71
72 TQImage maskImage();
73
74 void select(TQRect r);
75
76 void invert();
77
78 void clear(TQRect r);
79
80 void clear();
81
83 bool isTotallyUnselected(TQRect r);
84
91 bool isProbablyTotallyUnselected(TQRect r);
92
97 TQRect selectedRect() const;
98
103 TQRect selectedExactRect() const;
104
105 void paintSelection(TQImage img, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h);
106 void paintSelection(TQImage img, const TQRect& scaledImageRect, const TQSize& scaledImageSize, const TQSize& imageSize);
107
108 void startCachingExactRect();
109 void stopCachingExactRect();
110
111 // if the parent layer is interested in keeping up to date with the dirtyness
112 // of this layer, set to true
113 void setInterestedInDirtyness(bool b) { m_dirty = b; }
114 bool interestedInDirtyness() const { return m_dirty; }
115
116 virtual void setDirty(const TQRect & rc);
117 virtual void setDirty();
118 inline KisPaintDeviceSP parentPaintDevice() { return m_parentPaintDevice; }
119private:
120 void paintUniformSelectionRegion(TQImage img, const TQRect& imageRect, const TQRegion& uniformRegion);
121
122private:
123
124 // We don't want these methods to be used on selections:
125 void extent(TQ_INT32 &x, TQ_INT32 &y, TQ_INT32 &w, TQ_INT32 &h) const
126 {
127 KisPaintDevice::extent(x,y,w,h);
128 }
129
130 TQRect extent() const { return KisPaintDevice::extent(); }
131
132 void exactBounds(TQ_INT32 &x, TQ_INT32 &y, TQ_INT32 &w, TQ_INT32 &h) const
133 {
134 return KisPaintDevice::exactBounds(x,y,w,h);
135 }
136
137 TQRect exactBounds() const
138 {
140 }
141
142 TQRect exactBoundsOldMethod() const
143 {
144 return KisPaintDevice::exactBoundsOldMethod();
145 }
146
147 TQRect exactBoundsImprovedOldMethod() const
148 {
149 return KisPaintDevice::exactBoundsImprovedOldMethod();
150 }
151
152
153private:
154 KisPaintDeviceSP m_parentPaintDevice;
155 bool m_doCacheExactRect;
156 TQRect m_cachedExactRect;
157 bool m_dirty;
158};
159
160#endif // KIS_SELECTION_H_
KisPaintDevice(KisColorSpace *colorSpace, const char *name=0)
Create a new paint device with the specified colorspace.
virtual void clear()
Complete erase the current paint device.
virtual void setDirty()
Set the parent layer completely dirty, if this paint device has one.
virtual void extent(TQ_INT32 &x, TQ_INT32 &y, TQ_INT32 &w, TQ_INT32 &h) const
Retrieve the bounds of the paint device.
virtual void exactBounds(TQ_INT32 &x, TQ_INT32 &y, TQ_INT32 &w, TQ_INT32 &h) const
Get the exact bounds of this paint device.
TQRect selectedRect() const
Rough, but fastish way of determining the area of the tiles used by the selection.
TQRect selectedExactRect() const
Slow, but exact way of determining the rectangle that encloses the selection.
bool isTotallyUnselected(TQRect r)
Tests if the the rect is totally outside the selection.
KisSelection(KisPaintDeviceSP dev)
Create a new KisSelection.
bool isProbablyTotallyUnselected(TQRect r)
Tests if the the rect is totally outside the selection, but uses selectedRect instead of selectedRect...