|
| 1 | + |
| 2 | +#include "UnrealEnginePythonPrivatePCH.h" |
| 3 | + |
| 4 | +#include "UEPyFSlateApplication.h" |
| 5 | + |
| 6 | + |
| 7 | +static PyObject *py_ue_get_average_delta_time(PyObject *cls, PyObject * args) |
| 8 | +{ |
| 9 | + return PyFloat_FromDouble(FSlateApplication::Get().GetAverageDeltaTime()); |
| 10 | +} |
| 11 | + |
| 12 | +static PyObject *py_ue_get_delta_time(PyObject *cls, PyObject * args) |
| 13 | +{ |
| 14 | + return PyFloat_FromDouble(FSlateApplication::Get().GetDeltaTime()); |
| 15 | +} |
| 16 | + |
| 17 | +static PyObject *py_ue_goto_line_in_source(PyObject *cls, PyObject * args) |
| 18 | +{ |
| 19 | + char *filename; |
| 20 | + int line_number; |
| 21 | + if (!PyArg_ParseTuple(args, "si:goto_line_in_source", &filename, &line_number)) |
| 22 | + { |
| 23 | + return nullptr; |
| 24 | + } |
| 25 | + |
| 26 | + FSlateApplication::Get().GotoLineInSource(FString(UTF8_TO_TCHAR(filename)), line_number); |
| 27 | + |
| 28 | + Py_RETURN_NONE; |
| 29 | +} |
| 30 | + |
| 31 | +static PyObject *py_ue_is_gamepad_attached(PyObject *cls, PyObject * args) |
| 32 | +{ |
| 33 | + bool bAttached = FSlateApplication::Get().IsGamepadAttached(); |
| 34 | + if (bAttached) |
| 35 | + Py_RETURN_TRUE; |
| 36 | + Py_RETURN_FALSE; |
| 37 | +} |
| 38 | + |
| 39 | +static PyObject *py_ue_is_mouse_attached(PyObject *cls, PyObject * args) |
| 40 | +{ |
| 41 | + bool bAttached = FSlateApplication::Get().IsMouseAttached(); |
| 42 | + if (bAttached) |
| 43 | + Py_RETURN_TRUE; |
| 44 | + Py_RETURN_FALSE; |
| 45 | +} |
| 46 | + |
| 47 | +static PyObject *py_ue_process_key_down_event(PyObject *cls, PyObject * args) |
| 48 | +{ |
| 49 | + PyObject *py_event; |
| 50 | + if (!PyArg_ParseTuple(args, "O:process_key_down_event", &py_event)) |
| 51 | + { |
| 52 | + return nullptr; |
| 53 | + } |
| 54 | + |
| 55 | + FKeyEvent *InKeyEvent = ue_py_check_struct<FKeyEvent>(py_event); |
| 56 | + if (!InKeyEvent) |
| 57 | + { |
| 58 | + ue_PyFKeyEvent *py_fkey_event = py_ue_is_fkey_event(py_event); |
| 59 | + if (!py_fkey_event) |
| 60 | + { |
| 61 | + return PyErr_Format(PyExc_Exception, "argument is not a FKeyEvent"); |
| 62 | + } |
| 63 | + InKeyEvent = &py_fkey_event->key_event; |
| 64 | + } |
| 65 | + |
| 66 | + if (FSlateApplication::Get().ProcessKeyDownEvent(*InKeyEvent)) |
| 67 | + Py_RETURN_TRUE; |
| 68 | + |
| 69 | + Py_RETURN_FALSE; |
| 70 | +} |
| 71 | + |
| 72 | +static PyObject *py_ue_process_key_char_event(PyObject *cls, PyObject * args) |
| 73 | +{ |
| 74 | + PyObject *py_event; |
| 75 | + if (!PyArg_ParseTuple(args, "O:process_key_char_event", &py_event)) |
| 76 | + { |
| 77 | + return nullptr; |
| 78 | + } |
| 79 | + |
| 80 | + FCharacterEvent *InCharEvent = ue_py_check_struct<FCharacterEvent>(py_event); |
| 81 | + if (!InCharEvent) |
| 82 | + { |
| 83 | + ue_PyFCharacterEvent *py_fchar_event = py_ue_is_fcharacter_event(py_event); |
| 84 | + if (!py_fchar_event) |
| 85 | + { |
| 86 | + return PyErr_Format(PyExc_Exception, "argument is not a FCharacterEvent"); |
| 87 | + } |
| 88 | + InCharEvent = &py_fchar_event->character_event; |
| 89 | + } |
| 90 | + |
| 91 | + if (FSlateApplication::Get().ProcessKeyCharEvent(*InCharEvent)) |
| 92 | + Py_RETURN_TRUE; |
| 93 | + |
| 94 | + Py_RETURN_FALSE; |
| 95 | +} |
| 96 | + |
| 97 | +static PyMethodDef ue_PyFSlateApplication_methods[] = { |
| 98 | + { "get_average_delta_time", (PyCFunction)py_ue_get_average_delta_time, METH_VARARGS | METH_CLASS, "" }, |
| 99 | + { "get_delta_time", (PyCFunction)py_ue_get_delta_time, METH_VARARGS | METH_CLASS, "" }, |
| 100 | + { "goto_line_in_source", (PyCFunction)py_ue_goto_line_in_source, METH_VARARGS | METH_CLASS, "" }, |
| 101 | + { "is_gamepad_attached", (PyCFunction)py_ue_is_gamepad_attached, METH_VARARGS | METH_CLASS, "" }, |
| 102 | + { "is_mouse_attached", (PyCFunction)py_ue_is_mouse_attached, METH_VARARGS | METH_CLASS, "" }, |
| 103 | + { "process_key_down_event", (PyCFunction)py_ue_process_key_down_event, METH_VARARGS | METH_CLASS, "" }, |
| 104 | + { "process_key_char_event", (PyCFunction)py_ue_process_key_char_event, METH_VARARGS | METH_CLASS, "" }, |
| 105 | + { NULL } /* Sentinel */ |
| 106 | +}; |
| 107 | + |
| 108 | + |
| 109 | +static PyTypeObject ue_PyFSlateApplicationType = { |
| 110 | + PyVarObject_HEAD_INIT(NULL, 0) |
| 111 | + "unreal_engine.FSlateApplication", /* tp_name */ |
| 112 | + sizeof(ue_PyFSlateApplication), /* tp_basicsize */ |
| 113 | + 0, /* tp_itemsize */ |
| 114 | + 0, /* tp_dealloc */ |
| 115 | + 0, /* tp_print */ |
| 116 | + 0, /* tp_getattr */ |
| 117 | + 0, /* tp_setattr */ |
| 118 | + 0, /* tp_reserved */ |
| 119 | + 0, /* tp_repr */ |
| 120 | + 0, /* tp_as_number */ |
| 121 | + 0, /* tp_as_sequence */ |
| 122 | + 0, /* tp_as_mapping */ |
| 123 | + 0, /* tp_hash */ |
| 124 | + 0, /* tp_call */ |
| 125 | + 0, /* tp_str */ |
| 126 | + 0, /* tp_getattro */ |
| 127 | + 0, /* tp_setattro */ |
| 128 | + 0, /* tp_as_buffer */ |
| 129 | + Py_TPFLAGS_DEFAULT, /* tp_flags */ |
| 130 | + "Unreal Engine SlateApplication", /* tp_doc */ |
| 131 | + 0, /* tp_traverse */ |
| 132 | + 0, /* tp_clear */ |
| 133 | + 0, /* tp_richcompare */ |
| 134 | + 0, /* tp_weaklistoffset */ |
| 135 | + 0, /* tp_iter */ |
| 136 | + 0, /* tp_iternext */ |
| 137 | + ue_PyFSlateApplication_methods, /* tp_methods */ |
| 138 | + 0, |
| 139 | + 0, |
| 140 | +}; |
| 141 | + |
| 142 | +static int py_ue_fslate_application_init(ue_PyFSlateApplication *self, PyObject * args) |
| 143 | +{ |
| 144 | + PyErr_SetString(PyExc_Exception, "FSlateApplication is a singleton"); |
| 145 | + return -1; |
| 146 | +} |
| 147 | + |
| 148 | +void ue_python_init_fslate_application(PyObject *ue_module) |
| 149 | +{ |
| 150 | + ue_PyFSlateApplicationType.tp_new = PyType_GenericNew; |
| 151 | + ue_PyFSlateApplicationType.tp_init = (initproc)py_ue_fslate_application_init; |
| 152 | + |
| 153 | + if (PyType_Ready(&ue_PyFSlateApplicationType) < 0) |
| 154 | + return; |
| 155 | + |
| 156 | + Py_INCREF(&ue_PyFSlateApplicationType); |
| 157 | + PyModule_AddObject(ue_module, "FSlateApplication", (PyObject *)&ue_PyFSlateApplicationType); |
| 158 | +} |
0 commit comments