/// <summary> /// Static utility method to cut off a string to fit in a text area. /// </summary> public static void FitCaptionToArea(string caption, ref Mogre.TextAreaOverlayElement area, float maxWidth) { Mogre.FontPtr font = null; if (Mogre.FontManager.Singleton.ResourceExists(area.FontName)) { font = (Mogre.FontPtr)Mogre.FontManager.Singleton.GetByName(area.FontName); if (!font.IsLoaded) { font.Load(); } } else { OGRE_EXCEPT("this font:", area.FontName, "is not exist"); } Mogre.FontPtr f = font; string s = DisplayStringToString(caption); //int nl = s.find('\n'); //if (nl != string.npos) // s = s.substr(0, nl); int nl = s.IndexOf('\n'); if (nl != -1) { s = s.Substring(0, nl); } float width = 0; for (int i = 0; i < s.Length; i++) { if (s[i] == ' ' && area.SpaceWidth != 0) { width += area.SpaceWidth; } else { width += f.GetGlyphAspectRatio(s[i]) * area.CharHeight; } if (width > maxWidth) { s = s.Substring(0, i); break; } } area.Caption = (s); }
public Slider(string name, string caption, float width, float trackWidth, float valueBoxWidth, float minValue, float maxValue, uint snaps) { mDragOffset = 0.0f; mValue = 0.0f; mMinValue = 0.0f; mMaxValue = 0.0f; mInterval = 0.0f; mDragging = false; mFitToContents = false; element = Mogre.OverlayManager.Singleton.CreateOverlayElementFromTemplate("SdkTrays/Slider", "BorderPanel", name); element.Width = (width); Mogre.OverlayContainer c = (Mogre.OverlayContainer)element; mTextArea = (Mogre.TextAreaOverlayElement)c.GetChild(Name + "/SliderCaption"); Mogre.OverlayContainer valueBox = (Mogre.OverlayContainer)c.GetChild(Name + "/SliderValueBox"); valueBox.Width = (valueBoxWidth); valueBox.Left = (-(valueBoxWidth + 5)); mValueTextArea = (Mogre.TextAreaOverlayElement)valueBox.GetChild(valueBox.Name + "/SliderValueText"); mTrack = (Mogre.BorderPanelOverlayElement)c.GetChild(Name + "/SliderTrack"); mHandle = (Mogre.PanelOverlayElement)mTrack.GetChild(mTrack.Name + "/SliderHandle"); if (trackWidth <= 0f) // tall style { mTrack.Width = (width - 16f); } else // long style { if (width <= 0f) { mFitToContents = true; } element.Height = (34f); mTextArea.Top = (10f); valueBox.Top = (2f); mTrack.Top = (-23f); mTrack.Width = (trackWidth); mTrack.HorizontalAlignment = (GuiHorizontalAlignment.GHA_RIGHT); mTrack.Left = (-(trackWidth + valueBoxWidth + 5f)); } setCaption(caption); setRange(minValue, maxValue, snaps, false); }