home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectInput / DIConfig / cdevicecontrol.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  5.0 KB  |  179 lines

  1. //-----------------------------------------------------------------------------
  2. // File: cdevicecontrol.h
  3. //
  4. // Desc: CDeviceControl is a class that encapsulate the functionality of a
  5. //       device control (or a callout).  CDeviceView accesses it to retrieve/
  6. //       save information about the control.
  7. //
  8. // Copyright (C) 1999-2001 Microsoft Corporation. All Rights Reserved.
  9. //-----------------------------------------------------------------------------
  10.  
  11. #ifdef FORWARD_DECLS
  12.  
  13.  
  14.     struct DEVICECONTROLSTRUCT;
  15.     enum DEVCTRLHITRESULT;
  16.  
  17.     class CDeviceControl;
  18.  
  19.  
  20. #else // FORWARD_DECLS
  21.  
  22. #ifndef __CDEVICECONTROL_H__
  23. #define __CDEVICECONTROL_H__
  24.  
  25.  
  26. const int MAX_DEVICECONTROL_LINEPOINTS = 5;
  27.  
  28. #define CAF_LEFT 1
  29. #define CAF_RIGHT 2
  30. #define CAF_TOP 4
  31. #define CAF_BOTTOM 8
  32.  
  33. #define CAF_TOPLEFT (CAF_TOP | CAF_LEFT)
  34. #define CAF_TOPRIGHT (CAF_TOP | CAF_RIGHT)
  35. #define CAF_BOTTOMLEFT (CAF_BOTTOM | CAF_LEFT)
  36. #define CAF_BOTTOMRIGHT (CAF_BOTTOM | CAF_RIGHT)
  37.  
  38. struct DEVICECONTROLSTRUCT {
  39.     DEVICECONTROLSTRUCT() : nLinePoints(0) {CopyStr(wszOverlayPath, "", MAX_PATH); SRECT r; rectOverlay = r.r;}
  40.     DWORD dwDeviceControlOffset;
  41.     int nLinePoints;
  42.     POINT rgptLinePoint[MAX_DEVICECONTROL_LINEPOINTS];
  43.     DWORD dwCalloutAlign;
  44.     RECT rectCalloutMax;
  45.     WCHAR wszOverlayPath[MAX_PATH];
  46.     RECT rectOverlay;
  47. };
  48.  
  49. enum DEVCTRLHITRESULT {
  50.     DCHT_LINE,
  51.     DCHT_CAPTION,
  52.     DCHT_MAXRECT,
  53.     DCHT_CONTROL,
  54.     DCHT_NOHIT
  55. };
  56.  
  57.  
  58. class CDeviceControl
  59. {
  60. private:
  61.     friend class CDeviceView;     // CDeviceView has exclusive right to create/destroy views
  62.     CDeviceControl(CDeviceUI &ui, CDeviceView &view);
  63.     ~CDeviceControl();
  64.     CDeviceView &m_view;
  65.     CDeviceUI &m_ui;
  66.  
  67. public:
  68.     // Info
  69.     int GetViewIndex() { return m_view.GetViewIndex(); }
  70.     int GetControlIndex();
  71.  
  72.     // state information
  73.     void SetCaption(LPCTSTR tszCaption, BOOL bFixed = FALSE);
  74.     LPCTSTR GetCaption();
  75.     BOOL IsFixed() { return m_bFixed; }
  76.     void Unhighlight() {Highlight(FALSE);}
  77.     void Highlight(BOOL bHighlight = TRUE);
  78.     BOOL IsHighlighted() {return m_bHighlight;}
  79.     void GetInfo(GUID &rGuid, DWORD &rdwOffset);
  80.     DWORD GetOffset();
  81.     BOOL IsOffsetAssigned();
  82.     BOOL HasAction() { return lstrcmp(m_ptszCaption, g_tszUnassignedControlCaption); }
  83.     void FillImageInfo(DIDEVICEIMAGEINFOW *pImgInfo);  // This fills the structure info about this control
  84.     BOOL IsMapped();
  85.     int GetMinX() {return m_rectCallout.left;}
  86.     int GetMaxX() {return m_rectCallout.right;}
  87.     int GetMinY() {return m_rectCallout.top;}
  88.     int GetMaxY() {return m_rectCallout.bottom;}
  89.     const RECT &GetCalloutMaxRect() const { return m_rectCalloutMax; }
  90.  
  91.     // hit testing (in coord's relative to view's origin)
  92.     DEVCTRLHITRESULT HitTest(POINT test);
  93.  
  94.     // simple notification
  95.     void OnMouseOver(POINT point);
  96.     void OnClick(POINT point, BOOL bLeft, BOOL bDoubleClick = FALSE);
  97.     void OnPaint(HDC hDC);
  98.  
  99.     // redrawing
  100.     void Invalidate();
  101.  
  102.     // editing
  103.     void PlaceCalloutMaxCorner(int nCorner, POINT point);
  104.     void ConsiderAlignment(POINT point);
  105.     void FinalizeAlignment() { }
  106.     void SetLastLinePoint(int nPoint, POINT point, BOOL bShiftDown);
  107.     void Position(POINT point);
  108.     BOOL ReachedMaxLinePoints() { return m_nLinePoints >= MAX_DEVICECONTROL_LINEPOINTS; }
  109.     int GetNextLinePointIndex() { return m_nLinePoints; }
  110.     BOOL HasOverlay() { return m_pbmOverlay != NULL; }
  111.  
  112.     // population
  113.     void SetObjID(DWORD dwObjID) { m_dwDeviceControlOffset = dwObjID; m_bOffsetAssigned = TRUE; }
  114.     void SetLinePoints(int n, POINT *rgpt);
  115.     void SetCalloutMaxRect(const RECT &r) { m_rectCalloutMax = r; CalcCallout(); }
  116.     void SetAlignment(DWORD a) { m_dwCalloutAlign = a; }
  117.     void SetOverlayPath(LPCTSTR tszPath);
  118.     void SetOverlayRect(const RECT &r);
  119.     void Init();
  120.  
  121. private:
  122.     // editing vars/helpers
  123.     POINT m_ptFirstCorner;
  124.     BOOL m_bPlacedOnlyFirstCorner;
  125.  
  126.     // helpers
  127.     void Unpopulate();
  128.     BOOL m_bInit;
  129.     BOOL m_bFixed;  // Whether this control is assigned an action with DIA_APPFIXED flag.
  130.     DEVICEUINOTIFY m_uin;
  131.     BOOL HitControl(POINT point);
  132.     BOOL DrawOverlay(HDC hDC);
  133.  
  134.     // device information
  135.     DWORD m_dwDeviceControlOffset;
  136.     BOOL m_bOffsetAssigned;
  137.  
  138.     // location/indication/visualization...
  139.     // (all relative to view's origin)
  140.  
  141.     // overlay
  142.     LPTSTR m_ptszOverlayPath;
  143.     CBitmap *m_pbmOverlay;
  144.     CBitmap *m_pbmHitMask;
  145.     POINT m_ptOverlay;
  146.     POINT m_ptHitMask;
  147.  
  148.     // caption (allocated and stored here)
  149.     LPTSTR m_ptszCaption;
  150.     BOOL m_bCaptionClipped;  // Whether the caption is clipped when drawn by DrawTextEx.
  151.  
  152.     // coloring
  153.     BOOL m_bHighlight;
  154.  
  155.     // line points...  first connects to callout, last points to control
  156.     int m_nLinePoints;
  157.     POINT m_rgptLinePoint[MAX_DEVICECONTROL_LINEPOINTS];
  158.  
  159.     // callout specs
  160.     DWORD m_dwCalloutAlign;    // where the line emerges from the callout
  161.     RECT m_rectCallout, m_rectCalloutMax;    // current callout rect, and max rect
  162.  
  163.     // gdi
  164.     DWORD m_dwDrawTextFlags;
  165.     int m_FontHeight;
  166.     void PrepFont();
  167.     BOOL PrepCaption();
  168.     void PrepLinePoints();
  169.     void CalcCallout();
  170.     void PrepCallout();
  171.     BOOL m_bCalledCalcCallout;
  172.  
  173. };
  174.  
  175.  
  176. #endif //__CDEVICECONTROL_H__
  177.  
  178. #endif // FORWARD_DECLS
  179.