Caption object seems to be instantiable with a Font object now. Can't test actual rendering without a way to add objects to a collection.
This commit is contained in:
parent
bec2b3294d
commit
1bbb0aa5b8
35
src/UI.h
35
src/UI.h
|
@ -107,6 +107,7 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
std::shared_ptr<UICaption> data;
|
std::shared_ptr<UICaption> data;
|
||||||
|
PyObject* font;
|
||||||
} PyUICaptionObject;
|
} PyUICaptionObject;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -517,17 +518,41 @@ switch (target->derived_type()) \
|
||||||
static int PyUICaption_init(PyUICaptionObject* self, PyObject* args, PyObject* kwds)
|
static int PyUICaption_init(PyUICaptionObject* self, PyObject* args, PyObject* kwds)
|
||||||
{
|
{
|
||||||
//std::cout << "Init called\n";
|
//std::cout << "Init called\n";
|
||||||
static const char* keywords[] = { "x", "y", "text", nullptr };
|
static const char* keywords[] = { "x", "y", "text", "font", "fill_color", "outline_color", nullptr };
|
||||||
float x = 0.0f, y = 0.0f;
|
float x = 0.0f, y = 0.0f;
|
||||||
char* text;
|
char* text;
|
||||||
|
PyObject* font, fill_color, outline_color;
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ffz", const_cast<char**>(keywords), &x, &y, &text))
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ffzOOO",
|
||||||
|
const_cast<char**>(keywords), &x, &y, &text, &font, &fill_color, &outline_color))
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//self->data->x = x;
|
// check types for font, fill_color, outline_color
|
||||||
//self->data->y = y;
|
//
|
||||||
|
// Set Font
|
||||||
|
//
|
||||||
|
if (font != NULL && !PyObject_IsInstance(font, (PyObject*)&PyFontType)){
|
||||||
|
PyErr_SetString(PyExc_TypeError, "font must be a mcrfpy.Font instance");
|
||||||
|
return -1;
|
||||||
|
} else if (font != NULL)
|
||||||
|
{
|
||||||
|
auto font_obj = (PyFontObject*)font;
|
||||||
|
self->data->text.setFont(*font_obj->data);
|
||||||
|
self->font = font;
|
||||||
|
Py_INCREF(font);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
// default font
|
||||||
|
//self->data->text.setFont(Resources::game->getFont());
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set Color
|
||||||
|
//
|
||||||
|
self->data->text.setPosition(sf::Vector2f(x, y));
|
||||||
|
self->data->text.setString((std::string)text);
|
||||||
self->data->text.setFillColor(sf::Color(0,0,0,255));
|
self->data->text.setFillColor(sf::Color(0,0,0,255));
|
||||||
self->data->text.setOutlineColor(sf::Color(128,128,128,255));
|
self->data->text.setOutlineColor(sf::Color(128,128,128,255));
|
||||||
|
|
||||||
|
@ -542,6 +567,8 @@ switch (target->derived_type()) \
|
||||||
.tp_dealloc = (destructor)[](PyObject* self)
|
.tp_dealloc = (destructor)[](PyObject* self)
|
||||||
{
|
{
|
||||||
PyUICaptionObject* obj = (PyUICaptionObject*)self;
|
PyUICaptionObject* obj = (PyUICaptionObject*)self;
|
||||||
|
// release reference to font object
|
||||||
|
if (obj->font) Py_DECREF(obj->font);
|
||||||
obj->data.reset();
|
obj->data.reset();
|
||||||
Py_TYPE(self)->tp_free(self);
|
Py_TYPE(self)->tp_free(self);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue