浏览代码

Merge pull request #259 from Unity-Technologies/siyao/CopyPaste

native modify key
/main
GitHub 3 年前
当前提交
d3b06e46
共有 21 个文件被更改,包括 54 次插入24 次删除
  1. 2
      com.unity.uiwidgets/Runtime/Plugins/osx/libUIWidgets.dylib.meta
  2. 11
      com.unity.uiwidgets/Runtime/engine/UIWidgetsPanelWrapper.cs
  3. 8
      com.unity.uiwidgets/Runtime/gestures/converter.cs
  4. 3
      com.unity.uiwidgets/Runtime/ui/hooks.cs
  5. 11
      com.unity.uiwidgets/Runtime/ui/pointer.cs
  6. 3
      engine/src/lib/ui/window/pointer_data.h
  7. 1
      engine/src/shell/platform/embedder/embedder.cc
  8. 1
      engine/src/shell/platform/embedder/embedder.h
  9. 8
      engine/src/shell/platform/unity/android/uiwidgets_panel.cc
  10. 2
      engine/src/shell/platform/unity/android/uiwidgets_panel.h
  11. 2
      engine/src/shell/platform/unity/darwin/ios/uiwidgets_panel.h
  12. 7
      engine/src/shell/platform/unity/darwin/ios/uiwidgets_panel.mm
  13. 2
      engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.h
  14. 8
      engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.mm
  15. 7
      engine/src/shell/platform/unity/windows/uiwidgets_panel.cc
  16. 2
      engine/src/shell/platform/unity/windows/uiwidgets_panel.h

2
com.unity.uiwidgets/Runtime/Plugins/osx/libUIWidgets.dylib.meta


fileFormatVersion: 2
guid: 70f8ceca890db46af80df52d443eb11c
guid: 254931c60ed1242219bc572777ab7f31
PluginImporter:
externalObjects: {}
serializedVersion: 2

11
com.unity.uiwidgets/Runtime/engine/UIWidgetsPanelWrapper.cs


}
public void OnKeyDown(Event e) {
UIWidgetsPanel_onKey(ptr: _ptr, keyCode: e.keyCode, e.type == EventType.KeyDown);
int modifier = 0;
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
modifier |= e.shift ? (1 << (int) FunctionKey.shift) : 0;
modifier |= e.alt ? (1 << (int) FunctionKey.alt) : 0;
modifier |= e.command ? (1 << (int) FunctionKey.command) : 0;
modifier |= e.control ? (1 << (int) FunctionKey.control) : 0;
#endif
UIWidgetsPanel_onKey(ptr: _ptr, keyCode: e.keyCode, e.type == EventType.KeyDown, modifier);
if (e.character != 0 || e.keyCode == KeyCode.Backspace) {
PointerEventConverter.KeyEvent.Enqueue(new Event(other: e));
// TODO: add on char

static extern void UIWidgetsPanel_onChar(IntPtr ptr, char c);
[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_onKey(IntPtr ptr, KeyCode keyCode, bool isKeyDown);
static extern void UIWidgetsPanel_onKey(IntPtr ptr, KeyCode keyCode, bool isKeyDown, int modifier);
[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_onMouseDown(IntPtr ptr, float x, float y, int button);

8
com.unity.uiwidgets/Runtime/gestures/converter.cs


}else if (datum.change == PointerChange.kMouseUp) {
keyBoardEvent.type = EventType.KeyUp;
}
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
keyBoardEvent.shift = (datum.modifier & (1 << (int) FunctionKey.shift)) > 0;
keyBoardEvent.alt = (datum.modifier & (1 << (int) FunctionKey.alt)) > 0;
keyBoardEvent.command = (datum.modifier & (1 << (int) FunctionKey.command)) > 0;
keyBoardEvent.control = (datum.modifier & (1 << (int) FunctionKey.control)) > 0;
#endif
RawKeyboard.instance._handleKeyEvent(keyBoardEvent);
TextInput.OnGUI();
}

3
com.unity.uiwidgets/Runtime/ui/hooks.cs


}
}
const int _kPointerDataFieldCount = 28;
const int _kPointerDataFieldCount = 29;
static unsafe PointerDataPacket _unpackPointerDataPacket(byte* packet, int packetLength) {
const int kStride = 8;

physicalDeltaX: (float) *(double*) (packet + kStride * offset++),
physicalDeltaY: (float) *(double*) (packet + kStride * offset++),
buttons: (int) *(long*) (packet + kStride * offset++),
modifier: (int) *(long*) (packet + kStride * offset++),
obscured: *(long*) (packet + kStride * offset++) != 0,
synthesized: *(long*) (packet + kStride * offset++) != 0,
pressure: (float) *(double*) (packet + kStride * offset++),

11
com.unity.uiwidgets/Runtime/ui/pointer.cs


unknown,
}
public enum FunctionKey {
none = 0,
shift = 1,
alt = 2,
command = 3,
control = 4,
}
public readonly struct PointerData {
public PointerData(
TimeSpan? timeStamp = null,

float physicalDeltaX = 0.0f,
float physicalDeltaY = 0.0f,
int buttons = 0,
int modifier = 0,
bool obscured = false,
bool synthesized = false,
float pressure = 0.0f,

this.physicalDeltaX = physicalDeltaX;
this.physicalDeltaY = physicalDeltaY;
this.buttons = buttons;
this.modifier = modifier;
this.obscured = obscured;
this.synthesized = synthesized;
this.pressure = pressure;

public readonly float physicalDeltaX;
public readonly float physicalDeltaY;
public readonly int buttons;
public readonly int modifier;
public readonly bool obscured;
public readonly bool synthesized;
public readonly float pressure;

3
engine/src/lib/ui/window/pointer_data.h


namespace uiwidgets {
static constexpr int kPointerDataFieldCount = 28;
static constexpr int kPointerDataFieldCount = 29;
static constexpr int kBytesPerField = sizeof(int64_t);
enum PointerButtonMouse : int64_t {

double physical_delta_x;
double physical_delta_y;
int64_t buttons;
int64_t modifier;
int64_t obscured;
int64_t synthesized;
double pressure;

1
engine/src/shell/platform/embedder/embedder.cc


// For backwards compatibility with embedders written before the device kind
// and buttons were exposed, if the device kind is not set treat it as a
// mouse, with a synthesized primary button state based on the phase.
pointer_data.modifier = current->modifier;
if (device_kind == 0) {
pointer_data.kind = PointerData::DeviceKind::kMouse;
pointer_data.buttons =

1
engine/src/shell/platform/embedder/embedder.h


float scroll_delta_y;
UIWidgetsPointerDeviceKind device_kind;
int64_t buttons;
int64_t modifier;
} UIWidgetsPointerEvent;
struct _UIWidgetsPlatformMessageResponseHandle;

8
engine/src/shell/platform/unity/android/uiwidgets_panel.cc


return PointerData::DeviceKind::kTouch;
}
void UIWidgetsPanel::OnKeyDown(int keyCode, bool isKeyDown)
void UIWidgetsPanel::OnKeyDown(int keyCode, bool isKeyDown, int64_t modifier)
{
if (process_events_)
{

std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch())
.count();
event.modifier = modifier;
UIWidgetsEngineSendPointerEvent(engine_, &event, 1);
}

}
UIWIDGETS_API(void)
UIWidgetsPanel_onKey(UIWidgetsPanel *panel, int keyCode, bool isKeyDown)
{
panel->OnKeyDown(keyCode, isKeyDown);
UIWidgetsPanel_onKey(UIWidgetsPanel* panel, int keyCode, bool isKeyDown, int64_t modifier) {
panel->OnKeyDown(keyCode, isKeyDown, modifier);
}
UIWIDGETS_API(void)

2
engine/src/shell/platform/unity/android/uiwidgets_panel.h


void VSyncCallback(intptr_t baton);
void OnKeyDown(int keyCode, bool isKeyDown);
void OnKeyDown(int keyCode, bool isKeyDown, int64_t modifier);
void OnMouseMove(float x, float y, int button);

2
engine/src/shell/platform/unity/darwin/ios/uiwidgets_panel.h


void SetEventLocationFromCursorPosition(UIWidgetsPointerEvent* event_data);
void OnKeyDown(int keyCode, bool isKeyDown);
void OnKeyDown(int keyCode, bool isKeyDown, int64_t modifier);
void OnMouseMove(float x, float y, int button);

7
engine/src/shell/platform/unity/darwin/ios/uiwidgets_panel.mm


return PointerData::DeviceKind::kTouch;
}
void UIWidgetsPanel::OnKeyDown(int keyCode, bool isKeyDown) {
void UIWidgetsPanel::OnKeyDown(int keyCode, bool isKeyDown, int64_t modifier) {
if (process_events_) {
UIWidgetsPointerEvent event = {};
event.phase = isKeyDown ? UIWidgetsPointerPhase::kMouseDown : UIWidgetsPointerPhase::kMouseUp;

std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch())
.count();
event.modifier = modifier;
UIWidgetsEngineSendPointerEvent(engine_, &event, 1);
}

UIWIDGETS_API(void)
UIWidgetsPanel_onKey(UIWidgetsPanel* panel, int keyCode, bool isKeyDown) {
panel->OnKeyDown(keyCode, isKeyDown);
UIWidgetsPanel_onKey(UIWidgetsPanel* panel, int keyCode, bool isKeyDown, int64_t modifier) {
panel->OnKeyDown(keyCode, isKeyDown, modifier);
}
UIWIDGETS_API(void)

2
engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.h


void SetEventLocationFromCursorPosition(UIWidgetsPointerEvent* event_data);
void OnKeyDown(int keyCode, bool isKeyDown);
void OnKeyDown(int keyCode, bool isKeyDown, int64_t modifier);
void OnMouseMove(float x, float y);

8
engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.mm


}
}
void UIWidgetsPanel::OnKeyDown(int keyCode, bool isKeyDown) {
void UIWidgetsPanel::OnKeyDown(int keyCode, bool isKeyDown, int64_t modifier) {
if (process_events_) {
UIWidgetsPointerEvent event = {};
event.phase = isKeyDown ? UIWidgetsPointerPhase::kMouseDown : UIWidgetsPointerPhase::kMouseUp;

std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch())
.count();
event.modifier = modifier;
UIWidgetsEngineSendPointerEvent(engine_, &event, 1);
}

UIWIDGETS_API(void)
UIWidgetsPanel_onKey(UIWidgetsPanel* panel, int keyCode, bool isKeyDown) {
panel->OnKeyDown(keyCode, isKeyDown);
UIWidgetsPanel_onKey(UIWidgetsPanel* panel, int keyCode, bool isKeyDown, int64_t modifier) {
panel->OnKeyDown(keyCode, isKeyDown, modifier);
}
UIWIDGETS_API(void)

7
engine/src/shell/platform/unity/windows/uiwidgets_panel.cc


}
}
void UIWidgetsPanel::OnKeyDown(int keyCode, bool isKeyDown) {
void UIWidgetsPanel::OnKeyDown(int keyCode, bool isKeyDown, int64_t modifier) {
if (process_events_) {
UIWidgetsPointerEvent event = {};
event.phase = isKeyDown ? UIWidgetsPointerPhase::kMouseDown : UIWidgetsPointerPhase::kMouseUp;

std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch())
.count();
event.modifier = modifier;
UIWidgetsEngineSendPointerEvent(engine_, &event, 1);
}

UIWIDGETS_API(void)
UIWidgetsPanel_onKey(UIWidgetsPanel* panel, int keyCode, bool isKeyDown) {
panel->OnKeyDown(keyCode, isKeyDown);
UIWidgetsPanel_onKey(UIWidgetsPanel* panel, int keyCode, bool isKeyDown, int64_t modifier) {
panel->OnKeyDown(keyCode, isKeyDown, modifier);
}
UIWIDGETS_API(void)

2
engine/src/shell/platform/unity/windows/uiwidgets_panel.h


void SetEventLocationFromCursorPosition(UIWidgetsPointerEvent* event_data);
void OnKeyDown(int keyCode, bool isKeyDown);
void OnKeyDown(int keyCode, bool isKeyDown, int64_t modifier);
void OnMouseMove(float x, float y);

部分文件因为文件数量过多而无法显示

正在加载...
取消
保存