Skip to content

Commit 17ae938

Browse files
committed
asyncio (web)sockets, 3D canvas auto resize
1 parent ebccd7e commit 17ae938

File tree

3 files changed

+32
-29
lines changed

3 files changed

+32
-29
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
build:
77
runs-on: ubuntu-22.04
88
env:
9-
SDK_VERSION: 3.1.31.0
9+
SDK_VERSION: 3.1.31.1
1010
SYS_PYTHON: /usr/bin/python3
1111
PACKAGES: emsdk pygame
1212
STATIC: false

static/3d.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ config = {
313313

314314

315315
<canvas class="emscripten" id="canvas"
316-
width="1024px"
317-
height="600px"
316+
width="1px"
317+
height="1px"
318318
oncontextmenu="event.preventDefault()" tabindex=1>
319319
</canvas>
320320

static/pythons.js

+29-26
Original file line numberDiff line numberDiff line change
@@ -695,16 +695,18 @@ console.warn("TODO: user defined canvas")
695695
divider = divider || 1
696696
if ( (canvas.width==1) && (canvas.height==1) ){
697697
console.log("canvas context not set yet")
698-
setTimeout(window_canvas_adjust, 100, gui_divider);
698+
setTimeout(window_canvas_adjust_3d, 100, divider);
699699
return;
700-
} else {
701-
if (!vm.config.fb_ar) {
702-
vm.config.fb_width = canvas.width
703-
vm.config.fb_height = canvas.height
704-
vm.config.fb_ar = canvas.width / canvas.height
705-
}
706700
}
707701

702+
if (!vm.config.fb_ar) {
703+
vm.config.fb_width = canvas.width
704+
vm.config.fb_height = canvas.height
705+
vm.config.fb_ar = canvas.width / canvas.height
706+
console.warn("@@@@@@ GLES Canvas size",vm.config.fb_width,'x',vm.config.fb_height,"@@@@@@")
707+
}
708+
709+
708710
var want_w
709711
var want_h
710712

@@ -760,41 +762,42 @@ console.warn("TODO: user defined canvas")
760762
gl.viewport(0, 0, gl.canvas.width, gl.canvas.height)
761763
}
762764

763-
function window_resize(gui_divider) {
765+
function window_resize_3d(gui_divider) {
766+
console.warn("@@@@@@@@@@ 3D resize mode request @@@@@@@@")
767+
setTimeout(window_canvas_adjust_3d, 200, gui_divider);
768+
setTimeout(window.focus, 300);
769+
}
770+
771+
function window_resize_2d(gui_divider) {
772+
// don't interfere if program want to handle canvas placing/resizing
773+
if (vm.config.user_canvas_managed)
774+
return vm.config.user_canvas_managed
775+
764776
if (!window.canvas) {
765-
console.error("776: No canvas defined")
777+
console.warning("777: No canvas defined")
766778
return
767779
}
768780

769-
if (vm.config.user_canvas_managed==3) {
770-
setTimeout(window_canvas_adjust_3d, 100, gui_divider);
771-
setTimeout(window.focus, 300);
772-
return 3
773-
}
781+
setTimeout(window_canvas_adjust, 200, gui_divider);
782+
setTimeout(window.focus, 300);
783+
}
774784

775-
// canvas is handled by user program
776-
if (vm.config.user_canvas_managed) {
777-
return vm.config.user_canvas_managed
778-
}
779785

780-
setTimeout(window_canvas_adjust, 100, gui_divider);
781-
setTimeout(window.focus, 200);
782-
}
783786

784787
function window_resize_event() {
785788
// special management for 3D ctx
786789
if (vm.config.user_canvas_managed==3) {
787790
window_resize(vm.config.gui_divider)
788791
return
789792
}
790-
791-
// don't interfere if program want to handle canvas placing/resizing
792-
if (!vm.config.user_canvas_managed)
793-
window_resize(vm.config.gui_divider)
793+
window_resize(vm.config.gui_divider)
794794
}
795795

796796
window.addEventListener('resize', window_resize_event);
797-
window.window_resize = window_resize
797+
if (vm.config.user_canvas_managed==3)
798+
window.window_resize = window_resize_3d
799+
else
800+
window.window_resize = window_resize_2d
798801

799802
return canvas
800803
}

0 commit comments

Comments
 (0)