gl_math.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #pragma once
  8. #include <QtGui/QVector4D>
  9. #include <QtCore/QSizeF>
  10. namespace Ui::GL {
  11. class Rect final {
  12. public:
  13. Rect(QRect rect)
  14. : _x(rect.x())
  15. , _y(rect.y())
  16. , _width(rect.width())
  17. , _height(rect.height()) {
  18. }
  19. Rect(QRectF rect)
  20. : _x(rect.x())
  21. , _y(rect.y())
  22. , _width(rect.width())
  23. , _height(rect.height()) {
  24. }
  25. Rect(float x, float y, float width, float height)
  26. : _x(x)
  27. , _y(y)
  28. , _width(width)
  29. , _height(height) {
  30. }
  31. [[nodiscard]] float x() const {
  32. return _x;
  33. }
  34. [[nodiscard]] float y() const {
  35. return _y;
  36. }
  37. [[nodiscard]] float width() const {
  38. return _width;
  39. }
  40. [[nodiscard]] float height() const {
  41. return _height;
  42. }
  43. [[nodiscard]] float left() const {
  44. return _x;
  45. }
  46. [[nodiscard]] float top() const {
  47. return _y;
  48. }
  49. [[nodiscard]] float right() const {
  50. return _x + _width;
  51. }
  52. [[nodiscard]] float bottom() const {
  53. return _y + _height;
  54. }
  55. [[nodiscard]] bool empty() const {
  56. return (_width <= 0) || (_height <= 0);
  57. }
  58. private:
  59. float _x = 0;
  60. float _y = 0;
  61. float _width = 0;
  62. float _height = 0;
  63. };
  64. [[nodiscard]] QVector4D Uniform(const QRect &rect, float factor);
  65. [[nodiscard]] QVector4D Uniform(const Rect &rect);
  66. [[nodiscard]] QSizeF Uniform(QSize size);
  67. [[nodiscard]] Rect TransformRect(
  68. const Rect &raster,
  69. QSize viewport,
  70. float factor);
  71. } // namespace Ui::GL