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:
parent
c6233fa47f
commit
f9b6cdef1c
17 changed files with 448 additions and 87 deletions
|
|
@ -1089,7 +1089,7 @@ PyObject* UIDrawable::get_global_pos(PyObject* self, void* closure) {
|
|||
return result;
|
||||
}
|
||||
|
||||
// #138 - Python API for bounds property
|
||||
// #138, #188 - Python API for bounds property - returns (pos, size) as pair of Vectors
|
||||
PyObject* UIDrawable::get_bounds_py(PyObject* self, void* closure) {
|
||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
||||
UIDrawable* drawable = nullptr;
|
||||
|
|
@ -1122,10 +1122,35 @@ PyObject* UIDrawable::get_bounds_py(PyObject* self, void* closure) {
|
|||
}
|
||||
|
||||
sf::FloatRect bounds = drawable->get_bounds();
|
||||
return Py_BuildValue("(ffff)", bounds.left, bounds.top, bounds.width, bounds.height);
|
||||
|
||||
// Get Vector type from mcrfpy module
|
||||
PyObject* vector_type = PyObject_GetAttrString(McRFPy_API::mcrf_module, "Vector");
|
||||
if (!vector_type) return NULL;
|
||||
|
||||
// Create pos vector
|
||||
PyObject* pos_args = Py_BuildValue("(ff)", bounds.left, bounds.top);
|
||||
PyObject* pos = PyObject_CallObject(vector_type, pos_args);
|
||||
Py_DECREF(pos_args);
|
||||
if (!pos) {
|
||||
Py_DECREF(vector_type);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Create size vector
|
||||
PyObject* size_args = Py_BuildValue("(ff)", bounds.width, bounds.height);
|
||||
PyObject* size = PyObject_CallObject(vector_type, size_args);
|
||||
Py_DECREF(size_args);
|
||||
Py_DECREF(vector_type);
|
||||
if (!size) {
|
||||
Py_DECREF(pos);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Return tuple of two vectors (N steals reference)
|
||||
return Py_BuildValue("(NN)", pos, size);
|
||||
}
|
||||
|
||||
// #138 - Python API for global_bounds property
|
||||
// #138, #188 - Python API for global_bounds property - returns (pos, size) as pair of Vectors
|
||||
PyObject* UIDrawable::get_global_bounds_py(PyObject* self, void* closure) {
|
||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure));
|
||||
UIDrawable* drawable = nullptr;
|
||||
|
|
@ -1158,7 +1183,32 @@ PyObject* UIDrawable::get_global_bounds_py(PyObject* self, void* closure) {
|
|||
}
|
||||
|
||||
sf::FloatRect bounds = drawable->get_global_bounds();
|
||||
return Py_BuildValue("(ffff)", bounds.left, bounds.top, bounds.width, bounds.height);
|
||||
|
||||
// Get Vector type from mcrfpy module
|
||||
PyObject* vector_type = PyObject_GetAttrString(McRFPy_API::mcrf_module, "Vector");
|
||||
if (!vector_type) return NULL;
|
||||
|
||||
// Create pos vector
|
||||
PyObject* pos_args = Py_BuildValue("(ff)", bounds.left, bounds.top);
|
||||
PyObject* pos = PyObject_CallObject(vector_type, pos_args);
|
||||
Py_DECREF(pos_args);
|
||||
if (!pos) {
|
||||
Py_DECREF(vector_type);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Create size vector
|
||||
PyObject* size_args = Py_BuildValue("(ff)", bounds.width, bounds.height);
|
||||
PyObject* size = PyObject_CallObject(vector_type, size_args);
|
||||
Py_DECREF(size_args);
|
||||
Py_DECREF(vector_type);
|
||||
if (!size) {
|
||||
Py_DECREF(pos);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Return tuple of two vectors (N steals reference)
|
||||
return Py_BuildValue("(NN)", pos, size);
|
||||
}
|
||||
|
||||
// #140 - Python API for on_enter property
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue