-- TAShadowImpl.mesa
-- Rick Beach, June 30, 1982 11:51 pm
--Maureen Stone April 25, 1983 5:12 pm
-- Rick Beach, November 29, 1982 10:07 pm

DIRECTORY
 NodeStyle USING [GetPathType, Ref],
 RealFns USING [SinDeg, CosDeg],
 TextNode USING [Ref],
 TAPrivate,
 TAStyle,
 TAShadow;

TAShadowImpl: PROGRAM
 IMPORTS NodeStyle, RealFns, TAPrivate, TAStyle
 EXPORTS TAShadow = {

EstablishShadow: PUBLIC PROCEDURE[node: TextNode.Ref, nodeStyle: NodeStyle.Ref] = {
 shadowAngle: REAL ← TAStyle.GetShadowAngle[nodeStyle];
 SELECT TAStyle.GetShadowType[nodeStyle] FROM
  Offset => {
   shadowDistance: REAL ← TAStyle.GetShadowOffsetAmount[nodeStyle];
   xSign, ySign: REAL;
   SELECT TAStyle.GetShadowDirection[nodeStyle] FROM
    UpLeft => {xSign ← -1; ySign ← 1};
    UpRight => {xSign ← 1; ySign ← 1};
    DownLeft => {xSign ← -1; ySign ← -1};
    DownRight => {xSign ← 1; ySign ← -1};
    ENDCASE => {xSign ← 1; ySign ← -1};
   TAPrivate.PushDC[];
   TAPrivate.PushReal[shadowDistance*xSign*RealFns.SinDeg[shadowAngle]];
   TAPrivate.PushReal[shadowDistance*ySign*RealFns.CosDeg[shadowAngle]];
   TAPrivate.Translate[];
   SELECT TAStyle.GetShadowPathType[nodeStyle] FROM
    Filled, FilledAndOutlined => {
     TAPrivate.SetHSV[TAStyle.GetShadowAreaHue[nodeStyle], TAStyle.GetShadowAreaSaturation[nodeStyle], TAStyle.GetShadowAreaBrightness[nodeStyle]];
     TAPrivate.ExecuteNode[node];
     TAPrivate.DrawArea[];
     };
    ENDCASE;
   SELECT TAStyle.GetShadowPathType[nodeStyle] FROM
    Outlined, FilledAndOutlined => {
     TAPrivate.SetHSV[TAStyle.GetShadowOutlineHue[nodeStyle], TAStyle.GetShadowOutlineSaturation[nodeStyle], TAStyle.GetShadowOutlineBrightness[nodeStyle]];
     TAPrivate.ExecuteNode[node];
     TAPrivate.PushReal[TAStyle.GetShadowWeight[nodeStyle]];
     --TAPrivate.RoundPen[];
   
  --TAPrivate.ShadowPen[];
     --TAPrivate.ShadowPath[]; some bug makes this not work
     TAPrivate.OutlinePath[];
     };
    ENDCASE;
   
TAPrivate.PopDC[];
  };
  Drop => {
   TAPrivate.SetHSV[TAStyle.GetShadowAreaHue[nodeStyle], TAStyle.GetShadowAreaSaturation[nodeStyle], TAStyle.GetShadowAreaBrightness[nodeStyle]];
   TAPrivate.PushReal[TAStyle.GetShadowWeight[nodeStyle]];
   TAPrivate.PushReal[SELECT TAStyle.GetShadowDirection[nodeStyle] FROM
    UpLeft => 180-shadowAngle,
    UpRight => shadowAngle-180,
    DownLeft => shadowAngle,
    DownRight => -shadowAngle,
    ENDCASE => shadowAngle];
   TAPrivate.ItalicPen[];
   
--TAPrivate.ShadowPen[];
   TAPrivate.ExecuteNode[node];
   --TAPrivate.ShadowPath[];
   TAPrivate.OutlinePath[];
   };
  ENDCASE => NULL;
 IF NodeStyle.GetPathType[nodeStyle]=Outlined THEN {
  TAPrivate.SetHSV[0, 0, 1.0]; -- repaint white background for object
  TAPrivate.ExecuteNode[node];
  TAPrivate.DrawArea[]};
 };


}.