예제 #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);
        }
예제 #2
0
        public static double ProgressBar(string str_id, double percent, Size size, string overlayText = null)
        {
            var window = GetCurrentWindow();

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

            //get or create the root node
            var id        = window.GetID(str_id);
            var container = window.RenderTree.CurrentContainer;
            var node      = container.GetNodeById(id);

            if (node == null)
            {
                //create node
                node             = new Node(id, $"ProgressBar<{str_id}>");
                node.UseBoxModel = true;
                node.RuleSet.Replace(GUISkin.Current[GUIControlName.ProgressBar]);
                node.AttachLayoutEntry(size);
            }
            container.AppendChild(node);
            node.ActiveSelf = true;

            // rect
            node.Rect = window.GetRect(id);

            // last item state
            window.TempData.LastItemState = node.State;

            // render
            percent = MathEx.Clamp01(percent);
            var rect      = node.Rect;
            var fillWidth = rect.Width * percent;
            var fillRect  = new Rect(rect.X, rect.Y, fillWidth, rect.Height);

            using (var dc = node.RenderOpen())
            {
                dc.DrawRectangle(new Brush(new Color(0.80f, 0.80f, 0.80f, 0.30f)), null, rect);
                dc.DrawRectangle(new Brush(new Color(0.90f, 0.70f, 0.00f, 1.00f)), null, fillRect);
                if (overlayText != null)
                {
                    dc.DrawGlyphRun(node.RuleSet, overlayText, node.Rect.Location);
                }
            }

            return(percent);
        }
예제 #3
0
 /// <summary>
 ///   <para>Linearly interpolates between a and b by t.</para>
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 /// <param name="t"></param>
 public static double Lerp(double a, double b, double t)
 {
     return(a + (b - a) * MathEx.Clamp01(t));
 }
예제 #4
0
 /// <summary>
 ///   <para>Linearly interpolates between a and b by t.</para>
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 /// <param name="t"></param>
 public static float Lerp(float a, float b, float t)
 {
     return(a + (b - a) * MathEx.Clamp01(t));
 }
예제 #5
0
 public static Color Lerp(Color a, Color b, double k)
 {
     k = MathEx.Clamp01(k);
     return(new Color(a.r + (b.r - a.r) * k, a.g + (b.g - a.g) * k, a.b + (b.b - a.b) * k, a.a + (b.a - a.a) * k));
 }