fix: editor and cocos-play issues (#12908)

* fix: editor and cocos-play issues

* * Change 'windowId' to optional.
This commit is contained in:
林玮
2022-09-27 17:45:21 +08:00
committed by GitHub
parent be9975e874
commit e7e8036dcd
8 changed files with 23 additions and 16 deletions
+5 -5
View File
@@ -592,14 +592,14 @@ export class View extends Eventify(System) {
point.y = (point.y - viewport.y) / this._scaleY;
}
private _updateAdaptResult (event: jsb.WindowEvent) {
legacyCC.director.root.resize(event.windowId, event.width, event.height);
private _updateAdaptResult (width: number, height: number, windowId?: number) {
legacyCC.director.root.resize(width, height, windowId === undefined ? 1 : windowId);
// Frame size changed, do resize works
const width = this._designResolutionSize.width;
const height = this._designResolutionSize.height;
const w = this._designResolutionSize.width;
const h = this._designResolutionSize.height;
if (width > 0) {
this.setDesignResolutionSize(width, height, this._resolutionPolicy);
this.setDesignResolutionSize(w, h, this._resolutionPolicy);
}
this.emit('canvas-resize');
+2 -1
View File
@@ -341,8 +341,9 @@ export class Root {
* @zh 重置在屏窗口的大小。
* @param width The new width of the window.
* @param height The new height of the window.
* @param windowId The system window ID, optional for now.
*/
public resize (width: number, height: number) {
public resize (width: number, height: number, windowId?: number) {
for (const window of this._windows) {
if (window.swapchain) {
window.resize(width, height);
+5
View File
@@ -50,8 +50,13 @@ int BaseGame::init() {
std::call_once(_windowCreateFlag, [&]() {
ISystemWindowInfo info;
info.title = _windowInfo.title;
#if CC_PLATFORM == CC_PLATFORM_WINDOWS
info.x = _windowInfo.x == -1 ? 50 : _windowInfo.x; // 50 meams move window a little for now
info.y = _windowInfo.y == -1 ? 50 : _windowInfo.y; // same above
#else
info.x = _windowInfo.x == -1 ? 0 : _windowInfo.x;
info.y = _windowInfo.y == -1 ? 0 : _windowInfo.y;
#endif
info.width = _windowInfo.width;
info.height = _windowInfo.height;
info.flags = _windowInfo.flags;
+1 -1
View File
@@ -167,7 +167,7 @@ void Root::destroy() {
// this.dataPoolManager.clear();
}
void Root::resize(uint32_t windowId, uint32_t width, uint32_t height) {
void Root::resize(uint32_t width, uint32_t height, uint32_t windowId) {
for (const auto &window : _renderWindows) {
auto *swapchain = window->getSwapchain();
if (swapchain && (swapchain->getWindowId() == windowId)) {
+4 -3
View File
@@ -76,10 +76,11 @@ public:
/**
* @zh
* 重置大小
* @param width 屏幕宽度
* @param height 屏幕高度
* @param width 窗口宽度
* @param height 窗口高度
* @param windowId 窗口 ID
*/
void resize(uint32_t windowId, uint32_t width, uint32_t height);
void resize(uint32_t width, uint32_t height, uint32_t windowId);
bool setRenderPipeline(pipeline::RenderPipeline *rppl = nullptr);
void onGlobalPipelineStateChanged();
@@ -127,7 +127,7 @@ class ScreenAdapter extends EventTarget {
// TODO: onResize or onOrientationChange is not supported well
if (WECHAT || COCOSPLAY) {
minigame.onWindowResize?.(() => {
this.emit('window-resize');
this.emit('window-resize', this.windowSize.width, this.windowSize.height);
});
}
}
+1 -1
View File
@@ -118,7 +118,7 @@ class ScreenAdapter extends EventTarget {
if (event.width === 0 || event.height === 0) return;
// TODO: remove this function calling
window.resize(event.width / this.devicePixelRatio, event.height / this.devicePixelRatio);
this.emit('window-resize', event);
this.emit('window-resize', event.width, event.height, event.windowId);
};
jsb.onOrientationChanged = (event) => {
this.emit('orientation-change');
+4 -4
View File
@@ -350,7 +350,7 @@ class ScreenAdapter extends EventTarget {
const dpr = window.devicePixelRatio;
// NOTE: some browsers especially on iPhone doesn't support MediaQueryList
window.matchMedia(`(resolution: ${dpr}dppx)`)?.addEventListener?.('change', () => {
this.emit('window-resize');
this.emit('window-resize', this.windowSize.width, this.windowSize.height);
updateDPRChangeListener();
}, { once: true });
};
@@ -366,13 +366,13 @@ class ScreenAdapter extends EventTarget {
}
this._updateFrameState();
this._resizeFrame();
this.emit('orientation-change');
this.emit('orientation-change', this.windowSize.width, this.windowSize.height);
this._orientationChangeTimeoutId = -1;
}, EVENT_TIMEOUT);
});
document.addEventListener(this._fn.fullscreenchange, () => {
this._onFullscreenChange?.();
this.emit('fullscreen-change');
this.emit('fullscreen-change', this.windowSize.width, this.windowSize.height);
});
}
private _convertToSizeInCssPixels (size: Size) {
@@ -515,7 +515,7 @@ class ScreenAdapter extends EventTarget {
|| this._cachedFrameStyle.height !== this._gameFrame.style.height
|| this._cachedContainerStyle.width !== this._gameContainer.style.width
|| this._cachedContainerStyle.height !== this._gameContainer.style.height)) {
this.emit('window-resize');
this.emit('window-resize', this.windowSize.width, this.windowSize.height);
// Update Cache
this._cachedFrameStyle.width = this._gameFrame.style.width;