// ----------------------------------------------------------------------------- // | Internal method - cleans up an expanded menu. // ----------------------------------------------------------------------------- protected void retract() { isDragging = false; isExpanded = false; expandedBoxElement.Hide(); textAreaElement.Show(); smallBoxElement.Show(); smallBoxElement.MaterialName = ("SdkTrays/MiniTextBox"); smallBoxElement.BorderMaterialName = ("SdkTrays/MiniTextBox"); }
public override void CursorPressed(Vector2 cursorPos) { //Click the text area so that we can input if (IsCursorOver(inputBoxElement, cursorPos)) { isTextMode = true; inputBoxElement.MaterialName = "SdkTrays/MiniTextBox/Press"; inputBoxElement.BorderMaterialName = "SdkTrays/MiniTextBox/Press"; inputCursorElement.Show(); tick = init_tick; } else { isTextMode = false; inputBoxElement.MaterialName = "SdkTrays/MiniTextBox"; inputBoxElement.BorderMaterialName = "SdkTrays/MiniTextBox"; inputCursorElement.Hide(); tick = 0; } }
public InputBoxWidget(string name, string caption, float width, float boxWidth, string text = null) { isTextMode = false; element = OverlayManager.Singleton.CreateOverlayElementFromTemplate("AMGE/UI/InputBox", "BorderPanel", name); isFitToContents = false; inputBoxElement = (BorderPanelOverlayElement)((OverlayContainer)element).GetChild(name + "/InputBoxText"); inputBoxElement.Width = width - 10; captionTextAreaElement = (TextAreaOverlayElement)((OverlayContainer)element).GetChild(name + "/InputBoxCaption"); captionTextAreaElement.Width = width - inputBoxElement.Width; contentTextAreaElement = (TextAreaOverlayElement)inputBoxElement.GetChild(name + "/InputBoxText/InputBoxContentText"); contentTextAreaElement.Width = inputBoxElement.Width; inputCursorElement = (BorderPanelOverlayElement)inputBoxElement.GetChild(name + "/InputBoxText/InputBoxCursor"); inputCursorElement.Width = 2; inputCursorElement.Hide(); element.Width = width; originalText = string.Empty; if (boxWidth > 0) { if (width <= 0) { isFitToContents = true; } inputBoxElement.Width = boxWidth; inputBoxElement.Top = 2; inputBoxElement.Left = width - boxWidth - 5; element.Height = inputBoxElement.Height + 4; captionTextAreaElement.HorizontalAlignment = GuiHorizontalAlignment.GHA_LEFT; captionTextAreaElement.SetAlignment(TextAreaOverlayElement.Alignment.Left); captionTextAreaElement.Left = 12; captionTextAreaElement.Top = 9; } if (!string.IsNullOrEmpty(text)) { contentTextAreaElement.Caption = text; originalText = text; } setCaption(caption); }
public SelectMenuWidget(string name, string caption, float width, float boxWidth, uint maxItemsShown) { Items = new List <string>(); highlightIndex = 0; displayIndex = 0; dragOffset = 0.0f; selectionIndex = -1; isFitToContents = false; isCursorOver = false; isExpanded = false; isDragging = false; this.maxItemsShown = maxItemsShown; itemsShown = 0; element = (Mogre.BorderPanelOverlayElement)Mogre.OverlayManager.Singleton.CreateOverlayElementFromTemplate("SdkTrays/SelectMenu", "BorderPanel", name); textAreaElement = (Mogre.TextAreaOverlayElement)((Mogre.OverlayContainer)element).GetChild(name + "/MenuCaption"); smallBoxElement = (Mogre.BorderPanelOverlayElement)((Mogre.OverlayContainer)element).GetChild(name + "/MenuSmallBox"); smallBoxElement.Width = (width - 10); smallTextAreaElement = (Mogre.TextAreaOverlayElement)smallBoxElement.GetChild(name + "/MenuSmallBox/MenuSmallText"); element.Width = (width); if (boxWidth > 0f) // long style { if (width <= 0f) { isFitToContents = true; } smallBoxElement.Width = (boxWidth); smallBoxElement.Top = (2f); smallBoxElement.Left = (width - boxWidth - 5f); element.Height = (smallBoxElement.Height + 4f); textAreaElement.HorizontalAlignment = (GuiHorizontalAlignment.GHA_LEFT); textAreaElement.SetAlignment(Mogre.TextAreaOverlayElement.Alignment.Left); textAreaElement.Left = (12f); textAreaElement.Top = (10f); } expandedBoxElement = (Mogre.BorderPanelOverlayElement)((Mogre.OverlayContainer)element).GetChild(name + "/MenuExpandedBox"); expandedBoxElement.Width = (smallBoxElement.Width + 10); expandedBoxElement.Hide(); scrollTrackElement = (Mogre.BorderPanelOverlayElement)expandedBoxElement.GetChild(expandedBoxElement.Name + "/MenuScrollTrack"); scrollHandleElement = (Mogre.PanelOverlayElement)scrollTrackElement.GetChild(scrollTrackElement.Name + "/MenuScrollHandle"); setCaption(caption); }
public SimplePanelScrollableWidget(string name, float width = 0, float height = 0, float left = 0, float top = 0, float eachRowHeight = 0.03f, int col = 1, bool hasBorder = true) : base(name, width, height, left, top, (int)(height / eachRowHeight), col, hasBorder) { visualWidgets = new List <Widget>(); string scrollName = name + "_Scroll"; scroll = OverlayManager.Singleton.CreateOverlayElementFromTemplate("ScrollComponet", "BorderPanel", scrollName) as BorderPanelOverlayElement; drag = scroll.GetChild(scrollName + "/Drag") as OverlayElement; for (int i = 0; i < Rows.Count; i++) { Rows[i].Type = ValueType.Auto; } scroll.Left = -0.01f; scroll.Top = 0; AddChildOverlayElement(scroll); initDragTop = drag.Top; scroll.Hide(); drag.Hide(); }
public override void CursorPressed(Mogre.Vector2 cursorPos) { Mogre.OverlayManager om = Mogre.OverlayManager.Singleton; if (isExpanded) { if (scrollHandleElement.IsVisible) // check for scrolling { Mogre.Vector2 co = Widget.CursorOffset(scrollHandleElement, cursorPos); if (co.SquaredLength <= 81f) { isDragging = true; dragOffset = co.y; return; } else if (Widget.IsCursorOver(scrollTrackElement, cursorPos)) { float newTop = scrollHandleElement.Top + co.y; float lowerBoundary = scrollTrackElement.Height - scrollHandleElement.Height; scrollHandleElement.Top = (UIMathHelper.clamp <int>((int)newTop, 0, (int)lowerBoundary)); float scrollPercentage = UIMathHelper.clamp <float>(newTop / lowerBoundary, 0f, 1f); setDisplayIndex((uint)(scrollPercentage * (Items.Count - itemElements.Count) + 0.5f)); return; } } if (!IsCursorOver(expandedBoxElement, cursorPos, 3f)) { retract(); } else { float l = itemElements[0]._getDerivedLeft() * om.ViewportWidth + 5f; float t = itemElements[0]._getDerivedTop() * om.ViewportHeight + 5f; float r = l + itemElements[itemElements.Count - 1].Width - 10f; float b = itemElements[itemElements.Count - 1]._getDerivedTop() * om.ViewportHeight + itemElements[itemElements.Count - 1].Height - 5; if (cursorPos.x >= l && cursorPos.x <= r && cursorPos.y >= t && cursorPos.y <= b) { if (highlightIndex != selectionIndex) { SelectItem((uint)highlightIndex); } retract(); } } } else { if (Items.Count < 2) // don't waste time showing a menu if there's no choice { return; } if (IsCursorOver(smallBoxElement, cursorPos, 4f)) { expandedBoxElement.Show(); smallBoxElement.Hide(); // calculate how much vertical space we need float idealHeight = itemsShown * (smallBoxElement.Height - 8f) + 20f; expandedBoxElement.Height = (idealHeight); scrollTrackElement.Height = (expandedBoxElement.Height - 20f); expandedBoxElement.Left = (smallBoxElement.Left - 4f); // if the expanded menu goes down off the screen, make it go up instead if (smallBoxElement._getDerivedTop() * om.ViewportHeight + idealHeight > om.ViewportHeight) { expandedBoxElement.Top = (smallBoxElement.Top + smallBoxElement.Height - idealHeight + 3f); // if we're in thick style, hide the caption because it will interfere with the expanded menu if (textAreaElement.HorizontalAlignment == GuiHorizontalAlignment.GHA_CENTER) { textAreaElement.Hide(); } } else { expandedBoxElement.Top = (smallBoxElement.Top + 3f); } isExpanded = true; highlightIndex = selectionIndex; setDisplayIndex((uint)highlightIndex); if (itemsShown < Items.Count) // update scrollbar position { scrollHandleElement.Show(); float lowerBoundary = scrollTrackElement.Height - scrollHandleElement.Height; scrollHandleElement.Top = ((int)(displayIndex * lowerBoundary / (Items.Count - itemElements.Count))); } else { scrollHandleElement.Hide(); } } } }