Mirroring of the canvas

LukasT.dev@gmail.com lukast.dev at gmail.com
Wed Mar 24 20:30:49 CET 2010


Hello,

I'm trying to implement the mirroring of the canvas. It is a feature where we 
mirror the projection of the canvas instead of the mirroring the device when 
you want to see mirrored image of your paint. Similar feature is in mypaint.

I started with mirroring the events. There are some coordinate systems in 
canvas. First one is widget space, it is possition of the input device in 
widget pixels. Then there is document space, so when you paint, the event from 
the widget is converted by few function calls to document coordinates. 

First the coordinates are translated by scrolling offset (when you move with 
slider in bigger zoom ) and by document origin (it is the distance from the 
canvas top left corner to image top left corner). Then the coordinates 
are transformed to document coordinates with zoom.

I mirror the coordinates on document level, that means that when you draw 
stroke, the document is updated in the mirrored part. Document adds the "dirty 
rects on document level" so the projection is computed properly because so far 
projection does not know about mirroring.

Next step was to mirror the canvas. I mirrored the projection by QPainter
as Cyrille suggested using transformation like scale(-1,1) and 
translate(width,0)

Now the problems started to show  up. The projection with mirrored canvas is 
not updated properly. So I started to investigate. 
In KisCanvas2::updateCanvasProjection I tried to mirror the vRect rectangle. 
The rc rectangle update the projection and the vRect is responsible to for 
proper updates calls. 

So far I have these problems:
the canvas is not updated properly, I mirrored the vRect like this 
vRect = QRect(image()->width() - vRect.x() 
vRect.width(),vRect.top(),vRect.width(), vRect.height());

but that is not correct. The canvas is erased in QRect 
KisPrescaledProjection::preScale(const QRect & rc)


If I call just update(), when the whole canvas is updated, it is correct. 
What I miss there?

Question: how to solve it? I don't know much about projection even I spent a 
lot of time looking at the code. Dmitry, what do you think I need to do?
Is it correct to mirror the QPainter or should we mirror on the projection 
level? If so, what has to be mirrored?

Another problem. When we zoom and scroll vertically, part of the image is 
erased. It seems that when we mirror the image, the hidden part because 
actually visible and in the projection it is represented by transparent pixel. 
Is that what is happening? Any hints where and how to fix it?

Here is the patch I have for now 
http://valdyas.org/~lukast/mirroring.patch


More information about the kimageshop mailing list