Add panning to ScrollPanel when TouchUI is enabled
This commit is contained in:
parent
69e0a8b0aa
commit
588fe293ec
@ -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"
|
||||
|
@ -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<min)
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include "ScrollPanel.h"
|
||||
#include "Engine.h"
|
||||
|
||||
#include "graphics/Graphics.h"
|
||||
|
||||
#include "Misc.h"
|
||||
#include "PowderToySDL.h"
|
||||
#include "Window.h"
|
||||
#include <algorithm>
|
||||
|
||||
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<int> 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)
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Panel.h"
|
||||
#include <optional>
|
||||
#include <array>
|
||||
|
||||
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<std::optional<PanPoint>, PanHistorySize> panHistory;
|
||||
public:
|
||||
ScrollPanel(Point position, Point size);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user