private FrameworkElement RenderActiveObject(MapActiveObjectState activeObject, Rect area) { if (activeObject == null) { return(null); } if (activeObject.ActiveObject == null) { return(null); } MapImageWPF imageSource = new MapImageWPF(activeObject.Image); Image image = new Image { Source = imageSource.Image, Stretch = Stretch.Fill }; double wallWidth = area.Width * WallPadding; double wallHeight = area.Height * WallPadding; double imageWidth = area.Width - wallWidth * 2; double imageHeight = area.Height - wallHeight * 2; Canvas.SetLeft(image, area.Left + wallWidth); Canvas.SetTop(image, area.Top + wallHeight); image.Width = imageWidth; image.Height = imageHeight; return(image); }
private FrameworkElement RenderWall(MapWallState wall, Rect area) { if (wall == null) { return(null); } if (wall.Wall == null) { return(null); } MapImageWPF imageSource = new MapImageWPF(wall.CurrentImage); Image image = new Image { Source = imageSource.Image }; double wallWidth = area.Width * WallPadding; double wallHeight = area.Height * WallPadding; double imageWidth = area.Width; double imageHeight = wallHeight; image.Stretch = Stretch.Fill; if (wall.Direction == MapDirection.North) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top); image.Width = imageWidth; image.Height = imageHeight; } if (wall.Direction == MapDirection.South) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top + area.Height); image.Width = imageWidth; image.Height = imageHeight; image.RenderTransformOrigin = new Point(0.5, 0); image.RenderTransform = new RotateTransform(-180); } if (wall.Direction == MapDirection.West) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top + imageWidth); image.Width = imageWidth; image.Height = imageHeight; image.RenderTransformOrigin = new Point(0, 0); image.RenderTransform = new RotateTransform(-90); } if (wall.Direction == MapDirection.East) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top + imageWidth); image.Width = imageWidth; image.Height = imageHeight; image.RenderTransformOrigin = new Point(1, 0); image.RenderTransform = new RotateTransform(90); } return(image); }
public void TestConversion() { try { byte[] data = new byte[] { 1, 2, 3, 4, 5 }; MapImage tile = new MapImage(MapImageType.Bmp, data); MapImageWPF image = new MapImageWPF(tile); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(InvalidDataException)); } }
private FrameworkElement RenderPlace(MapPlaceState place, Rect area) { if (place == null) { return(null); } if (place.Place == null) { return(null); } MapImageWPF imageSource = new MapImageWPF(place.Image); Image image = new Image { Source = imageSource.Image, Stretch = Stretch.Fill }; Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top); image.Width = area.Width; image.Height = area.Height; return(image); }
private static FrameworkElement CreateValueControl(PropertyInfo property, object targetObject) { if (property == null) return null; if (targetObject == null) return null; Type type = property.PropertyType; if (type == null) return null; object val = property.GetValue(targetObject, null); FrameworkElement result = new FrameworkElement(); if (type.IsEnum) { ComboBox comboBox = new ComboBox(); comboBox.ItemsSource = type.GetEnumValues(); Binding itemBinding = new Binding(property.Name) { Mode = BindingMode.TwoWay, Source = targetObject, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; comboBox.SetBinding(ComboBox.SelectedItemProperty, itemBinding); result = comboBox; } else { if (type.Equals(typeof(MapImageWPF)) || type.IsSubclassOf(typeof(MapImageWPF))) { ImageSource imageSource = (val as MapImageWPF).Image; Image image = new Image(); image.Source = imageSource ?? new BitmapImage(new Uri("Images/no_image.gif", UriKind.Relative)); Viewbox box = new Viewbox(); box.Child = image; box.HorizontalAlignment = HorizontalAlignment.Center; box.VerticalAlignment = VerticalAlignment.Center; box.Width = 100; box.Height = 100; image.MouseLeftButtonUp += (s, e) => { var dialog = new Microsoft.Win32.OpenFileDialog() { CheckFileExists = true, CheckPathExists = true }; if (dialog.ShowDialog() == true) { string fileName = dialog.FileName; byte[] data; using (var file = File.OpenRead(fileName)) { data = new byte[file.Length]; file.Read(data, 0, data.Length); } MapImageWPF newImage = new MapImageWPF(MapImageType.Custom, data); image.Source = newImage.Image ?? new BitmapImage(new Uri("Images/no_image.gif", UriKind.Relative)); property.SetValue(targetObject, newImage, null); } }; result = box; } else { if (type.Equals(typeof(bool))) { CheckBox checkBox = new CheckBox(); Binding boolBinding = new Binding(property.Name) { Mode = BindingMode.TwoWay, Source = targetObject, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, ValidatesOnDataErrors = true }; checkBox.SetBinding(CheckBox.IsCheckedProperty, boolBinding); result = checkBox; } else { TextBox textBox = new TextBox(); Binding textBinding = new Binding(property.Name) { Mode = BindingMode.TwoWay, Source = targetObject, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, ValidatesOnDataErrors = true }; textBox.SetBinding(TextBox.TextProperty, textBinding); result = textBox; } } } if (result != null) { result.Margin = new Thickness(5); } return result; }
private FrameworkElement RenderWallCorner(MapWallState wall1, MapWallState wall2, Rect area) { if (wall1 == null) { return(null); } if (wall1.Wall == null) { return(null); } if (wall2 == null) { return(null); } if (wall2.Wall == null) { return(null); } if (wall1.Wall.Id != wall2.Wall.Id) { return(null); } MapImage cornerImage = wall1.Wall.ImageCorner; if (cornerImage == null) { return(null); } double wallWidth = area.Width * WallPadding; double wallHeight = area.Height * WallPadding; MapImageWPF imageSource = new MapImageWPF(cornerImage); double imageWidth = wallWidth; double imageHeight = wallHeight; Image image = new Image { Source = imageSource.Image, Width = imageWidth, Height = imageHeight, Stretch = Stretch.Uniform }; image.RenderTransformOrigin = new Point(0.5, 0.5); if ((wall1.Direction == MapDirection.North) && (wall2.Direction == MapDirection.West)) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top); } if ((wall1.Direction == MapDirection.North) && (wall2.Direction == MapDirection.East)) { Canvas.SetLeft(image, area.Left + area.Width - imageWidth); Canvas.SetTop(image, area.Top); image.RenderTransform = new RotateTransform(90); } if ((wall1.Direction == MapDirection.South) && (wall2.Direction == MapDirection.West)) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top + area.Height - imageHeight); image.RenderTransform = new RotateTransform(-90); } if ((wall1.Direction == MapDirection.South) && (wall2.Direction == MapDirection.East)) { Canvas.SetLeft(image, area.Left + area.Width - imageWidth); Canvas.SetTop(image, area.Top + area.Height - imageHeight); image.RenderTransform = new RotateTransform(180); } return(image); }
private FrameworkElement RenderWallCorner(MapWallState wall1, MapWallState wall2, Rect area) { if (wall1 == null) return null; if (wall1.Wall == null) return null; if (wall2 == null) return null; if (wall2.Wall == null) return null; if (wall1.Wall.Id != wall2.Wall.Id) return null; MapImage cornerImage = wall1.Wall.ImageCorner; if (cornerImage == null) return null; double wallWidth = area.Width * WallPadding; double wallHeight = area.Height * WallPadding; MapImageWPF imageSource = new MapImageWPF(cornerImage); double imageWidth = wallWidth; double imageHeight = wallHeight; Image image = new Image { Source = imageSource.Image, Width = imageWidth, Height = imageHeight, Stretch= Stretch.Uniform}; image.RenderTransformOrigin = new Point(0.5, 0.5); if ((wall1.Direction == MapDirection.North) && (wall2.Direction == MapDirection.West)) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top); } if ((wall1.Direction == MapDirection.North) && (wall2.Direction == MapDirection.East)) { Canvas.SetLeft(image, area.Left + area.Width - imageWidth); Canvas.SetTop(image, area.Top); image.RenderTransform = new RotateTransform(90); } if ((wall1.Direction == MapDirection.South) && (wall2.Direction == MapDirection.West)) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top + area.Height - imageHeight); image.RenderTransform = new RotateTransform(-90); } if ((wall1.Direction == MapDirection.South) && (wall2.Direction == MapDirection.East)) { Canvas.SetLeft(image, area.Left + area.Width - imageWidth); Canvas.SetTop(image, area.Top + area.Height - imageHeight); image.RenderTransform = new RotateTransform(180); } return image; }
private FrameworkElement RenderWall(MapWallState wall, Rect area) { if (wall == null) return null; if (wall.Wall == null) return null; MapImageWPF imageSource = new MapImageWPF(wall.CurrentImage); Image image = new Image { Source = imageSource.Image }; double wallWidth = area.Width * WallPadding; double wallHeight = area.Height * WallPadding; double imageWidth = area.Width; double imageHeight = wallHeight; image.Stretch = Stretch.Fill; if (wall.Direction == MapDirection.North) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top); image.Width = imageWidth; image.Height = imageHeight; } if (wall.Direction == MapDirection.South) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top + area.Height); image.Width = imageWidth; image.Height = imageHeight; image.RenderTransformOrigin = new Point(0.5, 0); image.RenderTransform = new RotateTransform(-180); } if (wall.Direction == MapDirection.West) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top + imageWidth); image.Width = imageWidth; image.Height = imageHeight; image.RenderTransformOrigin = new Point(0, 0); image.RenderTransform = new RotateTransform(-90); } if (wall.Direction == MapDirection.East) { Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top + imageWidth); image.Width = imageWidth; image.Height = imageHeight; image.RenderTransformOrigin = new Point(1, 0); image.RenderTransform = new RotateTransform(90); } return image; }
private FrameworkElement RenderPlace(MapPlaceState place, Rect area) { if (place == null) return null; if (place.Place == null) return null; MapImageWPF imageSource = new MapImageWPF(place.Image); Image image = new Image { Source = imageSource.Image, Stretch = Stretch.Fill }; Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top); image.Width = area.Width; image.Height = area.Height; return image; }
private FrameworkElement RenderActiveObject(MapActiveObjectState activeObject, Rect area) { if (activeObject == null) return null; if (activeObject.ActiveObject == null) return null; MapImageWPF imageSource = new MapImageWPF(activeObject.Image); Image image = new Image { Source = imageSource.Image, Stretch = Stretch.Fill }; double wallWidth = area.Width * WallPadding; double wallHeight = area.Height * WallPadding; double imageWidth = area.Width - wallWidth * 2; double imageHeight = area.Height - wallHeight * 2; Canvas.SetLeft(image, area.Left + wallWidth); Canvas.SetTop(image, area.Top + wallHeight); image.Width = imageWidth; image.Height = imageHeight; return image; }