Invert y axis for Component



I’m sure this has probably been asked before. Is it possible to simply invert the y-axis values for a component? Instead of 0 being at the top, I want it to be at the bottom. y values should increase as you move up rather than down. It would make things easier to paint, as this is generally how people view an xy axis in their mind.
g.setOrigin() doesn’t help as it only moves the origin to another place. I’ve tried the AffineTransform but I’m not sure if I’m using it correctly. It would be great if I could just change this in my resized() method at the start!
Any help is welcome.



That way madness lies… Having had to deal with CoreGraphics and openGL’s upside-downness, I can recommend keeping things the right way up!

If you’re just drawing stuff, then you can invert it by applying a transform to the Graphics object, with AffineTransform::verticalFlip. But of course any images will then appear upside down.


Fair enough. I might just leave things the way they are then, it will save me a lot of work by re-doing it from scratch anyway!

Thanks Jules.


Yeah, probably the easiest thing to do is to just add a transform to the Graphics object.

You could calculate what it should be in resized [you’ll want to scale by (1,-1), and then translate by (0,height)]
Then, you can use this transform in paint() [via g.addTransform()].

I’m not on the latest, but I don’t see any resetTransform function (or a way to get the current one)… but you can use saveState()/restoreState() if you need to change back for any reason in the same paint call.

… but really, it’s totally worth adapting to thinking about drawing to the screen in the ‘default’ way. Some libraries DO have an inverted* (graph-paper style) y axis, but some don’t. While everyone understands the upwards style from maths classes, a large number of codebases simply work the other** way round, and it helps to be able to just work with them.

Besides, you’ll soon realise that it’s obviously just the right way… such superior objectivity only comes from experience :wink:

  • yes, THEY are the inverted ones.
    ** correct