2024-03-28 01:10:03 +00:00
|
|
|
#pragma once
|
|
|
|
#include "Common.h"
|
|
|
|
#include "Python.h"
|
2024-03-29 00:53:49 +00:00
|
|
|
#include <functional>
|
2024-03-28 01:10:03 +00:00
|
|
|
|
|
|
|
class PyLinkedColor;
|
2024-03-29 03:50:50 +00:00
|
|
|
//class UIDrawable; // forward declare for pointer
|
|
|
|
class PyClickCallable;
|
|
|
|
|
|
|
|
// TODO - after UI.h gets broken up, this can go into a separate base class, since only derived classes use PyLinkedColor
|
|
|
|
#ifndef ui_h
|
|
|
|
enum PyObjectsEnum : int
|
|
|
|
{
|
|
|
|
UIFRAME = 1,
|
|
|
|
UICAPTION,
|
|
|
|
UISPRITE,
|
|
|
|
UIGRID
|
|
|
|
};
|
|
|
|
|
|
|
|
class UIDrawable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void render();
|
|
|
|
virtual void render(sf::Vector2f) = 0;
|
|
|
|
virtual PyObjectsEnum derived_type() = 0;
|
|
|
|
|
|
|
|
std::unique_ptr<PyClickCallable> click_callable;
|
|
|
|
virtual UIDrawable* click_at(sf::Vector2f point) = 0;
|
|
|
|
void click_register(PyObject*);
|
|
|
|
void click_unregister();
|
|
|
|
|
|
|
|
UIDrawable();
|
|
|
|
};
|
|
|
|
#endif
|
2024-03-28 01:10:03 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
std::weak_ptr<UIDrawable> parent; // lifetime management: parent must still exist
|
|
|
|
int index; // specific to the parent class, which color is it?
|
2024-03-29 00:53:49 +00:00
|
|
|
//sf::Color(*getter)();
|
|
|
|
//void(*setter)(sf::Color);
|
|
|
|
std::function<void(sf::Color)> setter;
|
|
|
|
std::function<sf::Color()> getter;
|
2024-03-28 01:10:03 +00:00
|
|
|
} _PyLinkedColorData;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
_PyLinkedColorData data;
|
|
|
|
} PyLinkedColorObject;
|
|
|
|
|
|
|
|
class PyLinkedColor
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
_PyLinkedColorData data;
|
2024-03-29 00:53:49 +00:00
|
|
|
PyLinkedColor(_PyLinkedColorData); // private constructor / for operations transferring between C++ and Python
|
2024-03-28 01:10:03 +00:00
|
|
|
|
|
|
|
public:
|
2024-03-29 00:53:49 +00:00
|
|
|
//PyLinkedColor(sf::Color (*)(), void (*)(sf::Color), std::weak_ptr<UIDrawable>, int);
|
|
|
|
PyLinkedColor(std::function<void(sf::Color)> setter, std::function<sf::Color()> getter, std::weak_ptr<UIDrawable> parent, int index);
|
2024-03-28 01:10:03 +00:00
|
|
|
void set(sf::Color); // change target value, behavior determined by the mode
|
|
|
|
sf::Color get(); // retrieve target value, behavior determined by the mode
|
|
|
|
PyObject* pyParent(); // UIDrawable derived parent object or None
|
|
|
|
std::string field(); // interpret the index as a field's name on UIDrawable
|
|
|
|
bool alive(); // true if SELF_OWNED or parent still exists
|
|
|
|
PyObject* pyObject();
|
|
|
|
static PyLinkedColor fromPy(PyObject*);
|
|
|
|
static PyLinkedColor fromPy(PyLinkedColorObject*);
|
|
|
|
static PyObject* repr(PyObject*);
|
|
|
|
static Py_hash_t hash(PyObject*);
|
|
|
|
static int init(PyLinkedColorObject*, PyObject*, PyObject*);
|
|
|
|
static PyObject* pynew(PyTypeObject* type, PyObject* args=NULL, PyObject* kwds=NULL);
|
|
|
|
static PyObject* get_member(PyObject*, void*);
|
|
|
|
static int set_member(PyObject*, PyObject*, void*);
|
|
|
|
static PyGetSetDef getsetters[];
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace mcrfpydef {
|
|
|
|
static PyTypeObject PyLinkedColorType = {
|
|
|
|
.tp_name = "mcrfpy.LinkedColor",
|
|
|
|
.tp_basicsize = sizeof(PyLinkedColorObject),
|
|
|
|
.tp_itemsize = 0,
|
|
|
|
.tp_repr = PyLinkedColor::repr,
|
|
|
|
.tp_hash = PyLinkedColor::hash,
|
|
|
|
.tp_flags = Py_TPFLAGS_DEFAULT,
|
|
|
|
.tp_doc = PyDoc_STR("SFML Color Object - Linked to UIDrawable Field"),
|
|
|
|
.tp_getset = PyLinkedColor::getsetters,
|
2024-03-29 03:50:50 +00:00
|
|
|
//.tp_init = (initproc)PyLinkedColor::init,
|
2024-03-28 01:10:03 +00:00
|
|
|
.tp_new = PyLinkedColor::pynew,
|
|
|
|
};
|
|
|
|
}
|