]>
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"
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
153 for (int i
= 0; i
< ulNumEntries
; i
++)
155 if (pualTable
[i
] == ulRGB
)
164 } // end of wxPalette::GetPixel
166 bool wxPalette::GetRGB(
168 , unsigned char* pRed
169 , unsigned char* pGreen
170 , unsigned char* pBlue
173 PULONG pualTable
= NULL
;
180 if (nIndex
< 0 || nIndex
> 255)
183 // Get number of entries first
185 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
186 ,M_PALETTEDATA
->m_hPS
189 ,0 // Force return of number entries
193 pualTable
= new ULONG
[ulNumEntries
];
196 // Now get the entries
198 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
199 ,M_PALETTEDATA
->m_hPS
202 ,ulNumEntries
// Force return of number entries
203 ,pualTable
// Palette entry array with RGB values
206 memcpy(&vRGB
, &pualTable
[nIndex
], sizeof(RGB2
));
208 *pGreen
= vRGB
.bGreen
;
211 } // end of wxPalette::GetRGB
213 void wxPalette::SetHPALETTE(
218 m_refData
= new wxPaletteRefData
;
220 M_PALETTEDATA
->m_hPalette
= hPal
;
221 } // end of wxPalette::SetHPALETTE
223 void wxPalette::SetPS(
228 m_refData
= new wxPaletteRefData
;
230 ::GpiSelectPalette(M_PALETTEDATA
->m_hPS
, M_PALETTEDATA
->m_hPalette
);
231 M_PALETTEDATA
->m_hPS
= hPS
;
232 } // end of wxPalette::SetHPALETTE