Jypeli 10
The simple game programming library
ListenContext.cs
Siirry tämän tiedoston dokumentaatioon.
1using System;
2using System.Collections.Generic;
3
4namespace Jypeli.Controls
5{
10 {
11 internal static ListenContext Null = new ListenContext() { Active = false };
12
13 private bool _active = false;
14
18 public bool Active
19 {
20 get
21 {
22 if ( destroyed ) return false;
23 if ( Parent != null && !Parent.Active ) return false;
24 return _active;
25 }
26
27 set
28 {
29 if ( value != _active )
30 {
31 _active = value;
32 if ( value && Activated != null ) Activated();
33 if ( !value && Deactivated != null ) Deactivated();
34 }
35 }
36 }
37
38 internal bool dynamicParent = false;
41
46 {
47 get
48 {
49 if ( dynamicParent && parentObject == null ) return null;
51 }
52 }
53
54 private Stack<bool> savedStates = null;
55
59 public event Action Activated;
60
64 public event Action Deactivated;
65
70 {
71 }
72
73 private ListenContext( ListenContext parent )
74 {
75 this.parentContext = parent;
76 }
77
78 private ListenContext( ControlContexted parentObj )
79 {
80 this.dynamicParent = true;
81 this.parentObject = parentObj;
82 }
83
89 {
90 return new ListenContext( this );
91 }
92
93 internal void SaveFocus()
94 {
95 if ( savedStates == null ) savedStates = new Stack<bool>();
96 savedStates.Push( Active );
97 }
98
99 internal void RestoreFocus()
100 {
101 if ( savedStates == null || savedStates.Count == 0 ) return;
102 Active = savedStates.Pop();
103 }
104
108 public void Enable() { Active = true; }
109
113 public void Disable() { Active = false; }
114
115 #region Destroyable Members
116
117 bool destroyed = false;
118
122 public bool IsDestroyed
123 {
124 get { return destroyed; }
125 }
126
130 public event Action Destroyed;
131
135 public void Destroy()
136 {
137 destroyed = true;
138 savedStates = null;
139 if ( Destroyed != null ) Destroyed();
140 }
141
142 #endregion
143 }
144
145 public interface ControlContexted
146 {
148 bool IsModal { get; }
149 }
150}
Kuuntelukonteksti ohjaimia varten
ListenContext? Parent
Kuuluuko tämä konteksti johonkin toiseen kontekstiin.
void Enable()
Aktivoi tämän ohjainkontekstin
Action Activated
Tapahtuu kun konteksti aktivoidaan.
Action Deactivated
Tapahtuu kun konteksti passivoidaan.
Action Destroyed
Ajetaan kun konteksti tuhotaan
bool Active
Onko tämä konteksti tällä hetkellä aktiivinen
void Destroy()
Tuhoaa kontekstin
static ListenContext Null
bool IsDestroyed
Onko konteksti tuhottu
ListenContext()
Muodostaa uuden ohjainkontekstin
ListenContext CreateSubcontext()
Muodostaa uuden ohjainkontekstin tämän lapseksi
ListenContext(ControlContexted parentObj)
void Disable()
Asettaa tämän ohjainkontekstin pois käytöstä.
ListenContext(ListenContext parent)
ControlContexted parentObject
Rajapinta olioille, jotka ovat tuhottavissa.
Definition: Destroyable.cs:9