[NUI] Rotary Event (Custom Wheel Type) improvement
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / TouchGestureSample.cs
1 using Tizen.NUI;
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
4 using Tizen.NUI.Events;
5
6
7 namespace Tizen.NUI.Samples
8 {
9     public class TouchGestureSample : IExample
10     {
11         private View root;
12         private View frontView;
13         private TextLabel backView;
14         private TapGestureDetector tapGestureDetector;
15         private LongPressGestureDetector longPressGestureDetector;
16
17         public void Activate()
18         {
19             Window window = NUIApplication.GetDefaultWindow();
20             root = new View();
21
22             window.WheelEvent += (s, e) =>
23             {
24                 Tizen.Log.Error("NUI", $"window WheelEvent!!!!{e.Wheel.Type}\n");
25             };
26
27             frontView = new View
28             {
29                 Size = new Size(300, 300),
30                 Position = new Position(150, 170),
31                 BackgroundColor = new Color(1.0f, 0.0f, 0.0f, 1.0f),
32                 Focusable = true,
33                 FocusableInTouch = true,
34             };
35             frontView.TouchEvent += OnFrontTouchEvent;
36             frontView.WheelEvent += (s, e) =>
37             {
38                 Tizen.Log.Error("NUI", $"frontView WheelEvent!!!!{e.Wheel.Type}\n");
39                 if (e.Wheel.Type == Wheel.WheelType.CustomWheel)
40                 {
41                        // rotary event
42                 }
43                 else if (e.Wheel.Type == Wheel.WheelType.MouseWheel)
44                 {
45                       // mouse wheel event
46                 }
47                 return false;
48             };
49
50             var middleView = new View
51             {
52                 Size = new Size(300, 300),
53                 Position = new Position(110, 120),
54                 BackgroundColor = new Color(0.0f, 1.0f, 0.0f, 1.0f),
55                 Focusable = true,
56                 FocusableInTouch = true,
57             };
58
59
60             // The default the maximum allowed time is 500ms.
61             // If you want to change this time, do as below.
62             // But keep in mind this is a global option. Affects all gestures.
63             GestureOptions.Instance.SetDoubleTapTimeout(300);
64             tapGestureDetector = new TapGestureDetector();
65             tapGestureDetector.Attach(frontView);
66             tapGestureDetector.SetMaximumTapsRequired(2);
67             tapGestureDetector.Detected += (s, e) =>
68             {
69               Tizen.Log.Error("NUI", $"OnTap {e.TapGesture.NumberOfTaps}\n");
70             };
71
72             backView = new TextLabel
73             {
74                 Size = new Size(300, 300),
75                 Text = "Back View",
76                 Position = new Position(50, 70),
77                 PointSize = 11,
78                 BackgroundColor = new Color(1.0f, 1.0f, 0.0f, 1.0f),
79                 Focusable = true,
80                 FocusableInTouch = true,
81             };
82             backView.TouchEvent += OnBackTouchEvent;
83             backView.WheelEvent += (s, e) =>
84             {
85                 Tizen.Log.Error("NUI", $"backView WheelEvent!!!!{e.Wheel.Type}\n");
86                 return true;
87             };
88
89             // The default the minimum holding time is 500ms.
90             // If you want to change this time, do as below.
91             // But keep in mind this is a global option. Affects all gestures.
92             GestureOptions.Instance.SetLongPressMinimumHoldingTime(300);
93
94             longPressGestureDetector = new LongPressGestureDetector();
95             longPressGestureDetector.Attach(backView);
96             longPressGestureDetector.Detected += (s, e) =>
97             {
98               Tizen.Log.Error("NUI", $"OnLongPress\n");
99             };
100
101             backView.Add(middleView);
102             backView.Add(frontView);
103             root.Add(backView);
104             window.Add(root);
105         }
106
107         private bool OnFrontTouchEvent(object source, View.TouchEventArgs e)
108         {
109             Tizen.Log.Error("NUI", $"OnFrontTouchEvent {e.Touch.GetState(0)}\n");
110             return false;
111         }
112
113
114         private bool OnBackTouchEvent(object source, View.TouchEventArgs e)
115         {
116             Tizen.Log.Error("NUI", $"OnBackTouchEvent {e.Touch.GetState(0)}\n");
117             return false;
118         }
119
120         public void Deactivate()
121         {
122             if (root != null)
123             {
124                 NUIApplication.GetDefaultWindow().Remove(root);
125                 root.Dispose();
126             }
127         }
128     }
129 }