albertoefg

Blog About Contact

Implementing a derivated class of kis_brushes_pipe

What I am working on

I am still working on the change of the brush index, so far I've been confused with the classes, because I am not sure why somethings are implemented and then overriden or why somethings are where they are, and I am not sure exactly when or why to do this.

I've been working all week, instead of trying to deliver a feature I tried to write and organize the whole class, and then slowly write all the small functions, this is because I've had problem with classes and objects, but I understand functions, so I to tried work with my strengths.

This is a little analysis of the things I've been trying implement based on kis_imagepipe_brush.h and kis_brushes_pipe.h.

kis_animated_brushes.h

This is the file that has the class and code to change the figures each time.

Type of brush

This is an enum that will have the types of brushes that are supported, for now only Sequence and Random.

namespace KisAnimated //I am not sure if this namespace should be defined elsewhere. Ask my mentor
{
enum SelectionMode {
    Sequence,
    Random,
};

Class

The main class, it calls a base class constructor to inherit from KisVectorAnimatedBrush, if I understand correctly the latter should only handle a single image, which means it probably should be renamed. (reminder to look closer at kis_gbr_brush.h)

The class should be created like this:

class BRUSH_EXPORT KisAnimatedBrushes : public KisVectorAnimatedBrush

Functions

There are several functions that should be implement for this class to work properly, so I will try to describe them by group.

Functions for starting and ending the brush

Function to initialize the brush, kis_imagepipe_brush.h uses an specialized constructor that is a vector of a vector, but I don't think that will be necessary in this case.

KisAnimatedBrushes(const QString& filename);

The next functions are pretty standard, so there is nothing special to explain about them

KisBrush* clone() const override;

bool load() override;
bool loadFromDevice(QIODevice *dev) override;
bool save() override;
bool saveToDevice(QIODevice* dev) const override;

~KisAnimatedBrushes() override;

Functions to deal with the Index

This functions refer just to the logic of the Index, they don't deal with graphics. Function to select the type of brush, this is necessary to know if the brush will change in sequence or randomly.

enumBrushType brushType() const override;

The next function will get the brushIndex to do that it needs a KisPaintInformation,

quint32 brushIndex(const KisPaintInformation& info) const override;

We need to know once the image has been painted

void notifyStrokeStarted() override;
void notifyCachedDabPainted(const KisPaintInformation& info) override;
void prepareForSeqNo(const KisPaintInformation& info, int seqNo) override; //I am not sure what this one does

Helper Functions

If I do this the same way as kis_imagepipe_brush, then it should call a helper class that is derived from KisBrushesPipe<KisVectorAnimatedBrush>, where chooseNextBrush and updateBrushIndexes should be implemented.

int chooseNextBrush(const KisPaintInformation& info) override;
void updateBrushIndexes(const KisPaintInformation& info, int seqNo) override; 
//I am not sure what seqNo is supposed to mean

Conclusion

Well so far I haven't listed everything about the classes I am working on, but this is a general idea of the things I need to implement for now, as I understand them.