1//---------------------------------------------------------------------------
2// This file is generated by wxPython's SIP generator.  Do not edit by hand.
3//
4// Copyright: (c) 2018 by Total Control Software
5// License:   wxWindows License
6//
7// This file will be included by _core.sip
8//
9//---------------------------------------------------------------------------
10%ModuleCode
11    #ifdef __WXMAC__
12    #include <wx/osx/private.h>
13    #endif
14
15    #undef wxTransparentColour
16    wxColour wxTransparentColour(0, 0, 0, wxALPHA_TRANSPARENT);
17
18    wxColour testColourTypeMap(const wxColour& c)
19    {
20        return c;
21    }
22
23%End
24
25//---------------------------------------------------------------------------
26
27enum
28{
29    wxC2S_NAME,
30    wxC2S_CSS_SYNTAX,
31    wxC2S_HTML_SYNTAX
32};
33
34const int wxALPHA_TRANSPARENT;
35
36const int wxALPHA_OPAQUE;
37
38class wxColour : wxObject   /AllowNone/
39{
40    %Docstring
41        Colour()
42        Colour(red, green, blue, alpha=ALPHA_OPAQUE)
43        Colour(colRGB)
44        Colour(colour)
45
46        A colour is an object representing a combination of Red, Green, and
47        Blue (RGB) intensity values, and is used to determine drawing colours.
48    %End
49    %TypeHeaderCode
50        #include <wx/colour.h>
51    %End
52
53public:
54    wxColour();
55
56    wxColour(
57        unsigned char red   /PyInt/,
58        unsigned char green   /PyInt/,
59        unsigned char blue   /PyInt/,
60        unsigned char alpha   /PyInt/ = wxALPHA_OPAQUE
61    );
62
63    wxColour(
64        unsigned long colRGB
65    );
66
67    wxColour(
68        const wxColour & colour
69    );
70    %PreMethodCode
71        if (!wxPyCheckForApp()) return NULL;
72    %End
73
74    void SetRGB(
75        wxUint32 colRGB
76    );
77    %Docstring
78        SetRGB(colRGB)
79
80        Sets the RGB or RGBA colour values from a single 32 bit value.
81    %End
82
83    void SetRGBA(
84        wxUint32 colRGBA
85    );
86    %Docstring
87        SetRGBA(colRGBA)
88
89        Sets the RGB or RGBA colour values from a single 32 bit value.
90    %End
91
92    wxUint32 GetRGB() const;
93    %Docstring
94        GetRGB() -> Uint32
95
96        Gets the RGB or RGBA colour values as a single 32 bit value.
97    %End
98
99    wxUint32 GetRGBA() const;
100    %Docstring
101        GetRGBA() -> Uint32
102
103        Gets the RGB or RGBA colour values as a single 32 bit value.
104    %End
105
106    void Set(
107        unsigned char red   /PyInt/,
108        unsigned char green   /PyInt/,
109        unsigned char blue   /PyInt/,
110        unsigned char alpha   /PyInt/ = wxALPHA_OPAQUE
111    );
112    %Docstring
113        Set(red, green, blue, alpha=ALPHA_OPAQUE)
114        Set(RGB)
115        Set(str) -> bool
116
117        Sets the RGB intensity values using the given values (first overload),
118        extracting them from the packed long (second overload), using the
119        given string (third overload).
120    %End
121
122    void Set(
123        unsigned long RGB
124    );
125
126    bool Set(
127        const wxString & str
128    );
129
130    unsigned char Alpha() const   /PyInt/;
131    %Docstring
132        Alpha() -> unsignedchar
133
134        Returns the alpha value, on platforms where alpha is not yet
135        supported, this always returns wxALPHA_OPAQUE.
136    %End
137
138    unsigned char Blue() const   /PyInt/;
139    %Docstring
140        Blue() -> unsignedchar
141
142        Returns the blue intensity.
143    %End
144
145    wxString GetAsString(
146        long flags = wxC2S_NAME|wxC2S_CSS_SYNTAX
147    ) const;
148    %Docstring
149        GetAsString(flags=C2S_NAME|C2S_CSS_SYNTAX) -> String
150
151        Converts this colour to a wxString using the given flags.
152    %End
153
154    wxIntPtr* GetPixel();
155    %Docstring
156        GetPixel() -> IntPtr
157    %End
158    %MethodCode
159        PyErr_Clear();
160        Py_BEGIN_ALLOW_THREADS
161        sipRes = _wxColour_GetPixel(sipCpp);
162        Py_END_ALLOW_THREADS
163        if (PyErr_Occurred()) sipIsErr = 1;
164    %End
165    %TypeCode
166    wxIntPtr* _wxColour_GetPixel(wxColour* self)
167    {
168        #ifdef __WXGTK3__
169            return new wxIntPtr(0);
170        #else
171            return new wxIntPtr((wxIntPtr)self->GetPixel());
172        #endif
173    }
174    %End
175
176    unsigned char Green() const   /PyInt/;
177    %Docstring
178        Green() -> unsignedchar
179
180        Returns the green intensity.
181    %End
182
183    bool IsOk() const;
184    %Docstring
185        IsOk() -> bool
186
187        Returns true if the colour object is valid (the colour has been
188        initialised with RGB values).
189    %End
190
191    unsigned char Red() const   /PyInt/;
192    %Docstring
193        Red() -> unsignedchar
194
195        Returns the red intensity.
196    %End
197
198    bool operator!=(
199        const wxColour & colour
200    ) const;
201
202    bool operator==(
203        const wxColour & colour
204    ) const;
205
206    wxColour & MakeDisabled(
207        unsigned char brightness   /PyInt/ = 255
208    );
209    %Docstring
210        MakeDisabled(brightness=255) -> Colour
211        MakeDisabled(r, g, b, brightness=255) -> (r, g, b)
212
213        Make a disabled version of this colour.
214    %End
215
216    static
217    void MakeDisabled(
218        unsigned char * r   /In, Out/,
219        unsigned char * g   /In, Out/,
220        unsigned char * b   /In, Out/,
221        unsigned char brightness   /PyInt/ = 255
222    );
223
224    wxColour ChangeLightness(
225        int ialpha
226    ) const;
227    %Docstring
228        ChangeLightness(ialpha) -> Colour
229        ChangeLightness(r, g, b, ialpha) -> (r, g, b)
230
231        wxColour wrapper for ChangeLightness(r,g,b,ialpha).
232    %End
233
234    static
235    void ChangeLightness(
236        unsigned char * r   /In, Out/,
237        unsigned char * g   /In, Out/,
238        unsigned char * b   /In, Out/,
239        int ialpha
240    );
241
242    static
243    void MakeMono(
244        unsigned char * r   /Out/,
245        unsigned char * g   /Out/,
246        unsigned char * b   /Out/,
247        bool on
248    );
249    %Docstring
250        MakeMono(on) -> (r, g, b)
251
252        Assign 0 or 255 to rgb out parameters.
253    %End
254
255    static
256    void MakeGrey(
257        unsigned char * r   /In, Out/,
258        unsigned char * g   /In, Out/,
259        unsigned char * b   /In, Out/
260    );
261    %Docstring
262        MakeGrey(r, g, b) -> (r, g, b)
263        MakeGrey(r, g, b, weight_r, weight_g, weight_b) -> (r, g, b)
264
265        Create a grey colour from (in/out) rgb parameters using integer
266        arithmetic.
267    %End
268
269    static
270    void MakeGrey(
271        unsigned char * r   /In, Out/,
272        unsigned char * g   /In, Out/,
273        unsigned char * b   /In, Out/,
274        double weight_r,
275        double weight_g,
276        double weight_b
277    );
278
279    static
280    unsigned char AlphaBlend(
281        unsigned char fg   /PyInt/,
282        unsigned char bg   /PyInt/,
283        double alpha
284    )   /PyInt/;
285    %Docstring
286        AlphaBlend(fg, bg, alpha) -> unsignedchar
287
288        Blend colour, taking alpha into account.
289    %End
290
291    %Property(name=Pixel, get=GetPixel)
292    %Property(name=RGB, get=GetRGB, set=SetRGB)
293    %Property(name=RGBA, get=GetRGBA, set=SetRGBA)
294    %Property(name=red, get=Red)
295    %Property(name=green, get=Green)
296    %Property(name=blue, get=Blue)
297    %Property(name=alpha, get=Alpha)
298    void _copyFrom(const wxColour* other);
299    %Docstring
300        _copyFrom(other)
301
302        For internal use only.
303    %End
304    %MethodCode
305        PyErr_Clear();
306        Py_BEGIN_ALLOW_THREADS
307        _wxColour__copyFrom(sipCpp, other);
308        Py_END_ALLOW_THREADS
309        if (PyErr_Occurred()) sipIsErr = 1;
310    %End
311    %TypeCode
312    void _wxColour__copyFrom(wxColour* self, const wxColour* other)
313    {
314        *self = *other;
315    }
316    %End
317
318    PyObject* Get(bool includeAlpha=true);
319    %Docstring
320        Get(includeAlpha=True) -> (r,g,b) or (r,g,b,a)
321
322        Returns the RGB intensity values as a tuple, optionally the alpha
323        value as well.
324    %End
325    %MethodCode
326        PyErr_Clear();
327        Py_BEGIN_ALLOW_THREADS
328        sipRes = _wxColour_Get(sipCpp, includeAlpha);
329        Py_END_ALLOW_THREADS
330        if (PyErr_Occurred()) sipIsErr = 1;
331    %End
332    %TypeCode
333    PyObject* _wxColour_Get(wxColour* self, bool includeAlpha)
334    {
335        int red = -1;
336        int green = -1;
337        int blue = -1;
338        int alpha = wxALPHA_OPAQUE;
339        if (self->IsOk()) {
340            red =   self->Red();
341            green = self->Green();
342            blue =  self->Blue();
343            alpha = self->Alpha();
344        }
345        wxPyThreadBlocker blocker;
346        if (includeAlpha)
347            return sipBuildResult(0, "(iiii)", red, green, blue, alpha);
348        else
349            return sipBuildResult(0, "(iii)", red, green, blue);
350    }
351    %End
352
353    int __nonzero__();
354    %Docstring
355        __nonzero__() -> int
356    %End
357    %MethodCode
358        PyErr_Clear();
359        Py_BEGIN_ALLOW_THREADS
360        sipRes = _wxColour___nonzero__(sipCpp);
361        Py_END_ALLOW_THREADS
362        if (PyErr_Occurred()) sipIsErr = 1;
363    %End
364    %TypeCode
365    int _wxColour___nonzero__(wxColour* self)
366    {
367        return self->IsOk();
368    }
369    %End
370
371    int __bool__();
372    %Docstring
373        __bool__() -> int
374    %End
375    %MethodCode
376        PyErr_Clear();
377        Py_BEGIN_ALLOW_THREADS
378        sipRes = _wxColour___bool__(sipCpp);
379        Py_END_ALLOW_THREADS
380        if (PyErr_Occurred()) sipIsErr = 1;
381    %End
382    %TypeCode
383    int _wxColour___bool__(wxColour* self)
384    {
385        return self->IsOk();
386    }
387    %End
388
389    %ConvertToTypeCode
390        // is it just a typecheck?
391        if (!sipIsErr) {
392            if (sipPy == Py_None)
393                return 1;
394            if (sipCanConvertToType(sipPy, sipType_wxColour, SIP_NO_CONVERTORS))
395                return 1;
396            if (PyBytes_Check(sipPy) || PyUnicode_Check(sipPy))
397                return 1;
398            if (wxPyNumberSequenceCheck(sipPy, 4) || wxPyNumberSequenceCheck(sipPy, 3)) {
399                return 1;
400            }
401            return 0;
402        }
403
404        // otherwise do the conversion
405        // is it None?
406        if (sipPy == Py_None) {
407            *sipCppPtr = new wxColour(wxNullColour);
408            return sipGetState(sipTransferObj);
409        }
410        // Is it a string?
411        else if (PyBytes_Check(sipPy) || PyUnicode_Check(sipPy)) {
412            wxString spec = Py2wxString(sipPy);
413            if (!spec.empty()
414                && spec.GetChar(0) == '#'
415                && (spec.length() == 7 || spec.length() == 9)) {  // It's  #RRGGBB[AA]
416                long red, green, blue;
417                red = green = blue = 0;
418                spec.Mid(1,2).ToLong(&red,   16);
419                spec.Mid(3,2).ToLong(&green, 16);
420                spec.Mid(5,2).ToLong(&blue,  16);
421
422                if (spec.length() == 7)         // no alpha
423                    *sipCppPtr = new wxColour(red, green, blue);
424                else {                          // yes alpha
425                    long alpha;
426                    spec.Mid(7,2).ToLong(&alpha, 16);
427                    *sipCppPtr = new wxColour(red, green, blue, alpha);
428                }
429                return sipGetState(sipTransferObj);
430            }
431            else {                                       // assume it's a colour name
432                // check if alpha is there too
433                int pos;
434                if (((pos = spec.Find(':', true)) != wxNOT_FOUND) && (pos == spec.length()-3)) {
435                    long alpha;
436                    spec.Right(2).ToLong(&alpha, 16);
437                    wxColour c = wxColour(spec.Left(spec.length()-3));
438                    *sipCppPtr = new wxColour(c.Red(), c.Green(), c.Blue(), alpha);
439                }
440                else
441                    *sipCppPtr = new wxColour(spec);
442                return sipGetState(sipTransferObj);
443            }
444        }
445        // Is it a sequence? (if so then length was checked above)
446        else if (wxPyNumberSequenceCheck(sipPy)) {
447            size_t len = PySequence_Size(sipPy);
448
449            PyObject* o1 = PySequence_ITEM(sipPy, 0);
450            PyObject* o2 = PySequence_ITEM(sipPy, 1);
451            PyObject* o3 = PySequence_ITEM(sipPy, 2);
452            if (len == 3)
453                *sipCppPtr = new wxColour(wxPyInt_AsLong(o1), wxPyInt_AsLong(o2), wxPyInt_AsLong(o3));
454            else {
455                PyObject* o4 = PySequence_ITEM(sipPy, 3);
456                *sipCppPtr = new wxColour(wxPyInt_AsLong(o1), wxPyInt_AsLong(o2), wxPyInt_AsLong(o3),
457                                          wxPyInt_AsLong(o4));
458                Py_DECREF(o4);
459            }
460            Py_DECREF(o1);
461            Py_DECREF(o2);
462            Py_DECREF(o3);
463            return sipGetState(sipTransferObj);
464        }
465
466        // if we get this far then it must already be a wxColour instance
467        *sipCppPtr = reinterpret_cast<wxColour*>(sipConvertToType(
468            sipPy, sipType_wxColour, sipTransferObj, SIP_NO_CONVERTORS, 0, sipIsErr));
469        return 0; // not a new instance
470    %End
471};  // end of class wxColour
472
473
474%Extract(id=pycode_core)
475def _Colour_GetIM(self):
476    """
477    Returns an immutable representation of the ``wx.Colour`` object, based on ``namedtuple``.
478
479    This new object is hashable and can be used as a dictionary key,
480    be added to sets, etc.  It can be converted back into a real ``wx.Colour``
481    with a simple statement like this: ``obj = wx.Colour(imObj)``.
482    """
483    return _im_Colour(*self.Get())
484Colour.GetIM = _Colour_GetIM
485del _Colour_GetIM
486%End
487
488%Extract(id=pycode_core)
489def _Colour___str__(self):
490    return str(self.Get())
491Colour.__str__ = _Colour___str__
492del _Colour___str__
493%End
494
495%Extract(id=pycode_core)
496def _Colour___repr__(self):
497    return "wx.Colour"+str(self.Get())
498Colour.__repr__ = _Colour___repr__
499del _Colour___repr__
500%End
501
502%Extract(id=pycode_core)
503def _Colour___len__(self):
504    return len(self.Get())
505Colour.__len__ = _Colour___len__
506del _Colour___len__
507%End
508
509%Extract(id=pycode_core)
510def _Colour___reduce__(self):
511    return (Colour, self.Get())
512Colour.__reduce__ = _Colour___reduce__
513del _Colour___reduce__
514%End
515
516%Extract(id=pycode_core)
517def _Colour___getitem__(self, idx):
518    return self.Get()[idx]
519Colour.__getitem__ = _Colour___getitem__
520del _Colour___getitem__
521%End
522
523%Extract(id=pycode_core)
524def _Colour___setitem__(self, idx, val):
525    if idx == 0:   self.red = val
526    elif idx == 1: self.green = val
527    elif idx == 2: self.blue = val
528    elif idx == 3: self.alpha = val
529    else: raise IndexError
530Colour.__setitem__ = _Colour___setitem__
531del _Colour___setitem__
532%End
533
534%Extract(id=pycode_core)
535Colour.__safe_for_unpickling__ = True
536
537%End
538
539wxColour wxNullColour;
540
541wxColour wxTransparentColour;
542
543wxColour* MacThemeColour(int themeBrushID)   /Factory/;
544%Docstring
545    MacThemeColour(themeBrushID) -> Colour
546%End
547%MethodCode
548    PyErr_Clear();
549    Py_BEGIN_ALLOW_THREADS
550    sipRes = _MacThemeColour_function(themeBrushID);
551    Py_END_ALLOW_THREADS
552    if (PyErr_Occurred()) sipIsErr = 1;
553%End
554%ModuleCode
555wxColour* _MacThemeColour_function(int themeBrushID)
556{
557    #ifdef __WXMAC__
558        return new wxColour(wxMacCreateCGColorFromHITheme(themeBrushID));
559    #else
560        wxPyRaiseNotImplemented();
561        return NULL;
562    #endif
563}
564%End
565
566%Extract(id=pycode_core)
567# These stock colours will be initialized when the wx.App object is created.
568BLACK = Colour()
569BLUE = Colour()
570CYAN = Colour()
571GREEN = Colour()
572YELLOW = Colour()
573LIGHT_GREY = Colour()
574RED = Colour()
575WHITE = Colour()
576
577%End
578
579%Extract(id=pycode_core)
580from collections import namedtuple
581_im_Colour = namedtuple('_im_Colour', ['red', 'green', 'blue', 'alpha'])
582del namedtuple
583
584%End
585
586%Extract(id=pycode_core)
587NamedColour = wx.deprecated(Colour, "Use Colour instead.")
588
589%End
590
591    wxColour testColourTypeMap(const wxColour& c);
592
593
594
595//---------------------------------------------------------------------------
596
597