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.

89 lines
2.0KB

  1. --- An integer (pixel-aligned) rectangle.
  2. -- Is converted to a [JUCE Rectangle](http://www.juce.com/api/classRectangle.html)
  3. -- @classmod juce.Rectangle_int
  4. --- Constuctor with classical arguments.
  5. -- @param x left position
  6. -- @param y top position
  7. -- @param w width
  8. -- @param h height
  9. -- @within Constructors
  10. -- @constructor
  11. -- @function Rectangle_int
  12. --- Constuctor with named arguments.
  13. -- Every field is optional.
  14. -- @tparam table args
  15. -- @param args.x left position
  16. -- @param args.y top position
  17. -- @param args.w width
  18. -- @param args.h height
  19. -- @within Constructors
  20. -- @constructor
  21. -- @function Rectangle_int
  22. local Rectangle_int = ffi.typeof("Rectangle_int")
  23. local Rectangle_float = {} -- circular dependency technique
  24. local Rectangle_int_mt = {
  25. -- operator '=='
  26. __eq = function(self, rhs)
  27. return self.x == rhs.x and
  28. self.y == rhs.y and
  29. self.w == rhs.w and
  30. self.h == rhs.h
  31. end;
  32. -- methods
  33. __index = {
  34. --- To float.
  35. -- Convert to a sub-pixel rectangle
  36. -- @treturn juce.Rectangle_float
  37. -- @function toFloat
  38. toFloat = function (self)
  39. Rectangle_float = Rectangle_float or require"include/protojuce/rectangle_float"
  40. return Rectangle_float {
  41. self.x, self.y, self.w, self.h
  42. }
  43. end;
  44. --- Contains.
  45. -- @tparam juce.Point point
  46. -- @treturn boolean whether the rectangle contains the point
  47. -- @function contains
  48. contains = function (self, p)
  49. return p.x>=self.x and p.x<=(self.x+self.w) and
  50. p.y>=self.y and p.y<=(self.y+self.h)
  51. end;
  52. --- Get right.
  53. -- @return the rectangle's right position on the X axis
  54. -- @function getR
  55. getR = function (self)
  56. return self.x + self.w
  57. end;
  58. --- Get bottom.
  59. -- @return the rectangle's bottom position on the Y axis
  60. -- @function getB
  61. getB = function (self)
  62. return self.y + self.h
  63. end;
  64. };
  65. }
  66. ffi.metatype(Rectangle_int, Rectangle_int_mt)
  67. --- Left position
  68. -- @simplefield x
  69. --- Top position
  70. -- @simplefield y
  71. --- Width
  72. -- @simplefield w
  73. --- Height
  74. -- @simplefield h
  75. return Rectangle_int