File indexing completed on 2024-06-23 04:27:49

0001 /*
0002  * SPDX-FileCopyrightText: 2008 Boudewijn Rempt <boud@valdyas.org>
0003  * SPDX-FileCopyrightText: 2011 Silvio Heinrich <plassy@web.de>
0004  * SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com>
0005  *
0006  *  SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 #ifndef KISCURVEOPTION_H
0009 #define KISCURVEOPTION_H
0010 
0011 #include <vector>
0012 #include <memory>
0013 
0014 #include <KisCurveOptionData.h>
0015 #include "sensors/KisDynamicSensor.h"
0016 
0017 class PAINTOP_EXPORT KisCurveOption
0018 {
0019 public:
0020     KisCurveOption(const KisCurveOptionData &data);
0021 
0022     KisCurveOption(KisCurveOption &) = delete;
0023     KisCurveOption &operator=(KisCurveOption &) = delete;
0024 
0025     struct ValueComponents {
0026         qreal constant {1.0};
0027         qreal scaling {1.0};
0028         qreal additive {0.0};
0029         qreal absoluteOffset {0.0};
0030         bool hasAbsoluteOffset {false};
0031         bool hasScaling {false};
0032         bool hasAdditive {false};
0033         qreal minSizeLikeValue {0.0};
0034         qreal maxSizeLikeValue {0.0};
0035 
0036         /**
0037          * @param normalizedBaseAngle canvas rotation angle normalized to range [0; 1]
0038          * @param absoluteAxesFlipped true if underlying image coordinate system is flipped (horiz. mirror != vert. mirror)
0039          */
0040 
0041         qreal rotationLikeValue(qreal normalizedBaseAngle, bool absoluteAxesFlipped, qreal scalingPartCoeff, bool disableScalingPart) const;
0042 
0043         qreal sizeLikeValue() const;
0044     };
0045 
0046     /**
0047      * Uses the curves set on the sensors to compute a single
0048      * double value that can control the parameters of a brush.
0049      *
0050      * This value is derives from the values stored in
0051      * ValuesComponents object.
0052      */
0053     ValueComponents computeValueComponents(const KisPaintInformation& info, bool useStrengthValue) const;
0054 
0055     qreal computeSizeLikeValue(const KisPaintInformation &info, bool useStrengthValue = true) const;
0056     qreal computeRotationLikeValue(const KisPaintInformation& info, qreal baseValue, bool absoluteAxesFlipped, qreal scalingPartCoeff, bool disableScalingPart) const;
0057 
0058     qreal strengthValue() const;
0059     qreal strengthMinValue() const;
0060     qreal strengthMaxValue() const;
0061 
0062     bool isChecked() const;
0063     bool isRandom() const;
0064 
0065 private:
0066     bool m_isChecked;
0067     bool m_useCurve;
0068     int m_curveMode;
0069     qreal m_strengthValue;
0070     qreal m_strengthMinValue;
0071     qreal m_strengthMaxValue;
0072     std::vector<std::unique_ptr<KisDynamicSensor>> m_sensors;
0073 };
0074 
0075 #endif // KISCURVEOPTION_H