diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-05 16:30:34 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-05 16:30:34 +0300 |
commit | f38a940d722064e4b3fb2df6a6c0bcc025383ca0 (patch) | |
tree | f3df6097a60b04ff324cf9105f9cb1a4dbd825c9 /src/ui/documentwidget.c | |
parent | 2b1de0641335ab1a88aeafcc8911056f155e94c9 (diff) |
Color palette theming
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r-- | src/ui/documentwidget.c | 74 |
1 files changed, 47 insertions, 27 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index dbcf57eb..48eb482f 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -841,6 +841,16 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
841 | return iTrue; | 841 | return iTrue; |
842 | } | 842 | } |
843 | break; | 843 | break; |
844 | case SDLK_9: { | ||
845 | iBlock *seed = new_Block(64); | ||
846 | for (size_t i = 0; i < 64; ++i) { | ||
847 | setByte_Block(seed, i, iRandom(0, 255)); | ||
848 | } | ||
849 | setThemeSeed_GmDocument(d->doc, seed); | ||
850 | delete_Block(seed); | ||
851 | refresh_Widget(w); | ||
852 | break; | ||
853 | } | ||
844 | #if 0 | 854 | #if 0 |
845 | case '0': { | 855 | case '0': { |
846 | extern int enableHalfPixelGlyphs_Text; | 856 | extern int enableHalfPixelGlyphs_Text; |
@@ -1013,34 +1023,38 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
1013 | !isEmpty_Rect(run->bounds)); | 1023 | !isEmpty_Rect(run->bounds)); |
1014 | const iInt2 visPos = add_I2(run->visBounds.pos, origin); | 1024 | const iInt2 visPos = add_I2(run->visBounds.pos, origin); |
1015 | /* Text markers. */ | 1025 | /* Text markers. */ |
1026 | /* TODO: Add themed palette entries */ | ||
1016 | fillRange_DrawContext_(d, run, teal_ColorId, d->widget->foundMark, &d->inFoundMark); | 1027 | fillRange_DrawContext_(d, run, teal_ColorId, d->widget->foundMark, &d->inFoundMark); |
1017 | fillRange_DrawContext_(d, run, brown_ColorId, d->widget->selectMark, &d->inSelectMark); | 1028 | fillRange_DrawContext_(d, run, brown_ColorId, d->widget->selectMark, &d->inSelectMark); |
1018 | if (run->linkId && !isEmpty_Rect(run->bounds)) { | 1029 | if (run->linkId && !isEmpty_Rect(run->bounds)) { |
1019 | // const int flags = linkFlags_GmDocument(doc, run->linkId); | 1030 | fg = linkColor_GmDocument(doc, run->linkId, isHover ? textHover_GmLinkPart : text_GmLinkPart); |
1020 | fg = /*flags & visited_GmLinkFlag ? gray88_ColorId :*/ white_ColorId; | 1031 | if (linkFlags_GmDocument(doc, run->linkId) & content_GmLinkFlag) { |
1021 | if (isHover || linkFlags_GmDocument(doc, run->linkId) & content_GmLinkFlag) { | 1032 | fg = linkColor_GmDocument(doc, run->linkId, textHover_GmLinkPart); /* link is inactive */ |
1022 | fg = linkColor_GmDocument(doc, run->linkId); | ||
1023 | } | 1033 | } |
1024 | } | 1034 | } |
1025 | if (run->flags & siteBanner_GmRunFlag) { | 1035 | if (run->flags & siteBanner_GmRunFlag) { |
1036 | /* Draw the site banner. */ | ||
1026 | fillRect_Paint( | 1037 | fillRect_Paint( |
1027 | &d->paint, | 1038 | &d->paint, |
1028 | initCorners_Rect(topLeft_Rect(d->widgetBounds), | 1039 | initCorners_Rect(topLeft_Rect(d->widgetBounds), |
1029 | init_I2(right_Rect(bounds_Widget(constAs_Widget(d->widget))), | 1040 | init_I2(right_Rect(bounds_Widget(constAs_Widget(d->widget))), |
1030 | visPos.y + height_Rect(run->visBounds))), | 1041 | visPos.y + height_Rect(run->visBounds))), |
1031 | black_ColorId); | 1042 | tmBannerBackground_ColorId); |
1032 | const iChar icon = siteIcon_GmDocument(doc); | 1043 | const iChar icon = siteIcon_GmDocument(doc); |
1033 | iString bannerText; | 1044 | iString bannerText; |
1034 | init_String(&bannerText); | 1045 | init_String(&bannerText); |
1035 | format_String(&bannerText, "%lc", (int) icon); | ||
1036 | //appendRange_String(&bannerText, run->text); | ||
1037 | const iInt2 iconSize = advanceN_Text(banner_FontId, cstr_String(&bannerText), 2); | ||
1038 | iInt2 bpos = add_I2(visPos, init_I2(0, lineHeight_Text(banner_FontId) / 2)); | 1046 | iInt2 bpos = add_I2(visPos, init_I2(0, lineHeight_Text(banner_FontId) / 2)); |
1039 | // draw_Text(run->font, bpos, fg, "%s", buf); | 1047 | if (icon) { |
1040 | // bpos.x += iconSize.x; | 1048 | format_String(&bannerText, "%lc", (int) icon); |
1041 | drawRange_Text(run->font, bpos, fg, range_String(&bannerText)); | 1049 | const iInt2 iconSize = advanceN_Text(banner_FontId, cstr_String(&bannerText), 2); |
1042 | bpos.x += iconSize.x + 3 * gap_Text; | 1050 | drawRange_Text(run->font, bpos, tmBannerIcon_ColorId, range_String(&bannerText)); |
1043 | drawRange_Text(run->font, bpos, fg, run->text); | 1051 | bpos.x += iconSize.x + 3 * gap_Text; |
1052 | } | ||
1053 | drawRange_Text(run->font, | ||
1054 | bpos, | ||
1055 | tmBannerTitle_ColorId, | ||
1056 | isEmpty_String(d->widget->titleUser) ? run->text | ||
1057 | : range_String(d->widget->titleUser)); | ||
1044 | deinit_String(&bannerText); | 1058 | deinit_String(&bannerText); |
1045 | } | 1059 | } |
1046 | else { | 1060 | else { |
@@ -1053,8 +1067,9 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
1053 | const int flags = linkFlags_GmDocument(doc, run->linkId); | 1067 | const int flags = linkFlags_GmDocument(doc, run->linkId); |
1054 | const iRect linkRect = moved_Rect(run->visBounds, origin); | 1068 | const iRect linkRect = moved_Rect(run->visBounds, origin); |
1055 | iMediaRequest *mr = NULL; | 1069 | iMediaRequest *mr = NULL; |
1070 | /* Show inline content. */ | ||
1056 | if (flags & content_GmLinkFlag) { | 1071 | if (flags & content_GmLinkFlag) { |
1057 | fg = linkColor_GmDocument(doc, run->linkId); | 1072 | fg = linkColor_GmDocument(doc, run->linkId, textHover_GmLinkPart); |
1058 | if (!isEmpty_Rect(run->bounds)) { | 1073 | if (!isEmpty_Rect(run->bounds)) { |
1059 | iGmImageInfo info; | 1074 | iGmImageInfo info; |
1060 | imageInfo_GmDocument(doc, linkImage_GmDocument(doc, run->linkId), &info); | 1075 | imageInfo_GmDocument(doc, linkImage_GmDocument(doc, run->linkId), &info); |
@@ -1064,7 +1079,7 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
1064 | info.mime, info.size.x, info.size.y, info.numBytes / 1.0e6f); | 1079 | info.mime, info.size.x, info.size.y, info.numBytes / 1.0e6f); |
1065 | if (findMediaRequest_DocumentWidget_(d->widget, run->linkId)) { | 1080 | if (findMediaRequest_DocumentWidget_(d->widget, run->linkId)) { |
1066 | appendFormat_String( | 1081 | appendFormat_String( |
1067 | &text, " %s\U0001f7a8", isHover ? white_ColorEscape : ""); | 1082 | &text, " %s\U0001f7a8", isHover ? escape_Color(tmLinkText_ColorId) : ""); |
1068 | } | 1083 | } |
1069 | drawAlign_Text(metaFont, | 1084 | drawAlign_Text(metaFont, |
1070 | add_I2(topRight_Rect(run->bounds), origin), | 1085 | add_I2(topRight_Rect(run->bounds), origin), |
@@ -1079,7 +1094,7 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
1079 | if (!isFinished_GmRequest(mr->req)) { | 1094 | if (!isFinished_GmRequest(mr->req)) { |
1080 | draw_Text(metaFont, | 1095 | draw_Text(metaFont, |
1081 | topRight_Rect(linkRect), | 1096 | topRight_Rect(linkRect), |
1082 | linkColor_GmDocument(doc, run->linkId), | 1097 | tmInlineContentMetadata_ColorId, |
1083 | " \u2014 Fetching\u2026"); | 1098 | " \u2014 Fetching\u2026"); |
1084 | } | 1099 | } |
1085 | } | 1100 | } |
@@ -1090,7 +1105,7 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
1090 | iUrl parts; | 1105 | iUrl parts; |
1091 | init_Url(&parts, url); | 1106 | init_Url(&parts, url); |
1092 | const iString *host = collect_String(newRange_String(parts.host)); | 1107 | const iString *host = collect_String(newRange_String(parts.host)); |
1093 | fg = linkColor_GmDocument(doc, linkId); | 1108 | fg = linkColor_GmDocument(doc, linkId, textHover_GmLinkPart); |
1094 | const iBool showHost = (!isEmpty_String(host) && flags & userFriendly_GmLinkFlag); | 1109 | const iBool showHost = (!isEmpty_String(host) && flags & userFriendly_GmLinkFlag); |
1095 | const iBool showImage = (flags & imageFileExtension_GmLinkFlag) != 0; | 1110 | const iBool showImage = (flags & imageFileExtension_GmLinkFlag) != 0; |
1096 | const iBool showAudio = (flags & audioFileExtension_GmLinkFlag) != 0; | 1111 | const iBool showAudio = (flags & audioFileExtension_GmLinkFlag) != 0; |
@@ -1099,20 +1114,25 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
1099 | if (run->flags & endOfLine_GmRunFlag && | 1114 | if (run->flags & endOfLine_GmRunFlag && |
1100 | (flags & (imageFileExtension_GmLinkFlag | audioFileExtension_GmLinkFlag) || | 1115 | (flags & (imageFileExtension_GmLinkFlag | audioFileExtension_GmLinkFlag) || |
1101 | showHost)) { | 1116 | showHost)) { |
1102 | format_String(&str, " \u2014%s%s%s\r%c%s", | 1117 | format_String( |
1103 | showHost ? " " : "", | 1118 | &str, |
1104 | showHost ? cstr_String(host) : "", | 1119 | " \u2014%s%s%s\r%c%s", |
1105 | showHost && (showImage || showAudio) ? " \u2014" : "", | 1120 | showHost ? " " : "", |
1106 | showImage || showAudio ? '0' + fg : ('0' + fg - 1), | 1121 | showHost ? cstr_String(host) : "", |
1107 | showImage ? " View Image \U0001f5bc" | 1122 | showHost && (showImage || showAudio) ? " \u2014" : "", |
1108 | : showAudio ? " Play Audio \U0001f3b5" : ""); | 1123 | showImage || showAudio |
1124 | ? '0' + fg | ||
1125 | : ('0' + linkColor_GmDocument(doc, run->linkId, domain_GmLinkPart)), | ||
1126 | showImage ? " View Image \U0001f5bc" | ||
1127 | : showAudio ? " Play Audio \U0001f3b5" : ""); | ||
1109 | } | 1128 | } |
1110 | if (run->flags & endOfLine_GmRunFlag && flags & visited_GmLinkFlag) { | 1129 | if (run->flags & endOfLine_GmRunFlag && flags & visited_GmLinkFlag) { |
1111 | iDate date; | 1130 | iDate date; |
1112 | init_Date(&date, linkTime_GmDocument(doc, run->linkId)); | 1131 | init_Date(&date, linkTime_GmDocument(doc, run->linkId)); |
1113 | appendFormat_String(&str, | 1132 | appendFormat_String(&str, |
1114 | " \u2014 %s%s", | 1133 | " \u2014 %s%s", |
1115 | escape_Color(fg), | 1134 | escape_Color(linkColor_GmDocument(doc, run->linkId, |
1135 | visited_GmLinkPart)), | ||
1116 | cstr_String(collect_String(format_Date(&date, "%b %d")))); | 1136 | cstr_String(collect_String(format_Date(&date, "%b %d")))); |
1117 | } | 1137 | } |
1118 | if (!isEmpty_String(&str)) { | 1138 | if (!isEmpty_String(&str)) { |
@@ -1128,7 +1148,7 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
1128 | } | 1148 | } |
1129 | drawAlign_Text(metaFont, | 1149 | drawAlign_Text(metaFont, |
1130 | init_I2(tx, top_Rect(linkRect)), | 1150 | init_I2(tx, top_Rect(linkRect)), |
1131 | fg - 1, | 1151 | linkColor_GmDocument(doc, run->linkId, domain_GmLinkPart), |
1132 | left_Alignment, | 1152 | left_Alignment, |
1133 | "%s", | 1153 | "%s", |
1134 | msg); | 1154 | msg); |
@@ -1152,7 +1172,7 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) { | |||
1152 | .bounds = documentBounds_DocumentWidget_(d) | 1172 | .bounds = documentBounds_DocumentWidget_(d) |
1153 | }; | 1173 | }; |
1154 | init_Paint(&ctx.paint); | 1174 | init_Paint(&ctx.paint); |
1155 | fillRect_Paint(&ctx.paint, bounds, black_ColorId); | 1175 | fillRect_Paint(&ctx.paint, bounds, tmBackground_ColorId); |
1156 | setClip_Paint(&ctx.paint, bounds); | 1176 | setClip_Paint(&ctx.paint, bounds); |
1157 | render_GmDocument(d->doc, visibleRange_DocumentWidget_(d), drawRun_DrawContext_, &ctx); | 1177 | render_GmDocument(d->doc, visibleRange_DocumentWidget_(d), drawRun_DrawContext_, &ctx); |
1158 | clearClip_Paint(&ctx.paint); | 1178 | clearClip_Paint(&ctx.paint); |