Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
WidgetInput.cs
浏览该文件的文档.
1using Engine;
3using Engine.Input;
5
6namespace Game {
7 public class WidgetInput {
8 public bool m_isCleared;
9
11
13
15
17
18 public double m_mouseDragTime;
19
21
23
24 public bool m_isMouseCursorVisible = true;
25
27
28 public int? m_touchId;
29
30 public bool m_touchCleared;
31
33
34 public double m_touchStartTime;
35
37
39
41
43
44 public double m_padDragTime;
45
47
48 public bool m_isPadCursorVisible = true;
49
51
52 public double m_vrDragTime;
53
54 public bool m_vrDragInProgress;
55
56 public bool m_isVrCursorVisible = true;
57
58 public bool Any { get; set; }
59
60 public bool Ok { get; set; }
61
62 public bool Cancel { get; set; }
63
64 public bool Back { get; set; }
65
66 public bool Left { get; set; }
67
68 public bool Right { get; set; }
69
70 public bool Up { get; set; }
71
72 public bool Down { get; set; }
73
74 public Vector2? Press { get; set; }
75
76 public Vector2? Tap { get; set; }
77
78 public Segment2? Click { get; set; }
79
80 public Segment2? SpecialClick { get; set; }
81
82 public Vector2? Drag { get; set; }
83
84 public DragMode DragMode { get; set; }
85
86 public Vector2? Hold { get; set; }
87
88 public float HoldTime { get; set; }
89
90 public Vector3? Scroll { get; set; }
91
92 public Key? LastKey {
93 get {
94 if (m_isCleared) {
95 return null;
96 }
97 if ((Devices & WidgetInputDevice.Keyboard) != 0) {
98 return Keyboard.LastKey;
99 }
100 for (int i = 0; i < 4; i++) {
101 if (((uint)Devices & (uint)(2 << i)) != 0) {
102 return MultiKeyboard.LastKey(i);
103 }
104 }
105 return null;
106 }
107 }
108
109 public char? LastChar {
110 get {
111 if (m_isCleared) {
112 return null;
113 }
114 if ((Devices & WidgetInputDevice.Keyboard) != 0) {
115 return Keyboard.LastChar;
116 }
117 for (int i = 0; i < 4; i++) {
118 if (((uint)Devices & (uint)(2 << i)) != 0) {
119 return MultiKeyboard.LastChar(i);
120 }
121 }
122 return null;
123 }
124 }
125
126 public bool UseSoftMouseCursor {
128 set => m_useSoftMouseCursor = value;
129 }
130
132 get {
133 if ((Devices & (WidgetInputDevice.MultiMice | WidgetInputDevice.Mouse)) == 0) {
134 return false;
135 }
137 }
138 set => m_isMouseCursorVisible = value;
139 }
140
142 get {
143 if (m_isCleared) {
144 return null;
145 }
146 if ((Devices & WidgetInputDevice.Mouse) != 0) {
149 }
150 if (!Mouse.MousePosition.HasValue) {
151 return null;
152 }
153 return new Vector2(Mouse.MousePosition.Value);
154 }
155 for (int i = 0; i < 4; i++) {
156 if (((uint)Devices & (uint)(64 << i)) != 0) {
159 }
160 return new Vector2(MultiMouse.MousePosition(i));
161 }
162 }
163 return null;
164 }
165 set {
166 Vector2 vector;
167 Vector2 vector2;
168 if (Widget != null) {
169 vector = Widget.GlobalBounds.Min;
170 vector2 = Widget.GlobalBounds.Max;
171 }
172 else {
173 vector = Vector2.Zero;
174 vector2 = new Vector2(Window.Size);
175 }
176 if ((Devices & WidgetInputDevice.Mouse) != WidgetInputDevice.None
177 && value.HasValue) {
180 Math.Clamp(value.Value.X, vector.X, vector2.X - 1f),
181 Math.Clamp(value.Value.Y, vector.Y, vector2.Y - 1f)
182 );
183 }
184 else {
185 Mouse.SetMousePosition((int)value.Value.X, (int)value.Value.Y);
186 }
187 return;
188 }
189 for (int i = 0; i < 4; i++) {
190 if (((uint)Devices & (uint)(64 << i)) != 0 && m_useSoftMouseCursor) {
192 Math.Clamp(value.Value.X, vector.X, vector2.X - 1f),
193 Math.Clamp(value.Value.Y, vector.Y, vector2.Y - 1f)
194 );
195 }
196 }
197 }
198 }
199
201 get {
202 if (!m_isCleared
203 && (Devices & WidgetInputDevice.Mouse) != 0) {
204 return Mouse.MouseMovement;
205 }
206 for (int i = 0; i < 4; i++) {
207 if (((uint)Devices & (uint)(64 << i)) != 0) {
208 return MultiMouse.MouseMovement(i);
209 }
210 }
211 return Point2.Zero;
212 }
213 }
214
216 get {
217 if (!m_isCleared
218 && (Devices & WidgetInputDevice.Mouse) != 0) {
220 }
221 for (int i = 0; i < 4; i++) {
222 if (((uint)Devices & (uint)(64 << i)) != 0) {
224 }
225 }
226 return 0;
227 }
228 }
229
230 public bool IsPadCursorVisible {
231 get {
233 if (((Devices & WidgetInputDevice.GamePad1) == 0 || !GamePad.IsConnected(0))
234 && ((Devices & WidgetInputDevice.GamePad2) == 0 || !GamePad.IsConnected(1))
235 && ((Devices & WidgetInputDevice.GamePad3) == 0 || !GamePad.IsConnected(2))) {
236 if ((Devices & WidgetInputDevice.GamePad4) != 0) {
237 return GamePad.IsConnected(3);
238 }
239 return false;
240 }
241 return true;
242 }
243 return false;
244 }
245 set => m_isPadCursorVisible = value;
246 }
247
249 get => m_padCursorPosition;
250 set {
251 Vector2 corner1;
252 Vector2 corner2;
253 if (Widget != null) {
254 corner1 = Widget.GlobalBounds.Min;
255 corner2 = Widget.GlobalBounds.Max;
256 }
257 else {
258 corner1 = Vector2.Zero;
259 corner2 = new Vector2(Window.Size);
260 }
261 value.X = Math.Clamp(value.X, corner1.X, corner2.X);
262 value.Y = Math.Clamp(value.Y, corner1.Y, corner2.Y);
263 m_padCursorPosition = value;
264 }
265 }
266
267 public ReadOnlyList<TouchLocation> TouchLocations {
268 get {
269 if (!m_isCleared
270 && (Devices & WidgetInputDevice.Touch) != 0) {
271 return Touch.TouchLocations;
272 }
273 return ReadOnlyList<TouchLocation>.Empty;
274 }
275 }
276
277 public Matrix? VrQuadMatrix { get; set; }
278
279 public bool IsVrCursorVisible {
280 get {
282 if ((Devices & WidgetInputDevice.VrControllers) != 0) {
283 return VrManager.IsVrStarted;
284 }
285 }
286 return false;
287 }
288 set => m_isVrCursorVisible = value;
289 }
290
291 public Vector2? VrCursorPosition { get; set; }
292
293 public static WidgetInput EmptyInput { get; } = new(WidgetInputDevice.None);
294
296
297 public WidgetInputDevice Devices { get; set; }
298
299 public bool IsKeyDown(Key key) {
300 if (m_isCleared) {
301 return false;
302 }
303 if ((Devices & WidgetInputDevice.Keyboard) != 0) {
304 return Keyboard.IsKeyDown(key);
305 }
306 for (int i = 0; i < 4; i++) {
307 if (((uint)Devices & (uint)(2 << i)) != 0) {
308 return MultiKeyboard.IsKeyDown(i, key);
309 }
310 }
311 return false;
312 }
313
314 public bool IsKeyDownOnce(Key key) {
315 if (m_isCleared) {
316 return false;
317 }
318 if ((Devices & WidgetInputDevice.Keyboard) != 0) {
319 return Keyboard.IsKeyDownOnce(key);
320 }
321 for (int i = 0; i < 4; i++) {
322 if (((uint)Devices & (uint)(2 << i)) != 0) {
323 return MultiKeyboard.IsKeyDownOnce(i, key);
324 }
325 }
326 return false;
327 }
328
329 public bool IsKeyDownRepeat(Key key) {
330 if (m_isCleared) {
331 return false;
332 }
333 if ((Devices & WidgetInputDevice.Keyboard) != 0) {
334 return Keyboard.IsKeyDownRepeat(key);
335 }
336 for (int i = 0; i < 4; i++) {
337 if (((uint)Devices & (uint)(2 << i)) != 0) {
338 return MultiKeyboard.IsKeyDownRepeat(i, key);
339 }
340 }
341 return false;
342 }
343
349 public bool IsKeyOrMouseDown(string mappingName) {
350 object key = SettingsManager.GetKeyboardMapping(mappingName);
351 if (key is MouseButton mouseButton) {
352 return IsMouseButtonDown(mouseButton);
353 }
354 if (key is Key key1
355 && key1 != Key.Null) {
356 return IsKeyDown(key1);
357 }
358 return false;
359 }
360
366 public bool IsKeyOrMouseDownOnce(string mappingName) {
367 object key = SettingsManager.GetKeyboardMapping(mappingName);
368 if (key is MouseButton mouseButton) {
369 return IsMouseButtonDownOnce(mouseButton);
370 }
371 if (key is Key key1
372 && key1 != Key.Null) {
373 return IsKeyDownOnce(key1);
374 }
375 return false;
376 }
377
383 public bool IsGamepadDown(string mappingName) {
384 object key = SettingsManager.GetGamepadMapping(mappingName);
385 if (key is GamePadTrigger trigger) {
387 }
388 if (key is GamePadButton button
389 && button != GamePadButton.Null) {
390 return IsPadButtonDown(button);
391 }
392 return false;
393 }
394
400 public bool IsGamepadDownOnce(string mappingName) {
401 //注意:组合键中行动键只能是GamePadButton,并且不能是肩键
403 object key = SettingsManager.GetGamepadMapping(mappingName);
404 if (key is GamePadTrigger trigger) {
405 return IsTriggerDownOnce(trigger, threshold);
406 }
407 if (key is GamePadButton button
408 && button != GamePadButton.Null
409 && (!IsAnyModifierKeyHolding() || GamePad.IsModifierKey(button))) { //当前没有按住修饰键,或者当前按下的就是修饰键(对于GamePadButton来说是左右肩键)
410 return IsPadButtonDownOnce(button);
411 }
412 if (key is ValuesDictionary combo) {
413 object modifier = combo.GetValue<object>("ModifierKey", null);
414 bool modifierHolding = false;
415 if (modifier is GamePadTrigger trigger1) {
416 modifierHolding = IsPadTriggerDown(trigger1, 0f, threshold);
417 }
418 else if (modifier is GamePadButton button1
419 && button1 != GamePadButton.Null) {
420 modifierHolding = IsPadButtonDown(button1);
421 }
422 if (modifierHolding) {
423 object action = combo.GetValue<object>("ActionKey", null);
424 if (action is GamePadButton button2
425 && button2 != GamePadButton.Null) {
426 bool flag = IsPadButtonDownOnce(button2);
427 if (flag) {
429 }
430 return flag;
431 }
432 }
433 }
434 return false;
435 }
436
437 public void EnterText(ContainerWidget parentWidget, string title, string text, int maxLength, Action<string> handler) {
439 title,
440 string.Empty,
441 text,
442 false,
443 delegate(string s) {
444 if (s.Length > maxLength) {
445 s = s.Substring(0, maxLength);
446 }
447 handler(s);
448 },
449 delegate { handler(null); }
450 );
451 }
452
453 public bool IsMouseButtonDown(MouseButton button) {
454 if (!m_isCleared
455 && (Devices & WidgetInputDevice.Mouse) != 0) {
456 return Mouse.IsMouseButtonDown(button);
457 }
458 for (int i = 0; i < 4; i++) {
459 if (((uint)Devices & (uint)(64 << i)) != 0) {
460 return MultiMouse.IsMouseButtonDown(i, button);
461 }
462 }
463 return false;
464 }
465
466 public bool IsMouseButtonDownOnce(MouseButton button) {
467 if (!m_isCleared
468 && (Devices & WidgetInputDevice.Mouse) != 0) {
469 return Mouse.IsMouseButtonDownOnce(button);
470 }
471 for (int i = 0; i < 4; i++) {
472 if (((uint)Devices & (uint)(64 << i)) != 0) {
473 return MultiMouse.IsMouseButtonDownOnce(i, button);
474 }
475 }
476 return false;
477 }
478
479 public Vector2 GetPadStickPosition(GamePadStick stick, float deadZone = 0f) {
480 if (m_isCleared) {
481 return Vector2.Zero;
482 }
483 Vector2 zero = Vector2.Zero;
484 for (int i = 0; i < 4; i++) {
485 if (((uint)Devices & (uint)(2048 << i)) != 0) {
486 zero += GamePad.GetStickPosition(i, stick, deadZone);
487 }
488 }
489 if (!(zero.LengthSquared() > 1f)) {
490 return zero;
491 }
492 return Vector2.Normalize(zero);
493 }
494
495 public float GetPadTriggerPosition(GamePadTrigger trigger, float deadZone = 0f) {
496 if (m_isCleared) {
497 return 0f;
498 }
499 float num = 0f;
500 for (int i = 0; i < 4; i++) {
501 if (((uint)Devices & (uint)(2048 << i)) != 0) {
502 num += GamePad.GetTriggerPosition(i, trigger, deadZone);
503 }
504 }
505 return MathUtils.Min(num, 1f);
506 }
507
508 public bool IsPadTriggerDown(GamePadTrigger trigger, float deadZone = 0f, float threshold = 0.5f) {
509 if (m_isCleared) {
510 return false;
511 }
512 for (int i = 0; i < 4; i++) {
513 if (((uint)Devices & (uint)(2048 << i)) != 0
514 && GamePad.IsTriggerDown(i, trigger, deadZone, threshold)) {
515 return true;
516 }
517 }
518 return false;
519 }
520
521 public bool IsTriggerDownOnce(GamePadTrigger trigger, float deadZone = 0f, float threshold = 0.5f) {
522 if (m_isCleared) {
523 return false;
524 }
525 for (int i = 0; i < 4; i++) {
526 if (((uint)Devices & (uint)(2048 << i)) != 0
527 && GamePad.IsTriggerDownOnce(i, trigger, deadZone, threshold)) {
528 return true;
529 }
530 }
531 return false;
532 }
533
534 public void SetModifierKeyOfCurrentCombo(object modifierKey) {
535 if (m_isCleared) {
536 return;
537 }
538 for (int i = 0; i < 4; i++) {
539 if (((uint)Devices & (uint)(2048 << i)) != 0) {
541 }
542 }
543 }
544
545 public bool IsPadButtonDown(GamePadButton button) {
546 if (m_isCleared) {
547 return false;
548 }
549 for (int i = 0; i < 4; i++) {
550 if (((uint)Devices & (uint)(2048 << i)) != 0
551 && GamePad.IsButtonDown(i, button)) {
552 return true;
553 }
554 }
555 return false;
556 }
557
558 public bool IsPadButtonDownOnce(GamePadButton button) {
559 if (m_isCleared) {
560 return false;
561 }
562 for (int i = 0; i < 4; i++) {
563 if (((uint)Devices & (uint)(2048 << i)) != 0
564 && GamePad.IsButtonDownOnce(i, button)) {
565 return true;
566 }
567 }
568 return false;
569 }
570
572 if (m_isCleared) {
573 return false;
574 }
575 for (int i = 0; i < 4; i++) {
576 if (((uint)Devices & (uint)(2048 << i)) != 0
577 && GamePad.IsButtonDownRepeat(i, button)) {
578 return true;
579 }
580 }
581 return false;
582 }
583
585 if (m_isCleared) {
586 return false;
587 }
588 for (int i = 0; i < 4; i++) {
589 if (((uint)Devices & (uint)(2048 << i)) != 0
591 //此处若使用SettingsManager.GamepadTriggerThreshold,恐与GamePad类中使用到IsAnyModifierKeyHolding的地方不一致。因为GamePad无法访问SettingsManager
592 return true;
593 }
594 }
595 return false;
596 }
597
603 //public void MakeGamePadVibration(float vibration,float durationMs)
604 //{
605 // for(int i = 0; i < 4; i++)
606 // {
607 // if(((uint)Devices & (uint)(2048 << i)) != 0)
608 // {
609 // GamePad.MakeVibration(i,vibration,durationMs);
610 // break;
611 // }
612 // }
613 //}
614
615 public Vector2 GetVrStickPosition(VrController controller, float deadZone = 0f) {
616 if (!m_isCleared
617 && (Devices & WidgetInputDevice.VrControllers) != 0) {
618 return VrManager.GetStickPosition(controller, deadZone);
619 }
620 return Vector2.Zero;
621 }
622
623 public Vector2? GetVrTouchpadPosition(VrController controller, float deadZone = 0f) {
624 if (!m_isCleared
625 && (Devices & WidgetInputDevice.VrControllers) != 0) {
626 return VrManager.GetTouchpadPosition(controller, deadZone);
627 }
628 return null;
629 }
630
631 public float GetVrTriggerPosition(VrController controller, float deadZone = 0f) {
632 if (!m_isCleared
633 && (Devices & WidgetInputDevice.VrControllers) != 0) {
634 return VrManager.GetTriggerPosition(controller, deadZone);
635 }
636 return 0f;
637 }
638
639 public bool IsVrButtonDown(VrController controller, VrControllerButton button) {
640 if (!m_isCleared
641 && (Devices & WidgetInputDevice.VrControllers) != 0) {
642 return VrManager.IsButtonDown(controller, button);
643 }
644 return false;
645 }
646
647 public bool IsVrButtonDownOnce(VrController controller, VrControllerButton button) {
648 if (!m_isCleared
649 && (Devices & WidgetInputDevice.VrControllers) != 0) {
650 return VrManager.IsButtonDownOnce(controller, button);
651 }
652 return false;
653 }
654
655 public WidgetInput(WidgetInputDevice devices = WidgetInputDevice.All) => Devices = devices;
656
657 public void Clear() {
658 m_isCleared = true;
659 m_mouseDownPoint = null;
660 m_mouseDragInProgress = false;
661 m_touchCleared = true;
662 m_padDownPoint = null;
663 m_padDragInProgress = false;
664 m_vrDownPoint = null;
665 m_vrDragInProgress = false;
666 ClearInput();
667 }
668
669 public virtual void Update() {
670 m_isCleared = false;
671 ClearInput();
672 if (Window.IsActive) {
673 if ((Devices & (WidgetInputDevice.MultiKeyboards | WidgetInputDevice.Keyboard)) != 0) {
675 }
676 if ((Devices & (WidgetInputDevice.MultiMice | WidgetInputDevice.Mouse)) != 0) {
678 }
679 if ((Devices & WidgetInputDevice.Gamepads) != 0) {
681 }
682 if ((Devices & WidgetInputDevice.Touch) != 0) {
684 }
685 }
686 }
687
688 public virtual void Draw(Widget.DrawContext dc) {
691 && MousePosition.HasValue) {
692 Texture2D texture2D = m_mouseDragInProgress ? ContentManager.Get<Texture2D>("Textures/Gui/PadCursorDrag") :
693 !m_mouseDownPoint.HasValue ? ContentManager.Get<Texture2D>("Textures/Gui/PadCursor") :
694 ContentManager.Get<Texture2D>("Textures/Gui/PadCursorDown");
695 TexturedBatch2D texturedBatch2D = dc.CursorPrimitivesRenderer2D.TexturedBatch(texture2D);
696 Vector2 corner;
697 Vector2 corner2 = (corner = Vector2.Transform(MousePosition.Value, Widget.InvertedGlobalTransform))
698 + new Vector2(texture2D.Width, texture2D.Height) * 0.8f;
699 int count = texturedBatch2D.TriangleVertices.Count;
700 texturedBatch2D.QueueQuad(corner, corner2, 0f, Vector2.Zero, Vector2.One, Color.White);
701 texturedBatch2D.TransformTriangles(Widget.GlobalTransform, count);
702 }
705 }
706 if (IsPadCursorVisible) {
707 Texture2D texture2D2 = m_padDragInProgress ? ContentManager.Get<Texture2D>("Textures/Gui/PadCursorDrag") :
708 !m_padDownPoint.HasValue ? ContentManager.Get<Texture2D>("Textures/Gui/PadCursor") :
709 ContentManager.Get<Texture2D>("Textures/Gui/PadCursorDown");
710 TexturedBatch2D texturedBatch2D2 = dc.CursorPrimitivesRenderer2D.TexturedBatch(texture2D2);
711 Vector2 corner3;
712 Vector2 corner4 = (corner3 = Vector2.Transform(PadCursorPosition, Widget.InvertedGlobalTransform))
713 + new Vector2(texture2D2.Width, texture2D2.Height) * 0.8f;
714 int count2 = texturedBatch2D2.TriangleVertices.Count;
715 texturedBatch2D2.QueueQuad(corner3, corner4, 0f, Vector2.Zero, Vector2.One, Color.White);
716 texturedBatch2D2.TransformTriangles(Widget.GlobalTransform, count2);
717 }
718 }
719
720 public void ClearInput() {
721 Any = false;
722 Ok = false;
723 Cancel = false;
724 Back = false;
725 Left = false;
726 Right = false;
727 Up = false;
728 Down = false;
729 Press = null;
730 Tap = null;
731 Click = null;
732 SpecialClick = null;
733 Drag = null;
734 DragMode = DragMode.AllItems;
735 Hold = null;
736 HoldTime = 0f;
737 Scroll = null;
738 }
739
740 public virtual void UpdateInputFromKeyboard() {
741 if (LastKey.HasValue
742 && LastKey != Key.Escape) {
743 Any = true;
744 }
745 if (IsKeyDownOnce(Key.Escape)) {
746 Back = true;
747 Cancel = true;
748 }
749 if (IsKeyDownRepeat(Key.LeftArrow)) {
750 Left = true;
751 }
752 if (IsKeyDownRepeat(Key.RightArrow)) {
753 Right = true;
754 }
755 if (IsKeyDownRepeat(Key.UpArrow)) {
756 Up = true;
757 }
758 if (IsKeyDownRepeat(Key.DownArrow)) {
759 Down = true;
760 }
761 if (IsKeyDownOnce(Key.Back)) {
762 Back = true;
763 }
764 }
765
766 public virtual void UpdateInputFromMouse() {
768 Any = true;
769 }
770 if (IsMouseCursorVisible && MousePosition.HasValue) {
771 Vector2 value = MousePosition.Value;
773 || IsMouseButtonDown(MouseButton.Right)) {
774 Press = value;
775 }
778 Tap = value;
779 m_mouseDownPoint = value;
782 }
784 && m_mouseDownPoint.HasValue
785 && m_mouseDownButton == MouseButton.Left) {
786 if (IsKeyDown(Key.Shift)) {
787 SpecialClick = new Segment2(m_mouseDownPoint.Value, value);
788 }
789 else {
790 Click = new Segment2(m_mouseDownPoint.Value, value);
791 }
792 }
794 && m_mouseDownPoint.HasValue
795 && m_mouseDownButton == MouseButton.Right) {
796 SpecialClick = new Segment2(m_mouseDownPoint.Value, value);
797 }
798 if (MouseWheelMovement != 0) {
799 Scroll = new Vector3(value, MouseWheelMovement / 120f);
800 }
801 if (m_mouseHoldInProgress && m_mouseDownPoint.HasValue) {
802 Hold = m_mouseDownPoint.Value;
804 }
806 Drag = value;
807 }
809 && m_mouseDownPoint.HasValue) {
813 Drag = m_mouseDownPoint.Value;
814 }
817 }
818 }
819 }
821 && !IsMouseButtonDown(MouseButton.Right)) {
822 m_mouseDragInProgress = false;
823 m_mouseHoldInProgress = false;
824 m_mouseDownPoint = null;
825 }
827 float x = 0.75f * MathUtils.PowSign(MouseMovement.X, 1.25f);
828 float y = 0.75f * MathUtils.PowSign(MouseMovement.Y, 1.25f);
830 }
831 }
832
833 public virtual void UpdateInputFromGamepads() {
834 if (IsPadButtonDownRepeat(GamePadButton.DPadLeft)) {
835 Left = true;
836 }
837 if (IsPadButtonDownRepeat(GamePadButton.DPadRight)) {
838 Right = true;
839 }
841 Up = true;
842 }
843 if (IsPadButtonDownRepeat(GamePadButton.DPadDown)) {
844 Down = true;
845 }
846 if (IsPadCursorVisible) {
849 }
850 if (IsPadButtonDownRepeat(GamePadButton.DPadDown)) {
851 Scroll = new Vector3(PadCursorPosition, -1f);
852 }
855 }
857 Ok = true;
861 }
863 && m_padDownPoint.HasValue) {
866 }
867 else {
869 }
870 }
871 }
876 Any = true;
877 }
879 m_padDragInProgress = false;
880 m_padDownPoint = null;
881 }
883 Cancel = true;
884 }
885 if (IsGamepadDownOnce("Back")) {
886 Back = true;
887 }
890 }
892 && m_padDownPoint.HasValue) {
894 m_padDragInProgress = true;
895 Drag = m_padDownPoint.Value;
896 DragMode = DragMode.AllItems;
897 }
899 Hold = m_padDownPoint.Value;
901 }
902 }
903 if (IsPadCursorVisible) {
904 Vector2 v = Vector2.Transform(PadCursorPosition, Widget.InvertedGlobalTransform);
906 Vector2 v2 = new(padStickPosition.X, 0f - padStickPosition.Y);
908 v += v2;
909 PadCursorPosition = Vector2.Transform(v, Widget.GlobalTransform);
910 }
911 }
912
913 public virtual void UpdateInputFromTouch() {
914 foreach (TouchLocation touchLocation in TouchLocations) {
915 if (touchLocation.State == TouchLocationState.Pressed) {
916 if (Widget.HitTest(touchLocation.Position)) {
917 Any = true;
918 Tap = touchLocation.Position;
919 Press = touchLocation.Position;
920 m_touchStartPoint = touchLocation.Position;
921 m_touchId = touchLocation.Id;
922 m_touchCleared = false;
924 m_touchDragInProgress = false;
925 m_touchHoldInProgress = false;
926 }
927 }
928 else if (touchLocation.State == TouchLocationState.Moved) {
929 if (m_touchId != touchLocation.Id) {
930 continue;
931 }
932 Press = touchLocation.Position;
933 if (m_touchCleared) {
934 continue;
935 }
937 Drag = touchLocation.Position;
938 }
939 else if (Vector2.Distance(touchLocation.Position, m_touchStartPoint) > SettingsManager.MinimumDragDistance * Widget.GlobalScale) {
942 }
947 }
950 }
951 }
952 }
953 else if (touchLocation.State == TouchLocationState.Released
954 && m_touchId == touchLocation.Id) {
955 if (!m_touchCleared) {
956 Click = new Segment2(m_touchStartPoint, touchLocation.Position);
957 }
958 m_touchId = null;
959 m_touchCleared = false;
960 m_touchDragInProgress = false;
961 m_touchHoldInProgress = false;
962 }
963 }
964 }
965 }
966}
Engine.Vector3 Vector3
static bool IsAnyModifierKeyHolding(int gamePadIndex, float threshold=0.5f)
static bool IsButtonDown(int gamePadIndex, GamePadButton button)
static bool IsTriggerDown(int gamePadIndex, GamePadTrigger trigger, float deadZone=0f, float threshold=0.5f)
static bool IsModifierKey(object obj)
static bool IsButtonDownRepeat(int gamePadIndex, GamePadButton button)
static Vector2 GetStickPosition(int gamePadIndex, GamePadStick stick, float deadZone=0f)
static float GetTriggerPosition(int gamePadIndex, GamePadTrigger trigger, float deadZone=0f)
static bool IsButtonDownOnce(int gamePadIndex, GamePadButton button)
static void SetModifierKeyOfCurrentCombo(int gamePadIndex, object modifierKey)
static bool IsConnected(int gamePadIndex)
static bool IsTriggerDownOnce(int gamePadIndex, GamePadTrigger trigger, float deadZone=0f, float threshold=0.5f)
static bool IsKeyDown(Key key)
static void ShowKeyboard(string title, string description, string defaultText, bool passwordMode, Action< string > enter, Action cancel)
static bool IsKeyDownRepeat(Key key)
static bool IsKeyDownOnce(Key key)
static ? Point2 MousePosition
static bool IsMouseButtonDownOnce(MouseButton mouseButton)
static int MouseWheelMovement
static void SetCursorType(CursorType cursorType)
static bool IsMouseButtonDown(MouseButton mouseButton)
static Point2 MouseMovement
static void SetMousePosition(int x, int y)
static ReadOnlyList< TouchLocation > TouchLocations
static int Min(int x1, int x2)
static float PowSign(float x, float n)
static float FrameDuration
定义 Time.cs:46
static double FrameStartTime
定义 Time.cs:42
static bool IsActive
static Point2 Size
static object Get(Type type, string name)
static object GetKeyboardMapping(string keyName, bool throwIfNotFound=true)
static float GamepadTriggerThreshold
手柄扳机触发阈值,范围0~1,默认0.5。扳机的按压幅度只有超过这个数时才会被视为“按下”状态,越小则越容易触发。
static object GetGamepadMapping(string keyName, bool throwIfNotFound=true)
static float GetTriggerPosition(VrController controller, float deadZone=0f)
static bool IsButtonDown(VrController controller, VrControllerButton button)
static ? Vector2 GetTouchpadPosition(VrController controller, float deadZone=0f)
static bool IsVrStarted
static bool IsButtonDownOnce(VrController controller, VrControllerButton button)
static Vector2 GetStickPosition(VrController controller, float deadZone=0f)
virtual void Draw(Widget.DrawContext dc)
virtual void Update()
MouseButton m_mouseDownButton
virtual void UpdateInputFromGamepads()
WidgetInput(WidgetInputDevice devices=WidgetInputDevice.All)
virtual void UpdateInputFromTouch()
bool IsMouseButtonDownOnce(MouseButton button)
virtual void UpdateInputFromKeyboard()
Vector2 GetPadStickPosition(GamePadStick stick, float deadZone=0f)
bool IsKeyDownRepeat(Key key)
bool IsKeyOrMouseDownOnce(string mappingName)
根据按键映射名称判断键盘鼠标按键是否按下
bool IsPadButtonDownRepeat(GamePadButton button)
ReadOnlyList< TouchLocation > TouchLocations
bool IsVrButtonDownOnce(VrController controller, VrControllerButton button)
Vector2 GetVrStickPosition(VrController controller, float deadZone=0f)
float GetVrTriggerPosition(VrController controller, float deadZone=0f)
Vector2 m_softMouseCursorPosition
static WidgetInput EmptyInput
void SetModifierKeyOfCurrentCombo(object modifierKey)
bool IsKeyDownOnce(Key key)
bool IsPadButtonDown(GamePadButton button)
bool IsGamepadDown(string mappingName)
根据按键映射名称判断手柄按键是否按住
float GetPadTriggerPosition(GamePadTrigger trigger, float deadZone=0f)
bool IsKeyOrMouseDown(string mappingName)
根据按键映射名称判断键盘鼠标按键是否按住
Vector2? GetVrTouchpadPosition(VrController controller, float deadZone=0f)
bool IsTriggerDownOnce(GamePadTrigger trigger, float deadZone=0f, float threshold=0.5f)
bool IsPadTriggerDown(GamePadTrigger trigger, float deadZone=0f, float threshold=0.5f)
bool IsGamepadDownOnce(string mappingName)
根据按键映射名称判断手柄按键是否按下
bool IsKeyDown(Key key)
virtual void UpdateInputFromMouse()
bool IsMouseButtonDown(MouseButton button)
WidgetInputDevice Devices
void EnterText(ContainerWidget parentWidget, string title, string text, int maxLength, Action< string > handler)
bool IsPadButtonDownOnce(GamePadButton button)
bool IsVrButtonDown(VrController controller, VrControllerButton button)
static bool IsKeyDownRepeat(int keyboardIndex, Key key)
static bool IsKeyDownOnce(int keyboardIndex, Key key)
static bool IsKeyDown(int keyboardIndex, Key key)
static ? char LastChar(int keyboardIndex)
static ? Key LastKey(int keyboardIndex)
static int MouseWheelMovement(int mouseIndex)
static bool IsMouseButtonDown(int mouseIndex, MouseButton mouseButton)
static Point2 MousePosition(int mouseIndex)
static Point2 MouseMovement(int mouseIndex)
static bool IsMouseButtonDownOnce(int mouseIndex, MouseButton mouseButton)
static Color White
static readonly Point2 Zero
static Vector2 Clamp(Vector2 v, float min, float max)
static readonly Vector2 Zero
static readonly Vector2 One
static Vector2 Transform(Vector2 v, Matrix m)
static Vector2 Normalize(Vector2 v)
float LengthSquared()
static float Distance(Vector2 v1, Vector2 v2)