48 lines
1.3 KiB
C
48 lines
1.3 KiB
C
|
|
#pragma once
|
||
|
|
#include "UIEntity.h"
|
||
|
|
#include "UIBase.h"
|
||
|
|
|
||
|
|
// UIEntity-specific property implementations
|
||
|
|
// These delegate to the wrapped sprite member
|
||
|
|
|
||
|
|
// Visible property
|
||
|
|
static PyObject* UIEntity_get_visible(PyUIEntityObject* self, void* closure)
|
||
|
|
{
|
||
|
|
return PyBool_FromLong(self->data->sprite.visible);
|
||
|
|
}
|
||
|
|
|
||
|
|
static int UIEntity_set_visible(PyUIEntityObject* self, PyObject* value, void* closure)
|
||
|
|
{
|
||
|
|
if (!PyBool_Check(value)) {
|
||
|
|
PyErr_SetString(PyExc_TypeError, "visible must be a boolean");
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
self->data->sprite.visible = PyObject_IsTrue(value);
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Opacity property
|
||
|
|
static PyObject* UIEntity_get_opacity(PyUIEntityObject* self, void* closure)
|
||
|
|
{
|
||
|
|
return PyFloat_FromDouble(self->data->sprite.opacity);
|
||
|
|
}
|
||
|
|
|
||
|
|
static int UIEntity_set_opacity(PyUIEntityObject* self, PyObject* value, void* closure)
|
||
|
|
{
|
||
|
|
float opacity;
|
||
|
|
if (PyFloat_Check(value)) {
|
||
|
|
opacity = PyFloat_AsDouble(value);
|
||
|
|
} else if (PyLong_Check(value)) {
|
||
|
|
opacity = PyLong_AsDouble(value);
|
||
|
|
} else {
|
||
|
|
PyErr_SetString(PyExc_TypeError, "opacity must be a number");
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Clamp to valid range
|
||
|
|
if (opacity < 0.0f) opacity = 0.0f;
|
||
|
|
if (opacity > 1.0f) opacity = 1.0f;
|
||
|
|
|
||
|
|
self->data->sprite.opacity = opacity;
|
||
|
|
return 0;
|
||
|
|
}
|