private void AddIDToDatabase(string name, AnchorID id) { if (!_database.ContainsKey(name)) { _database.Add(name, id); } }
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); } }
private IARAnchor Find(AnchorID anchorID) { if (_database.ContainsKey(anchorID)) { return(_database[anchorID]); } return(null); }
private bool IsActive(AnchorID anchorID) { if (_activeDatabase.TryGetValue(anchorID, out bool active)) { return(active); } return(false); }
// Метод возвращает координаты центра текущего активного якоря 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); }
private void Activate(AnchorID anchorID, bool active) { if (_activeDatabase.ContainsKey(anchorID)) { _activeDatabase[anchorID] = active; } else { _activeDatabase.Add(anchorID, active); } }
IARAnchor IARAnchorRepository.Create(AnchorID anchorID) { IARAnchor anchor = Find(anchorID); if (anchor == null) { anchor = _factory.Create(anchorID); } return(anchor); }
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(); }
IARAnchor IARAnchorSystem.Create() { AnchorID id = CreateNewID(); return(_repository.Create(id)); }
IARAnchor IARAnchorSystem.Find(AnchorID anchorID) => _repository.Find(anchorID);
public void Construct(AnchorID anchorID) { _anchorID = anchorID; name = $"{anchorID}"; }
IARAnchor IARAnchorService.Find(AnchorID anchorID) => _system.Find(anchorID);
IARAnchor IARAnchorRepository.Find(AnchorID anchorID) => Find(anchorID);
// Метод обновляет состояние якорей по заданным координатам // рамки выделения 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); } }