qeasingcurve.sip 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. // qeasingcurve.sip generated by MetaSIP
  2. //
  3. // This file is part of the QtCore Python extension module.
  4. //
  5. // Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  6. //
  7. // This file is part of PyQt6.
  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. class QEasingCurve /TypeHintIn="Union[QEasingCurve, QEasingCurve.Type]"/
  22. {
  23. %TypeHeaderCode
  24. #include <qeasingcurve.h>
  25. %End
  26. %TypeCode
  27. // The EasingFunction callback doesn't provide a context so we support a fixed
  28. // number of different functions.
  29. const int ec_nr_custom_types = 10;
  30. struct ec_custom_type {
  31. PyObject *py_func;
  32. QEasingCurve::EasingFunction func;
  33. };
  34. static qreal ec_call(int ec, qreal v);
  35. static qreal ec_func_0(qreal v)
  36. {
  37. return ec_call(0, v);
  38. }
  39. static qreal ec_func_1(qreal v)
  40. {
  41. return ec_call(1, v);
  42. }
  43. static qreal ec_func_2(qreal v)
  44. {
  45. return ec_call(2, v);
  46. }
  47. static qreal ec_func_3(qreal v)
  48. {
  49. return ec_call(3, v);
  50. }
  51. static qreal ec_func_4(qreal v)
  52. {
  53. return ec_call(4, v);
  54. }
  55. static qreal ec_func_5(qreal v)
  56. {
  57. return ec_call(5, v);
  58. }
  59. static qreal ec_func_6(qreal v)
  60. {
  61. return ec_call(6, v);
  62. }
  63. static qreal ec_func_7(qreal v)
  64. {
  65. return ec_call(7, v);
  66. }
  67. static qreal ec_func_8(qreal v)
  68. {
  69. return ec_call(8, v);
  70. }
  71. static qreal ec_func_9(qreal v)
  72. {
  73. return ec_call(9, v);
  74. }
  75. static ec_custom_type ec_custom_types[ec_nr_custom_types] = {
  76. {0, ec_func_0},
  77. {0, ec_func_1},
  78. {0, ec_func_2},
  79. {0, ec_func_3},
  80. {0, ec_func_4},
  81. {0, ec_func_5},
  82. {0, ec_func_6},
  83. {0, ec_func_7},
  84. {0, ec_func_8},
  85. {0, ec_func_9},
  86. };
  87. static qreal ec_call(int ec, qreal v)
  88. {
  89. PyObject *res_obj;
  90. qreal res = 0.0;
  91. SIP_BLOCK_THREADS
  92. res_obj = PyObject_CallFunction(ec_custom_types[ec].py_func, (char *)"(d)", (double)v);
  93. if (res_obj)
  94. {
  95. PyErr_Clear();
  96. res = PyFloat_AsDouble(res_obj);
  97. Py_DECREF(res_obj);
  98. if (PyErr_Occurred())
  99. res_obj = 0;
  100. }
  101. if (!res_obj)
  102. pyqt6_err_print();
  103. SIP_UNBLOCK_THREADS
  104. return res;
  105. }
  106. %End
  107. %ConvertToTypeCode
  108. // Allow a QEasingCurve::Type whenever a QEasingCurve is expected.
  109. bool is_ec_type = true;
  110. int ec_type = sipConvertToEnum(sipPy, sipType_QEasingCurve_Type);
  111. if (PyErr_Occurred())
  112. {
  113. PyErr_Clear();
  114. is_ec_type = false;
  115. }
  116. if (sipIsErr == NULL)
  117. return (is_ec_type ||
  118. sipCanConvertToType(sipPy, sipType_QEasingCurve, SIP_NO_CONVERTORS));
  119. if (is_ec_type)
  120. {
  121. *sipCppPtr = new QEasingCurve(static_cast<QEasingCurve::Type>(ec_type));
  122. return sipGetState(sipTransferObj);
  123. }
  124. *sipCppPtr = reinterpret_cast<QEasingCurve *>(sipConvertToType(sipPy,
  125. sipType_QEasingCurve, sipTransferObj, SIP_NO_CONVERTORS, 0, sipIsErr));
  126. return 0;
  127. %End
  128. public:
  129. enum Type
  130. {
  131. Linear,
  132. InQuad,
  133. OutQuad,
  134. InOutQuad,
  135. OutInQuad,
  136. InCubic,
  137. OutCubic,
  138. InOutCubic,
  139. OutInCubic,
  140. InQuart,
  141. OutQuart,
  142. InOutQuart,
  143. OutInQuart,
  144. InQuint,
  145. OutQuint,
  146. InOutQuint,
  147. OutInQuint,
  148. InSine,
  149. OutSine,
  150. InOutSine,
  151. OutInSine,
  152. InExpo,
  153. OutExpo,
  154. InOutExpo,
  155. OutInExpo,
  156. InCirc,
  157. OutCirc,
  158. InOutCirc,
  159. OutInCirc,
  160. InElastic,
  161. OutElastic,
  162. InOutElastic,
  163. OutInElastic,
  164. InBack,
  165. OutBack,
  166. InOutBack,
  167. OutInBack,
  168. InBounce,
  169. OutBounce,
  170. InOutBounce,
  171. OutInBounce,
  172. InCurve,
  173. OutCurve,
  174. SineCurve,
  175. CosineCurve,
  176. BezierSpline,
  177. TCBSpline,
  178. Custom,
  179. };
  180. QEasingCurve(QEasingCurve::Type type = QEasingCurve::Linear);
  181. QEasingCurve(const QEasingCurve &other);
  182. ~QEasingCurve();
  183. %If (- Qt_6_8_0)
  184. bool operator==(const QEasingCurve &other) const;
  185. %End
  186. %If (- Qt_6_8_0)
  187. bool operator!=(const QEasingCurve &other) const;
  188. %End
  189. qreal amplitude() const;
  190. void setAmplitude(qreal amplitude);
  191. qreal period() const;
  192. void setPeriod(qreal period);
  193. qreal overshoot() const;
  194. void setOvershoot(qreal overshoot);
  195. QEasingCurve::Type type() const;
  196. void setType(QEasingCurve::Type type);
  197. void setCustomType(SIP_PYCALLABLE func /TypeHint="Callable[[float], float]"/);
  198. %MethodCode
  199. int i;
  200. ec_custom_type *ct;
  201. for (i = 0; i < ec_nr_custom_types; ++i)
  202. {
  203. ct = &ec_custom_types[i];
  204. if (!ct->py_func || ct->py_func == a0)
  205. break;
  206. }
  207. if (i == ec_nr_custom_types)
  208. {
  209. PyErr_Format(PyExc_ValueError, "a maximum of %d different easing functions are supported", ec_nr_custom_types);
  210. sipError = sipErrorFail;
  211. }
  212. else
  213. {
  214. if (!ct->py_func)
  215. {
  216. ct->py_func = a0;
  217. Py_INCREF(a0);
  218. }
  219. sipCpp->setCustomType(ct->func);
  220. }
  221. %End
  222. SIP_PYCALLABLE customType() const /TypeHint="Callable[[float], float]"/;
  223. %MethodCode
  224. QEasingCurve::EasingFunction func = sipCpp->customType();
  225. sipRes = Py_None;
  226. if (func)
  227. {
  228. for (int i = 0; i < ec_nr_custom_types; ++i)
  229. {
  230. if (ec_custom_types[i].func == func)
  231. {
  232. sipRes = ec_custom_types[i].py_func;
  233. break;
  234. }
  235. }
  236. }
  237. Py_INCREF(sipRes);
  238. %End
  239. qreal valueForProgress(qreal progress) const;
  240. void swap(QEasingCurve &other /Constrained/);
  241. void addCubicBezierSegment(const QPointF &c1, const QPointF &c2, const QPointF &endPoint);
  242. void addTCBSegment(const QPointF &nextPoint, qreal t, qreal c, qreal b);
  243. QList<QPointF> toCubicSpline() const;
  244. };
  245. QDataStream &operator<<(QDataStream &, const QEasingCurve & /Constrained/) /ReleaseGIL/;
  246. QDataStream &operator>>(QDataStream &, QEasingCurve & /Constrained/) /ReleaseGIL/;
  247. %If (Qt_6_8_0 -)
  248. bool operator!=(const QEasingCurve &lhs, const QEasingCurve &rhs);
  249. %End
  250. %If (Qt_6_8_0 -)
  251. bool operator==(const QEasingCurve &lhs, const QEasingCurve &rhs);
  252. %End