Пример #1
0
        private void DrawThumbnails(float x, float y, float w, float h, int[] images, float t)
        {
            const float cornerRadius = 3.0f;
            const float thumb        = 60.0f;
            const float arry         = 30.5f;
            float       stackh       = (images.Length / 2) * (thumb + 10.0f) + 10.0f;
            float       u            = (1.0f + MathF.Cos(t * 0.5f)) * 0.5f;
            float       u2           = (1.0f - MathF.Cos(t * 0.2f)) * 0.5f;

            _nvg.Save();

            Paint shadowPaint = _nvg.BoxGradient(x, y + 4.0f, w, h, cornerRadius * 2.0f, 20.0f, _nvg.Rgba(0, 0, 0, 128), _nvg.Rgba(0, 0, 0, 0));

            _nvg.BeginPath();
            _nvg.Rect(x - 10.0f, y - 10.0f, w + 20.0f, h + 30.0f);
            _nvg.RoundedRect(x, y, w, h, cornerRadius);
            _nvg.PathWinding(Solidity.Hole);
            _nvg.FillPaint(shadowPaint);
            _nvg.Fill();

            _nvg.BeginPath();
            _nvg.RoundedRect(x, y, w, h, cornerRadius);
            _nvg.MoveTo(x - 10.0f, y + arry);
            _nvg.LineTo(x + 1.0f, y + arry - 11.0f);
            _nvg.LineTo(x + 1.0f, y + arry + 11.0f);
            _nvg.FillColour(_nvg.Rgba(200, 200, 200, 255));
            _nvg.Fill();

            _nvg.Save();
            _nvg.Scissor(x, y, w, h);
            _nvg.Translate(0, -(stackh - h) * u);

            float dv = 1.0f / (float)(images.Length - 1);

            for (uint i = 0; i < images.Length; i++)
            {
                float iw, ih;
                float ix, iy;
                float tx = x + 10.0f;
                float ty = y + 10.0f;
                tx += (i % 2) * (thumb + 10.0f);
                ty += (i / 2) * (thumb + 10.0f);
                _nvg.ImageSize(images[i], out uint imgW, out uint imgH);
                if (imgW < imgH)
                {
                    iw = thumb;
                    ih = iw * (float)imgH / (float)imgW;
                    ix = 0.0f;
                    iy = -(ih - thumb) * 0.5f;
                }
                else
                {
                    ih = thumb;
                    iw = ih * (float)imgW / (float)imgH;
                    ix = -(iw - thumb) * 0.5f;
                    iy = 0.0f;
                }

                float v = i * dv;
                float a = Clamp((u2 - v) / dv, 0.0f, 1.0f);

                if (a < 1.0f)
                {
                    DrawSpinner(tx + thumb / 2.0f, ty + thumb / 2.0f, thumb * 0.25f, t);
                }

                Paint imgPaint = Paint.ImagePattern(tx + ix, ty + iy, iw, ih, 0.0f / 180.0f * MathF.PI, images[i], a);
                _nvg.BeginPath();
                _nvg.RoundedRect(tx, ty, thumb, thumb, 5.0f);
                _nvg.FillPaint(imgPaint);
                _nvg.Fill();

                shadowPaint = Paint.BoxGradient(tx - 1.0f, ty, thumb + 2.0f, thumb + 2.0f, 5.0f, 3.0f, _nvg.Rgba(0, 0, 0, 128), _nvg.Rgba(0, 0, 0, 0));
                _nvg.BeginPath();
                _nvg.Rect(tx - 5.0f, ty - 5.0f, thumb + 10.0f, thumb + 10.0f);
                _nvg.RoundedRect(tx, ty, thumb, thumb, 6.0f);
                _nvg.PathWinding(Solidity.Hole);
                _nvg.FillPaint(shadowPaint);
                _nvg.Fill();

                _nvg.BeginPath();
                _nvg.RoundedRect(tx + 0.5f, ty + 0.5f, thumb - 1.0f, thumb - 1.0f, 4.0f - 0.5f);
                _nvg.StrokeWidth(1.0f);
                _nvg.StrokeColour(_nvg.Rgba(255, 255, 255, 192));
                _nvg.Fill();
            }
            _nvg.Restore();

            Paint fadePaint = _nvg.LinearGradient(x, y, x, y + 6.0f, _nvg.Rgba(200, 200, 200, 255), _nvg.Rgba(200, 200, 200, 0));

            _nvg.BeginPath();
            _nvg.Rect(x + 4.0f, y, w - 8.0f, 6.0f);
            _nvg.FillPaint(fadePaint);
            _nvg.Fill();

            fadePaint = _nvg.LinearGradient(x, y + h, x, y + h - 6.0f, _nvg.Rgba(200, 200, 200, 255), _nvg.Rgba(200, 200, 200, 0));
            _nvg.BeginPath();
            _nvg.Rect(x + 4.0f, y + h - 6.0f, w - 8.0f, 6.0f);
            _nvg.FillPaint(fadePaint);
            _nvg.Fill();

            shadowPaint = _nvg.BoxGradient(x + w - 12.0f + 1.0f, y + 4.0f + 1.0f, 8.0f, h - 8.0f, 3.0f, 4.0f, _nvg.Rgba(0, 0, 0, 32), _nvg.Rgba(0, 0, 0, 92));
            _nvg.BeginPath();
            _nvg.RoundedRect(x + w - 12.0f, y + 4.0f, 8.0f, h - 8.0f, 3.0f);
            _nvg.FillPaint(shadowPaint);
            _nvg.Fill();

            float scrollH = (h / stackh) * (h - 8.0f);

            shadowPaint = _nvg.BoxGradient(x + w - 12.0f - 1.0f, y + 4.0f + (h - 8.0f - scrollH) * u - 1.0f, 8.0f, scrollH, 3.0f, 4.0f, _nvg.Rgba(220, 220, 220, 255), _nvg.Rgba(128, 128, 128, 255));
            _nvg.BeginPath();
            _nvg.RoundedRect(x + w - 12.0f + 1.0f, y + 4.0f + 1.0f + (h - 8.0f - scrollH) * u, 8.0f - 2.0f, scrollH - 2.0f, 2.0f);
            _nvg.FillPaint(shadowPaint);
            _nvg.Fill();

            _nvg.Restore();
        }