diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-12 23:22:19 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-12 23:22:19 +0300 |
commit | a7806a4cd61e8125b9ce095515418e84f34256c1 (patch) | |
tree | 932670b156b5d5d4cea382cb3518b91847958de8 /src/ui/documentwidget.c | |
parent | 6480b31451f919bd4f4c08c124fd47621c39dd8e (diff) |
Cleanup
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r-- | src/ui/documentwidget.c | 172 |
1 files changed, 51 insertions, 121 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 2dd50e5b..9b6ad509 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -128,42 +128,6 @@ void deserialize_Model(iModel *d, iStream *ins) { | |||
128 | 128 | ||
129 | iDefineTypeConstruction(Model) | 129 | iDefineTypeConstruction(Model) |
130 | 130 | ||
131 | #if 0 | ||
132 | /*----------------------------------------------------------------------------------------------*/ | ||
133 | |||
134 | iDeclareType(VisBuffer) | ||
135 | iDeclareTypeConstruction(VisBuffer) | ||
136 | |||
137 | struct Impl_VisBuffer { | ||
138 | SDL_Texture * texture[2]; | ||
139 | int index; | ||
140 | iInt2 size; | ||
141 | iRangei validRange; | ||
142 | }; | ||
143 | |||
144 | void init_VisBuffer(iVisBuffer *d) { | ||
145 | iZap(*d); | ||
146 | } | ||
147 | |||
148 | void deinit_VisBuffer(iVisBuffer *d) { | ||
149 | iForIndices(i, d->texture) { | ||
150 | if (d->texture[i]) { | ||
151 | SDL_DestroyTexture(d->texture[i]); | ||
152 | } | ||
153 | } | ||
154 | } | ||
155 | |||
156 | void dealloc_VisBuffer(iVisBuffer *d) { | ||
157 | d->size = zero_I2(); | ||
158 | iZap(d->validRange); | ||
159 | iForIndices(i, d->texture) { | ||
160 | SDL_DestroyTexture(d->texture[i]); | ||
161 | d->texture[i] = NULL; | ||
162 | } | ||
163 | } | ||
164 | |||
165 | iDefineTypeConstruction(VisBuffer) | ||
166 | #endif | ||
167 | /*----------------------------------------------------------------------------------------------*/ | 131 | /*----------------------------------------------------------------------------------------------*/ |
168 | 132 | ||
169 | static const int smoothSpeed_DocumentWidget_ = 120; /* unit: gap_Text per second */ | 133 | static const int smoothSpeed_DocumentWidget_ = 120; /* unit: gap_Text per second */ |
@@ -313,16 +277,6 @@ static int forceBreakWidth_DocumentWidget_(const iDocumentWidget *d) { | |||
313 | return 0; | 277 | return 0; |
314 | } | 278 | } |
315 | 279 | ||
316 | iLocalDef int documentToWindowY_DocumentWidget_(const iDocumentWidget *d, int docY) { | ||
317 | return docY - d->scrollY + documentBounds_DocumentWidget_(d).pos.y; | ||
318 | } | ||
319 | |||
320 | #if 0 | ||
321 | iLocalDef int windowToDocumentY_DocumentWidget_(const iDocumentWidget *d, int localY) { | ||
322 | return localY + d->scrollY - documentBounds_DocumentWidget_(d).pos.y; | ||
323 | } | ||
324 | #endif | ||
325 | |||
326 | static iInt2 documentPos_DocumentWidget_(const iDocumentWidget *d, iInt2 pos) { | 280 | static iInt2 documentPos_DocumentWidget_(const iDocumentWidget *d, iInt2 pos) { |
327 | return addY_I2(sub_I2(pos, topLeft_Rect(documentBounds_DocumentWidget_(d))), d->scrollY); | 281 | return addY_I2(sub_I2(pos, topLeft_Rect(documentBounds_DocumentWidget_(d))), d->scrollY); |
328 | } | 282 | } |
@@ -1585,15 +1539,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
1585 | 1539 | ||
1586 | iDeclareType(DrawContext) | 1540 | iDeclareType(DrawContext) |
1587 | 1541 | ||
1588 | #if 0 | ||
1589 | enum iDrawRunPass { | ||
1590 | static_DrawRunPass, | ||
1591 | dynamic_DrawRunPass, | ||
1592 | }; | ||
1593 | #endif | ||
1594 | |||
1595 | struct Impl_DrawContext { | 1542 | struct Impl_DrawContext { |
1596 | // enum iDrawRunPass pass; | ||
1597 | const iDocumentWidget *widget; | 1543 | const iDocumentWidget *widget; |
1598 | iRect widgetBounds; | 1544 | iRect widgetBounds; |
1599 | iInt2 viewPos; /* document area origin */ | 1545 | iInt2 viewPos; /* document area origin */ |
@@ -1644,35 +1590,21 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
1644 | iDrawContext *d = context; | 1590 | iDrawContext *d = context; |
1645 | const iInt2 origin = d->viewPos; | 1591 | const iInt2 origin = d->viewPos; |
1646 | if (run->imageId) { | 1592 | if (run->imageId) { |
1647 | /*if (d->pass == static_DrawRunPass)*/ { | 1593 | SDL_Texture *tex = imageTexture_GmDocument(d->widget->doc, run->imageId); |
1648 | SDL_Texture *tex = imageTexture_GmDocument(d->widget->doc, run->imageId); | 1594 | if (tex) { |
1649 | if (tex) { | 1595 | const iRect dst = moved_Rect(run->visBounds, origin); |
1650 | const iRect dst = moved_Rect(run->visBounds, origin); | 1596 | SDL_RenderCopy(d->paint.dst->render, tex, NULL, |
1651 | SDL_RenderCopy(d->paint.dst->render, tex, NULL, | 1597 | &(SDL_Rect){ dst.pos.x, dst.pos.y, dst.size.x, dst.size.y }); |
1652 | &(SDL_Rect){ dst.pos.x, dst.pos.y, dst.size.x, dst.size.y }); | ||
1653 | } | ||
1654 | } | 1598 | } |
1655 | return; | 1599 | return; |
1656 | } | 1600 | } |
1657 | enum iColorId fg = run->color; | 1601 | enum iColorId fg = run->color; |
1658 | const iGmDocument *doc = d->widget->doc; | 1602 | const iGmDocument *doc = d->widget->doc; |
1659 | /* Matches the current drawing pass? */ | 1603 | const iBool isHover = |
1660 | // const iBool isDynamic = (run->linkId && ~run->flags & decoration_GmRunFlag); | ||
1661 | // if (isDynamic ^ (d->pass == dynamic_DrawRunPass)) { | ||
1662 | // return; | ||
1663 | // } | ||
1664 | const iBool isHover = | ||
1665 | (run->linkId && d->widget->hoverLink && run->linkId == d->widget->hoverLink->linkId && | 1604 | (run->linkId && d->widget->hoverLink && run->linkId == d->widget->hoverLink->linkId && |
1666 | ~run->flags & decoration_GmRunFlag); | 1605 | ~run->flags & decoration_GmRunFlag); |
1667 | const iInt2 visPos = add_I2(run->visBounds.pos, origin); | 1606 | const iInt2 visPos = add_I2(run->visBounds.pos, origin); |
1668 | fillRect_Paint(&d->paint, | 1607 | fillRect_Paint(&d->paint, (iRect){ visPos, run->visBounds.size }, tmBackground_ColorId); |
1669 | (iRect){ visPos, | ||
1670 | /* Links have additional hover info on the right side. */ | ||
1671 | // init_I2(run->linkId && ~run->flags & decoration_GmRunFlag | ||
1672 | // ? d->widgetBounds.size.x - visPos.x : | ||
1673 | init_I2(run->visBounds.size.x, | ||
1674 | run->visBounds.size.y) }, | ||
1675 | tmBackground_ColorId); | ||
1676 | if (run->linkId && ~run->flags & decoration_GmRunFlag) { | 1608 | if (run->linkId && ~run->flags & decoration_GmRunFlag) { |
1677 | fg = linkColor_GmDocument(doc, run->linkId, isHover ? textHover_GmLinkPart : text_GmLinkPart); | 1609 | fg = linkColor_GmDocument(doc, run->linkId, isHover ? textHover_GmLinkPart : text_GmLinkPart); |
1678 | if (linkFlags_GmDocument(doc, run->linkId) & content_GmLinkFlag) { | 1610 | if (linkFlags_GmDocument(doc, run->linkId) & content_GmLinkFlag) { |
@@ -1680,42 +1612,40 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
1680 | } | 1612 | } |
1681 | } | 1613 | } |
1682 | if (run->flags & siteBanner_GmRunFlag) { | 1614 | if (run->flags & siteBanner_GmRunFlag) { |
1683 | /*if (d->pass == static_DrawRunPass)*/ { | 1615 | /* Draw the site banner. */ |
1684 | /* Draw the site banner. */ | 1616 | fillRect_Paint( |
1685 | fillRect_Paint( | 1617 | &d->paint, |
1686 | &d->paint, | 1618 | initCorners_Rect(topLeft_Rect(d->widgetBounds), |
1687 | initCorners_Rect(topLeft_Rect(d->widgetBounds), | 1619 | init_I2(right_Rect(bounds_Widget(constAs_Widget(d->widget))), |
1688 | init_I2(right_Rect(bounds_Widget(constAs_Widget(d->widget))), | 1620 | visPos.y + height_Rect(run->visBounds))), |
1689 | visPos.y + height_Rect(run->visBounds))), | 1621 | tmBannerBackground_ColorId); |
1690 | tmBannerBackground_ColorId); | 1622 | const iChar icon = siteIcon_GmDocument(doc); |
1691 | const iChar icon = siteIcon_GmDocument(doc); | 1623 | iString bannerText; |
1692 | iString bannerText; | 1624 | init_String(&bannerText); |
1693 | init_String(&bannerText); | 1625 | iInt2 bpos = add_I2(visPos, init_I2(0, lineHeight_Text(banner_FontId) / 2)); |
1694 | iInt2 bpos = add_I2(visPos, init_I2(0, lineHeight_Text(banner_FontId) / 2)); | 1626 | if (icon) { |
1695 | if (icon) { | 1627 | // appendChar_String(&bannerText, 0x2b24); // icon); |
1696 | // appendChar_String(&bannerText, 0x2b24); // icon); | 1628 | // const iRect iconRect = visualBounds_Text(hugeBold_FontId, range_String(&bannerText)); |
1697 | // const iRect iconRect = visualBounds_Text(hugeBold_FontId, range_String(&bannerText)); | 1629 | // drawRange_Text(hugeBold_FontId, /*run->font,*/ |
1698 | // drawRange_Text(hugeBold_FontId, /*run->font,*/ | 1630 | // addY_I2(bpos, -mid_Rect(iconRect).y + lineHeight_Text(run->font) / 2), |
1699 | // addY_I2(bpos, -mid_Rect(iconRect).y + lineHeight_Text(run->font) / 2), | 1631 | // tmBannerIcon_ColorId, |
1700 | // tmBannerIcon_ColorId, | 1632 | // range_String(&bannerText)); |
1701 | // range_String(&bannerText)); | 1633 | // clear_String(&bannerText); |
1702 | // clear_String(&bannerText); | 1634 | appendChar_String(&bannerText, icon); |
1703 | appendChar_String(&bannerText, icon); | 1635 | const iRect iconRect = visualBounds_Text(run->font, range_String(&bannerText)); |
1704 | const iRect iconRect = visualBounds_Text(run->font, range_String(&bannerText)); | 1636 | drawRange_Text( |
1705 | drawRange_Text( | 1637 | run->font, |
1706 | run->font, | 1638 | addY_I2(bpos, -mid_Rect(iconRect).y + lineHeight_Text(run->font) / 2), |
1707 | addY_I2(bpos, -mid_Rect(iconRect).y + lineHeight_Text(run->font) / 2), | 1639 | tmBannerIcon_ColorId, |
1708 | tmBannerIcon_ColorId, | 1640 | range_String(&bannerText)); |
1709 | range_String(&bannerText)); | 1641 | bpos.x += right_Rect(iconRect) + 3 * gap_Text; |
1710 | bpos.x += right_Rect(iconRect) + 3 * gap_Text; | 1642 | } |
1711 | } | 1643 | drawRange_Text(run->font, |
1712 | drawRange_Text(run->font, | 1644 | bpos, |
1713 | bpos, | 1645 | tmBannerTitle_ColorId, |
1714 | tmBannerTitle_ColorId, | 1646 | isEmpty_String(d->widget->titleUser) ? run->text |
1715 | isEmpty_String(d->widget->titleUser) ? run->text | 1647 | : range_String(d->widget->titleUser)); |
1716 | : range_String(d->widget->titleUser)); | 1648 | deinit_String(&bannerText); |
1717 | deinit_String(&bannerText); | ||
1718 | } | ||
1719 | } | 1649 | } |
1720 | else { | 1650 | else { |
1721 | if (d->showLinkNumbers && run->linkId && run->flags & decoration_GmRunFlag) { | 1651 | if (d->showLinkNumbers && run->linkId && run->flags & decoration_GmRunFlag) { |
@@ -1734,7 +1664,7 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
1734 | runDrawn:; | 1664 | runDrawn:; |
1735 | } | 1665 | } |
1736 | /* Presentation of links. */ | 1666 | /* Presentation of links. */ |
1737 | if (run->linkId && ~run->flags & decoration_GmRunFlag/* && d->pass == dynamic_DrawRunPass*/) { | 1667 | if (run->linkId && ~run->flags & decoration_GmRunFlag) { |
1738 | const int metaFont = paragraph_FontId; | 1668 | const int metaFont = paragraph_FontId; |
1739 | /* TODO: Show status of an ongoing media request. */ | 1669 | /* TODO: Show status of an ongoing media request. */ |
1740 | const int flags = linkFlags_GmDocument(doc, run->linkId); | 1670 | const int flags = linkFlags_GmDocument(doc, run->linkId); |
@@ -1908,6 +1838,15 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) { | |||
1908 | setClip_Paint(&ctx.paint, bounds); | 1838 | setClip_Paint(&ctx.paint, bounds); |
1909 | const int yTop = docBounds.pos.y - d->scrollY; | 1839 | const int yTop = docBounds.pos.y - d->scrollY; |
1910 | draw_VisBuf(visBuf, init_I2(bounds.pos.x, yTop)); | 1840 | draw_VisBuf(visBuf, init_I2(bounds.pos.x, yTop)); |
1841 | /* Text markers. */ | ||
1842 | if (!isEmpty_Range(&d->foundMark) || !isEmpty_Range(&d->selectMark)) { | ||
1843 | SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), | ||
1844 | isDark_ColorTheme(colorTheme_App()) ? SDL_BLENDMODE_ADD | ||
1845 | : SDL_BLENDMODE_BLEND); | ||
1846 | ctx.viewPos = topLeft_Rect(docBounds); | ||
1847 | render_GmDocument(d->doc, vis, drawMark_DrawContext_, &ctx); | ||
1848 | SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_NONE); | ||
1849 | } | ||
1911 | unsetClip_Paint(&ctx.paint); | 1850 | unsetClip_Paint(&ctx.paint); |
1912 | /* Fill the top and bottom, in case the document is short. */ | 1851 | /* Fill the top and bottom, in case the document is short. */ |
1913 | if (yTop > top_Rect(bounds)) { | 1852 | if (yTop > top_Rect(bounds)) { |
@@ -1922,15 +1861,6 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) { | |||
1922 | init_Rect(bounds.pos.x, yBottom, bounds.size.x, bottom_Rect(bounds) - yBottom), | 1861 | init_Rect(bounds.pos.x, yBottom, bounds.size.x, bottom_Rect(bounds) - yBottom), |
1923 | tmBackground_ColorId); | 1862 | tmBackground_ColorId); |
1924 | } | 1863 | } |
1925 | /* Text markers. */ | ||
1926 | if (!isEmpty_Range(&d->foundMark) || !isEmpty_Range(&d->selectMark)) { | ||
1927 | SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), | ||
1928 | isDark_ColorTheme(colorTheme_App()) ? SDL_BLENDMODE_ADD | ||
1929 | : SDL_BLENDMODE_BLEND); | ||
1930 | ctx.viewPos = topLeft_Rect(docBounds); | ||
1931 | render_GmDocument(d->doc, vis, drawMark_DrawContext_, &ctx); | ||
1932 | SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_NONE); | ||
1933 | } | ||
1934 | draw_Widget(w); | 1864 | draw_Widget(w); |
1935 | } | 1865 | } |
1936 | 1866 | ||