Jypeli 10
The simple game programming library
TouchListener.cs
Siirry tämän tiedoston dokumentaatioon.
1using System;
2using System.Reflection;
3using Jypeli.Controls;
4
5namespace Jypeli
6{
10 public class TouchListener : Listener
11 {
12 private Predicate<Touch> isTriggered;
13 private Delegate handler;
14 private object[] handlerParams;
15 private bool isDestroyed;
16 private string _helpText;
17
18 private bool dynamicContext;
21
25 public string HelpText
26 {
27 get { return _helpText; }
28 set { _helpText = value; }
29 }
30
32 {
34 }
35
36 public TouchListener( Predicate<Touch> triggerRule, ListenContext context, string helpText, Delegate handler, params object[] args )
37 {
38 this.isDestroyed = false;
39 this.Destroyed = null;
40 this.isTriggered = triggerRule;
41 this.handler = handler;
42 this._helpText = helpText;
43 this.dynamicContext = false;
44 this.context = context;
45 this.contextedObject = null;
46
47 this.handlerParams = new object[args.Length + 1];
48
49 if ( args.Length > 0 )
50 {
51 Array.ConstrainedCopy( args, 0, handlerParams, 1, handlerParams.Length - 1 );
52 }
53 }
54
55 public TouchListener( Predicate<Touch> triggerRule, ControlContexted contexted, string helpText, Delegate handler, params object[] args )
56 {
57 this.isDestroyed = false;
58 this.Destroyed = null;
59 this.isTriggered = triggerRule;
60 this.handler = handler;
61 this._helpText = helpText;
62 this.dynamicContext = true;
63 this.context = null;
64 this.contextedObject = contexted;
65
66 this.handlerParams = new object[args.Length + 1];
67
68 if ( args.Length > 0 )
69 {
70 Array.ConstrainedCopy( args, 0, handlerParams, 1, handlerParams.Length - 1 );
71 }
72 }
73
79 {
80 this.dynamicContext = false;
81 this.context = context;
82 return this;
83 }
84
91 {
92 this.dynamicContext = true;
93 this.contextedObject = obj;
94 return this;
95 }
96
97 public void Invoke( Touch touch )
98 {
99#if WINDOWS_STOREAPP
100 // Win8
101 MethodInfo handlerMethod = handler.GetMethodInfo();
102#else
103 MethodInfo handlerMethod = handler.Method;
104#endif
105 handlerParams[0] = touch;
106 handlerMethod.Invoke( handler.Target, handlerParams );
107 }
108
109 public void CheckAndInvoke( Touch touch )
110 {
111 if ( !IsDestroyed && Context != null && !Context.IsDestroyed && Context.Active && isTriggered( touch ) )
112 Invoke( touch );
113 }
114
115 #region Destroyable Members
116
121 public bool IsDestroyed
122 {
123 get { return isDestroyed; }
124 }
125
126 public void Destroy()
127 {
128 isDestroyed = true;
129 OnDestroyed();
130 }
131
135 public event Action Destroyed;
136
137 private void OnDestroyed()
138 {
139 if ( Destroyed != null )
140 Destroyed();
141 }
142
143 #endregion
144 }
145}
Kuuntelukonteksti ohjaimia varten
bool Active
Onko tämä konteksti tällä hetkellä aktiivinen
bool IsDestroyed
Onko konteksti tuhottu
Kosketuspaneelin kosketus.
Definition: Touch.cs:39
Kuuntelija kosketusnäytölle.
Listener InContext(ControlContexted obj)
Kuuntelee tapahtumaa vain tietyssä kontekstissa. Esim. Keyboard.Listen(parametrit)....
TouchListener(Predicate< Touch > triggerRule, ListenContext context, string helpText, Delegate handler, params object[] args)
ListenContext context
Predicate< Touch > isTriggered
bool IsDestroyed
Onko olio tuhottu.
ListenContext? Context
void Destroy()
Tuhoaa kuuntelijan
void CheckAndInvoke(Touch touch)
ControlContexted contextedObject
TouchListener(Predicate< Touch > triggerRule, ControlContexted contexted, string helpText, Delegate handler, params object[] args)
string HelpText
Ohjeteksti.
void Invoke(Touch touch)
Action Destroyed
Tapahtuu, kun olio tuhotaan.
Listener InContext(ListenContext context)
Kuuntelee tapahtumaa vain tietyssä kontekstissa.
Ohjaintapahtumien kuuntelija.
Definition: Listener.cs:72
void Invoke()
Definition: Listener.cs:148