Squashed commit of the following: [break_up_ui_h]
Closes #43 No segfault found in cos_play after completing the checklist. Maybe I accidentally fixed it...? commit6aa151aba3Author: John McCardle <mccardle.john@gmail.com> Date: Fri Apr 19 21:43:58 2024 -0400 UISprite.h/.cpp cleanup commitec0374ef50Author: John McCardle <mccardle.john@gmail.com> Date: Fri Apr 19 21:37:39 2024 -0400 UIGridPoint.h/.cpp reorganization commit2cb7339535Author: John McCardle <mccardle.john@gmail.com> Date: Fri Apr 19 21:19:25 2024 -0400 UIGrid.h/.cpp cleanup. I have reservations about the UIEntityCollection[Iter] classes + methods living there, but not enough to fix it right now. commit5d6af324bfAuthor: John McCardle <mccardle.john@gmail.com> Date: Thu Apr 18 22:14:57 2024 -0400 UIFrame - moving static method into class namespace; no type object access commit567218cd7bAuthor: John McCardle <mccardle.john@gmail.com> Date: Thu Apr 18 21:23:49 2024 -0400 UIEntity fixes for the UI.h split: There are segfaults in cos_play, I may have missed a type usage or something commit76693acd28Author: John McCardle <mccardle.john@gmail.com> Date: Sat Apr 13 00:18:37 2024 -0400 delete leftover comments commit9efe998a33Author: John McCardle <mccardle.john@gmail.com> Date: Sat Apr 13 00:17:43 2024 -0400 some work on UICaption and UICollection; fixing segfaults resulting from mcrfpydef namepace TypeObject usage commit714965da45Author: John McCardle <mccardle.john@gmail.com> Date: Fri Apr 12 14:15:00 2024 -0400 eliminate extra includes on UICaption commit8efa25878fAuthor: John McCardle <mccardle.john@gmail.com> Date: Wed Apr 10 23:41:14 2024 -0400 remove a lot of stuff commitc186d8c7f3Author: John McCardle <mccardle.john@gmail.com> Date: Wed Apr 10 23:10:15 2024 -0400 We are compiling again! Started refactoring UICaption to be more idiomatic commit1b6e2a709bAuthor: John McCardle <mccardle.john@gmail.com> Date: Tue Apr 9 22:42:02 2024 -0400 Still not quite compiling; as predicted, a lot of interdependency and definition order bugs to untangle commitaa7553a818Author: John McCardle <mccardle.john@gmail.com> Date: Tue Apr 9 22:41:20 2024 -0400 PyTexture clean up scribbles and experiments commitc0201d989aAuthor: John McCardle <mccardle.john@gmail.com> Date: Mon Apr 8 22:55:00 2024 -0400 additional unsaved changes commit83a63a3093Author: John McCardle <mccardle.john@gmail.com> Date: Mon Apr 8 22:45:00 2024 -0400 doesn't compile, but UI.h/.cpp code has been divvy'd up. refs #43 @2h
This commit is contained in:
parent
1a7186f745
commit
ac7f7052cd
20 changed files with 2814 additions and 3052 deletions
183
src/UIGrid.h
Normal file
183
src/UIGrid.h
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
#pragma once
|
||||
#include "Common.h"
|
||||
#include "Python.h"
|
||||
#include "structmember.h"
|
||||
#include "IndexTexture.h"
|
||||
#include "Resources.h"
|
||||
#include <list>
|
||||
|
||||
#include "PyCallable.h"
|
||||
#include "PyTexture.h"
|
||||
#include "PyColor.h"
|
||||
#include "PyVector.h"
|
||||
#include "PyFont.h"
|
||||
|
||||
#include "UIGridPoint.h"
|
||||
#include "UIEntity.h"
|
||||
#include "UIDrawable.h"
|
||||
#include "UIBase.h"
|
||||
|
||||
class UIGrid: public UIDrawable
|
||||
{
|
||||
private:
|
||||
std::shared_ptr<PyTexture> ptex;
|
||||
public:
|
||||
UIGrid();
|
||||
//UIGrid(int, int, IndexTexture*, float, float, float, float);
|
||||
UIGrid(int, int, std::shared_ptr<PyTexture>, sf::Vector2f, sf::Vector2f);
|
||||
void update();
|
||||
void render(sf::Vector2f) override final;
|
||||
UIGridPoint& at(int, int);
|
||||
PyObjectsEnum derived_type() override final;
|
||||
//void setSprite(int);
|
||||
virtual UIDrawable* click_at(sf::Vector2f point) override final;
|
||||
|
||||
int grid_x, grid_y;
|
||||
//int grid_size; // grid sizes are implied by IndexTexture now
|
||||
sf::RectangleShape box;
|
||||
float center_x, center_y, zoom;
|
||||
//IndexTexture* itex;
|
||||
std::shared_ptr<PyTexture> getTexture();
|
||||
sf::Sprite sprite, output;
|
||||
sf::RenderTexture renderTexture;
|
||||
std::vector<UIGridPoint> points;
|
||||
std::shared_ptr<std::list<std::shared_ptr<UIEntity>>> entities;
|
||||
|
||||
static int init(PyUIGridObject* self, PyObject* args, PyObject* kwds);
|
||||
static PyObject* get_grid_size(PyUIGridObject* self, void* closure);
|
||||
static PyObject* get_position(PyUIGridObject* self, void* closure);
|
||||
static int set_position(PyUIGridObject* self, PyObject* value, void* closure);
|
||||
static PyObject* get_size(PyUIGridObject* self, void* closure);
|
||||
static int set_size(PyUIGridObject* self, PyObject* value, void* closure);
|
||||
static PyObject* get_center(PyUIGridObject* self, void* closure);
|
||||
static int set_center(PyUIGridObject* self, PyObject* value, void* closure);
|
||||
static PyObject* get_float_member(PyUIGridObject* self, void* closure);
|
||||
static int set_float_member(PyUIGridObject* self, PyObject* value, void* closure);
|
||||
static PyObject* get_texture(PyUIGridObject* self, void* closure);
|
||||
static PyObject* py_at(PyUIGridObject* self, PyObject* o);
|
||||
static PyMethodDef methods[];
|
||||
static PyGetSetDef getsetters[];
|
||||
static PyObject* get_children(PyUIGridObject* self, void* closure);
|
||||
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
std::shared_ptr<std::list<std::shared_ptr<UIEntity>>> data;
|
||||
std::shared_ptr<UIGrid> grid;
|
||||
} PyUIEntityCollectionObject;
|
||||
|
||||
class UIEntityCollection {
|
||||
public:
|
||||
static PySequenceMethods sqmethods;
|
||||
static PyObject* append(PyUIEntityCollectionObject* self, PyObject* o);
|
||||
static PyObject* remove(PyUIEntityCollectionObject* self, PyObject* o);
|
||||
static PyMethodDef methods[];
|
||||
static PyObject* repr(PyUIEntityCollectionObject* self);
|
||||
static int init(PyUIEntityCollectionObject* self, PyObject* args, PyObject* kwds);
|
||||
static PyObject* iter(PyUIEntityCollectionObject* self);
|
||||
static Py_ssize_t len(PyUIEntityCollectionObject* self);
|
||||
static PyObject* getitem(PyUIEntityCollectionObject* self, Py_ssize_t index);
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
std::shared_ptr<std::list<std::shared_ptr<UIEntity>>> data;
|
||||
int index;
|
||||
int start_size;
|
||||
} PyUIEntityCollectionIterObject;
|
||||
|
||||
class UIEntityCollectionIter {
|
||||
public:
|
||||
static int init(PyUIEntityCollectionIterObject* self, PyObject* args, PyObject* kwds);
|
||||
static PyObject* next(PyUIEntityCollectionIterObject* self);
|
||||
static PyObject* repr(PyUIEntityCollectionIterObject* self);
|
||||
static PyObject* getitem(PyUIEntityCollectionObject* self, Py_ssize_t index);
|
||||
|
||||
};
|
||||
|
||||
namespace mcrfpydef {
|
||||
static PyTypeObject PyUIGridType = {
|
||||
//PyVarObject_HEAD_INIT(NULL, 0)
|
||||
.tp_name = "mcrfpy.Grid",
|
||||
.tp_basicsize = sizeof(PyUIGridObject),
|
||||
.tp_itemsize = 0,
|
||||
//.tp_dealloc = (destructor)[](PyObject* self)
|
||||
//{
|
||||
// PyUIGridObject* obj = (PyUIGridObject*)self;
|
||||
// obj->data.reset();
|
||||
// Py_TYPE(self)->tp_free(self);
|
||||
//},
|
||||
//TODO - PyUIGrid REPR def:
|
||||
// .tp_repr = (reprfunc)UIGrid::repr,
|
||||
//.tp_hash = NULL,
|
||||
//.tp_iter
|
||||
//.tp_iternext
|
||||
.tp_flags = Py_TPFLAGS_DEFAULT,
|
||||
.tp_doc = PyDoc_STR("docstring"),
|
||||
.tp_methods = UIGrid::methods,
|
||||
//.tp_members = UIGrid::members,
|
||||
.tp_getset = UIGrid::getsetters,
|
||||
//.tp_base = NULL,
|
||||
.tp_init = (initproc)UIGrid::init,
|
||||
.tp_new = [](PyTypeObject* type, PyObject* args, PyObject* kwds) -> PyObject*
|
||||
{
|
||||
PyUIGridObject* self = (PyUIGridObject*)type->tp_alloc(type, 0);
|
||||
if (self) self->data = std::make_shared<UIGrid>();
|
||||
return (PyObject*)self;
|
||||
}
|
||||
};
|
||||
|
||||
static PyTypeObject PyUIEntityCollectionIterType = {
|
||||
//PyVarObject_HEAD_INIT(NULL, 0)
|
||||
.tp_name = "mcrfpy.UICollectionIter",
|
||||
.tp_basicsize = sizeof(PyUIEntityCollectionIterObject),
|
||||
.tp_itemsize = 0,
|
||||
.tp_dealloc = (destructor)[](PyObject* self)
|
||||
{
|
||||
PyUIEntityCollectionIterObject* obj = (PyUIEntityCollectionIterObject*)self;
|
||||
obj->data.reset();
|
||||
Py_TYPE(self)->tp_free(self);
|
||||
},
|
||||
.tp_repr = (reprfunc)UIEntityCollectionIter::repr,
|
||||
.tp_flags = Py_TPFLAGS_DEFAULT,
|
||||
.tp_doc = PyDoc_STR("Iterator for a collection of UI objects"),
|
||||
.tp_iternext = (iternextfunc)UIEntityCollectionIter::next,
|
||||
//.tp_getset = UIEntityCollection::getset,
|
||||
.tp_init = (initproc)UIEntityCollectionIter::init, // just raise an exception
|
||||
.tp_new = [](PyTypeObject* type, PyObject* args, PyObject* kwds) -> PyObject*
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "UICollection cannot be instantiated: a C++ data source is required.");
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
static PyTypeObject PyUIEntityCollectionType = {
|
||||
//PyVarObject_/HEAD_INIT(NULL, 0)
|
||||
.tp_name = "mcrfpy.EntityCollection",
|
||||
.tp_basicsize = sizeof(PyUIEntityCollectionObject),
|
||||
.tp_itemsize = 0,
|
||||
.tp_dealloc = (destructor)[](PyObject* self)
|
||||
{
|
||||
PyUIEntityCollectionObject* obj = (PyUIEntityCollectionObject*)self;
|
||||
obj->data.reset();
|
||||
Py_TYPE(self)->tp_free(self);
|
||||
},
|
||||
.tp_repr = (reprfunc)UIEntityCollection::repr,
|
||||
.tp_as_sequence = &UIEntityCollection::sqmethods,
|
||||
.tp_flags = Py_TPFLAGS_DEFAULT,
|
||||
.tp_doc = PyDoc_STR("Iterable, indexable collection of Entities"),
|
||||
.tp_iter = (getiterfunc)UIEntityCollection::iter,
|
||||
.tp_methods = UIEntityCollection::methods, // append, remove
|
||||
//.tp_getset = UIEntityCollection::getset,
|
||||
.tp_init = (initproc)UIEntityCollection::init, // just raise an exception
|
||||
.tp_new = [](PyTypeObject* type, PyObject* args, PyObject* kwds) -> PyObject*
|
||||
{
|
||||
// Does PyUIEntityCollectionType need __new__ if it's not supposed to be instantiable by the user?
|
||||
// Should I just raise an exception? Or is the uninitialized shared_ptr enough of a blocker?
|
||||
PyErr_SetString(PyExc_TypeError, "EntityCollection cannot be instantiated: a C++ data source is required.");
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue