]>
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"
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( unsigned char cRed
,
110 unsigned char cGreen
,
111 unsigned char cBlue
) const
114 PULONG pualTable
= NULL
;
116 ULONG ulRGB
= (PC_RESERVED
* 16777216) +
117 ((int)cRed
* 65536) +
118 ((int)cGreen
* 256) +
125 // Get number of entries first
127 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
128 ,M_PALETTEDATA
->m_hPS
131 ,0 // Force return of number entries
135 pualTable
= new ULONG
[ulNumEntries
];
138 // Now get the entries
140 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
141 ,M_PALETTEDATA
->m_hPS
144 ,ulNumEntries
// Force return of number entries
145 ,pualTable
// Palette entry array with RGB values
148 // Now loop through and find the matching entry
151 for (i
= 0; i
< ulNumEntries
; i
++)
153 if (pualTable
[i
] == ulRGB
)
162 } // end of wxPalette::GetPixel
164 bool wxPalette::GetRGB( int nIndex
,
166 unsigned char* pGreen
,
167 unsigned char* pBlue
) const
169 PULONG pualTable
= NULL
;
176 if (nIndex
< 0 || nIndex
> 255)
179 // Get number of entries first
181 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
182 ,M_PALETTEDATA
->m_hPS
185 ,0 // Force return of number entries
189 pualTable
= new ULONG
[ulNumEntries
];
192 // Now get the entries
194 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
195 ,M_PALETTEDATA
->m_hPS
198 ,ulNumEntries
// Force return of number entries
199 ,pualTable
// Palette entry array with RGB values
202 memcpy(&vRGB
, &pualTable
[nIndex
], sizeof(RGB2
));
204 *pGreen
= vRGB
.bGreen
;
207 } // end of wxPalette::GetRGB
209 void wxPalette::SetHPALETTE(
214 m_refData
= new wxPaletteRefData
;
216 M_PALETTEDATA
->m_hPalette
= hPal
;
217 } // end of wxPalette::SetHPALETTE
219 void wxPalette::SetPS(
224 m_refData
= new wxPaletteRefData
;
226 ::GpiSelectPalette(M_PALETTEDATA
->m_hPS
, M_PALETTEDATA
->m_hPalette
);
227 M_PALETTEDATA
->m_hPS
= hPS
;
228 } // end of wxPalette::SetHPALETTE