GUI: mobile menu button dragging

This commit is contained in:
tildearrow 2022-12-04 17:19:21 -05:00
parent e76dcdd0cf
commit a63e2284c7
3 changed files with 45 additions and 11 deletions

View File

@ -23,19 +23,29 @@
void FurnaceGUI::drawMobileControls() {
float timeScale=1.0f/(60.0f*ImGui::GetIO().DeltaTime);
if (mobileMenuOpen) {
if (mobileMenuPos<0.999f) {
WAKE_UP;
mobileMenuPos+=MIN(0.1,(1.0-mobileMenuPos)*0.65)*timeScale;
if (dragMobileMenu) {
if (portrait) {
mobileMenuPos=(dragMobileMenuOrigin.y-ImGui::GetMousePos().y)/(canvasH*0.65);
} else {
mobileMenuPos=1.0f;
mobileMenuPos=(ImGui::GetMousePos().x-dragMobileMenuOrigin.x)/(canvasW*0.65);
}
if (mobileMenuPos<0.0f) mobileMenuPos=0.0f;
if (mobileMenuPos>1.0f) mobileMenuPos=1.0f;
} else {
if (mobileMenuPos>0.001f) {
WAKE_UP;
mobileMenuPos-=MIN(0.1,mobileMenuPos*0.65)*timeScale;
if (mobileMenuOpen) {
if (mobileMenuPos<0.999f) {
WAKE_UP;
mobileMenuPos+=MIN(0.1,(1.0-mobileMenuPos)*0.65)*timeScale;
} else {
mobileMenuPos=1.0f;
}
} else {
mobileMenuPos=0.0f;
if (mobileMenuPos>0.001f) {
WAKE_UP;
mobileMenuPos-=MIN(0.1,mobileMenuPos*0.65)*timeScale;
} else {
mobileMenuPos=0.0f;
}
}
}
ImGui::SetNextWindowPos(portrait?ImVec2(0.0f,((1.0-mobileMenuPos*0.65)*canvasH)-(0.16*canvasW)):ImVec2(0.5*canvasW*mobileMenuPos,0.0f));
@ -54,7 +64,20 @@ void FurnaceGUI::drawMobileControls() {
}
}
if (ImGui::Button(mobButtonName,buttonSize)) {
mobileMenuOpen=!mobileMenuOpen;
if (!dragMobileMenu) {
mobileMenuOpen=!mobileMenuOpen;
}
}
if (ImGui::IsItemActive() && ImGui::GetIO().MouseDragMaxDistanceSqr[ImGuiMouseButton_Left]>ImGui::GetIO().ConfigInertialScrollToleranceSqr*2.0f) {
if (!dragMobileMenu) {
dragMobileMenu=true;
dragMobileMenuOrigin=ImGui::GetMousePos();
if (portrait) {
dragMobileMenuOrigin.y+=mobileMenuPos*canvasH*0.65f;
} else {
dragMobileMenuOrigin.x-=mobileMenuPos*canvasW*0.65f;
}
}
}
if (!portrait) ImGui::Separator();

View File

@ -2931,6 +2931,14 @@ void FurnaceGUI::pointUp(int x, int y, int button) {
}
orderScrollLocked=false;
orderScrollTolerance=false;
if (dragMobileMenu) {
dragMobileMenu=false;
if (mobileMenuOpen) {
mobileMenuOpen=(mobileMenuPos>=0.85f);
} else {
mobileMenuOpen=(mobileMenuPos>=0.15f);
}
}
if (selecting) {
if (!selectingFull) cursor=selEnd;
finishSelection();
@ -5785,6 +5793,7 @@ FurnaceGUI::FurnaceGUI():
keepLoopAlive(false),
orderScrollLocked(false),
orderScrollTolerance(false),
dragMobileMenu(false),
curWindow(GUI_WINDOW_NOTHING),
nextWindow(GUI_WINDOW_NOTHING),
curWindowLast(GUI_WINDOW_NOTHING),
@ -5877,6 +5886,7 @@ FurnaceGUI::FurnaceGUI():
orderScroll(0.0f),
orderScrollSlideOrigin(0.0f),
orderScrollRealOrigin(0.0f,0.0f),
dragMobileMenuOrigin(0.0f,0.0f),
layoutTimeBegin(0),
layoutTimeEnd(0),
layoutTimeDelta(0),

View File

@ -1435,7 +1435,7 @@ class FurnaceGUI {
SelectionPoint selStart, selEnd, cursor, cursorDrag, dragStart, dragEnd;
bool selecting, selectingFull, dragging, curNibble, orderNibble, followOrders, followPattern, changeAllOrders, mobileUI;
bool collapseWindow, demandScrollX, fancyPattern, wantPatName, firstFrame, tempoView, waveHex, waveSigned, waveGenVisible, lockLayout, editOptsVisible, latchNibble, nonLatchNibble;
bool keepLoopAlive, orderScrollLocked, orderScrollTolerance;
bool keepLoopAlive, orderScrollLocked, orderScrollTolerance, dragMobileMenu;
FurnaceGUIWindows curWindow, nextWindow, curWindowLast;
std::atomic<FurnaceGUIWindows> curWindowThreadSafe;
float peak[2];
@ -1581,6 +1581,7 @@ class FurnaceGUI {
float nextScroll, nextAddScroll, orderScroll, orderScrollSlideOrigin;
ImVec2 orderScrollRealOrigin;
ImVec2 dragMobileMenuOrigin;
int layoutTimeBegin, layoutTimeEnd, layoutTimeDelta;
int renderTimeBegin, renderTimeEnd, renderTimeDelta;