private void InitLabels() { for (int i = 0; i < Slots.Count; i++) { SlotLabel _label = new SlotLabel(); this.Controls.Add(_label); _label.AutoSize = false; _label.Size = new Size(70, 70); _label.Text = Storage.GetSetting(i + 1, "Title"); _label.ForeColor = Color.FromArgb(160, 160, 160); _label.BackColor = Color.Transparent; _label.TextAlign = ContentAlignment.BottomCenter; Labels.Add(_label); } for (int i = 0; i < Slots.Count; i++) { var pos = this.PointToScreen(Labels[i].Location); pos = Slots[i].PointToClient(pos); Labels[i].Parent = Slots[i]; Labels[i].Location = new Point(0, 0); Labels[i].BackColor = Color.Transparent; Labels[i].BringToFront(); } }
private void slot_DragDrop(object sender, DragEventArgs e) { isDrag = false; slotMouseDown = false; borderedSlot = (ActionSlot)sender; if (((ActionSlot)sender).Type != SlotType.FolderBack) { if (e.Data.GetDataPresent(typeof(SlotType))) { ((ActionSlot)sender).Type = (SlotType)e.Data.GetData(typeof(SlotType)); int id = GetSlotId((ActionSlot)sender); Storage.CurProfile.AddNewSlot(Storage.CurPathString(), id, ((ActionSlot)sender).Type); //Storage.SaveData(); //SyncSlots(); //SaveSlotImage(id, false); // TODO: Save second state default image } else if (e.Data.GetDataPresent(typeof(Slot))) { int fromId = GetSlotId(startDragSlot); int toId = GetSlotId((ActionSlot)sender); SlotLabel label_from = startDragSlot.Controls.OfType <SlotLabel>().First(); SlotLabel label_to = ((ActionSlot)sender).Controls.OfType <SlotLabel>().First(); string tmp = label_from.Text; label_from.Text = label_to.Text; label_to.Text = tmp; Storage.CurProfile.SwapSlots(Storage.CurPathString(), fromId, toId); SaveButtonImage(fromId); //Storage.SaveData(); //SyncSlots(); //if (Storage.GetSlotById(toId) != null) SaveSlotImage(toId, false); //if (Storage.GetSlotById(fromId) != null) SaveSlotImage(fromId, false); // TODO: Save second state default image } Storage.SaveData(); SyncSlots(); ShowSlotSettings((ActionSlot)sender); Invalidate(true); } }
private void SaveButtonImage(int id) { if (Slots[id - 1] == null || Storage.GetSlotById(id) == null) return; string filename_0 = Storage.GetSlotById(id).Image_0; string filename_1 = Storage.GetSlotById(id).Image_1; string baseName = Storage.CurPathString(); if (baseName != "") baseName += "."; string saveName_0 = baseName + id.ToString() + "_0.png"; string saveName_1 = baseName + id.ToString() + "_1.png"; try { Bitmap slotImage_0 = Bitmap.FromFile(filename_0) as Bitmap; Graphics g = Graphics.FromImage(slotImage_0); g.InterpolationMode = InterpolationMode.HighQualityBilinear; g.PixelOffsetMode = PixelOffsetMode.HighQuality; SlotLabel label = Slots[id - 1].Controls.OfType<SlotLabel>().First(); if (label != null) { Bitmap label_bmp = new Bitmap(label.Width, label.Height); label.DrawToBitmap(label_bmp, new Rectangle(0, 0, label.Width, label.Height)); g.CompositingMode = CompositingMode.SourceOver; g.DrawImage(label_bmp, new Rectangle(0, 0, label.Width, label.Height)); } string save = Storage.ButtonsDir + "\\" + saveName_0; if (File.Exists(save)) File.Delete(save); slotImage_0.Save(save); g.Flush(); Bitmap slotImage_1 = new Bitmap(70,70); g = Graphics.FromImage(slotImage_1); g.InterpolationMode = InterpolationMode.HighQualityBilinear; g.PixelOffsetMode = PixelOffsetMode.HighQuality; ActionSlot sl = new ActionSlot(); sl = Slots[id - 1].Clone(); sl.BackgroundImage = Image.FromFile(filename_1); //label = sl.Controls.OfType<SlotLabel>().First(); SlotLabel l = label.Clone(); l.Parent = sl; foreach(Control c in sl.Controls) { Console.WriteLine("!"); } //label = sl.Controls.OfType<SlotLabel>().First(); //sl.DrawToBitmap(slotImage_1, new Rectangle(0, 0, sl.Width, sl.Height)); //g.DrawImage(slotImage_1, new Rectangle(0, 0, slotImage_1.Width, slotImage_1.Height)); if (l != null) { Bitmap label_bmp = new Bitmap(label.Width, label.Height); l.DrawToBitmap(label_bmp, new Rectangle(0, 0, label.Width, label.Height)); g.CompositingMode = CompositingMode.SourceOver; g.DrawImage(label_bmp, new Rectangle(0, 0, label.Width, label.Height)); } save = Storage.ButtonsDir + "\\" + saveName_1; if (File.Exists(save)) File.Delete(save); slotImage_1.Save(save); } catch(Exception err) { Console.WriteLine(err); } }
// Syncronize slots with current storage state private void SyncSlots() { SlotPage page = Storage.CurProfile.GetPageByPath(Storage.CurPathString()); foreach (ActionSlot slot in Slots) { int id = Int32.Parse(Regex.Match(slot.Name, @"\d+").Value); SlotLabel label = slot.Controls.OfType <SlotLabel>().First(); Slot found = Storage.GetSlotById(id); if (found != null) { slot.Type = found.Type; label.Text = Storage.GetSetting(id, "Title"); ((Control)slot).AllowDrop = true; //TODO: Manage image changing if (!File.Exists(found.Image_0)) { switch (found.Type) { case SlotType.None: slot.BackgroundImage = null; break; case SlotType.Folder: slot.BackgroundImage = Properties.Resources.slot_folder; break; case SlotType.FolderBack: slot.BackgroundImage = Properties.Resources.slot_folder_back; break; case SlotType.OpenApp: slot.BackgroundImage = Properties.Resources.slot_launch; break; case SlotType.Website: slot.BackgroundImage = Properties.Resources.slot_website; break; case SlotType.Hotkey: break; } } else { Image img = Bitmap.FromFile(found.Image_0); Bitmap bgImg = new Bitmap(img); img.Dispose(); slot.BackgroundImage = bgImg; } } else if (Storage.CurPathString() != "" && slot == Slots[0]) { slot.Type = SlotType.FolderBack; slot.BackgroundImage = Properties.Resources.slot_folder_back; label.Text = ""; ((Control)slot).AllowDrop = false; } else { slot.Type = SlotType.None; label.Text = ""; slot.BackgroundImage = null; } } }