Compare commits
No commits in common. "1b6e2a709bfa3adc38183e30f1cc999efd7ef7c9" and "c0201d989acb2dbd25ae80f6642c4b849db0c0b5" have entirely different histories.
1b6e2a709b
...
c0201d989a
|
@ -28,12 +28,36 @@ sf::Sprite PyTexture::sprite(int index, sf::Vector2f pos, sf::Vector2f s)
|
||||||
|
|
||||||
PyObject* PyTexture::pyObject()
|
PyObject* PyTexture::pyObject()
|
||||||
{
|
{
|
||||||
|
// method 1: works but with type weirdness
|
||||||
|
//PyObject* obj = PyType_GenericAlloc(&mcrfpydef::PyTextureType, 0);
|
||||||
|
//Py_SET_TYPE(obj, &mcrfpydef::PyTextureType);
|
||||||
|
|
||||||
|
// method 2: does not work (segfault on use of the mcrfpy.Texture object)
|
||||||
|
//PyObject* obj = PyTexture::pynew(&mcrfpydef::PyTextureType, Py_None, Py_None);
|
||||||
|
|
||||||
|
// method 3: does not work (segfault on use of the mcrfpy.Texture object)
|
||||||
std::cout << "Find type" << std::endl;
|
std::cout << "Find type" << std::endl;
|
||||||
auto type = (PyTypeObject*)PyObject_GetAttrString(McRFPy_API::mcrf_module, "Texture");
|
auto type = (PyTypeObject*)PyObject_GetAttrString(McRFPy_API::mcrf_module, "Texture");
|
||||||
|
//auto type = obj->ob_type;
|
||||||
|
//auto type = &mcrfpydef::PyTextureType;
|
||||||
|
//std::cout << "assigned value 0x" << std::hex << reinterpret_cast<long>(type) << std::endl;
|
||||||
|
//std::cout << "Found PyTextureType: " << PyUnicode_AsUTF8(PyObject_Repr((PyObject*)type)) << std::endl;
|
||||||
|
//std::cout << "PyTextureType metatype: " << PyUnicode_AsUTF8(PyObject_Repr((PyObject_Type((PyObject*)type)))) << std::endl;
|
||||||
|
//std::cout << "tp_alloc: 0x" << std::hex << reinterpret_cast <long>(type->tp_alloc) << std::endl <<
|
||||||
|
// "tp_new: 0x" << std::hex << reinterpret_cast<long>(type->tp_new) << std::endl;
|
||||||
|
//PyObject* obj = ((PyTypeObject*)type)->tp_new((PyTypeObject*)type, Py_None, Py_None);
|
||||||
PyObject* obj = PyTexture::pynew(type, Py_None, Py_None);
|
PyObject* obj = PyTexture::pynew(type, Py_None, Py_None);
|
||||||
|
//Py_SET_TYPE(obj, type);
|
||||||
|
|
||||||
|
// method 4: call the type object?
|
||||||
|
|
||||||
|
std::cout << "Instantiated" << std::endl;
|
||||||
|
//Py_SET_TYPE(obj, &mcrfpydef::PyTextureType);
|
||||||
|
|
||||||
|
//PyObject_CallFunction(&mcrfpydef::PyTextureType,
|
||||||
try {
|
try {
|
||||||
((PyTextureObject*)obj)->data = shared_from_this();
|
((PyTextureObject*)obj)->data = shared_from_this();
|
||||||
|
std::cout << "Sideloaded texture: " << PyUnicode_AsUTF8(PyObject_Repr(obj)) << std::endl;
|
||||||
}
|
}
|
||||||
catch (std::bad_weak_ptr& e)
|
catch (std::bad_weak_ptr& e)
|
||||||
{
|
{
|
||||||
|
|
32
src/UIBase.h
32
src/UIBase.h
|
@ -1,32 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
class UIEntity;
|
|
||||||
typedef struct {
|
|
||||||
PyObject_HEAD
|
|
||||||
std::shared_ptr<UIEntity> data;
|
|
||||||
} PyUIEntityObject;
|
|
||||||
|
|
||||||
class UIFrame;
|
|
||||||
typedef struct {
|
|
||||||
PyObject_HEAD
|
|
||||||
std::shared_ptr<UIFrame> data;
|
|
||||||
} PyUIFrameObject;
|
|
||||||
|
|
||||||
class UICaption;
|
|
||||||
typedef struct {
|
|
||||||
PyObject_HEAD
|
|
||||||
std::shared_ptr<UICaption> data;
|
|
||||||
PyObject* font;
|
|
||||||
} PyUICaptionObject;
|
|
||||||
|
|
||||||
class UIGrid;
|
|
||||||
typedef struct {
|
|
||||||
PyObject_HEAD
|
|
||||||
std::shared_ptr<UIGrid> data;
|
|
||||||
} PyUIGridObject;
|
|
||||||
|
|
||||||
class UISprite;
|
|
||||||
typedef struct {
|
|
||||||
PyObject_HEAD
|
|
||||||
std::shared_ptr<UISprite> data;
|
|
||||||
} PyUISpriteObject;
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "UICaption.h"
|
#include "UICaption.h"
|
||||||
#include "GameEngine.h"
|
|
||||||
|
|
||||||
UIDrawable* UICaption::click_at(sf::Vector2f point)
|
UIDrawable* UICaption::click_at(sf::Vector2f point)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include "PyVector.h"
|
#include "PyVector.h"
|
||||||
#include "PyFont.h"
|
#include "PyFont.h"
|
||||||
#include "UIDrawable.h"
|
#include "UIDrawable.h"
|
||||||
#include "UIBase.h"
|
|
||||||
|
|
||||||
class UICaption: public UIDrawable
|
class UICaption: public UIDrawable
|
||||||
{
|
{
|
||||||
|
@ -23,12 +22,11 @@ public:
|
||||||
virtual UIDrawable* click_at(sf::Vector2f point) override final;
|
virtual UIDrawable* click_at(sf::Vector2f point) override final;
|
||||||
};
|
};
|
||||||
|
|
||||||
//class UICaption;
|
typedef struct {
|
||||||
//typedef struct {
|
PyObject_HEAD
|
||||||
// PyObject_HEAD
|
std::shared_ptr<UICaption> data;
|
||||||
// std::shared_ptr<UICaption> data;
|
PyObject* font;
|
||||||
// PyObject* font;
|
} PyUICaptionObject;
|
||||||
//} PyUICaptionObject;
|
|
||||||
|
|
||||||
namespace mcrfpydef {
|
namespace mcrfpydef {
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file
|
//TODO: add this method to class scope; move implementation to .cpp file
|
||||||
|
@ -207,7 +205,7 @@ namespace mcrfpydef {
|
||||||
//{"children", (getter)PyUIFrame_get_children, NULL, "UICollection of objects on top of this one", NULL},
|
//{"children", (getter)PyUIFrame_get_children, NULL, "UICollection of objects on top of this one", NULL},
|
||||||
{"text", (getter)PyUICaption_get_text, (setter)PyUICaption_set_text, "The text displayed", NULL},
|
{"text", (getter)PyUICaption_get_text, (setter)PyUICaption_set_text, "The text displayed", NULL},
|
||||||
{"size", (getter)PyUICaption_get_float_member, (setter)PyUICaption_set_float_member, "Text size (integer) in points", (void*)5},
|
{"size", (getter)PyUICaption_get_float_member, (setter)PyUICaption_set_float_member, "Text size (integer) in points", (void*)5},
|
||||||
{"click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click, "Object called with (x, y, button) when clicked", (void*)PyObjectsEnum::UICAPTION},
|
{"click", (getter)PyUIDrawable_get_click, (setter)PyUIDrawable_set_click, "Object called with (x, y, button) when clicked", (void*)PyObjectsEnum::UICAPTION},
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
#include "UIDrawable.h"
|
#include "UIDrawable.h"
|
||||||
#include "UIFrame.h"
|
|
||||||
#include "UICaption.h"
|
|
||||||
#include "UISprite.h"
|
|
||||||
#include "UIGrid.h"
|
|
||||||
|
|
||||||
UIDrawable::UIDrawable() { click_callable = NULL; }
|
UIDrawable::UIDrawable() { click_callable = NULL; }
|
||||||
|
|
||||||
|
@ -15,64 +11,3 @@ void UIDrawable::render()
|
||||||
{
|
{
|
||||||
render(sf::Vector2f());
|
render(sf::Vector2f());
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* UIDrawable::get_click(PyObject* self, void* closure) {
|
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure)); // trust me bro, it's an Enum
|
|
||||||
PyObject* ptr;
|
|
||||||
|
|
||||||
switch (objtype)
|
|
||||||
{
|
|
||||||
case PyObjectsEnum::UIFRAME:
|
|
||||||
ptr = ((PyUIFrameObject*)self)->data->click_callable->borrow();
|
|
||||||
break;
|
|
||||||
case PyObjectsEnum::UICAPTION:
|
|
||||||
ptr = ((PyUICaptionObject*)self)->data->click_callable->borrow();
|
|
||||||
break;
|
|
||||||
case PyObjectsEnum::UISPRITE:
|
|
||||||
ptr = ((PyUISpriteObject*)self)->data->click_callable->borrow();
|
|
||||||
break;
|
|
||||||
case PyObjectsEnum::UIGRID:
|
|
||||||
ptr = ((PyUIGridObject*)self)->data->click_callable->borrow();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
PyErr_SetString(PyExc_TypeError, "no idea how you did that; invalid UIDrawable derived instance for _get_click");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (ptr && ptr != Py_None)
|
|
||||||
return ptr;
|
|
||||||
else
|
|
||||||
return Py_None;
|
|
||||||
}
|
|
||||||
|
|
||||||
int UIDrawable::set_click(PyObject* self, PyObject* value, void* closure) {
|
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure)); // trust me bro, it's an Enum
|
|
||||||
UIDrawable* target;
|
|
||||||
switch (objtype)
|
|
||||||
{
|
|
||||||
case PyObjectsEnum::UIFRAME:
|
|
||||||
target = (((PyUIFrameObject*)self)->data.get());
|
|
||||||
break;
|
|
||||||
case PyObjectsEnum::UICAPTION:
|
|
||||||
target = (((PyUICaptionObject*)self)->data.get());
|
|
||||||
break;
|
|
||||||
case PyObjectsEnum::UISPRITE:
|
|
||||||
target = (((PyUISpriteObject*)self)->data.get());
|
|
||||||
break;
|
|
||||||
case PyObjectsEnum::UIGRID:
|
|
||||||
target = (((PyUIGridObject*)self)->data.get());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
PyErr_SetString(PyExc_TypeError, "no idea how you did that; invalid UIDrawable derived instance for _set_click");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value == Py_None)
|
|
||||||
{
|
|
||||||
target->click_unregister();
|
|
||||||
} else {
|
|
||||||
target->click_register(value);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
#include "PyVector.h"
|
#include "PyVector.h"
|
||||||
#include "PyFont.h"
|
#include "PyFont.h"
|
||||||
|
|
||||||
#include "Resources.h"
|
|
||||||
|
|
||||||
class UIFrame; class UICaption; class UISprite; class UIEntity; class UIGrid;
|
class UIFrame; class UICaption; class UISprite; class UIEntity; class UIGrid;
|
||||||
|
|
||||||
enum PyObjectsEnum : int
|
enum PyObjectsEnum : int
|
||||||
|
@ -38,9 +36,6 @@ public:
|
||||||
void click_unregister();
|
void click_unregister();
|
||||||
|
|
||||||
UIDrawable();
|
UIDrawable();
|
||||||
|
|
||||||
static PyObject* get_click(PyObject* self, void* closure);
|
|
||||||
static int set_click(PyObject* self, PyObject* value, void* closure);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -104,8 +99,7 @@ switch (target->derived_type()) \
|
||||||
// end macro definition
|
// end macro definition
|
||||||
|
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file
|
//TODO: add this method to class scope; move implementation to .cpp file
|
||||||
/*
|
static PyObject* PyUIDrawable_get_click(PyUIGridObject* self, void* closure) {
|
||||||
static PyObject* PyUIDrawable_get_click(PyObject* self, void* closure) {
|
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure)); // trust me bro, it's an Enum
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure)); // trust me bro, it's an Enum
|
||||||
PyObject* ptr;
|
PyObject* ptr;
|
||||||
|
|
||||||
|
@ -131,11 +125,10 @@ static PyObject* PyUIDrawable_get_click(PyObject* self, void* closure) {
|
||||||
return ptr;
|
return ptr;
|
||||||
else
|
else
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file
|
//TODO: add this method to class scope; move implementation to .cpp file
|
||||||
/*
|
static int PyUIDrawable_set_click(PyUIGridObject* self, PyObject* value, void* closure) {
|
||||||
static int PyUIDrawable_set_click(PyObject* self, PyObject* value, void* closure) {
|
|
||||||
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure)); // trust me bro, it's an Enum
|
PyObjectsEnum objtype = static_cast<PyObjectsEnum>(reinterpret_cast<long>(closure)); // trust me bro, it's an Enum
|
||||||
UIDrawable* target;
|
UIDrawable* target;
|
||||||
switch (objtype)
|
switch (objtype)
|
||||||
|
@ -165,5 +158,5 @@ static int PyUIDrawable_set_click(PyObject* self, PyObject* value, void* closure
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,75 +7,3 @@ UIEntity::UIEntity(UIGrid& grid)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* UIEntity::at(PyUIEntityObject* self, PyObject* o) {
|
|
||||||
int x, y;
|
|
||||||
if (!PyArg_ParseTuple(o, "ii", &x, &y)) {
|
|
||||||
PyErr_SetString(PyExc_TypeError, "UIEntity.at requires two integer arguments: (x, y)");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self->data->grid == NULL) {
|
|
||||||
PyErr_SetString(PyExc_ValueError, "Entity cannot access surroundings because it is not associated with a grid");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
PyUIGridPointStateObject* obj = (PyUIGridPointStateObject*)((&PyUIGridPointStateType)->tp_alloc(&PyUIGridPointStateType, 0));
|
|
||||||
//auto target = std::static_pointer_cast<UIEntity>(target);
|
|
||||||
obj->data = &(self->data->gridstate[y + self->data->grid->grid_x * x]);
|
|
||||||
obj->grid = self->data->grid;
|
|
||||||
obj->entity = self->data;
|
|
||||||
return (PyObject*)obj;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int PyUIEntity::init(PyUIEntityObject* self, PyObject* args, PyObject* kwds) {
|
|
||||||
static const char* keywords[] = { "x", "y", "texture", "sprite_index", "grid", nullptr };
|
|
||||||
float x = 0.0f, y = 0.0f, scale = 1.0f;
|
|
||||||
int sprite_index = -1;
|
|
||||||
PyObject* texture = NULL;
|
|
||||||
PyObject* grid = NULL;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "ffOi|O",
|
|
||||||
const_cast<char**>(keywords), &x, &y, &texture, &sprite_index, &grid))
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check types for texture
|
|
||||||
//
|
|
||||||
// Set Texture
|
|
||||||
//
|
|
||||||
if (texture != NULL && !PyObject_IsInstance(texture, (PyObject*)&mcrfpydef::PyTextureType)){
|
|
||||||
PyErr_SetString(PyExc_TypeError, "texture must be a mcrfpy.Texture instance");
|
|
||||||
return -1;
|
|
||||||
} /*else if (texture != NULL) // this section needs to go; texture isn't optional and isn't managed by the UI objects anymore
|
|
||||||
{
|
|
||||||
self->texture = texture;
|
|
||||||
Py_INCREF(texture);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
// default tex?
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (grid != NULL && !PyObject_IsInstance(grid, (PyObject*)&PyUIGridType)) {
|
|
||||||
PyErr_SetString(PyExc_TypeError, "grid must be a mcrfpy.Grid instance");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto pytexture = (PyTextureObject*)texture;
|
|
||||||
if (grid == NULL)
|
|
||||||
self->data = std::make_shared<UIEntity>();
|
|
||||||
else
|
|
||||||
self->data = std::make_shared<UIEntity>(*((PyUIGridObject*)grid)->data);
|
|
||||||
|
|
||||||
// TODO - PyTextureObjects and IndexTextures are a little bit of a mess with shared/unshared pointers
|
|
||||||
self->data->sprite = UISprite(pytexture->data, sprite_index, sf::Vector2f(0,0), 1.0);
|
|
||||||
self->data->position = sf::Vector2f(x, y);
|
|
||||||
if (grid != NULL) {
|
|
||||||
PyUIGridObject* pygrid = (PyUIGridObject*)grid;
|
|
||||||
self->data->grid = pygrid->data;
|
|
||||||
// todone - on creation of Entity with Grid assignment, also append it to the entity list
|
|
||||||
pygrid->data->entities->push_back(self->data);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -14,14 +14,8 @@
|
||||||
|
|
||||||
#include "UIGridPoint.h"
|
#include "UIGridPoint.h"
|
||||||
#include "UIDrawable.h"
|
#include "UIDrawable.h"
|
||||||
#include "UIBase.h"
|
|
||||||
class UIGrid;
|
|
||||||
|
|
||||||
//class UIEntity;
|
class UIGrid;
|
||||||
//typedef struct {
|
|
||||||
// PyObject_HEAD
|
|
||||||
// std::shared_ptr<UIEntity> data;
|
|
||||||
//} PyUIEntityObject;
|
|
||||||
|
|
||||||
// TODO: make UIEntity a drawable
|
// TODO: make UIEntity a drawable
|
||||||
class UIEntity//: public UIDrawable
|
class UIEntity//: public UIDrawable
|
||||||
|
@ -37,10 +31,14 @@ public:
|
||||||
UIEntity();
|
UIEntity();
|
||||||
UIEntity(UIGrid&);
|
UIEntity(UIGrid&);
|
||||||
|
|
||||||
static PyObject* at(PyUIEntityObject* self, PyObject* o);
|
|
||||||
static int init(PyUIEntityObject* self, PyObject* args, PyObject* kwds);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
PyObject_HEAD
|
||||||
|
std::shared_ptr<UIEntity> data;
|
||||||
|
//PyObject* texture;
|
||||||
|
} PyUIEntityObject;
|
||||||
|
|
||||||
namespace mcrfpydef {
|
namespace mcrfpydef {
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file; reconsider for moving to "UIBase.h/.cpp"
|
//TODO: add this method to class scope; move implementation to .cpp file; reconsider for moving to "UIBase.h/.cpp"
|
||||||
// TODO: sf::Vector2f convenience functions here might benefit from a PyVectorObject much like PyColorObject
|
// TODO: sf::Vector2f convenience functions here might benefit from a PyVectorObject much like PyColorObject
|
||||||
|
@ -126,7 +124,6 @@ static int PyUIEntity_set_spritenumber(PyUIEntityObject* self, PyObject* value,
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file
|
//TODO: add this method to class scope; move implementation to .cpp file
|
||||||
/*
|
|
||||||
static PyObject* PyUIEntity_at(PyUIEntityObject* self, PyObject* o)
|
static PyObject* PyUIEntity_at(PyUIEntityObject* self, PyObject* o)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
|
@ -147,11 +144,10 @@ static PyObject* PyUIEntity_at(PyUIEntityObject* self, PyObject* o)
|
||||||
obj->entity = self->data;
|
obj->entity = self->data;
|
||||||
return (PyObject*)obj;
|
return (PyObject*)obj;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
//TODO: add this static array to class scope; move implementation to .cpp file
|
//TODO: add this static array to class scope; move implementation to .cpp file
|
||||||
static PyMethodDef PyUIEntity_methods[] = {
|
static PyMethodDef PyUIEntity_methods[] = {
|
||||||
{"at", (PyCFunction)UIEntity::at, METH_O},
|
{"at", (PyCFunction)PyUIEntity_at, METH_O},
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -165,7 +161,7 @@ static PyGetSetDef PyUIEntity_getsetters[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
//TODO: add this method to class scope; forward declaration not required after .h/.cpp split
|
//TODO: add this method to class scope; forward declaration not required after .h/.cpp split
|
||||||
//static int PyUIEntity_init(PyUIEntityObject*, PyObject*, PyObject*); // forward declare
|
static int PyUIEntity_init(PyUIEntityObject*, PyObject*, PyObject*); // forward declare
|
||||||
|
|
||||||
|
|
||||||
// Define the PyTypeObject for UIEntity
|
// Define the PyTypeObject for UIEntity
|
||||||
|
@ -179,7 +175,7 @@ static PyTypeObject PyUIEntityType = {
|
||||||
.tp_doc = "UIEntity objects",
|
.tp_doc = "UIEntity objects",
|
||||||
.tp_methods = PyUIEntity_methods,
|
.tp_methods = PyUIEntity_methods,
|
||||||
.tp_getset = PyUIEntity_getsetters,
|
.tp_getset = PyUIEntity_getsetters,
|
||||||
.tp_init = (initproc)UIEntity::init,
|
.tp_init = (initproc)PyUIEntity_init,
|
||||||
.tp_new = PyType_GenericNew,
|
.tp_new = PyType_GenericNew,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,16 +54,6 @@ void UIFrame::render(sf::Vector2f offset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject* PyUIFrame::get_children(PyUIFrameObject* self, void* closure)
|
|
||||||
{
|
|
||||||
// create PyUICollection instance pointing to self->data->children
|
|
||||||
PyUICollectionObject* o = (PyUICollectionObject*)PyUICollectionType.tp_alloc(&PyUICollectionType, 0);
|
|
||||||
if (o)
|
|
||||||
o->data = self->data->children;
|
|
||||||
return (PyObject*)o;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
namespace mcrfpydef {
|
namespace mcrfpydef {
|
||||||
|
|
||||||
// TODO: move to class scope; but this should at least get us compiling
|
// TODO: move to class scope; but this should at least get us compiling
|
||||||
|
|
|
@ -10,14 +10,6 @@
|
||||||
#include "PyColor.h"
|
#include "PyColor.h"
|
||||||
#include "PyVector.h"
|
#include "PyVector.h"
|
||||||
#include "UIDrawable.h"
|
#include "UIDrawable.h"
|
||||||
#include "UIBase.h"
|
|
||||||
|
|
||||||
//class UIFrame;
|
|
||||||
//
|
|
||||||
//typedef struct {
|
|
||||||
// PyObject_HEAD
|
|
||||||
// std::shared_ptr<UIFrame> data;
|
|
||||||
//} PyUIFrameObject;
|
|
||||||
|
|
||||||
class UIFrame: public UIDrawable
|
class UIFrame: public UIDrawable
|
||||||
{
|
{
|
||||||
|
@ -32,10 +24,13 @@ public:
|
||||||
void move(sf::Vector2f);
|
void move(sf::Vector2f);
|
||||||
PyObjectsEnum derived_type() override final;
|
PyObjectsEnum derived_type() override final;
|
||||||
virtual UIDrawable* click_at(sf::Vector2f point) override final;
|
virtual UIDrawable* click_at(sf::Vector2f point) override final;
|
||||||
|
|
||||||
static PyObject* get_children(PyUIFrameObject* self, void* closure);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
PyObject_HEAD
|
||||||
|
std::shared_ptr<UIFrame> data;
|
||||||
|
} PyUIFrameObject;
|
||||||
|
|
||||||
namespace mcrfpydef {
|
namespace mcrfpydef {
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file
|
//TODO: add this method to class scope; move implementation to .cpp file
|
||||||
static PyObject* PyUIFrame_get_float_member(PyUIFrameObject* self, void* closure)
|
static PyObject* PyUIFrame_get_float_member(PyUIFrameObject* self, void* closure)
|
||||||
|
@ -178,7 +173,7 @@ namespace mcrfpydef {
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file
|
//TODO: add this method to class scope; move implementation to .cpp file
|
||||||
//static PyObject* PyUIFrame_get_children(PyUIFrameObject*, void*); // forward declaration until UICollection is defined
|
static PyObject* PyUIFrame_get_children(PyUIFrameObject*, void*); // forward declaration until UICollection is defined
|
||||||
// implementation after the PyUICollectionType definition
|
// implementation after the PyUICollectionType definition
|
||||||
|
|
||||||
//TODO: add this static array to class scope; move implementation to .cpp file
|
//TODO: add this static array to class scope; move implementation to .cpp file
|
||||||
|
@ -190,8 +185,8 @@ namespace mcrfpydef {
|
||||||
{"outline", (getter)PyUIFrame_get_float_member, (setter)PyUIFrame_set_float_member, "Thickness of the border", (void*)4},
|
{"outline", (getter)PyUIFrame_get_float_member, (setter)PyUIFrame_set_float_member, "Thickness of the border", (void*)4},
|
||||||
{"fill_color", (getter)PyUIFrame_get_color_member, (setter)PyUIFrame_set_color_member, "Fill color of the rectangle", (void*)0},
|
{"fill_color", (getter)PyUIFrame_get_color_member, (setter)PyUIFrame_set_color_member, "Fill color of the rectangle", (void*)0},
|
||||||
{"outline_color", (getter)PyUIFrame_get_color_member, (setter)PyUIFrame_set_color_member, "Outline color of the rectangle", (void*)1},
|
{"outline_color", (getter)PyUIFrame_get_color_member, (setter)PyUIFrame_set_color_member, "Outline color of the rectangle", (void*)1},
|
||||||
{"children", (getter)UIFrame::get_children, NULL, "UICollection of objects on top of this one", NULL},
|
{"children", (getter)PyUIFrame_get_children, NULL, "UICollection of objects on top of this one", NULL},
|
||||||
{"click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click, "Object called with (x, y, button) when clicked", (void*)PyObjectsEnum::UIFRAME},
|
{"click", (getter)PyUIDrawable_get_click, (setter)PyUIDrawable_set_click, "Object called with (x, y, button) when clicked", (void*)PyObjectsEnum::UIFRAME},
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
13
src/UIGrid.h
13
src/UIGrid.h
|
@ -15,7 +15,6 @@
|
||||||
#include "UIGridPoint.h"
|
#include "UIGridPoint.h"
|
||||||
#include "UIEntity.h"
|
#include "UIEntity.h"
|
||||||
#include "UIDrawable.h"
|
#include "UIDrawable.h"
|
||||||
#include "UIBase.h"
|
|
||||||
|
|
||||||
class UIGrid: public UIDrawable
|
class UIGrid: public UIDrawable
|
||||||
{
|
{
|
||||||
|
@ -44,11 +43,11 @@ public:
|
||||||
std::shared_ptr<std::list<std::shared_ptr<UIEntity>>> entities;
|
std::shared_ptr<std::list<std::shared_ptr<UIEntity>>> entities;
|
||||||
};
|
};
|
||||||
|
|
||||||
//typedef struct {
|
typedef struct {
|
||||||
// PyObject_HEAD
|
PyObject_HEAD
|
||||||
// std::shared_ptr<UIGrid> data;
|
std::shared_ptr<UIGrid> data;
|
||||||
// //PyObject* texture;
|
//PyObject* texture;
|
||||||
//} PyUIGridObject;
|
} PyUIGridObject;
|
||||||
|
|
||||||
namespace mcrfpydef {
|
namespace mcrfpydef {
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file
|
//TODO: add this method to class scope; move implementation to .cpp file
|
||||||
|
@ -258,7 +257,7 @@ static PyGetSetDef PyUIGrid_getsetters[] = {
|
||||||
{"center_y", (getter)PyUIGrid_get_float_member, (setter)PyUIGrid_set_float_member, "center of the view Y-coordinate", (void*)5},
|
{"center_y", (getter)PyUIGrid_get_float_member, (setter)PyUIGrid_set_float_member, "center of the view Y-coordinate", (void*)5},
|
||||||
{"zoom", (getter)PyUIGrid_get_float_member, (setter)PyUIGrid_set_float_member, "zoom factor for displaying the Grid", (void*)6},
|
{"zoom", (getter)PyUIGrid_get_float_member, (setter)PyUIGrid_set_float_member, "zoom factor for displaying the Grid", (void*)6},
|
||||||
|
|
||||||
{"click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click, "Object called with (x, y, button) when clicked", (void*)PyObjectsEnum::UIGRID},
|
{"click", (getter)PyUIDrawable_get_click, (setter)PyUIDrawable_set_click, "Object called with (x, y, button) when clicked", (void*)PyObjectsEnum::UIGRID},
|
||||||
|
|
||||||
{"texture", (getter)PyUIGrid_get_texture, NULL, "Texture of the grid", NULL}, //TODO 7DRL-day2-item5
|
{"texture", (getter)PyUIGrid_get_texture, NULL, "Texture of the grid", NULL}, //TODO 7DRL-day2-item5
|
||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
|
|
|
@ -29,8 +29,6 @@ public:
|
||||||
bool visible, discovered;
|
bool visible, discovered;
|
||||||
};
|
};
|
||||||
|
|
||||||
class UIGrid;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
UIGridPoint* data;
|
UIGridPoint* data;
|
||||||
|
|
|
@ -42,10 +42,10 @@ public:
|
||||||
PyObjectsEnum derived_type() override final;
|
PyObjectsEnum derived_type() override final;
|
||||||
};
|
};
|
||||||
|
|
||||||
//typedef struct {
|
typedef struct {
|
||||||
// PyObject_HEAD
|
PyObject_HEAD
|
||||||
// std::shared_ptr<UISprite> data;
|
std::shared_ptr<UISprite> data;
|
||||||
//} PyUISpriteObject;
|
} PyUISpriteObject;
|
||||||
|
|
||||||
namespace mcrfpydef {
|
namespace mcrfpydef {
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file
|
//TODO: add this method to class scope; move implementation to .cpp file
|
||||||
|
@ -143,7 +143,7 @@ namespace mcrfpydef {
|
||||||
{"scale", (getter)PyUISprite_get_float_member, (setter)PyUISprite_set_float_member, "Size factor", (void*)2},
|
{"scale", (getter)PyUISprite_get_float_member, (setter)PyUISprite_set_float_member, "Size factor", (void*)2},
|
||||||
{"sprite_number", (getter)PyUISprite_get_int_member, (setter)PyUISprite_set_int_member, "Which sprite on the texture is shown", NULL},
|
{"sprite_number", (getter)PyUISprite_get_int_member, (setter)PyUISprite_set_int_member, "Which sprite on the texture is shown", NULL},
|
||||||
{"texture", (getter)PyUISprite_get_texture, (setter)PyUISprite_set_texture, "Texture object", NULL},
|
{"texture", (getter)PyUISprite_get_texture, (setter)PyUISprite_set_texture, "Texture object", NULL},
|
||||||
{"click", (getter)UIDrawable::get_click, (setter)UIDrawable::set_click, "Object called with (x, y, button) when clicked", (void*)PyObjectsEnum::UISPRITE},
|
{"click", (getter)PyUIDrawable_get_click, (setter)PyUIDrawable_set_click, "Object called with (x, y, button) when clicked", (void*)PyObjectsEnum::UISPRITE},
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue