]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/palette.cpp
8012364200fa3529d9b2df1a8a33e918aac8f039
1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.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(
72 if ( M_PALETTEDATA
&& M_PALETTEDATA
->m_hPalette
)
74 ::GpiSelectPalette(M_PALETTEDATA
->m_hPS
, NULLHANDLE
);
75 ::GpiDeletePalette((HPAL
)M_PALETTEDATA
->m_hPalette
);
78 } // end of wxPalette::FreeResource
80 bool wxPalette::Create(
82 , const unsigned char* pRed
83 , const unsigned char* pGreen
84 , const unsigned char* pBlue
91 m_refData
= new wxPaletteRefData
;
92 pualTable
= new ULONG
[n
];
96 for (int i
= 0; i
< n
; i
++)
98 pualTable
[i
] = (PC_RESERVED
* 16777216) + ((int)pRed
[i
] * 65536) + ((int)pGreen
[i
] * 256) + (int)pBlue
[i
];
100 M_PALETTEDATA
->m_hPalette
= (WXHPALETTE
)::GpiCreatePalette( vHabmain
108 } // end of wxPalette::Create
110 int wxPalette::GetPixel(
111 const unsigned char cRed
112 , const unsigned char cGreen
113 , const unsigned char cBlue
117 PULONG pualTable
= NULL
;
119 ULONG ulRGB
= (PC_RESERVED
* 16777216) +
120 ((int)cRed
* 65536) +
121 ((int)cGreen
* 256) +
128 // Get number of entries first
130 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
131 ,M_PALETTEDATA
->m_hPS
134 ,0 // Force return of number entries
138 pualTable
= new ULONG
[ulNumEntries
];
141 // Now get the entries
143 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
144 ,M_PALETTEDATA
->m_hPS
147 ,ulNumEntries
// Force return of number entries
148 ,pualTable
// Palette entry array with RGB values
151 // Now loop through and find the matching entry
154 for (i
= 0; i
< ulNumEntries
; i
++)
156 if (pualTable
[i
] == ulRGB
)
165 } // end of wxPalette::GetPixel
167 bool wxPalette::GetRGB(
169 , unsigned char* pRed
170 , unsigned char* pGreen
171 , unsigned char* pBlue
174 PULONG pualTable
= NULL
;
181 if (nIndex
< 0 || nIndex
> 255)
184 // Get number of entries first
186 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
187 ,M_PALETTEDATA
->m_hPS
190 ,0 // Force return of number entries
194 pualTable
= new ULONG
[ulNumEntries
];
197 // Now get the entries
199 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
200 ,M_PALETTEDATA
->m_hPS
203 ,ulNumEntries
// Force return of number entries
204 ,pualTable
// Palette entry array with RGB values
207 memcpy(&vRGB
, &pualTable
[nIndex
], sizeof(RGB2
));
209 *pGreen
= vRGB
.bGreen
;
212 } // end of wxPalette::GetRGB
214 void wxPalette::SetHPALETTE(
219 m_refData
= new wxPaletteRefData
;
221 M_PALETTEDATA
->m_hPalette
= hPal
;
222 } // end of wxPalette::SetHPALETTE
224 void wxPalette::SetPS(
229 m_refData
= new wxPaletteRefData
;
231 ::GpiSelectPalette(M_PALETTEDATA
->m_hPS
, M_PALETTEDATA
->m_hPalette
);
232 M_PALETTEDATA
->m_hPS
= hPS
;
233 } // end of wxPalette::SetHPALETTE