home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Palettes / MiscCircularSlider / MiscCircularSlider.subproj / MiscCSWraps.psw < prev    next >
Encoding:
Text File  |  1995-07-06  |  7.9 KB  |  188 lines

  1.  
  2. defineps MiscCSDrawBezel(float xx; float yy; float realradius; float width; float grayLevel)
  3.  
  4. % this is straight from yap and needs tweaking/cleaning up.
  5. gsave
  6. xx yy 1 add translate
  7. /radius realradius 2 sub width 2 div sub def
  8. /x realradius 1 add def
  9. /y realradius 2 sub def
  10. /circle { translate x y radius 0 360 arc closepath stroke } def
  11. gsave
  12.     width setlinewidth
  13.     0.333 setgray -2 2 circle 0 1 circle 1 0 circle
  14.     0 setgray 0 -1 circle 0 -1 circle 1 1 circle
  15.     1 setgray 0 -2 circle 1 0 circle 0 1 circle
  16.     grayLevel setgray
  17.     -1 0 circle
  18. grestore
  19. grestore
  20. endps
  21.  
  22. defineps MiscCSDrawKnob(float xx; float yy; float width)
  23.  
  24. % this is straight from yap and needs tweaking/cleaning up.
  25.  
  26. % I changed this to just draw the knob to fit in a square with xx,yy as the orgin,
  27. % and with width as the size.  This way the knob fits neatly into a square NXImage
  28. % which can be placed more accurately.
  29. % The dividing by 2.01 is a slight kludge; when I divided by 2 it would draw a *square*
  30. % knob when width was 10 (the default).  Not a clue why -- I guess some funky
  31. % Postscript thing with whole numbers.
  32. %  -Carl
  33. gsave
  34. xx yy translate
  35. /knobwidth width 4 sub def
  36. /knob { translate newpath knobwidth 2.01 div knobwidth 2.01 div knobwidth 2 div 0 360 arc closepath fill grestore gsave }  def
  37.   gsave
  38.     % Fudge a little - the drawing below goes to the right and
  39.     % down of where I really want, but I didn't want to touch it :-)
  40.     % So, just move a bit to counteract.  -Carl
  41.     -3 3 translate
  42.     0 setgray gsave 7 -2 knob 7 0 knob 5 -2 knob grestore
  43.     0.333 setgray gsave 6 -1 knob 6 0 knob  5 -1 knob grestore
  44.     1 setgray gsave 4 1 knob 4 0 knob 5 1 knob grestore
  45.     0.666 setgray gsave 5 0 knob grestore
  46.   grestore
  47. grestore
  48. endps
  49.  
  50. defineps MiscCSDrawBackground(float center_x; float center_y; float radius; float height; float width)
  51.     gsave
  52.     center_x center_y translate    %% xlate to the center of the circle
  53.     %% if height is greater than the width then scale the y by height / width
  54.     height width gt { 1 height width div scale } if
  55.     %% if height is less than the width then scale the x by width / height
  56.     height width lt { width height div 1 scale } if
  57.     %% Draw the Raised Background
  58.     newpath 1.0 setgray -1.0 1.5 radius 2 add 0 360 arc closepath fill
  59.     newpath 0.0 setgray 1.5 -1 radius 2 add 225 45 arc closepath fill
  60.     newpath 0.3333 setgray 1.5 -0.25 radius 1 add 0 360 arc closepath fill
  61.     grestore
  62. endps
  63.  
  64. defineps MiscCSPieChart(float center_x; float center_y; float radius; float height; float width; float startangle; float finishangle)
  65.     gsave
  66.     center_x center_y translate    %% translate to center of circle
  67.     %% if height is greater than the width then scale the y by height / width
  68.     height width gt { 1 height width div scale } if
  69.     %% if height is less than the width then scale the x by width / height
  70.     height width lt { width height div 1 scale } if
  71.     %% Draw the background of the Circular Slider
  72.     newpath 0.33333 setgray 0 0.5 radius 1 add 0 360 arc closepath fill
  73.     %% Draw the control portion of Circular Slider
  74.     0.5 nxsetgray newpath 0 0 moveto
  75. %%    0 0.5 radius 90 90 angle sub arcn closepath fill
  76.     0 0.5 radius finishangle startangle arcn closepath fill
  77.     %% stroke out an outline
  78. %    0 setgray 2 setlinewidth 0.5 0.5 radius 1 add 0 360 arc
  79. %    matrix defaultmatrix setmatrix    %% create an empty 6x6 element unit matrix
  80.         %% replace the currently created matrix with the default matrix for
  81.         %% the device then sets up that matrix as the CTM.  This is done so
  82.         %% the stroked lines don't get wider because of the scaling
  83.     stroke
  84.     grestore
  85. endps
  86.  
  87. defineps MiscCSPieChartDisabled(float center_x; float center_y; float radius; float height; float width; float startangle; float finishangle)
  88.     gsave
  89.     center_x center_y translate        %% translate to the center of the circle
  90.     %% if height is greater than the width then scale the y by height / width
  91.     height width gt { 1 height width div scale } if
  92.     %% if height is less than the width then scale the x by width / height
  93.     height width lt { width height div 1 scale } if
  94.     %% Draw the background of the Circular Slider
  95.     newpath 0.666 setgray 0.5 0.5 radius 1 add 0 360 arc closepath fill
  96.     %% Draw the control portion of Circular Slider
  97.     0.333 setgray newpath 0 0 moveto
  98. %%    0.5 0.5 radius 90 90 angle sub arcn    closepath fill
  99.     0.5 0.5 radius finishangle startangle arcn    closepath fill
  100.     %% stroke out an outline
  101.     0 setgray 0.5 setlinewidth
  102.     newpath 0.5 0.5 radius 1 add 0 360 arc closepath
  103.     matrix defaultmatrix setmatrix    %% create an empty 6x6 element unit matrix
  104.         %% replace the currently created matrix with the default matrix for
  105.         %% the device then sets up that matrix as the CTM.  This is done so
  106.         %% the stroked lines don't get wider because of the scaling
  107.     stroke
  108.     grestore
  109. endps
  110.  
  111. defineps MiscCSDrawShuttleKnob(float center_x; float center_y; float realradius; float width; float angle)
  112.  
  113. % Added by Laurent Daudelin to get knob width adjustment.
  114.  
  115. % Modified by Carl Lindberg to find knob center based on
  116. %  the circle's center, radius, and width, instead of however
  117. %  it was done before using xx and yy.  (It assumed the origin
  118. %  was at 0,0 which was not the case if borders are used.)
  119.  
  120. gsave
  121. center_x center_y translate        %% translate to the center of the circle
  122. %% Draw the Control Portion of the Circular Slider2
  123. newpath 0.6666 nxsetgray 0.5 0.5 realradius 3 sub 0 360 arc    closepath fill
  124. grestore
  125. gsave
  126. /radius realradius 2 sub width 2 div sub 0.90 mul def
  127. /x realradius 1 add def
  128. /y realradius 2 sub def
  129. /knobwidth width 4 sub def
  130. /knob { translate knobwidth knobwidth scale newpath 0.5 0.5 0.5 0 360 arc closepath fill grestore gsave } def
  131.   gsave
  132.       center_x center_y translate
  133.     width 2 div neg  3 sub width 2 div neg 3 add translate
  134.     angle cos radius mul
  135.     angle sin radius mul translate
  136.     1 setgray gsave 7 -2 knob 7 0 knob 5 -2 knob grestore
  137.     0.333 setgray gsave 4 1 knob 4 0 knob 5 1 knob grestore
  138.     0 setgray gsave 6 -1 knob 6 0 knob  5 -1 knob grestore
  139.     0.666 setgray gsave 6 -1 knob grestore
  140.   grestore
  141. grestore
  142. endps
  143.  
  144. defineps MiscCSControlKnob(float center_x; float center_y; float radius; float height; float width; float angle)
  145.     gsave
  146.     center_x center_y translate        %% translate to the center of the circle
  147.     %% if height is greater than the width then scale the y by height / width
  148.     height width gt { 1 height width div scale } if
  149.     %% if height is less than the width then scale the x by width / height
  150.     height width lt { width height div 1 scale } if
  151.     %% Draw the Control Portion of the Circular Slider2
  152.     newpath 0.6666 nxsetgray 0.5 0.5 radius 1 add 0 360 arc    closepath fill
  153.     %% Draw the Knob
  154.     /rs radius radius 8 mul 100 div sub 2 sub def
  155.     rs angle cos mul 2 sub % xpos
  156.     rs angle sin mul 2 sub % ypos
  157.     translate 6 6 2 [1 0 0 -1 0 6] <9020455016a01af01bf09be0> image
  158.     grestore
  159. endps
  160.  
  161. defineps MiscCSControlKnobDisabled(float center_x; float center_y; float radius; float height; float width)
  162.     gsave
  163.     center_x center_y translate %% translate to the center of circle
  164.     %% if height is greater than the width then scale the y by height / width
  165.     height width gt { 1 height width div scale } if
  166.     %% if height is less than the width then scale the x by width / height
  167.     height width lt { width height div 1 scale } if
  168.     %% Draw the Control Portion of the Circular Slider2
  169.     newpath 0.6666 nxsetgray 0.5 0.5 radius 1 add 0 360 arc closepath fill
  170.     grestore
  171. endps
  172.  
  173. defineps MiscCSControlDial(float center_x; float center_y; float radius; float height; float width; float angle; float grayLevel)
  174.     gsave
  175.     center_x center_y translate %% translate to the center of circle
  176.     %% if height is greater than the width then scale the y by height / width
  177.     height width gt { 1 height width div scale } if
  178.     %% if height is less than the width then scale the x by width / height
  179.     height width lt { width height div 1 scale } if
  180.     %% Draw the Control Portion of the Circular Slider2
  181.     newpath 0.6666 nxsetgray 0.5 0.5 radius 1 add 0 360 arc closepath fill
  182.     %% Draw the "Knob" (line segment) 1/3 of way from center to outside
  183.     grayLevel setgray radius 25 div setlinewidth
  184.     /r2 radius 3 div def /ac angle cos def /as angle sin def
  185.     radius ac mul radius as mul moveto r2 ac mul r2 as mul lineto stroke
  186.     grestore
  187. endps
  188.