Check if a graphics object is visible to the user
Show older comments
The short version: Is there an easy way to check if a given graphics object is visible on screen? (Note that its visible property will not necessarily tell me this since its parent could be invisible while the object itself is visible).
The long version: Imagine you have a GUI with tabs (each tab containing an axes) and you want to add a callback that is invoked when the user moves the mouse scroll wheel. The callback needs to act differently depending upon which axes the mouse is currently positioned over. However, if the axes are positioned in the same location on screen in the different tabs, then the mouse is actually positioned over all of them. Thus I need to know which object is actually visible to the user and have the callback act accordingly. Also, because I'm trying to make this callback as generalizable as possible, the callback itself is ambivalent to the whole structure of the GUI so I can't just check which tab is currently selected. (I'm doing it this way so that I can reuse this code for other projects where the GUI design may be different from this specific case).
Any ideas would be appreciated. I could probably go handle diving and recursively figure out if an object is visible on screen, but I'd rather not have to do that if there's a simpler (and faster) way. Thanks!
Justin
Accepted Answer
More Answers (1)
Walter Roberson
on 18 Jun 2015
1 vote
This is difficult because it depends on the active Renderer and upon the release. There is an interesting article at http://blogs.mathworks.com/graphics/2014/11/04/sortmethod/
1 Comment
Joseph Cheng
on 18 Jun 2015
Edited: Joseph Cheng
on 18 Jun 2015
or... just a quick while loop looking for if the parent is visible or not..
h = figure;
for ind = 2:6
h(ind) = uipanel('parent',h(ind-1),'Title',['Main Panel' num2str(ind-1)],'FontSize',12,...
'BackgroundColor','white',...
'Position',[.01+ind/40 .01+ind/20 .9-ind/20 .9-ind/20]);
end
%set one to visible off
set(h(4),'visible','off')
%check to see if panel 5 is visible
isvisible = strcmp(get(h(6),'visible'),'on');
prnt = get(h(6),'parent');
while prnt~=0
isvisible = strcmp(get(prnt,'visible'),'on');
if isvisible ==0
break
end
prnt = get(prnt,'parent');
end
switch isvisible
case 1
disp('is visible');
case 0
invisparent = get(prnt,'title');
disp(['not visible because ' invisparent])
end
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!