%
% 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
%
%	@(#)nxlogo 23.2 90/06/19
%
% X logo window for NeWS
% Based on Danny Chong's X logo

% ===== ClassXLogo class =====

/ClassXLogo [] []
classbegin

    % thicknesses of ...
    /t0 1 4 div def			% thick stroke of logo
    /t1 1 11 div def			% thin stroke of logo
    /t2 t1 4 div def			% stripe between logo halves
    /t3 t1 dup add t2 add def		% thin strokes plus stripe

    /h0 t0 2 div def			% t0 for inner region
    /h1 t1 2 div def			% t1 for inner region

    % slopes
    /m1 1 t3 sub 1 exch div def		% upward-sloping line
    /m2 t0 1 sub 1 exch div def		% downward-sloping line

    % Find the intersection of two lines, using slopes m1 and m2,
    % The upward-sloping line intersects the bottom of the logo
    % (the y=0 line) at x1; the downward-sloping line intersects
    % the top of the logo (the y=1 line) at x2.
    /intersect {			% x1 x2 => X Y
	5 dict begin
	    /x2 exch def
	    /x1 exch def
	    m1 x1 mul m2 x2 mul sub 1 add   % numerator
	    m1 m2 sub			    % denominator
	    div				    % X
	    dup x1 sub m1 mul		    % X Y
	end
    } def

    %    t0
    %  _______
    %  \      \
    %   \      \
    %    \      \
    %     \      \
    %      \     /
    %       \   /
    %       /  /
    %      /  /
    %     /  /
    %    /  /
    %   /  /
    %  /__/
    %   t1
    %
    % Adds half of the X logo to the current path.
    /halflogo {
	0	0			moveto
	t1	0			lineto
	t1	t0	intersect	lineto
	t0	1			lineto
	0	1			lineto
	0	0	intersect	lineto
	closepath
    } def

    %
    % Adds a unit square X logo to the path.
    %
    /xlogo {
	halflogo
	1 1 translate -1 -1 scale
	halflogo
    } def

    % adds half a path for highlighting the X logo to the current path
    /halfhighlight { % inset => -
	h1 1 index sub	0				moveto
	h1 1 index add	0				lineto
	h1 1 index add	h0 2 index add	intersect	lineto
	h0 1 index add	1				lineto
	h0 1 index sub	1				lineto
	h1 1 index sub	h0 2 index sub	intersect	lineto
	closepath
    } def

    %
    % Adds a unit square X highlight to the path.
    %
    /xhighlight {
	halfhighlight
	1 1 translate -1 -1 scale
	halfhighlight
    } def

classend def

% ===== XLogoFrame class =====

/XLogoFrame [ClassXLogo OpenLookFrame] []
classbegin

    % frame ornaments
    /Close	    	false def
    /Footer		false def
    /Label		false def
    /Pin		false def
    /Reshape		false def

    /StrokeColor	0.3 0.3 0.3 rgbcolor	def

    % cursor image
    /CursorImage	/xcurs		def
    /CursorMask		/xcurs_m	def

    /path { % x y w h => -
	matrix currentmatrix 5 1 roll
	    4 2 roll translate scale
	    xlogo
	setmatrix
    } def

    /minsize { % - => w h
	/minsize super send
	32 max exch
	32 max exch
    } def

    /preferredsize { % - => w h
	/preferredsize super send
	256 max exch
	256 max exch
    } def

    % x y w h => - (set path)
    /StrokeCanvas { % color inset => -
	gsave
	    exch setcolor
	    /size self send
	    1 index 0 ne {
		2 copy scale
		min div 2 mul setlinewidth
		1 setlinejoin
		xlogo
		stroke
	    } {pop pop pop} ifelse
	grestore
    } def

classend def

% ===== XLogoBaseFrame class =====

/XLogoBaseFrame [XLogoFrame OpenLookBaseFrame] []
classbegin

    /Reshape	    	true def

    /FillColor		0 0 0 rgbcolor		def
    /SelStroke	    	8 def
    /UnSelStroke	4 def

    /IconFrameClass	{XLogoIconFrame} def

    /ReshapeCreate { % - => -
	/Reshape
	[{/ReshapeNotify /parent self send send} XLogoCorners]
	/addclient self send
    } def

classend def

% ===== XLogoIconFrame class =====

/XLogoIconFrame [XLogoFrame OpenLookIconFrame] []
classbegin

    /FillColor		0 0 0 rgbcolor		def
    /SelStroke	    	4 def
    /UnSelStroke	2 def

    /preferredsize { % - => w h
	64 64
    } def
classend def

% ===== XLogoCorners class =====

/XLogoCorners [ClassXLogo OpenLookFrameCorners] []
classbegin

    /StrokeColor	0 0 0 rgbcolor	def
    /minsize		{1 1}		def

    /Corner { % dx dy x y => -
    	2 copy 4 index add moveto
	2 copy lineto
	exch 3 index add exch lineto
	pop pop
    } def

    /Corners { % x y w h legsize => -
	2 index 0 ne 2 index 0 ne and {
	    2 mul
	    newpath matrix currentmatrix 6 1 roll
	    dup 3 index div exch 2 index div	% x y w h legwidth legheight
	    6 4 roll translate 4 2 roll scale	% legwidth legheight
	    1 index 0 moveto 0 0 lineto 0 1 index lineto closepath
	    1 2 index sub 0 moveto 1 0 lineto 1 1 index lineto closepath
	    1 2 index sub 1 moveto 1 1 lineto 1 1 2 index sub lineto closepath
	    exch 1 moveto 0 1 lineto 0 exch 1 exch sub lineto closepath
	    setmatrix
	} if
    } def

classend def

/xwin null [] framebuffer /new XLogoBaseFrame send def

/place xwin send
/activate xwin send
/map xwin send

newprocessgroup
currentfile closefile
