コード例 #1
0
        public Selection(uint selectionStartLineNumber, uint selectionStartColumn, uint positionLineNumber, uint positionColumn)
        {
            SelectionStartLineNumber = selectionStartLineNumber;
            SelectionStartColumn     = selectionStartColumn;
            PositionLineNumber       = positionLineNumber;
            PositionColumn           = positionColumn;

            if (selectionStartLineNumber < positionLineNumber || (selectionStartLineNumber == positionLineNumber && selectionStartColumn <= positionColumn))
            {
                // Start is first
                StartLineNumber = SelectionStartLineNumber;
                StartColumn     = SelectionStartColumn;
                EndLineNumber   = PositionLineNumber;
                EndColumn       = PositionColumn;

                Direction = SelectionDirection.LTR;
            }
            else
            {
                // Flipped
                StartLineNumber = PositionLineNumber;
                StartColumn     = PositionColumn;
                EndLineNumber   = SelectionStartLineNumber;
                EndColumn       = SelectionStartColumn;

                Direction = SelectionDirection.RTL;
            }
        }
コード例 #2
0
        public GaussianSelectionAlgorithm(double stdDev = 0.5, SelectionDirection direction = SelectionDirection.FromTop)
        {
            Contract.Requires(stdDev > 0.0);

            Direction = direction;
            StdDev = stdDev;
        }
コード例 #3
0
 /// <summary>
 /// Create with a direction.
 /// </summary>
 public static Selection CreateWithDirection(int startLineNumber,
                                             int startColumn,
                                             int endLineNumber,
                                             int endColumn,
                                             SelectionDirection direction)
 => direction == SelectionDirection.LTR
         ? new Selection(startLineNumber, startColumn, endLineNumber, endColumn)
         : new Selection(endLineNumber, endColumn, startLineNumber, startColumn);
コード例 #4
0
        public override void Draw(Context ctx, Rectangle selectedArea, SelectionDirection selectionDirection, TermSharp.SelectionMode selectionMode)
        {
            var scale = targetImageHeight / image.Height;

            ctx.Scale(scale, scale);
            ctx.DrawImage(image, new Point());
            ctx.Translate(0, -targetImageHeight);
            base.Draw(ctx, selectedArea, selectionDirection, selectionMode);
        }
コード例 #5
0
ファイル: InputManager.cs プロジェクト: DanielKorsah/ggj17
 // Reset the delegates related to non-permanent entities
 public void ResetManager()
 {
     RotateBeaconCall    = null;
     ChooseDirectionCall = null;
     ChangeBeaconCall    = null;
     PickupCall          = null;
     SelectionCall       = null;
     ResetCall           = null;
 }
コード例 #6
0
    public SelectionSpan(ConsoleCoordinate start, ConsoleCoordinate end, SelectionDirection direction)
    {
        Debug.Assert(start >= ConsoleCoordinate.Zero);
        Debug.Assert(start < end);

        Start     = start;
        End       = end;
        Direction = direction;
    }
コード例 #7
0
        void ItemClick(object sender, EventArgs e)
        {
            try
            {
                int index = (int)((Control)sender).Tag;

                selDirection = SelectionDirection.None;

                SelectItem(index, Control.ModifierKeys != Keys.Control);
                StartSelection = SelectedIndex;
            }
            catch { }
        }
コード例 #8
0
ファイル: Selection.cs プロジェクト: wushian/Bridge
 /// <summary>
 /// Applies a change to the current selection or cursor position, using simple textual commands.
 /// </summary>
 /// <param name="alter">The type of change to apply. Specify "move" to move the current cursor position or "extend" to extend the current selection.</param>
 /// <param name="direction">The direction in which to adjust the current selection. You can specify "forward" or "backward" to adjust in the appropriate direction based on the language at the selection point. If you want to adjust in a specific direction, you can specify "left" or "right".</param>
 /// <param name="granularity">The distance to adjust the current selection or cursor position. </param>
 public virtual extern void Modify(SelectionAlter alter, SelectionDirection direction, SelectionGranularity granularity);
コード例 #9
0
 public BorderSelectionAlgorithm(SelectionDirection direction = SelectionDirection.FromTop)
 {
     Direction = direction;
 }
コード例 #10
0
        private void Contract(Player player, int amount, int reverseAmount = 0, SelectionDirection direction = SelectionDirection.Me)
        {
            if (amount < 0 || reverseAmount < 0)
            {
                player.SendMessage($"The amount need to a positive value. Try reversing the direction instead");
                return;
            }

            var selector = RegionSelector.GetSelector(player);

            var position1 = selector.Position1;
            var position2 = selector.Position2;

            if (direction == SelectionDirection.Me)
            {
                int playerDirection = Entity.DirectionByRotationFlat(player.KnownPosition.HeadYaw);
                switch (playerDirection)
                {
                case 1:
                    direction = SelectionDirection.West;
                    break;

                case 2:
                    direction = SelectionDirection.North;
                    break;

                case 3:
                    direction = SelectionDirection.East;
                    break;

                case 0:
                    direction = SelectionDirection.South;
                    break;
                }
            }

            switch (direction)
            {
            case SelectionDirection.Up:
                if (position1.Y < position2.Y)
                {
                    selector.SelectPrimary(position1 + (Level.Up * amount));
                    if (reverseAmount != 0)
                    {
                        selector.SelectSecondary(position2 + (Level.Down * amount));
                    }
                }
                else
                {
                    selector.SelectSecondary(position2 + (Level.Up * amount));
                    if (reverseAmount != 0)
                    {
                        selector.SelectPrimary(position1 + (Level.Down * amount));
                    }
                }
                break;

            case SelectionDirection.Down:
                if (position1.Y > position2.Y)
                {
                    selector.SelectPrimary(position1 + (Level.Down * amount));
                    if (reverseAmount != 0)
                    {
                        selector.SelectSecondary(position2 + (Level.Up * amount));
                    }
                }
                else
                {
                    selector.SelectSecondary(position2 + (Level.Down * amount));
                    if (reverseAmount != 0)
                    {
                        selector.SelectPrimary(position1 + (Level.Up * amount));
                    }
                }
                break;

            case SelectionDirection.West:
                if (position1.Z < position2.Z)
                {
                    selector.SelectPrimary(position1 + (Level.West * amount));
                    if (reverseAmount != 0)
                    {
                        selector.SelectSecondary(position2 + (Level.East * amount));
                    }
                }
                else
                {
                    selector.SelectSecondary(position2 + (Level.West * amount));
                    if (reverseAmount != 0)
                    {
                        selector.SelectPrimary(position1 + (Level.East * amount));
                    }
                }
                break;

            case SelectionDirection.East:
                if (position1.Z > position2.Z)
                {
                    selector.SelectPrimary(position1 + (Level.East * amount));
                    if (reverseAmount != 0)
                    {
                        selector.SelectSecondary(position2 + (Level.West * amount));
                    }
                }
                else
                {
                    selector.SelectSecondary(position2 + (Level.East * amount));
                    if (reverseAmount != 0)
                    {
                        selector.SelectPrimary(position1 + (Level.West * amount));
                    }
                }
                break;

            case SelectionDirection.South:
                if (position1.X < position2.X)
                {
                    selector.SelectPrimary(position1 + (Level.South * amount));
                    if (reverseAmount != 0)
                    {
                        selector.SelectSecondary(position2 + (Level.North * amount));
                    }
                }
                else
                {
                    selector.SelectSecondary(position2 + (Level.South * amount));
                    if (reverseAmount != 0)
                    {
                        selector.SelectPrimary(position1 + (Level.North * amount));
                    }
                }
                break;

            case SelectionDirection.North:
                if (position1.X > position2.X)
                {
                    selector.SelectPrimary(position1 + (Level.North * amount));
                    if (reverseAmount != 0)
                    {
                        selector.SelectSecondary(position2 + (Level.South * amount));
                    }
                }
                else
                {
                    selector.SelectSecondary(position2 + (Level.North * amount));
                    if (reverseAmount != 0)
                    {
                        selector.SelectPrimary(position1 + (Level.South * amount));
                    }
                }
                break;
            }
        }
コード例 #11
0
        public virtual void Draw(Context ctx, Rectangle selectedArea, SelectionDirection selectionDirection, SelectionMode selectionMode)
        {
            ctx.SetColor(defaultForeground);
            var newLinesAt = new List <int> {
                0
            };                                    // contains indices of line wraps (i.e. \n)
            var charsOnLine = MaximalColumn + 1;

            var result               = new StringBuilder();
            var enumerator           = StringInfo.GetTextElementEnumerator(content);
            var textElementsThisLine = 0;

            while (enumerator.MoveNext())
            {
                textElementsThisLine++;
                result.Append(enumerator.GetTextElement());
                if (textElementsThisLine == charsOnLine)
                {
                    result.Append('\n');
                    newLinesAt.Add(enumerator.ElementIndex + newLinesAt.Count + 1);
                    textElementsThisLine = 0;
                }
            }
            textLayout.Text = result.ToString();

            var foregroundColors = specialForegrounds != null?specialForegrounds.ToDictionary(x => x.Key + x.Key / charsOnLine, x => x.Value) : new Dictionary <int, Color>();

            var backgroundColors = specialBackgrounds != null?specialBackgrounds.ToDictionary(x => x.Key + x.Key / charsOnLine, x => x.Value) : new Dictionary <int, Color>();

            if (selectedArea != default(Rectangle) && lengthInTextElements > 0)
            {
                var textWithNewLines = textLayout.Text;

                var firstSubrow = (int)Math.Min(newLinesAt.Count - 1, Math.Floor(selectedArea.Y / lineSize.Height));
                var lastSubrow  = (int)Math.Min(newLinesAt.Count - 1, Math.Floor((selectedArea.Y + selectedArea.Height) / lineSize.Height));
                var firstColumn = (int)Math.Round(selectedArea.X / charWidth);
                var lastColumn  = (int)Math.Floor((selectedArea.X + selectedArea.Width) / charWidth);
                if (selectionMode == SelectionMode.Block)
                {
                    for (var i = firstSubrow; i <= lastSubrow; i++)
                    {
                        for (var j = firstColumn; j <= lastColumn; j++)
                        {
                            foregroundColors[(charsOnLine + 1) * i + j] = GetSelectionForegroundColor(i, charsOnLine);
                            backgroundColors[(charsOnLine + 1) * i + j] = selectionColor;
                        }
                    }
                }
                else
                {
                    if (selectionDirection == SelectionDirection.NW)
                    {
                        Utilities.Swap(ref firstColumn, ref lastColumn);
                        Utilities.Swap(ref firstSubrow, ref lastSubrow);
                    }

                    var firstIndex = firstColumn + newLinesAt[firstSubrow];
                    var lastIndex  = lastColumn + newLinesAt[lastSubrow];

                    if (lastIndex < firstIndex)
                    {
                        Utilities.Swap(ref firstIndex, ref lastIndex);
                    }

                    var textWithNewLinesStringInfo = new StringInfo(textWithNewLines);
                    firstIndex = Math.Max(0, Math.Min(textWithNewLinesStringInfo.LengthInTextElements - 1, firstIndex));
                    lastIndex  = Math.Max(0, Math.Min(textWithNewLinesStringInfo.LengthInTextElements - 1, lastIndex));

                    for (var i = firstIndex; i <= lastIndex; i++)
                    {
                        foregroundColors[i] = GetSelectionForegroundColor(i, charsOnLine);
                        backgroundColors[i] = selectionColor;
                    }
                    selectedContent = textWithNewLinesStringInfo.SubstringByTextElements(firstIndex, lastIndex - firstIndex + 1);
                }
            }
            else
            {
                selectedContent = null;
            }

            foreach (var entry in GetColorRanges(foregroundColors))
            {
                textLayout.SetForeground(entry.Item3, entry.Item1, entry.Item2);
            }
            foreach (var entry in GetColorRanges(backgroundColors))
            {
                textLayout.SetBackground(entry.Item3, entry.Item1, entry.Item2);
            }
            if (cursorInRow.HasValue)
            {
                // we draw a rectangle AND set background so that one can see cursor in a row without character
                textLayout.SetForeground(Colors.Black, cursorInRow.Value, 1);
            }
            ctx.DrawTextLayout(textLayout, 0, 0);
            textLayout.ClearAttributes();
        }
コード例 #12
0
        // Jeez, this gonna be stupid
        // Seriously, Unity, why I can't have multiple inputs?
        private void moveSelection(SelectionDirection direction)
        {
            clearSelection();
            if (currentSelection == maleButton)
            {
                switch (direction)
                {
                case SelectionDirection.UP:
                    readyButton.Select();
                    currentSelection = readyButton;
                    break;

                case SelectionDirection.DOWN:
                    firstItem.itemSelect.Select();
                    currentSelection = firstItem.itemSelect;
                    break;

                case SelectionDirection.LEFT:
                    break;

                case SelectionDirection.RIGHT:
                    femaleButton.Select();
                    currentSelection = femaleButton;
                    break;
                }
            }
            else if (currentSelection == femaleButton)
            {
                switch (direction)
                {
                case SelectionDirection.UP:
                    readyButton.Select();
                    currentSelection = readyButton;
                    break;

                case SelectionDirection.DOWN:
                    secondItem.itemSelect.Select();
                    currentSelection = secondItem.itemSelect;
                    break;

                case SelectionDirection.LEFT:
                    maleButton.Select();
                    currentSelection = maleButton;
                    break;

                case SelectionDirection.RIGHT:
                    firstItem.itemSelect.Select();
                    currentSelection = firstItem.itemSelect;
                    break;
                }
            }
            else if (currentSelection == firstItem.itemSelect)
            {
                switch (direction)
                {
                case SelectionDirection.UP:
                    firstItem.nextItem();
                    break;

                case SelectionDirection.DOWN:
                    firstItem.prevItem();
                    break;

                case SelectionDirection.LEFT:
                    femaleButton.Select();
                    currentSelection = femaleButton;
                    break;

                case SelectionDirection.RIGHT:
                    secondItem.itemSelect.Select();
                    currentSelection = secondItem.itemSelect;
                    break;
                }
            }
            else if (currentSelection == secondItem.itemSelect)
            {
                switch (direction)
                {
                case SelectionDirection.UP:
                    secondItem.nextItem();
                    break;

                case SelectionDirection.DOWN:
                    secondItem.prevItem();
                    break;

                case SelectionDirection.LEFT:
                    firstItem.itemSelect.Select();
                    currentSelection = firstItem.itemSelect;
                    break;

                case SelectionDirection.RIGHT:
                    colorButton.Select();
                    currentSelection = colorButton;
                    break;
                }
            }
            else if (currentSelection == colorButton)
            {
                switch (direction)
                {
                case SelectionDirection.UP:
                    secondItem.itemSelect.Select();
                    currentSelection = secondItem.itemSelect;
                    break;

                case SelectionDirection.DOWN:
                    readyButton.Select();
                    currentSelection = readyButton;
                    break;

                case SelectionDirection.LEFT:
                    secondItem.itemSelect.Select();
                    currentSelection = secondItem.itemSelect;
                    break;

                case SelectionDirection.RIGHT:
                    readyButton.Select();
                    currentSelection = readyButton;
                    break;
                }
            }
            else if (currentSelection == readyButton)
            {
                switch (direction)
                {
                case SelectionDirection.UP:
                    colorButton.Select();
                    currentSelection = colorButton;
                    break;

                case SelectionDirection.DOWN:
                    maleButton.Select();
                    currentSelection = maleButton;
                    break;

                case SelectionDirection.LEFT:
                    colorButton.Select();
                    currentSelection = colorButton;
                    break;

                case SelectionDirection.RIGHT:
                    maleButton.Select();
                    currentSelection = maleButton;
                    break;
                }
            }
            Debug.Log("Current selection is " + currentSelection);
            highlightSelection();
        }
コード例 #13
0
 //
 public bool MoveSelectionPoint (SelectionDirection direction)
 {
     bool r = false;
     try
     {
         try
         {
             switch (direction)
             {
                 case SelectionDirection.Right:
                 {
                     r = this.SelectionRight();
                     break;
                 }
                 case SelectionDirection.Left:
                 {
                     r = this.SelectionLeft();
                     break;
                 }
                 case SelectionDirection.Up:
                 {
                     r = this.SelectionUp();
                     break;
                 }
                 case SelectionDirection.Down:
                 {
                     r = this.SelectionDown();
                     break;
                 }
             }
         }
         catch
         {
         }
     }
     catch
     {
     }
     return r;
 }
コード例 #14
0
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if ((keyData == (Keys.Shift | Keys.Up)) || (keyData == (Keys.Shift | Keys.Left)))
            {
                if (StartSelection == -1)
                {
                    return(base.ProcessCmdKey(ref msg, keyData));
                }

                if (SelectedIndex == StartSelection)
                {
                    selDirection = SelectionDirection.None;
                }

                if (selDirection == SelectionDirection.None)
                {
                    selDirection   = SelectionDirection.Left;
                    StartSelection = SelectedIndex;
                }

                if (selDirection == SelectionDirection.Left && SelectedIndex - 1 >= 0)
                {
                    Items[SelectedIndex - 1].Selected = true;
                    _selectedIndex = SelectedIndex - 1;
                }
                if (selDirection == SelectionDirection.Right && SelectedIndex - 1 >= 0)
                {
                    Items[SelectedIndex].Selected = false;
                    _selectedIndex = SelectedIndex - 1;
                }
            }
            else if ((keyData == (Keys.Shift | Keys.Down)) || (keyData == (Keys.Shift | Keys.Right)))
            {
                if (StartSelection == -1)
                {
                    return(base.ProcessCmdKey(ref msg, keyData));
                }

                if (SelectedIndex == StartSelection)
                {
                    selDirection = SelectionDirection.None;
                }

                if (selDirection == SelectionDirection.None)
                {
                    selDirection   = SelectionDirection.Right;
                    StartSelection = SelectedIndex;
                }

                if (selDirection == SelectionDirection.Left && SelectedIndex + 1 <= Items.Count - 1)
                {
                    Items[SelectedIndex].Selected = false;
                    _selectedIndex = SelectedIndex + 1;
                }
                if (selDirection == SelectionDirection.Right && SelectedIndex + 1 <= Items.Count - 1)
                {
                    Items[SelectedIndex + 1].Selected = true;
                    _selectedIndex = SelectedIndex + 1;
                }
            }

            if ((keyData == (Keys.Up)) || (keyData == (Keys.Left)))
            {
                if (SelectedIndex > 0)
                {
                    SelectedIndex = SelectedIndex - 1;
                }
                StartSelection = SelectedIndex;
                selDirection   = SelectionDirection.None;
            }
            else if ((keyData == (Keys.Down)) || (keyData == (Keys.Right)))
            {
                if (SelectedIndex < Items.Count - 1)
                {
                    SelectedIndex = SelectedIndex + 1;
                }
                StartSelection = SelectedIndex;
                selDirection   = SelectionDirection.None;
            }
            return(base.ProcessCmdKey(ref msg, keyData));
        }