Effacer les filtres
Effacer les filtres

Can the start position for ginput() crosshairs be chosen?

1 vue (au cours des 30 derniers jours)
Douglas Anderson
Douglas Anderson le 4 Mai 2022
Modifié(e) : Voss le 6 Mai 2022
Hello,
I have a GUIDE function that has a button defined for picking a location in an axes. When I click the button, the pick crosshairs don't appear until I move the cursor into the axes. A user can wonder what's going on and click the button more than once, not seeing a result. Is there a way to start the ginput() IN the relevant axes?
Thanks!
Doug

Réponse acceptée

Voss
Voss le 4 Mai 2022
There is no option for that, as far as I can tell.
However, you can make a copy of ginput.m (let's say you call it my_ginput.m so it doesn't conflict with ginput.m) and modify the copy to call updateCrossHair (a local function within ginput.m) immediately after the crosshairs are created (i.e., don't wait until mouse movement occurs to update the crosshairs).
In R2017b, in ginput.m there's a function called setupFcn, and in that function is a call to createCrossHair, so right after that you'd put this line:
updateCrossHair(fig,initialState.CrossHair)
and that should get the crosshairs to turn on immediately, which may be good enough (they'll be centered on the pushbutton or wherever the cursor is when my_ginput is called).
In addition to that, if you want to programmatically move the cursor to the center of the relevant axes, you can do that by setting the groot property 'PointerLocation', e.g.:
set(0,'PointerLocation',ax_pos([1 2])+ax_pos([3 4])/2);
but note that PointerLocation is relative to screen position, so that ax_pos has to be relative to screen position as well, so you'd have to do something like:
fig_pos = getpixelposition(fig); % figure Position in pixels
ax_pos = getpixelposition(gca(),true); % axes Position in pixels, relative to figure (taking into account any panels the axes is nested in)
set(0,'PointerLocation',fig_pos([1 2])+ax_pos([1 2])+ax_pos([3 4])/2); % center of axes, relative to screen
If you put those three lines in my_ginput.m, after the figure's WindowButtonMotionFcn is set, which is right after the call to createCrossHair mentioned above (again, at least that's where it is in R2017b), then the crosshairs will show up immediately and be centered in the current axes (and if you do that you can remove the call to updateCrossHair above, since it'll be called automatically when PointerLocation is set).
  9 commentaires
Douglas Anderson
Douglas Anderson le 6 Mai 2022
Yes, I have, thank you!
I had been trying to associate the crosshair with a specific axes, without success, but then figured out that all I needed to do was to find the right position within the main window!
Thanks again. Good solution.
Voss
Voss le 6 Mai 2022
Modifié(e) : Voss le 6 Mai 2022
You're welcome! Interesting problem. Glad it's working!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by