/src/serenity/Userland/Libraries/LibGfx/Gradients.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2023, MacDue <macdue@dueutil.tech> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/Math/Constants.h> |
10 | | #include <AK/Math/Fabs.h> |
11 | | #include <AK/Math/Radians.h> |
12 | | #include <AK/Math/Trigonometry.h> |
13 | | #include <LibGfx/Color.h> |
14 | | #include <LibGfx/Size.h> |
15 | | |
16 | | namespace Gfx { |
17 | | |
18 | | struct ColorStop { |
19 | | Color color; |
20 | | float position = AK::NaN<float>; |
21 | | Optional<float> transition_hint = {}; |
22 | | }; |
23 | | |
24 | | class GradientLine; |
25 | | |
26 | | inline float normalized_gradient_angle_radians(float gradient_angle) |
27 | 0 | { |
28 | | // Adjust angle so 0 degrees is bottom |
29 | 0 | float real_angle = 90 - gradient_angle; |
30 | 0 | return AK::to_radians(real_angle); |
31 | 0 | } |
32 | | |
33 | | template<typename T> |
34 | | inline float calculate_gradient_length(Size<T> gradient_size, float sin_angle, float cos_angle) |
35 | 0 | { |
36 | 0 | return AK::fabs(static_cast<float>(gradient_size.height()) * sin_angle) + AK::fabs(static_cast<float>(gradient_size.width()) * cos_angle); |
37 | 0 | } Unexecuted instantiation: float Gfx::calculate_gradient_length<int>(Gfx::Size<int>, float, float) Unexecuted instantiation: float Gfx::calculate_gradient_length<float>(Gfx::Size<float>, float, float) |
38 | | |
39 | | template<typename T> |
40 | | inline float calculate_gradient_length(Size<T> gradient_size, float gradient_angle) |
41 | 0 | { |
42 | 0 | float angle = normalized_gradient_angle_radians(gradient_angle); |
43 | 0 | float sin_angle, cos_angle; |
44 | 0 | AK::sincos(angle, sin_angle, cos_angle); |
45 | 0 | return calculate_gradient_length(gradient_size, sin_angle, cos_angle); |
46 | 0 | } |
47 | | |
48 | | } |