home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / source / xpal.cpp < prev    next >
C/C++ Source or Header  |  1997-04-02  |  4KB  |  120 lines

  1. #define INCL_GRE_COLORTABLE
  2. #include <xheaders.h>
  3. #include <pmddim.h>
  4. #include "xobject.h"
  5. #include "xgamexc.h"
  6. #include "xpal.h"
  7.  
  8.  
  9. /*DOC
  10. CLASS    XPalette
  11. FUNCTION XPalette
  12. GROUP    x-games/constructors/destructor
  13. REMARKS  Default constructor for a palette object. Queries the WPS colors (0-9, 246-255) and stores
  14.          them.
  15. */
  16. XPalette::XPalette()
  17. {
  18.         HPS     hpsDesktop;
  19.         HDC     hdcDesktop;
  20.         ULONG   aulWPSColors[10];
  21.         int     i;
  22.  
  23.         // get HPS and HDC of the root window
  24.         hpsDesktop = WinGetPS( HWND_DESKTOP );
  25.         hdcDesktop = GpiQueryDevice( hpsDesktop );
  26.  
  27.         // get WPS colors
  28.         GpiQueryRealColors( hpsDesktop, 0, 0, 10, (PLONG)aulWPSColors );
  29.         for( i = 0; i < 10; i++ )
  30.                 aulData[i] = aulWPSColors[i];
  31.         GpiQueryRealColors( hpsDesktop, 0, 246, 10, (PLONG)aulWPSColors );
  32.         for( i = 0; i < 10; i++ )
  33.                 aulData[246 + i] = aulWPSColors[i];
  34.  
  35.         WinReleasePS( hpsDesktop );
  36. } // XPalette::XPalette
  37.  
  38.  
  39. /*DOC
  40. CLASS    XPalette
  41. FUNCTION ~XPalette
  42. GROUP    x-games/constructors/destructor
  43. REMARKS  Destructor.
  44. */
  45.  
  46.  
  47. /*DOC
  48. CLASS    XPalette
  49. FUNCTION SetColors
  50. GROUP    x-games/constructors/destructor
  51. REMARKS  Sets colors for the palette. Please note that the colors 0-9 and 246-255 are used as 
  52.          systems colors by the WPS; so don't override them. 
  53. PARAMETERS       PULONG pulData                 Pointer to an array with the palette data.
  54.                                                 The format of the palette data is this:
  55.                                                         (R << 16) + (G << 8) + B
  56.                                                 The high order byte must be 0.
  57.            const ULONG  ulStart = 10            First entry to change
  58.            const ULONG  ulNumEntries = 236      Number of entries to change
  59. */
  60. void XPalette::SetColors( PULONG pulData, const ULONG ulStart, const ULONG ulNumEntries )
  61. {
  62.         memcpy( &aulData[ulStart], pulData, ulNumEntries * sizeof( ULONG ) );
  63. } // XPalette::SetColors
  64.  
  65.  
  66. /*DOC
  67. CLASS    XPalette
  68. FUNCTION Enable
  69. GROUP    x-games/constructors/destructor
  70. REMARKS  Enable this palette.
  71. */
  72. void XPalette::Enable( BOOL flInvalidate )
  73. {
  74.         HPS     hpsDesktop;
  75.         HDC     hdcDesktop;
  76.  
  77.         // get HPS and HDC of the root window
  78.         hpsDesktop = WinGetPS( HWND_DESKTOP );
  79.         hdcDesktop = GpiQueryDevice( hpsDesktop );
  80.  
  81.         GpiCreateLogColorTable( hpsDesktop,
  82.                                 LCOL_PURECOLOR | LCOL_REALIZABLE,
  83.                                 LCOLF_CONSECRGB,
  84.                                 0, 256, (PLONG)aulData             );
  85.  
  86.         if( !GreRealizeColorTable( hdcDesktop ) )
  87.                 throw XGameException( "XPalette: unable to set physical palette",
  88.                                       XGameException::XGERR_PALETTE               );
  89.  
  90.         if( flInvalidate )
  91.                 WinInvalidateRect( HWND_DESKTOP, (PRECTL)NULL, TRUE );
  92.  
  93.         WinReleasePS( hpsDesktop );
  94. } // XPalette::Enable
  95.  
  96.  
  97. /*DOC
  98. CLASS    XPalette
  99. FUNCTION Disable
  100. GROUP    x-games/constructors/destructor
  101. REMARKS  Disable this palette.
  102. */
  103. void XPalette::Disable( BOOL flInvalidate )
  104. {
  105.         HPS     hpsDesktop;
  106.         HDC     hdcDesktop;
  107.  
  108.         // get HPS and HDC of the root window
  109.         hpsDesktop = WinGetPS( HWND_DESKTOP );
  110.         hdcDesktop = GpiQueryDevice( hpsDesktop );
  111.  
  112.         GreUnrealizeColorTable( hdcDesktop );
  113.  
  114.         if( flInvalidate )
  115.                 WinInvalidateRect( HWND_DESKTOP, (PRECTL)NULL, TRUE );
  116.  
  117.         WinReleasePS( hpsDesktop );
  118. } // XPalette::Disable
  119.  
  120.