Пример #1
0
 /// <summary>
 /// Устанавливает цвет символов, в которых выводится указанный объект
 /// </summary>
 private void SetObjectSymbolsColor(ILCDIndicatorRowObject obj)
 {
     for (int i = obj.Position; i < obj.Position + obj.Mask.Length; i++)
     {
         this[i].ActivePixelColor = this.parent.objectSymbolsColor;
     }
 }
Пример #2
0
 /// <summary>
 /// Добавляет объект к строке без редактирования текста
 /// (маска объекта уже содержится в позиции вывода объекта)
 /// </summary>
 public void AddExistingObject(ILCDIndicatorRowObject obj)
 {
     this.objects.Add(obj);
     System.Comparison <ILCDIndicatorRowObject> comparer = new Comparison <ILCDIndicatorRowObject>(this.CompareObjects);
     this.objects.Sort(comparer);
     this.SetObjectSymbolsColor(obj);
 }
Пример #3
0
            /// <summary>
            /// Добавляет указанный объект
            /// </summary>
            public void AddObject(ILCDIndicatorRowObject obj)
            {
                int FreeSpace = this.Length - this.LastNonSpaceSymbolIndex - 1;

                if (obj.Position < this.LastNonSpaceSymbolIndex + 1)
                {
                    for (int i = obj.Position; i < this.Length && this[i].Symbol == ' '; i++)
                    {
                        FreeSpace++;
                    }
                }
                else
                {
                    FreeSpace = this.Length - obj.Position;
                }
                if (FreeSpace < obj.Mask.Length)
                {
                    throw new Exception("Недостаточно места на дисплее");
                }
                this.parent.SetSelection(new Point(obj.Position, this.Index), 1);
                this.parent.InsertString(obj.Mask);
                this.AddExistingObject(obj);
                this.parent.selectedObject = null;
                int position = obj.Mask.Length + obj.Position < this.Length ? obj.Mask.Length + obj.Position : obj.Mask.Length + obj.Position - 1;

                this.parent.SetSelection(new Point(position, this.index), 1);
                this.parent.RaiseSelectionChangedEvent();
            }
Пример #4
0
 /// <summary>
 /// Удаляет указанный объект из строки
 /// </summary>
 /// <param name="obj">Удаляемый объект</param>
 public void RemoveObject(ILCDIndicatorRowObject obj)
 {
     this.objects.Remove(obj);
     for (int i = obj.Position; i < obj.Position + obj.Mask.Length; i++)
     {
         this[i].ActivePixelColor = Color.Black;
     }
 }
Пример #5
0
        /// <summary>
        /// Устанавливает стартовую позицию и длину выделенных символов
        /// </summary>
        public void SetSelection(Point StartPosition, int Length)
        {
            Point p = this.CursorPos;

            if (Length == 0)
            {
                Length = 1;
            }
            // Снятие текущего выделения
            for (int i = 0; i < this.selection.AbsLength; i++)
            {
                int x = this.selection.Start.X + i * this.selection.Direction;

                /*if (x > Math.Min(StartPosition.X, StartPosition.X + Length) && x < Math.Max(StartPosition.X, StartPosition.X + Length))
                 *  continue;*/
                this.symbols[this.selection.Start.Y, x].Selected = false;
            }
            // Установка стартовой позиции переменной
            this.selection.Start = StartPosition;
            // Проверка на наличие объекта в выделении
            ILCDIndicatorRowObject obj = this[StartPosition.Y].GetObject(StartPosition.X);

            if (obj != null)
            {
                // Выделение попадает на объект
                this.selection.Start = new Point(obj.Position, this.CurrentRow);
                Length += StartPosition.X - obj.Position;
                if (Length < obj.Mask.Length)
                {
                    Length = obj.Mask.Length;
                }
                // Генерация события выделения объекта
                if (this.selectedObject != obj && this.LCDIndicatorRowObjectSelected != null)
                {
                    this.selectedObject = obj;
                    this.LCDIndicatorRowObjectSelected(this, new EventArgs <ILCDIndicatorRowObject>(obj));
                }
            }
            else if (this.selectedObject != null && this.LCDIndicatorRowObjectLostFocus != null)
            {
                // Объект в выделение не попал, но до этого он ам был
                // Генерация события потери объектом фокуса
                this.LCDIndicatorRowObjectLostFocus(this, EventArgs.Empty);
                this.selectedObject = null;
            }
            this.selection.Length = Length;
            // Выделение всех необходимых символов
            for (int i = 0; i < this.selection.AbsLength; i++)
            {
                this.symbols[this.selection.Start.Y, this.selection.Start.X + i * this.selection.Direction].Selected = true;
            }
            this.Invalidate();
            // Генерация события смены выделения
            if (p != this.CursorPos && this.SelectionChanged != null)
            {
                this.SelectionChanged(this, EventArgs.Empty);
            }
        }
Пример #6
0
            /// <summary>
            /// Возвращает объект в указанной позиции строки, или null, если там нет объекта
            /// </summary>
            public ILCDIndicatorRowObject GetObject(int Position)
            {
                ILCDIndicatorRowObject res = null;

                foreach (ILCDIndicatorRowObject obj in this.objects)
                {
                    if (obj.Position <= Position && obj.Position + obj.Mask.Length > Position)
                    {
                        res = obj;
                        break;
                    }
                }
                return(res);
            }
Пример #7
0
        /// <summary>
        /// Перемещает курсор на 1 символ вправо
        /// </summary>
        private void MoveCursorRight(bool Shift)
        {
            int StartPosition = this.selection.Start.X;
            int Length        = this.selection.Length;

            if (this.CursorPos.X == this.symbolsInRow - 1 && (this.selection.AbsLength == 1 || Shift))
            {
                return;
            }
            if (this.selection.AbsLength > 1 && !Shift)
            {
                ILCDIndicatorRowObject obj = this[this.CurrentRow].GetObject(StartPosition);
                if (obj != null)
                {
                    int x = (obj.Position + obj.Mask.Length) < this.symbolsInRow ? (obj.Position + obj.Mask.Length) : (this.symbolsInRow - 1);
                    this.SetSelection(new Point(x, this.selection.Start.Y), 1);
                }
                else
                {
                    // Если выделено более 1 символа и нажат только Right, то оставляем курсор наместе и снимаем выделение
                    this.SetSelection((this.selection.Direction == -1 ? this.CursorPos : new Point(this.CursorPos.X + this.selection.Length - 1, this.CursorPos.Y)), 1);
                }
                return;
            }
            // Выделенные символы располагаются располагаются справа от курсора
            if (!Shift || (this.selection.Direction == 1 && this.selection.AbsLength != 1 && !this.ContainsObjectInCursorPos()))
            {
                // Нажата просто клавиша Right или выделенные символы справа от курсора, то снимаем с него выделение
                this.symbols[this.CursorPos.Y, this.CursorPos.X].Selected = false;
            }
            if (Shift)
            {
                // Нажато Right+Shift - увеличиваем длину выделения
                Length = (this.selection.Length == 1) ? -2 : this.selection.Length - 1;
            }
            // И с Shift'ом и без сдвигаем курсор вправо
            StartPosition = this.selection.Start.X + 1;
            ILCDIndicatorRowObject obj1 = this[this.CurrentRow].GetObject(StartPosition);

            if (obj1 != null && Shift)
            {
                Length       -= obj1.Position + obj1.Mask.Length - StartPosition;
                StartPosition = (obj1.Position + obj1.Mask.Length) < this.symbolsInRow ? (obj1.Position + obj1.Mask.Length) : (this.symbolsInRow - 1);
            }
            this.SetSelection(new Point(StartPosition, this.selection.Start.Y), (Length == 0) ? 1 : Length);
        }
Пример #8
0
 /// <summary>
 /// Сдвигает подстроку, начинающуюся с указанной позиции на указанное число символов вправо
 /// </summary>
 public void MoveSubstringRight(int position, int count)
 {
     for (int i = this.LastNonSpaceSymbolIndex; i >= position; i--)
     {
         this[i + count].Symbol = this[i].Symbol;
     }
     for (int j = this.objects.Count - 1; j >= 0; j--)
     {
         ILCDIndicatorRowObject obj = this.objects[j];
         if (obj.Position >= position)
         {
             for (int i = obj.Position; i < obj.Position + Math.Min(obj.Mask.Length, count); i++)
             {
                 this[i].ActivePixelColor = Color.Black;
             }
             obj.Position += count;
             this.SetObjectSymbolsColor(obj);
         }
     }
 }
Пример #9
0
 /// <summary>
 /// Сравнивает два объекта по их позиции в строке
 /// </summary>
 private int CompareObjects(ILCDIndicatorRowObject o1, ILCDIndicatorRowObject o2)
 {
     return(o1.Position - o2.Position);
 }