% Example -2-
%
% A simple sample application written for BTOL

/AppFont /Courier findfont def
/AppFontSize    18 def

/changefontsize % dsize => -
{
/AppFontSize AppFontSize 3 -1 roll add 8 max store

AppFont AppFontSize scalefont
/paint win send
} def


/changefont % fontname => -
{
/AppFont exch findfont store
0 changefontsize
} def


/colormenu
[() dup dup dup dup dup dup dup dup dup]
[ {Hue /sethue /getappwin BtolAppWin send send} 9 { dup } repeat ]
/new BtolMenu send
dup /MenuItems get 0 1 9
{ dup 10 div /sethue 3 index 4 -1 roll get send } for pop
def

/sizemenu
    [(Enlarge by 2) (Enlarge by 10) (Reduce by 2) (Reduce by 10)]
[ { 2 changefontsize } { 10 changefontsize } { -2 changefontsize } { -10 changefontsize } ] /new BtolMenu send def

/fontmenu
[
(Courier) (Helvetica) (Times-Roman)
]
[ { ItemLabel changefont } 2 index length 1 sub { dup } repeat ] /new BtolMenu send def

/changefontmenu
[ (Font) (Size) ]
[ fontmenu sizemenu ] /new BtolMenu send def

colormenu
/sethue
{
   /Hue exch def
   /HiLiteColor Hue 0.3 1 hsbcolor def
   /ShadowColor Hue 1 0.45 hsbcolor def
   /FaceColor Hue 0.4 .9 hsbcolor def

   HiLiteFrame
   paint
 }
 put

/mainmenu
[(Window Color) (Change Font) (Hide) (Quit)]
[
    colormenu
    changefontmenu
    { /flipiconic /getappwin BtolAppWin send send }
    { /ZapNotify /getappwin BtolAppWin send send }
] /new BtolMenu send def

{
    /FrameLabel (Example #2) def
    AutoSize
} mainmenu send


/win framebuffer /new BtolAppWin send def
{
   CreateCloseControl
   CreateResizeControl
   /FrameMenu mainmenu def
   /FrameLabel (A BTOL window! Example #2) def
   /IconLabel (Example #2) def
   /PaintClient
   {
      gsave
      0 fillcanvas
      0 1 random 100 mul
      {
	 random mul random 144 mul
	 random random random setrgbcolor
	 moveto 240 100 lineto stroke
      } for
      AppFont AppFontSize scalefont setfont
      50 50 moveto (BTOL - it just looks better!) show
      grestore
   } def
   reshapefromuser
   ClientCanvas /Retained true put
   totop
   map
} win send
