home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / LANG.DI$ / MENU.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  2.7 KB  |  104 lines

  1. function k = menu(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,...
  2.             s17,s18,s19,s20,s21,s22,s23,s24,s25,s26,s27,s28,s29,s30,s31,s32);
  3. %MENU    Generate a menu of choices for user input.
  4. %    K = MENU('Choose a color','Red','Blue','Green') displays on
  5. %    the screen:
  6. %
  7. %    ----- Choose a color -----
  8. %
  9. %       1) Red
  10. %       2) Blue
  11. %       3) Green
  12. %
  13. %       Select a menu number: 
  14. %
  15. %    The number entered by the user in response to the prompt is
  16. %    returned.  On machines that support it, the local menu system
  17. %    is used.  The maximum number of menu items is 32.
  18.  
  19. %    J.N. Little 4-21-87, revised 4-13-92 by LS.
  20. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  21.  
  22. c = computer;
  23. display = 1;
  24. PC = strcmp(c(1:2),'PC');
  25. if ~strcmp(c(1:2),'PC') & ~strcmp(c(1:2),'MA')
  26. % might be unix or VMS
  27.     if isunix
  28.         display = length(getenv('DISPLAY')) > 0;
  29.     else
  30.         display = length(getenv('DECW$DISPLAY')) > 0;
  31.     end
  32. end
  33. if ~display
  34.     disp(' ')
  35.     disp(['----- ',s0,' -----'])
  36.     disp(' ')
  37.     for i=1:(nargin-1)
  38.         disp(['      ',int2str(i),') ',eval(['s',int2str(i)])])
  39.     end
  40.     disp(' ')
  41.     k = input('Select a menu number: ');
  42.     return
  43. end
  44.  
  45. kids = get(0,'Children');
  46. if ~isempty(kids)
  47.     otherfig = gcf;
  48.     M=get(otherfig,'Colormap');
  49. else
  50.     M=get(0,'DefaultFigureColormap');
  51. end
  52. global MENU_VARIABLE;
  53. MENU_VARIABLE = 0;
  54. xedge = 30;
  55. yedge = 35;
  56. ybord = 30;
  57. width = 30;
  58. avwidth = 7; % actually 6.8886 +/- 0.4887
  59. height = 30;
  60. imax = 1;
  61. maxlen = length(s0);
  62. for i = 1:nargin-1
  63.     mx = length(eval(['s',int2str(i)]));
  64.     if mx > maxlen
  65.        maxlen = mx;
  66.        imax = i;
  67.     end
  68. end
  69. twidth = 1.2*maxlen*avwidth;
  70. % now figure out total dimensions needed so things can get placed in pixels
  71. mwwidth = twidth + width + 2*xedge;
  72. mwheight = (nargin+1)*yedge;
  73. ss = get(0,'ScreenSize');
  74. swidth = ss(3); sheight = ss(4);
  75. %left = (swidth-mwwidth)/2;
  76. left = 20;
  77. bottom = sheight-mwheight-ybord;
  78. rect = [left bottom mwwidth mwheight];
  79. fig = figure('Position',rect,'number','off','name',' ','resize','off','Colormap',M);
  80. set(gca,'Position',[0 0 1 1]); axis off;
  81. % Place title
  82. t = text(mwwidth/2,mwheight-yedge/2,s0,'Horizontal','center','Vertical','top','units','pixels');
  83. set(t,'Color','white');
  84. for ii=(nargin-1):-1:1
  85.     i = nargin - ii;
  86.     h1 = uicontrol('position',[xedge  (i-.5)*yedge width+twidth height]);
  87.     set(h1,'callback',['global MENU_VARIABLE,MENU_VARIABLE = ',int2str(ii),';']);
  88.     set(h1,'string',['  ', eval(['s',int2str(ii)])])
  89.     set(h1,'HorizontalAlignment','left');
  90. % left justify string inside button
  91. end
  92. while MENU_VARIABLE == 0
  93.     if PC
  94.         waitforbuttonpress;
  95.     else
  96.         drawnow;
  97.     end
  98. end
  99. k = MENU_VARIABLE;
  100. delete(fig)
  101. if ~isempty(kids)
  102.     set(0,'CurrentFigure',otherfig);
  103. end
  104.