summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/color.c23
-rw-r--r--src/ui/color.h22
-rw-r--r--src/ui/documentwidget.c74
3 files changed, 84 insertions, 35 deletions
diff --git a/src/ui/color.c b/src/ui/color.c
index 0402d0fb..a2ff6e27 100644
--- a/src/ui/color.c
+++ b/src/ui/color.c
@@ -100,9 +100,12 @@ static float hueToRgb_(float p, float q, float t) {
100 return p; 100 return p;
101} 101}
102 102
103iColor fromHsl_Color(iHSLColor hsl) { 103iColor rgb_HSLColor(iHSLColor hsl) {
104 float r, g, b; 104 float r, g, b;
105 hsl.hue /= 360.0f; 105 hsl.hue /= 360.0f;
106 hsl.hue = iWrapf(hsl.hue, 0, 1);
107 hsl.sat = iClamp(hsl.sat, 0.0f, 1.0f);
108 hsl.lum = iClamp(hsl.lum, 0.0f, 1.0f);
106 if (hsl.sat < 0.00001f) { 109 if (hsl.sat < 0.00001f) {
107 r = g = b = hsl.lum; 110 r = g = b = hsl.lum;
108 } 111 }
@@ -137,7 +140,23 @@ const char *escape_Color(int color) {
137 if (color >= 0 && color < (int) iElemCount(esc)) { 140 if (color >= 0 && color < (int) iElemCount(esc)) {
138 return esc[color]; 141 return esc[color];
139 } 142 }
140 return white_ColorEscape; 143 return format_CStr("\r%c", color + '0');
144}
145
146iHSLColor setSat_HSLColor(iHSLColor d, float sat) {
147 d.sat = iClamp(sat, 0, 1);
148 return d;
149}
150
151iHSLColor setLum_HSLColor(iHSLColor d, float lum) {
152 d.lum = iClamp(lum, 0, 1);
153 return d;
154}
155
156iHSLColor addSatLum_HSLColor(iHSLColor d, float sat, float lum) {
157 d.sat = iClamp(d.sat + sat, 0, 1);
158 d.lum = iClamp(d.lum + lum, 0, 1);
159 return d;
141} 160}
142 161
143iColor ansi_Color(iRangecc escapeSequence, int fallback) { 162iColor ansi_Color(iRangecc escapeSequence, int fallback) {
diff --git a/src/ui/color.h b/src/ui/color.h
index 11feb63e..c3cacf77 100644
--- a/src/ui/color.h
+++ b/src/ui/color.h
@@ -19,6 +19,7 @@ enum iColorId {
19 magenta_ColorId, 19 magenta_ColorId,
20 blue_ColorId, 20 blue_ColorId,
21 green_ColorId, 21 green_ColorId,
22
22 /* content theme colors */ 23 /* content theme colors */
23 tmFirst_ColorId, 24 tmFirst_ColorId,
24 tmBackground_ColorId = tmFirst_ColorId, 25 tmBackground_ColorId = tmFirst_ColorId,
@@ -29,6 +30,11 @@ enum iColorId {
29 tmHeader1_ColorId, 30 tmHeader1_ColorId,
30 tmHeader2_ColorId, 31 tmHeader2_ColorId,
31 tmHeader3_ColorId, 32 tmHeader3_ColorId,
33 tmBannerBackground_ColorId,
34 tmBannerTitle_ColorId,
35 tmBannerIcon_ColorId,
36 tmInlineContentMetadata_ColorId,
37 tmBadLink_ColorId,
32 38
33 tmLinkIcon_ColorId, 39 tmLinkIcon_ColorId,
34 tmLinkIconVisited_ColorId, 40 tmLinkIconVisited_ColorId,
@@ -51,10 +57,6 @@ enum iColorId {
51 tmGopherLinkDomain_ColorId, 57 tmGopherLinkDomain_ColorId,
52 tmGopherLinkLastVisitDate_ColorId, 58 tmGopherLinkLastVisitDate_ColorId,
53 59
54 tmInlineContentMetadata_ColorId,
55 tmBannerBackground_ColorId,
56 tmBannerTitle_ColorId,
57 tmBannerIcon_ColorId,
58 max_ColorId 60 max_ColorId
59}; 61};
60 62
@@ -87,11 +89,19 @@ struct Impl_HSLColor {
87 float hue, sat, lum, a; 89 float hue, sat, lum, a;
88}; 90};
89 91
92iHSLColor hsl_Color (iColor);
93iColor rgb_HSLColor (iHSLColor);
94
95iHSLColor setSat_HSLColor (iHSLColor, float sat);
96iHSLColor setLum_HSLColor (iHSLColor, float lum);
97iHSLColor addSatLum_HSLColor (iHSLColor, float sat, float lum);
98
90iColor get_Color (int color); 99iColor get_Color (int color);
91void set_Color (int color, iColor rgba); 100void set_Color (int color, iColor rgba);
92 101
93iHSLColor hsl_Color (iColor rgba); 102iLocalDef void setHsl_Color(int color, iHSLColor hsl) {
94iColor fromHsl_Color (iHSLColor hsl); 103 set_Color(color, rgb_HSLColor(hsl));
104}
95 105
96iColor ansi_Color (iRangecc escapeSequence, int fallback); 106iColor ansi_Color (iRangecc escapeSequence, int fallback);
97const char * escape_Color (int color); 107const char * escape_Color (int color);
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);