public static CompositeImage GetButtonImage(BubbleButton button, Size size) { CompositeImage image=null; if(button.Image!=null) { if(button.Image.Size==size || button.ImageLarge==null) image=new CompositeImage(button.Image,false,size); else if(button.ImageLarge!=null && (button.ImageLarge.Size==size || button.ImageLarge.Size.Height/size.Height<2)) image=new CompositeImage(button.ImageLarge,false,size); else image=new CompositeImage(button.Image,false,size); } else if(button.ImageCached!=null) { if(button.ImageCached.Size==size || button.ImageLargeCached==null) image=new CompositeImage(button.ImageCached,false,size); else if(button.ImageLargeCached!=null && button.ImageLargeCached.Size.Height/size.Height<=2) image=new CompositeImage(button.ImageLargeCached,false,size); else image=new CompositeImage(button.ImageCached,false,size); } // else if(button.Icon!=null) // { // // } return image; }
/// <summary> /// Adds new item to the collection at specified location but it does not raise internal events. /// </summary> /// <param name="item">New item to add.</param> /// <param name="Position">Position to add item to.</param> internal void _Add(BubbleButton item, int Position) { m_IgnoreEvents=true; try { List.Insert(Position,item); } finally { m_IgnoreEvents=false; } }
/// <summary> /// Adds new item to the collection but it does not raise internal events. /// </summary> /// <param name="item">New item to add.</param> /// <returns>Index of newly added item.</returns> internal int _Add(BubbleButton item) { m_IgnoreEvents=true; int i=0; try { i=List.Add(item); } finally { m_IgnoreEvents=false; } return i; }
private int GetPreviousButtonIndex(BubbleButton[] buttons, int index) { int next=-1; for(int i=index-1;i>=0;i--) { if(buttons[i].Visible) { next=i; break; } } return next; }
private int GetNextButtonIndex(BubbleButton[] buttons, int index) { int next=-1; for(int i=index+1;i<buttons.Length;i++) { if(buttons[i].Visible) { next=i; break; } } return next; }
private void MouseUpMessage(MouseEventArgs e) { if (m_MouseDownButton != null) { BubbleButton button = m_MouseDownButton; Rectangle dispRect = button.DisplayRectangle; Rectangle magRect = button.MagnifiedDisplayRectangle; SetMouseDown(null); SetMouseOver(null); m_IgnoreMouseMove = true; this.RepaintAll(); if (dispRect.Contains(e.X, e.Y) || magRect.Contains(e.X, e.Y)) button.InvokeClick(eEventSource.Mouse, e.Button); m_IgnoreButtonMouseMove = button; } }
/// <summary> /// Called after new button is added to the Buttons collection. /// </summary> /// <param name="tab">Tab to which button was added.</param> /// <param name="button">Reference to the button added.</param> internal void OnButtonInserted(BubbleBarTab tab, BubbleButton button) { StopBubbleEffect(); LayoutButtons(); if (button.Shortcut != eShortcut.None) { m_HasShortcuts = true; } if (this.DesignMode) { this.RecalcLayout(); this.Refresh(); } }
/// <summary> /// Returns true if given item is contained by this collection. /// </summary> /// <param name="value">Item to test.</param> /// <returns>True if item is part of this collection otherwise false.</returns> public virtual bool Contains(BubbleButton value) { return List.Contains(value); }
/// <summary> /// Inserts new item at the specified position. /// </summary> /// <param name="index">Position to insert item at.</param> /// <param name="item">Item to insert.</param> public virtual void Insert(int index, BubbleButton item) { this.Add(item,index); }
/// <summary> /// Adds new item to the collection. /// </summary> /// <param name="item">New item to add.</param> /// <returns>Index of newly added item.</returns> public virtual int Add(BubbleButton item) { return Add(item,-1); }
internal void DragCancel() { if (!m_DragInProgress) return; if (m_DragTab != null) { if (m_DragTabOriginalIndex >= 0) { this.Tabs.Remove(m_DragTab); this.Tabs.Insert(m_DragTabOriginalIndex, m_DragTab); this.RecalcLayout(); this.Refresh(); } m_DragTab = null; m_DragTabOriginalIndex = -1; } else if (m_DragButton != null) { if (m_DragButtonOriginalIndex >= 0) { if (m_DragButton.Parent != null) m_DragButton.Parent.Buttons.Remove(m_DragButton); if (m_DragTabOriginalIndex >= 0 && m_DragTabOriginalIndex != this.Tabs.IndexOf(m_DragButton.Parent)) { this.Tabs[m_DragTabOriginalIndex].Buttons.Insert(m_DragButtonOriginalIndex, m_DragButton); } else this.Tabs[m_DragTabOriginalIndex].Buttons.Insert(m_DragButtonOriginalIndex, m_DragButton); m_DragButtonOriginalIndex = -1; m_DragTabOriginalIndex = -1; m_DragButton = null; this.RecalcLayout(); this.Refresh(); } } m_DragInProgress = false; }
public void DragMouseUp(Point mousePosition) { if (m_DragTab != null) { BubbleBarTab tab = GetTabAt(mousePosition); if (tab != m_DragTab) { DragCancel(); } else { m_DragTab = null; m_DragTabOriginalIndex = -1; } } else if (m_DragButton != null) { BubbleButton button = GetButtonAt(mousePosition); if (button != m_DragButton) DragCancel(); else { m_DragButton = null; m_DragTabOriginalIndex = -1; m_DragButtonOriginalIndex = -1; } } m_DragInProgress = false; }
public void StartDrag(BubbleButton button) { if (m_DragInProgress) return; m_DragInProgress = true; m_DragButton = button; Cursor.Current = Cursors.Hand; }
private void SetSelectedTab(BubbleBarTab tab, eEventSource source, bool bCanCancel) { if (TabChanging != null) { BubbleBarTabChangingEventArgs e = new BubbleBarTabChangingEventArgs(); e.CurrentTab = m_SelectedTab; e.NewTab = tab; e.Source = source; TabChanging(this, e); if (e.Cancel && bCanCancel) return; } m_SelectedTab = tab; m_IgnoreButtonMouseMove = null; this.LayoutButtons(); this.RepaintAll(); }
private void OnSelectedTabChanged() { StopBubbleEffect(); m_IgnoreButtonMouseMove = null; LayoutButtons(); this.Refresh(); }
private void AnimateButton(BubbleButton button, Point mousePosition, bool animateGrow) { if (m_AnimationTime <= 0 || m_Animation || m_SelectedTab == null || !m_AnimationEnabled) return; m_Animation = true; try { m_ContentManager.MouseOverIndex = m_SelectedTab.Buttons.IndexOf(button); bool animate = true; int totalSteps = m_ImageSizeLarge.Width - m_ImageSizeNormal.Width; int step = 1; int current = m_ImageSizeNormal.Width + step; if (!animateGrow) current = m_ImageSizeLarge.Width - step; Rectangle displayRectangle = GetButtonDisplayArea(); IBlock[] blocks = new IBlock[m_SelectedTab.Buttons.Count]; m_SelectedTab.Buttons.CopyTo(blocks); DateTime start = DateTime.Now; TimeSpan stepDuration = TimeSpan.MinValue; while (animate) { DateTime stepStart = DateTime.Now; float multi = (float)current / (float)m_ImageSizeNormal.Width; Size bubbleSize = new Size((int)((float)m_ImageSizeNormal.Width * multi), (int)((float)m_ImageSizeNormal.Height * multi)); BubbleFactors factors = this.GetBubbleFactors(button.DisplayRectangle, mousePosition, bubbleSize); m_ContentManager.Factor1 = factors.Factor1; m_ContentManager.Factor2 = factors.Factor2; m_ContentManager.Factor3 = factors.Factor3; m_ContentManager.Factor4 = factors.Factor4; m_ContentManager.BubbleSize = bubbleSize; m_ContentManager.MouseOverPosition = factors.x; m_ContentManager.Layout(displayRectangle, blocks, m_ButtonLayoutManager); this.RepaintAll(); stepDuration = DateTime.Now.Subtract(stepStart); step = (int)((float)totalSteps * ((float)stepDuration.TotalMilliseconds / (float)m_AnimationTime)); if (step <= 0) { int diff = (int)(m_AnimationTime / Math.Max((float)stepDuration.TotalMilliseconds, (float)1) / totalSteps); if (diff <= 0) diff = (int)stepDuration.TotalMilliseconds; System.Threading.Thread.Sleep(diff); step = 1; } if (animateGrow) current += step; else current -= step; totalSteps -= step; if (totalSteps <= 0 || DateTime.Now.Subtract(start).TotalMilliseconds >= m_AnimationTime) break; } } finally { m_Animation = false; } }
/// <summary> /// Called when Visible property of Button has changed. /// </summary> /// <param name="button">Button affected.</param> internal void OnButtonVisibleChanged(BubbleButton button) { LayoutButtons(); }
/// <summary> /// Performs layout of the content block. /// </summary> /// <param name="containerBounds">Container bounds to layout content blocks in.</param> /// <param name="contentBlocks">Content blocks to layout.</param> /// <param name="blockLayout">Block layout manager that resizes the content blocks.</param> /// <returns>The bounds of the content blocks within the container bounds.</returns> public override Rectangle Layout(Rectangle containerBounds,IBlock[] contentBlocks,BlockLayoutManager blockLayout) { if(contentBlocks.Length==0) return Rectangle.Empty; if(m_MouseOverIndex==-1) { return base.Layout(containerBounds,contentBlocks,blockLayout); } BubbleButton[] buttons=new BubbleButton[contentBlocks.Length]; contentBlocks.CopyTo(buttons,0); int x=0,y=0; if(this.ContentOrientation==eContentOrientation.Horizontal) { buttons[m_MouseOverIndex].SetMagnifiedDisplayRectangle(new Rectangle(m_MouseOverPosition,GetY(containerBounds,m_BubbleSize.Height),m_BubbleSize.Width,m_BubbleSize.Height)); x=m_MouseOverPosition; } else { buttons[m_MouseOverIndex].SetMagnifiedDisplayRectangle(new Rectangle(GetX(containerBounds,m_BubbleSize.Width),m_MouseOverPosition,m_BubbleSize.Width,m_BubbleSize.Height)); y=m_MouseOverPosition; } int growthWidth=m_BubbleSize.Width-contentBlocks[0].Bounds.Width; int growthHeight=m_BubbleSize.Height-contentBlocks[0].Bounds.Height; // Apply factor 2 int index=GetPreviousButtonIndex(buttons,m_MouseOverIndex); if(index>=0) SetFactorPrevious(containerBounds,buttons[index],growthWidth,growthHeight,m_Factor2,ref x, ref y); // Apply factor 1 index=GetPreviousButtonIndex(buttons,index); if(index>=0) SetFactorPrevious(containerBounds,buttons[index],growthWidth,growthHeight,m_Factor1,ref x, ref y); if(this.ContentOrientation==eContentOrientation.Horizontal) { while(index>=0) { index=GetPreviousButtonIndex(buttons,index); if(index>=0) { x-=(buttons[index].DisplayRectangle.Width+this.BlockSpacing); buttons[index].SetMagnifiedDisplayRectangle(new Rectangle(x,buttons[index].DisplayRectangle.Y,buttons[index].DisplayRectangle.Width,buttons[index].DisplayRectangle.Height)); } } x=m_MouseOverPosition+m_BubbleSize.Width+this.BlockSpacing; } else { while(index>=0) { index=GetPreviousButtonIndex(buttons,index); if(index>=0) { y-=(buttons[index].DisplayRectangle.Height+this.BlockSpacing); buttons[index].SetMagnifiedDisplayRectangle(new Rectangle(buttons[index].DisplayRectangle.X,y,buttons[index].DisplayRectangle.Width,buttons[index].DisplayRectangle.Height)); } } y=m_MouseOverPosition+m_BubbleSize.Height+this.BlockSpacing; } // Apply factor 3 index=GetNextButtonIndex(buttons,m_MouseOverIndex); if(index>=0) SetFactorNext(containerBounds,buttons[index],growthWidth,growthHeight,m_Factor3,ref x, ref y); // Apply factor 4 if(index==-1) index=m_MouseOverIndex; index=GetNextButtonIndex(buttons,index); if(index>=0) SetFactorNext(containerBounds,buttons[index],growthWidth,growthHeight,m_Factor4,ref x, ref y); if(this.ContentOrientation==eContentOrientation.Horizontal) { while(index>=0) { index=GetNextButtonIndex(buttons,index); if(index>=0) { buttons[index].SetMagnifiedDisplayRectangle(new Rectangle(x,buttons[index].DisplayRectangle.Y,buttons[index].DisplayRectangle.Width,buttons[index].DisplayRectangle.Height)); x+=(buttons[index].DisplayRectangle.Width+this.BlockSpacing); } } } else { while(index>=0) { index=GetNextButtonIndex(buttons,index); if(index>=0) { buttons[index].SetMagnifiedDisplayRectangle(new Rectangle(buttons[index].DisplayRectangle.X,y,buttons[index].DisplayRectangle.Width,buttons[index].DisplayRectangle.Height)); y+=(buttons[index].DisplayRectangle.Height+this.BlockSpacing); } } } if(buttons.Length==1) return buttons[0].MagnifiedDisplayRectangle; return Rectangle.Union(buttons[0].MagnifiedDisplayRectangle,buttons[buttons.Length-1].MagnifiedDisplayRectangle); }
/// <summary> /// Removes an item without raising internal events. /// </summary> /// <param name="item">Item to remove.</param> internal void _Remove(BubbleButton item) { m_IgnoreEvents=true; try{List.Remove(item);} finally{m_IgnoreEvents=false;} }
/// <summary> /// Invokes ButtonClick event on the control. /// </summary> /// <param name="button">Reference to the button that was clicked.</param> internal void InvokeButtonClick(BubbleButton button, ClickEventArgs e) { if (ButtonClick != null) ButtonClick(button, e); }
/// <summary> /// Adds new item to the collection at specified location. /// </summary> /// <param name="item">New item to add.</param> /// <param name="Position">Position to insert item at. Position of -1 will append the item to the end of the collection.</param> /// <returns>Index of the newly added item.</returns> public virtual int Add(BubbleButton item, int Position) { int iRet=Position; if(Position>=0) List.Insert(Position,item); else iRet=List.Add(item); return iRet; }
/// <summary> /// Internal processing of MouseMove event. /// </summary> /// <param name="e">Move move event arguments.</param> internal void MouseMoveMessage(MouseEventArgs e) { base.OnMouseMove(e); if (m_IgnoreMouseMove) { m_IgnoreMouseMove = false; return; } bool bRefresh = false; Point mousePosition = new Point(e.X, e.Y); BubbleButton mouseOver = GetButtonAt(mousePosition.X, mousePosition.Y); if (mouseOver != null && mouseOver == m_IgnoreButtonMouseMove) return; else if (mouseOver == null) m_IgnoreButtonMouseMove = null; if (mouseOver != null) { if (m_MouseOverButton == null) { CreateOverlay(); // Set to enable painting of magnified buttons... m_MouseOverButton = mouseOver; AnimateButton(mouseOver, mousePosition, true); m_MouseOverButton = null; } if (m_AnimationEnabled) { BubbleFactors factors = this.GetBubbleFactors(mouseOver.DisplayRectangle, mousePosition); m_ContentManager.Factor1 = factors.Factor1; m_ContentManager.Factor2 = factors.Factor2; m_ContentManager.Factor3 = factors.Factor3; m_ContentManager.Factor4 = factors.Factor4; m_ContentManager.BubbleSize = m_ImageSizeLarge; m_ContentManager.MouseOverPosition = factors.x; m_ContentManager.MouseOverIndex = mouseOver.Parent.Buttons.IndexOf(mouseOver); this.LayoutButtons(); bRefresh = true; m_LastMouseOverPosition = mousePosition; } } if (m_MouseOverTab != null || m_TabsBounds.Contains(mousePosition)) { BubbleBarTab tab = GetTabAt(mousePosition); SetMouseOverTab(tab); } if (m_MouseOverButton != mouseOver) { SetMouseOver(mouseOver); bRefresh |= true; } if (m_MouseOverButton != mouseOver && e.Button == MouseButtons.Left) { SetMouseDown(mouseOver); bRefresh |= true; } // Make sure that cursor did not escape while animation was going on... if (m_MouseOverButton != null) { Point p = Control.MousePosition; if (m_Overlay != null) p = m_Overlay.PointToClient(p); else p = this.PointToClient(p); mouseOver = GetButtonAt(p.X, p.Y); if (mouseOver != m_MouseOverButton) { SetMouseOver(mouseOver); bRefresh |= true; } } if (bRefresh) this.RepaintAll(); }
/// <summary> /// Returns index of an item. /// </summary> /// <param name="value">Item to return index for.</param> /// <returns>Item at the specified position.</returns> public virtual int IndexOf(BubbleButton value) { return List.IndexOf(value); }
/// <summary> /// Adds array of the items to the collection. /// </summary> /// <param name="items">Array of items to add.</param> public virtual void AddRange(BubbleButton[] items) { foreach(BubbleButton item in items) { this.Add(item); } }
/// <summary> /// Removes an item from the collection. /// </summary> /// <param name="item">Item to remove.</param> public virtual void Remove(BubbleButton item) { List.Remove(item); }
/// <summary> /// Called after specified button has been removed. /// </summary> /// <param name="tab">Tab from which button was removed.</param> /// <param name="button">Button that was removed.</param> internal void OnButtonRemoved(BubbleBarTab tab, BubbleButton button) { StopBubbleEffect(); if (m_HasShortcuts && !this.IsDisposed) RefreshHasShortcut(); if (this.DesignMode) { this.RecalcLayout(); this.Refresh(); } }
/// <summary> /// Copy the collection to the array. /// </summary> /// <param name="array">Array to copy collection to.</param> /// <param name="index">The zero-based relative index in array at which copying begins.</param> public virtual void CopyTo(BubbleButton[] array, int index) { List.CopyTo(array, index); }
/// <summary> /// Called after specified button has been removed. /// </summary> /// <param name="button">Button that was removed.</param> internal void OnButtonRemoved(BubbleButton button) { if(m_Parent!=null) m_Parent.OnButtonRemoved(this,button); }
private void SetFactorNext(Rectangle containerBounds, BubbleButton button, int growthWidth, int growthHeight, float factor, ref int x, ref int y) { int w=(int)(button.DisplayRectangle.Width+growthWidth*factor); int h=(int)(button.DisplayRectangle.Height+growthHeight*factor); if(this.ContentOrientation==eContentOrientation.Horizontal) { button.SetMagnifiedDisplayRectangle(new Rectangle(x,GetY(containerBounds,h),w,h)); x+=(w+this.BlockSpacing); } else { button.SetMagnifiedDisplayRectangle(new Rectangle(GetX(containerBounds,w),y,w,h)); y+=(h+this.BlockSpacing); } }
/// <summary> /// Internal processing for MouseLeave event. /// </summary> /// <param name="e">Event arguments</param> internal void MouseLeaveMessage(EventArgs e) { Point p = Point.Empty; if (m_MouseOverButton != null && m_Overlay != null) p = m_Overlay.PointToClient(Control.MousePosition); else p = this.PointToClient(Control.MousePosition); bool bRepaint = false; BubbleButton buttonAt = GetButtonAt(p.X, p.Y); if (m_MouseDownButton != null && buttonAt == null) { SetMouseDown(null); bRepaint = true; } SetMouseOverTab(null); if (bRepaint) this.RepaintAll(); StartMouseLeaveTimer(); m_IgnoreButtonMouseMove = null; }