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));
|
||||
for (int i = 1; i < points; i++)
|
||||
{
|
||||
snapPoints.push_back(ui::Point(0, (radius / points) * i));
|
||||
snapPoints.push_back(ui::Point(0, -1 * (radius / points) * i));
|
||||
snapPoints.push_back(ui::Point(-1 * (radius / points) * i, 0));
|
||||
snapPoints.push_back(ui::Point((radius / points) * i, 0));
|
||||
int dist = ((float)i / (float)(points - 1)) * maxRadius;
|
||||
snapPoints.push_back(ui::Point(0, dist));
|
||||
snapPoints.push_back(ui::Point(0, -1 * dist));
|
||||
snapPoints.push_back(ui::Point(-1 * dist, 0));
|
||||
snapPoints.push_back(ui::Point(dist, 0));
|
||||
}
|
||||
useSnapPoints = true;
|
||||
}
|
||||
|
@ -30,8 +30,12 @@ class DirectionSelector : public ui::Component
|
||||
ui::Colour borderColor;
|
||||
ui::Colour snapPointColor;
|
||||
|
||||
std::function<void(float x, float y)> updateCallback;
|
||||
std::function<void(float x, float y)> changeCallback;
|
||||
public:
|
||||
using DirectionSelectorCallback = std::function<void(float x, float y)>;
|
||||
|
||||
private:
|
||||
DirectionSelectorCallback updateCallback;
|
||||
DirectionSelectorCallback changeCallback;
|
||||
|
||||
bool mouseDown;
|
||||
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 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 SetChangeCallback(std::function<void(float x, float y)> callback) { changeCallback = callback; }
|
||||
inline void SetUpdateCallback(DirectionSelectorCallback callback) { updateCallback = callback; }
|
||||
inline void SetChangeCallback(DirectionSelectorCallback callback) { changeCallback = callback; }
|
||||
};
|
||||
|
||||
} /* namespace ui */
|
||||
|
@ -164,9 +164,7 @@ OptionsView::OptionsView():
|
||||
}
|
||||
|
||||
ui::DirectionSelector * gravityDirection;
|
||||
ui::Label * labelX;
|
||||
ui::Label * labelY;
|
||||
ui::Label * labelTotal;
|
||||
ui::Label * labelValues;
|
||||
|
||||
OptionsController * c;
|
||||
|
||||
@ -174,9 +172,6 @@ OptionsView::OptionsView():
|
||||
GravityWindow(ui::Point position, int radius, float x, float y, OptionsController * c_):
|
||||
ui::Window(position, ui::Point((radius * 2) + 20, (radius * 2) + 75)),
|
||||
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_)
|
||||
{
|
||||
ui::Label * tempLabel = new ui::Label(ui::Point(4, 1), ui::Point(Size.X - 8, 22), "Custom Gravity");
|
||||
@ -188,42 +183,20 @@ OptionsView::OptionsView():
|
||||
Separator * tempSeparator = new Separator(ui::Point(0, 22), ui::Point(Size.X, 1));
|
||||
AddComponent(tempSeparator);
|
||||
|
||||
labelX->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
labelX->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
StringBuilder temp;
|
||||
temp << "X:" << std::round(x * 10) / 10;
|
||||
labelX->SetText(temp.Build());
|
||||
AddComponent(labelX);
|
||||
labelValues = new ui::Label(ui::Point(0, (radius * 2) + 37), ui::Point(Size.X, 16), String::Build( "X:", std::round(x * 10.0f) / 10,
|
||||
" Y:", std::round(y * 10.0f) / 10,
|
||||
" Total:", std::round(std::hypot(x, y) * 10.0f) / 10));
|
||||
labelValues->Appearance.HorizontalAlign = ui::Appearance::AlignCentre;
|
||||
labelValues->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
AddComponent(labelValues);
|
||||
|
||||
labelY->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
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->SetValues(x / 2.0f, y / 2.0f);
|
||||
gravityDirection->SetUpdateCallback([this](float x, float y) {
|
||||
StringBuilder temp;
|
||||
temp << "X:" << std::round(x * 15) / 10;
|
||||
labelX->SetText(temp.Build());
|
||||
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());
|
||||
labelValues->SetText(String::Build( "X:", std::round(x * 20.0f) / 10,
|
||||
" Y:", std::round(y * 20.0f) / 10,
|
||||
" Total:", std::round(gravityDirection->GetTotalValue() * 20.0f) / 10));
|
||||
});
|
||||
gravityDirection->SetSnapPoints(5, 4);
|
||||
gravityDirection->SetSnapPoints(5, 5);
|
||||
AddComponent(gravityDirection);
|
||||
|
||||
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.BorderInactive = ui::Colour(200, 200, 200);
|
||||
okayButton->SetActionCallback({ [this] {
|
||||
c->SetCustomGravityX(gravityDirection->GetXValue() * 1.5f);
|
||||
c->SetCustomGravityY(gravityDirection->GetYValue() * 1.5f);
|
||||
c->SetCustomGravityX(gravityDirection->GetXValue() * 2.0f);
|
||||
c->SetCustomGravityY(gravityDirection->GetYValue() * 2.0f);
|
||||
CloseActiveWindow();
|
||||
SelfDestruct();
|
||||
} });
|
||||
|
Reference in New Issue
Block a user