Exemplo n.º 1
0
        override public bool doEvent(object caller, MouseButtonEventArgs e)
        {
            if (e.ButtonPressed && e.Button == MouseButton.PrimaryButton)
            {
                Rectangle titleBar = new Rectangle(
                    Compound.BorderPadding.Width,
                    Compound.BorderPadding.Height,
                    Width - Compound.BorderPadding.Width * 2,
                    Caption.Height + Compound.Padding - Compound.BorderPadding.Height);

                if (e.X >= titleBar.X && e.X < titleBar.X + titleBar.Width &&
                    e.Y >= titleBar.Y && e.Y < titleBar.Y + titleBar.Height)
                {
                    Point p = titleBar.Location;

                    p.X += titleBar.Width - DisplaySettings.minimizeIcon.Width -
                           DisplaySettings.closeIcon.Width - Compound.Padding;

                    if (e.X >= p.X && e.X < p.X + DisplaySettings.minimizeIcon.Width && caller is Compound)
                    {
                        Compound gui = (Compound)caller;

                        gui.Minimize(this);
                        return(true);
                    }

                    p.X += DisplaySettings.minimizeIcon.Width + Compound.Padding;

                    if (e.X >= p.X && e.X < p.X + DisplaySettings.closeIcon.Width && caller is Compound)
                    {
                        Compound gui = (Compound)caller;

                        gui.Remove(this);
                        return(true);
                    }

                    dragging = true;
                }
            }
            else
            {
                dragging = false;
            }

            Rectangle target = new Rectangle(
                Compound.BorderPadding.Width,
                Compound.BorderPadding.Height + Caption.Height,
                Width - Compound.BorderPadding.Width * 2,
                Height - Compound.BorderPadding.Height * 3 - Caption.Height);


            if (menu != null)
            {
                if (menu.doEvent(this, e))
                {
                    return(true);
                }

                target.Y      += menu.Height;
                target.Height -= menu.Height;
            }

            target.X      += Compound.Padding;
            target.Y      += Compound.Padding * 2;
            target.Width  -= Compound.Padding * 2;
            target.Height -= Compound.Padding * 2;

            if (draggingAtom != null)
            {
                MouseButtonEventArgs te = new MouseButtonEventArgs(
                    e.Button,
                    e.ButtonPressed,
                    (short)(e.X - draggingAtom.Position.X - target.X),
                    (short)(e.Y - draggingAtom.Position.Y - target.Y));

                draggingAtom.doEvent(this, te);
            }

            if (e.X < target.X || e.X >= target.X + target.Width ||
                e.Y < target.Y || e.Y >= target.Y + target.Height)
            {
                return(true);
            }

            if (e.Button == MouseButton.PrimaryButton && !e.ButtonPressed)
            {
                draggingAtom = null;
            }

            for (int i = windowAtoms.Count - 1; i >= 0; i--)
            {
                Rectangle r = windowAtoms[i].Boundaries;

                r.X += target.X;
                r.Y += target.Y;

                if (e.X < r.X || e.X >= r.X + r.Width ||
                    e.Y < r.Y || e.Y >= r.Y + r.Height)
                {
                    continue;
                }

                if (e.Button == MouseButton.PrimaryButton && e.ButtonPressed)
                {
                    draggingAtom = windowAtoms[i];
                }

                MouseButtonEventArgs te = new MouseButtonEventArgs(
                    e.Button,
                    e.ButtonPressed,
                    (short)(e.X - r.X),
                    (short)(e.Y - r.Y));

                Atom wa = windowAtoms[i];

                wa.doEvent(this, te);
                Focus(wa);

                return(true);
            }

            return(true);
        }