Llaves
Llaves

Reputation: 743

Coordinating overobj and toolbar buttons to set pointer in Matlab

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?

Upvotes: 1

Views: 99

Answers (1)

Suever
Suever

Reputation: 65460

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.

Upvotes: 2

Related Questions