mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-17 21:51:20 +02:00
Remove remaining dependence on tick rate
Similar to ce2f36c0a9
, except this fixes up all code that assumed that dt was always 1, which is even funnier.
This commit is contained in:
@@ -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)
|
||||
|
@@ -24,7 +24,7 @@ class ElementSearchActivity: public WindowActivity
|
||||
std::vector<ToolButton*> 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;
|
||||
|
@@ -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()
|
||||
|
@@ -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;
|
||||
|
@@ -1,54 +1,62 @@
|
||||
#include "Fade.h"
|
||||
#include "Engine.h"
|
||||
#include <algorithm>
|
||||
|
||||
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);
|
||||
if (target == newTarget)
|
||||
{
|
||||
return;
|
||||
}
|
||||
auto value = GetValue();
|
||||
target = newTarget;
|
||||
SetValue(value);
|
||||
}
|
||||
|
||||
void Fade::SetRateOfChange(int changeUpward, int changeDownward, int ticks)
|
||||
void Fade::SetProfile(Profile newProfile)
|
||||
{
|
||||
changeUpwardBiased = changeUpward * bias / ticks;
|
||||
changeDownwardBiased = changeDownward * bias / ticks;
|
||||
profile = newProfile;
|
||||
}
|
||||
|
||||
void Fade::MarkGoingUpwardThisTick()
|
||||
void Fade::SetValue(float newValue)
|
||||
{
|
||||
goingUpwardThisTick = true;
|
||||
referenceTick = int64_t(Engine::Ref().LastTick());
|
||||
referenceValue = newValue;
|
||||
}
|
||||
|
||||
void Fade::Tick()
|
||||
float Fade::GetValue() const
|
||||
{
|
||||
auto nextGoingUpward = goingUpwardThisTick;
|
||||
goingUpwardThisTick = false;
|
||||
if (goingUpward != nextGoingUpward)
|
||||
constexpr auto tickBias = 1000.f;
|
||||
auto nowTick = int64_t(Engine::Ref().LastTick());
|
||||
auto diffTick = nowTick - referenceTick;
|
||||
if (auto *linearProfile = std::get_if<LinearProfile>(&profile))
|
||||
{
|
||||
SetValue(GetValue());
|
||||
goingUpward = nextGoingUpward;
|
||||
}
|
||||
}
|
||||
|
||||
void Fade::SetValue(int newValue)
|
||||
auto change = linearProfile->change;
|
||||
if (target < referenceValue)
|
||||
{
|
||||
uint64_t now = Engine::Ref().LastTick();
|
||||
referenceValueBiased = newValue * bias;
|
||||
referenceTime = now;
|
||||
}
|
||||
|
||||
int Fade::GetValue() const
|
||||
if (linearProfile->changeDownward.has_value())
|
||||
{
|
||||
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;
|
||||
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<ExponentialProfile>(&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;
|
||||
}
|
||||
}
|
||||
|
@@ -1,43 +1,65 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <variant>
|
||||
#include <optional>
|
||||
|
||||
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<float> 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 };
|
||||
};
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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))
|
||||
{
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "Panel.h"
|
||||
#include "Fade.h"
|
||||
#include <optional>
|
||||
#include <array>
|
||||
|
||||
@@ -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;
|
||||
|
@@ -1,23 +1,14 @@
|
||||
#include "Spinner.h"
|
||||
#include "graphics/Graphics.h"
|
||||
#include "Engine.h"
|
||||
#include <cmath>
|
||||
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
};
|
||||
|
@@ -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,28 +115,10 @@ 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;
|
||||
}
|
||||
|
||||
Size.Y = targetSize.GetValue();
|
||||
loginButton->Position.Y = Size.Y-17;
|
||||
cancelButton->Position.Y = Size.Y-17;
|
||||
}
|
||||
}
|
||||
|
||||
void LoginView::OnDraw()
|
||||
{
|
||||
|
@@ -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;
|
||||
|
@@ -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();
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
#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<String> swearWords;
|
||||
|
@@ -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)
|
||||
|
@@ -20,7 +20,7 @@ class RenderView: public ui::Window {
|
||||
std::vector<ModeCheckbox *> displayModes;
|
||||
std::vector<ModeCheckbox *> 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();
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user