2014-02-09 04:35:11 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-02-09 04:35:11 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
https://axys1.github.io/
|
2014-02-09 04:35:11 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-09-20 22:23:13 +08:00
|
|
|
#include "VisibleRect.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2014-03-26 01:37:35 +08:00
|
|
|
|
2013-09-20 22:23:13 +08:00
|
|
|
Rect VisibleRect::s_visibleRect;
|
|
|
|
|
|
|
|
void VisibleRect::lazyInit()
|
|
|
|
{
|
2014-02-09 04:46:44 +08:00
|
|
|
// no lazy init
|
|
|
|
// Useful if we change the resolution in runtime
|
|
|
|
s_visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect();
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Rect VisibleRect::getVisibleRect()
|
|
|
|
{
|
|
|
|
lazyInit();
|
2014-02-09 04:35:11 +08:00
|
|
|
return s_visibleRect;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 VisibleRect::left()
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
lazyInit();
|
2021-12-28 16:06:23 +08:00
|
|
|
return Vec2(s_visibleRect.origin.x, s_visibleRect.origin.y + s_visibleRect.size.height / 2);
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 VisibleRect::right()
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
lazyInit();
|
2021-12-28 16:06:23 +08:00
|
|
|
return Vec2(s_visibleRect.origin.x + s_visibleRect.size.width,
|
|
|
|
s_visibleRect.origin.y + s_visibleRect.size.height / 2);
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 VisibleRect::top()
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
lazyInit();
|
2021-12-28 16:06:23 +08:00
|
|
|
return Vec2(s_visibleRect.origin.x + s_visibleRect.size.width / 2,
|
|
|
|
s_visibleRect.origin.y + s_visibleRect.size.height);
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 VisibleRect::bottom()
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
lazyInit();
|
2021-12-28 16:06:23 +08:00
|
|
|
return Vec2(s_visibleRect.origin.x + s_visibleRect.size.width / 2, s_visibleRect.origin.y);
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 VisibleRect::center()
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
lazyInit();
|
2021-12-28 16:06:23 +08:00
|
|
|
return Vec2(s_visibleRect.origin.x + s_visibleRect.size.width / 2,
|
|
|
|
s_visibleRect.origin.y + s_visibleRect.size.height / 2);
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 VisibleRect::leftTop()
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
lazyInit();
|
2021-12-28 16:06:23 +08:00
|
|
|
return Vec2(s_visibleRect.origin.x, s_visibleRect.origin.y + s_visibleRect.size.height);
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 VisibleRect::rightTop()
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
lazyInit();
|
2021-12-28 16:06:23 +08:00
|
|
|
return Vec2(s_visibleRect.origin.x + s_visibleRect.size.width, s_visibleRect.origin.y + s_visibleRect.size.height);
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 VisibleRect::leftBottom()
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
lazyInit();
|
|
|
|
return s_visibleRect.origin;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 VisibleRect::rightBottom()
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
lazyInit();
|
2021-12-28 16:06:23 +08:00
|
|
|
return Vec2(s_visibleRect.origin.x + s_visibleRect.size.width, s_visibleRect.origin.y);
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|