1

This post shows how to use the overobj function to set the pointer to change over the axes part of a gui. The problem is that this will override the pointer shape set by the zoom or pan toolbar buttons. I can test for various toolbar buttons being on like this:

  if (strcmp(handles.zoom.State, 'off'))
    obj_han=overobj('axes');
    if ~isempty(obj_han)
      set(handles.figure1,'Pointer','cross');
    else
      set(handles.figure1,'Pointer','arrow');
    end
  end

But that requires adding a new test for every tool button in the toolbar, which seems like a formula for error. How does zoom, for example, set the pointer? Is there a better way to integrate changing the pointer with the way the toolbar buttons make the change?

Suever
  • 64,497
  • 14
  • 82
  • 101
Llaves
  • 683
  • 7
  • 20

1 Answers1

2

You could use the undocumented uimode and uimodemanager to get the current uimode and if the current uimode is empty, then none of the tools are active.

manager = uigetmodemanager(gcf);

% Only alter the pointer if the CurrentMode is empty
if isempty(manager.CurrentMode)
    if ~isempty(obj_han)
        set(handles.figure1, 'Pointer', 'cross')
    else
        set(handles.figure1, 'Pointer', 'arrow')
    end
end

I would retrieve the uimodemanager outside of your callback and pass it explicitly to the callback so you don't have to retrieve it every time.

Suever
  • 64,497
  • 14
  • 82
  • 101
  • that works, but prompts an additional question. My gui has an axes obj that I then imshow('pic.bmp') on top of. The default behavior is to turn off visibility of the axes obj, which hides the axes from overobj. OK, turn it back on, but now I get tick marks outside my image. I can turn them off with axes.XTick = [] (and same for Y), but is there a more graceful way to do this? Also, should the first line of your code use gcbf instead of gcf? – Llaves Aug 10 '16 at 02:56
  • @Llaves The only way to accomplish that with an axes is what you have done. You can use `gcbf` if you prefer. The snippet just shows that you retrieve the `uimodemanager` from the figure. How you get that figure handle is up to you. – Suever Aug 10 '16 at 11:10