コード例 #1
0
        private void InitSettings()
        {
            bottomPanel = new Panel();
            bottomPanel.Location = new Point(260, 409);
            bottomPanel.Size = new Size(438, 185);
            bottomPanel.BackColor = Color.FromArgb(41, 41, 41);
            bottomPanel.Click += new EventHandler(bottomPanel_MouseClick);
            this.Controls.Add(bottomPanel);

            curSlot = new ActionSlot();
            curSlot.Location = new Point(46, 20);
            curSlot.Size = new Size(70, 70);
            curSlot.BackColor = Color.FromArgb(30,30,30);
            curSlot.MouseClick += new MouseEventHandler(curSlot_MouseClick);
            bottomPanel.Controls.Add(curSlot);

            ContextMenu menu = new ContextMenu();
            menu.MenuItems.Add("&Set Image", new EventHandler(menu_SetImage_Click));
            menu.MenuItems.Add("&Reset to Default", new EventHandler(menu_Reset_Click));
            menu.Popup += new EventHandler(menu_Popup);
            curSlot.ContextMenu = menu;

            deleteButton = new SPButton();
            deleteButton.Location = new Point(51, 130);
            deleteButton.Size = new Size(61, 26);
            deleteButton.FlatStyle = FlatStyle.Flat;
            deleteButton.FlatAppearance.BorderSize = 0;
            deleteButton.FlatAppearance.BorderColor = Color.FromArgb(41,41,41);
            deleteButton.BackgroundImage = Properties.Resources.deleteButton;
            deleteButton.FlatAppearance.MouseDownBackColor = Color.Transparent;
            deleteButton.FlatAppearance.MouseOverBackColor = Color.Transparent;
            deleteButton.BackColor = Color.Transparent;
            deleteButton.Cursor = Cursors.Hand;
            deleteButton.MouseEnter += new EventHandler(deleteButton_Enter);
            deleteButton.MouseLeave += new EventHandler(deleteButton_Leave);
            deleteButton.MouseClick += new MouseEventHandler(deleteButton_Click);
            bottomPanel.Controls.Add(deleteButton);

            titleLabel = new Label();
            titleLabel.AutoSize = false;
            titleLabel.Location = new Point(LABEL_POS_X, 21);
            titleLabel.Size = new Size(LABEL_WIDTH, 24);
            titleLabel.TextAlign = ContentAlignment.MiddleRight;
            titleLabel.Text = "Title:";
            titleLabel.Font = new Font("Segoe UI", 10f,  FontStyle.Regular);
            titleLabel.ForeColor = Color.FromArgb(120, 120, 120);
            bottomPanel.Controls.Add(titleLabel);

            title = new TextBox();
            title.Location = new Point(TEXT_POS_X, 26);
            title.Width = TEXT_WIDTH;
            title.Font = new Font("Segoe UI", 10f, FontStyle.Regular);
            title.ForeColor = Color.FromArgb(120, 120, 120);
            title.BackColor = Color.FromArgb(30, 30, 30);
            title.BorderStyle = BorderStyle.None;
            title.TextChanged += new EventHandler(title_TextChanged);
            bottomPanel.Controls.Add(title);

            HideSettings();
        }
コード例 #2
0
        private void action_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                isDrag     = true;
                dragObject = ((Button)sender);
                HideSettings();
                borderedSlot = null;
                Invalidate(true);

                Point  ptStart = this.PointToScreen(new Point(e.X, e.Y));
                int    relX    = ptStart.X - this.Location.X;
                int    relY    = ptStart.Y - this.Location.Y;
                Bitmap bm      = CursorUtil.AsBitmapWithCursor((Button)sender);
                if (dragCursor != null)
                {
                    dragCursor.Dispose();
                }
                dragCursor = CursorUtil.CreateCursor((Bitmap)bm, relX + CursorUtil.cursorSize, relY + CursorUtil.cursorSize);

                this.DoDragDrop(((Action)sender).Type, DragDropEffects.All);
                Cursor.Current = dragCursor;
            }
            else
            {
                isDrag = false;
            }
        }
コード例 #3
0
        private void slot_MouseMove(object sender, MouseEventArgs e)
        {
            var p = Cursor.Position;

            if (lastMoveSlot != p)
            {
                lastMoveSlot = p;

                if (slotMouseDown && ((ActionSlot)sender).Type != SlotType.None && ((ActionSlot)sender).Type != SlotType.FolderBack)
                {
                    isDrag       = true;
                    borderedSlot = null;
                    Invalidate(true);

                    Point  ptStart = this.PointToScreen(new Point(e.X, e.Y));
                    int    relX    = ptStart.X - this.Location.X;
                    int    relY    = ptStart.Y - this.Location.Y;
                    Bitmap bm      = CursorUtil.AsBitmapWithCursor((ActionSlot)sender);
                    if (dragCursor != null)
                    {
                        dragCursor.Dispose();
                    }
                    dragCursor = CursorUtil.CreateCursor((Bitmap)bm, relX + CursorUtil.cursorSize, relY + CursorUtil.cursorSize);

                    startDragSlot = ((ActionSlot)sender);

                    int  id          = GetSlotId((ActionSlot)sender);
                    Slot draggedSlot = Storage.CurProfile.GetPageByPath(Storage.CurPathString()).Slots.Find(s => s.Id == id);
                    this.DoDragDrop((Slot)draggedSlot, DragDropEffects.All);
                    Cursor.Current = dragCursor;
                }
            }
        }
コード例 #4
0
        private void slot_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (((ActionSlot)sender).Type == SlotType.Folder)
            {
                int id = GetSlotId((ActionSlot)sender);
                Storage.CurPath.Add(id);

                HideSettings();

                borderedSlot = null;
                Invalidate(true);
            }
            else if (((ActionSlot)sender).Type == SlotType.FolderBack)
            {
                Storage.CurPath.Remove(Storage.CurPath.Last());

                borderedSlot = null;
                Invalidate(true);
            }

            if (Storage.CurPathString() == "")
            {
                ((Control)Slots[0]).AllowDrop = true;
            }

            SyncSlots();
        }
コード例 #5
0
 private void Form1_Resize(object sender, EventArgs e)
 {
     if (FormWindowState.Minimized == this.WindowState)
     {
         borderedSlot = null;
         this.Hide();
     }
 }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        private void slot_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(SlotType)))
            {
                e.Effect = DragDropEffects.Copy;
            }
            if (e.Data.GetDataPresent(typeof(Slot)))
            {
                e.Effect = DragDropEffects.Copy;
            }

            borderedSlot = (ActionSlot)sender;
            Invalidate(true);
        }
コード例 #8
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            isDrag        = false;
            slotMouseDown = false;

            if (e.Button == MouseButtons.Left && isDrag)
            {
                foreach (ActionSlot slot in Slots)
                {
                    Point     pt = slot.PointToClient(Cursor.Position);
                    Rectangle rc = slot.ClientRectangle;
                    if (rc.Contains(pt))
                    {
                        borderedSlot = slot;
                    }
                }
            }
        }
コード例 #9
0
        private void ShowSlotSettings(ActionSlot actionSlot)
        {
            SlotPage page = Storage.GetSlotPage();
            Slot slot = null;
            int id = 1;
            if (page != null)
            {
                id = GetSlotId(actionSlot);
                slot = page.Slots.Find(s => s.Id == id);
            }

            if (slot == null) return;

            switch (slot.Type)
            {
                case SlotType.None:
                    break;
                case SlotType.Folder:
                    break;
                case SlotType.FolderBack:
                    break;
                case SlotType.OpenApp:
                    break;
                case SlotType.Website:
                    break;
                case SlotType.Hotkey:
                    break;
            }

            curSlot.BackgroundImage = actionSlot.BackgroundImage;
            title.Text = Storage.GetSetting(id, "Title");

            bottomPanel.Visible = true;

            isVisible = true;
        }
コード例 #10
0
        private void slot_MouseDown(object sender, MouseEventArgs e)
        {
            borderedSlot = (ActionSlot)sender;

            if (((ActionSlot)sender).Type != SlotType.FolderBack)
            {
                slotMouseDown = true;

                if (((ActionSlot)sender).Type != SlotType.None)
                {
                    ShowSlotSettings((ActionSlot)sender);
                }
                else
                {
                    HideSettings();
                }
            }
            else
            {
                HideSettings();
            }

            Invalidate(true);
        }
コード例 #11
0
        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);
            }
        }
コード例 #12
0
 private void Form1_MouseClick(object sender, MouseEventArgs e)
 {
     HideSettings();
     borderedSlot = null;
     Invalidate(true);
 }
コード例 #13
0
 private void slot_DragLeave(object sender, EventArgs e)
 {
     borderedSlot = null;
     Invalidate(true);
 }
コード例 #14
0
        private int GetSlotId(ActionSlot slot)
        {
            int id = Int32.Parse(Regex.Match(slot.Name, @"\d+").Value);

            return(id);
        }