Beispiel #1
0
 //Заливка примитивов
 public static void Fill(Shape shape, Color color)
 {
     if (shape.GetType() == typeof(Rectangle))
     {
         SolidColorBrush mySolidColorBrush = new SolidColorBrush(color);
         shape.Fill = mySolidColorBrush;
     }
 }
Beispiel #2
0
        //Заполнение структуры WorkSpaceObject
        private static void AddValuesToWorkSpaceObject(WorkSpaceObjects workSpaceObject, Shape currentShape)
        {
            string          figureTypeString;
            SolidColorBrush brush;
            MyColor         myColor;

            workSpaceObject.height.Add(currentShape.Height);
            workSpaceObject.width.Add(currentShape.Width);
            workSpaceObject.thickness.Add(currentShape.StrokeThickness);
            brush   = currentShape.Stroke as SolidColorBrush;
            myColor = SetMyColor(brush.Color);
            workSpaceObject.borderBrush.Add(myColor);

            if (currentShape.GetType() == typeof(Rectangle))
            {
                figureTypeString = typeof(Rectangle).ToString();
                workSpaceObject.shapeType.Add(figureTypeString);
                workSpaceObject.polylinePoints.Add(null);
                double angle = GetRotationAngle(currentShape);
                workSpaceObject.rotateAngle.Add(angle);

                workSpaceObject.position.Add(GetPosition(currentShape));

                brush   = currentShape.Fill as SolidColorBrush;
                myColor = SetMyColor(brush.Color);
                workSpaceObject.fillBrush.Add(myColor);
            }
            else if (currentShape.GetType() == typeof(Polyline))
            {
                figureTypeString = typeof(Polyline).ToString();
                workSpaceObject.shapeType.Add(figureTypeString);
                workSpaceObject.rotateAngle.Add(0);
                List <Point> polylinePoints = new();
                for (int j = 0; j < ((Polyline)currentShape).Points.Count; j++)
                {
                    polylinePoints.Add(((Polyline)currentShape).Points[j]);
                }
                workSpaceObject.polylinePoints.Add(polylinePoints);
                workSpaceObject.position.Add(new Rect(0, 0, 0, 0));
                myColor = SetMyColor(Colors.Transparent);
                workSpaceObject.fillBrush.Add(myColor);
            }
        }
Beispiel #3
0
        //Сдвиг примитивов
        public static void Reposition(Shape shape, double leftShift, double topShift)
        {
            TranslateTransform translateTransform = new(leftShift, topShift);

            if (shape.RenderTransform is TransformGroup myTransformGroup)
            {
                if (shape.GetType() == typeof(Polyline))
                {
                    for (int i = 0; i < ((Polyline)shape).Points.Count; i++)
                    {
                        ((Polyline)shape).Points[i] = translateTransform.Transform(((Polyline)shape).Points[i]);
                    }
                }
                else if (shape.GetType() == typeof(Rectangle))
                {
                    myTransformGroup.Children.Add(translateTransform);
                    shape.RenderTransform = myTransformGroup;
                }
            }
        }
Beispiel #4
0
 //Изменение размеров примитивов
 public static void Resize(Shape shape, Rect rect)
 {
     if (shape.GetType() == typeof(Rectangle))
     {
         double angle = GetRotationAngle(shape);
         shape.Height = rect.Height;
         shape.Width  = rect.Width;
         TransformGroup newTransformGroup = new();
         Point          Center            = GetCenter(rect);
         newTransformGroup.Children.Add(new TranslateTransform(rect.X, rect.Y));
         newTransformGroup.Children.Add(new RotateTransform(angle, Center.X, Center.Y));
         shape.RenderTransform = newTransformGroup;
     }
 }