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

  1. //-----------------------------------------------------------------------------
  2. // File: uiglobals.h
  3. //
  4. // Desc: CUIGlobals is a class that packs and holds most information
  5. //       relevent to a UI session.  Many classes make reference to
  6. //       CUIGlobals all the time.
  7. //
  8. //       CPaintHelper encapsulates GDI calls, simplifying GDI operations.
  9. //
  10. // Copyright (C) 1999-2001 Microsoft Corporation. All Rights Reserved.
  11. //-----------------------------------------------------------------------------
  12.  
  13. #ifndef __UIGLOBALS_H__
  14. #define __UIGLOBALS_H__
  15.  
  16.  
  17. #include "uielements.h"
  18.  
  19.  
  20. struct UIELEMENTINFO {
  21.     UIELEMENT eElement;
  22.     UIFONT eFont;
  23.     UIBRUSH eBrush;
  24.     UIPEN ePen;
  25.     UICOLOR eText, eBk;
  26. };
  27.  
  28. struct UIFONTINFO {
  29.     UIFONT eFont;
  30.     LPCTSTR lfFaceName;
  31.     int nPointSize;
  32.     BOOL bBold;
  33.     HGDIOBJ hFont;
  34. };
  35.  
  36. struct UIBRUSHINFO {
  37.     UIBRUSH eBrush;
  38.     UICOLOR eColor;
  39.     HGDIOBJ hBrush;
  40.     HGDIOBJ hPen;
  41. };
  42.  
  43. struct UIPENINFO {
  44.     UIPEN ePen;
  45.     int fnPenStyle;
  46.     int nWidth;
  47.     UICOLOR eColor;
  48.     HGDIOBJ hPen;
  49. };
  50.  
  51. struct UICOLORINFO {
  52.     UICOLOR eColor;
  53.     COLORREF rgb;
  54. };
  55.  
  56. enum UIRECTTYPE {
  57.     UIR_OUTLINE,
  58.     UIR_NORMAL,
  59.     UIR_SOLID,
  60. };
  61.  
  62. #define UIG_PARAMS_DEFINE \
  63.     DWORD dwFlags, \
  64.     LPCWSTR wszUserNames, \
  65.     DWORD dwNumAcFor, \
  66.     LPDIACTIONFORMATW lpAcFor, \
  67.     LPDICOLORSET lpDIColorSet, \
  68.     IUnknown FAR *lpSurface, \
  69.     LPDICONFIGUREDEVICESCALLBACK lpCallback, \
  70.     LPVOID pvRefData
  71.  
  72. #define UIG_PARAMS_DEFINE_PASS \
  73.     dwFlags, \
  74.     wszUserNames, \
  75.     dwNumAcFor, \
  76.     lpAcFor, \
  77.     lpDIColorSet, \
  78.     lpSurface, \
  79.     lpCallback, \
  80.     pvRefData
  81.  
  82. class CUIGlobals
  83. {
  84. public:
  85.     CUIGlobals(UIG_PARAMS_DEFINE);
  86.     ~CUIGlobals();
  87.  
  88.     // UI Variables/States/Etc...
  89. public:
  90.     HRESULT GetInitResult() {return m_hrInit;}
  91.  
  92.     HINSTANCE GetInstance() {return m_hInst;}
  93.     LPDIRECTINPUT8W GetDI();
  94.  
  95.     int GetUserNameIndex(LPCWSTR);
  96.     int GetNumUserNames();
  97.     LPCWSTR GetUserName(int i);
  98.  
  99.     // GetSurface should not be used as only IDirect3DSurface8 should be used. Instead, use GetSurface3D.
  100.     IDirectDrawSurface *GetSurface();    // must release when done with returned surface (it's addref'd before returned)
  101.     IDirect3DSurface8 *GetSurface3D();    // must release when done with returned surface (it's addref'd before returned)
  102.     LPDICONFIGUREDEVICESCALLBACK GetCallback() {return m_lpCallback;}
  103.     LPVOID GetRefData() {return m_pvRefData;}
  104.     DWORD GetFlags() {return m_dwFlags;}
  105.     BOOL IsFlagSet(DWORD dwFlag) {return AreFlagsSet(dwFlag);}
  106.     BOOL AreFlagsSet(DWORD dwFlags) {return (m_dwFlags & dwFlags) == dwFlags;}
  107.     BOOL InEditMode() {return IsFlagSet(DICD_EDIT);}
  108.     const DIACTIONFORMATW &RefMasterAcFor(int i);
  109.     int GetNumMasterAcFors() {return m_MasterAcForArray.GetSize();}
  110.     const DICOLORSET &GetColorSet() const { return m_ColorSet; }
  111.  
  112.     void SetFinalResult(HRESULT);
  113.     HRESULT GetFinalResult();
  114.  
  115. private:
  116.     HRESULT Init(UIG_PARAMS_DEFINE);
  117.     void Dump();
  118.     HRESULT m_hrInit;
  119.     HRESULT m_hrFinalResult;
  120.  
  121.     BOOL InitColorsAndTablesAndObjects(LPDICOLORSET lpDIColorSet);
  122.  
  123.     BOOL IsValidUserIndex(int i);
  124.     BOOL IsValidMasterAcForIndex(int i);
  125.     HRESULT InitMasterAcForArray(const DIACTIONFORMATW *af, int n);
  126.     void ClearMasterAcForArray();
  127.  
  128.     HINSTANCE m_hInst;
  129.     LPDIRECTINPUT8W m_lpDI;
  130.  
  131.     DWORD m_dwFlags;
  132.     LPCWSTR m_wszUserNames;
  133.     CArray<DIACTIONFORMATW, DIACTIONFORMATW &> m_MasterAcForArray;
  134.     BOOL m_bUseColorSet;
  135.     DICOLORSET m_ColorSet;
  136.     void SetTableColor(UICOLOR, COLORREF);
  137.     IDirectDrawSurface *m_pSurface;
  138.     IDirect3DSurface8 *m_pSurface3D;
  139.     LPDICONFIGUREDEVICESCALLBACK m_lpCallback;
  140.     LPVOID m_pvRefData;
  141.  
  142.     BOOL m_bAllowEditLayout;
  143.  
  144.     // UI Elements...
  145. public:
  146.     UIELEMENTINFO *GetElementInfo(UIELEMENT);
  147.     UIFONTINFO *GetFontInfo(UIFONT);
  148.     UIBRUSHINFO *GetBrushInfo(UIBRUSH);
  149.     UIPENINFO *GetPenInfo(UIPEN);
  150.     UICOLORINFO *GetColorInfo(UICOLOR);
  151.     HGDIOBJ GetFont(UIELEMENT);
  152.     HGDIOBJ GetFont(UIFONT);
  153.     HGDIOBJ GetBrush(UIELEMENT);
  154.     HGDIOBJ GetBrush(UIBRUSH);
  155.     HGDIOBJ GetPen(UIELEMENT);
  156.     HGDIOBJ GetPen(UIBRUSH);
  157.     HGDIOBJ GetPen(UIPEN);
  158.     COLORREF GetBrushColor(UIELEMENT);
  159.     COLORREF GetPenColor(UIELEMENT);
  160.     COLORREF GetTextColor(UIELEMENT);
  161.     COLORREF GetBkColor(UIELEMENT);
  162.     COLORREF GetColor(UIBRUSH);
  163.     COLORREF GetColor(UIPEN);
  164.     COLORREF GetColor(UICOLOR);
  165.     
  166.     void DeleteObjects();
  167.     void CreateObjects();
  168.     void RecreateObjects();
  169.  
  170. private:
  171.     BOOL InitTables();
  172.     void ClearTables();
  173.  
  174.     UIELEMENTINFO *m_pElement;
  175.     int m_nElements;
  176.     UIFONTINFO *m_pFont;
  177.     int m_nFonts;
  178.     UIBRUSHINFO *m_pBrush;
  179.     int m_nBrushes;
  180.     UIPENINFO *m_pPen;
  181.     int m_nPens;
  182.     UICOLORINFO *m_pColor;
  183.     int m_nColors;
  184. };
  185.  
  186. class CPaintHelper
  187. {
  188. public:
  189.     CPaintHelper(CUIGlobals &uig, HDC hDC);
  190.     ~CPaintHelper();
  191.     CUIGlobals &m_uig;
  192.     HDC &m_hDC;
  193.  
  194.     void SetElement(UIELEMENT eElement);
  195.     void SetFont(UIFONT eFont);
  196.     void SetBrush(UIBRUSH eBrush);
  197.     void SetPen(UIPEN ePen);
  198.     void SetText(UICOLOR eText, UICOLOR eBk = UIC_LAST);
  199.  
  200.     BOOL LineTo(SPOINT p) {return LineTo(p.x, p.y);}
  201.     BOOL LineTo(int x, int y);
  202.     BOOL MoveTo(SPOINT p, SPOINT *last = NULL) {return MoveTo(p.x, p.y, last);}
  203.     BOOL MoveTo(int x, int y, SPOINT *last = NULL);
  204.  
  205.     BOOL Rectangle(SRECT r, UIRECTTYPE eType = UIR_NORMAL);
  206.     BOOL Rectangle(int l, int t, int r, int b, UIRECTTYPE eType = UIR_NORMAL)
  207.         {SRECT s(l,t,r,b); return Rectangle(s, eType);}
  208.  
  209. private:
  210.     HDC m_priv_hDC;
  211.     HGDIOBJ m_hOldFont, m_hOldBrush, m_hOldPen;
  212.     BOOL m_bOldFont, m_bOldBrush, m_bOldPen;
  213.     COLORREF m_oldtextcolor, m_oldbkcolor;
  214.     int m_oldbkmode;
  215.     UIFONT m_eFont;
  216.     UIBRUSH m_eBrush;
  217.     UIPEN m_ePen;
  218.     UICOLOR m_eText, m_eBk;
  219. };
  220.  
  221. #endif //__UIGLOBALS_H__
  222.