/// <summary> /// Initializes a new instance of the <see cref="T:OregonTrailDotNet.Module.Director.EventFactory" /> class. /// </summary> public EventFactory() { // Create dictionaries for storing event reference types, history of execution, and execution count. EventReference = new Dictionary<EventKey, Type>(); // Collect all of the event types with the attribute decorated on them. var randomEvents = AttributeExtensions.GetTypesWith<DirectorEventAttribute>(true); foreach (var eventObject in randomEvents) { // Check if the class is abstract base class, we don't want to add that. if (eventObject.GetTypeInfo().IsAbstract) continue; // Check the attribute itself from the event we are working on, which gives us the event type enum. var eventAttribute = eventObject.GetTypeInfo().GetAttributes<DirectorEventAttribute>(true).First(); var eventType = eventAttribute.EventCategory; // Initialize the execution history dictionary with every event type. foreach (var modeType in Enum.GetValues(typeof(EventCategory))) { // Only proceed if enum value matches attribute enum value for event type. if (!modeType.Equals(eventType)) continue; // Create key for the event execution counter. var eventKey = new EventKey((EventCategory) modeType, eventObject.Name, eventAttribute.EventExecutionType); // Reference type for creating instances. if (!EventReference.ContainsKey(eventKey)) EventReference.Add(eventKey, eventObject); } } }
// Adds an EventKey -> Delegate mapping if it doesn't exist or // combines a delegate to an existing EventKey public void Add(EventKey eventKey, Delegate handler) { Monitor.Enter(m_events); Delegate d; m_events.TryGetValue(eventKey, out d); m_events[eventKey] = Delegate.Combine(d, handler); Monitor.Exit(m_events); }
public void Add(EventKey key, Delegate handler) { Monitor.Enter(eventSet); if (!eventSet.ContainsKey(key)) eventSet.Add(key, handler); Monitor.Exit(eventSet); }
public void SameFrameReceiveAsync() { var test = new EventSystemTest(); var frameCounter = 0; test.AddTask(async () => { while (test.IsRunning) { frameCounter++; await test.NextFrame(); } }, 100); test.AddTask(async () => { var key = new EventKey(); var recv = new EventReceiver(key); key.Broadcast(); var currentFrame = frameCounter; await recv.ReceiveAsync(); Assert.AreEqual(currentFrame, frameCounter); test.Exit(); }); test.Run(); }
// Adds an EventKey -> Delegate mapping if it doesn't exist or // combines a delegate to an existing EventKey public void Add(EventKey eventKey, Delegate handler) { lock (m_events) { Delegate d; m_events.TryGetValue(eventKey, out d); m_events[eventKey] = Delegate.Combine(d, handler); } }
// 添加事件映射,组合存在的代理 public void Add(EventKey kEventKey, Delegate kHandler) { lock (mEventDict) { Delegate kTemp; mEventDict.TryGetValue(kEventKey, out kTemp); mEventDict[kEventKey] = Delegate.Combine(kTemp, kHandler); } }
public Event FindEvent(EventKey key) { Type type = FindType(key); Event member = type.FindEvent(key); if (member == null) { member = type.AddEvent(key); } return member; }
public Delegate this[EventKey eventKey] { get { if (this.m_events.ContainsKey(eventKey)) { return this.m_events[eventKey]; } return null; } }
public void SameFrameReceive() { var key = new EventKey(); var recv = new EventReceiver(key); key.Broadcast(); Assert.True(recv.TryReceive()); Assert.False(recv.TryReceive()); }
public void Raise(EventKey evenetkey, Object sender, EventArgs e) { Delegate d; Monitor.Enter(m_events); m_events.TryGetValue(evenetkey, out d); Monitor.Exit(m_events); if (d != null) { d.DynamicInvoke(new Object[] {sender,e}); } }
// 触发事件 public void Raise(EventKey kEventKey, Object kSender, EventArgs kArg) { Delegate kHandler; lock (mEventDict) { mEventDict.TryGetValue(kEventKey, out kHandler); } if (kHandler != null) kHandler.DynamicInvoke(new Object[] { kSender, kArg }); }
public void Add(EventKey eventKey, Delegate handler) { Monitor.Enter(_events); Delegate currentHandler; _events.TryGetValue(eventKey, out currentHandler); _events[eventKey] = Delegate.Combine(currentHandler, handler); Monitor.Exit(_events); }
public void Remove(EventKey eventKey, Delegate handler) { Monitor.Enter(m_events); Delegate d; if (m_events.TryGetValue(eventKey, out d)) { d = Delegate.Remove(d, handler); } if (d != null) m_events[eventKey] = d; else m_events.Remove(eventKey); m_events[eventKey] = Delegate.Combine(d, handler); Monitor.Exit(m_events); }
public void Raise(EventKey key, Object sender, DictionaryEventArgs e) { Monitor.Enter(eventSet); Delegate d; eventSet.TryGetValue(key, out d); try { if(d!=null) d.DynamicInvoke(new object[] {this, e}); } catch (Exception ex) { } Monitor.Exit(eventSet); }
// Removes a delegate from an EventKey (if it exists) and // removes the EventKey -> Delegate mapping the last delegate is removed public void Remove(EventKey eventKey, Delegate handler) { Monitor.Enter(m_events); // Call TryGetValue to ensure that an exception is not thrown if // attempting to remove a delegate from an EventKey not in the set Delegate d; if (m_events.TryGetValue(eventKey, out d)) { d = Delegate.Remove(d, handler); // If a delegate remains, set the new head else remove the EventKey if (d != null) m_events[eventKey] = d; else m_events.Remove(eventKey); } Monitor.Exit(m_events); }
static Delegate GetHandler(Type componentType, EventInfo eventInfo) { var handlerType = eventInfo.EventHandlerType; var eventName = eventInfo.Name; var key = new EventKey(componentType, handlerType, eventName); var handler = (Delegate)null; if (!_eventHandlers.TryGetValue(key, out handler)) { var parameters = handlerType.GetMethod("Invoke") .GetParameters() .Select(p => Expression.Parameter(p.ParameterType, p.Name)) .ToArray(); var formatStringBuilder = new StringBuilder(); formatStringBuilder.AppendFormat( "<b>{0}[</b><color=navy>{{0}}</color><b>]</b>.<color=purple>{1}</color>", componentType.Name, eventName); if (parameters.Length > 0) { formatStringBuilder.Append(": "); } for (int i = 0; i < parameters.Length; ++i) { formatStringBuilder.AppendFormat( "[<color=blue>{0} = {{{1}}}</color>] ", parameters[i].Name, i + 1); } var method = typeof(EventLogger).GetMethod("LogFormat", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(string), typeof(string), typeof(object[]) }, null); var nameArg = Expression.Parameter(typeof(string), "gameObjectName"); var lambda = Expression.Lambda( Expression.Lambda(handlerType, Expression.Call(method, Expression.Constant(formatStringBuilder.ToString()), nameArg, Expression.NewArrayInit(typeof(object), parameters.Select(p => Expression.Convert(p, typeof(object))).ToArray())), parameters), nameArg); handler = lambda.Compile(); _eventHandlers[key] = handler; } return handler; }
public void Raise(EventKey eventKey, object sender, EventArgs e) { Delegate currentHandler; Monitor.Enter(_events); _events.TryGetValue(eventKey, out currentHandler); Monitor.Exit(_events); if (currentHandler == null) { return; } currentHandler.DynamicInvoke(sender, e); }
// Removes a delegate from an EventKey (if it exists) and // removes the EventKey -> Delegate mapping the last delegate is removed public void Remove(EventKey eventKey, Delegate handler) { lock (m_events) { // Do not throw an exception if attempting to remove // a delegate from an EventKey not in the set Delegate d; if (m_events.TryGetValue(eventKey, out d)) { d = Delegate.Remove(d, handler); // If a delegate remains, set the new head else remove the EventKey if (d != null) m_events[eventKey] = d; else m_events.Remove(eventKey); } } }
// Raies the event for the indicated EventKey public void Raise(EventKey eventKey, Object sender, EventArgs e) { // Don't throw an exception if the EventKey is not in the set Delegate d; lock (m_events) { m_events.TryGetValue(eventKey, out d); } if (d != null) { // Because the dictionary can contain several different delegate types, // it is impossible to construct a type-safe call to the delegate at // compile time. So, I call the System.Delegate type’s DynamicInvoke // method, passing it the callback method’s parameters as an array of // objects. Internally, DynamicInvoke will check the type safety of the // parameters with the callback method being called and call the method. // If there is a type mismatch, then DynamicInvoke will throw an exception. d.DynamicInvoke(sender, e); } }
public void Remove(EventKey eventKey, Delegate handler) { Monitor.Enter(_events); Delegate currentHandler; if (_events.TryGetValue(eventKey, out currentHandler)) { Delegate newHandler = Delegate.Remove(currentHandler, handler); if (newHandler == null) { _events.Remove(eventKey); } else { _events[eventKey] = newHandler; } } Monitor.Exit(_events); }
protected override bool OnKeyPressEvent(EventKey evnt) { // Console.WriteLine (evnt.Key); return(base.OnKeyPressEvent(evnt)); }
protected override bool OnKeyReleaseEvent(EventKey evnt) => ProcessKeyEvent(evnt);
public void EveryFrameClear() { var game = new EventSystemTest(); var frameCount = 0; var evt = new EventKey(); game.AddTask(async () => { while (frameCount < 25) { evt.Broadcast(); evt.Broadcast(); await game.NextFrame(); } }, 10); game.AddTask(async () => { var rcv = new EventReceiver(evt, EventReceiverOptions.Buffered); while (frameCount < 25) { if (frameCount == 20) { var manyEvents = rcv.TryReceiveAll(); Assert.AreEqual(2, manyEvents); game.Exit(); } rcv.Reset(); await game.NextFrame(); frameCount++; } }, -10); game.Run(); }
public void Unregister <T>(EventKey InEventKey, Action <T> InAction) { Unregister(InEventKey, InAction, EventDelegateType.One); }
protected override bool OnKeyPressEvent(EventKey evnt) { int focus_old = FocusCell; bool shift = ModifierType.ShiftMask == (evnt.State & ModifierType.ShiftMask); bool control = ModifierType.ControlMask == (evnt.State & ModifierType.ControlMask); switch (evnt.Key) { case Gdk.Key.Down: case Gdk.Key.J: case Gdk.Key.j: FocusCell += VisibleColums; break; case Gdk.Key.Left: case Gdk.Key.H: case Gdk.Key.h: if (control && shift) { FocusCell -= FocusCell % VisibleColums; } else { FocusCell--; } break; case Gdk.Key.Right: case Gdk.Key.L: case Gdk.Key.l: if (control && shift) { FocusCell += VisibleColums - (FocusCell % VisibleColums) - 1; } else { FocusCell++; } break; case Gdk.Key.Up: case Gdk.Key.K: case Gdk.Key.k: FocusCell -= VisibleColums; break; case Gdk.Key.Page_Up: FocusCell -= VisibleColums * VisibleRows; break; case Gdk.Key.Page_Down: FocusCell += VisibleColums * VisibleRows; break; case Gdk.Key.Home: FocusCell = 0; break; case Gdk.Key.End: FocusCell = Collection.Count - 1; break; case Gdk.Key.R: case Gdk.Key.r: FocusCell = new Random().Next(0, Collection.Count - 1); break; case Gdk.Key.space: Selection.ToggleCell(FocusCell); break; case Gdk.Key.Return: if (DoubleClicked != null) { DoubleClicked(this, new BrowsableEventArgs(FocusCell, null)); } break; default: return(false); } if (shift) { if (focus_old != FocusCell && Selection.Contains(focus_old) && Selection.Contains(FocusCell)) { Selection.Remove(FocusCell, focus_old); } else { Selection.Add(focus_old, FocusCell); } } else if (!control) { Selection.Clear(); Selection.Add(FocusCell); } ScrollTo(FocusCell); return(true); }
public virtual bool KeyPressed(CircuitEditor editor, EventKey eventKey) => false;
public void Register <T, T1, T2, T3>(EventKey InEventKey, Action <T, T1, T2, T3> InAction, bool InIsSingleTime = false) { Register(InEventKey, EventDelegate.Register(InAction, InIsSingleTime)); }
public StandardSendIntAndStringEvent(GameObject sender, int myInt, string myString, EventKey key) { _sender = sender; _key = key; MyInt = myInt; MyString = myString; }
/// <summary> /// Called on KeyPress event. /// </summary> /// <param name="e">An instance that contains the event data.</param> /// <returns>True if event was handled?</returns> protected override bool OnKeyPressEvent(EventKey e) { return(this.ActualController.HandleKeyDown(this, e.ToKeyEventArgs())); }
public void DifferentThreadBroadcast() { var game = new EventSystemTest(); var counter = 0; var broadcaster = new EventKey(); var readyCount = 0; game.AddTask(async() => { var recv = new EventReceiver(broadcaster, EventReceiverOptions.Buffered); Interlocked.Increment(ref readyCount); for (;;) { await recv.ReceiveAsync(); Interlocked.Increment(ref counter); } }); game.AddTask(async() => { var recv = new EventReceiver(broadcaster, EventReceiverOptions.Buffered); Interlocked.Increment(ref readyCount); for (;;) { await recv.ReceiveAsync(); Interlocked.Increment(ref counter); } }); game.AddTask(async() => { var recv = new EventReceiver(broadcaster, EventReceiverOptions.Buffered); Interlocked.Increment(ref readyCount); for (;;) { await recv.ReceiveAsync(); Interlocked.Increment(ref counter); } }); var t1W = new AutoResetEvent(false); var t2W = new AutoResetEvent(false); var waitHandles = new WaitHandle[] { t1W, t2W }; Exception threadException = null; new Thread(() => { try { while (!game.IsRunning && readyCount < 3) { Thread.Sleep(200); } var frameCounter = 0; while (true) { Thread.Sleep(50); frameCounter++; broadcaster.Broadcast(); if (frameCounter < 200) { continue; } t1W.Set(); return; } } catch (Exception e) { threadException = e; } }).Start(); new Thread(() => { try { while (!game.IsRunning && readyCount < 3) { Thread.Sleep(200); } var frameCounter = 0; while (true) { Thread.Sleep(50); frameCounter++; broadcaster.Broadcast(); if (frameCounter < 200) { continue; } t2W.Set(); return; } } catch (Exception e) { threadException = e; } }).Start(); new Thread(() => { try { //wait until both threads have broadcasted 200 times each WaitHandle.WaitAll(waitHandles); Thread.Sleep(2000); game.Exit(); } catch (Exception e) { threadException = e; } }).Start(); game.Run(); Assert.IsNull(threadException); Assert.AreEqual(1200, counter); }
public void DifferentSyntax() { var game = new EventSystemTest(); var frameCounter = 0; var broadcaster = new EventKey(); game.AddTask(async() => { var tests = 5; var recv = new EventReceiver(broadcaster); var threadId = Thread.CurrentThread.ManagedThreadId; while (tests-- > 0) { await recv; Assert.AreEqual(threadId, Thread.CurrentThread.ManagedThreadId); } }); game.AddTask(async() => { var tests = 5; var recv = new EventReceiver(broadcaster); var threadId = Thread.CurrentThread.ManagedThreadId; while (tests-- > 0) { await recv; Assert.AreEqual(threadId, Thread.CurrentThread.ManagedThreadId); } }); game.AddTask(async() => { var tests = 5; var recv = new EventReceiver(broadcaster); var threadId = Thread.CurrentThread.ManagedThreadId; while (tests-- > 0) { await recv; Assert.AreEqual(threadId, Thread.CurrentThread.ManagedThreadId); } }); Task.Run(async() => { while (!game.IsRunning) { await Task.Delay(100); } while (true) { frameCounter++; broadcaster.Broadcast(); if (frameCounter == 20) { game.Exit(); } await Task.Delay(50); } }); game.Run(); }
public void Unregister <T, T1, T2, T3>(EventKey InEventKey, Action <T, T1, T2, T3> InAction) { Unregister(InEventKey, InAction, EventDelegateType.Four); }
public void Unregister <T, T1, T2>(EventKey InEventKey, Action <T, T1, T2> InAction) { Unregister(InEventKey, InAction, EventDelegateType.Three); }
public void Unregister <T, T1>(EventKey InEventKey, Action <T, T1> InAction) { Unregister(InEventKey, InAction, EventDelegateType.Two); }
protected override bool OnKeyPressEvent(EventKey evnt) { if ((evnt.State & (ModifierType.Mod1Mask | ModifierType.ControlMask)) != 0) { return(base.OnKeyPressEvent(evnt)); } bool handled = true; int x, y; Gdk.ModifierType type; switch (evnt.Key) { case Gdk.Key.Up: case Gdk.Key.KP_Up: case Gdk.Key.k: case Gdk.Key.K: ScrollBy(0, -Vadjustment.StepIncrement); break; case Gdk.Key.Down: case Gdk.Key.KP_Down: case Gdk.Key.j: case Gdk.Key.J: ScrollBy(0, Vadjustment.StepIncrement); break; case Gdk.Key.Left: case Gdk.Key.KP_Left: case Gdk.Key.h: case Gdk.Key.H: ScrollBy(-Hadjustment.StepIncrement, 0); break; case Gdk.Key.Right: case Gdk.Key.KP_Right: case Gdk.Key.l: case Gdk.Key.L: ScrollBy(Hadjustment.StepIncrement, 0); break; case Gdk.Key.equal: case Gdk.Key.plus: case Gdk.Key.KP_Add: ZoomIn(); break; case Gdk.Key.minus: case Gdk.Key.KP_Subtract: ZoomOut(); break; case Gdk.Key.Key_0: case Gdk.Key.KP_0: ZoomFit(); break; case Gdk.Key.KP_1: case Gdk.Key.Key_1: GdkWindow.GetPointer(out x, out y, out type); DoZoom(1.0, x, y); break; case Gdk.Key.Key_2: case Gdk.Key.KP_2: GdkWindow.GetPointer(out x, out y, out type); DoZoom(2.0, x, y); break; default: handled = false; break; } return(handled || base.OnKeyPressEvent(evnt)); }
// 触发事件(虚函数继承,继承自IEventService) public virtual void FireEvent(EventKey kKey, Object kSender, EventArgs kArg) { mEventSet.Raise(kKey, kSender, kArg); }
protected override bool OnKeyPressEvent(EventKey evnt) { if (evnt.Key == Gdk.Key.Up) { do { int selected = GetSelected() - 1; if (selected < 0) { selected = NumberItems() - 1; } UpdateSelected(selected); } while (GetSelectedItem().item.Disabled); } else if (evnt.Key == Gdk.Key.Down) { do { int selected = GetSelected() + 1; if (selected > NumberItems() - 1) { selected = 0; } UpdateSelected(selected); } while (GetSelectedItem().item.Disabled); } else if (evnt.Key == Gdk.Key.Return && GetSelectedItem() != null) { MenuItem item = (GetSelectedItem() as MenuItemWidget).item; if (!item.Disabled) { item.SendClick(); Hide(); } } else if (evnt.Key == Gdk.Key.Escape) { Hide(); } else { foreach (Gtk.Widget widget in (Container.Child as VBox).Children) { if (widget is MenuItemWidget) { MenuItem item = (widget as MenuItemWidget).item; if (evnt.KeyValue == item.Mnemonic) { if (!item.Disabled) { item.SendClick(); Hide(); } } } } } return(base.OnKeyPressEvent(evnt)); }
// 反注册事件(虚函数继承,继承自IEventService) public virtual void UnregisterEvent(EventKey kKey, EventHandler kEvent) { mEventSet.Remove(kKey, kEvent); }
protected override bool OnKeyPressEvent(EventKey evnt) { bool shift = ModifierType.ShiftMask == (evnt.State & ModifierType.ShiftMask); bool control = ModifierType.ControlMask == (evnt.State & ModifierType.ControlMask); switch (evnt.Key) { case Gdk.Key.Down: case Gdk.Key.J: case Gdk.Key.j: Pointer.Index = Math.Min(Pointer.Collection.Count - 1, Pointer.Index + VisibleColums); break; case Gdk.Key.Left: case Gdk.Key.H: case Gdk.Key.h: if (control && shift) { Pointer.Index -= Pointer.Index % VisibleColums; } else { Pointer.MovePrevious(); } break; case Gdk.Key.Right: case Gdk.Key.L: case Gdk.Key.l: if (control && shift) { Pointer.Index = Math.Min(Pointer.Collection.Count - 1, Pointer.Index + VisibleColums - (Pointer.Index % VisibleColums) - 1); } else { Pointer.MoveNext(); } break; case Gdk.Key.Up: case Gdk.Key.K: case Gdk.Key.k: Pointer.Index = Math.Max(0, Pointer.Index - VisibleColums); break; case Gdk.Key.Page_Up: Pointer.Index = Math.Max(0, Pointer.Index - VisibleColums); break; case Gdk.Key.Page_Down: Pointer.Index = Math.Min(Pointer.Collection.Count - 1, Pointer.Index + VisibleColums * VisibleRows); break; case Gdk.Key.Home: Pointer.MoveFirst(); break; case Gdk.Key.End: Pointer.MoveLast(); break; default: return(false); } ScrollTo(Pointer.Index); return(true); }
protected override bool OnKeyPressEvent(EventKey evnt) { this.Theory.FireHook(EventType.KeyPress, evnt); return(base.OnKeyPressEvent(evnt)); }
// remove dead entries. When purgeAll is true, remove all entries. private bool Purge(bool purgeAll) { bool foundDirt = false; using (this.WriteLock) { #if WeakEventTelemetry WeakEventLogger.LogSnapshot(this, "+Purge"); #endif if (!BaseAppContextSwitches.EnableWeakEventMemoryImprovements) { // copy the keys into a separate array, so that later on // we can change the table while iterating over the keys ICollection ic = _dataTable.Keys; EventKey[] keys = new EventKey[ic.Count]; ic.CopyTo(keys, 0); for (int i = keys.Length - 1; i >= 0; --i) { object data = _dataTable[keys[i]]; // a purge earlier in the loop may have removed keys[i], // in which case there's nothing more to do if (data != null) { object source = keys[i].Source; foundDirt |= keys[i].Manager.PurgeInternal(source, data, purgeAll); // if source has been GC'd, remove its data if (!purgeAll && source == null) { _dataTable.Remove(keys[i]); } } } #if WeakEventTelemetry LogAllocation(ic.GetType(), 1, 12); // _dataTable.Keys - Hashtable+KeyCollection LogAllocation(typeof(EventKey[]), 1, 12 + ic.Count * 12); // keys LogAllocation(typeof(EventKey), ic.Count, 8 + 12); // box(key) LogAllocation(typeof(ReaderWriterLockWrapper), 1, 12); // actually the RWLW+AutoWriterRelease from WriteLock LogAllocation(typeof(Action), 2, 32); // anonymous delegates in RWLW #endif } else { Debug.Assert(_toRemove.Count == 0, "to-remove list should be empty"); _inPurge = true; // enumerate the dictionary using IDE explicitly rather than // foreach, to avoid allocating temporary DictionaryEntry objects IDictionaryEnumerator ide = _dataTable.GetEnumerator() as IDictionaryEnumerator; while (ide.MoveNext()) { EventKey key = (EventKey)ide.Key; object source = key.Source; foundDirt |= key.Manager.PurgeInternal(source, ide.Value, purgeAll); // if source has been GC'd, remove its data if (!purgeAll && source == null) { _toRemove.Add(key); } } #if WeakEventTelemetry LogAllocation(ide.GetType(), 1, 36); // Hashtable+HashtableEnumerator #endif _inPurge = false; } if (purgeAll) { _managerTable.Clear(); _dataTable.Clear(); } else if (_toRemove.Count > 0) { foreach (EventKey key in _toRemove) { _dataTable.Remove(key); } _toRemove.Clear(); _toRemove.TrimExcess(); } #if WeakEventTelemetry ++_purgeCount; if (!foundDirt) { ++_purgeNoops; } WeakEventLogger.LogSnapshot(this, "-Purge"); #endif } return(foundDirt); }
public void Unregister(EventKey InEventKey, Action InAction) { Unregister(InEventKey, InAction, EventDelegateType.None); }
// 注册事件(虚函数继承,继承自ILoggingService) public virtual void RegisterEvent(EventKey kKey, EventHandler kEvent) { mEventSet.Add(kKey, kEvent); }
protected override bool OnKeyPressEvent(EventKey evnt) { Gdk.Key key = evnt.Key; Gdk.ModifierType modifier = evnt.State; bool ret; ret = base.OnKeyPressEvent(evnt); if (openedProject == null && !player.Opened) { return(ret); } if (projectType != ProjectType.CaptureProject && projectType != ProjectType.FakeCaptureProject) { switch (key) { case Constants.SEEK_FORWARD: if (modifier == Constants.STEP) { player.StepForward(); } else { player.SeekToNextFrame(selectedTimeNode != null); } break; case Constants.SEEK_BACKWARD: if (modifier == Constants.STEP) { player.StepBackward(); } else { player.SeekToPreviousFrame(selectedTimeNode != null); } break; case Constants.FRAMERATE_UP: player.FramerateUp(); break; case Constants.FRAMERATE_DOWN: player.FramerateDown(); break; case Constants.TOGGLE_PLAY: player.TogglePlay(); break; } } else { switch (key) { case Constants.TOGGLE_PLAY: capturer.TogglePause(); break; } } return(ret); }
protected override bool OnKeyPressEvent(EventKey e) { if (e.Key == Gdk.Key.Left || e.Key == Gdk.Key.Right || e.Key == Gdk.Key.Up || e.Key == Gdk.Key.Down) { var step = 1; var stepY = 0; if ((e.State & ModifierType.ShiftMask) == ModifierType.ShiftMask) { step = 20; } if (e.Key == Gdk.Key.Left || e.Key == Gdk.Key.Up) { step = -step; } if ((e.State & ModifierType.ControlMask) == ModifierType.ControlMask) { Distance += step; } else { if (e.Key == Gdk.Key.Up || e.Key == Gdk.Key.Down) { stepY = step; step = 0; } SetWindowPosition(GetWindowPosition().Add(step, stepY)); } } if (e.Key == Gdk.Key.r || e.Key == Gdk.Key.t || e.Key == Gdk.Key.R || e.Key == Gdk.Key.T) { var angleDistance = Math.PI / 2; if ((e.State & ModifierType.ShiftMask) == ModifierType.ShiftMask) { angleDistance = Math.PI / 4; } if ((e.State & ModifierType.ControlMask) == ModifierType.ControlMask) { angleDistance = DEG1; } if (e.Key == Gdk.Key.t || e.Key == Gdk.Key.T) { angleDistance = -angleDistance; } SetAngle(Angle - angleDistance); } if (e.Key == Gdk.Key.v) { SetAngle(Math.PI / 2); } if (e.Key == Gdk.Key.h) { SetAngle(0); } if (e.Key == Gdk.Key.n) { Iconify(); } if (e.Key == Gdk.Key.Home) { Distance = 0; } if (e.Key == Gdk.Key.End) { var mon = Screen.GetMonitorAtWindow(GdkWindow); var geo = Screen.GetMonitorGeometry(mon); if (Angle == 0) { Distance = geo.Width - 200; } else { Distance = geo.Height - 200; } } if (e.Key == Gdk.Key.c) { ShowColorChooser(); } if ((e.Key == Gdk.Key.q || e.Key == Gdk.Key.w) && (e.State & ModifierType.ControlMask) == ModifierType.ControlMask) { Application.Quit(); } return(base.OnKeyPressEvent(e)); }
public void DifferentThreadBroadcast() { var game = new EventSystemTest(); var counter = 0; var broadcaster = new EventKey(); var readyCount = 0; game.AddTask(async () => { var recv = new EventReceiver(broadcaster, EventReceiverOptions.Buffered); Interlocked.Increment(ref readyCount); for (;;) { await recv.ReceiveAsync(); Interlocked.Increment(ref counter); } }); game.AddTask(async () => { var recv = new EventReceiver(broadcaster, EventReceiverOptions.Buffered); Interlocked.Increment(ref readyCount); for (;;) { await recv.ReceiveAsync(); Interlocked.Increment(ref counter); } }); game.AddTask(async () => { var recv = new EventReceiver(broadcaster, EventReceiverOptions.Buffered); Interlocked.Increment(ref readyCount); for (;;) { await recv.ReceiveAsync(); Interlocked.Increment(ref counter); } }); var t1W = new AutoResetEvent(false); var t2W = new AutoResetEvent(false); var waitHandles = new WaitHandle[] { t1W, t2W }; Exception threadException = null; new Thread(() => { try { while (!game.IsRunning && readyCount < 3) { Thread.Sleep(200); } var frameCounter = 0; while (true) { Thread.Sleep(50); frameCounter++; broadcaster.Broadcast(); if (frameCounter < 200) continue; t1W.Set(); return; } } catch (Exception e) { threadException = e; } }).Start(); new Thread(() => { try { while (!game.IsRunning && readyCount < 3) { Thread.Sleep(200); } var frameCounter = 0; while (true) { Thread.Sleep(50); frameCounter++; broadcaster.Broadcast(); if (frameCounter < 200) continue; t2W.Set(); return; } } catch (Exception e) { threadException = e; } }).Start(); new Thread(() => { try { //wait until both threads have broadcasted 200 times each if (!WaitHandle.WaitAll(waitHandles, TimeSpan.FromMinutes(2))) { throw new Exception("DifferentThreadBroadcast test timedout."); } Thread.Sleep(2000); game.Exit(); } catch (Exception e) { threadException = e; } }).Start(); game.Run(); Assert.IsNull(threadException); Assert.AreEqual(1200, counter); }
// 移除事件映射,移除存在的代理 public void Remove(EventKey kEventKey, Delegate kHandler) { lock (mEventDict) { Delegate kTemp; if (mEventDict.TryGetValue(kEventKey, out kTemp)) { kTemp = Delegate.Remove(kTemp, kHandler); if (kTemp != null) mEventDict[kEventKey] = kTemp; else mEventDict.Remove(kEventKey); } } }
public void ReceiveManyCheck() { var game = new EventSystemTest(); var frameCount = 0; game.AddTask(async () => { var evt = new EventKey(); var rcv = new EventReceiver(evt, EventReceiverOptions.Buffered); while (frameCount < 25) { evt.Broadcast(); if (frameCount == 20) { var manyEvents = rcv.TryReceiveAll(); Assert.AreEqual(manyEvents, 21); game.Exit(); } await game.NextFrame(); frameCount++; } }); game.Run(); }
protected override bool OnKeyPressEvent(EventKey evnt) { return(((DefaultWorkbench)IdeApp.Workbench.RootWindow).FilterWindowKeypress(evnt) || base.OnKeyPressEvent(evnt)); }
protected override bool OnKeyPressEvent(EventKey evnt) => ProcessKeyEvent(evnt);
public void DelayedReceiverCreation() { var game = new EventSystemTest(); var frameCount = 0; game.AddTask(async () => { var evt = new EventKey(); EventReceiver rcv = null; while (frameCount < 25) { if (frameCount == 5) { evt.Broadcast(); } if (frameCount == 20) { rcv = new EventReceiver(evt); Assert.False(rcv.TryReceive()); evt.Broadcast(); } if (frameCount == 22) { Assert.NotNull(rcv); Assert.True(rcv.TryReceive()); game.Exit(); } await game.NextFrame(); frameCount++; } }); game.Run(); }
public void Add(EventKey key, params object[] args) { eventInfoList.Add(new EventInfo(key, args)); }
public void DifferentSyntax() { var game = new EventSystemTest(); var frameCounter = 0; var broadcaster = new EventKey(); game.AddTask(async () => { var tests = 5; var recv = new EventReceiver(broadcaster); var threadId = Thread.CurrentThread.ManagedThreadId; while (tests-- > 0) { await recv; Assert.AreEqual(threadId, Thread.CurrentThread.ManagedThreadId); } }); game.AddTask(async () => { var tests = 5; var recv = new EventReceiver(broadcaster); var threadId = Thread.CurrentThread.ManagedThreadId; while (tests-- > 0) { await recv; Assert.AreEqual(threadId, Thread.CurrentThread.ManagedThreadId); } }); game.AddTask(async () => { var tests = 5; var recv = new EventReceiver(broadcaster); var threadId = Thread.CurrentThread.ManagedThreadId; while (tests-- > 0) { await recv; Assert.AreEqual(threadId, Thread.CurrentThread.ManagedThreadId); } }); Task.Run(async () => { while (!game.IsRunning) { await Task.Delay(100); } while (true) { frameCounter++; broadcaster.Broadcast(); if (frameCounter == 20) { game.Exit(); } await Task.Delay(50); } }); game.Run(); }
public void UnbindListener(EventKey key, Action <EventPayload> action, IEventContext evntContext) { UnbindListener(evntContext.GetEvent(key), action, evntContext); }
public void ReceiveFirstCheck() { var game = new EventSystemTest(); var frameCount = 0; var evt1 = new EventKey(); var evt2 = new EventKey(); game.AddTask(async () => { var rcv1 = new EventReceiver(evt1); var rcv2 = new EventReceiver(evt2); for (;;) { var rcv = await EventReceiver.ReceiveOne(rcv1, rcv2); if (rcv.Receiver == rcv1) { evt2.Broadcast(); //this is the point of this test.. see if t2 will get populated next loop await game.NextFrame(); } else if (rcv.Receiver == rcv2) { await game.NextFrame(); game.Exit(); } } }); game.AddTask(async () => { while (frameCount < 30 && game.IsRunning) { frameCount++; if (frameCount == 20) { evt1.Broadcast(); } await game.NextFrame(); } Assert.Fail("t2 should be completed"); }); }
protected override bool OnKeyPressEvent(EventKey evnt) { KeyPressEvent(evnt); return(base.OnKeyPressEvent(evnt)); }
protected override bool OnKeyReleaseEvent(EventKey evnt) { #region Key mapping switch (evnt.Key) { case Gdk.Key.a: this.input.KeyboardState.A = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.b: this.input.KeyboardState.B = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.BackSpace: this.input.KeyboardState.Back = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.c: this.input.KeyboardState.C = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Shift_Lock: this.input.KeyboardState.CapsLock = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Cancel: this.input.KeyboardState.Crsel = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.d: this.input.KeyboardState.D = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Key_0: this.input.KeyboardState.D0 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Key_1: this.input.KeyboardState.D1 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Key_2: this.input.KeyboardState.D2 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Key_3: this.input.KeyboardState.D3 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Key_4: this.input.KeyboardState.D4 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Key_5: this.input.KeyboardState.D5 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Key_6: this.input.KeyboardState.D6 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Key_7: this.input.KeyboardState.D7 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Key_8: this.input.KeyboardState.D8 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Key_9: this.input.KeyboardState.D9 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Delete: this.input.KeyboardState.Delete = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Down: this.input.KeyboardState.Down = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.e: this.input.KeyboardState.E = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Return: this.input.KeyboardState.Enter = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Escape: this.input.KeyboardState.Escape = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Execute: this.input.KeyboardState.Execute = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.f: this.input.KeyboardState.F = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.F1: this.input.KeyboardState.F = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.F10: this.input.KeyboardState.F10 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.F11: this.input.KeyboardState.F11 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.F12: this.input.KeyboardState.F12 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.F2: this.input.KeyboardState.F2 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.F3: this.input.KeyboardState.F3 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.F4: this.input.KeyboardState.F4 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.F5: this.input.KeyboardState.F5 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.F6: this.input.KeyboardState.F6 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.F7: this.input.KeyboardState.F7 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.F8: this.input.KeyboardState.F8 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.F9: this.input.KeyboardState.F9 = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.g: this.input.KeyboardState.G = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.h: this.input.KeyboardState.H = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.i: this.input.KeyboardState.I = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.j: this.input.KeyboardState.J = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.k: this.input.KeyboardState.K = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.l: this.input.KeyboardState.L = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Left: this.input.KeyboardState.Left = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Alt_L: this.input.KeyboardState.LeftAlt = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Control_L: this.input.KeyboardState.LeftControl = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Shift_L: this.input.KeyboardState.LeftShift = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.m: this.input.KeyboardState.M = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.n: this.input.KeyboardState.N = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.o: this.input.KeyboardState.O = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.p: this.input.KeyboardState.P = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.q: this.input.KeyboardState.Q = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.r: this.input.KeyboardState.R = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Right: this.input.KeyboardState.Right = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Alt_R: this.input.KeyboardState.RightAlt = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Control_R: this.input.KeyboardState.RightControl = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Shift_R: this.input.KeyboardState.RightShift = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.s: this.input.KeyboardState.S = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.space: this.input.KeyboardState.Space = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.KP_Subtract: this.input.KeyboardState.Subtract = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.t: this.input.KeyboardState.T = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Tab: this.input.KeyboardState.Tab = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.u: this.input.KeyboardState.U = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.Up: this.input.KeyboardState.Up = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.v: this.input.KeyboardState.V = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.w: this.input.KeyboardState.W = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.x: this.input.KeyboardState.X = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.y: this.input.KeyboardState.Y = WaveEngine.Common.Input.ButtonState.Release; break; case Gdk.Key.z: this.input.KeyboardState.Z = WaveEngine.Common.Input.ButtonState.Release; break; } #endregion return(base.OnKeyReleaseEvent(evnt)); }
/// <summary> /// Creates the key event arguments. /// </summary> /// <param name="e">The key event args.</param> /// <returns>Key event arguments.</returns> public static OxyKeyEventArgs ToKeyEventArgs(this EventKey e) { return(new OxyKeyEventArgs { ModifierKeys = GetModifiers(e.State), Key = e.Key.Convert() }); }
public EventModel(EventType eventType, EventKey eventKey, string args = null) { EventType = eventType; EventKey = eventKey; Args = args; }
public EventInfo(EventKey key, object[] args) { this.key = key; this.args = args; }