diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-29 07:42:30 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-29 07:42:30 +0300 |
commit | 4deb72ba6ea6c055dff69d74669887f30ea01e54 (patch) | |
tree | ea9b9645b38367afabaa66637c15d9a1cd0c3374 /src/ui | |
parent | d921021132367076cd2a5f120b3a49db6e29acf7 (diff) |
Showing and hiding image content
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/color.c | 25 | ||||
-rw-r--r-- | src/ui/color.h | 5 | ||||
-rw-r--r-- | src/ui/documentwidget.c | 97 | ||||
-rw-r--r-- | src/ui/window.c | 6 |
4 files changed, 99 insertions, 34 deletions
diff --git a/src/ui/color.c b/src/ui/color.c index 330dab1d..46d8a71f 100644 --- a/src/ui/color.c +++ b/src/ui/color.c | |||
@@ -30,6 +30,31 @@ iColor get_Color(int color) { | |||
30 | return *clr; | 30 | return *clr; |
31 | } | 31 | } |
32 | 32 | ||
33 | const char *escape_Color(int color) { | ||
34 | static const char *esc[] = { | ||
35 | black_ColorEscape, | ||
36 | gray15_ColorEscape, | ||
37 | gray25_ColorEscape, | ||
38 | gray50_ColorEscape, | ||
39 | gray75_ColorEscape, | ||
40 | gray88_ColorEscape, | ||
41 | white_ColorEscape, | ||
42 | brown_ColorEscape, | ||
43 | orange_ColorEscape, | ||
44 | teal_ColorEscape, | ||
45 | cyan_ColorEscape, | ||
46 | yellow_ColorEscape, | ||
47 | red_ColorEscape, | ||
48 | magenta_ColorEscape, | ||
49 | blue_ColorEscape, | ||
50 | green_ColorEscape, | ||
51 | }; | ||
52 | if (color >= 0 && color < max_ColorId) { | ||
53 | return esc[color]; | ||
54 | } | ||
55 | return white_ColorEscape; | ||
56 | } | ||
57 | |||
33 | iColor ansi_Color(iRangecc escapeSequence, int fallback) { | 58 | iColor ansi_Color(iRangecc escapeSequence, int fallback) { |
34 | iColor clr = get_Color(fallback); | 59 | iColor clr = get_Color(fallback); |
35 | for (const char *ch = escapeSequence.start; ch < escapeSequence.end; ch++) { | 60 | for (const char *ch = escapeSequence.start; ch < escapeSequence.end; ch++) { |
diff --git a/src/ui/color.h b/src/ui/color.h index d8b1f4d1..01e49c9c 100644 --- a/src/ui/color.h +++ b/src/ui/color.h | |||
@@ -49,5 +49,6 @@ struct Impl_Color { | |||
49 | uint8_t r, g, b, a; | 49 | uint8_t r, g, b, a; |
50 | }; | 50 | }; |
51 | 51 | ||
52 | iColor get_Color (int color); | 52 | iColor get_Color (int color); |
53 | iColor ansi_Color (iRangecc escapeSequence, int fallback); | 53 | iColor ansi_Color (iRangecc escapeSequence, int fallback); |
54 | const char * escape_Color (int color); | ||
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index cffd284f..f63e98bf 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -497,13 +497,15 @@ static iMediaRequest *findMediaRequest_DocumentWidget_(const iDocumentWidget *d, | |||
497 | return NULL; | 497 | return NULL; |
498 | } | 498 | } |
499 | 499 | ||
500 | static void requestMedia_DocumentWidget_(iDocumentWidget *d, iGmLinkId linkId) { | 500 | static iBool requestMedia_DocumentWidget_(iDocumentWidget *d, iGmLinkId linkId) { |
501 | if (!findMediaRequest_DocumentWidget_(d, linkId)) { | 501 | if (!findMediaRequest_DocumentWidget_(d, linkId)) { |
502 | pushBack_ObjectList( | 502 | pushBack_ObjectList( |
503 | d->media, | 503 | d->media, |
504 | iClob(new_MediaRequest( | 504 | iClob(new_MediaRequest( |
505 | d, linkId, absoluteUrl_DocumentWidget_(d, linkUrl_GmDocument(d->doc, linkId))))); | 505 | d, linkId, absoluteUrl_DocumentWidget_(d, linkUrl_GmDocument(d->doc, linkId))))); |
506 | return iTrue; | ||
506 | } | 507 | } |
508 | return iFalse; | ||
507 | } | 509 | } |
508 | 510 | ||
509 | static iBool handleMediaEvent_DocumentWidget_(iDocumentWidget *d, const char *cmd) { | 511 | static iBool handleMediaEvent_DocumentWidget_(iDocumentWidget *d, const char *cmd) { |
@@ -777,7 +779,26 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
777 | iAssert(linkId); | 779 | iAssert(linkId); |
778 | /* Media links are opened inline by default. */ | 780 | /* Media links are opened inline by default. */ |
779 | if (isMediaLink_GmDocument(d->doc, linkId)) { | 781 | if (isMediaLink_GmDocument(d->doc, linkId)) { |
780 | requestMedia_DocumentWidget_(d, linkId); | 782 | if (!requestMedia_DocumentWidget_(d, linkId)) { |
783 | if (linkFlags_GmDocument(d->doc, linkId) & content_GmLinkFlag) { | ||
784 | setImage_GmDocument(d->doc, linkId, NULL, NULL); | ||
785 | d->hoverLink = NULL; | ||
786 | updateVisible_DocumentWidget_(d); | ||
787 | refresh_Widget(w); | ||
788 | return iTrue; | ||
789 | } | ||
790 | else { | ||
791 | /* Show the existing content again if we have it. */ | ||
792 | iMediaRequest *req = findMediaRequest_DocumentWidget_(d, linkId); | ||
793 | if (req) { | ||
794 | setImage_GmDocument(d->doc, linkId, meta_GmRequest(req->req), | ||
795 | body_GmRequest(req->req)); | ||
796 | updateVisible_DocumentWidget_(d); | ||
797 | refresh_Widget(w); | ||
798 | return iTrue; | ||
799 | } | ||
800 | } | ||
801 | } | ||
781 | } | 802 | } |
782 | else { | 803 | else { |
783 | postCommandf_App("open url:%s", | 804 | postCommandf_App("open url:%s", |
@@ -840,8 +861,8 @@ static void fillRange_DrawContext_(iDrawContext *d, const iGmRun *run, enum iCol | |||
840 | } | 861 | } |
841 | 862 | ||
842 | static void drawRun_DrawContext_(void *context, const iGmRun *run) { | 863 | static void drawRun_DrawContext_(void *context, const iGmRun *run) { |
843 | iDrawContext *d = context; | 864 | iDrawContext *d = context; |
844 | const iInt2 origin = addY_I2(d->bounds.pos, -d->widget->scrollY); | 865 | const iInt2 origin = addY_I2(d->bounds.pos, -d->widget->scrollY); |
845 | if (run->imageId) { | 866 | if (run->imageId) { |
846 | SDL_Texture *tex = imageTexture_GmDocument(d->widget->doc, run->imageId); | 867 | SDL_Texture *tex = imageTexture_GmDocument(d->widget->doc, run->imageId); |
847 | if (tex) { | 868 | if (tex) { |
@@ -854,32 +875,50 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
854 | iString text; | 875 | iString text; |
855 | /* TODO: making a copy is unnecessary; the text routines should accept Rangecc */ | 876 | /* TODO: making a copy is unnecessary; the text routines should accept Rangecc */ |
856 | initRange_String(&text, run->text); | 877 | initRange_String(&text, run->text); |
857 | enum iColorId fg = run->color; | 878 | enum iColorId fg = run->color; |
858 | if (run == d->widget->hoverLink) { | 879 | const iGmDocument *doc = d->widget->doc; |
859 | const iGmDocument *doc = d->widget->doc; | 880 | if (run->linkId) { |
860 | const iGmLinkId linkId = d->widget->hoverLink->linkId; | 881 | /* TODO: Visualize an ongoing media request. */ |
861 | const iString * url = linkUrl_GmDocument(doc, linkId); | 882 | const int flags = linkFlags_GmDocument(doc, run->linkId); |
862 | const int flags = linkFlags_GmDocument(doc, linkId); | 883 | if (flags & content_GmLinkFlag) { |
863 | iUrl parts; | 884 | fg = linkColor_GmDocument(doc, run->linkId); |
864 | init_Url(&parts, url); | 885 | if (!isEmpty_Rect(run->bounds)) { |
865 | const iString *host = collect_String(newRange_String(parts.host)); | 886 | iGmImageInfo info; |
866 | fg = linkColor_GmDocument(doc, linkId); | 887 | imageInfo_GmDocument(doc, linkImage_GmDocument(doc, run->linkId), &info); |
867 | const iBool showHost = (!isEmpty_String(host) && flags & userFriendly_GmLinkFlag); | 888 | drawAlign_Text(default_FontId, |
868 | const iBool showImage = (flags & imageFileExtension_GmLinkFlag) != 0; | 889 | add_I2(topRight_Rect(run->bounds), origin), |
869 | const iBool showAudio = (flags & audioFileExtension_GmLinkFlag) != 0; | 890 | fg, |
870 | if (flags & (imageFileExtension_GmLinkFlag | audioFileExtension_GmLinkFlag) || showHost) { | 891 | right_Alignment, |
892 | "%s \u2014 %d x %d \u2014 %.1fMB %s \u2715", | ||
893 | info.mime, info.size.x, info.size.y, info.numBytes / 1.0e6f, | ||
894 | run == d->widget->hoverLink ? white_ColorEscape : ""); | ||
895 | } | ||
896 | } | ||
897 | else if (run == d->widget->hoverLink) { | ||
898 | const iGmLinkId linkId = d->widget->hoverLink->linkId; | ||
899 | const iString * url = linkUrl_GmDocument(doc, linkId); | ||
900 | const int flags = linkFlags_GmDocument(doc, linkId); | ||
901 | iUrl parts; | ||
902 | init_Url(&parts, url); | ||
903 | const iString *host = collect_String(newRange_String(parts.host)); | ||
904 | fg = linkColor_GmDocument(doc, linkId); | ||
905 | const iBool showHost = (!isEmpty_String(host) && flags & userFriendly_GmLinkFlag); | ||
906 | const iBool showImage = (flags & imageFileExtension_GmLinkFlag) != 0; | ||
907 | const iBool showAudio = (flags & audioFileExtension_GmLinkFlag) != 0; | ||
871 | iRect linkRect = moved_Rect(run->visBounds, origin); | 908 | iRect linkRect = moved_Rect(run->visBounds, origin); |
872 | drawAlign_Text(default_FontId, | 909 | if (flags & (imageFileExtension_GmLinkFlag | audioFileExtension_GmLinkFlag) || showHost) { |
873 | topRight_Rect(linkRect), | 910 | drawAlign_Text(default_FontId, |
874 | fg - 1, | 911 | topRight_Rect(linkRect), |
875 | left_Alignment, | 912 | fg - 1, |
876 | " \u2014%s%s%s\r%c%s", | 913 | left_Alignment, |
877 | showHost ? " " : "", | 914 | " \u2014%s%s%s\r%c%s", |
878 | showHost ? cstr_String(host) : "", | 915 | showHost ? " " : "", |
879 | showHost && (showImage || showAudio) ? " \u2014" : "", | 916 | showHost ? cstr_String(host) : "", |
880 | showImage || showAudio ? '0' + fg : ('0' + fg - 1), | 917 | showHost && (showImage || showAudio) ? " \u2014" : "", |
881 | showImage ? " View Image \U0001f5bc" | 918 | showImage || showAudio ? '0' + fg : ('0' + fg - 1), |
882 | : showAudio ? " Play Audio \U0001f3b5" : ""); | 919 | showImage ? " View Image \U0001f5bc" |
920 | : showAudio ? " Play Audio \U0001f3b5" : ""); | ||
921 | } | ||
883 | } | 922 | } |
884 | } | 923 | } |
885 | const iInt2 visPos = add_I2(run->visBounds.pos, origin); | 924 | const iInt2 visPos = add_I2(run->visBounds.pos, origin); |
diff --git a/src/ui/window.c b/src/ui/window.c index a7291320..feb917ff 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -204,9 +204,9 @@ static void setupUserInterface_Window(iWindow *d) { | |||
204 | iInputWidget *input = new_InputWidget(0); | 204 | iInputWidget *input = new_InputWidget(0); |
205 | setId_Widget(addChildFlags_Widget(searchBar, iClob(input), expand_WidgetFlag), | 205 | setId_Widget(addChildFlags_Widget(searchBar, iClob(input), expand_WidgetFlag), |
206 | "find.input"); | 206 | "find.input"); |
207 | addChild_Widget(searchBar, iClob(new_LabelWidget(" \U0001f86b ", 'g', KMOD_PRIMARY, "find.next"))); | 207 | addChild_Widget(searchBar, iClob(new_LabelWidget(" \U0001f86b ", 'g', KMOD_PRIMARY, "find.next"))); |
208 | addChild_Widget(searchBar, iClob(new_LabelWidget(" \U0001f869 ", 'g', KMOD_PRIMARY | KMOD_SHIFT, "find.prev"))); | 208 | addChild_Widget(searchBar, iClob(new_LabelWidget(" \U0001f869 ", 'g', KMOD_PRIMARY | KMOD_SHIFT, "find.prev"))); |
209 | addChild_Widget(searchBar, iClob(new_LabelWidget("\u00d7", SDLK_ESCAPE, 0, "find.close"))); | 209 | addChild_Widget(searchBar, iClob(new_LabelWidget("\u2715", SDLK_ESCAPE, 0, "find.close"))); |
210 | } | 210 | } |
211 | 211 | ||
212 | #if 0 | 212 | #if 0 |