146 lines
5.0 KiB
C++
146 lines
5.0 KiB
C++
#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 "Resources.h"
|
|
#include "UIBase.h"
|
|
class UIFrame; class UICaption; class UISprite; class UIEntity; class UIGrid;
|
|
|
|
enum PyObjectsEnum : int
|
|
{
|
|
UIFRAME = 1,
|
|
UICAPTION,
|
|
UISPRITE,
|
|
UIGRID
|
|
};
|
|
|
|
class UIDrawable
|
|
{
|
|
public:
|
|
void render();
|
|
//virtual void render(sf::Vector2f) = 0;
|
|
virtual void render(sf::Vector2f, sf::RenderTarget&) = 0;
|
|
virtual PyObjectsEnum derived_type() = 0;
|
|
|
|
// Mouse input handling - callable object, methods to find event's destination
|
|
std::unique_ptr<PyClickCallable> click_callable;
|
|
virtual UIDrawable* click_at(sf::Vector2f point) = 0;
|
|
void click_register(PyObject*);
|
|
void click_unregister();
|
|
|
|
UIDrawable();
|
|
|
|
static PyObject* get_click(PyObject* self, void* closure);
|
|
static int set_click(PyObject* self, PyObject* value, void* closure);
|
|
static PyObject* get_int(PyObject* self, void* closure);
|
|
static int set_int(PyObject* self, PyObject* value, void* closure);
|
|
|
|
// Z-order for rendering (lower values rendered first, higher values on top)
|
|
int z_index = 0;
|
|
|
|
// Animation support
|
|
virtual bool setProperty(const std::string& name, float value) { return false; }
|
|
virtual bool setProperty(const std::string& name, int value) { return false; }
|
|
virtual bool setProperty(const std::string& name, const sf::Color& value) { return false; }
|
|
virtual bool setProperty(const std::string& name, const sf::Vector2f& value) { return false; }
|
|
virtual bool setProperty(const std::string& name, const std::string& value) { return false; }
|
|
|
|
virtual bool getProperty(const std::string& name, float& value) const { return false; }
|
|
virtual bool getProperty(const std::string& name, int& value) const { return false; }
|
|
virtual bool getProperty(const std::string& name, sf::Color& value) const { return false; }
|
|
virtual bool getProperty(const std::string& name, sf::Vector2f& value) const { return false; }
|
|
virtual bool getProperty(const std::string& name, std::string& value) const { return false; }
|
|
};
|
|
|
|
typedef struct {
|
|
PyObject_HEAD
|
|
std::shared_ptr<std::vector<std::shared_ptr<UIDrawable>>> data;
|
|
} PyUICollectionObject;
|
|
|
|
typedef struct {
|
|
PyObject_HEAD
|
|
std::shared_ptr<std::vector<std::shared_ptr<UIDrawable>>> data;
|
|
int index;
|
|
int start_size;
|
|
} PyUICollectionIterObject;
|
|
|
|
namespace mcrfpydef {
|
|
// DEPRECATED: RET_PY_INSTANCE macro has been replaced with template functions in PyObjectUtils.h
|
|
// The macro was difficult to debug and used static type references that could cause initialization order issues.
|
|
// Use PyObjectUtils::convertDrawableToPython() or PyObjectUtils::createPyObject<T>() instead.
|
|
|
|
//TODO: add this method to class scope; move implementation to .cpp file
|
|
/*
|
|
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
|
|
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;
|
|
}*/
|
|
|
|
//TODO: add this method to class scope; move implementation to .cpp file
|
|
/*
|
|
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
|
|
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;
|
|
}
|
|
*/
|
|
}
|