Hi Mikael

I assume you use spec with the Morphic underlying graphical library.

In your presenter: 
- `anEvent position` will give you the event position in the global world coordinate.
- `self adapter widget position.` will give you the top left corner underlying Morph position in the global world coordinate.

`anEvent position - self adapter widget position` should give you the position you're looking for.

Renaud

Mar 3, 2025, 03:17 by mikael.svane@fridhem.org:

I have a presenter that is a subclass of SpPresenterWithModel and it contains, among other things, an ImagePresenter with an autoscaling image (a Form). I want to capture mouse clicks on the image and get the coordinate of the click relative to the upper left corner of the Form.

 

My #initializePresenter method looks like this:

initializePresenter

                           image := self newImage

                                                       image: self emptyImage;

                                                       autoScale: true.

                           image eventHandler whenMouseDownDo: [ :event |

                                                                                  self handleMouseDown: event].

 

This works, and the #handleMouseDown: method is run whenever the mouse is pressed on the ImagePresenter, but the MouseButtonEvent reports global coordinates and I can���t find out how to convert these to coordinates relative to the Form that the ImagePresenter holds. I have googled and found answers to similar old questions, but nothing that seems to apply to Spec2.

 

There must be a very simple solution to this, it���s just that I can���t seem to find it.

 

Kind regards,

Mikael