public void Draw() { mouseOverItem = null; Primitives.DrawAndFillRectangle(rectangle, Color.Brown, Color.Black, 1); int y = rectangle.Y; int x = rectangle.X; int width = rectangle.Width; int height = ITEMHEIGHT; for (int index = 0; index < Items.Count; index++) { Rectangle rectThisItem = new Rectangle(x, y, width, height); Color colorInner = Color.SandyBrown; ContextMenuItem item = Items[index]; if (Root.IsMouseOver(rectThisItem)) { colorInner = Color.White; mouseOverItem = item; // Tooltip if (item.Tooltip != null) { Tooltip.DrawTooltip(item.OptimumTooltipRectangle, item.Tooltip); } } Primitives.DrawAndFillRectangle(rectThisItem, colorInner, Color.Black, 1); Primitives.DrawImage(item.Icon, new Rectangle(rectThisItem.X + 2, rectThisItem.Y + 2, rectThisItem.Height - 4, rectThisItem.Height - 4)); Writer.DrawString(item.Name, new Rectangle(rectThisItem.X + rectThisItem.Height + 4, rectThisItem.Y, rectThisItem.Width - rectThisItem.Height - 6, rectThisItem.Height), Color.Black, font, Writer.TextAlignment.Left); y += height; } if (!Root.IsMouseOver(rectangle.Extend(40, 40))) { this.ScheduledForElimination = true; } }
private void setVisuals(int realx, int realy) { realx += 1; realy += 1; int maxwidth = 0; foreach (ContextMenuItem item in Items) { int thisWidth = (int)font.Regular.MeasureString(item.Name).Width + 25 + ITEMHEIGHT; if (thisWidth > maxwidth) { maxwidth = thisWidth; } } int maxheight = Items.Count * ITEMHEIGHT; if (realx + maxwidth > Root.ScreenWidth) { realx = Root.ScreenWidth - maxwidth; } if (realy + maxheight > Root.ScreenHeight) { realy = Root.ScreenHeight - maxheight; } rectangle = new Rectangle(realx, realy, maxwidth, maxheight); for (int i = 0; i < Items.Count; i++) { ContextMenuItem item = Items[i]; if (item.Tooltip != null) { Rectangle requestedTooltipRectangle = Tooltip.GetOptimumTooltipRectangle(item.Tooltip, new Point(rectangle.X + maxwidth, rectangle.Y + ITEMHEIGHT * i), 250, rectangle ); item.OptimumTooltipRectangle = requestedTooltipRectangle; } } }