Extra "ports" of juce-based plugins using the distrho build system
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

587 lines
15KB

  1. --- Path.
  2. -- Is a pointer to a [JUCE Path](http://www.juce.com/api/classPath.html).
  3. -- @classmod juce.Path
  4. local script = require "include/core/script"
  5. local Point = require"include/protojuce/point"
  6. local AffineTransform = require"include/protojuce/affinetransform"
  7. local util = require"include/luautil"
  8. util.requireCdef(script.protoplugDir.."/include/protojuce/cdef/path.h")
  9. --- Constuctor
  10. -- @within Constructors
  11. -- @constructor
  12. -- @function Path
  13. local Path_mt = {
  14. -- methods
  15. __index = {
  16. --- Get bounds.
  17. -- @treturn Rectangle_float rectangle containing the path
  18. -- @function getBounds
  19. getBounds = function (self)
  20. return protolib.Path_getBounds(self)
  21. end;
  22. --- Get bounds transformed.
  23. -- @tparam juce.AffineTransform transform
  24. -- @treturn Rectangle_float rectangle containing the transformed path
  25. -- @function getBoundsTransformed
  26. getBoundsTransformed = function (self, transform)
  27. return protolib.Path_getBoundsTransformed (self, transform)
  28. end;
  29. --- Contains.
  30. -- @param pointX
  31. -- @param pointY
  32. -- @param[opt=1] tolerance
  33. -- @treturn boolean whether the path contains the point
  34. -- @see closeSubPath
  35. -- @function contains
  36. --- Contains.
  37. -- @tparam juce.Point point
  38. -- @param[opt=1] tolerance
  39. -- @treturn boolean whether the path contains the point
  40. -- @see closeSubPath
  41. -- @function contains
  42. contains = function (self, ...)
  43. local control = ...
  44. tolerance = tolerance or 1
  45. if type(control)=="number" then
  46. return protolib.Path_contains (self, ...)
  47. else
  48. return protolib.Path_contains2 (self, ...)
  49. end
  50. end;
  51. --- Intersects line.
  52. -- @tparam juce.Line line
  53. -- @param[opt=1] tolerance
  54. -- @treturn boolean whether the path intersects the line
  55. -- @function intersectsLine
  56. intersectsLine = function (self, line, tolerance)
  57. tolerance = tolerance or 1
  58. return protolib.Path_intersectsLine (self, line, tolerance)
  59. end;
  60. --- Get clipped line.
  61. -- @tparam juce.Line line
  62. -- @tparam boolean keepSectionOutsidePath
  63. -- @treturn juce.Line_float the line clipped by the path
  64. -- @function getClippedLine
  65. getClippedLine = function (self, line, keepSectionOutsidePath)
  66. return protolib.Path_getClippedLine (self, line, keepSectionOutsidePath)
  67. end;
  68. --- Get length.
  69. -- @tparam[opt=juce.AffineTransform.identity] juce.AffineTransform transform
  70. -- @return length of the path
  71. -- @function getLength
  72. getLength = function (self, transform)
  73. transform = transform or AffineTransform.identity
  74. return protolib.Path_getLength (self, transform)
  75. end;
  76. --- Get point along path.
  77. -- @param distanceFromStart
  78. -- @tparam[opt=juce.AffineTransform.identity] juce.AffineTransform transform
  79. -- @treturn Point_float the point on the path
  80. -- @function getPointAlongPath
  81. getPointAlongPath = function (self, distanceFromStart, transform)
  82. transform = transform or AffineTransform.identity
  83. return protolib.Path_getPointAlongPath (self, distanceFromStart, transform)
  84. end;
  85. --- Get nearest point.
  86. -- Get the nearest on-path point to an arbitrary point, and
  87. -- the distance between the points
  88. -- @tparam juce.Point targetPoint
  89. -- @tparam[opt=juce.AffineTransform.identity] juce.AffineTransform transform
  90. -- @return distance
  91. -- @treturn juce.Point pointOnPath
  92. -- @function getNearestPoint
  93. getNearestPoint = function (self, targetPoint,
  94. transform)
  95. transform = transform or AffineTransform.identity
  96. local pointOnPath = Point()
  97. local distance = protolib.Path_getNearestPoint (self, targetPoint,
  98. pointOnPath,
  99. transform)
  100. return distance, pointOnPath
  101. end;
  102. --- Clear.
  103. -- @function clear
  104. clear = function (self)
  105. protolib.Path_clear(self)
  106. end;
  107. --- Start new sub path.
  108. -- @param startX
  109. -- @param startY
  110. -- @function startNewSubPath
  111. --- Start new sub path.
  112. -- @tparam juce.Point start
  113. -- @function startNewSubPath
  114. startNewSubPath = function (self, ...)
  115. local control = ...
  116. if type(control)=="number" then
  117. protolib.Path_startNewSubPath (self, ...)
  118. else
  119. protolib.Path_startNewSubPath2 (self, ...)
  120. end
  121. end;
  122. --- Close sub path.
  123. -- @function closeSubPath
  124. closeSubPath = function (self)
  125. protolib.Path_closeSubPath(self)
  126. end;
  127. --- Line to.
  128. -- @param endX
  129. -- @param endY
  130. -- @function lineTo
  131. --- Line to.
  132. -- @tparam juce.Point endpoint
  133. -- @function lineTo
  134. lineTo = function (self, ...)
  135. local control = ...
  136. if type(control)=="number" then
  137. protolib.Path_lineTo (self, ...)
  138. else
  139. protolib.Path_lineTo2 (self, ...)
  140. end
  141. end;
  142. --- Quadratic to.
  143. -- @param controlPointX
  144. -- @param controlPointY
  145. -- @param endPointX
  146. -- @param endPointY
  147. -- @function quadraticTo
  148. --- Quadratic to2.
  149. -- @tparam juce.Point controlPoint
  150. -- @tparam juce.Point endPoint
  151. -- @function quadraticTo2
  152. quadraticTo = function (self, ...)
  153. local control = ...
  154. if type(control)=="number" then
  155. protolib.Path_quadraticTo (self, ...)
  156. else
  157. protolib.Path_quadraticTo2 (self, ...)
  158. end
  159. end;
  160. --- Cubic to.
  161. -- @param controlPoint1X
  162. -- @param controlPoint1Y
  163. -- @param controlPoint2X
  164. -- @param controlPoint2Y
  165. -- @param endPointX
  166. -- @param endPointY
  167. -- @function cubicTo
  168. --- Cubic to.
  169. -- @tparam juce.Point controlPoint1
  170. -- @tparam juce.Point controlPoint2
  171. -- @tparam juce.Point endPoint
  172. -- @function cubicTo
  173. cubicTo = function (self, ...)
  174. local control = ...
  175. if type(control)=="number" then
  176. protolib.Path_cubicTo (self, ...)
  177. else
  178. protolib.Path_cubicTo2 (self, ...)
  179. end
  180. end;
  181. --- Get current position.
  182. -- @treturn juce.Point the current path construction position
  183. -- @function getCurrentPosition
  184. getCurrentPosition = function (self)
  185. return protolib.Path_getCurrentPosition(self)
  186. end;
  187. --- Add rectangle.
  188. -- @param x
  189. -- @param y
  190. -- @param width
  191. -- @param height
  192. -- @function addRectangle
  193. --- Add rectangle.
  194. -- @tparam juce.Rectangle_float rectangle
  195. -- @function addRectangle
  196. addRectangle = function (self, ...)
  197. local control = ...
  198. if type(control)=="number" then
  199. protolib.Path_addRectangle (self, ...)
  200. else
  201. protolib.Path_addRectangle2 (self, ...)
  202. end
  203. end;
  204. --- Add rounded rectangle.
  205. -- @param x
  206. -- @param y
  207. -- @param width
  208. -- @param height
  209. -- @param cornerSize
  210. -- @function addRoundedRectangle
  211. --- Add rounded rectangle.
  212. -- @param x
  213. -- @param y
  214. -- @param width
  215. -- @param height
  216. -- @param cornerSizeX
  217. -- @param cornerSizeY
  218. -- @function addRoundedRectangle
  219. --- Add rounded rectangle.
  220. -- @param x
  221. -- @param y
  222. -- @param width
  223. -- @param height
  224. -- @param cornerSizeX
  225. -- @param cornerSizeY
  226. -- @tparam boolean curveTopLeft
  227. -- @tparam boolean curveTopRight
  228. -- @tparam boolean curveBottomLeft
  229. -- @tparam boolean curveBottomRight
  230. -- @function addRoundedRectangle
  231. --- Add rounded rectangle.
  232. -- @tparam juce.Rectangle_float rectangle
  233. -- @param cornerSizeX
  234. -- @param cornerSizeY
  235. -- @function addRoundedRectangle
  236. --- Add rounded rectangle.
  237. -- @tparam juce.Rectangle_float rectangle
  238. -- @param cornerSize
  239. -- @function addRoundedRectangle
  240. addRoundedRectangle = function (self, ...)
  241. if select('#',...) == 5 then
  242. protolib.Path_addRoundedRectangle2 (self, ...)
  243. elseif select('#',...) == 6 then
  244. protolib.Path_addRoundedRectangle3 (self, ...)
  245. elseif select('#',...) == 10 then
  246. protolib.Path_addRoundedRectangle4 (self, ...)
  247. elseif select('#',...) == 3 then
  248. protolib.Path_addRoundedRectangle5 (self, ...)
  249. elseif select('#',...) == 2 then
  250. protolib.Path_addRoundedRectangle6 (self, ...)
  251. end
  252. end;
  253. --- Add triangle.
  254. -- @param x1
  255. -- @param y1
  256. -- @param x2
  257. -- @param y2
  258. -- @param x3
  259. -- @param y3
  260. -- @function addTriangle
  261. addTriangle = function (self, x1, y1,
  262. x2, y2,
  263. x3, y3)
  264. protolib.Path_addTriangle (self, x1, y1,
  265. x2, y2,
  266. x3, y3)
  267. end;
  268. --- Add quadrilateral.
  269. -- @param x1
  270. -- @param y1
  271. -- @param x2
  272. -- @param y2
  273. -- @param x3
  274. -- @param y3
  275. -- @param x4
  276. -- @param y4
  277. -- @function addQuadrilateral
  278. addQuadrilateral = function (self, x1, y1,
  279. x2, y2,
  280. x3, y3,
  281. x4, y4)
  282. protolib.Path_addQuadrilateral (self, x1, y1,
  283. x2, y2,
  284. x3, y3,
  285. x4, y4)
  286. end;
  287. --- Add ellipse.
  288. -- @param x
  289. -- @param y
  290. -- @param width
  291. -- @param height
  292. -- @function addEllipse
  293. addEllipse = function (self, x, y, width, height)
  294. protolib.Path_addEllipse (self, x, y, width, height)
  295. end;
  296. --- Add arc.
  297. -- @param x
  298. -- @param y
  299. -- @param width
  300. -- @param height
  301. -- @param fromRadians the start angle, clockwise from the top
  302. -- @param toRadians the end angle
  303. -- @param[opt=false] startAsNewSubPath
  304. -- @function addArc
  305. addArc = function (self, x, y, width, height,
  306. fromRadians,
  307. toRadians, startAsNewSubPath)
  308. startAsNewSubPath = startAsNewSubPath or false
  309. protolib.Path_addArc (self, x, y, width, height,
  310. fromRadians,
  311. toRadians, startAsNewSubPath)
  312. end;
  313. --- Add centred arc.
  314. -- @param centreX
  315. -- @param centreY
  316. -- @param radiusX
  317. -- @param radiusY
  318. -- @param rotationOfEllipse the ellipse inclination
  319. -- @param fromRadians the start angle, clockwise from the top
  320. -- @param toRadians the end angle
  321. -- @param[opt=false] startAsNewSubPath
  322. -- @function addCentredArc
  323. addCentredArc = function (self, centreX, centreY,
  324. radiusX, radiusY,
  325. rotationOfEllipse,
  326. fromRadians,
  327. toRadians, startAsNewSubPath)
  328. startAsNewSubPath = startAsNewSubPath or false
  329. protolib.Path_addCentredArc (self, centreX, centreY,
  330. radiusX, radiusY,
  331. rotationOfEllipse,
  332. fromRadians,
  333. toRadians, startAsNewSubPath)
  334. end;
  335. --- Add pie segment.
  336. -- @param x
  337. -- @param y
  338. -- @param width
  339. -- @param height
  340. -- @param fromRadians the start angle, clockwise from the top
  341. -- @param toRadians the end angle
  342. -- @param[opt=0] innerCircleProportionalSize band proportion size, if specified
  343. -- @function addPieSegment
  344. addPieSegment = function (self, x, y,
  345. width, height,
  346. fromRadians,
  347. toRadians, innerCircleProportionalSize)
  348. innerCircleProportionalSize = innerCircleProportionalSize or 0
  349. protolib.Path_addPieSegment (self, x, y,
  350. width, height,
  351. fromRadians,
  352. toRadians, innerCircleProportionalSize)
  353. end;
  354. --- Add line segment.
  355. -- @tparam juce.Line line
  356. -- @param lineThickness
  357. -- @function addLineSegment
  358. addLineSegment = function (self, line, lineThickness)
  359. protolib.Path_addLineSegment (self, line, lineThickness)
  360. end;
  361. --- Add arrow.
  362. -- @tparam juce.Line line
  363. -- @param lineThickness
  364. -- @param arrowheadWidth
  365. -- @param arrowheadLength
  366. -- @function addArrow
  367. addArrow = function (self, line,
  368. lineThickness,
  369. arrowheadWidth, arrowheadLength)
  370. protolib.Path_addArrow (self, line,
  371. lineThickness,
  372. arrowheadWidth, arrowheadLength)
  373. end;
  374. --- Add polygon.
  375. -- @tparam juce.Point centre
  376. -- @param numberOfSides
  377. -- @param radius
  378. -- @param[opt=0] startAngle
  379. -- @function addPolygon
  380. addPolygon = function (self, centre,
  381. numberOfSides,
  382. radius, startAngle)
  383. startAngle = startAngle or 0
  384. protolib.Path_addPolygon (self, centre,
  385. numberOfSides,
  386. radius, startAngle)
  387. end;
  388. --- Add star.
  389. -- @tparam juce.Point centre
  390. -- @param numberOfPoints
  391. -- @param innerRadius
  392. -- @param outerRadius
  393. -- @param[opt=0] startAngle
  394. -- @function addStar
  395. addStar = function (self, centre,
  396. numberOfPoints,
  397. innerRadius,
  398. outerRadius, startAngle)
  399. startAngle = startAngle or 0
  400. protolib.Path_addStar (self, centre,
  401. numberOfPoints,
  402. innerRadius,
  403. outerRadius, startAngle)
  404. end;
  405. --- Add bubble.
  406. -- @param bodyArea
  407. -- @param maximumArea
  408. -- @param arrowTipPosition
  409. -- @param cornerSize
  410. -- @param arrowBaseWidth
  411. -- @function addBubble
  412. addBubble = function (self, bodyArea,
  413. maximumArea,
  414. arrowTipPosition,
  415. cornerSize, arrowBaseWidth)
  416. protolib.Path_addBubble (self, bodyArea,
  417. maximumArea,
  418. arrowTipPosition,
  419. cornerSize, arrowBaseWidth)
  420. end;
  421. --- Add path.
  422. -- @param pathToAppend
  423. -- @tparam[opt=juce.AffineTransform.identity] juce.AffineTransform transform
  424. -- @function addPath
  425. addPath = function (self, pathToAppend, transformToApply)
  426. if transformToApply then
  427. protolib.Path_addPath2 (self, pathToAppend, transformToApply)
  428. else
  429. protolib.Path_addPath (self, pathToAppend)
  430. end
  431. end;
  432. --- Apply transform.
  433. -- @tparam juce.AffineTransform transform
  434. -- @function applyTransform
  435. applyTransform = function (self, transform)
  436. protolib.Path_applyTransform (self, transform)
  437. end;
  438. --- Scale to fit.
  439. -- @param x
  440. -- @param y
  441. -- @param width
  442. -- @param height
  443. -- @param preserveProportions
  444. -- @function scaleToFit
  445. scaleToFit = function (self, x, y, width, height, preserveProportions)
  446. protolib.Path_scaleToFit (self, x, y, width, height, preserveProportions)
  447. end;
  448. --- Get transform to scale to fit.
  449. -- @param x
  450. -- @param y
  451. -- @param width
  452. -- @param height
  453. -- @tparam boolean preserveProportions
  454. -- @tparam[opt=Justification.centred] juce.Justification justification
  455. -- @treturn juce.AffineTransform the required transform
  456. -- @function getTransformToScaleToFit
  457. --- Get transform to scale to fit.
  458. -- @tparam juce.Rectangle_float area
  459. -- @tparam boolean preserveProportions
  460. -- @tparam[opt=Justification.centred] juce.Justification justification
  461. -- @treturn juce.AffineTransform the required transform
  462. -- @function getTransformToScaleToFit
  463. getTransformToScaleToFit = function (self, ...)
  464. local control = ...
  465. if type(control)=="number" then
  466. return protolib.Path_getTransformToScaleToFit (self, ...)
  467. else
  468. return protolib.Path_getTransformToScaleToFit2 (self, ...)
  469. end
  470. end;
  471. --- Create path with rounded corners.
  472. -- @param cornerRadius
  473. -- @treturn juce.Path the rounded path
  474. -- @function createPathWithRoundedCorners
  475. createPathWithRoundedCorners = function (self, cornerRadius)
  476. return protolib.Path_createPathWithRoundedCorners (self, cornerRadius)
  477. end;
  478. --- Set using non zero winding.
  479. -- @tparam boolean isNonZeroWinding
  480. -- @function setUsingNonZeroWinding
  481. setUsingNonZeroWinding = function (self, isNonZeroWinding)
  482. protolib.Path_setUsingNonZeroWinding (self, isNonZeroWinding)
  483. end;
  484. --- Is using non zero winding.
  485. -- @treturn boolean whether the path is using non-zero winding
  486. -- @function isUsingNonZeroWinding
  487. isUsingNonZeroWinding = function (self)
  488. return protolib.Path_isUsingNonZeroWinding(self)
  489. end;
  490. toString = function (self, dest, bufSize)
  491. protolib.Path_toString(self, dest, bufSize)
  492. end;
  493. restoreFromString = function (self, src)
  494. protolib.Path_restoreFromString (self, src)
  495. end;
  496. }
  497. }
  498. ffi.metatype("pPath", Path_mt)
  499. local Line = ffi.typeof("Line_float")
  500. local Path = {
  501. --- Joint styles.
  502. -- for use with @{juce.Graphics.strokePath}
  503. -- @table juce.Path.JointStyle
  504. JointStyle =
  505. {
  506. mitered = 0;
  507. curved = 1;
  508. beveled = 2
  509. };
  510. --- End cap styles.
  511. -- for use with @{juce.Graphics.strokePath}
  512. -- @table juce.Path.EndCapStyle
  513. EndCapStyle =
  514. {
  515. butt = 0;
  516. square = 1;
  517. rounded = 2
  518. }
  519. };
  520. Path = setmetatable(Path,{
  521. -- constructor
  522. __call = function ()
  523. return ffi.gc(
  524. protolib.Path_new(),
  525. protolib.Path_delete
  526. )
  527. end;
  528. })
  529. return Path