-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRaylibInput.cs
More file actions
127 lines (108 loc) · 3.75 KB
/
Copy pathRaylibInput.cs
File metadata and controls
127 lines (108 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using FishUI;
using Raylib_cs;
using System;
using System.Numerics;
using System.Collections.Generic;
namespace RaylibFishGfx
{
public class RaylibInput : IFishUIInput
{
private readonly Dictionary<int, Vector2> _previousTouches = new Dictionary<int, Vector2>();
public FishKey GetKeyPressed()
{
int K = Raylib.GetKeyPressed();
if (K == 0)
return FishKey.None;
return (FishKey)K;
}
public int GetCharPressed()
{
return Raylib.GetCharPressed();
}
public Vector2 GetMousePosition()
{
return Raylib.GetMousePosition();
}
public float GetMouseWheelMove()
{
return Raylib.GetMouseWheelMove();
}
public FishTouchPoint[] GetTouchPoints()
{
int count = Raylib.GetTouchPointCount();
if (count <= 0 && _previousTouches.Count == 0)
return System.Array.Empty<FishTouchPoint>();
var current = new Dictionary<int, Vector2>(Math.Max(0, count));
var points = new List<FishTouchPoint>(Math.Max(count, _previousTouches.Count));
for (int i = 0; i < count; i++)
{
int id = Raylib.GetTouchPointId(i);
Vector2 position = Raylib.GetTouchPosition(i);
current[id] = position;
bool existed = _previousTouches.TryGetValue(id, out Vector2 previous);
points.Add(new FishTouchPoint
{
Id = id,
Position = position,
Delta = existed ? position - previous : Vector2.Zero,
TouchType = existed ? FishTouchType.Motion : FishTouchType.Press
});
}
foreach (KeyValuePair<int, Vector2> previous in _previousTouches)
{
if (current.ContainsKey(previous.Key)) continue;
points.Add(new FishTouchPoint
{
Id = previous.Key,
Position = previous.Value,
Delta = Vector2.Zero,
TouchType = FishTouchType.Release
});
}
_previousTouches.Clear();
foreach (KeyValuePair<int, Vector2> touch in current)
_previousTouches.Add(touch.Key, touch.Value);
return points.Count == 0 ? System.Array.Empty<FishTouchPoint>() : points.ToArray();
}
public bool IsKeyDown(FishKey Key)
{
return Raylib.IsKeyDown((KeyboardKey)Key);
}
public bool IsKeyPressed(FishKey Key)
{
return Raylib.IsKeyPressed((KeyboardKey)Key);
}
public bool IsKeyReleased(FishKey Key)
{
return Raylib.IsKeyReleased((KeyboardKey)Key);
}
public bool IsKeyUp(FishKey Key)
{
return Raylib.IsKeyUp((KeyboardKey)Key);
}
public bool IsMouseDown(FishMouseButton Button)
{
return Raylib.IsMouseButtonDown((MouseButton)Button);
}
public bool IsMousePressed(FishMouseButton Button)
{
return Raylib.IsMouseButtonPressed((MouseButton)Button);
}
public bool IsMouseReleased(FishMouseButton Button)
{
return Raylib.IsMouseButtonReleased((MouseButton)Button);
}
public bool IsMouseUp(FishMouseButton Button)
{
return Raylib.IsMouseButtonUp((MouseButton)Button);
}
public string GetClipboardText()
{
return Raylib.GetClipboardText_();
}
public void SetClipboardText(string text)
{
Raylib.SetClipboardText(text ?? "");
}
}
}