chalk

kis_paint_layer.h
1/*
2 * Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>
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_PAINT_LAYER_H_
19#define KIS_PAINT_LAYER_H_
20
21#include "kis_types.h"
22#include "kis_layer.h"
23#include "kis_paint_device.h"
24#include "kis_colorspace.h"
28class KisPaintLayer : public KisLayer, public KisLayerSupportsIndirectPainting {
29 typedef KisLayer super;
30
31 TQ_OBJECT
32
33
34public:
35 KisPaintLayer(KisImage *img, const TQString& name, TQ_UINT8 opacity, KisPaintDeviceSP dev);
36 KisPaintLayer(KisImage *img, const TQString& name, TQ_UINT8 opacity);
37 KisPaintLayer(KisImage *img, const TQString& name, TQ_UINT8 opacity, KisColorSpace * colorSpace);
38 KisPaintLayer(const KisPaintLayer& rhs);
39 virtual ~KisPaintLayer();
40
41 virtual KisLayerSP clone() const;
42public:
43
44 // Called when the layer is made active
45 virtual void activate() {}
46
47 // Called when another layer is made active
48 virtual void deactivate() {}
49
50 virtual TQ_INT32 x() const;
51 virtual void setX(TQ_INT32 x);
52
53 virtual TQ_INT32 y() const;
54 virtual void setY(TQ_INT32 y);
55
56 virtual TQRect extent() const;
57 virtual TQRect exactBounds() const;
58
59 virtual void paintSelection(TQImage &img, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h);
60 virtual void paintSelection(TQImage &img, const TQRect& scaledImageRect, const TQSize& scaledImageSize, const TQSize& imageSize);
61
62 virtual void paintMaskInactiveLayers(TQImage &img, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h);
63
64 virtual TQImage createThumbnail(TQ_INT32 w, TQ_INT32 h);
65
66 virtual bool accept(KisLayerVisitor &v)
67 {
68// kdDebug(41001) << "\tPAINT\t" << name()
69// << " dirty: " << dirty() << "\n";
70 return v.visit(this);
71 }
72
73
74 inline KisPaintDeviceSP paintDevice() const { return m_paintdev; }
75
77 inline KisPaintDeviceSP paintDeviceOrMask() const {
78 if (hasMask() && editMask())
79 return m_mask;
80 return m_paintdev;
81 }
82
83 // Mask Layer
84
86 bool hasMask() const { return m_mask != 0; }
87 // XXX TODO: Make these undo-able!
89 KisPaintDeviceSP createMask();
91 void createMaskFromPaintDevice(KisPaintDeviceSP from);
96 void createMaskFromSelection(KisSelectionSP from);
98 void removeMask();
100 void applyMask();
102 KisPaintDeviceSP getMask();
104 KisSelectionSP getMaskAsSelection();
105
107 KNamedCommand* createMaskCommand();
109 KNamedCommand* maskFromSelectionCommand();
111 KNamedCommand* maskToSelectionCommand();
113 KNamedCommand* removeMaskCommand();
115 KNamedCommand* applyMaskCommand();
116
118 bool renderMask() const { return m_renderMask; }
120 void setRenderMask(bool b);
121
127 bool editMask() const { return m_editMask; }
129 void setEditMask(bool b);
130
132 virtual void setDirty(bool propagate = true);
134 virtual void setDirty(const TQRect & rect, bool propagate = true);
135
136 // KisLayerSupportsIndirectPainting
137 virtual KisLayer* layer() { return this; }
138signals:
141
142private:
143 void convertMaskToSelection(const TQRect& r);
144 void genericMaskCreationHelper();
145 KisPaintDeviceSP m_paintdev;
146 // Layer mask related:
147 // XXX It would be nice to merge the next 2 devices...
148 KisPaintDeviceSP m_mask; // The mask that we can edit and display easily
149 KisSelectionSP m_maskAsSelection; // The mask as selection, to apply and render easily
150 bool m_renderMask;
151 bool m_editMask;
152};
153
154typedef TDESharedPtr<KisPaintLayer> KisPaintLayerSP;
155
156#endif // KIS_PAINT_LAYER_H_
157
A colorspace is the definition of a certain color model in Chalk.
Abstract class that represents the concept of a Layer in Chalk.
Definition kis_layer.h:42
virtual TQRect extent() const
Returns an approximation of where the bounds on actual data are in this layer.
KisPaintDeviceSP createMask()
Create a mask if it does not yet exist, and return it.
virtual bool accept(KisLayerVisitor &v)
Accept the KisLayerVisitor (for the Visitor design pattern), should call the correct function on the ...
virtual KisLayerSP clone() const
Return a copy of this layer.
KisPaintDeviceSP getMask()
Returns the layer mask's device. Creates one if there is currently none.
void setEditMask(bool b)
Sets the editMask property.
virtual void setDirty(bool propagate=true)
Overridden to call the private convertMaskToSelection.
KNamedCommand * createMaskCommand()
Undoable version of createMask.
void createMaskFromPaintDevice(KisPaintDeviceSP from)
Convert the from argument to the mask.
bool editMask() const
When this returns true, the KisPaintDevice returned in paintDevice will actually be the layer mask (i...
void setRenderMask(bool b)
Set the renderMask property.
void sigMaskInfoChanged()
When the mask is created/destroyed or the editmask or rendermask is changed.
virtual void paintMaskInactiveLayers(TQImage &img, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h)
paints where no data is on this layer. Useful when it is a transparent layer stacked on top of anothe...
virtual TQImage createThumbnail(TQ_INT32 w, TQ_INT32 h)
Returns a thumbnail in requested size.
KNamedCommand * applyMaskCommand()
Undoable version of applyMask.
KNamedCommand * maskFromSelectionCommand()
Undoable version of createMaskFromSelection.
KisSelectionSP getMaskAsSelection()
Returns the layer mask's device, converted to a selection. Creates one if there is currently none.
void removeMask()
Remove the layer mask.
KNamedCommand * removeMaskCommand()
Undoable version of removeMask.
bool renderMask() const
Returns true if the masked part of the mask will be rendered instead of being transparent.
virtual void paintSelection(TQImage &img, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h)
paints a mask where the selection on this layer resides
void applyMask()
Apply the layer mask to the paint device, this removes the mask afterwards.
virtual void activate()
Called when the layer is made active.
void createMaskFromSelection(KisSelectionSP from)
Convert the from selection to a paint device (should convert the getMaskAsSelection result back to th...
virtual TQRect exactBounds() const
Returns the exact bounds of where the actual data resides in this layer.
bool hasMask() const
Does this layer have a layer mask?
KisPaintDeviceSP paintDeviceOrMask() const
Returns the paintDevice that accompanies this layer (or mask, see editMask).
virtual void deactivate()
Called when another layer is made active.
KNamedCommand * maskToSelectionCommand()
Undoable, removes the current mask, but converts it to the current selection.