Fog-curve track bar
This commit is contained in:
parent
b14ef4f923
commit
76e57c42e1
@ -46,8 +46,9 @@ void Label::draw(Batch2D* batch, Assets* assets) {
|
|||||||
font->draw(batch, text_, coord.x, coord.y);
|
font->draw(batch, text_, coord.x, coord.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::textSupplier(wstringsupplier supplier) {
|
Label* Label::textSupplier(wstringsupplier supplier) {
|
||||||
this->supplier = supplier;
|
this->supplier = supplier;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Button::Button(shared_ptr<UINode> content, glm::vec4 padding) : Panel(vec2(32,32), padding, 0) {
|
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;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackBar::TrackBar(double min, double max, double value, double 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) {
|
: UINode(vec2(), vec2(32)), min(min), max(max), value(value), step(step), trackWidth(trackWidth) {
|
||||||
color(vec4(0.f, 0.f, 0.f, 0.4f));
|
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);
|
batch->rect(coord.x, coord.y, size_.x, size_.y);
|
||||||
|
|
||||||
float width = size_.x;
|
float width = size_.x;
|
||||||
float t = (value - min) / (max-min+trackWidth);
|
float t = (value - min) / (max-min+trackWidth*step);
|
||||||
|
|
||||||
batch->color = trackColor;
|
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) {
|
void TrackBar::supplier(doublesupplier supplier) {
|
||||||
@ -181,12 +182,13 @@ void TrackBar::consumer(doubleconsumer consumer) {
|
|||||||
|
|
||||||
void TrackBar::mouseMove(GUI*, int x, int y) {
|
void TrackBar::mouseMove(GUI*, int x, int y) {
|
||||||
vec2 coord = calcCoord();
|
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 = 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_) {
|
if (consumer_) {
|
||||||
consumer_(value);
|
consumer_(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,7 @@ namespace gui {
|
|||||||
|
|
||||||
virtual void draw(Batch2D* batch, Assets* assets) override;
|
virtual void draw(Batch2D* batch, Assets* assets) override;
|
||||||
|
|
||||||
virtual void textSupplier(wstringsupplier supplier);
|
virtual Label* textSupplier(wstringsupplier supplier);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Button : public Panel {
|
class Button : public Panel {
|
||||||
@ -86,9 +86,9 @@ namespace gui {
|
|||||||
double max;
|
double max;
|
||||||
double value;
|
double value;
|
||||||
double step;
|
double step;
|
||||||
int trackWidth = 3;
|
int trackWidth;
|
||||||
public:
|
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 draw(Batch2D* batch, Assets* assets) override;
|
||||||
|
|
||||||
virtual void supplier(doublesupplier supplier);
|
virtual void supplier(doublesupplier supplier);
|
||||||
|
|||||||
@ -173,13 +173,11 @@ Panel* create_settings_panel(Engine* engine) {
|
|||||||
panel->color(vec4(0.0f));
|
panel->color(vec4(0.0f));
|
||||||
panel->setCoord(vec2(10, 10));
|
panel->setCoord(vec2(10, 10));
|
||||||
|
|
||||||
{
|
/* Load Distance setting track bar */{
|
||||||
Label* label = new Label(L"");
|
panel->add((new Label(L""))->textSupplier([=]() {
|
||||||
label->textSupplier([=]() {
|
|
||||||
return L"Load Distance: " +
|
return L"Load Distance: " +
|
||||||
std::to_wstring(engine->getSettings().chunks.loadDistance);
|
std::to_wstring(engine->getSettings().chunks.loadDistance);
|
||||||
});
|
}));
|
||||||
panel->add(label);
|
|
||||||
|
|
||||||
TrackBar* trackbar = new TrackBar(0, 64, 10);
|
TrackBar* trackbar = new TrackBar(0, 64, 10);
|
||||||
trackbar->supplier([=]() {
|
trackbar->supplier([=]() {
|
||||||
@ -191,6 +189,22 @@ Panel* create_settings_panel(Engine* engine) {
|
|||||||
panel->add(trackbar);
|
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->add((new Button(L"Back", vec4(10.f)))->listenAction([=](GUI* gui) {
|
||||||
panel->visible(false);
|
panel->visible(false);
|
||||||
gui->get("back")->visible(true);
|
gui->get("back")->visible(true);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user