home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / mac / programm / 20642 < prev    next >
Encoding:
Text File  |  1993-01-04  |  3.5 KB  |  128 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!spool.mu.edu!umn.edu!csus.edu!netcom.com!jimlynch
  3. From: jimlynch@netcom.com (Jim Lynch)
  4. Subject: Re: TCL, CPanes of variant shapes?
  5. Message-ID: <1993Jan4.230114.18527@netcom.com>
  6. Organization: Netcom Online Communications Services (408-241-9760 login: guest)
  7. References: <1993Jan3.213713.11222@fsl.noaa.gov>
  8. Date: Mon, 4 Jan 1993 23:01:14 GMT
  9. Lines: 117
  10.  
  11. Yes, you can. Here's mine. Feel free to have it as a toy, but if you
  12. distribute it, it must include this message. Don't use it in
  13. commercially available software without talking to me well in advance.
  14.  
  15. --------------- *** file CRegion.c *** ------------------
  16. #include "CRegion.h"
  17.  
  18. void CRegion::IRegion
  19. (
  20.         CView                   *anEnclosure,
  21.         CBureaucrat             *aSupervisor,
  22.         short                   aWidth,
  23.         short                   aHeight,
  24.         short                   aHEncl,
  25.         short                   aVEncl,
  26.         SizingOption    aHSizing,
  27.         SizingOption    aVSizing
  28. )
  29. {
  30.         inherited::IPane
  31.         (
  32.                 anEnclosure, aSupervisor,
  33.                 aWidth, aHeight,
  34.                 aHEncl, aVEncl,
  35.                 aHSizing, aVSizing
  36.         ) ;
  37.  
  38.         itsRegionH = NewRgn() ;
  39. }
  40.  
  41. void CRegion::Dispose(void)
  42. }
  43.         return(result) ;
  44.         }
  45.                 result = PtInRgn(thePoint, itsRegionH) ;
  46.                 thePoint.v = theLPoint.v ;
  47.                 thePoint.h = theLPoint.h ;
  48.                 WindToFrame(thePoint, &theLPoint) ;
  49.         {
  50.                 aWidth, aHeight,
  51.                 aHEncl, aVEncl,
  52.                 aHSizing, aVSizing
  53.         ) ;
  54.  
  55.         itsRegionH = NewRgn() ;
  56. }
  57.  
  58. void CRegion::Dispose(void)
  59. {
  60.         DisposeRgn(itsRegionH) ;
  61.  
  62.         inherited::Dispose() ;
  63. }
  64.  
  65. Boolean CRegion::Contains(Point thePoint)
  66. {
  67.         LongPt theLPoint ;
  68.         Boolean result ;
  69.  
  70.         result = FALSE ;
  71.  
  72.         if(ReallyVisible())
  73.         {
  74.                 WindToFrame(thePoint, &theLPoint) ;
  75.                 thePoint.h = theLPoint.h ;
  76.                 thePoint.v = theLPoint.v ;
  77.                 result = PtInRgn(thePoint, itsRegionH) ;
  78.         }
  79.  
  80.         return(result) ;
  81. }
  82.  
  83. -------------- *** end of CRegion.c *** ------------------
  84.  
  85. Here's the .h file:
  86.  
  87. --------------- *** CRegion.h *** --------------------
  88. #pragma once
  89.  
  90. #include <CPane.h>
  91.  
  92. class CRegion : public CPane
  93. {
  94. protected:
  95.         RgnHandle itsRegionH ;
  96.  
  97. public:
  98.         void IRegion
  99.         (
  100.                 CView                   *anEnclosure,
  101.                 CBureaucrat             *aSupervisor,
  102.                 short                   aWidth,
  103.                 short                   aHeight,
  104.                 short                   aHEncl,
  105.                 short                   aVEncl,
  106.                 SizingOption    aHSizing,
  107.                 SizingOption    aVSizing
  108.         ) ;
  109.         void Dispose(void) ;
  110.  
  111.         Boolean Contains(Point thePoint);
  112. } ;
  113.  
  114. ---------------- *** end of CRegion.h *** ------------
  115.  
  116. Notice I don't do anything to itsRegionH after allocating; that's up to your
  117. code. Also note that I override CPane::Contains() so CRegion's version checks
  118. to see if the point lies in the region referred to by itsRegionH.
  119.  
  120. I use this as an abstract class. I was doing something with piano keys which
  121. are irregular shapes. Made buttons out of them, as I recall... In any case,
  122. my CKey::IKey method called its superclass' IRegion method then did something
  123. to the region (like make a shape).
  124.  
  125. So you could make a CHex which is a subclass of CRegion and draw a hex polygon
  126. in itsRegionH...
  127.  
  128.