Added CheckBox
This commit is contained in:
parent
9cd8870bd6
commit
dda9c40c41
@ -96,6 +96,7 @@ void Engine::mainloop() {
|
|||||||
screen->draw(delta);
|
screen->draw(delta);
|
||||||
gui->draw(&batch, assets);
|
gui->draw(&batch, assets);
|
||||||
|
|
||||||
|
Window::swapInterval(settings.display.swapInterval);
|
||||||
Window::swapBuffers();
|
Window::swapBuffers();
|
||||||
Events::pullEvents();
|
Events::pullEvents();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -193,3 +193,37 @@ void TrackBar::mouseMove(GUI*, int x, int y) {
|
|||||||
consumer_(value);
|
consumer_(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CheckBox::CheckBox(bool checked) : UINode(vec2(), vec2(32.0f)), checked_(checked) {
|
||||||
|
color(vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckBox::draw(Batch2D* batch, Assets* assets) {
|
||||||
|
if (supplier_) {
|
||||||
|
checked_ = supplier_();
|
||||||
|
}
|
||||||
|
vec2 coord = calcCoord();
|
||||||
|
batch->texture(nullptr);
|
||||||
|
batch->color = checked_ ? checkColor : (hover_ ? hoverColor : color_);
|
||||||
|
batch->rect(coord.x, coord.y, size_.x, size_.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckBox::mouseRelease(GUI*, int x, int y) {
|
||||||
|
checked_ = !checked_;
|
||||||
|
if (consumer_) {
|
||||||
|
consumer_(checked_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckBox::supplier(boolsupplier supplier) {
|
||||||
|
supplier_ = supplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckBox::consumer(boolconsumer consumer) {
|
||||||
|
consumer_ = consumer;
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckBox* CheckBox::checked(bool flag) {
|
||||||
|
checked_ = flag;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
@ -19,6 +19,9 @@ namespace gui {
|
|||||||
typedef std::function<double()> doublesupplier;
|
typedef std::function<double()> doublesupplier;
|
||||||
typedef std::function<void(double)> doubleconsumer;
|
typedef std::function<void(double)> doubleconsumer;
|
||||||
|
|
||||||
|
typedef std::function<bool()> boolsupplier;
|
||||||
|
typedef std::function<void(bool)> boolconsumer;
|
||||||
|
|
||||||
class Label : public UINode {
|
class Label : public UINode {
|
||||||
protected:
|
protected:
|
||||||
std::wstring text_;
|
std::wstring text_;
|
||||||
@ -37,7 +40,7 @@ namespace gui {
|
|||||||
|
|
||||||
class Button : public Panel {
|
class Button : public Panel {
|
||||||
protected:
|
protected:
|
||||||
glm::vec4 hoverColor {0.05f, 0.1f, 0.2f, 0.75f};
|
glm::vec4 hoverColor {0.05f, 0.1f, 0.15f, 0.75f};
|
||||||
glm::vec4 pressedColor {0.0f, 0.0f, 0.0f, 0.95f};
|
glm::vec4 pressedColor {0.0f, 0.0f, 0.0f, 0.95f};
|
||||||
std::vector<onaction> actions;
|
std::vector<onaction> actions;
|
||||||
public:
|
public:
|
||||||
@ -62,7 +65,8 @@ namespace gui {
|
|||||||
wstringsupplier supplier = nullptr;
|
wstringsupplier supplier = nullptr;
|
||||||
wstringconsumer consumer = nullptr;
|
wstringconsumer consumer = nullptr;
|
||||||
public:
|
public:
|
||||||
TextBox(std::wstring placeholder, glm::vec4 padding=glm::vec4(2.0f));
|
TextBox(std::wstring placeholder,
|
||||||
|
glm::vec4 padding=glm::vec4(2.0f));
|
||||||
|
|
||||||
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self) override;
|
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self) override;
|
||||||
|
|
||||||
@ -79,7 +83,6 @@ namespace gui {
|
|||||||
protected:
|
protected:
|
||||||
glm::vec4 hoverColor {0.01f, 0.02f, 0.03f, 0.5f};
|
glm::vec4 hoverColor {0.01f, 0.02f, 0.03f, 0.5f};
|
||||||
glm::vec4 trackColor {1.0f, 1.0f, 1.0f, 0.4f};
|
glm::vec4 trackColor {1.0f, 1.0f, 1.0f, 0.4f};
|
||||||
Label* label;
|
|
||||||
doublesupplier supplier_ = nullptr;
|
doublesupplier supplier_ = nullptr;
|
||||||
doubleconsumer consumer_ = nullptr;
|
doubleconsumer consumer_ = nullptr;
|
||||||
double min;
|
double min;
|
||||||
@ -88,7 +91,11 @@ namespace gui {
|
|||||||
double step;
|
double step;
|
||||||
int trackWidth;
|
int trackWidth;
|
||||||
public:
|
public:
|
||||||
TrackBar(double min, double max, double value, double step=1.0, int trackWidth=3);
|
TrackBar(double min,
|
||||||
|
double max,
|
||||||
|
double value,
|
||||||
|
double step=1.0,
|
||||||
|
int trackWidth=1);
|
||||||
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);
|
||||||
@ -96,6 +103,32 @@ namespace gui {
|
|||||||
|
|
||||||
virtual void mouseMove(GUI*, int x, int y) override;
|
virtual void mouseMove(GUI*, int x, int y) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CheckBox : public UINode {
|
||||||
|
protected:
|
||||||
|
glm::vec4 hoverColor {0.05f, 0.1f, 0.2f, 0.75f};
|
||||||
|
glm::vec4 checkColor {1.0f, 1.0f, 1.0f, 0.4f};
|
||||||
|
boolsupplier supplier_ = nullptr;
|
||||||
|
boolconsumer consumer_ = nullptr;
|
||||||
|
bool checked_ = false;
|
||||||
|
public:
|
||||||
|
CheckBox(bool checked=false);
|
||||||
|
|
||||||
|
virtual void draw(Batch2D* batch, Assets* assets) override;
|
||||||
|
|
||||||
|
virtual void mouseRelease(GUI*, int x, int y) override;
|
||||||
|
|
||||||
|
virtual void supplier(boolsupplier supplier);
|
||||||
|
virtual void consumer(boolconsumer consumer);
|
||||||
|
|
||||||
|
virtual CheckBox* checked(bool flag);
|
||||||
|
|
||||||
|
virtual bool checked() const {
|
||||||
|
if (supplier_)
|
||||||
|
return supplier_();
|
||||||
|
return checked_;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // FRONTEND_GUI_CONTROLS_H_
|
#endif // FRONTEND_GUI_CONTROLS_H_
|
||||||
@ -181,7 +181,7 @@ Panel* create_settings_panel(Engine* engine) {
|
|||||||
std::to_wstring(engine->getSettings().chunks.loadDistance);
|
std::to_wstring(engine->getSettings().chunks.loadDistance);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
TrackBar* trackbar = new TrackBar(3, 66, 10);
|
TrackBar* trackbar = new TrackBar(3, 66, 10, 1, 3);
|
||||||
trackbar->supplier([=]() {
|
trackbar->supplier([=]() {
|
||||||
return engine->getSettings().chunks.loadDistance;
|
return engine->getSettings().chunks.loadDistance;
|
||||||
});
|
});
|
||||||
@ -209,6 +209,25 @@ Panel* create_settings_panel(Engine* engine) {
|
|||||||
panel->add(trackbar);
|
panel->add(trackbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Panel* checkpanel = new Panel(vec2(400, 32), vec4(5.0f), 1.0f);
|
||||||
|
checkpanel->color(vec4(0.0f));
|
||||||
|
checkpanel->orientation(Orientation::horizontal);
|
||||||
|
|
||||||
|
CheckBox* checkbox = new CheckBox();
|
||||||
|
checkbox->margin(vec4(0.0f, 0.0f, 5.0f, 0.0f));
|
||||||
|
checkbox->supplier([=]() {
|
||||||
|
return engine->getSettings().display.swapInterval != 0;
|
||||||
|
});
|
||||||
|
checkbox->consumer([=](bool checked) {
|
||||||
|
engine->getSettings().display.swapInterval = checked;
|
||||||
|
});
|
||||||
|
checkpanel->add(checkbox);
|
||||||
|
checkpanel->add(new Label(L"V-Sync"));
|
||||||
|
|
||||||
|
panel->add(checkpanel);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@ -91,7 +91,7 @@ void WorldRenderer::draw(Camera* camera, bool occlusion, float fogFactor, float
|
|||||||
shader->uniform3f("u_cameraPos", camera->position);
|
shader->uniform3f("u_cameraPos", camera->position);
|
||||||
|
|
||||||
Block* cblock = Block::blocks[level->player->choosenBlock];
|
Block* cblock = Block::blocks[level->player->choosenBlock];
|
||||||
float multiplier = 0.2f;
|
float multiplier = 0.5f;
|
||||||
shader->uniform3f("u_torchlightColor",
|
shader->uniform3f("u_torchlightColor",
|
||||||
cblock->emission[0] / 15.0f * multiplier,
|
cblock->emission[0] / 15.0f * multiplier,
|
||||||
cblock->emission[1] / 15.0f * multiplier,
|
cblock->emission[1] / 15.0f * multiplier,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user