[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    About a Vector Plugin for Flake
From:       emanuele () valinor ! it
Date:       2006-07-25 17:24:15
Message-ID: 44131.192.168.0.45.1153848255.squirrel () www ! valinor ! it
[Download RAW message or body]

Hello,
Starting from a conversation with ThomasZ and Zagge I now open this
discussion here on the ml.

I'm developing for SoC a Framework for Curves in Krita. It's almost
complete and it seems to work well.

Now, the Vector Plugin for Flake, as far as I understood, needs something
to keep information about itself, and about how to draw itself.
My Framework, with some tweaking and a bit of work, might be suitable for
the job.

The idea of "curve" I have is this: a set of points, in which some of them
are "pivots". Pivots are used to modify the drawn curve, and used as start
and end point for some functions.

After this short introduction, I can describe my Framework.
It consists in:
- A CurvePoint class
- A KisCurve class
- A KisCurve::iterator class
- A KisToolCurve class to implement Krita tools

Class CurvePoint has a KisPoint member, two bools (m_pivot and m_selected)
and an integer (m_hint). The bools are used to check and set if the point
is a pivot and, if it's a pivot, if it's selected (only pivots can be
selected). m_hint is used to give points some more informations. For
example, hint can be used by the tool to know how to paint a point. Or by
other functions to decide how to handle (move, delete) the point itself.

Class KisCurve is the core of the Framework. It has a
QValueList<CurvePoint> as main member and a set of functions used by the
tools. The non-virtual functions are:
- addPoint() (a wrapper around insert, that uses KisCurve::iterators)
- pushPoint() (a wrapper around append)
- Some other utility & wrapper functions
- deleteFirstPivot() and deleteLastPivot(): these are used to delete the
first/last pivot and points before/after the next/previous pivot.
- deleteSelected() and moveSelected()
     These two functions are provided for convenience. They call movePivot
and deletePivot for each selected pivot. Really handy to implement
the tool.

Then the virtual functions are:
- addPivot() and pushPivot()
     These are used to add pivots. They are virtual 'cause some kind of
curves, for example bezier curves, need to add more than one pivot
for each click. The function, after the insertion of the pivot,
select it and return the selected pivot in order to handle it.

- deleteCurve()
     This delete the curve between two points/iterators provided as
parameters.

- calculateCurve()
     This is the core of the core. It takes 3 parameters (overloaded ones
take an array of iterators): the starting point, the end point, and
an iterator before which adding the point in the QValueList. It has
to calculate which points in the interval are in the curve. For
bezier, it will provide a de castejaux algorithm, for circles another
algorithm, for lines another one, for magnetic lazo a sobel algorithm
and so on... they are implemented each in the subclasses (for example
in the semi-ready-to-come KisCurveMagnetic). Points added can be then
drawn, modified, or simply stored for other uses...

- movePivot()
     Move the pivot provided as first argument to the position provided as
second argument. It then calls calculateCurve to recalculate the
curve.

- other side-effect functions.

KisCurve::iterator provides a pair of functions to retrieve the next and
previous pivots relative to the iterator that makes the call.

KisToolCurve defines all the events and the paint functions; one of them
is really interesting: selectByHandle(). By now, it checks if the click is
happened on a pivot handle. But it can do more without much work. It can
check if the click is happened near enough from a point of the curve, or a
line between two points. If it's so, it can select the next and previous
pivots and then the curve can be altered in a really easy way (just as
Gimp does it with paths).

As you see shown by selectByHandle(), my KisCurve can "recognize" itself
and KisCurveTool can easily draw it.

As far as I know, this is what a Flake shape needs to have: a structure
that describes the shape in a way it can be selected, modified, deleted,
drawn.

So, I'm wondering if my code could be used as base for the the Vector
Plugin for Flake.

I'm afraid if this email has became so long :(

I hope to answer as quickly as possible (I'm without a stable internet
connection in this week) to your questions.

Thank you for the attention,
Emanuele

_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic