]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/palette.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   8 // Copyright:   (c) AUTHOR 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  19 #include "wx/string.h" 
  20 #include "wx/os2/private.h" 
  21 #include "wx/palette.h" 
  30 IMPLEMENT_DYNAMIC_CLASS(wxPalette
, wxGDIObject
) 
  37 wxPaletteRefData::wxPaletteRefData() 
  39     m_hPalette 
= NULLHANDLE
; 
  41 } // end of wxPaletteRefData::wxPaletteRefData 
  43 wxPaletteRefData::~wxPaletteRefData() 
  47 } // end of wxPaletteRefData::~wxPaletteRefData 
  49 wxPalette::wxPalette() 
  51 } // end of wxPalette::wxPalette 
  55 , const unsigned char*              pRed
 
  56 , const unsigned char*              pGreen
 
  57 , const unsigned char*              pBlue
 
  65 } // end of wxPalette::wxPalette 
  67 wxPalette::~wxPalette() 
  69 } // end of wxPalette::~wxPalette 
  71 bool wxPalette::FreeResource( bool WXUNUSED(bForce
) ) 
  73     if ( M_PALETTEDATA 
&& M_PALETTEDATA
->m_hPalette
) 
  75         ::GpiSelectPalette(M_PALETTEDATA
->m_hPS
, NULLHANDLE
); 
  76         ::GpiDeletePalette((HPAL
)M_PALETTEDATA
->m_hPalette
); 
  79 } // end of wxPalette::FreeResource 
  81 bool wxPalette::Create( int n
, 
  82                         const unsigned char* pRed
, 
  83                         const unsigned char* pGreen
, 
  84                         const unsigned char* pBlue 
) 
  90     m_refData 
= new wxPaletteRefData
; 
  91     pualTable 
= new ULONG
[n
]; 
  95     for (int i 
= 0; i 
< n
; i 
++) 
  97         pualTable
[i
] = (PC_RESERVED 
* 16777216) + ((int)pRed
[i
] * 65536) + ((int)pGreen
[i
] * 256) + (int)pBlue
[i
]; 
  99     M_PALETTEDATA
->m_hPalette 
= (WXHPALETTE
)::GpiCreatePalette( vHabmain
 
 107 } // end of wxPalette::Create 
 109 int wxPalette::GetPixel( 
 110   const unsigned char               cRed
 
 111 , const unsigned char               cGreen
 
 112 , const unsigned char               cBlue
 
 116     PULONG                          pualTable 
= NULL
; 
 118     ULONG                           ulRGB 
= (PC_RESERVED 
* 16777216) + 
 119                                             ((int)cRed 
* 65536) + 
 120                                             ((int)cGreen 
* 256) + 
 127     // Get number of entries first 
 129     ulNumEntries 
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
 
 130                                          ,M_PALETTEDATA
->m_hPS
 
 133                                          ,0                    // Force return of number entries 
 137     pualTable 
= new ULONG
[ulNumEntries
]; 
 140     // Now get the entries 
 142     ulNumEntries 
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
 
 143                                          ,M_PALETTEDATA
->m_hPS
 
 146                                          ,ulNumEntries         
// Force return of number entries 
 147                                          ,pualTable            
// Palette entry array with RGB values 
 150     // Now loop through and find the matching entry 
 153     for (i 
= 0; i 
< ulNumEntries
; i
++) 
 155         if (pualTable
[i
] == ulRGB
) 
 164 } // end of wxPalette::GetPixel 
 166 bool wxPalette::GetRGB( 
 168 , unsigned char*                    pRed
 
 169 , unsigned char*                    pGreen
 
 170 , unsigned char*                    pBlue
 
 173     PULONG                          pualTable 
= NULL
; 
 180     if (nIndex 
< 0 || nIndex 
> 255) 
 183     // Get number of entries first 
 185     ulNumEntries 
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
 
 186                                          ,M_PALETTEDATA
->m_hPS
 
 189                                          ,0                    // Force return of number entries 
 193     pualTable 
= new ULONG
[ulNumEntries
]; 
 196     // Now get the entries 
 198     ulNumEntries 
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
 
 199                                          ,M_PALETTEDATA
->m_hPS
 
 202                                          ,ulNumEntries         
// Force return of number entries 
 203                                          ,pualTable            
// Palette entry array with RGB values 
 206     memcpy(&vRGB
, &pualTable
[nIndex
], sizeof(RGB2
)); 
 208     *pGreen 
= vRGB
.bGreen
; 
 211 } // end of wxPalette::GetRGB 
 213 void wxPalette::SetHPALETTE( 
 218         m_refData 
= new wxPaletteRefData
; 
 220     M_PALETTEDATA
->m_hPalette 
= hPal
; 
 221 } // end of wxPalette::SetHPALETTE 
 223 void wxPalette::SetPS( 
 228         m_refData 
= new wxPaletteRefData
; 
 230     ::GpiSelectPalette(M_PALETTEDATA
->m_hPS
, M_PALETTEDATA
->m_hPalette
); 
 231     M_PALETTEDATA
->m_hPS 
= hPS
; 
 232 } // end of wxPalette::SetHPALETTE