Added PyFont/mcrfpy.Font object
This commit is contained in:
parent
9486104377
commit
bec2b3294d
|
@ -123,7 +123,7 @@ PyObject* PyInit_mcrfpy()
|
||||||
// This code runs, but Python segfaults when accessing the UIFrame type.
|
// This code runs, but Python segfaults when accessing the UIFrame type.
|
||||||
//std::cout << "Adding UIFrame object to module\n";
|
//std::cout << "Adding UIFrame object to module\n";
|
||||||
PyModule_AddType(m, &mcrfpydef::PyColorType);
|
PyModule_AddType(m, &mcrfpydef::PyColorType);
|
||||||
|
PyModule_AddType(m, &mcrfpydef::PyFontType);
|
||||||
PyModule_AddType(m, &mcrfpydef::PyUICaptionType);
|
PyModule_AddType(m, &mcrfpydef::PyUICaptionType);
|
||||||
|
|
||||||
if (PyModule_AddType(m, &mcrfpydef::PyUIFrameType) < 0)
|
if (PyModule_AddType(m, &mcrfpydef::PyUIFrameType) < 0)
|
||||||
|
|
48
src/UI.h
48
src/UI.h
|
@ -194,6 +194,54 @@ switch (target->derived_type()) \
|
||||||
std::shared_ptr<UISprite> data;
|
std::shared_ptr<UISprite> data;
|
||||||
} PyUISpriteObject;
|
} PyUISpriteObject;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* Begin PyFontType defs
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
PyObject_HEAD
|
||||||
|
std::shared_ptr<sf::Font> 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<char**>(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<sf::Font>();
|
||||||
|
return (PyObject*)self;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* End PyFontType defs
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
static PyObject* PyColor_get_member(PyColorObject* self, void* closure)
|
static PyObject* PyColor_get_member(PyColorObject* self, void* closure)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue