home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osp1.exe / src / grafpart / iodgpoin.cpp < prev    next >
Text File  |  1997-04-02  |  14KB  |  342 lines

  1. // @(#) 1.11 com/src/samples/grafpart/iodgpoin.cpp, odgrafpart, od96nt 2/3/97 19:26:04 [2/5/97 20:45:00]
  2. /*====START_GENERATED_PROLOG======================================
  3.  */
  4. /*
  5.  *   COMPONENT_NAME: odgrafpart
  6.  *
  7.  *   CLASSES: ContentGrafPartPoin
  8.  *
  9.  *   ORIGINS: 27
  10.  *
  11.  *
  12.  *   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13.  *   All Rights Reserved
  14.  *   Licensed Materials - Property of IBM
  15.  *   US Government Users Restricted Rights - Use, duplication or
  16.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17.  *
  18.  *   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19.  *   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20.  *   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21.  *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22.  *   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23.  *   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24.  *   OR PERFORMANCE OF THIS SOFTWARE.
  25.  */
  26. /*====END_GENERATED_PROLOG========================================
  27.  */
  28.  
  29. // *********************************************************************
  30. //  File:      iodgpoin.cpp
  31. //  Contains:  Class implementation for a Point Object in a 2D-Drawing Container Part
  32. // ************************************************************************
  33.  
  34. #define ContentGrafPartPoin_Class_Source
  35.  
  36. #ifndef SOM_Module_GrafPoin_Source
  37.     #define SOM_Module_GrafPoin_Source
  38. #endif  // SOM_Module_GrafPoin_Source
  39.  
  40. // GrafPart's includes
  41. #ifndef _IODGCOMM_CPP_
  42.    #include <iodgcomm.cpp>
  43. #endif   // _IODGCOMM_CPP_
  44.  
  45. // GrafPart's constants & defines
  46. #ifndef _GRAFPART_HPP_
  47.    #include <iodgraph.hpp>
  48. #endif   // _GRAFPART_HPP_
  49.  
  50. // support use of temporary objects (Initialize & Uninitialize)
  51. #ifndef _TEMPOBJ_
  52.     #include <TempObj.h>
  53. #endif // _TEMPOBJ_
  54.  
  55. // support StorageUnit function
  56. #ifndef _STORUTIL_
  57.     #include <StorUtil.h>
  58. #endif  // _STORUTIL_
  59.  
  60. // support math function (ContainsPoint)
  61. #ifndef __math_h
  62.     #include <math.h>
  63. #endif  // __math_h
  64.  
  65. // includes for native drawing functions
  66. #if defined(_PLATFORM_WIN32_)
  67.     #include <windows.h>
  68.     #include <winuser.h>
  69.     #include <wingdi.h>
  70. #elif defined(_PLATFORM_OS2_)
  71.     #include <ODos2.h>
  72. #endif // _PLATFORM_???_
  73.  
  74.  
  75. // local function support includes
  76. #ifndef SOM_GrafPart_xh
  77.     #include "iodgraph.xh"
  78. #endif // SOM_GrafPart_xh
  79.  
  80. #ifndef SOM_ContentGrafPartFigr_xh
  81.     #include "iodgfigr.xh"
  82. #endif // SOM_ContentGrafPartFigr_xh
  83.  
  84. #ifndef SOM_ContentGrafPartPoin_xih
  85.     #include "iodgpoin.xih"
  86. #endif // SOM_ContentGrafPartPoin_xih
  87.  
  88.  
  89. // *************************************************************************
  90. //
  91. //  Class implementation:
  92. //      ContentGrafPartPoin : ContentGrafPartFigr
  93. //
  94. // *************************************************************************
  95.  
  96. // =========================================================================
  97. //
  98. //      Public Override methods: ContentGrafPartPoin
  99. //
  100. // =========================================================================
  101.  
  102. // -------------------------------------------------------------------------
  103. // ContentGrafPartPoin --> somInit
  104. //
  105. //     Initialization used at registration time
  106. //
  107. //     -> public override method
  108. //     -> calls parent first
  109. // -------------------------------------------------------------------------
  110. SOM_Scope void  SOMLINK ContentGrafPartPoinsomInit(ContentGrafPartPoin *somSelf )
  111. {
  112.     SQUAWK("> Invoked ContentGrafPartPoin::somInit()\n");
  113.  
  114.     /* ContentGrafPartPoinData *somThis = ContentGrafPartPoinGetData(somSelf); */
  115.     ContentGrafPartPoinMethodDebug("ContentGrafPartPoin","ContentGrafPartPoinsomInit");
  116.  
  117.     // call parent method
  118.     ContentGrafPartPoin_parent_ContentGrafPartFigr_somInit(somSelf);
  119.  
  120.     // set the objtype
  121.     somSelf->_set_objType(somGetGlobalEnvironment(), COBJ_GRAFPART_POIN);
  122.  
  123.     SQUAWK("< Leaving ContentGrafPartPoin::somInit()\n");
  124.  
  125. }   // somInit()
  126.  
  127.  
  128. // -------------------------------------------------------------------------
  129. // ContentGrafPartPoin --> MoveBy
  130. //
  131. //      Override ContentObject::MoveBy to update points
  132. //
  133. //      -> public override method
  134. //      -> calls parent first
  135. //      -> the 'offset' is a set of deltas from the origin of the
  136. //          point's bounding rect, expressed as coordinates (not a point)
  137. // -------------------------------------------------------------------------
  138. SOM_Scope void  SOMLINK ContentGrafPartPoinMoveBy(  ContentGrafPartPoin*    somSelf,
  139.                                                     Environment*            ev,
  140.                                                     ODPoint*                offset )
  141. {
  142.     SQUAWK("> Invoked ContentGrafPartPoin::MoveBy(ODPoint*)\n");
  143.     SQUAWK("\tContentGrafPartPoin::MoveBy(ODPoint*): received offset: %d, %d\n", ODFixedToInt(offset->x), ODFixedToInt(offset->y) );
  144.  
  145.     /* ContentGrafPartPoinData *somThis = ContentGrafPartPoinGetData(somSelf); */
  146.     ContentGrafPartPoinMethodDebug("ContentGrafPartPoin","ContentGrafPartPoinMoveBy");
  147.  
  148.     // call parent method
  149.     ContentGrafPartPoin_parent_ContentGrafPartFigr_MoveBy(  somSelf,
  150.                                                             ev,
  151.                                                             offset );
  152.  
  153.     // adjust the bounding rect for the new points
  154.     somSelf->AdjustBoundingRect(ev);
  155.  
  156.     SQUAWK("< Leaving ContentGrafPartPoin::MoveBy(ODPoint*)\n");
  157.  
  158. }   // ContentGrafPartPoin::MoveBy(ODPoint)
  159.  
  160.  
  161. // -------------------------------------------------------------------------
  162. // ContentGrafPartPoin --> Resize
  163. //
  164. //      Override ContentObject::Resize to update points
  165. //
  166. //     -> public override method
  167. //     -> does not call parent
  168. // -------------------------------------------------------------------------
  169. SOM_Scope void  SOMLINK ContentGrafPartPoinResize(  ContentGrafPartPoin*    somSelf,
  170.                                                     Environment*            ev,
  171.                                                     ODPoint*                point,
  172.                                                     ODULong                 flags )
  173. {
  174.     SQUAWK("> Invoked ContentGrafPartPoin::Resize()\n");
  175.     SQUAWK("\tContentGrafPartPoin::Resize(): received endpoint: %d, %d\n",
  176.         ODFixedToInt(point->x), ODFixedToInt(point->y) );
  177.  
  178.     /* ContentGrafPartPoinData *somThis = ContentGrafPartPoinGetData(somSelf); */
  179.     ContentGrafPartPoinMethodDebug("ContentGrafPartPoin","ContentGrafPartPoinResize");
  180.  
  181.     // call parent method
  182.     ContentGrafPartPoin_parent_ContentGrafPartFigr_Resize(  somSelf,
  183.                                                             ev,
  184.                                                             point,
  185.                                                             flags );
  186.  
  187.     // adjust the bounding rect for the new points
  188.     somSelf->AdjustBoundingRect(ev);
  189.  
  190.     SQUAWK("< Leaving ContentGrafPartPoin::Resize()\n");
  191.  
  192. }   // ContentGrafPartPoin::Resize()
  193.  
  194.  
  195. // -------------------------------------------------------------------------
  196. //  ContentGrafPartPoin --> AdjustBoundingRect
  197. //
  198. //      Adjust a Point's bounding rect to fit it's representation, which is
  199. //          possibly larger than a single pixel
  200. //
  201. //      -> public override method
  202. //      -> does not call parent
  203. // -------------------------------------------------------------------------
  204. SOM_Scope   void    SOMLINK ContentGrafPartPoinAdjustBoundingRect(  ContentGrafPartPoin*    somSelf,
  205.                                                                     Environment*            ev )
  206. {
  207.     SQUAWK("> Invoked ContentGrafPartPoin::AdjustBoundingRect()\n");
  208.  
  209.     /* ContentGrafPartPoinData *somThis = ContentGrafPartPoinGetData(somSelf); */
  210.     ContentGrafPartPoinMethodDebug("ContentGrafPartPoin","ContentGrafPartPoinAdjustBoundingRect");
  211.  
  212.     // set local buffer from persistant data
  213.     ODPoint pt1;                    // buffers for the point
  214.     pt1 = somSelf->_get_fPt1(ev);   // get origin from parent figure
  215.  
  216.     // reset the bounding box from the new points, keeping orientation
  217.     ODRect bbox;                                    // declare a buffer for bounding rectangle
  218.  
  219.     // set the buffer points to the new extents
  220. #ifdef _PLATFORM_OS2_                               // OS2 origin is LLC
  221.     bbox.top    = pt1.y + 1;
  222.     bbox.bottom = pt1.y - 1;
  223. #else                                               // everyone else's origin in ULC
  224.     bbox.top    = pt1.y - 1;
  225.     bbox.bottom = pt1.y + 1;
  226. #endif  // _PLATFORM_OS2_
  227.     bbox.left   = pt1.x - 1;
  228.     bbox.right  = pt1.x + 1;
  229.  
  230.     somSelf->_set_boundingRect(ev, &bbox);          // set the bounding rectangle from the buffer
  231.  
  232.     SQUAWK("< Leaving ContentGrafPartPoin::AdjustBoundingRect()\n");
  233.  
  234. }   // ContentGrafPartPoin::AdjustBoundingRect()
  235.  
  236.  
  237. // -------------------------------------------------------------------------
  238. //  ContentGrafPartPoin --> Draw
  239. //
  240. //      Render a poin on the screen
  241. //
  242. //      -> public override method
  243. //      -> does not call parent
  244. // -------------------------------------------------------------------------
  245. SOM_Scope   ODBoolean   SOMLINK ContentGrafPartPoinDraw(ContentGrafPartPoin*    somSelf,
  246.                                                         Environment*            ev,
  247.                                                         HDraw                   hDraw )
  248. {
  249.     SQUAWK("> Invoked ContentGrafPartPoin::Draw()\n");
  250.  
  251. #ifdef _PLATFORM_OS2_
  252.     // Instance data for this class, in addition to that defined by ContentGrafPartFigr,
  253.     //   only exists (and is used) on the OS/2 platform, so the following function is only
  254.     //   defined in the iodgpoin.xih file on the OS/2 platform.
  255.     ContentGrafPartPoinData *somThis = ContentGrafPartPoinGetData(somSelf);
  256. #endif  // _PLATFORM_OS2_
  257.     ContentGrafPartPoinMethodDebug("ContentGrafPartPoin","ContentGrafPartPoinDraw");
  258.  
  259.     // set local buffers from persistant data
  260.     ODPoint pt1;                    // buffers for the points
  261.     pt1 = somSelf->_get_fPt1(ev);   // get origin from parent figure
  262.  
  263. #if defined (_PLATFORM_OS2_)
  264.     SQUAWK("\tContentGrafPartPoin::Draw(): Drawing poin object for OS2\n");
  265.     _pPt1.x = ODFixedToInt(pt1.x); _pPt1.y = ODFixedToInt(pt1.y);
  266.     SQUAWK("\tContentGrafPartPoin::Draw(): point 1: %lx, %lx\n", pt1.x, pt1.y );
  267.     _pPt1.x = (_pPt1.x)-1; _pPt1.y = (_pPt1.y)-1;
  268.     GpiMove(hDraw, &_pPt1);
  269.     _pPt1.x = (_pPt1.x)+2; _pPt1.y = (_pPt1.y)+2;
  270.     GpiSetColor(hDraw, somSelf->_get_fColor(ev));
  271.     GpiBox(hDraw, DRO_OUTLINEFILL, &_pPt1, 2, 2);
  272. #elif defined (_PLATFORM_WIN32_)
  273.     SQUAWK("\tContentGrafPartPoin::Draw(): Drawing poin object for WIN32\n");
  274.     HBRUSH hbr = CreateSolidBrush(somSelf->_get_fColor(ev));
  275.     SelectObject( hDraw, hbr);
  276.     Rectangle(  hDraw,
  277.         ODFixedToInt(pt1.x)-1, ODFixedToInt(pt1.y)-1,
  278.         ODFixedToInt(pt1.x)+1, ODFixedToInt(pt1.y)+1 );
  279.     DeleteObject(hbr);
  280. #endif // _PLATFORM_???_
  281.  
  282.     SQUAWK("< Leaving ContentGrafPartPoin::Draw()\n");
  283.     return(kODTrue);
  284.  
  285. }   // ContentGrafPartPoin::Draw()
  286.  
  287.  
  288. // -------------------------------------------------------------------------
  289. //  ContentGrafPartPoin --> ContainsPoint
  290. //
  291. //      Determines whether a given point is on or near an intrinsic point object
  292. //
  293. //      -> public override method
  294. //      -> does not call parent
  295. // -------------------------------------------------------------------------
  296. SOM_Scope   ODBoolean   SOMLINK ContentGrafPartPoinContainsPoint(   ContentGrafPartPoin*    somSelf,
  297.                                                                     Environment*            ev,
  298.                                                                     ODPoint*                point )
  299. {
  300.     SQUAWK("> Invoked ContentGrafPartPoin::ContainsPoint()\n");
  301.  
  302.     /* ContentGrafPartPoinData *somThis = ContentGrafPartPoinGetData(somSelf); */
  303.     ContentGrafPartPoinMethodDebug("ContentGrafPartPoin","ContentGrafPartPoinContainsPoint");
  304.  
  305.     // set local buffers from persistant data
  306.     ODPoint pt1;                    // buffer for the origin point
  307.     pt1 = somSelf->_get_fPt1(ev);   // get copy of origin point from parent figure
  308.  
  309.     SQUAWK("\tContentGrafPartPoin::ContainsPoint(): received Point: %d, %d\n", ODFixedToInt(point->x), ODFixedToInt(point->y) );
  310.     SQUAWK("\tContentGrafPartPoin::ContainsPoint():   point origin: %d, %d\n", ODFixedToInt(pt1.x), ODFixedToInt(pt1.y) );
  311.     SQUAWK("\tContentGrafPartPoin::ContainsPoint(): X, Y SelectionThresholds: %d, %d\n", kODXSelectionThreshold, kODYSelectionThreshold );
  312.  
  313.     // do all math in double precision
  314.     struct POINTFL
  315.     {
  316.         double x;
  317.         double y;
  318.     }   Dpt1 =  { (double)pt1.x/65536.,    (double)pt1.y/65536.    },
  319.         Dpt2 =  { (double)point->x/65536., (double)point->y/65536. };
  320.  
  321.     // examine threshold ranges around origin point
  322.     if ( (Dpt2.x >= Dpt1.x - kODXSelectionThreshold ) &&    // point in x range of origin point
  323.          (Dpt2.x <= Dpt1.x + kODXSelectionThreshold ) &&    //   and
  324.          (Dpt2.y >= Dpt1.y - kODYSelectionThreshold ) &&    // point in y range of origin point
  325.          (Dpt2.y <= Dpt1.y + kODYSelectionThreshold ) )
  326.     {
  327.         SQUAWK("< Leaving ContentGrafPartPoin::ContainsPoint(), returning True (origin)\n");
  328.         return(kODTrue);
  329.     }   // if: origin
  330.     else
  331.     {
  332.         SQUAWK("< Leaving ContentGrafPartPoin::ContainsPoint(), returning False\n");
  333.         return(kODFalse);
  334.     }   // else: origin
  335.  
  336. }   // ContentGrafPartPoin::ContainsPoint()
  337.  
  338.  
  339. // =========================================================================
  340. // End of file: iodgpoin.cpp
  341. // =========================================================================
  342.