diff --git a/src/McRFPy_API.cpp b/src/McRFPy_API.cpp index 172f159..47a463d 100644 --- a/src/McRFPy_API.cpp +++ b/src/McRFPy_API.cpp @@ -123,7 +123,7 @@ PyObject* PyInit_mcrfpy() // This code runs, but Python segfaults when accessing the UIFrame type. //std::cout << "Adding UIFrame object to module\n"; PyModule_AddType(m, &mcrfpydef::PyColorType); - + PyModule_AddType(m, &mcrfpydef::PyFontType); PyModule_AddType(m, &mcrfpydef::PyUICaptionType); if (PyModule_AddType(m, &mcrfpydef::PyUIFrameType) < 0) diff --git a/src/UI.h b/src/UI.h index 8f93332..35a0de2 100644 --- a/src/UI.h +++ b/src/UI.h @@ -194,6 +194,54 @@ switch (target->derived_type()) \ std::shared_ptr data; } PyUISpriteObject; */ + + /* + * + * Begin PyFontType defs + * + */ + + typedef struct { + PyObject_HEAD + std::shared_ptr data; + } PyFontObject; + + static int PyFont_init(PyFontObject* self, PyObject* args, PyObject* kwds) + { + //std::cout << "Init called\n"; + static const char* keywords[] = { "filename", nullptr }; + char* filename; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", const_cast(keywords), &filename)) + { + return -1; + } + self->data->loadFromFile((std::string)filename); + return 0; + } + + static PyTypeObject PyFontType = { + //PyVarObject_HEAD_INIT(NULL, 0) + .tp_name = "mcrfpy.Font", + .tp_basicsize = sizeof(PyFontObject), + .tp_itemsize = 0, + .tp_flags = Py_TPFLAGS_DEFAULT, + .tp_doc = PyDoc_STR("SFML Font Object"), + .tp_init = (initproc)PyFont_init, + .tp_new = [](PyTypeObject* type, PyObject* args, PyObject* kwds) -> PyObject* + { + PyFontObject* self = (PyFontObject*)type->tp_alloc(type, 0); + self->data = std::make_shared(); + return (PyObject*)self; + } + }; + + /* + * + * End PyFontType defs + * + */ + static PyObject* PyColor_get_member(PyColorObject* self, void* closure) {