/// <summary> /// 이미지가 레이어에 드랍되었을 때, 이미지가 레이어에 추가되는 이벤트를 발생시킨다. /// </summary> /// <param name="drgevent">The <see cref="DragEventArgs"/> instance containing the event data.</param> public void Image_DragDrop(DragEventArgs drgevent) { bool imageFileValid = LayersCtrl.CheckImageFileExt(out string path, drgevent); if (imageFileValid) { this.AddImage(NemonicApp.GetImage(path), path); } }
/// <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); } }
//TODO: Json File 정보를 조합하여, 이미지를 만들어 반영해야 한다. public MemoElement(TabCtrl control, string path, Action hide) : base(control, path) { InitializeComponent(); this.Item = Button_Memo; this.Item.DoubleClick += Item_DoubleClick; this.Item.KeyDown += Item_KeyDown; this.Title = Label_Title; this.Title.Text = Path.GetFileNameWithoutExtension(this.RootPath); //Json 파일에서 Image 파일을 생성하는 과정 //바쁜 대기라, 매우 나쁜 코드지만 더 나은 코드가 생각나지 않는다. bool isReady = false; string json = string.Empty; while (!isReady) { try { json = File.ReadAllText(this.RootPath); isReady = true; } catch (Exception e) { Console.WriteLine("Busy Wait Error!\n\t" + e.StackTrace); //isReady = false; } } //Json 정보 해석 JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; List <JsonObject> objects = JsonConvert.DeserializeObject <List <JsonObject> >(json, settings); foreach (JsonObject obj in objects) { if (obj is Thumbnail) { //Thumbnail 정보를 찾아, Element의 이미지로 세팅 Thumbnail thumbnail = obj as Thumbnail; this.Item.BackgroundImage = NemonicApp.ByteToImage(thumbnail.image); this.Item.BackgroundImageLayout = ImageLayout.Zoom; } } this.HideSettings = hide; }
public TemplateElement(TabCtrl control, string path, Action hide) : base(control, path) { InitializeComponent(); this.Item = Button_Template; this.Item.DoubleClick += Item_DoubleClick; this.Item.KeyDown += Item_KeyDown; this.Item.BackgroundImage = NemonicApp.GetImage(this.RootPath); this.Item.BackgroundImageLayout = ImageLayout.Zoom; this.Title = Label_Title; this.Title.Text = Path.GetFileNameWithoutExtension(this.RootPath); this.HideSettings = hide; }
/// <summary> /// 메모에 이미지를 추가 /// </summary> public void SpawnImage() { DialogResult result = openImageDialog.ShowDialog(); if (result == DialogResult.OK) { string path = openImageDialog.FileName; Bitmap target = NemonicApp.GetImage(path); if (target != null) { this.LayersCtrl.AddImage(target, path); } } }
/// <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); }