/// <summary>Update the rectangles for the list box control</summary> protected override void UpdateRectangles() { // Get bounding box base.UpdateRectangles(); // Calculate the size of the selection rectangle selectionRect = boundingBox; selectionRect.Width -= scrollWidth; selectionRect.Inflate(-border, -border); textRect = selectionRect; textRect.Inflate(-margin, 0); // Update the scroll bars rects too scrollbarControl.SetLocation(boundingBox.Right - scrollWidth, boundingBox.Top); scrollbarControl.SetSize(scrollWidth, height); FontNode fNode = DialogResourceManager.GetGlobalInstance().GetFontNode((int)(elementList[0] as Element).FontIndex); if ((fNode != null) && (fNode.Height > 0)) { scrollbarControl.PageSize = (int)(textRect.Height / fNode.Height); // The selected item may have been scrolled off the page. // Ensure that it is in page again. scrollbarControl.ShowItem(selectedIndex); } }
public static DialogResourceManager GetGlobalInstance() { if (localObject == null) { localObject = new DialogResourceManager(); } return(localObject); }
/// <summary>Update the rectangles for the combo box control</summary> protected override void UpdateRectangles() { // Get bounding box base.UpdateRectangles(); // Update the bounding box for the items buttonRect = new System.Drawing.Rectangle(boundingBox.Right - boundingBox.Height, boundingBox.Top, boundingBox.Height, boundingBox.Height); textRect = boundingBox; textRect.Size = new System.Drawing.Size(textRect.Width - buttonRect.Width, textRect.Height); dropDownRect = textRect; dropDownRect.Offset(0, (int)(0.9f * textRect.Height)); dropDownRect.Size = new System.Drawing.Size(dropDownRect.Width - scrollWidth, dropDownRect.Height + dropHeight); // Scale it down slightly System.Drawing.Point loc = dropDownRect.Location; System.Drawing.Size size = dropDownRect.Size; loc.X += (int)(0.1f * dropDownRect.Width); loc.Y += (int)(0.1f * dropDownRect.Height); size.Width -= (2 * (int)(0.1f * dropDownRect.Width)); size.Height -= (2 * (int)(0.1f * dropDownRect.Height)); dropDownTextRect = new System.Drawing.Rectangle(loc, size); // Update the scroll bars rects too scrollbarControl.SetLocation(dropDownRect.Right, dropDownRect.Top + 2); scrollbarControl.SetSize(scrollWidth, dropDownRect.Height - 2); FontNode fNode = DialogResourceManager.GetGlobalInstance().GetFontNode((int)(elementList[2] as Element).FontIndex); if ((fNode != null) && (fNode.Height > 0)) { scrollbarControl.PageSize = (int)(dropDownTextRect.Height / fNode.Height); // The selected item may have been scrolled off the page. // Ensure that it is in page again. scrollbarControl.ShowItem(selectedIndex); } }
/// <summary>Called when the control should be rendered</summary> public override void Render(Device device, float elapsedTime) { if (!IsVisible) { return; // Nothing to render } Element e = elementList[ListBox.MainLayer] as Element; // Blend current color e.TextureColor.Blend(ControlState.Normal, elapsedTime); e.FontColor.Blend(ControlState.Normal, elapsedTime); Element selectedElement = elementList[ListBox.SelectionLayer] as Element; // Blend current color selectedElement.TextureColor.Blend(ControlState.Normal, elapsedTime); selectedElement.FontColor.Blend(ControlState.Normal, elapsedTime); parentDialog.DrawSprite(e, boundingBox); // Render the text if (itemList.Count > 0) { // Find out the height of a single line of text System.Drawing.Rectangle rc = textRect; System.Drawing.Rectangle sel = selectionRect; rc.Height = (int)(DialogResourceManager.GetGlobalInstance().GetFontNode((int)e.FontIndex).Height); textHeight = rc.Height; // If we have not initialized the scroll bar page size, // do that now. if (!isScrollBarInit) { if (textHeight > 0) { scrollbarControl.PageSize = (int)(textRect.Height / textHeight); } else { scrollbarControl.PageSize = textRect.Height; } isScrollBarInit = true; } rc.Width = textRect.Width; for (int i = scrollbarControl.TrackPosition; i < itemList.Count; ++i) { if (rc.Bottom > textRect.Bottom) { break; } ListBoxItem lb = (ListBoxItem)itemList[i]; // Determine if we need to render this item with the // selected element. bool isSelectedStyle = false; if ((selectedIndex == i) && (style == ListBoxStyle.SingleSelection)) { isSelectedStyle = true; } else if (style == ListBoxStyle.Multiselection) { if (isDragging && ((i >= selectedIndex && i < selectedStarted) || (i <= selectedIndex && i > selectedStarted))) { ListBoxItem selStart = (ListBoxItem)itemList[selectedStarted]; isSelectedStyle = selStart.IsItemSelected; } else { isSelectedStyle = lb.IsItemSelected; } } // Now render the text if (isSelectedStyle) { sel.Location = new System.Drawing.Point(sel.Left, rc.Top); sel.Height = rc.Height; parentDialog.DrawSprite(selectedElement, sel); parentDialog.DrawText(lb.ItemText, selectedElement, rc); } else { parentDialog.DrawText(lb.ItemText, e, rc); } rc.Offset(0, textHeight); } } // Render the scrollbar finally scrollbarControl.Render(device, elapsedTime); }
/// <summary>Called when the control should be rendered</summary> public override void Render(Device device, float elapsedTime) { ControlState state = ControlState.Normal; if (!isComboOpen) { state = ControlState.Hidden; } // Dropdown box Element e = elementList[ComboBox.DropdownLayer] as Element; // If we have not initialized the scroll bar page size, // do that now. if (!isScrollBarInit) { FontNode fNode = DialogResourceManager.GetGlobalInstance().GetFontNode((int)e.FontIndex); if ((fNode != null) && (fNode.Height > 0)) { scrollbarControl.PageSize = (int)(dropDownTextRect.Height / fNode.Height); } else { scrollbarControl.PageSize = dropDownTextRect.Height; } isScrollBarInit = true; } if (isComboOpen) { scrollbarControl.Render(device, elapsedTime); } // Blend current color e.TextureColor.Blend(state, elapsedTime); e.FontColor.Blend(state, elapsedTime); parentDialog.DrawSprite(e, dropDownRect); // Selection outline Element selectionElement = elementList[ComboBox.SelectionLayer] as Element; selectionElement.TextureColor.Current = e.TextureColor.Current; selectionElement.FontColor.Current = selectionElement.FontColor.States[(int)ControlState.Normal]; FontNode font = DialogResourceManager.GetGlobalInstance().GetFontNode((int)e.FontIndex); int currentY = dropDownTextRect.Top; int remainingHeight = dropDownTextRect.Height; for (int i = scrollbarControl.TrackPosition; i < itemList.Count; i++) { ComboBoxItem cbi = (ComboBoxItem)itemList[i]; // Make sure there's room left in the dropdown remainingHeight -= (int)font.Height; if (remainingHeight < 0) { // Not visible, store that item cbi.IsItemVisible = false; itemList[i] = cbi; // Store this back in list continue; } cbi.ItemRect = new System.Drawing.Rectangle(dropDownTextRect.Left, currentY, dropDownTextRect.Width, (int)font.Height); cbi.IsItemVisible = true; currentY += (int)font.Height; itemList[i] = cbi; // Store this back in list if (isComboOpen) { if (focusedIndex == i) { System.Drawing.Rectangle rect = new System.Drawing.Rectangle( dropDownRect.Left, cbi.ItemRect.Top - 2, dropDownRect.Width, cbi.ItemRect.Height + 4); parentDialog.DrawSprite(selectionElement, rect); parentDialog.DrawText(cbi.ItemText, selectionElement, cbi.ItemRect); } else { parentDialog.DrawText(cbi.ItemText, e, cbi.ItemRect); } } } int offsetX = 0; int offsetY = 0; state = ControlState.Normal; if (IsVisible == false) { state = ControlState.Hidden; } else if (IsEnabled == false) { state = ControlState.Disabled; } else if (isPressed) { state = ControlState.Pressed; offsetX = 1; offsetY = 2; } else if (isMouseOver) { state = ControlState.MouseOver; offsetX = -1; offsetY = -2; } else if (hasFocus) { state = ControlState.Focus; } float blendRate = (state == ControlState.Pressed) ? 0.0f : 0.8f; // Button e = elementList[ComboBox.ComboButtonLayer] as Element; // Blend current color e.TextureColor.Blend(state, elapsedTime, blendRate); System.Drawing.Rectangle windowRect = buttonRect; windowRect.Offset(offsetX, offsetY); // Draw sprite parentDialog.DrawSprite(e, windowRect); if (isComboOpen) { state = ControlState.Pressed; } // Main text box e = elementList[ComboBox.MainLayer] as Element; // Blend current color e.TextureColor.Blend(state, elapsedTime, blendRate); e.FontColor.Blend(state, elapsedTime, blendRate); // Draw sprite parentDialog.DrawSprite(e, textRect); if (selectedIndex >= 0 && selectedIndex < itemList.Count) { try { ComboBoxItem cbi = (ComboBoxItem)itemList[selectedIndex]; parentDialog.DrawText(cbi.ItemText, e, textRect); } catch { } // Ignore } }