and wxPG_EX_TOOLBAR_SEPARATOR styles for finer control over borders.
Borders around property grid are now native for consistency.
- Added wxXmlResource::LoadObjectRecursively().
+- Added wxColour::Set/GetRGB() and Set/GetRGBA() methods (Marcel Haß).
GTK:
ChannelType green,
ChannelType blue,
ChannelType alpha = wxALPHA_OPAQUE)
- { InitRGBA(red,green,blue, alpha); }
+ { InitRGBA(red, green, blue, alpha); }
// implemented in colourcmn.cpp
bool Set(const wxString &str)
// implemented in colourcmn.cpp
virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const;
+ void SetRGB(wxUint32 colRGB)
+ {
+ Set((ChannelType)(0xFF & colRGB),
+ (ChannelType)(0xFF & (colRGB >> 8)),
+ (ChannelType)(0xFF & (colRGB >> 16)));
+ }
+
+ void SetRGBA(wxUint32 colRGBA)
+ {
+ Set((ChannelType)(0xFF & colRGBA),
+ (ChannelType)(0xFF & (colRGBA >> 8)),
+ (ChannelType)(0xFF & (colRGBA >> 16)),
+ (ChannelType)(0xFF & (colRGBA >> 24)));
+ }
+
+ wxUint32 GetRGB() const
+ { return Red() | (Green() << 8) | (Blue() << 16); }
+
+ wxUint32 GetRGBA() const
+ { return Red() | (Green() << 8) | (Blue() << 16) | (Alpha() << 24); }
+
#if !wxCOLOUR_IS_GDIOBJECT
virtual bool IsOk() const= 0;
*/
virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const;
+ //@{
+ /**
+ Sets the RGB or RGBA colour values from a single 32 bit value.
+
+ The arguments @a colRGB and @a colRGBA should be of the form 0x00BBGGRR
+ and 0xAABBGGRR respectively where @c 0xRR, @c 0xGG, @c 0xBB and @c 0xAA
+ are the values of the red, blue, green and alpha components.
+
+ Notice the right-to-left order of components!
+
+ @see GetRGB(), GetRGBA()
+
+ @since 2.9.1
+ */
+ void SetRGB(wxUint32 colRGB);
+ void SetRGBA(wxUint32 colRGBA);
+ //@}
+
+ //@{
+ /**
+ Gets the RGB or RGBA colour values as a single 32 bit value.
+
+ The returned value is of the same form as expected by SetRGB() and
+ SetRGBA().
+
+ Notice that GetRGB() returns the value with 0 as its highest byte
+ independently of the value actually returned by Alpha(). So for a fully
+ opaque colour, the return value of GetRGBA() is @c 0xFFBBGGRR while
+ that of GetRGB() is @c 0x00BBGGRR.
+
+ @since 2.9.1
+ */
+ wxUint32 GetRGB() const;
+ wxUint32 GetRGBA() const;
+ //@}
+
/**
Returns a pixel value which is platform-dependent.
On Windows, a COLORREF is returned.
test_gui_rect.o \
test_gui_size.o \
test_gui_point.o \
+ test_gui_colour.o \
test_gui_measuring.o \
test_gui_config.o \
test_gui_comboboxtest.o \
test_gui_point.o: $(srcdir)/geometry/point.cpp $(TEST_GUI_ODEP)
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/geometry/point.cpp
+test_gui_colour.o: $(srcdir)/graphics/colour.cpp $(TEST_GUI_ODEP)
+ $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/graphics/colour.cpp
+
test_gui_measuring.o: $(srcdir)/graphics/measuring.cpp $(TEST_GUI_ODEP)
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/graphics/measuring.cpp
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: tests/graphics/colour.cpp
+// Purpose: wxColour unit test
+// Author: Vadim Zeitlin
+// Created: 2009-09-19
+// RCS-ID: $Id$
+// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#include "wx/colour.h"
+
+// ----------------------------------------------------------------------------
+// helper functions
+// ----------------------------------------------------------------------------
+
+namespace
+{
+ // by default colour components values are output incorrectly because they
+ // are unsigned chars, define a small helper struct which formats them in
+ // a more useful way
+ struct ColourChannel
+ {
+ ColourChannel(unsigned char value) : m_value(value) { }
+
+ unsigned char m_value;
+ };
+
+ std::ostream& operator<<(std::ostream& os, const ColourChannel& cc)
+ {
+ os.width(2);
+ os.fill('0');
+ os << static_cast<int>(cc.m_value);
+ return os;
+ }
+} // anonymous namespace
+
+// this operator is needed to use CPPUNIT_ASSERT_EQUAL with wxColour objects
+std::ostream& operator<<(std::ostream& os, const wxColour& c)
+{
+ os << std::hex << std::noshowbase
+ << "("
+ << ColourChannel(c.Red()) << ", "
+ << ColourChannel(c.Green()) << ", "
+ << ColourChannel(c.Blue());
+
+ if ( const unsigned char a = c.Alpha() )
+ {
+ os << ", " << ColourChannel(c.Alpha());
+ }
+
+ os << ")";
+
+ return os;
+}
+
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class ColourTestCase : public CppUnit::TestCase
+{
+public:
+ ColourTestCase() { }
+
+private:
+ CPPUNIT_TEST_SUITE( ColourTestCase );
+ CPPUNIT_TEST( GetSetRGB );
+ CPPUNIT_TEST_SUITE_END();
+
+ void GetSetRGB();
+
+ DECLARE_NO_COPY_CLASS(ColourTestCase)
+};
+
+// register in the unnamed registry so that these tests are run by default
+CPPUNIT_TEST_SUITE_REGISTRATION( ColourTestCase );
+
+// also include in it's own registry so that these tests can be run alone
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ColourTestCase, "ColourTestCase" );
+
+void ColourTestCase::GetSetRGB()
+{
+ wxColour c;
+ c.SetRGB(0x123456);
+
+ CPPUNIT_ASSERT_EQUAL( 0x56, (int)c.Red() );
+ CPPUNIT_ASSERT_EQUAL( 0x34, (int)c.Green() );
+ CPPUNIT_ASSERT_EQUAL( 0x12, (int)c.Blue() );
+ CPPUNIT_ASSERT_EQUAL( wxALPHA_OPAQUE, c.Alpha() );
+
+ CPPUNIT_ASSERT_EQUAL( wxColour(0x123456), c );
+ CPPUNIT_ASSERT_EQUAL( 0x123456, c.GetRGB() );
+
+ c.SetRGBA(0xaabbccdd);
+
+ CPPUNIT_ASSERT_EQUAL( 0xdd, (int)c.Red() );
+ CPPUNIT_ASSERT_EQUAL( 0xcc, (int)c.Green() );
+ CPPUNIT_ASSERT_EQUAL( 0xbb, (int)c.Blue() );
+ CPPUNIT_ASSERT_EQUAL( 0xaa, (int)c.Alpha() );
+
+ // FIXME: at least under wxGTK wxColour ctor doesn't take alpha channel
+ // into account: bug or feature?
+ //CPPUNIT_ASSERT_EQUAL( wxColour(0xaabbccdd), c );
+ CPPUNIT_ASSERT_EQUAL( 0xbbccdd, c.GetRGB() );
+ CPPUNIT_ASSERT_EQUAL( 0xaabbccdd, c.GetRGBA() );
+}
+
$(OBJS)\test_gui_rect.obj \
$(OBJS)\test_gui_size.obj \
$(OBJS)\test_gui_point.obj \
+ $(OBJS)\test_gui_colour.obj \
$(OBJS)\test_gui_measuring.obj \
$(OBJS)\test_gui_config.obj \
$(OBJS)\test_gui_comboboxtest.obj \
$(OBJS)\test_gui_point.obj: .\geometry\point.cpp
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\geometry\point.cpp
+$(OBJS)\test_gui_colour.obj: .\graphics\colour.cpp
+ $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\graphics\colour.cpp
+
$(OBJS)\test_gui_measuring.obj: .\graphics\measuring.cpp
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\graphics\measuring.cpp
$(OBJS)\test_gui_rect.o \
$(OBJS)\test_gui_size.o \
$(OBJS)\test_gui_point.o \
+ $(OBJS)\test_gui_colour.o \
$(OBJS)\test_gui_measuring.o \
$(OBJS)\test_gui_config.o \
$(OBJS)\test_gui_comboboxtest.o \
$(OBJS)\test_gui_point.o: ./geometry/point.cpp
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
+$(OBJS)\test_gui_colour.o: ./graphics/colour.cpp
+ $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
+
$(OBJS)\test_gui_measuring.o: ./graphics/measuring.cpp
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\test_gui_rect.obj \
$(OBJS)\test_gui_size.obj \
$(OBJS)\test_gui_point.obj \
+ $(OBJS)\test_gui_colour.obj \
$(OBJS)\test_gui_measuring.obj \
$(OBJS)\test_gui_config.obj \
$(OBJS)\test_gui_comboboxtest.obj \
$(OBJS)\test_gui_point.obj: .\geometry\point.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\geometry\point.cpp
+$(OBJS)\test_gui_colour.obj: .\graphics\colour.cpp
+ $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\graphics\colour.cpp
+
$(OBJS)\test_gui_measuring.obj: .\graphics\measuring.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\graphics\measuring.cpp
$(OBJS)\test_gui_rect.obj &
$(OBJS)\test_gui_size.obj &
$(OBJS)\test_gui_point.obj &
+ $(OBJS)\test_gui_colour.obj &
$(OBJS)\test_gui_measuring.obj &
$(OBJS)\test_gui_config.obj &
$(OBJS)\test_gui_comboboxtest.obj &
$(OBJS)\test_gui_point.obj : .AUTODEPEND .\geometry\point.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
+$(OBJS)\test_gui_colour.obj : .AUTODEPEND .\graphics\colour.cpp
+ $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
+
$(OBJS)\test_gui_measuring.obj : .AUTODEPEND .\graphics\measuring.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
geometry/rect.cpp
geometry/size.cpp
geometry/point.cpp
+ graphics/colour.cpp
graphics/measuring.cpp
config/config.cpp
controls/comboboxtest.cpp
# End Source File\r
# Begin Source File\r
\r
+SOURCE=.\graphics\colour.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\controls\comboboxtest.cpp\r
# End Source File\r
# Begin Source File\r
RelativePath=".\events\clone.cpp">\r
</File>\r
<File\r
+ RelativePath=".\graphics\colour.cpp">
+ </File>
+ <File
RelativePath=".\controls\comboboxtest.cpp">\r
</File>\r
<File\r
>\r
</File>\r
<File\r
+ RelativePath=".\graphics\colour.cpp"
+ >
+ </File>
+ <File
RelativePath=".\controls\comboboxtest.cpp"\r
>\r
</File>\r
>\r
</File>\r
<File\r
+ RelativePath=".\graphics\colour.cpp"
+ >
+ </File>
+ <File
RelativePath=".\controls\comboboxtest.cpp"\r
>\r
</File>\r