swing: scale & translate mouse position

74 views
Skip to first unread message

Boris Hollas

unread,
May 15, 2013, 6:41:04 AM5/15/13
to scala...@googlegroups.com
Hello,

I use graphics2d to draw graphics. These graphics are scaled and translated with g.scale and g.translate.
Also, I have a mouse click listener. I want to click at points in the graphics. To identify the correct position, I have to take into account the scaling and translating I've done to draw the graphics. How can this be done?

    listenTo(mouse.clicks)
    focusable = true
    reactions += {
        case event.MouseClicked(_, point, _, _, _) => {
            // need to scale & translate point.x, point.y to corresponding position
            ...
            repaint
        }
    }

Naftoli Gugenheim

unread,
May 20, 2013, 4:03:46 PM5/20/13
to Boris Hollas, scala-user
Where do you have the graphics transform?




--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Boris Hollas

unread,
May 21, 2013, 4:15:39 AM5/21/13
to scala...@googlegroups.com, Boris Hollas


On Monday, May 20, 2013 10:03:46 PM UTC+2, nafg wrote:
Where do you have the graphics transform?

in my paint-method:

    override def paintComponent(g: Graphics2D) {
        super.paintComponent(g)
        g.setColor(java.awt.Color.black)
        g.scale(s, s)
        g.translate(0.1, 0.1)
 

Naftoli Gugenheim

unread,
May 21, 2013, 4:20:06 AM5/21/13
to Boris Hollas, scala-user
So just add and multiply the point by those numbers.


--

Boris Hollas

unread,
May 21, 2013, 5:44:29 AM5/21/13
to scala...@googlegroups.com, Boris Hollas
This it what I have done as a work-around. But is there a scala-swing method to do so automatically?
Reply all
Reply to author
Forward
0 new messages