2024-03-24 03:07:10 +00:00
|
|
|
#pragma once
|
|
|
|
#include "Common.h"
|
|
|
|
#include "Python.h"
|
|
|
|
|
|
|
|
class PyColor;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
sf::Color* target; // color target to set/get
|
|
|
|
std::weak_ptr<UIDrawable> parent; // lifetime management: parent must still exist
|
|
|
|
int index; // specific to the parent class, which color is it?
|
|
|
|
} _PyColorData;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
_PyColorData data;
|
|
|
|
} PyTextureObject;
|
|
|
|
|
|
|
|
class PyColor
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
_PyColorData data;
|
|
|
|
public:
|
2024-03-24 12:36:06 +00:00
|
|
|
void set(sf::Color);
|
|
|
|
sf::Color get();
|
2024-03-24 03:07:10 +00:00
|
|
|
PyObject* pyObject();
|
|
|
|
static Py_hash_t hash(PyObject*);
|
|
|
|
static int init(PyColorObject*, PyObject*, PyObject*);
|
|
|
|
static PyObject* pynew(PyTypeObject* type, PyObject* args=NULL, PyObject* kwds=NULL);
|
2024-03-24 12:36:06 +00:00
|
|
|
|
|
|
|
static PyGetSetDef getsetters[] = {
|
|
|
|
{"r", (getter)PyColor_get_member, (setter)PyColor_set_member, "Red component", (void*)0},
|
|
|
|
{"g", (getter)PyColor_get_member, (setter)PyColor_set_member, "Green component", (void*)1},
|
|
|
|
{"b", (getter)PyColor_get_member, (setter)PyColor_set_member, "Blue component", (void*)2},
|
|
|
|
{"a", (getter)PyColor_get_member, (setter)PyColor_set_member, "Alpha component", (void*)3},
|
|
|
|
{NULL}
|
|
|
|
};
|
2024-03-24 03:07:10 +00:00
|
|
|
};
|
|
|
|
|
2024-03-24 12:36:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
// static PyTypeObject PyColorType = {
|
|
|
|
// //PyVarObject_HEAD_INIT(NULL, 0)
|
|
|
|
// .tp_name = "mcrfpy.Color",
|
|
|
|
// .tp_basicsize = sizeof(PyColorObject),
|
|
|
|
// .tp_itemsize = 0,
|
|
|
|
// .tp_dealloc = (destructor)[](PyObject* self)
|
|
|
|
// {
|
|
|
|
// PyColorObject* obj = (PyColorObject*)self;
|
|
|
|
// obj->data.reset();
|
|
|
|
// Py_TYPE(self)->tp_free(self);
|
|
|
|
// },
|
|
|
|
// //.tp_repr = (reprfunc)PyUIFrame_repr,
|
|
|
|
// //.tp_hash = NULL,
|
|
|
|
// //.tp_iter
|
|
|
|
// //.tp_iternext
|
|
|
|
// .tp_flags = Py_TPFLAGS_DEFAULT,
|
|
|
|
// .tp_doc = PyDoc_STR("SFML Color object (RGBA)"),
|
|
|
|
// //.tp_methods = PyUIFrame_methods,
|
|
|
|
// //.tp_members = PyColor_members,
|
|
|
|
// .tp_getset = PyColor_getsetters,
|
|
|
|
// //.tp_base = NULL,
|
|
|
|
// //.tp_init = (initproc)PyUIFrame_init,
|
|
|
|
// .tp_new = [](PyTypeObject* type, PyObject* args, PyObject* kwds) -> PyObject*
|
|
|
|
// {
|
|
|
|
// PyColorObject* self = (PyColorObject*)type->tp_alloc(type, 0);
|
|
|
|
// if (self) self->data = std::make_shared<sf::Color>();
|
|
|
|
// return (PyObject*)self;
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
|
2024-03-24 03:07:10 +00:00
|
|
|
namespace mcrfpydef {
|
|
|
|
static PyTypeObject PyColorType = {
|
|
|
|
.tp_name = "mcrfpy.Color",
|
|
|
|
.tp_basicsize = sizeof(PyColorObject),
|
|
|
|
.tp_itemsize = 0,
|
|
|
|
.tp_hash = PyColor::hash,
|
|
|
|
.tp_flags = Py_TPFLAGS_DEFAULT,
|
|
|
|
.tp_doc = PyDoc_STR("SFML Color Object"),
|
2024-03-24 12:36:06 +00:00
|
|
|
.tp_getset = PyColor::getsetters,
|
2024-03-24 03:07:10 +00:00
|
|
|
.tp_init = (initproc)PyColor::init,
|
|
|
|
.tp_new = PyTColor::pynew,
|
|
|
|
};
|
|
|
|
}
|