diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-08-15 19:50:22 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-08-15 19:50:22 +0300 |
commit | 32e7104dd03357dfd2032d200c528e88656daa69 (patch) | |
tree | 11184efde581fa6edd915bd727ea852db863df1f /src/ui/documentwidget.c | |
parent | 9d7469ded746cbfa1e86c1ecd67e4a36f29f635b (diff) | |
parent | 0cbb300784aab7c8bb6bcbcfb044a48a5f9a19ac (diff) |
Merge branch 'dev' into work/v1.7
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r-- | src/ui/documentwidget.c | 111 |
1 files changed, 57 insertions, 54 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 674b0352..a89eb0eb 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -4799,64 +4799,67 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) { | |||
4799 | }; | 4799 | }; |
4800 | init_Paint(&ctx.paint); | 4800 | init_Paint(&ctx.paint); |
4801 | render_DocumentWidget_(d, &ctx, iFalse /* just the mandatory parts */); | 4801 | render_DocumentWidget_(d, &ctx, iFalse /* just the mandatory parts */); |
4802 | setClip_Paint(&ctx.paint, clipBounds); | 4802 | int yTop = docBounds.pos.y - pos_SmoothScroll(&d->scrollY); |
4803 | int yTop = docBounds.pos.y - pos_SmoothScroll(&d->scrollY); | 4803 | const iBool isDocEmpty = size_GmDocument(d->doc).y == 0; |
4804 | draw_VisBuf(d->visBuf, init_I2(bounds.pos.x, yTop), ySpan_Rect(bounds)); | ||
4805 | /* Text markers. */ | ||
4806 | const iBool isTouchSelecting = (flags_Widget(w) & touchDrag_WidgetFlag) != 0; | 4804 | const iBool isTouchSelecting = (flags_Widget(w) & touchDrag_WidgetFlag) != 0; |
4807 | if (!isEmpty_Range(&d->foundMark) || !isEmpty_Range(&d->selectMark)) { | 4805 | if (!isDocEmpty) { |
4808 | SDL_Renderer *render = renderer_Window(get_Window()); | 4806 | setClip_Paint(&ctx.paint, clipBounds); |
4809 | ctx.firstMarkRect = zero_Rect(); | 4807 | draw_VisBuf(d->visBuf, init_I2(bounds.pos.x, yTop), ySpan_Rect(bounds)); |
4810 | ctx.lastMarkRect = zero_Rect(); | 4808 | /* Text markers. */ |
4811 | SDL_SetRenderDrawBlendMode(render, | 4809 | if (!isEmpty_Range(&d->foundMark) || !isEmpty_Range(&d->selectMark)) { |
4812 | isDark_ColorTheme(colorTheme_App()) ? SDL_BLENDMODE_ADD | 4810 | SDL_Renderer *render = renderer_Window(get_Window()); |
4813 | : SDL_BLENDMODE_BLEND); | 4811 | ctx.firstMarkRect = zero_Rect(); |
4814 | ctx.viewPos = topLeft_Rect(docBounds); | 4812 | ctx.lastMarkRect = zero_Rect(); |
4815 | /* Marker starting outside the visible range? */ | 4813 | SDL_SetRenderDrawBlendMode(render, |
4816 | if (d->visibleRuns.start) { | 4814 | isDark_ColorTheme(colorTheme_App()) ? SDL_BLENDMODE_ADD |
4817 | if (!isEmpty_Range(&d->selectMark) && | 4815 | : SDL_BLENDMODE_BLEND); |
4818 | d->selectMark.start < d->visibleRuns.start->text.start && | 4816 | ctx.viewPos = topLeft_Rect(docBounds); |
4819 | d->selectMark.end > d->visibleRuns.start->text.start) { | 4817 | /* Marker starting outside the visible range? */ |
4820 | ctx.inSelectMark = iTrue; | 4818 | if (d->visibleRuns.start) { |
4819 | if (!isEmpty_Range(&d->selectMark) && | ||
4820 | d->selectMark.start < d->visibleRuns.start->text.start && | ||
4821 | d->selectMark.end > d->visibleRuns.start->text.start) { | ||
4822 | ctx.inSelectMark = iTrue; | ||
4823 | } | ||
4824 | if (isEmpty_Range(&d->foundMark) && | ||
4825 | d->foundMark.start < d->visibleRuns.start->text.start && | ||
4826 | d->foundMark.end > d->visibleRuns.start->text.start) { | ||
4827 | ctx.inFoundMark = iTrue; | ||
4828 | } | ||
4821 | } | 4829 | } |
4822 | if (isEmpty_Range(&d->foundMark) && | 4830 | render_GmDocument(d->doc, vis, drawMark_DrawContext_, &ctx); |
4823 | d->foundMark.start < d->visibleRuns.start->text.start && | 4831 | SDL_SetRenderDrawBlendMode(render, SDL_BLENDMODE_NONE); |
4824 | d->foundMark.end > d->visibleRuns.start->text.start) { | 4832 | /* Selection range pins. */ |
4825 | ctx.inFoundMark = iTrue; | 4833 | if (isTouchSelecting) { |
4834 | drawPin_(&ctx.paint, ctx.firstMarkRect, 0); | ||
4835 | drawPin_(&ctx.paint, ctx.lastMarkRect, 1); | ||
4826 | } | 4836 | } |
4827 | } | 4837 | } |
4828 | render_GmDocument(d->doc, vis, drawMark_DrawContext_, &ctx); | 4838 | drawMedia_DocumentWidget_(d, &ctx.paint); |
4829 | SDL_SetRenderDrawBlendMode(render, SDL_BLENDMODE_NONE); | 4839 | /* Fill the top and bottom, in case the document is short. */ |
4830 | /* Selection range pins. */ | 4840 | if (yTop > top_Rect(bounds)) { |
4831 | if (isTouchSelecting) { | 4841 | fillRect_Paint(&ctx.paint, |
4832 | drawPin_(&ctx.paint, ctx.firstMarkRect, 0); | 4842 | (iRect){ bounds.pos, init_I2(bounds.size.x, yTop - top_Rect(bounds)) }, |
4833 | drawPin_(&ctx.paint, ctx.lastMarkRect, 1); | 4843 | hasSiteBanner_GmDocument(d->doc) ? tmBannerBackground_ColorId |
4834 | } | 4844 | : tmBackground_ColorId); |
4835 | } | 4845 | } |
4836 | drawMedia_DocumentWidget_(d, &ctx.paint); | 4846 | const int yBottom = yTop + size_GmDocument(d->doc).y + 1; |
4837 | /* Fill the top and bottom, in case the document is short. */ | 4847 | if (yBottom < bottom_Rect(bounds)) { |
4838 | if (yTop > top_Rect(bounds)) { | 4848 | fillRect_Paint(&ctx.paint, |
4839 | fillRect_Paint(&ctx.paint, | 4849 | init_Rect(bounds.pos.x, yBottom, bounds.size.x, bottom_Rect(bounds) - yBottom), |
4840 | (iRect){ bounds.pos, init_I2(bounds.size.x, yTop - top_Rect(bounds)) }, | 4850 | tmBackground_ColorId); |
4841 | hasSiteBanner_GmDocument(d->doc) ? tmBannerBackground_ColorId | 4851 | } |
4842 | : tmBackground_ColorId); | 4852 | unsetClip_Paint(&ctx.paint); |
4843 | } | 4853 | drawSideElements_DocumentWidget_(d); |
4844 | const int yBottom = yTop + size_GmDocument(d->doc).y + 1; | 4854 | if (prefs_App()->hoverLink && d->hoverLink) { |
4845 | if (yBottom < bottom_Rect(bounds)) { | 4855 | const int font = uiLabel_FontId; |
4846 | fillRect_Paint(&ctx.paint, | 4856 | const iRangecc linkUrl = range_String(linkUrl_GmDocument(d->doc, d->hoverLink->linkId)); |
4847 | init_Rect(bounds.pos.x, yBottom, bounds.size.x, bottom_Rect(bounds) - yBottom), | 4857 | const iInt2 size = measureRange_Text(font, linkUrl).bounds.size; |
4848 | tmBackground_ColorId); | 4858 | const iRect linkRect = { addY_I2(bottomLeft_Rect(bounds), -size.y), |
4849 | } | 4859 | addX_I2(size, 2 * gap_UI) }; |
4850 | unsetClip_Paint(&ctx.paint); | 4860 | fillRect_Paint(&ctx.paint, linkRect, tmBackground_ColorId); |
4851 | drawSideElements_DocumentWidget_(d); | 4861 | drawRange_Text(font, addX_I2(topLeft_Rect(linkRect), gap_UI), tmParagraph_ColorId, linkUrl); |
4852 | if (prefs_App()->hoverLink && d->hoverLink) { | 4862 | } |
4853 | const int font = uiLabel_FontId; | ||
4854 | const iRangecc linkUrl = range_String(linkUrl_GmDocument(d->doc, d->hoverLink->linkId)); | ||
4855 | const iInt2 size = measureRange_Text(font, linkUrl).bounds.size; | ||
4856 | const iRect linkRect = { addY_I2(bottomLeft_Rect(bounds), -size.y), | ||
4857 | addX_I2(size, 2 * gap_UI) }; | ||
4858 | fillRect_Paint(&ctx.paint, linkRect, tmBackground_ColorId); | ||
4859 | drawRange_Text(font, addX_I2(topLeft_Rect(linkRect), gap_UI), tmParagraph_ColorId, linkUrl); | ||
4860 | } | 4863 | } |
4861 | if (colorTheme_App() == pureWhite_ColorTheme) { | 4864 | if (colorTheme_App() == pureWhite_ColorTheme) { |
4862 | drawHLine_Paint(&ctx.paint, topLeft_Rect(bounds), width_Rect(bounds), uiSeparator_ColorId); | 4865 | drawHLine_Paint(&ctx.paint, topLeft_Rect(bounds), width_Rect(bounds), uiSeparator_ColorId); |