diff --git a/android/debug.sh b/android/debug.sh index 08d8ab1e2..ce8ee01af 100755 --- a/android/debug.sh +++ b/android/debug.sh @@ -55,6 +55,7 @@ lldb_server=${LLDB_SERVER:-$default_lldb_server} lldb_server_port=${LLDB_SERVER_PORT:-9998} jdb_port=${JDB_PORT:-13456} lldb_client=${LLDB_CLIENT:-$default_lldb_client} +meson=${MESON:-meson} adb=${ADB:-adb} jdb=${JDB:-jdb} @@ -113,6 +114,11 @@ Naturally, replace bagelsbagels with an appropriate password. HELP exit 1 fi + >&2 echo "[+] meson compiling android/$app_exe.apk" + if ! $meson compile sign-apk; then + >&2 echo "[-] failed" + return 1 + fi >&2 echo "[+] adb installing android/$app_exe.apk" if ! $adb install android/$app_exe.apk; then >&2 echo "[-] failed" diff --git a/src/Misc.h b/src/Misc.h index 5faa307fb..615cd57a4 100644 --- a/src/Misc.h +++ b/src/Misc.h @@ -51,6 +51,11 @@ inline int isign(float i) return 0; } +inline int iabs(int i) +{ + return i * isign(i); +} + inline unsigned clamp_flt(float f, float min, float max) { if (f using namespace ui; @@ -79,6 +80,7 @@ void ScrollPanel::XOnMouseDown(int x, int y, unsigned int button) scrollbarSelected = true; scrollbarInitialYOffset = int(offsetY); } + initialOffsetY = offsetY; scrollbarInitialYClick = y - Position.Y; scrollbarClickLocation = 100; } @@ -87,6 +89,21 @@ void ScrollPanel::XOnMouseDown(int x, int y, unsigned int button) void ScrollPanel::XOnMouseUp(int x, int y, unsigned int button) { scrollbarSelected = false; + panning = false; + { + auto it = panHistory.end(); + while (it != panHistory.begin() && *(it - 1)) + { + --it; + } + if (it < panHistory.end()) + { + auto offsetYDiff = panHistory.back()->offsetY - (*it)->offsetY; + auto tickDiff = panHistory.back()->ticks - (*it)->ticks; + yScrollVel += offsetYDiff / tickDiff * (1000.f / Engine::Ref().GetFps()); + } + } + panHistory = {}; isMouseInsideScrollbarArea = false; scrollbarClickLocation = 0; } @@ -116,6 +133,19 @@ void ScrollPanel::XOnMouseMoved(int x, int y, int dx, int dy) offsetY = float(scrollbarInitialYOffset); } } + else if (MouseDownInside) + { + Vec2 mouseAt{ x, y }; + if (Engine::Ref().TouchUI && iabs(scrollbarInitialYClick - mouseAt.Y) > PanOffsetThreshold) + { + panning = true; + for (auto *child : children) + { + child->MouseDownInside = false; + } + GetParentWindow()->FocusComponent(NULL); + } + } if (x > (Size.X-scrollBarWidth) && x < (Size.X-scrollBarWidth)+scrollBarWidth) { @@ -130,6 +160,19 @@ void ScrollPanel::XOnMouseMoved(int x, int y, int dx, int dy) void ScrollPanel::XTick(float dt) { + if (panning) + { + auto scrollY = initialOffsetY + scrollbarInitialYClick - (Engine::Ref().GetMouseY() - GetScreenPos().Y); + ViewportPosition.Y = -scrollY; + offsetY = float(scrollY); + PanPoint p{ offsetY, GetTicks() }; + if (!(panHistory.back() && panHistory.back()->ticks == p.ticks)) + { + std::copy(panHistory.begin() + 1, panHistory.end(), panHistory.begin()); + panHistory.back() = p; + } + } + if (xScrollVel > 7.0f) xScrollVel = 7.0f; if (xScrollVel < -7.0f) xScrollVel = -7.0f; if (xScrollVel > -0.5f && xScrollVel < 0.5) diff --git a/src/gui/interface/ScrollPanel.h b/src/gui/interface/ScrollPanel.h index a1ccb719b..eb41508ab 100644 --- a/src/gui/interface/ScrollPanel.h +++ b/src/gui/interface/ScrollPanel.h @@ -1,6 +1,7 @@ #pragma once - #include "Panel.h" +#include +#include namespace ui { @@ -19,6 +20,16 @@ namespace ui int scrollbarInitialYOffset; int scrollbarInitialYClick; int scrollbarClickLocation; + int initialOffsetY; + bool panning = false; + static constexpr int PanOffsetThreshold = 10; + static constexpr int PanHistorySize = 5; + struct PanPoint + { + float offsetY; + unsigned int ticks; + }; + std::array, PanHistorySize> panHistory; public: ScrollPanel(Point position, Point size);