X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f5bb2251332040fd8ac7adb9406ea2516a077ed6..bbd92d1dbea02db8c28e9c17bfacc0563d855b25:/src/mac/carbon/palette.cpp diff --git a/src/mac/carbon/palette.cpp b/src/mac/carbon/palette.cpp index c847131f40..37b1826a80 100644 --- a/src/mac/carbon/palette.cpp +++ b/src/mac/carbon/palette.cpp @@ -1,47 +1,68 @@ ///////////////////////////////////////////////////////////////////////////// -// 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/defs.h" +#include "wx/wxprec.h" #if wxUSE_PALETTE #include "wx/palette.h" +#include "wx/colour.h" -#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxPalette, wxGDIObject) -#endif -/* - * Palette - * - */ +// ============================================================================ +// wxPaletteRefData +// ============================================================================ + +class WXDLLEXPORT wxPaletteRefData: public wxGDIRefData +{ +public: + wxPaletteRefData(); + wxPaletteRefData(const wxPaletteRefData& data); + virtual ~wxPaletteRefData(); + + virtual bool IsOk() const { return m_count > 0; } + +protected: + wxColour* m_palette; + wxInt32 m_count; + + friend class WXDLLIMPEXP_FWD_CORE wxPalette; + + DECLARE_NO_ASSIGN_CLASS(wxPaletteRefData) +}; wxPaletteRefData::wxPaletteRefData() { - m_palette = NULL ; - m_count = 0 ; + m_palette = NULL; + m_count = 0; +} + +wxPaletteRefData::wxPaletteRefData(const wxPaletteRefData& data) +{ + m_count = data.m_count; + m_palette = new wxColour[m_count]; + for ( wxInt32 i = 0; i < m_count; i++ ) + m_palette[i] = data.m_palette[i]; } wxPaletteRefData::~wxPaletteRefData() { - if (m_palette != NULL) { - delete[] m_palette ; - m_palette = NULL; - } + delete[] m_palette; } +// ============================================================================ +// wxPalette +// ============================================================================ + wxPalette::wxPalette() { } @@ -57,62 +78,78 @@ 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] ; - - for ( int i = 0 ; i < n ; ++i) - { - M_PALETTEDATA->m_palette[i].Set( red[i] , green[i] , blue[i] ) ; - } + M_PALETTEDATA->m_count = n ; + M_PALETTEDATA->m_palette = new wxColour[n] ; - return FALSE; + for ( int i = 0 ; i < n ; ++i) + { + M_PALETTEDATA->m_palette[i].Set( red[i] , green[i] , blue[i] ) ; + } + + 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 -1; + 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 ; - } + 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 >= M_PALETTEDATA->m_count) - return FALSE; + return false; - const wxColour& col = &M_PALETTEDATA->m_palette[index] ; + const wxColour& col = M_PALETTEDATA->m_palette[index] ; *red = col.Red() ; *green = col.Green() ; *blue = col.Blue() ; - - return TRUE; + + return true; } -#endif - // wxUSE_PALETTE +int wxPalette::GetColoursCount() const +{ + if (m_refData) + return M_PALETTEDATA->m_count; + + return 0; +} + +wxGDIRefData *wxPalette::CreateGDIRefData() const +{ + return new wxPaletteRefData; +} + +wxGDIRefData *wxPalette::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxPaletteRefData(*wx_static_cast(const wxPaletteRefData *, data)); +} +#endif // wxUSE_PALETTE