Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Html5 support #47

Merged
merged 3 commits into from
Jan 4, 2018
Merged

Html5 support #47

merged 3 commits into from
Jan 4, 2018

Conversation

AGulev
Copy link
Collaborator

@AGulev AGulev commented Jan 3, 2018

Added support of HTML5 #24

@AGulev AGulev self-assigned this Jan 3, 2018
@subsoap
Copy link
Owner

subsoap commented Jan 3, 2018

Checking now.

@subsoap subsoap merged commit f173e59 into subsoap:master Jan 4, 2018
}

void defos_toggle_fullscreen() {
js_warn("Method 'toggle_fullscreen' don't supported in html5, you can use Module.toggleFullscreen() method in JS");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not call Module.toggleFullscreen() here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, but :
Note: Fullscreen requests need to be called from within an event handler or otherwise they will be denied.
https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory we can use some hack like
Module.canvas.onclick = function()
{
Module.toggleFullscreen();
Module.canvas.onclick = "";
}
But this method would be work only in action.pressed and won't in action.released

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could technically queue it to some other event, like mouse moved, or to multiple events, but yeah, it's finicky. Maybe put it on a hidden button and .click() it? I'm not sure that would work. I'll try out some things when I come back from work.

Copy link
Collaborator Author

@AGulev AGulev Jan 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked many variants (even emscripten_set_*_callback and so on)
I found only one way:
a hack with on_mouse_up (released) callback, but button should use action.pressed event then.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I managed to sort of work around the issue after all. I added an defos.on_click() event where the user can manually check if the mouse is clicking on his full screen button and then call defos.toggle_fullscreen() from there. This will work because defos.on_click() calls its callback inside the native HTML event handler.

}

void defos_event_handler_was_set(DefosEvent event) {
js_warn("Callbacks 'on_mouse_leave' and 'on_mouse_enter' don't supported in html5");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could technically be implemented with Module.canvas.addEventListener('mouseenter') and Module.canvas.addEventListener('mouseleave')

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I know.
But we have no possability to call cpp method from JS. defold/extension-html5#1

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should probably be safe to ccall() it. Setting up lua contexts is done by defos_emit_event() anyway. (And there's only one thread in JS anyway, so we have no such issues).

Copy link
Collaborator Author

@AGulev AGulev Jan 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, but it was a deep night when i make experiments.
Let this Pull Request will be start of new platform, and we make some improvements step by step.
I will try ccall today after work, but I have to use some compilation parameters like EXPORTED_FUNCTIONS, i need to understand how to use them

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it in #48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants