internal string uwfDrawTextField(string s, Font font, Color color, float x, float y, float width, float height, HorizontalAlignment alignment) { if (s == null) { s = ""; } UE.GUI.skin.textField.alignment = UE.TextAnchor.UpperLeft; switch (alignment) { case HorizontalAlignment.Center: UE.GUI.skin.textField.alignment = UE.TextAnchor.MiddleCenter; break; default: UE.GUI.skin.textField.alignment = UE.TextAnchor.MiddleLeft; break; case HorizontalAlignment.Right: UE.GUI.skin.textField.alignment = UE.TextAnchor.MiddleRight; break; } GUI_SetFont(UE.GUI.skin.textField, font); UE.GUI.color = color.ToUnityColor(); UE.GUI.skin.textField.hover.background = null; UE.GUI.skin.textField.active.background = null; UE.GUI.skin.textField.focused.background = null; UE.GUI.skin.textField.normal.background = null; return(UE.GUI.TextField(new UE.Rect(x, y, width, height), s)); }
public SizeF MeasureString(string text, Font font) { var labelSkin = UE.GUI.skin.label; int guiSkinFontSizeBuffer = GUI_SetFont(labelSkin, font); var size = labelSkin.CalcSize(new UE.GUIContent(text)); labelSkin.fontSize = guiSkinFontSizeBuffer; return(new SizeF(size.x, size.y)); }
internal string uwfDrawTextArea(string s, Font font, Color color, float x, float y, float width, float height) { if (s == null) { s = ""; } UE.GUI.skin.textArea.alignment = UE.TextAnchor.UpperLeft; UE.GUI.color = color.ToUnityColor(); //GUI.skin.textArea.hover.textColor = brush.Color.ToUColor(); GUI_SetFont(UE.GUI.skin.textArea, font); UE.GUI.skin.textArea.hover.background = null; UE.GUI.skin.textArea.active.background = null; UE.GUI.skin.textArea.focused.background = null; UE.GUI.skin.textArea.normal.background = null; return(UE.GUI.TextArea(new UE.Rect(x, y, width, height), s)); }
private static int GUI_SetFont(UE.GUIStyle style, Font font) { int guiSkinFontSizeBuffer = style.fontSize; if (font != null) { if (font.fontObject == null && global::UWinForms.Unity.UnityWinForms.gResources != null) { var fonts = global::UWinForms.Unity.UnityWinForms.gResources.Fonts; if (fonts != null) { for (int i = 0; i < fonts.Count; i++) { var fontItem = fonts[i]; if (fontItem.fontNames[0] != font.Name) { continue; } font.fontObject = fontItem; break; } } } if (font.fontObject != null) { style.font = (UE.Font)font.fontObject; } else { style.font = null; #if UNITY_EDITOR UnityEngine.Debug.LogError("Font not found: " + font.Name); #endif } var fontStyle = font.Style; style.fontSize = (int)font.Size; bool styleBold = (fontStyle & FontStyle.Bold) == FontStyle.Bold; bool styleItalic = (fontStyle & FontStyle.Italic) == FontStyle.Italic; if (styleBold) { if (styleItalic) { style.fontStyle = UnityEngine.FontStyle.BoldAndItalic; } else { style.fontStyle = UnityEngine.FontStyle.Bold; } } else if (styleItalic) { style.fontStyle = UnityEngine.FontStyle.Italic; } else { style.fontStyle = UnityEngine.FontStyle.Normal; } } else { if (UnityWinForms.gResources.Fonts.Count > 0) { var _font = UnityWinForms.gResources.Fonts[0]; if (_font != null) { style.font = _font; } style.fontSize = 12; style.fontStyle = UnityEngine.FontStyle.Normal; } } return(guiSkinFontSizeBuffer); }
public void DrawString(string text, Font font, Color color, float x, float y, float width, float height, ContentAlignment align, object material = null) { if (text == null || font == null) { return; } // TODO: material not supported. // Set align. var uAlign = UE.TextAnchor.UpperLeft; switch (align) { case ContentAlignment.BottomCenter: uAlign = UE.TextAnchor.LowerCenter; break; case ContentAlignment.BottomLeft: uAlign = UE.TextAnchor.LowerLeft; break; case ContentAlignment.BottomRight: uAlign = UE.TextAnchor.LowerRight; break; case ContentAlignment.MiddleCenter: uAlign = UE.TextAnchor.MiddleCenter; break; case ContentAlignment.MiddleLeft: uAlign = UE.TextAnchor.MiddleLeft; break; case ContentAlignment.MiddleRight: uAlign = UE.TextAnchor.MiddleRight; break; case ContentAlignment.TopCenter: uAlign = UE.TextAnchor.UpperCenter; break; case ContentAlignment.TopLeft: uAlign = UE.TextAnchor.UpperLeft; break; case ContentAlignment.TopRight: uAlign = UE.TextAnchor.UpperRight; break; } var labelSkin = UE.GUI.skin.label; int guiSkinFontSizeBuffer = GUI_SetFont(labelSkin, font); UE.GUI.color = color.ToUnityColor(); labelSkin.alignment = uAlign; textContent.text = text; // It's faster to invoke less methods and use your own GUIContent. Not that much, but anyway. UE.GUI.Label(new UE.Rect(x, y, width, height), textContent, labelSkin); labelSkin.fontSize = guiSkinFontSizeBuffer; }