示例#1
0
        private void BrushselectorBack_ChangedBrush(Controls.Special.BrushSelector brushSelector, Brush Sbrush)
        {
            lab.Background = Sbrush;

            if (Sbrush is ImageBrush)
            {
                if (lab.Tag != null)
                {
                    DesignSave designSave = DesignSave.Deserialize(lab.Tag.ToString());
                    designSave.Background = new ImageRepresentation(brushSelector.LastSelectedImageKey, ((ImageBrush)lab.Background).Stretch);
                    lab.Tag = designSave.Serialize();
                }
                else
                {
                    lab.Tag = new DesignSave(new ImageRepresentation(brushSelector.LastSelectedImageKey, ((ImageBrush)lab.Background).Stretch)).Serialize();
                }
            }
        }
示例#2
0
        public void SerializeWithKey(Brush brush, DataStore data, string key)
        {
            if (brush != null)
            {
                if (brush is ImageBrush)
                {
                    designSave = new DesignSave( new ImageRepresentation(key, ((ImageBrush)brush).Stretch));

                    isImage = true;
                    designSave.SerializeTransform(brush, designSave.Background);
                }
                else
                {
                    BrushS = SaveEditor.XMLSerialize(brush);
                    isImage = false;
                }
            }
        }
示例#3
0
 public void Serialize(Control element,Brush brush, DataStore data )
 {
     if (brush != null)
     {
         if(brush is ImageBrush)
         {
             if (element.Tag != null)
             {
                 DesignSave ds = DesignSave.Deserialize(element.Tag.ToString());
                 ds.Background.stretch = ((ImageBrush)brush).Stretch;
                 designSave = ds;
                 isImage = true;
                 ScaleQuality = RenderOptions.GetBitmapScalingMode(element);
                 ds.SerializeTransform(brush, ds.Background);
             }
         }
         else
         {
             BrushS = SaveEditor.XMLSerialize(brush);
             isImage = false;
         }
     }
 }
示例#4
0
        }//ToSerializableCanvas

        public static void ExtractHiddenData(DataStore data, Canvas canvas, int pos)
        {
            if ((int)data.BitmapScalingMode != 1)
            {
                RenderOptions.SetBitmapScalingMode(canvas, data.BitmapScalingMode);
            }

            if (data.pages[pos].IsImageBrush)
            {
                canvas.Background = new ImageBrush(data.archive.GetImage(data.pages[pos].ImageBrush.Path));
                ((ImageBrush)canvas.Background).Stretch = data.pages[pos].ImageBrush.stretch;
            }
            else if (data.pages[pos].CustomBrush && !String.IsNullOrWhiteSpace(data.pages[pos].canvasbrush))
            {
                canvas.Background = (Brush)SaveEditor.XMLDeserialize(data.pages[pos].canvasbrush);
            }
            else
            {
                if (data.IsImageBrush)
                {
                    canvas.Background = new ImageBrush(data.archive.GetImage(data.ImageBrush.Path));
                    ((ImageBrush)canvas.Background).Stretch = data.ImageBrush.stretch;
                }
                else if (!String.IsNullOrEmpty(data.AllBackground))
                {
                    canvas.Background = (Brush)SaveEditor.XMLDeserialize(data.AllBackground);
                }
                else
                {
                    canvas.Background = new SolidColorBrush(Colors.White);
                }
            }

            foreach (FrameworkElement frw in canvas.Children)
            {
                if (frw is Image)
                {
                    Image img = (Image)frw;


                    if (frw.Tag == null || String.IsNullOrWhiteSpace(frw.Tag.ToString()))
                    {
                        img.Source = new BitmapImage(new Uri("pack://application:,,,/Good Teacher;Component/Resources/Controls/image.png"));
                    }
                    else
                    {
                        DesignSave designSave = DesignSave.Deserialize(img.Tag.ToString());
                        designSave.ToImage(data, img);
                    }
                }
                else if (frw is Shape)
                {
                    Shape shape = (Shape)frw;

                    if (frw.Tag == null || String.IsNullOrWhiteSpace(frw.Tag.ToString()))
                    {
                    }
                    else
                    {
                        DesignSave designSave = DesignSave.Deserialize(shape.Tag.ToString());
                        designSave.ToShape(data, shape);
                    }
                }
                else if (frw is Label || frw is CheckBox || frw is RadioButton)
                {
                    Control control = (Control)frw;

                    if (frw.Tag == null || String.IsNullOrWhiteSpace(frw.Tag.ToString()))
                    {
                    }
                    else
                    {
                        DesignSave designSave = DesignSave.Deserialize(control.Tag.ToString());
                        designSave.ToControlWithForeground(data, control);
                    }


                    if (control.FontFamily.BaseUri != null && control.FontFamily.Source != null)
                    {
                        Debug.WriteLine("Ffontfamilysource: " + control.FontFamily.Source);

                        string fontfamilyloc  = "";
                        string fontfamilyfile = "";

                        if (control.FontFamily.Source.Length >= 5)
                        {
                            fontfamilyloc  = control.FontFamily.Source.Substring(0, 3);
                            fontfamilyfile = control.FontFamily.Source.Substring(0, 5);
                        }

                        if (!string.IsNullOrWhiteSpace(control.FontFamily.Source) && (fontfamilyloc == "./#" || fontfamilyfile == "file:"))
                        {
                            //Debug.WriteLine("-------------------\nBU: " + control.FontFamily.BaseUri + "\nFF: " + control.FontFamily + "\nAP: " + control.FontFamily.BaseUri.AbsolutePath + "\nAU: " + control.FontFamily.BaseUri.AbsoluteUri + "\nH: " + control.FontFamily.BaseUri.Host + "\nS: " + control.FontFamily.Source + "\n********\n");

                            FontFamily fontFamily;
                            if (FontWorker.GetFontFamily(control.FontFamily, out fontFamily))
                            {
                                control.FontFamily = fontFamily;
                            }
                        }
                    }
                }
                else if (frw is MediaPlayer_Control)
                {
                    //Nothing
                }
                else if (frw is Control)
                {
                    Control control = (Control)frw;

                    if (frw.Tag == null || String.IsNullOrWhiteSpace(frw.Tag.ToString()))
                    {
                    }
                    else
                    {
                        DesignSave designSave = DesignSave.Deserialize(control.Tag.ToString());
                        designSave.ToControl(data, control);
                    }

                    if (control.FontFamily.BaseUri != null)
                    {
                        //Debug.WriteLine(""+ control.FontFamily.BaseUri+ "  "+ control.FontFamily+"    AP: "+control.FontFamily.BaseUri.AbsolutePath+"   AU: "+control.FontFamily.BaseUri.AbsoluteUri+"   H: "+control.FontFamily.BaseUri.Host+ "   S: "+control.FontFamily.Source);

                        FontFamily fontFamily;
                        if (FontWorker.GetFontFamily(control.FontFamily, out fontFamily))
                        {
                            control.FontFamily = fontFamily;
                        }
                    }
                }
            }

            DeserializeCustomControls(data, canvas, pos);
        }
示例#5
0
        public static void ToSerializableCanvas(DataStore data, Canvas canvas, int pos)
        {
            SerializeCustomControls(data, canvas, pos);

            if (data.pages[pos].IsImageBrush)
            {
                data.archive.StoreImage(data.pages[pos].ImageBrush.Path, "" + data.LastAddedImageID++);
            }
            canvas.Background = null;

            foreach (FrameworkElement frw in canvas.Children)
            {
                if (frw is Image) //Image
                {
                    Image img = (Image)frw;
                    if (img.Source != null)
                    {
                        if (img.Tag != null)
                        {
                            DesignSave ds = DesignSave.Deserialize(img.Tag.ToString());
                            ds.Background.stretch = img.Stretch;
                            img.Tag = ds.Serialize();
                        }

                        img.Source = null;
                    }
                }
                else if (frw is Shape) //Shape
                {
                    Shape shape = (Shape)frw;
                    if (shape.Fill != null)
                    {
                        if (shape.Fill is ImageBrush)
                        {
                            if (shape.Tag != null)
                            {
                                DesignSave ds = DesignSave.Deserialize(shape.Tag.ToString());
                                ds.Background.stretch = ((ImageBrush)shape.Fill).Stretch;
                                ds.SerializeTransform(shape.Fill, ds.Background);
                                shape.Tag = ds.Serialize();
                            }

                            shape.Fill = null;
                        }
                        else
                        {
                            shape.Tag = null;
                        }
                    }
                }
                else if (frw is Label) //Label
                {
                    Control control = (Control)frw;

                    if (control.Tag != null)
                    {
                        DesignSave ds = DesignSave.Deserialize(control.Tag.ToString());

                        if (control.Background != null)
                        {
                            if (control.Background is ImageBrush)
                            {
                                ds.Background.stretch = ((ImageBrush)control.Background).Stretch;
                                ds.SerializeTransform(control.Background, ds.Background);
                                control.Background = null;
                            }
                            else
                            {
                                ds.Background.Path = "";
                            }
                        }


                        if (control.Foreground != null)
                        {
                            if (control.Foreground is ImageBrush)
                            {
                                ds.Foreground.stretch = ((ImageBrush)control.Foreground).Stretch;
                                ds.SerializeTransform(control.Foreground, ds.Foreground);
                                control.Foreground = null;
                            }
                            else
                            {
                                ds.Foreground.Path = "";
                            }
                        }

                        control.Tag = ds.Serialize();
                    }
                }
                else if (frw is CheckBox || frw is RadioButton) //Control
                {
                    Control cont = (Control)frw;
                    if (cont.Foreground != null)
                    {
                        if (cont.Foreground is ImageBrush)
                        {
                            if (cont.Tag != null)
                            {
                                DesignSave ds = DesignSave.Deserialize(cont.Tag.ToString());
                                ds.Foreground.stretch = ((ImageBrush)cont.Foreground).Stretch;
                                ds.SerializeTransform(cont.Foreground, ds.Foreground);
                                cont.Tag = ds.Serialize();
                            }

                            cont.Foreground = null;
                        }
                        else
                        {
                            cont.Tag = null;
                        }
                    }
                }
                else if (frw is Control) //Control
                {
                    Control cont = (Control)frw;
                    if (cont.Background != null)
                    {
                        if (cont.Background is ImageBrush)
                        {
                            if (cont.Tag != null)
                            {
                                DesignSave ds = DesignSave.Deserialize(cont.Tag.ToString());
                                ds.Background.stretch = ((ImageBrush)cont.Background).Stretch;
                                ds.SerializeTransform(cont.Background, ds.Background);
                                cont.Tag = ds.Serialize();
                            }

                            cont.Background = null;
                        }
                        else
                        {
                            cont.Tag = null;
                        }
                    }
                }
            }
        }//ToSerializableCanvas