diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-10-18 14:23:22 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-10-18 14:23:22 +0300 |
commit | a40b81c0f954d5aa98cc425ecbc2991af72d2898 (patch) | |
tree | 932fb91a51825cc1eb0d68020c10e48b340704a0 /src/gmdocument.c | |
parent | 6fbbdb349a94d75859bc4a22d7f08927d8680ca5 (diff) |
Added more document color themes
The dark and light themes are now configurable in Preferences.
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r-- | src/gmdocument.c | 171 |
1 files changed, 111 insertions, 60 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c index 4240b960..389cbfb2 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c | |||
@@ -631,12 +631,20 @@ void reset_GmDocument(iGmDocument *d) { | |||
631 | d->themeSeed = 0; | 631 | d->themeSeed = 0; |
632 | } | 632 | } |
633 | 633 | ||
634 | static float dimLightness_(float hue, float baseOffset) { | ||
635 | const float blueDiff = iWrapf(hue - 245, -180, 180); | ||
636 | float extra = 0.0f; | ||
637 | const float maxDiff = 60; | ||
638 | if (iAbs(blueDiff) < maxDiff) { | ||
639 | extra = 0.2f * (1.0f - iAbs(blueDiff) / maxDiff); | ||
640 | } | ||
641 | return baseOffset + extra; | ||
642 | } | ||
643 | |||
634 | void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { | 644 | void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { |
635 | const iPrefs * prefs = prefs_App(); | 645 | const iPrefs * prefs = prefs_App(); |
636 | enum iGmDocumentTheme theme = | 646 | enum iGmDocumentTheme theme = |
637 | (isDark_ColorTheme(colorTheme_App()) ? prefs->docThemeDark : prefs->docThemeLight); | 647 | (isDark_ColorTheme(colorTheme_App()) ? prefs->docThemeDark : prefs->docThemeLight); |
638 | // const iBool isLightMode = isLight_ColorTheme(colorTheme_App()); | ||
639 | // const iBool isDarkMode = !isLightMode; | ||
640 | static const iChar siteIcons[] = { | 648 | static const iChar siteIcons[] = { |
641 | 0x203b, 0x2042, 0x205c, 0x2182, 0x25ed, 0x2600, 0x2601, 0x2604, 0x2605, 0x2606, | 649 | 0x203b, 0x2042, 0x205c, 0x2182, 0x25ed, 0x2600, 0x2601, 0x2604, 0x2605, 0x2606, |
642 | 0x265c, 0x265e, 0x2690, 0x2691, 0x2693, 0x2698, 0x2699, 0x26f0, 0x270e, 0x2728, | 650 | 0x265c, 0x265e, 0x2690, 0x2691, 0x2693, 0x2698, 0x2699, 0x26f0, 0x270e, 0x2728, |
@@ -645,20 +653,10 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { | |||
645 | 0x1f306, 0x1f308, 0x1f30a, 0x1f319, 0x1f31f, 0x1f320, 0x1f340, 0x1f4cd, 0x1f4e1, 0x1f531, | 653 | 0x1f306, 0x1f308, 0x1f30a, 0x1f319, 0x1f31f, 0x1f320, 0x1f340, 0x1f4cd, 0x1f4e1, 0x1f531, |
646 | 0x1f533, 0x1f657, 0x1f659, 0x1f665, 0x1f668, 0x1f66b, 0x1f78b, 0x1f796, 0x1f79c, | 654 | 0x1f533, 0x1f657, 0x1f659, 0x1f665, 0x1f668, 0x1f66b, 0x1f78b, 0x1f796, 0x1f79c, |
647 | }; | 655 | }; |
648 | /* Default colors. */ { | 656 | /* Default colors. These are used on "about:" pages and local files, for example. */ { |
649 | if (theme == colorfulDark_GmDocumentTheme) { | 657 | /* Link colors are generally the same in all themes. */ |
650 | const iHSLColor base = { 200, 0, 0.15f, 1.0f }; | 658 | set_Color(tmBadLink_ColorId, get_Color(red_ColorId)); |
651 | setHsl_Color(tmBackground_ColorId, base); | 659 | if (isDark_GmDocumentTheme(theme)) { |
652 | set_Color(tmParagraph_ColorId, get_Color(gray75_ColorId)); | ||
653 | setHsl_Color(tmFirstParagraph_ColorId, addSatLum_HSLColor(base, 0, 0.75f)); | ||
654 | set_Color(tmQuote_ColorId, get_Color(cyan_ColorId)); | ||
655 | set_Color(tmPreformatted_ColorId, get_Color(cyan_ColorId)); | ||
656 | set_Color(tmHeading1_ColorId, get_Color(white_ColorId)); | ||
657 | setHsl_Color(tmHeading2_ColorId, addSatLum_HSLColor(base, 0.5f, 0.5f)); | ||
658 | setHsl_Color(tmHeading3_ColorId, addSatLum_HSLColor(base, 1.0f, 0.4f)); | ||
659 | set_Color(tmBannerBackground_ColorId, get_Color(black_ColorId)); | ||
660 | set_Color(tmBannerTitle_ColorId, get_Color(white_ColorId)); | ||
661 | set_Color(tmBannerIcon_ColorId, get_Color(orange_ColorId)); | ||
662 | set_Color(tmInlineContentMetadata_ColorId, get_Color(cyan_ColorId)); | 660 | set_Color(tmInlineContentMetadata_ColorId, get_Color(cyan_ColorId)); |
663 | set_Color(tmLinkText_ColorId, get_Color(white_ColorId)); | 661 | set_Color(tmLinkText_ColorId, get_Color(white_ColorId)); |
664 | set_Color(tmLinkIcon_ColorId, get_Color(cyan_ColorId)); | 662 | set_Color(tmLinkIcon_ColorId, get_Color(cyan_ColorId)); |
@@ -680,18 +678,6 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { | |||
680 | set_Color(tmGopherLinkLastVisitDate_ColorId, get_Color(blue_ColorId)); | 678 | set_Color(tmGopherLinkLastVisitDate_ColorId, get_Color(blue_ColorId)); |
681 | } | 679 | } |
682 | else { | 680 | else { |
683 | const iHSLColor base = { 40, 0, 1.0f, 1.0f }; | ||
684 | setHsl_Color(tmBackground_ColorId, base); | ||
685 | set_Color(tmParagraph_ColorId, get_Color(gray25_ColorId)); | ||
686 | set_Color(tmFirstParagraph_ColorId, get_Color(black_ColorId)); | ||
687 | set_Color(tmQuote_ColorId, get_Color(brown_ColorId)); | ||
688 | set_Color(tmPreformatted_ColorId, get_Color(brown_ColorId)); | ||
689 | set_Color(tmHeading1_ColorId, get_Color(black_ColorId)); | ||
690 | setHsl_Color(tmHeading2_ColorId, addSatLum_HSLColor(base, 0.15f, -0.7f)); | ||
691 | setHsl_Color(tmHeading3_ColorId, addSatLum_HSLColor(base, 0.3f, -0.6f)); | ||
692 | set_Color(tmBannerBackground_ColorId, get_Color(white_ColorId)); | ||
693 | set_Color(tmBannerTitle_ColorId, get_Color(gray50_ColorId)); | ||
694 | set_Color(tmBannerIcon_ColorId, get_Color(teal_ColorId)); | ||
695 | set_Color(tmInlineContentMetadata_ColorId, get_Color(brown_ColorId)); | 681 | set_Color(tmInlineContentMetadata_ColorId, get_Color(brown_ColorId)); |
696 | set_Color(tmLinkText_ColorId, get_Color(black_ColorId)); | 682 | set_Color(tmLinkText_ColorId, get_Color(black_ColorId)); |
697 | set_Color(tmLinkIcon_ColorId, get_Color(teal_ColorId)); | 683 | set_Color(tmLinkIcon_ColorId, get_Color(teal_ColorId)); |
@@ -712,7 +698,88 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { | |||
712 | set_Color(tmGopherLinkDomain_ColorId, get_Color(magenta_ColorId)); | 698 | set_Color(tmGopherLinkDomain_ColorId, get_Color(magenta_ColorId)); |
713 | set_Color(tmGopherLinkLastVisitDate_ColorId, get_Color(blue_ColorId)); | 699 | set_Color(tmGopherLinkLastVisitDate_ColorId, get_Color(blue_ColorId)); |
714 | } | 700 | } |
715 | set_Color(tmBadLink_ColorId, get_Color(red_ColorId)); | 701 | /* Set the non-link colors. */ |
702 | if (theme == colorfulDark_GmDocumentTheme) { | ||
703 | const iHSLColor base = { 200, 0, 0.15f, 1.0f }; | ||
704 | setHsl_Color(tmBackground_ColorId, base); | ||
705 | set_Color(tmParagraph_ColorId, get_Color(gray75_ColorId)); | ||
706 | setHsl_Color(tmFirstParagraph_ColorId, addSatLum_HSLColor(base, 0, 0.75f)); | ||
707 | set_Color(tmQuote_ColorId, get_Color(cyan_ColorId)); | ||
708 | set_Color(tmPreformatted_ColorId, get_Color(cyan_ColorId)); | ||
709 | set_Color(tmHeading1_ColorId, get_Color(white_ColorId)); | ||
710 | setHsl_Color(tmHeading2_ColorId, addSatLum_HSLColor(base, 0.5f, 0.5f)); | ||
711 | setHsl_Color(tmHeading3_ColorId, addSatLum_HSLColor(base, 1.0f, 0.4f)); | ||
712 | set_Color(tmBannerBackground_ColorId, get_Color(black_ColorId)); | ||
713 | set_Color(tmBannerTitle_ColorId, get_Color(white_ColorId)); | ||
714 | set_Color(tmBannerIcon_ColorId, get_Color(orange_ColorId)); | ||
715 | } | ||
716 | else if (theme == black_GmDocumentTheme) { | ||
717 | set_Color(tmBackground_ColorId, get_Color(black_ColorId)); | ||
718 | set_Color(tmParagraph_ColorId, get_Color(gray75_ColorId)); | ||
719 | set_Color(tmFirstParagraph_ColorId, mix_Color(get_Color(gray75_ColorId), get_Color(white_ColorId), 0.5f)); | ||
720 | set_Color(tmQuote_ColorId, get_Color(orange_ColorId)); | ||
721 | set_Color(tmPreformatted_ColorId, get_Color(orange_ColorId)); | ||
722 | set_Color(tmHeading1_ColorId, get_Color(cyan_ColorId)); | ||
723 | set_Color(tmHeading2_ColorId, mix_Color(get_Color(cyan_ColorId), get_Color(white_ColorId), 0.66f)); | ||
724 | set_Color(tmHeading3_ColorId, get_Color(white_ColorId)); | ||
725 | set_Color(tmBannerBackground_ColorId, get_Color(black_ColorId)); | ||
726 | set_Color(tmBannerTitle_ColorId, get_Color(teal_ColorId)); | ||
727 | set_Color(tmBannerIcon_ColorId, get_Color(teal_ColorId)); | ||
728 | } | ||
729 | else if (theme == gray_GmDocumentTheme) { | ||
730 | set_Color(tmBackground_ColorId, mix_Color(get_Color(gray25_ColorId), get_Color(black_ColorId), 0.25f)); | ||
731 | set_Color(tmParagraph_ColorId, mix_Color(get_Color(gray75_ColorId), get_Color(white_ColorId), 0.0f)); | ||
732 | set_Color(tmFirstParagraph_ColorId, mix_Color(get_Color(gray75_ColorId), get_Color(white_ColorId), 0.5f)); | ||
733 | set_Color(tmQuote_ColorId, get_Color(orange_ColorId)); | ||
734 | set_Color(tmPreformatted_ColorId, get_Color(orange_ColorId)); | ||
735 | set_Color(tmHeading1_ColorId, get_Color(cyan_ColorId)); | ||
736 | set_Color(tmHeading2_ColorId, mix_Color(get_Color(cyan_ColorId), get_Color(white_ColorId), 0.66f)); | ||
737 | set_Color(tmHeading3_ColorId, get_Color(white_ColorId)); | ||
738 | set_Color(tmBannerBackground_ColorId, mix_Color(get_Color(gray25_ColorId), get_Color(black_ColorId), 0.5f)); | ||
739 | set_Color(tmBannerTitle_ColorId, get_Color(teal_ColorId)); | ||
740 | set_Color(tmBannerIcon_ColorId, get_Color(teal_ColorId)); | ||
741 | } | ||
742 | else if (theme == sepia_GmDocumentTheme) { | ||
743 | const iHSLColor base = { 40, 0.6f, 0.9f, 1.0f }; | ||
744 | setHsl_Color(tmBackground_ColorId, base); | ||
745 | set_Color(tmParagraph_ColorId, get_Color(black_ColorId)); | ||
746 | set_Color(tmFirstParagraph_ColorId, get_Color(black_ColorId)); | ||
747 | set_Color(tmQuote_ColorId, get_Color(brown_ColorId)); | ||
748 | set_Color(tmPreformatted_ColorId, get_Color(brown_ColorId)); | ||
749 | set_Color(tmHeading1_ColorId, get_Color(brown_ColorId)); | ||
750 | set_Color(tmHeading2_ColorId, mix_Color(get_Color(brown_ColorId), get_Color(black_ColorId), 0.5f)); | ||
751 | set_Color(tmHeading3_ColorId, get_Color(black_ColorId)); | ||
752 | set_Color(tmBannerBackground_ColorId, mix_Color(get_Color(tmBackground_ColorId), get_Color(brown_ColorId), 0.15f)); | ||
753 | set_Color(tmBannerTitle_ColorId, get_Color(brown_ColorId)); | ||
754 | set_Color(tmBannerIcon_ColorId, get_Color(brown_ColorId)); | ||
755 | } | ||
756 | else if (theme == white_GmDocumentTheme) { | ||
757 | const iHSLColor base = { 40, 0, 1.0f, 1.0f }; | ||
758 | setHsl_Color(tmBackground_ColorId, base); | ||
759 | set_Color(tmParagraph_ColorId, get_Color(gray25_ColorId)); | ||
760 | set_Color(tmFirstParagraph_ColorId, get_Color(black_ColorId)); | ||
761 | set_Color(tmQuote_ColorId, get_Color(brown_ColorId)); | ||
762 | set_Color(tmPreformatted_ColorId, get_Color(brown_ColorId)); | ||
763 | set_Color(tmHeading1_ColorId, get_Color(black_ColorId)); | ||
764 | setHsl_Color(tmHeading2_ColorId, addSatLum_HSLColor(base, 0.15f, -0.7f)); | ||
765 | setHsl_Color(tmHeading3_ColorId, addSatLum_HSLColor(base, 0.3f, -0.6f)); | ||
766 | set_Color(tmBannerBackground_ColorId, get_Color(white_ColorId)); | ||
767 | set_Color(tmBannerTitle_ColorId, get_Color(gray50_ColorId)); | ||
768 | set_Color(tmBannerIcon_ColorId, get_Color(teal_ColorId)); | ||
769 | } | ||
770 | else if (theme == highContrast_GmDocumentTheme) { | ||
771 | set_Color(tmBackground_ColorId, get_Color(white_ColorId)); | ||
772 | set_Color(tmParagraph_ColorId, get_Color(black_ColorId)); | ||
773 | set_Color(tmFirstParagraph_ColorId, get_Color(black_ColorId)); | ||
774 | set_Color(tmQuote_ColorId, get_Color(black_ColorId)); | ||
775 | set_Color(tmPreformatted_ColorId, get_Color(black_ColorId)); | ||
776 | set_Color(tmHeading1_ColorId, get_Color(black_ColorId)); | ||
777 | set_Color(tmHeading2_ColorId, get_Color(black_ColorId)); | ||
778 | set_Color(tmHeading3_ColorId, get_Color(black_ColorId)); | ||
779 | set_Color(tmBannerBackground_ColorId, mix_Color(get_Color(gray75_ColorId), get_Color(white_ColorId), 0.75f)); | ||
780 | set_Color(tmBannerTitle_ColorId, get_Color(black_ColorId)); | ||
781 | set_Color(tmBannerIcon_ColorId, get_Color(black_ColorId)); | ||
782 | } | ||
716 | /* Apply the saturation setting. */ | 783 | /* Apply the saturation setting. */ |
717 | for (int i = tmFirst_ColorId; i < max_ColorId; i++) { | 784 | for (int i = tmFirst_ColorId; i < max_ColorId; i++) { |
718 | if (!isLink_ColorId(i)) { | 785 | if (!isLink_ColorId(i)) { |
@@ -819,7 +886,7 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { | |||
819 | set_Color(tmQuote_ColorId, get_Color(tmPreformatted_ColorId)); | 886 | set_Color(tmQuote_ColorId, get_Color(tmPreformatted_ColorId)); |
820 | set_Color(tmInlineContentMetadata_ColorId, get_Color(tmHeading3_ColorId)); | 887 | set_Color(tmInlineContentMetadata_ColorId, get_Color(tmHeading3_ColorId)); |
821 | } | 888 | } |
822 | else { | 889 | else if (theme == white_GmDocumentTheme) { |
823 | iHSLColor base = { hues[primIndex], 1.0f, 0.3f, 1.0f }; | 890 | iHSLColor base = { hues[primIndex], 1.0f, 0.3f, 1.0f }; |
824 | iHSLColor altBase = { altHue, base.sat, base.lum - 0.1f, 1 }; | 891 | iHSLColor altBase = { altHue, base.sat, base.lum - 0.1f, 1 }; |
825 | 892 | ||
@@ -838,39 +905,23 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { | |||
838 | set_Color(tmQuote_ColorId, get_Color(tmPreformatted_ColorId)); | 905 | set_Color(tmQuote_ColorId, get_Color(tmPreformatted_ColorId)); |
839 | set_Color(tmInlineContentMetadata_ColorId, get_Color(tmHeading3_ColorId)); | 906 | set_Color(tmInlineContentMetadata_ColorId, get_Color(tmHeading3_ColorId)); |
840 | } | 907 | } |
908 | else if (theme == black_GmDocumentTheme || theme == gray_GmDocumentTheme) { | ||
909 | const float primHue = hues[primIndex]; | ||
910 | const iHSLColor primBright = { primHue, 1, 0.6f, 1 }; | ||
911 | const iHSLColor primDim = { primHue, 1, dimLightness_(primHue, theme == black_GmDocumentTheme ? 0.25f : 0.45f), 1}; | ||
912 | const iHSLColor altBright = { altHue, 1, 0.6f, 1 }; | ||
913 | setHsl_Color(tmQuote_ColorId, altBright); | ||
914 | setHsl_Color(tmPreformatted_ColorId, altBright); | ||
915 | setHsl_Color(tmHeading1_ColorId, primBright); | ||
916 | set_Color(tmHeading2_ColorId, mix_Color(get_Color(tmHeading1_ColorId), get_Color(white_ColorId), 0.66f)); | ||
917 | setHsl_Color(tmBannerTitle_ColorId, primDim); | ||
918 | setHsl_Color(tmBannerIcon_ColorId, primDim); | ||
919 | } | ||
841 | 920 | ||
842 | /* Adjust colors based on light/dark mode. */ | 921 | /* Adjust colors based on light/dark mode. */ |
843 | for (int i = tmFirst_ColorId; i < max_ColorId; i++) { | 922 | for (int i = tmFirst_ColorId; i < max_ColorId; i++) { |
844 | iHSLColor color = hsl_Color(get_Color(i)); | 923 | iHSLColor color = hsl_Color(get_Color(i)); |
845 | if (theme == white_GmDocumentTheme) { | 924 | if (theme == colorfulDark_GmDocumentTheme) { /* dark mode */ |
846 | #if 0 | ||
847 | if (isLink_ColorId(i)) continue; | ||
848 | color.lum = 1.0f - color.lum; /* All colors invert lightness. */ | ||
849 | if (isRegularText_ColorId(i)) { | ||
850 | /* Darken paragraphs and default state link text. */ | ||
851 | color.lum *= 0.5f; | ||
852 | } | ||
853 | else if (i == tmBackground_ColorId) { | ||
854 | color.sat = (color.sat + 1) / 2; | ||
855 | color.lum += 0.06f; | ||
856 | } | ||
857 | else if (i == tmHeading3_ColorId) { | ||
858 | color.lum *= 0.75f; | ||
859 | } | ||
860 | else if (i == tmBannerIcon_ColorId || i == tmBannerTitle_ColorId) { | ||
861 | color.sat = 1.0f; | ||
862 | color.lum = 0.35f; | ||
863 | } | ||
864 | else if (i == tmBannerBackground_ColorId) { | ||
865 | color = hsl_Color(get_Color(tmBackground_ColorId)); | ||
866 | } | ||
867 | else if (isText_ColorId(i)) { | ||
868 | color.sat = 0.9f; | ||
869 | color.lum = (9 * color.lum + 0.5f) / 10; | ||
870 | } | ||
871 | #endif | ||
872 | } | ||
873 | else { /* dark mode */ | ||
874 | if (!isLink_ColorId(i)) { | 925 | if (!isLink_ColorId(i)) { |
875 | if (isDarkBgSat) { | 926 | if (isDarkBgSat) { |
876 | /* Saturate background, desaturate text. */ | 927 | /* Saturate background, desaturate text. */ |