]> git.saurik.com Git - wxWidgets.git/commitdiff
Add alpha component to wxColour
authorRobin Dunn <robin@alldunn.com>
Sat, 26 Aug 2006 20:37:29 +0000 (20:37 +0000)
committerRobin Dunn <robin@alldunn.com>
Sat, 26 Aug 2006 20:37:29 +0000 (20:37 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40849 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

wxPython/docs/CHANGES.txt
wxPython/src/_colour.i
wxPython/src/helpers.cpp

index c9b8d998f884dd76c50085d0cc84c278db680d2c..61216657369def444019936b85cf9e82bcbc0c26 100644 (file)
@@ -204,6 +204,11 @@ The wx.html.HTML_FONT_SIZE_x constants are no longer available as the
 default sizes are now calculated at runtime based on the size of the
 normal GUI font.
 
 default sizes are now calculated at runtime based on the size of the
 normal GUI font.
 
+wx.Colour now includes an alpha component, which defaults to
+wx.ALPHA_OPAQUE.  This is in preparation for allowing various new
+alpha blening functionality using wx.Colour objects, such as drawing
+with pens and brushes on a wx.DC.  
+
 
 
 
 
 
 
index 20467993dc873aac83cc68979bb8842f44a121b0..9934bfca237eb8732c6962b78ab4e2cb2384e287 100644 (file)
@@ -23,6 +23,11 @@ enum {
     wxC2S_HTML_SYNTAX,      // return colour in #rrggbb syntax     
 };
 
     wxC2S_HTML_SYNTAX,      // return colour in #rrggbb syntax     
 };
 
+enum {
+    wxALPHA_TRANSPARENT,
+    wxALPHA_OPAQUE
+};
+
 
 DocStr(wxColour,
 "A colour is an object representing a combination of Red, Green, and
 
 DocStr(wxColour,
 "A colour is an object representing a combination of Red, Green, and
@@ -53,7 +58,7 @@ class wxColour : public wxObject {
 public:
     
     DocCtorStr(
 public:
     
     DocCtorStr(
-        wxColour(byte red=0, byte green=0, byte blue=0),
+        wxColour(byte red=0, byte green=0, byte blue=0, byte alpha=wxALPHA_OPAQUE),
         "Constructs a colour from red, green and blue values.
 
 :see: Alternate constructors `wx.NamedColour` and `wx.ColourRGB`.
         "Constructs a colour from red, green and blue values.
 
 :see: Alternate constructors `wx.NamedColour` and `wx.ColourRGB`.
@@ -85,13 +90,17 @@ public:
         byte , Blue(),
         "Returns the blue intensity.", "");
     
         byte , Blue(),
         "Returns the blue intensity.", "");
     
+    DocDeclStr(
+        byte , Alpha(),
+        "Returns the Alpha value.", "");
+    
     DocDeclStr(
         bool , Ok(),
         "Returns True if the colour object is valid (the colour has been
 initialised with RGB values).", "");
     
     DocDeclStr(
     DocDeclStr(
         bool , Ok(),
         "Returns True if the colour object is valid (the colour has been
 initialised with RGB values).", "");
     
     DocDeclStr(
-        void , Set(byte red, byte green, byte blue),
+        void , Set(byte red, byte green, byte blue, byte alpha=wxALPHA_OPAQUE),
         "Sets the RGB intensity values.", "");
 
     DocDeclStrName(
         "Sets the RGB intensity values.", "");
 
     DocDeclStrName(
@@ -155,19 +164,23 @@ is returned if the pixel is invalid (on X, unallocated).", "");
         DocAStr(Get,
                 "Get() -> (r, g, b)",
                 "Returns the RGB intensity values as a tuple.", "");
         DocAStr(Get,
                 "Get() -> (r, g, b)",
                 "Returns the RGB intensity values as a tuple.", "");
-        PyObject* Get() {
-            PyObject* rv = PyTuple_New(3);
+        PyObject* Get(bool includeAlpha=false) {
+            PyObject* rv = PyTuple_New(includeAlpha ? 4 : 3);
             int red = -1;
             int green = -1;
             int blue = -1;
             int red = -1;
             int green = -1;
             int blue = -1;
+            int alpha = wxALPHA_OPAQUE;
             if (self->Ok()) {
                 red =   self->Red();
                 green = self->Green();
                 blue =  self->Blue();
             if (self->Ok()) {
                 red =   self->Red();
                 green = self->Green();
                 blue =  self->Blue();
+                alpha = self->Alpha();
             }
             PyTuple_SetItem(rv, 0, PyInt_FromLong(red));
             PyTuple_SetItem(rv, 1, PyInt_FromLong(green));
             PyTuple_SetItem(rv, 2, PyInt_FromLong(blue));
             }
             PyTuple_SetItem(rv, 0, PyInt_FromLong(red));
             PyTuple_SetItem(rv, 1, PyInt_FromLong(green));
             PyTuple_SetItem(rv, 2, PyInt_FromLong(blue));
+            if (includeAlpha)
+                PyTuple_SetItem(rv, 3, PyInt_FromLong(alpha));                
             return rv;
         }
 
             return rv;
         }
 
@@ -181,11 +194,11 @@ is returned if the pixel is invalid (on X, unallocated).", "");
 
     %pythoncode {
         asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
 
     %pythoncode {
         asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
-        def __str__(self):                  return str(self.Get())
-        def __repr__(self):                 return 'wx.Colour' + str(self.Get())
+        def __str__(self):                  return str(self.Get(True))
+        def __repr__(self):                 return 'wx.Colour' + str(self.Get(True))
         def __nonzero__(self):              return self.Ok()
         __safe_for_unpickling__ = True
         def __nonzero__(self):              return self.Ok()
         __safe_for_unpickling__ = True
-        def __reduce__(self):               return (Colour, self.Get())
+        def __reduce__(self):               return (Colour, self.Get(True))
         }
 };
 
         }
 };
 
index d562546189a972676fcc4bb18b82b1e8de7ba3c8..9c983e008bea51e44f7f97a1b29e0913336315f8 100644 (file)
@@ -2510,7 +2510,7 @@ bool wxColour_helper(PyObject* source, wxColour** obj) {
             return true;
         }
     }
             return true;
         }
     }
-    // last chance: 3-tuple of integers is expected
+    // last chance: 3-tuple or 4-tuple of integers is expected
     else if (PySequence_Check(source) && PyObject_Length(source) == 3) {
         PyObject* o1 = PySequence_GetItem(source, 0);
         PyObject* o2 = PySequence_GetItem(source, 1);
     else if (PySequence_Check(source) && PyObject_Length(source) == 3) {
         PyObject* o1 = PySequence_GetItem(source, 0);
         PyObject* o2 = PySequence_GetItem(source, 1);
@@ -2527,10 +2527,29 @@ bool wxColour_helper(PyObject* source, wxColour** obj) {
         Py_DECREF(o3);
         return true;
     }
         Py_DECREF(o3);
         return true;
     }
+    else if (PySequence_Check(source) && PyObject_Length(source) == 4) {
+        PyObject* o1 = PySequence_GetItem(source, 0);
+        PyObject* o2 = PySequence_GetItem(source, 1);
+        PyObject* o3 = PySequence_GetItem(source, 2);
+        PyObject* o4 = PySequence_GetItem(source, 3);
+        if (!PyNumber_Check(o1) || !PyNumber_Check(o2) || !PyNumber_Check(o3) || !PyNumber_Check(o4)) {
+            Py_DECREF(o1);
+            Py_DECREF(o2);
+            Py_DECREF(o3);
+            Py_DECREF(o4);
+            goto error;
+        }
+        **obj = wxColour(PyInt_AsLong(o1), PyInt_AsLong(o2), PyInt_AsLong(o3), PyInt_AsLong(o4));
+        Py_DECREF(o1);
+        Py_DECREF(o2);
+        Py_DECREF(o3);
+        Py_DECREF(o4);
+        return true;
+    }
 
  error:
     PyErr_SetString(PyExc_TypeError,
 
  error:
     PyErr_SetString(PyExc_TypeError,
-                    "Expected a wxColour object or a string containing a colour name or '#RRGGBB'.");
+                    "Expected a wxColour object, a string containing a colour name or '#RRGGBB', or a 3- or 4-tuple of integers.");
     return false;
 }
 
     return false;
 }