Skip to content

Commit bd3708a

Browse files
committed
EMCC: Emscripten version wip
- added resize handling
1 parent 5aeac19 commit bd3708a

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

src/platform/emcc/canvas.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ bool Canvas::create(int width, int height) {
221221
canvas.style.position = "absolute";
222222
canvas.className = "emscripten";
223223
document.body.appendChild(canvas);
224-
}, _id, _w, _h);
224+
}, _id, width, height);
225225
return true;
226226
};
227227

@@ -268,10 +268,12 @@ MAExtent maGetTextSize(const char *str) {
268268
}
269269

270270
MAExtent maGetScrSize(void) {
271+
int w = get_screen_width();
272+
int h = get_screen_height();
271273
if (screen == nullptr) {
272-
screen = new Canvas(get_screen_width(), get_screen_height());
274+
screen = new Canvas(w, h);
273275
}
274-
return (MAExtent)((screen->_w << 16) + screen->_h);
276+
return (MAExtent)((w << 16) + h);
275277
}
276278

277279
void maDestroyPlaceholder(MAHandle maHandle) {

src/platform/emcc/runtime.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define WAIT_INTERVAL 10
2424
#define EVENT_TYPE_RESTART 101
2525
#define EVENT_TYPE_SHOW_MENU 102
26+
#define EVENT_TYPE_RESIZE 103
2627

2728
Runtime *runtime;
2829

@@ -52,6 +53,15 @@ EM_BOOL key_callback(int eventType, const EmscriptenKeyboardEvent *e, void *user
5253
return 0;
5354
}
5455

56+
EM_BOOL resize_callback(int eventType, const EmscriptenUiEvent *e, void *userData) {
57+
MAEvent *event = new MAEvent();
58+
event->type = EVENT_TYPE_RESIZE;
59+
event->point.x = e->documentBodyClientWidth;
60+
event->point.y = e->documentBodyClientHeight;
61+
runtime->pushEvent(event);
62+
return 0;
63+
}
64+
5565
Runtime::Runtime() :
5666
System() {
5767
logEntered();
@@ -62,6 +72,7 @@ Runtime::Runtime() :
6272
emscripten_set_mouseup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, true, mouse_callback);
6373
emscripten_set_mousemove_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, true, mouse_callback);
6474
emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, true, key_callback);
75+
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, true, resize_callback);
6576

6677
MAExtent screenSize = maGetScrSize();
6778
_output = new AnsiWidget(EXTENT_X(screenSize), EXTENT_Y(screenSize));
@@ -221,10 +232,6 @@ MAEvent Runtime::processEvents(int waitFlag) {
221232

222233
void Runtime::processEvent(MAEvent &event) {
223234
switch (event.type) {
224-
case EVENT_TYPE_KEY_PRESSED:
225-
//handleKeyEvent(event);
226-
handleEvent(event);
227-
break;
228235
case EVENT_TYPE_RESTART:
229236
setRestart();
230237
break;
@@ -233,6 +240,9 @@ void Runtime::processEvent(MAEvent &event) {
233240
_menuY = event.point.y;
234241
showMenu();
235242
break;
243+
case EVENT_TYPE_RESIZE:
244+
resize();
245+
break;
236246
default:
237247
handleEvent(event);
238248
break;
@@ -241,8 +251,9 @@ void Runtime::processEvent(MAEvent &event) {
241251

242252
void Runtime::runShell() {
243253
logEntered();
244-
runMain(MAIN_BAS);
245-
_state = kDoneState;
254+
while (1) {
255+
runMain(MAIN_BAS);
256+
}
246257
}
247258

248259
void Runtime::showCursor(CursorType cursorType) {

src/platform/emcc/runtime.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ struct Runtime : public System {
3636
void processEvent(MAEvent &event);
3737
bool run(const char *bas) { return execute(bas); }
3838
void runShell();
39-
void resize(int w, int h);
4039
void setClipboardText(const char *text) {}
4140
void setFontSize(int size);
4241
void setLoadBreak(const char *url) {}

src/ui/system.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,8 +1140,10 @@ void System::showMenu() {
11401140
_systemMenu[index++] = MENU_SHARE;
11411141
}
11421142
#endif
1143+
#if !defined(_EMCC)
11431144
items->add(new String(MENU_STR_SCREEN));
11441145
_systemMenu[index++] = MENU_SCREENSHOT;
1146+
#endif
11451147
#if defined(_SDL) || defined(_FLTK) || defined(_EMCC)
11461148
items->add(new String(MENU_STR_BACK));
11471149
_systemMenu[index++] = MENU_BACK;

0 commit comments

Comments
 (0)