public override void OnCursorPressed( Vector2 cursorPos )
{
OverlayManager om = OverlayManager.Instance;
if ( this.isExpanded )
{
if ( this.scrollHandle.IsVisible ) // check for scrolling
{
Vector2 co = Widget.CursorOffset( this.scrollHandle, cursorPos );
if ( co.LengthSquared <= 81 )
{
this.isDragging = true;
this.dragOffset = co.y;
return;
}
else if ( Widget.IsCursorOver( this.scrollTrack, cursorPos ) )
{
Real newTop = this.scrollHandle.Top + co.y;
Real lowerBoundary = this.scrollTrack.Height - this.scrollHandle.Height;
this.scrollHandle.Top = Math.Utility.Clamp<Real>( newTop, lowerBoundary, 0 );
Real scrollPercentage = Math.Utility.Clamp<Real>( newTop / lowerBoundary, 1, 0 );
DisplayIndex = (int)( scrollPercentage * ( this.items.Count - this.itemElements.Count ) + 0.5 );
return;
}
}
if ( !IsCursorOver( this.expandedBox, cursorPos, 3 ) )
this.Retract();
else
{
Real l = this.itemElements[ 0 ].DerivedLeft * om.ViewportWidth + 5;
Real t = this.itemElements[ 0 ].DerivedTop * om.ViewportHeight + 5;
Real r = l + this.itemElements[ itemElements.Count - 1 ].Width - 10;
Real b = this.itemElements[ itemElements.Count - 1 ].DerivedTop * om.ViewportHeight +
this.itemElements[ itemElements.Count - 1 ].Height - 5;
if ( cursorPos.x >= l && cursorPos.x <= r && cursorPos.y >= t && cursorPos.y <= b )
{
if ( this.highlightIndex != this.sectionIndex )
this.SelectItem( this.highlightIndex );
this.Retract();
}
}
}
else
{
if ( this.items.Count < 2 )
return; // don't waste time showing a menu if there's no choice
if ( IsCursorOver( this.smallBox, cursorPos, 4 ) )
{
this.expandedBox.Show();
this.smallBox.Hide();
// calculate how much vertical space we need
Real idealHeight = this.itemsShown * ( this.smallBox.Height - 8 ) + 20;
this.expandedBox.Height = idealHeight;
this.scrollTrack.Height = this.expandedBox.Height - 20;
this.expandedBox.Left = this.smallBox.Left - 4;
// if the expanded menu goes down off the screen, make it go up instead
if ( this.smallBox.DerivedTop * om.ViewportHeight + idealHeight > om.ViewportHeight )
{
this.expandedBox.Top = this.smallBox.Top + this.smallBox.Height - idealHeight + 3;
// if we're in thick style, hide the caption because it will interfere with the expanded menu
if ( this.textArea.HorizontalAlignment == HorizontalAlignment.Center )
this.textArea.Hide();
}
else
this.expandedBox.Top = this.smallBox.Top + 3;
this.isExpanded = true;
this.highlightIndex = this.sectionIndex;
DisplayIndex = this.highlightIndex;
if ( this.itemsShown < this.items.Count ) // update scrollbar position
{
this.scrollHandle.Show();
Real lowerBoundary = this.scrollTrack.Height - this.scrollHandle.Height;
this.scrollHandle.Top = (int)( this.displayIndex * lowerBoundary / ( this.items.Count - this.itemElements.Count ) );
}
else
this.scrollHandle.Hide();
}
}
base.OnCursorPressed( cursorPos );
}