private void CalcLayout() { // For all of the items in the list, let them calc their size. float maxWidth = 0.0f; for (int i = 0; i < itemList.Count; i++) { itemList[i].CalcSize(); maxWidth = Math.Max(maxWidth, itemList[i].Size.X); } // Now set all the widths equal for (int i = 0; i < itemList.Count; i++) { Vector2 size = itemList[i].Size; size.X = maxWidth; itemList[i].Size = size; } // Layout menu. float height = itemList.Count / 2.0f * itemList[0].Size.Y; Vector2 pos = new Vector2(50.0f, 20.0f - height); for (int i = 0; i < itemList.Count; i++) { itemList[i].Position = pos; pos.Y += itemList[i].Size.Y; } /* * // Radial curve version. * float radius = 120.0f; * Vector2 centerOffset = new Vector2(-50.0f, 0.0f); * float dtheta = (float)Math.Asin(itemList[0].Size.Y / radius); * float theta = -itemList.Count * 0.7f * dtheta; * * for (int i = 0; i < itemList.Count; i++) * { * itemList[i].Position = centerOffset + radius * new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta)); * theta = (float)Math.Asin((itemList[i].Position.Y + itemList[i].Size.Y) / radius); * } */ // Calc extent of full menu. AABB2D menuBox = new AABB2D(itemList[0].HitBox); for (int i = 1; i < itemList.Count; i++) { menuBox.Union(itemList[i].HitBox); } // Check if this fits within overscan area. If not, move the menu. Vector2 safeMin = Vector2.Zero; Vector2 safeMax = BokuGame.ScreenSize; Vector2 curPos = Position; if (safeMin.X > menuBox.Min.X) { curPos.X += safeMin.X - menuBox.Min.X + 1; } else if (safeMax.X < menuBox.Max.X) { curPos.X -= menuBox.Max.X - safeMax.X + 1; } if (safeMin.Y > menuBox.Min.Y) { curPos.Y += safeMin.Y - menuBox.Min.Y + 1; } else if (safeMax.Y < menuBox.Max.Y) { curPos.Y -= menuBox.Max.Y - safeMax.Y + 1; } // Update position. Position = curPos; } // end of LayoutMenu()