From 43df58cc928f93ae0c852dffc70189e5e6ca4368 Mon Sep 17 00:00:00 2001 From: vintagepc <53943260+vintagepc@users.noreply.github.com> Date: Wed, 27 Oct 2021 22:07:46 -0400 Subject: [PATCH] Fix terminal/screenshot related bugs (#336) * Fix #333 - terminal positioning on scale * Fix #335 - GL scaling of hotkey snapshots --- MK404.cpp | 9 ++++----- parts/components/GLHelper.cpp | 7 ++++++- parts/printers/Prusa_MMU2.cpp | 3 +-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/MK404.cpp b/MK404.cpp index 4c8095bf..e98797f3 100644 --- a/MK404.cpp +++ b/MK404.cpp @@ -151,12 +151,11 @@ void displayCB() /* function called whenever redisplay needed */ glLoadIdentity(); glClear(US(GL_COLOR_BUFFER_BIT) | US(GL_DEPTH_BUFFER_BIT)); int iW = glutGet(GLUT_WINDOW_WIDTH); - //int iH = glutGet(GLUT_WINDOW_HEIGHT); if (m_bTerminal) { glPushMatrix(); - glTranslatef(0,m_iTermHeight,0); - ScriptHost::Draw(); + glTranslatef(0,4.F*(printer->GetWindowSize().second + 2),0); + ScriptHost::Draw(); glPopMatrix(); } printer->Draw(); @@ -224,7 +223,7 @@ void ResizeCB(int w, int h) std::pair winSize = printer->GetWindowSize(); if (m_bTerminal) { - winSize.second+=10; + winSize.second += 14; } float fWS = static_cast(w)/static_cast(winSize.first*4); float fHS = static_cast(h)/static_cast(winSize.second*4); @@ -461,7 +460,7 @@ int main(int argc, char *argv[]) int pixsize = 4; if (m_bTerminal) { - winSize.second +=10; + winSize.second += 14; } iWinW = winSize.first * pixsize; iWinH = (winSize.second)*pixsize; diff --git a/parts/components/GLHelper.cpp b/parts/components/GLHelper.cpp index da62d41b..ff3e2570 100644 --- a/parts/components/GLHelper.cpp +++ b/parts/components/GLHelper.cpp @@ -89,6 +89,11 @@ void GLHelper::OnDraw() case ActTakeSnapshotArea: case ActTakeSnapLCD: { + if (m_iAct.load() == ActTakeSnapLCD) // Account for LCD scaling + { + m_h = static_cast(m_h)*(static_cast(width)/static_cast(m_w)); + m_w = width; + } WritePNG(width, height, (m_iAct == ActTakeSnapshotArea || m_iAct == ActTakeSnapLCD)); std::cout << "Wrote: " << m_strFile << '\n'; if (m_bIsKeySnap) { @@ -120,7 +125,7 @@ void GLHelper::OnKeyPress(const Key& key) { std::cout << "LCD Snapshot toggled!\n"; m_bIsKeySnap = true; - // GLHelper::SnapRect(tests/snaps/LCD01,0,0,500,164) + // Args are scaled based on window width in the routine. ProcessAction(ActTakeSnapLCD,{"","0","0","500","164"}); } break; diff --git a/parts/printers/Prusa_MMU2.cpp b/parts/printers/Prusa_MMU2.cpp index 22313c65..c9ecdd17 100644 --- a/parts/printers/Prusa_MMU2.cpp +++ b/parts/printers/Prusa_MMU2.cpp @@ -35,8 +35,7 @@ std::pair Prusa_MMU2::GetWindowSize() void Prusa_MMU2::Draw() { glScalef(50.F/35.F,4,1); - auto fY = static_cast(glutGet(GLUT_WINDOW_HEIGHT)/4); - MM_Control_01::Draw(fY); + MM_Control_01::Draw(static_cast(GetWindowSize().second)); m_gl.OnDraw(); }