axmol/samples/Cpp/TestCpp/Classes/VisibleRect.cpp

74 lines
1.9 KiB
C++
Raw Normal View History

#include "VisibleRect.h"
Rect VisibleRect::s_visibleRect;
void VisibleRect::lazyInit()
{
if (s_visibleRect.size.width == 0.0f && s_visibleRect.size.height == 0.0f)
{
auto glView = EGLView::getInstance();
s_visibleRect.origin = glView->getVisibleOrigin();
s_visibleRect.size = glView->getVisibleSize();
}
}
Rect VisibleRect::getVisibleRect()
{
lazyInit();
return Rect(s_visibleRect.origin.x, s_visibleRect.origin.y, s_visibleRect.size.width, s_visibleRect.size.height);
}
Point VisibleRect::left()
{
lazyInit();
2013-07-12 14:11:55 +08:00
return Point(s_visibleRect.origin.x, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Point VisibleRect::right()
{
lazyInit();
2013-07-12 14:11:55 +08:00
return Point(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Point VisibleRect::top()
{
lazyInit();
2013-07-12 14:11:55 +08:00
return Point(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Point VisibleRect::bottom()
{
lazyInit();
2013-07-12 14:11:55 +08:00
return Point(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y);
}
Point VisibleRect::center()
{
lazyInit();
2013-07-12 14:11:55 +08:00
return Point(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y+s_visibleRect.size.height/2);
}
Point VisibleRect::leftTop()
{
lazyInit();
2013-07-12 14:11:55 +08:00
return Point(s_visibleRect.origin.x, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Point VisibleRect::rightTop()
{
lazyInit();
2013-07-12 14:11:55 +08:00
return Point(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y+s_visibleRect.size.height);
}
Point VisibleRect::leftBottom()
{
lazyInit();
return s_visibleRect.origin;
}
Point VisibleRect::rightBottom()
{
lazyInit();
2013-07-12 14:11:55 +08:00
return Point(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y);
}