From b1315673454111c9aa5fd39f506b58e8a01ef43c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Fri, 31 Jan 2025 15:55:40 +0100 Subject: [PATCH] Remove remaining dependence on tick rate Similar to ce2f36c0a999, except this fixes up all code that assumed that dt was always 1, which is even funnier. --- .../elementsearch/ElementSearchActivity.cpp | 7 +- src/gui/elementsearch/ElementSearchActivity.h | 2 +- src/gui/game/GameView.cpp | 16 ++-- src/gui/game/GameView.h | 8 +- src/gui/interface/Fade.cpp | 84 ++++++++++--------- src/gui/interface/Fade.h | 64 +++++++++----- src/gui/interface/ProgressBar.cpp | 2 +- src/gui/interface/ScrollPanel.cpp | 32 +++---- src/gui/interface/ScrollPanel.h | 6 +- src/gui/interface/Spinner.cpp | 18 ++-- src/gui/interface/Spinner.h | 3 - src/gui/login/LoginView.cpp | 36 +++----- src/gui/login/LoginView.h | 3 +- src/gui/preview/PreviewView.cpp | 62 +++++--------- src/gui/preview/PreviewView.h | 9 +- src/gui/render/RenderView.cpp | 7 +- src/gui/render/RenderView.h | 2 +- src/tasks/TaskWindow.cpp | 2 +- 18 files changed, 182 insertions(+), 181 deletions(-) diff --git a/src/gui/elementsearch/ElementSearchActivity.cpp b/src/gui/elementsearch/ElementSearchActivity.cpp index bec92e05c..09be65d6d 100644 --- a/src/gui/elementsearch/ElementSearchActivity.cpp +++ b/src/gui/elementsearch/ElementSearchActivity.cpp @@ -238,9 +238,12 @@ void ElementSearchActivity::OnTick() if (isToolTipFadingIn) { isToolTipFadingIn = false; - toolTipPresence.MarkGoingUpwardThisTick(); + toolTipPresence.SetTarget(120); + } + else + { + toolTipPresence.SetTarget(0); } - toolTipPresence.Tick(); } void ElementSearchActivity::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) diff --git a/src/gui/elementsearch/ElementSearchActivity.h b/src/gui/elementsearch/ElementSearchActivity.h index b830eb496..ccdeef58f 100644 --- a/src/gui/elementsearch/ElementSearchActivity.h +++ b/src/gui/elementsearch/ElementSearchActivity.h @@ -24,7 +24,7 @@ class ElementSearchActivity: public WindowActivity std::vector toolButtons; ui::ScrollPanel *scrollPanel = nullptr; String toolTip; - ui::Fade toolTipPresence{ 0, 0, 120, 120, 60, 1000 }; + ui::Fade toolTipPresence{ ui::Fade::LinearProfile{ 120.f, 60.f }, 0, 0 }; bool shiftPressed; bool ctrlPressed; bool altPressed; diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index bbb0dc4ab..ce72a57e6 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -1782,20 +1782,24 @@ void GameView::OnTick() } } - introText.Tick(); - infoTipPresence.Tick(); if (isButtonTipFadingIn || (selectMode != PlaceSave && selectMode != SelectNone)) { isButtonTipFadingIn = false; - buttonTipShow.MarkGoingUpwardThisTick(); + buttonTipShow.SetTarget(120); + } + else + { + buttonTipShow.SetTarget(0); } - buttonTipShow.Tick(); if (isToolTipFadingIn) { isToolTipFadingIn = false; - toolTipPresence.MarkGoingUpwardThisTick(); + toolTipPresence.SetTarget(120); + } + else + { + toolTipPresence.SetTarget(0); } - toolTipPresence.Tick(); } void GameView::OnSimTick() diff --git a/src/gui/game/GameView.h b/src/gui/game/GameView.h index 088ec88db..11c114896 100644 --- a/src/gui/game/GameView.h +++ b/src/gui/game/GameView.h @@ -66,16 +66,16 @@ private: int currentSaveType; int lastMenu; - ui::Fade toolTipPresence{ 0, 0, 120, 120, 60, 1000 }; + ui::Fade toolTipPresence{ ui::Fade::LinearProfile{ 120.f, 60.f }, 0, 0 }; String toolTip; bool isToolTipFadingIn; ui::Point toolTipPosition; - ui::Fade infoTipPresence{ 0, 0, 120, 60, 60, 1000 }; + ui::Fade infoTipPresence{ ui::Fade::LinearProfile{ 60.f, 60.f }, 0, 0 }; String infoTip; - ui::Fade buttonTipShow{ 0, 0, 120, 120, 60, 1000 }; + ui::Fade buttonTipShow{ ui::Fade::LinearProfile{ 120.f, 60.f }, 0, 0 }; String buttonTip; bool isButtonTipFadingIn; - ui::Fade introText{ 2048, 0, 10000, 60, 60, 1000 }; + ui::Fade introText{ ui::Fade::LinearProfile{ 60.f, 60.f }, 0, 2048 }; String introTextMessage; bool doScreenshot; diff --git a/src/gui/interface/Fade.cpp b/src/gui/interface/Fade.cpp index 0e8d0cf36..66e71da6d 100644 --- a/src/gui/interface/Fade.cpp +++ b/src/gui/interface/Fade.cpp @@ -1,54 +1,62 @@ #include "Fade.h" #include "Engine.h" -#include namespace ui { - constexpr int64_t bias = 1000; - - void Fade::SetRange(int newMinValue, int newMaxValue) + void Fade::SetTarget(float newTarget) { - minValueBiased = int64_t(newMinValue) * bias; - maxValueBiased = int64_t(newMaxValue) * bias; - SetValue(newMinValue); - } - - void Fade::SetRateOfChange(int changeUpward, int changeDownward, int ticks) - { - changeUpwardBiased = changeUpward * bias / ticks; - changeDownwardBiased = changeDownward * bias / ticks; - } - - void Fade::MarkGoingUpwardThisTick() - { - goingUpwardThisTick = true; - } - - void Fade::Tick() - { - auto nextGoingUpward = goingUpwardThisTick; - goingUpwardThisTick = false; - if (goingUpward != nextGoingUpward) + if (target == newTarget) { - SetValue(GetValue()); - goingUpward = nextGoingUpward; + return; } + auto value = GetValue(); + target = newTarget; + SetValue(value); } - void Fade::SetValue(int newValue) + void Fade::SetProfile(Profile newProfile) { - uint64_t now = Engine::Ref().LastTick(); - referenceValueBiased = newValue * bias; - referenceTime = now; + profile = newProfile; } - int Fade::GetValue() const + void Fade::SetValue(float newValue) { - uint64_t now = Engine::Ref().LastTick(); - auto minValueNow = goingUpward ? referenceValueBiased : minValueBiased; - auto maxValueNow = goingUpward ? maxValueBiased : referenceValueBiased; - auto changeNow = goingUpward ? changeUpwardBiased : changeDownwardBiased; - auto diff = std::min(int64_t(now - referenceTime), (maxValueNow - minValueNow) / changeNow); - return int(goingUpward ? (minValueNow + changeNow * diff) : (maxValueNow - changeNow * diff)) / bias; + referenceTick = int64_t(Engine::Ref().LastTick()); + referenceValue = newValue; + } + + float Fade::GetValue() const + { + constexpr auto tickBias = 1000.f; + auto nowTick = int64_t(Engine::Ref().LastTick()); + auto diffTick = nowTick - referenceTick; + if (auto *linearProfile = std::get_if(&profile)) + { + auto change = linearProfile->change; + if (target < referenceValue) + { + if (linearProfile->changeDownward.has_value()) + { + change = *linearProfile->changeDownward; + } + change = -change; + } + auto maxDiffTick = int64_t((target - referenceValue) / change * tickBias); + if (diffTick >= maxDiffTick) + { + return target; + } + return referenceValue + diffTick * change / tickBias; + } + if (auto *exponentialProfile = std::get_if(&profile)) + { + auto maxDiffTick = int64_t(std::log(exponentialProfile->margin / std::abs(referenceValue - target)) / std::log(exponentialProfile->decay) * tickBias); + if (diffTick >= maxDiffTick) + { + return target; + } + return target + (referenceValue - target) * std::pow(exponentialProfile->decay, diffTick / tickBias); + } + return 0.f; } } diff --git a/src/gui/interface/Fade.h b/src/gui/interface/Fade.h index 50cc8f640..79e5eb8a1 100644 --- a/src/gui/interface/Fade.h +++ b/src/gui/interface/Fade.h @@ -1,43 +1,65 @@ #pragma once #include +#include +#include namespace ui { class Fade { public: - int64_t minValueBiased; // real value * 1000 - int64_t maxValueBiased; // real value * 1000 - int64_t referenceValueBiased; // real value * 1000 - int64_t changeUpwardBiased; // real value * 1000 - int64_t changeDownwardBiased; // real value * 1000 - bool goingUpwardThisTick = false; - bool goingUpward = false; - uint64_t referenceTime = 0; - - Fade(int currentValue, int minValue, int maxValue, int changeUpward, int changeDownward, int ticks) + struct LinearProfile { - SetRange(minValue, maxValue); - SetRateOfChange(changeUpward, changeDownward, ticks); - SetValue(currentValue); + float change; // per second + std::optional changeDownward; // per second, ::change is upward change if set + }; + struct ExponentialProfile + { + float decay; // per second + float margin; // unit + }; + using Profile = std::variant< + LinearProfile, + ExponentialProfile + >; + + private: + float target = 0; + int64_t referenceTick = 0; + float referenceValue = 0; + Profile profile; + + public: + Fade(Profile newProfile, float newTarget = 0.f) + { + SetProfile(newProfile); + SetTarget(newTarget); + SetValue(newTarget); } - void SetRange(int newMinValue, int newMaxValue); - void SetRateOfChange(int changeUpward, int changeDownward, int ticks); - void MarkGoingUpwardThisTick(); // this is retained until the next Tick call - void Tick(); - void SetValue(int newValue); - int GetValue() const; + Fade(Profile newProfile, float newTarget, float newValue) + { + SetProfile(newProfile); + SetTarget(newTarget); + SetValue(newValue); + } + + void SetTarget(float newTarget); + void SetProfile(Profile newProfile); + void SetValue(float newValue); + float GetValue() const; operator int() const { - return GetValue(); + return int(GetValue()); } Fade &operator =(int newValue) { - SetValue(newValue); + SetValue(float(newValue)); return *this; } + + static constexpr ExponentialProfile BasicDimensionProfile{ 1.532496e-06f, 0.5f }; }; } diff --git a/src/gui/interface/ProgressBar.cpp b/src/gui/interface/ProgressBar.cpp index a29dee37c..982c00536 100644 --- a/src/gui/interface/ProgressBar.cpp +++ b/src/gui/interface/ProgressBar.cpp @@ -76,5 +76,5 @@ void ProgressBar::Draw(const Point &screenPos) void ProgressBar::Tick() { - intermediatePos = std::fmod(ui::Engine::Ref().LastTick() / 600.f, 100.f); + intermediatePos = std::fmod(ui::Engine::Ref().LastTick() * 0.06f, 100.f); } diff --git a/src/gui/interface/ScrollPanel.cpp b/src/gui/interface/ScrollPanel.cpp index ecac589f1..884c872f8 100644 --- a/src/gui/interface/ScrollPanel.cpp +++ b/src/gui/interface/ScrollPanel.cpp @@ -14,14 +14,13 @@ ScrollPanel::ScrollPanel(Point position, Point size): maxOffset(0, 0), offsetX(0), offsetY(0), - yScrollVel(0.0f), - xScrollVel(0.0f), isMouseInsideScrollbar(false), isMouseInsideScrollbarArea(false), scrollbarSelected(false), scrollbarInitialYOffset(0), scrollbarInitialYClick(0), - scrollbarClickLocation(0) + scrollbarClickLocation(0), + scrollLastTick(int64_t(Engine::Ref().LastTick())) { } @@ -45,9 +44,9 @@ void ScrollPanel::XOnMouseWheelInside(int localx, int localy, int d) if (!d) return; if (ui::Engine::Ref().MomentumScroll) - yScrollVel -= d * 2; + yScrollVel.SetValue(yScrollVel.GetValue() - d * 2); else - yScrollVel -= d * 20; + yScrollVel.SetValue(yScrollVel.GetValue() - d * 20); } void ScrollPanel::Draw(const Point& screenPos) @@ -109,7 +108,7 @@ void ScrollPanel::XOnMouseUp(int x, int y, unsigned int button) { auto offsetYDiff = oldPanHistory.back()->offsetY - (*it)->offsetY; auto tickDiff = oldPanHistory.back()->ticks - (*it)->ticks; - yScrollVel += offsetYDiff / tickDiff * (1000.f / Engine::Ref().GetFps()); + yScrollVel.SetValue(yScrollVel.GetValue() + offsetYDiff / tickDiff * (1000.f / Engine::Ref().GetFps())); } } isMouseInsideScrollbarArea = false; @@ -198,22 +197,23 @@ void ScrollPanel::XTick() maxOffset.X = std::max(0, maxOffset.X); auto oldOffsetY = int(offsetY); - offsetY += yScrollVel; - offsetX += xScrollVel; - - - if (ui::Engine::Ref().MomentumScroll) { - if (yScrollVel > -0.5f && yScrollVel < 0.5) - yScrollVel = 0; - yScrollVel *= 0.98f; + // the correct way to do this would be to add another profile to ui::Fade that analytically + // integrates the value of the fade and assign that here; way too much hassle for now though + auto now = int64_t(Engine::Ref().LastTick()); + auto diff = now - scrollLastTick; + scrollLastTick = now; + offsetY += yScrollVel * diff * 0.06f; + offsetX += xScrollVel * diff * 0.06f; } - else + + + if (!ui::Engine::Ref().MomentumScroll) { yScrollVel = 0.0f; + xScrollVel = 0.0f; } - xScrollVel*=0.98f; if (oldOffsetY!=int(offsetY)) { diff --git a/src/gui/interface/ScrollPanel.h b/src/gui/interface/ScrollPanel.h index acb9da744..edf759432 100644 --- a/src/gui/interface/ScrollPanel.h +++ b/src/gui/interface/ScrollPanel.h @@ -1,5 +1,6 @@ #pragma once #include "Panel.h" +#include "Fade.h" #include #include @@ -14,14 +15,15 @@ namespace ui Point maxOffset; float offsetX; float offsetY; - float yScrollVel; - float xScrollVel; + ui::Fade yScrollVel{ ui::Fade::ExponentialProfile{ 0.297553f, 0.5f }, 0, 0 }; + ui::Fade xScrollVel{ ui::Fade::ExponentialProfile{ 0.297553f, 0.5f }, 0, 0 }; bool isMouseInsideScrollbar; bool isMouseInsideScrollbarArea; bool scrollbarSelected; int scrollbarInitialYOffset; int scrollbarInitialYClick; int scrollbarClickLocation; + int64_t scrollLastTick; int initialOffsetY; bool panning = false; static constexpr int PanOffsetThreshold = 10; diff --git a/src/gui/interface/Spinner.cpp b/src/gui/interface/Spinner.cpp index b3df27f6a..9d5f1b933 100644 --- a/src/gui/interface/Spinner.cpp +++ b/src/gui/interface/Spinner.cpp @@ -1,23 +1,14 @@ #include "Spinner.h" #include "graphics/Graphics.h" +#include "Engine.h" #include using namespace ui; Spinner::Spinner(Point position, Point size): - Component(position, size), cValue(0), - tickInternal(0) + Component(position, size) { } -void Spinner::Tick() -{ - tickInternal++; - if(tickInternal == 4) - { - cValue += 0.25f;//0.05f; - tickInternal = 0; - } -} void Spinner::Draw(const Point& screenPos) { Graphics * g = GetGraphics(); @@ -25,11 +16,12 @@ void Spinner::Draw(const Point& screenPos) int baseY = screenPos.Y+(Size.Y/2); int lineInner = (Size.X/2); int lineOuter = (Size.X/2)+3; + auto cValue = std::floor(ui::Engine::Ref().LastTick() * 0.015f) * 0.25f; for(float t = 0.0f; t < 6.0f; t+=0.25f) { g->DrawLine( - { int(baseX+(sin(cValue+t)*lineInner)), int(baseY+(cos(cValue+t)*lineInner)) }, - { int(baseX+(sin(cValue+t)*lineOuter)), int(baseY+(cos(cValue+t)*lineOuter)) }, + { int(baseX+(std::sin(cValue+t)*lineInner)), int(baseY+(std::cos(cValue+t)*lineInner)) }, + { int(baseX+(std::sin(cValue+t)*lineOuter)), int(baseY+(std::cos(cValue+t)*lineOuter)) }, RGB(int((t/6)*255), int((t/6)*255), int((t/6)*255))); } } diff --git a/src/gui/interface/Spinner.h b/src/gui/interface/Spinner.h index d576c8408..2e82f4837 100644 --- a/src/gui/interface/Spinner.h +++ b/src/gui/interface/Spinner.h @@ -6,11 +6,8 @@ namespace ui class Spinner: public Component { - float cValue; - int tickInternal; public: Spinner(Point position, Point size); - void Tick() override; void Draw(const Point& screenPos) override; virtual ~Spinner(); }; diff --git a/src/gui/login/LoginView.cpp b/src/gui/login/LoginView.cpp index 805bd493c..4c9338ac8 100644 --- a/src/gui/login/LoginView.cpp +++ b/src/gui/login/LoginView.cpp @@ -21,9 +21,10 @@ LoginView::LoginView(): titleLabel(new ui::Label(ui::Point(4, 5), ui::Point(200-16, 16), "Server login")), infoLabel(new ui::RichLabel(ui::Point(6, 67), ui::Point(200-12, 16), "")), usernameField(new ui::Textbox(ui::Point(8, 25), ui::Point(200-16, 17), Client::Ref().GetAuthUser().Username.FromUtf8(), "[username]")), - passwordField(new ui::Textbox(ui::Point(8, 46), ui::Point(200-16, 17), "", "[password]")), - targetSize(defaultSize) + passwordField(new ui::Textbox(ui::Point(8, 46), ui::Point(200-16, 17), "", "[password]")) { + targetSize.SetTarget(Size.Y); + targetSize.SetValue(Size.Y); FocusComponent(usernameField); infoLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; @@ -97,10 +98,13 @@ void LoginView::NotifyStatusChanged(LoginModel * sender) cancelButton->Enabled = notWorking && userID; usernameField->Enabled = notWorking; passwordField->Enabled = notWorking; - targetSize = defaultSize; if (infoLabel->Visible) { - targetSize.Y += infoLabel->Size.Y; + targetSize.SetTarget(defaultSize.Y + infoLabel->Size.Y); + } + else + { + targetSize.SetTarget(defaultSize.Y); } if (sender->GetStatus() == loginSucceeded) { @@ -111,27 +115,9 @@ void LoginView::NotifyStatusChanged(LoginModel * sender) void LoginView::OnTick() { c->Tick(); - //if(targetSize != Size) - { - ui::Point difference = targetSize-Size; - if(difference.X!=0) - { - int xdiff = difference.X/5; - if(xdiff == 0) - xdiff = 1*isign(difference.X); - Size.X += xdiff; - } - if(difference.Y!=0) - { - int ydiff = difference.Y/5; - if(ydiff == 0) - ydiff = 1*isign(difference.Y); - Size.Y += ydiff; - } - - loginButton->Position.Y = Size.Y-17; - cancelButton->Position.Y = Size.Y-17; - } + Size.Y = targetSize.GetValue(); + loginButton->Position.Y = Size.Y-17; + cancelButton->Position.Y = Size.Y-17; } void LoginView::OnDraw() diff --git a/src/gui/login/LoginView.h b/src/gui/login/LoginView.h index ef86f317f..46c910338 100644 --- a/src/gui/login/LoginView.h +++ b/src/gui/login/LoginView.h @@ -1,5 +1,6 @@ #pragma once #include "gui/interface/Window.h" +#include "gui/interface/Fade.h" namespace ui { @@ -19,7 +20,7 @@ class LoginView: public ui::Window ui::Label *infoLabel{}; ui::Textbox *usernameField{}; ui::Textbox *passwordField{}; - ui::Point targetSize; + ui::Fade targetSize{ ui::Fade::BasicDimensionProfile }; public: LoginView(); void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override; diff --git a/src/gui/preview/PreviewView.cpp b/src/gui/preview/PreviewView.cpp index c83df636c..c0ccea7c5 100644 --- a/src/gui/preview/PreviewView.cpp +++ b/src/gui/preview/PreviewView.cpp @@ -209,10 +209,10 @@ void PreviewView::commentBoxAutoHeight() addCommentBox->Size.Y = oldSize; commentBoxHeight = newSize+22; - commentBoxPositionX = (XRES/2)+4; - commentBoxPositionY = float(Size.Y-(newSize+21)); - commentBoxSizeX = float(Size.X-(XRES/2)-8); - commentBoxSizeY = float(newSize); + commentBoxPositionX.SetTarget((XRES/2)+4); + commentBoxPositionY.SetTarget(float(Size.Y-(newSize+21))); + commentBoxSizeX.SetTarget(float(Size.X-(XRES/2)-8)); + commentBoxSizeY.SetTarget(float(newSize)); if (commentWarningLabel && commentHelpText && !commentWarningLabel->Visible && addCommentBox->Position.Y+addCommentBox->Size.Y < Size.Y-14) { @@ -224,10 +224,10 @@ void PreviewView::commentBoxAutoHeight() commentBoxHeight = 20; addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - commentBoxPositionX = (XRES/2)+4; - commentBoxPositionY = float(Size.Y-19); - commentBoxSizeX = float(Size.X-(XRES/2)-48); - commentBoxSizeY = 17; + commentBoxPositionX.SetTarget((XRES/2)+4); + commentBoxPositionY.SetTarget(float(Size.Y-19)); + commentBoxSizeX.SetTarget(float(Size.X-(XRES/2)-48)); + commentBoxSizeY.SetTarget(17); if (commentWarningLabel && commentWarningLabel->Visible) { @@ -367,40 +367,19 @@ void PreviewView::OnTick() { if(addCommentBox) { - ui::Point positionDiff = ui::Point(int(commentBoxPositionX), int(commentBoxPositionY))-addCommentBox->Position; - ui::Point sizeDiff = ui::Point(int(commentBoxSizeX), int(commentBoxSizeY))-addCommentBox->Size; + addCommentBox->Position.X = commentBoxPositionX; + addCommentBox->Position.Y = commentBoxPositionY; - if(positionDiff.X!=0) + if(addCommentBox->Size.X != commentBoxSizeX) { - int xdiff = positionDiff.X/5; - if(xdiff == 0) - xdiff = 1*isign(positionDiff.X); - addCommentBox->Position.X += xdiff; - } - if(positionDiff.Y!=0) - { - int ydiff = positionDiff.Y/5; - if(ydiff == 0) - ydiff = 1*isign(positionDiff.Y); - addCommentBox->Position.Y += ydiff; - } - - if(sizeDiff.X!=0) - { - int xdiff = sizeDiff.X/5; - if(xdiff == 0) - xdiff = 1*isign(sizeDiff.X); - addCommentBox->Size.X += xdiff; + addCommentBox->Size.X = commentBoxSizeX; addCommentBox->Invalidate(); commentBoxAutoHeight(); //make sure textbox height is correct after resizes addCommentBox->resetCursorPosition(); //make sure cursor is in correct position after resizes } - if(sizeDiff.Y!=0) + if(addCommentBox->Size.Y != commentBoxSizeY) { - int ydiff = sizeDiff.Y/5; - if(ydiff == 0) - ydiff = 1*isign(sizeDiff.Y); - addCommentBox->Size.Y += ydiff; + addCommentBox->Size.Y = commentBoxSizeY; addCommentBox->Invalidate(); } commentsPanel->Size.Y = addCommentBox->Position.Y-1; @@ -656,12 +635,15 @@ void PreviewView::NotifyCommentBoxEnabledChanged(PreviewModel * sender) } if(sender->GetCommentBoxEnabled()) { - commentBoxPositionX = (XRES/2)+4; - commentBoxPositionY = float(Size.Y-19); - commentBoxSizeX = float(Size.X-(XRES/2)-48); - commentBoxSizeY = 17; - addCommentBox = new ui::Textbox(ui::Point((XRES/2)+4, Size.Y-19), ui::Point(Size.X-(XRES/2)-48, 17), "", "Add Comment"); + commentBoxPositionX.SetTarget(addCommentBox->Position.X); + commentBoxPositionX.SetValue(addCommentBox->Position.X); + commentBoxPositionY.SetTarget(addCommentBox->Position.Y); + commentBoxPositionY.SetValue(addCommentBox->Position.Y); + commentBoxSizeX.SetTarget(addCommentBox->Size.X); + commentBoxSizeX.SetValue(addCommentBox->Size.X); + commentBoxSizeY.SetTarget(addCommentBox->Size.Y); + commentBoxSizeY.SetValue(addCommentBox->Size.Y); addCommentBox->SetActionCallback({ [this] { CheckComment(); commentBoxAutoHeight(); diff --git a/src/gui/preview/PreviewView.h b/src/gui/preview/PreviewView.h index 3e1a48326..b4672e2af 100644 --- a/src/gui/preview/PreviewView.h +++ b/src/gui/preview/PreviewView.h @@ -4,6 +4,7 @@ #include #include "common/String.h" #include "gui/interface/Window.h" +#include "gui/interface/Fade.h" #include "simulation/MissingElements.h" namespace http @@ -63,10 +64,10 @@ class PreviewView: public ui::Window bool isRefreshingComments = false; int commentBoxHeight; - float commentBoxPositionX; - float commentBoxPositionY; - float commentBoxSizeX; - float commentBoxSizeY; + ui::Fade commentBoxPositionX{ ui::Fade::BasicDimensionProfile }; + ui::Fade commentBoxPositionY{ ui::Fade::BasicDimensionProfile }; + ui::Fade commentBoxSizeX{ ui::Fade::BasicDimensionProfile }; + ui::Fade commentBoxSizeY{ ui::Fade::BasicDimensionProfile }; bool commentHelpText; std::set swearWords; diff --git a/src/gui/render/RenderView.cpp b/src/gui/render/RenderView.cpp index 4dd51ef12..a101b9d93 100644 --- a/src/gui/render/RenderView.cpp +++ b/src/gui/render/RenderView.cpp @@ -217,9 +217,12 @@ void RenderView::OnTick() if (isToolTipFadingIn) { isToolTipFadingIn = false; - toolTipPresence.MarkGoingUpwardThisTick(); + toolTipPresence.SetTarget(120); + } + else + { + toolTipPresence.SetTarget(0); } - toolTipPresence.Tick(); } void RenderView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) diff --git a/src/gui/render/RenderView.h b/src/gui/render/RenderView.h index 5aa06a9a2..8f16f3672 100644 --- a/src/gui/render/RenderView.h +++ b/src/gui/render/RenderView.h @@ -20,7 +20,7 @@ class RenderView: public ui::Window { std::vector displayModes; std::vector colourModes; String toolTip; - ui::Fade toolTipPresence{ 0, 0, 120, 120, 60, 1000 }; + ui::Fade toolTipPresence{ ui::Fade::LinearProfile{ 120.f, 60.f }, 0, 0 }; bool isToolTipFadingIn; int line1, line2, line3, line4; uint32_t CalculateRenderMode(); diff --git a/src/tasks/TaskWindow.cpp b/src/tasks/TaskWindow.cpp index 929f4c2e8..b0fc63c9b 100644 --- a/src/tasks/TaskWindow.cpp +++ b/src/tasks/TaskWindow.cpp @@ -79,7 +79,7 @@ void TaskWindow::NotifyProgress(Task * task) void TaskWindow::OnTick() { - intermediatePos = std::fmod(ui::Engine::Ref().LastTick() / 600.f, 100.f); + intermediatePos = std::fmod(ui::Engine::Ref().LastTick() * 0.06f, 100.f); task->Poll(); if (done) Exit();