home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Snippets / PNL Libraries / MyTriangleCDEF.p < prev    next >
Encoding:
Text File  |  1996-06-01  |  3.9 KB  |  164 lines  |  [TEXT/CWIE]

  1. unit MyTriangleCDEF;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Controls;
  7.         
  8.     function TriangleCDEF (variation: integer; theControl: ControlHandle; msg: integer; param: longint): longint;
  9.  
  10. implementation
  11.  
  12.     uses
  13.         MyTypes;
  14.         
  15.     const
  16.         kInactive = 255;        {    part code indicating the control is inactive        }
  17.  
  18.     function TriangleCDEF (variation: integer; theControl: ControlHandle; msg: integer; param: longint): longint;
  19.         procedure GetRgn (rgn: RgnHandle);
  20.             const
  21.                 offset = 2;
  22.                 offset2 = 2;
  23.             var
  24.                 r: Rect;        {    the Rect to draw the PICT in    }
  25.                 pt: Point;
  26.                 siz: Point;
  27.                 value: integer;
  28.         begin
  29.             r := theControl^^.contrlRect;
  30.             value := theControl^^.contrlValue mod 8;
  31.             pt.h := (r.left + r.right) div 2;
  32.             pt.v := (r.top + r.bottom) div 2;
  33.             if odd(value) then begin
  34.                 siz.h := 3 * (r.right - r.left) div 4;
  35.                 siz.v := 3 * (r.bottom - r.top) div 4;
  36.             end
  37.             else begin
  38.                 siz.h := (r.right - r.left) div 2;
  39.                 siz.v := (r.bottom - r.top) div 2;
  40.             end;
  41.             OpenRgn;
  42.             case value of
  43.                 0:  begin
  44.                     MoveTo(pt.h, pt.v + offset - siz.v);
  45.                     Line(siz.h, siz.v);
  46.                     Line(-2 * siz.h, 0);
  47.                     Line(siz.h, -siz.v);
  48.                 end;
  49.                 1:  begin
  50.                     MoveTo(pt.h - offset2 + siz.h div 2, pt.v + offset2 + siz.v div 2);
  51.                     Line(0, -siz.v);
  52.                     Line(-siz.h, 0);
  53.                     Line(siz.h, siz.v);
  54.                 end;
  55.                 2:  begin
  56.                     MoveTo(pt.h - offset + siz.h, pt.v);
  57.                     Line(-siz.h, siz.v);
  58.                     Line(0, -2 * siz.v);
  59.                     Line(siz.h, siz.v);
  60.                 end;
  61.                 3:  begin
  62.                     MoveTo(pt.h - offset2 + siz.h div 2, pt.v - offset2 - siz.v div 2);
  63.                     Line(0, siz.v);
  64.                     Line(-siz.h, 0);
  65.                     Line(siz.h, -siz.v);
  66.                 end;
  67.                 4:  begin
  68.                     MoveTo(pt.h, pt.v - offset + siz.v);
  69.                     Line(siz.h, -siz.v);
  70.                     Line(-2 * siz.h, 0);
  71.                     Line(siz.h, siz.v);
  72.                 end;
  73.                 5:  begin
  74.                     MoveTo(pt.h + offset2 - siz.h div 2, pt.v - offset2 - siz.v div 2);
  75.                     Line(0, siz.v);
  76.                     Line(siz.h, 0);
  77.                     Line(-siz.h, -siz.v);
  78.                 end;
  79.                 6:  begin
  80.                     MoveTo(pt.h + offset - siz.h, pt.v);
  81.                     Line(siz.h, siz.v);
  82.                     Line(0, -2 * siz.v);
  83.                     Line(-siz.h, siz.v);
  84.                 end;
  85.                 7:  begin
  86.                     MoveTo(pt.h + offset2 - siz.h div 2, pt.v + offset2 + siz.v div 2);
  87.                     Line(0, -siz.v);
  88.                     Line(siz.h, 0);
  89.                     Line(-siz.h, siz.v);
  90.                 end;
  91.             end;
  92.             CloseRgn(rgn);
  93.         end;
  94.  
  95.         var
  96.             result: longint;        {    the result to return        }
  97.             hilite: integer;        {    the current control hilite state    }
  98.             rgn: RgnHandle;
  99.             mousePoint: Point;
  100.     begin
  101.         result := 0;
  102.  
  103.         case msg of
  104.             initCntl: 
  105.                 ; { We won't get this call anyway }
  106.  
  107.             drawCntl:  begin    {    Draw the arrow control                }
  108.                 if theControl^^.contrlVis <> 0 then begin
  109.                     rgn := NewRgn;
  110.                     GetRgn(rgn);
  111.                     EraseRect(theControl^^.contrlRect);
  112.                     case theControl^^.contrlHilite of
  113.                         kInactive:  begin
  114.                             PenPat(GetQDGlobals^.gray);
  115.                             FrameRgn(rgn);
  116.                             PenPat(GetQDGlobals^.black);
  117.                         end;
  118.                         0, kInUpButtonControlPart:  begin
  119.                             if (theControl^^.contrlValue > 7) = (theControl^^.contrlHilite = kInUpButtonControlPart) then begin
  120.                                 FrameRgn(rgn);
  121.                             end
  122.                             else begin
  123.                                 FillRgn(rgn, GetQDGlobals^.black);
  124.                             end;
  125.                         end;
  126.                         otherwise
  127.                             ;
  128.                     end;
  129.                     DisposeRgn(rgn);
  130.                 end;
  131.             end;
  132.  
  133.             testCntl:  begin        {    Determine which part of the arrow the mouse is in    }
  134.                 mousePoint.v := hiwrd(param);
  135.                 mousePoint.h := lowrd(param);
  136.  
  137.             {    If the mouse Point is in the control and it is active, determine which part the mouse went down in.            }
  138.                 if (theControl^^.contrlHilite <> kInactive) then{ & PtInRect(mousePoint, theControl^^.contrlRect) }
  139.                     begin
  140.                     rgn := NewRgn;
  141.                     GetRgn(rgn);
  142.                     if PtInRgn(mousePoint, rgn) then begin
  143.                         result := kInUpButtonControlPart;
  144.                     end;
  145.                     DisposeRgn(rgn);
  146.                 end;
  147.             end;
  148.  
  149.             calcCRgns, calcCntlRgn, calcThumbRgn:  begin
  150.                 param := longint(StripAddress(Ptr(param)));        { Mask off the high Byte if necessary }
  151.                 GetRgn(RgnHandle(param));
  152.             end;
  153.  
  154.             dispCntl: 
  155.                 ;
  156.  
  157.             otherwise
  158.                 ;
  159.         end;
  160.  
  161.         TriangleCDEF := result;
  162.     end;
  163.  
  164. end.