diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-10-01 07:15:04 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-10-01 07:15:04 +0300 |
commit | d719e31a5d38c410e8e2d0795afe91fc59cf352e (patch) | |
tree | 7a4d2090c08d985c64df4e9168cc6d1097d8bc38 /src/ui | |
parent | 4041ff10f50d4b6dc5c14b18f180b2738cbbadd0 (diff) |
Refactor: Separate media from GmDocument
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/documentwidget.c | 67 |
1 files changed, 30 insertions, 37 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index eb248ceb..f63d93f4 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -31,9 +31,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
31 | #include "util.h" | 31 | #include "util.h" |
32 | #include "history.h" | 32 | #include "history.h" |
33 | #include "app.h" | 33 | #include "app.h" |
34 | #include "../gmdocument.h" | 34 | #include "gmdocument.h" |
35 | #include "../gmrequest.h" | 35 | #include "gmrequest.h" |
36 | #include "../gmutil.h" | 36 | #include "gmutil.h" |
37 | #include "media.h" | ||
37 | 38 | ||
38 | #include <the_Foundation/file.h> | 39 | #include <the_Foundation/file.h> |
39 | #include <the_Foundation/fileinfo.h> | 40 | #include <the_Foundation/fileinfo.h> |
@@ -735,8 +736,12 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d, const iGmResponse | |||
735 | baseName_Path(collect_String(newRange_String(parts.path))).start; | 736 | baseName_Path(collect_String(newRange_String(parts.path))).start; |
736 | } | 737 | } |
737 | format_String(&str, "=> %s %s\n", cstr_String(d->mod.url), imageTitle); | 738 | format_String(&str, "=> %s %s\n", cstr_String(d->mod.url), imageTitle); |
738 | setImage_GmDocument( | 739 | setImage_Media(media_GmDocument(d->doc), |
739 | d->doc, 1, mimeStr, &response->body, iFalse /* it's fixed */); | 740 | 1, |
741 | mimeStr, | ||
742 | &response->body, | ||
743 | iFalse /* it's fixed */); | ||
744 | redoLayout_GmDocument(d->doc); | ||
740 | } | 745 | } |
741 | else { | 746 | else { |
742 | clear_String(&str); | 747 | clear_String(&str); |
@@ -1136,13 +1141,13 @@ static iBool handleMediaCommand_DocumentWidget_(iDocumentWidget *d, const char * | |||
1136 | const enum iGmStatusCode code = status_GmRequest(req->req); | 1141 | const enum iGmStatusCode code = status_GmRequest(req->req); |
1137 | /* Give the media to the document for presentation. */ | 1142 | /* Give the media to the document for presentation. */ |
1138 | if (code == success_GmStatusCode) { | 1143 | if (code == success_GmStatusCode) { |
1139 | // printf("media finished: %s\n size: %zu\n type: %s\n", | ||
1140 | // cstr_String(url_GmRequest(req->req)), | ||
1141 | // size_Block(body_GmRequest(req->req)), | ||
1142 | // cstr_String(meta_GmRequest(req->req))); | ||
1143 | if (startsWith_String(meta_GmRequest(req->req), "image/")) { | 1144 | if (startsWith_String(meta_GmRequest(req->req), "image/")) { |
1144 | setImage_GmDocument(d->doc, req->linkId, meta_GmRequest(req->req), | 1145 | setImage_Media(media_GmDocument(d->doc), |
1145 | body_GmRequest(req->req), iTrue); | 1146 | req->linkId, |
1147 | meta_GmRequest(req->req), | ||
1148 | body_GmRequest(req->req), | ||
1149 | iTrue); | ||
1150 | redoLayout_GmDocument(d->doc); | ||
1146 | updateVisible_DocumentWidget_(d); | 1151 | updateVisible_DocumentWidget_(d); |
1147 | invalidate_DocumentWidget_(d); | 1152 | invalidate_DocumentWidget_(d); |
1148 | refresh_Widget(as_Widget(d)); | 1153 | refresh_Widget(as_Widget(d)); |
@@ -1792,10 +1797,11 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
1792 | further to do. */ | 1797 | further to do. */ |
1793 | return iTrue; | 1798 | return iTrue; |
1794 | } | 1799 | } |
1795 | if (!requestMedia_DocumentWidget_(d, linkId)) { | 1800 | if (!requestMedia_DocumentWidget_(d, linkId)) { |
1796 | if (linkFlags & content_GmLinkFlag) { | 1801 | if (linkFlags & content_GmLinkFlag) { |
1797 | /* Dismiss shown content on click. */ | 1802 | /* Dismiss shown content on click. */ |
1798 | setImage_GmDocument(d->doc, linkId, NULL, NULL, iTrue); | 1803 | setImage_Media(media_GmDocument(d->doc), linkId, NULL, NULL, iTrue); |
1804 | redoLayout_GmDocument(d->doc); | ||
1799 | d->hoverLink = NULL; | 1805 | d->hoverLink = NULL; |
1800 | scroll_DocumentWidget_(d, 0); | 1806 | scroll_DocumentWidget_(d, 0); |
1801 | updateVisible_DocumentWidget_(d); | 1807 | updateVisible_DocumentWidget_(d); |
@@ -1807,8 +1813,12 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
1807 | /* Show the existing content again if we have it. */ | 1813 | /* Show the existing content again if we have it. */ |
1808 | iMediaRequest *req = findMediaRequest_DocumentWidget_(d, linkId); | 1814 | iMediaRequest *req = findMediaRequest_DocumentWidget_(d, linkId); |
1809 | if (req) { | 1815 | if (req) { |
1810 | setImage_GmDocument(d->doc, linkId, meta_GmRequest(req->req), | 1816 | setImage_Media(media_GmDocument(d->doc), |
1811 | body_GmRequest(req->req), iTrue); | 1817 | linkId, |
1818 | meta_GmRequest(req->req), | ||
1819 | body_GmRequest(req->req), | ||
1820 | iTrue); | ||
1821 | redoLayout_GmDocument(d->doc); | ||
1812 | updateVisible_DocumentWidget_(d); | 1822 | updateVisible_DocumentWidget_(d); |
1813 | invalidate_DocumentWidget_(d); | 1823 | invalidate_DocumentWidget_(d); |
1814 | refresh_Widget(w); | 1824 | refresh_Widget(w); |
@@ -1894,7 +1904,7 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
1894 | iDrawContext *d = context; | 1904 | iDrawContext *d = context; |
1895 | const iInt2 origin = d->viewPos; | 1905 | const iInt2 origin = d->viewPos; |
1896 | if (run->imageId) { | 1906 | if (run->imageId) { |
1897 | SDL_Texture *tex = imageTexture_GmDocument(d->widget->doc, run->imageId); | 1907 | SDL_Texture *tex = imageTexture_Media(media_GmDocument(d->widget->doc), run->imageId); |
1898 | if (tex) { | 1908 | if (tex) { |
1899 | const iRect dst = moved_Rect(run->visBounds, origin); | 1909 | const iRect dst = moved_Rect(run->visBounds, origin); |
1900 | fillRect_Paint(&d->paint, dst, tmBackground_ColorId); /* in case the image has alpha */ | 1910 | fillRect_Paint(&d->paint, dst, tmBackground_ColorId); /* in case the image has alpha */ |
@@ -1981,7 +1991,7 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
1981 | fg = linkColor_GmDocument(doc, run->linkId, textHover_GmLinkPart); | 1991 | fg = linkColor_GmDocument(doc, run->linkId, textHover_GmLinkPart); |
1982 | iAssert(!isEmpty_Rect(run->bounds)); | 1992 | iAssert(!isEmpty_Rect(run->bounds)); |
1983 | iGmImageInfo info; | 1993 | iGmImageInfo info; |
1984 | imageInfo_GmDocument(doc, linkImage_GmDocument(doc, run->linkId), &info); | 1994 | imageInfo_Media(constMedia_GmDocument(doc), linkImage_GmDocument(doc, run->linkId), &info); |
1985 | iString text; | 1995 | iString text; |
1986 | init_String(&text); | 1996 | init_String(&text); |
1987 | format_String(&text, "%s \u2014 %d x %d \u2014 %.1fMB", | 1997 | format_String(&text, "%s \u2014 %d x %d \u2014 %.1fMB", |
@@ -2083,7 +2093,7 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
2083 | // drawRect_Paint(&d->paint, (iRect){ visPos, run->visBounds.size }, red_ColorId); | 2093 | // drawRect_Paint(&d->paint, (iRect){ visPos, run->visBounds.size }, red_ColorId); |
2084 | } | 2094 | } |
2085 | 2095 | ||
2086 | static int drawSideRect_(iPaint *p, iRect rect) { //}, int thickness) { | 2096 | static int drawSideRect_(iPaint *p, iRect rect) { |
2087 | int bg = tmBannerBackground_ColorId; | 2097 | int bg = tmBannerBackground_ColorId; |
2088 | int fg = tmBannerIcon_ColorId; | 2098 | int fg = tmBannerIcon_ColorId; |
2089 | if (equal_Color(get_Color(bg), get_Color(tmBackground_ColorId))) { | 2099 | if (equal_Color(get_Color(bg), get_Color(tmBackground_ColorId))) { |
@@ -2131,34 +2141,17 @@ static void drawSideElements_DocumentWidget_(const iDocumentWidget *d) { | |||
2131 | const iChar icon = siteIcon_GmDocument(d->doc); | 2141 | const iChar icon = siteIcon_GmDocument(d->doc); |
2132 | iRect rect = { add_I2(topLeft_Rect(bounds), init1_I2(margin)), init1_I2(minBannerSize) }; | 2142 | iRect rect = { add_I2(topLeft_Rect(bounds), init1_I2(margin)), init1_I2(minBannerSize) }; |
2133 | p.alpha = opacity * 255; | 2143 | p.alpha = opacity * 255; |
2134 | //int offset = iMax(0, bottom_Rect(banner->visBounds) - d->scrollY); | 2144 | rect.pos.y += height_Rect(bounds) / 2 - rect.size.y / 2 - (banner ? banner->visBounds.size.y / 2 : 0); |
2135 | rect.pos.y += height_Rect(bounds) / 2 - rect.size.y / 2 - (banner ? banner->visBounds.size.y / 2 : 0); // offset; | 2145 | int fg = drawSideRect_(&p, rect); |
2136 | //rect.pos.y -= lineHeight_Text(heading3_FontId) / 2; /* the heading text underneath */ | ||
2137 | int fg = drawSideRect_(&p, rect); //, gap_UI / 2); | ||
2138 | iString str; | 2146 | iString str; |
2139 | initUnicodeN_String(&str, &icon, 1); | 2147 | initUnicodeN_String(&str, &icon, 1); |
2140 | drawCentered_Text(banner_FontId, rect, iTrue, fg, "%s", cstr_String(&str)); | 2148 | drawCentered_Text(banner_FontId, rect, iTrue, fg, "%s", cstr_String(&str)); |
2141 | #if 1 | ||
2142 | if (avail >= minBannerSize * 2.25f) { | 2149 | if (avail >= minBannerSize * 2.25f) { |
2143 | iRangecc text = currentHeading_DocumentWidget_(d);// bannerText_DocumentWidget_(d); | 2150 | iRangecc text = currentHeading_DocumentWidget_(d);// bannerText_DocumentWidget_(d); |
2144 | iInt2 pos = addY_I2(bottomLeft_Rect(rect), gap_Text); | 2151 | iInt2 pos = addY_I2(bottomLeft_Rect(rect), gap_Text); |
2145 | const int font = heading3_FontId; | 2152 | const int font = heading3_FontId; |
2146 | drawWrapRange_Text(font, pos, avail - margin, tmBannerSideTitle_ColorId, text); | 2153 | drawWrapRange_Text(font, pos, avail - margin, tmBannerSideTitle_ColorId, text); |
2147 | #if 0 | ||
2148 | while (!isEmpty_Range(&text)) { | ||
2149 | tryAdvance_Text(font, text, avail - 2 * margin, &endp); | ||
2150 | drawRange_Text( | ||
2151 | font, pos, tmBannerTitle_ColorId, (iRangecc){ text.start, endp }); | ||
2152 | // drawRange_Text(font, | ||
2153 | // add_I2(pos, init1_I2(-gap_UI / 4)), | ||
2154 | // tmBackground_ColorId, | ||
2155 | // (iRangecc){ text.start, endp }); | ||
2156 | text.start = endp; | ||
2157 | pos.y += lineHeight_Text(font); | ||
2158 | } | ||
2159 | #endif | ||
2160 | } | 2154 | } |
2161 | #endif | ||
2162 | setOpacity_Text(1.0f); | 2155 | setOpacity_Text(1.0f); |
2163 | SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_NONE); | 2156 | SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_NONE); |
2164 | } | 2157 | } |