%
% This file is a product of Sun Microsystems, Inc. and is provided for
% unrestricted use provided that this legend is included on all tape
% media and as a part of the software program in whole or part.  Users
% may copy or modify this file without charge, but are not authorized to
% license or distribute it to anyone else except as part of a product
% or program developed by the user.
%
% THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
% WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
% PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
%
% This file is provided with no support and without any obligation on the
% part of Sun Microsystems, Inc. to assist in its use, correction,
% modification or enhancement.
%
% SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
% INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS FILE
% OR ANY PART THEREOF.
%
% In no event will Sun Microsystems, Inc. be liable for any lost revenue
% or profits or other special, indirect and consequential damages, even
% if Sun has been advised of the possibility of such damages.
%
% Sun Microsystems, Inc.
% 2550 Garcia Avenue
% Mountain View, California  94043
%
%
% @(#)flyinglogos 23.4 90/06/19
%
% Copyright (c) 1989 by Sun Microsystems, Inc.
%

/ClassLogoFrame /defaultclass ClassBaseFrame send []
classbegin
    /open { % bool => -
	% only flip the parent of the client if the open state
	% is really changing.
	dup /opened? self send ne {
	    dup dup {
		null /setclient /Icon /sendsubframe self send
		dup /setclient self send pop
		/validate self send
	    } {
		null /setclient self send
		dup /setclient /Icon /sendsubframe self send pop
		/validate /Icon /sendsubframe self send
	    } ifelse		    % open? open? client
	    /open exch send
	} if
	/open super send
    } def
classend def

/ClassLogoWindow ClassCanvas dictbegin

    % Instance Variables

    /PaintElement       null    def
    /LogoStart          null    def
    /LogoEnd            null    def
    /LogoDelta          null    def
    /LogoCurrent        null    def
    /LogoCanvas         null    def
    /LogoMonitor        null    def
    /LogoChanged?	false	def
    /NSteps             10      def
    /Step               0       def
    /StepDelta          1       def
    /StepProcess        null    def

dictend
classbegin

    % Private Methods

    /PaintCanvas {
	LogoMonitor { LogoCanvas imagecanvas } monitor
    } def

    /CreateLogoCanvas { % - => -
	LogoMonitor {
	    gsave
		framebuffer setcanvas
		/size self send				% w h
		Canvas setcanvas
		monochromecanvas {1} {8} ifelse		% w h d
		matrix currentmatrix			% w h d []
		null					% w h d [] proc
		buildimage				% cv
		/LogoCanvas exch def
		/PaintLogo self send
	    grestore
	} monitor
    } def

    /PaintLogo {
	LogoMonitor {
	    LogoCanvas setcanvas
	    FillColor setcolor clippath fill
	    LogoCurrent null ne {
		TextColor setcolor
		LogoCurrent /PaintElement load forall
	    } if
	} monitor
    } def

    /NewDelta { % - => -
	LogoEnd LogoStart
	2 copy null ne exch null ne and
	{ {{sub NSteps div} arrayop} arrayop LogoStart }
	{ pop pop null null }
	ifelse
	/LogoCurrent exch store
	/LogoChanged? true def
	/LogoDelta   exch store
    } def

    /minsize {  % - => minwidth minheight
	/minsize super send
	12 4 mul max exch
	18 4 mul max exch % 18 x 12 aspect ratio (see /reshape)
    } def

    /preferredsize { % - => w h
	/preferredsize super send
	12 25 mul max exch
	18 25 mul max exch % 18 x 12 aspect ratio (see /reshape)
    } def

    /CreateMenu { % - => -
	/CanvasMenu
	    [
		(Step once)     null    /EventStep self soften buildsend
		(Step to end)   null    /EventStepToEnd self soften buildsend
	    ] framebuffer /newdefault ClassMenu send
	    true /setpinnable 2 index send
	    (Logos) /setlabel 2 index send
	def
    } def

    /MakeInterests {
	/MakeInterests super send

	Canvas soften /DownTransition
	2 dict dup begin
	    /LeftMouseButton     /EventStep self soften buildsend def
	    /MiddleMouseButton   /EventStepToEnd self soften buildsend def
	end
	/new ClassInterest send
	    dup /Synchronous true put
	    dup /Exclusivity true put
    } def

    /EventStep { % event|canvas => -
	dup type /canvastype eq {pop} {eatupevent} ifelse
	/StepProcess {
	    /step self send
	    /StepProcess null def
	} refork
    } def

    /EventStepToEnd { % event|canvas => -
	dup type /canvastype eq {pop} {eatupevent} ifelse
	/StepProcess {
	    /steptoend self send
	    /StepProcess null def
	} refork
    } def

    % Public methods

    /newinit { % numsteps startarray endarray paintelementproc => canvas
	/newinit super send
	/CreateMenu self send
	/deflogos self send
	/numsteps self send
	/LogoMonitor createmonitor def
    } def

    /open { % bool => -
	not {
	    /deactivate self send
	} if
	LogoChanged? {
	    gsave Canvas setcanvas clippath extenddamage grestore
	} if
	/LogoChanged? false def
    } def

    /destroy { % - => -
	StepProcess null ne {
	    StepProcess killprocess
	    /StepProcess null def
	} if
	/destroy super send
    } def

    /deflogos { % startarray endarray paintelementproc => -
	/PaintElement exch store
	/LogoEnd exch store
	/LogoStart exch store
	/NewDelta self send
	LogoCanvas null ne {/PaintLogo self send} if
    } def

    /numsteps { % num => -
	Step NSteps div exch            % ratio num
	/NSteps 1 index store           % ratio num
	mul floor                       % newStep
	/NewDelta self send             % newStep
	/setstep self send              % -
    } def

    /setstep { % num => -
	dup NSteps gt {pop NSteps} if
	dup 0 lt {pop 0} if
	dup Step eq {
	    pop
	} {
	    /Step 1 index store
	    NSteps eq {
		LogoEnd
	    } {
		LogoStart LogoDelta
		{{Step mul add} arrayop} arrayop
	    } ifelse
	    /LogoCurrent exch store
	    /LogoChanged? true def
	    /paintlogo self send
	} ifelse
    } def

    /atend? {   % - => bool
	Step NSteps eq Step 0 eq or
    } def

    /step { % - => -
	Step StepDelta add
	/setstep self send
	/atend? self send { /reverse self send } if
    } def

    /steptoend { % - => -
	{
	    /step self send pause
	    /atend? self send {exit} if
	} loop
    } def

    /reverse { % - => -
	/StepDelta StepDelta neg def
    } def

    /paintlogo { % - => -
	/PaintLogo self send
	/paint self send
    } def

    /reshape {
	/reshape super send
	Canvas null ne {
	    gsave
	    Canvas setcanvas
	    clippath pathbbox
	    12 div exch 18 div exch scale
	    pop pop 2 2 translate
	    Canvas reshapecanvas
	    /CreateLogoCanvas self send
	    grestore
	} if
    } def

classend def

/Urad   .1      def
/URad   .9      def
/Ulen   2.9     def
/UcharFromArray { % [sx sy ang x y] => -
    gsave
	aload pop
	translate
	rotate
	scale
	newpath
	//Urad //Ulen moveto
	0 0 .1 0 180 arcn
	0 //Ulen rlineto
	//URad neg //Ulen lineto
	0 0 //URad 180 360 arc
	0 //Ulen rlineto
	closepath
	fill
    grestore
    pause
} def

/NeWSLogo [
	% scale rotation        translation
	[ -1 1  180             0       5.2 ]
	[ -1 1  0               2       3.2 ]
	[ 1 1   270             4       5.2 ]
	[ 1 1   -90             4       3.2 ]
	[ 1 1   0               8       3.2 ]
	[ 1 1   0               10      3.2 ]
	[ 1 1   270             12      5.2 ]
	[ 1 1   90              14      3.2 ]
] def

/SunLogo [
	% scale rotation        translation
	[ 1 1   135             5.6     4.2 ]
	[ 1 1   -45             2.8     4.2 ]
	[ 1 1   225             7       8.4 ]
	[ 1 1   45              7       5.6 ]
	[ 1 1   45              7       0   ]
	[ 1 1   -135            7       2.8 ]
	[ 1 1   315             8.4     4.2 ]
	[ 1 1   135             11.2    4.2 ]
] def

/win [11 SunLogo NeWSLogo /UcharFromArray load ClassLogoWindow]
    [] framebuffer /new ClassLogoFrame send
def

(Flying Logos) /setlabel win send
null /seticonlabel win send

/place win send
/activate win send
/map win send

newprocessgroup
currentfile closefile
