From: Vincent Vanwaelscappel Date: Tue, 10 Oct 2023 16:43:24 +0000 (+0200) Subject: wip #6381 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=49b293a9b06f19508be93a3a7a514d56087294ca;p=fluidbook-toolbox.git wip #6381 @1 --- diff --git a/app/Elearning/QuizCompiler/Animations.php b/app/Elearning/QuizCompiler/Animations.php index 8b388e064..a0edd1b13 100644 --- a/app/Elearning/QuizCompiler/Animations.php +++ b/app/Elearning/QuizCompiler/Animations.php @@ -15,7 +15,9 @@ trait Animations const NOK_COLOR = '#D0167C'; const CONFETTI_COLOR = '#E4FF19'; - protected $animations=[]; + const TEXT_COLOR = "#ffffff"; + + protected $animations = []; /** * @param $vdir VirtualDirectory @@ -26,16 +28,18 @@ trait Animations $colors = [ self::OK_COLOR => $this->theme->okColor, self::CONFETTI_COLOR => $this->theme->okColor, - self::NOK_COLOR => $this->theme->nokColor + self::NOK_COLOR => $this->theme->nokColor, + self::TEXT_COLOR => $this->theme->getTextsColor(), ]; $animationReplace = []; $animationPregReplace = []; // Replace colors foreach ($colors as $from => $to) { - $f = (new Color($from))->toLottie(5,true); + $f = (new Color($from))->toLottie(5, true); $t = (new Color($to))->toLottie(); - $animationPregReplace['/\[' . $f[0] . ',' . $f[1] . ',' . $f[2] . '/'] = '[' . $t[0] . ',' . $t[1] . ',' . $t[2]; + $animationPregReplace['/"c":{"a":0,"k":\[' . $f[0] . ',' . $f[1] . ',' . $f[2] . '/'] = '"c":{"a":0,"k":[' . $t[0] . ',' . $t[1] . ',' . $t[2]; + $animationPregReplace['/"fc":\[' . $f[0] . ',' . $f[1] . ',' . $f[2] . '/'] = '"fc":[' . $t[0] . ',' . $t[1] . ',' . $t[2]; } // Replace font $font = FluidbookFont::getAvailableFonts()[$this->theme->font ?: 'SourceSans']; diff --git a/app/Models/QuizTheme.php b/app/Models/QuizTheme.php index 3cc2a3098..bdee95dd1 100644 --- a/app/Models/QuizTheme.php +++ b/app/Models/QuizTheme.php @@ -19,6 +19,7 @@ use Cubist\Backpack\Magic\Fields\SelectFromArray; use Cubist\Util\CommandLine\Imagemagick; use Cubist\Util\Files\Files; use Cubist\Util\Graphics\Resizer; +use function PHPUnit\Framework\matches; class QuizTheme extends ToolboxModel { @@ -60,7 +61,7 @@ class QuizTheme extends ToolboxModel protected function _font() { $this->addField('sectionTexts', FormSection::class, __('Textes')); - $this->addField('textColor', SelectFromArray::class, __('Couleur des textes'), ['default' => 'auto', 'options' => ['auto' => __('Automatique'), '#ffffff' => __('Blanc'), '#000000' => __('Noir')]]); + $this->addField('textColor', SelectFromArray::class, __('Couleur des textes'), ['default' => 'auto', 'options' => ['auto' => __('Automatique'), 'light' => __('Blanc'), 'dark' => __('Noir')]]); $this->addField('font', FluidbookFont::class, __('Police de caractères'), ['default' => 'SourceSans', 'databaseDefault' => 'SourceSans']); } @@ -93,7 +94,6 @@ class QuizTheme extends ToolboxModel $this->addField('backgroundImageMobile', FluidbookThemeImage::class, __('Image ou animation'), ['hint' => __('Taille recommandée : :size', ['size' => '390 x 844px']), 'when' => ['backgroundCustom' => 1]]); } - protected function _intro() { $this->addField('sectionIntro', FormSection::class, __('Écran d\'introduction')); @@ -146,20 +146,28 @@ class QuizTheme extends ToolboxModel public function getTextsColor() { + $darkColor = '#383838'; + $lightColor = '#ffffff'; + if ($this->textColor == 'auto' || !$this->textColor) { // If auto mode, check between black and white which have the biggest distance (i.e. most contrast) with neutralColor $neutral = new \Cubist\Util\Graphics\Color($this->neutralColor); - $black = new \Cubist\Util\Graphics\Color('#000000'); - $white = new \Cubist\Util\Graphics\Color('#ffffff'); + $black = new \Cubist\Util\Graphics\Color($darkColor); + $white = new \Cubist\Util\Graphics\Color($lightColor); $distBlack = $neutral->distance($black); $distWhite = $neutral->distance($white); if ($distWhite > $distBlack) { - return '#ffffff'; + return $lightColor; } else { - return '#000000'; + return $darkColor; } } - return $this->textColor; + return match ($this->textColor) { + 'dark' => $darkColor, + '#000000' => $darkColor, + '#ffffff' => $lightColor, + 'light' => $lightColor, + }; } /**