Python API improvements: Vectors, bounds, window singleton, hidden types

- #177: GridPoint.grid_pos property returns (x, y) tuple
- #179: Grid.grid_size returns Vector instead of tuple
- #181: Grid.center returns Vector instead of tuple
- #182: Caption.size/w/h read-only properties for text dimensions
- #184: mcrfpy.window singleton for window access
- #185: Removed get_bounds() method, use .bounds property instead
- #188: bounds/global_bounds return (pos, size) as pair of Vectors
- #189: Hide internal types from module namespace (iterators, collections)

Also fixed critical bug: Changed static PyTypeObject to inline in headers
to ensure single instance across translation units (was causing segfaults).

Closes #177, closes #179, closes #181, closes #182, closes #184, closes #185, closes #188, closes #189

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
John McCardle 2026-01-05 23:00:48 -05:00
commit f9b6cdef1c
17 changed files with 448 additions and 87 deletions

View file

@ -261,12 +261,31 @@ int UICaption::set_text(PyUICaptionObject* self, PyObject* value, void* closure)
return 0;
}
PyObject* UICaption::get_size(PyUICaptionObject* self, void* closure)
{
auto bounds = self->data->text.getGlobalBounds();
return PyVector(sf::Vector2f(bounds.width, bounds.height)).pyObject();
}
PyObject* UICaption::get_w(PyUICaptionObject* self, void* closure)
{
auto bounds = self->data->text.getGlobalBounds();
return PyFloat_FromDouble(bounds.width);
}
PyObject* UICaption::get_h(PyUICaptionObject* self, void* closure)
{
auto bounds = self->data->text.getGlobalBounds();
return PyFloat_FromDouble(bounds.height);
}
PyGetSetDef UICaption::getsetters[] = {
{"x", (getter)UIDrawable::get_float_member, (setter)UIDrawable::set_float_member, "X coordinate of top-left corner", (void*)((intptr_t)PyObjectsEnum::UICAPTION << 8 | 0)},
{"y", (getter)UIDrawable::get_float_member, (setter)UIDrawable::set_float_member, "Y coordinate of top-left corner", (void*)((intptr_t)PyObjectsEnum::UICAPTION << 8 | 1)},
{"pos", (getter)UIDrawable::get_pos, (setter)UIDrawable::set_pos, "(x, y) vector", (void*)PyObjectsEnum::UICAPTION},
//{"w", (getter)PyUIFrame_get_float_member, (setter)PyUIFrame_set_float_member, "width of the rectangle", (void*)2},
//{"h", (getter)PyUIFrame_get_float_member, (setter)PyUIFrame_set_float_member, "height of the rectangle", (void*)3},
{"size", (getter)UICaption::get_size, NULL, "Text dimensions as Vector (read-only)", NULL},
{"w", (getter)UICaption::get_w, NULL, "Text width in pixels (read-only)", NULL},
{"h", (getter)UICaption::get_h, NULL, "Text height in pixels (read-only)", NULL},
{"outline", (getter)UICaption::get_float_member, (setter)UICaption::set_float_member, "Thickness of the border", (void*)4},
{"fill_color", (getter)UICaption::get_color_member, (setter)UICaption::set_color_member,
"Fill color of the text. Returns a copy; modifying components requires reassignment. "