Selaa lähdekoodia

LibGfx: Implement Rect resizing around a fixed point

Ben Wiederhake 4 vuotta sitten
vanhempi
commit
e8997e1de9
2 muutettua tiedostoa jossa 12 lisäystä ja 0 poistoa
  1. 10 0
      Userland/Libraries/LibGfx/Rect.cpp
  2. 2 0
      Userland/Libraries/LibGfx/Rect.h

+ 10 - 0
Userland/Libraries/LibGfx/Rect.cpp

@@ -141,6 +141,16 @@ void Rect<T>::align_within(const Rect<T>& other, TextAlignment alignment)
     }
 }
 
+template<typename T>
+void Rect<T>::set_size_around(const Size<T>& new_size, const Point<T>& fixed_point)
+{
+    const T new_x = fixed_point.x() - (T)(new_size.width() * ((float)(fixed_point.x() - x()) / width()));
+    const T new_y = fixed_point.y() - (T)(new_size.height() * ((float)(fixed_point.y() - y()) / height()));
+
+    set_location({ new_x, new_y });
+    set_size(new_size);
+}
+
 template<>
 String IntRect::to_string() const
 {

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

@@ -114,6 +114,8 @@ public:
         m_size = size;
     }
 
+    void set_size_around(const Size<T>&, const Point<T>& fixed_point);
+
     void set_size(T width, T height)
     {
         m_size.set_width(width);