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

fixed WebViewObject.cs to repaint only when Event.current.type is EventType.Repaint. #600

Merged
merged 1 commit into from
Oct 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixed WebViewObject.cs to repaint only when Event.current.type is Eve…
…ntType.Repaint.
KojiNakamaru committed Oct 13, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit ae005daca2a861a22d5c3fb0e669281330c4ad01
138 changes: 79 additions & 59 deletions plugins/WebViewObject.cs
Original file line number Diff line number Diff line change
@@ -1011,58 +1011,8 @@ void Update()
break;
}
}
}

public int bitmapRefreshCycle = 1;

void OnGUI()
{
if (webView == IntPtr.Zero || !visibility)
return;

Vector3 p;
p.x = Input.mousePosition.x - rect.x;
p.y = Input.mousePosition.y - rect.y;
{
int mouseState = 0;
if (Input.GetButtonDown("Fire1")) {
mouseState = 1;
} else if (Input.GetButtonUp("Fire1")) {
mouseState = 3;
} else if (Input.GetButton("Fire1")) {
mouseState = 2;
}
_CWebViewPlugin_SendMouseEvent(webView, (int)p.x, (int)p.y, Input.GetAxis("Mouse ScrollWheel"), mouseState);
}
{
string keyChars = "";
ushort keyCode = 0;
if (!string.IsNullOrEmpty(inputString)) {
keyChars = inputString.Substring(0, 1);
keyCode = (ushort)inputString[0];
inputString = inputString.Substring(1);
}
if (!string.IsNullOrEmpty(keyChars) || keyCode != 0) {
_CWebViewPlugin_SendKeyEvent(webView, (int)p.x, (int)p.y, keyChars, keyCode, 1);
}
// if (keyChars != keyChars0) {
// if (!string.IsNullOrEmpty(keyChars0)) {
// Debug.Log("XX1 " + (short)keyChars0[0]);
// _CWebViewPlugin_SendKeyEvent(webView, (int)p.x, (int)p.y, keyChars0, keyCode0, 3);
// }
// if (!string.IsNullOrEmpty(keyChars)) {
// Debug.Log("XX2 " + (short)keyChars[0]);
// _CWebViewPlugin_SendKeyEvent(webView, (int)p.x, (int)p.y, keyChars, keyCode, 1);
// }
// } else {
// if (!string.IsNullOrEmpty(keyChars)) {
// Debug.Log("XX3");
// _CWebViewPlugin_SendKeyEvent(webView, (int)p.x, (int)p.y, keyChars, keyCode, 2);
// }
// }
// keyChars0 = keyChars;
// keyCode0 = keyCode;
}
bool refreshBitmap = (Time.frameCount % bitmapRefreshCycle == 0);
_CWebViewPlugin_Update(webView, refreshBitmap);
if (refreshBitmap) {
@@ -1083,15 +1033,85 @@ void OnGUI()
GL.IssuePluginEvent(GetRenderEventFunc(), -1);
#endif
}
if (texture != null) {
Matrix4x4 m = GUI.matrix;
GUI.matrix
= Matrix4x4.TRS(
new Vector3(0, Screen.height, 0),
Quaternion.identity,
new Vector3(1, -1, 1));
GUI.DrawTexture(rect, texture);
GUI.matrix = m;
}

public int bitmapRefreshCycle = 1;

void OnGUI()
{
if (webView == IntPtr.Zero || !visibility)
return;

switch (Event.current.type) {
case EventType.MouseDown:
case EventType.MouseUp:
case EventType.MouseMove:
case EventType.MouseDrag:
case EventType.ScrollWheel:
{
Vector3 p;
p.x = Input.mousePosition.x - rect.x;
p.y = Input.mousePosition.y - rect.y;
{
int mouseState = 0;
if (Input.GetButtonDown("Fire1")) {
mouseState = 1;
} else if (Input.GetButtonUp("Fire1")) {
mouseState = 3;
} else if (Input.GetButton("Fire1")) {
mouseState = 2;
}
_CWebViewPlugin_SendMouseEvent(webView, (int)p.x, (int)p.y, Input.GetAxis("Mouse ScrollWheel"), mouseState);
}
}
break;
case EventType.KeyDown:
case EventType.KeyUp:
{
string keyChars = "";
ushort keyCode = 0;
if (!string.IsNullOrEmpty(inputString)) {
keyChars = inputString.Substring(0, 1);
keyCode = (ushort)inputString[0];
inputString = inputString.Substring(1);
}
if (!string.IsNullOrEmpty(keyChars) || keyCode != 0) {
Vector3 p;
p.x = Input.mousePosition.x - rect.x;
p.y = Input.mousePosition.y - rect.y;
_CWebViewPlugin_SendKeyEvent(webView, (int)p.x, (int)p.y, keyChars, keyCode, 1);
}
// if (keyChars != keyChars0) {
// if (!string.IsNullOrEmpty(keyChars0)) {
// Debug.Log("XX1 " + (short)keyChars0[0]);
// _CWebViewPlugin_SendKeyEvent(webView, (int)p.x, (int)p.y, keyChars0, keyCode0, 3);
// }
// if (!string.IsNullOrEmpty(keyChars)) {
// Debug.Log("XX2 " + (short)keyChars[0]);
// _CWebViewPlugin_SendKeyEvent(webView, (int)p.x, (int)p.y, keyChars, keyCode, 1);
// }
// } else {
// if (!string.IsNullOrEmpty(keyChars)) {
// Debug.Log("XX3");
// _CWebViewPlugin_SendKeyEvent(webView, (int)p.x, (int)p.y, keyChars, keyCode, 2);
// }
// }
// keyChars0 = keyChars;
// keyCode0 = keyCode;
}
break;
case EventType.Repaint:
if (texture != null) {
Matrix4x4 m = GUI.matrix;
GUI.matrix
= Matrix4x4.TRS(
new Vector3(0, Screen.height, 0),
Quaternion.identity,
new Vector3(1, -1, 1));
GUI.DrawTexture(rect, texture);
GUI.matrix = m;
}
break;
}
}
#endif