]>
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( 
  75     if ( M_PALETTEDATA 
&& M_PALETTEDATA
->m_hPalette
) 
  77         ::GpiSelectPalette(M_PALETTEDATA
->m_hPS
, NULLHANDLE
); 
  78         ::GpiDeletePalette((HPAL
)M_PALETTEDATA
->m_hPalette
); 
  81 } // end of wxPalette::FreeResource 
  83 bool wxPalette::Create( 
  85 , const unsigned char*              pRed
 
  86 , const unsigned char*              pGreen
 
  87 , const unsigned char*              pBlue
 
  94     m_refData 
= new wxPaletteRefData
; 
  95     pualTable 
= new ULONG
[n
]; 
  99     for (int i 
= 0; i 
< n
; i 
++) 
 101         pualTable
[i
] = (PC_RESERVED 
* 16777216) + ((int)pRed
[i
] * 65536) + ((int)pGreen
[i
] * 256) + (int)pBlue
[i
]; 
 103     M_PALETTEDATA
->m_hPalette 
= (WXHPALETTE
)::GpiCreatePalette( vHabmain
 
 111 } // end of wxPalette::Create 
 113 int wxPalette::GetPixel( 
 114   const unsigned char               cRed
 
 115 , const unsigned char               cGreen
 
 116 , const unsigned char               cBlue
 
 120     PULONG                          pualTable 
= NULL
; 
 122     ULONG                           ulRGB 
= (PC_RESERVED 
* 16777216) + 
 123                                             ((int)cRed 
* 65536) + 
 124                                             ((int)cGreen 
* 256) + 
 131     // Get number of entries first 
 133     ulNumEntries 
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
 
 134                                          ,M_PALETTEDATA
->m_hPS
 
 137                                          ,0                    // Force return of number entries 
 141     pualTable 
= new ULONG
[ulNumEntries
]; 
 144     // Now get the entries 
 146     ulNumEntries 
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
 
 147                                          ,M_PALETTEDATA
->m_hPS
 
 150                                          ,ulNumEntries         
// Force return of number entries 
 151                                          ,pualTable            
// Palette entry array with RGB values 
 154     // Now loop through and find the matching entry 
 157     for (i 
= 0; i 
< ulNumEntries
; i
++) 
 159         if (pualTable
[i
] == ulRGB
) 
 168 } // end of wxPalette::GetPixel 
 170 bool wxPalette::GetRGB( 
 172 , unsigned char*                    pRed
 
 173 , unsigned char*                    pGreen
 
 174 , unsigned char*                    pBlue
 
 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