Changeset - r25736:169627858688
[Not reviewed]
master
0 3 0
embeddedt - 3 years ago 2021-06-28 16:39:09
42941056+embeddedt@users.noreply.github.com
Change: [Emscripten] set default scrolling mode to non-pointer-locking (#9191)
3 files changed with 21 insertions and 28 deletions:
0 comments (0 inline, 0 general)
os/emscripten/shell.html
Show inline comments
 
@@ -76,24 +76,26 @@
 
      #message {
 
        color: #101010;
 
        height: 54px;
 
        padding: 4px 4px;
 
      }
 

	
 
      canvas.emscripten {
 
        border: 0px none;
 
        height: 100%;
 
        position: absolute;
 
        width: 100%;
 
        z-index: 2;
 
        /* OpenTTD draws the cursor itself */
 
        cursor: none !important;
 
      }
 
    </style>
 
  </head>
 
  <body>
 
    <div class="background">
 
      <div id="box">
 
        <div id="title">
 
          Loading ...
 
        </div>
 
        <div id="message">
 
        </div>
 
      </div>
src/table/settings/settings.ini
Show inline comments
 
@@ -2507,24 +2507,38 @@ cat      = SC_BASIC
 
var      = gui.auto_scrolling
 
type     = SLE_UINT8
 
flags    = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | SF_GUI_DROPDOWN
 
def      = 0
 
min      = 0
 
max      = 3
 
str      = STR_CONFIG_SETTING_AUTOSCROLL
 
strhelp  = STR_CONFIG_SETTING_AUTOSCROLL_HELPTEXT
 
strval   = STR_CONFIG_SETTING_AUTOSCROLL_DISABLED
 
cat      = SC_BASIC
 

	
 
[SDTC_VAR]
 
ifdef    = __EMSCRIPTEN__
 
var      = gui.scroll_mode
 
type     = SLE_UINT8
 
flags    = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | SF_GUI_DROPDOWN
 
def      = 2
 
min      = 0
 
max      = 3
 
str      = STR_CONFIG_SETTING_SCROLLMODE
 
strhelp  = STR_CONFIG_SETTING_SCROLLMODE_HELPTEXT
 
strval   = STR_CONFIG_SETTING_SCROLLMODE_DEFAULT
 
cat      = SC_BASIC
 

	
 
[SDTC_VAR]
 
ifndef    = __EMSCRIPTEN__
 
var      = gui.scroll_mode
 
type     = SLE_UINT8
 
flags    = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | SF_GUI_DROPDOWN
 
def      = 0
 
min      = 0
 
max      = 3
 
str      = STR_CONFIG_SETTING_SCROLLMODE
 
strhelp  = STR_CONFIG_SETTING_SCROLLMODE_HELPTEXT
 
strval   = STR_CONFIG_SETTING_SCROLLMODE_DEFAULT
 
cat      = SC_BASIC
 

	
 
[SDTC_BOOL]
src/video/sdl2_v.cpp
Show inline comments
 
@@ -21,29 +21,24 @@
 
#include "../fileio_func.h"
 
#include "../framerate_type.h"
 
#include "../window_func.h"
 
#include "sdl2_v.h"
 
#include <SDL.h>
 
#ifdef __EMSCRIPTEN__
 
#	include <emscripten.h>
 
#	include <emscripten/html5.h>
 
#endif
 

	
 
#include "../safeguards.h"
 

	
 
#ifdef __EMSCRIPTEN__
 
/** Whether we just had a window-enter event. */
 
static bool _cursor_new_in_window = false;
 
#endif
 

	
 
void VideoDriver_SDL_Base::MakeDirty(int left, int top, int width, int height)
 
{
 
	Rect r = {left, top, left + width, top + height};
 
	this->dirty_rect = BoundingRect(this->dirty_rect, r);
 
}
 

	
 
void VideoDriver_SDL_Base::CheckPaletteAnim()
 
{
 
	if (!CopyPalette(this->local_palette)) return;
 
	this->MakeDirty(0, 0, _screen.width, _screen.height);
 
}
 

	
 
@@ -194,27 +189,27 @@ bool VideoDriver_SDL_Base::CreateMainSur
 
	this->ClientSizeChanged(w, h, true);
 

	
 
	/* When in full screen, we will always have the mouse cursor
 
	 * within the window, even though SDL does not give us the
 
	 * appropriate event to know this. */
 
	if (_fullscreen) _cursor.in_window = true;
 

	
 
	return true;
 
}
 

	
 
bool VideoDriver_SDL_Base::ClaimMousePointer()
 
{
 
	/* Emscripten never claims the pointer, so we do not need to change the cursor visibility. */
 
#ifndef __EMSCRIPTEN__
 
	SDL_ShowCursor(0);
 
#ifdef __EMSCRIPTEN__
 
	SDL_SetRelativeMouseMode(SDL_TRUE);
 
#endif
 
	return true;
 
}
 

	
 
/**
 
 * This is called to indicate that an edit box has gained focus, text input mode should be enabled.
 
 */
 
void VideoDriver_SDL_Base::EditBoxGainedFocus()
 
{
 
	if (!this->edit_box_focused) {
 
		SDL_StartTextInput();
 
		this->edit_box_focused = true;
 
@@ -368,45 +363,27 @@ static uint ConvertSdlKeycodeIntoMy(SDL_
 

	
 
	return key;
 
}
 

	
 
bool VideoDriver_SDL_Base::PollEvent()
 
{
 
	SDL_Event ev;
 

	
 
	if (!SDL_PollEvent(&ev)) return false;
 

	
 
	switch (ev.type) {
 
		case SDL_MOUSEMOTION:
 
#ifdef __EMSCRIPTEN__
 
			if (_cursor_new_in_window) {
 
				/* The cursor just moved into the window; this means we don't
 
				 * know the absolutely position yet to move relative from.
 
				 * Before this time, SDL didn't know it either, and this is
 
				 * why we postpone it till now. Update the absolute position
 
				 * for this once, and work relative after. */
 
				_cursor.pos.x = ev.motion.x;
 
				_cursor.pos.y = ev.motion.y;
 
				_cursor.dirty = true;
 

	
 
				_cursor_new_in_window = false;
 
				SDL_SetRelativeMouseMode(SDL_TRUE);
 
			} else {
 
				_cursor.UpdateCursorPositionRelative(ev.motion.xrel, ev.motion.yrel);
 
			}
 
#else
 
			if (_cursor.UpdateCursorPosition(ev.motion.x, ev.motion.y, true)) {
 
				SDL_WarpMouseInWindow(this->sdl_window, _cursor.pos.x, _cursor.pos.y);
 
			}
 
#endif
 
			HandleMouseEvents();
 
			break;
 

	
 
		case SDL_MOUSEWHEEL:
 
			if (ev.wheel.y > 0) {
 
				_cursor.wheel--;
 
			} else if (ev.wheel.y < 0) {
 
				_cursor.wheel++;
 
			}
 
			break;
 

	
 
		case SDL_MOUSEBUTTONDOWN:
 
@@ -493,48 +470,48 @@ bool VideoDriver_SDL_Base::PollEvent()
 
		case SDL_WINDOWEVENT: {
 
			if (ev.window.event == SDL_WINDOWEVENT_EXPOSED) {
 
				// Force a redraw of the entire screen.
 
				this->MakeDirty(0, 0, _screen.width, _screen.height);
 
			} else if (ev.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
 
				int w = std::max(ev.window.data1, 64);
 
				int h = std::max(ev.window.data2, 64);
 
				CreateMainSurface(w, h, w != ev.window.data1 || h != ev.window.data2);
 
			} else if (ev.window.event == SDL_WINDOWEVENT_ENTER) {
 
				// mouse entered the window, enable cursor
 
				_cursor.in_window = true;
 
#ifdef __EMSCRIPTEN__
 
				/* Disable relative mouse mode for the first mouse motion,
 
				 * so we can pick up the absolutely position again. */
 
				_cursor_new_in_window = true;
 
				/* Ensure pointer lock will not occur. */
 
				SDL_SetRelativeMouseMode(SDL_FALSE);
 
#endif
 
			} else if (ev.window.event == SDL_WINDOWEVENT_LEAVE) {
 
				// mouse left the window, undraw cursor
 
				UndrawMouseCursor();
 
				_cursor.in_window = false;
 
			}
 
			break;
 
		}
 
	}
 

	
 
	return true;
 
}
 

	
 
static const char *InitializeSDL()
 
{
 
	/* Explicitly disable hardware acceleration. Enabling this causes
 
	 * UpdateWindowSurface() to update the window's texture instead of
 
	 * its surface. */
 
	SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "0");
 
#ifndef __EMSCRIPTEN__
 
	SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1");
 
#endif
 

	
 
	/* Check if the video-driver is already initialized. */
 
	if (SDL_WasInit(SDL_INIT_VIDEO) != 0) return nullptr;
 

	
 
	if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) return SDL_GetError();
 
	return nullptr;
 
}
 

	
 
const char *VideoDriver_SDL_Base::Initialize()
 
{
 
	this->UpdateAutoResolution();
 

	
0 comments (0 inline, 0 general)