Align value labels and adjust strength range
This commit is contained in:
parent
472360f0b9
commit
7500b4749b
@ -36,10 +36,11 @@ void DirectionSelector::SetSnapPoints(int newRadius, int points)
|
|||||||
snapPoints.push_back(ui::Point(0, 0));
|
snapPoints.push_back(ui::Point(0, 0));
|
||||||
for (int i = 1; i < points; i++)
|
for (int i = 1; i < points; i++)
|
||||||
{
|
{
|
||||||
snapPoints.push_back(ui::Point(0, (radius / points) * i));
|
int dist = ((float)i / (float)(points - 1)) * maxRadius;
|
||||||
snapPoints.push_back(ui::Point(0, -1 * (radius / points) * i));
|
snapPoints.push_back(ui::Point(0, dist));
|
||||||
snapPoints.push_back(ui::Point(-1 * (radius / points) * i, 0));
|
snapPoints.push_back(ui::Point(0, -1 * dist));
|
||||||
snapPoints.push_back(ui::Point((radius / points) * i, 0));
|
snapPoints.push_back(ui::Point(-1 * dist, 0));
|
||||||
|
snapPoints.push_back(ui::Point(dist, 0));
|
||||||
}
|
}
|
||||||
useSnapPoints = true;
|
useSnapPoints = true;
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,12 @@ class DirectionSelector : public ui::Component
|
|||||||
ui::Colour borderColor;
|
ui::Colour borderColor;
|
||||||
ui::Colour snapPointColor;
|
ui::Colour snapPointColor;
|
||||||
|
|
||||||
std::function<void(float x, float y)> updateCallback;
|
public:
|
||||||
std::function<void(float x, float y)> changeCallback;
|
using DirectionSelectorCallback = std::function<void(float x, float y)>;
|
||||||
|
|
||||||
|
private:
|
||||||
|
DirectionSelectorCallback updateCallback;
|
||||||
|
DirectionSelectorCallback changeCallback;
|
||||||
|
|
||||||
bool mouseDown;
|
bool mouseDown;
|
||||||
bool mouseHover;
|
bool mouseHover;
|
||||||
@ -74,8 +78,8 @@ public:
|
|||||||
inline void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override { altDown = alt; }
|
inline void OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override { altDown = alt; }
|
||||||
inline void OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override { altDown = alt; }
|
inline void OnKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) override { altDown = alt; }
|
||||||
|
|
||||||
inline void SetUpdateCallback(std::function<void(float x, float y)> callback) { updateCallback = callback; }
|
inline void SetUpdateCallback(DirectionSelectorCallback callback) { updateCallback = callback; }
|
||||||
inline void SetChangeCallback(std::function<void(float x, float y)> callback) { changeCallback = callback; }
|
inline void SetChangeCallback(DirectionSelectorCallback callback) { changeCallback = callback; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace ui */
|
} /* namespace ui */
|
||||||
|
@ -164,9 +164,7 @@ OptionsView::OptionsView():
|
|||||||
}
|
}
|
||||||
|
|
||||||
ui::DirectionSelector * gravityDirection;
|
ui::DirectionSelector * gravityDirection;
|
||||||
ui::Label * labelX;
|
ui::Label * labelValues;
|
||||||
ui::Label * labelY;
|
|
||||||
ui::Label * labelTotal;
|
|
||||||
|
|
||||||
OptionsController * c;
|
OptionsController * c;
|
||||||
|
|
||||||
@ -174,12 +172,9 @@ OptionsView::OptionsView():
|
|||||||
GravityWindow(ui::Point position, int radius, float x, float y, OptionsController * c_):
|
GravityWindow(ui::Point position, int radius, float x, float y, OptionsController * c_):
|
||||||
ui::Window(position, ui::Point((radius * 2) + 20, (radius * 2) + 75)),
|
ui::Window(position, ui::Point((radius * 2) + 20, (radius * 2) + 75)),
|
||||||
gravityDirection(new ui::DirectionSelector(ui::Point(10, 32), radius)),
|
gravityDirection(new ui::DirectionSelector(ui::Point(10, 32), radius)),
|
||||||
labelX(new ui::Label(ui::Point(0, (radius * 2) + 37), ui::Point(radius / 3, 16), "X:")),
|
|
||||||
labelY(new ui::Label(ui::Point((radius * 2) / 3, (radius * 2) + 37), ui::Point((radius * 2) / 3, 16), "Y:")),
|
|
||||||
labelTotal(new ui::Label(ui::Point((radius * 4) / 3, (radius * 2) + 37), ui::Point((radius * 2) / 3, 16), "Total:")),
|
|
||||||
c(c_)
|
c(c_)
|
||||||
{
|
{
|
||||||
ui::Label * tempLabel = new ui::Label(ui::Point(4, 1), ui::Point(Size.X-8, 22), "Custom Gravity");
|
ui::Label * tempLabel = new ui::Label(ui::Point(4, 1), ui::Point(Size.X - 8, 22), "Custom Gravity");
|
||||||
tempLabel->SetTextColour(style::Colour::InformationTitle);
|
tempLabel->SetTextColour(style::Colour::InformationTitle);
|
||||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||||
@ -188,42 +183,20 @@ OptionsView::OptionsView():
|
|||||||
Separator * tempSeparator = new Separator(ui::Point(0, 22), ui::Point(Size.X, 1));
|
Separator * tempSeparator = new Separator(ui::Point(0, 22), ui::Point(Size.X, 1));
|
||||||
AddComponent(tempSeparator);
|
AddComponent(tempSeparator);
|
||||||
|
|
||||||
labelX->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
labelValues = new ui::Label(ui::Point(0, (radius * 2) + 37), ui::Point(Size.X, 16), String::Build( "X:", std::round(x * 10.0f) / 10,
|
||||||
labelX->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
" Y:", std::round(y * 10.0f) / 10,
|
||||||
StringBuilder temp;
|
" Total:", std::round(std::hypot(x, y) * 10.0f) / 10));
|
||||||
temp << "X:" << std::round(x * 10) / 10;
|
labelValues->Appearance.HorizontalAlign = ui::Appearance::AlignCentre;
|
||||||
labelX->SetText(temp.Build());
|
labelValues->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||||
AddComponent(labelX);
|
AddComponent(labelValues);
|
||||||
|
|
||||||
labelY->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
gravityDirection->SetValues(x / 2.0f, y / 2.0f);
|
||||||
labelY->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
|
||||||
temp = StringBuilder();
|
|
||||||
temp << "Y:" << std::round(y * 10) / 10;
|
|
||||||
labelY->SetText(temp.Build());
|
|
||||||
AddComponent(labelY);
|
|
||||||
|
|
||||||
labelTotal->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
|
||||||
labelTotal->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
|
||||||
temp = StringBuilder();
|
|
||||||
temp << "Total:" << std::round(std::hypot(x, y) * 10) / 10;
|
|
||||||
labelTotal->SetText(temp.Build());
|
|
||||||
AddComponent(labelTotal);
|
|
||||||
|
|
||||||
gravityDirection->SetValues(x / 1.5f, y / 1.5f);
|
|
||||||
gravityDirection->SetUpdateCallback([this](float x, float y) {
|
gravityDirection->SetUpdateCallback([this](float x, float y) {
|
||||||
StringBuilder temp;
|
labelValues->SetText(String::Build( "X:", std::round(x * 20.0f) / 10,
|
||||||
temp << "X:" << std::round(x * 15) / 10;
|
" Y:", std::round(y * 20.0f) / 10,
|
||||||
labelX->SetText(temp.Build());
|
" Total:", std::round(gravityDirection->GetTotalValue() * 20.0f) / 10));
|
||||||
temp = StringBuilder();
|
|
||||||
|
|
||||||
temp << "Y:" << std::round(y * 15) / 10;
|
|
||||||
labelY->SetText(temp.Build());
|
|
||||||
temp = StringBuilder();
|
|
||||||
|
|
||||||
temp << "Total:" << std::round(gravityDirection->GetTotalValue() * 15) / 10;
|
|
||||||
labelTotal->SetText(temp.Build());
|
|
||||||
});
|
});
|
||||||
gravityDirection->SetSnapPoints(5, 4);
|
gravityDirection->SetSnapPoints(5, 5);
|
||||||
AddComponent(gravityDirection);
|
AddComponent(gravityDirection);
|
||||||
|
|
||||||
ui::Button * okayButton = new ui::Button(ui::Point(0, Size.Y - 17), ui::Point(Size.X, 17), "OK");
|
ui::Button * okayButton = new ui::Button(ui::Point(0, Size.Y - 17), ui::Point(Size.X, 17), "OK");
|
||||||
@ -231,8 +204,8 @@ OptionsView::OptionsView():
|
|||||||
okayButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
okayButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||||
okayButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
|
okayButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
|
||||||
okayButton->SetActionCallback({ [this] {
|
okayButton->SetActionCallback({ [this] {
|
||||||
c->SetCustomGravityX(gravityDirection->GetXValue() * 1.5f);
|
c->SetCustomGravityX(gravityDirection->GetXValue() * 2.0f);
|
||||||
c->SetCustomGravityY(gravityDirection->GetYValue() * 1.5f);
|
c->SetCustomGravityY(gravityDirection->GetYValue() * 2.0f);
|
||||||
CloseActiveWindow();
|
CloseActiveWindow();
|
||||||
SelfDestruct();
|
SelfDestruct();
|
||||||
} });
|
} });
|
||||||
|
Reference in New Issue
Block a user