Open s5k6 opened 8 years ago
Cairo/gtk and diagrams have different ideas about the y-axis: in diagrams, the positive y-axis points up (just like in math); in cairo/gtk, it points down (so (0,0) is at the top left of the screen). When a diagram is "adjusted" it is rescaled and centered but also flipped upside down to account for this.
I think the problem is that your code is flipping the diagram twice: toGtkCoords
calls adjustDia
with the last component of the options record (_cairoBypassAdjust
) set to False
: this option controls whether the adjustment step is skipped. So False
means it is not skipped, and toGtkCoords
does stuff like center the diagram and flip it upside down. But then your defaultRender'
function also has that option set to False
and so the adjustment happens again: the diagram is already properly scaled and centered so nothing happens there, but it does get flipped again. Notice how in the original code, liftIO . renderToGtk win . toGtkCoords
, if you look at the implementation of renderToGtk
it has _cairoBypassAdjust
set to True
, so the adjustment step is bypassed, avoiding a second flip.
Thanks for that illuminating answer.
So the original defaultRender
would do it wrong? I cannot test
because I do not have a DrawingArea
at hand, and don't know where to
get one from.
I've tried _cairoBypassAdjust = True
, but then the diagram does not
resize automatically when the window is resized. So what's the
correct way to do this? Do I have to reflect the diagram myself, as
follows?
...
> defaultRender' drawable diagram
> = renderDoubleBuffered drawable opts $ scaleY (-1) diagram
> where
...
> , _cairoBypassAdjust = False
And about the root of my problem: I have a DrawWindow
from
eventWindow
and need to run defaultRender
on it. How do I get the
required DrawingArea
?
Ah, I see now, toGtkCoords
does not resize the diagram, it only centers and flips it. But if you have _cairoBypassAdjust = False
in defaultRender'
then it will also center and flip the diagram, so I think the solution is to just omit the call to toGtkCoords
--- you don't need it at all.
Unfortunately I do not understand the GTK backend well enough to answer your questions about DrawingArea
.