Exemplo n.º 1
0
        public override void DrawSlider(PicoGfx gfx, Slider slider)
        {
            int x = slider.GlobalX;
            int y = slider.GlobalY;
            int w = slider.W;
            int h = slider.H;

            //var textSize = canvas.MeasureText(slider.Value.ToString(), _font);

            //var labelPosX = (x) + (w / 2 - textSize.Width / 2);
            //var labelPosY = (y + 2) + (h / 2 - textSize.Height / 2);

            float valueFactor = (float)(slider.Value) / (slider.MaxValue - slider.MinValue);

            if (slider.Orientation == Orientation.Horizontal)
            {
                DrawFrame(
                    gfx,
                    x, y,
                    w, h,
                    ref FrameOuterBorderColor,
                    ref FrameInnerBorderColor,
                    ref FrameFillColor,
                    drawShadow: true);


                int indicatorSize = (int)(valueFactor * w);

                indicatorSize = Calculate.Clamp(indicatorSize, 0, w - 4);

                gfx.SetColor(ref SliderFillColor);
                gfx.FillRect(x + 2, y + 2, indicatorSize, h - 4);

                //canvas.DrawText($"{slider.Value}", _font, labelPosX, labelPosY, 2);
            }
            else
            {
                DrawFrame(
                    gfx,
                    x, y,
                    w, h,
                    ref FrameOuterBorderColor,
                    ref FrameInnerBorderColor,
                    ref FrameFillColor,
                    drawShadow: true);

                int indicatorSize = (int)(((float)(slider.Value) / (slider.MaxValue - slider.MinValue)) * h);

                indicatorSize = Calculate.Clamp(indicatorSize, 0, h - 4);

                gfx.SetColor(ref SliderFillColor);
                gfx.FillRect(x + 2, y + 2, w - 3, indicatorSize);
            }
        }
Exemplo n.º 2
0
        private void DrawFrame(PicoGfx gfx, int x, int y, int w, int h, ref Color outerBorderColor, ref Color innerBorderColor, ref Color fillColor, bool drawShadow)
        {
            gfx.SetColor(ref outerBorderColor);
            gfx.DrawRect(x, y, w, h);

            gfx.SetColor(ref innerBorderColor);
            gfx.DrawRect(x + 1, y + 1, w - 2, h - 2);

            gfx.SetColor(ref fillColor);
            gfx.FillRect(x + 2, y + 2, w - 4, h - 4);
            if (drawShadow)
            {
                gfx.SetColor(ref outerBorderColor);
                gfx.DrawHLine(x, x + w - 1, y + h);
            }
        }