mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Better WindowClass handling, Added Clipboard
This commit is contained in:
@@ -82,5 +82,6 @@
|
||||
<body>
|
||||
<div id="msg"></div>
|
||||
<button id="btn" onclick="HandleClick();">Click Me!</button>
|
||||
<input type="text" id="testInput" value="Hello World!"></input>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,362 @@
|
||||
using Ultralight;
|
||||
using GlitchyEngine;
|
||||
using System;
|
||||
|
||||
namespace Ultralight;
|
||||
|
||||
extension ULKeyCode
|
||||
{
|
||||
public static explicit operator ULKeyCode(Key key)
|
||||
{
|
||||
return (ULKeyCode)(int32)key;
|
||||
}
|
||||
|
||||
public String GetKeyIdentifier()
|
||||
{
|
||||
switch (this)
|
||||
{
|
||||
case .GK_BACK:
|
||||
return "U+000008";
|
||||
case .GK_TAB:
|
||||
return "U+000009";
|
||||
case .GK_CLEAR:
|
||||
return "Clear";
|
||||
case .GK_RETURN:
|
||||
return "Enter";
|
||||
case .GK_SHIFT:
|
||||
return "Shift";
|
||||
case .GK_CONTROL:
|
||||
return "Control";
|
||||
case .GK_MENU:
|
||||
return "Alt";
|
||||
case .GK_PAUSE:
|
||||
return "Pause";
|
||||
case .GK_CAPITAL:
|
||||
return "CapsLock";
|
||||
case .GK_KANA:
|
||||
return "KanaMode";
|
||||
//case .GK_HANGUL:
|
||||
// return "HangulMode";
|
||||
case .GK_IME_ON:
|
||||
return "Convert";
|
||||
case .GK_JUNJA:
|
||||
return "JunjaMode";
|
||||
case .GK_FINAL:
|
||||
return "FinalMode";
|
||||
case .GK_HANJA:
|
||||
return "HanjaMode";
|
||||
//case .GK_KANJI:
|
||||
// return "KanjiMode";
|
||||
case .GK_IME_OFF:
|
||||
return "Nonconvert";
|
||||
case .GK_ESCAPE:
|
||||
return "U+00001B";
|
||||
case .GK_CONVERT:
|
||||
return "Convert";
|
||||
case .GK_NONCONVERT:
|
||||
return "Nonconvert";
|
||||
case .GK_ACCEPT:
|
||||
return "Accept";
|
||||
case .GK_MODECHANGE:
|
||||
return "ModeChange";
|
||||
case .GK_SPACE:
|
||||
return "U+000020";
|
||||
case .GK_PRIOR:
|
||||
return "PageUp";
|
||||
case .GK_NEXT:
|
||||
return "PageDown";
|
||||
case .GK_END:
|
||||
return "End";
|
||||
case .GK_HOME:
|
||||
return "Home";
|
||||
case .GK_LEFT:
|
||||
return "Left";
|
||||
case .GK_UP:
|
||||
return "Up";
|
||||
case .GK_RIGHT:
|
||||
return "Right";
|
||||
case .GK_DOWN:
|
||||
return "Down";
|
||||
case .GK_SELECT:
|
||||
return "Select";
|
||||
case .GK_PRINT:
|
||||
return "PrintScreen";
|
||||
case .GK_EXECUTE:
|
||||
return "Execute";
|
||||
case .GK_SNAPSHOT:
|
||||
return "PrintScreen";
|
||||
case .GK_INSERT:
|
||||
return "Insert";
|
||||
case .GK_DELETE:
|
||||
return "U+00007F";
|
||||
case .GK_HELP:
|
||||
return "Help";
|
||||
case .GK_0:
|
||||
return "U+000030";
|
||||
case .GK_1:
|
||||
return "U+000031";
|
||||
case .GK_2:
|
||||
return "U+000032";
|
||||
case .GK_3:
|
||||
return "U+000033";
|
||||
case .GK_4:
|
||||
return "U+000034";
|
||||
case .GK_5:
|
||||
return "U+000035";
|
||||
case .GK_6:
|
||||
return "U+000036";
|
||||
case .GK_7:
|
||||
return "U+000037";
|
||||
case .GK_8:
|
||||
return "U+000038";
|
||||
case .GK_9:
|
||||
return "U+000039";
|
||||
case .GK_A:
|
||||
return "U+000041";
|
||||
case .GK_B:
|
||||
return "U+000042";
|
||||
case .GK_C:
|
||||
return "U+000043";
|
||||
case .GK_D:
|
||||
return "U+000044";
|
||||
case .GK_E:
|
||||
return "U+000045";
|
||||
case .GK_F:
|
||||
return "U+000046";
|
||||
case .GK_G:
|
||||
return "U+000047";
|
||||
case .GK_H:
|
||||
return "U+000048";
|
||||
case .GK_I:
|
||||
return "U+000049";
|
||||
case .GK_J:
|
||||
return "U+00004A";
|
||||
case .GK_K:
|
||||
return "U+00004B";
|
||||
case .GK_L:
|
||||
return "U+00004C";
|
||||
case .GK_M:
|
||||
return "U+00004D";
|
||||
case .GK_N:
|
||||
return "U+00004E";
|
||||
case .GK_O:
|
||||
return "U+00004F";
|
||||
case .GK_P:
|
||||
return "U+000050";
|
||||
case .GK_Q:
|
||||
return "U+000051";
|
||||
case .GK_R:
|
||||
return "U+000052";
|
||||
case .GK_S:
|
||||
return "U+000053";
|
||||
case .GK_T:
|
||||
return "U+000054";
|
||||
case .GK_U:
|
||||
return "U+000055";
|
||||
case .GK_V:
|
||||
return "U+000056";
|
||||
case .GK_W:
|
||||
return "U+000057";
|
||||
case .GK_X:
|
||||
return "U+000058";
|
||||
case .GK_Y:
|
||||
return "U+000059";
|
||||
case .GK_Z:
|
||||
return "U+00005A";
|
||||
case .GK_LWIN:
|
||||
return "Win";
|
||||
case .GK_RWIN:
|
||||
return "Win";
|
||||
case .GK_APPS:
|
||||
return "Apps";
|
||||
case .GK_SLEEP:
|
||||
return "Sleep";
|
||||
case .GK_NUMPAD0:
|
||||
return "U+000030";
|
||||
case .GK_NUMPAD1:
|
||||
return "U+000031";
|
||||
case .GK_NUMPAD2:
|
||||
return "U+000032";
|
||||
case .GK_NUMPAD3:
|
||||
return "U+000033";
|
||||
case .GK_NUMPAD4:
|
||||
return "U+000034";
|
||||
case .GK_NUMPAD5:
|
||||
return "U+000035";
|
||||
case .GK_NUMPAD6:
|
||||
return "U+000036";
|
||||
case .GK_NUMPAD7:
|
||||
return "U+000037";
|
||||
case .GK_NUMPAD8:
|
||||
return "U+000038";
|
||||
case .GK_NUMPAD9:
|
||||
return "U+000039";
|
||||
case .GK_MULTIPLY:
|
||||
return "U+00002A";
|
||||
case .GK_ADD:
|
||||
return "U+00002B";
|
||||
case .GK_SEPARATOR:
|
||||
return "Separator";
|
||||
case .GK_SUBTRACT:
|
||||
return "U+00002D";
|
||||
case .GK_DECIMAL:
|
||||
return "U+00002E";
|
||||
case .GK_DIVIDE:
|
||||
return "U+00002F";
|
||||
case .GK_F1:
|
||||
return "F1";
|
||||
case .GK_F2:
|
||||
return "F2";
|
||||
case .GK_F3:
|
||||
return "F3";
|
||||
case .GK_F4:
|
||||
return "F4";
|
||||
case .GK_F5:
|
||||
return "F5";
|
||||
case .GK_F6:
|
||||
return "F6";
|
||||
case .GK_F7:
|
||||
return "F7";
|
||||
case .GK_F8:
|
||||
return "F8";
|
||||
case .GK_F9:
|
||||
return "F9";
|
||||
case .GK_F10:
|
||||
return "F10";
|
||||
case .GK_F11:
|
||||
return "F11";
|
||||
case .GK_F12:
|
||||
return "F12";
|
||||
case .GK_F13:
|
||||
return "F13";
|
||||
case .GK_F14:
|
||||
return "F14";
|
||||
case .GK_F15:
|
||||
return "F15";
|
||||
case .GK_F16:
|
||||
return "F16";
|
||||
case .GK_F17:
|
||||
return "F17";
|
||||
case .GK_F18:
|
||||
return "F18";
|
||||
case .GK_F19:
|
||||
return "F19";
|
||||
case .GK_F20:
|
||||
return "F20";
|
||||
case .GK_F21:
|
||||
return "F21";
|
||||
case .GK_F22:
|
||||
return "F22";
|
||||
case .GK_F23:
|
||||
return "F23";
|
||||
case .GK_F24:
|
||||
return "F24";
|
||||
case .GK_NUMLOCK:
|
||||
return "NumLock";
|
||||
case .GK_SCROLL:
|
||||
return "Scroll";
|
||||
case .GK_LSHIFT:
|
||||
return "Shift";
|
||||
case .GK_RSHIFT:
|
||||
return "Shift";
|
||||
case .GK_LCONTROL:
|
||||
return "Control";
|
||||
case .GK_RCONTROL:
|
||||
return "Control";
|
||||
case .GK_LMENU:
|
||||
return "Alt";
|
||||
case .GK_RMENU:
|
||||
return "AltGraph";
|
||||
case .GK_BROWSER_BACK:
|
||||
return "BrowserBack";
|
||||
case .GK_BROWSER_FORWARD:
|
||||
return "BrowserForward";
|
||||
case .GK_BROWSER_REFRESH:
|
||||
return "BrowserRefresh";
|
||||
case .GK_BROWSER_STOP:
|
||||
return "BrowserStop";
|
||||
case .GK_BROWSER_SEARCH:
|
||||
return "BrowserSearch";
|
||||
case .GK_BROWSER_FAVORITES:
|
||||
return "BrowserFavorites";
|
||||
case .GK_BROWSER_HOME:
|
||||
return "BrowserHome";
|
||||
case .GK_VOLUME_MUTE:
|
||||
return "VolumeMute";
|
||||
case .GK_VOLUME_DOWN:
|
||||
return "VolumeDown";
|
||||
case .GK_VOLUME_UP:
|
||||
return "VolumeUp";
|
||||
case .GK_MEDIA_NEXT_TRACK:
|
||||
return "MediaNextTrack";
|
||||
case .GK_MEDIA_PREV_TRACK:
|
||||
return "MediaPreviousTrack";
|
||||
case .GK_MEDIA_STOP:
|
||||
return "MediaStop";
|
||||
case .GK_MEDIA_PLAY_PAUSE:
|
||||
return "MediaPlayPause";
|
||||
case .GK_MEDIA_LAUNCH_MAIL:
|
||||
return "LaunchMail";
|
||||
case .GK_MEDIA_LAUNCH_MEDIA_SELECT:
|
||||
return "SelectMedia";
|
||||
case .GK_MEDIA_LAUNCH_APP1:
|
||||
return "LaunchApplication1";
|
||||
case .GK_MEDIA_LAUNCH_APP2:
|
||||
return "LaunchApplication2";
|
||||
case .GK_OEM_1:
|
||||
return "U+00003B";
|
||||
case .GK_OEM_PLUS:
|
||||
return "U+00002B";
|
||||
case .GK_OEM_COMMA:
|
||||
return "U+00002C";
|
||||
case .GK_OEM_MINUS:
|
||||
return "U+00002D";
|
||||
case .GK_OEM_PERIOD:
|
||||
return "U+00002E";
|
||||
case .GK_OEM_2:
|
||||
return "U+00002F";
|
||||
case .GK_OEM_3:
|
||||
return "U+000040";
|
||||
case .GK_OEM_4:
|
||||
return "U+00005B";
|
||||
case .GK_OEM_5:
|
||||
return "U+00005C";
|
||||
case .GK_OEM_6:
|
||||
return "U+00005D";
|
||||
case .GK_OEM_7:
|
||||
return "U+000027";
|
||||
case .GK_OEM_8:
|
||||
return "U+00005E";
|
||||
case .GK_OEM_102:
|
||||
return "U+00007C";
|
||||
case .GK_PROCESSKEY:
|
||||
return "Process";
|
||||
case .GK_PACKET:
|
||||
return "Packet";
|
||||
case .GK_OEM_ATTN:
|
||||
return "Attn";
|
||||
case .GK_ATTN:
|
||||
return "Attn";
|
||||
case .GK_CRSEL:
|
||||
return "Crsel";
|
||||
case .GK_EXSEL:
|
||||
return "Exsel";
|
||||
case .GK_EREOF:
|
||||
return "EraseEof";
|
||||
case .GK_PLAY:
|
||||
return "Play";
|
||||
case .GK_ZOOM:
|
||||
return "Zoom";
|
||||
case .GK_NONAME:
|
||||
return "NoName";
|
||||
case .GK_PA1:
|
||||
return "PA1";
|
||||
case .GK_OEM_CLEAR:
|
||||
return "Clear";
|
||||
case .GK_UNKNOWN:
|
||||
return "Unknown";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ using GlitchyEngine.Math;
|
||||
using GlitchyEngine.Events;
|
||||
using GlitchyEngine.ImGui;
|
||||
using ImGui;
|
||||
using System.Text;
|
||||
using GlitchyEngine.System;
|
||||
|
||||
namespace GlitchyEditor;
|
||||
|
||||
@@ -36,43 +38,101 @@ class UltralightLayer : Layer
|
||||
dispatcher.Dispatch<MouseMovedEvent>(scope => MouseMoved);
|
||||
dispatcher.Dispatch<MouseButtonPressedEvent>(scope (e) => MousePressed(e, true));
|
||||
dispatcher.Dispatch<MouseButtonReleasedEvent>(scope (e) => MousePressed(e, false));
|
||||
dispatcher.Dispatch<KeyPressedEvent>(scope (e) => KeyEvent(e, true, e.RepeatCount));
|
||||
dispatcher.Dispatch<KeyReleasedEvent>(scope (e) => KeyEvent(e, false, 0));
|
||||
dispatcher.Dispatch<KeyTypedEvent>(scope (e) => CharTypedEvent(e));
|
||||
dispatcher.Dispatch<WindowCloseEvent>(scope (e) => {
|
||||
delete windoww;
|
||||
windoww = null;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private bool CharTypedEvent(KeyTypedEvent e)
|
||||
{
|
||||
String s = scope String();
|
||||
s.Append(e.Char);
|
||||
|
||||
ULString str = ulCreateString(s.CStr());
|
||||
|
||||
ULKeyEvent event = ulCreateKeyEvent(.kKeyEventType_Char,
|
||||
0, 0, 0, str, str, false, false, false);
|
||||
|
||||
ulDestroyString(str);
|
||||
|
||||
ulViewFireKeyEvent(view, event);
|
||||
ulDestroyKeyEvent(event);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool KeyEvent(KeyEvent e, bool pressed, int repeatCount)
|
||||
{
|
||||
bool isRepeat = repeatCount > 1;
|
||||
|
||||
ULKeyCode keyCode = (ULKeyCode)e.KeyCode;
|
||||
|
||||
ULString str = ulCreateString(keyCode.GetKeyIdentifier());
|
||||
|
||||
ULKeyboardModifier modifier = 0;
|
||||
|
||||
if (Input.IsKeyPressed(.Control))
|
||||
modifier |= .kMod_CtrlKey;
|
||||
|
||||
if (Input.IsKeyPressed(.Alt))
|
||||
modifier |= .kMod_AltKey;
|
||||
|
||||
if (Input.IsKeyPressed(.Shift))
|
||||
modifier |= .kMod_ShiftKey;
|
||||
|
||||
if (Input.IsKeyPressed(.Home))
|
||||
modifier |= .kMod_MetaKey;
|
||||
|
||||
ULKeyEvent event = ulCreateKeyEvent(pressed ? .kKeyEventType_RawKeyDown : .kKeyEventType_KeyUp,
|
||||
(uint32)modifier, (int32)keyCode, 0, str, str, false, isRepeat, false);
|
||||
|
||||
ulDestroyString(str);
|
||||
|
||||
for (int i < repeatCount)
|
||||
{
|
||||
ulViewFireKeyEvent(view, event);
|
||||
}
|
||||
|
||||
ulDestroyKeyEvent(event);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool MouseMoved(MouseMovedEvent e)
|
||||
{
|
||||
if (e.Window == windoww)
|
||||
{
|
||||
Log.EngineLogger.Warning($"{e.PositionX}");
|
||||
ULMouseEvent evt = ulCreateMouseEvent(.kMouseEventType_MouseMoved, e.PositionX, e.PositionY, .kMouseButton_None);
|
||||
ulViewFireMouseEvent(view, evt);
|
||||
ulDestroyMouseEvent(evt);
|
||||
Log.EngineLogger.Warning($"{e.PositionX}");
|
||||
|
||||
cursorPosition = .(e.PositionX, e.PositionY);
|
||||
}
|
||||
ULMouseEvent evt = ulCreateMouseEvent(.kMouseEventType_MouseMoved, e.PositionX, e.PositionY, .kMouseButton_None);
|
||||
ulViewFireMouseEvent(view, evt);
|
||||
ulDestroyMouseEvent(evt);
|
||||
|
||||
return false;
|
||||
cursorPosition = .(e.PositionX, e.PositionY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool MousePressed(MouseButtonEvent e, bool press)
|
||||
{
|
||||
if (e.Window == windoww)
|
||||
ULMouseButton button = .kMouseButton_None;
|
||||
|
||||
switch (e.MouseButton)
|
||||
{
|
||||
ULMouseButton button = .kMouseButton_None;
|
||||
|
||||
switch (e.MouseButton)
|
||||
{
|
||||
case .LeftButton: button = .kMouseButton_Left;
|
||||
case .RightButton: button = .kMouseButton_Right;
|
||||
case .MiddleButton: button = .kMouseButton_Middle;
|
||||
default: button = .kMouseButton_None;
|
||||
}
|
||||
|
||||
ULMouseEvent evt = ulCreateMouseEvent(press ? .kMouseEventType_MouseDown : .kMouseEventType_MouseUp, cursorPosition.X, cursorPosition.Y, button);
|
||||
ulViewFireMouseEvent(view, evt);
|
||||
ulDestroyMouseEvent(evt);
|
||||
case .LeftButton: button = .kMouseButton_Left;
|
||||
case .RightButton: button = .kMouseButton_Right;
|
||||
case .MiddleButton: button = .kMouseButton_Middle;
|
||||
default: button = .kMouseButton_None;
|
||||
}
|
||||
|
||||
return false;
|
||||
ULMouseEvent evt = ulCreateMouseEvent(press ? .kMouseEventType_MouseDown : .kMouseEventType_MouseUp, cursorPosition.X, cursorPosition.Y, button);
|
||||
ulViewFireMouseEvent(view, evt);
|
||||
ulDestroyMouseEvent(evt);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void OnAppUpdate(void* user_data)
|
||||
@@ -170,6 +230,24 @@ class UltralightLayer : Layer
|
||||
|
||||
ULRenderer renderer;
|
||||
|
||||
private static void InitClipboard()
|
||||
{
|
||||
ULClipboard clipboard = .();
|
||||
clipboard.clear = () => Clipboard.Clear();
|
||||
|
||||
clipboard.read_plain_text = (s) => {
|
||||
String text = scope .();
|
||||
Clipboard.Read(text);
|
||||
ulStringAssignCString(s, text);
|
||||
};
|
||||
|
||||
clipboard.write_plain_text = (s) => {
|
||||
Clipboard.Set(StringView(ulStringGetData(s)));
|
||||
};
|
||||
|
||||
ulPlatformSetClipboard(clipboard);
|
||||
}
|
||||
|
||||
private void NoApp()
|
||||
{
|
||||
ULConfig config = ulCreateConfig();
|
||||
@@ -180,9 +258,7 @@ class UltralightLayer : Layer
|
||||
ulEnablePlatformFileSystem(fileSystemPath);
|
||||
ulDestroyString(fileSystemPath);
|
||||
|
||||
/*ULString styleSheet = ulCreateString("body { background: purple; }");
|
||||
ulConfigSetUserStylesheet(config, styleSheet);
|
||||
ulDestroyString(styleSheet);*/
|
||||
InitClipboard();
|
||||
|
||||
renderer = ulCreateRenderer(config);
|
||||
|
||||
@@ -225,6 +301,9 @@ class UltralightLayer : Layer
|
||||
|
||||
private void Render()
|
||||
{
|
||||
if (windoww == null)
|
||||
return;
|
||||
|
||||
RenderCommand.Clear(windoww.SwapChain.BackBuffer, .Color | .Depth, .(0.7f, 0.2f, 0.2f), 1.0f, 0);
|
||||
}
|
||||
|
||||
@@ -238,7 +317,11 @@ class UltralightLayer : Layer
|
||||
ulViewSetDOMReadyCallback(view, => OnDOMReady, null);
|
||||
|
||||
ulDestroyViewConfig(viewConfig);
|
||||
|
||||
|
||||
ulViewSetFailLoadingCallback(view, (user_data, caller, frame_id, is_main_frame, url, description, error_domain, error_code) => {
|
||||
Log.ClientLogger.Error("Errorrr");
|
||||
}, null);
|
||||
|
||||
ULString url = ulCreateString("file:///app.html");
|
||||
ulViewLoadURL(view, url);
|
||||
ulDestroyString(url);
|
||||
|
||||
Reference in New Issue
Block a user