X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e9576ca53db96b462ed4c0b4bdf47d64c40203e4..ea8ca011a351c6aaa4009bedbf0cec19a7c57d98:/src/mac/carbon/palette.cpp?ds=sidebyside diff --git a/src/mac/carbon/palette.cpp b/src/mac/carbon/palette.cpp index f8db96f8d0..642af2b89b 100644 --- a/src/mac/carbon/palette.cpp +++ b/src/mac/carbon/palette.cpp @@ -1,23 +1,21 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: palette.cpp +// Name: src/mac/carbon/palette.cpp // Purpose: wxPalette -// Author: AUTHOR +// Author: Stefan Csomor // Modified by: -// Created: ??/??/98 +// Created: 1998-01-01 // RCS-ID: $Id$ -// Copyright: (c) AUTHOR -// Licence: wxWindows licence +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "palette.h" -#endif +#include "wx/wxprec.h" + +#if wxUSE_PALETTE #include "wx/palette.h" -#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject) -#endif /* * Palette @@ -26,12 +24,16 @@ IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject) wxPaletteRefData::wxPaletteRefData() { - // TODO + m_palette = NULL ; + m_count = 0 ; } wxPaletteRefData::~wxPaletteRefData() { - // TODO + if (m_palette != NULL) { + delete[] m_palette ; + m_palette = NULL; + } } wxPalette::wxPalette() @@ -49,34 +51,61 @@ wxPalette::~wxPalette() bool wxPalette::Create(int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue) { - UnRef(); + UnRef(); + + m_refData = new wxPaletteRefData; - m_refData = new wxPaletteRefData; + M_PALETTEDATA->m_count = n ; + M_PALETTEDATA->m_palette = new wxColour[n] ; - // TODO + for ( int i = 0 ; i < n ; ++i) + { + M_PALETTEDATA->m_palette[i].Set( red[i] , green[i] , blue[i] ) ; + } - return FALSE; + return false; } -int wxPalette::GetPixel(const unsigned char red, const unsigned char green, const unsigned char blue) const +int wxPalette::GetPixel(unsigned char red, unsigned char green, unsigned char blue) const { if ( !m_refData ) - return FALSE; - - // TODO - return FALSE; + return wxNOT_FOUND; + + long bestdiff = 3 * 256 ; + long bestpos = 0 ; + long currentdiff ; + + for ( int i = 0 ; i < M_PALETTEDATA->m_count ; ++i ) + { + const wxColour& col = M_PALETTEDATA->m_palette[i] ; + currentdiff = abs ( col.Red() - red ) + abs( col.Green() - green ) + abs ( col.Blue() - blue ) ; + if ( currentdiff < bestdiff ) + { + bestdiff = currentdiff ; + bestpos = i ; + if ( bestdiff == 0 ) + break ; + } + } + + return bestpos; } bool wxPalette::GetRGB(int index, unsigned char *red, unsigned char *green, unsigned char *blue) const { if ( !m_refData ) - return FALSE; + return false; - if (index < 0 || index > 255) - return FALSE; + if (index < 0 || index >= M_PALETTEDATA->m_count) + return false; - // TODO - return FALSE; -} + const wxColour& col = M_PALETTEDATA->m_palette[index] ; + *red = col.Red() ; + *green = col.Green() ; + *blue = col.Blue() ; + return true; +} +#endif +// wxUSE_PALETTE