Ejemplo n.º 1
0
        public static double ProgressBar(string str_id, double percent, Size size, string overlayText = null)
        {
            Window window = GetCurrentWindow();

            if (window.SkipItems)
            {
                return(percent);
            }

            GUIContext g  = GetCurrentContext();
            int        id = window.GetID(str_id);

            // style
            var style = GUIStyle.Basic;

            // rect
            var rect = window.GetRect(id, size);

            percent = MathEx.Clamp01(percent);

            // render
            DrawList d = window.DrawList;

            GUIAppearance.DrawProgressBar(rect, percent);
            if (overlayText != null)
            {
                style.PushTextAlignment(TextAlignment.Center);
                d.DrawBoxModel(rect, overlayText, style);
                style.PopStyle();
            }

            return(percent);
        }
Ejemplo n.º 2
0
        public static Color ColorField(string label, Color value)
        {
            Window window = GetCurrentWindow();

            if (window.SkipItems)
            {
                return(value);
            }

            var style = GUIStyle.Basic;

            var id = window.GetID(label);

            // rect

            int rId;
            int gId;
            int bId;
            int aId;
            int colorId;

            Rect rectR, rectG, rectB, rectA, rectColor;

            var labelHeight = style.CalcSize(label, GUIState.Normal).Height;

            BeginHorizontal("FieldGroup~" + id);
            {
                {
                    using (HScope("#RGBA&Color", GUILayout.ExpandWidth(true)))
                    {
                        using (VScope(label + "#RGBA"))
                        {
                            using (HScope("#RGB"))
                            {
                                PushHStretchFactor(1);
                                rId   = window.GetID("#R");
                                gId   = window.GetID("#G");
                                bId   = window.GetID("#B");
                                rectR = window.GetRect(rId, (0, labelHeight));
                                rectG = window.GetRect(gId, (0, labelHeight));
                                rectB = window.GetRect(bId, (0, labelHeight));
                                PopStyleVar(1);
                            }

                            aId   = window.GetID("#A");
                            rectA = window.GetRect(aId, (0, labelHeight * 0.25), GUILayout.ExpandWidth(true));
                        }
                        colorId   = window.GetID("#Color");
                        rectColor = window.GetRect(colorId, (labelHeight * 1.25f, labelHeight * 1.25f));
                    }

                    // interact
                    value.R = GUIBehavior.SliderBehavior(rectR, rId, true, value.R, 0, 1.0, out bool R_hovered, out bool R_held);
                    value.G = GUIBehavior.SliderBehavior(rectG, gId, true, value.G, 0, 1.0, out bool G_hovered, out bool G_held);
                    value.B = GUIBehavior.SliderBehavior(rectB, bId, true, value.B, 0, 1.0, out bool B_hovered, out bool B_held);
                    value.A = GUIBehavior.SliderBehavior(rectA, aId, true, value.A, 0, 1.0, out bool A_hovered, out bool A_held);

                    // render
                    var d = window.DrawList;
                    DrawColorDragButton(d, rectR, rId, 'R', value.R, (R_hovered && R_held) ? GUIState.Active : R_hovered?GUIState.Hover: GUIState.Normal);
                    DrawColorDragButton(d, rectG, gId, 'G', value.G, (G_hovered && G_held) ? GUIState.Active : G_hovered?GUIState.Hover: GUIState.Normal);
                    DrawColorDragButton(d, rectB, bId, 'B', value.B, (B_hovered && B_held) ? GUIState.Active : B_hovered?GUIState.Hover: GUIState.Normal);

                    GUIAppearance.DrawProgressBar(rectA, value.A);

                    d.AddRectFilled(rectColor, value);
                }

                Space("FieldSpacing", GUISkin.Current.FieldSpacing);
                Label(label, GUILayout.Width((int)GUISkin.Current.LabelWidth));
            }
            EndHorizontal();

            return(value);
        }