Пример #1
0
 private void AddIDToDatabase(string name, AnchorID id)
 {
     if (!_database.ContainsKey(name))
     {
         _database.Add(name, id);
     }
 }
Пример #2
0
        public AnchorManager()
        {
            // Инициализируем вспомогательные поля объекта
            m_activeAnchorID = AnchorID.None;
            m_normalColor    = Colors.Green;
            m_radius         = 3.0;

            // Создаём девять якорей
            m_anchors = new Dictionary <AnchorID, Shape>();
            Point center = new Point(0, 0);

            AnchorID[] ids =
            {
                AnchorID.TopLeft,    AnchorID.TopCenter,    AnchorID.TopRight,
                AnchorID.MiddleLeft, AnchorID.MiddleCenter, AnchorID.MiddleRight,
                AnchorID.BottomLeft, AnchorID.BottomCenter, AnchorID.BottomRight
            };
            for (int i = 0; i < ids.Length; i++)
            {
                Shape anchor = new System.Windows.Shapes.Rectangle();
                anchor.Stroke          = new SolidColorBrush(m_normalColor);
                anchor.StrokeThickness = 2;
                m_anchors.Add(ids[i], anchor);
                SetAnchorCenter(ids[i], center);
            }
        }
Пример #3
0
        private IARAnchor Find(AnchorID anchorID)
        {
            if (_database.ContainsKey(anchorID))
            {
                return(_database[anchorID]);
            }

            return(null);
        }
Пример #4
0
        private bool IsActive(AnchorID anchorID)
        {
            if (_activeDatabase.TryGetValue(anchorID, out bool active))
            {
                return(active);
            }

            return(false);
        }
Пример #5
0
        // Метод возвращает координаты центра текущего активного якоря
        public Point GetAnchorCenter(AnchorID anchorID)
        {
            Point pt = new Point();

            if (anchorID != AnchorID.None)
            {
                pt.X = Canvas.GetLeft(m_anchors[anchorID]) + m_radius;
                pt.Y = Canvas.GetTop(m_anchors[anchorID]) + m_radius;
            }
            return(pt);
        }
Пример #6
0
 private void Activate(AnchorID anchorID, bool active)
 {
     if (_activeDatabase.ContainsKey(anchorID))
     {
         _activeDatabase[anchorID] = active;
     }
     else
     {
         _activeDatabase.Add(anchorID, active);
     }
 }
Пример #7
0
        IARAnchor IARAnchorRepository.Create(AnchorID anchorID)
        {
            IARAnchor anchor = Find(anchorID);

            if (anchor == null)
            {
                anchor = _factory.Create(anchorID);
            }

            return(anchor);
        }
Пример #8
0
        private Color m_normalColor;                    // цвет маркера по умолчанию

        private void SetAnchorCenter(AnchorID anchorID, Point center)
        {
            double width  = 2 * m_radius;
            double height = 2 * m_radius;
            double left   = center.X - m_radius;
            double top    = center.Y - m_radius;

            m_anchors[anchorID].Width  = width;
            m_anchors[anchorID].Height = height;
            Canvas.SetLeft(m_anchors[anchorID], left);
            Canvas.SetTop(m_anchors[anchorID], top);
            //m_anchors[anchorID].BringIntoView();
        }
Пример #9
0
        IARAnchor IARAnchorSystem.Create()
        {
            AnchorID id = CreateNewID();

            return(_repository.Create(id));
        }
Пример #10
0
 IARAnchor IARAnchorSystem.Find(AnchorID anchorID) => _repository.Find(anchorID);
Пример #11
0
        public void Construct(AnchorID anchorID)
        {
            _anchorID = anchorID;

            name = $"{anchorID}";
        }
Пример #12
0
 IARAnchor IARAnchorService.Find(AnchorID anchorID) => _system.Find(anchorID);
Пример #13
0
 IARAnchor IARAnchorRepository.Find(AnchorID anchorID) => Find(anchorID);
Пример #14
0
        // Метод обновляет состояние якорей по заданным координатам
        // рамки выделения rubber и параметрам мышки e. Следует вызывать
        // из обработчика события мыши OnMouseMove().
        public void Update(RubberBandManager rubber, Point mousePoint,
                           bool IsMouseCaptured)
        {
            // Определяем радиус якорей
            System.Drawing.Rectangle clip = rubber.GetClientRect();
            if (clip.Width < 15 || clip.Height < 15)
            {
                m_radius = 2.0;
            }
            else
            {
                m_radius = 3.0;
            }

            // Определяем координаты всех якорей
            Point  topleft     = rubber.currentTopLeftCorner;
            Point  bottomright = rubber.currentBottomRightCorner;
            double widthStep   = 0.5 * (bottomright.X - topleft.X);
            double heightStep  = 0.5 * (bottomright.Y - topleft.Y);
            Point  center      = topleft;

            SetAnchorCenter(AnchorID.TopLeft, center);
            center.X = topleft.X + widthStep;
            center.Y = topleft.Y;
            SetAnchorCenter(AnchorID.TopCenter, center);
            center.X = topleft.X + 2 * widthStep;
            center.Y = topleft.Y;
            SetAnchorCenter(AnchorID.TopRight, center);
            center.X = topleft.X;
            center.Y = topleft.Y + heightStep;
            SetAnchorCenter(AnchorID.MiddleLeft, center);
            center.X = topleft.X + widthStep;
            center.Y = topleft.Y + heightStep;
            SetAnchorCenter(AnchorID.MiddleCenter, center);
            center.X = topleft.X + 2 * widthStep;
            center.Y = topleft.Y + heightStep;
            SetAnchorCenter(AnchorID.MiddleRight, center);
            center.X = topleft.X;
            center.Y = topleft.Y + 2 * heightStep;
            SetAnchorCenter(AnchorID.BottomLeft, center);
            center.X = topleft.X + widthStep;
            center.Y = topleft.Y + 2 * heightStep;
            SetAnchorCenter(AnchorID.BottomCenter, center);
            center = bottomright;
            SetAnchorCenter(AnchorID.BottomRight, center);

            // При необходимости обновляем индекс активного якоря
            if (!IsMouseCaptured)
            {
                // Отыскиваем ближайший к указателю мыши якорь
                AnchorID nearestID   = AnchorID.None;
                double   nearestDist = 1e6;
                foreach (KeyValuePair <AnchorID, Shape> record in m_anchors)
                {
                    center = GetAnchorCenter(record.Key);
                    double distX = Math.Abs(center.X - mousePoint.X);
                    double distY = Math.Abs(center.Y - mousePoint.Y);
                    double dist  = Math.Sqrt(distX * distX + distY * distY);
                    if (dist < nearestDist)
                    {
                        nearestDist = dist;
                        nearestID   = record.Key;
                    }
                }

                // Сравниваем расстояние до ближайшего якоря с порогом
                if (nearestDist < 10)
                {
                    m_activeAnchorID = nearestID;
                }
                else
                {
                    m_activeAnchorID = AnchorID.None;
                }
            }

            // Обновляем цвета якорей в зависимости от их состояния
            foreach (KeyValuePair <AnchorID, Shape> record in m_anchors)
            {
                Color color;
                if (record.Key == m_activeAnchorID)
                {
                    // Активный якорь
                    color = IsMouseCaptured ? Colors.Blue : Colors.Red;
                }
                else
                {
                    // Неактивный якорь
                    color = m_normalColor;
                }
                record.Value.Stroke = new SolidColorBrush(color);
            }
        }