-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonoGui.cs
137 lines (117 loc) · 5.02 KB
/
MonoGui.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace MonoGuiFramework
{
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Controls;
using MonoGuiFramework.System;
using MonoGuiFramework.Base;
public class MonoGui : IDisposable
{
public Graphics Graphics { get; private set; } = GraphicsSingleton.GetInstance();
public Input Input { get; private set; } = InputSingleton.GetInstance();
public List<Activity> Activities { get; private set; } = new List<Activity>();
public Activity ActivitySelected;
public event EventHandler UpdateEvent;
public event EventHandler Exit;
public event EventHandler Initialize;
public MonoGui()
{
int baseY = 0;
this.Input.ClickTouch += (s, e) => { foreach (Region item in this.ActivitySelected.Items) item.CheckEntry(e.X, e.Y); };
this.Input.ClickMouse += (s, e) => { foreach (Region item in this.ActivitySelected.Items) item.CheckEntry(e.X, e.Y); };
this.Input.PressedMouse += (s, e) => { baseY = (int)e.Y; /*foreach (Region item in this.ActivitySelected.Items) item.CheckEntryPressed(e.X, e.Y);*/ };
this.Input.PressedTouch += (s, e) => { baseY = (int)e.Y; /*foreach (Region item in this.ActivitySelected.Items) item.CheckEntryPressed(e.X, e.Y);*/ };
this.Input.BackKeyboard += delegate (Object sender, DeviceEventArgs e)
{
if ((this.ActivitySelected != null) && (this.ActivitySelected.Parent != null))
{
this.ActivitySelected.ChangeActivity(false);
this.ActivitySelected.Parent.ChangeActivity(true);
this.ActivitySelected = this.ActivitySelected.Parent;
}
else
{
if (this.Exit != null)
this.Exit(this, EventArgs.Empty);
}
};
this.Input.ScrollingMouse += delegate (Object sender, DeviceEventArgs e)
{
if (this.ActivitySelected != null)
{
float s = (float) (e.ScrollValue / 120 * 0.1);
foreach (Region item in this.ActivitySelected.Items) item.Scale += s;
}
};
this.Input.Swype += delegate (Object sender, DeviceEventArgs e)
{
var s = e.Swype;
if (s != TypeSwype.None)
{
if ((s == TypeSwype.Up) || (s == TypeSwype.Down))
{
//int scrollValue = (int) ((e.Y2 - e.Y) / 10);
//this.ActivitySelected.Scroll(scrollValue);
}
else
{
var slctActivity = this.ActivitySelected.Navigation[(int)s];
if (slctActivity != null)
{
this.ActivitySelected.ChangeActivity(false);
slctActivity.ChangeActivity(true);
this.ActivitySelected = slctActivity;
}
}
}
};
void ClickMoveEvent(object sender, DeviceEventArgs e)
{
if (this.ActivitySelected.Scrollable)
{
int dy = (int)(e.Y2 - baseY);
if (Math.Abs(dy) > 10)
{
this.ActivitySelected.Scroll(dy);
baseY = (int)e.Y2;
}
}
}
this.Input.ClickMoveMouse += ClickMoveEvent;
this.Input.ClickMoveTouch += ClickMoveEvent;
// MonoGame engine events
this.Graphics.DrawEvent += (s, e) => { if (this.ActivitySelected != null) { this.ActivitySelected.Draw(s as GameTime); } };
this.Graphics.UpdateEvent += delegate (object s, EventArgs e)
{
this.Input.Update();
if (this.ActivitySelected != null)
this.ActivitySelected.Update(s as GameTime);
if (this.UpdateEvent != null)
this.UpdateEvent(s, e);
};
// MonoGame Load content events
this.Graphics.LoadContentEvent += (s, e) =>
{
Resources.LoadResource();
this.Initialize?.Invoke(this, EventArgs.Empty);
};
}
public void Run()
{
this.Graphics.Run();
}
public void SelectActivity(String name)
{
var activity = this.Activities.FirstOrDefault((x) => x.Name.Equals(name));
if (activity != null)
this.ActivitySelected = activity;
}
public void Dispose() => this.Activities.ForEach(x => x.Dispose());
}
}