]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/palette.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/palette.cpp
7 // Copyright: (c) AUTHOR
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
16 #include "wx/string.h"
17 #include "wx/os2/private.h"
18 #include "wx/palette.h"
27 IMPLEMENT_DYNAMIC_CLASS(wxPalette
, wxGDIObject
)
34 wxPaletteRefData::wxPaletteRefData()
36 m_hPalette
= NULLHANDLE
;
38 } // end of wxPaletteRefData::wxPaletteRefData
40 wxPaletteRefData::~wxPaletteRefData()
44 } // end of wxPaletteRefData::~wxPaletteRefData
46 wxPalette::wxPalette()
48 } // end of wxPalette::wxPalette
52 , const unsigned char* pRed
53 , const unsigned char* pGreen
54 , const unsigned char* pBlue
62 } // end of wxPalette::wxPalette
64 wxPalette::~wxPalette()
66 } // end of wxPalette::~wxPalette
68 bool wxPalette::FreeResource( bool WXUNUSED(bForce
) )
70 if ( M_PALETTEDATA
&& M_PALETTEDATA
->m_hPalette
)
72 ::GpiSelectPalette(M_PALETTEDATA
->m_hPS
, NULLHANDLE
);
73 ::GpiDeletePalette((HPAL
)M_PALETTEDATA
->m_hPalette
);
76 } // end of wxPalette::FreeResource
78 bool wxPalette::Create( int n
,
79 const unsigned char* pRed
,
80 const unsigned char* pGreen
,
81 const unsigned char* pBlue
)
87 m_refData
= new wxPaletteRefData
;
88 pualTable
= new ULONG
[n
];
92 for (int i
= 0; i
< n
; i
++)
94 pualTable
[i
] = (PC_RESERVED
* 16777216) + ((int)pRed
[i
] * 65536) + ((int)pGreen
[i
] * 256) + (int)pBlue
[i
];
96 M_PALETTEDATA
->m_hPalette
= (WXHPALETTE
)::GpiCreatePalette( vHabmain
104 } // end of wxPalette::Create
106 wxGDIRefData
*wxPalette::CreateGDIRefData() const
108 return new wxPaletteRefData
;
111 wxGDIRefData
*wxPalette::CloneGDIRefData(const wxGDIRefData
*data
) const
113 return new wxPaletteRefData(*static_cast<const wxPaletteRefData
*>(data
));
116 int wxPalette::GetPixel( unsigned char cRed
,
117 unsigned char cGreen
,
118 unsigned char cBlue
) const
121 PULONG pualTable
= NULL
;
123 ULONG ulRGB
= (PC_RESERVED
* 16777216) +
124 ((int)cRed
* 65536) +
125 ((int)cGreen
* 256) +
132 // Get number of entries first
134 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
135 ,M_PALETTEDATA
->m_hPS
138 ,0 // Force return of number entries
142 pualTable
= new ULONG
[ulNumEntries
];
145 // Now get the entries
147 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
148 ,M_PALETTEDATA
->m_hPS
151 ,ulNumEntries
// Force return of number entries
152 ,pualTable
// Palette entry array with RGB values
155 // Now loop through and find the matching entry
158 for (i
= 0; i
< ulNumEntries
; i
++)
160 if (pualTable
[i
] == ulRGB
)
169 } // end of wxPalette::GetPixel
171 bool wxPalette::GetRGB( int nIndex
,
173 unsigned char* pGreen
,
174 unsigned char* pBlue
) const
176 PULONG pualTable
= NULL
;
183 if (nIndex
< 0 || nIndex
> 255)
186 // Get number of entries first
188 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
189 ,M_PALETTEDATA
->m_hPS
192 ,0 // Force return of number entries
196 pualTable
= new ULONG
[ulNumEntries
];
199 // Now get the entries
201 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
202 ,M_PALETTEDATA
->m_hPS
205 ,ulNumEntries
// Force return of number entries
206 ,pualTable
// Palette entry array with RGB values
209 memcpy(&vRGB
, &pualTable
[nIndex
], sizeof(RGB2
));
211 *pGreen
= vRGB
.bGreen
;
214 } // end of wxPalette::GetRGB
216 void wxPalette::SetHPALETTE(
221 m_refData
= new wxPaletteRefData
;
223 M_PALETTEDATA
->m_hPalette
= hPal
;
224 } // end of wxPalette::SetHPALETTE
226 void wxPalette::SetPS(
231 m_refData
= new wxPaletteRefData
;
233 ::GpiSelectPalette(M_PALETTEDATA
->m_hPS
, M_PALETTEDATA
->m_hPalette
);
234 M_PALETTEDATA
->m_hPS
= hPS
;
235 } // end of wxPalette::SetHPALETTE