Commit 7e087bd6 authored by Blackbeard (alberto flores)'s avatar Blackbeard (alberto flores) 🚢
Browse files

Added Helper class for kis_vectoranimatedbrush

parent 4b725d50
...@@ -16,31 +16,70 @@ ...@@ -16,31 +16,70 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef KIS_ANIMATED_BRUSHES_ #include <QRandomGenerator>
#define KIS_ANIMATED_BRUSHES_
#include <kis_animated_brushes.h> #include <kis_animated_brushes.h>
#include <kis_brushes_pipe.h> #include <kis_brushes_pipe.h>
#include <kis_vectoranimated_brush.h> #include <kis_vectoranimated_brush.h>
class KisAnimatedBrushes : public KisVectorAnimatedBrush
KisAnimatedBrushes::KisAnimatedBrushes()
: m_isInitialized(false)
{ {
public: }
KisAnimatedBrushes()
: m_isInitialized(false)
{
}
protected:
int chooseNextBrush(const KisPaintInformation& info) override {
if (!m_isInitialized) { int KisAnimatedBrushes::chooseNextBrush(const KisPaintInformation &info) {
m_imageIndex = 0; int index;
if (!m_isInitialized) {
index = 0;
updateBrushIndexes(info, 0);
m_isInitialized = true; m_isInitialized = true;
} else { } else {
m_imageIndex ++; index = KisAnimatedBrushes::nextBrushSequence(m_currentIndex, m_numberOfImages)
}
return m_imageIndex;
} }
};
#endif /* __KIS_ANIMATED_BRUSHES_ */ m_currentIndex = index;
return index;
}
*/
int KisAnimatedBrushes::nextBrushSequence(int currentIndex, int numberOfImages) {
if (currentIndex == numberOfImages) {
return 0;
} else {
return currentIndex++;
}
}
int KisAnimatedBrushes::nextBrushRandom(int currentIndex, int numberOfImages) {
int index = rand() % numberOfImages + 1;
if (currentIndex == index) {
index = rand() % numberOfImages + 1;
}
return index;
}
void updateBrushIndexes(const KisPaintInformation& info, int seqNo) override {
for (int i = 0; i < m_parasite.dim; i++) {
m_parasite.index[i] = selectPost(m_parasite.selection[i],
m_parasite.index[i],
m_parasite.rank[i],
info,
seqNo);
}
...@@ -23,18 +23,41 @@ ...@@ -23,18 +23,41 @@
#include <kis_vectoranimated_brush.h> #include <kis_vectoranimated_brush.h>
class KisImageBrushesPipe(); class BRUSH_EXPORT KisAnimatedBrushes : public KisBrushesPipe<KisVectorAnimatedBrush>
class BRUSH_EXPORT KisAnimatedBrushes : public KisVectorAnimatedBrush
{ {
public: public:
KisAnimatedBrushes(const QString& filename); KisAnimatedBrushes();
// <-----------------Index Functions ------------------->
// KisPaintInformation -> int
// Returns and index for the next brush
int chooseNextBrush(const KisPaintInformation& info) override;
// int -> int
// helper for chooseNextBrush
// Returns next index in sequence
int nextBrushSequence(int currentIndex, int numberOfImages);
// int -> int
// helper for chooseNextBrush
// Returns a random index
int nextBrushRandom(int currentIndex, int numberOfImages);
private: void updateBrushIndexes(const KisPaintInformation& info, int seqNo);
int m_imageIndex;
private:
bool m_isInitialized;
int m_currentIndex;
int m_numberOfImages;
QString m_typeOfBrush;
struct Private; struct Private;
Private * const m_d; Private * const m_d;
}; };
#endif /* __KIS_ANIMATED_BRUSHES_ */ #endif /* __KIS_ANIMATED_BRUSHES_ */
...@@ -230,8 +230,42 @@ void KisVectorAnimatedBrush::toXML(QDomDocument& d, QDomElement& e) const ...@@ -230,8 +230,42 @@ void KisVectorAnimatedBrush::toXML(QDomDocument& d, QDomElement& e) const
int KisVectorAnimatedBrush::currentIndex() /*
// <---------------------- Index Functions -------------------->
void KisAnimatedBrushes::notifyStrokeStarted() {
m_isInitialized = false;
}
void KisAnimatedBrushes::notifyCachedDabPainted(const KisPaintInformation& info)
{
m_d->brushesPipe.notifyCachedDabPainted(info);
}
void KisAnimatedBrushes::prepareForSeqNo(const KisPaintInformation &info, int seqNo)
{
m_d->brushesPipe.prepareForSeqNo(info, seqNo);
}
enumBrushType KisAnimatedBrushes::brushType() const
{ {
qDebug() << "m_imageNumber" << m_imageNumber; return !hasColor() || useColorAsMask() ? PIPE_MASK : PIPE_IMAGE;
return m_imageNumber;
} }
bool KisAnimatedBrushes::hasColor() const
{
return m_d->brushesPipe.hasColor();
}
quint32 KisAnimatedBrushes::brushIndex(const KisPaintInformation& info) const
{
return m_d->brushesPipe.brushIndex(info);
}
*/
...@@ -42,9 +42,19 @@ public: ...@@ -42,9 +42,19 @@ public:
QString defaultFileExtension() const override; QString defaultFileExtension() const override;
void toXML(QDomDocument& d, QDomElement& e) const override; void toXML(QDomDocument& d, QDomElement& e) const override;
/*
// <------------------------------------------------- Draft Data --------------------------------------------------------> // <------------------------------------------------- Draft Data -------------------------------------------------------->
// State of the brush
//type of Brush
namespace KisAnimated
{
enum SelectionMode {
Sequence,
Random
};
}
// State of the brush
bool m_isInitialized; bool m_isInitialized;
// style of brush // style of brush
...@@ -123,7 +133,7 @@ public: ...@@ -123,7 +133,7 @@ public:
// <------------------------ Index Functions -----------------------------> // <------------------------ Index Functions ----------------------------->
//KisPaintInformation -> quint32 //KisPaintInformation -> quint32
// Returns current Index // Returns current Index
int32 brushIndex(); quint32 brushIndex(const KisPaintInformation& info) const override;
// KisPaintInformation -> int // KisPaintInformation -> int
// Returns and index for the next brush // Returns and index for the next brush
...@@ -141,12 +151,36 @@ public: ...@@ -141,12 +151,36 @@ public:
// qint32 maskWidth(KisDabShape const&, double subPixelX, double subPixelY, const KisPaintInformation& info) const override;
// qint32 maskHeight(KisDabShape const&, double subPixelX, double subPixelY, const KisPaintInformation& info) const override;
void notifyStrokeStarted() override;
void notifyCachedDabPainted(const KisPaintInformation& info) override;
void prepareForSeqNo(const KisPaintInformation& info, int seqNo) override;
protected:
void setBrushType(enumBrushType type) override;
// private:
// friend class KisAnimatedBrushesTest;
// KisVectorAnimatedBrush* testingGetCurrentBrush(const KisPaintInformation& info) const;
// void testingSelectNextBrush(const KisPaintInformation& info) const;
*/
private: private:
QByteArray m_svg; QByteArray m_svg;
int m_imageNumber; int m_imageNumber;
int m_numberOfImages; int m_numberOfImages;
bool m_isInitialized;
/* struct Private; /* struct Private;
Private * const m_d; */ Private * const m_d; */
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment