1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
/*
* Copyright (c) 2005 Casper Boemann <[email protected]>
*
* 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; either version 2 of the license, or
* (at your option) any later version.
*
* 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., 675 mass ave, cambridge, ma 02139, usa.
*/
#ifndef KIS_PAINT_LAYER_H_
#define KIS_PAINT_LAYER_H_
#include "kis_types.h"
#include "kis_layer.h"
#include "kis_paint_device.h"
#include "kis_colorspace.h"
/**
* This layer is of a type that can be painted on.
*/
class KisPaintLayer : public KisLayer, public KisLayerSupportsIndirectPainting {
typedef KisLayer super;
Q_OBJECT
public:
KisPaintLayer(KisImage *img, const TQString& name, TQ_UINT8 opacity, KisPaintDeviceSP dev);
KisPaintLayer(KisImage *img, const TQString& name, TQ_UINT8 opacity);
KisPaintLayer(KisImage *img, const TQString& name, TQ_UINT8 opacity, KisColorSpace * colorSpace);
KisPaintLayer(const KisPaintLayer& rhs);
virtual ~KisPaintLayer();
virtual KisLayerSP clone() const;
public:
// Called when the layer is made active
virtual void activate() {}
// Called when another layer is made active
virtual void deactivate() {}
virtual TQ_INT32 x() const;
virtual void setX(TQ_INT32 x);
virtual TQ_INT32 y() const;
virtual void setY(TQ_INT32 y);
virtual TQRect extent() const;
virtual TQRect exactBounds() const;
virtual void paintSelection(TQImage &img, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h);
virtual void paintSelection(TQImage &img, const TQRect& scaledImageRect, const TQSize& scaledImageSize, const TQSize& imageSize);
virtual void paintMaskInactiveLayers(TQImage &img, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h);
virtual TQImage createThumbnail(TQ_INT32 w, TQ_INT32 h);
virtual bool accept(KisLayerVisitor &v)
{
// kdDebug(41001) << "\tPAINT\t" << name()
// << " dirty: " << dirty() << "\n";
return v.visit(this);
}
inline KisPaintDeviceSP paintDevice() const { return m_paintdev; }
/// Returns the paintDevice that accompanies this layer (or mask, see editMask)
inline KisPaintDeviceSP paintDeviceOrMask() const {
if (hasMask() && editMask())
return m_mask;
return m_paintdev;
}
// Mask Layer
/// Does this layer have a layer mask?
bool hasMask() const { return m_mask != 0; }
// XXX TODO: Make these undo-able!
/// Create a mask if it does not yet exist, and return it
KisPaintDeviceSP createMask();
/// Convert the from argument to the mask
void createMaskFromPaintDevice(KisPaintDeviceSP from);
/**
* Convert the from selection to a paint device (should convert the getMaskAsSelection
* result back to the mask). Overwrites the current mask, if any. Also removes the selection
*/
void createMaskFromSelection(KisSelectionSP from);
/// Remove the layer mask
void removeMask();
/// Apply the layer mask to the paint device, this removes the mask afterwards
void applyMask();
/// Returns the layer mask's device. Creates one if there is currently none
KisPaintDeviceSP getMask();
/// Returns the layer mask's device, converted to a selection. Creates one if there is currently none
KisSelectionSP getMaskAsSelection();
/// Undoable version of createMask
KNamedCommand* createMaskCommand();
/// Undoable version of createMaskFromSelection
KNamedCommand* maskFromSelectionCommand();
/// Undoable, removes the current mask, but converts it to the current selection
KNamedCommand* maskToSelectionCommand();
/// Undoable version of removeMask
KNamedCommand* removeMaskCommand();
/// Undoable version of applyMask
KNamedCommand* applyMaskCommand();
/// Returns true if the masked part of the mask will be rendered instead of being transparent
bool renderMask() const { return m_renderMask; }
/// Set the renderMask property
void setRenderMask(bool b);
/**
* When this returns true, the KisPaintDevice returned in paintDevice will actually
* be the layer mask (if there is one). This is so that tools can draw on the mask
* without needing to know its existance.
*/
bool editMask() const { return m_editMask; }
/// Sets the editMask property
void setEditMask(bool b);
/// Overridden to call the private convertMaskToSelection
virtual void setDirty(bool propagate = true);
/// Same as above
virtual void setDirty(const TQRect & rect, bool propagate = true);
// KisLayerSupportsIndirectPainting
virtual KisLayer* layer() { return this; }
signals:
/// When the mask is created/destroyed or the editmask or rendermask is changed
void sigMaskInfoChanged();
private:
void convertMaskToSelection(const TQRect& r);
void genericMaskCreationHelper();
KisPaintDeviceSP m_paintdev;
// Layer mask related:
// XXX It would be nice to merge the next 2 devices...
KisPaintDeviceSP m_mask; // The mask that we can edit and display easily
KisSelectionSP m_maskAsSelection; // The mask as selection, to apply and render easily
bool m_renderMask;
bool m_editMask;
};
typedef TDESharedPtr<KisPaintLayer> KisPaintLayerSP;
#endif // KIS_PAINT_LAYER_H_
|