%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Pie Color Wheel for the NeWS toolkit % Version 3.0.0 % % Copyright (C) 1991, by Don Hopkins. All rights reserved. % This program is provided for unrestricted use, provided that this % copyright message is preserved. There is no warranty, and no author % or distributer accepts responsibility for any damage caused by this % program. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This code and the ideas behind it were developed over time by Don Hopkins % at the University of Maryland, UniPress Software, and Sun Microsystems. % Pie menus and tab windows and NOT patented or restricted, and the % interface and algorithms may be freely copied and improved upon. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% openwinversion 0 get 51 eq { % XXX: V3 /NeWS 3 0 findpackage beginpackage /TNTCore 3 0 findpackage beginpackage /TNT 3 0 findpackage dup beginpackage dup beginautoload begin } { % XXX: V2 systemdict begin } ifelse %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% /ClassPieColorWheel ClassPieMenu dictbegin /Hue 1 def /Saturation 1 def /Brightness 1 def dictend classbegin /InactiveRadius 1 def /RadiusMin 80 def /RimRadius .96 def /GrayRadius .78 def /InitialAngle 0 def openwinversion 0 get 51 eq { % XXX: V3 /ColorWheel (tnt/win/ColorWheel.im24) readcanvas def /GrayWheel (tnt/win/GrayWheel.im24) readcanvas def } { /ColorWheel (tnt/win/ColorWheel.im8) readcanvas def /GrayWheel (tnt/win/GrayWheel.im8) readcanvas def } ifelse /NewInit { /NewInit super send /Cursor 58 77 /ZapfDingbats findfont [40 0 0 40 -16 -16] makefont newcursor def [ (Red)(Green)(Blue) ] /setitemlist self send } def /TwistBrightness { % angle => 0..1 135 add dup 360 gt { 360 sub } if dup 180 gt { 360 exch sub } if 0 max 180 min 180 div 1.2 mul .1 sub 0 max 1 min } def /PaintFrame { % - => - gsave Radius neg dup translate /size self send scale gsave newpath .5 .5 RimRadius .5 mul 0 360 arc closepath gsave 0 0 1 1 rectpath eoclip .5 .5 translate -45 rotate -.5 -.5 translate GrayWheel imagecanvas grestore .5 .5 GrayRadius .5 mul 0 360 arc closepath eoclip .5 .5 translate 135 rotate -.5 -.5 translate GrayWheel imagecanvas grestore newpath .5 .5 GrayRadius .5 mul 0 360 arc closepath clip .5 .5 translate GrayRadius dup scale 1.01 1.01 scale -.5 -.5 translate [Brightness /mul load] cvx settransfer ColorWheel imagecanvas grestore } def /PaintItems { % - => - } def /PaintSlice { % draw key => - pop pop } def /PieStart { % event => - /PieStart super send Cursor grabcursor } def /PieStop { % event => - /PieStop super send null grabcursor } def /PieCancel { % event => - /PieCancel super send null grabcursor } def /OverlayPreview { % - => - Overlay setcanvas erasepage CurrentValue null ne { ItemList CurrentValue get begin /DisplayItem load XOffset YOffset DX 16 mul DY 16 mul Angle end /location self send Radius dup xyadd translate 0 0 moveto 0 0 Radius GrayRadius mul 4 -1 roll SliceWidth .5 mul sub dup SliceWidth add arc closepath 0 0 InactiveRadius 0 360 arc closepath stroke currentcursorlocation xyadd moveto DisplayItemPaint } if } def /hsb2rgb { % h s b => r g b gsave ColorWheel setcanvas sethsbcolor currentrgbcolor grestore } def /setpiecolor { % color => - gsave ColorWheel setcanvas setcolor currenthsbcolor grestore /Brightness exch def /Saturation exch def /Hue exch def } def /piecolor { % - => color Hue Saturation Brightness hsbcolor } def /SetCurrentValue { % dx dy => - /SetCurrentValue super send Distance GrayRadius Radius mul le { /Hue Direction 360 div def /Saturation Distance Radius GrayRadius mul div 1.3 mul .2 sub 0 max 1 min 1 exch sub def } { /Hue 0 def /Saturation 0 def Direction TwistBrightness /Brightness exch def /damage self send } ifelse Cursor /CursorColor /piecolor self send put Cursor /MaskColor Brightness .5 lt { 1 } { 0 } ifelse dup dup rgbcolor put } def /NotifyItem { % index => - pop Hue Saturation Brightness hsbcolor /Notifier load % color proc /ExecuteNotifier self send % - } def /PreviewItem { % index => - pop Hue Saturation Brightness hsbcolor /Previewer load % color proc /ExecuteNotifier self send % - } def /demo { userdict begin /pie framebuffer /new ClassPieColorWheel send def { { (Hue:% Sat:% Bri:%) [ 2 index colorhsb 3 { 3 -1 roll 255 mul cvi } repeat ] sprintf (Red:% Green:% Blue:%) [ 3 index colorrgb 3 { 3 -1 roll 255 mul cvi } repeat ] sprintf /setfooter Parent send ForegroundColor exch /setcolors self send } /sendtarget 3 -1 roll send } /setpreviewer pie send /can framebuffer /new ClassPieMenuCanvas send def /preferredsize { 256 256 } /promote can send pie /setpiemenu can send /win can framebuffer /new ClassBaseWindow send def (Color Pie Menu Demo) /setlabel win send /mgr /new ClassEventMgr send def mgr /activate win send /place win send /map win send end % userdict } def classend def %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% openwinversion 0 get 51 eq { % XXX: V3 currentdict endautoload end % TNT endpackage endpackage endpackage } { % XXX: V2 end % systemdict } ifelse %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%