Drawing on VectorLayer From Custom Tool


(Matis) #1

Hello,

This is my first post in this forum. So thanks everybody for all your efforts.
I am sorry but I am working on a side project (outside the roadmap). For now I am just discovering the source code and I am trying to develop basic stuff to get familiar with the source code.

I am trying to create my own custom tool and add it to pencil. For now I have created a tool inheriting from :StrokeTool, I am working essentially in the vector layer (for now), so up to now I can select my tool and select a stroke with it (as for the move tool), what I want to do is: Once a stroke is selected hit a key say “M” and automatically draw a new stroke on the vector layer.
I am able to generate the right path however I cannot manage to draw it. I am using (inside a keypressedevent):
QPainterPath path(X);
path.lineTo(Y);
mScribbleArea->drawPath(path, pen, Qt::NoBrush, QPainter::CompositionMode_Source);
mScribbleArea->refreshVector(path.boundingRect().toRect(), qRound((width/2 + 2) * mEditor->view()->scaling()));

and my pen is:

QPen pen( QColor(200, 0, 0),
          width,
          Qt::SolidLine,
          Qt::RoundCap,
          Qt::RoundJoin );

I guess there is something I don’t get, if anyone can give me a hand it would be much appreciated !

Thanks


(Jose Moreno) #2

@matis Cool! although i’m afraid I don’t know much about the programming side of Pencil2D. I suppose you could ask around on the github while seeking to understand the code, however there are just too few devs around, but hopefully you can get it to work, good luck with that!


(Matis) #3

Hey, thanks for that link, I will keep you updated If I manage to make it work !


(Matis) #4

Hey I found a solution, maybe one day it will help someone, actually the right way to do this is:

pVecImg->insertCurve( -1, curve, mEditor->view()->scaling(), false );
mScribbleArea->setModified( mEditor->layers()->currentLayerIndex(), mEditor->currentFrame() );
mScribbleArea->setAllDirty();

where curve is a bezier curve.


(Jose Moreno) #5

@matis Hey! nice and glad to hear you managed to break through adding a custom tool on Pencil2D :slight_smile:

The only devs I know that are working on Pencil2D at the moment are @chchwy who’s the maind dev and @scribblemaniac who is awesome and helping whenever he can. @feeef was also helping us to integrate mypaintLib and he also dabbled into the vector tools since he implemented some of the newest paintbucket functionality. Those are their usernames on Github as well so maybe they could review your code if you fork the github Pencil2D master project and use your own repository branch to implement this new feature.

Thanks for at least having time to work on the program. I really wish I could help more but I’m not knowledgeable with C++ yet.


(Matis) #6

@JoseMoreno
Hey, long time no see… The result of my research has now been publicly released. Maybe there is some better place where I can publish this. I am planning on releasing the code in the months to come.
Anyway results can be seen here:

Publication infos:


Video:


(Jose Moreno) #7

@matis That’s really cool! thank you for sharing the results of your research with us here. I’ll tag our developers so they can have a look at it as well.

@scribblemaniac @chchwy @J5lx @CandyFace


(Jose Moreno) #8

@matis If it’s ok with you, would you mind if we shared your research and video over our social media?


(Matis) #9

@JoseMoreno Yeah sure, no problem!