private HWTextureMapper ConvertTextureMapper(XmlNode node) { HWTextureMapper box = new HWTextureMapper(); SetValue(box, node.Attributes); return(box); }
private ContentControl AddTextureMapper(HWTextureMapper textureMapper) { Image image = new Image(); BitmapImage bitmapImage = ImageHelper.GetImage(textureMapper.Res_name); if (bitmapImage == null) { return(null); } image.Source = bitmapImage; image.Width = bitmapImage.PixelWidth; image.Height = bitmapImage.PixelHeight; image.Stretch = Stretch.Fill; ContentControl control = new ContentControl { Width = textureMapper.Drawable_width, Height = textureMapper.Drawable_height, Style = (Style)Application.Current.Resources["DesignerItemStyle"] }; image.HorizontalAlignment = HorizontalAlignment.Left; image.VerticalAlignment = VerticalAlignment.Top; image.Margin = new Thickness((textureMapper.Drawable_width - textureMapper.Rotation_center_x * 2) / 2.0, (textureMapper.Drawable_height - textureMapper.Rotation_center_y * 2.0) / 2, 0, 0); control.Content = image; canvas.Children.Add(control); Canvas.SetLeft(control, textureMapper.Drawable_x); Canvas.SetTop(control, textureMapper.Drawable_y); int value = ConstData.Datas[textureMapper.Data_type]; double angle = textureMapper.Begin_arc + (textureMapper.End_arc - textureMapper.Begin_arc) * value / 100.0; SetRotateTransform(image, new Point(textureMapper.Rotation_center_x, textureMapper.Rotation_center_y), angle); return(control); }
/// <summary> /// 刷新控件 /// </summary> private void RefreshControl() { if (WatchElement.DesignerControl != null && WatchElement.DesignerControl.Content != null && WatchElement.DesignerControl.Content is Image image) { HWTextureMapper textureMapper = WatchElement.HWElement as HWTextureMapper; image.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; image.VerticalAlignment = VerticalAlignment.Top; image.Margin = new Thickness((textureMapper.Drawable_width - textureMapper.Rotation_center_x * 2) / 2.0, (textureMapper.Drawable_height - textureMapper.Rotation_center_y * 2.0) / 2, 0, 0); int value = ConstData.Datas[textureMapper.Data_type]; double angle = textureMapper.Begin_arc + (textureMapper.End_arc - textureMapper.Begin_arc) * value / 100.0; ClockDialCreater.SetRotateTransform(image, new Point(textureMapper.Rotation_center_x, textureMapper.Rotation_center_y), angle); } }
/// <summary> /// 元素属性发生变化后 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void WatchElement_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { HWTextureMapper textureMapper = watchElement.HWElement as HWTextureMapper; switch (e.PropertyName) { case "X": textureMapper.Drawable_x = watchElement.X; break; case "Y": textureMapper.Drawable_y = watchElement.Y; break; case "Width": textureMapper.Drawable_width = watchElement.Width; break; case "Height": textureMapper.Drawable_height = watchElement.Height; break; } RefreshControl(); }