Fog-curve track bar

This commit is contained in:
MihailRis 2023-11-17 16:40:12 +03:00
parent b14ef4f923
commit 76e57c42e1
3 changed files with 34 additions and 18 deletions

View File

@ -46,8 +46,9 @@ void Label::draw(Batch2D* batch, Assets* assets) {
font->draw(batch, text_, coord.x, coord.y);
}
void Label::textSupplier(wstringsupplier supplier) {
Label* Label::textSupplier(wstringsupplier supplier) {
this->supplier = supplier;
return this;
}
Button::Button(shared_ptr<UINode> content, glm::vec4 padding) : Panel(vec2(32,32), padding, 0) {
@ -150,8 +151,8 @@ wstring TextBox::text() const {
return input;
}
TrackBar::TrackBar(double min, double max, double value, double step)
: UINode(vec2(), vec2(32)), min(min), max(max), value(value), step(step) {
TrackBar::TrackBar(double min, double max, double value, double step, int trackWidth)
: UINode(vec2(), vec2(32)), min(min), max(max), value(value), step(step), trackWidth(trackWidth) {
color(vec4(0.f, 0.f, 0.f, 0.4f));
}
@ -165,10 +166,10 @@ void TrackBar::draw(Batch2D* batch, Assets* assets) {
batch->rect(coord.x, coord.y, size_.x, size_.y);
float width = size_.x;
float t = (value - min) / (max-min+trackWidth);
float t = (value - min) / (max-min+trackWidth*step);
batch->color = trackColor;
batch->rect(coord.x + width * t, coord.y, size_.x * (trackWidth / (max-min)), size_.y);
batch->rect(coord.x + width * t, coord.y, size_.x * (trackWidth / (max-min+trackWidth*step) * step), size_.y);
}
void TrackBar::supplier(doublesupplier supplier) {
@ -181,12 +182,13 @@ void TrackBar::consumer(doubleconsumer consumer) {
void TrackBar::mouseMove(GUI*, int x, int y) {
vec2 coord = calcCoord();
x -= coord.x;
x = x/size_.x * (max-min+trackWidth);
x = (x > max) ? max : x;
x = (x < min) ? min : x;
x = (int)(x / step) * step;
value = x;
value -= coord.x;
value = (value)/size_.x * (max-min+trackWidth*step);
value += min;
value = (value > max) ? max : value;
value = (value < min) ? min : value;
value = (int)(value / step) * step;
if (consumer_) {
consumer_(value);
}

View File

@ -32,7 +32,7 @@ namespace gui {
virtual void draw(Batch2D* batch, Assets* assets) override;
virtual void textSupplier(wstringsupplier supplier);
virtual Label* textSupplier(wstringsupplier supplier);
};
class Button : public Panel {
@ -86,9 +86,9 @@ namespace gui {
double max;
double value;
double step;
int trackWidth = 3;
int trackWidth;
public:
TrackBar(double min, double max, double value, double step=1.0);
TrackBar(double min, double max, double value, double step=1.0, int trackWidth=3);
virtual void draw(Batch2D* batch, Assets* assets) override;
virtual void supplier(doublesupplier supplier);

View File

@ -173,13 +173,11 @@ Panel* create_settings_panel(Engine* engine) {
panel->color(vec4(0.0f));
panel->setCoord(vec2(10, 10));
{
Label* label = new Label(L"");
label->textSupplier([=]() {
/* Load Distance setting track bar */{
panel->add((new Label(L""))->textSupplier([=]() {
return L"Load Distance: " +
std::to_wstring(engine->getSettings().chunks.loadDistance);
});
panel->add(label);
}));
TrackBar* trackbar = new TrackBar(0, 64, 10);
trackbar->supplier([=]() {
@ -191,6 +189,22 @@ Panel* create_settings_panel(Engine* engine) {
panel->add(trackbar);
}
/* Fog Curve setting track bar */{
panel->add((new Label(L""))->textSupplier([=]() {
return L"Fog Curve: " +
std::to_wstring(engine->getSettings().graphics.fogCurve);
}));
TrackBar* trackbar = new TrackBar(1.0, 6.0, 1.0, 0.1, 2);
trackbar->supplier([=]() {
return engine->getSettings().graphics.fogCurve;
});
trackbar->consumer([=](double value) {
engine->getSettings().graphics.fogCurve = value;
});
panel->add(trackbar);
}
panel->add((new Button(L"Back", vec4(10.f)))->listenAction([=](GUI* gui) {
panel->visible(false);
gui->get("back")->visible(true);