1// qeasingcurve.sip generated by MetaSIP 2// 3// This file is part of the QtCore Python extension module. 4// 5// Copyright (c) 2021 Riverbank Computing Limited <info@riverbankcomputing.com> 6// 7// This file is part of PyQt5. 8// 9// This file may be used under the terms of the GNU General Public License 10// version 3.0 as published by the Free Software Foundation and appearing in 11// the file LICENSE included in the packaging of this file. Please review the 12// following information to ensure the GNU General Public License version 3.0 13// requirements will be met: http://www.gnu.org/copyleft/gpl.html. 14// 15// If you do not wish to use this file under the terms of the GPL version 3.0 16// then you may purchase a commercial license. For more information contact 17// info@riverbankcomputing.com. 18// 19// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 20// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 21 22 23class QEasingCurve /TypeHintIn="Union[QEasingCurve, QEasingCurve.Type]"/ 24{ 25%TypeHeaderCode 26#include <qeasingcurve.h> 27%End 28 29%TypeCode 30// The EasingFunction callback doesn't provide a context so we support a fixed 31// number of different functions. 32 33const int ec_nr_custom_types = 10; 34 35struct ec_custom_type { 36 PyObject *py_func; 37 QEasingCurve::EasingFunction func; 38}; 39 40static qreal ec_call(int ec, qreal v); 41 42static qreal ec_func_0(qreal v) 43{ 44 return ec_call(0, v); 45} 46 47static qreal ec_func_1(qreal v) 48{ 49 return ec_call(1, v); 50} 51 52static qreal ec_func_2(qreal v) 53{ 54 return ec_call(2, v); 55} 56 57static qreal ec_func_3(qreal v) 58{ 59 return ec_call(3, v); 60} 61 62static qreal ec_func_4(qreal v) 63{ 64 return ec_call(4, v); 65} 66 67static qreal ec_func_5(qreal v) 68{ 69 return ec_call(5, v); 70} 71 72static qreal ec_func_6(qreal v) 73{ 74 return ec_call(6, v); 75} 76 77static qreal ec_func_7(qreal v) 78{ 79 return ec_call(7, v); 80} 81 82static qreal ec_func_8(qreal v) 83{ 84 return ec_call(8, v); 85} 86 87static qreal ec_func_9(qreal v) 88{ 89 return ec_call(9, v); 90} 91 92static ec_custom_type ec_custom_types[ec_nr_custom_types] = { 93 {0, ec_func_0}, 94 {0, ec_func_1}, 95 {0, ec_func_2}, 96 {0, ec_func_3}, 97 {0, ec_func_4}, 98 {0, ec_func_5}, 99 {0, ec_func_6}, 100 {0, ec_func_7}, 101 {0, ec_func_8}, 102 {0, ec_func_9}, 103}; 104 105static qreal ec_call(int ec, qreal v) 106{ 107 PyObject *res_obj; 108 qreal res = 0.0; 109 110 SIP_BLOCK_THREADS 111 112 res_obj = PyObject_CallFunction(ec_custom_types[ec].py_func, (char *)"(d)", (double)v); 113 114 if (res_obj) 115 { 116 PyErr_Clear(); 117 118 res = PyFloat_AsDouble(res_obj); 119 Py_DECREF(res_obj); 120 121 if (PyErr_Occurred()) 122 res_obj = 0; 123 } 124 125 if (!res_obj) 126 pyqt5_err_print(); 127 128 SIP_UNBLOCK_THREADS 129 130 return res; 131} 132%End 133 134%ConvertToTypeCode 135// Allow a QEasingCurve::Type whenever a QEasingCurve is expected. 136 137if (sipIsErr == NULL) 138{ 139 if (sipCanConvertToType(sipPy, sipType_QEasingCurve, SIP_NO_CONVERTORS)) 140 return 1; 141 142 if (PyObject_TypeCheck(sipPy, sipTypeAsPyTypeObject(sipType_QEasingCurve_Type))) 143 return 1; 144 145 return 0; 146} 147 148if (sipCanConvertToType(sipPy, sipType_QEasingCurve, SIP_NO_CONVERTORS)) 149{ 150 *sipCppPtr = reinterpret_cast<QEasingCurve *>(sipConvertToType(sipPy, sipType_QEasingCurve, sipTransferObj, SIP_NO_CONVERTORS, 0, sipIsErr)); 151 152 return 0; 153} 154 155*sipCppPtr = new QEasingCurve((QEasingCurve::Type)SIPLong_AsLong(sipPy)); 156 157return sipGetState(sipTransferObj); 158%End 159 160public: 161 enum Type 162 { 163 Linear, 164 InQuad, 165 OutQuad, 166 InOutQuad, 167 OutInQuad, 168 InCubic, 169 OutCubic, 170 InOutCubic, 171 OutInCubic, 172 InQuart, 173 OutQuart, 174 InOutQuart, 175 OutInQuart, 176 InQuint, 177 OutQuint, 178 InOutQuint, 179 OutInQuint, 180 InSine, 181 OutSine, 182 InOutSine, 183 OutInSine, 184 InExpo, 185 OutExpo, 186 InOutExpo, 187 OutInExpo, 188 InCirc, 189 OutCirc, 190 InOutCirc, 191 OutInCirc, 192 InElastic, 193 OutElastic, 194 InOutElastic, 195 OutInElastic, 196 InBack, 197 OutBack, 198 InOutBack, 199 OutInBack, 200 InBounce, 201 OutBounce, 202 InOutBounce, 203 OutInBounce, 204 InCurve, 205 OutCurve, 206 SineCurve, 207 CosineCurve, 208 BezierSpline, 209 TCBSpline, 210 Custom, 211 }; 212 213 QEasingCurve(QEasingCurve::Type type = QEasingCurve::Linear); 214 QEasingCurve(const QEasingCurve &other); 215 ~QEasingCurve(); 216 bool operator==(const QEasingCurve &other) const; 217 bool operator!=(const QEasingCurve &other) const; 218 qreal amplitude() const; 219 void setAmplitude(qreal amplitude); 220 qreal period() const; 221 void setPeriod(qreal period); 222 qreal overshoot() const; 223 void setOvershoot(qreal overshoot); 224 QEasingCurve::Type type() const; 225 void setType(QEasingCurve::Type type); 226 void setCustomType(SIP_PYCALLABLE func /TypeHint="Callable[[float], float]"/); 227%MethodCode 228 int i; 229 ec_custom_type *ct; 230 231 for (i = 0; i < ec_nr_custom_types; ++i) 232 { 233 ct = &ec_custom_types[i]; 234 235 if (!ct->py_func || ct->py_func == a0) 236 break; 237 } 238 239 if (i == ec_nr_custom_types) 240 { 241 PyErr_Format(PyExc_ValueError, "a maximum of %d different easing functions are supported", ec_nr_custom_types); 242 sipError = sipErrorFail; 243 } 244 else 245 { 246 if (!ct->py_func) 247 { 248 ct->py_func = a0; 249 Py_INCREF(a0); 250 } 251 252 sipCpp->setCustomType(ct->func); 253 } 254%End 255 256 SIP_PYCALLABLE customType() const /TypeHint="Callable[[float], float]"/; 257%MethodCode 258 QEasingCurve::EasingFunction func = sipCpp->customType(); 259 260 sipRes = Py_None; 261 262 if (func) 263 { 264 for (int i = 0; i < ec_nr_custom_types; ++i) 265 { 266 if (ec_custom_types[i].func == func) 267 { 268 sipRes = ec_custom_types[i].py_func; 269 break; 270 } 271 } 272 } 273 274 Py_INCREF(sipRes); 275%End 276 277 qreal valueForProgress(qreal progress) const; 278 void swap(QEasingCurve &other /Constrained/); 279 void addCubicBezierSegment(const QPointF &c1, const QPointF &c2, const QPointF &endPoint); 280 void addTCBSegment(const QPointF &nextPoint, qreal t, qreal c, qreal b); 281 QVector<QPointF> toCubicSpline() const; 282}; 283 284QDataStream &operator<<(QDataStream &, const QEasingCurve & /Constrained/) /ReleaseGIL/; 285QDataStream &operator>>(QDataStream &, QEasingCurve & /Constrained/) /ReleaseGIL/; 286