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)); }
public void SciterColor_are_equal() { var one = SciterColor.Transparent; var two = SciterColor.Create(0, 0, 0, 0); Assert.IsTrue(one.Equals(two)); }
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); }
protected override bool OnDraw(SciterElement se, DrawArgs args) { if (args.DrawEvent == DrawEvent.Content) { using (var graphics = SciterGraphics.Create(args.Handle)) { graphics.SaveState() .Translate(args.Area.Left, args.Area.Top) .SetLineColor(SciterColor.Create(0, 255, 255, .75f)) .SetFillColor(SciterColor.Create(127, 78, 194, .75f)) .SetLineWidth(4) .DrawPolygon( PolygonPoint.Create(51.0f, 58.0f), PolygonPoint.Create(70.0f, 28.0f), PolygonPoint.Create(48.0f, 1.0f), PolygonPoint.Create(15.0f, 14.0f), PolygonPoint.Create(17.0f, 49.0f) ) .DrawEllipse(200, 50, 50, 50) .RestoreState(); } return(true); } return(false); }
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)); } } }
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); }
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()); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
private void DrawCirclesClock( SciterGraphics graphics, SciterRectangle area, float scale, DateTime timeInfo) { var markColor = SciterColor.Parse("#969696"); var hourColor = SciterColor.Parse("#969696"); var minuteColor = SciterColor.Parse("#969696"); var secondColor = SciterColor.Parse("#64C439"); 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); int sec = timeInfo.Second; int min = timeInfo.Minute; int hr = timeInfo.Hour; hr = hr >= 12 ? hr - 12 : hr; // Background graphics .SaveState() .Translate(0, 0) .SetLineColor(SciterColor.Transparent) .SetFillGradientLinear(0f, 75f, 150f, 75f, SciterColorStop.Create(0f, SciterColor.Parse("#242424")), SciterColorStop.Create(1f, SciterColor.Parse("#545454"))) .DrawEllipse(0, 0, 150, 150) .SetFillColor(SciterColor.Transparent) .SetLineColor(minuteColor) .DrawEllipse(0, 0, 150, 150) .RestoreState(); graphics .SaveState() .Translate(-(area.Height / 3.0f), 0) .SetLineWidth(2f) .SetLineColor(SciterColor.Black) .SetFillColor(SciterColor.Parse("#222222")) .DrawEllipse(0, 0, 50, 50) .SetLineColor(markColor) .Using(@ref => { for (var i = 0; i < 12; ++i) { @ref .Rotate(Pi / 6, 0, 0) .DrawLine(34, 0, 44f, 0); } }) .RestoreState(); graphics .SaveState() .Translate(-(area.Height / 3.0f), 0) .SetLineColor(secondColor) .Using(@ref => { @ref .SetLineWidth(2f) .SetLineColor(markColor); for (var i = 0; i < 60; ++i) { if (i % 5 != 0) { @ref.DrawLine(40f, 0, 44f, 0); } @ref.Rotate(Pi / 30f); } }) .RestoreState(); graphics .SaveState() .Translate(-(area.Height / 3.0f), 0) .Rotate(sec * Pi / 30) .SetLineColor(secondColor) .SetFillColor(secondColor) .SetLineWidth(2f) .DrawLine(0, 0, 44, 0) .DrawEllipse(0, 0, 3, 3) .RestoreState(); // Hour marks graphics .SaveState() .SetLineColor(markColor) .Using(@ref => { for (var i = 0; i < 12; ++i) { @ref.Rotate(Pi / 6, 0, 0); if (new [] { 2, 5, 8, 11 }.Contains(i)) { @ref .SetLineWidth(8f) .DrawLine(125f, 0, 142f, 0); } else { @ref .SetLineWidth(2f) .DrawLine(125f, 0, 145f, 0); } } }) .RestoreState(); // Minute marks graphics .SaveState() .SetLineWidth(2f) .SetLineColor(markColor) .Using(@ref => { for (var i = 0; i < 60; ++i) { if (i % 5 != 0) { @ref.DrawLine(138f, 0, 144f, 0); } @ref.Rotate(Pi / 30f); } }) .SetLineColor(minuteColor) .DrawEllipse(0, 0, 150, 150) .RestoreState(); // draw Hours graphics.SaveState() .Rotate(hr * (Pi / 6) + (Pi / 360) * min + (Pi / 21600) * sec) .SetLineWidth(1f) .SetFillGradientLinear(50f, -3f, 50f, 3f, SciterColorStop.Create(0f, SciterColor.Parse("#c4c4c4")), SciterColorStop.Create(1f, SciterColor.Parse("#B2B2B2"))) .DrawPolygon(() => new List <PolygonPoint>() { PolygonPoint.Create(0f, -3f), PolygonPoint.Create(90f, -3f), PolygonPoint.Create(100f, 0f), PolygonPoint.Create(90f, 3f), PolygonPoint.Create(0f, 3f), }) //.SetLineWidth(0f) //.DrawEllipse(0, 0, 10, 10) .RestoreState(); // draw Minutes graphics .SaveState() .Rotate((Pi / 30) * min + (Pi / 1800) * sec) //.SetLineColor(SciterColor.Transparent) //.SetLineWidth(0f) //.SetFillColor(SciterColor.Create(0, 0, 0, .5f)) //.DrawEllipse(0, 0, 10, 10) .SetLineWidth(1f) .SetLineColor(minuteColor) .SetFillColor(minuteColor) .SetFillGradientLinear(65, -3f, 65f, 3f, SciterColorStop.Create(0f, SciterColor.Parse("#c4c4c4")), SciterColorStop.Create(1f, SciterColor.Parse("#B2B2B2"))) .DrawPolygon(() => new List <PolygonPoint>() { PolygonPoint.Create(0, -3), PolygonPoint.Create(120, -3), PolygonPoint.Create(130, 0), PolygonPoint.Create(120, 3), PolygonPoint.Create(0, 3), }) .DrawEllipse(0, 0, 8, 8) .SetLineColor(SciterColor.Parse("#686868")) .SetFillColor(SciterColor.Parse("#2E2E2E")) .SetLineWidth(2f) .DrawEllipse(0, 0, 4, 4) //.SetLineWidth(1f) .RestoreState(); // Outer ring graphics .SaveState() .SetLineColor(minuteColor) .DrawEllipse(0, 0, 150, 150) .RestoreState(); graphics.RestoreState(); }
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()); }
public static bool TryClear(this SciterImage sciterImage, SciterColor color) { return(sciterImage?.TryClearInternal(color) == true); }
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()); }
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()); }
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(); }
public static void Clear(this SciterImage sciterImage, SciterColor color) { sciterImage?.ClearInternal(color); }
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); }