summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-09-17 09:21:01 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-09-17 09:21:01 +0300
commit9a7438c82f6dfc0605f28207648c4cdde7d98f1f (patch)
treec1cf47b9e299caa160ede40dcf99ef92383b3487
parent596c61c125ab9c796d4294b1762b65119c65f1d2 (diff)
InputWidget: Cleanup
-rw-r--r--src/ui/inputwidget.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index c9c170cd..b214d730 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -1632,10 +1632,10 @@ static enum iEventResult processTouchEvents_InputWidget_(iInputWidget *d, const
1632 d->tapStartTime = SDL_GetTicks(); 1632 d->tapStartTime = SDL_GetTicks();
1633 const int tapDist = dist_I2(latestPosition_Touch(), d->lastTapPos); 1633 const int tapDist = dist_I2(latestPosition_Touch(), d->lastTapPos);
1634 d->lastTapPos = latestPosition_Touch(); 1634 d->lastTapPos = latestPosition_Touch();
1635 printf("[%p] tap start time: %u (%u) %d\n", w, d->tapStartTime, d->tapStartTime - d->lastTapTime, tapDist); 1635// printf("[%p] tap start time: %u (%u) %d\n", w, d->tapStartTime, d->tapStartTime - d->lastTapTime, tapDist);
1636 if (d->tapStartTime - d->lastTapTime < 400 && tapDist < gap_UI * 4) { 1636 if (d->tapStartTime - d->lastTapTime < 400 && tapDist < gap_UI * 4) {
1637 d->tapCount++; 1637 d->tapCount++;
1638 printf("[%p] >> tap count: %d\n", w, d->tapCount); 1638// printf("[%p] >> tap count: %d\n", w, d->tapCount);
1639 } 1639 }
1640 else { 1640 else {
1641 d->tapCount = 0; 1641 d->tapCount = 0;
@@ -1648,11 +1648,11 @@ static enum iEventResult processTouchEvents_InputWidget_(iInputWidget *d, const
1648 indexToCursor_InputWidget_(d, d->mark.end)) 1648 indexToCursor_InputWidget_(d, d->mark.end))
1649 }; 1649 };
1650 if (dist[0] < dist[1]) { 1650 if (dist[0] < dist[1]) {
1651 printf("[%p] begin marker start drag\n", w); 1651// printf("[%p] begin marker start drag\n", w);
1652 d->inFlags |= dragMarkerStart_InputWidgetFlag; 1652 d->inFlags |= dragMarkerStart_InputWidgetFlag;
1653 } 1653 }
1654 else { 1654 else {
1655 printf("[%p] begin marker end drag\n", w); 1655// printf("[%p] begin marker end drag\n", w);
1656 d->inFlags |= dragMarkerEnd_InputWidgetFlag; 1656 d->inFlags |= dragMarkerEnd_InputWidgetFlag;
1657 } 1657 }
1658 d->inFlags |= isMarking_InputWidgetFlag; 1658 d->inFlags |= isMarking_InputWidgetFlag;
@@ -1660,9 +1660,9 @@ static enum iEventResult processTouchEvents_InputWidget_(iInputWidget *d, const
1660 } 1660 }
1661 else { 1661 else {
1662 const int dist = distanceToPos_InputWidget_(d, latestPosition_Touch(), d->cursor); 1662 const int dist = distanceToPos_InputWidget_(d, latestPosition_Touch(), d->cursor);
1663 printf("[%p] tap dist: %d\n", w, dist); 1663// printf("[%p] tap dist: %d\n", w, dist);
1664 if (dist < gap_UI * 10) { 1664 if (dist < gap_UI * 10) {
1665 printf("[%p] begin cursor drag\n", w); 1665// printf("[%p] begin cursor drag\n", w);
1666 setFlags_Widget(w, touchDrag_WidgetFlag, iTrue); 1666 setFlags_Widget(w, touchDrag_WidgetFlag, iTrue);
1667 d->inFlags |= dragCursor_InputWidgetFlag; 1667 d->inFlags |= dragCursor_InputWidgetFlag;
1668// d->inFlags |= touchBehavior_InputWidgetFlag; 1668// d->inFlags |= touchBehavior_InputWidgetFlag;
@@ -1685,16 +1685,16 @@ static enum iEventResult processTouchEvents_InputWidget_(iInputWidget *d, const
1685 const iInt2 relClick = sub_I2(pos_Click(&d->click), 1685 const iInt2 relClick = sub_I2(pos_Click(&d->click),
1686 topLeft_Rect(contentBounds_InputWidget_(d))); 1686 topLeft_Rect(contentBounds_InputWidget_(d)));
1687 if (dist_I2(curPos, relClick) < gap_UI * 8) { 1687 if (dist_I2(curPos, relClick) < gap_UI * 8) {
1688 printf("tap on cursor!\n"); 1688// printf("tap on cursor!\n");
1689 setFlags_Widget(w, touchDrag_WidgetFlag, iTrue); 1689 setFlags_Widget(w, touchDrag_WidgetFlag, iTrue);
1690 d->inFlags |= touchBehavior_InputWidgetFlag; 1690 d->inFlags |= touchBehavior_InputWidgetFlag;
1691 printf("[Input] begin cursor drag\n"); 1691// printf("[Input] begin cursor drag\n");
1692 setMouseGrab_Widget(w); 1692 setMouseGrab_Widget(w);
1693 return iTrue; 1693 return iTrue;
1694 } 1694 }
1695 } 1695 }
1696 else if (ev->motion.x > 0 && ev->motion.y > 0) { 1696 else if (ev->motion.x > 0 && ev->motion.y > 0) {
1697 printf("[Input] cursor being dragged\n"); 1697// printf("[Input] cursor being dragged\n");
1698 iRect bounds = shrunk_Rect(contentBounds_InputWidget_(d), one_I2()); 1698 iRect bounds = shrunk_Rect(contentBounds_InputWidget_(d), one_I2());
1699 bounds.size.y = iMini(numWrapLines_InputWidget_(d), d->maxWrapLines) * lineHeight_Text(d->font) - 2; 1699 bounds.size.y = iMini(numWrapLines_InputWidget_(d), d->maxWrapLines) * lineHeight_Text(d->font) - 2;
1700 iInt2 mpos = init_I2(ev->motion.x, ev->motion.y); 1700 iInt2 mpos = init_I2(ev->motion.x, ev->motion.y);
@@ -1711,7 +1711,7 @@ static enum iEventResult processTouchEvents_InputWidget_(iInputWidget *d, const
1711 d->inFlags &= ~touchBehavior_InputWidgetFlag; 1711 d->inFlags &= ~touchBehavior_InputWidgetFlag;
1712 setFlags_Widget(w, touchDrag_WidgetFlag, iFalse); 1712 setFlags_Widget(w, touchDrag_WidgetFlag, iFalse);
1713 setMouseGrab_Widget(NULL); 1713 setMouseGrab_Widget(NULL);
1714 printf("[Input] touch ends\n"); 1714// printf("[Input] touch ends\n");
1715 return iFalse; 1715 return iFalse;
1716 } 1716 }
1717 } 1717 }
@@ -1741,7 +1741,7 @@ static enum iEventResult processTouchEvents_InputWidget_(iInputWidget *d, const
1741 case none_ClickResult: 1741 case none_ClickResult:
1742 break; 1742 break;
1743 case started_ClickResult: { 1743 case started_ClickResult: {
1744 printf("[%p] started\n", w); 1744// printf("[%p] started\n", w);
1745 /* 1745 /*
1746 const iInt2 curPos = relativeCursorCoord_InputWidget_(d); 1746 const iInt2 curPos = relativeCursorCoord_InputWidget_(d);
1747 const iInt2 relClick = sub_I2(pos_Click(&d->click), 1747 const iInt2 relClick = sub_I2(pos_Click(&d->click),
@@ -1756,7 +1756,7 @@ static enum iEventResult processTouchEvents_InputWidget_(iInputWidget *d, const
1756 return true_EventResult; 1756 return true_EventResult;
1757 } 1757 }
1758 case drag_ClickResult: 1758 case drag_ClickResult:
1759 printf("[%p] drag %d,%d\n", w, pos_Click(&d->click).x, pos_Click(&d->click).y); 1759// printf("[%p] drag %d,%d\n", w, pos_Click(&d->click).x, pos_Click(&d->click).y);
1760 if (d->inFlags & dragCursor_InputWidgetFlag) { 1760 if (d->inFlags & dragCursor_InputWidgetFlag) {
1761 iZap(d->mark); 1761 iZap(d->mark);
1762 d->cursor = touchCoordCursor_InputWidget_(d, pos_Click(&d->click)); 1762 d->cursor = touchCoordCursor_InputWidget_(d, pos_Click(&d->click));
@@ -1777,10 +1777,10 @@ static enum iEventResult processTouchEvents_InputWidget_(iInputWidget *d, const
1777// setFlags_Widget(w, touchDrag_WidgetFlag, iFalse); 1777// setFlags_Widget(w, touchDrag_WidgetFlag, iFalse);
1778// return true_EventResult; 1778// return true_EventResult;
1779 case finished_ClickResult: 1779 case finished_ClickResult:
1780 case aborted_ClickResult: 1780 case aborted_ClickResult: {
1781 printf("[%p] ended\n", w); 1781// printf("[%p] ended\n", w);
1782 uint32_t tapElapsed = SDL_GetTicks() - d->tapStartTime; 1782 uint32_t tapElapsed = SDL_GetTicks() - d->tapStartTime;
1783 printf("tapElapsed: %u\n", tapElapsed); 1783// printf("tapElapsed: %u\n", tapElapsed);
1784 if (!isFocused_Widget(w)) { 1784 if (!isFocused_Widget(w)) {
1785 setFocus_Widget(w); 1785 setFocus_Widget(w);
1786 d->lastTapPos = latestPosition_Touch(); 1786 d->lastTapPos = latestPosition_Touch();
@@ -1811,7 +1811,7 @@ static enum iEventResult processTouchEvents_InputWidget_(iInputWidget *d, const
1811 } 1811 }
1812 if (d->inFlags & (dragCursor_InputWidgetFlag | dragMarkerStart_InputWidgetFlag | 1812 if (d->inFlags & (dragCursor_InputWidgetFlag | dragMarkerStart_InputWidgetFlag |
1813 dragMarkerEnd_InputWidgetFlag)) { 1813 dragMarkerEnd_InputWidgetFlag)) {
1814 printf("[%p] finished cursor/marker drag\n", w); 1814// printf("[%p] finished cursor/marker drag\n", w);
1815 d->inFlags &= ~(dragCursor_InputWidgetFlag | 1815 d->inFlags &= ~(dragCursor_InputWidgetFlag |
1816 dragMarkerStart_InputWidgetFlag | 1816 dragMarkerStart_InputWidgetFlag |
1817 dragMarkerEnd_InputWidgetFlag); 1817 dragMarkerEnd_InputWidgetFlag);
@@ -1842,6 +1842,7 @@ static enum iEventResult processTouchEvents_InputWidget_(iInputWidget *d, const
1842 } 1842 }
1843#endif 1843#endif
1844 return true_EventResult; 1844 return true_EventResult;
1845 }
1845 } 1846 }
1846#endif 1847#endif
1847// if ((ev->type == SDL_MOUSEBUTTONDOWN || ev->type == SDL_MOUSEBUTTONUP) && 1848// if ((ev->type == SDL_MOUSEBUTTONDOWN || ev->type == SDL_MOUSEBUTTONUP) &&