예제 #1
0
        public SelfmadeSVI(ProtoDefinition protoDefinition = null)
        {
            InitializeComponent();

            if (protoDefinition != null)
            {
                this.ProtoDefinition = protoDefinition;
            }

            //apply width and height
            this.MainCanvas.Width = this.ProtoDefinition.Width;
            this.MainCanvas.Height = this.ProtoDefinition.Height;

            // applying the color
            BrushConverter cConverter = new BrushConverter();
            this.OwnColoredRectangle.Fill = cConverter.ConvertFromString(this.ProtoDefinition.Color) as SolidColorBrush;

            //TODO: apply the given image

            // initial position
            MatrixTransform matrixTransform = this.RenderTransform as MatrixTransform;
            Matrix rectsMatrix = matrixTransform.Matrix;
            rectsMatrix.Translate(this.ProtoDefinition.X, this.ProtoDefinition.Y);
            this.RenderTransform = new MatrixTransform(rectsMatrix);
        }
예제 #2
0
        public SimObject(ProtoDefinition protoDefinition = null)
        {
            InitializeComponent();

            if (protoDefinition != null)
            {
                this.ProtoDefinition = protoDefinition;
            }

            //apply width and height
            this.Width = (this.ProtoDefinition.Width * App.UnitConversionFactor) / App.DpiFactor;
            this.Height = (this.ProtoDefinition.Height * App.UnitConversionFactor) / App.DpiFactor;

            // applying the color
            BrushConverter cConverter = new BrushConverter();
            this.MainGrid.Background = cConverter.ConvertFromString(this.ProtoDefinition.Color) as SolidColorBrush;

            //apply the given image
            if (this.ProtoDefinition.ImagePath != null && this.ProtoDefinition.ImagePath != "")
            {
                this.MainGrid.Background = Brushes.Transparent;
                this.ObjectNameTextBlock.Visibility = Visibility.Hidden;

                //see if we can load an image
                try
                {
                    BitmapImage src = new BitmapImage();
                    src.BeginInit();
                    src.UriSource = new Uri(App.ProjectPath + this.ProtoDefinition.ImagePath, UriKind.Relative);
                    src.CacheOption = BitmapCacheOption.OnLoad;
                    src.EndInit();
                    this.OwnImage.Source = src;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                this.OwnImage.Visibility = Visibility.Visible;

            }

            // initial position
            MatrixTransform matrixTransform = this.RenderTransform as MatrixTransform;
            Matrix rectsMatrix = matrixTransform.Matrix;
            rectsMatrix.Translate((this.ProtoDefinition.X * App.UnitConversionFactor) / App.DpiFactor, (this.ProtoDefinition.Y * App.UnitConversionFactor) / App.DpiFactor);
            this.RenderTransform = new MatrixTransform(rectsMatrix);

            //applying the name for debugging if in devmode
            if (App.DevMode)
            {
                this.ObjectNameTextBlock.Text = this.ProtoDefinition.ObjectName;
            }

            //Rendering Event for selfmade inertia
            CompositionTarget.Rendering += CompositionTarget_Rendering;
        }