15 #include "third_party/imgui/imgui.h"
28 canvas.Scale(aiks_test->GetContentScale());
30 canvas.Translate({100.0f, 0, 0});
32 std::vector<Color> colors = {Color{0.9568, 0.2627, 0.2118, 1.0},
33 Color{0.1294, 0.5882, 0.9529, 0.0}};
34 std::vector<Scalar> stops = {0.0, 1.0};
37 {0, 0}, {200, 200}, std::move(colors), std::move(stops), tile_mode, {});
39 paint.color = Color(1.0, 1.0, 1.0, 1.0);
41 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
60 canvas.
Scale(GetContentScale());
64 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
65 Color{0.1294, 0.5882, 0.9529, 0.0}};
66 std::vector<Scalar> stops = {0.0, 1.0};
69 {0, 0}, {200, 200}, std::move(colors), std::move(stops),
90 std::vector<Color> colors = {
Color{0.8, 0.8, 0.8, 1.0},
91 Color{0.2, 0.2, 0.2, 1.0}};
92 std::vector<Scalar> stops = {0.0, 1.0};
95 {0, 0}, {800, 500}, std::move(colors), std::move(stops),
97 paint.
dither = use_dithering;
111 bool use_dithering) {
117 std::vector<Color> colors = {
Color{1.0, 1.0, 1.0, 1.0},
118 Color{0.0, 0.0, 0.0, 1.0}};
119 std::vector<Scalar> stops = {0.0, 1.0};
122 {600, 600}, 600, std::move(colors), std::move(stops),
124 paint.
dither = use_dithering;
138 bool use_dithering) {
145 std::vector<Color> colors = {
Color{1.0, 1.0, 1.0, 1.0},
146 Color{0.0, 0.0, 0.0, 1.0}};
147 std::vector<Scalar> stops = {0.0, 1.0};
152 paint.
dither = use_dithering;
167 bool use_dithering) {
174 std::vector<Color> colors = {
Color{1.0, 1.0, 1.0, 1.0},
175 Color{0.0, 0.0, 0.0, 1.0}};
176 std::vector<Scalar> stops = {0.0, 1.0};
179 {100, 100}, 100, std::move(colors), std::move(stops), {0, 1}, 0,
181 paint.
dither = use_dithering;
196 void CanRenderLinearGradientWithOverlappingStops(
AiksTest* aiks_test,
202 std::vector<Color> colors = {
203 Color{0.9568, 0.2627, 0.2118, 1.0}, Color{0.9568, 0.2627, 0.2118, 1.0},
204 Color{0.1294, 0.5882, 0.9529, 1.0}, Color{0.1294, 0.5882, 0.9529, 1.0}};
205 std::vector<Scalar> stops = {0.0, 0.5, 0.5, 1.0};
208 {0, 0}, {500, 500}, std::move(colors), std::move(stops), tile_mode, {});
210 paint.
color = Color(1.0, 1.0, 1.0, 1.0);
222 void CanRenderLinearGradientManyColors(
AiksTest* aiks_test,
225 canvas.
Scale(aiks_test->GetContentScale());
229 std::vector<Color> colors = {
230 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
231 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
232 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
233 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
234 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
235 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
236 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
237 std::vector<Scalar> stops = {
248 {0, 0}, {200, 200}, std::move(colors), std::move(stops), tile_mode, {});
250 paint.
color = Color(1.0, 1.0, 1.0, 1.0);
271 void CanRenderLinearGradientWayManyColors(
AiksTest* aiks_test,
276 auto color = Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0};
277 std::vector<Color> colors;
278 std::vector<Scalar> stops;
279 auto current_stop = 0.0;
280 for (
int i = 0; i < 2000; i++) {
281 colors.push_back(color);
282 stops.push_back(current_stop);
283 current_stop += 1 / 2000.0;
285 stops[2000 - 1] = 1.0;
288 {0, 0}, {200, 200}, std::move(colors), std::move(stops), tile_mode, {});
301 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
302 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
307 static int selected_tile_mode = 0;
315 ImGuiWindowFlags_AlwaysAutoResize)) {
316 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
317 sizeof(tile_mode_names) /
sizeof(
char*));
318 std::string label =
"##1";
319 for (
int i = 0; i < 4; i++) {
320 ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
321 &(matrix.
vec[i]), 4, NULL, NULL,
"%.2f", 0);
330 auto tile_mode = tile_modes[selected_tile_mode];
332 std::vector<Color> colors = {
333 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
334 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
335 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
336 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
337 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
338 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
339 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
340 std::vector<Scalar> stops = {
341 0.0, 2.0 / 62.0, 4.0 / 62.0, 8.0 / 62.0, 16.0 / 62.0, 32.0 / 62.0, 1.0,
345 {0, 0}, {200, 200}, std::move(colors), std::move(stops), tile_mode, {});
350 ASSERT_TRUE(OpenPlaygroundHere(callback));
359 {200, 200}, {400, 400},
363 {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0},
365 .mask_blur_descriptor =
379 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
380 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
385 static int selected_tile_mode = 0;
393 ImGuiWindowFlags_AlwaysAutoResize)) {
394 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
395 sizeof(tile_mode_names) /
sizeof(
char*));
396 std::string label =
"##1";
397 for (
int i = 0; i < 4; i++) {
398 ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
399 &(matrix.
vec[i]), 4, NULL, NULL,
"%.2f", 0);
408 auto tile_mode = tile_modes[selected_tile_mode];
410 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
411 Color{0.1294, 0.5882, 0.9529, 1.0}};
412 std::vector<Scalar> stops = {0.0, 1.0};
415 {100, 100}, 100, std::move(colors), std::move(stops), tile_mode, {});
420 ASSERT_TRUE(OpenPlaygroundHere(callback));
424 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
425 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
430 static int selected_tile_mode = 0;
438 ImGuiWindowFlags_AlwaysAutoResize)) {
439 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
440 sizeof(tile_mode_names) /
sizeof(
char*));
441 std::string label =
"##1";
442 for (
int i = 0; i < 4; i++) {
443 ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
444 &(matrix.
vec[i]), 4, NULL, NULL,
"%.2f", 0);
453 auto tile_mode = tile_modes[selected_tile_mode];
455 std::vector<Color> colors = {
456 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
457 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
458 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
459 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
460 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
461 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
462 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
463 std::vector<Scalar> stops = {
474 {100, 100}, 100, std::move(colors), std::move(stops), tile_mode, {});
479 ASSERT_TRUE(OpenPlaygroundHere(callback));
485 canvas.
Scale(aiks_test->GetContentScale());
489 std::vector<Color> colors = {Color{0.9568, 0.2627, 0.2118, 1.0},
490 Color{0.1294, 0.5882, 0.9529, 1.0}};
491 std::vector<Scalar> stops = {0.0, 1.0};
494 {100, 100}, Degrees(45), Degrees(135), std::move(colors),
495 std::move(stops), tile_mode, {});
516 void CanRenderSweepGradientManyColors(
AiksTest* aiks_test,
522 std::vector<Color> colors = {
523 Color{0x1f / 255.0, 0.0, 0x5c / 255.0, 1.0},
524 Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0},
525 Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0},
526 Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0},
527 Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0},
528 Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0},
529 Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}};
530 std::vector<Scalar> stops = {
541 {100, 100}, Degrees(45), Degrees(135), std::move(colors),
542 std::move(stops), tile_mode, {});
572 std::vector<Scalar> stops = {0.0, 1.f / 3.f, 2.f / 3.f, 1.0};
573 std::array<std::tuple<Point, float, Point, float>, 8> array{
574 std::make_tuple(
Point{size / 2.f, size / 2.f}, 0.f,
575 Point{size / 2.f, size / 2.f}, size / 2.f),
576 std::make_tuple(
Point{size / 2.f, size / 2.f}, size / 4.f,
577 Point{size / 2.f, size / 2.f}, size / 2.f),
578 std::make_tuple(
Point{size / 4.f, size / 4.f}, 0.f,
579 Point{size / 2.f, size / 2.f}, size / 2.f),
580 std::make_tuple(
Point{size / 4.f, size / 4.f}, size / 2.f,
581 Point{size / 2.f, size / 2.f}, 0),
582 std::make_tuple(
Point{size / 4.f, size / 4.f}, size / 4.f,
583 Point{size / 2.f, size / 2.f}, size / 2.f),
584 std::make_tuple(
Point{size / 4.f, size / 4.f}, size / 16.f,
585 Point{size / 2.f, size / 2.f}, size / 8.f),
586 std::make_tuple(
Point{size / 4.f, size / 4.f}, size / 8.f,
587 Point{size / 2.f, size / 2.f}, size / 16.f),
588 std::make_tuple(
Point{size / 8.f, size / 8.f}, size / 8.f,
589 Point{size / 2.f, size / 2.f}, size / 8.f),
591 for (
int i = 0; i < 8; i++) {
593 canvas.
Translate({(i % 3) * size, i / 3 * size, 0});
595 std::get<0>(array[i]), std::get<1>(array[i]), colors, stops,
609 std::vector<Scalar> stops = {0.0, 1.f / 3.f, 2.f / 3.f, 1.0};
611 std::array<ColorSource, 3> color_sources = {
625 for (
int i = 0; i < 3; i++) {
635 #define APPLY_COLOR_FILTER_GRADIENT_TEST(name) \
636 TEST_P(AiksTest, name##GradientApplyColorFilter) { \
637 auto contents = name##GradientContents(); \
638 contents.SetColors({Color::CornflowerBlue().WithAlpha(0.75)}); \
639 auto result = contents.ApplyColorFilter([](const Color& color) { \
640 return color.Blend(Color::LimeGreen().WithAlpha(0.75), \
641 BlendMode::kScreen); \
643 ASSERT_TRUE(result); \
645 std::vector<Color> expected = {Color(0.433247, 0.879523, 0.825324, 0.75)}; \
646 ASSERT_COLORS_NEAR(contents.GetColors(), expected); \
656 auto callback = [&](
AiksContext& renderer) -> std::optional<Picture> {
657 static float scale = 3;
658 static bool add_circle_clip =
true;
659 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
663 static int selected_tile_mode = 0;
664 static float alpha = 1;
667 ImGuiWindowFlags_AlwaysAutoResize)) {
668 ImGui::SliderFloat(
"Scale", &
scale, 0, 6);
669 ImGui::Checkbox(
"Circle clip", &add_circle_clip);
670 ImGui::SliderFloat(
"Alpha", &alpha, 0, 1);
671 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
672 sizeof(tile_mode_names) /
sizeof(
char*));
677 canvas.
Scale(GetContentScale());
685 auto tile_mode = tile_modes[selected_tile_mode];
687 std::vector<Color> colors = {
Color{0.9568, 0.2627, 0.2118, 1.0},
688 Color{0.1294, 0.5882, 0.9529, 1.0}};
689 std::vector<Scalar> stops = {0.0, 1.0};
692 {0, 0}, {50, 50}, std::move(colors), std::move(stops), tile_mode, {});
696 .QuadraticCurveTo({60, 20}, {60, 60})
699 .QuadraticCurveTo({60, 60}, {20, 60})
704 if (add_circle_clip) {
709 auto [handle_a, handle_b] =
713 Point point_a = screen_to_canvas * handle_a * GetContentScale();
714 Point point_b = screen_to_canvas * handle_b * GetContentScale();
716 Point middle = (point_a + point_b) / 2;
734 ASSERT_TRUE(OpenPlaygroundHere(callback));