|
| 1 | +/* |
| 2 | + * Copyright 2023 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include "cpp/dynamiccolor/dynamic_scheme.h" |
| 18 | + |
| 19 | +#include "cpp/cam/hct.h" |
| 20 | +#include "cpp/dynamiccolor/material_dynamic_colors.h" |
| 21 | +#include "cpp/dynamiccolor/variant.h" |
| 22 | +#include "cpp/palettes/tones.h" |
| 23 | +#include "cpp/utils/utils.h" |
| 24 | + |
| 25 | +namespace material_color_utilities { |
| 26 | + |
| 27 | +DynamicScheme::DynamicScheme(Argb source_color_argb, Variant variant, |
| 28 | + double contrast_level, bool is_dark, |
| 29 | + TonalPalette primary_palette, |
| 30 | + TonalPalette secondary_palette, |
| 31 | + TonalPalette tertiary_palette, |
| 32 | + TonalPalette neutral_palette, |
| 33 | + TonalPalette neutral_variant_palette) |
| 34 | + : source_color_hct(Hct(source_color_argb)), |
| 35 | + variant(variant), |
| 36 | + is_dark(is_dark), |
| 37 | + contrast_level(contrast_level), |
| 38 | + primary_palette(primary_palette), |
| 39 | + secondary_palette(secondary_palette), |
| 40 | + tertiary_palette(tertiary_palette), |
| 41 | + neutral_palette(neutral_palette), |
| 42 | + neutral_variant_palette(neutral_variant_palette), |
| 43 | + error_palette(TonalPalette(25.0, 84.0)) {} |
| 44 | + |
| 45 | +double DynamicScheme::GetRotatedHue(Hct source_color, std::vector<double> hues, |
| 46 | + std::vector<double> rotations) { |
| 47 | + double source_hue = source_color.get_hue(); |
| 48 | + |
| 49 | + if (rotations.size() == 1) { |
| 50 | + return SanitizeDegreesDouble(source_color.get_hue() + rotations[0]); |
| 51 | + } |
| 52 | + int size = hues.size(); |
| 53 | + for (int i = 0; i <= (size - 2); i++) { |
| 54 | + double this_hue = hues[i]; |
| 55 | + double next_hue = hues[i + 1]; |
| 56 | + if (this_hue < source_hue && source_hue < next_hue) { |
| 57 | + return SanitizeDegreesDouble(source_hue + rotations[i]); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + return source_hue; |
| 62 | +} |
| 63 | + |
| 64 | +Argb DynamicScheme::SourceColorArgb() const { return source_color_hct.ToInt(); } |
| 65 | + |
| 66 | +Argb DynamicScheme::GetPrimaryPaletteKeyColor() const { |
| 67 | + return MaterialDynamicColors::PrimaryPaletteKeyColor().GetArgb(*this); |
| 68 | +} |
| 69 | + |
| 70 | +Argb DynamicScheme::GetSecondaryPaletteKeyColor() const { |
| 71 | + return MaterialDynamicColors::SecondaryPaletteKeyColor().GetArgb(*this); |
| 72 | +} |
| 73 | + |
| 74 | +Argb DynamicScheme::GetTertiaryPaletteKeyColor() const { |
| 75 | + return MaterialDynamicColors::TertiaryPaletteKeyColor().GetArgb(*this); |
| 76 | +} |
| 77 | + |
| 78 | +Argb DynamicScheme::GetNeutralPaletteKeyColor() const { |
| 79 | + return MaterialDynamicColors::NeutralPaletteKeyColor().GetArgb(*this); |
| 80 | +} |
| 81 | + |
| 82 | +Argb DynamicScheme::GetNeutralVariantPaletteKeyColor() const { |
| 83 | + return MaterialDynamicColors::NeutralVariantPaletteKeyColor().GetArgb(*this); |
| 84 | +} |
| 85 | + |
| 86 | +Argb DynamicScheme::GetBackground() const { |
| 87 | + return MaterialDynamicColors::Background().GetArgb(*this); |
| 88 | +} |
| 89 | + |
| 90 | +Argb DynamicScheme::GetOnBackground() const { |
| 91 | + return MaterialDynamicColors::OnBackground().GetArgb(*this); |
| 92 | +} |
| 93 | + |
| 94 | +Argb DynamicScheme::GetSurface() const { |
| 95 | + return MaterialDynamicColors::Surface().GetArgb(*this); |
| 96 | +} |
| 97 | + |
| 98 | +Argb DynamicScheme::GetSurfaceDim() const { |
| 99 | + return MaterialDynamicColors::SurfaceDim().GetArgb(*this); |
| 100 | +} |
| 101 | + |
| 102 | +Argb DynamicScheme::GetSurfaceBright() const { |
| 103 | + return MaterialDynamicColors::SurfaceBright().GetArgb(*this); |
| 104 | +} |
| 105 | + |
| 106 | +Argb DynamicScheme::GetSurfaceContainerLowest() const { |
| 107 | + return MaterialDynamicColors::SurfaceContainerLowest().GetArgb(*this); |
| 108 | +} |
| 109 | + |
| 110 | +Argb DynamicScheme::GetSurfaceContainerLow() const { |
| 111 | + return MaterialDynamicColors::SurfaceContainerLow().GetArgb(*this); |
| 112 | +} |
| 113 | + |
| 114 | +Argb DynamicScheme::GetSurfaceContainer() const { |
| 115 | + return MaterialDynamicColors::SurfaceContainer().GetArgb(*this); |
| 116 | +} |
| 117 | + |
| 118 | +Argb DynamicScheme::GetSurfaceContainerHigh() const { |
| 119 | + return MaterialDynamicColors::SurfaceContainerHigh().GetArgb(*this); |
| 120 | +} |
| 121 | + |
| 122 | +Argb DynamicScheme::GetSurfaceContainerHighest() const { |
| 123 | + return MaterialDynamicColors::SurfaceContainerHighest().GetArgb(*this); |
| 124 | +} |
| 125 | + |
| 126 | +Argb DynamicScheme::GetOnSurface() const { |
| 127 | + return MaterialDynamicColors::OnSurface().GetArgb(*this); |
| 128 | +} |
| 129 | + |
| 130 | +Argb DynamicScheme::GetSurfaceVariant() const { |
| 131 | + return MaterialDynamicColors::SurfaceVariant().GetArgb(*this); |
| 132 | +} |
| 133 | + |
| 134 | +Argb DynamicScheme::GetOnSurfaceVariant() const { |
| 135 | + return MaterialDynamicColors::OnSurfaceVariant().GetArgb(*this); |
| 136 | +} |
| 137 | + |
| 138 | +Argb DynamicScheme::GetInverseSurface() const { |
| 139 | + return MaterialDynamicColors::InverseSurface().GetArgb(*this); |
| 140 | +} |
| 141 | + |
| 142 | +Argb DynamicScheme::GetInverseOnSurface() const { |
| 143 | + return MaterialDynamicColors::InverseOnSurface().GetArgb(*this); |
| 144 | +} |
| 145 | + |
| 146 | +Argb DynamicScheme::GetOutline() const { |
| 147 | + return MaterialDynamicColors::Outline().GetArgb(*this); |
| 148 | +} |
| 149 | + |
| 150 | +Argb DynamicScheme::GetOutlineVariant() const { |
| 151 | + return MaterialDynamicColors::OutlineVariant().GetArgb(*this); |
| 152 | +} |
| 153 | + |
| 154 | +Argb DynamicScheme::GetShadow() const { |
| 155 | + return MaterialDynamicColors::Shadow().GetArgb(*this); |
| 156 | +} |
| 157 | + |
| 158 | +Argb DynamicScheme::GetScrim() const { |
| 159 | + return MaterialDynamicColors::Scrim().GetArgb(*this); |
| 160 | +} |
| 161 | + |
| 162 | +Argb DynamicScheme::GetSurfaceTint() const { |
| 163 | + return MaterialDynamicColors::SurfaceTint().GetArgb(*this); |
| 164 | +} |
| 165 | + |
| 166 | +Argb DynamicScheme::GetPrimary() const { |
| 167 | + return MaterialDynamicColors::Primary().GetArgb(*this); |
| 168 | +} |
| 169 | + |
| 170 | +Argb DynamicScheme::GetOnPrimary() const { |
| 171 | + return MaterialDynamicColors::OnPrimary().GetArgb(*this); |
| 172 | +} |
| 173 | + |
| 174 | +Argb DynamicScheme::GetPrimaryContainer() const { |
| 175 | + return MaterialDynamicColors::PrimaryContainer().GetArgb(*this); |
| 176 | +} |
| 177 | + |
| 178 | +Argb DynamicScheme::GetOnPrimaryContainer() const { |
| 179 | + return MaterialDynamicColors::OnPrimaryContainer().GetArgb(*this); |
| 180 | +} |
| 181 | + |
| 182 | +Argb DynamicScheme::GetInversePrimary() const { |
| 183 | + return MaterialDynamicColors::InversePrimary().GetArgb(*this); |
| 184 | +} |
| 185 | + |
| 186 | +Argb DynamicScheme::GetSecondary() const { |
| 187 | + return MaterialDynamicColors::Secondary().GetArgb(*this); |
| 188 | +} |
| 189 | + |
| 190 | +Argb DynamicScheme::GetOnSecondary() const { |
| 191 | + return MaterialDynamicColors::OnSecondary().GetArgb(*this); |
| 192 | +} |
| 193 | + |
| 194 | +Argb DynamicScheme::GetSecondaryContainer() const { |
| 195 | + return MaterialDynamicColors::SecondaryContainer().GetArgb(*this); |
| 196 | +} |
| 197 | + |
| 198 | +Argb DynamicScheme::GetOnSecondaryContainer() const { |
| 199 | + return MaterialDynamicColors::OnSecondaryContainer().GetArgb(*this); |
| 200 | +} |
| 201 | + |
| 202 | +Argb DynamicScheme::GetTertiary() const { |
| 203 | + return MaterialDynamicColors::Tertiary().GetArgb(*this); |
| 204 | +} |
| 205 | + |
| 206 | +Argb DynamicScheme::GetOnTertiary() const { |
| 207 | + return MaterialDynamicColors::OnTertiary().GetArgb(*this); |
| 208 | +} |
| 209 | + |
| 210 | +Argb DynamicScheme::GetTertiaryContainer() const { |
| 211 | + return MaterialDynamicColors::TertiaryContainer().GetArgb(*this); |
| 212 | +} |
| 213 | + |
| 214 | +Argb DynamicScheme::GetOnTertiaryContainer() const { |
| 215 | + return MaterialDynamicColors::OnTertiaryContainer().GetArgb(*this); |
| 216 | +} |
| 217 | + |
| 218 | +Argb DynamicScheme::GetError() const { |
| 219 | + return MaterialDynamicColors::Error().GetArgb(*this); |
| 220 | +} |
| 221 | + |
| 222 | +Argb DynamicScheme::GetOnError() const { |
| 223 | + return MaterialDynamicColors::OnError().GetArgb(*this); |
| 224 | +} |
| 225 | + |
| 226 | +Argb DynamicScheme::GetErrorContainer() const { |
| 227 | + return MaterialDynamicColors::ErrorContainer().GetArgb(*this); |
| 228 | +} |
| 229 | + |
| 230 | +Argb DynamicScheme::GetOnErrorContainer() const { |
| 231 | + return MaterialDynamicColors::OnErrorContainer().GetArgb(*this); |
| 232 | +} |
| 233 | + |
| 234 | +Argb DynamicScheme::GetPrimaryFixed() const { |
| 235 | + return MaterialDynamicColors::PrimaryFixed().GetArgb(*this); |
| 236 | +} |
| 237 | + |
| 238 | +Argb DynamicScheme::GetPrimaryFixedDim() const { |
| 239 | + return MaterialDynamicColors::PrimaryFixedDim().GetArgb(*this); |
| 240 | +} |
| 241 | + |
| 242 | +Argb DynamicScheme::GetOnPrimaryFixed() const { |
| 243 | + return MaterialDynamicColors::OnPrimaryFixed().GetArgb(*this); |
| 244 | +} |
| 245 | + |
| 246 | +Argb DynamicScheme::GetOnPrimaryFixedVariant() const { |
| 247 | + return MaterialDynamicColors::OnPrimaryFixedVariant().GetArgb(*this); |
| 248 | +} |
| 249 | + |
| 250 | +Argb DynamicScheme::GetSecondaryFixed() const { |
| 251 | + return MaterialDynamicColors::SecondaryFixed().GetArgb(*this); |
| 252 | +} |
| 253 | + |
| 254 | +Argb DynamicScheme::GetSecondaryFixedDim() const { |
| 255 | + return MaterialDynamicColors::SecondaryFixedDim().GetArgb(*this); |
| 256 | +} |
| 257 | + |
| 258 | +Argb DynamicScheme::GetOnSecondaryFixed() const { |
| 259 | + return MaterialDynamicColors::OnSecondaryFixed().GetArgb(*this); |
| 260 | +} |
| 261 | + |
| 262 | +Argb DynamicScheme::GetOnSecondaryFixedVariant() const { |
| 263 | + return MaterialDynamicColors::OnSecondaryFixedVariant().GetArgb(*this); |
| 264 | +} |
| 265 | + |
| 266 | +Argb DynamicScheme::GetTertiaryFixed() const { |
| 267 | + return MaterialDynamicColors::TertiaryFixed().GetArgb(*this); |
| 268 | +} |
| 269 | + |
| 270 | +Argb DynamicScheme::GetTertiaryFixedDim() const { |
| 271 | + return MaterialDynamicColors::TertiaryFixedDim().GetArgb(*this); |
| 272 | +} |
| 273 | + |
| 274 | +Argb DynamicScheme::GetOnTertiaryFixed() const { |
| 275 | + return MaterialDynamicColors::OnTertiaryFixed().GetArgb(*this); |
| 276 | +} |
| 277 | + |
| 278 | +Argb DynamicScheme::GetOnTertiaryFixedVariant() const { |
| 279 | + return MaterialDynamicColors::OnTertiaryFixedVariant().GetArgb(*this); |
| 280 | +} |
| 281 | + |
| 282 | +} // namespace material_color_utilities |
0 commit comments