diff --git a/plugins/paintops/hatching/CMakeLists.txt b/plugins/paintops/hatching/CMakeLists.txt index 417a3375a7..66aec6ddaa 100644 --- a/plugins/paintops/hatching/CMakeLists.txt +++ b/plugins/paintops/hatching/CMakeLists.txt @@ -1,22 +1,23 @@ set(kritahatchingpaintop_SOURCES hatching_paintop_plugin.cpp kis_hatching_paintop.cpp kis_hatching_options.cpp kis_hatching_preferences.cpp kis_hatching_paintop_settings.cpp kis_hatching_paintop_settings_widget.cpp + kis_hatching_pressure_angle_option.cpp kis_hatching_pressure_crosshatching_option.cpp kis_hatching_pressure_separation_option.cpp kis_hatching_pressure_thickness_option.cpp hatching_brush.cpp ) ki18n_wrap_ui(kritahatchingpaintop_SOURCES wdghatchingpreferences.ui wdghatchingoptions.ui) add_library(kritahatchingpaintop MODULE ${kritahatchingpaintop_SOURCES}) target_link_libraries(kritahatchingpaintop kritalibpaintop) install(TARGETS kritahatchingpaintop DESTINATION ${KRITA_PLUGIN_INSTALL_DIR}) install( FILES krita-hatching.png DESTINATION ${DATA_INSTALL_DIR}/krita/images) diff --git a/plugins/paintops/hatching/kis_hatching_paintop.cpp b/plugins/paintops/hatching/kis_hatching_paintop.cpp index 8d95873b32..96df6a45f9 100644 --- a/plugins/paintops/hatching/kis_hatching_paintop.cpp +++ b/plugins/paintops/hatching/kis_hatching_paintop.cpp @@ -1,210 +1,214 @@ /* * Copyright (c) 2008,2009 Lukáš Tvrdý * Copyright (c) 2010 José Luis Vergara * * 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_hatching_paintop.h" #include "kis_hatching_paintop_settings.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include KisHatchingPaintOp::KisHatchingPaintOp(const KisPaintOpSettingsSP settings, KisPainter * painter, KisNodeSP node, KisImageSP image) : KisBrushBasedPaintOp(settings, painter) , m_image(image) { Q_UNUSED(node); m_settings = new KisHatchingPaintOpSettings(); static_cast(settings.data())->initializeTwin(m_settings); m_hatchingBrush = new HatchingBrush(m_settings); + m_angleOption.readOptionSetting(settings); m_crosshatchingOption.readOptionSetting(settings); m_separationOption.readOptionSetting(settings); m_thicknessOption.readOptionSetting(settings); m_opacityOption.readOptionSetting(settings); m_sizeOption.readOptionSetting(settings); + m_angleOption.resetAllSensors(); m_crosshatchingOption.resetAllSensors(); m_separationOption.resetAllSensors(); m_thicknessOption.resetAllSensors(); m_opacityOption.resetAllSensors(); m_sizeOption.resetAllSensors(); } KisHatchingPaintOp::~KisHatchingPaintOp() { delete m_hatchingBrush; } KisSpacingInformation KisHatchingPaintOp::paintAt(const KisPaintInformation& info) { //------START SIMPLE ERROR CATCHING------- if (!painter()->device()) return KisSpacingInformation(1.0); if (!m_hatchedDab) m_hatchedDab = source()->createCompositionSourceDevice(); else m_hatchedDab->clear(); //Simple convenience renaming, I'm thinking of removing these inherited quirks KisBrushSP brush = m_brush; KisPaintDeviceSP device = painter()->device(); //Macro to catch errors Q_ASSERT(brush); //----------SIMPLE error catching code, maybe it's not even needed------ if (!brush) return KisSpacingInformation(1.0); if (!brush->canPaintFor(info)) return KisSpacingInformation(1.0); //SENSOR-depending settings + m_settings->anglesensorvalue = m_angleOption.apply(info); m_settings->crosshatchingsensorvalue = m_crosshatchingOption.apply(info); m_settings->separationsensorvalue = m_separationOption.apply(info); m_settings->thicknesssensorvalue = m_thicknessOption.apply(info); const qreal additionalScale = KisLodTransform::lodToScale(painter()->device()); const double scale = additionalScale * m_sizeOption.apply(info); if ((scale * brush->width()) <= 0.01 || (scale * brush->height()) <= 0.01) return KisSpacingInformation(1.0); KisDabShape shape(scale, 1.0, 0.0); quint8 origOpacity = m_opacityOption.apply(painter(), info); /*----Fetch the Dab----*/ static const KoColorSpace *cs = KoColorSpaceRegistry::instance()->alpha8(); static KoColor color(Qt::black, cs); QRect dstRect; KisFixedPaintDeviceSP maskDab = m_dabCache->fetchDab(cs, color, info.pos(), shape, info, 1.0, &dstRect); // sanity check KIS_ASSERT_RECOVER_NOOP(dstRect.size() == maskDab->bounds().size()); /*-----Convenient renaming for the limits of the maskDab, this will be used to hatch a dab of just the right size------*/ qint32 x, y, sw, sh; dstRect.getRect(&x, &y, &sw, &sh); //------This If_block pre-fills the future m_hatchedDab with a pretty backgroundColor if (m_settings->opaquebackground) { KoColor aersh = painter()->backgroundColor(); m_hatchedDab->fill(0, 0, (sw - 1), (sh - 1), aersh.data()); //this plus yellow background = french fry brush } - // Trick for moire pattern to look better - bool donotbasehatch = false; - /* If block describing how to stack hatching passes to generate crosshatching according to user specifications */ if (m_settings->enabledcurvecrosshatching) { if (m_settings->perpendicular) { if (m_settings->crosshatchingsensorvalue > 0.5) m_hatchingBrush->hatch(m_hatchedDab, x, y, sw, sh, spinAngle(90), painter()->paintColor(), additionalScale); } else if (m_settings->minusthenplus) { if (m_settings->crosshatchingsensorvalue > 0.33) m_hatchingBrush->hatch(m_hatchedDab, x, y, sw, sh, spinAngle(-45), painter()->paintColor(), additionalScale); if (m_settings->crosshatchingsensorvalue > 0.67) m_hatchingBrush->hatch(m_hatchedDab, x, y, sw, sh, spinAngle(45), painter()->paintColor(), additionalScale); } else if (m_settings->plusthenminus) { if (m_settings->crosshatchingsensorvalue > 0.33) m_hatchingBrush->hatch(m_hatchedDab, x, y, sw, sh, spinAngle(45), painter()->paintColor(), additionalScale); if (m_settings->crosshatchingsensorvalue > 0.67) m_hatchingBrush->hatch(m_hatchedDab, x, y, sw, sh, spinAngle(-45), painter()->paintColor(), additionalScale); } else if (m_settings->moirepattern) { - m_hatchingBrush->hatch(m_hatchedDab, x, y, sw, sh, spinAngle((m_settings->crosshatchingsensorvalue) * 180), painter()->paintColor(), additionalScale); - donotbasehatch = true; + m_hatchingBrush->hatch(m_hatchedDab, x, y, sw, sh, spinAngle((m_settings->crosshatchingsensorvalue) * 360), painter()->paintColor(), additionalScale); } } else { if (m_settings->perpendicular) { m_hatchingBrush->hatch(m_hatchedDab, x, y, sw, sh, spinAngle(90), painter()->paintColor(), additionalScale); } else if (m_settings->minusthenplus) { m_hatchingBrush->hatch(m_hatchedDab, x, y, sw, sh, spinAngle(-45), painter()->paintColor(), additionalScale); m_hatchingBrush->hatch(m_hatchedDab, x, y, sw, sh, spinAngle(45), painter()->paintColor(), additionalScale); } else if (m_settings->plusthenminus) { m_hatchingBrush->hatch(m_hatchedDab, x, y, sw, sh, spinAngle(45), painter()->paintColor(), additionalScale); m_hatchingBrush->hatch(m_hatchedDab, x, y, sw, sh, spinAngle(-45), painter()->paintColor(), additionalScale); } else if (m_settings->moirepattern) { m_hatchingBrush->hatch(m_hatchedDab, x, y, sw, sh, spinAngle(-10), painter()->paintColor(), additionalScale); } } - if (!donotbasehatch) + if (m_settings->enabledcurveangle) + m_hatchingBrush->hatch(m_hatchedDab, x, y, sw, sh, spinAngle((m_settings->anglesensorvalue)*360+m_settings->angle), painter()->paintColor(), additionalScale); + + // The base hatch... unless moiré or angle + if (!m_settings->moirepattern && !m_settings->enabledcurveangle) m_hatchingBrush->hatch(m_hatchedDab, x, y, sw, sh, m_settings->angle, painter()->paintColor(), additionalScale); + // The most important line, the one that paints to the screen. painter()->bitBltWithFixedSelection(x, y, m_hatchedDab, maskDab, sw, sh); painter()->renderMirrorMaskSafe(QRect(QPoint(x, y), QSize(sw, sh)), m_hatchedDab, 0, 0, maskDab, !m_dabCache->needSeparateOriginal()); painter()->setOpacity(origOpacity); return effectiveSpacing(scale); } KisSpacingInformation KisHatchingPaintOp::updateSpacingImpl(const KisPaintInformation &info) const { const qreal scale = KisLodTransform::lodToScale(painter()->device()) * m_sizeOption.apply(info); return effectiveSpacing(scale); } double KisHatchingPaintOp::spinAngle(double spin) { double tempangle = m_settings->angle + spin; qint8 factor = 1; if (tempangle < 0) factor = -1; tempangle = fabs(fmod(tempangle, 180)); if ((tempangle >= 0) && (tempangle <= 90)) return factor * tempangle; else if ((tempangle > 90) && (tempangle <= 180)) return factor * -(180 - tempangle); return 0; // this should never be executed except if NAN } diff --git a/plugins/paintops/hatching/kis_hatching_paintop.h b/plugins/paintops/hatching/kis_hatching_paintop.h index 4a513116b5..ef5fd28016 100644 --- a/plugins/paintops/hatching/kis_hatching_paintop.h +++ b/plugins/paintops/hatching/kis_hatching_paintop.h @@ -1,107 +1,114 @@ /* * Copyright (c) 2008 Boudewijn Rempt * Copyright (c) 2008, 2009 Lukáš Tvrdý * Copyright (c) 2010 José Luis Vergara Toloza * * 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_HATCHING_PAINTOP_H_ #define KIS_HATCHING_PAINTOP_H_ #include #include #include #include "hatching_brush.h" #include "kis_hatching_paintop_settings.h" +#include #include #include #include #include #include class KisPainter; class KisHatchingPaintOp : public KisBrushBasedPaintOp { public: KisHatchingPaintOp(const KisPaintOpSettingsSP settings, KisPainter * painter, KisNodeSP node, KisImageSP image); ~KisHatchingPaintOp() override; /** * Returns a number between -90 and 90, and corresponds to the * angle that results from adding angle 'spin' to 'm_settings->angle', * corrected to coincide with the way the GUI operates. */ double spinAngle(double spin); protected: /** * Paint a hatched dab around the mouse cursor according to * sensor settings and user preferences. */ KisSpacingInformation paintAt(const KisPaintInformation& info) override; KisSpacingInformation updateSpacingImpl(const KisPaintInformation &info) const override; private: KisHatchingPaintOpSettingsSP m_settings; KisImageWSP m_image; HatchingBrush *m_hatchingBrush; /** * PaintDevice that will be filled with a single pass of * hatching by HatchingBrush::hatch */ KisPaintDeviceSP m_hatchedDab; + /** + * Curve to control the hatching angle + * according to user preferences set in the GUI + */ + KisHatchingPressureAngleOption m_angleOption; + /** * Curve to control the intensity of crosshatching * according to user preferences set in the GUI */ KisHatchingPressureCrosshatchingOption m_crosshatchingOption; /** * Curve to control the dynamics of separation with * device input */ KisHatchingPressureSeparationOption m_separationOption; /** * Curve to control the thickness of the hatching lines * with device input */ KisHatchingPressureThicknessOption m_thicknessOption; /** * Curve to control the opacity of the entire dab * with device input */ KisPressureOpacityOption m_opacityOption; /** * Curve to control the size of the entire dab * with device input */ KisPressureSizeOption m_sizeOption; }; #endif // KIS_HATCHING_PAINTOP_H_ diff --git a/plugins/paintops/hatching/kis_hatching_paintop_settings.cpp b/plugins/paintops/hatching/kis_hatching_paintop_settings.cpp index 95081b8325..362ae1acb9 100644 --- a/plugins/paintops/hatching/kis_hatching_paintop_settings.cpp +++ b/plugins/paintops/hatching/kis_hatching_paintop_settings.cpp @@ -1,219 +1,220 @@ /* * Copyright (c) 2010 Lukáš Tvrdý * Copyright (c) 2010 José Luis Vergara * * 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_hatching_paintop_settings.h" #include #include #include const QString HATCHING_VERSION = "Hatching/Version"; struct KisHatchingPaintOpSettings::Private { QList uniformProperties; }; KisHatchingPaintOpSettings::KisHatchingPaintOpSettings() : m_d(new Private) { setProperty(HATCHING_VERSION, "2"); } KisHatchingPaintOpSettings::~KisHatchingPaintOpSettings() { } void KisHatchingPaintOpSettings::initializeTwin(KisPaintOpSettingsSP settings) const { // XXX: this is a nice way to reinvent the copy constructor? /*--------DO NOT REMOVE please, use this to review the XML config tree QMap rofl = QMap(getProperties()); QMap::const_iterator i; for (i = rofl.constBegin(); i != rofl.constEnd(); ++i) dbgKrita << i.key() << ":" << i.value(); /----------DO NOT REMOVE----------------*/ KisHatchingPaintOpSettings *convenienttwin = static_cast(settings.data()); + convenienttwin->enabledcurveangle = getBool("PressureAngle"); convenienttwin->enabledcurvecrosshatching = getBool("PressureCrosshatching"); convenienttwin->enabledcurveopacity = getBool("PressureOpacity"); convenienttwin->enabledcurveseparation = getBool("PressureSeparation"); convenienttwin->enabledcurvesize = getBool("PressureSize"); convenienttwin->enabledcurvethickness = getBool("PressureThickness"); convenienttwin->angle = getDouble("Hatching/angle"); convenienttwin->separation = getDouble("Hatching/separation"); convenienttwin->thickness = getDouble("Hatching/thickness"); convenienttwin->origin_x = getDouble("Hatching/origin_x"); convenienttwin->origin_y = getDouble("Hatching/origin_y"); convenienttwin->nocrosshatching = getBool("Hatching/bool_nocrosshatching"); convenienttwin->perpendicular = getBool("Hatching/bool_perpendicular"); convenienttwin->minusthenplus = getBool("Hatching/bool_minusthenplus"); convenienttwin->plusthenminus = getBool("Hatching/bool_plusthenminus"); convenienttwin->moirepattern = getBool("Hatching/bool_moirepattern"); convenienttwin->separationintervals = getInt("Hatching/separationintervals"); //convenienttwin->trigonometryalgebra = getBool("Hatching/bool_trigonometryalgebra"); //convenienttwin->scratchoff = getBool("Hatching/bool_scratchoff"); convenienttwin->antialias = getBool("Hatching/bool_antialias"); convenienttwin->opaquebackground = getBool("Hatching/bool_opaquebackground"); convenienttwin->subpixelprecision = getBool("Hatching/bool_subpixelprecision"); if (getBool("Hatching/bool_nocrosshatching")) convenienttwin->crosshatchingstyle = 0; else if (getBool("Hatching/bool_perpendicular")) convenienttwin->crosshatchingstyle = 1; else if (getBool("Hatching/bool_minusthenplus")) convenienttwin->crosshatchingstyle = 2; else if (getBool("Hatching/bool_plusthenminus")) convenienttwin->crosshatchingstyle = 3; if (getBool("Hatching/bool_moirepattern")) convenienttwin->crosshatchingstyle = 4; } void KisHatchingPaintOpSettings::fromXML(const QDomElement& elt) { setProperty(HATCHING_VERSION, "1"); // This make sure that fromXML will override HAIRY_VERSION with 2, or will default to 1 KisBrushBasedPaintOpSettings::fromXML(elt); QVariant v; if (!getProperty(HATCHING_VERSION, v) || v == "1") { setProperty("Hatching/thickness", 2.0 * getDouble("Hatching/thickness")); } setProperty(HATCHING_VERSION, "2"); // make sure it's saved as version 2 next time } #include #include "kis_paintop_preset.h" #include "kis_paintop_settings_update_proxy.h" #include "kis_hatching_options.h" QList KisHatchingPaintOpSettings::uniformProperties(KisPaintOpSettingsSP settings) { QList props = listWeakToStrong(m_d->uniformProperties); if (props.isEmpty()) { { KisDoubleSliderBasedPaintOpPropertyCallback *prop = new KisDoubleSliderBasedPaintOpPropertyCallback( KisDoubleSliderBasedPaintOpPropertyCallback::Double, "hatching_angle", i18n("Hatching Angle"), settings, 0); const QString degree = QChar(Qt::Key_degree); prop->setRange(-90, 90); prop->setSingleStep(0.01); prop->setDecimals(2); prop->setSuffix(degree); prop->setReadCallback( [](KisUniformPaintOpProperty *prop) { HatchingOption option; option.readOptionSetting(prop->settings().data()); prop->setValue(option.angle); }); prop->setWriteCallback( [](KisUniformPaintOpProperty *prop) { HatchingOption option; option.readOptionSetting(prop->settings().data()); option.angle = prop->value().toReal(); option.writeOptionSetting(prop->settings().data()); }); QObject::connect(preset()->updateProxy(), SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue())); prop->requestReadValue(); props << toQShared(prop); } { KisDoubleSliderBasedPaintOpPropertyCallback *prop = new KisDoubleSliderBasedPaintOpPropertyCallback( KisDoubleSliderBasedPaintOpPropertyCallback::Double, "hatching_separation", i18n("Separation"), settings, 0); prop->setRange(1.0, 30); prop->setSingleStep(0.01); prop->setDecimals(2); prop->setSuffix(i18n(" px")); prop->setReadCallback( [](KisUniformPaintOpProperty *prop) { HatchingOption option; option.readOptionSetting(prop->settings().data()); prop->setValue(option.separation); }); prop->setWriteCallback( [](KisUniformPaintOpProperty *prop) { HatchingOption option; option.readOptionSetting(prop->settings().data()); option.separation = prop->value().toReal(); option.writeOptionSetting(prop->settings().data()); }); QObject::connect(preset()->updateProxy(), SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue())); prop->requestReadValue(); props << toQShared(prop); } { KisDoubleSliderBasedPaintOpPropertyCallback *prop = new KisDoubleSliderBasedPaintOpPropertyCallback( KisDoubleSliderBasedPaintOpPropertyCallback::Double, "hatching_thickness", i18n("Thickness"), settings, 0); prop->setRange(1.0, 30); prop->setSingleStep(0.01); prop->setDecimals(2); prop->setSuffix(i18n(" px")); prop->setReadCallback( [](KisUniformPaintOpProperty *prop) { HatchingOption option; option.readOptionSetting(prop->settings().data()); prop->setValue(option.thickness); }); prop->setWriteCallback( [](KisUniformPaintOpProperty *prop) { HatchingOption option; option.readOptionSetting(prop->settings().data()); option.thickness = prop->value().toReal(); option.writeOptionSetting(prop->settings().data()); }); QObject::connect(preset()->updateProxy(), SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue())); prop->requestReadValue(); props << toQShared(prop); } } return KisPaintOpSettings::uniformProperties(settings) + props; } diff --git a/plugins/paintops/hatching/kis_hatching_paintop_settings.h b/plugins/paintops/hatching/kis_hatching_paintop_settings.h index b154931b90..089b3ed3bc 100644 --- a/plugins/paintops/hatching/kis_hatching_paintop_settings.h +++ b/plugins/paintops/hatching/kis_hatching_paintop_settings.h @@ -1,87 +1,89 @@ /* * Copyright (c) 2010 Lukáš Tvrdý * Copyright (c) 2010 José Luis Vergara * * 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_HATCHING_PAINTOP_SETTINGS_H_ #define KIS_HATCHING_PAINTOP_SETTINGS_H_ #include #include #include "kis_hatching_paintop_settings_widget.h" #include class KisHatchingPaintOpSettings : public KisBrushBasedPaintOpSettings { public: KisHatchingPaintOpSettings(); ~KisHatchingPaintOpSettings() override; //Dialogs enabled + bool enabledcurveangle; bool enabledcurvecrosshatching; bool enabledcurveopacity; bool enabledcurveseparation; bool enabledcurvesize; bool enabledcurvethickness; //Hatching Options double angle; double separation; double thickness; double origin_x; double origin_y; bool nocrosshatching; bool perpendicular; bool minusthenplus; bool plusthenminus; bool moirepattern; int crosshatchingstyle; int separationintervals; //Hatching Preferences //bool trigonometryalgebra; //bool scratchoff; bool antialias; bool subpixelprecision; bool opaquebackground; - //Crosshatching, Separation and Thickness curves + //Angle, Crosshatching, Separation and Thickness curves + double anglesensorvalue; double crosshatchingsensorvalue; double separationsensorvalue; double thicknesssensorvalue; void initializeTwin(KisPaintOpSettingsSP convenienttwin) const; using KisPropertiesConfiguration::fromXML; void fromXML(const QDomElement&) override; QList uniformProperties(KisPaintOpSettingsSP settings) override; private: Q_DISABLE_COPY(KisHatchingPaintOpSettings) struct Private; const QScopedPointer m_d; }; typedef KisSharedPtr KisHatchingPaintOpSettingsSP; #endif diff --git a/plugins/paintops/hatching/kis_hatching_paintop_settings_widget.cpp b/plugins/paintops/hatching/kis_hatching_paintop_settings_widget.cpp index c5f51457f0..85119605e4 100644 --- a/plugins/paintops/hatching/kis_hatching_paintop_settings_widget.cpp +++ b/plugins/paintops/hatching/kis_hatching_paintop_settings_widget.cpp @@ -1,137 +1,139 @@ /* * Copyright (c) 2010 Lukáš Tvrdý * Copyright (c) 2010 José Luis Vergara * * 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_hatching_paintop_settings_widget.h" #include "kis_hatching_options.h" #include "kis_hatching_preferences.h" #include "kis_hatching_paintop_settings.h" +#include "kis_hatching_pressure_angle_option.h" #include "kis_hatching_pressure_crosshatching_option.h" #include "kis_hatching_pressure_separation_option.h" #include "kis_hatching_pressure_thickness_option.h" #include #include #include #include #include #include #include #include "kis_texture_option.h" #include "kis_curve_option_widget.h" #include #include "kis_pressure_texture_strength_option.h" #include #include KisHatchingPaintOpSettingsWidget:: KisHatchingPaintOpSettingsWidget(QWidget* parent) : KisBrushBasedPaintopOptionWidget(parent) { setPrecisionEnabled(true); //-------Adding widgets to the screen------------ addPaintOpOption(new KisHatchingOptions(), i18n("Hatching options")); addPaintOpOption(new KisHatchingPreferences(), i18n("Hatching preferences")); addPaintOpOption(new KisCompositeOpOption(true), i18n("Blending Mode")); addPaintOpOption(new KisCurveOptionWidget(new KisHatchingPressureSeparationOption(), i18n("0.0"), i18n("1.0")), i18n("Separation")); addPaintOpOption(new KisCurveOptionWidget(new KisHatchingPressureThicknessOption(), i18n("0.0"), i18n("1.0")), i18n("Thickness")); + addPaintOpOption(new KisCurveOptionWidget(new KisHatchingPressureAngleOption(), i18n("0.0"), i18n("1.0")), i18n("Angle")); addPaintOpOption(new KisCurveOptionWidget(new KisHatchingPressureCrosshatchingOption(), i18n("0.0"), i18n("1.0")), i18n("Crosshatching")); addPaintOpOption(new KisCurveOptionWidget(new KisPressureOpacityOption(), i18n("Transparent"), i18n("Opaque")), i18n("Opacity")); addPaintOpOption(new KisCurveOptionWidget(new KisPressureSizeOption(), i18n("0%"), i18n("100%")), i18n("Size")); addPaintOpOption(new KisPressureMirrorOptionWidget(), i18n("Mirror")); addPaintOpOption(new KisPaintActionTypeOption(), i18n("Painting Mode")); addPaintOpOption(new KisTextureOption(), i18n("Pattern")); addPaintOpOption(new KisCurveOptionWidget(new KisPressureTextureStrengthOption(), i18n("Weak"), i18n("Strong")), i18n("Strength")); //-----Useful to read first:------ /* Below you will encounter a reasonably correct solution to the problem of changing the default presets of the "BrushTip" popup configuration dialogue. In my (Pentalis) opinion, the best solution is code refactoring (simpler ways to change the defaults). On the meanwhile, copypasting this code won't give your class a charisma penalty. In kis_hatching_paintop_settings.cpp you will find a snippet of code to discover the structure of your XML config tree if you need to edit it at build time like here. */ //---------START ALTERING DEFAULT VALUES----------- //As the name implies, reconfigurationCourier is the KisPropertiesConfigurationSP //we'll use as an intermediary to edit the default settings KisPropertiesConfigurationSP reconfigurationCourier = configuration(); /*xMLAnalyzer is an empty document we'll use to analyze and edit the config string part by part I know the important string is "brush_definition" because I read the tree with the snippet in kis_hatching_paintop_settings.cpp */ QDomDocument xMLAnalyzer; xMLAnalyzer.setContent(reconfigurationCourier->getString("brush_definition")); /*More things I know by reading the XML tree. At this point you can just read it with: dbgKrita << xMLAnalyzer.toString() ; those QDomElements are the way to navigate the XML tree, read http://doc.qt.nokia.com/latest/qdomdocument.html for more information */ QDomElement firstTag = xMLAnalyzer.documentElement(); QDomElement firstTagsChild = firstTag.elementsByTagName("MaskGenerator").item(0).toElement(); // SET THE DEFAULT VALUES firstTag.attributeNode("spacing").setValue("0.4"); firstTagsChild.attributeNode("diameter").setValue("30"); //Write them into the intermediary config file reconfigurationCourier->setProperty("brush_definition", xMLAnalyzer.toString()); KisCubicCurve CurveSize; CurveSize.fromString("0,1;1,0.1;"); //dbgKrita << "\n\n\n" << CurveSize.toString() << "\n\n\n"; QVariant QVCurveSize = QVariant::fromValue(CurveSize); reconfigurationCourier->setProperty("CurveSize", QVCurveSize); setConfiguration(reconfigurationCourier); // Finished. /* Debugging block QMap rofl = QMap(reconfigurationCourier->getProperties()); QMap::const_iterator i; for (i = rofl.constBegin(); i != rofl.constEnd(); ++i) dbgKrita << i.key() << ":" << i.value(); */ } KisHatchingPaintOpSettingsWidget::~ KisHatchingPaintOpSettingsWidget() { } KisPropertiesConfigurationSP KisHatchingPaintOpSettingsWidget::configuration() const { KisHatchingPaintOpSettingsSP config = new KisHatchingPaintOpSettings(); config->setOptionsWidget(const_cast(this)); config->setProperty("paintop", "hatchingbrush"); // XXX: make this a const id string writeConfiguration(config); return config; } diff --git a/plugins/paintops/hatching/kis_hatching_pressure_angle_option.cpp b/plugins/paintops/hatching/kis_hatching_pressure_angle_option.cpp new file mode 100644 index 0000000000..9fd38b6b13 --- /dev/null +++ b/plugins/paintops/hatching/kis_hatching_pressure_angle_option.cpp @@ -0,0 +1,36 @@ +/* By Idiomdrottning 2018, after a file that + * was Copyright (c) 2010 José Luis Vergara + * + * 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_hatching_pressure_angle_option.h" +#include + +#include +#include +#include + + +KisHatchingPressureAngleOption::KisHatchingPressureAngleOption() + : KisCurveOption("Angle", KisPaintOpOption::GENERAL, false) +{ +} + +double KisHatchingPressureAngleOption::apply(const KisPaintInformation & info) const +{ + if (!isChecked()) return 0.5; + return computeSizeLikeValue(info); +} diff --git a/plugins/paintops/hatching/kis_hatching_pressure_angle_option.h b/plugins/paintops/hatching/kis_hatching_pressure_angle_option.h new file mode 100644 index 0000000000..1e07db3dd4 --- /dev/null +++ b/plugins/paintops/hatching/kis_hatching_pressure_angle_option.h @@ -0,0 +1,37 @@ +/* By Idiomdrottning 2018, after a file that + * was Copyright (c) 2010 José Luis Vergara +* +* 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_HATCHING_PRESSURE_ANGLE_OPTION_H +#define KIS_HATCHING_PRESSURE_ANGLE_OPTION_H + +#include "kis_curve_option.h" +#include + +/** + * The pressure angle option defines a curve that is used to + * calculate the effect of pressure (or other parameters) on + * angle in the hatching brush + */ +class KisHatchingPressureAngleOption : public KisCurveOption +{ +public: + KisHatchingPressureAngleOption(); + double apply(const KisPaintInformation & info) const; +}; + +#endif