1
////////////////////////////////////////////////////////////
3
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
4
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
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.
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:
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.
18
// 2. Altered source versions must be plainly marked as such,
19
// and must not be misrepresented as being the original software.
21
// 3. This notice may not be removed or altered from any source distribution.
23
////////////////////////////////////////////////////////////
27
#include "offsetof.hpp"
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."},
41
PySfColor_dealloc(PySfColor *self)
48
PySfColorUpdate(PySfColor *self)
50
self->obj->r = self->r;
51
self->obj->g = self->g;
52
self->obj->b = self->b;
53
self->obj->a = self->a;
57
PySfColor_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
60
self = (PySfColor *)type->tp_alloc(type, 0);
67
self->obj = new sf::Color(0, 0, 0, 255);
69
return (PyObject *)self;
73
PySfColor_init(PySfColor *self, PyObject *args, PyObject *kwds)
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)))
78
PySfColorUpdate(self);
82
PyTypeObject PySfColorType = {
85
sizeof(PySfColor), /*tp_basicsize*/
87
(destructor)PySfColor_dealloc, /*tp_dealloc*/
102
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
103
"sf.Color is an utility class for manipulating 32-bits RGBA colors.", /* tp_doc */
106
0, /* tp_richcompare */
107
0, /* tp_weaklistoffset */
111
PySfColor_members, /* tp_members */
115
0, /* tp_descr_get */
116
0, /* tp_descr_set */
117
0, /* tp_dictoffset */
118
(initproc)PySfColor_init, /* tp_init */
120
PySfColor_new, /* tp_new */
126
return PyObject_New(PySfColor, &PySfColorType);
130
PySfColor_InitConst()
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);
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);
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);
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);
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);
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);
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);
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);