Beispiel #1
0
 public DesktopManager(string deserialize)
 {
     icons = new DesktopIcon[10];
     string[] serIcons = deserialize.Split(new[] { "@@" }, StringSplitOptions.None);
     foreach (string icon in serIcons)
     {
         AddIcon(DesktopIcon.Deserialize(icon, this));
     }
 }
Beispiel #2
0
        internal PointF GetSnapToGridPoint(DesktopIcon ico)
        {
            float pad = DesktopIcon.ICON_WITH_PADDING(); // All this is is the padding between icons. Not relevant.
            float x   = ico.target.X / pad;              // So we're saying "x = (icon's x / padding)"
            float y   = ico.target.Y / pad;              // So we're saying "y = (icon's y / padding)"

            x = (float)Math.Round(x);                    // Now we round x to the nearest whole number.
            y = (float)Math.Round(y);                    // Now we round y to the nearest whole number.
            return(new PointF(x * pad, y * pad));        // Return a "PointF" of the x and y locations multiplied by the padding.
        }
Beispiel #3
0
        private void ProcessIconContext(MouseEventArgs e, DesktopIcon ico, int index)
        {
            IconContext ict = new IconContext();

            void handler(object snd, FormClosedEventArgs args)
            {
                int pick = ict.buttonIndex;

                ict.Dispose();
                if (pick == 1)
                {
                    // Admin
                    Process p = new Process();
                    p.StartInfo.FileName         = ico.loc;
                    p.StartInfo.Verb             = "runas";
                    p.StartInfo.WorkingDirectory = Path.GetDirectoryName(ico.loc);
                    try {
                        p.Start();
                    } catch (Exception) { }
                    p.Exited += (object _, EventArgs _ev) =>
                    {
                        p.Dispose();
                    };
                }
                else if (pick == 2)
                {
                    // Rename
                    RenameIconWindow riw = new RenameIconWindow(ico.name);
                    riw.Location = Cursor.Position;
                    riw.ShowDialog();
                    string name = riw.name;
                    riw.Dispose();

                    ico.name        = name;
                    dm.icons[index] = ico;
                }
                else if (pick == 3)
                {
                    // Delete
                    List <DesktopIcon> ii = dm.icons.ToList();
                    ii.Remove(ico);
                    dm.icons = ii.ToArray();
                }
            }

            ict.FormClosed += handler;
            ict.Show();
            ict.Location = Cursor.Position;
        }
Beispiel #4
0
        private void Form1_DoubleClick(object sender, EventArgs e)
        {
            DesktopIcon[] icons  = dm.icons;
            Point         pos    = GetCorrectedCursorPosition();
            bool          opened = false;

            for (int i = 0; i < dm.IconCount(); i++)
            {
                DesktopIcon ico = icons[i];

                Rectangle rect  = GetRectangleFromIcon(ico);
                Rectangle mouse = new Rectangle(pos, new Size(1, 1));
                if (mouse.IntersectsWith(rect))
                {
                    opened = true;
                    //Process.Start(ico.loc); // start the program
                    Process p = new Process();
                    p.StartInfo.FileName         = ico.loc;
                    p.StartInfo.WorkingDirectory = Path.GetDirectoryName(ico.loc);
                    p.Start();
                    p.Exited += (object _, EventArgs _ev) =>
                    {
                        p.Dispose();
                    };
                }

                ico.selected = false;
                icons[i]     = ico;
                dm.icons     = icons;
            }
            if (!opened)
            {
                Random r = new Random();
                for (int i = 0; i < dm.IconCount(); i++)
                {
                    DesktopIcon ico = icons[i];
                    float       a   = (float)r.NextDouble() * 200;
                    a -= (a / 2);
                    float b = (float)r.NextDouble() * 200;
                    b -= (b / 2);
                    ico.velocity_x = a;
                    ico.velocity_y = b;
                    icons[i]       = ico;
                }
                dm.icons = icons;
            }
        }
Beispiel #5
0
 private void Form1_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         for (int i = 0; i < dm.IconCount(); i++)
         {
             DesktopIcon ico = dm.icons[i];
             Rectangle   r   = GetRectangleFromIcon(ico);
             if (PointIntersectsWithRectangle(e.Location, r))
             {
                 ProcessIconContext(e, ico, i);
                 return;
             }
         }
         ProcessDesktopContext(e);
         return;
     }
 }
Beispiel #6
0
        public void AddIcon(DesktopIcon ico)
        {
            // example: count = 9,
            //     length = 10
            //
            // insert at index 9
            int count = IconCount();

            if (count < icons.Length)
            {
                icons[count] = ico;
                return;
            }
            else
            {
                // requires resizing
                Array.Resize(ref icons, icons.Length + 10);
                icons[count] = ico;
            }
        }
Beispiel #7
0
        // INPUT
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            DesktopIcon[] icons = dm.icons;
            Point         pos   = GetCorrectedCursorPosition();

            for (int i = 0; i < dm.IconCount(); i++)
            {
                DesktopIcon ico = icons[i];
                ico.selected = false;

                Rectangle rect  = GetRectangleFromIcon(ico);
                Rectangle mouse = new Rectangle(pos, new Size(1, 1));
                if (mouse.IntersectsWith(rect))
                {
                    ico.selected   = true;
                    capturedIconID = ico.ID;
                    captureOffset  = new PointF(
                        pos.X - ico.x, pos.Y - ico.y);
                }
                icons[i] = ico;
            }
            lastHold = e.Location;
            mbDown   = true;
        }
Beispiel #8
0
        internal Rectangle GetRectangleFromIcon(DesktopIcon i)
        {
            int size = DesktopIcon.ICON_SIZE;

            return(new Rectangle((int)i.x, (int)i.y, size, size));
        }
Beispiel #9
0
        private void ProcessDesktopContext(MouseEventArgs e)
        {
            DesktopContext dct = new DesktopContext(snap);

            void handler(object snd, FormClosedEventArgs args)
            {
                int pick = dct.buttonIndex;

                dct.Dispose();
                if (pick == 1)
                {
                    if (!snap)
                    {
                        snap = true;
                        // Snap all icons to grid.
                        for (int i = 0; i < dm.IconCount(); i++)
                        {
                            DesktopIcon ico = dm.icons[i];
                            ico.target  = GetSnapToGridPoint(ico);
                            dm.icons[i] = ico;
                        }
                    }
                    else
                    {
                        snap = false;
                    }
                }
                else if (pick == 2)
                {
                    // Create new icon.
                    CreateIconWindow ciw = new CreateIconWindow();
                    ciw.Location = Cursor.Position;
                    ciw.ShowDialog();
                    if (!ciw.IsConfirmed())
                    {
                        return;
                    }
                    if (ciw.appdir.ToLower().EndsWith(".lnk"))
                    {
                        Shell32.Shell      sh   = new Shell32.Shell();
                        Shell32.Folder     scf  = sh.NameSpace(Path.GetDirectoryName(ciw.appdir));
                        Shell32.FolderItem item = scf.ParseName(Path.GetFileName(ciw.appdir));
                        if (item == null)
                        {
                            MessageBox.Show("Invalid .lnk file? null");
                            return;
                        }
                        if (!item.IsLink)
                        {
                            MessageBox.Show("Invalid .lnk file? nonlink");
                            //MessageBox.Show(item.Name + "\n" + item.IsLink + "\n" + item.Path + "\n" + item.Type);
                            return;
                        }
                        Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)item.GetLink;
                        DesktopIcon             ico = new DesktopIcon(e.X, e.Y, lnk.Target.Path, dm)
                        {
                            name = ciw.name
                        };
                        dm.AddIcon(ico);
                    }
                    else
                    {
                        DesktopIcon ico = new DesktopIcon(e.X, e.Y, ciw.appdir, dm)
                        {
                            name = ciw.name
                        };
                        dm.AddIcon(ico);
                    }
                    ciw.Dispose();
                }
                else if (pick == 3)
                {
                    // Change wallpaper.
                    OpenFileDialog ofd = new OpenFileDialog
                    {
                        CheckFileExists = true,
                        Multiselect     = false,
                        Filter          = "Image/Video Files (*.jpg, *.jpeg, *.png, *.gif, *.mp4)|*.jpg;*.jpeg;*.png;*.gif;*.mp4;"
                    };

                    var res = ofd.ShowDialog();

                    if (res != DialogResult.OK)
                    {
                        ofd.Dispose();
                        return;
                    }
                    wp.SetWallpaper(runOnMonitor, ofd);
                    return;
                }
                else if (pick == 4)
                {
                    // Save
                    SaveLayout();
                    return;
                }
                else if (pick == 5)
                {
                    // Load
                    if (!TryLoadLayout())
                    {
                        MessageBox.Show("Couldn't load any existing layout files. Try saving first.");
                        return;
                    }
                    return;
                }
            }

            dct.FormClosed += handler;
            dct.Show();
            dct.Location = Cursor.Position;
        }
Beispiel #10
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            if (!overrideWindowProc)
            {
                overrideWindowProc = true;
            }

            int iconExpand = 5;

            if (e.Graphics.CompositingQuality != CompositingQuality.HighSpeed)
            {
                e.Graphics.CompositingQuality = CompositingQuality.HighSpeed;
            }

            if (e.Graphics.SmoothingMode != SmoothingMode.HighSpeed)
            {
                e.Graphics.SmoothingMode = SmoothingMode.HighSpeed;
            }

            if (e.Graphics.PixelOffsetMode != PixelOffsetMode.HighSpeed)
            {
                e.Graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
            }

            if (e.Graphics.InterpolationMode != InterpolationMode.NearestNeighbor)
            {
                e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
            }

            if (wp.HasWallpaper())
            {
                Bitmap b = wp.StepGifFrame();
                e.Graphics.CompositingMode = CompositingMode.SourceCopy;
                e.Graphics.DrawImageUnscaled(b, Point.Empty);
                e.Graphics.CompositingMode = CompositingMode.SourceOver;
            }

            DesktopIcon[] icons = dm.icons;
            for (int xx = 0; xx < dm.IconCount(); xx++)
            {
                DesktopIcon i  = icons[xx];
                Bitmap      bm = i.image;

                i.TryPhysicsTick();

                // code
                if (i.selected)
                {
                    using (Brush br = new SolidBrush(Color.FromArgb(100, 80, 80, 255)))
                    {
                        var rec = GetRectangleFromIcon(i);

                        rec.X      -= iconExpand;
                        rec.Y      -= iconExpand;
                        rec.Width  += iconExpand * 2;
                        rec.Height += iconExpand * 2;

                        e.Graphics.FillRectangle(br, rec);
                    }
                }
                using (Font f = new Font(FontFamily.GenericSansSerif, DesktopIcon.ICON_SIZE / 5))
                {
                    int   offset = 0;
                    SizeF ss     = e.Graphics.MeasureString(i.name, f);
                    int   width  = (int)ss.Width;
                    if (width > DesktopIcon.ICON_SIZE)
                    {
                        int dif = DesktopIcon.ICON_SIZE - width;
                        offset = dif / 2;
                    }
                    if (width < DesktopIcon.ICON_SIZE)
                    {
                        int dif = DesktopIcon.ICON_SIZE - width;
                        offset = dif / 2;
                    }
                    e.Graphics.DrawString(i.name, f, Brushes.Black, i.x + offset + shadowOffset, i.y + DesktopIcon.ICON_SIZE + shadowOffset);
                    e.Graphics.DrawString(i.name, f, Brushes.White, i.x + offset, i.y + DesktopIcon.ICON_SIZE);
                }
                e.Graphics.DrawImage(bm, new PointF(i.x, i.y));
            }

            int alphaStep = 15; // 15(10) = 150

            if (mbDown && capturedIconID == -1)
            {
                using (Pen p = new Pen(new SolidBrush(Color.FromArgb(255, 20, 20, 255)), 1))
                    using (Brush b = new SolidBrush(Color.FromArgb(alphaStep * 10, 100, 100, 255)))
                    {
                        curHold = GetCorrectedCursorPosition();
                        Point cur  = curHold;
                        Point last = lastHold;

                        int minX = Math.Min(cur.X, last.X);
                        int minY = Math.Min(cur.Y, last.Y);

                        int width  = Math.Abs(cur.X - last.X);
                        int height = Math.Abs(cur.Y - last.Y);

                        Rectangle rect = new Rectangle(minX, minY, width, height);
                        for (int i = 0; i < dm.IconCount(); i++)
                        {
                            DesktopIcon ico = icons[i];
                            if (rect.IntersectsWith(GetRectangleFromIcon(ico)))
                            {
                                ico.selected = true;
                                icons[i]     = ico;
                                continue;
                            }
                        }
                        dm.icons = icons;

                        e.Graphics.FillRectangle(b, rect);
                        e.Graphics.DrawRectangle(p, rect);
                    }
            }
            else if (!mbDown && fadeLevel != -1 && capturedIconID == -1)
            {
                using (Brush b = new SolidBrush(Color.FromArgb(alphaStep * fadeLevel, 100, 100, 255)))
                {
                    fadeLevel--;

                    Point cur  = curHold;
                    Point last = lastHold;

                    int minX = Math.Min(cur.X, last.X);
                    int minY = Math.Min(cur.Y, last.Y);

                    int width  = Math.Abs(cur.X - last.X);
                    int height = Math.Abs(cur.Y - last.Y);

                    e.Graphics.FillRectangle(b,
                                             new Rectangle(minX, minY, width, height));
                }
            }
        }