protected override void Run(SkinIMGUIDrawer context, ScButton widget) { if (widget.IsOutsideClip()) { return; } var style = GetStyle(context, widget); var tmpColor = GUI.backgroundColor; try { GUI.backgroundColor = context.Skin.Color.Main; if (GUI.Button(widget.GetRect(), "", style)) { context.Schedule(() => { widget.Invoke(); }); GUI.FocusControl(""); } } finally { GUI.backgroundColor = tmpColor; } }
void RunSwitchStyle(GUIStyle style, SkinIMGUIDrawer context, ScToggle widget) { var rect = widget.GetRect(); style.fontSize = (int)(rect.height / 2.5f); var border = context.Skin.Circle.border; style.border.left = (int)border.x; style.border.right = (int)border.y; var tmpColor = GUI.backgroundColor; var tmpContentColor = GUI.contentColor; try { GUI.backgroundColor = widget.Value ? context.Skin.Color.Active : context.Skin.Color.Disable; GUI.contentColor = widget.Value ? context.Skin.Color.TextOnActive : context.Skin.Color.TextOnDisable; style.alignment = widget.Value ? TextAnchor.MiddleLeft : TextAnchor.MiddleRight; style.padding.left = 2 + (int)(rect.height / 4f); style.padding.right = (int)(rect.height / 4f); string text = widget.Value ? "ON" : "OFF"; var ret = GUI.Toggle(widget.GetRect(), widget.Value, text, style); if (ret != widget.Value) { context.Schedule(() => { widget.Set(ret); }); GUI.FocusControl(""); } } finally { GUI.backgroundColor = tmpColor; GUI.contentColor = tmpContentColor; } var leftPos = rect.position + new Vector2(2f, 2f); var height = rect.height - 4; var rightPos = new Vector2(rect.xMax - height - 2, leftPos.y); var size = new Vector2(height, height); if (widget.Value) { GUI.DrawTexture(new Rect(rightPos, size), context.Skin.Circle.texture); } else { GUI.DrawTexture(new Rect(leftPos, size), context.Skin.Circle.texture); } }
protected override void Run(SkinIMGUIDrawer context, ScRadioButton widget) { if (widget.IsOutsideClip()) { return; } var dummtyStyle = GetStyle("Dummy", context, widget); var buttonStyle = GetStyle("Button", context, widget); var rect = widget.GetRect(); var size = Vector2.Max(new Vector2(16, 16), Vector2.Min(rect.size, context.Skin.Circle.rect.size)); if (size.x > size.y) { size.x = size.y; } else { size.y = size.x; } var bgColor = GUI.backgroundColor; try { GUI.backgroundColor = context.Skin.Color.Line; GUI.Label(new Rect(rect.position, size), "", buttonStyle); GUI.backgroundColor = context.Skin.Color.Base; GUI.Label(new Rect(rect.position + new Vector2(1f, 1f), size - new Vector2(2f, 2f)), "", buttonStyle); if (widget.Value) { GUI.backgroundColor = context.Skin.Color.Active; GUI.Label(new Rect(rect.position + size / 4f, size - size / 2f), "", buttonStyle); } } finally { GUI.backgroundColor = bgColor; } var ret = GUI.Toggle(widget.GetRect(), widget.Value, "", dummtyStyle); if (ret && ret != widget.Value) { context.Schedule(() => { widget.Select(); }); GUI.FocusControl(""); } }
void RunCircleStyle(GUIStyle style, SkinIMGUIDrawer context, ScToggle widget) { var rect = widget.GetRect(); style.normal.background = context.Skin.Circle.texture; style.active.background = context.Skin.Circle.texture; style.onNormal.background = context.Skin.Circle.texture; style.onActive.background = context.Skin.Circle.texture; style.onHover.background = context.Skin.Circle.texture; style.fontSize = (int)(rect.height / 3f); style.padding.left = 2; style.padding.right = 0; var tmpColor = GUI.backgroundColor; var tmpContentColor = GUI.contentColor; try { GUI.backgroundColor = widget.Value ? context.Skin.Color.Active : context.Skin.Color.Disable; GUI.contentColor = widget.Value ? context.Skin.Color.TextOnActive : context.Skin.Color.TextOnDisable; string text = widget.Value ? "ON" : "OFF"; var ret = GUI.Toggle(widget.GetRect(), widget.Value, text, style); if (ret != widget.Value) { context.Schedule(() => { widget.Set(ret); }); GUI.FocusControl(""); } } finally { GUI.backgroundColor = tmpColor; GUI.contentColor = tmpContentColor; } }
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 override void Run(SkinIMGUIDrawer context, ScCheckBox widget) { if (widget.IsOutsideClip()) { return; } var style = GetStyle(context, widget); var rect = widget.GetRect(); style.fixedWidth = rect.width; style.fixedHeight = rect.height; var bgColor = GUI.backgroundColor; try { if (widget.Value) { GUI.backgroundColor = context.Skin.Color.Active; } else { GUI.backgroundColor = context.Skin.Color.Disable; } var ret = GUI.Toggle(rect, widget.Value, "", style); if (ret != widget.Value) { context.Schedule(() => { widget.Value = ret; }); GUI.FocusControl(""); } } finally { GUI.backgroundColor = bgColor; } if (Event.current.type == EventType.Repaint) { rect.position += new Vector2(2f, 2f); rect.size -= new Vector2(4f, 4f); style.fixedWidth = rect.width; style.fixedHeight = rect.height; style.Draw(rect, context.Skin.Check.texture, false, false, false, false); var color = GUI.backgroundColor; try { if (widget.Value) { GUI.backgroundColor = context.Skin.Color.Active; } else { GUI.backgroundColor = context.Skin.Color.Disable; } var label = GetStyle("Label", context, widget, "Label"); label.fixedWidth = rect.width; label.fixedHeight = rect.height; label.stretchHeight = true; label.stretchWidth = true; label.normal.background = context.Skin.Check.texture; label.Draw(rect, false, false, false, false); } finally { GUI.backgroundColor = bgColor; } } }