Ejemplo n.º 1
0
        /// <summary>
        /// Calculates bars and active bar's items location,sizes,... .
        /// </summary>
        private void CalculateBarInfo()
        {
            int barTop = 1;

            using (Graphics g = this.CreateGraphics()){
                //--- Calculate visible Bar's client rectangle
                int visibleBarClientHeight = this.ClientSize.Height - (CalculateBarsHeight(g)) - 2 - 1;

                //--- loop through all bars ------//
                for (int i = 0; i < m_pBars.Count; i++)
                {
                    Bar bar = this.Bars[i];
                    bar.BarClientRect = new Rectangle(0, 0, 0, 0);

                    //--- Calculate text rect Height
                    SizeF bSize         = g.MeasureString(bar.Caption, bar.Font, this.ClientSize.Width - 2);
                    int   barTextHeight = (int)(Math.Ceiling(bSize.Height));

                    int barHeight = barTextHeight + m_DefaultTextSpacing * 2;

                    //--- If upper bars ---------
                    if (i < m_ActiveBarIndex + 1)
                    {
                        bar.BarRect = new Rectangle(1, barTop, this.ClientSize.Width - 3, barHeight);

                        //--- If active bar
                        if (i == m_ActiveBarIndex)
                        {
                            bar.BarClientRect     = new Rectangle(1, bar.BarRect.Bottom, this.Width - 2, visibleBarClientHeight);
                            m_ActiveBarClientRect = new Rectangle(1, bar.BarRect.Bottom, this.Width - 2, visibleBarClientHeight);

                            int top = bar.BarRect.Bottom + 3;

                            //--- Calculate items rect --------------------------//
                            for (int it = bar.FirstVisibleIndex; it < bar.Items.Count; it++)
                            {
                                Item item = bar.Items[it];

                                int itemWidth = this.Width - 3;

                                //--- Look if multiline text, if is add extra Height to item.
                                SizeF iSize          = g.MeasureString(item.Caption, bar.ItemsFont, itemWidth);
                                int   itemTextHeight = (int)(Math.Ceiling(iSize.Height));

                                item.Bounds = new Rectangle(1, top, itemWidth, 43 + itemTextHeight);

                                top += 43 + itemTextHeight + 1;
                            }
                            //---------------------------------------------------//
                        }
                    }
                    //--- If lower bars
                    else
                    {
                        bar.BarRect = new Rectangle(1, barTop + visibleBarClientHeight, this.Width - 3, barHeight);
                    }

                    barTop += barHeight + 1;
                }
                //--------------------------------//
            }
        }
Ejemplo n.º 2
0
        protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            HitInfo hitInfo = new HitInfo(new Point(e.X, e.Y), this);

            //--- If hitted bar is different than activeBar, set hittedBar as activeBar.
            if (hitInfo.HittedObject == HittedObject.Bar && hitInfo.HittedBar.Index != m_ActiveBarIndex)
            {
                m_ActiveBarIndex = hitInfo.HittedBar.Index;
                this.UpdateAll();
                return;
            }

            //--- If button clicked
            if (hitInfo.HittedObject == HittedObject.Item)
            {
                if (hitInfo.HittedItem.AllowStuck)
                {
                    if (!hitInfo.HittedItem.Equals(m_StuckenItem))
                    {
                        Item oldItem = m_StuckenItem;
                        m_StuckenItem = hitInfo.HittedItem;

                        //--- Redraw old stucken item
                        if (oldItem != null && oldItem.Bar.IsItemVisible(oldItem))
                        {
                            using (Graphics g = this.CreateGraphics()){
                                g.SetClip(this.ActiveBar.BarClientRect);
                                DrawItem(g, oldItem, oldItem.Bar, false, false);
                            }
                        }

                        OnItemClicked(hitInfo.HittedItem);
                    }
                }
                else
                {
                    OnItemClicked(hitInfo.HittedItem);
                }
            }

            //--- If up scroll button clicked
            Bar activeBar = this.ActiveBar;

            if (hitInfo.HittedObject == HittedObject.UpScrollButton)
            {
                activeBar.FirstVisibleIndex--;
                this.UpdateAll();
                return;
            }

            //--- If down scroll button clicked
            if (hitInfo.HittedObject == HittedObject.DownScrollButton)
            {
                activeBar.FirstVisibleIndex++;
                this.UpdateAll();
                return;
            }

            // By default, redraw last hitted object
            DrawObject(hitInfo, false);
        }
Ejemplo n.º 3
0
        private void DrawItem(Graphics g, Item item, Bar bar, bool hot, bool pressed)
        {
            SolidBrush textBrush = new SolidBrush(hot ? m_ViewStyle.BarItemHotTextColor : m_ViewStyle.BarItemTextColor);

            if (hot || item.Equals(m_StuckenItem))
            {
                Rectangle iRect = new Rectangle(item.Bounds.Location, item.Bounds.Size);

                ItemsStyle itemStyle = bar.ItemsStyle;

                //--- If must use default item style ---------//
                //--- First load from ViewStyle
                if (bar.ItemsStyle == ItemsStyle.UseDefault)
                {
                    itemStyle = m_ViewStyle.BarItemsStyle;
                }

                //--- If ViewStyle retuned UseDefault, set IconSelect as default
                if (itemStyle == ItemsStyle.UseDefault)
                {
                    itemStyle = ItemsStyle.IconSelect;
                }
                //-------------------------------------------//

                //--- If item style is IconSelect
                if (itemStyle == ItemsStyle.IconSelect)
                {
                    iRect = new Rectangle(((this.Width - 32) / 2) - 1, item.Bounds.Y + 2, 34, 34);
                }

                //------- Draw item -----------------------------------------------------------//
                //--- if not stucken(selected) item
                if (!item.Equals(m_StuckenItem))
                {
                    if (pressed)
                    {
                        g.FillRectangle(new SolidBrush(m_ViewStyle.BarItemPressedColor), iRect);
                    }
                    else
                    {
                        g.FillRectangle(new SolidBrush(m_ViewStyle.BarItemHotColor), iRect);
                    }
                }
                else                  //---- If stucken(selected) item
                {
                    g.FillRectangle(new SolidBrush(m_ViewStyle.BarItemSelectedColor), iRect);
                    textBrush = new SolidBrush(m_ViewStyle.BarItemSelectedTextColor);
                }

                // Draw border
                g.DrawRectangle(new Pen(m_ViewStyle.BarItemBorderHotColor), iRect);
                //----------------------------------------------------------------------------//
            }
            else
            {
                //this.Invalidate(new Rectangle(item.Bounds.X,item.Bounds.Y,item.Bounds.Width+1,item.Bounds.Height+1));
                //g.FillRectangle(new SolidBrush(m_ViewStyle.BarClientAreaColor1),item.Bounds.X,item.Bounds.Y,item.Bounds.Width+1,item.Bounds.Height+1);
            }


            //---- Draw image ---------------------------//
            Rectangle imgRect = new Rectangle((this.Width - 32) / 2, item.Bounds.Y + 4, 32, 32);

            if (item.ImageIndex > -1 && this.ImageList != null && item.ImageIndex < this.ImageList.Images.Count)
            {
                g.DrawImage((Image)ImageList.Images[item.ImageIndex], imgRect);
            }
            //--------------------------------------------//

            //---- Draw items text ---------------------------------------------------------------//
            Rectangle txtRect = new Rectangle(item.Bounds.X + 2, imgRect.Bottom + 3, item.Bounds.Width, item.Bounds.Bottom - imgRect.Bottom + 3);

            g.DrawString(item.Caption, bar.ItemsFont, textBrush, txtRect, bar.ItemsStringFormat);
            //-------------------------------------------------------------------------------------//
        }