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

  1. function cinvert(object)
  2. %CINVERT Invert black and white objects for nice printer output.
  3. %    CINVERT is an M-file that will recursively change the color
  4. %    properties of the given object, or the current Figure window by 
  5. %    default, and its children to give proper black on white hardcopy 
  6. %    output.
  7. %
  8. %    When printing on white paper it looks nicer, and uses less
  9. %    ink/toner, to plot MATLAB graphics on a white background; instead
  10. %    of the default black background used on screen. Since the background
  11. %    changes, some children of the Figure also need to be inverted
  12. %    to stay visible. Non black or white objects will not have their
  13. %    colors changed. 
  14. %
  15. %    See value of 'params' in this M-file for list of what properties 
  16. %    of the different object types are to be inverted.
  17. %
  18. %    See also PRINT.
  19.  
  20. %       Copyright (c) 1984-93 by The MathWorks, Inc.
  21.  
  22.  
  23. %
  24. %assume current figure if no input given
  25. %
  26. if (nargin == 0)
  27.     object = gcf;
  28. end
  29.  
  30. %
  31. %properties of current object that maintain color information
  32. %
  33. if strcmp(get(object,'type'), 'axes')
  34.     %color of each axis may need to change
  35.     params = [ ['Color ']' ['XColor']' ['YColor']' ['ZColor']'];
  36.  
  37.     %setting axis color affects a corrosponding label, 
  38.     %need to put text color back to the way it was
  39.     axisLabels = [get(object,'xlabel') get(object,'ylabel') ...
  40.                   get(object,'zlabel') get(object,'title') ];
  41.     tc = [];
  42.     for whichLabel = axisLabels
  43.         tc = [ tc ; get(whichLabel, 'color') ];
  44.     end
  45.  
  46. elseif strcmp(get(object, 'type'), 'uicontrol')
  47.     params = [ ['BackgroundColor']' ['ForegroundColor']' ];
  48.  
  49. elseif strcmp(get(object, 'type'), 'surface')
  50.     %mesh plots have flat face colors that match background
  51.     c = get(object,'FaceColor');
  52.     if (1 == size(c,1)) & (3 == size(c,2)) 
  53.         params = [ ['FaceColor']' ['EdgeColor']' ];
  54.     else
  55.         params = [] ;
  56.     end
  57.  
  58. elseif strcmp(get(object, 'type'), 'patch')
  59.     params = [ ['FaceColor']' ['EdgeColor']' ];
  60.  
  61. elseif strcmp(get(object, 'type'), 'image')     ...
  62.     | strcmp(get(object, 'type'), 'uicontrol')  ...
  63.     | strcmp(get(object, 'type'), 'uimenu')
  64.     %there are no parameters to modify when inverting
  65.     params = [];
  66.  
  67. else
  68.     params = ['Color']';
  69. end
  70.  
  71. %
  72. %for looping on a matrix sets p to one column at a time
  73. %
  74. for p = params
  75.     p = p';
  76.     c = get(object, p);
  77.     if ~isstr(c)
  78.         if 3 == sum(c == [1 1 1]) %white
  79.             set(object, p, 'black');
  80.         elseif 3 == sum(c == [0 0 0]) %black
  81.             set(object, p, 'white');
  82.         end
  83.     end
  84. end
  85.  
  86. if strcmp(get(object,'type'), 'axes') & ~isempty(axisLabels)
  87.     % need to put text color back
  88.     for l = 1:length(axisLabels)
  89.         set( axisLabels(l), 'color', tc(l,:) );
  90.     end
  91. end
  92.  
  93. %
  94. %recursion ends when no more kids
  95. %need to change color of text objects used for axis labels
  96. %
  97. kids = get(object, 'Children')';
  98. if  strcmp(get(object,'type'), 'axes')
  99.     kids = [ kids get(object,'xlabel') get(object,'ylabel') ...
  100.         get(object,'zlabel') get(object,'title') ];
  101. end
  102. for obj = kids
  103.     cinvert(obj)
  104. end
  105.  
  106.  
  107.