Пример #1
0
        public void TestGraphics()
        {
            var gapi = Sciter.GraphicsApi;

            IntPtr himg;
            var    a = gapi.ImageCreate(out himg, 400, 400, true);

            IntPtr hgfx;

            gapi.GraphicsCreate(himg, out hgfx);

            IntPtr hpath;

            gapi.PathCreate(out hpath);

            var b = gapi.GraphicsPushClipPath(hgfx, hpath, 0.5f);
            var c = gapi.GraphicsPopClip(hgfx);

            // RGBA
            var actual = SciterColor.Create(1, 2, 3, 4);

            Assert.AreEqual(1, actual.R);
            Assert.AreEqual(2, actual.G);
            Assert.AreEqual(3, actual.B);
            Assert.AreEqual(4, actual.A);
        }
Пример #2
0
        public void SciterColor_ToString(byte r, byte g, byte b, byte a, string expected)
        {
            var actual = SciterColor.Create(r, g, b, a);

            Assert.AreEqual(actual.ToString(CultureInfo.InvariantCulture), actual.ToString(null));
            Assert.AreEqual(expected, actual.ToString(null));
        }
Пример #3
0
        private byte[] GenerateThemeContent(LoadDataArgs args)
        {
            var accentColor       = _uiSettings.GetColorValue(UIColorType.Accent);
            var backgroundColor   = _uiSettings.GetColorValue(UIColorType.Background);
            var foregroundColor   = _uiSettings.GetColorValue(UIColorType.Foreground);
            var accentLight2Color = _uiSettings.GetColorValue(UIColorType.AccentLight2);

            SciterColor sciterAccentColor =
                SciterColor.Create(accentColor.R, accentColor.G, accentColor.B, accentColor.A);
            SciterColor sciterBackgroundColor = SciterColor.Create(backgroundColor.R, backgroundColor.G,
                                                                   backgroundColor.B, backgroundColor.A);
            SciterColor sciterForeground = SciterColor.Create(foregroundColor.R, foregroundColor.G,
                                                              foregroundColor.B, foregroundColor.A);
            SciterColor sciterAccentLight2 = SciterColor.Create(accentLight2Color.R, accentLight2Color.G,
                                                                accentLight2Color.B, accentLight2Color.A);

            var themeCss =
                @$ " html:theme(system) {{
    var(accent-color): {sciterAccentColor.ToShortHtmlColor()};
    var(main-bg-color): {sciterBackgroundColor.ToShortHtmlColor()};
    var(main-color): {sciterForeground.ToShortHtmlColor()};

    var(card-bg-color): morph(color(main-color), opacity: 7.5%);
    var(card-bd-color): morph(color(main-color), opacity: 50%);
    var(card-bd-width): 2dip;

    var(header-bg-color): color(accent-color);

    var(toolbar-bg-color): morph(color(main-color), opacity: 10%);

    var(menu-main-color): #D0D2D6;

    var(menu-color): morph(rgb(255,255,255), opacity: 85%);
    var(menu-bg-color): morph(#262930, darken: 4%);

    var(menu-h-color): morph(color(menu-color), lighten: 10%);
    var(menu-h-bg-color): morph(color(accent-color), opacity: 75%);
}}

card:theme(system) {{
    border: transparent;
    box-shadow: none;
}}

card:hover:theme(system) {{
    box-shadow: none;
}}

cardheader:theme(system) > div:nth-child(2) {{
    color: {sciterAccentLight2.ToShortHtmlColor()};
    opacity: 1;
}}

";

            return(System.Text.Encoding.UTF8.GetBytes(themeCss));
        }
    }
}
Пример #4
0
        public void SciterColor_from_uint(uint color, int r, int g, int b, int a)
        {
            var actual = SciterColor.Create(color);

            Assert.AreEqual(r, actual.R);
            Assert.AreEqual(g, actual.G);
            Assert.AreEqual(b, actual.B);
            Assert.AreEqual(a, actual.A);
        }
Пример #5
0
        public void Alpha_as_int(byte r, byte g, byte b, byte a)
        {
            var actual = SciterColor.Create(r, g, b, a);

            Assert.AreEqual(r, actual.R);
            Assert.AreEqual(g, actual.G);
            Assert.AreEqual(b, actual.B);
            Assert.AreEqual(a, actual.A);
        }
Пример #6
0
        public void Test_max_value()
        {
            var actual = SciterColor.Create(byte.MaxValue, byte.MaxValue, byte.MaxValue, float.MaxValue);

            Assert.AreEqual(255, actual.R);
            Assert.AreEqual(255, actual.G);
            Assert.AreEqual(255, actual.B);
            Assert.AreEqual(255, actual.A);
        }
Пример #7
0
        public void Test_min_value()
        {
            var actual = SciterColor.Create(byte.MinValue, byte.MinValue, byte.MinValue, byte.MinValue);

            Assert.AreEqual(0, actual.R);
            Assert.AreEqual(0, actual.G);
            Assert.AreEqual(0, actual.B);
            Assert.AreEqual(0, actual.A);
        }
Пример #8
0
        public void Alpha_as_float(byte r, byte g, byte b, float a)
        {
            var actual = SciterColor.Create(r, g, b, a);

            Assert.AreEqual(r, actual.R);
            Assert.AreEqual(g, actual.G);
            Assert.AreEqual(b, actual.B);
            Assert.AreEqual((int)(a * byte.MaxValue), actual.A);
        }
Пример #9
0
        public void Basic(byte r, byte g, byte b)
        {
            var actual = SciterColor.Create(r, g, b);

            Assert.AreEqual(r, actual.R);
            Assert.AreEqual(g, actual.G);
            Assert.AreEqual(b, actual.B);
            Assert.AreEqual(byte.MaxValue, actual.A);
        }
Пример #10
0
        public void Value_from_SciterColor_RGBA(byte r, byte g, byte b, byte a)
        {
            var color = SciterColor.Create(r, g, b, a);

            var actual = SciterValue.Create(color);

            Assert.IsTrue(actual.IsColor);
            Assert.AreEqual(color, actual.AsColor());
        }
Пример #11
0
        public void From_System_Drawing_Color(int r, int g, int b, int a)
        {
            var color  = Color.FromArgb(a, r, g, b);
            var actual = SciterColor.Create(color);

            Assert.AreEqual(r, actual.R);
            Assert.AreEqual(g, actual.G);
            Assert.AreEqual(b, actual.B);
            Assert.AreEqual(a, actual.A);
        }
Пример #12
0
        public void Create_and_clear_image(byte r, byte g, byte b, byte alpha)
        {
            _sciterImage = SciterImage.Create(1, 1, true);
            _sciterImage.Clear(SciterColor.Create(r: r, g: g, b: b, alpha: alpha));

            var buffer = _sciterImage.Save(ImageEncoding.Raw);

            Assert.NotNull(_sciterImage);
            Assert.AreEqual(1 * 1 * 4, buffer.Length);
            Assert.AreEqual(new byte[] { (byte)(r / (byte.MaxValue / alpha)), (byte)(g / (byte.MaxValue / alpha)), (byte)(b / (byte.MaxValue / alpha)), alpha }, buffer);
        }
Пример #13
0
        private void DrawSwissClock(
            SciterGraphics graphics,
            SciterRectangle area,
            float scale,
            DateTime timeInfo)
        {
            var markColor   = SciterColor.Black;
            var hourColor   = SciterColor.Black;
            var minuteColor = SciterColor.Black;
            var secondColor = SciterColor.Create(0xA9, 0x33, 0x2A);

            graphics
            .SaveState()
            .Translate(area.Left + area.Width / 2.0f, area.Top + area.Height / 2.0f)
            .Scale(scale, scale)
            .Rotate(-Pi / 2)
            .SetLineColor(SciterColor.Transparent)
            .SetLineCap(LineCapType.Square);

            // Hour marks
            graphics
            .SaveState()
            .SetLineWidth(10f)
            .SetLineColor(markColor);

            for (int i1 = 0; i1 < 12; ++i1)
            {
                graphics.Rotate(Pi / 6, 0, 0);
                graphics.DrawLine(125f, 0, 140f, 0);
            }

            graphics.RestoreState();


            // Minute marks
            graphics
            .SaveState()
            .SetLineWidth(2f)
            .SetLineColor(markColor);
            for (int i = 0; i < 60; ++i)
            {
                if (i % 5 != 0)
                {
                    graphics.DrawLine(134f, 0, 144f, 0);
                }
                graphics.Rotate(Pi / 30f);
            }

            graphics.RestoreState();


            int sec = timeInfo.Second;
            int min = timeInfo.Minute;
            int hr  = timeInfo.Hour;

            hr = hr >= 12 ? hr - 12 : hr;

            // draw Hours
            graphics.SaveState()
            .Rotate(hr * (Pi / 6) + (Pi / 360) * min + (Pi / 21600) * sec)
            .SetLineWidth(10f)
            .SetLineColor(hourColor)
            .DrawLine(-40, 0, 80, 0)
            .RestoreState();

            // draw Minutes
            graphics
            .SaveState()
            .Rotate((Pi / 30) * min + (Pi / 1800) * sec)
            .SetLineWidth(10f)
            .SetLineColor(minuteColor)
            .DrawLine(-40, 0, 130, 0)
            .RestoreState();

            graphics
            .SaveState()
            .Rotate(sec * Pi / 30)
            .SetLineColor(secondColor)
            .SetFillColor(secondColor)
            .SetLineWidth(4)
            .DrawLine(-40, 0, 110, 0)
            .DrawEllipse(0, 0, 3, 3)
            .SetFillColor(SciterColor.Gold)
            .SetLineWidth(1f)
            .DrawEllipse(0, 0, 2, 2)
            .SetFillColor(secondColor)
            .DrawEllipse(105, 0, 10, 10)
            .RestoreState();

            graphics.RestoreState();
        }
Пример #14
0
        public void SciterColor_ToSingle(byte r, byte g, byte b, byte a, float expected)
        {
            var actual = SciterColor.Create(r, g, b, a);

            Assert.AreEqual(expected, actual.ToSingle());
        }
Пример #15
0
        private void DrawDefaultClock(
            SciterGraphics graphics,
            SciterRectangle area,
            float scale,
            DateTime timeInfo)
        {
            var markColor   = SciterColor.White;
            var hourColor   = SciterColor.White;
            var minuteColor = SciterColor.White;
            var secondColor = SciterColor.Create(0xF3, 0x7F, 0x14);

            graphics
            .SaveState()
            .Translate(area.Left + area.Width / 2.0f, area.Top + area.Height / 2.0f)
            .Scale(scale, scale)
            .Rotate(-Pi / 2)
            .SetLineColor(SciterColor.Transparent)
            .SetLineCap(LineCapType.Round);

            // Hour marks
            graphics
            .SaveState()
            .SetLineWidth(10f)
            .SetLineColor(markColor);

            for (int i1 = 0; i1 < 12; ++i1)
            {
                graphics.Rotate(Pi / 6, 0, 0);
                graphics.DrawLine(125f, 0, 140f, 0);
            }

            graphics.RestoreState();


            // Minute marks
            graphics
            .SaveState()
            .SetLineWidth(2f)
            .SetLineColor(markColor);
            for (int i = 0; i < 60; ++i)
            {
                if (i % 5 != 0)
                {
                    graphics.DrawLine(134f, 0, 144f, 0);
                }
                graphics.Rotate(Pi / 30f);
            }

            graphics.RestoreState();


            int sec = timeInfo.Second;
            int min = timeInfo.Minute;
            int hr  = timeInfo.Hour;

            hr = hr >= 12 ? hr - 12 : hr;

            // draw Hours
            graphics.SaveState()
            .Rotate(hr * (Pi / 6) + (Pi / 360) * min + (Pi / 21600) * sec)
            .SetLineWidth(10f)
            .SetLineColor(hourColor)
            .DrawLine(-20, 0, 50, 0)
            .RestoreState();

            // draw Minutes
            graphics
            .SaveState()
            .Rotate((Pi / 30) * min + (Pi / 1800) * sec)
            .SetLineWidth(10f)
            .SetLineColor(minuteColor)
            .DrawLine(-20, 0, 100, 0)
            .RestoreState();

            graphics
            .SaveState()
            .Rotate(sec * Pi / 30)
            .SetLineColor(secondColor)
            .SetFillColor(secondColor)
            .SetLineWidth(6f)
            .DrawLine(-20f, 0, 80, 0)
            .DrawEllipse(0, 0, 10, 10)
            .SetFillColor(SciterColor.Transparent)
            .DrawEllipse(90, 0, 8, 8)
            .SetLineWidth(1f)
            .SetLineColor(SciterColor.Goldenrod)
            .SetFillColor(SciterColor.Gold)
            .DrawEllipse(0, 0, 2, 2)
            .RestoreState();

            graphics.RestoreState();

            //graphics.DrawText(
            //	SciterText.CreateForElementAndStyle($"{timeinfo.Hour:00}:{timeinfo.Second:00}", se,
            //		$"font-size:24pt;color:{secondColorHex}"), area.Left + area.Width / 2.0f,
            //	area.Top + area.Height / 4.0f, 5);
        }
Пример #16
0
        public void DrawEllipse(string behaviorName)
        {
            var random = new Random();

            _mockBehaviorResolver.Setup(resolver => resolver.GetBehaviorHandler(behaviorName))
            .Returns(() =>
            {
                return(new DrawContentBehavior(_sciterWindow, (element, prms) =>
                {
                    switch (prms.DrawEvent)
                    {
                    case DrawEvent.Content:
                        using (var graphics = SciterGraphics.Create(prms.Handle))
                        {
                            for (int i = 0; i < byte.MaxValue; i++)
                            {
                                var color = SciterColor.Create(
                                    (byte)random.Next(byte.MinValue, byte.MaxValue),
                                    (byte)random.Next(byte.MinValue, byte.MaxValue),
                                    (byte)random.Next(byte.MinValue, byte.MaxValue),
                                    (byte)random.Next(byte.MinValue, byte.MaxValue));

                                graphics.SaveState()
                                .Translate(prms.Area.Left, prms.Area.Top)
                                .SetLineColor(color)
                                .SetLineWidth(random.Next(1, 4))
                                .DrawEllipse(prms.Area.Width / 2f, prms.Area.Height / 2f,
                                             random.Next(byte.MinValue, prms.Area.Width / 2),
                                             random.Next(byte.MinValue, prms.Area.Height / 2))
                                //.DrawPath(
                                //    SciterPath
                                //        .Create()
                                //        .MoveTo(prms.area.Width / 2, prms.area.Height / 2)
                                //        .ArcTo(random.Next(byte.MinValue, prms.area.Width), random.Next(byte.MinValue, prms.area.Height), random.Next(0, 360), random.Next(byte.MinValue, byte.MaxValue), random.Next(byte.MinValue, byte.MaxValue), false, true)
                                //        .LineTo(random.Next(byte.MinValue, prms.area.Width / 2), random.Next(byte.MinValue, prms.area.Height / 2))
                                //        .BezierCurveTo(random.Next(byte.MinValue, byte.MaxValue), random.Next(byte.MinValue, byte.MaxValue), random.Next(byte.MinValue, byte.MaxValue), random.Next(byte.MinValue, byte.MaxValue), random.Next(byte.MinValue, prms.area.Width / 2), random.Next(byte.MinValue, prms.area.Height / 2))
                                //        .QuadraticCurveTo(random.Next(byte.MinValue, byte.MaxValue), random.Next(byte.MinValue, byte.MaxValue), random.Next(byte.MinValue, prms.area.Width / 2), random.Next(byte.MinValue, prms.area.Height / 2))
                                //    , DrawPathMode.StrokeOnly)
                                //.DrawEllipse(prms.area.Width / 2, prms.area.Height / 2, 50f, 50f)
                                //.SetLineColor(SciterColor.Transparent)
                                //.SetFillColor(color)
                                //.DrawPath(
                                //    SciterPath
                                //        .Create()
                                //        .MoveTo(prms.area.Width / 2, prms.area.Height / 2 - 50)
                                //        .ArcTo(prms.area.Width / 2, prms.area.Height / 2, 90, 25,  25, false, true)
                                //        .ArcTo(prms.area.Width / 2, prms.area.Height / 2 + 50, 90, 25,  25, false, false)
                                //        .ArcTo(prms.area.Width / 2, prms.area.Height / 2 - 50, 90, 50,  50, false, false)
                                //    , DrawPathMode.FillOnly)
//
                                //.DrawEllipse(prms.area.Width / 2, prms.area.Height / 2 - 25, 6f, 6f)
                                //.DrawEllipse(prms.area.Width / 2, prms.area.Height / 2 + 25, 6f, 6f)
                                .RestoreState();
                            }
                        }

                        break;

                    case DrawEvent.Background:
                    case DrawEvent.Foreground:
                    case DrawEvent.Outline:
                    default:
                        return false;
                    }

                    element?.Window?.Close();

                    return true;
                }));
            });

            _ = new TestableSciterHost(_sciterWindow)
                .SetBehaviorResolver(_mockBehaviorResolver.Object);

            _sciterWindow.Show();

            var backgroundColor = random.Next(byte.MinValue, 80);

            _sciterWindow.RootElement.AppendElement("body", elm => elm)
            .SetStyleValue("background", $"rgb({backgroundColor}, {backgroundColor}, {backgroundColor})")
            .SetStyleValue("behavior", behaviorName);

            SciterPlatform.RunMessageLoop();

            //Assert.NotNull(_sciterGraphics);
        }
Пример #17
0
        public void SciterColor_ToInt64(byte r, byte g, byte b, byte a, ulong expected)
        {
            var actual = SciterColor.Create(r, g, b, a);

            Assert.AreEqual(expected, actual.ToUInt64());
        }
Пример #18
0
        public void SciterColor_ToDecimal(byte r, byte g, byte b, byte a, decimal expected)
        {
            var actual = SciterColor.Create(r, g, b, a);

            Assert.AreEqual(expected, actual.ToDecimal());
        }
Пример #19
0
        public void rgba_to_SciterColor(int r, int g, int b, int a, uint exp)
        {
            var actual = SciterColor.Create(Color.FromArgb(a, r, g, b));

            Assert.AreEqual(exp, actual.Value);
        }