~ubuntu-branches/ubuntu/trusty/python-sfml/trusty

« back to all changes in this revision

Viewing changes to python/src/Color.cpp

  • Committer: Package Import Robot
  • Author(s): James Cowgill
  • Date: 2013-12-09 17:50:52 UTC
  • mfrom: (1.1.3) (8.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20131209175052-11v6drpb6g3yksst
Tags: 1.5.1.is.1.3+dfsg-1
* New upstream version 1.3 (from python-sfml.org)
  - This is a complete rewrite of the Python bindings for SFML2, and
    the new maintainer is using a different version numbering scheme.
* Added myself to the list of uploaders
* Change package priority from extra to optional
* Bumped standards version (to 3.9.5) and debhelper compat (to 9)
* Added Python 3 and documentation packages
* Improve package description for debug packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
////////////////////////////////////////////////////////////
2
 
//
3
 
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
4
 
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
5
 
//
6
 
// This software is provided 'as-is', without any express or implied warranty.
7
 
// In no event will the authors be held liable for any damages arising from the use of this software.
8
 
//
9
 
// Permission is granted to anyone to use this software for any purpose,
10
 
// including commercial applications, and to alter it and redistribute it freely,
11
 
// subject to the following restrictions:
12
 
//
13
 
// 1. The origin of this software must not be misrepresented;
14
 
//    you must not claim that you wrote the original software.
15
 
//    If you use this software in a product, an acknowledgment
16
 
//    in the product documentation would be appreciated but is not required.
17
 
//
18
 
// 2. Altered source versions must be plainly marked as such,
19
 
//    and must not be misrepresented as being the original software.
20
 
//
21
 
// 3. This notice may not be removed or altered from any source distribution.
22
 
//
23
 
////////////////////////////////////////////////////////////
24
 
 
25
 
#include "Color.hpp"
26
 
 
27
 
#include "offsetof.hpp"
28
 
#include "compat.hpp"
29
 
 
30
 
static PyMemberDef PySfColor_members[] = {
31
 
        {(char *)"r", T_UBYTE, offsetof(PySfColor, r), 0, (char *)"Red component."},
32
 
        {(char *)"g", T_UBYTE, offsetof(PySfColor, g), 0, (char *)"Green component."},
33
 
        {(char *)"b", T_UBYTE, offsetof(PySfColor, b), 0, (char *)"Blue component."},
34
 
        {(char *)"a", T_UBYTE, offsetof(PySfColor, a), 0, (char *)"Alpha (transparency) component."},
35
 
        {NULL}  /* Sentinel */
36
 
};
37
 
 
38
 
 
39
 
 
40
 
static void
41
 
PySfColor_dealloc(PySfColor *self)
42
 
{
43
 
        delete self->obj;
44
 
        free_object(self);
45
 
}
46
 
 
47
 
void
48
 
PySfColorUpdate(PySfColor *self)
49
 
{
50
 
        self->obj->r = self->r;
51
 
        self->obj->g = self->g;
52
 
        self->obj->b = self->b;
53
 
        self->obj->a = self->a;
54
 
}
55
 
 
56
 
static PyObject *
57
 
PySfColor_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
58
 
{
59
 
        PySfColor *self;
60
 
        self = (PySfColor *)type->tp_alloc(type, 0);
61
 
        if (self != NULL)
62
 
        {
63
 
                self->r = 0;
64
 
                self->g = 0;
65
 
                self->b = 0;
66
 
                self->a = 255;
67
 
                self->obj = new sf::Color(0, 0, 0, 255);
68
 
        }
69
 
        return (PyObject *)self;
70
 
}
71
 
 
72
 
static int
73
 
PySfColor_init(PySfColor *self, PyObject *args, PyObject *kwds)
74
 
{
75
 
        const char *kwlist[] = {"r", "g", "b", "a", NULL};
76
 
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "BBB|B:Color.__init__", (char **)kwlist, &(self->r), &(self->g), &(self->b), &(self->a)))
77
 
                return -1;
78
 
        PySfColorUpdate(self);
79
 
        return 0;
80
 
}
81
 
 
82
 
PyTypeObject PySfColorType = {
83
 
        head_init
84
 
        "Color",                                /*tp_name*/
85
 
        sizeof(PySfColor),              /*tp_basicsize*/
86
 
        0,                                              /*tp_itemsize*/
87
 
        (destructor)PySfColor_dealloc, /*tp_dealloc*/
88
 
        0,                                              /*tp_print*/
89
 
        0,                                              /*tp_getattr*/
90
 
        0,                                              /*tp_setattr*/
91
 
        0,                                              /*tp_compare*/
92
 
        0,                                              /*tp_repr*/
93
 
        0,                                              /*tp_as_number*/
94
 
        0,                                              /*tp_as_sequence*/
95
 
        0,                                              /*tp_as_mapping*/
96
 
        0,                                              /*tp_hash */
97
 
        0,                                              /*tp_call*/
98
 
        0,                                              /*tp_str*/
99
 
        0,                                              /*tp_getattro*/
100
 
        0,                                              /*tp_setattro*/
101
 
        0,                                              /*tp_as_buffer*/
102
 
        Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
103
 
        "sf.Color is an utility class for manipulating 32-bits RGBA colors.", /* tp_doc */
104
 
        0,                                              /* tp_traverse */
105
 
        0,                                              /* tp_clear */
106
 
        0,                                              /* tp_richcompare */
107
 
        0,                                              /* tp_weaklistoffset */
108
 
        0,                                              /* tp_iter */
109
 
        0,                                              /* tp_iternext */
110
 
        0,                                              /* tp_methods */
111
 
        PySfColor_members,              /* tp_members */
112
 
        0,                                              /* tp_getset */
113
 
        0,                                              /* tp_base */
114
 
        0,                                              /* tp_dict */
115
 
        0,                                              /* tp_descr_get */
116
 
        0,                                              /* tp_descr_set */
117
 
        0,                                              /* tp_dictoffset */
118
 
        (initproc)PySfColor_init, /* tp_init */
119
 
        0,                                              /* tp_alloc */
120
 
        PySfColor_new,                  /* tp_new */
121
 
};
122
 
 
123
 
PySfColor *
124
 
GetNewPySfColor()
125
 
{
126
 
        return PyObject_New(PySfColor, &PySfColorType);
127
 
}
128
 
 
129
 
void
130
 
PySfColor_InitConst()
131
 
{
132
 
        PySfColor *Black, *White, *Red, *Green, *Blue, *Yellow, *Magenta, *Cyan;
133
 
        Black = GetNewPySfColor();
134
 
        Black->obj = (sf::Color *) &(sf::Color::Black);
135
 
        Black->r = sf::Color::Black.r;
136
 
        Black->g = sf::Color::Black.g;
137
 
        Black->b = sf::Color::Black.b;
138
 
        Black->a = sf::Color::Black.a;
139
 
        PyDict_SetItemString(PySfColorType.tp_dict, "Black", (PyObject *)Black);
140
 
        Py_DECREF(Black);
141
 
        White = GetNewPySfColor();
142
 
        White->obj = (sf::Color *) &(sf::Color::White);
143
 
        White->r = sf::Color::White.r;
144
 
        White->g = sf::Color::White.g;
145
 
        White->b = sf::Color::White.b;
146
 
        White->a = sf::Color::White.a;
147
 
        PyDict_SetItemString(PySfColorType.tp_dict, "White", (PyObject *)White);
148
 
        Py_DECREF(White);
149
 
        Red = GetNewPySfColor();
150
 
        Red->obj = (sf::Color *) &(sf::Color::Red);
151
 
        Red->r = sf::Color::Red.r;
152
 
        Red->g = sf::Color::Red.g;
153
 
        Red->b = sf::Color::Red.b;
154
 
        Red->a = sf::Color::Red.a;
155
 
        PyDict_SetItemString(PySfColorType.tp_dict, "Red", (PyObject *)Red);
156
 
        Py_DECREF(Red);
157
 
        Green = GetNewPySfColor();
158
 
        Green->obj = (sf::Color *) &(sf::Color::Green);
159
 
        Green->r = sf::Color::Green.r;
160
 
        Green->g = sf::Color::Green.g;
161
 
        Green->b = sf::Color::Green.b;
162
 
        Green->a = sf::Color::Green.a;
163
 
        PyDict_SetItemString(PySfColorType.tp_dict, "Green", (PyObject *)Green);
164
 
        Py_DECREF(Green);
165
 
        Blue = GetNewPySfColor();
166
 
        Blue->obj = (sf::Color *) &(sf::Color::Blue);
167
 
        Blue->r = sf::Color::Blue.r;
168
 
        Blue->g = sf::Color::Blue.g;
169
 
        Blue->b = sf::Color::Blue.b;
170
 
        Blue->a = sf::Color::Blue.a;
171
 
        PyDict_SetItemString(PySfColorType.tp_dict, "Blue", (PyObject *)Blue);
172
 
        Py_DECREF(Blue);
173
 
        Yellow = GetNewPySfColor();
174
 
        Yellow->obj = (sf::Color *) &(sf::Color::Yellow);
175
 
        Yellow->r = sf::Color::Yellow.r;
176
 
        Yellow->g = sf::Color::Yellow.g;
177
 
        Yellow->b = sf::Color::Yellow.b;
178
 
        Yellow->a = sf::Color::Yellow.a;
179
 
        PyDict_SetItemString(PySfColorType.tp_dict, "Yellow", (PyObject *)Yellow);
180
 
        Py_DECREF(Yellow);
181
 
        Magenta = GetNewPySfColor();
182
 
        Magenta->obj = (sf::Color *) &(sf::Color::Magenta);
183
 
        Magenta->r = sf::Color::Magenta.r;
184
 
        Magenta->g = sf::Color::Magenta.g;
185
 
        Magenta->b = sf::Color::Magenta.b;
186
 
        Magenta->a = sf::Color::Magenta.a;
187
 
        PyDict_SetItemString(PySfColorType.tp_dict, "Magenta", (PyObject *)Magenta);
188
 
        Py_DECREF(Magenta);
189
 
        Cyan = GetNewPySfColor();
190
 
        Cyan->obj = (sf::Color *) &(sf::Color::Cyan);
191
 
        Cyan->r = sf::Color::Cyan.r;
192
 
        Cyan->g = sf::Color::Cyan.g;
193
 
        Cyan->b = sf::Color::Cyan.b;
194
 
        Cyan->a = sf::Color::Cyan.a;
195
 
        PyDict_SetItemString(PySfColorType.tp_dict, "Cyan", (PyObject *)Cyan);
196
 
        Py_DECREF(Cyan);
197
 
}
198