Add Mouse.visible, move cursor backend for HTML5 to window

This commit is contained in:
Joshua Granick
2018-07-07 11:11:22 -07:00
parent ead5cd8946
commit cba70332e5
5 changed files with 100 additions and 25 deletions

View File

@@ -110,4 +110,11 @@ class FlashMouse {
}
public static function get_visible ():Bool {
return !__hidden;
}
}

View File

@@ -24,7 +24,7 @@ class HTML5Mouse {
for (window in Application.current.windows) {
window.__backend.element.style.cursor = "none";
window.__backend.hideCursor ();
}
@@ -39,9 +39,11 @@ class HTML5Mouse {
__hidden = false;
var cacheValue = __cursor;
__cursor = null;
set_cursor (cacheValue);
for (window in Application.current.windows) {
window.__backend.showCursor ();
}
}
@@ -74,28 +76,9 @@ class HTML5Mouse {
if (__cursor != value) {
if (!__hidden) {
for (window in Application.current.windows) {
for (window in Application.current.windows) {
window.__backend.element.style.cursor = switch (value) {
case ARROW: "default";
case CROSSHAIR: "crosshair";
case MOVE: "move";
case POINTER: "pointer";
case RESIZE_NESW: "nesw-resize";
case RESIZE_NS: "ns-resize";
case RESIZE_NWSE: "nwse-resize";
case RESIZE_WE: "ew-resize";
case TEXT: "text";
case WAIT: "wait";
case WAIT_ARROW: "wait";
default: "auto";
}
}
window.__backend.setCursor (value);
}
@@ -122,4 +105,11 @@ class HTML5Mouse {
}
public static function get_visible ():Bool {
return !__hidden;
}
}

View File

@@ -29,6 +29,7 @@ import lime.system.System;
import lime.system.Clipboard;
import lime.ui.Gamepad;
import lime.ui.Joystick;
import lime.ui.MouseCursor;
import lime.ui.Touch;
import lime.ui.Window;
@@ -62,6 +63,8 @@ class HTML5Window {
private var cacheElementWidth:Float;
private var cacheMouseX:Float;
private var cacheMouseY:Float;
private var cursor:MouseCursor;
private var cursorHidden:Bool;
private var currentTouches = new Map<Int, Touch> ();
private var enableTextEvents:Bool;
private var isFullscreen:Bool;
@@ -401,6 +404,18 @@ class HTML5Window {
}
public function hideCursor ():Void {
if (!cursorHidden) {
cursorHidden = true;
element.style.cursor = "none";
}
}
public function setDisplayMode (value:DisplayMode):DisplayMode {
return value;
@@ -1005,6 +1020,38 @@ class HTML5Window {
}
public function setCursor (value:MouseCursor):Void {
if (cursor != value) {
if (!cursorHidden) {
element.style.cursor = switch (value) {
case ARROW: "default";
case CROSSHAIR: "crosshair";
case MOVE: "move";
case POINTER: "pointer";
case RESIZE_NESW: "nesw-resize";
case RESIZE_NS: "ns-resize";
case RESIZE_NWSE: "nwse-resize";
case RESIZE_WE: "ew-resize";
case TEXT: "text";
case WAIT: "wait";
case WAIT_ARROW: "wait";
default: "auto";
}
}
cursor = value;
}
}
public function setEnableTextEvents (value:Bool):Bool {
if (value) {
@@ -1236,6 +1283,21 @@ class HTML5Window {
}
public function showCursor ():Void {
if (cursorHidden) {
cursorHidden = false;
var cacheValue = cursor;
cursor = null;
setCursor (cacheValue);
}
}
private function updateSize ():Void {
if (!parent.__resizable) return;

View File

@@ -139,6 +139,14 @@ class NativeMouse {
}
public static function get_visible ():Bool {
// TODO: Use SDL_ShowCursor (SDL_QUERY) to poll state instead?
return !__hidden;
}
}

View File

@@ -12,6 +12,7 @@ class Mouse {
public static var cursor (get, set):MouseCursor;
public static var lock (get, set):Bool;
public static var visible (get, never):Bool;
public static function hide ():Void {
@@ -70,6 +71,13 @@ class Mouse {
}
private static function get_visible ():Bool {
return MouseBackend.get_visible ();
}
}