Add mouse info to events
This commit is contained in:
parent
0d1d5c6490
commit
906bb498c6
|
@ -25,67 +25,67 @@ namespace Ooui
|
||||||
set => SetProperty (ref hidden, value, "hidden");
|
set => SetProperty (ref hidden, value, "hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler Clicked {
|
public event TargetEventHandler Clicked {
|
||||||
add => AddEventListener ("click", value);
|
add => AddEventListener ("click", value);
|
||||||
remove => RemoveEventListener ("click", value);
|
remove => RemoveEventListener ("click", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler DoubleClicked {
|
public event TargetEventHandler DoubleClicked {
|
||||||
add => AddEventListener ("dblclick", value);
|
add => AddEventListener ("dblclick", value);
|
||||||
remove => RemoveEventListener ("dblclick", value);
|
remove => RemoveEventListener ("dblclick", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler KeyDown {
|
public event TargetEventHandler KeyDown {
|
||||||
add => AddEventListener ("keydown", value);
|
add => AddEventListener ("keydown", value);
|
||||||
remove => RemoveEventListener ("keydown", value);
|
remove => RemoveEventListener ("keydown", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler KeyPressed {
|
public event TargetEventHandler KeyPressed {
|
||||||
add => AddEventListener ("keypress", value);
|
add => AddEventListener ("keypress", value);
|
||||||
remove => RemoveEventListener ("keypress", value);
|
remove => RemoveEventListener ("keypress", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler KeyUp {
|
public event TargetEventHandler KeyUp {
|
||||||
add => AddEventListener ("keyup", value);
|
add => AddEventListener ("keyup", value);
|
||||||
remove => RemoveEventListener ("keyup", value);
|
remove => RemoveEventListener ("keyup", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler MouseDown {
|
public event TargetEventHandler MouseDown {
|
||||||
add => AddEventListener ("mousedown", value);
|
add => AddEventListener ("mousedown", value);
|
||||||
remove => RemoveEventListener ("mousedown", value);
|
remove => RemoveEventListener ("mousedown", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler MouseEntered {
|
public event TargetEventHandler MouseEntered {
|
||||||
add => AddEventListener ("mouseenter", value);
|
add => AddEventListener ("mouseenter", value);
|
||||||
remove => RemoveEventListener ("mouseenter", value);
|
remove => RemoveEventListener ("mouseenter", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler MouseLeft {
|
public event TargetEventHandler MouseLeft {
|
||||||
add => AddEventListener ("mouseleave", value);
|
add => AddEventListener ("mouseleave", value);
|
||||||
remove => RemoveEventListener ("mouseleave", value);
|
remove => RemoveEventListener ("mouseleave", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler MouseMoved {
|
public event TargetEventHandler MouseMoved {
|
||||||
add => AddEventListener ("mousemove", value);
|
add => AddEventListener ("mousemove", value);
|
||||||
remove => RemoveEventListener ("mousemove", value);
|
remove => RemoveEventListener ("mousemove", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler MouseOut {
|
public event TargetEventHandler MouseOut {
|
||||||
add => AddEventListener ("mouseout", value);
|
add => AddEventListener ("mouseout", value);
|
||||||
remove => RemoveEventListener ("mouseout", value);
|
remove => RemoveEventListener ("mouseout", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler MouseOver {
|
public event TargetEventHandler MouseOver {
|
||||||
add => AddEventListener ("mouseover", value);
|
add => AddEventListener ("mouseover", value);
|
||||||
remove => RemoveEventListener ("mouseover", value);
|
remove => RemoveEventListener ("mouseover", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler MouseUp {
|
public event TargetEventHandler MouseUp {
|
||||||
add => AddEventListener ("mouseup", value);
|
add => AddEventListener ("mouseup", value);
|
||||||
remove => RemoveEventListener ("mouseup", value);
|
remove => RemoveEventListener ("mouseup", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler Wheeled {
|
public event TargetEventHandler Wheeled {
|
||||||
add => AddEventListener ("wheel", value);
|
add => AddEventListener ("wheel", value);
|
||||||
remove => RemoveEventListener ("wheel", value);
|
remove => RemoveEventListener ("wheel", value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ namespace Ooui
|
||||||
{
|
{
|
||||||
readonly List<Message> stateMessages = new List<Message> ();
|
readonly List<Message> stateMessages = new List<Message> ();
|
||||||
|
|
||||||
readonly Dictionary<string, List<EventHandler>> eventListeners =
|
readonly Dictionary<string, List<TargetEventHandler>> eventListeners =
|
||||||
new Dictionary<string, List<EventHandler>> ();
|
new Dictionary<string, List<TargetEventHandler>> ();
|
||||||
|
|
||||||
public string Id { get; private set; } = GenerateId ();
|
public string Id { get; private set; } = GenerateId ();
|
||||||
|
|
||||||
|
@ -45,17 +45,17 @@ namespace Ooui
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddEventListener (string eventType, EventHandler handler)
|
public void AddEventListener (string eventType, TargetEventHandler handler)
|
||||||
{
|
{
|
||||||
if (eventType == null) return;
|
if (eventType == null) return;
|
||||||
if (handler == null) return;
|
if (handler == null) return;
|
||||||
|
|
||||||
var sendListen = false;
|
var sendListen = false;
|
||||||
|
|
||||||
List<EventHandler> handlers;
|
List<TargetEventHandler> handlers;
|
||||||
lock (eventListeners) {
|
lock (eventListeners) {
|
||||||
if (!eventListeners.TryGetValue (eventType, out handlers)) {
|
if (!eventListeners.TryGetValue (eventType, out handlers)) {
|
||||||
handlers = new List<EventHandler> ();
|
handlers = new List<TargetEventHandler> ();
|
||||||
eventListeners[eventType] = handlers;
|
eventListeners[eventType] = handlers;
|
||||||
sendListen = true;
|
sendListen = true;
|
||||||
}
|
}
|
||||||
|
@ -70,12 +70,12 @@ namespace Ooui
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveEventListener (string eventType, EventHandler handler)
|
public void RemoveEventListener (string eventType, TargetEventHandler handler)
|
||||||
{
|
{
|
||||||
if (eventType == null) return;
|
if (eventType == null) return;
|
||||||
if (handler == null) return;
|
if (handler == null) return;
|
||||||
|
|
||||||
List<EventHandler> handlers;
|
List<TargetEventHandler> handlers;
|
||||||
lock (eventListeners) {
|
lock (eventListeners) {
|
||||||
if (eventListeners.TryGetValue (eventType, out handlers)) {
|
if (eventListeners.TryGetValue (eventType, out handlers)) {
|
||||||
handlers.Remove (handler);
|
handlers.Remove (handler);
|
||||||
|
@ -176,15 +176,19 @@ namespace Ooui
|
||||||
if (message.TargetId != Id)
|
if (message.TargetId != Id)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
List<EventHandler> handlers = null;
|
List<TargetEventHandler> handlers = null;
|
||||||
lock (eventListeners) {
|
lock (eventListeners) {
|
||||||
List<EventHandler> hs;
|
List<TargetEventHandler> hs;
|
||||||
if (eventListeners.TryGetValue (message.Key, out hs)) {
|
if (eventListeners.TryGetValue (message.Key, out hs)) {
|
||||||
handlers = new List<EventHandler> (hs);
|
handlers = new List<TargetEventHandler> (hs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (handlers != null) {
|
if (handlers != null) {
|
||||||
var args = EventArgs.Empty;
|
var args = new TargetEventArgs ();
|
||||||
|
if (message.Value is Newtonsoft.Json.Linq.JObject o) {
|
||||||
|
args.OffsetX = (double)o["offsetX"];
|
||||||
|
args.OffsetY = (double)o["offsetY"];
|
||||||
|
}
|
||||||
foreach (var h in handlers) {
|
foreach (var h in handlers) {
|
||||||
h.Invoke (this, args);
|
h.Invoke (this, args);
|
||||||
}
|
}
|
||||||
|
@ -212,4 +216,12 @@ namespace Ooui
|
||||||
return typeof (EventTarget).IsAssignableFrom (objectType);
|
return typeof (EventTarget).IsAssignableFrom (objectType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public delegate void TargetEventHandler (object sender, TargetEventArgs e);
|
||||||
|
|
||||||
|
public class TargetEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public double OffsetX { get; set; }
|
||||||
|
public double OffsetY { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,12 @@ namespace Ooui
|
||||||
set => SetProperty (ref action, value ?? "", "action");
|
set => SetProperty (ref action, value ?? "", "action");
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler Submitted {
|
public event TargetEventHandler Submitted {
|
||||||
add => AddEventListener ("submit", value);
|
add => AddEventListener ("submit", value);
|
||||||
remove => RemoveEventListener ("submit", value);
|
remove => RemoveEventListener ("submit", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler Reset {
|
public event TargetEventHandler Reset {
|
||||||
add => AddEventListener ("reset", value);
|
add => AddEventListener ("reset", value);
|
||||||
remove => RemoveEventListener ("reset", value);
|
remove => RemoveEventListener ("reset", value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,12 +30,12 @@ namespace Ooui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler Changed {
|
public event TargetEventHandler Changed {
|
||||||
add => AddEventListener ("change", value);
|
add => AddEventListener ("change", value);
|
||||||
remove => RemoveEventListener ("change", value);
|
remove => RemoveEventListener ("change", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler Inputted {
|
public event TargetEventHandler Inputted {
|
||||||
add => AddEventListener ("input", value);
|
add => AddEventListener ("input", value);
|
||||||
remove => RemoveEventListener ("input", value);
|
remove => RemoveEventListener ("input", value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace Ooui
|
||||||
set => SetProperty (ref val, value ?? "", "value");
|
set => SetProperty (ref val, value ?? "", "value");
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler Changed {
|
public event TargetEventHandler Changed {
|
||||||
add => AddEventListener ("change", value);
|
add => AddEventListener ("change", value);
|
||||||
remove => RemoveEventListener ("change", value);
|
remove => RemoveEventListener ("change", value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,12 @@ namespace Ooui
|
||||||
{
|
{
|
||||||
public class TextArea : FormControl
|
public class TextArea : FormControl
|
||||||
{
|
{
|
||||||
public event EventHandler Changed {
|
public event TargetEventHandler Changed {
|
||||||
add => AddEventListener ("change", value);
|
add => AddEventListener ("change", value);
|
||||||
remove => RemoveEventListener ("change", value);
|
remove => RemoveEventListener ("change", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler Inputted {
|
public event TargetEventHandler Inputted {
|
||||||
add => AddEventListener ("input", value);
|
add => AddEventListener ("input", value);
|
||||||
remove => RemoveEventListener ("input", value);
|
remove => RemoveEventListener ("input", value);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue