protected GUIStyle GetStyle(SkinIMGUIDrawer context, IScWidget widget) { var entry = context.GetEntry(widget); if (entry.Style == null) { entry.Style = CreateStyle(context, widget); } return(entry.Style); }
protected GUIStyle GetStyle(SkinIMGUIDrawer context, IScWidget widget, string def) { var entry = context.GetEntry(widget); if (entry.Style == null) { entry.Style = new GUIStyle(def); } return(entry.Style); }
protected GUIStyle GetStyle(string key, SkinIMGUIDrawer context, IScWidget widget, string def) { var entry = context.GetEntry(widget); if (entry.Styles == null) { entry.Styles = new Dictionary <string, GUIStyle>(); } GUIStyle style; if (!entry.Styles.TryGetValue(key, out style)) { entry.Styles[key] = style = new GUIStyle(def); } return(style); }
protected override void Run(SkinIMGUIDrawer context, ScInputField widget) { if (widget.IsOutsideClip()) { return; } var entry = context.GetEntry(widget); var rect = widget.GetRect(); var style = GetStyle(context, widget, "TextField"); style.normal.background = context.Skin.Box.texture; style.normal.textColor = new Color(0.4f, 0.4f, 0.4f); style.active.background = context.Skin.Box.texture; style.active.textColor = new Color(0, 0, 0); style.hover.background = context.Skin.Box.texture; style.hover.textColor = new Color(0, 0, 0); style.focused.background = context.Skin.Box.texture; style.focused.textColor = new Color(0, 0, 0); style.border = s_Border; style.fontSize = widget.FontSize; style.alignment = widget.TextAnchor; if (Event.current.type == EventType.Repaint) { var bgColor = GUI.backgroundColor; try { if (entry.ControlId != 0 && entry.ControlId + 1 == GUIUtility.keyboardControl) { GUI.backgroundColor = context.Skin.Color.Active; } else { GUI.backgroundColor = context.Skin.Color.Disable; } style.Draw(rect, false, false, false, false); } finally { GUI.backgroundColor = bgColor; } } rect.position += new Vector2(2f, 2f); rect.size -= new Vector2(4f, 4f); { var bgColor = GUI.backgroundColor; var cursorColor = GUI.skin.settings.cursorColor; try { GUI.skin.settings.cursorColor = new Color(0, 0, 0); GUI.backgroundColor = context.Skin.Color.Base; entry.ControlId = GUIUtility.GetControlID(FocusType.Keyboard); var input = GUI.TextField(rect, widget.Input, style); if (input != widget.Input) { context.Schedule(() => { widget.Set(input); }); } } finally { GUI.backgroundColor = bgColor; GUI.skin.settings.cursorColor = cursorColor; } } }
protected float DrawProgress(SkinIMGUIDrawer context, ScWidget widget, float val, float min, float max) { var sliderBase = GetStyle("SliderBase", context, widget, "HorizontalSlider"); var sliderActive = GetStyle("SliderActive", context, widget, "HorizontalSlider"); var thumb = GetStyle("Thumb", context, widget, "HorizontalSliderThumb"); var rect = widget.GetRect(); var baseSprite = context.Skin.Box; var height = Mathf.Clamp(rect.height, baseSprite.texture.height * 1.2f, baseSprite.texture.height * 2f); sliderBase.normal.background = baseSprite.texture; sliderBase.active.background = baseSprite.texture; sliderBase.fixedHeight = height; sliderBase.border.Set(baseSprite.border.x, baseSprite.border.y); sliderBase.padding.Reset(); sliderBase.stretchHeight = false; sliderActive.margin.Reset(); sliderActive.normal.background = baseSprite.texture; sliderActive.active.background = baseSprite.texture; sliderActive.border.Set(baseSprite.border.x, baseSprite.border.y); sliderActive.fixedHeight = height - 4; sliderActive.stretchHeight = false; sliderActive.margin.Set(top: 2, bottom: 2); sliderActive.padding = s_ZeroOffset; thumb.normal.background = context.Skin.Box.texture; thumb.hover.background = context.Skin.Box.texture; thumb.active.background = context.Skin.Box.texture; if (context.IsEditorGUI) { thumb.fixedWidth = height - 8f; thumb.fixedHeight = height - 8f; } else { thumb.fixedWidth = height - 2f; thumb.fixedHeight = height - 2f; } var bgColor = GUI.backgroundColor; try { var sliderRect = new Rect(rect); sliderRect.x += 2; sliderRect.width -= 4; GUI.backgroundColor = context.Skin.Color.Disable; GUI.Label(sliderRect, "", sliderBase); sliderRect.y += 2; sliderRect.x += 2; sliderRect.width -= 4; sliderRect.width = Mathf.Max(thumb.fixedWidth - 4, (sliderRect.width * val - min) / max); GUI.backgroundColor = context.Skin.Color.Active; GUI.Label(sliderRect, "", sliderActive); GUI.backgroundColor = context.Skin.Color.Base; var entry = context.GetEntry(widget); entry.ControlId = GUIUtility.GetControlID(FocusType.Passive) + 1; entry.DisableDragIfHotControl = true; return(GUI.HorizontalSlider(rect, val, min, max, GetStyle("Empty", context, widget), thumb)); } finally { GUI.backgroundColor = bgColor; } }