コード例 #1
0
        /// <summary>
        /// Opens the json.
        /// </summary>
        /// <param name="objects">The objects.</param>
        public void OpenJson(List <JsonObject> objects)
        {
            List <KeyValuePair <int, Control> > ctrls = new List <KeyValuePair <int, Control> >();

            foreach (JsonObject obj in objects)
            {
                if (obj is Config)
                {
                    Config config = obj as Config;
                    Enum.TryParse <Paper>(config.Paper, out Paper paper);
                    Enum.TryParse <ColorType>(config.Color, out ColorType color);
                    Enum.TryParse <Sticky>(config.Sticky, out Sticky sticky);

                    (this.Parent as NemonicForm).ChangePaper(paper);
                    (this.Parent as NemonicForm).ChangeColor(color);
                    this.ChangeSticky(paper, sticky);
                }
                else if (obj is TemplateLayer)
                {
                    TemplateLayer layer = obj as TemplateLayer;
                    this.ChangeTemplate(NemonicApp.ByteToImage(layer.image));
                }
                else if (obj is TransparentImage.ImageLayer)
                {
                    TransparentImage.ImageLayer layer = obj as TransparentImage.ImageLayer;

                    TransparentImage imageBox = new TransparentImage()
                    {
                        Location = new Point(layer.x, layer.y),
                        Image    = NemonicApp.ByteToImage(layer.image),
                        Size     = new Size(layer.width, layer.height)
                    };

                    ctrls.Add(new KeyValuePair <int, Control>(layer.priority, imageBox));
                }
                else if (obj is TransparentRichText.RichTextLayer)
                {
                    TransparentRichText.RichTextLayer layer = obj as TransparentRichText.RichTextLayer;
                    this.Layer_TextField.Font = layer.font;
                    this.Layer_TextField.SelectAll();
                    this.Layer_TextField.SelectionAlignment = layer.align;
                    this.Layer_TextField.DeselectAll();
                    this.Layer_TextField.Text = layer.text;
                }
            }

            ctrls.Sort(delegate(KeyValuePair <int, Control> A, KeyValuePair <int, Control> B)
            {
                return(B.Key.CompareTo(A.Key));
            });

            foreach (KeyValuePair <int, Control> element in ctrls)
            {
                this.AddCtrl(element.Value);
            }
        }
コード例 #2
0
        /// <summary>
        /// Saves the json.
        /// </summary>
        /// <param name="config">The configuration.</param>
        /// <param name="thumbnail">The thumbnail.</param>
        /// <returns></returns>
        public IList <JsonObject> SaveJson(Config config, Image thumbnail)
        {
            LinkedList <Control> src     = this.CtrlList;
            IList <JsonObject>   objects = new List <JsonObject>();

            config.Sticky = Convert.ToString(this.Layer_Sticky.CurrentSticky);
            objects.Add(config);

            int index = src.Count;

            for (LinkedListNode <Control> node = src.First; node != src.Last.Next; node = node.Next)
            {
                int priority = --index;
                //Layer Template만이 PictureBox일 경우를 가정하여 작성

                if (node.Value is StickyCtrl)
                {
                    continue;
                }

                if (node.Value is PictureBox)
                {
                    TemplateLayer layer = new TemplateLayer()
                    {
                        priority = priority,
                        x        = node.Value.Location.X,
                        y        = node.Value.Location.Y,
                        image    = NemonicApp.ImageToByte((node.Value as PictureBox).Image)
                    };

                    objects.Add(layer);
                }
                else if (node.Value is TransparentImage)
                {
                    TransparentImage.ImageLayer layer = new TransparentImage.ImageLayer()
                    {
                        priority = priority,
                        x        = node.Value.Location.X,
                        y        = node.Value.Location.Y,
                        width    = node.Value.Size.Width,
                        height   = node.Value.Size.Height,
                        image    = NemonicApp.ImageToByte((node.Value as TransparentImage).Image)
                    };

                    objects.Add(layer);
                }
                else if (node.Value is TransparentRichText)
                {
                    TransparentRichText.RichTextLayer layer = new TransparentRichText.RichTextLayer()
                    {
                        priority = priority,
                        x        = node.Value.Location.X,
                        y        = node.Value.Location.Y,
                        text     = (node.Value as TransparentRichText).Text,
                        font     = (node.Value as TransparentRichText).Font
                    };
                    (node.Value as TransparentRichText).SelectAll();
                    layer.align = (node.Value as TransparentRichText).SelectionAlignment;
                    (node.Value as TransparentRichText).DeselectAll();

                    objects.Add(layer);
                }
            }

            Thumbnail thumbNailData = new Thumbnail()
            {
                image = NemonicApp.ImageToByte(thumbnail)
            };

            objects.Add(thumbNailData);

            return(objects);
        }