No BSD License  

Highlights from
AddReorderButtons

4.66667

4.7 | 3 ratings Rate this file 1 Download (last 30 days) File Size: 1.86 KB File ID: #18136
image thumbnail

AddReorderButtons

by Geoffrey Adams

 

27 Dec 2007 (Updated 24 Jan 2008)

Add toolbar buttons to move plot objects forward and backward within axes.

| Watch this File

File Information
Description

AddReorderButtons adds two buttons to the top toolbar of a specified figure. When clicked while a plot object is selected, they will move that object "forward" or "backward" in the rendering list. This is most practically useful for multiple 2D plots in the same axes, in which one plot may partially or completely obscure another; this is a simple way of moving the obscured plot forward without having to change the code that generated the figure.

I personally find this function most useful as part of my DefaultFigureCreateFcn callback, so that all new figures include the buttons. An example of how to do this is included in the download.

Written in R2007b, but should work for the most recent versions of MATLAB.

Example usage:
Enter the following commands at the MATLAB prompt:
>> figure
>> fv.vertices = [-1 0; 0 1; 1 0; 0 -1];
>> fv.faces = [1 2 3 4];
>> fv.facevertexcdata = [0 1 0];
>> patch(fv,'FaceColor','flat')
>> fv.vertices = [-1 -1;-1 1;1 1;1 -1]./sqrt(2);
>> fv.facevertexcdata = [1 0 0];
>> AddReorderButtons

You should have a plot with two overlapping squares, one red and one green. Select the "Edit Plot" tool, and click on the square on top. Press the "Move Current Plot Object Backward" tool to see the reorder buttons in action.

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (9)
28 Dec 2007 M.Tauha Ali  
30 Dec 2007 V P

Two good things in this submission:

1. It matches one of my remarks to recent "Drag patch demo" of Josef Kirk.
2. A good demo how to append an UIPUSHBUTTON to toolbar.

I have two small remarks.

1. Do your CData for uipushtool really need such a heavy definition? I have a simple program MAKEICON which makes a 20*20 truecolor matrix out of an rgb image. However, if I submit it, I am afraid to be accused of primitivism or ignorance of last ML developments.

2. It seems that in your code

'Separator', 'off', ...
'TooltipString', 'Move Current Plot Object Backward'

'on' would more consistent.

Otherwise, good job.

31 Dec 2007 Geoffrey Adams

Hi V P,
You are probably correct about the icon definitions. I just wanted to avoid having to include separate files for the icons. If you prefer to make your own icons, it should be pretty straightforward to replace the code in the FORWARD_CDATA and BACKWARD_CDATA functions in AddReorderButtons.m with code like:

img = imread('your_icon.bmp');
c = double(img)./255;

As for your second point, the standard MATLAB figure toolbar (as with most programs' toolbars) uses separators only to delineate groups of functionally similar buttons. Since the "forward" and "backward" buttons form a functional group, I felt it would be more in accordance with standard MATLAB GUI style not to place a separator between the two buttons. Of course, you are free to change this to your own preference.

31 Dec 2007 V P

Hi, Geoffrey,
Happy New Year to you!

Say,
my_icon.bmp has size 100*100.
Now if i do

img = imread('my_icon.bmp');
c = double(img)./255;

and if I use c as my CData, will it have size 20*20? I find, size 100*100 for an icon is too luxury.

About icon group: your two icons are so similar, that in the absense of aNY separator a not very experienced eye could accept both icons as one "extended" button. Were the icons not that similar, the reasoning about icon groups could win. But, you know, this was only my first impression.
best,
Vassili

01 Jan 2008 V P

I confirm my fears that CData for uipushtool ARE NOT resized automatically. If I use as CData some image from a file, and look what is the size of CData in the icon, like:

h=uipushtool(tb(1), ...
               'Tag', 'MoveBackwardTool', ...
               'HandleVisibility', 'off', ...
               'Separator', 'on', ...
               'TooltipString', 'Move Current Plot Object Backward', ...
               'CData', backward_cdata, ...
               'ClickedCallback', @MoveObjBackward);
end

d=get(h,'CData')
size(d)
......
function c = backward_cdata
c=imread('iconx.jpg'); %big green X at red %background
return

then I see
size(d)=[800 1200 3]

It is not excluded that in later versions of ML this point was corrected (I have R14). Was it?

02 Jan 2008 Geoffrey Adams

Hello again, Vassili.

As of R2007b, the help documentation on the CData property of uipushtool objects states:

"If your CData array is larger than 16 in the first or second dimension, it may be clipped or cause other undesirable effects. If the array is clipped, only the center 16-by-16 part of the array is used."

Therefore it seems that the "official" behavior for oversized icons is clipping rather than scaling. If you wish to use larger icons and scale them down to size, it seems you will have to do it manually. If you have access to the Image Processing Toolbox, you could use the IMRESIZE function, but this would create additional computational overhead every time you want to add these buttons to a figure. I would suggest rescaling your icons ahead of time in an image manipulation program like the GIMP or Photoshop, and just saving small versions of them for use in your program.

Good luck.

06 Jan 2008 V P

>>just saving small versions of them for use in your program.

Thanks, Jeoffrey, that's exactly what I currently do.

07 Jan 2008 V P

Geoffrey, please, sorry for misprint.

21 Jan 2008 zhang hongx

Could you give an exact examplt,please?I try the function,but the effect of the buttons.I'm sorry to disturb you! Thank a lot!

Please login to add a comment or rating.
Updates
24 Jan 2008

Added example usage to description.

Tag Activity for this File
Tag Applied By Date/Time
annotation Geoffrey Adams 22 Oct 2008 09:40:37
customization Geoffrey Adams 22 Oct 2008 09:40:37
plot Geoffrey Adams 22 Oct 2008 09:40:37
order Geoffrey Adams 22 Oct 2008 09:40:37
button Geoffrey Adams 22 Oct 2008 09:40:37
toolbar Geoffrey Adams 22 Oct 2008 09:40:37
reorder Geoffrey Adams 22 Oct 2008 09:40:37
order Danilo Zanatta 03 Aug 2009 04:26:09
plot Danilo Zanatta 03 Aug 2009 04:26:13

Contact us at files@mathworks.com