]>
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"
17 #include "wx/string.h"
18 #include "wx/os2/private.h"
19 #include "wx/palette.h"
28 IMPLEMENT_DYNAMIC_CLASS(wxPalette
, wxGDIObject
)
35 wxPaletteRefData::wxPaletteRefData()
37 m_hPalette
= NULLHANDLE
;
39 } // end of wxPaletteRefData::wxPaletteRefData
41 wxPaletteRefData::~wxPaletteRefData()
45 } // end of wxPaletteRefData::~wxPaletteRefData
47 wxPalette::wxPalette()
49 } // end of wxPalette::wxPalette
53 , const unsigned char* pRed
54 , const unsigned char* pGreen
55 , const unsigned char* pBlue
63 } // end of wxPalette::wxPalette
65 wxPalette::~wxPalette()
67 } // end of wxPalette::~wxPalette
69 bool wxPalette::FreeResource( bool WXUNUSED(bForce
) )
71 if ( M_PALETTEDATA
&& M_PALETTEDATA
->m_hPalette
)
73 ::GpiSelectPalette(M_PALETTEDATA
->m_hPS
, NULLHANDLE
);
74 ::GpiDeletePalette((HPAL
)M_PALETTEDATA
->m_hPalette
);
77 } // end of wxPalette::FreeResource
79 bool wxPalette::Create( int n
,
80 const unsigned char* pRed
,
81 const unsigned char* pGreen
,
82 const unsigned char* pBlue
)
88 m_refData
= new wxPaletteRefData
;
89 pualTable
= new ULONG
[n
];
93 for (int i
= 0; i
< n
; i
++)
95 pualTable
[i
] = (PC_RESERVED
* 16777216) + ((int)pRed
[i
] * 65536) + ((int)pGreen
[i
] * 256) + (int)pBlue
[i
];
97 M_PALETTEDATA
->m_hPalette
= (WXHPALETTE
)::GpiCreatePalette( vHabmain
105 } // end of wxPalette::Create
107 int wxPalette::GetPixel( unsigned char cRed
,
108 unsigned char cGreen
,
109 unsigned char cBlue
) const
112 PULONG pualTable
= NULL
;
114 ULONG ulRGB
= (PC_RESERVED
* 16777216) +
115 ((int)cRed
* 65536) +
116 ((int)cGreen
* 256) +
123 // Get number of entries first
125 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
126 ,M_PALETTEDATA
->m_hPS
129 ,0 // Force return of number entries
133 pualTable
= new ULONG
[ulNumEntries
];
136 // Now get the entries
138 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
139 ,M_PALETTEDATA
->m_hPS
142 ,ulNumEntries
// Force return of number entries
143 ,pualTable
// Palette entry array with RGB values
146 // Now loop through and find the matching entry
149 for (i
= 0; i
< ulNumEntries
; i
++)
151 if (pualTable
[i
] == ulRGB
)
160 } // end of wxPalette::GetPixel
162 bool wxPalette::GetRGB( int nIndex
,
164 unsigned char* pGreen
,
165 unsigned char* pBlue
) const
167 PULONG pualTable
= NULL
;
174 if (nIndex
< 0 || nIndex
> 255)
177 // Get number of entries first
179 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
180 ,M_PALETTEDATA
->m_hPS
183 ,0 // Force return of number entries
187 pualTable
= new ULONG
[ulNumEntries
];
190 // Now get the entries
192 ulNumEntries
= ::GpiQueryPaletteInfo( M_PALETTEDATA
->m_hPalette
193 ,M_PALETTEDATA
->m_hPS
196 ,ulNumEntries
// Force return of number entries
197 ,pualTable
// Palette entry array with RGB values
200 memcpy(&vRGB
, &pualTable
[nIndex
], sizeof(RGB2
));
202 *pGreen
= vRGB
.bGreen
;
205 } // end of wxPalette::GetRGB
207 void wxPalette::SetHPALETTE(
212 m_refData
= new wxPaletteRefData
;
214 M_PALETTEDATA
->m_hPalette
= hPal
;
215 } // end of wxPalette::SetHPALETTE
217 void wxPalette::SetPS(
222 m_refData
= new wxPaletteRefData
;
224 ::GpiSelectPalette(M_PALETTEDATA
->m_hPS
, M_PALETTEDATA
->m_hPalette
);
225 M_PALETTEDATA
->m_hPS
= hPS
;
226 } // end of wxPalette::SetHPALETTE