mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
4bc2739786
* Vmath (#4895) * vmath refactor * value-type API change * vmath change update * conflict fix * value types change * translate modify (#4917) * value types bug fixed (#4940) * playground update (#4946) * bug fixed * bug fixed * bug fixed * bug fix * util modify * create remove & ccenum rename * export by cc.math * Rename value-types to math * util funtion deprecated warn * value-types change * color test fix * color API change
133 lines
3.5 KiB
TypeScript
133 lines
3.5 KiB
TypeScript
/*
|
|
Copyright (c) 2011-2012 cocos2d-x.org
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
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.
|
|
*/
|
|
|
|
import { Rect } from '../math';
|
|
|
|
/**
|
|
* cc.visibleRect is a singleton object which defines the actual visible rect of the current view,
|
|
* it should represent the same rect as cc.view.getViewportRect()
|
|
*/
|
|
const visibleRect = {
|
|
/**
|
|
* Top left coordinate of the screen related to the game scene.
|
|
*/
|
|
topLeft: cc.v2(0, 0),
|
|
|
|
/**
|
|
* Top right coordinate of the screen related to the game scene.
|
|
*/
|
|
topRight: cc.v2(0, 0),
|
|
|
|
/**
|
|
* Top center coordinate of the screen related to the game scene.
|
|
*/
|
|
top: cc.v2(0, 0),
|
|
|
|
/**
|
|
* Bottom left coordinate of the screen related to the game scene.
|
|
*/
|
|
bottomLeft: cc.v2(0, 0),
|
|
|
|
/**
|
|
* Bottom right coordinate of the screen related to the game scene.
|
|
*/
|
|
bottomRight: cc.v2(0, 0),
|
|
|
|
/**
|
|
* Bottom center coordinate of the screen related to the game scene.
|
|
*/
|
|
bottom: cc.v2(0, 0),
|
|
|
|
/**
|
|
* Center coordinate of the screen related to the game scene.
|
|
*/
|
|
center: cc.v2(0, 0),
|
|
|
|
/**
|
|
* Left center coordinate of the screen related to the game scene.
|
|
*/
|
|
left: cc.v2(0, 0),
|
|
|
|
/**
|
|
* Right center coordinate of the screen related to the game scene.
|
|
*/
|
|
right: cc.v2(0, 0),
|
|
|
|
/**
|
|
* Width of the screen.
|
|
*/
|
|
width: 0,
|
|
|
|
/**
|
|
* Height of the screen.
|
|
*/
|
|
height: 0,
|
|
|
|
/**
|
|
* initialize
|
|
*/
|
|
init (visibleRect_: Rect) {
|
|
|
|
const w = this.width = visibleRect_.width;
|
|
const h = this.height = visibleRect_.height;
|
|
const l = visibleRect_.x;
|
|
const b = visibleRect_.y;
|
|
const t = b + h;
|
|
const r = l + w;
|
|
|
|
// top
|
|
this.topLeft.x = l;
|
|
this.topLeft.y = t;
|
|
this.topRight.x = r;
|
|
this.topRight.y = t;
|
|
this.top.x = l + w / 2;
|
|
this.top.y = t;
|
|
|
|
// bottom
|
|
this.bottomLeft.x = l;
|
|
this.bottomLeft.y = b;
|
|
this.bottomRight.x = r;
|
|
this.bottomRight.y = b;
|
|
this.bottom.x = l + w / 2;
|
|
this.bottom.y = b;
|
|
|
|
// center
|
|
this.center.x = l + w / 2;
|
|
this.center.y = b + h / 2;
|
|
|
|
// left
|
|
this.left.x = l;
|
|
this.left.y = b + h / 2;
|
|
|
|
// right
|
|
this.right.x = r;
|
|
this.right.y = b + h / 2;
|
|
},
|
|
};
|
|
|
|
cc.visibleRect = visibleRect;
|
|
export default visibleRect;
|