]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/palette.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/os2/palette.cpp 
   8 // Copyright:   (c) AUTHOR 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  17     #include "wx/string.h" 
  18     #include "wx/os2/private.h" 
  19     #include "wx/palette.h" 
  28 IMPLEMENT_DYNAMIC_CLASS(wxPalette
, wxGDIObject
) 
  35 wxPaletteRefData::wxPaletteRefData() 
  37     m_hPalette 
= NULLHANDLE
; 
  39 } // end of wxPaletteRefData::wxPaletteRefData 
  41 wxPaletteRefData::~wxPaletteRefData() 
  45 } // end of wxPaletteRefData::~wxPaletteRefData 
  47 wxPalette::wxPalette() 
  49 } // end of wxPalette::wxPalette 
  53 , const unsigned char*              pRed
 
  54 , const unsigned char*              pGreen
 
  55 , const unsigned char*              pBlue
 
  63 } // end of wxPalette::wxPalette 
  65 wxPalette::~wxPalette() 
  67 } // end of wxPalette::~wxPalette 
  69 bool wxPalette::FreeResource( bool WXUNUSED(bForce
) ) 
  71     if ( M_PALETTEDATA 
&& M_PALETTEDATA
->m_hPalette
) 
  73         ::GpiSelectPalette(M_PALETTEDATA
->m_hPS
, NULLHANDLE
); 
  74         ::GpiDeletePalette((HPAL
)M_PALETTEDATA
->m_hPalette
); 
  77 } // end of wxPalette::FreeResource 
  79 bool wxPalette::Create( int n
, 
  80                         const unsigned char* pRed
, 
  81                         const unsigned char* pGreen
, 
  82                         const unsigned char* pBlue 
) 
  88     m_refData 
= new wxPaletteRefData
; 
  89     pualTable 
= new ULONG
[n
]; 
  93     for (int i 
= 0; i 
< n
; i 
++) 
  95         pualTable
[i
] = (PC_RESERVED 
* 16777216) + ((int)pRed
[i
] * 65536) + ((int)pGreen
[i
] * 256) + (int)pBlue
[i
]; 
  97     M_PALETTEDATA
->m_hPalette 
= (WXHPALETTE
)::GpiCreatePalette( vHabmain
 
 105 } // end of wxPalette::Create 
 107 wxGDIRefData 
*wxPalette::CreateGDIRefData() const 
 109     return new wxPaletteRefData
; 
 112 wxGDIRefData 
*wxPalette::CloneGDIRefData(const wxGDIRefData 
*data
) const 
 114     return new wxPaletteRefData(*static_cast<const wxPaletteRefData 
*>(data
)); 
 117 int wxPalette::GetPixel( unsigned char cRed
, 
 118                          unsigned char cGreen
, 
 119                          unsigned char cBlue
) const 
 122     PULONG  pualTable 
= NULL
; 
 124     ULONG   ulRGB 
= (PC_RESERVED 
* 16777216) + 
 125                     ((int)cRed 
* 65536) + 
 126                     ((int)cGreen 
* 256) + 
 133     // Get number of entries first 
 135     ulNumEntries 
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
 
 136                                          ,M_PALETTEDATA
->m_hPS
 
 139                                          ,0                    // Force return of number entries 
 143     pualTable 
= new ULONG
[ulNumEntries
]; 
 146     // Now get the entries 
 148     ulNumEntries 
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
 
 149                                          ,M_PALETTEDATA
->m_hPS
 
 152                                          ,ulNumEntries         
// Force return of number entries 
 153                                          ,pualTable            
// Palette entry array with RGB values 
 156     // Now loop through and find the matching entry 
 159     for (i 
= 0; i 
< ulNumEntries
; i
++) 
 161         if (pualTable
[i
] == ulRGB
) 
 170 } // end of wxPalette::GetPixel 
 172 bool wxPalette::GetRGB( int nIndex
, 
 174                         unsigned char* pGreen
, 
 175                         unsigned char* pBlue
) const 
 177     PULONG                          pualTable 
= NULL
; 
 184     if (nIndex 
< 0 || nIndex 
> 255) 
 187     // Get number of entries first 
 189     ulNumEntries 
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
 
 190                                          ,M_PALETTEDATA
->m_hPS
 
 193                                          ,0                    // Force return of number entries 
 197     pualTable 
= new ULONG
[ulNumEntries
]; 
 200     // Now get the entries 
 202     ulNumEntries 
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
 
 203                                          ,M_PALETTEDATA
->m_hPS
 
 206                                          ,ulNumEntries         
// Force return of number entries 
 207                                          ,pualTable            
// Palette entry array with RGB values 
 210     memcpy(&vRGB
, &pualTable
[nIndex
], sizeof(RGB2
)); 
 212     *pGreen 
= vRGB
.bGreen
; 
 215 } // end of wxPalette::GetRGB 
 217 void wxPalette::SetHPALETTE( 
 222         m_refData 
= new wxPaletteRefData
; 
 224     M_PALETTEDATA
->m_hPalette 
= hPal
; 
 225 } // end of wxPalette::SetHPALETTE 
 227 void wxPalette::SetPS( 
 232         m_refData 
= new wxPaletteRefData
; 
 234     ::GpiSelectPalette(M_PALETTEDATA
->m_hPS
, M_PALETTEDATA
->m_hPalette
); 
 235     M_PALETTEDATA
->m_hPS 
= hPS
; 
 236 } // end of wxPalette::SetHPALETTE