diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/documentwidget.c | 47 | ||||
-rw-r--r-- | src/ui/window.c | 6 |
2 files changed, 47 insertions, 6 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 64172a08..9df88068 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -199,6 +199,7 @@ enum iDocumentWidgetFlag { | |||
199 | centerVertically_DocumentWidgetFlag = iBit(6), | 199 | centerVertically_DocumentWidgetFlag = iBit(6), |
200 | selectWords_DocumentWidgetFlag = iBit(7), | 200 | selectWords_DocumentWidgetFlag = iBit(7), |
201 | selectLines_DocumentWidgetFlag = iBit(8), | 201 | selectLines_DocumentWidgetFlag = iBit(8), |
202 | pinchZoom_DocumentWidgetFlag = iBit(9), | ||
202 | }; | 203 | }; |
203 | 204 | ||
204 | enum iDocumentLinkOrdinalMode { | 205 | enum iDocumentLinkOrdinalMode { |
@@ -263,6 +264,8 @@ struct Impl_DocumentWidget { | |||
263 | iDrawBufs * drawBufs; /* dynamic state for drawing */ | 264 | iDrawBufs * drawBufs; /* dynamic state for drawing */ |
264 | iTranslation * translation; | 265 | iTranslation * translation; |
265 | iWidget * phoneToolbar; | 266 | iWidget * phoneToolbar; |
267 | int pinchZoomInitial; | ||
268 | int pinchZoomPosted; | ||
266 | }; | 269 | }; |
267 | 270 | ||
268 | iDefineObjectConstruction(DocumentWidget) | 271 | iDefineObjectConstruction(DocumentWidget) |
@@ -1663,6 +1666,37 @@ static iBool updateDocumentWidthRetainingScrollPosition_DocumentWidget_(iDocumen | |||
1663 | return iTrue; | 1666 | return iTrue; |
1664 | } | 1667 | } |
1665 | 1668 | ||
1669 | static iBool handlePinch_DocumentWidget_(iDocumentWidget *d, const char *cmd) { | ||
1670 | if (equal_Command(cmd, "pinch.began")) { | ||
1671 | d->pinchZoomInitial = d->pinchZoomPosted = prefs_App()->zoomPercent; | ||
1672 | d->flags |= pinchZoom_DocumentWidgetFlag; | ||
1673 | refresh_Widget(d); | ||
1674 | } | ||
1675 | else if (equal_Command(cmd, "pinch.moved")) { | ||
1676 | const float rel = argf_Command(cmd); | ||
1677 | int zoom = iClamp(iRound(d->pinchZoomInitial * rel / 5.0f) * 5, 50, 200); | ||
1678 | /* Snap to 100%. */ | ||
1679 | if (zoom > 90 && zoom < 110) { | ||
1680 | zoom = 100; | ||
1681 | } | ||
1682 | else if (zoom > 100) { | ||
1683 | zoom = iMax(100, zoom - 10); | ||
1684 | } | ||
1685 | else { | ||
1686 | zoom = iMin(100, zoom + 10); | ||
1687 | } | ||
1688 | if (d->pinchZoomPosted != zoom) { | ||
1689 | d->pinchZoomPosted = zoom; | ||
1690 | postCommandf_App("zoom.set arg:%d", zoom); | ||
1691 | } | ||
1692 | } | ||
1693 | else if (equal_Command(cmd, "pinch.ended")) { | ||
1694 | d->flags &= ~pinchZoom_DocumentWidgetFlag; | ||
1695 | refresh_Widget(d); | ||
1696 | } | ||
1697 | return iTrue; | ||
1698 | } | ||
1699 | |||
1666 | static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) { | 1700 | static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) { |
1667 | iWidget *w = as_Widget(d); | 1701 | iWidget *w = as_Widget(d); |
1668 | if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed")) { | 1702 | if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed")) { |
@@ -2257,6 +2291,9 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
2257 | else if (equal_Command(cmd, "document.autoreload.set") && document_App() == d) { | 2291 | else if (equal_Command(cmd, "document.autoreload.set") && document_App() == d) { |
2258 | d->mod.reloadInterval = arg_Command(cmd); | 2292 | d->mod.reloadInterval = arg_Command(cmd); |
2259 | } | 2293 | } |
2294 | else if (startsWith_CStr(cmd, "pinch.") && document_Command(cmd) == d) { | ||
2295 | return handlePinch_DocumentWidget_(d, cmd); | ||
2296 | } | ||
2260 | return iFalse; | 2297 | return iFalse; |
2261 | } | 2298 | } |
2262 | 2299 | ||
@@ -3593,6 +3630,16 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) { | |||
3593 | setOpacity_Text(1.0f); | 3630 | setOpacity_Text(1.0f); |
3594 | } | 3631 | } |
3595 | } | 3632 | } |
3633 | /* Pinch zoom indicator. */ | ||
3634 | if (d->flags & pinchZoom_DocumentWidgetFlag) { | ||
3635 | const int font = defaultLargeBold_FontId; | ||
3636 | const int height = lineHeight_Text(font) * 2; | ||
3637 | const iInt2 size = init_I2(height * 2, height); | ||
3638 | const iRect rect = { sub_I2(mid_Rect(bounds), divi_I2(size, 2)), size }; | ||
3639 | fillRect_Paint(&ctx.paint, rect, uiTextAction_ColorId); | ||
3640 | drawCentered_Text(font, bounds, iFalse, uiBackground_ColorId, "%d %%", | ||
3641 | d->pinchZoomPosted); | ||
3642 | } | ||
3596 | } | 3643 | } |
3597 | 3644 | ||
3598 | /*----------------------------------------------------------------------------------------------*/ | 3645 | /*----------------------------------------------------------------------------------------------*/ |
diff --git a/src/ui/window.c b/src/ui/window.c index aa854c72..715f5d5f 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -221,9 +221,6 @@ static const iMenuItem tabletNavMenuItems_[] = { | |||
221 | { magnifyingGlass_Icon " ${menu.find}", 0, 0, "focus.set id:find.input" }, | 221 | { magnifyingGlass_Icon " ${menu.find}", 0, 0, "focus.set id:find.input" }, |
222 | { leftHalf_Icon " ${menu.sidebar.left}", SDLK_l, KMOD_PRIMARY | KMOD_SHIFT, "sidebar.toggle" }, | 222 | { leftHalf_Icon " ${menu.sidebar.left}", SDLK_l, KMOD_PRIMARY | KMOD_SHIFT, "sidebar.toggle" }, |
223 | { rightHalf_Icon " ${menu.sidebar.right}", SDLK_p, KMOD_PRIMARY | KMOD_SHIFT, "sidebar2.toggle" }, | 223 | { rightHalf_Icon " ${menu.sidebar.right}", SDLK_p, KMOD_PRIMARY | KMOD_SHIFT, "sidebar2.toggle" }, |
224 | { "${menu.zoom.in}", SDLK_EQUALS, KMOD_PRIMARY, "zoom.delta arg:10" }, | ||
225 | { "${menu.zoom.out}", SDLK_MINUS, KMOD_PRIMARY, "zoom.delta arg:-10" }, | ||
226 | { "${menu.zoom.reset}", SDLK_0, KMOD_PRIMARY, "zoom.set arg:100" }, | ||
227 | { "---", 0, 0, NULL }, | 224 | { "---", 0, 0, NULL }, |
228 | { book_Icon " ${menu.bookmarks.list}", 0, 0, "!open url:about:bookmarks" }, | 225 | { book_Icon " ${menu.bookmarks.list}", 0, 0, "!open url:about:bookmarks" }, |
229 | { "${menu.bookmarks.bytag}", 0, 0, "!open url:about:bookmarks?tags" }, | 226 | { "${menu.bookmarks.bytag}", 0, 0, "!open url:about:bookmarks?tags" }, |
@@ -241,9 +238,6 @@ static const iMenuItem phoneNavMenuItems_[] = { | |||
241 | { "---", 0, 0, NULL }, | 238 | { "---", 0, 0, NULL }, |
242 | { magnifyingGlass_Icon " ${menu.find}", 0, 0, "focus.set id:find.input" }, | 239 | { magnifyingGlass_Icon " ${menu.find}", 0, 0, "focus.set id:find.input" }, |
243 | { leftHalf_Icon " ${menu.sidebar}", SDLK_l, KMOD_PRIMARY | KMOD_SHIFT, "sidebar.toggle" }, | 240 | { leftHalf_Icon " ${menu.sidebar}", SDLK_l, KMOD_PRIMARY | KMOD_SHIFT, "sidebar.toggle" }, |
244 | { "${menu.zoom.in}", SDLK_EQUALS, KMOD_PRIMARY, "zoom.delta arg:10" }, | ||
245 | { "${menu.zoom.out}", SDLK_MINUS, KMOD_PRIMARY, "zoom.delta arg:-10" }, | ||
246 | { "${menu.zoom.reset}", SDLK_0, KMOD_PRIMARY, "zoom.set arg:100" }, | ||
247 | { "---", 0, 0, NULL }, | 241 | { "---", 0, 0, NULL }, |
248 | { book_Icon " ${menu.bookmarks.list}", 0, 0, "!open url:about:bookmarks" }, | 242 | { book_Icon " ${menu.bookmarks.list}", 0, 0, "!open url:about:bookmarks" }, |
249 | { "${menu.feeds.entrylist}", 0, 0, "!open url:about:feeds" }, | 243 | { "${menu.feeds.entrylist}", 0, 0, "!open url:about:feeds" }, |