commit 6b2bad1d795898d06006e8e8b3ab54b271c448e2
parent c8ffd642778cd48debe1d1c8eb258fd7dd7e8771
Author: falkTX <falktx@gmail.com>
Date: Sat, 3 May 2014 12:16:03 +0200
More cleanup
Diffstat:
3 files changed, 98 insertions(+), 65 deletions(-)
diff --git a/dgl/Geometry.hpp b/dgl/Geometry.hpp
@@ -28,17 +28,19 @@ class Point
{
public:
Point() noexcept;
- Point(T x, T y) noexcept;
+ Point(const T& x, const T& y) noexcept;
Point(const Point<T>& pos) noexcept;
- T getX() const noexcept;
- T getY() const noexcept;
+ const T& getX() const noexcept;
+ const T& getY() const noexcept;
- void setX(T x) noexcept;
- void setY(T y) noexcept;
+ void setX(const T& x) noexcept;
+ void setY(const T& y) noexcept;
+ void setPos(const T& x, const T& y) noexcept;
+ void setPos(const Point<T>& pos) noexcept;
- void move(T x, T y) noexcept;
- void move(const Point<T>& pos) noexcept;
+ void moveBy(const T& x, const T& y) noexcept;
+ void moveBy(const Point<T>& pos) noexcept;
Point<T>& operator=(const Point<T>& pos) noexcept;
Point<T>& operator+=(const Point<T>& pos) noexcept;
@@ -60,20 +62,23 @@ class Size
{
public:
Size() noexcept;
- Size(T width, T height) noexcept;
+ Size(const T& width, const T& height) noexcept;
Size(const Size<T>& size) noexcept;
- T getWidth() const noexcept;
- T getHeight() const noexcept;
+ const T& getWidth() const noexcept;
+ const T& getHeight() const noexcept;
+
+ void setWidth(const T& width) noexcept;
+ void setHeight(const T& height) noexcept;
- void setWidth(T width) noexcept;
- void setHeight(T height) noexcept;
+ void growBy(const T& multiplier) noexcept;
+ void shrinkBy(const T& divider) noexcept;
Size<T>& operator=(const Size<T>& size) noexcept;
Size<T>& operator+=(const Size<T>& size) noexcept;
Size<T>& operator-=(const Size<T>& size) noexcept;
- Size<T>& operator*=(T m) noexcept;
- Size<T>& operator/=(T d) noexcept;
+ Size<T>& operator*=(const T& m) noexcept;
+ Size<T>& operator/=(const T& d) noexcept;
bool operator==(const Size<T>& size) const noexcept;
bool operator!=(const Size<T>& size) const noexcept;
@@ -91,36 +96,36 @@ class Rectangle
{
public:
Rectangle() noexcept;
- Rectangle(T x, T y, T width, T height) noexcept;
- Rectangle(T x, T y, const Size<T>& size) noexcept;
- Rectangle(const Point<T>& pos, T width, T height) noexcept;
+ Rectangle(const T& x, const T& y, const T& width, const T& height) noexcept;
+ Rectangle(const T& x, const T& y, const Size<T>& size) noexcept;
+ Rectangle(const Point<T>& pos, const T& width, const T& height) noexcept;
Rectangle(const Point<T>& pos, const Size<T>& size) noexcept;
Rectangle(const Rectangle<T>& rect) noexcept;
- T getX() const noexcept;
- T getY() const noexcept;
- T getWidth() const noexcept;
- T getHeight() const noexcept;
+ const T& getX() const noexcept;
+ const T& getY() const noexcept;
+ const T& getWidth() const noexcept;
+ const T& getHeight() const noexcept;
const Point<T>& getPos() const noexcept;
const Size<T>& getSize() const noexcept;
- bool contains(T x, T y) const noexcept;
+ bool contains(const T& x, const T& y) const noexcept;
bool contains(const Point<T>& pos) const noexcept;
- bool containsX(T x) const noexcept;
- bool containsY(T y) const noexcept;
+ bool containsX(const T& x) const noexcept;
+ bool containsY(const T& y) const noexcept;
- void setX(T x) noexcept;
- void setY(T y) noexcept;
- void setPos(T x, T y) noexcept;
+ void setX(const T& x) noexcept;
+ void setY(const T& y) noexcept;
+ void setPos(const T& x, const T& y) noexcept;
void setPos(const Point<T>& pos) noexcept;
- void move(T x, T y) noexcept;
+ void move(const T& x, const T& y) noexcept;
void move(const Point<T>& pos) noexcept;
- void setWidth(T width) noexcept;
- void setHeight(T height) noexcept;
- void setSize(T width, T height) noexcept;
+ void setWidth(const T& width) noexcept;
+ void setHeight(const T& height) noexcept;
+ void setSize(const T& width, const T& height) noexcept;
void setSize(const Size<T>& size) noexcept;
Rectangle<T>& operator=(const Rectangle<T>& rect) noexcept;
diff --git a/dgl/src/App.cpp b/dgl/src/App.cpp
@@ -24,8 +24,8 @@ START_NAMESPACE_DGL
// -----------------------------------------------------------------------
struct App::PrivateData {
- bool doLoop;
- unsigned visibleWindows;
+ bool doLoop;
+ uint visibleWindows;
std::list<Window*> windows;
std::list<IdleCallback*> idleCallbacks;
diff --git a/dgl/src/Geometry.cpp b/dgl/src/Geometry.cpp
@@ -29,52 +29,66 @@ Point<T>::Point() noexcept
}
template<typename T>
-Point<T>::Point(T x, T y) noexcept
+Point<T>::Point(const T& x, const T& y) noexcept
: fX(x),
fY(y)
{
}
template<typename T>
-Point<T>::Point(const Point& pos) noexcept
+Point<T>::Point(const Point<T>& pos) noexcept
: fX(pos.fX),
fY(pos.fY)
{
}
template<typename T>
-T Point<T>::getX() const noexcept
+const T& Point<T>::getX() const noexcept
{
return fX;
}
template<typename T>
-T Point<T>::getY() const noexcept
+const T& Point<T>::getY() const noexcept
{
return fY;
}
template<typename T>
-void Point<T>::setX(T x) noexcept
+void Point<T>::setX(const T& x) noexcept
{
fX = x;
}
template<typename T>
-void Point<T>::setY(T y) noexcept
+void Point<T>::setY(const T& y) noexcept
{
fY = y;
}
template<typename T>
-void Point<T>::move(T x, T y) noexcept
+void Point<T>::setPos(const T& x, const T& y) noexcept
+{
+ fX = x;
+ fY = y;
+}
+
+template<typename T>
+void Point<T>::setPos(const Point<T>& pos) noexcept
+{
+ fX = pos.fX;
+ fY = pos.fY;
+}
+
+template<typename T>
+void Point<T>::moveBy(const T& x, const T& y) noexcept
{
fX += x;
fY += y;
}
template<typename T>
-void Point<T>::move(const Point& pos) noexcept
+void Point<T>::moveBy(const Point<T>& pos) noexcept
{
fX += pos.fX;
fY += pos.fY;
@@ -127,7 +141,7 @@ Size<T>::Size() noexcept
}
template<typename T>
-Size<T>::Size(T width, T height) noexcept
+Size<T>::Size(const T& width, const T& height) noexcept
: fWidth(width),
fHeight(height)
{
@@ -141,30 +155,44 @@ Size<T>::Size(const Size<T>& size) noexcept
}
template<typename T>
-T Size<T>::getWidth() const noexcept
+const T& Size<T>::getWidth() const noexcept
{
return fWidth;
}
template<typename T>
-T Size<T>::getHeight() const noexcept
+const T& Size<T>::getHeight() const noexcept
{
return fHeight;
}
template<typename T>
-void Size<T>::setWidth(T width) noexcept
+void Size<T>::setWidth(const T& width) noexcept
{
fWidth = width;
}
template<typename T>
-void Size<T>::setHeight(T height) noexcept
+void Size<T>::setHeight(const T& height) noexcept
{
fHeight = height;
}
template<typename T>
+void Size<T>::growBy(const T& multiplier) noexcept
+{
+ fWidth *= multiplier;
+ fHeight *= multiplier;
+}
+
+template<typename T>
+void Size<T>::shrinkBy(const T& divider) noexcept
+{
+ fWidth /= divider;
+ fHeight /= divider;
+}
+
+template<typename T>
Size<T>& Size<T>::operator=(const Size<T>& size) noexcept
{
fWidth = size.fWidth;
@@ -189,7 +217,7 @@ Size<T>& Size<T>::operator-=(const Size<T>& size) noexcept
}
template<typename T>
-Size<T>& Size<T>::operator*=(T m) noexcept
+Size<T>& Size<T>::operator*=(const T& m) noexcept
{
fWidth *= m;
fHeight *= m;
@@ -197,7 +225,7 @@ Size<T>& Size<T>::operator*=(T m) noexcept
}
template<typename T>
-Size<T>& Size<T>::operator/=(T d) noexcept
+Size<T>& Size<T>::operator/=(const T& d) noexcept
{
fWidth /= d;
fHeight /= d;
@@ -227,21 +255,21 @@ Rectangle<T>::Rectangle() noexcept
}
template<typename T>
-Rectangle<T>::Rectangle(T x, T y, T width, T height) noexcept
+Rectangle<T>::Rectangle(const T& x, const T& y, const T& width, const T& height) noexcept
: fPos(x, y),
fSize(width, height)
{
}
template<typename T>
-Rectangle<T>::Rectangle(T x, T y, const Size<T>& size) noexcept
+Rectangle<T>::Rectangle(const T& x, const T& y, const Size<T>& size) noexcept
: fPos(x, y),
fSize(size)
{
}
template<typename T>
-Rectangle<T>::Rectangle(const Point<T>& pos, T width, T height) noexcept
+Rectangle<T>::Rectangle(const Point<T>& pos, const T& width, const T& height) noexcept
: fPos(pos),
fSize(width, height)
{
@@ -262,25 +290,25 @@ Rectangle<T>::Rectangle(const Rectangle<T>& rect) noexcept
}
template<typename T>
-T Rectangle<T>::getX() const noexcept
+const T& Rectangle<T>::getX() const noexcept
{
return fPos.fX;
}
template<typename T>
-T Rectangle<T>::getY() const noexcept
+const T& Rectangle<T>::getY() const noexcept
{
return fPos.fY;
}
template<typename T>
-T Rectangle<T>::getWidth() const noexcept
+const T& Rectangle<T>::getWidth() const noexcept
{
return fSize.fWidth;
}
template<typename T>
-T Rectangle<T>::getHeight() const noexcept
+const T& Rectangle<T>::getHeight() const noexcept
{
return fSize.fHeight;
}
@@ -298,7 +326,7 @@ const Size<T>& Rectangle<T>::getSize() const noexcept
}
template<typename T>
-bool Rectangle<T>::contains(T x, T y) const noexcept
+bool Rectangle<T>::contains(const T& x, const T& y) const noexcept
{
return (x >= fPos.fX && y >= fPos.fY && x <= fPos.fX+fSize.fWidth && y <= fPos.fY+fSize.fHeight);
}
@@ -310,31 +338,31 @@ bool Rectangle<T>::contains(const Point<T>& pos) const noexcept
}
template<typename T>
-bool Rectangle<T>::containsX(T x) const noexcept
+bool Rectangle<T>::containsX(const T& x) const noexcept
{
return (x >= fPos.fX && x <= fPos.fX + fSize.fWidth);
}
template<typename T>
-bool Rectangle<T>::containsY(T y) const noexcept
+bool Rectangle<T>::containsY(const T& y) const noexcept
{
return (y >= fPos.fY && y <= fPos.fY + fSize.fHeight);
}
template<typename T>
-void Rectangle<T>::setX(T x) noexcept
+void Rectangle<T>::setX(const T& x) noexcept
{
fPos.fX = x;
}
template<typename T>
-void Rectangle<T>::setY(T y) noexcept
+void Rectangle<T>::setY(const T& y) noexcept
{
fPos.fY = y;
}
template<typename T>
-void Rectangle<T>::setPos(T x, T y) noexcept
+void Rectangle<T>::setPos(const T& x, const T& y) noexcept
{
fPos.fX = x;
fPos.fY = y;
@@ -347,7 +375,7 @@ void Rectangle<T>::setPos(const Point<T>& pos) noexcept
}
template<typename T>
-void Rectangle<T>::move(T x, T y) noexcept
+void Rectangle<T>::move(const T& x, const T& y) noexcept
{
fPos.fX += x;
fPos.fY += y;
@@ -360,19 +388,19 @@ void Rectangle<T>::move(const Point<T>& pos) noexcept
}
template<typename T>
-void Rectangle<T>::setWidth(T width) noexcept
+void Rectangle<T>::setWidth(const T& width) noexcept
{
fSize.fWidth = width;
}
template<typename T>
-void Rectangle<T>::setHeight(T height) noexcept
+void Rectangle<T>::setHeight(const T& height) noexcept
{
fSize.fHeight = height;
}
template<typename T>
-void Rectangle<T>::setSize(T width, T height) noexcept
+void Rectangle<T>::setSize(const T& width, const T& height) noexcept
{
fSize.fWidth = width;
fSize.fHeight = height;