MyGUI_ICroppedRectangle.h
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#ifndef MYGUI_I_CROPPED_RECTANGLE_H_
#define MYGUI_I_CROPPED_RECTANGLE_H_
#include "MyGUI_Prerequest.h"
#include "MyGUI_Types.h"
namespace MyGUI
{
class MYGUI_EXPORT ICroppedRectangle
{
public:
virtual ~ICroppedRectangle() = default;
ICroppedRectangle* getCroppedParent()
{
return mCroppedParent;
}
virtual void setPosition(const IntPoint& _value)
{
mCoord.left = _value.left;
mCoord.top = _value.top;
}
virtual void setSize(const IntSize& _value)
{
mCoord.width = _value.width;
mCoord.height = _value.height;
}
virtual void setCoord(const IntCoord& _value)
{
mCoord = _value;
}
IntPoint getPosition() const
{
return mCoord.point();
}
IntSize getSize() const
{
return mCoord.size();
}
const IntCoord& getCoord() const
{
return mCoord;
}
const IntPoint& getAbsolutePosition() const
{
return mAbsolutePosition;
}
IntRect getAbsoluteRect() const
{
return {
mAbsolutePosition.left,
mAbsolutePosition.top,
mAbsolutePosition.left + mCoord.width,
mAbsolutePosition.top + mCoord.height};
}
IntCoord getAbsoluteCoord() const
{
return {mAbsolutePosition.left, mAbsolutePosition.top, mCoord.width, mCoord.height};
}
int getAbsoluteLeft() const
{
return mAbsolutePosition.left;
}
int getAbsoluteTop() const
{
return mAbsolutePosition.top;
}
int getLeft() const
{
return mCoord.left;
}
int getRight() const
{
return mCoord.right();
}
int getTop() const
{
return mCoord.top;
}
int getBottom() const
{
return mCoord.bottom();
}
int getWidth() const
{
return mCoord.width;
}
int getHeight() const
{
return mCoord.height;
}
/*internal:*/
bool _isMargin() const
{
return mIsMargin;
}
// Get cropped by parent rectangle coordinates
int _getViewLeft() const
{
return mCoord.left + mMargin.left;
}
int _getViewRight() const
{
return mCoord.right() - mMargin.right;
}
int _getViewTop() const
{
return mCoord.top + mMargin.top;
}
int _getViewBottom() const
{
return mCoord.bottom() - mMargin.bottom;
}
int _getViewWidth() const
{
return mCoord.width - mMargin.left - mMargin.right;
}
int _getViewHeight() const
{
return mCoord.height - mMargin.top - mMargin.bottom;
}
void _setCroppedParent(ICroppedRectangle* _parent)
{
mCroppedParent = _parent;
}
const IntRect& _getMargin() const
{
return mMargin;
}
int _getMarginLeft() const
{
return mMargin.left;
}
int _getMarginRight() const
{
return mMargin.right;
}
int _getMarginTop() const
{
return mMargin.top;
}
int _getMarginBottom() const
{
return mMargin.bottom;
}
protected:
bool _checkMargin()
{
bool margin = false;
//вылезли ли налево
if (getLeft() < mCroppedParent->mMargin.left)
{
mMargin.left = mCroppedParent->mMargin.left - getLeft();
margin = true;
}
else
{
mMargin.left = 0;
}
//вылезли ли направо
if (getRight() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right)
{
mMargin.right = getRight() - (mCroppedParent->getWidth() - mCroppedParent->mMargin.right);
margin = true;
}
else
{
mMargin.right = 0;
}
//вылезли ли вверх
if (getTop() < mCroppedParent->mMargin.top)
{
mMargin.top = mCroppedParent->mMargin.top - getTop();
margin = true;
}
else
{
mMargin.top = 0;
}
//вылезли ли вниз
if (getBottom() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom)
{
mMargin.bottom = getBottom() - (mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom);
margin = true;
}
else
{
mMargin.bottom = 0;
}
return margin;
}
bool _checkOutside() const // проверка на полный выход за границу
{
return (
(getRight() < mCroppedParent->mMargin.left) || // совсем уехали налево
(getLeft() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right) || // совсем уехали направо
(getBottom() < mCroppedParent->mMargin.top) || // совсем уехали вверх
(getTop() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom)); // совсем уехали вниз
}
protected:
IntRect mMargin; // перекрытие
IntCoord mCoord; // координаты
IntPoint mAbsolutePosition; // обсолютные координаты
bool mIsMargin{false};
ICroppedRectangle* mCroppedParent{nullptr};
};
} // namespace MyGUI
#endif // MYGUI_I_CROPPED_RECTANGLE_H_
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MyGUI_Types.h
MyGUI::ICroppedRectangle
Definition MyGUI_ICroppedRectangle.h:17
MyGUI::ICroppedRectangle::~ICroppedRectangle
virtual ~ICroppedRectangle()=default
MyGUI::ICroppedRectangle::_getMarginBottom
int _getMarginBottom() const
Definition MyGUI_ICroppedRectangle.h:178
MyGUI::ICroppedRectangle::mIsMargin
bool mIsMargin
Definition MyGUI_ICroppedRectangle.h:248
MyGUI::ICroppedRectangle::setPosition
virtual void setPosition(const IntPoint &_value)
Definition MyGUI_ICroppedRectangle.h:28
MyGUI::ICroppedRectangle::mCoord
IntCoord mCoord
Definition MyGUI_ICroppedRectangle.h:245
MyGUI::ICroppedRectangle::mMargin
IntRect mMargin
Definition MyGUI_ICroppedRectangle.h:244
MyGUI::ICroppedRectangle::getTop
int getTop() const
Definition MyGUI_ICroppedRectangle.h:103
MyGUI::ICroppedRectangle::setCoord
virtual void setCoord(const IntCoord &_value)
Definition MyGUI_ICroppedRectangle.h:40
MyGUI::ICroppedRectangle::getAbsoluteLeft
int getAbsoluteLeft() const
Definition MyGUI_ICroppedRectangle.h:82
MyGUI::ICroppedRectangle::getAbsolutePosition
const IntPoint & getAbsolutePosition() const
Definition MyGUI_ICroppedRectangle.h:62
MyGUI::ICroppedRectangle::_checkMargin
bool _checkMargin()
Definition MyGUI_ICroppedRectangle.h:184
MyGUI::ICroppedRectangle::_isMargin
bool _isMargin() const
Definition MyGUI_ICroppedRectangle.h:126
MyGUI::ICroppedRectangle::getPosition
IntPoint getPosition() const
Definition MyGUI_ICroppedRectangle.h:46
MyGUI::ICroppedRectangle::getWidth
int getWidth() const
Definition MyGUI_ICroppedRectangle.h:113
MyGUI::ICroppedRectangle::_checkOutside
bool _checkOutside() const
Definition MyGUI_ICroppedRectangle.h:234
MyGUI::ICroppedRectangle::getHeight
int getHeight() const
Definition MyGUI_ICroppedRectangle.h:118
MyGUI::ICroppedRectangle::_getMarginRight
int _getMarginRight() const
Definition MyGUI_ICroppedRectangle.h:170
MyGUI::ICroppedRectangle::mCroppedParent
ICroppedRectangle * mCroppedParent
Definition MyGUI_ICroppedRectangle.h:249
MyGUI::ICroppedRectangle::_getMarginLeft
int _getMarginLeft() const
Definition MyGUI_ICroppedRectangle.h:166
MyGUI::ICroppedRectangle::_getMargin
const IntRect & _getMargin() const
Definition MyGUI_ICroppedRectangle.h:162
MyGUI::ICroppedRectangle::mAbsolutePosition
IntPoint mAbsolutePosition
Definition MyGUI_ICroppedRectangle.h:246
MyGUI::ICroppedRectangle::_getMarginTop
int _getMarginTop() const
Definition MyGUI_ICroppedRectangle.h:174
MyGUI::ICroppedRectangle::getCoord
const IntCoord & getCoord() const
Definition MyGUI_ICroppedRectangle.h:56
MyGUI::ICroppedRectangle::getCroppedParent
ICroppedRectangle * getCroppedParent()
Definition MyGUI_ICroppedRectangle.h:22
MyGUI::ICroppedRectangle::getAbsoluteRect
IntRect getAbsoluteRect() const
Definition MyGUI_ICroppedRectangle.h:67
MyGUI::ICroppedRectangle::getRight
int getRight() const
Definition MyGUI_ICroppedRectangle.h:98
MyGUI::ICroppedRectangle::getAbsoluteCoord
IntCoord getAbsoluteCoord() const
Definition MyGUI_ICroppedRectangle.h:76
MyGUI::ICroppedRectangle::getLeft
int getLeft() const
Definition MyGUI_ICroppedRectangle.h:93
MyGUI::ICroppedRectangle::_setCroppedParent
void _setCroppedParent(ICroppedRectangle *_parent)
Definition MyGUI_ICroppedRectangle.h:157
MyGUI::ICroppedRectangle::getSize
IntSize getSize() const
Definition MyGUI_ICroppedRectangle.h:51
MyGUI::ICroppedRectangle::setSize
virtual void setSize(const IntSize &_value)
Definition MyGUI_ICroppedRectangle.h:34
MyGUI::ICroppedRectangle::getAbsoluteTop
int getAbsoluteTop() const
Definition MyGUI_ICroppedRectangle.h:87
MyGUI::ICroppedRectangle::getBottom
int getBottom() const
Definition MyGUI_ICroppedRectangle.h:108
MyGUI::ICroppedRectangle::_getViewRight
int _getViewRight() const
Definition MyGUI_ICroppedRectangle.h:136
MyGUI::ICroppedRectangle::_getViewWidth
int _getViewWidth() const
Definition MyGUI_ICroppedRectangle.h:148
MyGUI::ICroppedRectangle::_getViewLeft
int _getViewLeft() const
Definition MyGUI_ICroppedRectangle.h:132
MyGUI::ICroppedRectangle::_getViewTop
int _getViewTop() const
Definition MyGUI_ICroppedRectangle.h:140
MyGUI::ICroppedRectangle::_getViewBottom
int _getViewBottom() const
Definition MyGUI_ICroppedRectangle.h:144
MyGUI::ICroppedRectangle::_getViewHeight
int _getViewHeight() const
Definition MyGUI_ICroppedRectangle.h:152
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::IntRect
types::TRect< int > IntRect
Definition MyGUI_Types.h:33
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::types::TPoint::left
T left
Definition MyGUI_TPoint.h:19
MyGUI::types::TPoint::top
T top
Definition MyGUI_TPoint.h:20
MyGUI::types::TSize::width
T width
Definition MyGUI_TSize.h:19
MyGUI::types::TSize::height
T height
Definition MyGUI_TSize.h:20