home *** CD-ROM | disk | FTP | other *** search
/ Beginning Direct3D Game Programming / Direct3D.iso / directx / dxf / samples / multimedia / directinput / diconfig / configwnd.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-22  |  6.8 KB  |  247 lines

  1. //-----------------------------------------------------------------------------
  2. // File: configwnd.h
  3. //
  4. // Desc: CConfigWnd is derived from CFlexWnd. It implements the top-level
  5. //       UI window which all other windows are descendents of.
  6. //
  7. //       Functionalities handled by CConfigWnd are device tabs, Reset, Ok,
  8. //       and Cancel buttons.
  9. //
  10. // Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  11. //-----------------------------------------------------------------------------
  12.  
  13. #ifndef __CONFIGWND_H__
  14. #define __CONFIGWND_H__
  15.  
  16.  
  17. #define PAGETYPE IDIDeviceActionConfigPage
  18. #define NUMBUTTONS 3
  19.  
  20.  
  21. class CMouseTrap : public CFlexWnd
  22. {
  23.     HWND m_hParent;
  24.  
  25. public:
  26.     CMouseTrap() : m_hParent(NULL) { }
  27.     HWND Create(HWND hParent = NULL, BOOL bInRenderMode = TRUE);
  28.  
  29. protected:
  30.     virtual BOOL OnEraseBkgnd(HDC hDC) {return TRUE;}
  31.     virtual void OnPaint(HDC hDC)    {}
  32.     virtual void OnRender(BOOL bInternalCall = FALSE) {}
  33. };
  34.  
  35. // Each device is represented by an ELEMENT object that is managed by
  36. // CConfigWnd.
  37. struct ELEMENT {
  38.     ELEMENT() : nCurUser(-1), pPage(NULL), lpDID(NULL) {tszCaption[0] = 0;}
  39.     // everything's cleaned up in CConfigWnd::ClearElement();
  40.     DIDEVICEINSTANCEW didi;
  41.     PAGETYPE *pPage;
  42.     HWND hWnd;
  43.     BOOL bCalc;
  44.     RECT rect, textrect;
  45.     TCHAR tszCaption[MAX_PATH];
  46.     LPDIRECTINPUTDEVICE8W lpDID;
  47.  
  48.     // the map of acfors contains an acfor for each genre/username
  49.     // that has been used so far on this device.  the dword represents
  50.     // the genre username as follows:  the hiword is the index of the
  51.     // genre per uiglobals.  the loword is the index of the username
  52.     // per uiglobals.
  53.     CMap<DWORD, DWORD &, LPDIACTIONFORMATW, LPDIACTIONFORMATW &> AcForMap;
  54.  
  55. #define MAP2GENRE(m) (int(((m) & 0xffff0000) >> 16))
  56. #define MAP2USER(m) (int((m) & 0x0000ffff))
  57. #define GENREUSER2MAP(g,u) \
  58.     ( \
  59.         ((((DWORD)(nGenre)) & 0xffff) << 16) | \
  60.         (((DWORD)(nUser)) & 0xffff) \
  61.     )
  62.  
  63.     // this function simply returns the corresponding entry in the
  64.     // map if it already exists.  otherwise, it creates a copy for
  65.     // this entry from the masteracfor and calls buildactionmap on
  66.     // it with the appropriate username.
  67.  
  68.     // bHwDefault flag is added to properly support Reset button.  BuildActionMap must be
  69.     // called with the flag to get hardware default mapping, so we need this parameter.
  70.     LPDIACTIONFORMATW GetAcFor(int nGenre, int nUser, BOOL bHwDefault = FALSE);
  71.  
  72.     // we need to keep track of the current user per-element
  73.     int nCurUser;
  74.  
  75.     // we need a pointer to the uiglobals in order to correspond
  76.     // user indexes to the actual string
  77.     CUIGlobals *pUIGlobals;
  78.  
  79.     // this function will be called in CConfigWnd::ClearElement to
  80.     // free all the actionformats from the map
  81.     void FreeMap();
  82.  
  83.     // Applies all the acfor's in the map
  84.     void Apply();
  85. };
  86.  
  87. typedef CArray<ELEMENT, ELEMENT &> ELEMENTARRAY;
  88.  
  89. // CConfigWnd needs to expose methods for child windows to notify it.
  90. class CConfigWnd : public CFlexWnd, public IDIConfigUIFrameWindow
  91. {
  92. public:
  93.     CConfigWnd(CUIGlobals &uig);
  94.     ~CConfigWnd();
  95.  
  96.     BOOL Create(HWND hParent);
  97.     static void SetForegroundWindow();
  98.     LPDIRECTINPUTDEVICE8W RenewDevice(GUID &GuidInstance);
  99.  
  100.     BOOL EnumDeviceCallback(const DIDEVICEINSTANCEW *lpdidi);
  101.     void EnumDeviceCallbackAssignUser(const DIDEVICEINSTANCEW *lpdidi, DWORD *pdwOwner);
  102.  
  103.     CUIGlobals &m_uig;
  104.  
  105.     // IDIConfigUIFrameWindow implementation...
  106.  
  107.     // Reset Entire Configuration
  108.     STDMETHOD (Reset) ();
  109.  
  110.     // Assignment Querying
  111.     STDMETHOD (QueryActionAssignedAnywhere) (int i);
  112.  
  113.     // Genre Control
  114.     STDMETHOD_(int, GetNumGenres) ();
  115.     STDMETHOD (SetCurGenre) (int i);
  116.     STDMETHOD_(int, GetCurGenre) ();
  117.  
  118.     // User Control
  119.     STDMETHOD_(int, GetNumUsers) ();
  120.     STDMETHOD (SetCurUser) (int nPage, int nUser);
  121.     STDMETHOD_(int, GetCurUser) (int nPage);
  122.  
  123.     // ActionFormat Access
  124.     STDMETHOD (GetActionFormatFromInstanceGuid) (LPDIACTIONFORMATW *lplpAcFor, REFGUID);
  125.  
  126.     // Main HWND Access
  127.     STDMETHOD_(HWND, GetMainHWND) ();
  128.  
  129.  
  130. protected:
  131.     // overrides
  132.     virtual void OnRender(BOOL bInternalCall = FALSE);
  133.     virtual LRESULT OnCreate(LPCREATESTRUCT lpCreateStruct);
  134.     virtual void OnPaint(HDC hDC);
  135.     virtual void OnMouseOver(POINT point, WPARAM fwKeys);
  136.     virtual void OnClick(POINT point, WPARAM fwKeys, BOOL bLeft);
  137.     virtual void OnDestroy();
  138.     virtual LRESULT WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  139.  
  140. private:
  141.  
  142. #define CFGWND_INIT_REINIT 1
  143. #define CFGWND_INIT_RESET 2
  144.  
  145.     BOOL Init(DWORD dwInitFlags = 0);
  146.     DWORD m_dwInitFlags;
  147.     BOOL m_bCreated;
  148.     int AddToList(const DIDEVICEINSTANCEW *lpdidi, BOOL bReset = FALSE);
  149.     void ClearList();
  150.     void PlacePages();
  151.     void GetPageRect(RECT &rect, BOOL bTemp = FALSE);
  152.     void Render(BOOL bInternalCall = FALSE);
  153.  
  154.     ELEMENTARRAY m_Element;
  155.     ELEMENT m_InvalidElement;
  156.     int m_CurSel;
  157.     int GetNumElements();
  158.     ELEMENT &GetElement(int i);
  159.     void ClearElement(int i);
  160.     void ClearElement(ELEMENT &e);
  161.     BOOL m_bScrollTabs, m_bScrollTabsLeft, m_bScrollTabsRight;
  162.     int m_nLeftTab;
  163.     RECT m_rectSTLeft, m_rectSTRight;
  164.     void ScrollTabs(int);
  165.     LPDIRECTINPUTDEVICE8W CreateDevice(GUID &guid);
  166.     BOOL m_bNeedRedraw;
  167.  
  168.     LPDIACTIONFORMATW GetCurAcFor(ELEMENT &e);
  169.  
  170.     int m_nCurGenre;
  171.  
  172.     IClassFactory *m_pPageFactory;
  173.     HINSTANCE m_hPageFactoryInst;
  174.     PAGETYPE *CreatePageObject(int nPage, const ELEMENT &e, HWND &refhChildWnd);
  175.     void DestroyPageObject(PAGETYPE *&pPage);
  176.  
  177.     LPDIRECTINPUT8W m_lpDI;
  178.  
  179.     RECT m_rectTopGradient, m_rectBottomGradient;
  180.     CBitmap *m_pbmTopGradient, *m_pbmBottomGradient;
  181.     BOOL m_bHourGlass;  // Set when the cursor should be an hourglass
  182.  
  183.     typedef struct BUTTON {
  184.         BUTTON() {CopyStr(tszCaption, _T(""), MAX_PATH);}
  185.         RECT rect;
  186.         TCHAR tszCaption[MAX_PATH];
  187.         SIZE textsize;
  188.         RECT textrect;
  189.     } BUTTON;
  190.     BUTTON m_Button[NUMBUTTONS];
  191.     enum {
  192.         BUTTON_RESET = 0,
  193.         BUTTON_CANCEL,
  194.         BUTTON_OK,
  195.     };
  196.  
  197.     SIZE GetTextSize(LPCTSTR tszText);
  198.  
  199.     void CalcTabs();
  200.     void CalcButtons();
  201.     void InitGradients();
  202.  
  203.     void SelTab(int);
  204.     void FireButton(int);
  205.     void ShowPage(int);
  206.     void HidePage(int);
  207.  
  208.     HDC GetRenderDC();
  209.     void ReleaseRenderDC(HDC &phDC);
  210.     void Create3DBitmap();
  211.     void Copy3DBitmapToSurface3D();
  212.     void CallRenderCallback();
  213.  
  214.     IDirectDrawSurface *m_pSurface;
  215.     IDirect3DSurface8 *m_pSurface3D;
  216.     D3DFORMAT m_SurfFormat;
  217.     UINT m_uiPixelSize;  // Size of a pixel in byte for the format we are using
  218.     CBitmap *m_pbmPointerEraser;
  219.     CBitmap *m_pbm3D;
  220.     LPVOID m_p3DBits;
  221.     BOOL m_bRender3D;
  222.  
  223.     POINT m_ptTest;
  224.  
  225.     void MapBitmaps(HDC);
  226.     BOOL m_bBitmapsMapped;
  227.  
  228.     BOOL m_bAllowEditLayout;
  229.     BOOL m_bEditLayout;
  230.     void ToggleLayoutEditting();
  231.  
  232.     CMouseTrap m_MouseTrap;
  233.  
  234.     // Timer
  235.     static void CALLBACK TimerProc(UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2);
  236.  
  237.     HRESULT Apply();
  238.  
  239.     BOOL IsActionAssignedAnywhere(int nActionIndex);
  240.  
  241.     void Unacquire();
  242.     void Reacquire();
  243. };
  244.  
  245.  
  246. #endif //__CONFIGWND_H__
  247.