home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / atl / atltangram / atlgdiworld / atlgdiworldimpl.h < prev    next >
C/C++ Source or Header  |  1998-03-26  |  3KB  |  125 lines

  1. // AtlGdiWorldImpl.h : Declaration of the CAtlGdiWorld
  2. //
  3. // This is a part of the Active Template Library.
  4. // Copyright (C) 1996-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Active Template Library Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Active Template Library product.
  12.  
  13. #ifndef __ATLGDIWORLD_H_
  14. #define __ATLGDIWORLD_H_
  15. #include "TanType.h"
  16. // STL Headers
  17. #include <new.h>
  18. #include <algorithm>
  19. #include <xmemory>
  20. #include <list>
  21.  
  22. #include "util.h"
  23. #include "ATLTangramCanvas.h"
  24. #include "resource.h"       // main symbols
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CAtlGdiWorld
  28. class ATL_NO_VTABLE CAtlGdiWorld :
  29.     public CComObjectRootEx<CComSingleThreadModel>,
  30.     public CComCoClass<CAtlGdiWorld, &CLSID_AtlGdiWorld>,
  31.     public IAtlTangramGdiWorld
  32. {
  33. public:
  34.     CAtlGdiWorld():
  35.         m_pCanvas(0),
  36.         m_pCanvasUnknown(0)
  37.     {
  38.         m_sizedScale.cx = m_sizedScale.cy = 1.0 ;
  39.         m_ptdDeviceOrg.x = m_ptdDeviceOrg.y = 0.0 ;
  40.  
  41.         ::SetRectEmpty(&m_rectUpdate) ;
  42.     }
  43.  
  44.     ~CAtlGdiWorld();
  45.  
  46.     void FinalRelease()
  47.     {
  48.         TCHAR buf[128];
  49.         wsprintf(buf,_T("World: m_dwRef = %d\n"), m_dwRef);
  50.         ATLTRACE(buf);
  51.         // Release the ICanvas interface on the aggregated object.
  52.         if (m_pCanvas != NULL)
  53.         {
  54.             // Add a reference back to the outer object.
  55.             GetControllingUnknown()->AddRef() ;
  56.             // Remove the reference on the inner and outer objects.
  57.             m_pCanvas->Release() ;
  58.             m_pCanvas = NULL ;
  59.         }
  60.         wsprintf(buf,_T("World: m_dwRef = %d\n"), m_dwRef);
  61.         ATLTRACE(buf);
  62.  
  63.         // Release our hold on the inner object.
  64.         if (m_pCanvasUnknown != NULL)
  65.         {
  66.             m_pCanvasUnknown->Release() ;
  67.             m_pCanvasUnknown = NULL ;
  68.         }
  69.         wsprintf(buf,_T("World: m_dwRef = %d\n"), m_dwRef);
  70.         ATLTRACE(buf);
  71.     }
  72.  
  73. DECLARE_REGISTRY_RESOURCEID(IDR_ATLTANGRAMGDIVISUAL)
  74. DECLARE_GET_CONTROLLING_UNKNOWN()
  75.  
  76. BEGIN_COM_MAP(CAtlGdiWorld)
  77.     COM_INTERFACE_ENTRY(IAtlTangramGdiWorld)
  78.     COM_INTERFACE_ENTRY(IAtlTangramWorld)
  79.     COM_INTERFACE_ENTRY_AGGREGATE(IID_IAtlTangramCanvas, m_pCanvasUnknown )
  80. END_COM_MAP()
  81.  
  82. public:
  83.  
  84.     // Special Registration
  85.     static void SpecialReg(BOOL bRegister) ;
  86.  
  87.     // IAtlTangramWorld Members
  88.     HRESULT __stdcall Initialize(HWND hwnd, double logicalCX, double logicalCY) ;
  89.     HRESULT __stdcall DeviceToModel(POINT ptIN, TangramPoint2d* pptOut) ;
  90.  
  91.     HRESULT __stdcall VisualFromPoint(  POINT pt,
  92.                                         REFIID iid,
  93.                                         IUnknown** ppITangramVisual) ;
  94.     HRESULT __stdcall CreateVisualForModel(IATLTangramModel* pModel) ;
  95.     HRESULT __stdcall SelectVisual(IAtlTangramVisual* pSelectedVisual, BOOL bSelect) ;
  96.  
  97.     HRESULT __stdcall Animate() ;
  98.  
  99.     // ITangramGdiWorld
  100.     HRESULT __stdcall ModelToDevice(TangramPoint2d ptIn, POINT* pptOut);
  101.     HRESULT __stdcall AddUpdateRect(RECT rectUpdate) ;
  102.  
  103. private:
  104.     // Members
  105. #pragma warning(disable:4786)
  106.     typedef std::list<IAtlTangramGdiVisual*> CVisualList;
  107.     CVisualList m_VisualList ;
  108. #pragma warning(default:4786)
  109.     // Coordinate Transform
  110.     TangramSize2d m_sizedScale ;
  111.     TangramPoint2d m_ptdDeviceOrg ;
  112.  
  113.     double dDeviceUnits ;
  114.     double dModelUnits ;
  115.  
  116.     // Aggregated Canvas Component
  117.     IAtlTangramCanvas* m_pCanvas;
  118.     IUnknown* m_pCanvasUnknown ;
  119.  
  120.     // Update rectangle
  121.     RECT m_rectUpdate ;
  122. };
  123.  
  124. #endif //__ATLGDIWORLD_H_
  125.