private void DrawSensors() { double totalX = floorplanImage.ActualWidth; double totalY = floorplanImage.ActualHeight; foreach (Tuple <SensorViewModel, Rectangle, Viewbox, CompositeTransform> sensorTuple in canvasSensorList) { SensorViewModel sensor = sensorTuple.Item1; Rectangle sensorRect = sensorTuple.Item2; Viewbox sensorViewBox = sensorTuple.Item3; TextBlock sensorText = (sensorViewBox.Child as Border).Child as TextBlock; // Check if we hide the sensor or not if (_viewModel.SensorInView.Contains(sensor)) { // Update only those who are visible sensorRect.Height = sensorIconHeight; sensorRect.Width = sensorIconWidth; sensorViewBox.Height = sensorTextHeight; sensorViewBox.Width = sensorTextWidth; double startPosX = (sensorCanvas.ActualWidth - totalX) / 2 + ((Sensor)sensor).LocX * totalX; double startPosY = (sensorCanvas.ActualHeight - totalY) / 2 + ((Sensor)sensor).LocY * totalY; Canvas.SetTop(sensorRect, startPosY); Canvas.SetLeft(sensorRect, startPosX); Canvas.SetTop(sensorViewBox, startPosY + sensorIconHeight + 2); Canvas.SetLeft(sensorViewBox, startPosX - sensorTextWidth / 2 + sensorIconWidth / 2); // Determine the color string priorityCategory = (_viewModel.SensorCategorySelected == null) ? null : _viewModel.SensorCategorySelected.Name; Color color = SensorType.GetBestColorForSensor(sensor, priorityCategory); if ((sensorRect.Fill as SolidColorBrush).Color != color) { sensorRect.Fill = new SolidColorBrush(color); //sensorText.Foreground = new SolidColorBrush(color); } sensorRect.Visibility = Visibility.Visible; sensorViewBox.Visibility = Visibility.Visible; } else { sensorRect.Visibility = Visibility.Collapsed; sensorViewBox.Visibility = Visibility.Collapsed; } } sensorCanvas.InvalidateArrange(); sensorCanvas.UpdateLayout(); }
private void AddSensorToCanvas(SensorViewModel sensorViewModel) { Sensor sensor = sensorViewModel; double totalX = floorplanImage.ActualWidth; double totalY = floorplanImage.ActualHeight; // Draw Rectangle Rectangle sensorRect = new Rectangle { //Width = sensor.SizeX * totalX, //Height = sensor.SizeY * totalY, Width = sensorIconWidth, Height = sensorIconHeight, Fill = new SolidColorBrush(SensorType.GetBestColorForSensor(sensorViewModel)) { Opacity = 0.0 }, Stroke = new SolidColorBrush(SensorType.GetBestColorForSensor(sensorViewModel)), StrokeThickness = 2, StrokeDashCap = PenLineCap.Round, Opacity = 0.1, }; Canvas.SetZIndex(sensorRect, 0); // Draw Text TextBlock sensorText = new TextBlock { //Foreground = new SolidColorBrush(SensorType.GetBestColorForSensor(sensorViewModel)), Foreground = new SolidColorBrush(Colors.Black), Text = sensor.Name, TextAlignment = TextAlignment.Center, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Center }; Color bgColor = Colors.LightGray; bgColor.A = 0xA0; Border sensorTextBorder = new Border { Background = new SolidColorBrush(bgColor), Child = sensorText, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch }; Viewbox sensorViewbox = new Viewbox { //Height = sensorRect.Height, //Width = sensorRect.Width, Height = sensorTextHeight, Width = sensorTextWidth, Stretch = Stretch.Uniform, Child = sensorTextBorder, HorizontalAlignment = HorizontalAlignment.Center }; Canvas.SetZIndex(sensorViewbox, 0); // Populate Sensor List canvasSensorList.Add(new Tuple <SensorViewModel, Rectangle, Viewbox>( sensorViewModel, sensorRect, sensorViewbox)); sensorCanvas.Children.Add(sensorRect); sensorCanvas.Children.Add(sensorViewbox); }
private void AddSensorToCanvas(SensorViewModel sensorViewModel) { Sensor sensor = sensorViewModel; double totalX = floorplanImage.ActualWidth; double totalY = floorplanImage.ActualHeight; CompositeTransform compositeTransform = new CompositeTransform(); // Draw Rectangle Rectangle sensorRect = new Rectangle { Width = sensor.SizeX * totalX, Height = sensor.SizeY * totalY, Fill = new SolidColorBrush(SensorType.GetBestColorForSensor(sensorViewModel)), Stroke = new SolidColorBrush(Colors.DimGray), StrokeThickness = 1, StrokeDashCap = PenLineCap.Round }; Canvas.SetZIndex(sensorRect, 0); sensorRect.ManipulationMode = ManipulationModes.All; sensorRect.ManipulationDelta += Sensor_ManipulationDelta; sensorRect.ManipulationCompleted += Sensor_ManipulationCompleted; sensorRect.RenderTransform = compositeTransform; sensorRect.RightTapped += Sensor_RightTapped; //sensorRect.PointerMoved += Sensor_PointMoved; //sensorRect.PointerExited += Sensor_PointExited; sensorRect.PointerPressed += Sensor_PointerPressed; // Draw Text TextBlock sensorText = new TextBlock { //Foreground = new SolidColorBrush(SensorType.GetBestColorForSensor(sensorViewModel)), Foreground = new SolidColorBrush(Colors.Black), Text = sensor.Name, TextAlignment = TextAlignment.Center, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Center }; Color bgColor = Colors.Gray; bgColor.A = 0x40; Border sensorTextBorder = new Border { Background = new SolidColorBrush(bgColor), Child = sensorText, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch }; Viewbox sensorViewbox = new Viewbox { Height = sensorRect.Height, Width = sensorRect.Width, Stretch = Stretch.Uniform, Child = sensorTextBorder, HorizontalAlignment = HorizontalAlignment.Center }; Canvas.SetZIndex(sensorViewbox, 0); sensorViewbox.ManipulationMode = ManipulationModes.All; sensorViewbox.ManipulationStarted += Sensor_ManipulationStarted; sensorViewbox.ManipulationDelta += Sensor_ManipulationDelta; sensorViewbox.ManipulationCompleted += Sensor_ManipulationCompleted; sensorViewbox.RenderTransform = compositeTransform; sensorViewbox.RightTapped += Sensor_RightTapped; //sensorViewbox.PointerMoved += Sensor_PointMoved; //sensorViewbox.PointerExited += Sensor_PointExited; sensorText.PointerPressed += Sensor_PointerPressed; // Populate Sensor List canvasSensorList.Add(new Tuple <SensorViewModel, Rectangle, Viewbox, CompositeTransform>( sensorViewModel, sensorRect, sensorViewbox, compositeTransform)); sensorCanvas.Children.Add(sensorRect); sensorCanvas.Children.Add(sensorViewbox); }