Exemplo n.º 1
0
        /// <summary>
        /// Builds a menu based on the parameters given
        /// </summary>
        /// <typeparam name="T">The type of data the menu should hold</typeparam>
        /// <param name="parentControl">The parent control this menu resides in</param>
        /// <param name="appearance">The appearance of the menu<para>Leave null for default values</para></param>
        /// <param name="menuDrawer">The menu drawer to use when the menu needs to be drawn</param>
        /// <param name="tabDrawer">The tab drawer to use when a tab needs to be drawn</param>
        /// <param name="clickHandler">The click handler to use with the menu</param>
        /// <param name="locationDrawer">The location drawer the tab uses to finalize location dependent tab visuals</param>
        /// <param name="eventFunction">The function to execute when the tab changes</param>
        /// <returns>A Menu that conforms to the given parameters</returns>
        public static IMenu <T> Build <T>(Control parentControl, MenuAppearance appearance = null, IMenuDrawer menuDrawer = null, ITabDrawer tabDrawer = null, IClickHandler clickHandler = null, ITabLocationDrawer locationDrawer = null, EventHandler <TabChangedEventArgs <T> > eventFunction = null)
        {
            var menu = new Menu <T> {
                appearance       = appearance ?? MenuAppearance.GetDefaultAppearance(),
                allowRightClick  = false,
                parentControl    = parentControl,
                currentTabIndex  = -1,
                currentMouseMode = MouseModes.mouseClick,
                menuDrawer       = menuDrawer ?? new VerticalMenuDrawer(),
                tabDrawer        = tabDrawer ?? new VerticalTabDrawer(),
                clickHandler     = clickHandler ?? new VerticalClickHandler(),
            };

            parentControl.Paint      += menu.OnDraw;
            parentControl.MouseClick += menu.OnClick;

            if (locationDrawer != null)
            {
                menu.tabDrawer.tabLocationDrawer = locationDrawer;
            }

            if (eventFunction != null)
            {
                menu.tabChanged += eventFunction;
            }

            return(menu);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Finalizes the drawing of the tab based on its position of the tab
        /// </summary>
        /// <param name="g">The Graphics instance to draw to</param>
        /// <param name="location">The location the tab is located at</param>
        /// <param name="appearance">The appearance of the tab</param>
        public void Draw(Graphics g, Point location, MenuAppearance appearance)
        {
            using Pen pen = new Pen(appearance.tabBackColor, appearance.borderWidth);

            g.DrawLine(pen,
                       location.X + appearance.borderWidth,
                       location.Y,
                       location.X + appearance.tabSize.Width - appearance.borderWidth,
                       location.Y);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Builds a menu based on the parameters given
        /// </summary>
        /// <typeparam name="T">The type of data the menu should hold</typeparam>
        /// <param name="parentControl">The parent control this menu resides in</param>
        /// <param name="menuLayout">The standard layout to use, either horizontal or vertical</param>
        /// <param name="menuLocation">The location in the screen the menu is located at</param>
        /// <param name="appearance">The appearance this menu should take<para>Leave null for default layout</para></param>
        /// <param name="eventFunction">The function to execute when the tab changes</param>
        /// <returns>A menu based on the parameters given</returns>
        public static IMenu <T> Build <T>(Control parentControl, MenuLayout menuLayout, MenuLocation menuLocation, MenuAppearance appearance = null, EventHandler <TabChangedEventArgs <T> > eventFunction = null)
        {
            var menu = new Menu <T> {
                appearance       = appearance ?? MenuAppearance.GetDefaultAppearance(),
                allowRightClick  = false,
                parentControl    = parentControl,
                currentTabIndex  = -1,
                currentMouseMode = MouseModes.mouseClick,
            };

            switch (menuLayout)
            {
            case MenuLayout.horizontal:
                menu.menuDrawer   = new HorizontalMenuDrawer();
                menu.tabDrawer    = new HorizontalTabDrawer();
                menu.clickHandler = new HorizontalClickHandler();
                break;

            case MenuLayout.vertical:
                menu.menuDrawer   = new VerticalMenuDrawer();
                menu.tabDrawer    = new VerticalTabDrawer();
                menu.clickHandler = new VerticalClickHandler();
                break;
            }

            switch (menuLocation)
            {
            case MenuLocation.top:
                menu.tabDrawer.tabLocationDrawer = new TopTabLocationDrawer();
                break;

            case MenuLocation.right:
                menu.tabDrawer.tabLocationDrawer = new RightTabLocationDrawer();
                break;

            case MenuLocation.bottom:
                menu.tabDrawer.tabLocationDrawer = new BottomTabLocationDrawer();
                break;

            case MenuLocation.left:
                menu.tabDrawer.tabLocationDrawer = new LeftTabLocationDrawer();
                break;
            }

            parentControl.Paint      += menu.OnDraw;
            parentControl.MouseClick += menu.OnClick;

            if (eventFunction != null)
            {
                menu.tabChanged += eventFunction;
            }

            return(menu);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Draws the menu to a graphics instance
        /// </summary>
        /// <param name="g">The graphics instance to draw to</param>
        /// <param name="appearance">The appearance data of the menu</param>
        /// <param name="menuSize">The size of the menu</param>
        /// <param name="tabList">The list of tabs to draw</param>
        /// <param name="tabDrawer">The tab drawer to use when drawing the tabs</param>
        public void Draw <T>(Graphics g, MenuAppearance appearance, Size menuSize, IList <ITab <T> > tabList, ITabDrawer tabDrawer)
        {
            if (appearance.borderWidth > 0)
            {
                using Pen pen = new Pen(appearance.borderColor, appearance.borderWidth);

                g.DrawRectangle(pen, new Rectangle(0, 0, menuSize.Width - 1, menuSize.Height - 1));
            }

            for (int i = 0, y = 0; i < tabList.Count(); i++, y += appearance.tabSize.Height)
            {
                tabDrawer.Draw(g, appearance, tabList[i], new Point(0, y), i == 0, i == (tabList.Count - 1));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Draws the tab to a graphics instance
        /// </summary>
        /// <param name="g">The graphics instance to draw to</param>
        /// <param name="appearance">The appearance of the tab</param>
        /// <param name="tab">The tab to draw</param>
        /// <param name="location">The point where to draw the tab</param>
        /// <param name="isStart">Indicates this is the first tab</param>
        /// <param name="isEnd">Indicates this is the last tab and at the end of the menu</param>
        public void Draw <T>(Graphics g, MenuAppearance appearance, ITab <T> tab, Point location, bool isStart = false, bool isEnd = false)
        {
            // Create all the brushes and pens
            using SolidBrush tabBrush  = new SolidBrush(appearance.tabBackColor);
            using Pen tabBorderPen     = new Pen(appearance.borderColor, appearance.borderWidth);
            using SolidBrush textBrush = new SolidBrush(appearance.textColor);

            // Clear the tab area to get a clean canvas
            g.FillRectangle(tabBrush, location.X, location.Y, appearance.tabSize.Width - 1, appearance.tabSize.Height - 1);

            // If there should be a border, draw it
            if (appearance.borderWidth > 0)
            {
                g.DrawRectangle(tabBorderPen, location.X, location.Y, appearance.tabSize.Width - 1, appearance.tabSize.Height - 1);
            }

            SizeF tabNameSize  = g.MeasureString(tab.tabName, appearance.tabFont);
            Point tabNamePoint = new Point((int)((appearance.tabSize.Width - tabNameSize.Width) / 2) + location.X,
                                           (int)((appearance.tabSize.Height - tabNameSize.Height) / 2) + location.Y);

            if (tabNamePoint.X < 0)
            {
                TextRenderer.DrawText(null, tab.tabName, appearance.tabFont, new Rectangle(location, appearance.tabSize), appearance.textColor);
            }
            else
            {
                g.DrawString(tab.tabName, appearance.tabFont, textBrush, tabNamePoint);
            }

            if (!tab.selected)
            {
                return;
            }

            if (appearance.borderWidth == 0)
            {
                return;
            }

            tabLocationDrawer.Draw(g, location, appearance);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Draws the tab to a graphics instance
        /// </summary>
        /// <param name="g">The graphics instance to draw to</param>
        /// <param name="appearance">The appearance of the tab</param>
        /// <param name="tab">The tab to draw</param>
        /// <param name="location">The point where to draw the tab</param>
        /// <param name="isStart">Indicates this is the first tab</param>
        /// <param name="isEnd">Indicates this is the last tab and at the end of the menu</param>
        public void Draw <T>(Graphics g, MenuAppearance appearance, ITab <T> tab, Point location, bool isStart = false, bool isEnd = false)
        {
            using SolidBrush tabBrush  = new SolidBrush(appearance.tabBackColor);
            using Pen tabBorderPen     = new Pen(appearance.borderColor, appearance.borderWidth);
            using SolidBrush textBrush = new SolidBrush(appearance.textColor);

            g.FillRectangle(tabBrush, location.X, location.Y, appearance.tabSize.Width - 1, appearance.tabSize.Height - 1);

            if (appearance.borderWidth > 0)
            {
                g.DrawRectangle(tabBorderPen, location.X, location.Y, appearance.tabSize.Width - 1, appearance.tabSize.Height - 1);
            }

            SizeF tabNameSize  = g.MeasureString(tab.tabName, appearance.tabFont);
            Point tabNamePoint = new Point((int)((appearance.tabSize.Width - tabNameSize.Width) / 2) + location.X,
                                           (int)((appearance.tabSize.Height - tabNameSize.Height) / 2) + location.Y);

            if (tabNamePoint.X < 0)
            {
                TextRenderer.DrawText(null, tab.tabName, appearance.tabFont, new Rectangle(location, appearance.tabSize), appearance.textColor);
            }
            else
            {
                g.DrawString(tab.tabName, appearance.tabFont, textBrush, tabNamePoint);
            }

            if (appearance.borderWidth != 0)
            {
                if (isStart)
                {
                    g.DrawLine(new Pen(appearance.tabBackColor, appearance.borderWidth), new Point(0, 0), new Point(appearance.tabSize.Width, 0));
                }

                if (tab.selected)
                {
                    tabLocationDrawer.Draw(g, location, appearance);
                }
            }
        }