| @@ -70,6 +70,8 @@ public: | |||
| 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; | |||
| void growBy(const T& multiplier) noexcept; | |||
| void shrinkBy(const T& divider) noexcept; | |||
| @@ -110,27 +112,34 @@ public: | |||
| const Point<T>& getPos() const noexcept; | |||
| const Size<T>& getSize() const noexcept; | |||
| bool contains(const T& x, const T& y) const noexcept; | |||
| bool contains(const Point<T>& pos) const noexcept; | |||
| bool containsX(const T& x) const noexcept; | |||
| bool containsY(const T& y) const 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(const T& x, const 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; | |||
| 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; | |||
| void growBy(const T& multiplier) noexcept; | |||
| void shrinkBy(const T& divider) noexcept; | |||
| bool contains(const T& x, const T& y) const noexcept; | |||
| bool contains(const Point<T>& pos) const noexcept; | |||
| bool containsX(const T& x) const noexcept; | |||
| bool containsY(const T& y) const noexcept; | |||
| void draw(); | |||
| Rectangle<T>& operator=(const Rectangle<T>& rect) noexcept; | |||
| Rectangle<T>& operator*=(const T& m) noexcept; | |||
| Rectangle<T>& operator/=(const T& d) noexcept; | |||
| bool operator==(const Rectangle<T>& size) const noexcept; | |||
| bool operator!=(const Rectangle<T>& size) const noexcept; | |||
| private: | |||
| Point<T> fPos; | |||
| @@ -53,8 +53,8 @@ public: | |||
| void setPos(int x, int y); | |||
| void setPos(const Point<int>& pos); | |||
| void move(int x, int y); | |||
| void move(const Point<int>& pos); | |||
| void moveBy(int x, int y); | |||
| void moveBy(const Point<int>& pos); | |||
| int getWidth() const noexcept; | |||
| int getHeight() const noexcept; | |||
| @@ -63,13 +63,9 @@ public: | |||
| // virtual needed by cairo | |||
| virtual void setWidth(int width); | |||
| virtual void setHeight(int height); | |||
| virtual void setSize(int width, int height); | |||
| virtual void setSize(const Size<int>& size); | |||
| void setSize(int width, int height) | |||
| { | |||
| setSize(Size<int>(width, height)); | |||
| } | |||
| const Rectangle<int>& getArea() const noexcept; | |||
| uint32_t getEventTimestamp(); | |||
| @@ -178,6 +178,20 @@ void Size<T>::setHeight(const T& height) noexcept | |||
| fHeight = height; | |||
| } | |||
| template<typename T> | |||
| void Size<T>::setSize(const T& width, const T& height) noexcept | |||
| { | |||
| fWidth = width; | |||
| fHeight = height; | |||
| } | |||
| template<typename T> | |||
| void Size<T>::setSize(const Size<T>& size) noexcept | |||
| { | |||
| fWidth = size.fWidth; | |||
| fHeight = size.fHeight; | |||
| } | |||
| template<typename T> | |||
| void Size<T>::growBy(const T& multiplier) noexcept | |||
| { | |||
| @@ -325,30 +339,6 @@ const Size<T>& Rectangle<T>::getSize() const noexcept | |||
| return fSize; | |||
| } | |||
| template<typename T> | |||
| 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); | |||
| } | |||
| template<typename T> | |||
| bool Rectangle<T>::contains(const Point<T>& pos) const noexcept | |||
| { | |||
| return contains(pos.fX, pos.fY); | |||
| } | |||
| template<typename T> | |||
| 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(const T& y) const noexcept | |||
| { | |||
| return (y >= fPos.fY && y <= fPos.fY + fSize.fHeight); | |||
| } | |||
| template<typename T> | |||
| void Rectangle<T>::setX(const T& x) noexcept | |||
| { | |||
| @@ -375,14 +365,14 @@ void Rectangle<T>::setPos(const Point<T>& pos) noexcept | |||
| } | |||
| template<typename T> | |||
| void Rectangle<T>::move(const T& x, const T& y) noexcept | |||
| void Rectangle<T>::moveBy(const T& x, const T& y) noexcept | |||
| { | |||
| fPos.fX += x; | |||
| fPos.fY += y; | |||
| } | |||
| template<typename T> | |||
| void Rectangle<T>::move(const Point<T>& pos) noexcept | |||
| void Rectangle<T>::moveBy(const Point<T>& pos) noexcept | |||
| { | |||
| fPos += pos; | |||
| } | |||
| @@ -412,6 +402,44 @@ void Rectangle<T>::setSize(const Size<T>& size) noexcept | |||
| fSize = size; | |||
| } | |||
| template<typename T> | |||
| void Rectangle<T>::growBy(const T& multiplier) noexcept | |||
| { | |||
| fSize.fWidth *= multiplier; | |||
| fSize.fHeight *= multiplier; | |||
| } | |||
| template<typename T> | |||
| void Rectangle<T>::shrinkBy(const T& divider) noexcept | |||
| { | |||
| fSize.fWidth /= divider; | |||
| fSize.fHeight /= divider; | |||
| } | |||
| template<typename T> | |||
| 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); | |||
| } | |||
| template<typename T> | |||
| bool Rectangle<T>::contains(const Point<T>& pos) const noexcept | |||
| { | |||
| return contains(pos.fX, pos.fY); | |||
| } | |||
| template<typename T> | |||
| 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(const T& y) const noexcept | |||
| { | |||
| return (y >= fPos.fY && y <= fPos.fY + fSize.fHeight); | |||
| } | |||
| template<typename T> | |||
| void Rectangle<T>::draw() | |||
| { | |||
| @@ -444,6 +472,34 @@ Rectangle<T>& Rectangle<T>::operator=(const Rectangle<T>& rect) noexcept | |||
| return *this; | |||
| } | |||
| template<typename T> | |||
| Rectangle<T>& Rectangle<T>::operator*=(const T& m) noexcept | |||
| { | |||
| fSize.fWidth *= m; | |||
| fSize.fHeight *= m; | |||
| return *this; | |||
| } | |||
| template<typename T> | |||
| Rectangle<T>& Rectangle<T>::operator/=(const T& d) noexcept | |||
| { | |||
| fSize.fWidth /= d; | |||
| fSize.fHeight /= d; | |||
| return *this; | |||
| } | |||
| template<typename T> | |||
| bool Rectangle<T>::operator==(const Rectangle<T>& rect) const noexcept | |||
| { | |||
| return (fPos == rect.fPos && fSize == rect.fSize); | |||
| } | |||
| template<typename T> | |||
| bool Rectangle<T>::operator!=(const Rectangle<T>& rect) const noexcept | |||
| { | |||
| return !operator==(rect); | |||
| } | |||
| // ----------------------------------------------------------------------- | |||
| // Possible template data types | |||
| @@ -108,15 +108,20 @@ void Widget::setPos(const Point<int>& pos) | |||
| fParent.repaint(); | |||
| } | |||
| void Widget::move(int x, int y) | |||
| void Widget::moveBy(int x, int y) | |||
| { | |||
| fArea.move(x, y); | |||
| fArea.moveBy(x, y); | |||
| fParent.repaint(); | |||
| } | |||
| void Widget::move(const Point<int>& pos) | |||
| void Widget::moveBy(const Point<int>& pos) | |||
| { | |||
| fArea.move(pos); | |||
| Point<int> movedPos = fArea.getPos() + pos; | |||
| if (fArea.getPos() == movedPos) | |||
| return; | |||
| fArea.moveBy(pos); | |||
| fParent.repaint(); | |||
| } | |||
| @@ -153,6 +158,11 @@ void Widget::setHeight(int height) | |||
| fParent.repaint(); | |||
| } | |||
| void Widget::setSize(int width, int height) | |||
| { | |||
| setSize(Size<int>(width, height)); | |||
| } | |||
| void Widget::setSize(const Size<int>& size) | |||
| { | |||
| if (fArea.getSize() == size) | |||
| @@ -110,15 +110,17 @@ private: | |||
| void onReshape(int width, int height) override | |||
| { | |||
| // make widget same size as window | |||
| setSize(width, height); | |||
| Widget::onReshape(width, height); | |||
| // full bg | |||
| bgFull = Rectangle<int>(0, 0, width, height); | |||
| // small bg, centered 2/3 size | |||
| bgSmall = Rectangle<int>(width/6, height/6, width*2/3, height*2/3); | |||
| // make widget same size as window | |||
| setSize(width, height); | |||
| // default reshape implementation | |||
| Widget::onReshape(width, height); | |||
| } | |||
| char cur; | |||
| @@ -126,23 +126,6 @@ private: | |||
| repaint(); | |||
| } | |||
| void setNewTopImg(const int imgId) | |||
| { | |||
| if (fImgTop1st == imgId) | |||
| return; | |||
| if (fImgTop2nd == imgId) | |||
| { | |||
| fImgTop2nd = fImgTop1st; | |||
| fImgTop1st = imgId; | |||
| return; | |||
| } | |||
| fImgTop3rd = fImgTop2nd; | |||
| fImgTop2nd = fImgTop1st; | |||
| fImgTop1st = imgId; | |||
| } | |||
| void onDisplay() override | |||
| { | |||
| switch (fImgTop3rd) | |||
| @@ -185,6 +168,23 @@ private: | |||
| }; | |||
| } | |||
| void setNewTopImg(const int imgId) | |||
| { | |||
| if (fImgTop1st == imgId) | |||
| return; | |||
| if (fImgTop2nd == imgId) | |||
| { | |||
| fImgTop2nd = fImgTop1st; | |||
| fImgTop1st = imgId; | |||
| return; | |||
| } | |||
| fImgTop3rd = fImgTop2nd; | |||
| fImgTop2nd = fImgTop1st; | |||
| fImgTop1st = imgId; | |||
| } | |||
| int fImgTop1st, fImgTop2nd, fImgTop3rd; | |||
| int fImg1x, fImg2x, fImg3y; | |||
| bool fImg1rev, fImg2rev, fImg3rev; | |||