Przeglądaj źródła

LibGfx: Add Rect::centered_on()

This is a helper function for creating Rects of a given Size centered
on a Point.
Dmitrii Ubskii 4 lat temu
rodzic
commit
30c831a3be
1 zmienionych plików z 5 dodań i 0 usunięć
  1. 5 0
      Userland/Libraries/LibGfx/Rect.h

+ 5 - 0
Userland/Libraries/LibGfx/Rect.h

@@ -422,6 +422,11 @@ public:
 
     void intersect(const Rect<T>&);
 
+    static Rect<T> centered_on(const Point<T>& center, const Size<T>& size)
+    {
+        return { { center.x() - size.width() / 2, center.y() - size.height() / 2 }, size };
+    }
+
     static Rect<T> from_two_points(const Point<T>& a, const Point<T>& b)
     {
         return { min(a.x(), b.x()), min(a.y(), b.y()), abst(a.x() - b.x()), abst(a.y() - b.y()) };