use wxColourDatabase::Find() instead of deprecated FindColour(); some minor code cleanup
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24228 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: colour.h
|
// Name: wx/msw/colour.h
|
||||||
// Purpose: wxColour class
|
// Purpose: wxColour class
|
||||||
// Author: Julian Smart
|
// Author: Julian Smart
|
||||||
// Modified by:
|
// Modified by:
|
||||||
@@ -15,17 +15,27 @@
|
|||||||
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
|
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
|
||||||
#pragma interface "colour.h"
|
#pragma interface "colour.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/object.h"
|
#include "wx/object.h"
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
// Colour
|
// Colour
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class WXDLLEXPORT wxColour : public wxObject
|
class WXDLLEXPORT wxColour : public wxObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// ctors
|
// constructors
|
||||||
|
// ------------
|
||||||
|
|
||||||
// default
|
// default
|
||||||
wxColour();
|
wxColour() { Init(); }
|
||||||
// from RGB
|
|
||||||
wxColour( unsigned char red, unsigned char green, unsigned char blue );
|
// from separate RGB
|
||||||
|
wxColour( unsigned char red, unsigned char green, unsigned char blue )
|
||||||
|
{ Set(red, green, blue); }
|
||||||
|
|
||||||
|
// from packed RGB
|
||||||
wxColour( unsigned long colRGB ) { Set(colRGB); }
|
wxColour( unsigned long colRGB ) { Set(colRGB); }
|
||||||
|
|
||||||
// implicit conversion from the colour name
|
// implicit conversion from the colour name
|
||||||
@@ -40,6 +50,10 @@ public:
|
|||||||
// dtor
|
// dtor
|
||||||
~wxColour();
|
~wxColour();
|
||||||
|
|
||||||
|
|
||||||
|
// other methods
|
||||||
|
// -------------
|
||||||
|
|
||||||
// to have the matching Create also for this class
|
// to have the matching Create also for this class
|
||||||
void Create( unsigned char red, unsigned char green, unsigned char blue )
|
void Create( unsigned char red, unsigned char green, unsigned char blue )
|
||||||
{ Set(red, green, blue); }
|
{ Set(red, green, blue); }
|
||||||
@@ -56,6 +70,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// accessors
|
// accessors
|
||||||
|
// ---------
|
||||||
|
|
||||||
bool Ok() const {return m_isInit; }
|
bool Ok() const {return m_isInit; }
|
||||||
|
|
||||||
unsigned char Red() const { return m_red; }
|
unsigned char Red() const { return m_red; }
|
||||||
@@ -84,7 +100,8 @@ private:
|
|||||||
unsigned char m_blue;
|
unsigned char m_blue;
|
||||||
unsigned char m_green;
|
unsigned char m_green;
|
||||||
|
|
||||||
// helper func
|
// ctors helpers
|
||||||
|
void Init();
|
||||||
void InitFromName(const wxString& colourName);
|
void InitFromName(const wxString& colourName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -70,29 +70,18 @@ IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
|
|||||||
|
|
||||||
// Colour
|
// Colour
|
||||||
|
|
||||||
wxColour::wxColour ()
|
void wxColour::Init()
|
||||||
{
|
{
|
||||||
m_isInit = FALSE;
|
m_isInit = FALSE;
|
||||||
m_pixel = 0;
|
m_pixel = 0;
|
||||||
m_red = m_blue = m_green = 0;
|
m_red =
|
||||||
}
|
m_blue =
|
||||||
|
m_green = 0;
|
||||||
wxColour::wxColour (unsigned char r, unsigned char g, unsigned char b)
|
|
||||||
{
|
|
||||||
m_red = r;
|
|
||||||
m_green = g;
|
|
||||||
m_blue = b;
|
|
||||||
m_isInit = TRUE;
|
|
||||||
m_pixel = PALETTERGB (m_red, m_green, m_blue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxColour::wxColour (const wxColour& col)
|
wxColour::wxColour (const wxColour& col)
|
||||||
{
|
{
|
||||||
m_red = col.m_red;
|
*this = col;
|
||||||
m_green = col.m_green;
|
|
||||||
m_blue = col.m_blue;
|
|
||||||
m_isInit = col.m_isInit;
|
|
||||||
m_pixel = col.m_pixel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxColour& wxColour::operator=(const wxColour& col)
|
wxColour& wxColour::operator=(const wxColour& col)
|
||||||
@@ -105,24 +94,20 @@ wxColour& wxColour::operator =(const wxColour& col)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxColour::InitFromName(const wxString& col)
|
void wxColour::InitFromName(const wxString& name)
|
||||||
{
|
{
|
||||||
wxColour *the_colour = wxTheColourDatabase->FindColour (col);
|
if ( wxTheColourDatabase )
|
||||||
if (the_colour)
|
|
||||||
{
|
{
|
||||||
m_red = the_colour->Red ();
|
wxColour col = wxTheColourDatabase->Find(name);
|
||||||
m_green = the_colour->Green ();
|
if ( col.Ok() )
|
||||||
m_blue = the_colour->Blue ();
|
{
|
||||||
m_isInit = TRUE;
|
*this = col;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
m_red = 0;
|
|
||||||
m_green = 0;
|
|
||||||
m_blue = 0;
|
|
||||||
m_isInit = FALSE;
|
|
||||||
}
|
}
|
||||||
m_pixel = PALETTERGB (m_red, m_green, m_blue);
|
|
||||||
|
// leave invalid
|
||||||
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxColour::~wxColour()
|
wxColour::~wxColour()
|
||||||
@@ -137,3 +122,4 @@ void wxColour::Set (unsigned char r, unsigned char g, unsigned char b)
|
|||||||
m_isInit = TRUE;
|
m_isInit = TRUE;
|
||||||
m_pixel = PALETTERGB (m_red, m_green, m_blue);
|
m_pixel = PALETTERGB (m_red, m_green, m_blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user