Ejemplo n.º 1
0
        /// <summary>
        /// Mark areas by drag.
        /// </summary>
        /// <param name="keys">Keys.</param>
        /// <param name="n">Number of targets.</param>
        /// <param name="eventHandler">Event handler.</param>
        /// <param name="getState">Callback to get a target state.</param>
        private static void Mark(Keys[] keys, int n, TargetMarkEventHandler eventHandler, Func <TargetStateByDrag> getState)
        {
            if (n <= 0)
            {
                throw new ArgumentException($"Invalid n: {n}");
            }

            lock (stateLocker) {
                if (state != null)
                {
                    throw new InvalidOperationException("Already marking a target by drag");
                }
                state = getState();
            }

            string eventName = $"{nameof(TargetMarkerByDrag)}.drag";

            if (keys == null)
            {
                keys = defaultKeys;
            }

            EventDispatcher.KeyDown(
                $"{eventName}.start", keys, (e) => {
                state.UpdateArea(e.State.Mouse.Position);
            }, forSystem: true
                );
            EventDispatcher.KeyUp(
                $"{eventName}.end", keys, (e) => {
                if (!state.Next())
                {
                    EventDispatcher.Unlisten(eventName, forSystem: true);

                    TargetMarkEventArgs eventArgs = new TargetMarkEventArgs(state.GetTargets());
                    state = null;

                    eventHandler(eventArgs);
                }
            }, forSystem: true
                );
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Mark areas by drag with multiple border widths and colors.
 /// </summary>
 /// <param name="eventHandler">Event handler.</param>
 /// <param name="keys">Keys.</param>
 /// <param name="n">Number of targets.</param>
 /// <param name="borderWidths">Border widths.</param>
 /// <param name="borderColors">Border colors.</param>
 public static void MarkByDrag(TargetMarkEventHandler eventHandler, Keys[] keys = null, int n = 1, int[] borderWidths = null, Color[] borderColors = null)
 {
     TargetMarkerByDrag.Mark(keys, n, eventHandler, borderWidths, borderColors);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Mark areas by drag with multiple border widths and colors.
 /// </summary>
 /// <param name="keys">Keys.</param>
 /// <param name="n">Number of targets.</param>
 /// <param name="eventHandler">Event handler.</param>
 /// <param name="borderWidths">Border widths.</param>
 /// <param name="borderColors">Border colors.</param>
 public static void Mark(Keys[] keys, int n, TargetMarkEventHandler eventHandler, int[] borderWidths, Color[] borderColors)
 {
     Mark(keys, n, eventHandler, () => { return(new TargetStateByDrag(n, borderWidths, borderColors)); });
 }