diff options
Diffstat (limited to 'chalk/core/kis_paint_layer.h')
| -rw-r--r-- | chalk/core/kis_paint_layer.h | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/chalk/core/kis_paint_layer.h b/chalk/core/kis_paint_layer.h new file mode 100644 index 000000000..9e598e7aa --- /dev/null +++ b/chalk/core/kis_paint_layer.h @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2005 Casper Boemann <cbr@boemann.dk> + * + * 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 + TQ_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 tqmask, see editMask) + inline KisPaintDeviceSP paintDeviceOrMask() const { + if (hasMask() && editMask()) + return m_tqmask; + return m_paintdev; + } + + // Mask Layer + + /// Does this layer have a layer tqmask? + bool hasMask() const { return m_tqmask != 0; } + // XXX TODO: Make these undo-able! + /// Create a tqmask if it does not yet exist, and return it + KisPaintDeviceSP createMask(); + /// Convert the from argument to the tqmask + void createMaskFromPaintDevice(KisPaintDeviceSP from); + /** + * Convert the from selection to a paint device (should convert the getMaskAsSelection + * result back to the tqmask). Overwrites the current tqmask, if any. Also removes the selection + */ + void createMaskFromSelection(KisSelectionSP from); + /// Remove the layer tqmask + void removeMask(); + /// Apply the layer tqmask to the paint device, this removes the tqmask afterwards + void applyMask(); + /// Returns the layer tqmask's device. Creates one if there is currently none + KisPaintDeviceSP getMask(); + /// Returns the layer tqmask'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* tqmaskFromSelectionCommand(); + /// Undoable, removes the current tqmask, but converts it to the current selection + KNamedCommand* tqmaskToSelectionCommand(); + /// Undoable version of removeMask + KNamedCommand* removeMaskCommand(); + /// Undoable version of applyMask + KNamedCommand* applyMaskCommand(); + + /// Returns true if the tqmasked part of the tqmask 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 tqmask (if there is one). This is so that tools can draw on the tqmask + * 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 tqmask is created/destroyed or the edittqmask or rendertqmask is changed + void sigMaskInfoChanged(); + +private: + void convertMaskToSelection(const TQRect& r); + void genericMaskCreationHelper(); + KisPaintDeviceSP m_paintdev; + // Layer tqmask related: + // XXX It would be nice to merge the next 2 devices... + KisPaintDeviceSP m_tqmask; // The tqmask that we can edit and display easily + KisSelectionSP m_tqmaskAsSelection; // The tqmask as selection, to apply and render easily + bool m_renderMask; + bool m_editMask; +}; + +typedef KSharedPtr<KisPaintLayer> KisPaintLayerSP; + +#endif // KIS_PAINT_LAYER_H_ + |
