Jypeli  9
The simple game programming library
Control.cs
Siirry tämän tiedoston dokumentaatioon.
1 using System.Collections.Generic;
2 using Jypeli.Controls;
3 
4 namespace Jypeli
5 {
6  public partial class Widget
7  {
9 
14  internal List<Listener> associatedListeners = new List<Listener>();
15 
16  public ListenContext ControlContext { get { return _context; } }
17 
22  public bool IsModal { get; set; }
23 
24  public bool CapturesMouse { get; protected set; }
25  public bool IsCapturingMouse
26  {
27  get
28  {
29  // A widget IsCapturingMouse if either:
30  // it CapturesMouse and is under the cursor
31  // or:
32  // one of its children IsCapturingMouse.
33 
34  if (CapturesMouse && Game.Mouse.IsCursorOn(this))
35  return true;
36 
37  foreach (var o in Objects)
38  {
39  if (o is Widget w && w.IsCapturingMouse)
40  return true;
41  }
42 
43  return false;
44  }
45  }
46 
47  public void InitControl()
48  {
49  if ( ControlContext == null || ControlContext.IsDestroyed )
50  _context = new Controls.ListenContext();
51 
52  Objects.ItemAdded += InitChildContext;
53  Objects.ItemRemoved += ResetChildContext;
54 
55  Removed += RemoveListeners;
56  }
57 
58  private void InitChildContext( GameObject child )
59  {
60  ControlContexted ctxChild = child as ControlContexted;
61  if ( ctxChild == null ) return;
62  ctxChild.ControlContext.dynamicParent = true;
63  ctxChild.ControlContext.parentObject = this;
64  }
65 
66  private void ResetChildContext( GameObject child )
67  {
68  ControlContexted ctxChild = child as ControlContexted;
69  if ( ctxChild == null ) return;
70  ctxChild.ControlContext.parentObject = null;
71  ctxChild.ControlContext.parentContext = null;
72  }
73 
74  private void RemoveListeners()
75  {
76  associatedListeners.ForEach(l => l.Destroy());
77  associatedListeners.Clear();
78  }
79  }
80 }
Jypeli.Controls.ControlContexted.ControlContext
ListenContext ControlContext
Definition: ListenContext.cs:116
Jypeli.Controls.ControlContexted
Definition: ListenContext.cs:115
Jypeli
Definition: Automobile.cs:5
Jypeli.Widget.IsModal
bool IsModal
Jos true, pelin sekä ikkunan alla olevien widgettien ohjaimet eivät ole käytössä kun ikkuna on näkyvi...
Definition: Control.cs:22
Jypeli.Controls.ListenContext.dynamicParent
bool dynamicParent
Definition: ListenContext.cs:33
Jypeli.Widget.IsCapturingMouse
bool IsCapturingMouse
Definition: Control.cs:26
Jypeli.Widget.InitChildContext
void InitChildContext(GameObject child)
Definition: Control.cs:58
Jypeli.Widget.RemoveListeners
void RemoveListeners()
Definition: Control.cs:74
Jypeli.Controls.ListenContext.parentContext
ListenContext parentContext
Definition: ListenContext.cs:34
Jypeli.Game.Mouse
Mouse Mouse
Hiiri.
Definition: Controls.cs:49
Jypeli.Controls.ListenContext.ListenContext
ListenContext()
Definition: ListenContext.cs:58
Jypeli.Controls.ListenContext.IsDestroyed
bool IsDestroyed
Definition: ListenContext.cs:98
Jypeli.Widget.InitControl
void InitControl()
Definition: Control.cs:47
Jypeli.Widget
Käyttöliittymän komponentti.
Definition: Appearance.cs:6
Jypeli.Controls.ListenContext.parentObject
ControlContexted parentObject
Definition: ListenContext.cs:35
Jypeli.Controls
Definition: Controller.cs:34
Jypeli.Widget.CapturesMouse
bool CapturesMouse
Definition: Control.cs:24
Jypeli.Widget.ControlContext
ListenContext ControlContext
Definition: Control.cs:16
Jypeli.Widget._context
ListenContext _context
Definition: Control.cs:8
System
Definition: CFFauxAttributes.cs:29
Jypeli.Widget.associatedListeners
List< Listener > associatedListeners
Tähän listaan lisätyt kuuntelijat tuhotaan automaattisesti kun Widget poistetaan pelistä.
Definition: Control.cs:14
Jypeli.Mouse.IsCursorOn
static bool IsCursorOn(ScreenView screen, MouseState state, GameObject obj)
Onko hiiren kursori annetun olion päällä.
Definition: Mouse.cs:320
Jypeli.GameObject
Pelialueella liikkuva olio. Käytä fysiikkapeleissä PhysicsObject-olioita.
Definition: Appearance.cs:34
Jypeli.Controls.ListenContext
Definition: ListenContext.cs:7
Jypeli.Game
Definition: Content.cs:46
Jypeli.Widget.ResetChildContext
void ResetChildContext(GameObject child)
Definition: Control.cs:66