Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit de09743d authored by Boudewijn Rempt's avatar Boudewijn Rempt

Split of the potato brush handling into a separate library: this prepares

the way for making brush formats (abr, svg...) into plugins. Also fix the
text brush, and the memory management of autobrushes.

This is also a required step for making brushes serializable in paintop 
presets: that still needs to be finished, though

svn path=/trunk/koffice/; revision=941076
parent 3ca096e4
include_directories(libpaintop)
include_directories(libbrush libpaintop)
add_subdirectory( libbrush )
add_subdirectory( libpaintop )
add_subdirectory( defaultpaintops )
add_subdirectory( sumie )
......
......@@ -13,3 +13,5 @@ kde4_add_plugin(kritacomplexbrush ${kritacomplexbrush_PART_SRCS})
target_link_libraries(kritacomplexbrush pigmentcms kritalibpaintop)
install(TARGETS kritacomplexbrush DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES kritacomplexbrush.desktop DESTINATION ${SERVICES_INSTALL_DIR})
install( FILES krita-mixing.png DESTINATION ${DATA_INSTALL_DIR}/krita/images)
......@@ -80,7 +80,7 @@ void KisComplexOp::paintAt(const KisPaintInformation& info)
{
if (!painter()->device()) return;
KisBrush* brush = m_brush;
KisBrushSP brush = m_brush;
Q_ASSERT(brush);
if (!brush) return;
......
......@@ -52,7 +52,7 @@ public:
}
virtual QString pixmap() {
return "krita-paintbrush.png";
return "krita-mixing.png";
}
virtual KisPaintOpSettingsSP settings(QWidget * parent, const KoInputDevice& inputDevice, KisImageSP image);
......
......@@ -96,7 +96,7 @@ void KisAirbrushOp::paintAt(const KisPaintInformation& info)
if (!painter()->device()) return;
KisBrush* brush = m_brush;
KisBrushSP brush = m_brush;
Q_ASSERT(brush);
if (!brush) return;
......
......@@ -78,13 +78,12 @@ void KisBrushOp::paintAt(const KisPaintInformation& info)
{
if (!painter()->device()) return;
KisBrush* brush = m_brush;
KisBrushSP brush = m_brush;
Q_ASSERT(brush);
if (!brush) return;
KisPaintInformation adjustedInfo = settings->m_optionsWidget->m_sizeOption->apply(info);
if (! brush->canPaintFor(adjustedInfo))
if (!brush->canPaintFor(adjustedInfo))
return;
KisPaintDeviceSP device = painter()->device();
......@@ -125,7 +124,7 @@ void KisBrushOp::paintAt(const KisPaintInformation& info)
qint32 sh = dstRect.height();
KisPaintDeviceSP dab = KisPaintDeviceSP(0);
if (brush->brushType() == IMAGE || brush->brushType() == PIPE_IMAGE) {
dab = brush->image(device->colorSpace(), scale, 0.0, adjustedInfo, xFraction, yFraction);
} else {
......
......@@ -118,7 +118,7 @@ void KisDuplicateOp::paintAt(const KisPaintInformation& info)
if (!source()) return;
KisBrush* brush = m_brush;
KisBrushSP brush = m_brush;
if (!brush) return;
if (! brush->canPaintFor(info))
return;
......
......@@ -98,7 +98,7 @@ void KisEraseOp::paintAt(const KisPaintInformation& info)
if (!painter()->device()) return;
KisBrush* brush = m_brush;
KisBrushSP brush = m_brush;
Q_ASSERT(brush);
if (!brush) return;
......
......@@ -79,7 +79,7 @@ void KisPenOp::paintAt(const KisPaintInformation& info)
{
if (!painter()->device()) return;
KisBrush* brush = m_brush;
KisBrushSP brush = m_brush;
Q_ASSERT(brush);
if (!brush) return;
......
......@@ -89,7 +89,7 @@ void KisSmudgeOp::paintAt(const KisPaintInformation& info)
{
if (!painter()->device()) return;
KisBrush* brush = m_brush;
KisBrushSP brush = m_brush;
Q_ASSERT(brush);
if (!brush) return;
......
......@@ -28,3 +28,5 @@ install(TARGETS kritadynamicbrushpaintop DESTINATION ${PLUGIN_INSTALL_DIR})
install( FILES kritadynamicbrush.desktop DESTINATION ${SERVICES_INSTALL_DIR})
install( FILES dynamicbrush.rc DESTINATION ${DATA_INSTALL_DIR}/kritaplugins)
install( FILES krita-dynamic.png DESTINATION ${DATA_INSTALL_DIR}/krita/images)
......@@ -54,7 +54,7 @@ public:
}
virtual QString pixmap() {
return "dynamicbrush.png";
return "krita-dynamic.png";
}
virtual KisPaintOpSettingsSP settings(QWidget * parent, const KoInputDevice& inputDevice, KisImageSP image);
......
......@@ -31,6 +31,7 @@
#include "kis_dynamic_shape_program.h"
#include "kis_dynamic_coloring_program.h"
#include "kis_dab_shape.h"
#include "kis_brush.h"
#include "kis_bristle_shape.h"
KisDynamicOpSettings::KisDynamicOpSettings(KisDynamicOpSettingsWidget* widget, KisBookmarkedConfigurationsModel* shapeBookmarksManager, KisBookmarkedConfigurationsModel* coloringBookmarksManager)
......
......@@ -49,8 +49,19 @@ KisAlphaMaskShape::KisAlphaMaskShape() {}
#endif
KisDabShape::~KisDabShape() { }
KisDabShape::KisDabShape(KisBrush* brush) : m_scaleX(1.0), m_scaleY(1.0), m_rotate(0.0), m_dab(0), m_brush(brush) { }
KisDabShape::~KisDabShape()
{
}
KisDabShape::KisDabShape(KisBrushSP brush)
: m_scaleX(1.0)
, m_scaleY(1.0)
, m_rotate(0.0)
, m_dab(0)
, m_brush(brush)
{
}
KisDynamicShape* KisDabShape::clone() const
{
......
......@@ -27,14 +27,14 @@
class KisAutobrushShape;
class KisDynamicColoring;
class KisPaintInformation;
class KisBrush;
#include <kis_brush.h>
#include "kis_dynamic_shape.h"
class DYNAMIC_BRUSH_EXPORT KisDabShape : public KisDynamicShape
{
public:
KisDabShape(KisBrush* brush);
KisDabShape(KisBrushSP brush);
virtual ~KisDabShape();
virtual void paintAt(const QPointF &pos, const KisPaintInformation& info, KisDynamicColoring* coloringsrc);
virtual void resize(double xs, double ys);
......@@ -44,7 +44,7 @@ public:
private:
double m_scaleX, m_scaleY, m_rotate;
KisPaintDeviceSP m_dab;
KisBrush* m_brush;
KisBrushSP m_brush;
};
#endif
......@@ -92,7 +92,7 @@ void KisFilterOp::paintAt(const KisPaintInformation& info)
return;
}
KisBrush* brush = m_brush;;
KisBrushSP brush = m_brush;;
if (!brush) return;
KisPaintInformation adjustedInfo = settings->m_optionsWidget->m_sizeOption->apply(info);
......
......@@ -36,21 +36,9 @@ struct KisAutoBrush::Private {
KisMaskGenerator* shape;
};
QImage KisAutoBrush::createBrushPreview()
{
QImage img((int)(d->shape->width() + 0.5), (int)(d->shape->height() + 0.5), QImage::Format_ARGB32);
double centerX = img.width() * 0.5;
double centerY = img.height() * 0.5;
for (int j = 0; j < d->shape->height(); j++) {
for (int i = 0; i < d->shape->width(); i++) {
qint8 v = d->shape->valueAt(i - centerX, j - centerY);
img.setPixel(i, j, qRgb(v, v, v));
}
}
return img;
}
KisAutoBrush::KisAutoBrush(KisMaskGenerator* as) : KisBrush(""), d(new Private)
KisAutoBrush::KisAutoBrush(KisMaskGenerator* as)
: KisBrush()
, d( new Private )
{
d->shape = as;
QImage img = createBrushPreview();
......@@ -64,7 +52,11 @@ KisAutoBrush::~KisAutoBrush()
delete d;
}
void KisAutoBrush::generateMask(KisPaintDeviceSP dst, KisBrush::ColoringInformation* src, double scaleX, double scaleY, double angle, const KisPaintInformation& info, double subPixelX , double subPixelY) const
void KisAutoBrush::generateMask(KisPaintDeviceSP dst,
KisBrush::ColoringInformation* src,
double scaleX, double scaleY, double angle,
const KisPaintInformation& info,
double subPixelX , double subPixelY) const
{
Q_UNUSED(info);
......@@ -112,3 +104,18 @@ void KisAutoBrush::toXML(QDomDocument& doc, QDomElement& e) const
e.setAttribute("type", "autobrush");
d->shape->toXML(doc, e);
}
QImage KisAutoBrush::createBrushPreview()
{
QImage img((int)(d->shape->width() + 0.5), (int)(d->shape->height() + 0.5), QImage::Format_ARGB32);
double centerX = img.width() * 0.5;
double centerY = img.height() * 0.5;
for (int j = 0; j < d->shape->height(); j++) {
for (int i = 0; i < d->shape->width(); i++) {
qint8 v = d->shape->valueAt(i - centerX, j - centerY);
img.setPixel(i, j, qRgb(v, v, v));
}
}
return img;
}
......@@ -24,21 +24,40 @@
class KisMaskGenerator;
class PAINTOP_EXPORT KisAutoBrush : public KisBrush
/**
* XXX: docs!
*/
class BRUSH_EXPORT KisAutoBrush : public KisBrush
{
public:
KisAutoBrush(KisMaskGenerator* img);
virtual ~KisAutoBrush();
public:
virtual void generateMask(KisPaintDeviceSP dst, KisBrush::ColoringInformation* src, double scaleX, double scaleY, double angle, const KisPaintInformation& info = KisPaintInformation(), double subPixelX = 0, double subPixelY = 0) const;
virtual void generateMask(KisPaintDeviceSP dst,
KisBrush::ColoringInformation* src,
double scaleX, double scaleY, double angle,
const KisPaintInformation& info = KisPaintInformation(),
double subPixelX = 0, double subPixelY = 0) const;
public:
virtual bool load() {
return false;
}
virtual void toXML(QDomDocument& , QDomElement&) const;
private:
QImage createBrushPreview();
private:
struct Private;
Private* const d;
};
......
/*
* Copyright (c) 2008 Boudewijn Rempt <boud@valdyas.org>
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QString>
#include "kis_brush.h"
/**
* A brush factory can create a new brush instance based
* on a properties object that contains a serialized representation
* of the object.
*/
class BRUSH_EXPORT KisBrushFactory
{
public:
KisBrushFactory() {}
virtual ~KisBrushFactory() {}
/**
* Intializes the factory, for instance by loading the relevant resources.
*/
virtual void init() = 0;
/**
* Create a a new brush from the given data or return an existing KisBrush
* object. If this call leads to the creation of a resource, it should be
* added to the resource provider, too.
*/
virtual KisBrushSP createBrush( const QString& brushDefinition ) = 0;
};
/*
* Copyright (c) 2008 Boudewijn Rempt <boud@valdyas.org>
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QString>
#include "kis_brush.h"
/**
* A brush factory can create a new brush instance based
* on a properties object that contains a serialized representation
* of the object.
*/
class BRUSH_EXPORT KisBrushFactory
{
public:
KisBrushFactory() {}
virtual ~KisBrushFactory() {}
/**
* Intializes the factory, for instance by loading the relevant resources.
*/
virtual void init() = 0;
/**
* Create a a new brush from the given data or return an existing KisBrush
* object. If this call leads to the creation of a resource, it should be
* added to the resource provider, too.
*/
virtual KisBrushSP createBrush( const QString& brushDefinition ) = 0;
};
/*
* Copyright (c) 2008 Boudewijn Rempt <boud@valdyas.org>
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_brush_registry.h"
#include <QString>
#include <kaction.h>
#include <klocale.h>
#include <kparts/plugin.h>
#include <kservice.h>
#include <kservicetypetrader.h>
#include <kparts/componentfactory.h>
#include <KoPluginLoader.h>
#include "kis_debug.h"
#include "kis_brush_factory.h"
KisBrushRegistry *KisBrushRegistry::m_singleton = 0;
KisBrushRegistry::KisBrushRegistry()
{
Q_ASSERT(KisBrushRegistry::m_singleton == 0);
KisBrushRegistry::m_singleton = this;
}
KisBrushRegistry::~KisBrushRegistry()
{
}
KisBrushRegistry* KisBrushRegistry::instance()
{
if (KisBrushRegistry::m_singleton == 0) {
KisBrushRegistry::m_singleton = new KisBrushRegistry();
Q_CHECK_PTR( KisBrushRegistry::m_singleton );
KoPluginLoader::instance()->load( "Krita/brush", "Type == 'Service' and ([X-Krita-Version] == 3)" );
}
return KisBrushRegistry::m_singleton;
}
#include "kis_brush_registry.moc"
/*
* Copyright (c) 2008 Boudewijn Rempt <boud@valdyas.org>
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KIS_GENERATOR_REGISTRY_H_
#define KIS_GENERATOR_REGISTRY_H_
#include <QObject>
#include "kis_types.h"
#include "KoGenericRegistry.h"
#include <krita_export.h>
class QString;
class KisBrushFactory;
class BRUSH_EXPORT KisBrushRegistry : public QObject, public KoGenericRegistry<KisBrushFactory*>
{
Q_OBJECT
public:
virtual ~KisBrushRegistry();
static KisBrushRegistry* instance();
private:
KisBrushRegistry();
KisBrushRegistry(const KisBrushRegistry&);
KisBrushRegistry operator=(const KisBrushRegistry&);
private:
static KisBrushRegistry *m_singleton;
};
#endif // KIS_GENERATOR_REGISTRY_H_
......@@ -27,18 +27,20 @@
#include <KoResourceServer.h>
#include <KoResourceServerProvider.h>
#include "kis_brush.h"
#include "kis_gbr_brush.h"
#include "kis_imagepipe_brush.h"
class BrushResourceServer : public KoResourceServer<KisBrush>
class BrushResourceServer : public KoResourceServer<KisGbrBrush>
{
public:
BrushResourceServer() : KoResourceServer<KisBrush>("kis_brushes") {
BrushResourceServer() : KoResourceServer<KisGbrBrush>("kis_brushes") {
}
private:
virtual KisBrush* createResource(const QString & filename) {
virtual KisGbrBrush* createResource(const QString & filename) {
QString fileExtension;
int index = filename.lastIndexOf('.');
......@@ -46,12 +48,14 @@ private:
if (index != -1)
fileExtension = filename.mid(index).toLower();
KisBrush* brush = 0;
KisGbrBrush* brush = 0;
if (fileExtension == ".gbr")
brush = new KisBrush(filename);
else if (fileExtension == ".gih")
if (fileExtension == ".gbr") {
brush = new KisGbrBrush(filename);
}
else if (fileExtension == ".gih") {
brush = new KisImagePipeBrush(filename);
}
return brush;
}
......@@ -84,7 +88,7 @@ KisBrushServer* KisBrushServer::instance()
}
KoResourceServer<KisBrush>* KisBrushServer::brushServer()
KoResourceServer<KisGbrBrush>* KisBrushServer::brushServer()
{
return m_brushServer;
}
......
......@@ -25,7 +25,7 @@
#include <KoResourceServer.h>
class KoResource;
class KisBrush;
class KisGbrBrush;
/**
*
......@@ -38,7 +38,7 @@ class KisBrushServer : public QObject
public:
virtual ~KisBrushServer();
KoResourceServer<KisBrush>* brushServer();
KoResourceServer<KisGbrBrush>* brushServer();
static KisBrushServer* instance();
......@@ -50,7 +50,7 @@ private:
static KisBrushServer *m_singleton;
KoResourceServer<KisBrush>* m_brushServer;
KoResourceServer<KisGbrBrush>* m_brushServer;
private slots:
......
This diff is collapsed.
/*
* Copyright (c) 1999 Matthias Elter <me@kde.org>
* Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
* Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KIS_GBR_BRUSH_
#define KIS_GBR_BRUSH_
#include <QImage>
#include <QVector>
#include "kis_brush.h"
#include "kis_types.h"
#include "kis_shared.h"
#include "kis_paint_information.h"
#include "krita_export.h"
class KisQImagemask;
typedef KisSharedPtr<KisQImagemask> KisQImagemaskSP;
class QString;
class QPoint;
class QIODevice;
class KoColor;
class KoColorSpace;
class KisBoundary;
class BRUSH_EXPORT KisGbrBrush : public KisBrush
{
class ScaledBrush;
Q_OBJECT
protected:
public: